Make sure all members are initialized in the constructor.

This commit is contained in:
Mark de Wever 2007-12-08 18:05:23 +00:00
parent accdbb5c0f
commit 7ce81c12f4
2 changed files with 80 additions and 31 deletions

View file

@ -180,10 +180,15 @@ static void parse_times(const config& cfg, std::vector<time_of_day>& normal_time
//! 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)
teams(0),
times_(),
areas_(),
turn_(1),
numTurns_(num_turns),
currentTime_(0),
state_of_game_(s_o_g)
{
teams = NULL;
std::string turn_at = time_cfg["turn_at"];
std::string turn_at = time_cfg["turn_at"];
std::string current_tod = time_cfg["current_tod"];
std::string random_start_time = time_cfg["random_start_time"];
if (s_o_g)
@ -193,12 +198,10 @@ gamestatus::gamestatus(const config& time_cfg, int num_turns, game_state* s_o_g)
}
if(turn_at.empty() == false)
{
if(turn_at.empty() == false) {
turn_ = atoi(turn_at.c_str());
}
parse_times(time_cfg,times_);
set_start_ToD(const_cast<config&>(time_cfg),s_o_g);
@ -422,16 +425,29 @@ static player_info read_player(const game_data& data, const config* cfg)
return res;
}
game_state::game_state(const game_data& data, const config& cfg)
: difficulty("NORMAL"), last_selected(gamemap::location::null_location)
game_state::game_state(const game_data& data, const config& cfg) :
label(cfg["label"]),
version(cfg["version"]),
campaign_type(cfg["campaign_type"]),
campaign_define(cfg["campaign_define"]),
campaign_xtra_defines(utils::split(cfg["campaign_extra_defines"])),
campaign(cfg["campaign"]),
abbrev(),
scenario(cfg["scenario"]),
next_scenario(cfg["next_scenario"]),
completion(cfg["completion"]),
players(),
scoped_variables(),
wml_menu_items(),
difficulty(cfg["difficulty"]),
replay_data(),
starting_pos(),
snapshot(),
last_selected(gamemap::location::null_location),
variables(),
temporaries()
{
log_scope("read_game");
label = cfg["label"];
version = cfg["version"];
scenario = cfg["scenario"];
next_scenario = cfg["next_scenario"];
completion = cfg["completion"];
campaign = cfg["campaign"];
const config* snapshot = cfg.child("snapshot");
@ -457,17 +473,13 @@ game_state::game_state(const game_data& data, const config& cfg)
std::cerr << "scenario: '" << scenario << "'\n";
std::cerr << "next_scenario: '" << next_scenario << "'\n";
difficulty = cfg["difficulty"];
if(difficulty.empty())
if(difficulty.empty()) {
difficulty = "NORMAL";
}
campaign_define = cfg["campaign_define"];
campaign_xtra_defines = utils::split(cfg["campaign_extra_defines"]);
campaign_type = cfg["campaign_type"];
if(campaign_type.empty())
if(campaign_type.empty()) {
campaign_type = "scenario";
}
const config* const vars = cfg.child("variables");
if(vars != NULL) {
@ -1150,7 +1162,15 @@ void game_state::set_menu_items(const config::child_list& menu_items) {
}
}
wml_menu_item::wml_menu_item(const std::string& id, const config* cfg) : needs_select(false)
wml_menu_item::wml_menu_item(const std::string& id, const config* cfg) :
name(),
image(),
description(),
needs_select(false),
show_if(),
filter_location(),
command()
{
std::stringstream temp;
temp << "menu item";

View file

@ -93,7 +93,29 @@ struct player_info
class game_state : public variable_set
{
public:
game_state() : difficulty("NORMAL"), last_selected(gamemap::location::null_location) {}
game_state() :
label(),
version(),
campaign_type(),
campaign_define(),
campaign_xtra_defines(),
campaign(),
abbrev(),
scenario(),
next_scenario(),
completion(),
players(),
scoped_variables(),
wml_menu_items(),
difficulty("NORMAL"),
replay_data(),
starting_pos(),
snapshot(),
last_selected(gamemap::location::null_location),
variables(),
temporaries()
{}
game_state(const game_state& state);
game_state(const game_data& data, const config& cfg);
@ -104,14 +126,14 @@ public:
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::vector<std::string> campaign_xtra_defines; // more customization of 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 abbrev; //!< the campaign abbreviation
std::string scenario; //!< the scenario being played
std::string next_scenario; //!< the scenario coming next (for campaigns)
std::string completion; //!< running. victory, or defeat
std::string campaign; //!< the campaign being played
std::string abbrev; //!< the campaign abbreviation
std::string scenario; //!< the scenario being played
std::string next_scenario; //!< the scenario coming next (for campaigns)
std::string completion; //!< running. victory, or defeat
//! Information about campaign players who carry resources
//! from previous levels, indexed by a string identifier
@ -205,6 +227,13 @@ private:
std::vector<time_of_day> times_;
struct area_time_of_day {
area_time_of_day() :
xsrc(),
ysrc(),
times(),
hexes()
{}
std::string xsrc, ysrc;
std::vector<time_of_day> times;
std::set<gamemap::location> hexes;