1. // Global values
  2. // values per meal or drink
  3. // Hourly
  4. $DRINK = 0.01389;    // 1 / (3 * 24); // 72 hours , 3 days
  5. $MEAL  = 0.00595;    // 1 / (7 * 24); // 168 hours , 7 days
  6. $WARMTH= 0.033;       // 1 / (3);   // 3 hours ? was 0.33
  7. // Per Minute
  8. $THIRST = 0.000231;  //$DRINK / 60;
  9. $HUNGER = 0.000099;  //$MEAL / 60;
  10. $HEAT   = $WARMTH / 60; // 0.005556;
  11. // hard coded to reduce the floating point sizes
  12.  
  13. // default values used to determine Heat based off of time
  14. $SUNRISE = 0.05;
  15. $MIDDAY = 0.25;
  16. $SUNSET = 0.48;
  17.  
  18. $MSG_DELAY = 5;// default 5s
  19. $MSG_SIZE = 1; // default 1
  20.  
  21. // globals to keep track of scheduled tasks
  22. //$tempCheckId = 0;
  23. //$thirstCheckId = 0;
  24. //$hungerCheckId = 0;
  25. function statusHunger( %value )
  26. {
  27.    %msg = "";
  28.    %value = %value * 100; // precentage
  29.     // determine the current state    
  30.     if ( %value < 20)
  31.     {
  32.        %Status = 0; //
  33.        %msg = "";      
  34.     }    
  35.     else if ( %value <= 40 )
  36.     {
  37.        %Status = 1; //
  38.        %msg = "hunger pains";
  39.     }
  40.     else if ( %value <= 60)
  41.     {
  42.        %Status = 2; //
  43.        %msg = "severe hunger";      
  44.     }
  45.     else if ( %value <= 80)
  46.     {
  47.        %Status = 3; //
  48.        %msg = "extreme hunger";      
  49.     }    
  50.     else // greater than 80
  51.     {
  52.        %Status = 4; //
  53.        %msg = "starvation";      
  54.     }    
  55.    
  56.     return %msg;
  57. }
  58.  
  59. function hungerCheck()
  60. {
  61.    
  62.  
  63.     // give player some feedback    
  64.     %oldStatus = statusHunger(Hunger.GetValue()); // ok, dehydrated, severe dehydration, extreme dehydration.
  65.    
  66.     // you are feeling hungry
  67.     changeBar("HungerBar", $MEAL * $Game::speed);
  68.    
  69.     %newStatus = statusHunger(Hunger.GetValue()); // ok, dehydrated, severe dehydration, extreme dehydration.
  70.    
  71.     echo("Hunger " SPC %oldStatus SPC %newStatus );
  72.     if (%oldStatus !$= %newStatus)
  73.        clientCmdBottomPrint("You are suffering from " @ %newStatus,$MSG_DELAY,$MSG_SIZE);    
  74.  
  75.     // wait 60 second RT ~ 1 HOUR in GT
  76.     $hungerCheckId = schedule(60000,0,"hungerCheck");  // 1000 = 1 sec RT = 1 min game time
  77.     echo("+ + hungerCheckId = "@ $hungerCheckId @ " + + ");    
  78. }
  79.  
  80. function statusThirst( %value )
  81. {
  82.    %msg = "";
  83.    %value = %value * 100;// precentage
  84.     // determine the current state    
  85.     if ( %value < 25)
  86.     {
  87.        %Status = 0; //
  88.        %msg = "";      
  89.     }    
  90.     else if (  %value <= 50)
  91.     {
  92.        %Status = 1; //
  93.        %msg = "minor dehydration";      
  94.     }
  95.     else if ( %value <= 75)
  96.     {
  97.        %Status = 1; //
  98.        %msg = "severe dehydration";      
  99.     }
  100.     else // greater than 75
  101.     {
  102.        %Status = 1; //
  103.        %msg = "extreme dehydration";      
  104.     }    
  105.    
  106.     return %msg;
  107. }
  108.  
  109. function thirstCheck()
  110. {
  111.     // you are feeling thirsty
  112.     // since we check every 5 minutes
  113.     // need to multiply the per minute value
  114.     %dmg = 5 * $THIRST * $Game::speed;
  115.     %orig = %dmg;
  116.     if (Heat.GetValue() >= 0.70)
  117.     {
  118.        // increase thirst factor by 25% due to increased heat & water loss
  119.        %mult = 1 - Heat.GetValue() ; // 0 to 5
  120.        %mult = 10 * (0.5 - %mult); // reverse it ... .3 = x2, 0 = x5
  121.        %dmg = %dmg * %mult; // 1.5 to 5 x
  122.        
  123.        %message = "Your body is loosing more water than usual due to the excessive heat (x" @ %mult @ ")" ;      
  124.        clientCmdCenterPrint(%message,3,1);
  125.     }    
  126.    
  127.     // give player some feedback    
  128.     %oldStatus = statusThirst(Thirst.GetValue()); // ok, dehydrated, severe dehydration, extreme dehydration.
  129.    
  130.     changeBar("ThirstBar", %dmg);  
  131.    
  132.     %newStatus = statusThirst(Thirst.GetValue()); // ok, dehydrated, severe dehydration, extreme dehydration.
  133.    
  134.     echo("thirst " SPC %oldStatus SPC %newStatus );    
  135.     if (%oldStatus !$= %newStatus)
  136.        clientCmdBottomPrint("You are suffering from " @ %newStatus,$MSG_DELAY,$MSG_SIZE);  
  137.  
  138.  
  139.     // wait 5 second RT ~ 5 minute GT
  140.     $thirstCheckId = schedule(5000,0,"thirstCheck");  // 1000 = 1 sec RT = 1 min game time
  141.     echo("+ + thirstCheckId = "@ $thirstCheckId @ " + + ");
  142. }
  143.  
  144. function statusHeat( %value )
  145. {
  146.    %msg = "";
  147.    %value = %value * 100;// precentage
  148.     // determine the current state    
  149.     if ( %value < 25)
  150.     {
  151.        %Status = 0; //
  152.        %msg = "freezing cold ... possibly frostbite";      
  153.     }    
  154.     else if ( %value <= 40 )
  155.     {
  156.        %Status = 1; //
  157.        %msg = "cold";      
  158.     }
  159.     else if ( %value <= 60 )
  160.     {
  161.        %Status = 2; //  ok
  162.        %msg = "";      
  163.     }    
  164.     else if ( %value <= 80)
  165.     {
  166.        %Status = 3; //
  167.        %msg = "heat";
  168.     }
  169.     else // greater than 75
  170.     {
  171.        %Status = 4; //
  172.        %msg = "heat exhaustion";      
  173.     }    
  174.    
  175.     return %msg;
  176. }
  177.  
  178. function heatCheck()
  179. {
  180.     // day time,  gain heat
  181.     if ((DayNightCycle.time > $SUNRISE) && (DayNightCycle.time < $SUNSET))
  182.     {
  183.         echo("survivalCheck() : is Daytime");
  184.         %heatFactor = $HEAT;
  185.         if ((DayNightCycle.time > ($MIDDAY - 0.10)) && (DayNightCycle.time < ($MIDDAY + 0.10)))
  186.         {
  187.            echo("survivalCheck() : and it is Mid-Day (hottest part of day)");          
  188.            %heatFactor = $HEAT*2;
  189.            // hottest part of the day
  190.         }
  191.     }    
  192.     else
  193.     {
  194.        echo("survivalCheck() : is Night");
  195.        // night time - loose heat
  196.         %heatFactor = - $HEAT;
  197.     }
  198.  
  199.     // give player some feedback    
  200.     %oldStatus = statusHeat(Heat.GetValue()); // ok, dehydrated, severe dehydration, extreme dehydration.
  201.        
  202.     changeBar("HeatBar", %heatFactor * $Game::speed);
  203.    
  204.     %newStatus = statusHeat(Heat.GetValue()); // ok, dehydrated, severe dehydration, extreme dehydration.
  205.    
  206.     echo("Heat " SPC Heat.GetValue() SPC $oldStatus @ " -> " @ %newStatus );      
  207.     if (%oldStatus !$= %newStatus)
  208.        clientCmdBottomPrint("You are suffering from " @ %newStatus,  $MSG_DELAY,$MSG_SIZE);  
  209.            
  210.    
  211.     // wait 1 second RT ~ 1 minute GT
  212.     $tempCheckId = schedule(1000,0,"heatCheck");  // 1000 = 1 sec RT = 1 min game time
  213.     echo("+ + tempCheckId = "@ $tempCheckId @ " + + ");
  214. }
  215.  
  216.  
  217. function survivalCheck()
  218. {    
  219.    // cancel any scheduled checks
  220.    if (IsEventPending($tempCheckId))
  221.       cancel($tempCheckId);
  222.    if (IsEventPending($thirstCheckId))
  223.       cancel($thirstCheckId);
  224.    if (IsEventPending($hungerCheckId))
  225.       cancel($hungerCheckId);
  226.    
  227.    // only called once
  228.    // then respawn at thier own intervals
  229.    hungerCheck();
  230.    thirstCheck();
  231.    heatCheck();
  232. }
  233.  
  234.     //determine hourLength
  235. function logTimeofDay()
  236. {
  237.     echo("+ + logTimeofDay + + id("@$timeLogId@")");
  238.      
  239.     %minutes = RoundDown(DayNightCycle.time * 1440);
  240.     %time_hr = RoundDown(%minutes / 60);    
  241.     %time_mn = %minutes % 60; // remainder after division
  242.     echo("GMT time is "@ %time_hr @ ":" @ %time_mn);
  243.    
  244.     lblTime.setValue(%time_hr @ ":" @ %time_mn);
  245.    
  246.     echo("Time of Day="@DayNightCycle.time);
  247.     $timeLogId = schedule(1000,0,"logTimeofDay");
  248. }