Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/BuildingAI.js
Show First 20 Lines • Show All 280 Lines • ▼ Show 20 Lines | if (!this.targetUnits.length && !this.unitAITarget) | ||||
this.timer = undefined; | this.timer = undefined; | ||||
return; | return; | ||||
} | } | ||||
let cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); | let cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); | ||||
if (!cmpAttack) | if (!cmpAttack) | ||||
return; | return; | ||||
if (this.currentRound > roundCount - 1) | if (this.currentRound > roundCount - 1) | ||||
Freagarach: ^ | |||||
Done Inline ActionsThe sortof issue I have here, is that cmpPosition is not used directly in this function anymore. However removing the entire reference can lead to some perf loss, since we loop through. Probably we don't end up here anyway, since the query fails... Lets nuke bb: The sortof issue I have here, is that cmpPosition is not used directly in this function anymore. | |||||
this.currentRound = 0; | this.currentRound = 0; | ||||
if (this.currentRound == 0) | if (this.currentRound == 0) | ||||
this.arrowsLeft = this.GetArrowCount(); | this.arrowsLeft = this.GetArrowCount(); | ||||
let arrowsToFire = 0; | let arrowsToFire = 0; | ||||
if (this.currentRound == roundCount - 1) | if (this.currentRound == roundCount - 1) | ||||
arrowsToFire = this.arrowsLeft; | arrowsToFire = this.arrowsLeft; | ||||
Show All 28 Lines | if (this.unitAITarget && this.targetUnits.indexOf(this.unitAITarget) == -1) | ||||
addTarget(this.unitAITarget); | addTarget(this.unitAITarget); | ||||
for (let target of this.targetUnits) | for (let target of this.targetUnits) | ||||
addTarget(target); | addTarget(target); | ||||
// The obstruction manager performs approximate range checks. | // The obstruction manager performs approximate range checks. | ||||
// so we need to verify them here. | // so we need to verify them here. | ||||
// TODO: perhaps an optional 'precise' mode to range queries would be more performant. | // TODO: perhaps an optional 'precise' mode to range queries would be more performant. | ||||
let cmpObstructionManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ObstructionManager); | let cmpObstructionManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ObstructionManager); | ||||
let range = cmpAttack.GetRange(attackType); | let range = cmpAttack.GetRange(attackType); | ||||
Done Inline Actionssssshhh linter bb: sssshhh linter | |||||
let thisCmpPosition = Engine.QueryInterface(this.entity, IID_Position); | |||||
if (!thisCmpPosition.IsInWorld()) | |||||
return; | |||||
let s = thisCmpPosition.GetPosition(); | |||||
let firedArrows = 0; | let firedArrows = 0; | ||||
while (firedArrows < arrowsToFire && targets.length()) | while (firedArrows < arrowsToFire && targets.length()) | ||||
{ | { | ||||
let selectedTarget = targets.randomItem(); | let selectedTarget = targets.randomItem(); | ||||
if (this.CheckTargetVisible(selectedTarget) && cmpObstructionManager.IsInTargetParabolicRange( | |||||
let targetCmpPosition = Engine.QueryInterface(selectedTarget, IID_Position); | |||||
if (targetCmpPosition && targetCmpPosition.IsInWorld() && this.CheckTargetVisible(selectedTarget)) | |||||
{ | |||||
// Parabolic range compuation is the same as in UnitAI's MoveToTargetAttackRange. | |||||
// h is positive when I'm higher than the target. | |||||
let h = s.y - targetCmpPosition.GetPosition().y + range.elevationBonus; | |||||
if (h > -range.max / 2 && cmpObstructionManager.IsInTargetRange( | |||||
this.entity, | this.entity, | ||||
selectedTarget, | selectedTarget, | ||||
range.min, | range.min, | ||||
Math.sqrt(Math.square(range.max) + 2 * range.max * h), false)) | range.max, | ||||
range.elevationBonus, | |||||
false)) | |||||
Not Done Inline ActionsIdem. Freagarach: Idem. | |||||
Not Done Inline ActionsOne might want to do this outside of the loop. Freagarach: One might want to do this outside of the loop. | |||||
{ | { | ||||
cmpAttack.PerformAttack(attackType, selectedTarget); | cmpAttack.PerformAttack(attackType, selectedTarget); | ||||
PlaySound("attack_" + attackType.toLowerCase(), this.entity); | PlaySound("attack_" + attackType.toLowerCase(), this.entity); | ||||
++firedArrows; | ++firedArrows; | ||||
continue; | continue; | ||||
} | } | ||||
} | |||||
// Could not attack target, try a different target. | // Could not attack target, try a different target. | ||||
targets.remove(selectedTarget); | targets.remove(selectedTarget); | ||||
} | } | ||||
this.arrowsLeft -= firedArrows; | this.arrowsLeft -= firedArrows; | ||||
++this.currentRound; | ++this.currentRound; | ||||
}; | }; | ||||
Show All 21 Lines |
Wildfire Games · Phabricator
^