Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] Re: (PR#12800) idea: barbarian level 5 (nightmare)
Home

[Freeciv-Dev] Re: (PR#12800) idea: barbarian level 5 (nightmare)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#12800) idea: barbarian level 5 (nightmare)
From: "Brian Dunstan" <bdunstan149@xxxxxxxxx>
Date: Fri, 15 Apr 2005 13:03:53 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12800 >

Am attaching a revision of the patch.  It moves the
constants to #define's in barbarian.h, and uses player
production to calculate barbarian strength in
barbarian levels 2-5.  Barbarian strength increases
exponentially with level, e.g. 1/8, 3/8, 9/8, 27/8, as
a proportion of combined non-barbarian player
production.

The factor used, and the value for level=2, are
configurable in barbarian.h in this patch.  I've
tested for sanity the amount of barbarians made, but
it's hard to be too exact, since the AI currently in
CVS seems to have a hard time making new cities and
improving terrain.

Brian


--- Benoit Hudson <bh@xxxxxxxxxxxxxxxxxxx> wrote:
> 
> <URL:
> http://bugs.freeciv.org/Ticket/Display.html?id=12800
> >
> 
> On Thu, Apr 14, 2005 at 06:46:00PM -0700, Brian
> Dunstan wrote:
> >
> > <URL:
> http://bugs.freeciv.org/Ticket/Display.html?id=12800
> >
> >
> > I have noticed that the barbarian level 4 (raging
> > hordes)  does not have much rage in it.  For a
> > moderate to good player, they are not a major
> concern.
> 
> Indeed.
> 
> > The attached patch accomplishes this, adding
> barbarian
> > level 5 (nightmare).  Barbarians are generated
> each
> > turn with a shield cost equivalent to twice the
> > combined production of the non-barbarian players.
> 
> I like the idea of tying barbarian production to
> that of non-barbs.
> Perhaps that's how it should be at all barbarian
> levels?  Then
> game.barbarianrate would be used to define the
> function from players'
> production to barbarians' production.
> 
> Specific comments on the code: you use bare
> constants like 4, 5, 500,
> 1000.  Don't: make #defines so we can easily change
> the values later.
> 
>         -- Benoit
> 
> 
> 
> 
> 


                
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
diff -Nur -Xfreeciv/diff_ignore freeciv/common/game.h 
freeciv_altered/common/game.h
--- freeciv/common/game.h       2005-04-15 10:33:38.362028224 -0400
+++ freeciv_altered/common/game.h       2005-04-15 11:08:25.812687488 -0400
@@ -469,7 +469,7 @@
 
 #define GAME_DEFAULT_BARBARIANRATE   2
 #define GAME_MIN_BARBARIANRATE       0
-#define GAME_MAX_BARBARIANRATE       4
+#define GAME_MAX_BARBARIANRATE       5
 
 #define GAME_DEFAULT_ONSETBARBARIAN  (GAME_START_YEAR+ \
                                      
((GAME_DEFAULT_END_YEAR-(GAME_START_YEAR))/3))
diff -Nur -Xfreeciv/diff_ignore freeciv/server/barbarian.c 
freeciv_altered/server/barbarian.c
--- freeciv/server/barbarian.c  2005-04-15 10:33:38.168057712 -0400
+++ freeciv_altered/server/barbarian.c  2005-04-15 12:47:50.060983928 -0400
@@ -375,13 +375,6 @@
     return;
   }
 
-  /* do not harass small civs - in practice: do not uprise at the beginning */
-  if ((int)myrand(UPRISE_CIV_MORE) >
-           (int)city_list_size(victim->cities) -
-                UPRISE_CIV_SIZE/(game.barbarianrate-1)
-      || myrand(100) > get_gov_pcity(pc)->civil_war) {
-    return;
-  }
   freelog(LOG_DEBUG, "Barbarians are willing to fight");
 
   if (tile_has_special(utile, S_HUT)) {
@@ -447,7 +440,13 @@
 **************************************************************************/
 void summon_barbarians(void)
 {
-  int i, n;
+
+  int i = 0;
+  int barbarian_shields = 0;
+  int barbarian_units = 0; 
+  int barbarian_units_total_value = 0;
+  int barbarian_unit_avg_value = 0;
+  int barbarian_unit_quota = 0;
 
   if (game.barbarianrate == 0) {
     return;
@@ -456,14 +455,50 @@
   if (game.year < game.onsetbarbarian) {
     return;
   }
-
-  n = map_num_tiles() / MAP_FACTOR;
-  if (n == 0) {
-    /* Allow barbarians on maps smaller than MAP_FACTOR */
-    n = 1;
-  }
-
-  for (i = 0; i < n * (game.barbarianrate - 1); i++) {
+  
+  players_iterate(aplayer) {
+    if(!is_barbarian(aplayer)) {
+      city_list_iterate(aplayer->cities, acity) {
+       barbarian_shields += MAX(acity->size, acity->prod[O_SHIELD]);
+      } city_list_iterate_end;
+    }
+    else if(aplayer->is_alive) {
+      barbarian_units += unit_list_size(aplayer->units);
+      unit_list_iterate(aplayer->units, punit) {
+       barbarian_units_total_value +=
+         unit_build_shield_cost(punit->type);
+      } unit_list_iterate_end;
+    }
+  } players_iterate_end;
+    
+  barbarian_shields = (int)((float)barbarian_shields *
+                           BARBARIAN_STRENGTH);
+  
+  if(barbarian_shields == 0) return;
+  barbarian_units = MAX(1, barbarian_units);
+  
+  barbarian_unit_avg_value = 
+    (int)((float)barbarian_units_total_value / 
+         (float)barbarian_units);
+  
+  barbarian_unit_avg_value = 
+    MAX(BARBARIAN_UNIT_COST_STD, barbarian_unit_avg_value);
+  
+  barbarian_unit_quota = 
+    barbarian_units + (barbarian_shields / barbarian_unit_avg_value);
+  
+  barbarian_unit_quota = MIN(BARBARIAN_UNIT_LIMIT, barbarian_unit_quota);
+  
+  while (barbarian_units < barbarian_unit_quota && 
+        i < BARBARIAN_UNIT_LIMIT)  {
     try_summon_barbarians();
+    barbarian_units = 0;
+    players_iterate(aplayer) {
+      if(is_barbarian(aplayer) && aplayer->is_alive) {
+       barbarian_units += unit_list_size(aplayer->units);
+      }
+    } players_iterate_end;
+    i++;
   }
 }
+
diff -Nur -Xfreeciv/diff_ignore freeciv/server/barbarian.h 
freeciv_altered/server/barbarian.h
--- freeciv/server/barbarian.h  2005-04-15 10:33:38.108066832 -0400
+++ freeciv_altered/server/barbarian.h  2005-04-15 12:04:47.106652672 -0400
@@ -24,8 +24,23 @@
 #define UPRISE_CIV_SIZE  10
 #define UPRISE_CIV_MORE  30
 #define UPRISE_CIV_MOST  50
+  
+/* increase this to widen difference between lower and higher 
+ * barbarianrate settings */
+#define BARBARIAN_STRENGTH_BASE 3 
 
-#define MAP_FACTOR     2000  /* adjust this to get a good uprising frequency */
+/* increase this to increase barbarian frequency */
+#define BARBARIAN_STRENGTH_FACTOR 0.125
+
+#define BARBARIAN_UNIT_COST_STD 20 /*default unit cost */
+#define BARBARIAN_UNIT_LIMIT 500 /* max size of barbarian army */
+
+  /* barbarian unit production as a proportion of the combined production
+   * of non-barbarian players.  Lowest value is *_FACTOR, multiplied
+   * by *_BASE for each successive barbarian rate */
+#define BARBARIAN_STRENGTH (game.barbarianrate >= 2 ? \
+  (exp(log(BARBARIAN_STRENGTH_BASE) * (game.barbarianrate-2)) * \
+  BARBARIAN_STRENGTH_FACTOR) : 0.0)
 
 bool unleash_barbarians(struct tile *ptile);
 void summon_barbarians(void);
diff -Nur -Xfreeciv/diff_ignore freeciv/server/settings.c 
freeciv_altered/server/settings.c
--- freeciv/server/settings.c   2005-04-15 10:33:38.105067288 -0400
+++ freeciv_altered/server/settings.c   2005-04-15 11:08:25.814687184 -0400
@@ -690,7 +690,8 @@
             "1 = barbarians only in huts \n"
             "2 = normal rate of barbarian appearance \n"
             "3 = frequent barbarian uprising \n"
-            "4 = raging hordes, lots of barbarians"), NULL, 
+            "4 = raging hordes, lots of barbarians \n"
+            "5 = nightmare, way too many barbarians"), NULL, 
          GAME_MIN_BARBARIANRATE, GAME_MAX_BARBARIANRATE, 
          GAME_DEFAULT_BARBARIANRATE)
 

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