← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1736086-map-without-players into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1736086-map-without-players into lp:widelands.

Commit message:
New maps now have 0 players

- Initialize new maps with 0 players. Consistent use of Coords::null()
- Disable selection of maps with 0 players
- Automatically add first player to editor player menu for convenience


Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1736086 in widelands: "Editor: Saving a map with no player set shows up as having one player"
  https://bugs.launchpad.net/widelands/+bug/1736086

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1736086-map-without-players/+merge/345397

Maps with 0 players will still show up in the game load screens, but be disabled. I decided to show them to avoid "Where the F is my new map" moments.

If the starting position isn't set, the game load screen won't notice that, but the error is caught and displayed to the user on game start. I chose to keep it that way for efficiency.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1736086-map-without-players into lp:widelands.
=== modified file 'src/editor/map_generator.cc'
--- src/editor/map_generator.cc	2018-04-07 16:59:00 +0000
+++ src/editor/map_generator.cc	2018-05-11 05:37:05 +0000
@@ -663,7 +663,7 @@
 	const std::string ai = map_.get_scenario_player_ai(1);
 	map_.set_nrplayers(map_info_.numPlayers);
 	FindNodeSize functor(FindNodeSize::sizeBig);
-	Coords playerstart(-1, -1);
+	Coords playerstart(Coords::null());
 
 	// Build a basic structure how player start positions are placed
 	uint8_t line[3];
@@ -783,7 +783,7 @@
 
 			log("WARNING: Player %u has no starting position - illegal coordinates (%d, %d).\n", n,
 			    coords2.x, coords2.y);
-			coords2 = Coords(-1, -1);
+			coords2 = Coords::null();
 		}
 
 		// Finally set the found starting position

=== modified file 'src/editor/ui_menus/player_menu.cc'
--- src/editor/ui_menus/player_menu.cc	2018-04-07 16:59:00 +0000
+++ src/editor/ui_menus/player_menu.cc	2018-05-11 05:37:05 +0000
@@ -88,6 +88,10 @@
 		plr_set_pos_buts_[i] = nullptr;
 		plr_set_tribes_buts_[i] = nullptr;
 	}
+
+	if (parent.egbase().map().get_nrplayers() < 1) {
+		clicked_add_player();
+	}
 	update();
 
 	set_thinks(true);

=== modified file 'src/logic/map.cc'
--- src/logic/map.cc	2018-04-11 18:42:55 +0000
+++ src/logic/map.cc	2018-05-11 05:37:05 +0000
@@ -305,15 +305,7 @@
 	set_name(name);
 	set_author(author);
 	set_description(description);
-	set_nrplayers(1);
-	// Set first tribe found as the "basic" tribe
-	// <undefined> (as set before) is useless and will lead to a
-	// crash -> Widelands will search for tribe "<undefined>"
-	set_scenario_player_tribe(1, Widelands::get_all_tribenames()[0]);
-	set_scenario_player_name(1, (boost::format(_("Player %u")) % 1).str());
-	set_scenario_player_ai(1, "");
-	set_scenario_player_closeable(1, false);
-
+	set_nrplayers(0);
 	{
 		Field::Terrains default_terrains;
 		default_terrains.d = default_terrain;
@@ -494,7 +486,7 @@
 		return;
 	}
 
-	starting_pos_.resize(nrplayers, Coords(-1, -1));
+	starting_pos_.resize(nrplayers, Coords::null());
 	scenario_tribes_.resize(nrplayers);
 	scenario_ais_.resize(nrplayers);
 	scenario_closeables_.resize(nrplayers);

=== modified file 'src/map_io/coords_profile.cc'
--- src/map_io/coords_profile.cc	2018-04-07 16:59:00 +0000
+++ src/map_io/coords_profile.cc	2018-05-11 05:37:05 +0000
@@ -37,7 +37,7 @@
 	const long int x = strtol(endp, &endp, 0);
 	const long int y = strtol(endp, &endp, 0);
 
-	//  Check of consistence should NOT be at x, y < 0 as (-1, -1) is used for
+	//  Check of consistence should NOT be at x, y < 0 as (-1, -1) == Coords::null() is used for
 	//  not set starting positions in the editor. So check whether x, y < -1 so
 	//  the editor can load incomplete maps. For games the starting positions
 	//  will be checked in player initalisation anyway.

=== modified file 'src/map_io/map_player_position_packet.cc'
--- src/map_io/map_player_position_packet.cc	2018-04-07 16:59:00 +0000
+++ src/map_io/map_player_position_packet.cc	2018-05-11 05:37:05 +0000
@@ -41,7 +41,7 @@
 		if (packet_version == kCurrentPacketVersion) {
 			//  Read all the positions
 			//  This could bring trouble if one player position/ is not set (this
-			//  is possible in the editor), is also -1, -1.
+			//  is possible in the editor), is also -1, -1 == Coords::null().
 			Map* map = egbase.mutable_map();
 			Extent const extent = map->extent();
 			PlayerNumber const nr_players = map->get_nrplayers();

=== modified file 'src/sound/note_sound.h'
--- src/sound/note_sound.h	2018-04-07 16:59:00 +0000
+++ src/sound/note_sound.h	2018-05-11 05:37:05 +0000
@@ -41,7 +41,7 @@
 	}
 	NoteSound(const std::string& init_fx, uint32_t init_stereo_position, uint8_t init_priority)
 	   : fx(init_fx),
-	     coords(Widelands::Coords(-1, -1)),
+	     coords(Widelands::Coords::null()),
 	     priority(init_priority),
 	     stereo_position(init_stereo_position) {
 	}

=== modified file 'src/ui_fsmenu/mapselect.cc'
--- src/ui_fsmenu/mapselect.cc	2018-04-07 16:59:00 +0000
+++ src/ui_fsmenu/mapselect.cc	2018-05-11 05:37:05 +0000
@@ -184,7 +184,7 @@
 
 bool FullscreenMenuMapSelect::set_has_selection() {
 	bool has_selection = table_.has_selection();
-	ok_.set_enabled(has_selection);
+	ok_.set_enabled(has_selection && maps_data_.at(table_.get_selected()).nrplayers > 0);
 
 	if (!has_selection) {
 		map_details_.clear();


Follow ups