← Back to team overview

widelands-dev team mailing list archive

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

 

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

Commit message:
AI calculates military strength based on the actual init.lua files now rather than hard-coding the values. This removed the tribe name restriction for modders.

Requested reviews:
  TiborB (tiborb95)

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

The values should all be the same as before, except for Barbarian increase_per_level = 850, which was assumed = 700 before.

Also, the values were assigned by = for the Atlanteans, but by += for the other tribes. I went with =, please fix if this is not intended.
-- 
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/ai_for_mods.
=== modified file 'src/ai/defaultai.h'
--- src/ai/defaultai.h	2016-12-07 22:18:10 +0000
+++ src/ai/defaultai.h	2017-01-22 12:45:20 +0000
@@ -94,8 +94,6 @@
 		kAttackableVeryWeak
 	};
 
-	enum class Tribes : uint8_t { kNone, kBarbarians, kAtlanteans, kEmpire };
-
 	/// Implementation for Strong
 	struct NormalImpl : public ComputerPlayer::Implementation {
 		NormalImpl() {

=== modified file 'src/ai/defaultai_warfare.cc'
--- src/ai/defaultai_warfare.cc	2017-01-06 09:00:11 +0000
+++ src/ai/defaultai_warfare.cc	2017-01-22 12:45:20 +0000
@@ -699,19 +699,6 @@
 		return 0;
 	}
 
-	Tribes tribe = Tribes::kNone;
-
-	if (soldiers.at(0)->get_owner()->tribe().name() == "atlanteans") {
-		tribe = Tribes::kAtlanteans;
-	} else if (soldiers.at(0)->get_owner()->tribe().name() == "barbarians") {
-		tribe = Tribes::kBarbarians;
-	} else if (soldiers.at(0)->get_owner()->tribe().name() == "empire") {
-		tribe = Tribes::kEmpire;
-	} else {
-		throw wexception("AI warning: Unable to calculate strength for player of tribe %s",
-		                 soldiers.at(0)->get_owner()->tribe().name().c_str());
-	}
-
 	float health = 0;
 	float attack = 0;
 	float defense = 0;
@@ -719,29 +706,11 @@
 	float final = 0;
 
 	for (Soldier* soldier : soldiers) {
-		switch (tribe) {
-		case (Tribes::kAtlanteans):
-			health = 135 + 40 * soldier->get_health_level();
-			attack = 14 + 8 * soldier->get_attack_level();
-			defense = static_cast<float>(94 - 8 * soldier->get_defense_level()) / 100;
-			evade = static_cast<float>(70 - 17 * soldier->get_evade_level()) / 100;
-			break;
-		case (Tribes::kBarbarians):
-			health += 130 + 28 * soldier->get_health_level();
-			attack += 14 + 7 * soldier->get_attack_level();
-			defense += static_cast<float>(97 - 8 * soldier->get_defense_level()) / 100;
-			evade += static_cast<float>(75 - 15 * soldier->get_evade_level()) / 100;
-			break;
-		case (Tribes::kEmpire):
-			health += 130 + 21 * soldier->get_health_level();
-			attack += 14 + 8 * soldier->get_attack_level();
-			defense += static_cast<float>(95 - 8 * soldier->get_defense_level()) / 100;
-			evade += static_cast<float>(70 - 16 * soldier->get_evade_level()) / 100;
-			break;
-		case (Tribes::kNone):
-			NEVER_HERE();
-		}
-
+		const SoldierDescr& descr = soldier->descr();
+		health = (descr.get_base_health() + descr.get_health_incr_per_level() * soldier->get_health_level()) / 100;
+		attack = ((descr.get_base_max_attack() - descr.get_base_min_attack()) / 2 + descr.get_base_min_attack() + descr.get_attack_incr_per_level() * soldier->get_attack_level()) / 100;
+		defense = static_cast<float>(100 - descr.get_base_defense() - 8 * soldier->get_defense_level()) / 100;
+		evade = static_cast<float>(100 - descr.get_base_evade() - descr.get_evade_incr_per_level() / 100 * soldier->get_evade_level()) / 100;
 		final += (attack * health) / (defense * evade);
 	}
 


Follow ups