Ticket #3488: 3488.2.patch

File 3488.2.patch, 3.2 KB (added by Stan, 9 years ago)

Make them allowed classes instead, on the input of WowGetOffYourCellPhone. The unit has to have all the types in order to be allowed to garrison. Fix a bug where the garrison point was unvalidated if a unit had not the good requirements but entered before the first one.

  • binaries/data/mods/public/simulation/components/GarrisonHolder.js

     
    4545                        "<element name='Z'>" +
    4646                            "<data type='decimal'/>" +
    4747                        "</element>" +
     48                        "<optional>" +
     49                            "<element name='VisibleGarrisonAllowedClasses'>" +
     50                 "<attribute name='datatype'>" +
     51                    "<value>tokens</value>" +
     52                 "</attribute>" +
     53                        "<text/>" +
     54                            "</element>" +
     55                        "</optional>" +
    4856                    "</interleave>" +
    4957                "</element>" +
    5058            "</zeroOrMore>" +
     
    7280            o.x = +offset.X;
    7381            o.y = +offset.Y;
    7482            o.z = +offset.Z;
    75             this.visibleGarrisonPoints.push({"offset":o, "entity": null});
     83            this.visibleGarrisonPoints.push({"offset":o, "entity": null,"allowedClass" : offset.VisibleGarrisonAllowedClasses});
    7684        }
    7785    }
    7886};
     
    100108    return IsOwnedByPlayer(player, ent);
    101109};
    102110
    103 
    104111/**
    105112 * Return the list of entities garrisoned inside
    106113 */
     
    221228};
    222229
    223230/**
     231 * Returns an array of restricted classes from the original string.
     232 */
     233GarrisonHolder.prototype.GetVisibleGarrisonAllowedClasses = function(classList)
     234{
     235    if (classList)
     236    return classList._string.split(/\s+/);
     237
     238    return [];
     239};
     240
     241/**
     242 * Returns true if the unit is allowed be visible on that garrison point, false otherwise.
     243 */
     244GarrisonHolder.prototype.AllowedToVisibleGarrisoning = function(visibleGarrisonPoint)
     245{
     246    var allowedClassesList = this.GetVisibleGarrisonAllowedClasses(visibleGarrisonPoint.allowedClass);
     247    //If classlist is empty, everybody can garrison.
     248    if (!allowedClassesList)
     249        return true;
     250
     251    var entityClasses = (Engine.QueryInterface(visibleGarrisonPoint.entity, IID_Identity)).GetClassesList();
     252        for (let allowedClasses of allowedClassesList)       
     253            if(entityClasses.indexOf(allowedClasses) == -1)
     254                return false
     255           
     256    return true;
     257}
     258
     259/**
    224260 * Garrison a unit inside.
    225261 * Returns true if successful, false if not
    226262 * The timer for AutoHeal is started here
     
    246282            break;
    247283        }
    248284    }
    249 
    250285    if (visibleGarrisonPoint)
    251286    {
    252287        visibleGarrisonPoint.entity = entity;
    253         cmpPosition.SetTurretParent(this.entity, visibleGarrisonPoint.offset);
    254         let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
    255         if (cmpUnitAI)
    256             cmpUnitAI.SetTurretStance();
     288        let IsAllowed = this.AllowedToVisibleGarrisoning(visibleGarrisonPoint);
     289   
     290        if (IsAllowed)
     291        {
     292            cmpPosition.SetTurretParent(this.entity, visibleGarrisonPoint.offset);
     293            let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
     294            if (cmpUnitAI)
     295                cmpUnitAI.SetTurretStance();
     296        }
     297        else
     298        {
     299      visibleGarrisonPoint.entity = undefined; // We have to undefine the garrison point else it's marked as used.
     300            cmpPosition.MoveOutOfWorld();
     301        }
    257302    }
    258303    else
    259304        cmpPosition.MoveOutOfWorld();
    260 
    261305    return true;
    262306};
    263307
     
    713757    }
    714758};
    715759
    716 
    717760/**
    718761 * Eject all foreign garrisoned entities which are no more allied
    719762 */