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 9663 for ps


Ignore:
Timestamp:
06/26/11 04:03:36 (14 years ago)
Author:
Badmadblacksad
Message:

stances improvement and bugfixing. units now targets buildings last, after workers, and after every other units.

Location:
ps/trunk/binaries/data/mods/public/simulation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/simulation/components/Promotion.js

    r9631 r9663  
    6868    cmpPromotedUnitAI.SetHeldPosition(cmpCurrentUnitAI.GetHeldPosition());
    6969    if (cmpCurrentUnitAI.GetStanceName())
    70         cmpPromotedUnitAI.SetStance(cmpCurrentUnitAI.GetStanceName());
     70        cmpPromotedUnitAI.SwitchToStance(cmpCurrentUnitAI.GetStanceName());
    7171    cmpPromotedUnitAI.Cheer();
    7272    var orders = cmpCurrentUnitAI.GetOrders();
  • ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js

    r9661 r9663  
    284284
    285285    "Order.Gather": function(msg) {
    286         //If target is not visible anymore, give up
    287         if (!this.CheckTargetVisible(this.order.data.target))
    288         {
    289             this.FinishOrder();
    290             return;
    291         }
    292 
    293286        // If the target is still alive, we need to kill it first
    294         if (this.MustKillGatherTarget(this.order.data.target))
     287        if (this.MustKillGatherTarget(this.order.data.target) && this.CheckTargetVisible(this.order.data.target))
    295288        {
    296289            // Make sure we can attack the target, else we'll get very stuck
     
    382375
    383376        "Order.Walk": function(msg) {
     377            var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation);
     378            cmpFormation.CallMemberFunction("SetHeldPosition", [msg.data.x, msg.data.z]);
     379
    384380            this.MoveToPoint(this.order.data.x, this.order.data.z);
    385381            this.SetNextState("WALKING");
     
    734730                // TODO: respond to target deaths immediately, rather than waiting
    735731                // until the next Timer event
     732
     733                "Attacked": function(msg) {
     734                    if (this.order.data.target != msg.data.attacker)
     735                    {
     736                        // If we're attacked by a close enemy stronger than our current target, we choose to attack him
     737                        if (this.GetStance().targetAttackers && msg.data.type == "Melee")
     738                        {
     739                            var ents = [this.order.data.target, msg.data.attacker];
     740                            SortEntitiesByPriority(ents);
     741                            if (ents[0] != this.order.data.target)
     742                            {
     743                                this.RespondToTargetedEntities(ents);
     744                            }
     745                        }
     746                    }
     747                },
    736748            },
    737749
     
    23612373        return false;
    23622374
     2375    SortEntitiesByPriority(ents);
    23632376    return this.RespondToTargetedEntities(ents);
    23642377};
  • ps/trunk/binaries/data/mods/public/simulation/helpers/Entity.js

    r9631 r9663  
    1818}
    1919
     20/**
     21 *  Returns entities ordered by decreasing priority
     22 *  Do not alter order when units have the same priority
     23 */
     24function SortEntitiesByPriority(ents)
     25{
     26  // Priority list, weakers first
     27  var types = ["Structure", "Worker"];
     28
     29  ents.sort(function  (a, b) {
     30    var cmpIdentityA = Engine.QueryInterface(a, IID_Identity);
     31    var cmpIdentityB = Engine.QueryInterface(b, IID_Identity);
     32    if (!cmpIdentityA || !cmpIdentityB)
     33      return 0;
     34    var classesA = cmpIdentityA.GetClassesList();
     35    var classesB = cmpIdentityB.GetClassesList();
     36    for each (var type in types)
     37    {
     38      var inA = classesA.indexOf(type) != -1;
     39      var inB = classesB.indexOf(type) != -1;
     40      if (inA && !inB)
     41        return +1;
     42      if (inB && !inA)
     43        return -1;
     44    }
     45    return 0;
     46  });
     47}
     48
    2049Engine.RegisterGlobal("DistanceBetweenEntities", DistanceBetweenEntities);
     50Engine.RegisterGlobal("SortEntitiesByPriority", SortEntitiesByPriority);
Note: See TracChangeset for help on using the changeset viewer.