Ticket #1173: rallypoint-trade.patch
File rallypoint-trade.patch, 9.0 KB (added by , 12 years ago) |
---|
-
binaries/data/mods/public/gui/session/input.js
210 210 var gaiaOwned = (targetState.player == 0); 211 211 212 212 var cursor = ""; 213 var tooltip; 213 214 214 215 // default to walking there 215 216 var data = {command: "walk"}; … … 254 255 data.target = target; 255 256 cursor = "action-repair"; 256 257 } 258 else if (hasClass(entState, "Market") && hasClass(targetState, "Market") && entState.id != targetState.id && 259 (!hasClass(entState, "NavalMarket") || hasClass(targetState, "NavalMarket"))) 260 { 261 // Find a trader (if any) that this building can produce. 262 var trader; 263 if (entState.production && entState.production.entities.length) 264 for (var i = 0; i < entState.production.entities.length; ++i) 265 if ((trader = GetTemplateData(entState.production.entities[i]).trader)) 266 break; 267 268 var traderData = { "firstMarket": entState.id, "secondMarket": targetState.id, "template": trader }; 269 var gain = Engine.GuiInterfaceCall("GetTradingRouteGain", traderData); 270 if (gain !== null) 271 { 272 data.command = "trade"; 273 data.target = traderData.secondMarket; 274 data.source = traderData.firstMarket; 275 cursor = "action-setup-trade-route"; 276 tooltip = "Click to establish a default route for new traders. Gain: " + gain + " metal."; 277 } 278 } 257 279 258 return {"possible": true, "data": data, "position": targetState.position, "cursor": cursor };280 return {"possible": true, "data": data, "position": targetState.position, "cursor": cursor, "tooltip": tooltip}; 259 281 } 260 282 261 283 for each (var entityID in selection) … … 463 485 else if (getActionInfo("repair", target).possible) 464 486 return {"type": "build", "cursor": "action-repair", "target": target}; 465 487 else if ((actionInfo = getActionInfo("set-rallypoint", target)).possible) 466 return {"type": "set-rallypoint", "cursor": actionInfo.cursor, "data": actionInfo.data, " position": actionInfo.position};488 return {"type": "set-rallypoint", "cursor": actionInfo.cursor, "data": actionInfo.data, "tooltip": actionInfo.tooltip, "position": actionInfo.position}; 467 489 else if (getActionInfo("heal", target).possible) 468 490 return {"type": "heal", "cursor": "action-heal", "target": target}; 469 491 else if (getActionInfo("attack", target).possible) -
binaries/data/mods/public/simulation/helpers/RallyPointCommands.js
60 60 "queued": true 61 61 }); 62 62 break; 63 case "trade": 64 ret.push( { 65 "type": "setup-trade-route", 66 "entities": spawnedEnts, 67 "source": data[i].source, 68 "target": data[i].target, 69 "queued": true 70 }); 71 break; 63 72 default: 64 73 ret.push( { 65 74 "type": "walk", -
binaries/data/mods/public/simulation/helpers/Commands.js
379 379 { 380 380 var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); 381 381 if (cmpUnitAI) 382 cmpUnitAI.SetupTradeRoute(cmd.target );382 cmpUnitAI.SetupTradeRoute(cmd.target, cmd.source); 383 383 } 384 384 break; 385 385 -
binaries/data/mods/public/simulation/components/UnitAI.js
2919 2919 * Adds trade order to the queue. Either walk to the first market, or 2920 2920 * start a new route. Not forced, so it can be interrupted by attacks. 2921 2921 */ 2922 UnitAI.prototype.SetupTradeRoute = function(target, queued)2922 UnitAI.prototype.SetupTradeRoute = function(target, source, queued) 2923 2923 { 2924 2924 if (!this.CanTrade(target)) 2925 2925 { … … 2928 2928 } 2929 2929 2930 2930 var cmpTrader = Engine.QueryInterface(this.entity, IID_Trader); 2931 var marketsChanged = cmpTrader.SetTargetMarket(target );2931 var marketsChanged = cmpTrader.SetTargetMarket(target, source); 2932 2932 if (marketsChanged) 2933 2933 { 2934 2934 if (cmpTrader.HasBothMarkets()) -
binaries/data/mods/public/simulation/components/Trader.js
36 36 this.goods = { "type": null, "amount": 0 }; 37 37 } 38 38 39 Trader.prototype.CalculateGain = function(firstMarket, secondMarket )39 Trader.prototype.CalculateGain = function(firstMarket, secondMarket, template) 40 40 { 41 41 var cmpFirstMarketPosition = Engine.QueryInterface(firstMarket, IID_Position); 42 42 var cmpSecondMarketPosition = Engine.QueryInterface(secondMarket, IID_Position); … … 59 59 60 60 // For ship increase gain for each garrisoned trader 61 61 var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); 62 if (cmpIdentity .HasClass("Ship"))62 if (cmpIdentity && cmpIdentity.HasClass("Ship")) 63 63 { 64 64 var cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); 65 65 if (cmpGarrisonHolder) … … 75 75 } 76 76 } 77 77 78 if (this.template.GainMultiplier) 79 gain *= this.template.GainMultiplier; 78 // A template may be passed as an argument, serving as an override. 79 if (!template) 80 template = this.template; 81 82 if (template.GainMultiplier) 83 gain *= template.GainMultiplier; 80 84 gain = Math.round(gain); 81 85 return gain; 82 86 } … … 88 92 89 93 // Set target as target market. 90 94 // Return true if at least one of markets was changed. 91 Trader.prototype.SetTargetMarket = function(target )95 Trader.prototype.SetTargetMarket = function(target, source) 92 96 { 93 97 // Check that target is a market 94 98 var cmpTargetIdentity = Engine.QueryInterface(target, IID_Identity); … … 96 100 return false; 97 101 if (!cmpTargetIdentity.HasClass("Market") && !cmpTargetIdentity.HasClass("NavalMarket")) 98 102 return false; 99 var marketsChanged = false; 103 var marketsChanged = true; 104 if (source) 105 { 106 // Establish a trade route with both markets in one go. 107 cmpTargetIdentity = Engine.QueryInterface(source, IID_Identity); 108 if (!cmpTargetIdentity) 109 return false; 110 if (!cmpTargetIdentity.HasClass("Market") && !cmpTargetIdentity.HasClass("NavalMarket")) 111 return false; 112 113 this.firstMarket = source; 114 this.secondMarket = INVALID_ENTITY; 115 } 116 100 117 if (this.secondMarket) 101 118 { 102 119 // If we already have both markets - drop them 103 120 // and use the target as first market 104 121 this.firstMarket = target; 105 122 this.secondMarket = INVALID_ENTITY; 106 marketsChanged = true;107 123 } 108 124 else if (this.firstMarket) 109 125 { 110 126 // If we have only one market and target is different from it, 111 127 // set the target as second one 112 if (target != this.firstMarket) 128 if (target == this.firstMarket) 129 marketsChanged = false; 130 else 113 131 { 114 132 this.secondMarket = target; 115 133 this.gain = this.CalculateGain(this.firstMarket, this.secondMarket); 116 marketsChanged = true;117 134 } 118 135 } 119 136 else … … 121 138 // Else we don't have target markets at all, 122 139 // set the target as first market 123 140 this.firstMarket = target; 124 marketsChanged = true;125 141 } 126 142 if (marketsChanged) 127 143 { -
binaries/data/mods/public/simulation/components/GuiInterface.js
452 452 if (template.UnitMotion.Run) ret.speed.run = +template.UnitMotion.Run.Speed; 453 453 } 454 454 455 if (template.Trader) 456 ret.trader = template.Trader; 457 455 458 if (template.WallSet) 456 459 { 457 460 ret.wallSet = { … … 1468 1471 return 0; 1469 1472 }; 1470 1473 1474 GuiInterface.prototype.GetTradingRouteGain = function(player, data) 1475 { 1476 if (!data.firstMarket || !data.secondMarket) 1477 return null; 1478 1479 var cmpTrader = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trader); 1480 if (!cmpTrader) 1481 return null; 1482 1483 return cmpTrader.CalculateGain(data.firstMarket, data.secondMarket, data.template); 1484 } 1485 1471 1486 GuiInterface.prototype.GetTradingDetails = function(player, data) 1472 1487 { 1473 1488 var cmpEntityTrader = Engine.QueryInterface(data.trader, IID_Trader); … … 1588 1603 "GetFoundationSnapData": 1, 1589 1604 "PlaySound": 1, 1590 1605 "FindIdleUnit": 1, 1606 "GetTradingRouteGain": 1, 1591 1607 "GetTradingDetails": 1, 1592 1608 "CanAttack": 1, 1593 1609 -
source/simulation2/Simulation2.cpp
121 121 122 122 LOAD_SCRIPTED_COMPONENT("AIInterface"); 123 123 LOAD_SCRIPTED_COMPONENT("Barter"); 124 LOAD_SCRIPTED_COMPONENT("Trader"); 124 125 LOAD_SCRIPTED_COMPONENT("EndGameManager"); 125 126 LOAD_SCRIPTED_COMPONENT("GuiInterface"); 126 127 LOAD_SCRIPTED_COMPONENT("PlayerManager");