2013-12-30 11:04:59 +01:00
|
|
|
var AEGIS = function(m)
|
|
|
|
{
|
|
|
|
|
2014-01-14 20:54:31 +01:00
|
|
|
m.TrainingPlan = function(gameState, type, metadata, number, maxMerge) {
|
|
|
|
if (!m.QueuePlan.call(this, gameState, type, metadata))
|
2013-09-29 15:32:52 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
this.category = "unit";
|
2013-12-30 11:04:59 +01:00
|
|
|
this.cost = new API3.Resources(this.template.cost(), this.template._template.Cost.Population);
|
2013-09-29 15:32:52 +02:00
|
|
|
|
2014-01-14 20:54:31 +01:00
|
|
|
this.number = number !== undefined ? number : 1;
|
|
|
|
this.maxMerge = maxMerge !== undefined ? maxMerge : 5;
|
2013-09-29 15:32:52 +02:00
|
|
|
|
|
|
|
return true;
|
2013-08-17 15:59:53 +02:00
|
|
|
};
|
|
|
|
|
2014-01-14 20:54:31 +01:00
|
|
|
m.TrainingPlan.prototype = Object.create(m.QueuePlan.prototype);
|
2013-09-29 15:32:52 +02:00
|
|
|
|
2013-12-30 11:04:59 +01:00
|
|
|
m.TrainingPlan.prototype.canStart = function(gameState) {
|
2013-08-17 15:59:53 +02:00
|
|
|
if (this.invalidTemplate)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// TODO: we should probably check pop caps
|
|
|
|
|
|
|
|
var trainers = gameState.findTrainers(this.type);
|
|
|
|
|
|
|
|
return (trainers.length != 0);
|
|
|
|
};
|
|
|
|
|
2013-12-30 11:04:59 +01:00
|
|
|
m.TrainingPlan.prototype.start = function(gameState) {
|
2013-09-29 15:32:52 +02:00
|
|
|
//warn("Executing TrainingPlan " + uneval(this));
|
2013-08-17 15:59:53 +02:00
|
|
|
var self = this;
|
|
|
|
var trainers = gameState.findTrainers(this.type).toEntityArray();
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
var aa = a.trainingQueueTime();
|
|
|
|
var bb = b.trainingQueueTime();
|
|
|
|
if (a.hasClass("Civic") && !self.template.hasClass("Support"))
|
|
|
|
aa += 0.9;
|
|
|
|
if (b.hasClass("Civic") && !self.template.hasClass("Support"))
|
|
|
|
bb += 0.9;
|
|
|
|
return (aa - bb);
|
|
|
|
});
|
2013-09-29 15:32:52 +02:00
|
|
|
if (this.metadata && this.metadata.base !== undefined && this.metadata.base === 0)
|
|
|
|
this.metadata.base = trainers[0].getMetadata(PlayerID,"base");
|
2013-08-17 15:59:53 +02:00
|
|
|
trainers[0].train(this.type, this.number, this.metadata);
|
|
|
|
}
|
2014-01-14 20:54:31 +01:00
|
|
|
this.onStart(gameState);
|
2013-08-17 15:59:53 +02:00
|
|
|
};
|
|
|
|
|
2014-01-14 20:54:31 +01:00
|
|
|
m.TrainingPlan.prototype.addItem = function(amount) {
|
2013-08-17 15:59:53 +02:00
|
|
|
if (amount === undefined)
|
|
|
|
amount = 1;
|
|
|
|
this.number += amount;
|
2013-09-29 15:32:52 +02:00
|
|
|
};
|
2013-12-30 11:04:59 +01:00
|
|
|
|
|
|
|
return m;
|
|
|
|
}(AEGIS);
|