various small fixes and cleanings to Petra
This was SVN commit r15670.
This commit is contained in:
parent
0e01f20d29
commit
ac9d4f1036
@ -454,13 +454,16 @@ m.GameState.prototype.countEntitiesByType = function(type, maintain) {
|
||||
};
|
||||
|
||||
m.GameState.prototype.countEntitiesAndQueuedByType = function(type, maintain) {
|
||||
var template = this.getTemplate(type);
|
||||
if (!template)
|
||||
return 0;
|
||||
|
||||
var count = this.countEntitiesByType(type, maintain);
|
||||
|
||||
// Count building foundations
|
||||
var template = this.getTemplate(type);
|
||||
if (template && template.hasClass("Structure") === true)
|
||||
if (template.hasClass("Structure") === true)
|
||||
count += this.countFoundationsByType(type, true);
|
||||
else if (template && template.resourceSupplyType() !== undefined) // animal resources
|
||||
else if (template.resourceSupplyType() !== undefined) // animal resources
|
||||
count += this.countEntitiesByType("resource|" + type, true);
|
||||
else
|
||||
{
|
||||
|
@ -240,21 +240,15 @@ m.AttackManager.prototype.getPlan = function(planName)
|
||||
{
|
||||
for (var attackType in this.upcomingAttacks)
|
||||
{
|
||||
for (var i in this.upcomingAttacks[attackType])
|
||||
{
|
||||
var attack = this.upcomingAttacks[attackType][i];
|
||||
for (var attack of this.upcomingAttacks[attackType])
|
||||
if (attack.getName() == planName)
|
||||
return attack;
|
||||
}
|
||||
}
|
||||
for (var attackType in this.startedAttacks)
|
||||
{
|
||||
for (var i in this.startedAttacks[attackType])
|
||||
{
|
||||
var attack = this.startedAttacks[attackType][i];
|
||||
for (var attack of this.startedAttacks[attackType])
|
||||
if (attack.getName() == planName)
|
||||
return attack;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
@ -276,23 +270,23 @@ m.AttackManager.prototype.unpausePlan = function(planName)
|
||||
m.AttackManager.prototype.pauseAllPlans = function()
|
||||
{
|
||||
for (var attackType in this.upcomingAttacks)
|
||||
for (var i in this.upcomingAttacks[attackType])
|
||||
this.upcomingAttacks[attackType][i].setPaused(true);
|
||||
for (var attack of this.upcomingAttacks[attackType])
|
||||
attack.setPaused(true);
|
||||
|
||||
for (var attackType in this.startedAttacks)
|
||||
for (var i in this.startedAttacks[attackType])
|
||||
this.startedAttacks[attackType][i].setPaused(true);
|
||||
for (var attack of this.startedAttacks[attackType])
|
||||
attack.setPaused(true);
|
||||
};
|
||||
|
||||
m.AttackManager.prototype.unpauseAllPlans = function()
|
||||
{
|
||||
for (var attackType in this.upcomingAttacks)
|
||||
for (var i in this.upcomingAttacks[attackType])
|
||||
this.upcomingAttacks[attackType][i].setPaused(false);
|
||||
for (var attack of this.upcomingAttacks[attackType])
|
||||
attack.setPaused(false);
|
||||
|
||||
for (var attackType in this.startedAttacks)
|
||||
for (var i in this.startedAttacks[attackType])
|
||||
this.startedAttacks[attackType][i].setPaused(false);
|
||||
for (var attack of this.startedAttacks[attackType])
|
||||
attack.setPaused(false);
|
||||
};
|
||||
|
||||
return m;
|
||||
|
@ -1426,10 +1426,34 @@ m.AttackPlan.prototype.update = function(gameState, events)
|
||||
this.target = this.getNearestTarget(gameState, this.position, true);
|
||||
if (!this.target)
|
||||
{
|
||||
if (this.Config.debug > 0)
|
||||
API3.warn("No new target found. Remaining units " + this.unitCollection.length);
|
||||
Engine.ProfileStop();
|
||||
return false;
|
||||
// Check if we could help any current attack
|
||||
var attackManager = gameState.ai.HQ.attackManager;
|
||||
var accessIndex = gameState.ai.accessibility.getAccessValue(this.targetPos);
|
||||
for (var attackType in attackManager.startedAttacks)
|
||||
{
|
||||
if (this.target)
|
||||
break;
|
||||
for (var attack of attackManager.startedAttacks[attackType])
|
||||
{
|
||||
if (attack.name === this.name)
|
||||
continue;
|
||||
if (accessIndex !== gameState.ai.accessibility.getAccessValue(attack.targetPos))
|
||||
continue;
|
||||
this.target = attack.target;
|
||||
this.targetPlayer = attack.targetPlayer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.target)
|
||||
{
|
||||
if (this.Config.debug > 0)
|
||||
API3.warn("No new target found. Remaining units " + this.unitCollection.length);
|
||||
Engine.ProfileStop();
|
||||
return false;
|
||||
}
|
||||
else if (this.Config.debug > 0)
|
||||
API3.warn("We will help one of our other attacks");
|
||||
}
|
||||
this.targetPos = this.target.position();
|
||||
}
|
||||
|
@ -109,13 +109,30 @@ m.BaseManager.prototype.checkEvents = function (gameState, events, queues)
|
||||
this.removeDropsite(gameState, ent);
|
||||
if (evt.metadata[PlayerID]["baseAnchor"] && evt.metadata[PlayerID]["baseAnchor"] == true)
|
||||
{
|
||||
// sounds like we lost our anchor. Let's try rebuilding it.
|
||||
// TODO: currently the HQ manager sets us as initgathering, we probably ouht to do it
|
||||
// sounds like we lost our anchor. Let's reaffect our units and buildings
|
||||
this.anchor = undefined;
|
||||
|
||||
this.constructing = true; // let's switch mode.
|
||||
this.workers.forEach( function (worker) { worker.stopMoving(); });
|
||||
queues.civilCentre.addItem(new m.ConstructionPlan(gameState, gameState.ai.HQ.bBase[0], { "base": this.ID, "baseAnchor": true }, ent.position()));
|
||||
var distmin = Math.min();
|
||||
var basemin = undefined;
|
||||
for each (var base in gameState.ai.HQ.baseManagers)
|
||||
{
|
||||
if (!base.anchor)
|
||||
continue;
|
||||
var dist = API3.SquareVectorDistance(base.anchor.position(), ent.position());
|
||||
if (base.accessIndex !== this.accessIndex)
|
||||
dist += 100000000;
|
||||
if (dist > distmin)
|
||||
continue;
|
||||
distmin = dist;
|
||||
basemin = base;
|
||||
}
|
||||
if (this.Config.debug > 0)
|
||||
API3.warn(" base " + this.ID + " detruite");
|
||||
if (!basemin)
|
||||
continue;
|
||||
if (this.Config.debug > 0)
|
||||
API3.warn(" >>> on echange units/buildings vers base " + basemin.ID);
|
||||
this.units.forEach( function (ent) { ent.setMetadata(PlayerID, "base", basemin.ID); });
|
||||
this.buildings.forEach( function (ent) { ent.setMetadata(PlayerID, "base", basemin.ID); });
|
||||
}
|
||||
|
||||
}
|
||||
@ -840,6 +857,9 @@ m.BaseManager.prototype.assignToFoundations = function(gameState, noRepair)
|
||||
|
||||
m.BaseManager.prototype.update = function(gameState, queues, events)
|
||||
{
|
||||
if (!this.anchor) // this base has been destroyed
|
||||
return;
|
||||
|
||||
if (this.anchor && this.anchor.getMetadata(PlayerID, "access") !== this.accessIndex)
|
||||
API3.warn("Petra baseManager " + this.ID + " problem with accessIndex " + this.accessIndex
|
||||
+ " while metadata access is " + this.anchor.getMetadata(PlayerID, "access"));
|
||||
|
@ -102,7 +102,7 @@ m.Config.prototype.updateDifficulty = function(difficulty)
|
||||
{
|
||||
this.difficulty = difficulty;
|
||||
// changing settings based on difficulty.
|
||||
this.targetNumTraders = 2 * this.difficulty;
|
||||
this.Economy.targetNumTraders = 2 * this.difficulty;
|
||||
if (this.difficulty === 1)
|
||||
{
|
||||
this.Military.popForBarracks1 = 35;
|
||||
|
@ -1334,7 +1334,7 @@ m.HQ.prototype.buildMoreHouses = function(gameState,queues)
|
||||
};
|
||||
|
||||
// checks the status of the territory expansion. If no new economic bases created, build some strategic ones.
|
||||
m.HQ.prototype.checkBaseExpansion = function(gameState,queues)
|
||||
m.HQ.prototype.checkBaseExpansion = function(gameState, queues)
|
||||
{
|
||||
if (queues.civilCentre.length() > 0)
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user