Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11328) put ut->upkeep into an array
Home

[Freeciv-Dev] (PR#11328) put ut->upkeep into an array

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11328) put ut->upkeep into an array
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 3 Dec 2004 19:04:33 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=11328 >

This patch puts the food_cost, shield_cost, and gold_cost values of the 
unit_type struct into an array.  This allows some things to be 
simplified (like the helpdlg where we can use an iteration to list the 
upkeeps).

-jason

Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.131
diff -u -r1.131 aitools.c
--- ai/aitools.c        30 Nov 2004 08:37:02 -0000      1.131
+++ ai/aitools.c        4 Dec 2004 03:02:35 -0000
@@ -402,8 +402,8 @@
        the greater good -- Per */
     return FALSE;
   }
-  if (pcity->surplus[O_SHIELD] - unit_type(punit)->shield_cost >= 0
-      && pcity->surplus[O_FOOD] - unit_type(punit)->food_cost >= 0) {
+  if (pcity->surplus[O_SHIELD] >= unit_type(punit)->upkeep[O_SHIELD]
+      && pcity->surplus[O_FOOD] >= unit_type(punit)->upkeep[O_FOOD]) {
     handle_unit_change_homecity(unit_owner(punit), punit->id, pcity->id);
     return TRUE;
   }
Index: ai/aiunit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.h,v
retrieving revision 1.55
diff -u -r1.55 aiunit.h
--- ai/aiunit.h 29 Sep 2004 02:24:18 -0000      1.55
+++ ai/aiunit.h 4 Dec 2004 03:02:35 -0000
@@ -38,9 +38,9 @@
 #define HOSTILE_PLAYER(pplayer, ai, aplayer) \
   (pplayers_at_war(pplayer, aplayer)         \
    || ai->diplomacy.target == aplayer)
-#define UNITTYPE_COSTS(ut)                             \
-  (ut->pop_cost * 3 + ut->happy_cost + ut->shield_cost \
-   + ut->food_cost + ut->gold_cost)
+#define UNITTYPE_COSTS(ut)                                             \
+  (ut->pop_cost * 3 + ut->happy_cost                                   \
+   + ut->upkeep[O_SHIELD] + ut->upkeep[O_FOOD] + ut->upkeep[O_GOLD])
 
 struct ai_choice;
 struct pf_path;
Index: client/helpdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/helpdata.c,v
retrieving revision 1.87
diff -u -r1.87 helpdata.c
--- client/helpdata.c   27 Nov 2004 18:48:26 -0000      1.87
+++ client/helpdata.c   4 Dec 2004 03:02:35 -0000
@@ -1168,6 +1168,7 @@
 {
   static char buf[128];
   struct unit_type *utype;
+  int any = 0;
 
   utype = get_unit_type(i);
   if (!utype) {
@@ -1176,33 +1177,26 @@
   }
 
 
-  if (utype->shield_cost > 0 || utype->food_cost > 0
-      || utype->gold_cost > 0 || utype->happy_cost > 0) {
-    int any = 0;
-    buf[0] = '\0';
-    if (utype->shield_cost > 0) {
-      sprintf(buf+strlen(buf), _("%s%d shield"),
-             (any > 0 ? ", " : ""), utype->shield_cost);
+  buf[0] = '\0';
+  output_type_iterate(o) {
+    if (utype->upkeep[o] > 0) {
+      /* TRANS: "2 Food" or ", 1 shield" */
+      cat_snprintf(buf, sizeof(buf), _("%s%d %s"),
+             (any > 0 ? ", " : ""), utype->upkeep[o],
+             get_output_name(o));
       any++;
     }
-    if (utype->food_cost > 0) {
-      sprintf(buf+strlen(buf), _("%s%d food"),
-             (any > 0 ? ", " : ""), utype->food_cost);
-      any++;
-    }
-    if (utype->happy_cost > 0) {
-      sprintf(buf+strlen(buf), _("%s%d unhappy"),
-             (any > 0 ? ", " : ""), utype->happy_cost);
-      any++;
-    }
-    if (utype->gold_cost > 0) {
-      sprintf(buf+strlen(buf), _("%s%d gold"),
-             (any > 0 ? ", " : ""), utype->gold_cost);
-      any++;
-    }
-  } else {
+  } output_type_iterate_end;
+  if (utype->happy_cost > 0) {
+    /* TRANS: "2 unhappy" or ", 1 unhappy" */
+    cat_snprintf(buf, sizeof(buf), _("%s%d unhappy"),
+           (any > 0 ? ", " : ""), utype->happy_cost);
+    any++;
+  }
+
+  if (any == 0) {
     /* strcpy(buf, _("None")); */
-    sprintf(buf, "%d", 0);
+    snprintf(buf, sizeof(buf), "%d", 0);
   }
   return buf;
 }
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.431
diff -u -r1.431 packhand.c
--- client/packhand.c   4 Dec 2004 00:29:37 -0000       1.431
+++ client/packhand.c   4 Dec 2004 03:02:36 -0000
@@ -2228,9 +2228,9 @@
   u->flags              = p->flags;
   u->roles              = p->roles;
   u->happy_cost         = p->happy_cost;
-  u->shield_cost        = p->shield_cost;
-  u->food_cost          = p->food_cost;
-  u->gold_cost          = p->gold_cost;
+  output_type_iterate(o) {
+    u->upkeep[o] = p->upkeep[o];
+  } output_type_iterate_end;
   u->paratroopers_range = p->paratroopers_range;
   u->paratroopers_mr_req = p->paratroopers_mr_req;
   u->paratroopers_mr_sub = p->paratroopers_mr_sub;
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.63
diff -u -r1.63 packets.def
--- common/packets.def  4 Dec 2004 00:29:37 -0000       1.63
+++ common/packets.def  4 Dec 2004 03:02:36 -0000
@@ -948,9 +948,7 @@
   UINT8 fuel;
 
   UINT8 happy_cost;   # unhappy people in home city
-  UINT8 shield_cost;   # normal upkeep cost
-  UINT8 food_cost;   # settler food cost
-  UINT8 gold_cost;   # gold upkeep (n/a now, maybe later)
+  UINT8 upkeep[O_MAX]; # normal upkeep cost (food, gold, shields)
 
   UINT8 paratroopers_range;  # max range of paratroopers, F_PARATROOPERS
   UINT8 paratroopers_mr_req;
Index: common/unittype.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.c,v
retrieving revision 1.42
diff -u -r1.42 unittype.c
--- common/unittype.c   25 Nov 2004 05:34:35 -0000      1.42
+++ common/unittype.c   4 Dec 2004 03:02:36 -0000
@@ -124,7 +124,7 @@
       BV_ISSET(ut->flags, F_FANATIC)) {
     return 0;
   }
-  return ut->shield_cost * g->unit_shield_cost_factor;
+  return ut->upkeep[O_SHIELD] * g->unit_shield_cost_factor;
 }
 
 /**************************************************************************
@@ -132,7 +132,7 @@
 **************************************************************************/
 int utype_food_cost(struct unit_type *ut, struct government *g)
 {
-  return ut->food_cost * g->unit_food_cost_factor;
+  return ut->upkeep[O_FOOD] * g->unit_food_cost_factor;
 }
 
 /**************************************************************************
@@ -148,7 +148,7 @@
 **************************************************************************/
 int utype_gold_cost(struct unit_type *ut, struct government *g)
 {
-  return ut->gold_cost * g->unit_gold_cost_factor;
+  return ut->upkeep[O_GOLD] * g->unit_gold_cost_factor;
 }
 
 /**************************************************************************
Index: common/unittype.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.h,v
retrieving revision 1.34
diff -u -r1.34 unittype.h
--- common/unittype.h   25 Nov 2004 05:34:35 -0000      1.34
+++ common/unittype.h   4 Dec 2004 03:02:36 -0000
@@ -203,9 +203,7 @@
   bv_roles roles;
 
   int happy_cost;  /* unhappy people in home city */
-  int shield_cost; /* normal upkeep cost */
-  int food_cost;   /* settler food cost */
-  int gold_cost;   /* gold upkeep */
+  int upkeep[O_MAX];
 
   int paratroopers_range; /* only valid for F_PARATROOPERS */
   int paratroopers_mr_req;
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.276
diff -u -r1.276 cityturn.c
--- server/cityturn.c   30 Nov 2004 08:37:03 -0000      1.276
+++ server/cityturn.c   4 Dec 2004 03:02:37 -0000
@@ -540,7 +540,7 @@
      * reserves.  Hence, I'll assume food upkeep > 0 units. -- jjm
      */
     unit_list_iterate_safe(pcity->units_supported, punit) {
-      if (unit_type(punit)->food_cost > 0 
+      if (unit_type(punit)->upkeep[O_FOOD] > 0 
           && !unit_flag(punit, F_UNDISBANDABLE)) {
        const char *utname = unit_type(punit)->name;
        wipe_unit(punit);
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.208
diff -u -r1.208 ruleset.c
--- server/ruleset.c    4 Dec 2004 00:29:38 -0000       1.208
+++ server/ruleset.c    4 Dec 2004 03:02:37 -0000
@@ -943,9 +943,10 @@
     u->fuel = secfile_lookup_int(file,"%s.fuel", sec[i]);
 
     u->happy_cost  = secfile_lookup_int(file, "%s.uk_happy", sec[i]);
-    u->shield_cost = secfile_lookup_int(file, "%s.uk_shield", sec[i]);
-    u->food_cost   = secfile_lookup_int(file, "%s.uk_food", sec[i]);
-    u->gold_cost   = secfile_lookup_int(file, "%s.uk_gold", sec[i]);
+    output_type_iterate(o) {
+      u->upkeep[o] = secfile_lookup_int_default(file, 0, "%s.uk_%s", sec[i],
+                                               get_output_identifier(o));
+    } output_type_iterate_end;
 
     u->helptext = lookup_helptext(file, sec[i]);
 
@@ -2812,9 +2813,9 @@
     packet.flags = u->flags;
     packet.roles = u->roles;
     packet.happy_cost = u->happy_cost;
-    packet.shield_cost = u->shield_cost;
-    packet.food_cost = u->food_cost;
-    packet.gold_cost = u->gold_cost;
+    output_type_iterate(o) {
+      packet.upkeep[o] = u->upkeep[o];
+    } output_type_iterate_end;
     packet.paratroopers_range = u->paratroopers_range;
     packet.paratroopers_mr_req = u->paratroopers_mr_req;
     packet.paratroopers_mr_sub = u->paratroopers_mr_sub;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11328) put ut->upkeep into an array, Jason Short <=