/* CrossFire, A Multiplayer game for X-windows Copyright (C) 2002 Tim Rightnour Copyright (C) 2002 Mark Wedel & Crossfire Development Team Copyright (C) 1992 Frank Tore Johansen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. The authors can be reached via e-mail to */ /* This weather system was written for crossfire by Tim Rightnour */ #include #include #include #ifndef __CEXTRACT__ # include #endif extern unsigned long todtick; static const int season_timechange[5][HOURS_PER_DAY] = { /* 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 */ { 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}, { 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}, { 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}, { 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}, { 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} }; void maptile::set_darkness_map () { timeofday_t tod; if (!outdoor) return; get_tod (&tod); darkness = 0; for (int i = HOURS_PER_DAY / 2; i < HOURS_PER_DAY; i++) change_map_light (season_timechange[tod.season][i]); for (int i = 0; i <= tod.hour; i++) change_map_light (season_timechange[tod.season][i]); } /* * Compute the darkness level for all maps in the game. Requires the * time of day as an argument. */ static void dawn_to_dusk (const timeofday_t * tod) { /* If the light level isn't changing, no reason to do all * the work below. */ if (season_timechange[tod->season][tod->hour] == 0) return; maptile::change_all_map_light (season_timechange[tod->season][tod->hour]); } /* * This performs the basic function of advancing the clock one tick * forward. Every 20 ticks, the clock is saved to disk. It is also * saved on shutdown. Any time dependant functions should be called * from this function, and probably be passed tod as an argument. * Please don't modify tod in the dependant function. */ void tick_the_clock (void) { timeofday_t tod; todtick++; if (todtick % 20 == 0) write_todclock (); get_tod (&tod); dawn_to_dusk (&tod); }