mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-11 04:56:49 +03:00
Revision
- The Do-Actions and the Make_Targetable functions, have been removed from this code, and implemented as a Lua Module to be shared externally. - With the new Trigger approach, this commitment removes the implementation of the parameters feature. - Created a new function: GetSlotHP(), So Lua can read the default life points designated for the enemies. (useful for life percentages and such). - Changed the functions: GetItemFlag and SetItemFlag to GetItemFlags and SetItemFlags So they fits with the variable name they are referencing.
This commit is contained in:
parent
f3d9acf19c
commit
bf31a3d68b
8 changed files with 36 additions and 259 deletions
|
@ -58,13 +58,13 @@ namespace TEN::Control::Volumes
|
|||
{
|
||||
volume->Status = TriggerStatus::Entering;
|
||||
if (!volume->OnEnter.empty())
|
||||
g_GameScript->ExecuteFunction(volume->OnEnter, triggerer, volume->ParamOnEnter);
|
||||
g_GameScript->ExecuteFunction(volume->OnEnter, triggerer);
|
||||
}
|
||||
else
|
||||
{
|
||||
volume->Status = TriggerStatus::Inside;
|
||||
if (!volume->OnInside.empty())
|
||||
g_GameScript->ExecuteFunction(volume->OnInside, triggerer, volume->ParamOnInside);
|
||||
g_GameScript->ExecuteFunction(volume->OnInside, triggerer);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -73,7 +73,7 @@ namespace TEN::Control::Volumes
|
|||
{
|
||||
volume->Status = TriggerStatus::Leaving;
|
||||
if (!volume->OnLeave.empty())
|
||||
g_GameScript->ExecuteFunction(volume->OnLeave, triggerer, volume->ParamOnLeave);
|
||||
g_GameScript->ExecuteFunction(volume->OnLeave, triggerer);
|
||||
}
|
||||
else
|
||||
volume->Status = TriggerStatus::Outside;
|
||||
|
|
|
@ -41,10 +41,6 @@ struct TriggerVolume
|
|||
std::string OnInside;
|
||||
std::string OnLeave;
|
||||
|
||||
std::string ParamOnEnter = "nil";
|
||||
std::string ParamOnInside = "nil";
|
||||
std::string ParamOnLeave = "nil";
|
||||
|
||||
int Activators;
|
||||
bool OneShot;
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ static constexpr char ScriptReserved_Init[] = "Init";
|
|||
static constexpr char ScriptReserved_Enable[] = "Enable";
|
||||
static constexpr char ScriptReserved_Disable[] = "Disable";
|
||||
static constexpr char ScriptReserved_MakeInvisible[] = "MakeInvisible";
|
||||
static constexpr char ScriptReserved_MakeNotTargetable[]= "MakeNotTargetable";
|
||||
static constexpr char ScriptReserved_GetColor[] = "GetColor";
|
||||
static constexpr char ScriptReserved_SetColor[] = "SetColor";
|
||||
static constexpr char ScriptReserved_GetPosition[] = "GetPosition";
|
||||
|
@ -44,6 +43,7 @@ static constexpr char ScriptReserved_GetSoundID[] = "GetSoundID";
|
|||
static constexpr char ScriptReserved_SetSoundID[] = "SetSoundID";
|
||||
static constexpr char ScriptReserved_GetHP[] = "GetHP";
|
||||
static constexpr char ScriptReserved_SetHP[] = "SetHP";
|
||||
static constexpr char ScriptReserved_GetSlotHP[] = "GetSlotHP";
|
||||
static constexpr char ScriptReserved_GetFrameNumber[] = "GetFrame";
|
||||
static constexpr char ScriptReserved_SetFrameNumber[] = "SetFrame";
|
||||
static constexpr char ScriptReserved_GetAnimNumber[] = "GetAnim";
|
||||
|
@ -53,8 +53,8 @@ static constexpr char ScriptReserved_SetOCB[] = "SetOCB";
|
|||
static constexpr char ScriptReserved_GetStatus[] = "GetStatus";
|
||||
static constexpr char ScriptReserved_GetAIBits[] = "GetAIBits";
|
||||
static constexpr char ScriptReserved_SetAIBits[] = "SetAIBits";
|
||||
static constexpr char ScriptReserved_GetItemFlag[] = "GetItemFlag";
|
||||
static constexpr char ScriptReserved_SetItemFlag[] = "SetItemFlag";
|
||||
static constexpr char ScriptReserved_GetItemFlags[] = "GetItemFlags";
|
||||
static constexpr char ScriptReserved_SetItemFlags[] = "SetItemFlags";
|
||||
static constexpr char ScriptReserved_GetHitStatus[] = "GetHitStatus";
|
||||
static constexpr char ScriptReserved_GetActive[] = "GetActive";
|
||||
static constexpr char ScriptReserved_GetRoom[] = "GetRoom";
|
||||
|
@ -75,14 +75,6 @@ static constexpr char ScriptReserved_GetOnCollidedWithRoom[] = "GetOnCollidedWit
|
|||
static constexpr char ScriptReserved_SetOnCollidedWithRoom[] = "SetOnCollidedWithRoom";
|
||||
static constexpr char ScriptReserved_ToLength[] = "ToLength";
|
||||
|
||||
static constexpr char ScriptReserved_DoGoToNode[] = "DoGoToNode";
|
||||
static constexpr char ScriptReserved_DoGoDirectlyToNode[] = "DoGoDirectlyToNode";
|
||||
static constexpr char ScriptReserved_DoGoNextNode[] = "DoGoNextNode";
|
||||
static constexpr char ScriptReserved_DoNewBehaviour[] = "DoNewBehaviour";
|
||||
static constexpr char ScriptReserved_DoWaitForLara[] = "DoWaitForLara";
|
||||
static constexpr char ScriptReserved_DoRunDefault[] = "DoRunDefault";
|
||||
static constexpr char ScriptReserved_DoScareGuide[] = "DoScareGuide";
|
||||
|
||||
// Flow Functions
|
||||
static constexpr char ScriptReserved_AddLevel[] = "AddLevel";
|
||||
static constexpr char ScriptReserved_SetIntroImagePath[] = "SetIntroImagePath";
|
||||
|
|
|
@ -382,26 +382,6 @@ void LogicHandler::ExecuteFunction(std::string const& name, TEN::Control::Volume
|
|||
}
|
||||
}
|
||||
|
||||
void LogicHandler::ExecuteFunction(std::string const& name, TEN::Control::Volumes::VolumeTriggerer triggerer, std::string const& parameter)
|
||||
{
|
||||
sol::protected_function_result r;
|
||||
sol::protected_function func = (*m_handler.GetState())["LevelFuncs"][name.c_str()];
|
||||
if (std::holds_alternative<short>(triggerer))
|
||||
{
|
||||
r = func(parameter, std::make_unique<Moveable>(std::get<short>(triggerer), true));
|
||||
}
|
||||
else
|
||||
{
|
||||
r = func(parameter);
|
||||
}
|
||||
|
||||
if (!r.valid())
|
||||
{
|
||||
sol::error err = r;
|
||||
ScriptAssertF(false, "Could not execute function {}: {}", name, err.what());
|
||||
}
|
||||
}
|
||||
|
||||
static void doCallback(sol::protected_function const & func, std::optional<float> dt = std::nullopt) {
|
||||
auto r = dt.has_value() ? func(dt) : func();
|
||||
|
||||
|
|
|
@ -56,8 +56,6 @@ public:
|
|||
|
||||
void ExecuteFunction(std::string const& luaFuncName, short idOne, short idTwo) override;
|
||||
void ExecuteFunction(std::string const & name, TEN::Control::Volumes::VolumeTriggerer) override;
|
||||
void ExecuteFunction(std::string const& name, TEN::Control::Volumes::VolumeTriggerer, std::string const& parameter) override;
|
||||
|
||||
|
||||
void GetVariables(std::vector<SavedVar>& vars) override;
|
||||
void ResetVariables();
|
||||
|
|
|
@ -153,45 +153,6 @@ void Moveable::Register(sol::table & parent)
|
|||
// @function Moveable:MakeInvisible
|
||||
ScriptReserved_MakeInvisible, &Moveable::MakeInvisible,
|
||||
|
||||
/// Make the item not targetable by Lara.
|
||||
// @function Moveable:MakeNotTargetable
|
||||
// @tparam boolean value, true to make him not targetable, false to make him targetable again, Default is true.
|
||||
ScriptReserved_MakeNotTargetable, & Moveable::MakeNotTargetable,
|
||||
|
||||
/// Make the actor moves through its AI_Follow path till the indicated value.
|
||||
// @function Moveable:DoGoToNode
|
||||
// @tparam short value, the ocb number of the AI_Follow object where this actor must go.
|
||||
ScriptReserved_DoGoToNode, & Moveable::DoGoToNode,
|
||||
|
||||
/// Make the actor moves directly to the indicated AI_Follow object, ignoring the other nodes before.
|
||||
// @function Moveable:DoGoDirectlyToNode
|
||||
// @tparam short value, the ocb number of the AI_Follow object where this actor must go.
|
||||
ScriptReserved_DoGoDirectlyToNode, & Moveable::DoGoDirectlyToNode,
|
||||
|
||||
/// Make the actor moves to the AI_Follow object with the next ocb value
|
||||
// @function Moveable:DoGoNextNode
|
||||
ScriptReserved_DoGoNextNode, & Moveable::DoGoNextNode,
|
||||
|
||||
/// Make the guide follow his own path goal, instead of follow the communal path moved with flipeffect 30. Set to false to reactivate classic behaviour.
|
||||
// @function Moveable:DoNewBehaviour
|
||||
// @tparam boolean value, true activate or deactivate the new behaviour. Default is true.
|
||||
ScriptReserved_DoNewBehaviour, & Moveable::DoNewBehaviour,
|
||||
|
||||
/// Make the guide to wait for Lara to be near before to activate a heavy trigger action.
|
||||
// @function Moveable:DoWaitForLara
|
||||
// @tparam boolean value, true to make it wait, false to make it continue with no wait. Default is true.
|
||||
ScriptReserved_DoWaitForLara, & Moveable::DoWaitForLara,
|
||||
|
||||
/// Make the guide to run instead of walk.
|
||||
// @function Moveable:DoRunDefault
|
||||
// @tparam boolean value, true to make it run to the next AI node, false to restore the original behaviour. Default is false.
|
||||
ScriptReserved_DoRunDefault, & Moveable::DoRunDefault,
|
||||
|
||||
/// The next time the guide reads an inscription, it will activate his scared routine.
|
||||
// @function Moveable:DoScareGuide
|
||||
// @tparam boolean value, true to activate the order, flase to cancel it. Default is true.
|
||||
ScriptReserved_DoScareGuide, & Moveable::DoScareGuide,
|
||||
|
||||
/// Get the status of object.
|
||||
// possible values:
|
||||
// 0 - not active
|
||||
|
@ -297,6 +258,11 @@ ScriptReserved_DoScareGuide, & Moveable::DoScareGuide,
|
|||
// @tparam int HP the amount of HP to give the moveable
|
||||
ScriptReserved_SetHP, &Moveable::SetHP,
|
||||
|
||||
/// Get HP definded for that object type (hit points/health points) (Read Only).
|
||||
// @function Moveable:GetSlotHP
|
||||
// @tparam int ID of the moveable slot type.
|
||||
ScriptReserved_GetSlotHP, & Moveable::GetSlotHP,
|
||||
|
||||
/// Get OCB (object code bit) of the moveable
|
||||
// @function Moveable:GetOCB
|
||||
// @treturn int the moveable's current OCB value
|
||||
|
@ -307,15 +273,15 @@ ScriptReserved_DoScareGuide, & Moveable::DoScareGuide,
|
|||
// @tparam int OCB the new value for the moveable's OCB
|
||||
ScriptReserved_SetOCB, &Moveable::SetOCB,
|
||||
|
||||
/// Get ItemFlag[x] (object code bit) of the moveable
|
||||
// @function Moveable:GetItemFlag
|
||||
// @treturn short value from the moveable's ItemFlag[x]
|
||||
ScriptReserved_GetItemFlag, & Moveable::GetItemFlag,
|
||||
/// Get ItemFlags[x] (object code bit) of the moveable
|
||||
// @function Moveable:GetItemFlags
|
||||
// @treturn short value from the moveable's ItemFlags[x]
|
||||
ScriptReserved_GetItemFlags, & Moveable::GetItemFlags,
|
||||
|
||||
/// Set ItemFlag[x] (object code bit) of the moveable
|
||||
// @function Moveable:SetItemFlag
|
||||
// @tparam short value to store in the moveable's ItemFlag[x]
|
||||
ScriptReserved_SetItemFlag, & Moveable::SetItemFlag,
|
||||
/// Set ItemFlags[x] (object code bit) of the moveable
|
||||
// @function Moveable:SetItemFlags
|
||||
// @tparam short value to store in the moveable's ItemFlags[x]
|
||||
ScriptReserved_SetItemFlags, & Moveable::SetItemFlags,
|
||||
|
||||
/// Get the moveable's color
|
||||
// @function Moveable:GetColor
|
||||
|
@ -579,8 +545,11 @@ void Moveable::SetHP(short hp)
|
|||
ScriptAssert(false, "Invalid HP value: " + std::to_string(hp));
|
||||
if (hp < 0)
|
||||
{
|
||||
hp = 0;
|
||||
ScriptWarn("Setting HP to 0.");
|
||||
if (hp != NOT_TARGETABLE)
|
||||
{
|
||||
hp = 0;
|
||||
ScriptWarn("Setting HP to 0.");
|
||||
}
|
||||
}
|
||||
else if (hp > Objects[m_item->ObjectNumber].HitPoints)
|
||||
{
|
||||
|
@ -592,6 +561,11 @@ void Moveable::SetHP(short hp)
|
|||
m_item->HitPoints = hp;
|
||||
}
|
||||
|
||||
short Moveable::GetSlotHP() const
|
||||
{
|
||||
return (Objects[m_item->ObjectNumber].HitPoints);
|
||||
}
|
||||
|
||||
short Moveable::GetOCB() const
|
||||
{
|
||||
return m_item->TriggerFlags;
|
||||
|
@ -602,12 +576,12 @@ void Moveable::SetOCB(short ocb)
|
|||
m_item->TriggerFlags = ocb;
|
||||
}
|
||||
|
||||
short Moveable::GetItemFlag(int index) const
|
||||
short Moveable::GetItemFlags(int index) const
|
||||
{
|
||||
return m_item->ItemFlags[index];
|
||||
}
|
||||
|
||||
void Moveable::SetItemFlag(short value, int index)
|
||||
void Moveable::SetItemFlags(short value, int index)
|
||||
{
|
||||
m_item->ItemFlags[index] = value;
|
||||
}
|
||||
|
@ -800,146 +774,6 @@ void Moveable::MakeInvisible()
|
|||
dynamic_cast<ObjectsHandler*>(g_GameScriptEntities)->TryRemoveColliding(m_num);
|
||||
}
|
||||
|
||||
void Moveable::MakeNotTargetable(bool isNotTargetable)
|
||||
{
|
||||
if (isNotTargetable)
|
||||
m_item->HitPoints = NOT_TARGETABLE;
|
||||
else
|
||||
m_item->HitPoints = Objects[m_item->ObjectNumber].HitPoints;
|
||||
}
|
||||
|
||||
void Moveable::DoGoToNode(short nodeId)
|
||||
{
|
||||
GAME_OBJECT_ID objId = m_item->ObjectNumber;
|
||||
switch (objId)
|
||||
{
|
||||
case ID_GUIDE:
|
||||
m_item:DoNewBehaviour();
|
||||
if (nodeId <= m_item->ItemFlags[4])
|
||||
{
|
||||
m_item->ItemFlags[3] = nodeId;
|
||||
m_item->ItemFlags[2] |= (1 << 3); //turn on bit 3 for flag_RetryNodeSearch
|
||||
}
|
||||
m_item->ItemFlags[4] = nodeId;
|
||||
break;
|
||||
default:
|
||||
std::string InfoStr = "The Lua function DoGoToNode hasn't got actions for the object " + m_item->LuaName + ".";
|
||||
TENLog(InfoStr, LogLevel::Warning, LogConfig::All);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Moveable::DoGoDirectlyToNode(short nodeId)
|
||||
{
|
||||
GAME_OBJECT_ID objId = m_item->ObjectNumber;
|
||||
switch (objId)
|
||||
{
|
||||
case ID_GUIDE:
|
||||
m_item:DoNewBehaviour();
|
||||
m_item->ItemFlags[2] |= (1 << 3); //turn on bit 3 for flag_RetryNodeSearch
|
||||
m_item->ItemFlags[3] = nodeId;
|
||||
m_item->ItemFlags[4] = nodeId;
|
||||
break;
|
||||
default:
|
||||
std::string InfoStr = "The Lua function DoGoDirectlyToNode hasn't got actions for the object " + m_item->LuaName + ".";
|
||||
TENLog(InfoStr, LogLevel::Warning, LogConfig::All);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Moveable::DoGoNextNode()
|
||||
{
|
||||
GAME_OBJECT_ID objId = m_item->ObjectNumber;
|
||||
switch (objId)
|
||||
{
|
||||
case ID_GUIDE:
|
||||
m_item:DoNewBehaviour();
|
||||
m_item->ItemFlags[4] ++;
|
||||
break;
|
||||
default:
|
||||
std::string InfoStr = "The Lua function DoGoNextNode hasn't got actions for the object " + m_item->LuaName + ".";
|
||||
TENLog(InfoStr, LogLevel::Warning, LogConfig::All);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Moveable::DoNewBehaviour(bool isNewBehaviour)
|
||||
{
|
||||
GAME_OBJECT_ID objId = m_item->ObjectNumber;
|
||||
switch (objId)
|
||||
{
|
||||
case ID_GUIDE:
|
||||
if (isNewBehaviour)
|
||||
{
|
||||
m_item->ItemFlags[2] |= (1 << 0); //turn on bit 0 for flag_NewlBehaviour
|
||||
}else{
|
||||
m_item->ItemFlags[2] &= ~(1 << 0); //turn off bit 0 for flag_NewlBehaviour
|
||||
}
|
||||
break;
|
||||
default:
|
||||
std::string InfoStr = "The Lua function DoNewBehaviour hasn't got actions for the object " + m_item->LuaName + ".";
|
||||
TENLog(InfoStr, LogLevel::Warning, LogConfig::All);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Moveable::DoWaitForLara(bool isWaitForLara)
|
||||
{
|
||||
GAME_OBJECT_ID objId = m_item->ObjectNumber;
|
||||
switch (objId)
|
||||
{
|
||||
case ID_GUIDE:
|
||||
if (isWaitForLara)
|
||||
{
|
||||
m_item->ItemFlags[2] &= ~(1 << 1); //turn off bit 1 for flag_IgnoreLaraDistance
|
||||
}else{
|
||||
m_item->ItemFlags[2] |= (1 << 1); //turn on bit 1 for flag_IgnoreLaraDistance
|
||||
}
|
||||
break;
|
||||
default:
|
||||
std::string InfoStr = "The Lua function DoWaitForLara hasn't got actions for the object " + m_item->LuaName + ".";
|
||||
TENLog(InfoStr, LogLevel::Warning, LogConfig::All);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Moveable::DoRunDefault(bool isRunDefault)
|
||||
{
|
||||
GAME_OBJECT_ID objId = m_item->ObjectNumber;
|
||||
switch (objId)
|
||||
{
|
||||
case ID_GUIDE:
|
||||
if (isRunDefault)
|
||||
{
|
||||
m_item->ItemFlags[2] |= (1 << 2); //turn on bit 2 for flag_RunDefault
|
||||
}else{
|
||||
m_item->ItemFlags[2] &= ~(1 << 2); //turn off bit 2 for flag_RunDefault
|
||||
}
|
||||
break;
|
||||
default:
|
||||
std::string InfoStr = "The Lua function DoRunDefault hasn't got actions for the object " + m_item->LuaName + ".";
|
||||
TENLog(InfoStr, LogLevel::Warning, LogConfig::All);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Moveable::DoScareGuide(bool isScaryInscription)
|
||||
{
|
||||
if (m_item->ObjectNumber != ID_GUIDE)
|
||||
{
|
||||
std::string InfoStr = "The Lua function DoScareGuide hasn't got actions for the object " + m_item->LuaName + ", it only works for GUIDE objects.";
|
||||
TENLog(InfoStr, LogLevel::Warning, LogConfig::All);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isScaryInscription)
|
||||
{
|
||||
m_item->ItemFlags[2] |= (1 << 4); //turn on bit 4 for flag_ScaryInscription
|
||||
}else{
|
||||
m_item->ItemFlags[2] &= ~(1 << 4); //turn off bit 4 for flag_ScaryInscription
|
||||
}
|
||||
}
|
||||
|
||||
void Moveable::Invalidate()
|
||||
{
|
||||
// keep m_item as it is so that we can properly remove it from the moveables set when
|
||||
|
|
|
@ -58,14 +58,16 @@ public:
|
|||
[[nodiscard]] short GetHP() const;
|
||||
void SetHP(short hp);
|
||||
|
||||
[[nodiscard]] short GetSlotHP() const;
|
||||
|
||||
[[nodiscard]] short GetOCB() const;
|
||||
void SetOCB(short ocb);
|
||||
|
||||
[[nodiscard]] aiBitsType GetAIBits() const;
|
||||
void SetAIBits(aiBitsType const & bits);
|
||||
|
||||
[[nodiscard]] short GetItemFlag(int index = 0) const;
|
||||
void SetItemFlag(short value, int index = 0);
|
||||
[[nodiscard]] short GetItemFlags(int index = 0) const;
|
||||
void SetItemFlags(short value, int index = 0);
|
||||
|
||||
[[nodiscard]] bool GetHitStatus() const;
|
||||
|
||||
|
@ -78,15 +80,6 @@ public:
|
|||
void EnableItem();
|
||||
void DisableItem();
|
||||
void MakeInvisible();
|
||||
void MakeNotTargetable(bool isNotTargetable = true);
|
||||
|
||||
void DoGoToNode(short nodeId);
|
||||
void DoGoDirectlyToNode(short nodeId);
|
||||
void DoGoNextNode();
|
||||
void DoNewBehaviour( bool isNewBehaviour = true);
|
||||
void DoWaitForLara( bool isWaitForLara = true);
|
||||
void DoRunDefault( bool isRunDefault = false);
|
||||
void DoScareGuide(bool isScaryInscription = true);
|
||||
|
||||
[[nodiscard]] std::string GetOnHit() const;
|
||||
void SetOnHit(std::string const &);
|
||||
|
|
|
@ -791,23 +791,7 @@ void ReadRooms()
|
|||
numBytes = ReadInt8();
|
||||
ReadBytes(buffer, numBytes);
|
||||
volume.OnLeave = std::string(buffer, buffer + numBytes);
|
||||
|
||||
std::string temporalParameter;
|
||||
numBytes = ReadInt8();
|
||||
ReadBytes(buffer, numBytes);
|
||||
temporalParameter = std::string(buffer, buffer + numBytes);
|
||||
volume.ParamOnEnter = (temporalParameter.empty()) ? "nil" : temporalParameter;
|
||||
|
||||
numBytes = ReadInt8();
|
||||
ReadBytes(buffer, numBytes);
|
||||
temporalParameter = std::string(buffer, buffer + numBytes);
|
||||
volume.ParamOnInside = (temporalParameter.empty()) ? "nil" : temporalParameter;
|
||||
|
||||
numBytes = ReadInt8();
|
||||
ReadBytes(buffer, numBytes);
|
||||
temporalParameter = std::string(buffer, buffer + numBytes);
|
||||
volume.ParamOnLeave = (temporalParameter.empty()) ? "nil" : temporalParameter;
|
||||
|
||||
|
||||
volume.OneShot = ReadInt8();
|
||||
volume.Status = TriggerStatus::Outside;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue