Petra: fix for some units which stay idle when their base is destroyed

This was SVN commit r15684.
This commit is contained in:
mimo 2014-08-27 12:21:13 +00:00
parent b2d07d5e5a
commit a994053a6a
2 changed files with 24 additions and 7 deletions

View File

@ -78,6 +78,13 @@ m.BaseManager.prototype.setAnchor = function(gameState, anchorEntity)
this.anchor.setMetadata(PlayerID, "baseAnchor", true);
this.buildings.updateEnt(this.anchor);
this.accessIndex = gameState.ai.accessibility.getAccessValue(this.anchor.position());
// in case all our other bases were destroyed, reaffect these destroyed bases to this base
for each (var base in gameState.ai.HQ.baseManagers)
{
if (base.anchor || base.newbase)
continue;
base.newbase = this.ID;
}
return true;
};
@ -125,12 +132,13 @@ m.BaseManager.prototype.checkEvents = function (gameState, events, queues)
distmin = dist;
basemin = base;
}
if (this.Config.debug > 0)
API3.warn(" base " + this.ID + " detruite");
if (!basemin)
{
if (this.Config.debug > 0)
API3.warn(" base " + this.ID + " destroyed and no other bases found");
continue;
if (this.Config.debug > 0)
API3.warn(" >>> on echange units/buildings vers base " + basemin.ID);
}
this.newbase = basemin.ID;
this.units.forEach( function (ent) { ent.setMetadata(PlayerID, "base", basemin.ID); });
this.buildings.forEach( function (ent) { ent.setMetadata(PlayerID, "base", basemin.ID); });
}
@ -858,7 +866,16 @@ m.BaseManager.prototype.assignToFoundations = function(gameState, noRepair)
m.BaseManager.prototype.update = function(gameState, queues, events)
{
if (!this.anchor) // this base has been destroyed
{
// transfer possible remaining units (probably they were in training during previous transfers)
if (this.newbase)
{
var newbase = this.newbase;
this.units.forEach( function (ent) { ent.setMetadata(PlayerID, "base", newbase); });
this.buildings.forEach( function (ent) { ent.setMetadata(PlayerID, "base", newbase); });
}
return;
}
if (this.anchor && this.anchor.getMetadata(PlayerID, "access") !== this.accessIndex)
API3.warn("Petra baseManager " + this.ID + " problem with accessIndex " + this.accessIndex

View File

@ -54,7 +54,7 @@ m.GarrisonManager.prototype.update = function(gameState, queues)
if (!holder.position()) // could happen with siege unit inside a ship
continue;
if (gameState.ai.playedTurn - holder.getMetadata(PlayerID, "holderUpdate") > 5)
if (gameState.ai.elapsedTime - holder.getMetadata(PlayerID, "holderTimeUpdate") > 3)
{
if (holder.attackRange("Ranged"))
var range = holder.attackRange("Ranged").max;
@ -90,7 +90,7 @@ m.GarrisonManager.prototype.update = function(gameState, queues)
if (this.numberOfGarrisonedUnits(holder) === 0)
this.holders[id] = undefined;
else
holder.setMetadata(PlayerID, "holderUpdate", gameState.ai.playedTurn);
holder.setMetadata(PlayerID, "holderTimeUpdate", gameState.ai.elapsedTime);
}
}
};
@ -170,7 +170,7 @@ m.GarrisonManager.prototype.registerHolder = function(gameState, holder)
if (this.holders[holder.id()]) // already registered
return;
this.holders[holder.id()] = [];
holder.setMetadata(PlayerID, "holderUpdate", gameState.ai.playedTurn);
holder.setMetadata(PlayerID, "holderTimeUpdate", gameState.ai.elapsedTime);
};
return m;