Change my fix from revision [13586] to use something faster. Still Refs #1914

This was SVN commit r13587.
This commit is contained in:
wraitii 2013-07-23 10:37:43 +00:00
parent dc3c39fd93
commit efc1a678ed

View file

@ -1658,6 +1658,19 @@ var UnitFsmSpec = {
"enter": function() {
this.gatheringTarget = this.order.data.target; // deleted in "leave".
// Check if the resource is full.
if (this.gatheringTarget) {
// Check that we can gather from the resource we're supposed to gather from.
// Will only be added if we're not already in.
var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply);
if (!cmpSupply || !cmpSupply.AddGatherer(this.entity))
{
this.gatheringTarget = -1;
this.StartTimer(0);
return false;
}
}
// If this order was forced, the player probably gave it, but now we've reached the target
// switch to an unforced order (can be interrupted by attacks)
this.order.data.force = false;
@ -1687,22 +1700,6 @@ var UnitFsmSpec = {
// The offset should be at least as long as the repeat time so we use the same value for both.
var offset = 1000/rate;
var repeat = offset;
// Check if the resource is full.
if (this.gatheringTarget) {
// Check that we can gather from the resource we're supposed to gather from.
// Will only be added if we're not already in.
var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply);
if (!cmpSupply || !cmpSupply.AddGatherer(this.entity))
{
// actually start it like that because sometime the supply will
// have become available again once we reach Gather.Gathering.Timer
// And this leads to units getting stuck in Gather.Gathering forever.
this.StartTimer(offset, repeat);
return false;
}
}
this.StartTimer(offset, repeat);
// We want to start the gather animation as soon as possible,
@ -1738,9 +1735,8 @@ var UnitFsmSpec = {
var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply);
// Check we can still reach and gather from the target
if (this.CheckTargetRange(this.gatheringTarget, IID_ResourceGatherer) && this.CanGather(this.gatheringTarget) && cmpSupply && cmpSupply.IsAvailable(this.entity))
if (cmpSupply && this.CheckTargetRange(this.gatheringTarget, IID_ResourceGatherer) && this.CanGather(this.gatheringTarget) && cmpSupply.IsAvailable(this.entity))
{
cmpSupply.AddGatherer(this.entity);
// Gather the resources:
var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer);