Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 333 Lines • ▼ Show 20 Lines | if (this.CanPack()) | ||||
return; | return; | ||||
} | } | ||||
if (this.CheckRange(this.order.data)) | if (this.CheckRange(this.order.data)) | ||||
{ | { | ||||
// We are already at the target, or can't move at all | // We are already at the target, or can't move at all | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
Lint: ESLintBear (consistent-return): `Method 'Order.WalkToTarget' expected no return value.` | |||||
} | } | ||||
this.order.data.relaxed = true; | this.order.data.relaxed = true; | ||||
if (this.IsAnimal()) | if (this.IsAnimal()) | ||||
this.SetNextState("ANIMAL.WALKING"); | this.SetNextState("ANIMAL.WALKING"); | ||||
else | else | ||||
this.SetNextState("INDIVIDUAL.WALKING"); | this.SetNextState("INDIVIDUAL.WALKING"); | ||||
▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | UnitAI.prototype.UnitFsmSpec = { | ||||
"Order.Gather": function(msg) { | "Order.Gather": function(msg) { | ||||
if (!this.CanGather(this.order.data.target)) | if (!this.CanGather(this.order.data.target)) | ||||
{ | { | ||||
this.SetNextState("INDIVIDUAL.GATHER.FINDINGNEWTARGET"); | this.SetNextState("INDIVIDUAL.GATHER.FINDINGNEWTARGET"); | ||||
return; | return; | ||||
} | } | ||||
// If the unit is full go to the nearest dropsite instead of trying to gather. | |||||
// Unless our target is a treasure which we cannot be full enough with (we can't carry treasures). | |||||
let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | |||||
if (msg.data.type.generic !== "treasure" && cmpResourceGatherer && !cmpResourceGatherer.CanCarryMore(msg.data.type.generic)) | |||||
{ | |||||
let nearestDropsite = this.FindNearestDropsite(msg.data.type.generic); | |||||
if (nearestDropsite) | |||||
this.PushOrderFront("ReturnResource", { | |||||
"target": nearestDropsite, | |||||
"force": false, | |||||
"type": msg.data.type | |||||
}); | |||||
// Players expect the unit to move, so walk to the target instead of trying to gather. | |||||
else if (!this.FinishOrder()) | |||||
this.WalkToTarget(msg.data.target, false); | |||||
return; | |||||
} | |||||
if (this.MustKillGatherTarget(this.order.data.target)) | if (this.MustKillGatherTarget(this.order.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(this.order.data.target, false)) | if (!this.GetBestAttackAgainst(this.order.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 | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
Show All 21 Lines | if (this.MustKillGatherTarget(this.order.data.target)) | ||||
}); | }); | ||||
} | } | ||||
return; | return; | ||||
} | } | ||||
this.PushOrderFront("Attack", { "target": this.order.data.target, "force": !!this.order.data.force, "hunting": true, "allowCapture": false }); | this.PushOrderFront("Attack", { "target": this.order.data.target, "force": !!this.order.data.force, "hunting": true, "allowCapture": false }); | ||||
return; | return; | ||||
} | } | ||||
// If the unit is full go to the nearest dropsite instead of trying to gather. | |||||
// We also do not do it for hunting as you might want to kill animals for other units. | |||||
// Unless our target is a treasure which we cannot be full enough with (we can't carry treasures). | |||||
let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | |||||
if (msg.data.type.generic !== "treasure" && cmpResourceGatherer && !cmpResourceGatherer.CanCarryMore(msg.data.type.generic)) | |||||
{ | |||||
let nearestDropsite = this.FindNearestDropsite(msg.data.type.generic); | |||||
if (nearestDropsite) | |||||
this.PushOrderFront("ReturnResource", { | |||||
"target": nearestDropsite, | |||||
"force": false, | |||||
"type": msg.data.type | |||||
}); | |||||
// Players expect the unit to move, so walk to the target instead of trying to gather. | |||||
else if (!this.FinishOrder()) | |||||
this.WalkToTarget(msg.data.target, false); | |||||
return; | |||||
} | |||||
Not Done Inline ActionsShould be here no? wraitii: Should be here no? | |||||
this.RememberTargetPosition(); | this.RememberTargetPosition(); | ||||
if (!this.order.data.initPos) | if (!this.order.data.initPos) | ||||
this.order.data.initPos = this.order.data.lastPos; | this.order.data.initPos = this.order.data.lastPos; | ||||
if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer)) | if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer)) | ||||
this.SetNextState("INDIVIDUAL.GATHER.GATHERING"); | this.SetNextState("INDIVIDUAL.GATHER.GATHERING"); | ||||
else | else | ||||
this.SetNextState("INDIVIDUAL.GATHER.APPROACHING"); | this.SetNextState("INDIVIDUAL.GATHER.APPROACHING"); | ||||
▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | "Order.Garrison": function(msg) { | ||||
if (!this.CheckGarrisonRange(msg.data.target)) | if (!this.CheckGarrisonRange(msg.data.target)) | ||||
{ | { | ||||
if (!this.CheckTargetVisible(msg.data.target)) | if (!this.CheckTargetVisible(msg.data.target)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
Lint: ESLintBear (no-else-return) Unnecessary 'else' after 'return'. Lint: ESLintBear (no-else-return): `Unnecessary 'else' after 'return'.` | |||||
this.SetNextState("GARRISON.APPROACHING"); | this.SetNextState("GARRISON.APPROACHING"); | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
this.SetNextState("GARRISON.GARRISONING"); | this.SetNextState("GARRISON.GARRISONING"); | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 1,352 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
this.SetNextState("FINDINGNEWTARGET"); | this.SetNextState("FINDINGNEWTARGET"); | ||||
}, | }, | ||||
// TODO: respond to target deaths immediately, rather than waiting | // TODO: respond to target deaths immediately, rather than waiting | ||||
// until the next Timer event | // until the next Timer event | ||||
"Attacked": function(msg) { | "Attacked": function(msg) { | ||||
if (this.order.data.attackType == "Capture" && (this.GetStance().targetAttackersAlways || !this.order.data.force) | if (this.order.data.attackType == "Capture" && (this.GetStance().targetAttackersAlways || !this.order.data.force) | ||||
&& this.order.data.target != msg.data.attacker && this.GetBestAttackAgainst(msg.data.attacker, true) != "Capture") | && this.order.data.target != msg.data.attacker && this.GetBestAttackAgainst(msg.data.attacker, true) != "Capture") | ||||
Lint: ESLintBear (operator-linebreak) '&&' should be placed at the end of the line. Lint: ESLintBear (operator-linebreak): `'&&' should be placed at the end of the line.` | |||||
this.RespondToTargetedEntities([msg.data.attacker]); | this.RespondToTargetedEntities([msg.data.attacker]); | ||||
}, | }, | ||||
}, | }, | ||||
"FINDINGNEWTARGET": { | "FINDINGNEWTARGET": { | ||||
"Order.Cheer": function() { | "Order.Cheer": function() { | ||||
if (!this.cheeringTime) | if (!this.cheeringTime) | ||||
return { "discardOrder": true }; | return { "discardOrder": true }; | ||||
▲ Show 20 Lines • Show All 4,409 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Method 'Order.WalkToTarget' expected no return value.