← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~qcumber-some/widelands/bug543113 into lp:widelands

 

Jens Beyer (Qcumber-some) has proposed merging lp:~qcumber-some/widelands/bug543113 into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #543113 in widelands: "Land owned statistics should not display number of fields but instead % of total map size"
  https://bugs.launchpad.net/widelands/+bug/543113

For more details, see:
https://code.launchpad.net/~qcumber-some/widelands/bug543113/+merge/128126

Implemented variant 2 of the bug description

percentage of total land mass (then, only land fields should be counted)

It uses the same counting method as the Territorial Lord win condition (which is the most useful statistic, I think).
-- 
https://code.launchpad.net/~qcumber-some/widelands/bug543113/+merge/128126
Your team Widelands Developers is requested to review the proposed merge of lp:~qcumber-some/widelands/bug543113 into lp:widelands.
=== modified file 'src/logic/game.cc'
--- src/logic/game.cc	2012-09-21 21:36:07 +0000
+++ src/logic/game.cc	2012-10-04 22:21:23 +0000
@@ -905,9 +905,25 @@
 	//  We walk the map, to gain all needed information.
 	Map const &  themap = map();
 	Extent const extent = themap.extent();
+	m_land_size_total = 0;
 	iterate_Map_FCoords(themap, extent, fc) {
-		if (Player_Number const owner = fc.field->get_owned_by())
-			++land_size[owner - 1];
+		// use the same method of counting fields as in Territorial Lord win condition
+		// a countable field is not swimmable; but walkable or has an immovable
+		// a countable field belongs to a player if it is owned by the player
+		bool count = false;
+		if (!(fc.field->nodecaps() & MOVECAPS_SWIM)) {
+			if (fc.field->nodecaps() & MOVECAPS_WALK) {
+				count = true;
+			}
+			else if (fc.field->get_immovable()) {
+				count = true;
+			}
+		}
+		if (count) {
+			m_land_size_total++;
+			if (Player_Number const owner = fc.field->get_owned_by())
+			      ++land_size[owner - 1];
+		}
 
 			// Get the immovable
 		if (upcast(Building, building, fc.field->get_immovable()))
@@ -986,7 +1002,7 @@
 	// Now, push this on the general statistics
 	m_general_stats.resize(map().get_nrplayers());
 	for (uint32_t i = 0; i < map().get_nrplayers(); ++i) {
-		m_general_stats[i].land_size       .push_back(land_size       [i]);
+		m_general_stats[i].land_size       .push_back(100 * land_size       [i] / m_land_size_total);
 		m_general_stats[i].nr_buildings    .push_back(nr_buildings    [i]);
 		m_general_stats[i].nr_casualties   .push_back(nr_casualties   [i]);
 		m_general_stats[i].nr_kills        .push_back(nr_kills        [i]);

=== modified file 'src/logic/game.h'
--- src/logic/game.h	2012-02-15 21:25:34 +0000
+++ src/logic/game.h	2012-10-04 22:21:23 +0000
@@ -245,6 +245,9 @@
 
 	/// For save games and statistics generation
 	std::string          m_win_condition_string;
+
+	// used in statistics building
+	uint32_t m_land_size_total;
 };
 
 inline Coords Game::random_location(Coords location, uint8_t radius) {