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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
#include "common.h"
#include "Pools.h"
#include "ModelIndices.h"
#include "World.h"
#include "Wanted.h"
#include "EventList.h"
#include "Messages.h"
#include "Text.h"
#include "main.h"
#include "Accident.h"
// --MIAMI: file done
int32 CEventList::ms_nFirstFreeSlotIndex;
CEvent gaEvent[NUMEVENTS];
enum
{
EVENT_STATE_0,
EVENT_STATE_CANDELETE,
EVENT_STATE_CLEAR,
};
void
CEventList::Initialise(void)
{
int i;
debug("Initialising CEventList...");
for(i = 0; i < NUMEVENTS; i++){
gaEvent[i].type = EVENT_NULL;
gaEvent[i].entityType = EVENT_ENTITY_NONE;
gaEvent[i].entityRef = 0;
gaEvent[i].posn.x = 0.0f;
gaEvent[i].posn.y = 0.0f;
gaEvent[i].posn.z = 0.0f;
gaEvent[i].timeout = 0;
gaEvent[i].state = EVENT_STATE_0;
}
ms_nFirstFreeSlotIndex = 0;
}
void
CEventList::Update(void)
{
int i;
ms_nFirstFreeSlotIndex = 0;
for(i = 0; i < NUMEVENTS; i++){
if(gaEvent[i].type == EVENT_NULL)
continue;
if(CTimer::GetTimeInMilliseconds() > gaEvent[i].timeout || gaEvent[i].state == EVENT_STATE_CANDELETE){
gaEvent[i].type = EVENT_NULL;
gaEvent[i].state = EVENT_STATE_0;
}
if(gaEvent[i].state == EVENT_STATE_CLEAR)
gaEvent[i].state = EVENT_STATE_CANDELETE;
}
}
void
CEventList::RegisterEvent(eEventType type, eEventEntity entityType, CEntity *ent, CPed *criminal, int32 timeout)
{
int i;
int ref;
bool copsDontCare;
#ifdef SQUEEZE_PERFORMANCE
if (type == EVENT_INJURED_PED) {
gAccidentManager.ReportAccident((CPed*)ent);
return;
}
#endif
copsDontCare = false;
switch(entityType){
case EVENT_ENTITY_PED:
ref = CPools::GetPedRef((CPed*)ent);
break;
case EVENT_ENTITY_VEHICLE:
ref = CPools::GetVehicleRef((CVehicle*)ent);
break;
case EVENT_ENTITY_OBJECT:
ref = CPools::GetObjectRef((CObject*)ent);
break;
default:
Error("Undefined entity type, RegisterEvent, EventList.cpp");
ref = 0;
break;
}
// only update time if event exists already
for(i = 0; i < NUMEVENTS; i++)
if(gaEvent[i].type == type &&
gaEvent[i].entityType == entityType &&
gaEvent[i].entityRef == ref){
gaEvent[i].timeout = CTimer::GetTimeInMilliseconds() + timeout;
return;
}
for(i = ms_nFirstFreeSlotIndex; i < NUMEVENTS; i++)
if(gaEvent[i].type == EVENT_NULL){
ms_nFirstFreeSlotIndex = i;
break;
}
if(i < NUMEVENTS){
gaEvent[i].type = type;
gaEvent[i].entityType = entityType;
gaEvent[i].timeout = CTimer::GetTimeInMilliseconds() + timeout;
gaEvent[i].entityRef = ref;
gaEvent[i].posn = ent->GetPosition();
gaEvent[i].criminal = criminal;
if(gaEvent[i].criminal)
gaEvent[i].criminal->RegisterReference((CEntity**)&gaEvent[i].criminal);
if(type == EVENT_GUNSHOT)
gaEvent[i].state = EVENT_STATE_CLEAR;
else
gaEvent[i].state = EVENT_STATE_0;
}
if(criminal == FindPlayerPed())
ReportCrimeForEvent(type, (intptr)ent, copsDontCare);
}
void
CEventList::RegisterEvent(eEventType type, CVector posn, int32 timeout)
{
int i;
// only update time if event exists already
for(i = 0; i < NUMEVENTS; i++)
if(gaEvent[i].type == type &&
gaEvent[i].posn.x == posn.x &&
gaEvent[i].posn.y == posn.y &&
gaEvent[i].posn.z == posn.z &&
gaEvent[i].entityType == EVENT_ENTITY_NONE){
gaEvent[i].timeout = CTimer::GetTimeInMilliseconds() + timeout;
return;
}
for(i = ms_nFirstFreeSlotIndex; i < NUMEVENTS; i++)
if(gaEvent[i].type == EVENT_NULL){
ms_nFirstFreeSlotIndex = i;
break;
}
if(i < NUMEVENTS){
gaEvent[i].type = type;
gaEvent[i].entityType = EVENT_ENTITY_NONE;
gaEvent[i].timeout = CTimer::GetTimeInMilliseconds() + timeout;
gaEvent[i].posn = posn;
gaEvent[i].entityRef = 0;
if(type == EVENT_GUNSHOT)
gaEvent[i].state = EVENT_STATE_CLEAR;
else
gaEvent[i].state = EVENT_STATE_0;
}
}
bool
CEventList::GetEvent(eEventType type, int32 *event)
{
int i;
for(i = 0; i < NUMEVENTS; i++)
if(gaEvent[i].type == type){
*event = i;
return true;
}
return false;
}
void
CEventList::ClearEvent(int32 event)
{
if(gaEvent[event].state != EVENT_STATE_CANDELETE)
gaEvent[event].state = EVENT_STATE_CLEAR;
}
bool
CEventList::FindClosestEvent(eEventType type, CVector posn, int32 *event)
{
int i;
float dist;
bool found = false;
float mindist = 60.0f;
for(i = 0; i < NUMEVENTS; i++){
if(gaEvent[i].type != type)
continue;
dist = (posn - gaEvent[i].posn).Magnitude();
if(dist < mindist){
mindist = dist;
found = true;
*event = i;
}
}
return found;
}
void
CEventList::ReportCrimeForEvent(eEventType type, intptr crimeId, bool copsDontCare)
{
eCrimeType crime;
switch(type){
case EVENT_ASSAULT: crime = CRIME_HIT_PED; break;
case EVENT_RUN_REDLIGHT: crime = CRIME_RUN_REDLIGHT; break;
case EVENT_ASSAULT_POLICE: crime = CRIME_HIT_COP; break;
case EVENT_GUNSHOT: crime = CRIME_POSSESSION_GUN; break;
case EVENT_STEAL_CAR: crime = CRIME_STEAL_CAR; break;
case EVENT_HIT_AND_RUN: crime = CRIME_RUNOVER_PED; break;
case EVENT_HIT_AND_RUN_COP: crime = CRIME_RUNOVER_COP; break;
case EVENT_SHOOT_PED: crime = CRIME_SHOOT_PED; break;
case EVENT_SHOOT_COP: crime = CRIME_SHOOT_COP; break;
case EVENT_EXPLOSION: crime = CRIME_EXPLOSION; break;
case EVENT_PED_SET_ON_FIRE: crime = CRIME_PED_BURNED; break;
case EVENT_COP_SET_ON_FIRE: crime = CRIME_COP_BURNED; break;
case EVENT_CAR_SET_ON_FIRE: crime = CRIME_VEHICLE_BURNED; break;
case EVENT_ASSAULT_NASTYWEAPON: crime = CRIME_HIT_PED_NASTYWEAPON; break;
case EVENT_ASSAULT_NASTYWEAPON_POLICE: crime = CRIME_HIT_COP_NASTYWEAPON; break;
default: crime = CRIME_NONE; break;
}
if (crime == CRIME_HIT_PED && IsPedPointerValid((CPed*)crimeId) && FindPlayerPed()->m_pWanted->m_nWantedLevel == 0 && ((CPed*)crimeId)->bBeingChasedByPolice) {
if (!((CPed*)crimeId)->DyingOrDead()) {
CMessages::AddBigMessage(TheText.Get("GOODBOY"), 5000, 0);
CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 50;
}
return;
}
if(crime == CRIME_NONE)
return;
#ifdef FIX_BUGS
CVector playerPedCoors = FindPlayerCoors();
#else
CVector playerPedCoors = FindPlayerPed()->GetPosition();
#endif
CVector playerCoors = FindPlayerCoors();
if(CWanted::WorkOutPolicePresence(playerCoors, 14.0f) != 0 ||
CGame::germanGame && (crime == CRIME_SHOOT_PED || crime == CRIME_SHOOT_COP || crime == CRIME_COP_BURNED || crime == CRIME_VEHICLE_BURNED)){
FindPlayerPed()->m_pWanted->RegisterCrime_Immediately(crime, playerPedCoors, (uint32)crimeId, copsDontCare);
FindPlayerPed()->m_pWanted->SetWantedLevelNoDrop(1);
}else
FindPlayerPed()->m_pWanted->RegisterCrime(crime, playerPedCoors, (uint32)crimeId, copsDontCare);
if(type == EVENT_ASSAULT_POLICE)
FindPlayerPed()->SetWantedLevelNoDrop(1);
if(type == EVENT_SHOOT_COP || type == EVENT_ASSAULT_NASTYWEAPON_POLICE)
FindPlayerPed()->SetWantedLevelNoDrop(2);
}
|