2021-05-28 12:36:40 +02:00
|
|
|
#include "framework.h"
|
|
|
|
#include "tr4_dog.h"
|
2021-09-19 23:41:26 +03:00
|
|
|
#include "control/box.h"
|
2021-09-08 18:07:48 +03:00
|
|
|
#include "effects\effects.h"
|
2021-05-28 12:36:40 +02:00
|
|
|
#include "setup.h"
|
|
|
|
#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-24 07:53:42 +02:00
|
|
|
#include "item.h"
|
2021-09-25 11:27:47 +02:00
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
namespace TEN::Entities::TR4
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
enum DOG_STATES
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
STATE_DOG_NONE = 0,
|
|
|
|
STATE_DOG_STOP = 1,
|
|
|
|
STATE_DOG_WALK = 2,
|
|
|
|
STATE_DOG_RUN = 3,
|
|
|
|
STATE_DOG_STALK = 5,
|
|
|
|
STATE_DOG_JUMP_ATTACK = 6,
|
|
|
|
STATE_DOG_HOWL = 7,
|
|
|
|
STATE_DOG_SLEEP = 8,
|
|
|
|
STATE_DOG_CROUCH = 9,
|
|
|
|
STATE_DOG_DEATH = 11,
|
|
|
|
STATE_DOG_CROUCH_ATTACK = 12
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr auto DOG_CROUCH_ATTACK_DAMAGE = 10;
|
|
|
|
constexpr auto DOG_JUMP_ATTACK_DAMAGE = 20;
|
|
|
|
|
|
|
|
BYTE DogAnims[] = { 20, 21, 22, 20 };
|
|
|
|
BITE_INFO DogBite = { 0, 0, 100, 3 };
|
|
|
|
|
|
|
|
void InitialiseTr4Dog(short itemNum)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
ITEM_INFO* item;
|
2021-05-28 12:36:40 +02:00
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
item = &g_Level.Items[itemNum];
|
|
|
|
item->currentAnimState = STATE_DOG_STOP;
|
|
|
|
item->animNumber = Objects[item->objectNumber].animIndex + 8;
|
2021-05-28 12:36:40 +02:00
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
// OCB 1 makes the dog sitting down until fired
|
|
|
|
if (item->triggerFlags)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
item->animNumber = Objects[item->objectNumber].animIndex + 1;
|
|
|
|
item->status -= ITEM_INVISIBLE;
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
item->frameNumber = g_Level.Anims[item->animNumber].frameBase;
|
|
|
|
}
|
2021-05-28 12:36:40 +02:00
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
void Tr4DogControl(short itemNumber)
|
|
|
|
{
|
|
|
|
if (!CreatureActive(itemNumber))
|
|
|
|
return;
|
2021-05-28 12:36:40 +02:00
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
short angle = 0;
|
|
|
|
short joint2 = 0;
|
|
|
|
short joint1 = 0;
|
|
|
|
short joint0 = 0;
|
2021-05-28 12:36:40 +02:00
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
ITEM_INFO* item = &g_Level.Items[itemNumber];
|
|
|
|
CREATURE_INFO* creature = (CREATURE_INFO*)item->data;
|
|
|
|
OBJECT_INFO* obj = &Objects[item->objectNumber];
|
2021-05-28 12:36:40 +02:00
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
if (item->hitPoints <= 0)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
if (item->animNumber == obj->animIndex + 1)
|
|
|
|
{
|
|
|
|
item->hitPoints = obj->hitPoints;
|
|
|
|
}
|
|
|
|
else if (item->currentAnimState != STATE_DOG_DEATH)
|
|
|
|
{
|
|
|
|
item->animNumber = obj->animIndex + DogAnims[GetRandomControl() & 3];
|
|
|
|
item->currentAnimState = STATE_DOG_DEATH;
|
|
|
|
item->frameNumber = g_Level.Anims[item->animNumber].frameBase;
|
|
|
|
}
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
2021-08-31 05:19:11 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (item->aiBits)
|
|
|
|
GetAITarget(creature);
|
|
|
|
else
|
|
|
|
creature->enemy = LaraItem;
|
2021-05-28 12:36:40 +02:00
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
AI_INFO info;
|
|
|
|
CreatureAIInfo(item, &info);
|
2021-05-28 12:36:40 +02:00
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
int distance;
|
|
|
|
if (creature->enemy == LaraItem)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
distance = info.distance;
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
int dx = LaraItem->pos.xPos - item->pos.xPos;
|
|
|
|
int dz = LaraItem->pos.zPos - item->pos.zPos;
|
|
|
|
phd_atan(dz, dx);
|
|
|
|
distance = SQUARE(dx) + SQUARE(dz);
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
if (info.ahead)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
joint2 = info.xAngle; // Maybe swapped
|
|
|
|
joint1 = info.angle;
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
GetCreatureMood(item, &info, VIOLENT);
|
|
|
|
CreatureMood(item, &info, VIOLENT);
|
|
|
|
|
|
|
|
if (creature->mood == BORED_MOOD)
|
|
|
|
creature->maximumTurn /= 2;
|
|
|
|
|
|
|
|
angle = CreatureTurn(item, creature->maximumTurn);
|
|
|
|
joint0 = 4 * angle;
|
|
|
|
|
|
|
|
if (creature->hurtByLara || distance < SQUARE(3072) && !(item->aiBits & MODIFY))
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
AlertAllGuards(itemNumber);
|
|
|
|
item->aiBits &= ~MODIFY;
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
short random = GetRandomControl();
|
|
|
|
int frame = item->frameNumber - g_Level.Anims[item->animNumber].frameBase;
|
|
|
|
|
|
|
|
switch (item->currentAnimState)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
case STATE_DOG_NONE:
|
|
|
|
case STATE_DOG_SLEEP:
|
|
|
|
joint1 = 0;
|
|
|
|
joint2 = 0;
|
|
|
|
if (creature->mood && (item->aiBits) != MODIFY)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
item->goalAnimState = STATE_DOG_STOP;
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
2021-08-31 05:19:11 +02:00
|
|
|
else
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
creature->flags++;
|
|
|
|
creature->maximumTurn = 0;
|
|
|
|
if (creature->flags > 300 && random < 128)
|
|
|
|
item->goalAnimState = STATE_DOG_STOP;
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
2021-08-31 05:19:11 +02:00
|
|
|
break;
|
2021-05-28 12:36:40 +02:00
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
case STATE_DOG_STOP:
|
|
|
|
case STATE_DOG_CROUCH:
|
|
|
|
if (item->currentAnimState == STATE_DOG_CROUCH && item->requiredAnimState)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
item->goalAnimState = item->requiredAnimState;
|
2021-05-28 12:36:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
creature->maximumTurn = 0;
|
|
|
|
if (item->aiBits & GUARD)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
joint1 = AIGuard(creature);
|
|
|
|
if (GetRandomControl())
|
|
|
|
break;
|
|
|
|
if (item->currentAnimState == STATE_DOG_STOP)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
item->goalAnimState = STATE_DOG_CROUCH;
|
|
|
|
break;
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
2021-08-31 05:19:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (item->currentAnimState == STATE_DOG_CROUCH && random < 128)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
item->goalAnimState = STATE_DOG_STOP;
|
|
|
|
break;
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
if (item->aiBits & PATROL1)
|
|
|
|
{
|
|
|
|
if (item->currentAnimState == STATE_DOG_STOP)
|
|
|
|
item->goalAnimState = STATE_DOG_WALK;
|
|
|
|
else
|
|
|
|
item->goalAnimState = STATE_DOG_STOP;
|
|
|
|
break;
|
|
|
|
}
|
2021-05-28 12:36:40 +02:00
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
if (creature->mood == ESCAPE_MOOD)
|
|
|
|
{
|
|
|
|
if (Lara.target == item || !info.ahead || item->hitStatus)
|
|
|
|
{
|
|
|
|
item->requiredAnimState = STATE_DOG_RUN;
|
|
|
|
item->goalAnimState = STATE_DOG_CROUCH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item->goalAnimState = STATE_DOG_STOP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-05-28 12:36:40 +02:00
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
if (creature->mood != BORED_MOOD)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
item->requiredAnimState = STATE_DOG_RUN;
|
|
|
|
if (item->currentAnimState == STATE_DOG_STOP)
|
|
|
|
item->goalAnimState = STATE_DOG_CROUCH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
creature->flags = 0;
|
|
|
|
creature->maximumTurn = ANGLE(1);
|
|
|
|
|
|
|
|
if (random < 256)
|
|
|
|
{
|
|
|
|
if (item->aiBits & MODIFY)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
if (item->currentAnimState == STATE_DOG_STOP)
|
|
|
|
{
|
|
|
|
item->goalAnimState = STATE_DOG_SLEEP;
|
|
|
|
creature->flags = 0;
|
|
|
|
break;
|
|
|
|
}
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-31 05:19:11 +02:00
|
|
|
|
|
|
|
if (random >= 4096)
|
|
|
|
{
|
|
|
|
if (!(random & 0x1F))
|
|
|
|
item->goalAnimState = STATE_DOG_HOWL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->currentAnimState == STATE_DOG_STOP)
|
|
|
|
{
|
|
|
|
item->goalAnimState = STATE_DOG_WALK;
|
|
|
|
break;
|
|
|
|
}
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
2021-08-31 05:19:11 +02:00
|
|
|
item->goalAnimState = STATE_DOG_STOP;
|
|
|
|
break;
|
2021-05-28 12:36:40 +02:00
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
case STATE_DOG_WALK:
|
|
|
|
creature->maximumTurn = ANGLE(3);
|
|
|
|
if (item->aiBits & PATROL1)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
item->goalAnimState = STATE_DOG_WALK;
|
2021-05-28 12:36:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
if (!creature->mood && random < 256)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
item->goalAnimState = STATE_DOG_STOP;
|
2021-05-28 12:36:40 +02:00
|
|
|
break;
|
|
|
|
}
|
2021-08-31 05:19:11 +02:00
|
|
|
item->goalAnimState = STATE_DOG_STALK;
|
2021-05-28 12:36:40 +02:00
|
|
|
break;
|
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
case STATE_DOG_RUN:
|
|
|
|
creature->maximumTurn = ANGLE(6);
|
|
|
|
if (creature->mood == ESCAPE_MOOD)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
if (Lara.target != item && info.ahead)
|
|
|
|
item->goalAnimState = STATE_DOG_CROUCH;
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
2021-08-31 05:19:11 +02:00
|
|
|
else if (creature->mood)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
if (info.bite && info.distance < SQUARE(1024))
|
|
|
|
{
|
|
|
|
item->goalAnimState = STATE_DOG_JUMP_ATTACK;
|
|
|
|
}
|
|
|
|
else if (info.distance < SQUARE(1536))
|
|
|
|
{
|
|
|
|
item->requiredAnimState = STATE_DOG_STALK;
|
|
|
|
item->goalAnimState = STATE_DOG_CROUCH;
|
|
|
|
}
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
2021-08-31 05:19:11 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
item->goalAnimState = STATE_DOG_CROUCH;
|
|
|
|
}
|
|
|
|
break;
|
2021-05-28 12:36:40 +02:00
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
case STATE_DOG_STALK:
|
|
|
|
creature->maximumTurn = ANGLE(3);
|
|
|
|
if (creature->mood)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
if (creature->mood == ESCAPE_MOOD)
|
|
|
|
{
|
|
|
|
item->goalAnimState = STATE_DOG_RUN;
|
|
|
|
}
|
|
|
|
else if (info.bite && info.distance < SQUARE(341))
|
|
|
|
{
|
|
|
|
item->goalAnimState = STATE_DOG_CROUCH_ATTACK;
|
|
|
|
item->requiredAnimState = STATE_DOG_STALK;
|
|
|
|
}
|
|
|
|
else if (info.distance > SQUARE(1536) || item->hitStatus)
|
|
|
|
{
|
|
|
|
item->goalAnimState = STATE_DOG_RUN;
|
|
|
|
}
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
2021-08-31 05:19:11 +02:00
|
|
|
else
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
item->goalAnimState = STATE_DOG_CROUCH;
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
2021-08-31 05:19:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_DOG_JUMP_ATTACK:
|
|
|
|
if (info.bite
|
|
|
|
&& item->touchBits & 0x6648
|
|
|
|
&& frame >= 4
|
|
|
|
&& frame <= 14)
|
2021-05-28 12:36:40 +02:00
|
|
|
{
|
2021-08-31 05:19:11 +02:00
|
|
|
CreatureEffect2(item, &DogBite, 2, -1, DoBloodSplat);
|
|
|
|
LaraItem->hitPoints -= DOG_JUMP_ATTACK_DAMAGE;
|
|
|
|
LaraItem->hitStatus = true;
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
2021-08-31 05:19:11 +02:00
|
|
|
item->goalAnimState = STATE_DOG_RUN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_DOG_HOWL:
|
|
|
|
joint1 = 0;
|
|
|
|
joint2 = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_DOG_CROUCH_ATTACK:
|
|
|
|
if (info.bite
|
|
|
|
&& item->touchBits & 0x48
|
|
|
|
&& (frame >= 9
|
|
|
|
&& frame <= 12
|
|
|
|
|| frame >= 22
|
|
|
|
&& frame <= 25))
|
|
|
|
{
|
|
|
|
CreatureEffect2(item, &DogBite, 2, -1, DoBloodSplat);
|
|
|
|
LaraItem->hitPoints -= DOG_CROUCH_ATTACK_DAMAGE;
|
|
|
|
LaraItem->hitStatus = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2021-05-28 12:36:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-31 05:19:11 +02:00
|
|
|
CreatureTilt(item, 0);
|
|
|
|
CreatureJoint(item, 0, joint0);
|
|
|
|
CreatureJoint(item, 1, joint1);
|
|
|
|
CreatureJoint(item, 2, joint2);
|
|
|
|
CreatureAnimation(itemNumber, angle, 0);
|
|
|
|
}
|
2021-08-31 17:37:15 +02:00
|
|
|
}
|