Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/queue.js
var PETRA = function(m) | (function(m) | ||||
{ | { | ||||
/** | /** | ||||
* Holds a list of wanted plans to train or construct | * Holds a list of wanted plans to train or construct | ||||
*/ | */ | ||||
m.Queue = function() | m.Queue = function() | ||||
{ | { | ||||
this.plans = []; | this.plans = []; | ||||
this.paused = false; | this.paused = false; | ||||
this.switched = 0; | this.switched = 0; | ||||
}; | }; | ||||
m.Queue.prototype.empty = function() | m.Queue.prototype.empty = function() | ||||
{ | { | ||||
this.plans = []; | this.plans = []; | ||||
}; | }; | ||||
m.Queue.prototype.addPlan = function(newPlan) | m.Queue.prototype.addPlan = function(newPlan) | ||||
{ | { | ||||
if (!newPlan) | if (!newPlan) | ||||
return; | return; | ||||
for (let plan of this.plans) | for (let plan of this.plans) | ||||
{ | |||||
if (newPlan.category === "unit" && plan.type == newPlan.type && plan.number + newPlan.number <= plan.maxMerge) | if (newPlan.category === "unit" && plan.type == newPlan.type && plan.number + newPlan.number <= plan.maxMerge) | ||||
{ | { | ||||
plan.addItem(newPlan.number); | plan.addItem(newPlan.number); | ||||
return; | return; | ||||
} | } | ||||
else if (newPlan.category === "technology" && plan.type === newPlan.type) | else if (newPlan.category === "technology" && plan.type === newPlan.type) | ||||
return; | return; | ||||
} | |||||
this.plans.push(newPlan); | this.plans.push(newPlan); | ||||
}; | }; | ||||
m.Queue.prototype.check= function(gameState) | m.Queue.prototype.check= function(gameState) | ||||
{ | { | ||||
while (this.plans.length > 0) | while (this.plans.length > 0) | ||||
{ | { | ||||
if (!this.plans[0].isInvalid(gameState)) | if (!this.plans[0].isInvalid(gameState)) | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | else | ||||
API3.warn("Petra deserialization error: plan unknown " + uneval(dataPlan)); | API3.warn("Petra deserialization error: plan unknown " + uneval(dataPlan)); | ||||
continue; | continue; | ||||
} | } | ||||
plan.Deserialize(gameState, dataPlan); | plan.Deserialize(gameState, dataPlan); | ||||
this.plans.push(plan); | this.plans.push(plan); | ||||
} | } | ||||
}; | }; | ||||
return m; | }(PETRA)); | ||||
}(PETRA); |
Wildfire Games · Phabricator