[Freeciv-Dev] [PATCH] Turns left to build in citydlg
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Oki, here's a quick hack to display turns left in the city-dialog.
It displays turns left on the unit/imp that the city is building, and it
also displays turns to build next to the units/imps in the change
production dialoge, taking into account the penalty for switching
prod. type.
Hope it comes through alright, long time since I diff'ed :-)
I've set my emacs c-set-style to k&r and c-basic-offset to 2, but i get
some minor changes in indention. Also `indent -kr -i2` changes the
indent on the repository file. What do you guys use?
(I guess I have to drop my bad habit of re-indenting the entire file
after changing :)
I haven't added the code for the xaw version yet, you can add precisely
the same code, but you get a minor flaw because the production box
doesn't resize like the gtk-version does. ("42/200 (10 turns left)" gets
cut off ).
I have to read some xaw i guess :)
The patch is quite simple, but there might be some side-effects that can
break it that I am unfamiliar with. (looks ok though)
Advice is always welcome :)
======================================================================
client/gui-gtk/citydlg.c
Repository revision: 1.31
======================================================================
--- citydlg.c.orig Tue Jan 4 20:32:33 2000
+++ citydlg.c Tue Jan 4 20:53:10 2000
@@ -939,14 +939,25 @@
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);
+
+ 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) {
@@ -954,8 +965,17 @@
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);
+ 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));
}
@@ -1645,7 +1665,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();
@@ -1698,13 +1719,32 @@
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;
+ }
+
+ 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;
@@ -1715,9 +1755,28 @@
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;
+ }
+
+
+ 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
- [Freeciv-Dev] [PATCH] Turns left to build in citydlg,
Daniel Zinsli <=
|
|