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

On 1/15/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
>
> On 7/21/06, Tommi Björkbacka <[EMAIL PROTECTED]> wrote:
> >
> > You can reproduce this problem easily. First buy a random unit and
> > then put a new unit into worklist. After that try to adjust new unit
> > to the top of worklist. Result is that you have two indentical units
> > in worklist.
>
>  I took a different approach to Tommi's patch. This should be more
> generic fix, meaning that it fixes all the cases where this bug
> appears and not only one special case.

 S2_0 version


 - ML

diff -Nurd -X.diff_ignore freeciv/client/citydlg_common.c freeciv/client/citydlg_common.c
--- freeciv/client/citydlg_common.c	2007-01-13 00:55:34.000000000 +0200
+++ freeciv/client/citydlg_common.c	2007-01-17 18:03:54.000000000 +0200
@@ -576,7 +576,7 @@
 /**************************************************************************
   Set the city current production and the worklist, like it should be.
 **************************************************************************/
-void city_set_queue(struct city *pcity, struct worklist *pqueue)
+bool city_set_queue(struct city *pcity, struct worklist *pqueue)
 {
   struct worklist copy;
   int id;
@@ -588,6 +588,15 @@
      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 (!city_can_change_build(pcity)
+        && (id != pcity->currently_building
+            || is_unit != pcity->is_building_unit)) {
+      /* We cannot change production to one from worklist.
+       * Do not replace old worklist with new one. */
+      return FALSE;
+    }
+
     worklist_advance(&copy);
 
     city_set_worklist(pcity, &copy);
@@ -600,6 +609,8 @@
       city_set_worklist(pcity, &copy);
     }
   }
+
+  return TRUE;
 }
 
 /**************************************************************************
diff -Nurd -X.diff_ignore freeciv/client/citydlg_common.h freeciv/client/citydlg_common.h
--- freeciv/client/citydlg_common.h	2007-01-13 00:55:34.000000000 +0200
+++ freeciv/client/citydlg_common.h	2007-01-17 17:53:37.000000000 +0200
@@ -65,7 +65,7 @@
 bool city_queue_insert(struct city *pcity, int position,
 		       bool item_is_unit, int item_id);
 void city_get_queue(struct city *pcity, struct worklist *pqueue);
-void city_set_queue(struct city *pcity, struct worklist *pqueue);
+bool city_set_queue(struct city *pcity, struct worklist *pqueue);
 bool city_can_buy(const struct city *pcity);
 int city_sell_improvement(struct city *pcity, Impr_Type_id sell_id);
 int city_buy_production(struct city *pcity);
diff -Nurd -X.diff_ignore freeciv/client/gui-gtk-2.0/wldlg.c freeciv/client/gui-gtk-2.0/wldlg.c
--- freeciv/client/gui-gtk-2.0/wldlg.c	2007-01-13 00:55:19.000000000 +0200
+++ freeciv/client/gui-gtk-2.0/wldlg.c	2007-01-17 17:53:37.000000000 +0200
@@ -1444,7 +1444,11 @@
 
   /* dance around worklist braindamage. */
   if (ptr->pcity) {
-    city_set_queue(ptr->pcity, &queue);
+    if (!city_set_queue(ptr->pcity, &queue)) {
+      /* Failed to change worklist. This means worklist visible
+       * on screen is not true. */
+      refresh_worklist(ptr->editor);
+    }
   } else {
     copy_worklist(pwl, &queue);
   }
diff -Nurd -X.diff_ignore freeciv/common/city.c freeciv/common/city.c
--- freeciv/common/city.c	2007-01-13 00:55:12.000000000 +0200
+++ freeciv/common/city.c	2007-01-17 18:08:08.000000000 +0200
@@ -477,6 +477,14 @@
   return pcity->size >= game.rgame.specialists[type].min_size;
 }
 
+/****************************************************************************
+  Returns TRUE iff if the given city can change what it is building
+****************************************************************************/
+bool city_can_change_build(const struct city *pcity)
+{
+  return !pcity->did_buy || pcity->shield_stock <= 0;
+}
+
 /**************************************************************************
  Returns how many thousand citizen live in this city.
 **************************************************************************/
diff -Nurd -X.diff_ignore freeciv/common/city.h freeciv/common/city.h
--- freeciv/common/city.h	2007-01-13 00:55:12.000000000 +0200
+++ freeciv/common/city.h	2007-01-17 17:53:37.000000000 +0200
@@ -389,6 +389,7 @@
                         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);
+bool city_can_change_build(const struct city *pcity);
 
 /* textual representation of buildings */
 
diff -Nurd -X.diff_ignore freeciv/common/worklist.c freeciv/common/worklist.c
--- freeciv/common/worklist.c	2007-01-13 00:55:12.000000000 +0200
+++ freeciv/common/worklist.c	2007-01-17 17:53:37.000000000 +0200
@@ -82,7 +82,8 @@
 
 /****************************************************************
   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.
+  worklist. If the worklist has fewer than idx elements,
+  return FALSE.
 ****************************************************************/
 bool worklist_peek_ith(const struct worklist *pwl, int *id, bool *is_unit,
 		      int idx)
diff -Nurd -X.diff_ignore freeciv/server/cityhand.c freeciv/server/cityhand.c
--- freeciv/server/cityhand.c	2007-01-13 00:54:27.000000000 +0200
+++ freeciv/server/cityhand.c	2007-01-17 17:56:20.000000000 +0200
@@ -218,7 +218,7 @@
     return;
   }
 
-  if (pcity->did_buy) {
+  if (!city_can_change_build(pcity)) {
     notify_player_ex(pplayer, pcity->tile, E_NOEVENT,
 		  _("Game: You have already bought this turn."));
     return;
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to