ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/weather.C
Revision: 1.16
Committed: Mon Jan 15 21:06:20 2007 UTC (17 years, 5 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_0
Changes since 1.15: +23 -23 lines
Log Message:
comments

File Contents

# User Rev Content
1 elmex 1.1 /*
2 pippijn 1.16 * 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 elmex 1.1
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 root 1.5 # include <sproto.h>
33 elmex 1.1 #endif
34    
35     extern unsigned long todtick;
36    
37     static const int season_timechange[5][HOURS_PER_DAY] = {
38 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 */
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 elmex 1.1 };
45    
46 root 1.5 void
47 root 1.14 maptile::set_darkness_map ()
48 elmex 1.1 {
49 root 1.5 timeofday_t tod;
50 elmex 1.1
51 root 1.14 if (!outdoor)
52 root 1.5 return;
53 elmex 1.1
54 root 1.5 get_tod (&tod);
55 root 1.14 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 elmex 1.1 }
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 root 1.5 static void
70     dawn_to_dusk (const timeofday_t * tod)
71 elmex 1.1 {
72 root 1.5 /* 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 root 1.14 maptile::change_all_map_light (season_timechange[tod->season][tod->hour]);
79 elmex 1.1 }
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 root 1.5 void
89     tick_the_clock (void)
90 elmex 1.1 {
91 root 1.5 timeofday_t tod;
92    
93     todtick++;
94     if (todtick % 20 == 0)
95     write_todclock ();
96 root 1.13
97 root 1.5 get_tod (&tod);
98     dawn_to_dusk (&tod);
99 elmex 1.1 }