2020-05-27 09:21:20 +02:00
|
|
|
#include "framework.h"
|
|
|
|
#include "tr4_bigscorpion.h"
|
2021-09-19 23:41:26 +03:00
|
|
|
#include "control/box.h"
|
2021-09-25 16:00:30 +03:00
|
|
|
#include "effects/effects.h"
|
2020-05-27 09:21:20 +02:00
|
|
|
#include "items.h"
|
|
|
|
#include "setup.h"
|
2021-09-19 23:41:26 +03:00
|
|
|
#include "control/lot.h"
|
2020-05-27 09:21:20 +02:00
|
|
|
#include "level.h"
|
|
|
|
#include "lara.h"
|
2021-09-16 05:06:03 +03:00
|
|
|
#include "itemdata/creature_info.h"
|
2021-09-19 23:41:26 +03:00
|
|
|
#include "control/control.h"
|
2021-09-25 11:27:47 +02:00
|
|
|
|
2021-09-15 21:09:09 +03:00
|
|
|
int CutSeqNum;
|
|
|
|
|
2019-12-05 17:35:57 +01:00
|
|
|
BITE_INFO scorpionBite1 = { 0, 0, 0, 8 };
|
|
|
|
BITE_INFO scorpionBite2 = { 0, 0, 0, 23 };
|
|
|
|
|
2020-12-26 14:44:05 +01:00
|
|
|
enum SCORPION_STATES {
|
2021-05-13 10:11:22 +02:00
|
|
|
STATE_SCORPION_STOP = 1,
|
|
|
|
STATE_SCORPION_WALK = 2,
|
|
|
|
STATE_SCORPION_RUN = 3,
|
|
|
|
STATE_SCORPION_ATTACK1 = 4,
|
|
|
|
STATE_SCORPION_ATTACK2 = 5,
|
|
|
|
STATE_SCORPION_DEATH = 6,
|
|
|
|
STATE_SCORPION_SPECIAL_DEATH = 7,
|
|
|
|
STATE_SCORPION_TROOPS_ATTACK = 8
|
2020-12-26 14:44:05 +01:00
|
|
|
};
|
|
|
|
|
2020-05-27 09:21:20 +02:00
|
|
|
void InitialiseScorpion(short itemNumber)
|
2019-12-05 17:35:57 +01:00
|
|
|
{
|
2020-07-21 09:56:47 +02:00
|
|
|
ITEM_INFO* item = &g_Level.Items[itemNumber];
|
2019-12-05 17:35:57 +01:00
|
|
|
|
2020-05-27 09:21:20 +02:00
|
|
|
ClearItem(itemNumber);
|
2019-12-05 17:35:57 +01:00
|
|
|
|
|
|
|
if (item->triggerFlags == 1)
|
|
|
|
{
|
2021-05-13 10:11:22 +02:00
|
|
|
item->goalAnimState = STATE_SCORPION_TROOPS_ATTACK;
|
|
|
|
item->currentAnimState = STATE_SCORPION_TROOPS_ATTACK;
|
2020-02-24 12:51:28 +01:00
|
|
|
item->animNumber = Objects[ID_BIG_SCORPION].animIndex + 7;
|
2019-12-05 17:35:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-13 10:11:22 +02:00
|
|
|
item->goalAnimState = STATE_SCORPION_STOP;
|
|
|
|
item->currentAnimState = STATE_SCORPION_STOP;
|
2020-02-24 12:51:28 +01:00
|
|
|
item->animNumber = Objects[ID_BIG_SCORPION].animIndex + 2;
|
2019-12-05 17:35:57 +01:00
|
|
|
}
|
|
|
|
|
2020-07-21 09:56:47 +02:00
|
|
|
item->frameNumber = g_Level.Anims[item->animNumber].frameBase;
|
2019-12-05 17:35:57 +01:00
|
|
|
}
|
|
|
|
|
2020-05-27 09:21:20 +02:00
|
|
|
void ScorpionControl(short itemNumber)
|
2019-12-05 17:35:57 +01:00
|
|
|
{
|
2020-05-27 09:21:20 +02:00
|
|
|
if (!CreatureActive(itemNumber))
|
2019-12-05 17:35:57 +01:00
|
|
|
return;
|
|
|
|
|
2020-07-21 09:56:47 +02:00
|
|
|
ITEM_INFO* item = &g_Level.Items[itemNumber];
|
2019-12-05 17:35:57 +01:00
|
|
|
CREATURE_INFO* creature = (CREATURE_INFO*)item->data;
|
|
|
|
short angle = 0;
|
|
|
|
short head = 0;
|
|
|
|
short neck = 0;
|
|
|
|
short tilt = 0;
|
|
|
|
short joint0 = 0;
|
|
|
|
short joint1 = 0;
|
|
|
|
short joint2 = 0;
|
|
|
|
short joint3 = 0;
|
|
|
|
short roomNumber = item->roomNumber;
|
|
|
|
|
2020-10-05 22:24:57 -03:00
|
|
|
int x = item->pos.xPos + 682 * phd_sin(item->pos.yRot);
|
|
|
|
int z = item->pos.zPos + 682 * phd_cos(item->pos.yRot);
|
2019-12-05 17:35:57 +01:00
|
|
|
|
|
|
|
FLOOR_INFO* floor = GetFloor(x, item->pos.yPos, z, &roomNumber);
|
|
|
|
int height1 = GetFloorHeight(floor, x, item->pos.yPos, z);
|
|
|
|
if (abs(item->pos.yPos - height1) > 512)
|
|
|
|
height1 = item->pos.yPos;
|
|
|
|
|
2020-10-05 22:24:57 -03:00
|
|
|
x = item->pos.xPos - 682 * phd_sin(item->pos.yRot);
|
|
|
|
z = item->pos.zPos - 682 * phd_cos(item->pos.yRot);
|
2019-12-05 17:35:57 +01:00
|
|
|
|
|
|
|
floor = GetFloor(x, item->pos.yPos, z, &roomNumber);
|
|
|
|
int height2 = GetFloorHeight(floor, x, item->pos.yPos, z);
|
|
|
|
if (abs(item->pos.yPos - height2) > 512)
|
|
|
|
height2 = item->pos.yPos;
|
|
|
|
|
2020-04-25 16:23:53 +02:00
|
|
|
short angle1 = phd_atan(1344, height2 - height1);
|
2019-12-05 17:35:57 +01:00
|
|
|
|
2020-10-05 22:24:57 -03:00
|
|
|
x = item->pos.xPos - 682 * phd_sin(item->pos.yRot);
|
|
|
|
z = item->pos.zPos + 682 * phd_cos(item->pos.yRot);
|
2019-12-05 17:35:57 +01:00
|
|
|
|
|
|
|
floor = GetFloor(x, item->pos.yPos, z, &roomNumber);
|
|
|
|
int height3 = GetFloorHeight(floor, x, item->pos.yPos, z);
|
|
|
|
if (abs(item->pos.yPos - height3) > 512)
|
|
|
|
height3 = item->pos.yPos;
|
|
|
|
|
2020-10-05 22:24:57 -03:00
|
|
|
x = item->pos.xPos + 682 * phd_sin(item->pos.yRot);
|
|
|
|
z = item->pos.zPos - 682 * phd_cos(item->pos.yRot);
|
2019-12-05 17:35:57 +01:00
|
|
|
|
|
|
|
floor = GetFloor(x, item->pos.yPos, z, &roomNumber);
|
|
|
|
int height4 = GetFloorHeight(floor, x, item->pos.yPos, z);
|
|
|
|
if (abs(item->pos.yPos - height4) > 512)
|
|
|
|
height4 = item->pos.yPos;
|
|
|
|
|
2020-04-25 16:23:53 +02:00
|
|
|
short angle2 = phd_atan(1344, height4 - height3);
|
2019-12-05 17:35:57 +01:00
|
|
|
|
|
|
|
if (item->hitPoints <= 0)
|
|
|
|
{
|
|
|
|
item->hitPoints = 0;
|
2021-05-13 10:11:22 +02:00
|
|
|
if (item->currentAnimState != STATE_SCORPION_DEATH)
|
2019-12-05 17:35:57 +01:00
|
|
|
{
|
2021-05-13 10:11:22 +02:00
|
|
|
if (item->triggerFlags > 0 && item->triggerFlags < 7)
|
|
|
|
{
|
|
|
|
CutSeqNum = 4;
|
|
|
|
|
|
|
|
item->animNumber = Objects[item->animNumber].animIndex + 5;
|
|
|
|
item->currentAnimState = STATE_SCORPION_DEATH;
|
|
|
|
item->frameNumber = g_Level.Anims[item->animNumber].frameBase;
|
|
|
|
item->status = ITEM_INVISIBLE;
|
|
|
|
creature->maximumTurn = 0;
|
|
|
|
|
|
|
|
short linkNum = g_Level.Rooms[item->roomNumber].itemNumber;
|
|
|
|
if (linkNum != NO_ITEM)
|
|
|
|
{
|
|
|
|
for (linkNum = g_Level.Rooms[item->roomNumber].itemNumber; linkNum != NO_ITEM; linkNum = g_Level.Items[linkNum].nextItem)
|
|
|
|
{
|
|
|
|
ITEM_INFO* currentItem = &g_Level.Items[linkNum];
|
|
|
|
|
|
|
|
if (currentItem->objectNumber == ID_TROOPS && currentItem->triggerFlags == 1)
|
|
|
|
{
|
|
|
|
DisableBaddieAI(linkNum);
|
|
|
|
KillItem(linkNum);
|
|
|
|
currentItem->flags |= IFLAG_KILLED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (item->currentAnimState != STATE_SCORPION_DEATH && item->currentAnimState != STATE_SCORPION_SPECIAL_DEATH)
|
|
|
|
{
|
|
|
|
item->animNumber = Objects[item->objectNumber].animIndex + 5;
|
|
|
|
item->currentAnimState = STATE_SCORPION_DEATH;
|
|
|
|
item->frameNumber = g_Level.Anims[item->animNumber].frameBase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (CutSeqNum == 4)
|
|
|
|
{
|
|
|
|
item->frameNumber = g_Level.Anims[item->animNumber].frameEnd - 1;
|
|
|
|
item->status = ITEM_INVISIBLE;
|
|
|
|
}
|
|
|
|
else if (item->currentAnimState == STATE_SCORPION_DEATH)
|
|
|
|
{
|
|
|
|
if (item->status == ITEM_INVISIBLE)
|
|
|
|
{
|
|
|
|
item->status = ITEM_ACTIVE;
|
|
|
|
}
|
2019-12-05 17:35:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (item->aiBits)
|
|
|
|
GetAITarget(creature);
|
|
|
|
else
|
2021-05-13 10:11:22 +02:00
|
|
|
{
|
|
|
|
if (creature->hurtByLara
|
|
|
|
&& item->currentAnimState != STATE_SCORPION_TROOPS_ATTACK)
|
|
|
|
{
|
|
|
|
creature->enemy = LaraItem;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
creature->enemy = NULL;
|
|
|
|
int minDistance = 0x7FFFFFFF;
|
|
|
|
|
2021-09-03 09:37:42 +02:00
|
|
|
for (int i = 0; i < ActiveCreatures.size(); i++)
|
2021-05-13 10:11:22 +02:00
|
|
|
{
|
2021-09-03 09:37:42 +02:00
|
|
|
CREATURE_INFO* baddy = ActiveCreatures[i];
|
2021-05-13 10:11:22 +02:00
|
|
|
|
|
|
|
if (baddy->itemNum != NO_ITEM && baddy->itemNum != itemNumber)
|
|
|
|
{
|
|
|
|
ITEM_INFO* currentItem = &g_Level.Items[baddy->itemNum];
|
|
|
|
|
|
|
|
if (currentItem->objectNumber != ID_LARA)
|
|
|
|
{
|
|
|
|
if (currentItem->objectNumber != ID_BIG_SCORPION &&
|
|
|
|
(currentItem != LaraItem || creature->hurtByLara))
|
|
|
|
{
|
|
|
|
int dx = currentItem->pos.xPos - item->pos.xPos;
|
|
|
|
int dy = currentItem->pos.yPos - item->pos.yPos;
|
|
|
|
int dz = currentItem->pos.zPos - item->pos.zPos;
|
|
|
|
|
|
|
|
int distance = SQUARE(dx) + SQUARE(dy) + SQUARE(dz);
|
|
|
|
|
|
|
|
if (distance < minDistance)
|
|
|
|
{
|
|
|
|
minDistance = distance;
|
|
|
|
creature->enemy = currentItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-05 17:35:57 +01:00
|
|
|
|
|
|
|
AI_INFO info;
|
|
|
|
|
|
|
|
CreatureAIInfo(item, &info);
|
|
|
|
|
|
|
|
GetCreatureMood(item, &info, VIOLENT);
|
|
|
|
CreatureMood(item, &info, VIOLENT);
|
|
|
|
|
|
|
|
angle = CreatureTurn(item, creature->maximumTurn);
|
|
|
|
|
|
|
|
switch (item->currentAnimState)
|
|
|
|
{
|
2021-05-13 10:11:22 +02:00
|
|
|
case STATE_SCORPION_STOP:
|
2019-12-05 17:35:57 +01:00
|
|
|
creature->maximumTurn = 0;
|
|
|
|
creature->flags = 0;
|
|
|
|
|
|
|
|
if (info.distance > SQUARE(1365))
|
|
|
|
{
|
2021-05-13 10:11:22 +02:00
|
|
|
item->goalAnimState = STATE_SCORPION_WALK;
|
2019-12-05 17:35:57 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.bite)
|
|
|
|
{
|
|
|
|
creature->maximumTurn = ANGLE(2);
|
|
|
|
|
2021-05-13 10:11:22 +02:00
|
|
|
if (GetRandomControl() & 1
|
|
|
|
&& creature->enemy->hitPoints <= 15
|
|
|
|
&& creature->enemy->objectNumber == ID_TROOPS)
|
2019-12-05 17:35:57 +01:00
|
|
|
{
|
2021-05-13 10:11:22 +02:00
|
|
|
item->goalAnimState = STATE_SCORPION_ATTACK1;
|
2019-12-05 17:35:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-13 10:11:22 +02:00
|
|
|
item->goalAnimState = STATE_SCORPION_ATTACK2;
|
2019-12-05 17:35:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!info.ahead)
|
|
|
|
{
|
2021-05-13 10:11:22 +02:00
|
|
|
item->goalAnimState = STATE_SCORPION_WALK;
|
2019-12-05 17:35:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-05-13 10:11:22 +02:00
|
|
|
case STATE_SCORPION_WALK:
|
2019-12-05 17:35:57 +01:00
|
|
|
creature->maximumTurn = ANGLE(2);
|
|
|
|
|
|
|
|
if (info.distance < SQUARE(1365))
|
|
|
|
{
|
2021-05-13 10:11:22 +02:00
|
|
|
item->goalAnimState = STATE_SCORPION_STOP;
|
2019-12-05 17:35:57 +01:00
|
|
|
}
|
2021-05-13 10:11:22 +02:00
|
|
|
else if (info.distance > SQUARE(853))
|
2019-12-05 17:35:57 +01:00
|
|
|
{
|
2021-05-13 10:11:22 +02:00
|
|
|
item->goalAnimState = STATE_SCORPION_RUN;
|
2019-12-05 17:35:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-05-13 10:11:22 +02:00
|
|
|
case STATE_SCORPION_RUN:
|
2019-12-05 17:35:57 +01:00
|
|
|
creature->maximumTurn = ANGLE(3);
|
|
|
|
|
2021-05-13 10:11:22 +02:00
|
|
|
if (info.distance < SQUARE(1365))
|
2019-12-05 17:35:57 +01:00
|
|
|
{
|
2021-05-13 10:11:22 +02:00
|
|
|
item->goalAnimState = STATE_SCORPION_STOP;
|
2019-12-05 17:35:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-05-13 10:11:22 +02:00
|
|
|
case STATE_SCORPION_ATTACK1:
|
|
|
|
case STATE_SCORPION_ATTACK2:
|
2019-12-05 17:35:57 +01:00
|
|
|
creature->maximumTurn = 0;
|
|
|
|
|
|
|
|
if (abs(info.angle) >= ANGLE(2))
|
|
|
|
{
|
|
|
|
if (info.angle >= 0)
|
|
|
|
{
|
|
|
|
item->pos.yRot += ANGLE(2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item->pos.yRot -= ANGLE(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item->pos.yRot += info.angle;
|
|
|
|
}
|
2021-05-13 10:11:22 +02:00
|
|
|
|
2019-12-05 17:35:57 +01:00
|
|
|
if (creature->flags)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-05-13 10:11:22 +02:00
|
|
|
if (creature->enemy
|
|
|
|
&& creature->enemy != LaraItem
|
|
|
|
&& info.distance < SQUARE(1365))
|
2019-12-05 17:35:57 +01:00
|
|
|
{
|
|
|
|
creature->enemy->hitPoints -= 15;
|
|
|
|
if (creature->enemy->hitPoints <= 0)
|
|
|
|
{
|
2021-05-13 10:11:22 +02:00
|
|
|
item->goalAnimState = STATE_SCORPION_SPECIAL_DEATH;
|
2019-12-05 17:35:57 +01:00
|
|
|
creature->maximumTurn = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
creature->enemy->hitStatus = true;
|
|
|
|
creature->flags = 1;
|
|
|
|
|
|
|
|
CreatureEffect2(
|
|
|
|
item,
|
|
|
|
&scorpionBite1,
|
|
|
|
10,
|
|
|
|
item->pos.yRot - ANGLE(180),
|
|
|
|
DoBloodSplat);
|
|
|
|
}
|
|
|
|
else if (item->touchBits & 0x1B00100)
|
|
|
|
{
|
|
|
|
LaraItem->hitPoints -= 120;
|
|
|
|
LaraItem->hitStatus = true;
|
|
|
|
|
|
|
|
if (item->currentAnimState == 5)
|
|
|
|
{
|
2021-08-17 00:15:09 +03:00
|
|
|
Lara.poisoned += 2048;
|
2019-12-05 17:35:57 +01:00
|
|
|
|
|
|
|
CreatureEffect2(
|
|
|
|
item,
|
|
|
|
&scorpionBite1,
|
|
|
|
10,
|
|
|
|
item->pos.yRot - ANGLE(180),
|
|
|
|
DoBloodSplat);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CreatureEffect2(
|
|
|
|
item,
|
|
|
|
&scorpionBite2,
|
|
|
|
10,
|
|
|
|
item->pos.yRot - ANGLE(180),
|
|
|
|
DoBloodSplat);
|
|
|
|
}
|
|
|
|
|
|
|
|
creature->flags = 1;
|
|
|
|
if (LaraItem->hitPoints <= 0)
|
|
|
|
{
|
|
|
|
CreatureKill(item, 6, 7, 442);
|
|
|
|
creature->maximumTurn = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-05-13 10:11:22 +02:00
|
|
|
case STATE_SCORPION_TROOPS_ATTACK:
|
2019-12-05 17:35:57 +01:00
|
|
|
creature->maximumTurn = 0;
|
2020-07-21 09:56:47 +02:00
|
|
|
if (item->frameNumber == g_Level.Anims[item->animNumber].frameEnd)
|
2019-12-05 17:35:57 +01:00
|
|
|
{
|
|
|
|
item->triggerFlags++;
|
|
|
|
}
|
2021-05-13 10:11:22 +02:00
|
|
|
if (creature->enemy
|
|
|
|
&& creature->enemy->hitPoints <= 0
|
|
|
|
|| item->triggerFlags > 6)
|
2019-12-05 17:35:57 +01:00
|
|
|
{
|
2021-05-13 10:11:22 +02:00
|
|
|
item->goalAnimState = STATE_SCORPION_SPECIAL_DEATH;
|
2019-12-05 17:35:57 +01:00
|
|
|
creature->enemy->hitPoints = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((angle1 - item->pos.xRot) < 256)
|
|
|
|
item->pos.xRot = 256;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (angle1 <= item->pos.xRot)
|
|
|
|
item->pos.xRot -= 256;
|
|
|
|
else
|
|
|
|
item->pos.xRot += 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((angle2 - item->pos.zRot) < 256)
|
|
|
|
item->pos.zRot = 256;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (angle2 <= item->pos.zRot)
|
|
|
|
item->pos.zRot -= 256;
|
|
|
|
else
|
|
|
|
item->pos.zRot += 256;
|
|
|
|
}
|
|
|
|
|
2021-05-13 10:11:22 +02:00
|
|
|
if (!CutSeqNum)
|
|
|
|
CreatureAnimation(itemNumber, angle, 0);
|
2021-08-31 17:37:15 +02:00
|
|
|
}
|