Ticket #3488: 3488.3.diff

File 3488.3.diff, 3.0 KB (added by Stan, 8 years ago)

Not sure if it asserts all the above, could someone check ?

  • 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 */
     
    203210    return MatchesClassList(entityClasses, this.template.List._string);
    204211};
    205212
     213
    206214/**
     215 * Returns true if the unit is allowed be visible on that garrison point, false otherwise.
     216 */
     217GarrisonHolder.prototype.AllowedToVisibleGarrisoning = function(visibleGarrisonPoint)
     218{
     219    var allowedClassesList = visibleGarrisonPoint.allowedClass._string;
     220    //If classlist is empty, everybody can garrison.
     221    if (!allowedClassesList)
     222        return true;
     223   
     224    return MatchesClassList((Engine.QueryInterface(visibleGarrisonPoint.entity, IID_Identity)).GetClassesList(), allowedClassesList);
     225}
     226
     227/**
    207228 * Garrison a unit inside.
    208229 * Returns true if successful, false if not
    209230 * The timer for AutoHeal is started here
     
    229250            break;
    230251        }
    231252    }
    232 
    233253    if (visibleGarrisonPoint)
    234254    {
    235255        visibleGarrisonPoint.entity = entity;
    236         cmpPosition.SetTurretParent(this.entity, visibleGarrisonPoint.offset);
    237         let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
    238         if (cmpUnitAI)
    239             cmpUnitAI.SetTurretStance();
     256   
     257        if (this.AllowedToVisibleGarrisoning(visibleGarrisonPoint))
     258        {
     259            cmpPosition.SetTurretParent(this.entity, visibleGarrisonPoint.offset);
     260            let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
     261            if (cmpUnitAI)
     262                cmpUnitAI.SetTurretStance();
     263        }
     264        else
     265        {
     266            cmpPosition.MoveOutOfWorld();
     267        }
    240268    }
    241269    else
    242270        cmpPosition.MoveOutOfWorld();
    243 
    244271    return true;
    245272};
    246273
     
    634661
    635662/**
    636663 * Update list of garrisoned entities if one gets renamed (e.g. by promotion)
     664 * vgpEntity is only defined in some peculiar case where we want to reuse the same visibleGarrisonPoint,
     665 * in case of promotion for example, and thus should always be allowed.
    637666 */
    638667GarrisonHolder.prototype.OnGlobalEntityRenamed = function(msg)
    639668{
     
    670699    }
    671700};
    672701
    673 
    674702/**
    675703 * Eject all foreign garrisoned entities which are no more allied
    676704 */