// A file of helper functions for getting player/npc status-related strings.
//TODO: Dry this up more.
module.exports = {
  getHealthText: getHealthText,
  getSanityText: getSanityText,
  getGenderNoun: getGenderNoun,
  getStatusColor: getStatusColor,
  getPercentage: getPercentage
};

function getHealthText(maxHealth, player, npc) {
  return function(health) {
    var locale = player ? player.getLocale() : 'en';
    var isPlayer = !npc;
    var percentage = getPercentage(health, maxHealth);
    var noun = isPlayer ? getGenderNoun(player.getGender()) : 'creature';
    var nounPhrase = isPlayer ? 'You are ' : npc.getShortDesc(locale) + ' is ';
    var color = getStatusColor(percentage);

    var healthStatus = {
      0: 'a dead ' + noun + ' walking',
      5: 'hanging by a thread',
      10: 'in excruciating pain',
      15: 'wracked by pain',
      25: 'maimed',
      35: 'gravely wounded',
      50: 'wounded',
      60: 'in awful shape',
      70: 'feeling poor',
      80: 'in average physical health',
      90: 'in good physical health',
      95: 'in great health',
      100: 'in perfect physical health'
    };

    for (var tier in healthStatus) {
      if (percentage <= parseInt(tier)) {
        return '<' + color + '>' + nounPhrase + healthStatus[tier] +
          '.</' + color + '>';
      }
    }
  }
}

function getSanityText(maxSanity, player) {
  return function(sanity) {
    var percentage = getPercentage(sanity, maxSanity);
    var sanityStatus = {
      0:  'consumed by madness',
      10: 'nearing insanity',
      15: 'feeling dysphoric',
      50: 'stressed to breaking',
      60: 'mentally unsound',
      70: 'feeling stressed',
      80: 'discontent',
      90: 'mentally well',
      95: 'quite stable',
      100: 'sharp as a knife'
    };

    var color = getStatusColor(percentage);
    for (var tier in sanityStatus) {
      if (percentage <= parseInt(tier)) {
        return '<' + color + '>You are ' + sanityStatus[tier] +
          '.</' + color + '>';
      }
    }
    return '<' + color + '>You are feeling strange.</' + color + '>';
  }
}

function getActionText(maxSanity, player) {
  return function(sanity) {
    var percentage = getPercentage(energy, maxEnergy);
    var energyStatus = {
      0:  'consumed by madness',
      10: 'nearing insanity',
      15: 'feeling dysphoric',
      50: 'stressed to breaking',
      60: 'mentally unsound',
      70: 'feeling stressed',
      80: 'discontent',
      90: 'mentally well',
      95: 'quite stable',
      100: 'sharp as a knife'
    };

    var color = getStatusColor(percentage);
    for (var tier in sanityStatus) {
      if (percentage <= parseInt(tier)) {
        return '<' + color + '>You are ' + sanityStatus[tier] +
          '.</' + color + '>';
      }
    }
    return '<' + color + '>You are feeling strange.</' + color + '>';
  }
}


function getGenderNoun(gender) {
  var nouns = {
    M: 'man',
    F: 'woman',
    A: 'person'
  };
  return nouns[gender] || nouns.A;
}

function getStatusColor(percentage) {
  return percentage > 50 ? 'green' : 'red'
}

function getPercentage(numerator, denominator){
  return Math.floor((numerator / denominator) * 100);
}

@@ -2109,37 +2109,37 @@
 etActionText(max
-Sanit
+Energ
 y, player) %7B%0A  r
@@ -2145,37 +2145,37 @@
 return function(
-sanit
+energ
 y) %7B%0A    var per
@@ -2254,35 +2254,30 @@
    0:  '
-consumed by madness
+unable to move
 ',%0A     
@@ -2282,32 +2282,26 @@
    10: '
-nearing insanity
+dead tired
 ',%0A     
@@ -2310,88 +2310,55 @@
 5: '
-feeling dysphoric',%0A      50: 'stressed to breaking',%0A      60: 'mentally unsoun
+exhausted',%0A      50: 'drowsy',%0A      60: 'tire
 d',%0A
@@ -2365,37 +2365,29 @@
       70: 'f
-eeling stress
+atigu
 ed',%0A      8
@@ -2386,34 +2386,29 @@
 %0A      80: '
-discontent
+weary
 ',%0A      90:
@@ -2405,37 +2405,30 @@
 %0A      90: '
-mentally well
+active
 ',%0A      95:
@@ -2425,36 +2425,28 @@
 %0A      95: '
-quite stable
+spry
 ',%0A      100
@@ -2448,32 +2448,21 @@
   100: '
-sharp as a knife
+fresh
 '%0A    %7D;
@@ -2621,37 +2621,37 @@
 + '%3EYou are ' + 
-sanit
+energ
 yStatus%5Btier%5D +%0A
@@ -2962,32 +2962,63 @@
 urn 
-percentage %3E 50 ? 'green
+status %3E 75 ?%0A    'green' : status %3E 35 ?%0A      'yellow
 ' : 
@@ -3022,16 +3022,17 @@
  : 'red'
+;
 %0A%7D%0A%0Afunc

Change status colors to include yellow and be a bit more colorful :sunny: