ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/weather.C
Revision: 1.17
Committed: Sat Mar 17 22:11:23 2007 UTC (17 years, 3 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_1
Changes since 1.16: +2 -14 lines
Log Message:
remove clockdata and base it off of the runtime; improve the tod code.

File Contents

# Content
1 /*
2 * CrossFire, A Multiplayer game for X-windows
3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copyright (C) 2002 Tim Rightnour
6 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
7 * Copyright (C) 1992 Frank Tore Johansen
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 * The authors can be reached via e-mail to <crossfire@schmorp.de>
24 */
25
26 /* This weather system was written for crossfire by Tim Rightnour */
27
28 #include <global.h>
29 #include <tod.h>
30 #include <map.h>
31 #ifndef __CEXTRACT__
32 # include <sproto.h>
33 #endif
34
35 static const int season_timechange[5][HOURS_PER_DAY] = {
36 /* 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 */
37 { 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},
38 { 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},
39 { 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},
40 { 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},
41 { 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}
42 };
43
44 void
45 maptile::set_darkness_map ()
46 {
47 timeofday_t tod;
48
49 if (!outdoor)
50 return;
51
52 get_tod (&tod);
53 darkness = 0;
54
55 for (int i = HOURS_PER_DAY / 2; i < HOURS_PER_DAY; i++)
56 change_map_light (season_timechange[tod.season][i]);
57
58 for (int i = 0; i <= tod.hour; i++)
59 change_map_light (season_timechange[tod.season][i]);
60 }
61
62 /*
63 * Compute the darkness level for all maps in the game. Requires the
64 * time of day as an argument.
65 */
66
67 static void
68 dawn_to_dusk (const timeofday_t * tod)
69 {
70 /* If the light level isn't changing, no reason to do all
71 * the work below.
72 */
73 if (season_timechange[tod->season][tod->hour] == 0)
74 return;
75
76 maptile::change_all_map_light (season_timechange[tod->season][tod->hour]);
77 }
78
79 void
80 adjust_daylight ()
81 {
82 timeofday_t tod;
83
84 get_tod (&tod);
85 dawn_to_dusk (&tod);
86 }
87