Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | UnitAI.prototype.UnitFsmSpec = { | ||||
"TradingCanceled": function(msg) { | "TradingCanceled": function(msg) { | ||||
// ignore | // ignore | ||||
}, | }, | ||||
"GuardedAttacked": function(msg) { | "GuardedAttacked": function(msg) { | ||||
// ignore | // ignore | ||||
}, | }, | ||||
"TargetDeath": function() { | |||||
// ignore | |||||
}, | |||||
// Formation handlers: | // Formation handlers: | ||||
"FormationLeave": function(msg) { | "FormationLeave": function(msg) { | ||||
// ignore when we're not in FORMATIONMEMBER | // ignore when we're not in FORMATIONMEMBER | ||||
}, | }, | ||||
// Called when being told to walk as part of a formation | // Called when being told to walk as part of a formation | ||||
"Order.FormationWalk": function(msg) { | "Order.FormationWalk": function(msg) { | ||||
▲ Show 20 Lines • Show All 1,788 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
this.FaceTowardsTarget(target); | this.FaceTowardsTarget(target); | ||||
// BuildingAI has it's own attack-routine | // BuildingAI has it's own attack-routine | ||||
let cmpBuildingAI = Engine.QueryInterface(this.entity, IID_BuildingAI); | let cmpBuildingAI = Engine.QueryInterface(this.entity, IID_BuildingAI); | ||||
if (!cmpBuildingAI) | if (!cmpBuildingAI) | ||||
{ | { | ||||
let cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); | let cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); | ||||
cmpAttack.PerformAttack(this.order.data.attackType, target); | cmpAttack.PerformAttack(this.order.data.attackType, target); | ||||
if (!this.order) | |||||
return; | |||||
} | } | ||||
// Check we can still reach the target for the next attack | // Check we can still reach the target for the next attack | ||||
if (this.CheckTargetAttackRange(target, this.order.data.attackType)) | if (this.CheckTargetAttackRange(target, this.order.data.attackType)) | ||||
{ | { | ||||
if (this.resyncAnimation) | if (this.resyncAnimation) | ||||
{ | { | ||||
this.SetAnimationSync(this.attackTimers.repeat, this.attackTimers.repeat); | this.SetAnimationSync(this.attackTimers.repeat, this.attackTimers.repeat); | ||||
Show All 12 Lines | "COMBAT": { | ||||
} | } | ||||
this.SetNextState("COMBAT.CHASING"); | this.SetNextState("COMBAT.CHASING"); | ||||
return; | return; | ||||
} | } | ||||
this.SetNextState("FINDINGNEWTARGET"); | this.SetNextState("FINDINGNEWTARGET"); | ||||
}, | }, | ||||
// TODO: respond to target deaths immediately, rather than waiting | "TargetDeath": function(msg) { | ||||
// until the next Timer event | this.SetNextState("COMBAT.FINDINGNEWTARGET"); | ||||
}, | |||||
"Attacked": function(msg) { | "Attacked": function(msg) { | ||||
// If we are capturing and are attacked by something that we would not capture, attack that entity instead | // If we are capturing and are attacked by something that we would not capture, attack that entity instead | ||||
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") | ||||
this.RespondToTargetedEntities([msg.data.attacker]); | this.RespondToTargetedEntities([msg.data.attacker]); | ||||
}, | }, | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
if (this.ShouldAbandonChase(this.order.data.target, this.order.data.force, IID_Attack, this.order.data.attackType)) | if (this.ShouldAbandonChase(this.order.data.target, this.order.data.force, IID_Attack, this.order.data.attackType)) | ||||
{ | { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
// Return to our original position | // Return to our original position | ||||
if (this.GetStance().respondHoldGround) | if (this.GetStance().respondHoldGround) | ||||
this.WalkToHeldPosition(); | this.WalkToHeldPosition(); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
this.RememberTargetPosition(); | this.RememberTargetPosition(); | ||||
Freagarach: Leftover from testing other patch. | |||||
if (this.order.data.hunting && this.orderQueue.length > 1 && | if (this.order.data.hunting && this.orderQueue.length > 1 && | ||||
this.orderQueue[1].type === "Gather") | this.orderQueue[1].type === "Gather") | ||||
this.RememberTargetPosition(this.orderQueue[1].data); | this.RememberTargetPosition(this.orderQueue[1].data); | ||||
} | } | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
if (msg.likelyFailure) | if (msg.likelyFailure) | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | "COMBAT": { | ||||
return false; | return false; | ||||
}, | }, | ||||
"leave": function() { | "leave": function() { | ||||
this.StopMoving(); | this.StopMoving(); | ||||
}, | }, | ||||
"MovementUpdate": function(msg) { | "MovementUpdate": function(msg) { | ||||
// If it looks like the path is failing, and we are close enough (3 tiles) from wanted range | // If it looks like the path is failing, and we are close enough (3 tiles) from wanted range | ||||
// stop anyways. This avoids pathing for an unreachable goal and reduces lag considerably. | // stop anyways. This avoids pathing for an unreachable goal and reduces lag considerably. | ||||
if (msg.likelyFailure || | if (msg.likelyFailure || | ||||
msg.obstructed && this.RelaxedMaxRangeCheck(this.order.data, this.order.data.max + this.DefaultRelaxedMaxRange) || | msg.obstructed && this.RelaxedMaxRangeCheck(this.order.data, this.order.data.max + this.DefaultRelaxedMaxRange) || | ||||
!msg.obstructed && this.CheckRange(this.order.data)) | !msg.obstructed && this.CheckRange(this.order.data)) | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 1,976 Lines • ▼ Show 20 Lines | UnitAI.prototype.OnAttacked = function(msg) | ||||
this.UnitFsm.ProcessMessage(this, {"type": "Attacked", "data": msg}); | this.UnitFsm.ProcessMessage(this, {"type": "Attacked", "data": msg}); | ||||
}; | }; | ||||
UnitAI.prototype.OnGuardedAttacked = function(msg) | UnitAI.prototype.OnGuardedAttacked = function(msg) | ||||
{ | { | ||||
this.UnitFsm.ProcessMessage(this, {"type": "GuardedAttacked", "data": msg.data}); | this.UnitFsm.ProcessMessage(this, {"type": "GuardedAttacked", "data": msg.data}); | ||||
}; | }; | ||||
UnitAI.prototype.OnTargetDeath = function(msg) | |||||
{ | |||||
if (this.order && this.order.data && this.order.data.target && this.order.data.target == msg.target) | |||||
this.UnitFsm.ProcessMessage(this, {"type": "TargetDeath", "target": msg.target}); | |||||
}; | |||||
UnitAI.prototype.OnHealthChanged = function(msg) | UnitAI.prototype.OnHealthChanged = function(msg) | ||||
{ | { | ||||
this.UnitFsm.ProcessMessage(this, {"type": "HealthChanged", "from": msg.from, "to": msg.to}); | this.UnitFsm.ProcessMessage(this, {"type": "HealthChanged", "from": msg.from, "to": msg.to}); | ||||
}; | }; | ||||
UnitAI.prototype.OnRangeUpdate = function(msg) | UnitAI.prototype.OnRangeUpdate = function(msg) | ||||
{ | { | ||||
if (msg.tag == this.losRangeQuery) | if (msg.tag == this.losRangeQuery) | ||||
▲ Show 20 Lines • Show All 1,365 Lines • ▼ Show 20 Lines | UnitAI.prototype.SetupTradeRoute = function(target, source, route, queued) | ||||
} | } | ||||
// AI has currently no access to BackToWork | // AI has currently no access to BackToWork | ||||
let cmpPlayer = QueryOwnerInterface(this.entity); | let cmpPlayer = QueryOwnerInterface(this.entity); | ||||
if (cmpPlayer && cmpPlayer.IsAI() && !this.IsFormationController() && | if (cmpPlayer && cmpPlayer.IsAI() && !this.IsFormationController() && | ||||
this.workOrders.length && this.workOrders[0].type == "Trade") | this.workOrders.length && this.workOrders[0].type == "Trade") | ||||
{ | { | ||||
let cmpTrader = Engine.QueryInterface(this.entity, IID_Trader); | let cmpTrader = Engine.QueryInterface(this.entity, IID_Trader); | ||||
if (cmpTrader.HasBothMarkets() && | if (cmpTrader.HasBothMarkets() && | ||||
(cmpTrader.GetFirstMarket() == target && cmpTrader.GetSecondMarket() == source || | (cmpTrader.GetFirstMarket() == target && cmpTrader.GetSecondMarket() == source || | ||||
cmpTrader.GetFirstMarket() == source && cmpTrader.GetSecondMarket() == target)) | cmpTrader.GetFirstMarket() == source && cmpTrader.GetSecondMarket() == target)) | ||||
{ | { | ||||
this.BackToWork(); | this.BackToWork(); | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 820 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Leftover from testing other patch.