1 // Copyright (C) 2008, Ben Asselstine
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 #ifndef RECENTLY_PLAYED_GAME_H
19 #define RECENTLY_PLAYED_GAME_H
27 #include "GameScenario.h"
30 //! A single game entry in the recently played games list.
34 class RecentlyPlayedGame
38 //! The xml tag of this object in a recently played game file.
39 static std::string d_tag;
41 //! Loading constructor.
43 * Make a new recently played game object by reading it in from an
44 * opened recently played games list file.
46 * @param helper The opened recently played games list file to read the
49 RecentlyPlayedGame(XML_Helper* helper);
51 //! Default constructor.
53 * Make a new recently played game object by taking values from the
56 RecentlyPlayedGame(GameScenario *game_scenario);
59 virtual ~RecentlyPlayedGame();
63 //! Get the scenario id of the recently played game entry.
64 std::string getId() const {return d_id;};
66 //! Get time of when this game was last played (seconds past the epoch).
67 time_t getTimeOfLastPlay() const { return d_time;};
69 //! Get the round that we last saw this game at..
70 guint32 getRound() const { return d_round;};
72 //! Get the number of cities in the game.
73 guint32 getNumberOfCities() const {return d_number_of_cities;};
75 //! Get the number of players in the game.
76 guint32 getNumberOfPlayers() const {return d_number_of_players;};
78 //! Get the kind of game.
79 GameScenario::PlayMode getPlayMode() const {return d_playmode;};
81 //! Get the name of the scenario.
82 std::string getName() const {return d_name;};
87 //! Set the last time we saw something happen in this game.
88 void setTimeOfLastPlay(time_t then) { d_time = then;};
90 //! Set the round that we last saw this game at.
91 void setRound(guint32 round) { d_round = round;};
94 // Methods that operate on the class data but do not modify it.
96 //! Save the game entry to an opened file.
97 bool save(XML_Helper* helper) const;
99 //! Save the game entry, but not the enclosing tags.
100 bool saveContents(XML_Helper *helper) const;
106 * static load function (see XML_Helper)
108 * Whenever a game entry is loaded, this function is called. It
109 * examines the stored id and calls the constructor of the appropriate
110 * recently played game class.
112 * @param helper the XML_Helper instance for the savegame
114 static RecentlyPlayedGame* handle_load(XML_Helper *helper);
118 //! Save the entry to an opened file.
119 virtual bool doSave(XML_Helper *helper) const = 0;
123 //! The id of the game.
126 //! When the game was last played.
129 //! What round the game was at.
132 //! How many cities the game has.
133 guint32 d_number_of_cities;
135 //! How many players the game had at the start of the game.
136 guint32 d_number_of_players;
138 //! The kind of game.
139 GameScenario::PlayMode d_playmode;
141 //! The name of the game.
146 class RecentlyPlayedHotseatGame : public RecentlyPlayedGame
149 //! Make a new hotseat game entry.
150 RecentlyPlayedHotseatGame(GameScenario *game_scenario);
152 //! Load a new hotseat game from an opened file.
153 RecentlyPlayedHotseatGame(XML_Helper *helper);
155 //! Destroy a hotseat game entry.
156 ~RecentlyPlayedHotseatGame();
159 // Methods that operate on the class data but do not modify it.
161 //! Save the hotseat game entry to an opened file.
162 virtual bool doSave(XML_Helper *helper) const;
165 // Methods that operate on the class data and modify it.
167 //! Assign the filename to the entry.
168 bool fillData(std::string filename);
171 std::string d_filename;
174 class RecentlyPlayedPbmGame : public RecentlyPlayedGame
177 //! Make a new pbm game entry.
178 RecentlyPlayedPbmGame(GameScenario *game_scenario);
180 //! Load a new pbm game from an opened saved-game file.
181 RecentlyPlayedPbmGame(XML_Helper *helper);
183 //! Destroy a pbm game entry.
184 ~RecentlyPlayedPbmGame();
187 // Methods that operate on the class data but do not modify it.
189 //! Save the play-by-mail game entry to an opened file.
190 virtual bool doSave(XML_Helper *helper) const;
193 // Methods that operate on the class data and modify it.
195 //! Assign the filename to the entry.
196 bool fillData(std::string filename);
201 //! The filename of the play-by-mail game for this entry.
202 std::string d_filename;
205 class RecentlyPlayedNetworkedGame : public RecentlyPlayedGame
208 //! Make a new networked game entry.
209 RecentlyPlayedNetworkedGame(GameScenario *game_scenario);
211 //! Load a new networked game from an opened file.
212 RecentlyPlayedNetworkedGame(XML_Helper *helper);
214 //! Destroy a networked game entry.
215 ~RecentlyPlayedNetworkedGame();
220 //! Get the hostname associated with the game.
221 std::string getHost() const {return d_host;};
223 //! Get the port associated with the host, and game.
224 guint32 getPort() const {return d_port;};
227 // Methods that operate on the class data but do not modify it.
229 //! Save the networked game entry to an opened file.
230 virtual bool doSave(XML_Helper *helper) const;
233 // Methods that operate on the class data and modify it.
235 bool fillData(std::string host, guint32 port);
241 //! The hostname that the network game was hosted at.
244 //! The port on the hostname that the network game was hosted at.
248 #endif // RECENTLY_PLAYED_GAME_H