TombEngine/TR5Main/Objects/Generic/Switches/crowbar_switch.cpp

157 lines
3.4 KiB
C++
Raw Normal View History

#include "framework.h"
2021-09-08 06:10:38 +02:00
#include "generic_switch.h"
#include "input.h"
#include "lara.h"
#include "crowbar_switch.h"
2021-11-16 15:51:50 +03:00
#include "gui.h"
#include "Sound/sound.h"
#include "pickup.h"
Merge branch 'master' into item_data # Conflicts: # TR5Main/Game/Lara/lara.cpp # TR5Main/Game/Lara/lara_collide.cpp # TR5Main/Game/Lara/lara_monkey.cpp # TR5Main/Game/Lara/lara_struct.h # TR5Main/Game/Lara/lara_tests.cpp # TR5Main/Game/collide.h # TR5Main/Game/control.h # TR5Main/Game/effect.h # TR5Main/Game/effect2.cpp # TR5Main/Game/flipeffect.cpp # TR5Main/Game/floordata.h # TR5Main/Game/hair.cpp # TR5Main/Game/health.cpp # TR5Main/Game/items.cpp # TR5Main/Game/newinv2.cpp # TR5Main/Game/spotcam.cpp # TR5Main/Objects/Effects/tr4_bubbles.cpp # TR5Main/Objects/TR1/Entity/tr1_ape.cpp # TR5Main/Objects/TR1/Entity/tr1_bigrat.cpp # TR5Main/Objects/TR1/Entity/tr1_doppelganger.cpp # TR5Main/Objects/TR2/Entity/tr2_birdmonster.cpp # TR5Main/Objects/TR2/Entity/tr2_shark.cpp # TR5Main/Objects/TR2/Entity/tr2_spider.cpp # TR5Main/Objects/TR2/Entity/tr2_yeti.cpp # TR5Main/Objects/TR3/Entity/tr3_fishemitter.cpp # TR5Main/Objects/TR3/Entity/tr3_flamethrower.cpp # TR5Main/Objects/TR3/Entity/tr3_monkey.cpp # TR5Main/Objects/TR3/Entity/tr3_raptor.cpp # TR5Main/Objects/TR3/Entity/tr3_scuba.cpp # TR5Main/Objects/TR3/Entity/tr3_trex.cpp # TR5Main/Objects/TR3/Vehicles/kayak.cpp # TR5Main/Objects/TR3/Vehicles/minecart.cpp # TR5Main/Objects/TR4/Entity/tr4_bat.cpp # TR5Main/Objects/TR4/Entity/tr4_big_beetle.cpp # TR5Main/Objects/TR4/Entity/tr4_bigscorpion.cpp # TR5Main/Objects/TR4/Entity/tr4_demigod.cpp # TR5Main/Objects/TR4/Entity/tr4_dog.cpp # TR5Main/Objects/TR4/Entity/tr4_hammerhead.cpp # TR5Main/Objects/TR4/Entity/tr4_harpy.cpp # TR5Main/Objects/TR4/Entity/tr4_mutant.cpp # TR5Main/Objects/TR4/Entity/tr4_smallscorpion.cpp # TR5Main/Objects/TR4/Entity/tr4_troops.cpp # TR5Main/Objects/TR4/Entity/tr4_wildboar.cpp # TR5Main/Objects/TR4/Trap/tr4_joby_spikes.cpp # TR5Main/Objects/TR4/Vehicles/motorbike.cpp # TR5Main/Objects/TR5/Entity/tr5_doberman.cpp # TR5Main/Objects/TR5/Entity/tr5_imp.cpp # TR5Main/Objects/TR5/Entity/tr5_larson.cpp # TR5Main/Objects/TR5/Entity/tr5_lion.cpp # TR5Main/Objects/TR5/Entity/tr5_reaper.cpp # TR5Main/Objects/TR5/Object/tr5_pushableblock.cpp # TR5Main/Objects/TR5/Object/tr5_rollingball.cpp # TR5Main/Objects/TR5/Trap/tr5_fallingceiling.cpp # TR5Main/Renderer/Renderer11Draw2D.cpp # TR5Main/Specific/input.cpp # TR5Main/Specific/level.cpp # TR5Main/TombEngine.vcxproj.filters
2021-08-31 17:37:15 +02:00
#include "level.h"
#include "collide.h"
#include "animation.h"
2021-09-25 16:00:30 +03:00
#include "items.h"
2021-09-25 11:27:47 +02:00
2021-08-28 06:37:22 +02:00
namespace TEN::Entities::Switches
{
PHD_VECTOR CrowbarPos = { -89, 0, -328 };
OBJECT_COLLISION_BOUNDS CrowbarBounds =
{
-256, 256,
0, 0,
-512, -256,
-ANGLE(10), ANGLE(10),
-ANGLE(30), ANGLE(30),
-ANGLE(10), ANGLE(10)
};
PHD_VECTOR CrowbarPos2 = { 89, 0, 328 };
OBJECT_COLLISION_BOUNDS CrowbarBounds2 =
{
-256, 256,
0, 0,
256, 512,
-ANGLE(10), ANGLE(10),
-ANGLE(30), ANGLE(30),
-ANGLE(10), ANGLE(10)
};
void CrowbarSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll)
{
int doSwitch = 0;
ITEM_INFO* item = &g_Level.Items[itemNum];
2021-11-16 15:51:50 +03:00
if ((((TrInput & IN_ACTION) || g_Gui.GetInventoryItemChosen() == ID_CROWBAR_ITEM)
2021-09-08 06:10:38 +02:00
&& l->currentAnimState == LS_STOP
&& l->animNumber == LA_STAND_IDLE
&& Lara.gunStatus == LG_NO_ARMS
&& item->itemFlags[0] == 0)
|| (Lara.isMoving && Lara.interactedItem == itemNum))
{
2021-09-08 06:10:38 +02:00
if (item->currentAnimState == SWITCH_ON)
{
2021-09-08 06:10:38 +02:00
l->pos.yRot ^= (short)ANGLE(180);
2021-09-08 06:10:38 +02:00
if (TestLaraPosition(&CrowbarBounds2, item, l))
{
2021-11-16 15:51:50 +03:00
if (Lara.isMoving || g_Gui.GetInventoryItemChosen() == ID_CROWBAR_ITEM)
{
2021-09-08 06:10:38 +02:00
if (MoveLaraPosition(&CrowbarPos2, item, l))
{
doSwitch = 1;
l->animNumber = LA_CROWBAR_USE_ON_FLOOR;
l->frameNumber = g_Level.Anims[l->animNumber].frameBase;
item->goalAnimState = SWITCH_OFF;
}
else
{
Lara.interactedItem = itemNum;
2021-09-08 06:10:38 +02:00
}
2021-10-12 00:26:46 -05:00
2021-11-16 15:51:50 +03:00
g_Gui.SetInventoryItemChosen(NO_ITEM);
}
else
{
2021-09-08 06:10:38 +02:00
doSwitch = -1;
}
}
else if (Lara.isMoving && Lara.interactedItem == itemNum)
{
2021-09-08 06:10:38 +02:00
Lara.isMoving = false;
Lara.gunStatus = LG_NO_ARMS;
}
2021-09-08 06:10:38 +02:00
l->pos.yRot ^= (short)ANGLE(180);
}
2021-09-08 06:10:38 +02:00
else
{
2021-09-08 06:10:38 +02:00
if (TestLaraPosition(&CrowbarBounds, item, l))
{
2021-11-16 15:51:50 +03:00
if (Lara.isMoving || g_Gui.GetInventoryItemChosen() == ID_CROWBAR_ITEM)
2021-09-08 06:10:38 +02:00
{
if (MoveLaraPosition(&CrowbarPos, item, l))
{
doSwitch = 1;
l->animNumber = LA_CROWBAR_USE_ON_FLOOR;
l->frameNumber = g_Level.Anims[l->animNumber].frameBase;
item->goalAnimState = SWITCH_ON;
}
else
{
Lara.interactedItem = itemNum;
2021-09-08 06:10:38 +02:00
}
2021-10-12 00:26:46 -05:00
2021-11-16 15:51:50 +03:00
g_Gui.SetInventoryItemChosen(NO_ITEM);
2021-09-08 06:10:38 +02:00
}
else
{
doSwitch = -1;
}
}
else if (Lara.isMoving && Lara.interactedItem == itemNum)
{
Lara.isMoving = false;
Lara.gunStatus = LG_NO_ARMS;
}
}
2021-09-08 06:10:38 +02:00
}
2021-09-08 06:10:38 +02:00
if (doSwitch)
{
if (doSwitch == -1)
{
if (Lara.Crowbar)
2021-11-16 15:51:50 +03:00
g_Gui.SetEnterInventory(ID_CROWBAR_ITEM);
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();
}
}
}
else
{
2021-09-08 06:10:38 +02:00
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);
}
}
else
{
2021-09-08 06:10:38 +02:00
ObjectCollision(itemNum, l, coll);
}
}
}