2020-04-30 21:52:16 +02:00
|
|
|
#pragma once
|
2020-05-30 15:55:23 +02:00
|
|
|
#include "items.h"
|
2021-07-21 18:12:17 +01:00
|
|
|
#include "room.h"
|
2021-06-16 14:39:43 +01:00
|
|
|
#include "LuaHandler.h"
|
2021-06-29 05:00:15 +02:00
|
|
|
#include "trmath.h"
|
2021-08-06 16:47:24 +01:00
|
|
|
#include <unordered_set>
|
2021-06-29 05:28:17 +02:00
|
|
|
#include "GameScriptColor.h"
|
|
|
|
#include "GameScriptPosition.h"
|
|
|
|
#include "GameScriptRotation.h"
|
|
|
|
#include "GameScriptItemInfo.h"
|
2021-07-21 18:12:17 +01:00
|
|
|
#include "GameScriptMeshInfo.h"
|
2021-07-23 16:02:30 +01:00
|
|
|
#include "GameScriptSinkInfo.h"
|
2021-07-24 12:29:25 +01:00
|
|
|
#include "GameScriptAIObject.h"
|
|
|
|
#include "GameScriptSoundSourceInfo.h"
|
2021-07-23 02:09:52 +01:00
|
|
|
#include "GameScriptCameraInfo.h"
|
2020-04-30 21:52:16 +02:00
|
|
|
|
2021-07-18 15:22:15 +01:00
|
|
|
struct LuaFunction {
|
2020-06-18 15:54:08 +02:00
|
|
|
std::string Name;
|
|
|
|
std::string Code;
|
2020-04-30 21:52:16 +02:00
|
|
|
bool Executed;
|
|
|
|
};
|
|
|
|
|
2021-06-29 05:00:15 +02:00
|
|
|
struct GameScriptVector3 {
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
float z;
|
|
|
|
};
|
|
|
|
|
2020-04-30 21:52:16 +02:00
|
|
|
|
|
|
|
class LuaVariables
|
|
|
|
{
|
|
|
|
public:
|
2020-06-20 23:39:08 +02:00
|
|
|
std::map<std::string, sol::object> variables;
|
2020-04-30 21:52:16 +02:00
|
|
|
|
2021-08-05 21:36:18 +01:00
|
|
|
sol::object GetVariable(sol::table tab, std::string key);
|
|
|
|
void SetVariable(sol::table tab, std::string key, sol::object value);
|
2020-04-30 21:52:16 +02:00
|
|
|
};
|
|
|
|
|
2021-07-18 15:22:15 +01:00
|
|
|
struct LuaVariable
|
2020-04-30 21:52:16 +02:00
|
|
|
{
|
|
|
|
bool IsGlobal;
|
2020-06-18 15:54:08 +02:00
|
|
|
std::string Name;
|
2020-04-30 21:52:16 +02:00
|
|
|
int Type;
|
|
|
|
float FloatValue;
|
|
|
|
int IntValue;
|
2020-06-18 15:54:08 +02:00
|
|
|
std::string StringValue;
|
2020-04-30 21:52:16 +02:00
|
|
|
bool BoolValue;
|
|
|
|
};
|
|
|
|
|
2021-06-16 14:39:43 +01:00
|
|
|
class GameScript : public LuaHandler
|
2020-04-30 21:52:16 +02:00
|
|
|
{
|
|
|
|
private:
|
2021-08-06 16:47:24 +01:00
|
|
|
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{};
|
2020-04-30 21:52:16 +02:00
|
|
|
public:
|
|
|
|
GameScript(sol::state* lua);
|
|
|
|
|
|
|
|
void FreeLevelScripts();
|
|
|
|
void AddTrigger(LuaFunction* function);
|
2021-07-24 12:29:25 +01:00
|
|
|
|
2021-07-23 16:02:30 +01:00
|
|
|
bool AddLuaNameItem(std::string const & luaName, short itemNumber);
|
|
|
|
bool RemoveLuaNameItem(std::string const& luaName);
|
2021-07-24 12:29:25 +01:00
|
|
|
|
2021-07-21 18:12:17 +01:00
|
|
|
bool AddLuaNameMesh(std::string const & luaName, MESH_INFO &);
|
|
|
|
bool RemoveLuaNameMesh(std::string const& luaName);
|
2021-07-24 12:29:25 +01:00
|
|
|
|
2021-07-23 02:09:52 +01:00
|
|
|
bool AddLuaNameCamera(std::string const & luaName, LEVEL_CAMERA_INFO &);
|
|
|
|
bool RemoveLuaNameCamera(std::string const& luaName);
|
2021-07-24 12:29:25 +01:00
|
|
|
|
2021-07-23 16:02:30 +01:00
|
|
|
bool AddLuaNameSink(std::string const & luaName, SINK_INFO &);
|
|
|
|
bool RemoveLuaNameSink(std::string const& luaName);
|
2021-07-24 12:29:25 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2021-08-05 21:36:18 +01:00
|
|
|
bool SetLevelFunc(sol::table tab, std::string const& luaName, sol::object obj);
|
|
|
|
|
2020-04-30 21:52:16 +02:00
|
|
|
void AssignItemsAndLara();
|
|
|
|
|
2021-06-29 05:00:15 +02:00
|
|
|
|
|
|
|
bool ExecuteTrigger(short index);
|
2021-07-17 22:26:07 +01:00
|
|
|
void ExecuteFunction(std::string const & name);
|
2021-06-29 05:00:15 +02:00
|
|
|
void MakeItemInvisible(short id);
|
2021-07-23 02:09:52 +01:00
|
|
|
|
2021-07-24 12:29:25 +01:00
|
|
|
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);
|
2021-06-29 05:00:15 +02:00
|
|
|
|
|
|
|
// Variables
|
2020-06-09 04:16:51 -03:00
|
|
|
template <typename T>
|
2020-06-20 23:39:08 +02:00
|
|
|
void GetVariables(std::map<std::string, T>& locals, std::map<std::string, T>& globals);
|
2020-06-09 04:16:51 -03:00
|
|
|
template <typename T>
|
2020-06-20 23:39:08 +02:00
|
|
|
void SetVariables(std::map<std::string, T>& locals, std::map<std::string, T>& globals);
|
2021-06-29 05:00:15 +02:00
|
|
|
void ResetVariables();
|
|
|
|
|
2021-07-01 19:31:15 +01:00
|
|
|
|
2021-07-04 14:33:57 +01:00
|
|
|
void InitCallbacks();
|
|
|
|
void OnStart();
|
|
|
|
void OnLoad();
|
2021-08-12 18:20:14 +01:00
|
|
|
void OnControlPhase(float dt);
|
2021-07-04 14:33:57 +01:00
|
|
|
void OnSave();
|
|
|
|
void OnEnd();
|
2021-08-05 21:36:18 +01:00
|
|
|
};
|