Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2005:
[Freeciv-Dev] (PR#13572) change city/worklist API to use city_production
Home

[Freeciv-Dev] (PR#13572) change city/worklist API to use city_production

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13572) change city/worklist API to use city_production structs
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 30 Jul 2005 19:05:41 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch changes functions in the city, citydlg, and worklist API to
use city_production struct values instead of (id,value) pairs.  This is
more legible and less bug-prone since it's typesafe.

-jason

Index: ai/aiferry.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiferry.c,v
retrieving revision 1.24
diff -p -u -r1.24 aiferry.c
--- ai/aiferry.c        26 Jul 2005 16:35:56 -0000      1.24
+++ ai/aiferry.c        31 Jul 2005 02:02:50 -0000
@@ -773,8 +773,7 @@ static bool aiferry_find_interested_city
                && unit_has_role(get_unit_type(pcity->production.value),
                                 L_FERRYBOAT)))) {
       bool really_needed = TRUE;
-      int turns = city_turns_to_build(pcity, pcity->production.value,
-                                      pcity->production.is_unit, TRUE);
+      int turns = city_turns_to_build(pcity, pcity->production, TRUE);
 
       UNIT_LOG(LOGLEVEL_FERRY, pferry, "%s (%d, %d) looks promising...", 
                pcity->name, TILE_XY(pcity->tile));
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.84
diff -p -u -r1.84 citydlg_common.c
--- client/citydlg_common.c     28 Jul 2005 17:59:06 -0000      1.84
+++ client/citydlg_common.c     31 Jul 2005 02:02:50 -0000
@@ -214,8 +214,7 @@ void get_city_dialog_production(struct c
     return;
   }
 
-  turns = city_turns_to_build(pcity, pcity->production.value,
-                             pcity->production.is_unit, TRUE);
+  turns = city_turns_to_build(pcity, pcity->production, TRUE);
   stock = pcity->shield_stock;
 
   if (pcity->production.is_unit) {
@@ -230,7 +229,7 @@ void get_city_dialog_production(struct c
   } else {
     char time[50];
 
-    if (turns < 999) {
+    if (turns < FC_INFINITY) {
       if (concise_city_production) {
        my_snprintf(time, sizeof(time), "%3d", turns);
       } else {
@@ -262,27 +261,28 @@ void get_city_dialog_production(struct c
  less flexibility.
 **************************************************************************/
 void get_city_dialog_production_full(char *buffer, size_t buffer_len,
-                                    int id, bool is_unit,
+                                    struct city_production target,
                                     struct city *pcity)
 {
-  if (!is_unit && building_has_effect(id, EFT_PROD_TO_GOLD)) {
+  if (!target.is_unit
+      && building_has_effect(target.value, EFT_PROD_TO_GOLD)) {
     my_snprintf(buffer, buffer_len, _("%s (XX) %d/turn"),
-               get_impr_name_ex(pcity, id),
+               get_impr_name_ex(pcity, target.value),
                MAX(0, pcity->surplus[O_SHIELD]));
   } else {
-    int turns = city_turns_to_build(pcity, id, is_unit, TRUE);
+    int turns = city_turns_to_build(pcity, target, TRUE);
     const char *name;
     int cost;
 
-    if (is_unit) {
-      name = get_unit_name(get_unit_type(id));
-      cost = unit_build_shield_cost(get_unit_type(id));
+    if (target.is_unit) {
+      name = get_unit_name(get_unit_type(target.value));
+      cost = unit_build_shield_cost(get_unit_type(target.value));
     } else {
-      name = get_impr_name_ex(pcity, id);
-      cost = impr_build_shield_cost(id);
+      name = get_impr_name_ex(pcity, target.value);
+      cost = impr_build_shield_cost(target.value);
     }
 
-    if (turns < 999) {
+    if (turns < FC_INFINITY) {
       my_snprintf(buffer, buffer_len,
                  PL_("%s (%d) %d turn", "%s (%d) %d turns", turns),
                  name, cost, turns);
@@ -297,11 +297,12 @@ void get_city_dialog_production_full(cha
  cost, turns to build). The columns must each have a size of
  column_size bytes.
 **************************************************************************/
-void get_city_dialog_production_row(char *buf[], size_t column_size, int id,
-                                   bool is_unit, struct city *pcity)
+void get_city_dialog_production_row(char *buf[], size_t column_size,
+                                   struct city_production target,
+                                   struct city *pcity)
 {
-  if (is_unit) {
-    struct unit_type *ptype = get_unit_type(id);
+  if (target.is_unit) {
+    struct unit_type *ptype = get_unit_type(target.value);
 
     my_snprintf(buf[0], column_size, unit_name(ptype));
 
@@ -320,34 +321,34 @@ void get_city_dialog_production_row(char
     struct player *pplayer = game.player_ptr;
 
     /* Total & turns left meaningless on capitalization */
-    if (building_has_effect(id, EFT_PROD_TO_GOLD)) {
-      my_snprintf(buf[0], column_size, get_improvement_name(id));
+    if (building_has_effect(target.value, EFT_PROD_TO_GOLD)) {
+      my_snprintf(buf[0], column_size, get_improvement_name(target.value));
       buf[1][0] = '\0';
       my_snprintf(buf[2], column_size, "---");
     } else {
-      my_snprintf(buf[0], column_size, get_improvement_name(id));
+      my_snprintf(buf[0], column_size, get_improvement_name(target.value));
 
       /* from city.c get_impr_name_ex() */
-      if (pcity && is_building_replaced(pcity, id)) {
+      if (pcity && is_building_replaced(pcity, target.value)) {
        my_snprintf(buf[1], column_size, "*");
       } else {
        const char *state = "";
 
-       if (is_great_wonder(id)) {
-          if (improvement_obsolete(pplayer, id)) {
+       if (is_great_wonder(target.value)) {
+          if (improvement_obsolete(pplayer, target.value)) {
             state = _("Obsolete");
-          } else if (great_wonder_was_built(id)) {
+          } else if (great_wonder_was_built(target.value)) {
             state = _("Built");
           } else {
             state = _("Great Wonder");
           }
        }
-       if (is_small_wonder(id)) {
+       if (is_small_wonder(target.value)) {
          state = _("Small Wonder");
-         if (find_city_from_small_wonder(pplayer, id)) {
+         if (find_city_from_small_wonder(pplayer, target.value)) {
            state = _("Built");
          }
-         if (improvement_obsolete(pplayer, id)) {
+         if (improvement_obsolete(pplayer, target.value)) {
            state = _("Obsolete");
          }
        }
@@ -355,18 +356,20 @@ void get_city_dialog_production_row(char
       }
 
       my_snprintf(buf[2], column_size, "%d",
-                 impr_build_shield_cost(id));
+                 impr_build_shield_cost(target.value));
     }
   }
 
   /* Add the turns-to-build entry in the 4th position */
   if (pcity) {
-    if (!is_unit && building_has_effect(id, EFT_PROD_TO_GOLD)) {
+    if (!target.is_unit
+       && building_has_effect(target.value, EFT_PROD_TO_GOLD)) {
       my_snprintf(buf[3], column_size, _("%d/turn"),
                  MAX(0, pcity->surplus[O_SHIELD]));
     } else {
-      int turns = city_turns_to_build(pcity, id, is_unit, FALSE);
-      if (turns < 999) {
+      int turns = city_turns_to_build(pcity, target, FALSE);
+
+      if (turns < FC_INFINITY) {
        my_snprintf(buf[3], column_size, "%d", turns);
       } else {
        my_snprintf(buf[3], column_size, "%s", _("never"));
@@ -598,10 +601,10 @@ void activate_all_units(struct tile *pti
 /**************************************************************************
   Change the production of a given city.  Return the request ID.
 **************************************************************************/
-int city_change_production(struct city *pcity, bool is_unit, int build_id)
+int city_change_production(struct city *pcity, struct city_production target)
 {
-  return dsend_packet_city_change(&aconnection, pcity->id, build_id,
-                                 is_unit);
+  return dsend_packet_city_change(&aconnection, pcity->id,
+                                 target.value, target.is_unit);
 }
 
 /**************************************************************************
@@ -631,52 +634,50 @@ int city_set_worklist(struct city *pcity
   Note that the queue DOES include the current production.
 **************************************************************************/
 static bool base_city_queue_insert(struct city *pcity, int position,
-                                  bool item_is_unit, int item_id)
+                                  struct city_production item)
 {
   if (position == 0) {
-    int old_id;
-    bool old_is_unit;
+    struct city_production old = pcity->production;
 
     /* Insert as current production. */
-    if (item_is_unit
-       && !can_build_unit_direct(pcity, get_unit_type(item_id))) {
+    if (item.is_unit
+       && !can_build_unit_direct(pcity, get_unit_type(item.value))) {
       return FALSE;
     }
-    if (!item_is_unit && !can_build_improvement_direct(pcity, item_id)) {
+    if (!item.is_unit && !can_build_improvement_direct(pcity, item.value)) {
       return FALSE;
     }
 
-    old_id = pcity->production.value;
-    old_is_unit = pcity->production.is_unit;
-    if (!worklist_insert(&pcity->worklist, old_id, old_is_unit, 0)) {
+    if (!worklist_insert(&pcity->worklist, old, 0)) {
       return FALSE;
     }
 
-    city_change_production(pcity, item_is_unit, item_id);
+    city_change_production(pcity, item);
   } else if (position >= 1
             && position <= worklist_length(&pcity->worklist)) {
     /* Insert into middle. */
-    if (item_is_unit
-       && !can_eventually_build_unit(pcity, get_unit_type(item_id))) {
+    if (item.is_unit
+       && !can_eventually_build_unit(pcity, get_unit_type(item.value))) {
       return FALSE;
     }
-    if (!item_is_unit && !can_eventually_build_improvement(pcity, item_id)) {
+    if (!item.is_unit
+       && !can_eventually_build_improvement(pcity, item.value)) {
       return FALSE;
     }
-    if (!worklist_insert(&pcity->worklist, item_id, item_is_unit,
-                        position - 1)) {
+    if (!worklist_insert(&pcity->worklist, item, position - 1)) {
       return FALSE;
     }
   } else {
     /* Insert at end. */
-    if (item_is_unit
-       && !can_eventually_build_unit(pcity, get_unit_type(item_id))) {
+    if (item.is_unit
+       && !can_eventually_build_unit(pcity, get_unit_type(item.value))) {
       return FALSE;
     }
-    if (!item_is_unit && !can_eventually_build_improvement(pcity, item_id)) {
+    if (!item.is_unit
+       && !can_eventually_build_improvement(pcity, item.value)) {
       return FALSE;
     }
-    if (!worklist_append(&pcity->worklist, item_id, item_is_unit)) {
+    if (!worklist_append(&pcity->worklist, item)) {
       return FALSE;
     }
   }
@@ -689,9 +690,9 @@ static bool base_city_queue_insert(struc
   Note that the queue DOES include the current production.
 **************************************************************************/
 bool city_queue_insert(struct city *pcity, int position,
-                      bool item_is_unit, int item_id)
+                      struct city_production item)
 {
-  if (base_city_queue_insert(pcity, position, item_is_unit, item_id)) {
+  if (base_city_queue_insert(pcity, position, item)) {
     city_set_worklist(pcity, &pcity->worklist);
     return TRUE;
   }
@@ -725,8 +726,8 @@ bool city_queue_insert_worklist(struct c
     return TRUE;
   }
 
-  worklist_iterate(worklist, id, is_unit) {
-    if (base_city_queue_insert(pcity, position, is_unit, id)) {
+  worklist_iterate(worklist, target) {
+    if (base_city_queue_insert(pcity, position, target)) {
       if (position > 0) {
        /* Move to the next position (unless position == -1 in which case
         * we're appending. */
@@ -748,9 +749,6 @@ bool city_queue_insert_worklist(struct c
 **************************************************************************/
 void city_get_queue(struct city *pcity, struct worklist *pqueue)
 {
-  int id;
-  bool is_unit;
-
   copy_worklist(pqueue, &pcity->worklist);
 
   /* The GUI wants current production to be in the task list, but the
@@ -760,9 +758,7 @@ void city_get_queue(struct city *pcity, 
   /* We want the current production to be in the queue. Always. */
   worklist_remove(pqueue, MAX_LEN_WORKLIST - 1);
 
-  id = pcity->production.value;
-  is_unit = pcity->production.is_unit;
-  worklist_insert(pqueue, id, is_unit, 0);
+  worklist_insert(pqueue, pcity->production, 0);
 }
 
 /**************************************************************************
@@ -771,19 +767,18 @@ void city_get_queue(struct city *pcity, 
 void city_set_queue(struct city *pcity, struct worklist *pqueue)
 {
   struct worklist copy;
-  int id;
-  bool is_unit;
+  struct city_production target;
 
   copy_worklist(&copy, pqueue);
 
   /* The GUI wants current production to be in the task list, but the
      worklist API wants it out for reasons unknown. Perhaps someone enjoyed
      making things more complicated than necessary? So I dance around it. */
-  if (worklist_peek(&copy, &id, &is_unit)) {
+  if (worklist_peek(&copy, &target)) {
     worklist_advance(&copy);
 
     city_set_worklist(pcity, &copy);
-    city_change_production(pcity, is_unit, id);
+    city_change_production(pcity, target);
   } else {
     /* You naughty boy, you can't erase the current production. Nyah! */
     if (worklist_is_empty(&pcity->worklist)) {
Index: client/citydlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.h,v
retrieving revision 1.31
diff -p -u -r1.31 citydlg_common.h
--- client/citydlg_common.h     30 Apr 2005 17:09:25 -0000      1.31
+++ client/citydlg_common.h     31 Jul 2005 02:02:50 -0000
@@ -51,10 +51,11 @@ void city_dialog_redraw_map(struct city 
 void get_city_dialog_production(struct city *pcity,
                                 char *buffer, size_t buffer_len);
 void get_city_dialog_production_full(char *buffer, size_t buffer_len,
-                                    int id, bool is_unit,
+                                    struct city_production target,
                                     struct city *pcity);
-void get_city_dialog_production_row(char *buf[], size_t column_size, int id,
-                                   bool is_unit, struct city *pcity);
+void get_city_dialog_production_row(char *buf[], size_t column_size,
+                                   struct city_production target,
+                                   struct city *pcity);
 
 void get_city_dialog_output_text(const struct city *pcity,
                                 Output_type_id otype,
@@ -68,10 +69,10 @@ void city_rotate_specialist(struct city 
 
 void activate_all_units(struct tile *ptile);
 
-int city_change_production(struct city *pcity, bool is_unit, int build_id);
+int city_change_production(struct city *pcity, struct city_production target);
 int city_set_worklist(struct city *pcity, struct worklist *pworklist);
 bool city_queue_insert(struct city *pcity, int position,
-                      bool item_is_unit, int item_id);
+                      struct city_production target);
 bool city_queue_clear(struct city *pcity);
 bool city_queue_insert_worklist(struct city *pcity, int position,
                                struct worklist *worklist);
Index: client/cityrepdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/cityrepdata.c,v
retrieving revision 1.53
diff -p -u -r1.53 cityrepdata.c
--- client/cityrepdata.c        26 Jul 2005 16:35:56 -0000      1.53
+++ client/cityrepdata.c        31 Jul 2005 02:02:51 -0000
@@ -363,8 +363,7 @@ static const char *cr_entry_building(con
                get_impr_name_ex(pcity, pcity->production.value),
                MAX(0, pcity->surplus[O_SHIELD]), from_worklist);
   } else {
-    int turns = city_turns_to_build(pcity, pcity->production.value,
-                                   pcity->production.is_unit, TRUE);
+    int turns = city_turns_to_build(pcity, pcity->production, TRUE);
     char time[32];
     const char *name;
     int cost;
Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.173
diff -p -u -r1.173 climisc.c
--- client/climisc.c    28 Jul 2005 19:02:09 -0000      1.173
+++ client/climisc.c    31 Jul 2005 02:02:51 -0000
@@ -158,34 +158,28 @@ could be improvements or units. X and Y 
 **************************************************************************/
 void client_change_all(cid x, cid y)
 {
-  int fr_id = cid_id(x), to_id = cid_id(y);
-  bool fr_is_unit = cid_is_unit(x), to_is_unit = cid_is_unit(y);
+  struct city_production from = cid_production(x), to = cid_production(y);
   char buf[512];
   int last_request_id = 0;
 
   my_snprintf(buf, sizeof(buf),
              _("Changing production of every %s into %s."),
-             fr_is_unit ? get_unit_type(fr_id)->name :
-             get_improvement_name(fr_id),
-             to_is_unit ? get_unit_type(to_id)->
-             name : get_improvement_name(to_id));
+             from.is_unit ? get_unit_type(from.value)->name
+             : get_improvement_name(from.value),
+             to.is_unit ? get_unit_type(to.value)->name
+             : get_improvement_name(to.value));
   append_output_window(buf);
 
   connection_do_buffer(&aconnection);
   city_list_iterate (game.player_ptr->cities, pcity) {
-    if (((fr_is_unit &&
-         (pcity->production.is_unit) &&
-         (pcity->production.value == fr_id)) ||
-        (!fr_is_unit &&
-         !(pcity->production.is_unit) &&
-         (pcity->production.value == fr_id))) &&
-       ((to_is_unit &&
-         can_build_unit (pcity, get_unit_type(to_id))) ||
-        (!to_is_unit &&
-         can_build_improvement (pcity, to_id))))
-      {
-       last_request_id = city_change_production(pcity, to_is_unit, to_id);
-      }
+    if (from.is_unit == pcity->production.is_unit
+       && from.value == pcity->production.value
+       && ((to.is_unit
+            && can_build_unit(pcity, get_unit_type(to.value)))
+           || (!to.is_unit
+               && can_build_improvement(pcity, to.value)))) {
+      last_request_id = city_change_production(pcity, to);
+    }
   } city_list_iterate_end;
 
   connection_do_unbuffer(&aconnection);
@@ -483,6 +477,20 @@ int cid_id(cid cid)
   return (cid >= B_LAST) ? (cid - B_LAST) : cid;
 }
 
+/****************************************************************************
+  Return a city_production struct for the given cid.
+
+  This is a temporary sort of measure since hopefully the city_production
+  will someday replace the cid entirely.
+****************************************************************************/
+struct city_production cid_production(cid cid)
+{
+  struct city_production prod = {.is_unit = cid_is_unit(cid),
+                                .value = cid_id(cid)};
+
+  return prod;
+}
+
 /**************************************************************************
 ...
 **************************************************************************/
Index: client/climisc.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.h,v
retrieving revision 1.56
diff -p -u -r1.56 climisc.h
--- client/climisc.h    28 Mar 2005 16:59:14 -0000      1.56
+++ client/climisc.h    31 Jul 2005 02:02:51 -0000
@@ -56,6 +56,7 @@ cid cid_encode_from_city(struct city *pc
 void cid_decode(cid cid, bool *is_unit, int *id);
 bool cid_is_unit(cid cid);
 int cid_id(cid cid);
+struct city_production cid_production(cid cid);
 
 /* 
  * A worklist id (wid) can hold all objects which can be part of a
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.241
diff -p -u -r1.241 mapview_common.c
--- client/mapview_common.c     26 Jul 2005 16:35:56 -0000      1.241
+++ client/mapview_common.c     31 Jul 2005 02:02:51 -0000
@@ -1888,8 +1888,7 @@ struct city *find_city_near_tile(const s
 void get_city_mapview_production(struct city *pcity,
                                  char *buffer, size_t buffer_len)
 {
-  int turns = city_turns_to_build(pcity, pcity->production.value,
-                                 pcity->production.is_unit, TRUE);
+  int turns = city_turns_to_build(pcity, pcity->production, TRUE);
                                
   if (pcity->production.is_unit) {
     struct unit_type *punit_type =
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/citydlg.c,v
retrieving revision 1.135
diff -p -u -r1.135 citydlg.c
--- client/gui-gtk-2.0/citydlg.c        26 Jul 2005 16:35:57 -0000      1.135
+++ client/gui-gtk-2.0/citydlg.c        31 Jul 2005 02:02:52 -0000
@@ -879,7 +879,7 @@ target_drag_data_received(GtkWidget *w, 
     if (gtk_tree_model_get_iter(model, &it, path)) {
       cid cid;
       gtk_tree_model_get(model, &it, 0, &cid, -1);
-      city_change_production(pdialog->pcity, cid_is_unit(cid), cid_id(cid));
+      city_change_production(pdialog->pcity, cid_production(cid));
       gtk_drag_finish(context, TRUE, FALSE, time);
     }
     gtk_tree_path_free(path);
@@ -2457,7 +2457,7 @@ static void change_production_callback(G
       gtk_tree_model_get(
         GTK_TREE_MODEL(pdial->overview.change_production_store),
         &iter, 2, &cid, -1);
-      city_change_production(pdial->pcity, cid_is_unit(cid), cid_id(cid)); 
+      city_change_production(pdial->pcity, cid_production(cid)); 
     }
 }
 
Index: client/gui-gtk-2.0/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/cityrep.c,v
retrieving revision 1.75
diff -p -u -r1.75 cityrep.c
--- client/gui-gtk-2.0/cityrep.c        26 Jul 2005 16:35:57 -0000      1.75
+++ client/gui-gtk-2.0/cityrep.c        31 Jul 2005 02:02:52 -0000
@@ -270,8 +270,9 @@ static void append_impr_or_unit_to_menu_
     GtkWidget *menu_item, *hbox, *label;
     char txt[256];
 
-    get_city_dialog_production_row(row, sizeof(buf[0]), cid_id(cid),
-                                  cid_is_unit(cid), NULL);
+    get_city_dialog_production_row(row, sizeof(buf[0]), cid_production(cid),
+                                  NULL);
+
 
     menu_item = gtk_menu_item_new();
     hbox = gtk_hbox_new(FALSE, 18);
@@ -323,7 +324,7 @@ static void impr_or_unit_iterate(GtkTree
 
   gtk_tree_model_get(model, it, 1, &id, -1);
 
-  city_change_production(find_city_by_id(id), cid_is_unit(cid), cid_id(cid));
+  city_change_production(find_city_by_id(id), cid_production(cid));
 }
 
 /****************************************************************
@@ -344,7 +345,7 @@ static void worklist_last_impr_or_unit_i
   gtk_tree_model_get(model, it, 1, &id, -1);
   pcity = find_city_by_id(id);
 
-  (void) city_queue_insert(pcity, -1, cid_is_unit(cid), cid_id(cid));
+  (void) city_queue_insert(pcity, -1, cid_production(cid));
   /* perhaps should warn the user if not successful? */
 }
 
@@ -368,7 +369,7 @@ static void worklist_first_impr_or_unit_
   gtk_tree_model_get(model, it, 1, &id, -1);
   pcity = find_city_by_id(id);
 
-  (void) city_queue_insert(pcity, 0, cid_is_unit(cid), cid_id(cid));
+  (void) city_queue_insert(pcity, 0, cid_production(cid));
   /* perhaps should warn the user if not successful? */
 }
 
@@ -390,7 +391,7 @@ static void worklist_next_impr_or_unit_i
   gtk_tree_model_get(model, it, 1, &id, -1);
   pcity = find_city_by_id(id);
 
-  (void) city_queue_insert(pcity, 1, cid_is_unit(cid), cid_id(cid));
+  (void) city_queue_insert(pcity, 1, cid_production(cid));
   /* perhaps should warn the user if not successful? */
 }
 
Index: client/gui-gtk-2.0/wldlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/wldlg.c,v
retrieving revision 1.47
diff -p -u -r1.47 wldlg.c
--- client/gui-gtk-2.0/wldlg.c  28 Jul 2005 17:59:06 -0000      1.47
+++ client/gui-gtk-2.0/wldlg.c  31 Jul 2005 02:02:52 -0000
@@ -585,7 +585,7 @@ static void change_callback(GtkWidget *w
 
     gtk_tree_model_get(model, &it, 0, &cid, -1);
 
-    city_change_production(ptr->pcity, cid_is_unit(cid), cid_id(cid));
+    city_change_production(ptr->pcity, cid_production(cid));
   }
 }
 
@@ -950,17 +950,16 @@ static void cell_render_func(GtkTreeView
                             GtkTreeModel *model, GtkTreeIter *it,
                             gpointer data)
 {
-  gint cid, id;
-  bool is_unit;
+  gint cid;
+  struct city_production target;
 
   gtk_tree_model_get(model, it, 0, &cid, -1);
-  is_unit = cid_is_unit(cid);
-  id = cid_id(cid);
+  target = cid_production(cid);
 
   if (GTK_IS_CELL_RENDERER_PIXBUF(rend)) {
     GdkPixbuf *pix;
 
-    if (is_unit) {
+    if (target.is_unit) {
       struct canvas store;
 
       pix = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8,
@@ -968,18 +967,18 @@ static void cell_render_func(GtkTreeView
 
       store.type = CANVAS_PIXBUF;
       store.v.pixbuf = pix;
-      create_overlay_unit(&store, get_unit_type(id));
+      create_overlay_unit(&store, get_unit_type(target.value));
 
       g_object_set(rend, "pixbuf", pix, NULL);
       g_object_unref(pix);
     } else {
-      struct sprite *sprite = get_building_sprite(tileset, id);
+      struct sprite *sprite = get_building_sprite(tileset, target.value);
 
       pix = sprite_get_pixbuf(sprite);
       g_object_set(rend, "pixbuf", pix, NULL);
     }
   } else {
-    struct city **pcity;
+    struct city **pcity = data;
     struct player *plr;
     gint column;
     char *row[4];
@@ -987,20 +986,18 @@ static void cell_render_func(GtkTreeView
     int   i;
     gboolean useless;
 
-    pcity = (struct city **) data;
-
     for (i = 0; i < ARRAY_SIZE(row); i++) {
       row[i] = buf[i];
     }
     column = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(rend), "column"));
 
-    get_city_dialog_production_row(row, sizeof(buf[0]), id, is_unit, *pcity);
+    get_city_dialog_production_row(row, sizeof(buf[0]), target, *pcity);
     g_object_set(rend, "text", row[column], NULL);
 
-    if (!is_unit && *pcity) {
+    if (!target.is_unit && *pcity) {
       plr = city_owner(*pcity);
-      useless = improvement_obsolete(plr, id)
-       || is_building_replaced(*pcity, id);
+      useless = improvement_obsolete(plr, target.value)
+       || is_building_replaced(*pcity, target.value);
       g_object_set(rend, "strikethrough", useless, NULL);
     } else {
       g_object_set(rend, "strikethrough", FALSE, NULL);
@@ -1471,7 +1468,7 @@ static void commit_worklist(struct workl
 
       gtk_tree_model_get(model, &it, 0, &cid, -1);
 
-      worklist_append(&queue, cid_id(cid), cid_is_unit(cid));
+      worklist_append(&queue, cid_production(cid));
 
       i++;
     } while (gtk_tree_model_iter_next(model, &it));
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.362
diff -p -u -r1.362 city.c
--- common/city.c       30 Jul 2005 05:10:01 -0000      1.362
+++ common/city.c       31 Jul 2005 02:02:53 -0000
@@ -1201,7 +1201,7 @@ bool city_style_has_requirements(const s
  original improvement class of this turn, restore lost production.
 **************************************************************************/
 int city_change_production_penalty(const struct city *pcity,
-                                  int target, bool is_unit)
+                                  struct city_production target)
 {
   int shield_stock_after_adjustment;
   enum production_class_type orig_class;
@@ -1216,12 +1216,13 @@ int city_change_production_penalty(const
     orig_class = TYPE_NORMAL_IMPROVEMENT;
   }
 
-  if (is_unit)
-    new_class=TYPE_UNIT;
-  else if (is_wonder(target))
-    new_class=TYPE_WONDER;
-  else
-    new_class=TYPE_NORMAL_IMPROVEMENT;
+  if (target.is_unit) {
+    new_class = TYPE_UNIT;
+  } else if (is_wonder(target.value)) {
+    new_class = TYPE_WONDER;
+  } else {
+    new_class = TYPE_NORMAL_IMPROVEMENT;
+  }
 
   /* Changing production is penalized under certain circumstances. */
   if (orig_class == new_class) {
@@ -1261,23 +1262,23 @@ int city_change_production_penalty(const
  Calculates the turns which are needed to build the requested
  improvement in the city.  GUI Independent.
 **************************************************************************/
-int city_turns_to_build(const struct city *pcity, int id, bool id_is_unit,
+int city_turns_to_build(const struct city *pcity,
+                       struct city_production target,
                        bool include_shield_stock)
 {
   int city_shield_surplus = pcity->surplus[O_SHIELD];
   int city_shield_stock = include_shield_stock ?
-      city_change_production_penalty(pcity, id, id_is_unit) : 0;
-  int improvement_cost = id_is_unit ?
-    unit_build_shield_cost(get_unit_type(id)) : impr_build_shield_cost(id);
+      city_change_production_penalty(pcity, target) : 0;
+  int cost = (target.is_unit
+             ? unit_build_shield_cost(get_unit_type(target.value))
+             : impr_build_shield_cost(target.value));
 
-  if (include_shield_stock && (city_shield_stock >= improvement_cost)) {
+  if (include_shield_stock && (city_shield_stock >= cost)) {
     return 1;
   } else if (city_shield_surplus > 0) {
-    return
-      (improvement_cost - city_shield_stock + city_shield_surplus - 1) /
-      city_shield_surplus;
+    return (cost - city_shield_stock - 1) / city_shield_surplus + 1;
   } else {
-    return 999;
+    return FC_INFINITY;
   }
 }
 
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.222
diff -p -u -r1.222 city.h
--- common/city.h       30 Jul 2005 05:10:01 -0000      1.222
+++ common/city.h       31 Jul 2005 02:02:54 -0000
@@ -388,9 +388,10 @@ bool is_capital(const struct city *pcity
 bool city_got_citywalls(const struct city *pcity);
 bool building_replaced(const struct city *pcity, Impr_type_id id);
 int city_change_production_penalty(const struct city *pcity,
-                                  int target, bool is_unit);
-int city_turns_to_build(const struct city *pcity, int id, bool id_is_unit,
-                        bool include_shield_stock );
+                                  struct city_production target);
+int city_turns_to_build(const struct city *pcity,
+                       struct city_production target,
+                        bool include_shield_stock);
 int city_turns_to_grow(const struct city *pcity);
 bool city_can_grow_to(const struct city *pcity, int pop_size);
 
Index: common/dataio.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/dataio.c,v
retrieving revision 1.21
diff -p -u -r1.21 dataio.c
--- common/dataio.c     28 Jul 2005 17:59:06 -0000      1.21
+++ common/dataio.c     31 Jul 2005 02:02:54 -0000
@@ -650,12 +650,11 @@ void dio_get_worklist(struct data_in *di
 
     dio_get_uint8(din, &length);
     for (i = 0; i < length; i++) {
-      bool is_unit;
-      int value;
+      struct city_production prod;
 
-      dio_get_bool8(din, &is_unit);
-      dio_get_uint8(din, &value);
-      worklist_append(pwl, value, is_unit);
+      dio_get_bool8(din, &prod.is_unit);
+      dio_get_uint8(din, &prod.value);
+      worklist_append(pwl, prod);
     }
   }
 }
Index: common/worklist.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/worklist.c,v
retrieving revision 1.19
diff -p -u -r1.19 worklist.c
--- common/worklist.c   28 Jul 2005 17:59:06 -0000      1.19
+++ common/worklist.c   31 Jul 2005 02:02:54 -0000
@@ -68,30 +68,26 @@ bool worklist_is_empty(const struct work
   if the worklist is non-empty.  Return 1 iff id and is_unit
   are valid.
 ****************************************************************/
-bool worklist_peek(const struct worklist *pwl, int *id, bool *is_unit)
+bool worklist_peek(const struct worklist *pwl, struct city_production *prod)
 {
-  if (worklist_is_empty(pwl))
-    return FALSE;
-
-  return worklist_peek_ith(pwl, id, is_unit, 0);
+  return worklist_peek_ith(pwl, prod, 0);
 }
 
 /****************************************************************
   Fill in the id and is_unit values for the ith element in the
   worklist.  If the worklist has fewer than i elements, return 0.
 ****************************************************************/
-bool worklist_peek_ith(const struct worklist *pwl, int *id, bool *is_unit,
-                     int idx)
+bool worklist_peek_ith(const struct worklist *pwl,
+                      struct city_production *prod, int idx)
 {
   /* Out of possible bounds. */
   if (idx < 0 || pwl->length <= idx) {
-    *is_unit = FALSE;
-    *id = -1;
+    prod->is_unit = FALSE;
+    prod->value = -1;
     return FALSE;
   }
 
-  *is_unit = pwl->entries[idx].is_unit;
-  *id = pwl->entries[idx].value;
+  *prod = pwl->entries[idx];
 
   return TRUE;
 }
@@ -138,7 +134,7 @@ void worklist_remove(struct worklist *pw
   the unit/building to be produced; is_unit specifies whether it's a unit or
   a building.  Returns TRUE if successful.
 ****************************************************************************/
-bool worklist_append(struct worklist *pwl, int id, bool is_unit)
+bool worklist_append(struct worklist *pwl, struct city_production prod)
 {
   int next_index = worklist_length(pwl);
 
@@ -146,8 +142,7 @@ bool worklist_append(struct worklist *pw
     return FALSE;
   }
 
-  pwl->entries[next_index].is_unit = is_unit;
-  pwl->entries[next_index].value = id;
+  pwl->entries[next_index] = prod;
   pwl->length++;
 
   return TRUE;
@@ -159,7 +154,8 @@ bool worklist_append(struct worklist *pw
   be produced; is_unit tells whether it's a unit or building.  Returns TRUE
   if successful.
 ****************************************************************************/
-bool worklist_insert(struct worklist *pwl, int id, bool is_unit, int idx)
+bool worklist_insert(struct worklist *pwl,
+                    struct city_production prod, int idx)
 {
   int new_len = MIN(pwl->length + 1, MAX_LEN_WORKLIST), i;
 
@@ -174,9 +170,7 @@ bool worklist_insert(struct worklist *pw
     pwl->entries[i + 1] = pwl->entries[i];
   }
   
-  pwl->entries[idx].is_unit = is_unit;
-  pwl->entries[idx].value = id;
-
+  pwl->entries[idx] = prod;
   pwl->length = new_len;
 
   return TRUE;
Index: common/worklist.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/worklist.h,v
retrieving revision 1.11
diff -p -u -r1.11 worklist.h
--- common/worklist.h   28 Jul 2005 17:59:07 -0000      1.11
+++ common/worklist.h   31 Jul 2005 02:02:54 -0000
@@ -33,15 +33,16 @@ void init_worklist(struct worklist *pwl)
 
 int worklist_length(const struct worklist *pwl);
 bool worklist_is_empty(const struct worklist *pwl);
-bool worklist_peek(const struct worklist *pwl, int *id, bool *is_unit);
-bool worklist_peek_ith(const struct worklist *pwl, int *id, bool *is_unit,
-                     int idx);
+bool worklist_peek(const struct worklist *pwl, struct city_production *prod);
+bool worklist_peek_ith(const struct worklist *pwl,
+                      struct city_production *prod, int idx);
 void worklist_advance(struct worklist *pwl);
 
 void copy_worklist(struct worklist *dst, const struct worklist *src);
 void worklist_remove(struct worklist *pwl, int idx);
-bool worklist_append(struct worklist *pwl, int id, bool is_unit);
-bool worklist_insert(struct worklist *pwl, int id, bool is_unit, int idx);
+bool worklist_append(struct worklist *pwl, struct city_production prod);
+bool worklist_insert(struct worklist *pwl, struct city_production prod,
+                    int idx);
 bool are_worklists_equal(const struct worklist *wlist1,
                         const struct worklist *wlist2);
 
@@ -55,16 +56,15 @@ void worklist_save(struct section_file *
                   const char *path, ...)
   fc__attribute((format (printf, 3, 4)));
 
-/* Iterate over all entries in the worklist.  Note the 'id' parameter
- * comes before the 'is_unit' one. */
-#define worklist_iterate(worklist, id, is_unit)                                
    \
+/* Iterate over all entries in the worklist. */
+#define worklist_iterate(worklist, prod)                                   \
 {                                                                          \
   struct worklist *_worklist = (worklist);                                 \
-  int id, _iter, _length = worklist_length(_worklist);                     \
-  bool is_unit;                                                                
    \
+  int _iter, _length = worklist_length(_worklist);                         \
+  struct city_production prod;                                             \
                                                                            \
   for (_iter = 0; _iter < _length; _iter++) {                              \
-    worklist_peek_ith(_worklist, &id, &is_unit, _iter);
+    worklist_peek_ith(_worklist, &prod, _iter);
 
 #define worklist_iterate_end                                               \
   }                                                                        \
Index: server/cityhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityhand.c,v
retrieving revision 1.152
diff -p -u -r1.152 cityhand.c
--- server/cityhand.c   26 Jul 2005 16:36:00 -0000      1.152
+++ server/cityhand.c   31 Jul 2005 02:02:54 -0000
@@ -336,6 +336,10 @@ void handle_city_change(struct player *p
                        bool is_build_id_unit_id)
 {
   struct city *pcity = player_find_city_by_id(pplayer, city_id);
+  struct city_production prod = {
+    .is_unit = is_build_id_unit_id,
+    .value = build_id
+  };
 
   if (!pcity) {
     return;
@@ -359,8 +363,7 @@ void handle_city_change(struct player *p
     return;
   }
 
-  change_build_target(pplayer, pcity, build_id, is_build_id_unit_id,
-                     E_NOEVENT);
+  change_build_target(pplayer, pcity, prod, E_NOEVENT);
 
   sanity_check_city(pcity);
   city_refresh(pcity);
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.341
diff -p -u -r1.341 citytools.c
--- server/citytools.c  30 Jul 2005 05:10:02 -0000      1.341
+++ server/citytools.c  31 Jul 2005 02:02:55 -0000
@@ -1781,14 +1781,15 @@ void building_lost(struct city *pcity, I
   Change the build target.
 **************************************************************************/
 void change_build_target(struct player *pplayer, struct city *pcity,
-                        int target, bool is_unit, enum event_type event)
+                        struct city_production target,
+                        enum event_type event)
 {
   const char *name;
   const char *source;
 
   /* If the city is already building this thing, don't do anything */
-  if (pcity->production.is_unit == is_unit &&
-      pcity->production.value == target) {
+  if (pcity->production.is_unit == target.is_unit &&
+      pcity->production.value == target.value) {
     return;
   }
 
@@ -1808,17 +1809,17 @@ void change_build_target(struct player *
 
   /* Manage the city change-production penalty.
      (May penalize, restore or do nothing to the shield_stock.) */
-  pcity->shield_stock = city_change_production_penalty(pcity, target, is_unit);
+  pcity->shield_stock = city_change_production_penalty(pcity, target);
 
   /* Change build target. */
-  pcity->production.value = target;
-  pcity->production.is_unit = is_unit;
+  pcity->production = target;
 
   /* What's the name of the target? */
-  if (is_unit)
+  if (target.is_unit) {
     name = get_unit_type(pcity->production.value)->name;
-  else
+  } else {
     name = get_improvement_name(pcity->production.value);
+  }
 
   switch (event) {
     case E_WORKLIST: source = _(" from the worklist"); break;
Index: server/citytools.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.h,v
retrieving revision 1.65
diff -p -u -r1.65 citytools.h
--- server/citytools.h  22 Jul 2005 16:18:06 -0000      1.65
+++ server/citytools.h  31 Jul 2005 02:02:55 -0000
@@ -71,7 +71,8 @@ void do_sell_building(struct player *ppl
                      Impr_type_id id);
 void building_lost(struct city *pcity, Impr_type_id id);
 void change_build_target(struct player *pplayer, struct city *pcity,
-                        int target, bool is_unit, enum event_type event);
+                        struct city_production target,
+                        enum event_type event);
 
 bool is_allowed_city_name(struct player *pplayer, const char *city_name,
                          char *error_buf, size_t bufsz);
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.327
diff -p -u -r1.327 cityturn.c
--- server/cityturn.c   30 Jul 2005 05:10:02 -0000      1.327
+++ server/cityturn.c   31 Jul 2005 02:02:55 -0000
@@ -295,8 +295,7 @@ void send_global_city_turn_notifications
       /* can_player_build_improvement() checks whether wonder is build
         elsewhere (or destroyed) */
       if (!pcity->production.is_unit && 
is_great_wonder(pcity->production.value)
-         && (city_turns_to_build(pcity, pcity->production.value, FALSE, TRUE)
-             <= 1)
+         && (city_turns_to_build(pcity, pcity->production, TRUE) <= 1)
          && can_player_build_improvement(city_owner(pcity), 
pcity->production.value)) {
        notify_conn_ex(dest, pcity->tile,
                       E_WONDER_WILL_BE_BUILT,
@@ -582,7 +581,10 @@ void advisor_choose_build(struct player 
   /* See what AI has to say */
   ai_advisor_choose_building(pcity, &choice);
   if (choice.choice >= 0 && choice.choice < B_LAST) {
-    change_build_target(pplayer, pcity, choice.choice, FALSE, E_IMP_AUTO);
+    struct city_production target = {.is_unit = FALSE,
+                                    .value = choice.choice};
+
+    change_build_target(pplayer, pcity, target, E_IMP_AUTO);
     return;
   }
 
@@ -590,7 +592,9 @@ void advisor_choose_build(struct player 
   impr_type_iterate(i) {
     if (can_build_improvement(pcity, i)
        && !building_has_effect(i, EFT_CAPITAL_CITY)) {
-      change_build_target(pplayer, pcity, i, FALSE, E_IMP_AUTO);
+      struct city_production target = {.is_unit = FALSE, .value = i};
+
+      change_build_target(pplayer, pcity, target, E_IMP_AUTO);
       return;
     }
   } impr_type_iterate_end;
@@ -614,20 +618,19 @@ static bool worklist_change_build_target
 
   i = 0;
   while (TRUE) {
-    int target;
-    bool is_unit;
+    struct city_production target;
 
     /* What's the next item in the worklist? */
-    if (!worklist_peek_ith(&pcity->worklist, &target, &is_unit, i))
+    if (!worklist_peek_ith(&pcity->worklist, &target, i))
       /* Nothing more in the worklist.  Ah, well. */
       break;
 
     i++;
 
     /* Sanity checks */
-    if (is_unit &&
-       !can_build_unit(pcity, get_unit_type(target))) {
-      struct unit_type *ptarget = get_unit_type(target);
+    if (target.is_unit &&
+       !can_build_unit(pcity, get_unit_type(target.value))) {
+      struct unit_type *ptarget = get_unit_type(target.value);
       struct unit_type *new_target = unit_upgrades_to(pcity, ptarget);
 
       /* Maybe we can just upgrade the target to what the city /can/ build. */
@@ -636,8 +639,7 @@ static bool worklist_change_build_target
        notify_player_ex(pplayer, pcity->tile, E_CITY_CANTBUILD,
                         _("%s can't build %s from the worklist; "
                           "tech not yet available.  Postponing..."),
-                        pcity->name,
-                        get_unit_type(target)->name);
+                        pcity->name, ptarget->name);
        script_signal_emit("unit_cant_be_built", 3,
                           API_TYPE_UNIT_TYPE, ptarget,
                           API_TYPE_CITY, pcity,
@@ -653,7 +655,7 @@ static bool worklist_change_build_target
                         /* Yes, warn about the targets that's actually
                            in the worklist, not its obsolete-closure
                            new_target. */
-                        get_unit_type(target)->name);
+                        ptarget->name);
        script_signal_emit("unit_cant_be_built", 3,
                           API_TYPE_UNIT_TYPE, ptarget,
                           API_TYPE_CITY, pcity,
@@ -672,11 +674,12 @@ static bool worklist_change_build_target
                         new_target->name,
                         pcity->name);
        ptarget = new_target;
-       target = new_target->index;
+       target.value = new_target->index;
       }
-    } else if (!is_unit && !can_build_improvement(pcity, target)) {
-      Impr_type_id new_target = building_upgrades_to(pcity, target);
-      struct impr_type *ptarget = get_improvement_type(target);
+    } else if (!target.is_unit
+              && !can_build_improvement(pcity, target.value)) {
+      Impr_type_id new_target = building_upgrades_to(pcity, target.value);
+      struct impr_type *ptarget = get_improvement_type(target.value);
 
       /* If the city can never build this improvement, drop it. */
       if (!can_eventually_build_improvement(pcity, new_target)) {
@@ -685,7 +688,7 @@ static bool worklist_change_build_target
                         _("%s can't build %s from the worklist.  "
                           "Purging..."),
                         pcity->name,
-                        get_impr_name_ex(pcity, target));
+                        get_impr_name_ex(pcity, ptarget->index));
        script_signal_emit("building_cant_be_built", 3,
                           API_TYPE_BUILDING_TYPE, ptarget,
                           API_TYPE_CITY, pcity,
@@ -702,8 +705,8 @@ static bool worklist_change_build_target
 
       /* Maybe this improvement has been obsoleted by something that
         we can build. */
-      if (new_target == target) {
-       struct impr_type *building = get_improvement_type(target);
+      if (new_target == target.value) {
+       struct impr_type *building = get_improvement_type(target.value);
        bool known = FALSE;
 
        /* Nope, no use.  *sigh*  */
@@ -717,7 +720,7 @@ static bool worklist_change_build_target
                               _("%s can't build %s from the worklist; "
                                 "tech %s not yet available.  Postponing..."),
                               pcity->name,
-                              get_impr_name_ex(pcity, target),
+                              get_impr_name_ex(pcity, building->index),
                               get_tech_name(pplayer,
                                             preq->source.value.tech));
              script_signal_emit("building_cant_be_built", 3,
@@ -730,7 +733,7 @@ static bool worklist_change_build_target
                               _("%s can't build %s from the worklist; "
                                 "need to have %s first.  Postponing..."),
                               pcity->name,
-                              get_impr_name_ex(pcity, target),
+                              get_impr_name_ex(pcity, building->index),
                               get_impr_name_ex(pcity,
                                                preq->source.value.building));
              script_signal_emit("building_cant_be_built", 3,
@@ -743,7 +746,7 @@ static bool worklist_change_build_target
                               _("%s can't build %s from the worklist; "
                                 "it needs %s government.  Postponing..."),
                               pcity->name,
-                              get_impr_name_ex(pcity, target),
+                              get_impr_name_ex(pcity, building->index),
                               get_government_name(preq->source.value.gov));
              script_signal_emit("building_cant_be_built", 3,
                                 API_TYPE_BUILDING_TYPE, building,
@@ -755,7 +758,7 @@ static bool worklist_change_build_target
                               _("%s can't build %s from the worklist; "
                                 "%s special is required.  Postponing..."),
                               pcity->name,
-                              get_impr_name_ex(pcity, target),
+                              get_impr_name_ex(pcity, building->index),
                               get_special_name(preq->source.value.special));
              script_signal_emit("building_cant_be_built", 3,
                                 API_TYPE_BUILDING_TYPE, building,
@@ -767,7 +770,7 @@ static bool worklist_change_build_target
                               _("%s can't build %s from the worklist; "
                                 "%s terrain is required.  Postponing..."),
                               pcity->name,
-                              get_impr_name_ex(pcity, target),
+                              get_impr_name_ex(pcity, building->index),
                               get_terrain_name(preq->source.value.terrain));
              script_signal_emit("building_cant_be_built", 3,
                                 API_TYPE_BUILDING_TYPE, building,
@@ -781,7 +784,7 @@ static bool worklist_change_build_target
                               _("%s can't build %s from the worklist; "
                                 "only %s may build this.  Postponing..."),
                               pcity->name,
-                              get_impr_name_ex(pcity, target),
+                              get_impr_name_ex(pcity, building->index),
                               get_nation_name(preq->source.value.nation));
              script_signal_emit("building_cant_be_built", 3,
                                 API_TYPE_BUILDING_TYPE, building,
@@ -798,7 +801,8 @@ static bool worklist_change_build_target
              notify_player_ex(pplayer, pcity->tile, E_CITY_CANTBUILD,
                               _("%s can't build %s from the worklist; "
                                 "city must be of size %d.  Postponing..."),
-                              pcity->name, get_impr_name_ex(pcity, target),
+                              pcity->name,
+                              get_impr_name_ex(pcity, building->index),
                               preq->source.value.minsize);
              script_signal_emit("building_cant_be_built", 3,
                                 API_TYPE_BUILDING_TYPE, building,
@@ -820,22 +824,22 @@ static bool worklist_change_build_target
                           _("%s can't build %s from the worklist; "
                             "Reason unknown!  Postponing..."),
                           pcity->name,
-                          get_impr_name_ex(pcity, target));
+                          get_impr_name_ex(pcity, building->index));
        }
        continue;
       } else {
        /* Hey, we can upgrade the improvement!  */
        notify_player_ex(pplayer, pcity->tile, E_WORKLIST,
                         _("Production of %s is upgraded to %s in %s."),
-                        get_impr_name_ex(pcity, target), 
+                        get_impr_name_ex(pcity, target.value), 
                         get_impr_name_ex(pcity, new_target),
                         pcity->name);
-       target = new_target;
+       target.value = new_target;
       }
     }
 
     /* All okay.  Switch targets. */
-    change_build_target(pplayer, pcity, target, is_unit, E_WORKLIST);
+    change_build_target(pplayer, pcity, target, E_WORKLIST);
 
     success = TRUE;
     break;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13572) change city/worklist API to use city_production structs, Jason Short <=