← Back to team overview

widelands-dev team mailing list archive

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


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

Commit message:
Set random tribes when using the random map generator

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"

For more details, see:

Fixes a bug in random map generator -> explicitly set a tribe to each player. The tribe is set randomly.
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/map_generator.cc'
--- src/editor/map_generator.cc	2018-07-21 07:53:42 +0000
+++ src/editor/map_generator.cc	2018-08-01 18:31:33 +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
 	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