gameclk.h

Go to the documentation of this file.
00001 /*
00002  *  gameclk.h - Keep track of time.
00003  *
00004  *  Copyright (C) 2000-2001  The Exult Team
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #ifndef GAMECLK_H
00022 #define GAMECLK_H 1
00023 
00024 #include "tqueue.h"
00025 
00026 /*
00027  *  Time passes 15 times faster in game than in real-life, so
00028  *  1 real minute = 15 game minutes.
00029  */
00030 const int time_factor = 15;
00031 
00032 /*
00033  *  Keep track of time, and of the palette for a given time.
00034  */
00035 class Game_clock : public Time_sensitive
00036   {
00037   Time_queue *tqueue;   // The time queue.
00038   short hour, minute;   // Time (0-23, 0-59).
00039   int day;      // Keep track of days played.
00040   int light_source_level;   // Last set light source level.
00041   unsigned int dungeon;   // Last set 'in_dungeon' value.
00042   int storm;      // >0 if storm in progress.
00043   unsigned short time_rate;
00044   void set_time_palette();
00045   void set_light_source_level(int lev);
00046   void check_hunger();
00047 public:
00048   Game_clock(Time_queue *tq) : tqueue(tq), hour(6), minute(0), day(0),
00049       light_source_level(0), dungeon(255),
00050       storm(0), time_rate(1)
00051     { }
00052   int get_hour()
00053     { return hour; }
00054   void set_hour(int h)
00055     { hour = h; }
00056   int get_minute()
00057     { return minute; }
00058   void set_minute(int m)
00059     { minute = m; }
00060   int get_day()
00061     { return day; }
00062   void set_day(int d)
00063     { day = d; }
00064   unsigned long get_total_hours() // Get total # hours.
00065     { return day*24 + hour; }
00066   unsigned long get_total_minutes()
00067     { return get_total_hours()*60 + minute; }
00068   void set_palette();   // Set palette for current hour.
00069           // Set light source.  MUST be fast,
00070           //   since it's called during paint().
00071   void set_light_source(int lev, int dun)
00072     {
00073     if (lev != light_source_level || dun != dungeon)
00074       set_light_source_level(lev);
00075     }
00076   void set_storm(bool onoff); // Start/end storm.
00077   void increment(int num_minutes);// Increment clock.
00078   virtual void handle_event(unsigned long curtime, long udata);
00079   void fake_next_period();  // For debugging.
00080   int get_time_rate() { return time_rate; }
00081   void set_time_rate(int i) { time_rate=i>0?i:1; }
00082   };
00083 
00084 #endif  /* INCL_GAMECLK */

Generated on Mon Jul 9 14:42:45 2007 for ExultEngine by  doxygen 1.5.1