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
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
|
#include "common.h"
#include "main.h"
#include "General.h"
#include "Timer.h"
#include "Pad.h"
#include "Vehicle.h"
#include "Bike.h"
#include "Automobile.h"
#include "Pools.h"
#include "HandlingMgr.h"
#include "CarCtrl.h"
#include "Population.h"
#include "ModelIndices.h"
#include "World.h"
#include "Lights.h"
#include "PointLights.h"
#include "Renderer.h"
#include "VisibilityPlugins.h"
#include "DMAudio.h"
#include "Radar.h"
#include "Fire.h"
#include "Darkel.h"
#include "Streaming.h"
#include "Camera.h"
#include "Stats.h"
#include "Garages.h"
#include "Wanted.h"
#include "SurfaceTable.h"
#include "Particle.h"
#include "WaterLevel.h"
#include "Timecycle.h"
#include "Weather.h"
#include "Coronas.h"
#include "SaveBuf.h"
// LCS: done except trivial stuff
bool CVehicle::bWheelsOnlyCheat;
bool CVehicle::bAllDodosCheat;
bool CVehicle::bCheat3;
bool CVehicle::bCheat4;
bool CVehicle::bCheat5;
bool CVehicle::bCheat8;
bool CVehicle::bCheat9;
bool CVehicle::bCheat10;
bool CVehicle::bHoverCheat;
bool CVehicle::bAllTaxisHaveNitro;
bool CVehicle::m_bDisableMouseSteering = true;
bool CVehicle::bDisableRemoteDetonation;
bool CVehicle::bDisableRemoteDetonationOnContact;
#ifndef MASTER
bool CVehicle::m_bDisplayHandlingInfo;
#endif
float CVehicle::rcHeliHeightLimit = 60.0f;
float CVehicle::WHEELSPIN_FALL_RATE = 0.7f;
float CVehicle::WHEELSPIN_RISE_RATE = 0.95f;
float CVehicle::WHEELSPIN_INAIR_TARGET_RATE = 10.0f;
float CVehicle::WHEELSPIN_TARGET_RATE = 1.0f;
void *CVehicle::operator new(size_t sz) throw() { return CPools::GetVehiclePool()->New(); }
void *CVehicle::operator new(size_t sz, int handle) throw() { return CPools::GetVehiclePool()->New(handle); }
void CVehicle::operator delete(void *p, size_t sz) throw() { CPools::GetVehiclePool()->Delete((CVehicle*)p); }
void CVehicle::operator delete(void *p, int handle) throw() { CPools::GetVehiclePool()->Delete((CVehicle*)p); }
#ifdef FIX_BUGS
// I think they meant that
#define DAMAGE_FLEE_IN_CAR_PROBABILITY_VALUE (MYRAND_MAX * 35 / 100)
#define DAMAGE_FLEE_ON_FOOT_PROBABILITY_VALUE (MYRAND_MAX * 70 / 100)
#else
#define DAMAGE_FLEE_IN_CAR_PROBABILITY_VALUE (35000)
#define DAMAGE_FLEE_ON_FOOT_PROBABILITY_VALUE (70000)
#endif
#define DAMAGE_HEALTH_TO_FLEE_ALWAYS (200.0f)
#define DAMAGE_HEALTH_TO_CATCH_FIRE (250.0f)
CVehicle::CVehicle(uint8 CreatedBy)
{
int i;
m_fGasPedal = 0.0f;
m_fBrakePedal = 0.0f;
m_fWheelSpin = 0.0f;
m_vehLCS_29E = 0;
m_vehLCS_29C = 0;
m_vehLCS_2A3 = -1;
m_bSuperBrake = false; // probably for multiplayer
m_nCurrentGear = 1;
m_fChangeGearTime = 0.0f;
m_fSteerInput = 0.0f;
m_type = ENTITY_TYPE_VEHICLE;
VehicleCreatedBy = CreatedBy;
m_nRouteSeed = 0;
bIsLocked = false;
bIsLawEnforcer = false;
bIsAmbulanceOnDuty = false;
bIsFireTruckOnDuty = false;
bIsHandbrakeOn = false;
CCarCtrl::UpdateCarCount(this, false);
m_fHealth = 1000.0f;
bEngineOn = true;
bFreebies = true;
pDriver = nil;
m_nNumPassengers = 0;
m_nNumGettingIn = 0;
m_nGettingInFlags = 0;
m_nGettingOutFlags = 0;
m_nNumMaxPassengers = ARRAY_SIZE(pPassengers);
for(i = 0; i < m_nNumMaxPassengers; i++)
pPassengers[i] = nil;
m_nBombTimer = 0;
m_pBlowUpEntity = nil;
m_nPacManPickupsCarried = 0;
bComedyControls = false;
bCraneMessageDone = false;
bExtendedRange = false;
bTakeLessDamage = false;
bIsDamaged = false;
bFadeOut = false;
bIsBeingCarJacked = false;
m_nTimeOfDeath = 0;
m_pCarFire = nil;
bHasBeenOwnedByPlayer = false;
bCreateRoadBlockPeds = false;
bCanBeDamaged = true;
bUsingSpecialColModel = false;
bOccupantsHaveBeenGenerated = false;
bGunSwitchedOff = false;
m_nGunFiringTime = 0;
m_nTimeBlocked = 0;
bLightsOn = false;
bVehicleColProcessed = false;
m_numPedsUseItAsCover = 0;
bIsCarParkVehicle = false;
bHasAlreadyBeenRecorded = false;
m_bSirenOrAlarm = false;
m_nCarHornTimer = 0;
m_nCarHornPattern = 0;
m_nCarHornDelay = 0;
bPartOfConvoy = false;
bHeliMinimumTilt = false;
bAudioChangingGear = false;
bIsDrowning = false;
bTyresDontBurst = false;
bCreatedAsPoliceVehicle = false;
bRestingOnPhysical = false;
bParking = false;
m_bGarageTurnedLightsOff = false;
m_vehLCS_259 = -1;
bCanPark = CGeneral::GetRandomNumberInRange(0.0f, 1.0f) < 0.0f; // never true. probably doesn't work very well
bIsVan = false;
bIsBus = false;
bIsBig = false;
bLowVehicle = false;
m_bombType = CARBOMB_NONE;
m_pBombRigger = nil;
bDriverLastFrame = false;
m_nSetPieceExtendedRangeTime = 0;
m_nAlarmState = 0;
m_nDoorLock = CARLOCK_UNLOCKED;
m_nLastWeaponDamage = -1;
m_pLastDamageEntity = nil;
m_fMapObjectHeightAhead = m_fMapObjectHeightBehind = 0.0f;
m_audioEntityId = DMAudio.CreateEntity(AUDIOTYPE_PHYSICAL, this);
if(m_audioEntityId >= 0)
DMAudio.SetEntityStatus(m_audioEntityId, TRUE);
//m_nRadioStation = CGeneral::GetRandomNumber() % NUM_RADIOS;
switch(GetModelIndex()){
case MI_HUNTER:
case MI_ANGEL:
case MI_ANGEL2:
case MI_FREEWAY:
m_nRadioStation = V_ROCK;
break;
case MI_RCBARON:
case MI_RCBANDIT:
case MI_RCRAIDER:
case MI_RCGOBLIN:
case MI_TOPFUN:
case MI_CADDY:
case MI_BAGGAGE:
m_nRadioStation = RADIO_OFF;
break;
default:
m_nRadioStation = CGeneral::GetRandomNumber() % NUM_RADIOS;
break;
}
m_pCurGroundEntity = nil;
m_bRainAudioCounter = 0;
m_bRainSamplesCounter = 0;
m_comedyControlState = 0;
m_aCollPolys[0].valid = false;
m_aCollPolys[1].valid = false;
AutoPilot.m_nCarMission = MISSION_NONE;
AutoPilot.m_nTempAction = TEMPACT_NONE;
AutoPilot.m_nTimeToStartMission = CTimer::GetTimeInMilliseconds();
AutoPilot.m_bStayInCurrentLevel = false;
AutoPilot.m_bIgnorePathfinding = false;
AutoPilot.m_nSwitchDistance = 20;
}
CVehicle::~CVehicle()
{
//TODO(LCS): clear something in music manager (?)
m_nAlarmState = 0;
if (m_audioEntityId >= 0){
DMAudio.DestroyEntity(m_audioEntityId);
m_audioEntityId = -5;
}
CRadar::ClearBlipForEntity(BLIP_CAR, CPools::GetVehiclePool()->GetIndex(this));
if (pDriver)
pDriver->FlagToDestroyWhenNextProcessed();
for (int i = 0; i < m_nNumMaxPassengers; i++){
if (pPassengers[i])
pPassengers[i]->FlagToDestroyWhenNextProcessed();
}
if (m_pCarFire)
m_pCarFire->Extinguish();
CCarCtrl::UpdateCarCount(this, true);
if (bIsAmbulanceOnDuty){
CCarCtrl::NumAmbulancesOnDuty--;
bIsAmbulanceOnDuty = false;
}
if (bIsFireTruckOnDuty){
CCarCtrl::NumFiretrucksOnDuty--;
bIsFireTruckOnDuty = false;
}
}
void
CVehicle::SetModelIndex(uint32 id)
{
CEntity::SetModelIndex(id);
m_aExtras[0] = CVehicleModelInfo::mspInfo->ms_compsUsed[0];
m_aExtras[1] = CVehicleModelInfo::mspInfo->ms_compsUsed[1];
m_nNumMaxPassengers = CVehicleModelInfo::GetMaximumNumberOfPassengersFromNumberOfDoors(id);
}
bool
CVehicle::SetupLighting(void)
{
ActivateDirectional();
SetAmbientColoursForPedsCarsAndObjects();
if(bRenderScorched){
WorldReplaceNormalLightsWithScorched(Scene.world, 0.1f);
}else{
CVector coors = GetPosition();
float lighting = CPointLights::GenerateLightsAffectingObject(&coors);
if(lighting != 1.0f){
SetAmbientAndDirectionalColours(lighting);
return true;
}
}
return false;
}
void
CVehicle::RemoveLighting(bool reset)
{
CRenderer::RemoveVehiclePedLights(this, reset);
SetAmbientColours();
DeActivateDirectional();
}
bool
CVehicle::IsClearToDriveAway(void)
{
CColPoint point;
float length = GetColModel()->boundingBox.GetSize().y;
CEntity *ent = nil;
CVector front = GetForward() * (length*0.5f + 3.0f);
return !CWorld::ProcessLineOfSight(GetPosition() + front, GetPosition(),
point, ent, true, true, false, false, false, true, true) ||
ent == this;
}
float
CVehicle::GetHeightAboveRoad(void)
{
return -1.0f * GetColModel()->boundingBox.min.z;
}
void
CVehicle::FlyingControl(eFlightModel flightModel)
{
if(pFlyingHandling == nil)
return;
switch(flightModel){
case FLIGHT_MODEL_DODO:
{
// This seems pretty magic
// Move Left/Right
float moveSpeed = m_vecMoveSpeed.Magnitude();
float sideSpeed = DotProduct(m_vecMoveSpeed, GetRight());
float sideImpulse = -1.0f * sideSpeed / moveSpeed;
float fwdSpeed = DotProduct(m_vecMoveSpeed, GetForward());
float magic = m_vecMoveSpeed.MagnitudeSqr() * sq(fwdSpeed);
float turnImpulse = (sideImpulse*0.003f + m_fSteerAngle*0.001f) *
magic*m_fTurnMass*CTimer::GetTimeStep();
ApplyTurnForce(turnImpulse*GetRight(), -4.0f*GetForward());
float impulse = sideImpulse*0.2f *
magic*m_fMass*CTimer::GetTimeStep();
ApplyMoveForce(impulse*GetRight());
ApplyTurnForce(impulse*GetRight(), 2.0f*GetUp());
// Move Up/Down
moveSpeed = m_vecMoveSpeed.Magnitude();
float upSpeed = DotProduct(m_vecMoveSpeed, GetUp());
float upImpulse = -1.0f * upSpeed / moveSpeed;
turnImpulse = (upImpulse*0.002f + -CPad::GetPad(0)->GetSteeringUpDown()/128.0f*0.001f) *
magic*m_fTurnMass*CTimer::GetTimeStep();
ApplyTurnForce(turnImpulse*GetUp(), -4.0f*GetForward());
impulse = (upImpulse*3.5f + 0.5f)*0.05f *
magic*m_fMass*CTimer::GetTimeStep();
if(GRAVITY*m_fMass*CTimer::GetTimeStep() < impulse &&
GetPosition().z > 100.0f)
impulse = 0.9f*GRAVITY*m_fMass*CTimer::GetTimeStep();
CVector com = Multiply3x3(GetMatrix(), m_vecCentreOfMass);
ApplyMoveForce(impulse*GetUp());
ApplyTurnForce(impulse*GetUp(), 2.0f*GetUp() + com);
m_vecTurnSpeed.y *= Pow(0.9f, CTimer::GetTimeStep());
moveSpeed = m_vecMoveSpeed.MagnitudeSqr();
if(moveSpeed > SQR(1.5f))
m_vecMoveSpeed *= 1.5f/Sqrt(moveSpeed);
float turnSpeed = m_vecTurnSpeed.MagnitudeSqr();
if(turnSpeed > SQR(0.2f))
m_vecTurnSpeed *= 0.2f/Sqrt(turnSpeed);
break;
}
case FLIGHT_MODEL_RCPLANE:
case FLIGHT_MODEL_SEAPLANE:
case FLIGHT_MODEL_PLANE_UNUSED:
case FLIGHT_MODEL_PLANE:
{
float fSteerLR = CPad::GetPad(0)->GetSteeringLeftRight() / 128.0f;
float fSteerUD = CPad::GetPad(0)->GetSteeringUpDown() / 128.0f;
/*
float fGunUD = Abs(CPad::GetPad(0)->GetCarGunUpDown());
#ifdef FREE_CAM
if(!CCamera::bFreeCam || (CCamera::bFreeCam && !CPad::IsAffectedByController))
#endif
if(fGunUD > 1.0f)
fSteerUD = -CPad::GetPad(0)->GetCarGunUpDown() / 128.0f;
*/
float fSteerAngle = fSteerUD != 0.0f && fSteerLR != 0.0f ? Atan2(fSteerUD, fSteerLR) : 0.0f;
float fSteerMult = 1.0f;
if(fSteerAngle > -PI/4.0f && fSteerAngle <= PI/4.0f)
fSteerMult = 1.0f/Cos(fSteerAngle);
else if(fSteerAngle > PI/4.0f && fSteerAngle <= PI*3.0f/4.0f)
fSteerMult = 1.0f/Cos(fSteerAngle - HALFPI);
else if(fSteerAngle > PI*3.0f/4.0f)
fSteerMult = 1.0f/Cos(fSteerAngle - PI);
else if(fSteerAngle <= -PI*3.0f/4.0f)
fSteerMult = 1.0f/Cos(fSteerAngle + PI);
else if(fSteerAngle > -PI*3.0f/4.0f && fSteerAngle < -PI/4.0f)
fSteerMult = 1.0f/Cos(fSteerAngle + HALFPI);
fSteerLR *= fSteerMult;
fSteerUD *= -fSteerMult;
// thrust
float fThrust = pFlyingHandling->fThrust;
float fThrustFallOff = pFlyingHandling->fThrustFallOff;
float fThrustFallOffBack = pFlyingHandling->fThrustFallOff * 8.0f;
#ifdef BETTER_ALLCARSAREDODO_CHEAT
if (bAllDodosCheat && !IsRealPlane()) {
fThrust = pHandling->Transmission.fEngineAcceleration
* (pHandling->Transmission.nDriveType == '4' ? 4.0f : 2.0f);
fThrust = 5.0f * Max(fThrust, pFlyingHandling->fThrust); //tweak: (cars engines too weak to thrust car on air)
fThrustFallOff = Min(0.7f / pHandling->Transmission.fMaxVelocity, fThrustFallOff); //tweak: (use 0.7 instead of 1.0 to make cars 30% faster)
fThrustFallOffBack = -1.0f / pHandling->Transmission.fMaxReverseVelocity;
}
#endif
float fForwSpeed = DotProduct(GetMoveSpeed(), GetForward());
CVector vecTail = GetColModel()->boundingBox.min.y * GetForward();
float fPedalState = (CPad::GetPad(0)->GetAccelerate() - CPad::GetPad(0)->GetBrake()) / 255.0f;
float fThrustAccel;
if(fForwSpeed > 0.0f || fPedalState > 0.0f)
fThrustAccel = (fPedalState - fThrustFallOff * fForwSpeed) * fThrust;
else
fThrustAccel = Min(fPedalState - fThrustFallOffBack * fForwSpeed, 0.0f) * fThrust;
if(flightModel == FLIGHT_MODEL_PLANE_UNUSED)
fThrustAccel *= 0.3f;
else if(flightModel == FLIGHT_MODEL_PLANE)
fThrustAccel *= 0.1f;
ApplyMoveForce(fThrustAccel * GetForward() * m_fMass * CTimer::GetTimeStep());
// left/right
float fSideSpeed = -DotProduct(GetMoveSpeed(), GetRight());
float fSideSlipAccel = pFlyingHandling->fSideSlip * fSideSpeed * Abs(fSideSpeed);
ApplyMoveForce(m_fMass * GetRight() * fSideSlipAccel * CTimer::GetTimeStep());
float fYaw = -DotProduct(GetSpeed(vecTail), GetRight());
float fYawAccel = pFlyingHandling->fYawStab * fYaw * Abs(fYaw) + pFlyingHandling->fYaw * fSteerLR * fForwSpeed;
ApplyTurnForce(fYawAccel * GetRight() * m_fTurnMass * CTimer::GetTimeStep(), vecTail);
float fRollAccel;
if (flightModel == FLIGHT_MODEL_RCPLANE) {
float fDirectionMultiplier = CPad::GetPad(0)->GetLookRight();
if (CPad::GetPad(0)->GetLookLeft())
fDirectionMultiplier = -1;
fRollAccel = (0.5f * fDirectionMultiplier + fSteerLR) * pFlyingHandling->fRoll;
}
else
fRollAccel = fSteerLR * pFlyingHandling->fRoll;
ApplyTurnForce(GetRight() * fRollAccel * fForwSpeed * m_fTurnMass * CTimer::GetTimeStep(), GetUp());
CVector vecFRight = CrossProduct(GetForward(), CVector(0.0f, 0.0f, 1.0f));
CVector vecStabilise = (GetUp().z > 0.0f) ? vecFRight : -vecFRight;
float fStabiliseDirection = (GetRight().z > 0.0f) ? -1.0f : 1.0f;
float fStabiliseSpeed = pFlyingHandling->fRollStab * fStabiliseDirection * (1.0f - DotProduct(GetRight(), vecStabilise)) * (1.0f - Abs(GetForward().z));
ApplyTurnForce(fStabiliseSpeed * m_fTurnMass * GetRight(), GetUp()); // no CTimer::GetTimeStep(), is it right?
// up/down
float fTail = -DotProduct(GetSpeed(vecTail), GetUp());
float fPitchAccel = pFlyingHandling->fPitchStab * fTail * Abs(fTail) + pFlyingHandling->fPitch * fSteerUD * fForwSpeed;
ApplyTurnForce(fPitchAccel * m_fTurnMass * GetUp() * CTimer::GetTimeStep(), vecTail);
float fLift = DotProduct(GetMoveSpeed(), GetUp()) / Max(0.01f, GetMoveSpeed().Magnitude()); //accel*angle
float fLiftAccel = (pFlyingHandling->fFormLift - pFlyingHandling->fAttackLift * fLift) * SQR(fForwSpeed);
float fLiftImpulse = fLiftAccel * m_fMass * CTimer::GetTimeStep();
if (GRAVITY * CTimer::GetTimeStep() * m_fMass < fLiftImpulse) {
if (flightModel == FLIGHT_MODEL_RCPLANE && GetPosition().z > 50.0f)
fLiftImpulse = CTimer::GetTimeStep() * 0.9f*GRAVITY * m_fMass;
else if (flightModel == FLIGHT_MODEL_SEAPLANE && GetPosition().z > 80.0f)
fLiftImpulse = CTimer::GetTimeStep() * 0.9f*GRAVITY * m_fMass;
#ifdef BETTER_ALLCARSAREDODO_CHEAT
else if(bAllDodosCheat && GetPosition().z > 170.0f)
fLiftImpulse = CTimer::GetTimeStep() * 0.9f * GRAVITY * m_fMass;
#endif
}
ApplyMoveForce(fLiftImpulse * GetUp());
CVector vecResistance;
vecResistance = pFlyingHandling->vecTurnRes;
float rX = Pow(vecResistance.x, CTimer::GetTimeStep());
float rY = Pow(vecResistance.y, CTimer::GetTimeStep());
float rZ = Pow(vecResistance.z, CTimer::GetTimeStep());
CVector vecTurnSpeed = Multiply3x3(m_vecTurnSpeed, GetMatrix());
vecTurnSpeed.x *= rX;
float fResistance = vecTurnSpeed.y * (1.0f / (pFlyingHandling->vecSpeedRes.y * SQR(vecTurnSpeed.y) + 1.0f)) * rY - vecTurnSpeed.y;
vecTurnSpeed.z *= rZ;
m_vecTurnSpeed = Multiply3x3(GetMatrix(), vecTurnSpeed);
ApplyTurnForce(-GetUp() * fResistance * m_fTurnMass, GetRight() + Multiply3x3(GetMatrix(), m_vecCentreOfMass));
/*
float fMoveSpeed = m_vecMoveSpeed.MagnitudeSqr();
if(fMoveSpeed > SQR(1.5f))
m_vecMoveSpeed *= 1.5f/Sqrt(fMoveSpeed);
float fTurnSpeed = m_vecTurnSpeed.MagnitudeSqr();
if(fTurnSpeed > SQR(0.2f))
m_vecTurnSpeed *= 0.2f/Sqrt(fTurnSpeed);
*/
break;
}
case FLIGHT_MODEL_RCHELI:
case FLIGHT_MODEL_HELI:
{
#ifdef RESTORE_ALLCARSHELI_CHEAT
tFlyingHandlingData* flyingHandling = bAllCarCheat && !IsRealHeli() ? mod_HandlingManager.GetFlyingPointer(HANDLING_MAVERICK) : pFlyingHandling;
#else
tFlyingHandlingData* flyingHandling = pFlyingHandling;
#endif
float rm = Pow(flyingHandling->fMoveRes, CTimer::GetTimeStep());
m_vecMoveSpeed *= rm;
if (GetStatus() != STATUS_PLAYER && GetStatus() != STATUS_PLAYER_REMOTE)
return;
float fUpSpeed = DotProduct(m_vecMoveSpeed, GetUp());
float fThrust = (CPad::GetPad(0)->GetAccelerate() - CPad::GetPad(0)->GetBrake()) / 255.0f;
#ifdef FREE_CAM
if(!CCamera::bFreeCam || (CCamera::bFreeCam && !CPad::IsAffectedByController))
#endif
if(Abs(CPad::GetPad(0)->GetCarGunUpDown()) > 1.0f)
fThrust = CPad::GetPad(0)->GetCarGunUpDown() / 128.0f;
if(fThrust < 0.0f)
fThrust *= 2.0f;
if(flightModel == FLIGHT_MODEL_RCHELI){
fThrust = flyingHandling->fThrust * fThrust + 0.45f;
ApplyMoveForce(GRAVITY * CVector(0.0f, 0.0f, 0.5f) * m_fMass * CTimer::GetTimeStep());
}else
fThrust = flyingHandling->fThrust * fThrust + 0.95f;
fThrust -= flyingHandling->fThrustFallOff * fUpSpeed;
if(flightModel == FLIGHT_MODEL_RCHELI && GetPosition().z > rcHeliHeightLimit)
fThrust *= 10.0f/(GetPosition().z - 30.0f);
else if(GetPosition().z > 80.0f)
fThrust *= 10.0f/(GetPosition().z - 70.0f);
ApplyMoveForce(GRAVITY * GetUp() * fThrust * m_fMass * CTimer::GetTimeStep());
if (GetUp().z > 0.0f){
float upRight = Clamp(GetRight().z, -flyingHandling->fFormLift, flyingHandling->fFormLift);
float upImpulseRight = -upRight * flyingHandling->fAttackLift * m_fTurnMass * CTimer::GetTimeStep();
ApplyTurnForce(upImpulseRight * GetUp(), GetRight());
float upFwd = Clamp(GetForward().z, -flyingHandling->fFormLift, flyingHandling->fFormLift);
float upImpulseFwd = -upFwd * flyingHandling->fAttackLift * m_fTurnMass * CTimer::GetTimeStep();
ApplyTurnForce(upImpulseFwd * GetUp(), GetForward());
}else{
float upRight = GetRight().z < 0.0f ? -flyingHandling->fFormLift : flyingHandling->fFormLift;
float upImpulseRight = -upRight * flyingHandling->fAttackLift * m_fTurnMass * CTimer::GetTimeStep();
ApplyTurnForce(upImpulseRight * GetUp(), GetRight());
float upFwd = GetForward().z < 0.0f ? -flyingHandling->fFormLift : flyingHandling->fFormLift;
float upImpulseFwd = -upFwd * flyingHandling->fAttackLift * m_fTurnMass * CTimer::GetTimeStep();
ApplyTurnForce(upImpulseFwd * GetUp(), GetForward());
}
float fRoll, fPitch, fYaw;
if (bCheat5) {
fPitch = CPad::GetPad(0)->GetSteeringUpDown() / 128.0f;
fRoll = CPad::GetPad(0)->GetLookLeft();
if (CPad::GetPad(0)->GetLookRight())
fRoll = -1.0f;
fYaw = CPad::GetPad(0)->GetSteeringLeftRight() / 128.0f;
} else {
fPitch = CPad::GetPad(0)->GetSteeringUpDown() / 128.0f;
fRoll = -CPad::GetPad(0)->GetSteeringLeftRight() / 128.0f;
fYaw = CPad::GetPad(0)->GetLookRight();
if (CPad::GetPad(0)->GetLookLeft())
fYaw = -1.0f;
#ifdef FREE_CAM
if (!CCamera::bFreeCam || (CCamera::bFreeCam && !CPad::IsAffectedByController))
#endif
if(Abs(CPad::GetPad(0)->GetCarGunLeftRight()) > 1.0f)
fYaw = CPad::GetPad(0)->GetCarGunLeftRight() / 128.0f;
}
/*
#ifdef FREE_CAM
if(!CCamera::bFreeCam || (CCamera::bFreeCam && !CPad::IsAffectedByController))
#endif
if(Abs(CPad::GetPad(0)->GetCarGunUpDown()) > 1.0f)
fPitch = -CPad::GetPad(0)->GetCarGunUpDown() / 128.0f;
*/
if (CPad::GetPad(0)->GetHorn()) {
fYaw = 0.0f;
fPitch = Clamp(flyingHandling->fPitchStab * DotProduct(m_vecMoveSpeed, GetForward()), -200.0f, 1.3f);
fRoll = Clamp(flyingHandling->fRollStab * DotProduct(m_vecMoveSpeed, GetRight()), -200.0f, 1.3f);
}
ApplyTurnForce(fPitch * GetUp() * flyingHandling->fPitch * m_fTurnMass * CTimer::GetTimeStep(), GetForward());
ApplyTurnForce(fRoll * GetUp() * flyingHandling->fRoll * m_fTurnMass * CTimer::GetTimeStep(), GetRight());
float fSideSpeed = -DotProduct(GetMoveSpeed(), GetRight());
float fSideSlipAccel = flyingHandling->fSideSlip * fSideSpeed * Abs(fSideSpeed);
ApplyMoveForce(m_fMass * GetRight() * fSideSlipAccel * CTimer::GetTimeStep());
float fYawAccel = flyingHandling->fYawStab * fSideSpeed * Abs(fSideSpeed) + flyingHandling->fYaw * fYaw;
ApplyTurnForce(fYawAccel * GetRight() * m_fTurnMass * CTimer::GetTimeStep(), -GetForward());
ApplyTurnForce(fYaw * GetForward() * flyingHandling->fYaw * m_fTurnMass * CTimer::GetTimeStep(), GetRight());
float rX = Pow(flyingHandling->vecTurnRes.x, CTimer::GetTimeStep());
float rY = Pow(flyingHandling->vecTurnRes.y, CTimer::GetTimeStep());
float rZ = Pow(flyingHandling->vecTurnRes.z, CTimer::GetTimeStep());
CVector vecTurnSpeed = Multiply3x3(m_vecTurnSpeed, GetMatrix());
float fResistanceMultiplier = Pow(1.0f / (flyingHandling->vecSpeedRes.z * SQR(vecTurnSpeed.z) + 1.0f) * rZ, CTimer::GetTimeStep());
float fResistance = vecTurnSpeed.z * fResistanceMultiplier - vecTurnSpeed.z;
vecTurnSpeed.x *= rX;
vecTurnSpeed.y *= rY;
vecTurnSpeed.z *= fResistanceMultiplier;
m_vecTurnSpeed = Multiply3x3(GetMatrix(), vecTurnSpeed);
ApplyTurnForce(-GetRight() * fResistance * m_fTurnMass, GetForward() + Multiply3x3(GetMatrix(), m_vecCentreOfMass));
break;
}
}
}
static CColModel rotorColModel;
static CColSphere rotorColSphere;
float ROTOR_SEMI_THICKNESS = 0.05f;
float ROTOR_TURN_SPEED = 0.2f;
float ROTOR_DISGUARD_MULT = 0.3f;
float ROTOR_COL_ELASTICITY = 1.0f;
float ROTOR_COL_TURNMULT = -0.001f;
float ROTOR_DEFAULT_DAMAGE = 100.0f;
bool
CVehicle::DoBladeCollision(CVector pos, CMatrix &matrix, int16 rotorType, float radius, float damageMult)
{
CVector max(radius, radius, radius);
CVector min(-radius, -radius, -radius);
switch(rotorType){
case ROTOR_TOP:
case ROTOR_BOTTOM:
min.z = -ROTOR_SEMI_THICKNESS;
max.z = ROTOR_SEMI_THICKNESS;
break;
case ROTOR_FRONT:
case ROTOR_BACK:
min.y = -ROTOR_SEMI_THICKNESS;
max.y = ROTOR_SEMI_THICKNESS;
break;
case ROTOR_RIGHT:
case ROTOR_LEFT:
min.x = -ROTOR_SEMI_THICKNESS;
max.x = ROTOR_SEMI_THICKNESS;
break;
}
min += pos;
max += pos;
rotorColModel.boundingBox.Set(min, max);
rotorColModel.boundingSphere.Set(radius, pos);
rotorColSphere.Set(radius, pos, 0, 0);
rotorColModel.spheres = &rotorColSphere;
rotorColModel.numSpheres = 1;
pos = matrix * pos;
bool hadCollision = false;
int minX = CWorld::GetSectorIndexX(pos.x - radius);
if(minX <= 0) minX = 0;
int minY = CWorld::GetSectorIndexY(pos.y - radius);
if(minY <= 0) minY = 0;
int maxX = CWorld::GetSectorIndexX(pos.x + radius);
#ifdef FIX_BUGS
if(maxX >= NUMSECTORS_X) maxX = NUMSECTORS_X - 1;
#else
if(maxX >= NUMSECTORS_X) maxX = NUMSECTORS_X;
#endif
int maxY = CWorld::GetSectorIndexY(pos.y + radius);
#ifdef FIX_BUGS
if(maxY >= NUMSECTORS_Y) maxY = NUMSECTORS_Y - 1;
#else
if(maxY >= NUMSECTORS_Y) maxY = NUMSECTORS_Y;
#endif
CWorld::AdvanceCurrentScanCode();
for(int curY = minY; curY <= maxY; curY++) {
for(int curX = minX; curX <= maxX; curX++) {
CSector *sector = CWorld::GetSector(curX, curY);
if(BladeColSectorList(sector->m_lists[ENTITYLIST_BUILDINGS], rotorColModel, matrix, rotorType, damageMult))
hadCollision = true;
if(BladeColSectorList(sector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP], rotorColModel, matrix, rotorType, damageMult))
hadCollision = true;
if(BladeColSectorList(sector->m_lists[ENTITYLIST_VEHICLES], rotorColModel, matrix, rotorType, damageMult))
hadCollision = true;
if(BladeColSectorList(sector->m_lists[ENTITYLIST_VEHICLES_OVERLAP], rotorColModel, matrix, rotorType, damageMult))
hadCollision = true;
if(BladeColSectorList(sector->m_lists[ENTITYLIST_PEDS], rotorColModel, matrix, rotorType, 0.0f))
hadCollision = true;
if(BladeColSectorList(sector->m_lists[ENTITYLIST_PEDS_OVERLAP], rotorColModel, matrix, rotorType, 0.0f))
hadCollision = true;
if(BladeColSectorList(sector->m_lists[ENTITYLIST_OBJECTS], rotorColModel, matrix, rotorType, damageMult))
hadCollision = true;
if(BladeColSectorList(sector->m_lists[ENTITYLIST_OBJECTS_OVERLAP], rotorColModel, matrix, rotorType, damageMult))
hadCollision = true;
}
}
rotorColModel.spheres = nil;
rotorColModel.numSpheres = 0;
return hadCollision;
}
bool
CVehicle::BladeColSectorList(CPtrList &list, CColModel &rotorColModel, CMatrix &matrix, int16 rotorType, float damageMult)
{
int i;
CVector axis;
CVector turnSpeed(0.0f, 0.0f, 0.0f);
switch(rotorType){
case ROTOR_TOP:
turnSpeed.z = -ROTOR_TURN_SPEED;
axis = -matrix.GetUp();
break;
case ROTOR_BOTTOM:
turnSpeed.z = ROTOR_TURN_SPEED;
axis = matrix.GetUp();
break;
case ROTOR_FRONT:
turnSpeed.y = -ROTOR_TURN_SPEED;
axis = -matrix.GetForward();
break;
case ROTOR_BACK:
turnSpeed.y = ROTOR_TURN_SPEED;
axis = matrix.GetForward();
break;
case ROTOR_RIGHT:
turnSpeed.x = -ROTOR_TURN_SPEED;
axis = -matrix.GetRight();
break;
case ROTOR_LEFT:
turnSpeed.x = ROTOR_TURN_SPEED;
axis = matrix.GetRight();
break;
}
turnSpeed = Multiply3x3(matrix, turnSpeed);
CVector center = rotorColModel.boundingSphere.center;
center = matrix*center;
for(CPtrNode *node = list.first; node; node = node->next) {
CEntity *entity = (CEntity *)node->item;
if(entity == (CEntity*)this ||
!entity->bUsesCollision ||
entity->m_scanCode == CWorld::GetCurrentScanCode())
continue;
entity->m_scanCode = CWorld::GetCurrentScanCode();
int numCollisions;
CColModel *entityCol;
if(entity->IsPed())
entityCol = ((CPedModelInfo*)CModelInfo::GetModelInfo(entity->GetModelIndex()))->AnimatePedColModelSkinned(entity->GetClump());
else
entityCol = entity->GetColModel();
if(entityCol)
numCollisions = CCollision::ProcessColModels(matrix, rotorColModel, entity->GetMatrix(), *entityCol,
CWorld::m_aTempColPts, nil, nil);
else
numCollisions = 0;
if(numCollisions > 0 && entity->IsPed()){
CPed *ped = (CPed*)entity;
CVector2D dirToRotor = GetPosition() - entity->GetPosition();
dirToRotor.Normalise();
int localDir = ped->GetLocalDirection(dirToRotor);
if(ped->m_attachedTo == nil){
ped->bIsStanding = false;
ped->ApplyMoveForce(-5.0f*dirToRotor.x, -5.0f*dirToRotor.y, 5.0f);
}
ped->InflictDamage(this, WEAPONTYPE_RUNOVERBYCAR, 1000.0f, PEDPIECE_TORSO, localDir);
if(ped->GetIsOnScreen()){
for(i = 0; i < 16; i++)
CParticle::AddParticle(PARTICLE_BLOOD_SMALL, ped->GetPosition(), CVector(dirToRotor.x, dirToRotor.y, 1.0f) * 0.01f);
CParticle::AddParticle(PARTICLE_TEST, ped->GetPosition(), CVector(0.0f, 0.0f, 0.02f), nil, 0.1f);
CParticle::AddParticle(PARTICLE_TEST, ped->GetPosition()+CVector(0.0f, 0.0f, 0.2f), CVector(0.0f, 0.0f, -0.01f), nil, 0.1f);
}
}else if(numCollisions > 0 && entity->GetModelIndex() != MI_MISSILE){
float impulse = 0.0f;
bool hadCollision = false;
float savedElasticity = m_fElasticity;
m_fElasticity = ROTOR_COL_ELASTICITY;
for(i = 0; i < numCollisions; i++){
CVector colpos = CWorld::m_aTempColPts[i].point;
CVector localColpos = colpos - center;
float axisDir = DotProduct(axis, localColpos);
float colDir = DotProduct(CWorld::m_aTempColPts[i].normal, localColpos);
if(2.0f*ROTOR_SEMI_THICKNESS < Abs(axisDir) &&
ROTOR_DISGUARD_MULT*Abs(colDir) < Abs(axisDir))
continue;
hadCollision = true;
colpos -= axisDir*axis; // get rid of axis component
CVector tangentSpeed = CrossProduct(turnSpeed, colpos - center);
// Particles
for(int j = 0; j < 4; j++){
CParticle::AddParticle(PARTICLE_SPARK_SMALL, colpos, (tangentSpeed+m_vecMoveSpeed)/2.0f);
CParticle::AddParticle(PARTICLE_SPARK, colpos, 0.1f*CWorld::m_aTempColPts[i].normal);
}
// Apply Collision
if(IsCar()){
CAutomobile *heli = (CAutomobile*)this;
if(heli->m_aWheelSpeed[1] > 0.15f){
ApplyCollision(CWorld::m_aTempColPts[i], impulse);
ApplyTurnForce(m_fTurnMass*ROTOR_COL_TURNMULT*tangentSpeed, colpos - center);
heli->m_aWheelSpeed[1] = 0.15f;
}else if(heli->m_aWheelSpeed[1] < 0.075f && heli->m_aWheelSpeed[1] > 0.0f)
heli->m_aWheelSpeed[1] *= -1.0f;
}
float damageImpulse = damageMult * Max(impulse, ROTOR_DEFAULT_DAMAGE*m_fMass/3000.0f);
if(damageImpulse > m_fDamageImpulse)
SetDamagedPieceRecord(0, damageImpulse, entity, CWorld::m_aTempColPts[i].normal);
}
if(hadCollision && !entity->IsPed())
DMAudio.ReportCollision(this, entity, SURFACE_CAR_PANEL, SURFACE_TARMAC, 50.0f, 0.09f);
m_fElasticity = savedElasticity;
}
}
return false;
}
float WS_ALREADY_SPINNING_LOSS = 0.2f;
float WS_TRAC_FRAC_LIMIT = 0.3f;
float fBurstSpeedMax = 0.2f;
float fBurstTyreMod = 0.13f;
void
CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelContactSpeed, CVector &wheelContactPoint,
int32 wheelsOnGround, float thrust, float brake, float adhesion, int8 wheelId, float *wheelSpeed, tWheelState *wheelState, uint16 wheelStatus)
{
// BUG: using statics here is probably a bad idea
static bool bAlreadySkidding = false; // this is never reset
static bool bBraking;
static bool bDriving;
#ifdef FIX_SIGNIFICANT_BUGS
bAlreadySkidding = false;
#endif
// how much force we want to apply in these axes
float fwd = 0.0f;
float right = 0.0f;
bBraking = brake != 0.0f;
if(bBraking)
thrust = 0.0f;
bDriving = thrust != 0.0f;
float contactSpeedFwd = DotProduct(wheelContactSpeed, wheelFwd);
float contactSpeedRight = DotProduct(wheelContactSpeed, wheelRight);
adhesion *= CTimer::GetTimeStep();
if(*wheelState != WHEEL_STATE_NORMAL){
bAlreadySkidding = true;
adhesion *= pHandling->fTractionLoss;
if(*wheelState == WHEEL_STATE_SPINNING && (GetStatus() == STATUS_PLAYER || GetStatus() == STATUS_PLAYER_REMOTE))
adhesion *= 1.0f - Abs(m_fGasPedal) * WS_ALREADY_SPINNING_LOSS;
}
*wheelState = WHEEL_STATE_NORMAL;
// moving sideways
if(contactSpeedRight != 0.0f){
// exert opposing force
right = -contactSpeedRight/wheelsOnGround;
// BUG?
// contactSpeedRight is independent of framerate but right has timestep as a factor
// so we probably have to fix this
// fixing this causes jittery cars at 15fps, and causes the car to move backwards slowly at 18fps
// at 19fps, the effects are gone ...
//right *= CTimer::GetTimeStepFix();
if(wheelStatus == WHEEL_STATUS_BURST){
float fwdspeed = Min(contactSpeedFwd, fBurstSpeedMax);
right += fwdspeed * CGeneral::GetRandomNumberInRange(-fBurstTyreMod, fBurstTyreMod);
}
}
if(bDriving){
fwd = thrust;
// limit sideways force (why?)
if(right > 0.0f){
if(right > adhesion)
right = adhesion;
}else{
if(right < -adhesion)
right = -adhesion;
}
}else if(contactSpeedFwd != 0.0f){
fwd = -contactSpeedFwd/wheelsOnGround;
#ifdef FIX_BUGS
// contactSpeedFwd is independent of framerate but fwd has timestep as a factor
// so we probably have to fix this
// better get rid of it here too
//fwd *= CTimer::GetTimeStepFix();
#endif
if(!bBraking){
if(m_fGasPedal < 0.01f){
if(IsBike())
brake = 0.6f * mod_HandlingManager.fWheelFriction / (pHandling->GetMass() + 200.0f);
else if(IsPlane())
brake = 0.0f;
else if(pHandling->GetMass() < 500.0f)
brake = 0.1f * mod_HandlingManager.fWheelFriction / pHandling->GetMass();
else if(GetModelIndex() == MI_RCBANDIT)
brake = 0.2f * mod_HandlingManager.fWheelFriction / pHandling->GetMass();
else
brake = mod_HandlingManager.fWheelFriction / pHandling->GetMass();
#ifdef FIX_BUGS
brake *= CTimer::GetTimeStepFix();
#endif
}
}
if(brake > adhesion){
if(Abs(contactSpeedFwd) > 0.005f)
*wheelState = WHEEL_STATE_FIXED;
}else {
if(fwd > 0.0f){
if(fwd > brake)
fwd = brake;
}else{
if(fwd < -brake)
fwd = -brake;
}
}
}
float speedSq = sq(right) + sq(fwd);
if(sq(adhesion) < speedSq){
if(*wheelState != WHEEL_STATE_FIXED){
float tractionLimit = WS_TRAC_FRAC_LIMIT;
if(contactSpeedFwd > 0.15f && (wheelId == CARWHEEL_FRONT_LEFT || wheelId == CARWHEEL_FRONT_RIGHT))
tractionLimit *= 2.0f;
if(bDriving && tractionLimit*adhesion < Abs(fwd))
*wheelState = WHEEL_STATE_SPINNING;
else
*wheelState = WHEEL_STATE_SKIDDING;
}
float l = Sqrt(speedSq);
float tractionLoss = bAlreadySkidding ? 1.0f : pHandling->fTractionLoss;
if(*wheelState == WHEEL_STATE_SPINNING && (GetStatus() == STATUS_PLAYER || GetStatus() == STATUS_PLAYER_REMOTE))
tractionLoss *= 1.0f - Abs(m_fGasPedal) * WS_ALREADY_SPINNING_LOSS;
right *= adhesion * tractionLoss / l;
fwd *= adhesion * tractionLoss / l;
}
if(fwd != 0.0f || right != 0.0f){
CVector totalSpeed = fwd*wheelFwd + right*wheelRight;
CVector turnDirection = totalSpeed;
bool separateTurnForce = false;
if(pHandling->fSuspensionAntidiveMultiplier > 0.0f){
if(bBraking){
separateTurnForce = true;
turnDirection = totalSpeed - pHandling->fSuspensionAntidiveMultiplier*fwd*wheelFwd;
}else if(bDriving){
separateTurnForce = true;
turnDirection = totalSpeed - 0.5f*pHandling->fSuspensionAntidiveMultiplier*fwd*wheelFwd;
}
}
CVector direction = totalSpeed;
float speed = totalSpeed.Magnitude();
float turnSpeed;
if(separateTurnForce)
turnSpeed = turnDirection.Magnitude();
else
turnSpeed = speed;
direction.Normalise();
if(separateTurnForce)
turnDirection.Normalise();
else
turnDirection = direction;
float impulse = speed*m_fMass;
float turnImpulse = turnSpeed*GetMass(wheelContactPoint, turnDirection);
ApplyMoveForce(impulse * direction);
ApplyTurnForce(turnImpulse * turnDirection, wheelContactPoint);
}
}
float fBurstBikeSpeedMax = 0.08f;
float fBurstBikeTyreMod = 0.05f;
float fTweakBikeWheelTurnForce = 2.0f;
void
CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelContactSpeed, CVector &wheelContactPoint,
int32 wheelsOnGround, float thrust, float brake, float adhesion, float destabTraction, int8 wheelId, float *wheelSpeed, tWheelState *wheelState, eBikeWheelSpecial special, uint16 wheelStatus)
{
// BUG: using statics here is probably a bad idea
static bool bAlreadySkidding = false; // this is never reset
static bool bBraking;
static bool bDriving;
static bool bReversing;
#ifdef FIX_SIGNIFICANT_BUGS
bAlreadySkidding = false;
#endif
// how much force we want to apply in these axes
float fwd = 0.0f;
float right = 0.0f;
bBraking = brake != 0.0f;
if(bBraking)
thrust = 0.0f;
bDriving = thrust != 0.0f;
bReversing = thrust < 0.0f;
float contactSpeedFwd = DotProduct(wheelContactSpeed, wheelFwd);
float contactSpeedRight;
if(*wheelState != WHEEL_STATE_NORMAL)
bAlreadySkidding = true;
*wheelState = WHEEL_STATE_NORMAL;
adhesion *= CTimer::GetTimeStep();
if(bAlreadySkidding)
adhesion *= pHandling->fTractionLoss;
if(special == BIKE_WHEELSPEC_2 || special == BIKE_WHEELSPEC_3)
contactSpeedRight = 0.0f;
else
contactSpeedRight = DotProduct(wheelContactSpeed, wheelRight);
// moving sideways
if(contactSpeedRight != 0.0f){
// exert opposing force
right = -contactSpeedRight/wheelsOnGround;
#ifdef FIX_BUGS
// contactSpeedRight is independent of framerate but right has timestep as a factor
// so we probably have to fix this
// see above
//right *= CTimer::GetTimeStepFix();
#endif
if(wheelStatus == WHEEL_STATUS_BURST){
float fwdspeed = Min(contactSpeedFwd, fBurstBikeSpeedMax);
right += fwdspeed * CGeneral::GetRandomNumberInRange(-fBurstBikeTyreMod, fBurstBikeTyreMod);
}
}
if(bDriving){
fwd = thrust;
// limit sideways force (why?)
if(right > 0.0f){
if(right > adhesion)
right = adhesion;
}else{
if(right < -adhesion)
right = -adhesion;
}
}else if(contactSpeedFwd != 0.0f){
fwd = -contactSpeedFwd/wheelsOnGround;
#ifdef FIX_BUGS
// contactSpeedFwd is independent of framerate but fwd has timestep as a factor
// so we probably have to fix this
// see above
//fwd *= CTimer::GetTimeStepFix();
#endif
if(!bBraking){
if(m_fGasPedal < 0.01f){
if(IsBike())
brake = 0.6f * mod_HandlingManager.fWheelFriction / (pHandling->fMass + 200.0f);
else if(pHandling->fMass < 500.0f)
brake = mod_HandlingManager.fWheelFriction / m_fMass;
else if(GetModelIndex() == MI_RCBANDIT)
brake = 0.2f * mod_HandlingManager.fWheelFriction / m_fMass;
else
brake = mod_HandlingManager.fWheelFriction / m_fMass;
#ifdef FIX_BUGS
brake *= CTimer::GetTimeStepFix();
#endif
}
}
if(brake > adhesion){
if(Abs(contactSpeedFwd) > 0.005f)
*wheelState = WHEEL_STATE_FIXED;
}else {
if(fwd > 0.0f){
if(fwd > brake)
fwd = brake;
}else{
if(fwd < -brake)
fwd = -brake;
}
}
}
float speedSq = sq(right) + sq(fwd);
if(sq(adhesion) < speedSq){
if(*wheelState != WHEEL_STATE_FIXED){
if(bDriving && contactSpeedFwd < 0.2f)
*wheelState = WHEEL_STATE_SPINNING;
else
*wheelState = WHEEL_STATE_SKIDDING;
}
float l = Sqrt(speedSq);
float tractionLoss = bAlreadySkidding ? 1.0f : pHandling->fTractionLoss;
right *= adhesion * tractionLoss / l;
fwd *= adhesion * tractionLoss / l;
if(destabTraction < 1.0f)
right *= destabTraction;
}else if(destabTraction < 1.0f){
if(!bAlreadySkidding)
destabTraction *= pHandling->fTractionLoss;
if(sq(adhesion*destabTraction) < speedSq){
float l = Sqrt(speedSq);
right *= adhesion * destabTraction / l;
}
}
if(fwd != 0.0f || right != 0.0f){
CVector direction = fwd*wheelFwd + right*wheelRight;
float speed = direction.Magnitude();
direction.Normalise();
float impulse = speed*m_fMass;
float turnImpulse = speed*GetMass(wheelContactPoint, direction);
CVector vTurnImpulse = turnImpulse * direction;
ApplyMoveForce(impulse * direction);
float turnRight = DotProduct(vTurnImpulse, GetRight());
float contactRight = DotProduct(wheelContactPoint, GetRight());
float contactFwd = DotProduct(wheelContactPoint, GetForward());
if(wheelId != BIKEWHEEL_REAR || !bBraking && !bReversing)
ApplyTurnForce((vTurnImpulse - turnRight*GetRight()) * fTweakBikeWheelTurnForce,
wheelContactPoint - contactRight*GetRight());
ApplyTurnForce(turnRight*GetRight(), contactFwd*GetForward());
}
}
float
CVehicle::ProcessWheelRotation(tWheelState state, const CVector &fwd, const CVector &speed, float radius)
{
float angularVelocity;
switch(state){
case WHEEL_STATE_SPINNING:
angularVelocity = -1.1f; // constant speed forward
break;
case WHEEL_STATE_FIXED:
angularVelocity = 0.0f; // not moving
break;
default:
angularVelocity = -DotProduct(fwd, speed) / radius; // forward speed
break;
}
return angularVelocity * CTimer::GetTimeStep();
}
int
CVehicle::FindTyreNearestPoint(float x, float y)
{
CVector pos = CVector(x - GetPosition().x, y - GetPosition().y, 0.0f);
float fwd = DotProduct(GetForward(), pos);
float right = DotProduct(GetRight(), pos);
int piece;
if(IsBike()){
piece = fwd > 0.0f ? CAR_PIECE_WHEEL_LF : CAR_PIECE_WHEEL_LR;
}else{
piece = fwd > 0.0f ?
right > 0.0f ? CAR_PIECE_WHEEL_RF : CAR_PIECE_WHEEL_LF :
right > 0.0f ? CAR_PIECE_WHEEL_RR : CAR_PIECE_WHEEL_LR;
}
return piece - CAR_PIECE_WHEEL_LF;
}
bool
CVehicle::PedsShouldScreamOnDisembarking(void)
{
switch(GetModelIndex()){
case MI_AMBULAN:
case MI_TAXI:
case MI_CABBIE:
return false;
default:
return true;
}
}
void
CVehicle::OccupantsReactToDamage(CEntity *damagedBy)
{
if (VehicleCreatedBy == RANDOM_VEHICLE && !IsBoat()){
switch (GetStatus()) {
case STATUS_SIMPLE:
case STATUS_PHYSICS:
if(bIsLawEnforcer &&
(GetModelIndex() == MI_POLICE || GetModelIndex() == MI_ENFORCER ||
GetModelIndex() == MI_CHOPPER || GetModelIndex() == MI_PREDATOR) &&
damagedBy == FindPlayerPed()){
// Police gets angry
FindPlayerPed()->SetWantedLevelNoDrop(1);
}else if(pDriver && pDriver->CharCreatedBy != MISSION_CHAR &&
pDriver->m_nPedType >= PEDTYPE_GANG1 && pDriver->m_nPedType <= PEDTYPE_GANG9 &&
damagedBy == FindPlayerPed()){
// Gang gets angry
SetStatus(STATUS_ABANDONED);
pDriver->SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, damagedBy);
int time = 200;
for (int i = 0; i < m_nNumMaxPassengers; i++) {
if (pPassengers[i] &&
pPassengers[i]->m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT &&
pPassengers[i]->CharCreatedBy != MISSION_CHAR) {
pPassengers[i]->SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, damagedBy);
pPassengers[i]->m_objectiveTimer = CTimer::GetTimeInMilliseconds() + time;
time += 200;
}
}
}else if(AutoPilot.m_nDrivingStyle == DRIVINGSTYLE_PLOUGH_THROUGH ||
CGeneral::GetRandomNumberInRange(0.0f, 1.0f) > 0.5f && AutoPilot.m_nCarMission == MISSION_CRUISE){
// Drive away like a maniac
if(pDriver && pDriver->m_objective != OBJECTIVE_LEAVE_CAR){
if(AutoPilot.m_nDrivingStyle != DRIVINGSTYLE_PLOUGH_THROUGH)
AutoPilot.m_nCruiseSpeed *= 1.5f;
AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_PLOUGH_THROUGH;
}
}else{
// Leave vehicle
if (pDriver && pDriver->CharCreatedBy != MISSION_CHAR) {
SetStatus(STATUS_ABANDONED);
pDriver->bFleeAfterExitingCar = true;
pDriver->SetObjective(OBJECTIVE_LEAVE_CAR, this);
pDriver->Say(SOUND_PED_FLEE_SPRINT);
}
int time = 200;
for (int i = 0; i < m_nNumMaxPassengers; i++) {
if (pPassengers[i] &&
pPassengers[i]->m_objective != OBJECTIVE_LEAVE_CAR &&
pPassengers[i]->CharCreatedBy != MISSION_CHAR) {
pPassengers[i]->bFleeAfterExitingCar = true;
pPassengers[i]->SetObjective(OBJECTIVE_LEAVE_CAR, this);
pPassengers[i]->m_objectiveTimer = CTimer::GetTimeInMilliseconds() + time;
pPassengers[i]->Say(SOUND_PED_FLEE_SPRINT);
time += 200;
}
}
}
break;
default:
break;
}
}
}
void
CVehicle::InflictDamage(CEntity *damagedBy, eWeaponType weaponType, float damage, CVector pos)
{
if (!bCanBeDamaged)
return;
if(GetStatus() == STATUS_PLAYER && CStats::GetPercentageProgress() >= 100.0f)
damage *= 0.5f;
if (GetStatus() != STATUS_PLAYER && bOnlyDamagedByPlayer && (damagedBy != FindPlayerPed() && damagedBy != FindPlayerVehicle()))
return;
if(damage > 10.0f && (damagedBy == FindPlayerPed() || damagedBy == FindPlayerVehicle()) && GetStatus() != STATUS_WRECKED){
CWorld::Players[CWorld::PlayerInFocus].m_nHavocLevel += 2;
CWorld::Players[CWorld::PlayerInFocus].m_fMediaAttention += 1.0f;
CStats::PropertyDestroyed += CGeneral::GetRandomNumberInRange(5, 25);
}
bool bFrightensDriver = false;
switch (weaponType) {
case WEAPONTYPE_UNARMED:
case WEAPONTYPE_BRASSKNUCKLE:
case WEAPONTYPE_SCREWDRIVER:
case WEAPONTYPE_GOLFCLUB:
case WEAPONTYPE_NIGHTSTICK:
case WEAPONTYPE_KNIFE:
case WEAPONTYPE_BASEBALLBAT:
case WEAPONTYPE_HAMMER:
case WEAPONTYPE_CLEAVER:
case WEAPONTYPE_MACHETE:
case WEAPONTYPE_KATANA:
case WEAPONTYPE_CHAINSAW:
if (bMeleeProof)
return;
break;
case WEAPONTYPE_COLT45:
case WEAPONTYPE_PYTHON:
case WEAPONTYPE_SHOTGUN:
case WEAPONTYPE_SPAS12_SHOTGUN:
case WEAPONTYPE_STUBBY_SHOTGUN:
case WEAPONTYPE_TEC9:
case WEAPONTYPE_UZI:
case WEAPONTYPE_SILENCED_INGRAM:
case WEAPONTYPE_MP5:
case WEAPONTYPE_M4:
case WEAPONTYPE_RUGER:
case WEAPONTYPE_SNIPERRIFLE:
case WEAPONTYPE_LASERSCOPE:
case WEAPONTYPE_M60:
case WEAPONTYPE_MINIGUN:
case WEAPONTYPE_HELICANNON:
case WEAPONTYPE_UZI_DRIVEBY:
if (bBulletProof)
return;
bFrightensDriver = true;
break;
case WEAPONTYPE_GRENADE:
case WEAPONTYPE_MOLOTOV:
case WEAPONTYPE_ROCKET:
case WEAPONTYPE_EXPLOSION:
if (bExplosionProof)
return;
bFrightensDriver = true;
break;
case WEAPONTYPE_FLAMETHROWER:
if (bFireProof)
return;
break;
case WEAPONTYPE_RAMMEDBYCAR:
if (bCollisionProof)
return;
break;
default:
break;
}
if(bFrightensDriver && GetStatus() == STATUS_PLAYER && m_fHealth < 250.0f)
return;
// Pop tires
if(damagedBy && damagedBy->IsPed() && (IsCar() || IsBike())){
int accuracy = 0;
switch(weaponType){
case WEAPONTYPE_COLT45:
accuracy = 10;
break;
case WEAPONTYPE_PYTHON:
// if(!((CPed*)damagedBy)->IsPlayer())
accuracy = 64;
break;
case WEAPONTYPE_SHOTGUN:
case WEAPONTYPE_STUBBY_SHOTGUN:
case WEAPONTYPE_M60:
case WEAPONTYPE_HELICANNON:
accuracy = 25;
break;
case WEAPONTYPE_TEC9:
case WEAPONTYPE_UZI:
case WEAPONTYPE_SILENCED_INGRAM:
case WEAPONTYPE_MP5:
case WEAPONTYPE_UZI_DRIVEBY:
accuracy = 15;
break;
case WEAPONTYPE_M4:
case WEAPONTYPE_RUGER:
if(!((CPed*)damagedBy)->IsPlayer())
accuracy = 15;
break;
}
// not in LCS (ifdef?)
if(((CPed*)damagedBy)->IsPlayer() && (CCamera::m_bUseMouse3rdPerson || TheCamera.Using1stPersonWeaponMode()))
accuracy = 0;
int difficulty = damagedBy == FindPlayerPed() ? 0x7F : 0xFF;
if(accuracy != 0 && !bTyresDontBurst && (CGeneral::GetRandomNumber()&difficulty) < accuracy){
if(IsBike())
BurstTyre(FindTyreNearestPoint(pos.x, pos.y) + CAR_PIECE_WHEEL_LF, false);
else// if(GetVehicleAppearance() == VEHICLE_APPEARANCE_CAR)
BurstTyre(FindTyreNearestPoint(pos.x, pos.y) + CAR_PIECE_WHEEL_LF, false); //true);
}
}
if (m_fHealth > 0.0f) {
if (VehicleCreatedBy == RANDOM_VEHICLE && pDriver &&
(GetStatus() == STATUS_SIMPLE || GetStatus() == STATUS_PHYSICS) &&
AutoPilot.m_nCarMission == MISSION_CRUISE) {
if (m_randomSeed < DAMAGE_FLEE_IN_CAR_PROBABILITY_VALUE) {
CCarCtrl::SwitchVehicleToRealPhysics(this);
AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_AVOID_CARS;
AutoPilot.m_nCruiseSpeed = GAME_SPEED_TO_CARAI_SPEED * pHandling->Transmission.fMaxCruiseVelocity;
SetStatus(STATUS_PHYSICS);
}
}
m_nLastWeaponDamage = weaponType;
m_pLastDamageEntity = damagedBy;
float oldHealth = m_fHealth;
if (m_fHealth > damage) {
m_fHealth -= damage;
OccupantsReactToDamage(damagedBy);
if (oldHealth >= DAMAGE_HEALTH_TO_CATCH_FIRE && m_fHealth < DAMAGE_HEALTH_TO_CATCH_FIRE) {
if (IsCar()) {
CAutomobile* pThisCar = (CAutomobile*)this;
pThisCar->Damage.SetEngineStatus(ENGINE_STATUS_ON_FIRE);
pThisCar->m_pSetOnFireEntity = damagedBy;
if (damagedBy)
damagedBy->RegisterReference((CEntity**)&pThisCar->m_pSetOnFireEntity);
}
}
}
else {
m_fHealth = 0.0f;
if (weaponType == WEAPONTYPE_EXPLOSION) {
// between 1000 and 3047. Also not very nice: can't be saved by respray or cheat
m_nBombTimer = 1000 + CGeneral::GetRandomNumber() & 0x7FF;
m_pBlowUpEntity = damagedBy;
if (damagedBy)
damagedBy->RegisterReference((CEntity**)&m_pBlowUpEntity);
}
else
BlowUpCar(damagedBy);
}
}
}
void
CVehicle::DoFixedMachineGuns(void)
{
if(TheCamera.Cams[TheCamera.ActiveCam].DirectionWasLooking == LOOKING_FORWARD){
if(CPad::GetPad(0)->GetCarGunFired() && !bGunSwitchedOff){
FireFixedMachineGuns();
}else{
if(CTimer::GetTimeInMilliseconds() > m_nGunFiringTime + 1400)
m_nAmmoInClip = 20;
}
}
}
void
CVehicle::FireFixedMachineGuns(void)
{
if (CTimer::GetTimeInMilliseconds() <= m_nGunFiringTime + 150)
return;
CVector source, target;
float dx, dy, len;
dx = GetForward().x;
dy = GetForward().y;
len = Sqrt(SQR(dx) + SQR(dy));
if (len < 0.1f) len = 0.1f;
dx /= len;
dy /= len;
m_nGunFiringTime = CTimer::GetTimeInMilliseconds();
source = GetMatrix() * CVector(0.95f, 9.3f, 0.85f);
target = source + CVector(dx, dy, 0.0f) * 60.0f;
target += CVector(
((CGeneral::GetRandomNumber() & 0xFF) - 128) * 0.015f,
((CGeneral::GetRandomNumber() & 0xFF) - 128) * 0.015f,
((CGeneral::GetRandomNumber() & 0xFF) - 128) * 0.02f);
CWeapon::DoTankDoomAiming(this, pDriver, &source, &target);
FireOneInstantHitRound(&source, &target, 15);
source = GetMatrix() * CVector(-0.95f, 9.3f, 0.85f);
target = source + CVector(dx, dy, 0.0f) * 60.0f;
target += CVector(
((CGeneral::GetRandomNumber() & 0xFF) - 128) * 0.015f,
((CGeneral::GetRandomNumber() & 0xFF) - 128) * 0.015f,
((CGeneral::GetRandomNumber() & 0xFF) - 128) * 0.02f);
CWeapon::DoTankDoomAiming(this, pDriver, &source, &target);
FireOneInstantHitRound(&source, &target, 15);
DMAudio.PlayOneShot(m_audioEntityId, SOUND_WEAPON_SHOT_FIRED, 0.0f);
m_nAmmoInClip--;
if (m_nAmmoInClip == 0) {
m_nAmmoInClip = 20;
m_nGunFiringTime = CTimer::GetTimeInMilliseconds() + 1400;
}
}
//LCS: in CAutomobile
void
CVehicle::ActivateBomb(void)
{
if(m_bombType == CARBOMB_TIMED){
m_bombType = CARBOMB_TIMEDACTIVE;
m_nBombTimer = 7000;
m_pBlowUpEntity = FindPlayerPed();
CGarages::TriggerMessage("GA_12", -1, 3000, -1);
DMAudio.PlayOneShot(m_audioEntityId, SOUND_BOMB_TIMED_ACTIVATED, 1.0f);
}else if(m_bombType == CARBOMB_ONIGNITION){
m_bombType = CARBOMB_ONIGNITIONACTIVE;
CGarages::TriggerMessage("GA_12", -1, 3000, -1);
DMAudio.PlayOneShot(m_audioEntityId, SOUND_BOMB_ONIGNITION_ACTIVATED, 1.0f);
}
}
//LCS: in CAutomobile and CBike
void
CVehicle::ActivateBombWhenEntered(void)
{
if(pDriver){
if(!bDriverLastFrame && m_bombType == CARBOMB_ONIGNITIONACTIVE){
// If someone enters the car and there is a bomb, detonate
m_nBombTimer = 1000;
m_pBlowUpEntity = m_pBombRigger;
if(m_pBlowUpEntity)
m_pBlowUpEntity->RegisterReference((CEntity**)&m_pBlowUpEntity);
DMAudio.PlayOneShot(m_audioEntityId, SOUND_BOMB_TICK, 1.0f);
}
bDriverLastFrame = true;
}else
bDriverLastFrame = false;
}
void
CVehicle::ExtinguishCarFire(void)
{
//TODO(LCS): check if this line was added in PC VC
// if(GetStatus() != STATUS_WRECKED)
m_fHealth = Max(m_fHealth, 300.0f);
if(m_pCarFire)
m_pCarFire->Extinguish();
if(IsCar()){
CAutomobile *car = (CAutomobile*)this;
if(car->Damage.GetEngineStatus() >= ENGINE_STATUS_ON_FIRE)
car->Damage.SetEngineStatus(ENGINE_STATUS_ON_FIRE-10);
car->m_fFireBlowUpTimer = 0.0f;
}
}
bool
CVehicle::ShufflePassengersToMakeSpace(void)
{
if (m_nNumPassengers >= m_nNumMaxPassengers)
return false;
if (pPassengers[1] &&
!(m_nGettingInFlags & CAR_DOOR_FLAG_LR) &&
!(m_nGettingOutFlags & CAR_DOOR_FLAG_LR) &&
IsRoomForPedToLeaveCar(CAR_DOOR_LR, nil)) {
if (!pPassengers[2] && !(m_nGettingInFlags & CAR_DOOR_FLAG_RR)) {
pPassengers[2] = pPassengers[1];
pPassengers[1] = nil;
pPassengers[2]->m_vehDoor = CAR_DOOR_RR;
return true;
}
if (!pPassengers[0] && !pPassengers[1]->bOnlyAllowedToSitBehind && !(m_nGettingInFlags & CAR_DOOR_FLAG_RF)) {
pPassengers[0] = pPassengers[1];
pPassengers[1] = nil;
pPassengers[0]->m_vehDoor = CAR_DOOR_RF;
return true;
}
return false;
}
if (pPassengers[2] &&
!(m_nGettingInFlags & CAR_DOOR_FLAG_RR) &&
!(m_nGettingOutFlags & CAR_DOOR_FLAG_RR) &&
IsRoomForPedToLeaveCar(CAR_DOOR_RR, nil)) {
if (!pPassengers[1] && !(m_nGettingInFlags & CAR_DOOR_FLAG_LR)) {
pPassengers[1] = pPassengers[2];
pPassengers[2] = nil;
pPassengers[1]->m_vehDoor = CAR_DOOR_LR;
return true;
}
if (!pPassengers[0] && !pPassengers[2]->bOnlyAllowedToSitBehind && !(m_nGettingInFlags & CAR_DOOR_FLAG_RF)) {
pPassengers[0] = pPassengers[2];
pPassengers[2] = nil;
pPassengers[0]->m_vehDoor = CAR_DOOR_RF;
return true;
}
return false;
}
if (pPassengers[0] &&
!(m_nGettingInFlags & CAR_DOOR_FLAG_RF) &&
!(m_nGettingOutFlags & CAR_DOOR_FLAG_RF) &&
IsRoomForPedToLeaveCar(CAR_DOOR_RF, nil)) {
if (!pPassengers[1] && !pPassengers[0]->bOnlyAllowedToSitInFront && !(m_nGettingInFlags & CAR_DOOR_FLAG_LR)) {
pPassengers[1] = pPassengers[0];
pPassengers[0] = nil;
pPassengers[1]->m_vehDoor = CAR_DOOR_LR;
return true;
}
if (!pPassengers[2] && !(m_nGettingInFlags & CAR_DOOR_FLAG_RR)) {
pPassengers[2] = pPassengers[0];
pPassengers[0] = nil;
pPassengers[2]->m_vehDoor = CAR_DOOR_RR;
return true;
}
return false;
}
return false;
}
void
CVehicle::MakeNonDraggedPedsLeaveVehicle(CPed *ped1, CPed *ped2, CPlayerPed *&player, CCopPed *&cop)
{
int i;
player = nil;
cop = nil;
if(ped1->IsPlayer() && ped2->m_nPedType == PEDTYPE_COP &&
((CPlayerPed*)ped1)->m_pWanted->GetWantedLevel() > 0 &&
ped2->m_pedInObjective == ped1){
player = (CPlayerPed*)ped1;
cop = (CCopPed*)ped2;
return;
}
bool ped1IsDriver = ped1 == pDriver;
// Just what the hell is this weird code?
CPed *peds[9];
CPed *peds2[9];
int numPeds = 0;
int numPeds2 = 0;
for(i = 0; i < m_nNumMaxPassengers; i++){
CPed *p = pPassengers[i];
if(p && p != ped1 && !p->bStayInCarOnJack){
peds[numPeds++] = p;
// uhh what?
if(i > 0 || ped1IsDriver)
peds2[numPeds2++] = p;
}
}
// So we're copying this array for no reason...
CPed *peds3[9];
int numPeds3 = 0;
for(i = 0; i < numPeds; i++){
if(peds[i]->IsPlayer() && ped2->m_nPedType == PEDTYPE_COP &&
((CPlayerPed*)peds[i])->m_pWanted->GetWantedLevel() > 0 &&
ped2->m_pedInObjective == peds[i]){
player = (CPlayerPed*)peds[i];
cop = (CCopPed*)ped2;
return;
}
peds3[numPeds3++] = peds[i];
}
int time = 1800;
for(i = 0; i < numPeds3; i++){
peds3[i]->m_leaveCarTimer = CTimer::GetTimeInMilliseconds() + time;
peds3[i]->SetObjective(OBJECTIVE_LEAVE_CAR, this);
time += CGeneral::GetRandomNumberInRange(300.0f, 600.0f);
}
if(IsCar() && numPeds2 > 0 && CGeneral::GetRandomTrueFalse())
for(i = 0; i < numPeds2; i++)
if(peds2[i]->IsFemale() || CGeneral::GetRandomTrueFalse()){
peds2[i]->m_leaveCarTimer = CTimer::GetTimeInMilliseconds() + 10000;
if(peds2[i]->b1A4_2)
peds2[i]->bHeldHostageInCar = true;
peds2[i]->bFleeAfterExitingCar = true;
}
}
void
CVehicle::ProcessDelayedExplosion(void)
{
if(m_nBombTimer == 0)
return;
int tick = CTimer::GetTimeStep()/60.0f*1000.0f;
int16 prev = m_nBombTimer;
if(tick > m_nBombTimer)
m_nBombTimer = 0;
else
m_nBombTimer -= tick;
if(IsCar() && ((CAutomobile*)this)->m_bombType == CARBOMB_TIMEDACTIVE && (m_nBombTimer & 0xFE00) != (prev & 0xFE00))
DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_BOMB_TICK, 0.0f);
if (m_nBombTimer == 0)
BlowUpCar(m_pBlowUpEntity);
}
bool
CVehicle::IsLawEnforcementVehicle(void)
{
switch(GetModelIndex()){
case MI_FBICAR:
case MI_POLICE:
case MI_ENFORCER:
case MI_PREDATOR:
case MI_RHINO:
case MI_BARRACKS:
// case MI_FBIRANCH:
// case MI_VICECHEE:
return true;
default:
return false;
}
}
bool
CVehicle::UsesSiren(void)
{
switch(GetModelIndex()){
case MI_FIRETRUCK:
case MI_AMBULAN:
case MI_FBICAR:
case MI_MRWHOOP:
case MI_POLICE:
case MI_ENFORCER:
case MI_PREDATOR:
// case MI_FBIRANCH:
// case MI_VICECHEE:
return true;
default:
return false;
}
}
bool
CVehicle::IsVehicleNormal(void)
{
if (!pDriver || m_nNumPassengers != 0 || GetStatus() == STATUS_WRECKED)
return false;
return GetModelInfo()->m_vehicleClass != -1;
}
bool
CVehicle::CarHasRoof(void)
{
if((pHandling->Flags & HANDLING_HAS_NO_ROOF) == 0)
return true;
// component 0 is assumed to be a roof
return m_aExtras[0] == 0 || m_aExtras[1] == 0;
}
bool
CVehicle::IsUpsideDown(void)
{
if(GetUp().z > -0.9f)
return false;
return true;
}
bool
CVehicle::IsOnItsSide(void)
{
if(GetRight().z < 0.8f && GetRight().z > -0.8f)
return false;
return true;
}
bool
CVehicle::CanBeDeleted(void)
{
int i;
if(m_nNumGettingIn || m_nGettingOutFlags)
return false;
if(pDriver){
// This looks like it was inlined
if(pDriver->CharCreatedBy == MISSION_CHAR)
return false;
if(pDriver->GetPedState() != PED_DRIVING &&
pDriver->GetPedState() != PED_DEAD)
return false;
}
for(i = 0; i < ARRAY_SIZE(pPassengers); i++){
// Same check as above
if(pPassengers[i]){
if(pPassengers[i]->CharCreatedBy == MISSION_CHAR)
return false;
if(pPassengers[i]->GetPedState() != PED_DRIVING &&
pPassengers[i]->GetPedState() != PED_DEAD)
return false;
}
// and then again... probably because something was inlined
if(pPassengers[i]){
if(pPassengers[i]->GetPedState() != PED_DRIVING &&
pPassengers[i]->GetPedState() != PED_DEAD)
return false;
}
}
switch(VehicleCreatedBy){
case RANDOM_VEHICLE: return true;
case MISSION_VEHICLE: return false;
case PARKED_VEHICLE: return true;
case PERMANENT_VEHICLE: return false;
}
return true;
}
bool
CVehicle::CanPedOpenLocks(CPed *ped)
{
if(m_nDoorLock == CARLOCK_LOCKED ||
m_nDoorLock == CARLOCK_LOCKED_INITIALLY ||
m_nDoorLock == CARLOCK_LOCKED_PLAYER_INSIDE ||
m_nDoorLock == CARLOCK_LOCKED_BUT_CAN_BE_DAMAGED)
return false;
// if(ped->IsPlayer() && m_nDoorLock == CARLOCK_LOCKOUT_PLAYER_ONLY)
// return false;
return true;
}
bool
CVehicle::CanDoorsBeDamaged(void)
{
return m_nDoorLock == CARLOCK_NOT_USED ||
m_nDoorLock == CARLOCK_UNLOCKED ||
m_nDoorLock == CARLOCK_LOCKED_BUT_CAN_BE_DAMAGED;
}
bool
CVehicle::CanPedEnterCar(void)
{
// can't enter when car is on side
if(IsBike() || GetUp().z > 0.1f || GetUp().z < -0.1f){
// also when car is moving too fast
if(m_vecMoveSpeed.MagnitudeSqr() > sq(0.2f))
return false;
if(m_vecTurnSpeed.MagnitudeSqr() > sq(0.2f))
return false;
return true;
}
return false;
}
bool
CVehicle::CanPedExitCar(bool jumpExit)
{
CVector up = GetUp();
if(up.z > 0.1f || up.z < -0.1f){
if (IsBoat())
return true;
// can't exit when car is moving too fast
if(m_vecMoveSpeed.MagnitudeSqr() > 0.005f && !jumpExit)
return false;
// if car is slow enough, check turn speed
if(Abs(m_vecTurnSpeed.x) > 0.01f ||
Abs(m_vecTurnSpeed.y) > 0.01f ||
Abs(m_vecTurnSpeed.z) > 0.01f)
return false;
return true;
}else{
// What is this? just > replaced by >= ??
// can't exit when car is moving too fast
if(m_vecMoveSpeed.MagnitudeSqr() >= 0.005f)
return false;
// if car is slow enough, check turn speed
if(Abs(m_vecTurnSpeed.x) >= 0.01f ||
Abs(m_vecTurnSpeed.y) >= 0.01f ||
Abs(m_vecTurnSpeed.z) >= 0.01f)
return false;
return true;
}
}
bool
CVehicle::CanPedJumpOutCar(void)
{
if(GetUp().z < 0.3f)
return false;
float speed = m_vecMoveSpeed.MagnitudeSqr();
return speed < 0.1f || speed > 0.5f ? false : true;
}
bool
CVehicle::CanPedJumpOffBike(void)
{
if(pPassengers[0])
return false;
return m_vecMoveSpeed.MagnitudeSqr() < 0.07f ? false : true;
}
void
CVehicle::ChangeLawEnforcerState(uint8 enable)
{
if (enable) {
if (!bIsLawEnforcer) {
bIsLawEnforcer = true;
CCarCtrl::NumLawEnforcerCars++;
}
} else {
if (bIsLawEnforcer) {
bIsLawEnforcer = false;
CCarCtrl::NumLawEnforcerCars--;
}
}
}
CPed*
CVehicle::SetUpDriver(void)
{
if(pDriver)
return pDriver;
if(VehicleCreatedBy != RANDOM_VEHICLE)
return nil;
pDriver = CPopulation::AddPedInCar(this, true);
pDriver->m_pMyVehicle = this;
pDriver->m_pMyVehicle->RegisterReference((CEntity**)&pDriver->m_pMyVehicle);
pDriver->bInVehicle = true;
pDriver->SetPedState(PED_DRIVING);
if(bIsBus)
pDriver->bRenderPedInCar = false;
return pDriver;
}
CPed*
CVehicle::SetupPassenger(int n)
{
int i;
if(pPassengers[n])
return pPassengers[n];
if((IsTaxi() || IsLimo()) && n == 0)
pPassengers[0] = nil;
else{
CPed *passenger = CPopulation::AddPedInCar(this, false);
pPassengers[n] = passenger;
passenger->m_pMyVehicle = this;
passenger->m_pMyVehicle->RegisterReference((CEntity**)&pPassengers[n]->m_pMyVehicle);
passenger->bInVehicle = true;
passenger->SetPedState(PED_DRIVING);
if(passenger->m_nPedType == PEDTYPE_CIVMALE || passenger->m_nPedType == PEDTYPE_CIVFEMALE)
for(i = 0; i < n; i++)
if(pPassengers[i] && pPassengers[n] &&
(pPassengers[i]->m_nPedType == PEDTYPE_CIVMALE || pPassengers[i]->m_nPedType == PEDTYPE_CIVFEMALE) &&
passenger->GetModelIndex() == pPassengers[i]->GetModelIndex()){
pPassengers[n] = nil;
CPopulation::RemovePed(passenger);
}
}
if(bIsBus && pPassengers[n])
pPassengers[n]->bRenderPedInCar = false;
++m_nNumPassengers;
return pPassengers[n];
}
void
CVehicle::SetDriver(CPed *driver)
{
m_vehLCS_258 = false;
bCraneMessageDone = false;
pDriver = driver;
pDriver->RegisterReference((CEntity**)&pDriver);
if(bFreebies && driver == FindPlayerPed()){
bFreebies = false;
switch(GetModelIndex()){
case MI_AMBULAN:
FindPlayerPed()->m_fHealth = Max(FindPlayerPed()->m_fHealth, Min(FindPlayerPed()->m_fHealth + 20.0f, CWorld::Players[0].m_nMaxHealth));
break;
case MI_TAXI:
case MI_CABBIE:
case MI_BORGNINE:
CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 12;
break;
case MI_POLICE:
CStreaming::RequestModel(MI_SHOTGUN, STREAMFLAGS_DONT_REMOVE);
bFreebies = true;
break;
case MI_ENFORCER:
driver->m_fArmour = Max(driver->m_fArmour, CWorld::Players[0].m_nMaxArmour);
break;
/*
case MI_CADDY:
if(!(driver->IsPlayer() && ((CPlayerPed*)driver)->DoesPlayerWantNewWeapon(WEAPONTYPE_GOLFCLUB, true)))
CStreaming::RequestModel(MI_GOLFCLUB, STREAMFLAGS_DONT_REMOVE);
break;
*/
}
}
if(IsBike())
ApplyMoveForce(-0.02f*driver->m_fMass * GetUp());
else
ApplyTurnForce(0.0f, 0.0f, -0.02f*driver->m_fMass,
driver->GetPosition().x - GetPosition().x,
driver->GetPosition().y - GetPosition().y,
0.0f);
}
bool
CVehicle::AddPassenger(CPed *passenger)
{
int i;
if(IsBike())
ApplyTurnForce(-0.02f*passenger->m_fMass * GetUp(), -0.1f*GetForward());
else
ApplyTurnForce(0.0f, 0.0f, -0.2f*passenger->m_fMass,
passenger->GetPosition().x - GetPosition().x,
passenger->GetPosition().y - GetPosition().y,
0.0f);
for(i = 0; i < m_nNumMaxPassengers; i++)
if(pPassengers[i] == nil){
pPassengers[i] = passenger;
m_nNumPassengers++;
return true;
}
return false;
}
bool
CVehicle::AddPassenger(CPed *passenger, uint8 n)
{
if(bIsBus)
return AddPassenger(passenger);
if(IsBike())
ApplyTurnForce(-0.02f*passenger->m_fMass * GetUp(), -0.1f*GetForward());
else
ApplyTurnForce(0.0f, 0.0f, -0.2f*passenger->m_fMass,
passenger->GetPosition().x - GetPosition().x,
passenger->GetPosition().y - GetPosition().y,
0.0f);
if(n < m_nNumMaxPassengers && pPassengers[n] == nil){
pPassengers[n] = passenger;
m_nNumPassengers++;
return true;
}
return false;
}
void
CVehicle::RemoveDriver(void)
{
m_vehLCS_259 = -1;
#ifdef FIX_BUGS
if (GetStatus() != STATUS_WRECKED)
#endif
SetStatus(STATUS_ABANDONED);
if(pDriver == FindPlayerPed()){
if(GetModelIndex() == MI_POLICE && CStreaming::HasModelLoaded(MI_SHOTGUN)){
if(bFreebies){
if(((CPlayerPed*)pDriver)->DoesPlayerWantNewWeapon(WEAPONTYPE_SHOTGUN, true))
pDriver->GiveWeapon(WEAPONTYPE_SHOTGUN, 5, true);
else
pDriver->GrantAmmo(WEAPONTYPE_SHOTGUN, 5);
bFreebies = false;
}
CStreaming::SetModelIsDeletable(MI_SHOTGUN);
/*
}else if(GetModelIndex() == MI_CADDY && CStreaming::HasModelLoaded(MI_GOLFCLUB)){
if(((CPlayerPed*)pDriver)->DoesPlayerWantNewWeapon(WEAPONTYPE_GOLFCLUB, true))
pDriver->GiveWeapon(WEAPONTYPE_GOLFCLUB, 1, true);
CStreaming::SetModelIsDeletable(MI_GOLFCLUB);
*/
}
}
pDriver = nil;
}
void
CVehicle::RemovePassenger(CPed *p)
{
if (IsTrain()){
for (int i = 0; i < ARRAY_SIZE(pPassengers); i++){
if (pPassengers[i] == p) {
pPassengers[i] = nil;
m_nNumPassengers--;
return;
}
}
return;
}
for (int i = 0; i < m_nNumMaxPassengers; i++){
if (pPassengers[i] == p){
pPassengers[i] = nil;
m_nNumPassengers--;
return;
}
}
}
bool
CVehicle::IsDriver(CPed *ped)
{
return ped && ped == pDriver;
}
bool
CVehicle::IsDriver(int32 model)
{
return pDriver && pDriver->GetModelIndex() == model;
}
bool
CVehicle::IsPassenger(CPed *ped)
{
int i;
if(ped == nil)
return false;
for(i = 0; i < 8; i++)
if(pPassengers[i] == ped)
return true;
return false;
}
bool
CVehicle::IsPassenger(int32 model)
{
int i;
for(i = 0; i < 8; i++)
if(pPassengers[i] && pPassengers[i]->GetModelIndex() == model)
return true;
return false;
}
void
CVehicle::UpdatePassengerList(void)
{
int i;
bool hasPassenger = false;
if(m_nNumPassengers)
for(i = 0; i < 8; i++)
if(pPassengers[i]){
hasPassenger = true;
break;
}
if(!hasPassenger)
m_nNumPassengers = 0;
}
bool
CVehicle::AreThereAnyPassengers(void)
{
int i;
for(i = 0; i < m_nNumMaxPassengers; i++)
if(pPassengers[i])
return true;
return false;
}
void
CVehicle::ProcessCarAlarm(void)
{
uint32 step;
if(m_nAlarmState == 0 || m_nAlarmState == -1)
return;
step = CTimer::GetTimeStepInMilliseconds();
if((uint16)m_nAlarmState < step){
m_nAlarmState = 0;
m_nCarHornTimer = 0;
}else
m_nAlarmState -= step;
}
bool
CVehicle::IsSphereTouchingVehicle(float sx, float sy, float sz, float radius)
{
float x, y, z;
// sphere relative to vehicle
CVector sph = CVector(sx, sy, sz) - GetPosition();
CColModel *colmodel = GetColModel();
x = DotProduct(sph, GetRight());
if(colmodel->boundingBox.min.x - radius > x ||
colmodel->boundingBox.max.x + radius < x)
return false;
y = DotProduct(sph, GetForward());
if(colmodel->boundingBox.min.y - radius > y ||
colmodel->boundingBox.max.y + radius < y)
return false;
z = DotProduct(sph, GetUp());
if(colmodel->boundingBox.min.z - radius > z ||
colmodel->boundingBox.max.z + radius < z)
return false;
return true;
}
RpMaterial*
SetCompAlphaCB(RpMaterial *material, void *data)
{
uint32 alpha = (uint32)(uintptr)data;
RwRGBA *col = (RwRGBA*)RpMaterialGetColor(material); // get rid of const
col->alpha = alpha;
return material;
}
void
CVehicle::SetComponentAtomicAlpha(RpAtomic *atomic, int32 alpha)
{
RpGeometry *geo = RpAtomicGetGeometry(atomic);
RpGeometrySetFlags(geo, RpGeometryGetFlags(geo) | rpGEOMETRYMODULATEMATERIALCOLOR);
RpGeometryForAllMaterials(geo, SetCompAlphaCB, (void*)alpha);
}
void
CVehicle::UpdateClumpAlpha(void)
{
int clumpAlpha = CVisibilityPlugins::GetClumpAlpha((RpClump*)m_rwObject);
if(bFadeOut){
clumpAlpha -= 8;
if(clumpAlpha < 0)
clumpAlpha = 0;
}else if(clumpAlpha < 255){
clumpAlpha += 16;
if(clumpAlpha > 255)
clumpAlpha = 255;
}
CVisibilityPlugins::SetClumpAlpha((RpClump*)m_rwObject, clumpAlpha);
}
void
CVehicle::HeliDustGenerate(CEntity *heli, float radius, float ground, int rnd)
{
int i;
float angle;
CColPoint point;
CEntity *entity;
uint8 r, g, b;
if(heli == nil)
return;
uint8 surface = SURFACE_TARMAC;
int frm = CTimer::GetFrameCounter() & 7;
float testLowZ = ground - 10.0f;
float dustSize = 0.0f;
float baseSize = 1.0f;
float offset = 1.0f; // when heli is tilted
float particleZ = -101.0f;
int n = 0;
if(heli->GetModelIndex() == MI_RCGOBLIN || heli->GetModelIndex() == MI_RCRAIDER){
radius = 3.0f;
dustSize = 0.04f;
baseSize = 0.07f;
offset = 0.3f;
}
CVector heliPos = heli->GetPosition();
if(heli->IsVehicle() && ((CVehicle*)heli)->IsCar()){
heliPos.x -= (heliPos.z - ground)*heli->GetUp().x*offset*0.5f;
heliPos.y -= (heliPos.z - ground)*heli->GetUp().y*offset*0.5f;
}
float steamSize = 0.25f * radius * baseSize;
float splashSize = 0.3f * radius * baseSize;
i = 0;
for(i = 0; i < 32+rnd; i++){
angle = i * TWOPI/32.0f;
CVector pos(radius*Cos(angle), radius*Sin(angle), 0.0f);
CVector dir = CVector(pos.x, pos.y, 1.0f)*0.01f;
pos += heliPos;
if(i < 32 && i == 4*frm){
if(CWorld::ProcessVerticalLine(pos, testLowZ, point, entity, true, false, false, false, true, false, nil)){
n = rnd;
particleZ = point.point.z;
surface = point.surfaceB;
}else
n = 0;
float waterLevel = 0.0f;
if(CWaterLevel::GetWaterLevel(pos, &waterLevel, false) && waterLevel > particleZ){
surface = SURFACE_WATER;
n = rnd;
particleZ = waterLevel;
}
}
if(n){
pos.z = particleZ;
if(surface == SURFACE_WATER){
float red = (0.3*CTimeCycle::GetDirectionalRed() + CTimeCycle::GetAmbientRed_Obj())*255.0f/4.0f;
float green = (0.3*CTimeCycle::GetDirectionalGreen() + CTimeCycle::GetAmbientGreen_Obj())*255.0f/4.0f;
float blue = (0.3*CTimeCycle::GetDirectionalBlue() + CTimeCycle::GetAmbientBlue_Obj())*255.0f/4.0f;
r = Clamp(red, 0.0f, 255.0f);
g = Clamp(green, 0.0f, 255.0f);
b = Clamp(blue, 0.0f, 255.0f);
RwRGBA col1 = { r, g, b, (RwUInt8)CGeneral::GetRandomNumberInRange(8, 32) };
RwRGBA col2 = { 255, 255, 255, 32 };
if(n&1)
CParticle::AddParticle(PARTICLE_STEAM_NY_SLOWMOTION, pos, dir, nil, steamSize, col2);
else
CParticle::AddParticle(PARTICLE_CAR_SPLASH, pos, dir, nil, splashSize, col1,
CGeneral::GetRandomNumberInRange(0.0f, 10.0f),
CGeneral::GetRandomNumberInRange(0.0f, 90.0f), 1);
}else{
switch(surface){
default:
case SURFACE_TARMAC:
r = 10;
g = 10;
b = 10;
break;
case SURFACE_GRASS:
r = 10;
g = 10;
b = 3;
break;
case SURFACE_GRAVEL:
r = 10;
g = 8;
b = 7;
break;
case SURFACE_MUD_DRY:
r = 10;
g = 6;
b = 3;
break;
case SURFACE_SAND:
case SURFACE_SAND_BEACH:
r = 10;
g = 10;
b = 7;
break;
}
RwRGBA col = { r, g, b, 32 };
if(heliPos.z - pos.z < 20.0f)
CParticle::AddParticle(PARTICLE_HELI_DUST, pos, dir, nil, dustSize, col);
}
n--;
}
}
}
/*
#define GLARE_MIN_DIST (13.0f)
#define GLARE_FULL_DIST (30.0f)
#define GLARE_MIN_ANGLE (0.99f)
#define GLARE_FULL_ANGLE (0.995f)
void
CVehicle::DoSunGlare(void)
{
if(bRenderScorched || GetPosition().z < 0.0f ||
GetVehicleAppearance() != VEHICLE_APPEARANCE_CAR || CWeather::SunGlare <= 0.0f)
return;
CVector camDir = TheCamera.GetPosition() - GetPosition();
float dist = camDir.Magnitude();
camDir *= 2.0f/dist;
CVector glareVec = camDir + CTimeCycle::GetSunDirection();
CVector localGlareVec;
localGlareVec.x = DotProduct(glareVec, GetRight());
localGlareVec.y = DotProduct(glareVec, GetForward());
localGlareVec.z = 0.0;
localGlareVec.Normalise();
CVector2D fwd2D = GetForward();
fwd2D.Normalise();
CVector2D camDir2D = camDir;
camDir2D.Normalise();
float fwdness = Abs(DotProduct2D(fwd2D, camDir2D));
// check angle
float strength;
if(fwdness > GLARE_FULL_ANGLE)
strength = 1.0f;
else if(fwdness > GLARE_MIN_ANGLE)
strength = (fwdness - GLARE_MIN_ANGLE)/(GLARE_FULL_ANGLE-GLARE_MIN_ANGLE);
else
return;
// check distance
if(dist > GLARE_FULL_DIST){
// no max distance
}else if(dist > GLARE_MIN_DIST)
strength *= (dist - GLARE_MIN_DIST)/(GLARE_FULL_DIST - GLARE_MIN_DIST);
else
return;
float intens = 0.8f * strength * CWeather::SunGlare;
int r = intens * (CTimeCycle::GetSunCoreRed() + 2*255)/3.0f;
int g = intens * (CTimeCycle::GetSunCoreGreen() + 2*255)/3.0f;
int b = intens * (CTimeCycle::GetSunCoreBlue() + 2*255)/3.0f;
CColModel *colmodel = GetColModel();
CCollision::CalculateTrianglePlanes(colmodel);
int i;
for(i = 0; i < colmodel->numTriangles-2; i += 2){
int a1 = colmodel->triangles[i].a;
int b1 = colmodel->triangles[i].b;
int c1 = colmodel->triangles[i].c;
int a2 = colmodel->triangles[i+1].a;
int b2 = colmodel->triangles[i+1].b;
int c2 = colmodel->triangles[i+1].c;
CVector vert1 = colmodel->vertices[a1].Get();
CVector vert4;
// Need an upward surface
if(vert1.z <= 0.0f)
continue;
// trying to find a quad here
int numTri2Verts = 0;
if(a2 != a1 && a2 != b1 && a2 != c1){
// a2 is not in tri1
numTri2Verts++;
vert4 = colmodel->vertices[a2].Get();
}
if(b2 != a1 && b2 != b1 && b2 != c1){
// b2 is not in tri1
numTri2Verts++;
vert4 = colmodel->vertices[b2].Get();
}
if(c2 != a1 && c2 != b1 && c2 != c1){
// c2 is not in tri1
numTri2Verts++;
vert4 = colmodel->vertices[c2].Get();
}
// Need exactly one vertex from tri2 for a quad with tri1
if(numTri2Verts != 1)
continue;
CVector mid = (vert1 + colmodel->vertices[b1].Get() + colmodel->vertices[c1].Get() + vert4)/4.0f;
float dy = mid.y - vert1.y;
float dx = mid.x - vert1.x;
float dist = 1.4f * Min(Abs(dx), Abs(dy));
if(dist > 0.6f){
CVector pos = GetMatrix() * (dist * localGlareVec + mid) + camDir;
CCoronas::RegisterCorona((uintptr)this + 27 + i,
r, g, b, 255,
pos, 0.9f*CWeather::SunGlare, 90.0f,
CCoronas::TYPE_STAR, CCoronas::FLARE_NONE,
CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF,
CCoronas::STREAK_OFF, 0.0f);
}
}
}
*/
void
CVehicle::KillPedsInVehicle(void)
{
int i;
if(pDriver){
CDarkel::RegisterKillByPlayer(pDriver, WEAPONTYPE_EXPLOSION);
if(pDriver->GetPedState() == PED_DRIVING){
pDriver->SetDead();
if(!pDriver->IsPlayer())
pDriver->FlagToDestroyWhenNextProcessed();
}else
pDriver->SetDie();
}
for(i = 0; i < m_nNumMaxPassengers; i++){
if(pPassengers[i]){
CDarkel::RegisterKillByPlayer(pPassengers[i], WEAPONTYPE_EXPLOSION);
if(pPassengers[i]->GetPedState() == PED_DRIVING){
pPassengers[i]->SetDead();
if(!pPassengers[i]->IsPlayer())
pPassengers[i]->FlagToDestroyWhenNextProcessed();
}else
pPassengers[i]->SetDie();
}
}
}
void
DestroyVehicleAndDriverAndPassengers(CVehicle* pVehicle)
{
if (pVehicle->pDriver) {
CDarkel::RegisterKillByPlayer(pVehicle->pDriver, WEAPONTYPE_UNIDENTIFIED);
pVehicle->pDriver->FlagToDestroyWhenNextProcessed();
}
for (int i = 0; i < pVehicle->m_nNumMaxPassengers; i++) {
if (pVehicle->pPassengers[i]) {
CDarkel::RegisterKillByPlayer(pVehicle->pPassengers[i], WEAPONTYPE_UNIDENTIFIED);
pVehicle->pPassengers[i]->FlagToDestroyWhenNextProcessed();
}
}
CWorld::Remove(pVehicle);
delete pVehicle;
}
#ifdef COMPATIBLE_SAVES
void
CVehicle::Save(uint8*& buf)
{
ZeroSaveBuf(buf, 4);
WriteSaveBuf(buf, GetRight().x);
WriteSaveBuf(buf, GetRight().y);
WriteSaveBuf(buf, GetRight().z);
ZeroSaveBuf(buf, 4);
WriteSaveBuf(buf, GetForward().x);
WriteSaveBuf(buf, GetForward().y);
WriteSaveBuf(buf, GetForward().z);
ZeroSaveBuf(buf, 4);
WriteSaveBuf(buf, GetUp().x);
WriteSaveBuf(buf, GetUp().y);
WriteSaveBuf(buf, GetUp().z);
ZeroSaveBuf(buf, 4);
WriteSaveBuf(buf, GetPosition().x);
WriteSaveBuf(buf, GetPosition().y);
WriteSaveBuf(buf, GetPosition().z);
ZeroSaveBuf(buf, 16);
SaveEntityFlags(buf);
ZeroSaveBuf(buf, 208);
AutoPilot.Save(buf);
WriteSaveBuf(buf, m_currentColour1);
WriteSaveBuf(buf, m_currentColour2);
ZeroSaveBuf(buf, 2);
WriteSaveBuf(buf, m_nAlarmState);
ZeroSaveBuf(buf, 42);
WriteSaveBuf(buf, m_nNumMaxPassengers);
ZeroSaveBuf(buf, 3);
WriteSaveBuf(buf, m_vehLCS_230.x);
WriteSaveBuf(buf, m_vehLCS_230.y);
WriteSaveBuf(buf, m_vehLCS_230.z);
WriteSaveBuf(buf, m_vehLCS_230.w);
ZeroSaveBuf(buf, 8);
WriteSaveBuf(buf, m_fSteerAngle);
WriteSaveBuf(buf, m_fGasPedal);
WriteSaveBuf(buf, m_fBrakePedal);
WriteSaveBuf(buf, VehicleCreatedBy);
uint8 flags = 0;
if (bIsLawEnforcer) flags |= BIT(0);
if (bIsLocked) flags |= BIT(3);
if (bEngineOn) flags |= BIT(4);
if (bIsHandbrakeOn) flags |= BIT(5);
if (bLightsOn) flags |= BIT(6);
if (bFreebies) flags |= BIT(7);
WriteSaveBuf(buf, flags);
ZeroSaveBuf(buf, 10);
WriteSaveBuf(buf, m_fHealth);
WriteSaveBuf(buf, m_nCurrentGear);
ZeroSaveBuf(buf, 3);
WriteSaveBuf(buf, m_fChangeGearTime);
ZeroSaveBuf(buf, 12);
WriteSaveBuf(buf, m_nTimeOfDeath);
ZeroSaveBuf(buf, 2);
WriteSaveBuf(buf, m_nBombTimer);
ZeroSaveBuf(buf, 12);
WriteSaveBuf(buf, m_nDoorLock);
ZeroSaveBuf(buf, 108);
}
void
CVehicle::Load(uint8*& buf)
{
CMatrix tmp;
SkipSaveBuf(buf, 4);
ReadSaveBuf(&tmp.GetRight().x, buf);
ReadSaveBuf(&tmp.GetRight().y, buf);
ReadSaveBuf(&tmp.GetRight().z, buf);
SkipSaveBuf(buf, 4);
ReadSaveBuf(&tmp.GetForward().x, buf);
ReadSaveBuf(&tmp.GetForward().y, buf);
ReadSaveBuf(&tmp.GetForward().z, buf);
SkipSaveBuf(buf, 4);
ReadSaveBuf(&tmp.GetUp().x, buf);
ReadSaveBuf(&tmp.GetUp().y, buf);
ReadSaveBuf(&tmp.GetUp().z, buf);
SkipSaveBuf(buf, 4);
ReadSaveBuf(&tmp.GetPosition().x, buf);
ReadSaveBuf(&tmp.GetPosition().y, buf);
ReadSaveBuf(&tmp.GetPosition().z, buf);
m_matrix = tmp;
SkipSaveBuf(buf, 16);
LoadEntityFlags(buf);
SkipSaveBuf(buf, 208);
AutoPilot.Load(buf);
ReadSaveBuf(&m_currentColour1, buf);
ReadSaveBuf(&m_currentColour2, buf);
SkipSaveBuf(buf, 2);
ReadSaveBuf(&m_nAlarmState, buf);
SkipSaveBuf(buf, 42);
ReadSaveBuf(&m_nNumMaxPassengers, buf);
SkipSaveBuf(buf, 3);
ReadSaveBuf(&m_vehLCS_230.x, buf);
ReadSaveBuf(&m_vehLCS_230.y, buf);
ReadSaveBuf(&m_vehLCS_230.z, buf);
ReadSaveBuf(&m_vehLCS_230.w, buf);
SkipSaveBuf(buf, 8);
ReadSaveBuf(&m_fSteerAngle, buf);
ReadSaveBuf(&m_fGasPedal, buf);
ReadSaveBuf(&m_fBrakePedal, buf);
ReadSaveBuf(&VehicleCreatedBy, buf);
uint8 flags;
ReadSaveBuf(&flags, buf);
bIsLawEnforcer = !!(flags & BIT(0));
bIsLocked = !!(flags & BIT(3));
bEngineOn = !!(flags & BIT(4));
bIsHandbrakeOn = !!(flags & BIT(5));
bLightsOn = !!(flags & BIT(6));
bFreebies = !!(flags & BIT(7));
SkipSaveBuf(buf, 10);
ReadSaveBuf(&m_fHealth, buf);
ReadSaveBuf(&m_nCurrentGear, buf);
SkipSaveBuf(buf, 3);
ReadSaveBuf(&m_fChangeGearTime, buf);
SkipSaveBuf(buf, 12);
ReadSaveBuf(&m_nTimeOfDeath, buf);
SkipSaveBuf(buf, 2);
ReadSaveBuf(&m_nBombTimer, buf);
SkipSaveBuf(buf, 12);
ReadSaveBuf(&m_nDoorLock, buf);
SkipSaveBuf(buf, 108);
}
#endif
eVehicleAppearance
CVehicle::GetVehicleAppearance(void)
{
uint32 flags = pHandling->Flags & 0xF0000;
if (flags == 0)
return VEHICLE_APPEARANCE_CAR;
if (flags == HANDLING_IS_BIKE)
return VEHICLE_APPEARANCE_BIKE;
if (flags == HANDLING_IS_HELI)
return VEHICLE_APPEARANCE_HELI;
if (flags == HANDLING_IS_PLANE)
return VEHICLE_APPEARANCE_PLANE;
if (flags == HANDLING_IS_BOAT)
return VEHICLE_APPEARANCE_BOAT;
return VEHICLE_APPEARANCE_NONE;
}
bool
IsVehiclePointerValid(CVehicle* pVehicle)
{
if (!pVehicle)
return false;
int index = CPools::GetVehiclePool()->GetJustIndex_NoFreeAssert(pVehicle);
#ifdef FIX_BUGS
if (index < 0 || index >= NUMVEHICLES)
#else
if (index < 0 || index > NUMVEHICLES)
#endif
return false;
return pVehicle->m_vehType == VEHICLE_TYPE_PLANE || pVehicle->m_entryInfoList.first;
}
|