mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-10 04:26:42 +03:00
Add GameScriptSoundSourceInfo and GameScriptAIObject, and associated functions.
This commit is contained in:
parent
6720fb2318
commit
cf8723c448
7 changed files with 386 additions and 9 deletions
|
@ -436,22 +436,32 @@ std::unique_ptr<T> GetTByName(std::string const & type, std::string const& name,
|
|||
|
||||
std::unique_ptr<GameScriptItemInfo> GameScript::GetItemByName(std::string const & name)
|
||||
{
|
||||
return GetTByName<GameScriptItemInfo, short>("Item", name, m_itemsMapName);
|
||||
return GetTByName<GameScriptItemInfo, short>("ItemInfo", name, m_itemsMapName);
|
||||
}
|
||||
|
||||
std::unique_ptr<GameScriptMeshInfo> GameScript::GetMeshByName(std::string const & name)
|
||||
{
|
||||
return GetTByName<GameScriptMeshInfo, MESH_INFO &>("Mesh", name, m_meshesMapName);
|
||||
return GetTByName<GameScriptMeshInfo, MESH_INFO &>("MeshInfo", name, m_meshesMapName);
|
||||
}
|
||||
|
||||
std::unique_ptr<GameScriptCameraInfo> GameScript::GetCameraByName(std::string const & name)
|
||||
{
|
||||
return GetTByName<GameScriptCameraInfo, LEVEL_CAMERA_INFO &>("Camera", name, m_camerasMapName);
|
||||
return GetTByName<GameScriptCameraInfo, LEVEL_CAMERA_INFO &>("CameraInfo", name, m_camerasMapName);
|
||||
}
|
||||
|
||||
std::unique_ptr<GameScriptSinkInfo> GameScript::GetSinkByName(std::string const & name)
|
||||
{
|
||||
return GetTByName<GameScriptSinkInfo, SINK_INFO &>("Sink", name, m_sinksMapName);
|
||||
return GetTByName<GameScriptSinkInfo, SINK_INFO &>("SinkInfo", name, m_sinksMapName);
|
||||
}
|
||||
|
||||
std::unique_ptr<GameScriptAIObject> GameScript::GetAIObjectByName(std::string const & name)
|
||||
{
|
||||
return GetTByName<GameScriptAIObject, AI_OBJECT &>("AIObject", name, m_aiObjectsMapName);
|
||||
}
|
||||
|
||||
std::unique_ptr<GameScriptSoundSourceInfo> GameScript::GetSoundSourceByName(std::string const & name)
|
||||
{
|
||||
return GetTByName<GameScriptSoundSourceInfo, SOUND_SOURCE_INFO &>("SoundSourceInfo", name, m_soundSourcesMapName);
|
||||
}
|
||||
|
||||
void GameScript::PlayAudioTrack(std::string const & trackName, bool looped)
|
||||
|
|
|
@ -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<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::vector<LuaFunction*> 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();
|
||||
|
||||
|
||||
|
@ -86,6 +101,8 @@ public:
|
|||
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>
|
||||
|
|
163
TR5Main/Scripting/GameScriptAIObject.cpp
Normal file
163
TR5Main/Scripting/GameScriptAIObject.cpp
Normal file
|
@ -0,0 +1,163 @@
|
|||
#pragma once
|
||||
#include "framework.h"
|
||||
#include "GameScriptAIObject.h"
|
||||
#include "GameScriptPosition.h"
|
||||
#include <sol.hpp>
|
||||
/***
|
||||
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<GameScriptAIObject>(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;
|
||||
}
|
||||
|
47
TR5Main/Scripting/GameScriptAIObject.h
Normal file
47
TR5Main/Scripting/GameScriptAIObject.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
#pragma once
|
||||
|
||||
#include "GameScriptNamedBase.h"
|
||||
#include "level.h"
|
||||
|
||||
namespace sol {
|
||||
class state;
|
||||
}
|
||||
class GameScriptPosition;
|
||||
|
||||
class GameScriptAIObject : public GameScriptNamedBase<GameScriptAIObject, AI_OBJECT&>
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
103
TR5Main/Scripting/GameScriptSoundSourceInfo.cpp
Normal file
103
TR5Main/Scripting/GameScriptSoundSourceInfo.cpp
Normal file
|
@ -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<GameScriptSoundSourceInfo>(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;
|
||||
}
|
33
TR5Main/Scripting/GameScriptSoundSourceInfo.h
Normal file
33
TR5Main/Scripting/GameScriptSoundSourceInfo.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include "GameScriptNamedBase.h"
|
||||
#include "phd_global.h"
|
||||
|
||||
namespace sol {
|
||||
class state;
|
||||
}
|
||||
class GameScriptPosition;
|
||||
|
||||
class GameScriptSoundSourceInfo : public GameScriptNamedBase<GameScriptSoundSourceInfo, SOUND_SOURCE_INFO &>
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
|
@ -170,6 +170,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\"</Command>
|
|||
<ClInclude Include="Game\prng.h" />
|
||||
<ClInclude Include="Game\puzzles_keys.h" />
|
||||
<ClInclude Include="Game\room.h" />
|
||||
<ClInclude Include="Scripting\GameScriptAIObject.h" />
|
||||
<ClInclude Include="Scripting\GameScriptCameraInfo.h" />
|
||||
<ClInclude Include="Scripting\GameScriptColor.h" />
|
||||
<ClInclude Include="Scripting\GameScriptItemInfo.h" />
|
||||
|
@ -392,6 +393,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\"</Command>
|
|||
<ClInclude Include="Scripting\GameScriptPosition.h" />
|
||||
<ClInclude Include="Scripting\GameScriptRotation.h" />
|
||||
<ClInclude Include="Scripting\GameScriptSinkInfo.h" />
|
||||
<ClInclude Include="Scripting\GameScriptSoundSourceInfo.h" />
|
||||
<ClInclude Include="Scripting\LanguageScript.h" />
|
||||
<ClInclude Include="Renderer\Renderer11.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
|
@ -498,6 +500,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\"</Command>
|
|||
<ClCompile Include="Game\pickup\pickup_weapon.cpp" />
|
||||
<ClCompile Include="Game\prng.cpp" />
|
||||
<ClCompile Include="Game\puzzles_keys.cpp" />
|
||||
<ClCompile Include="Scripting\GameScriptAIObject.cpp" />
|
||||
<ClCompile Include="Scripting\GameScriptCameraInfo.cpp" />
|
||||
<ClCompile Include="Scripting\GameScriptColor.cpp" />
|
||||
<ClCompile Include="Scripting\GameScriptItemInfo.cpp" />
|
||||
|
@ -688,6 +691,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\"</Command>
|
|||
<ClCompile Include="Scripting\GameScriptPosition.cpp" />
|
||||
<ClCompile Include="Scripting\GameScriptRotation.cpp" />
|
||||
<ClCompile Include="Scripting\GameScriptSinkInfo.cpp" />
|
||||
<ClCompile Include="Scripting\GameScriptSoundSourceInfo.cpp" />
|
||||
<ClCompile Include="Scripting\LanguageScript.cpp" />
|
||||
<ClCompile Include="Objects\TR4\Entity\tr4_demigod.cpp" />
|
||||
<ClCompile Include="Objects\TR4\Entity\tr4_guide.cpp" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue