Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/entityExtend.js
var PETRA = function(m) | var PETRA = function(m) | ||||
{ | { | ||||
/** returns true if this unit should be considered as a siege unit */ | /** returns true if this unit should be considered as a siege unit */ | ||||
m.isSiegeUnit = function(ent) | m.isSiegeUnit = function(ent) | ||||
{ | { | ||||
return ent.hasClass("Siege") || ent.hasClass("Elephant") && ent.hasClass("Melee") && ent.hasClass("Champion"); | return ent.hasClass("Siege") || ent.hasClass("Elephant") && ent.hasClass("Melee") && ent.hasClass("Champion"); | ||||
}; | }; | ||||
/** returns some sort of DPS * health factor. If you specify a class, it'll use the modifiers against that class too. */ | /** returns some sort of DPS * health factor. If you specify a class, it'll use the modifiers against that class too. */ | ||||
m.getMaxStrength = function(ent, againstClass) | m.getMaxStrength = function(ent, damageTypeFactors, againstClass) | ||||
{ | { | ||||
let strength = 0; | let strength = 0; | ||||
let attackTypes = ent.attackTypes(); | let attackTypes = ent.attackTypes(); | ||||
let damageTypes = Object.keys(damageTypeFactors); | |||||
if (!attackTypes) | if (!attackTypes) | ||||
return strength; | return strength; | ||||
for (let type of attackTypes) | for (let type of attackTypes) | ||||
{ | { | ||||
if (type == "Slaughter") | if (type == "Slaughter") | ||||
continue; | continue; | ||||
let attackStrength = ent.attackStrengths(type); | let attackStrength = ent.attackStrengths(type); | ||||
for (let str in attackStrength) | for (let str in attackStrength) | ||||
{ | { | ||||
let val = parseFloat(attackStrength[str]); | let val = parseFloat(attackStrength[str]); | ||||
if (againstClass) | if (againstClass) | ||||
val *= ent.getMultiplierAgainst(type, againstClass); | val *= ent.getMultiplierAgainst(type, againstClass); | ||||
switch (str) | damageTypeFactors[str] ? strength += damageTypeFactors[str] * val / damageTypes.length : | ||||
{ | API3.warn("Petra: " + str + " unknown attackStrength in getMaxStrength (please add " + str + " to config.js)."); | ||||
wraitii: Not a fan of the ternary here - in general I usually prefer ifs which I find simply more… | |||||
StanUnsubmitted Done Inline ActionsSeems harder to see no ? Stan: Seems harder to see no ? | |||||
wraitiiUnsubmitted Done Inline ActionsDiscussed a bit on irc... What I dislike is that it forces anybody adding a new damage type to change the AI, including mods, which seems like it will happen a lot and thus conflict a lot and I just don't really like that. One option would be to hide the warning behind the AI debug levels: wraitii: Discussed a bit on irc... What I dislike is that it forces anybody adding a new damage type to… | |||||
case "Crush": | |||||
strength += val * 0.085 / 3; | |||||
break; | |||||
case "Hack": | |||||
strength += val * 0.075 / 3; | |||||
break; | |||||
case "Pierce": | |||||
strength += val * 0.065 / 3; | |||||
break; | |||||
default: | |||||
API3.warn("Petra: " + str + " unknown attackStrength in getMaxStrength"); | |||||
} | |||||
} | } | ||||
let attackRange = ent.attackRange(type); | let attackRange = ent.attackRange(type); | ||||
if (attackRange) | if (attackRange) | ||||
strength += attackRange.max * 0.0125; | strength += attackRange.max * 0.0125; | ||||
let attackTimes = ent.attackTimes(type); | let attackTimes = ent.attackTimes(type); | ||||
for (let str in attackTimes) | for (let str in attackTimes) | ||||
Show All 12 Lines | for (let str in attackTimes) | ||||
} | } | ||||
} | } | ||||
} | } | ||||
let armourStrength = ent.armourStrengths(); | let armourStrength = ent.armourStrengths(); | ||||
for (let str in armourStrength) | for (let str in armourStrength) | ||||
{ | { | ||||
let val = parseFloat(armourStrength[str]); | let val = parseFloat(armourStrength[str]); | ||||
switch (str) | damageTypeFactors[str] ? strength += damageTypeFactors[str] * val / damageTypes.length : | ||||
{ | API3.warn("Petra: " + str + " unknown armourStrength in getMaxStrength (please add " + str + " to config.js)."); | ||||
wraitiiUnsubmitted Done Inline ActionsSame wraitii: Same | |||||
case "Crush": | |||||
strength += val * 0.085 / 3; | |||||
break; | |||||
case "Hack": | |||||
strength += val * 0.075 / 3; | |||||
break; | |||||
case "Pierce": | |||||
strength += val * 0.065 / 3; | |||||
break; | |||||
default: | |||||
API3.warn("Petra: " + str + " unknown armourStrength in getMaxStrength"); | |||||
} | |||||
} | } | ||||
return strength * ent.maxHitpoints() / 100.0; | return strength * ent.maxHitpoints() / 100.0; | ||||
}; | }; | ||||
/** Get access and cache it (except for units as it can change) in metadata if not already done */ | /** Get access and cache it (except for units as it can change) in metadata if not already done */ | ||||
m.getLandAccess = function(gameState, ent) | m.getLandAccess = function(gameState, ent) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 349 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Not a fan of the ternary here - in general I usually prefer ifs which I find simply more readable - as you might have noticed at this point.
Also not a fan of warning - this forces somebody adding a new damage type to add it to the AI, which is annoying - I'd prefer it just silently returned zero.