Crossfire Server, Branches 1.12  R18729
weather.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_weather_c =
3  * "$Id: weather.c 11578 2009-02-23 22:02:27Z lalo $";
4  */
5 /*
6  CrossFire, A Multiplayer game for X-windows
7 
8  Copyright (C) 2006,2007 Mark Wedel & Crossfire Development Team
9  Copyright (C) 2002 Tim Rightnour
10  Copyright (C) 1992 Frank Tore Johansen
11 
12  This program is free software; you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) any later version.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 
26  The authors can be reached via e-mail to crossfire-devel@real-time.com
27 */
28 
34 #include <global.h>
35 #include <tod.h>
36 #include <map.h>
37 #ifndef __CEXTRACT__
38 #include <sproto.h>
39 #endif
40 #include <assert.h>
41 
42 extern unsigned long todtick;
43 
44 static void dawn_to_dusk(const timeofday_t *tod);
46 static const int season_timechange[5][HOURS_PER_DAY] = {
47 /* 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 */
48  { 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 },
49  { 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 },
50  { 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 },
51  { 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 },
52  { 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 }
53 };
54 
62  int i;
63  timeofday_t tod;
64 
65  if (!m->outdoor) {
66  return;
67  }
68 
69  get_tod(&tod);
70  m->darkness = 0;
71  for (i = HOURS_PER_DAY/2; i < HOURS_PER_DAY; i++) {
73  }
74  for (i = 0; i <= tod.hour; i++) {
76  }
77 }
78 
85 static void dawn_to_dusk(const timeofday_t *tod) {
86  mapstruct *m;
87 
88  /* If the light level isn't changing, no reason to do all
89  * the work below.
90  */
91  if (season_timechange[tod->season][tod->hour] == 0) {
92  return;
93  }
94 
95  for (m = first_map; m != NULL; m = m->next) {
96  if (!m->outdoor) {
97  continue;
98  }
99 
101  }
102 }
103 
111 void tick_the_clock(void) {
112  timeofday_t tod;
113 
114  todtick++;
115  if (todtick%20 == 0) {
116  write_todclock();
117  }
118  get_tod(&tod);
119  dawn_to_dusk(&tod);
120 }
121 
132 int similar_direction(int a, int b) {
133  /* shortcut the obvious */
134  if (a == b)
135  return 1;
136 
137  switch (a) {
138  case 1: if (b <= 2 || b == 8) return 1; break;
139  case 2: if (b > 0 && b < 4) return 1; break;
140  case 3: if (b > 1 && b < 5) return 1; break;
141  case 4: if (b > 2 && b < 6) return 1; break;
142  case 5: if (b > 3 && b < 7) return 1; break;
143  case 6: if (b > 4 && b < 8) return 1; break;
144  case 7: if (b > 5) return 1; break;
145  case 8: if (b > 6 || b == 1) return 1; break;
146  }
147  return 0;
148 }
void set_darkness_map(mapstruct *m)
Definition: weather.c:61
static const int season_timechange[5][HOURS_PER_DAY]
Definition: weather.c:46
unsigned long todtick
Definition: init.c:418
int change_map_light(mapstruct *m, int change)
Definition: map.c:2000
void write_todclock(void)
Definition: init.c:424
static void dawn_to_dusk(const timeofday_t *tod)
Definition: weather.c:85
void tick_the_clock(void)
Definition: weather.c:111
uint8 darkness
Definition: map.h:369
void get_tod(timeofday_t *tod)
Definition: time.c:268
#define HOURS_PER_DAY
Definition: tod.h:41
Definition: tod.h:61
int hour
Definition: tod.h:66
int similar_direction(int a, int b)
Definition: weather.c:132
struct mapdef * next
Definition: map.h:347
Definition: map.h:346
uint32 outdoor
Definition: map.h:361
EXTERN mapstruct * first_map
Definition: global.h:191
int season
Definition: tod.h:69