forked from Bad-Scientists/AF-Script-Packet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routines_waynet.d
1722 lines (1332 loc) · 49.2 KB
/
routines_waynet.d
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
/*
* Global variables
*/
var oCRtnManager MEM_RtnMan;
/*
* zCVobSpot / FreePoint engine functions
*/
func void zCVobSpot_MarkAsUsed (var int vobSpotPtr, var int timeDeltaF, var int vobPtr) {
//0x007094A0 public: void __thiscall zCVobSpot::MarkAsUsed(float,class zCVob *)
const int zCVobSpot__MarkAsUsed_G1 = 7378080;
//0x007B31A0 public: void __thiscall zCVobSpot::MarkAsUsed(float,class zCVob *)
const int zCVobSpot__MarkAsUsed_G2 = 8073632;
if (!Hlp_Is_zCVobSpot (vobSpotPtr)) { return; };
const int call = 0;
if (CALL_Begin(call)) {
CALL_PtrParam (_@ (vobPtr));
CALL_FloatParam (_@ (timeDeltaF));
CALL__thiscall (_@ (vobSpotPtr), MEMINT_SwitchG1G2 (zCVobSpot__MarkAsUsed_G1, zCVobSpot__MarkAsUsed_G2));
call = CALL_End();
};
};
//Function updates availability if there is no vob on vobSpot (freepoint) --> this will proactively clears freepoint availability
func int zCVobSpot_IsAvailable (var int vobSpotPtr, var int vobPtr) {
//0x00709320 public: int __thiscall zCVobSpot::IsAvailable(class zCVob *)
const int zCVobSpot__IsAvailable_G1 = 7377696;
//0x007B3020 public: int __thiscall zCVobSpot::IsAvailable(class zCVob *)
const int zCVobSpot__IsAvailable_G2 = 8073248;
if (!Hlp_Is_zCVobSpot (vobSpotPtr)) { return 0; };
var int retVal;
const int call = 0;
if (CALL_Begin (call)) {
CALL_PutRetValTo (_@ (retVal));
CALL_PtrParam (_@ (vobPtr));
CALL__thiscall (_@ (vobSpotPtr), MEMINT_SwitchG1G2 (zCVobSpot__IsAvailable_G1, zCVobSpot__IsAvailable_G2));
call = CALL_End ();
};
return + retVal;
};
/*
* MEM_RtnMan init function
*/
//0x008DC220 class oCRtnManager rtnMan
const int MEMINT_RtnMan_Address_G1 = 9290272;
//0x00AB31C8 class oCRtnManager rtnMan
const int MEMINT_RtnMan_Address_G2 = 11219400;
func void MEM_RtnMan_Init () {
MEM_RtnMan = _^ (MEMINT_SwitchG1G2 (MEMINT_RtnMan_Address_G1, MEMINT_RtnMan_Address_G2));
};
/*
* zCWaypoint_GetName
* - returns waypoints name
*/
func string zCWaypoint_GetName (var int wpPtr) {
if (!Hlp_Is_zCWaypoint (wpPtr)) { return ""; };
var zCWaypoint wp; wp = _^ (wpPtr);
return wp.Name;
//0x00706110 public: class zSTRING const & __thiscall zCWaypoint::GetName(void)
//const int zCWaypoint__GetName_G1 = 7364880;
//0x007AFD10 public: class zSTRING const & __thiscall zCWaypoint::GetName(void)
//const int zCWaypoint__GetName_G2 = 8060176;
//var int strPtr;
//CALL__thiscall (wpPtr, MEMINT_SwitchG1G2 (zCWaypoint__GetName_G1, zCWaypoint__GetName_G2));
//strPtr = CALL_RetValAsPtr ();
//return MEM_ReadString (strPtr);
};
/*
* zCVobWaypoint_GetWaypoint
* - returns pointer to waypoint
*/
func int zCVobWaypoint_GetWaypoint (var int vobPtr) {
if (!Hlp_Is_zCVobWaypoint (vobPtr)) { return 0; };
var string vobWaypointName; vobWaypointName = zCVob_GetName (vobPtr);
return + SearchWaypointByName (vobWaypointName);
};
/*
*
*/
func void oCRtnManager_RemoveEntry (var int rtnEntryPtr) {
//0x006CE040 public: void __thiscall oCRtnManager::RemoveEntry(class oCRtnEntry *)
const int oCRtnManager__RemoveEntry_G1 = 7135296;
//0x00775E70 public: void __thiscall oCRtnManager::RemoveEntry(class oCRtnEntry *)
const int oCRtnManager__RemoveEntry_G2 = 7822960;
const int call = 0;
if (CALL_Begin (call)) {
var int rtnManPtr; rtnManPtr = MEMINT_SwitchG1G2 (MEMINT_RtnMan_Address_G1, MEMINT_RtnMan_Address_G2);
CALL_PtrParam (_@ (rtnEntryPtr));
CALL__thiscall (_@ (rtnManPtr), MEMINT_SwitchG1G2 (oCRtnManager__RemoveEntry_G1, oCRtnManager__RemoveEntry_G2));
call = CALL_End ();
};
};
/*
*
*/
func void oCRtnManager_RemoveRoutine (var int npcPtr) {
//0x006CE0C0 public: void __thiscall oCRtnManager::RemoveRoutine(class oCNpc *)
const int oCRtnManager__RemoveRoutine_G1 = 7135424;
//0x00775EF0 public: void __thiscall oCRtnManager::RemoveRoutine(class oCNpc *)
const int oCRtnManager__RemoveRoutine_G2 = 7823088;
const int call = 0;
if (CALL_Begin (call)) {
var int rtnManPtr; rtnManPtr = MEMINT_SwitchG1G2 (MEMINT_RtnMan_Address_G1, MEMINT_RtnMan_Address_G2);
CALL_PtrParam (_@ (npcPtr));
CALL__thiscall (_@ (rtnManPtr), MEMINT_SwitchG1G2 (oCRtnManager__RemoveRoutine_G1, oCRtnManager__RemoveRoutine_G2));
call = CALL_End ();
};
};
func int oCRtnManager_FindRoutine (var int slfInstance, var int rtnBeforePtr, var int rtnNowPtr) {
//0x006CD720 public: int __thiscall oCRtnManager::FindRoutine(class oCNpc *,class oCRtnEntry * &,class oCRtnEntry * &)
const int oCRtnManager__FindRoutine_G1 = 7132960;
//0x00775580 public: int __thiscall oCRtnManager::FindRoutine(class oCNpc *,class oCRtnEntry * &,class oCRtnEntry * &)
const int oCRtnManager__FindRoutine_G2 = 7820672;
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
If (!Hlp_IsValidNPC (slf)) { return FALSE; };
//--> safety check: function can be called only when NPC has routine - otherwise game will crash!
var int statePtr; statePtr = NPC_GetNPCState (slfInstance);
if (!statePtr) { return FALSE; };
var oCNPC_States state; state = _^ (statePtr);
if (!state.hasRoutine) { return FALSE; };
//<--
var int slfPtr; slfPtr = _@ (slf);
var int retVal;
const int call = 0;
if (CALL_Begin (call)) {
var int rtnManPtr; rtnManPtr = MEMINT_SwitchG1G2 (MEMINT_RtnMan_Address_G1, MEMINT_RtnMan_Address_G2);
CALL_PutRetValTo (_@ (retVal));
CALL_PtrParam (_@ (rtnNowPtr));
CALL_PtrParam (_@ (rtnBeforePtr));
CALL_PtrParam (_@ (slfPtr));
CALL__thiscall (_@ (rtnManPtr), MEMINT_SwitchG1G2 (oCRtnManager__FindRoutine_G1, oCRtnManager__FindRoutine_G2));
call = CALL_End ();
};
return + retVal;
};
func int oCRtnManager_GetRoutinePos (var int slfInstance) {
//0x006CD970 public: class zVEC3 __thiscall oCRtnManager::GetRoutinePos(class oCNpc *)
const int oCRtnManager__GetRoutinePos_G1 = 7133552;
//0x007757D0 public: class zVEC3 __thiscall oCRtnManager::GetRoutinePos(class oCNpc *)
const int oCRtnManager__GetRoutinePos_G2 = 7821264;
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
If (!Hlp_IsValidNPC (slf)) { return 0; };
var int rtnManPtr; rtnManPtr = MEMINT_SwitchG1G2 (MEMINT_RtnMan_Address_G1, MEMINT_RtnMan_Address_G2);
CALL_RetValIsStruct (12);
CALL_PtrParam (_@ (slf));
CALL__thiscall (rtnManPtr, MEMINT_SwitchG1G2 (oCRtnManager__GetRoutinePos_G1, oCRtnManager__GetRoutinePos_G2));
return CALL_RetValAsPtr ();
};
func void oCRtnManager_RemoveAllRoutines () {
MEM_RtnMan_Init ();
var zCListSort list;
var int rtnPtr; rtnPtr = MEM_RtnMan.rtnList_next;
while (rtnPtr);
list = _^ (rtnPtr);
if (list.data) {
var oCRtnEntry rtn; rtn = _^ (list.data);
oCRtnManager_RemoveRoutine (rtn.npc);
};
rtnPtr = MEM_RtnMan.rtnList_next;
end;
};
func int oCRtnManager_GetNpcRoutines (var int slfInstance) {
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return 0; };
var int slfPtr; slfPtr = _@ (slf);
MEM_RtnMan_Init ();
var int rtnArrayPtr; rtnArrayPtr = MEM_ArrayCreate ();
var zCListSort list;
var int rtnPtr; rtnPtr = MEM_RtnMan.rtnList_next;
while (rtnPtr);
list = _^ (rtnPtr);
if (list.data) {
var oCRtnEntry rtn; rtn = _^ (list.data);
if (rtn.npc == slfPtr) {
MEM_ArrayInsert (rtnArrayPtr, list.data);
};
};
rtnPtr = list.next;
end;
return rtnArrayPtr;
};
/*
*
*/
func int zCWay_GetGoalWaypoint (var int wayPtr, var int wpPtr) {
//0x00704EA0 public: class zCWaypoint * __thiscall zCWay::GetGoalWaypoint(class zCWaypoint *)
const int zCWay__GetGoalWaypoint_G1 = 7360160;
//0x007AEA90 public: class zCWaypoint * __thiscall zCWay::GetGoalWaypoint(class zCWaypoint *)
const int zCWay__GetGoalWaypoint_G2 = 8055440;
if (!wpPtr) { return 0; };
if (!wayPtr) { return 0; };
var int retVal;
const int call = 0;
if (CALL_Begin (call)) {
CALL_PtrParam (_@ (wpPtr));
CALL_PutRetValTo(_@ (retVal));
CALL__thiscall (_@ (wayPtr), MEMINT_SwitchG1G2 (zCWay__GetGoalWaypoint_G1, zCWay__GetGoalWaypoint_G2));
call = CALL_End ();
};
return +retVal;
};
/*
* zCWay_EstimateCost
* - returns zCWay 'manhattan' distance
*/
func void zCWay_EstimateCost (var int wayPtr) {
//0x00704EB0 protected: void __thiscall zCWay::EstimateCost(void)
const int zCWay__EstimateCost_G1 = 7360176;
//0x007AEAA0 protected: void __thiscall zCWay::EstimateCost(void)
const int zCWay__EstimateCost_G2 = 8055456;
if (!wayPtr) { return; };
const int call = 0;
if (CALL_Begin (call)) {
CALL__thiscall (_@ (wayPtr), MEMINT_SwitchG1G2 (zCWay__EstimateCost_G1, zCWay__EstimateCost_G2));
call = CALL_End ();
};
};
/*
* zCWay_GetLength
* - returns zCWay 'air' distance
*/
func int zCWay_GetLength (var int wayPtr) {
//0x00704F20 public: float __thiscall zCWay::GetLength(void)
const int zCWay__GetLength_G1 = 7360288;
//0x007AEB10 public: float __thiscall zCWay::GetLength(void)
const int zCWay__GetLength_G2 = 8055568;
if (!wayPtr) { return FLOATNULL; };
var int retVal;
const int call = 0;
if (CALL_Begin (call)) {
CALL_RetValIsFloat ();
CALL_PutRetValTo (_@ (retVal));
CALL__thiscall (_@ (wayPtr), MEMINT_SwitchG1G2 (zCWay__GetLength_G1, zCWay__GetLength_G2));
call = CALL_End ();
};
return + retVal;
};
/*
* zCRoute_InitWayNode
* - for some reason wayNode is un-initialized, so here we will initialize it
* - we will also setup first target --> it should be starting waypoint
*/
func void zCRoute_InitWayNode (var int rt) {
//Safety check
if (!rt) { return; };
var zCRoute route; route = _^ (rt);
if (!route.wayNode) {
route.wayNode = route.wayList_next;
route.target = route.startWp;
};
};
func int zCWayNet_FindRoute_Positions (var int fromPosPtr, var int toPosPtr, var int vobPtr) {
//0x007068D0 public: class zCRoute * __thiscall zCWayNet::FindRoute(class zVEC3 const &,class zVEC3 const &,class zCVob const *)
const int zCWayNet__FindRoute_G1 = 7366864;
//0x007B04D0 public: class zCRoute * __thiscall zCWayNet::FindRoute(class zVEC3 const &,class zVEC3 const &,class zCVob const *)
const int zCWayNet__FindRoute_G2 = 8062160;
if (!toPosPtr) { return 0; };
if (!fromPosPtr) { return 0; };
if (!MEM_World.wayNet) { return 0; };
var int waynetPtr; waynetPtr = MEM_World.wayNet;
var int retVal;
const int call = 0;
if (CALL_Begin (call)) {
CALL_PtrParam (_@ (vobPtr));
CALL_PtrParam (_@ (toPosPtr));
CALL_PtrParam (_@ (fromPosPtr));
CALL_PutRetValTo(_@ (retVal));
CALL__thiscall (_@ (waynetPtr), MEMINT_SwitchG1G2 (zCWayNet__FindRoute_G1, zCWayNet__FindRoute_G2));
call = CALL_End ();
};
zCRoute_InitWayNode (retVal);
return +retVal;
};
func int zCWayNet_FindRoute_PosToWp (var int fromPosPtr, var int toWaypointPtr, var int vobPtr) {
//0x00706960 public: class zCRoute * __thiscall zCWayNet::FindRoute(class zVEC3 const &,class zCWaypoint *,class zCVob const *)
const int zCWayNet__FindRoute_G1 = 7367008;
//0x007B0560 public: class zCRoute * __thiscall zCWayNet::FindRoute(class zVEC3 const &,class zCWaypoint *,class zCVob const *)
const int zCWayNet__FindRoute_G2 = 8062304;
if (!toWaypointPtr) { return 0; };
if (!fromPosPtr) { return 0; };
if (!MEM_World.wayNet) { return 0; };
var int waynetPtr; waynetPtr = MEM_World.wayNet;
var int retVal;
const int call = 0;
if (CALL_Begin (call)) {
CALL_PtrParam (_@ (vobPtr));
CALL_PtrParam (_@ (toWaypointPtr));
CALL_PtrParam (_@ (fromPosPtr));
CALL_PutRetValTo(_@ (retVal));
CALL__thiscall (_@ (waynetPtr), MEMINT_SwitchG1G2 (zCWayNet__FindRoute_G1, zCWayNet__FindRoute_G2));
call = CALL_End ();
};
zCRoute_InitWayNode (retVal);
return +retVal;
};
func int zCWayNet_FindRoute_Waypoints (var int fromWaypointPtr, var int toWaypointPtr, var int vobPtr) {
//0x00706A40 public: class zCRoute * __thiscall zCWayNet::FindRoute(class zCWaypoint *,class zCWaypoint *,class zCVob const *)
const int zCWayNet__FindRoute_G1 = 7367232;
//0x007B0640 public: class zCRoute * __thiscall zCWayNet::FindRoute(class zCWaypoint *,class zCWaypoint *,class zCVob const *)
const int zCWayNet__FindRoute_G2 = 8062528;
if (!toWaypointPtr) { return 0; };
if (!fromWaypointPtr) { return 0; };
if (!MEM_World.wayNet) { return 0; };
var int waynetPtr; waynetPtr = MEM_World.wayNet;
var int retVal;
const int call = 0;
if (CALL_Begin (call)) {
CALL_PtrParam (_@ (vobPtr));
CALL_PtrParam (_@ (toWaypointPtr));
CALL_PtrParam (_@ (fromWaypointPtr));
CALL_PutRetValTo(_@ (retVal));
CALL__thiscall (_@ (waynetPtr), MEMINT_SwitchG1G2 (zCWayNet__FindRoute_G1, zCWayNet__FindRoute_G2));
call = CALL_End ();
};
zCRoute_InitWayNode (retVal);
return +retVal;
};
func string zCRoute_GetDesc (var int routePtr) {
//0x00708C80 public: class zSTRING __thiscall zCRoute::GetDesc(void)
const int zCRoute__GetDesc_G1 = 7376000;
//0x007B2980 public: class zSTRING __thiscall zCRoute::GetDesc(void)
const int zCRoute__GetDesc_G2 = 8071552;
if (!routePtr) { return ""; };
CALL_RetValIszString();
CALL__thiscall (routePtr, MEMINT_SwitchG1G2 (zCRoute__GetDesc_G1, zCRoute__GetDesc_G2));
return CALL_RetValAszstring ();
};
/*
* zCRoute_GetCost // int
* - function iterates through zCWay list - and calculates total 'cost'
*/
func int zCRoute_GetCost (var int routePtr) {
if (!routePtr) { return 0; };
var zCRoute rt; rt = _^ (routePtr);
//Loop through wayNodes
var int list; list = rt.wayNode;
if (!list) { return 0; };
var int totalCost; totalCost = 0;
while (list);
var zCList l; l = _^ (list);
if (l.data) {
zCWay_EstimateCost (l.data);
var zCWay way; way = _^ (l.data);
totalCost += way.cost;
};
list = l.next;
end;
return totalCost;
};
/*
* zCRoute_GetLength // float
* - function iterates through zCWay list - and calculates total length
*/
func int zCRoute_GetLength (var int routePtr) {
if (!routePtr) { return FLOATNULL; };
var zCRoute rt; rt = _^ (routePtr);
//Loop through wayNodes
var int list; list = rt.wayNode;
if (!list) { return FLOATNULL; };
var int totalCost; totalCost = FLOATNULL;
while (list);
var zCList l; l = _^ (list);
if (l.data) {
totalCost = addF (totalCost, zCWay_GetLength (l.data));
};
list = l.next;
end;
return totalCost;
};
/*
* zCRoute_GetWP
* - function iterates through wayList data and finds which waypoint NPC will visit next (@ index)
*/
func int zCRoute_GetWP (var int routePtr, var int index) {
if (!routePtr) { return 0; };
var zCRoute rt; rt = _^ (routePtr);
if (index <= 0) { index = 1; };
//If we are looking for next waypoint - return target
if (index == 1) { return rt.target; };
//Loop through wayNodes
var int list; list = rt.wayNode;
if (!list) { return 0; };
//Remember target
var int target; target = rt.target;
index += 1;
repeat (i, index); var int i;
var zCList l; l = _^ (list);
if (l.data) {
var zCWay way; way = _^ (l.data);
//Get next waypoint
target = zCWay_GetGoalWaypoint (l.data, target);
if (i == index - 1) {
return +target;
};
};
list = l.next;
//Exit loop if there are no wayNodes
if (!list) { return 0; };
end;
return 0;
};
func int NPC_Route_GetWP (var int slfInstance, var int index) {
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNpc (slf)) { return 0; };
return +zCRoute_GetWP (slf.route, index);
};
func string NPC_Route_GetWPName (var int slfInstance, var int index) {
var int nextWPPtr;
nextWPPtr = NPC_Route_GetWP (slfInstance, index);
if (nextWPPtr) {
return zCWaypoint_GetName (nextWPPtr);
};
return "";
};
func void NPC_FindRoute (var int slfInstance, var string fromWP, var string toWP) {
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
var int wp1;
var int wp2;
//If first waypoint is not supplied - then take nearest
if (!STR_Len (fromWP)) {
fromWP = Npc_GetNearestWP (slf);
};
wp1 = SearchWaypointByName (fromWP);
if (!wp1) { return; };
wp2 = SearchWaypointByName (toWP);
if (!wp2) { return; };
var int routePtr; routePtr = zCWayNet_FindRoute_Waypoints (wp1, wp2, 0);
if (!routePtr) { return; };
oCNpc_SetRoute (slfInstance, routePtr);
};
/*
* zCRoute_Delete
* - *hacky* destructor - using oCNpc_SetRoute to delete route
*/
func void zCRoute_Delete (var int routePtr) {
if (!routePtr) { return; };
if (!Hlp_IsValidNPC (hero)) { return; };
var oCNpc slf; slf = Hlp_GetNpc (hero);
//Backup route
var int bRoute; bRoute = slf.route;
slf.route = 0;
//Setup new route and delete it
oCNpc_SetRoute (slf, routePtr);
oCNpc_SetRoute (slf, 0);
//Restore backed up route
slf.route = bRoute;
};
/*
* Function returns waypoint from last routine entry
*/
func string NPC_GetLastRoutineWP (var int slfInstance) {
var int statePtr; statePtr = NPC_GetNPCState (slfInstance);
if (!statePtr) { return ""; };
var oCNPC_States state; state = _^ (statePtr);
if (!state.hasRoutine) { return ""; };
//If rtnBefore == rtnNow - then return blank string
if (state.rtnBefore == state.rtnNow) { return ""; };
// Unused engine variables
// state.walkmode_routine
// state.weaponmode_routine
// state.aiStateDriven
//
if (state.rntChangeCount == 0) {
state.walkmode_routine = TRUE;
};
if (state.walkmode_routine) {
if (Hlp_Is_oCNpc (state.npc)) {
var oCNpc slf; slf = _^ (state.npc);
if (Hlp_StrCmp (Npc_GetNearestWP (slf), slf.wpName)) {
state.walkmode_routine = FALSE;
};
} else {
state.walkmode_routine = FALSE;
};
};
if (state.walkmode_routine) {
return "";
};
var int rtnEntryPtr; rtnEntryPtr = state.rtnBefore;
if (!rtnEntryPtr) { return ""; };
var oCRtnEntry rtnEntry; rtnEntry = _^ (rtnEntryPtr);
return rtnEntry.wpname;
};
/*
* Custom function for searching freepoints
* - allows us to search for freepoints
* - parameter deprioritizeFreePoint will basically put freepoints with certain strings to the 'end of the list'
* for example we can search for freepoints SMALLTALK and we can deprioritize those freepoints that also contain string _RAIN:
* vobSpotPtr = NPC_GetFreepoint (self, freePoint, "_RAIN", mkf (1200));
* function will prefer freePoint FP_SMALLTALK_XYZ before FP_SMALLTALK_RAIN_XYZ, however if freePoint FP_SMALLTALK_XYZ is marked as used ... function returns FP_SMALLTALK_RAIN_XYZ
*/
func int NPC_GetFreepoint (var int slfInstance, var string freePoint, var string deprioritizeFreePoint, var int searchFlags, var int range, var int distLimit, var int verticalLimit) {
var oCNpc slf; slf = Hlp_GetNpc (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return 0; };
var int i;
var int vobPtr;
var int slfPtr; slfPtr = _@ (slf);
var int dist;
var int dist2;
var int maxDist; maxDist = 999999;
var int maxDist2; maxDist2 = 999999;
var int firstPtr; firstPtr = 0;
var int nearestPtr; nearestPtr = 0;
var int nearestPtr2; nearestPtr2 = 0;
//Get Npc position
var int fromPos[3];
if (!zCVob_GetPositionWorldToPos (_@ (slf), _@ (fromPos))) { return 0; };
//Target position
var int toPos[3];
var int routePtr;
//Collect all vobs in range
var int arrPtr; arrPtr = Wld_CollectVobsInRange (_@ (fromPos), mkf (range));
if (!arrPtr) { return 0; };
var zCArray vobList; vobList = _^ (arrPtr);
repeat (i, vobList.numInArray);
vobPtr = MEM_ReadIntArray (vobList.array, i);
//Seems like engine still returns true when NPC is standing on freepoint
//(this function also checks if object is zCVobSpot)
if (!zCVobSpot_IsAvailable (vobPtr, slfPtr)) {
continue;
};
if (searchFlags & SEARCHVOBLIST_CANSEE) {
if (!oCNPC_CanSee (slfInstance, vobPtr, 1)) {
continue;
};
};
//Check for portal room owner
if (searchFlags & SEARCHVOBLIST_CHECKPORTALROOMOWNER) {
var string portalName; portalName = Vob_GetPortalName (vobPtr);
//If portal room is owned by Npc
if (Wld_PortalGetOwnerInstanceID (portalName) > -1) {
//If this portal is not owned by me - ignore - pretend we don't see it :)
if (!Wld_PortalIsOwnedByNPC (portalName, slf)) {
continue;
};
};
};
if ((abs (NPC_GetHeightToVobPtr (slf, vobPtr)) < verticalLimit) || (verticalLimit == -1)) {
var zCVobSpot vobSpot; vobSpot = _^ (vobPtr);
//Ignore FP that Npc is currently standing on
if (searchFlags & SEARCHVOBLIST_IGNORECURRENTFP) {
if (vobSpot.inUseVob == slfPtr) {
continue;
};
};
var int index1; index1 = STR_IndexOf (vobSpot._zCObject_objectName, freePoint);
var int index2; index2 = STR_IndexOf (vobSpot._zCObject_objectName, deprioritizeFreePoint);
//Matching freePoint name
if (index1 > -1) {
//Find route from Npc to vob - get total distance if Npc travels by waynet
if (searchFlags & SEARCHVOBLIST_USEWAYNET) {
if (zCVob_GetPositionWorldToPos (vobPtr, _@ (toPos))) {
routePtr = zCWayNet_FindRoute_Positions (_@ (fromPos), _@ (toPos), 0);
dist = zCRoute_GetLength (routePtr); //float
zCRoute_Delete (routePtr);
dist = RoundF (dist);
};
} else {
dist = NPC_GetDistToVobPtr (slfInstance, vobPtr); //int
};
if ((dist <= distLimit) || (distLimit == -1)) {
if (!firstPtr) { firstPtr = vobPtr; };
if (dist < maxDist) {
nearestPtr = vobPtr;
maxDist = dist;
};
};
//'Randomize' outcome - this way we won't be searching for nearest FP
/*
if (searchFlags & SEARCHVOBLIST_IGNOREORDER) {
if (Hlp_Random (100) > 50) {
break;
};
};
*/
};
//Matching freePoint name (not matching deprioritizeFreePoint)
if ((index1 > -1) && (index2 == -1) && (STR_Len (deprioritizeFreePoint) > 0)) {
//Find route from Npc to vob - get total distance if Npc travels by waynet
if (searchFlags & SEARCHVOBLIST_USEWAYNET) {
if (zCVob_GetPositionWorldToPos (vobPtr, _@ (toPos))) {
routePtr = zCWayNet_FindRoute_Positions (_@ (fromPos), _@ (toPos), 0);
dist2 = zCRoute_GetLength (routePtr); //float
zCRoute_Delete (routePtr);
dist2 = RoundF (dist2);
};
} else {
dist2 = NPC_GetDistToVobPtr (slfInstance, vobPtr); //int
};
if ((dist2 <= distLimit) || (distLimit == -1)) {
if (dist2 < maxDist2) {
nearestPtr2 = vobPtr;
maxDist2 = dist2;
};
};
};
};
end;
MEM_Free (arrPtr);
if (nearestPtr2) { return nearestPtr2; };
if (nearestPtr) { return nearestPtr; };
return firstPtr;
};
/*
* Function returns freepoint which NPC is standing on
*/
func int NPC_GetCurrentFreepoint (var int slfInstance) {
var oCNpc slf; slf = Hlp_GetNpc (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return 0; };
var int i;
var int vobPtr;
var int slfPtr; slfPtr = _@ (slf);
//Get Npc position
var int fromPos[3];
if (!zCVob_GetPositionWorldToPos (_@ (slf), _@ (fromPos))) { return 0; };
//Collect all vobs in range
var int arrPtr; arrPtr = Wld_CollectVobsInRange (_@ (fromPos), mkf (100));
if (!arrPtr) { return 0; };
var zCArray vobList; vobList = _^ (arrPtr);
repeat (i, vobList.numInArray);
vobPtr = MEM_ReadIntArray (vobList.array, i);
if (Hlp_Is_zCVobSpot (vobPtr)) {
var zCVobSpot vobSpot; vobSpot = _^ (vobPtr);
//Override inUseVob (if not used by anyone) - zCVobSpot_IsAvailable will update it if Npc is not intersecting with freepoint
var int markAsUsed; markAsUsed = FALSE;
if (!vobSpot.inUseVob) {
vobSpot.inUseVob = slfPtr;
markAsUsed = TRUE;
};
if (zCVobSpot_IsAvailable (vobPtr, slfPtr)) {
if (vobSpot.inUseVob == slfPtr) {
if (markAsUsed) {
zCVobSpot_MarkAsUsed (vobPtr, mkf (3000), slfPtr);
};
MEM_Free (arrPtr);
return vobPtr;
};
};
};
end;
MEM_Free (arrPtr);
return 0;
};
/*
* Function returns freepoint name
*/
func string FP_GetFreePointName (var int vobSpotPtr) {
if (!Hlp_Is_zCVobSpot (vobSpotPtr)) { return ""; };
var zCVobSpot vobSpot; vobSpot = _^ (vobSpotPtr);
return vobSpot._zCObject_objectName;
};
/*
* Function checks if Npc is standing on freepoint
*/
func int Npc_IsOnFreepoint (var int slfInstance, var string searchFreePointName) {
var int fp; fp = NPC_GetCurrentFreepoint (slfInstance);
var string fpName; fpName = FP_GetFreePointName (fp);
return (STR_IndexOf (fpName, searchFreePointName) >= 0);
};
/*
* Following format of freepoints is expected
* FP_STAND
* FP_STAND_RAIN
* FP_STAND_RAIN_XYZ123
*
* - function returns freePoint name STAND
*/
func string FP_GetCleanName (var string freePoint) {
var int len; len = STR_Len (freePoint);
//Remove prefix
if (STR_StartsWith (freePoint, "FP_")) {
freePoint = mySTR_SubStr (freePoint, 3, len - 3);
};
var int index; index = STR_IndexOf (freePoint, "_");
if (index > -1) {
freePoint = mySTR_SubStr (freePoint, 0, index);
};
return freePoint;
};
/*
* zCWaypoint_SetName
* - function updates waypoint name
*/
func void zCWaypoint_SetName (var int wpPtr, var string waypointName) {
//0x00705FB0 public: void __thiscall zCWaypoint::SetName(class zSTRING &)
const int zCWaypoint__SetName_G1 = 7364528;
//0x007AFBB0 public: void __thiscall zCWaypoint::SetName(class zSTRING &)
const int zCWaypoint__SetName_G2 = 8059824;
if (!wpPtr) { return; };
CALL_zStringPtrParam (waypointName);
CALL__thiscall (wpPtr, MEMINT_SwitchG1G2 (zCWaypoint__SetName_G1, zCWaypoint__SetName_G2));
};
func int zCWaypoint_HasWay (var int wpPtr1, var int wpPtr2) {
//0x007065B0 public: class zCWay * __thiscall zCWaypoint::HasWay(class zCWaypoint *)
const int zCWaypoint__HasWay_G1 = 7366064;
//0x007B01B0 public: class zCWay * __thiscall zCWaypoint::HasWay(class zCWaypoint *)
const int zCWaypoint__HasWay_G2 = 8061360;
if (!wpPtr1) { return 0; };
if (!wpPtr2) { return 0; };
var int retVal;
const int call = 0;
if (CALL_Begin (call)) {
CALL_PutRetValTo(_@ (retVal));
CALL_PtrParam (_@ (wpPtr2));
CALL__thiscall (_@ (wpPtr1), MEMINT_SwitchG1G2 (zCWaypoint__HasWay_G1, zCWaypoint__HasWay_G2));
call = CALL_End ();
};
return +retVal;
};
func void zCWaypoint_CorrectHeight (var int wpPtr) {
//0x007064A0 public: void __thiscall zCWaypoint::CorrectHeight(class zCWorld *)
const int zCWaypoint__CorrectHeight_G1 = 7365792;
//0x007B00A0 public: void __thiscall zCWaypoint::CorrectHeight(class zCWorld *)
const int zCWaypoint__CorrectHeight_G2 = 8061088;
if (!wpPtr) { return; };
var int worldPtr; worldPtr = _@ (MEM_World);
const int call = 0;
if (CALL_Begin (call)) {
CALL_PtrParam (_@ (worldPtr));
CALL__thiscall (_@ (wpPtr), MEMINT_SwitchG1G2 (zCWaypoint__CorrectHeight_G1, zCWaypoint__CorrectHeight_G2));
call = CALL_End ();
};
};
/*
* zCWayNet_GetNearestWaypoint
* - returns nearest waypoint to pos pointer
*/
func int zCWayNet_GetNearestWaypoint (var int posPtr) {
//0x00703A50 public: class zCWaypoint * __fastcall zCWayNet::GetNearestWaypoint(class zVEC3 const &)
const int zCWayNet__GetNearestWaypoint_G1 = 7354960;
//0x007AD660 public: class zCWaypoint * __fastcall zCWayNet::GetNearestWaypoint(class zVEC3 const &)
const int zCWayNet__GetNearestWaypoint_G2 = 8050272;
if (!posPtr) { return 0; };
if (!MEM_World.wayNet) { return 0; };
var int waynetPtr; waynetPtr = MEM_World.wayNet;
var int retVal;
const int call = 0;
if (CALL_Begin (call)) {
CALL_PutRetValTo(_@ (retVal));
CALL__fastcall (_@ (wayNetPtr) , _@ (posPtr), MEMINT_SwitchG1G2 (zCWayNet__GetNearestWaypoint_G1, zCWayNet__GetNearestWaypoint_G2));
call = CALL_End ();
};
return + retVal;
};
/*
* zCWayNet_InsertWaypoint
* - creates waypoint at xyz coordinates
*/
// !!! Do not add to waynet waypoints with this function ... further below explanation in WP_Create function
//func int zCWayNet_InsertWaypoint (var int x, var int y, var int z) {
// //0x007033E0 public: class zCWaypoint * __thiscall zCWayNet::InsertWaypoint(float,float,float)
// const int zCWayNet__InsertWaypoint_G1 = 7353312;
// //0x007ACFF0 public: class zCWaypoint * __thiscall zCWayNet::InsertWaypoint(float,float,float)
// const int zCWayNet__InsertWaypoint_G2 = 8048624;
// if (!MEM_World.wayNet) { return 0; };
// //MEM_Waynet
// CALL_FloatParam (z);
// CALL_FloatParam (y);
// CALL_FloatParam (x);
// CALL__thiscall (MEM_World.wayNet, MEMINT_SwitchG1G2 (zCWayNet__InsertWaypoint_G1, zCWayNet__InsertWaypoint_G2));
// return CALL_RetValAsPtr ();
//};
/*
* zCWayNet_InsertWaypoint_ByPtr
* - function inserts waypoint to waynet
*/