Crossfire Server, Trunk  1.75.0
weather.cpp
Go to the documentation of this file.
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 <crossfire@metalforge.org>.
12  */
13 
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 #include <string.h>
27 
28 static void dawn_to_dusk(const timeofday_t *tod);
29 
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 
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++) {
58  }
59  for (i = 0; i <= tod.hour; i++) {
61  }
62 }
63 
73  timeofday_t tod;
74  get_tod(&tod); // Get time of day.
75  // Determine the darkness on the world
76  // Since the world map has uniform darkness, just calculate it outright.
77  int darkness = 0;
78  for (int i = 0; i < tod.hour; ++i) {
79  darkness += season_timechange[tod.season][i];
80  }
81  return darkness;
82 }
83 
90 static void dawn_to_dusk(const timeofday_t *tod) {
91  mapstruct *m;
92 
93  /* If the light level isn't changing, no reason to do all
94  * the work below.
95  */
96  if (season_timechange[tod->season][tod->hour] == 0) {
97  return;
98  }
99 
100  for (m = first_map; m != NULL; m = m->next) {
101  if (!m->outdoor) {
102  continue;
103  }
104 
106  }
107 }
108 
116 void tick_the_clock(void) {
117  timeofday_t tod;
118 
119  todtick++;
120  if (todtick%20 == 0) {
121  write_todclock();
122  }
123  get_tod(&tod);
124  dawn_to_dusk(&tod);
125 }
126 
season_timechange
static const int season_timechange[5][HOURS_PER_DAY]
How to alter darkness, based on time of day and season.
Definition: weather.cpp:31
global.h
HOURS_PER_DAY
#define HOURS_PER_DAY
Definition: tod.h:15
timeofday_t
Represents the ingame time.
Definition: tod.h:38
tick_the_clock
void tick_the_clock(void)
This performs the basic function of advancing the clock one tick forward.
Definition: weather.cpp:116
get_tod
void get_tod(timeofday_t *tod)
Computes the ingame time of the day.
Definition: time.cpp:219
m
static event_registration m
Definition: citylife.cpp:424
write_todclock
void write_todclock(void)
Write out the current time to the file so time does not reset every time the server reboots.
Definition: init.cpp:508
first_map
mapstruct * first_map
First map.
Definition: init.cpp:107
change_map_light
int change_map_light(mapstruct *m, int change)
Used to change map light level (darkness) up or down.
Definition: map.cpp:2027
todtick
unsigned long todtick
Game world time, in in-game hours.
Definition: time.cpp:38
get_world_darkness
int get_world_darkness()
Get the darkness of the world map at this point.
Definition: weather.cpp:72
sproto.h
timeofday_t::season
int season
Definition: tod.h:46
map.h
set_darkness_map
void set_darkness_map(mapstruct *m)
Set the darkness level for a map, based on the time of the day.
Definition: weather.cpp:46
mapstruct
This is a game-map.
Definition: map.h:320
timeofday_t::hour
int hour
Definition: tod.h:43
tod.h
dawn_to_dusk
static void dawn_to_dusk(const timeofday_t *tod)
Compute the darkness level for all loaded maps in the game.
Definition: weather.cpp:90