Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 2,742 Lines • ▼ Show 20 Lines | "REPAIR": { | ||||
"enter": function() { | "enter": function() { | ||||
// If this order was forced, the player probably gave it, but now we've reached the target | // If this order was forced, the player probably gave it, but now we've reached the target | ||||
// switch to an unforced order (can be interrupted by attacks) | // switch to an unforced order (can be interrupted by attacks) | ||||
if (this.order.data.force) | if (this.order.data.force) | ||||
this.order.data.autoharvest = true; | this.order.data.autoharvest = true; | ||||
this.order.data.force = false; | this.order.data.force = false; | ||||
this.repairTarget = this.order.data.target; // temporary, deleted in "leave". | // Needed to remove the entity from the builder list when leaving this state. | ||||
Stan: Comments on top :) | |||||
// Check we can still reach and repair the target | this.repairTarget = this.order.data.target; | ||||
// Check we can still reach and repair the target. | |||||
if (!this.CanRepair(this.repairTarget)) | if (!this.CanRepair(this.repairTarget)) | ||||
{ | { | ||||
// Can't reach it, no longer owned by ally, or it doesn't exist any more | // Can't reach it, no longer owned by ally, or it doesn't exist any more. | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return true; | return true; | ||||
} | } | ||||
if (!this.CheckTargetRange(this.repairTarget, IID_Builder)) | if (!this.CheckTargetRange(this.repairTarget, IID_Builder)) | ||||
{ | { | ||||
this.SetNextState("APPROACHING"); | this.SetNextState("APPROACHING"); | ||||
return true; | return true; | ||||
} | } | ||||
// Check if the target is still repairable | // Check if the target is still repairable. | ||||
var cmpHealth = Engine.QueryInterface(this.repairTarget, IID_Health); | let cmpHealth = Engine.QueryInterface(this.repairTarget, IID_Health); | ||||
Done Inline Actionslet ? Stan: let ? | |||||
if (cmpHealth && cmpHealth.GetHitpoints() >= cmpHealth.GetMaxHitpoints()) | if (cmpHealth && cmpHealth.GetHitpoints() >= cmpHealth.GetMaxHitpoints()) | ||||
{ | { | ||||
// The building was already finished/fully repaired before we arrived; | // The building was already finished/fully repaired before we arrived; | ||||
// let the ConstructionFinished handler handle this. | // let the ConstructionFinished handler handle this. | ||||
this.OnGlobalConstructionFinished({"entity": this.repairTarget, "newentity": this.repairTarget}); | this.OnGlobalConstructionFinished({"entity": this.repairTarget, "newentity": this.repairTarget}); | ||||
return true; | return true; | ||||
} | } | ||||
this.StopMoving(); | this.StopMoving(); | ||||
let cmpBuilderList = QueryBuilderListInterface(this.repairTarget); | let cmpBuilderList = QueryBuilderListInterface(this.repairTarget); | ||||
if (cmpBuilderList) | if (cmpBuilderList) | ||||
cmpBuilderList.AddBuilder(this.entity); | cmpBuilderList.AddBuilder(this.entity); | ||||
this.FaceTowardsTarget(this.order.data.target); | this.FaceTowardsTarget(this.repairTarget); | ||||
this.SelectAnimation("build"); | this.SelectAnimation("build"); | ||||
this.StartTimer(1000, 1000); | this.StartTimer(1000, 1000); | ||||
return false; | return false; | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
let cmpBuilderList = QueryBuilderListInterface(this.repairTarget); | let cmpBuilderList = QueryBuilderListInterface(this.repairTarget); | ||||
if (cmpBuilderList) | if (cmpBuilderList) | ||||
cmpBuilderList.RemoveBuilder(this.entity); | cmpBuilderList.RemoveBuilder(this.entity); | ||||
delete this.repairTarget; | delete this.repairTarget; | ||||
this.StopTimer(); | this.StopTimer(); | ||||
this.ResetAnimation(); | this.ResetAnimation(); | ||||
}, | }, | ||||
Done Inline ActionsRevert accidental order change. Freagarach: Revert accidental order change. | |||||
"Timer": function(msg) { | "Timer": function(msg) { | ||||
// Check we can still reach and repair the target | // Check we can still reach and repair the target. | ||||
if (!this.CanRepair(this.repairTarget)) | if (!this.CanRepair(this.repairTarget)) | ||||
Done Inline ActionsComments on top. Freagarach: Comments on top. | |||||
{ | { | ||||
// No longer owned by ally, or it doesn't exist any more | // No longer owned by ally, or it doesn't exist any more. | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
this.FaceTowardsTarget(this.order.data.target); | this.FaceTowardsTarget(this.repairTarget); | ||||
let cmpBuilder = Engine.QueryInterface(this.entity, IID_Builder); | let cmpBuilder = Engine.QueryInterface(this.entity, IID_Builder); | ||||
cmpBuilder.PerformBuilding(this.repairTarget); | cmpBuilder.PerformBuilding(this.repairTarget); | ||||
// if the building is completed, the leave() function will be called | // If the building is completed, the leave() function will be called | ||||
// by the ConstructionFinished message | // by the ConstructionFinished message. | ||||
// in that case, the repairTarget is deleted, and we can just return | // In that case, the repairTarget is deleted, and we can just return. | ||||
if (!this.repairTarget) | if (!this.repairTarget) | ||||
return; | return; | ||||
if (!this.CheckTargetRange(this.repairTarget, IID_Builder)) | if (!this.CheckTargetRange(this.repairTarget, IID_Builder)) | ||||
this.SetNextState("APPROACHING"); | this.SetNextState("APPROACHING"); | ||||
}, | }, | ||||
}, | }, | ||||
"ConstructionFinished": function(msg) { | "ConstructionFinished": function(msg) { | ||||
▲ Show 20 Lines • Show All 1,258 Lines • ▼ Show 20 Lines | if (order.data && order.data.target && order.data.target == msg.entity) | ||||
order.data.target = msg.newentity; | order.data.target = msg.newentity; | ||||
} | } | ||||
if (order.data && order.data.formationTarget && order.data.formationTarget == msg.entity) | if (order.data && order.data.formationTarget && order.data.formationTarget == msg.entity) | ||||
{ | { | ||||
changed = true; | changed = true; | ||||
order.data.formationTarget = msg.newentity; | order.data.formationTarget = msg.newentity; | ||||
} | } | ||||
} | } | ||||
if (this.repairTarget && this.repairTarget == msg.entity) | |||||
{ | |||||
this.repairTarget = msg.newentity; | |||||
changed = true; | |||||
Done Inline Actionsprobably no, because this did not changed order data and would be already true anyway because looping above and this is not changing order data unless you can brake it somehow, but i dont see it currenlty Silier: probably no, because this did not changed order data and would be already true anyway because… | |||||
} | |||||
if (changed) | if (changed) | ||||
Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() }); | Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() }); | ||||
}; | }; | ||||
UnitAI.prototype.OnAttacked = function(msg) | UnitAI.prototype.OnAttacked = function(msg) | ||||
{ | { | ||||
this.UnitFsm.ProcessMessage(this, {"type": "Attacked", "data": msg}); | this.UnitFsm.ProcessMessage(this, {"type": "Attacked", "data": msg}); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 2,142 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Comments on top :)