From d0da243f736a9c7fb68ecd310d532f23430a00ba Mon Sep 17 00:00:00 2001 From: MontyTRC89 Date: Sat, 28 Aug 2021 06:37:22 +0200 Subject: [PATCH] Refactored switches --- TR5Main/Game/Lara/lara_one_gun.cpp | 3 + TR5Main/Game/control.cpp | 7 +- TR5Main/Game/door.cpp | 12 +- TR5Main/Game/pickup.h | 4 + TR5Main/Game/puzzles_keys.cpp | 3 + TR5Main/Game/savegame.cpp | 9 +- TR5Main/Game/switch.cpp | 779 +----------------- TR5Main/Game/switch.h | 17 - TR5Main/Objects/Effects/tr4_bubbles.cpp | 2 +- TR5Main/Objects/Effects/tr4_locusts.cpp | 2 +- TR5Main/Objects/Effects/tr4_locusts.h | 2 +- .../Objects/Generic/Switches/cog_switch.cpp | 2 +- TR5Main/Objects/Generic/Switches/cog_switch.h | 2 +- .../Generic/Switches/crowbar_switch.cpp | 5 +- .../Objects/Generic/Switches/crowbar_switch.h | 2 +- .../Generic/Switches/fullblock_switch.cpp | 105 +++ .../Generic/Switches/fullblock_switch.h | 15 + .../Generic/Switches/generic_switch.cpp | 111 ++- .../Objects/Generic/Switches/generic_switch.h | 8 +- .../Objects/Generic/Switches/jump_switch.cpp | 2 +- .../Objects/Generic/Switches/jump_switch.h | 2 +- .../Generic/Switches/pulley_switch.cpp | 103 +++ .../Objects/Generic/Switches/pulley_switch.h | 10 + .../Objects/Generic/Switches/rail_switch.cpp | 2 +- .../Objects/Generic/Switches/rail_switch.h | 2 +- .../Objects/Generic/Switches/turn_switch.cpp | 252 ++++++ .../Objects/Generic/Switches/turn_switch.h | 10 + .../Generic/Switches/underwater_switch.cpp | 2 +- .../Generic/Switches/underwater_switch.h | 2 +- TR5Main/Objects/Generic/generic_objects.cpp | 41 +- .../Objects/TR4/Entity/tr4_littlebeetle.cpp | 2 +- TR5Main/Objects/TR4/Entity/tr4_littlebeetle.h | 2 +- TR5Main/Objects/TR4/Entity/tr4_mutant.cpp | 4 +- TR5Main/Objects/TR4/Entity/tr4_mutant.h | 2 +- TR5Main/Objects/TR4/Entity/tr4_skeleton.cpp | 2 +- TR5Main/Objects/TR4/Entity/tr4_skeleton.h | 2 +- .../Objects/TR4/Object/tr4_element_puzzle.cpp | 3 + TR5Main/Objects/TR4/Object/tr4_scales.cpp | 3 + TR5Main/Objects/TR4/tr4_objects.cpp | 20 +- .../TR5/Switch/tr5_crowdove_switch.cpp | 118 +++ .../Objects/TR5/Switch/tr5_crowdove_switch.h | 11 + TR5Main/Objects/TR5/Switch/tr5_raisingcog.cpp | 6 +- TR5Main/Objects/TR5/Trap/tr5_explosion.cpp | 3 + TR5Main/Objects/TR5/tr5_objects.cpp | 15 + TR5Main/Renderer/Renderer11Draw.cpp | 8 +- TR5Main/Specific/setup.cpp | 66 +- TR5Main/TR5Main.vcxproj | 8 + TR5Main/TR5Main.vcxproj.filters | 24 + 48 files changed, 910 insertions(+), 907 deletions(-) create mode 100644 TR5Main/Objects/Generic/Switches/fullblock_switch.cpp create mode 100644 TR5Main/Objects/Generic/Switches/fullblock_switch.h create mode 100644 TR5Main/Objects/Generic/Switches/pulley_switch.cpp create mode 100644 TR5Main/Objects/Generic/Switches/pulley_switch.h create mode 100644 TR5Main/Objects/Generic/Switches/turn_switch.cpp create mode 100644 TR5Main/Objects/Generic/Switches/turn_switch.h create mode 100644 TR5Main/Objects/TR5/Switch/tr5_crowdove_switch.cpp create mode 100644 TR5Main/Objects/TR5/Switch/tr5_crowdove_switch.h diff --git a/TR5Main/Game/Lara/lara_one_gun.cpp b/TR5Main/Game/Lara/lara_one_gun.cpp index 8a8658008..642ba3b95 100644 --- a/TR5Main/Game/Lara/lara_one_gun.cpp +++ b/TR5Main/Game/Lara/lara_one_gun.cpp @@ -25,6 +25,9 @@ #include "savegame.h" #include "sound.h" #include "bubble.h" +#include "generic_switch.h" + +using namespace TEN::Entities::Switches; extern GameFlow* g_GameFlow; diff --git a/TR5Main/Game/control.cpp b/TR5Main/Game/control.cpp index e6fcdf36d..401c43d2b 100644 --- a/TR5Main/Game/control.cpp +++ b/TR5Main/Game/control.cpp @@ -51,6 +51,9 @@ #include #include "prng.h" #include +#include "generic_switch.h" + +using namespace TEN::Entities::Switches; using std::vector; using std::unordered_map; @@ -569,8 +572,8 @@ GAME_STATUS ControlPhase(int numFrames, int demoMode) ten::Effects::Drip::UpdateDrips(); UpdateExplosionParticles(); UpdateShockwaves(); - ten::entities::tr4::UpdateScarabs(); - ten::entities::tr4::UpdateLocusts(); + TEN::Entities::TR4::UpdateScarabs(); + TEN::Entities::TR4::UpdateLocusts(); //Legacy_UpdateLightning(); AnimateWaterfalls(); diff --git a/TR5Main/Game/door.cpp b/TR5Main/Game/door.cpp index 8e91640d3..582705b6f 100644 --- a/TR5Main/Game/door.cpp +++ b/TR5Main/Game/door.cpp @@ -18,6 +18,11 @@ #include "sound.h" #include "trmath.h" #include "cog_switch.h" +#include "generic_switch.h" +#include "pickup.h" +#include "fullblock_switch.h" + +using namespace TEN::Entities::Switches; PHD_VECTOR DoubleDoorPos(0, 0, 220); PHD_VECTOR PullDoorPos(-201, 0, 322); @@ -45,11 +50,6 @@ ITEM_INFO* ClosedDoors[32]; byte LiftDoor; int DontUnlockBox; -extern byte SequenceUsed[6]; -extern byte SequenceResults[3][3][3]; -extern byte Sequences[3]; -extern byte CurrentSequence; -extern PHD_VECTOR OldPickupPos; #ifndef NEW_INV extern Inventory g_Inventory; #endif @@ -458,7 +458,7 @@ void DoorControl(short itemNumber) { BOUNDING_BOX* bounds = GetBoundsAccurate(item); --item->itemFlags[0]; - item->pos.yPos -= ten::entities::switches::COG_DOOR_SPEED; + item->pos.yPos -= TEN::Entities::Switches::COG_DOOR_SPEED; int y = bounds->Y1 + item->itemFlags[2] - STEP_SIZE; if (item->pos.yPos < y) { diff --git a/TR5Main/Game/pickup.h b/TR5Main/Game/pickup.h index e0a44da86..d594d8eb3 100644 --- a/TR5Main/Game/pickup.h +++ b/TR5Main/Game/pickup.h @@ -4,6 +4,10 @@ enum GAME_OBJECT_ID : short; +extern int NumRPickups; +extern short RPickups[16]; +extern PHD_VECTOR OldPickupPos; + void InitialisePickup(short itemNumber); void PickedUpObject(GAME_OBJECT_ID objectNumber, int count); void RemoveObjectFromInventory(GAME_OBJECT_ID objectNumber, int count); diff --git a/TR5Main/Game/puzzles_keys.cpp b/TR5Main/Game/puzzles_keys.cpp index f92b4d259..315277194 100644 --- a/TR5Main/Game/puzzles_keys.cpp +++ b/TR5Main/Game/puzzles_keys.cpp @@ -11,6 +11,9 @@ #include "pickup.h" #include "draw.h" #include "puzzles_keys.h" +#include "generic_switch.h" + +using namespace TEN::Entities::Switches; enum PuzzleType { PUZZLETYPE_NORMAL, diff --git a/TR5Main/Game/savegame.cpp b/TR5Main/Game/savegame.cpp index eb02d960a..67eecac3c 100644 --- a/TR5Main/Game/savegame.cpp +++ b/TR5Main/Game/savegame.cpp @@ -16,6 +16,11 @@ #include "tr5_rats_emitter.h" #include "tr5_bats_emitter.h" #include "tr5_spider_emitter.h" +#include "generic_switch.h" +#include "fullblock_switch.h" + +using namespace TEN::Entities::Switches; + using std::string; using std::vector; FileStream* SaveGame::m_stream; @@ -68,10 +73,6 @@ std::unique_ptr SaveGame::m_chunkWeaponItem; SAVEGAME_INFO Savegame; //extern vector g_AudioTracks; -extern byte SequenceUsed[6]; -extern byte SequenceResults[3][3][3]; -extern byte Sequences[3]; -extern byte CurrentSequence; void SaveGame::saveItems() { diff --git a/TR5Main/Game/switch.cpp b/TR5Main/Game/switch.cpp index c54f6acd0..64378630c 100644 --- a/TR5Main/Game/switch.cpp +++ b/TR5Main/Game/switch.cpp @@ -18,50 +18,7 @@ #include "input.h" #include "sound.h" -byte SequenceUsed[6]; -byte SequenceResults[3][3][3]; -byte Sequences[3]; -byte CurrentSequence; -int PulleyItemNumber = NO_ITEM; - -extern PHD_VECTOR OldPickupPos; -#ifndef NEW_INV -extern Inventory g_Inventory; -#endif - -OBJECT_COLLISION_BOUNDS Switch2Bounds = -{ - 0xFC00, 0x0400, 0xFC00, 0x0400, 0xFC00, 0x0200, 0xC720, 0x38E0, 0xC720, 0x38E0, - 0xC720, 0x38E0 -}; -PHD_VECTOR Switch2Position = { 0, 0, 108 }; -OBJECT_COLLISION_BOUNDS TurnSwitchBoundsA = // offset 0xA14D8 -{ - 0x0200, 0x0380, 0x0000, 0x0000, 0xFE00, 0x0000, 0xF8E4, 0x071C, 0xEAAC, 0x1554, - 0xF8E4, 0x071C -}; -PHD_VECTOR TurnSwitchPos = { 650, 0, 138 }; // offset 0xA14F0 -OBJECT_COLLISION_BOUNDS TurnSwitchBoundsC = // offset 0xA14FC -{ - 0x0200, 0x0380, 0x0000, 0x0000, 0x0000, 0x0200, 0xF8E4, 0x071C, 0xEAAC, 0x1554, - 0xF8E4, 0x071C -}; -PHD_VECTOR TurnSwitchPosA = { 650, 0, -138 }; // offset 0xA1514 - -OBJECT_COLLISION_BOUNDS FullBlockSwitchBounds = // offset 0xA15F8 -{ - 0xFE80, 0x0180, 0x0000, 0x0100, 0x0000, 0x0200, 0xF8E4, 0x071C, 0xEAAC, 0x1554, - 0xF8E4, 0x071C -}; -PHD_VECTOR FullBlockSwitchPos = { 0, 0, 0 }; // offset 0xA1610 -OBJECT_COLLISION_BOUNDS PulleyBounds = // offset 0xA161C -{ - 0xFF00, 0x0100, 0x0000, 0x0000, 0xFE00, 0x0200, 0xF8E4, 0x071C, 0xEAAC, 0x1554, - 0xF8E4, 0x071C -}; -PHD_VECTOR PulleyPos = { 0, 0, -148 }; // offset 0xA1634 -PHD_VECTOR CrowDovePos = { 0, 0, -400 }; // offset 0xA1640 - +// NOTE: we need to decompile/inspect if these functions are still needed void ProcessExplodingSwitchType8(ITEM_INFO* item) { @@ -75,721 +32,6 @@ void ProcessExplodingSwitchType8(ITEM_INFO* item) item->meshBits |= 1 << ((Objects[item->objectNumber].nmeshes & 0xFF) - 2); } -void CrowDoveSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) -{ - ITEM_INFO* item = &g_Level.Items[itemNum]; - - if (item->flags & 0x100 - || !(item->meshBits & 4) - || (!(TrInput & IN_ACTION) - || Lara.gunStatus - || l->currentAnimState != LS_STOP - || l->animNumber != LA_STAND_IDLE - || l->gravityStatus) - && (!Lara.isMoving || Lara.generalPtr != (void*)itemNum)) - { - if (l->currentAnimState != LS_DOVESWITCH) - ObjectCollision(itemNum, l, coll); - } - else - { - int oldYrot = item->pos.yRot; - item->pos.yRot = l->pos.yRot; - if (TestLaraPosition(&PulleyBounds, item, l)) - { - if (MoveLaraPosition(&CrowDovePos, item, l)) - { - l->animNumber = LA_DOVESWITCH_TURN; - l->currentAnimState = LS_DOVESWITCH; - l->frameNumber = g_Level.Anims[l->animNumber].frameBase; - - AddActiveItem(itemNum); - - item->itemFlags[0] = 0; // This enables the switch again (in TR5 this switch was always triggered by heavy triggers) - item->status = ITEM_ACTIVE; - item->pos.yRot = oldYrot; - Lara.isMoving = false; - Lara.headYrot = 0; - Lara.headXrot = 0; - Lara.torsoYrot = 0; - Lara.torsoXrot = 0; - Lara.gunStatus = LG_HANDS_BUSY; - Lara.generalPtr = (void*)item; - } - else - { - Lara.generalPtr = (void*)itemNum; - } - item->pos.yRot = oldYrot; - } - else - { - if (Lara.isMoving && Lara.generalPtr == (void*)itemNum) - { - Lara.isMoving = false; - Lara.gunStatus = LG_NO_ARMS; - } - item->pos.yRot = oldYrot; - } - } -} - -void CrowDoveSwitchControl(short itemNumber) -{ - ITEM_INFO* item = &g_Level.Items[itemNumber]; - - if ((item->meshBits & 2)) - { - ExplodeItemNode(item, 1, 0, 0x100); - SoundEffect(SFX_TR5_RAVENSWITCH_EXP, &item->pos, 0); - item->meshBits = 5; - RemoveActiveItem(itemNumber); - item->itemFlags[0] = 1; // I use this for not making it activable again by trigger - } - else if (!item->itemFlags[0]) - { - if (item->currentAnimState == 0) - item->goalAnimState = 1; - - AnimateItem(item); - - if (item->currentAnimState == 0) - item->pos.yRot += ANGLE(90); - } -} - -void FullBlockSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) -{ - ITEM_INFO* item = &g_Level.Items[itemNum]; - - if ((!(TrInput & IN_ACTION) - || item->status - || item->flags & 0x100 - || CurrentSequence >= 3u - || Lara.gunStatus - || l->currentAnimState != LS_STOP - || l->animNumber != LA_STAND_IDLE) - && (!Lara.isMoving || Lara.generalPtr != (void*)itemNum)) - { - ObjectCollision(itemNum, l, coll); - return; - } - - if (TestLaraPosition(&FullBlockSwitchBounds, item, l)) - { - if (MoveLaraPosition(&FullBlockSwitchPos, item, l)) - { - if (item->currentAnimState == 1) - { - l->currentAnimState = LS_SWITCH_DOWN; - l->animNumber = LA_BUTTON_GIANT_PUSH; - item->goalAnimState = 0; - } - l->goalAnimState = LS_STOP; - l->frameNumber = g_Level.Anims[l->animNumber].frameBase; - item->status = ITEM_ACTIVE; - - AddActiveItem(itemNum); - AnimateItem(item); - - Lara.isMoving = false; - Lara.headYrot = 0; - Lara.headXrot = 0; - Lara.torsoYrot = 0; - Lara.torsoXrot = 0; - Lara.gunStatus = LG_HANDS_BUSY; - } - else - { - Lara.generalPtr = (void*)itemNum; - } - } - else if (Lara.isMoving && Lara.generalPtr == (void*)itemNum) - { - Lara.isMoving = false; - Lara.gunStatus = LG_NO_ARMS; - } -} - -void FullBlockSwitchControl(short itemNumber) -{ - ITEM_INFO* item = &g_Level.Items[itemNumber]; - - if (item->animNumber != Objects[item->objectNumber].animIndex + 2 - || CurrentSequence >= 3u - || item->itemFlags[0]) - { - if (CurrentSequence >= 4u) - { - item->itemFlags[0] = 0; - item->goalAnimState = 1; - item->status = ITEM_NOT_ACTIVE; - if (++CurrentSequence >= 7u) - CurrentSequence = 0; - } - } - else - { - item->itemFlags[0] = 1; - Sequences[CurrentSequence++] = item->triggerFlags; - } - - AnimateItem(item); -} - -void CrowbarSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) -{ - int doSwitch = 0; - ITEM_INFO* item = &g_Level.Items[itemNum]; - - if ((!(TrInput & IN_ACTION) && -#ifdef NEW_INV - GLOBAL_inventoryitemchosen != ID_CROWBAR_ITEM -#else - g_Inventory.GetSelectedObject() != ID_CROWBAR_ITEM -#endif - || l->currentAnimState != LS_STOP - || l->animNumber != LA_STAND_IDLE - || Lara.gunStatus - || item->itemFlags[0]) - && (!Lara.isMoving || Lara.generalPtr != (void*)itemNum)) - { - ObjectCollision(itemNum, l, coll); - return; - } - - if (item->currentAnimState) - { - if (item->currentAnimState != 1) - { - ObjectCollision(itemNum, l, coll); - return; - } - - l->pos.yRot ^= (short)ANGLE(180); - if (TestLaraPosition(&CrowbarBounds2, item, l)) - { - if (Lara.isMoving || -#ifdef NEW_INV - GLOBAL_inventoryitemchosen == ID_CROWBAR_ITEM -#else - g_Inventory.GetSelectedObject() == ID_CROWBAR_ITEM -#endif - ) - { - if (MoveLaraPosition(&CrowbarPos2, item, l)) - { - l->animNumber = LA_CROWBAR_USE_ON_FLOOR; - doSwitch = 1; - l->frameNumber = g_Level.Anims[l->animNumber].frameBase; - item->goalAnimState = 0; - } - else - { - Lara.generalPtr = (void*)itemNum; - } -#ifdef NEW_INV - GLOBAL_inventoryitemchosen = NO_ITEM; -#else - g_Inventory.SetSelectedObject(NO_ITEM); -#endif - } - else - { - doSwitch = -1; - } - } - else if (Lara.isMoving && Lara.generalPtr == (void*)itemNum) - { - Lara.isMoving = false; - Lara.gunStatus = LG_NO_ARMS; - } - l->pos.yRot ^= (short)ANGLE(180); - } - else - { - if (!TestLaraPosition(&CrowbarBounds, item, l)) - { - if (Lara.isMoving && Lara.generalPtr == (void*)itemNum) - { - Lara.isMoving = false; - Lara.gunStatus = LG_NO_ARMS; - } - ObjectCollision(itemNum, l, coll); - return; - } - - if (!(Lara.isMoving && -#ifdef NEW_INV - GLOBAL_inventoryitemchosen != ID_CROWBAR_ITEM) -#else - g_Inventory.GetSelectedObject() != ID_CROWBAR_ITEM) -#endif - ) - { - if (Lara.Crowbar) -#ifdef NEW_INV - GLOBAL_inventoryitemchosen = ID_CROWBAR_ITEM; -#else - g_Inventory.SetEnterObject(ID_CROWBAR_ITEM); -#endif - else - { - if (OldPickupPos.x != l->pos.xPos || OldPickupPos.y != l->pos.yPos || OldPickupPos.z != l->pos.zPos) - { - OldPickupPos.x = l->pos.xPos; - OldPickupPos.y = l->pos.yPos; - OldPickupPos.z = l->pos.zPos; - SayNo(); - } - } - return; - } - - if (MoveLaraPosition(&CrowbarPos, item, l)) - { - l->animNumber = LA_CROWBAR_USE_ON_FLOOR; - doSwitch = 1; - l->frameNumber = g_Level.Anims[l->animNumber].frameBase; - item->goalAnimState = 1; - } - else - { - Lara.generalPtr = (void*)itemNum; - } -#ifdef NEW_INV - GLOBAL_inventoryitemchosen = NO_ITEM; -#else - g_Inventory.SetSelectedObject(NO_ITEM); -#endif - } - - if (!doSwitch) - { - ObjectCollision(itemNum, l, coll); - return; - } - - if (doSwitch != -1) - { - l->goalAnimState = LS_SWITCH_DOWN; - l->currentAnimState = LS_SWITCH_DOWN; - Lara.isMoving = false; - Lara.headYrot = 0; - Lara.headXrot = 0; - Lara.torsoYrot = 0; - Lara.torsoXrot = 0; - Lara.gunStatus = LG_HANDS_BUSY; - item->status = ITEM_ACTIVE; - - AddActiveItem(itemNum); - AnimateItem(item); - - return; - } - - if (Lara.Crowbar) -#ifdef NEW_INV - GLOBAL_enterinventory = ID_CROWBAR_ITEM; -#else - g_Inventory.SetEnterObject(ID_CROWBAR_ITEM); -#endif - else - { - if (OldPickupPos.x != l->pos.xPos || OldPickupPos.y != l->pos.yPos || OldPickupPos.z != l->pos.zPos) - { - OldPickupPos.x = l->pos.xPos; - OldPickupPos.y = l->pos.yPos; - OldPickupPos.z = l->pos.zPos; - SayNo(); - } - } -} - -void TurnSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) -{ - ITEM_INFO* item = &g_Level.Items[itemNum]; - int flag = 0; - - if (item->currentAnimState - && TrInput & IN_ACTION - && l->currentAnimState == LS_STOP - && l->animNumber == LA_STAND_IDLE - && !l->gravityStatus - && Lara.gunStatus == LG_NO_ARMS - || Lara.isMoving && Lara.generalPtr == (void*)itemNum) - { - short ItemNos[8]; - if (TestLaraPosition(&TurnSwitchBoundsA, item, l)) - { - if (MoveLaraPosition(&TurnSwitchPosA, item, l)) - { - l->animNumber = LA_TURNSWITCH_GRAB_COUNTER_CLOCKWISE; - l->frameNumber = g_Level.Anims[LA_TURNSWITCH_GRAB_COUNTER_CLOCKWISE].frameBase; - item->animNumber = Objects[item->objectNumber].animIndex + 4; - item->frameNumber = g_Level.Anims[item->animNumber].frameBase; - item->itemFlags[0] = 1; - ForcedFixedCamera.x = item->pos.xPos - 1024 * phd_sin(item->pos.yRot); - ForcedFixedCamera.z = item->pos.zPos - 1024 * phd_cos(item->pos.yRot); - Lara.isMoving = 0; - Lara.headYrot = 0; - Lara.headXrot = 0; - Lara.torsoYrot = 0; - Lara.torsoXrot = 0; - Lara.gunStatus = LG_HANDS_BUSY; - l->currentAnimState = LA_REACH; - - UseForcedFixedCamera = true; - ForcedFixedCamera.y = item->pos.yPos - 2048; - ForcedFixedCamera.roomNumber = item->roomNumber; - - AddActiveItem(itemNum); - - item->status = ITEM_ACTIVE; - item->itemFlags[1] = 0; - - if (GetSwitchTrigger(item, ItemNos, 0)) - { - if (!TriggerActive(&g_Level.Items[ItemNos[0]])) - { - g_Level.Items[ItemNos[0]].animNumber = Objects[g_Level.Items[ItemNos[0]].objectNumber].animIndex; - g_Level.Items[ItemNos[0]].frameNumber = g_Level.Anims[g_Level.Items[ItemNos[0]].animNumber].frameBase; - } - } - return; - } - Lara.generalPtr = (void*)itemNum; - } - else - { - l->pos.yRot ^= (short)ANGLE(180); - if (TestLaraPosition(&TurnSwitchBoundsC, item, l)) - { - if (MoveLaraPosition(&TurnSwitchPos, item, l)) - { - l->animNumber = 319; - flag = 1; - l->frameNumber = g_Level.Anims[319].frameBase; - item->itemFlags[0] = 2; - ForcedFixedCamera.x = item->pos.xPos + 1024 * phd_sin(item->pos.yRot); - ForcedFixedCamera.z = item->pos.zPos + 1024 * phd_cos(item->pos.yRot); - } - else - { - Lara.generalPtr = (void*)itemNum; - } - } - else if (Lara.isMoving && Lara.generalPtr == (void*)itemNum) - { - Lara.isMoving = false; - Lara.gunStatus = LG_NO_ARMS; - } - l->pos.yRot ^= (short)ANGLE(180); - if (flag) - { - Lara.isMoving = 0; - Lara.headYrot = 0; - Lara.headXrot = 0; - Lara.torsoYrot = 0; - Lara.torsoXrot = 0; - Lara.gunStatus = LG_HANDS_BUSY; - l->currentAnimState = LA_REACH; - UseForcedFixedCamera = true; - ForcedFixedCamera.y = item->pos.yPos - 2048; - ForcedFixedCamera.roomNumber = item->roomNumber; - AddActiveItem(itemNum); - item->status = ITEM_ACTIVE; - item->itemFlags[1] = 0; - if (GetSwitchTrigger(item, ItemNos, 0)) - { - if (!TriggerActive(&g_Level.Items[ItemNos[0]])) - { - g_Level.Items[ItemNos[0]].animNumber = Objects[g_Level.Items[ItemNos[0]].objectNumber].animIndex + 4; - g_Level.Items[ItemNos[0]].frameNumber = g_Level.Anims[g_Level.Items[ItemNos[0]].animNumber].frameBase; - } - } - return; - } - } - } - - if (coll->enableBaddiePush && TestBoundsCollide(item, l, coll->radius)) - { - GlobalCollisionBounds.X1 = -512; - GlobalCollisionBounds.X2 = 512; - GlobalCollisionBounds.Y1 = -512; - GlobalCollisionBounds.Y2 = 0; - GlobalCollisionBounds.Z1 = -512; - GlobalCollisionBounds.Z2 = 512; - - ItemPushLara(item, l, coll, 0, 2); - - GlobalCollisionBounds.X1 = 256; - GlobalCollisionBounds.X2 = 1024; - GlobalCollisionBounds.Z1 = -128; - GlobalCollisionBounds.Z2 = 128; - - ItemPushLara(item, l, coll, 0, 2); - } -} - -void TurnSwitchControl(short itemNum) -{ - ITEM_INFO* l = LaraItem; - ITEM_INFO* item = &g_Level.Items[itemNum]; - - if (g_Level.Items[itemNum].itemFlags[0] == 2) - { - if (item->animNumber == Objects[ID_TURN_SWITCH].animIndex + 2) - { - item->pos.yRot += ANGLE(90); - if (TrInput & IN_ACTION) - { - l->animNumber = LA_TURNSWITCH_PUSH_CLOCKWISE_START; - l->frameNumber = g_Level.Anims[l->animNumber].frameBase; - item->animNumber = Objects[item->objectNumber].animIndex + 1; - item->frameNumber = g_Level.Anims[item->animNumber].frameBase; - } - } - - if (l->animNumber == LA_TURNSWITCH_PUSH_CLOCKWISE_END && l->frameNumber == g_Level.Anims[l->animNumber].frameEnd && !item->itemFlags[1]) - item->itemFlags[1] = 1; - - if (l->frameNumber >= g_Level.Anims[LA_TURNSWITCH_PUSH_CLOCKWISE_START].frameBase && - l->frameNumber <= g_Level.Anims[LA_TURNSWITCH_PUSH_CLOCKWISE_START].frameBase + 43 - || - l->frameNumber >= g_Level.Anims[LA_TURNSWITCH_PUSH_CLOCKWISE_START].frameBase + 58 && - l->frameNumber <= g_Level.Anims[LA_TURNSWITCH_PUSH_CLOCKWISE_START].frameBase + 115) - { - SoundEffect(SFX_TR4_PUSHABLE_SOUND, &item->pos, 2); - } - } - else - { - if (item->animNumber == Objects[ID_TURN_SWITCH].animIndex + 6) - { - item->pos.yRot -= ANGLE(90); - if (TrInput & IN_ACTION) - { - l->animNumber = LA_TURNSWITCH_PUSH_COUNTER_CLOCKWISE_START; - l->frameNumber = g_Level.Anims[l->animNumber].frameBase; - item->animNumber = Objects[item->objectNumber].animIndex + 5; - item->frameNumber = g_Level.Anims[item->animNumber].frameBase; - } - } - - if (l->animNumber == LA_TURNSWITCH_PUSH_COUNTER_CLOCKWISE_END && l->frameNumber == g_Level.Anims[LA_TURNSWITCH_PUSH_COUNTER_CLOCKWISE_END].frameEnd && - !item->itemFlags[1]) - item->itemFlags[1] = 1; - - if (l->frameNumber >= g_Level.Anims[LA_TURNSWITCH_PUSH_COUNTER_CLOCKWISE_START].frameBase && - l->frameNumber <= g_Level.Anims[LA_TURNSWITCH_PUSH_COUNTER_CLOCKWISE_START].frameBase + 43 - || - l->frameNumber >= g_Level.Anims[LA_TURNSWITCH_PUSH_COUNTER_CLOCKWISE_START].frameBase + 58 && - l->frameNumber <= g_Level.Anims[LA_TURNSWITCH_PUSH_COUNTER_CLOCKWISE_START].frameBase + 115) - { - SoundEffect(SFX_TR4_PUSHABLE_SOUND, &item->pos, 2); - } - } - - AnimateItem(item); - - if (item->itemFlags[1] == 1) - { - l->animNumber = LA_STAND_IDLE; - l->currentAnimState = LS_STOP; - l->frameNumber = g_Level.Anims[l->animNumber].frameBase; - item->animNumber = Objects[item->objectNumber].animIndex; - item->frameNumber = g_Level.Anims[item->animNumber].frameBase; - item->status = ITEM_NOT_ACTIVE; - - RemoveActiveItem(itemNum); - - Lara.gunStatus = LG_NO_ARMS; - UseForcedFixedCamera = 0; - item->itemFlags[1] = 2; - } -} - -void PulleyCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) -{ - ITEM_INFO* item = &g_Level.Items[itemNum]; - - if (item->flags & 0x100 - || (!(TrInput & IN_ACTION) - || Lara.gunStatus - || l->currentAnimState != LS_STOP - || l->animNumber != LA_STAND_IDLE - || item->gravityStatus) - && (!Lara.isMoving - || Lara.generalPtr != (void*)itemNum)) - { - if (l->currentAnimState != LS_PULLEY) - ObjectCollision(itemNum, l, coll); - } - else - { - short oldYrot = item->pos.yRot; - item->pos.yRot = l->pos.yRot; - if (TestLaraPosition(&PulleyBounds, item, l)) - { - if (item->itemFlags[1]) - { - if (OldPickupPos.x != l->pos.xPos || OldPickupPos.y != l->pos.yPos || OldPickupPos.z != l->pos.zPos) - { - OldPickupPos.x = l->pos.xPos; - OldPickupPos.y = l->pos.yPos; - OldPickupPos.z = l->pos.zPos; - SayNo(); - } - } - else if (MoveLaraPosition(&PulleyPos, item, l)) - { - l->animNumber = LA_PULLEY_GRAB; - l->currentAnimState = LS_PULLEY; - l->frameNumber = g_Level.Anims[l->animNumber].frameBase; - - AddActiveItem(itemNum); - - item->pos.yRot = oldYrot; - item->status = ITEM_ACTIVE; - - Lara.isMoving = false; - Lara.headYrot = 0; - Lara.headXrot = 0; - Lara.torsoYrot = 0; - Lara.torsoXrot = 0; - Lara.gunStatus = LG_HANDS_BUSY; - Lara.generalPtr = item; - } - else - { - Lara.generalPtr = (void*)itemNum; - } - item->pos.yRot = oldYrot; - } - else - { - if (Lara.isMoving && Lara.generalPtr == (void*)itemNum) - { - Lara.isMoving = false; - Lara.gunStatus = LG_NO_ARMS; - } - item->pos.yRot = oldYrot; - } - } -} - -int GetKeyTrigger(ITEM_INFO* item) -{ - FLOOR_INFO* floor = GetFloor(item->pos.xPos, item->pos.yPos, item->pos.zPos, &item->roomNumber); - GetFloorHeight(floor, item->pos.xPos, item->pos.yPos, item->pos.zPos); - - if (TriggerIndex) - { - short* trigger = TriggerIndex; - for (short i = *TriggerIndex; (i & 0x1F) != 4; trigger++) - { - if (i < 0) - break; - i = trigger[1]; - } - if (*trigger & 4) - { - for (short* j = &trigger[2]; (*j / 256) & 0x3C || item != &g_Level.Items[*j & 0x3FF]; j++) - { - if (*j & 0x8000) - return 0; - } - return 1; - } - } - - return 0; -} - -int GetSwitchTrigger(ITEM_INFO* item, short* itemNos, int AttatchedToSwitch) -{ - FLOOR_INFO* floor = GetFloor(item->pos.xPos, item->pos.yPos, item->pos.zPos, &item->roomNumber); - GetFloorHeight(floor, item->pos.xPos, item->pos.yPos, item->pos.zPos); - - if (TriggerIndex) - { - short* trigger; - for (trigger = TriggerIndex; (*trigger & DATA_TYPE) != TRIGGER_TYPE; trigger++) - { - if (*trigger & END_BIT) - break; - } - - if (*trigger & 4) - { - trigger += 2; - short* current = itemNos; - int k = 0; - do - { - if (TRIG_BITS(*trigger) == TO_OBJECT && item != &g_Level.Items[*trigger & VALUE_BITS]) - { - current[k] = *trigger & VALUE_BITS; - ++k; - } - if (*trigger & END_BIT) - break; - ++trigger; - } - while (true); - - return k; - } - } - - return 0; -} - -int SwitchTrigger(short itemNum, short timer) -{ - ITEM_INFO* item = &g_Level.Items[itemNum]; - if (item->status == ITEM_DEACTIVATED) - { - if ((!item->currentAnimState && item->objectNumber != ID_JUMP_SWITCH || item->currentAnimState == 1 && item->objectNumber == ID_JUMP_SWITCH) && timer > 0) - { - item->timer = timer; - item->status = ITEM_ACTIVE; - if (timer != 1) - item->timer = 30 * timer; - return 1; - } - if (item->triggerFlags != 6 || item->currentAnimState) - { - RemoveActiveItem(itemNum); - - item->status = ITEM_NOT_ACTIVE; - if (!item->itemFlags[0] == 0) - item->flags |= 0x100; - if (item->currentAnimState != 1) - return 1; - if (item->triggerFlags != 5 && item->triggerFlags != 6) - return 1; - } - else - { - item->status = ITEM_ACTIVE; - return 1; - } - } - else if (item->status) - { - return ((item->flags & 0x100u) / 256); - } - else - { - return 0; - } - - return 0; -} - void InitialiseShootSwitch(short itemNumber) { ITEM_INFO* item = &g_Level.Items[itemNumber]; @@ -797,25 +39,6 @@ void InitialiseShootSwitch(short itemNumber) item->meshBits &= ~(1 << (Objects[item->objectNumber].nmeshes - 2)); } -void InitialisePulleySwitch(short itemNumber) -{ - ITEM_INFO* item = &g_Level.Items[itemNumber]; - - item->itemFlags[3] = item->triggerFlags; - item->triggerFlags = abs(item->triggerFlags); - - if (item->status == ITEM_INVISIBLE) - { - item->itemFlags[1] = 1; - item->status = ITEM_NOT_ACTIVE; - } -} - -void InitialiseCrowDoveSwitch(short itemNumber) -{ - g_Level.Items[itemNumber].meshBits = 3; -} - void ShootSwitchCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* coll) { ITEM_INFO* item = &g_Level.Items[itemNumber]; diff --git a/TR5Main/Game/switch.h b/TR5Main/Game/switch.h index 4998e9d6d..3a796fb48 100644 --- a/TR5Main/Game/switch.h +++ b/TR5Main/Game/switch.h @@ -2,23 +2,6 @@ #include "collide.h" -extern int PulleyItemNumber; - -void CrowDoveSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); -void CrowDoveSwitchControl(short itemNumber); -void FullBlockSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); -void FullBlockSwitchControl(short itemNumber); -void CrowbarSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); -void TurnSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); -void TurnSwitchControl(short itemNum); -void PulleyCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); -void UnderwaterSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); -void SwitchCollision2(short itemNum, ITEM_INFO* l, COLL_INFO* coll); -int GetKeyTrigger(ITEM_INFO* item); -int GetSwitchTrigger(ITEM_INFO* item, short* itemNos, int AttatchedToSwitch); -int SwitchTrigger(short itemNum, short timer); -void InitialisePulleySwitch(short itemNumber); -void InitialiseCrowDoveSwitch(short itemNumber); void ProcessExplodingSwitchType8(ITEM_INFO* item); void InitialiseShootSwitch(short itemNumber); void ShootSwitchCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* coll); diff --git a/TR5Main/Objects/Effects/tr4_bubbles.cpp b/TR5Main/Objects/Effects/tr4_bubbles.cpp index a2a0170d6..e249da46b 100644 --- a/TR5Main/Objects/Effects/tr4_bubbles.cpp +++ b/TR5Main/Objects/Effects/tr4_bubbles.cpp @@ -411,7 +411,7 @@ namespace ten::entities::all TriggerDemigodMissileFlame(fxNum, 16 * dx, 16 * dy, 16 * dz); break; case 6: - ten::entities::tr4::TriggerCrocgodMissileFlame(fxNum, 16 * dx, 16 * dy, 16 * dz); + TEN::Entities::TR4::TriggerCrocgodMissileFlame(fxNum, 16 * dx, 16 * dy, 16 * dz); break; } } diff --git a/TR5Main/Objects/Effects/tr4_locusts.cpp b/TR5Main/Objects/Effects/tr4_locusts.cpp index b52ab9ab6..5c197e501 100644 --- a/TR5Main/Objects/Effects/tr4_locusts.cpp +++ b/TR5Main/Objects/Effects/tr4_locusts.cpp @@ -7,7 +7,7 @@ #include "lara.h" #include "tomb4fx.h" -namespace ten::entities::tr4 { +namespace TEN::Entities::TR4 { LOCUST_INFO Locusts[MAX_LOCUSTS]; int CreateLocust(void) diff --git a/TR5Main/Objects/Effects/tr4_locusts.h b/TR5Main/Objects/Effects/tr4_locusts.h index 95944a5eb..a5d4598d5 100644 --- a/TR5Main/Objects/Effects/tr4_locusts.h +++ b/TR5Main/Objects/Effects/tr4_locusts.h @@ -15,7 +15,7 @@ struct LOCUST_INFO BYTE counter; }; -namespace ten::entities::tr4 { +namespace TEN::Entities::TR4 { constexpr auto MAX_LOCUSTS = 64; constexpr auto LOCUST_LARA_DAMAGE = 3; constexpr auto LOCUST_ENTITY_DAMAGE = 1; diff --git a/TR5Main/Objects/Generic/Switches/cog_switch.cpp b/TR5Main/Objects/Generic/Switches/cog_switch.cpp index 890ce6af9..2410c9874 100644 --- a/TR5Main/Objects/Generic/Switches/cog_switch.cpp +++ b/TR5Main/Objects/Generic/Switches/cog_switch.cpp @@ -6,7 +6,7 @@ #include "generic_switch.h" #include "door.h" -namespace ten::entities::switches +namespace TEN::Entities::Switches { PHD_VECTOR CogSwitchPos(0, 0, -856); diff --git a/TR5Main/Objects/Generic/Switches/cog_switch.h b/TR5Main/Objects/Generic/Switches/cog_switch.h index 566092587..0d4316c1d 100644 --- a/TR5Main/Objects/Generic/Switches/cog_switch.h +++ b/TR5Main/Objects/Generic/Switches/cog_switch.h @@ -3,7 +3,7 @@ #include "items.h" #include -namespace ten::entities::switches +namespace TEN::Entities::Switches { constexpr auto COG_DOOR_TURN = 40; constexpr auto COG_DOOR_SPEED = 12; diff --git a/TR5Main/Objects/Generic/Switches/crowbar_switch.cpp b/TR5Main/Objects/Generic/Switches/crowbar_switch.cpp index a91af7f56..521eeaa38 100644 --- a/TR5Main/Objects/Generic/Switches/crowbar_switch.cpp +++ b/TR5Main/Objects/Generic/Switches/crowbar_switch.cpp @@ -6,8 +6,9 @@ #include "crowbar_switch.h" #include "newinv2.h" #include "sound.h" +#include "pickup.h" -namespace ten::entities::switches +namespace TEN::Entities::Switches { PHD_VECTOR CrowbarPos = { -89, 0, -328 }; @@ -33,8 +34,6 @@ namespace ten::entities::switches -ANGLE(10), ANGLE(10) }; - extern PHD_VECTOR OldPickupPos; - void CrowbarSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) { int doSwitch = 0; diff --git a/TR5Main/Objects/Generic/Switches/crowbar_switch.h b/TR5Main/Objects/Generic/Switches/crowbar_switch.h index f12d6229c..2fdfd48e4 100644 --- a/TR5Main/Objects/Generic/Switches/crowbar_switch.h +++ b/TR5Main/Objects/Generic/Switches/crowbar_switch.h @@ -3,7 +3,7 @@ #include "items.h" #include -namespace ten::entities::switches +namespace TEN::Entities::Switches { void CrowbarSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); } \ No newline at end of file diff --git a/TR5Main/Objects/Generic/Switches/fullblock_switch.cpp b/TR5Main/Objects/Generic/Switches/fullblock_switch.cpp new file mode 100644 index 000000000..ba4af8a1f --- /dev/null +++ b/TR5Main/Objects/Generic/Switches/fullblock_switch.cpp @@ -0,0 +1,105 @@ +#include "framework.h" +#include "fullblock_switch.h" +#include "control.h" +#include "input.h" +#include "lara.h" +#include "generic_switch.h" + +namespace TEN::Entities::Switches +{ + OBJECT_COLLISION_BOUNDS FullBlockSwitchBounds = + { + -384, 384, + 0, 256, + 0, 512, + -ANGLE(10), ANGLE(10), + -ANGLE(30), ANGLE(30), + -ANGLE(10), ANGLE(10) + }; + + PHD_VECTOR FullBlockSwitchPos = { 0, 0, 0 }; + + byte SequenceUsed[6]; + byte SequenceResults[3][3][3]; + byte Sequences[3]; + byte CurrentSequence; + + void FullBlockSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) + { + ITEM_INFO* item = &g_Level.Items[itemNum]; + + if ((!(TrInput & IN_ACTION) + || item->status + || item->flags & 0x100 + || CurrentSequence >= 3 + || Lara.gunStatus + || l->currentAnimState != LS_STOP + || l->animNumber != LA_STAND_IDLE) + && (!Lara.isMoving || Lara.generalPtr != (void*)itemNum)) + { + ObjectCollision(itemNum, l, coll); + return; + } + + if (TestLaraPosition(&FullBlockSwitchBounds, item, l)) + { + if (MoveLaraPosition(&FullBlockSwitchPos, item, l)) + { + if (item->currentAnimState == 1) + { + l->currentAnimState = LS_SWITCH_DOWN; + l->animNumber = LA_BUTTON_GIANT_PUSH; + item->goalAnimState = 0; + } + l->goalAnimState = LS_STOP; + l->frameNumber = g_Level.Anims[l->animNumber].frameBase; + item->status = ITEM_ACTIVE; + + AddActiveItem(itemNum); + AnimateItem(item); + + Lara.isMoving = false; + Lara.headYrot = 0; + Lara.headXrot = 0; + Lara.torsoYrot = 0; + Lara.torsoXrot = 0; + Lara.gunStatus = LG_HANDS_BUSY; + } + else + { + Lara.generalPtr = (void*)itemNum; + } + } + else if (Lara.isMoving && Lara.generalPtr == (void*)itemNum) + { + Lara.isMoving = false; + Lara.gunStatus = LG_NO_ARMS; + } + } + + void FullBlockSwitchControl(short itemNumber) + { + ITEM_INFO* item = &g_Level.Items[itemNumber]; + + if (item->animNumber != Objects[item->objectNumber].animIndex + 2 + || CurrentSequence >= 3 + || item->itemFlags[0]) + { + if (CurrentSequence >= 4) + { + item->itemFlags[0] = 0; + item->goalAnimState = SWITCH_ON; + item->status = ITEM_NOT_ACTIVE; + if (++CurrentSequence >= 7) + CurrentSequence = 0; + } + } + else + { + item->itemFlags[0] = 1; + Sequences[CurrentSequence++] = item->triggerFlags; + } + + AnimateItem(item); + } +} \ No newline at end of file diff --git a/TR5Main/Objects/Generic/Switches/fullblock_switch.h b/TR5Main/Objects/Generic/Switches/fullblock_switch.h new file mode 100644 index 000000000..6dcc4d9b8 --- /dev/null +++ b/TR5Main/Objects/Generic/Switches/fullblock_switch.h @@ -0,0 +1,15 @@ +#pragma once + +#include "items.h" +#include + +namespace TEN::Entities::Switches +{ + extern byte SequenceUsed[6]; + extern byte SequenceResults[3][3][3]; + extern byte Sequences[3]; + extern byte CurrentSequence; + + void FullBlockSwitchControl(short itemNumber); + void FullBlockSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); +} \ No newline at end of file diff --git a/TR5Main/Objects/Generic/Switches/generic_switch.cpp b/TR5Main/Objects/Generic/Switches/generic_switch.cpp index e2a38cb88..4b1cea816 100644 --- a/TR5Main/Objects/Generic/Switches/generic_switch.cpp +++ b/TR5Main/Objects/Generic/Switches/generic_switch.cpp @@ -6,7 +6,7 @@ #include "sphere.h" #include "draw.h" -namespace ten::entities::switches +namespace TEN::Entities::Switches { OBJECT_COLLISION_BOUNDS SwitchBounds = { @@ -227,4 +227,113 @@ namespace ten::entities::switches if (l->currentAnimState != LS_SWITCH_DOWN && l->currentAnimState != LS_SWITCH_UP) ObjectCollision(itemNum, l, coll); } + + int GetKeyTrigger(ITEM_INFO* item) + { + FLOOR_INFO* floor = GetFloor(item->pos.xPos, item->pos.yPos, item->pos.zPos, &item->roomNumber); + GetFloorHeight(floor, item->pos.xPos, item->pos.yPos, item->pos.zPos); + + if (TriggerIndex) + { + short* trigger = TriggerIndex; + for (short i = *TriggerIndex; (i & 0x1F) != 4; trigger++) + { + if (i < 0) + break; + i = trigger[1]; + } + if (*trigger & 4) + { + for (short* j = &trigger[2]; (*j / 256) & 0x3C || item != &g_Level.Items[*j & 0x3FF]; j++) + { + if (*j & 0x8000) + return 0; + } + return 1; + } + } + + return 0; + } + + int GetSwitchTrigger(ITEM_INFO* item, short* itemNos, int AttatchedToSwitch) + { + FLOOR_INFO* floor = GetFloor(item->pos.xPos, item->pos.yPos, item->pos.zPos, &item->roomNumber); + GetFloorHeight(floor, item->pos.xPos, item->pos.yPos, item->pos.zPos); + + if (TriggerIndex) + { + short* trigger; + for (trigger = TriggerIndex; (*trigger & DATA_TYPE) != TRIGGER_TYPE; trigger++) + { + if (*trigger & END_BIT) + break; + } + + if (*trigger & 4) + { + trigger += 2; + short* current = itemNos; + int k = 0; + do + { + if (TRIG_BITS(*trigger) == TO_OBJECT && item != &g_Level.Items[*trigger & VALUE_BITS]) + { + current[k] = *trigger & VALUE_BITS; + ++k; + } + if (*trigger & END_BIT) + break; + ++trigger; + } while (true); + + return k; + } + } + + return 0; + } + + int SwitchTrigger(short itemNum, short timer) + { + ITEM_INFO* item = &g_Level.Items[itemNum]; + if (item->status == ITEM_DEACTIVATED) + { + if ((!item->currentAnimState && item->objectNumber != ID_JUMP_SWITCH || item->currentAnimState == 1 && item->objectNumber == ID_JUMP_SWITCH) && timer > 0) + { + item->timer = timer; + item->status = ITEM_ACTIVE; + if (timer != 1) + item->timer = 30 * timer; + return 1; + } + if (item->triggerFlags != 6 || item->currentAnimState) + { + RemoveActiveItem(itemNum); + + item->status = ITEM_NOT_ACTIVE; + if (!item->itemFlags[0] == 0) + item->flags |= 0x100; + if (item->currentAnimState != 1) + return 1; + if (item->triggerFlags != 5 && item->triggerFlags != 6) + return 1; + } + else + { + item->status = ITEM_ACTIVE; + return 1; + } + } + else if (item->status) + { + return ((item->flags & 0x100u) / 256); + } + else + { + return 0; + } + + return 0; + } } \ No newline at end of file diff --git a/TR5Main/Objects/Generic/Switches/generic_switch.h b/TR5Main/Objects/Generic/Switches/generic_switch.h index 362dcc1a0..48ab1568f 100644 --- a/TR5Main/Objects/Generic/Switches/generic_switch.h +++ b/TR5Main/Objects/Generic/Switches/generic_switch.h @@ -3,15 +3,17 @@ #include "items.h" #include -namespace ten::entities::switches +namespace TEN::Entities::Switches { enum SwitchStatus { SWITCH_OFF, SWITCH_ON }; - - void InitialiseSwitch(short itemNumber); + void SwitchControl(short itemNumber); void SwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); + int GetKeyTrigger(ITEM_INFO* item); + int GetSwitchTrigger(ITEM_INFO* item, short* itemNos, int AttatchedToSwitch); + int SwitchTrigger(short itemNum, short timer); } \ No newline at end of file diff --git a/TR5Main/Objects/Generic/Switches/jump_switch.cpp b/TR5Main/Objects/Generic/Switches/jump_switch.cpp index de7edaa99..0b4d83008 100644 --- a/TR5Main/Objects/Generic/Switches/jump_switch.cpp +++ b/TR5Main/Objects/Generic/Switches/jump_switch.cpp @@ -5,7 +5,7 @@ #include "lara.h" #include "generic_switch.h" -namespace ten::entities::switches +namespace TEN::Entities::Switches { OBJECT_COLLISION_BOUNDS JumpSwitchBounds = { diff --git a/TR5Main/Objects/Generic/Switches/jump_switch.h b/TR5Main/Objects/Generic/Switches/jump_switch.h index 178b229a0..5169758a2 100644 --- a/TR5Main/Objects/Generic/Switches/jump_switch.h +++ b/TR5Main/Objects/Generic/Switches/jump_switch.h @@ -3,7 +3,7 @@ #include "items.h" #include -namespace ten::entities::switches +namespace TEN::Entities::Switches { void JumpSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); } \ No newline at end of file diff --git a/TR5Main/Objects/Generic/Switches/pulley_switch.cpp b/TR5Main/Objects/Generic/Switches/pulley_switch.cpp new file mode 100644 index 000000000..3cb2b3afa --- /dev/null +++ b/TR5Main/Objects/Generic/Switches/pulley_switch.cpp @@ -0,0 +1,103 @@ +#include "framework.h" +#include "pulley_switch.h" +#include "control.h" +#include "input.h" +#include "lara.h" +#include "generic_switch.h" +#include "sound.h" +#include "pickup.h" + +namespace TEN::Entities::Switches +{ + OBJECT_COLLISION_BOUNDS PulleyBounds = + { + -256, 256, + 0, 0, + -512, 512, + -ANGLE(10), ANGLE(10), + -ANGLE(30), ANGLE(30), + -ANGLE(10), ANGLE(10) + }; + + PHD_VECTOR PulleyPos = { 0, 0, -148 }; + + void InitialisePulleySwitch(short itemNumber) + { + ITEM_INFO* item = &g_Level.Items[itemNumber]; + + item->itemFlags[3] = item->triggerFlags; + item->triggerFlags = abs(item->triggerFlags); + + if (item->status == ITEM_INVISIBLE) + { + item->itemFlags[1] = 1; + item->status = ITEM_NOT_ACTIVE; + } + } + + void PulleySwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) + { + ITEM_INFO* item = &g_Level.Items[itemNum]; + + if ((TrInput & IN_ACTION) + && Lara.gunStatus == LG_NO_ARMS + && l->currentAnimState == LS_STOP + && l->animNumber == LA_STAND_IDLE + && l->gravityStatus == false + || Lara.isMoving && Lara.generalPtr == (void*)itemNum) + { + short oldYrot = item->pos.yRot; + item->pos.yRot = l->pos.yRot; + if (TestLaraPosition(&PulleyBounds, item, l)) + { + if (item->itemFlags[1]) + { + if (OldPickupPos.x != l->pos.xPos || OldPickupPos.y != l->pos.yPos || OldPickupPos.z != l->pos.zPos) + { + OldPickupPos.x = l->pos.xPos; + OldPickupPos.y = l->pos.yPos; + OldPickupPos.z = l->pos.zPos; + SayNo(); + } + } + else if (MoveLaraPosition(&PulleyPos, item, l)) + { + l->animNumber = LA_PULLEY_GRAB; + l->currentAnimState = LS_PULLEY; + l->frameNumber = g_Level.Anims[l->animNumber].frameBase; + + AddActiveItem(itemNum); + + item->pos.yRot = oldYrot; + item->status = ITEM_ACTIVE; + + Lara.isMoving = false; + Lara.headYrot = 0; + Lara.headXrot = 0; + Lara.torsoYrot = 0; + Lara.torsoXrot = 0; + Lara.gunStatus = LG_HANDS_BUSY; + Lara.generalPtr = item; + } + else + { + Lara.generalPtr = (void*)itemNum; + } + item->pos.yRot = oldYrot; + } + else + { + if (Lara.isMoving && Lara.generalPtr == (void*)itemNum) + { + Lara.isMoving = false; + Lara.gunStatus = LG_NO_ARMS; + } + item->pos.yRot = oldYrot; + } + } + else if (l->currentAnimState != LS_PULLEY) + { + ObjectCollision(itemNum, l, coll); + } + } +} \ No newline at end of file diff --git a/TR5Main/Objects/Generic/Switches/pulley_switch.h b/TR5Main/Objects/Generic/Switches/pulley_switch.h new file mode 100644 index 000000000..9fc7fa849 --- /dev/null +++ b/TR5Main/Objects/Generic/Switches/pulley_switch.h @@ -0,0 +1,10 @@ +#pragma once + +#include "items.h" +#include + +namespace TEN::Entities::Switches +{ + void InitialisePulleySwitch(short itemNumber); + void PulleySwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); +} \ No newline at end of file diff --git a/TR5Main/Objects/Generic/Switches/rail_switch.cpp b/TR5Main/Objects/Generic/Switches/rail_switch.cpp index 59d7761ef..020938590 100644 --- a/TR5Main/Objects/Generic/Switches/rail_switch.cpp +++ b/TR5Main/Objects/Generic/Switches/rail_switch.cpp @@ -5,7 +5,7 @@ #include "lara.h" #include "generic_switch.h" -namespace ten::entities::switches +namespace TEN::Entities::Switches { PHD_VECTOR RailSwitchPos = { 0, 0, -550 }; diff --git a/TR5Main/Objects/Generic/Switches/rail_switch.h b/TR5Main/Objects/Generic/Switches/rail_switch.h index 99d8f3222..6a2c3f4b3 100644 --- a/TR5Main/Objects/Generic/Switches/rail_switch.h +++ b/TR5Main/Objects/Generic/Switches/rail_switch.h @@ -3,7 +3,7 @@ #include "items.h" #include -namespace ten::entities::switches +namespace TEN::Entities::Switches { void RailSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); } \ No newline at end of file diff --git a/TR5Main/Objects/Generic/Switches/turn_switch.cpp b/TR5Main/Objects/Generic/Switches/turn_switch.cpp new file mode 100644 index 000000000..9b71f9493 --- /dev/null +++ b/TR5Main/Objects/Generic/Switches/turn_switch.cpp @@ -0,0 +1,252 @@ +#include "framework.h" +#include "turn_switch.h" +#include "control.h" +#include "input.h" +#include "lara.h" +#include "generic_switch.h" +#include "door.h" +#include "sound.h" +#include "switch.h" + +namespace TEN::Entities::Switches +{ + enum TurnSwitchDirection + { + TURN_SWITCH_STOP, + TURN_SWITCH_ANTICLOCKWISE, + TURN_SWITCH_CLOCKWISE + }; + + OBJECT_COLLISION_BOUNDS TurnSwitchBoundsA = + { + 512, 896, + 0, 0, + -512, 0, + -ANGLE(10), ANGLE(10), + -ANGLE(30), ANGLE(30), + -ANGLE(10), ANGLE(10) + }; + + PHD_VECTOR TurnSwitchPos = { 650, 0, 138 }; + + OBJECT_COLLISION_BOUNDS TurnSwitchBoundsC = + { + 512, 896, + 0, 0, + 0, 512, + -ANGLE(10), ANGLE(10), + -ANGLE(30), ANGLE(30), + -ANGLE(10), ANGLE(10) + }; + + PHD_VECTOR TurnSwitchPosA = { 650, 0, -138 }; + + void TurnSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) + { + ITEM_INFO* item = &g_Level.Items[itemNum]; + int flag = 0; + + if (item->currentAnimState + && TrInput & IN_ACTION + && l->currentAnimState == LS_STOP + && l->animNumber == LA_STAND_IDLE + && !l->gravityStatus + && Lara.gunStatus == LG_NO_ARMS + || Lara.isMoving && Lara.generalPtr == (void*)itemNum) + { + short ItemNos[8]; + if (TestLaraPosition(&TurnSwitchBoundsA, item, l)) + { + if (MoveLaraPosition(&TurnSwitchPosA, item, l)) + { + l->animNumber = LA_TURNSWITCH_GRAB_COUNTER_CLOCKWISE; + l->frameNumber = g_Level.Anims[LA_TURNSWITCH_GRAB_COUNTER_CLOCKWISE].frameBase; + item->animNumber = Objects[item->objectNumber].animIndex + 4; + item->frameNumber = g_Level.Anims[item->animNumber].frameBase; + item->itemFlags[0] = 1; + ForcedFixedCamera.x = item->pos.xPos - 1024 * phd_sin(item->pos.yRot); + ForcedFixedCamera.z = item->pos.zPos - 1024 * phd_cos(item->pos.yRot); + + Lara.isMoving = false; + Lara.headYrot = 0; + Lara.headXrot = 0; + Lara.torsoYrot = 0; + Lara.torsoXrot = 0; + Lara.gunStatus = LG_HANDS_BUSY; + l->currentAnimState = LA_REACH; + + UseForcedFixedCamera = true; + ForcedFixedCamera.y = item->pos.yPos - 2048; + ForcedFixedCamera.roomNumber = item->roomNumber; + + AddActiveItem(itemNum); + + item->status = ITEM_ACTIVE; + item->itemFlags[1] = 0; + + if (GetSwitchTrigger(item, ItemNos, 0)) + { + if (!TriggerActive(&g_Level.Items[ItemNos[0]])) + { + g_Level.Items[ItemNos[0]].animNumber = Objects[g_Level.Items[ItemNos[0]].objectNumber].animIndex; + g_Level.Items[ItemNos[0]].frameNumber = g_Level.Anims[g_Level.Items[ItemNos[0]].animNumber].frameBase; + } + } + return; + } + Lara.generalPtr = (void*)itemNum; + } + else + { + l->pos.yRot ^= (short)ANGLE(180); + if (TestLaraPosition(&TurnSwitchBoundsC, item, l)) + { + if (MoveLaraPosition(&TurnSwitchPos, item, l)) + { + l->animNumber = 319; + flag = 1; + l->frameNumber = g_Level.Anims[319].frameBase; + item->itemFlags[0] = 2; + ForcedFixedCamera.x = item->pos.xPos + 1024 * phd_sin(item->pos.yRot); + ForcedFixedCamera.z = item->pos.zPos + 1024 * phd_cos(item->pos.yRot); + } + else + { + Lara.generalPtr = (void*)itemNum; + } + } + else if (Lara.isMoving && Lara.generalPtr == (void*)itemNum) + { + Lara.isMoving = false; + Lara.gunStatus = LG_NO_ARMS; + } + l->pos.yRot ^= (short)ANGLE(180); + if (flag) + { + Lara.isMoving = 0; + Lara.headYrot = 0; + Lara.headXrot = 0; + Lara.torsoYrot = 0; + Lara.torsoXrot = 0; + Lara.gunStatus = LG_HANDS_BUSY; + l->currentAnimState = LA_REACH; + UseForcedFixedCamera = true; + ForcedFixedCamera.y = item->pos.yPos - 2048; + ForcedFixedCamera.roomNumber = item->roomNumber; + AddActiveItem(itemNum); + item->status = ITEM_ACTIVE; + item->itemFlags[1] = 0; + if (GetSwitchTrigger(item, ItemNos, 0)) + { + if (!TriggerActive(&g_Level.Items[ItemNos[0]])) + { + g_Level.Items[ItemNos[0]].animNumber = Objects[g_Level.Items[ItemNos[0]].objectNumber].animIndex + 4; + g_Level.Items[ItemNos[0]].frameNumber = g_Level.Anims[g_Level.Items[ItemNos[0]].animNumber].frameBase; + } + } + return; + } + } + } + + if (coll->enableBaddiePush && TestBoundsCollide(item, l, coll->radius)) + { + GlobalCollisionBounds.X1 = -512; + GlobalCollisionBounds.X2 = 512; + GlobalCollisionBounds.Y1 = -512; + GlobalCollisionBounds.Y2 = 0; + GlobalCollisionBounds.Z1 = -512; + GlobalCollisionBounds.Z2 = 512; + + ItemPushLara(item, l, coll, 0, 2); + + GlobalCollisionBounds.X1 = 256; + GlobalCollisionBounds.X2 = 1024; + GlobalCollisionBounds.Z1 = -128; + GlobalCollisionBounds.Z2 = 128; + + ItemPushLara(item, l, coll, 0, 2); + } + } + + void TurnSwitchControl(short itemNum) + { + ITEM_INFO* l = LaraItem; + ITEM_INFO* item = &g_Level.Items[itemNum]; + + if (g_Level.Items[itemNum].itemFlags[0] == TURN_SWITCH_CLOCKWISE) + { + if (item->animNumber == Objects[item->objectNumber].animIndex + 2) + { + item->pos.yRot += ANGLE(90); + if (TrInput & IN_ACTION) + { + l->animNumber = LA_TURNSWITCH_PUSH_CLOCKWISE_START; + l->frameNumber = g_Level.Anims[l->animNumber].frameBase; + + item->animNumber = Objects[item->objectNumber].animIndex + 1; + item->frameNumber = g_Level.Anims[item->animNumber].frameBase; + } + } + + if (l->animNumber == LA_TURNSWITCH_PUSH_CLOCKWISE_END + && l->frameNumber == g_Level.Anims[l->animNumber].frameEnd && + !item->itemFlags[1]) + item->itemFlags[1] = 1; + + if (l->frameNumber >= g_Level.Anims[LA_TURNSWITCH_PUSH_CLOCKWISE_START].frameBase && + l->frameNumber <= g_Level.Anims[LA_TURNSWITCH_PUSH_CLOCKWISE_START].frameBase + 43 + || + l->frameNumber >= g_Level.Anims[LA_TURNSWITCH_PUSH_CLOCKWISE_START].frameBase + 58 && + l->frameNumber <= g_Level.Anims[LA_TURNSWITCH_PUSH_CLOCKWISE_START].frameBase + 115) + { + SoundEffect(SFX_TR4_PUSHABLE_SOUND, &item->pos, 2); + } + } + else + { + if (item->animNumber == Objects[ID_TURN_SWITCH].animIndex + 6) + { + item->pos.yRot -= ANGLE(90); + if (TrInput & IN_ACTION) + { + l->animNumber = LA_TURNSWITCH_PUSH_COUNTER_CLOCKWISE_START; + l->frameNumber = g_Level.Anims[l->animNumber].frameBase; + item->animNumber = Objects[item->objectNumber].animIndex + 5; + item->frameNumber = g_Level.Anims[item->animNumber].frameBase; + } + } + + if (l->animNumber == LA_TURNSWITCH_PUSH_COUNTER_CLOCKWISE_END && l->frameNumber == g_Level.Anims[LA_TURNSWITCH_PUSH_COUNTER_CLOCKWISE_END].frameEnd && + !item->itemFlags[1]) + item->itemFlags[1] = 1; + + if (l->frameNumber >= g_Level.Anims[LA_TURNSWITCH_PUSH_COUNTER_CLOCKWISE_START].frameBase && + l->frameNumber <= g_Level.Anims[LA_TURNSWITCH_PUSH_COUNTER_CLOCKWISE_START].frameBase + 43 + || + l->frameNumber >= g_Level.Anims[LA_TURNSWITCH_PUSH_COUNTER_CLOCKWISE_START].frameBase + 58 && + l->frameNumber <= g_Level.Anims[LA_TURNSWITCH_PUSH_COUNTER_CLOCKWISE_START].frameBase + 115) + { + SoundEffect(SFX_TR4_PUSHABLE_SOUND, &item->pos, 2); + } + } + + AnimateItem(item); + + if (item->itemFlags[1] == 1) + { + l->animNumber = LA_STAND_IDLE; + l->currentAnimState = LS_STOP; + l->frameNumber = g_Level.Anims[l->animNumber].frameBase; + item->animNumber = Objects[item->objectNumber].animIndex; + item->frameNumber = g_Level.Anims[item->animNumber].frameBase; + item->status = ITEM_NOT_ACTIVE; + + RemoveActiveItem(itemNum); + + Lara.gunStatus = LG_NO_ARMS; + UseForcedFixedCamera = 0; + item->itemFlags[1] = 2; + } + } +} \ No newline at end of file diff --git a/TR5Main/Objects/Generic/Switches/turn_switch.h b/TR5Main/Objects/Generic/Switches/turn_switch.h new file mode 100644 index 000000000..33dccbb5d --- /dev/null +++ b/TR5Main/Objects/Generic/Switches/turn_switch.h @@ -0,0 +1,10 @@ +#pragma once + +#include "items.h" +#include + +namespace TEN::Entities::Switches +{ + void TurnSwitchControl(short itemNumber); + void TurnSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); +} \ No newline at end of file diff --git a/TR5Main/Objects/Generic/Switches/underwater_switch.cpp b/TR5Main/Objects/Generic/Switches/underwater_switch.cpp index 078fc0180..f31981983 100644 --- a/TR5Main/Objects/Generic/Switches/underwater_switch.cpp +++ b/TR5Main/Objects/Generic/Switches/underwater_switch.cpp @@ -7,7 +7,7 @@ #include "sound.h" #include "generic_switch.h" -namespace ten::entities::switches +namespace TEN::Entities::Switches { OBJECT_COLLISION_BOUNDS UnderwaterSwitchBounds = { diff --git a/TR5Main/Objects/Generic/Switches/underwater_switch.h b/TR5Main/Objects/Generic/Switches/underwater_switch.h index e52953c87..b76afcde5 100644 --- a/TR5Main/Objects/Generic/Switches/underwater_switch.h +++ b/TR5Main/Objects/Generic/Switches/underwater_switch.h @@ -3,7 +3,7 @@ #include "items.h" #include -namespace ten::entities::switches +namespace TEN::Entities::Switches { void UnderwaterSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); void CeilingUnderwaterSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); diff --git a/TR5Main/Objects/Generic/generic_objects.cpp b/TR5Main/Objects/Generic/generic_objects.cpp index 6a90c11ba..c6cc0ef97 100644 --- a/TR5Main/Objects/Generic/generic_objects.cpp +++ b/TR5Main/Objects/Generic/generic_objects.cpp @@ -12,11 +12,13 @@ #include "generic_switch.h" #include "crowbar_switch.h" #include "underwater_switch.h" +#include "pulley_switch.h" +#include "fullblock_switch.h" /// necessary import #include "setup.h" -using namespace ten::entities::switches; +using namespace TEN::Entities::Switches; static void StartObject() { @@ -234,6 +236,43 @@ void StartSwitches() obj->saveAnim = true; } } + + obj = &Objects[ID_PULLEY]; + if (obj->loaded) + { + obj->initialise = InitialisePulleySwitch; + obj->control = SwitchControl; + obj->collision = PulleySwitchCollision; + obj->saveFlags = true; + obj->saveAnim = true; + } + + obj = &Objects[ID_SEQUENCE_SWITCH1]; + if (obj->loaded) + { + obj->collision = FullBlockSwitchCollision; + obj->control = FullBlockSwitchControl; + obj->saveFlags = true; + obj->saveAnim = true; + } + + obj = &Objects[ID_SEQUENCE_SWITCH2]; + if (obj->loaded) + { + obj->collision = FullBlockSwitchCollision; + obj->control = FullBlockSwitchControl; + obj->saveFlags = true; + obj->saveAnim = true; + } + + obj = &Objects[ID_SEQUENCE_SWITCH3]; + if (obj->loaded) + { + obj->collision = FullBlockSwitchCollision; + obj->control = FullBlockSwitchControl; + obj->saveFlags = true; + obj->saveAnim = true; + } } void InitialiseGenericObjects() diff --git a/TR5Main/Objects/TR4/Entity/tr4_littlebeetle.cpp b/TR5Main/Objects/TR4/Entity/tr4_littlebeetle.cpp index 65f454c8c..fb71bf68a 100644 --- a/TR5Main/Objects/TR4/Entity/tr4_littlebeetle.cpp +++ b/TR5Main/Objects/TR4/Entity/tr4_littlebeetle.cpp @@ -5,7 +5,7 @@ #include "trmath.h" #include "lara.h" -namespace ten::entities::tr4 +namespace TEN::Entities::TR4 { SCARAB_INFO* Scarabs; int NextScarab; diff --git a/TR5Main/Objects/TR4/Entity/tr4_littlebeetle.h b/TR5Main/Objects/TR4/Entity/tr4_littlebeetle.h index dac849dc8..8cda22e83 100644 --- a/TR5Main/Objects/TR4/Entity/tr4_littlebeetle.h +++ b/TR5Main/Objects/TR4/Entity/tr4_littlebeetle.h @@ -11,7 +11,7 @@ struct SCARAB_INFO byte flags; }; -namespace ten::entities::tr4 +namespace TEN::Entities::TR4 { constexpr auto NUM_LITTLE_BETTLES = 256; diff --git a/TR5Main/Objects/TR4/Entity/tr4_mutant.cpp b/TR5Main/Objects/TR4/Entity/tr4_mutant.cpp index fdae0d67b..421ac61c8 100644 --- a/TR5Main/Objects/TR4/Entity/tr4_mutant.cpp +++ b/TR5Main/Objects/TR4/Entity/tr4_mutant.cpp @@ -10,7 +10,7 @@ #include "objectslist.h" #include "trmath.h" -namespace ten::entities::tr4 +namespace TEN::Entities::TR4 { void TriggerCrocgodMissile(PHD_3DPOS* src, short roomNumber, short counter) { @@ -306,7 +306,7 @@ namespace ten::entities::tr4 case STATE_MUTANT_LOCUST1: frameNumber = (item->frameNumber - g_Level.Anims[item->animNumber].frameBase); if (frameNumber >= 60 && frameNumber <= 120) - ten::entities::tr4::SpawnLocust(item); + TEN::Entities::TR4::SpawnLocust(item); break; case STATE_MUTANT_LOCUST2: diff --git a/TR5Main/Objects/TR4/Entity/tr4_mutant.h b/TR5Main/Objects/TR4/Entity/tr4_mutant.h index 8f9da9e33..bc8dc5157 100644 --- a/TR5Main/Objects/TR4/Entity/tr4_mutant.h +++ b/TR5Main/Objects/TR4/Entity/tr4_mutant.h @@ -3,7 +3,7 @@ #include "framework.h" #include "trmath.h" -namespace ten::entities::tr4 +namespace TEN::Entities::TR4 { enum STATES_CROCGOD { diff --git a/TR5Main/Objects/TR4/Entity/tr4_skeleton.cpp b/TR5Main/Objects/TR4/Entity/tr4_skeleton.cpp index 804a2f6a4..f7030cd4c 100644 --- a/TR5Main/Objects/TR4/Entity/tr4_skeleton.cpp +++ b/TR5Main/Objects/TR4/Entity/tr4_skeleton.cpp @@ -14,7 +14,7 @@ #include "tomb4fx.h" #include "level.h" -namespace ten::entities::tr4 +namespace TEN::Entities::TR4 { BITE_INFO skeletonBite = { 0, -16, 200, 11 }; diff --git a/TR5Main/Objects/TR4/Entity/tr4_skeleton.h b/TR5Main/Objects/TR4/Entity/tr4_skeleton.h index 4a03c06ea..f47565a8d 100644 --- a/TR5Main/Objects/TR4/Entity/tr4_skeleton.h +++ b/TR5Main/Objects/TR4/Entity/tr4_skeleton.h @@ -1,6 +1,6 @@ #pragma once -namespace ten::entities::tr4 +namespace TEN::Entities::TR4 { enum STATES_SKELETON { diff --git a/TR5Main/Objects/TR4/Object/tr4_element_puzzle.cpp b/TR5Main/Objects/TR4/Object/tr4_element_puzzle.cpp index f41c0f058..b2f9a0cf9 100644 --- a/TR5Main/Objects/TR4/Object/tr4_element_puzzle.cpp +++ b/TR5Main/Objects/TR4/Object/tr4_element_puzzle.cpp @@ -10,6 +10,9 @@ #include #include #include +#include "generic_switch.h" + +using namespace TEN::Entities::Switches; OBJECT_COLLISION_BOUNDS ElementPuzzleBounds = { 0x0000, 0x0000, 0xFFC0, 0x0000, 0x0000, 0x0000, diff --git a/TR5Main/Objects/TR4/Object/tr4_scales.cpp b/TR5Main/Objects/TR4/Object/tr4_scales.cpp index c56236706..dc0f42b0e 100644 --- a/TR5Main/Objects/TR4/Object/tr4_scales.cpp +++ b/TR5Main/Objects/TR4/Object/tr4_scales.cpp @@ -10,6 +10,9 @@ #include "draw.h" #include "tomb4fx.h" #include "tr4_ahmet.h" +#include "generic_switch.h" + +using namespace TEN::Entities::Switches; OBJECT_COLLISION_BOUNDS ScalesBounds = { diff --git a/TR5Main/Objects/TR4/tr4_objects.cpp b/TR5Main/Objects/TR4/tr4_objects.cpp index 5a8f950ed..7e685e26d 100644 --- a/TR5Main/Objects/TR4/tr4_objects.cpp +++ b/TR5Main/Objects/TR4/tr4_objects.cpp @@ -314,8 +314,8 @@ static void StartBaddy(OBJECT_INFO* obj) obj = &Objects[ID_SKELETON]; if (obj->loaded) { - obj->initialise = ten::entities::tr4::InitialiseSkeleton; - obj->control = ten::entities::tr4::SkeletonControl; + obj->initialise = TEN::Entities::TR4::InitialiseSkeleton; + obj->control = TEN::Entities::TR4::SkeletonControl; obj->collision = CreatureCollision; obj->hitPoints = 15; obj->hitEffect = HIT_SMOKE; @@ -664,8 +664,8 @@ static void StartBaddy(OBJECT_INFO* obj) obj = &Objects[ID_CROCODILE_GOD]; if (obj->loaded) { - obj->initialise = ten::entities::tr4::InitialiseCrocgod; - obj->control = ten::entities::tr4::CrocgodControl; + obj->initialise = TEN::Entities::TR4::InitialiseCrocgod; + obj->control = TEN::Entities::TR4::CrocgodControl; obj->collision = CreatureCollision; obj->shadowSize = UNIT_SHADOW / 2; obj->hitPoints = NOT_TARGETABLE; @@ -686,8 +686,8 @@ static void StartBaddy(OBJECT_INFO* obj) obj = &Objects[ID_LOCUSTS_EMITTER]; if (obj->loaded) { - obj->initialise = ten::entities::tr4::InitialiseLocust; - obj->control = ten::entities::tr4::LocustControl; + obj->initialise = TEN::Entities::TR4::InitialiseLocust; + obj->control = TEN::Entities::TR4::LocustControl; obj->drawRoutine = NULL; obj->saveFlags = true; obj->zoneType = ZONE_BASIC; @@ -729,8 +729,8 @@ static void StartBaddy(OBJECT_INFO* obj) obj = &Objects[ID_LITTLE_BEETLE]; if (obj->loaded) { - obj->initialise = ten::entities::tr4::InitialiseScarabs; - obj->control = ten::entities::tr4::ScarabsControl; + obj->initialise = TEN::Entities::TR4::InitialiseScarabs; + obj->control = TEN::Entities::TR4::ScarabsControl; obj->drawRoutine = NULL; obj->saveFlags = true; obj->zoneType = ZONE_BASIC; @@ -1185,6 +1185,6 @@ void InitialiseTR4Objects() void AllocTR4Objects() { - ten::entities::tr4::Scarabs = game_malloc(ten::entities::tr4::NUM_LITTLE_BETTLES); - ZeroMemory(ten::entities::tr4::Scarabs, ten::entities::tr4::NUM_LITTLE_BETTLES * sizeof(SCARAB_INFO)); + TEN::Entities::TR4::Scarabs = game_malloc(TEN::Entities::TR4::NUM_LITTLE_BETTLES); + ZeroMemory(TEN::Entities::TR4::Scarabs, TEN::Entities::TR4::NUM_LITTLE_BETTLES * sizeof(SCARAB_INFO)); } \ No newline at end of file diff --git a/TR5Main/Objects/TR5/Switch/tr5_crowdove_switch.cpp b/TR5Main/Objects/TR5/Switch/tr5_crowdove_switch.cpp new file mode 100644 index 000000000..48b4c4edc --- /dev/null +++ b/TR5Main/Objects/TR5/Switch/tr5_crowdove_switch.cpp @@ -0,0 +1,118 @@ +#include "framework.h" +#include "tr5_crowdove_switch.h" +#include "control.h" +#include "input.h" +#include "lara.h" +#include "generic_switch.h" +#include "sound.h" + +using namespace TEN::Entities::Switches; + +namespace TEN::Entities::TR5 +{ + OBJECT_COLLISION_BOUNDS CrowDoveBounds = + { + -256, 256, + 0, 0, + -512, 512, + -ANGLE(10), ANGLE(10), + -ANGLE(30), ANGLE(30), + -ANGLE(10), ANGLE(10) + }; + + PHD_VECTOR CrowDovePos = { 0, 0, -400 }; + + void InitialiseCrowDoveSwitch(short itemNumber) + { + g_Level.Items[itemNumber].meshBits = 3; + } + + void CrowDoveSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) + { + ITEM_INFO* item = &g_Level.Items[itemNum]; + + if (item->flags & ONESHOT + || !(item->meshBits & 4) + || (!(TrInput & IN_ACTION) + || Lara.gunStatus + || l->currentAnimState != LS_STOP + || l->animNumber != LA_STAND_IDLE + || l->gravityStatus) + && (!Lara.isMoving || Lara.generalPtr != (void*)itemNum)) + { + if (l->currentAnimState != LS_DOVESWITCH) + ObjectCollision(itemNum, l, coll); + } + else + { + int oldYrot = item->pos.yRot; + item->pos.yRot = l->pos.yRot; + if (TestLaraPosition(&CrowDoveBounds, item, l)) + { + if (MoveLaraPosition(&CrowDovePos, item, l)) + { + l->animNumber = LA_DOVESWITCH_TURN; + l->currentAnimState = LS_DOVESWITCH; + l->frameNumber = g_Level.Anims[l->animNumber].frameBase; + + AddActiveItem(itemNum); + + // NOTE: In original TR5 the switch was used together with heavy switches. + // This little fix make it usable normaly and less hardcoded. + item->itemFlags[0] = 0; + + item->status = ITEM_ACTIVE; + item->pos.yRot = oldYrot; + Lara.isMoving = false; + Lara.headYrot = 0; + Lara.headXrot = 0; + Lara.torsoYrot = 0; + Lara.torsoXrot = 0; + Lara.gunStatus = LG_HANDS_BUSY; + Lara.generalPtr = (void*)item; + } + else + { + Lara.generalPtr = (void*)itemNum; + } + item->pos.yRot = oldYrot; + } + else + { + if (Lara.isMoving && Lara.generalPtr == (void*)itemNum) + { + Lara.isMoving = false; + Lara.gunStatus = LG_NO_ARMS; + } + item->pos.yRot = oldYrot; + } + } + } + + void CrowDoveSwitchControl(short itemNumber) + { + ITEM_INFO* item = &g_Level.Items[itemNumber]; + + if (item->meshBits & 2) + { + ExplodeItemNode(item, 1, 0, 256); + SoundEffect(SFX_TR5_RAVENSWITCH_EXP, &item->pos, 0); + item->meshBits = 5; + RemoveActiveItem(itemNumber); + + // NOTE: In original TR5 the switch was used together with heavy switches. + // This little fix make it usable normaly and less hardcoded. + item->itemFlags[0] = 1; + } + else if (item->itemFlags[0] == 0) + { + if (item->currentAnimState == SWITCH_OFF) + item->goalAnimState = SWITCH_ON; + + AnimateItem(item); + + if (item->currentAnimState == SWITCH_OFF) + item->pos.yRot += ANGLE(90); + } + } +} \ No newline at end of file diff --git a/TR5Main/Objects/TR5/Switch/tr5_crowdove_switch.h b/TR5Main/Objects/TR5/Switch/tr5_crowdove_switch.h new file mode 100644 index 000000000..e94b803e0 --- /dev/null +++ b/TR5Main/Objects/TR5/Switch/tr5_crowdove_switch.h @@ -0,0 +1,11 @@ +#pragma once + +#include "items.h" +#include "collide.h" + +namespace TEN::Entities::TR5 +{ + void InitialiseCrowDoveSwitch(short itemNumber); + void CrowDoveSwitchControl(short itemNumber); + void CrowDoveSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); +} \ No newline at end of file diff --git a/TR5Main/Objects/TR5/Switch/tr5_raisingcog.cpp b/TR5Main/Objects/TR5/Switch/tr5_raisingcog.cpp index 5bc1dca44..31cd9c5d5 100644 --- a/TR5Main/Objects/TR5/Switch/tr5_raisingcog.cpp +++ b/TR5Main/Objects/TR5/Switch/tr5_raisingcog.cpp @@ -7,6 +7,9 @@ #include "sound.h" #include "spotcam.h" #include "objectslist.h" +#include "generic_switch.h" + +using namespace TEN::Entities::Switches; void InitialiseRaisingCog(short itemNumber) { @@ -29,7 +32,8 @@ void InitialiseRaisingCog(short itemNumber) if (currentItem->objectNumber == ID_PULLEY || currentItem->objectNumber == ID_TRIGGER_TRIGGERER) { currentItem->itemFlags[1] = 1; - PulleyItemNumber = itemNos[i]; + // FIXME: no more hardcoding! + //PulleyItemNumber = itemNos[i]; } } } diff --git a/TR5Main/Objects/TR5/Trap/tr5_explosion.cpp b/TR5Main/Objects/TR5/Trap/tr5_explosion.cpp index 792ead078..5b58bdf93 100644 --- a/TR5Main/Objects/TR5/Trap/tr5_explosion.cpp +++ b/TR5Main/Objects/TR5/Trap/tr5_explosion.cpp @@ -12,6 +12,9 @@ #include "lara_one_gun.h" #include "switch.h" #include "debris.h" +#include "generic_switch.h" + +using namespace TEN::Entities::Switches; void InitialiseExplosion(short itemNumber) { diff --git a/TR5Main/Objects/TR5/tr5_objects.cpp b/TR5Main/Objects/TR5/tr5_objects.cpp index 9791c054d..d86802341 100644 --- a/TR5Main/Objects/TR5/tr5_objects.cpp +++ b/TR5Main/Objects/TR5/tr5_objects.cpp @@ -50,6 +50,7 @@ #include "tr5_rollingball.h" #include "tr5_explosion.h" /// switch +#include "tr5_crowdove_switch.h" /// shatter #include "tr5_smashobject.h" @@ -67,6 +68,8 @@ /// register objects #include "object_helper.h" +using namespace TEN::Entities::TR5; + static void StartBaddy(OBJECT_INFO *obj) { obj = &Objects[ID_LARA]; @@ -1221,6 +1224,18 @@ static void StartSwitch(OBJECT_INFO *obj) obj->savePosition = true; obj->saveAnim = true; } + + obj = &Objects[ID_CROWDOVE_SWITCH]; + if (obj->loaded) + { + obj->initialise = InitialiseCrowDoveSwitch; + obj->collision = CrowDoveSwitchCollision; + obj->control = CrowDoveSwitchControl; + obj->hitEffect = HIT_RICOCHET; + obj->saveFlags = true; + obj->saveAnim = true; + obj->saveMesh = true; + } } static void StartShatter(OBJECT_INFO *obj) diff --git a/TR5Main/Renderer/Renderer11Draw.cpp b/TR5Main/Renderer/Renderer11Draw.cpp index d50221bc5..b1344e28a 100644 --- a/TR5Main/Renderer/Renderer11Draw.cpp +++ b/TR5Main/Renderer/Renderer11Draw.cpp @@ -2307,9 +2307,9 @@ namespace ten::renderer for (int m = 0; m < 32; m++) memcpy(&m_stItem.BonesMatrices[m], &Matrix::Identity, sizeof(Matrix)); - for (int i = 0; i < ten::entities::tr4::NUM_LITTLE_BETTLES; i++) + for (int i = 0; i < TEN::Entities::TR4::NUM_LITTLE_BETTLES; i++) { - SCARAB_INFO* beetle = &ten::entities::tr4::Scarabs[i]; + SCARAB_INFO* beetle = &TEN::Entities::TR4::Scarabs[i]; if (beetle->on) { @@ -2355,9 +2355,9 @@ namespace ten::renderer for (int m = 0; m < 32; m++) memcpy(&m_stItem.BonesMatrices[m], &Matrix::Identity, sizeof(Matrix)); - for (int i = 0; i < ten::entities::tr4::MAX_LOCUSTS; i++) + for (int i = 0; i < TEN::Entities::TR4::MAX_LOCUSTS; i++) { - LOCUST_INFO* locust = &ten::entities::tr4::Locusts[i]; + LOCUST_INFO* locust = &TEN::Entities::TR4::Locusts[i]; if (locust->on) { diff --git a/TR5Main/Specific/setup.cpp b/TR5Main/Specific/setup.cpp index 563895e00..1072917b0 100644 --- a/TR5Main/Specific/setup.cpp +++ b/TR5Main/Specific/setup.cpp @@ -31,11 +31,10 @@ /// register objects #include "object_helper.h" -extern byte SequenceUsed[6]; -extern byte SequenceResults[3][3][3]; -extern byte Sequences[3]; -extern byte CurrentSequence; -extern int NumRPickups; +#include "generic_switch.h" +#include "fullblock_switch.h" + +using namespace TEN::Entities::Switches; OBJECT_INFO Objects[ID_NUMBER_OBJECTS]; STATIC_INFO StaticObjects[MAX_STATICS]; @@ -163,63 +162,14 @@ void ObjectObjects() obj->saveMesh = true; } - obj = &Objects[ID_AIRLOCK_SWITCH]; + /*obj = &Objects[ID_AIRLOCK_SWITCH]; if (obj->loaded) { - obj->collision = ten::entities::switches::SwitchCollision; + obj->collision = TEN::Entities::Switches::SwitchCollision; obj->control = SwitchControl; obj->saveFlags = true; obj->saveAnim = true; - } - - obj = &Objects[ID_SEQUENCE_SWITCH1]; - if (obj->loaded) - { - obj->collision = FullBlockSwitchCollision; - obj->control = FullBlockSwitchControl; - obj->saveFlags = true; - obj->saveAnim = true; - } - - obj = &Objects[ID_SEQUENCE_SWITCH2]; - if (obj->loaded) - { - obj->collision = FullBlockSwitchCollision; - obj->control = FullBlockSwitchControl; - obj->saveFlags = true; - obj->saveAnim = true; - } - - obj = &Objects[ID_SEQUENCE_SWITCH3]; - if (obj->loaded) - { - obj->collision = FullBlockSwitchCollision; - obj->control = FullBlockSwitchControl; - obj->saveFlags = true; - obj->saveAnim = true; - } - - obj = &Objects[ID_PULLEY]; - if (obj->loaded) - { - obj->initialise = InitialisePulleySwitch; - obj->control = SwitchControl; - obj->collision = PulleyCollision; - obj->saveFlags = true; - obj->saveAnim = true; - } - - obj = &Objects[ID_CROWDOVE_SWITCH]; - if (obj->loaded) - { - obj->initialise = InitialiseCrowDoveSwitch; - obj->collision = CrowDoveSwitchCollision; - obj->control = CrowDoveSwitchControl; - obj->hitEffect = HIT_RICOCHET; - obj->saveFlags = true; - obj->saveAnim = true; - obj->saveMesh = true; - } + }*/ for (int objNum = ID_DOOR_TYPE1; objNum <= ID_CLOSED_DOOR6; objNum++) { @@ -601,7 +551,7 @@ void InitialiseSpecialEffects() NextDrip = 0; NextBlood = 0; WBRoom = -1; - ten::entities::tr4::ClearScarabs(); + TEN::Entities::TR4::ClearScarabs(); } void CustomObjects() diff --git a/TR5Main/TR5Main.vcxproj b/TR5Main/TR5Main.vcxproj index 92b8b8e30..445a87057 100644 --- a/TR5Main/TR5Main.vcxproj +++ b/TR5Main/TR5Main.vcxproj @@ -174,9 +174,13 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\" + + + + @@ -520,10 +524,14 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\" + + + + diff --git a/TR5Main/TR5Main.vcxproj.filters b/TR5Main/TR5Main.vcxproj.filters index 6230387a7..6431e87c7 100644 --- a/TR5Main/TR5Main.vcxproj.filters +++ b/TR5Main/TR5Main.vcxproj.filters @@ -1068,6 +1068,18 @@ File di intestazione + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + @@ -1961,6 +1973,18 @@ File di origine + + File di origine + + + File di origine + + + File di origine + + + File di origine +