Adonthell 0.4
gamedate.h
Go to the documentation of this file.
00001 /*
00002    $Id: gamedate.h,v 1.4 2002/12/04 17:09:48 ksterker Exp $
00003 
00004    Copyright (C) 2002 Kai Sterker <kaisterker@linuxgames.com>
00005    Part of the Adonthell Project http://adonthell.linuxgames.com
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 /**
00016  * @file gamedate.h
00017  *
00018  * @author Kai Sterker
00019  * @brief Declares the gamedate class.
00020  */
00021 
00022 #ifndef GAMEDATE_H__
00023 #define GAMEDATE_H__
00024 
00025 #include "fileops.h"
00026 
00027 #ifndef SWIG
00028 /**
00029  * The number of hours that make one gameworld day.
00030  */
00031 #define HOURS_PER_DAY 24
00032 
00033 /**
00034  * The number of days that make one gameworld week.
00035  */
00036 #define DAYS_PER_WEEK 7
00037 #endif // SWIG
00038 
00039 /**
00040  * Keeps track of the time the player spent within the game so far. This
00041  * time span is given in %game time minutes, not real time.
00042  * %gamedate further includes functions to retrieve those minutes as day,
00043  * weekday, hour and minute values.
00044  */
00045 class gamedate
00046 {
00047 public:
00048 
00049     /**
00050      * Update the %game date. Whenever a minute of %gametime has 
00051      * passed, a time event will be raised. This function needs to
00052      * be called from the main loop and uses 
00053      */        
00054     static void update ();
00055 
00056     /**
00057      * Get the current %gametime.
00058      * @return %gametime in 1/10 minutes since start of the game.
00059      */
00060     static u_int32 time ()      { return Time; }
00061 
00062     /**
00063      * Get the current weekday.
00064      * @return weekday as a number between 0 and DAYS_PER_WEEK - 1
00065      */
00066     static u_int16 weekday ();
00067     /**
00068      * Returns the current day in the gameworld.
00069      * @return number of days spent in the gameworld, beginning with day 0.
00070      */
00071     static u_int16 day ();
00072     /**
00073      * Return the hour of the current day.
00074      * @return hour of the current day between 0 and HOURS_PER_DAY - 1
00075      */
00076     static u_int16 hour ();
00077     /**
00078      * Return the minute of the current hour.
00079      * @return minute of the current hour between 0 and 59.
00080      */
00081     static u_int16 minute ();
00082 
00083     /**
00084      * convert the time string to gametime minutes. The time string
00085      * has the format "<number>X", where X may be (w)eek, (d)ay,
00086      * (h)our, (m)inute or (t)enth minute. Several such pairs can be
00087      * concatenated.
00088      * Valid examples are "1w1d1h", "30m1h" but also "1h1h".
00089      *
00090      * @param time The time format string.
00091      * @return The time represented by the string in minutes.
00092      */
00093     static u_int32 parse_time (const std::string & time);
00094 
00095     /**
00096      * Load the state of the %gamedate class from disk
00097      * @param in stream to read the state from
00098      * @return <b>true</b> if the state was successfully retrieved,
00099      *      <b>false</b> otherwise.
00100      */
00101     static bool get_state (igzstream &in);
00102     /**
00103      * Save the state of the %gamedate class to disk
00104      * @param out stream to write the state to
00105      */
00106     static void put_state (ogzstream &out);
00107     
00108 private:
00109 #ifndef SWIG
00110     // Time spent in the game in 1/10 gametime minutes
00111     static u_int32 Time;
00112 
00113     // number of game cycles since the last 1/10 gametime minute passed
00114     static double Ticks;
00115 #endif // SWIG
00116 };
00117 
00118 #endif // GAMEDATE_H__