← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/ai_persdata_fix into lp:widelands

 

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

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/ai_persdata_fix/+merge/276056

This is another quick fix after merging of persistent data for AI. When tinkering with seafaring I found that AI is not buiding port, after debug I found that variable colony_scan_area_ is set to 0, but AI expects it to be in range 10 - 35.

So obviously some variables must be saved to player class immediatly during first initialization, otherwise they can be restored later as zeros....
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/ai_persdata_fix into lp:widelands.
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc	2015-10-26 14:58:53 +0000
+++ src/ai/defaultai.cc	2015-10-28 21:24:48 +0000
@@ -64,6 +64,9 @@
 constexpr int kMarineDecisionInterval = 20 * 1000;
 constexpr int kTrainingSitesCheckInterval = 45 * 1000;
 
+// least radius to scan terrain when considering colonization port
+constexpr int kColonyScanMinArea = 10;
+
 // this is intended for map developers, by default should be off
 constexpr bool kPrintStats = false;
 
@@ -763,6 +766,12 @@
 		ai_personality_early_militarysites = std::rand() % 20 + 20;
 		player_->set_ai_data(ai_personality_early_militarysites, kEarlyMilitary);
 
+		// same defaults are directly saved to avoid inconsistency
+		player_->set_ai_data(colony_scan_area_, kColonyScan);
+		player_->set_ai_data(last_attacked_player_, kLastAttack);
+		player_->set_ai_data(least_military_score_, kLeastMilit);
+		player_->set_ai_data(target_military_score_, kTargetMilit);
+
 	} else {
 		log (" %d: restoring saved AI data...\n", player_number());
 
@@ -790,7 +799,7 @@
 		check_range<int16_t>(last_attacked_player_, 0, 8, "last_attacked_player_");
 
 		player_->get_ai_data(&colony_scan_area_, kColonyScan);
-		check_range<uint32_t>(colony_scan_area_, 50, "colony_scan_area_");
+		check_range<uint32_t>(colony_scan_area_, kColonyScanMinArea, 50, "colony_scan_area_");
 
 		player_->get_ai_data(&trees_around_cutters_, kTreesAround);
 
@@ -4523,7 +4532,6 @@
 		}
 	}
 	*tested_fields = done.size();
-
 	return false;  // no players found
 }
 
@@ -4628,10 +4636,11 @@
 		}
 
 		// decreasing colony_scan_area_
-		if (colony_scan_area_ > 10 && gametime % 10 == 0) {
+		if (colony_scan_area_ > kColonyScanMinArea && gametime % 5 == 0) {
 			colony_scan_area_ -= 1;
 			player_->set_ai_data(colony_scan_area_, kColonyScan);
 		}
+		assert(colony_scan_area_ >= kColonyScanMinArea);
 	}
 
 	// if we are here, port was not ordered above


Follow ups