TombEngine/TR5Main/Scripting/GameLogicScript.h
hispidence dc40060a63 Make m_levelFuncs an unordered_set, as these seem to be the proper structure to use when the key IS the value.
Make all GameScript maps unordered_maps, as these are supposed to be more suitable for cases where we don't need the data to be sorted.

Add default member initialisers to GameScript.
2021-08-06 16:47:24 +01:00

126 lines
4 KiB
C++

#pragma once
#include "items.h"
#include "room.h"
#include "LuaHandler.h"
#include "trmath.h"
#include <unordered_set>
#include "GameScriptColor.h"
#include "GameScriptPosition.h"
#include "GameScriptRotation.h"
#include "GameScriptItemInfo.h"
#include "GameScriptMeshInfo.h"
#include "GameScriptSinkInfo.h"
#include "GameScriptAIObject.h"
#include "GameScriptSoundSourceInfo.h"
#include "GameScriptCameraInfo.h"
struct LuaFunction {
std::string Name;
std::string Code;
bool Executed;
};
struct GameScriptVector3 {
float x;
float y;
float z;
};
class LuaVariables
{
public:
std::map<std::string, sol::object> variables;
sol::object GetVariable(sol::table tab, std::string key);
void SetVariable(sol::table tab, std::string key, sol::object value);
};
struct LuaVariable
{
bool IsGlobal;
std::string Name;
int Type;
float FloatValue;
int IntValue;
std::string StringValue;
bool BoolValue;
};
class GameScript : public LuaHandler
{
private:
LuaVariables m_globals{};
LuaVariables m_locals{};
std::unordered_map<std::string, short> m_itemsMapName{};
std::unordered_map<std::string, MESH_INFO&> m_meshesMapName{};
std::unordered_map<std::string, LEVEL_CAMERA_INFO&> m_camerasMapName{};
std::unordered_map<std::string, SINK_INFO&> m_sinksMapName{};
std::unordered_map<std::string, SOUND_SOURCE_INFO&> m_soundSourcesMapName{};
std::unordered_map<std::string, AI_OBJECT&> m_aiObjectsMapName{};
std::unordered_set<std::string> m_levelFuncs{};
std::vector<LuaFunction* > m_triggers{};
sol::protected_function m_onStart{};
sol::protected_function m_onLoad{};
sol::protected_function m_onControlPhase{};
sol::protected_function m_onSave{};
sol::protected_function m_onEnd{};
public:
GameScript(sol::state* lua);
void FreeLevelScripts();
void AddTrigger(LuaFunction* function);
bool AddLuaNameItem(std::string const & luaName, short itemNumber);
bool RemoveLuaNameItem(std::string const& luaName);
bool AddLuaNameMesh(std::string const & luaName, MESH_INFO &);
bool RemoveLuaNameMesh(std::string const& luaName);
bool AddLuaNameCamera(std::string const & luaName, LEVEL_CAMERA_INFO &);
bool RemoveLuaNameCamera(std::string const& luaName);
bool AddLuaNameSink(std::string const & luaName, SINK_INFO &);
bool RemoveLuaNameSink(std::string const& luaName);
bool AddLuaNameSoundSource(std::string const& luaName, SOUND_SOURCE_INFO&);
bool RemoveLuaNameSoundSource(std::string const& luaName);
bool AddLuaNameAIObject(std::string const & luaName, AI_OBJECT &);
bool RemoveLuaNameAIObject(std::string const& luaName);
bool SetLevelFunc(sol::table tab, std::string const& luaName, sol::object obj);
void AssignItemsAndLara();
bool ExecuteTrigger(short index);
void ExecuteFunction(std::string const & name);
void MakeItemInvisible(short id);
std::unique_ptr<GameScriptItemInfo> GetItemByName(std::string const & name);
std::unique_ptr<GameScriptMeshInfo> GetMeshByName(std::string const & name);
std::unique_ptr<GameScriptCameraInfo> GetCameraByName(std::string const & name);
std::unique_ptr<GameScriptSinkInfo> GetSinkByName(std::string const & name);
std::unique_ptr<GameScriptSoundSourceInfo> GetSoundSourceByName(std::string const & name);
std::unique_ptr<GameScriptAIObject> GetAIObjectByName(std::string const & name);
// Variables
template <typename T>
void GetVariables(std::map<std::string, T>& locals, std::map<std::string, T>& globals);
template <typename T>
void SetVariables(std::map<std::string, T>& locals, std::map<std::string, T>& globals);
void ResetVariables();
void InitCallbacks();
void OnStart();
void OnLoad();
void OnControlPhase();
void OnSave();
void OnEnd();
};
int CalculateDistance(GameScriptPosition pos1, GameScriptPosition pos2);
int CalculateHorizontalDistance(GameScriptPosition pos1, GameScriptPosition pos2);