1. //gameUpdates
  2.  
  3. function Tick()
  4. {  
  5.    if ( updatePlayerHealth() != -1 )
  6.       $tickId = schedule(1000,0,"Tick");
  7. }
  8.  
  9. function updatePlayerHealth()
  10. {
  11.    %player = LocalClientConnection.player;
  12.    if (! isObject(%player) )
  13.       {
  14.          echo("updatePlayerHealth : player object not valid (" SPC $tickId SPC ")" );
  15.              
  16.          return -1;
  17.       }    
  18.      
  19.     // figures out the total health penalty at once
  20.     // this way, reducing the values will "raise" the players over-all health
  21.     %amount = 0;
  22.    
  23.     %totalPossibleDamge = 0;
  24.    
  25.     // JY - NOTE: The latest changes make sure that you won't die by a single low value
  26.     // rather by a combination of thirst, hunger and Heat
  27.    
  28.     // HUNGER health loss
  29.     %hungerDmg=0;
  30.     if(Hunger.getValue() > 0.1)
  31.       {
  32.         %hungerDmg = 100 * (Hunger.GetValue()-0.1);
  33.         echo("Hunger health penalty is " @ %hungerDmg);
  34.  
  35.         // tracks the MAX damage taken
  36.         if (%hungerDmg > $Player::HungerDamage)
  37.          $Player::HungerDamage = %hungerDmg;
  38.          
  39.         %totalPossibleDamge = %totalPossibleDamge - 90;
  40.       }
  41.    
  42.  
  43.     // WATER health loss
  44.     %thirstDmg=0;
  45.     if(Thirst.GetValue() > 0.1)
  46.       {
  47.          %thirstDmg = 100 * (Thirst.GetValue()-0.1); // ... .1 = -10, .5 = -50, .9 = -90
  48.  
  49.         // tracks the MAX damage taken
  50.         if (%hungerDmg > $Player::ThirstDamage)
  51.          $Player::ThirstDamage = %thirstDmg;
  52.  
  53.         echo("Thirst health penalty is " @ %thirstDmg);
  54.         %totalPossibleDamge = %totalPossibleDamge - 90;    
  55.       }  
  56.    
  57.        
  58.     // HEAT health loss
  59.     %tempDmg = 0;
  60.     if (Heat.GetValue() < 0.4)
  61.     {
  62.       %tempDmg = (0.4 - Heat.GetValue()) * 200; // 0.01 to 0.40 = 80 to 2
  63.       %totalPossibleDamge = %totalPossibleDamge - 80; // max 80 dmg
  64.       echo("Heat health penalty is " @ %tempDmg);      
  65.     }
  66.     else if (Heat.GetValue() > 0.6)
  67.     {
  68.       echo("The heat is getting to you ...");
  69.       %tempDmg = (Heat.GetValue() - 0.6) * 100; // 0.01 to 0.40 = 1 to 40
  70.       %totalPossibleDamge = %totalPossibleDamge - 40; // max 40 dmg
  71.       echo("Heat health penalty is " @ %tempDmg);      
  72.     }    
  73.     if (%tempDmg > $Player::TempDamage)
  74.          $Player::TempDamage = %tempDmg;
  75.    
  76.     // determine actual over-all impact on players health
  77.     // and keep it seperate from actual damage from wounds, etc.
  78.     %amount = 0 - %thirstDmg - %hungerDmg - %tempDmg;    
  79.    
  80.     if (%amount != 0)
  81.       {
  82.          %player.adjustHealth( %amount );
  83.          $Player::Score = $Player::Score + (1 - (%amount/%totalPossibleDamge));        
  84.       }
  85.     else
  86.       $Player::Score = $Player::Score + 1;
  87.    
  88.    
  89.     $Game::totalScore = $Game::totalScore + 1;
  90.     %gameScore = $Player::Score/$Game::totalScore;
  91.     GameScore.SetValue(%gameScore);
  92.     echo(" ++ gameScore = " @ %gameScore);
  93. }
  94.  
  95. function changeBar(%whichBar, %amount)
  96. {  
  97.    echo(%whichBar @" is being changed by "@ %amount);
  98.    switch$(%whichBar)
  99.     {
  100.         case "HeatBar":
  101.             Heat.SetValue(Heat.GetValue() + %amount);
  102.         case "HungerBar":
  103.             Hunger.SetValue(Hunger.GetValue() + %amount);
  104.         case "ThirstBar":
  105.             Thirst.SetValue(Thirst.GetValue() + %amount);
  106.     }
  107. }