Ticket #3791: sharedDropsites-v3.patch

File sharedDropsites-v3.patch, 19.1 KB (added by mimo, 8 years ago)
  • binaries/data/mods/public/gui/session/selection_panels.js

     
    224224    },
    225225    "setGraphics": function(data)
    226226    {
    227         data.icon.sprite = "stretched:session/icons/" + data.item.icon;
    228227        data.button.enabled = controlsPlayer(data.unitEntState.player);
     228        let grayscale = data.button.enabled ? "" : "grayscale:";
     229        data.icon.sprite = "stretched:" + grayscale + "session/icons/" + data.item.icon;
    229230    },
    230231    "setPosition": function(data)
    231232    {
     
    280281    },
    281282    "setGraphics": function(data)
    282283    {
    283         data.icon.sprite = "stretched:session/icons/" + data.item.icon;
    284         data.button.enabled = data.item.count > 0;
     284        data.button.enabled = data.item.count != undefined && data.item.count > 0;
     285        let grayscale = data.button.enabled ? "" : "grayscale:";
     286        data.icon.sprite = "stretched:" + grayscale + "session/icons/" + data.item.icon;
    285287    },
    286288    "setPosition": function(data)
    287289    {
  • binaries/data/mods/public/gui/session/unit_actions.js

     
    270270        },
    271271        "getActionInfo": function(entState, targetState)
    272272        {
    273             if (!targetState.resourceDropsite)
     273            if (!targetState.resourceDropsite || !targetState.resourceDropsite.sharable)
    274274                return false;
    275             if (!playerCheck(entState, targetState, ["Player"]))
     275            var playerState = GetSimState().players[entState.player];
     276            if (playerState.hasSharedDropsites && targetState.resourceDropsite.shared)
     277            {
     278                if (!playerCheck(entState, targetState, ["Player", "MutualAlly"]))
     279                    return false;
     280            }
     281            else if (!playerCheck(entState, targetState, ["Player"]))
    276282                return false;
    277283            if (!entState.resourceCarrying || !entState.resourceCarrying.length)
    278284                return false;
     
    872878        },
    873879    },
    874880    // Trading
    875      "select-trading-goods": {
     881    "select-trading-goods": {
    876882        "getInfo": function(entState)
    877883        {
    878884            if (!hasClass(entState, "Market"))
     
    887893            toggleTrade();
    888894        },
    889895    },
     896    // Dropsite sharing
     897    "share-dropsite": {
     898        "getInfo": function(entState)
     899        {
     900            if (!entState.resourceDropsite || !entState.resourceDropsite.sharable)
     901                return false;
     902            let playerState = GetSimState().players[entState.player];
     903            if (!playerState.isMutualAlly.some((e, i) => e && i != entState.player))
     904                return false;
     905            if (entState.resourceDropsite.shared)
     906                return {
     907                    "tooltip": translate("Press to prevent allies from using this dropsite"),
     908                    "icon": "lock_unlocked.png"
     909                };
     910            return {
     911                "tooltip": translate("Press to allow allies to use this dropsite"),
     912                "icon": "lock_locked.png"
     913            };
     914        },
     915        "execute": function(entState)
     916        {
     917            Engine.PostNetworkCommand({
     918                "type": "set-dropsite-sharing",
     919                "entities": [entState.id],
     920                "shared": !entState.resourceDropsite.shared
     921            });
     922        },
     923    }
    890924};
    891925
    892926var g_AllyEntityCommands =
     
    923957            unloadAllByOwner();
    924958        },
    925959    },
     960    // Dropsite sharing
     961    "share-dropsite": {
     962        "getInfo": function(entState)
     963        {
     964            if (!GetSimState().players[Engine.GetPlayerID()].hasSharedDropsites)
     965                return false;
     966            if (!entState.resourceDropsite || !entState.resourceDropsite.sharable)
     967                return false;
     968            if (entState.resourceDropsite.shared)
     969                return {
     970                    "tooltip": translate("You are allowed to use this dropsite"),
     971                    "icon": "lock_unlocked.png"
     972                };
     973            return {
     974                "tooltip": translate("The use of this dropsite is prohibited"),
     975                "icon": "lock_locked.png"
     976            };
     977        },
     978        "execute": function(entState)
     979        {
     980            // This command button is always disabled
     981        },
     982    }
    926983};
    927984
    928985function playerCheck(entState, targetState, validPlayers)
  • binaries/data/mods/public/simulation/ai/petra/baseManager.js

     
    264264            });
    265265        } */
    266266    }
     267
     268    // Allows all allies to use this dropsite except if base anchor to be sure to keep
     269    // a minimum of resources for this base
     270    Engine.PostCommand(PlayerID, {
     271        "type": "set-dropsite-sharing",
     272        "entities": [dropsiteId],
     273        "shared": dropsiteId !== this.anchorId
     274    });
    267275};
    268276
    269277// completely remove the dropsite resources from our list.
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    106106            "teamsLocked": cmpPlayer.GetLockTeams(),
    107107            "cheatsEnabled": cmpPlayer.GetCheatsEnabled(),
    108108            "disabledTemplates": cmpPlayer.GetDisabledTemplates(),
     109            "hasSharedDropsites": cmpPlayer.HasSharedDropsites(),
    109110            "phase": phase,
    110111            "isAlly": allies,
    111112            "isMutualAlly": mutualAllies,
     
    516517    let cmpResourceDropsite = Engine.QueryInterface(ent, IID_ResourceDropsite);
    517518    if (cmpResourceDropsite)
    518519        ret.resourceDropsite = {
    519             "types": cmpResourceDropsite.GetTypes()
     520            "types": cmpResourceDropsite.GetTypes(),
     521            "sharable": cmpResourceDropsite.IsSharable(),
     522            "shared": cmpResourceDropsite.IsShared()
    520523        };
    521524
    522525    let cmpPromotion = Engine.QueryInterface(ent, IID_Promotion);
  • binaries/data/mods/public/simulation/components/Player.js

     
    33Player.prototype.Schema =
    44    "<element name='SharedLosTech' a:help='Allies will share los when this technology is researched. Leave empty to never share LOS.'>" +
    55        "<text/>" +
     6    "</element>" +
     7    "<element name='SharedDropsitesTech' a:help='Allies will share dropsites when this technology is researched. Leave empty to never share dropsites.'>" +
     8        "<text/>" +
    69    "</element>";
    710
    811Player.prototype.Init = function()
     
    3134    this.teamsLocked = false;
    3235    this.state = "active"; // game state - one of "active", "defeated", "won"
    3336    this.diplomacy = [];    // array of diplomatic stances for this player with respect to other players (including gaia and self)
     37    this.sharedDropsites = false;
    3438    this.formations = [];
    3539    this.startCam = undefined;
    3640    this.controlAllUnits = false;
     
    507511    return (this.startCam !== undefined);
    508512};
    509513
     514Player.prototype.HasSharedDropsites = function()
     515{
     516    return this.sharedDropsites;
     517};
     518
    510519Player.prototype.SetControlAllUnits = function(c)
    511520{
    512521    this.controlAllUnits = c;
     
    682691{
    683692    if (msg.tech == this.template.SharedLosTech)
    684693        this.UpdateSharedLos();
     694    else if (msg.tech == this.template.SharedDropsitesTech)
     695        this.sharedDropsites = true;
    685696};
    686697
    687698Player.prototype.OnDiplomacyChanged = function()
  • binaries/data/mods/public/simulation/components/ResourceDropsite.js

     
    1212                "</choice>" +
    1313            "</zeroOrMore>" +
    1414        "</list>" +
     15    "</element>" +
     16    "<element name='Sharable' a:help='Allows allies to use this entity.'>" +
     17        "<data type='boolean'/>" +
    1518    "</element>";
    1619
    17 ResourceDropsite.prototype.Serialize = null;
     20ResourceDropsite.prototype.Init = function()
     21{
     22    this.sharable = this.template.Sharable == "true";
     23    this.shared = false;
     24};
    1825
    1926/**
    2027 * Returns the list of resource types accepted by this dropsite.
     
    3340    return this.GetTypes().indexOf(type) != -1;
    3441};
    3542
     43ResourceDropsite.prototype.IsSharable = function()
     44{
     45    return this.sharable;
     46};
     47
     48ResourceDropsite.prototype.IsShared = function()
     49{
     50    return this.shared;
     51};
     52
     53ResourceDropsite.prototype.SetSharing = function(value)
     54{
     55    if (this.sharable)
     56        this.shared = value;
     57};
     58
    3659Engine.RegisterComponentType(IID_ResourceDropsite, "ResourceDropsite", ResourceDropsite);
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    40834083    if (!cmpOwnership || cmpOwnership.GetOwner() == -1)
    40844084        return undefined;
    40854085
    4086     // Find dropsites owned by this unit's player
    4087     var players = [cmpOwnership.GetOwner()];
     4086    // Find dropsites owned by this unit's player or allied ones if allowed
     4087    var owner = cmpOwnership.GetOwner();
     4088    var players = [owner];
     4089    var cmpPlayer = QueryOwnerInterface(this.entity);
     4090    if (cmpPlayer && cmpPlayer.HasSharedDropsites())
     4091    {
     4092        let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
     4093        for (let i = 1; i < cmpPlayerManager.GetNumPlayers(); ++i)
     4094            if (i != owner && cmpPlayer.IsMutualAlly(i))
     4095                players.push(i);
     4096    }
    40884097
    40894098    var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    40904099    var nearby = cmpRangeManager.ExecuteQuery(this.entity, 0, -1, players, IID_ResourceDropsite);
     
    40944103    if (excludeLand)
    40954104        nearby = nearby.filter(e => Engine.QueryInterface(e, IID_Identity).HasClass("Naval"));
    40964105
    4097     return nearby.find(ent => Engine.QueryInterface(ent, IID_ResourceDropsite).AcceptsType(genericType));
     4106    return nearby.find(ent => {
     4107        let cmpResourceDropsite = Engine.QueryInterface(ent, IID_ResourceDropsite);
     4108        if (!cmpResourceDropsite.AcceptsType(genericType))
     4109            return false;
     4110        let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership);
     4111        return cmpOwnership.GetOwner() == owner || cmpResourceDropsite.IsShared();
     4112    });
    40984113};
    40994114
    41004115/**
     
    57695784            return false;
    57705785    }
    57715786
    5772     // Verify that the dropsite is owned by this entity's player
     5787    // Verify that the dropsite is owned by this entity's player (or an a mutual allied if allowed)
    57735788    var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
    5774     return cmpOwnership && IsOwnedByPlayer(cmpOwnership.GetOwner(), target);
     5789    var cmpPlayer = QueryOwnerInterface(this.entity);
     5790    if (cmpOwnership && IsOwnedByPlayer(cmpOwnership.GetOwner(), target))
     5791        return true;
     5792    return cmpPlayer && cmpPlayer.HasSharedDropsites() && cmpResourceDropsite.IsShared() &&
     5793           cmpOwnership && IsOwnedByMutualAllyOfPlayer(cmpOwnership.GetOwner(), target);
    57755794};
    57765795
    57775796UnitAI.prototype.CanTrade = function(target)
  • binaries/data/mods/public/simulation/data/technologies/unlock_shared_dropsites.json

     
     1{
     2    "genericName": "Diaspora",
     3    "description": "The extension of trade leads to the permanent establishment of storekeepers and their families in foreign countries, allowing them to exploit these countries wealth.",
     4    "cost": { "food": 200, "wood": 200, "stone": 100, "metal": 100 },
     5    "requirements": { "class": "Trader", "number": 3 },
     6    "requirementsTooltip": "Requires 3 Traders",
     7    "supersedes": "unlock_shared_los",
     8    "icon": "diaspora.png",
     9    "researchTime": 40,
     10    "tooltip": "Player can use his allies dropsites.",
     11    "modifications": [{ "value": "Player/sharedDropsites", "replace": true }],
     12    "soundComplete": "interface/alarm/alarm_upgradearmory.xml"
     13}
  • binaries/data/mods/public/simulation/helpers/Commands.js

     
    685685        // Currently nothing. Triggers can read it anyway, and send this
    686686        // message to any component you like.
    687687    },
     688
     689    "set-dropsite-sharing": function(player, cmd, data)
     690    {
     691        for (let ent of data.entities)
     692        {
     693            let cmpResourceDropsite = Engine.QueryInterface(ent, IID_ResourceDropsite);
     694            if (cmpResourceDropsite && cmpResourceDropsite.IsSharable())
     695                cmpResourceDropsite.SetSharing(cmd.shared);
     696        }
     697    },
    688698};
    689699
    690700/**
  • binaries/data/mods/public/simulation/templates/special/player.xml

     
    5555  </Identity>
    5656  <Player>
    5757    <SharedLosTech>unlock_shared_los</SharedLosTech>
     58    <SharedDropsitesTech>unlock_shared_dropsites</SharedDropsitesTech>
    5859  </Player>
    5960  <StatisticsTracker/>
    6061  <TechnologyManager/>
  • binaries/data/mods/public/simulation/templates/special/player_gaia.xml

     
    22<Entity>
    33  <Player>
    44    <SharedLosTech/>
     5    <SharedDropsitesTech/>
    56  </Player>
    67</Entity>
  • binaries/data/mods/public/simulation/templates/structures/brit_crannog.xml

     
    4747  </RallyPointRenderer>
    4848  <ResourceDropsite>
    4949    <Types>food wood stone metal</Types>
     50    <Sharable>true</Sharable>
    5051  </ResourceDropsite>
    5152  <VisualActor>
    5253    <Actor>structures/britons/crannog.xml</Actor>
  • binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml

     
    6868  <Identity>
    6969    <GenericName>Civic Center</GenericName>
    7070    <Tooltip>Build to acquire large tracts of territory. Train citizens. Garrison: 20.</Tooltip>
    71     <Classes datatype="tokens">
    72       Defensive
    73       CivCentre
    74     </Classes>
     71    <Classes datatype="tokens">Defensive CivCentre</Classes>
    7572    <VisibleClasses datatype="tokens">CivilCentre</VisibleClasses>
    7673    <Icon>structures/civic_centre.png</Icon>
    7774  </Identity>
     
    9794  </ProductionQueue>
    9895  <ResourceDropsite>
    9996    <Types>food wood stone metal</Types>
     97    <Sharable>true</Sharable>
    10098  </ResourceDropsite>
    10199  <Sound>
    102100    <SoundGroups>
     
    104102      <constructed>interface/complete/building/complete_civ_center.xml</constructed>
    105103      <attack>attack/weapon/arrowfly.xml</attack>
    106104      <death>attack/destruction/building_collapse_large.xml</death>
    107       <alert0>interface/alarm/alarm_alert_0.xml</alert0>
    108       <alert1>interface/alarm/alarm_alert_1.xml</alert1>
    109       <alert2>interface/alarm/alarm_alert_2.xml</alert2>
     105      <alert0>interface/alarm/alarm_alert_0.xml</alert0>
     106      <alert1>interface/alarm/alarm_alert_1.xml</alert1>
     107      <alert2>interface/alarm/alarm_alert_2.xml</alert2>
    110108    </SoundGroups>
    111109  </Sound>
    112110  <TerritoryInfluence>
  • binaries/data/mods/public/simulation/templates/template_structure_economic_farmstead.xml

     
    4949  <RallyPoint disable=""/>
    5050  <ResourceDropsite>
    5151    <Types>food</Types>
     52    <Sharable>true</Sharable>
    5253  </ResourceDropsite>
    5354  <Sound>
    5455    <SoundGroups>
  • binaries/data/mods/public/simulation/templates/template_structure_economic_market.xml

     
    5151    <BatchTimeModifier>0.7</BatchTimeModifier>
    5252    <Technologies datatype="tokens">
    5353      unlock_shared_los
     54      unlock_shared_dropsites
    5455      trade_convoys_speed
    5556      trade_convoys_armor
    5657      trade_gain_01
  • binaries/data/mods/public/simulation/templates/template_structure_economic_storehouse.xml

     
    2323  <Identity>
    2424    <GenericName>Storehouse</GenericName>
    2525    <Tooltip>Dropsite for wood, stone, and metal resources. Research gathering improvements for these resources.</Tooltip>
    26     <Classes datatype="tokens">
    27       DropsiteWood
    28       DropsiteMetal
    29       DropsiteStone
    30       -ConquestCritical
    31     </Classes>
     26    <Classes datatype="tokens">DropsiteWood DropsiteMetal DropsiteStone -ConquestCritical</Classes>
    3227    <VisibleClasses datatype="tokens">Village Storehouse</VisibleClasses>
    3328    <Icon>structures/storehouse.png</Icon>
    3429  </Identity>
     
    6257  <RallyPoint disable=""/>
    6358  <ResourceDropsite>
    6459    <Types>wood stone metal</Types>
     60    <Sharable>true</Sharable>
    6561  </ResourceDropsite>
    6662  <Sound>
    6763    <SoundGroups>
  • binaries/data/mods/public/simulation/templates/template_structure_military_dock.xml

     
    4545  </RallyPointRenderer>
    4646  <ResourceDropsite>
    4747    <Types>food wood stone metal</Types>
     48    <Sharable>true</Sharable>
    4849  </ResourceDropsite>
    4950  <Sound>
    5051    <SoundGroups>
     
    7172      armor_ship_hullsheathing
    7273    </Technologies>
    7374  </ProductionQueue>
    74   <Vision>
     75   <Vision>
    7576    <Range>40</Range>
    7677  </Vision>
    7778  <VisualActor>
  • binaries/data/mods/public/simulation/templates/units/maur_support_elephant.xml

     
    4444  </Position>
    4545  <ResourceDropsite>
    4646    <Types>food wood stone metal</Types>
     47    <Sharable>false</Sharable>
    4748  </ResourceDropsite>
    4849  <Selectable>
    4950    <Overlay>