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-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 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
|
|
|
|
2020-06-18 15:54:08 +02:00
|
|
|
sol::object GetVariable(std::string key);
|
|
|
|
void SetVariable(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-07-23 02:09:52 +01:00
|
|
|
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::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);
|
|
|
|
void AddLuaId(int luaId, short itemNumber);
|
2021-07-17 22:26:07 +01:00
|
|
|
bool AddLuaName(std::string const & luaName, short itemNumber);
|
|
|
|
bool RemoveLuaName(std::string const& luaName);
|
2021-07-21 18:12:17 +01:00
|
|
|
bool AddLuaNameMesh(std::string const & luaName, MESH_INFO &);
|
|
|
|
bool RemoveLuaNameMesh(std::string const& luaName);
|
2021-07-23 02:09:52 +01:00
|
|
|
bool AddLuaNameCamera(std::string const & luaName, LEVEL_CAMERA_INFO &);
|
|
|
|
bool RemoveLuaNameCamera(std::string const& luaName);
|
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
|
|
|
|
|
|
|
std::unique_ptr<GameScriptItemInfo> GetItemById(int 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);
|
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();
|
|
|
|
|
|
|
|
// Sound
|
2021-07-04 14:33:57 +01:00
|
|
|
static void PlayAudioTrack(std::string const & trackName, bool looped);
|
2021-06-29 05:00:15 +02:00
|
|
|
void PlaySoundEffect(int id, GameScriptPosition pos, int flags);
|
|
|
|
void PlaySoundEffect(int id, int flags);
|
2021-07-04 14:33:57 +01:00
|
|
|
static void SetAmbientTrack(std::string const & trackName);
|
2021-06-29 05:00:15 +02:00
|
|
|
|
|
|
|
// Special FX
|
|
|
|
void AddLightningArc(GameScriptPosition src, GameScriptPosition dest, GameScriptColor color, int lifetime, int amplitude, int beamWidth, int segments, int flags);
|
|
|
|
void AddShockwave(GameScriptPosition pos, int innerRadius, int outerRadius, GameScriptColor color, int lifetime, int speed, int angle, int flags);
|
|
|
|
void AddSprite(GameScriptPosition pos, VectorInt3 vel, VectorInt2 falloff, GameScriptColor startColor, GameScriptColor endColor, int lifeTime, int fadeIn, int fadeOut, int spriteNum, int startSize, int endSize, float angle, int rotation);
|
|
|
|
void AddDynamicLight(GameScriptPosition pos, GameScriptColor color, int radius, int lifetime);
|
|
|
|
void AddBlood(GameScriptPosition pos, int num);
|
|
|
|
void AddFireFlame(GameScriptPosition pos, int size);
|
|
|
|
void Earthquake(int strength);
|
|
|
|
|
|
|
|
// Inventory
|
2021-07-13 13:21:13 +01:00
|
|
|
static void InventoryAdd(GAME_OBJECT_ID slot, sol::optional<int> count);
|
|
|
|
static void InventoryRemove(GAME_OBJECT_ID slot, sol::optional<int> count);
|
|
|
|
static int InventoryGetCount(GAME_OBJECT_ID slot);
|
|
|
|
static void InventorySetCount(GAME_OBJECT_ID slot, int count);
|
2021-06-29 05:00:15 +02:00
|
|
|
void InventoryCombine(int slot1, int slot2);
|
2021-07-05 18:18:20 +01:00
|
|
|
void InventorySeparate(int slot);
|
2021-06-29 05:00:15 +02:00
|
|
|
|
|
|
|
// Misc
|
|
|
|
void PrintString(std::string key, GameScriptPosition pos, GameScriptColor color, int lifetime, int flags);
|
|
|
|
int FindRoomNumber(GameScriptPosition pos);
|
2020-04-30 21:52:16 +02:00
|
|
|
void JumpToLevel(int levelNum);
|
|
|
|
int GetSecretsCount();
|
|
|
|
void SetSecretsCount(int secretsNum);
|
|
|
|
void AddOneSecret();
|
2021-06-29 05:00:15 +02:00
|
|
|
int CalculateDistance(GameScriptPosition pos1, GameScriptPosition pos2);
|
|
|
|
int CalculateHorizontalDistance(GameScriptPosition pos1, GameScriptPosition pos2);
|
2021-07-01 19:31:15 +01:00
|
|
|
|
2021-07-04 14:33:57 +01:00
|
|
|
void InitCallbacks();
|
|
|
|
void OnStart();
|
|
|
|
void OnLoad();
|
|
|
|
void OnControlPhase();
|
|
|
|
void OnSave();
|
|
|
|
void OnEnd();
|
2018-09-22 23:54:36 +02:00
|
|
|
};
|