ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/weather.C
Revision: 1.14
Committed: Sat Dec 30 10:16:11 2006 UTC (17 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.13: +16 -3373 lines
Log Message:
preliminary snapshot check-in, DO NOT USE IN PRODUCTION SYSTEMS
See the Changes file for details

File Contents

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