Adonthell  0.4
gamedate.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002 Kai Sterker <kai.sterker@gmail.com>
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  Adonthell is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 /**
20  * @file gamedate.h
21  *
22  * @author Kai Sterker
23  * @brief Declares the gamedate class.
24  */
25 
26 #ifndef GAMEDATE_H__
27 #define GAMEDATE_H__
28 
29 #include "fileops.h"
30 
31 #ifndef SWIG
32 /**
33  * The number of hours that make one gameworld day.
34  */
35 #define HOURS_PER_DAY 24
36 
37 /**
38  * The number of days that make one gameworld week.
39  */
40 #define DAYS_PER_WEEK 7
41 #endif // SWIG
42 
43 /**
44  * Keeps track of the time the player spent within the game so far. This
45  * time span is given in %game time minutes, not real time.
46  * %gamedate further includes functions to retrieve those minutes as day,
47  * weekday, hour and minute values.
48  */
49 class gamedate
50 {
51 public:
52 
53  /**
54  * Update the %game date. Whenever a minute of %gametime has
55  * passed, a time event will be raised. This function needs to
56  * be called from the main loop and uses
57  */
58  static void update ();
59 
60  /**
61  * Get the current %gametime.
62  * @return %gametime in 1/10 minutes since start of the game.
63  */
64  static u_int32 time () { return Time; }
65 
66  /**
67  * Get the current weekday.
68  * @return weekday as a number between 0 and DAYS_PER_WEEK - 1
69  */
70  static u_int16 weekday ();
71  /**
72  * Returns the current day in the gameworld.
73  * @return number of days spent in the gameworld, beginning with day 0.
74  */
75  static u_int16 day ();
76  /**
77  * Return the hour of the current day.
78  * @return hour of the current day between 0 and HOURS_PER_DAY - 1
79  */
80  static u_int16 hour ();
81  /**
82  * Return the minute of the current hour.
83  * @return minute of the current hour between 0 and 59.
84  */
85  static u_int16 minute ();
86 
87  /**
88  * convert the time string to gametime minutes. The time string
89  * has the format "<number>X", where X may be (w)eek, (d)ay,
90  * (h)our, (m)inute or (t)enth minute. Several such pairs can be
91  * concatenated.
92  * Valid examples are "1w1d1h", "30m1h" but also "1h1h".
93  *
94  * @param time The time format string.
95  * @return The time represented by the string in minutes.
96  */
97  static u_int32 parse_time (const std::string & time);
98 
99  /**
100  * Load the state of the %gamedate class from disk
101  * @param in stream to read the state from
102  * @return <b>true</b> if the state was successfully retrieved,
103  * <b>false</b> otherwise.
104  */
105  static bool get_state (igzstream &in);
106  /**
107  * Save the state of the %gamedate class to disk
108  * @param out stream to write the state to
109  */
110  static void put_state (ogzstream &out);
111 
112 private:
113 #ifndef SWIG
114  // Time spent in the game in 1/10 gametime minutes
115  static u_int32 Time;
116 
117  // number of game cycles since the last 1/10 gametime minute passed
118  static double Ticks;
119 #endif // SWIG
120 };
121 
122 #endif // GAMEDATE_H__
static bool get_state(igzstream &in)
Load the state of the gamedate class from disk.
Definition: gamedate.cc:61
Class to write data from a Gzip compressed file.
Definition: fileops.h:227
static u_int16 weekday()
Get the current weekday.
Definition: gamedate.cc:77
Class to read data from a Gzip compressed file.
Definition: fileops.h:135
#define u_int16
16 bits long unsigned integer
Definition: types.h:38
static u_int16 hour()
Return the hour of the current day.
Definition: gamedate.cc:92
#define u_int32
32 bits long unsigned integer
Definition: types.h:41
static u_int16 day()
Returns the current day in the gameworld.
Definition: gamedate.cc:83
static u_int32 time()
Get the current gametime.
Definition: gamedate.h:64
static u_int16 minute()
Return the minute of the current hour.
Definition: gamedate.cc:98
static u_int32 parse_time(const std::string &time)
convert the time string to gametime minutes.
Definition: gamedate.cc:104
static void put_state(ogzstream &out)
Save the state of the gamedate class to disk.
Definition: gamedate.cc:70
static void update()
Update the game date.
Definition: gamedate.cc:40
Declares the igzstream, ogzstream and fileops classes.
Keeps track of the time the player spent within the game so far.
Definition: gamedate.h:49