forked from 0ad/0ad
Make builders look for nearby foundations to help with, once they finish their own building
This was SVN commit r9032.
This commit is contained in:
parent
08d5e7bf66
commit
22e16e4554
@ -35,6 +35,11 @@ Foundation.prototype.GetBuildPercentage = function()
|
|||||||
return Math.floor(this.buildProgress * 100);
|
return Math.floor(this.buildProgress * 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Foundation.prototype.IsFinished = function()
|
||||||
|
{
|
||||||
|
return (this.buildProgress >= 1.0);
|
||||||
|
};
|
||||||
|
|
||||||
Foundation.prototype.OnDestroy = function()
|
Foundation.prototype.OnDestroy = function()
|
||||||
{
|
{
|
||||||
// Refund a portion of the construction cost, proportional to the amount of build progress remaining
|
// Refund a portion of the construction cost, proportional to the amount of build progress remaining
|
||||||
|
@ -917,7 +917,13 @@ var UnitFsmSpec = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: look for a nearby foundation to help with
|
// Look for a nearby foundation to help with
|
||||||
|
var nearbyFoundation = this.FindNearbyFoundation();
|
||||||
|
if (nearbyFoundation)
|
||||||
|
{
|
||||||
|
this.Repair(nearbyFoundation, oldAutocontinue, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Override the LeaveFoundation order since we don't want to be
|
// Override the LeaveFoundation order since we don't want to be
|
||||||
@ -1511,6 +1517,37 @@ UnitAI.prototype.FindNearestDropsite = function(genericType)
|
|||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the entity ID of the nearest building that needs to be constructed,
|
||||||
|
* or undefined if none can be found close enough.
|
||||||
|
*/
|
||||||
|
UnitAI.prototype.FindNearbyFoundation = function()
|
||||||
|
{
|
||||||
|
var range = 64; // TODO: what's a sensible number?
|
||||||
|
|
||||||
|
// Find buildings owned by this unit's player
|
||||||
|
var players = [];
|
||||||
|
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
|
||||||
|
if (cmpOwnership)
|
||||||
|
players.push(cmpOwnership.GetOwner());
|
||||||
|
|
||||||
|
var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
|
||||||
|
var nearby = rangeMan.ExecuteQuery(this.entity, 0, range, players, IID_Foundation);
|
||||||
|
for each (var ent in nearby)
|
||||||
|
{
|
||||||
|
// Skip foundations that are already complete. (This matters since
|
||||||
|
// we process the ConstructionFinished message before the foundation
|
||||||
|
// we're working on has been deleted.)
|
||||||
|
var cmpFoundation = Engine.QueryInterface(ent, IID_Foundation);
|
||||||
|
if (cmpFoundation.IsFinished())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Play a sound appropriate to the current entity.
|
* Play a sound appropriate to the current entity.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user