home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / d / d-linux.zip / dm-dist / weather.c < prev   
C/C++ Source or Header  |  1991-03-01  |  4KB  |  218 lines

  1. /* ************************************************************************
  2. *  file: weather.c , Weather and time module              Part of DIKUMUD *
  3. *  Usage: Performing the clock and the weather                            *
  4. *  Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
  5. ************************************************************************* */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. #include "structs.h"
  11. #include "utils.h"
  12. #include "comm.h"
  13. #include "handler.h"
  14. #include "interpreter.h"
  15. #include "db.h"
  16.  
  17. /* uses */
  18.  
  19. extern struct time_info_data time_info;
  20. extern struct weather_data weather_info;
  21.  
  22. /* In this part. */
  23.  
  24. void weather_and_time(int mode);
  25. void another_hour(int mode);
  26. void weather_change(void);
  27.  
  28. /* Here comes the code */
  29.  
  30. void weather_and_time(int mode)
  31. {
  32.     another_hour(mode);
  33.     if(mode)
  34.         weather_change();
  35. }
  36.  
  37.  
  38.  
  39. void another_hour(int mode)
  40. {
  41.     time_info.hours++;
  42.  
  43.     if (mode) {
  44.         switch (time_info.hours) {
  45.             case 5 :
  46.             {
  47.                 weather_info.sunlight = SUN_RISE;
  48.                 send_to_outdoor("The sun rises in the east.\n\r");
  49.                 break;
  50.             }
  51.             case 6 :
  52.             {
  53.                 weather_info.sunlight = SUN_LIGHT;
  54.                 send_to_outdoor("The day has begun.\n\r");
  55.                 break;    
  56.             }
  57.             case 21 :
  58.             {
  59.                 weather_info.sunlight = SUN_SET;
  60.                 send_to_outdoor(
  61.                 "The sun slowly disappears in the west.\n\r");
  62.                 break;
  63.             }
  64.             case 22 :
  65.             {
  66.                 weather_info.sunlight = SUN_DARK;
  67.                 send_to_outdoor("The night has begun.\n\r");
  68.                 break;
  69.             }
  70.             default : break;
  71.         }
  72.     }
  73.  
  74.     if (time_info.hours > 23)  /* Changed by HHS due to bug ???*/
  75.     {
  76.         time_info.hours -= 24;
  77.         time_info.day++;
  78.  
  79.         if (time_info.day>34)
  80.         {
  81.             time_info.day = 0;
  82.             time_info.month++;
  83.  
  84.             if(time_info.month>16)
  85.             {
  86.                 time_info.month = 0;
  87.                 time_info.year++;
  88.             }
  89.         }
  90.     }
  91. }
  92.  
  93. void weather_change(void)
  94. {
  95.     int diff, change;
  96.     if((time_info.month>=9)&&(time_info.month<=16))
  97.         diff=(weather_info.pressure>985 ? -2 : 2);
  98.     else
  99.         diff=(weather_info.pressure>1015? -2 : 2);
  100.  
  101.     weather_info.change += (dice(1,4)*diff+dice(2,6)-dice(2,6));
  102.  
  103.     weather_info.change = MIN(weather_info.change,12);
  104.     weather_info.change = MAX(weather_info.change,-12);
  105.  
  106.     weather_info.pressure += weather_info.change;
  107.  
  108.     weather_info.pressure = MIN(weather_info.pressure,1040);
  109.     weather_info.pressure = MAX(weather_info.pressure,960);
  110.  
  111.     change = 0;
  112.  
  113.     switch(weather_info.sky){
  114.         case SKY_CLOUDLESS :
  115.         {
  116.             if (weather_info.pressure<990)
  117.                 change = 1;
  118.             else if (weather_info.pressure<1010)
  119.                 if(dice(1,4)==1)
  120.                     change = 1;
  121.             break;
  122.         }
  123.         case SKY_CLOUDY :
  124.         {
  125.             if (weather_info.pressure<970)
  126.                 change = 2;
  127.             else if (weather_info.pressure<990)
  128.                 if(dice(1,4)==1)
  129.                     change = 2;
  130.                 else
  131.                     change = 0;
  132.             else if (weather_info.pressure>1030)
  133.                 if(dice(1,4)==1)
  134.                     change = 3;
  135.  
  136.             break;
  137.         }
  138.         case SKY_RAINING :
  139.         {
  140.             if (weather_info.pressure<970)
  141.                 if(dice(1,4)==1)
  142.                     change = 4;
  143.                 else
  144.                     change = 0;
  145.             else if (weather_info.pressure>1030)
  146.                     change = 5;
  147.             else if (weather_info.pressure>1010)
  148.                 if(dice(1,4)==1)
  149.                     change = 5;
  150.  
  151.             break;
  152.         }
  153.         case SKY_LIGHTNING :
  154.         {
  155.             if (weather_info.pressure>1010)
  156.                     change = 6;
  157.             else if (weather_info.pressure>990)
  158.                 if(dice(1,4)==1)
  159.                     change = 6;
  160.  
  161.             break;
  162.         }
  163.         default : 
  164.         {
  165.             change = 0;
  166.             weather_info.sky=SKY_CLOUDLESS;
  167.             break;
  168.         }
  169.     }
  170.  
  171.     switch(change){
  172.         case 0 : break;
  173.         case 1 :
  174.         {
  175.             send_to_outdoor(
  176.             "The sky is getting cloudy.\n\r");
  177.             weather_info.sky=SKY_CLOUDY;
  178.             break;
  179.         }
  180.         case 2 :
  181.         {
  182.             send_to_outdoor(
  183.             "It starts to rain.\n\r");
  184.             weather_info.sky=SKY_RAINING;
  185.             break;
  186.         }
  187.         case 3 :
  188.         {
  189.             send_to_outdoor(
  190.             "The clouds disappear.\n\r");
  191.             weather_info.sky=SKY_CLOUDLESS;
  192.             break;
  193.         }
  194.         case 4 :
  195.         {
  196.             send_to_outdoor(
  197.             "Lightning starts to show in the sky.\n\r");
  198.             weather_info.sky=SKY_LIGHTNING;
  199.             break;
  200.         }
  201.         case 5 :
  202.         {
  203.             send_to_outdoor(
  204.             "The rain stopped.\n\r");
  205.             weather_info.sky=SKY_CLOUDY;
  206.             break;
  207.         }
  208.         case 6 :
  209.         {
  210.             send_to_outdoor(
  211.             "The lightning has stopped.\n\r");
  212.             weather_info.sky=SKY_RAINING;
  213.             break;
  214.         }
  215.         default : break;
  216.     }
  217. }
  218.