TombEngine/TR5Main/Game/lot.cpp

329 lines
8.2 KiB
C++
Raw Normal View History

#include "framework.h"
2018-08-19 09:46:58 +02:00
#include "lot.h"
#include "box.h"
#include "setup.h"
#include "camera.h"
2020-04-23 19:22:01 +02:00
#include "lara.h"
#include "level.h"
2018-08-19 09:46:58 +02:00
#define DEFAULT_FLY_UPDOWN_SPEED 16
#define DEFAULT_SWIM_UPDOWN_SPEED 32
int SlotsUsed;
2020-07-11 21:16:04 +02:00
std::vector<CREATURE_INFO> BaddieSlots;
void InitialiseLOTarray(int allocMem)
2018-08-19 09:46:58 +02:00
{
if (allocMem)
2020-07-11 21:16:04 +02:00
{
BaddieSlots.clear();
BaddieSlots.resize(NUM_SLOTS);
}
2018-08-19 09:46:58 +02:00
2020-07-11 21:16:04 +02:00
CREATURE_INFO* creature = BaddieSlots.data();
for (int i = 0; i < NUM_SLOTS; i++, creature++)
2018-08-19 09:46:58 +02:00
{
creature->itemNum = NO_ITEM;
2020-07-11 21:16:04 +02:00
if (allocMem)
{
creature->LOT.node.clear();
creature->LOT.node.resize(g_Level.Boxes.size());
for (int j = 0; j < g_Level.Boxes.size(); j++)
2020-07-11 21:16:04 +02:00
{
creature->LOT.node.emplace_back(BOX_NODE());
}
}
2018-08-19 09:46:58 +02:00
}
SlotsUsed = 0;
}
int EnableBaddieAI(short itemNum, int always)
2018-08-19 09:46:58 +02:00
{
ITEM_INFO* item = &g_Level.Items[itemNum];
2018-08-19 09:46:58 +02:00
if (item->data != NULL)
return true;
if (SlotsUsed >= NUM_SLOTS)
2018-08-19 09:46:58 +02:00
{
int cameraDistance = 0;
2018-08-19 09:46:58 +02:00
if (!always)
{
int deltaX = (item->pos.xPos - Camera.pos.x) >> 8;
int deltaY = (item->pos.yPos - Camera.pos.y) >> 8;
int deltaZ = (item->pos.zPos - Camera.pos.z) >> 8;
2018-08-19 09:46:58 +02:00
cameraDistance = SQUARE(deltaX) + SQUARE(deltaY) + SQUARE(deltaZ);
}
int slotToDisable = -1;
2020-07-11 21:16:04 +02:00
CREATURE_INFO* creature = BaddieSlots.data();
for (int slot = 0; slot < NUM_SLOTS; slot++, creature++)
2018-08-19 09:46:58 +02:00
{
item = &g_Level.Items[creature->itemNum];
2018-08-19 09:46:58 +02:00
int deltaX = (item->pos.xPos - Camera.pos.x) >> 8;
int deltaY = (item->pos.yPos - Camera.pos.y) >> 8;
int deltaZ = (item->pos.zPos - Camera.pos.z) >> 8;
int distance = SQUARE(deltaX) + SQUARE(deltaY) + SQUARE(deltaZ);
2018-08-19 09:46:58 +02:00
if (distance > cameraDistance)
{
cameraDistance = distance;
slotToDisable = slot;
}
}
if (slotToDisable < 0 || slotToDisable > NUM_SLOTS)
2018-08-19 09:46:58 +02:00
return false;
ITEM_INFO* itemToDisable = &g_Level.Items[BaddieSlots[slotToDisable].itemNum];
CREATURE_INFO* creatureToDisable = &BaddieSlots[slotToDisable];
2018-08-19 09:46:58 +02:00
itemToDisable->status = ITEM_INVISIBLE;
DisableBaddieAI(creatureToDisable->itemNum);
InitialiseSlot(itemNum, slotToDisable);
2018-08-19 09:46:58 +02:00
return true;
}
else
{
2020-07-11 21:16:04 +02:00
CREATURE_INFO* creature = BaddieSlots.data();
for (int slot = 0; slot < NUM_SLOTS; slot++, creature++)
2018-08-19 09:46:58 +02:00
{
if (creature->itemNum == NO_ITEM)
{
InitialiseSlot(itemNum, slot);
return true;
}
}
}
return false;
}
void DisableBaddieAI(short itemNumber)
{
ITEM_INFO* item = &g_Level.Items[itemNumber];
CREATURE_INFO* creature = (CREATURE_INFO*)item->data;
item->data = NULL;
if (creature)
{
creature->itemNum = NO_ITEM;
SlotsUsed--;
}
}
void InitialiseSlot(short itemNum, short slot)
2018-08-19 09:46:58 +02:00
{
ITEM_INFO* item = &g_Level.Items[itemNum];
2020-07-07 07:32:33 +02:00
OBJECT_INFO* obj = &Objects[item->objectNumber];
CREATURE_INFO* creature = &BaddieSlots[slot];
2018-08-19 09:46:58 +02:00
item->data = creature;
creature->itemNum = itemNum;
creature->mood = BORED_MOOD;
creature->jointRotation[0] = 0;
creature->jointRotation[1] = 0;
2018-08-19 09:46:58 +02:00
creature->jointRotation[2] = 0;
creature->jointRotation[3] = 0;
2018-08-19 09:46:58 +02:00
creature->alerted = false;
creature->headLeft = false;
creature->headRight = false;
creature->reachedGoal = false;
creature->hurtByLara = false;
creature->patrol2 = false;
creature->jumpAhead = false;
creature->monkeyAhead = false;
creature->LOT.canJump = false;
creature->LOT.canMonkey = false;
creature->LOT.isAmphibious = false; // only the crocodile can go water and land. (default: true)
2018-08-19 09:46:58 +02:00
creature->LOT.isJumping = false;
creature->LOT.isMonkeying = false;
creature->maximumTurn = ANGLE(1);
2018-08-19 09:46:58 +02:00
creature->flags = 0;
creature->enemy = NULL;
creature->LOT.fly = NO_FLYING;
creature->LOT.blockMask = BLOCKED;
if (obj->intelligent)
2018-08-19 09:46:58 +02:00
{
2020-01-13 13:18:55 +01:00
// simple check to set hitEffect to blood or smoke by default if intelligent enabled and no value assigned to hitEffect and the entity have HP !
// undead have smoke instead of blood !
if (obj->hitEffect == HIT_NONE)
{
if (obj->undead)
obj->hitEffect = HIT_SMOKE;
else if (!obj->undead && obj->hitPoints)
obj->hitEffect = HIT_BLOOD;
}
obj->nonLot = false; // change to use pathfinding
2018-08-19 09:46:58 +02:00
}
switch (obj->zoneType)
{
default:
case ZONE_NULL:
creature->LOT.step = SECTOR(1) - CLICK(3);
creature->LOT.drop = -(SECTOR(1) - CLICK(3));
obj->zoneType = ZONE_BASIC; // only entity that use CreatureActive() will reach InitialiseSlot() !
break;
case ZONE_SKELLY:
// Can jump
creature->LOT.step = SECTOR(1) - CLICK(3);
creature->LOT.drop = -(SECTOR(1) - CLICK(3));
creature->LOT.canJump = true;
creature->LOT.zone = ZONE_SKELLY;
break;
case ZONE_BASIC:
creature->LOT.step = SECTOR(1) - CLICK(3);
creature->LOT.drop = -(SECTOR(1) - CLICK(3));
creature->LOT.zone = ZONE_BASIC;
break;
case ZONE_FLYER:
// Can fly
creature->LOT.step = SECTOR(20);
creature->LOT.drop = -SECTOR(20);
creature->LOT.fly = DEFAULT_FLY_UPDOWN_SPEED;
creature->LOT.zone = ZONE_FLYER;
break;
case ZONE_WATER:
// Can swim
creature->LOT.step = SECTOR(20);
creature->LOT.drop = -SECTOR(20);
if (item->objectNumber == ID_CROCODILE)
{
creature->LOT.fly = DEFAULT_SWIM_UPDOWN_SPEED / 2; // is more slow than the other underwater entity
creature->LOT.isAmphibious = true; // crocodile can walk and swim.
}
else if (item->objectNumber == ID_BIG_RAT)
{
creature->LOT.fly = NO_FLYING; // dont want the bigrat to be able to go in water (just the surface !)
creature->LOT.isAmphibious = true; // bigrat can walk and swim.
}
else
{
creature->LOT.fly = DEFAULT_SWIM_UPDOWN_SPEED;
}
creature->LOT.zone = ZONE_WATER;
break;
case ZONE_HUMAN_CLASSIC:
// Can climb
creature->LOT.step = SECTOR(1);
creature->LOT.drop = -SECTOR(1);
creature->LOT.zone = ZONE_HUMAN_CLASSIC;
break;
case ZONE_HUMAN_JUMP:
// Can climb and jump
creature->LOT.step = SECTOR(1);
creature->LOT.drop = -SECTOR(1);
creature->LOT.canJump = true;
creature->LOT.zone = ZONE_HUMAN_CLASSIC;
break;
case ZONE_HUMAN_JUMP_AND_MONKEY:
// Can climb, jump, monkey
creature->LOT.step = SECTOR(1);
creature->LOT.drop = -SECTOR(1);
creature->LOT.canJump = true;
creature->LOT.canMonkey = true;
creature->LOT.zone = ZONE_HUMAN_CLASSIC;
break;
case ZONE_SPIDER:
creature->LOT.step = SECTOR(1) - CLICK(2);
creature->LOT.drop = -(SECTOR(1) - CLICK(2));
creature->LOT.zone = ZONE_HUMAN_CLASSIC;
break;
2020-01-13 13:18:55 +01:00
case ZONE_BLOCKABLE:
creature->LOT.blockMask = BLOCKABLE;
creature->LOT.zone = ZONE_BASIC;
2020-01-13 13:18:55 +01:00
break;
case ZONE_SOPHIALEE:
creature->LOT.step = CLICK(4);
creature->LOT.drop = -CLICK(3);
creature->LOT.zone = ZONE_HUMAN_CLASSIC;
2020-01-13 13:18:55 +01:00
break;
}
2018-08-19 09:46:58 +02:00
ClearLOT(&creature->LOT);
if (itemNum != Lara.itemNumber)
CreateZone(item);
SlotsUsed++;
}
void ClearLOT(LOT_INFO* LOT)
{
LOT->head = NO_BOX;
LOT->tail = NO_BOX;
LOT->searchNumber = 0;
LOT->targetBox = NO_BOX;
LOT->requiredBox = NO_BOX;
2020-07-11 21:16:04 +02:00
BOX_NODE* node = LOT->node.data();
for (int i = 0; i < g_Level.Boxes.size(); i++)
{
node->exitBox = NO_BOX;
node->nextExpansion = NO_BOX;
node->searchNumber = 0;
node++;
}
}
void CreateZone(ITEM_INFO* item)
{
CREATURE_INFO* creature = (CREATURE_INFO*)item->data;
ROOM_INFO* r = &g_Level.Rooms[item->roomNumber];
item->boxNumber = XZ_GET_SECTOR(r, item->pos.xPos - r->x, item->pos.zPos - r->z).box;
if (creature->LOT.fly)
{
2020-07-11 21:16:04 +02:00
BOX_NODE* node = creature->LOT.node.data();
creature->LOT.zoneCount = 0;
for (int i = 0; i < g_Level.Boxes.size(); i++)
{
node->boxNumber = i;
node++;
creature->LOT.zoneCount++;
}
}
else
{
int* zone = g_Level.Zones[creature->LOT.zone][0].data();
int* flippedZone = g_Level.Zones[creature->LOT.zone][1].data();
2020-07-11 21:16:04 +02:00
int zoneNumber = zone[item->boxNumber];
int flippedZoneNumber = flippedZone[item->boxNumber];
2020-07-11 21:16:04 +02:00
BOX_NODE* node = creature->LOT.node.data();
creature->LOT.zoneCount = 0;
for (int i = 0; i < g_Level.Boxes.size(); i++)
{
if (*zone == zoneNumber || *flippedZone == flippedZoneNumber)
{
node->boxNumber = i;
node++;
creature->LOT.zoneCount++;
}
zone++;
flippedZone++;
}
}
}