← Back to team overview

widelands-dev team mailing list archive

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

 

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

Commit message:
Unset player starting position in MapGenerator if coordinates are illegal.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1535065 in widelands: "Editor crashes with random map regarding player positions"
  https://bugs.launchpad.net/widelands/+bug/1535065

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1535065/+merge/284658

This fixes a crash with the random map generator where coordinates of player positions would be outside of the map.

The player positions generated aren't necessarily viable, but that's a problem for another day.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1535065 into lp:widelands.
=== modified file 'src/editor/map_generator.cc'
--- src/editor/map_generator.cc	2016-01-28 05:24:34 +0000
+++ src/editor/map_generator.cc	2016-02-01 18:29:14 +0000
@@ -741,7 +741,7 @@
 	const std::string ai    = map_.get_scenario_player_ai(1);
 	map_.set_nrplayers(map_info_.numPlayers);
 	FindNodeSize functor(FindNodeSize::sizeBig);
-	Coords playerstart;
+	Coords playerstart(-1, -1);
 
 	// Build a basic structure how player start positions are placed
 	uint8_t line[3];
@@ -850,6 +850,21 @@
 			coords2 = playerstart;
 		}
 
+		// Remove coordinates if they are an illegal starting position.
+		if (coords2.x < 0 || coords2.x > map_.get_width() - 1 ||
+			 coords2.y < 0 || coords2.y > map_.get_height() - 1) {
+
+			// TODO(GunChleoc): If we check for buildcaps here, this always fails.
+			// we should bulldoze a bit of terrain to increase the chance that starting positions
+			// do not fail:
+			// map_.get_fcoords(coords2).field->nodecaps() & Widelands::BUILDCAPS_SIZEMASK
+			// != Widelands::BUILDCAPS_BIG)
+
+			log("WARNING: Player %u has no starting position - illegal coordinates (%d, %d).\n",
+				 n, coords2.x, coords2.y);
+			coords2 = Coords(-1, -1);
+		}
+
 		// Finally set the found starting position
 		map_.set_starting_pos(n, coords2);
 	}


Follow ups