Ticket #3791: sharedDropsites-v3.patch
File sharedDropsites-v3.patch, 19.1 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/session/selection_panels.js
224 224 }, 225 225 "setGraphics": function(data) 226 226 { 227 data.icon.sprite = "stretched:session/icons/" + data.item.icon;228 227 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; 229 230 }, 230 231 "setPosition": function(data) 231 232 { … … 280 281 }, 281 282 "setGraphics": function(data) 282 283 { 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; 285 287 }, 286 288 "setPosition": function(data) 287 289 { -
binaries/data/mods/public/gui/session/unit_actions.js
270 270 }, 271 271 "getActionInfo": function(entState, targetState) 272 272 { 273 if (!targetState.resourceDropsite )273 if (!targetState.resourceDropsite || !targetState.resourceDropsite.sharable) 274 274 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"])) 276 282 return false; 277 283 if (!entState.resourceCarrying || !entState.resourceCarrying.length) 278 284 return false; … … 872 878 }, 873 879 }, 874 880 // Trading 875 881 "select-trading-goods": { 876 882 "getInfo": function(entState) 877 883 { 878 884 if (!hasClass(entState, "Market")) … … 887 893 toggleTrade(); 888 894 }, 889 895 }, 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 } 890 924 }; 891 925 892 926 var g_AllyEntityCommands = … … 923 957 unloadAllByOwner(); 924 958 }, 925 959 }, 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 } 926 983 }; 927 984 928 985 function playerCheck(entState, targetState, validPlayers) -
binaries/data/mods/public/simulation/ai/petra/baseManager.js
264 264 }); 265 265 } */ 266 266 } 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 }); 267 275 }; 268 276 269 277 // completely remove the dropsite resources from our list. -
binaries/data/mods/public/simulation/components/GuiInterface.js
106 106 "teamsLocked": cmpPlayer.GetLockTeams(), 107 107 "cheatsEnabled": cmpPlayer.GetCheatsEnabled(), 108 108 "disabledTemplates": cmpPlayer.GetDisabledTemplates(), 109 "hasSharedDropsites": cmpPlayer.HasSharedDropsites(), 109 110 "phase": phase, 110 111 "isAlly": allies, 111 112 "isMutualAlly": mutualAllies, … … 516 517 let cmpResourceDropsite = Engine.QueryInterface(ent, IID_ResourceDropsite); 517 518 if (cmpResourceDropsite) 518 519 ret.resourceDropsite = { 519 "types": cmpResourceDropsite.GetTypes() 520 "types": cmpResourceDropsite.GetTypes(), 521 "sharable": cmpResourceDropsite.IsSharable(), 522 "shared": cmpResourceDropsite.IsShared() 520 523 }; 521 524 522 525 let cmpPromotion = Engine.QueryInterface(ent, IID_Promotion); -
binaries/data/mods/public/simulation/components/Player.js
3 3 Player.prototype.Schema = 4 4 "<element name='SharedLosTech' a:help='Allies will share los when this technology is researched. Leave empty to never share LOS.'>" + 5 5 "<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/>" + 6 9 "</element>"; 7 10 8 11 Player.prototype.Init = function() … … 31 34 this.teamsLocked = false; 32 35 this.state = "active"; // game state - one of "active", "defeated", "won" 33 36 this.diplomacy = []; // array of diplomatic stances for this player with respect to other players (including gaia and self) 37 this.sharedDropsites = false; 34 38 this.formations = []; 35 39 this.startCam = undefined; 36 40 this.controlAllUnits = false; … … 507 511 return (this.startCam !== undefined); 508 512 }; 509 513 514 Player.prototype.HasSharedDropsites = function() 515 { 516 return this.sharedDropsites; 517 }; 518 510 519 Player.prototype.SetControlAllUnits = function(c) 511 520 { 512 521 this.controlAllUnits = c; … … 682 691 { 683 692 if (msg.tech == this.template.SharedLosTech) 684 693 this.UpdateSharedLos(); 694 else if (msg.tech == this.template.SharedDropsitesTech) 695 this.sharedDropsites = true; 685 696 }; 686 697 687 698 Player.prototype.OnDiplomacyChanged = function() -
binaries/data/mods/public/simulation/components/ResourceDropsite.js
12 12 "</choice>" + 13 13 "</zeroOrMore>" + 14 14 "</list>" + 15 "</element>" + 16 "<element name='Sharable' a:help='Allows allies to use this entity.'>" + 17 "<data type='boolean'/>" + 15 18 "</element>"; 16 19 17 ResourceDropsite.prototype.Serialize = null; 20 ResourceDropsite.prototype.Init = function() 21 { 22 this.sharable = this.template.Sharable == "true"; 23 this.shared = false; 24 }; 18 25 19 26 /** 20 27 * Returns the list of resource types accepted by this dropsite. … … 33 40 return this.GetTypes().indexOf(type) != -1; 34 41 }; 35 42 43 ResourceDropsite.prototype.IsSharable = function() 44 { 45 return this.sharable; 46 }; 47 48 ResourceDropsite.prototype.IsShared = function() 49 { 50 return this.shared; 51 }; 52 53 ResourceDropsite.prototype.SetSharing = function(value) 54 { 55 if (this.sharable) 56 this.shared = value; 57 }; 58 36 59 Engine.RegisterComponentType(IID_ResourceDropsite, "ResourceDropsite", ResourceDropsite); -
binaries/data/mods/public/simulation/components/UnitAI.js
4083 4083 if (!cmpOwnership || cmpOwnership.GetOwner() == -1) 4084 4084 return undefined; 4085 4085 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 } 4088 4097 4089 4098 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 4090 4099 var nearby = cmpRangeManager.ExecuteQuery(this.entity, 0, -1, players, IID_ResourceDropsite); … … 4094 4103 if (excludeLand) 4095 4104 nearby = nearby.filter(e => Engine.QueryInterface(e, IID_Identity).HasClass("Naval")); 4096 4105 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 }); 4098 4113 }; 4099 4114 4100 4115 /** … … 5769 5784 return false; 5770 5785 } 5771 5786 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) 5773 5788 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); 5775 5794 }; 5776 5795 5777 5796 UnitAI.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
685 685 // Currently nothing. Triggers can read it anyway, and send this 686 686 // message to any component you like. 687 687 }, 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 }, 688 698 }; 689 699 690 700 /** -
binaries/data/mods/public/simulation/templates/special/player.xml
55 55 </Identity> 56 56 <Player> 57 57 <SharedLosTech>unlock_shared_los</SharedLosTech> 58 <SharedDropsitesTech>unlock_shared_dropsites</SharedDropsitesTech> 58 59 </Player> 59 60 <StatisticsTracker/> 60 61 <TechnologyManager/> -
binaries/data/mods/public/simulation/templates/special/player_gaia.xml
2 2 <Entity> 3 3 <Player> 4 4 <SharedLosTech/> 5 <SharedDropsitesTech/> 5 6 </Player> 6 7 </Entity> -
binaries/data/mods/public/simulation/templates/structures/brit_crannog.xml
47 47 </RallyPointRenderer> 48 48 <ResourceDropsite> 49 49 <Types>food wood stone metal</Types> 50 <Sharable>true</Sharable> 50 51 </ResourceDropsite> 51 52 <VisualActor> 52 53 <Actor>structures/britons/crannog.xml</Actor> -
binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml
68 68 <Identity> 69 69 <GenericName>Civic Center</GenericName> 70 70 <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> 75 72 <VisibleClasses datatype="tokens">CivilCentre</VisibleClasses> 76 73 <Icon>structures/civic_centre.png</Icon> 77 74 </Identity> … … 97 94 </ProductionQueue> 98 95 <ResourceDropsite> 99 96 <Types>food wood stone metal</Types> 97 <Sharable>true</Sharable> 100 98 </ResourceDropsite> 101 99 <Sound> 102 100 <SoundGroups> … … 104 102 <constructed>interface/complete/building/complete_civ_center.xml</constructed> 105 103 <attack>attack/weapon/arrowfly.xml</attack> 106 104 <death>attack/destruction/building_collapse_large.xml</death> 107 108 109 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> 110 108 </SoundGroups> 111 109 </Sound> 112 110 <TerritoryInfluence> -
binaries/data/mods/public/simulation/templates/template_structure_economic_farmstead.xml
49 49 <RallyPoint disable=""/> 50 50 <ResourceDropsite> 51 51 <Types>food</Types> 52 <Sharable>true</Sharable> 52 53 </ResourceDropsite> 53 54 <Sound> 54 55 <SoundGroups> -
binaries/data/mods/public/simulation/templates/template_structure_economic_market.xml
51 51 <BatchTimeModifier>0.7</BatchTimeModifier> 52 52 <Technologies datatype="tokens"> 53 53 unlock_shared_los 54 unlock_shared_dropsites 54 55 trade_convoys_speed 55 56 trade_convoys_armor 56 57 trade_gain_01 -
binaries/data/mods/public/simulation/templates/template_structure_economic_storehouse.xml
23 23 <Identity> 24 24 <GenericName>Storehouse</GenericName> 25 25 <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> 32 27 <VisibleClasses datatype="tokens">Village Storehouse</VisibleClasses> 33 28 <Icon>structures/storehouse.png</Icon> 34 29 </Identity> … … 62 57 <RallyPoint disable=""/> 63 58 <ResourceDropsite> 64 59 <Types>wood stone metal</Types> 60 <Sharable>true</Sharable> 65 61 </ResourceDropsite> 66 62 <Sound> 67 63 <SoundGroups> -
binaries/data/mods/public/simulation/templates/template_structure_military_dock.xml
45 45 </RallyPointRenderer> 46 46 <ResourceDropsite> 47 47 <Types>food wood stone metal</Types> 48 <Sharable>true</Sharable> 48 49 </ResourceDropsite> 49 50 <Sound> 50 51 <SoundGroups> … … 71 72 armor_ship_hullsheathing 72 73 </Technologies> 73 74 </ProductionQueue> 74 <Vision>75 <Vision> 75 76 <Range>40</Range> 76 77 </Vision> 77 78 <VisualActor> -
binaries/data/mods/public/simulation/templates/units/maur_support_elephant.xml
44 44 </Position> 45 45 <ResourceDropsite> 46 46 <Types>food wood stone metal</Types> 47 <Sharable>false</Sharable> 47 48 </ResourceDropsite> 48 49 <Selectable> 49 50 <Overlay>