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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
|
#include "common.h"
#include "Automobile.h"
#include "Bridge.h"
#include "Camera.h"
#include "CarCtrl.h"
#include "Cranes.h"
#include "Darkel.h"
#include "Explosion.h"
#include "Fire.h"
#include "Frontend.h"
#include "General.h"
#include "HandlingMgr.h"
#include "Messages.h"
#include "Pad.h"
#include "PathFind.h"
#include "PlayerInfo.h"
#include "PlayerPed.h"
#include "PlayerSkin.h"
#include "ProjectileInfo.h"
#include "Remote.h"
#include "Renderer.h"
#include "Replay.h"
#include "Script.h"
#include "SpecialFX.h"
#include "Stats.h"
#include "Streaming.h"
#include "Text.h"
#include "Wanted.h"
#include "WaterLevel.h"
#include "World.h"
#include "ZoneCull.h"
#include "main.h"
#include "Bike.h"
#include "Automobile.h"
#include "GameLogic.h"
CVector lastPlayerPos;
void
CPlayerInfo::Clear(void)
{
m_pPed = nil;
m_pRemoteVehicle = nil;
if (m_pVehicleEx) {
m_pVehicleEx->bUsingSpecialColModel = false;
m_pVehicleEx = nil;
}
m_nVisibleMoney = 0;
m_nMoney = m_nVisibleMoney;
m_WBState = WBSTATE_PLAYING;
m_nWBTime = 0;
m_nTrafficMultiplier = 0;
m_fRoadDensity = 1.0f;
m_bInRemoteMode = false;
field_D5 = false;
field_D6 = false;
m_bUnusedTaxiThing = false;
m_nUnusedTaxiTimer = 0;
m_nCollectedPackages = 0;
m_nTotalPackages = 3;
m_nTimeLastHealthLoss = 0;
m_nTimeLastArmourLoss = 0;
m_nNextSexFrequencyUpdateTime = 0;
m_nNextSexMoneyUpdateTime = 0;
m_nSexFrequency = 0;
m_pHooker = nil;
m_nTimeTankShotGun = 0;
field_EC = 0;
m_nUpsideDownCounter = 0;
m_nTimeCarSpentOnTwoWheels = 0;
m_nDistanceCarTravelledOnTwoWheels = 0;
m_nTimeNotFullyOnGround = 0;
m_nTimeSpentOnWheelie = 0;
m_nDistanceTravelledOnWheelie = 0.0f;
m_nTimeSpentOnStoppie = 0;
m_nDistanceTravelledOnStoppie = 0.0f;
m_nCancelWheelStuntTimer = 0;
m_nLastTimeCarSpentOnTwoWheels = 0;
m_nLastDistanceCarTravelledOnTwoWheels = 0;
m_nLastTimeSpentOnWheelie = 0;
m_nLastDistanceTravelledOnWheelie = 0;
m_nLastTimeSpentOnStoppie = 0;
m_nLastDistanceTravelledOnStoppie = 0;
m_bInfiniteSprint = false;
m_bFastReload = false;
m_bFireproof = false;
m_nMaxHealth = m_nMaxArmour = 100;
m_bGetOutOfJailFree = false;
m_bGetOutOfHospitalFree = false;
m_bDriveByAllowed = true;
m_nPreviousTimeRewardedForExplosion = 0;
m_nExplosionsSinceLastReward = 0;
m_nHavocLevel = 0;
m_fMediaAttention = 0.0f;
m_nCurrentBustedAudio = 1;
m_nBustedAudioStatus = BUSTEDAUDIO_NONE;
}
void
CPlayerInfo::Process(void)
{
#ifdef FIX_BUGS
if (CReplay::IsPlayingBack())
return;
#endif
// Unused taxi feature. Gives you a dollar for every second with a passenger. Can be toggled via 0x29A opcode.
bool startTaxiTimer = true;
if (m_bUnusedTaxiThing && m_pPed->bInVehicle) {
CVehicle *veh = m_pPed->m_pMyVehicle;
if (veh->IsTaxi()
&& veh->pDriver == m_pPed && veh->m_nNumPassengers != 0) {
for (uint32 timePassed = CTimer::GetTimeInMilliseconds() - m_nUnusedTaxiTimer; timePassed >= 1000; m_nUnusedTaxiTimer += 1000) {
timePassed -= 1000;
++m_nMoney;
}
startTaxiTimer = false;
}
}
if (startTaxiTimer)
m_nUnusedTaxiTimer = CTimer::GetTimeInMilliseconds();
if (!m_pPed->InVehicle()) {
m_nTimeCarSpentOnTwoWheels = 0;
m_nTimeNotFullyOnGround = 0;
m_nTimeSpentOnWheelie = 0;
m_nTimeSpentOnStoppie = 0;
m_nCancelWheelStuntTimer = 0;
} else if (m_pPed->m_pMyVehicle->IsCar()) {
CAutomobile *car = (CAutomobile*)m_pPed->m_pMyVehicle;
if (car->m_nWheelsOnGround < 3)
m_nTimeNotFullyOnGround += CTimer::GetTimeStepInMilliseconds();
else
m_nTimeNotFullyOnGround = 0;
if (car->m_aSuspensionSpringRatioPrev[2] == 1.f && car->m_aSuspensionSpringRatioPrev[3] == 1.f) {
if (car->m_aSuspensionSpringRatioPrev[0] < 1.0f && car->m_aSuspensionSpringRatioPrev[1] < 1.0f && car->m_fDamageImpulse == 0.0f) {
m_nTimeCarSpentOnTwoWheels += CTimer::GetTimeStepInMilliseconds();
m_nDistanceCarTravelledOnTwoWheels += car->m_fDistanceTravelled;
m_nCancelWheelStuntTimer = Max(0.0f, m_nCancelWheelStuntTimer - CTimer::GetTimeStepInMilliseconds() * 0.5f);
} else {
if (m_nTimeCarSpentOnTwoWheels != 0 && m_nCancelWheelStuntTimer < 500) {
m_nCancelWheelStuntTimer += CTimer::GetTimeStepInMilliseconds();
} else {
if (m_nTimeCarSpentOnTwoWheels >= 2000) {
m_nLastTimeCarSpentOnTwoWheels = m_nTimeCarSpentOnTwoWheels;
m_nLastDistanceCarTravelledOnTwoWheels = m_nDistanceCarTravelledOnTwoWheels;
if (CStats::Longest2Wheel < m_nTimeCarSpentOnTwoWheels / 1000)
CStats::Longest2Wheel = m_nTimeCarSpentOnTwoWheels / 1000;
if (CStats::Longest2WheelDist < m_nDistanceCarTravelledOnTwoWheels)
CStats::Longest2WheelDist = m_nDistanceCarTravelledOnTwoWheels;
}
m_nTimeCarSpentOnTwoWheels = 0;
m_nDistanceCarTravelledOnTwoWheels = 0;
m_nCancelWheelStuntTimer = 0;
}
}
} else if (car->m_aSuspensionSpringRatioPrev[0] == 1.0f && car->m_aSuspensionSpringRatioPrev[1] == 1.0f) {
#ifdef FIX_BUGS
if (car->m_aSuspensionSpringRatioPrev[2] < 1.f
#else
if (car->m_aSuspensionSpringRatioPrev[1] < 1.f
#endif
&& car->m_aSuspensionSpringRatioPrev[3] < 1.f && 0.0f == car->m_fDamageImpulse) {
m_nTimeCarSpentOnTwoWheels += CTimer::GetTimeStepInMilliseconds();
m_nDistanceCarTravelledOnTwoWheels += car->m_fDistanceTravelled;
m_nCancelWheelStuntTimer = Max(0.0f, m_nCancelWheelStuntTimer - CTimer::GetTimeStepInMilliseconds() * 0.2f);
} else if (m_nTimeCarSpentOnTwoWheels != 0 && m_nCancelWheelStuntTimer < 500) {
m_nCancelWheelStuntTimer += CTimer::GetTimeStepInMilliseconds();
} else {
if (m_nTimeCarSpentOnTwoWheels >= 2000) {
m_nLastTimeCarSpentOnTwoWheels = m_nTimeCarSpentOnTwoWheels;
m_nLastDistanceCarTravelledOnTwoWheels = m_nDistanceCarTravelledOnTwoWheels;
if (CStats::Longest2Wheel < m_nTimeCarSpentOnTwoWheels / 1000)
CStats::Longest2Wheel = m_nTimeCarSpentOnTwoWheels / 1000;
if (CStats::Longest2WheelDist < m_nDistanceCarTravelledOnTwoWheels)
CStats::Longest2WheelDist = m_nDistanceCarTravelledOnTwoWheels;
}
m_nTimeCarSpentOnTwoWheels = 0;
m_nDistanceCarTravelledOnTwoWheels = 0;
m_nCancelWheelStuntTimer = 0;
}
} else if (m_nTimeCarSpentOnTwoWheels != 0) {
if (m_nTimeCarSpentOnTwoWheels >= 2000) {
m_nLastTimeCarSpentOnTwoWheels = m_nTimeCarSpentOnTwoWheels;
m_nLastDistanceCarTravelledOnTwoWheels = m_nDistanceCarTravelledOnTwoWheels;
if (CStats::Longest2Wheel < m_nTimeCarSpentOnTwoWheels / 1000)
CStats::Longest2Wheel = m_nTimeCarSpentOnTwoWheels / 1000;
if (CStats::Longest2WheelDist < m_nDistanceCarTravelledOnTwoWheels)
CStats::Longest2WheelDist = m_nDistanceCarTravelledOnTwoWheels;
}
m_nTimeCarSpentOnTwoWheels = 0;
m_nDistanceCarTravelledOnTwoWheels = 0;
m_nCancelWheelStuntTimer = 0;
}
m_nTimeSpentOnWheelie = 0;
m_nTimeSpentOnStoppie = 0;
} else if (m_pPed->m_pMyVehicle->IsBike()) {
CBike *bike = (CBike*)m_pPed->m_pMyVehicle;
if (bike->m_aSuspensionSpringRatioPrev[0] == 1.0f && bike->m_aSuspensionSpringRatioPrev[1] == 1.0f) {
if (bike->m_aSuspensionSpringRatioPrev[2] < 1.0f
|| (bike->m_aSuspensionSpringRatioPrev[3] < 1.0f && 0.0f == bike->m_fDamageImpulse)) {
m_nTimeSpentOnWheelie += CTimer::GetTimeStepInMilliseconds();
m_nDistanceTravelledOnWheelie += bike->m_fDistanceTravelled;
m_nCancelWheelStuntTimer = Max(0.0f, m_nCancelWheelStuntTimer - CTimer::GetTimeStepInMilliseconds() * 0.2f);
} else {
if (m_nTimeSpentOnWheelie != 0 && m_nCancelWheelStuntTimer < 500) {
m_nCancelWheelStuntTimer += CTimer::GetTimeStepInMilliseconds();
} else {
if (m_nTimeSpentOnWheelie >= 5000) {
m_nLastTimeSpentOnWheelie = m_nTimeSpentOnWheelie;
m_nLastDistanceTravelledOnWheelie = m_nDistanceTravelledOnWheelie;
if (CStats::LongestWheelie < m_nTimeSpentOnWheelie / 1000)
CStats::LongestWheelie = m_nTimeSpentOnWheelie / 1000;
if (CStats::LongestWheelieDist < m_nDistanceTravelledOnWheelie)
CStats::LongestWheelieDist = m_nDistanceTravelledOnWheelie;
}
m_nTimeSpentOnWheelie = 0;
m_nDistanceTravelledOnWheelie = 0;
m_nCancelWheelStuntTimer = 0;
}
}
} else if (m_nTimeSpentOnWheelie != 0) {
if (m_nTimeSpentOnWheelie >= 5000) {
m_nLastTimeSpentOnWheelie = m_nTimeSpentOnWheelie;
m_nLastDistanceTravelledOnWheelie = m_nDistanceTravelledOnWheelie;
if (CStats::LongestWheelie < m_nTimeSpentOnWheelie / 1000)
CStats::LongestWheelie = m_nTimeSpentOnWheelie / 1000;
if (CStats::LongestWheelieDist < m_nDistanceTravelledOnWheelie)
CStats::LongestWheelieDist = m_nDistanceTravelledOnWheelie;
}
m_nTimeSpentOnWheelie = 0;
m_nDistanceTravelledOnWheelie = 0;
m_nCancelWheelStuntTimer = 0;
} else if (bike->m_aSuspensionSpringRatioPrev[2] == 1.0f && bike->m_aSuspensionSpringRatioPrev[3] == 1.0f
&& 0.0f == bike->m_fDamageImpulse) {
m_nTimeSpentOnStoppie += CTimer::GetTimeStepInMilliseconds();
m_nDistanceTravelledOnStoppie += bike->m_fDistanceTravelled;
m_nCancelWheelStuntTimer = Max(0.0f, m_nCancelWheelStuntTimer - CTimer::GetTimeStepInMilliseconds() * 0.2f);
} else {
if (m_nTimeSpentOnStoppie != 0 && m_nCancelWheelStuntTimer < 500) {
m_nCancelWheelStuntTimer += CTimer::GetTimeStepInMilliseconds();
} else {
if (m_nTimeSpentOnStoppie >= 2000) {
m_nLastTimeSpentOnStoppie = m_nTimeSpentOnStoppie;
m_nLastDistanceTravelledOnStoppie = m_nDistanceTravelledOnStoppie;
if (CStats::LongestStoppie < m_nTimeSpentOnStoppie / 1000)
CStats::LongestStoppie = m_nTimeSpentOnStoppie / 1000;
if (CStats::LongestStoppieDist < m_nDistanceTravelledOnStoppie)
CStats::LongestStoppieDist = m_nDistanceTravelledOnStoppie;
}
m_nTimeSpentOnStoppie = 0;
m_nDistanceTravelledOnStoppie = 0;
m_nCancelWheelStuntTimer = 0;
}
}
m_nTimeCarSpentOnTwoWheels = 0;
m_nTimeNotFullyOnGround = 0;
} else {
m_nTimeCarSpentOnTwoWheels = 0;
m_nTimeNotFullyOnGround = 0;
m_nTimeSpentOnWheelie = 0;
m_nTimeSpentOnStoppie = 0;
m_nCancelWheelStuntTimer = 0;
}
// The effect that makes money counter does while earning/losing money
if (m_nVisibleMoney != m_nMoney) {
int diff = m_nMoney - m_nVisibleMoney;
int diffAbs = Abs(diff);
int changeBy;
if (diffAbs > 100000)
changeBy = 12345;
else if (diffAbs > 10000)
changeBy = 1234;
else if (diffAbs > 1000)
changeBy = 123;
else if (diffAbs > 50)
changeBy = 42;
else
changeBy = 1;
if (diff < 0)
m_nVisibleMoney -= changeBy;
else
m_nVisibleMoney += changeBy;
}
if (!(CTimer::GetFrameCounter() & 15)) {
CVector2D playerPos = m_pPed->bInVehicle ? m_pPed->m_pMyVehicle->GetPosition() : m_pPed->GetPosition();
m_fRoadDensity = ThePaths.CalcRoadDensity(playerPos.x, playerPos.y);
}
m_fRoadDensity = clamp(m_fRoadDensity, 0.5f, 1.45f);
// Because vehicle enter/exit use same key binding.
bool enterOrExitVeh;
if (m_pPed->bVehExitWillBeInstant && m_pPed->bInVehicle)
enterOrExitVeh = CPad::GetPad(0)->ExitVehicleJustDown();
else
enterOrExitVeh = CPad::GetPad(0)->GetExitVehicle();
if (enterOrExitVeh && m_pPed->m_nPedState != PED_ANSWER_MOBILE && m_pPed->m_nPedState != PED_SNIPER_MODE && m_pPed->m_nPedState != PED_ROCKET_MODE) {
if (m_pPed->bInVehicle) {
if (!m_pRemoteVehicle) {
CEntity *surfaceBelowVeh = m_pPed->m_pMyVehicle->m_pCurGroundEntity;
if (!surfaceBelowVeh || !CBridge::ThisIsABridgeObjectMovingUp(surfaceBelowVeh->GetModelIndex())) {
CVehicle *veh = m_pPed->m_pMyVehicle;
if (!veh->IsBoat() || veh->m_nDoorLock == CARLOCK_LOCKED_PLAYER_INSIDE) {
if (veh->GetStatus() != STATUS_WRECKED && veh->GetStatus() != STATUS_TRAIN_MOVING && veh->m_nDoorLock != CARLOCK_LOCKED_PLAYER_INSIDE) {
bool canJumpOff = false;
if (veh->m_vehType == VEHICLE_TYPE_BIKE) {
canJumpOff = veh->CanPedJumpOffBike();
} else if (veh->pDriver == m_pPed) {
canJumpOff = veh->CanPedJumpOutCar();
}
if (canJumpOff || veh->m_vecMoveSpeed.Magnitude() < 0.1f) {
if (!veh->bIsInWater)
m_pPed->SetObjective(OBJECTIVE_LEAVE_CAR, veh);
} else if (veh->GetStatus() != STATUS_PLAYER && veh != CGameLogic::pShortCutTaxi) {
veh->AutoPilot.m_nTempAction = TEMPACT_WAIT;
veh->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 1000;
}
}
} else {
m_pPed->SetExitBoat(veh);
m_pPed->bTryingToReachDryLand = true;
}
}
}
} else {
// Enter vehicle
if (CPad::GetPad(0)->ExitVehicleJustDown()) {
bool weAreOnBoat = false;
float lastCloseness = 0.0f;
CVehicle *carBelow = nil;
CEntity *surfaceBelow = m_pPed->m_pCurrentPhysSurface;
if (surfaceBelow && surfaceBelow->IsVehicle()) {
carBelow = (CVehicle*)surfaceBelow;
if (carBelow->IsBoat() && carBelow->m_modelIndex != MI_SKIMMER) {
weAreOnBoat = true;
m_pPed->bOnBoat = true;
if (carBelow->GetStatus() != STATUS_WRECKED && carBelow->GetUp().z > 0.3f)
m_pPed->SetSeekBoatPosition(carBelow);
}
}
// Find closest car
if (!weAreOnBoat) {
float minX = m_pPed->GetPosition().x - 10.0f;
float maxX = 10.0f + m_pPed->GetPosition().x;
float minY = m_pPed->GetPosition().y - 10.0f;
float maxY = 10.0f + m_pPed->GetPosition().y;
int minXSector = CWorld::GetSectorIndexX(minX);
if (minXSector < 0) minXSector = 0;
int minYSector = CWorld::GetSectorIndexY(minY);
if (minYSector < 0) minYSector = 0;
int maxXSector = CWorld::GetSectorIndexX(maxX);
if (maxXSector > NUMSECTORS_X - 1) maxXSector = NUMSECTORS_X - 1;
int maxYSector = CWorld::GetSectorIndexY(maxY);
if (maxYSector > NUMSECTORS_Y - 1) maxYSector = NUMSECTORS_Y - 1;
CWorld::AdvanceCurrentScanCode();
for (int curY = minYSector; curY <= maxYSector; curY++) {
for (int curX = minXSector; curX <= maxXSector; curX++) {
CSector *sector = CWorld::GetSector(curX, curY);
FindClosestCarSectorList(sector->m_lists[ENTITYLIST_VEHICLES], m_pPed,
minX, minY, maxX, maxY, &lastCloseness, &carBelow);
FindClosestCarSectorList(sector->m_lists[ENTITYLIST_VEHICLES_OVERLAP], m_pPed,
minX, minY, maxX, maxY, &lastCloseness, &carBelow);
}
}
}
// carBelow is now closest vehicle
if (carBelow && !weAreOnBoat) {
if (carBelow->GetStatus() == STATUS_TRAIN_NOT_MOVING) {
m_pPed->SetObjective(OBJECTIVE_ENTER_CAR_AS_PASSENGER, carBelow);
} else if (carBelow->IsBoat()) {
if (!carBelow->pDriver) {
m_pPed->m_vehDoor = 0;
m_pPed->SetEnterCar(carBelow, m_pPed->m_vehDoor);
}
} else {
m_pPed->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, carBelow);
}
}
}
}
}
if (m_bInRemoteMode) {
uint32 timeWithoutRemoteCar = CTimer::GetTimeInMilliseconds() - m_nTimeLostRemoteCar;
if (CTimer::GetPreviousTimeInMilliseconds() - m_nTimeLostRemoteCar < 1000 && timeWithoutRemoteCar >= 1000 && m_WBState == WBSTATE_PLAYING && field_D6) {
TheCamera.SetFadeColour(0, 0, 0);
TheCamera.Fade(1.0f, FADE_OUT);
}
if (timeWithoutRemoteCar > 2000) {
if (m_WBState == WBSTATE_PLAYING && field_D6) {
TheCamera.RestoreWithJumpCut();
TheCamera.SetFadeColour(0, 0, 0);
TheCamera.Fade(1.0f, FADE_IN);
TheCamera.Process();
CTimer::Stop();
CCullZones::ForceCullZoneCoors(TheCamera.GetPosition());
CRenderer::RequestObjectsInFrustum();
CStreaming::LoadAllRequestedModels(false);
CTimer::Update();
}
m_bInRemoteMode = false;
CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle->bRemoveFromWorld = true;
CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle = nil;
if (FindPlayerVehicle()) {
FindPlayerVehicle()->SetStatus(STATUS_PLAYER);
}
}
}
if (!(CTimer::GetFrameCounter() & 31)) {
CVehicle *veh = FindPlayerVehicle();
if (veh && m_pPed->bInVehicle && veh->GetUp().z < 0.0f
&& veh->m_vecMoveSpeed.Magnitude() < 0.05f && (veh->IsCar() || veh->IsBoat()) && !veh->bIsInWater) {
if (veh->GetUp().z < -0.5f) {
m_nUpsideDownCounter += 2;
} else {
m_nUpsideDownCounter++;
}
} else {
m_nUpsideDownCounter = 0;
}
if (m_nUpsideDownCounter > 6 && veh->bCanBeDamaged) {
veh->m_fHealth = 249.0f < veh->m_fHealth ? 249.0f : veh->m_fHealth;
if (veh->IsCar()) {
CAutomobile* car = (CAutomobile*)veh;
car->Damage.SetEngineStatus(225);
car->m_pSetOnFireEntity = nil;
}
}
}
if (FindPlayerVehicle()) {
CVehicle *veh = FindPlayerVehicle();
veh->m_nZoneLevel = LEVEL_IGNORE;
for (int i = 0; i < ARRAY_SIZE(veh->pPassengers); i++) {
if (veh->pPassengers[i])
veh->pPassengers[i]->m_nZoneLevel = LEVEL_GENERIC;
}
if(veh->m_modelIndex == MI_CADDY)
CStats::DistanceTravelledByGolfCart += veh->m_fDistanceTravelled;
else {
if(veh->GetVehicleAppearance() == VEHICLE_APPEARANCE_HELI)
CStats::DistanceTravelledByHelicoptor += veh->m_fDistanceTravelled;
if (veh->GetVehicleAppearance() == VEHICLE_APPEARANCE_PLANE)
CStats::DistanceTravelledByPlane += veh->m_fDistanceTravelled;
if (veh->GetVehicleAppearance() == VEHICLE_APPEARANCE_CAR)
CStats::DistanceTravelledByCar += veh->m_fDistanceTravelled;
if (veh->GetVehicleAppearance() == VEHICLE_APPEARANCE_BIKE)
CStats::DistanceTravelledByBike += veh->m_fDistanceTravelled;
if (veh->GetVehicleAppearance() == VEHICLE_APPEARANCE_BOAT)
CStats::DistanceTravelledByBoat += veh->m_fDistanceTravelled;
if (veh->GetVehicleAppearance() == VEHICLE_APPEARANCE_PLANE) {
if (veh->m_vecMoveSpeed.Magnitude() > 0.2f) {
CStats::FlightTime += CTimer::GetTimeStep() * 16.f; // what a weird choice
}
}
}
} else {
CStats::DistanceTravelledOnFoot += FindPlayerPed()->m_fDistanceTravelled;
}
if (m_pPed->m_pWanted->GetWantedLevel() && !CTheScripts::IsPlayerOnAMission()) {
float maxDelta = 0.0f;
static bool movedSignificantly = true;
static bool thereIsACarPathNear = true;
// there was one more guard without variable's itself???
if (CTimer::GetTimeInMilliseconds() / 20000 != CTimer::GetPreviousTimeInMilliseconds() / 20000) {
float posChange = (lastPlayerPos - FindPlayerCoors()).Magnitude();
movedSignificantly = posChange >= 10.0f;
lastPlayerPos = FindPlayerCoors();
thereIsACarPathNear = ThePaths.FindNodeClosestToCoors(FindPlayerCoors(), PATH_CAR, 60.0f, true, false, false, false) != 0;
}
switch (m_pPed->m_pWanted->GetWantedLevel()) {
case 1:
maxDelta = 31.f;
break;
case 2:
maxDelta = 62.f;
break;
case 3:
maxDelta = 125.f;
break;
case 4:
maxDelta = 250.f;
break;
case 5:
maxDelta = 500.f;
break;
case 6:
maxDelta = 1000.f;
break;
default:
break;
}
float increaseDelta = maxDelta - m_fMediaAttention;
float increaseAttentionBy = CTimer::GetTimeStep() * 0.0001f * increaseDelta;
if (increaseAttentionBy < 0.0f
|| movedSignificantly && thereIsACarPathNear && !CCullZones::NoPolice() && !CCullZones::PoliceAbandonCars() && CGame::currArea == AREA_MAIN_MAP) {
m_fMediaAttention += increaseAttentionBy;
}
} else {
m_fMediaAttention = 0.0f;
}
CStats::HighestChaseValue = Max(m_fMediaAttention, CStats::HighestChaseValue);
m_nMoney = Min(999999999, m_nMoney);
m_nVisibleMoney = Min(999999999, m_nVisibleMoney);
}
bool
CPlayerInfo::IsPlayerInRemoteMode()
{
return m_pRemoteVehicle || m_bInRemoteMode;
}
void
CPlayerInfo::SavePlayerInfo(uint8 *buf, uint32 *size)
{
// Interesting
*size = sizeof(CPlayerInfo);
#define CopyToBuf(buf, data) memcpy(buf, &data, sizeof(data)); buf += sizeof(data);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nMoney);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_WBState);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nWBTime);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nTrafficMultiplier);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_fRoadDensity);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nCollectedPackages);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nTotalPackages);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bInfiniteSprint);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bFastReload);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bFireproof);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nMaxHealth);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nMaxArmour);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bGetOutOfJailFree);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bGetOutOfHospitalFree);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bDriveByAllowed);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_aPlayerName);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nBustedAudioStatus);
CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nCurrentBustedAudio);
#undef CopyToBuf
}
void
CPlayerInfo::LoadPlayerInfo(uint8 *buf, uint32 size)
{
#define CopyFromBuf(buf, data) memcpy(&data, buf, sizeof(data)); buf += sizeof(data);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nMoney);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_WBState);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nWBTime);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nTrafficMultiplier);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_fRoadDensity);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nCollectedPackages);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nTotalPackages);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bInfiniteSprint);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bFastReload);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bFireproof);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nMaxHealth);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nMaxArmour);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bGetOutOfJailFree);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bGetOutOfHospitalFree);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bDriveByAllowed);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_aPlayerName);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nBustedAudioStatus);
CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nCurrentBustedAudio)
#undef CopyFromBuf
}
void
CPlayerInfo::FindClosestCarSectorList(CPtrList& carList, CPed* ped, float unk1, float unk2, float unk3, float unk4, float* lastCloseness, CVehicle** closestCarOutput)
{
for (CPtrNode* node = carList.first; node; node = node->next) {
CVehicle *car = (CVehicle*)node->item;
if(car->m_scanCode != CWorld::GetCurrentScanCode()) {
if (!car->bUsesCollision || !car->IsVehicle())
continue;
car->m_scanCode = CWorld::GetCurrentScanCode();
if (car->GetStatus() != STATUS_WRECKED && car->GetStatus() != STATUS_TRAIN_MOVING
&& (car->GetUp().z > 0.3f || (car->IsVehicle() && ((CVehicle*)car)->m_vehType == VEHICLE_TYPE_BIKE))) {
CVector carCentre = car->GetBoundCentre();
if (Abs(ped->GetPosition().z - carCentre.z) < 2.0f || car->IsCar() && carCentre.z < ped->GetPosition().z && ped->GetPosition().z - 4.f < carCentre.z) {
float dist = (ped->GetPosition() - carCentre).Magnitude2D();
if (dist <= 10.0f && !CCranes::IsThisCarBeingCarriedByAnyCrane(car)) {
EvaluateCarPosition(car, ped, dist, lastCloseness, closestCarOutput);
}
}
}
}
}
}
// lastCloseness is passed to other calls of this function
void
CPlayerInfo::EvaluateCarPosition(CEntity *carToTest, CPed *player, float carBoundCentrePedDist, float *lastCloseness, CVehicle **closestCarOutput)
{
// This dist used for determining the angle to face
CVector2D dist(carToTest->GetPosition() - player->GetPosition());
float neededTurn = CGeneral::GetATanOfXY(player->GetForward().x, player->GetForward().y) - CGeneral::GetATanOfXY(dist.x, dist.y);
while (neededTurn >= PI) {
neededTurn -= 2 * PI;
}
while (neededTurn < -PI) {
neededTurn += 2 * PI;
}
// This dist used for evaluating cars' distances, weird...
// Accounts inverted needed turn (or needed turn in long way) and car dist.
float closeness = (1.0f - Abs(neededTurn) / TWOPI) * (10.0f - carBoundCentrePedDist);
if (closeness > *lastCloseness) {
*lastCloseness = closeness;
*closestCarOutput = (CVehicle*)carToTest;
}
}
const CVector &
CPlayerInfo::GetPos()
{
#ifdef FIX_BUGS
if (!m_pPed)
return TheCamera.GetPosition();
#endif
if (m_pPed->InVehicle())
return m_pPed->m_pMyVehicle->GetPosition();
return m_pPed->GetPosition();
}
CVector
FindPlayerCoors(void)
{
#ifdef FIX_BUGS
if (CReplay::IsPlayingBack())
return TheCamera.GetPosition();
#endif
CPlayerPed *ped = FindPlayerPed();
if(ped->InVehicle())
return ped->m_pMyVehicle->GetPosition();
else
return ped->GetPosition();
}
const CVector &
FindPlayerSpeed(void)
{
#ifdef FIX_BUGS
static CVector vecTmpVector(0.0f, 0.0f, 0.0f);
if (CReplay::IsPlayingBack())
return vecTmpVector;
#endif
CPlayerPed *ped = FindPlayerPed();
if(ped->InVehicle())
return ped->m_pMyVehicle->m_vecMoveSpeed;
else
return ped->m_vecMoveSpeed;
}
CVehicle *
FindPlayerVehicle(void)
{
CPlayerPed *ped = FindPlayerPed();
if(ped && ped->InVehicle()) return ped->m_pMyVehicle;
return nil;
}
CEntity *
FindPlayerEntity(void)
{
CPlayerPed *ped = FindPlayerPed();
if(ped->InVehicle())
return ped->m_pMyVehicle;
else
return ped;
}
CVehicle *
FindPlayerTrain(void)
{
if(FindPlayerVehicle() && FindPlayerVehicle()->IsTrain())
return FindPlayerVehicle();
else
return nil;
}
CPlayerPed *
FindPlayerPed(void)
{
return CWorld::Players[CWorld::PlayerInFocus].m_pPed;
}
const CVector &
FindPlayerCentreOfWorld(int32 player)
{
#ifdef FIX_BUGS
if(CReplay::IsPlayingBack()) return TheCamera.GetPosition();
#endif
if(CCarCtrl::bCarsGeneratedAroundCamera) return TheCamera.GetPosition();
if(CWorld::Players[player].m_pRemoteVehicle) return CWorld::Players[player].m_pRemoteVehicle->GetPosition();
if(FindPlayerVehicle()) return FindPlayerVehicle()->GetPosition();
return CWorld::Players[player].m_pPed->GetPosition();
}
const CVector &
FindPlayerCentreOfWorld_NoSniperShift(void)
{
#ifdef FIX_BUGS
if (CReplay::IsPlayingBack()) return TheCamera.GetPosition();
#endif
if(CCarCtrl::bCarsGeneratedAroundCamera) return TheCamera.GetPosition();
if(CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle)
return CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle->GetPosition();
if(FindPlayerVehicle()) return FindPlayerVehicle()->GetPosition();
return FindPlayerPed()->GetPosition();
}
float
FindPlayerHeading(void)
{
if(CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle)
return CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle->GetForward().Heading();
if(FindPlayerVehicle()) return FindPlayerVehicle()->GetForward().Heading();
return FindPlayerPed()->GetForward().Heading();
}
bool
CPlayerInfo::IsRestartingAfterDeath()
{
return m_WBState == WBSTATE_WASTED;
}
bool
CPlayerInfo::IsRestartingAfterArrest()
{
return m_WBState == WBSTATE_BUSTED;
}
void
CPlayerInfo::KillPlayer()
{
if (m_WBState != WBSTATE_PLAYING) return;
m_WBState = WBSTATE_WASTED;
m_nWBTime = CTimer::GetTimeInMilliseconds();
CDarkel::ResetOnPlayerDeath();
CMessages::AddBigMessage(TheText.Get("DEAD"), 4000, 2);
CStats::TimesDied++;
}
void
CPlayerInfo::ArrestPlayer()
{
if (m_WBState != WBSTATE_PLAYING) return;
m_WBState = WBSTATE_BUSTED;
m_nWBTime = CTimer::GetTimeInMilliseconds();
m_nBustedAudioStatus = BUSTEDAUDIO_NONE;
CDarkel::ResetOnPlayerDeath();
CMessages::AddBigMessage(TheText.Get("BUSTED"), 5000, 2);
CStats::TimesArrested++;
}
void
CPlayerInfo::PlayerFailedCriticalMission()
{
if (m_WBState != WBSTATE_PLAYING)
return;
m_WBState = WBSTATE_FAILED_CRITICAL_MISSION;
m_nWBTime = CTimer::GetTimeInMilliseconds();
CDarkel::ResetOnPlayerDeath();
}
void
CPlayerInfo::CancelPlayerEnteringCars(CVehicle *car)
{
if (!car || car == m_pPed->m_pMyVehicle) {
if (m_pPed->EnteringCar())
m_pPed->QuitEnteringCar();
}
if (m_pPed->m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER || m_pPed->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER)
m_pPed->ClearObjective();
}
void
CPlayerInfo::MakePlayerSafe(bool toggle)
{
if (toggle) {
m_pPed->m_pWanted->m_bIgnoredByEveryone = true;
CWorld::StopAllLawEnforcersInTheirTracks();
CPad::GetPad(0)->SetDisablePlayerControls(PLAYERCONTROL_PLAYERINFO);
CPad::StopPadsShaking();
m_pPed->bBulletProof = true;
m_pPed->bFireProof = true;
m_pPed->bCollisionProof = true;
m_pPed->bMeleeProof = true;
m_pPed->bOnlyDamagedByPlayer = true;
m_pPed->bExplosionProof = true;
m_pPed->m_bCanBeDamaged = false;
((CPlayerPed*)m_pPed)->ClearAdrenaline();
CancelPlayerEnteringCars(nil);
gFireManager.ExtinguishPoint(GetPos(), 4000.0f);
CExplosion::RemoveAllExplosionsInArea(GetPos(), 4000.0f);
CProjectileInfo::RemoveAllProjectiles();
CWorld::SetAllCarsCanBeDamaged(false);
CWorld::ExtinguishAllCarFiresInArea(GetPos(), 4000.0f);
CReplay::DisableReplays();
} else {
m_pPed->m_pWanted->m_bIgnoredByEveryone = false;
CPad::GetPad(0)->SetEnablePlayerControls(PLAYERCONTROL_PLAYERINFO);
m_pPed->bBulletProof = false;
m_pPed->bFireProof = false;
m_pPed->bCollisionProof = false;
m_pPed->bMeleeProof = false;
m_pPed->bOnlyDamagedByPlayer = false;
m_pPed->bExplosionProof = false;
m_pPed->m_bCanBeDamaged = true;
CWorld::SetAllCarsCanBeDamaged(true);
CReplay::EnableReplays();
}
}
void
CPlayerInfo::BlowUpRCBuggy(bool actually)
{
if (!m_pRemoteVehicle || m_pRemoteVehicle->bRemoveFromWorld)
return;
CRemote::TakeRemoteControlledCarFromPlayer(actually);
if (actually)
m_pRemoteVehicle->BlowUpCar(FindPlayerPed());
}
#ifdef GTA_PC
void
CPlayerInfo::SetPlayerSkin(const char *skin)
{
strncpy(m_aSkinName, skin, 32);
LoadPlayerSkin();
}
void
CPlayerInfo::LoadPlayerSkin()
{
DeletePlayerSkin();
m_pSkinTexture = CPlayerSkin::GetSkinTexture(m_aSkinName);
}
void
CPlayerInfo::DeletePlayerSkin()
{
if (m_pSkinTexture) {
RwTextureDestroy(m_pSkinTexture);
m_pSkinTexture = nil;
}
}
#endif
|