1
0
forked from 0ad/0ad

Petra fixes for maps without cc

This was SVN commit r15200.
This commit is contained in:
mimo 2014-05-22 15:09:42 +00:00
parent 3fc2574ecf
commit 41de9f6e84
3 changed files with 29 additions and 25 deletions

View File

@ -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 (this.upcomingAttacks["Attack"].length === 0 && this.upcomingAttacks["HugeAttack"].length === 0
else if (gameState.countEntitiesByType(gameState.applyCiv("structures/{civ}_barracks"), true) >= 1 && (this.startedAttacks["Attack"].length + this.startedAttacks["HugeAttack"].length < Math.round(gameState.getPopulationMax()/100)))
&& (this.startedAttacks["Attack"].length + this.startedAttacks["HugeAttack"].length < Math.round(gameState.getPopulationMax()/100))
&& (gameState.currentPhase() > 1 || gameState.isResearching(gameState.townPhase())))
{ {
if (gameState.countEntitiesByType(gameState.applyCiv("structures/{civ}_dock"), true) === 0 && gameState.ai.HQ.navalMap) if ((gameState.countEntitiesByType(gameState.applyCiv("structures/{civ}_barracks"), true) >= 1
{ && (gameState.currentPhase() > 1 || gameState.isResearching(gameState.townPhase())))
// wait till we get a dock. || !gameState.ai.HQ.baseManagers[1]) // if we have no base ... nothing else to do than attack
}
else if (this.upcomingAttacks["Attack"].length === 0 && this.upcomingAttacks["HugeAttack"].length === 0)
{ {
if (this.attackNumber < 2 || this.startedAttacks["HugeAttack"].length > 0) if (this.attackNumber < 2 || this.startedAttacks["HugeAttack"].length > 0)
var type = "Attack"; var type = "Attack";

View File

@ -32,19 +32,28 @@ m.AttackPlan = function(gameState, Config, uniqueID, type, enemy, target)
} }
// get a starting rallyPoint ... will be improved later // get a starting rallyPoint ... will be improved later
this.rallyPoint = undefined; var rallyPoint = undefined;
for each (var base in gameState.ai.HQ.baseManagers) for each (var base in gameState.ai.HQ.baseManagers)
{ {
if (!base.anchor || !base.anchor.position()) if (!base.anchor || !base.anchor.position())
continue; continue;
this.rallyPoint = base.anchor.position(); rallyPoint = base.anchor.position();
break; break;
} }
if (!this.rallyPoint) if (!rallyPoint) // no base ? take the position of any of our entities
{ {
this.failed = true; gameState.getOwnEntities().forEach(function (ent) {
return false; if (rallyPoint || !ent.position())
return;
rallyPoint = ent.position();
});
if (!rallyPoint)
{
this.failed = true;
return false;
}
} }
this.rallyPoint = rallyPoint;
this.overseas = false; this.overseas = false;
this.paused = false; this.paused = false;
@ -373,6 +382,10 @@ m.AttackPlan.prototype.updatePreparation = function(gameState, events)
return ret; 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); this.assignUnits(gameState);
// special case: if we've reached max pop, and we can start the plan, start it. // 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.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 // find the actual queue we want
var queue = this.queue; var queue = this.queue;
if (this.buildOrder[0][3]["classes"].indexOf("Siege") !== -1 || 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). // Assign all no-roles that fit (after a plan aborts, for example).
if (this.type === "Raid") 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; var num = 0;
candidates.forEach(function(ent) { candidates.forEach(function(ent) {
if (!ent.position()) if (!ent.position())
@ -570,7 +581,7 @@ m.AttackPlan.prototype.assignUnits = function(gameState)
return; 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) { noRole.forEach(function(ent) {
if (!ent.position()) if (!ent.position())
return; return;
@ -578,7 +589,7 @@ m.AttackPlan.prototype.assignUnits = function(gameState)
return; return;
if (ent.getMetadata(PlayerID, "transport") !== undefined || ent.getMetadata(PlayerID, "transporter") !== undefined) if (ent.getMetadata(PlayerID, "transport") !== undefined || ent.getMetadata(PlayerID, "transporter") !== undefined)
return; return;
if (ent.hasClass("Support") || ent.attackTypes() === undefined) if (ent.hasClass("Ship") || ent.hasClass("Support") || ent.attackTypes() === undefined)
return; return;
ent.setMetadata(PlayerID, "plan", plan); ent.setMetadata(PlayerID, "plan", plan);
}); });
@ -594,7 +605,7 @@ m.AttackPlan.prototype.assignUnits = function(gameState)
if (this.type !== "Rush") if (this.type !== "Rush")
return; return;
// For a rush, assign also workers (but keep a minimum number of defenders) // 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; var num = 0;
worker.forEach(function(ent) { worker.forEach(function(ent) {
if (!ent.position()) if (!ent.position())
@ -672,10 +683,7 @@ m.AttackPlan.prototype.rushTargetFinder = function(gameState)
this.position = this.unitCollection.getCentrePosition(); this.position = this.unitCollection.getCentrePosition();
if (!this.position) if (!this.position)
{ this.position = this.rallyPoint;
var ourCC = gameState.getOwnStructures().filter(API3.Filters.byClass("CivCentre")).toEntityArray();
this.position = ourCC[0].position();
}
var minDist = Math.min(); var minDist = Math.min();
var target = undefined; var target = undefined;

View File

@ -46,7 +46,7 @@ m.NavalManager = function(Config)
m.NavalManager.prototype.init = function(gameState, queues) m.NavalManager.prototype.init = function(gameState, queues)
{ {
// finished docks // 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()))); API3.Filters.not(API3.Filters.isFoundation())));
this.docks.allowQuickIter(); this.docks.allowQuickIter();
this.docks.registerUpdates(); this.docks.registerUpdates();