2013-12-30 11:04:59 +01:00
|
|
|
var AEGIS = function(m)
|
|
|
|
{
|
|
|
|
|
2014-01-14 20:54:31 +01:00
|
|
|
m.ResearchPlan = function(gameState, type, rush) {
|
|
|
|
if (!m.QueuePlan.call(this, gameState, type, {}))
|
|
|
|
return false;
|
2013-09-29 15:32:52 +02:00
|
|
|
|
2014-01-14 20:54:31 +01:00
|
|
|
if (this.template.researchTime === undefined)
|
2013-08-17 15:59:53 +02:00
|
|
|
return false;
|
2014-01-14 20:54:31 +01:00
|
|
|
|
2013-08-17 15:59:53 +02:00
|
|
|
this.category = "technology";
|
2013-09-29 15:32:52 +02:00
|
|
|
|
2014-01-14 20:54:31 +01:00
|
|
|
this.rush = rush ? true : false;
|
2013-09-29 15:32:52 +02:00
|
|
|
|
2013-08-17 15:59:53 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2014-01-14 20:54:31 +01:00
|
|
|
m.ResearchPlan.prototype = Object.create(m.QueuePlan.prototype);
|
2013-08-17 15:59:53 +02:00
|
|
|
|
2013-12-30 11:04:59 +01:00
|
|
|
m.ResearchPlan.prototype.canStart = function(gameState) {
|
2013-08-17 15:59:53 +02:00
|
|
|
// also checks canResearch
|
|
|
|
return (gameState.findResearchers(this.type).length !== 0);
|
|
|
|
};
|
|
|
|
|
2013-12-30 11:04:59 +01:00
|
|
|
m.ResearchPlan.prototype.start = function(gameState) {
|
2013-08-17 15:59:53 +02:00
|
|
|
var self = this;
|
2013-09-29 15:32:52 +02:00
|
|
|
|
2013-12-30 11:04:59 +01:00
|
|
|
//m.debug ("Starting the research plan for " + this.type);
|
2013-08-17 15:59:53 +02:00
|
|
|
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);
|
|
|
|
}
|
2014-01-14 20:54:31 +01:00
|
|
|
this.onStart(gameState);
|
2013-08-17 15:59:53 +02:00
|
|
|
};
|
|
|
|
|
2013-12-30 11:04:59 +01:00
|
|
|
return m;
|
|
|
|
}(AEGIS);
|