Index: binaries/data/mods/public/simulation/components/BuildingAI.js
===================================================================
--- binaries/data/mods/public/simulation/components/BuildingAI.js
+++ binaries/data/mods/public/simulation/components/BuildingAI.js
@@ -310,24 +310,14 @@
}
// Add targets to a weighted list, to allow preferences.
- let targets = new WeightedList();
+ let targets = [];//use normal list instead, we don't need weights.
let maxPreference = this.MAX_PREFERENCE_BONUS;
- let addTarget = function(target)
- {
- let preference = cmpAttack.GetPreference(target);
- let weight = 1;
- if (preference !== null && preference !== undefined)
- weight += maxPreference / (1 + preference);
-
- targets.push(target, weight);
- };
-
// Add the UnitAI target separately, as the UnitMotion and RangeManager implementations differ.
if (this.unitAITarget && this.targetUnits.indexOf(this.unitAITarget) == -1)
- addTarget(this.unitAITarget);
+ targets.push(this.unitAITarget);
for (let target of this.targetUnits)
- addTarget(target);
+ targets.push(target);
// The obstruction manager performs approximate range checks.
// so we need to verify them here.
@@ -336,10 +326,29 @@
const range = cmpAttack.GetRange(attackType);
const yOrigin = cmpAttack.GetAttackYOrigin(attackType);
- let firedArrows = 0;
- while (firedArrows < arrowsToFire && targets.length())
- {
- const selectedTarget = targets.randomItem();
+ let firedArrows = 0;
+ let buildings = [];
+ while (firedArrows < arrowsToFire && targets.length)
+ {
+ let i = 0;
+ do {
+ let cmpIdentity = Engine.QueryInterface(targets[i], IID_Identity);
+ if (cmpIdentity && (cmpIdentity.GetClassesList().includes('Structure')||cmpIdentity.GetClassesList().includes('Siege'))){
+ buildings.push(i);
+ i++;
+ }
+ else {
+ break;
+ }
+ } while (i < targets.length)
+ let selection;
+ if (i < targets.length){
+ selection = targets[i];
+ }
+ else{
+ selection = targets[buildings[0]];
+ }
+ const selectedTarget = selection
if (this.CheckTargetVisible(selectedTarget) && cmpObstructionManager.IsInTargetParabolicRange(
this.entity,
selectedTarget,
@@ -355,7 +364,7 @@
}
// Could not attack target, try a different target.
- targets.remove(selectedTarget);
+ targets.splice(i,1);
}
this.arrowsLeft -= firedArrows;
Index: binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml
+++ binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml
@@ -17,7 +17,7 @@
2000
100
- 1.5
+ 3
50
false
Index: binaries/data/mods/public/simulation/templates/template_structure_military_fortress.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_structure_military_fortress.xml
+++ binaries/data/mods/public/simulation/templates/template_structure_military_fortress.xml
@@ -11,7 +11,7 @@
2000
100
- 1.5
+ 4
50
false