This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 9631 for ps


Ignore:
Timestamp:
06/18/11 00:13:39 (14 years ago)
Author:
Badmadblacksad
Message:

Stances draft, refs #865

Location:
ps/trunk
Files:
1 added
16 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/gui/session/input.js

    r9468 r9631  
    11461146}
    11471147
     1148// Performs the specified stance
     1149function performStance(entity, stanceName)
     1150{
     1151    if (entity)
     1152    {
     1153        var selection = g_Selection.toList();
     1154        Engine.PostNetworkCommand({
     1155            "type": "stance",
     1156            "entities": selection,
     1157            "name": stanceName
     1158        });
     1159    }
     1160}
     1161
    11481162// Set the camera to follow the given unit
    11491163function setCameraFollow(entity)
  • ps/trunk/binaries/data/mods/public/gui/session/session.js

    r9600 r9631  
    236236{
    237237    var guiName = "Group";
     238    g_Groups.update();
    238239    for (var i = 0; i < 10; i++)
    239240    {
    240241        var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]");
    241242        var label = getGUIObjectByName("unit"+guiName+"Label["+i+"]").caption = i;
    242         g_Groups.update();
    243243        if (g_Groups.groups[i].getTotalCount() == 0)
    244244            button.hidden = true;
  • ps/trunk/binaries/data/mods/public/gui/session/session.xml

    r9600 r9631  
    406406            </object>
    407407        </repeat>
     408    </object>
     409
     410    <!-- ================================  ================================ -->
     411    <!-- Stance Selection (Temporary location) -->
     412    <!-- ================================  ================================ -->
     413    <object name="unitStancePanel"
     414        sprite="bottomMiddle"
     415        size="50 50 300 106"
     416        type="text"
     417    >
     418        <object size="-5 -2 59 62" type="image" sprite="snIconSheetTab" tooltip_style="sessionToolTipBottom"
     419             cell_id="4" tooltip="Stances"/>
     420
     421        <object size="56 12 100% 100%">
     422            <repeat count="5">
     423                <object name="unitStanceButton[n]" hidden="true" style="iconButton" type="button" size="0 0 36 36" tooltip_style="sessionToolTipBottomBold" z="100">
     424                    <object name="unitStanceIcon[n]" type="image" ghost="true" size="3 3 33 33"/>
     425                </object>
     426            </repeat>
     427        </object>
    408428    </object>
    409429
     
    639659            </object>
    640660
    641             <object name="unitStancePanel"
    642                 style="goldPanelFrilly"
    643                 size="0 100%-56 100% 100%"
    644                 type="text"
    645             >
    646                 <object size="-5 -2 59 62" type="image" sprite="snIconSheetTab" tooltip_style="sessionToolTipBottom"
    647                      cell_id="4" tooltip="Stances"/>
    648 
    649                 [stance commands]
    650             </object>
    651 
    652661            <object name="unitResearchPanel"
    653662                style="goldPanelFrilly"
  • ps/trunk/binaries/data/mods/public/gui/session/unit_commands.js

    r9385 r9631  
    77const CONSTRUCTION = "Construction";
    88const COMMAND = "Command";
     9const STANCE = "Stance";
    910
    1011// Constants
     
    1415
    1516// The number of currently visible buttons (used to optimise showing/hiding)
    16 var g_unitPanelButtons = {"Selection": 0, "Queue": 0, "Formation": 0, "Garrison": 0, "Training": 0, "Construction": 0, "Command": 0};
     17var g_unitPanelButtons = {"Selection": 0, "Queue": 0, "Formation": 0, "Garrison": 0, "Training": 0, "Construction": 0, "Command": 0, "Stance": 0};
    1718
    1819// Unit panels are panels with row(s) of buttons
     
    121122                numberOfItems =  16;
    122123    }
    123     if (guiName == "Formation")
     124    else if (guiName == "Formation")
    124125    {
    125126        if (numberOfItems > 16)
    126127                numberOfItems =  16;
     128    }   
     129    else if (guiName == "Stance")
     130    {
     131        if (numberOfItems > 5)
     132                numberOfItems =  5;
    127133    }
    128134    else if (guiName == "Queue")
     
    154160        var entType = ((guiName == "Queue")? item.template : item);
    155161        var template;
    156         if (guiName != "Formation" && guiName != "Command")
     162        if (guiName != "Formation" && guiName != "Command" && guiName != "Stance")
    157163        {
    158164            template = GetTemplateData(entType);
     
    191197            break;
    192198
     199        case STANCE:
    193200        case FORMATION:
    194201            var tooltip = toTitleCase(item);
     
    265272                icon.sprite = "formation";
    266273            }
     274        }
     275        else if (guiName == "Stance")
     276        {
     277            var stanceSelected = Engine.GuiInterfaceCall("StanceSelected", {
     278                "ents": g_Selection.toList(),
     279                "stance": item
     280            });
     281
     282            icon.cell_id = i;
     283            if (stanceSelected)
     284                icon.sprite = "snIconSheetStanceButton";
     285            else
     286                icon.sprite = "snIconSheetStanceButtonDisabled";
    267287        }
    268288        else if (guiName == "Command")
     
    369389                function (item) { performFormation(entState.id, item); } );
    370390
     391        var stances = ["violent","aggressive","passive","defensive","stand"];
     392        if (isUnit(entState) && !isAnimal(entState) && !entState.garrisonHolder && stances.length)
     393            setupUnitPanel("Stance", usedPanels, entState, stances,
     394                function (item) { performStance(entState.id, item); } );
     395
    371396        if (entState.buildEntities && entState.buildEntities.length)
    372397        {
  • ps/trunk/binaries/data/mods/public/maps/scenarios/Combat_demo.xml

    r8800 r9631  
    4141    }
    4242  ],
    43   "RevealMap": true
     43  "RevealMap": true,
     44  "DefaultStance": "defensive"
    4445}
    4546]]></ScriptSettings>
  • ps/trunk/binaries/data/mods/public/maps/scenarios/Pathfinding_demo.xml

    r8800 r9631  
    4242  ],
    4343  "RevealMap": true,
    44   "DefaultStance": "holdfire",
     44  "DefaultStance": "defensive",
    4545  "GameType": "endless"
    4646}
  • ps/trunk/binaries/data/mods/public/simulation/components/Attack.js

    r9391 r9631  
    246246
    247247    Engine.PostMessage(data.target, MT_Attacked,
    248         { "attacker": this.entity, "target": data.target });
     248        { "attacker": this.entity, "target": data.target, "type": data.type });
    249249
    250250    PlaySound("attack_impact", this.entity);
  • ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js

    r9600 r9631  
    299299};
    300300
     301GuiInterface.prototype.StanceSelected = function(player, data)
     302{
     303    for each (var ent in data.ents)
     304    {
     305        var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
     306        if (cmpUnitAI)
     307        {
     308            if (cmpUnitAI.GetStanceName() == data.stance)
     309                return true;
     310        }
     311    }
     312    return false;
     313};
     314
    301315GuiInterface.prototype.SetSelectionHighlight = function(player, cmd)
    302316{
     
    554568
    555569    "CanMoveEntsIntoFormation": 1,
     570    "StanceSelected": 1,
    556571
    557572    "SetSelectionHighlight": 1,
  • ps/trunk/binaries/data/mods/public/simulation/components/Promotion.js

    r9391 r9631  
    6666    var cmpCurrentUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI);
    6767    var cmpPromotedUnitAI = Engine.QueryInterface(promotedUnitEntity, IID_UnitAI);
     68    cmpPromotedUnitAI.SetHeldPosition(cmpCurrentUnitAI.GetHeldPosition());
     69    if (cmpCurrentUnitAI.GetStanceName())
     70        cmpPromotedUnitAI.SetStance(cmpCurrentUnitAI.GetStanceName());
    6871    cmpPromotedUnitAI.Cheer();
    6972    var orders = cmpCurrentUnitAI.GetOrders();
  • ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js

    r9605 r9631  
    77        "<choice>" +
    88            "<value>aggressive</value>" +
    9             "<value>holdfire</value>" +
    10             "<value>noncombat</value>" +
     9            "<value>defensive</value>" +
     10            "<value>passive</value>" +
    1111        "</choice>" +
    1212    "</element>" +
     
    6060// dynamic stance changes).
    6161var g_Stances = {
     62    "violent": {
     63        targetVisibleEnemies: true,
     64        targetAttackers: true,
     65        respondFlee: false,
     66        respondChase: true,
     67        respondStandGround : false,
     68        respondHoldGround : false,
     69        respondChaseToHell : true,
     70    },
    6271    "aggressive": {
    6372        targetVisibleEnemies: true,
     
    6574        respondFlee: false,
    6675        respondChase: true,
    67     },
    68     "holdfire": {
    69         targetVisibleEnemies: false,
     76        respondStandGround : false,
     77        respondHoldGround : false,
     78    },
     79    "defensive": {
     80        targetVisibleEnemies: true,
    7081        targetAttackers: true,
    7182        respondFlee: false,
    72         respondChase: true,
    73     },
    74     "noncombat": {
     83        respondChase: false,
     84        respondStandGround : false,
     85        respondHoldGround : true,
     86    },
     87    "passive": {
    7588        targetVisibleEnemies: false,
    7689        targetAttackers: true,
    7790        respondFlee: true,
    7891        respondChase: false,
     92        respondStandGround : false,
     93        respondHoldGround : false,
     94    },
     95    "stand": {
     96        targetVisibleEnemies: true,
     97        targetAttackers: true,
     98        respondFlee: false,
     99        respondChase: false,
     100        respondStandGround : true,
     101        respondHoldGround : false,
    79102    },
    80103};
     
    115138    },
    116139
     140    "StanceChanged": function(msg) {
     141        if (this.StanceSpecificQuery(this.stance,true))
     142            return;
     143    },
     144
    117145    // Formation handlers:
    118146
     
    155183        }
    156184
     185        this.SetHeldPosition(this.order.data.x, this.order.data.z);
    157186        this.MoveToPoint(this.order.data.x, this.order.data.z);
    158187        this.SetNextState("INDIVIDUAL.WALKING");
     
    218247        this.attackType = type;
    219248
     249        if (this.CheckTargetRange(this.order.data.target, IID_Attack, this.attackType))
     250        {
     251            // We are already at the target
     252            // so try attacking it from here.
     253            this.StopMoving();
     254            if (this.IsAnimal())
     255                this.SetNextState("ANIMAL.COMBAT.ATTACKING");
     256            else
     257                this.SetNextState("INDIVIDUAL.COMBAT.ATTACKING");
     258        }
    220259        // Try to move within attack range
    221         if (this.MoveToTargetRange(this.order.data.target, IID_Attack, this.attackType))
     260        else if ((!this.GetStance().respondStandGround || this.order.data.force) && this.MoveToTargetRange(this.order.data.target, IID_Attack, this.attackType))
    222261        {
    223262            // We've started walking to the given point
     
    228267        }
    229268        else
    230         {
    231             // We are already at the target, or can't move at all,
    232             // so try attacking it from here.
    233             // TODO: need better handling of the can't-reach-target case
    234             this.StopMoving();
    235             if (this.IsAnimal())
    236                 this.SetNextState("ANIMAL.COMBAT.ATTACKING");
    237             else
    238                 this.SetNextState("INDIVIDUAL.COMBAT.ATTACKING");
    239         }
     269            this.FinishOrder();
    240270    },
    241271
     
    253283            }
    254284
    255             this.PushOrderFront("Attack", { "target": this.order.data.target });
     285            this.PushOrderFront("Attack", { "target": this.order.data.target, "force": false });
    256286            return;
    257287        }
     
    485515                // so immediately check whether there's anybody nearby to attack.
    486516                // (If anyone approaches later, it'll be handled via LosRangeUpdate.)
    487                 if (this.losRangeQuery)
    488                 {
    489                     var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    490                     var ents = rangeMan.ResetActiveQuery(this.losRangeQuery);
    491                     if (this.GetStance().targetVisibleEnemies)
    492                     {
    493                         if (this.RespondToTargetedEntities(ents))
    494                             return true; // (abort the FSM transition since we may have already switched state)
    495                     }
    496                 }
     517                if (this.StanceSpecificQuery(this.stance))
     518                    return true;
    497519
    498520                // Nobody to attack - stay in idle
     
    552574            },
    553575
     576            "StanceChanged": function(msg) {
     577                if (this.StanceSpecificQuery(this.stance))
     578                    return;
     579            },
    554580        },
    555581
     
    601627                "enter": function () {
    602628                    this.SelectAnimation("move");
     629                    this.StartTimer(1000, 1000);
     630                },
     631
     632                "leave": function() {
     633                    this.StopTimer();
     634                },
     635
     636                "Timer": function(msg) {
     637                    if (!this.ChaseTargetedEntity(this.order.data.target, this.order.data.force))
     638                    {
     639                        this.StopMoving();
     640                        this.FinishOrder();
     641
     642                        // we return to our position
     643                        if (this.GetStance().respondHoldGround)
     644                            this.WalkToHeldPosition();
     645                    }
    603646                },
    604647
    605648                "MoveCompleted": function() {
    606649                    this.SetNextState("ATTACKING");
     650                },
     651
     652                "Attacked": function(msg) {
     653                    // If we're attacked by a close enemy, we should try to defend ourself
     654                    if (this.GetStance().targetAttackers && msg.data.type == "Melee")
     655                    {
     656                        this.RespondToTargetedEntities([msg.data.attacker]);
     657                    }
    607658                },
    608659            },
     
    641692                        }
    642693
    643                         // Can't reach it - try to chase after it
    644                         if (this.MoveToTargetRange(this.order.data.target, IID_Attack, this.attackType))
     694                        if (this.ChaseTargetedEntity(this.order.data.target))
    645695                        {
    646                             this.SetNextState("COMBAT.CHASING");
     696                            if (this.MoveToTargetRange(this.order.data.target, IID_Attack, this.attackType))
     697                            {
     698                                this.SetNextState("COMBAT.CHASING");
     699                                return;
     700                            }
     701                        }
     702
     703                    }
     704
     705                    // Can't reach it, or it doesn't exist any more - give up
     706                    if (this.FinishOrder())
     707                        return;
     708
     709                    // see if we can switch to a new nearby enemy
     710                    if (this.StanceSpecificQuery(this.stance, true))
     711                        return;
     712
     713                    // we return to our position
     714                    if (this.GetStance().respondHoldGround)
     715                    {
     716                        if (this.WalkToHeldPosition())
    647717                            return;
    648                         }
    649718                    }
    650 
    651                     // Can't reach it, or it doesn't exist any more - give up
    652                     this.FinishOrder();
    653 
    654                     // TODO: see if we can switch to a new nearby enemy
    655719                },
    656720
     
    662726                "enter": function () {
    663727                    this.SelectAnimation("move");
    664                 },
    665            
     728                    this.StartTimer(1000, 1000);
     729                },
     730
     731                "leave": function() {
     732                    this.StopTimer();
     733                },
     734
     735                "Timer": function(msg) {
     736                    if (!this.ChaseTargetedEntity(this.order.data.target))
     737                    {
     738                        this.StopMoving();
     739                        this.FinishOrder();
     740
     741                        // we return to our position
     742                        if (this.GetStance().respondHoldGround)
     743                            this.WalkToHeldPosition();
     744                    }
     745                },
     746
    666747                "MoveCompleted": function() {
    667748                    this.SetNextState("ATTACKING");
     
    13041385UnitAI.prototype.SetupRangeQuery = function(owner)
    13051386{
    1306     var cmpVision = Engine.QueryInterface(this.entity, IID_Vision);
    1307     if (!cmpVision)
    1308         return;
    1309    
    13101387    var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    13111388    var playerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
    1312    
     1389
    13131390    if (this.losRangeQuery)
    13141391        rangeMan.DestroyActiveQuery(this.losRangeQuery);
    13151392
    1316     var range = cmpVision.GetRange();
    1317    
    13181393    var players = [];
    1319    
     1394
    13201395    if (owner != -1)
    13211396    {
     
    13351410        }
    13361411    }
    1337    
    1338     this.losRangeQuery = rangeMan.CreateActiveQuery(this.entity, 0, range, players, IID_DamageReceiver);
     1412
     1413    var range = this.StanceSpecificRange();
     1414
     1415    this.losRangeQuery = rangeMan.CreateActiveQuery(this.entity, 0, range.max, players, IID_DamageReceiver);
    13391416    rangeMan.EnableActiveQuery(this.losRangeQuery);
    1340 };
     1417}
    13411418
    13421419//// FSM linkage functions ////
     
    18341911}
    18351912
     1913UnitAI.prototype.CheckTargetDistanceFromHeldPosition = function(target, type)
     1914{
     1915    var cmpRanged = Engine.QueryInterface(this.entity, IID_Attack);
     1916    var range = cmpRanged.GetRange(type);
     1917
     1918    var cmpPosition = Engine.QueryInterface(target, IID_Position);
     1919    if (!cmpPosition || !cmpPosition.IsInWorld())
     1920        return false;
     1921
     1922    var cmpVision = Engine.QueryInterface(this.entity, IID_Vision);
     1923    if (!cmpVision)
     1924        return false;
     1925    var halfvision = cmpVision.GetRange() / 2;
     1926
     1927    var pos = cmpPosition.GetPosition();
     1928    var dx = this.heldPosition.x - pos.x;
     1929    var dz = this.heldPosition.z - pos.z;
     1930    var dist = Math.sqrt(dx*dx + dz*dz);
     1931
     1932    return dist < halfvision + range.max;
     1933};
     1934
     1935UnitAI.prototype.CheckTargetIsInVisionRange = function(target)
     1936{
     1937    var cmpVision = Engine.QueryInterface(this.entity, IID_Vision);
     1938    if (!cmpVision)
     1939        return false;
     1940    var range = cmpVision.GetRange();
     1941
     1942    var distance = DistanceBetweenEntities(this.entity,target);
     1943
     1944    return distance < range;
     1945}
     1946
    18361947UnitAI.prototype.GetBestAttack = function()
    18371948{
     
    18531964        if (this.CanAttack(target))
    18541965        {
    1855             this.PushOrderFront("Attack", { "target": target });
     1966            this.PushOrderFront("Attack", { "target": target, "force": false });
     1967            return true;
     1968        }
     1969    }
     1970    return false;
     1971};
     1972
     1973/**
     1974 * Try to find one of the given entities which can be attacked,
     1975 * within zone.
     1976 * Returns true if it found something to attack.
     1977 */
     1978UnitAI.prototype.AttackEntityInZone = function(ents)
     1979{
     1980    var type = this.GetBestAttack();
     1981    for each (var target in ents)
     1982    {
     1983        if (this.CanAttack(target) && this.CheckTargetDistanceFromHeldPosition(target, type))
     1984        {
     1985            this.PushOrderFront("Attack", { "target": target, "force": false });
    18561986            return true;
    18571987        }
     
    18732003        return this.AttackVisibleEntity(ents);
    18742004
     2005    if (this.GetStance().respondStandGround)
     2006        return this.AttackVisibleEntity(ents);
     2007
     2008    if (this.GetStance().respondHoldGround)
     2009        return this.AttackEntityInZone(ents);
     2010
    18752011    if (this.GetStance().respondFlee)
    18762012    {
     
    18812017    return false;
    18822018};
     2019
     2020/*
     2021 * Try to chase targeted entity given our current stance
     2022 */
     2023UnitAI.prototype.ChaseTargetedEntity = function(ent, force)
     2024{
     2025  if (this.GetStance().respondChase)
     2026  {
     2027    if (this.CheckTargetIsInVisionRange(ent))
     2028    {
     2029      return true;
     2030    }
     2031  }
     2032
     2033  if (this.GetStance().respondChaseToHell || force)
     2034  {
     2035    //if ( TODO : Check ent is not in Shroud of Darkness)
     2036    {
     2037      return true;
     2038    }
     2039  }
     2040
     2041  if (this.GetStance().respondHoldGround)
     2042  {
     2043    if (this.CheckTargetDistanceFromHeldPosition(ent, this.attackType))
     2044    {
     2045      return true;
     2046    }
     2047  }
     2048
     2049  return false;
     2050
     2051}
    18832052
    18842053//// External interface functions ////
     
    20222191    }
    20232192
    2024     this.AddOrder("Attack", { "target": target }, queued);
     2193    this.AddOrder("Attack", { "target": target, "force": true }, queued);
    20252194};
    20262195
     
    21072276    else
    21082277        error("UnitAI: Setting to invalid stance '"+stance+"'");
     2278}
     2279
     2280UnitAI.prototype.SwitchToStance = function(stance)
     2281{
     2282    var cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
     2283    if (!cmpPosition || !cmpPosition.IsInWorld())
     2284        return;
     2285    var pos = cmpPosition.GetPosition();
     2286    this.SetHeldPosition(pos.x, pos.z);
     2287
     2288    this.SetStance(stance);
     2289    if (stance == "stand" || stance == "defensive" || stance == "passive")
     2290        this.StopMoving();
     2291
     2292    UnitFsm.ProcessMessage(this, {"type": "StanceChanged", "stance": stance});
     2293}
     2294
     2295UnitAI.prototype.StanceSpecificQuery = function(stance, disable)
     2296{
     2297    if (!g_Stances[stance])
     2298    {
     2299        error("UnitAI: Setting to invalid stance '"+stance+"'");
     2300        return false;
     2301    }
     2302
     2303    if (!this.losRangeQuery)
     2304        return false;
     2305
     2306    var range = this.StanceSpecificRange();
     2307
     2308    var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     2309    var ents = rangeMan.ModifyRangeActiveQuery(this.losRangeQuery, range.min, range.max);
     2310
     2311    if (disable && !this.IsAnimal())
     2312        rangeMan.DisableActiveQuery(this.losRangeQuery);
     2313
     2314    return this.RespondToTargetedEntities(ents);
     2315};
     2316
     2317UnitAI.prototype.StanceSpecificRange = function()
     2318{
     2319    var ret = { "min": 0, "max": 0 };
     2320    if (this.GetStance().respondStandGround)
     2321    {
     2322        var cmpRanged = Engine.QueryInterface(this.entity, IID_Attack);
     2323        if (!cmpRanged)
     2324            return ret;
     2325        var range = cmpRanged.GetRange(cmpRanged.GetBestAttack());
     2326        ret.min = range.min;
     2327        ret.max = range.max;
     2328    }
     2329    else if (this.GetStance().respondChase)
     2330    {
     2331        var cmpVision = Engine.QueryInterface(this.entity, IID_Vision);
     2332        if (!cmpVision)
     2333            return ret;
     2334        var range = cmpVision.GetRange();
     2335        ret.max = range;
     2336    }
     2337    else if (this.GetStance().respondHoldGround)
     2338    {
     2339        var cmpRanged = Engine.QueryInterface(this.entity, IID_Attack);
     2340        if (!cmpRanged)
     2341            return ret;
     2342        var range = cmpRanged.GetRange(cmpRanged.GetBestAttack());
     2343        var cmpVision = Engine.QueryInterface(this.entity, IID_Vision);
     2344        if (!cmpVision)
     2345            return ret;
     2346        var halfvision = cmpVision.GetRange() / 2;
     2347        ret.max = range.max + halfvision;
     2348    }
     2349    return ret;
    21092350};
    21102351
     
    21122353{
    21132354    return g_Stances[this.stance];
     2355};
     2356
     2357UnitAI.prototype.GetStanceName = function()
     2358{
     2359    return this.stance;
    21142360};
    21152361
     
    22532499};
    22542500
     2501UnitAI.prototype.SetHeldPosition = function(x, z)
     2502{
     2503    this.heldPosition = {"x": x, "z": z};
     2504};
     2505
     2506UnitAI.prototype.GetHeldPosition = function(pos)
     2507{
     2508    return this.heldPosition;
     2509};
     2510
     2511UnitAI.prototype.WalkToHeldPosition = function()
     2512{
     2513    if (this.heldPosition)
     2514    {
     2515        this.Walk(this.heldPosition.x, this.heldPosition.z, false);
     2516        return true;
     2517    }
     2518    return false;
     2519};
     2520
    22552521Engine.RegisterComponentType(IID_UnitAI, "UnitAI", UnitAI);
  • ps/trunk/binaries/data/mods/public/simulation/helpers/Commands.js

    r9527 r9631  
    259259            if (cmpPromotion)
    260260                cmpPromotion.IncreaseXp(cmpPromotion.GetRequiredXp() - cmpPromotion.GetCurrentXp());
     261        }
     262        break;
     263
     264    case "stance":
     265        for each (var ent in cmd.entities)
     266        {
     267            var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
     268            if (cmpUnitAI)
     269                cmpUnitAI.SwitchToStance(cmd.name);
    261270        }
    262271        break;
  • ps/trunk/binaries/data/mods/public/simulation/helpers/Setup.js

    r8865 r9631  
    1515        {
    1616            var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
    17             cmpUnitAI.SetStance(settings.DefaultStance);
     17            cmpUnitAI.SwitchToStance(settings.DefaultStance);
    1818        }
    1919    }
  • ps/trunk/binaries/data/mods/public/simulation/templates/template_unit_support.xml

    r9010 r9631  
    99  </Minimap>
    1010  <UnitAI>
    11     <DefaultStance>noncombat</DefaultStance>
     11    <DefaultStance>passive</DefaultStance>
    1212  </UnitAI>
    1313  <Cost>
  • ps/trunk/source/simulation2/components/CCmpRangeManager.cpp

    r9362 r9631  
    458458
    459459        return (tag_t)id;
     460    }
     461
     462    virtual std::vector<entity_id_t> ModifyRangeActiveQuery(tag_t tag,
     463        entity_pos_t minRange, entity_pos_t maxRange)
     464    {
     465        std::map<tag_t, Query>::iterator it = m_Queries.find(tag);
     466        if (it == m_Queries.end())
     467        {
     468            LOGERROR(L"CCmpRangeManager: ModifyRangeActiveQuery called with invalid tag %d", tag);
     469            std::vector<entity_id_t> r;
     470            return r;
     471        }
     472
     473        Query& q = it->second;
     474        q.minRange = minRange;
     475        q.maxRange = maxRange;
     476        return ResetActiveQuery(tag);
    460477    }
    461478
  • ps/trunk/source/simulation2/components/ICmpRangeManager.cpp

    r8679 r9631  
    3737DEFINE_INTERFACE_METHOD_5("ExecuteQuery", std::vector<entity_id_t>, ICmpRangeManager, ExecuteQuery, entity_id_t, entity_pos_t, entity_pos_t, std::vector<int>, int)
    3838DEFINE_INTERFACE_METHOD_5("CreateActiveQuery", ICmpRangeManager::tag_t, ICmpRangeManager, CreateActiveQuery, entity_id_t, entity_pos_t, entity_pos_t, std::vector<int>, int)
     39DEFINE_INTERFACE_METHOD_3("ModifyRangeActiveQuery", std::vector<entity_id_t>, ICmpRangeManager, ModifyRangeActiveQuery, ICmpRangeManager::tag_t, entity_pos_t, entity_pos_t)
    3940DEFINE_INTERFACE_METHOD_1("DestroyActiveQuery", void, ICmpRangeManager, DestroyActiveQuery, ICmpRangeManager::tag_t)
    4041DEFINE_INTERFACE_METHOD_1("EnableActiveQuery", void, ICmpRangeManager, EnableActiveQuery, ICmpRangeManager::tag_t)
  • ps/trunk/source/simulation2/components/ICmpRangeManager.h

    r9362 r9631  
    103103
    104104    /**
     105     * Modify an active query's range parameters and execute a ResetActiveQuery.
     106     * @param tag identifier of query.
     107     * @param minRange non-negative minimum distance in metres (inclusive).
     108     * @param maxRange non-negative maximum distance in metres (inclusive); or -1.0 to ignore distance.
     109     * @return list of entities matching the query, ordered by increasing distance from the source entity.
     110     */
     111    virtual std::vector<entity_id_t> ModifyRangeActiveQuery(tag_t tag,
     112        entity_pos_t minRange, entity_pos_t maxRange) = 0;
     113
     114    /**
    105115     * Destroy a query and clean up resources. This must be called when an entity no longer needs its
    106116     * query (e.g. when the entity is destroyed).
Note: See TracChangeset for help on using the changeset viewer.