← Back to team overview

widelands-dev team mailing list archive

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

 

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

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1637386 in widelands: "Militarysites warn about allies"
  https://bugs.launchpad.net/widelands/+bug/1637386

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

A tiny change that should make sure that soldier visiting other territory is not presented as an aggressor to a militarysite that belongs to an ally. 
I tested it with teamed AI-only game, it at least had not crashed. So I have not tested if issue with messages is really fixed.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1637386 into lp:widelands.
=== modified file 'src/logic/map_objects/tribes/soldier.cc'
--- src/logic/map_objects/tribes/soldier.cc	2017-01-25 18:55:59 +0000
+++ src/logic/map_objects/tribes/soldier.cc	2017-01-30 21:39:20 +0000
@@ -1524,15 +1524,21 @@
 	}
 
 	PlayerNumber const land_owner = get_position().field->get_owned_by();
+	// First check if the soldier is standing on someone else's territory
 	if (land_owner != owner().player_number()) {
+		// Let collect all eachable attackable sites in vicinity (militarysites mainly)
 		std::vector<BaseImmovable*> attackables;
 		game.map().find_reachable_immovables_unique(
 		   Area<FCoords>(get_position(), MaxProtectionRadius), attackables,
 		   CheckStepWalkOn(descr().movecaps(), false), FindImmovableAttackable());
 
 		for (BaseImmovable* temp_attackable : attackables) {
-			if (dynamic_cast<const PlayerImmovable&>(*temp_attackable).get_owner()->player_number() ==
-			    land_owner) {
+			const Player* attackable_player =
+			   dynamic_cast<const PlayerImmovable&>(*temp_attackable).get_owner();
+			// Let inform the site that this (=enemy) soldier is nearby and within the site's owner
+			// territory
+			if (attackable_player->player_number() == land_owner &&
+			    attackable_player->is_hostile(*get_owner())) {
 				dynamic_cast<Attackable&>(*temp_attackable).aggressor(*this);
 			}
 		}


Follow ups