← Back to team overview

widelands-dev team mailing list archive

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

 

TiborB has proposed merging lp:~widelands-dev/widelands/bug-1734199 into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1734199 in widelands: "AI Data needs to write remaining buildings as strings"
  https://bugs.launchpad.net/widelands/+bug/1734199

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

Buildings in remaining_basic_buildings are now stored as strings.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1734199 into lp:widelands.
=== modified file 'src/game_io/game_player_ai_persistent_packet.cc'
--- src/game_io/game_player_ai_persistent_packet.cc	2017-11-20 07:54:19 +0000
+++ src/game_io/game_player_ai_persistent_packet.cc	2017-11-28 11:00:28 +0000
@@ -29,7 +29,9 @@
 namespace Widelands {
 
 // Introduction of genetic algorithm with all structures that are needed for it
-constexpr uint16_t kCurrentPacketVersion = 3;
+constexpr uint16_t kCurrentPacketVersion = 4;
+// First version with genetics
+constexpr uint16_t kPacketVersion3 = 3;
 // Old Version before using genetics
 constexpr uint16_t kPacketVersion2 = 2;
 
@@ -66,7 +68,7 @@
 					// Make the AI initialize itself
 					player->ai_data.initialized = 0;
 				} else {
-					// kCurrentPacketVersion
+					// Contains Genetic algorithm data
 					player->ai_data.initialized = (fr.unsigned_8() == 1) ? true : false;
 					player->ai_data.colony_scan_area = fr.unsigned_32();
 					player->ai_data.trees_around_cutters = fr.unsigned_32();
@@ -131,8 +133,16 @@
 
 					size_t remaining_basic_buildings_size = fr.unsigned_32();
 					for (uint16_t i = 0; i < remaining_basic_buildings_size; ++i) {
-						player->ai_data.remaining_basic_buildings.emplace(
-						   static_cast<Widelands::DescriptionIndex>(fr.unsigned_32()), fr.unsigned_32());
+						if (packet_version == kPacketVersion3) {  // Old genetics (buildings saved as idx)
+							player->ai_data.remaining_basic_buildings.emplace(
+							   static_cast<Widelands::DescriptionIndex>(fr.unsigned_32()),
+							   fr.unsigned_32());
+						} else {  // New genetics (buildings saved as strigs)
+							const std::string building_string = fr.string();
+							const Widelands::DescriptionIndex bld_idx =
+							   player->tribe().building_index(building_string);
+							player->ai_data.remaining_basic_buildings.emplace(bld_idx, fr.unsigned_32());
+						}
 					}
 					// Basic sanity check for remaining basic buildings
 					assert(player->ai_data.remaining_basic_buildings.size() <
@@ -203,11 +213,12 @@
 		// Remaining buildings for basic economy
 		fw.unsigned_32(player->ai_data.remaining_basic_buildings.size());
 		for (auto bb : player->ai_data.remaining_basic_buildings) {
-			fw.unsigned_32(bb.first);
+			const std::string bld_name = game.tribes().get_building_descr(bb.first)->name().c_str();
+			fw.string(bld_name);
 			fw.unsigned_32(bb.second);
 		}
 	}
 
 	fw.write(fs, "binary/player_ai");
 }
-}
+}  // namespace Widelands


Follow ups