Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/wesnoth/wesnoth
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 11, 2014
2 parents 22cc827 + c9be48f commit 148d42e
Show file tree
Hide file tree
Showing 38 changed files with 285 additions and 260 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Expand Up @@ -859,6 +859,7 @@ set(wesnoth-main_SRC
resources.cpp
save_blocker.cpp
save_index.cpp
saved_game.cpp
savegame.cpp
scripting/debug_lua.cpp
scripting/lua.cpp
Expand Down
1 change: 1 addition & 0 deletions src/SConscript
Expand Up @@ -492,6 +492,7 @@ wesnoth_sources = Split("""
resources.cpp
save_blocker.cpp
save_index.cpp
saved_game.cpp
savegame.cpp
scripting/debug_lua.cpp
scripting/lua.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/editor/map/context_manager.cpp
Expand Up @@ -84,8 +84,8 @@ class map_context_refresher
context_manager_.gui().replace_overlay_map(&context_manager_.get_map_context().get_overlays());


resources::classification = &context_manager_.get_map_context().get_game_state().classification();
resources::mp_settings = &context_manager_.get_map_context().get_game_state().mp_settings();
resources::classification = &context_manager_.get_map_context().get_classification();
resources::mp_settings = &context_manager_.get_map_context().get_mp_settings();

context_manager_.gui().init_flags();

Expand Down
6 changes: 4 additions & 2 deletions src/editor/map/map_context.cpp
Expand Up @@ -63,7 +63,8 @@ map_context::map_context(const editor_map& map, const display& disp, bool pure_m
, units_()
, teams_()
, tod_manager_(new tod_manager(schedule))
, state_()
, mp_settings_()
, game_classification_()
, music_tracks_()
{
}
Expand Down Expand Up @@ -94,7 +95,8 @@ map_context::map_context(const config& game_config, const std::string& filename,
, units_()
, teams_()
, tod_manager_(new tod_manager(game_config.find_child("editor_times", "id", "default")))
, state_()
, mp_settings_()
, game_classification_()
, music_tracks_()
{
/*
Expand Down
12 changes: 8 additions & 4 deletions src/editor/map/map_context.hpp
Expand Up @@ -157,9 +157,12 @@ class map_context : public display_context, private boost::noncopyable
tod_manager* get_time_manager() {
return tod_manager_.get();
}

game_state& get_game_state() {
return state_;

mp_game_settings & get_mp_settings() {
return mp_settings_;
}
game_classification& get_classification() {
return game_classification_;
}

/**
Expand Down Expand Up @@ -475,7 +478,8 @@ class map_context : public display_context, private boost::noncopyable
unit_map units_;
std::vector<team> teams_;
boost::scoped_ptr<tod_manager> tod_manager_;
game_state state_;
mp_game_settings mp_settings_;
game_classification game_classification_;

typedef std::map<std::string, sound::music_track> music_map;
music_map music_tracks_;
Expand Down
8 changes: 4 additions & 4 deletions src/game_controller.cpp
Expand Up @@ -643,7 +643,7 @@ bool game_controller::load_game()

void game_controller::set_tutorial()
{
state_ = game_state();
state_ = saved_game();
state_.classification().campaign_type = game_classification::TUTORIAL;
state_.carryover_sides_start["next_scenario"] = "tutorial";
state_.classification().campaign_define = "TUTORIAL";
Expand All @@ -658,7 +658,7 @@ void game_controller::mark_completed_campaigns(std::vector<config> &campaigns)

bool game_controller::new_campaign()
{
state_ = game_state();
state_ = saved_game();
state_.classification().campaign_type = game_classification::SCENARIO;

std::vector<config> campaigns;
Expand Down Expand Up @@ -881,7 +881,7 @@ bool game_controller::play_multiplayer()
{
int res;

state_ = game_state();
state_ = saved_game();
state_.classification().campaign_type = game_classification::MULTIPLAYER;

//Print Gui only if the user hasn't specified any server
Expand Down Expand Up @@ -1002,7 +1002,7 @@ bool game_controller::play_multiplayer_commandline()
DBG_MP << "starting multiplayer game from the commandline" << std::endl;

// These are all the relevant lines taken literally from play_multiplayer() above
state_ = game_state();
state_ = saved_game();
state_.classification().campaign_type = game_classification::MULTIPLAYER;

resources::config_manager->
Expand Down
4 changes: 2 additions & 2 deletions src/game_controller.hpp
Expand Up @@ -16,7 +16,7 @@

#include "commandline_options.hpp"
#include "editor/editor_main.hpp"
#include "gamestatus.hpp"
#include "saved_game.hpp"
#include "game_config_manager.hpp"
#include "game_display.hpp"
#include "game_preferences.hpp"
Expand Down Expand Up @@ -110,7 +110,7 @@ class game_controller

std::string screenshot_map_, screenshot_filename_;

game_state state_;
saved_game state_;

std::string multiplayer_server_;
bool jump_to_multiplayer_;
Expand Down
1 change: 0 additions & 1 deletion src/game_preferences.hpp
Expand Up @@ -16,7 +16,6 @@

class game_board;
class gamemap;
class game_state;
class team;
class unit_map;

Expand Down
98 changes: 0 additions & 98 deletions src/gamestatus.cpp
Expand Up @@ -598,74 +598,6 @@ config game_classification::to_config() const
return cfg;
}

game_state::game_state() :
replay_data(),
snapshot(),
carryover_sides(),
carryover_sides_start(carryover_info().to_config()),
replay_start_(),
classification_(),
mp_settings_()
{}

game_state::game_state(const config& cfg, bool show_replay) :
replay_data(),
snapshot(),
carryover_sides(),
carryover_sides_start(),
replay_start_(),
classification_(cfg),
mp_settings_(cfg)
{
log_scope("read_game");

if(cfg.has_child("carryover_sides")){
carryover_sides = cfg.child("carryover_sides");
}
if(cfg.has_child("carryover_sides_start")){
carryover_sides_start = cfg.child("carryover_sides_start");
}

if(show_replay){
//If replay_start and replay_data couldn't be loaded
if(!load_replay(cfg)){
//TODO: notify user of failure
ERR_NG<<"Could not load as replay " << std::endl;
}
} else {
if(const config& snapshot = cfg.child("snapshot")){
this->snapshot = snapshot;
load_replay(cfg);
} else if(carryover_sides_start.empty() && !carryover_sides.empty()){
//if we are loading a start of scenario save and don't have carryover_sides_start, use carryover_sides
carryover_sides_start = carryover_sides;
}
//TODO: check if loading fails completely
}

LOG_NG << "scenario: '" << carryover_sides_start["next_scenario"] << "'\n";

if (const config &stats = cfg.child("statistics")) {
statistics::fresh_stats();
statistics::read_stats(stats);
}

}

bool game_state::load_replay(const config& cfg){
bool replay_loaded = false;

if(const config& replay_start = cfg.child("replay_start")){
replay_start_ = replay_start;
if(const config& replay = cfg.child("replay")){
this->replay_data = replay;
replay_loaded = true;
}
}

return replay_loaded;
}

void convert_old_saves(config& cfg){
if(!cfg.has_child("snapshot")){
return;
Expand Down Expand Up @@ -771,33 +703,3 @@ void convert_old_saves(config& cfg){
//1.12-1.13 end
LOG_RG<<"cfg after conversion "<<cfg<<"\n";
}

game_state::game_state(const game_state& state) :
replay_data(state.replay_data),
snapshot(state.snapshot),
carryover_sides(state.carryover_sides),
carryover_sides_start(state.carryover_sides_start),
replay_start_(state.replay_start_),
classification_(state.classification_),
mp_settings_(state.mp_settings_)
{}

game_state& game_state::operator=(const game_state& state)
{
// Use copy constructor to make sure we are coherent
if (this != &state) {
this->~game_state();
new (this) game_state(state) ;
}
return *this ;
}


void game_state::write_config(config_writer& out) const
{
out.write(classification_.to_config());
if (classification_.campaign_type == game_classification::MULTIPLAYER) {
out.write_child(lexical_cast<std::string>(game_classification::MULTIPLAYER), mp_settings_.to_config());
}
}

52 changes: 0 additions & 52 deletions src/gamestatus.hpp
Expand Up @@ -163,56 +163,4 @@ class game_classification : public savegame::savegame_config
};
MAKE_ENUM_STREAM_OPS2(game_classification, CAMPAIGN_TYPE)

class game_state
{
public:
game_state();
game_state(const game_state& state);
explicit game_state(const config& cfg, bool show_replay = false);

~game_state(){}
game_state& operator=(const game_state& state);

//write the config information into a stream (file)
void write_config(config_writer& out) const;

game_classification& classification() { return classification_; }
const game_classification& classification() const { return classification_; }

/** Multiplayer parameters for this game */
mp_game_settings& mp_settings() { return mp_settings_; }
const mp_game_settings& mp_settings() const { return mp_settings_; }

bool load_replay(const config& cfg);

config& replay_start() { return replay_start_; }

/**
* 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;

/**
* 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 carryover information for all sides*/
config carryover_sides;

/** The carryover information for all sides as it was before the scenario started*/
config carryover_sides_start;

private:
/** First turn snapshot for replays, contains starting position */
config replay_start_;

game_classification classification_;
mp_game_settings mp_settings_;
};

#endif
10 changes: 5 additions & 5 deletions src/mp_game_utils.cpp
Expand Up @@ -17,7 +17,7 @@
#include "config.hpp"
#include "dialogs.hpp"
#include "formula_string_utils.hpp"
#include "gamestatus.hpp"
#include "saved_game.hpp"
#include "game_config_manager.hpp"
#include "gettext.hpp"
#include "log.hpp"
Expand Down Expand Up @@ -45,7 +45,7 @@ static lg::log_domain log_network("network");
namespace mp {

config initial_level_config(game_display& disp, const mp_game_settings& params,
game_state& state)
saved_game& state)
{
config level;

Expand Down Expand Up @@ -161,7 +161,7 @@ config initial_level_config(game_display& disp, const mp_game_settings& params,
return level;
}

void level_to_gamestate(config& level, game_state& state)
void level_to_gamestate(config& level, saved_game& state)
{
// Any replay data is only temporary and should be removed from
// the level data in case we want to save the game later.
Expand Down Expand Up @@ -259,9 +259,9 @@ void level_to_gamestate(config& level, game_state& state)
}
}
if (sides.get_variables().empty()) {
LOG_NG << "No variables were found for the game_state." << std::endl;
LOG_NG << "No variables were found for the saved_game." << std::endl;
} else {
LOG_NG << "Variables found and loaded into game_state:" << std::endl;
LOG_NG << "Variables found and loaded into saved_game:" << std::endl;
LOG_NG << sides.get_variables();
}

Expand Down
6 changes: 3 additions & 3 deletions src/mp_game_utils.hpp
Expand Up @@ -19,14 +19,14 @@
#include "network.hpp"

class config;
class game_state;
class saved_game;

namespace mp {

config initial_level_config(game_display& disp, const mp_game_settings& params,
game_state& state);
saved_game& state);

void level_to_gamestate(config& level, game_state& state);
void level_to_gamestate(config& level, saved_game& state);

void check_response(network::connection res, const config& data);

Expand Down

0 comments on commit 148d42e

Please sign in to comment.