← Back to team overview

widelands-dev team mailing list archive

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

 

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

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1729856 in widelands: "AI enhances past its building limit"
  https://bugs.launchpad.net/widelands/+bug/1729856

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

I inserted a check when considering the upgrade of trainingsites to make sure we are not going to exceed the limit for weaker AI
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1729856 into lp:widelands.
=== modified file 'src/ai/defaultai_warfare.cc'
--- src/ai/defaultai_warfare.cc	2017-11-02 19:55:17 +0000
+++ src/ai/defaultai_warfare.cc	2017-11-04 20:46:09 +0000
@@ -576,14 +576,24 @@
 	TrainingSiteObserver& tso = trainingsites.front();
 
 	// Make sure we are not above ai type limit
-	assert(tso.bo->total_count() <= tso.bo->cnt_limit_by_aimode);
+	if (tso.bo->total_count() > tso.bo->cnt_limit_by_aimode) {
+		throw wexception("%d AI count of %s exceeds an AI limit %d: actual count: %d\n",
+		                 player_number(), tso.bo->name, tso.bo->cnt_limit_by_aimode,
+		                 tso.bo->total_count());
+	}
 
 	const DescriptionIndex enhancement = ts->descr().enhancement();
 
 	if (enhancement != INVALID_INDEX && ts_without_trainers_ == 0 && mines_.size() > 3 &&
 	    ts_finished_count_ > 1 && ts_in_const_count_ == 0) {
 
-		if (player_->is_building_type_allowed(enhancement)) {
+		// Make sure that"
+		// 1. Building is allowed
+		// 2. AI limit for weaker AI is not to be exceeded
+		BuildingObserver& en_bo =
+		   get_building_observer(tribe_->get_building_descr(enhancement)->name().c_str());
+		if (player_->is_building_type_allowed(enhancement) &&
+		    en_bo.aimode_limit_status() == AiModeBuildings::kAnotherAllowed) {
 			game().send_player_enhance_building(*tso.site, enhancement);
 		}
 	}


Follow ups