doxygen, comments

This commit is contained in:
Hans Joachim Gurt 2007-08-26 13:59:05 +00:00
parent b1b809feed
commit 713099208d
3 changed files with 97 additions and 94 deletions

View file

@ -422,7 +422,7 @@ int divide(int a,int b) {
/** -file display.hpp */
/** -file filesystem.hpp */
/** @file game.hpp */
/** @file gamestatus.hpp */
/** -file gamestatus.hpp */
/** @file intro.hpp */
/** @file key.hpp */
/** @file language.hpp */

View file

@ -12,6 +12,9 @@
See the COPYING file for more details.
*/
//! @file gamestatus.cpp
//! Maintain status of a game, load&save games.
#include "global.hpp"
#include "wassert.hpp"
@ -45,13 +48,13 @@
#ifdef _WIN32
#include <windows.h>
// conv_ansi_utf8()
// - Convert a string between ANSI encoding (for Windows filename) and UTF-8
// string &name
// - filename to be converted
// bool a2u
// - if true, convert the string from ANSI to UTF-8.
// - if false, reverse. (convert it from UTF-8 to ANSI)
//! conv_ansi_utf8()
//! - Convert a string between ANSI encoding (for Windows filename) and UTF-8
//! string &name
//! - filename to be converted
//! bool a2u
//! - if true, convert the string from ANSI to UTF-8.
//! - if false, reverse. (convert it from UTF-8 to ANSI)
void conv_ansi_utf8(std::string &name, bool a2u) {
int wlen = MultiByteToWideChar(a2u ? CP_ACP : CP_UTF8, 0,
name.c_str(), -1, NULL, 0);
@ -167,15 +170,15 @@ static void parse_times(const config& cfg, std::vector<time_of_day>& normal_time
if(normal_times.empty())
{
// Makeing sure we have at least default time
// Make sure we have at least default time
config dummy_cfg;
normal_times.push_back(time_of_day(dummy_cfg));
}
}
/// Reads turns and time information from parameters
/// It sets random starting ToD and current_tod to config
///
//! Reads turns and time information from parameters.
//! It sets random starting ToD and current_tod to config.
//!
gamestatus::gamestatus(const config& time_cfg, int num_turns, game_state* s_o_g) :
turn_(1),numTurns_(num_turns),currentTime_(0),state_of_game_(s_o_g)
{
@ -241,8 +244,8 @@ void gamestatus::write(config& cfg) const
}
}
/// returns time of day object in the turn
/// Correct time is calculated from current time.
//! Returns time of day object in the turn.
//! Correct time is calculated from current time.
time_of_day gamestatus::get_time_of_day_turn(int nturn) const
{
wassert(!times_.empty());
@ -257,8 +260,7 @@ time_of_day gamestatus::get_time_of_day_turn(int nturn) const
return times_[time];
}
/// returns time of day object for current turn
//! ~eturns time of day object for current turn.
time_of_day gamestatus::get_time_of_day() const
{
return times_[currentTime_];
@ -269,9 +271,9 @@ time_of_day gamestatus::get_previous_time_of_day() const
return get_time_of_day_turn(turn()-1);
}
/// Returns time of day object in the turn.
/// It first tryes to look for specified. If no area time specified in location it returns global time.
//! Returns time of day object in the turn.
//! It first tries to look for specified.
//! If no area time specified in location, it returns global time.
time_of_day gamestatus::get_time_of_day(int illuminated, const gamemap::location& loc, int n_turn) const
{
time_of_day res = get_time_of_day_turn(n_turn);
@ -299,9 +301,8 @@ time_of_day gamestatus::get_time_of_day(int illuminated, const gamemap::location
return get_time_of_day(illuminated,loc,turn());
}
/// Sets global time of day in this turn.
/// Time is number between 0 and n-1 where n is number of ToDs
//! Sets global time of day in this turn.
//! Time is a number between 0 and n-1, where n is number of ToDs.
bool gamestatus::set_time_of_day(int newTime)
{
// newTime can come from network so have to take run time test
@ -355,7 +356,7 @@ void gamestatus::set_start_ToD(config &level, game_state* s_o_g)
set_time_of_day((turn() - 1) % times_.size());
}
// Setting tod to level data
// Setting ToD to level data
std::stringstream buf;
buf << currentTime_;
@ -435,8 +436,8 @@ game_state::game_state(const game_data& data, const config& cfg)
const config::child_list& players = cfg.get_children("player");
if(players.empty()) {
//backwards compatibility code: assume that there is player data
//in the file itself, which corresponds to the leader of side 1
// Backwards compatibility code: assume that there is player data
// in the file itself, which corresponds to the leader of side 1.
const config::child_list& units = cfg.get_children("unit");
config::child_list::const_iterator i;
for(i = units.begin(); i != units.end(); ++i) {
@ -488,7 +489,7 @@ game_state::game_state(const game_data& data, const config& cfg)
replay_data = *replay;
}
//older save files used to use 'start', so still support that for now
// Older save files used to use 'start', so still support that for now.
if(snapshot == NULL) {
snapshot = cfg.child("start");
}
@ -528,7 +529,7 @@ static void write_player(const player_info& player, config& cfg)
std::copy(player.can_recruit.begin(),player.can_recruit.end(),std::ostream_iterator<std::string>(can_recruit,","));
std::string can_recruit_str = can_recruit.str();
//remove the trailing comma
// Remove the trailing comma
if(can_recruit_str.empty() == false) {
can_recruit_str.resize(can_recruit_str.size()-1);
}
@ -556,7 +557,7 @@ static void write_player(config_writer &out, const player_info& player)
std::copy(player.can_recruit.begin(),player.can_recruit.end(),std::ostream_iterator<std::string>(can_recruit,","));
std::string can_recruit_str = can_recruit.str();
//remove the trailing comma
// Remove the trailing comma
if(can_recruit_str.empty() == false) {
can_recruit_str.resize(can_recruit_str.size()-1);
}
@ -565,7 +566,7 @@ static void write_player(config_writer &out, const player_info& player)
}
// Deprecated, use other write_game below.
//! @deprecated, use other write_game below.
void write_game(const game_state& gamestate, config& cfg, WRITE_GAME_MODE mode)
{
log_scope("write_game");
@ -673,8 +674,8 @@ void write_game(config_writer &out, const game_state& gamestate, WRITE_GAME_MODE
}
}
//a structure for comparing to save_info objects based on their modified time.
//if the times are equal, will order based on the name
//! A structure for comparing to save_info objects based on their modified time.
//! If the times are equal, will order based on the name.
struct save_info_less_time {
bool operator()(const save_info& a, const save_info& b) const {
return a.time_modified > b.time_modified ||
@ -724,7 +725,7 @@ void read_save_file(const std::string& name, config& cfg, std::string* error_log
std::string modified_name = name;
replace_space2underbar(modified_name);
//try reading the file both with and without underscores
// Try reading the file both with and without underscores
scoped_istream file_stream = istream_file(get_saves_dir() + "/" + modified_name);
if (file_stream->fail())
file_stream = istream_file(get_saves_dir() + "/" + name);
@ -763,7 +764,7 @@ void load_game_summary(const std::string& name, config& cfg_summary, std::string
extract_summary_from_config(cfg, cfg_summary);
}
//throws game::save_game_failed
// Throws game::save_game_failed
scoped_ostream open_save_game(const std::string &label)
{
std::string name = label;
@ -797,7 +798,7 @@ void finish_save_game(config_writer &out, const game_state& gamestate, const std
}
}
//throws game::save_game_failed
// Throws game::save_game_failed
void save_game(const game_state& gamestate)
{
scoped_ostream os(open_save_game(gamestate.label));
@ -875,10 +876,9 @@ void extract_summary_data_from_save(const game_state& gamestate, config& out)
}
}
//find the first human leader so we can display their icon in the load menu
// Find the first human leader so we can display their icon in the load menu.
//ideally we should grab all leaders if there's more than 1
//human player?
//! @todo Ideally we should grab all leaders if there's more than 1 human player?
std::string leader;
for(std::map<std::string, player_info>::const_iterator p = gamestate.players.begin();
@ -956,10 +956,9 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary)
}
}
//find the first human leader so we can display their icon in the load menu
// Find the first human leader so we can display their icon in the load menu.
//ideally we should grab all leaders if there's more than 1
//human player?
//! @todo Ideally we should grab all leaders if there's more than 1 human player?
std::string leader;
const config::child_list& players = cfg_save.get_children("player");

View file

@ -11,6 +11,10 @@
See the COPYING file for more details.
*/
//! @file gamestatus.hpp
//!
#ifndef GAME_STATUS_HPP_INCLUDED
#define GAME_STATUS_HPP_INCLUDED
@ -25,32 +29,32 @@
class scoped_wml_variable;
//an object which defines the current time of day
//! Object which defines the current time of day.
struct time_of_day
{
explicit time_of_day(const config& cfg);
void write(config& cfg) const;
//the % bonus lawful units receive. chaotic units will
//receive -lawful_bonus.
// The % bonus lawful units receive.
// Chaotic units will receive -lawful_bonus.
int lawful_bonus;
int bonus_modified;
//the image to be displayed in the game status.
// The image to be displayed in the game status.
std::string image;
t_string name;
std::string id;
//the image that is to be laid over all images while it's this
//time of day
// The image that is to be laid over all images
// while this time of day lasts.
std::string image_mask;
//the colour modifications that should
//be made to the game board to reflect the time of day.
// The colour modifications that should be made
// to the game board to reflect the time of day.
int red, green, blue;
// list of "ambient" sounds associated with this time_of_day,
// played at the beginning of turn
//! List of "ambient" sounds associated with this time_of_day,
//! Played at the beginning of turn.
std::string sounds;
};
@ -71,11 +75,10 @@ struct player_info
{
player_info():gold(-1) {}
std::string name; /** < to sore the current_player name */
int gold; /** < amount of gold the player has saved */
std::vector<unit> available_units; /** < units the player may recall */
std::set<std::string> can_recruit; /** < units the player has the ability to recruit */
std::string name; /** < Stores the current_player name */
int gold; /** < Amount of gold the player has saved */
std::vector<unit> available_units; /** < Units the player may recall */
std::set<std::string> can_recruit; /** < Units the player has the ability to recruit */
};
class game_state : public variable_set
@ -88,24 +91,24 @@ public:
~game_state();
game_state& operator=(const game_state& state);
std::string label; //name of the game (e.g. name of save file)
std::string version; //version game was created with.
std::string campaign_type; //type of the game - campaign, multiplayer etc
std::string label; //!< Name of the game (e.g. name of save file).
std::string version; //!< Version game was created with.
std::string campaign_type; //!< Type of the game - campaign, multiplayer etc.
std::string campaign_define; //if there is a define the campaign uses to customize data
std::string campaign_define; //! If there is a define the campaign uses to customize data
std::vector<std::string> campaign_xtra_defines; // more customization of data
std::string campaign; //the campaign being played
std::string scenario; //the scenario being played
std::string completion; // running. victory, or defeat
std::string campaign; //!< the campaign being played
std::string scenario; //!< the scenario being played
std::string completion; //!< running. victory, or defeat
// information about campaign players who carry resources from
// previous levels, indexed by a string identifier (which is
// the leader name by default, but can be set with the "id"
// attribute of the "side" tag)
//! Information about campaign players who carry resources
//! from previous levels, indexed by a string identifier
// (which is the leader name by default, but can be set
// with the "id" attribute of the "side" tag).
std::map<std::string, player_info> players;
// Return the Nth player, or NULL if no such player exists
//! Return the Nth player, or NULL if no such player exists.
player_info* get_player(const std::string& id);
std::vector<scoped_wml_variable*> scoped_variables;
@ -116,7 +119,7 @@ public:
void set_menu_items(const config::child_list& menu_items);
//Variable access
// Variable access
t_string& get_variable(const std::string& varname);
virtual const t_string& get_variable_const(const std::string& varname) const;
@ -126,33 +129,35 @@ public:
config& add_variable_cfg(const std::string& varname, const config& value=config());
void clear_variable(const std::string& varname);
void clear_variable_cfg(const std::string& varname); //clears only the config children
void clear_variable_cfg(const std::string& varname); // Clears only the config children
std::string difficulty; //the difficulty level the game is being played on.
std::string difficulty; //!< The difficulty level the game is being played on.
//if the game is saved mid-level, we have a series of replay steps to
//take the game up to the position it was saved at.
//! If the game is saved mid-level, we have a series of replay steps
//! to take the game up to the position it was saved at.
config replay_data;
//for multiplayer games, the position the game started in may be different to
//the scenario, so we save the starting state of the game here.
//! Saved starting state of the game.
//! For multiplayer games, the position the game started in
//! may be different to the scenario,
config starting_pos;
//the snapshot of the game's current contents. i.e. unless the player selects
//to view a replay, the game's settings are read in from this object
//! Snapshot of the game's current contents.
//! i.e. unless the player selects to view a replay,
//! the game's settings are read in from this object.
config snapshot;
//the last location where a select event fired.
//! the last location where a select event fired.
gamemap::location last_selected;
private:
config variables;
mutable config temporaries; //lengths of arrays, etc.
mutable config temporaries; // lengths of arrays, etc.
friend struct variable_info;
};
//class which contains the global status of the game -- namely
//the current turn, the number of turns, and the time of day.
//! Contains the global status of the game.
//! Namely the current turn, the number of turns, and the time of day.
class gamestatus
{
public:
@ -169,14 +174,14 @@ public:
void modify_turns(const std::string& mod);
void add_turns(int num);
//function to move to the next turn. Returns true iff time
//has expired.
//! function to move to the next turn.
//! Returns true iff time has expired.
bool next_turn();
static bool is_start_ToD(const std::string&);
//FIXME: since gamestatus may be constructed with NULL game_state* (by default),
//you should not rely on this function to return the current game_state
//! @todo FIXME: since gamestatus may be constructed with NULL game_state* (by default),
//! you should not rely on this function to return the current game_state.
const game_state& sog() const{return(*state_of_game_);}
std::vector<team> *teams;
@ -202,17 +207,16 @@ private:
const game_state* state_of_game_;
};
//object which holds all the data needed to start a scenario.
//i.e. this is the object serialized to disk when saving/loading a game.
//is also the object which needs to be created to start a new game
//! Holds all the data needed to start a scenario.
//! i.e. this is the object serialized to disk when saving/loading a game.
//! It is also the object which needs to be created to start a new game.
struct save_info {
save_info(const std::string& n, time_t t) : name(n), time_modified(t) {}
std::string name;
time_t time_modified;
};
//function to get a list of available saves.
//! Get a list of available saves.
std::vector<save_info> get_saves_list(const std::string *dir = NULL);
enum WRITE_GAME_MODE { WRITE_SNAPSHOT_ONLY, WRITE_FULL_GAME };
@ -222,20 +226,20 @@ void read_save_file(const std::string& name, config& cfg, std::string* error_log
void write_game(const game_state& gamestate, config& cfg, WRITE_GAME_MODE mode=WRITE_FULL_GAME);
void write_game(config_writer &out, const game_state& gamestate, WRITE_GAME_MODE mode=WRITE_FULL_GAME);
// function returns true iff there is already savegame with that name
//! Returns true iff there is already a savegame with that name.
bool save_game_exists(const std::string & name);
//throws game::save_game_failed
//! Throws game::save_game_failed
scoped_ostream open_save_game(const std::string &label);
void finish_save_game(config_writer &out, const game_state& gamestate, const std::string &label);
//functions to load/save games.
//! Load/Save games.
void load_game(const game_data& data, const std::string& name, game_state& gamestate, std::string* error_log);
void load_game_summary(const std::string& name, config& cfg_summary, std::string* error_log);
//throws gamestatus::save_game_failed
//! Throws gamestatus::save_game_failed
void save_game(const game_state& gamestate);
//function to delete a save
//! Delete a savegame.
void delete_game(const std::string& name);
config& save_summary(const std::string& save);