Petra: Initial Capture The Relic support

Patch by Sandarac
Differential Revision: https://code.wildfiregames.com/D236
This was SVN commit r19356.
This commit is contained in:
mimo 2017-03-28 18:51:10 +00:00
parent da2b89583a
commit 5dcc52f46a
3 changed files with 83 additions and 33 deletions

View file

@ -360,6 +360,29 @@ m.AttackManager.prototype.getEnemyPlayer = function(gameState, attack)
return enemyPlayer;
}
}
else if (gameState.getGameType() === "capture_the_relic")
{
// Target the player with the most relics
let maxRelicsOwned = 0;
// TODO: target gaia relics
for (let i = 1; i < gameState.sharedScript.playersData.length; ++i)
{
if (!gameState.isPlayerEnemy(i) || this.defeated[i])
continue;
let relicsCount = gameState.getEnemyUnits(i).filter(API3.Filters.byClass("Relic")).length;
if (relicsCount <= maxRelicsOwned)
continue;
maxRelicsOwned = relicsCount;
enemyPlayer = i;
}
if (enemyPlayer)
{
if (attack.targetPlayer === undefined)
this.currentEnemyPlayer = enemyPlayer;
return enemyPlayer;
}
}
let veto = {};
for (let i in this.defeated)

View file

@ -834,6 +834,8 @@ m.AttackPlan.prototype.defaultTargetFinder = function(gameState, playerEnemy)
targets = gameState.getEnemyStructures(playerEnemy).filter(API3.Filters.byClass("Wonder"));
else if (gameState.getGameType() === "regicide")
targets = gameState.getEnemyUnits(playerEnemy).filter(API3.Filters.byClass("Hero"));
else if (gameState.getGameType() === "capture_the_relic")
targets = gameState.getEnemyUnits(playerEnemy).filter(API3.Filters.byClass("Relic"));
if (targets && targets.hasEntities())
return targets;

View file

@ -170,26 +170,7 @@ m.GameTypeManager.prototype.checkEvents = function(gameState, events)
let entId = evt.entityObj.id();
if (this.criticalEnts.has(entId))
{
for (let [guardId, role] of this.criticalEnts.get(entId).guards)
{
let guardEnt = gameState.getEntityById(guardId);
if (!guardEnt)
continue;
if (role === "healer")
this.guardEnts.set(guardId, false);
else
{
guardEnt.setMetadata(PlayerID, "plan", -1);
guardEnt.setMetadata(PlayerID, "role", undefined);
this.guardEnts.delete(guardId);
}
if (guardEnt.getMetadata(PlayerID, "guardedEnt"))
guardEnt.setMetadata(PlayerID, "guardedEnt", undefined);
}
this.criticalEnts.delete(entId);
this.removeGuardsFromCriticalEnt(gameState, entId);
continue;
}
@ -245,6 +226,50 @@ m.GameTypeManager.prototype.checkEvents = function(gameState, events)
}
}
}
for (let evt of events.OwnershipChanged)
{
if (evt.from === PlayerID && this.criticalEnts.has(evt.entity))
{
this.removeGuardsFromCriticalEnt(gameState, evt.entity);
continue;
}
if (evt.to !== PlayerID)
continue;
let ent = gameState.getEntityById(evt.entity);
if (ent && (gameState.getGameType() === "wonder" && ent.hasClass("Wonder") ||
gameState.getGameType() === "capture_the_relic" && ent.hasClass("Relic")))
{
this.criticalEnts.set(ent.id(), { "guardsAssigned": 0, "guards": new Map() });
// Move captured relics to the closest base
if (ent.hasClass("Unit"))
this.pickCriticalEntRetreatLocation(gameState, ent, false);
}
}
};
m.GameTypeManager.prototype.removeGuardsFromCriticalEnt = function(gameState, criticalEntId)
{
for (let [guardId, role] of this.criticalEnts.get(criticalEntId).guards)
{
let guardEnt = gameState.getEntityById(guardId);
if (!guardEnt)
continue;
if (role === "healer")
this.guardEnts.set(guardId, false);
else
{
guardEnt.setMetadata(PlayerID, "plan", -1);
guardEnt.setMetadata(PlayerID, "role", undefined);
this.guardEnts.delete(guardId);
}
if (guardEnt.getMetadata(PlayerID, "guardedEnt"))
guardEnt.setMetadata(PlayerID, "guardedEnt", undefined);
}
this.criticalEnts.delete(evt.entity);
};
m.GameTypeManager.prototype.buildWonder = function(gameState, queues)
@ -474,24 +499,24 @@ m.GameTypeManager.prototype.update = function(gameState, events, queues)
this.manageCriticalEntGuards(gameState);
}
if (gameState.getGameType() === "regicide")
if (gameState.getGameType() === "regicide" && gameState.ai.playedTurn % 10 === 0)
{
if (gameState.ai.playedTurn % 10 === 0)
for (let [id, data] of this.criticalEnts)
{
for (let [id, data] of this.criticalEnts)
{
let ent = gameState.getEntityById(id);
if (ent && ent.healthLevel() > 0.7 && ent.hasClass("Soldier") &&
data.stance !== "aggressive")
ent.setStance("aggressive");
let ent = gameState.getEntityById(id);
if (ent && ent.healthLevel() > 0.7 && ent.hasClass("Soldier") &&
data.stance !== "aggressive")
ent.setStance("aggressive");
if (data.healersAssigned < this.healersPerCriticalEnt &&
this.guardEnts.size < Math.min(gameState.getPopulationMax() / 10, gameState.getPopulation() / 4))
this.trainCriticalEntHealer(gameState, queues, id);
}
this.manageCriticalEntGuards(gameState);
if (data.healersAssigned < this.healersPerCriticalEnt &&
this.guardEnts.size < Math.min(gameState.getPopulationMax() / 10, gameState.getPopulation() / 4))
this.trainCriticalEntHealer(gameState, queues, id);
}
this.manageCriticalEntGuards(gameState);
}
if (gameState.getGameType() === "capture_the_relic" && gameState.ai.playedTurn % 10 === 0)
this.manageCriticalEntGuards(gameState);
};
m.GameTypeManager.prototype.Serialize = function()