Debian Codegraph @

server/weather.c

raw symbols SCIP
1 /*
2 * Crossfire -- cooperative multi-player graphical RPG and adventure game
3 *
4 * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5 * Copyright (c) 1992 Frank Tore Johansen
6 *
7 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8 * welcome to redistribute it under certain conditions. For details, please
9 * see COPYING and LICENSE.
10 *
11 * The authors can be reached via e-mail at <[email protected]>.
12 */
13
14 /**
15 * @file
16 * Time-related functions.
17 */
18
19 #include <global.h>
20 #include <tod.h>
21 #include <map.h>
22 #ifndef __CEXTRACT__
23 #include <sproto.h>
24 #endif
25 #include <assert.h>
26
27 extern unsigned long todtick;
28
29 static void dawn_to_dusk(const timeofday_t *tod);
30 /** How to alter darkness, based on time of day and season. */
31 static const int season_timechange[5][HOURS_PER_DAY] = {
32 /* 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 */
33 { 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 },
34 { 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 },
35 { 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 },
36 { 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 },
37 { 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 }
38 };
39
40 /**
41 * Set the darkness level for a map, based on the time of the day.
42 *
43 * @param m
44 * map to alter.
45 */
46 void set_darkness_map(mapstruct *m) {
47 int i;
48 timeofday_t tod;
49
50 if (!m->outdoor) {
51 return;
52 }
53
54 get_tod(&tod);
55 m->darkness = 0;
56 for (i = HOURS_PER_DAY/2; i < HOURS_PER_DAY; i++) {
57 change_map_light(m, season_timechange[tod.season][i]);
58 }
59 for (i = 0; i <= tod.hour; i++) {
60 change_map_light(m, season_timechange[tod.season][i]);
61 }
62 }
63
64 /**
65 * Compute the darkness level for all loaded maps in the game.
66 *
67 * @param tod
68 * time of day to compute darkness for.
69 */
70 static void dawn_to_dusk(const timeofday_t *tod) {
71 mapstruct *m;
72
73 /* If the light level isn't changing, no reason to do all
74 * the work below.
75 */
76 if (season_timechange[tod->season][tod->hour] == 0) {
77 return;
78 }
79
80 for (m = first_map; m != NULL; m = m->next) {
81 if (!m->outdoor) {
82 continue;
83 }
84
85 change_map_light(m, season_timechange[tod->season][tod->hour]);
86 }
87 }
88
89 /**
90 * This performs the basic function of advancing the clock one tick
91 * forward. Every 20 ticks, the clock is saved to disk. It is also
92 * saved on shutdown. Any time dependant functions should be called
93 * from this function, and probably be passed tod as an argument.
94 * Please don't modify tod in the dependant function.
95 */
96 void tick_the_clock(void) {
97 timeofday_t tod;
98
99 todtick++;
100 if (todtick%20 == 0) {
101 write_todclock();
102 }
103 get_tod(&tod);
104 dawn_to_dusk(&tod);
105 }