ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/weather.C
Revision: 1.15
Committed: Sat Jan 6 14:42:31 2007 UTC (17 years, 5 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.14: +1 -0 lines
Log Message:
added some copyrights

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 extern unsigned long todtick;
36
37 static const int season_timechange[5][HOURS_PER_DAY] = {
38 /* 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 */
39 { 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},
40 { 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},
41 { 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},
42 { 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},
43 { 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}
44 };
45
46 void
47 maptile::set_darkness_map ()
48 {
49 timeofday_t tod;
50
51 if (!outdoor)
52 return;
53
54 get_tod (&tod);
55 darkness = 0;
56
57 for (int i = HOURS_PER_DAY / 2; i < HOURS_PER_DAY; i++)
58 change_map_light (season_timechange[tod.season][i]);
59
60 for (int i = 0; i <= tod.hour; i++)
61 change_map_light (season_timechange[tod.season][i]);
62 }
63
64 /*
65 * Compute the darkness level for all maps in the game. Requires the
66 * time of day as an argument.
67 */
68
69 static void
70 dawn_to_dusk (const timeofday_t * tod)
71 {
72 /* If the light level isn't changing, no reason to do all
73 * the work below.
74 */
75 if (season_timechange[tod->season][tod->hour] == 0)
76 return;
77
78 maptile::change_all_map_light (season_timechange[tod->season][tod->hour]);
79 }
80
81 /*
82 * This performs the basic function of advancing the clock one tick
83 * forward. Every 20 ticks, the clock is saved to disk. It is also
84 * saved on shutdown. Any time dependant functions should be called
85 * from this function, and probably be passed tod as an argument.
86 * Please don't modify tod in the dependant function.
87 */
88 void
89 tick_the_clock (void)
90 {
91 timeofday_t tod;
92
93 todtick++;
94 if (todtick % 20 == 0)
95 write_todclock ();
96
97 get_tod (&tod);
98 dawn_to_dusk (&tod);
99 }