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 ); }
void OutputDebugInfoForTurnBasedNextTileWaiting( SOLDIERTYPE * pSoldier ) { if ( (gTacticalStatus.uiFlags & INCOMBAT) && (pSoldier->usPathDataSize > 0) ) { UINT32 uiLoop; UINT16 usTemp; UINT16 usNewGridNo; usNewGridNo = NewGridNo( pSoldier->sGridNo, DirectionInc( (UINT8)pSoldier->usPathingData[ pSoldier->usPathIndex ] ) ); // provide more info!! DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String(" Soldier path size %d, index %d", pSoldier->usPathDataSize, pSoldier->usPathIndex ) ); DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String(" Who is at blocked gridno: %d", WhoIsThere2( usNewGridNo, pSoldier->bLevel ) ) ); for ( uiLoop = 0; uiLoop < pSoldier->usPathDataSize; uiLoop++ ) { if ( uiLoop > pSoldier->usPathIndex ) { usTemp = NewGridNo( usTemp, DirectionInc( (UINT8)pSoldier->usPathingData[ uiLoop ] ) ); DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String(" Soldier path[%d]: %d == gridno %d", uiLoop, pSoldier->usPathingData[uiLoop], usTemp ) ); } else if ( uiLoop == pSoldier->usPathIndex ) { usTemp = usNewGridNo; DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String(" Soldier path[%d]: %d == gridno %d", uiLoop, pSoldier->usPathingData[uiLoop], usTemp ) ); } else { DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String(" Soldier path[%d]: %d", uiLoop, pSoldier->usPathingData[uiLoop] ) ); } } } }
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 ); }
INT8 FindBestPatient( SOLDIERTYPE * pSoldier, BOOLEAN * pfDoClimb ) { UINT8 cnt, cnt2; INT32 bBestPriority = 0, sBestAdjGridNo = NOWHERE; INT32 sPatientGridNo = NOWHERE, sBestPatientGridNo = NOWHERE; INT16 sShortestPath = 1000, sPathCost, sOtherMedicPathCost; SOLDIERTYPE * pPatient; SOLDIERTYPE * pBestPatient = NULL; SOLDIERTYPE * pOtherMedic; INT8 bPatientPriority; UINT8 ubDirection; INT32 sAdjustedGridNo, sAdjacentGridNo, sOtherAdjacentGridNo; INT32 sClimbGridNo, sBestClimbGridNo = NOWHERE, sShortestClimbPath = 1000; BOOLEAN fClimbingNecessary; gubGlobalPathFlags = PATH_THROUGH_PEOPLE; // search for someone who needs aid cnt = gTacticalStatus.Team[ OUR_TEAM ].bFirstID; for ( pPatient = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ OUR_TEAM ].bLastID; cnt++,pPatient++) { if ( !(pPatient->bActive) || !(pPatient->bInSector) ) { continue; // NEXT!!! } if (pPatient->stats.bLife > 0 && pPatient->bBleeding && pPatient->ubServiceCount == 0) { if (pPatient->stats.bLife < OKLIFE) { bPatientPriority = 3; } else if (pPatient->stats.bLife < OKLIFE * 2) { bPatientPriority = 2; } else { bPatientPriority = 1; } if (bPatientPriority >= bBestPriority) { if ( !ClimbingNecessary( pSoldier, pPatient->sGridNo, pPatient->pathing.bLevel ) ) { sPatientGridNo = pPatient->sGridNo; sAdjacentGridNo = FindAdjacentGridEx( pSoldier, sPatientGridNo, &ubDirection, &sAdjustedGridNo, FALSE, FALSE ); if ( sAdjacentGridNo == -1 && gAnimControl[ pPatient->usAnimState ].ubEndHeight == ANIM_PRONE ) { // prone; could be the base tile is inaccessible but the rest isn't... for ( cnt2 = 0; cnt2 < NUM_WORLD_DIRECTIONS; cnt2++ ) { sPatientGridNo = pPatient->sGridNo + DirectionInc( cnt2 ); if ( WhoIsThere2( sPatientGridNo, pPatient->pathing.bLevel ) == pPatient->ubID ) { // patient is also here, try this location sAdjacentGridNo = FindAdjacentGridEx( pSoldier, sPatientGridNo, &ubDirection, &sAdjustedGridNo, FALSE, FALSE ); if ( sAdjacentGridNo != -1 ) { break; } } } } if (sAdjacentGridNo != -1) { if (sAdjacentGridNo == pSoldier->sGridNo) { sPathCost = 1; } else { sPathCost = PlotPath( pSoldier, sAdjacentGridNo, FALSE, FALSE, FALSE, RUNNING, FALSE, FALSE, 0); } if ( sPathCost != 0 ) { // we can get there... can anyone else? if ( pPatient->ubAutoBandagingMedic != NOBODY && pPatient->ubAutoBandagingMedic != pSoldier->ubID ) { // only switch to this patient if our distance is closer than // the other medic's pOtherMedic = MercPtrs[ pPatient->ubAutoBandagingMedic ]; sOtherAdjacentGridNo = FindAdjacentGridEx( pOtherMedic, sPatientGridNo, &ubDirection, &sAdjustedGridNo, FALSE, FALSE ); if (sOtherAdjacentGridNo != -1) { if (sOtherAdjacentGridNo == pOtherMedic->sGridNo) { sOtherMedicPathCost = 1; } else { sOtherMedicPathCost = PlotPath( pOtherMedic, sOtherAdjacentGridNo, FALSE, FALSE, FALSE, RUNNING, FALSE, FALSE, 0); } if (sPathCost >= sOtherMedicPathCost) { // this patient is best served by the merc moving to them now continue; } } } if (bPatientPriority == bBestPriority) { // compare path distances if ( sPathCost > sShortestPath ) { continue; } } sShortestPath = sPathCost; pBestPatient = pPatient; sBestPatientGridNo = sPatientGridNo; bBestPriority = bPatientPriority; sBestAdjGridNo = sAdjacentGridNo; } } } else { sClimbGridNo = NOWHERE; // see if guy on another building etc and we need to climb somewhere sPathCost = EstimatePathCostToLocation( pSoldier, pPatient->sGridNo, pPatient->pathing.bLevel, FALSE, &fClimbingNecessary, &sClimbGridNo ); // if we can get there if ( sPathCost != 0 && fClimbingNecessary && sPathCost < sShortestClimbPath ) { sBestClimbGridNo = sClimbGridNo; sShortestClimbPath = sPathCost; } } } } } gubGlobalPathFlags = 0; if (pBestPatient) { if (pBestPatient->ubAutoBandagingMedic != NOBODY) { // cancel that medic CancelAIAction( MercPtrs[ pBestPatient->ubAutoBandagingMedic ], TRUE ); } pBestPatient->ubAutoBandagingMedic = pSoldier->ubID; *pfDoClimb = FALSE; if ( CardinalSpacesAway( pSoldier->sGridNo, sBestPatientGridNo ) == 1 ) { pSoldier->aiData.usActionData = sBestPatientGridNo; return( AI_ACTION_GIVE_AID ); } else { pSoldier->aiData.usActionData = sBestAdjGridNo; return( AI_ACTION_GET_CLOSER ); } } else if (!TileIsOutOfBounds(sBestClimbGridNo)) { *pfDoClimb = TRUE; pSoldier->aiData.usActionData = sBestClimbGridNo; return( AI_ACTION_MOVE_TO_CLIMB ); } else { return( AI_ACTION_NONE ); } }
void SoldierTriesToContinueAlongPath(SOLDIERTYPE *pSoldier) { INT16 usNewGridNo,bAPCost; // turn off the flag now that we're going to do something about it... // ATE: USed to be redundent, now if called befroe NewDest can cause some side efects... // AdjustNoAPToFinishMove( pSoldier, FALSE ); if (pSoldier->bNewSituation == IS_NEW_SITUATION) { CancelAIAction(pSoldier,DONTFORCE); return; } if (pSoldier->usActionData >= NOWHERE) { CancelAIAction(pSoldier,DONTFORCE); return; } if (!NewOKDestination( pSoldier,pSoldier->usActionData, TRUE, pSoldier->bLevel )) { CancelAIAction(pSoldier,DONTFORCE); return; } if (IsActionAffordable(pSoldier)) { if (pSoldier->bActionInProgress == FALSE) { // start a move that didn't even get started before... // hope this works... NPCDoesAct(pSoldier); // perform the chosen action pSoldier->bActionInProgress = ExecuteAction(pSoldier); // if started, mark us as busy } else { // otherwise we shouldn't have to do anything(?) } } else { CancelAIAction(pSoldier,DONTFORCE); #ifdef TESTAI DebugMsg( TOPIC_JA2AI, DBG_LEVEL_3, String("Soldier (%d) HAS NOT ENOUGH AP to continue along path",pSoldier->ubID) ); #endif } usNewGridNo = NewGridNo( (UINT16)pSoldier->sGridNo, DirectionInc( (UINT8)pSoldier->usPathingData[ pSoldier->usPathIndex ] ) ); // Find out how much it takes to move here! bAPCost = EstimateActionPointCost( pSoldier, usNewGridNo, (INT8)pSoldier->usPathingData[ pSoldier->usPathIndex ], pSoldier->usUIMovementMode, (INT8) pSoldier->usPathIndex, (INT8) pSoldier->usPathDataSize ); if (pSoldier->bActionPoints >= bAPCost) { // seems to have enough points... NewDest(pSoldier,usNewGridNo); // maybe we didn't actually start the action last turn... pSoldier->bActionInProgress = TRUE; #ifdef TESTAI DebugMsg( TOPIC_JA2AI, DBG_LEVEL_3, String("Soldier (%d) continues along path",pSoldier->ubID) ); #endif } else { CancelAIAction(pSoldier,DONTFORCE); #ifdef TESTAI DebugMsg( TOPIC_JA2AI, DBG_LEVEL_3, String("Soldier (%d) HAS NOT ENOUGH AP to continue along path",pSoldier->ubID) ); #endif } }
INT16 InternalGoAsFarAsPossibleTowards(SOLDIERTYPE *pSoldier, INT16 sDesGrid, INT8 bReserveAPs, INT8 bAction, INT8 fFlags ) { INT16 sLoop,sAPCost; INT16 sTempDest,sGoToGrid; INT16 sOrigin; UINT16 usMaxDist; UINT8 ubDirection,ubDirsLeft,ubDirChecked[8],fFound = FALSE; INT8 bAPsLeft, fPathFlags; UINT8 ubRoomRequired = 0, ubTempRoom; if ( bReserveAPs == -1 ) { // default reserve points if ( CREATURE_OR_BLOODCAT( pSoldier ) ) { bReserveAPs = 0; } else { bReserveAPs = MAX_AP_CARRIED; } } sTempDest = -1; // obtain maximum roaming distance from soldier's sOrigin usMaxDist = RoamingRange(pSoldier,&sOrigin); if ( pSoldier->bOrders <= CLOSEPATROL && (pSoldier->bTeam == CIV_TEAM || pSoldier->ubProfile != NO_PROFILE ) ) { if ( InARoom( pSoldier->usPatrolGrid[0], &ubRoomRequired ) ) { // make sure this doesn't interfere with pathing for scripts if ( pSoldier->sAbsoluteFinalDestination != NOWHERE ) { ubRoomRequired = 0; } } } pSoldier->usUIMovementMode = DetermineMovementMode(pSoldier, bAction ); if ( pSoldier->usUIMovementMode == RUNNING && fFlags & FLAG_CAUTIOUS ) { pSoldier->usUIMovementMode = WALKING; } #ifdef DEBUGDECISIONS sprintf(tempstr,"%s wants to go towards %d (has range %d)",pSoldier->name,sDesGrid,usMaxDist); AIPopMessage(tempstr); #endif // if soldier is ALREADY at the desired destination, quit right away if (sDesGrid == pSoldier->sGridNo) { return(NOWHERE); } // don't try to approach go after noises or enemies actually in water // would be too easy to throw rocks in water, etc. & distract the AI if (Water(sDesGrid)) { return(NOWHERE); } fPathFlags = 0; if ( CREATURE_OR_BLOODCAT( pSoldier ) ) { /* if ( PythSpacesAway( pSoldier->sGridNo, sDesGrid ) <= PATH_CLOSE_RADIUS ) { // then do a limited range path search and see if we can get there gubNPCDistLimit = 10; if ( !LegalNPCDestination( pSoldier, sDesGrid, ENSURE_PATH, NOWATER, fPathFlags) ) { gubNPCDistLimit = 0; return( NOWHERE ); } else { // allow attempt to path without 'good enough' flag on gubNPCDistLimit = 0; } } else { */ fPathFlags = PATH_CLOSE_GOOD_ENOUGH; //} } // first step: try to find an OK destination at or near the desired gridno if (!LegalNPCDestination(pSoldier,sDesGrid,ENSURE_PATH,NOWATER,fPathFlags)) { #ifdef DEBUGDECISIONS AIPopMessage("destination Grid # itself not valid, looking around it"); #endif if ( CREATURE_OR_BLOODCAT( pSoldier ) ) { // we tried to get close, failed; abort! return( NOWHERE ); } else { // else look at the 8 nearest gridnos to sDesGrid for a valid destination // clear ubDirChecked flag for all 8 directions for (ubDirection = 0; ubDirection < 8; ubDirection++) ubDirChecked[ubDirection] = FALSE; ubDirsLeft = 8; // examine all 8 spots around 'sDesGrid' // keep looking while directions remain and a satisfactory one not found for (ubDirsLeft = 8; ubDirsLeft != 0; ubDirsLeft--) { if (fFound) { break; } // randomly select a direction which hasn't been 'checked' yet do { ubDirection = (UINT8) Random(8); } while (ubDirChecked[ubDirection]); ubDirChecked[ubDirection] = TRUE; // determine the gridno 1 tile away from current friend in this direction sTempDest = NewGridNo(sDesGrid,DirectionInc( (INT16)(ubDirection + 1) )); // if that's out of bounds, ignore it & check next direction if (sTempDest == sDesGrid) continue; if (LegalNPCDestination(pSoldier,sTempDest,ENSURE_PATH,NOWATER,0)) { fFound = TRUE; // found a spot #ifdef DEBUGDECISIONS AINumMessage("Found a spot! ubDirection = ",ubDirection + 1); #endif break; // stop checking in other directions } } if (!fFound) { #ifdef DEBUGDECISIONS AINumMessage("Couldn't find OK destination around grid #",sDesGrid); #endif return(NOWHERE); } // found a good grid #, this becomes our actual desired grid # sDesGrid = sTempDest; } } // HAVE FOUND AN OK destination AND PLOTTED A VALID BEST PATH TO IT #ifdef DEBUGDECISIONS AINumMessage("Chosen legal destination is gridno ",sDesGrid); AINumMessage("Tracing along path, pathRouteToGo = ",pSoldier->pathRouteToGo); #endif sGoToGrid = pSoldier->sGridNo; // start back where soldier is standing now sAPCost = 0; // initialize path cost counter // we'll only go as far along the plotted route as is within our // permitted roaming range, and we'll stop as soon as we're down to <= 5 APs for (sLoop = 0; sLoop < (pSoldier->usPathDataSize - pSoldier->usPathIndex); sLoop++) { // what is the next gridno in the path? //sTempDest = NewGridNo( sGoToGrid,DirectionInc( (INT16) (pSoldier->usPathingData[sLoop] + 1) ) ); sTempDest = NewGridNo( sGoToGrid,DirectionInc( (INT16) (pSoldier->usPathingData[sLoop]) ) ); //NumMessage("sTempDest = ",sTempDest); // this should NEVER be out of bounds if (sTempDest == sGoToGrid) { #ifdef BETAVERSION sprintf(tempstr,"GoAsFarAsPossibleTowards: ERROR - gridno along valid route is invalid! guynum %d, sTempDest = %d",pSoldier->ubID,sTempDest); #ifdef RECORDNET fprintf(NetDebugFile,"\n\t%s\n",tempstr); #endif PopMessage(tempstr); SaveGame(ERROR_SAVE); #endif break; // quit here, sGoToGrid is where we are going } // if this takes us beyond our permitted "roaming range" if (SpacesAway(sOrigin,sTempDest) > usMaxDist) break; // quit here, sGoToGrid is where we are going if ( ubRoomRequired ) { if ( !( InARoom( sTempDest, &ubTempRoom ) && ubTempRoom == ubRoomRequired ) ) { // quit here, limited by room! break; } } if ( (fFlags & FLAG_STOPSHORT) && SpacesAway( sDesGrid, sTempDest ) <= STOPSHORTDIST ) { break; // quit here, sGoToGrid is where we are going } // if this gridno is NOT a legal NPC destination // DONT'T test path again - that would replace the traced path! - Ian // NOTE: It's OK to go *THROUGH* water to try and get to the destination! if (!LegalNPCDestination(pSoldier,sTempDest,IGNORE_PATH,WATEROK,0)) break; // quit here, sGoToGrid is where we are going // CAN'T CALL PathCost() HERE! IT CALLS findBestPath() and overwrites // pathRouteToGo !!! Gotta calculate the cost ourselves - Ian // //ubAPsLeft = pSoldier->bActionPoints - PathCost(pSoldier,sTempDest,FALSE,FALSE,FALSE,FALSE,FALSE); if (gfTurnBasedAI) { // if we're just starting the "costing" process (first gridno) if (sLoop == 0) { /* // first, add any additional costs - such as intermediate animations, etc. switch(pSoldier->anitype[pSoldier->anim]) { // in theory, no NPC should ever be in one of these animations as // things stand (they don't medic anyone), but leave it for robustness case START_AID : case GIVING_AID : sAnimCost = AP_STOP_FIRST_AID; break; case TWISTOMACH : case COLLAPSED : sAnimCost = AP_GET_UP; break; case TWISTBACK : case UNCONSCIOUS : sAnimCost = (AP_ROLL_OVER + AP_GET_UP); break; default : sAnimCost = 0; } // this is our first cost sAPCost += sAnimCost; */ if (pSoldier->usUIMovementMode == RUNNING) { sAPCost += AP_START_RUN_COST; } } // ATE: Direction here? sAPCost += EstimateActionPointCost( pSoldier, sTempDest, (INT8) pSoldier->usPathingData[sLoop], pSoldier->usUIMovementMode, (INT8) sLoop, (INT8) pSoldier->usPathDataSize ); bAPsLeft = pSoldier->bActionPoints - sAPCost; } // if after this, we have <= 5 APs remaining, that's far enough, break out // (the idea is to preserve APs so we can crouch or react if // necessary, and benefit from the carry-over next turn if not needed) // This routine is NOT used by any GREEN AI, so such caution is warranted! if ( gfTurnBasedAI && (bAPsLeft < bReserveAPs) ) break; else { sGoToGrid = sTempDest; // we're OK up to here // if exactly 5 APs left, don't bother checking any further if ( gfTurnBasedAI && (bAPsLeft == bReserveAPs) ) break; } } // if it turned out we couldn't go even 1 tile towards the desired gridno if (sGoToGrid == pSoldier->sGridNo) { #ifdef DEBUGDECISIONS sprintf(tempstr,"%s will go NOWHERE, path doesn't meet criteria",pSoldier->name); AIPopMessage(tempstr); #endif return(NOWHERE); // then go nowhere } else { // possible optimization - stored path IS good if we're going all the way if (sGoToGrid == sDesGrid) { pSoldier->bPathStored = TRUE; pSoldier->sFinalDestination = sGoToGrid; } else if ( pSoldier->usPathIndex == 0 ) { // we can hack this surely! -- CJC pSoldier->bPathStored = TRUE; pSoldier->sFinalDestination = sGoToGrid; pSoldier->usPathDataSize = sLoop + 1; } #ifdef DEBUGDECISIONS ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_BETAVERSION, L"%d to %d with %d APs left", pSoldier->ubID, sGoToGrid, pSoldier->bActionPoints ); #endif return( sGoToGrid ); } }
BUILDING * GenerateBuilding( INT16 sDesiredSpot ) { UINT32 uiLoop; INT16 sTempGridNo, sNextTempGridNo, sVeryTemporaryGridNo; INT16 sStartGridNo, sCurrGridNo, sPrevGridNo = NOWHERE, sRightGridNo; INT8 bDirection, bTempDirection; BOOLEAN fFoundDir, fFoundWall; UINT32 uiChanceIn = ROOF_LOCATION_CHANCE; // chance of a location being considered INT16 sWallGridNo; INT8 bDesiredOrientation; INT8 bSkipSpots = 0; SOLDIERTYPE FakeSoldier; BUILDING * pBuilding; UINT8 ubBuildingID = 0; pBuilding = CreateNewBuilding( &ubBuildingID ); if (!pBuilding) { return( NULL ); } // set up fake soldier for location testing memset( &FakeSoldier, 0, sizeof( SOLDIERTYPE ) ); FakeSoldier.sGridNo = sDesiredSpot; FakeSoldier.bLevel = 1; FakeSoldier.bTeam = 1; #ifdef ROOF_DEBUG memset( gsCoverValue, 0x7F, sizeof( INT16 ) * WORLD_MAX ); #endif // Set reachable RoofReachableTest( sDesiredSpot, ubBuildingID ); // From sGridNo, search until we find a spot that isn't part of the building bDirection = NORTHWEST; sTempGridNo = sDesiredSpot; // using diagonal directions to hopefully prevent picking a // spot that while( (gpWorldLevelData[ sTempGridNo ].uiFlags & MAPELEMENT_REACHABLE ) ) { sNextTempGridNo = NewGridNo( sTempGridNo, DirectionInc( bDirection ) ); if ( sTempGridNo == sNextTempGridNo ) { // hit edge of map!??! return( NULL ); } else { sTempGridNo = sNextTempGridNo; } } // we've got our spot sStartGridNo = sTempGridNo; sCurrGridNo = sStartGridNo; sVeryTemporaryGridNo = NewGridNo( sCurrGridNo, DirectionInc( EAST ) ); if ( gpWorldLevelData[ sVeryTemporaryGridNo ].uiFlags & MAPELEMENT_REACHABLE ) { // go north first bDirection = NORTH; } else { // go that way (east) bDirection = EAST; } gpWorldLevelData[ sStartGridNo ].ubExtFlags[0] |= MAPELEMENT_EXT_ROOFCODE_VISITED; while( 1 ) { // if point to (2 clockwise) is not part of building and is not visited, // or is starting point, turn! sRightGridNo = NewGridNo( sCurrGridNo, DirectionInc( gTwoCDirection[ bDirection ] ) ); sTempGridNo = sRightGridNo; if ( ( ( !(gpWorldLevelData[ sTempGridNo ].uiFlags & MAPELEMENT_REACHABLE) && !(gpWorldLevelData[ sTempGridNo ].ubExtFlags[0] & MAPELEMENT_EXT_ROOFCODE_VISITED) ) || (sTempGridNo == sStartGridNo) ) && (sCurrGridNo != sStartGridNo) ) { bDirection = gTwoCDirection[ bDirection ]; // try in that direction continue; } // if spot ahead is part of building, turn sTempGridNo = NewGridNo( sCurrGridNo, DirectionInc( bDirection ) ); if ( gpWorldLevelData[ sTempGridNo ].uiFlags & MAPELEMENT_REACHABLE ) { // first search for a spot that is neither part of the building or visited // we KNOW that the spot in the original direction is blocked, so only loop 3 times bTempDirection = gTwoCDirection[ bDirection ]; fFoundDir = FALSE; for ( uiLoop = 0; uiLoop < 3; uiLoop++ ) { sTempGridNo = NewGridNo( sCurrGridNo, DirectionInc( bTempDirection ) ); if ( !(gpWorldLevelData[ sTempGridNo ].uiFlags & MAPELEMENT_REACHABLE) && !(gpWorldLevelData[ sTempGridNo ].ubExtFlags[0] & MAPELEMENT_EXT_ROOFCODE_VISITED) ) { // this is the way to go! fFoundDir = TRUE; break; } bTempDirection = gTwoCDirection[ bTempDirection ]; } if (!fFoundDir) { // now search for a spot that is just not part of the building bTempDirection = gTwoCDirection[ bDirection ]; fFoundDir = FALSE; for ( uiLoop = 0; uiLoop < 3; uiLoop++ ) { sTempGridNo = NewGridNo( sCurrGridNo, DirectionInc( bTempDirection ) ); if ( !(gpWorldLevelData[ sTempGridNo ].uiFlags & MAPELEMENT_REACHABLE) ) { // this is the way to go! fFoundDir = TRUE; break; } bTempDirection = gTwoCDirection[ bTempDirection ]; } if (!fFoundDir) { // WTF is going on? return( NULL ); } } bDirection = bTempDirection; // try in that direction continue; } // move ahead sPrevGridNo = sCurrGridNo; sCurrGridNo = sTempGridNo; sRightGridNo = NewGridNo( sCurrGridNo, DirectionInc( gTwoCDirection[ bDirection ] ) ); #ifdef ROOF_DEBUG if (gsCoverValue[sCurrGridNo] == 0x7F7F) { gsCoverValue[sCurrGridNo] = 1; } else if (gsCoverValue[sCurrGridNo] >= 0) { gsCoverValue[sCurrGridNo]++; } DebugAI( String( "Roof code visits %d", sCurrGridNo ) ); #endif if (sCurrGridNo == sStartGridNo) { // done break; } if ( !(gpWorldLevelData[ sCurrGridNo ].ubExtFlags[0] & MAPELEMENT_EXT_ROOFCODE_VISITED) ) { gpWorldLevelData[ sCurrGridNo ].ubExtFlags[0] |= MAPELEMENT_EXT_ROOFCODE_VISITED; // consider this location as possible climb gridno // there must be a regular wall adjacent to this for us to consider it a // climb gridno // if the direction is east or north, the wall would be in our gridno; // if south or west, the wall would be in the gridno two clockwise fFoundWall = FALSE; switch( bDirection ) { case NORTH: sWallGridNo = sCurrGridNo; bDesiredOrientation = OUTSIDE_TOP_RIGHT; break; case EAST: sWallGridNo = sCurrGridNo; bDesiredOrientation = OUTSIDE_TOP_LEFT; break; case SOUTH: sWallGridNo = (INT16) ( sCurrGridNo + DirectionInc( gTwoCDirection[ bDirection ] ) ); bDesiredOrientation = OUTSIDE_TOP_RIGHT; break; case WEST: sWallGridNo = (INT16) ( sCurrGridNo + DirectionInc( gTwoCDirection[ bDirection ] ) ); bDesiredOrientation = OUTSIDE_TOP_LEFT; break; default: // what the heck? return( NULL ); } if (bDesiredOrientation == OUTSIDE_TOP_LEFT) { if (WallExistsOfTopLeftOrientation( sWallGridNo )) { fFoundWall = TRUE; } } else { if (WallExistsOfTopRightOrientation( sWallGridNo )) { fFoundWall = TRUE; } } if (fFoundWall) { if (bSkipSpots > 0) { bSkipSpots--; } else if ( Random( uiChanceIn ) == 0 ) { // don't consider people as obstacles if ( NewOKDestination( &FakeSoldier, sCurrGridNo, FALSE, 0 ) ) { pBuilding->sUpClimbSpots[ pBuilding->ubNumClimbSpots ] = sCurrGridNo; pBuilding->sDownClimbSpots[ pBuilding->ubNumClimbSpots ] = sRightGridNo; pBuilding->ubNumClimbSpots++; if ( pBuilding->ubNumClimbSpots == MAX_CLIMBSPOTS_PER_BUILDING) { // gotta stop! return( pBuilding ); } // if location is added as a spot, reset uiChanceIn uiChanceIn = ROOF_LOCATION_CHANCE; #ifdef ROOF_DEBUG gsCoverValue[sCurrGridNo] = 99; #endif // skip the next spot bSkipSpots = 1; } else { // if location is not added, 100% chance of handling next location // and the next until we can add one uiChanceIn = 1; } } else { // didn't pick this location, so increase chance that next location // will be considered if (uiChanceIn > 2) { uiChanceIn--; } } } else { // can't select this spot if ( (sPrevGridNo != NOWHERE) && (pBuilding->ubNumClimbSpots > 0) ) { if ( pBuilding->sDownClimbSpots[ pBuilding->ubNumClimbSpots - 1 ] == sCurrGridNo ) { // unselect previous spot pBuilding->ubNumClimbSpots--; // overwrote a selected spot so go into automatic selection for later uiChanceIn = 1; #ifdef ROOF_DEBUG // reset marker gsCoverValue[sPrevGridNo] = 1; #endif } } // skip the next gridno bSkipSpots = 1; } } } // at end could prune # of locations if there are too many /* #ifdef ROOF_DEBUG SetRenderFlags( RENDER_FLAG_FULL ); RenderWorld(); RenderCoverDebug( ); InvalidateScreen( ); EndFrameBufferRender(); RefreshScreen( NULL ); #endif */ return( pBuilding ); }
void RevealRoofsAndItems(SOLDIERTYPE *pSoldier, UINT32 itemsToo, BOOLEAN fShowLocators, UINT8 ubLevel, BOOLEAN fForce ) { INT32 maincnt,markercnt,marker,tilesLeftToSee,prevmarker; UINT8 cnt; INT32 Inc[6],Dir[6]; INT8 itemVisible = FALSE; INT8 Blocking,twoMoreTiles,markerDir; INT8 nextDir=0; UINT8 who; //,itemIndex; // for each square checked UINT8 dir,range,Path2; //DBrot: More Rooms //UINT8 ubRoomNo; UINT16 usRoomNo; BOOLEAN fCheckForRooms = FALSE; ITEM_POOL *pItemPool; BOOLEAN fHiddenStructVisible; UINT8 ubMovementCost; BOOLEAN fTravelCostObs; BOOLEAN fGoneThroughDoor = FALSE; BOOLEAN fThroughWindow = FALSE; BOOLEAN fItemsQuoteSaid = FALSE; UINT16 usIndex; BOOLEAN fRevealItems = TRUE; BOOLEAN fStopRevealingItemsAfterThisTile = FALSE; INT8 bTallestStructureHeight; INT32 iDoorGridNo; STRUCTURE *pStructure, *pDummy; INT8 bStructHeight; INT8 bThroughWindowDirection; if ( pSoldier->flags.uiStatusFlags & SOLDIER_ENEMY ) { //pSoldier->needToLookForItems = FALSE; return; } if ( pSoldier->flags.uiStatusFlags & SOLDIER_VEHICLE ) { return; } // Return if this guy has no gridno, has bad life, etc if(TileIsOutOfBounds(pSoldier->sGridNo) || !pSoldier->bInSector || pSoldier->stats.bLife < OKLIFE ) { return; } if (pSoldier->bBlindedCounter > 0) { return; } gubGridNoValue++; if ( gubGridNoValue == 255 ) { // Reset! Assert(gubGridNoMarkers); memset(gubGridNoMarkers, 0, sizeof(UINT8)*WORLD_MAX); gubGridNoValue = 1; } // OK, look for doors MercLooksForDoors( pSoldier, TRUE ); who = pSoldier->ubID; dir = pSoldier->ubDirection; //NumMessage("good old reveal",dir); // a gassed merc can only see 1 tile away due to blurred vision if ( pSoldier->flags.uiStatusFlags & SOLDIER_GASSED ) { range = 1; } else { range = pSoldier->bViewRange; // Flugente: adjust sightrange range = (UINT8)( (range * (100 + pSoldier->GetSightRangeBonus()) ) / 100); // balance item viewing range between normal and the limit set by opplist-type functions -- CJC range = (AdjustMaxSightRangeForEnvEffects( pSoldier, LightTrueLevel( pSoldier->sGridNo, pSoldier->pathing.bLevel), range ) + range) / 2; } BuildSightDir(dir,(UINT32 *)&Dir[0],(UINT32 *)&Dir[1],(UINT32 *)&Dir[2],(UINT32 *)&Dir[3],(UINT32 *)&Dir[4]); for (cnt = 0; cnt < 5; cnt++) Inc[cnt] = DirectionInc( (UINT8) Dir[cnt]); // create gridno increment for NOVIEW - in other words, no increment! Inc[5] = 0; Dir[5] = pSoldier->ubDirection; if (dir % 2 == 1) /* even numbers use ViewPath2 */ Path2 = TRUE; else Path2 = FALSE; // ATE: if in this special cercumstance... our guys are moving on their own... // Stop sighting items // IN the future, we may want to do something else here... if ( gTacticalStatus.uiFlags & OUR_MERCS_AUTO_MOVE ) { itemsToo = FALSE; } for (maincnt = 0; maincnt < MAXVIEWPATHS; maincnt++) { marker = pSoldier->sGridNo; Blocking = FALSE; twoMoreTiles = FALSE; tilesLeftToSee = 99; fRevealItems = TRUE; fStopRevealingItemsAfterThisTile = FALSE; #ifdef _DEBUG if ( _KeyDown( NUM_LOCK ) ) { memset( gubFOVDebugInfoInfo, 0, sizeof( gubFOVDebugInfoInfo ) ); SetRenderFlags( RENDER_FLAG_FULL ); RenderWorld( ); } #endif for (markercnt = 0; markercnt < range; markercnt++) { //fGoneThroughDoor = FALSE; //fThroughWindow = FALSE; prevmarker = marker; nextDir = 99; fCheckForRooms = FALSE; fTravelCostObs = FALSE; if ( fStopRevealingItemsAfterThisTile ) { fRevealItems = FALSE; fStopRevealingItemsAfterThisTile = FALSE; } if (Path2) { markerDir = ViewPath2[maincnt][markercnt]; if (markercnt < 12) nextDir = ViewPath2[maincnt][markercnt+1]; } else { markerDir = ViewPath[maincnt][markercnt]; if (markercnt < 12) nextDir = ViewPath[maincnt][markercnt+1]; } // OK, check flags for going through door/window last tile if ( fThroughWindow == 1 ) { // ATE: Make sure we are going through the same direction! // THis is to solve the drassen SAM problem with seeing through walls if ( Dir[markerDir] == bThroughWindowDirection) { fThroughWindow = 2; } else { fThroughWindow = 0; } } else if ( fThroughWindow == 2 ) { // We've overstayed our welcome - remove! fThroughWindow = 0; } if ( fGoneThroughDoor == 1 ) { fGoneThroughDoor = 2; } else if ( fGoneThroughDoor == 2 ) { // We've overstayed our welcome - remove! fGoneThroughDoor = 0; } //ATE CHECK FOR NOVIEW! if ( nextDir == NOVIEW ) { nextDir = 99; } marker = NewGridNo(marker,(INT16)Inc[markerDir]); if ( marker == 12426 ) { int i = 0; } // End if this is a no view... if ( markerDir == NOVIEW && markercnt != 0 ) { break; } #ifdef _DEBUG if ( _KeyDown( NUM_LOCK ) ) { int cnt = GetJA2Clock( ); gubFOVDebugInfoInfo[ marker ] = (UINT8)markercnt; StartFrameBufferRender(); RenderFOVDebug( ); SetFont( LARGEFONT1 ); SetFontBackground( FONT_MCOLOR_BLACK ); SetFontForeground( FONT_MCOLOR_WHITE ); mprintf( 10, 10 , L"%d", maincnt ); //mprintf( 10, 20 , L"%d", marker ); //mprintf( 50, 20 , L"%d", pSoldier->sGridNo ); InvalidateScreen( ); EndFrameBufferRender(); RefreshScreen( NULL ); do { } while( ( GetJA2Clock( ) - cnt ) < 250 ); } #endif // Check if we can get to this gridno from our direction in ubMovementCost = gubWorldMovementCosts[ marker ][ Dir[ markerDir ] ][ ubLevel ]; // ATE: Added: If our current sector is below ground, ignore any blocks! if ( gfCaves && ubMovementCost != TRAVELCOST_CAVEWALL ) { ubMovementCost = TRAVELCOST_FLAT; } if ( IS_TRAVELCOST_DOOR( ubMovementCost ) ) { ubMovementCost = DoorTravelCost( pSoldier, marker, ubMovementCost, (BOOLEAN) (pSoldier->bTeam == gbPlayerNum), &iDoorGridNo ); pStructure = FindStructure( iDoorGridNo, STRUCTURE_ANYDOOR ); if ( pStructure != NULL && pStructure->fFlags & STRUCTURE_TRANSPARENT) { // cell door or somehow otherwise transparent; allow merc to see through ubMovementCost = TRAVELCOST_FLAT; } } // If we have hit an obstacle, STOP HERE if ( ubMovementCost >= TRAVELCOST_BLOCKED ) { // We have an obstacle here... // If it is bigger than a breadbox... err... taller than a man... // Then stop path altogether // otherwise just stop revealing items // CJC: only do this when the direction is horizontal; easier and faster to check // and the effect should still be good enough if ( ubMovementCost == TRAVELCOST_WALL || ubMovementCost == TRAVELCOST_DOOR || ubMovementCost == TRAVELCOST_EXITGRID ) { fTravelCostObs = TRUE; fRevealItems = FALSE; } else { // walls are handled above, so the blocking object is guaranteed not to be a wall bTallestStructureHeight = GetTallestStructureHeight( marker, FALSE ); if (bTallestStructureHeight >= 3) { fTravelCostObs = TRUE; fStopRevealingItemsAfterThisTile = TRUE; } else if ( bTallestStructureHeight != 0 ) { // stop revealing items after this tile but keep going fStopRevealingItemsAfterThisTile = TRUE; } } if ( (Dir[markerDir] % 2) == 1 ) { // diagonal fTravelCostObs = TRUE; // cheap hack... don't reveal items fRevealItems = FALSE; } else { bTallestStructureHeight = GetTallestStructureHeight( marker, FALSE ); if (bTallestStructureHeight >= 3) { fTravelCostObs = TRUE; fStopRevealingItemsAfterThisTile = TRUE; } else if ( bTallestStructureHeight != 0 ) { // stop revealing items after this tile but keep going fStopRevealingItemsAfterThisTile = TRUE; } } } // Check if it's been done already! if ( gubGridNoMarkers[ marker ] != gubGridNoValue ) { // Mark gridno gubGridNoMarkers[ marker ] = gubGridNoValue; // check and see if the gridno changed // if the gridno is the same, avoid redundancy and break if (marker==prevmarker && markercnt != 0 ) { } else // it changed { // Skip others if we have gone through a door but are too far away.... if ( fGoneThroughDoor ) { if (markercnt > 5 ) // Are we near the door? { break; } } // DO MINE FINDING STUFF // GET INDEX FOR ITEM HERE // if there IS a direction after this one, nextdir WILL NOT be 99 if (nextDir != 99) { Blocking = GetBlockingStructureInfo( marker, (INT8)Dir[ markerDir ], (INT8)Dir[ nextDir ], ubLevel, &bStructHeight, &pDummy, FALSE ); } else // no "next" direction, so pass in a NOWHERE so that // "SpecialViewObstruction" will know not to take it UINT32o consideration { Blocking = GetBlockingStructureInfo( marker, (INT8)Dir[markerDir], (INT8)30, ubLevel, &bStructHeight, &pDummy, FALSE ); } if ( gfCaves ) { Blocking = NOTHING_BLOCKING; } // CHECK FOR ROOMS if ( Blocking == BLOCKING_TOPLEFT_WINDOW || Blocking == BLOCKING_TOPLEFT_OPEN_WINDOW ) { // CHECK FACING DIRECTION! if ( Dir[markerDir] == NORTH || Dir[markerDir] == SOUTH ) { if (markercnt <= 1 ) // Are we right beside it? { fThroughWindow = TRUE; bThroughWindowDirection = ( INT8 ) Dir[ markerDir ]; } } } if ( Blocking == BLOCKING_TOPRIGHT_WINDOW || Blocking == BLOCKING_TOPRIGHT_OPEN_WINDOW ) { // CHECK FACING DIRECTION! if ( Dir[markerDir] == EAST || Dir[markerDir] == WEST ) { if (markercnt <= 1 ) // Are we right beside it? { fThroughWindow = TRUE; bThroughWindowDirection = ( INT8 ) Dir[ markerDir ]; } } } if ( Blocking == BLOCKING_TOPLEFT_DOOR ) { fGoneThroughDoor = TRUE; } if ( Blocking == BLOCKING_TOPRIGHT_DOOR ) { fGoneThroughDoor = TRUE; } // ATE: If we hit this tile, find item always! //if (Blocking < FULL_BLOCKING ) { // Handle special things for our mercs, like uncovering roofs // and revealing objects... //gpSoldier->shad |= SEENBIT; //itemVisible = ObjList[itemIndex].visible; // NOTE: don't allow object viewing if gassed XXX if (itemsToo && fRevealItems ) // && itemIndex < MAXOBJECTLIST) { // OK, look for corpses... LookForAndMayCommentOnSeeingCorpse( pSoldier, marker, ubLevel ); if ( GetItemPool( marker, &pItemPool, ubLevel ) ) { itemVisible = pItemPool->bVisible; if ( SetItemPoolVisibilityOn( pItemPool, INVISIBLE, fShowLocators ) ) { SetRenderFlags(RENDER_FLAG_FULL); // WANNE: Should we pause when item was found in tactical? bool enableItemSpottingAction = true; if ( !is_networked && gGameExternalOptions.fItemSpottedNoTalk && gTacticalStatus.uiFlags & TURNBASED && gTacticalStatus.uiFlags & INCOMBAT) enableItemSpottingAction = false; if (enableItemSpottingAction) { if ( fShowLocators ) { // Set makred render flags //gpWorldLevelData[marker].uiFlags|=MAPELEMENT_REDRAW; //gpWorldLevelData[gusCurMousePos].pTopmostHead->uiFlags |= LEVELNODE_DYNAMIC; //SetRenderFlags(RENDER_FLAG_MARKED); SetRenderFlags(RENDER_FLAG_FULL); // Hault soldier // ATE: Only if in combat... if ( gTacticalStatus.uiFlags & INCOMBAT ) { pSoldier->HaultSoldierFromSighting( FALSE ); } else { // ATE: Make sure we show locators... gTacticalStatus.fLockItemLocators = FALSE; } if ( !fItemsQuoteSaid && gTacticalStatus.fLockItemLocators == FALSE ) { gTacticalStatus.fLockItemLocators = TRUE; if ( gTacticalStatus.ubAttackBusyCount > 0 && ( gTacticalStatus.uiFlags & INCOMBAT ) ) { gTacticalStatus.fItemsSeenOnAttack = TRUE; gTacticalStatus.ubItemsSeenOnAttackSoldier = pSoldier->ubID; gTacticalStatus.usItemsSeenOnAttackGridNo = marker; } else { // Display quote! if ( !AM_AN_EPC( pSoldier ) ) { TacticalCharacterDialogueWithSpecialEvent( pSoldier, (UINT16)( QUOTE_SPOTTED_SOMETHING_ONE + Random( 2 ) ), DIALOGUE_SPECIAL_EVENT_SIGNAL_ITEM_LOCATOR_START, marker, 0 ); } else { // Turn off item lock for locators... gTacticalStatus.fLockItemLocators = FALSE; // Slide to location! SlideToLocation( 0, marker ); } } fItemsQuoteSaid = TRUE; } } } } } } // if blood here, let the user see it now... //if (ExtGrid[marker].patrolInfo < MAXBLOOD) // gpSoldier->blood = ExtGrid[marker].patrolInfo; //DoRoofs(marker,gpSoldier); tilesLeftToSee--; } // CHECK FOR HIDDEN STRUCTS // IF we had a hidden struct here that is not visible ( which will still be true because // we set it revealed below... if ( DoesGridNoContainHiddenStruct( marker, &fHiddenStructVisible ) ) { if ( !fHiddenStructVisible ) { gpWorldLevelData[marker].uiFlags|=MAPELEMENT_REDRAW; SetRenderFlags(RENDER_FLAG_MARKED); RecompileLocalMovementCosts( marker ); } } if (tilesLeftToSee <= 0) break; if ( Blocking == FULL_BLOCKING || ( fTravelCostObs && !fThroughWindow ) ) { break; } //if ( Blocking == NOTHING_BLOCKING || Blocking == BLOCKING_NEXT_TILE ) if ( Blocking == NOTHING_BLOCKING ) { fCheckForRooms = TRUE; } if ( ubLevel != 0 ) { fCheckForRooms = FALSE; } // CHECK FOR SLANT ROOF! { STRUCTURE *pStructure, *pBase; pStructure = FindStructure( marker, STRUCTURE_SLANTED_ROOF ); if ( pStructure != NULL ) { pBase = FindBaseStructure( pStructure ); // ADD TO SLANTED ROOF LIST! AddSlantRoofFOVSlot( marker ); } } // Set gridno as revealed if ( ubLevel == FIRST_LEVEL ) { if ( gfBasement || gfCaves ) { // OK, if we are underground, we don't want to reveal stuff if // 1 ) there is a roof over us and // 2 ) we are not in a room if ( gusWorldRoomInfo[ marker ] == NO_ROOM && TypeRangeExistsInRoofLayer( marker, FIRSTROOF, FOURTHROOF, &usIndex ) ) { int i = 0; } else { gpWorldLevelData[ marker ].uiFlags |= MAPELEMENT_REVEALED; if( gfCaves ) { RemoveFogFromGridNo( marker ); } } } else { gpWorldLevelData[ marker ].uiFlags |= MAPELEMENT_REVEALED; } // CHECK FOR ROOMS //if ( fCheckForRooms ) { if ( InAHiddenRoom( marker, &usRoomNo ) ) { RemoveRoomRoof( marker, usRoomNo, pSoldier ); if ( usRoomNo == ROOM_SURROUNDING_BOXING_RING && gWorldSectorX == BOXING_SECTOR_X && gWorldSectorY == BOXING_SECTOR_Y && gbWorldSectorZ == BOXING_SECTOR_Z ) { // reveal boxing ring at same time RemoveRoomRoof( marker, BOXING_RING, pSoldier ); } } } } else { gpWorldLevelData[ marker ].uiFlags |= MAPELEMENT_REVEALED_ROOF; } // Check for blood.... UpdateBloodGraphics( marker, ubLevel ); if ( Blocking != NOTHING_BLOCKING && Blocking != BLOCKING_TOPLEFT_DOOR && Blocking != BLOCKING_TOPRIGHT_DOOR && Blocking != BLOCKING_TOPLEFT_WINDOW && Blocking != BLOCKING_TOPRIGHT_WINDOW && Blocking != BLOCKING_TOPRIGHT_OPEN_WINDOW && Blocking != BLOCKING_TOPLEFT_OPEN_WINDOW) { break; } //gpWorldLevelData[ marker ].uiFlags |= MAPELEMENT_SHADELAND; } } // End of duplicate check else { if ( fTravelCostObs ) { break; } } } // end of one path } // end of path loop // Loop through all availible slant roofs we collected and perform cool stuff on them ExamineSlantRoofFOVSlots( ); //pSoldier->needToLookForItems = FALSE; //LookForDoors(pSoldier,UNAWARE); }
BOOLEAN HandleNextTileWaiting( SOLDIERTYPE *pSoldier ) { // Buddy is waiting to continue his path INT8 bBlocked, bPathBlocked; INT16 sCost; INT16 sNewGridNo, sCheckGridNo; UINT8 ubDirection, bCauseDirection; UINT8 ubPerson; UINT8 fFlags = 0; if ( pSoldier->fDelayedMovement ) { if ( TIMECOUNTERDONE( pSoldier->NextTileCounter, NEXT_TILE_CHECK_DELAY ) ) { RESETTIMECOUNTER( pSoldier->NextTileCounter, NEXT_TILE_CHECK_DELAY ); // Get direction from gridno... bCauseDirection = (INT8)GetDirectionToGridNoFromGridNo( pSoldier->sGridNo, pSoldier->sDelayedMovementCauseGridNo ); bBlocked = TileIsClear( pSoldier, bCauseDirection, pSoldier->sDelayedMovementCauseGridNo, pSoldier->bLevel ); // If we are waiting for a temp blockage.... continue to wait if ( pSoldier->fDelayedMovement >= 100 && bBlocked == MOVE_TILE_TEMP_BLOCKED ) { // ATE: Increment 1 pSoldier->fDelayedMovement++; // Are we close enough to give up? ( and are a pc ) if ( pSoldier->fDelayedMovement > 120 ) { // Quit... SetFinalTile( pSoldier, pSoldier->sGridNo, TRUE ); pSoldier->fDelayedMovement = FALSE; } return( TRUE ); } // Try new path if anything but temp blockage! if ( bBlocked != MOVE_TILE_TEMP_BLOCKED ) { // Set to normal delay if ( pSoldier->fDelayedMovement >= 100 && pSoldier->fDelayedMovement != 150 ) { pSoldier->fDelayedMovement = 1; } // Default to pathing through people fFlags = PATH_THROUGH_PEOPLE; // Now, if we are in the state where we are desparently trying to get out... // Use other flag // CJC: path-through-people includes ignoring person at dest /* if ( pSoldier->fDelayedMovement >= 150 ) { fFlags = PATH_IGNORE_PERSON_AT_DEST; } */ // Check destination first! if ( pSoldier->sAbsoluteFinalDestination == pSoldier->sFinalDestination ) { // on last lap of scripted move, make sure we get to final dest sCheckGridNo = pSoldier->sAbsoluteFinalDestination; } else if (!NewOKDestination( pSoldier, pSoldier->sFinalDestination, TRUE, pSoldier->bLevel )) { if ( pSoldier->fDelayedMovement >= 150 ) { // OK, look around dest for the first one! sCheckGridNo = FindGridNoFromSweetSpot( pSoldier, pSoldier->sFinalDestination, 6, &ubDirection ); if ( sCheckGridNo == NOWHERE ) { // If this is nowhere, try harder! sCheckGridNo = FindGridNoFromSweetSpot( pSoldier, pSoldier->sFinalDestination, 16, &ubDirection ); } } else { // OK, look around dest for the first one! sCheckGridNo = FindGridNoFromSweetSpotThroughPeople( pSoldier, pSoldier->sFinalDestination, 6, &ubDirection ); if ( sCheckGridNo == NOWHERE ) { // If this is nowhere, try harder! sCheckGridNo = FindGridNoFromSweetSpotThroughPeople( pSoldier, pSoldier->sFinalDestination, 16, &ubDirection ); } } } else { sCheckGridNo = pSoldier->sFinalDestination; } // Try another path to destination // ATE: Allow path to exit grid! if ( pSoldier->ubWaitActionToDo == 1 && gubWaitingForAllMercsToExitCode == WAIT_FOR_MERCS_TO_WALK_TO_GRIDNO ) { gfPlotPathToExitGrid = TRUE; } sCost = (INT16) FindBestPath( pSoldier, sCheckGridNo, pSoldier->bLevel, pSoldier->usUIMovementMode, NO_COPYROUTE, fFlags ); gfPlotPathToExitGrid = FALSE; // Can we get there if ( sCost > 0 ) { // Is the next tile blocked too? sNewGridNo = NewGridNo( (UINT16)pSoldier->sGridNo, DirectionInc( (UINT8)guiPathingData[ 0 ] ) ); bPathBlocked = TileIsClear( pSoldier, (UINT8)guiPathingData[ 0 ], sNewGridNo, pSoldier->bLevel ); if ( bPathBlocked == MOVE_TILE_STATIONARY_BLOCKED ) { // Try to path around everyone except dest person if ( pSoldier->ubWaitActionToDo == 1 && gubWaitingForAllMercsToExitCode == WAIT_FOR_MERCS_TO_WALK_TO_GRIDNO ) { gfPlotPathToExitGrid = TRUE; } sCost = (INT16) FindBestPath( pSoldier, sCheckGridNo, pSoldier->bLevel, pSoldier->usUIMovementMode, NO_COPYROUTE, PATH_IGNORE_PERSON_AT_DEST ); gfPlotPathToExitGrid = FALSE; // Is the next tile in this new path blocked too? sNewGridNo = NewGridNo( (UINT16)pSoldier->sGridNo, DirectionInc( (UINT8)guiPathingData[ 0 ] ) ); bPathBlocked = TileIsClear( pSoldier, (UINT8)guiPathingData[ 0 ], sNewGridNo, pSoldier->bLevel ); // now working with a path which does not go through people pSoldier->ubDelayedMovementFlags &= (~DELAYED_MOVEMENT_FLAG_PATH_THROUGH_PEOPLE); } else { // path through people worked fine if ( pSoldier->fDelayedMovement < 150 ) { pSoldier->ubDelayedMovementFlags |= DELAYED_MOVEMENT_FLAG_PATH_THROUGH_PEOPLE; } } // Are we clear? if ( bPathBlocked == MOVE_TILE_CLEAR ) { // Go for it path! if ( pSoldier->ubWaitActionToDo == 1 && gubWaitingForAllMercsToExitCode == WAIT_FOR_MERCS_TO_WALK_TO_GRIDNO ) { gfPlotPathToExitGrid = TRUE; } //pSoldier->fDelayedMovement = FALSE; // ATE: THis will get set in EENT_GetNewSoldierPath.... pSoldier->usActionData = sCheckGridNo; pSoldier->bPathStored = FALSE; EVENT_GetNewSoldierPath( pSoldier, sCheckGridNo, pSoldier->usUIMovementMode ); gfPlotPathToExitGrid = FALSE; return( TRUE ); } } pSoldier->fDelayedMovement++; if ( pSoldier->fDelayedMovement == 99 ) { // Cap at 99 pSoldier->fDelayedMovement = 99; } // Do we want to force a swap? if (pSoldier->fDelayedMovement == 3 && (pSoldier->sAbsoluteFinalDestination != NOWHERE || gTacticalStatus.fAutoBandageMode) ) { // with person who is in the way? ubPerson = WhoIsThere2( pSoldier->sDelayedMovementCauseGridNo, pSoldier->bLevel ); // if either on a mission from god, or two AI guys not on stationary... if ( ubPerson != NOBODY && ( pSoldier->ubQuoteRecord != 0 || ( pSoldier->bTeam != gbPlayerNum && pSoldier->bOrders != STATIONARY && MercPtrs[ ubPerson ]->bTeam != gbPlayerNum && MercPtrs[ ubPerson ]->bOrders != STATIONARY ) || (pSoldier->bTeam == gbPlayerNum && gTacticalStatus.fAutoBandageMode && !(MercPtrs[ ubPerson ]->bTeam == CIV_TEAM && MercPtrs[ ubPerson ]->bOrders == STATIONARY ) ) ) ) { // Swap now! //MercPtrs[ ubPerson ]->fBlockedByAnotherMerc = FALSE; // Restore final dest.... //MercPtrs[ ubPerson ]->sFinalDestination = sTempDestGridNo; // Swap merc positions..... SwapMercPositions( pSoldier, MercPtrs[ ubPerson ] ); // With these two guys swapped, we should try to continue on our way.... pSoldier->fDelayedMovement = FALSE; // We must calculate the path here so that we can give it the "through people" parameter if ( gTacticalStatus.fAutoBandageMode && pSoldier->sAbsoluteFinalDestination == NOWHERE ) { FindBestPath( pSoldier, pSoldier->sFinalDestination, pSoldier->bLevel, pSoldier->usUIMovementMode, COPYROUTE, PATH_THROUGH_PEOPLE ); } else if ( pSoldier->sAbsoluteFinalDestination != NOWHERE && !FindBestPath( pSoldier, pSoldier->sAbsoluteFinalDestination, pSoldier->bLevel, pSoldier->usUIMovementMode, COPYROUTE, PATH_THROUGH_PEOPLE ) ) { // check to see if we're there now! if ( pSoldier->sGridNo == pSoldier->sAbsoluteFinalDestination ) { NPCReachedDestination( pSoldier, FALSE ); pSoldier->bNextAction = AI_ACTION_WAIT; pSoldier->usNextActionData = 500; return( TRUE ); } } pSoldier->bPathStored = TRUE; EVENT_GetNewSoldierPath( pSoldier, pSoldier->sAbsoluteFinalDestination, pSoldier->usUIMovementMode ); //EVENT_GetNewSoldierPath( MercPtrs[ ubPerson ], MercPtrs[ ubPerson ]->sFinalDestination, MercPtrs[ ubPerson ]->usUIMovementMode ); } } // Are we close enough to give up? ( and are a pc ) if ( pSoldier->fDelayedMovement > 20 && pSoldier->fDelayedMovement != 150) { if ( PythSpacesAway( pSoldier->sGridNo, pSoldier->sFinalDestination ) < 5 && pSoldier->bTeam == gbPlayerNum ) { // Quit... SetFinalTile( pSoldier, pSoldier->sGridNo, FALSE ); pSoldier->fDelayedMovement = FALSE; } } // Are we close enough to give up? ( and are a pc ) if ( pSoldier->fDelayedMovement > 170 ) { if ( PythSpacesAway( pSoldier->sGridNo, pSoldier->sFinalDestination ) < 5 && pSoldier->bTeam == gbPlayerNum ) { // Quit... SetFinalTile( pSoldier, pSoldier->sGridNo, FALSE ); pSoldier->fDelayedMovement = FALSE; } } } } } return( TRUE ); }
INT8 TileIsClear( SOLDIERTYPE *pSoldier, INT8 bDirection, INT16 sGridNo, INT8 bLevel ) { UINT8 ubPerson; INT16 sTempDestGridNo; INT16 sNewGridNo; BOOLEAN fSwapInDoor = FALSE; if ( sGridNo == NOWHERE ) { return( MOVE_TILE_CLEAR ); } ubPerson = WhoIsThere2( sGridNo, bLevel ); if ( ubPerson != NO_SOLDIER ) { // If this us? if ( ubPerson != pSoldier->ubID ) { // OK, set flag indicating we are blocked by a merc.... if ( pSoldier->bTeam != gbPlayerNum ) // CJC: shouldn't this be in all cases??? //if ( 0 ) { pSoldier->fBlockedByAnotherMerc = TRUE; // Set direction we were trying to goto pSoldier->bBlockedByAnotherMercDirection = bDirection; // Are we only temporarily blocked? // Check if our final destination is = our gridno if ( ( MercPtrs[ ubPerson ]->sFinalDestination == MercPtrs[ ubPerson ]->sGridNo ) ) { return( MOVE_TILE_STATIONARY_BLOCKED ); } else { // OK, if buddy who is blocking us is trying to move too... // And we are in opposite directions... if ( MercPtrs[ ubPerson ]->fBlockedByAnotherMerc && MercPtrs[ ubPerson ]->bBlockedByAnotherMercDirection == gOppositeDirection[ bDirection ] ) { // OK, try and get a path around buddy.... // We have to temporarily make buddy stopped... sTempDestGridNo = MercPtrs[ ubPerson ]->sFinalDestination; MercPtrs[ ubPerson ]->sFinalDestination = MercPtrs[ ubPerson ]->sGridNo; if ( PlotPath( pSoldier, pSoldier->sFinalDestination, NO_COPYROUTE, NO_PLOT, TEMPORARY, pSoldier->usUIMovementMode, NOT_STEALTH, FORWARD, pSoldier->bActionPoints ) ) { pSoldier->bPathStored = FALSE; // OK, make guy go here... EVENT_GetNewSoldierPath( pSoldier, pSoldier->sFinalDestination, pSoldier->usUIMovementMode ); // Restore final dest.... MercPtrs[ ubPerson ]->sFinalDestination = sTempDestGridNo; pSoldier->fBlockedByAnotherMerc = FALSE; // Is the next tile blocked too? sNewGridNo = NewGridNo( (UINT16)pSoldier->sGridNo, DirectionInc( (UINT8)guiPathingData[ 0 ] ) ); return( TileIsClear( pSoldier, (UINT8)guiPathingData[ 0 ], sNewGridNo, pSoldier->bLevel ) ); } else { // Not for multi-tiled things... if ( !( pSoldier->uiStatusFlags & SOLDIER_MULTITILE ) ) { // Is the next movement cost for a door? if ( DoorTravelCost( pSoldier, sGridNo, gubWorldMovementCosts[ sGridNo ][ bDirection ][ pSoldier->bLevel ], (BOOLEAN)( pSoldier->bTeam == gbPlayerNum ), NULL ) == TRAVELCOST_DOOR ) { fSwapInDoor = TRUE; } // If we are to swap and we're near a door, open door first and then close it...? // Swap now! MercPtrs[ ubPerson ]->fBlockedByAnotherMerc = FALSE; // Restore final dest.... MercPtrs[ ubPerson ]->sFinalDestination = sTempDestGridNo; // Swap merc positions..... SwapMercPositions( pSoldier, MercPtrs[ ubPerson ] ); // With these two guys swapped, they should try and continue on their way.... // Start them both again along their way... EVENT_GetNewSoldierPath( pSoldier, pSoldier->sFinalDestination, pSoldier->usUIMovementMode ); EVENT_GetNewSoldierPath( MercPtrs[ ubPerson ], MercPtrs[ ubPerson ]->sFinalDestination, MercPtrs[ ubPerson ]->usUIMovementMode ); } } } return( MOVE_TILE_TEMP_BLOCKED ); } } else { //return( MOVE_TILE_STATIONARY_BLOCKED ); // ATE: OK, put some smartshere... // If we are waiting for more than a few times, change to stationary... if ( MercPtrs[ ubPerson ]->fDelayedMovement >= 105 ) { // Set to special 'I want to walk through people' value pSoldier->fDelayedMovement = 150; return( MOVE_TILE_STATIONARY_BLOCKED ); } if ( MercPtrs[ ubPerson ]->sGridNo == MercPtrs[ ubPerson ]->sFinalDestination ) { return( MOVE_TILE_STATIONARY_BLOCKED ); } return( MOVE_TILE_TEMP_BLOCKED ); } } } if ( ( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_MOVEMENT_RESERVED ) ) { if ( gpWorldLevelData[ sGridNo ].ubReservedSoldierID != pSoldier->ubID ) { return( MOVE_TILE_TEMP_BLOCKED ); } } // Are we clear of structs? if ( !NewOKDestination( pSoldier, sGridNo, FALSE, pSoldier->bLevel ) ) { // ATE: Fence cost is an exclusiuon here.... if ( gubWorldMovementCosts[ sGridNo ][ bDirection ][ pSoldier->bLevel ] != TRAVELCOST_FENCE ) { // ATE: HIdden structs - we do something here... reveal it! if ( gubWorldMovementCosts[ sGridNo ][ bDirection ][ pSoldier->bLevel ] == TRAVELCOST_HIDDENOBSTACLE ) { gpWorldLevelData[ sGridNo ].uiFlags|=MAPELEMENT_REVEALED; gpWorldLevelData[ sGridNo ].uiFlags|=MAPELEMENT_REDRAW; SetRenderFlags(RENDER_FLAG_MARKED); RecompileLocalMovementCosts( (UINT16)sGridNo ); } // Unset flag for blocked by soldier... pSoldier->fBlockedByAnotherMerc = FALSE; return( MOVE_TILE_STATIONARY_BLOCKED ); } else { #if 0 // Check if there is a reserved marker here at least.... sNewGridNo = NewGridNo( sGridNo, DirectionInc( bDirection ) ); if ( ( gpWorldLevelData[ sNewGridNo ].uiFlags & MAPELEMENT_MOVEMENT_RESERVED ) ) { if ( gpWorldLevelData[ sNewGridNo ].ubReservedSoldierID != pSoldier->ubID ) { return( MOVE_TILE_TEMP_BLOCKED ); } } #endif } } // Unset flag for blocked by soldier... pSoldier->fBlockedByAnotherMerc = FALSE; return( MOVE_TILE_CLEAR ); }
void FindPanicBombsAndTriggers( void ) { // This function searches the bomb table to find panic-trigger-tuned bombs and triggers UINT32 uiBombIndex; OBJECTTYPE * pObj; STRUCTURE * pSwitch; INT32 sGridNo = NOWHERE; INT8 bPanicIndex; for (uiBombIndex = 0; uiBombIndex < guiNumWorldBombs; uiBombIndex++) { if (gWorldBombs[ uiBombIndex ].fExists) { pObj = &(gWorldItems[ gWorldBombs[ uiBombIndex ].iItemIndex ].object); if ((*pObj)[0]->data.misc.bFrequency == PANIC_FREQUENCY || (*pObj)[0]->data.misc.bFrequency == PANIC_FREQUENCY_2 || (*pObj)[0]->data.misc.bFrequency == PANIC_FREQUENCY_3 ) { if (pObj->usItem == SWITCH) { sGridNo = gWorldItems[ gWorldBombs[ uiBombIndex ].iItemIndex ].sGridNo; switch( (*pObj)[0]->data.misc.bFrequency ) { case PANIC_FREQUENCY: bPanicIndex = 0; break; case PANIC_FREQUENCY_2: bPanicIndex = 1; break; case PANIC_FREQUENCY_3: bPanicIndex = 2; break; default: // augh!!! continue; } pSwitch = FindStructure( sGridNo, STRUCTURE_SWITCH ); if (pSwitch) { switch( pSwitch->ubWallOrientation ) { case INSIDE_TOP_LEFT: case OUTSIDE_TOP_LEFT: sGridNo += DirectionInc( SOUTH ); break; case INSIDE_TOP_RIGHT: case OUTSIDE_TOP_RIGHT: sGridNo += DirectionInc( EAST ); break; default: break; } } gTacticalStatus.sPanicTriggerGridNo[ bPanicIndex ] = sGridNo; gTacticalStatus.ubPanicTolerance[ bPanicIndex ] = (*pObj)[0]->data.misc.ubTolerance; if ((*pObj).fFlags & OBJECT_ALARM_TRIGGER) { gTacticalStatus.bPanicTriggerIsAlarm[ bPanicIndex ] = TRUE; } gTacticalStatus.fPanicFlags |= PANIC_TRIGGERS_HERE; bPanicIndex++; if (bPanicIndex == NUM_PANIC_TRIGGERS) { return; } } else { gTacticalStatus.fPanicFlags |= PANIC_BOMBS_HERE; } } } } }