mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-06 19:01:06 +03:00
Add error checking to GameScriptItemInfo::Init and added room range info in GameScriptItemInfo::SetRoom.
This commit is contained in:
parent
52757896d6
commit
864308335b
1 changed files with 14 additions and 2 deletions
|
@ -277,6 +277,17 @@ the WadTool animation editor.
|
|||
|
||||
void GameScriptItemInfo::Init()
|
||||
{
|
||||
bool cond = IsPointInRoom(m_item->pos, m_item->roomNumber);
|
||||
std::string err{ "Position of item \"{}\" does not match its room ID." };
|
||||
if (!ScriptAssertF(cond, err, m_item->luaName))
|
||||
{
|
||||
ScriptWarn("Resetting to the center of the room.");
|
||||
PHD_3DPOS center = GetRoomCenter(m_item->roomNumber);
|
||||
// reset position but not rotation
|
||||
m_item->pos.xPos = center.xPos;
|
||||
m_item->pos.yPos = center.yPos;
|
||||
m_item->pos.zPos = center.zPos;
|
||||
}
|
||||
InitialiseItem(m_num);
|
||||
m_initialised = true;
|
||||
}
|
||||
|
@ -501,9 +512,10 @@ short GameScriptItemInfo::GetRoom() const
|
|||
|
||||
void GameScriptItemInfo::SetRoom(short room)
|
||||
{
|
||||
if (room < 0 || static_cast<size_t>(room) >= g_Level.Rooms.size())
|
||||
const size_t nRooms = g_Level.Rooms.size();
|
||||
if (room < 0 || static_cast<size_t>(room) >= nRooms)
|
||||
{
|
||||
ScriptAssert(false, std::string{ "Invalid room number: " } + std::to_string(room));
|
||||
ScriptAssertF(false, "Invalid room number: {}. Value must be in range [0, {})", room, nRooms);
|
||||
TENLog("Room number will not be set", LogLevel::Warning, LogConfig::All);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue