1 #include "3dc.h"
2
3 #include "inline.h"
4 #include "module.h"
5 #include "stratdef.h"
6 #include "bh_types.h"
7 #include "pvisible.h"
8 #include "pfarlocs.h"
9 #include "avpview.h"
10 #include "ourasert.h"
11 #include "pldghost.h"
12
13 #if SupportModules
14
15 /* imported externs */
16
17 extern SCENE Global_Scene;
18 extern int NumActiveBlocks;
19 extern DISPLAYBLOCK *ActiveBlockList[];
20 extern DISPLAYBLOCK *dptr_last;
21 extern unsigned char KeyASCII;
22
23 /**** Protos ****/
24
25 void FindVisibleModules(VMODULE *vptr,int flag);
26
27 /**** Statics ****/
28
29 static MODULE **Global_ModuleArrayPtr;
30
AllNewModuleHandler(void)31 void AllNewModuleHandler(void)
32 {
33 {
34 int i;
35 SCENEMODULE *smptr;
36 smptr = Global_ModulePtr[Global_Scene];
37 Global_ModuleArrayPtr = smptr->sm_marray;
38
39 for(i = 0; i < ModuleArraySize; i++)
40 {
41 ModuleCurrVisArray[i] = 0;
42 }
43 }
44
45 /* handle dynamic module objects */
46 {
47 int numberOfObjects = NumActiveBlocks;
48
49 while (numberOfObjects--)
50 {
51 DISPLAYBLOCK* objectPtr = ActiveBlockList[numberOfObjects];
52
53 if(objectPtr->ObFlags3 & ObFlag3_DynamicModuleObject)
54 {
55 STRATEGYBLOCK *sbPtr = objectPtr->ObStrategyBlock;
56
57 sbPtr->containingModule = (ModuleFromPosition(&(objectPtr->ObWorld), sbPtr->containingModule));
58 if (sbPtr->containingModule)
59 if (ModuleIsPhysical(sbPtr->containingModule))
60 {
61 ModuleCurrVisArray[sbPtr->containingModule->m_index] = 1;
62 if(sbPtr->containingModule->m_vmptr) FindVisibleModules(sbPtr->containingModule->m_vmptr,1);
63 }
64 }
65 }
66 }
67
68 /*If this is an network game , and this machine is the ai server , then need to check if
69 there are any aliens near to other players*/
70 if(AvP.Network!=I_No_Network && AvP.NetworkAIServer)
71 {
72 /* go through the strategy blocks looking for players*/
73 int sbIndex;
74 for(sbIndex=0;sbIndex<NumActiveStBlocks;sbIndex++)
75 {
76 STRATEGYBLOCK *playerSbPtr = ActiveStBlockList[sbIndex];
77 NETGHOSTDATABLOCK *ghostData;
78 if(playerSbPtr->I_SBtype!=I_BehaviourNetGhost) continue;
79 ghostData = (NETGHOSTDATABLOCK *)playerSbPtr->SBdataptr;
80
81 if(ghostData->type==I_BehaviourAlienPlayer ||
82 ghostData->type==I_BehaviourMarinePlayer ||
83 ghostData->type==I_BehaviourPredatorPlayer)
84 {
85 int sbIndex2;
86 //found one of the players
87 if(!playerSbPtr->containingModule) continue;
88
89 /*now search through the strategy blocks , to see if any aliens are
90 visible from the player's location*/
91 for(sbIndex2=0;sbIndex2<NumActiveStBlocks;sbIndex2++)
92 {
93 STRATEGYBLOCK *alienSbPtr = ActiveStBlockList[sbIndex2];
94 /*Is it an alien?*/
95 if(alienSbPtr->I_SBtype!=I_BehaviourAlien) continue;
96 if(!alienSbPtr->containingModule) continue;
97
98 if(IsModuleVisibleFromModule(playerSbPtr->containingModule,alienSbPtr->containingModule))
99 {
100 /*The player can see the alien , so link in all modules that the
101 player can see*/
102 if (ModuleIsPhysical(playerSbPtr->containingModule))
103 {
104 ModuleCurrVisArray[playerSbPtr->containingModule->m_index] = 1;
105 if(playerSbPtr->containingModule->m_vmptr) FindVisibleModules(playerSbPtr->containingModule->m_vmptr,1);
106 }
107
108 /*Since all modules visible by this player have now been linked , don't need
109 to check for any more aliens for this player*/
110 break;
111
112 }
113
114 }
115
116 }
117 }
118 }
119
120 /* handle player visibilities */
121 {
122 extern MODULE * playerPherModule;
123 playerPherModule = (ModuleFromPosition(&(Global_VDB_Ptr->VDB_World), playerPherModule));
124
125 if(!playerPherModule)
126 {
127 playerPherModule = (ModuleFromPosition(&(Player->ObWorld), playerPherModule));
128 }
129
130 if (playerPherModule)
131 {
132 ModuleCurrVisArray[playerPherModule->m_index] = 2;
133 if(playerPherModule->m_vmptr) FindVisibleModules(playerPherModule->m_vmptr,2);
134 }
135 }
136
137
138
139 /* handle AIMODULE visibility stuff */
140 {
141 int i;
142 for(i = 0; i < ModuleArraySize; i++)
143 {
144 if (ModuleCurrVisArray[i] == 2)
145 {
146 AIMODULE *aiModulePtr = Global_ModuleArrayPtr[i]->m_aimodule;
147 if (aiModulePtr)
148 {
149 MODULE **modulelistPtr = aiModulePtr->m_module_ptrs;
150 while(*modulelistPtr)
151 {
152 int index = (*modulelistPtr)->m_index;
153 if (!ModuleCurrVisArray[index]) ModuleCurrVisArray[index]=1;
154 modulelistPtr++;
155 }
156 }
157 }
158 }
159 }
160 /* update active block list */
161 {
162 int i;
163
164 for(i = 0; i < ModuleArraySize; i++)
165 {
166 MODULE *mptr = Global_ModuleArrayPtr[i];
167
168 if(ModuleCurrVisArray[i])
169 {
170 if(mptr->m_dptr == 0 && ((mptr->m_flags & m_flag_dormant) == 0))
171 {
172 AllocateModuleObject(mptr);
173 }
174
175 }
176 else
177 {
178 if(mptr->m_dptr) DeallocateModuleObject(mptr);
179 }
180
181 }
182
183 }
184
185 /* call Patrick's code */
186 DoObjectVisibilities();
187 }
188
189
FindVisibleModules(VMODULE * vptr,int flag)190 void FindVisibleModules(VMODULE *vptr,int flag)
191 {
192 while(vptr->vmod_type != vmtype_term)
193 {
194 MODULE *mptr = NULL;
195
196 /* Add this module to the visible array */
197 if(vptr->vmod_mref.mref_ptr != NULL)
198 {
199 mptr = vptr->vmod_mref.mref_ptr;
200 ModuleCurrVisArray[mptr->m_index] = flag;
201 }
202
203 /* VMODULE instructions */
204 switch(vptr->vmod_instr)
205 {
206 case vmodi_null:
207 vptr++;
208 break;
209
210 case vmodi_bra_vc:
211 /* If the door/viewport is closed... */
212 /* Branch to this vptr */
213 /* else vptr++; */
214 if(mptr != NULL)
215 {
216 if(mptr->m_flags & m_flag_open) vptr++;
217 else vptr = vptr->vmod_data.vmodidata_ptr;
218 }
219 break;
220 }
221 }
222 }
223
224
ThisObjectIsInAModuleVisibleFromCurrentlyVisibleModules(STRATEGYBLOCK * sbPtr)225 int ThisObjectIsInAModuleVisibleFromCurrentlyVisibleModules(STRATEGYBLOCK *sbPtr)
226 {
227 VMODULE *vPtr;
228
229 GLOBALASSERT(sbPtr);
230 GLOBALASSERT(sbPtr->containingModule);
231
232 vPtr = sbPtr->containingModule->m_vmptr;
233 GLOBALASSERT(vPtr);
234
235 if(ModuleCurrVisArray[sbPtr->containingModule->m_index] == 2)
236 {
237 return 1;
238 }
239
240 while(vPtr->vmod_type != vmtype_term)
241 {
242 MODULE *mptr = NULL;
243
244 /* consider this module */
245 if(vPtr->vmod_mref.mref_ptr != NULL)
246 {
247 mptr = vPtr->vmod_mref.mref_ptr;
248 if(ModuleCurrVisArray[mptr->m_index] == 2)
249 {
250 if(vPtr->vmod_instr==vmodi_bra_vc)
251 {
252 if(mptr->m_flags & m_flag_open) return 1;
253 }
254 else
255 {
256 return 1;
257 }
258 }
259 }
260
261 /* VMODULE instructions */
262 switch(vPtr->vmod_instr)
263 {
264 case vmodi_null:
265 vPtr++;
266 break;
267
268 case vmodi_bra_vc:
269 /* If the door/viewport is closed... */
270 /* Branch to this vPtr */
271 /* else vPtr++; */
272 if(mptr != NULL)
273 {
274 if(mptr->m_flags & m_flag_open) vPtr++;
275 else vPtr = vPtr->vmod_data.vmodidata_ptr;
276 }
277 break;
278 }
279 }
280
281 return 0;
282 }
283
284
285
286
287
ModuleFunctions(MODULE * mptr,MFUNCTION mf)288 void ModuleFunctions(MODULE *mptr, MFUNCTION mf)
289 {
290 switch(mf)
291 {
292 case mfun_null:
293 break;
294 }
295 }
296
297
AllocateModuleObject(MODULE * mptr)298 void AllocateModuleObject(MODULE *mptr)
299 {
300
301 DISPLAYBLOCK *dptr;
302 MODULEMAPBLOCK *mapblockptr;
303 STRATEGYBLOCK *sb = 0;
304
305 #if SupportMorphing
306 MORPHCTRL *mc;
307 #endif
308
309 dptr_last = 0;
310
311 mptr->m_dptr = 0;
312
313 if(mptr == 0) return; /* Whoops! */
314
315 if(mptr->m_mapptr == 0) return; /* Not all modules have maps */
316
317
318 dptr = CreateActiveObject();
319
320
321 if(dptr) {
322
323
324 /* Tell the module we exist */
325
326 mptr->m_dptr = dptr;
327
328 /* Tell the object who its module is */
329
330 dptr->ObMyModule = mptr;
331
332 /* Get the strategy block, if it exists */
333
334 if(mptr->m_sbptr) sb = mptr->m_sbptr;
335
336 /* If there is a STRATEGYBLOCK, tell it we exist */
337
338 if(sb) {
339
340 dptr->ObStrategyBlock = sb;
341 sb->SBdptr = dptr;
342
343 }
344
345
346 /* Read the map */
347
348 mapblockptr = mptr->m_mapptr;
349
350 dptr->ObShape = mapblockptr->MapShape;
351
352
353
354 CopyLocation(&mapblockptr->MapWorld, &dptr->ObWorld);
355 CopyEuler(&mapblockptr->MapEuler, &dptr->ObEuler);
356
357 dptr->ObFlags = mapblockptr->MapFlags;
358 dptr->ObFlags2 = mapblockptr->MapFlags2;
359 dptr->ObFlags3 = mapblockptr->MapFlags3;
360
361
362
363
364 #if SupportMorphing
365
366 /* If there is a strategy block, see if it has a MORPHCTRL structure */
367
368 if(sb) {
369
370 if(sb->SBmorphctrl) {
371
372 /* Pass MORPHCTRL to dptr */
373
374 dptr->ObMorphCtrl = sb->SBmorphctrl;
375
376 /* Copy the morph pointer from the map to the dptr */
377
378 mc = dptr->ObMorphCtrl;
379
380 mc->ObMorphHeader = mapblockptr->MapMorphHeader;
381
382 /* OLD TEST - These values are now set elsewhere */
383 #if 0
384 if(mc->ObMorphHeader) {
385 mc->ObMorphCurrFrame = 0;
386 mc->ObMorphFlags = mph_flag_play/* | mph_flag_noloop | mph_flag_reverse*/;
387 mc->ObMorphSpeed = ONE_FIXED;
388 }
389 #endif
390
391 }
392
393 }
394
395 #endif /* Support Morphing */
396
397
398 dptr->ObLightType = LightType_PerVertex;
399 dptr->ObFlags |= ObFlag_MultLSrc;
400
401
402 if(mapblockptr->MapVDBData)
403 MapSetVDB(dptr, mapblockptr->MapVDBData);
404
405 dptr->ObLightType = mapblockptr->MapLightType;
406
407
408 MapBlockInit(dptr);
409
410 /* KJL 14:15:34 04/19/97 - their used to be lots of maths here
411 to calculate orientation, but in AvP all modules are aligned to
412 the world space axes... */
413 {
414 extern MATRIXCH IdentityMatrix;
415 dptr->ObMat = IdentityMatrix;
416 }
417
418
419 /*
420
421 Module lights
422
423 There is an option for a pointer to an array of lights in a module
424 structure. These lights are transferred to the display block and
425 flagged as "LFlag_WasNotAllocated" so that "DeallocateLightBlock()"
426 knows to ignore them.
427
428 The number of lights in the array is "m_numlights" and the pointer
429 is called "m_lightarray".
430
431 The addition of non-allocated does not need to be a module specific
432 option.
433
434 Non-allocated lights can co-exist peacefully with the other lights.
435
436 */
437
438 if(mptr->m_numlights && mptr->m_lightarray) {
439
440 LIGHTBLOCK *lptr_array = mptr->m_lightarray;
441 int i;
442
443 for(i = mptr->m_numlights; i!=0; i--) {
444
445 /* Make sure the light is flagged correctly */
446
447 lptr_array->LightFlags |= LFlag_WasNotAllocated;
448
449 /* Add the light */
450
451 AddLightBlock(dptr, lptr_array);
452
453 /* Next light from the array */
454
455 lptr_array++;
456
457 }
458
459 }
460
461
462
463
464 /*
465
466 As with shared points, extra item data for prelighting is also
467 copied from the module to the display block.
468
469 WARNING:
470
471 Allocation and deallocation of this pointer is the responsibility
472 of the user!
473
474 */
475
476 dptr->ObEIDPtr = mptr->m_extraitemdata;
477
478 /* Added Name to DISPLAYBLOCK */
479
480 dptr->name = mptr->name;
481
482 MapPostProcessing(dptr);
483
484
485 ModuleObjectJustAllocated(mptr); /* Project Function */
486
487 /* Bug Fix */
488
489 if (dptr->ObStrategyBlock) {
490
491 STRATEGYBLOCK *sbptr=dptr->ObStrategyBlock;
492
493 if (sbptr->I_SBtype==I_BehaviourSimpleAnimation) {
494
495 SIMPLE_ANIM_BEHAV_BLOCK *sanimbhv;
496
497 sanimbhv = (SIMPLE_ANIM_BEHAV_BLOCK*)(sbptr->SBdataptr);
498
499 GLOBALASSERT(sanimbhv->bhvr_type == I_BehaviourSimpleAnimation);
500 GLOBALASSERT (dptr == sbptr->SBdptr);
501
502 if(!dptr->ObTxAnimCtrlBlks) {
503 dptr->ObTxAnimCtrlBlks = sanimbhv->tacbSimple;
504 }
505
506 }
507
508 }
509
510 }
511
512 dptr_last = dptr;
513
514 }
515
516
DeallocateModuleObject(MODULE * mptr)517 void DeallocateModuleObject(MODULE *mptr)
518
519 {
520
521 DISPLAYBLOCK *dptr;
522 STRATEGYBLOCK *sb;
523
524
525 if(mptr->m_dptr) {
526
527 ModuleObjectAboutToBeDeallocated(mptr); /* Project Function */
528
529 dptr = mptr->m_dptr;
530
531 DestroyActiveObject(dptr);
532
533 /* Clear module reference to dptr */
534
535 mptr->m_dptr = 0;
536
537 /* If there is a STRATEGYBLOCK, clear that reference too */
538
539 if(mptr->m_sbptr) {
540
541 sb = mptr->m_sbptr;
542 sb->SBdptr = 0;
543
544 }
545
546 }
547
548 }
549
550
551 /*
552
553 The Module Preprocessor
554
555 Pass the array of pointers to modules.
556 This function creates module indices and converts names into pointers.
557
558 */
559
560 /*
561 temp patch to match current chunk
562 loader configuration
563 */
564
PreprocessAllModules(void)565 void PreprocessAllModules(void)
566 {
567
568 SCENEMODULE **sm_array_ptr;
569 SCENEMODULE *sm_ptr;
570
571
572 if(Global_ModulePtr == 0) return;
573
574 sm_array_ptr = Global_ModulePtr;
575
576 while(*sm_array_ptr)
577 {
578 sm_ptr = *sm_array_ptr;
579
580 PreprocessModuleArray(sm_ptr->sm_marray);
581
582 sm_array_ptr++;
583 }
584 }
585
586
587
588 /*
589
590 A special function to deallocate the module visibility arrays
591
592 */
593
DeallocateModuleVisArrays(void)594 void DeallocateModuleVisArrays(void)
595
596 {
597
598 if(ModuleCurrVisArray) {
599
600 DeallocateMem(ModuleCurrVisArray);
601 ModuleCurrVisArray = 0;
602
603 }
604
605 }
606
607
608 /*
609
610 Allocate the two arrays used to keep track of module visibility from
611 frame to frame. The function uses the global scene variable to access the
612 appropriate SCENEMODULE and find out how many modules are present. It also
613 deallocates the previous arrays if they exist.
614
615 */
616
GetModuleVisArrays(void)617 int GetModuleVisArrays(void)
618
619 {
620
621 SCENEMODULE *sm_ptr;
622 MODULE **m_array_ptr;
623 MODULE *m_ptr;
624 int index, i;
625
626
627 if(Global_ModulePtr == 0) return No;
628
629 DeallocateModuleVisArrays();
630
631 sm_ptr = Global_ModulePtr[Global_Scene];
632
633 m_array_ptr = sm_ptr->sm_marray;
634 index = smallint;
635
636 while(*m_array_ptr) {
637
638 m_ptr = *m_array_ptr++;
639 if(m_ptr->m_index > index) index = m_ptr->m_index;
640
641 }
642
643 ModuleArraySize = index + 1;
644
645
646 ModuleCurrVisArray = (char*) AllocateMem(ModuleArraySize);
647
648 if(ModuleCurrVisArray)
649 {
650
651 for(i = 0; i < ModuleArraySize; i++)
652 {
653
654 ModuleCurrVisArray[i] = 0;
655 }
656
657 #if 0
658 textprint("visibility arrays ok, size %d\n", ModuleArraySize);
659 #endif
660
661 return Yes;
662
663 }
664
665 else return No;
666
667 }
668
669
670
671
672 #define ppma_print No
673
674
675 #if 1
676
677
PreprocessModuleArray(MODULE ** m_array_ptr)678 void PreprocessModuleArray(MODULE **m_array_ptr)
679 {
680 MODULE **m_array = m_array_ptr;
681 MODULE *m_ptr;
682 int index;
683
684
685 #if ppma_print
686 textprint("PreprocessModuleArray %u\n", m_array_ptr);
687 #endif
688
689
690 index = 0;
691
692 while(*m_array) {
693
694 /* Get the module pointer */
695
696 m_ptr = *m_array;
697
698
699 /* Assign the module an index */
700
701 m_ptr->m_index = index++;
702
703
704 #if ppma_print
705 textprint("\nModule %u, ", m_ptr);
706 PrintName(&m_ptr->m_name);
707 textprint(", index %d\n", m_ptr->m_index);
708 textprint(" (vptr = ");
709 PrintName(&m_ptr->m_vptr.mref_name);
710 textprint(")\n");
711 #endif
712
713
714 /* Convert module references from names to pointers */
715
716 if(!(m_ptr->m_flags & m_flag_gotptrs)) {
717
718 #if 0
719 /* Vertical Pointer */
720
721 ConvertModuleNameToPointer(&m_ptr->m_vptr, m_array_ptr);
722
723
724 /* Extent Pointer */
725
726 ConvertModuleNameToPointer(&m_ptr->m_ext, m_array_ptr);
727
728
729 /* Function Pointer */
730
731 ConvertModuleNameToPointer(&m_ptr->m_funref, m_array_ptr);
732
733
734 // Hack by John to make the m_link pointers work
735
736 if (m_ptr->m_link_ptrs)
737 {
738 MREF * m_link_ptr = m_ptr->m_link_ptrs;
739
740 while (m_link_ptr->mref_ptr)
741 {
742 ConvertModuleNameToPointer(m_link_ptr++, m_array_ptr);
743 }
744
745 }
746 #endif
747 /* VMODULE Array */
748
749 if(m_ptr->m_vmptr) {
750
751 /* Convert VMODIDATA names to pointers */
752
753 PreprocessVMODIDATA(m_ptr->m_vmptr);
754
755 /* Convert MREF names to pointers */
756 /*
757 v_ptr = m_ptr->m_vmptr;
758
759 while(v_ptr->vmod_type != vmtype_term) {
760
761 ConvertModuleNameToPointer(&v_ptr->vmod_mref, m_array_ptr);
762
763 v_ptr++;
764
765 }
766 */
767 }
768
769
770 /* Tell the module that its names are now pointers */
771
772 m_ptr->m_flags |= m_flag_gotptrs;
773
774 }
775
776
777 /* Calculate module extents */
778
779 //I'll set the extents and world position in the loaders -Richard.
780 //GetModuleMapData(m_ptr);
781
782
783 /* Next module array entry */
784
785 m_array++;
786
787 }
788
789 /*WaitForReturn();*/
790
791 }
792
793
794 #else
795
796
797
798
799 #endif
800
801
802 /*
803
804 VMODIDATA is the data associated with VMODI, the VMODULE instruction. Some
805 of the data items are names which need to be converted to pointers.
806
807 */
808
PreprocessVMODIDATA(VMODULE * v_ptr)809 void PreprocessVMODIDATA(VMODULE *v_ptr)
810
811 {
812
813 VMODULE *v_array_ptr = v_ptr;
814
815
816 while(v_ptr->vmod_type != vmtype_term) {
817
818 if(!(v_ptr->vmod_flags & vm_flag_gotptrs)) {
819
820 switch(v_ptr->vmod_instr) {
821
822 case vmodi_null:
823 break;
824
825 case vmodi_bra_vc:
826 ConvertVModuleNameToPointer(&v_ptr->vmod_data, v_array_ptr);
827 break;
828
829 }
830
831 v_ptr->vmod_flags |= vm_flag_gotptrs;
832
833 }
834
835 v_ptr++;
836
837 }
838
839 }
840
841
842 /*
843
844 Convert MREF name to MREF pointer
845
846 */
847
848
849 #define cmntp_print No
850
851
ConvertModuleNameToPointer(MREF * mref_ptr,MODULE ** m_array_ptr)852 void ConvertModuleNameToPointer(MREF *mref_ptr, MODULE **m_array_ptr)
853
854 {
855
856 MODULE *m_ptr;
857 int StillSearching;
858
859
860 #if cmntp_print
861 textprint("ConvertModuleNameToPointer\n");
862 #endif
863
864
865 /* Set "null" names to null pointers */
866
867 if(CompareName((char *)&mref_ptr->mref_name, "null")) {
868
869 #if cmntp_print
870 textprint("making ptr null\n");
871 #endif
872
873 mref_ptr->mref_ptr = 0;
874 return;
875
876 }
877
878
879 /* Search for the module with the same name */
880
881 #if cmntp_print
882 textprint("Searching for name...\n");
883 #endif
884
885 StillSearching = Yes;
886
887 while(*m_array_ptr && StillSearching) {
888
889 m_ptr = *m_array_ptr;
890
891 if(CompareName((char *)&mref_ptr->mref_name, (char *)&m_ptr->m_name)) {
892
893 #if cmntp_print
894 textprint(" found name ");
895 PrintName(&m_ptr->m_name);
896 textprint(", ptr %u\n", m_ptr);
897 #endif
898
899 mref_ptr->mref_ptr = m_ptr;
900 StillSearching = No;
901
902 }
903
904 m_array_ptr++;
905
906 }
907
908
909 /* If the name was not found, make this a null pointer */
910
911 if(StillSearching) mref_ptr->mref_ptr = 0;
912
913 }
914
915
916 /*
917
918 Convert VMODIDATA.vmodidata_label names to VMODIDATA.vmodidata_ptr
919
920 */
921
922
923 #define cvmntp_print No
924
925
ConvertVModuleNameToPointer(VMODIDATA * vmodidata_ptr,VMODULE * v_array_ptr)926 void ConvertVModuleNameToPointer(VMODIDATA *vmodidata_ptr, VMODULE *v_array_ptr)
927
928 {
929
930 int StillSearching;
931
932
933 #if cvmntp_print
934 textprint("ConvertVModuleNameToPointer\n");
935 #endif
936
937
938 /* Set "null" names to null pointers */
939
940 if(CompareName((char *)&vmodidata_ptr->vmodidata_label, "null")) {
941
942 #if cvmntp_print
943 textprint(" making vmodidata_ptr null\n");
944 #endif
945
946 vmodidata_ptr->vmodidata_ptr = 0;
947 return;
948
949 }
950
951
952 /* Search for the VMODULE with the same name */
953
954 #if cvmntp_print
955 textprint(" Searching for name...\n");
956 #endif
957
958 StillSearching = Yes;
959
960 while((v_array_ptr->vmod_type != vmtype_term) && StillSearching) {
961
962 if(CompareName((char *)&vmodidata_ptr->vmodidata_label, (char *)&v_array_ptr->vmod_name)) {
963
964 #if cmntp_print
965 textprint(" found name ");
966 PrintName(&v_array_ptr->vmod_name);
967 textprint(", ptr %u\n", v_array_ptr);
968 #endif
969
970 vmodidata_ptr->vmodidata_ptr = v_array_ptr;
971 StillSearching = No;
972
973 }
974
975 v_array_ptr++;
976
977 }
978
979
980 /* If the name was not found, make this a null pointer */
981
982 if(StillSearching)
983 {
984 if(v_array_ptr->vmod_type == vmtype_term)
985 {
986 vmodidata_ptr->vmodidata_ptr = v_array_ptr;
987 }
988 else
989 {
990 vmodidata_ptr->vmodidata_ptr = 0;
991 }
992 }
993
994
995 }
996
997
998
999
CompareName(char * name1,char * name2)1000 int CompareName(char *name1, char *name2)
1001
1002 {
1003
1004 int i;
1005
1006
1007 for(i = 4; i!=0; i--) {
1008
1009 if(*name1++ != *name2++) return No;
1010
1011 }
1012
1013 return Yes;
1014
1015 }
1016
1017
PrintName(char * name)1018 void PrintName(char *name)
1019
1020 {
1021
1022 char m_name[5];
1023
1024
1025 m_name[0] = name[0];
1026 m_name[1] = name[1];
1027 m_name[2] = name[2];
1028 m_name[3] = name[3];
1029 m_name[4] = 0;
1030 textprint(m_name);
1031
1032 }
1033
1034
IsModuleVisibleFromModule(MODULE * source,MODULE * target)1035 int IsModuleVisibleFromModule(MODULE *source, MODULE *target) {
1036
1037 VMODULE *vptr;
1038 MODULE *mptr;
1039 int gotit;
1040
1041 vptr=source->m_vmptr;
1042 mptr=NULL;
1043 gotit=0;
1044
1045 if ((source==NULL)||(target==NULL)) return(0);
1046 if (source==target) return(1);
1047
1048 while(! ((vptr->vmod_type == vmtype_term)||(gotit)) ) {
1049
1050 /* Add this module to the visible array */
1051
1052 if(vptr->vmod_mref.mref_ptr) {
1053
1054 mptr = vptr->vmod_mref.mref_ptr;
1055
1056 if (mptr==target) gotit=1;
1057
1058 }
1059
1060 /* VMODULE instructions */
1061
1062 switch(vptr->vmod_instr) {
1063
1064 case vmodi_null:
1065
1066 vptr++;
1067
1068 break;
1069
1070 case vmodi_bra_vc:
1071
1072 /* NYD */
1073
1074 /* If the door/viewport is closed... */
1075
1076 /* Branch to this vptr */
1077
1078 if(mptr)
1079 {
1080 if(mptr->m_flags & m_flag_open)
1081 vptr++;
1082 else
1083 vptr = vptr->vmod_data.vmodidata_ptr;
1084 }
1085
1086
1087
1088 /* else vptr++; */
1089
1090 break;
1091
1092 }
1093
1094 }
1095
1096 return(gotit);
1097
1098 }
1099
IsAIModuleVisibleFromAIModule(AIMODULE * source,AIMODULE * target)1100 int IsAIModuleVisibleFromAIModule(AIMODULE *source,AIMODULE *target) {
1101
1102 if ((source==NULL)||(target==NULL)) return(0);
1103 if (source==target) return(1);
1104
1105 {
1106 MODULE **targetModulelistPtr;
1107 MODULE **sourceModulelistPtr = source->m_module_ptrs;
1108 while(*sourceModulelistPtr) {
1109
1110 targetModulelistPtr=target->m_module_ptrs;
1111 while(*targetModulelistPtr) {
1112 if (IsModuleVisibleFromModule(*sourceModulelistPtr,*targetModulelistPtr)) {
1113 return(1);
1114 }
1115 targetModulelistPtr++;
1116 }
1117 sourceModulelistPtr++;
1118 }
1119 }
1120
1121 return(0);
1122 }
1123
1124 #endif
1125