-
Notifications
You must be signed in to change notification settings - Fork 2
/
AI_Functions.d
1493 lines (1157 loc) · 42.3 KB
/
AI_Functions.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
/*
* AI functions
* - dependencies:
EngineClasses_G1/2\zEventMan.d
EngineClasses_G1/2\zCVobSpot.d
vectors.d
vobFunctions.d
ScriptBin\insertAnything.d
ObjectFactory\oCMsgMovement.d
ObjectFactory\oCMsgManipulate.d
eventManager_engine.d
eventManager.d
world_engine.d
*/
/*
* AI_TurnToPos
* - same as AI_TurnToNPC, but allows us to use position
*/
func void AI_TurnToPos (var int slfInstance, var int posPtr) {
/*
if (!posPtr) { return; };
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
slf.soundPosition[0] = MEM_ReadIntArray(posPtr, 0);
slf.soundPosition[1] = MEM_ReadIntArray(posPtr, 1);
slf.soundPosition[2] = MEM_ReadIntArray(posPtr, 2);
AI_TurnToSound (slf);
*/
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
if (!posPtr) { return; };
//Create new message
var int eMsg; eMsg = oCMsgMovement_Create (EV_TURNTOPOS, STR_EMPTY, 0, posPtr, mkf (0), 0);
//Get Event Manager
var int eMgr; eMgr = zCVob_GetEM (_@ (slf));
//Add new msg to Event Manager
zCEventManager_OnMessage (eMgr, eMsg, _@ (slf));
};
/*
* AI_TurnAwayPos
* - same as AI_TurnAway, but allows us to use position
*/
func void AI_TurnAwayPos (var int slfInstance, var int posPtr) {
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
if (!posPtr) { return; };
var int posSelf[3]; //position - slf
var int dir[3]; //direction - slf - wp
var int pos[3]; //position - vob
copyVector (posPtr, _@ (pos));
//get position of slf
TrfToPos (_@ (slf._zCVob_trafoObjToWorld), _@ (posSelf));
//subtract posSelf from pos - to get 'direction vector'
SubVectors (_@ (dir), _@(pos), _@ (posSelf));
//subtract direction vector from posSelf - should be basically pos rotated by 180 around self pos
SubVectors (_@ (pos), _@ (posSelf), _@ (dir));
AI_TurnToPos (slf, _@ (pos));
};
/*
AI_TurnAwayWP
- same as AI_TurnAway, but allows us to use waypoint
[waypoint]
/
/
[self] ([dir vector] = [waypoint] - [self])
/
/
[pos] (pos = [self] - [dir vector])
*/
func void AI_TurnAwayWP (var int slfInstance, var string waypoint) {
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
var int wpPtr; wpPtr = SearchWaypointByName (waypoint);
if (!wpPtr) { return; };
var zCWaypoint wp; wp = _^ (wpPtr);
AI_TurnAwayPos (slf, _@ (wp.pos));
};
/*
* AI_TurnToVobPtr
* - same as AI_TurnToNPC, but allows us to use vob pointer
*/
func void AI_TurnToVobPtr (var int slfInstance, var int vobPtr) {
if (!vobPtr) { return; };
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
var zCVob vob; vob = _^(vobPtr);
var int pos[3];
TrfToPos (_@(vob.trafoObjToWorld), _@ (pos));
AI_TurnToPos (slf, _@ (pos));
};
/*
* AI_TurnAwayVobPtr
* - same as AI_TurnAway, but allows us to use vob pointer
*/
func void AI_TurnAwayVobPtr (var int slfInstance, var int vobPtr) {
if (!vobPtr) { return; };
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
var zCVob vob; vob = _^(vobPtr);
var int pos[3]; //position - vob
TrfToPos (_@ (vob.trafoObjToWorld), _@ (pos));
AI_TurnAwayPos (slf, _@ (pos));
};
/*
* AI_GotoPos
* - same as AI_GotoNPC, but allows us to define position to which NPC should walk to
*/
func void AI_GotoPos (var int slfInstance, var int posPtr) {
/*
if (!posPtr) { return; };
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
slf.soundPosition[0] = MEM_ReadIntArray(posPtr, 0);
slf.soundPosition[1] = MEM_ReadIntArray(posPtr, 1);
slf.soundPosition[2] = MEM_ReadIntArray(posPtr, 2);
AI_GotoSound (slf);
*/
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
if (!posPtr) { return; };
//Create new message
var int eMsg; eMsg = oCMsgMovement_Create (EV_GOTOPOS, STR_EMPTY, 0, posPtr, mkf (0), 0);
//Get Event Manager
var int eMgr; eMgr = zCVob_GetEM (_@ (slf));
//Add new msg to Event Manager
zCEventManager_OnMessage (eMgr, eMsg, _@ (slf));
};
/*
* AI_GotoPos_Ext
* - same as AI_GotoPos, but allows us to define maxTargetDist
*/
func void AI_GotoPos_Ext (var int slfInstance, var int posPtr, var int maxTargetDist) {
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
if (!posPtr) { return; };
//Create new message
var int eMsg; eMsg = oCMsgMovement_Create (EV_GOTOPOS, STR_EMPTY, 0, posPtr, mkf (0), 0);
//Init robust trace
oCNpc_RbtInit (slfInstance, posPtr, 0);
//Setup additional parameters for robust trace
//Define locally (G1 class def has different naming convention than the one in G2A ... values are same though)
const int oTRobustTrace_bitfield_exactPosition = ((1 << 1) - 1) << 2;
const int oTRobustTrace_bitfield_standIfTargetReached = ((1 << 1) - 1) << 4;
//const int oCNpc_oTRobustTrace_bitfield_exactPosition = ((1 << 1) - 1) << 2;
//const int oCNpc_oTRobustTrace_bitfield_standIfTargetReached = ((1 << 1) - 1) << 4;
slf.rbt_bitfield = slf.rbt_bitfield | oTRobustTrace_bitfield_standIfTargetReached;
slf.rbt_bitfield = slf.rbt_bitfield & ~ oTRobustTrace_bitfield_exactPosition;
slf.rbt_maxTargetDist = mkf(maxTargetDist * maxTargetDist);
//Set inUse
oCNpcMessage_SetInUse (eMsg, 1);
//Get Event Manager
var int eMgr; eMgr = zCVob_GetEM (_@ (slf));
//Add new msg to Event Manager
zCEventManager_OnMessage (eMgr, eMsg, _@ (slf));
};
/*
* AI_GotoVobPtr_EvalWaynetUse
* - function evaluates whether to use or not waynet system to navigate to vob (this way Npc should be behaving slightly more inteligent)
*
* Rules:
* - Npc has to be standing close to waypoint (x meters), waypoint has to be visible to Npc
* - vob has to be close to waypoint (x meters), waypoint has to be visible to vob
* - if vob is visible to Npc - then waynet distance cannot be longer than 120% of 'air' distance to vob
* - if any chasm is detected - then waynet will be used by default
* - if vob is not visible to Npc - then waynet will be used by default
*/
func void AI_GotoVobPtr_EvalWaynetUse (var int slfInstance, var int vobPtr) {
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
var int slfPtr; slfPtr = _@ (slf);
var int posNpc[3];
var int posVob[3];
//Get Npc position
if (!zCVob_GetPositionWorldToPos (_@ (slf), _@ (posNpc)))
//Get Vob position
|| (!zCVob_GetPositionWorldToPos (vobPtr, _@ (posVob)))
{
return;
};
//Update vob position with ideal position in case of oCMobInter objects
if (Hlp_Is_oCMobInter(vobPtr)) {
//func void oCMobInter_ScanIdealPositions (var int mobPtr) {
//0x0067C9C0 protected: void __thiscall oCMobInter::ScanIdealPositions(void)
const int oCMobInter__ScanIdealPositions_G1 = 6801856;
//0x0071DC30 public: void __thiscall oCMobInter::ScanIdealPositions(void)
const int oCMobInter__ScanIdealPositions_G2 = 7461936;
const int call = 0;
if (CALL_Begin(call)) {
CALL__thiscall (_@ (vobPtr), MEMINT_SwitchG1G2 (oCMobInter__ScanIdealPositions_G1, oCMobInter__ScanIdealPositions_G2));
call = CALL_End();
};
//};
//func int oCMobInter_GetFreePosition (var int mobPtr, var int slfInstance, var int vecPtr) {
//0x0067CD00 public: int __thiscall oCMobInter::GetFreePosition(class oCNpc *,class zVEC3 &)
const int oCMobInter__GetFreePosition_G1 = 6802688;
//0x0071DF50 public: int __thiscall oCMobInter::GetFreePosition(class oCNpc *,class zVEC3 &)
const int oCMobInter__GetFreePosition_G2 = 7462736;
var int freePos[3]; var int freePosPtr; freePosPtr = _@(freePos);
const int call2 = 0;
if (CALL_Begin(call2)) {
CALL_PtrParam (_@ (freePosPtr));
CALL_PtrParam (_@ (slfPtr));
CALL__thiscall (_@ (vobPtr), MEMINT_SwitchG1G2 (oCMobInter__GetFreePosition_G1, oCMobInter__GetFreePosition_G2));
call2 = CALL_End();
};
var int retVal; retVal = CALL_RetValAsInt ();
if (retVal) {
MEM_CopyBytes(freePosPtr, _@(posVob), 12);
};
//};
};
//-- Get nearest waypoint to vob
//var string toWp; toWp = WP_GetNearestWPAtVob (vobPtr);
var string toWp; toWp = WP_GetByPosAndPortalRoom (_@ (posVob), STR_EMPTY, STR_EMPTY, SEARCHVOBLIST_CANSEE, vobPtr, 500, 500, 400);
//if vob is not visible from waypoint ... ignore
if (!STR_Len (toWp)) {
//zSpy_Info ("... target waypoint - can't see vob. Waynet might not be reliable.");
//zSpy_Info ("<--");
return;
};
var int wpDistToVob;
wpDistToVob = WP_GetDistToVob (toWp, vobPtr); //float
wpDistToVob = RoundF (wpDistToVob);
//-- Get nearest waypoint to Npc
//var string fromWp; fromWp = WP_GetNearestWPAtVob (_@ (slf));
var string fromWp; fromWp = WP_GetByPosAndPortalRoom (_@ (posNpc), STR_EMPTY, STR_EMPTY, SEARCHVOBLIST_CANSEE, _@ (slf), 500, 500, 400);
//if vob is not visible from waypoint ... ignore
if (!STR_Len (fromWp)) {
//zSpy_Info ("... npc waypoint - can't see npc. Waynet might not be reliable.");
//zSpy_Info ("<--");
return;
};
//If nearest fromWp & toWp are one and the same - exit
if (Hlp_StrCmp (fromWp, toWp)) {
return;
};
var int wpDistToNpc;
wpDistToNpc = WP_GetDistToVob (fromWp, _@ (slf)); //float
wpDistToNpc = RoundF (wpDistToNpc);
//-- Get 'air' distance to vob
var int distToVob;
distToVob = zCVob_GetDistanceToVob (_@ (slf), vobPtr); //float
var int npcDistToVobWp;
npcDistToVobWp = Npc_GetDistToWP (slf, toWp); //int
var int vobDistToFromWp;
vobDistToFromWp = WP_GetDistToVob (fromWp, vobPtr); //float
//-- Evaluate waynet route
//multiply by 120%
var int distToVobTolerance; distToVobTolerance = distToVob;
distToVobTolerance = mulf (distToVobTolerance, mkf (120));
distToVobTolerance = divf (distToVobTolerance, mkf (100));
distToVobTolerance = RoundF (distToVobTolerance);
var int fromWpPtr; fromWpPtr = SearchWaypointByName (fromWp);
var int toWpPtr; toWpPtr = SearchWaypointByName (toWp);
var int routePtr; routePtr = zCWayNet_FindRoute_Waypoints (fromWpPtr, toWpPtr, 0);
var int distWaynet; distWaynet = zCRoute_GetLength (routePtr); //float
zCRoute_Delete (routePtr);
distWaynet = RoundF (distWaynet);
var int isTooFar; isTooFar = (distWaynet > distToVobTolerance);
//zSpy_Info (ConcatStrings ("... dist air: ", IntToString (RoundF (distToVob))));
//zSpy_Info (ConcatStrings ("... dist tolerance (120% air dist): ", IntToString (distToVobTolerance)));
//zSpy_Info (ConcatStrings ("... dist waynet: ", IntToString (distWaynet)));
//zSpy_Info (ConcatStrings ("... ", zCRoute_GetDesc (routePtr)));
//-- Detect chasms
/*
* Here we will create waypoint - move it towards vob and detect possible issues with ground. (chasm detection)
* It is more convenient to use waypoint, because we can move it around and use zCWaypoint_CorrectHeight to easily align it to ground.
*/
var int dir[3];
var int chasmDetected; chasmDetected = 0;
//Get direction vector (total distance)
SubVectors (_@ (dir), _@ (posVob), _@ (posNpc));
//Copy vector - we will use vec to move waypoint towards vob
var int vec[3];
CopyVector (_@ (dir), _@ (vec));
//Normalize vector
zVEC3_NormalizeSafe (_@ (vec));
//Multiply by 50 (to get 0.5 m length)
MulVector (_@ (vec), mkf (50));
//Waypoint pointer
var int wpPtr; wpPtr = 0;
var int lastPos[3];
var int newPos[3];
var int i; i = 0;
var int newDistToVob;
CopyVector (_@ (posNpc), _@ (newPos));
//Debugging - generate and leave waypoints for investigation :)
const int Debug_GenerateWaypoints = 0;
var string wpName;
if (!STR_Len (wpName)) {
wpName = "WP_TEMP_DETECTCHASM_001";
};
while (true);
var zCWaypoint wp;
if (Debug_GenerateWaypoints) {
//Create new waypoint
if (i == 0) {
//First waypoint
wpPtr = zCWayNet_GetNearestWaypoint (_@ (posNpc));
} else {
//Generate new name
wpName = WP_GenerateNewName (wpName);
};
wpPtr = WP_Create (wpName, _@ (newPos), wpPtr);
wp = _^ (wpPtr);
//Get last position of waypoint
CopyVector (_@ (wp.pos), _@ (lastPos));
} else {
//Create single waypoint
if (!wpPtr) {
wpPtr = WP_Create (wpName, _@ (newPos), 0);
wp = _^ (wpPtr);
};
};
//Move waypoint towards vob
AddVectors (_@ (wp.pos), _@ (wp.pos), _@ (vec));
//Correct waypoint height - align to ground properly
zCWaypoint_CorrectHeight (wpPtr);
//Get new position of waypoint
CopyVector (_@ (wp.pos), _@ (newPos));
//Get vector from Npc to new position of waypoint (to get length)
SubVectors (_@ (dir), _@ (newPos), _@ (posNpc));
//Get length
var int distNew; distNew = zVEC3_LengthApprox (_@ (dir));
//If we are behind vob position - we can exit loop - no chasms detected so far
if (gef (distNew, distToVob)) {
break;
};
//Detect chasms underneath waypoint
dir[0] = FLOATNULL;
dir[1] = mkf (100);
dir[2] = FLOATNULL;
var int distF; distF = mkf (100);
var int cdNormal[3];
//oCAniCtrl_Human_DetectChasm (var int aniCtrlPtr, var int posPtr, var int dirPtr, var int distPtrF, var int cdNormalPtr) {
chasmDetected = oCAniCtrl_Human_DetectChasm (slf.aniCtrl, _@ (newPos), _@ (dir), _@ (distF), _@ (cdNormal));
//Chasm detected - exit loop
if (chasmDetected) {
break;
};
if (Debug_GenerateWaypoints) {
//zSpy_Info (ConcatStrings ("... chasmDetected", IntToString (chasmDetected)));
//zSpy_Info (ConcatStrings ("... distF", toStringF (distF)));
if (i > 0) {
var int heightDelta;
var int lastHeightDelta;
heightDelta = roundf (subf (lastPos[1], newPos[1]));
//heightDelta = heightDelta - lastHeightDelta;
//zSpy_Info (ConcatStrings ("... height check ", IntToString (heightDelta)));
if (abs (heightDelta) > 50) {
chasmDetected = TRUE;
//break;
};
};
lastHeightDelta = heightDelta;
CopyVector (_@ (wp.pos), _@ (newPos));
};
i += 1;
end;
if (!Debug_GenerateWaypoints) {
//Delete waypoint
zCWayNet_DeleteWaypoint_ByPtr (wpPtr);
} else {
//Connect last waypoint to vob waypoint
if (!chasmDetected) {
zCWayNet_CreateWay (wpPtr, SearchWaypointByName (toWp));
};
};
//--
if (!chasmDetected) {
//if waypoint is too far from vob & it is not on the way to vob ... ignore
if ((wpDistToVob > 300) && (npcDistToVobWp > RoundF (distToVob))) {
//zSpy_Info ("... target waypoint too far");
//zSpy_Info ("<--");
return;
};
//if waypoint is too far from Npc & it is not on the way to vob ... ignore
if ((wpDistToNpc > 300) && (RoundF (vobDistToFromWp) > RoundF (distToVob))) {
//zSpy_Info ("... npc waypoint too far");
//zSpy_Info ("<--");
return;
};
//If Npc can see vob - and if waynet navigation is longer then air distance - ignore ...
if (oCNpc_CanSee (slfInstance, vobPtr, 1) && isTooFar) {
//zSpy_Info ("... npc can see vob + distance through waynet navigation > air distance");
//zSpy_Info ("<--");
return;
};
if (isTooFar) {
//zSpy_Info ("... distance through waynet navigation > air distance ... but npc can't see vob - using waynet");
};
} else {
//zSpy_Info ("... chasm detected!");
};
//var string s; s = "... navigating using waynet, from: ";
//s = ConcatStrings (s, fromWp);
//s = ConcatStrings (s, " to: ");
//s = ConcatStrings (s, toWp);
//zSpy_Info (s);
AI_GotoWp (slf, toWp);
//zSpy_Info ("<--");
};
/*
* AI_GotoFpPtr
* - same as AI_GotoFP, but allows us to define freePoint pointer
*/
func void AI_GotoFpPtr (var int slfInstance, var int vobSpotPtr) {
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
if (!Hlp_Is_zCVobSpot (vobSpotPtr)) { return; };
AI_GotoVobPtr_EvalWaynetUse (slfInstance, vobSpotPtr);
//Flag temporarily as used - so no other NPC will try to go to the same freePoint
var int timeDeltaF; timeDeltaF = mkf (6000);
var int vobPtr; vobPtr = _@ (slf);
//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;
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();
};
//};
var zCVobSpot vobSpot; vobSpot = _^ (vobSpotPtr);
//Create new message
//EV_GOTOFP does not save targetVob into savefile! we have to use targetName
var int eMsg; eMsg = oCMsgMovement_Create (EV_GOTOFP, vobSpot._zCObject_objectName, vobSpotPtr, 0, mkf (0), 0);
//Get Event Manager
var int eMgr; eMgr = zCVob_GetEM (_@ (slf));
//Add new msg to Event Manager
zCEventManager_OnMessage (eMgr, eMsg, _@ (slf));
};
/*
* AI_GotoVobPtr
* - same as AI_GotoNPC, but allows us to use any vob pointer
*/
func void AI_GotoVobPtr (var int slfInstance, var int vobPtr) {
if (!vobPtr) { return; };
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
var zCVob vob; vob = _^(vobPtr);
var int pos[3];
TrfToPos (_@ (vob.trafoObjToWorld), _@ (pos));
AI_GotoVobPtr_EvalWaynetUse (slfInstance, vobPtr);
AI_GotoPos (slf, _@ (pos));
};
func void _AI_TeleportKeepQueue (var string vobName) {
Npc_BeamToKeepQueue (self, vobName);
Wld_PlayEffect ("SPELLFX_TELEPORT_RING", self, self, 0, 0, 0, FALSE);
Snd_Play ("MFX_TELEPORT_CAST");
};
/*
* AI_TeleportKeepQueue
* - function performs teleportation without clearing AI queue (use carefully!)
*/
func void AI_TeleportKeepQueue (var int slfInstance, var string vobName) {
var C_NPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
if (!Npc_HasAni(slf, ANINAME_T_STAND_2_TELEPORT))
&& (!Npc_HasAni(slf, ANINAME_T_MAGRUN_2_HEASHOOT))
&& (!Npc_HasAni(slf, ANINAME_S_TELEPORT))
&& (!Npc_HasAni(slf, ANINAME_S_HEASHOOT))
{
//G1 version has much cooler teleportation animation with particle effects ;-)
if (MEMINT_SwitchG1G2(0, 1))
{
AI_PlayAni(slf, ANINAME_T_STAND_2_TELEPORT);
} else {
AI_PlayAni(slf, ANINAME_T_MAGRUN_2_HEASHOOT);
};
};
AI_Function_S (slf, _AI_TeleportKeepQueue, vobName);
//G1 version has much cooler teleportation animation with particle effects ;-)
if (MEMINT_SwitchG1G2 (1, 0)) {
AI_PlayAni(slf, ANINAME_T_TELEPORT_2_STAND);
} else {
AI_PlayAni(slf, ANINAME_T_HEASHOOT_2_STAND);
};
};
func void _AI_BeamToKeepQueue (var string vobName) {
Npc_BeamToKeepQueue (self, vobName);
};
/*
* AI_BeamToKeepQueue
* - function beams Npc to target vobName / waypoint without clearing AI queue
*/
func void AI_BeamToKeepQueue (var int slfInstance, var string vobName) {
var C_NPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
AI_Function_S (slf, _AI_BeamToKeepQueue, vobName);
};
/*
* AI_TeleportToWorld
* - function allows teleportation between worlds
*/
func void AI_TeleportToWorld (var int slfInstance, var string levelName, var string vobName) {
var C_NPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
var string thisLevelName; thisLevelName = oCWorld_GetWorldFilename ();
if (Hlp_StrCmp (thisLevelName, levelName)) {
AI_TeleportKeepQueue (slfInstance, vobName);
} else {
if (!Npc_HasAni (slf, ANINAME_T_STAND_2_TELEPORT))
&& (!Npc_HasAni (slf, ANINAME_T_MAGRUN_2_HEASHOOT))
{
//G1 version has much cooler teleportation animation with particle effects ;-)
if (MEMINT_SwitchG1G2(0, 1))
{
AI_PlayAni(slf, ANINAME_T_STAND_2_TELEPORT);
} else {
AI_PlayAni(slf, ANINAME_T_MAGRUN_2_HEASHOOT);
};
};
AI_Function_SS (slf, oCGame_TriggerChangeLevel, levelName, vobName);
};
};
/*
* An alternative that will turn to vob only when not within acceptable angle
*/
func void AI_TurnToVobPtrAngleX (var int slfInstance, var int vobPtr, var int angle) {
var int angleX; var int angleXPtr; angleXPtr = _@ (angleX);
var int angleY; var int angleYPtr; angleYPtr = _@ (angleY);
//func void oCNpc_GetAnglesVob (var int slfInstance, var int vobPtr, var int angleXPtr, var int angleYPtr) {
//0x0074C0D0 public: void __thiscall oCNpc::GetAngles(class zCVob *,float &,float &)
const int oCNPC__GetAnglesVob_G1 = 7651536;
//0x00681680 public: void __thiscall oCNpc::GetAngles(class zCVob *,float &,float &)
const int oCNPC__GetAnglesVob_G2 = 6821504;
if (!vobPtr) { return; };
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
var int slfPtr; slfPtr = _@ (slf);
const int call = 0;
if (CALL_Begin(call)) {
CALL_PtrParam (_@ (angleYPtr));
CALL_PtrParam (_@ (angleXPtr));
CALL_PtrParam (_@ (vobPtr));
CALL__thiscall (_@ (slfPtr), MEMINT_SwitchG1G2 (oCNPC__GetAnglesVob_G1, oCNPC__GetAnglesVob_G2));
call = CALL_End();
};
//};
//func int NPC_IsVobPtrInAngleX (var int slfInstance, var int vobPtr, var int angle) {
// var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
// if (!Hlp_IsValidNPC (slf)) { return FALSE; };
// if (!vobPtr) { return FALSE; };
// var int angleX;
// var int angleY;
// oCNpc_GetAnglesVob (slfInstance, vobPtr, _@ (angleX), _@ (angleY));
if (gef (angleX, negf (mkf (angle))))
&& (lef (angleX, mkf (angle)))
{
return;
};
AI_TurnToVobPtr (slfInstance, vobPtr);
};
/*
* Scans for ideal positions, finds free positions and sends there NPC
* Function returns TRUE if successfull, FALSE if not
*/
func int AI_GotoMobPtr (var int slfInstance, var int mobPtr) {
//func void oCMobInter_ScanIdealPositions (var int mobPtr) {
//0x0067C9C0 protected: void __thiscall oCMobInter::ScanIdealPositions(void)
const int oCMobInter__ScanIdealPositions_G1 = 6801856;
//0x0071DC30 public: void __thiscall oCMobInter::ScanIdealPositions(void)
const int oCMobInter__ScanIdealPositions_G2 = 7461936;
if (!Hlp_Is_oCMobInter (mobPtr)) { return FALSE; };
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return FALSE; };
var int slfPtr; slfPtr = _@ (slf);
const int call = 0;
if (CALL_Begin(call)) {
CALL__thiscall (_@ (mobPtr), MEMINT_SwitchG1G2 (oCMobInter__ScanIdealPositions_G1, oCMobInter__ScanIdealPositions_G2));
call = CALL_End();
};
//};
/*
//func int oCMobInter_SearchFreePosition (var int mobPtr, var int slfInstance) {
var int freePosPtr;
//0x0067CD60 protected: virtual struct TMobOptPos * __thiscall oCMobInter::SearchFreePosition(class oCNpc *)
const int oCMobInter__SearchFreePosition_G1 = 6802784;
//0x0071DFC0 public: virtual struct TMobOptPos * __thiscall oCMobInter::SearchFreePosition(class oCNpc *,float)
const int oCMobInter__SearchFreePosition_G2 = 7462848;
var int rangeF; rangeF = mkf (1000);
const int call2 = 0;
if (CALL_Begin(call2)) {
//G2A has 1 extra parameter - I assume range
if (MEMINT_SwitchG1G2 (0, 1)) {
CALL_PtrParam (_@ (rangeF));
};
CALL_PtrParam (_@ (slfPtr));
CALL__thiscall (_@ (mobPtr), MEMINT_SwitchG1G2 (oCMobInter__SearchFreePosition_G1, oCMobInter__SearchFreePosition_G2));
call2 = CALL_End();
};
freePosPtr = CALL_RetValAsPtr ();
//};
if (!freePosPtr) { return FALSE; };
//class TMobOptPos {
// var int trafo[16]; //zMAT4
// var int distance; //int
// var int npc; //oCNpc*
// var string nodeName; //zSTRING
//};
//TMobOptPos.trafo is at offset 0, so we can read trafo directly from freePosPtr
var int pos[3];
TrfPosToVector (freePosPtr, _@ (pos));
AI_GotoPos (slf, _@ (pos));
*/
//func int oCMobInter_GetFreePosition (var int mobPtr, var int slfInstance, var int vecPtr) {
//0x0067CD00 public: int __thiscall oCMobInter::GetFreePosition(class oCNpc *,class zVEC3 &)
const int oCMobInter__GetFreePosition_G1 = 6802688;
//0x0071DF50 public: int __thiscall oCMobInter::GetFreePosition(class oCNpc *,class zVEC3 &)
const int oCMobInter__GetFreePosition_G2 = 7462736;
var int pos[3]; var int posPtr; posPtr = _@ (pos);
const int call2 = 0;
if (CALL_Begin(call2)) {
CALL_PtrParam (_@ (posPtr));
CALL_PtrParam (_@ (slfPtr));
CALL__thiscall (_@ (mobPtr), MEMINT_SwitchG1G2 (oCMobInter__GetFreePosition_G1, oCMobInter__GetFreePosition_G2));
call2 = CALL_End();
};
var int retVal; retVal = CALL_RetValAsInt ();
//};
if (!retVal) { return FALSE; };
AI_GotoVobPtr_EvalWaynetUse (slfInstance, mobPtr);
AI_GotoPos(slfInstance, _@ (pos));
return TRUE;
};
/*
* Scans for ideal positions, finds position with specified nodeName and sends there NPC
* Function returns TRUE if successfull, FALSE if not
*/
func int AI_GotoMobPtrNodeName (var int slfInstance, var int mobPtr, var string nodeName) {
//func void oCMobInter_ScanIdealPositions (var int mobPtr) {
//0x0067C9C0 protected: void __thiscall oCMobInter::ScanIdealPositions(void)
const int oCMobInter__ScanIdealPositions_G1 = 6801856;
//0x0071DC30 public: void __thiscall oCMobInter::ScanIdealPositions(void)
const int oCMobInter__ScanIdealPositions_G2 = 7461936;
if (!Hlp_Is_oCMobInter (mobPtr)) { return FALSE; };
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return FALSE; };
var int slfPtr; slfPtr = _@ (slf);
const int call = 0;
if (CALL_Begin(call)) {
CALL__thiscall (_@ (mobPtr), MEMINT_SwitchG1G2 (oCMobInter__ScanIdealPositions_G1, oCMobInter__ScanIdealPositions_G2));
call = CALL_End();
};
//};
var int pos[3];
var int nodeNameFound; nodeNameFound = FALSE;
//Search optimalPosList and find nodeName
var oCMobInter mob; mob = _^ (mobPtr);
var int ptr;
var zCList list;
ptr = mob.optimalPosList_next;
while (ptr);
list = _^ (ptr);
ptr = list.data;
if (ptr) {
var TMobOptPos mobOptPos;
mobOptPos = _^ (ptr);
//ZS_POS0_FRONT, ZS_POS0_BACK
if (STR_EndsWith (mobOptPos.nodeName, nodeName)) {
pos[0] = mobOptPos.trafo[03];
pos[1] = mobOptPos.trafo[07];
pos[2] = mobOptPos.trafo[11];
nodeNameFound = TRUE;
break;
};
};
ptr = list.next;
end;
if (!nodeNameFound) { return FALSE; };
AI_GotoVobPtr_EvalWaynetUse (slfInstance, mobPtr);
AI_GotoPos (slfInstance, _@ (pos));
return TRUE;
};
/*
*
*/
func void _AI_MobSetIdealPosition () {
//func void NPC_MobSetIdealPosition (var int slfInstance) {
//This function is called from AI_Function where ECX is pointer to NPC
if (!Hlp_Is_oCNpc (ECX)) { return; };
var oCNPC slf; slf = _^ (ECX);
if (!Hlp_IsValidNPC (slf)) { return; };
if (!slf.interactMob) { return; };
//oCMobInter_ScanIdealPositions (slf.interactMob);
var oCMobInter mob; mob = _^ (slf.interactMob);
if (mob.optimalPosList_next) {
var int ptr;
var zCList list;
ptr = mob.optimalPosList_next;
while (ptr);
list = _^ (ptr);
ptr = list.data;
if (ptr) {
//TMobOptPos.trafo is at offset 0, so we can read trafo directly from ptr
//AlignVobAt (_@ (slf), ptr); --> copying whole function here - in order to have this file 'standalone'
var int trfPtr; trfPtr = ptr;
var int vobPtr; vobPtr = _@ (slf);
//0x005EE760 public: void __thiscall zCVob::SetTrafoObjToWorld(class zMAT4 const &)
const int zCVob__SetTrafoObjToWorld_G1 = 6219616;
//0x0061BC80 public: void __thiscall zCVob::SetTrafoObjToWorld(class zMAT4 const &)
const int zCVob__SetTrafoObjToWorld_G2 = 6405248;
// Lift collision
var zCVob vob; vob = _^ (vobPtr);
var int bits; bits = vob.bitfield[0];
vob.bitfield[0] = vob.bitfield[0] & ~zCVob_bitfield0_collDetectionStatic & ~zCVob_bitfield0_collDetectionDynamic;
const int call = 0;
if (CALL_Begin(call)) {
CALL_PtrParam(_@(trfPtr));
CALL__thiscall(_@(vobPtr), MEMINT_SwitchG1G2(zCVob__SetTrafoObjToWorld_G1, zCVob__SetTrafoObjToWorld_G2));
call = CALL_End();
};
// Restore bits
vob.bitfield[0] = bits;
//<--
return;
};
ptr = list.next;
end;
};
//};
};
/*
* Function alligns NPC at ideal position of mob
*/
func void AI_MobSetIdealPosition (var int slfInstance) {
var C_NPC slf; slf = Hlp_GetNPC (slfInstance);
AI_Function (slf, _AI_MobSetIdealPosition);
};
/*
* Same as AI_UseMob - but you can specify vob pointer
*/
func void AI_UseMobPtr (var int slfInstance, var int vobPtr, var int targetState) {
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
if (!Hlp_Is_oCMobInter (vobPtr)) { return; };
//var oCMobInter mob; mob = _^ (vobPtr);
//Create new message
//var int eMsg; eMsg = oCMsgManipulate_Create (EV_USEMOB, mob.sceme, vobPtr, targetState, STR_EMPTY, STR_EMPTY);
var int eMsg; eMsg = oCMsgManipulate_Create (EV_USEMOB, oCMobInter_GetScemeName (vobPtr), vobPtr, targetState, STR_EMPTY, STR_EMPTY);
//Get Event Manager
var int eMgr; eMgr = zCVob_GetEM (_@ (slf));
//Add new msg to Event Manager
zCEventManager_OnMessage (eMgr, eMsg, _@ (slf));
};
/*
* Same as AI_UseMob - but you can specify vob pointer + additional action in name string (UNLOCK, LOCK)
*/
func void AI_UseMobPtr_Ext (var int slfInstance, var int vobPtr, var int targetState, var string name) {
var oCNpc slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
if (!Hlp_Is_oCMobInter (vobPtr)) { return; };