diff --git a/TR5Main/Game/control.cpp b/TR5Main/Game/control.cpp index ea60ecd95..9432ddd8c 100644 --- a/TR5Main/Game/control.cpp +++ b/TR5Main/Game/control.cpp @@ -814,8 +814,10 @@ GAME_STATUS DoLevel(int index, std::string ambient, bool loadFromSavegame) // Run the level script GameScriptLevel* level = g_GameFlow->Levels[index]; std::string err; + g_GameScript->ExecuteScript(level->ScriptFileName, err); g_GameScript->InitCallbacks(); + // Restore the game? if (loadFromSavegame) { @@ -929,6 +931,43 @@ void TestTriggers(short *data, int heavy, int HeavyFlags) short cameraTimer = 0; int spotCamIndex = 0; + // Test trigger volumes if any + if (heavy == 0) + { + ROOM_INFO* room = &g_Level.Rooms[LaraItem->roomNumber]; + for (int i = 0; i < room->triggerVolumes.size(); i++) + { + TRIGGER_VOLUME* volume = &room->triggerVolumes[i]; + /*ANIM_FRAME* frame = GetBestFrame(LaraItem); + + Vector3 boxMin = Vector3(frame->boundingBox.X1, frame->boundingBox.Y1, frame->boundingBox.Z1); + Vector3 boxMax = Vector3(frame->boundingBox.X2, frame->boundingBox.Y2, frame->boundingBox.Z2); + Vector3 centre = (boxMin + boxMax) / 2.0f; + Vector3 extens = boxMax - centre; + BoundingBox laraBox = BoundingBox((Vector3)(centre + Vector3(room->x, room->y, room->z)), extens);*/ + + /*BoundingOrientedBox volumeBox = BoundingOrientedBox( + (Vector3)(volume->position + Vector3(room->x, room->y, room->z)), + (Vector3)(volume->scale / 2.0f), + volume->rotation);*/ + + if (volume->box.Contains(Vector3(LaraItem->pos.xPos, LaraItem->pos.yPos, LaraItem->pos.zPos)) == ContainmentType::CONTAINS) + { + // Execute trigger + //g_GameScript->ExecuteScript(); + Lara.gunType = WEAPON_UZI; + } + else + Lara.gunType = WEAPON_NONE; + + /*if (volumeBox.Intersects(laraBox)) + { + // Execute trigger + g_GameScript->ExecuteScript(); + }*/ + } + } + HeavyTriggered = false; if (!heavy) diff --git a/TR5Main/Game/room.h b/TR5Main/Game/room.h index 39fd1ccd9..a56d0fd79 100644 --- a/TR5Main/Game/room.h +++ b/TR5Main/Game/room.h @@ -82,6 +82,28 @@ enum RoomEnumFlag ENV_FLAG_UNKNOWN3 = 0x0400 }; +enum TriggerStatus +{ + TS_OUTSIDE = 0, + TS_ENTERING = 1, + TS_INSIDE = 2, + TS_LEAVING = 3 +}; + +struct TRIGGER_VOLUME +{ + Vector3 position; + Quaternion rotation; + Vector3 scale; + int activators; + std::string onEnter; + std::string onInside; + std::string onLeave; + bool oneShot; + TriggerStatus status; + BoundingOrientedBox box; +}; + struct ROOM_INFO { int x; @@ -108,6 +130,7 @@ struct ROOM_INFO short itemNumber; short fxNumber; bool boundActive; + std::vector triggerVolumes; }; struct ANIM_STRUCT diff --git a/TR5Main/Scripting/GameScriptItemInfo.cpp b/TR5Main/Scripting/GameScriptItemInfo.cpp index 813932fff..9d08895a4 100644 --- a/TR5Main/Scripting/GameScriptItemInfo.cpp +++ b/TR5Main/Scripting/GameScriptItemInfo.cpp @@ -329,5 +329,4 @@ void GameScriptItemInfo::DisableItem() m_item->status = ITEM_DEACTIVATED; } } -} - +} \ No newline at end of file diff --git a/TR5Main/Specific/level.cpp b/TR5Main/Specific/level.cpp index 563c08a6b..3a85367b0 100644 --- a/TR5Main/Specific/level.cpp +++ b/TR5Main/Specific/level.cpp @@ -682,6 +682,43 @@ void ReadRooms() room.mesh.push_back(mesh); } + int numTriggerVolumes = ReadInt32(); + for (int j = 0; j < numTriggerVolumes; j++) + { + TRIGGER_VOLUME volume; + + volume.position = Vector3(ReadFloat(), ReadFloat(), ReadFloat()); + volume.rotation = Quaternion(ReadFloat(), ReadFloat(), ReadFloat(), ReadFloat()); + volume.scale = Vector3(ReadFloat(), ReadFloat(), ReadFloat()); + volume.activators = ReadInt32(); + + byte numBytes = ReadInt8(); + char* buffer[255]; + ZeroMemory(buffer, 256); + ReadBytes(buffer, numBytes); + volume.onEnter = std::string((const char*)buffer); + + numBytes = ReadInt8(); + ZeroMemory(buffer, 256); + ReadBytes(buffer, numBytes); + volume.onInside = std::string((const char*)buffer); + + numBytes = ReadInt8(); + ZeroMemory(buffer, 256); + ReadBytes(buffer, numBytes); + volume.onLeave = std::string((const char*)buffer); + + volume.oneShot = ReadInt8(); + volume.status = TS_OUTSIDE; + + volume.box = BoundingOrientedBox( + (Vector3)(volume.position + Vector3(room.x, room.minfloor, room.z)), + (Vector3)(volume.scale / 2.0f), + volume.rotation); + + room.triggerVolumes.push_back(volume); + } + room.flippedRoom = ReadInt32(); room.flags = ReadInt32(); room.meshEffect = ReadInt32();