Changeset View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 2,193 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(); | ||||
let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); | |||||
if (cmpResourceGatherer) | |||||
cmpResourceGatherer.PlayerCounterDec(); | |||||
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 | |||||
}, | }, | ||||
"APPROACHING": { | "APPROACHING": { | ||||
"enter": function() { | "enter": function() { | ||||
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); | ||||
▲ Show 20 Lines • Show All 114 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.PlayerCounterInc(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 | ||||
▲ Show 20 Lines • Show All 1,407 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,625 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.)