summaryrefslogtreecommitdiffstats
path: root/src/vehicles/Cranes.h
blob: 0e134310411ab98f4fbb93ce9dc108552409ef17 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#include "common.h"

#include "World.h"

class CVehicle;
class CEntity;
class CObject;
class CBuilding;

class CCrane
{
public:
	enum CraneState {
		IDLE = 0,
		GOING_TOWARDS_TARGET = 1,
		LIFTING_TARGET = 2,
		GOING_TOWARDS_TARGET_ONLY_HEIGHT = 3,
		ROTATING_TARGET = 4,
		DROPPING_TARGET = 5
	};
	enum CraneStatus {
		NONE = 0,
		ACTIVATED = 1,
		DEACTIVATED = 2
	};
	CBuilding *m_pCraneEntity;
	CObject *m_pHook;
	int32 m_nAudioEntity;
	float m_fPickupX1;
	float m_fPickupX2;
	float m_fPickupY1;
	float m_fPickupY2;
	CVector m_vecDropoffTarget;
	float m_fDropoffHeading;
	float m_fPickupAngle;
	float m_fDropoffAngle;
	float m_fPickupDistance;
	float m_fDropoffDistance;
	float m_fPickupHeight;
	float m_fDropoffHeight;
	float m_fHookAngle;
	float m_fHookOffset;
	float m_fHookHeight;
	CVector m_vecHookInitPos;
	CVector m_vecHookCurPos;
	CVector2D m_vecHookVelocity;
	CVehicle *m_pVehiclePickedUp;
	uint32 m_nTimeForNextCheck;
	uint8 m_nCraneStatus;
	uint8 m_nCraneState;
	uint8 m_nVehiclesCollected;
	bool m_bIsCrusher;
	bool m_bIsMilitaryCrane;
	bool m_bWasMilitaryCrane;
	bool m_bIsTop;

	void Init(void) { memset(this, 0, sizeof(*this)); }
	void Update(void);
	bool RotateCarriedCarProperly(void);
	void FindCarInSectorList(CPtrList* pList);
	bool DoesCranePickUpThisCarType(uint32 mi);
	bool GoTowardsTarget(float fAngleToTarget, float fDistanceToTarget, float fTargetHeight, float fSpeedMultiplier = 1.0f);
	bool GoTowardsHeightTarget(float fTargetHeight, float fSpeedMultiplier = 1.0f);
	void FindParametersForTarget(float X, float Y, float Z, float* pAngle, float* pDistance, float* pHeight);
	void CalcHookCoordinates(float* pX, float* pY, float* pZ);
	void SetHookMatrix(void);

	float GetHeightToPickup() { return 4.0f + m_fPickupHeight + (m_bIsCrusher ? 4.5f : 0.0f); };
	float GetHeightToDropoff() { return m_bIsCrusher ? (2.0f + m_fDropoffHeight + 3.0f) : (2.0f + m_fDropoffHeight); }
	float GetHeightToPickupHeight() { return m_fPickupHeight + (m_bIsCrusher ? 7.0f : 4.0f); }
	float GetHeightToDropoffHeight() { return m_fDropoffHeight + (m_bIsCrusher ? 7.0f : 2.0f); }
};

VALIDATE_SIZE(CCrane, 128);

class CCranes
{
public:
	static void InitCranes(void);
	static void AddThisOneCrane(CEntity* pCraneEntity);
	static void ActivateCrane(float fInfX, float fSupX, float fInfY, float fSupY, float fDropOffX, float fDropOffY, float fDropOffZ, float fHeading, bool bIsCrusher, bool bIsMilitary, float fPosX, float fPosY);
	static void DeActivateCrane(float fX, float fY);
	static bool IsThisCarPickedUp(float fX, float fY, CVehicle* pVehicle);
	static void UpdateCranes(void);
	static bool DoesMilitaryCraneHaveThisOneAlready(uint32 mi);
	static void RegisterCarForMilitaryCrane(uint32 mi);
	static bool HaveAllCarsBeenCollectedByMilitaryCrane(void);
	static bool IsThisCarBeingCarriedByAnyCrane(CVehicle* pVehicle);
	static bool IsThisCarBeingTargettedByAnyCrane(CVehicle* pVehicle);
	static void Save(uint8* buf, uint32* size);
	static void Load(uint8* buf, uint32 size); // on mobile it's CranesLoad outside of the class

	static uint32 CarsCollectedMilitaryCrane;
	static int32 NumCranes;
	static CCrane aCranes[NUM_CRANES];
};