Ticket #1521: technology-queue.patch

File technology-queue.patch, 6.1 KB (added by Deiz, 12 years ago)
  • binaries/data/mods/public/gui/session/unit_commands.js

     
    505505                grayscale = "grayscale:";
    506506            }
    507507           
    508             if (guiName == RESEARCH && !Engine.GuiInterfaceCall("CheckTechnologyRequirements", entType))
     508            if (guiName == RESEARCH && !Engine.GuiInterfaceCall("CheckTechnologyRequirements", { "tech": entType, "researcher": unitEntState.id }))
    509509            {
    510510                button.enabled = false;
    511511                button.tooltip += "\n" + GetTechnologyData(entType).requirementsTooltip;
     
    520520                {
    521521                    grayscale = "";
    522522                    button1.enabled = true;
    523                     if (guiName == RESEARCH && !Engine.GuiInterfaceCall("CheckTechnologyRequirements", entType1))
     523                    if (guiName == RESEARCH && !Engine.GuiInterfaceCall("CheckTechnologyRequirements", { "tech": entType1, "researcher": unitEntState.id }))
    524524                    {
    525525                        button1.enabled = false;
    526526                        button1.tooltip += "\n" + GetTechnologyData(entType1).requirementsTooltip;
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    521521};
    522522
    523523// Checks whether the requirements for this technology have been met
    524 GuiInterface.prototype.CheckTechnologyRequirements = function(player, tech)
     524GuiInterface.prototype.CheckTechnologyRequirements = function(player, data)
    525525{
    526526    var cmpTechnologyManager = QueryPlayerIDInterface(player, IID_TechnologyManager);
    527527   
    528528    if (!cmpTechnologyManager)
    529529        return false;
    530530   
    531     return cmpTechnologyManager.CanResearch(tech);
     531    return cmpTechnologyManager.CanResearch(data.tech, data.researcher);
    532532};
    533533
    534534GuiInterface.prototype.PushNotification = function(notification)
  • binaries/data/mods/public/simulation/components/ProductionQueue.js

     
    233233            // Tell the technology manager that we have started researching this so that people can't research the same
    234234            // thing twice.
    235235            var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
    236             cmpTechMan.StartedResearch(templateName);
     236            cmpTechMan.StartedResearch(templateName, this.entity);
    237237
    238238            this.queue.push({
    239239                "id": this.nextID++,
     
    306306        // Mark the research as stopped if we cancel it
    307307        if (item.technologyTemplate)
    308308        {
    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            }
    310329            cmpTechMan.StoppedResearch(item.technologyTemplate);
    311330        }
    312331       
  • binaries/data/mods/public/simulation/components/TechnologyManager.js

     
    9090};
    9191
    9292// Checks the requirements for a technology to see if it can be researched at the current time
    93 TechnologyManager.prototype.CanResearch = function (tech)
     93TechnologyManager.prototype.CanResearch = function (tech, researcher)
    9494{
    9595    var template = this.GetTechnologyTemplate(tech);
    9696    if (!template)
     
    9898        warn("Technology \"" + tech + "\" does not exist");
    9999        return false;
    100100    }
    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.
    103104    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))
    104122        return false;
    105123   
    106     if (template.pair && !this.CanResearch(template.pair))
    107         return false;
    108    
    109124    return this.CheckTechnologyRequirements(template.requirements);
    110125};
    111126
     
    326341}
    327342
    328343// Marks a technology as being currently researched
    329 TechnologyManager.prototype.StartedResearch = function (tech)
     344TechnologyManager.prototype.StartedResearch = function (tech, researcher)
    330345{
    331     this.inProgressTechs[tech] = true;
     346    this.inProgressTechs[tech] = researcher;
    332347};
    333348
    334349// Marks a technology as not being currently researched
     
    346361        return false;
    347362};
    348363
     364// Gets the entity currently researching a technology
     365TechnologyManager.prototype.GetResearcher = function(tech)
     366{
     367    if (this.inProgressTechs[tech])
     368        return this.inProgressTechs[tech];
     369    return undefined;
     370};
     371
    349372// Get helper data for tech modifications
    350373TechnologyManager.prototype.GetTechModifications = function()
    351374{