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;
+}