Differential D617 Diff 2598 ps/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
Show First 20 Lines • Show All 758 Lines • ▼ Show 20 Lines | for (let dy = 0; dy <= size; ++dy) | ||||
nbcell += weight; | nbcell += weight; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return nbcell ? total / nbcell : 0; | return nbcell ? total / nbcell : 0; | ||||
}; | }; | ||||
m.ConstructionPlan.prototype.isGo = function(gameState) | |||||
{ | |||||
if (this.isGoRequirement && this.isGoRequirement === "houseNeeded") | |||||
{ | |||||
if (!gameState.ai.HQ.canBuild(gameState, "structures/{civ}_house")) | |||||
return false; | |||||
if (gameState.getPopulationMax() <= gameState.getPopulationLimit()) | |||||
return false; | |||||
let freeSlots = gameState.getPopulationLimit() - gameState.getPopulation(); | |||||
for (let ent of gameState.getOwnFoundations().values()) | |||||
freeSlots += ent.getPopulationBonus(); | |||||
if (gameState.ai.HQ.saveResources) | |||||
return freeSlots <= 10; | |||||
else if (gameState.getPopulation() > 55) | |||||
return freeSlots <= 21; | |||||
else if (gameState.getPopulation() > 30) | |||||
return freeSlots <= 15; | |||||
return freeSlots <= 10; | |||||
} | |||||
return true; | |||||
}; | |||||
m.ConstructionPlan.prototype.onStart = function(gameState) | |||||
{ | |||||
if (this.queueToReset) | |||||
gameState.ai.queueManager.changePriority(this.queueToReset, gameState.ai.Config.priorities[this.queueToReset]); | |||||
}; | |||||
m.ConstructionPlan.prototype.Serialize = function() | m.ConstructionPlan.prototype.Serialize = function() | ||||
{ | { | ||||
let prop = { | return { | ||||
"category": this.category, | "category": this.category, | ||||
"type": this.type, | "type": this.type, | ||||
"ID": this.ID, | "ID": this.ID, | ||||
"metadata": this.metadata, | "metadata": this.metadata, | ||||
"cost": this.cost.Serialize(), | "cost": this.cost.Serialize(), | ||||
"number": this.number, | "number": this.number, | ||||
"position": this.position | "position": this.position, | ||||
"isGoRequirement": this.isGoRequirement || undefined, | |||||
"queueToReset": this.queueToReset || undefined | |||||
}; | }; | ||||
let func = { | |||||
"isGo": uneval(this.isGo), | |||||
"onStart": uneval(this.onStart) | |||||
}; | |||||
return { "prop": prop, "func": func }; | |||||
}; | }; | ||||
m.ConstructionPlan.prototype.Deserialize = function(gameState, data) | m.ConstructionPlan.prototype.Deserialize = function(gameState, data) | ||||
{ | { | ||||
for (let key in data.prop) | for (let key in data) | ||||
this[key] = data.prop[key]; | this[key] = data[key]; | ||||
let cost = new API3.Resources(); | let cost = new API3.Resources(); | ||||
cost.Deserialize(data.prop.cost); | cost.Deserialize(data.cost); | ||||
this.cost = cost; | this.cost = cost; | ||||
for (let fun in data.func) | |||||
this[fun] = eval(data.func[fun]); | |||||
}; | }; | ||||
return m; | return m; | ||||
}(PETRA); | }(PETRA); |
Wildfire Games · Phabricator