Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | m.DefenseArmy.prototype.addFoe = function(gameState, enemyId, force) | ||||
// check distance | // check distance | ||||
if (!force && API3.SquareVectorDistance(ent.position(), this.foePosition) > this.compactSize) | if (!force && API3.SquareVectorDistance(ent.position(), this.foePosition) > this.compactSize) | ||||
return false; | return false; | ||||
this.foeEntities.push(enemyId); | this.foeEntities.push(enemyId); | ||||
this.assignedAgainst[enemyId] = []; | this.assignedAgainst[enemyId] = []; | ||||
this.positionLastUpdate = 0; | this.positionLastUpdate = 0; | ||||
this.evaluateStrength(ent); | this.evaluateStrength(ent, gameState.ai.Config.DamageTypeFactors); | ||||
Silier: use this.Config.DamageType... | |||||
ent.setMetadata(PlayerID, "PartOfArmy", this.ID); | ent.setMetadata(PlayerID, "PartOfArmy", this.ID); | ||||
return true; | return true; | ||||
}; | }; | ||||
/** | /** | ||||
* returns true if the entity was removed and false otherwise. | * returns true if the entity was removed and false otherwise. | ||||
* TODO: when there is a technology update, we should probably recompute the strengths, or weird stuffs will happen. | * TODO: when there is a technology update, we should probably recompute the strengths, or weird stuffs will happen. | ||||
Show All 9 Lines | m.DefenseArmy.prototype.removeFoe = function(gameState, enemyId, enemyEntity) | ||||
this.assignedAgainst[enemyId] = undefined; | this.assignedAgainst[enemyId] = undefined; | ||||
for (let to in this.assignedTo) | for (let to in this.assignedTo) | ||||
if (this.assignedTo[to] == enemyId) | if (this.assignedTo[to] == enemyId) | ||||
this.assignedTo[to] = undefined; | this.assignedTo[to] = undefined; | ||||
let ent = enemyEntity ? enemyEntity : gameState.getEntityById(enemyId); | let ent = enemyEntity ? enemyEntity : gameState.getEntityById(enemyId); | ||||
if (ent) // TODO recompute strength when no entities (could happen if capture+destroy) | if (ent) // TODO recompute strength when no entities (could happen if capture+destroy) | ||||
{ | { | ||||
this.evaluateStrength(ent, false, true); | this.evaluateStrength(ent, gameState.ai.Config.DamageTypeFactors, false, true); | ||||
ent.setMetadata(PlayerID, "PartOfArmy", undefined); | ent.setMetadata(PlayerID, "PartOfArmy", undefined); | ||||
} | } | ||||
return true; | return true; | ||||
}; | }; | ||||
/** | /** | ||||
* adds a defender but doesn't assign him yet. | * adds a defender but doesn't assign him yet. | ||||
* force is true when merging armies, so in this case we should add it even if no position as it can be in a ship | * force is true when merging armies, so in this case we should add it even if no position as it can be in a ship | ||||
*/ | */ | ||||
m.DefenseArmy.prototype.addOwn = function(gameState, id, force) | m.DefenseArmy.prototype.addOwn = function(gameState, id, force) | ||||
{ | { | ||||
if (this.ownEntities.indexOf(id) !== -1) | if (this.ownEntities.indexOf(id) !== -1) | ||||
return false; | return false; | ||||
let ent = gameState.getEntityById(id); | let ent = gameState.getEntityById(id); | ||||
if (!ent || !ent.position() && !force) | if (!ent || !ent.position() && !force) | ||||
return false; | return false; | ||||
this.ownEntities.push(id); | this.ownEntities.push(id); | ||||
this.evaluateStrength(ent, true); | this.evaluateStrength(ent, gameState.ai.Config.DamageTypeFactors, true); | ||||
ent.setMetadata(PlayerID, "PartOfArmy", this.ID); | ent.setMetadata(PlayerID, "PartOfArmy", this.ID); | ||||
this.assignedTo[id] = 0; | this.assignedTo[id] = 0; | ||||
let plan = ent.getMetadata(PlayerID, "plan"); | let plan = ent.getMetadata(PlayerID, "plan"); | ||||
if (plan !== undefined) | if (plan !== undefined) | ||||
ent.setMetadata(PlayerID, "plan", -2); | ent.setMetadata(PlayerID, "plan", -2); | ||||
else | else | ||||
ent.setMetadata(PlayerID, "plan", -3); | ent.setMetadata(PlayerID, "plan", -3); | ||||
Show All 19 Lines | if (temp) | ||||
temp.splice(temp.indexOf(id), 1); | temp.splice(temp.indexOf(id), 1); | ||||
} | } | ||||
this.assignedTo[id] = undefined; | this.assignedTo[id] = undefined; | ||||
let ent = Entity ? Entity : gameState.getEntityById(id); | let ent = Entity ? Entity : gameState.getEntityById(id); | ||||
if (!ent) | if (!ent) | ||||
return true; | return true; | ||||
this.evaluateStrength(ent, true, true); | this.evaluateStrength(ent, gameState.ai.Config.DamageTypeFactors, true, true); | ||||
ent.setMetadata(PlayerID, "PartOfArmy", undefined); | ent.setMetadata(PlayerID, "PartOfArmy", undefined); | ||||
if (ent.getMetadata(PlayerID, "plan") === -2) | if (ent.getMetadata(PlayerID, "plan") === -2) | ||||
ent.setMetadata(PlayerID, "plan", -1); | ent.setMetadata(PlayerID, "plan", -1); | ||||
else | else | ||||
ent.setMetadata(PlayerID, "plan", undefined); | ent.setMetadata(PlayerID, "plan", undefined); | ||||
let formerSubrole = ent.getMetadata(PlayerID, "formerSubrole"); | let formerSubrole = ent.getMetadata(PlayerID, "formerSubrole"); | ||||
if (formerSubrole !== undefined) | if (formerSubrole !== undefined) | ||||
▲ Show 20 Lines • Show All 304 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
m.DefenseArmy.prototype.recalculateStrengths = function(gameState) | m.DefenseArmy.prototype.recalculateStrengths = function(gameState) | ||||
{ | { | ||||
this.ownStrength = 0; | this.ownStrength = 0; | ||||
this.foeStrength = 0; | this.foeStrength = 0; | ||||
for (let id of this.foeEntities) | for (let id of this.foeEntities) | ||||
this.evaluateStrength(gameState.getEntityById(id)); | this.evaluateStrength(gameState.getEntityById(id), gameState.ai.Config.DamageTypeFactors); | ||||
for (let id of this.ownEntities) | for (let id of this.ownEntities) | ||||
this.evaluateStrength(gameState.getEntityById(id), true); | this.evaluateStrength(gameState.getEntityById(id), gameState.ai.Config.DamageTypeFactors, true); | ||||
}; | }; | ||||
/** adds or remove the strength of the entity either to the enemy or to our units. */ | /** adds or remove the strength of the entity either to the enemy or to our units. */ | ||||
m.DefenseArmy.prototype.evaluateStrength = function(ent, isOwn, remove) | m.DefenseArmy.prototype.evaluateStrength = function(ent, damageTypeFactors, isOwn, remove) | ||||
{ | { | ||||
if (!ent) | if (!ent) | ||||
Done Inline ActionsDo the factor change depending on the game state ? Else maybe instead of passing it everywhere it could be called directly here ? Stan: Do the factor change depending on the game state ? Else maybe instead of passing it everywhere… | |||||
Done Inline ActionsNo they don't. Freagarach: No they don't.
Well, I tried calling it in the "m.getMaxStrength" directly, but I couldn't get… | |||||
Done Inline ActionsOh, I understand, you mean calling it in "evaluateStrength", well we need the gamestate for that so we then need to pass the gamestate instead of DTFs. I thought that passing as little data as possible would be beneficial. Freagarach: Oh, I understand, you mean calling it in "evaluateStrength", well we need the gamestate for… | |||||
return; | return; | ||||
let entStrength; | let entStrength; | ||||
if (ent.hasClass("Structure")) | if (ent.hasClass("Structure")) | ||||
{ | { | ||||
if (ent.owner() !== PlayerID) | if (ent.owner() !== PlayerID) | ||||
entStrength = ent.getDefaultArrow() ? 6*ent.getDefaultArrow() : 4; | entStrength = ent.getDefaultArrow() ? 6*ent.getDefaultArrow() : 4; | ||||
else // small strength used only when we try to recover capture points | else // small strength used only when we try to recover capture points | ||||
entStrength = 2; | entStrength = 2; | ||||
} | } | ||||
else | else | ||||
entStrength = m.getMaxStrength(ent); | entStrength = m.getMaxStrength(ent, damageTypeFactors); | ||||
// TODO adapt the getMaxStrength function for animals. | // TODO adapt the getMaxStrength function for animals. | ||||
// For the time being, just increase it for elephants as the returned value is too small. | // For the time being, just increase it for elephants as the returned value is too small. | ||||
if (ent.hasClass("Animal") && ent.hasClass("Elephant")) | if (ent.hasClass("Animal") && ent.hasClass("Elephant")) | ||||
entStrength *= 3; | entStrength *= 3; | ||||
if (remove) | if (remove) | ||||
entStrength *= -1; | entStrength *= -1; | ||||
▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
use this.Config.DamageType...