From 992c487176e17066dd79016043bd6846b905331b Mon Sep 17 00:00:00 2001 From: Sevenfm Date: Tue, 21 Dec 2021 21:20:48 +0000 Subject: [PATCH] Reverted r9221 change. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9222 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- TacticalAI/AIUtils.cpp | 47 ++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/TacticalAI/AIUtils.cpp b/TacticalAI/AIUtils.cpp index cb7e9a205..c577b7626 100644 --- a/TacticalAI/AIUtils.cpp +++ b/TacticalAI/AIUtils.cpp @@ -5876,40 +5876,43 @@ INT32 RandomizeLocation(INT32 sSpot, INT8 bLevel, UINT8 ubTimes, SOLDIERTYPE *pS UINT8 ubDirection; UINT8 ubMovementCost; INT32 sTempSpot; + INT32 sSpotArray[NUM_WORLD_DIRECTIONS + 1]; + UINT8 ubSpots; - std::vector spots; - std::vector::iterator iter; - - // store original location - spots.push_back(sSpot); - - // find all spots reachable within ubTimes steps for (UINT8 ubCnt = 0; ubCnt < ubTimes; ubCnt++) { - for (iter = spots.begin(); iter != spots.end(); iter++) + // store original location + ubSpots = 1; + sSpotArray[0] = sSpot; + + // find adjacent locations + for (ubDirection = 0; ubDirection < NUM_WORLD_DIRECTIONS; ubDirection++) { - // find adjacent locations - for (ubDirection = 0; ubDirection < NUM_WORLD_DIRECTIONS; ubDirection++) + sTempSpot = NewGridNo(sSpot, DirectionInc(ubDirection)); + + if (sTempSpot != sSpot) { - sTempSpot = NewGridNo(*iter, DirectionInc(ubDirection)); + ubMovementCost = gubWorldMovementCosts[sTempSpot][ubDirection][bLevel]; - if (sTempSpot != *iter) + if (ubMovementCost < TRAVELCOST_BLOCKED && + IsLocationSittableExcludingPeople(sTempSpot, bLevel) && + (!pSightSoldier || SoldierToVirtualSoldierLineOfSightTest(pSightSoldier, sTempSpot, bLevel, ANIM_STAND, TRUE, NO_DISTANCE_LIMIT))) { - ubMovementCost = gubWorldMovementCosts[sTempSpot][ubDirection][bLevel]; - - if (ubMovementCost < TRAVELCOST_BLOCKED && - std::find(spots.begin(), spots.end(), sTempSpot) == spots.end() && - IsLocationSittableExcludingPeople(sTempSpot, bLevel) && - (!pSightSoldier || SoldierToVirtualSoldierLineOfSightTest(pSightSoldier, sTempSpot, bLevel, ANIM_STAND, TRUE, NO_DISTANCE_LIMIT))) - { - spots.push_back(sTempSpot); - } + sSpotArray[ubSpots] = sTempSpot; + ubSpots++; } } } + // find random location + sSpot = sSpotArray[Random(ubSpots)]; + // stop if could not find any adjacent spot + if (ubSpots < 2) + { + break; + } } - return spots[Random(spots.size())]; + return sSpot; } INT32 RandomizeOpponentLocation(INT32 sSpot, SOLDIERTYPE *pOpponent, INT16 sMaxDistance)