Changeset View
Standalone View
binaries/data/mods/public/simulation/ai/common-api/entity.js
Show First 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | m.Template = m.Class({ | ||||
"isRepairable": function() { return this.get("Repairable") !== undefined; }, | "isRepairable": function() { return this.get("Repairable") !== undefined; }, | ||||
"getPopulationBonus": function() { return +this.get("Cost/PopulationBonus"); }, | "getPopulationBonus": function() { return +this.get("Cost/PopulationBonus"); }, | ||||
"armourStrengths": function() { | "armourStrengths": function() { | ||||
if (!this.get("Armour")) | if (!this.get("Armour")) | ||||
return undefined; | return undefined; | ||||
return { | let armour = {}; | ||||
"Hack": +this.get("Armour/Hack"), | for (let damageType in this.get("Armour")) | ||||
"Pierce": +this.get("Armour/Pierce"), | if (damageType != "Foundation") | ||||
"Crush": +this.get("Armour/Crush") | armour[damageType] = +this.get("Armour/" + damageType); | ||||
}; | |||||
wraitii: I think here instead we should have the AI construct a dict of all armour types that the… | |||||
Done Inline ActionsWell, *we* can understand that if nothing is specified it ought to be zero, but this lets the AI "understand" that as well. Freagarach: Well, *we* can understand that if nothing is specified it ought to be zero, but this lets the… | |||||
Done Inline ActionsThat should probably be handled at the call-site, rather. wraitii: That should probably be handled at the call-site, rather. | |||||
Done Inline ActionsHere check if the entity is a foundation and return the foundation damage if so. wraitii: Here check if the entity is a foundation and return the foundation damage if so. | |||||
Done Inline ActionsIt seems that it is never called for buildings. Should I still return foundation damages? Freagarach: It seems that it is never called for buildings. Should I still return foundation damages? | |||||
Done Inline ActionsI guess it also didn't work before... wraitii: I guess it also didn't work before...
Feel free to just add a "TODO implement". | |||||
Done Inline ActionsI read that adding "TODO" in code is not appreciated;
(I do not recall where I read it, I think it was in a old ticket on trac ;) ) Freagarach: I read that adding "TODO" in code is not appreciated;
> we have trac for that
(I do not recall… | |||||
Done Inline ActionsSame here: for (let damageType in template.Armour) if (damageType != "Foundation") armour[damageType] = +this.get("Armour/" + damageType); Stan: Same here:
```lang=js
for (let damageType in template.Armour)
if (damageType != "Foundation")… | |||||
return armour; | |||||
Done Inline ActionsI think armour is also a mass-noun. ArmourTypes perhaps here. wraitii: I think `armour` is also a mass-noun. ArmourTypes perhaps here. | |||||
Done Inline ActionsIt should be armor I think https://trac.wildfiregames.com/wiki/EnglishStyleGuide Stan: It should be armor I think https://trac.wildfiregames.com/wiki/EnglishStyleGuide | |||||
Done Inline ActionsThe style guide only applies to user-facing text strings; “armor” because US spelling. Nescio: The style guide only applies to user-facing text strings; “armor” because US spelling.
However… | |||||
}, | }, | ||||
"attackTypes": function() { | "attackTypes": function() { | ||||
if (!this.get("Attack")) | if (!this.get("Attack")) | ||||
return undefined; | return undefined; | ||||
let ret = []; | let ret = []; | ||||
for (let type in this.get("Attack")) | for (let type in this.get("Attack")) | ||||
ret.push(type); | ret.push(type); | ||||
return ret; | return ret; | ||||
}, | }, | ||||
"attackRange": function(type) { | "attackRange": function(type) { | ||||
if (!this.get("Attack/" + type +"")) | if (!this.get("Attack/" + type +"")) | ||||
return undefined; | return undefined; | ||||
return { | return { | ||||
"max": +this.get("Attack/" + type +"/MaxRange"), | "max": +this.get("Attack/" + type +"/MaxRange"), | ||||
"min": +(this.get("Attack/" + type +"/MinRange") || 0) | "min": +(this.get("Attack/" + type +"/MinRange") || 0) | ||||
}; | }; | ||||
}, | }, | ||||
"attackStrengths": function(type) { | "attackStrengths": function(type) { | ||||
if (!this.get("Attack/" + type +"")) | let path = "Attack/" + type +"/Damage/" | ||||
wraitiiUnsubmitted Done Inline ActionsDoesn't work with the final '/' wraitii: Doesn't work with the final '/' | |||||
if (!this.get(path)) | |||||
Done Inline ActionsThis will not work at line 239, because missing / at the end Silier: This will not work at line 239, because missing / at the end | |||||
return undefined; | return undefined; | ||||
return { | let damage = {}; | ||||
"Hack": +(this.get("Attack/" + type + "/Damage/Hack") || 0), | for (let damageType in this.get(path)) | ||||
"Pierce": +(this.get("Attack/" + type + "/Damage/Pierce") || 0), | damage[damageType] = +this.get(path + damageType); | ||||
Done Inline ActionsMaybe cache "Attack/" + type + "/Damage/" into a variable ? so it's not recomputed every time. Stan: Maybe cache "Attack/" + type + "/Damage/" into a variable ? so it's not recomputed every time. | |||||
wraitiiUnsubmitted Done Inline Actionsthis.get(path) should be called once only, I kinda doubt JS automatically optimises this well. wraitii: `this.get(path)` should be called once only, I kinda doubt JS automatically optimises this well. | |||||
SilierUnsubmitted Done Inline ActionsI meant path + "/" + damageType Silier: I meant
```
path + "/" + damageType
```
| |||||
"Crush": +(this.get("Attack/" + type + "/Damage/Crush") || 0) | |||||
}; | return damage; | ||||
Done Inline ActionsLikewise wraitii: Likewise | |||||
}, | }, | ||||
"captureStrength": function() { | "captureStrength": function() { | ||||
if (!this.get("Attack/Capture")) | if (!this.get("Attack/Capture")) | ||||
return undefined; | return undefined; | ||||
return +this.get("Attack/Capture/Value") || 0; | return +this.get("Attack/Capture/Value") || 0; | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 698 Lines • Show Last 20 Lines |
I think here instead we should have the AI construct a dict of all armour types that the template has. There's no reason to use DamageTypes.GetTypes() over the template data.