123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570 |
- #ifdef PRECOMPILEDHEADERS
- #include "Tactical All.h"
- #else
- #include <stdio.h>
- #include "debug.h"
- #include "wcheck.h"
- #include "worlddef.h"
- #include "worldman.h"
- #include "structure wrap.h"
- #include "isometric utils.h"
- #include "worldman.h"
- #include "overhead.h"
- #include "renderworld.h"
- #include "strategicmap.h"
- #include "rotting corpses.h"
- #endif
- extern BOOLEAN DoesSAMExistHere( INT16 sSectorX, INT16 sSectorY, INT16 sSectorZ, INT16 sGridNo );
- BOOLEAN IsFencePresentAtGridno( INT16 sGridNo )
- {
- if ( FindStructure( sGridNo, STRUCTURE_ANYFENCE ) != NULL )
- {
- return( TRUE );
- }
- return( FALSE );
- }
- BOOLEAN IsRoofPresentAtGridno( INT16 sGridNo )
- {
- if ( FindStructure( sGridNo, STRUCTURE_ROOF ) != NULL )
- {
- return( TRUE );
- }
- return( FALSE );
- }
- BOOLEAN IsJumpableFencePresentAtGridno( INT16 sGridNo )
- {
- STRUCTURE * pStructure;
- pStructure = FindStructure( sGridNo, STRUCTURE_OBSTACLE );
- if ( pStructure )
- {
- if ( pStructure->fFlags & STRUCTURE_FENCE && !(pStructure->fFlags & STRUCTURE_SPECIAL) )
- {
- return( TRUE );
- }
- if ( pStructure->pDBStructureRef->pDBStructure->ubArmour == MATERIAL_SANDBAG && StructureHeight( pStructure ) < 2 )
- {
- return( TRUE );
- }
- }
- return( FALSE );
- }
- BOOLEAN IsDoorPresentAtGridno( INT16 sGridNo )
- {
- if ( FindStructure( sGridNo, STRUCTURE_ANYDOOR ) != NULL )
- {
- return( TRUE );
- }
- return( FALSE );
- }
- BOOLEAN IsTreePresentAtGridno( INT16 sGridNo )
- {
- if ( FindStructure( sGridNo, STRUCTURE_TREE ) != NULL )
- {
- return( TRUE );
- }
- return( FALSE );
- }
- LEVELNODE *IsWallPresentAtGridno( INT16 sGridNo )
- {
- LEVELNODE *pNode = NULL;
- STRUCTURE * pStructure;
- pStructure = FindStructure( sGridNo, STRUCTURE_WALLSTUFF );
- if ( pStructure != NULL )
- {
- pNode = FindLevelNodeBasedOnStructure( sGridNo, pStructure );
- }
- return( pNode );
- }
- LEVELNODE *GetWallLevelNodeOfSameOrientationAtGridno( INT16 sGridNo, INT8 ubOrientation )
- {
- LEVELNODE *pNode = NULL;
- STRUCTURE * pStructure;
- pStructure = FindStructure( sGridNo, STRUCTURE_WALLSTUFF );
- while ( pStructure != NULL )
- {
- // Check orientation
- if ( pStructure->ubWallOrientation == ubOrientation )
- {
- pNode = FindLevelNodeBasedOnStructure( sGridNo, pStructure );
- return( pNode );
- }
- pStructure = FindNextStructure( pStructure, STRUCTURE_WALLSTUFF );
- }
- return( NULL );
- }
- LEVELNODE *GetWallLevelNodeAndStructOfSameOrientationAtGridno( INT16 sGridNo, INT8 ubOrientation, STRUCTURE **ppStructure )
- {
- LEVELNODE *pNode = NULL;
- STRUCTURE * pStructure, * pBaseStructure;
- (*ppStructure) = NULL;
- pStructure = FindStructure( sGridNo, STRUCTURE_WALLSTUFF );
- while ( pStructure != NULL )
- {
- // Check orientation
- if ( pStructure->ubWallOrientation == ubOrientation )
- {
- pBaseStructure = FindBaseStructure( pStructure );
- if (pBaseStructure)
- {
- pNode = FindLevelNodeBasedOnStructure( pBaseStructure->sGridNo, pBaseStructure );
- (*ppStructure) = pBaseStructure;
- return( pNode );
- }
- }
- pStructure = FindNextStructure( pStructure, STRUCTURE_WALLSTUFF );
- }
- return( NULL );
- }
- BOOLEAN IsDoorVisibleAtGridNo( INT16 sGridNo )
- {
- STRUCTURE * pStructure;
- INT16 sNewGridNo;
- pStructure = FindStructure( sGridNo, STRUCTURE_ANYDOOR );
- if ( pStructure != NULL )
- {
- // Check around based on orientation
- switch( pStructure->ubWallOrientation )
- {
- case INSIDE_TOP_LEFT:
- case OUTSIDE_TOP_LEFT:
- // Here, check north direction
- sNewGridNo = NewGridNo( sGridNo, DirectionInc( NORTH ) );
- if ( IsRoofVisible2( sNewGridNo ) )
- {
- // OK, now check south, if true, she's not visible
- sNewGridNo = NewGridNo( sGridNo, DirectionInc( SOUTH ) );
- if ( IsRoofVisible2( sNewGridNo ) )
- {
- return( FALSE );
- }
- }
- break;
- case INSIDE_TOP_RIGHT:
- case OUTSIDE_TOP_RIGHT:
- // Here, check west direction
- sNewGridNo = NewGridNo( sGridNo, DirectionInc( WEST ) );
- if ( IsRoofVisible2( sNewGridNo ) )
- {
- // OK, now check south, if true, she's not visible
- sNewGridNo = NewGridNo( sGridNo, DirectionInc( EAST ) );
- if ( IsRoofVisible2( sNewGridNo ) )
- {
- return( FALSE );
- }
- }
- break;
- }
- }
- // Return true here, even if she does not exist
- return( TRUE );
- }
- BOOLEAN DoesGridnoContainHiddenStruct( INT16 sGridNo, BOOLEAN *pfVisible )
- {
- // ATE: These are ignored now - always return false
- //STRUCTURE *pStructure;
- //pStructure = FindStructure( sGridNo, STRUCTURE_HIDDEN );
- //if ( pStructure != NULL )
- //{
- // if ( !(gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REVEALED ) && !(gTacticalStatus.uiFlags&SHOW_ALL_MERCS) )
- // {
- // *pfVisible = FALSE;
- // }
- // else
- // {
- // *pfVisible = TRUE;
- // }//
- //
- // return( TRUE );
- //}
- return( FALSE );
- }
- BOOLEAN IsHiddenStructureVisible( INT16 sGridNo, UINT16 usIndex )
- {
- // Check if it's a hidden struct and we have not revealed anything!
- if ( gTileDatabase[ usIndex ].uiFlags & HIDDEN_TILE )
- {
- if ( !(gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REVEALED ) && !(gTacticalStatus.uiFlags&SHOW_ALL_MERCS) )
- {
- // Return false
- return( FALSE );
- }
- }
- return( TRUE );
- }
- BOOLEAN WallExistsOfTopLeftOrientation( INT16 sGridNo )
- {
- // CJC: changing to search only for normal walls, July 16, 1998
- STRUCTURE * pStructure;
- pStructure = FindStructure( sGridNo, STRUCTURE_WALL );
- while ( pStructure != NULL )
- {
- // Check orientation
- if ( pStructure->ubWallOrientation == INSIDE_TOP_LEFT || pStructure->ubWallOrientation == OUTSIDE_TOP_LEFT )
- {
- return( TRUE );
- }
-
- pStructure = FindNextStructure( pStructure, STRUCTURE_WALL );
- }
- return( FALSE );
- }
- BOOLEAN WallExistsOfTopRightOrientation( INT16 sGridNo )
- {
- // CJC: changing to search only for normal walls, July 16, 1998
- STRUCTURE * pStructure;
- pStructure = FindStructure( sGridNo, STRUCTURE_WALL );
- while ( pStructure != NULL )
- {
- // Check orientation
- if ( pStructure->ubWallOrientation == INSIDE_TOP_RIGHT || pStructure->ubWallOrientation == OUTSIDE_TOP_RIGHT )
- {
- return( TRUE );
- }
- pStructure = FindNextStructure( pStructure, STRUCTURE_WALL );
- }
- return( FALSE );
- }
- BOOLEAN WallOrClosedDoorExistsOfTopLeftOrientation( INT16 sGridNo )
- {
- STRUCTURE * pStructure;
- pStructure = FindStructure( sGridNo, STRUCTURE_WALLSTUFF );
- while ( pStructure != NULL )
- {
- // skip it if it's an open door
- if ( ! ( ( pStructure->fFlags & STRUCTURE_ANYDOOR ) && ( pStructure->fFlags & STRUCTURE_OPEN ) ) )
- {
- // Check orientation
- if ( pStructure->ubWallOrientation == INSIDE_TOP_LEFT || pStructure->ubWallOrientation == OUTSIDE_TOP_LEFT )
- {
- return( TRUE );
- }
- }
-
- pStructure = FindNextStructure( pStructure, STRUCTURE_WALLSTUFF );
- }
- return( FALSE );
- }
- BOOLEAN WallOrClosedDoorExistsOfTopRightOrientation( INT16 sGridNo )
- {
- STRUCTURE * pStructure;
- pStructure = FindStructure( sGridNo, STRUCTURE_WALLSTUFF );
- while ( pStructure != NULL )
- {
- // skip it if it's an open door
- if ( ! ( ( pStructure->fFlags & STRUCTURE_ANYDOOR ) && ( pStructure->fFlags & STRUCTURE_OPEN ) ) )
- {
- // Check orientation
- if ( pStructure->ubWallOrientation == INSIDE_TOP_RIGHT || pStructure->ubWallOrientation == OUTSIDE_TOP_RIGHT )
- {
- return( TRUE );
- }
- }
-
- pStructure = FindNextStructure( pStructure, STRUCTURE_WALLSTUFF );
- }
- return( FALSE );
- }
- BOOLEAN OpenRightOrientedDoorWithDoorOnRightOfEdgeExists( INT16 sGridNo )
- {
- STRUCTURE * pStructure;
- pStructure = FindStructure( sGridNo, STRUCTURE_ANYDOOR );
- while ( pStructure != NULL && (pStructure->fFlags & STRUCTURE_OPEN) )
- {
- // Check orientation
- if ( pStructure->ubWallOrientation == INSIDE_TOP_RIGHT || pStructure->ubWallOrientation == OUTSIDE_TOP_RIGHT )
- {
- if ( (pStructure->fFlags & STRUCTURE_DOOR) || (pStructure->fFlags & STRUCTURE_DDOOR_RIGHT) )
- {
- return( TRUE );
- }
- }
-
- pStructure = FindNextStructure( pStructure, STRUCTURE_ANYDOOR );
- }
- return( FALSE );
- }
- BOOLEAN OpenLeftOrientedDoorWithDoorOnLeftOfEdgeExists( INT16 sGridNo )
- {
- STRUCTURE * pStructure;
- pStructure = FindStructure( sGridNo, STRUCTURE_ANYDOOR );
- while ( pStructure != NULL && (pStructure->fFlags & STRUCTURE_OPEN) )
- {
- // Check orientation
- if ( pStructure->ubWallOrientation == INSIDE_TOP_LEFT || pStructure->ubWallOrientation == OUTSIDE_TOP_LEFT )
- {
- if ( (pStructure->fFlags & STRUCTURE_DOOR) || (pStructure->fFlags & STRUCTURE_DDOOR_LEFT) )
- {
- return( TRUE );
- }
- }
-
- pStructure = FindNextStructure( pStructure, STRUCTURE_ANYDOOR );
- }
- return( FALSE );
- }
- STRUCTURE * FindCuttableWireFenceAtGridNo( INT16 sGridNo )
- {
- STRUCTURE * pStructure;
- pStructure = FindStructure( sGridNo, STRUCTURE_WIREFENCE );
- if (pStructure != NULL && pStructure->ubWallOrientation != NO_ORIENTATION && !(pStructure->fFlags & STRUCTURE_OPEN) )
- {
- return( pStructure );
- }
- return( NULL );
- }
- BOOLEAN CutWireFence( INT16 sGridNo )
- {
- STRUCTURE * pStructure;
-
- pStructure = FindCuttableWireFenceAtGridNo( sGridNo );
- if (pStructure)
- {
- pStructure = SwapStructureForPartnerAndStoreChangeInMap( sGridNo, pStructure );
- if (pStructure)
- {
- RecompileLocalMovementCosts( sGridNo );
- SetRenderFlags( RENDER_FLAG_FULL );
- return( TRUE );
- }
- }
- return( FALSE );
- }
- BOOLEAN IsCuttableWireFenceAtGridNo( INT16 sGridNo )
- {
- return( FindCuttableWireFenceAtGridNo( sGridNo ) != NULL );
- }
- BOOLEAN IsRepairableStructAtGridNo( INT16 sGridNo, UINT8 *pubID )
- {
- UINT8 ubMerc;
- // OK, first look for a vehicle....
- ubMerc = WhoIsThere2( sGridNo, 0 );
- if ( pubID != NULL )
- {
- (*pubID) = ubMerc;
- }
- if ( ubMerc != NOBODY )
- {
- if ( MercPtrs[ ubMerc ]->uiStatusFlags & SOLDIER_VEHICLE )
- {
- return( 2 );
- }
- }
- // Then for over a robot....
- // then for SAM site....
- if ( DoesSAMExistHere( gWorldSectorX, gWorldSectorY, gbWorldSectorZ, sGridNo ) )
- {
- return( 3 );
- }
- return( FALSE );
- }
- BOOLEAN IsRefuelableStructAtGridNo( INT16 sGridNo, UINT8 *pubID )
- {
- UINT8 ubMerc;
- // OK, first look for a vehicle....
- ubMerc = WhoIsThere2( sGridNo, 0 );
- if ( pubID != NULL )
- {
- (*pubID) = ubMerc;
- }
- if ( ubMerc != NOBODY )
- {
- if ( MercPtrs[ ubMerc ]->uiStatusFlags & SOLDIER_VEHICLE )
- {
- return( TRUE );
- }
- }
- return( FALSE );
- }
- BOOLEAN IsCutWireFenceAtGridNo( INT16 sGridNo )
- {
- STRUCTURE * pStructure;
- pStructure = FindStructure( sGridNo, STRUCTURE_WIREFENCE );
- if (pStructure != NULL && (pStructure->ubWallOrientation != NO_ORIENTATION) && (pStructure->fFlags & STRUCTURE_OPEN) )
- {
- return( TRUE );
- }
- return( FALSE );
- }
- INT16 FindDoorAtGridNoOrAdjacent( INT16 sGridNo )
- {
- STRUCTURE * pStructure;
- STRUCTURE * pBaseStructure;
- INT16 sTestGridNo;
- sTestGridNo = sGridNo;
- pStructure = FindStructure( sTestGridNo, STRUCTURE_ANYDOOR );
- if (pStructure)
- {
- pBaseStructure = FindBaseStructure( pStructure );
- return( pBaseStructure->sGridNo );
- }
- sTestGridNo = sGridNo + DirectionInc( NORTH );
- pStructure = FindStructure( sTestGridNo, STRUCTURE_ANYDOOR );
- if (pStructure)
- {
- pBaseStructure = FindBaseStructure( pStructure );
- return( pBaseStructure->sGridNo );
- }
- sTestGridNo = sGridNo + DirectionInc( WEST );
- pStructure = FindStructure( sTestGridNo, STRUCTURE_ANYDOOR );
- if (pStructure)
- {
- pBaseStructure = FindBaseStructure( pStructure );
- return( pBaseStructure->sGridNo );
- }
- return( NOWHERE );
- }
- BOOLEAN IsCorpseAtGridNo( INT16 sGridNo, UINT8 ubLevel )
- {
- if ( GetCorpseAtGridNo( sGridNo , ubLevel ) != NULL )
- {
- return( TRUE );
- }
- else
- {
- return( FALSE );
- }
- }
- BOOLEAN SetOpenableStructureToClosed( INT16 sGridNo, UINT8 ubLevel )
- {
- STRUCTURE * pStructure;
- STRUCTURE * pNewStructure;
- pStructure = FindStructure( sGridNo, STRUCTURE_OPENABLE );
- if ( !pStructure )
- {
- return( FALSE );
- }
- if ( pStructure->fFlags & STRUCTURE_OPEN )
- {
- pNewStructure = SwapStructureForPartner( sGridNo, pStructure );
- if ( pNewStructure != NULL)
- {
- RecompileLocalMovementCosts( sGridNo );
- SetRenderFlags( RENDER_FLAG_FULL );
- }
- }
- // else leave it as is!
- return( TRUE );
- }
|