Ticket #4085: sharing.patch

File sharing.patch, 5.7 KB (added by mimo, 8 years ago)
  • binaries/data/mods/public/simulation/ai/common-api/entity.js

     
    623623    decaying: function() { return this._entity.decaying !== undefined ? this._entity.decaying : undefined; },
    624624    capturePoints: function() {return this._entity.capturePoints !== undefined ? this._entity.capturePoints : undefined; },
    625625
     626    "isSharedDropsite": function() { return this._entity.sharedDropsite === true; },
     627
    626628    /**
    627629     * Returns the current training queue state, of the form
    628630     * [ { "id": 0, "template": "...", "count": 1, "progress": 0.5, "metadata": ... }, ... ]
  • binaries/data/mods/public/simulation/ai/common-api/gamestate.js

     
    595595m.GameState.prototype.getOwnDropsites = function(resource)
    596596{
    597597    if (resource !== undefined)
    598         return this.updatingCollection("dropsite-" + resource, m.Filters.isDropsite(resource), this.getOwnEntities());
    599     return this.updatingCollection("dropsite-all", m.Filters.isDropsite(), this.getOwnEntities());
     598        return this.updatingCollection("ownDropsite-" + resource, m.Filters.isDropsite(resource), this.getOwnEntities());
     599    return this.updatingCollection("ownDropsite-all", m.Filters.isDropsite(), this.getOwnEntities());
    600600};
    601601
     602m.GameState.prototype.getAnyDropsites = function(resource)
     603{
     604    if (resource !== undefined)
     605        return this.updatingGlobalCollection("anyDropsite-" + resource, m.Filters.isDropsite(resource), this.getEntities());
     606    return this.updatingGlobalCollection("anyDropsite-all", m.Filters.isDropsite(), this.getEntities());
     607};
     608
    602609m.GameState.prototype.getResourceSupplies = function(resource)
    603610{
    604611    return this.updatingGlobalCollection("resource-" + resource, m.Filters.byResource(resource), this.getEntities());
  • binaries/data/mods/public/simulation/ai/petra/entityExtend.js

     
    9999    let closestDropsite;
    100100    let distmin = Math.min();
    101101    let access = gameState.ai.accessibility.getAccessValue(ent.position());
    102     gameState.getOwnDropsites(resource).forEach(function(dropsite) {
    103         if (!dropsite.position() || dropsite.getMetadata(PlayerID, "access") !== access)
     102    let hasSharedDropsites = gameState.playerData.hasSharedDropsites;
     103    let dropsiteCollection = hasSharedDropsites ? gameState.getAnyDropsites(resource) : gameState.getOwnDropsites(resource);
     104    dropsiteCollection.forEach(function(dropsite) {
     105        if (!dropsite.position())
    104106            return;
     107        if (hasSharedDropsites && !gameState.isPlayerMutualAlly(dropsite.owner()))
     108            return;
     109        let dropsiteAccess = dropsite.getMetadata(PlayerID, "access");
     110        if (!dropsiteAccess)
     111        {
     112            dropsiteAccess = gameState.ai.accessibility.getAccessValue(dropsite.position());
     113            dropsite.setMetadata(PlayerID, "access", dropsiteAccess);
     114        }
     115        if (dropsiteAccess !== access)
     116            return;
    105117        let dist = API3.SquareVectorDistance(ent.position(), dropsite.position());
    106118        if (dist > distmin)
    107119            return;
  • binaries/data/mods/public/simulation/components/AIProxy.js

     
    193193    this.changes.foundationBuilders = msg.to;
    194194};
    195195
     196AIProxy.prototype.OnDropsiteSharingChanged = function(msg)
     197{
     198    if (!this.NotifyChange())
     199        return;
     200    this.changes.sharedDropsite = msg.shared;
     201};
     202
    196203AIProxy.prototype.OnTerritoryDecayChanged = function(msg)
    197204{
    198205    if (!this.NotifyChange())
     
    286293        ret.resourceCarrying = cmpResourceGatherer.GetCarryingStatus();
    287294    }
    288295
     296    let cmpResourceDropsite = Engine.QueryInterface(this.entity, IID_ResourceDropsite);
     297    if (cmpResourceDropsite)
     298    {
     299        // Updated by OnDropsiteSharingChanged
     300        ret.sharedDropsite = cmpResourceDropsite.IsShared();
     301    }
     302
    289303    let cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder);
    290304    if (cmpGarrisonHolder)
    291305    {
  • binaries/data/mods/public/simulation/components/ResourceDropsite.js

     
    5252
    5353ResourceDropsite.prototype.SetSharing = function(value)
    5454{
    55     if (this.sharable)
    56         this.shared = value;
     55    if (!this.sharable)
     56        return;
     57    this.shared = value;
     58    Engine.PostMessage(this.entity, MT_DropsiteSharingChanged, { "shared": this.shared });
    5759};
    5860
    5961Engine.RegisterComponentType(IID_ResourceDropsite, "ResourceDropsite", ResourceDropsite);
  • binaries/data/mods/public/simulation/components/interfaces/ResourceDropsite.js

     
    11Engine.RegisterInterface("ResourceDropsite");
     2
     3// Message of the form { "shared": true },
     4Engine.RegisterMessageType("DropsiteSharingChanged");