Merge branch 'master' into coll_info_reorganize

This commit is contained in:
Lwmte 2021-09-10 10:11:15 +03:00
commit 280c9fa28b
244 changed files with 1313 additions and 887 deletions

View file

@ -1,16 +1,10 @@
#pragma once
#include "Specific\phd_global.h"
#include "items.h"
#include "level.h"
enum MOOD_TYPE
{
BORED_MOOD,
ATTACK_MOOD,
ESCAPE_MOOD,
STALK_MOOD
};
struct ITEM_INFO;
struct BITE_INFO;
struct CREATURE_INFO;
struct LOT_INFO;
enum TARGET_TYPE
{
NO_TARGET,
@ -18,25 +12,7 @@ enum TARGET_TYPE
SECONDARY_TARGET
};
enum ZoneType
{
ZONE_NULL = -1, // default zone
ZONE_SKELLY = 0,
ZONE_BASIC,
ZONE_FLYER,
ZONE_HUMAN_CLASSIC,
ZONE_VON_CROY,
ZONE_WATER,
ZONE_MAX,
/// custom zone (using zone above for LOT.zone):
ZONE_HUMAN_JUMP_AND_MONKEY,
ZONE_HUMAN_JUMP,
ZONE_SPIDER,
ZONE_BLOCKABLE, // for trex, shiva, etc..
ZONE_SOPHIALEE, // dont want sophia to go down again !
ZONE_APE, // only 2 click climb
ZONE_HUMAN_LONGJUMP_AND_MONKEY,
};
struct OBJECT_BONES
{
@ -86,13 +62,7 @@ struct OBJECT_BONES
}
};
struct BOX_NODE
{
int exitBox;
int searchNumber;
int nextExpansion;
int boxNumber;
};
struct AI_INFO
{
@ -147,49 +117,7 @@ struct BITE_INFO
}
};
struct LOT_INFO
{
std::vector<BOX_NODE> node;
int head;
int tail;
int searchNumber;
int blockMask;
short step;
short drop;
short zoneCount;
int targetBox;
int requiredBox;
short fly;
bool canJump;
bool canMonkey;
bool isAmphibious;
bool isJumping;
bool isMonkeying;
PHD_VECTOR target;
ZoneType zone;
};
struct CREATURE_INFO
{
short jointRotation[4];
short maximumTurn;
short flags;
bool alerted;
bool headLeft;
bool headRight;
bool reachedGoal;
bool hurtByLara;
bool patrol2;
bool jumpAhead;
bool monkeyAhead;
MOOD_TYPE mood;
ITEM_INFO* enemy;
ITEM_INFO aiTarget;
short pad;
short itemNum;
PHD_VECTOR target;
LOT_INFO LOT;
};
struct EntityStoringInfo
{
@ -231,7 +159,7 @@ struct EntityStoringInfo
};
#define CreatureEffectFunction short(int x, int y, int z, short speed, short yRot, short roomNumber)
#define XZ_GET_SECTOR(room, x, z) (room->floor[(z) / SECTOR(1) + (x) / SECTOR(1) * room->xSize])
//#define XZ_GET_SECTOR(room, x, z) (room->floor[(z) / SECTOR(1) + (x) / SECTOR(1) * room->xSize])
constexpr auto UNIT_SHADOW = 256;
constexpr auto NO_SHADOW = 0;
@ -314,5 +242,6 @@ void CreatureAIInfo(ITEM_INFO* item, AI_INFO* info);
TARGET_TYPE CalculateTarget(PHD_VECTOR* target, ITEM_INFO* item, LOT_INFO* LOT);
int CreatureAnimation(short itemNumber, short angle, short tilt);
void AdjustStopperFlag(ITEM_INFO* item, int dir, int set);
//(room->floor[ + * room->xSize])
FLOOR_INFO* XZ_GET_SECTOR(ROOM_INFO* r, int x, int z);

View file

@ -37,6 +37,8 @@
#include "rubberboat.h"
#include <Game\misc.h>
#include <control\volume.h>
#include "Renderer11.h"
#include "camera.h"
#ifdef NEW_INV
#include "newinv2.h"

View file

@ -1,6 +1,7 @@
#pragma once
#include "lara_struct.h"
struct ITEM_INFO;
struct COLL_INFO;
#define FRONT_ARC ANGLE(90.0f)
#define LARA_LEAN_RATE ANGLE(1.5f)
#define LARA_LEAN_MAX ANGLE(11.0f)

View file

@ -10,6 +10,9 @@
#include "Sound\sound.h"
#include "draw.h"
#include "pickup\pickup.h"
#include "collide.h"
#include "item.h"
#include "camera.h"
bool DoJump = false;

View file

@ -1,6 +1,6 @@
#pragma once
#include "lara_struct.h"
struct ITEM_INFO;
struct COLL_INFO;
/*generic functions*/
void lara_void_func(ITEM_INFO* item, COLL_INFO* coll);
void lara_default_col(ITEM_INFO* item, COLL_INFO* coll);

View file

@ -8,7 +8,10 @@
#endif
#include "effects\effects.h"
#include "Sound\sound.h"
#include "collide.h"
#include "item.h"
#include "setup.h"
#include "level.h"
extern GameFlow* g_GameFlow;
int NoCheatCounter;

View file

@ -1,5 +1,6 @@
#pragma once
struct ITEM_INFO;
struct COLL_INFO;
void lara_as_swimcheat(ITEM_INFO* item, COLL_INFO* coll);
void LaraCheatyBits();

View file

@ -3,8 +3,8 @@
#include "input.h"
#include "draw.h"
#include "effects\effects.h"
#include "collide.h"
#include "control.h"
/*this file has all the generic **collision** test functions called in lara's state code*/
int LaraDeflectEdge(ITEM_INFO* item, COLL_INFO* coll)

View file

@ -1,6 +1,6 @@
#pragma once
#include "lara_struct.h"
struct ITEM_INFO;
struct COLL_INFO;
int LaraDeflectEdge(ITEM_INFO* item, COLL_INFO* coll);
void LaraDeflectEdgeJump(ITEM_INFO* item, COLL_INFO* coll);
int LaraDeflectEdgeDuck(ITEM_INFO* item, COLL_INFO* coll);

View file

@ -7,7 +7,10 @@
#include "draw.h"
#include "control.h"
#include <Game/Lara/lara_flare.h>
#include "collide.h"
#include "item.h"
#include "camera.h"
#include "control.h"
/*this file has all the related functions to ducking and crawling*/
/*crouch/duck start*/

View file

@ -18,7 +18,7 @@
#include "savegame.h"
#include "GameFlowScript.h"
#include "lara_struct.h"
#include "creature_info.h"
WEAPON_INFO Weapons[NUM_WEAPONS] =
{
/* No weapons */
@ -1006,11 +1006,11 @@ void LaraGetNewTarget(WEAPON_INFO* weapon)
maxDistance = weapon->targetDist;
targets = 0;
for (slot = 0; slot < NUM_SLOTS; ++slot)
for (slot = 0; slot < ActiveCreatures.size(); ++slot)
{
if (BaddieSlots[slot].itemNum != NO_ITEM)
if (ActiveCreatures[slot]->itemNum != NO_ITEM)
{
item = &g_Level.Items[BaddieSlots[slot].itemNum];
item = &g_Level.Items[ActiveCreatures[slot]->itemNum];
if (item->hitPoints > 0)
{
x = item->pos.xPos - src.x;

View file

@ -1,6 +1,7 @@
#pragma once
#include "lara.h"
struct ITEM_INFO;
struct COLL_INFO;
enum FireWeaponType
{
FW_MISS = -1,

View file

@ -63,7 +63,8 @@ void FlareControl(short itemNumber)
DoProjectileDynamics(itemNumber, oldX, oldY, oldZ, xv, item->fallspeed, zv);
short age = (short)(item->data) & 0x7FFF;
short& age = item->data;
age &= 0x7FFF;
if (age >= FLARE_AGE)
{
if (!item->fallspeed && !item->speed)
@ -84,8 +85,6 @@ void FlareControl(short itemNumber)
age |= 0x8000;
}
item->data = (void*)age;
}
void ready_flare()
@ -362,10 +361,12 @@ void CreateFlare(GAME_OBJECT_ID objectNum, int thrown)
if (objectNum == ID_FLARE_ITEM)
{
item->data = (short)0;
short& age = item->data;
if (DoFlareLight((PHD_VECTOR*)&item->pos, Lara.flareAge))
item->data = (void*)(Lara.flareAge | 0x8000);
age = (Lara.flareAge | 0x8000);
else
item->data = (void*)(Lara.flareAge & 0x7FFF);
age = (Lara.flareAge & 0x7FFF);
}
else
{

View file

@ -1,6 +1,8 @@
#pragma once
#include "items.h"
struct ITEM_INFO;
struct COLL_INFO;
struct PHD_VECTOR;
enum GAME_OBJECT_ID : short;
#define FLARE_AGE 30*30 //30 seconds * 30 frames

View file

@ -2,7 +2,10 @@
#include "lara.h"
#include "input.h"
#include "lara_tests.h"
#include "item.h"
#include "collide.h"
#include "camera.h"
#include "level.h"
/*this file has all the lara_as/lara_col functions related to hanging*/
/*normal hanging and shimmying*/

View file

@ -0,0 +1 @@
#pragma once

View file

@ -2,7 +2,10 @@
#include "lara.h"
#include "lara_initialise.h"
#include "health.h"
#include "item.h"
#include "items.h"
#include "setup.h"
#include "level.h"
void InitialiseLara(int restore)
{
if (Lara.itemNumber == NO_ITEM)
@ -10,7 +13,7 @@ void InitialiseLara(int restore)
short itemNumber = Lara.itemNumber;
LaraItem->data = &Lara;
//LaraItem->data = &Lara;
LaraItem->collidable = false;
LaraItem->location.roomNumber = LaraItem->roomNumber;
LaraItem->location.yNumber = LaraItem->pos.yPos;

View file

@ -5,7 +5,12 @@
#include "lara_collide.h"
#include "lara_tests.h"
#include "lara_monkey.h"
#include "floordata.h"
#include "collide.h"
#include "item.h"
#include "camera.h"
#include "control.h"
#include "level.h"
using namespace TEN::Floordata;
/*this file has all the related functions to monkeyswinging*/

View file

@ -1,6 +1,6 @@
#pragma once
#include "lara_struct.h"
struct ITEM_INFO;
struct COLL_INFO;
/*monkeyswing state handling functions*/
void lara_as_hang2(ITEM_INFO* item, COLL_INFO* coll);
void lara_col_hang2(ITEM_INFO* item, COLL_INFO* coll);

View file

@ -7,8 +7,9 @@
#include "lara_tests.h"
#include "camera.h"
#include "collide.h"
#include "item.h"
#include "control.h"
#include "Specific\prng.h"
/*This file has "all" lara_as/lara_col functions where Lara is interacting with an object.*/
/*pickups*/

View file

@ -1,7 +1,7 @@
#pragma once
#include "items.h"
#include "Specific\trmath.h"
struct ITEM_INFO;
enum GRENADE_TYPE
{
GRENADE_NORMAL,

View file

@ -3,6 +3,9 @@
#include "lara_collide.h"
#include "input.h"
#include "Sound\sound.h"
#include "collide.h"
#include "camera.h"
#include "level.h"
short OldAngle = 1;

View file

@ -1,5 +1,7 @@
#pragma once
#include "lara_struct.h"
struct ITEM_INFO;
struct COLL_INFO;
/*Tests and others*/
int TestLaraSlide(ITEM_INFO* item, COLL_INFO* coll);

View file

@ -1,10 +1,6 @@
#pragma once
#include "box.h"
#include "collide.h"
#include "effects\effects.h"
#include "objectslist.h"
#include "Specific\trmath.h"
#include "Renderer11.h"
#define NUM_PUZZLES (ID_PUZZLE_ITEM16 - ID_PUZZLE_ITEM1 + 1)
#define NUM_PUZZLE_PIECES (ID_PUZZLE_ITEM16_COMBO2 - ID_PUZZLE_ITEM1_COMBO1 + 1)
@ -15,6 +11,15 @@
#define NUM_EXAMINES (ID_EXAMINE8 - ID_EXAMINE1 + 1)
#define NUM_EXAMINES_PIECES (ID_EXAMINE8_COMBO2 - ID_EXAMINE1_COMBO1 + 1)
struct CREATURE_INFO;
struct ITEM_INFO;
struct FX_INFO;
namespace TEN::Renderer {
struct RendererMesh;
}
#pragma region state_and_animation
enum LARA_STATE
{
@ -965,7 +970,7 @@ struct LARA_ARM
struct AnimsNew
{
bool CrouchRoll; //crouch roll
bool Monkey180Roll; //the 180° roll on monkeybars
bool Monkey180Roll; //the 180<EFBFBD> roll on monkeybars
bool Crawl1clickup; //going 1 click up in crawlspaces
bool Crawl1clickdown; //going 1 click down in crawlspaces
bool CrawlExit1click; //crawlspace exit at 1 click
@ -1110,4 +1115,4 @@ struct LaraInfo
int NumSmallMedipacks;
int NumLargeMedipacks;
int NumFlares;
};
};

View file

@ -1,8 +1,8 @@
#pragma once
#include "Lara.h"
struct ITEM_INFO;
struct COLL_INFO;
void _cdecl lara_col_surftread(ITEM_INFO* item, COLL_INFO* coll);
void _cdecl lara_col_surfright(ITEM_INFO* item, COLL_INFO* coll);
void _cdecl lara_col_surfleft(ITEM_INFO* item, COLL_INFO* coll);

View file

@ -160,7 +160,7 @@ int GetWaterDepth(int x, int y, int z, short roomNumber)
floor = GetFloor(x, y, z, &roomNumber);
return (GetFloorHeight(floor, x, y, z) - wh);
}
floor = &XZ_GET_SECTOR(r, x - r->x, z - r->z);
floor = XZ_GET_SECTOR(r, x - r->x, z - r->z);
}
return 0x7FFF;
}
@ -175,7 +175,7 @@ int GetWaterDepth(int x, int y, int z, short roomNumber)
floor = GetFloor(x, y, z, &roomNumber);
return (GetFloorHeight(floor, x, y, z) - wh);
}
floor = &XZ_GET_SECTOR(r, x - r->x, z - r->z);
floor = XZ_GET_SECTOR(r, x - r->x, z - r->z);
}
return NO_HEIGHT;
}

View file

@ -6,6 +6,7 @@
#include "control.h"
#include "lara_climb.h"
#include "lara_collide.h"
#include "control.h"
using namespace TEN::Floordata;

View file

@ -1,6 +1,8 @@
#pragma once
#include "lara_struct.h"
#include "collide.h"
struct ITEM_INFO;
struct COLL_INFO;
int TestLaraVault(ITEM_INFO* item, COLL_INFO* coll);
bool TestLaraStandUp(COLL_INFO* coll);
int TestWall(ITEM_INFO* item, int front, int right, int down);

View file

@ -11,7 +11,7 @@
#include "setup.h"
#include "Specific\trmath.h"
#include "objectslist.h"
#include "creature_info.h"
#define CHECK_CLICK(x) CLICK(x) / 2
#define ESCAPE_DIST SECTOR(5)
#define STALK_DIST SECTOR(3)
@ -22,7 +22,15 @@
#define BIFF_AVOID_TURN 1536
#define FEELER_DISTANCE 512
#define FEELER_ANGLE ANGLE(45.0f)
#ifdef CREATURE_AI_PRIORITY_OPTIMIZATION
constexpr int HIGH_PRIO_RANGE = 8;
constexpr int MEDIUM_PRIO_RANGE = HIGH_PRIO_RANGE + HIGH_PRIO_RANGE * (HIGH_PRIO_RANGE / 6.0f);
constexpr int LOW_PRIO_RANGE = MEDIUM_PRIO_RANGE + MEDIUM_PRIO_RANGE * (MEDIUM_PRIO_RANGE / 24.0f);
constexpr int NONE_PRIO_RANGE = LOW_PRIO_RANGE + LOW_PRIO_RANGE * (LOW_PRIO_RANGE / 32.0f);
constexpr auto FRAME_PRIO_BASE = 4;
constexpr auto FRAME_PRIO_EXP = 1.5;
#endif // CREATURE_AI_PRIORITY_OPTIMIZATION
void DropBaddyPickups(ITEM_INFO* item)
{
ITEM_INFO* pickup = NULL;
@ -109,13 +117,13 @@ bool SameZone(CREATURE_INFO* creature, ITEM_INFO* target)
int* zone = g_Level.Zones[creature->LOT.zone][FlipStatus].data();
ITEM_INFO* item = &g_Level.Items[creature->itemNum];
ROOM_INFO* room = &g_Level.Rooms[item->roomNumber];
FLOOR_INFO* floor = &XZ_GET_SECTOR(room, item->pos.xPos - room->x, item->pos.zPos - room->z);
FLOOR_INFO* floor = XZ_GET_SECTOR(room, item->pos.xPos - room->x, item->pos.zPos - room->z);
if (floor->box == NO_BOX)
return false;
item->boxNumber = floor->box;
room = &g_Level.Rooms[target->roomNumber];
floor = &XZ_GET_SECTOR(room, target->pos.xPos - room->x, target->pos.zPos - room->z);
floor = XZ_GET_SECTOR(room, target->pos.xPos - room->x, target->pos.zPos - room->z);
if (floor->box == NO_BOX)
return false;
target->boxNumber = floor->box;
@ -166,9 +174,9 @@ void AlertNearbyGuards(ITEM_INFO* item)
int x, y, z;
int distance;
for (int i = 0; i < NUM_SLOTS; i++)
for (int i = 0; i < ActiveCreatures.size(); i++)
{
creature = &BaddieSlots[i];
creature = ActiveCreatures[i];
if (creature->itemNum == NO_ITEM)
continue;
@ -195,9 +203,9 @@ void AlertAllGuards(short itemNumber)
CREATURE_INFO* creature;
short objNumber;
for (int i = 0; i < NUM_SLOTS; i++)
for (int i = 0; i < ActiveCreatures.size(); i++)
{
creature = &BaddieSlots[i];
creature = ActiveCreatures[i];
if (creature->itemNum == NO_ITEM)
continue;
@ -364,7 +372,7 @@ void CreatureFloat(short itemNumber)
void CreatureJoint(ITEM_INFO* item, short joint, short required)
{
if (item->data == NULL)
if (!item->data)
return;
CREATURE_INFO* creature = (CREATURE_INFO*)item->data;
@ -403,7 +411,7 @@ void CreatureTilt(ITEM_INFO* item, short angle)
short CreatureTurn(ITEM_INFO* item, short maximumTurn)
{
if (item->data == NULL || maximumTurn == 0)
if (!item->data || maximumTurn == 0)
return 0;
CREATURE_INFO* creature;
@ -446,7 +454,7 @@ int CreatureAnimation(short itemNumber, short angle, short tilt)
int boxHeight, height, nextHeight, nextBox;
item = &g_Level.Items[itemNumber];
if (item->data == NULL)
if (!item->data)
return false;
creature = (CREATURE_INFO*)item->data;
@ -1074,7 +1082,23 @@ int SearchLOT(LOT_INFO* LOT, int depth)
return true;
}
int CreatureActive(short itemNumber)
#if CREATURE_AI_PRIORITY_OPTIMIZATION
CREATURE_AI_PRIORITY GetCreatureLOTPriority(ITEM_INFO* item) {
Vector3 itemPos = Vector3(item->pos.xPos, item->pos.yPos, item->pos.zPos);
Vector3 cameraPos = Vector3(Camera.pos.x, Camera.pos.y, Camera.pos.z);
float distance = Vector3::Distance(itemPos, cameraPos);
distance /= SECTOR(1);
if(distance <= HIGH_PRIO_RANGE)
return CREATURE_AI_PRIORITY::HIGH;
if(distance <= MEDIUM_PRIO_RANGE)
return CREATURE_AI_PRIORITY::MEDIUM;
if(distance <= LOW_PRIO_RANGE)
return CREATURE_AI_PRIORITY::LOW;
return CREATURE_AI_PRIORITY::NONE;
}
#endif
int CreatureActive(short itemNumber)
{
ITEM_INFO* item = &g_Level.Items[itemNumber];
@ -1091,6 +1115,10 @@ int CreatureActive(short itemNumber)
}
item->status = ITEM_ACTIVE;
}
#ifdef CREATURE_AI_PRIORITY_OPTIMIZATION
CREATURE_INFO* creature = (CREATURE_INFO*)item->data;
creature->priority = GetCreatureLOTPriority(item);
#endif // CREATURE_AI_PRIORITY_OPTIMIZATION
return true;
}
@ -1395,10 +1423,10 @@ void FindAITargetObject(CREATURE_INFO* creature, short objectNumber)
int* zone = g_Level.Zones[creature->LOT.zone][FlipStatus].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;
item->boxNumber = XZ_GET_SECTOR(r, item->pos.xPos - r->x, item->pos.zPos - r->z)->box;
r = &g_Level.Rooms[aiObject->roomNumber];
aiObject->boxNumber = XZ_GET_SECTOR(r, aiObject->x - r->x, aiObject->z - r->z).box;
aiObject->boxNumber = XZ_GET_SECTOR(r, aiObject->x - r->x, aiObject->z - r->z)->box;
if (item->boxNumber == NO_BOX || aiObject->boxNumber == NO_BOX)
{
@ -1415,9 +1443,9 @@ void FindAITargetObject(CREATURE_INFO* creature, short objectNumber)
if (foundObject != NULL)
{
ITEM_INFO* aiItem = &creature->aiTarget;
CREATURE_TARGET* aiItem = &creature->aiTarget;
creature->enemy = aiItem;
creature->enemy = nullptr;
aiItem->objectNumber = foundObject->objectNumber;
aiItem->roomNumber = foundObject->roomNumber;
@ -1440,7 +1468,7 @@ void FindAITargetObject(CREATURE_INFO* creature, short objectNumber)
void CreatureAIInfo(ITEM_INFO* item, AI_INFO* info)
{
if (item->data == NULL)
if (!item->data)
return;
CREATURE_INFO * creature;
@ -1464,14 +1492,20 @@ void CreatureAIInfo(ITEM_INFO* item, AI_INFO* info)
zone = g_Level.Zones[creature->LOT.zone][FlipStatus].data();
r = &g_Level.Rooms[item->roomNumber];
item->boxNumber = XZ_GET_SECTOR(r, item->pos.xPos - r->x, item->pos.zPos - r->z).box;
item->boxNumber = NO_BOX;
FLOOR_INFO* floor = XZ_GET_SECTOR(r, item->pos.xPos - r->x, item->pos.zPos - r->z);
if(floor)
item->boxNumber = floor->box;
if (item->boxNumber != NO_BOX)
info->zoneNumber = zone[item->boxNumber];
else
info->zoneNumber = NO_ZONE;
r = &g_Level.Rooms[enemy->roomNumber];
enemy->boxNumber = XZ_GET_SECTOR(r, enemy->pos.xPos - r->x, enemy->pos.zPos - r->z).box;
enemy->boxNumber = NO_BOX;
floor = XZ_GET_SECTOR(r, enemy->pos.xPos - r->x, enemy->pos.zPos - r->z);
if(floor)
enemy->boxNumber = floor->box;
if (enemy->boxNumber != NO_BOX)
info->enemyZone = zone[enemy->boxNumber];
else
@ -1543,7 +1577,7 @@ void CreatureAIInfo(ITEM_INFO* item, AI_INFO* info)
void CreatureMood(ITEM_INFO* item, AI_INFO* info, int violent)
{
if (item->data == NULL)
if (!item->data)
return;
CREATURE_INFO* creature;
@ -1627,8 +1661,37 @@ void CreatureMood(ITEM_INFO* item, AI_INFO* info, int violent)
if (LOT->targetBox == NO_BOX)
TargetBox(LOT, item->boxNumber);
#ifdef CREATURE_AI_PRIORITY_OPTIMIZATION
bool shouldUpdateTarget = false;
switch(creature->priority) {
case CREATURE_AI_PRIORITY::HIGH:
shouldUpdateTarget = true;
break;
case CREATURE_AI_PRIORITY::MEDIUM:
{
if(creature->framesSinceLOTUpdate > std::pow(FRAME_PRIO_BASE, FRAME_PRIO_EXP))
shouldUpdateTarget = true;
}
break;
case CREATURE_AI_PRIORITY::LOW:
{
if(creature->framesSinceLOTUpdate > std::pow(FRAME_PRIO_BASE,FRAME_PRIO_EXP*2))
shouldUpdateTarget = true;
}
break;
default:
break;
}
if(shouldUpdateTarget) {
CalculateTarget(&creature->target, item, &creature->LOT);
creature->framesSinceLOTUpdate = 0;
} else {
creature->framesSinceLOTUpdate++;
}
#else
CalculateTarget(&creature->target, item, &creature->LOT);
#endif // CREATURE_AI_PRIORITY_OPTIMIZATION
creature->jumpAhead = false;
creature->monkeyAhead = false;
@ -1663,7 +1726,7 @@ void CreatureMood(ITEM_INFO* item, AI_INFO* info, int violent)
void GetCreatureMood(ITEM_INFO* item, AI_INFO* info, int isViolent)
{
if (item->data == NULL)
if (!item->data)
return;
CREATURE_INFO* creature;
@ -2009,7 +2072,7 @@ void AdjustStopperFlag(ITEM_INFO* item, int dir, int set)
ROOM_INFO* r = &g_Level.Rooms[item->roomNumber];
FLOOR_INFO* floor = &XZ_GET_SECTOR(r, x - r->x, z - r->z);
FLOOR_INFO* floor = XZ_GET_SECTOR(r, x - r->x, z - r->z);
floor->stopper = set;
x = item->pos.xPos + 1024 * phd_sin(dir);
@ -2019,6 +2082,16 @@ void AdjustStopperFlag(ITEM_INFO* item, int dir, int set)
GetFloor(x, item->pos.yPos, z, &roomNumber);
r = &g_Level.Rooms[roomNumber];
floor = &XZ_GET_SECTOR(r, x - r->x, z - r->z);
floor = XZ_GET_SECTOR(r, x - r->x, z - r->z);
floor->stopper = set;
}
}
FLOOR_INFO* XZ_GET_SECTOR(ROOM_INFO* r, int x, int z) {
int sectorX = (x) / SECTOR(1);
int sectorZ = (z) / SECTOR(1);
int index = sectorZ + sectorX * r->xSize;
if(index > r->floor.size()) {
return nullptr;
}
return &r->floor[index];
}

View file

@ -12,6 +12,7 @@
#include "Specific\trmath.h"
#include "Specific\prng.h"
#include "room.h"
#include "Renderer11.h""
using std::vector;
using namespace TEN::Math::Random;
@ -1251,7 +1252,7 @@ COLL_RESULT GetCollisionResult(FLOOR_INFO* floor, int x, int y, int z)
if (CheckNoColFloorTriangle(floor, x, z) == 1)
break;
r = &g_Level.Rooms[floor->pitRoom];
floor = &XZ_GET_SECTOR(r, x - r->x, z - r->z);
floor = XZ_GET_SECTOR(r, x - r->x, z - r->z);
}
// Return probed bottom block into result.

View file

@ -1,6 +1,10 @@
#pragma once
#include "Specific\phd_global.h"
#include "level.h"
#include "trmath.h"
struct ITEM_INFO;
struct COLL_INFO;
struct FLOOR_INFO;
struct MESH_INFO;
// used by coll->Setup.BadHeightUp
#define NO_BAD_POS (-NO_HEIGHT)

View file

@ -52,7 +52,7 @@
#include <Game/Lara/lara_one_gun.h>
#include <Game/Lara/lara_climb.h>
#include "generic_switch.h"
#include "creature_info.h"
using namespace TEN::Entities::Switches;
using std::vector;
@ -562,9 +562,6 @@ unsigned CALLBACK GameMain(void *)
{
try {
printf("GameMain\n");
// Initialise legacy memory buffer and game timer
init_game_malloc();
TIME_Init();
if (g_GameFlow->IntroImagePath.empty())
{
@ -906,7 +903,7 @@ void TranslateItem(ITEM_INFO *item, int x, int y, int z)
int GetWaterSurface(int x, int y, int z, short roomNumber)
{
ROOM_INFO *room = &g_Level.Rooms[roomNumber];
FLOOR_INFO *floor = &XZ_GET_SECTOR(room, x - room->x, z - room->z);
FLOOR_INFO *floor = XZ_GET_SECTOR(room, x - room->x, z - room->z);
if (room->flags & ENV_FLAG_WATER)
{
@ -915,7 +912,7 @@ int GetWaterSurface(int x, int y, int z, short roomNumber)
room = &g_Level.Rooms[floor->skyRoom];
if (!(room->flags & ENV_FLAG_WATER))
return (floor->ceiling << 8);
floor = &XZ_GET_SECTOR(room, x - room->x, z - room->z);
floor = XZ_GET_SECTOR(room, x - room->x, z - room->z);
}
return NO_HEIGHT;
}
@ -926,7 +923,7 @@ int GetWaterSurface(int x, int y, int z, short roomNumber)
room = &g_Level.Rooms[floor->pitRoom];
if (room->flags & ENV_FLAG_WATER)
return (floor->floor << 8);
floor = &XZ_GET_SECTOR(room, x - room->x, z - room->z);
floor = XZ_GET_SECTOR(room, x - room->x, z - room->z);
}
}
@ -2406,9 +2403,9 @@ void DoFlipMap(short group)
FlipStats[group] = status;
FlipStatus = status;
for (int i = 0; i < NUM_SLOTS; i++)
for (int i = 0; i < ActiveCreatures.size(); i++)
{
BaddieSlots[i].LOT.targetBox = NO_BOX;
ActiveCreatures[i]->LOT.targetBox = NO_BOX;
}
}
@ -2613,7 +2610,7 @@ int GetWaterHeight(int x, int y, int z, short roomNumber)
r = &g_Level.Rooms[floor->skyRoom];
if (!(r->flags & (ENV_FLAG_WATER | ENV_FLAG_SWAMP)))
return r->minfloor;
floor = &XZ_GET_SECTOR(r, x - r->x, z - r->z);
floor = XZ_GET_SECTOR(r, x - r->x, z - r->z);
if (floor->skyRoom == NO_ROOM)
break;
}
@ -2629,7 +2626,7 @@ int GetWaterHeight(int x, int y, int z, short roomNumber)
r = &g_Level.Rooms[floor->pitRoom];
if (r->flags & (ENV_FLAG_WATER | ENV_FLAG_SWAMP))
return r->maxceiling;
floor = &XZ_GET_SECTOR(r, x - r->x, z - r->z);
floor = XZ_GET_SECTOR(r, x - r->x, z - r->z);
if (floor->pitRoom == NO_ROOM)
break;
}

View file

@ -6,7 +6,12 @@
#include "control\trigger.h"
struct BOUNDING_BOX;
struct ITEM_INFO;
struct COLL_INFO;
class FLOOR_INFO;
struct ANIM_STRUCT;
struct MESH_INFO;
struct ROOM_INFO;
enum GAME_STATUS
{
GAME_STATUS_NONE,
@ -144,4 +149,4 @@ void InterpolateAngle(short angle, short* rotation, short* outAngle, int shift);
int IsRoomOutside(int x, int y, int z);
void ResetGlobals();
unsigned CALLBACK GameMain(void*);
unsigned CALLBACK GameMain(void*);

View file

@ -163,7 +163,7 @@ short* GetTriggerIndex(FLOOR_INFO* floor, int x, int y, int z)
if (CheckNoColFloorTriangle(floor, x, z) == 1)
break;
r = &g_Level.Rooms[floor->pitRoom];
floor = &XZ_GET_SECTOR(r, x - r->x, z - r->z);
floor = XZ_GET_SECTOR(r, x - r->x, z - r->z);
}
if ((floor->floor * 256) == NO_HEIGHT || floor->index == 0)

View file

@ -1,7 +1,7 @@
#pragma once
#include "items.h"
#include "control.h"
struct ITEM_INFO;
struct FLOOR_INFO;
int GetKeyTrigger(ITEM_INFO* item);
int GetSwitchTrigger(ITEM_INFO* item, short* itemNos, int AttatchedToSwitch);

View file

@ -0,0 +1,98 @@
#pragma once
#include "phd_global.h"
#include <vector>
struct BOX_NODE {
int exitBox;
int searchNumber;
int nextExpansion;
int boxNumber;
};
enum ZoneType : char {
ZONE_NULL = -1, // default zone
ZONE_SKELLY = 0,
ZONE_BASIC,
ZONE_FLYER,
ZONE_HUMAN_CLASSIC,
ZONE_VON_CROY,
ZONE_WATER,
ZONE_MAX,
/// custom zone (using zone above for LOT.zone):
ZONE_HUMAN_JUMP_AND_MONKEY,
ZONE_HUMAN_JUMP,
ZONE_SPIDER,
ZONE_BLOCKABLE, // for trex, shiva, etc..
ZONE_SOPHIALEE, // dont want sophia to go down again !
ZONE_APE, // only 2 click climb
ZONE_HUMAN_LONGJUMP_AND_MONKEY,
};
struct LOT_INFO {
std::vector<BOX_NODE> node;
int head;
int tail;
int searchNumber;
int blockMask;
short step;
short drop;
short zoneCount;
int targetBox;
int requiredBox;
short fly;
bool canJump;
bool canMonkey;
bool isAmphibious;
bool isJumping;
bool isMonkeying;
PHD_VECTOR target;
ZoneType zone;
bool initialised;
};
enum MOOD_TYPE {
BORED_MOOD,
ATTACK_MOOD,
ESCAPE_MOOD,
STALK_MOOD
};
struct CREATURE_TARGET {
GAME_OBJECT_ID objectNumber;
int boxNumber;
PHD_3DPOS pos;
uint16_t flags; // ItemFlags enum
uint16_t triggerFlags;
short roomNumber;
};
enum class CREATURE_AI_PRIORITY {
HIGH,
MEDIUM,
LOW,
NONE
};
struct CREATURE_INFO {
short jointRotation[4];
short maximumTurn;
short flags;
bool alerted;
bool headLeft;
bool headRight;
bool reachedGoal;
bool hurtByLara;
bool patrol2;
bool jumpAhead;
bool monkeyAhead;
MOOD_TYPE mood;
ITEM_INFO* enemy;
CREATURE_TARGET aiTarget;
short pad;
short itemNum;
PHD_VECTOR target;
LOT_INFO LOT;
#ifdef CREATURE_AI_PRIORITY_OPTIMIZATION
CREATURE_AI_PRIORITY priority;
size_t framesSinceLOTUpdate;
#endif
};

View file

@ -21,7 +21,8 @@
#include "generic_switch.h"
#include "pickup\pickup.h"
#include "fullblock_switch.h"
#include "creature_info.h"
#include "door_data.h"
using namespace TEN::Entities::Switches;
PHD_VECTOR DoubleDoorPos(0, 0, 220);
@ -583,7 +584,7 @@ void OpenThatDoor(DOORPOS_DATA* doorPos, DOOR_DATA* dd)
if (floor != NULL)
{
memcpy(doorPos->floor, &doorPos->data, sizeof(FLOOR_INFO));
*doorPos->floor = doorPos->data;
short boxIndex = doorPos->block;
if (boxIndex != NO_BOX)
@ -591,9 +592,9 @@ void OpenThatDoor(DOORPOS_DATA* doorPos, DOOR_DATA* dd)
if (!DontUnlockBox)
g_Level.Boxes[boxIndex].flags &= ~BLOCKED;
for (int i = 0; i < NUM_SLOTS; i++)
for (int i = 0; i < ActiveCreatures.size(); i++)
{
BaddieSlots[i].LOT.targetBox = NO_BOX;
ActiveCreatures[i]->LOT.targetBox = NO_BOX;
}
}
}
@ -681,9 +682,9 @@ void ShutThatDoor(DOORPOS_DATA* doorPos, DOOR_DATA* dd)
if (boxIndex != NO_BOX)
{
g_Level.Boxes[boxIndex].flags |= BLOCKED;
for (int i = 0; i < NUM_SLOTS; i++)
for (int i = 0; i < ActiveCreatures.size(); i++)
{
BaddieSlots[i].LOT.targetBox = NO_BOX;
ActiveCreatures[i]->LOT.targetBox = NO_BOX;
}
}
}
@ -723,15 +724,14 @@ void InitialiseDoor(short itemNumber)
if (item->objectNumber == ID_LIFT_DOORS1 || item->objectNumber == ID_LIFT_DOORS2)
item->itemFlags[0] = 4096;
item->data = DOOR_DATA();
DOOR_DATA* door = item->data;
DOOR_DATA * door = game_malloc<DOOR_DATA>();
item->data = door;
door->opened = false;
door->dptr1 = NULL;
door->dptr2 = NULL;
door->dptr3 = NULL;
door->dptr4 = NULL;
door->dptr1 = nullptr;
door->dptr2 = nullptr;
door->dptr3 = nullptr;
door->dptr4 = nullptr;
int dz, dx;
ROOM_INFO* r;
@ -761,8 +761,7 @@ void InitialiseDoor(short itemNumber)
boxNumber = b->floor[(item->pos.zPos - b->z) / SECTOR(1) + dz + ((item->pos.xPos - b->x) / SECTOR(1) + dx) * b->xSize].box;
}
door->d1.block = (boxNumber != NO_BOX && g_Level.Boxes[boxNumber].flags & BLOCKABLE) ? boxNumber : NO_BOX;
memcpy(&door->d1.data, door->d1.floor, sizeof(FLOOR_INFO));
door->d1.data = *door->d1.floor;
if (r->flippedRoom != -1)
{
@ -779,7 +778,7 @@ void InitialiseDoor(short itemNumber)
}
door->d1flip.block = (boxNumber != NO_BOX && g_Level.Boxes[boxNumber].flags & BLOCKABLE) ? boxNumber : NO_BOX;
memcpy(&door->d1flip.data, door->d1flip.floor, sizeof(FLOOR_INFO));
door->d1flip.data = *door->d1flip.floor;
}
else
door->d1flip.floor = NULL;
@ -809,7 +808,7 @@ void InitialiseDoor(short itemNumber)
}
door->d2.block = (boxNumber != NO_BOX && g_Level.Boxes[boxNumber].flags & BLOCKABLE) ? boxNumber : NO_BOX;
memcpy(&door->d2.data, door->d2.floor, sizeof(FLOOR_INFO));
door->d2.data = *door->d2.floor;
if (r->flippedRoom != -1)
{
@ -826,7 +825,7 @@ void InitialiseDoor(short itemNumber)
}
door->d2flip.block = (boxNumber != NO_BOX && g_Level.Boxes[boxNumber].flags & BLOCKABLE) ? boxNumber : NO_BOX;
memcpy(&door->d2flip.data, door->d2flip.floor, sizeof(FLOOR_INFO));
door->d2flip.data = *door->d2flip.floor;
}
else
door->d2flip.floor = NULL;

View file

@ -1,32 +1,10 @@
#pragma once
#include "items.h"
#include "collide.h"
#include "room.h"
struct COLL_INFO;
struct ITEM_INFO;
struct ROOM_INFO;
struct DOORPOS_DATA;
struct DOOR_DATA;
struct DOORPOS_DATA
{
FLOOR_INFO* floor;
FLOOR_INFO data;
short block;
};
struct DOOR_DATA
{
DOORPOS_DATA d1;
DOORPOS_DATA d1flip;
DOORPOS_DATA d2;
DOORPOS_DATA d2flip;
short opened;
short* dptr1;
short* dptr2;
short* dptr3;
short* dptr4;
byte dn1;
byte dn2;
byte dn3;
byte dn4;
ITEM_INFO* item;
};
void SequenceDoorControl(short itemNumber);
void UnderwaterDoorCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll);

25
TR5Main/Game/door_data.h Normal file
View file

@ -0,0 +1,25 @@
#pragma once
#include "floordata.h"
struct ITEM_INFO;
struct DOORPOS_DATA {
FLOOR_INFO* floor;
FLOOR_INFO data;
short block;
};
struct DOOR_DATA {
DOORPOS_DATA d1;
DOORPOS_DATA d1flip;
DOORPOS_DATA d2;
DOORPOS_DATA d2flip;
short opened;
short* dptr1;
short* dptr2;
short* dptr3;
short* dptr4;
unsigned char dn1;
unsigned char dn2;
unsigned char dn3;
unsigned char dn4;
ITEM_INFO* item;
};

View file

@ -1,5 +1,9 @@
#pragma once
#include "box.h"
#include "Box.h"
struct PHD_3DPOS;
struct PHD_VECTOR;
struct ANIM_FRAME;
struct ITEM_INFO;
extern BITE_INFO EnemyBites[9];
extern int LightningCount;

View file

@ -16,6 +16,7 @@
#include <Game\effects\bubble.h>
#include "smoke.h"
#include "Specific\prng.h"
#include "Renderer11.h"
using TEN::Renderer::g_Renderer;
using TEN::Effects::Explosion::TriggerExplosion;
@ -23,7 +24,7 @@ using namespace TEN::Effects::Spark;
using namespace TEN::Math::Random;
short FXType;
FX_INFO* EffectList;
FX_INFO EffectList[NUM_EFFECTS];
int NextSpark;
int DeadlyBounds[6];
@ -1869,4 +1870,4 @@ void TriggerMetalSparks(int x, int y, int z, int xv, int yv, int zv, int additio
spark->dSize = ((r >> 8) & 0xF) + 24;
}
}
}
}

View file

@ -1,6 +1,7 @@
#pragma once
#include "Specific\phd_global.h"
#include "items.h"
struct ITEM_INFO;
struct COLL_INFO;
enum RIPPLE_TYPE
{
@ -180,7 +181,7 @@ constexpr auto SD_UWEXPLOSION = 2;
#define MAX_RIPPLES 256
#define MAX_SPLASHES 8
#define MAX_SPARKS_DYNAMICS 8
#define NUM_EFFECTS 256
extern int NextSpark;
extern int DeadlyBounds[6];
extern SPLASH_SETUP SplashSetup;
@ -195,7 +196,7 @@ extern int SplashCount;
extern PHD_VECTOR NodeVectors[MAX_NODE];
extern NODEOFFSET_INFO NodeOffsets[MAX_NODE];
extern FX_INFO* EffectList;
extern FX_INFO EffectList[NUM_EFFECTS];
void DetatchSpark(int num, SpriteEnumFlag type);
int GetFreeSpark();

View file

@ -8,6 +8,7 @@
#include "setup.h"
#include "sphere.h"
#include "level.h"
#include "Renderer11.h"
using TEN::Renderer::g_Renderer;
int FirstHair[HAIR_MAX];
HAIR_STRUCT Hairs[HAIR_MAX][HAIR_SEGMENTS + 1];

View file

@ -1,7 +1,7 @@
#pragma once
#include "Specific\phd_global.h"
#include "items.h"
#include "lara_struct.h"
struct ITEM_INFO;
struct ENERGY_ARC
{

View file

@ -1,6 +1,6 @@
#include "framework.h"
#include "Specific\trmath.h"
#include "floordata.h"
#include "Specific\trmath.h"
#include "room.h"
#include "level.h"
#include "setup.h"

View file

@ -1,6 +1,7 @@
#pragma once
#include "Specific\trmath.h"
#include "items.h"
#include <optional>
#include "roomvector.h"
struct SECTOR_COLLISION_INFO
{
@ -25,7 +26,7 @@ struct SECTOR_FLAGS
class FLOOR_INFO
{
public:
public:
int index;
int box;
int fx;

View file

@ -6,7 +6,7 @@
#include "camera.h"
#include "level.h"
#include "control.h"
#include "Renderer11.h"
using namespace TEN::Renderer;
short PickupX;
short PickupY;

57
TR5Main/Game/item.h Normal file
View file

@ -0,0 +1,57 @@
#pragma once
#include <cstdint>
#include "phd_global.h"
#include <string>
#include "itemdata.h"
#include "roomvector.h"
enum GAME_OBJECT_ID : short;
struct ITEM_INFO {
int floor;
uint32_t touchBits;
uint32_t meshBits;
GAME_OBJECT_ID objectNumber;
short currentAnimState;
short goalAnimState;
short requiredAnimState;
short animNumber;
short frameNumber;
short roomNumber;
ROOM_VECTOR location;
short nextItem;
short nextActive;
short speed;
short fallspeed;
short hitPoints;
int boxNumber;
short timer;
uint16_t flags; // ItemFlags enum
short shade;
uint16_t triggerFlags;
short carriedItem;
short afterDeath;
short firedWeapon;
short itemFlags[8];
ITEM_DATA data;
PHD_3DPOS pos;
bool active;
short status; // ItemStatus enum
bool gravityStatus;
bool hitStatus;
bool collidable;
bool lookedAt;
bool dynamicLight;
bool poisoned;
uint8_t aiBits; // AIObjectType enum
bool reallyActive;
bool inDrawRoom;
bool friendly;
uint32_t swapMeshFlags;
short drawRoom;
short TOSSPAD;
PHD_3DPOS startPos;
short locationAI;
std::string luaName;
};

View file

@ -0,0 +1,4 @@
#include "framework.h"
#include "itemdata.h"
ITEM_DATA::ITEM_DATA() : data(nullptr) {}

View file

@ -0,0 +1,131 @@
#pragma once
#include <variant>
#include <functional>
#include <cstddef>
#include "upv_info.h"
#include "skidoo_info.h"
#include "door_data.h"
#include "kayak_info.h"
#include "lara_struct.h"
#include "jeep_info.h"
#include "motorbike_info.h"
#include "minecart_info.h"
#include "biggun_info.h"
#include "quad_info.h"
#include "tr5_laserhead_info.h"
#include "creature_info.h"
#include "boat_info.h"
#include "rubberboat_info.h"
#include <stdexcept>
#include "phd_global.h"
#include "tr4_wraith_info.h"
#include "tr5_pushableblock_info.h"
template<class... Ts> struct visitor : Ts... { using Ts::operator()...; };
template<class... Ts> visitor(Ts...)->visitor<Ts...>; // line not needed in C++20...
struct ITEM_INFO;
class ITEM_DATA {
std::variant<std::nullptr_t,
char,
short,
int,
long,
long long,
unsigned char,
unsigned short,
unsigned int,
unsigned long,
unsigned long long,
float,
double,
long double,
std::array<short, 4>,
ITEM_INFO*,
CREATURE_INFO,
LASER_HEAD_INFO,
QUAD_INFO,
BIGGUNINFO,
MOTORBIKE_INFO,
JEEP_INFO,
LaraInfo,
KAYAK_INFO,
DOOR_DATA,
SKIDOO_INFO,
SUB_INFO,
BOAT_INFO,
GAME_VECTOR,
WRAITH_INFO,
RUBBER_BOAT_INFO,
PUSHABLE_INFO,
CART_INFO
> data;
public:
ITEM_DATA();
template<typename D>
ITEM_DATA(D&& type) : data(std::move(type)) {}
// conversion operators to keep original syntax!
// TODO: should be removed later and
template<typename T>
operator T* () {
if(std::holds_alternative<T>(data)) {
auto& ref = std::get<T>(data);
return &ref;
}
throw std::runtime_error("ITEM_DATA does not hold the requested type!\n The code set the ITEM_DATA to a different type than the type that was attempted to read");
}
template<typename T>
operator T& () {
if(std::holds_alternative<T>(data)) {
auto& ref = std::get<T>(data);
return ref;
}
throw std::runtime_error("ITEM_DATA does not hold the requested type!\n The code set the ITEM_DATA to a different type than the type that was attempted to read");
}
template<typename T>
ITEM_DATA& operator=(T* newData) {
data = *newData;
return *this;
}
ITEM_DATA& operator=(std::nullptr_t null) {
data = nullptr;
return *this;
}
template<typename T>
ITEM_DATA& operator=(T& newData) {
data = newData;
return *this;
}
template<typename T>
ITEM_DATA& operator=(T&& newData) {
data = std::move(newData);
return *this;
}
operator bool() const {
return !std::holds_alternative<std::nullptr_t>(data);
}
template<typename ... Funcs>
void apply(Funcs&&... funcs) {
std::visit(
visitor{
[](auto const&) {},
std::forward<Funcs>(funcs)...
},
data);
}
template<typename T>
bool is() const {
return std::holds_alternative<T>(data);
}
};

View file

@ -5,6 +5,7 @@
#include "lara.h"
#include "control.h"
#include "effects\effects.h"
#include "Game\box.h"
void ClearItem(short itemNum)
{
@ -12,7 +13,7 @@ void ClearItem(short itemNum)
ROOM_INFO* room = &g_Level.Rooms[item->roomNumber];
item->collidable = true;
item->data = NULL;
item->data = nullptr;
item->startPos = item->pos;
}
@ -270,8 +271,6 @@ short CreateNewEffect(short roomNum)
void InitialiseFXArray(int allocmem)
{
if (allocmem)
EffectList = game_malloc<FX_INFO>(NUM_EFFECTS);
FX_INFO* fx;
@ -382,7 +381,6 @@ void InitialiseItem(short itemNum)
item->touchBits = 0;
item->afterDeath = false;
item->firedWeapon = 0;
item->data = NULL;
item->swapMeshFlags = 0;
if (item->flags & IFLAG_INVISIBLE)
@ -408,7 +406,7 @@ void InitialiseItem(short itemNum)
item->nextItem = r->itemNumber;
r->itemNumber = itemNum;
FLOOR_INFO* floor = &XZ_GET_SECTOR(r, item->pos.xPos - r->x, item->pos.zPos - r->z);
FLOOR_INFO* floor = XZ_GET_SECTOR(r, item->pos.xPos - r->x, item->pos.zPos - r->z);
item->floor = floor->floor * 256;
item->boxNumber = floor->box;

View file

@ -1,7 +1,7 @@
#pragma once
#include "Specific\phd_global.h"
enum GAME_OBJECT_ID : short;
#include "item.h"
#include <vector>
enum AIObjectType
{
@ -32,60 +32,8 @@ enum ItemFlags
IFLAG_ACTIVATION_MASK = 0x3E00 // bits 9-13
};
struct ROOM_VECTOR
{
int roomNumber;
int yNumber;
};
struct ITEM_INFO
{
int floor;
DWORD touchBits;
DWORD meshBits;
GAME_OBJECT_ID objectNumber;
short currentAnimState;
short goalAnimState;
short requiredAnimState;
short animNumber;
short frameNumber;
short roomNumber;
ROOM_VECTOR location;
short nextItem;
short nextActive;
short speed;
short fallspeed;
short hitPoints;
int boxNumber;
short timer;
unsigned short flags; // ItemFlags enum
short shade;
short triggerFlags;
short carriedItem;
short afterDeath;
short firedWeapon;
short itemFlags[8];
void* data;
PHD_3DPOS pos;
bool active;
short status; // ItemStatus enum
bool gravityStatus;
bool hitStatus;
bool collidable;
bool lookedAt;
bool dynamicLight;
bool poisoned;
byte aiBits; // AIObjectType enum
bool reallyActive;
bool inDrawRoom;
bool friendly;
int swapMeshFlags;
short drawRoom;
short TOSSPAD;
PHD_3DPOS startPos;
short locationAI;
std::string luaName;
};
// used by fx->shade !
#define RGB555(r, g, b) ((r << 7) & 0x7C00 | (g << 2) & 0x3E0 | (b >> 3) & 0x1F)
@ -97,7 +45,6 @@ constexpr auto NO_ITEM = -1;
constexpr auto ALL_MESHBITS = -1;
constexpr auto NOT_TARGETABLE = -16384;
#define NUM_ITEMS 1024
#define NUM_EFFECTS 1024
void EffectNewRoom(short fxNumber, short roomNumber);
void ItemNewRoom(short itemNum, short roomNumber);

View file

@ -5,46 +5,35 @@
#include "camera.h"
#include "lara.h"
#include "level.h"
#include "creature_info.h"
#define DEFAULT_FLY_UPDOWN_SPEED 16
#define DEFAULT_SWIM_UPDOWN_SPEED 32
int SlotsUsed;
std::vector<CREATURE_INFO> BaddieSlots;
std::vector<CREATURE_INFO*> ActiveCreatures;
void InitialiseLOTarray(int allocMem)
void InitialiseLOTarray(int itemNum)
{
if (allocMem)
{
BaddieSlots.clear();
BaddieSlots.resize(NUM_SLOTS);
ITEM_INFO* item = &g_Level.Items[itemNum];
CREATURE_INFO* creature = item->data;
if(!creature->LOT.initialised) {
creature->LOT.node = std::vector<BOX_NODE>(g_Level.Boxes.size(), BOX_NODE{});
creature->LOT.initialised = true;
}
CREATURE_INFO* creature = BaddieSlots.data();
for (int i = 0; i < NUM_SLOTS; i++, creature++)
{
creature->itemNum = NO_ITEM;
if (allocMem)
{
creature->LOT.node.clear();
creature->LOT.node.resize(g_Level.Boxes.size());
for (int j = 0; j < g_Level.Boxes.size(); j++)
{
creature->LOT.node.emplace_back(BOX_NODE());
}
}
}
SlotsUsed = 0;
}
int EnableBaddieAI(short itemNum, int always)
{
ITEM_INFO* item = &g_Level.Items[itemNum];
if (item->data != NULL)
if (item->data.is<CREATURE_INFO>())
return true;
/*
if (SlotsUsed >= NUM_SLOTS)
{
int cameraDistance = 0;
@ -57,9 +46,11 @@ int EnableBaddieAI(short itemNum, int always)
}
int slotToDisable = -1;
CREATURE_INFO* creature = BaddieSlots.data();
for (int slot = 0; slot < NUM_SLOTS; slot++, creature++)
for (int slot = 0; slot < ActiveCreatures.size(); slot++)
{
CREATURE_INFO* creature = ActiveCreatures[slot];
item = &g_Level.Items[creature->itemNum];
int deltaX = (item->pos.xPos - Camera.pos.x) >> 8;
@ -77,17 +68,18 @@ int EnableBaddieAI(short itemNum, int always)
if (slotToDisable < 0 || slotToDisable > NUM_SLOTS)
return false;
ITEM_INFO* itemToDisable = &g_Level.Items[BaddieSlots[slotToDisable].itemNum];
CREATURE_INFO* creatureToDisable = &BaddieSlots[slotToDisable];
ITEM_INFO* itemToDisable = &g_Level.Items[ActiveCreatures[slotToDisable].itemNum];
CREATURE_INFO* creatureToDisable = &ActiveCreatures[slotToDisable];
itemToDisable->status = ITEM_INVISIBLE;
DisableBaddieAI(creatureToDisable->itemNum);
InitialiseSlot(itemNum, slotToDisable);
return true;
}
else
else*/
{
CREATURE_INFO* creature = BaddieSlots.data();
/*
CREATURE_INFO* creature = ActiveCreatures.data();
for (int slot = 0; slot < NUM_SLOTS; slot++, creature++)
{
if (creature->itemNum == NO_ITEM)
@ -96,9 +88,12 @@ int EnableBaddieAI(short itemNum, int always)
return true;
}
}
*/
InitialiseSlot(itemNum, 0);
ActiveCreatures.push_back(item->data);
}
return false;
return true;
}
void DisableBaddieAI(short itemNumber)
@ -106,11 +101,13 @@ 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--;
ActiveCreatures.erase(std::find(ActiveCreatures.begin(), ActiveCreatures.end(), creature));
item->data = nullptr;
}
}
@ -118,9 +115,10 @@ void InitialiseSlot(short itemNum, short slot)
{
ITEM_INFO* item = &g_Level.Items[itemNum];
OBJECT_INFO* obj = &Objects[item->objectNumber];
CREATURE_INFO* creature = &BaddieSlots[slot];
item->data = creature;
item->data = CREATURE_INFO();
CREATURE_INFO* creature = item->data;
InitialiseLOTarray(itemNum);
creature->itemNum = itemNum;
creature->mood = BORED_MOOD;
creature->jointRotation[0] = 0;
@ -283,12 +281,11 @@ void ClearLOT(LOT_INFO* LOT)
LOT->requiredBox = NO_BOX;
BOX_NODE* node = LOT->node.data();
for (int i = 0; i < g_Level.Boxes.size(); i++)
for(auto& node : LOT->node)
{
node->exitBox = NO_BOX;
node->nextExpansion = NO_BOX;
node->searchNumber = 0;
node++;
node.exitBox = NO_BOX;
node.nextExpansion = NO_BOX;
node.searchNumber = 0;
}
}
@ -297,7 +294,7 @@ 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;
item->boxNumber = XZ_GET_SECTOR(r, item->pos.xPos - r->x, item->pos.zPos - r->z)->box;
if (creature->LOT.fly)
{

View file

@ -1,9 +1,7 @@
#pragma once
#include "box.h"
constexpr auto NUM_SLOTS = 32;
extern int SlotsUsed;
extern std::vector<CREATURE_INFO> BaddieSlots;
extern std::vector<CREATURE_INFO*> ActiveCreatures;
void InitialiseLOTarray(int allocMem);
int EnableBaddieAI(short itemNum, int always);

View file

@ -1,17 +0,0 @@
#include "framework.h"
#include "malloc.h"
#include "door.h"
char* malloc_buffer;
int malloc_size;
char* malloc_ptr;
int malloc_free;
int malloc_used;
void init_game_malloc() noexcept
{
}
void game_free(void* ptr) noexcept
{
delete[] ptr;
}

View file

@ -1,15 +0,0 @@
#pragma once
#include <utility>
extern char* malloc_buffer;
extern int malloc_size;
extern char* malloc_ptr;
extern int malloc_free;
extern int malloc_used;
template <typename T,typename ... Args>
T* game_malloc(size_t count = 1,Args&&...args) noexcept {
return new T[count]{std::forward<Args>(args)...};
}
void init_game_malloc() noexcept;
void game_free(void* ptr) noexcept;

View file

@ -4,6 +4,7 @@
#include "level.h"
#include "lara.h"
#include "draw.h"
#include "creature_info.h"
using std::vector;
short GF(short animIndex, short frameToStart)
{

View file

@ -8,7 +8,7 @@
#include "level.h"
#include "setup.h"
#include "lara.h"
#include "collide.h"
#define SHARD_DAMAGE 30
#define ROCKET_DAMAGE 100
#define DIVER_HARPOON_DAMAGE 50

View file

@ -17,6 +17,7 @@
#include "level.h"
#include "input.h"
#include "pickup\pickup.h"
#include "Renderer11.h"
using namespace TEN::Renderer;
bool goUp, goDown, goRight, goLeft, goSelect, goDeselect;
@ -4258,4 +4259,4 @@ int do_special_waterskin_combine_bullshit(int flag)
return 0;
}
#endif
#endif

View file

@ -14,6 +14,7 @@
#include "level.h"
#include "input.h"
#include "Sound\sound.h"
#include "collide.h"
OBJECT_TEXTURE* WaterfallTextures[6];
float WaterfallY[6];

View file

@ -1,7 +1,8 @@
#pragma once
#include "collide.h"
struct ITEM_INFO;
struct COLL_INFO;
struct OBJECT_TEXTURE;
extern OBJECT_TEXTURE* WaterfallTextures[6];
extern float WaterfallY[6];

View file

@ -7,6 +7,7 @@
#include "effects\debris.h"
#include "lara.h"
#include "Sound\sound.h"
#include "creature_info.h"
int ShotLara(ITEM_INFO* item, AI_INFO* info, BITE_INFO* gun, short extra_rotation, int damage)
{

View file

@ -1,7 +1,9 @@
#pragma once
#include "collide.h"
struct ITEM_INFO;
struct COLL_INFO;
struct PHD_VECTOR;
struct BOUNDING_BOX;
enum GAME_OBJECT_ID : short;
extern int NumRPickups;

View file

@ -13,7 +13,8 @@
#include "control.h"
#include "puzzles_keys.h"
#include "generic_switch.h"
#include "camera.h"
#include "control.h"
using namespace TEN::Entities::Switches;
enum PuzzleType {

View file

@ -1,6 +1,7 @@
#pragma once
#include "collide.h"
struct ITEM_INFO;
struct COLL_INFO;
/*puzzles*/
void PuzzleHoleCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll);
void PuzzleDoneCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll);

View file

@ -0,0 +1,5 @@
#pragma once
struct ROOM_VECTOR {
int roomNumber;
int yNumber;
};

View file

@ -6,6 +6,7 @@
#include "input.h"
#include "control.h"
#include "Sound\sound.h"
#include "camera.h"
PENDULUM CurrentPendulum;
PENDULUM AlternatePendulum;

View file

@ -18,7 +18,8 @@
#include "tr5_spider_emitter.h"
#include "generic_switch.h"
#include "fullblock_switch.h"
#include "creature_info.h"
#include "quad_info.h"
using namespace TEN::Entities::Switches;
using std::string;
@ -996,7 +997,7 @@ bool SaveGame::readItemChunks(ChunkId* chunkId, int maxSize, int itemNumber)
creature->mood = (MOOD_TYPE)LEB128::ReadInt32(m_stream);
ITEM_INFO* enemy = (ITEM_INFO*)LEB128::ReadLong(m_stream);
creature->enemy = AddPtr(enemy, ITEM_INFO, malloc_buffer);
//creature->enemy = AddPtr(enemy, ITEM_INFO, malloc_buffer);
creature->aiTarget.objectNumber = from_underlying(LEB128::ReadInt16(m_stream));
creature->aiTarget.roomNumber = LEB128::ReadInt16(m_stream);
@ -1019,10 +1020,10 @@ bool SaveGame::readItemChunks(ChunkId* chunkId, int maxSize, int itemNumber)
}
else if (chunkId->EqualsTo(m_chunkItemQuadInfo.get()))
{
QUAD_INFO* quadInfo = game_malloc<QUAD_INFO>();
m_stream->ReadBytes(reinterpret_cast<byte*>(quadInfo), sizeof(QUAD_INFO));
if (item->objectNumber == ID_QUAD)
item->data = (void*)quadInfo;
//QUAD_INFO* quadInfo = game_malloc<QUAD_INFO>();
//m_stream->ReadBytes(reinterpret_cast<byte*>(quadInfo), sizeof(QUAD_INFO));
//if (item->objectNumber == ID_QUAD)
// item->data = quadInfo;
return true;
}
@ -1107,7 +1108,7 @@ void SaveGame::saveItemIntelligentData(int arg1, int arg2)
OBJECT_INFO* obj = &Objects[item->objectNumber];
CREATURE_INFO* creature = (CREATURE_INFO*)item->data;
ITEM_INFO* enemy = (ITEM_INFO*)((char*)creature->enemy - (ptrdiff_t)malloc_buffer);
ITEM_INFO* enemy = (ITEM_INFO*)((char*)creature->enemy);
LEB128::Write(m_stream, creature->jointRotation[0]);
LEB128::Write(m_stream, creature->jointRotation[1]);
@ -1418,7 +1419,7 @@ bool SaveGame::readFlare()
AddActiveItem(itemNumber);
// Flare age
item->data = (void*)LEB128::ReadInt32(m_stream);
item->data = LEB128::ReadInt32(m_stream);
return true;
}
@ -1465,7 +1466,8 @@ bool SaveGame::readTorpedo()
void SaveGame::saveItemQuadInfo(int itemNumber, int arg2)
{
m_stream->WriteBytes(reinterpret_cast<byte*>(g_Level.Items[itemNumber].data), sizeof(QUAD_INFO));
//m_stream->WriteBytes(reinterpret_cast<byte*>(g_Level.Items[itemNumber].data), sizeof(QUAD_INFO));
}
void SaveGame::saveRats(int arg1, int arg2)

View file

@ -1,7 +1,7 @@
#pragma once
#include "collide.h"
struct COLL_INFO;
struct ITEM_INFO;
void ProcessExplodingSwitchType8(ITEM_INFO* item);
void InitialiseShootSwitch(short itemNumber);
void ShootSwitchCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* coll);

View file

@ -1,10 +1,10 @@
#pragma once
#include "collide.h"
struct COLL_INFO;
struct ITEM_INFO;
extern ITEM_INFO* WBItem;
extern short WBRoom;
void LaraBurn();
void LavaBurn(ITEM_INFO* item);
void FlameControl(short fxNumber);

View file

@ -10,6 +10,7 @@
#include "lara.h"
#include "control.h"
#include "tr4_mutant.h"
#include "collide.h"
namespace TEN::entities::all
{

View file

@ -6,6 +6,7 @@
#include "misc.h"
#include "lara.h"
#include "effects\tomb4fx.h"
#include "collide.h"
namespace TEN::Entities::TR4 {
LOCUST_INFO Locusts[MAX_LOCUSTS];

View file

@ -1,5 +1,6 @@
#pragma once
#include "Specific\phd_global.h"
#include "level.h"
void InitialiseBridge(short itemNumber);
int GetOffset(short angle, int x, int z);

View file

@ -2,7 +2,9 @@
#include "generic_trapdoor.h"
#include "lara.h"
#include "input.h"
#include "camera.h"
#include "control.h"
#include "level.h"
OBJECT_COLLISION_BOUNDS CeilingTrapDoorBounds = {-256, 256, 0, 900, -768, -256, -1820, 1820, -5460, 5460, -1820, 1820};
static PHD_VECTOR CeilingTrapDoorPos = {0, 1056, -480};
OBJECT_COLLISION_BOUNDS FloorTrapDoorBounds = {-256, 256, 0, 0, -1024, -256, -1820, 1820, -5460, 5460, -1820, 1820};

View file

@ -4,8 +4,8 @@
#include "input.h"
#include "lara.h"
#include "generic_switch.h"
#include "door.h"
#include "door_data.h"
#include "Box.h"
namespace TEN::Entities::Switches
{
OBJECT_COLLISION_BOUNDS CogSwitchBounds =

View file

@ -7,6 +7,7 @@
#include "newinv2.h"
#include "Sound\sound.h"
#include "pickup\pickup.h"
#include "level.h"
namespace TEN::Entities::Switches
{

View file

@ -4,7 +4,9 @@
#include "input.h"
#include "lara.h"
#include "generic_switch.h"
#include "setup.h"
#include "collide.h"
#include "level.h"
namespace TEN::Entities::Switches
{
OBJECT_COLLISION_BOUNDS FullBlockSwitchBounds =

View file

@ -1,7 +1,7 @@
#pragma once
#include "items.h"
#include <collide.h>
struct ITEM_INFO;
struct COLL_INFO;
namespace TEN::Entities::Switches
{

View file

@ -5,7 +5,8 @@
#include "generic_switch.h"
#include "sphere.h"
#include "draw.h"
#include "collide.h"
#include "floordata.h"
namespace TEN::Entities::Switches
{
OBJECT_COLLISION_BOUNDS SwitchBounds =

View file

@ -1,8 +1,8 @@
#pragma once
#include "items.h"
#include <collide.h>
struct ITEM_INFO;
struct COLL_INFO;
namespace TEN::Entities::Switches
{
enum SwitchStatus

View file

@ -4,6 +4,7 @@
#include "input.h"
#include "lara.h"
#include "generic_switch.h"
#include "level.h"
namespace TEN::Entities::Switches
{

View file

@ -6,6 +6,7 @@
#include "generic_switch.h"
#include "Sound\sound.h"
#include "pickup\pickup.h"
#include "level.h"
namespace TEN::Entities::Switches
{

View file

@ -4,6 +4,7 @@
#include "input.h"
#include "lara.h"
#include "generic_switch.h"
#include "level.h"
namespace TEN::Entities::Switches
{

View file

@ -7,6 +7,9 @@
#include "door.h"
#include "Sound\sound.h"
#include "switch.h"
#include "setup.h"
#include "camera.h"
#include "level.h"
namespace TEN::Entities::Switches
{

View file

@ -6,6 +6,9 @@
#include "newinv2.h"
#include "Sound\sound.h"
#include "generic_switch.h"
#include "camera.h"
#include "collide.h"
#include "level.h"
namespace TEN::Entities::Switches
{

View file

@ -6,6 +6,8 @@
#include "level.h"
#include "control.h"
#include "lara.h"
#include "creature_info.h"
#include "control.h"
BITE_INFO bearBite = { 0, 96, 335, 14 };

View file

@ -11,6 +11,9 @@
#include "lara_one_gun.h"
#include "effects\effects.h"
#include "draw.h"
#include "collide.h"
#include "item.h"
#include "setup.h"
enum centaur_anims {
CENTAUR_EMPTY,

View file

@ -107,7 +107,7 @@ void DoppelgangerControl(short itemNum)
item->gravityStatus = true;
item->fallspeed = 0;
item->speed = 0;
item->data = (void*)-1;
item->data = -1;
item->pos.yPos += 50;
}
}

View file

@ -8,6 +8,7 @@
#include "level.h"
#include "lara.h"
#include "Sound\sound.h"
#include "creature_info.h"
enum abortion_anims {
ABORT_EMPTY, ABORT_STOP, ABORT_TURNL, ABORT_TURNR, ABORT_ATTACK1, ABORT_ATTACK2,

View file

@ -8,6 +8,7 @@
#include "Sound\sound.h"
#include "effects\effects.h"
#include "Specific\trmath.h"
#include "creature_info.h"
#define NATLA_NEAR_DEATH 200

View file

@ -7,7 +7,8 @@
#include "setup.h"
#include "control.h"
#include "level.h"
#include "creature_info.h"
#include "control.h"
BITE_INFO wolfBite = { 0, -14, 174, 6 };
enum wolfStates {

View file

@ -19,6 +19,7 @@
#include "setup.h"
#include "level.h"
#include "object_helper.h"
#include "creature_info.h"
static void StartBaddy(OBJECT_INFO* obj)
{

View file

@ -5,7 +5,7 @@
#include "lara.h"
#include "setup.h"
#include "level.h"
#include "creature_info.h"
BITE_INFO barracudaBite = { 2, -60, 121, 7 };
void BarracudaControl(short itemNum)

View file

@ -12,7 +12,7 @@
#include "setup.h"
#include "input.h"
#include "Sound\sound.h"
#include "creature_info.h"
#define DRAGON_SWIPE_DAMAGE 250
#define DRAGON_TOUCH_DAMAGE 10
@ -478,7 +478,7 @@ void InitialiseBartoli(short itemNum)
InitialiseItem(back_item);
back->meshBits = 0x1FFFFF;
item->data = (void*)back_item;
item->data = back_item;
front = &g_Level.Items[front_item];
front->objectNumber = ID_DRAGON_FRONT;
@ -492,7 +492,7 @@ void InitialiseBartoli(short itemNum)
InitialiseItem(front_item);
back->data = (void*)front_item;
back->data = front_item;
g_Level.NumItems += 2;
}

View file

@ -6,6 +6,7 @@
#include "items.h"
#include "setup.h"
#include "level.h"
#include "creature_info.h"
BITE_INFO eagleBite = { 15, 46, 21, 6 };
BITE_INFO crowBite = { 2, 10, 60, 14 };

View file

@ -8,6 +8,9 @@
#include "level.h"
#include "lara.h"
#include "Sound\sound.h"
#include "creature_info.h"
#include "floordata.h"
#include "collide.h"
BITE_INFO knifeLeft = { 0, 0, 0, 5 };
BITE_INFO knifeRight = { 0, 0, 0, 8 };

View file

@ -6,6 +6,7 @@
#include "level.h"
#include "control.h"
#include "Specific\trmath.h"
#include "creature_info.h"
BITE_INFO mercUziBite = { 0, 150, 19, 17 };
BITE_INFO mercAutoPistolBite = { 0, 230, 9, 17 };

View file

@ -6,7 +6,7 @@
#include "Sound\sound.h"
#include "setup.h"
#include "level.h"
#include "creature_info.h"
BITE_INFO monkBite = { -23,16,265, 14 };
extern bool MonksAttackLara;

View file

@ -6,6 +6,8 @@
#include "setup.h"
#include "control.h"
#include "level.h"
#include "creature_info.h"
#include "control.h"
BITE_INFO ratBite = { 0, 0, 57, 2 };

View file

@ -5,7 +5,7 @@
#include "setup.h"
#include "level.h"
#include "control.h"
#include "creature_info.h"
BITE_INFO silencerGun = { 3, 331, 56, 10 };
void SilencerControl(short itemNum)

Some files were not shown because too many files have changed in this diff Show more