Complete.Org: Mailing Lists: Archives: freeciv-dev: November 1999:
[Freeciv-Dev] Re: barbarians patch
Home

[Freeciv-Dev] Re: barbarians patch

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Jeff Mallatt <jjm@xxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: barbarians patch
From: Jerzy Klek <jekl@xxxxxxxxxx>
Date: Wed, 10 Nov 1999 15:45:30 +0100 (MET)

> Found a few problems with the latest barbarians patch:
> 
> 1. Barbarians showed up in the scorelog file.
> 2. Barbarians showed up in the gamelog file.
> 3. Barbarians still entered huts; in doing so, if they triggered more
> barbarians, the result seemed to be an infinite loop.
> 
> In the attached patch:  I fixed #1.  I made a minor change to address #2:
> Barbarians no longer show up in the ranking, but events they participate in
> still show up.  For #3, I tried really hard to keep barbarians from
> entering huts (seems to work).
> 
> I noticed that when barbarians have explored an entire island, they simply
> sit down and fortify and hang around for a very, very long time (perhaps,
> forever?).  If a very long time, this seems sort of boring, and if forever,
> this seems totally wrong, but I didn't look into how to change it.

The code below was meant to address this problem. It's very simple minded
but I though it should work. Maybe changing the retirement chance from
10% to 25% or more would help?

/Jerzy

+/**************************************************************************
+  Barbarian units may disband spontaneously if their age is more then 5,
+  they are not in cities, and they are far from any enemy units. It is to 
+  remove barbarians that do not engage into any activity for a long time.
+**************************************************************************/
+
+static int unit_can_be_retired(struct unit *punit)
+{
+  int x, y;
+
+  if( punit->fuel ) {   /* fuel abused for barbarian life span */
+    punit->fuel--;
+    return 0;
+  }
+
+  if( is_friendly_city_tile( punit->x, punit->y, punit->owner) )
+    return 0;
+
+  /* check if there is enemy nearby */
+  for(x = punit->x - 3; x < punit->x + 4; x++)
+    for(y = punit->y - 3; y < punit->y + 4; y++) { 
+      if( y < 0 || y > map.ysize )
+        continue;
+      x = map_adjust_x(x);
+      if( is_enemy_city_tile(x,y,punit->owner) ||
+          is_enemy_unit_tile(x,y,punit->owner) )
+        return 0;
+    }
+
+  return 1;
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+
 void ai_manage_unit(struct player *pplayer, struct unit *punit) 
 {
+  /* retire useless barbarian units here, before calling the management
+     function */
+  if( is_barbarian(pplayer) ) {
+    if( unit_can_be_retired(punit) && myrand(100) > 90 ) {
+      wipe_unit(0,punit);
+      return;
+    }
+    if( !is_military_unit(punit)
+       && !unit_has_role(punit->type, L_BARBARIAN_LEADER)) {
+      freelog(LOG_VERBOSE, "Barbarians picked up non-military unit.");
+      return;
+    }
+  }
+



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