diff --git a/TR5Main/Game/door.cpp b/TR5Main/Game/door.cpp index 8bef01a7e..8e91640d3 100644 --- a/TR5Main/Game/door.cpp +++ b/TR5Main/Game/door.cpp @@ -17,7 +17,7 @@ #include "input.h" #include "sound.h" #include "trmath.h" - +#include "cog_switch.h" PHD_VECTOR DoubleDoorPos(0, 0, 220); PHD_VECTOR PullDoorPos(-201, 0, 322); @@ -458,7 +458,7 @@ void DoorControl(short itemNumber) { BOUNDING_BOX* bounds = GetBoundsAccurate(item); --item->itemFlags[0]; - item->pos.yPos -= 12; + item->pos.yPos -= ten::entities::switches::COG_DOOR_SPEED; int y = bounds->Y1 + item->itemFlags[2] - STEP_SIZE; if (item->pos.yPos < y) { @@ -491,7 +491,6 @@ void DoorControl(short itemNumber) } } } - return; } if (item->objectNumber < ID_LIFT_DOORS1 || item->objectNumber > ID_LIFT_DOORS2) diff --git a/TR5Main/Game/switch.cpp b/TR5Main/Game/switch.cpp index 48cf58491..29e23c6c9 100644 --- a/TR5Main/Game/switch.cpp +++ b/TR5Main/Game/switch.cpp @@ -28,12 +28,7 @@ extern PHD_VECTOR OldPickupPos; #ifndef NEW_INV extern Inventory g_Inventory; #endif -static PHD_VECTOR CogSwitchPos(0, 0, -856); -OBJECT_COLLISION_BOUNDS CogSwitchBounds = -{ - 0xFE00, 0x0200, 0x0000, 0x0000, 0xFA00, 0xFE00, 0xF8E4, 0x071C, 0xEAAC, 0x1554, - 0xF8E4, 0x071C -}; + OBJECT_COLLISION_BOUNDS Switch2Bounds = { 0xFC00, 0x0400, 0xFC00, 0x0400, 0xFC00, 0x0200, 0xC720, 0x38E0, 0xC720, 0x38E0, @@ -1332,126 +1327,3 @@ void ShootSwitchCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* coll) if (item->objectNumber == ID_SHOOT_SWITCH1 && !(item->meshBits & 1)) item->status = ITEM_INVISIBLE; } - -void CogSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) -{ - ITEM_INFO* item = &g_Level.Items[itemNum]; - - 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) - { - ObjectCollision(itemNum, l, coll); - return; - } - - short* trigger = TriggerIndex; - for (int i = *TriggerIndex; (i & 0x1F) != 4; trigger++) - { - if (i < 0) - break; - i = trigger[1]; - } - - ITEM_INFO* target = &g_Level.Items[trigger[3] & 0x3FF]; - DOOR_DATA* door = (DOOR_DATA*)target->data; - - if (item->status == ITEM_NOT_ACTIVE) - { - if (!(item->flags & 0x100) - && (TrInput & IN_ACTION - && !Lara.gunStatus - && !item->gravityStatus - && l->currentAnimState == LS_STOP - && l->animNumber == LA_STAND_IDLE - || Lara.isMoving - && Lara.generalPtr == (void*)itemNum)) - { - if (TestLaraPosition(&CogSwitchBounds, item, l)) - { - if (MoveLaraPosition(&CogSwitchPos, item, l)) - { - Lara.isMoving = false; - Lara.headYrot = 0; - Lara.headXrot = 0; - Lara.torsoYrot = 0; - Lara.torsoXrot = 0; - Lara.gunStatus = LG_HANDS_BUSY; - Lara.generalPtr = target; - item->goalAnimState = 1; - item->status = ITEM_ACTIVE; - l->animNumber = LA_COGWHEEL_GRAB; - l->goalAnimState = LS_COGWHEEL; - l->currentAnimState = LS_COGWHEEL; - l->frameNumber = g_Level.Anims[l->animNumber].frameBase; - - AddActiveItem(itemNum); - if (door != NULL) - { - if (!door->opened) - { - AddActiveItem((target - g_Level.Items.data())); - target->itemFlags[2] = target->pos.yPos; - target->status = ITEM_ACTIVE; - } - } - } - else - { - Lara.generalPtr = (void*)itemNum; - } - return; - } - if (Lara.isMoving && Lara.generalPtr == (void*)itemNum) - { - Lara.isMoving = false; - Lara.gunStatus = LG_NO_ARMS; - } - } - - ObjectCollision(itemNum, l, coll); - } -} - -void CogSwitchControl(short itemNumber) -{ - ITEM_INFO* item = &g_Level.Items[itemNumber]; - - AnimateItem(item); - - if (item->currentAnimState == 1) - { - if (item->goalAnimState == 1 && !(TrInput & IN_ACTION)) - { - LaraItem->goalAnimState = LS_STOP; - item->goalAnimState = 0; - } - - if (LaraItem->animNumber == LA_COGWHEEL_PULL) - { - if (LaraItem->frameNumber == g_Level.Anims[LA_COGWHEEL_PULL].frameBase + 10) - { - ITEM_INFO* it = (ITEM_INFO*)Lara.generalPtr; - it->itemFlags[0] = 40; - Lara.generalPtr = (ITEM_INFO*)it; - } - } - } - else - { - if (item->frameNumber == g_Level.Anims[item->animNumber].frameEnd) - { - item->currentAnimState = 0; - item->status = ITEM_NOT_ACTIVE; - - RemoveActiveItem(itemNumber); - - LaraItem->animNumber = LA_STAND_SOLID; - LaraItem->frameNumber = g_Level.Anims[item->animNumber].frameBase; - LaraItem->goalAnimState = LS_STOP; - LaraItem->currentAnimState = LS_STOP; - Lara.gunStatus = LG_NO_ARMS; - } - } -} diff --git a/TR5Main/Game/switch.h b/TR5Main/Game/switch.h index 2c8f2675a..fa3348c61 100644 --- a/TR5Main/Game/switch.h +++ b/TR5Main/Game/switch.h @@ -6,8 +6,6 @@ extern int PulleyItemNumber; void CrowDoveSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); void CrowDoveSwitchControl(short itemNumber); -void CogSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); -void CogSwitchControl(short itemNum); void FullBlockSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); void FullBlockSwitchControl(short itemNumber); void CrowbarSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); diff --git a/TR5Main/Objects/Generic/Switches/cog_switch.cpp b/TR5Main/Objects/Generic/Switches/cog_switch.cpp new file mode 100644 index 000000000..805ac89e1 --- /dev/null +++ b/TR5Main/Objects/Generic/Switches/cog_switch.cpp @@ -0,0 +1,143 @@ +#include "framework.h" +#include "cog_switch.h" +#include +#include +#include +#include + +namespace ten::entities::switches +{ + PHD_VECTOR CogSwitchPos(0, 0, -856); + + OBJECT_COLLISION_BOUNDS CogSwitchBounds = + { + -512, 512, + 0, 0, + -1536, -512, + -ANGLE(10), ANGLE(10), + -ANGLE(30), ANGLE(30), + -ANGLE(10), ANGLE(10) + }; + + void CogSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) + { + ITEM_INFO* item = &g_Level.Items[itemNum]; + + 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) + { + ObjectCollision(itemNum, l, coll); + return; + } + + short* trigger = TriggerIndex; + for (int i = *TriggerIndex; (i & 0x1F) != 4; trigger++) + { + if (i < 0) + break; + i = trigger[1]; + } + + ITEM_INFO* target = &g_Level.Items[trigger[3] & 0x3FF]; + DOOR_DATA* door = (DOOR_DATA*)target->data; + + if (item->status == ITEM_NOT_ACTIVE) + { + if (!(item->flags & ONESHOT) + && (TrInput & IN_ACTION + && !Lara.gunStatus + && !item->gravityStatus + && l->currentAnimState == LS_STOP + && l->animNumber == LA_STAND_IDLE + || Lara.isMoving + && Lara.generalPtr == (void*)itemNum)) + { + if (TestLaraPosition(&CogSwitchBounds, item, l)) + { + if (MoveLaraPosition(&CogSwitchPos, item, l)) + { + Lara.isMoving = false; + Lara.headYrot = 0; + Lara.headXrot = 0; + Lara.torsoYrot = 0; + Lara.torsoXrot = 0; + Lara.gunStatus = LG_HANDS_BUSY; + Lara.generalPtr = target; + l->animNumber = LA_COGWHEEL_GRAB; + l->goalAnimState = LS_COGWHEEL; + l->currentAnimState = LS_COGWHEEL; + l->frameNumber = g_Level.Anims[l->animNumber].frameBase; + + AddActiveItem(itemNum); + item->goalAnimState = 1; + item->status = ITEM_ACTIVE; + + if (door != NULL) + { + if (!door->opened) + { + AddActiveItem((target - g_Level.Items.data())); + target->itemFlags[2] = target->pos.yPos; + target->status = ITEM_ACTIVE; + } + } + } + else + { + Lara.generalPtr = (void*)itemNum; + } + return; + } + else if (Lara.isMoving && Lara.generalPtr == (void*)itemNum) + { + Lara.isMoving = false; + Lara.gunStatus = LG_NO_ARMS; + } + } + + ObjectCollision(itemNum, l, coll); + } + } + + void CogSwitchControl(short itemNumber) + { + ITEM_INFO* item = &g_Level.Items[itemNumber]; + + AnimateItem(item); + + if (item->currentAnimState == 1) + { + if (item->goalAnimState == 1 && !(TrInput & IN_ACTION)) + { + LaraItem->goalAnimState = LS_STOP; + item->goalAnimState = 0; + } + + if (LaraItem->animNumber == LA_COGWHEEL_PULL) + { + if (LaraItem->frameNumber == g_Level.Anims[LaraItem->animNumber].frameBase + 10) + { + ((ITEM_INFO*)Lara.generalPtr)->itemFlags[0] = COG_DOOR_TURN; + } + } + } + else + { + if (item->frameNumber == g_Level.Anims[item->animNumber].frameEnd) + { + item->currentAnimState = 0; + item->status = ITEM_NOT_ACTIVE; + + RemoveActiveItem(itemNumber); + + LaraItem->animNumber = LA_STAND_SOLID; + LaraItem->frameNumber = g_Level.Anims[LaraItem->animNumber].frameBase; + LaraItem->goalAnimState = LS_STOP; + LaraItem->currentAnimState = LS_STOP; + Lara.gunStatus = LG_NO_ARMS; + } + } + } +} \ No newline at end of file diff --git a/TR5Main/Objects/Generic/Switches/cog_switch.h b/TR5Main/Objects/Generic/Switches/cog_switch.h new file mode 100644 index 000000000..566092587 --- /dev/null +++ b/TR5Main/Objects/Generic/Switches/cog_switch.h @@ -0,0 +1,13 @@ +#pragma once + +#include "items.h" +#include + +namespace ten::entities::switches +{ + constexpr auto COG_DOOR_TURN = 40; + constexpr auto COG_DOOR_SPEED = 12; + + void CogSwitchControl(short itemNumber); + void CogSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); +} \ No newline at end of file diff --git a/TR5Main/Objects/Generic/generic_objects.cpp b/TR5Main/Objects/Generic/generic_objects.cpp index eb03c7d45..9929f3a56 100644 --- a/TR5Main/Objects/Generic/generic_objects.cpp +++ b/TR5Main/Objects/Generic/generic_objects.cpp @@ -1,13 +1,18 @@ #include "framework.h" #include "generic_objects.h" -/// objects +// objects #include "generic_trapdoor.h" #include "generic_bridge.h" +// switches +#include "cog_switch.h" + /// necessary import #include "setup.h" +using namespace ten::entities::switches; + static void StartObject() { auto obj = &Objects[ID_TRAPDOOR1]; @@ -159,7 +164,23 @@ static void StartObject() } } +void StartSwitches() +{ + OBJECT_INFO* obj; + + obj = &Objects[ID_COG_SWITCH]; + if (obj->loaded) + { + obj->collision = CogSwitchCollision; + obj->control = CogSwitchControl; + obj->hitEffect = HIT_RICOCHET; + obj->saveFlags = true; + obj->saveAnim = true; + } +} + void InitialiseGenericObjects() { StartObject(); + StartSwitches(); } diff --git a/TR5Main/Objects/TR5/tr5_objects.cpp b/TR5Main/Objects/TR5/tr5_objects.cpp index ef6cf0862..9791c054d 100644 --- a/TR5Main/Objects/TR5/tr5_objects.cpp +++ b/TR5Main/Objects/TR5/tr5_objects.cpp @@ -1211,16 +1211,6 @@ static void StartTrap(OBJECT_INFO *obj) static void StartSwitch(OBJECT_INFO *obj) { - obj = &Objects[ID_COG_SWITCH]; - if (obj->loaded) - { - obj->collision = CogSwitchCollision; - obj->control = CogSwitchControl; - obj->hitEffect = HIT_RICOCHET; - obj->saveFlags = true; - obj->saveAnim = true; - } - obj = &Objects[ID_RAISING_COG]; if (obj->loaded) { diff --git a/TR5Main/TR5Main.vcxproj b/TR5Main/TR5Main.vcxproj index b619c92c2..79938b2c6 100644 --- a/TR5Main/TR5Main.vcxproj +++ b/TR5Main/TR5Main.vcxproj @@ -66,7 +66,7 @@ true _CRT_SECURE_NO_WARNINGS;WIN32;TR5MAIN_EXPORTS;_WINDOWS;_USRDLL;NOMINMAX;NEW_INV;%(PreprocessorDefinitions) false - $(SolutionDir)TR5Main;$(SolutionDir)TR5Main\Game;$(SolutionDir)TR5Main\Game\Lara;$(SolutionDir)TR5Main\Objects;$(SolutionDir)TR5Main\Objects\Utils;$(SolutionDir)TR5Main\Objects\Effects;$(SolutionDir)TR5Main\Objects\Generic;$(SolutionDir)TR5Main\Objects\Generic\Object;$(SolutionDir)TR5Main\Objects\TR1;$(SolutionDir)TR5Main\Objects\TR1\Entity;$(SolutionDir)TR5Main\Objects\TR1\Trap;$(SolutionDir)TR5Main\Objects\TR2;$(SolutionDir)TR5Main\Objects\TR2\Entity;$(SolutionDir)TR5Main\Objects\TR2\Trap;$(SolutionDir)TR5Main\Objects\TR2\Vehicles;$(SolutionDir)TR5Main\Objects\TR3;$(SolutionDir)TR5Main\Objects\TR3\Entity;$(SolutionDir)TR5Main\Objects\TR3\Trap;$(SolutionDir)TR5Main\Objects\TR3\Vehicles;$(SolutionDir)TR5Main\Objects\TR4;$(SolutionDir)TR5Main\Objects\TR4\Entity;$(SolutionDir)TR5Main\Objects\TR4\Trap;$(SolutionDir)TR5Main\Objects\TR4\Object;$(SolutionDir)TR5Main\Objects\TR4\Floor;$(SolutionDir)TR5Main\Objects\TR4\Switch;$(SolutionDir)TR5Main\Objects\TR4\Vehicles;$(SolutionDir)TR5Main\Objects\TR5;$(SolutionDir)TR5Main\Objects\TR5\Entity;$(SolutionDir)TR5Main\Objects\TR5\Trap;$(SolutionDir)TR5Main\Objects\TR5\Light;$(SolutionDir)TR5Main\Objects\TR5\Emitter;$(SolutionDir)TR5Main\Objects\TR5\Shatter;$(SolutionDir)TR5Main\Objects\TR5\Switch;$(SolutionDir)TR5Main\Objects\TR5\Object;$(SolutionDir)TR5Main\Objects\Vehicles;$(SolutionDir)TR5Main\Renderer;$(SolutionDir)TR5Main\Scripting;$(SolutionDir)TR5Main\Specific;$(SolutionDir)TR5Main\Specific\IO;%(AdditionalIncludeDirectories) + $(SolutionDir)TR5Main;$(SolutionDir)TR5Main\Game;$(SolutionDir)TR5Main\Game\Lara;$(SolutionDir)TR5Main\Objects;$(SolutionDir)TR5Main\Objects\Utils;$(SolutionDir)TR5Main\Objects\Effects;$(SolutionDir)TR5Main\Objects\Generic;$(SolutionDir)TR5Main\Objects\Generic\Object;$(SolutionDir)TR5Main\Objects\TR1;$(SolutionDir)TR5Main\Objects\TR1\Entity;$(SolutionDir)TR5Main\Objects\TR1\Trap;$(SolutionDir)TR5Main\Objects\TR2;$(SolutionDir)TR5Main\Objects\TR2\Entity;$(SolutionDir)TR5Main\Objects\TR2\Trap;$(SolutionDir)TR5Main\Objects\TR2\Vehicles;$(SolutionDir)TR5Main\Objects\TR3;$(SolutionDir)TR5Main\Objects\TR3\Entity;$(SolutionDir)TR5Main\Objects\TR3\Trap;$(SolutionDir)TR5Main\Objects\TR3\Vehicles;$(SolutionDir)TR5Main\Objects\TR4;$(SolutionDir)TR5Main\Objects\TR4\Entity;$(SolutionDir)TR5Main\Objects\TR4\Trap;$(SolutionDir)TR5Main\Objects\TR4\Object;$(SolutionDir)TR5Main\Objects\TR4\Floor;$(SolutionDir)TR5Main\Objects\TR4\Switch;$(SolutionDir)TR5Main\Objects\TR4\Vehicles;$(SolutionDir)TR5Main\Objects\TR5;$(SolutionDir)TR5Main\Objects\TR5\Entity;$(SolutionDir)TR5Main\Objects\TR5\Trap;$(SolutionDir)TR5Main\Objects\TR5\Light;$(SolutionDir)TR5Main\Objects\TR5\Emitter;$(SolutionDir)TR5Main\Objects\TR5\Shatter;$(SolutionDir)TR5Main\Objects\TR5\Switch;$(SolutionDir)TR5Main\Objects\TR5\Object;$(SolutionDir)TR5Main\Objects\Generic\Switches;$(SolutionDir)TR5Main\Objects\Vehicles;$(SolutionDir)TR5Main\Renderer;$(SolutionDir)TR5Main\Scripting;$(SolutionDir)TR5Main\Specific;$(SolutionDir)TR5Main\Specific\IO;%(AdditionalIncludeDirectories) MultiThreadedDebugDLL false true @@ -172,6 +172,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\" + @@ -513,6 +514,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\" + diff --git a/TR5Main/TR5Main.vcxproj.filters b/TR5Main/TR5Main.vcxproj.filters index c496b3aca..696a275f1 100644 --- a/TR5Main/TR5Main.vcxproj.filters +++ b/TR5Main/TR5Main.vcxproj.filters @@ -1053,6 +1053,9 @@ File di intestazione + + File di intestazione + @@ -1928,6 +1931,9 @@ File di origine + + File di origine +