Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2000:
[Freeciv-Dev] Re: [PATCH] Turns left to build in citydlg
Home

[Freeciv-Dev] Re: [PATCH] Turns left to build in citydlg

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Randy Scott <scottr@xxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [PATCH] Turns left to build in citydlg
From: Daniel Zinsli <s830+priv@xxxxxxxxx>
Date: 04 Jan 2000 22:14:12 +0100

Randy Scott <scottr@xxxxxxx> writes:
> Nice, but it doesn't look like you took into account when the
> shield_surplus is zero (when the city is revolting, for example).
> I made a very similar change that I've been playing with for a 
> while now, and that was one of the same mistakes that I made.

Starting off with a divide-by-zero *blush* :-)

Here is the updated patch, sorry for the repost:

======================================================================
client/gui-gtk/citydlg.c
Repository revision:    1.31
======================================================================
--- client/gui-gtk/citydlg.c.orig       Tue Jan  4 22:13:19 2000
+++ client/gui-gtk/citydlg.c    Tue Jan  4 22:13:33 2000
@@ -14,11 +14,14 @@
 #include <config.h>
 #endif
 
+#include <math.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 
+
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
@@ -936,14 +939,29 @@
 void city_dialog_update_building(struct city_dialog *pdialog)
 {
   char buf[32], buf2[64];
+  int turnsleft; 
   struct city *pcity=pdialog->pcity;
   
   gtk_widget_set_sensitive(pdialog->buy_command, !pcity->did_buy);
   gtk_widget_set_sensitive(pdialog->sell_command, !pcity->did_sell);
 
   if(pcity->is_building_unit) {
-    my_snprintf(buf, sizeof(buf), "%3d/%3d", pcity->shield_stock, 
-           get_unit_type(pcity->currently_building)->build_cost);
+
+    if (pcity->shield_surplus < 1) {
+      turnsleft = 999;
+    } else {
+      turnsleft = (int) ceil((double)
(get_unit_type(pcity->currently_building)->build_cost -
+                                      pcity->shield_stock)
+                            / pcity->shield_surplus);
+    }
+    
+    if (turnsleft <= 0)
+      turnsleft = 1;
+    
+    my_snprintf(buf, sizeof(buf), "%3d/%3d (%d turns left)",
pcity->shield_stock,
+               get_unit_type(pcity->currently_building)->build_cost,   
+               turnsleft);
+
     sz_strlcpy(buf2, get_unit_type(pcity->currently_building)->name);
   } else {
     if(pcity->currently_building==B_CAPITAL)  {
@@ -951,8 +969,20 @@
       my_snprintf(buf, sizeof(buf), "%3d/XXX", pcity->shield_stock);
       gtk_widget_set_sensitive(pdialog->buy_command, FALSE);
     } else {
-      my_snprintf(buf, sizeof(buf), "%3d/%3d", pcity->shield_stock, 
-
get_improvement_type(pcity->currently_building)->build_cost);
+      if (pcity->shield_surplus < 1) {
+       turnsleft = 999;
+      } else {
+       turnsleft = (int) ceil((double)
(get_improvement_type(pcity->currently_building)->build_cost -
+                                        pcity->shield_stock)
+                              / pcity->shield_surplus);
+      }
+      if (turnsleft <= 0)
+       turnsleft = 1;
+
+      my_snprintf(buf, sizeof(buf), "%3d/%3d (%d turns left)",
pcity->shield_stock,
+
get_improvement_type(pcity->currently_building)->build_cost,    
+                 turnsleft);
+
     }
     sz_strlcpy(buf2, get_imp_name_ex(pcity,
pcity->currently_building));
   }    
@@ -1642,7 +1672,8 @@
 {
   GtkWidget *cshell, *button, *scrolled;
   struct city_dialog *pdialog;
-  int i, n;
+  int i, n, turnsleft;
+  double prodchange; 
   static gchar *title_[1] = { N_("Select new production") };
   static gchar **title = NULL;
   GtkAccelGroup *accel=gtk_accel_group_new();
@@ -1695,13 +1726,35 @@
        GTK_SIGNAL_FUNC(change_help_callback), pdialog);
 
   gtk_widget_set_sensitive(pdialog->shell, FALSE);
-
+  
   for(i=0, n=0; i<B_LAST; i++)
     if(can_build_improvement(pdialog->pcity, i)) {
+
+      /*  Check for production penalty, adjust accordingly */
+      if (pdialog->pcity->is_building_unit ||
+         (is_wonder(pdialog->pcity->currently_building) !=
+          is_wonder(i))) {
+       prodchange = 0.5;
+      } else {
+       prodchange = 1;
+      }
+      if (pdialog->pcity->shield_surplus < 1) {
+       turnsleft = 999; 
+      } else {
+       turnsleft = (int) ceil((get_improvement_type(i)->build_cost -
+                               floor(pdialog->pcity->shield_stock *
prodchange)) /
+                              (pdialog->pcity->shield_surplus));
+      }
+
+      if (turnsleft <= 0)
+       turnsleft = 1;
+
+
       my_snprintf(pdialog->change_list_names[n],
-                 sizeof(pdialog->change_list_names[n]), "%s (%d)",
+                 sizeof(pdialog->change_list_names[n]), "%s (%d) %d
turns",
                  get_imp_name_ex(pdialog->pcity, i),
-                 get_improvement_type(i)->build_cost);
+                 get_improvement_type(i)->build_cost,
+                 turnsleft);
       
       pdialog->change_list_names_ptrs[n]=pdialog->change_list_names[n];
       pdialog->change_list_ids[n++]=i;
@@ -1712,9 +1765,31 @@
 
   for(i=0; i<game.num_unit_types; i++)
     if(can_build_unit(pdialog->pcity, i)) {
+
+      /* Check for production penalty, adjust accordingly */
+      if (!pdialog->pcity->is_building_unit) {
+       prodchange = 0.5;
+      } else {
+       prodchange = 1;
+      }
+
+      if (pdialog->pcity->shield_surplus < 1) {
+       turnsleft = 999;
+      } else {
+       turnsleft = (int) ceil((get_unit_type(i)->build_cost -
+                               floor(pdialog->pcity->shield_stock *
     prodchange)) /
+                              (pdialog->pcity->shield_surplus));
+      }
+
+      if (turnsleft <= 0)
+       turnsleft = 1;
+
+
       my_snprintf(pdialog->change_list_names[n],
-                 sizeof(pdialog->change_list_names[n]), "%s (%d)",
-                 get_unit_name(i), get_unit_type(i)->build_cost);
+                 sizeof(pdialog->change_list_names[n]), "%s (%d) %d
     turns",
+                 get_unit_name(i), get_unit_type(i)->build_cost,       
+                 turnsleft);
+
 
       pdialog->change_list_names_ptrs[n]=pdialog->change_list_names[n];
       pdialog->change_list_ids[n++]=i;

-- 
Daniel Zinsli
University of Bergen, Norway
Finger s830@xxxxxxxxxxxxxxx for more info


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