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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
#include "common.h"
#include "Bridge.h"
#include "Pools.h"
#include "ModelIndices.h"
#include "PathFind.h"
#include "Stats.h"
//--LCS: file done except TODO
CEntity *CBridge::pLiftRoad;
CEntity *CBridge::pLiftPart;
CEntity *CBridge::pWeight;
int CBridge::State;
int CBridge::OldState;
float CBridge::DefaultZLiftPart;
float CBridge::DefaultZLiftRoad;
float CBridge::DefaultZLiftWeight;
float CBridge::OldLift;
uint32 CBridge::TimeOfBridgeBecomingOperational;
void CBridge::Init()
{
#ifdef GTA_BRIDGE
FindBridgeEntities();
State = STATE_BRIDGE_LOCKED;
OldLift = -1.0f;
if (pLiftPart && pWeight)
{
DefaultZLiftPart = pLiftPart->GetPosition().z;
if (pLiftRoad)
DefaultZLiftRoad = pLiftRoad->GetPosition().z;
DefaultZLiftWeight = pWeight->GetPosition().z;
ThePaths.SetLinksBridgeLights(-330.0, -230.0, -700.0, -588.0, true);
}
#endif
}
void CBridge::Update()
{
#ifdef GTA_BRIDGE
if (!pLiftPart || !pWeight)
return;
OldState = State;
float liftHeight;
if (State == STATE_BRIDGE_LOCKED) {
liftHeight = 25.0f;
TimeOfBridgeBecomingOperational = 0;
}
else if (State == STATE_BRIDGE_ALWAYS_UNLOCKED) {
liftHeight = 0.0f;
TimeOfBridgeBecomingOperational = CTimer::GetTimeInMilliseconds() - 20001;
}
else {
if (TimeOfBridgeBecomingOperational == 0)
TimeOfBridgeBecomingOperational = CTimer::GetTimeInMilliseconds();
// Time remaining for bridge to become operational
// this time cycle duration is 0x20000, so ~2:11
uint32 timeElapsed = (CTimer::GetTimeInMilliseconds() - TimeOfBridgeBecomingOperational) % 0x20000;
// Calculate lift part height and bridge state
if (timeElapsed < 20000)
{
State = STATE_LIFT_PART_MOVING_DOWN;
liftHeight = 25.0f - timeElapsed / 20000.0f * 25.0f;
}
else if (timeElapsed < 80000)
{
liftHeight = 0.0f;
State = STATE_LIFT_PART_IS_DOWN;
}
else if (timeElapsed < 90000)
{
liftHeight = 0.0f;
State = STATE_LIFT_PART_ABOUT_TO_MOVE_UP;
}
else if (timeElapsed < 110000)
{
State = STATE_LIFT_PART_MOVING_UP;
liftHeight = (timeElapsed - 90000) / 20000.0f * 25.0f;
}
else
{
liftHeight = 25.0f;
State = STATE_LIFT_PART_IS_UP;
}
}
// Move bridge part
if (liftHeight != OldLift)
{
pLiftPart->GetMatrix().GetPosition().z = DefaultZLiftPart + liftHeight;
pLiftPart->GetMatrix().UpdateRW();
pLiftPart->UpdateRwFrame();
if (pLiftRoad)
{
pLiftRoad->GetMatrix().GetPosition().z = DefaultZLiftRoad + liftHeight;
pLiftRoad->GetMatrix().UpdateRW();
pLiftRoad->UpdateRwFrame();
}
pWeight->GetMatrix().GetPosition().z = DefaultZLiftWeight - liftHeight;
pWeight->GetMatrix().UpdateRW();
pWeight->UpdateRwFrame();
OldLift = liftHeight;
}
// TODO(LCS): cWorldStream
if (State == STATE_LIFT_PART_ABOUT_TO_MOVE_UP && OldState == STATE_LIFT_PART_IS_DOWN)
ThePaths.SetLinksBridgeLights(-330.0, -230.0, -700.0, -588.0, true);
else if (State == STATE_LIFT_PART_IS_DOWN && OldState == STATE_LIFT_PART_MOVING_DOWN)
ThePaths.SetLinksBridgeLights(-330.0, -230.0, -700.0, -588.0, false);
#endif
}
bool CBridge::ShouldLightsBeFlashing()
{
#ifdef GTA_BRIDGE
return State != STATE_LIFT_PART_IS_DOWN;
#else
return false;
#endif
}
void CBridge::FindBridgeEntities()
{
#ifdef GTA_BRIDGE
pWeight = nil;
pLiftRoad = nil;
pLiftPart = nil;
for (int i = CPools::GetBuildingPool()->GetSize()-1; i >= 0; i--) {
CBuilding* entry = CPools::GetBuildingPool()->GetSlot(i);
if (entry)
{
if (entry->GetModelIndex() == MI_BRIDGELIFT)
pLiftPart = entry;
else if (entry->GetModelIndex() == MI_BRIDGEROADSEGMENT)
pLiftRoad = entry;
else if (entry->GetModelIndex() == MI_BRIDGEWEIGHT)
pWeight = entry;
}
}
#endif
}
bool CBridge::ThisIsABridgeObjectMovingUp(int index)
{
#ifdef GTA_BRIDGE
if (index != MI_BRIDGEROADSEGMENT && index != MI_BRIDGELIFT)
return false;
return State == STATE_LIFT_PART_ABOUT_TO_MOVE_UP || State == STATE_LIFT_PART_MOVING_UP;
#else
return false;
#endif
}
void CBridge::ForceBridgeState(uint8 state)
{
#ifdef GTA_BRIDGE
State = state;
switch (state)
{
case STATE_BRIDGE_LOCKED:
case STATE_LIFT_PART_MOVING_DOWN:
case STATE_LIFT_PART_ABOUT_TO_MOVE_UP:
ThePaths.SetLinksBridgeLights(-330.0f, -230.0f, -700.0f, -588.0f, true);
break;
case STATE_BRIDGE_ALWAYS_UNLOCKED:
ThePaths.SetLinksBridgeLights(-330.0f, -230.0f, -700.0f, -588.0f, false);
break;
default:
break;
}
#endif
}
|