various small tunings for petra
This was SVN commit r16011.
This commit is contained in:
parent
89cc0fd0e1
commit
049312e5a2
@ -272,6 +272,13 @@ m.AttackManager.prototype.unpauseAllPlans = function()
|
||||
attack.setPaused(false);
|
||||
};
|
||||
|
||||
m.AttackManager.prototype.getAttackInPreparation = function(type)
|
||||
{
|
||||
if (!this.upcomingAttacks[type].length)
|
||||
return undefined;
|
||||
return this.upcomingAttacks[type][0];
|
||||
};
|
||||
|
||||
m.AttackManager.prototype.Serialize = function()
|
||||
{
|
||||
let properties = {
|
||||
|
@ -187,8 +187,7 @@ m.AttackPlan.prototype.init = function(gameState)
|
||||
for (var cat in this.unitStat)
|
||||
{
|
||||
var Unit = this.unitStat[cat];
|
||||
var filter = API3.Filters.and(API3.Filters.byClassesAnd(Unit["classes"]), API3.Filters.byMetadata(PlayerID, "plan",this.name));
|
||||
this.unit[cat] = gameState.getOwnUnits().filter(filter);
|
||||
this.unit[cat] = this.unitCollection.filter(API3.Filters.byClassesAnd(Unit["classes"]));
|
||||
this.unit[cat].registerUpdates();
|
||||
if (this.canBuildUnits)
|
||||
this.buildOrder.push([0, Unit["classes"], this.unit[cat], Unit, cat]);
|
||||
@ -469,6 +468,8 @@ m.AttackPlan.prototype.updatePreparation = function(gameState, events)
|
||||
return 1;
|
||||
|
||||
this.assignUnits(gameState);
|
||||
if (this.type !== "Raid" && gameState.ai.HQ.attackManager.getAttackInPreparation("Raid") !== undefined)
|
||||
this.reassignCavUnit(gameState); // reassign some cav (if any) to fasten raid preparations
|
||||
|
||||
// special case: if we've reached max pop, and we can start the plan, start it.
|
||||
if (gameState.getPopulationMax() - gameState.getPopulation() < 10)
|
||||
@ -519,7 +520,10 @@ m.AttackPlan.prototype.updatePreparation = function(gameState, events)
|
||||
|
||||
// if we're here, it means we must start (and have no units in training left).
|
||||
this.state = "completing";
|
||||
this.maxCompletingTurn = gameState.ai.playedTurn + 60;
|
||||
if (this.type === "Raid")
|
||||
this.maxCompletingTurn = gameState.ai.playedTurn + 20;
|
||||
else
|
||||
this.maxCompletingTurn = gameState.ai.playedTurn + 60;
|
||||
|
||||
var rallyPoint = this.rallyPoint;
|
||||
var rallyIndex = gameState.ai.accessibility.getAccessValue(rallyPoint);
|
||||
@ -730,6 +734,27 @@ m.AttackPlan.prototype.assignUnits = function(gameState)
|
||||
return added;
|
||||
};
|
||||
|
||||
// Reassign one (at each turn) Cav unit to fasten raid preparation
|
||||
m.AttackPlan.prototype.reassignCavUnit = function(gameState)
|
||||
{
|
||||
var found = undefined;
|
||||
this.unitCollection.forEach(function(ent) {
|
||||
if (found)
|
||||
return;
|
||||
if (!ent.position() || ent.getMetadata(PlayerID, "transport") !== undefined)
|
||||
return;
|
||||
if (!ent.hasClass("Cavalry") || !ent.hasClass("CitizenSoldier"))
|
||||
return;
|
||||
found = ent;
|
||||
});
|
||||
if (!found)
|
||||
return;
|
||||
let raid = gameState.ai.HQ.attackManager.getAttackInPreparation("Raid");
|
||||
found.setMetadata(PlayerID, "plan", raid.name);
|
||||
this.unitCollection.updateEnt(found);
|
||||
raid.unitCollection.updateEnt(found);
|
||||
};
|
||||
|
||||
// sameLand true means that we look for a target for which we do not need to take a transport
|
||||
m.AttackPlan.prototype.getNearestTarget = function(gameState, position, sameLand)
|
||||
{
|
||||
@ -1577,7 +1602,7 @@ m.AttackPlan.prototype.Abort = function(gameState)
|
||||
gameState.ai.queueManager.removeQueue("plan_" + this.name + "_siege");
|
||||
};
|
||||
|
||||
m.AttackPlan.prototype.removeUnit = function(ent)
|
||||
m.AttackPlan.prototype.removeUnit = function(ent, update)
|
||||
{
|
||||
if (ent.hasClass("CitizenSoldier") && ent.getMetadata(PlayerID, "role") !== "worker")
|
||||
{
|
||||
@ -1585,7 +1610,8 @@ m.AttackPlan.prototype.removeUnit = function(ent)
|
||||
ent.setMetadata(PlayerID, "subrole", undefined);
|
||||
}
|
||||
ent.setMetadata(PlayerID, "plan", -1);
|
||||
this.unitCollection.updateEnt(ent);
|
||||
if (update)
|
||||
this.unitCollection.updateEnt(ent);
|
||||
};
|
||||
|
||||
m.AttackPlan.prototype.checkEvents = function(gameState, events)
|
||||
|
@ -37,7 +37,7 @@ m.Config = function(difficulty)
|
||||
// defense
|
||||
this.Defense =
|
||||
{
|
||||
"defenseRatio" : 2, // see defense.js for more info.
|
||||
"defenseRatio" : 2, // ratio of defenders/attackers.
|
||||
"armyCompactSize" : 2000, // squared. Half-diameter of an army.
|
||||
"armyBreakawaySize" : 3500, // squared.
|
||||
"armyMergeSize" : 1400 // squared.
|
||||
|
@ -32,7 +32,7 @@ m.DefenseArmy.prototype.assignUnit = function (gameState, entID)
|
||||
continue;
|
||||
|
||||
if (eEnt.unitAIOrderData().length && eEnt.unitAIOrderData()[0]["target"] &&
|
||||
eEnt.unitAIOrderData()[0]["target"] === entID)
|
||||
eEnt.unitAIOrderData()[0]["target"] == entID)
|
||||
{ // being attacked >>> target the unit
|
||||
idMin = id;
|
||||
break;
|
||||
@ -68,7 +68,7 @@ m.DefenseArmy.prototype.assignUnit = function (gameState, entID)
|
||||
var ownIndex = gameState.ai.accessibility.getAccessValue(ent.position());
|
||||
var foePosition = gameState.getEntityById(idFoe).position();
|
||||
var foeIndex = gameState.ai.accessibility.getAccessValue(foePosition);
|
||||
if (ownIndex === foeIndex || ent.hasClass("Ship"))
|
||||
if (ownIndex == foeIndex || ent.hasClass("Ship"))
|
||||
{
|
||||
this.assignedTo[entID] = idFoe;
|
||||
this.assignedAgainst[idFoe].push(entID);
|
||||
@ -82,8 +82,8 @@ m.DefenseArmy.prototype.assignUnit = function (gameState, entID)
|
||||
// TODO: this should return cleverer results ("needs anti-elephant"…)
|
||||
m.DefenseArmy.prototype.needsDefenders = function (gameState, events)
|
||||
{
|
||||
// some preliminary checks because we don't update for tech
|
||||
if (this.foeStrength < 0 || this.ownStrength < 0)
|
||||
// some preliminary checks because we don't update for tech so entStrength removed can be > entStrength added
|
||||
if (this.foeStrength <= 0 || this.ownStrength <= 0)
|
||||
this.recalculateStrengths(gameState);
|
||||
|
||||
if (this.foeStrength * this.defenseRatio <= this.ownStrength)
|
||||
@ -93,26 +93,24 @@ m.DefenseArmy.prototype.needsDefenders = function (gameState, events)
|
||||
|
||||
m.DefenseArmy.prototype.getState = function (gameState)
|
||||
{
|
||||
if (this.foeEntities.length === 0)
|
||||
if (this.foeEntities.length == 0)
|
||||
return 0;
|
||||
return 1;
|
||||
};
|
||||
|
||||
m.DefenseArmy.prototype.update = function (gameState)
|
||||
{
|
||||
for (var entId of this.ownEntities)
|
||||
for (let entId of this.ownEntities)
|
||||
{
|
||||
var ent = gameState.getEntityById(entId);
|
||||
let ent = gameState.getEntityById(entId);
|
||||
if (!ent)
|
||||
continue;
|
||||
var orders = ent.unitAIOrderData();
|
||||
if (orders.length === 0 && !ent.getMetadata(PlayerID, "transport"))
|
||||
let orders = ent.unitAIOrderData();
|
||||
if (orders.length == 0 && !ent.getMetadata(PlayerID, "transport"))
|
||||
this.assignUnit(gameState, entId);
|
||||
}
|
||||
|
||||
var breakaways = this.onUpdate(gameState);
|
||||
|
||||
return breakaways;
|
||||
return this.onUpdate(gameState);
|
||||
};
|
||||
|
||||
m.DefenseArmy.prototype.Serialize = function()
|
||||
@ -132,7 +130,7 @@ m.DefenseArmy.prototype.Serialize = function()
|
||||
|
||||
m.DefenseArmy.prototype.Deserialize = function(data)
|
||||
{
|
||||
for (var key in data)
|
||||
for (let key in data)
|
||||
this[key] = data[key]
|
||||
};
|
||||
|
||||
|
@ -453,68 +453,38 @@ m.QueueManager.prototype.checkPausedQueues = function(gameState)
|
||||
});
|
||||
});
|
||||
|
||||
if (numWorkers < 8)
|
||||
for (let q in this.queues)
|
||||
{
|
||||
for (let q in this.queues)
|
||||
{
|
||||
let queue = this.queues[q];
|
||||
if (!queue.paused
|
||||
&& q != "citizenSoldier" && q != "villager"
|
||||
&& (q != "civilCentre" || gameState.getOwnStructures().filter(API3.Filters.byClass("CivCentre")) > 0))
|
||||
{
|
||||
queue.paused = true;
|
||||
this.accounts[q].reset();
|
||||
}
|
||||
else if (queue.paused)
|
||||
queue.paused = false;
|
||||
}
|
||||
}
|
||||
else if (numWorkers < 16)
|
||||
{
|
||||
for (let q in this.queues)
|
||||
{
|
||||
let queue = this.queues[q];
|
||||
if (!queue.paused
|
||||
&& (q == "economicBuilding" || q == "militaryBuilding" || q == "defenseBuilding"
|
||||
let toBePaused = false;
|
||||
if (numWorkers < 8)
|
||||
toBePaused = (q != "citizenSoldier" && q != "villager"
|
||||
&& (q != "civilCentre" || gameState.getOwnStructures().filter(API3.Filters.byClass("CivCentre")) > 0));
|
||||
else if (numWorkers < 16)
|
||||
toBePaused = (q == "economicBuilding" || q == "militaryBuilding" || q == "defenseBuilding"
|
||||
|| (q == "civilCentre" && gameState.getOwnStructures().filter(API3.Filters.byClass("CivCentre")) > 0)
|
||||
|| q == "majorTech" || q == "minorTech" || q.indexOf("plan_") != -1))
|
||||
{
|
||||
queue.paused = true;
|
||||
this.accounts[q].reset();
|
||||
}
|
||||
else if (queue.paused)
|
||||
queue.paused = false;
|
||||
}
|
||||
}
|
||||
else if (numWorkers < 24)
|
||||
{
|
||||
for (let q in this.queues)
|
||||
{
|
||||
let queue = this.queues[q];
|
||||
if (!queue.paused
|
||||
&& (q == "defenseBuilding"
|
||||
|| q == "majorTech" || q == "minorTech" || q.indexOf("plan_") != -1);
|
||||
else if (numWorkers < 24)
|
||||
toBePaused = (q == "defenseBuilding"
|
||||
|| (q == "civilCentre" && gameState.getOwnStructures().filter(API3.Filters.byClass("CivCentre")) > 0)
|
||||
|| q == "majorTech" || q.indexOf("_siege") != -1 || q.indexOf("_champ") != -1))
|
||||
{
|
||||
queue.paused = true;
|
||||
this.accounts[q].reset();
|
||||
}
|
||||
else if (queue.paused)
|
||||
queue.paused = false;
|
||||
|| q == "majorTech" || q.indexOf("_siege") != -1 || q.indexOf("_champ") != -1);
|
||||
|
||||
// And reduce the batch sizes of attack queues
|
||||
if (q.indexOf("plan_") != -1 && queue.queue[0])
|
||||
{
|
||||
queue.queue[0].number = 1;
|
||||
if (queue.queue[1])
|
||||
queue.queue[1].number = 1;
|
||||
}
|
||||
let queue = this.queues[q];
|
||||
if (!queue.paused && toBePaused)
|
||||
{
|
||||
queue.paused = true;
|
||||
this.accounts[q].reset();
|
||||
}
|
||||
else if (queue.paused && !toBePaused)
|
||||
queue.paused = false;
|
||||
|
||||
// And reduce the batch sizes of attack queues
|
||||
if (q.indexOf("plan_") != -1 && numWorkers < 24 && queue.queue[0])
|
||||
{
|
||||
queue.queue[0].number = 1;
|
||||
if (queue.queue[1])
|
||||
queue.queue[1].number = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
for (let q in this.queues)
|
||||
if (this.queues[q].paused)
|
||||
this.queues[q].paused = false;
|
||||
};
|
||||
|
||||
m.QueueManager.prototype.pauseQueue = function(queue, scrapAccounts)
|
||||
|
@ -560,7 +560,7 @@ m.TransportPlan.prototype.resetUnit = function(gameState, ent)
|
||||
{
|
||||
var attackPlan = gameState.ai.HQ.attackManager.getPlan(ent.getMetadata(PlayerID, "plan"));
|
||||
if (attackPan)
|
||||
attackPlan.removeUnit(ent);
|
||||
attackPlan.removeUnit(ent, true);
|
||||
}
|
||||
if (ent.getMetadata(PlayerID, "PartOfArmy"))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user