Per wrote:Seems fixed now.
On a side note, I wonder if there is anything we can do to make the AI stop "stealing" "my" oil derricks... It is a bit annoying when you play with an AI buddy. (No idea if playing with an AI ally is something someone else does, or if it just me, though.)
On game init I loop through all players to find the closest ally and closest enemy x,y coordinates by searching for their HQ or first constructor droid they have if they don't have a HQ.
- Code: Select all
function int nearestAlly()
{
local int _ally,_closestAlly,_newDist,_bestDist,_closestAllyX,_closestAllyY,_numUnits;
local bool _haveTruck;
_bestDist = 99999;
_closestAlly = -1;
_ally = 0;
_numUnits = 0;
while(_ally < 10)
{
if(allianceExistsBetween(me, _ally) and me != _ally)
{
initEnumStruct(FALSE,playerHQ,_ally,_ally);
structure= enumStruct();
while(structure != NULLOBJECT)
{
_newDist = distBetweenTwoPoints(baseX, baseY, structure.x, structure.y);
if (_newDist < _bestDist)
{
_bestDist = _newDist;
_closestAlly = structure.player;
_closestAllyX = structure.x;
_closestAllyY = structure.y;
}
structure= enumStruct();
}
if(getStructure(playerHQ, _ally) == NULLOBJECT)
{
_haveTruck = FALSE;
InitEnumDroids(_ally,_ally);
droid = EnumDroid();
while (droid != NULLOBJECT and _haveTruck == FALSE)
{
if(droid.droidType == DROID_CONSTRUCT or droid.droidType == DROID_CYBORG_CONSTRUCT) // check to see if any of our allies don't have a truck
{
_haveTruck = TRUE;
_newDist = distBetweenTwoPoints(baseX, baseY, droid.x, droid.y);
if (_newDist < _bestDist)
{
_bestDist = _newDist;
_closestAlly = droid.player;
_closestAllyX = droid.x;
_closestAllyY = droid.y;
}
}
_numUnits++;
droid = EnumDroid();
}
}
closestAllyDist = _bestDist;
closestAllyHQx = _closestAllyX;
closestAllyHQy = _closestAllyY;
numAllyUnits = _numUnits;
}
_ally++;
}
return _closestAlly;
}
Then if gameTime < 6000 (first 10 minutes of game) I check if the distance between the oil resource is closer to the closest ally or closer to me. If closer to the closest ally then don't build it.
I backed it out because it caused problems when trying to compete for legit resources out on the map and never revisited it. It would probably be better to just keep track of all ally x,y base coordinates and just check if the oil resource is within say ~10 tiles of their base like Berserk said above.