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

 This fixes a lot of compiler warnings/errors from gui-win32, updates
things, and makes some other adjustments.

 It still does not compile. But there is patch somewhere in RT that
should fix some of the older problems, so I'm avoiding duplicate work
here.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/gui-win32/citydlg.c freeciv/client/gui-win32/citydlg.c
--- freeciv/client/gui-win32/citydlg.c	2007-08-13 20:51:06.000000000 +0300
+++ freeciv/client/gui-win32/citydlg.c	2007-08-14 02:11:07.000000000 +0300
@@ -229,18 +229,24 @@
 void city_dialog_update_improvement_list(struct city_dialog *pdialog)
 {
   LV_COLUMN lvc;
-  int changed, total, item, targets_used;
+  int total, item, targets_used;
   struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
   struct item items[MAX_NUM_PRODUCTION_TARGETS];
   char buf[100];
+  bool changed;
 
   /* Test if the list improvements of pcity has changed */
-  changed = 0;
+  changed = false;
   improvement_iterate(pimprove) {
-    if (pdialog->pcity->improvements[improvement_index(pimprove)] !=
-        pdialog->last_improvlist_seen[improvement_index(pimprove)]) {
-      changed = 1;
-      break;
+    int index = improvement_index(pimprove);
+    bool has_building = city_has_building(pdialog->pcity, pimprove);
+    bool had_building =
+      pdialog->last_improvlist_seen[index];
+
+    if ((has_building && !had_building)
+        || (!has_building && had_building)) {
+      changed = true;
+      pdialog->last_improvlist_seen[index] = has_building;
     }
   } improvement_iterate_end;
 
@@ -248,12 +254,6 @@
     return;
   }
   
-  /* Update pdialog->last_improvlist_seen */
-  improvement_iterate(pimprove) {
-    pdialog->last_improvlist_seen[improvement_index(pimprove)] = 
-    pdialog->pcity->improvements[improvement_index(pimprove)];
-  } improvement_iterate_end;
-  
   targets_used = collect_already_built_targets(targets, pdialog->pcity);
   name_and_sort_items(targets, targets_used, items, FALSE, pdialog->pcity);
    
@@ -278,7 +278,7 @@
    
     row=fcwin_listview_add_row(pdialog->buildings_list,
 			   item, 2, strings);
-    pdialog->building_values[row] = target.value.building;
+    pdialog->building_values[row] = improvement_index(target.value.building);
     total += upkeep;
   }
   lvc.mask=LVCF_TEXT;
@@ -346,6 +346,8 @@
   int i;
   struct unit_list *plist;
   struct canvas store;
+  int free_upkeep[O_COUNT];
+  int free_unhappy;
 
   store.type = CANVAS_DC;
   store.hdc = hdc;
@@ -353,6 +355,13 @@
   store.wnd = NULL;
   store.tmp = NULL;
 
+  free_unhappy = get_city_bonus(pdialog->pcity, EFT_MAKE_CONTENT_MIL);
+
+  output_type_iterate(o) {
+    free_upkeep[o] = get_city_output_bonus(pdialog->pcity, get_output_type(o),
+                                           EFT_UNIT_UPKEEP_FREE_PER_CITY);
+  } output_type_iterate_end;
+
   if  (pdialog->pcity->owner != game.player_ptr) {
     plist = pdialog->pcity->info_units_supported;
   } else {
@@ -373,12 +382,17 @@
   i = 0;
   
   unit_list_iterate(plist, punit) {
+    int upkeep_cost[O_COUNT];
+    int happy_cost = city_unit_unhappiness(punit, &free_unhappy);
+        
+    city_unit_upkeep(punit, upkeep_cost, free_upkeep);
+
     put_unit(punit, &store,
 	     pdialog->pop_x + i * (tileset_small_sprite_width(tileset) + tileset_tile_width(tileset)),
 	     pdialog->supported_y);
     put_unit_city_overlays(punit, &store,
-	     pdialog->pop_x + i * (tileset_small_sprite_width(tileset) + tileset_tile_width(tileset)),
-	     pdialog->supported_y);
+             pdialog->pop_x + i * (tileset_small_sprite_width(tileset) + tileset_tile_width(tileset)),
+                           pdialog->supported_y, upkeep_cost, happy_cost);
     pdialog->support_unit_ids[i] = punit->id;
     i++;
     if (i == NUM_UNITS_SHOWN) {
@@ -888,9 +902,10 @@
 **************************************************************************/
 static void buy_callback(struct city_dialog *pdialog)
 {
-  char buf[512];    
+  char buf[512];
+  struct city *pcity = pdialog->pcity;
   const char *name = city_production_name_translation(pcity);
-  int value = city_production_buy_gold_cost(pdialog->pcity);
+  int value = city_production_buy_gold_cost(pcity);
  
   if(game.player_ptr->economic.gold>=value) {
     my_snprintf(buf, sizeof(buf),
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/connectdlg.c freeciv/client/gui-win32/connectdlg.c
--- freeciv/client/gui-win32/connectdlg.c	2007-08-04 18:38:53.000000000 +0300
+++ freeciv/client/gui-win32/connectdlg.c	2007-08-14 02:12:00.000000000 +0300
@@ -794,7 +794,7 @@
   aiskill = ComboBox_GetCurSel(GetDlgItem(newgame_dlg,
 					  ID_NEWGAMEDLG_AISKILL));
 
-  my_snprintf(buf, sizeof(buf), "/%s", skill_level_names[aiskill]);
+  my_snprintf(buf, sizeof(buf), "/%s", ai_level_cmd(aiskill));
   send_chat(buf);
 
 #if 0 
@@ -925,6 +925,7 @@
   struct fcwin_box *players_vbox;
   struct fcwin_box *newgame_vbox;
   LV_COLUMN lvc;
+  enum ai_level level;
   
   titles[0] =_(titles_[0]);
   titles[1] =_(titles_[1]);
@@ -1019,11 +1020,16 @@
 
   fcwin_box_add_static(hbox, _("AI skill level:"), 0, SS_LEFT, TRUE, TRUE,
 		       5);
-  fcwin_box_add_combo(hbox, NUM_SKILL_LEVELS, ID_NEWGAMEDLG_AISKILL,
+
+  fcwin_box_add_combo(hbox, number_of_ai_levels(), ID_NEWGAMEDLG_AISKILL,
 		      CBS_DROPDOWN | WS_VSCROLL, TRUE, TRUE, 5);
-  for (i = 0; i < NUM_SKILL_LEVELS; i++) {
-    ComboBox_AddString(GetDlgItem(newgame_dlg, ID_NEWGAMEDLG_AISKILL), 
-		       _(skill_level_names[i]));
+  for (level = 0; level < AI_LEVEL_LAST; level++) {
+    if (is_settable_ai_level(level)) {
+      /* We insert translated ai_level_name here. This cannot be used as
+       * command for setting ai level (that would be ai_level_cmd(level) */
+      ComboBox_AddString(GetDlgItem(newgame_dlg, ID_NEWGAMEDLG_AISKILL),
+                         ai_level_name(level));
+    }
   }
   ComboBox_SetCurSel(GetDlgItem(newgame_dlg, ID_NEWGAMEDLG_AISKILL), 1);
 
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/dialogs.c freeciv/client/gui-win32/dialogs.c
--- freeciv/client/gui-win32/dialogs.c	2007-08-13 20:51:06.000000000 +0300
+++ freeciv/client/gui-win32/dialogs.c	2007-08-14 02:14:55.000000000 +0300
@@ -104,8 +104,10 @@
 static HWND races_dlg;
 struct player *races_player;
 static HWND races_listview;
+/*
 static HWND races_class;
 static HWND races_legend;
+*/
 int visible_nations[MAX_NUM_ITEMS];
 int selected_leader_sex;
 int selected_style;
@@ -282,11 +284,14 @@
 **************************************************************************/
 static void update_nation_info()
 {
+  /*
   int i;
   char buf[255];
   struct nation_type *nation = nation_by_number(selected_nation);
  
   buf[0] = '\0';
+  */
+
 /*
   for (i = 0; i < nation->num_groups; i++) {
     sz_strlcat(buf, nation->groups[i]->name);
@@ -456,16 +461,6 @@
   return 0;
 }
 
-
-/****************************************************************
-...
-*****************************************************************/
-static int cmp_func(const void * a_p, const void * b_p)
-{
-  return strcmp(nation_name_translation(nation_by_number((*(int *)a_p)-ID_RACESDLG_NATION_BASE)),
-                nation_name_translation(nation_by_number((*(int *)b_p)-ID_RACESDLG_NATION_BASE)));
-}
-
 /****************************************************************
 ...
 *****************************************************************/
@@ -483,14 +478,15 @@
       continue;
     }
 
-    if (group != NULL && !is_nation_in_group(pnation, group->name)) {
+    if (group != NULL && !is_nation_in_group(pnation, group)) {
       continue;
     }
 
-    strings[0] = nation_name_translation(pnation);
+    /* FIXME: Casting const away!!! */
+    strings[0] = (char *) nation_name_translation(pnation);
 
-    fcwin_listview_add_row(listview, pnation->index, 1, strings);
-    visible_nations[n++] = pnation->index;
+    fcwin_listview_add_row(listview, nation_index(pnation), 1, strings);
+    visible_nations[n++] = nation_index(pnation);
 
   } nations_iterate_end;
 
@@ -1396,7 +1392,7 @@
   improvement_iterate(pimprove) {
     if (pimprove->sabotage > 0) {
       ListBox_AddString(lb,city_improvement_name_translation(pcity, pimprove));
-      improvement_type[j++] = improvement_by_number(pimprove);
+      improvement_type[j++] = improvement_index(pimprove);
     }  
   } improvement_iterate_end;
 
@@ -1734,14 +1730,15 @@
 
 **************************************************************************/
 void popup_pillage_dialog(struct unit *punit,
-			  bv_special may_pillage)
+			  bv_special may_pillage,
+                          struct base_type *pbase)
 {
   HWND dlg;
   struct fcwin_box *vbox;
   enum tile_special_type what, prereq;
 
   if (!is_showing_pillage_dialog) {
-    is_showing_pillage_dialog = TRUE;   
+    is_showing_pillage_dialog = TRUE;
     unit_to_use_to_pillage = punit->id;
     dlg=fcwin_create_layouted_window(pillage_proc,_("What To Pillage"),
 				     WS_OVERLAPPEDWINDOW,
@@ -1752,19 +1749,25 @@
     vbox=fcwin_vbox_new(dlg,FALSE);
     fcwin_box_add_static(vbox,_("Select what to pillage:"),0,SS_LEFT,
 			 FALSE,FALSE,10);
-    while ((what = get_preferred_pillage(may_pillage)) != S_LAST) {
+    while ((what = get_preferred_pillage(may_pillage, pbase)) != S_LAST) {
       bv_special what_bv;
 
-      BV_CLR_ALL(what_bv);
-      BV_SET(what_bv, what);
+      if (what != S_PILLAGE_BASE) {
+        BV_CLR_ALL(what_bv);
+        BV_SET(what_bv, what);
 
-      fcwin_box_add_button(vbox, get_infrastructure_text(what_bv),
-			   ID_PILLAGE_BASE+what,0,TRUE,FALSE,5);
+        fcwin_box_add_button(vbox, get_infrastructure_text(what_bv),
+                             ID_PILLAGE_BASE+what,0,TRUE,FALSE,5);
 
-      clear_special(&may_pillage, what);
-      prereq = get_infrastructure_prereq(what);
-      if (prereq != S_LAST) {
-	clear_special(&may_pillage, prereq);
+        clear_special(&may_pillage, what);
+        prereq = get_infrastructure_prereq(what);
+        if (prereq != S_LAST) {
+          clear_special(&may_pillage, prereq);
+        }
+      } else {
+        fcwin_box_add_button(vbox, base_name_translation(pbase),
+                             ID_PILLAGE_BASE + what, 0, TRUE, FALSE, 5);
+        pbase = NULL;
       }
     }
     fcwin_box_add_button(vbox,_("Cancel"),IDCANCEL,0,TRUE,FALSE,5);
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/gui_stuff.c freeciv/client/gui-win32/gui_stuff.c
--- freeciv/client/gui-win32/gui_stuff.c	2007-08-04 18:38:53.000000000 +0300
+++ freeciv/client/gui-win32/gui_stuff.c	2007-08-14 02:09:16.000000000 +0300
@@ -1406,7 +1406,7 @@
 /**************************************************************************
 
 **************************************************************************/
-int fcwin_listview_add_row(HWND lv,int row_nr,int columns,char **row)
+int fcwin_listview_add_row(HWND lv, int row_nr, int columns, char **row)
 {
   LV_ITEM lvi;
   int i,id;
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/gui_stuff.h freeciv/client/gui-win32/gui_stuff.h
--- freeciv/client/gui-win32/gui_stuff.h	2007-08-04 18:38:53.000000000 +0300
+++ freeciv/client/gui-win32/gui_stuff.h	2007-08-14 02:09:29.000000000 +0300
@@ -15,7 +15,8 @@
 void mydrawrect(HDC hdc, int x, int y,int w,int h);
 char *convertnl2crnl(const char *str);
 void my_get_win_border(HWND hWnd,int *w,int *h);
-int fcwin_listview_add_row(HWND lv,int row_nr,int columns,char **row);
+int fcwin_listview_add_row(HWND lv, int row_nr,
+                           int columns, char **row);
 struct fcwin_box;
 
 typedef void (*t_fcminsize)(POINT *,void *);
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/happiness.c freeciv/client/gui-win32/happiness.c
--- freeciv/client/gui-win32/happiness.c	2007-08-04 18:38:53.000000000 +0300
+++ freeciv/client/gui-win32/happiness.c	2007-08-14 02:18:17.000000000 +0300
@@ -177,7 +177,7 @@
   struct player *pplayer = pcity->owner;
   int cities = city_list_size(pplayer->cities);
   int content = get_player_bonus(pcity->owner, EFT_CITY_UNHAPPY_SIZE);
-  int basis = get_player_bonus(game.player_ptr, EFT_EMPIRE_SIZE_MOD);
+  int basis = get_player_bonus(game.player_ptr, EFT_EMPIRE_SIZE_BASE);
   int step = get_player_bonus(game.player_ptr, EFT_EMPIRE_SIZE_STEP);
   int excess = cities - basis;
   int penalty = 0;
@@ -240,7 +240,6 @@
   char buf[512], *bptr = buf;
   int nleft = sizeof(buf);
   struct city *pcity = pdialog->pcity;
-  struct government *g = government_of_city(pcity);
   int mlmax = get_city_bonus(pcity, EFT_MARTIAL_LAW_MAX);
   int uhcfac = get_player_bonus(city_owner(pcity), EFT_UNHAPPY_FACTOR);
 
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/helpdlg.c freeciv/client/gui-win32/helpdlg.c
--- freeciv/client/gui-win32/helpdlg.c	2007-08-13 20:51:06.000000000 +0300
+++ freeciv/client/gui-win32/helpdlg.c	2007-08-14 02:19:58.000000000 +0300
@@ -730,7 +730,8 @@
     if (U_NOT_OBSOLETED == utype->obsoleted_by) {
       SetWindowText(help_ulabel[4][4], _("None"));
     } else {
-      SetWindowText(help_ulabel[4][4], utype->obsoleted_by->name);
+      SetWindowText(help_ulabel[4][4],
+                    utype_name_translation(utype->obsoleted_by));
     }
 
     helptext_unit(buf, utype, pitem->text);
diff -Nurd -X.diff_ignore freeciv/common/player.c freeciv/common/player.c
--- freeciv/common/player.c	2007-08-13 20:51:04.000000000 +0300
+++ freeciv/common/player.c	2007-08-14 01:36:03.000000000 +0300
@@ -1003,3 +1003,28 @@
   /* It's usable if it has name */
   return ai_level_cmd(level) != NULL;
 }
+
+/***************************************************************
+  Return number of AI levels in game
+***************************************************************/
+int number_of_ai_levels(void)
+{
+  /* We determine this runtime instead of hardcoding correct answer.
+   * But as this is constant, we determine it only once. */
+  static int count = 0;
+  enum ai_level level;
+
+  if (count) {
+    /* Answer already known */
+    return count;
+  }
+
+  /* Determine how many levels are actually usable */
+  for (level = 0; level < AI_LEVEL_LAST; level++) {
+    if (is_settable_ai_level(level)) {
+      count++;
+    }
+  }
+
+  return count;
+}
diff -Nurd -X.diff_ignore freeciv/common/player.h freeciv/common/player.h
--- freeciv/common/player.h	2007-08-04 18:38:32.000000000 +0300
+++ freeciv/common/player.h	2007-08-14 01:36:15.000000000 +0300
@@ -315,5 +315,6 @@
 const char *ai_level_name(enum ai_level level);
 const char *ai_level_cmd(enum ai_level level);
 bool is_settable_ai_level(enum ai_level level);
+int number_of_ai_levels(void);
 
 #endif  /* FC__PLAYER_H */
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to