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); | ||||
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 20 Lines • Show All 394 Lines • ▼ Show 20 Lines | for (let id of this.foeEntities) | ||||
this.evaluateStrength(gameState.getEntityById(id)); | this.evaluateStrength(gameState.getEntityById(id)); | ||||
for (let id of this.ownEntities) | for (let id of this.ownEntities) | ||||
this.evaluateStrength(gameState.getEntityById(id), true); | this.evaluateStrength(gameState.getEntityById(id), 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, 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, this.Config.debug, this.Config.DamageTypeImportance); | ||||
// 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...