Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 575 Lines • ▼ Show 20 Lines | "Order.GatherNearPosition": function(msg) { | ||||
this.order.data.initPos = { 'x': this.order.data.x, 'z': this.order.data.z }; | this.order.data.initPos = { 'x': this.order.data.x, 'z': this.order.data.z }; | ||||
this.order.data.relaxed = true; | this.order.data.relaxed = true; | ||||
}, | }, | ||||
"Order.ReturnResource": function(msg) { | "Order.ReturnResource": function(msg) { | ||||
// Check if the dropsite is already in range | // Check if the dropsite is already in range | ||||
if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer) && this.CanReturnResource(this.order.data.target, true)) | if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer) && this.CanReturnResource(this.order.data.target, true)) | ||||
{ | { | ||||
var cmpResourceDropsite = Engine.QueryInterface(this.order.data.target, IID_ResourceDropsite); | let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | ||||
if (cmpResourceDropsite) | if (cmpResourceGatherer) | ||||
wraitii: This is already check by CanReturnResource (in fact the existing check is already redundant it… | |||||
{ | { | ||||
// Dump any resources we can | cmpResourceGatherer.CommitResources(this.order.data.target); | ||||
var dropsiteTypes = cmpResourceDropsite.GetTypes(); | |||||
Engine.QueryInterface(this.entity, IID_ResourceGatherer).CommitResources(dropsiteTypes); | |||||
// Stop showing the carried resource animation. | // Stop showing the carried resource animation. | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
// Our next order should always be a Gather, | // Our next order should always be a Gather, | ||||
// so just switch back to that order | // so just switch back to that order | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,032 Lines • ▼ Show 20 Lines | "RETURNRESOURCE": { | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
// Check the dropsite is in range and we can return our resource there | // Check the dropsite is in range and we can return our resource there | ||||
// (we didn't get stopped before reaching it) | // (we didn't get stopped before reaching it) | ||||
if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer) && this.CanReturnResource(this.order.data.target, true)) | if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer) && this.CanReturnResource(this.order.data.target, true)) | ||||
{ | { | ||||
let cmpResourceDropsite = Engine.QueryInterface(this.order.data.target, IID_ResourceDropsite); | |||||
if (cmpResourceDropsite) | |||||
{ | |||||
// Dump any resources we can | |||||
let dropsiteTypes = cmpResourceDropsite.GetTypes(); | |||||
let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | ||||
Not Done Inline ActionsLikewise. wraitii: Likewise. | |||||
cmpResourceGatherer.CommitResources(dropsiteTypes); | if (cmpResourceGatherer) | ||||
{ | |||||
// Dump any resources we can. | |||||
cmpResourceGatherer.CommitResources(this.order.data.target); | |||||
// Stop showing the carried resource animation. | // Stop showing the carried resource animation. | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
// Our next order should always be a Gather, | // Our next order should always be a Gather, | ||||
// so just switch back to that order | // so just switch back to that order. | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
if (msg.obstructed) | if (msg.obstructed) | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | "REPAIR": { | ||||
// Save the current state so we can continue walking if necessary | // Save the current state so we can continue walking if necessary | ||||
// FinishOrder() below will switch to IDLE if there's no order, which sets the idle animation. | // FinishOrder() below will switch to IDLE if there's no order, which sets the idle animation. | ||||
// Idle animation while moving towards finished construction looks weird (ghosty). | // Idle animation while moving towards finished construction looks weird (ghosty). | ||||
let oldState = this.GetCurrentState(); | let oldState = this.GetCurrentState(); | ||||
// Drop any resource we can if we are in range when the construction finishes | // Drop any resource we can if we are in range when the construction finishes | ||||
let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | ||||
let cmpResourceDropsite = Engine.QueryInterface(msg.data.newentity, IID_ResourceDropsite); | if (cmpResourceGatherer && this.CheckTargetRange(msg.data.newentity, IID_Builder) && | ||||
if (cmpResourceGatherer && cmpResourceDropsite && this.CheckTargetRange(msg.data.newentity, IID_Builder) && | |||||
this.CanReturnResource(msg.data.newentity, true)) | this.CanReturnResource(msg.data.newentity, true)) | ||||
Not Done Inline ActionsLikewise :p wraitii: Likewise :p | |||||
{ | { | ||||
let dropsiteTypes = cmpResourceDropsite.GetTypes(); | cmpResourceGatherer.CommitResources(msg.data.newentity); | ||||
cmpResourceGatherer.CommitResources(dropsiteTypes); | |||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
} | } | ||||
// We finished building it. | // We finished building it. | ||||
// Switch to the next order (if any) | // Switch to the next order (if any) | ||||
if (this.FinishOrder()) | if (this.FinishOrder()) | ||||
{ | { | ||||
if (this.CanReturnResource(msg.data.newentity, true)) | if (this.CanReturnResource(msg.data.newentity, true)) | ||||
{ | { | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
this.PushOrderFront("ReturnResource", { "target": msg.data.newentity, "force": false }); | this.PushOrderFront("ReturnResource", { "target": msg.data.newentity, "force": false }); | ||||
} | } | ||||
Not Done Inline Actionsdoes not this invalidate PushOrderFront ? Silier: does not this invalidate `PushOrderFront` ?
`PushOrderFront` calls `this.UnitFsm. | |||||
Not Done Inline ActionsHm, you're right, PushOrderFront immediately executes the order. wraitii: Hm, you're right, PushOrderFront immediately executes the order. | |||||
return; | return; | ||||
} | } | ||||
// No remaining orders - pick a useful default behaviour | // No remaining orders - pick a useful default behaviour | ||||
// If autocontinue explicitly disabled (e.g. by AI) then | // If autocontinue explicitly disabled (e.g. by AI) then | ||||
// do nothing automatically | // do nothing automatically | ||||
if (!oldData.autocontinue) | if (!oldData.autocontinue) | ||||
Show All 11 Lines | "REPAIR": { | ||||
this.PerformGather(msg.data.newentity, true, false); | this.PerformGather(msg.data.newentity, true, false); | ||||
return; | return; | ||||
} | } | ||||
// If this building was e.g. a farmstead of ours, entities that received | // If this building was e.g. a farmstead of ours, entities that received | ||||
// the build command should look for nearby resources to gather | // the build command should look for nearby resources to gather | ||||
if ((oldData.force || oldData.autoharvest) && this.CanReturnResource(msg.data.newentity, false)) | if ((oldData.force || oldData.autoharvest) && this.CanReturnResource(msg.data.newentity, false)) | ||||
{ | { | ||||
let cmpResourceDropsite = Engine.QueryInterface(msg.data.newentity, IID_ResourceDropsite); | |||||
let types = cmpResourceDropsite.GetTypes(); | let types = cmpResourceDropsite.GetTypes(); | ||||
let pos; | let pos; | ||||
let cmpPosition = Engine.QueryInterface(msg.data.newentity, IID_Position); | let cmpPosition = Engine.QueryInterface(msg.data.newentity, IID_Position); | ||||
if (cmpPosition && cmpPosition.IsInWorld()) | if (cmpPosition && cmpPosition.IsInWorld()) | ||||
pos = cmpPosition.GetPosition2D(); | pos = cmpPosition.GetPosition2D(); | ||||
// TODO: Slightly undefined behavior here, we don't know what type of resource will be collected, | // TODO: Slightly undefined behavior here, we don't know what type of resource will be collected, | ||||
// may cause problems for AIs (especially hunting fast animals), but avoid ugly hacks to fix that! | // may cause problems for AIs (especially hunting fast animals), but avoid ugly hacks to fix that! | ||||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | "GARRISON": { | ||||
// move command | // move command | ||||
var rearrange = cmpFormation.rearrange; | var rearrange = cmpFormation.rearrange; | ||||
cmpFormation.SetRearrange(false); | cmpFormation.SetRearrange(false); | ||||
cmpFormation.RemoveMembers([this.entity]); | cmpFormation.RemoveMembers([this.entity]); | ||||
cmpFormation.SetRearrange(rearrange); | cmpFormation.SetRearrange(rearrange); | ||||
} | } | ||||
} | } | ||||
// Check if we are garrisoned in a dropsite | // Check if we are garrisoned in a dropsite. | ||||
var cmpResourceDropsite = Engine.QueryInterface(target, IID_ResourceDropsite); | let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | ||||
if (cmpResourceDropsite && this.CanReturnResource(target, true)) | if (cmpResourceGatherer && this.CanReturnResource(target, true)) | ||||
Not Done Inline Actionsyou can move the interface call inside Edit -> for that matter there's a ton of redundancy here. wraitii: you can move the interface call inside
Edit -> for that matter there's a ton of redundancy… | |||||
{ | |||||
// Dump any resources we can | |||||
var dropsiteTypes = cmpResourceDropsite.GetTypes(); | |||||
var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | |||||
if (cmpResourceGatherer) | |||||
{ | { | ||||
cmpResourceGatherer.CommitResources(dropsiteTypes); | cmpResourceGatherer.CommitResources(target); | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
} | } | ||||
} | |||||
// If a pickup has been requested, remove it | // If a pickup has been requested, remove it | ||||
if (this.pickup) | if (this.pickup) | ||||
{ | { | ||||
var cmpHolderPosition = Engine.QueryInterface(target, IID_Position); | var cmpHolderPosition = Engine.QueryInterface(target, IID_Position); | ||||
var cmpHolderUnitAI = Engine.QueryInterface(target, IID_UnitAI); | var cmpHolderUnitAI = Engine.QueryInterface(target, IID_UnitAI); | ||||
if (cmpHolderUnitAI && cmpHolderPosition) | if (cmpHolderUnitAI && cmpHolderPosition) | ||||
cmpHolderUnitAI.lastShorelinePosition = cmpHolderPosition.GetPosition(); | cmpHolderUnitAI.lastShorelinePosition = cmpHolderPosition.GetPosition(); | ||||
▲ Show 20 Lines • Show All 3,245 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
This is already check by CanReturnResource (in fact the existing check is already redundant it seems).