Skip to content

Commit

Permalink
move game_classification to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgtdf committed Jun 16, 2014
1 parent 64580a7 commit 63c07fe
Show file tree
Hide file tree
Showing 30 changed files with 178 additions and 143 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Expand Up @@ -740,6 +740,7 @@ set(wesnoth-main_SRC
formula_string_utils.cpp
formula_tokenizer.cpp
game_board.cpp
game_classification.cpp
game_config_manager.cpp
game_controller.cpp
game_display.cpp
Expand Down
1 change: 1 addition & 0 deletions src/SConscript
Expand Up @@ -273,6 +273,7 @@ wesnoth_sources = Split("""
formula_string_utils.cpp
formula_tokenizer.cpp
game_board.cpp
game_classification.cpp
game_config_manager.cpp
game_controller.cpp
game_display.cpp
Expand Down
1 change: 0 additions & 1 deletion src/ai/composite/goal.cpp
Expand Up @@ -23,7 +23,6 @@
#include "../manager.hpp"
#include "../../log.hpp"
#include "../lua/lua_object.hpp"
#include "../../gamestatus.hpp"
#include "../../resources.hpp"
#include "../../scripting/lua.hpp"
#include "../../terrain_filter.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/ai/default/ai.cpp
Expand Up @@ -27,7 +27,7 @@
#include "../../dialogs.hpp"
#include "../../game_board.hpp"
#include "../../game_events/pump.hpp"
#include "../../gamestatus.hpp"
#include "../../game_classification.hpp"
#include "../../log.hpp"
#include "../../mouse_handler_base.hpp"
#include "../../resources.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/ai/lua/core.cpp
Expand Up @@ -33,7 +33,6 @@
#include "../../attack_prediction.hpp"
#include "../../filesystem.hpp"
#include "../../game_display.hpp"
#include "../../gamestatus.hpp"
#include "../../log.hpp"
#include "../../map.hpp"
#include "../../pathfind/pathfind.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/ai/testing/ca.cpp
Expand Up @@ -24,6 +24,7 @@
#include "../composite/rca.hpp"
#include "../composite/stage.hpp"
#include "../../game_board.hpp"
#include "../../game_classification.hpp"
#include "../../gamestatus.hpp"
#include "../../log.hpp"
#include "../../map.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/ai/testing/ca_testing_recruitment.cpp
Expand Up @@ -24,7 +24,6 @@
#include "../composite/rca.hpp"
#include "../composite/stage.hpp"
#include "../../game_board.hpp"
#include "../../gamestatus.hpp"
#include "../../log.hpp"
#include "../../map.hpp"
#include "../../resources.hpp"
Expand Down
3 changes: 2 additions & 1 deletion src/editor/map/map_context.hpp
Expand Up @@ -16,8 +16,9 @@
#define EDITOR_MAP_CONTEXT_HPP_INCLUDED

#include "editor_map.hpp"
#include "gamestatus.hpp"
#include "game_classification.hpp"
#include "map_label.hpp"
#include "mp_game_settings.hpp"
#include "sound_music_track.hpp"
#include "tod_manager.hpp"
#include "unit_map.hpp"
Expand Down
101 changes: 101 additions & 0 deletions src/game_classification.cpp
@@ -0,0 +1,101 @@
/*
Copyright (C) 2003 - 2014 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/

#include "global.hpp"
#include "game_classification.hpp"
#include "util.hpp"
#include "serialization/string_utils.hpp"
#include "log.hpp"

static lg::log_domain log_engine("engine");
#define ERR_NG LOG_STREAM(err, log_engine)
#define WRN_NG LOG_STREAM(warn, log_engine)
#define LOG_NG LOG_STREAM(info, log_engine)
#define DBG_NG LOG_STREAM(debug, log_engine)

/// The default difficulty setting for campaigns.
const std::string DEFAULT_DIFFICULTY("NORMAL");

game_classification::game_classification():
savegame_config(),
label(),
version(),
campaign_type(),
campaign_define(),
campaign_xtra_defines(),
campaign(),
abbrev(),
completion(),
end_credits(true),
end_text(),
end_text_duration(),
difficulty(DEFAULT_DIFFICULTY),
random_mode("")
{}

game_classification::game_classification(const config& cfg):
savegame_config(),
label(cfg["label"]),
version(cfg["version"]),
campaign_type(lexical_cast_default<game_classification::CAMPAIGN_TYPE> (cfg["campaign_type"].str(), game_classification::SCENARIO)),
campaign_define(cfg["campaign_define"]),
campaign_xtra_defines(utils::split(cfg["campaign_extra_defines"])),
campaign(cfg["campaign"]),
abbrev(cfg["abbrev"]),
completion(cfg["completion"]),
end_credits(cfg["end_credits"].to_bool(true)),
end_text(cfg["end_text"]),
end_text_duration(cfg["end_text_duration"]),
difficulty(cfg["difficulty"].empty() ? DEFAULT_DIFFICULTY : cfg["difficulty"].str()),
random_mode(cfg["random_mode"])
{}

game_classification::game_classification(const game_classification& gc):
savegame_config(),
label(gc.label),
version(gc.version),
campaign_type(gc.campaign_type),
campaign_define(gc.campaign_define),
campaign_xtra_defines(gc.campaign_xtra_defines),
campaign(gc.campaign),
abbrev(gc.abbrev),
completion(gc.completion),
end_credits(gc.end_credits),
end_text(gc.end_text),
end_text_duration(gc.end_text_duration),
difficulty(gc.difficulty),
random_mode(gc.random_mode)
{
}

config game_classification::to_config() const
{
config cfg;

cfg["label"] = label;
cfg["version"] = game_config::version;
cfg["campaign_type"] = lexical_cast<std::string> (campaign_type);
cfg["campaign_define"] = campaign_define;
cfg["campaign_extra_defines"] = utils::join(campaign_xtra_defines);
cfg["campaign"] = campaign;
cfg["abbrev"] = abbrev;
cfg["completion"] = completion;
cfg["end_credits"] = end_credits;
cfg["end_text"] = end_text;
cfg["end_text_duration"] = str_cast<unsigned int>(end_text_duration);
cfg["difficulty"] = difficulty;
cfg["random_mode"] = random_mode;

return cfg;
}
61 changes: 61 additions & 0 deletions src/game_classification.hpp
@@ -0,0 +1,61 @@
/*
Copyright (C) 2003 - 2014 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/

#ifndef GAME_CLASSIFICATION_HPP_INCLUDED
#define GAME_CLASSIFICATION_HPP_INCLUDED

#include "config.hpp"
#include "make_enum.hpp"
#include "savegame_config.hpp"

/// The default difficulty setting for campaigns.
extern const std::string DEFAULT_DIFFICULTY;

//meta information of the game
class game_classification : public savegame::savegame_config
{
public:
game_classification();
explicit game_classification(const config& cfg);
game_classification(const game_classification& gc);

config to_config() const;

std::string label; /**< Name of the game (e.g. name of save file). */
std::string version; /**< Version game was created with. */
MAKE_ENUM (CAMPAIGN_TYPE, /**< Type of the game - campaign, multiplayer etc. */
(SCENARIO, "scenario")
(MULTIPLAYER, "multiplayer")
(TEST, "test")
(TUTORIAL, "tutorial")
)
CAMPAIGN_TYPE campaign_type;
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 */
bool end_credits; /**< whether to show the standard credits at the end */
std::string end_text; /**< end-of-campaign text */
unsigned int end_text_duration; /**< for how long the end-of-campaign text is shown */
std::string difficulty; /**< The difficulty level the game is being played on. */
std::string random_mode;
};
MAKE_ENUM_STREAM_OPS2(game_classification, CAMPAIGN_TYPE)

#endif
1 change: 1 addition & 0 deletions src/game_config_manager.cpp
Expand Up @@ -19,6 +19,7 @@
#include "cursor.hpp"
#include "game_config.hpp"
#include "gettext.hpp"
#include "game_classification.hpp"
#include "gui/dialogs/wml_error.hpp"
#include "hotkey/hotkey_item.hpp"
#include "hotkey/hotkey_command.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/game_config_manager.hpp
Expand Up @@ -16,11 +16,11 @@

#include "commandline_options.hpp"
#include "config_cache.hpp"
#include "gamestatus.hpp"
#include "game_display.hpp"
#include "filesystem.hpp"

class config;
class game_classification;

class game_config_manager
{
Expand Down
1 change: 1 addition & 0 deletions src/game_events/action_wml.cpp
Expand Up @@ -32,6 +32,7 @@
#include "../dialogs.hpp"
#include "../fake_unit.hpp"
#include "../fake_unit_manager.hpp"
#include "../game_classification.hpp"
#include "../game_display.hpp"
#include "../game_preferences.hpp"
#include "../gettext.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/game_preferences.cpp
Expand Up @@ -19,7 +19,6 @@
#include "game_board.hpp"
#include "game_display.hpp"
#include "game_preferences.hpp"
#include "gamestatus.hpp"
#include "gettext.hpp"
#include "log.hpp"
#include "map.hpp"
Expand Down
73 changes: 0 additions & 73 deletions src/gamestatus.cpp
Expand Up @@ -523,76 +523,3 @@ game_data* game_data::operator=(const game_data* info)
}
return this ;
}

game_classification::game_classification():
savegame_config(),
label(),
version(),
campaign_type(),
campaign_define(),
campaign_xtra_defines(),
campaign(),
abbrev(),
completion(),
end_credits(true),
end_text(),
end_text_duration(),
difficulty(DEFAULT_DIFFICULTY),
random_mode("")
{}

game_classification::game_classification(const config& cfg):
savegame_config(),
label(cfg["label"]),
version(cfg["version"]),
campaign_type(lexical_cast_default<game_classification::CAMPAIGN_TYPE> (cfg["campaign_type"].str(), game_classification::SCENARIO)),
campaign_define(cfg["campaign_define"]),
campaign_xtra_defines(utils::split(cfg["campaign_extra_defines"])),
campaign(cfg["campaign"]),
abbrev(cfg["abbrev"]),
completion(cfg["completion"]),
end_credits(cfg["end_credits"].to_bool(true)),
end_text(cfg["end_text"]),
end_text_duration(cfg["end_text_duration"]),
difficulty(cfg["difficulty"].empty() ? DEFAULT_DIFFICULTY : cfg["difficulty"].str()),
random_mode(cfg["random_mode"])
{}

game_classification::game_classification(const game_classification& gc):
savegame_config(),
label(gc.label),
version(gc.version),
campaign_type(gc.campaign_type),
campaign_define(gc.campaign_define),
campaign_xtra_defines(gc.campaign_xtra_defines),
campaign(gc.campaign),
abbrev(gc.abbrev),
completion(gc.completion),
end_credits(gc.end_credits),
end_text(gc.end_text),
end_text_duration(gc.end_text_duration),
difficulty(gc.difficulty),
random_mode(gc.random_mode)
{
}

config game_classification::to_config() const
{
config cfg;

cfg["label"] = label;
cfg["version"] = game_config::version;
cfg["campaign_type"] = lexical_cast<std::string> (campaign_type);
cfg["campaign_define"] = campaign_define;
cfg["campaign_extra_defines"] = utils::join(campaign_xtra_defines);
cfg["campaign"] = campaign;
cfg["abbrev"] = abbrev;
cfg["completion"] = completion;
cfg["end_credits"] = end_credits;
cfg["end_text"] = end_text;
cfg["end_text_duration"] = str_cast<unsigned int>(end_text_duration);
cfg["difficulty"] = difficulty;
cfg["random_mode"] = random_mode;

return cfg;
}

0 comments on commit 63c07fe

Please sign in to comment.