← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~nasenbaer/widelands/teams-defaultAI into lp:~nha/widelands/teams

 

Nasenbaer has proposed merging lp:~nasenbaer/widelands/teams-defaultAI into lp:~nha/widelands/teams.

Requested reviews:
  Widelands Developers (widelands-dev)


Fixes to let defaultAI behave "logical" near allied players
-- 
https://code.launchpad.net/~nasenbaer/widelands/teams-defaultAI/+merge/26855
Your team Widelands Developers is requested to review the proposed merge of lp:~nasenbaer/widelands/teams-defaultAI into lp:~nha/widelands/teams.
=== modified file 'src/ai/ai_help_structs.h'
--- src/ai/ai_help_structs.h	2010-05-08 13:41:26 +0000
+++ src/ai/ai_help_structs.h	2010-06-05 09:33:32 +0000
@@ -24,7 +24,9 @@
 #include "economy/flag.h"
 #include "economy/road.h"
 #include "logic/findnode.h"
+#include "logic/game.h"
 #include "logic/map.h"
+#include "logic/player.h"
 
 #include <list>
 
@@ -54,18 +56,22 @@
 struct FindNodeUnowned {
 	bool accept (const Map &, const FCoords & fc) const {
 		// when looking for unowned terrain to acquire, we are actually
-		// only interested in fields we can walk on
+		// only interested in fields we can walk on.
+		// Fields should either be completely unowned or owned by an opposing player
 		return
 			fc.field->nodecaps() & MOVECAPS_WALK
-			&& fc.field->get_owned_by() != playernum
+			&& ((fc.field->get_owned_by() == 0) 
+				 || player->is_hostile(*game.get_player(fc.field->get_owned_by())))
 			&& (!onlyenemies || (fc.field->get_owned_by() != 0));
 	}
 
-	int8_t playernum;
+	//int8_t playernum;
+	Player * player;
+	Game & game;
 	bool onlyenemies;
 
-	FindNodeUnowned(int8_t pn, bool oe = false)
-		: playernum(pn), onlyenemies(oe)
+	FindNodeUnowned(Player * p, Game & g, bool oe = false)
+		: player(p), game(g), onlyenemies(oe)
 	{}
 };
 

=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc	2010-06-04 20:34:47 +0000
+++ src/ai/defaultai.cc	2010-06-05 09:33:32 +0000
@@ -474,8 +474,9 @@
 	(BuildableField & field, uint16_t range, bool military)
 {
 	// look if there is any unowned land nearby
-	FindNodeUnowned find_unowned(player_number());
 	Map & map = game().map();
+	FindNodeUnowned find_unowned(player, game());
+	Player_Number const pn = player->player_number();
 
 	field.unowned_land_nearby =
 		map.find_fields(Area<FCoords>(field.coords, range), 0, find_unowned);
@@ -528,8 +529,11 @@
 			if (dynamic_cast<const Flag *>(&base_immovable))
 				field.reachable = true;
 			if (upcast(PlayerImmovable const, player_immovable, &base_immovable))
-				if (player_immovable->owner().player_number() != player_number()) {
-					field.enemy_nearby = true;
+				// TODO  Only continue; if this is an opposing site
+				// TODO  allied sites should be counted for military influence
+				if (player_immovable->owner().player_number() != pn) {
+					if (player->is_hostile(player_immovable->owner()))
+						field.enemy_nearby = true;
 					continue;
 				}
 
@@ -1687,13 +1691,12 @@
 	// Check next militarysite
 	bool changed = false;
 	Map & map = game().map();
-	uint16_t const pn = player_number();
 	MilitarySite * ms = militarysites.front().site;
 	uint32_t const vision = ms->vision_range();
 	FCoords f = map.get_fcoords(ms->get_position());
 
 	// look if there is any enemy land nearby
-	FindNodeUnowned find_unowned(pn, true);
+	FindNodeUnowned find_unowned(player, game(), true);
 
 	if (map.find_fields(Area<FCoords>(f, vision), 0, find_unowned) == 0) {
 		// If no enemy in sight - decrease the number of stationed soldiers
@@ -2097,7 +2100,7 @@
 	FCoords f = map.get_fcoords(ms->get_position());
 
 	Building * target = ms; // dummy initialisation to silence the compiler
-	int32_t   chance    = 0;
+	int32_t    chance    = 0;
 	uint32_t   attackers = 0;
 	uint8_t    retreat   = ms->owner().get_retreat_percentage();