From f54ad0f865083485e91b71233481faed5c6d8633 Mon Sep 17 00:00:00 2001
From: hispidence
Date: Fri, 12 Aug 2022 11:59:51 +0100
Subject: [PATCH 001/106] Improve error messages and properly shut down TENLog
if we have to crash the game.
---
TombEngine/Scripting/Internal/TEN/Flow/FlowHandler.cpp | 5 +++--
TombEngine/Specific/winmain.cpp | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/TombEngine/Scripting/Internal/TEN/Flow/FlowHandler.cpp b/TombEngine/Scripting/Internal/TEN/Flow/FlowHandler.cpp
index b1828248e..9dd54070a 100644
--- a/TombEngine/Scripting/Internal/TEN/Flow/FlowHandler.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Flow/FlowHandler.cpp
@@ -244,8 +244,9 @@ bool FlowHandler::DoFlow()
}
catch (TENScriptException const& e)
{
- std::string msg = std::string{ "An unrecoverable error occurred in " } + __func__ + ": " + e.what();
+ std::string msg = std::string{ "A Lua error occurred while running the title level; " } + __func__ + ": " + e.what();
TENLog(msg, LogLevel::Error, LogConfig::All);
+ ShutdownTENLog();
throw;
}
}
@@ -277,7 +278,7 @@ bool FlowHandler::DoFlow()
}
catch (TENScriptException const& e)
{
- std::string msg = std::string{ "An unrecoverable error occurred in " } + __func__ + ": " + e.what();
+ std::string msg = std::string{ "A Lua error occurred while running a level; " } + __func__ + ": " + e.what();
TENLog(msg, LogLevel::Error, LogConfig::All);
status = GameStatus::ExitToTitle;
}
diff --git a/TombEngine/Specific/winmain.cpp b/TombEngine/Specific/winmain.cpp
index 41f1de856..5e3ff1d48 100644
--- a/TombEngine/Specific/winmain.cpp
+++ b/TombEngine/Specific/winmain.cpp
@@ -290,7 +290,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
}
catch (TENScriptException const& e)
{
- std::string msg = std::string{ "An unrecoverable error occurred in " } + __func__ + ": " + e.what();
+ std::string msg = std::string{ "A Lua error occurred while setting up scripts; " } + __func__ + ": " + e.what();
TENLog(msg, LogLevel::Error, LogConfig::All);
ShutdownTENLog();
return 0;
From 47c7775ee18e88ddae6c8b80e1c742ef3acd2371 Mon Sep 17 00:00:00 2001
From: hispidence
Date: Sun, 14 Aug 2022 18:17:07 +0100
Subject: [PATCH 002/106] Add EventSequence documentation
---
.../5 lua utility modules/EventSequence.html | 340 ++++++++++++++++++
1 file changed, 340 insertions(+)
create mode 100644 Documentation/doc/5 lua utility modules/EventSequence.html
diff --git a/Documentation/doc/5 lua utility modules/EventSequence.html b/Documentation/doc/5 lua utility modules/EventSequence.html
new file mode 100644
index 000000000..be2753a3d
--- /dev/null
+++ b/Documentation/doc/5 lua utility modules/EventSequence.html
@@ -0,0 +1,340 @@
+
+
+
+
+ TombEngine 1.0.1 Lua API
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
TombEngine
+
+
+
+
Contents
+
+
+
+
5 Lua utility modules
+
+
1 Modules
+
+
2 Classes
+
+
3 Primitive Classes
+
+
4 Enums
+
+
+
+
+
+
+
Lua utility module EventSequence
+
Event sequence - a chain of functions to call at specified times, modeled after TRNG's organizers.
+
+
+
Example usage:
+
+
+local EventSequence = require ("EventSequence" )
+
+LevelFuncs.HealLara = function ()
+ Lara:SetHP(Lara:GetHP()+10 )
+end
+
+local nSpawned = 0
+LevelFuncs.SpawnBaddy = function (baddy, name, pos)
+ local myBaddy = TEN.Objects.Moveable(baddy, name..nSpawned, pos, nil , 0 )
+ myBaddy:Enable()
+ nSpawned = nSpawned + 1
+end
+
+LevelFuncs.TriggerSequence = function (obj)
+ local posSteve = TEN.Objects.GetMoveableByName("stevePosNullmesh" ):GetPosition()
+ local posChris = TEN.Objects.GetMoveableByName("chrisPosNullmesh" ):GetPosition()
+ local mySeq = EventSequence.Create("my_seq" ,
+ false , {seconds = true , deciseconds = true }, 6 , "HealLara" , 2.1 , {"SpawnBaddy" , TEN.Objects.ObjID.BADDY1, "steve" , posSteve}, 0.5 ,
+ {"SpawnBaddy" , TEN.Objects.ObjID.SAS_CAIRO, "chris" , posChris},
+ 1 ,
+ "HealLara" )
+
+ mySeq:Start()
+end
+
+LevelFuncs.OnControlPhase = function (dt)
+ Timer.UpdateAll(dt)
+end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Create(name, loop, timerFormat[, ...])
+
+
+ Create (but do not start) a new event sequence.
+
+
+ Parameters:
+
+ name
+ string
+ A label to give the sequence; used to retrieve the timer later as well as internally by TEN.
+
+ loop
+ bool
+ if true, the sequence will start again from its first timer once its final function has been called
+
+ timerFormat
+ table or bool
+ same as in Timer. This is mainly for debugging. This will not work properly if another sequence or timer is showing a countdown.
+
+ ...
+ a variable number of pairs of arguments - a time in seconds, followed by the function (must be defined in the LevelFuncs table) to call once the time has elapsed, followed by another duration in seconds, another function name, etc. You can specify a function either by its name as a string, or by a table with the function name as the first member, followed by its arguments (see above example).
+ (optional )
+
+
+
+ Returns:
+
+
+ The inactive sequence.
+
+
+
+
+
+
+
+
+ Get(name)
+
+
+ Get an event sequence by its name.
+
+
+ Parameters:
+
+ name
+ string
+ The label that was given to the sequence when it was created
+
+
+
+ Returns:
+
+
+ The sequence
+
+
+
+
+
+
+
+
+ mySequence:SetPaused(p)
+
+
+ Pause or unpause the sequence. If showing the remaining time on-screen, its color will be set to yellow (paused) or white (unpaused).
+
+
+ Parameters:
+
+ p
+ bool
+ if true, the sequence will be paused; if false, it will be unpaused
+
+
+
+
+
+
+
+
+
+
+ mySequence:IsPaused()
+
+
+ Get whether or not the sequence is paused
+
+
+
+ Returns:
+
+
+ true if the timer is paused, false if otherwise
+
+
+
+
+
+
+
+
+ mySequence:Start()
+
+
+ Begin or unpause a sequence. If showing the remaining time on-screen, its color will be set to white.
+
+
+
+
+
+
+
+
+
+
+ mySequence:Stop()
+
+
+ Stop the sequence.
+
+
+
+
+
+
+
+
+
+
+ mySequence:IsActive()
+
+
+ Get whether or not the sequence is active
+
+
+
+ Returns:
+
+
+ true if the sequence is active, false if otherwise
+
+
+
+
+
+
+
+
+
+
+
+
+
generated by LDoc 1.4.6
+
Last updated 2022-08-11 22:43:52
+
+
+
+
From d9e0ecb79ed178291ef90df75c99afb4812fefd2 Mon Sep 17 00:00:00 2001
From: hispidence
Date: Mon, 15 Aug 2022 17:43:19 +0100
Subject: [PATCH 003/106] Hopefully fix #627
---
TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
index 2d7f28eaf..9057db93e 100644
--- a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
@@ -131,6 +131,8 @@ void LogicHandler::ResetScripts(bool clearGameVars)
ResetGameTables();
m_handler.ResetGlobals();
+
+ m_handler.GetState()->collect_garbage();
}
void LogicHandler::FreeLevelScripts()
From 96d1af28a72b2d7886a05e0c86713e176dbac964 Mon Sep 17 00:00:00 2001
From: hispidence
Date: Mon, 15 Aug 2022 18:31:15 +0100
Subject: [PATCH 004/106] Finish PlaySound documentation.
---
Documentation/doc/1 modules/Misc.html | 61 +++++++++----------
.../Internal/TEN/Misc/Miscellanous.cpp | 8 +--
2 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/Documentation/doc/1 modules/Misc.html b/Documentation/doc/1 modules/Misc.html
index 86d155089..22ce29e8d 100644
--- a/Documentation/doc/1 modules/Misc.html
+++ b/Documentation/doc/1 modules/Misc.html
@@ -124,6 +124,10 @@
Set and play an ambient track
+ PlaySound(sound[, position])
+ Play sound effect
+
+
CalculateDistance(posA, posB)
Calculate the distance between two positions.
@@ -144,10 +148,6 @@
Vibrate gamepad, if possible.
- PlaySound(sound, position)
- Play sound effect
-
-
KeyIsHeld(action)
Check if particular action key is held
@@ -355,6 +355,32 @@ eyes of the creatures would be.
+
+
+
+ PlaySound(sound[, position])
+
+
+ Play sound effect
+
+
+ Parameters:
+
+ sound
+ int
+ ID to play. Corresponds to the value in the sound XML file or Tomb Editor's "Sound Infos" window.
+
+ position
+ Vec3
+ The 3D position of the sound, i.e. where the sound "comes from". If not given, the sound will not be positional.
+ (optional )
+
+
+
+
+
+
+
@@ -514,33 +540,6 @@ To be used with
- PlaySound(sound, position)
-
-
- Play sound effect
-
-
- Parameters:
-
- sound
- int
- ID to play
-
- position
- Vec3
-
-
-
-
-
-
-
-
-
-
diff --git a/TombEngine/Scripting/Internal/TEN/Misc/Miscellanous.cpp b/TombEngine/Scripting/Internal/TEN/Misc/Miscellanous.cpp
index a36abe198..d63c2d78b 100644
--- a/TombEngine/Scripting/Internal/TEN/Misc/Miscellanous.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Misc/Miscellanous.cpp
@@ -120,6 +120,10 @@ namespace Misc
PlaySoundTrack(trackName, SoundTrackType::BGM);
}
+ /// Play sound effect
+ //@function PlaySound
+ //@tparam int sound ID to play. Corresponds to the value in the sound XML file or Tomb Editor's "Sound Infos" window.
+ ////@tparam[opt] Vec3 position The 3D position of the sound, i.e. where the sound "comes from". If not given, the sound will not be positional.
static void PlaySoundEffect(int id, sol::optional p)
{
SoundEffect(id, p.has_value() ? &PHD_3DPOS(p.value().x, p.value().y, p.value().z) : nullptr, SoundEnvironment::Always);
@@ -222,10 +226,6 @@ namespace Misc
table_misc.set_function(ScriptReserved_PlayAudioTrack, &PlayAudioTrack);
- /// Play sound effect
- //@function PlaySound
- //@tparam int sound ID to play
- //@tparam Vec3 position
table_misc.set_function(ScriptReserved_PlaySound, &PlaySoundEffect);
/// Check if particular action key is held
From e9329f9c1368c3029a94921a8f9e8ec67576bce2 Mon Sep 17 00:00:00 2001
From: Sezz
Date: Tue, 16 Aug 2022 20:55:43 +1000
Subject: [PATCH 005/106] Convert some probabilities; tr5_larson.cpp cleanup
---
.../Objects/TR3/Entity/tr3_flamethrower.cpp | 15 +-
TombEngine/Objects/TR3/Entity/tr3_monkey.cpp | 27 +-
TombEngine/Objects/TR3/Entity/tr3_mp_gun.cpp | 26 +-
.../Objects/TR3/Entity/tr3_mp_stick.cpp | 14 +-
TombEngine/Objects/TR3/Entity/tr3_raptor.cpp | 2 +-
.../Objects/TR3/Entity/tr3_tribesman.cpp | 5 +-
.../Objects/TR5/Entity/tr5_autoguns.cpp | 24 +-
TombEngine/Objects/TR5/Entity/tr5_chef.cpp | 11 +-
.../Objects/TR5/Entity/tr5_doberman.cpp | 44 +--
.../Objects/TR5/Entity/tr5_gladiator.cpp | 20 +-
TombEngine/Objects/TR5/Entity/tr5_guard.cpp | 30 +-
TombEngine/Objects/TR5/Entity/tr5_hydra.cpp | 28 +-
.../Objects/TR5/Entity/tr5_lagoon_witch.cpp | 1 +
TombEngine/Objects/TR5/Entity/tr5_larson.cpp | 272 +++++++++---------
14 files changed, 269 insertions(+), 250 deletions(-)
diff --git a/TombEngine/Objects/TR3/Entity/tr3_flamethrower.cpp b/TombEngine/Objects/TR3/Entity/tr3_flamethrower.cpp
index cdda7e9c1..5af828ce5 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_flamethrower.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_flamethrower.cpp
@@ -14,8 +14,11 @@
#include "Game/people.h"
#include "Sound/sound.h"
#include "Specific/level.h"
+#include "Specific/prng.h"
#include "Specific/setup.h"
+using namespace TEN::Math::Random;
+
namespace TEN::Entities::TR3
{
const auto FlamethrowerOffset = Vector3Int(0, 340, 0);
@@ -57,9 +60,7 @@ namespace TEN::Entities::TR3
TriggerPilotFlame(itemNumber, 9);
}
else
- {
TriggerDynamicLight(pos.x, pos.y, pos.z, (random & 3) + 10, 31 - ((random / 16) & 3), 24 - ((random / 64) & 3), random & 7);
- }
if (item->HitPoints <= 0)
{
@@ -154,7 +155,7 @@ namespace TEN::Entities::TR3
{
head = AIGuard(creature);
- if (!(GetRandomControl() & 0xFF))
+ if (TestProbability(0.008f))
item->Animation.TargetState = 4;
break;
@@ -170,9 +171,9 @@ namespace TEN::Entities::TR3
else
item->Animation.TargetState = 2;
}
- else if (creature->Mood == MoodType::Bored && AI.ahead && !(GetRandomControl() & 0xFF))
+ else if (creature->Mood == MoodType::Bored && AI.ahead && TestProbability(0.008f))
item->Animation.TargetState = 4;
- else if (creature->Mood == MoodType::Attack || !(GetRandomControl() & 0xFF))
+ else if (creature->Mood == MoodType::Attack || TestProbability(0.008f))
item->Animation.TargetState = 2;
break;
@@ -184,7 +185,7 @@ namespace TEN::Entities::TR3
{
head = AIGuard(creature);
- if (!(GetRandomControl() & 0xFF))
+ if (TestProbability(0.008f))
item->Animation.TargetState = 1;
break;
@@ -193,7 +194,7 @@ namespace TEN::Entities::TR3
AI.distance < pow(SECTOR(4), 2) &&
(realEnemy != LaraItem || creature->HurtByLara) ||
creature->Mood != MoodType::Bored ||
- !(GetRandomControl() & 0xFF)))
+ TestProbability(0.008f)))
{
item->Animation.TargetState = 1;
}
diff --git a/TombEngine/Objects/TR3/Entity/tr3_monkey.cpp b/TombEngine/Objects/TR3/Entity/tr3_monkey.cpp
index d01d4a5fb..806106f26 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_monkey.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_monkey.cpp
@@ -10,21 +10,22 @@
#include "Game/Lara/lara.h"
#include "Game/misc.h"
#include "Specific/level.h"
+#include "Specific/prng.h"
#include "Specific/setup.h"
+using namespace TEN::Math::Random;
using std::vector;
namespace TEN::Entities::TR3
{
- const vector MonkeyAttackJoints = { 10, 13 };
const auto MonkeyBite = BiteInfo(Vector3(10.0f, 10.0f, 11.0f), 13);
+ const vector MonkeyAttackJoints = { 10, 13 };
void InitialiseMonkey(short itemNumber)
{
auto* item = &g_Level.Items[itemNumber];
ClearItem(itemNumber);
-
item->Animation.AnimNumber = Objects[ID_MONKEY].animIndex + 2;
item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
item->Animation.ActiveState = 6;
@@ -154,9 +155,9 @@ namespace TEN::Entities::TR3
if (item->AIBits & GUARD)
{
torsoY = AIGuard(creature);
- if (!(GetRandomControl() & 0xF))
+ if (TestProbability(0.06f))
{
- if (GetRandomControl() & 0x1)
+ if (TestProbability(0.5f))
item->Animation.TargetState = 8;
else
item->Animation.TargetState = 7;
@@ -173,11 +174,11 @@ namespace TEN::Entities::TR3
{
if (item->Animation.RequiredState)
item->Animation.TargetState = item->Animation.RequiredState;
- else if (!(GetRandomControl() & 0xF))
+ else if (TestProbability(0.06f))
item->Animation.TargetState = 2;
- else if (!(GetRandomControl() & 0xF))
+ else if (TestProbability(0.06f))
{
- if (GetRandomControl() & 0x1)
+ if (TestProbability(0.5f))
item->Animation.TargetState = 8;
else
item->Animation.TargetState = 7;
@@ -210,9 +211,9 @@ namespace TEN::Entities::TR3
{
torsoY = AIGuard(creature);
- if (!(GetRandomControl() & 15))
+ if (TestProbability(0.06f))
{
- if (GetRandomControl() & 1)
+ if (TestProbability(0.5f))
item->Animation.TargetState = 10;
else
item->Animation.TargetState = 6;
@@ -233,11 +234,11 @@ namespace TEN::Entities::TR3
{
if (item->Animation.RequiredState)
item->Animation.TargetState = item->Animation.RequiredState;
- else if (!(GetRandomControl() & 15))
+ else if (TestProbability(0.06f))
item->Animation.TargetState = 2;
- else if (!(GetRandomControl() & 15))
+ else if (TestProbability(0.06f))
{
- if (GetRandomControl() & 1)
+ if (TestProbability(0.5f))
item->Animation.TargetState = 10;
else
item->Animation.TargetState = 6;
@@ -361,7 +362,7 @@ namespace TEN::Entities::TR3
item->Animation.TargetState = 4;
else if (creature->Mood == MoodType::Bored)
{
- if (GetRandomControl() < 256)
+ if (TestProbability(0.008f))
item->Animation.TargetState = 6;
}
else if (AI.bite && AI.distance < pow(682, 2))
diff --git a/TombEngine/Objects/TR3/Entity/tr3_mp_gun.cpp b/TombEngine/Objects/TR3/Entity/tr3_mp_gun.cpp
index 2526236f9..a46c432c2 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_mp_gun.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_mp_gun.cpp
@@ -14,8 +14,11 @@
#include "Game/people.h"
#include "Sound/sound.h"
#include "Specific/level.h"
+#include "Specific/prng.h"
#include "Specific/setup.h"
+using namespace TEN::Math::Random;
+
namespace TEN::Entities::TR3
{
const auto MPGunBite = BiteInfo(Vector3(0.0f, 160.0f, 40.0f), 13);
@@ -76,8 +79,8 @@ namespace TEN::Entities::TR3
if (item->BoxNumber != NO_BOX && (g_Level.Boxes[item->BoxNumber].flags & BLOCKED))
{
- DoLotsOfBlood(item->Pose.Position.x, item->Pose.Position.y - (GetRandomControl() & 255) - 32, item->Pose.Position.z, (GetRandomControl() & 127) + 128, GetRandomControl() * 2, item->RoomNumber, 3);
DoDamage(item, 20);
+ DoLotsOfBlood(item->Pose.Position.x, item->Pose.Position.y - (GetRandomControl() & 255) - 32, item->Pose.Position.z, (GetRandomControl() & 127) + 128, GetRandomControl() * 2, item->RoomNumber, 3);
}
AI_INFO AI;
@@ -91,7 +94,7 @@ namespace TEN::Entities::TR3
item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
item->Animation.ActiveState = 13;
}
- else if (!(GetRandomControl() & 3) && item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase + 1)
+ else if (TestProbability(0.25f) && item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase + 1)
{
CreatureAIInfo(item, &AI);
@@ -220,10 +223,9 @@ namespace TEN::Entities::TR3
item->Animation.TargetState = MPGUN_STATE_RUN;
else if (Targetable(item, &AI))
{
- int random = GetRandomControl();
- if (random < 0x2000)
+ if (TestProbability(0.25f))
item->Animation.TargetState = MPGUN_STATE_SHOOT_1;
- else if (random < 0x4000)
+ else if (TestProbability(0.5f))
item->Animation.TargetState = MPGUN_STATE_SHOOT_2;
else
item->Animation.TargetState = MPGUN_STATE_AIM_3;
@@ -315,7 +317,7 @@ namespace TEN::Entities::TR3
if (!ShotLara(item, &AI, MPGunBite, torsoY, 32))
item->Animation.RequiredState = MPGUN_STATE_WAIT;
}
- else if (item->HitStatus && !(GetRandomControl() & 0x3) && cover)
+ else if (item->HitStatus && TestProbability(0.25f) && cover)
{
item->Animation.RequiredState = MPGUN_STATE_CROUCH;
item->Animation.TargetState = MPGUN_STATE_WAIT;
@@ -347,7 +349,7 @@ namespace TEN::Entities::TR3
if (!ShotLara(item, &AI, MPGunBite, torsoY, 32))
item->Animation.TargetState = MPGUN_STATE_WAIT;
}
- else if (item->HitStatus && !(GetRandomControl() & 0x3) && cover)
+ else if (item->HitStatus && TestProbability(0.25f) && cover)
{
item->Animation.RequiredState = MPGUN_STATE_CROUCH;
item->Animation.TargetState = MPGUN_STATE_WAIT;
@@ -369,7 +371,7 @@ namespace TEN::Entities::TR3
if (!ShotLara(item, &AI, MPGunBite, torsoY, 32))
item->Animation.TargetState = MPGUN_STATE_WAIT;
}
- else if (item->HitStatus && !(GetRandomControl() & 0x3) && cover)
+ else if (item->HitStatus && TestProbability(0.25f) && cover)
{
item->Animation.RequiredState = MPGUN_STATE_CROUCH;
item->Animation.TargetState = MPGUN_STATE_WAIT;
@@ -390,7 +392,7 @@ namespace TEN::Entities::TR3
if (!ShotLara(item, &AI, MPGunBite, torsoY, 32))
item->Animation.RequiredState = MPGUN_STATE_WALK;
}
- else if (item->HitStatus && !(GetRandomControl() & 0x3) && cover)
+ else if (item->HitStatus && TestProbability(0.25f) && cover)
{
item->Animation.RequiredState = MPGUN_STATE_CROUCH;
item->Animation.TargetState = MPGUN_STATE_WAIT;
@@ -431,7 +433,7 @@ namespace TEN::Entities::TR3
if (Targetable(item, &AI))
item->Animation.TargetState = MPGUN_STATE_CROUCH_AIM;
- else if (item->HitStatus || !cover || (AI.ahead && !(GetRandomControl() & 0x1F)))
+ else if (item->HitStatus || !cover || (AI.ahead && TestProbability(0.03f)))
item->Animation.TargetState = MPGUN_STATE_STAND;
else
item->Animation.TargetState = MPGUN_STATE_CROUCH_WALK;
@@ -457,7 +459,7 @@ namespace TEN::Entities::TR3
if (item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase)
{
- if (!ShotLara(item, &AI, MPGunBite, torsoY, 32) || !(GetRandomControl() & 0x7))
+ if (!ShotLara(item, &AI, MPGunBite, torsoY, 32) || TestProbability(0.125f))
item->Animation.TargetState = MPGUN_STATE_CROUCHED;
}
@@ -469,7 +471,7 @@ namespace TEN::Entities::TR3
if (AI.ahead)
head = AI.angle;
- if (Targetable(item, &AI) || item->HitStatus || !cover || (AI.ahead && !(GetRandomControl() & 0x1F)))
+ if (Targetable(item, &AI) || item->HitStatus || !cover || (AI.ahead && TestProbability(0.03f)))
item->Animation.TargetState = MPGUN_STATE_CROUCHED;
break;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_mp_stick.cpp b/TombEngine/Objects/TR3/Entity/tr3_mp_stick.cpp
index 94676c6f2..3378fed0e 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_mp_stick.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_mp_stick.cpp
@@ -11,8 +11,10 @@
#include "Game/people.h"
#include "Sound/sound.h"
#include "Specific/level.h"
+#include "Specific/prng.h"
#include "Specific/setup.h"
+using namespace TEN::Math::Random;
using std::vector;
namespace TEN::Entities::TR3
@@ -20,7 +22,7 @@ namespace TEN::Entities::TR3
const auto MPStickBite1 = BiteInfo(Vector3(247.0f, 10.0f, 11.0f), 13);
const auto MPStickBite2 = BiteInfo(Vector3(0.0f, 0.0f, 100.0f), 6);
const vector MPStickPunchAttackJoints = { 10, 13 };
- const vector MPStickKickAttackJoints = { 5, 6 };
+ const vector MPStickKickAttackJoints = { 5, 6 };
enum MPStickState
{
@@ -184,7 +186,7 @@ namespace TEN::Entities::TR3
if (item->AIBits & GUARD)
{
head = AIGuard(creature);
- if (!(GetRandomControl() & 0xFF))
+ if (TestProbability(0.004f))
{
if (item->Animation.ActiveState == MPSTICK_STATE_STOP)
item->Animation.TargetState = MPSTICK_STATE_WAIT;
@@ -240,7 +242,7 @@ namespace TEN::Entities::TR3
item->Animation.TargetState = MPSTICK_STATE_RUN;
else if (creature->Mood == MoodType::Bored)
{
- if (GetRandomControl() < 0x100)
+ if (TestProbability(0.008f))
{
item->Animation.RequiredState = MPSTICK_STATE_WAIT;
item->Animation.TargetState = MPSTICK_STATE_STOP;
@@ -458,8 +460,8 @@ namespace TEN::Entities::TR3
if (creature->Flags != 1 && item->TestBits(JointBitType::Touch, MPStickKickAttackJoints) &&
item->Animation.FrameNumber > g_Level.Anims[item->Animation.AnimNumber].frameBase + 8)
{
- CreatureEffect(item, MPStickBite2, DoBloodSplat);
DoDamage(enemy, 150);
+ CreatureEffect(item, MPStickBite2, DoBloodSplat);
SoundEffect(SFX_TR4_LARA_THUD, &item->Pose);
creature->Flags = 1;
}
@@ -473,10 +475,10 @@ namespace TEN::Entities::TR3
abs(enemy->Pose.Position.y - item->Pose.Position.y) <= SECTOR(0.25f) &&
abs(enemy->Pose.Position.z - item->Pose.Position.z) < SECTOR(0.25f))
{
- creature->Flags = 1;
- CreatureEffect(item, MPStickBite2, DoBloodSplat);
DoDamage(enemy, 9);
+ CreatureEffect(item, MPStickBite2, DoBloodSplat);
SoundEffect(SFX_TR4_LARA_THUD, &item->Pose);
+ creature->Flags = 1;
}
}
}
diff --git a/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp b/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp
index 9f1829f04..5a1864f7b 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp
@@ -86,7 +86,7 @@ namespace TEN::Entities::TR3
}
else
{
- if (creature->Enemy == nullptr || !(GetRandomControl() & 0x7F)) // TODO: Probability is 0.004f or 0.996f?
+ if (creature->Enemy == nullptr || TestProbability(0.008f))
{
ItemInfo* nearestItem = nullptr;
int minDistance = INT_MAX;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_tribesman.cpp b/TombEngine/Objects/TR3/Entity/tr3_tribesman.cpp
index 7eac71702..f8abb0681 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_tribesman.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_tribesman.cpp
@@ -280,6 +280,7 @@ namespace TEN::Entities::TR3
case TRIBESMAN_STATE_AXE_ATTACK_HIGH_START:
creature->MaxTurn = ANGLE(4.0f);
+
if (AI.bite || AI.distance < pow(682, 2))
item->Animation.TargetState = TRIBESMAN_STATE_AXE_ATTACK_HIGH_CONTINUE;
else
@@ -452,7 +453,7 @@ namespace TEN::Entities::TR3
torsoX = 0;
torsoY = 0;
- if (!(GetRandomControl() & 0xFF))
+ if (TestProbability(0.004f))
item->Animation.TargetState = TRIBESMAN_STATE_IDLE;
break;
@@ -493,7 +494,7 @@ namespace TEN::Entities::TR3
torsoX = 0;
torsoY = 0;
- if (!(GetRandomControl() & 0xFF))
+ if (TestProbability(0.004f))
item->Animation.TargetState = TRIBESMAN_STATE_CROUCH_IDLE;
break;
diff --git a/TombEngine/Objects/TR5/Entity/tr5_autoguns.cpp b/TombEngine/Objects/TR5/Entity/tr5_autoguns.cpp
index b56f70de7..380cc0bfb 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_autoguns.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_autoguns.cpp
@@ -1,14 +1,18 @@
#include "framework.h"
-#include "tr5_autoguns.h"
-#include "Game/collision/sphere.h"
-#include "Game/Lara/lara.h"
+#include "Objects/TR5/Entity/tr5_autoguns.h"
+
#include "Game/animation.h"
+#include "Game/collision/sphere.h"
#include "Game/control/los.h"
#include "Game/effects/effects.h"
#include "Game/effects/tomb4fx.h"
+#include "Game/items.h"
+#include "Game/Lara/lara.h"
#include "Specific/level.h"
#include "Sound/sound.h"
-#include "Game/items.h"
+#include "Specific/prng.h"
+
+using namespace TEN::Math::Random;
namespace TEN::Entities::TR5
{
@@ -64,10 +68,10 @@ namespace TEN::Entities::TR5
item->MeshBits = 1664;
- GameVector pos1 = { 0, 0, -64 };
+ auto pos1 = GameVector(0, 0, -64);
GetJointAbsPosition(item, (Vector3Int*)&pos1, 8);
- GameVector pos2 = { 0, 0, 0 };
+ auto pos2 = GameVector();
GetLaraJointPosition((Vector3Int*)&pos2, 0);
pos1.roomNumber = item->RoomNumber;
@@ -95,7 +99,7 @@ namespace TEN::Entities::TR5
data[1] = item->ItemFlags[1];
data[2] += item->ItemFlags[2];
- if (abs(angle1) < 1024 && abs(angle2) < 1024 && los)
+ if (abs(angle1) < ANGLE(5.6f) && abs(angle2) < ANGLE(5.6f) && los)
{
SoundEffect(SFX_TR4_HK_FIRE, &item->Pose, SoundEnvironment::Land, 0.8f);
@@ -105,10 +109,10 @@ namespace TEN::Entities::TR5
TriggerDynamicLight(pos1.x, pos1.y, pos1.z, 10, (GetRandomControl() & 0x1F) + 192, (GetRandomControl() & 0x1F) + 128, 0);
- if (GetRandomControl() & 3)
+ if (TestProbability(0.75f))
{
- auto pos2 = Vector3Int();
- GetLaraJointPosition((Vector3Int*)&pos2, GetRandomControl() % 15);
+ auto pos2 = Vector3Int::Zero;
+ GetLaraJointPosition(&pos2, GetRandomControl() % 15);
DoBloodSplat(pos2.x, pos2.y, pos2.z, (GetRandomControl() & 3) + 3, 2 * GetRandomControl(), LaraItem->RoomNumber);
DoDamage(LaraItem, 20);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_chef.cpp b/TombEngine/Objects/TR5/Entity/tr5_chef.cpp
index d61157779..6e58f1cda 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_chef.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_chef.cpp
@@ -1,16 +1,17 @@
#include "framework.h"
-#include "tr5_chef.h"
+#include "Objects/TR5/Entity/tr5_chef.h"
+
#include "Game/items.h"
#include "Game/control/box.h"
#include "Game/effects/effects.h"
#include "Game/effects/tomb4fx.h"
-#include "Game/people.h"
-#include "Specific/setup.h"
-#include "Specific/level.h"
+#include "Game/itemdata/creature_info.h"
#include "Game/Lara/lara.h"
#include "Game/misc.h"
+#include "Game/people.h"
#include "Sound/sound.h"
-#include "Game/itemdata/creature_info.h"
+#include "Specific/level.h"
+#include "Specific/setup.h"
namespace TEN::Entities::TR5
{
diff --git a/TombEngine/Objects/TR5/Entity/tr5_doberman.cpp b/TombEngine/Objects/TR5/Entity/tr5_doberman.cpp
index 9447b3418..7c386d4bd 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_doberman.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_doberman.cpp
@@ -1,14 +1,18 @@
#include "framework.h"
-#include "tr5_doberman.h"
+#include "Objects/TR5/Entity/tr5_doberman.h"
+
#include "Game/control/box.h"
-#include "Game/effects/effects.h"
-#include "Specific/setup.h"
-#include "Specific/level.h"
-#include "Game/Lara/lara.h"
-#include "Game/itemdata/creature_info.h"
#include "Game/control/control.h"
+#include "Game/effects/effects.h"
+#include "Game/itemdata/creature_info.h"
#include "Game/items.h"
+#include "Game/Lara/lara.h"
#include "Game/misc.h"
+#include "Specific/level.h"
+#include "Specific/prng.h"
+#include "Specific/setup.h"
+
+using namespace TEN::Math::Random;
namespace TEN::Entities::TR5
{
@@ -106,20 +110,21 @@ namespace TEN::Entities::TR5
item->Animation.TargetState = DOBERMAN_STATE_RUN_FORWARD;
else
{
- int random = GetRandomControl();
- if (random < 768)
+ if (TestProbability(0.025f))
{
item->Animation.RequiredState = DOBERMAN_STATE_STAND_LOW_BITE_ATTACK;
item->Animation.TargetState = DOBERMAN_STATE_STOP;
break;
}
- if (random < 1536)
+
+ if (TestProbability(0.045f))
{
item->Animation.RequiredState = DOBERMAN_STATE_SIT_IDLE;
item->Animation.TargetState = DOBERMAN_STATE_STOP;
break;
}
- if (random < 2816)
+
+ if (TestProbability(0.085f))
{
item->Animation.TargetState = DOBERMAN_STATE_STOP;
break;
@@ -146,6 +151,7 @@ namespace TEN::Entities::TR5
case DOBERMAN_STATE_STOP:
creature->MaxTurn = 0;
creature->Flags = 0;
+
if (creature->Mood != MoodType::Bored)
{
if (creature->Mood != MoodType::Escape &&
@@ -163,12 +169,11 @@ namespace TEN::Entities::TR5
item->Animation.TargetState = item->Animation.RequiredState;
else
{
- int random = GetRandomControl();
- if (random >= 768)
+ if (TestProbability(0.975f))
{
- if (random >= 1536)
+ if (TestProbability(0.95f))
{
- if (random < 9728)
+ if (TestProbability(0.3f))
item->Animation.TargetState = DOBERMAN_STATE_WALK_FORWARD;
}
else
@@ -178,22 +183,23 @@ namespace TEN::Entities::TR5
item->Animation.TargetState = DOBERMAN_STATE_STAND_LOW_BITE_ATTACK;
}
}
+
break;
case DOBERMAN_STATE_STAND_LOW_BITE_ATTACK:
- if (creature->Mood != MoodType::Bored || GetRandomControl() < 1280)
+ if (creature->Mood != MoodType::Bored || TestProbability(0.04f))
item->Animation.TargetState = DOBERMAN_STATE_STOP;
break;
case DOBERMAN_STATE_SIT_IDLE:
- if (creature->Mood != MoodType::Bored || GetRandomControl() < 256)
+ if (creature->Mood != MoodType::Bored || TestProbability(0.008f))
item->Animation.TargetState = DOBERMAN_STATE_STOP;
break;
case DOBERMAN_STATE_STAND_IDLE:
- if (creature->Mood != MoodType::Bored || GetRandomControl() < 512)
+ if (creature->Mood != MoodType::Bored || TestProbability(0.015f))
item->Animation.TargetState = DOBERMAN_STATE_STOP;
break;
@@ -201,8 +207,7 @@ namespace TEN::Entities::TR5
case DOBERMAN_STATE_STAND_HIGH_BITE_ATTACK:
creature->MaxTurn = ANGLE(0.5f);
- if (creature->Flags != 1 &&
- AI.ahead &&
+ if (creature->Flags != 1 && AI.ahead &&
item->TouchBits & 0x122000)
{
DoDamage(creature->Enemy, 30);
@@ -244,6 +249,7 @@ namespace TEN::Entities::TR5
CreatureEffect(item, DobermanBite, DoBloodSplat);
creature->Flags = 3;
}
+
if (AI.distance < pow(341, 2))
item->Animation.TargetState = DOBERMAN_STATE_STAND_HIGH_BITE_ATTACK;
diff --git a/TombEngine/Objects/TR5/Entity/tr5_gladiator.cpp b/TombEngine/Objects/TR5/Entity/tr5_gladiator.cpp
index abe2c8b45..aae3085dd 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_gladiator.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_gladiator.cpp
@@ -24,8 +24,8 @@ namespace TEN::Entities::TR5
// TODO: Ranges.
- const vector GladiatorAttackJoints = { 13, 14 };
const auto GladiatorBite = BiteInfo(Vector3::Zero, 16);
+ const vector GladiatorAttackJoints = { 13, 14 };
enum GladiatorState
{
@@ -156,7 +156,7 @@ namespace TEN::Entities::TR5
creature->Flags = 0;
if (item->AIBits & GUARD ||
- !(GetRandomControl() & 0x1F) &&
+ TestProbability(0.03f) &&
(AI.distance > pow(SECTOR(1), 2) || creature->Mood != MoodType::Attack))
{
joint2 = AIGuard(creature);
@@ -179,13 +179,12 @@ namespace TEN::Entities::TR5
else
{
if (creature->Mood == MoodType::Bored ||
- item->AIBits & FOLLOW &&
- (creature->ReachedGoal ||
- distance > pow(SECTOR(2), 2)))
+ (item->AIBits & FOLLOW &&
+ (creature->ReachedGoal || distance > pow(SECTOR(2), 2))))
{
if (item->Animation.RequiredState)
item->Animation.TargetState = item->Animation.RequiredState;
- else if (!(GetRandomControl() & 0x3F))
+ else if (TestProbability(0.015f))
item->Animation.TargetState = GLADIATOR_STATE_IDLE;
break;
@@ -194,7 +193,7 @@ namespace TEN::Entities::TR5
if (Lara.TargetEntity == item &&
unknown && distance < pow(SECTOR(1.5f), 2) &&
TestProbability(0.5f) &&
- (Lara.Control.Weapon.GunType == LaraWeaponType::Shotgun || !(GetRandomControl() & 0xF)) &&
+ (Lara.Control.Weapon.GunType == LaraWeaponType::Shotgun || TestProbability(0.06f)) &&
item->MeshBits == -1)
{
item->Animation.TargetState = GLADIATOR_STATE_GUARD_START;
@@ -242,7 +241,7 @@ namespace TEN::Entities::TR5
else if (!AI.ahead || AI.distance > pow(SECTOR(1.5f), 2))
item->Animation.TargetState = GLADIATOR_STATE_RUN_FORWARD;
}
- else if (!(GetRandomControl() & 0x3F))
+ else if (TestProbability(0.015f))
{
item->Animation.TargetState = GLADIATOR_STATE_IDLE;
break;
@@ -308,8 +307,7 @@ namespace TEN::Entities::TR5
break;
}
}
- else if (Lara.TargetEntity != item ||
- !(GetRandomControl() & 0x7F))
+ else if (Lara.TargetEntity != item || TestProbability(0.008f))
{
item->Animation.TargetState = GLADIATOR_STATE_IDLE;
break;
@@ -343,7 +341,7 @@ namespace TEN::Entities::TR5
{
auto* room = &g_Level.Rooms[item->RoomNumber];
- auto pos = Vector3Int();
+ auto pos = Vector3Int::Zero;
GetJointAbsPosition(item, &pos, 16);
auto* floor = GetSector(room, pos.x - room->x, pos.z - room->z);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_guard.cpp b/TombEngine/Objects/TR5/Entity/tr5_guard.cpp
index 33f3b89f9..aa39aee12 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_guard.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_guard.cpp
@@ -1,19 +1,23 @@
#include "framework.h"
-#include "tr5_guard.h"
-#include "Game/items.h"
+#include "Objects/TR5/Entity/tr5_guard.h"
+
+#include "Game/animation.h"
#include "Game/collision/collide_room.h"
#include "Game/control/box.h"
-#include "Game/people.h"
+#include "Game/control/los.h"
#include "Game/effects/effects.h"
#include "Game/effects/tomb4fx.h"
-#include "Game/control/los.h"
-#include "Specific/setup.h"
-#include "Game/animation.h"
-#include "Specific/level.h"
+#include "Game/itemdata/creature_info.h"
+#include "Game/items.h"
#include "Game/Lara/lara.h"
#include "Game/misc.h"
+#include "Game/people.h"
#include "Sound/sound.h"
-#include "Game/itemdata/creature_info.h"
+#include "Specific/level.h"
+#include "Specific/prng.h"
+#include "Specific/setup.h"
+
+using namespace TEN::Math::Random;
namespace TEN::Entities::TR5
{
@@ -354,7 +358,7 @@ namespace TEN::Entities::TR5
if (item->ObjectNumber == ID_SWAT_PLUS)
{
item->ItemFlags[0]++;
- if (item->ItemFlags[0] > 60 && !(GetRandomControl() & 0xF))
+ if (item->ItemFlags[0] > 60 && TestProbability(0.06f))
{
SoundEffect(SFX_TR5_BIO_BREATHE_OUT, &item->Pose);
item->ItemFlags[0] = 0;
@@ -839,7 +843,7 @@ namespace TEN::Entities::TR5
case GUARD_STATE_USE_COMPUTER:
if ((item->ObjectNumber != ID_SCIENTIST || item != Lara.TargetEntity) &&
- (GetRandomControl() & 0x7F || item->TriggerFlags >= 10 || item->TriggerFlags == 9))
+ (TestProbability(0.992f) || item->TriggerFlags >= 10 || item->TriggerFlags == 9))
{
if (item->AIBits & GUARD)
{
@@ -859,7 +863,7 @@ namespace TEN::Entities::TR5
break;
case GUARD_STATE_SURRENDER:
- if (item != Lara.TargetEntity && !(GetRandomControl() & 0x3F))
+ if (item != Lara.TargetEntity && TestProbability(0.015f))
{
if (item->TriggerFlags == 7 || item->TriggerFlags == 9)
item->Animation.RequiredState = GUARD_STATE_USE_COMPUTER;
@@ -1044,11 +1048,11 @@ namespace TEN::Entities::TR5
creature->Flags = 0;
if (!TargetVisible(item, &AI) ||
item->HitStatus &&
- GetRandomControl() & 1)
+ TestProbability(0.5f))
{
item->Animation.TargetState = SNIPER_STATE_COVER;
}
- else if (!(GetRandomControl() & 0x1F))
+ else if (TestProbability(0.03f))
item->Animation.TargetState = SNIPER_STATE_FIRE;
break;
diff --git a/TombEngine/Objects/TR5/Entity/tr5_hydra.cpp b/TombEngine/Objects/TR5/Entity/tr5_hydra.cpp
index e04af88b4..94230274b 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_hydra.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_hydra.cpp
@@ -1,18 +1,21 @@
#include "framework.h"
-#include "tr5_hydra.h"
+#include "Objects/TR5/Entity/tr5_hydra.h"
-#include "Game/items.h"
+#include "Game/Lara/lara.h"
+#include "Game/animation.h"
#include "Game/collision/collide_room.h"
#include "Game/control/box.h"
#include "Game/effects/debris.h"
#include "Game/effects/effects.h"
-#include "Specific/setup.h"
-#include "Game/animation.h"
-#include "Specific/level.h"
-#include "Game/Lara/lara.h"
+#include "Game/itemdata/creature_info.h"
+#include "Game/items.h"
#include "Game/misc.h"
#include "Sound/sound.h"
-#include "Game/itemdata/creature_info.h"
+#include "Specific/level.h"
+#include "Specific/prng.h"
+#include "Specific/setup.h"
+
+using namespace TEN::Math::Random;
namespace TEN::Entities::TR5
{
@@ -103,7 +106,7 @@ namespace TEN::Entities::TR5
spark->flags = SP_EXPDEF | SP_ROTATE | SP_DEF | SP_SCALE;
spark->rotAng = GetRandomControl() & 0xFFF;
- if (GetRandomControl() & 1)
+ if (TestProbability(0.5f))
spark->rotAdd = -32 - (GetRandomControl() & 0x1F);
else
spark->rotAdd = (GetRandomControl() & 0x1F) + 32;
@@ -227,11 +230,11 @@ namespace TEN::Entities::TR5
else if (item->TriggerFlags == 2)
tilt = ANGLE(2.8f);
- if (AI.distance >= pow(CLICK(7), 2) && GetRandomControl() & 0x1F)
+ if (AI.distance >= pow(CLICK(7), 2) && TestProbability(0.97f))
{
- if (AI.distance >= pow(SECTOR(2), 2) && GetRandomControl() & 0x1F)
+ if (AI.distance >= pow(SECTOR(2), 2) && TestProbability(0.97f))
{
- if (!(GetRandomControl() & 0xF))
+ if (TestProbability(0.06f))
item->Animation.TargetState = HYDRA_STATE_AIM;
}
else
@@ -290,7 +293,8 @@ namespace TEN::Entities::TR5
if (Lara.Control.Weapon.GunType == LaraWeaponType::Shotgun)
damage *= 3;
- if ((GetRandomControl() & 0xF) < damage && AI.distance < SQUARE(10240) && damage > 0)
+ if ((GetRandomControl() & 0xF) < damage &&
+ AI.distance < SQUARE(SECTOR(10)) && damage > 0)
{
item->Animation.TargetState = 4;
DoDamage(item, damage);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.cpp b/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.cpp
index 1cea7a9f8..149d45168 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.cpp
@@ -1,5 +1,6 @@
#include "framework.h"
#include "tr5_lagoon_witch.h"
+
#include "Game/items.h"
#include "Game/control/box.h"
#include "Game/effects/effects.h"
diff --git a/TombEngine/Objects/TR5/Entity/tr5_larson.cpp b/TombEngine/Objects/TR5/Entity/tr5_larson.cpp
index 5b5f28a08..b45c443e6 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_larson.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_larson.cpp
@@ -1,41 +1,45 @@
#include "framework.h"
-#include "tr5_larson.h"
-#include "Game/items.h"
-#include "Game/control/box.h"
-#include "Game/effects/effects.h"
-#include "Game/people.h"
-#include "Game/Lara/lara.h"
-#include "Specific/setup.h"
-#include "Specific/level.h"
-#include "Game/itemdata/creature_info.h"
-#include "Game/control/control.h"
+#include "Objects/TR5/Entity/tr5_larson.h"
+
#include "Game/animation.h"
+#include "Game/control/box.h"
+#include "Game/control/control.h"
+#include "Game/effects/effects.h"
+#include "Game/itemdata/creature_info.h"
+#include "Game/items.h"
+#include "Game/Lara/lara.h"
+#include "Game/misc.h"
+#include "Game/people.h"
+#include "Specific/level.h"
+#include "Specific/prng.h"
+#include "Specific/setup.h"
+
+using namespace TEN::Math::Random;
namespace TEN::Entities::TR5
{
-#define STATE_TR5_LARSON_STOP 1
-#define STATE_TR5_LARSON_WALK 2
-#define STATE_TR5_LARSON_RUN 3
-#define STATE_TR5_LARSON_AIM 4
-#define STATE_TR5_LARSON_DIE 5
-#define STATE_TR5_LARSON_IDLE 6
-#define STATE_TR5_LARSON_ATTACK 7
+ #define STATE_TR5_LARSON_STOP 1
+ #define STATE_TR5_LARSON_WALK 2
+ #define STATE_TR5_LARSON_RUN 3
+ #define STATE_TR5_LARSON_AIM 4
+ #define STATE_TR5_LARSON_DIE 5
+ #define STATE_TR5_LARSON_IDLE 6
+ #define STATE_TR5_LARSON_ATTACK 7
-#define ANIMATION_TR5_PIERRE_DIE 12
-#define ANIMATION_TR5_LARSON_DIE 15
+ #define ANIMATION_TR5_PIERRE_DIE 12
+ #define ANIMATION_TR5_LARSON_DIE 15
-#define TR5_LARSON_MIN_HP 40
+ #define TR5_LARSON_MIN_HP 40
- const auto LarsonGun = BiteInfo(Vector3(-55, 200, 5), 14);
- const auto PierreGun1 = BiteInfo(Vector3(60, 200, 0), 11);
- const auto PierreGun2 = BiteInfo(Vector3(-57, 200, 0), 14);
+ const auto LarsonGun = BiteInfo(Vector3(-55.0f, 200.0f, 5.0f), 14);
+ const auto PierreGun1 = BiteInfo(Vector3(60.0f, 200.0f, 0.0f), 11);
+ const auto PierreGun2 = BiteInfo(Vector3(-57.0f, 200.0f, 0.0f), 14);
void InitialiseLarson(short itemNum)
{
- ItemInfo* item = &g_Level.Items[itemNum];
+ auto* item = &g_Level.Items[itemNum];
ClearItem(itemNum);
-
item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex;
item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
item->Animation.TargetState = STATE_TR5_LARSON_STOP;
@@ -47,22 +51,14 @@ namespace TEN::Entities::TR5
item->ItemFlags[3] = item->TriggerFlags;
short rotY = item->Pose.Orientation.y;
- if (rotY > ANGLE(22.5f) && rotY < 28672)
- {
+ if (rotY > ANGLE(22.5f) && rotY < ANGLE(157.5f))
item->Pose.Position.x += STEPUP_HEIGHT;
- }
- else if (rotY < -ANGLE(22.5f) && rotY > -28672)
- {
+ else if (rotY < ANGLE(-22.5f) && rotY > ANGLE(-157.5f))
item->Pose.Position.x -= STEPUP_HEIGHT;
- }
- else if (rotY < -20480 || rotY > 20480)
- {
+ else if (rotY < ANGLE(-112.5f) || rotY > ANGLE(112.5f))
item->Pose.Position.z -= STEPUP_HEIGHT;
- }
- else if (rotY > -8192 || rotY < 8192)
- {
+ else if (rotY > ANGLE(-45.0f) || rotY < ANGLE(45.0f))
item->Pose.Position.z += STEPUP_HEIGHT;
- }
}
void LarsonControl(short itemNumber)
@@ -77,7 +73,7 @@ namespace TEN::Entities::TR5
short joint2 = 0;
auto* item = &g_Level.Items[itemNumber];
- CreatureInfo* creature = (CreatureInfo*)item->Data;
+ auto* creature = GetCreatureInfo(item);
// In Streets of Rome when Larson HP are below 40 he runs way
/*if (item->HitPoints <= TR5_LARSON_MIN_HP && !(item->flags & IFLAG_INVISIBLE))
@@ -113,6 +109,7 @@ namespace TEN::Entities::TR5
item->Collidable = false;
item->Status = ITEM_ACTIVE;
}
+
item->TriggerFlags = 0;
}
@@ -123,11 +120,11 @@ namespace TEN::Entities::TR5
else
creature->Enemy = LaraItem;
- AI_INFO info;
- CreatureAIInfo(item, &info);
+ AI_INFO AI;
+ CreatureAIInfo(item, &AI);
- if (info.ahead)
- joint2 = info.angle;
+ if (AI.ahead)
+ joint2 = AI.angle;
// FIXME: this should make Larson running away, but it's broken
/*if (creature->flags)
@@ -140,13 +137,13 @@ namespace TEN::Entities::TR5
creature->flags = 0;
}*/
- GetCreatureMood(item, &info, true);
- CreatureMood(item, &info, true);
+ GetCreatureMood(item, &AI, true);
+ CreatureMood(item, &AI, true);
- if (info.distance < SQUARE(2048)
- && LaraItem->Animation.Velocity.z > 20
- || item->HitStatus
- || TargetVisible(item, &info) != 0)
+ if (AI.distance < SQUARE(SECTOR(2)) &&
+ LaraItem->Animation.Velocity > 20 ||
+ item->HitStatus ||
+ TargetVisible(item, &AI) != 0)
{
item->Status &= ~ITEM_ACTIVE;
creature->Alerted = true;
@@ -157,40 +154,34 @@ namespace TEN::Entities::TR5
switch (item->Animation.ActiveState)
{
case STATE_TR5_LARSON_STOP:
- joint0 = info.angle / 2;
- joint2 = info.angle / 2;
- if (info.ahead)
- joint1 = info.xAngle;
+ joint0 = AI.angle / 2;
+ joint2 = AI.angle / 2;
+
+ if (AI.ahead)
+ joint1 = AI.xAngle;
if (item->Animation.RequiredState)
- {
item->Animation.TargetState = item->Animation.RequiredState;
- }
else if (item->AIBits & AMBUSH)
- {
item->Animation.TargetState = STATE_TR5_LARSON_RUN;
- }
- else if (Targetable(item, &info))
- {
+ else if (Targetable(item, &AI))
item->Animation.TargetState = STATE_TR5_LARSON_AIM;
- }
else
{
if (item->AIBits & GUARD || CurrentLevel == 2 || item->ItemFlags[3])
{
- creature->MaxTurn = 0;
item->Animation.TargetState = STATE_TR5_LARSON_STOP;
- if (abs(info.angle) >= ANGLE(2))
+ creature->MaxTurn = 0;
+
+ if (abs(AI.angle) >= ANGLE(2.0f))
{
- if (info.angle > 0)
- item->Pose.Orientation.y += ANGLE(2);
+ if (AI.angle > 0)
+ item->Pose.Orientation.y += ANGLE(2.0f);
else
- item->Pose.Orientation.y -= ANGLE(2);
+ item->Pose.Orientation.y -= ANGLE(2.0f);
}
else
- {
- item->Pose.Orientation.y += info.angle;
- }
+ item->Pose.Orientation.y += AI.angle;
}
else
{
@@ -202,69 +193,67 @@ namespace TEN::Entities::TR5
item->Animation.TargetState = STATE_TR5_LARSON_WALK;
}
else
- {
- item->Animation.TargetState = GetRandomControl() >= 96 ? 2 : 6;
- }
+ item->Animation.TargetState = TestProbability(0.997f) ? 2 : 6;
}
}
+
break;
case STATE_TR5_LARSON_WALK:
- if (info.ahead)
- joint2 = info.angle;
+ creature->MaxTurn = ANGLE(7.0f);
- creature->MaxTurn = ANGLE(7);
- if (creature->Mood == MoodType::Bored && GetRandomControl() < 96)
+ if (AI.ahead)
+ joint2 = AI.angle;
+
+ if (creature->Mood == MoodType::Bored && TestProbability(0.003f))
{
- item->Animation.RequiredState = STATE_TR5_LARSON_IDLE;
item->Animation.TargetState = STATE_TR5_LARSON_STOP;
+ item->Animation.RequiredState = STATE_TR5_LARSON_IDLE;
break;
}
if (creature->Mood == MoodType::Escape || item->AIBits & AMBUSH)
{
- item->Animation.RequiredState = STATE_TR5_LARSON_RUN;
item->Animation.TargetState = STATE_TR5_LARSON_STOP;
+ item->Animation.RequiredState = STATE_TR5_LARSON_RUN;
}
- else if (Targetable(item, &info))
+ else if (Targetable(item, &AI))
{
+ item->Animation.TargetState = STATE_TR5_LARSON_STOP;
item->Animation.RequiredState = STATE_TR5_LARSON_AIM;
- item->Animation.TargetState = STATE_TR5_LARSON_STOP;
}
- else if (!info.ahead || info.distance > SQUARE(3072))
+ else if (!AI.ahead || AI.distance > SQUARE(SECTOR(3)))
{
- item->Animation.RequiredState = STATE_TR5_LARSON_RUN;
item->Animation.TargetState = STATE_TR5_LARSON_STOP;
+ item->Animation.RequiredState = STATE_TR5_LARSON_RUN;
}
+
break;
case STATE_TR5_LARSON_RUN:
- if (info.ahead)
- joint2 = info.angle;
- creature->MaxTurn = ANGLE(11);
tilt = angle / 2;
+ creature->MaxTurn = ANGLE(11.0f);
+
+ if (AI.ahead)
+ joint2 = AI.angle;
if (creature->ReachedGoal)
- {
item->Animation.TargetState = STATE_TR5_LARSON_STOP;
- }
else if (item->AIBits & AMBUSH)
- {
item->Animation.TargetState = STATE_TR5_LARSON_RUN;
- }
- else if (creature->Mood != MoodType::Bored || GetRandomControl() >= 96)
+ else if (creature->Mood != MoodType::Bored || TestProbability(0.997f))
{
- if (Targetable(item, &info))
+ if (Targetable(item, &AI))
{
- item->Animation.RequiredState = STATE_TR5_LARSON_AIM;
item->Animation.TargetState = STATE_TR5_LARSON_STOP;
+ item->Animation.RequiredState = STATE_TR5_LARSON_AIM;
}
- else if (info.ahead)
+ else if (AI.ahead)
{
- if (info.distance <= SQUARE(3072))
+ if (AI.distance <= SQUARE(SECTOR(3)))
{
- item->Animation.RequiredState = STATE_TR5_LARSON_WALK;
item->Animation.TargetState = STATE_TR5_LARSON_STOP;
+ item->Animation.RequiredState = STATE_TR5_LARSON_WALK;
}
}
}
@@ -273,104 +262,108 @@ namespace TEN::Entities::TR5
item->Animation.RequiredState = STATE_TR5_LARSON_IDLE;
item->Animation.TargetState = STATE_TR5_LARSON_STOP;
}
+
break;
case STATE_TR5_LARSON_AIM:
- joint0 = info.angle / 2;
- joint2 = info.angle / 2;
- if (info.ahead)
- joint1 = info.xAngle;
+ joint0 = AI.angle / 2;
+ joint2 = AI.angle / 2;
creature->MaxTurn = 0;
- if (abs(info.angle) >= ANGLE(2))
+
+ if (AI.ahead)
+ joint1 = AI.xAngle;
+
+ if (abs(AI.angle) >= ANGLE(2.0f))
{
- if (info.angle > 0)
- item->Pose.Orientation.y += ANGLE(2);
+ if (AI.angle > 0)
+ item->Pose.Orientation.y += ANGLE(2.0f);
else
- item->Pose.Orientation.y -= ANGLE(2);
+ item->Pose.Orientation.y -= ANGLE(2.0f);
}
else
- {
- item->Pose.Orientation.y += info.angle;
- }
+ item->Pose.Orientation.y += AI.angle;
- if (Targetable(item, &info))
+ if (Targetable(item, &AI))
item->Animation.TargetState = STATE_TR5_LARSON_ATTACK;
else
item->Animation.TargetState = STATE_TR5_LARSON_STOP;
+
break;
case STATE_TR5_LARSON_IDLE:
- joint0 = info.angle / 2;
- joint2 = info.angle / 2;
- if (info.ahead)
- joint1 = info.xAngle;
+ joint0 = AI.angle / 2;
+ joint2 = AI.angle / 2;
+
+ if (AI.ahead)
+ joint1 = AI.xAngle;
if (creature->Mood != MoodType::Bored)
- {
item->Animation.TargetState = STATE_TR5_LARSON_STOP;
- }
else
{
- if (GetRandomControl() <= 96)
+ if (TestProbability(0.003f))
{
- item->Animation.RequiredState = STATE_TR5_LARSON_WALK;
item->Animation.TargetState = STATE_TR5_LARSON_STOP;
+ item->Animation.RequiredState = STATE_TR5_LARSON_WALK;
}
}
+
break;
case STATE_TR5_LARSON_ATTACK:
- joint0 = info.angle / 2;
- joint2 = info.angle / 2;
- if (info.ahead)
- joint1 = info.xAngle;
+ joint0 = AI.angle / 2;
+ joint2 = AI.angle / 2;
creature->MaxTurn = 0;
- if (abs(info.angle) >= ANGLE(2))
+
+ if (AI.ahead)
+ joint1 = AI.xAngle;
+
+ if (abs(AI.angle) >= ANGLE(2.0f))
{
- if (info.angle > 0)
- item->Pose.Orientation.y += ANGLE(2);
+ if (AI.angle > 0)
+ item->Pose.Orientation.y += ANGLE(2.0f);
else
- item->Pose.Orientation.y -= ANGLE(2);
+ item->Pose.Orientation.y -= ANGLE(2.0f);
}
else
- {
- item->Pose.Orientation.y += info.angle;
- }
+ item->Pose.Orientation.y += AI.angle;
+
if (item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase)
{
if (item->ObjectNumber == ID_PIERRE)
{
- ShotLara(item, &info, PierreGun1, joint0, 20);
- ShotLara(item, &info, PierreGun2, joint0, 20);
+ ShotLara(item, &AI, PierreGun1, joint0, 20);
+ ShotLara(item, &AI, PierreGun2, joint0, 20);
}
else
- {
- ShotLara(item, &info, LarsonGun, joint0, 20);
- }
+ ShotLara(item, &AI, LarsonGun, joint0, 20);
+
creature->FiredWeapon = 2;
}
- if (creature->Mood == MoodType::Escape && GetRandomControl() > 0x2000)
+
+ if (creature->Mood == MoodType::Escape && TestProbability(0.75f))
item->Animation.RequiredState = STATE_TR5_LARSON_STOP;
+
break;
default:
break;
-
}
}
else if (item->Animation.ActiveState == STATE_TR5_LARSON_DIE)
{
// When Larson dies, it activates trigger at start position
- if (item->ObjectNumber == ID_LARSON
- && item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameEnd)
+ if (item->ObjectNumber == ID_LARSON &&
+ item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameEnd)
{
short roomNumber = item->ItemFlags[2] & 0xFF;
short floorHeight = item->ItemFlags[2] & 0xFF00;
- ROOM_INFO* r = &g_Level.Rooms[roomNumber];
- int x = r->x + (creature->Tosspad / 256 & 0xFF) * SECTOR(1) + 512;
- int y = r->minfloor + floorHeight;
- int z = r->z + (creature->Tosspad & 0xFF) * SECTOR(1) + 512;
+ auto* room = &g_Level.Rooms[roomNumber];
+
+ int x = room->x + (creature->Tosspad / 256 & 0xFF) * SECTOR(1) + 512;
+ int y = room->minfloor + floorHeight;
+ int z = room->z + (creature->Tosspad & 0xFF) * SECTOR(1) + 512;
TestTriggers(x, y, z, roomNumber, true);
@@ -379,13 +372,14 @@ namespace TEN::Entities::TR5
}
else
{
- // Die
+ // Death.
if (item->ObjectNumber == ID_PIERRE)
item->Animation.AnimNumber = Objects[ID_PIERRE].animIndex + ANIMATION_TR5_PIERRE_DIE;
else
item->Animation.AnimNumber = Objects[ID_LARSON].animIndex + ANIMATION_TR5_LARSON_DIE;
- item->Animation.ActiveState = STATE_TR5_LARSON_DIE;
+
item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
+ item->Animation.ActiveState = STATE_TR5_LARSON_DIE;
}
CreatureTilt(item, tilt);
From 30bd87164b633569ef1e502951b0e756bf4b0ed3 Mon Sep 17 00:00:00 2001
From: Sezz
Date: Wed, 17 Aug 2022 16:43:07 +1000
Subject: [PATCH 006/106] Convert probabilities
---
TombEngine/Objects/TR1/Entity/tr1_ape.cpp | 8 ++++----
TombEngine/Objects/TR1/Entity/tr1_bear.cpp | 18 ++++++++++--------
TombEngine/Objects/TR1/Entity/tr1_centaur.cpp | 14 ++++++++------
.../Objects/TR1/Entity/tr1_giant_mutant.cpp | 13 ++++++++-----
TombEngine/Objects/TR1/Entity/tr1_natla.cpp | 8 ++++++--
.../Objects/TR1/Entity/tr1_winged_mutant.cpp | 12 +++++++-----
TombEngine/Objects/TR1/Entity/tr1_wolf.cpp | 14 ++++++++------
7 files changed, 51 insertions(+), 36 deletions(-)
diff --git a/TombEngine/Objects/TR1/Entity/tr1_ape.cpp b/TombEngine/Objects/TR1/Entity/tr1_ape.cpp
index 274645477..b4a66dcda 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_ape.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_ape.cpp
@@ -22,10 +22,10 @@ namespace TEN::Entities::TR1
constexpr auto APE_ATTACK_RANGE = SQUARE(SECTOR(0.42f));
constexpr auto APE_PANIC_RANGE = SQUARE(SECTOR(2));
- constexpr auto APE_JUMP_CHANCE = 0xA0;
- constexpr auto APE_POUND_CHEST_CHANCE = APE_JUMP_CHANCE + 0xA0;
- constexpr auto APE_POUND_GROUND_CHANCE = APE_POUND_CHEST_CHANCE + 0xA0;
- constexpr auto APE_RUN_LEFT_CHANCE = APE_POUND_GROUND_CHANCE + 0xA0;
+ constexpr auto APE_JUMP_CHANCE = 0.005f;
+ constexpr auto APE_POUND_CHEST_CHANCE = 0.01f;
+ constexpr auto APE_POUND_GROUND_CHANCE = 0.015f;
+ constexpr auto APE_RUN_LEFT_CHANCE = 0.02f;
constexpr auto SHIFT = 75;
diff --git a/TombEngine/Objects/TR1/Entity/tr1_bear.cpp b/TombEngine/Objects/TR1/Entity/tr1_bear.cpp
index 0038f9e06..49cf01acb 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_bear.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_bear.cpp
@@ -9,8 +9,10 @@
#include "Game/Lara/lara.h"
#include "Game/misc.h"
#include "Specific/level.h"
+#include "Specific/prng.h"
#include "Specific/setup.h"
+using namespace TEN::Math::Random;
using std::vector;
namespace TEN::Entities::TR1
@@ -24,10 +26,10 @@ namespace TEN::Entities::TR1
constexpr auto BEAR_REAR_RANGE = SECTOR(2);
constexpr auto BEAR_REAR_SWIPE_ATTACK_RANGE = SECTOR(0.6f);
constexpr auto BEAR_EAT_RANGE = CLICK(3);
-
- constexpr auto BEAR_ROAR_CHANCE = 0x50;
- constexpr auto BEAR_REAR_CHANCE = 0x300;
- constexpr auto BEAR_DROP_CHANCE = 0x600;
+
+ constexpr auto BEAR_ROAR_CHANCE = 0.0025f;
+ constexpr auto BEAR_REAR_CHANCE = 0.025f;
+ constexpr auto BEAR_DROP_CHANCE = 0.045f;
#define BEAR_WALK_TURN_RATE_MAX ANGLE(2.0f)
#define BEAR_RUN_TURN_RATE_MAX ANGLE(5.0f)
@@ -174,7 +176,7 @@ namespace TEN::Entities::TR1
if (creature->Mood == MoodType::Escape)
item->Animation.RequiredState = BEAR_STATE_STROLL;
}
- else if (GetRandomControl() < BEAR_ROAR_CHANCE)
+ else if (TestProbability(BEAR_ROAR_CHANCE))
{
item->Animation.RequiredState = BEAR_STATE_ROAR;
item->Animation.TargetState = BEAR_STATE_IDLE;
@@ -195,7 +197,7 @@ namespace TEN::Entities::TR1
else if (AI.ahead && !item->Animation.RequiredState)
{
if (AI.distance < pow(BEAR_REAR_RANGE, 2) &&
- GetRandomControl() < BEAR_REAR_CHANCE &&
+ TestProbability(BEAR_REAR_CHANCE) &&
!creature->Flags)
{
item->Animation.RequiredState = BEAR_STATE_REAR;
@@ -237,12 +239,12 @@ namespace TEN::Entities::TR1
item->Animation.TargetState = BEAR_STATE_REAR;
item->Animation.RequiredState = BEAR_STATE_STROLL;
}
- else if (creature->Mood == MoodType::Bored || GetRandomControl() < BEAR_ROAR_CHANCE)
+ else if (creature->Mood == MoodType::Bored || TestProbability(BEAR_ROAR_CHANCE))
{
item->Animation.RequiredState = BEAR_STATE_ROAR;
item->Animation.TargetState = BEAR_STATE_REAR;
}
- else if (AI.distance > pow(BEAR_REAR_RANGE, 2) || GetRandomControl() < BEAR_DROP_CHANCE)
+ else if (AI.distance > pow(BEAR_REAR_RANGE, 2) || TestProbability(BEAR_DROP_CHANCE))
{
item->Animation.RequiredState = BEAR_STATE_IDLE;
item->Animation.TargetState = BEAR_STATE_REAR;
diff --git a/TombEngine/Objects/TR1/Entity/tr1_centaur.cpp b/TombEngine/Objects/TR1/Entity/tr1_centaur.cpp
index 27f76ce0a..3f9029d35 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_centaur.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_centaur.cpp
@@ -15,15 +15,17 @@
#include "Game/people.h"
#include "Sound/sound.h"
#include "Specific/level.h"
+#include "Specific/prng.h"
#include "Specific/setup.h"
+using namespace TEN::Math::Random;
using std::vector;
namespace TEN::Entities::TR1
{
constexpr auto CENTAUR_REAR_DAMAGE = 200;
constexpr auto CENTAUR_REAR_RANGE = SECTOR(1.5f);
- constexpr auto CENTAUR_REAR_CHANCE = 0x60;
+ constexpr auto CENTAUR_REAR_CHANCE = 0.003f;
constexpr auto CENTAUR_BOMB_VELOCITY = 20;
#define CENTAUR_TURN_RATE_MAX ANGLE(4.0f)
@@ -98,18 +100,18 @@ namespace TEN::Entities::TR1
case CENTAUR_STATE_RUN_FORWARD:
if (AI.bite && AI.distance < pow(CENTAUR_REAR_RANGE, 2))
{
- item->Animation.RequiredState = CENTAUR_STATE_WARNING;
item->Animation.TargetState = CENTAUR_STATE_IDLE;
+ item->Animation.RequiredState = CENTAUR_STATE_WARNING;
}
else if (Targetable(item, &AI))
{
+ item->Animation.TargetState = CENTAUR_STATE_IDLE;
item->Animation.RequiredState = CENTAUR_STATE_AIM;
- item->Animation.TargetState = CENTAUR_STATE_IDLE;
}
- else if (GetRandomControl() < CENTAUR_REAR_CHANCE)
+ else if (TestProbability(CENTAUR_REAR_CHANCE))
{
- item->Animation.RequiredState = CENTAUR_STATE_WARNING;
item->Animation.TargetState = CENTAUR_STATE_IDLE;
+ item->Animation.RequiredState = CENTAUR_STATE_WARNING;
}
break;
@@ -137,8 +139,8 @@ namespace TEN::Entities::TR1
if (!item->Animation.RequiredState &&
item->TestBits(JointBitType::Touch, CentaurAttackJoints))
{
- CreatureEffect(item, CentaurRearBite, DoBloodSplat);
DoDamage(creature->Enemy, CENTAUR_REAR_DAMAGE);
+ CreatureEffect(item, CentaurRearBite, DoBloodSplat);
item->Animation.RequiredState = CENTAUR_STATE_IDLE;
}
diff --git a/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.cpp b/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.cpp
index 7061059ec..46709db1e 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.cpp
@@ -12,8 +12,10 @@
#include "Game/misc.h"
#include "Sound/sound.h"
#include "Specific/level.h"
+#include "Specific/prng.h"
#include "Specific/setup.h"
+using namespace TEN::Math::Random;
using std::vector;
namespace TEN::Entities::TR1
@@ -24,16 +26,17 @@ namespace TEN::Entities::TR1
constexpr auto MUTANT_ATTACK_RANGE = SQUARE(SECTOR(2.5f));
constexpr auto MUTANT_CLOSE_RANGE = SQUARE(SECTOR(2.2f));
- constexpr auto MUTANT_ATTACK_1_CHANCE = 0x2AF8;
- constexpr auto MUTANT_ATTACK_2_CHANCE = 0x55F0;
+ // TODO: Unused.
+ constexpr auto MUTANT_ATTACK_1_CHANCE = 0.33f;
+ constexpr auto MUTANT_ATTACK_2_CHANCE = 0.67f;
#define MUTANT_NEED_TURN ANGLE(45.0f)
#define MUTANT_TURN ANGLE(3.0f)
#define LARA_GIANT_MUTANT_DEATH 6 // TODO: Not 13? Check this.
- const vector MutantAttackJoints = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 };
- const vector MutantAttackLeftJoints = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
+ const vector MutantAttackJoints = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 };
+ const vector MutantAttackLeftJoint = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
const vector MutantAttackRightJoints = { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 };
enum GiantMutantState
@@ -122,7 +125,7 @@ namespace TEN::Entities::TR1
else
item->Animation.TargetState = MUTANT_STATE_FORWARD;
}
- else if (GetRandomControl() < 0x4000)
+ else if (TestProbability(0.5f))
item->Animation.TargetState = MUTANT_STATE_ATTACK_1;
else
item->Animation.TargetState = MUTANT_STATE_ATTACK_2;
diff --git a/TombEngine/Objects/TR1/Entity/tr1_natla.cpp b/TombEngine/Objects/TR1/Entity/tr1_natla.cpp
index 503b169d5..f18c25f1e 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_natla.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_natla.cpp
@@ -10,8 +10,11 @@
#include "Game/people.h"
#include "Sound/sound.h"
#include "Specific/level.h"
+#include "Specific/prng.h"
#include "Specific/trmath.h"
+using namespace TEN::Math::Random;
+
namespace TEN::Entities::TR1
{
// TODO: Organise.
@@ -20,9 +23,10 @@ namespace TEN::Entities::TR1
constexpr auto NATLA_DEATH_TIME = (FPS * 16); // 16 seconds.
constexpr auto NATLA_FLYMODE = 0x8000;
constexpr auto NATLA_TIMER = 0x7FFF;
- constexpr auto NATLA_LAND_CHANCE = 0x100;
constexpr auto NATLA_GUN_VELOCITY = 400;
+ constexpr auto NATLA_LAND_CHANCE = 0.008f;
+
#define NATLA_TURN_NEAR_DEATH_SPEED ANGLE(6.0f)
#define NATLA_TURN_SPEED ANGLE(5.0f)
#define NATLA_FLY_ANGLE_SPEED ANGLE(5.0f)
@@ -183,7 +187,7 @@ namespace TEN::Entities::TR1
if (item->Animation.ActiveState == NATLA_STATE_FLY && (creature->Flags & NATLA_FLYMODE))
{
- if (creature->Flags & NATLA_FLYMODE && shoot && GetRandomControl() < NATLA_LAND_CHANCE)
+ if (creature->Flags & NATLA_FLYMODE && shoot && TestProbability(NATLA_LAND_CHANCE))
creature->Flags -= NATLA_FLYMODE;
if (!(creature->Flags & NATLA_FLYMODE))
diff --git a/TombEngine/Objects/TR1/Entity/tr1_winged_mutant.cpp b/TombEngine/Objects/TR1/Entity/tr1_winged_mutant.cpp
index 1e84f91f0..4684f4326 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_winged_mutant.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_winged_mutant.cpp
@@ -13,8 +13,10 @@
#include "Game/people.h"
#include "Sound/sound.h"
#include "Specific/level.h"
+#include "Specific/prng.h"
#include "Specific/trmath.h"
+using namespace TEN::Math::Random;
using std::vector;
namespace TEN::Entities::TR1
@@ -29,8 +31,8 @@ namespace TEN::Entities::TR1
constexpr auto WINGED_MUTANT_IDLE_JUMP_ATTACK_RANGE = SQUARE(SECTOR(2.5f));
constexpr auto WINGED_MUTANT_ATTACK_RANGE = SQUARE(SECTOR(3.75f));
- constexpr auto WINGED_MUTANT_POSE_CHANCE = 85;
- constexpr auto WINGED_MUTANT_UNPOSE_CHANCE = 200;
+ constexpr auto WINGED_MUTANT_POSE_CHANCE = 0.0025f;
+ constexpr auto WINGED_MUTANT_UNPOSE_CHANCE = 0.006f;
constexpr auto WINGED_MUTANT_FLY_VELOCITY = CLICK(1) / 8;
constexpr auto WINGED_MUTANT_SHARD_VELOCITY = 250;
@@ -337,7 +339,7 @@ namespace TEN::Entities::TR1
if (AI.distance < WINGED_MUTANT_WALK_RANGE)
{
if (AI.zoneNumber == AI.enemyZone ||
- GetRandomControl() < WINGED_MUTANT_UNPOSE_CHANCE)
+ TestProbability(WINGED_MUTANT_UNPOSE_CHANCE))
{
item->Animation.TargetState = WMUTANT_STATE_WALK_FORWARD;
}
@@ -345,7 +347,7 @@ namespace TEN::Entities::TR1
else
item->Animation.TargetState = WMUTANT_STATE_IDLE;
}
- else if (creature->Mood == MoodType::Bored && GetRandomControl() < WINGED_MUTANT_UNPOSE_CHANCE)
+ else if (creature->Mood == MoodType::Bored && TestProbability(WINGED_MUTANT_UNPOSE_CHANCE))
item->Animation.TargetState = WMUTANT_STATE_WALK_FORWARD;
else if (creature->Mood == MoodType::Attack ||
creature->Mood == MoodType::Escape)
@@ -363,7 +365,7 @@ namespace TEN::Entities::TR1
else if (creature->Mood == MoodType::Bored ||
(creature->Mood == MoodType::Stalk && AI.zoneNumber != AI.enemyZone))
{
- if (GetRandomControl() < WINGED_MUTANT_POSE_CHANCE)
+ if (TestProbability(WINGED_MUTANT_POSE_CHANCE))
item->Animation.TargetState = WMUTANT_STATE_POSE;
}
else if (creature->Mood == MoodType::Stalk &&
diff --git a/TombEngine/Objects/TR1/Entity/tr1_wolf.cpp b/TombEngine/Objects/TR1/Entity/tr1_wolf.cpp
index 20ab213b8..a8a293eb8 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_wolf.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_wolf.cpp
@@ -9,8 +9,10 @@
#include "Game/Lara/lara.h"
#include "Game/misc.h"
#include "Specific/level.h"
+#include "Specific/prng.h"
#include "Specific/setup.h"
+using namespace TEN::Math::Random;
using std::vector;
namespace TEN::Entities::TR1
@@ -21,9 +23,9 @@ namespace TEN::Entities::TR1
constexpr auto WOLF_ATTACK_RANGE = SQUARE(SECTOR(1.5f));
constexpr auto WOLF_STALK_RANGE = SQUARE(SECTOR(2));
- constexpr auto WOLF_WAKE_CHANCE = 0x20;
- constexpr auto WOLF_SLEEP_CHANCE = 0x20;
- constexpr auto WOLF_HOWL_CHANCE = 0x180;
+ constexpr auto WOLF_WAKE_CHANCE = 0.00095f;
+ constexpr auto WOLF_SLEEP_CHANCE = 0.00095f;
+ constexpr auto WOLF_HOWL_CHANCE = 0.012f;
constexpr auto WOLF_SLEEP_FRAME = 96;
@@ -110,7 +112,7 @@ namespace TEN::Entities::TR1
item->Animation.RequiredState = WOLF_STATE_CROUCH;
item->Animation.TargetState = WOLF_STATE_IDLE;
}
- else if (GetRandomControl() < WOLF_WAKE_CHANCE)
+ else if (TestProbability(WOLF_WAKE_CHANCE))
{
item->Animation.RequiredState = WOLF_STATE_WALK;
item->Animation.TargetState = WOLF_STATE_IDLE;
@@ -133,7 +135,7 @@ namespace TEN::Entities::TR1
item->Animation.TargetState = WOLF_STATE_STALK;
item->Animation.RequiredState = WOLF_STATE_NONE;
}
- else if (GetRandomControl() < WOLF_SLEEP_CHANCE)
+ else if (TestProbability(WOLF_SLEEP_CHANCE))
{
item->Animation.RequiredState = WOLF_STATE_SLEEP;
item->Animation.TargetState = WOLF_STATE_IDLE;
@@ -174,7 +176,7 @@ namespace TEN::Entities::TR1
item->Animation.TargetState = WOLF_STATE_RUN;
}
}
- else if (GetRandomControl() < WOLF_HOWL_CHANCE)
+ else if (TestProbability(WOLF_HOWL_CHANCE))
{
item->Animation.RequiredState = WOLF_STATE_HOWL;
item->Animation.TargetState = WOLF_STATE_CROUCH;
From 37a45e6d6007ba2525355626c3fbcbfe66ee4a17 Mon Sep 17 00:00:00 2001
From: Sezz
Date: Wed, 17 Aug 2022 17:19:33 +1000
Subject: [PATCH 007/106] Finish probability conversion for TR1 ape
---
TombEngine/Objects/TR1/Entity/tr1_ape.cpp | 28 ++++++++++++-----------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/TombEngine/Objects/TR1/Entity/tr1_ape.cpp b/TombEngine/Objects/TR1/Entity/tr1_ape.cpp
index b4a66dcda..23ddb3759 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_ape.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_ape.cpp
@@ -22,10 +22,14 @@ namespace TEN::Entities::TR1
constexpr auto APE_ATTACK_RANGE = SQUARE(SECTOR(0.42f));
constexpr auto APE_PANIC_RANGE = SQUARE(SECTOR(2));
- constexpr auto APE_JUMP_CHANCE = 0.005f;
- constexpr auto APE_POUND_CHEST_CHANCE = 0.01f;
- constexpr auto APE_POUND_GROUND_CHANCE = 0.015f;
- constexpr auto APE_RUN_LEFT_CHANCE = 0.02f;
+ constexpr auto APE_IDLE_JUMP_CHANCE = 0.16f;
+ constexpr auto APE_IDLE_POUND_CHEST_CHANCE = 0.32f;
+ constexpr auto APE_IDLE_POUND_GROUND_CHANCE = 0.47f;
+ constexpr auto APE_IDLE_RUN_LEFT_CHANCE = 0.63f;
+ constexpr auto APE_RUN_JUMP_CHANCE = 0.005f;
+ constexpr auto APE_RUN_POUND_CHEST_CHANCE = 0.01f;
+ constexpr auto APE_RUN_POUND_GROUND_CHANCE = 0.015f;
+ constexpr auto APE_RUN_RUN_LEFT_CHANCE = 0.02f;
constexpr auto SHIFT = 75;
@@ -207,14 +211,13 @@ namespace TEN::Entities::TR1
else if (!(creatureInfo->Flags & APE_FLAG_ATTACK) &&
AI.zoneNumber == AI.enemyZone && AI.ahead)
{
- random = (short)(GetRandomControl() / 32);
- if (random < APE_JUMP_CHANCE)
+ if (TestProbability(APE_IDLE_JUMP_CHANCE))
item->Animation.TargetState = APE_STATE_JUMP;
- else if (random < APE_POUND_CHEST_CHANCE)
+ else if (TestProbability(APE_IDLE_POUND_CHEST_CHANCE))
item->Animation.TargetState = APE_STATE_POUND_CHEST;
- else if (random < APE_POUND_GROUND_CHANCE)
+ else if (TestProbability(APE_IDLE_POUND_GROUND_CHANCE))
item->Animation.TargetState = APE_STATE_POUND_GROUND;
- else if (random < APE_RUN_LEFT_CHANCE)
+ else if (TestProbability(APE_IDLE_RUN_LEFT_CHANCE))
{
item->Animation.TargetState = APE_STATE_RUN_LEFT;
creatureInfo->MaxTurn = 0;
@@ -246,18 +249,17 @@ namespace TEN::Entities::TR1
}
else if (creatureInfo->Mood != MoodType::Escape)
{
- random = (short)GetRandomControl();
- if (random < APE_JUMP_CHANCE)
+ if (TestProbability(APE_RUN_JUMP_CHANCE))
{
item->Animation.RequiredState = APE_STATE_JUMP;
item->Animation.TargetState = APE_STATE_IDLE;
}
- else if (random < APE_POUND_CHEST_CHANCE)
+ else if (TestProbability(APE_RUN_POUND_CHEST_CHANCE))
{
item->Animation.RequiredState = APE_STATE_POUND_CHEST;
item->Animation.TargetState = APE_STATE_IDLE;
}
- else if (random < APE_POUND_GROUND_CHANCE)
+ else if (TestProbability(APE_RUN_POUND_GROUND_CHANCE))
{
item->Animation.RequiredState = APE_STATE_POUND_GROUND;
item->Animation.TargetState = APE_STATE_IDLE;
From 673b61bf74e9e957527db1b08d17ab1abe8a68ba Mon Sep 17 00:00:00 2001
From: Sezz
Date: Thu, 18 Aug 2022 21:04:11 +1000
Subject: [PATCH 008/106] Demagic tr3_monkey.cpp; cleanup
---
TombEngine/Game/control/box.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_monkey.cpp | 359 ++++++++++--------
TombEngine/Objects/TR3/Entity/tr3_shiva.cpp | 22 +-
.../Objects/TR4/Entity/tr4_von_croy.cpp | 18 +-
TombEngine/Objects/TR5/Entity/tr5_larson.cpp | 2 +-
5 files changed, 226 insertions(+), 177 deletions(-)
diff --git a/TombEngine/Game/control/box.cpp b/TombEngine/Game/control/box.cpp
index 19085c70d..f11437934 100644
--- a/TombEngine/Game/control/box.cpp
+++ b/TombEngine/Game/control/box.cpp
@@ -1170,7 +1170,7 @@ int CreatureVault(short itemNumber, short angle, int vault, int shift)
vault = 0;
else if (item->Floor > y + CHECK_CLICK(7))
vault = -4;
- // FIXME: edit assets adding climb down animations for Von Croy and baddys?
+ // FIXME: edit assets adding climb down animations for Von Croy and baddies?
else if (item->Floor > y + CHECK_CLICK(5) &&
item->ObjectNumber != ID_VON_CROY &&
item->ObjectNumber != ID_BADDY1 &&
diff --git a/TombEngine/Objects/TR3/Entity/tr3_monkey.cpp b/TombEngine/Objects/TR3/Entity/tr3_monkey.cpp
index 806106f26..63816c709 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_monkey.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_monkey.cpp
@@ -18,18 +18,80 @@ using std::vector;
namespace TEN::Entities::TR3
{
+ // TODO: Work out damage constants.
+ constexpr auto MONKEY_SWIPE_ATTACK_PLAYER_DAMAGE = 40;
+ constexpr auto MONKEY_SWIPE_ATTACK_CREATURE_DAMAGE = 20;
+
+ // TODO: Range constants.
+
const auto MonkeyBite = BiteInfo(Vector3(10.0f, 10.0f, 11.0f), 13);
const vector MonkeyAttackJoints = { 10, 13 };
+ enum MonkeyState
+ {
+ // No states 0-1.
+ MONKEY_STATE_WALK_FORWARD = 2,
+ MONKEY_STATE_IDLE = 3,
+ MONKEY_STATE_RUN_FORWARD = 4,
+ MONKEY_STATE_BITE_ATTACK = 5, // Check.
+ MONKEY_STATE_SIT = 6,
+ MONKEY_STATE_SIT_EAT = 7,
+ MONKEY_STATE_SIT_SCRATCH = 8,
+ MONKEY_STATE_RUN_FORWARD_ROLL = 9,
+ MONKEY_STATE_POUND_GROUND = 10,
+ MONKEY_STATE_DEATH = 11,
+ MONKEY_STATE_SWIPE_ATTACK = 12,
+ MONKEY_STATE_JUMP_ATTACK = 13,
+ MONKEY_STATE_HIGH_JUMP_ATTACK = 14,
+ MONKEY_STATE_VAULT_UP_1_BLOCK = 15,
+ MONKEY_STATE_VAULT_UP_0_POINT_3_BLOCKS = 16,
+ MONKEY_STATE_VAULT_UP_0_POINT_2_BLOCKS = 17,
+ MONKEY_STATE_VAULT_DOWN_1_BLOCK = 18,
+ MONKEY_STATE_VAULT_DOWN_0_POINT_3_BLOCKS = 19,
+ MONKEY_STATE_VAULT_DOWN_0_POINT_2_BLOCKS = 20
+ };
+
+ enum MonkeyAnim
+ {
+ MONKEY_ANIM_WALK_FORWARD = 0,
+ MONKEY_ANIM_WALK_FORWARD_TO_SIT = 1,
+ MONKEY_ANIM_SIT = 2,
+ MONKEY_ANIM_SIT_TO_WALK_FORWARD = 3,
+ MONKEY_ANIM_SIT_EAT = 4,
+ MONKEY_ANIM_SIT_SCRATCH = 5,
+ MONKEY_ANIM_RUN_FORWARD = 6,
+ MONKEY_ANIM_RUN_FORWARD_ROLL = 7,
+ MONKEY_ANIM_IDLE_POUND_GROUND = 8,
+ MONKEY_ANIM_IDLE = 9,
+ MONKEY_ANIM_IDLE_TO_RUN_FORWARD = 10,
+ MONKEY_ANIM_WALK_FORWARD_TO_RUN_FORWARD = 11,
+ MONKEY_ANIM_RUN_FORWARD_TO_IDLE = 12,
+ MONKEY_ANIM_SIT_TO_IDLE = 13,
+ MONKEY_ANIM_DEATH = 14,
+ MONKEY_ANIM_RUN_FORWARD_TO_WALK_FORWARD = 15,
+ MONKEY_ANIM_IDLE_TO_SIT = 16,
+ MONKEY_ANIM_VAULT_UP_1_BLOCK = 17,
+ MONKEY_ANIM_VAULT_UP_0_POINT_3_BLOCKS = 18,
+ MONKEY_ANIM_VAULT_UP_0_POINT_2_BLOCKS = 19,
+ MONKEY_ANIM_VAULT_DOWN_1_BLOCK = 20,
+ MONKEY_ANIM_VAULT_DOWN_0_POINT_3_BLOCKS = 21,
+ MONKEY_ANIM_VAULT_DOWN_0_POINT_2_BLOCKS = 22,
+ MONKEY_ANIM_SWIPE_ATTACK = 23,
+ MONKEY_ANIM_JUMP_ATTACK = 24,
+ MONKEY_ANIM_BITE_ATTACK = 25,
+ MONKEY_ANIM_HIGH_JUMP_ATTACK_START = 26,
+ MONKEY_ANIM_HIGH_JUMP_ATTACK_CONTINUE = 27,
+ MONKEY_ANIM_HIGH_JUMP_ATTACK_END = 28,
+ MONKEY_ANIM_IDLE_TO_WALK_FORWARD = 29,
+ MONKEY_ANIM_WALK_FORWARD_TO_IDLE = 30
+ };
+
void InitialiseMonkey(short itemNumber)
{
auto* item = &g_Level.Items[itemNumber];
ClearItem(itemNumber);
- item->Animation.AnimNumber = Objects[ID_MONKEY].animIndex + 2;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = 6;
- item->Animation.TargetState = 6;
+ SetAnimation(item, MONKEY_ANIM_SIT);
}
void MonkeyControl(short itemNumber)
@@ -40,20 +102,17 @@ namespace TEN::Entities::TR3
auto* item = &g_Level.Items[itemNumber];
auto* creature = GetCreatureInfo(item);
- short headX = 0;
- short headY = 0;
- short torsoY = 0;
short angle = 0;
short tilt = 0;
+ auto extraHeadRot = Vector3Shrt::Zero;
+ auto extraTorsoRot = Vector3Shrt::Zero;
if (item->HitPoints <= 0)
{
- if (item->Animation.ActiveState != 11)
+ if (item->Animation.ActiveState != MONKEY_STATE_DEATH)
{
+ SetAnimation(item, MONKEY_ANIM_DEATH);
item->MeshBits = ALL_JOINT_BITS;
- item->Animation.AnimNumber = Objects[ID_MONKEY].animIndex + 14;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = 11;
}
}
else
@@ -64,12 +123,11 @@ namespace TEN::Entities::TR3
creature->Enemy = LaraItem;
else
{
- int minDistance = 0x7FFFFFFF;
creature->Enemy = nullptr;
+ int minDistance = INT_MAX;
- for (int i = 0; i < ActiveCreatures.size(); i++)
+ for (auto& currentCreature : ActiveCreatures)
{
- auto* currentCreature = ActiveCreatures[i];
if (currentCreature->ItemNumber == NO_ITEM || currentCreature->ItemNumber == itemNumber)
continue;
@@ -110,11 +168,11 @@ namespace TEN::Entities::TR3
AI_INFO AI;
CreatureAIInfo(item, &AI);
- if (!creature->HurtByLara && creature->Enemy == LaraItem)
+ if (!creature->HurtByLara && creature->Enemy->IsLara())
creature->Enemy = nullptr;
AI_INFO laraAI;
- if (creature->Enemy == LaraItem)
+ if (creature->Enemy->IsLara())
{
laraAI.angle = AI.angle;
laraAI.distance = AI.distance;
@@ -147,144 +205,147 @@ namespace TEN::Entities::TR3
switch (item->Animation.ActiveState)
{
- case 6:
- creature->Flags = 0;
+ case MONKEY_STATE_SIT:
creature->MaxTurn = 0;
- torsoY = laraAI.angle;
+ creature->Flags = 0;
+ extraTorsoRot.y = laraAI.angle;
if (item->AIBits & GUARD)
{
- torsoY = AIGuard(creature);
+ extraTorsoRot.y = AIGuard(creature);
if (TestProbability(0.06f))
{
if (TestProbability(0.5f))
- item->Animation.TargetState = 8;
+ item->Animation.TargetState = MONKEY_STATE_SIT_EAT;
else
- item->Animation.TargetState = 7;
+ item->Animation.TargetState = MONKEY_STATE_SIT_SCRATCH;
}
break;
}
-
else if (item->AIBits & PATROL1)
- item->Animation.TargetState = 2;
+ item->Animation.TargetState = MONKEY_STATE_WALK_FORWARD;
else if (creature->Mood == MoodType::Escape)
- item->Animation.TargetState = 3;
+ item->Animation.TargetState = MONKEY_STATE_IDLE;
else if (creature->Mood == MoodType::Bored)
{
if (item->Animation.RequiredState)
item->Animation.TargetState = item->Animation.RequiredState;
else if (TestProbability(0.06f))
- item->Animation.TargetState = 2;
+ item->Animation.TargetState = MONKEY_STATE_WALK_FORWARD;
else if (TestProbability(0.06f))
{
if (TestProbability(0.5f))
- item->Animation.TargetState = 8;
+ item->Animation.TargetState = MONKEY_STATE_SIT_EAT;
else
- item->Animation.TargetState = 7;
+ item->Animation.TargetState = MONKEY_STATE_SIT_SCRATCH;
}
}
- else if ((item->AIBits & FOLLOW) && (creature->ReachedGoal || laraAI.distance > pow(SECTOR(2), 2)))
+ else if ((item->AIBits & FOLLOW) &&
+ (creature->ReachedGoal || laraAI.distance > pow(SECTOR(2), 2)))
{
if (item->Animation.RequiredState)
item->Animation.TargetState = item->Animation.RequiredState;
else if (AI.ahead)
- item->Animation.TargetState = 6;
+ item->Animation.TargetState = MONKEY_STATE_SIT;
else
- item->Animation.TargetState = 3;
+ item->Animation.TargetState = MONKEY_STATE_IDLE;
}
else if (AI.bite && AI.distance < pow(682, 2))
- item->Animation.TargetState = 3;
+ item->Animation.TargetState = MONKEY_STATE_IDLE;
else if (AI.bite && AI.distance < pow(682, 2))
- item->Animation.TargetState = 2;
+ item->Animation.TargetState = MONKEY_STATE_WALK_FORWARD;
else
- item->Animation.TargetState = 3;
+ item->Animation.TargetState = MONKEY_STATE_IDLE;
break;
- case 3:
+ case MONKEY_STATE_IDLE:
creature->MaxTurn = 0;
creature->Flags = 0;
- torsoY = laraAI.angle;
+ extraTorsoRot.y = laraAI.angle;
if (item->AIBits & GUARD)
{
- torsoY = AIGuard(creature);
+ extraTorsoRot.y = AIGuard(creature);
if (TestProbability(0.06f))
{
if (TestProbability(0.5f))
- item->Animation.TargetState = 10;
+ item->Animation.TargetState = MONKEY_STATE_POUND_GROUND;
else
- item->Animation.TargetState = 6;
+ item->Animation.TargetState = MONKEY_STATE_SIT;
}
break;
}
else if (item->AIBits & PATROL1)
- item->Animation.TargetState = 2;
+ item->Animation.TargetState = MONKEY_STATE_WALK_FORWARD;
else if (creature->Mood == MoodType::Escape)
{
if (Lara.TargetEntity != item && AI.ahead)
- item->Animation.TargetState = 3;
+ item->Animation.TargetState = MONKEY_STATE_IDLE;
else
- item->Animation.TargetState = 4;
+ item->Animation.TargetState = MONKEY_STATE_RUN_FORWARD;
}
else if (creature->Mood == MoodType::Bored)
{
if (item->Animation.RequiredState)
item->Animation.TargetState = item->Animation.RequiredState;
else if (TestProbability(0.06f))
- item->Animation.TargetState = 2;
+ item->Animation.TargetState = MONKEY_STATE_WALK_FORWARD;
else if (TestProbability(0.06f))
{
if (TestProbability(0.5f))
- item->Animation.TargetState = 10;
+ item->Animation.TargetState = MONKEY_STATE_POUND_GROUND;
else
- item->Animation.TargetState = 6;
+ item->Animation.TargetState = MONKEY_STATE_SIT;
}
}
- else if (item->AIBits & FOLLOW && (creature->ReachedGoal || laraAI.distance > pow(SECTOR(2), 2)))
+ else if (item->AIBits & FOLLOW &&
+ (creature->ReachedGoal || laraAI.distance > pow(SECTOR(2), 2)))
{
if (item->Animation.RequiredState)
item->Animation.TargetState = item->Animation.RequiredState;
else if (AI.ahead)
- item->Animation.TargetState = 6;
+ item->Animation.TargetState = MONKEY_STATE_SIT;
else
- item->Animation.TargetState = 4;
+ item->Animation.TargetState = MONKEY_STATE_RUN_FORWARD;
}
else if (AI.bite && AI.distance < pow(341, 2))
{
if (LaraItem->Pose.Position.y < item->Pose.Position.y)
- item->Animation.TargetState = 13;
+ item->Animation.TargetState = MONKEY_STATE_JUMP_ATTACK;
else
- item->Animation.TargetState = 12;
+ item->Animation.TargetState = MONKEY_STATE_SWIPE_ATTACK;
}
else if (AI.bite && AI.distance < pow(682, 2))
- item->Animation.TargetState = 14;
+ item->Animation.TargetState = MONKEY_STATE_HIGH_JUMP_ATTACK;
else if (AI.bite && AI.distance < pow(682, 2))
- item->Animation.TargetState = 2;
- else if (AI.distance < pow(682, 2) && creature->Enemy != LaraItem && creature->Enemy != nullptr &&
- creature->Enemy->ObjectNumber != ID_AI_PATROL1 && creature->Enemy->ObjectNumber != ID_AI_PATROL2 &&
- abs(item->Pose.Position.y - creature->Enemy->Pose.Position.y) < 256)
+ item->Animation.TargetState = MONKEY_STATE_WALK_FORWARD;
+ else if (AI.distance < pow(682, 2) &&
+ !creature->Enemy->IsLara() && creature->Enemy != nullptr &&
+ creature->Enemy->ObjectNumber != ID_AI_PATROL1 &&
+ creature->Enemy->ObjectNumber != ID_AI_PATROL2 &&
+ abs(item->Pose.Position.y - creature->Enemy->Pose.Position.y) < CLICK(1))
{
- item->Animation.TargetState = 5;
+ item->Animation.TargetState = MONKEY_STATE_BITE_ATTACK;
}
else if (AI.bite && AI.distance < pow(SECTOR(1), 2))
- item->Animation.TargetState = 9;
+ item->Animation.TargetState = MONKEY_STATE_RUN_FORWARD_ROLL;
else
- item->Animation.TargetState = 4;
+ item->Animation.TargetState = MONKEY_STATE_RUN_FORWARD;
break;
- case 5:
+ case MONKEY_STATE_BITE_ATTACK:
creature->ReachedGoal = true;
if (creature->Enemy == nullptr)
break;
else if ((creature->Enemy->ObjectNumber == ID_SMALLMEDI_ITEM ||
creature->Enemy->ObjectNumber == ID_KEY_ITEM4) &&
- item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase + 12)
+ item->Animation.FrameNumber == (g_Level.Anims[item->Animation.AnimNumber].frameBase + 12))
{
if (creature->Enemy->RoomNumber == NO_ROOM ||
creature->Enemy->Status == ITEM_INVISIBLE ||
@@ -299,9 +360,8 @@ namespace TEN::Entities::TR3
creature->Enemy->RoomNumber = NO_ROOM;
creature->Enemy->CarriedItem = NO_ITEM;
- for (int i = 0; i < ActiveCreatures.size(); i++)
+ for (auto& currentCreature : ActiveCreatures)
{
- auto* currentCreature = ActiveCreatures[i];
if (currentCreature->ItemNumber == NO_ITEM || currentCreature->ItemNumber == itemNumber)
continue;
@@ -319,15 +379,14 @@ namespace TEN::Entities::TR3
}
}
}
- else if (creature->Enemy->ObjectNumber == ID_AI_AMBUSH && item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase + 12)
+ else if (creature->Enemy->ObjectNumber == ID_AI_AMBUSH &&
+ item->Animation.FrameNumber == (g_Level.Anims[item->Animation.AnimNumber].frameBase + 12))
{
item->AIBits = 0;
auto* carriedItem = &g_Level.Items[item->CarriedItem];
- carriedItem->Pose.Position.x = item->Pose.Position.x;
- carriedItem->Pose.Position.y = item->Pose.Position.y;
- carriedItem->Pose.Position.z = item->Pose.Position.z;
+ carriedItem->Pose.Position = item->Pose.Position;
ItemNewRoom(item->CarriedItem, item->RoomNumber);
item->CarriedItem = NO_ITEM;
@@ -349,60 +408,106 @@ namespace TEN::Entities::TR3
break;
- case 2:
+ case MONKEY_STATE_WALK_FORWARD:
creature->MaxTurn = ANGLE(7.0f);
- torsoY = laraAI.angle;
+ extraTorsoRot.y = laraAI.angle;
if (item->AIBits & PATROL1)
{
- item->Animation.TargetState = 2;
- torsoY = 0;
+ item->Animation.TargetState = MONKEY_STATE_WALK_FORWARD;
+ extraTorsoRot.y = 0;
}
else if (creature->Mood == MoodType::Escape)
- item->Animation.TargetState = 4;
+ item->Animation.TargetState = MONKEY_STATE_RUN_FORWARD;
else if (creature->Mood == MoodType::Bored)
{
if (TestProbability(0.008f))
- item->Animation.TargetState = 6;
+ item->Animation.TargetState = MONKEY_STATE_SIT;
}
else if (AI.bite && AI.distance < pow(682, 2))
- item->Animation.TargetState = 3;
+ item->Animation.TargetState = MONKEY_STATE_IDLE;
break;
- case 4:
+ case MONKEY_STATE_RUN_FORWARD:
creature->MaxTurn = ANGLE(11.0f);
tilt = angle / 2;
if (AI.ahead)
- torsoY = AI.angle;
+ extraTorsoRot.y = AI.angle;
if (item->AIBits & GUARD)
- item->Animation.TargetState = 3;
+ item->Animation.TargetState = MONKEY_STATE_IDLE;
else if (creature->Mood == MoodType::Escape)
{
if (Lara.TargetEntity != item && AI.ahead)
- item->Animation.TargetState = 3;
+ item->Animation.TargetState = MONKEY_STATE_IDLE;
+
break;
}
- else if ((item->AIBits & FOLLOW) && (creature->ReachedGoal || laraAI.distance > pow(SECTOR(2), 2)))
- item->Animation.TargetState = 3;
+ else if ((item->AIBits & FOLLOW) &&
+ (creature->ReachedGoal || laraAI.distance > pow(SECTOR(2), 2)))
+ {
+ item->Animation.TargetState = MONKEY_STATE_IDLE;
+ }
else if (creature->Mood == MoodType::Bored)
- item->Animation.TargetState = 9;
+ item->Animation.TargetState = MONKEY_STATE_RUN_FORWARD_ROLL;
else if (AI.distance < pow(682, 2))
- item->Animation.TargetState = 3;
+ item->Animation.TargetState = MONKEY_STATE_IDLE;
else if (AI.bite && AI.distance < pow(SECTOR(1), 2))
- item->Animation.TargetState = 9;
+ item->Animation.TargetState = MONKEY_STATE_RUN_FORWARD_ROLL;
break;
- case 12:
+ case MONKEY_STATE_SWIPE_ATTACK:
creature->MaxTurn = 0;
if (AI.ahead)
{
- headY = AI.angle;
- headX = AI.xAngle;
+ extraHeadRot.x = AI.xAngle;
+ extraHeadRot.y = AI.angle;
+ }
+
+ if (abs(AI.angle) < ANGLE(7.0f))
+ item->Pose.Orientation.y += AI.angle;
+ else if (AI.angle < 0)
+ item->Pose.Orientation.y -= ANGLE(7.0f);
+ else
+ item->Pose.Orientation.y += ANGLE(7.0f);
+
+ if (enemy->IsLara())
+ {
+ if (!creature->Flags && item->TestBits(JointBitType::Touch, MonkeyAttackJoints))
+ {
+ DoDamage(enemy, MONKEY_SWIPE_ATTACK_PLAYER_DAMAGE);
+ CreatureEffect(item, MonkeyBite, DoBloodSplat);
+ creature->Flags = 1;
+ }
+ }
+ else
+ {
+ if (!creature->Flags && enemy)
+ {
+ if (abs(enemy->Pose.Position.x - item->Pose.Position.x) < CLICK(1) &&
+ abs(enemy->Pose.Position.y - item->Pose.Position.y) <= CLICK(1) &&
+ abs(enemy->Pose.Position.z - item->Pose.Position.z) < CLICK(1))
+ {
+ DoDamage(enemy, MONKEY_SWIPE_ATTACK_CREATURE_DAMAGE);
+ CreatureEffect(item, MonkeyBite, DoBloodSplat);
+ creature->Flags = 1;
+ }
+ }
+ }
+
+ break;
+
+ case MONKEY_STATE_JUMP_ATTACK:
+ creature->MaxTurn = 0;
+
+ if (AI.ahead)
+ {
+ extraHeadRot.x = AI.xAngle;
+ extraHeadRot.y = AI.angle;
}
if (abs(AI.angle) < ANGLE(7.0f))
@@ -423,7 +528,7 @@ namespace TEN::Entities::TR3
}
else
{
- if (!creature->Flags && enemy)
+ if (!creature->Flags && enemy != nullptr)
{
if (abs(enemy->Pose.Position.x - item->Pose.Position.x) < CLICK(1) &&
abs(enemy->Pose.Position.y - item->Pose.Position.y) <= CLICK(1) &&
@@ -438,55 +543,13 @@ namespace TEN::Entities::TR3
break;
- case 13:
+ case MONKEY_STATE_HIGH_JUMP_ATTACK:
creature->MaxTurn = 0;
if (AI.ahead)
{
- headY = AI.angle;
- headX = AI.xAngle;
- }
-
- if (abs(AI.angle) < ANGLE(7.0f))
- item->Pose.Orientation.y += AI.angle;
- else if (AI.angle < 0)
- item->Pose.Orientation.y -= ANGLE(7.0f);
- else
- item->Pose.Orientation.y += ANGLE(7.0f);
-
- if (enemy->IsLara())
- {
- if (!creature->Flags && item->TestBits(JointBitType::Touch, MonkeyAttackJoints))
- {
- DoDamage(enemy, 40);
- CreatureEffect(item, MonkeyBite, DoBloodSplat);
- creature->Flags = 1;
- }
- }
- else
- {
- if (!creature->Flags && enemy)
- {
- if (abs(enemy->Pose.Position.x - item->Pose.Position.x) < CLICK(1) &&
- abs(enemy->Pose.Position.y - item->Pose.Position.y) <= CLICK(1) &&
- abs(enemy->Pose.Position.z - item->Pose.Position.z) < CLICK(1))
- {
- DoDamage(enemy, 20);
- CreatureEffect(item, MonkeyBite, DoBloodSplat);
- creature->Flags = 1;
- }
- }
- }
-
- break;
-
- case 14:
- creature->MaxTurn = 0;
-
- if (AI.ahead)
- {
- headX = AI.xAngle;
- headY = AI.angle;
+ extraHeadRot.x = AI.xAngle;
+ extraHeadRot.y = AI.angle;
}
if (abs(AI.angle) < ANGLE(7.0f))
@@ -525,54 +588,42 @@ namespace TEN::Entities::TR3
}
CreatureTilt(item, tilt);
- CreatureJoint(item, 0, headY);
- CreatureJoint(item, 1, headX);
- CreatureJoint(item, 2, torsoY);
+ CreatureJoint(item, 0, extraHeadRot.y);
+ CreatureJoint(item, 1, extraHeadRot.x);
+ CreatureJoint(item, 2, extraTorsoRot.y);
- if (item->Animation.ActiveState < 15)
+ if (item->Animation.ActiveState < MONKEY_STATE_VAULT_UP_1_BLOCK)
{
- switch (CreatureVault(itemNumber, angle, 2, 128))
+ switch (CreatureVault(itemNumber, angle, 2, CLICK(0.5f)))
{
case 2:
+ SetAnimation(item, MONKEY_ANIM_VAULT_UP_0_POINT_2_BLOCKS);
creature->MaxTurn = 0;
- item->Animation.AnimNumber = Objects[ID_MONKEY].animIndex + 19;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = 17;
break;
case 3:
+ SetAnimation(item, MONKEY_ANIM_VAULT_UP_0_POINT_3_BLOCKS);
creature->MaxTurn = 0;
- item->Animation.AnimNumber = Objects[ID_MONKEY].animIndex + 18;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = 16;
break;
case 4:
+ SetAnimation(item, MONKEY_ANIM_VAULT_UP_1_BLOCK);
creature->MaxTurn = 0;
- item->Animation.AnimNumber = Objects[ID_MONKEY].animIndex + 17;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = 15;
break;
case -2:
+ SetAnimation(item, MONKEY_ANIM_VAULT_DOWN_0_POINT_2_BLOCKS);
creature->MaxTurn = 0;
- item->Animation.AnimNumber = Objects[ID_MONKEY].animIndex + 22;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = 20;
break;
case -3:
+ SetAnimation(item, MONKEY_ANIM_VAULT_DOWN_0_POINT_3_BLOCKS);
creature->MaxTurn = 0;
- item->Animation.AnimNumber = Objects[ID_MONKEY].animIndex + 21;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = 19;
break;
case -4:
+ SetAnimation(item, MONKEY_ANIM_VAULT_DOWN_1_BLOCK);
creature->MaxTurn = 0;
- item->Animation.AnimNumber = Objects[ID_MONKEY].animIndex + 20;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = 18;
break;
}
}
diff --git a/TombEngine/Objects/TR3/Entity/tr3_shiva.cpp b/TombEngine/Objects/TR3/Entity/tr3_shiva.cpp
index 2d618700a..3a8eb3d89 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_shiva.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_shiva.cpp
@@ -29,10 +29,10 @@ namespace TEN::Entities::TR3
#define SHIVA_WALK_TURN_RATE_MAX ANGLE(4.0f)
#define SHIVA_ATTACK_TURN_RATE_MAX ANGLE(4.0f)
- const vector ShivaAttackLeftJoints = { 10, 13 };
- const vector ShivaAttackRightJoints = { 22, 25 };
const auto ShivaBiteLeft = BiteInfo(Vector3(0.0f, 0.0f, 920.0f), 13);
const auto ShivaBiteRight = BiteInfo(Vector3(0.0f, 0.0f, 920.0f), 22);
+ const vector ShivaAttackLeftJoints = { 10, 13 };
+ const vector ShivaAttackRightJoints = { 22, 25 };
enum ShivaState
{
@@ -81,7 +81,7 @@ namespace TEN::Entities::TR3
};
- static void TriggerShivaSmoke(long x, long y, long z, long uw)
+ void TriggerShivaSmoke(long x, long y, long z, long uw)
{
long dx = LaraItem->Pose.Position.x - x;
long dz = LaraItem->Pose.Position.z - z;
@@ -169,7 +169,7 @@ namespace TEN::Entities::TR3
sptr->dSize = size;
}
- static void ShivaDamage(ItemInfo* item, CreatureInfo* creature, int damage)
+ void ShivaDamage(ItemInfo* item, CreatureInfo* creature, int damage)
{
if (!(creature->Flags) && item->TestBits(JointBitType::Touch, ShivaAttackRightJoints))
{
@@ -451,8 +451,8 @@ namespace TEN::Entities::TR3
case SHIVA_STATE_KILL:
shiva->MaxTurn = 0;
- extraHeadRot = Vector3Shrt();
- extraTorsoRot = Vector3Shrt();
+ extraHeadRot = Vector3Shrt::Zero;
+ extraTorsoRot = Vector3Shrt::Zero;
if (item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase + SHIVA_ANIM_WALK_FORWARD_TO_GUARDED_LEFT_1 ||
item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase + SHIVA_ANIM_WALK_BACK_RIGHT ||
@@ -466,7 +466,7 @@ namespace TEN::Entities::TR3
}
}
- // Dispatch kill animation
+ // Dispatch kill animation.
if (laraAlive && LaraItem->HitPoints <= 0)
{
item->Animation.TargetState = SHIVA_STATE_KILL;
@@ -474,15 +474,13 @@ namespace TEN::Entities::TR3
if (LaraItem->RoomNumber != item->RoomNumber)
ItemNewRoom(Lara.ItemNumber, item->RoomNumber);
- LaraItem->Pose.Position = item->Pose.Position;
- LaraItem->Pose.Orientation = Vector3Shrt(0, item->Pose.Orientation.y, 0);
- LaraItem->Animation.IsAirborne = false;
-
LaraItem->Animation.AnimNumber = Objects[ID_LARA_EXTRA_ANIMS].animIndex + LARA_ANIM_SHIVA_DEATH;
LaraItem->Animation.FrameNumber = g_Level.Anims[LaraItem->Animation.AnimNumber].frameBase;
LaraItem->Animation.ActiveState = LS_DEATH;
LaraItem->Animation.TargetState = LS_DEATH;
-
+ LaraItem->Animation.IsAirborne = false;
+ LaraItem->Pose.Position = item->Pose.Position;
+ LaraItem->Pose.Orientation = Vector3Shrt(0, item->Pose.Orientation.y, 0);
LaraItem->HitPoints = NOT_TARGETABLE;
Lara.Air = -1;
Lara.Control.HandStatus = HandStatus::Special;
diff --git a/TombEngine/Objects/TR4/Entity/tr4_von_croy.cpp b/TombEngine/Objects/TR4/Entity/tr4_von_croy.cpp
index a90133027..bccb3d500 100644
--- a/TombEngine/Objects/TR4/Entity/tr4_von_croy.cpp
+++ b/TombEngine/Objects/TR4/Entity/tr4_von_croy.cpp
@@ -770,10 +770,10 @@ namespace TEN::Entities::TR4
creature->MaxTurn = 0;
ClampRotation(&item->Pose, AI.angle, ANGLE(6.0f));
- if ((enemy == NULL || enemy->Flags != NULL) ||
+ if ((enemy == nullptr || enemy->Flags != 0) ||
item->Animation.FrameNumber <= g_Level.Anims[item->Animation.AnimNumber].frameBase + 21)
{
- if (creature->Flags == NULL && enemy != nullptr)
+ if (creature->Flags == 0 && enemy != nullptr)
{
if (item->Animation.FrameNumber > g_Level.Anims[item->Animation.AnimNumber].frameBase + 15 &&
item->Animation.FrameNumber < g_Level.Anims[item->Animation.AnimNumber].frameBase + 26)
@@ -849,7 +849,7 @@ namespace TEN::Entities::TR4
item->Animation.TargetState = VON_CROY_STATE_WALK;
item->Animation.RequiredState = VON_CROY_STATE_RUN;
- item->ItemFlags[2] = NULL;
+ item->ItemFlags[2] = 0;
//if (sVar3 == -1) goto LAB_0041a991;
if (!flags)
{
@@ -878,38 +878,38 @@ namespace TEN::Entities::TR4
CreatureJoint(item, 2, joint2);
CreatureJoint(item, 3, joint3);
- if ((item->Animation.ActiveState < VON_CROY_STATE_JUMP) && (item->Animation.ActiveState != VON_CROY_STATE_MONKEY))
+ if (item->Animation.ActiveState < VON_CROY_STATE_JUMP &&
+ item->Animation.ActiveState != VON_CROY_STATE_MONKEY)
{
switch (CreatureVault(itemNumber, angle, 2, 260))
{
- case VON_CROY_STATE_WALK:
+ case 2:
item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex + VON_CROY_ANIM_CLIMB_2_BLOCKS;
item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
item->Animation.ActiveState = VON_CROY_STATE_CLIMB_2_BLOCKS;
creature->MaxTurn = 0;
break;
- case VON_CROY_STATE_RUN:
+ case 3:
item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex + VON_CROY_ANIM_CLIMB_3_BLOCKS;
item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
item->Animation.ActiveState = VON_CROY_STATE_CLIMB_3_BLOCKS;
creature->MaxTurn = 0;
break;
- case VON_CROY_STATE_START_MONKEY:
+ case 4:
item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex + VON_CROY_ANIM_CLIMB_4_BLOCKS;
item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
item->Animation.ActiveState = VON_CROY_STATE_CLIMB_4_BLOCKS;
creature->MaxTurn = 0;
break;
- case VON_CROY_STATE_LOOK_BEFORE_JUMP:
+ case 7:
item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex + VON_CROY_ANIM_JUMP_TO_HANG;
item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
item->Animation.ActiveState = VON_CROY_STATE_GRAB_LADDER;
creature->MaxTurn = 0;
break;
- // I am not sure what negative states are (probably the inverse of the above), I will leave them alone - Kubsy 18/06/2022
case -7:
item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex + VON_CROY_ANIM_CLIMB_DOWN_2_SECTORS;
item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
diff --git a/TombEngine/Objects/TR5/Entity/tr5_larson.cpp b/TombEngine/Objects/TR5/Entity/tr5_larson.cpp
index b45c443e6..99147a8c1 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_larson.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_larson.cpp
@@ -141,7 +141,7 @@ namespace TEN::Entities::TR5
CreatureMood(item, &AI, true);
if (AI.distance < SQUARE(SECTOR(2)) &&
- LaraItem->Animation.Velocity > 20 ||
+ LaraItem->Animation.Velocity.z > 20.0f ||
item->HitStatus ||
TargetVisible(item, &AI) != 0)
{
From 02a8d935caac79db4d3dfce505598e0718e8d34b Mon Sep 17 00:00:00 2001
From: hispidence
Date: Fri, 19 Aug 2022 00:05:52 +0100
Subject: [PATCH 009/106] Update docs
---
Documentation/config.ld | 2 +-
Documentation/doc/1 modules/Effects.html | 4 +--
Documentation/doc/1 modules/Flow.html | 4 +--
Documentation/doc/1 modules/Inventory.html | 4 +--
Documentation/doc/1 modules/Logic.html | 4 +--
Documentation/doc/1 modules/Misc.html | 4 +--
Documentation/doc/1 modules/Objects.html | 4 +--
Documentation/doc/1 modules/Strings.html | 4 +--
.../doc/2 classes/Flow.Animations.html | 4 +--
Documentation/doc/2 classes/Flow.Fog.html | 4 +--
.../doc/2 classes/Flow.InventoryItem.html | 4 +--
Documentation/doc/2 classes/Flow.Level.html | 29 ++-----------------
Documentation/doc/2 classes/Flow.Mirror.html | 4 +--
.../doc/2 classes/Flow.Settings.html | 4 +--
.../doc/2 classes/Flow.SkyLayer.html | 4 +--
.../doc/2 classes/Objects.AIObject.html | 4 +--
.../doc/2 classes/Objects.Camera.html | 4 +--
.../doc/2 classes/Objects.Moveable.html | 4 +--
Documentation/doc/2 classes/Objects.Sink.html | 4 +--
.../doc/2 classes/Objects.SoundSource.html | 4 +--
.../doc/2 classes/Objects.Static.html | 4 +--
.../doc/2 classes/Strings.DisplayString.html | 4 +--
.../doc/3 primitive classes/Color.html | 4 +--
.../doc/3 primitive classes/Rotation.html | 4 +--
.../doc/3 primitive classes/Vec3.html | 4 +--
.../doc/4 enums/Effects.BlendID.html | 4 +--
Documentation/doc/4 enums/Flow.InvID.html | 4 +--
Documentation/doc/4 enums/Objects.ObjID.html | 4 +--
.../5 lua utility modules/EventSequence.html | 4 +--
.../doc/5 lua utility modules/Timer.html | 4 +--
.../doc/5 lua utility modules/Util.html | 4 +--
Documentation/doc/index.html | 6 ++--
.../Internal/TEN/Flow/Level/FlowLevel.cpp | 8 -----
.../Internal/TEN/Flow/Level/FlowLevel.h | 1 -
34 files changed, 65 insertions(+), 97 deletions(-)
diff --git a/Documentation/config.ld b/Documentation/config.ld
index 75fce7222..903bc8e9e 100644
--- a/Documentation/config.ld
+++ b/Documentation/config.ld
@@ -12,7 +12,7 @@ new_type("luautil", "5 Lua utility modules", true)
not_luadoc = true
-local version = "1.0.1"
+local version = "1.0.2"
project = "TombEngine"
title = "TombEngine " .. version .. " Lua API"
description = "TombEngine " .. version .. " scripting interface"
diff --git a/Documentation/doc/1 modules/Effects.html b/Documentation/doc/1 modules/Effects.html
index acb3a242b..96a620603 100644
--- a/Documentation/doc/1 modules/Effects.html
+++ b/Documentation/doc/1 modules/Effects.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -511,7 +511,7 @@
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/1 modules/Flow.html b/Documentation/doc/1 modules/Flow.html
index c80e697c8..058eb30e2 100644
--- a/Documentation/doc/1 modules/Flow.html
+++ b/Documentation/doc/1 modules/Flow.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -353,7 +353,7 @@ Specify which translations in the strings table correspond to which languages.
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/1 modules/Inventory.html b/Documentation/doc/1 modules/Inventory.html
index 327be00e9..2b13b1af3 100644
--- a/Documentation/doc/1 modules/Inventory.html
+++ b/Documentation/doc/1 modules/Inventory.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -204,7 +204,7 @@ Similar to GiveItem but repla
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/1 modules/Logic.html b/Documentation/doc/1 modules/Logic.html
index 4475152b2..75f3dbfed 100644
--- a/Documentation/doc/1 modules/Logic.html
+++ b/Documentation/doc/1 modules/Logic.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -279,7 +279,7 @@ and provides the delta time (a float representing game time since last call) via
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/1 modules/Misc.html b/Documentation/doc/1 modules/Misc.html
index 22ce29e8d..e49ef1a65 100644
--- a/Documentation/doc/1 modules/Misc.html
+++ b/Documentation/doc/1 modules/Misc.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -632,7 +632,7 @@ To be used with
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/1 modules/Objects.html b/Documentation/doc/1 modules/Objects.html
index 0aa9b0508..fbd3e71bd 100644
--- a/Documentation/doc/1 modules/Objects.html
+++ b/Documentation/doc/1 modules/Objects.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -297,7 +297,7 @@
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/1 modules/Strings.html b/Documentation/doc/1 modules/Strings.html
index d07a6c74d..0bc83ae5d 100644
--- a/Documentation/doc/1 modules/Strings.html
+++ b/Documentation/doc/1 modules/Strings.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -169,7 +169,7 @@ with a call to ShowString , or
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/2 classes/Flow.Animations.html b/Documentation/doc/2 classes/Flow.Animations.html
index 25b6ecaa5..956dc4fca 100644
--- a/Documentation/doc/2 classes/Flow.Animations.html
+++ b/Documentation/doc/2 classes/Flow.Animations.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -100,7 +100,7 @@
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/2 classes/Flow.Fog.html b/Documentation/doc/2 classes/Flow.Fog.html
index 1aeaeeaef..912f3ea19 100644
--- a/Documentation/doc/2 classes/Flow.Fog.html
+++ b/Documentation/doc/2 classes/Flow.Fog.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -227,7 +227,7 @@
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/2 classes/Flow.InventoryItem.html b/Documentation/doc/2 classes/Flow.InventoryItem.html
index 8a35205c0..b5e5dd9c2 100644
--- a/Documentation/doc/2 classes/Flow.InventoryItem.html
+++ b/Documentation/doc/2 classes/Flow.InventoryItem.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -182,7 +182,7 @@ EXAMINE
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/2 classes/Flow.Level.html b/Documentation/doc/2 classes/Flow.Level.html
index e43c230be..4e29132bb 100644
--- a/Documentation/doc/2 classes/Flow.Level.html
+++ b/Documentation/doc/2 classes/Flow.Level.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -120,8 +120,7 @@
layer2
- (Flow.SkyLayer ) Secondary sky layer
- (not yet implemented)
+ (Flow.SkyLayer ) Secondary sky layer
fog
@@ -132,10 +131,6 @@
(bool) Draw sky layer?
- colAddHorizon
- (bool) Enable smooth transition from horizon graphic to sky layer.
-
-
storm
(bool) Enable flickering lightning in the sky.
@@ -282,7 +277,6 @@
(Flow.SkyLayer ) Secondary sky layer
- (not yet implemented)
@@ -320,23 +314,6 @@
-
-
-
- colAddHorizon
-
-
- (bool) Enable smooth transition from horizon graphic to sky layer.
- If set to false, there will be a black band between the two.
-
- (not yet implemented)
-
-
-
-
-
-
-
@@ -519,7 +496,7 @@ Must be at least 4.
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/2 classes/Flow.Mirror.html b/Documentation/doc/2 classes/Flow.Mirror.html
index 8847b143e..4f4f07877 100644
--- a/Documentation/doc/2 classes/Flow.Mirror.html
+++ b/Documentation/doc/2 classes/Flow.Mirror.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -100,7 +100,7 @@
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/2 classes/Flow.Settings.html b/Documentation/doc/2 classes/Flow.Settings.html
index 96ef22346..95edfc4f5 100644
--- a/Documentation/doc/2 classes/Flow.Settings.html
+++ b/Documentation/doc/2 classes/Flow.Settings.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -143,7 +143,7 @@ an invalid argument.
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/2 classes/Flow.SkyLayer.html b/Documentation/doc/2 classes/Flow.SkyLayer.html
index 69b0dd699..7fea04f07 100644
--- a/Documentation/doc/2 classes/Flow.SkyLayer.html
+++ b/Documentation/doc/2 classes/Flow.SkyLayer.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -199,7 +199,7 @@ Less is more. City of The Dead, for example, uses a speed value of 16.
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/2 classes/Objects.AIObject.html b/Documentation/doc/2 classes/Objects.AIObject.html
index 290626a04..c2a673b47 100644
--- a/Documentation/doc/2 classes/Objects.AIObject.html
+++ b/Documentation/doc/2 classes/Objects.AIObject.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -372,7 +372,7 @@ aiObj:SetObjectID(TEN.Objects.ObjID.AI_PATROL1)
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/2 classes/Objects.Camera.html b/Documentation/doc/2 classes/Objects.Camera.html
index 2b81eb147..ed23fa7e6 100644
--- a/Documentation/doc/2 classes/Objects.Camera.html
+++ b/Documentation/doc/2 classes/Objects.Camera.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -260,7 +260,7 @@
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/2 classes/Objects.Moveable.html b/Documentation/doc/2 classes/Objects.Moveable.html
index 324c4e627..d89f7958c 100644
--- a/Documentation/doc/2 classes/Objects.Moveable.html
+++ b/Documentation/doc/2 classes/Objects.Moveable.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -1488,7 +1488,7 @@ sas:SetPosition(destinationPosition)
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/2 classes/Objects.Sink.html b/Documentation/doc/2 classes/Objects.Sink.html
index 329da6b12..bb1d7e3f7 100644
--- a/Documentation/doc/2 classes/Objects.Sink.html
+++ b/Documentation/doc/2 classes/Objects.Sink.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -262,7 +262,7 @@
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/2 classes/Objects.SoundSource.html b/Documentation/doc/2 classes/Objects.SoundSource.html
index cfb423da8..f75d1282c 100644
--- a/Documentation/doc/2 classes/Objects.SoundSource.html
+++ b/Documentation/doc/2 classes/Objects.SoundSource.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -260,7 +260,7 @@
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/2 classes/Objects.Static.html b/Documentation/doc/2 classes/Objects.Static.html
index e79e73406..4ec87c539 100644
--- a/Documentation/doc/2 classes/Objects.Static.html
+++ b/Documentation/doc/2 classes/Objects.Static.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -358,7 +358,7 @@
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/2 classes/Strings.DisplayString.html b/Documentation/doc/2 classes/Strings.DisplayString.html
index d73bbcdd6..4448c7061 100644
--- a/Documentation/doc/2 classes/Strings.DisplayString.html
+++ b/Documentation/doc/2 classes/Strings.DisplayString.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -307,7 +307,7 @@ TEN.Strings.DisplayStringOption.SHADOW -- will give the text a small shadow
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/3 primitive classes/Color.html b/Documentation/doc/3 primitive classes/Color.html
index 1c762a147..ae3beb4e4 100644
--- a/Documentation/doc/3 primitive classes/Color.html
+++ b/Documentation/doc/3 primitive classes/Color.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -312,7 +312,7 @@
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/3 primitive classes/Rotation.html b/Documentation/doc/3 primitive classes/Rotation.html
index 4dcb6d4fa..8a3550d64 100644
--- a/Documentation/doc/3 primitive classes/Rotation.html
+++ b/Documentation/doc/3 primitive classes/Rotation.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -250,7 +250,7 @@ All values will be clamped to [-32768, 32767].
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/3 primitive classes/Vec3.html b/Documentation/doc/3 primitive classes/Vec3.html
index 3e37fa21e..3854494cc 100644
--- a/Documentation/doc/3 primitive classes/Vec3.html
+++ b/Documentation/doc/3 primitive classes/Vec3.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -277,7 +277,7 @@ However, this function would return it as (0, 1, 1).
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/4 enums/Effects.BlendID.html b/Documentation/doc/4 enums/Effects.BlendID.html
index 4ec654dd5..e28f95e94 100644
--- a/Documentation/doc/4 enums/Effects.BlendID.html
+++ b/Documentation/doc/4 enums/Effects.BlendID.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -149,7 +149,7 @@ ALPHABLEND
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/4 enums/Flow.InvID.html b/Documentation/doc/4 enums/Flow.InvID.html
index fde91a227..f8cc82a68 100644
--- a/Documentation/doc/4 enums/Flow.InvID.html
+++ b/Documentation/doc/4 enums/Flow.InvID.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -358,7 +358,7 @@ EXAMINE_ITEM8_COMBO2
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/4 enums/Objects.ObjID.html b/Documentation/doc/4 enums/Objects.ObjID.html
index 74f8fea1f..d7319e080 100644
--- a/Documentation/doc/4 enums/Objects.ObjID.html
+++ b/Documentation/doc/4 enums/Objects.ObjID.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -1096,7 +1096,7 @@ PANEL_MIDDLE_CORNER
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/5 lua utility modules/EventSequence.html b/Documentation/doc/5 lua utility modules/EventSequence.html
index be2753a3d..4433f4d59 100644
--- a/Documentation/doc/5 lua utility modules/EventSequence.html
+++ b/Documentation/doc/5 lua utility modules/EventSequence.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -333,7 +333,7 @@ LevelFuncs.SpawnBaddy = function (baddy, name, pos)
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/5 lua utility modules/Timer.html b/Documentation/doc/5 lua utility modules/Timer.html
index c5d37ad0c..f9956d80e 100644
--- a/Documentation/doc/5 lua utility modules/Timer.html
+++ b/Documentation/doc/5 lua utility modules/Timer.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -524,7 +524,7 @@ local myTimeFormat4 = {seconds = true}
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/5 lua utility modules/Util.html b/Documentation/doc/5 lua utility modules/Util.html
index 5f54cb8a0..4b016dc95 100644
--- a/Documentation/doc/5 lua utility modules/Util.html
+++ b/Documentation/doc/5 lua utility modules/Util.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -138,7 +138,7 @@
generated by LDoc 1.4.6
-
Last updated 2022-08-11 22:43:52
+
Last updated 2022-08-19 00:04:24
diff --git a/Documentation/doc/index.html b/Documentation/doc/index.html
index af9e6cbea..99e56b692 100644
--- a/Documentation/doc/index.html
+++ b/Documentation/doc/index.html
@@ -3,7 +3,7 @@
- TombEngine 1.0.1 Lua API
+ TombEngine 1.0.2 Lua API
@@ -80,7 +80,7 @@
-
TombEngine 1.0.1 scripting interface
+
TombEngine 1.0.2 scripting interface
Welcome to the TombEngine scripting API. This is a work in progress and some information might be wrong or outdated. Please also note that this is primarily a reference document, not a tutorial, so expect descriptions to be fairly sparse.
At the time of writing, there is a tutorial describing the basics of Lua, as well as a number of example scripts, on the wiki here .
@@ -248,7 +248,7 @@ Util.ShortenTENCalls()
generated by LDoc 1.4.6
-
Last updated 2022-08-14 20:33:42
+
Last updated 2022-08-19 00:04:24
diff --git a/TombEngine/Scripting/Internal/TEN/Flow/Level/FlowLevel.cpp b/TombEngine/Scripting/Internal/TEN/Flow/Level/FlowLevel.cpp
index 37d8abb75..a3b8e0a47 100644
--- a/TombEngine/Scripting/Internal/TEN/Flow/Level/FlowLevel.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Flow/Level/FlowLevel.cpp
@@ -49,7 +49,6 @@ void Level::Register(sol::table & parent)
"layer1", &Level::Layer1,
/// (@{Flow.SkyLayer}) Secondary sky layer
-// __(not yet implemented)__
//@mem layer2
"layer2", &Level::Layer2,
@@ -63,13 +62,6 @@ void Level::Register(sol::table & parent)
//@mem horizon
"horizon", &Level::Horizon,
-/// (bool) Enable smooth transition from horizon graphic to sky layer.
-// If set to false, there will be a black band between the two.
-//
-// __(not yet implemented)__
-//@mem colAddHorizon
- "colAddHorizon", &Level::ColAddHorizon,
-
/// (bool) Enable flickering lightning in the sky.
// Equivalent to classic TRLE's LIGHTNING setting. As in the TRC Ireland levels.
//
diff --git a/TombEngine/Scripting/Internal/TEN/Flow/Level/FlowLevel.h b/TombEngine/Scripting/Internal/TEN/Flow/Level/FlowLevel.h
index eba71e1b2..d0a4717b4 100644
--- a/TombEngine/Scripting/Internal/TEN/Flow/Level/FlowLevel.h
+++ b/TombEngine/Scripting/Internal/TEN/Flow/Level/FlowLevel.h
@@ -29,7 +29,6 @@ struct Level : public ScriptInterfaceLevel
std::string AmbientTrack;
SkyLayer Layer1;
SkyLayer Layer2;
- bool ColAddHorizon{ false };
Fog Fog;
bool Storm{ false };
WeatherType Weather{ WeatherType::None };
From 71f2ab7310b8c3d1d090ddd664250e07344f83da Mon Sep 17 00:00:00 2001
From: Sezz
Date: Fri, 19 Aug 2022 15:54:52 +1000
Subject: [PATCH 010/106] Demagic tr3_tiger.cpp
---
TombEngine/Game/control/box.cpp | 42 ++---
TombEngine/Objects/TR3/Entity/tr3_tiger.cpp | 165 ++++++++++++--------
TombEngine/Objects/TR4/Entity/tr4_ahmet.cpp | 12 +-
3 files changed, 121 insertions(+), 98 deletions(-)
diff --git a/TombEngine/Game/control/box.cpp b/TombEngine/Game/control/box.cpp
index f11437934..5374e914d 100644
--- a/TombEngine/Game/control/box.cpp
+++ b/TombEngine/Game/control/box.cpp
@@ -449,7 +449,8 @@ int CreatureAnimation(short itemNumber, short angle, short tilt)
short top;
auto* item = &g_Level.Items[itemNumber];
- if (!item->Data)
+
+ if (!item->IsCreature())
return false;
auto* creature = GetCreatureInfo(item);
@@ -462,7 +463,7 @@ int CreatureAnimation(short itemNumber, short angle, short tilt)
else
boxHeight = item->Floor;
- auto old = item->Pose.Position;
+ auto oldPos = item->Pose.Position;
AnimateItem(item);
@@ -477,7 +478,7 @@ int CreatureAnimation(short itemNumber, short angle, short tilt)
int y = item->Pose.Position.y + bounds->Y1;
short roomNumber = item->RoomNumber;
- GetFloor(old.x, y, old.z, &roomNumber);
+ GetFloor(oldPos.x, y, oldPos.z, &roomNumber);
FloorInfo* floor = GetFloor(item->Pose.Position.x, y, item->Pose.Position.z, &roomNumber);
// TODO: Check why some blocks have box = -1 assigned to them -- Lwmte, 10.11.21
@@ -506,18 +507,18 @@ int CreatureAnimation(short itemNumber, short angle, short tilt)
{
xPos = item->Pose.Position.x / SECTOR(1);
zPos = item->Pose.Position.z / SECTOR(1);
- shiftX = old.x / SECTOR(1);
- shiftZ = old.z / SECTOR(1);
+ shiftX = oldPos.x / SECTOR(1);
+ shiftZ = oldPos.z / SECTOR(1);
if (xPos < shiftX)
- item->Pose.Position.x = old.x & (~(SECTOR(1) - 1));
+ item->Pose.Position.x = oldPos.x & (~(SECTOR(1) - 1));
else if (xPos > shiftX)
- item->Pose.Position.x = old.x | (SECTOR(1) - 1);
+ item->Pose.Position.x = oldPos.x | (SECTOR(1) - 1);
if (zPos < shiftZ)
- item->Pose.Position.z = old.z & (~(SECTOR(1) - 1));
+ item->Pose.Position.z = oldPos.z & (~(SECTOR(1) - 1));
else if (zPos > shiftZ)
- item->Pose.Position.z = old.z | (SECTOR(1) - 1);
+ item->Pose.Position.z = oldPos.z | (SECTOR(1) - 1);
floor = GetFloor(item->Pose.Position.x, y, item->Pose.Position.z, &roomNumber);
height = g_Level.Boxes[floor->Box].height;
@@ -669,8 +670,8 @@ int CreatureAnimation(short itemNumber, short angle, short tilt)
{
if (item->Pose.Position.y + top < ceiling)
{
- item->Pose.Position.x = old.x;
- item->Pose.Position.z = old.z;
+ item->Pose.Position.x = oldPos.x;
+ item->Pose.Position.z = oldPos.z;
dy = LOT->Fly;
}
else
@@ -689,13 +690,13 @@ int CreatureAnimation(short itemNumber, short angle, short tilt)
}
else if (item->Pose.Position.y <= height)
{
- dy = 0;
item->Pose.Position.y = height;
+ dy = 0;
}
else
{
- item->Pose.Position.x = old.x;
- item->Pose.Position.z = old.z;
+ item->Pose.Position.x = oldPos.x;
+ item->Pose.Position.z = oldPos.z;
dy = -LOT->Fly;
}
@@ -732,11 +733,7 @@ int CreatureAnimation(short itemNumber, short angle, short tilt)
if (item->Pose.Position.y > item->Floor)
{
if (item->Pose.Position.y > (item->Floor + CLICK(1)))
- {
- item->Pose.Position.x = old.x;
- item->Pose.Position.y = old.y;
- item->Pose.Position.z = old.z;
- }
+ item->Pose.Position = oldPos;
else
item->Pose.Position.y = item->Floor;
}
@@ -753,11 +750,7 @@ int CreatureAnimation(short itemNumber, short angle, short tilt)
top = bounds->Y1; // TODO: check if Y1 or Y2
if (item->Pose.Position.y + top < ceiling)
- {
- item->Pose.Position.x = old.x;
- item->Pose.Position.z = old.z;
- item->Pose.Position.y = old.y;
- }
+ item->Pose.Position = oldPos;
floor = GetFloor(item->Pose.Position.x, item->Pose.Position.y, item->Pose.Position.z, &roomNumber);
item->Floor = GetFloorHeight(floor, item->Pose.Position.x, item->Pose.Position.y, item->Pose.Position.z);
@@ -773,7 +766,6 @@ int CreatureAnimation(short itemNumber, short angle, short tilt)
}
CreatureSwitchRoom(itemNumber);
-
return true;
}
diff --git a/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp b/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp
index 5a142f497..404fbaf58 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp
@@ -19,19 +19,48 @@ namespace TEN::Entities::TR3
{
constexpr auto TIGER_ATTACK_DAMAGE = 90;
+ constexpr auto TIGER_BITE_ATTACK_RANGE = SQUARE(SECTOR(0.33f));
+ constexpr auto TIGER_POUNCE_ATTACK_RANGE = SQUARE(SECTOR(1));
+ constexpr auto TIGER_RUN_ATTACK_RANGE = SQUARE(SECTOR(1.5f));
+
+ constexpr auto TIGER_WALK_CHANCE = 0.035f;
+ constexpr auto TIGER_ROAR_CHANCE = 0.003f;
+
const auto TigerBite = BiteInfo(Vector3(19.0f, -13.0f, 3.0f), 26);
const vector TigerAttackJoints = { 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26 };
- // TODO
+ #define TIGER_WALK_TURN_RATE_MAX ANGLE(3.0f)
+ #define TIGER_RUN_TURN_RATE_MAX ANGLE(6.0f)
+ #define TIGER_POUNCE_ATTACK_TURN_RATE_MAX ANGLE(3.0f)
+
enum TigerState
{
-
+ TIGER_STATE_DEATH = 0,
+ TIGER_STATE_IDLE = 1,
+ TIGER_STATE_WALK_FORWARD = 2,
+ TIGER_STATE_RUN_FORWARD = 3,
+ // No state 4.
+ TIGER_STATE_ROAR = 5,
+ TIGER_STATE_BITE_ATTACK = 6,
+ TIGER_STATE_SWIPE_ATTACK = 7,
+ TIGER_STATE_POUNCE_ATTACK = 8
};
- // TODO
enum TigerAnim
{
-
+ TIGER_ANIM_IDLE_TO_RUN_FORWARD = 0,
+ TIGER_ANIM_BITE_ATTACK = 1,
+ TIGER_ANIM_SWIPE_ATTACK = 2,
+ TIGER_ANIM_POUNCE_ATTACK_START = 3,
+ TIGER_ANIM_ROAR = 4,
+ TIGER_ANIM_RUN_FORWARD = 5,
+ TIGER_ANIM_RUN_FORWARD_TO_IDLE = 6,
+ TIGER_ANIM_IDLE = 7,
+ TIGER_ANIM_WALK_FORWARD = 8,
+ TIGER_ANIM_IDLE_TO_WALK_FORWARD = 9,
+ TIGER_ANIM_WALK_FORWARD_TO_IDLE = 10,
+ TIGER_ANIM_DEATH = 11,
+ TIGER_ANIM_POUNCE_ATTACK_END = 12
};
void TigerControl(short itemNumber)
@@ -40,20 +69,16 @@ namespace TEN::Entities::TR3
return;
auto* item = &g_Level.Items[itemNumber];
- auto* info = GetCreatureInfo(item);
+ auto* creature = GetCreatureInfo(item);
- short head = 0;
short angle = 0;
short tilt = 0;
+ auto extraHeadRot = Vector3Shrt::Zero;
if (item->HitPoints <= 0)
{
- if (item->Animation.ActiveState != 9)
- {
- item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex + 11;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = 9;
- }
+ if (item->Animation.ActiveState != TIGER_STATE_DEATH)
+ SetAnimation(item, TIGER_ANIM_DEATH);
}
else
{
@@ -61,99 +86,105 @@ namespace TEN::Entities::TR3
CreatureAIInfo(item, &AI);
if (AI.ahead)
- head = AI.angle;
+ extraHeadRot.y = AI.angle;
- GetCreatureMood(item, &AI, 1);
+ GetCreatureMood(item, &AI, true);
- if (info->Alerted && AI.zoneNumber != AI.enemyZone)
- info->Mood = MoodType::Escape;
+ if (creature->Alerted && AI.zoneNumber != AI.enemyZone)
+ creature->Mood = MoodType::Escape;
- CreatureMood(item, &AI, 1);
+ CreatureMood(item, &AI, true);
- angle = CreatureTurn(item, info->MaxTurn);
+ angle = CreatureTurn(item, creature->MaxTurn);
switch (item->Animation.ActiveState)
{
- case 1:
- info->MaxTurn = 0;
- info->Flags = 0;
+ case TIGER_STATE_IDLE:
+ creature->MaxTurn = 0;
+ creature->Flags = 0;
- if (info->Mood == MoodType::Escape)
+ if (creature->Mood == MoodType::Escape)
{
if (Lara.TargetEntity != item && AI.ahead)
- item->Animation.TargetState = 1;
+ item->Animation.TargetState = TIGER_STATE_IDLE;
else
- item->Animation.TargetState = 3;
+ item->Animation.TargetState = TIGER_STATE_RUN_FORWARD;
}
- else if (info->Mood == MoodType::Bored)
+ else if (creature->Mood == MoodType::Bored)
{
- if (TestProbability(0.003f))
- item->Animation.TargetState = 5;
- else if (TestProbability(0.035f))
- item->Animation.TargetState = 2;
+ if (TestProbability(TIGER_ROAR_CHANCE))
+ item->Animation.TargetState = TIGER_STATE_ROAR;
+ else if (TestProbability(TIGER_WALK_CHANCE))
+ item->Animation.TargetState = TIGER_STATE_WALK_FORWARD;
}
- else if (AI.bite && AI.distance < pow(340, 2))
- item->Animation.TargetState = 6;
- else if (AI.bite && AI.distance < pow(SECTOR(1), 2))
+ else if (AI.bite && AI.distance < TIGER_BITE_ATTACK_RANGE)
+ item->Animation.TargetState = TIGER_STATE_BITE_ATTACK;
+ else if (AI.bite && AI.distance < TIGER_POUNCE_ATTACK_RANGE)
{
- info->MaxTurn = ANGLE(3.0f);
- item->Animation.TargetState = 8;
+ creature->MaxTurn = TIGER_POUNCE_ATTACK_TURN_RATE_MAX;
+ item->Animation.TargetState = TIGER_STATE_POUNCE_ATTACK;
}
else if (item->Animation.RequiredState)
item->Animation.TargetState = item->Animation.RequiredState;
- else if (info->Mood != MoodType::Attack && TestProbability(0.003f))
- item->Animation.TargetState = 5;
+ else if (creature->Mood != MoodType::Attack && TestProbability(TIGER_ROAR_CHANCE))
+ item->Animation.TargetState = TIGER_STATE_ROAR;
else
- item->Animation.TargetState = 3;
+ item->Animation.TargetState = TIGER_STATE_RUN_FORWARD;
break;
- case 2:
- info->MaxTurn = ANGLE(3.0f);
+ case TIGER_STATE_WALK_FORWARD:
+ creature->MaxTurn = TIGER_WALK_TURN_RATE_MAX;
- if (info->Mood == MoodType::Escape || info->Mood == MoodType::Attack)
- item->Animation.TargetState = 3;
- else if (TestProbability(0.003f))
+ if (creature->Mood == MoodType::Escape ||
+ creature->Mood == MoodType::Attack)
{
- item->Animation.TargetState = 1;
- item->Animation.RequiredState = 5;
+ item->Animation.TargetState = TIGER_STATE_RUN_FORWARD;
+ }
+ else if (TestProbability(TIGER_ROAR_CHANCE))
+ {
+ item->Animation.TargetState = TIGER_STATE_IDLE;
+ item->Animation.RequiredState = TIGER_STATE_ROAR;
}
break;
- case 3:
- info->MaxTurn = ANGLE(6.0f);
+ case TIGER_STATE_RUN_FORWARD:
+ creature->MaxTurn = TIGER_RUN_TURN_RATE_MAX;
- if (info->Mood == MoodType::Bored)
- item->Animation.TargetState = 1;
- else if (info->Flags && AI.ahead)
- item->Animation.TargetState = 1;
- else if (AI.bite && AI.distance < pow(SECTOR(1.5f), 2))
+ if (creature->Mood == MoodType::Bored)
+ item->Animation.TargetState = TIGER_STATE_IDLE;
+ else if (creature->Flags && AI.ahead)
+ item->Animation.TargetState = TIGER_STATE_IDLE;
+ else if (AI.bite && AI.distance < TIGER_RUN_ATTACK_RANGE)
{
- if (LaraItem->Animation.Velocity.z == 0)
- item->Animation.TargetState = 1;
+ if (LaraItem->Animation.Velocity.z == 0.0f)
+ item->Animation.TargetState = TIGER_STATE_IDLE;
else
- item->Animation.TargetState = 7;
+ item->Animation.TargetState = TIGER_STATE_SWIPE_ATTACK;
}
- else if (info->Mood != MoodType::Attack && TestProbability(0.003f))
+ else if (creature->Mood != MoodType::Attack && TestProbability(TIGER_ROAR_CHANCE))
{
- item->Animation.TargetState = 1;
- item->Animation.RequiredState = 5;
+ item->Animation.TargetState = TIGER_STATE_IDLE;
+ item->Animation.RequiredState = TIGER_STATE_ROAR;
+ }
+ else if (creature->Mood == MoodType::Escape &&
+ Lara.TargetEntity != item && AI.ahead)
+ {
+ item->Animation.TargetState = TIGER_STATE_IDLE;
}
- else if (info->Mood == MoodType::Escape && Lara.TargetEntity != item && AI.ahead)
- item->Animation.TargetState = 1;
- info->Flags = 0;
+ creature->Flags = 0;
break;
- case 6:
- case 7:
- case 8:
- if (!info->Flags && item->TestBits(JointBitType::Touch, TigerAttackJoints))
+ case TIGER_STATE_BITE_ATTACK:
+ case TIGER_STATE_SWIPE_ATTACK:
+ case TIGER_STATE_POUNCE_ATTACK:
+ if (!creature->Flags && item->TestBits(JointBitType::Touch, TigerAttackJoints))
{
- DoDamage(info->Enemy, TIGER_ATTACK_DAMAGE);
+ DoDamage(creature->Enemy, TIGER_ATTACK_DAMAGE);
CreatureEffect(item, TigerBite, DoBloodSplat);
- info->Flags = 1;
+ creature->Flags = 1;
}
break;
@@ -161,7 +192,7 @@ namespace TEN::Entities::TR3
}
CreatureTilt(item, tilt);
- CreatureJoint(item, 0, head);
+ CreatureJoint(item, 0, extraHeadRot.y);
CreatureAnimation(itemNumber, angle, tilt);
}
}
diff --git a/TombEngine/Objects/TR4/Entity/tr4_ahmet.cpp b/TombEngine/Objects/TR4/Entity/tr4_ahmet.cpp
index 9c2dc71a3..9851152e8 100644
--- a/TombEngine/Objects/TR4/Entity/tr4_ahmet.cpp
+++ b/TombEngine/Objects/TR4/Entity/tr4_ahmet.cpp
@@ -131,7 +131,7 @@ namespace TEN::Entities::TR4
auto* creature = GetCreatureInfo(item);
short angle = 0;
- short headY = 0;
+ auto extraHeadRot = Vector3Shrt::Zero;
if (item->HitPoints <= 0)
{
@@ -186,7 +186,7 @@ namespace TEN::Entities::TR4
}
if (AI.ahead)
- headY = AI.angle;
+ extraHeadRot.y = AI.angle;
switch (item->Animation.ActiveState)
{
@@ -197,12 +197,12 @@ namespace TEN::Entities::TR4
if (item->AIBits & GUARD)
{
item->Animation.TargetState = AHMET_STATE_IDLE;
- headY = AIGuard(creature);
+ extraHeadRot.y = AIGuard(creature);
}
else if (item->AIBits & PATROL1)
{
item->Animation.TargetState = AHMET_STATE_WALK_FORWARD;
- headY = 0;
+ extraHeadRot.y = 0;
}
else if (creature->Mood == MoodType::Bored || creature->Mood == MoodType::Escape)
{
@@ -239,7 +239,7 @@ namespace TEN::Entities::TR4
if (item->AIBits & PATROL1)
{
item->Animation.TargetState = AHMET_STATE_WALK_FORWARD;
- headY = 0;
+ extraHeadRot.y = 0;
}
else if (AI.bite && AI.distance < AHMET_IDLE_RANGE)
item->Animation.TargetState = AHMET_STATE_IDLE;
@@ -371,7 +371,7 @@ namespace TEN::Entities::TR4
TestTriggers(item, true);
CreatureTilt(item, 0);
- CreatureJoint(item, 0, headY);
+ CreatureJoint(item, 0, extraHeadRot.y);
CreatureAnimation(itemNumber, angle, 0);
}
From a92a3c76447775e01891007bf08378c700a7a42b Mon Sep 17 00:00:00 2001
From: Sezz
Date: Fri, 19 Aug 2022 16:22:28 +1000
Subject: [PATCH 011/106] Demagic raptor ranges and probabilities
---
TombEngine/Objects/TR3/Entity/tr3_raptor.cpp | 26 +++++++++++---------
TombEngine/Objects/TR3/Entity/tr3_tiger.cpp | 17 +++++++------
2 files changed, 25 insertions(+), 18 deletions(-)
diff --git a/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp b/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp
index 5a1864f7b..5ec7ab18c 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp
@@ -19,6 +19,11 @@ using std::vector;
namespace TEN::Entities::TR3
{
constexpr auto RAPTOR_ATTACK_DAMAGE = 100;
+ constexpr auto RAPTOR_BITE_ATTACK_RANGE = SQUARE(585);
+ constexpr auto RAPTOR_JUMP_ATTACK_RANGE = SQUARE(SECTOR(1.5f));
+ constexpr auto RAPTOR_RUN_ATTACK_RANGE = SQUARE(SECTOR(1.5f));
+ constexpr auto RAPTOR_ROAR_CHANCE = 0.004f;
+ constexpr auto RAPTOR_SWITCH_TARGET_CHANCE = 0.008f;
#define RAPTOR_WALK_TURN_RATE_MAX ANGLE(2.0f)
#define RAPTOR_RUN_TURN_RATE_MAX ANGLE(2.0f)
@@ -86,14 +91,13 @@ namespace TEN::Entities::TR3
}
else
{
- if (creature->Enemy == nullptr || TestProbability(0.008f))
+ if (creature->Enemy == nullptr || TestProbability(RAPTOR_SWITCH_TARGET_CHANCE))
{
ItemInfo* nearestItem = nullptr;
int minDistance = INT_MAX;
- for (int i = 0; i < ActiveCreatures.size(); i++)
+ for (auto* currentCreature : ActiveCreatures)
{
- auto* currentCreature = ActiveCreatures[i];
if (currentCreature->ItemNumber == NO_ITEM || currentCreature->ItemNumber == itemNumber)
{
currentCreature++;
@@ -106,7 +110,7 @@ namespace TEN::Entities::TR3
int y = (targetItem->Pose.Position.y - item->Pose.Position.y) / 64;
int z = (targetItem->Pose.Position.z - item->Pose.Position.z) / 64;
- int distance = pow(x, 2) + pow(y, 2) + pow(z, 2);
+ int distance = SQUARE(x) + SQUARE(y) + SQUARE(z);
if (distance < minDistance && item->HitPoints > 0)
{
nearestItem = targetItem;
@@ -118,7 +122,7 @@ namespace TEN::Entities::TR3
if (nearestItem != nullptr &&
(nearestItem->ObjectNumber != ID_RAPTOR ||
- (TestProbability(0.03f) && minDistance < pow(SECTOR(2), 2))))
+ (TestProbability(0.03f) && minDistance < SQUARE(SECTOR(2)))))
{
creature->Enemy = nearestItem;
}
@@ -127,7 +131,7 @@ namespace TEN::Entities::TR3
int y = (LaraItem->Pose.Position.y - item->Pose.Position.y) / 64;
int z = (LaraItem->Pose.Position.z - item->Pose.Position.z) / 64;
- int distance = pow(x, 2) + pow(y, 2) + pow(z, 2);
+ int distance = SQUARE(x) + SQUARE(y) + SQUARE(z);
if (distance <= minDistance)
creature->Enemy = LaraItem;
}
@@ -164,11 +168,11 @@ namespace TEN::Entities::TR3
item->Animation.TargetState = RAPTOR_STATE_ROAR;
}
else if (item->TestBits(JointBitType::Touch, RaptorAttackJoints) ||
- (AI.distance < pow(585, 2) && AI.bite))
+ (AI.distance < RAPTOR_BITE_ATTACK_RANGE && AI.bite))
{
item->Animation.TargetState = RAPTOR_STATE_BITE_ATTACK;
}
- else if (AI.bite && AI.distance < pow(SECTOR(1.5f), 2))
+ else if (AI.bite && AI.distance < RAPTOR_JUMP_ATTACK_RANGE)
item->Animation.TargetState = RAPTOR_STATE_JUMP_ATTACK;
else if (creature->Mood == MoodType::Escape &&
Lara.TargetEntity != item && AI.ahead && !item->HitStatus)
@@ -188,7 +192,7 @@ namespace TEN::Entities::TR3
if (creature->Mood != MoodType::Bored)
item->Animation.TargetState = RAPTOR_STATE_IDLE;
- else if (AI.ahead && TestProbability(0.004f))
+ else if (AI.ahead && TestProbability(RAPTOR_ROAR_CHANCE))
{
item->Animation.TargetState = RAPTOR_STATE_IDLE;
item->Animation.RequiredState = RAPTOR_STATE_ROAR;
@@ -210,7 +214,7 @@ namespace TEN::Entities::TR3
item->Animation.RequiredState = RAPTOR_STATE_ROAR;
creature->Flags &= ~2;
}
- else if (AI.bite && AI.distance < pow(SECTOR(1.5f), 2))
+ else if (AI.bite && AI.distance < RAPTOR_RUN_ATTACK_RANGE)
{
if (item->Animation.TargetState == RAPTOR_STATE_RUN_FORWARD)
{
@@ -221,7 +225,7 @@ namespace TEN::Entities::TR3
}
}
else if (AI.ahead && creature->Mood != MoodType::Escape &&
- TestProbability(0.004f))
+ TestProbability(RAPTOR_ROAR_CHANCE))
{
item->Animation.TargetState = RAPTOR_STATE_IDLE;
item->Animation.RequiredState = RAPTOR_STATE_ROAR;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp b/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp
index 404fbaf58..cadb2a7bd 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp
@@ -18,11 +18,9 @@ using std::vector;
namespace TEN::Entities::TR3
{
constexpr auto TIGER_ATTACK_DAMAGE = 90;
-
constexpr auto TIGER_BITE_ATTACK_RANGE = SQUARE(SECTOR(0.33f));
constexpr auto TIGER_POUNCE_ATTACK_RANGE = SQUARE(SECTOR(1));
constexpr auto TIGER_RUN_ATTACK_RANGE = SQUARE(SECTOR(1.5f));
-
constexpr auto TIGER_WALK_CHANCE = 0.035f;
constexpr auto TIGER_ROAR_CHANCE = 0.003f;
@@ -42,7 +40,7 @@ namespace TEN::Entities::TR3
// No state 4.
TIGER_STATE_ROAR = 5,
TIGER_STATE_BITE_ATTACK = 6,
- TIGER_STATE_SWIPE_ATTACK = 7,
+ TIGER_STATE_RUN_SWIPE_ATTACK = 7,
TIGER_STATE_POUNCE_ATTACK = 8
};
@@ -50,7 +48,7 @@ namespace TEN::Entities::TR3
{
TIGER_ANIM_IDLE_TO_RUN_FORWARD = 0,
TIGER_ANIM_BITE_ATTACK = 1,
- TIGER_ANIM_SWIPE_ATTACK = 2,
+ TIGER_ANIM_RUN_SWIPE_ATTACK = 2,
TIGER_ANIM_POUNCE_ATTACK_START = 3,
TIGER_ANIM_ROAR = 4,
TIGER_ANIM_RUN_FORWARD = 5,
@@ -63,6 +61,11 @@ namespace TEN::Entities::TR3
TIGER_ANIM_POUNCE_ATTACK_END = 12
};
+ enum TigerFlags
+ {
+ TIGER_FLAG_ATTACKING = (1 << 0)
+ };
+
void TigerControl(short itemNumber)
{
if (!CreatureActive(itemNumber))
@@ -161,7 +164,7 @@ namespace TEN::Entities::TR3
if (LaraItem->Animation.Velocity.z == 0.0f)
item->Animation.TargetState = TIGER_STATE_IDLE;
else
- item->Animation.TargetState = TIGER_STATE_SWIPE_ATTACK;
+ item->Animation.TargetState = TIGER_STATE_RUN_SWIPE_ATTACK;
}
else if (creature->Mood != MoodType::Attack && TestProbability(TIGER_ROAR_CHANCE))
{
@@ -178,13 +181,13 @@ namespace TEN::Entities::TR3
break;
case TIGER_STATE_BITE_ATTACK:
- case TIGER_STATE_SWIPE_ATTACK:
+ case TIGER_STATE_RUN_SWIPE_ATTACK:
case TIGER_STATE_POUNCE_ATTACK:
if (!creature->Flags && item->TestBits(JointBitType::Touch, TigerAttackJoints))
{
DoDamage(creature->Enemy, TIGER_ATTACK_DAMAGE);
CreatureEffect(item, TigerBite, DoBloodSplat);
- creature->Flags = 1;
+ creature->Flags = TIGER_FLAG_ATTACKING;
}
break;
From 99086467de91036c4cc94598c23bcbfcf5414982 Mon Sep 17 00:00:00 2001
From: Sezz
Date: Fri, 19 Aug 2022 16:49:27 +1000
Subject: [PATCH 012/106] Cleanup
---
TombEngine/Objects/TR3/Entity/tr3_cobra.cpp | 3 +-
TombEngine/Objects/TR3/Entity/tr3_raptor.cpp | 6 ++-
TombEngine/Objects/TR3/Entity/tr3_tiger.cpp | 4 +-
TombEngine/Objects/TR3/Entity/tr3_trex.cpp | 48 +++++++++++---------
4 files changed, 35 insertions(+), 26 deletions(-)
diff --git a/TombEngine/Objects/TR3/Entity/tr3_cobra.cpp b/TombEngine/Objects/TR3/Entity/tr3_cobra.cpp
index 899c40376..fdb3806ec 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_cobra.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_cobra.cpp
@@ -24,7 +24,6 @@ namespace TEN::Entities::TR3
constexpr auto COBRA_SLEEP_RANGE = SQUARE(SECTOR(2.5f));
constexpr auto PLAYER_DISTURB_VELOCITY = 15;
-
constexpr auto COBRA_SLEEP_FRAME = 45;
const auto CobraBite = BiteInfo(Vector3::Zero, 13);
@@ -65,9 +64,9 @@ namespace TEN::Entities::TR3
auto* item = &g_Level.Items[itemNumber];
auto* creature = GetCreatureInfo(item);
- short head = 0;
short angle = 0;
short tilt = 0;
+ short head = 0;
if (item->HitPoints <= 0 && item->HitPoints != NOT_TARGETABLE)
{
diff --git a/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp b/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp
index 5ec7ab18c..a74c292dc 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp
@@ -19,9 +19,11 @@ using std::vector;
namespace TEN::Entities::TR3
{
constexpr auto RAPTOR_ATTACK_DAMAGE = 100;
+
constexpr auto RAPTOR_BITE_ATTACK_RANGE = SQUARE(585);
constexpr auto RAPTOR_JUMP_ATTACK_RANGE = SQUARE(SECTOR(1.5f));
constexpr auto RAPTOR_RUN_ATTACK_RANGE = SQUARE(SECTOR(1.5f));
+
constexpr auto RAPTOR_ROAR_CHANCE = 0.004f;
constexpr auto RAPTOR_SWITCH_TARGET_CHANCE = 0.008f;
@@ -79,10 +81,10 @@ namespace TEN::Entities::TR3
auto* item = &g_Level.Items[itemNumber];
auto* creature = GetCreatureInfo(item);
- short head = 0;
- short neck = 0;
short angle = 0;
short tilt = 0;
+ short head = 0;
+ short neck = 0;
if (item->HitPoints <= 0)
{
diff --git a/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp b/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp
index cadb2a7bd..918e2729d 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp
@@ -18,9 +18,11 @@ using std::vector;
namespace TEN::Entities::TR3
{
constexpr auto TIGER_ATTACK_DAMAGE = 90;
+
constexpr auto TIGER_BITE_ATTACK_RANGE = SQUARE(SECTOR(0.33f));
constexpr auto TIGER_POUNCE_ATTACK_RANGE = SQUARE(SECTOR(1));
constexpr auto TIGER_RUN_ATTACK_RANGE = SQUARE(SECTOR(1.5f));
+
constexpr auto TIGER_WALK_CHANCE = 0.035f;
constexpr auto TIGER_ROAR_CHANCE = 0.003f;
@@ -124,8 +126,8 @@ namespace TEN::Entities::TR3
item->Animation.TargetState = TIGER_STATE_BITE_ATTACK;
else if (AI.bite && AI.distance < TIGER_POUNCE_ATTACK_RANGE)
{
- creature->MaxTurn = TIGER_POUNCE_ATTACK_TURN_RATE_MAX;
item->Animation.TargetState = TIGER_STATE_POUNCE_ATTACK;
+ creature->MaxTurn = TIGER_POUNCE_ATTACK_TURN_RATE_MAX;
}
else if (item->Animation.RequiredState)
item->Animation.TargetState = item->Animation.RequiredState;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_trex.cpp b/TombEngine/Objects/TR3/Entity/tr3_trex.cpp
index d68260be4..256ee4738 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_trex.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_trex.cpp
@@ -17,10 +17,15 @@ using std::vector;
namespace TEN::Entities::TR3
{
+ constexpr auto TREX_ROAR_CHANCE = 0.015f;
+
constexpr auto LARA_ANIM_TREX_DEATH_ANIM = 4;
const vector TRexAttackJoints = { 12, 13 };
+ #define TREX_WALK_TURN_RATE_MAX ANGLE(2.0f)
+ #define TREX_RUN_TURN_RATE_MAX ANGLE(4.0f)
+
enum TRexState
{
TREX_STATE_NONE = 0,
@@ -57,8 +62,9 @@ namespace TEN::Entities::TR3
if (laraItem->RoomNumber != tRexItem->RoomNumber)
ItemNewRoom(Lara.ItemNumber, tRexItem->RoomNumber);
- laraItem->Pose.Position = tRexItem->Pose.Position;
- laraItem->Pose.Orientation = Vector3Shrt(0, tRexItem->Pose.Orientation.y, 0);
+ laraItem->Pose = PHD_3DPOS(
+ tRexItem->Pose.Position,
+ Vector3Shrt(0, tRexItem->Pose.Orientation.y, 0));
laraItem->Animation.IsAirborne = false;
laraItem->Animation.AnimNumber = Objects[ID_LARA_EXTRA_ANIMS].animIndex + LARA_ANIM_TREX_DEATH_ANIM;
@@ -82,10 +88,10 @@ namespace TEN::Entities::TR3
return;
auto* item = &g_Level.Items[itemNumber];
- auto* info = GetCreatureInfo(item);
+ auto* creature = GetCreatureInfo(item);
- short head = 0;
short angle = 0;
+ short head = 0;
if (item->HitPoints <= 0)
{
@@ -105,18 +111,18 @@ namespace TEN::Entities::TR3
GetCreatureMood(item, &AI, true);
CreatureMood(item, &AI, true);
- angle = CreatureTurn(item, info->MaxTurn);
+ angle = CreatureTurn(item, creature->MaxTurn);
if (item->TouchBits)
DoDamage(LaraItem, (item->Animation.ActiveState == TREX_STATE_RUN_FORWARD) ? 10 : 1);
- info->Flags = (info->Mood != MoodType::Escape && !AI.ahead && AI.enemyFacing > -FRONT_ARC && AI.enemyFacing < FRONT_ARC);
+ creature->Flags = (creature->Mood != MoodType::Escape && !AI.ahead && AI.enemyFacing > -FRONT_ARC && AI.enemyFacing < FRONT_ARC);
if (AI.distance > pow(1500, 2) &&
AI.distance < pow(SECTOR(4), 2) &&
- AI.bite && !info->Flags)
+ AI.bite && !creature->Flags)
{
- info->Flags = 1;
+ creature->Flags = 1;
}
switch (item->Animation.ActiveState)
@@ -126,7 +132,7 @@ namespace TEN::Entities::TR3
item->Animation.TargetState = item->Animation.RequiredState;
else if (AI.distance < pow(1500, 2) && AI.bite)
item->Animation.TargetState = TREX_STATE_ATTACK;
- else if (info->Mood == MoodType::Bored || info->Flags)
+ else if (creature->Mood == MoodType::Bored || creature->Flags)
item->Animation.TargetState = TREX_STATE_WALK_FORWARD;
else
item->Animation.TargetState = TREX_STATE_RUN_FORWARD;
@@ -134,32 +140,32 @@ namespace TEN::Entities::TR3
break;
case TREX_STATE_WALK_FORWARD:
- info->MaxTurn = ANGLE(2.0f);
+ creature->MaxTurn = TREX_WALK_TURN_RATE_MAX;
- if (info->Mood != MoodType::Bored || !info->Flags)
+ if (creature->Mood != MoodType::Bored || !creature->Flags)
item->Animation.TargetState = TREX_STATE_IDLE;
- else if (AI.ahead && TestProbability(0.015f))
+ else if (AI.ahead && TestProbability(TREX_ROAR_CHANCE))
{
- item->Animation.RequiredState = TREX_STATE_ROAR;
item->Animation.TargetState = TREX_STATE_IDLE;
+ item->Animation.RequiredState = TREX_STATE_ROAR;
}
break;
case TREX_STATE_RUN_FORWARD:
- info->MaxTurn = ANGLE(4.0f);
+ creature->MaxTurn = TREX_RUN_TURN_RATE_MAX;
if (AI.distance < pow(SECTOR(5), 2) && AI.bite)
item->Animation.TargetState = TREX_STATE_IDLE;
- else if (info->Flags)
+ else if (creature->Flags)
item->Animation.TargetState = TREX_STATE_IDLE;
- else if (info->Mood != MoodType::Escape &&
- AI.ahead && TestProbability(0.015f))
+ else if (creature->Mood != MoodType::Escape &&
+ AI.ahead && TestProbability(TREX_ROAR_CHANCE))
{
- item->Animation.RequiredState = TREX_STATE_ROAR;
item->Animation.TargetState = TREX_STATE_IDLE;
+ item->Animation.RequiredState = TREX_STATE_ROAR;
}
- else if (info->Mood == MoodType::Bored)
+ else if (creature->Mood == MoodType::Bored)
item->Animation.TargetState = TREX_STATE_IDLE;
break;
@@ -178,8 +184,8 @@ namespace TEN::Entities::TR3
}
}
- CreatureJoint(item, 0, (short)(head * 2));
- info->JointRotation[1] = info->JointRotation[0];
+ CreatureJoint(item, 0, head * 2);
+ creature->JointRotation[1] = creature->JointRotation[0];
CreatureAnimation(itemNumber, angle, 0);
From 44e80f88f85d9604f4ae5dcc56bb0bfc64006dba Mon Sep 17 00:00:00 2001
From: hispidence
Date: Fri, 19 Aug 2022 22:42:16 +0100
Subject: [PATCH 013/106] Add mechanism for adding callbacks to be called
before/after OnControlPhase
---
TombEngine/Game/savegame.cpp | 28 ++++--
.../Scripting/Include/ScriptInterfaceGame.h | 3 +
.../Scripting/Internal/ReservedScriptNames.h | 7 +-
.../Internal/TEN/Logic/LogicHandler.cpp | 86 +++++++++++++++++++
.../Internal/TEN/Logic/LogicHandler.h | 36 +++-----
.../Internal/TEN/Rotation/Rotation.cpp | 3 +-
.../flatbuffers/ten_savegame_generated.h | 48 +++++++++--
.../Specific/savegame/schema/ten_savegame.fbs | 2 +
8 files changed, 175 insertions(+), 38 deletions(-)
diff --git a/TombEngine/Game/savegame.cpp b/TombEngine/Game/savegame.cpp
index a58985c66..377aab6bf 100644
--- a/TombEngine/Game/savegame.cpp
+++ b/TombEngine/Game/savegame.cpp
@@ -1026,16 +1026,9 @@ bool SaveGame::Save(int slot)
alternatePendulumOffset = alternatePendulumInfo.Finish();
}
-
- std::vector> levelTableVec;
- std::vector> levelStringVec2;
-
- //std::vector savedTables;
- std::vector savedStrings;
std::vector savedVars;
g_GameScript->GetVariables(savedVars);
-
std::vector> varsVec;
for (auto const& s : savedVars)
@@ -1107,6 +1100,13 @@ bool SaveGame::Save(int slot)
uvb.add_members(unionVec);
auto unionVecOffset = uvb.Finish();
+ std::vector callbackVecPreControl;
+ std::vector callbackVecPostControl;
+ g_GameScript->GetCallbackStrings(callbackVecPreControl, callbackVecPostControl);
+
+ auto stringsCallbackPreControl = fbb.CreateVectorOfStrings(callbackVecPreControl);
+ auto stringsCallbackPostControl = fbb.CreateVectorOfStrings(callbackVecPostControl);
+
Save::SaveGameBuilder sgb{ fbb };
sgb.add_header(headerOffset);
@@ -1150,6 +1150,8 @@ bool SaveGame::Save(int slot)
}
sgb.add_script_vars(unionVecOffset);
+ sgb.add_callbacks_pre_control(stringsCallbackPreControl);
+ sgb.add_callbacks_post_control(stringsCallbackPostControl);
auto sg = sgb.Finish();
fbb.Finish(sg);
@@ -1927,6 +1929,18 @@ bool SaveGame::Load(int slot)
g_GameScript->SetVariables(loadedVars);
+ std::vector callbacksPreControlVec;
+ auto callbacksPreControlOffsetVec = s->callbacks_pre_control();
+ for (auto const& s : *callbacksPreControlOffsetVec)
+ callbacksPreControlVec.push_back(s->str());
+
+ std::vector callbacksPostControlVec;
+ auto callbacksPostControlOffsetVec = s->callbacks_post_control();
+ for (auto const& s : *callbacksPostControlOffsetVec)
+ callbacksPostControlVec.push_back(s->str());
+
+ g_GameScript->SetCallbackStrings(callbacksPreControlVec, callbacksPostControlVec);
+
return true;
}
diff --git a/TombEngine/Scripting/Include/ScriptInterfaceGame.h b/TombEngine/Scripting/Include/ScriptInterfaceGame.h
index 33b7b3344..e49e5c80d 100644
--- a/TombEngine/Scripting/Include/ScriptInterfaceGame.h
+++ b/TombEngine/Scripting/Include/ScriptInterfaceGame.h
@@ -41,6 +41,9 @@ public:
virtual void GetVariables(std::vector & vars) = 0;
virtual void SetVariables(std::vector const& vars) = 0;
+
+ virtual void GetCallbackStrings(std::vector & preControl, std::vector & postControl) const = 0;
+ virtual void SetCallbackStrings(std::vector const & preControl, std::vector const & postControl) = 0;
};
extern ScriptInterfaceGame* g_GameScript;
diff --git a/TombEngine/Scripting/Internal/ReservedScriptNames.h b/TombEngine/Scripting/Internal/ReservedScriptNames.h
index ef99ae505..6ce0294ab 100644
--- a/TombEngine/Scripting/Internal/ReservedScriptNames.h
+++ b/TombEngine/Scripting/Internal/ReservedScriptNames.h
@@ -19,6 +19,7 @@ static constexpr char ScriptReserved_SoundSource[] = "SoundSource";
static constexpr char ScriptReserved_AIObject[] = "AIObject";
static constexpr char ScriptReserved_DisplayString[] = "DisplayString";
static constexpr char ScriptReserved_Vec3[] = "Vec3";
+static constexpr char ScriptReserved_Rotation[] = "Rotation";
// Member functions
static constexpr char ScriptReserved_New[] = "New";
@@ -92,8 +93,6 @@ static constexpr char ScriptReserved_SetTitleScreenImagePath[] = "SetTitleScreen
static constexpr char ScriptReserved_SetFarView[] = "SetFarView";
static constexpr char ScriptReserved_SetSettings[] = "SetSettings";
static constexpr char ScriptReserved_SetAnimations[] = "SetAnimations";
-
-// Flow Functions
static constexpr char ScriptReserved_SetStrings[] = "SetStrings";
static constexpr char ScriptReserved_GetString[] = "GetString";
static constexpr char ScriptReserved_SetLanguageNames[] = "SetLanguageNames";
@@ -129,6 +128,9 @@ static constexpr char ScriptReserved_ScreenToPercent[] = "ScreenToPercent";
static constexpr char ScriptReserved_PercentToScreen[] = "PercentToScreen";
static constexpr char ScriptReserved_HasLineOfSight[] = "HasLineOfSight";
+static constexpr char ScriptReserved_AddCallback[] = "AddCallback";
+static constexpr char ScriptReserved_RemoveCallback[] = "RemoveCallback";
+
static constexpr char ScriptReserved_EmitParticle[] = "EmitParticle";
static constexpr char ScriptReserved_EmitLightningArc[] = "EmitLightningArc";
static constexpr char ScriptReserved_EmitShockwave[] = "EmitShockwave";
@@ -154,6 +156,7 @@ static constexpr char ScriptReserved_KeyClear[] = "KeyClear";
static constexpr char ScriptReserved_ObjID[] = "ObjID";
static constexpr char ScriptReserved_BlendID[] = "BlendID";
static constexpr char ScriptReserved_DisplayStringOption[] = "DisplayStringOption";
+static constexpr char ScriptReserved_CallbackPoint[] = "CallbackPoint";
static constexpr char ScriptReserved_LevelVars[] = "LevelVars";
static constexpr char ScriptReserved_GameVars[] = "GameVars";
diff --git a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
index 9057db93e..5590508f8 100644
--- a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
@@ -17,6 +17,18 @@ Saving data, triggering functions, and callbacks for level-specific scripts.
@pragma nostrip
*/
+enum class CallbackPoint
+{
+ PreControl,
+ PostControl,
+};
+
+static const std::unordered_map kCallbackPoints
+{
+ {"PreControlPhase", CallbackPoint::PreControl},
+ {"PostControlPhase", CallbackPoint::PostControl},
+};
+
void SetVariable(sol::table tab, sol::object key, sol::object value)
{
switch (value.get_type())
@@ -63,6 +75,16 @@ sol::object GetVariable(sol::table tab, sol::object key)
LogicHandler::LogicHandler(sol::state* lua, sol::table & parent) : m_handler{ lua }
{
m_handler.GetState()->set_function("print", &LogicHandler::LogPrint, this);
+
+ sol::table table_logic{ m_handler.GetState()->lua_state(), sol::create };
+
+ parent.set(ScriptReserved_Logic, table_logic);
+
+ table_logic.set_function(ScriptReserved_AddCallback, &LogicHandler::AddCallback, this);
+ table_logic.set_function(ScriptReserved_RemoveCallback, &LogicHandler::RemoveCallback, this);
+
+ m_handler.MakeReadOnlyTable(table_logic, ScriptReserved_CallbackPoint, kCallbackPoints);
+
ResetScripts(true);
}
@@ -71,6 +93,33 @@ void LogicHandler::ResetGameTables()
MakeSpecialTable(m_handler.GetState(), ScriptReserved_GameVars, &GetVariable, &SetVariable);
}
+void LogicHandler::AddCallback(CallbackPoint point, std::string const & name)
+{
+ switch(point)
+ {
+ case CallbackPoint::PreControl:
+ m_callbacksPreControl.insert(name);
+ break;
+
+ case CallbackPoint::PostControl:
+ m_callbacksPostControl.insert(name);
+ break;
+ }
+}
+
+void LogicHandler::RemoveCallback(CallbackPoint point, std::string const & name)
+{
+ switch(point)
+ {
+ case CallbackPoint::PreControl:
+ m_callbacksPreControl.erase(name);
+ break;
+
+ case CallbackPoint::PostControl:
+ m_callbacksPostControl.erase(name);
+ break;
+ }
+}
void LogicHandler::ResetLevelTables()
{
@@ -121,6 +170,9 @@ void LogicHandler::ResetScripts(bool clearGameVars)
{
FreeLevelScripts();
+ m_callbacksPreControl.clear();
+ m_callbacksPostControl.clear();
+
auto currentPackage = m_handler.GetState()->get("package");
auto currentLoaded = currentPackage.get("loaded");
@@ -347,6 +399,24 @@ void LogicHandler::GetVariables(std::vector & vars)
populate(tab);
}
+void LogicHandler::GetCallbackStrings(std::vector& preControl, std::vector& postControl) const
+{
+ for (auto const& s : m_callbacksPreControl)
+ preControl.push_back(s);
+
+ for (auto const& s : m_callbacksPostControl)
+ postControl.push_back(s);
+}
+
+void LogicHandler::SetCallbackStrings(std::vector const & preControl, std::vector const & postControl)
+{
+ for (auto const& s : preControl)
+ m_callbacksPreControl.insert(s);
+
+ for (auto const& s : postControl)
+ m_callbacksPostControl.insert(s);
+}
+
template
std::unique_ptr GetByName(std::string const & type, std::string const & name, mapType const & map)
{
@@ -428,9 +498,25 @@ void LogicHandler::OnLoad()
void LogicHandler::OnControlPhase(float dt)
{
+ sol::table levelFuncs = (*m_handler.GetState())[ScriptReserved_LevelFuncs];
+
+ auto tryCall = [dt, &levelFuncs](std::string const& name)
+ {
+ if (!levelFuncs[name].valid())
+ ScriptAssertF(false, "Callback {} not valid", name);
+ else
+ levelFuncs[name].call(dt);
+ };
+
+ for (auto& name : m_callbacksPreControl)
+ tryCall(name);
+
lua_gc(m_handler.GetState()->lua_state(), LUA_GCCOLLECT, 0);
if(m_onControlPhase.valid())
doCallback(m_onControlPhase, dt);
+
+ for (auto& name : m_callbacksPostControl)
+ tryCall(name);
}
void LogicHandler::OnSave()
diff --git a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.h b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.h
index db58965f6..498102f1c 100644
--- a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.h
+++ b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.h
@@ -5,28 +5,7 @@
#include
#include "Strings/StringsHandler.h"
-struct LuaFunction {
- std::string Name;
- std::string Code;
- bool Executed;
-};
-
-struct GameScriptVector3 {
- float x;
- float y;
- float z;
-};
-
-struct LuaVariable
-{
- bool IsGlobal;
- std::string Name;
- int Type;
- float FloatValue;
- int IntValue;
- std::string StringValue;
- bool BoolValue;
-};
+enum class CallbackPoint;
class LogicHandler : public ScriptInterfaceGame
{
@@ -38,6 +17,9 @@ private:
sol::protected_function m_onSave{};
sol::protected_function m_onEnd{};
+ std::unordered_set m_callbacksPreControl;
+ std::unordered_set m_callbacksPostControl;
+
void ResetLevelTables();
void ResetGameTables();
LuaHandler m_handler;
@@ -49,6 +31,10 @@ public:
void LogPrint(sol::variadic_args va);
bool SetLevelFunc(sol::table tab, std::string const& luaName, sol::object value);
+
+ void AddCallback(CallbackPoint point, std::string const& name);
+ void RemoveCallback(CallbackPoint point, std::string const & name);
+
void ResetScripts(bool clearGameVars) override;
sol::protected_function GetLevelFunc(sol::table tab, std::string const& luaName);
@@ -59,13 +45,17 @@ public:
void ExecuteFunction(std::string const& name, short idOne, short idTwo) override;
void GetVariables(std::vector& vars) override;
+ void SetVariables(std::vector const& vars) override;
void ResetVariables();
- void SetVariables(std::vector const& vars) override;
+ void SetCallbackStrings(std::vector const& preControl, std::vector const& postControl) override;
+ void GetCallbackStrings(std::vector& preControl, std::vector& postControl) const override;
+
void InitCallbacks() override;
void OnStart() override;
void OnLoad() override;
void OnControlPhase(float dt) override;
void OnSave() override;
void OnEnd() override;
+
};
diff --git a/TombEngine/Scripting/Internal/TEN/Rotation/Rotation.cpp b/TombEngine/Scripting/Internal/TEN/Rotation/Rotation.cpp
index 88f796cb4..479e9c9f1 100644
--- a/TombEngine/Scripting/Internal/TEN/Rotation/Rotation.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Rotation/Rotation.cpp
@@ -1,5 +1,6 @@
#include "framework.h"
#include "Rotation.h"
+#include "ReservedScriptNames.h"
#include "Specific/phd_global.h"
/*** Represents a rotation.
@@ -13,7 +14,7 @@ All values will be clamped to [-32768, 32767].
void Rotation::Register(sol::table & parent)
{
using ctors = sol::constructors;
- parent.new_usertype("Rotation",
+ parent.new_usertype(ScriptReserved_Rotation,
ctors(),
sol::call_constructor, ctors(),
sol::meta_function::to_string, &Rotation::ToString,
diff --git a/TombEngine/Specific/savegame/flatbuffers/ten_savegame_generated.h b/TombEngine/Specific/savegame/flatbuffers/ten_savegame_generated.h
index a3ce470cc..9d157a5a0 100644
--- a/TombEngine/Specific/savegame/flatbuffers/ten_savegame_generated.h
+++ b/TombEngine/Specific/savegame/flatbuffers/ten_savegame_generated.h
@@ -5849,6 +5849,8 @@ struct SaveGameT : public flatbuffers::NativeTable {
std::vector> volume_states{};
std::vector> call_counters{};
std::unique_ptr script_vars{};
+ std::vector callbacks_pre_control{};
+ std::vector callbacks_post_control{};
};
struct SaveGame FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
@@ -5891,7 +5893,9 @@ struct SaveGame FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
VT_ALTERNATE_PENDULUM = 68,
VT_VOLUME_STATES = 70,
VT_CALL_COUNTERS = 72,
- VT_SCRIPT_VARS = 74
+ VT_SCRIPT_VARS = 74,
+ VT_CALLBACKS_PRE_CONTROL = 76,
+ VT_CALLBACKS_POST_CONTROL = 78
};
const TEN::Save::SaveGameHeader *header() const {
return GetPointer(VT_HEADER);
@@ -6001,6 +6005,12 @@ struct SaveGame FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
const TEN::Save::UnionVec *script_vars() const {
return GetPointer(VT_SCRIPT_VARS);
}
+ const flatbuffers::Vector> *callbacks_pre_control() const {
+ return GetPointer> *>(VT_CALLBACKS_PRE_CONTROL);
+ }
+ const flatbuffers::Vector> *callbacks_post_control() const {
+ return GetPointer> *>(VT_CALLBACKS_POST_CONTROL);
+ }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyOffset(verifier, VT_HEADER) &&
@@ -6079,6 +6089,12 @@ struct SaveGame FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
verifier.VerifyVectorOfTables(call_counters()) &&
VerifyOffset(verifier, VT_SCRIPT_VARS) &&
verifier.VerifyTable(script_vars()) &&
+ VerifyOffset(verifier, VT_CALLBACKS_PRE_CONTROL) &&
+ verifier.VerifyVector(callbacks_pre_control()) &&
+ verifier.VerifyVectorOfStrings(callbacks_pre_control()) &&
+ VerifyOffset(verifier, VT_CALLBACKS_POST_CONTROL) &&
+ verifier.VerifyVector(callbacks_post_control()) &&
+ verifier.VerifyVectorOfStrings(callbacks_post_control()) &&
verifier.EndTable();
}
SaveGameT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
@@ -6198,6 +6214,12 @@ struct SaveGameBuilder {
void add_script_vars(flatbuffers::Offset script_vars) {
fbb_.AddOffset(SaveGame::VT_SCRIPT_VARS, script_vars);
}
+ void add_callbacks_pre_control(flatbuffers::Offset>> callbacks_pre_control) {
+ fbb_.AddOffset(SaveGame::VT_CALLBACKS_PRE_CONTROL, callbacks_pre_control);
+ }
+ void add_callbacks_post_control(flatbuffers::Offset>> callbacks_post_control) {
+ fbb_.AddOffset(SaveGame::VT_CALLBACKS_POST_CONTROL, callbacks_post_control);
+ }
explicit SaveGameBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
@@ -6246,10 +6268,14 @@ inline flatbuffers::Offset CreateSaveGame(
flatbuffers::Offset alternate_pendulum = 0,
flatbuffers::Offset>> volume_states = 0,
flatbuffers::Offset>> call_counters = 0,
- flatbuffers::Offset script_vars = 0) {
+ flatbuffers::Offset script_vars = 0,
+ flatbuffers::Offset>> callbacks_pre_control = 0,
+ flatbuffers::Offset>> callbacks_post_control = 0) {
SaveGameBuilder builder_(_fbb);
builder_.add_oneshot_position(oneshot_position);
builder_.add_ambient_position(ambient_position);
+ builder_.add_callbacks_post_control(callbacks_post_control);
+ builder_.add_callbacks_pre_control(callbacks_pre_control);
builder_.add_script_vars(script_vars);
builder_.add_call_counters(call_counters);
builder_.add_volume_states(volume_states);
@@ -6329,7 +6355,9 @@ inline flatbuffers::Offset CreateSaveGameDirect(
flatbuffers::Offset alternate_pendulum = 0,
const std::vector> *volume_states = nullptr,
const std::vector> *call_counters = nullptr,
- flatbuffers::Offset script_vars = 0) {
+ flatbuffers::Offset script_vars = 0,
+ const std::vector> *callbacks_pre_control = nullptr,
+ const std::vector> *callbacks_post_control = nullptr) {
auto items__ = items ? _fbb.CreateVector>(*items) : 0;
auto room_items__ = room_items ? _fbb.CreateVector(*room_items) : 0;
auto fxinfos__ = fxinfos ? _fbb.CreateVector>(*fxinfos) : 0;
@@ -6349,6 +6377,8 @@ inline flatbuffers::Offset CreateSaveGameDirect(
auto cd_flags__ = cd_flags ? _fbb.CreateVector(*cd_flags) : 0;
auto volume_states__ = volume_states ? _fbb.CreateVector>(*volume_states) : 0;
auto call_counters__ = call_counters ? _fbb.CreateVector>(*call_counters) : 0;
+ auto callbacks_pre_control__ = callbacks_pre_control ? _fbb.CreateVector>(*callbacks_pre_control) : 0;
+ auto callbacks_post_control__ = callbacks_post_control ? _fbb.CreateVector>(*callbacks_post_control) : 0;
return TEN::Save::CreateSaveGame(
_fbb,
header,
@@ -6386,7 +6416,9 @@ inline flatbuffers::Offset CreateSaveGameDirect(
alternate_pendulum,
volume_states__,
call_counters__,
- script_vars);
+ script_vars,
+ callbacks_pre_control__,
+ callbacks_post_control__);
}
flatbuffers::Offset CreateSaveGame(flatbuffers::FlatBufferBuilder &_fbb, const SaveGameT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
@@ -8117,6 +8149,8 @@ inline void SaveGame::UnPackTo(SaveGameT *_o, const flatbuffers::resolver_functi
{ auto _e = volume_states(); if (_e) { _o->volume_states.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->volume_states[_i] = std::unique_ptr(_e->Get(_i)->UnPack(_resolver)); } } }
{ auto _e = call_counters(); if (_e) { _o->call_counters.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->call_counters[_i] = std::unique_ptr(_e->Get(_i)->UnPack(_resolver)); } } }
{ auto _e = script_vars(); if (_e) _o->script_vars = std::unique_ptr(_e->UnPack(_resolver)); }
+ { auto _e = callbacks_pre_control(); if (_e) { _o->callbacks_pre_control.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->callbacks_pre_control[_i] = _e->Get(_i)->str(); } } }
+ { auto _e = callbacks_post_control(); if (_e) { _o->callbacks_post_control.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->callbacks_post_control[_i] = _e->Get(_i)->str(); } } }
}
inline flatbuffers::Offset SaveGame::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SaveGameT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
@@ -8163,6 +8197,8 @@ inline flatbuffers::Offset CreateSaveGame(flatbuffers::FlatBufferBuild
auto _volume_states = _fbb.CreateVector> (_o->volume_states.size(), [](size_t i, _VectorArgs *__va) { return CreateVolumeState(*__va->__fbb, __va->__o->volume_states[i].get(), __va->__rehasher); }, &_va );
auto _call_counters = _fbb.CreateVector> (_o->call_counters.size(), [](size_t i, _VectorArgs *__va) { return CreateEventSetCallCounters(*__va->__fbb, __va->__o->call_counters[i].get(), __va->__rehasher); }, &_va );
auto _script_vars = _o->script_vars ? CreateUnionVec(_fbb, _o->script_vars.get(), _rehasher) : 0;
+ auto _callbacks_pre_control = _fbb.CreateVectorOfStrings(_o->callbacks_pre_control);
+ auto _callbacks_post_control = _fbb.CreateVectorOfStrings(_o->callbacks_post_control);
return TEN::Save::CreateSaveGame(
_fbb,
_header,
@@ -8200,7 +8236,9 @@ inline flatbuffers::Offset CreateSaveGame(flatbuffers::FlatBufferBuild
_alternate_pendulum,
_volume_states,
_call_counters,
- _script_vars);
+ _script_vars,
+ _callbacks_pre_control,
+ _callbacks_post_control);
}
inline bool VerifyVarUnion(flatbuffers::Verifier &verifier, const void *obj, VarUnion type) {
diff --git a/TombEngine/Specific/savegame/schema/ten_savegame.fbs b/TombEngine/Specific/savegame/schema/ten_savegame.fbs
index 2e1d13b31..f5f467269 100644
--- a/TombEngine/Specific/savegame/schema/ten_savegame.fbs
+++ b/TombEngine/Specific/savegame/schema/ten_savegame.fbs
@@ -458,6 +458,8 @@ table SaveGame {
volume_states: [VolumeState];
call_counters: [EventSetCallCounters];
script_vars: UnionVec;
+ callbacks_pre_control: [string];
+ callbacks_post_control: [string];
}
root_type TEN.Save.SaveGame;
From 0f8bc8676855bff38742931f1c85d5b11ec00045 Mon Sep 17 00:00:00 2001
From: hispidence
Date: Fri, 19 Aug 2022 23:18:03 +0100
Subject: [PATCH 014/106] Add documentation. Put constants in caps for
consistency.
---
Documentation/doc/1 modules/Logic.html | 83 +++++++++++++++++++
.../Internal/TEN/Logic/LogicHandler.cpp | 28 ++++++-
2 files changed, 109 insertions(+), 2 deletions(-)
diff --git a/Documentation/doc/1 modules/Logic.html b/Documentation/doc/1 modules/Logic.html
index 75f3dbfed..9c1deb41d 100644
--- a/Documentation/doc/1 modules/Logic.html
+++ b/Documentation/doc/1 modules/Logic.html
@@ -32,6 +32,7 @@
Contents
@@ -94,6 +95,17 @@
+
+
@@ -121,6 +133,77 @@
+
+
+
+
+
+ AddCallback(CallbackPoint, string)
+
+
+ Register a function as a callback.
+Possible values for CallbackPoint:
+PRECONTROLPHASE -- will be called immediately before OnControlPhase
+POSTCONTROLPHASE -- will be called immediately after OnControlPhase
+
+
+The order in which two functions with the same CallbackPoint are called is undefined.
+i.e. if you register MyFunc
and MyFunc2
with PRECONTROLPHASE
, both will be called before OnControlPhase
, but there is no guarantee whether MyFunc
will be called before MyFunc2
, or vice-versa.
+
+
+
Parameters:
+
+ CallbackPoint
+ point
+ When should the callback be called?
+
+ string
+ func
+ The LevelFuncs function to be called. Will receive as an argument the time in seconds since the last frame.
+
+
+
+
+
+
+ Usage:
+ LevelFuncs.MyFunc = function (dt) print (dt) end
+TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.PRECONTROLPHASE, "MyFunc" )
+
+
+
+
+
+ RemoveCallback(CallbackPoint, string)
+
+
+ Deregister a function as a callback.
+Will have no effect if the function was not registered as a callback
+
+
+ Parameters:
+
+ CallbackPoint
+ point
+ The callback point the function was registered with. See AddCallback
+
+ string
+ func
+ The LevelFuncs function to remove.
+
+
+
+
+
+
+ Usage:
+ TEN.Logic.RemoveCallback(TEN.Logic.CallbackPoint.PRECONTROLPHASE, "MyFunc" )
+
+
+
+
diff --git a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
index 5590508f8..c1d2ec656 100644
--- a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
@@ -25,8 +25,8 @@ enum class CallbackPoint
static const std::unordered_map kCallbackPoints
{
- {"PreControlPhase", CallbackPoint::PreControl},
- {"PostControlPhase", CallbackPoint::PostControl},
+ {"PRECONTROLPHASE", CallbackPoint::PreControl},
+ {"POSTCONTROLPHASE", CallbackPoint::PostControl},
};
void SetVariable(sol::table tab, sol::object key, sol::object value)
@@ -93,6 +93,21 @@ void LogicHandler::ResetGameTables()
MakeSpecialTable(m_handler.GetState(), ScriptReserved_GameVars, &GetVariable, &SetVariable);
}
+/*** Register a function as a callback.
+Possible values for CallbackPoint:
+ PRECONTROLPHASE -- will be called immediately before OnControlPhase
+ POSTCONTROLPHASE -- will be called immediately after OnControlPhase
+
+The order in which two functions with the same CallbackPoint are called is undefined.
+i.e. if you register `MyFunc` and `MyFunc2` with `PRECONTROLPHASE`, both will be called before `OnControlPhase`, but there is no guarantee whether `MyFunc` will be called before `MyFunc2`, or vice-versa.
+
+@function AddCallback
+@tparam point CallbackPoint When should the callback be called?
+@tparam func string The LevelFuncs function to be called. Will receive as an argument the time in seconds since the last frame.
+@usage
+ LevelFuncs.MyFunc = function(dt) print(dt) end
+ TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.PRECONTROLPHASE, "MyFunc")
+*/
void LogicHandler::AddCallback(CallbackPoint point, std::string const & name)
{
switch(point)
@@ -107,6 +122,15 @@ void LogicHandler::AddCallback(CallbackPoint point, std::string const & name)
}
}
+/*** Deregister a function as a callback.
+Will have no effect if the function was not registered as a callback
+
+@function RemoveCallback
+@tparam point CallbackPoint The callback point the function was registered with. See @{AddCallback}
+@tparam func string The LevelFuncs function to remove.
+@usage
+ TEN.Logic.RemoveCallback(TEN.Logic.CallbackPoint.PRECONTROLPHASE, "MyFunc")
+*/
void LogicHandler::RemoveCallback(CallbackPoint point, std::string const & name)
{
switch(point)
From 267b05c91f9a0a3ef6aaa19b9e576f94463eec2a Mon Sep 17 00:00:00 2001
From: hispidence
Date: Sat, 20 Aug 2022 14:23:07 +0100
Subject: [PATCH 015/106] Allow Vec3s to be saved and loaded in LevelVars and
GameVars
---
TombEngine/Game/savegame.cpp | 60 ++++----
.../Scripting/Include/ScriptInterfaceGame.h | 2 +-
.../Internal/TEN/Logic/LogicHandler.cpp | 71 ++++++---
.../TEN/Objects/Moveable/MoveableObject.cpp | 2 -
.../Scripting/Internal/TEN/Vec3/Vec3.cpp | 9 ++
TombEngine/Scripting/Internal/TEN/Vec3/Vec3.h | 5 +
.../flatbuffers/ten_savegame_generated.h | 141 +++++++++++++++++-
.../Specific/savegame/schema/ten_savegame.fbs | 7 +-
8 files changed, 240 insertions(+), 57 deletions(-)
diff --git a/TombEngine/Game/savegame.cpp b/TombEngine/Game/savegame.cpp
index 377aab6bf..6ee4de384 100644
--- a/TombEngine/Game/savegame.cpp
+++ b/TombEngine/Game/savegame.cpp
@@ -1033,29 +1033,38 @@ bool SaveGame::Save(int slot)
std::vector> varsVec;
for (auto const& s : savedVars)
{
- flatbuffers::Offset scriptTableOffset;
- flatbuffers::Offset strOffset;
- flatbuffers::Offset doubleOffset;
- flatbuffers::Offset boolOffset;
+ auto putDataInVec = [&varsVec, &fbb](Save::VarUnion type, auto const & offsetVar)
+ {
+ Save::UnionTableBuilder ut{ fbb };
+ ut.add_u_type(type);
+ ut.add_u(offsetVar.Union());
+ varsVec.push_back(ut.Finish());
+ };
if (std::holds_alternative(s))
{
auto strOffset2 = fbb.CreateString(std::get(s));
Save::stringTableBuilder stb{ fbb };
stb.add_str(strOffset2);
- strOffset = stb.Finish();
+ auto strOffset = stb.Finish();
+
+ putDataInVec(Save::VarUnion::str, strOffset);
}
else if (std::holds_alternative(s))
{
Save::doubleTableBuilder dtb{ fbb };
dtb.add_scalar(std::get(s));
- doubleOffset = dtb.Finish();
+ auto doubleOffset = dtb.Finish();
+
+ putDataInVec(Save::VarUnion::num, doubleOffset);
}
else if (std::holds_alternative(s))
{
Save::boolTableBuilder btb{ fbb };
btb.add_scalar(std::get(s));
- boolOffset = btb.Finish();
+ auto boolOffset = btb.Finish();
+
+ putDataInVec(Save::VarUnion::boolean, boolOffset);
}
else if (std::holds_alternative(s))
{
@@ -1069,31 +1078,20 @@ bool SaveGame::Save(int slot)
auto vecOffset = fbb.CreateVectorOfStructs(keyValVec);
Save::ScriptTableBuilder stb{ fbb };
stb.add_keys_vals(vecOffset);
- scriptTableOffset = stb.Finish();
- }
+ auto scriptTableOffset = stb.Finish();
- Save::UnionTableBuilder ut{ fbb };
- if (std::holds_alternative(s))
- {
- ut.add_u_type(Save::VarUnion::str);
- ut.add_u(strOffset.Union());
+ putDataInVec(Save::VarUnion::tab, scriptTableOffset);
}
- else if (std::holds_alternative(s))
+ else if (std::holds_alternative(s))
{
- ut.add_u_type(Save::VarUnion::num);
- ut.add_u(doubleOffset.Union());
+ Save::vec3TableBuilder vtb{ fbb };
+ Vector3Int data = std::get(s);
+ Save::Vector3 saveVec = FromVector3(std::get(s));
+ vtb.add_vec(&saveVec);
+ auto vec3Offset = vtb.Finish();
+
+ putDataInVec(Save::VarUnion::vec3, vec3Offset);
}
- else if (std::holds_alternative(s))
- {
- ut.add_u_type(Save::VarUnion::boolean);
- ut.add_u(boolOffset.Union());
- }
- else if (std::holds_alternative(s))
- {
- ut.add_u_type(Save::VarUnion::tab);
- ut.add_u(scriptTableOffset.Union());
- }
- varsVec.push_back(ut.Finish());
}
auto unionVec = fbb.CreateVector(varsVec);
Save::UnionVecBuilder uvb{ fbb };
@@ -1918,12 +1916,16 @@ bool SaveGame::Load(int slot)
{
auto tab = var->u_as_tab()->keys_vals();
auto& loadedTab = loadedVars.emplace_back(IndexTable{});
-
+
for (auto const& p : *tab)
{
std::get(loadedTab).push_back(std::make_pair(p->key(), p->val()));
}
}
+ else if (var->u_type() == Save::VarUnion::vec3)
+ {
+ loadedVars.push_back(ToVector3Int(var->u_as_vec3()->vec()));
+ }
}
}
diff --git a/TombEngine/Scripting/Include/ScriptInterfaceGame.h b/TombEngine/Scripting/Include/ScriptInterfaceGame.h
index e49e5c80d..7c4c087a2 100644
--- a/TombEngine/Scripting/Include/ScriptInterfaceGame.h
+++ b/TombEngine/Scripting/Include/ScriptInterfaceGame.h
@@ -19,7 +19,7 @@ using VarSaveType = std::variant;
using IndexTable = std::vector>;
-using SavedVar = std::variant;
+using SavedVar = std::variant;
class ScriptInterfaceGame {
public:
diff --git a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
index c1d2ec656..e51798363 100644
--- a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
@@ -8,6 +8,7 @@
#include "Game/effects/lightning.h"
#include "ScriptUtil.h"
#include "Objects/Moveable/MoveableObject.h"
+#include "Vec3/Vec3.h"
using namespace TEN::Effects::Lightning;
@@ -290,6 +291,11 @@ void LogicHandler::SetVariables(std::vector const & vars)
solTables[i][vars[first]] = vars[second];
}
}
+ else if (std::holds_alternative(vars[second]))
+ {
+ auto theVec = Vec3{ std::get(vars[second]) };
+ solTables[i][vars[first]] = theVec;
+ }
else
{
solTables[i][vars[first]] = vars[second];
@@ -322,12 +328,20 @@ void LogicHandler::GetVariables(std::vector & vars)
std::unordered_map varsMap;
std::unordered_map numMap;
std::unordered_map boolMap;
- size_t nVars = 0;
- auto handleNum = [&](double num)
- {
- auto [first, second] = numMap.insert(std::pair(num, nVars));
- // true if the var was inserted
+ size_t nVars = 0;
+
+ // The following functions will all try to put their values in a map. If it succeeds
+ // then the value was not already in the map, so we can put it into the var vector.
+ // If it fails, the value is in the map, and thus will also be in the var vector.
+ // We then return the value's position in the var vector.
+
+ // The purpose of this is to only store each value once, and to fill our tables with
+ // indices to the values rather than copies of the values.
+ auto handleNum = [&](double num)
+ {
+ auto [first, second] = numMap.insert(std::make_pair(num, nVars));
+
if (second)
{
vars.push_back(num);
@@ -339,9 +353,8 @@ void LogicHandler::GetVariables(std::vector & vars)
auto handleBool = [&](bool num)
{
- auto [first, second] = boolMap.insert(std::pair(num, nVars));
+ auto [first, second] = boolMap.insert(std::make_pair(num, nVars));
- // true if the var was inserted
if (second)
{
vars.push_back(num);
@@ -354,9 +367,8 @@ void LogicHandler::GetVariables(std::vector & vars)
auto handleStr = [&](sol::object const& obj)
{
auto str = obj.as();
- auto [first, second] = varsMap.insert(std::pair(str.data(), nVars));
+ auto [first, second] = varsMap.insert(std::make_pair(str.data(), nVars));
- // true if the string was inserted
if (second)
{
vars.push_back(std::string{ str.data() });
@@ -366,11 +378,23 @@ void LogicHandler::GetVariables(std::vector & vars)
return first->second;
};
+ auto handleVec3 = [&](Vec3 const & vec)
+ {
+ auto [first, second] = varsMap.insert(std::make_pair(&vec, nVars));
+
+ if (second)
+ {
+ vars.push_back(vec);
+ ++nVars;
+ }
+
+ return first->second;
+ };
+
std::function populate = [&](sol::table const & obj)
{
- auto [first, second] = varsMap.insert(std::pair(obj.pointer(), nVars));
+ auto [first, second] = varsMap.insert(std::make_pair(obj.pointer(), nVars));
- // true if the table was inserted
if(second)
{
++nVars;
@@ -394,24 +418,33 @@ void LogicHandler::GetVariables(std::vector & vars)
ScriptAssert(false, "Tried saving an unsupported type as a key");
}
+ auto putInVars = [&vars, id, keyIndex](uint32_t valIndex)
+ {
+ std::get(vars[id]).push_back(std::make_pair(keyIndex, valIndex));
+ };
+
uint32_t valIndex = 0;
switch (second.get_type())
{
case sol::type::table:
- valIndex = populate(second.as());
- std::get(vars[id]).push_back(std::make_pair(keyIndex, valIndex));
+ putInVars(populate(second.as()));
break;
case sol::type::string:
- valIndex = handleStr(second);
- std::get(vars[id]).push_back(std::make_pair(keyIndex, valIndex));
+ putInVars(handleStr(second));
break;
case sol::type::number:
- valIndex = handleNum(second.as());
- std::get(vars[id]).push_back(std::make_pair(keyIndex, valIndex));
+ putInVars(handleNum(second.as()));
break;
case sol::type::boolean:
- valIndex = handleBool(second.as());
- std::get(vars[id]).push_back(std::make_pair(keyIndex, valIndex));
+ putInVars(handleBool(second.as()));
+ break;
+ case sol::type::userdata:
+ {
+ if(second.is())
+ putInVars(handleVec3(second.as()));
+ else
+ ScriptAssert(false, "Tried saving an unsupported userdata as a value");
+ }
break;
default:
ScriptAssert(false, "Tried saving an unsupported type as a value");
diff --git a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
index f2354ea10..8edc6cb58 100644
--- a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
@@ -89,8 +89,6 @@ most can just be ignored (see usage).
0, -- room
)
*/
-
-
static std::unique_ptr Create(
GAME_OBJECT_ID objID,
std::string const & name,
diff --git a/TombEngine/Scripting/Internal/TEN/Vec3/Vec3.cpp b/TombEngine/Scripting/Internal/TEN/Vec3/Vec3.cpp
index 5c7de764f..c435f8dd7 100644
--- a/TombEngine/Scripting/Internal/TEN/Vec3/Vec3.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Vec3/Vec3.cpp
@@ -63,6 +63,15 @@ Vec3::Vec3(PHD_3DPOS const& pos) : x{pos.Position.x}, y{pos.Position.y}, z{pos.P
{
}
+Vec3::Vec3(Vector3Int const& pos) : x{pos.x}, y{pos.y}, z{pos.z}
+{
+}
+
+Vec3::operator Vector3Int() const
+{
+ return Vector3Int{ x, y, z };
+};
+
void Vec3::StoreInPHDPos(PHD_3DPOS& pos) const
{
pos.Position.x = x;
diff --git a/TombEngine/Scripting/Internal/TEN/Vec3/Vec3.h b/TombEngine/Scripting/Internal/TEN/Vec3/Vec3.h
index 0d51b62a9..4713b3cff 100644
--- a/TombEngine/Scripting/Internal/TEN/Vec3/Vec3.h
+++ b/TombEngine/Scripting/Internal/TEN/Vec3/Vec3.h
@@ -1,5 +1,7 @@
#pragma once
+struct Vector3Int;
+
namespace sol {
class state;
}
@@ -15,6 +17,9 @@ public:
Vec3(int x, int y, int z);
Vec3(PHD_3DPOS const& pos);
+ Vec3(Vector3Int const& pos);
+
+ operator Vector3Int() const;
[[nodiscard]] std::string ToString() const;
diff --git a/TombEngine/Specific/savegame/flatbuffers/ten_savegame_generated.h b/TombEngine/Specific/savegame/flatbuffers/ten_savegame_generated.h
index 9d157a5a0..ad9d4a229 100644
--- a/TombEngine/Specific/savegame/flatbuffers/ten_savegame_generated.h
+++ b/TombEngine/Specific/savegame/flatbuffers/ten_savegame_generated.h
@@ -139,6 +139,10 @@ struct boolTable;
struct boolTableBuilder;
struct boolTableT;
+struct vec3Table;
+struct vec3TableBuilder;
+struct vec3TableT;
+
struct UnionTable;
struct UnionTableBuilder;
struct UnionTableT;
@@ -201,35 +205,38 @@ enum class VarUnion : uint8_t {
tab = 2,
num = 3,
boolean = 4,
+ vec3 = 5,
MIN = NONE,
- MAX = boolean
+ MAX = vec3
};
-inline const VarUnion (&EnumValuesVarUnion())[5] {
+inline const VarUnion (&EnumValuesVarUnion())[6] {
static const VarUnion values[] = {
VarUnion::NONE,
VarUnion::str,
VarUnion::tab,
VarUnion::num,
- VarUnion::boolean
+ VarUnion::boolean,
+ VarUnion::vec3
};
return values;
}
inline const char * const *EnumNamesVarUnion() {
- static const char * const names[6] = {
+ static const char * const names[7] = {
"NONE",
"str",
"tab",
"num",
"boolean",
+ "vec3",
nullptr
};
return names;
}
inline const char *EnumNameVarUnion(VarUnion e) {
- if (flatbuffers::IsOutRange(e, VarUnion::NONE, VarUnion::boolean)) return "";
+ if (flatbuffers::IsOutRange(e, VarUnion::NONE, VarUnion::vec3)) return "";
const size_t index = static_cast(e);
return EnumNamesVarUnion()[index];
}
@@ -254,6 +261,10 @@ template<> struct VarUnionTraits {
static const VarUnion enum_value = VarUnion::boolean;
};
+template<> struct VarUnionTraits {
+ static const VarUnion enum_value = VarUnion::vec3;
+};
+
struct VarUnionUnion {
VarUnion type;
void *value;
@@ -318,6 +329,14 @@ struct VarUnionUnion {
return type == VarUnion::boolean ?
reinterpret_cast(value) : nullptr;
}
+ TEN::Save::vec3TableT *Asvec3() {
+ return type == VarUnion::vec3 ?
+ reinterpret_cast(value) : nullptr;
+ }
+ const TEN::Save::vec3TableT *Asvec3() const {
+ return type == VarUnion::vec3 ?
+ reinterpret_cast(value) : nullptr;
+ }
};
bool VerifyVarUnion(flatbuffers::Verifier &verifier, const void *obj, VarUnion type);
@@ -5361,6 +5380,64 @@ struct boolTable::Traits {
flatbuffers::Offset CreateboolTable(flatbuffers::FlatBufferBuilder &_fbb, const boolTableT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
+struct vec3TableT : public flatbuffers::NativeTable {
+ typedef vec3Table TableType;
+ std::unique_ptr vec{};
+};
+
+struct vec3Table FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
+ typedef vec3TableT NativeTableType;
+ typedef vec3TableBuilder Builder;
+ struct Traits;
+ enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
+ VT_VEC = 4
+ };
+ const TEN::Save::Vector3 *vec() const {
+ return GetStruct(VT_VEC);
+ }
+ bool Verify(flatbuffers::Verifier &verifier) const {
+ return VerifyTableStart(verifier) &&
+ VerifyField(verifier, VT_VEC) &&
+ verifier.EndTable();
+ }
+ vec3TableT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
+ void UnPackTo(vec3TableT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const;
+ static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const vec3TableT* _o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
+};
+
+struct vec3TableBuilder {
+ typedef vec3Table Table;
+ flatbuffers::FlatBufferBuilder &fbb_;
+ flatbuffers::uoffset_t start_;
+ void add_vec(const TEN::Save::Vector3 *vec) {
+ fbb_.AddStruct(vec3Table::VT_VEC, vec);
+ }
+ explicit vec3TableBuilder(flatbuffers::FlatBufferBuilder &_fbb)
+ : fbb_(_fbb) {
+ start_ = fbb_.StartTable();
+ }
+ flatbuffers::Offset Finish() {
+ const auto end = fbb_.EndTable(start_);
+ auto o = flatbuffers::Offset(end);
+ return o;
+ }
+};
+
+inline flatbuffers::Offset Createvec3Table(
+ flatbuffers::FlatBufferBuilder &_fbb,
+ const TEN::Save::Vector3 *vec = 0) {
+ vec3TableBuilder builder_(_fbb);
+ builder_.add_vec(vec);
+ return builder_.Finish();
+}
+
+struct vec3Table::Traits {
+ using type = vec3Table;
+ static auto constexpr Create = Createvec3Table;
+};
+
+flatbuffers::Offset Createvec3Table(flatbuffers::FlatBufferBuilder &_fbb, const vec3TableT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
+
struct UnionTableT : public flatbuffers::NativeTable {
typedef UnionTable TableType;
TEN::Save::VarUnionUnion u{};
@@ -5393,6 +5470,9 @@ struct UnionTable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
const TEN::Save::boolTable *u_as_boolean() const {
return u_type() == TEN::Save::VarUnion::boolean ? static_cast(u()) : nullptr;
}
+ const TEN::Save::vec3Table *u_as_vec3() const {
+ return u_type() == TEN::Save::VarUnion::vec3 ? static_cast(u()) : nullptr;
+ }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField(verifier, VT_U_TYPE) &&
@@ -5421,6 +5501,10 @@ template<> inline const TEN::Save::boolTable *UnionTable::u_as inline const TEN::Save::vec3Table *UnionTable::u_as() const {
+ return u_as_vec3();
+}
+
struct UnionTableBuilder {
typedef UnionTable Table;
flatbuffers::FlatBufferBuilder &fbb_;
@@ -7958,6 +8042,32 @@ inline flatbuffers::Offset CreateboolTable(flatbuffers::FlatBufferBui
_scalar);
}
+inline vec3TableT *vec3Table::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
+ auto _o = std::make_unique();
+ UnPackTo(_o.get(), _resolver);
+ return _o.release();
+}
+
+inline void vec3Table::UnPackTo(vec3TableT *_o, const flatbuffers::resolver_function_t *_resolver) const {
+ (void)_o;
+ (void)_resolver;
+ { auto _e = vec(); if (_e) _o->vec = std::unique_ptr(new TEN::Save::Vector3(*_e)); }
+}
+
+inline flatbuffers::Offset vec3Table::Pack(flatbuffers::FlatBufferBuilder &_fbb, const vec3TableT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
+ return Createvec3Table(_fbb, _o, _rehasher);
+}
+
+inline flatbuffers::Offset Createvec3Table(flatbuffers::FlatBufferBuilder &_fbb, const vec3TableT *_o, const flatbuffers::rehasher_function_t *_rehasher) {
+ (void)_rehasher;
+ (void)_o;
+ struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const vec3TableT* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
+ auto _vec = _o->vec ? _o->vec.get() : 0;
+ return TEN::Save::Createvec3Table(
+ _fbb,
+ _vec);
+}
+
inline UnionTableT *UnionTable::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
auto _o = std::make_unique();
UnPackTo(_o.get(), _resolver);
@@ -8262,6 +8372,10 @@ inline bool VerifyVarUnion(flatbuffers::Verifier &verifier, const void *obj, Var
auto ptr = reinterpret_cast(obj);
return verifier.VerifyTable(ptr);
}
+ case VarUnion::vec3: {
+ auto ptr = reinterpret_cast(obj);
+ return verifier.VerifyTable(ptr);
+ }
default: return true;
}
}
@@ -8296,6 +8410,10 @@ inline void *VarUnionUnion::UnPack(const void *obj, VarUnion type, const flatbuf
auto ptr = reinterpret_cast(obj);
return ptr->UnPack(resolver);
}
+ case VarUnion::vec3: {
+ auto ptr = reinterpret_cast(obj);
+ return ptr->UnPack(resolver);
+ }
default: return nullptr;
}
}
@@ -8318,6 +8436,10 @@ inline flatbuffers::Offset VarUnionUnion::Pack(flatbuffers::FlatBufferBuil
auto ptr = reinterpret_cast(value);
return CreateboolTable(_fbb, ptr, _rehasher).Union();
}
+ case VarUnion::vec3: {
+ auto ptr = reinterpret_cast(value);
+ return Createvec3Table(_fbb, ptr, _rehasher).Union();
+ }
default: return 0;
}
}
@@ -8340,6 +8462,10 @@ inline VarUnionUnion::VarUnionUnion(const VarUnionUnion &u) : type(u.type), valu
value = new TEN::Save::boolTableT(*reinterpret_cast(u.value));
break;
}
+ case VarUnion::vec3: {
+ FLATBUFFERS_ASSERT(false); // TEN::Save::vec3TableT not copyable.
+ break;
+ }
default:
break;
}
@@ -8367,6 +8493,11 @@ inline void VarUnionUnion::Reset() {
delete ptr;
break;
}
+ case VarUnion::vec3: {
+ auto ptr = reinterpret_cast(value);
+ delete ptr;
+ break;
+ }
default: break;
}
value = nullptr;
diff --git a/TombEngine/Specific/savegame/schema/ten_savegame.fbs b/TombEngine/Specific/savegame/schema/ten_savegame.fbs
index f5f467269..90e21696b 100644
--- a/TombEngine/Specific/savegame/schema/ten_savegame.fbs
+++ b/TombEngine/Specific/savegame/schema/ten_savegame.fbs
@@ -385,11 +385,16 @@ table boolTable {
scalar: bool;
}
+table vec3Table {
+ vec: Vector3;
+}
+
union VarUnion {
str: stringTable,
tab: ScriptTable,
num: doubleTable,
- boolean: boolTable
+ boolean: boolTable,
+ vec3: vec3Table
}
table UnionTable{
From fe8b5d0025c161e0f77edc2b2cab9ddde71bfc7b Mon Sep 17 00:00:00 2001
From: hispidence
Date: Sat, 20 Aug 2022 17:05:25 +0100
Subject: [PATCH 016/106] Timer and EventSequence no longer require you to call
Timer.UpdateAll
---
.../5 lua utility modules/EventSequence.html | 8 ++---
.../doc/5 lua utility modules/Timer.html | 33 ++-----------------
Scripts/EventSequence.lua | 8 ++---
Scripts/Timer.lua | 23 +++++++------
4 files changed, 22 insertions(+), 50 deletions(-)
diff --git a/Documentation/doc/5 lua utility modules/EventSequence.html b/Documentation/doc/5 lua utility modules/EventSequence.html
index 4433f4d59..456664b91 100644
--- a/Documentation/doc/5 lua utility modules/EventSequence.html
+++ b/Documentation/doc/5 lua utility modules/EventSequence.html
@@ -90,6 +90,9 @@
Event sequence - a chain of functions to call at specified times, modeled after TRNG's organizers.
+
+
Works atop the Timer, and so is updated automatically pre-OnControlPhase, and saved automatically when the game is saved.
+
Example usage:
@@ -126,11 +129,6 @@ LevelFuncs.SpawnBaddy = function (baddy, name, pos)
mySeq:Start()
end
-
-LevelFuncs.OnControlPhase = function (dt)
- Timer.UpdateAll(dt)
-end
diff --git a/Documentation/doc/5 lua utility modules/Timer.html b/Documentation/doc/5 lua utility modules/Timer.html
index f9956d80e..493b98dee 100644
--- a/Documentation/doc/5 lua utility modules/Timer.html
+++ b/Documentation/doc/5 lua utility modules/Timer.html
@@ -90,6 +90,9 @@
Basic timer - after a specified number of seconds, the specified thing happens.
+
+
Timers are updated automatically every frame before OnControlPhase.
+
Example usage:
@@ -112,10 +115,6 @@
"Well done!" )
myTimer:Start()
end
-
-LevelFuncs.OnControlPhase = function (dt)
- Timer.UpdateAll(dt)
-end
@@ -132,10 +131,6 @@ LevelFuncs.OnControlPhase = function (dt)
Get a timer by its name.
- UpdateAll(dt)
- Update all active timers.
-
-
myTimer:SetFunction(func[, ...])
Give the timer a new function and args
@@ -280,28 +275,6 @@ local myTimeFormat4 = {seconds = true}
-
-
-
- UpdateAll(dt)
-
-
- Update all active timers.
- Should be called in LevelFuncs.OnControlPhase
-
-
- Parameters:
-
- dt
- number
- The time in seconds since the last frame
-
-
-
-
-
-
-
diff --git a/Scripts/EventSequence.lua b/Scripts/EventSequence.lua
index 6fde9d7bc..8e99b9257 100644
--- a/Scripts/EventSequence.lua
+++ b/Scripts/EventSequence.lua
@@ -1,5 +1,8 @@
-----
--- Event sequence - a chain of functions to call at specified times, modeled after TRNG's organizers.
+--
+-- Works atop the Timer, and so is updated automatically pre-OnControlPhase, and saved automatically when the game is saved.
+--
-- Example usage:
-- local EventSequence = require("EventSequence")
--
@@ -35,11 +38,6 @@
-- mySeq:Start()
-- end
--
--- -- EventSequence runs on Timer, so this call is required
--- LevelFuncs.OnControlPhase = function(dt)
--- Timer.UpdateAll(dt)
--- end
---
-- @luautil EventSequence
local Timer = require("Timer")
diff --git a/Scripts/Timer.lua b/Scripts/Timer.lua
index 66567506e..99eb821cf 100644
--- a/Scripts/Timer.lua
+++ b/Scripts/Timer.lua
@@ -1,5 +1,8 @@
-----
--- Basic timer - after a specified number of seconds, the specified thing happens.
+--
+-- Timers are updated automatically every frame before OnControlPhase.
+--
-- Example usage:
-- local Timer = require("Timer")
--
@@ -21,10 +24,6 @@
-- myTimer:Start()
-- end
--
--- LevelFuncs.OnControlPhase = function(dt)
--- Timer.UpdateAll(dt)
--- end
---
-- @luautil Timer
LevelVars.__TEN_timer = {timers = {}}
@@ -35,6 +34,7 @@ local unpausedColor = TEN.Color(255, 255, 255)
local pausedColor = TEN.Color(255, 255, 0)
local str = TEN.Strings.DisplayString("TIMER", 0, 0, unpausedColor, false, {TEN.Strings.DisplayStringOption.CENTER, TEN.Strings.DisplayStringOption.SHADOW} )
+
Timer = {
--- Create (but do not start) a new timer.
--
@@ -190,13 +190,8 @@ Timer = {
end
end;
- --- Update all active timers.
- -- Should be called in LevelFuncs.OnControlPhase
- -- @number dt The time in seconds since the last frame
UpdateAll = function(dt)
- for _, t in pairs(LevelVars.__TEN_timer.timers) do
- Timer.Update(t, dt)
- end
+ print("Timer.UpdateAll is deprecated; timers and event sequences now get updated automatically pre-control phase.")
end;
--- Give the timer a new function and args
@@ -296,5 +291,13 @@ Timer = {
end;
}
+LevelFuncs.__TEN_timer_updateAll = function(dt)
+ for _, t in pairs(LevelVars.__TEN_timer.timers) do
+ Timer.Update(t, dt)
+ end
+end
+
+TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.PRECONTROLPHASE, "__TEN_timer_updateAll")
+
return Timer
From 412b6d2de8be285c29a90cd74aae415fa531f646 Mon Sep 17 00:00:00 2001
From: Sezz
Date: Sun, 21 Aug 2022 13:42:55 +1000
Subject: [PATCH 017/106] Demagic some entity TouchBits
---
TombEngine/Objects/TR2/Entity/tr2_dragon.cpp | 49 ++++++--------------
TombEngine/Objects/TR2/Entity/tr2_yeti.cpp | 24 ++++++----
2 files changed, 29 insertions(+), 44 deletions(-)
diff --git a/TombEngine/Objects/TR2/Entity/tr2_dragon.cpp b/TombEngine/Objects/TR2/Entity/tr2_dragon.cpp
index 8bb783680..d8234d996 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_dragon.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_dragon.cpp
@@ -18,28 +18,23 @@
#include "Specific/setup.h"
using namespace TEN::Input;
+using std::vector;
namespace TEN::Entities::TR2
{
- const auto DragonMouthBite = BiteInfo(Vector3(35.0f, 171.0f, 1168.0f), 12);
-
constexpr auto DRAGON_SWIPE_ATTACK_DAMAGE = 250;
- constexpr auto DRAGON_TOUCH_DAMAGE = 10;
-
+ constexpr auto DRAGON_CONTACT_DAMAGE = 10;
+ const auto DragonMouthBite = BiteInfo(Vector3(35.0f, 171.0f, 1168.0f), 12);
+ const vector DragonSwipeAttackJointsLeft = { 24, 25, 26, 27, 28, 29, 30 };
+ const vector DragonSwipeAttackJointsRight = { 1, 2, 3, 4, 5, 6, 7 };
// TODO: Organise.
- #define DRAGON_SWIPE_DAMAGE 250
- #define DRAGON_TOUCH_DAMAGE 10
-
#define DRAGON_LIVE_TIME (30 * 11)
#define DRAGON_CLOSE_RANGE pow(SECTOR(3), 2)
#define DRAGON_STATE_IDLE_RANGE pow(SECTOR(6), 2)
#define DRAGON_FLAME_SPEED 200
- #define DRAGON_TOUCH_R 0x0fe
- #define DRAGON_TOUCH_L 0x7f000000
-
#define DRAGON_ALMOST_LIVE 100
#define BOOM_TIME 130
#define BOOM_TIME_MIDDLE 140
@@ -255,8 +250,8 @@ namespace TEN::Entities::TR2
auto* item = &g_Level.Items[itemNumber];
auto* creature = GetCreatureInfo(item);
- short head = 0;
short angle = 0;
+ short head = 0;
bool ahead;
@@ -318,9 +313,7 @@ namespace TEN::Entities::TR2
ahead = (AI.ahead && AI.distance > DRAGON_CLOSE_RANGE && AI.distance < DRAGON_STATE_IDLE_RANGE);
if (item->TouchBits)
- {
- DoDamage(creature->Enemy, DRAGON_TOUCH_DAMAGE);
- }
+ DoDamage(creature->Enemy, DRAGON_CONTACT_DAMAGE);
switch (item->Animation.ActiveState)
{
@@ -350,19 +343,19 @@ namespace TEN::Entities::TR2
break;
case DRAGON_STATE_SWIPE_LEFT:
- if (item->TouchBits & DRAGON_TOUCH_L)
+ if (item->TestBits(JointBitType::Touch, DragonSwipeAttackJointsLeft))
{
+ DoDamage(creature->Enemy, DRAGON_SWIPE_ATTACK_DAMAGE);
creature->Flags = 0;
- DoDamage(creature->Enemy, DRAGON_SWIPE_DAMAGE);
}
break;
case DRAGON_STATE_SWIPE_RIGHT:
- if (item->TouchBits & DRAGON_TOUCH_R)
+ if (item->TestBits(JointBitType::Touch, DragonSwipeAttackJointsRight))
{
+ DoDamage(creature->Enemy, DRAGON_SWIPE_ATTACK_DAMAGE);
creature->Flags = 0;
- DoDamage(creature->Enemy, DRAGON_SWIPE_DAMAGE);
}
break;
@@ -404,13 +397,11 @@ namespace TEN::Entities::TR2
case DRAGON_STATE_TURN_LEFT:
item->Pose.Orientation.y += -(ANGLE(1.0f) - angle);
creature->Flags = 0;
-
break;
case DRAGON_STATE_TURN_RIGHT:
item->Pose.Orientation.y += (ANGLE(1.0f) - angle);
creature->Flags = 0;
-
break;
case DRAGON_STATE_AIM_1:
@@ -434,12 +425,11 @@ namespace TEN::Entities::TR2
case DRAGON_STATE_FIRE_1:
item->Pose.Orientation.y -= angle;
+ SoundEffect(SFX_TR2_DRAGON_FIRE, &item->Pose);
if (AI.ahead)
head = -AI.angle;
- SoundEffect(SFX_TR2_DRAGON_FIRE, &item->Pose);
-
if (creature->Flags)
{
if (AI.ahead)
@@ -459,12 +449,7 @@ namespace TEN::Entities::TR2
back->Animation.ActiveState = item->Animation.ActiveState;
back->Animation.AnimNumber = Objects[ID_DRAGON_BACK].animIndex + (item->Animation.AnimNumber - Objects[ID_DRAGON_FRONT].animIndex);
back->Animation.FrameNumber = g_Level.Anims[back->Animation.AnimNumber].frameBase + (item->Animation.FrameNumber - g_Level.Anims[item->Animation.AnimNumber].frameBase);
- back->Pose.Position.x = item->Pose.Position.x;
- back->Pose.Position.y = item->Pose.Position.y;
- back->Pose.Position.z = item->Pose.Position.z;
- back->Pose.Orientation.x = item->Pose.Orientation.x;
- back->Pose.Orientation.y = item->Pose.Orientation.y;
- back->Pose.Orientation.z = item->Pose.Orientation.z;
+ back->Pose = item->Pose;
if (back->RoomNumber != item->RoomNumber)
ItemNewRoom(backItemNumber, item->RoomNumber);
@@ -484,9 +469,7 @@ namespace TEN::Entities::TR2
{
auto* back = &g_Level.Items[backItem];
back->ObjectNumber = ID_DRAGON_BACK;
- back->Pose.Position.x = item->Pose.Position.x;
- back->Pose.Position.y = item->Pose.Position.y;
- back->Pose.Position.z = item->Pose.Position.z;
+ back->Pose.Position = item->Pose.Position;
back->Pose.Orientation.y = item->Pose.Orientation.y;
back->RoomNumber = item->RoomNumber;
back->Status = ITEM_INVISIBLE;
@@ -500,9 +483,7 @@ namespace TEN::Entities::TR2
auto* front = &g_Level.Items[frontItem];
front->ObjectNumber = ID_DRAGON_FRONT;
- front->Pose.Position.x = item->Pose.Position.x;
- front->Pose.Position.y = item->Pose.Position.y;
- front->Pose.Position.z = item->Pose.Position.z;
+ front->Pose.Position = item->Pose.Position;
front->Pose.Orientation.y = item->Pose.Orientation.y;
front->RoomNumber = item->RoomNumber;
front->Status = ITEM_INVISIBLE;
diff --git a/TombEngine/Objects/TR2/Entity/tr2_yeti.cpp b/TombEngine/Objects/TR2/Entity/tr2_yeti.cpp
index 0a80c62bb..173ba1dd8 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_yeti.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_yeti.cpp
@@ -13,11 +13,14 @@
#include "Specific/setup.h"
using namespace TEN::Math::Random;
+using std::vector;
namespace TEN::Entities::TR2
{
- const auto YetiBiteLeft = BiteInfo(Vector3(12.0f, 101.0f, 19.0f), 13);
+ const auto YetiBiteLeft = BiteInfo(Vector3(12.0f, 101.0f, 19.0f), 13);
const auto YetiBiteRight = BiteInfo(Vector3(12.0f, 101.0f, 19.0f), 10);
+ const vector YetiAttackJoints1 = { 10, 12 }; // TODO: Rename.
+ const vector YetiAttackJoints2 = { 8, 9, 10 };
// TODO
enum YetiState
@@ -50,9 +53,9 @@ namespace TEN::Entities::TR2
bool isLaraAlive = LaraItem->HitPoints > 0;
short angle = 0;
+ short tilt = 0;
short torso = 0;
short head = 0;
- short tilt = 0;
if (item->HitPoints <= 0)
{
@@ -213,8 +216,7 @@ namespace TEN::Entities::TR2
if (AI.ahead)
torso = AI.angle;
- if (!info->Flags &&
- item->TouchBits & 0x1400)
+ if (!info->Flags && item->TestBits(JointBitType::Touch, YetiAttackJoints1))
{
CreatureEffect(item, YetiBiteRight, DoBloodSplat);
DoDamage(info->Enemy, 100);
@@ -230,11 +232,12 @@ namespace TEN::Entities::TR2
torso = AI.angle;
if (!info->Flags &&
- item->TouchBits & (0x0700 | 0x1400))
+ (item->TestBits(JointBitType::Touch, YetiAttackJoints1) || item->TestBits(JointBitType::Touch, YetiAttackJoints2)))
{
- if (item->TouchBits & 0x0700)
+ if (item->TestBits(JointBitType::Touch, YetiAttackJoints2))
CreatureEffect(item, YetiBiteLeft, DoBloodSplat);
- if (item->TouchBits & 0x1400)
+
+ if (item->TestBits(JointBitType::Touch, YetiAttackJoints1))
CreatureEffect(item, YetiBiteRight, DoBloodSplat);
DoDamage(info->Enemy, 150);
@@ -248,11 +251,12 @@ namespace TEN::Entities::TR2
torso = AI.angle;
if (!info->Flags &&
- item->TouchBits & (0x0700 | 0x1400))
+ (item->TestBits(JointBitType::Touch, YetiAttackJoints1) || item->TestBits(JointBitType::Touch, YetiAttackJoints2)))
{
- if (item->TouchBits & 0x0700)
+ if (item->TestBits(JointBitType::Touch, YetiAttackJoints2))
CreatureEffect(item, YetiBiteLeft, DoBloodSplat);
- if (item->TouchBits & 0x1400)
+
+ if (item->TestBits(JointBitType::Touch, YetiAttackJoints1))
CreatureEffect(item, YetiBiteRight, DoBloodSplat);
DoDamage(info->Enemy, 200);
From 21865430af6544406cd44b3ffbf90deb455c3980 Mon Sep 17 00:00:00 2001
From: Sezz
Date: Sun, 21 Aug 2022 14:58:30 +1000
Subject: [PATCH 018/106] Cleanup
---
TombEngine/Game/control/box.cpp | 2 +-
.../Objects/TR5/Entity/tr5_doberman.cpp | 340 +++++++++---------
.../Objects/TR5/Entity/tr5_lagoon_witch.cpp | 31 +-
TombEngine/Objects/TR5/Entity/tr5_larson.cpp | 61 ++--
TombEngine/Objects/TR5/Entity/tr5_lion.cpp | 4 +-
.../Objects/TR5/Entity/tr5_submarine.cpp | 194 +++++-----
.../Objects/TR5/Entity/tr5_willowwisp.cpp | 5 +-
7 files changed, 312 insertions(+), 325 deletions(-)
diff --git a/TombEngine/Game/control/box.cpp b/TombEngine/Game/control/box.cpp
index 5374e914d..8e7e99e0e 100644
--- a/TombEngine/Game/control/box.cpp
+++ b/TombEngine/Game/control/box.cpp
@@ -1084,7 +1084,7 @@ int CreatureActive(short itemNumber)
if (item->Flags & IFLAG_KILLED)
return false; // Object is already dead
- if (item->Status == ITEM_INVISIBLE || !item->Data.is())
+ if (item->Status == ITEM_INVISIBLE || !item->IsCreature())
{
if (!EnableEntityAI(itemNumber, 0))
return false; // AI couldn't be activated
diff --git a/TombEngine/Objects/TR5/Entity/tr5_doberman.cpp b/TombEngine/Objects/TR5/Entity/tr5_doberman.cpp
index 7c386d4bd..eb3e4543a 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_doberman.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_doberman.cpp
@@ -79,198 +79,198 @@ namespace TEN::Entities::TR5
void DobermanControl(short itemNumber)
{
- if (CreatureActive(itemNumber))
+ auto* item = &g_Level.Items[itemNumber];
+ auto* creature = GetCreatureInfo(item);
+
+ if (!CreatureActive(itemNumber))
+ return;
+
+ short angle = 0;
+ short tilt = 0;
+ short joint = 0;
+
+ if (item->HitPoints > 0)
{
- short angle = 0;
- short tilt = 0;
- short joint = 0;
+ AI_INFO AI;
+ CreatureAIInfo(item, &AI);
- auto* item = &g_Level.Items[itemNumber];
- auto* creature = GetCreatureInfo(item);
+ if (AI.ahead)
+ joint = AI.angle;
- if (item->HitPoints > 0)
+ GetCreatureMood(item, &AI, false);
+ CreatureMood(item, &AI, false);
+
+ angle = CreatureTurn(item, creature->MaxTurn);
+
+ switch (item->Animation.ActiveState)
{
- AI_INFO AI;
- CreatureAIInfo(item, &AI);
+ case DOBERMAN_STATE_WALK_FORWARD:
+ creature->MaxTurn = ANGLE(3.0f);
- if (AI.ahead)
- joint = AI.angle;
-
- GetCreatureMood(item, &AI, false);
- CreatureMood(item, &AI, false);
-
- angle = CreatureTurn(item, creature->MaxTurn);
-
- switch (item->Animation.ActiveState)
+ if (creature->Mood != MoodType::Bored)
+ item->Animation.TargetState = DOBERMAN_STATE_RUN_FORWARD;
+ else
{
- case DOBERMAN_STATE_WALK_FORWARD:
- creature->MaxTurn = ANGLE(3.0f);
-
- if (creature->Mood != MoodType::Bored)
- item->Animation.TargetState = DOBERMAN_STATE_RUN_FORWARD;
- else
- {
- if (TestProbability(0.025f))
- {
- item->Animation.RequiredState = DOBERMAN_STATE_STAND_LOW_BITE_ATTACK;
- item->Animation.TargetState = DOBERMAN_STATE_STOP;
- break;
- }
-
- if (TestProbability(0.045f))
- {
- item->Animation.RequiredState = DOBERMAN_STATE_SIT_IDLE;
- item->Animation.TargetState = DOBERMAN_STATE_STOP;
- break;
- }
-
- if (TestProbability(0.085f))
- {
- item->Animation.TargetState = DOBERMAN_STATE_STOP;
- break;
- }
- }
-
- break;
-
- case DOBERMAN_STATE_RUN_FORWARD:
- tilt = angle;
- creature->MaxTurn = ANGLE(6.0f);
-
- if (creature->Mood == MoodType::Bored)
+ if (TestProbability(0.025f))
{
+ item->Animation.RequiredState = DOBERMAN_STATE_STAND_LOW_BITE_ATTACK;
item->Animation.TargetState = DOBERMAN_STATE_STOP;
break;
}
- if (AI.distance < pow(768, 2))
- item->Animation.TargetState = DOBERMAN_STATE_JUMP_BITE_ATTACK;
-
- break;
-
- case DOBERMAN_STATE_STOP:
- creature->MaxTurn = 0;
- creature->Flags = 0;
-
- if (creature->Mood != MoodType::Bored)
+ if (TestProbability(0.045f))
{
- if (creature->Mood != MoodType::Escape &&
- AI.distance < pow(341, 2) &&
- AI.ahead)
- {
- item->Animation.TargetState = DOBERMAN_STATE_STAND_HIGH_BITE_ATTACK;
- }
- else
- item->Animation.TargetState = DOBERMAN_STATE_RUN_FORWARD;
- }
- else
- {
- if (item->Animation.RequiredState)
- item->Animation.TargetState = item->Animation.RequiredState;
- else
- {
- if (TestProbability(0.975f))
- {
- if (TestProbability(0.95f))
- {
- if (TestProbability(0.3f))
- item->Animation.TargetState = DOBERMAN_STATE_WALK_FORWARD;
- }
- else
- item->Animation.TargetState = DOBERMAN_STATE_SIT_IDLE;
- }
- else
- item->Animation.TargetState = DOBERMAN_STATE_STAND_LOW_BITE_ATTACK;
- }
- }
-
- break;
-
- case DOBERMAN_STATE_STAND_LOW_BITE_ATTACK:
- if (creature->Mood != MoodType::Bored || TestProbability(0.04f))
+ item->Animation.RequiredState = DOBERMAN_STATE_SIT_IDLE;
item->Animation.TargetState = DOBERMAN_STATE_STOP;
+ break;
+ }
- break;
-
- case DOBERMAN_STATE_SIT_IDLE:
- if (creature->Mood != MoodType::Bored || TestProbability(0.008f))
+ if (TestProbability(0.085f))
+ {
item->Animation.TargetState = DOBERMAN_STATE_STOP;
-
- break;
-
- case DOBERMAN_STATE_STAND_IDLE:
- if (creature->Mood != MoodType::Bored || TestProbability(0.015f))
- item->Animation.TargetState = DOBERMAN_STATE_STOP;
-
- break;
-
- case DOBERMAN_STATE_STAND_HIGH_BITE_ATTACK:
- creature->MaxTurn = ANGLE(0.5f);
-
- if (creature->Flags != 1 && AI.ahead &&
- item->TouchBits & 0x122000)
- {
- DoDamage(creature->Enemy, 30);
- CreatureEffect(item, DobermanBite, DoBloodSplat);
- creature->Flags = 1;
+ break;
}
+ }
- if (AI.distance <= pow(341, 2) || AI.distance >= pow(682, 2))
- item->Animation.TargetState = DOBERMAN_STATE_STOP;
- else
- item->Animation.TargetState = DOBERMAN_STATE_LEAP_BITE_ATTACK;
+ break;
- break;
+ case DOBERMAN_STATE_RUN_FORWARD:
+ creature->MaxTurn = ANGLE(6.0f);
+ tilt = angle;
- case DOBERMAN_STATE_JUMP_BITE_ATTACK:
- if (creature->Flags != 2 && item->TouchBits & 0x122000)
- {
- DoDamage(creature->Enemy, 80);
- CreatureEffect(item, DobermanBite, DoBloodSplat);
- creature->Flags = 2;
- }
-
- if (AI.distance >= pow(341, 2))
- {
- if (AI.distance < pow(682, 2))
- item->Animation.TargetState = DOBERMAN_STATE_LEAP_BITE_ATTACK;
- }
- else
- item->Animation.TargetState = DOBERMAN_STATE_STAND_HIGH_BITE_ATTACK;
-
- break;
-
- case DOBERMAN_STATE_LEAP_BITE_ATTACK:
- creature->MaxTurn = ANGLE(6.0f);
-
- if (creature->Flags != 3 && item->TouchBits & 0x122000)
- {
- DoDamage(creature->Enemy, 50);
- CreatureEffect(item, DobermanBite, DoBloodSplat);
- creature->Flags = 3;
- }
-
- if (AI.distance < pow(341, 2))
- item->Animation.TargetState = DOBERMAN_STATE_STAND_HIGH_BITE_ATTACK;
-
- break;
-
- default:
+ if (creature->Mood == MoodType::Bored)
+ {
+ item->Animation.TargetState = DOBERMAN_STATE_STOP;
break;
}
- }
- else if (item->Animation.ActiveState != DOBERMAN_STATE_DEATH)
- {
- item->Animation.AnimNumber = Objects[ID_DOBERMAN].animIndex + DOBERMAN_ANIM_DEATH;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = DOBERMAN_STATE_DEATH;
- }
- CreatureTilt(item, tilt);
- CreatureJoint(item, 0, 0);
- CreatureJoint(item, 1, joint);
- CreatureJoint(item, 2, 0);
- CreatureAnimation(itemNumber, angle, tilt);
+ if (AI.distance < pow(768, 2))
+ item->Animation.TargetState = DOBERMAN_STATE_JUMP_BITE_ATTACK;
+
+ break;
+
+ case DOBERMAN_STATE_STOP:
+ creature->MaxTurn = 0;
+ creature->Flags = 0;
+
+ if (creature->Mood != MoodType::Bored)
+ {
+ if (creature->Mood != MoodType::Escape &&
+ AI.distance < pow(341, 2) &&
+ AI.ahead)
+ {
+ item->Animation.TargetState = DOBERMAN_STATE_STAND_HIGH_BITE_ATTACK;
+ }
+ else
+ item->Animation.TargetState = DOBERMAN_STATE_RUN_FORWARD;
+ }
+ else
+ {
+ if (item->Animation.RequiredState)
+ item->Animation.TargetState = item->Animation.RequiredState;
+ else
+ {
+ if (TestProbability(0.975f))
+ {
+ if (TestProbability(0.95f))
+ {
+ if (TestProbability(0.3f))
+ item->Animation.TargetState = DOBERMAN_STATE_WALK_FORWARD;
+ }
+ else
+ item->Animation.TargetState = DOBERMAN_STATE_SIT_IDLE;
+ }
+ else
+ item->Animation.TargetState = DOBERMAN_STATE_STAND_LOW_BITE_ATTACK;
+ }
+ }
+
+ break;
+
+ case DOBERMAN_STATE_STAND_LOW_BITE_ATTACK:
+ if (creature->Mood != MoodType::Bored || TestProbability(0.04f))
+ item->Animation.TargetState = DOBERMAN_STATE_STOP;
+
+ break;
+
+ case DOBERMAN_STATE_SIT_IDLE:
+ if (creature->Mood != MoodType::Bored || TestProbability(0.008f))
+ item->Animation.TargetState = DOBERMAN_STATE_STOP;
+
+ break;
+
+ case DOBERMAN_STATE_STAND_IDLE:
+ if (creature->Mood != MoodType::Bored || TestProbability(0.015f))
+ item->Animation.TargetState = DOBERMAN_STATE_STOP;
+
+ break;
+
+ case DOBERMAN_STATE_STAND_HIGH_BITE_ATTACK:
+ creature->MaxTurn = ANGLE(0.5f);
+
+ if (creature->Flags != 1 && AI.ahead &&
+ item->TouchBits & 0x122000)
+ {
+ DoDamage(creature->Enemy, 30);
+ CreatureEffect(item, DobermanBite, DoBloodSplat);
+ creature->Flags = 1;
+ }
+
+ if (AI.distance <= pow(341, 2) || AI.distance >= pow(682, 2))
+ item->Animation.TargetState = DOBERMAN_STATE_STOP;
+ else
+ item->Animation.TargetState = DOBERMAN_STATE_LEAP_BITE_ATTACK;
+
+ break;
+
+ case DOBERMAN_STATE_JUMP_BITE_ATTACK:
+ if (creature->Flags != 2 && item->TouchBits & 0x122000)
+ {
+ DoDamage(creature->Enemy, 80);
+ CreatureEffect(item, DobermanBite, DoBloodSplat);
+ creature->Flags = 2;
+ }
+
+ if (AI.distance >= pow(341, 2))
+ {
+ if (AI.distance < pow(682, 2))
+ item->Animation.TargetState = DOBERMAN_STATE_LEAP_BITE_ATTACK;
+ }
+ else
+ item->Animation.TargetState = DOBERMAN_STATE_STAND_HIGH_BITE_ATTACK;
+
+ break;
+
+ case DOBERMAN_STATE_LEAP_BITE_ATTACK:
+ creature->MaxTurn = ANGLE(6.0f);
+
+ if (creature->Flags != 3 && item->TouchBits & 0x122000)
+ {
+ DoDamage(creature->Enemy, 50);
+ CreatureEffect(item, DobermanBite, DoBloodSplat);
+ creature->Flags = 3;
+ }
+
+ if (AI.distance < pow(341, 2))
+ item->Animation.TargetState = DOBERMAN_STATE_STAND_HIGH_BITE_ATTACK;
+
+ break;
+
+ default:
+ break;
+ }
}
+ else if (item->Animation.ActiveState != DOBERMAN_STATE_DEATH)
+ {
+ item->Animation.AnimNumber = Objects[ID_DOBERMAN].animIndex + DOBERMAN_ANIM_DEATH;
+ item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
+ item->Animation.ActiveState = DOBERMAN_STATE_DEATH;
+ }
+
+ CreatureTilt(item, tilt);
+ CreatureJoint(item, 0, 0);
+ CreatureJoint(item, 1, joint);
+ CreatureJoint(item, 2, 0);
+ CreatureAnimation(itemNumber, angle, tilt);
}
}
diff --git a/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.cpp b/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.cpp
index 149d45168..170b4f6b8 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.cpp
@@ -1,20 +1,25 @@
#include "framework.h"
-#include "tr5_lagoon_witch.h"
+#include "Objects/TR5/Entity/tr5_lagoon_witch.h"
-#include "Game/items.h"
#include "Game/control/box.h"
#include "Game/effects/effects.h"
#include "Game/effects/tomb4fx.h"
#include "Game/gui.h"
-#include "Specific/setup.h"
-#include "Specific/level.h"
-#include "Game/Lara/lara.h"
#include "Game/itemdata/creature_info.h"
+#include "Game/items.h"
+#include "Game/Lara/lara.h"
#include "Game/misc.h"
+#include "Specific/level.h"
+#include "Specific/setup.h"
+
+using std::vector;
namespace TEN::Entities::TR5
{
+ constexpr auto LAGOON_WITCH_ATTACK_DAMAGE = 100;
+
const auto LagoonWitchBite = BiteInfo(Vector3::Zero, 7);
+ const vector LagoonWitchAttackJoints = { 6, 7, 8, 9, 14, 15, 16, 17 };
enum LagoonWitchState
{
@@ -35,11 +40,7 @@ namespace TEN::Entities::TR5
auto* item = &g_Level.Items[itemNumber];
ClearItem(itemNumber);
-
- item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex + 1;
- item->Animation.TargetState = WITCH_STATE_IDLE;
- item->Animation.ActiveState = WITCH_STATE_IDLE;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
+ SetAnimation(item, 1);
item->Pose.Position.y += CLICK(2);
}
@@ -54,17 +55,17 @@ namespace TEN::Entities::TR5
short joint2 = 0;
auto* item = &g_Level.Items[itemNumber];
- auto* creature = GetCreatureInfo(item);
auto* object = &Objects[item->ObjectNumber];
+ auto* creature = GetCreatureInfo(item);
if (item->HitPoints <= 0)
{
if (item->Animation.ActiveState != WITCH_STATE_DEATH)
{
- item->HitPoints = 0;
item->Animation.ActiveState = WITCH_STATE_DEATH;
item->Animation.AnimNumber = object->animIndex + WITCH_ANIM_DEATH;
item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
+ item->HitPoints = 0;
}
}
else
@@ -127,10 +128,10 @@ namespace TEN::Entities::TR5
creature->MaxTurn = ANGLE(2.0f);
if (!creature->Flags &&
- item->TouchBits & 0x3C3C0 &&
+ item->TestBits(JointBitType::Touch, LagoonWitchAttackJoints) &&
item->Animation.FrameNumber > g_Level.Anims[item->Animation.AnimNumber].frameBase + 29)
{
- DoDamage(creature->Enemy, 100);
+ DoDamage(creature->Enemy, LAGOON_WITCH_ATTACK_DAMAGE);
CreatureEffect2(item, LagoonWitchBite, 10, item->Pose.Orientation.y, DoBloodSplat);
creature->Flags = WITCH_STATE_SWIM;
}
@@ -149,7 +150,7 @@ namespace TEN::Entities::TR5
item->ItemFlags[3]++;
creature->ReachedGoal = false;
- creature->Enemy = 0;
+ creature->Enemy = nullptr;
}
}
}
diff --git a/TombEngine/Objects/TR5/Entity/tr5_larson.cpp b/TombEngine/Objects/TR5/Entity/tr5_larson.cpp
index 99147a8c1..48d874e13 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_larson.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_larson.cpp
@@ -35,15 +35,12 @@ namespace TEN::Entities::TR5
const auto PierreGun1 = BiteInfo(Vector3(60.0f, 200.0f, 0.0f), 11);
const auto PierreGun2 = BiteInfo(Vector3(-57.0f, 200.0f, 0.0f), 14);
- void InitialiseLarson(short itemNum)
+ void InitialiseLarson(short itemNumber)
{
- auto* item = &g_Level.Items[itemNum];
+ auto* item = &g_Level.Items[itemNumber];
- ClearItem(itemNum);
- item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.TargetState = STATE_TR5_LARSON_STOP;
- item->Animation.ActiveState = STATE_TR5_LARSON_STOP;
+ ClearItem(itemNumber);
+ SetAnimation(item, 0);
if (!item->TriggerFlags)
return;
@@ -66,23 +63,23 @@ namespace TEN::Entities::TR5
if (!CreatureActive(itemNumber))
return;
- short tilt = 0;
+ auto* item = &g_Level.Items[itemNumber];
+ auto* creature = GetCreatureInfo(item);
+
short angle = 0;
+ short tilt = 0;
short joint0 = 0;
short joint1 = 0;
short joint2 = 0;
- auto* item = &g_Level.Items[itemNumber];
- auto* creature = GetCreatureInfo(item);
-
- // In Streets of Rome when Larson HP are below 40 he runs way
+ // TODO: When Larson's HP is below 40, he runs away in Streets of Rome. Keeping block commented for reference.
/*if (item->HitPoints <= TR5_LARSON_MIN_HP && !(item->flags & IFLAG_INVISIBLE))
{
item->HitPoints = TR5_LARSON_MIN_HP;
creature->flags++;
}*/
- // Fire weapon effects
+ // Fire weapon effects.
if (creature->FiredWeapon)
{
auto pos = Vector3Int(LarsonGun.Position);
@@ -96,18 +93,18 @@ namespace TEN::Entities::TR5
{
if (CurrentLevel == 2)
{
- item->ItemFlags[3] = 1;
item->Animation.IsAirborne = false;
- item->HitStatus = false;
- item->Collidable = false;
item->Status = ITEM_DEACTIVATED;
+ item->Collidable = false;
+ item->HitStatus = false;
+ item->ItemFlags[3] = 1;
}
else
{
item->Animation.IsAirborne = false;
- item->HitStatus = false;
- item->Collidable = false;
item->Status = ITEM_ACTIVE;
+ item->Collidable = false;
+ item->HitStatus = false;
}
item->TriggerFlags = 0;
@@ -126,15 +123,15 @@ namespace TEN::Entities::TR5
if (AI.ahead)
joint2 = AI.angle;
- // FIXME: this should make Larson running away, but it's broken
+ // FIXME: This should make Larson run away, but it doesn't work.
/*if (creature->flags)
{
item->HitPoints = 60;
item->IsAirborne = false;
- item->hitStatus = false;
- item->collidable = false;
- item->status = ITEM_DESACTIVATED;
- creature->flags = 0;
+ item->HitStatus = false;
+ item->Collidable = false;
+ item->Status = ITEM_DESACTIVATED;
+ creature->Flags = 0;
}*/
GetCreatureMood(item, &AI, true);
@@ -231,8 +228,8 @@ namespace TEN::Entities::TR5
break;
case STATE_TR5_LARSON_RUN:
- tilt = angle / 2;
creature->MaxTurn = ANGLE(11.0f);
+ tilt = angle / 2;
if (AI.ahead)
joint2 = AI.angle;
@@ -259,16 +256,16 @@ namespace TEN::Entities::TR5
}
else
{
- item->Animation.RequiredState = STATE_TR5_LARSON_IDLE;
item->Animation.TargetState = STATE_TR5_LARSON_STOP;
+ item->Animation.RequiredState = STATE_TR5_LARSON_IDLE;
}
break;
case STATE_TR5_LARSON_AIM:
+ creature->MaxTurn = 0;
joint0 = AI.angle / 2;
joint2 = AI.angle / 2;
- creature->MaxTurn = 0;
if (AI.ahead)
joint1 = AI.xAngle;
@@ -311,9 +308,9 @@ namespace TEN::Entities::TR5
break;
case STATE_TR5_LARSON_ATTACK:
+ creature->MaxTurn = 0;
joint0 = AI.angle / 2;
joint2 = AI.angle / 2;
- creature->MaxTurn = 0;
if (AI.ahead)
joint1 = AI.xAngle;
@@ -394,12 +391,12 @@ namespace TEN::Entities::TR5
{
item->TargetState = STATE_TR5_LARSON_STOP;
item->RequiredState = STATE_TR5_LARSON_STOP;
- creature->reachedGoal = false;
+ creature->ReachedGoal = false;
item->IsAirborne = false;
- item->hitStatus = false;
- item->collidable = false;
- item->status = ITEM_NOT_ACTIVE;
- item->triggerFlags = 0;
+ item->HitStatus = false;
+ item->Collidable = false;
+ item->Status = ITEM_NOT_ACTIVE;
+ item->TriggerFlags = 0;
}
else
{
diff --git a/TombEngine/Objects/TR5/Entity/tr5_lion.cpp b/TombEngine/Objects/TR5/Entity/tr5_lion.cpp
index a5443ddfd..72c780d24 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_lion.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_lion.cpp
@@ -181,9 +181,9 @@ namespace TEN::Entities::TR5
if (!item->Animation.RequiredState &&
item->TestBits(JointBitType::Touch, LionAttackJoints))
{
- item->Animation.RequiredState = LION_STATE_IDLE;
DoDamage(creature->Enemy, LION_POUNCE_ATTACK_DAMAGE);
CreatureEffect2(item, LionBite1, 10, item->Pose.Orientation.y, DoBloodSplat);
+ item->Animation.RequiredState = LION_STATE_IDLE;
}
break;
@@ -194,9 +194,9 @@ namespace TEN::Entities::TR5
if (!item->Animation.RequiredState &&
item->TestBits(JointBitType::Touch, LionAttackJoints))
{
- item->Animation.RequiredState = LION_STATE_IDLE;
DoDamage(creature->Enemy, LION_BITE_ATTACK_DAMAGE);
CreatureEffect2(item, LionBite2, 10, item->Pose.Orientation.y, DoBloodSplat);
+ item->Animation.RequiredState = LION_STATE_IDLE;
}
break;
diff --git a/TombEngine/Objects/TR5/Entity/tr5_submarine.cpp b/TombEngine/Objects/TR5/Entity/tr5_submarine.cpp
index 208386092..4581b2184 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_submarine.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_submarine.cpp
@@ -1,24 +1,26 @@
#include "framework.h"
-#include "tr5_submarine.h"
-#include "Game/items.h"
-#include "Game/control/box.h"
-#include "Game/people.h"
+#include "Objects/TR5/Entity/tr5_submarine.h"
+
+#include "Game/animation.h"
#include "Game/collision/collide_item.h"
#include "Game/collision/collide_room.h"
+#include "Game/control/box.h"
#include "Game/control/los.h"
#include "Game/effects/effects.h"
#include "Game/effects/tomb4fx.h"
#include "Game/itemdata/creature_info.h"
-#include "Game/animation.h"
+#include "Game/items.h"
#include "Game/Lara/lara.h"
#include "Game/Lara/lara_one_gun.h"
-#include "Specific/setup.h"
-#include "Specific/level.h"
+#include "Game/misc.h"
+#include "Game/people.h"
#include "Sound/sound.h"
+#include "Specific/level.h"
+#include "Specific/setup.h"
namespace TEN::Entities::TR5
{
- static void TriggerSubmarineSparks(short itemNumber)
+ void TriggerSubmarineSparks(short itemNumber)
{
auto* spark = GetFreeParticle();
@@ -50,7 +52,7 @@ namespace TEN::Entities::TR5
spark->dSize = spark->sSize = spark->size = (GetRandomControl() & 7) + 192;
}
- static void TriggerTorpedoBubbles(Vector3Int* pos1, Vector3Int* pos2, char factor)
+ void TriggerTorpedoBubbles(Vector3Int* pos1, Vector3Int* pos2, char factor)
{
auto* spark = GetFreeParticle();
@@ -83,7 +85,7 @@ namespace TEN::Entities::TR5
spark->dSize = spark->size * 2;
}
- static void TriggerTorpedoSparks2(Vector3Int* pos1, Vector3Int* pos2, char scale)
+ void TriggerTorpedoSparks2(Vector3Int* pos1, Vector3Int* pos2, char scale)
{
auto* spark = GetFreeParticle();
@@ -115,55 +117,56 @@ namespace TEN::Entities::TR5
spark->dSize = spark->size * 2;
}
- static void SubmarineAttack(ItemInfo* item)
+ void SubmarineAttack(ItemInfo* item)
{
short itemNumber = CreateItem();
+ if (itemNumber == NO_ITEM)
+ return;
- if (itemNumber != NO_ITEM)
+ auto* torpedoItem = &g_Level.Items[itemNumber];
+
+ SoundEffect(SFX_TR5_UNDERWATER_TORPEDO, &torpedoItem->Pose, SoundEnvironment::Always);
+
+ torpedoItem->ObjectNumber = ID_TORPEDO;
+ torpedoItem->Color = Vector4(0.5f, 0.5f, 0.5f, 1.0f);
+
+ Vector3Int pos1;
+ Vector3Int pos2;
+
+ for (int i = 0; i < 8; i++)
{
- auto* torpedoItem = &g_Level.Items[itemNumber];
+ auto pos1 = Vector3Int(
+ (GetRandomControl() & 0x7F) - 414,
+ -320,
+ 352
+ );
+ GetJointAbsPosition(item, &pos1, 4);
- SoundEffect(SFX_TR5_UNDERWATER_TORPEDO, &torpedoItem->Pose, SoundEnvironment::Always);
+ auto pos2 = Vector3Int(
+ (GetRandomControl() & 0x3FF) - 862,
+ -320 - (GetRandomControl() & 0x3FF),
+ (GetRandomControl() & 0x3FF) - 160
+ );
+ GetJointAbsPosition(item, &pos2, 4);
- torpedoItem->ObjectNumber = ID_TORPEDO;
- torpedoItem->Color = Vector4(0.5f, 0.5f, 0.5f, 1.0f);
-
- Vector3Int pos1;
- Vector3Int pos2;
-
- for (int i = 0; i < 8; i++)
- {
- pos1.x = (GetRandomControl() & 0x7F) - 414;
- pos1.y = -320;
- pos1.z = 352;
- GetJointAbsPosition(item, &pos1, 4);
-
- pos2.x = (GetRandomControl() & 0x3FF) - 862;
- pos2.y = -320 - (GetRandomControl() & 0x3FF);
- pos2.z = (GetRandomControl() & 0x3FF) - 160;
- GetJointAbsPosition(item, &pos2, 4);
-
- TriggerTorpedoSparks2(&pos1, &pos2, 0);
- }
-
- torpedoItem->RoomNumber = item->RoomNumber;
- GetFloor(pos1.x, pos1.y, pos1.z, &torpedoItem->RoomNumber);
-
- torpedoItem->Pose.Position.x = pos1.x;
- torpedoItem->Pose.Position.y = pos1.y;
- torpedoItem->Pose.Position.z = pos1.z;
-
- InitialiseItem(itemNumber);
-
- torpedoItem->Pose.Orientation.x = 0;
- torpedoItem->Pose.Orientation.y = item->Pose.Orientation.y;
- torpedoItem->Pose.Orientation.z = 0;
- torpedoItem->Animation.Velocity.z = 0;
- torpedoItem->Animation.Velocity.y = 0;
- torpedoItem->ItemFlags[0] = -1;
-
- AddActiveItem(itemNumber);
+ TriggerTorpedoSparks2(&pos1, &pos2, 0);
}
+
+ torpedoItem->RoomNumber = item->RoomNumber;
+ GetFloor(pos1.x, pos1.y, pos1.z, &torpedoItem->RoomNumber);
+
+ torpedoItem->Pose.Position = pos1;
+
+ InitialiseItem(itemNumber);
+
+ torpedoItem->Animation.Velocity.y = 0.0f;
+ torpedoItem->Animation.Velocity.z = 0.0f;
+ torpedoItem->Pose.Orientation.x = 0;
+ torpedoItem->Pose.Orientation.y = item->Pose.Orientation.y;
+ torpedoItem->Pose.Orientation.z = 0;
+ torpedoItem->ItemFlags[0] = -1;
+
+ AddActiveItem(itemNumber);
}
void InitialiseSubmarine(short itemNumber)
@@ -171,10 +174,7 @@ namespace TEN::Entities::TR5
auto* item = &g_Level.Items[itemNumber];
ClearItem(itemNumber);
- item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.TargetState = 0;
- item->Animation.ActiveState = 0;
+ SetAnimation(item, 0);
if (!item->TriggerFlags)
item->TriggerFlags = 120;
@@ -186,14 +186,14 @@ namespace TEN::Entities::TR5
return;
auto* item = &g_Level.Items[itemNumber];
- auto* creature = (CreatureInfo*)item->Data;
+ auto* creature = GetCreatureInfo(item);
if (item->AIBits)
GetAITarget(creature);
else
creature->Enemy = LaraItem;
- AI_INFO AI, laraInfo;
+ AI_INFO AI, laraAI;
CreatureAIInfo(item, &AI);
GetCreatureMood(item, &AI, true);
@@ -203,34 +203,34 @@ namespace TEN::Entities::TR5
if (creature->Enemy == LaraItem)
{
- laraInfo.angle = AI.angle;
- laraInfo.distance = AI.distance;
+ laraAI.angle = AI.angle;
+ laraAI.distance = AI.distance;
}
else
{
int dx = LaraItem->Pose.Position.x - item->Pose.Position.x;
int dz = LaraItem->Pose.Position.z - item->Pose.Position.z;
- laraInfo.angle = phd_atan(dz, dx) - item->Pose.Orientation.y;
- laraInfo.distance = pow(dx, 2) + pow(dz, 2);
- laraInfo.ahead = true;
+ laraAI.angle = phd_atan(dz, dx) - item->Pose.Orientation.y;
+ laraAI.distance = pow(dx, 2) + pow(dz, 2);
+ laraAI.ahead = true;
}
int tilt = item->ItemFlags[0] + (angle / 2);
- if (tilt > 2048)
- tilt = 2048;
- else if (tilt < -2048)
- tilt = -2048;
+ if (tilt > ANGLE(11.25f))
+ tilt = ANGLE(11.25f);
+ else if (tilt < ANGLE(-11.25f))
+ tilt = ANGLE(-11.25f);
item->ItemFlags[0] = tilt;
- if (abs(tilt) >= 64)
+ if (abs(tilt) >= ANGLE(0.35f))
{
if (tilt > 0)
- item->ItemFlags[0] -= 64;
+ item->ItemFlags[0] -= ANGLE(0.35f);
else
- item->ItemFlags[0] += 64;
+ item->ItemFlags[0] += ANGLE(0.35f);
}
else
item->ItemFlags[0] = 0;
@@ -245,17 +245,17 @@ namespace TEN::Entities::TR5
auto* enemy = creature->Enemy;
creature->Enemy = LaraItem;
- if (Targetable(item, &laraInfo))
+ if (Targetable(item, &laraAI))
{
if (creature->Flags >= item->TriggerFlags &&
- laraInfo.angle > -ANGLE(90.0f) &&
- laraInfo.angle < ANGLE(90.0f))
+ laraAI.angle > -ANGLE(90.0f) &&
+ laraAI.angle < ANGLE(90.0f))
{
SubmarineAttack(item);
creature->Flags = 0;
}
- if (laraInfo.distance >= pow(SECTOR(3), 2))
+ if (laraAI.distance >= pow(SECTOR(3), 2))
{
item->Animation.TargetState = 1;
SoundEffect(SFX_TR5_VEHICLE_DIVESUIT_LOOP, &item->Pose, SoundEnvironment::Always);
@@ -266,15 +266,15 @@ namespace TEN::Entities::TR5
if (AI.distance < pow(SECTOR(1), 2))
{
creature->MaxTurn = 0;
- if (abs(laraInfo.angle) >= ANGLE(2.0f))
+ if (abs(laraAI.angle) >= ANGLE(2.0f))
{
- if (laraInfo.angle >= 0)
+ if (laraAI.angle >= 0)
item->Pose.Orientation.y += ANGLE(2.0f);
else
item->Pose.Orientation.y -= ANGLE(2.0f);
}
else
- item->Pose.Orientation.y += laraInfo.angle;
+ item->Pose.Orientation.y += laraAI.angle;
}
}
else
@@ -288,36 +288,36 @@ namespace TEN::Entities::TR5
if (GlobalCounter & 1)
{
- Vector3Int pos1 = { 200, 320, 90 };
+ auto pos1 = Vector3Int(200, 320, 90);
GetJointAbsPosition(item, &pos1, 1);
- Vector3Int pos2 = { 200, 1280, 90 };
+ auto pos2 = Vector3Int(200, 1280, 90);
GetJointAbsPosition(item, &pos2, 1);
TriggerTorpedoBubbles(&pos1, &pos2, 0);
- pos1 = { 200, 320, -100 };
+ pos1 = Vector3Int(200, 320, -100);
GetJointAbsPosition(item, &pos1, 1);
- pos2 = { 200, 1280, -100 };
+ pos2 = Vector3Int(200, 1280, -100);
GetJointAbsPosition(item, &pos2, 1);
TriggerTorpedoBubbles(&pos1, &pos2, 0);
}
else
{
- Vector3Int pos1 = { -200, 320, 90 };
+ auto pos1 = Vector3Int(-200, 320, 90);
GetJointAbsPosition(item, &pos1, 2);
- Vector3Int pos2 = { -200, 1280, 90 };
+ auto pos2 = Vector3Int(-200, 1280, 90);
GetJointAbsPosition(item, &pos2, 2);
TriggerTorpedoBubbles(&pos1, &pos2, 0);
- pos1 = { -200, 320, -100 };
+ pos1 = Vector3Int(-200, 320, -100);
GetJointAbsPosition(item, &pos1, 2);
- pos2 = { -200, 1280, -100 };
+ pos2 = Vector3Int(-200, 1280, -100);
GetJointAbsPosition(item, &pos2, 2);
TriggerTorpedoBubbles(&pos1, &pos2, 0);
@@ -384,8 +384,8 @@ namespace TEN::Entities::TR5
if (TestEnvironment(ENV_FLAG_WATER, item->RoomNumber))
{
- item->Animation.Velocity.z += (5 - item->Animation.Velocity.z) / 2;
- item->Animation.Velocity.y+= (5 - item->Animation.Velocity.y) / 2;
+ item->Animation.Velocity.y += (5.0f - item->Animation.Velocity.y) / 2.0f;
+ item->Animation.Velocity.z += (5.0f - item->Animation.Velocity.z) / 2.0f;
}
else
item->Animation.Velocity.y += GRAVITY;
@@ -440,20 +440,14 @@ namespace TEN::Entities::TR5
if (searchItem->ObjectNumber == ID_CHAFF && searchItem->Active)
{
item->ItemFlags[0] = i;
- pos.x = searchItem->Pose.Position.x;
- pos.y = searchItem->Pose.Position.y;
- pos.z = searchItem->Pose.Position.z;
+ pos = searchItem->Pose.Position;
found = true;
break;
}
}
if (!found)
- {
- pos.x = LaraItem->Pose.Position.x;
- pos.y = LaraItem->Pose.Position.y;
- pos.z = LaraItem->Pose.Position.z;
- }
+ pos = LaraItem->Pose.Position;
}
else
{
@@ -461,9 +455,7 @@ namespace TEN::Entities::TR5
if (chaffItem->Active && chaffItem->ObjectNumber == ID_CHAFF)
{
- pos.x = chaffItem->Pose.Position.x;
- pos.y = chaffItem->Pose.Position.y;
- pos.z = chaffItem->Pose.Position.z;
+ pos = chaffItem->Pose.Position;
item->Animation.ActiveState = pos.x / 4;
item->Animation.TargetState = pos.y / 4;
item->Animation.RequiredState = pos.z / 4;
@@ -478,13 +470,13 @@ namespace TEN::Entities::TR5
auto angles = GetVectorAngles(pos.x - item->Pose.Position.x, pos.y - item->Pose.Position.y, pos.z - item->Pose.Position.z);
- if (item->Animation.Velocity.z >= 48)
+ if (item->Animation.Velocity.z >= 48.0f)
{
- if (item->Animation.Velocity.z < 192)
+ if (item->Animation.Velocity.z < 192.0f)
item->Animation.Velocity.z++;
}
else
- item->Animation.Velocity.z += 4;
+ item->Animation.Velocity.z += 4.0f;
item->ItemFlags[1]++;
diff --git a/TombEngine/Objects/TR5/Entity/tr5_willowwisp.cpp b/TombEngine/Objects/TR5/Entity/tr5_willowwisp.cpp
index f2c8e6a04..5cbeef02e 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_willowwisp.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_willowwisp.cpp
@@ -17,9 +17,6 @@ namespace TEN::Entities::TR5
auto* item = &g_Level.Items[itemNumber];
ClearItem(itemNumber);
- item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = WWISP_STATE_UNK;
- item->Animation.TargetState = WWISP_STATE_UNK;
+ SetAnimation(item, 0);
}
}
From 5782965e11690c38212f0f33775f42a2e5625a3c Mon Sep 17 00:00:00 2001
From: Sezz
Date: Sun, 21 Aug 2022 15:13:45 +1000
Subject: [PATCH 019/106] Move TR5 creatures into more appropriate namespace
---
TombEngine/Game/itemdata/itemdata.h | 2 +-
.../Objects/TR4/Entity/tr4_big_scorpion.cpp | 2 +-
.../Objects/TR5/Entity/tr5_autoguns.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_autoguns.h | 2 +-
.../Objects/TR5/Entity/tr5_brownbeast.cpp | 2 +-
.../Objects/TR5/Entity/tr5_brownbeast.h | 2 +-
TombEngine/Objects/TR5/Entity/tr5_chef.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_chef.h | 2 +-
TombEngine/Objects/TR5/Entity/tr5_cyborg.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_cyborg.h | 2 +-
.../Objects/TR5/Entity/tr5_doberman.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_doberman.h | 2 +-
TombEngine/Objects/TR5/Entity/tr5_dog.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_dog.h | 2 +-
TombEngine/Objects/TR5/Entity/tr5_ghost.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_ghost.h | 2 +-
.../Objects/TR5/Entity/tr5_gladiator.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_gladiator.h | 2 +-
TombEngine/Objects/TR5/Entity/tr5_guard.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_guard.h | 2 +-
TombEngine/Objects/TR5/Entity/tr5_gunship.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_gunship.h | 2 +-
TombEngine/Objects/TR5/Entity/tr5_hydra.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_hydra.h | 2 +-
TombEngine/Objects/TR5/Entity/tr5_imp.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_imp.h | 2 +-
.../Objects/TR5/Entity/tr5_lagoon_witch.cpp | 2 +-
.../Objects/TR5/Entity/tr5_lagoon_witch.h | 2 +-
TombEngine/Objects/TR5/Entity/tr5_larson.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_larson.h | 2 +-
.../Objects/TR5/Entity/tr5_laser_head.cpp | 2 +-
.../Objects/TR5/Entity/tr5_laser_head.h | 2 +-
.../Objects/TR5/Entity/tr5_laserhead_info.h | 2 +-
TombEngine/Objects/TR5/Entity/tr5_lion.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_lion.h | 2 +-
TombEngine/Objects/TR5/Entity/tr5_reaper.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_reaper.h | 2 +-
.../Objects/TR5/Entity/tr5_roman_statue.cpp | 2 +-
.../Objects/TR5/Entity/tr5_roman_statue.h | 2 +-
.../Objects/TR5/Entity/tr5_submarine.cpp | 2 +-
TombEngine/Objects/TR5/Entity/tr5_submarine.h | 2 +-
.../Objects/TR5/Entity/tr5_willowwisp.cpp | 2 +-
.../Objects/TR5/Entity/tr5_willowwisp.h | 2 +-
.../TR5/Switch/tr5_crowdove_switch.cpp | 16 ++++----
.../Objects/TR5/Switch/tr5_crowdove_switch.h | 5 +--
TombEngine/Objects/TR5/tr5_objects.cpp | 40 +++++++++----------
46 files changed, 73 insertions(+), 74 deletions(-)
diff --git a/TombEngine/Game/itemdata/itemdata.h b/TombEngine/Game/itemdata/itemdata.h
index fa34c7a83..cf44da884 100644
--- a/TombEngine/Game/itemdata/itemdata.h
+++ b/TombEngine/Game/itemdata/itemdata.h
@@ -26,7 +26,7 @@ template struct visitor : Ts... { using Ts::operator()...; };
template visitor(Ts...)->visitor; // line not needed in C++20...
using namespace TEN::Entities::TR4;
-using namespace TEN::Entities::TR5;
+using namespace TEN::Entities::Creatures::TR5;
using namespace TEN::Entities::Vehicles;
struct ItemInfo;
diff --git a/TombEngine/Objects/TR4/Entity/tr4_big_scorpion.cpp b/TombEngine/Objects/TR4/Entity/tr4_big_scorpion.cpp
index 4d920706a..84481377b 100644
--- a/TombEngine/Objects/TR4/Entity/tr4_big_scorpion.cpp
+++ b/TombEngine/Objects/TR4/Entity/tr4_big_scorpion.cpp
@@ -22,7 +22,7 @@ namespace TEN::Entities::TR4
{
constexpr auto BIG_SCORPION_ATTACK_DAMAGE = 120;
constexpr auto BIG_SCORPION_TROOP_ATTACK_DAMAGE = 15;
- constexpr auto BIG_SCORPION_STINGER_POISON_POTENCY = 8;
+ constexpr auto BIG_SCORPION_STINGER_POISON_POTENCY = 16;
constexpr auto BIG_SCORPION_ATTACK_RANGE = SQUARE(SECTOR(1.35));
constexpr auto BIG_SCORPION_RUN_RANGE = SQUARE(SECTOR(2));
diff --git a/TombEngine/Objects/TR5/Entity/tr5_autoguns.cpp b/TombEngine/Objects/TR5/Entity/tr5_autoguns.cpp
index 380cc0bfb..c11ab4975 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_autoguns.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_autoguns.cpp
@@ -14,7 +14,7 @@
using namespace TEN::Math::Random;
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseAutoGuns(short itemNumber)
{
diff --git a/TombEngine/Objects/TR5/Entity/tr5_autoguns.h b/TombEngine/Objects/TR5/Entity/tr5_autoguns.h
index d9d344551..3c37772dd 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_autoguns.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_autoguns.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseAutoGuns(short itemNumber);
void AutoGunsControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_brownbeast.cpp b/TombEngine/Objects/TR5/Entity/tr5_brownbeast.cpp
index ebd6f23b6..5fffd2aa9 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_brownbeast.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_brownbeast.cpp
@@ -15,7 +15,7 @@
using namespace TEN::Math::Random;
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
constexpr auto BROWN_BEAST_ATTACK_DAMAGE = 150;
diff --git a/TombEngine/Objects/TR5/Entity/tr5_brownbeast.h b/TombEngine/Objects/TR5/Entity/tr5_brownbeast.h
index aad8f18a9..fa5cab857 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_brownbeast.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_brownbeast.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseBrownBeast(short itemNumber);
void ControlBrowsBeast(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_chef.cpp b/TombEngine/Objects/TR5/Entity/tr5_chef.cpp
index 6e58f1cda..2085c9a1f 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_chef.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_chef.cpp
@@ -13,7 +13,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
const auto ChefBite = BiteInfo(Vector3(0.0f, 200.0f, 0.0f), 13);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_chef.h b/TombEngine/Objects/TR5/Entity/tr5_chef.h
index 46b2aaaf3..da801ab5d 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_chef.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_chef.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseChef(short itemNumber);
void ControlChef(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_cyborg.cpp b/TombEngine/Objects/TR5/Entity/tr5_cyborg.cpp
index a9cfe4c9a..c0ab19da9 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_cyborg.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_cyborg.cpp
@@ -19,7 +19,7 @@
using namespace TEN::Effects::Lara;
using namespace TEN::Effects::Lightning;
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
const auto CyborgGunBite = BiteInfo(Vector3(0.0f, 300.0f, 64.0f), 7);
byte HitmanJoints[12] = { 15, 14, 13, 6, 5, 12, 7, 4, 10, 11, 19 };
diff --git a/TombEngine/Objects/TR5/Entity/tr5_cyborg.h b/TombEngine/Objects/TR5/Entity/tr5_cyborg.h
index b81f7a942..80ec07d97 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_cyborg.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_cyborg.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseCyborg(short itemNumber);
void CyborgControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_doberman.cpp b/TombEngine/Objects/TR5/Entity/tr5_doberman.cpp
index eb3e4543a..ca562e8fc 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_doberman.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_doberman.cpp
@@ -14,7 +14,7 @@
using namespace TEN::Math::Random;
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
const auto DobermanBite = BiteInfo(Vector3(0.0f, 30.0f, 141.0f), 20);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_doberman.h b/TombEngine/Objects/TR5/Entity/tr5_doberman.h
index 2edd5c50b..bba3b5fb1 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_doberman.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_doberman.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseDoberman(short itemNumber);
void DobermanControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_dog.cpp b/TombEngine/Objects/TR5/Entity/tr5_dog.cpp
index 6fa38a571..dec3abace 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_dog.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_dog.cpp
@@ -11,7 +11,7 @@
#include "Game/items.h"
#include "Game/misc.h"
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
const auto DogBite = BiteInfo(Vector3(0.0f, 0.0f, 100.0f), 3);
static BYTE DogAnims[] = { 20, 21, 22, 20 };
diff --git a/TombEngine/Objects/TR5/Entity/tr5_dog.h b/TombEngine/Objects/TR5/Entity/tr5_dog.h
index 3021da3b5..82e278d2c 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_dog.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_dog.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseTr5Dog(short itemNumber);
void Tr5DogControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_ghost.cpp b/TombEngine/Objects/TR5/Entity/tr5_ghost.cpp
index af812e63f..52b543a91 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_ghost.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_ghost.cpp
@@ -10,7 +10,7 @@
#include "Sound/sound.h"
#include "Game/itemdata/creature_info.h"
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
const auto InvisibleGhostBite = BiteInfo(Vector3::Zero, 17);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_ghost.h b/TombEngine/Objects/TR5/Entity/tr5_ghost.h
index 40ef99ba3..62ccb4596 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_ghost.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_ghost.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseInvisibleGhost(short itemNumber);
void InvisibleGhostControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_gladiator.cpp b/TombEngine/Objects/TR5/Entity/tr5_gladiator.cpp
index aae3085dd..8434d8639 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_gladiator.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_gladiator.cpp
@@ -18,7 +18,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
constexpr auto GLADIATOR_ATTACK_DAMAGE = 120;
diff --git a/TombEngine/Objects/TR5/Entity/tr5_gladiator.h b/TombEngine/Objects/TR5/Entity/tr5_gladiator.h
index a28b30371..752637ef9 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_gladiator.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_gladiator.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseGladiator(short itemNumber);
void ControlGladiator(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_guard.cpp b/TombEngine/Objects/TR5/Entity/tr5_guard.cpp
index aa39aee12..eefc48524 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_guard.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_guard.cpp
@@ -19,7 +19,7 @@
using namespace TEN::Math::Random;
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
const auto SwatGunBite = BiteInfo(Vector3(80.0f, 200.0f, 13.0f), 0);
const auto SniperGunBite = BiteInfo(Vector3(0.0f, 480.0f, 110.0f), 13);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_guard.h b/TombEngine/Objects/TR5/Entity/tr5_guard.h
index 847958397..68aa3e723 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_guard.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_guard.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseGuard(short itemNumber);
void GuardControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_gunship.cpp b/TombEngine/Objects/TR5/Entity/tr5_gunship.cpp
index 782e180bf..6ecc0e7c7 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_gunship.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_gunship.cpp
@@ -12,7 +12,7 @@
#include "Game/items.h"
#include "Game/Lara/lara.h"
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
int GunShipCounter = 0;
diff --git a/TombEngine/Objects/TR5/Entity/tr5_gunship.h b/TombEngine/Objects/TR5/Entity/tr5_gunship.h
index 60ba90808..9f862512a 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_gunship.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_gunship.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void ControlGunShip(short itemNumber);
}
diff --git a/TombEngine/Objects/TR5/Entity/tr5_hydra.cpp b/TombEngine/Objects/TR5/Entity/tr5_hydra.cpp
index 94230274b..05e51a6ff 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_hydra.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_hydra.cpp
@@ -17,7 +17,7 @@
using namespace TEN::Math::Random;
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
const auto HydraBite = BiteInfo(Vector3::Zero, 11);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_hydra.h b/TombEngine/Objects/TR5/Entity/tr5_hydra.h
index 0567421b4..324ca600d 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_hydra.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_hydra.h
@@ -1,7 +1,7 @@
#pragma once
#include "Specific/phd_global.h"
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseHydra(short itemNumber);
void HydraControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_imp.cpp b/TombEngine/Objects/TR5/Entity/tr5_imp.cpp
index 29c2e501b..b8715c98b 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_imp.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_imp.cpp
@@ -14,7 +14,7 @@
using namespace TEN::Entities::Generic;
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
const auto ImpBite = BiteInfo(Vector3(0.0f, 100.0f, 0.0f), 9);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_imp.h b/TombEngine/Objects/TR5/Entity/tr5_imp.h
index f32d76ab6..2b3f5882e 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_imp.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_imp.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseImp(short itemNumber);
void ImpControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.cpp b/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.cpp
index 170b4f6b8..e73250c6f 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.cpp
@@ -14,7 +14,7 @@
using std::vector;
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
constexpr auto LAGOON_WITCH_ATTACK_DAMAGE = 100;
diff --git a/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.h b/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.h
index f4808d67e..b43431ba4 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_lagoon_witch.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseLagoonWitch(short itemNumber);
void LagoonWitchControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_larson.cpp b/TombEngine/Objects/TR5/Entity/tr5_larson.cpp
index 48d874e13..89e698ca5 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_larson.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_larson.cpp
@@ -16,7 +16,7 @@
using namespace TEN::Math::Random;
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
#define STATE_TR5_LARSON_STOP 1
#define STATE_TR5_LARSON_WALK 2
diff --git a/TombEngine/Objects/TR5/Entity/tr5_larson.h b/TombEngine/Objects/TR5/Entity/tr5_larson.h
index 15c75470b..4e86b61c9 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_larson.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_larson.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseLarson(short itemNumber);
void LarsonControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_laser_head.cpp b/TombEngine/Objects/TR5/Entity/tr5_laser_head.cpp
index a1a848331..a889a960e 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_laser_head.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_laser_head.cpp
@@ -19,7 +19,7 @@
using namespace TEN::Effects::Lara;
using namespace TEN::Effects::Lightning;
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
struct LaserHeadStruct
{
diff --git a/TombEngine/Objects/TR5/Entity/tr5_laser_head.h b/TombEngine/Objects/TR5/Entity/tr5_laser_head.h
index 5990de0b3..abd3542b4 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_laser_head.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_laser_head.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseLaserHead(short itemNumber);
void LaserHeadControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_laserhead_info.h b/TombEngine/Objects/TR5/Entity/tr5_laserhead_info.h
index a0b038821..52adc215f 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_laserhead_info.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_laserhead_info.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
struct LaserHeadInfo
{
diff --git a/TombEngine/Objects/TR5/Entity/tr5_lion.cpp b/TombEngine/Objects/TR5/Entity/tr5_lion.cpp
index 72c780d24..66fd9992e 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_lion.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_lion.cpp
@@ -16,7 +16,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
constexpr auto LION_POUNCE_ATTACK_DAMAGE = 200;
constexpr auto LION_BITE_ATTACK_DAMAGE = 60;
diff --git a/TombEngine/Objects/TR5/Entity/tr5_lion.h b/TombEngine/Objects/TR5/Entity/tr5_lion.h
index 85d223a2d..4218188f4 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_lion.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_lion.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseLion(short itemNumber);
void LionControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_reaper.cpp b/TombEngine/Objects/TR5/Entity/tr5_reaper.cpp
index f8f1ba0ac..4018b8e2a 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_reaper.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_reaper.cpp
@@ -9,7 +9,7 @@
#include "Game/itemdata/creature_info.h"
#include "Game/control/control.h"
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseReaper(short itemNumber)
{
diff --git a/TombEngine/Objects/TR5/Entity/tr5_reaper.h b/TombEngine/Objects/TR5/Entity/tr5_reaper.h
index 464d8dae5..cebde76ff 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_reaper.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_reaper.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseReaper(short itemNumber);
void ReaperControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_roman_statue.cpp b/TombEngine/Objects/TR5/Entity/tr5_roman_statue.cpp
index a7d242b5e..3bccfa45d 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_roman_statue.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_roman_statue.cpp
@@ -18,7 +18,7 @@
using namespace TEN::Effects::Lightning;
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
const auto RomanStatueBite = BiteInfo(Vector3::Zero, 15);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_roman_statue.h b/TombEngine/Objects/TR5/Entity/tr5_roman_statue.h
index d2b9ee411..0b35f6e09 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_roman_statue.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_roman_statue.h
@@ -1,7 +1,7 @@
#pragma once
#include "Specific/phd_global.h"
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseRomanStatue(short itemNumber);
void RomanStatueControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_submarine.cpp b/TombEngine/Objects/TR5/Entity/tr5_submarine.cpp
index 4581b2184..bfdde4086 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_submarine.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_submarine.cpp
@@ -18,7 +18,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void TriggerSubmarineSparks(short itemNumber)
{
diff --git a/TombEngine/Objects/TR5/Entity/tr5_submarine.h b/TombEngine/Objects/TR5/Entity/tr5_submarine.h
index ab76d34ca..7a3db051e 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_submarine.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_submarine.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseSubmarine(short itemNumber);
void SubmarineControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_willowwisp.cpp b/TombEngine/Objects/TR5/Entity/tr5_willowwisp.cpp
index 5cbeef02e..d99d28674 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_willowwisp.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_willowwisp.cpp
@@ -5,7 +5,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
enum WillowWispState
{
diff --git a/TombEngine/Objects/TR5/Entity/tr5_willowwisp.h b/TombEngine/Objects/TR5/Entity/tr5_willowwisp.h
index 778c3ea29..6271a9c6f 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_willowwisp.h
+++ b/TombEngine/Objects/TR5/Entity/tr5_willowwisp.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Creatures::TR5
{
void InitialiseLightingGuide(short itemNumber);
}
diff --git a/TombEngine/Objects/TR5/Switch/tr5_crowdove_switch.cpp b/TombEngine/Objects/TR5/Switch/tr5_crowdove_switch.cpp
index 274bb64bb..7f725661a 100644
--- a/TombEngine/Objects/TR5/Switch/tr5_crowdove_switch.cpp
+++ b/TombEngine/Objects/TR5/Switch/tr5_crowdove_switch.cpp
@@ -1,21 +1,21 @@
#include "framework.h"
#include "tr5_crowdove_switch.h"
+
+#include "Game/animation.h"
+#include "Game/collision/collide_item.h"
#include "Game/control/control.h"
-#include "Specific/input.h"
-#include "Specific/level.h"
+#include "Game/effects/debris.h"
+#include "Game/items.h"
#include "Game/Lara/lara.h"
#include "Game/Lara/lara_helpers.h"
#include "Objects/Generic/Switches/generic_switch.h"
#include "Sound/sound.h"
-#include "Game/animation.h"
-#include "Game/items.h"
-#include "Game/collision/collide_item.h"
-#include "Game/effects/debris.h"
+#include "Specific/input.h"
+#include "Specific/level.h"
using namespace TEN::Input;
-using namespace TEN::Entities::Switches;
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Switches
{
OBJECT_COLLISION_BOUNDS CrowDoveBounds =
{
diff --git a/TombEngine/Objects/TR5/Switch/tr5_crowdove_switch.h b/TombEngine/Objects/TR5/Switch/tr5_crowdove_switch.h
index 8aeeea90f..c32c73df8 100644
--- a/TombEngine/Objects/TR5/Switch/tr5_crowdove_switch.h
+++ b/TombEngine/Objects/TR5/Switch/tr5_crowdove_switch.h
@@ -1,9 +1,8 @@
#pragma once
-
-#include "Game/items.h"
#include "Game/collision/collide_room.h"
+#include "Game/items.h"
-namespace TEN::Entities::TR5
+namespace TEN::Entities::Switches
{
void InitialiseCrowDoveSwitch(short itemNumber);
void CrowDoveSwitchControl(short itemNumber);
diff --git a/TombEngine/Objects/TR5/tr5_objects.cpp b/TombEngine/Objects/TR5/tr5_objects.cpp
index 1efa9b1dd..aa98ec944 100644
--- a/TombEngine/Objects/TR5/tr5_objects.cpp
+++ b/TombEngine/Objects/TR5/tr5_objects.cpp
@@ -1,7 +1,20 @@
#include "framework.h"
#include "Objects/TR5/tr5_objects.h"
-/// Entities
+#include "Game/collision/collide_item.h"
+#include "Game/control/box.h"
+#include "Game/itemdata/creature_info.h"
+#include "Game/Lara/lara_flare.h"
+#include "Game/Lara/lara_initialise.h"
+#include "Game/Lara/lara_one_gun.h"
+#include "Game/pickup/pickup.h"
+#include "Objects/Generic/Object/objects.h"
+#include "Objects/Generic/Switches/switch.h"
+#include "Objects/Utils/object_helper.h"
+#include "Specific/level.h"
+#include "Specific/setup.h"
+
+// Creatures
#include "tr5_autoguns.h" // OK
#include "tr5_brownbeast.h" // OK
#include "tr5_chef.h" // OK
@@ -23,13 +36,13 @@
#include "tr5_submarine.h" // OK
#include "tr5_willowwisp.h" // OK
-/// Emitters
+// Emitters
#include "Objects/TR5/Emitter/tr5_rats_emitter.h"
#include "Objects/TR5/Emitter/tr5_bats_emitter.h"
#include "Objects/TR5/Emitter/tr5_spider_emitter.h"
#include "tr5_smoke_emitter.h"
-/// Objects
+// Objects
#include "Objects/TR5/Object/tr5_pushableblock.h"
#include "tr5_twoblockplatform.h"
#include "tr5_raisingcog.h"
@@ -42,7 +55,7 @@
#include "tr5_missile.h"
#include "tr5_genslot.h"
-/// Traps
+// Traps
#include "tr5_ventilator.h"
#include "tr5_deathslide.h"
#include "Objects/Effects/tr5_electricity.h"
@@ -55,24 +68,11 @@
// Switches
#include "tr5_crowdove_switch.h"
-/// shatter
+// Shatters
#include "Objects/TR5/Shatter/tr5_smashobject.h"
-/// necessary import
-#include "Game/collision/collide_item.h"
-#include "Game/Lara/lara_one_gun.h"
-#include "Game/Lara/lara_flare.h"
-#include "Game/Lara/lara_initialise.h"
-#include "Game/pickup/pickup.h"
-#include "Specific/setup.h"
-#include "Objects/Generic/Switches/switch.h"
-#include "Objects/Generic/Object/objects.h"
-#include "Specific/level.h"
-/// register objects
-#include "Objects/Utils/object_helper.h"
-#include "Game/itemdata/creature_info.h"
-#include "Game/control/box.h"
-using namespace TEN::Entities::TR5;
+using namespace TEN::Entities::Creatures::TR5;
+using namespace TEN::Entities::Switches;
static void StartEntity(ObjectInfo *obj)
{
From 658498d17b9d20943996264c2792f5d455df214b Mon Sep 17 00:00:00 2001
From: Sezz
Date: Sun, 21 Aug 2022 15:17:57 +1000
Subject: [PATCH 020/106] Move TR1 creatures into more appropriate namespace
---
TombEngine/Objects/TR1/Entity/tr1_ape.cpp | 2 +-
TombEngine/Objects/TR1/Entity/tr1_ape.h | 2 +-
TombEngine/Objects/TR1/Entity/tr1_bear.cpp | 2 +-
TombEngine/Objects/TR1/Entity/tr1_bear.h | 2 +-
TombEngine/Objects/TR1/Entity/tr1_big_rat.cpp | 2 +-
TombEngine/Objects/TR1/Entity/tr1_big_rat.h | 2 +-
TombEngine/Objects/TR1/Entity/tr1_centaur.cpp | 2 +-
TombEngine/Objects/TR1/Entity/tr1_centaur.h | 2 +-
TombEngine/Objects/TR1/Entity/tr1_doppelganger.cpp | 2 +-
TombEngine/Objects/TR1/Entity/tr1_doppelganger.h | 2 +-
TombEngine/Objects/TR1/Entity/tr1_giant_mutant.cpp | 2 +-
TombEngine/Objects/TR1/Entity/tr1_giant_mutant.h | 2 +-
TombEngine/Objects/TR1/Entity/tr1_natla.cpp | 2 +-
TombEngine/Objects/TR1/Entity/tr1_natla.h | 2 +-
TombEngine/Objects/TR1/Entity/tr1_winged_mutant.cpp | 2 +-
TombEngine/Objects/TR1/Entity/tr1_winged_mutant.h | 2 +-
TombEngine/Objects/TR1/Entity/tr1_wolf.cpp | 2 +-
TombEngine/Objects/TR1/Entity/tr1_wolf.h | 2 +-
TombEngine/Objects/TR1/tr1_objects.cpp | 5 ++---
19 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/TombEngine/Objects/TR1/Entity/tr1_ape.cpp b/TombEngine/Objects/TR1/Entity/tr1_ape.cpp
index 23ddb3759..baa2cf01d 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_ape.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_ape.cpp
@@ -15,7 +15,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
constexpr auto APE_ATTACK_DAMAGE = 200;
diff --git a/TombEngine/Objects/TR1/Entity/tr1_ape.h b/TombEngine/Objects/TR1/Entity/tr1_ape.h
index 9edc287ab..081f18fdf 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_ape.h
+++ b/TombEngine/Objects/TR1/Entity/tr1_ape.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
void ApeControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR1/Entity/tr1_bear.cpp b/TombEngine/Objects/TR1/Entity/tr1_bear.cpp
index 49cf01acb..e84b60561 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_bear.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_bear.cpp
@@ -15,7 +15,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
constexpr auto BEAR_RUN_DAMAGE = 3;
constexpr auto BEAR_ATTACK_DAMAGE = 200;
diff --git a/TombEngine/Objects/TR1/Entity/tr1_bear.h b/TombEngine/Objects/TR1/Entity/tr1_bear.h
index dcfd85eb9..24107b33d 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_bear.h
+++ b/TombEngine/Objects/TR1/Entity/tr1_bear.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
void BearControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR1/Entity/tr1_big_rat.cpp b/TombEngine/Objects/TR1/Entity/tr1_big_rat.cpp
index 69e96d258..219a35439 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_big_rat.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_big_rat.cpp
@@ -16,7 +16,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
constexpr auto BIG_RAT_BITE_ATTACK_DAMAGE = 20;
constexpr auto BIG_RAT_POUNCE_ATTACK_DAMAGE = 25;
diff --git a/TombEngine/Objects/TR1/Entity/tr1_big_rat.h b/TombEngine/Objects/TR1/Entity/tr1_big_rat.h
index bdf2afe97..d0e38f9a6 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_big_rat.h
+++ b/TombEngine/Objects/TR1/Entity/tr1_big_rat.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
void InitialiseBigRat(short itemNumber);
void BigRatControl(short itemNumber);
diff --git a/TombEngine/Objects/TR1/Entity/tr1_centaur.cpp b/TombEngine/Objects/TR1/Entity/tr1_centaur.cpp
index 3f9029d35..ffe8549a5 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_centaur.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_centaur.cpp
@@ -21,7 +21,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
constexpr auto CENTAUR_REAR_DAMAGE = 200;
constexpr auto CENTAUR_REAR_RANGE = SECTOR(1.5f);
diff --git a/TombEngine/Objects/TR1/Entity/tr1_centaur.h b/TombEngine/Objects/TR1/Entity/tr1_centaur.h
index ebf3a4984..cf34267d2 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_centaur.h
+++ b/TombEngine/Objects/TR1/Entity/tr1_centaur.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
constexpr auto SHARD_VELOCITY = 250;
constexpr auto BOMB_VELOCITY = 220;
diff --git a/TombEngine/Objects/TR1/Entity/tr1_doppelganger.cpp b/TombEngine/Objects/TR1/Entity/tr1_doppelganger.cpp
index 828dbc715..7c9c06de0 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_doppelganger.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_doppelganger.cpp
@@ -14,7 +14,7 @@
// - Bacon Lara cannot be targeted.
// - Bacon Lara cannot move like Lara.
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
// Original:
void InitialiseDoppelganger(short itemNumber)
diff --git a/TombEngine/Objects/TR1/Entity/tr1_doppelganger.h b/TombEngine/Objects/TR1/Entity/tr1_doppelganger.h
index 0c44a7406..d0b6df5ed 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_doppelganger.h
+++ b/TombEngine/Objects/TR1/Entity/tr1_doppelganger.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
void InitialiseDoppelganger(short itemNumber);
void DoppelgangerControl(short itemNumber);
diff --git a/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.cpp b/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.cpp
index 46709db1e..9d9f200f7 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.cpp
@@ -18,7 +18,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
constexpr auto MUTANT_ATTACK_DAMAGE = 500;
constexpr auto MUTANT_CONTACT_DAMAGE = 6;
diff --git a/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.h b/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.h
index 67c8af943..7c34920d3 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.h
+++ b/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
void GiantMutantControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR1/Entity/tr1_natla.cpp b/TombEngine/Objects/TR1/Entity/tr1_natla.cpp
index f18c25f1e..31aaf4f5f 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_natla.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_natla.cpp
@@ -15,7 +15,7 @@
using namespace TEN::Math::Random;
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
// TODO: Organise.
constexpr auto NATLA_SHOT_DAMAGE = 100;
diff --git a/TombEngine/Objects/TR1/Entity/tr1_natla.h b/TombEngine/Objects/TR1/Entity/tr1_natla.h
index 1140021da..1cbebf286 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_natla.h
+++ b/TombEngine/Objects/TR1/Entity/tr1_natla.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
void NatlaControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR1/Entity/tr1_winged_mutant.cpp b/TombEngine/Objects/TR1/Entity/tr1_winged_mutant.cpp
index 4684f4326..65954e623 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_winged_mutant.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_winged_mutant.cpp
@@ -19,7 +19,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
constexpr auto WINGED_MUTANT_IDLE_JUMP_ATTACK_DAMAGE = 150;
constexpr auto WINGED_MUTANT_RUN_JUMP_ATTACK_DAMAGE = 100;
diff --git a/TombEngine/Objects/TR1/Entity/tr1_winged_mutant.h b/TombEngine/Objects/TR1/Entity/tr1_winged_mutant.h
index d8d9f8688..e637dead4 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_winged_mutant.h
+++ b/TombEngine/Objects/TR1/Entity/tr1_winged_mutant.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
void InitialiseWingedMutant(short itemNumber);
void WingedMutantControl(short itemNumber);
diff --git a/TombEngine/Objects/TR1/Entity/tr1_wolf.cpp b/TombEngine/Objects/TR1/Entity/tr1_wolf.cpp
index a8a293eb8..cdb15b63b 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_wolf.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_wolf.cpp
@@ -15,7 +15,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
constexpr auto WOLF_BITE_DAMAGE = 100;
constexpr auto WOLF_LUNGE_DAMAGE = 50;
diff --git a/TombEngine/Objects/TR1/Entity/tr1_wolf.h b/TombEngine/Objects/TR1/Entity/tr1_wolf.h
index c9a4ec7ec..38b83ab1c 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_wolf.h
+++ b/TombEngine/Objects/TR1/Entity/tr1_wolf.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR1
+namespace TEN::Entities::Creatures::TR1
{
void InitialiseWolf(short itemNumber);
void WolfControl(short itemNumber);
diff --git a/TombEngine/Objects/TR1/tr1_objects.cpp b/TombEngine/Objects/TR1/tr1_objects.cpp
index bd5211126..942ca6f0f 100644
--- a/TombEngine/Objects/TR1/tr1_objects.cpp
+++ b/TombEngine/Objects/TR1/tr1_objects.cpp
@@ -1,7 +1,6 @@
#include "framework.h"
#include "Objects/TR1/tr1_objects.h"
-/// necessary import
#include "Game/control/box.h"
#include "Game/collision/collide_item.h"
#include "Game/itemdata/creature_info.h"
@@ -9,7 +8,7 @@
#include "Specific/setup.h"
#include "Specific/level.h"
-/// entities
+// Creatures
#include "Objects/TR1/Entity/tr1_ape.h" // OK
#include "Objects/TR1/Entity/tr1_bear.h" // OK
#include "Objects/TR1/Entity/tr1_doppelganger.h" // OK
@@ -21,7 +20,7 @@
#include "Objects/TR1/Entity/tr1_winged_mutant.h"
#include "Objects/Utils/object_helper.h"
-using namespace TEN::Entities::TR1;
+using namespace TEN::Entities::Creatures::TR1;
static void StartEntity(ObjectInfo* obj)
{
From deca190af548debb37a2888dd3750229b9ed90b0 Mon Sep 17 00:00:00 2001
From: Sezz
Date: Sun, 21 Aug 2022 15:20:13 +1000
Subject: [PATCH 021/106] Move TR2 creatures into more appropriate namespace
---
TombEngine/Objects/TR2/Entity/tr2_barracuda.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_barracuda.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_bird_monster.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_bird_monster.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_dragon.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_dragon.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_eagle_or_crow.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_eagle_or_crow.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_knife_thrower.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_knife_thrower.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_mercenary.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_mercenary.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_monk.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_monk.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_rat.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_rat.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_shark.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_shark.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_silencer.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_silencer.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_skidman.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_skidman.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_spear_guardian.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_spear_guardian.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_spider.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_spider.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_sword_guardian.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_sword_guardian.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_worker_dualrevolver.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_worker_dualrevolver.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_worker_flamethrower.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_worker_flamethrower.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_worker_machinegun.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_worker_machinegun.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_worker_shotgun.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_worker_shotgun.h | 2 +-
TombEngine/Objects/TR2/Entity/tr2_yeti.cpp | 2 +-
TombEngine/Objects/TR2/Entity/tr2_yeti.h | 2 +-
TombEngine/Objects/TR2/tr2_objects.cpp | 2 +-
39 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/TombEngine/Objects/TR2/Entity/tr2_barracuda.cpp b/TombEngine/Objects/TR2/Entity/tr2_barracuda.cpp
index 4346a201c..68e717b09 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_barracuda.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_barracuda.cpp
@@ -12,7 +12,7 @@
using std::vector;
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
constexpr auto BARRACUDA_ATTACK_DAMAGE = 100;
constexpr auto BARRACUDA_IDLE_ATTACK_RANGE = SQUARE(SECTOR(0.67f));
diff --git a/TombEngine/Objects/TR2/Entity/tr2_barracuda.h b/TombEngine/Objects/TR2/Entity/tr2_barracuda.h
index dfde88ccf..64ddf1939 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_barracuda.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_barracuda.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void BarracudaControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR2/Entity/tr2_bird_monster.cpp b/TombEngine/Objects/TR2/Entity/tr2_bird_monster.cpp
index 1d56afbcf..a71985072 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_bird_monster.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_bird_monster.cpp
@@ -14,7 +14,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
constexpr auto BIRD_MONSTER_ATTACK_DAMAGE = 200;
constexpr auto BIRD_MONSTER_SLAM_CRUSH_ATTACK_RANGE = SQUARE(SECTOR(1));
diff --git a/TombEngine/Objects/TR2/Entity/tr2_bird_monster.h b/TombEngine/Objects/TR2/Entity/tr2_bird_monster.h
index 5756af247..3c97478ce 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_bird_monster.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_bird_monster.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void BirdMonsterControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR2/Entity/tr2_dragon.cpp b/TombEngine/Objects/TR2/Entity/tr2_dragon.cpp
index d8234d996..2ab45bf54 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_dragon.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_dragon.cpp
@@ -20,7 +20,7 @@
using namespace TEN::Input;
using std::vector;
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
constexpr auto DRAGON_SWIPE_ATTACK_DAMAGE = 250;
constexpr auto DRAGON_CONTACT_DAMAGE = 10;
diff --git a/TombEngine/Objects/TR2/Entity/tr2_dragon.h b/TombEngine/Objects/TR2/Entity/tr2_dragon.h
index 0809af93a..d501de501 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_dragon.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_dragon.h
@@ -2,7 +2,7 @@
#include "Game/collision/collide_room.h"
#include "Game/items.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void DragonCollision(short itemNumber, ItemInfo* laraItem, CollisionInfo* coll);
void DragonControl(short backNumber);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_eagle_or_crow.cpp b/TombEngine/Objects/TR2/Entity/tr2_eagle_or_crow.cpp
index a5b078769..b59911c68 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_eagle_or_crow.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_eagle_or_crow.cpp
@@ -10,7 +10,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
const auto EagleBite = BiteInfo(Vector3(15.0f, 46.0f, 21.0f), 6);
const auto CrowBite = BiteInfo(Vector3(2.0f, 10.0f, 60.0f), 14);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_eagle_or_crow.h b/TombEngine/Objects/TR2/Entity/tr2_eagle_or_crow.h
index 4b704e256..828b15bf8 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_eagle_or_crow.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_eagle_or_crow.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void InitialiseEagle(short itemNumber);
void EagleControl(short itemNumber);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_knife_thrower.cpp b/TombEngine/Objects/TR2/Entity/tr2_knife_thrower.cpp
index bde2bff9c..de1b22b40 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_knife_thrower.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_knife_thrower.cpp
@@ -18,7 +18,7 @@
using namespace TEN::Math::Random;
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
constexpr auto KNIFE_PROJECTILE_DAMAGE = 50;
diff --git a/TombEngine/Objects/TR2/Entity/tr2_knife_thrower.h b/TombEngine/Objects/TR2/Entity/tr2_knife_thrower.h
index 640373f24..2204a999c 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_knife_thrower.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_knife_thrower.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void KnifeControl(short fxNumber);
void KnifeThrowerControl(short itemNumber);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_mercenary.cpp b/TombEngine/Objects/TR2/Entity/tr2_mercenary.cpp
index b166e57f0..c312e5002 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_mercenary.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_mercenary.cpp
@@ -11,7 +11,7 @@
#include "Specific/setup.h"
#include "Specific/trmath.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
const auto MercenaryUziBite = BiteInfo(Vector3(0.0f, 150.0f, 19.0f), 17);
const auto MercenaryAutoPistolBite = BiteInfo(Vector3(0.0f, 230.0f, 9.0f), 17);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_mercenary.h b/TombEngine/Objects/TR2/Entity/tr2_mercenary.h
index 5199716ad..80f95100d 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_mercenary.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_mercenary.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void MercenaryUziControl(short itemNumber);
void MercenaryAutoPistolControl(short itemNumber);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_monk.cpp b/TombEngine/Objects/TR2/Entity/tr2_monk.cpp
index 6dd61eb4d..1308c90e5 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_monk.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_monk.cpp
@@ -11,7 +11,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
const auto MonkBite = BiteInfo(Vector3(-23.0f, 16.0f, 265.0f), 14);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_monk.h b/TombEngine/Objects/TR2/Entity/tr2_monk.h
index dcf98f279..5fa99a252 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_monk.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_monk.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void MonkControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR2/Entity/tr2_rat.cpp b/TombEngine/Objects/TR2/Entity/tr2_rat.cpp
index 473e071b2..a636344e6 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_rat.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_rat.cpp
@@ -14,7 +14,7 @@
using namespace TEN::Math::Random;
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
constexpr auto RAT_ATTACK_DAMAGE = 20;
constexpr auto RAT_ATTACK_RANGE = SQUARE(CLICK(0.7f));
diff --git a/TombEngine/Objects/TR2/Entity/tr2_rat.h b/TombEngine/Objects/TR2/Entity/tr2_rat.h
index 1b4ebadcc..9afbf9b8a 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_rat.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_rat.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void RatControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR2/Entity/tr2_shark.cpp b/TombEngine/Objects/TR2/Entity/tr2_shark.cpp
index 6d1e71a10..2f1ef3ae8 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_shark.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_shark.cpp
@@ -11,7 +11,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
const auto SharkBite = BiteInfo(Vector3(17.0f, -22.0f, 344.0f), 12);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_shark.h b/TombEngine/Objects/TR2/Entity/tr2_shark.h
index 1f2d76299..5788ee192 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_shark.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_shark.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void SharkControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR2/Entity/tr2_silencer.cpp b/TombEngine/Objects/TR2/Entity/tr2_silencer.cpp
index c5f124b5f..6261b52d3 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_silencer.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_silencer.cpp
@@ -10,7 +10,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
const auto SilencerGunBite = BiteInfo(Vector3(3.0f, 331.0f, 56.0f), 10);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_silencer.h b/TombEngine/Objects/TR2/Entity/tr2_silencer.h
index 3b91c1f71..69e903dfc 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_silencer.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_silencer.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void SilencerControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR2/Entity/tr2_skidman.cpp b/TombEngine/Objects/TR2/Entity/tr2_skidman.cpp
index dec4daf4e..fb0c8b51c 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_skidman.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_skidman.cpp
@@ -17,7 +17,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
#define SMAN_MIN_TURN (ANGLE(2.0f))
#define SMAN_TARGET_ANGLE ANGLE(15.0f)
diff --git a/TombEngine/Objects/TR2/Entity/tr2_skidman.h b/TombEngine/Objects/TR2/Entity/tr2_skidman.h
index 3a79818c5..bc6147943 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_skidman.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_skidman.h
@@ -2,7 +2,7 @@
#include "Game/collision/collide_room.h"
#include "Game/items.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void InitialiseSkidooMan(short itemNumber);
void SkidooManCollision(short itemNumber, ItemInfo* laraItem, CollisionInfo* coll);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_spear_guardian.cpp b/TombEngine/Objects/TR2/Entity/tr2_spear_guardian.cpp
index 3ad9912e7..32a46fbf1 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_spear_guardian.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_spear_guardian.cpp
@@ -12,7 +12,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
const auto SpearBiteLeft = BiteInfo(Vector3(0.0f, 0.0f, 920.0f), 11);
const auto SpearBiteRight = BiteInfo(Vector3(0.0f, 0.0f, 920.0f), 18);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_spear_guardian.h b/TombEngine/Objects/TR2/Entity/tr2_spear_guardian.h
index d7965b761..e46bb4ea1 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_spear_guardian.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_spear_guardian.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void InitialiseSpearGuardian(short itemNumber);
void SpearGuardianControl(short itemNumber);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_spider.cpp b/TombEngine/Objects/TR2/Entity/tr2_spider.cpp
index 7043d2fc6..e7bb5ac5a 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_spider.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_spider.cpp
@@ -14,7 +14,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
const auto SpiderBite = BiteInfo(Vector3(0.0f, 0.0f, 41.0f), 1);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_spider.h b/TombEngine/Objects/TR2/Entity/tr2_spider.h
index 23d72cc40..9b5876eec 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_spider.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_spider.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void SmallSpiderControl(short itemNumber);
void BigSpiderControl(short itemNumber);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_sword_guardian.cpp b/TombEngine/Objects/TR2/Entity/tr2_sword_guardian.cpp
index 155e51721..062eb22e9 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_sword_guardian.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_sword_guardian.cpp
@@ -13,7 +13,7 @@
#include "Sound/sound.h"
#include "Specific/level.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
const auto SwordBite = BiteInfo(Vector3(0.0f, 37.0f, 550.0f), 15);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_sword_guardian.h b/TombEngine/Objects/TR2/Entity/tr2_sword_guardian.h
index 9c837688b..588df13b8 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_sword_guardian.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_sword_guardian.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void InitialiseSwordGuardian(short itemNumber);
void SwordGuardianControl(short itemNumber);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_worker_dualrevolver.cpp b/TombEngine/Objects/TR2/Entity/tr2_worker_dualrevolver.cpp
index 66e424bf2..5ab9a903b 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_worker_dualrevolver.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_worker_dualrevolver.cpp
@@ -10,7 +10,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
const auto WorkerDualGunBiteLeft = BiteInfo(Vector3(-2.0f, 275.0f, 23.0f), 6);
const auto WorkerDualGunBiteRight = BiteInfo(Vector3(2.0f, 275.0f, 23.0f), 10);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_worker_dualrevolver.h b/TombEngine/Objects/TR2/Entity/tr2_worker_dualrevolver.h
index fd95395f8..d4a1761d3 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_worker_dualrevolver.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_worker_dualrevolver.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void WorkerDualGunControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR2/Entity/tr2_worker_flamethrower.cpp b/TombEngine/Objects/TR2/Entity/tr2_worker_flamethrower.cpp
index a1ed233eb..ee7738029 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_worker_flamethrower.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_worker_flamethrower.cpp
@@ -16,7 +16,7 @@
#include "Specific/level.h"
#include "Specific/trmath.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
const auto WorkerFlamethrowerOffset = Vector3Int(0, 140, 0);
const auto WorkerFlamethrowerBite = BiteInfo(Vector3(0.0f, 250.0f, 32.0f), 9);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_worker_flamethrower.h b/TombEngine/Objects/TR2/Entity/tr2_worker_flamethrower.h
index 89fa4122b..f8b851421 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_worker_flamethrower.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_worker_flamethrower.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void InitialiseWorkerFlamethrower(short itemNumber);
void WorkerFlamethrower(short itemNumber);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_worker_machinegun.cpp b/TombEngine/Objects/TR2/Entity/tr2_worker_machinegun.cpp
index 6a69c3e15..2a198c8f5 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_worker_machinegun.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_worker_machinegun.cpp
@@ -11,7 +11,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
const auto WorkerMachineGunBite = BiteInfo(Vector3(0.0f, 308.0f, 32.0f), 9);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_worker_machinegun.h b/TombEngine/Objects/TR2/Entity/tr2_worker_machinegun.h
index fef58f199..1ba9b187a 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_worker_machinegun.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_worker_machinegun.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void InitialiseWorkerMachineGun(short itemNumber);
void WorkerMachineGunControl(short itemNumber);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_worker_shotgun.cpp b/TombEngine/Objects/TR2/Entity/tr2_worker_shotgun.cpp
index b5bb9e0d1..9f44426e1 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_worker_shotgun.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_worker_shotgun.cpp
@@ -12,7 +12,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
const auto WorkerShotgunBite = BiteInfo(Vector3(0.0f, 281.0f, 40.0f), 9);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_worker_shotgun.h b/TombEngine/Objects/TR2/Entity/tr2_worker_shotgun.h
index a6ad5f5a6..5022fcbd7 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_worker_shotgun.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_worker_shotgun.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void InitialiseWorkerShotgun(short itemNumber);
void WorkerShotgunControl(short itemNumber);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_yeti.cpp b/TombEngine/Objects/TR2/Entity/tr2_yeti.cpp
index 173ba1dd8..8dcd9889c 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_yeti.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_yeti.cpp
@@ -15,7 +15,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
const auto YetiBiteLeft = BiteInfo(Vector3(12.0f, 101.0f, 19.0f), 13);
const auto YetiBiteRight = BiteInfo(Vector3(12.0f, 101.0f, 19.0f), 10);
diff --git a/TombEngine/Objects/TR2/Entity/tr2_yeti.h b/TombEngine/Objects/TR2/Entity/tr2_yeti.h
index aa6ae5f16..f77c73350 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_yeti.h
+++ b/TombEngine/Objects/TR2/Entity/tr2_yeti.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR2
+namespace TEN::Entities::Creatures::TR2
{
void InitialiseYeti(short itemNumber);
void YetiControl(short itemNumber);
diff --git a/TombEngine/Objects/TR2/tr2_objects.cpp b/TombEngine/Objects/TR2/tr2_objects.cpp
index 67c07965b..599a45b7d 100644
--- a/TombEngine/Objects/TR2/tr2_objects.cpp
+++ b/TombEngine/Objects/TR2/tr2_objects.cpp
@@ -37,7 +37,7 @@
#include "Objects/TR2/Vehicles/speedboat.h"
#include "Objects/TR2/Vehicles/skidoo.h"
-using namespace TEN::Entities::TR2;
+using namespace TEN::Entities::Creatures::TR2;
static void StartEntity(ObjectInfo* obj)
{
From 1455ff52a6badabc8451999ef760d0a3bedd3d05 Mon Sep 17 00:00:00 2001
From: Sezz
Date: Sun, 21 Aug 2022 15:23:13 +1000
Subject: [PATCH 022/106] Move TR3 creatures into more appropriate namespace
---
TombEngine/Objects/TR3/Entity/tr3_civvy.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_civvy.h | 2 +-
TombEngine/Objects/TR3/Entity/tr3_cobra.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_cobra.h | 2 +-
TombEngine/Objects/TR3/Entity/tr3_fish_emitter.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_fish_emitter.h | 2 +-
TombEngine/Objects/TR3/Entity/tr3_flamethrower.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_flamethrower.h | 2 +-
TombEngine/Objects/TR3/Entity/tr3_monkey.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_monkey.h | 2 +-
TombEngine/Objects/TR3/Entity/tr3_mp_gun.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_mp_gun.h | 2 +-
TombEngine/Objects/TR3/Entity/tr3_mp_stick.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_mp_stick.h | 2 +-
TombEngine/Objects/TR3/Entity/tr3_raptor.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_raptor.h | 2 +-
TombEngine/Objects/TR3/Entity/tr3_scuba_diver.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_scuba_diver.h | 2 +-
TombEngine/Objects/TR3/Entity/tr3_shiva.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_shiva.h | 2 +-
TombEngine/Objects/TR3/Entity/tr3_sophia.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_sophia.h | 2 +-
TombEngine/Objects/TR3/Entity/tr3_tiger.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_tiger.h | 2 +-
TombEngine/Objects/TR3/Entity/tr3_tony.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_tony.h | 2 +-
TombEngine/Objects/TR3/Entity/tr3_trex.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_trex.h | 2 +-
TombEngine/Objects/TR3/Entity/tr3_tribesman.cpp | 2 +-
TombEngine/Objects/TR3/Entity/tr3_tribesman.h | 2 +-
TombEngine/Objects/TR3/tr3_objects.cpp | 2 +-
31 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/TombEngine/Objects/TR3/Entity/tr3_civvy.cpp b/TombEngine/Objects/TR3/Entity/tr3_civvy.cpp
index aad4a59a4..7ffafd62a 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_civvy.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_civvy.cpp
@@ -16,7 +16,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
constexpr auto CIVVY_ATTACK_DAMAGE = 40;
constexpr auto CIVVY_SWIPE_DAMAGE = 50;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_civvy.h b/TombEngine/Objects/TR3/Entity/tr3_civvy.h
index 0bb46d8b8..f541c16e5 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_civvy.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_civvy.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void InitialiseCivvy(short itemNumber);
void CivvyControl(short itemNumber);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_cobra.cpp b/TombEngine/Objects/TR3/Entity/tr3_cobra.cpp
index fdb3806ec..aaff1fb58 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_cobra.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_cobra.cpp
@@ -14,7 +14,7 @@
using std::vector;
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
constexpr auto COBRA_BITE_ATTACK_DAMAGE = 80;
constexpr auto COBRA_BITE_POISON_POTENCY = 8;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_cobra.h b/TombEngine/Objects/TR3/Entity/tr3_cobra.h
index 53e817328..261d28bd3 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_cobra.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_cobra.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void InitialiseCobra(short itemNum);
void CobraControl(short itemNum);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_fish_emitter.cpp b/TombEngine/Objects/TR3/Entity/tr3_fish_emitter.cpp
index 66a437818..c3b67735f 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_fish_emitter.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_fish_emitter.cpp
@@ -9,7 +9,7 @@
#include "Objects/TR3/fish.h"
#include "Specific/level.h"
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
int PirahnaHitWait = false;
int CarcassItem = NO_ITEM;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_fish_emitter.h b/TombEngine/Objects/TR3/Entity/tr3_fish_emitter.h
index c8168a1c7..0f3f8cc2a 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_fish_emitter.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_fish_emitter.h
@@ -1,7 +1,7 @@
#pragma once
#include "Game/items.h"
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void SetupShoal(int shoalNumber);
void ControlFish(short itemNumber);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_flamethrower.cpp b/TombEngine/Objects/TR3/Entity/tr3_flamethrower.cpp
index 5af828ce5..7531abd3e 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_flamethrower.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_flamethrower.cpp
@@ -19,7 +19,7 @@
using namespace TEN::Math::Random;
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
const auto FlamethrowerOffset = Vector3Int(0, 340, 0);
const auto FlamethrowerBite = BiteInfo(Vector3(0.0f, 340.0f, 64.0f), 7);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_flamethrower.h b/TombEngine/Objects/TR3/Entity/tr3_flamethrower.h
index 61044cf99..761df41cf 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_flamethrower.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_flamethrower.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void FlameThrowerControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR3/Entity/tr3_monkey.cpp b/TombEngine/Objects/TR3/Entity/tr3_monkey.cpp
index 63816c709..5b912e7d1 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_monkey.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_monkey.cpp
@@ -16,7 +16,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
// TODO: Work out damage constants.
constexpr auto MONKEY_SWIPE_ATTACK_PLAYER_DAMAGE = 40;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_monkey.h b/TombEngine/Objects/TR3/Entity/tr3_monkey.h
index e136456b9..8b617e255 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_monkey.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_monkey.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void InitialiseMonkey(short itemNumber);
void MonkeyControl(short itemNumber);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_mp_gun.cpp b/TombEngine/Objects/TR3/Entity/tr3_mp_gun.cpp
index a46c432c2..e3e72d317 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_mp_gun.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_mp_gun.cpp
@@ -19,7 +19,7 @@
using namespace TEN::Math::Random;
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
const auto MPGunBite = BiteInfo(Vector3(0.0f, 160.0f, 40.0f), 13);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_mp_gun.h b/TombEngine/Objects/TR3/Entity/tr3_mp_gun.h
index 9c768f11b..47a21c4e1 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_mp_gun.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_mp_gun.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void MPGunControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR3/Entity/tr3_mp_stick.cpp b/TombEngine/Objects/TR3/Entity/tr3_mp_stick.cpp
index 3378fed0e..525f60f34 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_mp_stick.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_mp_stick.cpp
@@ -17,7 +17,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
const auto MPStickBite1 = BiteInfo(Vector3(247.0f, 10.0f, 11.0f), 13);
const auto MPStickBite2 = BiteInfo(Vector3(0.0f, 0.0f, 100.0f), 6);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_mp_stick.h b/TombEngine/Objects/TR3/Entity/tr3_mp_stick.h
index 75d1addcb..8848a7f72 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_mp_stick.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_mp_stick.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void InitialiseMPStick(short itemNumber);
void MPStickControl(short itemNumber);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp b/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp
index a74c292dc..2e651aaed 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_raptor.cpp
@@ -16,7 +16,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
constexpr auto RAPTOR_ATTACK_DAMAGE = 100;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_raptor.h b/TombEngine/Objects/TR3/Entity/tr3_raptor.h
index a9424ca89..640e202ec 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_raptor.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_raptor.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void RaptorControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR3/Entity/tr3_scuba_diver.cpp b/TombEngine/Objects/TR3/Entity/tr3_scuba_diver.cpp
index f432647a3..c290527e4 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_scuba_diver.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_scuba_diver.cpp
@@ -13,7 +13,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
constexpr auto SCUBA_DIVER_ATTACK_DAMAGE = 50;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_scuba_diver.h b/TombEngine/Objects/TR3/Entity/tr3_scuba_diver.h
index d5bc5b60d..23f9b6167 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_scuba_diver.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_scuba_diver.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void ScubaHarpoonControl(short itemNumber);
void ScubaControl(short itemNumber);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_shiva.cpp b/TombEngine/Objects/TR3/Entity/tr3_shiva.cpp
index 3a8eb3d89..b5fd5f8cb 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_shiva.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_shiva.cpp
@@ -19,7 +19,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
constexpr auto SHIVA_GRAB_ATTACK_DAMAGE = 150;
constexpr auto SHIVA_DOWNWARD_ATTACK_DAMAGE = 180;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_shiva.h b/TombEngine/Objects/TR3/Entity/tr3_shiva.h
index 2aa7cac52..4f208c955 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_shiva.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_shiva.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void InitialiseShiva(short itemNumber);
void ShivaControl(short itemNumber);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_sophia.cpp b/TombEngine/Objects/TR3/Entity/tr3_sophia.cpp
index f28c82d3e..123e255da 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_sophia.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_sophia.cpp
@@ -9,7 +9,7 @@
#include "Sound/sound.h"
#include "Specific/level.h"
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
static BOSS_STRUCT BossData;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_sophia.h b/TombEngine/Objects/TR3/Entity/tr3_sophia.h
index 52778680c..5a96a3725 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_sophia.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_sophia.h
@@ -1,7 +1,7 @@
#pragma once
#include "Game/items.h"
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void ControlLaserBolts(short itemNumber);
void ControlLondBossPlasmaBall(short fxNumber);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp b/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp
index 918e2729d..d80433f11 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_tiger.cpp
@@ -15,7 +15,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
constexpr auto TIGER_ATTACK_DAMAGE = 90;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_tiger.h b/TombEngine/Objects/TR3/Entity/tr3_tiger.h
index d1966b8fb..4f002d68a 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_tiger.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_tiger.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void TigerControl(short itemNumber);
}
diff --git a/TombEngine/Objects/TR3/Entity/tr3_tony.cpp b/TombEngine/Objects/TR3/Entity/tr3_tony.cpp
index 762c1685d..55f663cd7 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_tony.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_tony.cpp
@@ -20,7 +20,7 @@
using namespace TEN::Effects::Lara;
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
static BOSS_STRUCT BossData;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_tony.h b/TombEngine/Objects/TR3/Entity/tr3_tony.h
index 398cb37e5..2606a52a2 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_tony.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_tony.h
@@ -1,7 +1,7 @@
#pragma once
#include "Game/items.h"
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void InitialiseTony(short itemNumber);
void TonyControl(short itemNumber);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_trex.cpp b/TombEngine/Objects/TR3/Entity/tr3_trex.cpp
index 256ee4738..c96d26d90 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_trex.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_trex.cpp
@@ -15,7 +15,7 @@
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
constexpr auto TREX_ROAR_CHANCE = 0.015f;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_trex.h b/TombEngine/Objects/TR3/Entity/tr3_trex.h
index 7975f0b52..af6ba80f7 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_trex.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_trex.h
@@ -1,7 +1,7 @@
#pragma once
#include "Game/items.h"
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void LaraTRexDeath(ItemInfo* tRexItem, ItemInfo* laraItem);
void TRexControl(short itemNumber);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_tribesman.cpp b/TombEngine/Objects/TR3/Entity/tr3_tribesman.cpp
index f8abb0681..68f121572 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_tribesman.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_tribesman.cpp
@@ -20,7 +20,7 @@ using namespace TEN::Entities::Traps;
using namespace TEN::Math::Random;
using std::vector;
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
const auto TribesmanAxeBite = BiteInfo(Vector3(0.0f, 16.0f, 265.0f), 13);
const auto TribesmanDartBite1 = BiteInfo(Vector3(0.0f, 0.0f, -200.0f), 13);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_tribesman.h b/TombEngine/Objects/TR3/Entity/tr3_tribesman.h
index 72743252a..696518dea 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_tribesman.h
+++ b/TombEngine/Objects/TR3/Entity/tr3_tribesman.h
@@ -1,6 +1,6 @@
#pragma once
-namespace TEN::Entities::TR3
+namespace TEN::Entities::Creatures::TR3
{
void TribemanAxeControl(short itemNumber);
void TribemanDartsControl(short itemNumber);
diff --git a/TombEngine/Objects/TR3/tr3_objects.cpp b/TombEngine/Objects/TR3/tr3_objects.cpp
index c9dde913f..4cd5a68ec 100644
--- a/TombEngine/Objects/TR3/tr3_objects.cpp
+++ b/TombEngine/Objects/TR3/tr3_objects.cpp
@@ -35,7 +35,7 @@
#include "Objects/TR3/Vehicles/upv.h"
#include "Objects/TR3/Vehicles/rubber_boat.h"
-using namespace TEN::Entities::TR3;
+using namespace TEN::Entities::Creatures::TR3;
static void StartEntity(ObjectInfo* obj)
{
From 6fe5dfa425a968e8a99ab80ecac76b026ef9619a Mon Sep 17 00:00:00 2001
From: Sezz
Date: Sun, 21 Aug 2022 16:13:21 +1000
Subject: [PATCH 023/106] Minor organising
---
TombEngine/Objects/TR3/Entity/tr3_civvy.cpp | 65 +++++++++----------
TombEngine/Objects/TR3/Entity/tr3_cobra.cpp | 45 +++++++------
.../Objects/TR3/Entity/tr3_flamethrower.cpp | 63 ++++++++----------
3 files changed, 84 insertions(+), 89 deletions(-)
diff --git a/TombEngine/Objects/TR3/Entity/tr3_civvy.cpp b/TombEngine/Objects/TR3/Entity/tr3_civvy.cpp
index 7ffafd62a..be9f320fe 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_civvy.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_civvy.cpp
@@ -89,11 +89,10 @@ namespace TEN::Entities::Creatures::TR3
auto* item = &g_Level.Items[itemNumber];
auto* creature = GetCreatureInfo(item);
- short torsoX = 0;
- short torsoY = 0;
- short head = 0;
short angle = 0;
short tilt = 0;
+ auto extraHeadRot = Vector3Shrt::Zero;
+ auto extraTorsoRot = Vector3Shrt::Zero;
if (item->BoxNumber != NO_BOX && (g_Level.Boxes[item->BoxNumber].flags & BLOCKED))
{
@@ -119,18 +118,18 @@ namespace TEN::Entities::Creatures::TR3
AI_INFO AI;
CreatureAIInfo(item, &AI);
- AI_INFO laraAiInfo;
+ AI_INFO laraAI;
if (creature->Enemy == LaraItem)
{
- laraAiInfo.angle = AI.angle;
- laraAiInfo.distance = AI.distance;
+ laraAI.angle = AI.angle;
+ laraAI.distance = AI.distance;
}
else
{
int laraDz = LaraItem->Pose.Position.z - item->Pose.Position.z;
int laraDx = LaraItem->Pose.Position.x - item->Pose.Position.x;
- laraAiInfo.angle = phd_atan(laraDz, laraDx) - item->Pose.Orientation.y;
- laraAiInfo.distance = pow(laraDx, 2) + pow(laraDz, 2);
+ laraAI.angle = phd_atan(laraDz, laraDx) - item->Pose.Orientation.y;
+ laraAI.distance = pow(laraDx, 2) + pow(laraDz, 2);
}
GetCreatureMood(item, &AI, true);
@@ -150,7 +149,7 @@ namespace TEN::Entities::Creatures::TR3
auto* realEnemy = creature->Enemy;
creature->Enemy = LaraItem;
- if ((laraAiInfo.distance < CIVVY_AWARE_RANGE || item->HitStatus || TargetVisible(item, &laraAiInfo)) &&
+ if ((laraAI.distance < CIVVY_AWARE_RANGE || item->HitStatus || TargetVisible(item, &laraAI)) &&
!(item->AIBits & FOLLOW))
{
if (!creature->Alerted)
@@ -170,13 +169,13 @@ namespace TEN::Entities::Creatures::TR3
}
case CIVVY_STATE_IDLE:
- head = laraAiInfo.angle;
creature->MaxTurn = 0;
creature->Flags = 0;
+ extraHeadRot.y = laraAI.angle;
if (item->AIBits & GUARD)
{
- head = AIGuard(creature);
+ extraHeadRot.y = AIGuard(creature);
if (!(GetRandomControl() & 0xFF))
{
if (item->Animation.ActiveState == CIVVY_STATE_IDLE)
@@ -199,7 +198,7 @@ namespace TEN::Entities::Creatures::TR3
item->Animation.TargetState = CIVVY_STATE_RUN_FORWARD;
}
else if (creature->Mood == MoodType::Bored ||
- (item->AIBits & FOLLOW && (creature->ReachedGoal || laraAiInfo.distance > pow(SECTOR(2), 2))))
+ (item->AIBits & FOLLOW && (creature->ReachedGoal || laraAI.distance > pow(SECTOR(2), 2))))
{
if (item->Animation.RequiredState)
item->Animation.TargetState = item->Animation.RequiredState;
@@ -221,11 +220,11 @@ namespace TEN::Entities::Creatures::TR3
case CIVVY_STATE_WALK_FORWARD:
creature->MaxTurn = CIVVY_WALK_TURN_RATE_MAX;
- head = laraAiInfo.angle;
+ extraHeadRot.y = laraAI.angle;
if (item->AIBits & PATROL1)
{
- head = 0;
+ extraHeadRot.y = 0;
item->Animation.TargetState = CIVVY_STATE_WALK_FORWARD;
}
else if (creature->Mood == MoodType::Escape)
@@ -252,7 +251,7 @@ namespace TEN::Entities::Creatures::TR3
tilt = angle / 2;
if (AI.ahead)
- head = AI.angle;
+ extraHeadRot.y = AI.angle;
if (item->AIBits & GUARD)
item->Animation.TargetState = CIVVY_WAIT;
@@ -262,7 +261,7 @@ namespace TEN::Entities::Creatures::TR3
item->Animation.TargetState = CIVVY_STATE_IDLE;
break;
}
- else if ((item->AIBits & FOLLOW) && (creature->ReachedGoal || laraAiInfo.distance > pow(SECTOR(2), 2)))
+ else if ((item->AIBits & FOLLOW) && (creature->ReachedGoal || laraAI.distance > pow(SECTOR(2), 2)))
item->Animation.TargetState = CIVVY_STATE_IDLE;
else if (creature->Mood == MoodType::Bored)
item->Animation.TargetState = CIVVY_STATE_WALK_FORWARD;
@@ -273,11 +272,12 @@ namespace TEN::Entities::Creatures::TR3
case CIVVY_AIM0:
creature->MaxTurn = CIVVY_WALK_TURN_RATE_MAX;
+ creature->Flags = 0;
if (AI.ahead)
{
- torsoX = AI.xAngle;
- torsoY = AI.angle;
+ extraTorsoRot.x = AI.xAngle;
+ extraTorsoRot.y = AI.angle;
}
if (AI.bite && AI.distance < CIVVY_ATTACK0_RANGE)
@@ -285,16 +285,16 @@ namespace TEN::Entities::Creatures::TR3
else
item->Animation.TargetState = CIVVY_STATE_IDLE;
- creature->Flags = 0;
break;
case CIVVY_AIM1:
creature->MaxTurn = CIVVY_WALK_TURN_RATE_MAX;
+ creature->Flags = 0;
if (AI.ahead)
{
- torsoX = AI.xAngle;
- torsoY = AI.angle;
+ extraTorsoRot.x = AI.xAngle;
+ extraTorsoRot.y = AI.angle;
}
if (AI.ahead && AI.distance < CIVVY_ATTACK1_RANGE)
@@ -302,7 +302,6 @@ namespace TEN::Entities::Creatures::TR3
else
item->Animation.TargetState = CIVVY_STATE_IDLE;
- creature->Flags = 0;
break;
case CIVVY_AIM2:
@@ -311,8 +310,8 @@ namespace TEN::Entities::Creatures::TR3
if (AI.ahead)
{
- torsoX = AI.xAngle;
- torsoY = AI.angle;
+ extraTorsoRot.x = AI.xAngle;
+ extraTorsoRot.y = AI.angle;
}
if (AI.bite && AI.distance < CIVVY_ATTACK2_RANGE)
@@ -327,8 +326,8 @@ namespace TEN::Entities::Creatures::TR3
if (AI.ahead)
{
- torsoX = AI.xAngle;
- torsoY = AI.angle;
+ extraTorsoRot.x = AI.xAngle;
+ extraTorsoRot.y = AI.angle;
}
if (!creature->Flags && item->TestBits(JointBitType::Touch, CivvyAttackJoints))
@@ -346,8 +345,8 @@ namespace TEN::Entities::Creatures::TR3
if (AI.ahead)
{
- torsoX = AI.xAngle;
- torsoY = AI.angle;
+ extraTorsoRot.x = AI.xAngle;
+ extraTorsoRot.y = AI.angle;
}
if (!creature->Flags && item->TestBits(JointBitType::Touch, CivvyAttackJoints))
@@ -368,8 +367,8 @@ namespace TEN::Entities::Creatures::TR3
if (AI.ahead)
{
- torsoX = AI.xAngle;
- torsoY = AI.angle;
+ extraTorsoRot.x = AI.xAngle;
+ extraTorsoRot.y = AI.angle;
}
if (creature->Flags != 2 && item->TestBits(JointBitType::Touch, CivvyAttackJoints))
@@ -385,9 +384,9 @@ namespace TEN::Entities::Creatures::TR3
}
CreatureTilt(item, tilt);
- CreatureJoint(item, 0, torsoY);
- CreatureJoint(item, 1, torsoX);
- CreatureJoint(item, 2, head);
+ CreatureJoint(item, 0, extraTorsoRot.y);
+ CreatureJoint(item, 1, extraTorsoRot.x);
+ CreatureJoint(item, 2, extraHeadRot.y);
if (item->Animation.ActiveState < CIVVY_DEATH)
{
diff --git a/TombEngine/Objects/TR3/Entity/tr3_cobra.cpp b/TombEngine/Objects/TR3/Entity/tr3_cobra.cpp
index aaff1fb58..322e88500 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_cobra.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_cobra.cpp
@@ -23,7 +23,7 @@ namespace TEN::Entities::Creatures::TR3
constexpr auto COBRA_AWARE_RANGE = SQUARE(SECTOR(1.5f));
constexpr auto COBRA_SLEEP_RANGE = SQUARE(SECTOR(2.5f));
- constexpr auto PLAYER_DISTURB_VELOCITY = 15;
+ constexpr auto COBRA_DISTURBANCE_VELOCITY = 15;
constexpr auto COBRA_SLEEP_FRAME = 45;
const auto CobraBite = BiteInfo(Vector3::Zero, 13);
@@ -41,12 +41,17 @@ namespace TEN::Entities::Creatures::TR3
enum CobraAnim
{
COBRA_ANIM_IDLE = 0,
- COBRA_ANIM_WAKE_UP = 1,
+ COBRA_ANIM_SLEEP_TO_IDLE = 1,
COBRA_ANIM_IDLE_TO_SLEEP = 2,
COBRA_ANIM_BITE_ATTACK = 3,
COBRA_ANIM_DEATH = 4
};
+ enum CobraFlags
+ {
+ COBRA_FLAG_ATTACKING = (1 << 0)
+ };
+
void InitialiseCobra(short itemNumber)
{
auto* item = &g_Level.Items[itemNumber];
@@ -83,19 +88,23 @@ namespace TEN::Entities::Creatures::TR3
GetCreatureMood(item, &AI, 1);
CreatureMood(item, &AI, 1);
- bool enemyMoving = false;
- bool enemyVisible = false;
- if (creature->Enemy && (GlobalCounter & 2))
- {
- auto src = GameVector(creature->Enemy->Pose.Position, creature->Enemy->RoomNumber);
- auto dest = GameVector(item->Pose.Position, item->RoomNumber);
- enemyVisible = LOS(&src, &dest);
+ bool isEnemyMoving = false;
+ bool isEnemyVisible = false;
- enemyMoving = creature->Enemy->Animation.Velocity.z > PLAYER_DISTURB_VELOCITY ||
- abs(creature->Enemy->Animation.Velocity.y) > PLAYER_DISTURB_VELOCITY;
+ if (creature->Enemy != nullptr && (GlobalCounter & 2))
+ {
+ auto origin = GameVector(creature->Enemy->Pose.Position, creature->Enemy->RoomNumber);
+ auto target = GameVector(item->Pose.Position, item->RoomNumber);
+ isEnemyVisible = LOS(&origin, &target);
+
+ if (creature->Enemy->Animation.Velocity.z > COBRA_DISTURBANCE_VELOCITY ||
+ abs(creature->Enemy->Animation.Velocity.y) > COBRA_DISTURBANCE_VELOCITY)
+ {
+ isEnemyMoving = true;
+ }
}
- if (enemyVisible && item->Animation.ActiveState != COBRA_STATE_SLEEP)
+ if (isEnemyVisible && item->Animation.ActiveState != COBRA_STATE_SLEEP)
{
creature->Target.x = creature->Enemy->Pose.Position.x;
creature->Target.z = creature->Enemy->Pose.Position.z;
@@ -118,12 +127,10 @@ namespace TEN::Entities::Creatures::TR3
creature->Flags = 0;
if (AI.distance > COBRA_SLEEP_RANGE)
- {
item->Animation.TargetState = COBRA_STATE_SLEEP;
- }
- else if (creature->Enemy->HitPoints > 0 && enemyVisible &&
- ((AI.ahead && AI.distance < COBRA_ATTACK_RANGE && AI.verticalDistance <= GetBoundsAccurate(item)->Height()) ||
- item->HitStatus || enemyMoving))
+ else if (creature->Enemy->HitPoints > 0 && isEnemyVisible &&
+ ((AI.ahead && AI.distance < COBRA_ATTACK_RANGE && AI.verticalDistance <= GetBoundsAccurate(item)->Height()) ||
+ item->HitStatus || isEnemyMoving))
{
item->Animation.TargetState = COBRA_STATE_ATTACK;
}
@@ -148,12 +155,12 @@ namespace TEN::Entities::Creatures::TR3
break;
case COBRA_STATE_ATTACK:
- if (creature->Flags != 1 &&
+ if (!(creature->Flags & COBRA_FLAG_ATTACKING) &&
item->TestBits(JointBitType::Touch, CobraAttackJoints))
{
DoDamage(creature->Enemy, COBRA_BITE_ATTACK_DAMAGE);
CreatureEffect(item, CobraBite, DoBloodSplat);
- creature->Flags = 1;
+ creature->Flags |= COBRA_FLAG_ATTACKING;
if (creature->Enemy->IsLara())
GetLaraInfo(creature->Enemy)->PoisonPotency += COBRA_BITE_POISON_POTENCY;
diff --git a/TombEngine/Objects/TR3/Entity/tr3_flamethrower.cpp b/TombEngine/Objects/TR3/Entity/tr3_flamethrower.cpp
index 7531abd3e..98b2038f7 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_flamethrower.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_flamethrower.cpp
@@ -44,32 +44,27 @@ namespace TEN::Entities::Creatures::TR3
auto* item = &g_Level.Items[itemNumber];
auto* creature = GetCreatureInfo(item);
- short torsoX = 0;
- short torsoY = 0;
short angle = 0;
short tilt = 0;
- short head = 0;
+ auto extraHeadRot = Vector3Shrt::Zero;
+ auto extraTorsoRot = Vector3Shrt::Zero;
auto pos = Vector3Int(FlamethrowerBite.Position);
GetJointAbsPosition(item, &pos, FlamethrowerBite.meshNum);
- int random = GetRandomControl();
+ int randomInt = GetRandomControl();
if (item->Animation.ActiveState != 6 && item->Animation.ActiveState != 11)
{
- TriggerDynamicLight(pos.x, pos.y, pos.z, (random & 3) + 6, 24 - ((random / 16) & 3), 16 - ((random / 64) & 3), random & 3);
+ TriggerDynamicLight(pos.x, pos.y, pos.z, (randomInt & 3) + 6, 24 - ((randomInt / 16) & 3), 16 - ((randomInt / 64) & 3), randomInt & 3);
TriggerPilotFlame(itemNumber, 9);
}
else
- TriggerDynamicLight(pos.x, pos.y, pos.z, (random & 3) + 10, 31 - ((random / 16) & 3), 24 - ((random / 64) & 3), random & 7);
+ TriggerDynamicLight(pos.x, pos.y, pos.z, (randomInt & 3) + 10, 31 - ((randomInt / 16) & 3), 24 - ((randomInt / 64) & 3), randomInt & 7);
if (item->HitPoints <= 0)
{
if (item->Animation.ActiveState != 7)
- {
- item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex + 19;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = 7;
- }
+ SetAnimation(item, 19);
}
else
{
@@ -84,9 +79,8 @@ namespace TEN::Entities::Creatures::TR3
ItemInfo* target = nullptr;
int minDistance = INT_MAX;
- for (int i = 0; i < ActiveCreatures.size(); i++)
+ for (auto& currentCreature : ActiveCreatures)
{
- auto* currentCreature = ActiveCreatures[i];
if (currentCreature->ItemNumber == NO_ITEM || currentCreature->ItemNumber == itemNumber)
continue;
@@ -149,11 +143,11 @@ namespace TEN::Entities::Creatures::TR3
case 1:
creature->MaxTurn = 0;
creature->Flags = 0;
- head = laraAI.angle;
+ extraHeadRot.y = laraAI.angle;
if (item->AIBits & GUARD)
{
- head = AIGuard(creature);
+ extraHeadRot.y = AIGuard(creature);
if (TestProbability(0.008f))
item->Animation.TargetState = 4;
@@ -179,11 +173,11 @@ namespace TEN::Entities::Creatures::TR3
break;
case 4:
- head = laraAI.angle;
+ extraHeadRot.y = laraAI.angle;
if (item->AIBits & GUARD)
{
- head = AIGuard(creature);
+ extraHeadRot.y = AIGuard(creature);
if (TestProbability(0.008f))
item->Animation.TargetState = 1;
@@ -202,17 +196,12 @@ namespace TEN::Entities::Creatures::TR3
break;
case 2:
- creature->Flags = 0;
creature->MaxTurn = ANGLE(5.0f);
- head = laraAI.angle;
+ creature->Flags = 0;
+ extraHeadRot.y = laraAI.angle;
if (item->AIBits & GUARD)
- {
- item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex + 12;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = 1;
- item->Animation.TargetState = 1;
- }
+ SetAnimation(item, 12);
else if (item->AIBits & PATROL1)
item->Animation.TargetState = 2;
else if (creature->Mood == MoodType::Escape)
@@ -237,8 +226,8 @@ namespace TEN::Entities::Creatures::TR3
if (AI.ahead)
{
- torsoX = AI.xAngle;
- torsoY = AI.angle;
+ extraTorsoRot.x = AI.xAngle;
+ extraTorsoRot.y = AI.angle;
if (Targetable(item, &AI) &&
AI.distance < pow(SECTOR(4), 2) &&
@@ -257,8 +246,8 @@ namespace TEN::Entities::Creatures::TR3
if (AI.ahead)
{
- torsoX = AI.xAngle;
- torsoY = AI.angle;
+ extraTorsoRot.x = AI.xAngle;
+ extraTorsoRot.y = AI.angle;
if (Targetable(item, &AI) &&
AI.distance < pow(SECTOR(4), 2) &&
@@ -278,8 +267,8 @@ namespace TEN::Entities::Creatures::TR3
if (AI.ahead)
{
- torsoX = AI.xAngle;
- torsoY = AI.angle;
+ extraTorsoRot.x = AI.xAngle;
+ extraTorsoRot.y = AI.angle;
if (Targetable(item, &AI) &&
AI.distance < pow(SECTOR(4), 2) &&
@@ -313,12 +302,12 @@ namespace TEN::Entities::Creatures::TR3
if (AI.ahead)
{
- torsoX = AI.xAngle;
- torsoY = AI.angle;
+ extraTorsoRot.x = AI.xAngle;
+ extraTorsoRot.y = AI.angle;
if (Targetable(item, &AI) &&
AI.distance < pow(SECTOR(4), 2) &&
- (realEnemy != LaraItem || creature->HurtByLara))
+ (!realEnemy->IsLara() || creature->HurtByLara))
{
item->Animation.TargetState = 6;
}
@@ -345,9 +334,9 @@ namespace TEN::Entities::Creatures::TR3
}
CreatureTilt(item, tilt);
- CreatureJoint(item, 0, torsoY);
- CreatureJoint(item, 1, torsoX);
- CreatureJoint(item, 2, head);
+ CreatureJoint(item, 0, extraTorsoRot.y);
+ CreatureJoint(item, 1, extraTorsoRot.x);
+ CreatureJoint(item, 2, extraHeadRot.y);
CreatureAnimation(itemNumber, angle, 0);
}
From d568187ce9d885158b24769cf2fb32013cd52960 Mon Sep 17 00:00:00 2001
From: Sezz
Date: Sun, 21 Aug 2022 19:08:53 +1000
Subject: [PATCH 024/106] Cleanup
---
TombEngine/Game/itemdata/creature_info.h | 71 ++++++------
.../Objects/TR3/Entity/tr3_scuba_diver.cpp | 78 ++++++-------
TombEngine/Objects/TR3/Entity/tr3_shiva.cpp | 106 +++++++++---------
TombEngine/Specific/phd_global.h | 9 ++
4 files changed, 129 insertions(+), 135 deletions(-)
diff --git a/TombEngine/Game/itemdata/creature_info.h b/TombEngine/Game/itemdata/creature_info.h
index 85cf640ff..32c06190b 100644
--- a/TombEngine/Game/itemdata/creature_info.h
+++ b/TombEngine/Game/itemdata/creature_info.h
@@ -15,7 +15,7 @@ struct BOX_NODE
enum ZoneType : char
{
ZONE_NULL = -1, // default zone
- ZONE_SKELLY = 0,
+ ZONE_SKELLY,
ZONE_BASIC,
ZONE_FLYER,
ZONE_HUMAN_CLASSIC,
@@ -27,8 +27,8 @@ enum ZoneType : char
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_SOPHIALEE, // dont want sophia to go down again.
+ ZONE_APE, // only half block climb
ZONE_HUMAN_LONGJUMP_AND_MONKEY,
};
@@ -49,18 +49,19 @@ struct LOTInfo
int RequiredBox;
short Fly;
- bool CanJump;
- bool CanMonkey;
- bool IsJumping;
- bool IsMonkeying;
- bool IsAmphibious;
+ bool CanJump = false;
+ bool CanMonkey = false;
+ bool IsJumping = false;
+ bool IsMonkeying = false;
+ bool IsAmphibious = false;
- Vector3Int Target;
- ZoneType Zone;
+ Vector3Int Target = Vector3Int::Zero;
+ ZoneType Zone = ZoneType::ZONE_NULL;
};
enum class MoodType
{
+ None,
Bored,
Attack,
Escape,
@@ -77,38 +78,36 @@ enum class CreatureAIPriority
struct CreatureInfo
{
- short ItemNumber;
+ short ItemNumber = -1;
- short MaxTurn;
- short JointRotation[4];
- bool HeadLeft;
- bool HeadRight;
+ LOTInfo LOT = {};
+ MoodType Mood = MoodType::None;
+ ItemInfo* Enemy = nullptr;
+ ItemInfo* AITarget = nullptr;
+ short AITargetNumber = -1;
+ Vector3Int Target = Vector3Int::Zero;
- bool Patrol; // Unused?
- bool Alerted;
- bool Friendly;
- bool HurtByLara;
- bool Poisoned;
- bool JumpAhead;
- bool MonkeySwingAhead;
- bool ReachedGoal;
+ short MaxTurn = 0;
+ short JointRotation[4] = {};
+ bool HeadLeft = false;
+ bool HeadRight = false;
+ bool Patrol = false; // Unused?
+ bool Alerted = false;
+ bool Friendly = false;
+ bool HurtByLara = false;
+ bool Poisoned = false;
+ bool JumpAhead = false;
+ bool MonkeySwingAhead = false;
+ bool ReachedGoal = false;
+
+ short FiredWeapon;
short Tosspad;
short LocationAI;
- short FiredWeapon;
-
- LOTInfo LOT;
- MoodType Mood;
- ItemInfo* Enemy;
- short AITargetNumber;
- ItemInfo* AITarget;
- short Pad; // Unused?
- Vector3Int Target;
+ short Flags = 0;
#ifdef CREATURE_AI_PRIORITY_OPTIMIZATION
- CreatureAIPriority Priority;
- size_t FramesSinceLOTUpdate;
+ CreatureAIPriority Priority = CreatureAIPriority::None;
+ size_t FramesSinceLOTUpdate = 0;
#endif
-
- short Flags;
};
diff --git a/TombEngine/Objects/TR3/Entity/tr3_scuba_diver.cpp b/TombEngine/Objects/TR3/Entity/tr3_scuba_diver.cpp
index c290527e4..095ee262e 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_scuba_diver.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_scuba_diver.cpp
@@ -60,23 +60,23 @@ namespace TEN::Entities::Creatures::TR3
static void ShootHarpoon(ItemInfo* item, Vector3Int pos, short velocity, short yRot, short roomNumber)
{
short harpoonItemNumber = CreateItem();
- if (harpoonItemNumber != NO_ITEM)
- {
- auto* harpoonItem = &g_Level.Items[harpoonItemNumber];
+ if (harpoonItemNumber == NO_ITEM)
+ return;
- harpoonItem->ObjectNumber = ID_SCUBA_HARPOON;
- harpoonItem->RoomNumber = item->RoomNumber;
- harpoonItem->Pose.Position = pos;
+ auto* harpoonItem = &g_Level.Items[harpoonItemNumber];
- InitialiseItem(harpoonItemNumber);
+ harpoonItem->ObjectNumber = ID_SCUBA_HARPOON;
+ harpoonItem->RoomNumber = item->RoomNumber;
+ harpoonItem->Pose.Position = pos;
- harpoonItem->Animation.Velocity.z = 150;
- harpoonItem->Pose.Orientation.x = 0;
- harpoonItem->Pose.Orientation.y = yRot;
+ InitialiseItem(harpoonItemNumber);
- AddActiveItem(harpoonItemNumber);
- harpoonItem->Status = ITEM_ACTIVE;
- }
+ harpoonItem->Animation.Velocity.z = 150.0f;
+ harpoonItem->Pose.Orientation.x = 0;
+ harpoonItem->Pose.Orientation.y = yRot;
+
+ AddActiveItem(harpoonItemNumber);
+ harpoonItem->Status = ITEM_ACTIVE;
}
void ScubaHarpoonControl(short itemNumber)
@@ -91,14 +91,7 @@ namespace TEN::Entities::Creatures::TR3
}
else
{
- int ox = item->Pose.Position.x;
- int oz = item->Pose.Position.z;
-
- int velocity = item->Animation.Velocity.z * phd_cos(item->Pose.Orientation.x);
-
- item->Pose.Position.z += velocity * phd_cos(item->Pose.Orientation.y);
- item->Pose.Position.x += velocity * phd_sin(item->Pose.Orientation.y);
- item->Pose.Position.y += -item->Animation.Velocity.z * phd_sin(item->Pose.Orientation.x);
+ TranslateItem(item, item->Pose.Orientation, item->Animation.Velocity.z);
auto probe = GetCollision(item);
@@ -123,7 +116,8 @@ namespace TEN::Entities::Creatures::TR3
short head = 0;
short neck = 0;
- int waterHeight;
+ int waterHeight = 0;
+
if (item->HitPoints <= 0)
{
if (item->Animation.ActiveState != SDIVER_STATE_DEATH)
@@ -140,22 +134,23 @@ namespace TEN::Entities::Creatures::TR3
GetCreatureMood(item, &AI, false);
CreatureMood(item, &AI, false);
- GameVector origin;
- GameVector target;
bool shoot = false;
-
if (Lara.Control.WaterStatus == WaterStatus::Dry)
{
- origin.x = item->Pose.Position.x;
- origin.y = item->Pose.Position.y - CLICK(1);
- origin.z = item->Pose.Position.z;
- origin.roomNumber = item->RoomNumber;
-
- target.x = LaraItem->Pose.Position.x;
- target.y = LaraItem->Pose.Position.y - (LARA_HEIGHT - 150);
- target.z = LaraItem->Pose.Position.z;
+ auto origin = GameVector(
+ item->Pose.Position.x,
+ item->Pose.Position.y - CLICK(1),
+ item->Pose.Position.z,
+ item->RoomNumber
+ );
+ auto target = GameVector(
+ LaraItem->Pose.Position.x,
+ LaraItem->Pose.Position.y - (LARA_HEIGHT - 150),
+ LaraItem->Pose.Position.z
+ );
shoot = LOS(&origin, &target);
+
if (shoot)
creature->Target = LaraItem->Pose.Position;
@@ -164,19 +159,11 @@ namespace TEN::Entities::Creatures::TR3
}
else if (AI.angle > -ANGLE(45.0f) && AI.angle < ANGLE(45.0f))
{
- origin.x = item->Pose.Position.x;
- origin.y = item->Pose.Position.y;
- origin.z = item->Pose.Position.z;
- origin.roomNumber = item->RoomNumber;
-
- target.x = LaraItem->Pose.Position.x;
- target.y = LaraItem->Pose.Position.y;
- target.z = LaraItem->Pose.Position.z;
-
+ auto origin = GameVector(item->Pose.Position, item->RoomNumber);
+ auto target = GameVector(LaraItem->Pose.Position);
+
shoot = LOS(&origin, &target);
}
- else
- shoot = false;
angle = CreatureTurn(item, creature->MaxTurn);
waterHeight = GetWaterSurface(item->Pose.Position.x, item->Pose.Position.y, item->Pose.Position.z, item->RoomNumber) + SECTOR(0.5f);
@@ -202,7 +189,7 @@ namespace TEN::Entities::Creatures::TR3
break;
case SDIVER_STATE_SWIM_AIM:
- creature->Flags = NULL;
+ creature->Flags = 0;
if (shoot)
neck = -AI.angle;
@@ -270,7 +257,6 @@ namespace TEN::Entities::Creatures::TR3
}
break;
-
}
}
diff --git a/TombEngine/Objects/TR3/Entity/tr3_shiva.cpp b/TombEngine/Objects/TR3/Entity/tr3_shiva.cpp
index b5fd5f8cb..0db04d15f 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_shiva.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_shiva.cpp
@@ -208,15 +208,15 @@ namespace TEN::Entities::Creatures::TR3
return;
auto* item = &g_Level.Items[itemNumber];
- auto* shiva = GetCreatureInfo(item);
+ auto* creature = GetCreatureInfo(item);
- auto pos = Vector3Int(0, 0, 256);
- bool laraAlive = LaraItem->HitPoints > 0;
+ auto pos = Vector3Int(0, 0, CLICK(1));
+ bool isLaraAlive = LaraItem->HitPoints > 0;
- Vector3Shrt extraHeadRot;
- Vector3Shrt extraTorsoRot;
short angle = 0;
short tilt = 0;
+ Vector3Shrt extraHeadRot = Vector3Shrt::Zero;
+ Vector3Shrt extraTorsoRot = Vector3Shrt::Zero;
if (item->HitPoints <= 0)
{
@@ -235,13 +235,13 @@ namespace TEN::Entities::Creatures::TR3
GetCreatureMood(item, &AI, true);
CreatureMood(item, &AI, true);
- if (shiva->Mood == MoodType::Escape)
+ if (creature->Mood == MoodType::Escape)
{
- shiva->Target.x = LaraItem->Pose.Position.x;
- shiva->Target.z = LaraItem->Pose.Position.z;
+ creature->Target.x = LaraItem->Pose.Position.x;
+ creature->Target.z = LaraItem->Pose.Position.z;
}
- angle = CreatureTurn(item, shiva->MaxTurn);
+ angle = CreatureTurn(item, creature->MaxTurn);
if (item->Animation.ActiveState != SHIVA_STATE_INACTIVE)
item->MeshBits = ALL_JOINT_BITS;
@@ -251,15 +251,15 @@ namespace TEN::Entities::Creatures::TR3
switch (item->Animation.ActiveState)
{
case SHIVA_STATE_INACTIVE:
- shiva->MaxTurn = 0;
+ creature->MaxTurn = 0;
- if (!shiva->Flags)
+ if (!creature->Flags)
{
if (!item->MeshBits)
effectMesh = 0;
item->MeshBits = (item->MeshBits * 2) + 1;
- shiva->Flags = 1;
+ creature->Flags = 1;
GetJointAbsPosition(item, &pos, effectMesh++);
TriggerExplosionSparks(pos.x, pos.y, pos.z, 2, 0, 0, item->RoomNumber);
@@ -267,45 +267,45 @@ namespace TEN::Entities::Creatures::TR3
}
else
- shiva->Flags--;
+ creature->Flags--;
if (item->MeshBits == 0x7FFFFFFF)
{
item->Animation.TargetState = SHIVA_STATE_IDLE;
- shiva->Flags = -45;
+ creature->Flags = -45;
effectMesh = 0;
}
break;
case SHIVA_STATE_IDLE:
- shiva->MaxTurn = 0;
+ creature->MaxTurn = 0;
if (AI.ahead)
extraHeadRot.y = AI.angle;
- if (shiva->Flags < 0)
+ if (creature->Flags < 0)
{
- shiva->Flags++;
+ creature->Flags++;
TriggerShivaSmoke(item->Pose.Position.x + (GetRandomControl() & 0x5FF) - 0x300, pos.y - (GetRandomControl() & 0x5FF), item->Pose.Position.z + (GetRandomControl() & 0x5FF) - 0x300, 1);
break;
}
- if (shiva->Flags == 1)
- shiva->Flags = 0;
+ if (creature->Flags == 1)
+ creature->Flags = 0;
- if (shiva->Mood == MoodType::Escape)
+ if (creature->Mood == MoodType::Escape)
{
int x = item->Pose.Position.x + SECTOR(1) * phd_sin(item->Pose.Orientation.y + ANGLE(180.0f));
int z = item->Pose.Position.z + SECTOR(1) * phd_cos(item->Pose.Orientation.y + ANGLE(180.0f));
auto box = GetCollision(x, item->Pose.Position.y, z, item->RoomNumber).BottomBlock->Box;
- if (box != NO_BOX && !(g_Level.Boxes[box].flags & BLOCKABLE) && !shiva->Flags)
+ if (box != NO_BOX && !(g_Level.Boxes[box].flags & BLOCKABLE) && !creature->Flags)
item->Animation.TargetState = SHIVA_STATE_WALK_BACK;
else
item->Animation.TargetState = SHIVA_STATE_GUARD_IDLE;
}
- else if (shiva->Mood == MoodType::Bored)
+ else if (creature->Mood == MoodType::Bored)
{
if (TestProbability(0.0325f))
item->Animation.TargetState = SHIVA_STATE_WALK_FORWARD;
@@ -313,17 +313,17 @@ namespace TEN::Entities::Creatures::TR3
else if (AI.bite && AI.distance < pow(SECTOR(1.25f), 2))
{
item->Animation.TargetState = SHIVA_STATE_GRAB_ATTACK;
- shiva->Flags = 0;
+ creature->Flags = 0;
}
else if (AI.bite && AI.distance < pow(SECTOR(4) / 3, 2))
{
item->Animation.TargetState = SHIVA_STATE_DOWNWARD_ATTACK;
- shiva->Flags = 0;
+ creature->Flags = 0;
}
else if (item->HitStatus && AI.ahead)
{
item->Animation.TargetState = SHIVA_STATE_GUARD_IDLE;
- shiva->Flags = 4;
+ creature->Flags = 4;
}
else
item->Animation.TargetState = SHIVA_STATE_WALK_FORWARD;
@@ -331,103 +331,103 @@ namespace TEN::Entities::Creatures::TR3
break;
case SHIVA_STATE_GUARD_IDLE:
- shiva->MaxTurn = 0;
+ creature->MaxTurn = 0;
if (AI.ahead)
extraHeadRot.y = AI.angle;
- if (item->HitStatus || shiva->Mood == MoodType::Escape)
- shiva->Flags = 4;
+ if (item->HitStatus || creature->Mood == MoodType::Escape)
+ creature->Flags = 4;
if (AI.bite && AI.distance < pow(SECTOR(4) / 3, 2) ||
(item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase &&
- !shiva->Flags) ||
+ !creature->Flags) ||
!AI.ahead)
{
item->Animation.TargetState = SHIVA_STATE_IDLE;
- shiva->Flags = 0;
+ creature->Flags = 0;
}
- else if (shiva->Flags)
+ else if (creature->Flags)
item->Animation.TargetState = SHIVA_STATE_GUARD_IDLE;
if (item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase &&
- shiva->Flags > 1)
+ creature->Flags > 1)
{
- shiva->Flags -= 2;
+ creature->Flags -= 2;
}
break;
case SHIVA_STATE_WALK_FORWARD:
- shiva->MaxTurn = SHIVA_WALK_TURN_RATE_MAX;
+ creature->MaxTurn = SHIVA_WALK_TURN_RATE_MAX;
if (AI.ahead)
extraHeadRot.y = AI.angle;
- if (shiva->Mood == MoodType::Escape)
+ if (creature->Mood == MoodType::Escape)
item->Animation.TargetState = SHIVA_STATE_IDLE;
- else if (shiva->Mood == MoodType::Bored)
+ else if (creature->Mood == MoodType::Bored)
item->Animation.TargetState = SHIVA_STATE_IDLE;
else if (AI.bite && AI.distance < pow(SECTOR(4) / 3, 2))
{
item->Animation.TargetState = SHIVA_STATE_IDLE;
- shiva->Flags = 0;
+ creature->Flags = 0;
}
else if (item->HitStatus)
{
item->Animation.TargetState = SHIVA_STATE_WALK_FORWARD_GUARDING;
- shiva->Flags = 4;
+ creature->Flags = 4;
}
break;
case SHIVA_STATE_WALK_FORWARD_GUARDING:
- shiva->MaxTurn = SHIVA_WALK_TURN_RATE_MAX;
+ creature->MaxTurn = SHIVA_WALK_TURN_RATE_MAX;
if (AI.ahead)
extraHeadRot.y = AI.angle;
if (item->HitStatus)
- shiva->Flags = 4;
+ creature->Flags = 4;
if (AI.bite && AI.distance < pow(SECTOR(1.25f), 2) ||
(item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase &&
- !shiva->Flags))
+ !creature->Flags))
{
item->Animation.TargetState = SHIVA_STATE_WALK_FORWARD;
- shiva->Flags = 0;
+ creature->Flags = 0;
}
- else if (shiva->Flags)
+ else if (creature->Flags)
item->Animation.TargetState = SHIVA_STATE_WALK_FORWARD_GUARDING;
if (item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase)
- shiva->Flags = 0;
+ creature->Flags = 0;
break;
case SHIVA_STATE_WALK_BACK:
- shiva->MaxTurn = SHIVA_WALK_TURN_RATE_MAX;
+ creature->MaxTurn = SHIVA_WALK_TURN_RATE_MAX;
if (AI.ahead)
extraHeadRot.y = AI.angle;
if (AI.ahead && AI.distance < pow(SECTOR(4) / 3, 2) ||
(item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase &&
- !shiva->Flags))
+ !creature->Flags))
{
item->Animation.TargetState = SHIVA_STATE_IDLE;
}
else if (item->HitStatus)
{
item->Animation.TargetState = SHIVA_STATE_IDLE;
- shiva->Flags = 4;
+ creature->Flags = 4;
}
break;
case SHIVA_STATE_GRAB_ATTACK:
- shiva->MaxTurn = SHIVA_ATTACK_TURN_RATE_MAX;
+ creature->MaxTurn = SHIVA_ATTACK_TURN_RATE_MAX;
if (AI.ahead)
{
@@ -435,22 +435,22 @@ namespace TEN::Entities::Creatures::TR3
extraTorsoRot = Vector3Shrt(AI.xAngle, AI.angle, 0);
}
- ShivaDamage(item, shiva, SHIVA_GRAB_ATTACK_DAMAGE);
+ ShivaDamage(item, creature, SHIVA_GRAB_ATTACK_DAMAGE);
break;
case SHIVA_STATE_DOWNWARD_ATTACK:
- shiva->MaxTurn = SHIVA_ATTACK_TURN_RATE_MAX;
+ creature->MaxTurn = SHIVA_ATTACK_TURN_RATE_MAX;
extraHeadRot.y = AI.angle;
extraTorsoRot.y = AI.angle;
if (AI.xAngle > 0)
extraTorsoRot.x = AI.xAngle;
- ShivaDamage(item, shiva, SHIVA_DOWNWARD_ATTACK_DAMAGE);
+ ShivaDamage(item, creature, SHIVA_DOWNWARD_ATTACK_DAMAGE);
break;
case SHIVA_STATE_KILL:
- shiva->MaxTurn = 0;
+ creature->MaxTurn = 0;
extraHeadRot = Vector3Shrt::Zero;
extraTorsoRot = Vector3Shrt::Zero;
@@ -467,7 +467,7 @@ namespace TEN::Entities::Creatures::TR3
}
// Dispatch kill animation.
- if (laraAlive && LaraItem->HitPoints <= 0)
+ if (isLaraAlive && LaraItem->HitPoints <= 0)
{
item->Animation.TargetState = SHIVA_STATE_KILL;
diff --git a/TombEngine/Specific/phd_global.h b/TombEngine/Specific/phd_global.h
index 2deef2cef..44b22b53c 100644
--- a/TombEngine/Specific/phd_global.h
+++ b/TombEngine/Specific/phd_global.h
@@ -356,6 +356,15 @@ struct GameVector
this->boxNumber = boxNumber;
}
+ GameVector(Vector3Int& pos)
+ {
+ this->x = pos.x;
+ this->y = pos.y;
+ this->z = pos.z;
+ this->roomNumber = 0;
+ this->boxNumber = 0;
+ }
+
GameVector(Vector3Int& pos, short roomNumber)
{
this->x = pos.x;
From c714716f8d356fedeb6f705e7112c7e67dc1c65b Mon Sep 17 00:00:00 2001
From: Sezz
Date: Sun, 21 Aug 2022 20:06:32 +1000
Subject: [PATCH 025/106] Convert ZoneType enum to enum class
---
TombEngine/Game/control/box.cpp | 16 +--
TombEngine/Game/control/lot.cpp | 109 +++++++++---------
TombEngine/Game/itemdata/creature_info.h | 56 ++++-----
TombEngine/Game/people.cpp | 36 +++---
TombEngine/Objects/TR1/tr1_objects.cpp | 8 +-
.../Objects/TR2/Entity/tr2_sword_guardian.cpp | 4 +-
TombEngine/Objects/TR2/tr2_objects.cpp | 10 +-
TombEngine/Objects/TR3/tr3_objects.cpp | 6 +-
TombEngine/Objects/TR4/tr4_objects.cpp | 76 ++++++------
TombEngine/Objects/TR5/tr5_objects.cpp | 56 ++++-----
TombEngine/Specific/setup.cpp | 2 +-
TombEngine/Specific/setup.h | 10 +-
12 files changed, 195 insertions(+), 194 deletions(-)
diff --git a/TombEngine/Game/control/box.cpp b/TombEngine/Game/control/box.cpp
index 8e7e99e0e..0b6c24a1a 100644
--- a/TombEngine/Game/control/box.cpp
+++ b/TombEngine/Game/control/box.cpp
@@ -157,7 +157,7 @@ void CreatureYRot2(PHD_3DPOS* srcPos, short angle, short angleAdd)
bool SameZone(CreatureInfo* creature, ItemInfo* target)
{
- int* zone = g_Level.Zones[creature->LOT.Zone][FlipStatus].data();
+ int* zone = g_Level.Zones[(int)(int)creature->LOT.Zone][FlipStatus].data();
auto* item = &g_Level.Items[creature->ItemNumber];
auto* room = &g_Level.Rooms[item->RoomNumber];
@@ -455,7 +455,7 @@ int CreatureAnimation(short itemNumber, short angle, short tilt)
auto* creature = GetCreatureInfo(item);
auto* LOT = &creature->LOT;
- int* zone = g_Level.Zones[LOT->Zone][FlipStatus].data();
+ int* zone = g_Level.Zones[(int)LOT->Zone][FlipStatus].data();
int boxHeight;
if (item->BoxNumber != NO_BOX)
@@ -884,7 +884,7 @@ int ValidBox(ItemInfo* item, short zoneNumber, short boxNumber)
return false;
auto* creature = GetCreatureInfo(item);
- int* zone = g_Level.Zones[creature->LOT.Zone][FlipStatus].data();
+ int* zone = g_Level.Zones[(int)creature->LOT.Zone][FlipStatus].data();
if (creature->LOT.Fly == NO_FLYING && zone[boxNumber] != zoneNumber)
return false;
@@ -970,7 +970,7 @@ int UpdateLOT(LOTInfo* LOT, int depth)
int SearchLOT(LOTInfo* LOT, int depth)
{
- int* zone = g_Level.Zones[LOT->Zone][FlipStatus].data();
+ int* zone = g_Level.Zones[(int)LOT->Zone][FlipStatus].data();
int searchZone = zone[LOT->Head];
if (depth <= 0)
@@ -1375,7 +1375,7 @@ void FindAITargetObject(CreatureInfo* creature, short objectNumber)
if (aiObject->objectNumber == objectNumber && aiObject->triggerFlags == item->ItemFlags[3] && aiObject->roomNumber != NO_ROOM)
{
- int* zone = g_Level.Zones[creature->LOT.Zone][FlipStatus].data();
+ int* zone = g_Level.Zones[(int)creature->LOT.Zone][FlipStatus].data();
auto* room = &g_Level.Rooms[item->RoomNumber];
item->BoxNumber = GetSector(room, item->Pose.Position.x - room->x, item->Pose.Position.z - room->z)->Box;
@@ -1435,7 +1435,7 @@ void CreatureAIInfo(ItemInfo* item, AI_INFO* AI)
creature->Enemy = LaraItem;
}
- int* zone = g_Level.Zones[creature->LOT.Zone][FlipStatus].data();
+ int* zone = g_Level.Zones[(int)creature->LOT.Zone][FlipStatus].data();
auto* room = &g_Level.Rooms[item->RoomNumber];
item->BoxNumber = NO_BOX;
@@ -1457,8 +1457,8 @@ void CreatureAIInfo(ItemInfo* item, AI_INFO* AI)
// This prevents enemies from running to Lara and attacking nothing when she is hanging or shimmying. -- Lwmte, 27.06.22
bool reachable = false;
- if (object->zoneType == ZoneType::ZONE_FLYER ||
- (object->zoneType == ZoneType::ZONE_WATER && TestEnvironment(RoomEnvFlags::ENV_FLAG_WATER, item->RoomNumber)))
+ if (object->ZoneType == ZoneType::Flyer ||
+ (object->ZoneType == ZoneType::Water && TestEnvironment(RoomEnvFlags::ENV_FLAG_WATER, item->RoomNumber)))
{
reachable = true; // If NPC is flying or swimming in water, always reach Lara
}
diff --git a/TombEngine/Game/control/lot.cpp b/TombEngine/Game/control/lot.cpp
index 712558575..83cf70a2d 100644
--- a/TombEngine/Game/control/lot.cpp
+++ b/TombEngine/Game/control/lot.cpp
@@ -112,15 +112,15 @@ void DisableEntityAI(short itemNumber)
item->Data = nullptr;
}
-void InitialiseSlot(short itemNum, short slot, bool makeTarget)
+void InitialiseSlot(short itemNumber, short slot, bool makeTarget)
{
- auto* item = &g_Level.Items[itemNum];
- auto* obj = &Objects[item->ObjectNumber];
-
+ auto* item = &g_Level.Items[itemNumber];
+ auto* object = &Objects[item->ObjectNumber];
item->Data = CreatureInfo();
auto* creature = GetCreatureInfo(item);
- InitialiseLOTarray(itemNum);
- creature->ItemNumber = itemNum;
+
+ InitialiseLOTarray(itemNumber);
+ creature->ItemNumber = itemNumber;
creature->Mood = MoodType::Bored;
creature->JointRotation[0] = 0;
creature->JointRotation[1] = 0;
@@ -136,12 +136,12 @@ void InitialiseSlot(short itemNum, short slot, bool makeTarget)
creature->MonkeySwingAhead = false;
creature->LOT.CanJump = false;
creature->LOT.CanMonkey = false;
- creature->LOT.IsAmphibious = false; // only the crocodile can go water and land. (default: true)
+ creature->LOT.IsAmphibious = false; // True for crocodile by default as the only the crocodile that can move in water and on land.
creature->LOT.IsJumping = false;
creature->LOT.IsMonkeying = false;
creature->MaxTurn = ANGLE(1);
creature->Flags = 0;
- creature->Enemy = NULL;
+ creature->Enemy = nullptr;
creature->LOT.Fly = NO_FLYING;
creature->LOT.BlockMask = BLOCKED;
@@ -155,117 +155,116 @@ void InitialiseSlot(short itemNum, short slot, bool makeTarget)
else
creature->AITarget = nullptr;
- switch (obj->zoneType)
+ switch (object->ZoneType)
{
default:
- case ZONE_NULL:
+ case ZoneType::None:
creature->LOT.Step = CLICK(1);
creature->LOT.Drop = -CLICK(1);
- obj->zoneType = ZONE_BASIC; // only entity that use CreatureActive() will reach InitialiseSlot() !
+ object->ZoneType = ZoneType::Basic; // Only entities that use CreatureActive() will reach InitialiseSlot().
break;
- case ZONE_SKELLY:
- // Can jump
+ // Can jump.
+ case ZoneType::Skeleton:
creature->LOT.Step = CLICK(1);
creature->LOT.Drop = -CLICK(1);
creature->LOT.CanJump = true;
- creature->LOT.Zone = ZONE_SKELLY;
+ creature->LOT.Zone = ZoneType::Skeleton;
break;
- case ZONE_BASIC:
+ case ZoneType::Basic:
creature->LOT.Step = CLICK(1);
creature->LOT.Drop = -CLICK(1);
- creature->LOT.Zone = ZONE_BASIC;
+ creature->LOT.Zone = ZoneType::Basic;
break;
- case ZONE_FLYER:
- // Can fly
+ // Can fly.
+ case ZoneType::Flyer:
creature->LOT.Step = SECTOR(20);
creature->LOT.Drop = -SECTOR(20);
creature->LOT.Fly = DEFAULT_FLY_UPDOWN_SPEED;
- creature->LOT.Zone = ZONE_FLYER;
+ creature->LOT.Zone = ZoneType::Flyer;
break;
- case ZONE_WATER:
- // Can swim
+ // Can swim.
+ case ZoneType::Water:
creature->LOT.Step = SECTOR(20);
creature->LOT.Drop = -SECTOR(20);
- creature->LOT.Zone = ZONE_WATER;
+ creature->LOT.Zone = ZoneType::Water;
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.
+ creature->LOT.Fly = DEFAULT_SWIM_UPDOWN_SPEED / 2; // Slower than the other underwater creatures.
+ creature->LOT.IsAmphibious = true; // 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.
+ creature->LOT.Fly = NO_FLYING; // Can't swim underwater, only on the surface.
+ creature->LOT.IsAmphibious = true; // Can walk and swim.
}
else
- {
creature->LOT.Fly = DEFAULT_SWIM_UPDOWN_SPEED;
- }
+
break;
- case ZONE_HUMAN_CLASSIC:
- // Can climb
+ // Can climb.
+ case ZoneType::HumanClassic:
creature->LOT.Step = SECTOR(1);
creature->LOT.Drop = -SECTOR(1);
- creature->LOT.Zone = ZONE_HUMAN_CLASSIC;
+ creature->LOT.Zone = ZoneType::HumanClassic;
break;
- case ZONE_HUMAN_JUMP:
- // Can climb and jump
+ // Can climb and jump.
+ case ZoneType::HumanJump:
creature->LOT.Step = SECTOR(1);
creature->LOT.Drop = -SECTOR(1);
creature->LOT.CanJump = true;
- creature->LOT.Zone = ZONE_HUMAN_CLASSIC;
+ creature->LOT.Zone = ZoneType::HumanClassic;
break;
- case ZONE_HUMAN_JUMP_AND_MONKEY:
- // Can climb, jump, monkey
+ // Can climb, jump, monkeyswing.
+ case ZoneType::HumanJumpAndMonkey:
creature->LOT.Step = SECTOR(1);
creature->LOT.Drop = -SECTOR(1);
creature->LOT.CanJump = true;
creature->LOT.CanMonkey = true;
- creature->LOT.Zone = ZONE_HUMAN_CLASSIC;
+ creature->LOT.Zone = ZoneType::HumanClassic;
break;
- case ZONE_HUMAN_LONGJUMP_AND_MONKEY:
- // Can climb, jump, monkey, long jump
+ // Can climb, jump, monkey swing, long jump.
+ case ZoneType::HumanLongJumpAndMonkey:
creature->LOT.Step = SECTOR(1) + CLICK(3);
creature->LOT.Drop = -(SECTOR(1) + CLICK(3));
creature->LOT.CanJump = true;
creature->LOT.CanMonkey = true;
- creature->LOT.Zone = ZONE_VON_CROY;
+ creature->LOT.Zone = ZoneType::VonCroy;
break;
- case ZONE_SPIDER:
+ case ZoneType::Spider:
creature->LOT.Step = SECTOR(1) - CLICK(2);
creature->LOT.Drop = -(SECTOR(1) - CLICK(2));
- creature->LOT.Zone = ZONE_HUMAN_CLASSIC;
+ creature->LOT.Zone = ZoneType::HumanClassic;
break;
- case ZONE_BLOCKABLE:
+ case ZoneType::Blockable:
creature->LOT.BlockMask = BLOCKABLE;
- creature->LOT.Zone = ZONE_BASIC;
+ creature->LOT.Zone = ZoneType::Basic;
break;
- case ZONE_APE:
+ case ZoneType::Ape:
creature->LOT.Step = CLICK(2);
creature->LOT.Drop = -SECTOR(1);
break;
- case ZONE_SOPHIALEE:
+ case ZoneType::SophiaLee:
creature->LOT.Step = SECTOR(1);
creature->LOT.Drop = -CLICK(3);
- creature->LOT.Zone = ZONE_HUMAN_CLASSIC;
+ creature->LOT.Zone = ZoneType::HumanClassic;
break;
}
ClearLOT(&creature->LOT);
- if (itemNum != Lara.ItemNumber)
+ if (itemNumber != Lara.ItemNumber)
CreateZone(item);
SlotsUsed++;
@@ -304,16 +303,16 @@ void ClearLOT(LOTInfo* LOT)
void CreateZone(ItemInfo* item)
{
auto* creature = GetCreatureInfo(item);
- auto* r = &g_Level.Rooms[item->RoomNumber];
+ auto* room = &g_Level.Rooms[item->RoomNumber];
- item->BoxNumber = GetSector(r, item->Pose.Position.x - r->x, item->Pose.Position.z - r->z)->Box;
+ item->BoxNumber = GetSector(room, item->Pose.Position.x - room->x, item->Pose.Position.z - room->z)->Box;
if (creature->LOT.Fly)
{
- BOX_NODE* node = creature->LOT.Node.data();
+ auto* node = creature->LOT.Node.data();
creature->LOT.ZoneCount = 0;
- for (int i = 0; i < g_Level.Boxes.size(); i++)
+ for (size_t i = 0; i < g_Level.Boxes.size(); i++)
{
node->boxNumber = i;
node++;
@@ -322,8 +321,8 @@ void CreateZone(ItemInfo* item)
}
else
{
- int* zone = g_Level.Zones[creature->LOT.Zone][0].data();
- int* flippedZone = g_Level.Zones[creature->LOT.Zone][1].data();
+ int* zone = g_Level.Zones[(int)creature->LOT.Zone][0].data();
+ int* flippedZone = g_Level.Zones[(int)creature->LOT.Zone][1].data();
int zoneNumber = zone[item->BoxNumber];
int flippedZoneNumber = flippedZone[item->BoxNumber];
@@ -331,7 +330,7 @@ void CreateZone(ItemInfo* item)
auto* node = creature->LOT.Node.data();
creature->LOT.ZoneCount = 0;
- for (int i = 0; i < g_Level.Boxes.size(); i++)
+ for (size_t i = 0; i < g_Level.Boxes.size(); i++)
{
if (*zone == zoneNumber || *flippedZone == flippedZoneNumber)
{
diff --git a/TombEngine/Game/itemdata/creature_info.h b/TombEngine/Game/itemdata/creature_info.h
index 32c06190b..c76d9bc4e 100644
--- a/TombEngine/Game/itemdata/creature_info.h
+++ b/TombEngine/Game/itemdata/creature_info.h
@@ -1,7 +1,8 @@
#pragma once
-#include
#include "Specific/phd_global.h"
+using std::vector;
+
struct ItemInfo;
struct BOX_NODE
@@ -12,34 +13,37 @@ struct BOX_NODE
int boxNumber;
};
-enum ZoneType : char
+enum class ZoneType
{
- ZONE_NULL = -1, // default zone
- ZONE_SKELLY,
- 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 half block climb
- ZONE_HUMAN_LONGJUMP_AND_MONKEY,
+ None = -1,
+ Skeleton,
+ Basic,
+ Flyer,
+ HumanClassic,
+ VonCroy,
+ Water,
+ Max,
+
+ // Custom zones (above zones are used for LOT.zone):
+ HumanJumpAndMonkey,
+ HumanJump,
+ Spider,
+ Blockable, // For large creatures such as trex and shiva.
+ SophiaLee, // Prevents Sophia from going to lower levels again.
+ Ape, // Only 0.5 block climb.
+ HumanLongJumpAndMonkey,
};
struct LOTInfo
{
bool Initialised;
- std::vector Node;
+ vector Node;
int Head;
int Tail;
+ ZoneType Zone = ZoneType::None;
+ Vector3Int Target = Vector3Int::Zero;
int SearchNumber;
int BlockMask;
short Step;
@@ -49,14 +53,12 @@ struct LOTInfo
int RequiredBox;
short Fly;
- bool CanJump = false;
- bool CanMonkey = false;
- bool IsJumping = false;
- bool IsMonkeying = false;
+ bool CanJump = false;
+ bool CanMonkey = false;
+ bool IsJumping = false;
+ bool IsMonkeying = false;
bool IsAmphibious = false;
- Vector3Int Target = Vector3Int::Zero;
- ZoneType Zone = ZoneType::ZONE_NULL;
};
enum class MoodType
@@ -71,9 +73,9 @@ enum class MoodType
enum class CreatureAIPriority
{
None,
- High,
+ Low,
Medium,
- Low
+ High
};
struct CreatureInfo
diff --git a/TombEngine/Game/people.cpp b/TombEngine/Game/people.cpp
index d0d4ee188..688ca2fc5 100644
--- a/TombEngine/Game/people.cpp
+++ b/TombEngine/Game/people.cpp
@@ -145,32 +145,32 @@ bool TargetVisible(ItemInfo* item, AI_INFO* AI, float maxAngle)
return false;
// Check just in case.
- auto* creatureInfo = GetCreatureInfo(item);
- if (creatureInfo == nullptr)
+ auto* creature = GetCreatureInfo(item);
+ if (creature == nullptr)
return false;
- auto* enemy = creatureInfo->Enemy;
+ auto* enemy = creature->Enemy;
if (enemy == nullptr || enemy->HitPoints == 0)
return false;
- short angle = AI->angle - creatureInfo->JointRotation[2];
- if (angle > -ANGLE(maxAngle) && angle < ANGLE(maxAngle))
+ short angle = AI->angle - creature->JointRotation[2];
+ if (angle > ANGLE(-maxAngle) && angle < ANGLE(maxAngle))
{
- GameVector start;
- GameVector target;
auto& bounds = GetBestFrame(enemy)->boundingBox;
- start.x = item->Pose.Position.x;
- start.y = item->Pose.Position.y - CLICK(3);
- start.z = item->Pose.Position.z;
- start.roomNumber = item->RoomNumber;
-
- target.x = enemy->Pose.Position.x;
- target.y = enemy->Pose.Position.y + ((((bounds.Y1 * 2) + bounds.Y1) + bounds.Y2) / 4);
- target.z = enemy->Pose.Position.z;
- target.roomNumber = enemy->RoomNumber; // TODO: Check why this line didn't exist before. -- TokyoSU, 10/8/2022
-
- return LOS(&start, &target);
+ auto origin = GameVector(
+ item->Pose.Position.x,
+ item->Pose.Position.y - CLICK(3),
+ item->Pose.Position.z,
+ item->RoomNumber
+ );
+ auto target = GameVector(
+ enemy->Pose.Position.x,
+ enemy->Pose.Position.y + ((((bounds.Y1 * 2) + bounds.Y1) + bounds.Y2) / 4),
+ enemy->Pose.Position.z,
+ enemy->RoomNumber // TODO: Check why this line didn't exist before. -- TokyoSU, 10/8/2022
+ );
+ return LOS(&origin, &target);
}
return false;
diff --git a/TombEngine/Objects/TR1/tr1_objects.cpp b/TombEngine/Objects/TR1/tr1_objects.cpp
index 942ca6f0f..7a8b0c68f 100644
--- a/TombEngine/Objects/TR1/tr1_objects.cpp
+++ b/TombEngine/Objects/TR1/tr1_objects.cpp
@@ -77,7 +77,7 @@ static void StartEntity(ObjectInfo* obj)
obj->saveHitpoints = true;
obj->saveAnim = true;
obj->saveFlags = true;
- obj->zoneType = ZONE_APE;
+ obj->ZoneType = ZoneType::Ape;
}
obj = &Objects[ID_BIG_RAT];
@@ -97,7 +97,7 @@ static void StartEntity(ObjectInfo* obj)
obj->saveAnim = true;
obj->saveFlags = true;
obj->waterCreature = true;
- obj->zoneType = ZONE_WATER;
+ obj->ZoneType = ZoneType::Water;
obj->SetBoneRotation(1, ROT_Y); // head
}
@@ -173,7 +173,7 @@ static void StartEntity(ObjectInfo* obj)
obj->saveHitpoints = true;
obj->saveAnim = true;
obj->saveFlags = true;
- obj->zoneType = ZONE_BLOCKABLE;
+ obj->ZoneType = ZoneType::Blockable;
obj->SetBoneRotation(10, ROT_X | ROT_Y);
}
@@ -193,7 +193,7 @@ static void StartEntity(ObjectInfo* obj)
obj->saveFlags = true;
obj->saveHitpoints = true;
obj->savePosition = true;
- obj->zoneType = ZONE_FLYER;
+ obj->ZoneType = ZoneType::Flyer;
obj->SetBoneRotation(1, ROT_Y); // torso
obj->SetBoneRotation(2, ROT_Y); // head
}
diff --git a/TombEngine/Objects/TR2/Entity/tr2_sword_guardian.cpp b/TombEngine/Objects/TR2/Entity/tr2_sword_guardian.cpp
index 062eb22e9..699280d38 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_sword_guardian.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_sword_guardian.cpp
@@ -68,7 +68,7 @@ namespace TEN::Entities::Creatures::TR2
creature->LOT.Step = STEP_SIZE;
creature->LOT.Drop = -STEP_SIZE;
creature->LOT.Fly = NO_FLYING;
- creature->LOT.Zone = ZONE_BASIC;
+ creature->LOT.Zone = ZoneType::Basic;
AI_INFO AI;
CreatureAIInfo(item, &AI);
@@ -80,7 +80,7 @@ namespace TEN::Entities::Creatures::TR2
creature->LOT.Step = WALL_SIZE * 20;
creature->LOT.Drop = -WALL_SIZE * 20;
creature->LOT.Fly = STEP_SIZE / 4;
- creature->LOT.Zone = ZONE_FLYER;
+ creature->LOT.Zone = ZoneType::Flyer;
CreatureAIInfo(item, &AI);
}
}
diff --git a/TombEngine/Objects/TR2/tr2_objects.cpp b/TombEngine/Objects/TR2/tr2_objects.cpp
index 599a45b7d..33375d613 100644
--- a/TombEngine/Objects/TR2/tr2_objects.cpp
+++ b/TombEngine/Objects/TR2/tr2_objects.cpp
@@ -57,7 +57,7 @@ static void StartEntity(ObjectInfo* obj)
obj->saveHitpoints = true;
obj->saveAnim = true;
obj->saveFlags = true;
- obj->zoneType = ZONE_WATER;
+ obj->ZoneType = ZoneType::Water;
g_Level.Bones[obj->boneIndex + 9 * 4] |= ROT_Y;
}
@@ -78,7 +78,7 @@ static void StartEntity(ObjectInfo* obj)
obj->saveHitpoints = true;
obj->saveAnim = true;
obj->saveFlags = true;
- obj->zoneType = ZONE_WATER;
+ obj->ZoneType = ZoneType::Water;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
}
@@ -99,7 +99,7 @@ static void StartEntity(ObjectInfo* obj)
obj->saveAnim = true;
obj->saveFlags = true;
obj->pivotLength = 0;
- obj->zoneType = ZONE_FLYER;
+ obj->ZoneType = ZoneType::Flyer;
}
obj = &Objects[ID_CROW];
@@ -118,7 +118,7 @@ static void StartEntity(ObjectInfo* obj)
obj->saveAnim = true;
obj->saveFlags = true;
obj->pivotLength = 0;
- obj->zoneType = ZONE_FLYER;
+ obj->ZoneType = ZoneType::Flyer;
}
obj = &Objects[ID_RAT];
@@ -154,7 +154,7 @@ static void StartEntity(ObjectInfo* obj)
obj->saveFlags = true;
obj->saveHitpoints = true;
obj->savePosition = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= (ROT_Y);
g_Level.Bones[obj->boneIndex + 14 * 4] |= (ROT_Y);
}
diff --git a/TombEngine/Objects/TR3/tr3_objects.cpp b/TombEngine/Objects/TR3/tr3_objects.cpp
index 4cd5a68ec..4a0503d97 100644
--- a/TombEngine/Objects/TR3/tr3_objects.cpp
+++ b/TombEngine/Objects/TR3/tr3_objects.cpp
@@ -7,7 +7,7 @@
#include "Specific/level.h"
#include "Specific/setup.h"
-// Entities
+// Creatures
#include "Objects/TR3/Entity/tr3_civvy.h" // OK
#include "Objects/TR3/Entity/tr3_cobra.h" // OK
#include "Objects/TR3/Entity/tr3_fish_emitter.h" // OK
@@ -198,7 +198,7 @@ static void StartEntity(ObjectInfo* obj)
obj->saveAnim = true;
obj->saveFlags = true;
obj->pivotLength = 50;
- obj->zoneType = ZONE_WATER;
+ obj->ZoneType = ZoneType::Water;
g_Level.Bones[obj->boneIndex + 10 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 14 * 4] |= ROT_Z;
@@ -293,7 +293,7 @@ static void StartEntity(ObjectInfo* obj)
obj->saveAnim = true;
obj->saveFlags = true;
obj->pivotLength = 0;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_X;
diff --git a/TombEngine/Objects/TR4/tr4_objects.cpp b/TombEngine/Objects/TR4/tr4_objects.cpp
index 5116b5006..4e3b03ff3 100644
--- a/TombEngine/Objects/TR4/tr4_objects.cpp
+++ b/TombEngine/Objects/TR4/tr4_objects.cpp
@@ -9,7 +9,7 @@
#include "Specific/setup.h"
#include "Specific/level.h"
-// Entities
+// Creatures
#include "tr4_enemy_jeep.h"
#include "tr4_ahmet.h" // OK
#include "tr4_baddy.h" // OK
@@ -100,7 +100,7 @@ namespace TEN::Entities
obj->saveHitpoints = true;
obj->saveAnim = true;
obj->saveFlags = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
}
obj = &Objects[ID_BIG_SCORPION];
@@ -119,7 +119,7 @@ namespace TEN::Entities
obj->saveHitpoints = true;
obj->saveFlags = true;
obj->saveAnim = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
}
obj = &Objects[ID_HAMMERHEAD];
@@ -139,7 +139,7 @@ namespace TEN::Entities
obj->saveAnim = true;
obj->saveFlags = true;
obj->waterCreature = true;
- obj->zoneType = ZONE_WATER;
+ obj->ZoneType = ZoneType::Water;
}
obj = &Objects[ID_WILD_BOAR];
@@ -158,7 +158,7 @@ namespace TEN::Entities
obj->saveHitpoints = true;
obj->saveAnim = true;
obj->saveFlags = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 48 * 4] |= ROT_Z;
g_Level.Bones[obj->boneIndex + 48 * 4] |= ROT_Y;
@@ -182,7 +182,7 @@ namespace TEN::Entities
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 19 * 4] |= ROT_Y;
}
@@ -202,7 +202,7 @@ namespace TEN::Entities
obj->saveHitpoints = true;
obj->saveAnim = true;
obj->saveFlags = true;
- obj->zoneType = ZONE_FLYER;
+ obj->ZoneType = ZoneType::Flyer;
}
obj = &Objects[ID_AHMET];
@@ -221,7 +221,7 @@ namespace TEN::Entities
obj->saveFlags = true;
obj->saveHitpoints = true;
obj->savePosition = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 9 * 4] |= ROT_Y;
}
@@ -244,7 +244,7 @@ namespace TEN::Entities
obj->saveAnim = true;
obj->saveFlags = true;
obj->meshSwapSlot = ID_MESHSWAP_BADDY1;
- obj->zoneType = ZONE_HUMAN_JUMP_AND_MONKEY;
+ obj->ZoneType = ZoneType::HumanJumpAndMonkey;
g_Level.Bones[obj->boneIndex + 28 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 28 * 4] |= ROT_X;
@@ -270,7 +270,7 @@ namespace TEN::Entities
obj->saveAnim = true;
obj->saveFlags = true;
obj->meshSwapSlot = ID_MESHSWAP_BADDY2;
- obj->zoneType = ZONE_HUMAN_JUMP_AND_MONKEY;
+ obj->ZoneType = ZoneType::HumanJumpAndMonkey;
g_Level.Bones[obj->boneIndex + 28 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 28 * 4] |= ROT_X;
@@ -295,7 +295,7 @@ namespace TEN::Entities
obj->saveHitpoints = true;
obj->saveAnim = true;
obj->saveFlags = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex] |= ROT_Y;
g_Level.Bones[obj->boneIndex] |= ROT_X;
@@ -319,7 +319,7 @@ namespace TEN::Entities
obj->saveAnim = true;
obj->saveFlags = true;
obj->undead = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 7 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 7 * 4] |= ROT_X;
@@ -344,7 +344,7 @@ namespace TEN::Entities
obj->saveAnim = true;
obj->saveFlags = true;
obj->undead = true;
- obj->zoneType = ZONE_SKELLY;
+ obj->ZoneType = ZoneType::Skeleton;
}
obj = &Objects[ID_KNIGHT_TEMPLAR];
@@ -363,7 +363,7 @@ namespace TEN::Entities
obj->saveHitpoints = true;
obj->saveFlags = true;
obj->saveAnim = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_X | ROT_Y;
g_Level.Bones[obj->boneIndex + 7 * 4] |= ROT_Y;
@@ -386,7 +386,7 @@ namespace TEN::Entities
obj->saveAnim = true;
obj->savePosition = true;
obj->undead = false;
- obj->zoneType = ZONE_FLYER;
+ obj->ZoneType = ZoneType::Flyer;
}
obj = &Objects[ID_SETHA];
@@ -406,7 +406,7 @@ namespace TEN::Entities
obj->saveFlags = true;
obj->saveAnim = true;
obj->undead = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
}
obj = &Objects[ID_DEMIGOD1];
@@ -426,7 +426,7 @@ namespace TEN::Entities
obj->saveFlags = true;
obj->saveAnim = true;
obj->undead = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 4 * 4] |= ROT_X | ROT_Y | ROT_Z;
g_Level.Bones[obj->boneIndex + 5 * 4] |= ROT_Y;
@@ -448,7 +448,7 @@ namespace TEN::Entities
obj->saveHitpoints = true;
obj->saveFlags = true;
obj->saveAnim = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 4 * 4] |= ROT_X | ROT_Y | ROT_Z;
g_Level.Bones[obj->boneIndex + 5 * 4] |= ROT_Y;
}
@@ -469,7 +469,7 @@ namespace TEN::Entities
obj->saveHitpoints = true;
obj->saveFlags = true;
obj->saveAnim = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 4 * 4] |= ROT_X | ROT_Y | ROT_Z;
g_Level.Bones[obj->boneIndex + 5 * 4] |= ROT_Y;
}
@@ -483,7 +483,7 @@ namespace TEN::Entities
obj->hitEffect = HIT_BLOOD;
obj->nonLot = true;
obj->savePosition = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
}
obj = &Objects[ID_TROOPS];
@@ -502,7 +502,7 @@ namespace TEN::Entities
obj->saveHitpoints = true;
obj->saveAnim = true;
obj->saveFlags = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex] |= ROT_X | ROT_Y;
g_Level.Bones[obj->boneIndex + 7 * 4] |= ROT_X | ROT_Y;
@@ -525,7 +525,7 @@ namespace TEN::Entities
obj->saveAnim = true;
obj->saveFlags = true;
obj->explodableMeshbits = 64;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 0] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 1 * 4] |= ROT_X;
@@ -548,7 +548,7 @@ namespace TEN::Entities
obj->saveHitpoints = true;
obj->saveAnim = true;
obj->saveFlags = true;
- obj->zoneType = ZONE_FLYER;
+ obj->ZoneType = ZoneType::Flyer;
}
obj = &Objects[ID_GUIDE];
@@ -567,7 +567,7 @@ namespace TEN::Entities
obj->saveAnim = true;
obj->saveFlags = true;
obj->meshSwapSlot = ID_MESHSWAP2;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_X | ROT_Y;
g_Level.Bones[obj->boneIndex + 20 * 4] |= ROT_X | ROT_Y;
@@ -589,7 +589,7 @@ namespace TEN::Entities
obj->saveAnim = true;
obj->saveFlags = true;
obj->waterCreature = true;
- obj->zoneType = ZONE_WATER;
+ obj->ZoneType = ZoneType::Water;
g_Level.Bones[obj->boneIndex] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 7 * 4] |= ROT_Y;
@@ -612,7 +612,7 @@ namespace TEN::Entities
obj->saveHitpoints = true;
obj->saveAnim = true;
obj->saveFlags = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
}
obj = &Objects[ID_HORSE];
@@ -642,7 +642,7 @@ namespace TEN::Entities
obj->saveFlags = true;
obj->savePosition = true;
obj->saveMesh = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
}
obj = &Objects[ID_BABOON_NORMAL];
@@ -661,7 +661,7 @@ namespace TEN::Entities
obj->saveFlags = true;
obj->saveHitpoints = true;
obj->savePosition = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
}
obj = &Objects[ID_BABOON_INV];
@@ -680,7 +680,7 @@ namespace TEN::Entities
obj->saveFlags = true;
obj->saveHitpoints = true;
obj->savePosition = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
if (Objects[ID_BABOON_NORMAL].loaded)
Objects[ID_BABOON_INV].animIndex = Objects[ID_BABOON_NORMAL].animIndex;
@@ -702,7 +702,7 @@ namespace TEN::Entities
obj->saveFlags = true;
obj->saveHitpoints = true;
obj->savePosition = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
if (Objects[ID_BABOON_NORMAL].loaded)
Objects[ID_BABOON_SILENT].animIndex = Objects[ID_BABOON_NORMAL].animIndex;
@@ -725,7 +725,7 @@ namespace TEN::Entities
obj->saveMesh = true;
obj->savePosition = true;
obj->undead = true;
- obj->zoneType = ZONE_WATER;
+ obj->ZoneType = ZoneType::Water;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y | ROT_X;
g_Level.Bones[obj->boneIndex + 7 * 4] |= ROT_Y | ROT_X;
}
@@ -737,7 +737,7 @@ namespace TEN::Entities
obj->control = TEN::Entities::TR4::LocustControl;
obj->drawRoutine = NULL;
obj->saveFlags = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
}
obj = &Objects[ID_WRAITH1];
@@ -780,7 +780,7 @@ namespace TEN::Entities
obj->control = TEN::Entities::TR4::BeetleSwarmControl;
obj->drawRoutine = NULL;
obj->saveFlags = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
}
obj = &Objects[ID_SAS_DYING];
@@ -793,7 +793,7 @@ namespace TEN::Entities
obj->saveFlags = true;
obj->savePosition = true;
obj->saveAnim = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
}
obj = &Objects[ID_SAS_DRAG_BLOKE];
@@ -805,7 +805,7 @@ namespace TEN::Entities
obj->saveFlags = true;
obj->savePosition = true;
obj->saveAnim = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
}
obj = &Objects[ID_ENEMY_JEEP];
@@ -823,7 +823,7 @@ namespace TEN::Entities
obj->shadowType = ShadowMode::All;
obj->radius = 512;
obj->HitPoints = 40;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 4 * 8] |= ROT_X;
g_Level.Bones[obj->boneIndex + 4 * 9] |= ROT_X;
@@ -847,7 +847,7 @@ namespace TEN::Entities
obj->savePosition = true;
obj->saveHitpoints = true;
obj->saveMesh = true;
- obj->zoneType = ZONE_HUMAN_LONGJUMP_AND_MONKEY;
+ obj->ZoneType = ZoneType::HumanLongJumpAndMonkey;
g_Level.Bones[obj->boneIndex + 4 * 6] |= ROT_X;
g_Level.Bones[obj->boneIndex + 4 * 6] |= ROT_Y;
@@ -1176,7 +1176,7 @@ namespace TEN::Entities
obj->saveHitpoints = true;
obj->saveFlags = true;
obj->saveAnim = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
}
obj = &Objects[ID_TEETH_SPIKES];
diff --git a/TombEngine/Objects/TR5/tr5_objects.cpp b/TombEngine/Objects/TR5/tr5_objects.cpp
index aa98ec944..5c7b5261f 100644
--- a/TombEngine/Objects/TR5/tr5_objects.cpp
+++ b/TombEngine/Objects/TR5/tr5_objects.cpp
@@ -105,7 +105,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_X;
g_Level.Bones[obj->boneIndex + 13 * 4] |= ROT_Y;
@@ -130,7 +130,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_X;
g_Level.Bones[obj->boneIndex + 13 * 4] |= ROT_Y;
@@ -157,7 +157,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_X;
g_Level.Bones[obj->boneIndex + 13 * 4] |= ROT_Y;
@@ -187,7 +187,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_X;
g_Level.Bones[obj->boneIndex + 13 * 4] |= ROT_Y;
@@ -218,7 +218,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_X;
g_Level.Bones[obj->boneIndex + 13 * 4] |= ROT_Y;
@@ -247,7 +247,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[Objects[69].boneIndex + 6 * 4] |= ROT_Y;
g_Level.Bones[Objects[69].boneIndex + 6 * 4] |= ROT_X;
g_Level.Bones[Objects[69].boneIndex + 13 * 4] |= ROT_Y;
@@ -278,7 +278,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_X;
g_Level.Bones[obj->boneIndex + 13 * 4] |= ROT_Y;
@@ -310,7 +310,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_X;
g_Level.Bones[obj->boneIndex + 13 * 4] |= ROT_Y;
@@ -334,7 +334,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveHitpoints = true;
obj->savePosition = true;
obj->waterCreature = true;
- obj->zoneType = ZONE_FLYER;
+ obj->ZoneType = ZoneType::Flyer;
obj->undead = true;
g_Level.Bones[obj->boneIndex] |= ROT_X;
g_Level.Bones[obj->boneIndex + 4] |= ROT_X;
@@ -357,7 +357,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 4 * 6] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 4 * 6] |= ROT_X;
@@ -381,7 +381,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 19 * 4] |= ROT_Y;
}
@@ -402,7 +402,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 19 * 4] |= ROT_Y;
}
@@ -422,7 +422,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 19 * 4] |= ROT_Y;
}
@@ -443,7 +443,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveHitpoints = true;
obj->savePosition = true;
obj->waterCreature = true;
- obj->zoneType = ZONE_FLYER;
+ obj->ZoneType = ZoneType::Flyer;
}
obj = &Objects[ID_MAFIA2];
@@ -464,7 +464,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
obj->meshSwapSlot = ID_MESHSWAP_MAFIA2;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
@@ -490,7 +490,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_X;
g_Level.Bones[obj->boneIndex + 7 * 4] |= ROT_Y;
@@ -514,7 +514,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_X;
g_Level.Bones[obj->boneIndex + 7 * 4] |= ROT_Y;
@@ -539,7 +539,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveAnim = true;
obj->saveHitpoints = true;
obj->undead = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
obj->meshSwapSlot = ID_MESHSWAP_HITMAN;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
@@ -591,7 +591,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveAnim = true;
obj->saveHitpoints = true;
obj->undead = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex] |= ROT_Y;
g_Level.Bones[obj->boneIndex] |= ROT_X;
g_Level.Bones[obj->boneIndex + 4] |= ROT_Y;
@@ -616,7 +616,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveAnim = true;
obj->saveHitpoints = true;
obj->undead = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 0] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 8 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 8 * 4] |= ROT_X;
@@ -641,7 +641,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveAnim = true;
obj->saveHitpoints = true;
obj->meshSwapSlot = ID_MESHSWAP_IMP;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->meshIndex + 4 * 4] |= ROT_Z;
g_Level.Bones[obj->meshIndex + 4 * 4] |= ROT_X;
@@ -665,7 +665,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveHitpoints = true;
obj->savePosition = true;
- obj->zoneType = ZONE_FLYER;
+ obj->ZoneType = ZoneType::Flyer;
g_Level.Bones[obj->boneIndex + 4 * 4] |= ROT_Z;
g_Level.Bones[obj->boneIndex + 4 * 4] |= ROT_X;
g_Level.Bones[obj->boneIndex + 9 * 4] |= ROT_Z;
@@ -689,7 +689,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveHitpoints = true;
obj->savePosition = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 4 * 4] |= ROT_Z;
g_Level.Bones[obj->boneIndex + 4 * 4] |= ROT_X;
g_Level.Bones[obj->boneIndex + 9 * 4] |= ROT_Z;
@@ -714,7 +714,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveHitpoints = true;
obj->savePosition = true;
obj->waterCreature = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
g_Level.Bones[obj->boneIndex + 4 * 4] |= ROT_Z;
g_Level.Bones[obj->boneIndex + 4 * 4] |= ROT_X;
@@ -739,7 +739,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_X;
g_Level.Bones[obj->boneIndex + 8 * 4] |= ROT_Y;
@@ -790,7 +790,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveFlags = true;
obj->saveAnim = true;
obj->saveHitpoints = true;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 6 * 4] |= ROT_X;
g_Level.Bones[obj->boneIndex + 13 * 4] |= ROT_Y;
@@ -817,7 +817,7 @@ static void StartEntity(ObjectInfo *obj)
obj->saveAnim = true;
obj->saveHitpoints = true;
obj->meshSwapSlot = ID_MESHSWAP_ROMAN_GOD1 + i;
- obj->zoneType = ZONE_HUMAN_CLASSIC;
+ obj->ZoneType = ZoneType::HumanClassic;
g_Level.Bones[obj->boneIndex + 24] |= ROT_Y;
g_Level.Bones[obj->boneIndex + 24] |= ROT_X;
@@ -876,7 +876,7 @@ static void StartEntity(ObjectInfo *obj)
obj->initialise = InitialiseSubmarine;
obj->control = SubmarineControl;
obj->saveAnim = true;
- obj->zoneType = ZONE_BASIC;
+ obj->ZoneType = ZoneType::Basic;
obj->hitEffect = HIT_RICOCHET;
obj->shadowType = ShadowMode::All;
obj->HitPoints = 100;
diff --git a/TombEngine/Specific/setup.cpp b/TombEngine/Specific/setup.cpp
index d30ba5659..d56cd088d 100644
--- a/TombEngine/Specific/setup.cpp
+++ b/TombEngine/Specific/setup.cpp
@@ -408,7 +408,7 @@ void InitialiseObjects()
obj->usingDrawAnimatingItem = true;
obj->semiTransparent = false;
obj->undead = false;
- obj->zoneType = ZONE_NULL;
+ obj->ZoneType = ZoneType::None;
obj->biteOffset = -1;
obj->meshSwapSlot = NO_ITEM;
obj->isPickup = false;
diff --git a/TombEngine/Specific/setup.h b/TombEngine/Specific/setup.h
index 550ebf858..d8fa8efe3 100644
--- a/TombEngine/Specific/setup.h
+++ b/TombEngine/Specific/setup.h
@@ -1,12 +1,12 @@
#pragma once
#include "Objects/objectslist.h"
-#include "Specific/phd_global.h"
-#include "Specific/level.h"
#include "Renderer/Renderer11Enums.h"
+#include "Specific/level.h"
+#include "Specific/phd_global.h"
-struct ItemInfo;
+enum class ZoneType;
struct CollisionInfo;
-enum ZoneType : char;
+struct ItemInfo;
constexpr auto DEFAULT_RADIUS = 10;
constexpr auto ROT_X = 0x0004;
@@ -44,7 +44,7 @@ struct ObjectInfo
std::function ceilingBorder;
std::function drawRoutine;
std::function collision;
- ZoneType zoneType;
+ ZoneType ZoneType;
int animIndex;
short HitPoints;
short pivotLength;
From 6c7a856522600162f0b20ce1f2d361ef2f6b0d2e Mon Sep 17 00:00:00 2001
From: Sezz
Date: Sun, 21 Aug 2022 21:54:59 +1000
Subject: [PATCH 026/106] Minor cleanup
---
TombEngine/Game/itemdata/creature_info.h | 1 -
TombEngine/Objects/TR3/Entity/tr3_trex.cpp | 5 +-
.../Objects/TR3/Entity/tr3_tribesman.cpp | 52 +++++++++----------
3 files changed, 28 insertions(+), 30 deletions(-)
diff --git a/TombEngine/Game/itemdata/creature_info.h b/TombEngine/Game/itemdata/creature_info.h
index c76d9bc4e..fd8c710e7 100644
--- a/TombEngine/Game/itemdata/creature_info.h
+++ b/TombEngine/Game/itemdata/creature_info.h
@@ -58,7 +58,6 @@ struct LOTInfo
bool IsJumping = false;
bool IsMonkeying = false;
bool IsAmphibious = false;
-
};
enum class MoodType
diff --git a/TombEngine/Objects/TR3/Entity/tr3_trex.cpp b/TombEngine/Objects/TR3/Entity/tr3_trex.cpp
index c96d26d90..137deb7af 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_trex.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_trex.cpp
@@ -17,8 +17,9 @@ using std::vector;
namespace TEN::Entities::Creatures::TR3
{
+ constexpr auto TREX_CONTACT_DAMAGE = 1;
+ constexpr auto TREX_RUN_CONTACT_DAMAGE = 10;
constexpr auto TREX_ROAR_CHANCE = 0.015f;
-
constexpr auto LARA_ANIM_TREX_DEATH_ANIM = 4;
const vector TRexAttackJoints = { 12, 13 };
@@ -114,7 +115,7 @@ namespace TEN::Entities::Creatures::TR3
angle = CreatureTurn(item, creature->MaxTurn);
if (item->TouchBits)
- DoDamage(LaraItem, (item->Animation.ActiveState == TREX_STATE_RUN_FORWARD) ? 10 : 1);
+ DoDamage(LaraItem, (item->Animation.ActiveState == TREX_STATE_RUN_FORWARD) ? TREX_RUN_CONTACT_DAMAGE : TREX_CONTACT_DAMAGE);
creature->Flags = (creature->Mood != MoodType::Escape && !AI.ahead && AI.enemyFacing > -FRONT_ARC && AI.enemyFacing < FRONT_ARC);
diff --git a/TombEngine/Objects/TR3/Entity/tr3_tribesman.cpp b/TombEngine/Objects/TR3/Entity/tr3_tribesman.cpp
index 68f121572..4ff0ae04c 100644
--- a/TombEngine/Objects/TR3/Entity/tr3_tribesman.cpp
+++ b/TombEngine/Objects/TR3/Entity/tr3_tribesman.cpp
@@ -105,9 +105,9 @@ namespace TEN::Entities::Creatures::TR3
auto* item = &g_Level.Items[itemNumber];
auto* creature = GetCreatureInfo(item);
- short head = 0;
short angle = 0;
short tilt = 0;
+ short head = 0;
if (item->HitPoints <= 0)
{
@@ -217,9 +217,9 @@ namespace TEN::Entities::Creatures::TR3
break;
case TRIBESMAN_STATE_WALK_FORWARD:
- tilt = angle / 8;
creature->MaxTurn = ANGLE(9.0f);
creature->Flags = 0;
+ tilt = angle / 8;
if (creature->Mood == MoodType::Bored)
{
@@ -248,9 +248,9 @@ namespace TEN::Entities::Creatures::TR3
break;
case TRIBESMAN_STATE_RUN_FORWARD:
- tilt = angle / 4;
creature->MaxTurn = ANGLE(6.0f);
creature->Flags = 0;
+ tilt = angle / 4;
if (creature->Mood == MoodType::Bored)
{
@@ -312,7 +312,7 @@ namespace TEN::Entities::Creatures::TR3
}
else
{
- if (creature->Enemy)
+ if (creature->Enemy != nullptr)
{
auto direction = creature->Enemy->Pose.Position - item->Pose.Position;
if (abs(direction.x) < SECTOR(0.5f) &&
@@ -387,10 +387,8 @@ namespace TEN::Entities::Creatures::TR3
short angle = 0;
short tilt = 0;
- short headX = 0;
- short headY = 0;
- short torsoX = 0;
- short torsoY = 0;
+ auto extraHeadRot = Vector3Shrt::Zero;
+ auto extraTorsoRot = Vector3Shrt::Zero;
if (item->HitPoints <= 0)
{
@@ -423,8 +421,8 @@ namespace TEN::Entities::Creatures::TR3
angle = CreatureTurn(item, creature->Mood == MoodType::Bored ? ANGLE(2.0f) : creature->MaxTurn);
if (AI.ahead)
{
- headY = AI.angle / 2;
- torsoY = AI.angle / 2;
+ extraHeadRot.y = AI.angle / 2;
+ extraTorsoRot.y = AI.angle / 2;
}
if (item->HitStatus ||
@@ -442,16 +440,16 @@ namespace TEN::Entities::Creatures::TR3
if (AI.ahead)
{
- torsoY = AI.angle;
- torsoX = AI.xAngle / 2;
+ extraTorsoRot.x = AI.xAngle / 2;
+ extraTorsoRot.y = AI.angle;
}
if (item->AIBits & GUARD)
{
creature->MaxTurn = 0;
- headY = AIGuard(creature);
- torsoX = 0;
- torsoY = 0;
+ extraHeadRot.y = AIGuard(creature);
+ extraTorsoRot.x = 0;
+ extraTorsoRot.y = 0;
if (TestProbability(0.004f))
item->Animation.TargetState = TRIBESMAN_STATE_IDLE;
@@ -483,16 +481,16 @@ namespace TEN::Entities::Creatures::TR3
break;
- case 11:
+ case TRIBESMAN_STATE_IDLE:
creature->MaxTurn = ANGLE(2.0f);
creature->Flags &= 0x0FFF;
if (item->AIBits & GUARD)
{
creature->MaxTurn = 0;
- headY = AIGuard(creature);
- torsoX = 0;
- torsoY = 0;
+ extraHeadRot.y = AIGuard(creature);
+ extraTorsoRot.x = 0;
+ extraTorsoRot.y = 0;
if (TestProbability(0.004f))
item->Animation.TargetState = TRIBESMAN_STATE_CROUCH_IDLE;
@@ -544,7 +542,7 @@ namespace TEN::Entities::Creatures::TR3
break;
- case 3:
+ case TRIBESMAN_STATE_RUN_FORWARD:
creature->MaxTurn = ANGLE(6.0f);
creature->Flags &= 0x0FFF;
tilt = angle / 4;
@@ -576,8 +574,8 @@ namespace TEN::Entities::Creatures::TR3
if (AI.ahead)
{
- torsoX = AI.xAngle;
- torsoY = AI.angle;
+ extraTorsoRot.x = AI.xAngle;
+ extraTorsoRot.y = AI.angle;
}
if (abs(AI.angle) < ANGLE(2.0f))
@@ -628,12 +626,12 @@ namespace TEN::Entities::Creatures::TR3
CreatureTilt(item, tilt);
- headY -= torsoY;
+ extraHeadRot.y -= extraTorsoRot.y;
- CreatureJoint(item, 0, torsoY);
- CreatureJoint(item, 1, torsoX);
- CreatureJoint(item, 2, headY);
- CreatureJoint(item, 3, headX);
+ CreatureJoint(item, 0, extraTorsoRot.y);
+ CreatureJoint(item, 1, extraTorsoRot.x);
+ CreatureJoint(item, 2, extraHeadRot.y);
+ CreatureJoint(item, 3, extraHeadRot.x);
CreatureAnimation(itemNumber, angle, 0);
}
From 10d3e3c253558166c6c55ef15262d7348f558e6d Mon Sep 17 00:00:00 2001
From: Sezz
Date: Sun, 21 Aug 2022 22:18:53 +1000
Subject: [PATCH 027/106] Fix double cast
---
TombEngine/Game/control/box.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/TombEngine/Game/control/box.cpp b/TombEngine/Game/control/box.cpp
index 0b6c24a1a..e18fe2f3b 100644
--- a/TombEngine/Game/control/box.cpp
+++ b/TombEngine/Game/control/box.cpp
@@ -157,7 +157,7 @@ void CreatureYRot2(PHD_3DPOS* srcPos, short angle, short angleAdd)
bool SameZone(CreatureInfo* creature, ItemInfo* target)
{
- int* zone = g_Level.Zones[(int)(int)creature->LOT.Zone][FlipStatus].data();
+ int* zone = g_Level.Zones[(int)creature->LOT.Zone][FlipStatus].data();
auto* item = &g_Level.Items[creature->ItemNumber];
auto* room = &g_Level.Rooms[item->RoomNumber];
From 28a39efe95d67cb87ace96d6625d4f8abe822ade Mon Sep 17 00:00:00 2001
From: hispidence
Date: Mon, 22 Aug 2022 13:44:44 +0100
Subject: [PATCH 028/106] Fix #689
---
TombEngine/Game/Lara/lara_fire.cpp | 6 ++-
TombEngine/Game/Lara/lara_one_gun.cpp | 6 ++-
TombEngine/Game/Lara/lara_struct.h | 2 +-
TombEngine/Game/Lara/lara_two_guns.cpp | 11 +++-
TombEngine/Game/pickup/pickup_weapon.cpp | 64 +++++++++++++++++++-----
5 files changed, 71 insertions(+), 18 deletions(-)
diff --git a/TombEngine/Game/Lara/lara_fire.cpp b/TombEngine/Game/Lara/lara_fire.cpp
index f6049ea56..6d1f1de0b 100644
--- a/TombEngine/Game/Lara/lara_fire.cpp
+++ b/TombEngine/Game/Lara/lara_fire.cpp
@@ -571,7 +571,9 @@ void LaraGun(ItemInfo* laraItem)
{
if (!GetAmmo(laraItem, lara->Control.Weapon.GunType))
{
- lara->Control.Weapon.RequestGunType = Objects[ID_PISTOLS_ITEM].loaded ? LaraWeaponType::Pistol : LaraWeaponType::None;
+ bool hasPistols = lara->Weapons[(int)LaraWeaponType::Pistol].Present && Objects[ID_PISTOLS_ITEM].loaded;
+
+ lara->Control.Weapon.RequestGunType = hasPistols ? LaraWeaponType::Pistol : LaraWeaponType::None;
return;
}
}
@@ -1184,7 +1186,7 @@ HolsterSlot HolsterSlotForWeapon(LaraWeaponType weaponType)
return HolsterSlot::Harpoon;
case LaraWeaponType::Crossbow:
- return HolsterSlot::Crowssbow;
+ return HolsterSlot::Crossbow;
case LaraWeaponType::GrenadeLauncher:
return HolsterSlot::GrenadeLauncher;
diff --git a/TombEngine/Game/Lara/lara_one_gun.cpp b/TombEngine/Game/Lara/lara_one_gun.cpp
index c09b63b63..6d84bd9fe 100644
--- a/TombEngine/Game/Lara/lara_one_gun.cpp
+++ b/TombEngine/Game/Lara/lara_one_gun.cpp
@@ -434,8 +434,12 @@ void UndrawShotgunMeshes(ItemInfo* laraItem, LaraWeaponType weaponType)
{
auto* lara = GetLaraInfo(laraItem);
- lara->Control.Weapon.HolsterInfo.BackHolster = HolsterSlotForWeapon(weaponType);
lara->MeshPtrs[LM_RHAND] = Objects[ID_LARA_SKIN].meshIndex + LM_RHAND;
+
+ if (lara->Weapons[(int)weaponType].Present)
+ lara->Control.Weapon.HolsterInfo.BackHolster = HolsterSlotForWeapon(weaponType);
+ else
+ lara->Control.Weapon.HolsterInfo.BackHolster = HolsterSlot::Empty;
}
void FireHarpoon(ItemInfo* laraItem)
diff --git a/TombEngine/Game/Lara/lara_struct.h b/TombEngine/Game/Lara/lara_struct.h
index e47d6fa3a..f0d276613 100644
--- a/TombEngine/Game/Lara/lara_struct.h
+++ b/TombEngine/Game/Lara/lara_struct.h
@@ -887,7 +887,7 @@ enum class HolsterSlot
Shotgun = ID_SHOTGUN_ANIM,
HK = ID_HK_ANIM,
Harpoon = ID_HARPOON_ANIM,
- Crowssbow = ID_CROSSBOW_ANIM,
+ Crossbow = ID_CROSSBOW_ANIM,
GrenadeLauncher = ID_GRENADE_ANIM,
RocketLauncher = ID_ROCKET_ANIM
};
diff --git a/TombEngine/Game/Lara/lara_two_guns.cpp b/TombEngine/Game/Lara/lara_two_guns.cpp
index 2bc720fde..4b93d3add 100644
--- a/TombEngine/Game/Lara/lara_two_guns.cpp
+++ b/TombEngine/Game/Lara/lara_two_guns.cpp
@@ -490,7 +490,10 @@ void UndrawPistolMeshRight(ItemInfo* laraItem, LaraWeaponType weaponType)
auto* lara = GetLaraInfo(laraItem);
lara->MeshPtrs[LM_RHAND] = Objects[ID_LARA_SKIN].meshIndex + LM_RHAND;
- lara->Control.Weapon.HolsterInfo.RightHolster = HolsterSlotForWeapon(weaponType);
+ if (lara->Weapons[(int)weaponType].Present)
+ lara->Control.Weapon.HolsterInfo.RightHolster = HolsterSlotForWeapon(weaponType);
+ else
+ lara->Control.Weapon.HolsterInfo.RightHolster = HolsterSlot::Empty;
}
void UndrawPistolMeshLeft(ItemInfo* laraItem, LaraWeaponType weaponType)
@@ -500,6 +503,10 @@ void UndrawPistolMeshLeft(ItemInfo* laraItem, LaraWeaponType weaponType)
if (weaponType != LaraWeaponType::Revolver)
{
lara->MeshPtrs[LM_LHAND] = Objects[ID_LARA_SKIN].meshIndex + LM_LHAND;
- lara->Control.Weapon.HolsterInfo.LeftHolster = HolsterSlotForWeapon(weaponType);
+
+ if (lara->Weapons[(int)weaponType].Present)
+ lara->Control.Weapon.HolsterInfo.LeftHolster = HolsterSlotForWeapon(weaponType);
+ else
+ lara->Control.Weapon.HolsterInfo.LeftHolster = HolsterSlot::Empty;
}
}
diff --git a/TombEngine/Game/pickup/pickup_weapon.cpp b/TombEngine/Game/pickup/pickup_weapon.cpp
index a99f065a6..d61b4f884 100644
--- a/TombEngine/Game/pickup/pickup_weapon.cpp
+++ b/TombEngine/Game/pickup/pickup_weapon.cpp
@@ -2,30 +2,39 @@
#include "Game/pickup/pickup_weapon.h"
#include
+
+#include "lara_fire.h"
#include "Game/Lara/lara_struct.h"
#include "Game/pickup/pickuputil.h"
#include "Game/pickup/pickup_ammo.h"
#include "Objects/objectslist.h"
+enum class HolsterType
+{
+ Hips,
+ Back
+};
+
struct WeaponPickupInfo
{
GAME_OBJECT_ID ObjectID;
GAME_OBJECT_ID AmmoID; // When the player picks up a weapon, they get one clip's worth of this ammo.
LaraWeaponType LaraWeaponType;
+ HolsterType Holster;
};
static constexpr std::array kWeapons
{
{
- { ID_PISTOLS_ITEM, ID_PISTOLS_AMMO_ITEM, LaraWeaponType::Pistol },
- { ID_UZI_ITEM, ID_UZI_AMMO_ITEM, LaraWeaponType::Uzi },
- { ID_SHOTGUN_ITEM, ID_SHOTGUN_AMMO1_ITEM, LaraWeaponType::Shotgun },
- { ID_CROSSBOW_ITEM, ID_CROSSBOW_AMMO1_ITEM, LaraWeaponType::Crossbow },
- { ID_REVOLVER_ITEM, ID_REVOLVER_AMMO_ITEM, LaraWeaponType::Revolver },
- { ID_HK_ITEM, ID_HK_AMMO_ITEM, LaraWeaponType::HK },
- { ID_GRENADE_GUN_ITEM, ID_GRENADE_AMMO1_ITEM, LaraWeaponType::GrenadeLauncher },
- { ID_ROCKET_LAUNCHER_ITEM, ID_ROCKET_LAUNCHER_AMMO_ITEM, LaraWeaponType::RocketLauncher },
- { ID_HARPOON_ITEM, ID_HARPOON_AMMO_ITEM, LaraWeaponType::HarpoonGun }
+ { ID_PISTOLS_ITEM, ID_PISTOLS_AMMO_ITEM, LaraWeaponType::Pistol, HolsterType::Hips },
+ { ID_UZI_ITEM, ID_UZI_AMMO_ITEM, LaraWeaponType::Uzi, HolsterType::Hips},
+ { ID_SHOTGUN_ITEM, ID_SHOTGUN_AMMO1_ITEM, LaraWeaponType::Shotgun, HolsterType::Back },
+ { ID_CROSSBOW_ITEM, ID_CROSSBOW_AMMO1_ITEM, LaraWeaponType::Crossbow, HolsterType::Back},
+ { ID_REVOLVER_ITEM, ID_REVOLVER_AMMO_ITEM, LaraWeaponType::Revolver, HolsterType::Back},
+ { ID_HK_ITEM, ID_HK_AMMO_ITEM, LaraWeaponType::HK, HolsterType::Back},
+ { ID_GRENADE_GUN_ITEM, ID_GRENADE_AMMO1_ITEM, LaraWeaponType::GrenadeLauncher, HolsterType::Back },
+ { ID_ROCKET_LAUNCHER_ITEM, ID_ROCKET_LAUNCHER_AMMO_ITEM, LaraWeaponType::RocketLauncher, HolsterType::Back },
+ { ID_HARPOON_ITEM, ID_HARPOON_AMMO_ITEM, LaraWeaponType::HarpoonGun, HolsterType::Back }
}
};
@@ -50,10 +59,41 @@ static bool TryModifyWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID, int ammoAmo
// Set the SelectedAmmo type to WeaponAmmoType::Ammo1 (0) if adding the weapon for the first time.
// Note that this refers to the index of the weapon's ammo array, and not the weapon's actual ammunition count.
- if (!lara.Weapons[(int)info.LaraWeaponType].Present)
- lara.Weapons[(int)info.LaraWeaponType].SelectedAmmo = WeaponAmmoType::Ammo1;
+ auto& currWeapon = lara.Weapons[(int)info.LaraWeaponType];
+
+ if (!currWeapon.Present)
+ currWeapon.SelectedAmmo = WeaponAmmoType::Ammo1;
- lara.Weapons[(int)info.LaraWeaponType].Present = add;
+ currWeapon.Present = add;
+ if(!add)
+ {
+ if (info.LaraWeaponType == lara.Control.Weapon.GunType)
+ {
+ lara.Control.Weapon.RequestGunType = LaraWeaponType::None;
+
+ // If Lara has pistols and it's not the pistols we're removing, set them
+ // as the "next weapon" so that Lara equips them next.
+ if (LaraWeaponType::Pistol == info.LaraWeaponType || !lara.Weapons[(int)LaraWeaponType::Pistol].Present)
+ {
+ lara.Control.Weapon.LastGunType = LaraWeaponType::None;
+ }
+ else
+ {
+ lara.Control.Weapon.LastGunType = LaraWeaponType::Pistol;
+ }
+ }
+
+ if (HolsterType::Hips == info.Holster && lara.Control.Weapon.HolsterInfo.LeftHolster == HolsterSlotForWeapon(info.LaraWeaponType))
+ {
+ lara.Control.Weapon.HolsterInfo.LeftHolster = HolsterSlot::Empty;
+ lara.Control.Weapon.HolsterInfo.RightHolster = HolsterSlot::Empty;
+ }
+ else if (HolsterType::Back == info.Holster && lara.Control.Weapon.HolsterInfo.BackHolster == HolsterSlotForWeapon(info.LaraWeaponType))
+ {
+ lara.Control.Weapon.HolsterInfo.BackHolster = HolsterSlot::Empty;
+ }
+ }
+
auto ammoID = info.AmmoID;
return add ? TryAddingAmmo(lara, ammoID, ammoAmount) : TryRemovingAmmo(lara, ammoID, ammoAmount);
}
From 4e4ec4bb0b10a21c7f37ddf76198f5632aa07d36 Mon Sep 17 00:00:00 2001
From: hispidence
Date: Mon, 22 Aug 2022 14:03:18 +0100
Subject: [PATCH 029/106] Fix #689 in other situations
---
TombEngine/Game/pickup/pickup_weapon.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/TombEngine/Game/pickup/pickup_weapon.cpp b/TombEngine/Game/pickup/pickup_weapon.cpp
index d61b4f884..9fc1f4b0d 100644
--- a/TombEngine/Game/pickup/pickup_weapon.cpp
+++ b/TombEngine/Game/pickup/pickup_weapon.cpp
@@ -67,7 +67,7 @@ static bool TryModifyWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID, int ammoAmo
currWeapon.Present = add;
if(!add)
{
- if (info.LaraWeaponType == lara.Control.Weapon.GunType)
+ if (info.LaraWeaponType == lara.Control.Weapon.GunType || info.LaraWeaponType == lara.Control.Weapon.LastGunType)
{
lara.Control.Weapon.RequestGunType = LaraWeaponType::None;
From 221c89bb59b9257a75020e50878926cc00977a1c Mon Sep 17 00:00:00 2001
From: hispidence
Date: Mon, 22 Aug 2022 21:50:11 +0100
Subject: [PATCH 030/106] Revolver is a hips weapon
---
TombEngine/Game/pickup/pickup_weapon.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/TombEngine/Game/pickup/pickup_weapon.cpp b/TombEngine/Game/pickup/pickup_weapon.cpp
index 9fc1f4b0d..4e03ac4ea 100644
--- a/TombEngine/Game/pickup/pickup_weapon.cpp
+++ b/TombEngine/Game/pickup/pickup_weapon.cpp
@@ -30,7 +30,7 @@ static constexpr std::array kWeapons
{ ID_UZI_ITEM, ID_UZI_AMMO_ITEM, LaraWeaponType::Uzi, HolsterType::Hips},
{ ID_SHOTGUN_ITEM, ID_SHOTGUN_AMMO1_ITEM, LaraWeaponType::Shotgun, HolsterType::Back },
{ ID_CROSSBOW_ITEM, ID_CROSSBOW_AMMO1_ITEM, LaraWeaponType::Crossbow, HolsterType::Back},
- { ID_REVOLVER_ITEM, ID_REVOLVER_AMMO_ITEM, LaraWeaponType::Revolver, HolsterType::Back},
+ { ID_REVOLVER_ITEM, ID_REVOLVER_AMMO_ITEM, LaraWeaponType::Revolver, HolsterType::Hips},
{ ID_HK_ITEM, ID_HK_AMMO_ITEM, LaraWeaponType::HK, HolsterType::Back},
{ ID_GRENADE_GUN_ITEM, ID_GRENADE_AMMO1_ITEM, LaraWeaponType::GrenadeLauncher, HolsterType::Back },
{ ID_ROCKET_LAUNCHER_ITEM, ID_ROCKET_LAUNCHER_AMMO_ITEM, LaraWeaponType::RocketLauncher, HolsterType::Back },
From d186b15b98935e8716b064083059f124b0e3bad7 Mon Sep 17 00:00:00 2001
From: Sezz
Date: Tue, 23 Aug 2022 13:45:10 +1000
Subject: [PATCH 031/106] Fix horseman axe attacks
---
TombEngine/Objects/TR4/Entity/tr4_horseman.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/TombEngine/Objects/TR4/Entity/tr4_horseman.cpp b/TombEngine/Objects/TR4/Entity/tr4_horseman.cpp
index 55d173b21..fb1daf7fb 100644
--- a/TombEngine/Objects/TR4/Entity/tr4_horseman.cpp
+++ b/TombEngine/Objects/TR4/Entity/tr4_horseman.cpp
@@ -655,7 +655,7 @@ namespace TEN::Entities::TR4
if (!creature->Flags)
{
- if (item->TouchBits & 0x4000)
+ if (item->TouchBits & 0x60)
{
DoDamage(creature->Enemy, 100);
CreatureEffect2(item, HorsemanBite2, 3, item->Pose.Orientation.y, DoBloodSplat);
From 633ada9413ffe781e4a03ed2cf148fefbf4b410c Mon Sep 17 00:00:00 2001
From: Sezz
Date: Tue, 23 Aug 2022 14:00:34 +1000
Subject: [PATCH 032/106] Demagic horseman TouchBits
---
TombEngine/Objects/TR4/Entity/tr4_horseman.cpp | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/TombEngine/Objects/TR4/Entity/tr4_horseman.cpp b/TombEngine/Objects/TR4/Entity/tr4_horseman.cpp
index fb1daf7fb..fb40ecc75 100644
--- a/TombEngine/Objects/TR4/Entity/tr4_horseman.cpp
+++ b/TombEngine/Objects/TR4/Entity/tr4_horseman.cpp
@@ -18,12 +18,17 @@
#include "Specific/trmath.h"
using namespace TEN::Math::Random;
+using std::vector;
namespace TEN::Entities::TR4
{
const auto HorsemanBite1 = BiteInfo(Vector3::Zero, 6);
const auto HorsemanBite2 = BiteInfo(Vector3::Zero, 14);
const auto HorsemanBite3 = BiteInfo(Vector3::Zero, 10);
+ const vector HorsemanAxeAttackJoints = { 5, 6 };
+ const vector HorsemanKickAttackJoints = { 14 };
+ const vector HorsemanMountedAttackJoints = { 5, 6, 10 };
+ const vector HorsemanShieldAttackJoints = { 10 };
const auto HorseBite1 = BiteInfo(Vector3::Zero, 13);
const auto HorseBite2 = BiteInfo(Vector3::Zero, 17);
@@ -550,7 +555,7 @@ namespace TEN::Entities::TR4
case HORSEMAN_STATE_MOUNTED_ATTACK_RIGHT:
if (!creature->Flags)
{
- if (item->TouchBits & 0x60)
+ if (item->TestBits(JointBitType::Touch, HorsemanAxeAttackJoints))
{
DoDamage(creature->Enemy, 250);
CreatureEffect2(item, HorsemanBite1, 10, item->Pose.Orientation.y, DoBloodSplat);
@@ -566,7 +571,7 @@ namespace TEN::Entities::TR4
case HORSEMAN_STATE_MOUNTED_ATTACK_LEFT:
if (!creature->Flags)
{
- if (item->TouchBits & 0x4000)
+ if (item->TestBits(JointBitType::Touch, HorsemanKickAttackJoints))
{
DoDamage(creature->Enemy, 100);
CreatureEffect2(item, HorsemanBite2, 3, item->Pose.Orientation.y, DoBloodSplat);
@@ -655,7 +660,7 @@ namespace TEN::Entities::TR4
if (!creature->Flags)
{
- if (item->TouchBits & 0x60)
+ if (item->TestBits(JointBitType::Touch, HorsemanAxeAttackJoints))
{
DoDamage(creature->Enemy, 100);
CreatureEffect2(item, HorsemanBite2, 3, item->Pose.Orientation.y, DoBloodSplat);
@@ -696,16 +701,16 @@ namespace TEN::Entities::TR4
if (!creature->Flags)
{
- if (item->TouchBits & 0x460)
+ if (item->TestBits(JointBitType::Touch, HorsemanMountedAttackJoints))
{
LaraItem->HitStatus = true;
- if (item->TouchBits & 0x60)
+ if (item->TestBits(JointBitType::Touch, HorsemanAxeAttackJoints))
{
DoDamage(creature->Enemy, 250);
CreatureEffect2(horseItem, HorsemanBite1, 20, -1, DoBloodSplat);
}
- else if (item->TouchBits & 0x400)
+ else if (item->TestBits(JointBitType::Touch, HorsemanShieldAttackJoints))
{
DoDamage(creature->Enemy, 150);
CreatureEffect2(horseItem, HorsemanBite3, 10, -1, DoBloodSplat);
From 7ce086c0cbe25aa2a0f036a995946f43244633ca Mon Sep 17 00:00:00 2001
From: Sezz
Date: Tue, 23 Aug 2022 15:01:02 +1000
Subject: [PATCH 033/106] Demagic brown beast TouchBits
---
.../Objects/TR5/Entity/tr5_brownbeast.cpp | 28 +++++++++----------
TombEngine/Objects/TR5/Entity/tr5_cyborg.cpp | 12 +++-----
2 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/TombEngine/Objects/TR5/Entity/tr5_brownbeast.cpp b/TombEngine/Objects/TR5/Entity/tr5_brownbeast.cpp
index 5fffd2aa9..d71b9241b 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_brownbeast.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_brownbeast.cpp
@@ -14,6 +14,7 @@
#include "Specific/level.h"
using namespace TEN::Math::Random;
+using std::vector;
namespace TEN::Entities::Creatures::TR5
{
@@ -21,6 +22,8 @@ namespace TEN::Entities::Creatures::TR5
const auto BrownBeastBite1 = BiteInfo(Vector3::Zero, 16);
const auto BrownBeastBite2 = BiteInfo(Vector3::Zero, 22);
+ const vector BrownBeastAttackJoints1 = { 14, 15, 16, 17 };
+ const vector BrownBeastAttackJoints2 = { 20, 21, 22, 23 };
// TODO
enum BrownBeastState
@@ -39,11 +42,7 @@ namespace TEN::Entities::Creatures::TR5
auto* item = &g_Level.Items[itemNumber];
ClearItem(itemNumber);
-
- item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.TargetState = 1;
- item->Animation.ActiveState = 1;
+ SetAnimation(item, 0);
}
void ControlBrowsBeast(short itemNumber)
@@ -99,6 +98,7 @@ namespace TEN::Entities::Creatures::TR5
{
case 1:
creature->Flags = 0;
+
if (creature->Mood == MoodType::Attack)
{
if (distance <= pow(SECTOR(1), 2))
@@ -143,7 +143,7 @@ namespace TEN::Entities::Creatures::TR5
if (creature->Flags)
break;
- if (item->TouchBits & 0x3C000)
+ if (item->TestBits(JointBitType::Touch, BrownBeastAttackJoints1))
{
if (item->Animation.AnimNumber == Objects[ID_BROWN_BEAST].animIndex + 8)
{
@@ -157,7 +157,7 @@ namespace TEN::Entities::Creatures::TR5
}
}
- if (item->Animation.AnimNumber == Objects[ID_BROWN_BEAST].animIndex + 2)
+ if (item->Animation.AnimNumber == (Objects[ID_BROWN_BEAST].animIndex + 2))
{
if (item->Animation.FrameNumber > g_Level.Anims[item->Animation.AnimNumber].frameBase + 6 &&
item->Animation.FrameNumber < g_Level.Anims[item->Animation.AnimNumber].frameBase + 16)
@@ -170,13 +170,13 @@ namespace TEN::Entities::Creatures::TR5
}
}
- if (!(item->TouchBits & 0xF00000))
+ if (!item->TestBits(JointBitType::Touch, BrownBeastAttackJoints2))
break;
- if (item->Animation.AnimNumber == Objects[ID_BROWN_BEAST].animIndex + 8)
+ if (item->Animation.AnimNumber == (Objects[ID_BROWN_BEAST].animIndex + 8))
{
- if (item->Animation.FrameNumber > g_Level.Anims[item->Animation.AnimNumber].frameBase + 13 &&
- item->Animation.FrameNumber < g_Level.Anims[item->Animation.AnimNumber].frameBase + 20)
+ if (item->Animation.FrameNumber > (g_Level.Anims[item->Animation.AnimNumber].frameBase + 13) &&
+ item->Animation.FrameNumber < (g_Level.Anims[item->Animation.AnimNumber].frameBase + 20))
{
DoDamage(creature->Enemy, BROWN_BEAST_ATTACK_DAMAGE);
CreatureEffect2(item, BrownBeastBite2, 20, item->Pose.Orientation.y, DoBloodSplat);
@@ -185,10 +185,10 @@ namespace TEN::Entities::Creatures::TR5
}
}
- if (item->Animation.AnimNumber == Objects[ID_BROWN_BEAST].animIndex + 2)
+ if (item->Animation.AnimNumber == (Objects[ID_BROWN_BEAST].animIndex + 2))
{
- if (item->Animation.FrameNumber > g_Level.Anims[item->Animation.AnimNumber].frameBase + 33 &&
- item->Animation.FrameNumber < g_Level.Anims[item->Animation.AnimNumber].frameBase + 43)
+ if (item->Animation.FrameNumber > (g_Level.Anims[item->Animation.AnimNumber].frameBase + 33) &&
+ item->Animation.FrameNumber < (g_Level.Anims[item->Animation.AnimNumber].frameBase + 43))
{
DoDamage(creature->Enemy, BROWN_BEAST_ATTACK_DAMAGE);
CreatureEffect2(item, BrownBeastBite2, 20, item->Pose.Orientation.y, DoBloodSplat);
diff --git a/TombEngine/Objects/TR5/Entity/tr5_cyborg.cpp b/TombEngine/Objects/TR5/Entity/tr5_cyborg.cpp
index c0ab19da9..0c543d0d9 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_cyborg.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_cyborg.cpp
@@ -124,11 +124,7 @@ namespace TEN::Entities::Creatures::TR5
auto* item = &g_Level.Items[itemNumber];
ClearItem(itemNumber);
-
- item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex + 4;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.TargetState = CYBORG_STATE_IDLE;
- item->Animation.ActiveState = CYBORG_STATE_IDLE;
+ SetAnimation(item, CYBORG_ANIM_IDLE);
}
static void TriggerHitmanSparks(int x, int y, int z, short xv, short yv, short zv)
@@ -174,13 +170,13 @@ namespace TEN::Entities::Creatures::TR5
if (CreatureActive(itemNumber))
{
auto* item = &g_Level.Items[itemNumber];
- auto* creature = GetCreatureInfo(item);
auto* object = &Objects[item->ObjectNumber];
+ auto* creature = GetCreatureInfo(item);
short angle = 0;
- short joint2 = 0;
- short joint1 = 0;
short joint0 = 0;
+ short joint1 = 0;
+ short joint2 = 0;
int x = item->Pose.Position.x;
int z = item->Pose.Position.z;
From d4af4eedbdffc234378556bf3c9a0ebf9d7390ea Mon Sep 17 00:00:00 2001
From: Sezz
Date: Tue, 23 Aug 2022 16:16:18 +1000
Subject: [PATCH 034/106] Organise
---
TombEngine/Objects/TR2/Entity/tr2_shark.cpp | 40 +++--
.../Objects/TR2/Entity/tr2_silencer.cpp | 119 +++++++------
.../Objects/TR4/Entity/tr4_hammerhead.cpp | 163 +++++++++---------
TombEngine/Objects/TR4/Entity/tr4_harpy.cpp | 61 ++++---
.../Objects/TR4/Entity/tr4_knight_templar.cpp | 19 +-
TombEngine/Objects/TR4/Entity/tr4_mummy.cpp | 33 ++--
6 files changed, 207 insertions(+), 228 deletions(-)
diff --git a/TombEngine/Objects/TR2/Entity/tr2_shark.cpp b/TombEngine/Objects/TR2/Entity/tr2_shark.cpp
index 2f1ef3ae8..ba8a93458 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_shark.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_shark.cpp
@@ -11,9 +11,14 @@
#include "Specific/level.h"
#include "Specific/setup.h"
+using std::vector;
+
namespace TEN::Entities::Creatures::TR2
{
+ constexpr auto SHARK_BITE_ATTACK_DAMAGE = 400;
+
const auto SharkBite = BiteInfo(Vector3(17.0f, -22.0f, 344.0f), 12);
+ const vector SharkBiteAttackJoints = { 10, 12, 13 };
void SharkControl(short itemNumber)
{
@@ -21,7 +26,7 @@ namespace TEN::Entities::Creatures::TR2
return;
auto* item = &g_Level.Items[itemNumber];
- auto* info = GetCreatureInfo(item);
+ auto* creature = GetCreatureInfo(item);
short angle = 0;
short head = 0;
@@ -29,11 +34,7 @@ namespace TEN::Entities::Creatures::TR2
if (item->HitPoints <= 0)
{
if (item->Animation.ActiveState != 5)
- {
- item->Animation.AnimNumber = Objects[ID_SHARK].animIndex + 4;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = 5;
- }
+ SetAnimation(item, 4);
CreatureFloat(itemNumber);
return;
@@ -46,39 +47,40 @@ namespace TEN::Entities::Creatures::TR2
GetCreatureMood(item, &AI, true);
CreatureMood(item, &AI, true);
- angle = CreatureTurn(item, info->MaxTurn);
+ angle = CreatureTurn(item, creature->MaxTurn);
switch (item->Animation.ActiveState)
{
case 0:
- info->Flags = 0;
- info->MaxTurn = 0;
+ creature->MaxTurn = 0;
+ creature->Flags = 0;
if (AI.ahead && AI.distance < pow(SECTOR(0.75f), 2) && AI.zoneNumber == AI.enemyZone)
item->Animation.TargetState = 3;
else
item->Animation.TargetState = 1;
+
break;
case 1:
- info->MaxTurn = ANGLE(0.5f);
+ creature->MaxTurn = ANGLE(0.5f);
- if (info->Mood == MoodType::Bored)
+ if (creature->Mood == MoodType::Bored)
break;
else if (AI.ahead && AI.distance < pow(SECTOR(0.75f), 2))
item->Animation.TargetState = 0;
- else if (info->Mood == MoodType::Escape || AI.distance > pow(SECTOR(3), 2) || !AI.ahead)
+ else if (creature->Mood == MoodType::Escape || AI.distance > pow(SECTOR(3), 2) || !AI.ahead)
item->Animation.TargetState = 2;
break;
case 2:
- info->MaxTurn = ANGLE(2.0f);
- info->Flags = 0;
+ creature->MaxTurn = ANGLE(2.0f);
+ creature->Flags = 0;
- if (info->Mood == MoodType::Bored)
+ if (creature->Mood == MoodType::Bored)
item->Animation.TargetState = 1;
- else if (info->Mood == MoodType::Escape)
+ else if (creature->Mood == MoodType::Escape)
break;
else if (AI.ahead && AI.distance < pow(1365, 2) && AI.zoneNumber == AI.enemyZone)
{
@@ -95,11 +97,11 @@ namespace TEN::Entities::Creatures::TR2
if (AI.ahead)
head = AI.angle;
- if (!info->Flags && item->TouchBits & 0x3400)
+ if (!creature->Flags && item->TestBits(JointBitType::Touch, SharkBiteAttackJoints))
{
+ DoDamage(creature->Enemy, SHARK_BITE_ATTACK_DAMAGE);
CreatureEffect(item, SharkBite, DoBloodSplat);
- DoDamage(info->Enemy, 400);
- info->Flags = 1;
+ creature->Flags = 1;
}
break;
diff --git a/TombEngine/Objects/TR2/Entity/tr2_silencer.cpp b/TombEngine/Objects/TR2/Entity/tr2_silencer.cpp
index 6261b52d3..442333b9f 100644
--- a/TombEngine/Objects/TR2/Entity/tr2_silencer.cpp
+++ b/TombEngine/Objects/TR2/Entity/tr2_silencer.cpp
@@ -32,22 +32,17 @@ namespace TEN::Entities::Creatures::TR2
return;
auto* item = &g_Level.Items[itemNumber];
- auto* info = GetCreatureInfo(item);
+ auto* creature = GetCreatureInfo(item);
short angle = 0;
- short torsoX = 0;
- short torsoY = 0;
- short head = 0;
short tilt = 0;
+ Vector3Shrt extraHeadRot = Vector3Shrt::Zero;
+ Vector3Shrt extraTorsoRot = Vector3Shrt::Zero;
if (item->HitPoints <= 0)
{
if (item->Animation.ActiveState != 12 && item->Animation.ActiveState != 13)
- {
- item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex + 20;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = 13;
- }
+ SetAnimation(item, 20);
}
else
{
@@ -57,14 +52,15 @@ namespace TEN::Entities::Creatures::TR2
GetCreatureMood(item, &AI, true);
CreatureMood(item, &AI, true);
- angle = CreatureTurn(item, info->MaxTurn);
+ angle = CreatureTurn(item, creature->MaxTurn);
switch (item->Animation.ActiveState)
{
case 3:
+ creature->MaxTurn = 0;
+
if (AI.ahead)
- head = AI.angle;
- info->MaxTurn = 0;
+ extraHeadRot.y = AI.angle;
if (item->Animation.RequiredState)
item->Animation.TargetState = item->Animation.RequiredState;
@@ -72,34 +68,35 @@ namespace TEN::Entities::Creatures::TR2
break;
case 4:
- if (AI.ahead)
- head = AI.angle;
- info->MaxTurn = 0;
+ creature->MaxTurn = 0;
- if (info->Mood == MoodType::Escape)
+ if (AI.ahead)
+ extraHeadRot.y = AI.angle;
+
+ if (creature->Mood == MoodType::Escape)
{
- item->Animation.RequiredState = 2;
item->Animation.TargetState = 3;
+ item->Animation.RequiredState = 2;
}
else
{
if (Targetable(item, &AI))
{
- item->Animation.RequiredState = (GetRandomControl() >= 0x4000 ? 10 : 6);
item->Animation.TargetState = 3;
+ item->Animation.RequiredState = (GetRandomControl() >= 0x4000 ? 10 : 6);
}
- if (info->Mood == MoodType::Attack || !AI.ahead)
+ if (creature->Mood == MoodType::Attack || !AI.ahead)
{
if (AI.distance >= pow(SECTOR(2), 2))
{
- item->Animation.RequiredState = 2;
item->Animation.TargetState = 3;
+ item->Animation.RequiredState = 2;
}
else
{
- item->Animation.RequiredState = 1;
item->Animation.TargetState = 3;
+ item->Animation.RequiredState = 1;
}
}
else
@@ -108,14 +105,14 @@ namespace TEN::Entities::Creatures::TR2
{
if (GetRandomControl() < 2560)
{
- item->Animation.RequiredState = 1;
item->Animation.TargetState = 3;
+ item->Animation.RequiredState = 1;
}
}
else
{
- item->Animation.RequiredState = 5;
item->Animation.TargetState = 3;
+ item->Animation.RequiredState = 5;
}
}
}
@@ -124,36 +121,36 @@ namespace TEN::Entities::Creatures::TR2
case 1:
if (AI.ahead)
- head = AI.angle;
+ extraHeadRot.y = AI.angle;
- info->MaxTurn = 910;
+ creature->MaxTurn = 910;
- if (info->Mood == MoodType::Escape)
+ if (creature->Mood == MoodType::Escape)
item->Animation.TargetState = 2;
else if (Targetable(item, &AI))
{
- item->Animation.RequiredState = (GetRandomControl() >= 0x4000 ? 10 : 6);
item->Animation.TargetState = 3;
+ item->Animation.RequiredState = (GetRandomControl() >= 0x4000 ? 10 : 6);
}
else
{
if (AI.distance > pow(SECTOR(2), 2) || !AI.ahead)
item->Animation.TargetState = 2;
- if (info->Mood == MoodType::Bored && GetRandomControl() < 0x300)
+ if (creature->Mood == MoodType::Bored && GetRandomControl() < 0x300)
item->Animation.TargetState = 3;
}
break;
case 2:
- if (AI.ahead)
- head = AI.angle;
-
- info->MaxTurn = ANGLE(5.0f);
- info->Flags = 0;
+ creature->MaxTurn = ANGLE(5.0f);
+ creature->Flags = 0;
tilt = angle / 4;
- if (info->Mood == MoodType::Escape)
+ if (AI.ahead)
+ extraHeadRot.y = AI.angle;
+
+ if (creature->Mood == MoodType::Escape)
{
if (Targetable(item, &AI))
item->Animation.TargetState = 9;
@@ -169,7 +166,7 @@ namespace TEN::Entities::Creatures::TR2
break;
}
- else if (info->Mood == MoodType::Attack)
+ else if (creature->Mood == MoodType::Attack)
item->Animation.TargetState = (GetRandomControl() >= 0x4000) ? 3 : 2;
else
item->Animation.TargetState = 3;
@@ -177,19 +174,19 @@ namespace TEN::Entities::Creatures::TR2
break;
case 5:
- if (AI.ahead)
- head = AI.angle;
+ creature->MaxTurn = 0;
- info->MaxTurn = 0;
+ if (AI.ahead)
+ extraHeadRot.y = AI.angle;
if (Targetable(item, &AI))
{
- item->Animation.RequiredState = 6;
item->Animation.TargetState = 3;
+ item->Animation.RequiredState = 6;
}
else
{
- if (info->Mood == MoodType::Attack || GetRandomControl() < 0x100)
+ if (creature->Mood == MoodType::Attack || GetRandomControl() < 0x100)
item->Animation.TargetState = 3;
if (!AI.ahead)
item->Animation.TargetState = 3;
@@ -199,18 +196,18 @@ namespace TEN::Entities::Creatures::TR2
case 6:
case 10:
- info->MaxTurn = 0;
- info->Flags = 0;
+ creature->MaxTurn = 0;
+ creature->Flags = 0;
if (AI.ahead)
{
- torsoY = AI.angle;
- torsoX = AI.xAngle;
+ extraTorsoRot.x = AI.xAngle;
+ extraTorsoRot.y = AI.angle;
}
else
- head = AI.angle;
+ extraHeadRot.y = AI.angle;
- if (info->Mood == MoodType::Escape)
+ if (creature->Mood == MoodType::Escape)
item->Animation.TargetState = 3;
else if (Targetable(item, &AI))
item->Animation.TargetState = item->Animation.ActiveState != 6 ? 11 : 7;
@@ -221,38 +218,38 @@ namespace TEN::Entities::Creatures::TR2
case 7:
case 11:
- info->MaxTurn = 0;
+ creature->MaxTurn = 0;
if (AI.ahead)
{
- torsoY = AI.angle;
- torsoX = AI.xAngle;
+ extraTorsoRot.x = AI.xAngle;
+ extraTorsoRot.y = AI.angle;
}
else
- head = AI.angle;
+ extraHeadRot.y = AI.angle;
- if (!info->Flags)
+ if (!creature->Flags)
{
- ShotLara(item, &AI, SilencerGunBite, torsoY, 50);
- info->Flags = 1;
+ ShotLara(item, &AI, SilencerGunBite, extraTorsoRot.y, 50);
+ creature->Flags = 1;
}
break;
case 9:
- info->MaxTurn = ANGLE(5.0f);
+ creature->MaxTurn = ANGLE(5.0f);
if (AI.ahead)
{
- torsoY = AI.angle;
- torsoX = AI.xAngle;
+ extraTorsoRot.x = AI.xAngle;
+ extraTorsoRot.y = AI.angle;
}
else
- head = AI.angle;
+ extraHeadRot.y = AI.angle;
if (!item->Animation.RequiredState)
{
- if (!ShotLara(item, &AI, SilencerGunBite, torsoY, 50))
+ if (!ShotLara(item, &AI, SilencerGunBite, extraTorsoRot.y, 50))
item->Animation.TargetState = 2;
item->Animation.RequiredState = 9;
@@ -263,9 +260,9 @@ namespace TEN::Entities::Creatures::TR2
}
CreatureTilt(item, tilt);
- CreatureJoint(item, 0, torsoY);
- CreatureJoint(item, 1, torsoX);
- CreatureJoint(item, 2, head);
+ CreatureJoint(item, 0, extraTorsoRot.y);
+ CreatureJoint(item, 1, extraTorsoRot.x);
+ CreatureJoint(item, 2, extraHeadRot.y);
CreatureAnimation(itemNumber, angle, tilt);
}
}
diff --git a/TombEngine/Objects/TR4/Entity/tr4_hammerhead.cpp b/TombEngine/Objects/TR4/Entity/tr4_hammerhead.cpp
index 53c67e5b3..6533c94e1 100644
--- a/TombEngine/Objects/TR4/Entity/tr4_hammerhead.cpp
+++ b/TombEngine/Objects/TR4/Entity/tr4_hammerhead.cpp
@@ -60,109 +60,100 @@ namespace TEN::Entities::TR4
auto* item = &g_Level.Items[itemNumber];
ClearItem(itemNumber);
-
- item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex + HAMMERHEAD_ANIM_IDLE;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = HAMMERHEAD_STATE_IDLE;
- item->Animation.TargetState = HAMMERHEAD_STATE_IDLE;
+ SetAnimation(item, HAMMERHEAD_ANIM_IDLE);
}
void HammerheadControl(short itemNumber)
{
- if (CreatureActive(itemNumber))
+ if (!CreatureActive(itemNumber))
+ return;
+
+ auto* item = &g_Level.Items[itemNumber];
+ auto* creature = GetCreatureInfo(item);
+
+ if (item->HitPoints <= 0)
{
- auto* item = &g_Level.Items[itemNumber];
- auto* creature = GetCreatureInfo(item);
+ if (item->Animation.ActiveState != HAMMERHEAD_STATE_DEATH)
+ SetAnimation(item, HAMMERHEAD_ANIM_DEATH_START);
- if (item->HitPoints > 0)
+ item->HitPoints = 0;
+ CreatureFloat(itemNumber);
+ }
+ else
+ {
+ if (item->AIBits)
+ GetAITarget(creature);
+ else if (creature->HurtByLara)
+ creature->Enemy = LaraItem;
+
+ AI_INFO AI;
+ CreatureAIInfo(item, &AI);
+
+ if (!creature->Enemy->IsLara())
+ phd_atan(LaraItem->Pose.Position.z - item->Pose.Position.z, LaraItem->Pose.Position.x - item->Pose.Position.x);
+
+ GetCreatureMood(item, &AI, true);
+ CreatureMood(item, &AI, true);
+
+ short angle = CreatureTurn(item, creature->MaxTurn);
+
+ switch (item->Animation.ActiveState)
{
- if (item->AIBits)
- GetAITarget(creature);
- else if (creature->HurtByLara)
- creature->Enemy = LaraItem;
+ case HAMMERHEAD_STATE_IDLE:
+ item->Animation.TargetState = HAMMERHEAD_STATE_SWIM_SLOW;
+ creature->Flags = 0;
+ break;
- AI_INFO AI;
- CreatureAIInfo(item, &AI);
+ case HAMMERHEAD_STATE_SWIM_SLOW:
+ creature->MaxTurn = ANGLE(7.0f);
- if (creature->Enemy != LaraItem)
- phd_atan(LaraItem->Pose.Position.z - item->Pose.Position.z, LaraItem->Pose.Position.x - item->Pose.Position.x);
-
- GetCreatureMood(item, &AI, true);
- CreatureMood(item, &AI, true);
-
- short angle = CreatureTurn(item, creature->MaxTurn);
-
- switch (item->Animation.ActiveState)
+ if (AI.distance <= pow(SECTOR(1), 2))
{
- case HAMMERHEAD_STATE_IDLE:
- item->Animation.TargetState = HAMMERHEAD_STATE_SWIM_SLOW;
- creature->Flags = 0;
- break;
-
- case HAMMERHEAD_STATE_SWIM_SLOW:
- creature->MaxTurn = ANGLE(7.0f);
-
- if (AI.distance <= pow(SECTOR(1), 2))
- {
- if (AI.distance < pow(682, 2))
- item->Animation.TargetState = HAMMERHEAD_STATE_IDLE_BITE_ATTACK;
- }
- else
- item->Animation.TargetState = HAMMERHEAD_STATE_SWIM_FAST;
-
- break;
-
- case HAMMERHEAD_STATE_SWIM_FAST:
- if (AI.distance < pow(SECTOR(1), 2))
- item->Animation.TargetState = HAMMERHEAD_STATE_SWIM_SLOW;
-
- break;
-
- case HAMMERHEAD_STATE_IDLE_BITE_ATTACK:
- if (!creature->Flags)
- {
- if (item->TestBits(JointBitType::Touch, HammerheadBiteAttackJoints))
- {
- DoDamage(creature->Enemy, HAMMERHEAD_BITE_ATTACK_DAMAGE);
- CreatureEffect(item, HammerheadBite, DoBloodSplat);
- creature->Flags = 1;
- }
- }
-
- break;
-
- default:
- break;
+ if (AI.distance < pow(682, 2))
+ item->Animation.TargetState = HAMMERHEAD_STATE_IDLE_BITE_ATTACK;
}
-
- CreatureTilt(item, 0);
- CreatureJoint(item, 0, angle * -2);
- CreatureJoint(item, 1, angle * -2);
- CreatureJoint(item, 2, angle * -2);
- CreatureJoint(item, 3, angle * 2);
-
- // NOTE: in TR2 shark there was a call to CreatureKill with special kill anim
- // Hammerhead seems to not have it in original code but this check is still there as a leftover
- if (item->Animation.ActiveState == HAMMERHEAD_STATE_KILL)
- AnimateItem(item);
else
+ item->Animation.TargetState = HAMMERHEAD_STATE_SWIM_FAST;
+
+ break;
+
+ case HAMMERHEAD_STATE_SWIM_FAST:
+ if (AI.distance < pow(SECTOR(1), 2))
+ item->Animation.TargetState = HAMMERHEAD_STATE_SWIM_SLOW;
+
+ break;
+
+ case HAMMERHEAD_STATE_IDLE_BITE_ATTACK:
+ if (!creature->Flags)
{
- CreatureAnimation(itemNumber, angle, 0);
- CreatureUnderwater(item, 341);
+ if (item->TestBits(JointBitType::Touch, HammerheadBiteAttackJoints))
+ {
+ DoDamage(creature->Enemy, HAMMERHEAD_BITE_ATTACK_DAMAGE);
+ CreatureEffect(item, HammerheadBite, DoBloodSplat);
+ creature->Flags = 1;
+ }
}
+
+ break;
+
+ default:
+ break;
}
+
+ CreatureTilt(item, 0);
+ CreatureJoint(item, 0, angle * -2);
+ CreatureJoint(item, 1, angle * -2);
+ CreatureJoint(item, 2, angle * -2);
+ CreatureJoint(item, 3, angle * 2);
+
+ // NOTE: in TR2 shark there was a call to CreatureKill with special kill anim
+ // Hammerhead seems to not have it in original code but this check is still there as a leftover
+ if (item->Animation.ActiveState == HAMMERHEAD_STATE_KILL)
+ AnimateItem(item);
else
{
- item->HitPoints = 0;
-
- if (item->Animation.ActiveState != HAMMERHEAD_STATE_DEATH)
- {
- item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex + HAMMERHEAD_ANIM_DEATH_START;
- item->Animation.ActiveState = HAMMERHEAD_STATE_DEATH;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.FrameNumber].frameBase;
- }
-
- CreatureFloat(itemNumber);
+ CreatureAnimation(itemNumber, angle, 0);
+ CreatureUnderwater(item, 341);
}
}
}
diff --git a/TombEngine/Objects/TR4/Entity/tr4_harpy.cpp b/TombEngine/Objects/TR4/Entity/tr4_harpy.cpp
index ee80886b1..f23c2476a 100644
--- a/TombEngine/Objects/TR4/Entity/tr4_harpy.cpp
+++ b/TombEngine/Objects/TR4/Entity/tr4_harpy.cpp
@@ -75,31 +75,32 @@ namespace TEN::Entities::TR4
HARPY_ANIM_GLIDE = 18
};
- static void TriggerHarpyMissile(PHD_3DPOS* pose, short roomNumber, short mesh)
+ void TriggerHarpyMissile(PHD_3DPOS* pose, short roomNumber, short mesh)
{
short fxNumber = CreateNewEffect(roomNumber);
- if (fxNumber != -1)
- {
- auto* fx = &EffectList[fxNumber];
+ if (fxNumber == -1)
+ return;
- fx->pos.Position.x = pose->Position.x;
- fx->pos.Position.y = pose->Position.y - (GetRandomControl() & 0x3F) - 32;
- fx->pos.Position.z = pose->Position.z;
- fx->pos.Orientation.x = pose->Orientation.x;
- fx->pos.Orientation.y = pose->Orientation.y;
- fx->pos.Orientation.z = 0;
- fx->roomNumber = roomNumber;
- fx->counter = short(2 * GetRandomControl() + 0x8000);
- fx->objectNumber = ID_ENERGY_BUBBLES;
- fx->speed = (GetRandomControl() & 0x1F) + 96;
- fx->flag1 = mesh;
- fx->frameNumber = Objects[fx->objectNumber].meshIndex + mesh * 2;
- }
+ auto* fx = &EffectList[fxNumber];
+
+ fx->pos.Position.x = pose->Position.x;
+ fx->pos.Position.y = pose->Position.y - (GetRandomControl() & 0x3F) - 32;
+ fx->pos.Position.z = pose->Position.z;
+ fx->pos.Orientation.x = pose->Orientation.x;
+ fx->pos.Orientation.y = pose->Orientation.y;
+ fx->pos.Orientation.z = 0;
+ fx->roomNumber = roomNumber;
+ fx->counter = short(2 * GetRandomControl() + 0x8000);
+ fx->objectNumber = ID_ENERGY_BUBBLES;
+ fx->speed = (GetRandomControl() & 0x1F) + 96;
+ fx->flag1 = mesh;
+ fx->frameNumber = Objects[fx->objectNumber].meshIndex + mesh * 2;
}
- static void TriggerHarpyFlame(short itemNumber, ItemInfo* target, byte nodeNumber, short size)
+ void TriggerHarpyFlame(short itemNumber, ItemInfo* target, byte nodeNumber, short size)
{
auto* item = &g_Level.Items[itemNumber];
+
int dx = target->Pose.Position.x - item->Pose.Position.x;
int dz = target->Pose.Position.z - item->Pose.Position.z;
@@ -143,7 +144,7 @@ namespace TEN::Entities::TR4
}
}
- static void TriggerHarpySparks(ItemInfo* target, int x, int y, int z, short xv, short yv, short zv)
+ void TriggerHarpySparks(ItemInfo* target, int x, int y, int z, short xv, short yv, short zv)
{
int dx = target->Pose.Position.x - x;
int dz = target->Pose.Position.z - z;
@@ -180,12 +181,13 @@ namespace TEN::Entities::TR4
}
}
- static void DoHarpyEffects(ItemInfo* item, CreatureInfo* creature, short itemNumber)
+ void DoHarpyEffects(ItemInfo* item, CreatureInfo* creature, short itemNumber)
{
item->ItemFlags[0]++;
auto rh = Vector3Int(HarpyAttack1.Position);
GetJointAbsPosition(item, &rh, HarpyAttack1.meshNum);
+
auto lr = Vector3Int(HarpyAttack2.Position);
GetJointAbsPosition(item, &lr, HarpyAttack2.meshNum);
@@ -269,9 +271,9 @@ namespace TEN::Entities::TR4
if (item->HitPoints <= 0)
{
- int state = item->Animation.ActiveState - 9;
item->HitPoints = 0;
+ int state = item->Animation.ActiveState - 9;
if (state)
{
state--;
@@ -307,7 +309,7 @@ namespace TEN::Entities::TR4
{
item->Animation.TargetState = HARPY_STATE_DEATH_END;
item->Animation.IsAirborne = false;
- item->Animation.Velocity.y = 0;
+ item->Animation.Velocity.y = 0.0f;
item->Pose.Position.y = item->Floor;
}
@@ -322,10 +324,8 @@ namespace TEN::Entities::TR4
creature->Enemy = nullptr;
- for (int i = 0; i < ActiveCreatures.size(); i++)
+ for (auto& currentCreature : ActiveCreatures)
{
- auto* currentCreature = ActiveCreatures[i];
-
if (currentCreature->ItemNumber == NO_ITEM || currentCreature->ItemNumber == itemNumber)
continue;
@@ -348,7 +348,7 @@ namespace TEN::Entities::TR4
AI_INFO AI;
CreatureAIInfo(item, &AI);
- if (creature->Enemy != LaraItem)
+ if (!creature->Enemy->IsLara())
phd_atan(LaraItem->Pose.Position.z - item->Pose.Position.z, LaraItem->Pose.Position.x - item->Pose.Position.x);
GetCreatureMood(item, &AI, true);
@@ -437,10 +437,9 @@ namespace TEN::Entities::TR4
{
if (AI.distance >= pow(341, 2))
{
- if (AI.ahead &&
+ if (AI.ahead && TestProbability(0.5f) &&
AI.distance >= pow(SECTOR(2), 2) &&
- AI.distance > pow(SECTOR(3.5f), 2) &&
- TestProbability(0.5f))
+ AI.distance > pow(SECTOR(3.5f), 2))
{
item->Animation.TargetState = HARPY_STATE_FLAME_ATTACK;
item->ItemFlags[0] = 0;
@@ -507,7 +506,7 @@ namespace TEN::Entities::TR4
creature->MaxTurn = ANGLE(2.0f);
if (item->TestBits(JointBitType::Touch, HarpySwoopAttackJoints) ||
- creature->Enemy && !creature->Enemy->IsLara() &&
+ creature->Enemy != nullptr && !creature->Enemy->IsLara() &&
abs(creature->Enemy->Pose.Position.y - item->Pose.Position.y) <= SECTOR(1) &&
AI.distance < pow(SECTOR(2), 2))
{
@@ -526,7 +525,7 @@ namespace TEN::Entities::TR4
if (creature->Flags == 0 &&
(item->TestBits(JointBitType::Touch, HarpyStingerAttackJoints) ||
- creature->Enemy && !creature->Enemy->IsLara() &&
+ creature->Enemy != nullptr && !creature->Enemy->IsLara() &&
abs(creature->Enemy->Pose.Position.y - item->Pose.Position.y) <= SECTOR(1) &&
AI.distance < pow(SECTOR(2), 2)))
{
diff --git a/TombEngine/Objects/TR4/Entity/tr4_knight_templar.cpp b/TombEngine/Objects/TR4/Entity/tr4_knight_templar.cpp
index f211923c9..60185d1f0 100644
--- a/TombEngine/Objects/TR4/Entity/tr4_knight_templar.cpp
+++ b/TombEngine/Objects/TR4/Entity/tr4_knight_templar.cpp
@@ -62,10 +62,7 @@ namespace TEN::Entities::TR4
auto* item = &g_Level.Items[itemNumber];
ClearItem(itemNumber);
- item->Animation.AnimNumber = Objects[ID_KNIGHT_TEMPLAR].animIndex + KTEMPLAR_ANIM_IDLE;
- item->Animation.TargetState = KTEMPLAR_STATE_IDLE;
- item->Animation.ActiveState = KTEMPLAR_STATE_IDLE;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
+ SetAnimation(item, KTEMPLAR_ANIM_IDLE);
item->MeshBits &= 0xF7FF;
}
@@ -75,8 +72,14 @@ namespace TEN::Entities::TR4
return;
auto* item = &g_Level.Items[itemNumber];
- auto* creature = GetCreatureInfo(item);
auto* object = &Objects[item->ObjectNumber];
+ auto* creature = GetCreatureInfo(item);
+
+ short angle = 0;
+ short tilt = 0;
+ short joint0 = 0;
+ short joint1 = 0;
+ short joint2 = 0;
if (item->Animation.AnimNumber == object->animIndex ||
(item->Animation.AnimNumber - object->animIndex) == KTEMPLAR_ANIM_WALK_FORWARD_RIGHT_1 ||
@@ -92,12 +95,6 @@ namespace TEN::Entities::TR4
}
}
- short tilt = 0;
- short angle = 0;
- short joint0 = 0;
- short joint1 = 0;
- short joint2 = 0;
-
// Knight is immortal.
if (item->HitPoints < object->HitPoints)
item->HitPoints = object->HitPoints;
diff --git a/TombEngine/Objects/TR4/Entity/tr4_mummy.cpp b/TombEngine/Objects/TR4/Entity/tr4_mummy.cpp
index bd09df3ed..bbcf21b34 100644
--- a/TombEngine/Objects/TR4/Entity/tr4_mummy.cpp
+++ b/TombEngine/Objects/TR4/Entity/tr4_mummy.cpp
@@ -17,7 +17,7 @@ using std::vector;
namespace TEN::Entities::TR4
{
- constexpr auto MUMMY_ATTACK_DAMAGE = 100;
+ constexpr auto MUMMY_SWIPE_ATTACK_DAMAGE = 100;
constexpr auto MUMMY_IDLE_SWIPE_ATTACK_RANGE = SQUARE(SECTOR(0.5f));
constexpr auto MUMMY_WALK_SWIPE_ATTACK_RANGE = SQUARE(SECTOR(0.67f));
@@ -26,11 +26,12 @@ namespace TEN::Entities::TR4
constexpr auto MUMMY_ARMS_UP_RANGE = SQUARE(SECTOR(3));
constexpr auto MUMMY_AWARE_RANGE = SQUARE(SECTOR(7));
- #define MUMMY_WALK_TURN_ANGLE ANGLE(7.0f)
+ #define MUMMY_WALK_TURN_RATE_MAX ANGLE(7.0f)
+ #define MUMMY_ATTACK_TURN_RATE_MAX ANGLE(7.0f)
const auto MummyBite1 = BiteInfo(Vector3::Zero, 11);
const auto MummyBite2 = BiteInfo(Vector3::Zero, 14);
- const vector MummyAttackJoints { 11, 14 };
+ const vector MummySwipeAttackJoints { 11, 14 };
enum MummyState
{
@@ -81,16 +82,10 @@ namespace TEN::Entities::TR4
if (item->TriggerFlags == 2)
{
SetAnimation(item, MUMMY_ANIM_COLLAPSE_END);
- item->Animation.TargetState = MUMMY_STATE_INACTIVE_LYING_DOWN; // TODO: Check if needed. -- Sezz
- item->Animation.ActiveState = MUMMY_STATE_INACTIVE_LYING_DOWN;
item->Status -= ITEM_INVISIBLE;
}
else
- {
SetAnimation(item, MUMMY_ANIM_ARMS_CROSSED);
- item->Animation.TargetState = MUMMY_STATE_INACTIVE_ARMS_CROSSED; // TODO: Check if needed. -- Sezz
- item->Animation.ActiveState = MUMMY_STATE_INACTIVE_ARMS_CROSSED;
- }
}
void MummyControl(short itemNumber)
@@ -101,8 +96,8 @@ namespace TEN::Entities::TR4
auto* item = &g_Level.Items[itemNumber];
auto* creature = GetCreatureInfo(item);
- short tilt = 0;
short angle = 0;
+ short tilt = 0;
short joint0 = 0;
short joint1 = 0;
short joint2 = 0;
@@ -209,7 +204,7 @@ namespace TEN::Entities::TR4
}
else
{
- creature->MaxTurn = MUMMY_WALK_TURN_ANGLE;
+ creature->MaxTurn = MUMMY_WALK_TURN_RATE_MAX;
if (AI.distance >= MUMMY_ARMS_UP_RANGE)
{
@@ -223,7 +218,7 @@ namespace TEN::Entities::TR4
break;
case MUMMY_STATE_WALK_FORWARD_ARMS_UP:
- creature->MaxTurn = MUMMY_WALK_TURN_ANGLE;
+ creature->MaxTurn = MUMMY_WALK_TURN_RATE_MAX;
creature->Flags = 0;
if (AI.distance < MUMMY_IDLE_SWIPE_ATTACK_RANGE)
@@ -272,26 +267,26 @@ namespace TEN::Entities::TR4
case MUMMY_STATE_IDLE_SWIPE_ATTACK:
creature->MaxTurn = 0;
- if (abs(AI.angle) >= ANGLE(7.0f))
+ if (abs(AI.angle) >= MUMMY_ATTACK_TURN_RATE_MAX)
{
if (AI.angle >= 0)
- item->Pose.Orientation.y += ANGLE(7.0f);
+ item->Pose.Orientation.y += MUMMY_ATTACK_TURN_RATE_MAX;
else
- item->Pose.Orientation.y -= ANGLE(7.0f);
+ item->Pose.Orientation.y -= MUMMY_ATTACK_TURN_RATE_MAX;
}
else
item->Pose.Orientation.y += AI.angle;
if (!creature->Flags)
{
- if (item->TestBits(JointBitType::Touch, MummyAttackJoints))
+ if (item->TestBits(JointBitType::Touch, MummySwipeAttackJoints))
{
if (item->Animation.FrameNumber > g_Level.Anims[item->Animation.AnimNumber].frameBase &&
item->Animation.FrameNumber < g_Level.Anims[item->Animation.AnimNumber].frameEnd)
{
- DoDamage(creature->Enemy, MUMMY_ATTACK_DAMAGE);
+ DoDamage(creature->Enemy, MUMMY_SWIPE_ATTACK_DAMAGE);
- if (item->Animation.AnimNumber == Objects[item->ObjectNumber].animIndex + MUMMY_ANIM_IDLE_SWIPE_ATTACK_LEFT)
+ if (item->Animation.AnimNumber == (Objects[item->ObjectNumber].animIndex + MUMMY_ANIM_IDLE_SWIPE_ATTACK_LEFT))
CreatureEffect2(item, MummyBite1, 5, -1, DoBloodSplat);
else
CreatureEffect2(item, MummyBite2, 5, -1, DoBloodSplat);
@@ -309,11 +304,9 @@ namespace TEN::Entities::TR4
}
CreatureTilt(item, 0);
-
CreatureJoint(item, 0, joint0);
CreatureJoint(item, 1, joint1);
CreatureJoint(item, 2, joint2);
-
CreatureAnimation(itemNumber, angle, 0);
}
}
From c10b783bcbb1e36dc4d74283ffa5997f3cff71ce Mon Sep 17 00:00:00 2001
From: Sezz
Date: Tue, 23 Aug 2022 17:01:09 +1000
Subject: [PATCH 035/106] Organise
---
TombEngine/Objects/TR1/Entity/tr1_bear.cpp | 24 ++++++++----------
TombEngine/Objects/TR1/Entity/tr1_big_rat.cpp | 9 ++++---
TombEngine/Objects/TR1/Entity/tr1_centaur.cpp | 17 ++++++-------
.../Objects/TR1/Entity/tr1_doppelganger.cpp | 16 ++++++------
.../Objects/TR1/Entity/tr1_giant_mutant.cpp | 25 ++++++-------------
5 files changed, 38 insertions(+), 53 deletions(-)
diff --git a/TombEngine/Objects/TR1/Entity/tr1_bear.cpp b/TombEngine/Objects/TR1/Entity/tr1_bear.cpp
index e84b60561..709fc0a7f 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_bear.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_bear.cpp
@@ -83,8 +83,8 @@ namespace TEN::Entities::Creatures::TR1
auto* item = &g_Level.Items[itemNumber];
auto* creature = GetCreatureInfo(item);
- short head = 0;
short angle = 0;
+ short head = 0;
if (item->HitPoints <= 0)
{
@@ -119,8 +119,8 @@ namespace TEN::Entities::Creatures::TR1
{
if (creature->Flags && item->TestBits(JointBitType::Touch, BearAttackJoints))
{
- creature->Flags = 0;
DoDamage(creature->Enemy, BEAR_SLAM_DAMAGE);
+ creature->Flags = 0;
}
break;
@@ -143,12 +143,12 @@ namespace TEN::Entities::Creatures::TR1
if (item->HitStatus)
creature->Flags = 1;
- const bool laraDead = LaraItem->HitPoints <= 0;
+ bool isLaraDead = LaraItem->HitPoints <= 0;
switch (item->Animation.ActiveState)
{
case BEAR_STATE_IDLE:
- if (laraDead)
+ if (isLaraDead)
{
if (AI.bite && AI.distance < pow(BEAR_EAT_RANGE, 2))
item->Animation.TargetState = BEAR_STATE_EAT;
@@ -167,7 +167,7 @@ namespace TEN::Entities::Creatures::TR1
case BEAR_STATE_STROLL:
creature->MaxTurn = BEAR_WALK_TURN_RATE_MAX;
- if (laraDead && item->TestBits(JointBitType::Touch, BearAttackJoints) && AI.ahead)
+ if (isLaraDead && item->TestBits(JointBitType::Touch, BearAttackJoints) && AI.ahead)
item->Animation.TargetState = BEAR_STATE_IDLE;
else if (creature->Mood != MoodType::Bored)
{
@@ -178,8 +178,8 @@ namespace TEN::Entities::Creatures::TR1
}
else if (TestProbability(BEAR_ROAR_CHANCE))
{
- item->Animation.RequiredState = BEAR_STATE_ROAR;
item->Animation.TargetState = BEAR_STATE_IDLE;
+ item->Animation.RequiredState = BEAR_STATE_ROAR;
}
break;
@@ -188,11 +188,9 @@ namespace TEN::Entities::Creatures::TR1
creature->MaxTurn = BEAR_RUN_TURN_RATE_MAX;
if (item->TestBits(JointBitType::Touch, BearAttackJoints))
- {
DoDamage(creature->Enemy, BEAR_RUN_DAMAGE);
- }
- if (creature->Mood == MoodType::Bored || laraDead)
+ if (creature->Mood == MoodType::Bored || isLaraDead)
item->Animation.TargetState = BEAR_STATE_IDLE;
else if (AI.ahead && !item->Animation.RequiredState)
{
@@ -229,8 +227,8 @@ namespace TEN::Entities::Creatures::TR1
case BEAR_STATE_WALK_FORWARD:
if (creature->Flags)
{
- item->Animation.RequiredState = BEAR_STATE_STROLL;
item->Animation.TargetState = BEAR_STATE_REAR;
+ item->Animation.RequiredState = BEAR_STATE_STROLL;
}
else if (AI.ahead && item->TestBits(JointBitType::Touch, BearAttackJoints))
item->Animation.TargetState = BEAR_STATE_REAR;
@@ -241,13 +239,13 @@ namespace TEN::Entities::Creatures::TR1
}
else if (creature->Mood == MoodType::Bored || TestProbability(BEAR_ROAR_CHANCE))
{
- item->Animation.RequiredState = BEAR_STATE_ROAR;
item->Animation.TargetState = BEAR_STATE_REAR;
+ item->Animation.RequiredState = BEAR_STATE_ROAR;
}
else if (AI.distance > pow(BEAR_REAR_RANGE, 2) || TestProbability(BEAR_DROP_CHANCE))
{
- item->Animation.RequiredState = BEAR_STATE_IDLE;
item->Animation.TargetState = BEAR_STATE_REAR;
+ item->Animation.RequiredState = BEAR_STATE_IDLE;
}
break;
@@ -266,8 +264,8 @@ namespace TEN::Entities::Creatures::TR1
if (!item->Animation.RequiredState &&
item->TestBits(JointBitType::Touch, BearAttackJoints))
{
- CreatureEffect(item, BearBite, DoBloodSplat);
DoDamage(creature->Enemy, BEAR_ATTACK_DAMAGE);
+ CreatureEffect(item, BearBite, DoBloodSplat);
item->Animation.RequiredState = BEAR_STATE_IDLE;
}
diff --git a/TombEngine/Objects/TR1/Entity/tr1_big_rat.cpp b/TombEngine/Objects/TR1/Entity/tr1_big_rat.cpp
index 219a35439..649050997 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_big_rat.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_big_rat.cpp
@@ -115,10 +115,11 @@ namespace TEN::Entities::Creatures::TR1
auto* creature = GetCreatureInfo(item);
int waterHeight = GetRatWaterHeight(item);
- short head = 0;
- short angle = 0;
bool isOnWater = waterHeight != NO_HEIGHT;
+ short angle = 0;
+ short head = 0;
+
if (item->HitPoints <= 0)
{
if (item->Animation.ActiveState != BIG_RAT_STATE_LAND_DEATH &&
@@ -183,9 +184,9 @@ namespace TEN::Entities::Creatures::TR1
if (!item->Animation.RequiredState && AI.ahead &&
item->TestBits(JointBitType::Touch, BigRatBite.meshNum))
{
- item->Animation.RequiredState = BIG_RAT_STATE_IDLE;
DoDamage(creature->Enemy, BIG_RAT_BITE_ATTACK_DAMAGE);
CreatureEffect(item, BigRatBite, DoBloodSplat);
+ item->Animation.RequiredState = BIG_RAT_STATE_IDLE;
}
break;
@@ -194,9 +195,9 @@ namespace TEN::Entities::Creatures::TR1
if (!item->Animation.RequiredState && AI.ahead &&
item->TestBits(JointBitType::Touch, BigRatBite.meshNum))
{
- item->Animation.RequiredState = BIG_RAT_STATE_RUN_FORWARD;
DoDamage(creature->Enemy, BIG_RAT_POUNCE_ATTACK_DAMAGE);
CreatureEffect(item, BigRatBite, DoBloodSplat);
+ item->Animation.RequiredState = BIG_RAT_STATE_RUN_FORWARD;
}
break;
diff --git a/TombEngine/Objects/TR1/Entity/tr1_centaur.cpp b/TombEngine/Objects/TR1/Entity/tr1_centaur.cpp
index ffe8549a5..5bf82d856 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_centaur.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_centaur.cpp
@@ -23,15 +23,15 @@ using std::vector;
namespace TEN::Entities::Creatures::TR1
{
- constexpr auto CENTAUR_REAR_DAMAGE = 200;
- constexpr auto CENTAUR_REAR_RANGE = SECTOR(1.5f);
- constexpr auto CENTAUR_REAR_CHANCE = 0.003f;
+ constexpr auto CENTAUR_REAR_DAMAGE = 200;
+ constexpr auto CENTAUR_REAR_RANGE = SECTOR(1.5f);
+ constexpr auto CENTAUR_REAR_CHANCE = 0.003f;
constexpr auto CENTAUR_BOMB_VELOCITY = 20;
#define CENTAUR_TURN_RATE_MAX ANGLE(4.0f)
const auto CentaurRocketBite = BiteInfo(Vector3(11.0f, 415.0f, 41.0f), 13);
- const auto CentaurRearBite = BiteInfo(Vector3(50.0f, 30.0f, 0.0f), 5);
+ const auto CentaurRearBite = BiteInfo(Vector3(50.0f, 30.0f, 0.0f), 5);
const vector CentaurAttackJoints = { 0, 3, 4, 7, 8, 16, 17 };
enum CentaurState
@@ -58,17 +58,14 @@ namespace TEN::Entities::Creatures::TR1
auto* item = &g_Level.Items[itemNumber];
auto* creature = GetCreatureInfo(item);
- short head = 0;
+
short angle = 0;
+ short head = 0;
if (item->HitPoints <= 0)
{
if (item->Animation.ActiveState != CENTAUR_STATE_DEATH)
- {
- item->Animation.AnimNumber = Objects[ID_CENTAUR_MUTANT].animIndex + CENTAUR_ANIM_DEATH;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = CENTAUR_STATE_DEATH;
- }
+ SetAnimation(item, CENTAUR_ANIM_DEATH);
}
else
{
diff --git a/TombEngine/Objects/TR1/Entity/tr1_doppelganger.cpp b/TombEngine/Objects/TR1/Entity/tr1_doppelganger.cpp
index 7c9c06de0..29e45ce8e 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_doppelganger.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_doppelganger.cpp
@@ -80,26 +80,24 @@ namespace TEN::Entities::Creatures::TR1
int laraFloorHeight = GetCollision(LaraItem).Position.Floor;
// Animate bacon Lara, mirroring Lara's position.
- item->Animation.FrameNumber = LaraItem->Animation.FrameNumber;
item->Animation.AnimNumber = LaraItem->Animation.AnimNumber;
- item->Pose.Position.x = pos.x;
- item->Pose.Position.y = pos.y;
- item->Pose.Position.z = pos.z;
+ item->Animation.FrameNumber = LaraItem->Animation.FrameNumber;
+ item->Pose.Position = pos;
item->Pose.Orientation.x = LaraItem->Pose.Orientation.x;
item->Pose.Orientation.y = LaraItem->Pose.Orientation.y - ANGLE(180.0f);
item->Pose.Orientation.z = LaraItem->Pose.Orientation.z;
ItemNewRoom(itemNumber, LaraItem->RoomNumber);
// Compare floor heights.
- if (item->Floor >= laraFloorHeight + SECTOR(1) + 1 && // Add 1 to avoid bacon Lara dying when exiting water.
+ if (item->Floor >= (laraFloorHeight + SECTOR(1) + 1) && // Add 1 to avoid bacon Lara dying when exiting water.
!LaraItem->Animation.IsAirborne)
{
SetAnimation(item, LA_JUMP_WALL_SMASH_START);
- item->Animation.Velocity.z = 0;
- item->Animation.Velocity.y = 0;
item->Animation.IsAirborne = true;
- item->Data = -1;
+ item->Animation.Velocity.y = 0.0f;
+ item->Animation.Velocity.z = 0.0f;
item->Pose.Position.y += 50;
+ item->Data = -1;
}
}
@@ -114,8 +112,8 @@ namespace TEN::Entities::Creatures::TR1
item->Pose.Position.y = item->Floor;
TestTriggers(item, true);
- item->Animation.Velocity.y = 0;
item->Animation.IsAirborne = false;
+ item->Animation.Velocity.y = 0.0f;
item->Animation.TargetState = LS_DEATH;
item->Animation.RequiredState = LS_DEATH;
}
diff --git a/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.cpp b/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.cpp
index 9d9f200f7..e15d5e498 100644
--- a/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.cpp
+++ b/TombEngine/Objects/TR1/Entity/tr1_giant_mutant.cpp
@@ -69,17 +69,13 @@ namespace TEN::Entities::Creatures::TR1
auto* item = &g_Level.Items[itemNumber];
auto* creature = GetCreatureInfo(item);
- short head = 0;
short angle = 0;
+ short head = 0;
if (item->HitPoints <= 0)
{
if (item->Animation.ActiveState != MUTANT_STATE_DEATH)
- {
- item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex + MUTANT_ANIM_DEATH;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = MUTANT_STATE_DEATH;
- }
+ SetAnimation(item, MUTANT_ANIM_DEATH);
}
else
{
@@ -95,9 +91,7 @@ namespace TEN::Entities::Creatures::TR1
angle = (short)phd_atan(creature->Target.z - item->Pose.Position.z, creature->Target.x - item->Pose.Position.x) - item->Pose.Orientation.y;
if (item->TouchBits)
- {
DoDamage(creature->Enemy, MUTANT_CONTACT_DAMAGE);
- }
switch (item->Animation.ActiveState)
{
@@ -181,8 +175,8 @@ namespace TEN::Entities::Creatures::TR1
case MUTANT_STATE_ATTACK_1:
if (!creature->Flags && item->TestBits(JointBitType::Touch, MutantAttackRightJoints))
{
- creature->Flags = 1;
DoDamage(creature->Enemy, MUTANT_ATTACK_DAMAGE);
+ creature->Flags = 1;
}
break;
@@ -190,8 +184,8 @@ namespace TEN::Entities::Creatures::TR1
case MUTANT_STATE_ATTACK_2:
if (!creature->Flags && item->TestBits(JointBitType::Touch, MutantAttackJoints))
{
- creature->Flags = 1;
DoDamage(creature->Enemy, MUTANT_ATTACK_DAMAGE);
+ creature->Flags = 1;
}
break;
@@ -205,14 +199,11 @@ namespace TEN::Entities::Creatures::TR1
LaraItem->Animation.AnimNumber = Objects[ID_LARA_EXTRA_ANIMS].animIndex + LARA_GIANT_MUTANT_DEATH;
LaraItem->Animation.FrameNumber = g_Level.Anims[LaraItem->Animation.AnimNumber].frameBase;
- LaraItem->Animation.ActiveState = LaraItem->Animation.TargetState = 46;
- LaraItem->RoomNumber = item->RoomNumber;
- LaraItem->Pose.Position.x = item->Pose.Position.x;
- LaraItem->Pose.Position.y = item->Pose.Position.y;
- LaraItem->Pose.Position.z = item->Pose.Position.z;
- LaraItem->Pose.Orientation.y = item->Pose.Orientation.y;
- LaraItem->Pose.Orientation.x = LaraItem->Pose.Orientation.z = 0;
+ LaraItem->Animation.ActiveState = 46;
+ LaraItem->Animation.TargetState = 46;
LaraItem->Animation.IsAirborne = false;
+ LaraItem->Pose = PHD_3DPOS(item->Pose.Position, 0, item->Pose.Orientation.y, 0);
+ LaraItem->RoomNumber = item->RoomNumber;
LaraItem->HitPoints = -1;
Lara.Air = -1;
Lara.Control.HandStatus = HandStatus::Busy;
From abeb0920fda9833f83f98509fd880f8a6ede77f8 Mon Sep 17 00:00:00 2001
From: hispidence
Date: Tue, 23 Aug 2022 22:08:46 +0100
Subject: [PATCH 036/106] First stage of attempt to defuck inventory code and
allow to set/unset infinite ammo/consumables
---
TombEngine/Game/health.cpp | 2 +-
TombEngine/Game/pickup/pickup.cpp | 22 +++++++++--
TombEngine/Game/pickup/pickup.h | 5 ++-
TombEngine/Game/pickup/pickup_ammo.cpp | 39 +++++++++++++------
TombEngine/Game/pickup/pickup_ammo.h | 6 ++-
TombEngine/Game/pickup/pickup_consumable.cpp | 32 ++++++++++-----
TombEngine/Game/pickup/pickup_consumable.h | 6 ++-
TombEngine/Game/pickup/pickup_key_items.cpp | 31 ++++++++++-----
TombEngine/Game/pickup/pickup_key_items.h | 6 ++-
TombEngine/Game/pickup/pickup_misc_items.cpp | 10 +++--
TombEngine/Game/pickup/pickup_misc_items.h | 2 +
TombEngine/Game/pickup/pickup_weapon.cpp | 22 +++++------
TombEngine/Game/pickup/pickup_weapon.h | 6 ++-
TombEngine/Game/pickup/pickuputil.h | 7 ++++
.../Objects/TR4/Object/tr4_sarcophagus.cpp | 2 +-
.../TEN/Inventory/InventoryHandler.cpp | 21 ++++++----
16 files changed, 150 insertions(+), 69 deletions(-)
diff --git a/TombEngine/Game/health.cpp b/TombEngine/Game/health.cpp
index a106b100d..c3ab89b71 100644
--- a/TombEngine/Game/health.cpp
+++ b/TombEngine/Game/health.cpp
@@ -265,7 +265,7 @@ void AddDisplayPickup(GAME_OBJECT_ID objectNumber)
}
// No free slot found; pickup the object without displaying it.
- PickedUpObject(objectNumber, 0);
+ PickedUpObject(objectNumber, std::nullopt);
}
void InitialisePickupDisplay()
diff --git a/TombEngine/Game/pickup/pickup.cpp b/TombEngine/Game/pickup/pickup.cpp
index 67ab19a4e..93d778391 100644
--- a/TombEngine/Game/pickup/pickup.cpp
+++ b/TombEngine/Game/pickup/pickup.cpp
@@ -1,6 +1,7 @@
#include "framework.h"
#include "Game/pickup/pickup.h"
+#include "pickuputil.h"
#include "Game/animation.h"
#include "Game/camera.h"
#include "Game/collision/collide_item.h"
@@ -128,10 +129,23 @@ short RPickups[16];
short getThisItemPlease = NO_ITEM;
Vector3Int OldPickupPos;
-void PickedUpObject(GAME_OBJECT_ID objectID, int count)
+bool SetInventoryCount(GAME_OBJECT_ID objectID, int count)
+{
+ if (!TryModifyWeapon(Lara, objectID, count, ModificationType::Set) &&
+ !TryModifyingAmmo(Lara, objectID, count, ModificationType::Set) &&
+ !TryModifyingKeyItem(Lara, objectID, count, ModificationType::Set) &&
+ !TryModifyingConsumable(Lara, objectID, count, ModificationType::Set) &&
+ !TryModifyMiscCount(Lara, objectID, count, ModificationType::Set))
+ {
+ return false;
+ }
+ return true;
+}
+
+void PickedUpObject(GAME_OBJECT_ID objectID, std::optional count)
{
// see if the items fit into one of these easy groups
- if (!TryAddingWeapon(Lara, objectID, count) &&
+ if (!TryAddingWeapon(Lara, objectID) &&
!TryAddingAmmo(Lara, objectID, count) &&
!TryAddingKeyItem(Lara, objectID, count) &&
!TryAddingConsumable(Lara, objectID, count) &&
@@ -166,10 +180,10 @@ int GetInventoryCount(GAME_OBJECT_ID objectID)
return 0;
}
-void RemoveObjectFromInventory(GAME_OBJECT_ID objectID, int count)
+void RemoveObjectFromInventory(GAME_OBJECT_ID objectID, std::optional count)
{
// see if the items fit into one of these easy groups
- if (!TryRemovingWeapon(Lara, objectID, count) &&
+ if (!TryRemovingWeapon(Lara, objectID) &&
!TryRemovingAmmo(Lara, objectID, count) &&
!TryRemovingKeyItem(Lara, objectID, count) &&
!TryRemovingConsumable(Lara, objectID, count) &&
diff --git a/TombEngine/Game/pickup/pickup.h b/TombEngine/Game/pickup/pickup.h
index 6167b7fb4..e7fd887ec 100644
--- a/TombEngine/Game/pickup/pickup.h
+++ b/TombEngine/Game/pickup/pickup.h
@@ -11,8 +11,9 @@ extern short RPickups[16];
extern Vector3Int OldPickupPos;
void InitialisePickup(short itemNumber);
-void PickedUpObject(GAME_OBJECT_ID objectID, int count);
-void RemoveObjectFromInventory(GAME_OBJECT_ID objectID, int count);
+void PickedUpObject(GAME_OBJECT_ID objectID, std::optional count = std::nullopt);
+bool SetInventoryCount(GAME_OBJECT_ID objectID, int count);
+void RemoveObjectFromInventory(GAME_OBJECT_ID objectID, std::optional count = std::nullopt);
int GetInventoryCount(GAME_OBJECT_ID objectID);
void CollectCarriedItems(ItemInfo* item);
void PickupCollision(short itemNumber, ItemInfo* laraItem, CollisionInfo* coll);
diff --git a/TombEngine/Game/pickup/pickup_ammo.cpp b/TombEngine/Game/pickup/pickup_ammo.cpp
index 18eda360c..c994be5cf 100644
--- a/TombEngine/Game/pickup/pickup_ammo.cpp
+++ b/TombEngine/Game/pickup/pickup_ammo.cpp
@@ -34,7 +34,7 @@ static constexpr std::array kAmmo
}
};
-static bool TryModifyingAmmo(LaraInfo& lara, GAME_OBJECT_ID objectID, int amount, bool add)
+bool TryModifyingAmmo(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount, ModificationType modType)
{
int arrayPos = GetArraySlot(kAmmo, objectID);
if (-1 == arrayPos)
@@ -42,26 +42,41 @@ static bool TryModifyingAmmo(LaraInfo& lara, GAME_OBJECT_ID objectID, int amount
AmmoPickupInfo info = kAmmo[arrayPos];
- auto currentAmmo = lara.Weapons[(int)info.LaraWeaponType].Ammo[(int)info.AmmoType];
- if (!currentAmmo.hasInfinite())
+ auto & currentWeapon = lara.Weapons[(int)info.LaraWeaponType];
+ auto & currentAmmo = currentWeapon.Ammo[(int)info.AmmoType];
+
+ switch(modType)
{
- int defaultModify = add ? info.Amount : -info.Amount;
- int newVal = int{ currentAmmo.getCount() } + (amount ? amount : defaultModify);
- lara.Weapons[(int)info.LaraWeaponType].Ammo[(int)info.AmmoType] = std::max(0, newVal);
- }
+ case ModificationType::Set:
+ currentAmmo = amount.value();
+ currentAmmo.setInfinite(amount == -1);
+
+ break;
+
+ default:
+ if (!currentAmmo.hasInfinite())
+ {
+ int defaultModify = modType == ModificationType::Add ? info.Amount : -info.Amount;
+ int newVal = int{ currentAmmo.getCount() } + (amount.has_value() ? amount.value() : defaultModify);
+ currentAmmo = std::max(0, newVal);
+ }
+ break;
+ };
return true;
}
-// We need the extra bool because amount might be zero to signify the default amount.
-bool TryAddingAmmo(LaraInfo& lara, GAME_OBJECT_ID objectID, int amount)
+bool TryAddingAmmo(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount)
{
- return TryModifyingAmmo(lara, objectID, amount, true);
+ return TryModifyingAmmo(lara, objectID, amount, ModificationType::Add);
}
-bool TryRemovingAmmo(LaraInfo& lara, GAME_OBJECT_ID objectID, int amount)
+bool TryRemovingAmmo(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount)
{
- return TryModifyingAmmo(lara, objectID, -amount, false);
+ if (amount.has_value())
+ return TryModifyingAmmo(lara, objectID, -amount.value(), ModificationType::Remove);
+ else
+ return TryModifyingAmmo(lara, objectID, amount, ModificationType::Remove);
}
std::optional GetAmmoCount(LaraInfo& lara, GAME_OBJECT_ID objectID)
diff --git a/TombEngine/Game/pickup/pickup_ammo.h b/TombEngine/Game/pickup/pickup_ammo.h
index 83e685fed..4a05e92b2 100644
--- a/TombEngine/Game/pickup/pickup_ammo.h
+++ b/TombEngine/Game/pickup/pickup_ammo.h
@@ -1,8 +1,10 @@
#pragma once
+enum class ModificationType;
enum GAME_OBJECT_ID : short;
struct LaraInfo;
-bool TryAddingAmmo(LaraInfo&, GAME_OBJECT_ID objectID, int amount = 0);
-bool TryRemovingAmmo(LaraInfo&, GAME_OBJECT_ID objectID, int amount = 0);
+bool TryAddingAmmo(LaraInfo&, GAME_OBJECT_ID objectID, std::optional amount = std::nullopt);
+bool TryRemovingAmmo(LaraInfo&, GAME_OBJECT_ID objectID, std::optional amount = std::nullopt);
+bool TryModifyingAmmo(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount, ModificationType modType);
std::optional GetAmmoCount(LaraInfo&, GAME_OBJECT_ID objectID);
diff --git a/TombEngine/Game/pickup/pickup_consumable.cpp b/TombEngine/Game/pickup/pickup_consumable.cpp
index 29b7d1123..6ce0859c5 100644
--- a/TombEngine/Game/pickup/pickup_consumable.cpp
+++ b/TombEngine/Game/pickup/pickup_consumable.cpp
@@ -25,32 +25,44 @@ static constexpr std::array kConsumables =
}
};
-static bool TryModifyingConsumable(LaraInfo& lara, GAME_OBJECT_ID objectID, int amount, bool add)
+bool TryModifyingConsumable(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount, ModificationType modType)
{
int arrayPos = GetArraySlot(kConsumables, objectID);
if (-1 == arrayPos)
return false;
ConsumablePickupInfo info = kConsumables[arrayPos];
-
- if (lara.Inventory.*(info.Count) != -1)
+ auto & currentAmt = lara.Inventory.*(info.Count);
+ switch (modType)
{
- int defaultModify = add ? info.Amount : -info.Amount;
- int newVal = lara.Inventory.*(info.Count) + (amount ? amount : defaultModify);
- lara.Inventory.*(info.Count) = std::max(0, newVal);
+ case ModificationType::Set:
+ currentAmt = amount.value();
+ break;
+
+ default:
+ if (currentAmt != -1)
+ {
+ int defaultModify = ModificationType::Add == modType ? info.Amount : -info.Amount;
+ int newVal = currentAmt + (amount.has_value() ? amount.value() : defaultModify);
+ currentAmt = std::max(0, newVal);
+ }
+ break;
}
return true;
}
-bool TryAddingConsumable(LaraInfo& lara, GAME_OBJECT_ID objectID, int amount)
+bool TryAddingConsumable(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount)
{
- return TryModifyingConsumable(lara, objectID, amount, true);
+ return TryModifyingConsumable(lara, objectID, amount, ModificationType::Add);
}
-bool TryRemovingConsumable(LaraInfo& lara, GAME_OBJECT_ID objectID, int amount)
+bool TryRemovingConsumable(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount)
{
- return TryModifyingConsumable(lara, objectID, -amount, false);
+ if (amount.has_value())
+ return TryModifyingConsumable(lara, objectID, -amount.value(), ModificationType::Remove);
+ else
+ return TryModifyingConsumable(lara, objectID, amount, ModificationType::Remove);
}
std::optional GetConsumableCount(LaraInfo& lara, GAME_OBJECT_ID objectID)
diff --git a/TombEngine/Game/pickup/pickup_consumable.h b/TombEngine/Game/pickup/pickup_consumable.h
index e2c2d56d9..fcf3acf5b 100644
--- a/TombEngine/Game/pickup/pickup_consumable.h
+++ b/TombEngine/Game/pickup/pickup_consumable.h
@@ -1,8 +1,10 @@
#pragma once
+enum class ModificationType;
enum GAME_OBJECT_ID : short;
struct LaraInfo;
-bool TryAddingConsumable(LaraInfo&, GAME_OBJECT_ID objectID, int amount = 0);
-bool TryRemovingConsumable(LaraInfo&, GAME_OBJECT_ID objectID, int amount = 0);
+bool TryAddingConsumable(LaraInfo&, GAME_OBJECT_ID objectID, std::optional amount = 0);
+bool TryRemovingConsumable(LaraInfo&, GAME_OBJECT_ID objectID, std::optional amount = 0);
+bool TryModifyingConsumable(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount, ModificationType modType);
std::optional GetConsumableCount(LaraInfo&, GAME_OBJECT_ID objectID);
diff --git a/TombEngine/Game/pickup/pickup_key_items.cpp b/TombEngine/Game/pickup/pickup_key_items.cpp
index aa2a16572..0d1ca734e 100644
--- a/TombEngine/Game/pickup/pickup_key_items.cpp
+++ b/TombEngine/Game/pickup/pickup_key_items.cpp
@@ -2,7 +2,7 @@
#include "Game/pickup/pickup_key_items.h"
#include "Game/Lara/lara_struct.h"
-#include "Game/pickup/pickup_misc_items.h"
+#include "Game/pickup/pickuputil.h"
#include "Objects/objectslist.h"
template struct KeyPickupInfo
@@ -64,29 +64,42 @@ template<> static std::pair GetArrayInternal<0>(LaraInfo& lara, GA
return TestAgainstRange<0>(lara, objectID);
}
-static bool TryModifyingKeyItem(LaraInfo& lara, GAME_OBJECT_ID objectID, int amount, bool add)
+bool TryModifyingKeyItem(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount, ModificationType modType)
{
// kick off the recursion starting at the last element
auto result = GetArrayInternal(lara, objectID);
+
if (result.first)
{
- int defaultModify = add ? kDefaultPickupAmount : -kDefaultPickupAmount;
- int newVal = int{result.first[result.second]} + (amount ? amount : defaultModify);
- result.first[result.second] = std::max(0, newVal);
+ auto& amt = result.first[result.second];
+ switch (modType)
+ {
+ case ModificationType::Set:
+ // infinite key items not yet implemented
+ amt = amount.value();
+ break;
+ default:
+ int defaultModify = modType == ModificationType::Add ? kDefaultPickupAmount : -kDefaultPickupAmount;
+ int newVal = int{ result.first[result.second] } + (amount.has_value() ? amount.value() : defaultModify);
+ result.first[result.second] = std::max(0, newVal);
+ }
return true;
}
return false;
}
-bool TryAddingKeyItem(LaraInfo& lara, GAME_OBJECT_ID objectID, int count)
+bool TryAddingKeyItem(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount)
{
- return TryModifyingKeyItem(lara, objectID, count, true);
+ return TryModifyingKeyItem(lara, objectID, amount, ModificationType::Add);
}
-bool TryRemovingKeyItem(LaraInfo& lara, GAME_OBJECT_ID objectID, int count)
+bool TryRemovingKeyItem(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount)
{
- return TryModifyingKeyItem(lara, objectID, -count, false);
+ if(amount.has_value())
+ return TryModifyingKeyItem(lara, objectID, -amount.value(), ModificationType::Remove);
+ else
+ return TryModifyingKeyItem(lara, objectID, amount, ModificationType::Remove);
}
std::optional GetKeyItemCount(LaraInfo& lara, GAME_OBJECT_ID objectID)
diff --git a/TombEngine/Game/pickup/pickup_key_items.h b/TombEngine/Game/pickup/pickup_key_items.h
index 5160d0c96..4b17fe653 100644
--- a/TombEngine/Game/pickup/pickup_key_items.h
+++ b/TombEngine/Game/pickup/pickup_key_items.h
@@ -1,8 +1,10 @@
#pragma once
+enum class ModificationType;
enum GAME_OBJECT_ID : short;
struct LaraInfo;
-bool TryAddingKeyItem(LaraInfo& lara, GAME_OBJECT_ID objectID, int count);
-bool TryRemovingKeyItem(LaraInfo& lara, GAME_OBJECT_ID objectID, int count);
+bool TryAddingKeyItem(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount = std::nullopt);
+bool TryRemovingKeyItem(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount = std::nullopt);
+bool TryModifyingKeyItem(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount, ModificationType modType);
std::optional GetKeyItemCount(LaraInfo& lara, GAME_OBJECT_ID objectID);
diff --git a/TombEngine/Game/pickup/pickup_misc_items.cpp b/TombEngine/Game/pickup/pickup_misc_items.cpp
index afc74a7ee..347c6e408 100644
--- a/TombEngine/Game/pickup/pickup_misc_items.cpp
+++ b/TombEngine/Game/pickup/pickup_misc_items.cpp
@@ -1,7 +1,6 @@
#include "framework.h"
#include "Game/pickup/pickup_misc_items.h"
-#include
#include "Game/Lara/lara_struct.h"
#include "Game/pickup/pickuputil.h"
#include "Objects/objectslist.h"
@@ -33,11 +32,14 @@ auto LaserSightIsEquipped(LaraInfo& lara)
return false;
};
-static bool TryModifyMiscCount(LaraInfo & lara, GAME_OBJECT_ID objectID, bool add)
+bool TryModifyMiscCount(LaraInfo & lara, GAME_OBJECT_ID objectID, std::optional amount, ModificationType modType)
{
// If adding, replace the small/large waterskin with one of the requested
// capacity. If removing, only remove the waterskin if it contains the given
// capacity.
+
+ bool add = ModificationType::Add == modType || ((ModificationType::Set == modType) && amount != 0);
+
auto modifyWaterSkinAmount = [&](byte& currentFlag, byte newFlag)
{
if (add)
@@ -140,12 +142,12 @@ static bool TryModifyMiscCount(LaraInfo & lara, GAME_OBJECT_ID objectID, bool ad
bool TryAddMiscItem(LaraInfo & lara, GAME_OBJECT_ID objectID)
{
- return TryModifyMiscCount(lara, objectID, true);
+ return TryModifyMiscCount(lara, objectID, std::nullopt, ModificationType::Add);
}
bool TryRemoveMiscItem(LaraInfo & lara, GAME_OBJECT_ID objectID)
{
- return TryModifyMiscCount(lara, objectID, false);
+ return TryModifyMiscCount(lara, objectID, std::nullopt, ModificationType::Remove);
}
std::optional HasMiscItem(LaraInfo& lara, GAME_OBJECT_ID objectID)
diff --git a/TombEngine/Game/pickup/pickup_misc_items.h b/TombEngine/Game/pickup/pickup_misc_items.h
index 9b1784418..6d03ef06b 100644
--- a/TombEngine/Game/pickup/pickup_misc_items.h
+++ b/TombEngine/Game/pickup/pickup_misc_items.h
@@ -1,8 +1,10 @@
#pragma once
+enum class ModificationType;
enum GAME_OBJECT_ID : short;
struct LaraInfo;
bool TryAddMiscItem(LaraInfo& lara, GAME_OBJECT_ID objectID);
bool TryRemoveMiscItem(LaraInfo& lara, GAME_OBJECT_ID objectID);
+bool TryModifyMiscCount(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional amount, ModificationType modType);
std::optional HasMiscItem(LaraInfo& lara, GAME_OBJECT_ID objectID);
diff --git a/TombEngine/Game/pickup/pickup_weapon.cpp b/TombEngine/Game/pickup/pickup_weapon.cpp
index 4e03ac4ea..d2141b934 100644
--- a/TombEngine/Game/pickup/pickup_weapon.cpp
+++ b/TombEngine/Game/pickup/pickup_weapon.cpp
@@ -49,7 +49,7 @@ static int GetWeapon(GAME_OBJECT_ID objectID)
return -1;
}
-static bool TryModifyWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID, int ammoAmount, bool add)
+bool TryModifyWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional count, ModificationType type)
{
int arrayPos = GetArraySlot(kWeapons, objectID);
if (-1 == arrayPos)
@@ -63,8 +63,10 @@ static bool TryModifyWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID, int ammoAmo
if (!currWeapon.Present)
currWeapon.SelectedAmmo = WeaponAmmoType::Ammo1;
-
+
+ bool add = ModificationType::Add == type || ((ModificationType::Set == type) && count != 0);
currWeapon.Present = add;
+
if(!add)
{
if (info.LaraWeaponType == lara.Control.Weapon.GunType || info.LaraWeaponType == lara.Control.Weapon.LastGunType)
@@ -94,21 +96,19 @@ static bool TryModifyWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID, int ammoAmo
}
}
- auto ammoID = info.AmmoID;
- return add ? TryAddingAmmo(lara, ammoID, ammoAmount) : TryRemovingAmmo(lara, ammoID, ammoAmount);
+ return true;
}
-// Adding a weapon will either give the player the weapon + an amount of ammo, or,
-// if they already have the weapon, simply the ammo.
-bool TryAddingWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID, int amount)
+// Adding a weapon will not give the player any ammo even if they already have the weapon
+bool TryAddingWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID)
{
- return TryModifyWeapon(lara, objectID, amount, true);
+ return TryModifyWeapon(lara, objectID, 1, ModificationType::Add);
}
-// Removing a weapon is the reverse of the above; it will remove the weapon (if it's there) and the amount of ammo.
-bool TryRemovingWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID, int amount)
+// Removing a weapon is the reverse of the above; it will remove the weapon (if it's there).
+bool TryRemovingWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID)
{
- return TryModifyWeapon(lara, objectID, amount, false);
+ return TryModifyWeapon(lara, objectID, 1, ModificationType::Remove);
}
std::optional HasWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID)
diff --git a/TombEngine/Game/pickup/pickup_weapon.h b/TombEngine/Game/pickup/pickup_weapon.h
index d61f86dd9..7ae6ace52 100644
--- a/TombEngine/Game/pickup/pickup_weapon.h
+++ b/TombEngine/Game/pickup/pickup_weapon.h
@@ -1,8 +1,10 @@
#pragma once
+enum class ModificationType;
enum GAME_OBJECT_ID : short;
struct LaraInfo;
-bool TryAddingWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID, int amount = 0);
-bool TryRemovingWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID, int amount = 0);
+bool TryAddingWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID);
+bool TryRemovingWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID);
+bool TryModifyWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional count, ModificationType type);
std::optional HasWeapon(LaraInfo&, GAME_OBJECT_ID objectID);
diff --git a/TombEngine/Game/pickup/pickuputil.h b/TombEngine/Game/pickup/pickuputil.h
index 6904d15f5..9f1217459 100644
--- a/TombEngine/Game/pickup/pickuputil.h
+++ b/TombEngine/Game/pickup/pickuputil.h
@@ -2,6 +2,13 @@
enum GAME_OBJECT_ID : short;
+enum class ModificationType
+{
+ Add,
+ Remove,
+ Set
+};
+
// Given an array and an Object ID, iterate through the array until we find
// an ID that matches the ID we've passed in.
template int GetArraySlot(std::array const& arr, GAME_OBJECT_ID objectID)
diff --git a/TombEngine/Objects/TR4/Object/tr4_sarcophagus.cpp b/TombEngine/Objects/TR4/Object/tr4_sarcophagus.cpp
index de7c8f3ae..62a14b29f 100644
--- a/TombEngine/Objects/TR4/Object/tr4_sarcophagus.cpp
+++ b/TombEngine/Objects/TR4/Object/tr4_sarcophagus.cpp
@@ -86,7 +86,7 @@ void SarcophagusCollision(short itemNumber, ItemInfo* laraItem, CollisionInfo* c
{
if (Objects[currentItem->ObjectNumber].isPickup)
{
- PickedUpObject(static_cast(currentItem->ObjectNumber), 0);
+ PickedUpObject(currentItem->ObjectNumber);
currentItem->Status = ITEM_ACTIVE;
currentItem->ItemFlags[3] = 1;
AddDisplayPickup(currentItem->ObjectNumber);
diff --git a/TombEngine/Scripting/Internal/TEN/Inventory/InventoryHandler.cpp b/TombEngine/Scripting/Internal/TEN/Inventory/InventoryHandler.cpp
index 33e4f699b..3af82d1a1 100644
--- a/TombEngine/Scripting/Internal/TEN/Inventory/InventoryHandler.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Inventory/InventoryHandler.cpp
@@ -11,20 +11,29 @@ Inventory manipulation
@pragma nostrip
*/
+
namespace InventoryHandler
{
static void InventoryAdd(ItemEnumPair slot, sol::optional count)
{
- // If 0 is passed in, then the amount added will be the default amount
+ // If nil is passed in, then the amount added will be the default amount
// for that pickup - i.e. the amount you would get from picking up the
// item in-game (e.g. 1 for medipacks, 12 for flares).
- PickedUpObject(slot.m_pair.first, count.value_or(0));
+
+ //can't use value_or(std::nullopt) here because nullopt isn't an int
+ if (count.has_value())
+ PickedUpObject(slot.m_pair.first, count.value());
+ else
+ PickedUpObject(slot.m_pair.first, std::nullopt);
}
static void InventoryRemove(ItemEnumPair slot, sol::optional count)
{
- // 0 is default for the same reason as in InventoryAdd.
- RemoveObjectFromInventory(slot.m_pair.first, count.value_or(0));
+ //can't use value_or(std::nullopt) here because nullopt isn't an int
+ if (count.has_value())
+ RemoveObjectFromInventory(slot.m_pair.first, count.value());
+ else
+ RemoveObjectFromInventory(slot.m_pair.first, std::nullopt);
}
static int InventoryGetCount(ItemEnumPair slot)
@@ -34,9 +43,7 @@ namespace InventoryHandler
static void InventorySetCount(ItemEnumPair slot, int count)
{
- // add the amount we'd need to add to get to count
- int currAmt = GetInventoryCount(slot.m_pair.first);
- InventoryAdd(slot, count - currAmt);
+ SetInventoryCount(slot.m_pair.first, count);
}
static void InventoryCombine(int slot1, int slot2)
From 93a0539fcb9db912c3841f60016f8650c505a692 Mon Sep 17 00:00:00 2001
From: hispidence
Date: Tue, 23 Aug 2022 22:09:13 +0100
Subject: [PATCH 037/106] Cleanup
---
TombEngine/Game/health.cpp | 2 +-
TombEngine/Game/pickup/pickup.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/TombEngine/Game/health.cpp b/TombEngine/Game/health.cpp
index c3ab89b71..c955d436a 100644
--- a/TombEngine/Game/health.cpp
+++ b/TombEngine/Game/health.cpp
@@ -265,7 +265,7 @@ void AddDisplayPickup(GAME_OBJECT_ID objectNumber)
}
// No free slot found; pickup the object without displaying it.
- PickedUpObject(objectNumber, std::nullopt);
+ PickedUpObject(objectNumber);
}
void InitialisePickupDisplay()
diff --git a/TombEngine/Game/pickup/pickup.h b/TombEngine/Game/pickup/pickup.h
index e7fd887ec..cc55419e7 100644
--- a/TombEngine/Game/pickup/pickup.h
+++ b/TombEngine/Game/pickup/pickup.h
@@ -11,8 +11,8 @@ extern short RPickups[16];
extern Vector3Int OldPickupPos;
void InitialisePickup(short itemNumber);
-void PickedUpObject(GAME_OBJECT_ID objectID, std::optional count = std::nullopt);
bool SetInventoryCount(GAME_OBJECT_ID objectID, int count);
+void PickedUpObject(GAME_OBJECT_ID objectID, std::optional count = std::nullopt);
void RemoveObjectFromInventory(GAME_OBJECT_ID objectID, std::optional count = std::nullopt);
int GetInventoryCount(GAME_OBJECT_ID objectID);
void CollectCarriedItems(ItemInfo* item);
From 269104a41c8c7bfa301edb0a189cd33f56c45bfb Mon Sep 17 00:00:00 2001
From: hispidence
Date: Wed, 24 Aug 2022 15:00:56 +0100
Subject: [PATCH 038/106] Fix shotgun count and add documentation for new
inventory functions.
---
TombEngine/Game/pickup/pickup_ammo.cpp | 5 +-
.../TEN/Inventory/InventoryHandler.cpp | 55 +++++++++----------
2 files changed, 27 insertions(+), 33 deletions(-)
diff --git a/TombEngine/Game/pickup/pickup_ammo.cpp b/TombEngine/Game/pickup/pickup_ammo.cpp
index c994be5cf..b41cfc6d7 100644
--- a/TombEngine/Game/pickup/pickup_ammo.cpp
+++ b/TombEngine/Game/pickup/pickup_ammo.cpp
@@ -19,8 +19,8 @@ static constexpr std::array kAmmo
{
{ ID_PISTOLS_AMMO_ITEM, LaraWeaponType::Pistol, WeaponAmmoType::Ammo1, 0 },
{ ID_UZI_AMMO_ITEM, LaraWeaponType::Uzi, WeaponAmmoType::Ammo1, 30 },
- { ID_SHOTGUN_AMMO1_ITEM, LaraWeaponType::Shotgun, WeaponAmmoType::Ammo1, 36 },
- { ID_SHOTGUN_AMMO2_ITEM, LaraWeaponType::Shotgun, WeaponAmmoType::Ammo2, 36 },
+ { ID_SHOTGUN_AMMO1_ITEM, LaraWeaponType::Shotgun, WeaponAmmoType::Ammo1, 6 },
+ { ID_SHOTGUN_AMMO2_ITEM, LaraWeaponType::Shotgun, WeaponAmmoType::Ammo2, 6 },
{ ID_CROSSBOW_AMMO1_ITEM, LaraWeaponType::Crossbow, WeaponAmmoType::Ammo1, 10 },
{ ID_CROSSBOW_AMMO2_ITEM, LaraWeaponType::Crossbow, WeaponAmmoType::Ammo2, 10 },
{ ID_CROSSBOW_AMMO3_ITEM, LaraWeaponType::Crossbow, WeaponAmmoType::Ammo3, 10 },
@@ -50,7 +50,6 @@ bool TryModifyingAmmo(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional count)
{
// If nil is passed in, then the amount added will be the default amount
// for that pickup - i.e. the amount you would get from picking up the
// item in-game (e.g. 1 for medipacks, 12 for flares).
- //can't use value_or(std::nullopt) here because nullopt isn't an int
+ // can't use value_or(std::nullopt) here because nullopt isn't an int
if (count.has_value())
PickedUpObject(slot.m_pair.first, count.value());
else
PickedUpObject(slot.m_pair.first, std::nullopt);
}
+ ///Remove x of a certain item from the inventory.
+ //As in @{GiveItem}, omitting the count will remove the "default" amount of that item.
+ //Has no effect if the player has an infinite number of the item.
+ //@function TakeItem
+ //@tparam InvID item the item to be removed
+ //@int[opt] count the number of items to remove (default: the amount you would get from a pickup)
static void InventoryRemove(ItemEnumPair slot, sol::optional count)
{
//can't use value_or(std::nullopt) here because nullopt isn't an int
@@ -36,11 +50,20 @@ namespace InventoryHandler
RemoveObjectFromInventory(slot.m_pair.first, std::nullopt);
}
+ ///Set the amount of a certain item the player has in the inventory.
+ //Similar to @{GiveItem} but replaces with the new amount instead of adding it.
+ //@function SetItemCount
+ //@tparam InvID item the ID of the item to be set.
+ //@tparam int count the number of items the player will have. A value of -1 will give an infinite amount of that item.
static int InventoryGetCount(ItemEnumPair slot)
{
return GetInventoryCount(slot.m_pair.first);
}
+ ///Get the amount the player holds of an item.
+ //@function GetItemCount
+ //@tparam InvID item the ID item to check
+ //@treturn int the amount of the item the player has in the inventory. -1 indicates an infinite amount of that item.
static void InventorySetCount(ItemEnumPair slot, int count)
{
SetInventoryCount(slot.m_pair.first, count);
@@ -61,37 +84,9 @@ namespace InventoryHandler
sol::table table_inventory{ state->lua_state(), sol::create };
parent.set(ScriptReserved_Inventory, table_inventory);
- ///Add x of an item to the inventory.
- //A count of 0 will add the "default" amount of that item
- //(i.e. the amount the player would get from a pickup of that type).
- //For example, giving "zero" crossbow ammo would give the player
- //10 instead, whereas giving "zero" medkits would give the player 1 medkit.
- //@function GiveItem
- //@tparam InvID item the item to be added
- //@tparam int count the number of items to add (default: 0)
table_inventory.set_function(ScriptReserved_GiveInvItem, &InventoryAdd);
-
-
- //Remove x of a certain item from the inventory.
- //As in @{GiveItem}, a count of 0 will remove the "default" amount of that item.
- //@function TakeItem
- //@tparam InvID item the item to be removed
- //@tparam int count the number of items to remove (default: 0)
table_inventory.set_function(ScriptReserved_TakeInvItem, &InventoryRemove);
-
-
- ///Get the amount the player holds of an item.
- //@function GetItemCount
- //@tparam InvID item the ID item to check
- //@treturn int the amount of the item the player has in the inventory
table_inventory.set_function(ScriptReserved_GetInvItemCount, &InventoryGetCount);
-
-
- ///Set the amount of a certain item the player has in the inventory.
- //Similar to @{GiveItem} but replaces with the new amount instead of adding it.
- //@function SetItemCount
- //@tparam @{InvID} item the ID of the item to be set
- //@tparam int count the number of items the player will have
table_inventory.set_function(ScriptReserved_SetInvItemCount, &InventorySetCount);
}
}
From ec7ef1aa4aacacb9f742695d37fb51114b1c1719 Mon Sep 17 00:00:00 2001
From: hispidence
Date: Wed, 24 Aug 2022 15:01:46 +0100
Subject: [PATCH 039/106] Update docs
---
Documentation/doc/1 modules/Inventory.html | 105 ++++++++++++------
Documentation/doc/2 classes/Flow.Fog.html | 8 +-
Documentation/doc/2 classes/Flow.Level.html | 8 +-
.../doc/2 classes/Flow.Settings.html | 10 +-
.../doc/2 classes/Flow.SkyLayer.html | 8 +-
.../Scripting/Internal/TEN/Flow/Fog/Fog.cpp | 2 +-
.../Internal/TEN/Flow/Level/FlowLevel.cpp | 2 +-
.../Internal/TEN/Flow/Settings/Settings.cpp | 9 +-
.../Internal/TEN/Flow/SkyLayer/SkyLayer.cpp | 2 +-
9 files changed, 95 insertions(+), 59 deletions(-)
diff --git a/Documentation/doc/1 modules/Inventory.html b/Documentation/doc/1 modules/Inventory.html
index 2b13b1af3..d1f5c39fe 100644
--- a/Documentation/doc/1 modules/Inventory.html
+++ b/Documentation/doc/1 modules/Inventory.html
@@ -96,17 +96,21 @@
@@ -118,14 +122,15 @@
- GiveItem(item, count)
+ GiveItem(item[, count])
Add x of an item to the inventory.
-A count of 0 will add the "default" amount of that item
+Omitting the second argument will give the "default" amount of the item
(i.e. the amount the player would get from a pickup of that type).
-For example, giving "zero" crossbow ammo would give the player
-10 instead, whereas giving "zero" medkits would give the player 1 medkit.
+For example, giving crossbow ammo without specifying the number would give the player
+10 instead.
+Has no effect if the player has an infinite number of that item.
Parameters:
@@ -136,7 +141,62 @@ For example, giving "zero" crossbow ammo would give the player
count
int
- the number of items to add (default: 0)
+ the number of items to add (default: the amount you would get from a pickup)
+ (optional )
+
+
+
+
+
+
+
+
+
+
+ TakeItem(item[, count])
+
+
+ Remove x of a certain item from the inventory.
+As in GiveItem , omitting the count will remove the "default" amount of that item.
+Has no effect if the player has an infinite number of the item.
+
+
+ Parameters:
+
+ item
+ InvID
+ the item to be removed
+
+ count
+ int
+ the number of items to remove (default: the amount you would get from a pickup)
+ (optional )
+
+
+
+
+
+
+
+
+
+
+ SetItemCount(item, count)
+
+
+ Set the amount of a certain item the player has in the inventory.
+Similar to GiveItem but replaces with the new amount instead of adding it.
+
+
+ Parameters:
+
+ item
+ InvID
+ the ID of the item to be set.
+
+ count
+ int
+ the number of items the player will have. A value of -1 will give an infinite amount of that item.
@@ -165,37 +225,12 @@ For example, giving "zero" crossbow ammo would give the player
int
- the amount of the item the player has in the inventory
+ the amount of the item the player has in the inventory. -1 indicates an infinite amount of that item.
-
-
-
- SetItemCount(item, count)
-
-
- Set the amount of a certain item the player has in the inventory.
-Similar to GiveItem but replaces with the new amount instead of adding it.
-
-
- Parameters:
-
- item
- the ID of the item to be set
-
- count
- int
- the number of items the player will have
-
-
-
-
-
-
-
@@ -204,7 +239,7 @@ Similar to GiveItem but repla
generated by LDoc 1.4.6
-
Last updated 2022-08-19 00:04:24
+
Last updated 2022-08-24 15:00:16
diff --git a/Documentation/doc/2 classes/Flow.Fog.html b/Documentation/doc/2 classes/Flow.Fog.html
index 912f3ea19..f64efa973 100644
--- a/Documentation/doc/2 classes/Flow.Fog.html
+++ b/Documentation/doc/2 classes/Flow.Fog.html
@@ -112,7 +112,7 @@
- Fog.new(color, Min, Max)
+ Fog(color, Min, Max)
@@ -185,8 +185,8 @@
-
- Fog.new(color, Min, Max)
+
+ Fog(color, Min, Max)
@@ -227,7 +227,7 @@
generated by LDoc 1.4.6
-
Last updated 2022-08-19 00:04:24
+
Last updated 2022-08-24 15:00:16
diff --git a/Documentation/doc/2 classes/Flow.Level.html b/Documentation/doc/2 classes/Flow.Level.html
index 4e29132bb..4a604d46c 100644
--- a/Documentation/doc/2 classes/Flow.Level.html
+++ b/Documentation/doc/2 classes/Flow.Level.html
@@ -170,7 +170,7 @@
@@ -471,8 +471,8 @@ Must be at least 4.
-
- Level.new()
+
+ Level()
Make a new Level object.
@@ -496,7 +496,7 @@ Must be at least 4.
generated by LDoc 1.4.6
-
Last updated 2022-08-19 00:04:24
+
Last updated 2022-08-24 15:00:16
diff --git a/Documentation/doc/2 classes/Flow.Settings.html b/Documentation/doc/2 classes/Flow.Settings.html
index 95edfc4f5..6214d9b3c 100644
--- a/Documentation/doc/2 classes/Flow.Settings.html
+++ b/Documentation/doc/2 classes/Flow.Settings.html
@@ -115,19 +115,19 @@
How should the application respond to script errors?
Must be one of the following:
-ErrorMode.TERMINATE
- print to the log file and terminate the application when any script error is hit.
+ErrorMode.TERMINATE
- print to the log file and return to the title level when any script error is hit.
This is the one you will want to go for if you want to know IMMEDIATELY if something has gone wrong.
ErrorMode.WARN
- print to the log file and continue running the application when a recoverable script error is hit.
-Choose this one if terminating the application is too much for you. Note that unrecoverable errors will still terminate
-the application.
+Choose this one if booting to the title level is too much for you.
ErrorMode.SILENT
- do nothing when a recoverable script error is hit.
Think very carefully before using this setting. These error modes are here to help you to keep your scripts
working properly, but if you opt to ignore errors, you won't be alerted if you've misused a function or passed
an invalid argument.
-As with ErrorMode.WARN
, unrecoverable errors will still terminate the application.
+
In all of these modes, an unrecoverable error will boot you to the title level. If the title level itself
+has an unrecoverable error, the game will close.
@@ -143,7 +143,7 @@ an invalid argument.
generated by LDoc 1.4.6
-
Last updated 2022-08-19 00:04:24
+
Last updated 2022-08-24 15:00:16
diff --git a/Documentation/doc/2 classes/Flow.SkyLayer.html b/Documentation/doc/2 classes/Flow.SkyLayer.html
index 7fea04f07..bb74f9213 100644
--- a/Documentation/doc/2 classes/Flow.SkyLayer.html
+++ b/Documentation/doc/2 classes/Flow.SkyLayer.html
@@ -106,7 +106,7 @@
- SkyLayer.new(color, speed)
+ SkyLayer(color, speed)
@@ -161,8 +161,8 @@ Less is more. City of The Dead, for example, uses a speed value of 16.
-
- SkyLayer.new(color, speed)
+
+ SkyLayer(color, speed)
@@ -199,7 +199,7 @@ Less is more. City of The Dead, for example, uses a speed value of 16.
generated by LDoc 1.4.6
-
Last updated 2022-08-19 00:04:24
+
Last updated 2022-08-24 15:00:16
diff --git a/TombEngine/Scripting/Internal/TEN/Flow/Fog/Fog.cpp b/TombEngine/Scripting/Internal/TEN/Flow/Fog/Fog.cpp
index cae08ef39..cd6bbc0d2 100644
--- a/TombEngine/Scripting/Internal/TEN/Flow/Fog/Fog.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Flow/Fog/Fog.cpp
@@ -40,7 +40,7 @@ void Fog::Register(sol::table & parent)
@tparam int Min Distance fog starts (in Sectors)
@tparam int Max Distance fog ends (in Sectors)
@return A fog object.
-@function Fog.new
+@function Fog
*/
Fog::Fog(ScriptColor const& col, short minDistance, short maxDistance)
{
diff --git a/TombEngine/Scripting/Internal/TEN/Flow/Level/FlowLevel.cpp b/TombEngine/Scripting/Internal/TEN/Flow/Level/FlowLevel.cpp
index a3b8e0a47..9bbcdbf4a 100644
--- a/TombEngine/Scripting/Internal/TEN/Flow/Level/FlowLevel.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Flow/Level/FlowLevel.cpp
@@ -11,7 +11,7 @@ These are things things which aren't present in the compiled level file itself.
*/
/*** Make a new Level object.
- @function Level.new
+ @function Level
@return a Level object
*/
void Level::Register(sol::table & parent)
diff --git a/TombEngine/Scripting/Internal/TEN/Flow/Settings/Settings.cpp b/TombEngine/Scripting/Internal/TEN/Flow/Settings/Settings.cpp
index 269e554a0..bcb0e5de2 100644
--- a/TombEngine/Scripting/Internal/TEN/Flow/Settings/Settings.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Flow/Settings/Settings.cpp
@@ -15,19 +15,20 @@ void Settings::Register(sol::table & parent)
/*** How should the application respond to script errors?
Must be one of the following:
-`ErrorMode.TERMINATE` - print to the log file and terminate the application when any script error is hit.
+`ErrorMode.TERMINATE` - print to the log file and return to the title level when any script error is hit.
This is the one you will want to go for if you want to know IMMEDIATELY if something has gone wrong.
`ErrorMode.WARN` - print to the log file and continue running the application when a recoverable script error is hit.
-Choose this one if terminating the application is too much for you. Note that unrecoverable errors will still terminate
-the application.
+Choose this one if booting to the title level is too much for you.
`ErrorMode.SILENT` - do nothing when a recoverable script error is hit.
Think __very__ carefully before using this setting. These error modes are here to help you to keep your scripts
working properly, but if you opt to ignore errors, you won't be alerted if you've misused a function or passed
an invalid argument.
-As with `ErrorMode.WARN`, unrecoverable errors will still terminate the application.
+In all of these modes, an *unrecoverable* error will boot you to the title level. If the title level itself
+has an unrecoverable error, the game will close.
+
@mem errorMode
*/
"errorMode", &Settings::ErrorMode
diff --git a/TombEngine/Scripting/Internal/TEN/Flow/SkyLayer/SkyLayer.cpp b/TombEngine/Scripting/Internal/TEN/Flow/SkyLayer/SkyLayer.cpp
index a46442134..3bc4271ee 100644
--- a/TombEngine/Scripting/Internal/TEN/Flow/SkyLayer/SkyLayer.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Flow/SkyLayer/SkyLayer.cpp
@@ -37,7 +37,7 @@ Less is more. City of The Dead, for example, uses a speed value of 16.
@tparam Color color RGB color
@tparam int speed cloud speed
@return A SkyLayer object.
-@function SkyLayer.new
+@function SkyLayer
*/
SkyLayer::SkyLayer(ScriptColor const& col, short speed)
{
From b0ed147c936686f7c333a07f986f40c12fcb36f2 Mon Sep 17 00:00:00 2001
From: hispidence
Date: Wed, 24 Aug 2022 23:23:57 +0100
Subject: [PATCH 040/106] Fix #700
---
TombEngine/Game/gui.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/TombEngine/Game/gui.cpp b/TombEngine/Game/gui.cpp
index 7eaa1bd2b..f5f0ec7a2 100644
--- a/TombEngine/Game/gui.cpp
+++ b/TombEngine/Game/gui.cpp
@@ -1495,7 +1495,7 @@ void GuiController::SetupAmmoSelector()
{
num++;
ammo_object_list[0].invitem = INV_OBJECT_PISTOLS_AMMO;
- ammo_object_list[0].amount = -1;
+ ammo_object_list[0].amount = AmountPistolsAmmo;
num_ammo_slots = num;
current_ammo_type = &CurrentPistolsAmmoType;
}
From 0a630c8e52fda772b4397a401c71813ce8b8fde6 Mon Sep 17 00:00:00 2001
From: hispidence
Date: Wed, 24 Aug 2022 23:30:23 +0100
Subject: [PATCH 041/106] Remove New to finally hopefully kill the new/New
discourse (the correct way is to use neither)
---
.../Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp | 1 -
.../Internal/TEN/Strings/DisplayString/DisplayString.cpp | 1 -
2 files changed, 2 deletions(-)
diff --git a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
index 8edc6cb58..365f1e466 100644
--- a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
@@ -132,7 +132,6 @@ static std::unique_ptr Create(
void Moveable::Register(sol::table & parent)
{
parent.new_usertype(LUA_CLASS_NAME,
- ScriptReserved_New, Create,
sol::call_constructor, Create,
sol::meta_function::index, index_error,
sol::meta_function::new_index, newindex_error,
diff --git a/TombEngine/Scripting/Internal/TEN/Strings/DisplayString/DisplayString.cpp b/TombEngine/Scripting/Internal/TEN/Strings/DisplayString/DisplayString.cpp
index 1b0cc600a..7da684e54 100644
--- a/TombEngine/Scripting/Internal/TEN/Strings/DisplayString/DisplayString.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Strings/DisplayString/DisplayString.cpp
@@ -93,7 +93,6 @@ void DisplayString::Register(sol::table & parent)
{
parent.new_usertype(
ScriptReserved_DisplayString,
- ScriptReserved_New, &CreateString,
sol::call_constructor, &CreateString,
/// Get the display string's color
From e7a1a06cd6c5f9eae855ae7dc8240cd1c2f620d4 Mon Sep 17 00:00:00 2001
From: hispidence
Date: Thu, 25 Aug 2022 00:07:48 +0100
Subject: [PATCH 042/106] Add Lua changes to Changex.txt.
---
Documentation/Changes.txt | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/Documentation/Changes.txt b/Documentation/Changes.txt
index 2e7d80d69..6817f5cf4 100644
--- a/Documentation/Changes.txt
+++ b/Documentation/Changes.txt
@@ -1,3 +1,12 @@
+Version 1.0.2
+=============
+
+- EventSequence and Timer no longer require you to call Timer.UpdateAll in OnControlPhase.
+- TEN.Logic.AddCallback and TEN.Logic.RemoveCallback have been added.
+- GiveItem, TakeItem, and SetItemCount have been reworked (e.g. SetItemCount with a value of -1 can give infinite ammo/consumables).
+- Removing Pistols with TakeItem and SetItemCount now works correctly.
+- Vec3s can now be saved and loaded in LevelVars and GameVars.
+
Version 1.0.1
=============
From 5fd30e05a162bc03802e80c0452df22d114fef0e Mon Sep 17 00:00:00 2001
From: hispidence
Date: Thu, 25 Aug 2022 00:07:48 +0100
Subject: [PATCH 043/106] Add Lua changes to Changes.txt.
---
Documentation/Changes.txt | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/Documentation/Changes.txt b/Documentation/Changes.txt
index 2e7d80d69..6817f5cf4 100644
--- a/Documentation/Changes.txt
+++ b/Documentation/Changes.txt
@@ -1,3 +1,12 @@
+Version 1.0.2
+=============
+
+- EventSequence and Timer no longer require you to call Timer.UpdateAll in OnControlPhase.
+- TEN.Logic.AddCallback and TEN.Logic.RemoveCallback have been added.
+- GiveItem, TakeItem, and SetItemCount have been reworked (e.g. SetItemCount with a value of -1 can give infinite ammo/consumables).
+- Removing Pistols with TakeItem and SetItemCount now works correctly.
+- Vec3s can now be saved and loaded in LevelVars and GameVars.
+
Version 1.0.1
=============
From b9a0e692af37bf73654b74df284de2c50925d01f Mon Sep 17 00:00:00 2001
From: hispidence
Date: Thu, 25 Aug 2022 21:28:59 +0100
Subject: [PATCH 044/106] Part 1 of hopefully fixing #671.
---
TombEngine/Game/items.cpp | 5 ++++-
TombEngine/Game/items.h | 1 +
.../Internal/TEN/Objects/Moveable/MoveableObject.cpp | 4 ++++
TombEngine/Specific/level.cpp | 1 +
4 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/TombEngine/Game/items.cpp b/TombEngine/Game/items.cpp
index 2d3a5bb19..6a2e9a1bc 100644
--- a/TombEngine/Game/items.cpp
+++ b/TombEngine/Game/items.cpp
@@ -447,6 +447,8 @@ void InitialiseItem(short itemNumber)
{
auto* item = &g_Level.Items[itemNumber];
+ item->VectorIndex = itemNumber;
+
item->Animation.AnimNumber = Objects[item->ObjectNumber].animIndex;
item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
@@ -552,6 +554,7 @@ void InitialiseItemArray(int totalItem)
{
for(int i = g_Level.NumItems + 1; i < totalItem; i++, item++)
{
+ item->VectorIndex = i-1;
item->NextItem = i;
item->Active = false;
item->Data = nullptr;
@@ -616,7 +619,7 @@ void UpdateItemRoom(ItemInfo* item, int height, int xOffset, int zOffset)
item->Floor = GetFloorHeight(item->Location, x, z).value_or(NO_HEIGHT);
if (item->RoomNumber != item->Location.roomNumber)
- ItemNewRoom(FindItem(item), item->Location.roomNumber);
+ ItemNewRoom(item->VectorIndex, item->Location.roomNumber);
}
std::vector FindAllItems(short objectNumber)
diff --git a/TombEngine/Game/items.h b/TombEngine/Game/items.h
index c923a7e1e..79b43c4d3 100644
--- a/TombEngine/Game/items.h
+++ b/TombEngine/Game/items.h
@@ -69,6 +69,7 @@ struct EntityAnimationData
//todo we need to find good "default states" for a lot of these - squidshire 25/05/2022
struct ItemInfo
{
+ short VectorIndex = -1;
GAME_OBJECT_ID ObjectNumber;
int Status; // ItemStatus enum.
bool Active;
diff --git a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
index 365f1e466..50184f6d5 100644
--- a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
@@ -562,6 +562,10 @@ Vec3 Moveable::GetPos() const
void Moveable::SetPos(Vec3 const& pos)
{
pos.StoreInPHDPos(m_item->Pose);
+
+ //todo make a non-updating version
+ if(m_initialised)
+ UpdateItemRoom(m_item, pos.y);
}
Vec3 Moveable::GetJointPos(int jointIndex) const
diff --git a/TombEngine/Specific/level.cpp b/TombEngine/Specific/level.cpp
index 4a5bc417a..afa0953eb 100644
--- a/TombEngine/Specific/level.cpp
+++ b/TombEngine/Specific/level.cpp
@@ -172,6 +172,7 @@ void LoadItems()
{
ItemInfo* item = &g_Level.Items[i];
+ item->VectorIndex = i;
item->Data = ITEM_DATA{};
item->ObjectNumber = from_underlying(ReadInt16());
item->RoomNumber = ReadInt16();
From dad4ac26f942e4c635ab412e97e4a6d30abe8a70 Mon Sep 17 00:00:00 2001
From: hispidence
Date: Thu, 25 Aug 2022 22:52:54 +0100
Subject: [PATCH 045/106] Part 2 of fixing #671
---
TombEngine/Game/items.cpp | 1 -
.../TEN/Objects/Moveable/MoveableObject.cpp | 59 +++++++++++--------
.../TEN/Objects/Moveable/MoveableObject.h | 2 +-
3 files changed, 34 insertions(+), 28 deletions(-)
diff --git a/TombEngine/Game/items.cpp b/TombEngine/Game/items.cpp
index 6a2e9a1bc..fa64a1522 100644
--- a/TombEngine/Game/items.cpp
+++ b/TombEngine/Game/items.cpp
@@ -605,7 +605,6 @@ int GlobalItemReplace(short search, GAME_OBJECT_ID replace)
}
// Offset values may be used to account for the quirk of room traversal only being able to occur at portals.
-// Note: may not work for dynamic items because of FindItem.
void UpdateItemRoom(ItemInfo* item, int height, int xOffset, int zOffset)
{
float sinY = phd_sin(item->Pose.Orientation.y);
diff --git a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
index 50184f6d5..43b9c6e6d 100644
--- a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
@@ -94,7 +94,7 @@ static std::unique_ptr Create(
std::string const & name,
Vec3 const & pos,
TypeOrNil const & rot,
- short room,
+ TypeOrNil room,
TypeOrNil animNumber,
TypeOrNil frameNumber,
TypeOrNil hp,
@@ -108,9 +108,15 @@ static std::unique_ptr Create(
if (ScriptAssert(ptr->SetName(name), "Could not set name for Moveable; returning an invalid object."))
{
ItemInfo* item = &g_Level.Items[num];
- ptr->SetPos(pos);
+ if (std::holds_alternative(room))
+ {
+ ptr->SetPos(pos, false);
+ ptr->SetRoom(std::get(room));
+ }
+ else
+ ptr->SetPos(pos, true);
+
ptr->SetRot(USE_IF_HAVE(Rotation, rot, Rotation{}));
- ptr->SetRoom(room);
ptr->SetObjectID(objID);
ptr->Init();
@@ -378,24 +384,10 @@ void Moveable::Register(sol::table & parent)
// @treturn bool true if the moveable is active
ScriptReserved_GetActive, &Moveable::GetActive,
-/// Get the current room of the object
-// @function Moveable:GetRoom
-// @treturn int number representing the current room of the object
ScriptReserved_GetRoom, &Moveable::GetRoom,
-/// Set room of object
-// This is used in conjunction with SetPosition to teleport an item to a new room.
-// @function Moveable:SetRoom
-// @tparam int ID the ID of the new room
-// @usage
-// local sas = TEN.Objects.GetMoveableByName("sas_enemy")
-// sas:SetRoom(destinationRoom)
-// sas:SetPosition(destinationPosition)
ScriptReserved_SetRoom, &Moveable::SetRoom,
-/// Get the object's position
-// @function Moveable:GetPosition
-// @treturn Vec3 a copy of the moveable's position
ScriptReserved_GetPosition, & Moveable::GetPos,
/// Get the object's joint position
@@ -403,12 +395,6 @@ void Moveable::Register(sol::table & parent)
// @treturn Vec3 a copy of the moveable's position
ScriptReserved_GetJointPosition, & Moveable::GetJointPos,
-/// Set the moveable's position
-// If you are moving a moveable whose behaviour involves knowledge of room geometry,
-// (e.g. a BADDY1, which uses it for pathfinding), then you *must* use this in conjunction
-// with @{Moveable:SetRoom}. Otherwise, said moveable will not behave correctly.
-// @function Moveable:SetPosition
-// @tparam Vec3 position the new position of the moveable
ScriptReserved_SetPosition, & Moveable::SetPos,
/// Get the moveable's rotation
@@ -554,17 +540,27 @@ bool Moveable::SetName(std::string const & id)
return true;
}
+/// Get the object's position
+// @function Moveable:GetPosition
+// @treturn Vec3 a copy of the moveable's position
Vec3 Moveable::GetPos() const
{
return Vec3(m_item->Pose);
}
-void Moveable::SetPos(Vec3 const& pos)
+/// Set the moveable's position
+// If you are moving a moveable whose behaviour involves knowledge of room geometry,
+// (e.g. a BADDY1, which uses it for pathfinding), then the second argument should
+// be true (or omitted, as true is the default). Otherwise, said moveable will not behave correctly.
+// @function Moveable:SetPosition
+// @tparam Vec3 position the new position of the moveable
+// @bool[opt] updateRoom Will room changes be automatically detected? Set to false if you are using overlapping rooms (default: true)
+void Moveable::SetPos(Vec3 const& pos, sol::optional updateRoom)
{
pos.StoreInPHDPos(m_item->Pose);
- //todo make a non-updating version
- if(m_initialised)
+ bool willUpdate = !updateRoom.has_value() || updateRoom.value();
+ if(m_initialised && willUpdate)
UpdateItemRoom(m_item, pos.y);
}
@@ -722,11 +718,22 @@ bool Moveable::GetHitStatus() const
return m_item->HitStatus;
}
+/// Get the current room of the object
+// @function Moveable:GetRoom
+// @treturn int number representing the current room of the object
short Moveable::GetRoom() const
{
return m_item->RoomNumber;
}
+/// Set room of object
+// Use this if you are not using SetPosition's automatic room update - for example, when dealing with overlapping rooms.
+// @function Moveable:SetRoom
+// @tparam int ID the ID of the new room
+// @usage
+// local sas = TEN.Objects.GetMoveableByName("sas_enemy")
+// sas:SetRoom(destinationRoom)
+// sas:SetPosition(destinationPosition, false)
void Moveable::SetRoom(short room)
{
const size_t nRooms = g_Level.Rooms.size();
diff --git a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.h b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.h
index 96225563e..a47a1cc81 100644
--- a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.h
+++ b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.h
@@ -42,7 +42,7 @@ public:
[[nodiscard]] Vec3 GetPos() const;
[[nodiscard]] Vec3 GetJointPos(int index) const;
- void SetPos(Vec3 const& pos);
+ void SetPos(Vec3 const& pos, sol::optional updateRoom);
[[nodiscard]] Rotation GetRot() const;
void SetRot(Rotation const& rot);
From e6319ee18a12910d37b870653330471e33424b11 Mon Sep 17 00:00:00 2001
From: hispidence
Date: Fri, 26 Aug 2022 00:13:02 +0100
Subject: [PATCH 046/106] Update docs
---
.../doc/2 classes/Objects.Moveable.html | 254 +++++++++---------
.../TEN/Objects/Moveable/MoveableObject.cpp | 18 +-
2 files changed, 140 insertions(+), 132 deletions(-)
diff --git a/Documentation/doc/2 classes/Objects.Moveable.html b/Documentation/doc/2 classes/Objects.Moveable.html
index d89f7958c..a945e9401 100644
--- a/Documentation/doc/2 classes/Objects.Moveable.html
+++ b/Documentation/doc/2 classes/Objects.Moveable.html
@@ -95,7 +95,7 @@ pickups, and Lara herself.
- Moveable(object, name, position, rotation, room, animNumber, frameNumber, hp, OCB, AIBits)
+ Moveable(object, name, position[, rotation[, room[, animNumber=0[, frameNumber=0[, hp=10[, OCB=0[, AIBits]]]]]]])
For more information on each parameter, see the
associated getters and setters.
@@ -270,27 +270,8 @@ associated getters and setters.
Determine whether the moveable is active or not
- Moveable:GetRoom()
- Get the current room of the object
-
-
- Moveable:SetRoom(ID)
- Set room of object
- This is used in conjunction with SetPosition to teleport an item to a new room.
-
-
- Moveable:GetPosition()
- Get the object's position
-
-
Moveable:GetJointPosition()
Get the object's joint position
-
-
- Moveable:SetPosition(position)
- Set the moveable's position
- If you are moving a moveable whose behaviour involves knowledge of room geometry,
- (e.g.
Moveable:GetRotation()
@@ -318,6 +299,25 @@ associated getters and setters.
Moveable:Destroy()
Destroy the moveable.
+
+ Moveable:GetPosition()
+ Get the object's position
+
+
+ Moveable:SetPosition(position[, updateRoom])
+ Set the moveable's position
+ If you are moving a moveable whose behaviour involves knowledge of room geometry,
+ (e.g.
+
+
+ Moveable:GetRoom()
+ Get the current room of the object
+
+
+ Moveable:SetRoom(ID)
+ Set room of object
+ Use this if you are not using SetPosition's automatic room update - for example, when dealing with overlapping rooms.
+
@@ -329,7 +329,7 @@ associated getters and setters.
- Moveable(object, name, position, rotation, room, animNumber, frameNumber, hp, OCB, AIBits)
+ Moveable(object, name, position[, rotation[, room[, animNumber=0[, frameNumber=0[, hp=10[, OCB=0[, AIBits]]]]]]])
For more information on each parameter, see the
@@ -354,30 +354,37 @@ most can just be ignored (see usage).
rotation
Rotation
rotation about x, y, and z axes (default Rotation(0, 0, 0))
+ (optional )
room
int
- room ID item is in
+ room ID item is in (default: calculated automatically)
+ (optional )
animNumber
int
- anim number (default 0)
+ anim number
+ (default 0)
frameNumber
int
- frame number (default 0)
+ frame number
+ (default 0)
hp
int
- HP of item (default 10)
+ HP of item
+ (default 10)
OCB
int
ocb of item (default 0)
+ (default 0)
AIBits
table
table with AI bits (default {0,0,0,0,0,0})
+ (optional )
@@ -394,10 +401,8 @@ most can just be ignored (see usage).
local item = Moveable(
TEN.ObjID.PISTOLS_ITEM, "test" , Vec3(18907 , 0 , 21201 ),
- Rotation(0 ,0 ,0 ),
- 0 , )
+ Vec3(18907 , 0 , 21201 )
+ )
@@ -1242,74 +1247,6 @@ sas:SetAIBits({1 , 0 ,
-
-
- Moveable:GetRoom()
-
-
- Get the current room of the object
-
-
-
- Returns:
-
-
- int
- number representing the current room of the object
-
-
-
-
-
-
-
-
- Moveable:SetRoom(ID)
-
-
- Set room of object
- This is used in conjunction with SetPosition to teleport an item to a new room.
-
-
- Parameters:
-
- ID
- int
- the ID of the new room
-
-
-
-
-
-
- Usage:
- local sas = TEN.Objects.GetMoveableByName("sas_enemy" )
-sas:SetRoom(destinationRoom)
-sas:SetPosition(destinationPosition)
-
-
-
-
-
- Moveable:GetPosition()
-
-
- Get the object's position
-
-
-
- Returns:
-
-
- Vec3
- a copy of the moveable's position
-
-
-
-
-
@@ -1330,30 +1267,6 @@ sas:SetPosition(destinationPosition)
-
-
-
- Moveable:SetPosition(position)
-
-
- Set the moveable's position
- If you are moving a moveable whose behaviour involves knowledge of room geometry,
- (e.g. a BADDY1, which uses it for pathfinding), then you must use this in conjunction
- with Moveable:SetRoom . Otherwise, said moveable will not behave correctly.
-
-
- Parameters:
-
- position
- Vec3
- the new position of the moveable
-
-
-
-
-
-
-
@@ -1480,6 +1393,103 @@ sas:SetPosition(destinationPosition)
+
+
+
+ Moveable:GetPosition()
+
+
+ Get the object's position
+
+
+
+ Returns:
+
+
+ Vec3
+ a copy of the moveable's position
+
+
+
+
+
+
+
+
+ Moveable:SetPosition(position[, updateRoom])
+
+
+ Set the moveable's position
+ If you are moving a moveable whose behaviour involves knowledge of room geometry,
+ (e.g. a BADDY1, which uses it for pathfinding), then the second argument should
+ be true (or omitted, as true is the default). Otherwise, said moveable will not behave correctly.
+
+
+ Parameters:
+
+ position
+ Vec3
+ the new position of the moveable
+
+ updateRoom
+ bool
+ Will room changes be automatically detected? Set to false if you are using overlapping rooms (default: true)
+ (optional )
+
+
+
+
+
+
+
+
+
+
+ Moveable:GetRoom()
+
+
+ Get the current room of the object
+
+
+
+ Returns:
+
+
+ int
+ number representing the current room of the object
+
+
+
+
+
+
+
+
+ Moveable:SetRoom(ID)
+
+
+ Set room of object
+ Use this if you are not using SetPosition's automatic room update - for example, when dealing with overlapping rooms.
+
+
+ Parameters:
+
+ ID
+ int
+ the ID of the new room
+
+
+
+
+
+
+ Usage:
+ local sas = TEN.Objects.GetMoveableByName("sas_enemy" )
+sas:SetRoom(destinationRoom)
+sas:SetPosition(destinationPosition, false )
+
+
@@ -1488,7 +1498,7 @@ sas:SetPosition(destinationPosition)
generated by LDoc 1.4.6
-
Last updated 2022-08-19 00:04:24
+
Last updated 2022-08-26 00:12:28
diff --git a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
index 43b9c6e6d..aff367fc0 100644
--- a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp
@@ -72,21 +72,19 @@ most can just be ignored (see usage).
@tparam ObjID object ID
@tparam string name Lua name of the item
@tparam Vec3 position position in level
- @tparam Rotation rotation rotation about x, y, and z axes (default Rotation(0, 0, 0))
- @tparam int room room ID item is in
- @tparam int animNumber anim number (default 0)
- @tparam int frameNumber frame number (default 0)
- @tparam int hp HP of item (default 10)
- @tparam int OCB ocb of item (default 0)
- @tparam table AIBits table with AI bits (default {0,0,0,0,0,0})
+ @tparam[opt] Rotation rotation rotation about x, y, and z axes (default Rotation(0, 0, 0))
+ @int[opt] room room ID item is in (default: calculated automatically)
+ @int[opt=0] animNumber anim number
+ @int[opt=0] frameNumber frame number
+ @int[opt=10] hp HP of item
+ @int[opt=0] OCB ocb of item (default 0)
+ @tparam[opt] table AIBits table with AI bits (default {0,0,0,0,0,0})
@return reference to new Moveable object
@usage
local item = Moveable(
TEN.ObjID.PISTOLS_ITEM, -- object id
"test", -- name
- Vec3(18907, 0, 21201),
- Rotation(0,0,0),
- 0, -- room
+ Vec3(18907, 0, 21201)
)
*/
static std::unique_ptr Create(
From 08535c08a7c0c786f5665a99fbf8ad333edf2c55 Mon Sep 17 00:00:00 2001
From: Sezz
Date: Sat, 27 Aug 2022 14:31:03 +1000
Subject: [PATCH 047/106] Light cleanup
---
.../Objects/TR4/Entity/tr4_crocodile.cpp | 20 ++---
.../Objects/TR4/Entity/tr4_skeleton.cpp | 88 +++++++------------
.../Objects/TR5/Entity/tr5_gladiator.cpp | 26 +++---
TombEngine/Objects/TR5/Entity/tr5_lion.cpp | 2 +-
4 files changed, 55 insertions(+), 81 deletions(-)
diff --git a/TombEngine/Objects/TR4/Entity/tr4_crocodile.cpp b/TombEngine/Objects/TR4/Entity/tr4_crocodile.cpp
index d8c267c31..d71ffe5f2 100644
--- a/TombEngine/Objects/TR4/Entity/tr4_crocodile.cpp
+++ b/TombEngine/Objects/TR4/Entity/tr4_crocodile.cpp
@@ -30,9 +30,9 @@ namespace TEN::Entities::TR4
constexpr auto CROC_SWIM_SPEED = 16;
- #define CROC_STATE_WALK_FORWARD_ANGLE ANGLE(3.0f)
- #define CROC_SWIM_ANGLE ANGLE(3.0f)
- #define CROC_STATE_RUN_FORWARD_ANGLE ANGLE(5.0f)
+ #define CROC_STATE_WALK_TURN_RATE_MAX ANGLE(3.0f)
+ #define CROC_STATE_RUN_TURN_RATE_MAX ANGLE(5.0f)
+ #define CROC_STATE_SWIM_TURN_RATE_MAX ANGLE(3.0f)
const auto CrocodileBite = BiteInfo(Vector3(0.0f, -100.0f, 500.0f), 9);
const vector CrocodileBiteAttackJoints = { 8, 9 };
@@ -49,7 +49,7 @@ namespace TEN::Entities::TR4
CROC_STATE_DEATH = 7,
CROC_STATE_SWIM_FORWARD = 8,
CROC_STATE_WATER_BITE_ATTACK = 9,
- CROC_STATE_WATER_DEATH = 10,
+ CROC_STATE_WATER_DEATH = 10
};
enum CrocodileAnim
@@ -118,12 +118,12 @@ namespace TEN::Entities::TR4
return;
auto* item = &g_Level.Items[itemNumber];
- auto* creature = GetCreatureInfo(item);
auto* object = &Objects[item->ObjectNumber];
+ auto* creature = GetCreatureInfo(item);
- AI_INFO AI;
short angle = 0;
short boneAngle = 0;
+ AI_INFO AI;
if (item->HitPoints <= 0)
{
@@ -202,7 +202,7 @@ namespace TEN::Entities::TR4
break;
case CROC_STATE_WALK_FORWARD:
- creature->MaxTurn = CROC_STATE_WALK_FORWARD_ANGLE;
+ creature->MaxTurn = CROC_STATE_WALK_TURN_RATE_MAX;
// Land to water transition.
if (IsCrocodileInWater(item) && !item->Animation.RequiredState)
@@ -221,7 +221,7 @@ namespace TEN::Entities::TR4
break;
case CROC_STATE_RUN_FORWARD:
- creature->MaxTurn = CROC_STATE_RUN_FORWARD_ANGLE;
+ creature->MaxTurn = CROC_STATE_RUN_TURN_RATE_MAX;
// Land to water transition.
if (IsCrocodileInWater(item))
@@ -242,7 +242,7 @@ namespace TEN::Entities::TR4
case CROC_STATE_BITE_ATTACK:
if (item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase)
- item->Animation.RequiredState = 0;
+ item->Animation.RequiredState = CROC_STATE_NONE_1;
if (AI.bite &&
item->TestBits(JointBitType::Touch, CrocodileBiteAttackJoints))
@@ -260,7 +260,7 @@ namespace TEN::Entities::TR4
break;
case CROC_STATE_SWIM_FORWARD:
- creature->MaxTurn = CROC_SWIM_ANGLE;
+ creature->MaxTurn = CROC_STATE_SWIM_TURN_RATE_MAX;
// Water to land transition.
if (!IsCrocodileInWater(item))
diff --git a/TombEngine/Objects/TR4/Entity/tr4_skeleton.cpp b/TombEngine/Objects/TR4/Entity/tr4_skeleton.cpp
index 5f3e68d0c..15c8a16db 100644
--- a/TombEngine/Objects/TR4/Entity/tr4_skeleton.cpp
+++ b/TombEngine/Objects/TR4/Entity/tr4_skeleton.cpp
@@ -29,6 +29,7 @@ namespace TEN::Entities::TR4
const auto SkeletonBite = BiteInfo(Vector3(0.0f, -16.0f, 200.0f), 11);
const vector SkeletonSwordAttackJoints = { 15, 16 };
+ // TODO: Fill in missign states.
enum SkeletonState
{
SKELETON_STATE_SUBTERRANEAN = 0,
@@ -72,36 +73,28 @@ namespace TEN::Entities::TR4
void InitialiseSkeleton(short itemNumber)
{
auto* item = &g_Level.Items[itemNumber];
- auto* object = &Objects[item->ObjectNumber];
ClearItem(itemNumber);
+ // TODO: Check cases 0 and 3.
switch (item->TriggerFlags)
{
case 0:
- item->Animation.AnimNumber = object->animIndex;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
+ SetAnimation(item, SKELETON_ANIM_EMERGE);
item->Animation.ActiveState = SKELETON_STATE_SUBTERRANEAN;
item->Animation.TargetState = SKELETON_STATE_SUBTERRANEAN;
break;
case 1:
- item->Animation.AnimNumber = object->animIndex + SKELETON_ANIM_JUMP_RIGHT_START;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = SKELETON_STATE_JUMP_RIGHT;
- item->Animation.TargetState = SKELETON_STATE_JUMP_RIGHT;
+ SetAnimation(item, SKELETON_ANIM_JUMP_RIGHT_START);
break;
case 2:
- item->Animation.AnimNumber = object->animIndex + SKELETON_ANIM_JUMP_LEFT_START;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = SKELETON_STATE_JUMP_LEFT;
- item->Animation.TargetState = SKELETON_STATE_JUMP_LEFT;
+ SetAnimation(item, SKELETON_ANIM_JUMP_LEFT_START);
break;
case 3:
- item->Animation.AnimNumber = object->animIndex;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
+ SetAnimation(item, SKELETON_ANIM_EMERGE);
item->Animation.ActiveState = SKELETON_STATE_JUMP_LIE_DOWN;
item->Animation.TargetState = SKELETON_STATE_JUMP_LIE_DOWN;
//item->status = ITEM_DEACTIVATED;
@@ -175,15 +168,15 @@ namespace TEN::Entities::TR4
bool jumpLeft = false;
bool jumpRight = false;
- int distance = 0;
- short tilt = 0;
short angle = 0;
+ short tilt = 0;
short joint1 = 0;
short joint2 = 0;
short joint3 = 0;
short rotation = 0;
+ int distance = 0;
- // Can skeleton jump? Check for a distance of 1 and 2 sectors.
+ // Can skeleton jump? Check for a distance of 1 and 2 blocks.
int x = item->Pose.Position.x;
int y = item->Pose.Position.y;
int z = item->Pose.Position.z;
@@ -204,24 +197,24 @@ namespace TEN::Entities::TR4
int height3 = GetCollision(x, y, z, item->RoomNumber).Position.Floor;
int height = 0;
- bool canJump1sector = true;
- if (enemyItem && item->BoxNumber == LaraItem->BoxNumber && item->MeshBits & 0x200 ||
- y >= height1 - CLICK(1.5f) ||
- y >= height2 + CLICK(2) ||
- y <= height2 - CLICK(2))
+ bool canJump1Block = true;
+ if (enemyItem && item->BoxNumber == LaraItem->BoxNumber && (item->MeshBits & 0x200) ||
+ y >= (height1 - CLICK(1.5f)) ||
+ y >= (height2 + CLICK(2)) ||
+ y <= (height2 - CLICK(2)))
{
height = height2;
- canJump1sector = false;
+ canJump1Block = false;
}
- bool canJump2sectors = true;
- if (enemyItem && item->BoxNumber == LaraItem->BoxNumber && item->MeshBits & 0x200 ||
- y >= height1 - CLICK(1.5f) ||
- y >= height - CLICK(1.5f) ||
- y >= height3 + CLICK(2) ||
- y <= height3 - CLICK(2))
+ bool canJump2Blocks = true;
+ if (enemyItem && item->BoxNumber == LaraItem->BoxNumber && (item->MeshBits & 0x200) ||
+ y >= (height1 - CLICK(1.5f)) ||
+ y >= (height - CLICK(1.5f)) ||
+ y >= (height3 + CLICK(2)) ||
+ y <= (height3 - CLICK(2)))
{
- canJump2sectors = false;
+ canJump2Blocks = false;
}
if (item->AIBits)
@@ -235,17 +228,17 @@ namespace TEN::Entities::TR4
if (item->HitStatus &&
Lara.Control.Weapon.GunType == LaraWeaponType::Shotgun &&
AI.distance < pow(SECTOR(3.5f), 2) &&
- item->Animation.ActiveState != 7 &&
+ item->Animation.ActiveState != SKELETON_STATE_USE_SHIELD &&
item->Animation.ActiveState != 17 &&
item->Animation.ActiveState != SKELETON_STATE_HURT_BY_SHOTGUN_1 &&
item->Animation.ActiveState != SKELETON_STATE_HURT_BY_SHOTGUN_2 &&
- item->Animation.ActiveState != 25)
+ item->Animation.ActiveState != SKELETON_STATE_JUMP_LIE_DOWN)
{
if (AI.angle >= ANGLE(67.5f) || AI.angle <= -ANGLE(67.5f))
{
item->Animation.ActiveState = SKELETON_STATE_HURT_BY_SHOTGUN_2;
item->Animation.AnimNumber = Objects[ID_SKELETON].animIndex + 33;
- item->Pose.Orientation.y += AI.angle + -32768;
+ item->Pose.Orientation.y += AI.angle - ANGLE(180.0f);
}
else
{
@@ -381,14 +374,14 @@ namespace TEN::Entities::TR4
{
if (item->AIBits & PATROL1)
item->Animation.TargetState = 15;
- else if (canJump1sector || canJump2sectors)
+ else if (canJump1Block || canJump2Blocks)
{
item->Animation.AnimNumber = Objects[ID_SKELETON].animIndex + 40;
item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
item->Animation.ActiveState = SKELETON_STATE_JUMP_LEFT;
creature->MaxTurn = 0;
- if (!canJump2sectors)
+ if (!canJump2Blocks)
{
item->Animation.TargetState = SKELETON_STATE_JUMP_FORWARD_1_BLOCK;
creature->LOT.IsJumping = true;
@@ -400,26 +393,15 @@ namespace TEN::Entities::TR4
}
}
else if (jumpLeft)
- {
- item->Animation.AnimNumber = Objects[ID_SKELETON].animIndex + 34;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = SKELETON_STATE_JUMP_LEFT;
- item->Animation.TargetState = SKELETON_STATE_JUMP_LEFT;
- }
+ SetAnimation(item, SKELETON_ANIM_JUMP_LEFT_START);
else if (jumpRight)
- {
- item->Animation.AnimNumber = Objects[ID_SKELETON].animIndex + 37;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- item->Animation.ActiveState = SKELETON_STATE_JUMP_RIGHT;
- item->Animation.TargetState = SKELETON_STATE_JUMP_RIGHT;
- }
+ SetAnimation(item, SKELETON_ANIM_JUMP_RIGHT_START);
else
{
if (creature->Mood == MoodType::Escape)
{
if (Lara.TargetEntity == item ||
- !AI.ahead ||
- item->HitStatus ||
+ !AI.ahead || item->HitStatus ||
!(item->MeshBits & 0x200))
{
item->Animation.TargetState = 15;
@@ -430,8 +412,7 @@ namespace TEN::Entities::TR4
}
else if (creature->Mood == MoodType::Bored ||
item->AIBits & FOLLOW &&
- (creature->ReachedGoal ||
- laraAI.distance > pow(SECTOR(2), 2)))
+ (creature->ReachedGoal || laraAI.distance > pow(SECTOR(2), 2)))
{
if (item->Animation.RequiredState)
item->Animation.TargetState = item->Animation.RequiredState;
@@ -439,8 +420,7 @@ namespace TEN::Entities::TR4
item->Animation.TargetState = 15;
}
else if (Lara.TargetEntity == item &&
- laraAI.angle &&
- laraAI.distance < pow(SECTOR(2), 2) &&
+ laraAI.angle && laraAI.distance < pow(SECTOR(2), 2) &&
TestProbability(0.5f) &&
(Lara.Control.Weapon.GunType == LaraWeaponType::Shotgun || TestProbability(0.06f)) &&
item->MeshBits == -1)
@@ -509,7 +489,7 @@ namespace TEN::Entities::TR4
{
if (AI.bite && AI.distance < pow(SECTOR(1), 2))
item->Animation.TargetState = 18;
- else if (canJump1sector || canJump2sectors)
+ else if (canJump1Block || canJump2Blocks)
{
item->Animation.TargetState = 2;
creature->MaxTurn = 0;
@@ -530,7 +510,7 @@ namespace TEN::Entities::TR4
creature->MaxTurn = ANGLE(7.0f);
creature->LOT.IsJumping = false;
- if (item->AIBits & GUARD || canJump1sector || canJump2sectors)
+ if (item->AIBits & GUARD || canJump1Block || canJump2Blocks)
{
if (item->MeshBits & 0x200)
{
diff --git a/TombEngine/Objects/TR5/Entity/tr5_gladiator.cpp b/TombEngine/Objects/TR5/Entity/tr5_gladiator.cpp
index 8434d8639..2bb89c123 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_gladiator.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_gladiator.cpp
@@ -88,8 +88,8 @@ namespace TEN::Entities::Creatures::TR5
auto* item = &g_Level.Items[itemNumber];
auto* creature = GetCreatureInfo(item);
- short tilt = 0;
short angle = 0;
+ short tilt = 0;
short joint0 = 0;
short joint1 = 0;
short joint2 = 0;
@@ -99,11 +99,7 @@ namespace TEN::Entities::Creatures::TR5
item->HitPoints = 0;
if (item->Animation.ActiveState != GLADIATOR_STATE_DEATH)
- {
- item->Animation.AnimNumber = Objects[ID_GLADIATOR].animIndex + GLADIATOR_ANIM_DEATH;
- item->Animation.ActiveState = GLADIATOR_STATE_DEATH;
- item->Animation.FrameNumber = g_Level.Anims[item->Animation.AnimNumber].frameBase;
- }
+ SetAnimation(item, GLADIATOR_ANIM_DEATH);
}
else
{
@@ -116,21 +112,21 @@ namespace TEN::Entities::Creatures::TR5
CreatureAIInfo(item, &AI);
int unknown = true;
- short rot;
+ short deltaAngle;
int distance;
if (creature->Enemy == LaraItem)
{
distance = AI.distance;
- rot = AI.angle;
+ deltaAngle = AI.angle;
}
else
{
int dx = LaraItem->Pose.Position.x - item->Pose.Position.x;
int dz = LaraItem->Pose.Position.z - item->Pose.Position.z;
- rot = phd_atan(dz, dx) - item->Pose.Orientation.y;
- if (rot <= -ANGLE(90.0f) || rot >= ANGLE(90.0f))
+ deltaAngle = phd_atan(dz, dx) - item->Pose.Orientation.y;
+ if (deltaAngle <= -ANGLE(90.0f) || deltaAngle >= ANGLE(90.0f))
unknown = false;
distance = pow(dx, 2) + pow(dz, 2);
@@ -151,7 +147,7 @@ namespace TEN::Entities::Creatures::TR5
switch (item->Animation.ActiveState)
{
case GLADIATOR_STATE_IDLE:
- joint2 = rot;
+ joint2 = deltaAngle;
creature->MaxTurn = (-(int)(creature->Mood != MoodType::Bored)) & 0x16C;
creature->Flags = 0;
@@ -169,8 +165,7 @@ namespace TEN::Entities::Creatures::TR5
{
if (creature->Mood == MoodType::Escape)
{
- if (Lara.TargetEntity != item &&
- AI.ahead && !item->HitStatus)
+ if (Lara.TargetEntity != item && AI.ahead && !item->HitStatus)
{
item->Animation.TargetState = GLADIATOR_STATE_IDLE;
break;
@@ -179,8 +174,7 @@ namespace TEN::Entities::Creatures::TR5
else
{
if (creature->Mood == MoodType::Bored ||
- (item->AIBits & FOLLOW &&
- (creature->ReachedGoal || distance > pow(SECTOR(2), 2))))
+ (item->AIBits & FOLLOW && (creature->ReachedGoal || distance > pow(SECTOR(2), 2))))
{
if (item->Animation.RequiredState)
item->Animation.TargetState = item->Animation.RequiredState;
@@ -217,7 +211,7 @@ namespace TEN::Entities::Creatures::TR5
break;
case GLADIATOR_STATE_WALK_FORWARD:
- joint2 = rot;
+ joint2 = deltaAngle;
creature->MaxTurn = creature->Mood != MoodType::Bored ? ANGLE(7.0f) : ANGLE(2.0f);
creature->Flags = 0;
diff --git a/TombEngine/Objects/TR5/Entity/tr5_lion.cpp b/TombEngine/Objects/TR5/Entity/tr5_lion.cpp
index 66fd9992e..f7dbe1196 100644
--- a/TombEngine/Objects/TR5/Entity/tr5_lion.cpp
+++ b/TombEngine/Objects/TR5/Entity/tr5_lion.cpp
@@ -23,9 +23,9 @@ namespace TEN::Entities::Creatures::TR5
constexpr auto LION_POUNCE_ATTACK_RANGE = SQUARE(SECTOR(1));
- const vector LionAttackJoints = { 3, 6, 21 };
const auto LionBite1 = BiteInfo(Vector3(2.0f, -10.0f, 250.0f), 21);
const auto LionBite2 = BiteInfo(Vector3(-2.0f, -10.0f, 132.0f), 21);
+ const vector LionAttackJoints = { 3, 6, 21 };
enum LionState
{
From 680065ad0335b32429a5be5aaa21d46d6210312a Mon Sep 17 00:00:00 2001
From: hispidence
Date: Tue, 30 Aug 2022 15:20:44 +0100
Subject: [PATCH 048/106] Add hacky subtable fuckery
---
TombEngine/Game/savegame.cpp | 15 ++
.../Scripting/Include/ScriptInterfaceGame.h | 7 +-
TombEngine/Scripting/Internal/ScriptUtil.h | 6 +-
.../Internal/TEN/Flow/FlowHandler.cpp | 2 +
.../Internal/TEN/Logic/FuncNameHolder.h | 37 +++
.../Internal/TEN/Logic/LogicHandler.cpp | 251 ++++++++++++++++--
.../Internal/TEN/Logic/LogicHandler.h | 73 ++++-
.../flatbuffers/ten_savegame_generated.h | 151 ++++++++++-
.../Specific/savegame/schema/ten_savegame.fbs | 7 +-
TombEngine/TombEngine.vcxproj | 1 +
10 files changed, 514 insertions(+), 36 deletions(-)
create mode 100644 TombEngine/Scripting/Internal/TEN/Logic/FuncNameHolder.h
diff --git a/TombEngine/Game/savegame.cpp b/TombEngine/Game/savegame.cpp
index 6ee4de384..9379db071 100644
--- a/TombEngine/Game/savegame.cpp
+++ b/TombEngine/Game/savegame.cpp
@@ -1082,6 +1082,16 @@ bool SaveGame::Save(int slot)
putDataInVec(Save::VarUnion::tab, scriptTableOffset);
}
+ else if (std::holds_alternative(s))
+ {
+ std::string data = std::get(s).name;
+ auto strOffset = fbb.CreateString(data);
+ Save::funcNameTableBuilder ftb{ fbb };
+ ftb.add_str(strOffset);
+ auto funcNameOffset = ftb.Finish();
+
+ putDataInVec(Save::VarUnion::funcName, funcNameOffset);
+ }
else if (std::holds_alternative(s))
{
Save::vec3TableBuilder vtb{ fbb };
@@ -1926,6 +1936,11 @@ bool SaveGame::Load(int slot)
{
loadedVars.push_back(ToVector3Int(var->u_as_vec3()->vec()));
}
+ else if (var->u_type() == Save::VarUnion::funcName)
+ {
+ loadedVars.push_back(FuncName{var->u_as_funcName()->str()->str()});
+ }
+
}
}
diff --git a/TombEngine/Scripting/Include/ScriptInterfaceGame.h b/TombEngine/Scripting/Include/ScriptInterfaceGame.h
index 7c4c087a2..5181c8b32 100644
--- a/TombEngine/Scripting/Include/ScriptInterfaceGame.h
+++ b/TombEngine/Scripting/Include/ScriptInterfaceGame.h
@@ -19,7 +19,12 @@ using VarSaveType = std::variant;
using IndexTable = std::vector>;
-using SavedVar = std::variant;
+struct FuncName
+{
+ std::string name;
+};
+
+using SavedVar = std::variant;
class ScriptInterfaceGame {
public:
diff --git a/TombEngine/Scripting/Internal/ScriptUtil.h b/TombEngine/Scripting/Internal/ScriptUtil.h
index 49715c7f1..0700dfbeb 100644
--- a/TombEngine/Scripting/Internal/ScriptUtil.h
+++ b/TombEngine/Scripting/Internal/ScriptUtil.h
@@ -37,17 +37,19 @@ template using TypeOrNil = std::variant
-void MakeSpecialTable(sol::state * state, std::string const & name, funcIndex const & fi, funcNewindex const & fni)
+sol::table MakeSpecialTable(sol::state * state, std::string const & name, funcIndex const & fi, funcNewindex const & fni)
{
auto meta = MakeSpecialTableBase(state, name);
meta.set_function("__index", fi);
meta.set_function("__newindex", fni);
+ return (*state)[name];
}
template
-void MakeSpecialTable(sol::state * state, std::string const & name, funcIndex const & fi, funcNewindex const & fni, ObjPtr objPtr)
+sol::table MakeSpecialTable(sol::state * state, std::string const & name, funcIndex const & fi, funcNewindex const & fni, ObjPtr objPtr)
{
auto meta = MakeSpecialTableBase(state, name);
meta.set_function("__index", fi, objPtr);
meta.set_function("__newindex", fni, objPtr);
+ return (*state)[name];
}
diff --git a/TombEngine/Scripting/Internal/TEN/Flow/FlowHandler.cpp b/TombEngine/Scripting/Internal/TEN/Flow/FlowHandler.cpp
index 9dd54070a..11c0978bc 100644
--- a/TombEngine/Scripting/Internal/TEN/Flow/FlowHandler.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Flow/FlowHandler.cpp
@@ -8,6 +8,7 @@
#include "Flow/InventoryItem/InventoryItem.h"
#include "InventorySlots.h"
#include "Game/gui.h"
+#include "Logic/FuncNameHolder.h"
#include "Vec3/Vec3.h"
#include "Objects/ScriptInterfaceObjectsHandler.h"
#include "Specific/trutils.h"
@@ -112,6 +113,7 @@ Specify which translations in the strings table correspond to which languages.
Animations::Register(table_flow);
Settings::Register(table_flow);
Fog::Register(table_flow);
+ FuncNameHolder::Register(parent);
m_handler.MakeReadOnlyTable(table_flow, ScriptReserved_WeatherType, kWeatherTypes);
m_handler.MakeReadOnlyTable(table_flow, ScriptReserved_LaraType, kLaraTypes);
diff --git a/TombEngine/Scripting/Internal/TEN/Logic/FuncNameHolder.h b/TombEngine/Scripting/Internal/TEN/Logic/FuncNameHolder.h
new file mode 100644
index 000000000..f89a95759
--- /dev/null
+++ b/TombEngine/Scripting/Internal/TEN/Logic/FuncNameHolder.h
@@ -0,0 +1,37 @@
+#pragma once
+#include "LogicHandler.h"
+
+// Why do we need this class?
+// We need a way to save and load functions in a way that remembers exactly what "path" they have in the LevelFuncs table hierarchy.
+// Thus, even if we use Lua to put a LevelFuncs function in a variable with another, shorter name, we can still pass it into
+// LevelVars and have it remember the right function name when loaded.
+// todo actually test the above
+// This is needed for things like Timers, which call a certain function after a certain amount of time. If we save and then load,
+// the FuncNameHolder will be able to use its path as the key to find the actual Lua function to call at the end of the timer.
+
+// The alternative would be to pass in a full string, but then we would need to split the string at runtime to find
+// the exact tables to look in, which seems like it would take longer.
+
+TO DO:
+make sure nested tables save/loads work
+make sure timers whose funcs take multiple args works
+make sure nested tables AND multiple args works
+class FuncNameHolder {
+public:
+ std::string m_funcName;
+ LogicHandler* m_handler;
+ void Call(sol::variadic_args vs)
+ {
+ m_handler->CallLevelFunc(m_funcName, vs);
+ }
+ void CallDT(float dt)
+ {
+ m_handler->CallLevelFunc(m_funcName, dt);
+ }
+
+ static void Register(sol::table & parent)
+ {
+ parent.new_usertype("FuncHolderNameString", sol::no_constructor, sol::meta_function::call, &Call);
+ }
+};
+
diff --git a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
index e51798363..6dc2c8b0e 100644
--- a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
+++ b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp
@@ -9,7 +9,7 @@
#include "ScriptUtil.h"
#include "Objects/Moveable/MoveableObject.h"
#include "Vec3/Vec3.h"
-
+#include "FuncNameHolder.h"
using namespace TEN::Effects::Lightning;
/***
@@ -30,6 +30,8 @@ static const std::unordered_map kCallbackPoints
{"POSTCONTROLPHASE", CallbackPoint::PostControl},
};
+using LevelFuncsTable = std::pair;
+
void SetVariable(sol::table tab, sol::object key, sol::object value)
{
switch (value.get_type())
@@ -86,6 +88,10 @@ LogicHandler::LogicHandler(sol::state* lua, sol::table & parent) : m_handler{ lu
m_handler.MakeReadOnlyTable(table_logic, ScriptReserved_CallbackPoint, kCallbackPoints);
+ //it crashes when here
+ // todo fix?
+ //FuncNameHolder::Register(table_logic);
+
ResetScripts(true);
}
@@ -102,23 +108,44 @@ Possible values for CallbackPoint:
The order in which two functions with the same CallbackPoint are called is undefined.
i.e. if you register `MyFunc` and `MyFunc2` with `PRECONTROLPHASE`, both will be called before `OnControlPhase`, but there is no guarantee whether `MyFunc` will be called before `MyFunc2`, or vice-versa.
+
+
@function AddCallback
@tparam point CallbackPoint When should the callback be called?
-@tparam func string The LevelFuncs function to be called. Will receive as an argument the time in seconds since the last frame.
+@tparam func string The name of the function to be called. Will receive as an argument the time in seconds since the last frame.
@usage
- LevelFuncs.MyFunc = function(dt) print(dt) end
+ local MyFunc = function(dt) print(dt) end
TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.PRECONTROLPHASE, "MyFunc")
*/
-void LogicHandler::AddCallback(CallbackPoint point, std::string const & name)
+void LogicHandler::AddCallback(CallbackPoint point, FuncNameHolder & fnh)
{
+ //sol::object obj = tab["funcName"];
+ //sol::type type = obj.get_type();
+ //switch(type)
+ //{
+ //case sol::type::string:
+ // TENLog("fuck it's a string");
+ // break;
+
+ //case sol::type::userdata:
+ // TENLog("fuck it's userdata");
+ // break;
+
+ //case sol::type::table:
+ // TENLog("fuck it's a table");
+ // break;
+ //}
+
+ //auto fnh = tab["funcName"];
+ //std::string name = tab["funcName"];
switch(point)
{
case CallbackPoint::PreControl:
- m_callbacksPreControl.insert(name);
+ m_callbacksPreControl.insert(fnh.m_funcName);
break;
case CallbackPoint::PostControl:
- m_callbacksPostControl.insert(name);
+ m_callbacksPostControl.insert(fnh.m_funcName);
break;
}
}
@@ -132,6 +159,7 @@ Will have no effect if the function was not registered as a callback
@usage
TEN.Logic.RemoveCallback(TEN.Logic.CallbackPoint.PRECONTROLPHASE, "MyFunc")
*/
+//todo this has to deal with LevelFuncs subtables too now
void LogicHandler::RemoveCallback(CallbackPoint point, std::string const & name)
{
switch(point)
@@ -146,33 +174,151 @@ void LogicHandler::RemoveCallback(CallbackPoint point, std::string const & name)
}
}
+ static constexpr char const* strKey = "__internal_name";
void LogicHandler::ResetLevelTables()
{
- MakeSpecialTable(m_handler.GetState(), ScriptReserved_LevelFuncs, &LogicHandler::GetLevelFunc, &LogicHandler::SetLevelFunc, this);
+ //todo does levelFuncs get cleared normally, pre-these changes?
+ //NO. the TABLE gets reset but m_levelFuncs does NOT get reset
+
+
MakeSpecialTable(m_handler.GetState(), ScriptReserved_LevelVars, &GetVariable, &SetVariable);
}
-sol::protected_function LogicHandler::GetLevelFunc(sol::table tab, std::string const& luaName)
+sol::object LogicHandler::GetLevelFunc(sol::table tab, std::string const& luaName)
{
- if (m_levelFuncs.find(luaName) == m_levelFuncs.end())
- return sol::lua_nil;
+ //if (m_levelFuncs.find(luaName) == m_levelFuncs.end())
+ // return sol::lua_nil;
- return m_levelFuncs.at(luaName);
+ std::string partName = tab.raw_get(strKey);
+ //std::string x = m_levelFuncsTables[luaName];
+ sol::table theTab = m_levelFuncsTables[partName];
+ //TENLog("looking for " + luaName);
+ //std::string x = theTab.raw_get(luaName);
+ //theTab.raw_get_or()
+ //TENLog("table has:");
+ //for(auto & [key, val] : theTab)
+ //{
+ // std::string keyStr = key.as();
+ // std::string valStr = val.as();
+ // TENLog(fmt::format("{} = {}", keyStr, valStr));
+ //}
+ //TENLog("");
+ std::string x;
+ sol::object obj = theTab.raw_get(luaName);
+ if (obj.is())
+ {
+ x = obj.as();
+ //TENLog("found " + luaName + ", it was " + x);
+
+ //what if you are asking for a table?
+ if (m_levelFuncsFakeFuncs[x].valid())
+ return m_levelFuncsFakeFuncs[x];
+ else
+ return m_levelFuncsTables[x];
+ }
+ if (obj.is())
+ {
+ return obj;
+ }
+ else
+ {
+ return sol::nil;
+ }
+ //return m_levelFuncs.at(luaName);
+}
+
+void LogicHandler::CallLevelFunc(std::string name, float dt)
+{
+ sol::protected_function f = m_levelFuncsActualFuncs[name];
+ //for (auto & v : va)
+ //{
+ // TENLog(v.as());
+ //}
+ f.call(dt);
+}
+
+
+void LogicHandler::CallLevelFunc(std::string name, sol::variadic_args va)
+{
+ sol::protected_function f = m_levelFuncsActualFuncs[name];
+ //for (auto & v : va)
+ //{
+ // TENLog(v.as());
+ //}
+ f.call(va);
}
bool LogicHandler::SetLevelFunc(sol::table tab, std::string const& luaName, sol::object value)
{
+
+ //make m_levelFuncs the 'root' table, make everything else go into "tab" (so maybe all these should act on "tab" and we gotta create original m_levelFuncs ourselves outside of here)
+ std::string partName;
+ std::string fullName;
+ sol::table newTab;
+ sol::table newLevelFuncsTab;
+ sol::table aTab;
+ sol::table meta;
+ FuncNameHolder fnh;
switch (value.get_type())
{
case sol::type::lua_nil:
- m_levelFuncs.erase(luaName);
- break;
case sol::type::function:
- m_levelFuncs.insert_or_assign(luaName, value.as());
+ partName = tab.raw_get(strKey);
+ fullName = partName + "." + luaName;
+ aTab = m_levelFuncsTables[partName];
+ aTab.raw_set(luaName, fullName);
+ m_levelFuncsActualFuncs[fullName] = value;
+
+ fnh.m_funcName = fullName;
+ fnh.m_handler = this;
+
+ m_levelFuncsFakeFuncs[fullName] = fnh;
+
+ //newTab = sol::table{ *(m_handler.GetState()), sol::create };
+ //newTab[sol::metatable_key] = sol::table{ *(m_handler.GetState()), sol::create };
+
+ //meta = newTab[sol::metatable_key];
+ //meta.set_function("__call", &LogicHandler::CallLevelFunc, this);
+ //newTab.set("funcName", fullName);
+// m_levelFuncsFakeFuncs[fullName] = newTab;
+
+ //update: don't need to do this actually I don't think...
+ //todo make another m_levelFuncsActualFuncs member with the actual func call
+ break;
+ case sol::type::table:
+ //make a copy of the table using
+ //tab.raw_set(luaName, MakeSpecialTable(m_handler.GetState(), luaName, &LogicHandler::GetLevelFunc, &LogicHandler::SetLevelFunc, this));
+ //todo need to make anonoymous version of MakeSpecialTable
+ newTab = sol::table{ *(m_handler.GetState()), sol::create };
+ fullName = tab.raw_get(strKey) + "." + luaName;
+ m_levelFuncsTables[fullName] = newTab;
+
+ partName = tab.raw_get(strKey);
+ aTab = m_levelFuncsTables[partName];
+ aTab.raw_set(luaName, fullName);
+
+ newTab.raw_set(strKey, fullName);
+
+ for (auto& [key, val] : value.as())
+ {
+ newTab[key] = val;
+ }
+
+ newLevelFuncsTab = MakeSpecialTable(m_handler.GetState(), luaName, &LogicHandler::GetLevelFunc, &LogicHandler::SetLevelFunc, this);
+ newLevelFuncsTab.raw_set(strKey, fullName);
+ tab.raw_set(luaName, newLevelFuncsTab);
+
+ for (auto& [key, val] : value.as())
+ {
+ newLevelFuncsTab[key] = val;
+ }
+ //tab.raw_set(luaName, newTab);
+
+ // assign the copy of the table
break;
default:
- std::string error{ "Could not assign LevelFuncs." };
- error += luaName + "; it must be a function (or nil).";
+ std::string error{ "Failed to add " };
+ error += luaName + " to LevelFuncs or one of its tables; it must be a function, a table of functions, or nil.";
return ScriptAssert(false, error);
}
return true;
@@ -195,6 +341,10 @@ void LogicHandler::ResetScripts(bool clearGameVars)
{
FreeLevelScripts();
+ //todo are these getting called?
+ //load level. walk to trigger that adds here
+ //save and reload
+
m_callbacksPreControl.clear();
m_callbacksPostControl.clear();
@@ -214,7 +364,16 @@ void LogicHandler::ResetScripts(bool clearGameVars)
void LogicHandler::FreeLevelScripts()
{
- m_levelFuncs.clear();
+ //m_levelFuncs.clear();
+ //m_levelFuncs =
+ m_levelFuncs = MakeSpecialTable(m_handler.GetState(), ScriptReserved_LevelFuncs, &LogicHandler::GetLevelFunc, &LogicHandler::SetLevelFunc, this);
+
+ m_levelFuncsTables = sol::table{ *(m_handler.GetState()), sol::create };
+ m_levelFuncsActualFuncs = sol::table{ *(m_handler.GetState()), sol::create };
+ m_levelFuncsFakeFuncs = sol::table{ *(m_handler.GetState()), sol::create };
+
+ m_levelFuncsTables[ScriptReserved_LevelFuncs] = sol::table{ *(m_handler.GetState()), sol::create };
+ m_levelFuncs.raw_set(strKey, ScriptReserved_LevelFuncs);
ResetLevelTables();
m_onStart = sol::nil;
m_onLoad = sol::nil;
@@ -296,6 +455,13 @@ void LogicHandler::SetVariables(std::vector const & vars)
auto theVec = Vec3{ std::get(vars[second]) };
solTables[i][vars[first]] = theVec;
}
+ else if (std::holds_alternative(vars[second]))
+ {
+ FuncNameHolder fnh;
+ fnh.m_funcName = std::get(vars[second]).name;
+ fnh.m_handler = this;
+ solTables[i][vars[first]] = fnh;
+ }
else
{
solTables[i][vars[first]] = vars[second];
@@ -391,6 +557,20 @@ void LogicHandler::GetVariables(std::vector & vars)
return first->second;
};
+ auto handleFuncName = [&](FuncNameHolder const& fnh)
+ {
+ //auto str = obj.as