From cf8723c4486c4e3ffb3674d23918dc380538a23f Mon Sep 17 00:00:00 2001 From: hispidence Date: Sat, 24 Jul 2021 12:29:25 +0100 Subject: [PATCH] Add GameScriptSoundSourceInfo and GameScriptAIObject, and associated functions. --- TR5Main/Scripting/GameLogicScript.cpp | 18 +- TR5Main/Scripting/GameLogicScript.h | 27 ++- TR5Main/Scripting/GameScriptAIObject.cpp | 163 ++++++++++++++++++ TR5Main/Scripting/GameScriptAIObject.h | 47 +++++ .../Scripting/GameScriptSoundSourceInfo.cpp | 103 +++++++++++ TR5Main/Scripting/GameScriptSoundSourceInfo.h | 33 ++++ TR5Main/TR5Main.vcxproj | 4 + 7 files changed, 386 insertions(+), 9 deletions(-) create mode 100644 TR5Main/Scripting/GameScriptAIObject.cpp create mode 100644 TR5Main/Scripting/GameScriptAIObject.h create mode 100644 TR5Main/Scripting/GameScriptSoundSourceInfo.cpp create mode 100644 TR5Main/Scripting/GameScriptSoundSourceInfo.h diff --git a/TR5Main/Scripting/GameLogicScript.cpp b/TR5Main/Scripting/GameLogicScript.cpp index dec14f09c..7752746a0 100644 --- a/TR5Main/Scripting/GameLogicScript.cpp +++ b/TR5Main/Scripting/GameLogicScript.cpp @@ -436,22 +436,32 @@ std::unique_ptr GetTByName(std::string const & type, std::string const& name, std::unique_ptr GameScript::GetItemByName(std::string const & name) { - return GetTByName("Item", name, m_itemsMapName); + return GetTByName("ItemInfo", name, m_itemsMapName); } std::unique_ptr GameScript::GetMeshByName(std::string const & name) { - return GetTByName("Mesh", name, m_meshesMapName); + return GetTByName("MeshInfo", name, m_meshesMapName); } std::unique_ptr GameScript::GetCameraByName(std::string const & name) { - return GetTByName("Camera", name, m_camerasMapName); + return GetTByName("CameraInfo", name, m_camerasMapName); } std::unique_ptr GameScript::GetSinkByName(std::string const & name) { - return GetTByName("Sink", name, m_sinksMapName); + return GetTByName("SinkInfo", name, m_sinksMapName); +} + +std::unique_ptr GameScript::GetAIObjectByName(std::string const & name) +{ + return GetTByName("AIObject", name, m_aiObjectsMapName); +} + +std::unique_ptr GameScript::GetSoundSourceByName(std::string const & name) +{ + return GetTByName("SoundSourceInfo", name, m_soundSourcesMapName); } void GameScript::PlayAudioTrack(std::string const & trackName, bool looped) diff --git a/TR5Main/Scripting/GameLogicScript.h b/TR5Main/Scripting/GameLogicScript.h index 9271527fe..6499e74d0 100644 --- a/TR5Main/Scripting/GameLogicScript.h +++ b/TR5Main/Scripting/GameLogicScript.h @@ -9,6 +9,8 @@ #include "GameScriptItemInfo.h" #include "GameScriptMeshInfo.h" #include "GameScriptSinkInfo.h" +#include "GameScriptAIObject.h" +#include "GameScriptSoundSourceInfo.h" #include "GameScriptCameraInfo.h" struct LuaFunction { @@ -54,6 +56,8 @@ private: std::map m_meshesMapName; std::map m_camerasMapName; std::map m_sinksMapName; + std::map m_soundSourcesMapName; + std::map m_aiObjectsMapName; std::vector m_triggers; sol::protected_function m_onStart; sol::protected_function m_onLoad; @@ -65,15 +69,26 @@ public: void FreeLevelScripts(); void AddTrigger(LuaFunction* function); + void AddLuaId(int luaId, short itemNumber); 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); + void AssignItemsAndLara(); @@ -81,11 +96,13 @@ public: void ExecuteFunction(std::string const & name); void MakeItemInvisible(short id); - std::unique_ptr GetItemById(int id); - std::unique_ptr GetItemByName(std::string const & name); - std::unique_ptr GetMeshByName(std::string const & name); - std::unique_ptr GetCameraByName(std::string const & name); - std::unique_ptr GetSinkByName(std::string const & name); + std::unique_ptr GetItemById(int id); + std::unique_ptr GetItemByName(std::string const & name); + std::unique_ptr GetMeshByName(std::string const & name); + std::unique_ptr GetCameraByName(std::string const & name); + std::unique_ptr GetSinkByName(std::string const & name); + std::unique_ptr GetSoundSourceByName(std::string const & name); + std::unique_ptr GetAIObjectByName(std::string const & name); // Variables template diff --git a/TR5Main/Scripting/GameScriptAIObject.cpp b/TR5Main/Scripting/GameScriptAIObject.cpp new file mode 100644 index 000000000..e26cb98af --- /dev/null +++ b/TR5Main/Scripting/GameScriptAIObject.cpp @@ -0,0 +1,163 @@ +#pragma once +#include "framework.h" +#include "GameScriptAIObject.h" +#include "GameScriptPosition.h" +#include +/*** +AI object + +@classmod AIObject +@pragma nostrip +*/ + +extern bool const WarningsAsErrors; + +constexpr auto LUA_CLASS_NAME{ "AIObject" }; + +static auto index_error = index_error_maker(GameScriptAIObject, LUA_CLASS_NAME); + +GameScriptAIObject::GameScriptAIObject(AI_OBJECT & ref, bool temp) : m_aiObject{ref}, m_temporary{ temp } +{}; + +GameScriptAIObject::~GameScriptAIObject() { + if (m_temporary) + { + s_callbackRemoveName(m_aiObject.luaName); + } +} + +void GameScriptAIObject::Register(sol::state* state) +{ + state->new_usertype(LUA_CLASS_NAME, + sol::meta_function::index, index_error, + + /// (@{Position}) position in level + // @mem pos + "pos", sol::property(&GameScriptAIObject::GetPos, &GameScriptAIObject::SetPos), + + /// (int) y-axis rotation + // @mem yRot + "yRot", sol::property(&GameScriptAIObject::GetYRot, &GameScriptAIObject::SetYRot), + + /// (string) unique string identifier. + // e.g. "door_back_room" or "cracked_greek_statue" + // @mem name + "name", sol::property(&GameScriptAIObject::GetName, &GameScriptAIObject::SetName), + + /// (int) room number + // @mem room + "room", sol::property(&GameScriptAIObject::GetRoom, &GameScriptAIObject::SetRoom), + + /// (@{ObjID}) object ID + // @mem objID + "objID", sol::property(&GameScriptAIObject::GetObjID, &GameScriptAIObject::SetObjID), + + /// (short) flags + // @mem flags + "flags", sol::property(&GameScriptAIObject::GetFlags, &GameScriptAIObject::SetFlags), + + /// (short) trigger flags + // @mem triggerFlags + "triggerFlags", sol::property(&GameScriptAIObject::GetTriggerFlags, &GameScriptAIObject::SetTriggerFlags), + + /// (short) box number + // @mem boxNumber + "boxNumber", sol::property(&GameScriptAIObject::GetBoxNumber, &GameScriptAIObject::SetBoxNumber) + ); +} + +GameScriptPosition GameScriptAIObject::GetPos() const +{ + return GameScriptPosition{ m_aiObject.x, m_aiObject.y, m_aiObject.z }; +} + +void GameScriptAIObject::SetPos(GameScriptPosition const& pos) +{ + m_aiObject.x = pos.x; + m_aiObject.y = pos.y; + m_aiObject.z = pos.z; +} + +GAME_OBJECT_ID GameScriptAIObject::GetObjID() const +{ + return m_aiObject.objectNumber; +} + +void GameScriptAIObject::SetObjID(GAME_OBJECT_ID objNum) +{ + m_aiObject.objectNumber = objNum; +} + +short GameScriptAIObject::GetYRot() const +{ + return m_aiObject.yRot; +} + +void GameScriptAIObject::SetYRot(short yRot) +{ + m_aiObject.yRot = yRot; +} + +std::string GameScriptAIObject::GetName() const +{ + return m_aiObject.luaName; +} + +void GameScriptAIObject::SetName(std::string const & id) +{ + if (id.empty() && WarningsAsErrors) + throw std::runtime_error("Name cannot be blank"); + + // remove the old name if we have one + s_callbackRemoveName(m_aiObject.luaName); + + // un-register any other objects using this name. + // maybe we should throw an error if another object + // already uses the name... + s_callbackRemoveName(id); + m_aiObject.luaName = id; + // todo add error checking + s_callbackSetName(id, m_aiObject); +} + +short GameScriptAIObject::GetRoom() const +{ + return m_aiObject.roomNumber; +} + +void GameScriptAIObject::SetRoom(short room) +{ + m_aiObject.roomNumber = room; +} + +short GameScriptAIObject::GetTriggerFlags() const +{ + + return m_aiObject.triggerFlags; +} + +void GameScriptAIObject::SetTriggerFlags(short tf) +{ + m_aiObject.triggerFlags = tf; +} + +short GameScriptAIObject::GetFlags() const +{ + return m_aiObject.flags; +} + +void GameScriptAIObject::SetFlags(short tf) +{ + m_aiObject.flags = tf; +} + +short GameScriptAIObject::GetBoxNumber() const +{ + return m_aiObject.boxNumber; +} + +void GameScriptAIObject::SetBoxNumber(short bn) +{ + m_aiObject.boxNumber = bn; +} + diff --git a/TR5Main/Scripting/GameScriptAIObject.h b/TR5Main/Scripting/GameScriptAIObject.h new file mode 100644 index 000000000..2dd9e9f2d --- /dev/null +++ b/TR5Main/Scripting/GameScriptAIObject.h @@ -0,0 +1,47 @@ +#pragma once + +#include "GameScriptNamedBase.h" +#include "level.h" + +namespace sol { + class state; +} +class GameScriptPosition; + +class GameScriptAIObject : public GameScriptNamedBase +{ +public: + GameScriptAIObject(AI_OBJECT& ref, bool temp); + ~GameScriptAIObject(); + + static void Register(sol::state *); + + GameScriptPosition GetPos() const; + void SetPos(GameScriptPosition const& pos); + + short GetRoom() const; + void SetRoom(short Room); + + std::string GetName() const; + void SetName(std::string const &); + + GAME_OBJECT_ID GetObjID() const; + void SetObjID(GAME_OBJECT_ID); + + short GetTriggerFlags() const; + void SetTriggerFlags(short); + + short GetFlags() const; + void SetFlags(short); + + short GetYRot() const; + void SetYRot(short); + + short GetBoxNumber() const; + void SetBoxNumber(short); + +private: + AI_OBJECT & m_aiObject; + bool m_temporary; +}; + diff --git a/TR5Main/Scripting/GameScriptSoundSourceInfo.cpp b/TR5Main/Scripting/GameScriptSoundSourceInfo.cpp new file mode 100644 index 000000000..235a36630 --- /dev/null +++ b/TR5Main/Scripting/GameScriptSoundSourceInfo.cpp @@ -0,0 +1,103 @@ +#include "framework.h" +#include "GameScriptSoundSourceInfo.h" +#include "GameScriptPosition.h" +/*** +Camera info + +@classmod SoundSourceInfo +@pragma nostrip +*/ + +extern bool const WarningsAsErrors; + +static constexpr auto LUA_CLASS_NAME{ "SoundSourceInfo" }; + +static auto index_error = index_error_maker(GameScriptSoundSourceInfo, LUA_CLASS_NAME); + +GameScriptSoundSourceInfo::GameScriptSoundSourceInfo(SOUND_SOURCE_INFO & ref, bool temp) : m_soundSource{ref}, m_temporary{ temp } +{}; + +GameScriptSoundSourceInfo::~GameScriptSoundSourceInfo() { + if (m_temporary) + { + s_callbackRemoveName(m_soundSource.luaName); + } +} + +void GameScriptSoundSourceInfo::Register(sol::state* state) +{ + state->new_usertype(LUA_CLASS_NAME, + sol::meta_function::index, index_error, + + /// (@{Position}) position in level + // @mem pos + "pos", sol::property(&GameScriptSoundSourceInfo::GetPos, &GameScriptSoundSourceInfo::SetPos), + + /// (string) unique string identifier. + // e.g. "machine_sound_1" or "discordant_humming" + // @mem name + "name", sol::property(&GameScriptSoundSourceInfo::GetName, &GameScriptSoundSourceInfo::SetName), + + /// (int) sound ID + // @mem soundID + "soundID", sol::property(&GameScriptSoundSourceInfo::GetSoundID, &GameScriptSoundSourceInfo::SetSoundID), + + /// (int) flags + // @mem flags + "flags", sol::property(&GameScriptSoundSourceInfo::GetFlags, &GameScriptSoundSourceInfo::SetFlags) + ); +} + +GameScriptPosition GameScriptSoundSourceInfo::GetPos() const +{ + return GameScriptPosition{ m_soundSource.x, m_soundSource.y, m_soundSource.z }; +} + +void GameScriptSoundSourceInfo::SetPos(GameScriptPosition const& pos) +{ + m_soundSource.x = pos.x; + m_soundSource.y = pos.y; + m_soundSource.z = pos.z; +} + +std::string GameScriptSoundSourceInfo::GetName() const +{ + return m_soundSource.luaName; +} + +void GameScriptSoundSourceInfo::SetName(std::string const & id) +{ + if (id.empty() && WarningsAsErrors) + throw std::runtime_error("Name cannot be blank"); + + // remove the old name if we have one + s_callbackRemoveName(m_soundSource.luaName); + + // un-register any other objects using this name. + // maybe we should throw an error if another object + // already uses the name... + s_callbackRemoveName(id); + m_soundSource.luaName = id; + // todo add error checking + s_callbackSetName(id, m_soundSource); +} + +int GameScriptSoundSourceInfo::GetSoundID() const +{ + return m_soundSource.soundId; +} + +void GameScriptSoundSourceInfo::SetSoundID(int soundID) +{ + m_soundSource.soundId = soundID; +} + +int GameScriptSoundSourceInfo::GetFlags() const +{ + return m_soundSource.flags; +} + +void GameScriptSoundSourceInfo::SetFlags(int flags) +{ + m_soundSource.flags = flags; +} diff --git a/TR5Main/Scripting/GameScriptSoundSourceInfo.h b/TR5Main/Scripting/GameScriptSoundSourceInfo.h new file mode 100644 index 000000000..957ab95d4 --- /dev/null +++ b/TR5Main/Scripting/GameScriptSoundSourceInfo.h @@ -0,0 +1,33 @@ +#pragma once + +#include "GameScriptNamedBase.h" +#include "phd_global.h" + +namespace sol { + class state; +} +class GameScriptPosition; + +class GameScriptSoundSourceInfo : public GameScriptNamedBase +{ +public: + GameScriptSoundSourceInfo(SOUND_SOURCE_INFO& ref, bool temp); + ~GameScriptSoundSourceInfo(); + static void Register(sol::state *); + GameScriptPosition GetPos() const; + void SetPos(GameScriptPosition const& pos); + + int GetSoundID() const; + void SetSoundID(int soundID); + + int GetFlags() const; + void SetFlags(int flags); + + std::string GetName() const; + void SetName(std::string const &); + +private: + SOUND_SOURCE_INFO & m_soundSource; + bool m_temporary; +}; + diff --git a/TR5Main/TR5Main.vcxproj b/TR5Main/TR5Main.vcxproj index 34e47fb8a..cf86235d3 100644 --- a/TR5Main/TR5Main.vcxproj +++ b/TR5Main/TR5Main.vcxproj @@ -170,6 +170,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\" + @@ -392,6 +393,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\" + @@ -498,6 +500,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\" + @@ -688,6 +691,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\" +