petra: internal renaming to follow the GameType -> VictoryConditions change in simu

This was SVN commit r21706.
This commit is contained in:
mimo
2018-04-12 17:18:24 +00:00
parent 4a5f5c58e6
commit fdba663e1d
5 changed files with 31 additions and 31 deletions
@@ -597,7 +597,7 @@ m.AttackManager.prototype.getRelicEnemyPlayer = function(gameState, attack)
for (let i = 0; i < gameState.sharedScript.playersData.length; ++i)
{
if (!gameState.isPlayerEnemy(i) || this.defeated[i] ||
i == 0 && !gameState.ai.HQ.gameTypeManager.tryCaptureGaiaRelic)
i == 0 && !gameState.ai.HQ.victoryManager.tryCaptureGaiaRelic)
continue;
let relicsCount = allRelics.filter(relic => relic.owner() == i).length;
@@ -611,7 +611,7 @@ m.AttackManager.prototype.getRelicEnemyPlayer = function(gameState, attack)
if (attack.targetPlayer === undefined)
this.currentEnemyPlayer = enemyPlayer;
if (enemyPlayer == 0)
gameState.ai.HQ.gameTypeManager.resetCaptureGaiaRelic(gameState);
gameState.ai.HQ.victoryManager.resetCaptureGaiaRelic(gameState);
}
return enemyPlayer;
};
@@ -747,7 +747,7 @@ m.AttackPlan.prototype.isAvailableUnit = function(gameState, ent)
if (ent.getMetadata(PlayerID, "plan") !== undefined && ent.getMetadata(PlayerID, "plan") !== -1 ||
ent.getMetadata(PlayerID, "transport") !== undefined || ent.getMetadata(PlayerID, "transporter") !== undefined)
return false;
if (gameState.ai.HQ.gameTypeManager.criticalEnts.has(ent.id()) && (this.overseas || ent.healthLevel() < 0.8))
if (gameState.ai.HQ.victoryManager.criticalEnts.has(ent.id()) && (this.overseas || ent.healthLevel() < 0.8))
return false;
return true;
};
@@ -893,7 +893,7 @@ m.AttackPlan.prototype.getNearestTarget = function(gameState, position, sameLand
for (let ent of targets.values())
{
if (this.targetPlayer == 0 && gameState.getVictoryConditions().has("capture_the_relic") &&
(!ent.hasClass("Relic") || gameState.ai.HQ.gameTypeManager.targetedGaiaRelics.has(ent.id())))
(!ent.hasClass("Relic") || gameState.ai.HQ.victoryManager.targetedGaiaRelics.has(ent.id())))
continue;
// Do not bother with some pointless targets
if (!this.isValidTarget(ent))
@@ -917,7 +917,7 @@ m.AttackPlan.prototype.getNearestTarget = function(gameState, position, sameLand
if (!target)
return undefined;
if (this.targetPlayer == 0 && gameState.getVictoryConditions().has("capture_the_relic") && target.hasClass("Relic"))
gameState.ai.HQ.gameTypeManager.targetedGaiaRelics.set(target.id(), [this.name]);
gameState.ai.HQ.victoryManager.targetedGaiaRelics.set(target.id(), [this.name]);
// Rushes can change their enemy target if nothing found with the preferred enemy
// Obstruction also can change the enemy target
this.targetPlayer = target.owner();
@@ -438,7 +438,7 @@ m.DefenseManager.prototype.assignDefenders = function(gameState)
if (ent.getMetadata(PlayerID, "transport") !== undefined ||
ent.getMetadata(PlayerID, "transporter") !== undefined)
return;
if (gameState.ai.HQ.gameTypeManager.criticalEnts.has(ent.id()))
if (gameState.ai.HQ.victoryManager.criticalEnts.has(ent.id()))
return;
if (ent.getMetadata(PlayerID, "plan") !== undefined && ent.getMetadata(PlayerID, "plan") != -1)
{
@@ -521,7 +521,7 @@ m.DefenseManager.prototype.abortArmy = function(gameState, army)
* If our defense structures are attacked, garrison soldiers inside when possible
* and if a support unit is attacked and has less than 55% health, garrison it inside the nearest healing structure
* and if a ranged siege unit (not used for defense) is attacked, garrison it in the nearest fortress
* If our hero is attacked in regicide game mode, the gameTypeManager will handle it
* If our hero is attacked with regicide victory condition, the victoryManager will handle it
*/
m.DefenseManager.prototype.checkEvents = function(gameState, events)
{
@@ -8,7 +8,7 @@ var PETRA = function(m)
* in wonder, train military guards.
*/
m.GameTypeManager = function(Config)
m.VictoryManager = function(Config)
{
this.Config = Config;
this.criticalEnts = new Map();
@@ -22,9 +22,9 @@ m.GameTypeManager = function(Config)
};
/**
* Cache the ids of any inital gameType-critical entities.
* Cache the ids of any inital victory-critical entities.
*/
m.GameTypeManager.prototype.init = function(gameState)
m.VictoryManager.prototype.init = function(gameState)
{
if (gameState.getVictoryConditions().has("wonder"))
{
@@ -59,11 +59,11 @@ m.GameTypeManager.prototype.init = function(gameState)
};
/**
* In regicide mode, if the hero has less than 70% health, try to garrison it in a healing structure
* In regicide victory condition, if the hero has less than 70% health, try to garrison it in a healing structure
* If it is less than 40%, try to garrison in the closest possible structure
* If the hero cannot garrison, retreat it to the closest base
*/
m.GameTypeManager.prototype.checkEvents = function(gameState, events)
m.VictoryManager.prototype.checkEvents = function(gameState, events)
{
if (gameState.getVictoryConditions().has("wonder"))
{
@@ -307,7 +307,7 @@ m.GameTypeManager.prototype.checkEvents = function(gameState, events)
}
};
m.GameTypeManager.prototype.removeCriticalEnt = function(gameState, criticalEntId)
m.VictoryManager.prototype.removeCriticalEnt = function(gameState, criticalEntId)
{
for (let [guardId, role] of this.criticalEnts.get(criticalEntId).guards)
{
@@ -333,7 +333,7 @@ m.GameTypeManager.prototype.removeCriticalEnt = function(gameState, criticalEntI
/**
* Train more healers to be later affected to critical entities if needed
*/
m.GameTypeManager.prototype.manageCriticalEntHealers = function(gameState, queues)
m.VictoryManager.prototype.manageCriticalEntHealers = function(gameState, queues)
{
if (gameState.ai.HQ.saveResources || queues.healer.hasQueuedUnits() ||
!gameState.getOwnEntitiesByClass("Temple", true).hasEntities() ||
@@ -355,7 +355,7 @@ m.GameTypeManager.prototype.manageCriticalEntHealers = function(gameState, queue
* If we have too low a population and require units for other needs, remove guards so they can be reassigned.
* TODO: Swap citizen soldier guards with champions if they become available.
*/
m.GameTypeManager.prototype.manageCriticalEntGuards = function(gameState)
m.VictoryManager.prototype.manageCriticalEntGuards = function(gameState)
{
let numWorkers = gameState.getOwnEntitiesByRole("worker", true).length;
if (numWorkers < 20)
@@ -442,7 +442,7 @@ m.GameTypeManager.prototype.manageCriticalEntGuards = function(gameState)
}
};
m.GameTypeManager.prototype.tryAssignMilitaryGuard = function(gameState, guardEnt, criticalEnt, checkForSameAccess)
m.VictoryManager.prototype.tryAssignMilitaryGuard = function(gameState, guardEnt, criticalEnt, checkForSameAccess)
{
if (guardEnt.getMetadata(PlayerID, "plan") !== undefined ||
guardEnt.getMetadata(PlayerID, "transport") !== undefined || this.criticalEnts.has(guardEnt.id()) ||
@@ -458,7 +458,7 @@ m.GameTypeManager.prototype.tryAssignMilitaryGuard = function(gameState, guardEn
return true;
};
m.GameTypeManager.prototype.pickCriticalEntRetreatLocation = function(gameState, criticalEnt, emergency)
m.VictoryManager.prototype.pickCriticalEntRetreatLocation = function(gameState, criticalEnt, emergency)
{
gameState.ai.HQ.defenseManager.garrisonAttackedUnit(gameState, criticalEnt, emergency);
let plan = criticalEnt.getMetadata(PlayerID, "plan");
@@ -489,7 +489,7 @@ m.GameTypeManager.prototype.pickCriticalEntRetreatLocation = function(gameState,
* which will be used once its transport has finished.
* Return false if the guardEnt is not a valid guard unit (i.e. cannot guard or is being transported).
*/
m.GameTypeManager.prototype.assignGuardToCriticalEnt = function(gameState, guardEnt, criticalEntId)
m.VictoryManager.prototype.assignGuardToCriticalEnt = function(gameState, guardEnt, criticalEntId)
{
if (guardEnt.getMetadata(PlayerID, "transport") !== undefined || !guardEnt.canGuard())
return false;
@@ -564,14 +564,14 @@ m.GameTypeManager.prototype.assignGuardToCriticalEnt = function(gameState, guard
return true;
};
m.GameTypeManager.prototype.resetCaptureGaiaRelic = function(gameState)
m.VictoryManager.prototype.resetCaptureGaiaRelic = function(gameState)
{
// Do not capture gaia relics too frequently as the ai has access to the entire map
this.tryCaptureGaiaRelicLapseTime = gameState.ai.elapsedTime + 240 - 30 * (this.Config.difficulty - 3);
this.tryCaptureGaiaRelic = false;
};
m.GameTypeManager.prototype.update = function(gameState, events, queues)
m.VictoryManager.prototype.update = function(gameState, events, queues)
{
// Wait a turn for trigger scripts to spawn any critical ents (i.e. in regicide)
if (gameState.ai.playedTurn == 1)
@@ -651,7 +651,7 @@ m.GameTypeManager.prototype.update = function(gameState, events, queues)
/**
* Send an expedition to capture a gaia relic, or reinforce an existing one.
*/
m.GameTypeManager.prototype.captureGaiaRelic = function(gameState, relic)
m.VictoryManager.prototype.captureGaiaRelic = function(gameState, relic)
{
let capture = -relic.defaultRegenRate();
let sumCapturePoints = relic.capturePoints().reduce((a, b) => a + b);
@@ -715,7 +715,7 @@ m.GameTypeManager.prototype.captureGaiaRelic = function(gameState, relic)
this.targetedGaiaRelics.get(relic.id()).push(plan);
};
m.GameTypeManager.prototype.abortCaptureGaiaRelic = function(gameState, relicId)
m.VictoryManager.prototype.abortCaptureGaiaRelic = function(gameState, relicId)
{
for (let plan of this.targetedGaiaRelics.get(relicId))
{
@@ -726,7 +726,7 @@ m.GameTypeManager.prototype.abortCaptureGaiaRelic = function(gameState, relicId)
this.targetedGaiaRelics.delete(relicId);
};
m.GameTypeManager.prototype.Serialize = function()
m.VictoryManager.prototype.Serialize = function()
{
return {
"criticalEnts": this.criticalEnts,
@@ -738,7 +738,7 @@ m.GameTypeManager.prototype.Serialize = function()
};
};
m.GameTypeManager.prototype.Deserialize = function(data)
m.VictoryManager.prototype.Deserialize = function(data)
{
for (let key in data)
this[key] = data[key];
@@ -48,7 +48,7 @@ m.HQ = function(Config)
this.researchManager = new m.ResearchManager(this.Config);
this.diplomacyManager = new m.DiplomacyManager(this.Config);
this.garrisonManager = new m.GarrisonManager(this.Config);
this.gameTypeManager = new m.GameTypeManager(this.Config);
this.victoryManager = new m.VictoryManager(this.Config);
this.capturableTargets = new Map();
this.capturableTargetsTime = 0;
@@ -1597,7 +1597,7 @@ m.HQ.prototype.buildFarmstead = function(gameState, queues)
/**
* Try to build a wonder when required
* force = true when called from the gameTypeManager in case of Wonder mode
* force = true when called from the victoryManager in case of Wonder victory condition.
*/
m.HQ.prototype.buildWonder = function(gameState, queues, force = false)
{
@@ -2745,7 +2745,7 @@ m.HQ.prototype.update = function(gameState, queues, events)
this.diplomacyManager.update(gameState, events);
this.gameTypeManager.update(gameState, events, queues);
this.victoryManager.update(gameState, events, queues);
// We update the capture strength at the end as it can change attack orders
if (gameState.ai.elapsedTime - this.capturableTargetsTime > 3)
@@ -2800,7 +2800,7 @@ m.HQ.prototype.Serialize = function()
API3.warn(" researchManager " + uneval(this.researchManager.Serialize()));
API3.warn(" diplomacyManager " + uneval(this.diplomacyManager.Serialize()));
API3.warn(" garrisonManager " + uneval(this.garrisonManager.Serialize()));
API3.warn(" gameTypeManager " + uneval(this.gameTypeManager.Serialize()));
API3.warn(" victoryManager " + uneval(this.victoryManager.Serialize()));
}
return {
@@ -2815,7 +2815,7 @@ m.HQ.prototype.Serialize = function()
"researchManager": this.researchManager.Serialize(),
"diplomacyManager": this.diplomacyManager.Serialize(),
"garrisonManager": this.garrisonManager.Serialize(),
"gameTypeManager": this.gameTypeManager.Serialize(),
"victoryManager": this.victoryManager.Serialize(),
};
};
@@ -2863,8 +2863,8 @@ m.HQ.prototype.Deserialize = function(gameState, data)
this.garrisonManager = new m.GarrisonManager(this.Config);
this.garrisonManager.Deserialize(data.garrisonManager);
this.gameTypeManager = new m.GameTypeManager(this.Config);
this.gameTypeManager.Deserialize(data.gameTypeManager);
this.victoryManager = new m.VictoryManager(this.Config);
this.victoryManager.Deserialize(data.victoryManager);
};
return m;