Complete.Org: Mailing Lists: Archives: freeciv-ai: August 2002:
[freeciv-ai] Re: ai_military_attack()
Home

[freeciv-ai] Re: ai_military_attack()

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "Per I. Mathisen" <per@xxxxxxxxxxx>
Cc: freeciv-ai@xxxxxxxxxxx
Subject: [freeciv-ai] Re: ai_military_attack()
From: Jordi Negrevernis i Font <jorneg@xxxxxxxxxxx>
Date: Mon, 26 Aug 2002 22:32:22 +0200



Per I. Mathisen wrote:

This is actually an older patch of mine, which I don't think I ever posted
here. It cleans up ai_military_attack(), except for the barb code, and
introduces the function ai_military_rampage(), which blasts anything
adjacent to punit for as many movement points as you have. This saves code
duplication.

Yours
Per


------------------------------------------------------------------------

diff -uNrX freeciv/diff_ignore freeciv/ai/aiunit.c freeciv-ai/ai/aiunit.c
--- freeciv/ai/aiunit.c 2002-08-13 03:15:25.000000000 +0200
+++ freeciv-ai/ai/aiunit.c      2002-08-13 03:06:02.000000000 +0200
@@ -56,6 +56,7 @@
static void ai_military_findjob(struct player *pplayer,struct unit *punit);
static void ai_military_gohome(struct player *pplayer,struct unit *punit);
static void ai_military_attack(struct player *pplayer,struct unit *punit);
+static struct unit *ai_military_rampage(struct unit *punit, int threshold);

static int unit_move_turns(struct unit *punit, int x, int y);
static bool unit_can_defend(Unit_Type_id type);
@@ -1075,6 +1076,23 @@
}

/*************************************************************************
+ Find and kill anything adjacent to us that we don't like with a + given threshold until we have run out of juicy targets or movement. + Wraps ai_military_findvictim().
+**************************************************************************/
+static struct unit *ai_military_rampage(struct unit *punit, int threshold)
+{
+  int x, y, id = punit->id;
+
+  while (punit && punit->moves_left
+         && ai_military_findvictim(punit, &x, &y) >= threshold) {
+    ai_unit_attack(punit, x, y);
+    punit = find_unit_by_id(id);
+  }
+  return punit;
+}

Be aware that this code does not check to see if the coordinates returned by ai_military_findvictim are the same as the unit ones. You should have to check that they are diferent or i'll have an assert in ai_unit_attack...





[Prev in Thread] Current Thread [Next in Thread]