forked from 0ad/0ad
Yves
3362c591f5
This avoids wrapping overhead that would otherwise be required because multiple globals per compartment aren't supported anymore in newer versions of SpiderMonkey. Check the ticket for a detailed explanation. Closes #2322 Refs #2241 Refs #1886 This was SVN commit r14441.
81 lines
2.0 KiB
JavaScript
81 lines
2.0 KiB
JavaScript
var AEGIS = function(m)
|
|
{
|
|
|
|
m.ResearchPlan = function(gameState, type, startTime, expectedTime, rush) {
|
|
this.type = type;
|
|
|
|
this.ID = m.playerGlobals[PlayerID].uniqueIDBOPlans++;
|
|
|
|
this.template = gameState.getTemplate(this.type);
|
|
if (!this.template || this.template.researchTime === undefined) {
|
|
return false;
|
|
}
|
|
this.category = "technology";
|
|
this.cost = new API3.Resources(this.template.cost(),0);
|
|
this.number = 1; // Obligatory for compatibility
|
|
|
|
if (!startTime)
|
|
this.startTime = 0;
|
|
else
|
|
this.startTime = startTime;
|
|
|
|
if (!expectedTime)
|
|
this.expectedTime = -1;
|
|
else
|
|
this.expectedTime = expectedTime;
|
|
|
|
if (rush)
|
|
this.rush = true;
|
|
else
|
|
this.rush = false;
|
|
|
|
return true;
|
|
};
|
|
|
|
// return true if we willstart amassing resource for this plan
|
|
m.ResearchPlan.prototype.isGo = function(gameState) {
|
|
return (gameState.getTimeElapsed() > this.startTime);
|
|
};
|
|
|
|
m.ResearchPlan.prototype.canStart = function(gameState) {
|
|
// also checks canResearch
|
|
return (gameState.findResearchers(this.type).length !== 0);
|
|
};
|
|
|
|
m.ResearchPlan.prototype.start = function(gameState) {
|
|
var self = this;
|
|
|
|
// TODO: this is special cased for "rush" technologies, ie the town phase
|
|
// which currently is a 100% focus.
|
|
gameState.ai.queueManager.unpauseAll();
|
|
|
|
//m.debug ("Starting the research plan for " + this.type);
|
|
var trainers = gameState.findResearchers(this.type).toEntityArray();
|
|
|
|
//for (var i in trainers)
|
|
// warn (this.type + " - " +trainers[i].genericName());
|
|
|
|
// Prefer training buildings with short queues
|
|
// (TODO: this should also account for units added to the queue by
|
|
// plans that have already been executed this turn)
|
|
if (trainers.length > 0){
|
|
trainers.sort(function(a, b) {
|
|
return (a.trainingQueueTime() - b.trainingQueueTime());
|
|
});
|
|
// drop anything in the queue if we rush it.
|
|
if (this.rush)
|
|
trainers[0].stopAllProduction(0.45);
|
|
trainers[0].research(this.type);
|
|
}
|
|
};
|
|
|
|
m.ResearchPlan.prototype.getCost = function(){
|
|
var costs = new API3.Resources();
|
|
costs.add(this.cost);
|
|
return costs;
|
|
};
|
|
|
|
|
|
return m;
|
|
}(AEGIS);
|