Ticket #3791: sharedDropsites-v2.patch

File sharedDropsites-v2.patch, 17.7 KB (added by mimo, 4 years ago)

the player can now choose which dropsites can be used by its allies

  • binaries/data/mods/public/gui/session/selection_panels.js

     
    281281    "setGraphics": function(data)
    282282    {
    283283        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;
    285285    },
    286286    "setPosition": function(data)
    287287    {
  • 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({ "type": "toggle-dropsite-sharing", "entities": [entState.id] });
     918        },
     919    }
    890920};
    891921
    892922var g_AllyEntityCommands =
     
    923953            unloadAllByOwner();
    924954        },
    925955    },
     956    // Dropsite sharing
     957    "share-dropsite": {
     958        "getInfo": function(entState)
     959        {
     960            if (!entState.resourceDropsite || !entState.resourceDropsite.sharable)
     961                return false;
     962            if (entState.resourceDropsite.shared)
     963                return {
     964                    "tooltip": translate("You are allowed to use this dropsite"),
     965                    "icon": "lock_unlocked.png"
     966                };
     967            return {
     968                "tooltip": translate("The use of this dropsite is prohibited"),
     969                "icon": "lock_locked.png"
     970            };
     971        },
     972        "execute": function(entState)
     973        {
     974            // This command button is always disabled, TODO find a better place to display this info
     975        },
     976    }
    926977};
    927978
    928979function playerCheck(entState, targetState, validPlayers)
  • 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;
     
    509513    return (this.startCam !== undefined);
    510514};
    511515
     516Player.prototype.HasSharedDropsites = function()
     517{
     518    return this.sharedDropsites;
     519};
     520
    512521Player.prototype.SetControlAllUnits = function(c)
    513522{
    514523    this.controlAllUnits = c;
     
    679688{
    680689    if (msg.tech == this.template.SharedLosTech)
    681690        this.UpdateSharedLos();
     691    else if (msg.tech == this.template.SharedDropsitesTech)
     692        this.sharedDropsites = true;
    682693};
    683694
    684695Player.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.ToggleSharing = function()
     54{
     55    if (this.sharable)
     56        this.shared = !this.shared;
     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/**
     
    57695785            return false;
    57705786    }
    57715787
    5772     // Verify that the dropsite is owned by this entity's player
     5788    // Verify that the dropsite is owned by this entity's player (or an a mutual allied if allowed)
    57735789    var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
    5774     return cmpOwnership && IsOwnedByPlayer(cmpOwnership.GetOwner(), target);
     5790    var cmpPlayer = QueryOwnerInterface(this.entity);
     5791    if (cmpOwnership && IsOwnedByPlayer(cmpOwnership.GetOwner(), target))
     5792        return true;
     5793    return cmpPlayer && cmpPlayer.HasSharedDropsites() && cmpResourceDropsite.IsShared() &&
     5794           cmpOwnership && IsOwnedByMutualAllyOfPlayer(cmpOwnership.GetOwner(), target);
    57755795};
    57765796
    57775797UnitAI.prototype.CanTrade = function(target)
  • binaries/data/mods/public/simulation/data/technologies/unlock_shared_dropsites.json

     
     1{
     2    "genericName": "Coinage",
     3    "description": "Coinage increases the exchange of merchandises between civilizations.",
     4    "cost": { "food": 200, "wood": 200, "stone": 100, "metal": 0 },
     5    "requirements": { "tech": "phase_town" },
     6    "requirementsTooltip": "Unlocked in Town Phase.",
     7    "icon": "coinage.png",
     8    "researchTime": 40,
     9    "tooltip": "Player can use his allies dropsites.",
     10    "modifications": [{ "value": "Player/sharedDropsites", "replace": true }],
     11    "soundComplete": "interface/alarm/alarm_upgradearmory.xml"
     12}
  • binaries/data/mods/public/simulation/helpers/Commands.js

     
    677677        // Currently nothing. Triggers can read it anyway, and send this
    678678        // message to any component you like.
    679679    },
     680
     681    "toggle-dropsite-sharing": function(player, cmd, data)
     682    {
     683        for (let ent of data.entities)
     684        {
     685            let cmpResourceDropsite = Engine.QueryInterface(ent, IID_ResourceDropsite);
     686            if (cmpResourceDropsite && cmpResourceDropsite.IsSharable())
     687                cmpResourceDropsite.ToggleSharing();
     688        }
     689    },
    680690};
    681691
    682692/**
  • binaries/data/mods/public/simulation/templates/special/player.xml

     
    4949    </LimitRemovers>
    5050  </EntityLimits>
    5151  <Player>
    52     <SharedLosTech>unlock_shared_los</SharedLosTech>
     52    <SharedLosTech>unlock_shared_los</SharedLosTech>
     53    <SharedDropsitesTech>unlock_shared_dropsites</SharedDropsitesTech>
    5354  </Player>
    5455  <StatisticsTracker/>
    5556  <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>