Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

}
Expand Down Expand Up @@ -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;
Expand Down
38 changes: 22 additions & 16 deletions GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

}
Expand Down Expand Up @@ -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;
Expand Down
Loading