forked from dethrace-labs/dethrace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopponent.c
3840 lines (3547 loc) · 175 KB
/
opponent.c
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
#include "opponent.h"
#include "brender/brender.h"
#include "car.h"
#include "controls.h"
#include "crush.h"
#include "displays.h"
#include "errors.h"
#include "finteray.h"
#include "globvars.h"
#include "globvrkm.h"
#include "globvrme.h"
#include "globvrpb.h"
#include "harness/trace.h"
#include "loading.h"
#include "oppoproc.h"
#include "pd/sys.h"
#include "skidmark.h"
#include "trig.h"
#include "utility.h"
#include <stdlib.h>
br_actor* gOppo_path_actor;
br_model* gOppo_path_model;
br_material* gMat_dk_yel;
br_material* gMat_md_yel;
br_material* gMat_lt_yel;
br_material* gMat_dk_red;
br_material* gMat_lt_red;
br_material* gMat_dk_grn;
br_material* gMat_lt_grn;
br_material* gMat_dk_blu;
br_material* gMat_lt_blu;
br_material* gMat_dk_turq;
br_material* gMat_lt_turq;
br_material* gMat_dk_gry;
br_material* gMat_md_gry;
br_material* gMat_lt_gry;
int gMellow_opponents;
int gTest_toggle;
int gAlready_elasticating;
int gVertices_used_in_non_edit_paths;
int gFaces_used_in_non_edit_paths;
int gMats_allocated;
int gOppo_paths_shown;
int gMade_path_filename;
int gBIG_APC_index = -1;
char* gPath_section_type_names[3];
int gMin_bangness = 100;
int gMax_bangness;
tU32 gNext_elastication;
tU32 gNext_write_during_elastication;
char* gCop_name = "Faceless Cop";
char* gDrone_name = "Innocent Civilian";
int gChallenger_index__opponent = -1; // suffix added to avoid duplicate symbol
int gSFS_count;
int gSFS_total_cycles;
int gSFS_max_cycles;
float gOpponent_nastyness_frigger = 1.f;
char gOppo_path_filename[256];
br_scalar gIn_view_distance;
tU8* gBit_per_node;
int gGrudge_reduction_per_period;
int gSFS_cycles_this_time;
br_scalar gMinimum_yness_before_knackerisation;
int gWanky_arse_tit_fuck;
br_scalar gHead_on_cos_value;
tU32 gNext_grudge_reduction;
br_scalar gCop_pursuit_speed_percentage_multiplier;
br_scalar gDefinite_cop_pursuit_speed;
int gAcknowledged_start;
int gStart_jumped;
int gNum_of_opponents_getting_near;
int gNumber_of_cops_before_faffage;
int gFirst_frame;
tU32 gAcme_frame_count;
br_scalar gDefinite_no_cop_pursuit_speed;
int gNum_of_opponents_completing_race;
int gNum_of_opponents_pursuing;
int gActive_car_list_rebuild_required;
br_scalar gFrame_period_for_this_munging_in_secs;
int gBig_bang;
int gProcessing_opponents;
tU32 gFrame_period_for_this_munging;
tU32 gTime_stamp_for_this_munging;
tS16 gMobile_section;
// IDA: void __usercall PointActorAlongThisBloodyVector(br_actor *pThe_actor@<EAX>, br_vector3 *pThe_vector@<EDX>)
void PointActorAlongThisBloodyVector(br_actor* pThe_actor, br_vector3* pThe_vector) {
br_transform trans;
LOG_TRACE("(%p, %p)", pThe_actor, pThe_vector);
trans.type = BR_TRANSFORM_LOOK_UP;
BrVector3Copy(&trans.t.look_up.look, pThe_vector);
BrVector3Set(&trans.t.look_up.up, 0.f, 1.f, 0.f);
BrVector3Copy(&trans.t.look_up.t, &pThe_actor->t.t.translate.t);
BrTransformToTransform(&pThe_actor->t, &trans);
}
// IDA: void __usercall ProcessCurrentObjective(tOpponent_spec *pOpponent_spec@<EAX>, tProcess_objective_command pCommand@<EDX>)
void ProcessCurrentObjective(tOpponent_spec* pOpponent_spec, tProcess_objective_command pCommand) {
LOG_TRACE("(%p, %d)", pOpponent_spec, pCommand);
switch (pOpponent_spec->current_objective) {
case eOOT_complete_race:
ProcessCompleteRace(pOpponent_spec, pCommand);
break;
case eOOT_pursue_and_twat:
ProcessPursueAndTwat(pOpponent_spec, pCommand);
break;
case eOOT_run_away:
ProcessRunAway(pOpponent_spec, pCommand);
break;
case eOOT_get_near_player:
ProcessGetNearPlayer(pOpponent_spec, pCommand);
break;
case eOOT_levitate:
ProcessLevitate(pOpponent_spec, pCommand);
break;
case eOOT_knackered_and_freewheeling:
// FIXME: is keys correct?
memset(&pOpponent_spec->car_spec->keys, 0, sizeof(pOpponent_spec->car_spec->keys));
pOpponent_spec->car_spec->acc_force = 0.f;
pOpponent_spec->car_spec->brake_force = 0.f;
pOpponent_spec->car_spec->curvature = 0.f;
break;
case eOOT_frozen:
ProcessFrozen(pOpponent_spec, pCommand);
break;
case eOOT_wait_for_some_hapless_sod:
ProcessWaitForSomeHaplessSod(pOpponent_spec, pCommand);
break;
case eOOT_rematerialise:
break;
case eOOT_return_to_start:
ProcessReturnToStart(pOpponent_spec, pCommand);
break;
default:
break;
}
}
// IDA: tS16 __usercall ReallocExtraPathNodes@<AX>(int pHow_many_then@<EAX>)
tS16 ReallocExtraPathNodes(int pHow_many_then) {
tPath_node* new_nodes;
tS16 first_new_node;
LOG_TRACE("(%d)", pHow_many_then);
first_new_node = -1;
if (pHow_many_then != 0) {
first_new_node = gProgram_state.AI_vehicles.number_of_path_nodes;
new_nodes = BrMemAllocate(sizeof(tPath_node) * (pHow_many_then + gProgram_state.AI_vehicles.number_of_path_nodes), kMem_oppo_new_nodes);
memcpy(new_nodes, gProgram_state.AI_vehicles.path_nodes, sizeof(tPath_node) * gProgram_state.AI_vehicles.number_of_path_nodes);
if (gProgram_state.AI_vehicles.path_nodes != NULL) {
BrMemFree(gProgram_state.AI_vehicles.path_nodes);
}
gProgram_state.AI_vehicles.number_of_path_nodes += pHow_many_then;
gProgram_state.AI_vehicles.path_nodes = new_nodes;
}
dr_dprintf(
"ReallocExtraPathNodes(): Allocated %d bytes for %d path nodes",
sizeof(tPath_node) * (pHow_many_then + gProgram_state.AI_vehicles.number_of_path_nodes),
pHow_many_then);
return first_new_node;
}
// IDA: tS16 __usercall ReallocExtraPathSections@<AX>(int pHow_many_then@<EAX>)
tS16 ReallocExtraPathSections(int pHow_many_then) {
tPath_section* new_sections;
tS16 first_new_section;
LOG_TRACE("(%d)", pHow_many_then);
first_new_section = -1;
if (pHow_many_then) {
first_new_section = gProgram_state.AI_vehicles.number_of_path_sections;
new_sections = BrMemAllocate(sizeof(tPath_section) * (pHow_many_then + gProgram_state.AI_vehicles.number_of_path_sections), kMem_oppo_new_sections);
memcpy(new_sections, gProgram_state.AI_vehicles.path_sections, sizeof(tPath_section) * gProgram_state.AI_vehicles.number_of_path_sections);
if (gProgram_state.AI_vehicles.path_sections) {
BrMemFree(gProgram_state.AI_vehicles.path_sections);
}
gProgram_state.AI_vehicles.number_of_path_sections += pHow_many_then;
gProgram_state.AI_vehicles.path_sections = new_sections;
}
dr_dprintf(
"ReallocExtraPathSections(): Allocated %d bytes for %d path sections",
sizeof(tPath_section) * (pHow_many_then + gProgram_state.AI_vehicles.number_of_path_sections),
pHow_many_then);
return first_new_section;
}
// IDA: int __usercall PointVisibleFromHere@<EAX>(br_vector3 *pFrom@<EAX>, br_vector3 *pTo@<EDX>)
int PointVisibleFromHere(br_vector3* pFrom, br_vector3* pTo) {
br_vector3 from;
br_vector3 dir;
br_vector3 norm;
br_scalar t;
br_material* material;
LOG_TRACE("(%p, %p)", pFrom, pTo);
BrVector3Sub(&dir, pTo, pFrom);
from = *pFrom;
from.v[1] += 0.15f;
dir.v[1] += 0.15f;
FindFace(&from, &dir, &norm, &t, &material);
return t > 1.0;
}
// IDA: tS16 __usercall FindNearestPathNode@<AX>(br_vector3 *pActor_coords@<EAX>, br_scalar *pDistance@<EDX>)
tS16 FindNearestPathNode(br_vector3* pActor_coords, br_scalar* pDistance) {
int i;
tS16 nearest_node;
br_scalar distance;
br_vector3 actor_to_node;
LOG_TRACE("(%p, %p)", pActor_coords, pDistance);
NOT_IMPLEMENTED();
}
// IDA: tS16 __usercall FindNearestPathSection@<AX>(br_vector3 *pActor_coords@<EAX>, br_vector3 *pPath_direction@<EDX>, br_vector3 *pIntersect@<EBX>, br_scalar *pDistance@<ECX>)
tS16 FindNearestPathSection(br_vector3* pActor_coords, br_vector3* pPath_direction, br_vector3* pIntersect, br_scalar* pDistance) {
LOG_TRACE("(%p, %p, %p, %p)", pActor_coords, pPath_direction, pIntersect, pDistance);
return FindNearestGeneralSection(NULL, pActor_coords, pPath_direction, pIntersect, pDistance);
}
// IDA: tS16 __usercall FindNearestGeneralSection@<AX>(tCar_spec *pPursuee@<EAX>, br_vector3 *pActor_coords@<EDX>, br_vector3 *pPath_direction@<EBX>, br_vector3 *pIntersect@<ECX>, br_scalar *pDistance)
tS16 FindNearestGeneralSection(tCar_spec* pPursuee, br_vector3* pActor_coords, br_vector3* pPath_direction, br_vector3* pIntersect, br_scalar* pDistance) {
int section_no;
int no_sections;
tS16 nearest_node_section_no;
tS16 nearest_section;
br_scalar nearest_node_distance_squared;
br_scalar closest_distance_squared;
br_scalar the_distance_squared;
br_scalar t;
br_scalar length_squared_a;
br_vector3 a;
br_vector3 p;
br_vector3 wank;
br_vector3 intersect;
br_vector3* start;
br_vector3* finish;
br_vector3* nearest_node_v;
LOG_TRACE("(%p, %p, %p, %p, %p)", pPursuee, pActor_coords, pPath_direction, pIntersect, pDistance);
nearest_section = -1;
nearest_node_section_no = -1;
closest_distance_squared = BR_SCALAR_MAX;
nearest_node_distance_squared = BR_SCALAR_MAX;
if (pPursuee != NULL) {
no_sections = pPursuee->my_trail.number_of_nodes - 1;
} else {
no_sections = gProgram_state.AI_vehicles.number_of_path_sections;
}
for (section_no = 0; section_no < no_sections; section_no++) {
if (pPursuee != NULL) {
start = &pPursuee->my_trail.trail_nodes[section_no];
finish = &pPursuee->my_trail.trail_nodes[section_no + 1];
} else {
start = &gProgram_state.AI_vehicles.path_nodes[gProgram_state.AI_vehicles.path_sections[section_no].node_indices[0]].p;
finish = &gProgram_state.AI_vehicles.path_nodes[gProgram_state.AI_vehicles.path_sections[section_no].node_indices[1]].p;
}
if (!gAlready_elasticating || gMobile_section != section_no) {
BrVector3Sub(&a, finish, start);
BrVector3Sub(&p, pActor_coords, start);
the_distance_squared = Vector3DistanceSquared(&p, &a);
if (the_distance_squared < closest_distance_squared) {
closest_distance_squared = the_distance_squared;
nearest_section = section_no;
nearest_node_v = finish;
}
the_distance_squared = BrVector3LengthSquared(&p);
if (the_distance_squared < closest_distance_squared) {
closest_distance_squared = the_distance_squared;
nearest_section = section_no;
nearest_node_v = start;
}
length_squared_a = BrVector3LengthSquared(&a);
if (length_squared_a >= 0.0001f) {
t = BrVector3Dot(&p, &a) / length_squared_a;
if (t >= 0 && t <= 1.f) {
p.v[0] -= t * a.v[0];
p.v[1] -= t * a.v[1];
p.v[2] -= t * a.v[2];
the_distance_squared = BrVector3LengthSquared(&p);
if (the_distance_squared < nearest_node_distance_squared) {
BrVector3Scale(&intersect, &a, t);
BrVector3Add(pIntersect, start, &intersect);
BrVector3NormaliseQuick(pPath_direction, &a);
nearest_node_distance_squared = the_distance_squared;
nearest_node_section_no = section_no;
}
}
}
}
}
if (nearest_node_distance_squared > closest_distance_squared) {
nearest_node_section_no = nearest_section;
if (pPursuee != NULL) {
start = &pPursuee->my_trail.trail_nodes[nearest_section];
finish = &pPursuee->my_trail.trail_nodes[nearest_section + 1];
} else {
start = &gProgram_state.AI_vehicles.path_nodes[gProgram_state.AI_vehicles.path_sections[nearest_section].node_indices[0]].p;
finish = &gProgram_state.AI_vehicles.path_nodes[gProgram_state.AI_vehicles.path_sections[nearest_section].node_indices[1]].p;
}
BrVector3Sub(&p, finish, start);
BrVector3NormaliseQuick(pPath_direction, &p);
BrVector3Copy(pIntersect, nearest_node_v);
*pDistance = sqrtf(closest_distance_squared);
} else {
*pDistance = sqrtf(nearest_node_distance_squared);
}
if (pPursuee != NULL) {
nearest_node_section_no += 15000;
}
return nearest_node_section_no;
}
// IDA: void __usercall DeadStopCar(tCar_spec *pCar_spec@<EAX>)
void DeadStopCar(tCar_spec* pCar_spec) {
LOG_TRACE("(%p)", pCar_spec);
pCar_spec->acc_force = 0.f;
pCar_spec->brake_force = 0.f;
pCar_spec->curvature = 0.f;
pCar_spec->gear = 0.f;
pCar_spec->revs = 0.f;
BrVector3SetFloat(&pCar_spec->omega, 0.f, 0.f, 0.f);
BrVector3SetFloat(&pCar_spec->v, 0.f, 0.f, 0.f);
}
// IDA: void __usercall TurnOpponentPhysicsOn(tOpponent_spec *pOpponent_spec@<EAX>)
void TurnOpponentPhysicsOn(tOpponent_spec* pOpponent_spec) {
LOG_TRACE("(%p)", pOpponent_spec);
if (pOpponent_spec->physics_me == 0) {
pOpponent_spec->physics_me = 1;
gActive_car_list_rebuild_required = 1;
}
}
// IDA: void __usercall TurnOpponentPhysicsOff(tOpponent_spec *pOpponent_spec@<EAX>)
void TurnOpponentPhysicsOff(tOpponent_spec* pOpponent_spec) {
LOG_TRACE("(%p)", pOpponent_spec);
DeadStopCar(pOpponent_spec->car_spec);
if (pOpponent_spec->physics_me) {
pOpponent_spec->physics_me = 0;
gActive_car_list_rebuild_required = 1;
}
}
// IDA: void __cdecl NewObjective(tOpponent_spec *pOpponent_spec, tOpponent_objective_type pObjective_type, ...)
void NewObjective(tOpponent_spec* pOpponent_spec, tOpponent_objective_type pObjective_type, ...) {
va_list marker;
LOG_TRACE("(%p, %d)", pOpponent_spec, pObjective_type);
if (pOpponent_spec->current_objective != eOOT_none) {
ProcessCurrentObjective(pOpponent_spec, ePOC_die);
}
pOpponent_spec->current_objective = pObjective_type;
pOpponent_spec->time_this_objective_started = gTime_stamp_for_this_munging;
pOpponent_spec->time_for_this_objective_to_finish = gTime_stamp_for_this_munging + IRandomBetween(30, 180) * 1000;
if (pObjective_type == eOOT_pursue_and_twat) {
pOpponent_spec->time_for_this_objective_to_finish += 90000;
}
switch (pObjective_type) {
case eOOT_complete_race:
gNum_of_opponents_completing_race++;
break;
case eOOT_pursue_and_twat:
va_start(marker, pObjective_type);
pOpponent_spec->pursue_car_data.pursuee = va_arg(marker, tCar_spec*);
va_end(marker);
break;
case eOOT_get_near_player:
gNum_of_opponents_getting_near++;
break;
default:
break;
}
dr_dprintf("%s: NewObjective() - type %d", pOpponent_spec->car_spec->driver_name, pObjective_type);
ProcessCurrentObjective(pOpponent_spec, ePOC_start);
}
// IDA: void __usercall CalcRaceRoute(tOpponent_spec *pOpponent_spec@<EAX>)
void CalcRaceRoute(tOpponent_spec* pOpponent_spec) {
tS16 section_no;
tS16 section_no_index;
tS16 node_no;
tS16 race_section_count;
tS16 normal_section_ok_direction_count;
tS16 normal_section_wrong_direction_count;
tS16 temp_section_array[8];
br_scalar distance;
br_vector3 direction_v;
br_vector3 intersect;
char str[256];
char work_str[32];
int i;
LOG_TRACE("(%p)", pOpponent_spec);
if (pOpponent_spec->nnext_sections >= COUNT_OF(pOpponent_spec->next_sections)) {
dr_dprintf("%s: CalcRaceRoute() - Pissing off 'cos projected route full up", pOpponent_spec->car_spec->driver_name);
return;
}
if (pOpponent_spec->nnext_sections == 0) {
dr_dprintf("%s: CalcRaceRoute() - Projected route empty; starting from nearest section", pOpponent_spec->car_spec->driver_name);
pOpponent_spec->complete_race_data.finished_calcing_race_route = 0;
pOpponent_spec->complete_race_data.found_race_section = 0;
section_no = FindNearestPathSection(&pOpponent_spec->car_spec->car_master_actor->t.t.translate.t, &direction_v, &intersect, &distance);
if (section_no < 0) {
return;
}
AddToOpponentsProjectedRoute(pOpponent_spec, section_no, 1);
if (gProgram_state.AI_vehicles.path_sections[section_no].type == ePST_race_path) {
pOpponent_spec->complete_race_data.found_race_section = 1;
}
}
while (pOpponent_spec->nnext_sections < COUNT_OF(pOpponent_spec->next_sections) && !pOpponent_spec->complete_race_data.finished_calcing_race_route) {
node_no = gProgram_state.AI_vehicles.path_sections[pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1].section_no].node_indices[pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1].direction];
race_section_count = 0;
normal_section_ok_direction_count = 0;
normal_section_wrong_direction_count = 0;
for (i = 0; i < gProgram_state.AI_vehicles.path_nodes[node_no].number_of_sections; i++) {
section_no = gProgram_state.AI_vehicles.path_nodes[node_no].sections[i];
if (pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1].section_no != section_no) {
if (gProgram_state.AI_vehicles.path_sections[section_no].type == 1 && gProgram_state.AI_vehicles.path_sections[section_no].node_indices[0] == node_no) {
pOpponent_spec->complete_race_data.found_race_section = 1;
temp_section_array[race_section_count] = section_no;
race_section_count++;
} else if (race_section_count == 0 && gProgram_state.AI_vehicles.path_sections[section_no].node_indices[0] == node_no) {
temp_section_array[normal_section_ok_direction_count] = section_no;
normal_section_ok_direction_count++;
} else if (race_section_count == 0 && normal_section_ok_direction_count == 0 && (!gProgram_state.AI_vehicles.path_sections[section_no].one_way || gProgram_state.AI_vehicles.path_sections[section_no].node_indices[1] == node_no)) {
temp_section_array[normal_section_wrong_direction_count] = section_no;
normal_section_wrong_direction_count++;
}
}
}
if (race_section_count != 0) {
AddToOpponentsProjectedRoute(pOpponent_spec, temp_section_array[IRandomBetween(0, race_section_count - 1)], 1);
} else if (normal_section_ok_direction_count != 0) {
AddToOpponentsProjectedRoute(pOpponent_spec, temp_section_array[IRandomBetween(0, normal_section_ok_direction_count - 1)], 1);
} else if (normal_section_wrong_direction_count != 0) {
AddToOpponentsProjectedRoute(pOpponent_spec, temp_section_array[IRandomBetween(0, normal_section_wrong_direction_count - 1)], 1);
} else if (pOpponent_spec->complete_race_data.found_race_section) {
pOpponent_spec->complete_race_data.finished_calcing_race_route = 1;
} else {
AddToOpponentsProjectedRoute(pOpponent_spec, pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1].section_no, pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1].direction == 0);
}
}
}
// IDA: void __usercall TopUpRandomRoute(tOpponent_spec *pOpponent_spec@<EAX>, int pSections_to_add@<EDX>)
void TopUpRandomRoute(tOpponent_spec* pOpponent_spec, int pSections_to_add) {
tS16 section_no;
tS16 node_no;
tS16 temp_section_array[8];
int i;
int target;
int num_of_temp_sections;
int direction;
LOG_TRACE("(%p, %d)", pOpponent_spec, pSections_to_add);
if (!pSections_to_add) {
PDEnterDebugger("TopUpRandomRoute() called with no seed (woof, bark, etc.)");
}
if (pSections_to_add >= 0) {
target = MIN(pSections_to_add + pOpponent_spec->nnext_sections, 10);
} else {
target = 10;
}
while (pOpponent_spec->nnext_sections < target) {
node_no = gProgram_state.AI_vehicles.path_sections[pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1].section_no].node_indices[pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1].direction];
if (gProgram_state.AI_vehicles.path_nodes[node_no].number_of_sections <= 1) {
section_no = pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1].section_no;
direction = pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1].direction == 0;
} else {
num_of_temp_sections = 0;
for (i = 0; i < gProgram_state.AI_vehicles.path_nodes[node_no].number_of_sections; i++) {
section_no = gProgram_state.AI_vehicles.path_nodes[node_no].sections[i];
if (pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1].section_no != section_no
&& (!gProgram_state.AI_vehicles.path_sections[section_no].one_way || gProgram_state.AI_vehicles.path_sections[section_no].node_indices[1] != node_no)
&& (pOpponent_spec->cheating || gProgram_state.AI_vehicles.path_sections[section_no].type != ePST_cheat_only)) {
temp_section_array[num_of_temp_sections] = section_no;
num_of_temp_sections++;
}
}
if (num_of_temp_sections == 0) {
section_no = pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1].section_no;
direction = pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1].direction == 0;
} else if (num_of_temp_sections == 1) {
section_no = temp_section_array[0];
direction = gProgram_state.AI_vehicles.path_sections[temp_section_array[0]].node_indices[1] != node_no;
} else {
section_no = temp_section_array[IRandomBetween(0, num_of_temp_sections - 1)];
direction = gProgram_state.AI_vehicles.path_sections[section_no].node_indices[1] != node_no;
}
}
AddToOpponentsProjectedRoute(pOpponent_spec, section_no, direction);
}
}
// IDA: int __usercall SearchForSection@<EAX>(tRoute_section *pTemp_store@<EAX>, tRoute_section *pPerm_store@<EDX>, int *pNum_of_perm_store_sections@<EBX>, tS16 pTarget_section@<ECX>, int pDepth, br_scalar pDistance_so_far, tOpponent_spec *pOpponent_spec)
int SearchForSection(tRoute_section* pTemp_store, tRoute_section* pPerm_store, int* pNum_of_perm_store_sections, tS16 pTarget_section, int pDepth, br_scalar pDistance_so_far, tOpponent_spec* pOpponent_spec) {
static br_scalar shortest_dist;
static int routes_found;
char depth_indent[32];
int direction;
tPath_node* node_ptr;
tS16 node_no;
tS16 section_no;
tS16 section_no_index;
br_scalar distance_so_far;
LOG_TRACE("(%p, %p, %p, %d, %d, %f, %p)", pTemp_store, pPerm_store, pNum_of_perm_store_sections, pTarget_section, pDepth, pDistance_so_far, pOpponent_spec);
// added by dethrace for readability (?)
tS16 section_no_dir_index;
gSFS_cycles_this_time++;
if (pDepth == 1) {
memset(gBit_per_node, 0, (gProgram_state.AI_vehicles.number_of_path_nodes + 7) / 8);
shortest_dist = BR_SCALAR_MAX;
routes_found = 0;
*pNum_of_perm_store_sections = 0;
}
if (pDepth >= 10) {
return 0;
}
node_no = gProgram_state.AI_vehicles.path_sections[pTemp_store[pDepth - 1].section_no].node_indices[pTemp_store[pDepth - 1].direction];
node_ptr = &gProgram_state.AI_vehicles.path_nodes[node_no];
gBit_per_node[node_no / 8] |= 1 << (node_no % 8);
for (section_no_index = 0; section_no_index < node_ptr->number_of_sections; section_no_index++) {
section_no = node_ptr->sections[section_no_index];
direction = gProgram_state.AI_vehicles.path_sections[section_no].node_indices[1] != node_no;
section_no_dir_index = gProgram_state.AI_vehicles.path_sections[section_no].node_indices[direction];
// int b = BYTE4(v8);
// int y = (int)(((BYTE4(v8) ^ (((BYTE4(v8) ^ v8) - BYTE4(v8)) & 7)) - BYTE4(v8)));
// int val = valx(v8);
// LOG_DEBUG("val %d, b %d, y %d", val, b, y);
// int x = ((BYTE4(v8) ^ (((BYTE4(v8) ^ v8) - BYTE4(v8)) & 7)) - BYTE4(v8));
// int x2 = v8 & 7;
// if (x != x2 || val != x) {
// TELL_ME_IF_WE_PASS_THIS_WAY();
// }
if ((gBit_per_node[section_no_dir_index / 8] & (1 << (section_no_dir_index & 7))) == 0
&& (!gProgram_state.AI_vehicles.path_sections[section_no].one_way || direction)
&& (pOpponent_spec->cheating || gProgram_state.AI_vehicles.path_sections[section_no].type != ePST_cheat_only)) {
pTemp_store[pDepth].section_no = section_no;
pTemp_store[pDepth].direction = direction;
distance_so_far = gProgram_state.AI_vehicles.path_sections[section_no].length + pDistance_so_far;
if (pTarget_section == section_no && distance_so_far < shortest_dist) {
shortest_dist = gProgram_state.AI_vehicles.path_sections[section_no].length + pDistance_so_far;
*pNum_of_perm_store_sections = pDepth + 1;
memcpy(pPerm_store, pTemp_store, sizeof(tRoute_section) * *pNum_of_perm_store_sections);
// dword_530DD4 = ++routes_found
routes_found++;
LOG_DEBUG("found route");
if (routes_found >= 2) {
return 1;
}
break;
}
if (pDepth < 9
&& SearchForSection(pTemp_store, pPerm_store, pNum_of_perm_store_sections, pTarget_section, pDepth + 1, distance_so_far, pOpponent_spec)) {
return 1;
}
}
}
gBit_per_node[node_no / 8] &= ~(1 << (node_no % 8));
return 0;
}
// IDA: void __usercall CalcGetNearPlayerRoute(tOpponent_spec *pOpponent_spec@<EAX>, tCar_spec *pPlayer@<EDX>)
void CalcGetNearPlayerRoute(tOpponent_spec* pOpponent_spec, tCar_spec* pPlayer) {
int i;
int pass_2_depth;
int sections_away;
int num_of_perm_store_sections;
int sections_to_copy;
int fuck_it;
tS16 section_no;
tS16 players_section;
br_vector3 section_v;
br_vector3 intersect;
br_scalar distance;
tRoute_section temp_store[10];
tRoute_section perm_store[10];
char work_str[32];
char str[256];
LOG_TRACE("(%p, %p)", pOpponent_spec, pPlayer);
fuck_it = 0;
if (pOpponent_spec->nnext_sections >= COUNT_OF(pOpponent_spec->next_sections)) {
dr_dprintf("%s: CalcGetNearPlayerRoute() - Quitting because route full up", pOpponent_spec->car_spec->driver_name);
return;
}
players_section = FindNearestPathSection(&pPlayer->car_master_actor->t.t.translate.t, §ion_v, &intersect, &distance);
if (players_section < 0) {
PDEnterDebugger("No path section near player. THIS CAN'T HAPPEN!");
return;
}
if (pOpponent_spec->players_section_when_last_calced_full_path != players_section) {
dr_dprintf("%s: CalcGetNearPlayerRoute() - Player has moved since last time (section #%d; was #%d)", pOpponent_spec->car_spec->driver_name, players_section, pOpponent_spec->players_section_when_last_calced_full_path);
ClearOpponentsProjectedRoute(pOpponent_spec);
}
if (pOpponent_spec->nnext_sections == 0) {
pOpponent_spec->players_section_when_last_calced_full_path = players_section;
dr_dprintf("%s: CalcGetNearPlayerRoute() - Empty route; setting players_section_when_last_calced_full_path to #%d", pOpponent_spec->car_spec->driver_name, pOpponent_spec->players_section_when_last_calced_full_path);
section_no = FindNearestPathSection(&pOpponent_spec->car_spec->car_master_actor->t.t.translate.t, §ion_v, &intersect, &distance);
if (section_no < 0) {
return;
}
AddToOpponentsProjectedRoute(pOpponent_spec, section_no, 1);
}
if (pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1].section_no == players_section) {
dr_dprintf("%s: CalcGetNearPlayerRoute() - Last section is player's section (%d), so tack a random one on t'end", pOpponent_spec->car_spec->driver_name, players_section);
TopUpRandomRoute(pOpponent_spec, 1);
}
while (pOpponent_spec->nnext_sections < 6 && !fuck_it) {
temp_store[0] = pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1];
dr_dprintf("%s: CalcGetNearPlayerRoute() - In loop; our section #%d, player's section #%d", pOpponent_spec->car_spec->driver_name, temp_store[0].section_no, players_section);
gSFS_count++;
gSFS_cycles_this_time = 0;
SearchForSection(temp_store, perm_store, &num_of_perm_store_sections, players_section, 1, 0.0, pOpponent_spec);
gSFS_total_cycles += gSFS_cycles_this_time;
if (gSFS_max_cycles < gSFS_cycles_this_time) {
gSFS_max_cycles = gSFS_cycles_this_time;
}
dr_dprintf(">>>SearchForSection() - max %d, avg %.1f", gSFS_max_cycles, gSFS_total_cycles / (float)gSFS_count);
if (num_of_perm_store_sections <= 1) {
dr_dprintf("%s: CalcGetNearPlayerRoute() - SearchForSection() produced bugger all", pOpponent_spec->car_spec->driver_name);
fuck_it = 1;
if (pOpponent_spec->nnext_sections <= 4) {
TopUpRandomRoute(pOpponent_spec, 4 - pOpponent_spec->nnext_sections + 4);
}
} else {
sections_to_copy = MIN(COUNT_OF(pOpponent_spec->next_sections) - pOpponent_spec->nnext_sections, num_of_perm_store_sections - 1);
memcpy(&pOpponent_spec->next_sections[pOpponent_spec->nnext_sections], &perm_store[1], sizeof(tRoute_section) * sections_to_copy);
pOpponent_spec->nnext_sections += sections_to_copy;
TopUpRandomRoute(pOpponent_spec, 1);
}
}
}
// IDA: void __usercall CalcReturnToStartPointRoute(tOpponent_spec *pOpponent_spec@<EAX>)
void CalcReturnToStartPointRoute(tOpponent_spec* pOpponent_spec) {
int i;
int pass_2_depth;
int sections_away;
int num_of_perm_store_sections;
int sections_to_copy;
tS16 section_no;
br_vector3 intersect;
br_vector3 section_v;
br_scalar distance;
tRoute_section temp_store[10];
tRoute_section perm_store[10];
LOG_TRACE("(%p)", pOpponent_spec);
ClearOpponentsProjectedRoute(pOpponent_spec);
section_no = FindNearestPathSection(&pOpponent_spec->car_spec->car_master_actor->t.t.translate.t, §ion_v, &intersect, &distance);
distance = BrVector3Length(§ion_v);
BrVector3Normalise(§ion_v, §ion_v);
if (BrVector3Dot(&pOpponent_spec->car_spec->direction, §ion_v) <= 0.0f) {
AddToOpponentsProjectedRoute(pOpponent_spec, section_no, 0);
} else {
AddToOpponentsProjectedRoute(pOpponent_spec, section_no, 1);
}
temp_store[0] = pOpponent_spec->next_sections[pOpponent_spec->nnext_sections - 1];
gSFS_count++;
gSFS_cycles_this_time = 0;
SearchForSection(temp_store, perm_store, &num_of_perm_store_sections, pOpponent_spec->return_to_start_data.section_no, 1, 0.0f, pOpponent_spec);
gSFS_total_cycles += gSFS_cycles_this_time;
if (gSFS_max_cycles < gSFS_cycles_this_time) {
gSFS_max_cycles = gSFS_cycles_this_time;
}
if (num_of_perm_store_sections <= 1) {
if (pOpponent_spec->nnext_sections <= 6) {
TopUpRandomRoute(pOpponent_spec, 4 - pOpponent_spec->nnext_sections + 4);
}
} else {
sections_to_copy = 10 - pOpponent_spec->nnext_sections;
if (sections_to_copy >= num_of_perm_store_sections - 1) {
sections_to_copy = num_of_perm_store_sections - 1;
}
memcpy(&pOpponent_spec->next_sections[pOpponent_spec->nnext_sections], &perm_store[1], sizeof(tRoute_section) * sections_to_copy);
pOpponent_spec->nnext_sections += sections_to_copy;
TopUpRandomRoute(pOpponent_spec, 1);
}
}
// IDA: void __usercall ClearOpponentsProjectedRoute(tOpponent_spec *pOpponent_spec@<EAX>)
void ClearOpponentsProjectedRoute(tOpponent_spec* pOpponent_spec) {
LOG_TRACE("(%p)", pOpponent_spec);
pOpponent_spec->nnext_sections = 0;
}
// IDA: int __usercall AddToOpponentsProjectedRoute@<EAX>(tOpponent_spec *pOpponent_spec@<EAX>, tS16 pSection_no@<EDX>, int pDirection@<EBX>)
int AddToOpponentsProjectedRoute(tOpponent_spec* pOpponent_spec, tS16 pSection_no, int pDirection) {
LOG_TRACE("(%p, %d, %d)", pOpponent_spec, pSection_no, pDirection);
if (pOpponent_spec->nnext_sections >= COUNT_OF(pOpponent_spec->next_sections)) {
return 0;
}
pOpponent_spec->next_sections[pOpponent_spec->nnext_sections].section_no = pSection_no;
pOpponent_spec->next_sections[pOpponent_spec->nnext_sections].direction = pDirection;
pOpponent_spec->nnext_sections++;
return 1;
}
// IDA: int __usercall ShiftOpponentsProjectedRoute@<EAX>(tOpponent_spec *pOpponent_spec@<EAX>, int pPlaces@<EDX>)
int ShiftOpponentsProjectedRoute(tOpponent_spec* pOpponent_spec, int pPlaces) {
int i;
LOG_TRACE("(%p, %d)", pOpponent_spec, pPlaces);
if (pOpponent_spec->nnext_sections <= pPlaces) {
return 0;
}
for (i = 0; COUNT_OF(pOpponent_spec->next_sections) - pPlaces > i; i++) {
pOpponent_spec->next_sections[i].section_no = pOpponent_spec->next_sections[pPlaces + i].section_no;
pOpponent_spec->next_sections[i].direction = pOpponent_spec->next_sections[pPlaces + i].direction;
}
pOpponent_spec->nnext_sections -= pPlaces;
return 1;
}
// IDA: void __usercall StunTheBugger(tOpponent_spec *pOpponent_spec@<EAX>, int pMilliseconds@<EDX>)
void StunTheBugger(tOpponent_spec* pOpponent_spec, int pMilliseconds) {
LOG_TRACE("(%p, %d)", pOpponent_spec, pMilliseconds);
pOpponent_spec->car_spec->acc_force = 0.f;
pOpponent_spec->car_spec->brake_force = 0.f;
pOpponent_spec->car_spec->curvature = 0.f;
pOpponent_spec->stun_time_ends = MAX(gTime_stamp_for_this_munging + pMilliseconds, pOpponent_spec->stun_time_ends);
}
// IDA: void __usercall UnStunTheBugger(tOpponent_spec *pOpponent_spec@<EAX>)
void UnStunTheBugger(tOpponent_spec* pOpponent_spec) {
LOG_TRACE("(%p)", pOpponent_spec);
pOpponent_spec->stun_time_ends = 0;
}
// IDA: void __usercall ProcessCompleteRace(tOpponent_spec *pOpponent_spec@<EAX>, tProcess_objective_command pCommand@<EDX>)
void ProcessCompleteRace(tOpponent_spec* pOpponent_spec, tProcess_objective_command pCommand) {
br_vector3* initial_pos;
br_actor* car_actor;
tComplete_race_data* data;
int res;
char str[256];
LOG_TRACE("(%p, %d)", pOpponent_spec, pCommand);
switch (pCommand) {
case ePOC_start:
dr_dprintf("%s: ProcessCompleteRace() - new objective started", pOpponent_spec->car_spec->driver_name);
ClearOpponentsProjectedRoute(pOpponent_spec);
CalcRaceRoute(pOpponent_spec);
ProcessFollowPath(pOpponent_spec, ePOC_start, 0, 0, 0);
break;
case ePOC_run:
if (pOpponent_spec->follow_path_data.section_no > 20000) {
ShiftOpponentsProjectedRoute(pOpponent_spec, pOpponent_spec->follow_path_data.section_no - 20000);
pOpponent_spec->follow_path_data.section_no = 20000;
}
res = ProcessFollowPath(pOpponent_spec, ePOC_run, 0, 0, 0);
if (pOpponent_spec->nnext_sections == 0 || res == eFPR_end_of_path) {
dr_dprintf("%s: Giving up following race path because ran out of race path", pOpponent_spec->car_spec->driver_name);
NewObjective(pOpponent_spec, eOOT_get_near_player);
}
if (res != eFPR_OK) {
if (res == eFPR_given_up) {
dr_dprintf("%s: Giving up complete_race because ProcessFollowPath() gave up", pOpponent_spec->car_spec->driver_name);
} else {
dr_dprintf("%s: Giving up complete_race because reached end", pOpponent_spec->car_spec->driver_name);
}
ObjectiveComplete(pOpponent_spec);
}
if (gTime_stamp_for_this_munging > pOpponent_spec->time_this_objective_started + 20000) {
dr_dprintf("%s: Time to give up complete_race. Might be back in a sec, though!", pOpponent_spec->car_spec->driver_name);
ObjectiveComplete(pOpponent_spec);
}
if (pOpponent_spec->nnext_sections < 5 && !pOpponent_spec->complete_race_data.finished_calcing_race_route) {
CalcRaceRoute(pOpponent_spec);
}
break;
default:
break;
}
}
// IDA: void __usercall StartRecordingTrail(tCar_spec *pPursuee@<EAX>)
void StartRecordingTrail(tCar_spec* pPursuee) {
int i;
LOG_TRACE("(%p)", pPursuee);
if (pPursuee->no_of_processes_recording_my_trail == 0) {
dr_dprintf("StartRecordingTrail - starting from scratch");
pPursuee->no_of_processes_recording_my_trail = 1;
pPursuee->my_trail.nodes_shifted_this_frame = 0;
pPursuee->my_trail.has_deviated_recently = 0;
pPursuee->my_trail.number_of_nodes = 2;
pPursuee->my_trail.time_of_next_recording = gTime_stamp_for_this_munging + 500;
BrVector3Copy(&pPursuee->my_trail.base_heading, &pPursuee->direction);
BrVector3Copy(&pPursuee->my_trail.trail_nodes[0], &pPursuee->car_master_actor->t.t.translate.t);
BrVector3Copy(&pPursuee->my_trail.trail_nodes[1], &pPursuee->car_master_actor->t.t.translate.t);
pPursuee->my_trail.trail_nodes[0].v[2] += 0.2f;
} else {
dr_dprintf("StartRecordingTrail - another pursuer attaching");
pPursuee->no_of_processes_recording_my_trail++;
}
}
// IDA: void __usercall RecordNextTrailNode(tCar_spec *pPursuee@<EAX>)
void RecordNextTrailNode(tCar_spec* pPursuee) {
tPursuee_trail* trail;
br_vector3 start1;
br_vector3 finish1;
br_vector3 start2;
br_vector3 finish2;
br_vector3 offset_v;
br_vector3 car_to_last_point_v;
br_scalar length;
int visible;
LOG_TRACE("(%p)", pPursuee);
trail = &pPursuee->my_trail;
if (trail->time_of_next_recording >= gTime_stamp_for_this_munging) {
return;
}
trail->time_of_next_recording = gTime_stamp_for_this_munging + 500;
trail->nodes_shifted_this_frame = 0;
if (BrVector3Dot(&trail->base_heading, &pPursuee->direction) < FastScalarCos(30)) {
trail->has_deviated_recently = 1;
}
BrVector3Sub(&car_to_last_point_v, &trail->trail_nodes[trail->number_of_nodes - 2], &pPursuee->car_master_actor->t.t.translate.t);
length = BrVector3Length(&car_to_last_point_v);
if (length < 0.3f) {
return;
}
CalcNegativeXVector(&offset_v, &trail->trail_nodes[trail->number_of_nodes - 2], &pPursuee->car_master_actor->t.t.translate.t, 0.5f);
BrVector3Add(&start1, &trail->trail_nodes[trail->number_of_nodes - 2], &offset_v);
BrVector3Add(&finish1, &pPursuee->car_master_actor->t.t.translate.t, &offset_v);
BrVector3Sub(&start2, &trail->trail_nodes[trail->number_of_nodes - 2], &offset_v);
BrVector3Sub(&finish2, &pPursuee->car_master_actor->t.t.translate.t, &offset_v);
visible = 1;
if ((trail->has_deviated_recently
|| !(visible = PointVisibleFromHere(&start1, &finish1))
|| !(visible = PointVisibleFromHere(&start2, &finish2))
|| !(visible = PointVisibleFromHere(&trail->trail_nodes[trail->number_of_nodes - 2], &pPursuee->car_master_actor->t.t.translate.t)))
&& ((visible && length > 2.0f) || (!visible && length > 1.5f))) {
if (trail->number_of_nodes >= COUNT_OF(trail->trail_nodes)) {
memmove(trail->trail_nodes, &trail->trail_nodes[1], (COUNT_OF(trail->trail_nodes) - 1) * sizeof(trail->trail_nodes[0]));
trail->nodes_shifted_this_frame = 1;
} else {
trail->number_of_nodes++;
}
trail->has_deviated_recently = 0;
BrVector3Copy(&trail->base_heading, &pPursuee->direction);
}
BrVector3Copy(&trail->trail_nodes[trail->number_of_nodes - 1], &pPursuee->car_master_actor->t.t.translate.t);
}
// IDA: tS16 __usercall FindNearestTrailSection@<AX>(tOpponent_spec *pOpponent_spec@<EAX>, tCar_spec *pPursuee@<EDX>, br_vector3 *pSection_v@<EBX>, br_vector3 *pIntersect@<ECX>, br_scalar *pDistance)
tS16 FindNearestTrailSection(tOpponent_spec* pOpponent_spec, tCar_spec* pPursuee, br_vector3* pSection_v, br_vector3* pIntersect, br_scalar* pDistance) {
LOG_TRACE("(%p, %p, %p, %p, %p)", pOpponent_spec, pPursuee, pSection_v, pIntersect, pDistance);
return FindNearestGeneralSection(pPursuee, &pOpponent_spec->car_spec->car_master_actor->t.t.translate.t, pSection_v, pIntersect, pDistance);
}
// IDA: tS16 __usercall CalcNextTrailSection@<AX>(tOpponent_spec *pOpponent_spec@<EAX>, int pSection@<EDX>)
tS16 CalcNextTrailSection(tOpponent_spec* pOpponent_spec, int pSection) {
int section_no;
tPursuee_trail* trail;
LOG_TRACE("(%p, %d)", pOpponent_spec, pSection);
trail = &pOpponent_spec->pursue_car_data.pursuee->my_trail;
section_no = pSection - 15000;
if (trail->number_of_nodes - 2 > section_no) {
return pSection + 1;
}
return -1;
}
// IDA: void __usercall ProcessPursueAndTwat(tOpponent_spec *pOpponent_spec@<EAX>, tProcess_objective_command pCommand@<EDX>)
void ProcessPursueAndTwat(tOpponent_spec* pOpponent_spec, tProcess_objective_command pCommand) {
tPursue_car_data* data;
br_vector3 wank;
br_vector3 section_v;
br_vector3 intersect;
br_scalar d;
br_scalar s;
br_scalar t;
br_scalar distance;
tFollow_path_result res;
char str[256];
tS16 section_no;
LOG_TRACE("(%p, %d)", pOpponent_spec, pCommand);
data = &pOpponent_spec->pursue_car_data;
if (pCommand == ePOC_start) {
dr_dprintf("%s: ProcessPursueAndTwat() - new objective started", pOpponent_spec->car_spec->driver_name);
data->direct_line_nodes[0].number_of_sections = 1;
data->direct_line_nodes[0].sections[0] = 10000;
data->direct_line_nodes[1].number_of_sections = 1;
data->direct_line_nodes[1].sections[0] = 10000;
data->direct_line_section.node_indices[0] = 10000;
data->direct_line_section.node_indices[1] = 10001;
data->direct_line_section.min_speed[0] = 0;
data->direct_line_section.min_speed[1] = 0;
data->direct_line_section.max_speed[0] = -1;
data->direct_line_section.max_speed[1] = -1;
data->direct_line_section.width = 0.5f;
data->direct_line_section.type = ePST_normal;
data->start_backup_time = 0;
data->time_of_next_visibility_check = 0;
data->time_pursuee_last_visible = 0;
data->time_last_twatted_em = 0;
data->time_last_away_from_pursuee = gTime_stamp_for_this_munging;
data->state = ePCS_what_now;
return;
}
if (pCommand != ePOC_run) {
return;
}
if (CAR_SPEC_IS_ROZZER(pOpponent_spec->car_spec) && pOpponent_spec->distance_from_home > 75.0f) {
dr_dprintf("%s: Completing pursuit objective because I'm out of my precinct", pOpponent_spec->car_spec->driver_name);
NewObjective(pOpponent_spec, eOOT_return_to_start);
return;
}
data->direct_line_section.length = MAX(pOpponent_spec->player_to_oppo_d, 3.0f);
if (pOpponent_spec->player_to_oppo_d > 3.0f) {
data->time_last_away_from_pursuee = gTime_stamp_for_this_munging;
}
if (gOpponents[pOpponent_spec->index].psyche.grudge_against_player < 15u) {
dr_dprintf("%s: Completing pursuit objective because I'm happy now", pOpponent_spec->car_spec->driver_name);
ObjectiveComplete(pOpponent_spec);
return;
}
if (data->state != ePCS_backing_up) {
if (data->time_last_twatted_em + 1000 >= gTime_stamp_for_this_munging || data->time_last_twatted_em + 3000 <= gTime_stamp_for_this_munging || BrVector3Length(&data->pursuee->v) >= 0.3f) {
if (data->time_last_away_from_pursuee + 7000 >= gTime_stamp_for_this_munging || data->time_last_twatted_em + 7000 >= gTime_stamp_for_this_munging || data->start_backup_time + 10000 >= gTime_stamp_for_this_munging) {
if (pOpponent_spec->cheating) {
if (pOpponent_spec->player_to_oppo_d < 50.0f
&& PointVisibleFromHere(&data->pursuee->car_master_actor->t.t.translate.t, &pOpponent_spec->car_spec->car_master_actor->t.t.translate.t)) {
data->time_pursuee_last_visible = gTime_stamp_for_this_munging;
} else {
data->time_pursuee_last_visible = 0;
}
} else if (pOpponent_spec->player_in_view_now || (data->time_of_next_visibility_check < gTime_stamp_for_this_munging && pOpponent_spec->player_to_oppo_d < 35.0f && PointVisibleFromHere(&data->pursuee->car_master_actor->t.t.translate.t, &pOpponent_spec->car_spec->car_master_actor->t.t.translate.t))) {
data->time_pursuee_last_visible = gTime_stamp_for_this_munging;
data->time_of_next_visibility_check = gTime_stamp_for_this_munging + 600;
}
if (data->time_pursuee_last_visible + 3000 <= gTime_stamp_for_this_munging) {
if (data->pursuee->my_trail.number_of_nodes < 2) {
dr_dprintf("%s: Giving up pursuit - not visible & no trail yet", pOpponent_spec->car_spec->driver_name);
NewObjective(pOpponent_spec, eOOT_get_near_player);
return;
}
if (data->state != ePCS_following_trail) {
section_no = FindNearestTrailSection(pOpponent_spec, data->pursuee, §ion_v, &intersect, &distance);
data->state = ePCS_following_trail;
if (distance > 20.0f || section_no == -1) {
dr_dprintf("%s: Giving up pursuit - not visible & trail ain't close enough (%f)", pOpponent_spec->car_spec->driver_name, distance);
NewObjective(pOpponent_spec, eOOT_get_near_player);
return;
}
dr_dprintf("%s: Commencing ePCS_following_trail state", pOpponent_spec->car_spec->driver_name);
pOpponent_spec->follow_path_data.section_no = section_no;
ProcessFollowPath(pOpponent_spec, ePOC_start, 1, 0, 0);
}
} else if (data->state != ePCS_following_line_of_sight) {
dr_dprintf("%s: Commencing ePCS_following_line_of_sight state", pOpponent_spec->car_spec->driver_name);
data->state = ePCS_following_line_of_sight;
sprintf(str, "%s: I've spotted you!", pOpponent_spec->car_spec->driver_name);
ProcessFollowPath(pOpponent_spec, ePOC_start, 1, 1, 0);
}
} else {
dr_dprintf("%s: Backing up because we're too close to pursuee without having twatted him", pOpponent_spec->car_spec->driver_name);
data->start_backup_time = gTime_stamp_for_this_munging;
data->state = ePCS_backing_up;
}
} else {
dr_dprintf("%s: Backing up because we're 'stationary' after colliding with pursuee", pOpponent_spec->car_spec->driver_name);
data->start_backup_time = gTime_stamp_for_this_munging;
data->state = ePCS_backing_up;