mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-01 01:08:01 +03:00

Rework Level and Game tables as they weren't entirely working before. These correspond to m_locals and m_globals, which hold the level-specific and game-spanning data that will go into save files. Make GetVariable and SetVariable take sol::table args. Sol seems to require this in order to use them as metamethods of a table (it doesn't require them for usertypes, but it seems more logical from the API point of view for Level and Game to be tables). Add documentation for the above tables. Move several functions out of the GameScript class in order to simplify its interface, and make them static functions that only live in GameLogicScript.cpp. Remove g_GameScript from GameLogicScript.cpp as it's not used there; let winmain.cpp deal with it instead.
127 lines
4 KiB
C++
127 lines
4 KiB
C++
#pragma once
|
|
#include "items.h"
|
|
#include "room.h"
|
|
#include "LuaHandler.h"
|
|
#include "trmath.h"
|
|
#include <unordered_map>
|
|
#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::map<int, short> m_itemsMapId;
|
|
std::map<std::string, short> m_itemsMapName;
|
|
std::map<std::string, MESH_INFO&> m_meshesMapName;
|
|
std::map<std::string, LEVEL_CAMERA_INFO&> m_camerasMapName;
|
|
std::map<std::string, SINK_INFO&> m_sinksMapName;
|
|
std::map<std::string, SOUND_SOURCE_INFO&> m_soundSourcesMapName;
|
|
std::map<std::string, AI_OBJECT &> m_aiObjectsMapName;
|
|
std::unordered_map<std::string, bool> 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);
|
|
|