-
Notifications
You must be signed in to change notification settings - Fork 2
/
miscellaneous.d
1126 lines (882 loc) · 29.8 KB
/
miscellaneous.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
/*
* Miscellaneous functions
* - these functions are very useful, but I felt they should not be in same files as other more 'generic' functions.
*/
/*
* Function traverses through all oCMobInter objects and updates onStateFunc, conditionFunc and useWithItem for all objects, which do have specified visual name.
* Usage:
*
* oCMobInter_SetupAllMobsByVisual ("ORE_GROUND.ASC", "MINING", STR_EMPTY, "ITMWPICKAXE");
*/
func void oCMobInter_SetupAllMobsByVisual (var string searchVisual, var string onStateFunc, var string conditionFunc, var string useWithItem) {
var int vobListPtr; vobListPtr = MEM_ArrayCreate ();
if (!SearchVobsByClass ("oCMobInter", vobListPtr)) {
MEM_Info ("oCMobInter_SetupAllMobsByVisual: No oCMobInter objects found.");
MEM_ArrayFree (vobListPtr);
return;
};
var int vobPtr;
var zCArray vobList; vobList = _^ (vobListPtr);
var int count; count = vobList.numInArray;
var string mobVisualName;
repeat(i, count); var int i;
//Read vobPtr from vobList array
vobPtr = MEM_ArrayRead (vobListPtr, i);
//Get visual name
mobVisualName = Vob_GetVisualName (vobPtr);
if (Hlp_StrCmp (mobVisualName, searchVisual)) {
oCMobInter_SetOnStateFuncName (vobPtr, onStateFunc);
oCMobInter_SetConditionFunc (vobPtr, conditionFunc);
oCMobInter_SetUseWithItem (vobPtr, useWithItem);
};
end;
MEM_ArrayFree (vobListPtr);
};
/*
* oCMobContainer_SearchByPortalRoom
* - function returns first pointer to chest with searchVisual located in portal room searchPortalRoom
*/
func int oCMobContainer_SearchByPortalRoom (var string searchVisual, var string searchPortalRoom) {
var int vobListPtr; vobListPtr = MEM_ArrayCreate ();
if (!SearchVobsByClass ("oCMobContainer", vobListPtr)) {
MEM_Info ("oCMobContainer_SearchByPortalRoom: No oCMobContainer objects found.");
MEM_ArrayFree (vobListPtr);
return 0;
};
var int vobPtr;
var zCArray vobList; vobList = _^ (vobListPtr);
var int count; count = vobList.numInArray;
var string mobVisualName;
var string mobPortalRoom;
repeat(i, count); var int i;
//Read vobPtr from vobList array
vobPtr = MEM_ArrayRead (vobListPtr, i);
//Get visual name
mobVisualName = Vob_GetVisualName (vobPtr);
if (Hlp_StrCmp (mobVisualName, searchVisual)) {
mobPortalRoom = Vob_GetPortalName (vobPtr);
if (Hlp_StrCmp (mobPortalRoom, searchPortalRoom)) {
MEM_ArrayFree (vobListPtr);
return vobPtr;
};
};
end;
MEM_ArrayFree (vobListPtr);
return 0;
};
func void test_G2A_InsertItemsToChestsInOldCampCastle () {
var int chestPtr;
chestPtr = oCMobContainer_SearchByPortalRoom ("CHESTBIG_OCCHESTLARGELOCKED.MDS", "KI1");
if (chestPtr) {
FillMobContainer (chestPtr, "ItMi_Nugget:10");
};
chestPtr = oCMobContainer_SearchByPortalRoom ("CHESTBIG_OCCHESTLARGE.MDS", "KI3");
if (chestPtr) {
FillMobContainer (chestPtr, "ItMi_Nugget:12");
};
};
/*
*
* Vob list functions
*
*/
//zCArray *
func int Npc_CollectVobsInRange (var int slfInstance, var int range) {
var oCNpc slf; slf = Hlp_GetNpc (slfInstance);
if (!Hlp_IsValidNpc (slf)) {
return 0;
};
//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 (range));
return + arrPtr;
};
//Additional filters
var string _searchFilter_Visuals;
func void Npc_DetectVobSetSearchByVisuals(var string visualNames) {
_searchFilter_Visuals = visualNames;
};
/*
* Npc_DetectMobByScemeName
* - function returns pointer to *nearest* available mob with specified scemeName with specified state within specified verticalLimit
*/
func int Npc_DetectMobByScemeName (var int slfInstance, var int range, var string scemeNames, var int state, var int availabilityCheck, var int searchFlags, var int distLimit, var int verticalLimit) {
var int dist;
var int firstPtr; firstPtr = 0;
var int nearestPtr; nearestPtr = 0;
var int maxDist; maxDist = mkf (999999);
//Reset global visual filter
var string visualNames; visualNames = _searchFilter_Visuals; _searchFilter_Visuals = STR_EMPTY;
var int checkVisual; checkVisual = STR_Len(visualNames);
//Get Npc
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) {
return 0;
};
//Collect vobs in range
var int arrPtr; arrPtr = Npc_CollectVobsInRange (slf, range);
if (!arrPtr) {
return 0;
};
//Get Npc position
var int fromPos[3];
var int retVal; retVal = zCVob_GetPositionWorldToPos (_@ (slf), _@ (fromPos));
//Target position
var int toPos[3];
var int routePtr;
var string scemeName;
var int scemeNameCount; scemeNameCount = STR_SplitCount (scemeNames, STR_PIPE);
var string searchVisual;
var string vobVisualName;
var int visualNameCount; visualNameCount = STR_SplitCount (visualNames, STR_PIPE);
//Loop through list
var zCArray vobList; vobList = _^ (arrPtr);
repeat(i, vobList.numInArray); var int i;
var int vobPtr; vobPtr = MEM_ReadIntArray (vobList.array, i);
if (availabilityCheck) {
if (!oCMobInter_IsAvailable (vobPtr, slf)) {
continue;
};
} else {
if (!Hlp_Is_oCMobInter (vobPtr)) {
continue;
};
};
if (Hlp_Is_oCMobLockable(vobPtr)) {
var oCMobLockable mobLockable;
if (searchFlags & SEARCHVOBLIST_ONLYLOCKED) {
mobLockable = _^(vobPtr);
if ((mobLockable.bitfield & oCMobLockable_bitfield_locked) != oCMobLockable_bitfield_locked) {
continue;
};
};
if (searchFlags & SEARCHVOBLIST_ONLYUNLOCKED) {
mobLockable = _^(vobPtr);
if ((mobLockable.bitfield & oCMobLockable_bitfield_locked) == oCMobLockable_bitfield_locked) {
continue;
};
};
};
if (searchFlags & SEARCHVOBLIST_CANSEE) {
//if (!oCNpc_CanSee (slfInstance, vobPtr, 1)) {
if (!oCNpc_FreeLineOfSight (slfInstance, vobPtr)) {
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)) {
repeat(j, scemeNameCount); var int j;
scemeName = STR_Split (scemeNames, STR_PIPE, j);
if (STR_StartsWith (oCMobInter_GetScemeName (vobPtr), scemeName)) {
if (checkVisual) {
var int visualMatch; visualMatch = FALSE;
repeat(k, visualNameCount); var int k;
searchVisual = STR_Split(visualNames, STR_PIPE, k);
vobVisualName = Vob_GetVisualName(vobPtr);
if (Hlp_StrCmp(searchVisual, vobVisualName)) {
visualMatch = TRUE;
break;
};
end;
if (!visualMatch) {
break;
};
};
var oCMobInter mob; mob = _^ (vobPtr);
if ((mob.state == state) || (state == -1)) {
//Find route from Npc to vob - get total distance if Npc travels by waynet
if (searchFlags & SEARCHVOBLIST_USEWAYNET) {
retVal = 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;
};
};
};
};
end;
};
end;
//Free array
MEM_Free (arrPtr);
if (nearestPtr) {
return nearestPtr;
};
return firstPtr;
};
/*
* Npc_DetectVobByVisual
* - function returns pointer to *nearest* vob with specified visualNames within specified verticalLimit
*/
func int Npc_DetectVobByVisual (var int slfInstance, var int range, var string visualNames, var int searchFlags, var int distLimit, var int verticalLimit) {
var int dist;
var int firstPtr; firstPtr = 0;
var int nearestPtr; nearestPtr = 0;
var int maxDist; maxDist = mkf (999999);
//Get Npc
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) {
return 0;
};
//Collect vobs in range
var int arrPtr; arrPtr = Npc_CollectVobsInRange (slf, range);
if (!arrPtr) {
return 0;
};
//Get Npc position
var int fromPos[3];
var int retVal; retVal = zCVob_GetPositionWorldToPos (_@ (slf), _@ (fromPos));
//Target position
var int toPos[3];
var int routePtr;
var string searchVisual;
var string vobVisualName;
var int visualNameCount; visualNameCount = STR_SplitCount (visualNames, STR_PIPE);
//Loop through list
var zCArray vobList; vobList = _^ (arrPtr);
repeat(i, vobList.numInArray); var int i;
var int vobPtr; vobPtr = MEM_ReadIntArray (vobList.array, i);
if (searchFlags & SEARCHVOBLIST_CANSEE) {
//if (!oCNPC_CanSee (slfInstance, vobPtr, 1)) {
if (!oCNpc_FreeLineOfSight (slfInstance, vobPtr)) {
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)) {
repeat(j, visualNameCount); var int j;
searchVisual = STR_Split (visualNames, STR_PIPE, j);
vobVisualName = Vob_GetVisualName (vobPtr);
if (Hlp_StrCmp (searchVisual, vobVisualName)) {
//Find route from Npc to vob - get total distance if Npc travels by waynet
if (searchFlags & SEARCHVOBLIST_USEWAYNET) {
retVal = 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;
};
};
};
end;
};
end;
//Free array
MEM_Free (arrPtr);
if (nearestPtr) {
return nearestPtr;
};
return firstPtr;
};
/*
* Npc_DetectItem
* - function returns pointer to *nearest* item with specified mainflag and flags within specified verticalLimit
* - vob list has to be generated prior calling this function (oCNpc_ClearVobList (self); oCNpc_CreateVobList (self, rangeF);)
*/
func int Npc_DetectItem (var int slfInstance, var int range, var int mainflag, var int excludeMainFlag, var int flags, var int excludeFlags, var int searchFlags, var int distLimit, var int verticalLimit) {
var int dist;
var int firstPtr; firstPtr = 0;
var int nearestPtr; nearestPtr = 0;
var int maxDist; maxDist = mkf (999999);
var oCItem itm;
//Get Npc
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) {
return 0;
};
//Collect vobs in range
var int arrPtr; arrPtr = Npc_CollectVobsInRange (slf, range);
if (!arrPtr) {
return 0;
};
//Get Npc position
var int fromPos[3];
var int retVal; retVal = zCVob_GetPositionWorldToPos (_@ (slf), _@ (fromPos));
//Target position
var int toPos[3];
var int routePtr;
//Loop through list
var zCArray vobList; vobList = _^ (arrPtr);
repeat(i, vobList.numInArray); var int i;
var int vobPtr; vobPtr = MEM_ReadIntArray (vobList.array, i);
if (!Hlp_Is_oCItem (vobPtr)) {
continue;
};
if (searchFlags & SEARCHVOBLIST_CANSEE) {
//if (!oCNPC_CanSee (slfInstance, vobPtr, 1)) {
if (!oCNpc_FreeLineOfSight (slfInstance, vobPtr)) {
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)) {
itm = _^ (vobPtr);
if (Hlp_IsValidItem (itm)) {
if (((!mainflag) || (itm.mainflag == mainflag))
&& ((!excludeMainFlag) || (itm.mainflag != excludeMainFlag)))
{
if (((!flags) || (itm.flags & flags))
&& ((!excludeFlags) || (!(itm.flags & excludeFlags))))
{
//Find route from Npc to vob - get total distance if Npc travels by waynet
if (searchFlags & SEARCHVOBLIST_USEWAYNET) {
retVal = 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;
};
};
};
};
};
};
end;
//Free array
MEM_Free (arrPtr);
if (nearestPtr) {
return nearestPtr;
};
return firstPtr;
};
func int Npc_DetectNpc (var int slfInstance, var int range, var string stateName, var int searchFlags, var int distLimit, var int verticalLimit) {
var int dist;
var int firstPtr; firstPtr = 0;
var int nearestPtr; nearestPtr = 0;
var int maxDist; maxDist = mkf (999999);
var oCNPC npc;
//Get Npc
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) {
return 0;
};
var int slfPtr; slfPtr = _@ (slf);
//Collect vobs in range
var int arrPtr; arrPtr = Npc_CollectVobsInRange (slf, range);
if (!arrPtr) {
return 0;
};
//Get Npc position
var int fromPos[3];
var int retVal; retVal = zCVob_GetPositionWorldToPos (_@ (slf), _@ (fromPos));
//Target position
var int toPos[3];
var int routePtr;
//Loop through list
var zCArray vobList; vobList = _^ (arrPtr);
repeat(i, vobList.numInArray); var int i;
var int vobPtr; vobPtr = MEM_ReadIntArray (vobList.array, i);
//Ignore self
if (vobPtr == slfPtr) {
continue;
};
if (!Hlp_Is_oCNpc (vobPtr)) {
continue;
};
if (searchFlags & SEARCHVOBLIST_CANSEE) {
//if (!oCNPC_CanSee (slfInstance, vobPtr, 1)) {
if (!oCNpc_FreeLineOfSight (slfInstance, vobPtr)) {
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)) {
npc = _^ (vobPtr);
if (Npc_IsInStateName (npc, stateName)) {
//Find route from Npc to vob - get total distance if Npc travels by waynet
if (searchFlags & SEARCHVOBLIST_USEWAYNET) {
retVal = 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;
};
};
};
};
end;
//Free array
MEM_Free (arrPtr);
if (nearestPtr) {
return nearestPtr;
};
return firstPtr;
};
func int Npc_DetectVobByName (var int slfInstance, var int range, var string objectName, var int searchFlags, var int distLimit, var int verticalLimit) {
var int dist;
var int firstPtr; firstPtr = 0;
var int nearestPtr; nearestPtr = 0;
var int maxDist; maxDist = mkf (999999);
objectName = STR_Upper (objectName);
//Get Npc
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) {
return 0;
};
//Collect vobs in range
var int arrPtr; arrPtr = Npc_CollectVobsInRange (slf, range);
if (!arrPtr) {
return 0;
};
//Get Npc position
var int fromPos[3];
var int retVal; retVal = zCVob_GetPositionWorldToPos (_@ (slf), _@ (fromPos));
//Target position
var int toPos[3];
var int routePtr;
//Loop through list
var zCArray vobList; vobList = _^ (arrPtr);
repeat(i, vobList.numInArray); var int i;
var int vobPtr; vobPtr = MEM_ReadIntArray (vobList.array, i);
if (!vobPtr) {
continue;
};
if (searchFlags & SEARCHVOBLIST_CANSEE) {
//if (!oCNPC_CanSee (slfInstance, vobPtr, 1)) {
if (!oCNpc_FreeLineOfSight (slfInstance, vobPtr)) {
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 zCVob vob; vob = _^ (vobPtr);
if (Hlp_StrCmp (STR_Upper (vob._zCObject_objectName), objectName)) {
//Find route from Npc to vob - get total distance if Npc travels by waynet
if (searchFlags & SEARCHVOBLIST_USEWAYNET) {
retVal = 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;
};
};
};
};
end;
//Free array
MEM_Free (arrPtr);
if (nearestPtr) {
return nearestPtr;
};
return firstPtr;
};
func void NPC_VobListRemoveDeadNpcs (var int slfInstance) {
var oCNPC slf; slf = Hlp_GetNPC (slfInstance);
if (!Hlp_IsValidNPC (slf)) { return; };
var int vobPtr;
var int i; i = slf.vobList_numInArray;
while (i > 0);
vobPtr = MEM_ReadIntArray (slf.vobList_array, i);
if (Hlp_Is_oCNpc (vobPtr)) {
var oCNPC npc; npc = _^ (vobPtr);
if (Npc_IsDead (npc)) {
oCNpc_RemoveFromVobList (slfInstance, vobPtr);
};
};
i -= 1;
end;
};
/*
* zCVob_GetNearest_AtPos
* - function returns first pointer to object closest to fromPosPtr
*/
func int zCVob_GetNearest_AtPos (var string className, var int fromPosPtr) {
var int vobListPtr; vobListPtr = MEM_ArrayCreate ();
if (!SearchVobsByClass (className, vobListPtr)) {
var string msg;
msg = ConcatStrings ("zCVob_GetNearest_AtPos: No ", className);
msg = ConcatStrings (msg, " objects found.");
MEM_Info (msg);
MEM_ArrayFree (vobListPtr);
return 0;
};
var int dist;
var int maxDist; maxDist = mkf (999999);
var int firstPtr; firstPtr = 0;
var int nearestPtr; nearestPtr = 0;
var int vobPtr;
var zCArray vobList; vobList = _^ (vobListPtr);
var int count; count = vobList.numInArray;
var int dir[3];
var int posPtr;
repeat(i, count); var int i;
//Read vobPtr from vobList array
vobPtr = MEM_ArrayRead (vobListPtr, i);
if (vobPtr) {
if (!firstPtr) { firstPtr = vobPtr; };
posPtr = zCVob_GetPositionWorld (vobPtr);
SubVectors (_@ (dir), fromPosPtr, posPtr);
MEM_Free (posPtr);
dist = zVEC3_LengthApprox (_@ (dir));
if (lf (dist, maxDist)) {
nearestPtr = vobPtr;
maxDist = dist;
};
};
end;
MEM_ArrayFree (vobListPtr);
if (nearestPtr) { return nearestPtr; };
return firstPtr;
};
//--
func int GetSymbolIntValue (var int symbolIndex) {
var int symbPtr; symbPtr = MEM_GetSymbolByIndex (symbolIndex);
if (symbPtr) {
var zCPar_symbol symb; symb = _^ (symbPtr);
if ((symb.bitfield & zCPar_Symbol_bitfield_type) == zPAR_TYPE_INT)
|| ((symb.bitfield & zCPar_Symbol_bitfield_type) == zPAR_TYPE_FLOAT) {
return symb.content;
};
};
return 0;
};
func void SetSymbolIntValue (var int symbolIndex, var int value) {
var int symbPtr; symbPtr = MEM_GetSymbolByIndex (symbolIndex);
if (symbPtr) {
var zCPar_symbol symb; symb = _^ (symbPtr);
if ((symb.bitfield & zCPar_Symbol_bitfield_type) == zPAR_TYPE_INT)
|| ((symb.bitfield & zCPar_Symbol_bitfield_type) == zPAR_TYPE_FLOAT) {
symb.content = value;
};
};
};
func string GetSymbolStringValue (var int symbolIndex) {
var int symbPtr; symbPtr = MEM_GetSymbolByIndex (symbolIndex);
if (symbPtr) {
var zCPar_symbol symb; symb = _^ (symbPtr);
if ((symb.bitfield & zCPar_Symbol_bitfield_type) == zPAR_TYPE_STRING) {
var string s; s = MEM_ReadString(symb.content);
return s;
};
};
return STR_EMPTY;
};
func void SetSymbolStringValue (var int symbolIndex, var string s) {
var int symbPtr; symbPtr = MEM_GetSymbolByIndex (symbolIndex);
if (symbPtr) {
var zCPar_symbol symb; symb = _^ (symbPtr);
if ((symb.bitfield & zCPar_Symbol_bitfield_type) == zPAR_TYPE_STRING) {
MEM_WriteString(symb.content, s);
};
};
};
func string API_GetSymbolStringValue (var string symbolName, var string defaultValue) {
var int symbID; symbID = MEM_GetSymbolIndex (symbolName);
if (symbID == -1) {
MEM_Info (ConcatStrings ("API_GetSymbolStringValue symbol not found: ", symbolName));
return defaultValue;
};
var string s; s = GetSymbolStringValue (symbID);
return s;
};
func int API_GetSymbolIntValue (var string symbolName, var int defaultValue) {
var int symbID; symbID = MEM_GetSymbolIndex (symbolName);
if (symbID == -1) {
MEM_Info (ConcatStrings ("API_GetSymbolIntValue symbol not found: ", symbolName));
return defaultValue;
};
return + GetSymbolIntValue (symbID);
};
/*
* - wrapper function that converts value from hex to RGBA
*/
func int API_GetSymbolHEX2RGBAValue (var string symbolName, var string defaultValue) {
var int symbID; symbID = MEM_GetSymbolIndex (symbolName);
if (symbID == -1) {
MEM_Info (ConcatStrings ("API_GetSymbolHEX2RGBAValue symbol not found: ", symbolName));
return + HEX2RGBA (defaultValue);
};
var string s; s = GetSymbolStringValue (symbID);
return + HEX2RGBA (s);
};
/*
* Basically copy of MEM_CallByString - without any error messaging
*/
func void API_CallByString (var string fnc) {
var int symbID;
//This does not work - seems like we cannot use global constant when initializing local one?
//const string cacheFunc = STR_EMPTY;
const string cacheFunc = "";
const int cacheSymbID = 0;
if (Hlp_StrCmp (cacheFunc, fnc)) {
symbID = cacheSymbID;
} else {
symbID = MEM_FindParserSymbol (fnc);
if (symbID == -1) {
return;
};
cacheFunc = fnc; cacheSymbID = symbID;
};
MEM_CallByID (symbID);
};
//--
func string AlphaBlendFuncTypeToString (var int rndAlphaBlendFunc) {
const int zRND_ALPHA_FUNC_MAT_DEFAULT = 0;
const int zRND_ALPHA_FUNC_NONE = 1;
const int zRND_ALPHA_FUNC_BLEND = 2;
const int zRND_ALPHA_FUNC_ADD = 3;
const int zRND_ALPHA_FUNC_SUB = 4;
const int zRND_ALPHA_FUNC_MUL = 5;
const int zRND_ALPHA_FUNC_MUL2 = 6;
const int zRND_ALPHA_FUNC_TEST = 7;
const int zRND_ALPHA_FUNC_BLEND_TEST = 8;
if (rndAlphaBlendFunc == zRND_ALPHA_FUNC_MAT_DEFAULT) { return "zRND_ALPHA_FUNC_MAT_DEFAULT"; };
if (rndAlphaBlendFunc == zRND_ALPHA_FUNC_NONE) { return "zRND_ALPHA_FUNC_NONE"; };
if (rndAlphaBlendFunc == zRND_ALPHA_FUNC_BLEND) { return "zRND_ALPHA_FUNC_BLEND"; };
if (rndAlphaBlendFunc == zRND_ALPHA_FUNC_ADD) { return "zRND_ALPHA_FUNC_ADD"; };
if (rndAlphaBlendFunc == zRND_ALPHA_FUNC_SUB) { return "zRND_ALPHA_FUNC_SUB"; };
if (rndAlphaBlendFunc == zRND_ALPHA_FUNC_MUL) { return "zRND_ALPHA_FUNC_MUL"; };
if (rndAlphaBlendFunc == zRND_ALPHA_FUNC_MUL2) { return "zRND_ALPHA_FUNC_MUL2"; };
if (rndAlphaBlendFunc == zRND_ALPHA_FUNC_TEST) { return "zRND_ALPHA_FUNC_TEST"; };
if (rndAlphaBlendFunc == zRND_ALPHA_FUNC_BLEND_TEST) { return "zRND_ALPHA_FUNC_BLEND_TEST"; };
return "NONE";
};
func int zCRenderer_GetAlphaBlendFunc (var int ptr) {
//0x00713A90 public: virtual enum zTRnd_AlphaBlendFunc __thiscall zCRenderer::GetAlphaBlendFunc(void)const
const int zCRenderer__GetAlphaBlendFunc_G1 = 7420560;
//0x0064A1E0 public: virtual enum zTRnd_AlphaBlendFunc __thiscall zCRenderer::GetAlphaBlendFunc(void)const
const int zCRenderer__GetAlphaBlendFunc_G2 = 6595040;
if (!ptr) { return 0; };
var int retVal;
const int call = 0;
if (CALL_Begin(call)) {
CALL_PutRetValTo (_@ (retVal));
CALL__thiscall(_@(ptr), MEMINT_SwitchG1G2 (zCRenderer__GetAlphaBlendFunc_G1, zCRenderer__GetAlphaBlendFunc_G2));
call = CALL_End();
};
return + retVal;
};
/*
* Pos_ToScreenXYF (float)
* - converts 3D coordinates in the world to screen coordinates
*/
func void Pos_ToScreenXYF (var int posPtr, var int ptrXF, var int ptrYF) {
var int pos[3]; MEM_CopyBytes(posPtr, _@(pos), 12);
if (!pos[2]) { return; }; //Division by 0 safetycheck!
var int activeCam; activeCam = zCCamera_Get_activeCam ();
//zCCamera_Activate (activeCam);
zMAT4_Mul_zVEC3 (_@ (MEM_Camera.camMatrix), posPtr, posPtr);
zCCamera_ProjectF (activeCam, posPtr, ptrXF, ptrYF);
};
func void Pos_ToScreenXY (var int posPtr, var int ptrX, var int ptrY) {
var int pos[3]; MEM_CopyBytes(posPtr, _@(pos), 12);
if (!pos[2]) { return; }; //Division by 0 safetycheck!
var int activeCam; activeCam = zCCamera_Get_activeCam ();
//zCCamera_Activate (activeCam);
zMAT4_Mul_zVEC3 (_@ (MEM_Camera.camMatrix), posPtr, posPtr);
zCCamera_Project (activeCam, posPtr, ptrX, ptrY);
};
//--
/*
* Npc_SetAIStateToPos
* - function sets aiStatePosition to specified position
*/
func void Npc_SetAIStateToPos (var int slfInstance, var int posPtr) {
var oCNpc slf; slf = Hlp_GetNpc (slfInstance);
var int statePtr; statePtr = NPC_GetNPCState (slf);
if (!statePtr) { return; };
var oCNPC_States state; state = _^ (statePtr);
if (state.hasRoutine) { return; };
//Update aiStateDriven - to kick in ai state
state.aiStateDriven = 1;
//Update ai position - to desired position
MEM_CopyBytes (posPtr, _@ (slf.state_aiStatePosition[0]), 12);
//Update also spawn node position