Petra fixes for maps without cc
This was SVN commit r15200.
This commit is contained in:
parent
3fc2574ecf
commit
41de9f6e84
@ -175,16 +175,12 @@ m.AttackManager.prototype.update = function(gameState, queues, events)
|
||||
}
|
||||
}
|
||||
}
|
||||
// if we have a barracks, there's no water, we're at age >= 1 and we've decided to attack.
|
||||
else if (gameState.countEntitiesByType(gameState.applyCiv("structures/{civ}_barracks"), true) >= 1
|
||||
&& (this.startedAttacks["Attack"].length + this.startedAttacks["HugeAttack"].length < Math.round(gameState.getPopulationMax()/100))
|
||||
&& (gameState.currentPhase() > 1 || gameState.isResearching(gameState.townPhase())))
|
||||
else if (this.upcomingAttacks["Attack"].length === 0 && this.upcomingAttacks["HugeAttack"].length === 0
|
||||
&& (this.startedAttacks["Attack"].length + this.startedAttacks["HugeAttack"].length < Math.round(gameState.getPopulationMax()/100)))
|
||||
{
|
||||
if (gameState.countEntitiesByType(gameState.applyCiv("structures/{civ}_dock"), true) === 0 && gameState.ai.HQ.navalMap)
|
||||
{
|
||||
// wait till we get a dock.
|
||||
}
|
||||
else if (this.upcomingAttacks["Attack"].length === 0 && this.upcomingAttacks["HugeAttack"].length === 0)
|
||||
if ((gameState.countEntitiesByType(gameState.applyCiv("structures/{civ}_barracks"), true) >= 1
|
||||
&& (gameState.currentPhase() > 1 || gameState.isResearching(gameState.townPhase())))
|
||||
|| !gameState.ai.HQ.baseManagers[1]) // if we have no base ... nothing else to do than attack
|
||||
{
|
||||
if (this.attackNumber < 2 || this.startedAttacks["HugeAttack"].length > 0)
|
||||
var type = "Attack";
|
||||
|
@ -32,19 +32,28 @@ m.AttackPlan = function(gameState, Config, uniqueID, type, enemy, target)
|
||||
}
|
||||
|
||||
// get a starting rallyPoint ... will be improved later
|
||||
this.rallyPoint = undefined;
|
||||
var rallyPoint = undefined;
|
||||
for each (var base in gameState.ai.HQ.baseManagers)
|
||||
{
|
||||
if (!base.anchor || !base.anchor.position())
|
||||
continue;
|
||||
this.rallyPoint = base.anchor.position();
|
||||
rallyPoint = base.anchor.position();
|
||||
break;
|
||||
}
|
||||
if (!this.rallyPoint)
|
||||
if (!rallyPoint) // no base ? take the position of any of our entities
|
||||
{
|
||||
this.failed = true;
|
||||
return false;
|
||||
gameState.getOwnEntities().forEach(function (ent) {
|
||||
if (rallyPoint || !ent.position())
|
||||
return;
|
||||
rallyPoint = ent.position();
|
||||
});
|
||||
if (!rallyPoint)
|
||||
{
|
||||
this.failed = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
this.rallyPoint = rallyPoint;
|
||||
|
||||
this.overseas = false;
|
||||
this.paused = false;
|
||||
@ -373,6 +382,10 @@ m.AttackPlan.prototype.updatePreparation = function(gameState, events)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// if we need a transport, wait for some transport ships
|
||||
if (this.overseas && !gameState.ai.HQ.navalManager.seaTransportShips.length)
|
||||
return 1;
|
||||
|
||||
this.assignUnits(gameState);
|
||||
|
||||
// special case: if we've reached max pop, and we can start the plan, start it.
|
||||
@ -503,8 +516,6 @@ m.AttackPlan.prototype.trainMoreUnits = function(gameState)
|
||||
|
||||
if (this.buildOrder[0][0] < this.buildOrder[0][3]["targetSize"])
|
||||
{
|
||||
// if (this.Config.debug > 0)
|
||||
// warn(" we have less than nominal Try to train more units");
|
||||
// find the actual queue we want
|
||||
var queue = this.queue;
|
||||
if (this.buildOrder[0][3]["classes"].indexOf("Siege") !== -1 ||
|
||||
@ -555,7 +566,7 @@ m.AttackPlan.prototype.assignUnits = function(gameState)
|
||||
// Assign all no-roles that fit (after a plan aborts, for example).
|
||||
if (this.type === "Raid")
|
||||
{
|
||||
var candidates = gameState.getOwnUnits().filter(API3.Filters.byClass(["Cavalry"]));
|
||||
var candidates = gameState.getOwnUnits().filter(API3.Filters.byClass("Cavalry"));
|
||||
var num = 0;
|
||||
candidates.forEach(function(ent) {
|
||||
if (!ent.position())
|
||||
@ -570,7 +581,7 @@ m.AttackPlan.prototype.assignUnits = function(gameState)
|
||||
return;
|
||||
}
|
||||
|
||||
var noRole = gameState.getOwnEntitiesByRole(undefined, false).filter(API3.Filters.byClass(["Unit"]));
|
||||
var noRole = gameState.getOwnEntitiesByRole(undefined, false).filter(API3.Filters.byClass("Unit"));
|
||||
noRole.forEach(function(ent) {
|
||||
if (!ent.position())
|
||||
return;
|
||||
@ -578,7 +589,7 @@ m.AttackPlan.prototype.assignUnits = function(gameState)
|
||||
return;
|
||||
if (ent.getMetadata(PlayerID, "transport") !== undefined || ent.getMetadata(PlayerID, "transporter") !== undefined)
|
||||
return;
|
||||
if (ent.hasClass("Support") || ent.attackTypes() === undefined)
|
||||
if (ent.hasClass("Ship") || ent.hasClass("Support") || ent.attackTypes() === undefined)
|
||||
return;
|
||||
ent.setMetadata(PlayerID, "plan", plan);
|
||||
});
|
||||
@ -594,7 +605,7 @@ m.AttackPlan.prototype.assignUnits = function(gameState)
|
||||
if (this.type !== "Rush")
|
||||
return;
|
||||
// For a rush, assign also workers (but keep a minimum number of defenders)
|
||||
var worker = gameState.getOwnEntitiesByRole("worker", true).filter(API3.Filters.byClass(["Unit"]));
|
||||
var worker = gameState.getOwnEntitiesByRole("worker", true).filter(API3.Filters.byClass("Unit"));
|
||||
var num = 0;
|
||||
worker.forEach(function(ent) {
|
||||
if (!ent.position())
|
||||
@ -672,10 +683,7 @@ m.AttackPlan.prototype.rushTargetFinder = function(gameState)
|
||||
|
||||
this.position = this.unitCollection.getCentrePosition();
|
||||
if (!this.position)
|
||||
{
|
||||
var ourCC = gameState.getOwnStructures().filter(API3.Filters.byClass("CivCentre")).toEntityArray();
|
||||
this.position = ourCC[0].position();
|
||||
}
|
||||
this.position = this.rallyPoint;
|
||||
|
||||
var minDist = Math.min();
|
||||
var target = undefined;
|
||||
|
@ -46,7 +46,7 @@ m.NavalManager = function(Config)
|
||||
m.NavalManager.prototype.init = function(gameState, queues)
|
||||
{
|
||||
// finished docks
|
||||
this.docks = gameState.getOwnStructures().filter(API3.Filters.and(API3.Filters.or(API3.Filters.byClass("Dock"), API3.Filters.byClass("Shipyard")),
|
||||
this.docks = gameState.getOwnStructures().filter(API3.Filters.and(API3.Filters.byClassesOr(["Dock", "Shipyard"]),
|
||||
API3.Filters.not(API3.Filters.isFoundation())));
|
||||
this.docks.allowQuickIter();
|
||||
this.docks.registerUpdates();
|
||||
|
Loading…
Reference in New Issue
Block a user