HomeWildfire Games

Health.js cleanup: add tests, add an "IsInjured" function, use this.hitpoints…

Description

Health.js cleanup: add tests, add an "IsInjured" function, use this.hitpoints everywhere

Continuation of D1769.

Differential Revision: https://code.wildfiregames.com/D1828

Event Timeline

elexis added a subscriber: elexis.Jun 24 2019, 3:59 PM
elexis added inline comments.
/ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js
257

All callers to IsRepairable also check for IsInjured, hence isInjured may be checked inside isRepairable

/ps/trunk/binaries/data/mods/public/simulation/components/Health.js
86

this.maxHitpoints

118
  this.hitpoints <= 0 || !this.IsInjured()
= this.hitpoints <= 0 || !(this.hitpoints > 0 && this.hitpoints < this.maxHitpoints)
= this.hitpoints <= 0 || (this.hitpoints <= 0 || this.hitpoints >= this.maxHitpoints)
= this.hitpoints <= 0 || this.hitpoints >= this.maxHitpoints

IsUnhealable -> IsHealable? (one logical operation indirection less)

IsHealable  = this.hitpoints < this.maxHitpoints && this.hitpoints > 0 && this.template.Unhealable != "true"

(also ordering the conditions so that the one that is most often false comes first, for performance, though probably negligible)

396

(whitespace)

/ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
1429

This looks like it might be a positive behavior change, removing an edge case where a guarded entity that just died was ordered to be taken care of (unless that entity has stopped to exist at the point this code is processed, but usually they stick around for some short time)

elexis raised a concern with this commit.EditedJun 27 2019, 12:17 AM

From https://youtu.be/uqHzawvxhO8?t=1384

cmpHealth.IsInjured is not a function

Edit: Looks like clicking on a mirage

This commit now has outstanding concerns.Jun 27 2019, 12:17 AM

Indeed, I wasn't aware mirages needed specific code. D2018 fixes this.

wraitii requested verification of this commit.Aug 12 2019, 10:07 AM
This commit now requires verification by auditors.Aug 12 2019, 10:07 AM
elexis removed an auditor: elexis.Aug 12 2019, 10:58 AM
This commit no longer requires audit.Aug 12 2019, 10:58 AM