Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 * static char *rcsid_weather_c = 00003 * "$Id: weather.c 11578 2009-02-23 22:02:27Z lalo $"; 00004 */ 00005 /* 00006 CrossFire, A Multiplayer game for X-windows 00007 00008 Copyright (C) 2006,2007 Mark Wedel & Crossfire Development Team 00009 Copyright (C) 2002 Tim Rightnour 00010 Copyright (C) 1992 Frank Tore Johansen 00011 00012 This program is free software; you can redistribute it and/or modify 00013 it under the terms of the GNU General Public License as published by 00014 the Free Software Foundation; either version 2 of the License, or 00015 (at your option) any later version. 00016 00017 This program is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 GNU General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License 00023 along with this program; if not, write to the Free Software 00024 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 00026 The authors can be reached via e-mail to crossfire-devel@real-time.com 00027 */ 00028 00034 #include <global.h> 00035 #include <tod.h> 00036 #include <map.h> 00037 #ifndef __CEXTRACT__ 00038 #include <sproto.h> 00039 #endif 00040 #include <assert.h> 00041 00042 extern unsigned long todtick; 00043 00044 static void dawn_to_dusk(const timeofday_t *tod); 00046 static const int season_timechange[5][HOURS_PER_DAY] = { 00047 /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 9 10 11 12 13 */ 00048 { 0, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 }, 00049 { 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0 }, 00050 { 0, 0, 0, 0, 0,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0 }, 00051 { 0, 0, 0, 0, 0,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0 }, 00052 { 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0 } 00053 }; 00054 00061 void set_darkness_map(mapstruct *m) { 00062 int i; 00063 timeofday_t tod; 00064 00065 if (!m->outdoor) { 00066 return; 00067 } 00068 00069 get_tod(&tod); 00070 m->darkness = 0; 00071 for (i = HOURS_PER_DAY/2; i < HOURS_PER_DAY; i++) { 00072 change_map_light(m, season_timechange[tod.season][i]); 00073 } 00074 for (i = 0; i <= tod.hour; i++) { 00075 change_map_light(m, season_timechange[tod.season][i]); 00076 } 00077 } 00078 00085 static void dawn_to_dusk(const timeofday_t *tod) { 00086 mapstruct *m; 00087 00088 /* If the light level isn't changing, no reason to do all 00089 * the work below. 00090 */ 00091 if (season_timechange[tod->season][tod->hour] == 0) { 00092 return; 00093 } 00094 00095 for (m = first_map; m != NULL; m = m->next) { 00096 if (!m->outdoor) { 00097 continue; 00098 } 00099 00100 change_map_light(m, season_timechange[tod->season][tod->hour]); 00101 } 00102 } 00103 00111 void tick_the_clock(void) { 00112 timeofday_t tod; 00113 00114 todtick++; 00115 if (todtick%20 == 0) { 00116 write_todclock(); 00117 } 00118 get_tod(&tod); 00119 dawn_to_dusk(&tod); 00120 } 00121 00132 int similar_direction(int a, int b) { 00133 /* shortcut the obvious */ 00134 if (a == b) 00135 return 1; 00136 00137 switch (a) { 00138 case 1: if (b <= 2 || b == 8) return 1; break; 00139 case 2: if (b > 0 && b < 4) return 1; break; 00140 case 3: if (b > 1 && b < 5) return 1; break; 00141 case 4: if (b > 2 && b < 6) return 1; break; 00142 case 5: if (b > 3 && b < 7) return 1; break; 00143 case 6: if (b > 4 && b < 8) return 1; break; 00144 case 7: if (b > 5) return 1; break; 00145 case 8: if (b > 6 || b == 1) return 1; break; 00146 } 00147 return 0; 00148 }