//Uses a recursive method to elimate adjacent tiles of structure information. //The code will attempt to delete the current mapindex, then search using this method: //1) if there isn't structure info here, return. //2) if there is structure info here, delete it now. //3) KillBuilding at x-1, y. //4) KillBuilding at x , y-1. //5) KillBuilding at x+1, y. //6) KillBuilding at x , y+1. void KillBuilding( UINT32 iMapIndex ) { BOOLEAN fFound = FALSE; if( !gfBasement ) fFound |= RemoveAllRoofsOfTypeRange( iMapIndex, FIRSTTEXTURE, LASTITEM ); fFound |= RemoveAllLandsOfTypeRange( iMapIndex, FIRSTFLOOR, LASTFLOOR ); EraseBuilding( iMapIndex ); gubWorldRoomInfo[ iMapIndex ] = 0; if( !fFound ) { if( gfBasement ) RebuildRoof( iMapIndex, 0 ); return; } if( GridNoOnVisibleWorldTile( (UINT16)( iMapIndex - WORLD_COLS ) ) ) KillBuilding( iMapIndex - WORLD_COLS ); if( GridNoOnVisibleWorldTile( (UINT16)( iMapIndex + WORLD_COLS ) ) ) KillBuilding( iMapIndex + WORLD_COLS ); if( GridNoOnVisibleWorldTile( (UINT16)( iMapIndex + 1 ) ) ) KillBuilding( iMapIndex + 1 ); if( GridNoOnVisibleWorldTile( (UINT16)( iMapIndex - 1 ) ) ) KillBuilding( iMapIndex - 1 ); if( gfBasement ) RebuildRoof( iMapIndex, 0 ); }
void SearchForOtherMembersWithinPitRadiusAndMakeThemFall( INT16 sGridNo, INT16 sRadius ) { INT16 x, y, sNewGridNo; UINT8 ubID; SOLDIERTYPE *pSoldier; PlayJA2Sample( CAVE_COLLAPSE, RATE_11025, SoundVolume( HIGHVOLUME, sGridNo ), 1, SoundDir( sGridNo ) ); for( y = -sRadius; y <= sRadius; y++ ) for( x = -sRadius; x <= sRadius; x++ ) { sNewGridNo = sGridNo + y * WORLD_COLS + x; //Validate gridno location, and check if there are any mercs here. If there are //any mercs, we want them to fall below. The exitgrid already exists at this location if( GridNoOnVisibleWorldTile( sNewGridNo ) ) { // Check if buddy exists here..... ubID = WhoIsThere2( sNewGridNo, 0 ); if ( ubID != NOBODY ) { // OK, make guy fall... // Set data to look for exit grid.... pSoldier = MercPtrs[ ubID ]; pSoldier->uiPendingActionData4 = sNewGridNo; EVENT_InitNewSoldierAnim( pSoldier, FALL_INTO_PIT, 0 , FALSE ); } } } }
int LegalNPCDestination(SOLDIERTYPE *pSoldier, INT16 sGridno, UINT8 ubPathMode, UINT8 ubWaterOK, UINT8 fFlags) { BOOLEAN fSkipTilesWithMercs; if ((sGridno < 0) || (sGridno >= GRIDSIZE)) { #ifdef RECORDNET fprintf(NetDebugFile,"LegalNPC->sDestination: ERROR - rcvd invalid gridno %d",gridno); #endif #ifdef BETAVERSION NumMessage("LegalNPC->sDestination: ERROR - rcvd invalid gridno ",gridno); #endif return(FALSE); } // return false if gridno on different level from merc if ( GridNoOnVisibleWorldTile( pSoldier->sGridNo ) && gpWorldLevelData[ pSoldier->sGridNo ].sHeight != gpWorldLevelData[ sGridno ].sHeight ) { return( FALSE ); } // skip mercs if turnbased and adjacent AND not doing an IGNORE_PATH check (which is used almost exclusively by GoAsFarAsPossibleTowards) fSkipTilesWithMercs = (gfTurnBasedAI && ubPathMode != IGNORE_PATH && SpacesAway( pSoldier->sGridNo, sGridno ) == 1 ); // if this gridno is an OK destination // AND the gridno is NOT in a tear-gassed tile when we have no gas mask // AND someone is NOT already standing there // AND we're NOT already standing at that gridno // AND the gridno hasn't been black-listed for us // Nov 28 98: skip people in destination tile if in turnbased if ( ( NewOKDestination(pSoldier, sGridno, fSkipTilesWithMercs, pSoldier->bLevel ) ) && ( !InGas( pSoldier, sGridno ) ) && ( sGridno != pSoldier->sGridNo ) && ( sGridno != pSoldier->sBlackList ) ) /* if ( ( NewOKDestination(pSoldier, sGridno, FALSE, pSoldier->bLevel ) ) && ( !(gpWorldLevelData[ sGridno ].ubExtFlags[0] & (MAPELEMENT_EXT_SMOKE | MAPELEMENT_EXT_TEARGAS | MAPELEMENT_EXT_MUSTARDGAS)) || ( pSoldier->inv[ HEAD1POS ].usItem == GASMASK || pSoldier->inv[ HEAD2POS ].usItem == GASMASK ) ) && ( sGridno != pSoldier->sGridNo ) && ( sGridno != pSoldier->sBlackList ) )*/ /* if ( ( NewOKDestination(pSoldier,sGridno,ALLPEOPLE, pSoldier->bLevel ) ) && ( !(gpWorldLevelData[ sGridno ].ubExtFlags[0] & (MAPELEMENT_EXT_SMOKE | MAPELEMENT_EXT_TEARGAS | MAPELEMENT_EXT_MUSTARDGAS)) || ( pSoldier->inv[ HEAD1POS ].usItem == GASMASK || pSoldier->inv[ HEAD2POS ].usItem == GASMASK ) ) && ( sGridno != pSoldier->sGridNo ) && ( sGridno != pSoldier->sBlackList ) ) */ { // if water's a problem, and gridno is in a water tile (bridges are OK) if (!ubWaterOK && Water(sGridno)) return(FALSE); // passed all checks, now try to make sure we can get there! switch (ubPathMode) { // if finding a path wasn't asked for (could have already been done, // for example), don't bother case IGNORE_PATH : return(TRUE); case ENSURE_PATH : if ( FindBestPath( pSoldier, sGridno, pSoldier->bLevel, WALKING, COPYROUTE, fFlags ) ) { return(TRUE); // legal destination } else // got this far, but found no clear path, { // so test fails return(FALSE); } // *** NOTE: movement mode hardcoded to WALKING !!!!! case ENSURE_PATH_COST: return(PlotPath(pSoldier,sGridno,FALSE,FALSE,FALSE,WALKING,FALSE,FALSE,0)); default : #ifdef BETAVERSION NumMessage("LegalNPC->sDestination: ERROR - illegal pathMode = ",ubPathMode); #endif return(FALSE); } } else // something failed - didn't even have to test path return(FALSE); // illegal destination }
BOOLEAN HandleNextTile( SOLDIERTYPE *pSoldier, INT8 bDirection, INT16 sGridNo, INT16 sFinalDestTile ) { INT8 bBlocked; INT16 bOverTerrainType; // Check for blocking if in realtime ///if ( ( gTacticalStatus.uiFlags & REALTIME ) || !( gTacticalStatus.uiFlags & INCOMBAT ) ) // ATE: If not on visible tile, return clear ( for path out of map ) if ( !GridNoOnVisibleWorldTile( sGridNo ) ) { return( TRUE ); } // If animation state is crow, iall is clear if ( pSoldier->usAnimState == CROW_FLY ) { return( TRUE ); } { bBlocked = TileIsClear( pSoldier, bDirection, sGridNo, pSoldier->bLevel ); // Check if we are blocked... if ( bBlocked != MOVE_TILE_CLEAR ) { // Is the next gridno our destination? // OK: Let's check if we are NOT walking off screen if ( sGridNo == sFinalDestTile && pSoldier->ubWaitActionToDo == 0 && (pSoldier->bTeam == gbPlayerNum || pSoldier->sAbsoluteFinalDestination == NOWHERE) ) { // Yah, well too bad, stop here. SetFinalTile( pSoldier, pSoldier->sGridNo, FALSE ); return( FALSE ); } // CHECK IF they are stationary else if ( bBlocked == MOVE_TILE_STATIONARY_BLOCKED ) { // Stationary, { INT16 sOldFinalDest; // Maintain sFinalDest.... sOldFinalDest = pSoldier->sFinalDestination; #ifdef JA2BETAVERSION if ( gTacticalStatus.uiFlags & INCOMBAT ) { OutputDebugInfoForTurnBasedNextTileWaiting( pSoldier ); } #endif EVENT_StopMerc( pSoldier, pSoldier->sGridNo, pSoldier->bDirection ); // Restore... pSoldier->sFinalDestination = sOldFinalDest; SetDelayedTileWaiting( pSoldier, sGridNo, 1 ); return( FALSE ); } } else { { INT16 sOldFinalDest; // Maintain sFinalDest.... sOldFinalDest = pSoldier->sFinalDestination; #ifdef JA2BETAVERSION if ( gTacticalStatus.uiFlags & INCOMBAT ) { OutputDebugInfoForTurnBasedNextTileWaiting( pSoldier ); } #endif EVENT_StopMerc( pSoldier, pSoldier->sGridNo, pSoldier->bDirection ); // Restore... pSoldier->sFinalDestination = sOldFinalDest; // Setting to two means: try and wait until this tile becomes free.... SetDelayedTileWaiting( pSoldier, sGridNo, 100 ); } return( FALSE ); } } else { // Mark this tile as reserverd ( until we get there! ) if ( !( (gTacticalStatus.uiFlags & TURNBASED) && (gTacticalStatus.uiFlags & INCOMBAT) ) ) { MarkMovementReserved( pSoldier, sGridNo ); } bOverTerrainType = GetTerrainType( sGridNo ); // Check if we are going into water! if ( bOverTerrainType == LOW_WATER || bOverTerrainType == MED_WATER || bOverTerrainType == DEEP_WATER ) { // Check if we are of prone or crawl height and change stance accordingly.... switch( gAnimControl[ pSoldier->usAnimState ].ubHeight ) { case ANIM_PRONE: case ANIM_CROUCH: // Change height to stand pSoldier->fContinueMoveAfterStanceChange = TRUE; SendChangeSoldierStanceEvent( pSoldier, ANIM_STAND ); break; } // Check animation // Change to walking if ( pSoldier->usAnimState == RUNNING ) { ChangeSoldierState( pSoldier, WALKING, 0 , FALSE ); } } } } return( TRUE ); }