| | 1 | #include "system.h" |
| | 2 | #include "stratdef.h" |
| | 3 | #include "bh_types.h" |
| | 4 | #include "pldghost.h" |
| | 5 | #include "pfarlocs.h" |
| | 6 | #include <assert.h> |
| | 7 | #include <string.h> |
| | 8 | #include <stdlib.h> |
| | 9 | #include <stdio.h> |
| | 10 | |
| | 11 | SCENEMODULE MainScene; |
| | 12 | |
| | 13 | const MATRIXCH IdentityMatrix = |
| | 14 | { |
| | 15 | ONE_FIXED, 0, 0, |
| | 16 | 0, ONE_FIXED, 0, |
| | 17 | 0, 0, ONE_FIXED |
| | 18 | }; |
| | 19 | |
| | 20 | extern int ModuleArraySize; |
| | 21 | extern int NumActiveBlocks; |
| | 22 | extern DISPLAYBLOCK *ActiveBlockList[]; |
| | 23 | extern int render_sky; |
| | 24 | |
| | 25 | unsigned char *ModuleCurrVisArray; |
| | 26 | |
| | 27 | void FindVisibleModules(VMODULE *vptr, int flag) |
| | 28 | { |
| | 29 | while(!vptr->end_module) |
| | 30 | { |
| | 31 | MODULE *mptr = vptr->vmod_mref.mref_ptr; |
| | 32 | |
| | 33 | if(NULL != mptr) |
| | 34 | { |
| | 35 | if(!ModuleCurrVisArray[mptr->m_index]) |
| | 36 | ModuleCurrVisArray[mptr->m_index] = flag; |
| | 37 | |
| | 38 | // If the door/viewport is closed... |
| | 39 | if((NULL != vptr->vmod_data) && !(mptr->m_flags & m_flag_open)) |
| | 40 | { |
| | 41 | // Branch to this vptr |
| | 42 | vptr = vptr->vmod_data->vmodidata_ptr; |
| | 43 | continue; |
| | 44 | } |
| | 45 | // else vptr++; |
| | 46 | } |
| | 47 | |
| | 48 | vptr++; |
| | 49 | } |
| | 50 | } |
| | 51 | |
| | 52 | DISPLAYBLOCK * AllocateNewObject(const int shapeIndex) |
| | 53 | { |
| | 54 | DISPLAYBLOCK *dptr = CreateActiveObject(); |
| | 55 | |
| | 56 | if(dptr) |
| | 57 | { |
| | 58 | struct shapeheader* sptr = mainshapelist[shapeIndex]; |
| | 59 | dptr->ObShape = shapeIndex; |
| | 60 | dptr->ShapeData = sptr; |
| | 61 | dptr->extent.radius = sptr->shaperadius; |
| | 62 | dptr->extent.max_x = sptr->shapemaxx; |
| | 63 | dptr->extent.min_x = sptr->shapeminx; |
| | 64 | dptr->extent.max_y = sptr->shapemaxy; |
| | 65 | dptr->extent.min_y = sptr->shapeminy; |
| | 66 | dptr->extent.max_z = sptr->shapemaxz; |
| | 67 | dptr->extent.min_z = sptr->shapeminz; |
| | 68 | dptr->ObMat = IdentityMatrix; |
| | 69 | } |
| | 70 | |
| | 71 | return dptr; |
| | 72 | } |
| | 73 | |
| | 74 | static void AllocateModuleObject(MODULE *mptr) |
| | 75 | { |
| | 76 | DISPLAYBLOCK *dptr = CreateActiveObject(); |
| | 77 | |
| | 78 | if(dptr) |
| | 79 | { |
| | 80 | mptr->m_dptr = dptr; |
| | 81 | dptr->Module = mptr; |
| | 82 | |
| | 83 | if(mptr->m_sbptr) |
| | 84 | { |
| | 85 | dptr->ObStrategyBlock = mptr->m_sbptr; |
| | 86 | mptr->m_sbptr->DisplayBlock = dptr; |
| | 87 | |
| | 88 | if(mptr->m_sbptr->morphctrl) |
| | 89 | dptr->ObMorphCtrl = mptr->m_sbptr->morphctrl; |
| | 90 | } |
| | 91 | |
| | 92 | MODULEMAPBLOCK *mapblockptr = mptr->m_mapptr; |
| | 93 | |
| | 94 | dptr->ObShape = mapblockptr->MapShape; |
| | 95 | dptr->ObWorld = mapblockptr->MapWorld; |
| | 96 | dptr->ObEuler = mapblockptr->MapEuler; |
| | 97 | dptr->ObFlags = mapblockptr->MapFlags; |
| | 98 | dptr->ObFlags2 = mapblockptr->MapFlags2; |
| | 99 | dptr->ObFlags3 = mapblockptr->MapFlags3; |
| | 100 | |
| | 101 | struct shapeheader* sptr = mainshapelist[dptr->ObShape]; |
| | 102 | dptr->ShapeData = sptr; |
| | 103 | |
| | 104 | dptr->extent.radius = sptr->shaperadius; |
| | 105 | dptr->extent.max_x = sptr->shapemaxx; |
| | 106 | dptr->extent.min_x = sptr->shapeminx; |
| | 107 | dptr->extent.max_y = sptr->shapemaxy; |
| | 108 | dptr->extent.min_y = sptr->shapeminy; |
| | 109 | dptr->extent.max_z = sptr->shapemaxz; |
| | 110 | dptr->extent.min_z = sptr->shapeminz; |
| | 111 | |
| | 112 | /* |
| | 113 | KJL 14:15:34 04/19/97 - their used to be lots of maths here |
| | 114 | to calculate orientation, but in AvP all modules are aligned to |
| | 115 | the world space axes... |
| | 116 | */ |
| | 117 | |
| | 118 | dptr->ObMat = IdentityMatrix; |
| | 119 | |
| | 120 | /* |
| | 121 | |
| | 122 | Module lights |
| | 123 | |
| | 124 | There is an option for a pointer to an array of lights in a module |
| | 125 | structure. These lights are transferred to the display block and |
| | 126 | flagged as "LFlag_WasNotAllocated" so that "DeallocateLightBlock()" |
| | 127 | knows to ignore them. |
| | 128 | |
| | 129 | The number of lights in the array is "m_numlights" and the pointer |
| | 130 | is called "m_lightarray". |
| | 131 | |
| | 132 | The addition of non-allocated does not need to be a module specific |
| | 133 | option. |
| | 134 | |
| | 135 | Non-allocated lights can co-exist peacefully with the other lights. |
| | 136 | |
| | 137 | */ |
| | 138 | |
| | 139 | if(mptr->m_numlights && mptr->m_lightarray) |
| | 140 | { |
| | 141 | LIGHTBLOCK *lptr_array = mptr->m_lightarray; |
| | 142 | int i; |
| | 143 | |
| | 144 | for(i = mptr->m_numlights; i; i--) |
| | 145 | { |
| | 146 | /* Make sure the light is flagged correctly */ |
| | 147 | |
| | 148 | lptr_array->LightFlags |= LFlag_WasNotAllocated; |
| | 149 | |
| | 150 | AddLightBlock(dptr, lptr_array); |
| | 151 | |
| | 152 | /* Next light from the array */ |
| | 153 | |
| | 154 | lptr_array++; |
| | 155 | } |
| | 156 | } |
| | 157 | |
| | 158 | /* Bug Fix */ // for what?? |
| | 159 | /* |
| | 160 | if (dptr->ObStrategyBlock) |
| | 161 | { |
| | 162 | STRATEGYBLOCK *sbptr = dptr->ObStrategyBlock; |
| | 163 | |
| | 164 | if (sbptr->type == I_BehaviourSimpleAnimation) |
| | 165 | { |
| | 166 | SIMPLE_ANIM_BEHAV_BLOCK *sanimbhv = (SIMPLE_ANIM_BEHAV_BLOCK*)(sbptr->dataptr); |
| | 167 | |
| | 168 | assert(sanimbhv->bhvr_type == I_BehaviourSimpleAnimation); |
| | 169 | assert (dptr == sbptr->DisplayBlock); |
| | 170 | |
| | 171 | if(!dptr->ObTxAnimCtrlBlks) |
| | 172 | dptr->ObTxAnimCtrlBlks = sanimbhv->tacbSimple; |
| | 173 | } |
| | 174 | } |
| | 175 | */ |
| | 176 | } |
| | 177 | } |
| | 178 | |
| | 179 | int IsModuleVisibleFromModule(MODULE *source, MODULE *target) |
| | 180 | { |
| | 181 | if ((source == NULL) || (target == NULL)) |
| | 182 | return 0; |
| | 183 | else if (source == target) |
| | 184 | return 1; |
| | 185 | else |
| | 186 | { |
| | 187 | VMODULE *vptr = source->m_vmptr; |
| | 188 | |
| | 189 | while(!vptr->end_module) |
| | 190 | { |
| | 191 | /* Add this module to the visible array */ |
| | 192 | MODULE *mptr = vptr->vmod_mref.mref_ptr; |
| | 193 | |
| | 194 | if(NULL != mptr) |
| | 195 | { |
| | 196 | if (mptr == target) |
| | 197 | return 1; |
| | 198 | else if((NULL != vptr->vmod_data) && !(mptr->m_flags & m_flag_open)) |
| | 199 | { |
| | 200 | vptr = vptr->vmod_data->vmodidata_ptr; |
| | 201 | continue; |
| | 202 | } |
| | 203 | } |
| | 204 | |
| | 205 | vptr++; |
| | 206 | } |
| | 207 | |
| | 208 | return 0; |
| | 209 | } |
| | 210 | } |
| | 211 | |
| | 212 | |
| | 213 | void ModuleHandler() |
| | 214 | { |
| | 215 | int i; |
| | 216 | |
| | 217 | for(i=0; i < ModuleArraySize; i++) |
| | 218 | ModuleCurrVisArray[i] = 0; |
| | 219 | |
| | 220 | /*If this is an network game , and this machine is the ai server , then need to check if |
| | 221 | there are any aliens near to other players*/ |
| | 222 | |
| | 223 | if(NetworkHost == AvP.PlayMode) |
| | 224 | { |
| | 225 | /* go through the strategy blocks looking for players*/ |
| | 226 | int sbIndex; |
| | 227 | for(sbIndex = 0; sbIndex < NumActiveStBlocks; sbIndex++) |
| | 228 | { |
| | 229 | STRATEGYBLOCK *playerSbPtr = ActiveStBlockList[sbIndex]; |
| | 230 | |
| | 231 | if(playerSbPtr->type != I_BehaviourNetGhost) |
| | 232 | continue; |
| | 233 | |
| | 234 | NETGHOSTDATABLOCK *ghostData = (NETGHOSTDATABLOCK *)playerSbPtr->dataptr; |
| | 235 | |
| | 236 | switch(ghostData->type) |
| | 237 | { |
| | 238 | case I_BehaviourAlienPlayer: |
| | 239 | case I_BehaviourMarinePlayer: |
| | 240 | case I_BehaviourPredatorPlayer: |
| | 241 | { |
| | 242 | int sbIndex2 = 0; |
| | 243 | //found one of the players |
| | 244 | if(!playerSbPtr->containingModule) |
| | 245 | continue; |
| | 246 | |
| | 247 | /*now search through the strategy blocks , to see if any aliens are |
| | 248 | visible from the player's location*/ |
| | 249 | |
| | 250 | for(; sbIndex2 < NumActiveStBlocks; sbIndex2++) |
| | 251 | { |
| | 252 | STRATEGYBLOCK *alienSbPtr = ActiveStBlockList[sbIndex2]; |
| | 253 | /*Is it an alien?*/ |
| | 254 | if(alienSbPtr->type != I_BehaviourAlien) |
| | 255 | continue; |
| | 256 | |
| | 257 | if(!alienSbPtr->containingModule) |
| | 258 | continue; |
| | 259 | |
| | 260 | if(IsModuleVisibleFromModule(playerSbPtr->containingModule, alienSbPtr->containingModule)) |
| | 261 | { |
| | 262 | /*The player can see the alien , so link in all modules that the player can see*/ |
| | 263 | |
| | 264 | if (ModuleIsPhysical(playerSbPtr->containingModule)) |
| | 265 | { |
| | 266 | ModuleCurrVisArray[playerSbPtr->containingModule->m_index] = 1; |
| | 267 | |
| | 268 | if(playerSbPtr->containingModule->m_vmptr) |
| | 269 | FindVisibleModules(playerSbPtr->containingModule->m_vmptr, 1); |
| | 270 | } |
| | 271 | |
| | 272 | /* Since all modules visible by this player have now been linked, |
| | 273 | don't need to check for any more aliens for this player */ |
| | 274 | break; |
| | 275 | } |
| | 276 | } |
| | 277 | } |
| | 278 | default: |
| | 279 | break; |
| | 280 | } |
| | 281 | } |
| | 282 | } |
| | 283 | |
| | 284 | //static void FindVisibleModulesForPlayer() |
| | 285 | { |
| | 286 | int flag = 3; |
| | 287 | VMODULE *vptr = PlayerStatus.sbptr->containingModule->m_vmptr; |
| | 288 | |
| | 289 | ModuleCurrVisArray[PlayerStatus.sbptr->containingModule->m_index] = 2; |
| | 290 | |
| | 291 | if(NULL != vptr) |
| | 292 | { |
| | 293 | while(!vptr->end_module) |
| | 294 | { |
| | 295 | MODULE *mptr = vptr->vmod_mref.mref_ptr; |
| | 296 | |
| | 297 | if(NULL != mptr) |
| | 298 | { |
| | 299 | ModuleCurrVisArray[mptr->m_index] = flag++; |
| | 300 | |
| | 301 | // If the door/viewport is closed... |
| | 302 | if((NULL != vptr->vmod_data) && !(mptr->m_flags & m_flag_open)) |
| | 303 | { |
| | 304 | // Branch to this vptr |
| | 305 | vptr = vptr->vmod_data->vmodidata_ptr; |
| | 306 | continue; |
| | 307 | } |
| | 308 | // else vptr++; |
| | 309 | { |
| | 310 | AIMODULE *aiModulePtr = MainScene.sm_marray[mptr->m_index]->m_aimodule; |
| | 311 | |
| | 312 | if(NULL != aiModulePtr) |
| | 313 | { |
| | 314 | MODULE **modulelistPtr = aiModulePtr->m_module_ptrs; |
| | 315 | |
| | 316 | while(*modulelistPtr) |
| | 317 | { |
| | 318 | int index = (*modulelistPtr)->m_index; |
| | 319 | |
| | 320 | if (!ModuleCurrVisArray[index]) |
| | 321 | ModuleCurrVisArray[index] = 1; |
| | 322 | |
| | 323 | modulelistPtr++; |
| | 324 | } |
| | 325 | } |
| | 326 | } |
| | 327 | } |
| | 328 | |
| | 329 | vptr++; |
| | 330 | } |
| | 331 | } |
| | 332 | } |
| | 333 | |
| | 334 | render_sky = 0; |
| | 335 | |
| | 336 | for(i=0; i < ModuleArraySize; i++) |
| | 337 | { |
| | 338 | MODULE *mptr = MainScene.sm_marray[i]; |
| | 339 | |
| | 340 | if(ModuleCurrVisArray[i] > 1) |
| | 341 | { |
| | 342 | /* mptr->m_mapptr Not all modules have maps */ |
| | 343 | |
| | 344 | if(!mptr->m_dptr && !(mptr->m_flags & m_flag_dormant) && mptr->m_mapptr) |
| | 345 | { |
| | 346 | AllocateModuleObject(mptr); |
| | 347 | } |
| | 348 | |
| | 349 | if((mptr->m_flags & MODULEFLAG_SKY) && (ModuleCurrVisArray[mptr->m_index] > 1)) |
| | 350 | render_sky = 1; |
| | 351 | } |
| | 352 | else if(mptr->m_dptr) |
| | 353 | { |
| | 354 | DestroyActiveObject(&mptr->m_dptr); |
| | 355 | |
| | 356 | if(mptr->m_sbptr) |
| | 357 | mptr->m_sbptr->DisplayBlock = NULL; |
| | 358 | } |
| | 359 | } |
| | 360 | } |
| | 361 | |
| | 362 | int ThisObjectIsInAModuleVisibleFromCurrentlyVisibleModules(STRATEGYBLOCK *sbPtr) |
| | 363 | { |
| | 364 | assert(sbPtr); |
| | 365 | assert(sbPtr->containingModule); |
| | 366 | |
| | 367 | VMODULE *vPtr = sbPtr->containingModule->m_vmptr; |
| | 368 | assert(vPtr); |
| | 369 | |
| | 370 | if(ModuleCurrVisArray[sbPtr->containingModule->m_index] > 1) |
| | 371 | return 1; |
| | 372 | |
| | 373 | while(!vPtr->end_module) |
| | 374 | { |
| | 375 | /* consider this module */ |
| | 376 | MODULE *mptr = vPtr->vmod_mref.mref_ptr; |
| | 377 | |
| | 378 | if(NULL != mptr) |
| | 379 | { |
| | 380 | if(ModuleCurrVisArray[mptr->m_index] > 1) |
| | 381 | { |
| | 382 | if(NULL != vPtr->vmod_data) |
| | 383 | { |
| | 384 | if (mptr->m_flags & m_flag_open) |
| | 385 | return 1; |
| | 386 | } |
| | 387 | else |
| | 388 | return 1; |
| | 389 | } |
| | 390 | |
| | 391 | if((NULL != vPtr->vmod_data) && !(mptr->m_flags & m_flag_open)) |
| | 392 | { |
| | 393 | /* If the door/viewport is closed... */ |
| | 394 | /* Branch to this vPtr */ |
| | 395 | /* else vPtr++; */ |
| | 396 | vPtr = vPtr->vmod_data->vmodidata_ptr; |
| | 397 | continue; |
| | 398 | } |
| | 399 | } |
| | 400 | |
| | 401 | vPtr++; |
| | 402 | } |
| | 403 | |
| | 404 | return 0; |
| | 405 | } |
| | 406 | |
| | 407 | static void PrintName(char *name) |
| | 408 | { |
| | 409 | char m_name[5]; |
| | 410 | |
| | 411 | m_name[0] = name[0]; |
| | 412 | m_name[1] = name[1]; |
| | 413 | m_name[2] = name[2]; |
| | 414 | m_name[3] = name[3]; |
| | 415 | m_name[4] = '\0'; |
| | 416 | printf("%s",m_name); |
| | 417 | } |
| | 418 | |
| | 419 | // Convert MREF name to MREF pointer |
| | 420 | |
| | 421 | void ConvertModuleNameToPointer(MREF *mref_ptr, MODULE **m_array_ptr) |
| | 422 | { |
| | 423 | /* Set "null" names to null pointers */ |
| | 424 | |
| | 425 | if(!strncmp(mref_ptr->mref_name, "null", 4)) |
| | 426 | { |
| | 427 | mref_ptr->mref_ptr = NULL; |
| | 428 | return; |
| | 429 | } |
| | 430 | |
| | 431 | /* Search for the module with the same name */ |
| | 432 | |
| | 433 | while(*m_array_ptr) |
| | 434 | { |
| | 435 | MODULE *m_ptr = *m_array_ptr++; |
| | 436 | |
| | 437 | if(!strncmp(mref_ptr->mref_name, m_ptr->m_name, 5)) |
| | 438 | { |
| | 439 | /* |
| | 440 | printf(" found name "); |
| | 441 | PrintName(&m_ptr->m_name); |
| | 442 | printf(", ptr %u\n", m_ptr); |
| | 443 | */ |
| | 444 | |
| | 445 | mref_ptr->mref_ptr = m_ptr; |
| | 446 | return; |
| | 447 | } |
| | 448 | } |
| | 449 | |
| | 450 | /* If the name was not found, make this a null pointer */ |
| | 451 | mref_ptr->mref_ptr = NULL; |
| | 452 | } |
| | 453 | |
| | 454 | // Convert VMODIDATA.vmodidata_label names to VMODIDATA.vmodidata_ptr |
| | 455 | |
| | 456 | static void ConvertVModuleNameToPointer(VMODIDATA *vmodidata_ptr, VMODULE *v_array_ptr) |
| | 457 | { |
| | 458 | /* Set "null" names to null pointers */ |
| | 459 | |
| | 460 | if(!strncmp(vmodidata_ptr->vmodidata_label, "null", 4)) |
| | 461 | { |
| | 462 | vmodidata_ptr->vmodidata_ptr = NULL; |
| | 463 | return; |
| | 464 | } |
| | 465 | |
| | 466 | while(!v_array_ptr->end_module) |
| | 467 | { |
| | 468 | if(!strncmp(vmodidata_ptr->vmodidata_label, v_array_ptr->vmod_name, 4)) |
| | 469 | { |
| | 470 | /* |
| | 471 | printf(" found name "); |
| | 472 | PrintName(&v_array_ptr->vmod_name); |
| | 473 | printf(", ptr %u\n", v_array_ptr); |
| | 474 | */ |
| | 475 | |
| | 476 | vmodidata_ptr->vmodidata_ptr = v_array_ptr; |
| | 477 | return; |
| | 478 | } |
| | 479 | |
| | 480 | v_array_ptr++; |
| | 481 | } |
| | 482 | |
| | 483 | vmodidata_ptr->vmodidata_ptr = v_array_ptr->end_module ? v_array_ptr : NULL; |
| | 484 | } |
| | 485 | |
| | 486 | /* |
| | 487 | |
| | 488 | VMODIDATA is the data associated with VMODI, the VMODULE instruction. Some |
| | 489 | of the data items are names which need to be converted to pointers. |
| | 490 | |
| | 491 | */ |
| | 492 | |
| | 493 | static void PreprocessVMODIDATA(VMODULE *v_ptr) |
| | 494 | { |
| | 495 | #define vm_flag_gotptrs 0x00000001 /* VMODULE references have been converted from names to pointers */ |
| | 496 | |
| | 497 | VMODULE *v_array_ptr = v_ptr; |
| | 498 | |
| | 499 | while(!v_ptr->end_module) |
| | 500 | { |
| | 501 | if((NULL != v_ptr->vmod_data) && !(v_ptr->vmod_flags & vm_flag_gotptrs)) |
| | 502 | { |
| | 503 | ConvertVModuleNameToPointer(v_ptr->vmod_data, v_array_ptr); |
| | 504 | v_ptr->vmod_flags |= vm_flag_gotptrs; |
| | 505 | } |
| | 506 | |
| | 507 | v_ptr++; |
| | 508 | } |
| | 509 | } |
| | 510 | |
| | 511 | /* |
| | 512 | The Module Preprocessor |
| | 513 | |
| | 514 | Pass the array of pointers to modules. |
| | 515 | This function creates module indices and converts names into pointers. |
| | 516 | */ |
| | 517 | |
| | 518 | void PreprocessModuleArray() |
| | 519 | { |
| | 520 | MODULE **m_array_ptr = MainScene.sm_marray; |
| | 521 | ModuleArraySize = 0; |
| | 522 | #define m_flag_gotptrs 0x00000002 /* Module references have been converted from names to pointers */ |
| | 523 | |
| | 524 | while(*m_array_ptr) |
| | 525 | { |
| | 526 | MODULE *m_ptr = *m_array_ptr; |
| | 527 | |
| | 528 | m_ptr->m_index = ModuleArraySize++; |
| | 529 | |
| | 530 | /* |
| | 531 | printf("\nModule %u, ", m_ptr); |
| | 532 | PrintName(&m_ptr->m_name); |
| | 533 | printf(", index %d\n", m_ptr->m_index); |
| | 534 | printf(" (vptr = "); |
| | 535 | PrintName(&m_ptr->m_vptr.mref_name); |
| | 536 | printf(")\n"); |
| | 537 | */ |
| | 538 | |
| | 539 | /* Convert module references from names to pointers */ |
| | 540 | |
| | 541 | if(m_ptr->m_vmptr && !(m_ptr->m_flags & m_flag_gotptrs)) |
| | 542 | { |
| | 543 | /* Convert VMODIDATA names to pointers */ |
| | 544 | PreprocessVMODIDATA(m_ptr->m_vmptr); |
| | 545 | /* Tell the module that its names are now pointers */ |
| | 546 | |
| | 547 | m_ptr->m_flags |= m_flag_gotptrs; |
| | 548 | } |
| | 549 | |
| | 550 | m_array_ptr++; |
| | 551 | } |
| | 552 | |
| | 553 | ModuleCurrVisArray = malloc(ModuleArraySize); |
| | 554 | |
| | 555 | if (NULL == ModuleCurrVisArray) |
| | 556 | { |
| | 557 | printf("GetModuleVisArrays() failed\n"); |
| | 558 | } |
| | 559 | else |
| | 560 | { |
| | 561 | int i; |
| | 562 | for(i = 0; i < ModuleArraySize; i++) |
| | 563 | ModuleCurrVisArray[i] = 0; |
| | 564 | } |
| | 565 | |
| | 566 | //printf("visibility arrays ok, size %d\n", ModuleArraySize); |
| | 567 | } |
| | 568 | |
| | 569 | int IsAIModuleVisibleFromAIModule(AIMODULE *source, AIMODULE *target) |
| | 570 | { |
| | 571 | if ((source == NULL) || (target == NULL)) |
| | 572 | return 0; |
| | 573 | else if (source == target) |
| | 574 | return 1; |
| | 575 | else |
| | 576 | { |
| | 577 | MODULE **sourceModulelistPtr = source->m_module_ptrs; |
| | 578 | |
| | 579 | while(*sourceModulelistPtr) |
| | 580 | { |
| | 581 | MODULE **targetModulelistPtr = target->m_module_ptrs; |
| | 582 | |
| | 583 | while(*targetModulelistPtr) |
| | 584 | { |
| | 585 | if (IsModuleVisibleFromModule(*sourceModulelistPtr,*targetModulelistPtr)) |
| | 586 | return 1; |
| | 587 | |
| | 588 | targetModulelistPtr++; |
| | 589 | } |
| | 590 | |
| | 591 | sourceModulelistPtr++; |
| | 592 | } |
| | 593 | |
| | 594 | return 0; |
| | 595 | } |
| | 596 | } |
| | 597 | |
| | 598 | void DeallocateModules() |
| | 599 | { |
| | 600 | int i = 0; |
| | 601 | |
| | 602 | if(NULL != MainScene.sm_marray) |
| | 603 | { |
| | 604 | MODULE **m_arrayPtr = MainScene.sm_marray; |
| | 605 | |
| | 606 | while (*m_arrayPtr) |
| | 607 | { |
| | 608 | MODULE * this_mod = *m_arrayPtr++; |
| | 609 | |
| | 610 | free(this_mod->m_mapptr); |
| | 611 | free(this_mod->name); |
| | 612 | |
| | 613 | if(NULL != this_mod->m_vmptr) |
| | 614 | { |
| | 615 | VMODULE *temp = this_mod->m_vmptr; |
| | 616 | |
| | 617 | while(!temp->end_module) |
| | 618 | { |
| | 619 | free(temp->vmod_data); |
| | 620 | temp++; |
| | 621 | } |
| | 622 | |
| | 623 | free(this_mod->m_vmptr); |
| | 624 | } |
| | 625 | |
| | 626 | free(this_mod->m_lightarray); |
| | 627 | } |
| | 628 | |
| | 629 | free(MainScene.sm_marray); |
| | 630 | MainScene.sm_marray = NULL; |
| | 631 | } |
| | 632 | |
| | 633 | free(MainScene.sm_module); |
| | 634 | MainScene.sm_module = NULL; |
| | 635 | |
| | 636 | for(i=0; i < AIModuleArraySize; i++) |
| | 637 | { |
| | 638 | AIMODULE* aim = &AIModuleArray[i]; |
| | 639 | WAYPOINT_HEADER* wh = aim->m_waypoints; |
| | 640 | |
| | 641 | free(aim->m_link_ptrs); |
| | 642 | free(aim->m_module_ptrs); |
| | 643 | |
| | 644 | if(NULL != wh) |
| | 645 | { |
| | 646 | int j = 0; |
| | 647 | |
| | 648 | for(; j < wh->num_waypoints; j++) |
| | 649 | { |
| | 650 | WAYPOINT_VOLUME* wv = &wh->first_waypoint[j]; |
| | 651 | free(wv->first_link); |
| | 652 | } |
| | 653 | |
| | 654 | free(wh->first_waypoint); |
| | 655 | free(wh); |
| | 656 | } |
| | 657 | } |
| | 658 | |
| | 659 | free(AIModuleArray); |
| | 660 | AIModuleArray = NULL; |
| | 661 | |
| | 662 | free(ModuleCurrVisArray); |
| | 663 | ModuleCurrVisArray = NULL; |
| | 664 | } |