diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index 38eaf8e8bdb..50744dd4ce7 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -900,17 +900,20 @@ void AIPlayer::guardSupplyCenter( Team *team, Int minSupplies ) Coord3D location = *warehouse->getPosition(); // It's probably a defensive move - position towards the enemy. Region2D bounds; - Int enemyNdx = TheScriptEngine->getSkirmishEnemyPlayer()->getPlayerIndex(); - getPlayerStructureBounds(&bounds, enemyNdx); - Coord3D offset; - offset.zero(); - offset.x = location.x - (bounds.lo.x+bounds.hi.x)*0.5f; - offset.y = location.y - (bounds.lo.y+bounds.hi.y)*0.5f; - offset.normalize(); - Real radius = warehouse->getGeometryInfo().getBoundingCircleRadius()*0.8f; + Player *enemyPlayer = TheScriptEngine->getSkirmishEnemyPlayer(); + if (enemyPlayer) { + Int enemyNdx = enemyPlayer->getPlayerIndex(); + getPlayerStructureBounds(&bounds, enemyNdx); + Coord3D offset; + offset.zero(); + offset.x = location.x - (bounds.lo.x+bounds.hi.x)*0.5f; + offset.y = location.y - (bounds.lo.y+bounds.hi.y)*0.5f; + offset.normalize(); + Real radius = warehouse->getGeometryInfo().getBoundingCircleRadius()*0.8f; - location.x -= offset.x*radius; - location.y -= offset.y*radius; + location.x -= offset.x*radius; + location.y -= offset.y*radius; + } theGroup->groupGuardPosition( &location, GUARDMODE_NORMAL, CMD_FROM_SCRIPT ); } @@ -1757,12 +1760,15 @@ void AIPlayer::buildBySupplies(Int minimumCash, const AsciiString& thingName) if (!tTemplate->isKindOf(KINDOF_CASH_GENERATOR)) { // It's probably a defensive structure - build towards the enemy. Region2D bounds; - Int enemyNdx = TheScriptEngine->getSkirmishEnemyPlayer()->getPlayerIndex(); - getPlayerStructureBounds(&bounds, enemyNdx); - offset.x = location.x - (bounds.lo.x+bounds.hi.x)*0.5f; - offset.y = location.y - (bounds.lo.y+bounds.hi.y)*0.5f; - offset.normalize(); - radius = bestSupplyWarehouse->getGeometryInfo().getBoundingCircleRadius(); + Player *enemyPlayer = TheScriptEngine->getSkirmishEnemyPlayer(); + if (enemyPlayer) { + Int enemyNdx = enemyPlayer->getPlayerIndex(); + getPlayerStructureBounds(&bounds, enemyNdx); + offset.x = location.x - (bounds.lo.x+bounds.hi.x)*0.5f; + offset.y = location.y - (bounds.lo.y+bounds.hi.y)*0.5f; + offset.normalize(); + radius = bestSupplyWarehouse->getGeometryInfo().getBoundingCircleRadius(); + } } location.x -= offset.x*radius; location.y -= offset.y*radius; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index d0db9660b47..cd409692b43 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -907,17 +907,20 @@ void AIPlayer::guardSupplyCenter( Team *team, Int minSupplies ) Coord3D location = *warehouse->getPosition(); // It's probably a defensive move - position towards the enemy. Region2D bounds; - Int enemyNdx = TheScriptEngine->getSkirmishEnemyPlayer()->getPlayerIndex(); - getPlayerStructureBounds(&bounds, enemyNdx); - Coord3D offset; - offset.zero(); - offset.x = location.x - (bounds.lo.x+bounds.hi.x)*0.5f; - offset.y = location.y - (bounds.lo.y+bounds.hi.y)*0.5f; - offset.normalize(); - Real radius = warehouse->getGeometryInfo().getBoundingCircleRadius()*0.8f; + Player *enemyPlayer = TheScriptEngine->getSkirmishEnemyPlayer(); + if (enemyPlayer) { + Int enemyNdx = enemyPlayer->getPlayerIndex(); + getPlayerStructureBounds(&bounds, enemyNdx); + Coord3D offset; + offset.zero(); + offset.x = location.x - (bounds.lo.x+bounds.hi.x)*0.5f; + offset.y = location.y - (bounds.lo.y+bounds.hi.y)*0.5f; + offset.normalize(); + Real radius = warehouse->getGeometryInfo().getBoundingCircleRadius()*0.8f; - location.x -= offset.x*radius; - location.y -= offset.y*radius; + location.x -= offset.x*radius; + location.y -= offset.y*radius; + } theGroup->groupGuardPosition( &location, GUARDMODE_NORMAL, CMD_FROM_SCRIPT ); } @@ -1877,12 +1880,15 @@ void AIPlayer::buildBySupplies(Int minimumCash, const AsciiString& thingName) if (!tTemplate->isKindOf(KINDOF_CASH_GENERATOR)) { // It's probably a defensive structure - build towards the enemy. Region2D bounds; - Int enemyNdx = TheScriptEngine->getSkirmishEnemyPlayer()->getPlayerIndex(); - getPlayerStructureBounds(&bounds, enemyNdx); - offset.x = location.x - (bounds.lo.x+bounds.hi.x)*0.5f; - offset.y = location.y - (bounds.lo.y+bounds.hi.y)*0.5f; - offset.normalize(); - radius = bestSupplyWarehouse->getGeometryInfo().getBoundingCircleRadius(); + Player *enemyPlayer = TheScriptEngine->getSkirmishEnemyPlayer(); + if (enemyPlayer) { + Int enemyNdx = enemyPlayer->getPlayerIndex(); + getPlayerStructureBounds(&bounds, enemyNdx); + offset.x = location.x - (bounds.lo.x+bounds.hi.x)*0.5f; + offset.y = location.y - (bounds.lo.y+bounds.hi.y)*0.5f; + offset.normalize(); + radius = bestSupplyWarehouse->getGeometryInfo().getBoundingCircleRadius(); + } } location.x -= offset.x*radius; location.y -= offset.y*radius;