MODULE.C 20 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  1. #include "3dc.h"
  2. #include "inline.h"
  3. #include "module.h"
  4. #include "stratdef.h"
  5. #include "bh_types.h"
  6. #include "pvisible.h"
  7. #include "pfarlocs.h"
  8. #include "avpview.h"
  9. #include "ourasert.h"
  10. #include "pldghost.h"
  11. #if SupportModules
  12. /* imported externs */
  13. extern SCENE Global_Scene;
  14. extern int NumActiveBlocks;
  15. extern DISPLAYBLOCK *ActiveBlockList[];
  16. extern DISPLAYBLOCK *dptr_last;
  17. extern unsigned char KeyASCII;
  18. /**** Protos ****/
  19. void FindVisibleModules(VMODULE *vptr,int flag);
  20. /**** Statics ****/
  21. static MODULE **Global_ModuleArrayPtr;
  22. void AllNewModuleHandler(void)
  23. {
  24. {
  25. int i;
  26. SCENEMODULE *smptr;
  27. smptr = Global_ModulePtr[Global_Scene];
  28. Global_ModuleArrayPtr = smptr->sm_marray;
  29. for(i = 0; i < ModuleArraySize; i++)
  30. {
  31. ModuleCurrVisArray[i] = 0;
  32. }
  33. }
  34. /* handle dynamic module objects */
  35. {
  36. int numberOfObjects = NumActiveBlocks;
  37. while (numberOfObjects--)
  38. {
  39. DISPLAYBLOCK* objectPtr = ActiveBlockList[numberOfObjects];
  40. if(objectPtr->ObFlags3 & ObFlag3_DynamicModuleObject)
  41. {
  42. STRATEGYBLOCK *sbPtr = objectPtr->ObStrategyBlock;
  43. sbPtr->containingModule = (ModuleFromPosition(&(objectPtr->ObWorld), sbPtr->containingModule));
  44. if (sbPtr->containingModule)
  45. if (ModuleIsPhysical(sbPtr->containingModule))
  46. {
  47. ModuleCurrVisArray[sbPtr->containingModule->m_index] = 1;
  48. if(sbPtr->containingModule->m_vmptr) FindVisibleModules(sbPtr->containingModule->m_vmptr,1);
  49. }
  50. }
  51. }
  52. }
  53. /*If this is an network game , and this machine is the ai server , then need to check if
  54. there are any aliens near to other players*/
  55. if(AvP.Network!=I_No_Network && AvP.NetworkAIServer)
  56. {
  57. /* go through the strategy blocks looking for players*/
  58. int sbIndex;
  59. for(sbIndex=0;sbIndex<NumActiveStBlocks;sbIndex++)
  60. {
  61. STRATEGYBLOCK *playerSbPtr = ActiveStBlockList[sbIndex];
  62. NETGHOSTDATABLOCK *ghostData;
  63. if(playerSbPtr->I_SBtype!=I_BehaviourNetGhost) continue;
  64. ghostData = (NETGHOSTDATABLOCK *)playerSbPtr->SBdataptr;
  65. if(ghostData->type==I_BehaviourAlienPlayer ||
  66. ghostData->type==I_BehaviourMarinePlayer ||
  67. ghostData->type==I_BehaviourPredatorPlayer)
  68. {
  69. int sbIndex2;
  70. //found one of the players
  71. if(!playerSbPtr->containingModule) continue;
  72. /*now search through the strategy blocks , to see if any aliens are
  73. visible from the player's location*/
  74. for(sbIndex2=0;sbIndex2<NumActiveStBlocks;sbIndex2++)
  75. {
  76. STRATEGYBLOCK *alienSbPtr = ActiveStBlockList[sbIndex2];
  77. /*Is it an alien?*/
  78. if(alienSbPtr->I_SBtype!=I_BehaviourAlien) continue;
  79. if(!alienSbPtr->containingModule) continue;
  80. if(IsModuleVisibleFromModule(playerSbPtr->containingModule,alienSbPtr->containingModule))
  81. {
  82. /*The player can see the alien , so link in all modules that the
  83. player can see*/
  84. if (ModuleIsPhysical(playerSbPtr->containingModule))
  85. {
  86. ModuleCurrVisArray[playerSbPtr->containingModule->m_index] = 1;
  87. if(playerSbPtr->containingModule->m_vmptr) FindVisibleModules(playerSbPtr->containingModule->m_vmptr,1);
  88. }
  89. /*Since all modules visible by this player have now been linked , don't need
  90. to check for any more aliens for this player*/
  91. break;
  92. }
  93. }
  94. }
  95. }
  96. }
  97. /* handle player visibilities */
  98. {
  99. extern MODULE * playerPherModule;
  100. playerPherModule = (ModuleFromPosition(&(Global_VDB_Ptr->VDB_World), playerPherModule));
  101. if(!playerPherModule)
  102. {
  103. playerPherModule = (ModuleFromPosition(&(Player->ObWorld), playerPherModule));
  104. }
  105. if (playerPherModule)
  106. {
  107. ModuleCurrVisArray[playerPherModule->m_index] = 2;
  108. if(playerPherModule->m_vmptr) FindVisibleModules(playerPherModule->m_vmptr,2);
  109. }
  110. }
  111. /* handle AIMODULE visibility stuff */
  112. {
  113. int i;
  114. for(i = 0; i < ModuleArraySize; i++)
  115. {
  116. if (ModuleCurrVisArray[i] == 2)
  117. {
  118. AIMODULE *aiModulePtr = Global_ModuleArrayPtr[i]->m_aimodule;
  119. if (aiModulePtr)
  120. {
  121. MODULE **modulelistPtr = aiModulePtr->m_module_ptrs;
  122. while(*modulelistPtr)
  123. {
  124. int index = (*modulelistPtr)->m_index;
  125. if (!ModuleCurrVisArray[index]) ModuleCurrVisArray[index]=1;
  126. modulelistPtr++;
  127. }
  128. }
  129. }
  130. }
  131. }
  132. /* update active block list */
  133. {
  134. int i;
  135. for(i = 0; i < ModuleArraySize; i++)
  136. {
  137. MODULE *mptr = Global_ModuleArrayPtr[i];
  138. if(ModuleCurrVisArray[i])
  139. {
  140. if(mptr->m_dptr == 0 && ((mptr->m_flags & m_flag_dormant) == 0))
  141. {
  142. AllocateModuleObject(mptr);
  143. }
  144. }
  145. else
  146. {
  147. if(mptr->m_dptr) DeallocateModuleObject(mptr);
  148. }
  149. }
  150. }
  151. /* call Patrick's code */
  152. DoObjectVisibilities();
  153. }
  154. void FindVisibleModules(VMODULE *vptr,int flag)
  155. {
  156. while(vptr->vmod_type != vmtype_term)
  157. {
  158. MODULE *mptr;
  159. /* Add this module to the visible array */
  160. if(vptr->vmod_mref.mref_ptr)
  161. {
  162. mptr = vptr->vmod_mref.mref_ptr;
  163. ModuleCurrVisArray[mptr->m_index] = flag;
  164. }
  165. /* VMODULE instructions */
  166. switch(vptr->vmod_instr)
  167. {
  168. case vmodi_null:
  169. vptr++;
  170. break;
  171. case vmodi_bra_vc:
  172. /* If the door/viewport is closed... */
  173. /* Branch to this vptr */
  174. /* else vptr++; */
  175. if(mptr)
  176. {
  177. if(mptr->m_flags & m_flag_open) vptr++;
  178. else vptr = vptr->vmod_data.vmodidata_ptr;
  179. }
  180. break;
  181. }
  182. }
  183. }
  184. int ThisObjectIsInAModuleVisibleFromCurrentlyVisibleModules(STRATEGYBLOCK *sbPtr)
  185. {
  186. VMODULE *vPtr;
  187. GLOBALASSERT(sbPtr);
  188. GLOBALASSERT(sbPtr->containingModule);
  189. vPtr = sbPtr->containingModule->m_vmptr;
  190. GLOBALASSERT(vPtr);
  191. if(ModuleCurrVisArray[sbPtr->containingModule->m_index] == 2)
  192. {
  193. return 1;
  194. }
  195. while(vPtr->vmod_type != vmtype_term)
  196. {
  197. MODULE *mptr;
  198. /* consider this module */
  199. if(vPtr->vmod_mref.mref_ptr)
  200. {
  201. mptr = vPtr->vmod_mref.mref_ptr;
  202. if(ModuleCurrVisArray[mptr->m_index] == 2)
  203. {
  204. if(vPtr->vmod_instr==vmodi_bra_vc)
  205. {
  206. if(mptr->m_flags & m_flag_open) return 1;
  207. }
  208. else
  209. {
  210. return 1;
  211. }
  212. }
  213. }
  214. /* VMODULE instructions */
  215. switch(vPtr->vmod_instr)
  216. {
  217. case vmodi_null:
  218. vPtr++;
  219. break;
  220. case vmodi_bra_vc:
  221. /* If the door/viewport is closed... */
  222. /* Branch to this vPtr */
  223. /* else vPtr++; */
  224. if(mptr)
  225. {
  226. if(mptr->m_flags & m_flag_open) vPtr++;
  227. else vPtr = vPtr->vmod_data.vmodidata_ptr;
  228. }
  229. break;
  230. }
  231. }
  232. return 0;
  233. }
  234. void ModuleFunctions(MODULE *mptr, MFUNCTION mf)
  235. {
  236. switch(mf)
  237. {
  238. case mfun_null:
  239. break;
  240. }
  241. }
  242. void AllocateModuleObject(MODULE *mptr)
  243. {
  244. DISPLAYBLOCK *dptr;
  245. MODULEMAPBLOCK *mapblockptr;
  246. STRATEGYBLOCK *sb = 0;
  247. #if SupportMorphing
  248. MORPHCTRL *mc;
  249. #endif
  250. dptr_last = 0;
  251. mptr->m_dptr = 0;
  252. if(mptr == 0) return; /* Whoops! */
  253. if(mptr->m_mapptr == 0) return; /* Not all modules have maps */
  254. dptr = CreateActiveObject();
  255. if(dptr) {
  256. /* Tell the module we exist */
  257. mptr->m_dptr = dptr;
  258. /* Tell the object who its module is */
  259. dptr->ObMyModule = mptr;
  260. /* Get the strategy block, if it exists */
  261. if(mptr->m_sbptr) sb = mptr->m_sbptr;
  262. /* If there is a STRATEGYBLOCK, tell it we exist */
  263. if(sb) {
  264. dptr->ObStrategyBlock = sb;
  265. sb->SBdptr = dptr;
  266. }
  267. /* Read the map */
  268. mapblockptr = mptr->m_mapptr;
  269. dptr->ObShape = mapblockptr->MapShape;
  270. CopyLocation(&mapblockptr->MapWorld, &dptr->ObWorld);
  271. CopyEuler(&mapblockptr->MapEuler, &dptr->ObEuler);
  272. dptr->ObFlags = mapblockptr->MapFlags;
  273. dptr->ObFlags2 = mapblockptr->MapFlags2;
  274. dptr->ObFlags3 = mapblockptr->MapFlags3;
  275. #if SupportMorphing
  276. /* If there is a strategy block, see if it has a MORPHCTRL structure */
  277. if(sb) {
  278. if(sb->SBmorphctrl) {
  279. /* Pass MORPHCTRL to dptr */
  280. dptr->ObMorphCtrl = sb->SBmorphctrl;
  281. /* Copy the morph pointer from the map to the dptr */
  282. mc = dptr->ObMorphCtrl;
  283. mc->ObMorphHeader = mapblockptr->MapMorphHeader;
  284. /* OLD TEST - These values are now set elsewhere */
  285. #if 0
  286. if(mc->ObMorphHeader) {
  287. mc->ObMorphCurrFrame = 0;
  288. mc->ObMorphFlags = mph_flag_play/* | mph_flag_noloop | mph_flag_reverse*/;
  289. mc->ObMorphSpeed = ONE_FIXED;
  290. }
  291. #endif
  292. }
  293. }
  294. #endif /* Support Morphing */
  295. #if InterfaceEngine
  296. dbptr->o_chunk = mapblockptr->o_chunk;
  297. #endif
  298. dptr->ObLightType = LightType_PerVertex;
  299. dptr->ObFlags |= ObFlag_MultLSrc;
  300. if(mapblockptr->MapVDBData)
  301. MapSetVDB(dptr, mapblockptr->MapVDBData);
  302. dptr->ObLightType = mapblockptr->MapLightType;
  303. MapBlockInit(dptr);
  304. /* KJL 14:15:34 04/19/97 - their used to be lots of maths here
  305. to calculate orientation, but in AvP all modules are aligned to
  306. the world space axes... */
  307. {
  308. extern MATRIXCH IdentityMatrix;
  309. dptr->ObMat = IdentityMatrix;
  310. }
  311. /*
  312. Module lights
  313. There is an option for a pointer to an array of lights in a module
  314. structure. These lights are transferred to the display block and
  315. flagged as "LFlag_WasNotAllocated" so that "DeallocateLightBlock()"
  316. knows to ignore them.
  317. The number of lights in the array is "m_numlights" and the pointer
  318. is called "m_lightarray".
  319. The addition of non-allocated does not need to be a module specific
  320. option.
  321. Non-allocated lights can co-exist peacefully with the other lights.
  322. */
  323. if(mptr->m_numlights && mptr->m_lightarray) {
  324. LIGHTBLOCK *lptr_array = mptr->m_lightarray;
  325. int i;
  326. for(i = mptr->m_numlights; i!=0; i--) {
  327. /* Make sure the light is flagged correctly */
  328. lptr_array->LightFlags |= LFlag_WasNotAllocated;
  329. /* Add the light */
  330. AddLightBlock(dptr, lptr_array);
  331. /* Next light from the array */
  332. lptr_array++;
  333. }
  334. }
  335. /*
  336. As with shared points, extra item data for prelighting is also
  337. copied from the module to the display block.
  338. WARNING:
  339. Allocation and deallocation of this pointer is the responsibility
  340. of the user!
  341. */
  342. dptr->ObEIDPtr = mptr->m_extraitemdata;
  343. /* Added Name to DISPLAYBLOCK */
  344. #if SupportWindows95
  345. dptr->name = mptr->name;
  346. #endif
  347. MapPostProcessing(dptr);
  348. ModuleObjectJustAllocated(mptr); /* Project Function */
  349. /* Bug Fix */
  350. if (dptr->ObStrategyBlock) {
  351. STRATEGYBLOCK *sbptr=dptr->ObStrategyBlock;
  352. if (sbptr->I_SBtype==I_BehaviourSimpleAnimation) {
  353. SIMPLE_ANIM_BEHAV_BLOCK *sanimbhv;
  354. sanimbhv = (SIMPLE_ANIM_BEHAV_BLOCK*)(sbptr->SBdataptr);
  355. GLOBALASSERT(sanimbhv->bhvr_type == I_BehaviourSimpleAnimation);
  356. GLOBALASSERT (dptr == sbptr->SBdptr);
  357. if(!dptr->ObTxAnimCtrlBlks) {
  358. dptr->ObTxAnimCtrlBlks = sanimbhv->tacbSimple;
  359. }
  360. }
  361. }
  362. }
  363. dptr_last = dptr;
  364. }
  365. void DeallocateModuleObject(MODULE *mptr)
  366. {
  367. DISPLAYBLOCK *dptr;
  368. STRATEGYBLOCK *sb;
  369. if(mptr->m_dptr) {
  370. ModuleObjectAboutToBeDeallocated(mptr); /* Project Function */
  371. dptr = mptr->m_dptr;
  372. DestroyActiveObject(dptr);
  373. /* Clear module reference to dptr */
  374. mptr->m_dptr = 0;
  375. /* If there is a STRATEGYBLOCK, clear that reference too */
  376. if(mptr->m_sbptr) {
  377. sb = mptr->m_sbptr;
  378. sb->SBdptr = 0;
  379. }
  380. }
  381. }
  382. /*
  383. The Module Preprocessor
  384. Pass the array of pointers to modules.
  385. This function creates module indices and converts names into pointers.
  386. */
  387. /*
  388. temp patch to match current chunk
  389. loader configuration
  390. */
  391. void PreprocessAllModules(void)
  392. {
  393. SCENEMODULE **sm_array_ptr;
  394. SCENEMODULE *sm_ptr;
  395. if(Global_ModulePtr == 0) return;
  396. sm_array_ptr = Global_ModulePtr;
  397. while(*sm_array_ptr)
  398. {
  399. sm_ptr = *sm_array_ptr;
  400. PreprocessModuleArray(sm_ptr->sm_marray);
  401. sm_array_ptr++;
  402. }
  403. }
  404. /*
  405. A special function to deallocate the module visibility arrays
  406. */
  407. void DeallocateModuleVisArrays(void)
  408. {
  409. if(ModuleCurrVisArray) {
  410. DeallocateMem(ModuleCurrVisArray);
  411. ModuleCurrVisArray = 0;
  412. }
  413. }
  414. /*
  415. Allocate the two arrays used to keep track of module visibility from
  416. frame to frame. The function uses the global scene variable to access the
  417. appropriate SCENEMODULE and find out how many modules are present. It also
  418. deallocates the previous arrays if they exist.
  419. */
  420. int GetModuleVisArrays(void)
  421. {
  422. SCENEMODULE *sm_ptr;
  423. MODULE **m_array_ptr;
  424. MODULE *m_ptr;
  425. int index, i;
  426. if(Global_ModulePtr == 0) return No;
  427. DeallocateModuleVisArrays();
  428. sm_ptr = Global_ModulePtr[Global_Scene];
  429. m_array_ptr = sm_ptr->sm_marray;
  430. index = smallint;
  431. while(*m_array_ptr) {
  432. m_ptr = *m_array_ptr++;
  433. if(m_ptr->m_index > index) index = m_ptr->m_index;
  434. }
  435. ModuleArraySize = index + 1;
  436. ModuleCurrVisArray = AllocateMem(ModuleArraySize);
  437. if(ModuleCurrVisArray)
  438. {
  439. for(i = 0; i < ModuleArraySize; i++)
  440. {
  441. ModuleCurrVisArray[i] = 0;
  442. }
  443. #if 0
  444. textprint("visibility arrays ok, size %d\n", ModuleArraySize);
  445. #endif
  446. return Yes;
  447. }
  448. else return No;
  449. }
  450. #define ppma_print No
  451. #if 1
  452. void PreprocessModuleArray(MODULE **m_array_ptr)
  453. {
  454. MODULE **m_array = m_array_ptr;
  455. MODULE *m_ptr;
  456. int index;
  457. #if ppma_print
  458. textprint("PreprocessModuleArray %u\n", m_array_ptr);
  459. #endif
  460. index = 0;
  461. while(*m_array) {
  462. /* Get the module pointer */
  463. m_ptr = *m_array;
  464. /* Assign the module an index */
  465. m_ptr->m_index = index++;
  466. #if ppma_print
  467. textprint("\nModule %u, ", m_ptr);
  468. PrintName(&m_ptr->m_name);
  469. textprint(", index %d\n", m_ptr->m_index);
  470. textprint(" (vptr = ");
  471. PrintName(&m_ptr->m_vptr.mref_name);
  472. textprint(")\n");
  473. #endif
  474. /* Convert module references from names to pointers */
  475. if(!(m_ptr->m_flags & m_flag_gotptrs)) {
  476. #if 0
  477. /* Vertical Pointer */
  478. ConvertModuleNameToPointer(&m_ptr->m_vptr, m_array_ptr);
  479. /* Extent Pointer */
  480. ConvertModuleNameToPointer(&m_ptr->m_ext, m_array_ptr);
  481. /* Function Pointer */
  482. ConvertModuleNameToPointer(&m_ptr->m_funref, m_array_ptr);
  483. // Hack by John to make the m_link pointers work
  484. if (m_ptr->m_link_ptrs)
  485. {
  486. MREF * m_link_ptr = m_ptr->m_link_ptrs;
  487. while (m_link_ptr->mref_ptr)
  488. {
  489. ConvertModuleNameToPointer(m_link_ptr++, m_array_ptr);
  490. }
  491. }
  492. #endif
  493. /* VMODULE Array */
  494. if(m_ptr->m_vmptr) {
  495. /* Convert VMODIDATA names to pointers */
  496. PreprocessVMODIDATA(m_ptr->m_vmptr);
  497. /* Convert MREF names to pointers */
  498. /*
  499. v_ptr = m_ptr->m_vmptr;
  500. while(v_ptr->vmod_type != vmtype_term) {
  501. ConvertModuleNameToPointer(&v_ptr->vmod_mref, m_array_ptr);
  502. v_ptr++;
  503. }
  504. */
  505. }
  506. /* Tell the module that its names are now pointers */
  507. m_ptr->m_flags |= m_flag_gotptrs;
  508. }
  509. /* Calculate module extents */
  510. //I'll set the extents and world position in the loaders -Richard.
  511. //GetModuleMapData(m_ptr);
  512. /* Next module array entry */
  513. m_array++;
  514. }
  515. /*WaitForReturn();*/
  516. }
  517. #else
  518. #endif
  519. /*
  520. VMODIDATA is the data associated with VMODI, the VMODULE instruction. Some
  521. of the data items are names which need to be converted to pointers.
  522. */
  523. void PreprocessVMODIDATA(VMODULE *v_ptr)
  524. {
  525. VMODULE *v_array_ptr = v_ptr;
  526. while(v_ptr->vmod_type != vmtype_term) {
  527. if(!(v_ptr->vmod_flags & vm_flag_gotptrs)) {
  528. switch(v_ptr->vmod_instr) {
  529. case vmodi_null:
  530. break;
  531. case vmodi_bra_vc:
  532. ConvertVModuleNameToPointer(&v_ptr->vmod_data, v_array_ptr);
  533. break;
  534. }
  535. v_ptr->vmod_flags |= vm_flag_gotptrs;
  536. }
  537. v_ptr++;
  538. }
  539. }
  540. /*
  541. Convert MREF name to MREF pointer
  542. */
  543. #define cmntp_print No
  544. void ConvertModuleNameToPointer(MREF *mref_ptr, MODULE **m_array_ptr)
  545. {
  546. MODULE *m_ptr;
  547. int StillSearching;
  548. #if cmntp_print
  549. textprint("ConvertModuleNameToPointer\n");
  550. #endif
  551. /* Set "null" names to null pointers */
  552. if(CompareName((char *)&mref_ptr->mref_name, "null")) {
  553. #if cmntp_print
  554. textprint("making ptr null\n");
  555. #endif
  556. mref_ptr->mref_ptr = 0;
  557. return;
  558. }
  559. /* Search for the module with the same name */
  560. #if cmntp_print
  561. textprint("Searching for name...\n");
  562. #endif
  563. StillSearching = Yes;
  564. while(*m_array_ptr && StillSearching) {
  565. m_ptr = *m_array_ptr;
  566. if(CompareName((char *)&mref_ptr->mref_name, (char *)&m_ptr->m_name)) {
  567. #if cmntp_print
  568. textprint(" found name ");
  569. PrintName(&m_ptr->m_name);
  570. textprint(", ptr %u\n", m_ptr);
  571. #endif
  572. mref_ptr->mref_ptr = m_ptr;
  573. StillSearching = No;
  574. }
  575. m_array_ptr++;
  576. }
  577. /* If the name was not found, make this a null pointer */
  578. if(StillSearching) mref_ptr->mref_ptr = 0;
  579. }
  580. /*
  581. Convert VMODIDATA.vmodidata_label names to VMODIDATA.vmodidata_ptr
  582. */
  583. #define cvmntp_print No
  584. void ConvertVModuleNameToPointer(VMODIDATA *vmodidata_ptr, VMODULE *v_array_ptr)
  585. {
  586. int StillSearching;
  587. #if cvmntp_print
  588. textprint("ConvertVModuleNameToPointer\n");
  589. #endif
  590. /* Set "null" names to null pointers */
  591. if(CompareName((char *)&vmodidata_ptr->vmodidata_label, "null")) {
  592. #if cvmntp_print
  593. textprint(" making vmodidata_ptr null\n");
  594. #endif
  595. vmodidata_ptr->vmodidata_ptr = 0;
  596. return;
  597. }
  598. /* Search for the VMODULE with the same name */
  599. #if cvmntp_print
  600. textprint(" Searching for name...\n");
  601. #endif
  602. StillSearching = Yes;
  603. while((v_array_ptr->vmod_type != vmtype_term) && StillSearching) {
  604. if(CompareName((char *)&vmodidata_ptr->vmodidata_label, (char *)&v_array_ptr->vmod_name)) {
  605. #if cmntp_print
  606. textprint(" found name ");
  607. PrintName(&v_array_ptr->vmod_name);
  608. textprint(", ptr %u\n", v_array_ptr);
  609. #endif
  610. vmodidata_ptr->vmodidata_ptr = v_array_ptr;
  611. StillSearching = No;
  612. }
  613. v_array_ptr++;
  614. }
  615. /* If the name was not found, make this a null pointer */
  616. if(StillSearching)
  617. {
  618. if(v_array_ptr->vmod_type == vmtype_term)
  619. {
  620. vmodidata_ptr->vmodidata_ptr = v_array_ptr;
  621. }
  622. else
  623. {
  624. vmodidata_ptr->vmodidata_ptr = 0;
  625. }
  626. }
  627. }
  628. int CompareName(char *name1, char *name2)
  629. {
  630. int i;
  631. for(i = 4; i!=0; i--) {
  632. if(*name1++ != *name2++) return No;
  633. }
  634. return Yes;
  635. }
  636. void PrintName(char *name)
  637. {
  638. char m_name[5];
  639. m_name[0] = name[0];
  640. m_name[1] = name[1];
  641. m_name[2] = name[2];
  642. m_name[3] = name[3];
  643. m_name[4] = 0;
  644. textprint(m_name);
  645. }
  646. int IsModuleVisibleFromModule(MODULE *source, MODULE *target) {
  647. VMODULE *vptr;
  648. MODULE *mptr;
  649. int gotit;
  650. vptr=source->m_vmptr;
  651. gotit=0;
  652. if ((source==NULL)||(target==NULL)) return(0);
  653. if (source==target) return(1);
  654. while(! ((vptr->vmod_type == vmtype_term)||(gotit)) ) {
  655. /* Add this module to the visible array */
  656. if(vptr->vmod_mref.mref_ptr) {
  657. mptr = vptr->vmod_mref.mref_ptr;
  658. if (mptr==target) gotit=1;
  659. }
  660. /* VMODULE instructions */
  661. switch(vptr->vmod_instr) {
  662. case vmodi_null:
  663. vptr++;
  664. break;
  665. case vmodi_bra_vc:
  666. /* NYD */
  667. /* If the door/viewport is closed... */
  668. /* Branch to this vptr */
  669. if(mptr)
  670. {
  671. if(mptr->m_flags & m_flag_open)
  672. vptr++;
  673. else
  674. vptr = vptr->vmod_data.vmodidata_ptr;
  675. }
  676. /* else vptr++; */
  677. break;
  678. }
  679. }
  680. return(gotit);
  681. }
  682. int IsAIModuleVisibleFromAIModule(AIMODULE *source,AIMODULE *target) {
  683. if ((source==NULL)||(target==NULL)) return(0);
  684. if (source==target) return(1);
  685. {
  686. MODULE **targetModulelistPtr;
  687. MODULE **sourceModulelistPtr = source->m_module_ptrs;
  688. while(*sourceModulelistPtr) {
  689. targetModulelistPtr=target->m_module_ptrs;
  690. while(*targetModulelistPtr) {
  691. if (IsModuleVisibleFromModule(*sourceModulelistPtr,*targetModulelistPtr)) {
  692. return(1);
  693. }
  694. targetModulelistPtr++;
  695. }
  696. sourceModulelistPtr++;
  697. }
  698. }
  699. return(0);
  700. }
  701. #endif