Crossfire Server, Trunk  R20513
weather.c
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 
27 extern unsigned long todtick;
28 
29 static void dawn_to_dusk(const timeofday_t *tod);
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 
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 
86  }
87 }
88 
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 }
void set_darkness_map(mapstruct *m)
Set the darkness level for a map, based on the time of the day.
Definition: weather.c:46
Defines for the ingame clock, ticks management and weather system.
static const int season_timechange[5][HOURS_PER_DAY]
How to alter darkness, based on time of day and season.
Definition: weather.c:31
unsigned long todtick
Ingame time.
Definition: init.c:440
Global type definitions and header inclusions.
int change_map_light(mapstruct *m, int change)
Used to change map light level (darkness) up or down.
Definition: map.c:1995
void write_todclock(void)
Write out the current time to the file so time does not reset every time the server reboots...
Definition: init.c:446
uint8_t darkness
Indicates level of darkness of map.
Definition: map.h:346
static void dawn_to_dusk(const timeofday_t *tod)
Compute the darkness level for all loaded maps in the game.
Definition: weather.c:70
void tick_the_clock(void)
This performs the basic function of advancing the clock one tick forward.
Definition: weather.c:96
uint32_t outdoor
True if an outdoor map.
Definition: map.h:340
void get_tod(timeofday_t *tod)
Computes the ingame time of the day.
Definition: time.c:215
#define HOURS_PER_DAY
Definition: tod.h:12
Represents the ingame time.
Definition: tod.h:32
This file contains basic map-related structures and macros.
int hour
Definition: tod.h:37
struct mapdef * next
Next map, linked list.
Definition: map.h:326
This is a game-map.
Definition: map.h:325
EXTERN mapstruct * first_map
First map.
Definition: global.h:118
int season
Definition: tod.h:40