← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1783878_editor_random_map_tribe into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1783878_editor_random_map_tribe into lp:widelands.

Commit message:
Random Map Generator now assigns a random tribe to all players. Fix crash when loading a map in the editor where there is a player with no tribe assigned.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1783878 in widelands: "Editor: Saved random map does segfault on load if no tribe is explicitly set"
  https://bugs.launchpad.net/widelands/+bug/1783878

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1783878_editor_random_map_tribe/+merge/352943

I decided not to bother with any UI changes at this point - we have more important bugs to fix for Build 20.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1783878_editor_random_map_tribe into lp:widelands.
=== modified file 'src/editor/editorinteractive.cc'
--- src/editor/editorinteractive.cc	2018-07-20 08:42:23 +0000
+++ src/editor/editorinteractive.cc	2018-08-12 17:17:16 +0000
@@ -180,7 +180,7 @@
 	loader_ui.step(_("Creating players"));
 	iterate_player_numbers(p, map->get_nrplayers()) {
 		egbase().add_player(
-		   p, 0, map->get_scenario_player_tribe(p), map->get_scenario_player_name(p));
+		   p, 0, map->get_scenario_player_tribe(p).empty() ? Widelands::get_all_tribenames().front() : map->get_scenario_player_tribe(p), map->get_scenario_player_name(p));
 	}
 
 	ml->load_map_complete(egbase(), Widelands::MapLoader::LoadType::kEditor);

=== modified file 'src/editor/map_generator.cc'
--- src/editor/map_generator.cc	2018-07-21 07:53:42 +0000
+++ src/editor/map_generator.cc	2018-08-12 17:17:16 +0000
@@ -28,6 +28,7 @@
 #include "logic/editor_game_base.h"
 #include "logic/findnode.h"
 #include "logic/map.h"
+#include "logic/map_objects/tribes/tribe_basic_info.h"
 #include "logic/map_objects/world/map_gen.h"
 #include "logic/map_objects/world/world.h"
 #include "scripting/lua_interface.h"
@@ -661,7 +662,6 @@
 	// Care about players and place their start positions
 	map_.set_nrplayers(map_info_.numPlayers);
 	assert(map_info_.numPlayers >= 1);
-	const std::string tribe = map_.get_scenario_player_tribe(1);
 	const std::string ai = map_.get_scenario_player_ai(1);
 	FindNodeSize functor(FindNodeSize::sizeBig);
 	Coords playerstart(Coords::null());
@@ -714,6 +714,7 @@
 	for (PlayerNumber n = 1; n <= map_info_.numPlayers; ++n) {
 		// Set scenario information - needed even if it's not a scenario
 		map_.set_scenario_player_name(n, _("Random Player"));
+		const std::string tribe = get_all_tribenames()[rng.rand() % get_all_tribenames().size()];
 		map_.set_scenario_player_tribe(n, tribe);
 		map_.set_scenario_player_ai(n, ai);
 		map_.set_scenario_player_closeable(n, false);


Follow ups