Changeset View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 2,187 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
"GATHER": { | "GATHER": { | ||||
"leave": function() { | "leave": function() { | ||||
// Show the carried resource, if we've gathered anything. | // Show the carried resource, if we've gathered anything. | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
}, | }, | ||||
"APPROACHING": { | "APPROACHING": { | ||||
"enter": function() { | "enter": function() { | ||||
Freagarach: What you basically want (for now at least) is keep these calls in sync with `cmpResourceSupply. | |||||
Done Inline ActionsIt was inside AddGatherer in one of the earlier version of this patch, but it was too flickering, since they count gatherers for different purposes, for display I decided to count them as soon as the animation starts, but could be putted in GATHER:APPROACHING too like AddGatherer, but then could be tricky to count him not twice without sets. I'll check. mammadori: It was inside AddGatherer in one of the earlier version of this patch, but it was too… | |||||
Done Inline ActionsIf you move this to both approaching.leave and gathering.leave you should be good. Freagarach: If you move this to both approaching.leave and gathering.leave you should be good. | |||||
Done Inline ActionsInstead of 1 in GATHER: leave? mammadori: Instead of 1 in GATHER: leave? | |||||
Done Inline ActionsThe main GATHER should be nice, or not? mammadori: The main GATHER should be nice, or not? | |||||
Done Inline ActionsInstead of one in gather.leave, yes. Since one can go from gather.approaching of one resource to gather.approaching of another and IIRC one doesn't leave gather, but does leave gather.approaching. Freagarach: Instead of one in gather.leave, yes. Since one can go from gather.approaching of one resource… | |||||
Done Inline Actions
That's indeed correct wraitii: > IIRC one doesn't leave gather, but does leave gather.approaching.
That's indeed correct | |||||
this.gatheringTarget = this.order.data.target; // temporary, deleted in "leave". | this.gatheringTarget = this.order.data.target; // temporary, deleted in "leave". | ||||
let cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); | let cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); | ||||
let cmpMirage = Engine.QueryInterface(this.gatheringTarget, IID_Mirage); | let cmpMirage = Engine.QueryInterface(this.gatheringTarget, IID_Mirage); | ||||
if ((!cmpMirage || !cmpMirage.Mirages(IID_ResourceSupply)) && | if ((!cmpMirage || !cmpMirage.Mirages(IID_ResourceSupply)) && | ||||
(!cmpSupply || !cmpSupply.AddGatherer(this.entity)) || | (!cmpSupply || !cmpSupply.AddGatherer(this.entity)) || | ||||
!this.MoveTo(this.order.data, IID_ResourceGatherer)) | !this.MoveTo(this.order.data, IID_ResourceGatherer)) | ||||
{ | { | ||||
// If the target's last known position is in FOW, try going there | // If the target's last known position is in FOW, try going there | ||||
// and hope that we might find it then. | // and hope that we might find it then. | ||||
let lastPos = this.order.data.lastPos; | let lastPos = this.order.data.lastPos; | ||||
if (this.gatheringTarget != INVALID_ENTITY && | if (this.gatheringTarget != INVALID_ENTITY && | ||||
lastPos && !this.CheckPositionVisible(lastPos.x, lastPos.z)) | lastPos && !this.CheckPositionVisible(lastPos.x, lastPos.z)) | ||||
{ | { | ||||
this.PushOrderFront("Walk", { | this.PushOrderFront("Walk", { | ||||
"x": lastPos.x, "z": lastPos.z, | "x": lastPos.x, "z": lastPos.z, | ||||
"force": this.order.data.force | "force": this.order.data.force | ||||
}); | }); | ||||
return true; | return true; | ||||
} | } | ||||
this.SetNextState("FINDINGNEWTARGET"); | this.SetNextState("FINDINGNEWTARGET"); | ||||
return true; | return true; | ||||
} | } | ||||
this.SetAnimationVariant("approach_" + this.order.data.type.specific); | this.SetAnimationVariant("approach_" + this.order.data.type.specific); | ||||
let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | |||||
if (cmpResourceGatherer) | |||||
cmpResourceGatherer.AddToPlayerCounter(this.order.data.type); | |||||
return false; | return false; | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
// The GATHERING timer will handle finding a valid resource. | // The GATHERING timer will handle finding a valid resource. | ||||
if (msg.likelyFailure) | if (msg.likelyFailure) | ||||
this.SetNextState("FINDINGNEWTARGET"); | this.SetNextState("FINDINGNEWTARGET"); | ||||
else if (this.CheckRange(this.order.data, IID_ResourceGatherer)) | else if (this.CheckRange(this.order.data, IID_ResourceGatherer)) | ||||
this.SetNextState("GATHERING"); | this.SetNextState("GATHERING"); | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
if (!this.gatheringTarget) | if (!this.gatheringTarget) | ||||
return; | return; | ||||
// don't use ownership because this is called after a conversion/resignation | // don't use ownership because this is called after a conversion/resignation | ||||
// and the ownership would be invalid then. | // and the ownership would be invalid then. | ||||
let cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); | let cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); | ||||
if (cmpSupply) | if (cmpSupply) | ||||
cmpSupply.RemoveGatherer(this.entity); | cmpSupply.RemoveGatherer(this.entity); | ||||
let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | |||||
if (cmpResourceGatherer) | |||||
cmpResourceGatherer.RemoveFromPlayerCounter(); | |||||
delete this.gatheringTarget; | delete this.gatheringTarget; | ||||
}, | }, | ||||
}, | }, | ||||
// Walking to a good place to gather resources near, used by GatherNearPosition | // Walking to a good place to gather resources near, used by GatherNearPosition | ||||
"WALKING": { | "WALKING": { | ||||
"enter": function() { | "enter": function() { | ||||
if (!this.MoveTo(this.order.data)) | if (!this.MoveTo(this.order.data)) | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | "GATHER": { | ||||
// (If it's not alive, the Timer handler will deal with sending us | // (If it's not alive, the Timer handler will deal with sending us | ||||
// off to a different target.) | // off to a different target.) | ||||
if (this.CheckTargetRange(this.gatheringTarget, IID_ResourceGatherer)) | if (this.CheckTargetRange(this.gatheringTarget, IID_ResourceGatherer)) | ||||
{ | { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.SetDefaultAnimationVariant(); | this.SetDefaultAnimationVariant(); | ||||
this.FaceTowardsTarget(this.order.data.target); | this.FaceTowardsTarget(this.order.data.target); | ||||
this.SelectAnimation("gather_" + this.order.data.type.specific); | this.SelectAnimation("gather_" + this.order.data.type.specific); | ||||
cmpResourceGatherer.AddToPlayerCounter(this.order.data.type); | |||||
} | } | ||||
return false; | return false; | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopTimer(); | this.StopTimer(); | ||||
// Don't use ownership because this is called after a conversion/resignation | // Don't use ownership because this is called after a conversion/resignation | ||||
// and the ownership would be invalid then. | // and the ownership would be invalid then. | ||||
let cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); | let cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); | ||||
if (cmpSupply) | if (cmpSupply) | ||||
cmpSupply.RemoveGatherer(this.entity); | cmpSupply.RemoveGatherer(this.entity); | ||||
let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | |||||
if (cmpResourceGatherer) | |||||
cmpResourceGatherer.RemoveFromPlayerCounter(); | |||||
delete this.gatheringTarget; | delete this.gatheringTarget; | ||||
this.ResetAnimation(); | this.ResetAnimation(); | ||||
}, | }, | ||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
let resourceTemplate = this.order.data.template; | let resourceTemplate = this.order.data.template; | ||||
let resourceType = this.order.data.type; | let resourceType = this.order.data.type; | ||||
▲ Show 20 Lines • Show All 1,395 Lines • ▼ Show 20 Lines | UnitAI.prototype.FinishOrder = function() | ||||
this.orderQueue = []; | this.orderQueue = []; | ||||
this.order = undefined; | this.order = undefined; | ||||
// Switch to IDLE as a default state. | // Switch to IDLE as a default state. | ||||
this.SetNextState("IDLE"); | this.SetNextState("IDLE"); | ||||
Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() }); | Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() }); | ||||
Done Inline ActionsI would use the function you have SetGathering in case there would need to be added some additional logic to not copy it everywhere you set this variable Silier: I would use the function you have SetGathering in case there would need to be added some… | |||||
// Check if there are queued formation orders | // Check if there are queued formation orders | ||||
if (this.IsFormationMember()) | if (this.IsFormationMember()) | ||||
{ | { | ||||
this.SetNextState("FORMATIONMEMBER.IDLE"); | this.SetNextState("FORMATIONMEMBER.IDLE"); | ||||
let cmpUnitAI = Engine.QueryInterface(this.formationController, IID_UnitAI); | let cmpUnitAI = Engine.QueryInterface(this.formationController, IID_UnitAI); | ||||
if (cmpUnitAI) | if (cmpUnitAI) | ||||
{ | { | ||||
// Inform the formation controller that we finished this task | // Inform the formation controller that we finished this task | ||||
▲ Show 20 Lines • Show All 2,635 Lines • Show Last 20 Lines |
What you basically want (for now at least) is keep these calls in sync with cmpResourceSupply.AddGatherer, I think. (I mean they need to be called at the same time.)