Ticket #3894: marketVisibility.patch
File marketVisibility.patch, 6.4 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Fogging.js
129 129 if (cmpResourceSupply) 130 130 cmpMirage.CopyResourceSupply(cmpResourceSupply); 131 131 132 var cmpMarket = Engine.QueryInterface(this.entity, IID_Market); 133 if (cmpMarket) 134 cmpMirage.CopyMarket(cmpMarket); 135 132 136 // Notify the GUI the entity has been replaced by a mirage, in case it is selected at this moment 133 137 var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 134 138 cmpGuiInterface.AddMiragedEntity(player, this.entity, this.mirages[player]); -
binaries/data/mods/public/simulation/components/GuiInterface.js
289 289 if (cmpBuilder) 290 290 ret.builder = true; 291 291 292 let cmpMarket = Engine.QueryInterface(ent, IID_Market);292 let cmpMarket = QueryMiragedInterface(ent, IID_Market); 293 293 if (cmpMarket) 294 294 ret.market = { 295 295 "land": cmpMarket.HasType("land"), -
binaries/data/mods/public/simulation/components/Market.js
33 33 return this.tradeType.has(type); 34 34 }; 35 35 36 Market.prototype.GetType = function() 37 { 38 return this.tradeType; 39 }; 40 36 41 /** 37 42 * Check if all traders with a route on this market can still trade 38 43 */ … … 59 64 if (!cmpTrader) 60 65 this.RemoveTrader(ent); 61 66 else if (msg.to == -1) 62 cmpTrader.RemoveMarket(this.entity); 67 { 68 let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership); 69 let cmpFogging = Engine.QueryInterface(this.entity, IID_Fogging); 70 if (cmpOwnership && cmpFogging && cmpFogging.IsMiraged(cmpOwnership.GetOwner())) 71 cmpTrader.SwitchMarket(this.entity, cmpFogging.GetMirage(cmpOwnership.GetOwner())); 72 else 73 cmpTrader.RemoveMarket(this.entity); 74 } 63 75 else if (!cmpTrader.CanTrade(this.entity)) 64 76 { 65 77 this.RemoveTrader(ent); -
binaries/data/mods/public/simulation/components/Mirage.js
34 34 this.killBeforeGather = null; 35 35 this.maxGatherers = null; 36 36 this.numGatherers = null; 37 38 this.marketType = null; 37 39 }; 38 40 41 Mirage.prototype.GetParent = function() 42 { 43 return this.parent; 44 }; 45 39 46 Mirage.prototype.SetParent = function(ent) 40 47 { 41 48 this.parent = ent; … … 125 132 Mirage.prototype.GetMaxGatherers = function() { return this.maxGatherers; }; 126 133 Mirage.prototype.GetNumGatherers = function() { return this.numGatherers; }; 127 134 135 // Market data 136 137 Mirage.prototype.CopyMarket = function(cmpMarket) 138 { 139 this.miragedIids.add(IID_Market); 140 this.marketType = cmpMarket.GetType(); 141 }; 142 143 Mirage.prototype.HasType = function(type) { return this.marketType.has(type); }; 144 128 145 // ============================ 129 146 130 147 Mirage.prototype.OnVisibilityChanged = function(msg) -
binaries/data/mods/public/simulation/components/Trader.js
45 45 { 46 46 var garrisonMultiplier = 1; 47 47 var garrisonedTradersCount = 0; 48 for each (var entity incmpGarrisonHolder.GetEntities())48 for (var entity of cmpGarrisonHolder.GetEntities()) 49 49 { 50 50 var cmpGarrisonedUnitTrader = Engine.QueryInterface(entity, IID_Trader); 51 51 if (cmpGarrisonedUnitTrader) … … 156 156 { 157 157 var cmpTraderIdentity = Engine.QueryInterface(this.entity, IID_Identity); 158 158 // Check that the target exists 159 var cmpTargetMarket = Engine.QueryInterface(target, IID_Market);159 var cmpTargetMarket = QueryMiragedInterface(target, IID_Market); 160 160 if (!cmpTargetMarket) 161 161 return false; 162 162 // Check that the target is not a foundation … … 248 248 }; 249 249 250 250 /** 251 * Called when this trader can no longer trade with the market 251 * The two following functions are called when this trader can no longer trade with the market: 252 * - if the market is destroyed and not visible, it is replaced by its mirage if it exists 253 * - otherwise the market is removed 252 254 */ 253 255 Trader.prototype.RemoveMarket = function(market) 254 256 { … … 257 259 this.markets.splice(index, 1); 258 260 }; 259 261 262 Trader.prototype.SwitchMarket = function(market, miragedMarket) 263 { 264 if (miragedMarket == INVALID_ENTITY) 265 { 266 this.RemoveMarket(market); 267 return; 268 } 269 let index = this.markets.indexOf(market); 270 if (index != -1) 271 this.markets[index] = miragedMarket; 272 }; 273 260 274 Trader.prototype.StopTrading = function() 261 275 { 262 276 for (let market of this.markets) -
binaries/data/mods/public/simulation/components/UnitAI.js
648 648 "Order.Trade": function(msg) { 649 649 // We must check if this trader has both markets in case it was a back-to-work order 650 650 var cmpTrader = Engine.QueryInterface(this.entity, IID_Trader); 651 if (!cmpTrader || ! 651 if (!cmpTrader || !cmpTrader.HasBothMarkets()) 652 652 { 653 653 this.FinishOrder(); 654 654 return; … … 5156 5156 return; 5157 5157 } 5158 5158 5159 // Register the parent when dealing with mirages 5160 if (target) 5161 { 5162 let cmpMirage = Engine.QueryInterface(target, IID_Mirage); 5163 if (cmpMirage) 5164 { 5165 let parent = cmpMirage.GetParent(); 5166 if (parent && Engine.QueryInterface(parent, IID_Market)) 5167 target = parent; 5168 } 5169 } 5170 if (source) 5171 { 5172 let cmpMirage = Engine.QueryInterface(source, IID_Mirage); 5173 if (cmpMirage) 5174 { 5175 let parent = cmpMirage.GetParent(); 5176 if (parent && Engine.QueryInterface(parent, IID_Market)) 5177 source = parent; 5178 } 5179 } 5180 5159 5181 var marketsChanged = this.SetTargetMarket(target, source); 5160 5182 if (!marketsChanged) 5161 5183 return;