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