Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2003:
[Freeciv-Dev] Re: resync'ed and stylified (PR#5378) Diplomacy informatio
Home

[Freeciv-Dev] Re: resync'ed and stylified (PR#5378) Diplomacy informatio

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: resync'ed and stylified (PR#5378) Diplomacy information in map middle-click
From: "Daniel L Speyer" <dspeyer@xxxxxxxxxxx>
Date: Wed, 17 Sep 2003 17:23:30 -0700
Reply-to: rt@xxxxxxxxxxxxxx

OK, the "if("s are fixed.  That's all I found for remaining style 
errors.  This whole style thing is getting really annoying.  Has anyone 
written some tools to help with it?

I don't feal qualified to write the win32 version, because I neither 
know the toolkit nor have an environment to test on.  I would probably 
mess up, and there'd be no way for me to know.  Someon else will have to 
write that -- it should be pretty easy.

--Daniel Speyer

andrearo@xxxxxxxxxxxx wrote:

>On Sun, 14 Sep 2003, Daniel L Speyer wrote:
>  
>
>>Here's the diplomacy information in middle-click patch, resycnhronized,
>>stylified and commented.
>>
>>Enjoy!
>>--Daniel Speyer
>>    
>>
>
>Here's the second review of the patch. (recheck codingstyle)
>
>Andreas Røsdal
>  
>
>------------------------------------------------------------------------
>
>I. Testing
>
>1. Was the patch tested (yes / no-elaborate)?
>
>Yes
>
>2. Which client was used to testing the patch (N/A if it's a
>server-only patch)?
>
>gtk-1.2, gtk-2.0, Xaw, Xaw3d
>
>3. Does the patch work / do what it promises to (yes / no)?
>
>Yes, patch works.
>
>==========================================================================
>
>II. Code correctness
>
>1. Does the patch adhere to the style guide (yes / no)?
>
>There's still some Codingstyle problems. 
>Here's some examples:
>
>+    if(punit && (punit->activity == ACTIVITY_GOTO || punit->connecting))  {
>
>+    if(punit && (punit->activity == ACTIVITY_GOTO || punit->connecting)) {
>
>+  if(tile_get_known(xtile, ytile)>=TILE_KNOWN_FOGGED) {
>
>+      if (end) {
>+       content = end+1;
>
>+  char *diplo_adjectives[DS_LAST] = {_("Neutral"), _("Hostile"), 
>_("Ceasefire"),
>
>+      }else{
>
>+    if(punit->owner == game.player_idx) {
>+       struct city *pcity;
>+       pcity=player_find_city_by_id(game.player_ptr, punit->homecity);
>+       if(pcity)
>+         my_snprintf(tmp, sizeof(tmp), "/%s", pcity->name);
>+      }
>
>2. Is the patch well commented / easy to read (yes / no-elaborate)?
>
>Yes
>
>3. Are there coding errors in the patch (list)?
>
>No
>
>4. What can be improved / simplified / done differently (list)?
>
>Would it be possible to add win32 support also?
>
>==========================================================================
>
>III. Verdict
>
>1. Should the patch be
>  a) rejected completely
>  b) split - elaborate
>  c) revised and resubmitted for review
>  d) revised and then committed
>  e) committed as it is
>
>--------------
>
>  Verdict: c) revised and resubmitted for review. 
>
>--------------
>
>  
>


diff -ur freeciv-cvs-Sep-11-orig/client/gui-gtk/mapctrl.c 
freeciv-cvs-Sep-11-popit/client/gui-gtk/mapctrl.c
--- freeciv-cvs-Sep-11-orig/client/gui-gtk/mapctrl.c    2003-08-29 
12:31:17.000000000 +0000
+++ freeciv-cvs-Sep-11-popit/client/gui-gtk/mapctrl.c   2003-09-14 
19:08:17.000000000 +0000
@@ -68,140 +68,27 @@
 **************************************************************************/
 static void popit(GdkEventButton *event, int xtile, int ytile)
 {
-  GtkWidget *p, *b;
+  GtkWidget *p;
   static struct map_position cross_list[2 + 1];
   struct map_position *cross_head = cross_list;
   int i;
-  char s[512];
   static struct t_popup_pos popup_pos;
-  struct city *pcity;
   struct unit *punit;
-  struct tile *ptile = map_get_tile(xtile, ytile);
 
   if(tile_get_known(xtile, ytile) >= TILE_KNOWN_FOGGED) {
     p=gtk_window_new(GTK_WINDOW_POPUP);
-    b=gtk_vbox_new(FALSE, 0);
-    gtk_container_add(GTK_CONTAINER(p), b);
-
-#ifdef DEBUG    
-    my_snprintf(s, sizeof(s), _("Location: (%d, %d) [%d]"), xtile, ytile, 
-                ptile->continent);
-    gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                   "GtkLabel::label", s, NULL);
-#endif /* DEBUG */
-
-    my_snprintf(s, sizeof(s), _("Terrain: %s"),
-               map_get_tile_info_text(xtile, ytile));
-    gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                  "GtkLabel::label", s, NULL);
-
-    my_snprintf(s, sizeof(s), _("Food/Prod/Trade: %s"),
-               map_get_tile_fpt_text(xtile, ytile));
-    gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                   "GtkLabel::label", s, NULL);
-
-    if (tile_has_special(ptile, S_HUT)) {
-      gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                    "GtkLabel::label", 
-                                     _("Minor Tribe Village"), NULL);
-    }
-
-    pcity = map_get_city(xtile, ytile);
-    if (game.borders > 0 && !pcity) {
-      struct player *owner = map_get_owner(xtile, ytile);
-      if (owner) {
-       my_snprintf(s, sizeof(s), _("Claimed by %s"),
-                   get_nation_name(owner->nation));
-       gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                      "GtkLabel::label", s, NULL);
-      } else {
-       gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                      "GtkLabel::label",
-                                      _("Unclaimed territory"), NULL);
-      }
-    }
-    
-    if (pcity) {
-      my_snprintf(s, sizeof(s), _("City: %s(%s)"), pcity->name,
-                 get_nation_name(city_owner(pcity)->nation));
-      gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                    "GtkLabel::label", s, NULL);
-
-      if (city_got_citywalls(pcity)) {
-        gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                      "GtkLabel::label", _("with City Walls"), NULL);
-      }
-    }
-
-    if(get_tile_infrastructure_set(ptile)) {
-      sz_strlcpy(s, _("Infrastructure: "));
-      sz_strlcat(s, map_get_infrastructure_text(ptile->special));
-      gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                    "GtkLabel::label", s, NULL);
-    }
+    gtk_container_add(GTK_CONTAINER(p), gtk_label_new(popup_info_text(xtile, 
ytile)));
     
-    sz_strlcpy(s, _("Activity: "));
-    if (concat_tile_activity_text(s, sizeof(s), xtile, ytile)) {
-      gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                    "GtkLabel::label", s, NULL);
+    punit = find_visible_unit(map_get_tile(xtile, ytile));
+    if (punit && (punit->activity == ACTIVITY_GOTO || punit->connecting))  {
+      cross_head->x = goto_dest_x(punit);
+      cross_head->y = goto_dest_y(punit);
+      cross_head++;
     }
-    
-    if((punit = find_visible_unit(ptile)) && !pcity) {
-      char cn[64];
-      struct unit_type *ptype = unit_type(punit);
-      cn[0] = '\0';
-      if(punit->owner == game.player_idx) {
-       struct city *pcity;
-       pcity=player_find_city_by_id(game.player_ptr, punit->homecity);
-       if(pcity)
-         my_snprintf(cn, sizeof(cn), "/%s", pcity->name);
-      }
-      my_snprintf(s, sizeof(s), _("Unit: %s(%s%s)"), ptype->name,
-                 get_nation_name(unit_owner(punit)->nation), cn);
-      gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                    "GtkLabel::label", s, NULL);
-
-      if(punit->owner == game.player_idx)  {
-       char uc[64] = "";
-       if(unit_list_size(&ptile->units) >= 2) {
-         my_snprintf(uc, sizeof(uc), _("  (%d more)"),
-                     unit_list_size(&ptile->units) - 1);
-       }
-        my_snprintf(s, sizeof(s), _("A:%d D:%d FP:%d HP:%d/%d%s%s"),
-                   ptype->attack_strength, 
-                   ptype->defense_strength, ptype->firepower, punit->hp, 
-                   ptype->hp, punit->veteran ? _(" V") : "", uc);
-
-        if(punit->activity == ACTIVITY_GOTO || punit->connecting)  {
-         cross_head->x = goto_dest_x(punit);
-         cross_head->y = goto_dest_y(punit);
-         cross_head++;
-        }
-      } else {
-       int att_chance, def_chance;
-
-        /* calculate chance to win */
-        if (get_chance_to_win(&att_chance, &def_chance, xtile, ytile)) {
-          my_snprintf(s, sizeof(s), _("Chance to win: A:%d%% D:%d%%"),
-               att_chance, def_chance);
-          gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                         "GtkLabel::label", s, NULL);
-        }
-
-        my_snprintf(s, sizeof(s), _("A:%d D:%d FP:%d HP:%d0%%"),
-                   ptype->attack_strength, 
-                   ptype->defense_strength, ptype->firepower, 
-                   (punit->hp * 100 / ptype->hp + 9) / 10);
-      }
-      gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                    "GtkLabel::label", s, NULL);
-    }
-
     cross_head->x = xtile;
     cross_head->y = ytile;
     cross_head++;
 
-    gtk_widget_show_all(b);
 
     cross_head->x = -1;
     for (i = 0; cross_list[i].x >= 0; i++) {
@@ -218,7 +105,7 @@
                        GTK_SIGNAL_FUNC(popupinfo_positioning_callback), 
                        &popup_pos);
 
-    gtk_widget_show(p);
+    gtk_widget_show_all(p);
     gdk_pointer_grab(p->window, TRUE, GDK_BUTTON_RELEASE_MASK,
                     NULL, NULL, event->time);
     gtk_grab_add(p);
diff -ur freeciv-cvs-Sep-11-orig/client/gui-gtk-2.0/mapctrl.c 
freeciv-cvs-Sep-11-popit/client/gui-gtk-2.0/mapctrl.c
--- freeciv-cvs-Sep-11-orig/client/gui-gtk-2.0/mapctrl.c        2003-08-29 
12:31:17.000000000 +0000
+++ freeciv-cvs-Sep-11-popit/client/gui-gtk-2.0/mapctrl.c       2003-09-14 
20:01:37.000000000 +0000
@@ -65,155 +65,29 @@
 **************************************************************************/
 static void popit(GdkEventButton *event, int xtile, int ytile)
 {
-  GtkWidget *p, *b;
+  GtkWidget *p;
   static struct map_position cross_list[2 + 1];
   struct map_position *cross_head = cross_list;
-  int i, count = 0;
+  int i;
   int popx, popy;
-  char s[512];
-  struct city *pcity;
   struct unit *punit;
-  struct tile *ptile = map_get_tile(xtile, ytile);
 
   if(tile_get_known(xtile, ytile) >= TILE_KNOWN_FOGGED) {
     p=gtk_window_new(GTK_WINDOW_POPUP);
     gtk_widget_set_app_paintable(p, TRUE);
     gtk_container_set_border_width(GTK_CONTAINER(p), 4);
-    b=gtk_vbox_new(FALSE, 0);
-    gtk_container_add(GTK_CONTAINER(p), b);
-
-#ifdef DEBUG    
-    my_snprintf(s, sizeof(s), _("Location: (%d, %d)"), xtile, ytile);
-    gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                   "GtkLabel::label", s, NULL);
-    count++;
-#endif /* DEBUG */
-
-    my_snprintf(s, sizeof(s), _("Terrain: %s"),
-               map_get_tile_info_text(xtile, ytile));
-    gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                  "GtkLabel::label", s, NULL);
-    count++;
-
-    my_snprintf(s, sizeof(s), _("Food/Prod/Trade: %s"),
-               map_get_tile_fpt_text(xtile, ytile));
-    gtk_widget_new(GTK_TYPE_LABEL,  "GtkWidget::parent", b,
-                                   "GtkLabel::label", s, NULL);
-    count++;
-
-    if (tile_has_special(ptile, S_HUT)) {
-      gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                    "GtkLabel::label",
-                                    _("Minor Tribe Village"), NULL);
-      count++;
-    }
-
-    pcity = map_get_city(xtile, ytile);
-
-    if (game.borders > 0 && !pcity) {
-      struct player *owner = map_get_owner(xtile, ytile);
-      if (owner) {
-        my_snprintf(s, sizeof(s), _("Claimed by %s"),
-                   get_nation_name(owner->nation));
-        gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                      "GtkLabel::label", s, NULL);
-      } else {
-        gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                      "GtkLabel::label",
-                                      _("Unclaimed territory"), NULL);
-      }
-      count++;
-    }
-    
-    if (pcity) {
-      my_snprintf(s, sizeof(s), _("City: %s(%s)"), pcity->name,
-                 get_nation_name(city_owner(pcity)->nation));
-      gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                    "GtkLabel::label", s, NULL);
-      count++;
-
-      if (city_got_citywalls(pcity)) {
-        gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                      "GtkLabel::label", _("with City Walls"), NULL);
-       count++;
-      }
-    }
-
-    if(get_tile_infrastructure_set(ptile)) {
-      sz_strlcpy(s, _("Infrastructure: "));
-      sz_strlcat(s, map_get_infrastructure_text(ptile->special));
-      gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                    "GtkLabel::label", s, NULL);
-      count++;
-    }
+    gtk_container_add(GTK_CONTAINER(p), gtk_label_new(popup_info_text(xtile, 
ytile)));
     
-    sz_strlcpy(s, _("Activity: "));
-    if (concat_tile_activity_text(s, sizeof(s), xtile, ytile)) {
-      gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                    "GtkLabel::label", s, NULL);
-      count++;
+    punit = find_visible_unit(map_get_tile(xtile, ytile));
+    if (punit && (punit->activity == ACTIVITY_GOTO || punit->connecting)) {
+      cross_head->x = goto_dest_x(punit);
+      cross_head->y = goto_dest_y(punit);
+      cross_head++;
     }
-    
-    if((punit = find_visible_unit(ptile)) && !pcity) {
-      char cn[64];
-      struct unit_type *ptype = unit_type(punit);
-      cn[0] = '\0';
-      if(punit->owner == game.player_idx) {
-       struct city *pcity;
-       pcity=player_find_city_by_id(game.player_ptr, punit->homecity);
-       if(pcity)
-         my_snprintf(cn, sizeof(cn), "/%s", pcity->name);
-      }
-      my_snprintf(s, sizeof(s), _("Unit: %s(%s%s)"), ptype->name,
-                 get_nation_name(unit_owner(punit)->nation), cn);
-      gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                    "GtkLabel::label", s, NULL);
-      count++;
-
-      if(punit->owner == game.player_idx)  {
-       char uc[64] = "";
-       if(unit_list_size(&ptile->units) >= 2) {
-         my_snprintf(uc, sizeof(uc), _("  (%d more)"),
-                     unit_list_size(&ptile->units) - 1);
-       }
-        my_snprintf(s, sizeof(s), _("A:%d D:%d FP:%d HP:%d/%d%s%s"),
-                   ptype->attack_strength, 
-                   ptype->defense_strength, ptype->firepower, punit->hp, 
-                   ptype->hp, punit->veteran ? _(" V") : "", uc);
-
-        if(punit->activity == ACTIVITY_GOTO || punit->connecting)  {
-         cross_head->x = goto_dest_x(punit);
-         cross_head->y = goto_dest_y(punit);
-         cross_head++;
-        }
-      } else {
-       int att_chance, def_chance;
-
-        /* calculate chance to win */
-        if (get_chance_to_win(&att_chance, &def_chance, xtile, ytile)) {
-          my_snprintf(s, sizeof(s), _("Chance to win: A:%d%% D:%d%%"),
-               att_chance, def_chance);
-          gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                         "GtkLabel::label", s, NULL);
-          count++;
-        }
-
-        my_snprintf(s, sizeof(s), _("A:%d D:%d FP:%d HP:%d0%%"),
-                   ptype->attack_strength, 
-                   ptype->defense_strength, ptype->firepower, 
-                   (punit->hp * 100 / ptype->hp + 9) / 10 );
-      }
-      gtk_widget_new(GTK_TYPE_LABEL, "GtkWidget::parent", b,
-                                    "GtkLabel::label", s, NULL);
-      count++;
-    }
-
     cross_head->x = xtile;
     cross_head->y = ytile;
     cross_head++;
 
-    gtk_widget_show_all(b);
-
     cross_head->x = -1;
     for (i = 0; cross_list[i].x >= 0; i++) {
       put_cross_overlay_tile(cross_list[i].x, cross_list[i].y);
@@ -224,11 +98,11 @@
 
     /* displace popup so as not to obscure it by the mouse cursor */
     popx= event->x_root + 16;
-    popy= event->y_root - (8 * count);
+    popy= event->y_root;
     if (popy < 0)
       popy = 0;      
     gtk_window_move(GTK_WINDOW(p), popx, popy);
-    gtk_widget_show(p);
+    gtk_widget_show_all(p);
     gdk_pointer_grab(p->window, TRUE, GDK_BUTTON_RELEASE_MASK,
                     NULL, NULL, event->time);
     gtk_grab_add(p);
diff -ur freeciv-cvs-Sep-11-orig/client/gui-xaw/mapctrl.c 
freeciv-cvs-Sep-11-popit/client/gui-xaw/mapctrl.c
--- freeciv-cvs-Sep-11-orig/client/gui-xaw/mapctrl.c    2003-08-06 
07:34:38.000000000 +0000
+++ freeciv-cvs-Sep-11-popit/client/gui-xaw/mapctrl.c   2003-09-14 
20:00:44.000000000 +0000
@@ -31,6 +31,7 @@
 #include <X11/Xaw/SmeBSB.h>
 #include <X11/Xaw/SmeLine.h>
 
+#include "climap.h"
 #include "fcintl.h"
 #include "game.h"
 #include "map.h"
@@ -104,80 +105,36 @@
   static struct map_position cross_list[2+1];
   struct map_position *cross_head = cross_list;
   int i;
-  char s[512];
-  struct city *pcity;
   struct unit *punit;
-  struct tile *ptile=map_get_tile(xtile, ytile);
-
+  char *content;
   
-  if(ptile->known>=TILE_KNOWN_FOGGED) {
+  if (tile_get_known(xtile, ytile)>=TILE_KNOWN_FOGGED) {
     Widget p=XtCreatePopupShell("popupinfo", simpleMenuWidgetClass,
                                map_canvas, NULL, 0);
-    my_snprintf(s, sizeof(s), _("Terrain: %s"),
-               map_get_tile_info_text(xtile, ytile));
-    XtCreateManagedWidget(s, smeBSBObjectClass, p, NULL, 0);
-
-    my_snprintf(s, sizeof(s), _("Food/Prod/Trade: %s"),
-               map_get_tile_fpt_text(xtile, ytile));
-    XtCreateManagedWidget(s, smeBSBObjectClass, p, NULL, 0);
-
-    if (tile_has_special(ptile, S_HUT)) {
-      XtCreateManagedWidget(_("Minor Tribe Village"), smeBSBObjectClass,
-                           p, NULL, 0);
-    }
-    
-    if((pcity=map_get_city(xtile, ytile))) {
-      my_snprintf(s, sizeof(s), _("City: %s(%s) %s"), pcity->name,
-                 get_nation_name(city_owner(pcity)->nation),
-                 city_got_citywalls(pcity) ? _("with City Walls") : "");
-      XtCreateManagedWidget(s, smeBSBObjectClass, p, NULL, 0);
-    }
-
-    if(get_tile_infrastructure_set(ptile)) {
-      sz_strlcpy(s, _("Infrastructure: "));
-      sz_strlcat(s, map_get_infrastructure_text(ptile->special));
-      XtCreateManagedWidget(s, smeBSBObjectClass, p, NULL, 0);
-    }
-
-    if((punit=find_visible_unit(ptile)) && !pcity) {
-      char cn[64];
-      struct unit_type *ptype=unit_type(punit);
-      cn[0]='\0';
-      if(punit->owner==game.player_idx) {
-       struct city *pcity;
-       pcity=player_find_city_by_id(game.player_ptr, punit->homecity);
-       if(pcity)
-         my_snprintf(cn, sizeof(cn), "/%s", pcity->name);
+    content = popup_info_text(xtile,ytile);
+    /* content is provided to us as a single string with multiple lines,
+       but xaw doens't support multi-line labels.  So we break it up.
+       We mangle it in the process, but who cares?  It's never going to be
+       used again anyway. */
+    while (1) {
+      char *end = strchr(content, '\n'); 
+      if (end) {
+       *end='\0';
       }
-      my_snprintf(s, sizeof(s), _("Unit: %s(%s%s)"), ptype->name,
-                 get_nation_name(unit_owner(punit)->nation), cn);
-      XtCreateManagedWidget(s, smeBSBObjectClass, p, NULL, 0);
-
-      if(punit->owner==game.player_idx)  {
-       char uc[64] = "";
-       if(unit_list_size(&ptile->units)>=2) {
-         my_snprintf(uc, sizeof(uc), _("  (%d more)"),
-                     unit_list_size(&ptile->units) - 1);
-       }
-        my_snprintf(s, sizeof(s),
-               _("A:%d D:%d FP:%d HP:%d/%d%s%s"), ptype->attack_strength, 
-               ptype->defense_strength, ptype->firepower, punit->hp, 
-               ptype->hp, punit->veteran?_(" V"):"", uc);
-
-        if(punit->activity==ACTIVITY_GOTO)  {
-         cross_head->x = goto_dest_x(punit);
-         cross_head->y = goto_dest_y(punit);
-         cross_head++;
-        }
+      XtCreateManagedWidget(content, smeBSBObjectClass, p, NULL, 0);
+      if (end) {
+       content = end+1;
       } else {
-        my_snprintf(s, sizeof(s),
-                   _("A:%d D:%d FP:%d HP:%d0%%"), ptype->attack_strength, 
-                   ptype->defense_strength, ptype->firepower, 
-                   (punit->hp*100/ptype->hp + 9)/10 );
+       break;
       }
-      XtCreateManagedWidget(s, smeBSBObjectClass, p, NULL, 0);
     }
 
+    punit = find_visible_unit(map_get_tile(xtile, ytile));
+    if (punit && (punit->activity == ACTIVITY_GOTO || punit->connecting)) {
+      cross_head->x = goto_dest_x(punit);
+      cross_head->y = goto_dest_y(punit);
+      cross_head++;
+    }
     cross_head->x = xtile;
     cross_head->y = ytile;
     cross_head++;
diff -ur freeciv-cvs-Sep-11-orig/client/mapctrl_common.c 
freeciv-cvs-Sep-11-popit/client/mapctrl_common.c
--- freeciv-cvs-Sep-11-orig/client/mapctrl_common.c     2003-08-29 
12:31:17.000000000 +0000
+++ freeciv-cvs-Sep-11-popit/client/mapctrl_common.c    2003-09-14 
19:33:33.000000000 +0000
@@ -17,12 +17,15 @@
 
 #include "combat.h"
 #include "log.h"
+#include "support.h"
 
 #include "agents.h"
 #include "civclient.h"
+#include "climisc.h"
 #include "clinet.h"
 #include "cma_core.h"
 #include "control.h"
+#include "fcintl.h"
 #include "goto.h"
 #include "mapctrl_g.h"
 #include "mapview_g.h"
@@ -247,3 +250,110 @@
 
   return TRUE;
 }
+
+/************************************************************************
+Text to popup on middle-click
+************************************************************************/
+char* popup_info_text(int xtile, int ytile)
+{
+  static char out[256];
+  char buf[64];
+  struct city *pcity = map_get_city(xtile, ytile);
+  struct tile *ptile = map_get_tile(xtile, ytile);
+  struct unit *punit = find_visible_unit(ptile);
+  char *diplo_adjectives[DS_LAST] = {_("Neutral"), _("Hostile"), 
_("Ceasefire"),
+                                    _("Peaceful"), _("Friendly"), 
_("Mysterious")};
+  out[0]='\0';
+
+#ifdef DEBUG
+  my_snprintf(out, sizeof(out), _("Location: (%d, %d) [%d]\n"), 
+             xtile, ytile, ptile->continent); 
+#endif /*DEBUG*/
+  my_snprintf(buf, sizeof(buf), _("Terrain: %s"),
+             map_get_tile_info_text(xtile, ytile));
+  sz_strlcat(out, buf);
+  my_snprintf(buf, sizeof(buf), _("\nFood/Prod/Trade: %s"),
+             map_get_tile_fpt_text(xtile, ytile));
+  sz_strlcat(out, buf);
+  if (tile_has_special(ptile, S_HUT)) {
+    sz_strlcat(out, _("\nMinor Tribe Village"));
+  }
+  if (game.borders > 0 && !pcity) {
+    struct player *owner = map_get_owner(xtile, ytile);
+    if (owner == game.player_ptr){
+      sz_strlcat(out, _("\nOur Territory"));
+    } else if (owner) {
+      if (game.player_ptr->diplstates[owner->player_no].type==DS_CEASEFIRE){
+       my_snprintf(buf, sizeof(buf), _("\n%s territory (%d turn ceasefire)"),
+                   get_nation_name(owner->nation),
+                   game.player_ptr->diplstates[owner->player_no].turns_left);
+      }else{
+       my_snprintf(buf, sizeof(buf), _("\nTerritory of the %s %s"),
+                   
diplo_adjectives[game.player_ptr->diplstates[owner->player_no].type],
+                   get_nation_name_plural(owner->nation));
+      }
+      sz_strlcat(out, buf);
+    } else {
+      sz_strlcat(out, _("\nUnclaimed territory"));
+    }
+  }
+  if (pcity) {
+      my_snprintf(buf, sizeof(buf), _("\nCity: %s(%s,%s)"), pcity->name,
+                 get_nation_name(city_owner(pcity)->nation),
+                 diplo_adjectives[game.player_ptr->
+                                  
diplstates[city_owner(pcity)->player_no].type]);
+      sz_strlcat(out, buf);
+      if (city_got_citywalls(pcity)) {
+       sz_strlcat(out, _(" with City Walls"));
+      }
+  } 
+  if (get_tile_infrastructure_set(ptile)) {
+    my_snprintf(buf, sizeof(buf), _("\nInfrastructure: %s"),
+               map_get_infrastructure_text(ptile->special));
+    sz_strlcat(out, buf);
+  }
+  sz_strlcpy(buf, _("\nActivity: "));
+  if (concat_tile_activity_text(buf, sizeof(buf), xtile, ytile)) {
+    sz_strlcat(out, buf);
+  }
+  if (punit && !pcity) {
+    char tmp[64] = {0};
+    struct unit_type *ptype = unit_type(punit);
+    if (punit->owner == game.player_idx) {
+       struct city *pcity;
+       pcity=player_find_city_by_id(game.player_ptr, punit->homecity);
+       if (pcity)
+         my_snprintf(tmp, sizeof(tmp), "/%s", pcity->name);
+      }
+    my_snprintf(buf, sizeof(buf), _("\nUnit: %s(%s%s)"), ptype->name,
+               get_nation_name(unit_owner(punit)->nation), tmp);
+    sz_strlcat(out, buf);
+    if (punit->owner != game.player_idx){
+      struct unit *apunit;
+      if ((apunit = get_unit_in_focus())) {
+       /* chance to win when active unit is attacking the selected unit */
+       int att_chance = unit_win_chance(apunit, punit) * 100;
+       
+       /* chance to win when selected unit is attacking the active unit */
+       int def_chance = (1.0 - unit_win_chance(punit, apunit)) * 100;
+       
+       my_snprintf(buf, sizeof(buf), _("\nChance to win: A:%d%% D:%d%%"),
+                   att_chance, def_chance);
+       sz_strlcat(out, buf);
+      }
+    }
+    my_snprintf(buf, sizeof(buf), _("\nA:%d D:%d FP:%d HP:%d/%d%s"),
+                   ptype->attack_strength, 
+                   ptype->defense_strength, ptype->firepower, punit->hp, 
+                   ptype->hp, punit->veteran ? _(" V") : "");
+    sz_strlcat(out, buf);
+    if (punit->owner == game.player_idx && unit_list_size(&ptile->units) >= 2){
+      my_snprintf(buf, sizeof(buf), _("  (%d more)"),
+                 unit_list_size(&ptile->units) - 1);
+      sz_strlcat(out, buf);
+    }
+  } 
+  return out;
+}
+
+       
diff -ur freeciv-cvs-Sep-11-orig/client/mapctrl_common.h 
freeciv-cvs-Sep-11-popit/client/mapctrl_common.h
--- freeciv-cvs-Sep-11-orig/client/mapctrl_common.h     2003-08-29 
12:31:17.000000000 +0000
+++ freeciv-cvs-Sep-11-popit/client/mapctrl_common.h    2003-09-14 
19:04:45.000000000 +0000
@@ -25,6 +25,7 @@
 void recenter_button_pressed(int canvas_x, int canvas_y);
 void update_turn_done_button_state(void);
 void update_line(int canvas_x, int canvas_y);
+char* popup_info_text(int xtile, int ytile);
 
 bool get_chance_to_win(int *att_chance, int *def_chance,
                       int map_x, int map_y);

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