[Wesnoth-cvs-commits] wesnoth/src multiplayer_connect.cpp multiplayer... (February 21, 2005 - 22:58)

 

CVSROOT:	/cvsroot/wesnoth
Module name:	wesnoth
Branch: 	
Changes by:	Philippe Plantier <gruikya@xxxxxxxxxxxxxxxx>	05/02/21 21:33:28

Modified files:
	src            : multiplayer_connect.cpp multiplayer_connect.hpp 
	                 multiplayer_create.cpp multiplayer_create.hpp 

Log message:
	Fixed bug #12060: multiplayer_game parameters not being saved, and not working at all.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer_connect.cpp.diff?tr1=1.108&tr2=1.109&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer_connect.hpp.diff?tr1=1.26&tr2=1.27&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer_create.cpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer_create.hpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: wesnoth/src/multiplayer_connect.cpp
diff -u wesnoth/src/multiplayer_connect.cpp:1.108 wesnoth/src/multiplayer_connect.cpp:1.109
--- wesnoth/src/multiplayer_connect.cpp:1.108	Mon Feb 21 09:05:51 2005
+++ wesnoth/src/multiplayer_connect.cpp	Mon Feb 21 21:33:27 2005
@@ -1,4 +1,4 @@
-/* $Id: multiplayer_connect.cpp,v 1.108 2005/02/21 09:05:51 silene Exp $ */
+/* $Id: multiplayer_connect.cpp,v 1.109 2005/02/21 21:33:27 gruikya Exp $ */
 /*
    Copyright (C) 
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -37,8 +37,7 @@
 
 namespace mp {
 
-connect::side::side(connect& parent, const config& cfg, int index, int default_gold,
-		bool enabled) :
+connect::side::side(connect& parent, const config& cfg, int index) :
 	parent_(&parent),
 
 	cfg_(cfg),
@@ -59,17 +58,17 @@
 
 	llm_(parent.era_sides_, &parent.game_data_, &combo_leader_),
 
-	enabled_(enabled),
+	enabled_(!parent_->params_.saved_game),
 	changed_(false)
 {
 	SDL_Rect r;
-	r.w = 64;
+	r.w = 120;
 	r.h = 16;
 
 	slider_gold_.set_min(20);
 	slider_gold_.set_max(1000);
 	slider_gold_.set_increment(25);
-	slider_gold_.set_value(lexical_cast_default<int>(cfg_["gold"], default_gold));
+	slider_gold_.set_value(lexical_cast_default<int>(cfg_["gold"], 100));
 	slider_gold_.set_location(r);
 
 	combo_faction_.enable(enabled_);
@@ -83,7 +82,7 @@
 	faction_ = lexical_cast_default<int>(cfg_["team"], 0);
 	team_ = lexical_cast_default<int>(cfg_["team"], index_);
 	colour_ = lexical_cast_default<int>(cfg_["colour"], index_);
-	gold_ = lexical_cast_default<int>(cfg_["gold"], default_gold);
+	gold_ = lexical_cast_default<int>(cfg_["gold"], 100);
 
 	// "Faction name" hack
 	if (!enabled_) {
@@ -277,11 +276,18 @@
 		} else {
 			res["type"] = leader_;
 		}
-		res["team"] = lexical_cast<std::string>(team_);
+		// res["team"] = lexical_cast<std::string>(team_);
 		res["team_name"] = lexical_cast<std::string>(team_ + 1);
 		res["colour"] = lexical_cast<std::string>(colour_);
 		res["gold"] = lexical_cast<std::string>(gold_);
 
+		res["fog"] = parent_->params_.fog_game ? "yes" : "no";
+		res["shroud"] = parent_->params_.shroud_game ? "yes" : "no";
+		res["share_maps"] = parent_->params_.share_maps ? "yes" : "no";
+		res["share_view"] =  parent_->params_.share_view ? "yes" : "no";
+		res["village_gold"] = lexical_cast<std::string>(parent_->params_.village_gold);
+		res["experience_modifier"] = lexical_cast<std::string>(parent_->params_.xp_modifier);
+
 		res["allow_changes"] = "yes";
 	} else {
 		res["allow_changes"] = "no";
@@ -411,6 +417,8 @@
 	mp::ui(disp, game_config, c, gamelist),
 
 	game_data_(data),
+	level_(),
+	params_(params),
 
 	waiting_label_(disp, _("")),
 	message_full_(false),
@@ -433,8 +441,8 @@
 	create_game["name"] = params.name;
 	network::send_data(response);
 
-	load_game(params);
-	lists_init(!params.saved_game);
+	load_game();
+	lists_init();
 
 	// Adds the current user as default user.
 	users_.push_back(connected_user(preferences::login(), CNTR_LOCAL, 0));
@@ -755,7 +763,7 @@
 	scroll_pane_.set_location(scroll_pane_rect);
 }
 
-void connect::lists_init(bool changes_allowed)
+void connect::lists_init()
 {
 	//Options
 	player_types_.push_back(_("Network Player"));
@@ -817,7 +825,7 @@
 	sides_.reserve(sides.second - sides.first);
 	int index = 0;
 	for(sd = sides.first; sd != sides.second; ++sd, ++index) {
-		sides_.push_back(side(*this, **sd, index, 100, changes_allowed));
+		sides_.push_back(side(*this, **sd, index));
 	}
 	// This function must be called after the sides_ vector is fully populated.
 	for(side_list::iterator s = sides_.begin(); s != sides_.end(); ++s) {
@@ -829,9 +837,9 @@
 }
 
 // Called by the constructor to initialize the game from a create::parameters structure.
-void connect::load_game(const create::parameters& params)
+void connect::load_game()
 {
-	if(params.saved_game) {
+	if(params_.saved_game) {
 		bool show_replay = false;
 		const std::string game = dialogs::load_game_dialog(disp(), game_config(), game_data_, &show_replay);
 		if(game.empty()) {
@@ -880,13 +888,13 @@
 		// Gets the era from the era of the savegame
 		era_ = level_["era"];
 		if(era_.empty())
-			era_ = params.era;
+			era_ = params_.era;
 
 	} else {
-		level_ = params.scenario_data;
-		level_["turns"] = lexical_cast_default<std::string>(params.num_turns, "20");
+		level_ = params_.scenario_data;
+		level_["turns"] = lexical_cast_default<std::string>(params_.num_turns, "20");
 
-		era_ = params.era;
+		era_ = params_.era;
 		level_["era"] = era_;
 	}
 	
@@ -902,10 +910,13 @@
 
 	state_.label = level_["name"];
 	state_.players.clear();
-	state_.scenario = params.name;
+	state_.scenario = params_.name;
 	state_.campaign_type = "multiplayer";
 
-	level_["observers"] = params.allow_observers ? "yes" : "no";
+	if(!params_.saved_game) 
+		level_["experience_modifier"] = lexical_cast<std::string>(params_.xp_modifier);
+
+	level_["observers"] = params_.allow_observers ? "yes" : "no";
 
 	if(level_["objectives"].empty()) {
 		level_["objectives"] = _("Victory\n\
Index: wesnoth/src/multiplayer_connect.hpp
diff -u wesnoth/src/multiplayer_connect.hpp:1.26 wesnoth/src/multiplayer_connect.hpp:1.27
--- wesnoth/src/multiplayer_connect.hpp:1.26	Mon Feb 21 00:37:28 2005
+++ wesnoth/src/multiplayer_connect.hpp	Mon Feb 21 21:33:27 2005
@@ -1,4 +1,4 @@
-/* $Id: multiplayer_connect.hpp,v 1.26 2005/02/21 00:37:28 Sirp Exp $ */
+/* $Id: multiplayer_connect.hpp,v 1.27 2005/02/21 21:33:27 gruikya Exp $ */
 /*
    Copyright (C) 
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -41,9 +41,7 @@
 
 	class side {
 	public:
-		side(connect& parent, const config& cfg,
-				int index, int default_gold,
-				bool enabled = true);
+		side(connect& parent, const config& cfg, int index);
 
 		side(const side& a);
 
@@ -124,9 +122,9 @@
 
 		bool enabled_;
 		bool changed_;
-	};
-
-	friend class side;
+	};
+
+	friend class side;
 
 	typedef std::vector<side> side_list;
 
@@ -158,11 +156,9 @@
 	virtual void gamelist_updated();
 private:
 	// Those 2 functions are actually the steps of the (complex)
-	// construction of this class. First, initialize default lists (for
-	// colours, sides, etc), then, load the game set the widgets values to
-	// the values given a the game creation step.
-	void lists_init(bool changes_allowes);
-	void load_game(const create::parameters& params);
+	// construction of this class.
+	void load_game();
+	void lists_init();
 
 	// Updates the level_ variable to reflect the sides in the sides_ vector
 	void update_level();
@@ -193,6 +189,8 @@
 	// 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
 	game_state state_;
Index: wesnoth/src/multiplayer_create.cpp
diff -u wesnoth/src/multiplayer_create.cpp:1.1 wesnoth/src/multiplayer_create.cpp:1.2
--- wesnoth/src/multiplayer_create.cpp:1.1	Sun Feb 20 22:46:38 2005
+++ wesnoth/src/multiplayer_create.cpp	Mon Feb 21 21:33:27 2005
@@ -1,4 +1,4 @@
-/* $Id: multiplayer_create.cpp,v 1.1 2005/02/20 22:46:38 gruikya Exp $ */
+/* $Id: multiplayer_create.cpp,v 1.2 2005/02/21 21:33:27 gruikya Exp $ */
 /*
    Copyright (C) 
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -66,31 +66,32 @@
 
 	//create the scenarios menu
 	maps_menu_.set_items(map_options_);
-	maps_menu_.move_selection(0);
+	if (preferences::map() < map_options_.size())
+		maps_menu_.move_selection(preferences::map());
 	maps_menu_.set_numeric_keypress_selection(false);
 
 	turns_slider_.set_min(20);
 	turns_slider_.set_max(100);
-	turns_slider_.set_value(50);
+	turns_slider_.set_value(preferences::turns());
 	turns_slider_.set_help_string(_("The maximum turns the game will go for"));
 
 	village_gold_slider_.set_min(1);
 	village_gold_slider_.set_max(5);
-	village_gold_slider_.set_value(1);
+	village_gold_slider_.set_value(preferences::village_gold());
 	village_gold_slider_.set_help_string(_("The amount of income each village yields per turn"));
 	xp_modifier_slider_.set_min(25);
 	xp_modifier_slider_.set_max(200);
-	xp_modifier_slider_.set_value(100);
+	xp_modifier_slider_.set_value(preferences::xp_modifier());
 	xp_modifier_slider_.set_increment(10);
 	xp_modifier_slider_.set_help_string(_("The amount of experience a unit needs to advance"));
 
-	fog_game_.set_check(false);
+	fog_game_.set_check(preferences::fog());
 	fog_game_.set_help_string(_("Enemy units cannot be seen unless they are in range of your units"));
 
-	shroud_game_.set_check(false);
+	shroud_game_.set_check(preferences::shroud());
 	shroud_game_.set_help_string(_("The map is unknown until your units explore it"));
 
-	observers_game_.set_check(true);
+	observers_game_.set_check(preferences::allow_observers());
 	observers_game_.set_help_string(_("Allow users who are not playing to watch the game"));
 
 	// The possible vision settings
@@ -113,7 +114,9 @@
 		throw config::error(_("No eras found"));
 	}
 	era_combo_.set_items(eras);
-	era_combo_.set_selected(0);
+
+	if (preferences::era() < eras.size())
+		era_combo_.set_selected(preferences::era());
 
 	string_map i18n_symbols;
 	i18n_symbols["login"] = preferences::login();
@@ -122,6 +125,21 @@
 	gamelist_updated();
 }
 
+create::~create()
+{
+	get_parameters();
+
+	//Save values for next game
+	preferences::set_allow_observers(parameters_.allow_observers);
+	preferences::set_fog(parameters_.fog_game);
+	preferences::set_shroud(parameters_.shroud_game);
+	preferences::set_turns(parameters_.num_turns);
+	preferences::set_village_gold(parameters_.village_gold);
+	preferences::set_xp_modifier(parameters_.xp_modifier);
+	preferences::set_era(era_combo_.selected()); // FIXME: may be broken if new eras are added
+	preferences::set_map(map_selection_);
+}
+
 create::parameters& create::get_parameters() 
 {
 	const config::child_list& era_list = game_config().get_children("era");
@@ -315,8 +333,8 @@
 	observers_game_.hide(hide);
 	cancel_game_.hide(hide);
 	launch_game_.hide(hide);
-	regenerate_map_.hide(hide);
-	generator_settings_.hide(hide);
+	regenerate_map_.hide(hide || generator_ == NULL);
+	generator_settings_.hide(hide || generator_ == NULL);
 
 	era_combo_.hide(hide);
 	vision_combo_.hide(hide);
@@ -379,8 +397,9 @@
 	maps_menu_.set_max_height(ca.x + ca.h - ypos);
 	maps_menu_.set_location(xpos, ypos);
 	// Menu dimensions are only updated when items are set. So do this now.
+	int mapsel_save = maps_menu_.selection();
 	maps_menu_.set_items(map_options_);
-	maps_menu_.move_selection(map_selection_);
+	maps_menu_.move_selection(mapsel_save);
 
 	// Third column: big buch of options
 	ypos = ypos_columntop + border_size;
Index: wesnoth/src/multiplayer_create.hpp
diff -u wesnoth/src/multiplayer_create.hpp:1.1 wesnoth/src/multiplayer_create.hpp:1.2
--- wesnoth/src/multiplayer_create.hpp:1.1	Sun Feb 20 22:46:38 2005
+++ wesnoth/src/multiplayer_create.hpp	Mon Feb 21 21:33:27 2005
@@ -1,4 +1,4 @@
-/* $Id: multiplayer_create.hpp,v 1.1 2005/02/20 22:46:38 gruikya Exp $ */
+/* $Id: multiplayer_create.hpp,v 1.2 2005/02/21 21:33:27 gruikya Exp $ */
 /*
    Copyright (C) 
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -61,6 +61,7 @@
 	};
 
 	create(display& dist, const config& game_config, chat& c, config& gamelist);
+	~create();
 
 	parameters& get_parameters();
 



You are on the gna.org mail server.

Generated by mhonarc, Tue Sep 20 16:46:54 2005