/ circle3.1 / src / weather.c
weather.c
  1  /* ************************************************************************
  2  *   File: weather.c                                     Part of CircleMUD *
  3  *  Usage: functions handling time and the weather                         *
  4  *                                                                         *
  5  *  All rights reserved.  See license.doc for complete information.        *
  6  *                                                                         *
  7  *  Copyright (C) 1993, 94 by the Trustees of the Johns Hopkins University *
  8  *  CircleMUD is based on DikuMUD, Copyright (C) 1990, 1991.               *
  9  ************************************************************************ */
 10  
 11  #include "conf.h"
 12  #include "sysdep.h"
 13  
 14  
 15  #include "structs.h"
 16  #include "utils.h"
 17  #include "comm.h"
 18  #include "handler.h"
 19  #include "interpreter.h"
 20  #include "db.h"
 21  
 22  extern struct time_info_data time_info;
 23  
 24  void weather_and_time(int mode);
 25  void another_hour(int mode);
 26  void weather_change(void);
 27  
 28  
 29  void weather_and_time(int mode)
 30  {
 31    another_hour(mode);
 32    if (mode)
 33      weather_change();
 34  }
 35  
 36  
 37  void another_hour(int mode)
 38  {
 39    time_info.hours++;
 40  
 41    if (mode) {
 42      switch (time_info.hours) {
 43      case 5:
 44        weather_info.sunlight = SUN_RISE;
 45        send_to_outdoor("The sun rises in the east.\r\n");
 46        break;
 47      case 6:
 48        weather_info.sunlight = SUN_LIGHT;
 49        send_to_outdoor("The day has begun.\r\n");
 50        break;
 51      case 21:
 52        weather_info.sunlight = SUN_SET;
 53        send_to_outdoor("The sun slowly disappears in the west.\r\n");
 54        break;
 55      case 22:
 56        weather_info.sunlight = SUN_DARK;
 57        send_to_outdoor("The night has begun.\r\n");
 58        break;
 59      default:
 60        break;
 61      }
 62    }
 63    if (time_info.hours > 23) {	/* Changed by HHS due to bug ??? */
 64      time_info.hours -= 24;
 65      time_info.day++;
 66  
 67      if (time_info.day > 34) {
 68        time_info.day = 0;
 69        time_info.month++;
 70  
 71        if (time_info.month > 16) {
 72  	time_info.month = 0;
 73  	time_info.year++;
 74        }
 75      }
 76    }
 77  }
 78  
 79  
 80  void weather_change(void)
 81  {
 82    int diff, change;
 83    if ((time_info.month >= 9) && (time_info.month <= 16))
 84      diff = (weather_info.pressure > 985 ? -2 : 2);
 85    else
 86      diff = (weather_info.pressure > 1015 ? -2 : 2);
 87  
 88    weather_info.change += (dice(1, 4) * diff + dice(2, 6) - dice(2, 6));
 89  
 90    weather_info.change = MIN(weather_info.change, 12);
 91    weather_info.change = MAX(weather_info.change, -12);
 92  
 93    weather_info.pressure += weather_info.change;
 94  
 95    weather_info.pressure = MIN(weather_info.pressure, 1040);
 96    weather_info.pressure = MAX(weather_info.pressure, 960);
 97  
 98    change = 0;
 99  
100    switch (weather_info.sky) {
101    case SKY_CLOUDLESS:
102      if (weather_info.pressure < 990)
103        change = 1;
104      else if (weather_info.pressure < 1010)
105        if (dice(1, 4) == 1)
106  	change = 1;
107      break;
108    case SKY_CLOUDY:
109      if (weather_info.pressure < 970)
110        change = 2;
111      else if (weather_info.pressure < 990) {
112        if (dice(1, 4) == 1)
113  	change = 2;
114        else
115  	change = 0;
116      } else if (weather_info.pressure > 1030)
117        if (dice(1, 4) == 1)
118  	change = 3;
119  
120      break;
121    case SKY_RAINING:
122      if (weather_info.pressure < 970) {
123        if (dice(1, 4) == 1)
124  	change = 4;
125        else
126  	change = 0;
127      } else if (weather_info.pressure > 1030)
128        change = 5;
129      else if (weather_info.pressure > 1010)
130        if (dice(1, 4) == 1)
131  	change = 5;
132  
133      break;
134    case SKY_LIGHTNING:
135      if (weather_info.pressure > 1010)
136        change = 6;
137      else if (weather_info.pressure > 990)
138        if (dice(1, 4) == 1)
139  	change = 6;
140  
141      break;
142    default:
143      change = 0;
144      weather_info.sky = SKY_CLOUDLESS;
145      break;
146    }
147  
148    switch (change) {
149    case 0:
150      break;
151    case 1:
152      send_to_outdoor("The sky starts to get cloudy.\r\n");
153      weather_info.sky = SKY_CLOUDY;
154      break;
155    case 2:
156      send_to_outdoor("It starts to rain.\r\n");
157      weather_info.sky = SKY_RAINING;
158      break;
159    case 3:
160      send_to_outdoor("The clouds disappear.\r\n");
161      weather_info.sky = SKY_CLOUDLESS;
162      break;
163    case 4:
164      send_to_outdoor("Lightning starts to show in the sky.\r\n");
165      weather_info.sky = SKY_LIGHTNING;
166      break;
167    case 5:
168      send_to_outdoor("The rain stops.\r\n");
169      weather_info.sky = SKY_CLOUDY;
170      break;
171    case 6:
172      send_to_outdoor("The lightning stops.\r\n");
173      weather_info.sky = SKY_RAINING;
174      break;
175    default:
176      break;
177    }
178  }