00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00034 #include <global.h>
00035 #include <tod.h>
00036 #include <map.h>
00037 #ifndef __CEXTRACT__
00038 #include <sproto.h>
00039 #endif
00040 #include <assert.h>
00041
00042 extern unsigned long todtick;
00043
00044 static void dawn_to_dusk(const timeofday_t *tod);
00046 static const int season_timechange[5][HOURS_PER_DAY] = {
00047
00048 { 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 },
00049 { 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 },
00050 { 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 },
00051 { 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 },
00052 { 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 }
00053 };
00054
00061 void set_darkness_map(mapstruct *m) {
00062 int i;
00063 timeofday_t tod;
00064
00065 if (!m->outdoor) {
00066 return;
00067 }
00068
00069 get_tod(&tod);
00070 m->darkness = 0;
00071 for (i = HOURS_PER_DAY/2; i < HOURS_PER_DAY; i++) {
00072 change_map_light(m, season_timechange[tod.season][i]);
00073 }
00074 for (i = 0; i <= tod.hour; i++) {
00075 change_map_light(m, season_timechange[tod.season][i]);
00076 }
00077 }
00078
00085 static void dawn_to_dusk(const timeofday_t *tod) {
00086 mapstruct *m;
00087
00088
00089
00090
00091 if (season_timechange[tod->season][tod->hour] == 0) {
00092 return;
00093 }
00094
00095 for (m = first_map; m != NULL; m = m->next) {
00096 if (!m->outdoor) {
00097 continue;
00098 }
00099
00100 change_map_light(m, season_timechange[tod->season][tod->hour]);
00101 }
00102 }
00103
00111 void tick_the_clock(void) {
00112 timeofday_t tod;
00113
00114 todtick++;
00115 if (todtick%20 == 0) {
00116 write_todclock();
00117 }
00118 get_tod(&tod);
00119 dawn_to_dusk(&tod);
00120 }
00121
00132 int similar_direction(int a, int b) {
00133
00134 if (a == b)
00135 return 1;
00136
00137 switch (a) {
00138 case 1: if (b <= 2 || b == 8) return 1; break;
00139 case 2: if (b > 0 && b < 4) return 1; break;
00140 case 3: if (b > 1 && b < 5) return 1; break;
00141 case 4: if (b > 2 && b < 6) return 1; break;
00142 case 5: if (b > 3 && b < 7) return 1; break;
00143 case 6: if (b > 4 && b < 8) return 1; break;
00144 case 7: if (b > 5) return 1; break;
00145 case 8: if (b > 6 || b == 1) return 1; break;
00146 }
00147 return 0;
00148 }