mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-30 16:57:57 +03:00
170 lines
No EOL
3.5 KiB
C++
170 lines
No EOL
3.5 KiB
C++
#include "../newobjects.h"
|
|
#include "../../Game/Box.h"
|
|
#include "../../Game/items.h"
|
|
#include "../../Game/effects.h"
|
|
|
|
BITE_INFO wildboardBiteInfo = { 0, 0, 0, 14 };
|
|
|
|
void InitialiseWildBoar(short itemNum)
|
|
{
|
|
ITEM_INFO* item = &Items[itemNum];
|
|
|
|
ClearItem(itemNum);
|
|
|
|
item->animNumber = Objects[ID_WILD_BOAR].animIndex + 6;
|
|
item->frameNumber = Anims[item->animNumber].frameBase;
|
|
item->goalAnimState = 1;
|
|
item->currentAnimState = 1;
|
|
}
|
|
|
|
void WildBoarControl(short itemNum)
|
|
{
|
|
if (!CreatureActive(itemNum))
|
|
return;
|
|
|
|
ITEM_INFO* item = &Items[itemNum];
|
|
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;
|
|
|
|
if (item->hitPoints > 0)
|
|
{
|
|
int dx = LaraItem->pos.xPos - item->pos.xPos;
|
|
int dz = LaraItem->pos.zPos - item->pos.zPos;
|
|
int laraDistance = dx * dx + dz * dz;
|
|
|
|
if (item->aiBits & GUARD)
|
|
{
|
|
GetAITarget(creature);
|
|
}
|
|
else
|
|
{
|
|
creature->enemy = LaraItem;
|
|
|
|
CREATURE_INFO* baddie = &BaddieSlots[0];
|
|
CREATURE_INFO* found = &BaddieSlots[0];
|
|
int minDistance = 0x7FFFFFFF;
|
|
|
|
for (int i = 0; i < NUM_SLOTS; i++, baddie++)
|
|
{
|
|
if (baddie->itemNum == NO_ITEM || baddie->itemNum == itemNum)
|
|
continue;
|
|
|
|
ITEM_INFO* target = &Items[baddie->itemNum];
|
|
if (target->objectNumber != ID_WILD_BOAR)
|
|
{
|
|
int dx2 = target->pos.xPos - item->pos.xPos;
|
|
int dz2 = target->pos.zPos - item->pos.zPos;
|
|
int distance = dx2 * dx2 + dz2 * dz2;
|
|
|
|
if (distance < minDistance && distance < laraDistance)
|
|
{
|
|
creature->enemy = target;
|
|
minDistance = distance;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
AI_INFO info;
|
|
CreatureAIInfo(item, &info);
|
|
|
|
GetCreatureMood(item, &info, VIOLENT);
|
|
if (item->flags)
|
|
creature->mood = ESCAPE_MOOD;
|
|
CreatureMood(item, &info, VIOLENT);
|
|
|
|
angle = CreatureTurn(item, creature->maximumTurn);
|
|
|
|
if (info.ahead)
|
|
{
|
|
joint1 = info.angle >> 1;
|
|
joint3 = info.angle >> 1;
|
|
}
|
|
|
|
switch (item->currentAnimState)
|
|
{
|
|
case 1:
|
|
creature->maximumTurn = 0;
|
|
if (info.ahead && info.distance || item->flags)
|
|
{
|
|
item->goalAnimState = 2;
|
|
}
|
|
else if (GetRandomControl() & 0x7F)
|
|
{
|
|
joint1 = AIGuard(creature) >> 1;
|
|
joint3 = joint1;
|
|
}
|
|
else
|
|
{
|
|
item->goalAnimState = 3;
|
|
}
|
|
break;
|
|
|
|
case 3:
|
|
creature->maximumTurn = 0;
|
|
if (info.ahead && info.distance)
|
|
{
|
|
item->goalAnimState = 1;
|
|
}
|
|
else if (!(GetRandomControl() & 0x7F))
|
|
{
|
|
item->goalAnimState = 1;
|
|
}
|
|
break;
|
|
|
|
case 2:
|
|
if (info.distance >= 0x400000)
|
|
{
|
|
creature->maximumTurn = 1092;
|
|
item->flags = 0;
|
|
}
|
|
else
|
|
{
|
|
creature->maximumTurn = 546;
|
|
joint0 = -info.distance;
|
|
joint2 = -info.distance;
|
|
}
|
|
if (!item->flags && (info.distance < 0x10000 && info.bite))
|
|
{
|
|
item->goalAnimState = 4;
|
|
if (creature->enemy == LaraItem)
|
|
{
|
|
LaraItem->hitPoints -= 30;
|
|
LaraItem->hitStatus = true;
|
|
}
|
|
|
|
CreatureEffect2(item, &wildboardBiteInfo, 3, item->pos.yRot, DoBloodSplat);
|
|
item->flags = 1;
|
|
}
|
|
break;
|
|
|
|
case 4:
|
|
creature->maximumTurn = 0;
|
|
break;
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
item->hitPoints = 0;
|
|
if (item->currentAnimState != 5)
|
|
{
|
|
item->animNumber = Objects[ID_WILD_BOAR].animIndex + 5;
|
|
item->currentAnimState = 5;
|
|
item->frameNumber = Anims[item->animNumber].frameBase;
|
|
}
|
|
}
|
|
|
|
CreatureJoint(item, 0, joint0);
|
|
CreatureJoint(item, 1, joint1);
|
|
CreatureJoint(item, 2, joint2);
|
|
CreatureJoint(item, 3, joint3);
|
|
CreatureAnimation(itemNum, angle, 0);
|
|
} |