wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src Makefile.am game.cpp gamestatus.cpp...


From: Philippe Plantier
Subject: [Wesnoth-cvs-commits] wesnoth/src Makefile.am game.cpp gamestatus.cpp...
Date: Wed, 27 Apr 2005 17:11:44 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Philippe Plantier <address@hidden>      05/04/27 21:11:44

Modified files:
        src            : Makefile.am game.cpp gamestatus.cpp 
                         gamestatus.hpp multiplayer.cpp multiplayer.hpp 
                         multiplayer_connect.cpp multiplayer_connect.hpp 
                         multiplayer_ui.cpp multiplayer_ui.hpp 
                         multiplayer_wait.cpp multiplayer_wait.hpp 
                         playlevel.cpp playlevel.hpp unit.cpp 
        src/server     : game.cpp game.hpp server.cpp 
Added files:
        src            : playcampaign.cpp playcampaign.hpp 

Log message:
        Added support for the "next_scenario" WML value in multiplayer games.
        
        (This means that now, we only need a few UI polishing fixes to have 
decent
        support for multiplayer campaigns)
        
        This is possibly buggy and needs polishing anyway.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playcampaign.cpp?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playcampaign.hpp?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/Makefile.am.diff?tr1=1.93&tr2=1.94&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.238&tr2=1.239&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/gamestatus.cpp.diff?tr1=1.70&tr2=1.71&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/gamestatus.hpp.diff?tr1=1.44&tr2=1.45&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer.cpp.diff?tr1=1.157&tr2=1.158&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer.hpp.diff?tr1=1.26&tr2=1.27&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer_connect.cpp.diff?tr1=1.141&tr2=1.142&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer_connect.hpp.diff?tr1=1.36&tr2=1.37&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer_ui.cpp.diff?tr1=1.21&tr2=1.22&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer_ui.hpp.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer_wait.cpp.diff?tr1=1.24&tr2=1.25&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer_wait.hpp.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playlevel.cpp.diff?tr1=1.202&tr2=1.203&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playlevel.hpp.diff?tr1=1.22&tr2=1.23&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit.cpp.diff?tr1=1.145&tr2=1.146&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/server/game.cpp.diff?tr1=1.31&tr2=1.32&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/server/game.hpp.diff?tr1=1.17&tr2=1.18&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/server/server.cpp.diff?tr1=1.77&tr2=1.78&r1=text&r2=text

Patches:
Index: wesnoth/src/Makefile.am
diff -u wesnoth/src/Makefile.am:1.93 wesnoth/src/Makefile.am:1.94
--- wesnoth/src/Makefile.am:1.93        Sat Apr 23 12:13:10 2005
+++ wesnoth/src/Makefile.am     Wed Apr 27 21:11:44 2005
@@ -81,6 +81,7 @@
        network_worker.cpp \
        pathfind.cpp \
        pathutils.cpp \
+       playcampaign.cpp \
        playlevel.cpp \
        playturn.cpp \
        preferences.cpp \
@@ -175,6 +176,7 @@
        network_worker.hpp \
        pathfind.hpp \
        pathutils.hpp \
+       playcampaign.hpp \
        playlevel.hpp \
        playturn.hpp \
        preferences.hpp \
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.238 wesnoth/src/game.cpp:1.239
--- wesnoth/src/game.cpp:1.238  Sun Apr 24 19:15:36 2005
+++ wesnoth/src/game.cpp        Wed Apr 27 21:11:44 2005
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.238 2005/04/24 19:15:36 isaaccp Exp $ */
+/* $Id: game.cpp,v 1.239 2005/04/27 21:11:44 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -39,7 +39,7 @@
 #include "multiplayer.hpp"
 #include "network.hpp"
 #include "pathfind.hpp"
-#include "playlevel.hpp"
+#include "playcampaign.hpp"
 #include "preferences.hpp"
 #include "publish_campaign.hpp"
 #include "replay.hpp"
@@ -73,156 +73,6 @@
 #include <sstream>
 #include <string>
 
-LEVEL_RESULT play_game(display& disp, game_state& state, config& game_config,
-                                      game_data& units_data, CVideo& video)
-{
-       std::string type = state.campaign_type;
-       if(type.empty())
-               type = "scenario";
-
-       config* scenario = NULL;
-
-       //'starting_pos' will contain the position we start the game from.
-       config starting_pos;
-
-       recorder.set_save_info(state);
-
-       //see if we load the scenario from the scenario data -- if there is
-       //no snapshot data available from a save, or if the user has selected
-       //to view the replay from scratch
-       if(state.snapshot.child("side") == NULL || !recorder.at_end()) {
-               //if the starting state is specified, then use that,
-               //otherwise get the scenario data and start from there.
-               if(state.starting_pos.empty() == false) {
-                       std::cerr << "loading starting position...\n";
-                       starting_pos = state.starting_pos;
-                       scenario = &starting_pos;
-               } else {
-                       std::cerr << "loading scenario: '" << state.scenario << 
"'\n";
-                       scenario = 
game_config.find_child(type,"id",state.scenario);
-                       std::cerr << "scenario found: " << (scenario != NULL ? 
"yes" : "no") << "\n";
-               }
-       } else {
-               std::cerr << "loading snapshot...\n";
-               //load from a save-snapshot.
-               starting_pos = state.snapshot;
-               scenario = &starting_pos;
-               state = read_game(units_data,&state.snapshot);
-       }
-
-       while(scenario != NULL) {
-
-               const config::child_list& story = 
scenario->get_children("story");
-               const std::string current_scenario = state.scenario;
-
-               bool save_game_after_scenario = true;
-
-               try {
-                       state.label = (*scenario)["name"];
-
-                       LEVEL_RESULT res = 
play_level(units_data,game_config,scenario,video,state,story);
-
-                       state.snapshot = config();
-
-                       //ask to save a replay of the game
-                       if(res == VICTORY || res == DEFEAT) {
-                               const std::string orig_scenario = 
state.scenario;
-                               state.scenario = current_scenario;
-
-                               std::string label = state.label + " replay";
-
-                               bool retry = true;
-
-                               while(retry) {
-                                       retry = false;
-
-                                       const int should_save = 
dialogs::get_save_name(disp,
-                                                                               
                _("Do you want to save a replay of this scenario?"),
-                                                                               
                _("Name:"),
-                                                                               
                &label);
-                                       if(should_save == 0) {
-                                               try {
-                                                       config snapshot;
-
-                                                       
recorder.save_game(label, snapshot, state.starting_pos);
-                                               } 
catch(game::save_game_failed&) {
-                                                       
gui::show_error_message(disp, _("The game could not be saved"));
-                                                       retry = true;
-                                               };
-                                       }
-                               }
-
-                               state.scenario = orig_scenario;
-                       }
-
-                       recorder.clear();
-                       state.replay_data.clear();
-
-                       //continue without saving is like a victory, but the 
save game dialog isn't displayed
-                       if(res == LEVEL_CONTINUE_NO_SAVE) {
-                               res = VICTORY;
-                               save_game_after_scenario = false;
-                       }
-
-                       if(res != VICTORY) {
-                               return res;
-                       }
-               } catch(game::load_game_failed& e) {
-                       gui::show_error_message(disp, _("The game could not be 
loaded: ") + e.message);
-                       return QUIT;
-               } catch(game::game_error& e) {
-                       gui::show_error_message(disp, _("Error while playing 
the game: ") + e.message);
-                       return QUIT;
-               } catch(gamemap::incorrect_format_exception& e) {
-                       gui::show_error_message(disp, std::string(_("The game 
map could not be loaded: ")) + e.msg_);
-                       return QUIT;
-               }
-
-               //if the scenario hasn't been set in-level, set it now.
-               if(state.scenario == current_scenario)
-                       state.scenario = (*scenario)["next_scenario"];
-
-               scenario = game_config.find_child(type,"id",state.scenario);
-
-               //if this isn't the last scenario, then save the game
-               if(scenario != NULL && save_game_after_scenario) {
-                       state.label = (*scenario)["name"];
-                       state.starting_pos = config();
-
-                       bool retry = true;
-
-                       while(retry) {
-                               retry = false;
-
-                               const int should_save = 
dialogs::get_save_name(disp,
-                                                                               
                        _("Do you want to save your game?"),
-                                                                               
                        _("Name:"),
-                                                                               
                        &state.label);
-
-                               if(should_save == 0) {
-                                       try {
-                                               save_game(state);
-                                       } catch(game::save_game_failed&) {
-                                               gui::show_error_message(disp, 
_("The game could not be saved"));
-                                               retry = true;
-                                       }
-                               }
-                       }
-
-                       state.starting_pos = *scenario;
-               }
-
-               recorder.set_save_info(state);
-       }
-
-       if (!state.scenario.empty() && state.scenario != "null") {
-               gui::show_error_message(disp, _("Unknown scenario: '") + 
state.scenario + '\'');
-               return QUIT;
-       }
-
-       return VICTORY;
-}
-
 namespace {
 
 
@@ -719,7 +569,8 @@
        }
 
        try {
-               play_level(units_data_,game_config_,&level,video_,state_,story);
+               ::play_game(disp(),state_,game_config_,units_data_,video_);
+               
//play_level(units_data_,game_config_,&level,video_,state_,story);
        } catch(game::error& e) {
                std::cerr << "caught error: '" << e.message << "'\n";
        } catch(game::load_game_exception& e) {
@@ -835,46 +686,11 @@
        if(state_.campaign_type == "tutorial") {
                defines_map_["TUTORIAL"] = preproc_define();
        } else if(state_.campaign_type == "multiplayer") {
-               //make all network players local
                for(config::child_itors sides = 
state_.snapshot.child_range("side");
                    sides.first != sides.second; ++sides.first) {
                        if((**sides.first)["controller"] == "network")
                                (**sides.first)["controller"] = "human";
                }
-               //make all network players local, even in the replay starting 
pos, if any
-               for(config::child_itors sides = 
state_.starting_pos.child_range("side");
-                   sides.first != sides.second; ++sides.first) {
-                       if((**sides.first)["controller"] == "network")
-                               (**sides.first)["controller"] = "human";
-               }
-       
-               recorder.set_save_info(state_);
-               std::vector<config*> story;
-
-               config starting_pos;
-               if(recorder.at_end()) {
-                       starting_pos = state_.snapshot;
-                                // state.gold = -100000;
-               } else {
-                       starting_pos = state_.starting_pos;
-               }
-
-               try {
-                       
play_level(units_data_,game_config_,&starting_pos,video_,state_,story);
-                       recorder.clear();
-               } catch(game::load_game_failed& e) {
-                       gui::show_error_message(disp(), _("The game could not 
be loaded: ") + e.message);
-               } catch(game::game_error& e) {
-                       gui::show_error_message(disp(), _("Error while playing 
the game: ") + e.message);
-               } catch(game::load_game_exception& e) {
-                       //this will make it so next time through the title 
screen loop, this game is loaded
-                       loaded_game_ = e.game;
-                       loaded_game_show_replay_ = e.show_replay;
-               } catch(gamemap::incorrect_format_exception& e) {
-                       gui::show_error_message(disp(), std::string(_("The game 
map could not be loaded: ")) + e.msg_);
-               }
-
-               return false;
        }
 
        return true;
Index: wesnoth/src/gamestatus.cpp
diff -u wesnoth/src/gamestatus.cpp:1.70 wesnoth/src/gamestatus.cpp:1.71
--- wesnoth/src/gamestatus.cpp:1.70     Tue Apr  5 19:42:05 2005
+++ wesnoth/src/gamestatus.cpp  Wed Apr 27 21:11:44 2005
@@ -1,4 +1,4 @@
-/* $Id: gamestatus.cpp,v 1.70 2005/04/05 19:42:05 gruikya Exp $ */
+/* $Id: gamestatus.cpp,v 1.71 2005/04/27 21:11:44 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -97,7 +97,7 @@
 
 }
 
-gamestatus::gamestatus(config& time_cfg, int num_turns) :
+gamestatus::gamestatus(const config& time_cfg, int num_turns) :
                  turn_(1),numTurns_(num_turns)
 {
        const std::string& turn_at = time_cfg["turn_at"];
Index: wesnoth/src/gamestatus.hpp
diff -u wesnoth/src/gamestatus.hpp:1.44 wesnoth/src/gamestatus.hpp:1.45
--- wesnoth/src/gamestatus.hpp:1.44     Tue Apr  5 19:42:05 2005
+++ wesnoth/src/gamestatus.hpp  Wed Apr 27 21:11:44 2005
@@ -1,4 +1,4 @@
-/* $Id: gamestatus.hpp,v 1.44 2005/04/05 19:42:05 gruikya Exp $ */
+/* $Id: gamestatus.hpp,v 1.45 2005/04/27 21:11:44 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -49,7 +49,7 @@
 class gamestatus
 {
 public:
-       gamestatus(config& time_cfg, int num_turns);
+       gamestatus(const config& time_cfg, int num_turns);
        void write(config& cfg) const;
 
        const time_of_day& get_time_of_day() const;
@@ -79,15 +79,15 @@
        int numTurns_;
 };
 
-// Information on a particular player of the game.
+/** Information on a particular player of the game. */
 struct player_info
 {
        player_info():gold(-1) {}
 
-       int gold; //amount of gold the player has saved
-       std::vector<unit> available_units; //units the player may recall
+       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::set<std::string> can_recruit; /** < units the player has the 
ability to recruit */
 };
 
 //object which holds all the data needed to start a scenario.
@@ -132,10 +132,6 @@
        //the scenario, so we save the starting state of the game here.
        config starting_pos;
 
-       //information about the starting conditions of the scenario. Used in
-       //multiplayer games, when the starting position isn't just literally
-       //read from a file, since there is game setup information.
-
        //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
        config snapshot;
Index: wesnoth/src/multiplayer.cpp
diff -u wesnoth/src/multiplayer.cpp:1.157 wesnoth/src/multiplayer.cpp:1.158
--- wesnoth/src/multiplayer.cpp:1.157   Sun Apr 24 21:31:29 2005
+++ wesnoth/src/multiplayer.cpp Wed Apr 27 21:11:44 2005
@@ -1,4 +1,4 @@
-/* $Id: multiplayer.cpp,v 1.157 2005/04/24 21:31:29 gruikya Exp $ */
+/* $Id: multiplayer.cpp,v 1.158 2005/04/27 21:11:44 gruikya Exp $ */
 /*
    Copyright (C)
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -23,7 +23,7 @@
 #include "multiplayer_lobby.hpp"
 #include "multiplayer_create.hpp"
 #include "network.hpp"
-#include "playlevel.hpp"
+#include "playcampaign.hpp"
 #include "preferences.hpp"
 #include "random.hpp"
 #include "replay.hpp"
@@ -234,7 +234,6 @@
 void enter_wait_mode(display& disp, const config& game_config, game_data& 
data, mp::chat& chat, config& gamelist, bool observe)
 {
        mp::ui::result res;
-       config level;
        game_state state;
        network_game_manager m;
 
@@ -251,14 +250,14 @@
 
                if (res == mp::ui::PLAY) {
                        ui.start_game();
-                       level = ui.get_level();
+
                        state = ui.get_state();
                }
        }
 
        switch (res) {
        case mp::ui::PLAY:
-               play_level(data, game_config, &level, disp.video(), state, 
std::vector<config*>());
+               play_game(disp, state, game_config, data, disp.video(), 
IO_CLIENT);
                recorder.clear();
 
                break;
@@ -273,7 +272,6 @@
                mp::controller default_controller, bool is_server)
 {
        mp::ui::result res;
-       config level;
        game_state state;
        const network::manager net_manager;
        const network::server_manager serv_manager(15000, is_server ? 
@@ -294,14 +292,13 @@
                // so it must be called before get_level() 
                if (res == mp::ui::PLAY) {
                        ui.start_game();
-                       level = ui.get_level();
                        state = ui.get_state();
                }
        }
 
        switch (res) {
        case mp::ui::PLAY:
-               play_level(data, game_config, &level, disp.video(), state, 
std::vector<config*>());
+               play_game(disp, state, game_config, data, disp.video(), 
IO_SERVER);
                recorder.clear();
 
                break;
Index: wesnoth/src/multiplayer.hpp
diff -u wesnoth/src/multiplayer.hpp:1.26 wesnoth/src/multiplayer.hpp:1.27
--- wesnoth/src/multiplayer.hpp:1.26    Wed Mar  9 09:32:10 2005
+++ wesnoth/src/multiplayer.hpp Wed Apr 27 21:11:44 2005
@@ -1,6 +1,6 @@
-/* $Id: multiplayer.hpp,v 1.26 2005/03/09 09:32:10 ydirson Exp $ */
+/* $Id: multiplayer.hpp,v 1.27 2005/04/27 21:11:44 gruikya Exp $ */
 /*
-   Copyright (C)
+   Copyright (C) 2005 Philippe Plantier <address@hidden>
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
 
    This program is free software; you can redistribute it and/or modify
@@ -13,19 +13,36 @@
 #ifndef MULTIPLAYER_HPP_INCLUDED
 #define MULTIPLAYER_HPP_INCLUDED
 
-#include "display.hpp"
-#include "config.hpp"
-#include "multiplayer_connect.hpp"
-#include "unit_types.hpp"
+#include "multiplayer_ui.hpp"
+
+class config;
+class display;
+struct game_data;
 
 namespace mp {
-       
-/**
+
+/*
  * This is the main entry points of multiplayer mode.
  */
+
+/** Starts a multiplayer game in server mode, or in single-user mode.
+ *
+ * @param disp        The global display 
+ * @param game_config The global, top-level WML configuration for the game
+ * @param data        The global game data (unit types, etc)
+ * @param default_controller The default controller type
+ * @param is_server   Whether to open a port to the outside, or not.
+ */
 void start_server(display& disp, const config& game_config, game_data& data,
                mp::controller default_controller, bool is_server);
 
+/** Starts a multiplayer game in client mode.
+ *
+ * @param disp        The global display 
+ * @param game_config The global, top-level WML configuration for the game
+ * @param data        The global game data (unit types, etc)
+ * @param host        The host to connect to.
+ */
 void start_client(display& disp, const config& game_config, game_data& data, 
                const std::string host);
 
Index: wesnoth/src/multiplayer_connect.cpp
diff -u wesnoth/src/multiplayer_connect.cpp:1.141 
wesnoth/src/multiplayer_connect.cpp:1.142
--- wesnoth/src/multiplayer_connect.cpp:1.141   Sun Apr 24 12:17:56 2005
+++ wesnoth/src/multiplayer_connect.cpp Wed Apr 27 21:11:44 2005
@@ -1,4 +1,4 @@
-/* $Id: multiplayer_connect.cpp,v 1.141 2005/04/24 12:17:56 silene Exp $ */
+/* $Id: multiplayer_connect.cpp,v 1.142 2005/04/27 21:11:44 gruikya Exp $ */
 /*
    Copyright (C) 
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -20,7 +20,6 @@
 #include "log.hpp"
 #include "multiplayer_connect.hpp"
 #include "preferences.hpp"
-#include "replay.hpp"
 #include "statistics.hpp"
 #include "show_dialog.hpp"
 #include "wassert.hpp"
@@ -501,6 +500,8 @@
        network::send_data(response);
 
        load_game();
+       if(get_result() == QUIT)
+               return;
        lists_init();
 
        // Adds the current user as default user.
@@ -571,11 +572,6 @@
        }
 }
 
-const config& connect::get_level()
-{
-       return level_;
-}
-
 const game_state& connect::get_state()
 {
        return state_;
@@ -594,23 +590,15 @@
        lock.add_child("stop_updates");
        network::send_data(lock);
 
-       // Replays the level
-       recorder.set_save_info(state_);
-       recorder.set_skip(-1);
-       level_.clear_children("replay");
-
        // Re-sends the whole level
        update_and_send_diff();
 
-       // This must be done after updating level_
-       state_.snapshot = level_;
-       state_.starting_pos = level_;
-       state_.players.clear();
+       // Build the gamestate object after updating the level
+       level_to_gamestate(level_, state_);
 
        config cfg;
        cfg.add_child("start_game");
        network::send_data(cfg);
-
 }
 
 void connect::hide_children(bool hide)
@@ -878,13 +866,14 @@
                        return;
                }
                
-               //state_.players.clear();
                std::string error_log;
                ::load_game(game_data_, game, state_, &error_log);
                if(!error_log.empty()) {
                        gui::show_error_message(disp(), 
                                        _("The file you have tried to load is 
corrupt: '") +
                                        error_log);
+                       set_result(QUIT);
+                       return;
                }
 
                if(state_.campaign_type != "multiplayer") {
@@ -905,23 +894,15 @@
                }
 
                level_ = state_.snapshot;
-               level_.add_child("statistics") = statistics::write_stats();
 
-               recorder = replay(state_.replay_data);
+               // Adds the replay data, and the replay start, to the level, so
+               // clients can receive it.
+               level_.add_child("replay") = state_.replay_data;
+               if(!state_.starting_pos.empty())
+                       level_.add_child("replay_start") = state_.starting_pos;
+
+               level_.add_child("statistics") = statistics::write_stats();
 
-               //if this is a snapshot save, we don't want to use the replay 
data
-               if(level_["snapshot"] == "yes") {
-                       config* const start = level_.child("start");
-                       if(start != NULL)
-                               start->clear_children("replay");
-                       level_.clear_children("replay");
-                       recorder.set_to_end();
-               } else {
-                       //add the replay data under the level data so clients 
can
-                       //receive it
-                       level_.clear_children("replay");
-                       level_.add_child("replay") = state_.replay_data;
-               }
        } else {
                level_ = params_.scenario_data;
                level_["turns"] = 
lexical_cast_default<std::string>(params_.num_turns, "20");
@@ -937,17 +918,13 @@
                        throw config::error(vgettext("Cannot find era $era", 
i18n_symbols));
                }
                era_sides_ = era_cfg->get_children("multiplayer_side");
+               level_["scenario"] = params_.name;
                level_.add_child("era", *era_cfg);
        }
 
        //this will force connecting clients to be using the same version 
number as us.
        level_["version"] = game_config::version;
 
-       state_.label = level_["name"];
-       state_.players.clear();
-       level_["scenario"] = state_.scenario = params_.name;
-       state_.campaign_type = "multiplayer";
-
        if(!params_.saved_game) 
                level_["experience_modifier"] = 
lexical_cast<std::string>(params_.xp_modifier);
 
Index: wesnoth/src/multiplayer_connect.hpp
diff -u wesnoth/src/multiplayer_connect.hpp:1.36 
wesnoth/src/multiplayer_connect.hpp:1.37
--- wesnoth/src/multiplayer_connect.hpp:1.36    Sat Apr  2 10:36:12 2005
+++ wesnoth/src/multiplayer_connect.hpp Wed Apr 27 21:11:44 2005
@@ -1,4 +1,4 @@
-/* $Id: multiplayer_connect.hpp,v 1.36 2005/04/02 10:36:12 gruikya Exp $ */
+/* $Id: multiplayer_connect.hpp,v 1.37 2005/04/27 21:11:44 gruikya Exp $ */
 /*
    Copyright (C) 
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -25,8 +25,6 @@
 
 namespace mp {
 
-enum controller { CNTR_NETWORK = 0, CNTR_LOCAL, CNTR_COMPUTER, CNTR_EMPTY, 
CNTR_LAST };
-
 class connect : public mp::ui
 {
 public:
@@ -137,12 +135,14 @@
 
        virtual void process_event();
 
-       // Returns the level data useful to play the game
-       const config& get_level();
+       /** Returns the game state, which contains all information about the
+        * current scenario.
+        */
        const game_state& get_state();
 
-       // Updates the current level, resolves random factions, and sends a
-       // "start game" message to the network, with the current level
+       /** Updates the current game state, resolves random factions, and sends
+        * a "start game" message to the network.
+        */
        void start_game();
 
 protected:
@@ -190,16 +190,13 @@
        // This is the main, and global, game data.
        const game_data& game_data_;
 
-       // This is the configuration object which represents the level which
-       // will be generated by configuring this multiplayer game.
        config level_;
 
-       create::parameters params_;
-
-       // This is the "game state" object, which is constructed along with the
-       // "level" object
+       // This is the "game state" object which is created by this dialog.
        game_state state_;
 
+       create::parameters params_;
+
        // The list of available sides for the current era
        config::child_list era_sides_;
 
Index: wesnoth/src/multiplayer_ui.cpp
diff -u wesnoth/src/multiplayer_ui.cpp:1.21 wesnoth/src/multiplayer_ui.cpp:1.22
--- wesnoth/src/multiplayer_ui.cpp:1.21 Sun Apr 24 19:15:36 2005
+++ wesnoth/src/multiplayer_ui.cpp      Wed Apr 27 21:11:44 2005
@@ -1,6 +1,6 @@
-/* $Id: multiplayer_ui.cpp,v 1.21 2005/04/24 19:15:36 isaaccp Exp $ */
+/* $Id: multiplayer_ui.cpp,v 1.22 2005/04/27 21:11:44 gruikya Exp $ */
 /*
-   Copyright (C) 
+   Copyright (C) 2005 
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
 
    This program is free software; you can redistribute it and/or modify
@@ -22,6 +22,7 @@
 #include "network.hpp"
 #include "sound.hpp"
 #include "video.hpp"
+#include "replay.hpp"
 
 #define LOG_NW LOG_STREAM(info, network)
 #define ERR_NW LOG_STREAM(err, network)
@@ -40,6 +41,33 @@
        }
 }
 
+void level_to_gamestate(config& level, game_state& state)
+{
+       //any replay data is only temporary and should be removed from
+       //the level data in case we want to save the game later
+       config * const replay_data = level.child("replay");
+       config replay_data_store;
+       if(replay_data != NULL) {
+               replay_data_store = *replay_data;
+               LOG_NW << "setting replay\n";
+               recorder = replay(replay_data_store);
+               if(!recorder.empty()) {
+                       recorder.set_skip(-1);
+               }
+
+               level.clear_children("replay");
+       }
+
+       //adds the starting pos to the level
+       if(level.child("replay_start") == NULL)
+               level.add_child("replay_start") = level;
+
+       level["campaign_type"] = "multiplayer";
+       state.campaign_type = "multiplayer";
+       state.snapshot = level;
+
+}
+
 std::string get_colour_string(int id)
 {
        std::string prefix(" ");
Index: wesnoth/src/multiplayer_ui.hpp
diff -u wesnoth/src/multiplayer_ui.hpp:1.8 wesnoth/src/multiplayer_ui.hpp:1.9
--- wesnoth/src/multiplayer_ui.hpp:1.8  Thu Apr 14 18:44:05 2005
+++ wesnoth/src/multiplayer_ui.hpp      Wed Apr 27 21:11:44 2005
@@ -1,4 +1,4 @@
-/* $Id: multiplayer_ui.hpp,v 1.8 2005/04/14 18:44:05 gruikya Exp $ */
+/* $Id: multiplayer_ui.hpp,v 1.9 2005/04/27 21:11:44 gruikya Exp $ */
 /*
    Copyright (C) 
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -13,8 +13,6 @@
 #ifndef MULTIPLAYER_UI_HPP_INCLUDED
 #define MULTIPLAYER_UI_HPP_INCLUDED
 
-class display;
-
 #include "config.hpp"
 #include "hotkeys.hpp"
 #include "network.hpp"
@@ -26,10 +24,17 @@
 #include <deque>
 #include <string>
 
+class display;
+struct game_state;
+
 namespace mp {
 
+enum controller { CNTR_NETWORK = 0, CNTR_LOCAL, CNTR_COMPUTER, CNTR_EMPTY, 
CNTR_LAST };
+
 void check_response(network::connection res, const config& data);
 
+void level_to_gamestate(config& level, game_state& state);
+
 std::string get_colour_string(int id);
 
 //this class memorizes a chat session.
Index: wesnoth/src/multiplayer_wait.cpp
diff -u wesnoth/src/multiplayer_wait.cpp:1.24 
wesnoth/src/multiplayer_wait.cpp:1.25
--- wesnoth/src/multiplayer_wait.cpp:1.24       Sun Apr 17 13:43:13 2005
+++ wesnoth/src/multiplayer_wait.cpp    Wed Apr 27 21:11:44 2005
@@ -1,4 +1,4 @@
-/* $Id: multiplayer_wait.cpp,v 1.24 2005/04/17 13:43:13 gruikya Exp $ */
+/* $Id: multiplayer_wait.cpp,v 1.25 2005/04/27 21:11:44 gruikya Exp $ */
 /*
    Copyright (C) 
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -18,7 +18,6 @@
 #include "log.hpp"
 #include "multiplayer_wait.hpp"
 #include "preferences.hpp"
-#include "replay.hpp"
 #include "statistics.hpp"
 #include "util.hpp"
 #include "video.hpp"
@@ -251,53 +250,17 @@
        return state_;
 }
 
-const config& wait::get_level()
-{
-       return level_;
-}
-
 void wait::start_game() 
 {
-       const config::child_list& sides_list = level_.get_children("side");
-       for(config::child_list::const_iterator side = sides_list.begin(); 
-                       side != sides_list.end(); ++side) {
-               if((**side)["controller"] == "network" && 
(**side)["description"] == preferences::login()) {
-                       (**side)["controller"] = preferences::client_type();
-               } else if((**side)["controller"] != "null") {
-                       (**side)["controller"] = "network";
-               }
-       }
-
-       //any replay data is only temporary and should be removed from
-       //the level data in case we want to save the game later
-       config* const replay_data = level_.child("replay");
-       config replay_data_store;
-       if(replay_data != NULL) {
-               replay_data_store = *replay_data;
-               LOG_NW << "setting replay\n";
-               recorder = replay(replay_data_store);
-               if(!recorder.empty()) {
-                       recorder.set_skip(-1);
-               }
-
-               level_.clear_children("replay");
-       }
-
        config const * const stats = level_.child("statistics");
        if(stats != NULL) {
                statistics::fresh_stats();
                statistics::read_stats(*stats);
        }
 
-       LOG_NW << "starting game\n";
+       level_to_gamestate(level_, state_);
 
-       state_.campaign_type = "multiplayer";
-       state_.label = level_["name"];
-       state_.scenario = level_["id"];
-       state_.starting_pos = level_;
-       state_.snapshot = level_;
-       state_.players.clear();
-       recorder.set_save_info(state_);
+       LOG_NW << "starting game\n";
 }
 
 void wait::layout_children(const SDL_Rect& rect)
Index: wesnoth/src/multiplayer_wait.hpp
diff -u wesnoth/src/multiplayer_wait.hpp:1.4 
wesnoth/src/multiplayer_wait.hpp:1.5
--- wesnoth/src/multiplayer_wait.hpp:1.4        Wed Mar 30 19:48:17 2005
+++ wesnoth/src/multiplayer_wait.hpp    Wed Apr 27 21:11:44 2005
@@ -1,4 +1,4 @@
-/* $Id: multiplayer_wait.hpp,v 1.4 2005/03/30 19:48:17 gruikya Exp $ */
+/* $Id: multiplayer_wait.hpp,v 1.5 2005/04/27 21:11:44 gruikya Exp $ */
 /*
    Copyright (C) 
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -35,7 +35,6 @@
        void join_game(bool observe);
 
        const game_state& get_state();
-       const config& get_level();
 
        void start_game();
 
Index: wesnoth/src/playlevel.cpp
diff -u wesnoth/src/playlevel.cpp:1.202 wesnoth/src/playlevel.cpp:1.203
--- wesnoth/src/playlevel.cpp:1.202     Mon Apr 18 19:59:00 2005
+++ wesnoth/src/playlevel.cpp   Wed Apr 27 21:11:44 2005
@@ -1,4 +1,4 @@
-/* $Id: playlevel.cpp,v 1.202 2005/04/18 19:59:00 gruikya Exp $ */
+/* $Id: playlevel.cpp,v 1.203 2005/04/27 21:11:44 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -122,7 +122,7 @@
 }
 
 LEVEL_RESULT play_level(const game_data& gameinfo, const config& game_config,
-               config* level, CVideo& video,
+               config const* level, CVideo& video,
                game_state& state_of_game,
                const std::vector<config*>& story)
 {
@@ -262,6 +262,15 @@
 
                teams.push_back(team(**ui,ngold));
 
+               //update/fix the recall list for this side, by setting the
+               //"side" of each unit in it to be the "side" of the player.
+               int side = lexical_cast_default<int>((**ui)["side"], 1);
+               if(player != NULL) {
+                       for(std::vector<unit>::iterator it = 
player->available_units.begin(); it != player->available_units.end(); ++it) {
+                               it->set_side(side);
+                       }
+               }
+
                //if this team has no objectives, set its objectives to the
                //level-global "objectives"
                if(teams.back().objectives().empty())
@@ -289,7 +298,7 @@
                        gamemap::location start_pos(**ui);
 
                        if(has_loc.empty()) {
-                               start_pos = 
map.starting_position(new_unit.side());
+                               start_pos = map.starting_position(side);
                                LOG_NG << "initializing side '" << 
(**ui)["side"] << "' at "
                                       << start_pos.x << "," << start_pos.y << 
"\n";
                        }
@@ -324,7 +333,7 @@
                for(config::child_list::const_iterator su = 
starting_units.begin(); su != starting_units.end(); ++su) {
                        unit new_unit(gameinfo,**su);
 
-                       
new_unit.set_side(lexical_cast_default<int>((**ui)["side"],1));
+                       new_unit.set_side(side);
 
                        const std::string& x = (**su)["x"];
                        const std::string& y = (**su)["y"];
Index: wesnoth/src/playlevel.hpp
diff -u wesnoth/src/playlevel.hpp:1.22 wesnoth/src/playlevel.hpp:1.23
--- wesnoth/src/playlevel.hpp:1.22      Tue Mar 22 23:42:36 2005
+++ wesnoth/src/playlevel.hpp   Wed Apr 27 21:11:44 2005
@@ -1,4 +1,4 @@
-/* $Id: playlevel.hpp,v 1.22 2005/03/22 23:42:36 ydirson Exp $ */
+/* $Id: playlevel.hpp,v 1.23 2005/04/27 21:11:44 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -38,7 +38,7 @@
 };
 
 LEVEL_RESULT play_level(const game_data& gameinfo, const config& 
terrain_config,
-               config* level, CVideo& video,
+               config const* level, CVideo& video,
                game_state& state_of_game,
                const std::vector<config*>& story);
 
Index: wesnoth/src/server/game.cpp
diff -u wesnoth/src/server/game.cpp:1.31 wesnoth/src/server/game.cpp:1.32
--- wesnoth/src/server/game.cpp:1.31    Sat Mar  5 10:54:25 2005
+++ wesnoth/src/server/game.cpp Wed Apr 27 21:11:44 2005
@@ -535,6 +535,11 @@
        history_.append(data);
 }
 
+void game::reset_history()
+{
+       history_.clear();
+}
+
 bool game::level_init() const
 {
        return level_.child("side") != NULL;
Index: wesnoth/src/server/game.hpp
diff -u wesnoth/src/server/game.hpp:1.17 wesnoth/src/server/game.hpp:1.18
--- wesnoth/src/server/game.hpp:1.17    Sun Feb 20 22:30:29 2005
+++ wesnoth/src/server/game.hpp Wed Apr 27 21:11:44 2005
@@ -58,6 +58,7 @@
        void send_data_observers(const config& data);
 
        void record_data(const config& data);
+       void reset_history();
 
        //the full scenario data
        bool level_init() const;
Index: wesnoth/src/server/server.cpp
diff -u wesnoth/src/server/server.cpp:1.77 wesnoth/src/server/server.cpp:1.78
--- wesnoth/src/server/server.cpp:1.77  Sun Apr 17 14:35:15 2005
+++ wesnoth/src/server/server.cpp       Wed Apr 27 21:11:44 2005
@@ -684,6 +684,22 @@
                return;
        }
 
+       //if this is data telling us that the scenario did change.
+       else if(g->is_owner(sock) && data.child("next_scenario") != NULL) {
+               config* scenario = data.child("next_scenario");
+
+               if(g->level_init()) {
+                       g->level() = *scenario;
+                       g->reset_history();
+                       g->update_side_data();
+               } else {
+                       // next_scenario sent while the scenario was not
+                       // initialized. Something's broken here.
+                       std::cerr << "Error: next_scenario sent while the 
scenario is not yet initialized";
+                       return;
+               }
+       }
+
        const string_map::const_iterator side = data.values.find("side");
        if(side != data.values.end()) {
                const bool res = g->take_side(sock,data);
Index: wesnoth/src/unit.cpp
diff -u wesnoth/src/unit.cpp:1.145 wesnoth/src/unit.cpp:1.146
--- wesnoth/src/unit.cpp:1.145  Sat Apr 23 22:14:52 2005
+++ wesnoth/src/unit.cpp        Wed Apr 27 21:11:44 2005
@@ -1,4 +1,4 @@
-/* $Id: unit.cpp,v 1.145 2005/04/23 22:14:52 silene Exp $ */
+/* $Id: unit.cpp,v 1.146 2005/04/27 21:11:44 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -26,6 +26,10 @@
 #include "wassert.hpp"
 #include "serialization/string_utils.hpp"
 
+//DEBUG
+#include <iostream>
+#include <serialization/parser.hpp>
+
 #include <algorithm>
 #include <cstdlib>
 #include <iostream>
@@ -600,10 +604,13 @@
 void unit::read(const game_data& data, const config& cfg)
 {
        std::map<std::string,unit_type>::const_iterator i = 
data.unit_types.find(cfg["type"]);
-       if(i != data.unit_types.end())
+       if(i != data.unit_types.end()) {
                type_ = &i->second;
-       else
+       } else {
+               //DEBUG
+               ::write(std::cerr, cfg);
                throw game::load_game_failed("Unit not found: '" + cfg["type"] 
+ "'");
+       }
 
        wassert(type_ != NULL);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]