| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 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 |
|
| 31 |
static const int season_timechange[5][HOURS_PER_DAY] = { |
| 32 |
|
| 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 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 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 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
static void dawn_to_dusk(const timeofday_t *tod) { |
| 71 |
mapstruct *m; |
| 72 |
|
| 73 |
|
| 74 |
|
| 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 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 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 |
} |