From d1ed264c9bab8ed8824ceb3ea7e85d5fd947758f Mon Sep 17 00:00:00 2001 From: historic_bruno Date: Fri, 9 Mar 2012 23:33:55 +0000 Subject: [PATCH] Fixes stance change during garrison causing instant garrison. Fixes #1184. Adds range check to garrisoning, with element added to GarrisonHolder. Adds maximum range values to templates (2 for land units/structures, 10 for ships). Adds retry to garrison failure due to unreachable target. Cleans up a few templates. This was SVN commit r11292. --- .../simulation/components/GarrisonHolder.js | 20 +++++-- .../public/simulation/components/UnitAI.js | 53 ++++++++++++++----- .../templates/structures/rome_army_camp.xml | 4 +- .../template_structure_civic_civil_centre.xml | 7 +-- .../template_structure_civic_temple.xml | 7 +-- ...mplate_structure_defense_defense_tower.xml | 7 +-- .../template_structure_defense_outpost.xml | 7 +-- .../template_structure_defense_wall_tower.xml | 7 +-- .../template_structure_military_barracks.xml | 7 +-- .../template_structure_military_fortress.xml | 7 +-- .../template_structure_resource_corral.xml | 7 +-- .../templates/template_structure_special.xml | 7 +-- .../template_unit_mechanical_ship_bireme.xml | 1 + .../template_unit_mechanical_ship_fishing.xml | 1 + ...template_unit_mechanical_ship_merchant.xml | 1 + ...plate_unit_mechanical_ship_quinquereme.xml | 1 + .../template_unit_mechanical_ship_trireme.xml | 1 + .../template_unit_mechanical_siege_ram.xml | 7 +++ .../template_unit_mechanical_siege_tower.xml | 7 +-- .../units/celt_mechanical_siege_ram.xml | 3 -- .../units/iber_mechanical_siege_ram.xml | 6 --- .../units/rome_mechanical_siege_ram.xml | 6 --- 22 files changed, 109 insertions(+), 65 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/GarrisonHolder.js b/binaries/data/mods/public/simulation/components/GarrisonHolder.js index f1ed0de1a2..c675bd3b9c 100644 --- a/binaries/data/mods/public/simulation/components/GarrisonHolder.js +++ b/binaries/data/mods/public/simulation/components/GarrisonHolder.js @@ -1,20 +1,23 @@ function GarrisonHolder() {} GarrisonHolder.prototype.Schema = - "" + + "" + "" + "" + - "" + + "" + "" + "tokens" + "" + "" + "" + - "" + + "" + "" + "" + - "" + + "" + "" + + "" + + "" + + "" + ""; /** @@ -29,6 +32,15 @@ GarrisonHolder.prototype.Init = function() this.healRate = +this.template.BuffHeal; }; +/** + * Return range at which entities can garrison here + */ +GarrisonHolder.prototype.GetLoadingRange = function() +{ + var max = +this.template.LoadingRange; + return { "max": max, "min": 0 }; +}; + /** * Return the list of entities garrisoned inside */ diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index 4ffe7a209c..3bbe7b58a9 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -374,9 +374,7 @@ var UnitFsmSpec = { } else { - // TODO: this is probably bogus if the unit was - // unable to move at all - we need to do some range checks - // before actually garrisoning + // We do a range check before actually garrisoning this.StopMoving(); this.SetNextState("INDIVIDUAL.GARRISON.GARRISONED"); } @@ -1232,18 +1230,36 @@ var UnitFsmSpec = { "GARRISONED": { "enter": function() { var target = this.order.data.target; - // Check that we can still garrison here and that garrisoning succeeds var cmpGarrisonHolder = Engine.QueryInterface(target, IID_GarrisonHolder); - if (this.CanGarrison(target) && cmpGarrisonHolder.Garrison(this.entity)) + + // Check that we can garrison here + if (this.CanGarrison(target)) { - this.isGarrisoned = true; - } - else - { - // Garrisoning failed for some reason, so finish the order - if (this.FinishOrder()) - return; + // Check that we're in range of the garrison target + if (this.CheckGarrisonRange(target)) + { + // Check that garrisoning succeeds + if (cmpGarrisonHolder.Garrison(this.entity)) + { + this.isGarrisoned = true; + return; + } + } + else + { + // Unable to reach the target, try again + // (or follow if it's a moving target) + if (this.MoveToTarget(target)) + { + this.SetNextState("APPROACHING"); + return; + } + } } + + // Garrisoning failed for some reason, so finish the order + this.FinishOrder(); + return; }, "Order.Ungarrison": function() { @@ -2008,6 +2024,15 @@ UnitAI.prototype.CheckTargetRange = function(target, iid, type) return cmpUnitMotion.IsInTargetRange(target, range.min, range.max); }; +UnitAI.prototype.CheckGarrisonRange = function(target) +{ + var cmpGarrisonHolder = Engine.QueryInterface(target, IID_GarrisonHolder); + var range = cmpGarrisonHolder.GetLoadingRange(); + + var cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); + return cmpUnitMotion.IsInTargetRange(target, range.min, range.max); +} + /** * Returns true if the target entity is visible through the FoW/SoD. */ @@ -2516,7 +2541,9 @@ UnitAI.prototype.SwitchToStance = function(stance) this.SetHeldPosition(pos.x, pos.z); this.SetStance(stance); - if (stance == "stand" || stance == "defensive" || stance == "passive") + // Stop moving if switching to stand ground + // TODO: Also stop existing orders in a sensible way + if (stance == "stand") this.StopMoving(); // Reset the range query, since the range depends on stance diff --git a/binaries/data/mods/public/simulation/templates/structures/rome_army_camp.xml b/binaries/data/mods/public/simulation/templates/structures/rome_army_camp.xml index 073f1ac150..16a81c2ec5 100644 --- a/binaries/data/mods/public/simulation/templates/structures/rome_army_camp.xml +++ b/binaries/data/mods/public/simulation/templates/structures/rome_army_camp.xml @@ -39,9 +39,7 @@ 20 - 0.1 - Support Infantry Cavalry Siege - 1 + Support Infantry Cavalry Siege 3500 diff --git a/binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml b/binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml index 77ed511303..1eb22ef956 100644 --- a/binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml +++ b/binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml @@ -45,9 +45,10 @@ 20 - 0.1 - Support Infantry Cavalry - 1 + 0.1 + Support Infantry Cavalry + 1 + 2 3000 diff --git a/binaries/data/mods/public/simulation/templates/template_structure_civic_temple.xml b/binaries/data/mods/public/simulation/templates/template_structure_civic_temple.xml index 979d43f8e3..085683694c 100644 --- a/binaries/data/mods/public/simulation/templates/template_structure_civic_temple.xml +++ b/binaries/data/mods/public/simulation/templates/template_structure_civic_temple.xml @@ -27,9 +27,10 @@ 15 - 0.1 - Support Infantry Cavalry - 2 + 0.1 + Support Infantry Cavalry + 2 + 2 2000 diff --git a/binaries/data/mods/public/simulation/templates/template_structure_defense_defense_tower.xml b/binaries/data/mods/public/simulation/templates/template_structure_defense_defense_tower.xml index 997f70bd55..57fbb4183b 100644 --- a/binaries/data/mods/public/simulation/templates/template_structure_defense_defense_tower.xml +++ b/binaries/data/mods/public/simulation/templates/template_structure_defense_defense_tower.xml @@ -37,9 +37,10 @@ 5 - 0.1 - Support Infantry - 1 + 0.1 + Support Infantry + 1 + 2 1200 diff --git a/binaries/data/mods/public/simulation/templates/template_structure_defense_outpost.xml b/binaries/data/mods/public/simulation/templates/template_structure_defense_outpost.xml index b3341571de..40bf57e572 100644 --- a/binaries/data/mods/public/simulation/templates/template_structure_defense_outpost.xml +++ b/binaries/data/mods/public/simulation/templates/template_structure_defense_outpost.xml @@ -23,9 +23,10 @@ 1 - 0.1 - Support Infantry - 1 + 0.1 + Support Infantry + 1 + 2 800 diff --git a/binaries/data/mods/public/simulation/templates/template_structure_defense_wall_tower.xml b/binaries/data/mods/public/simulation/templates/template_structure_defense_wall_tower.xml index 8ed14c1b36..7bae621351 100644 --- a/binaries/data/mods/public/simulation/templates/template_structure_defense_wall_tower.xml +++ b/binaries/data/mods/public/simulation/templates/template_structure_defense_wall_tower.xml @@ -36,9 +36,10 @@ 5 - 0.1 - Support Infantry - 1 + 0.1 + Support Infantry + 1 + 2 2500 diff --git a/binaries/data/mods/public/simulation/templates/template_structure_military_barracks.xml b/binaries/data/mods/public/simulation/templates/template_structure_military_barracks.xml index 1b3c179e28..9a97a383f0 100644 --- a/binaries/data/mods/public/simulation/templates/template_structure_military_barracks.xml +++ b/binaries/data/mods/public/simulation/templates/template_structure_military_barracks.xml @@ -20,9 +20,10 @@ 10 - 0.1 - Infantry Cavalry - 1 + 0.1 + Infantry Cavalry + 1 + 2 2000 diff --git a/binaries/data/mods/public/simulation/templates/template_structure_military_fortress.xml b/binaries/data/mods/public/simulation/templates/template_structure_military_fortress.xml index 165e2618db..5a0b05fb63 100644 --- a/binaries/data/mods/public/simulation/templates/template_structure_military_fortress.xml +++ b/binaries/data/mods/public/simulation/templates/template_structure_military_fortress.xml @@ -38,9 +38,10 @@ 20 - 0.1 - Support Infantry Cavalry Siege - 1 + 0.1 + Support Infantry Cavalry Siege + 1 + 2 4200 diff --git a/binaries/data/mods/public/simulation/templates/template_structure_resource_corral.xml b/binaries/data/mods/public/simulation/templates/template_structure_resource_corral.xml index ee0e363285..c819c21ff7 100644 --- a/binaries/data/mods/public/simulation/templates/template_structure_resource_corral.xml +++ b/binaries/data/mods/public/simulation/templates/template_structure_resource_corral.xml @@ -17,9 +17,10 @@ 10 - 0.1 - Animal - 1 + 0.1 + Animal + 1 + 2 500 diff --git a/binaries/data/mods/public/simulation/templates/template_structure_special.xml b/binaries/data/mods/public/simulation/templates/template_structure_special.xml index 6b84c0fd4b..711e037890 100644 --- a/binaries/data/mods/public/simulation/templates/template_structure_special.xml +++ b/binaries/data/mods/public/simulation/templates/template_structure_special.xml @@ -18,9 +18,10 @@ 5 - 0.1 - Support Infantry Cavalry - 1 + 0.1 + Support Infantry Cavalry + 1 + 2 2000 diff --git a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_bireme.xml b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_bireme.xml index f045cc6903..a1d7d15c9c 100644 --- a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_bireme.xml +++ b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_bireme.xml @@ -33,6 +33,7 @@ 0 Support Infantry Cavalry 1 + 10 800 diff --git a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_fishing.xml b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_fishing.xml index afcbc81f4a..57145ece3c 100644 --- a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_fishing.xml +++ b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_fishing.xml @@ -23,6 +23,7 @@ 0 Support Infantry 1 + 10 Fishing Boat diff --git a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_merchant.xml b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_merchant.xml index a884d0e999..e7c23e2b50 100644 --- a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_merchant.xml +++ b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_merchant.xml @@ -16,6 +16,7 @@ 0 Support Infantry Cavalry 1 + 10 400 diff --git a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_quinquereme.xml b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_quinquereme.xml index f8bdc86394..5e3123dd05 100644 --- a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_quinquereme.xml +++ b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_quinquereme.xml @@ -33,6 +33,7 @@ 0 Support Infantry Cavalry Siege 1 + 10 2000 diff --git a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_trireme.xml b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_trireme.xml index af55a1dc50..83baf3037b 100644 --- a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_trireme.xml +++ b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_trireme.xml @@ -37,6 +37,7 @@ 0 Support Infantry Cavalry Siege 1 + 10 1400 diff --git a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_siege_ram.xml b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_siege_ram.xml index 652601e6b3..40b5955dfd 100644 --- a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_siege_ram.xml +++ b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_siege_ram.xml @@ -48,6 +48,13 @@ 100 + + 5 + 0.1 + Support Infantry + 1 + 2 + 200 diff --git a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_siege_tower.xml b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_siege_tower.xml index fa6b6e3e2a..22bfe3426a 100644 --- a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_siege_tower.xml +++ b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_siege_tower.xml @@ -25,9 +25,10 @@ 20 - 0.1 - Support Infantry - 1 + 0.1 + Support Infantry + 1 + 2 800 diff --git a/binaries/data/mods/public/simulation/templates/units/celt_mechanical_siege_ram.xml b/binaries/data/mods/public/simulation/templates/units/celt_mechanical_siege_ram.xml index b0baa5cc14..e671d2b5d5 100644 --- a/binaries/data/mods/public/simulation/templates/units/celt_mechanical_siege_ram.xml +++ b/binaries/data/mods/public/simulation/templates/units/celt_mechanical_siege_ram.xml @@ -16,9 +16,6 @@ 10 - 0.1 - Support Infantry - 1 250 diff --git a/binaries/data/mods/public/simulation/templates/units/iber_mechanical_siege_ram.xml b/binaries/data/mods/public/simulation/templates/units/iber_mechanical_siege_ram.xml index ecb8042752..bb2ce790ad 100644 --- a/binaries/data/mods/public/simulation/templates/units/iber_mechanical_siege_ram.xml +++ b/binaries/data/mods/public/simulation/templates/units/iber_mechanical_siege_ram.xml @@ -4,12 +4,6 @@ 3.0 - - 5 - 0.1 - Support Infantry - 1 - iber Ariete diff --git a/binaries/data/mods/public/simulation/templates/units/rome_mechanical_siege_ram.xml b/binaries/data/mods/public/simulation/templates/units/rome_mechanical_siege_ram.xml index 5bdc918a70..c91caecd97 100644 --- a/binaries/data/mods/public/simulation/templates/units/rome_mechanical_siege_ram.xml +++ b/binaries/data/mods/public/simulation/templates/units/rome_mechanical_siege_ram.xml @@ -20,12 +20,6 @@ 3.0 - - 5 - 0.1 - Support Infantry - 1 - rome Aries