Ticket #1184: garrisonfix-03042012.patch

File garrisonfix-03042012.patch, 6.9 KB (added by historic_bruno, 12 years ago)
  • binaries/data/mods/public/simulation/components/GarrisonHolder.js

     
    11function GarrisonHolder() {}
    22
    33GarrisonHolder.prototype.Schema =
    4     "<element name='Max'>" +
     4    "<element name='Max' a:help='Maximum number of entities which can be garrisoned inside this holder'>" +
    55        "<data type='positiveInteger'/>" +
    66    "</element>" +
    7     "<element name='List'>" +
     7    "<element name='List' a:help='Classes of entities which are allowed to garrison inside this holder (from Identity)'>" +
    88        "<attribute name='datatype'>" +
    99            "<value>tokens</value>" +
    1010        "</attribute>" +
    1111        "<text/>" +
    1212    "</element>" +
    13     "<element name='EjectHealth'>" +
     13    "<element name='EjectHealth' a:help='Percentage of maximum health below which point this entity no longer allows garrisoning'>" +
    1414        "<ref name='nonNegativeDecimal'/>" +
    1515    "</element>" +
    16     "<element name='BuffHeal'>" +
     16    "<element name='BuffHeal' a:help='How many hit points will be restored every second'>" +
    1717        "<data type='positiveInteger'/>" +
    18     "</element>";
     18    "</element>" +
     19    "<optional>" +
     20        "<element name='LoadingRange' a:help='The maximum distance from this garrison holder at which entities are allowed to garrison (should be at least 2 since entities cannot move directly onto the garrison holder)'>" +
     21            "<ref name='nonNegativeDecimal'/>" +
     22        "</element>" +
     23    "</optional>";
    1924
    2025/**
    2126 * Initialize GarrisonHolder Component
     
    3035};
    3136
    3237/**
     38 * Return range at which entities can garrison here
     39 */
     40GarrisonHolder.prototype.GetLoadingRange = function()
     41{
     42    var max = +(this.template.LoadingRange || 2);
     43    return { "max": max, "min": 0 };
     44};
     45
     46/**
    3347 * Return the list of entities garrisoned inside
    3448 */
    3549GarrisonHolder.prototype.GetEntities = function()
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    366366        }
    367367        else
    368368        {
    369             // TODO: this is probably bogus if the unit was
    370             // unable to move at all - we need to do some range checks
    371             // before actually garrisoning
     369            // We do a range check before actually garrisoning
    372370            this.StopMoving();
    373371            this.SetNextState("INDIVIDUAL.GARRISON.GARRISONED");
    374372        }
     
    11981196                    var target = this.order.data.target;
    11991197                    // Check that we can still garrison here and that garrisoning succeeds
    12001198                    var cmpGarrisonHolder = Engine.QueryInterface(target, IID_GarrisonHolder);
    1201                     if (this.CanGarrison(target) && cmpGarrisonHolder.Garrison(this.entity))
     1199                    if (this.CanGarrison(target) && this.CheckGarrisonRange(target) && cmpGarrisonHolder.Garrison(this.entity))
    12021200                    {
    12031201                        this.isGarrisoned = true;
    12041202                    }
     
    19721970    return cmpUnitMotion.IsInTargetRange(target, range.min, range.max);
    19731971};
    19741972
     1973UnitAI.prototype.CheckGarrisonRange = function(target)
     1974{
     1975    var cmpGarrisonHolder = Engine.QueryInterface(target, IID_GarrisonHolder);
     1976    var range = cmpGarrisonHolder.GetLoadingRange();
     1977
     1978    var cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
     1979    return cmpUnitMotion.IsInTargetRange(target, range.min, range.max);
     1980}
     1981
    19751982/**
    19761983 * Returns true if the target entity is visible through the FoW/SoD.
    19771984 */
     
    24072414    this.SetHeldPosition(pos.x, pos.z);
    24082415
    24092416    this.SetStance(stance);
    2410     if (stance == "stand" || stance == "defensive" || stance == "passive")
     2417    // Stop moving if switching to stand ground
     2418    // TODO: Also stop existing orders in a sensible way
     2419    if (stance == "stand")
    24112420        this.StopMoving();
    24122421
    24132422    // Reset the range query, since the range depends on stance
  • binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_bireme.xml

     
    3333    <EjectHealth>0</EjectHealth>
    3434    <List datatype="tokens">Support Infantry Cavalry</List>
    3535    <BuffHeal>1</BuffHeal>
     36    <LoadingRange>10</LoadingRange>
    3637  </GarrisonHolder>
    3738  <Health>
    3839    <Max>800</Max>
  • binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_fishing.xml

     
    2323    <EjectHealth>0</EjectHealth>
    2424    <List datatype="tokens">Support Infantry</List>
    2525    <BuffHeal>1</BuffHeal>
     26    <LoadingRange>10</LoadingRange>
    2627  </GarrisonHolder>
    2728  <Identity>
    2829    <GenericName>Fishing Boat</GenericName>
  • binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_merchant.xml

     
    1616    <EjectHealth>0</EjectHealth>
    1717    <List datatype="tokens">Support Infantry Cavalry</List>
    1818    <BuffHeal>1</BuffHeal>
     19    <LoadingRange>10</LoadingRange>
    1920  </GarrisonHolder>
    2021  <Health>
    2122    <Max>400</Max>
  • binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_quinquereme.xml

     
    3333    <EjectHealth>0</EjectHealth>
    3434    <List datatype="tokens">Support Infantry Cavalry Siege</List>
    3535    <BuffHeal>1</BuffHeal>
     36    <LoadingRange>10</LoadingRange>
    3637  </GarrisonHolder>
    3738  <Health>
    3839    <Max>2000</Max>
  • binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_trireme.xml

     
    3737    <EjectHealth>0</EjectHealth>
    3838    <List datatype="tokens">Support Infantry Cavalry Siege</List>
    3939    <BuffHeal>1</BuffHeal>
     40    <LoadingRange>10</LoadingRange>
    4041  </GarrisonHolder>
    4142  <Health>
    4243    <Max>1400</Max>