Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2002:
[Freeciv-Dev] build_cost_prime
Home

[Freeciv-Dev] build_cost_prime

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Freeciv Bugs <bugs@xxxxxxxxxxxxxxxxxxx>, Freeciv development list <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] build_cost_prime
From: Gregory Berkolaiko <gberkolaiko@xxxxxxxxxxx>
Date: Thu, 3 Jan 2002 13:45:35 +0000 (GMT)

Hi,

the variable with an expressive name "fprime" is calculated in the same
way in 3 different places.  I propose to separate the calculation into a
function and supply it with a comment.  The patch is attached.

Patch from todays CVS.
Compiles smooth.
Savegames identical.

Best,
G.

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
Index: ai/advmilitary.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advmilitary.c,v
retrieving revision 1.80
diff -u -r1.80 advmilitary.c
--- ai/advmilitary.c    2001/12/21 11:17:30     1.80
+++ ai/advmilitary.c    2002/01/03 13:12:29
@@ -603,9 +603,7 @@
           !unit_type_flag(i, F_IGWALL) && !city_got_citywalls(acity)) d *= 9; 
 
       f = unit_types[i].build_cost;
-      fprime = f * 2 * unit_types[i].attack_strength /
-           (unit_types[i].attack_strength +
-            unit_types[i].defense_strength);
+      fprime = build_cost_prime(i);
 
       if (acity) g = unit_list_size(&(map_get_tile(acity->x, 
acity->y)->units)) + 1;
       else g = 1;
@@ -802,9 +800,7 @@
     if (is_ground_unit(myunit) && !sanity && !boatid)
       needferry = 40; /* cost of ferry */
     f = unit_types[v].build_cost;
-    fprime = f * 2 * unit_types[v].attack_strength /
-           (unit_types[v].attack_strength +
-            unit_types[v].defense_strength);
+    fprime = build_cost_prime(v);
 
     if (acity) g = unit_list_size(&(map_get_tile(acity->x, acity->y)->units)) 
+ 1;
     else g = 1;
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.158
diff -u -r1.158 aiunit.c
--- ai/aiunit.c 2001/11/05 01:59:59     1.158
+++ ai/aiunit.c 2002/01/03 13:12:32
@@ -416,6 +416,25 @@
 }
 
 /**************************************************************************
+In the words of Syela:
+"Using funky fprime variable instead of f in the denom, so
+that def=1 units are penalized correctly."
+Translation (GB):
+build_cost_prime is used in the denominator of the want equation (see, e.g.
+find_something_to_kill) instead of just build_cost to make AI build more 
+balanced units.
+**************************************************************************/
+int build_cost_prime(Unit_Type_id i)
+{
+  int res;
+
+  res = 2 * unit_types[i].build_cost * unit_types[i].attack_strength /
+    (unit_types[i].attack_strength + unit_types[i].defense_strength);
+  return res;
+}
+
+
+/**************************************************************************
 ...
 **************************************************************************/
 static int unit_belligerence_primitive(struct unit *punit)
@@ -1229,9 +1248,7 @@
   if (unit_flag(punit, F_IGTER)) m *= SINGLE_MOVE;
   maxd = MIN(6, m) * THRESHOLD + 1;
   f = unit_type(punit)->build_cost;
-  fprime = f * 2 * unit_type(punit)->attack_strength /
-           (unit_type(punit)->attack_strength +
-            unit_type(punit)->defense_strength);
+  fprime = build_cost_prime(punit->type);
 
   generate_warmap(map_get_city(*x, *y), punit);
                              /* most flexible but costs milliseconds */
Index: ai/aiunit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.h,v
retrieving revision 1.24
diff -u -r1.24 aiunit.h
--- ai/aiunit.h 2001/01/10 18:50:45     1.24
+++ ai/aiunit.h 2002/01/03 13:12:32
@@ -29,6 +29,7 @@
                             int *x, int *y);
 int find_beachhead(struct unit *punit, int dest_x, int dest_y, int *x, int *y);
 
+int build_cost_prime(Unit_Type_id i);
 int unit_belligerence_basic(struct unit *punit);
 int unit_belligerence(struct unit *punit);
 int unit_vulnerability_basic(struct unit *punit, struct unit *pdef);

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