Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 488 Lines • ▼ Show 20 Lines | if (lastGatheredType && msg.data.type.generic != lastGatheredType) | ||||
this.UnitFsm.SwitchToNextState(this, "INDIVIDUAL.GATHER"); | this.UnitFsm.SwitchToNextState(this, "INDIVIDUAL.GATHER"); | ||||
if (!this.CanGather(msg.data.target)) | if (!this.CanGather(msg.data.target)) | ||||
{ | { | ||||
this.SetNextState("INDIVIDUAL.GATHER.FINDINGNEWTARGET"); | this.SetNextState("INDIVIDUAL.GATHER.FINDINGNEWTARGET"); | ||||
return ACCEPT_ORDER; | return ACCEPT_ORDER; | ||||
} | } | ||||
// If the unit is full go to the nearest dropsite instead of trying to gather. | |||||
if (!cmpResourceGatherer.CanCarryMore(msg.data.type.generic)) | |||||
{ | |||||
this.SetNextState("INDIVIDUAL.GATHER.RETURNINGRESOURCE"); | |||||
return ACCEPT_ORDER; | |||||
} | |||||
if (this.MustKillGatherTarget(msg.data.target)) | if (this.MustKillGatherTarget(msg.data.target)) | ||||
{ | { | ||||
// Make sure we can attack the target, else we'll get very stuck | // Make sure we can attack the target, else we'll get very stuck | ||||
if (!this.GetBestAttackAgainst(msg.data.target, false)) | if (!this.GetBestAttackAgainst(msg.data.target, false)) | ||||
{ | { | ||||
// Oops, we can't attack at all - give up | // Oops, we can't attack at all - give up | ||||
// TODO: should do something so the player knows why this failed | // TODO: should do something so the player knows why this failed | ||||
return this.FinishOrder(); | return this.FinishOrder(); | ||||
Show All 17 Lines | if (this.MustKillGatherTarget(msg.data.target)) | ||||
}); | }); | ||||
return ACCEPT_ORDER; | return ACCEPT_ORDER; | ||||
} | } | ||||
this.PushOrderFront("Attack", { "target": msg.data.target, "force": !!msg.data.force, "hunting": true, "allowCapture": false }); | this.PushOrderFront("Attack", { "target": msg.data.target, "force": !!msg.data.force, "hunting": true, "allowCapture": false }); | ||||
return ACCEPT_ORDER; | return ACCEPT_ORDER; | ||||
} | } | ||||
// If the unit is full go to the nearest dropsite instead of trying to gather. | |||||
if (!cmpResourceGatherer.CanCarryMore(msg.data.type.generic)) | |||||
{ | |||||
this.SetNextState("INDIVIDUAL.GATHER.RETURNINGRESOURCE"); | |||||
return ACCEPT_ORDER; | |||||
} | |||||
this.RememberTargetPosition(); | this.RememberTargetPosition(); | ||||
if (!msg.data.initPos) | if (!msg.data.initPos) | ||||
msg.data.initPos = msg.data.lastPos; | msg.data.initPos = msg.data.lastPos; | ||||
if (this.CheckTargetRange(msg.data.target, IID_ResourceGatherer)) | if (this.CheckTargetRange(msg.data.target, IID_ResourceGatherer)) | ||||
this.SetNextState("INDIVIDUAL.GATHER.GATHERING"); | this.SetNextState("INDIVIDUAL.GATHER.GATHERING"); | ||||
else if (this.AbleToMove()) | else if (this.AbleToMove()) | ||||
this.SetNextState("INDIVIDUAL.GATHER.APPROACHING"); | this.SetNextState("INDIVIDUAL.GATHER.APPROACHING"); | ||||
▲ Show 20 Lines • Show All 5,888 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator