← Back to team overview

widelands-dev team mailing list archive

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

 

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

Requested reviews:
  TiborB (tiborb95)

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

Fixed a crash in AI when enemy slots are empty.

To reproduce the crash, host a new multiplayer game with the Trident of Fire scenario and leave player slots 2 and 3 empty.
-- 
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/ai_null_enemy.
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc	2015-10-25 12:26:20 +0000
+++ src/ai/defaultai.cc	2015-10-26 09:07:23 +0000
@@ -5023,7 +5023,7 @@
 	// summing team power, creating team_power std::map of team_number:strength
 	std::map<TeamNumber, uint32_t> team_power;
 	for (uint8_t j = 1; j <= plr_in_game; ++j) {
-		TeamNumber const tm = game().get_player(j)->team_number();
+		TeamNumber const tm = (game().get_player(j)) ? game().get_player(j)->team_number() : 0;
 		if (tm == 0) {
 			continue;
 		}
@@ -5075,8 +5075,9 @@
 	}
 	// adding power of team (minus my power) divided by 2
 	// (if I am a part of a team of course)
-	if (game().get_player(pn)->team_number() > 0) {
-		my_power += (team_power[game().get_player(pn)->team_number()] - my_power) / 2;
+	TeamNumber team_number = (game().get_player(pn)) ? game().get_player(pn)->team_number() : 0;
+	if (team_number > 0) {
+		my_power += (team_power[team_number] - my_power) / 2;
 	}
 
 	// now we test all players to identify 'attackable' ones
@@ -5087,8 +5088,8 @@
 			continue;
 		}
 		// if we are the same team
-		if (game().get_player(pn)->team_number() > 0 &&
-		game().get_player(pn)->team_number() == game().get_player(j)->team_number()) {
+		TeamNumber other_team_number = (game().get_player(j)) ? game().get_player(j)->team_number() : 0;
+		if (team_number > 0 && team_number == other_team_number) {
 			player_attackable[j - 1] = false;
 			continue;
 		}
@@ -5101,7 +5102,7 @@
 				players_power += genstats.at(j - 1).miltary_strength.back();
 			}
 			// +power of team (if member of a team)
-			if (game().get_player(j)->team_number() > 0) {
+			if (game().get_player(j) && game().get_player(j)->team_number() > 0) {
 				players_power += (team_power[game().get_player(j)->team_number()] - players_power) / 2;
 			}
 


Follow ups