Ticket #1521: technology-queue.patch
File technology-queue.patch, 6.1 KB (added by , 12 years ago) |
---|
-
binaries/data/mods/public/gui/session/unit_commands.js
505 505 grayscale = "grayscale:"; 506 506 } 507 507 508 if (guiName == RESEARCH && !Engine.GuiInterfaceCall("CheckTechnologyRequirements", entType))508 if (guiName == RESEARCH && !Engine.GuiInterfaceCall("CheckTechnologyRequirements", { "tech": entType, "researcher": unitEntState.id })) 509 509 { 510 510 button.enabled = false; 511 511 button.tooltip += "\n" + GetTechnologyData(entType).requirementsTooltip; … … 520 520 { 521 521 grayscale = ""; 522 522 button1.enabled = true; 523 if (guiName == RESEARCH && !Engine.GuiInterfaceCall("CheckTechnologyRequirements", entType1))523 if (guiName == RESEARCH && !Engine.GuiInterfaceCall("CheckTechnologyRequirements", { "tech": entType1, "researcher": unitEntState.id })) 524 524 { 525 525 button1.enabled = false; 526 526 button1.tooltip += "\n" + GetTechnologyData(entType1).requirementsTooltip; -
binaries/data/mods/public/simulation/components/GuiInterface.js
521 521 }; 522 522 523 523 // Checks whether the requirements for this technology have been met 524 GuiInterface.prototype.CheckTechnologyRequirements = function(player, tech)524 GuiInterface.prototype.CheckTechnologyRequirements = function(player, data) 525 525 { 526 526 var cmpTechnologyManager = QueryPlayerIDInterface(player, IID_TechnologyManager); 527 527 528 528 if (!cmpTechnologyManager) 529 529 return false; 530 530 531 return cmpTechnologyManager.CanResearch( tech);531 return cmpTechnologyManager.CanResearch(data.tech, data.researcher); 532 532 }; 533 533 534 534 GuiInterface.prototype.PushNotification = function(notification) -
binaries/data/mods/public/simulation/components/ProductionQueue.js
233 233 // Tell the technology manager that we have started researching this so that people can't research the same 234 234 // thing twice. 235 235 var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager); 236 cmpTechMan.StartedResearch(templateName );236 cmpTechMan.StartedResearch(templateName, this.entity); 237 237 238 238 this.queue.push({ 239 239 "id": this.nextID++, … … 306 306 // Mark the research as stopped if we cancel it 307 307 if (item.technologyTemplate) 308 308 { 309 var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager); 309 // item.player is used as this.entity's owner may be invalid (deletion, etc.) 310 var cmpTechMan = QueryPlayerIDInterface(item.player, IID_TechnologyManager); 311 var template = cmpTechMan.GetTechnologyTemplate(item.technologyTemplate); 312 var removed = item.technologyTemplate; 313 if (template.pair) 314 removed = template.pair; 315 316 // Recurse to remove any technologies that supersede this one. 317 for (var j = i; j < this.queue.length; ++j) 318 { 319 if (!this.queue[j].technologyTemplate) 320 continue; 321 322 var queued = cmpTechMan.GetTechnologyTemplate(this.queue[j].technologyTemplate); 323 if (!queued.supersedes && queued.pair) 324 queued = cmpTechMan.GetTechnologyTemplate(queued.pair); 325 326 if (queued.supersedes == removed) 327 this.RemoveBatch(this.queue[j--].id); 328 } 310 329 cmpTechMan.StoppedResearch(item.technologyTemplate); 311 330 } 312 331 -
binaries/data/mods/public/simulation/components/TechnologyManager.js
90 90 }; 91 91 92 92 // Checks the requirements for a technology to see if it can be researched at the current time 93 TechnologyManager.prototype.CanResearch = function (tech )93 TechnologyManager.prototype.CanResearch = function (tech, researcher) 94 94 { 95 95 var template = this.GetTechnologyTemplate(tech); 96 96 if (!template) … … 98 98 warn("Technology \"" + tech + "\" does not exist"); 99 99 return false; 100 100 } 101 102 // The technology which this technology supersedes is required 101 102 // A technology can be researched if a technology that it supersedes 103 // is already being researched at the same building. 103 104 if (template.supersedes && !this.IsTechnologyResearched(template.supersedes)) 105 { 106 if (!researcher) 107 return false; 108 109 var oldtech = this.GetTechnologyTemplate(template.supersedes); 110 111 // Pairs are handled specially, as it's their members that are 112 // researched, not the actual pairs themselves. 113 if (oldtech.top) 114 { 115 if ((this.GetResearcher(oldtech.top) || this.GetResearcher(oldtech.bottom)) != researcher) 116 return false; 117 } 118 else if (this.GetResearcher(template.supersedes) != researcher) 119 return false; 120 } 121 if (template.pair && !this.CanResearch(template.pair, researcher)) 104 122 return false; 105 123 106 if (template.pair && !this.CanResearch(template.pair))107 return false;108 109 124 return this.CheckTechnologyRequirements(template.requirements); 110 125 }; 111 126 … … 326 341 } 327 342 328 343 // Marks a technology as being currently researched 329 TechnologyManager.prototype.StartedResearch = function (tech )344 TechnologyManager.prototype.StartedResearch = function (tech, researcher) 330 345 { 331 this.inProgressTechs[tech] = true;346 this.inProgressTechs[tech] = researcher; 332 347 }; 333 348 334 349 // Marks a technology as not being currently researched … … 346 361 return false; 347 362 }; 348 363 364 // Gets the entity currently researching a technology 365 TechnologyManager.prototype.GetResearcher = function(tech) 366 { 367 if (this.inProgressTechs[tech]) 368 return this.inProgressTechs[tech]; 369 return undefined; 370 }; 371 349 372 // Get helper data for tech modifications 350 373 TechnologyManager.prototype.GetTechModifications = function() 351 374 {