Ticket #3488: 3488.patch

File 3488.patch, 2.9 KB (added by Stan, 9 years ago)

You can now add a tag inside the garison point to restrict a certain type of unit. For instance if you type "Archer" no archer will garison on that point.

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

     
    4545                        "<element name='Z'>" +
    4646                            "<data type='decimal'/>" +
    4747                        "</element>" +
     48                        "<optional>" +
     49                            "<element name='VisibleGarrisonRestrictedClasses'>" +
     50                                "<text/>" +
     51                            "</element>" +
     52                        "</optional>" +
    4853                    "</interleave>" +
    4954                "</element>" +
    5055            "</zeroOrMore>" +
     
    7277            o.x = +offset.X;
    7378            o.y = +offset.Y;
    7479            o.z = +offset.Z;
    75             this.visibleGarrisonPoints.push({"offset":o, "entity": null});
     80            this.visibleGarrisonPoints.push({"offset":o, "entity": null,"restrictedClass" : offset.VisibleGarrisonRestrictedClasses});
    7681        }
    7782    }
    7883};
    7984
    8085/**
     86 * Returns an array of restricted classes from the original string.
     87 */
     88GarrisonHolder.prototype.GetVisibleGarrisonRestrictedClasses = function(classList)
     89{
     90    if (classList)
     91        return classList.split(/\s+/);
     92    return [];
     93};
     94
     95/**
    8196 * Return range at which entities can garrison here
    8297 */
    8398GarrisonHolder.prototype.GetLoadingRange = function()
     
    100115    return IsOwnedByPlayer(player, ent);
    101116};
    102117
    103 
    104118/**
    105119 * Return the list of entities garrisoned inside
    106120 */
     
    221235};
    222236
    223237/**
     238 * Returns true if the unit is allowed be visible on that garrison point, false otherwise.
     239 */
     240GarrisonHolder.prototype.AllowedToVisibleGarrisoning = function(visibleGarrisonPoint)
     241{
     242    var restrictedClassesList = this.GetVisibleGarrisonRestrictedClasses(visibleGarrisonPoint.restrictedClass);
     243    if (!allowedClasses)
     244        return false;
     245   
     246    for (let entityClasses of (Engine.QueryInterface(visibleGarrisonPoint.entity, IID_Identity)).GetClassesList())
     247        for (let restrictedClasses of restrictedClassesList)
     248            if (entityClasses == restrictedClasses)
     249                return false;
     250           
     251    return true;
     252}
     253
     254/**
    224255 * Garrison a unit inside.
    225256 * Returns true if successful, false if not
    226257 * The timer for AutoHeal is started here
     
    249280
    250281    if (visibleGarrisonPoint)
    251282    {
     283        let IsAllowed = this.AllowedToVisibleGarrisoning(visibleGarrisonPoint);
    252284        visibleGarrisonPoint.entity = entity;
    253         cmpPosition.SetTurretParent(this.entity, visibleGarrisonPoint.offset);
    254         let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
    255         if (cmpUnitAI)
    256             cmpUnitAI.SetTurretStance();
     285       
     286        if (IsAllowed)
     287        {
     288            cmpPosition.SetTurretParent(this.entity, visibleGarrisonPoint.offset);
     289            let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
     290            if (cmpUnitAI)
     291                cmpUnitAI.SetTurretStance();
     292        }
     293        else
     294        {
     295            cmpPosition.MoveOutOfWorld();
     296        }
    257297    }
    258298    else
    259299        cmpPosition.MoveOutOfWorld();
     
    713753    }
    714754};
    715755
    716 
    717756/**
    718757 * Eject all foreign garrisoned entities which are no more allied
    719758 */