Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12158) draw city outlines
Home

[Freeciv-Dev] (PR#12158) draw city outlines

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12158) draw city outlines
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 8 Feb 2005 12:21:33 -0800
Reply-to: bugs@xxxxxxxxxxx

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

Here is a new patch.  This one draws outlines for settlers too.

-jason

? fog
? fog.c
? fog.png
? data/isotrident/grid.png
? data/isotrident/mask-30x30.png
? data/misc/colors.png
? data/trident/foo.png
? data/trident/grid.png
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.154
diff -u -r1.154 control.c
--- client/control.c    8 Feb 2005 18:43:51 -0000       1.154
+++ client/control.c    8 Feb 2005 20:21:03 -0000
@@ -1104,6 +1104,19 @@
 }
 
 /**************************************************************************
+ Toggle display of city outlines on the map
+**************************************************************************/
+void request_toggle_city_outlines(void) 
+{
+  if (!can_client_change_view()) {
+    return;
+  }
+
+  draw_city_outlines = !draw_city_outlines;
+  update_map_canvas_visible();
+}
+
+/**************************************************************************
  Toggle display of grid lines on the map
 **************************************************************************/
 void request_toggle_map_grid(void) 
@@ -1392,23 +1405,24 @@
     center_tile_mapcanvas(target_unit->tile);
   }
 
+  /* Set the tile before the movement animation is done, so that everything
+   * drawn there will be up-to-date. */
+  punit->tile = target_unit->tile;
+
   if (punit->transported_by == -1) {
     /* We have to refresh the tile before moving.  This will draw
      * the tile without the unit (because it was unlinked above). */
-    refresh_unit_mapcanvas(punit, punit->tile, FALSE);
+    refresh_unit_mapcanvas(punit, ptile, FALSE);
 
     if (do_animation) {
       int dx, dy;
 
       /* For the duration of the animation the unit exists at neither
        * tile. */
-      map_distance_vector(&dx, &dy, punit->tile,
-                         target_unit->tile);
+      map_distance_vector(&dx, &dy, ptile, target_unit->tile);
       move_unit_map_canvas(punit, ptile, dx, dy);
     }
   }
-    
-  punit->tile = target_unit->tile;
 
   unit_list_prepend(punit->tile->units, punit);
 
@@ -2098,6 +2112,14 @@
 }
 
 /**************************************************************************
+  Toggle drawing of city outlines.
+**************************************************************************/
+void key_city_outlines_toggle(void)
+{
+  request_toggle_city_outlines();
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 void key_map_grid_toggle(void)
Index: client/control.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.h,v
retrieving revision 1.47
diff -u -r1.47 control.h
--- client/control.h    5 Feb 2005 07:41:53 -0000       1.47
+++ client/control.h    8 Feb 2005 20:21:03 -0000
@@ -83,6 +83,7 @@
 void request_unit_wakeup(struct unit *punit);
 void request_diplomat_action(enum diplomat_actions action, int dipl_id,
                             int target_id, int value);
+void request_toggle_city_outlines(void);
 void request_toggle_map_grid(void);
 void request_toggle_map_borders(void);
 void request_toggle_city_names(void);
@@ -135,6 +136,7 @@
 void key_focus_unit_toggle(void);
 void key_fog_of_war_toggle(void);
 void key_end_turn(void);
+void key_city_outlines_toggle(void);
 void key_map_grid_toggle(void);
 void key_map_borders_toggle(void);
 void key_quickselect(enum quickselect_type qtype);
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.179
diff -u -r1.179 mapview_common.c
--- client/mapview_common.c     8 Feb 2005 18:43:51 -0000       1.179
+++ client/mapview_common.c     8 Feb 2005 20:21:04 -0000
@@ -1376,20 +1376,46 @@
 {
   enum direction8 dir;
 
-  if (!draw_map_grid) {
-    return;
-  }
-
-  for (dir = 0; dir < 8; dir++) {
-    int start_x, start_y, end_x, end_y;
-
-    if (get_tile_boundaries(dir, 0, 1,
-                           &start_x, &start_y, &end_x, &end_y)) {
-      canvas_put_line(pcanvas,
-                     get_grid_color(ptile, dir),
-                     LINE_NORMAL,
-                     canvas_x + start_x, canvas_y + start_y,
-                     end_x - start_x, end_y - start_y);
+  if (draw_map_grid) {
+    for (dir = 0; dir < 8; dir++) {
+      int start_x, start_y, end_x, end_y;
+
+      if (get_tile_boundaries(dir, 0, 1,
+                             &start_x, &start_y, &end_x, &end_y)) {
+       canvas_put_line(pcanvas,
+                       get_grid_color(ptile, dir),
+                       LINE_NORMAL,
+                       canvas_x + start_x, canvas_y + start_y,
+                       end_x - start_x, end_y - start_y);
+      }
+    }
+  } else if (draw_city_outlines) {
+    for (dir = 0; dir < 8; dir++) {
+      int start_x, start_y, end_x, end_y, dummy_x, dummy_y;
+      struct tile *tile2 = mapstep(ptile, dir);
+      struct unit *pfocus;
+      enum color_std color = COLOR_STD_LAST;
+
+      if (get_tile_boundaries(dir, 0, 1,
+                             &start_x, &start_y, &end_x, &end_y)) {
+       if (XOR(player_in_city_radius(game.player_ptr, ptile),
+               player_in_city_radius(game.player_ptr, tile2))) {
+         color = COLOR_STD_WHITE;
+       } else if ((pfocus = get_unit_in_focus())
+                  && unit_flag(pfocus, F_CITIES)
+                  && city_can_be_built_here(pfocus->tile, pfocus)
+                  && XOR(base_map_to_city_map(&dummy_x, &dummy_y,
+                                              pfocus->tile, ptile),
+                         base_map_to_city_map(&dummy_x, &dummy_y,
+                                              pfocus->tile, tile2))) {
+         color = COLOR_STD_RED;
+       }
+       if (color != COLOR_STD_LAST) {
+         canvas_put_line(pcanvas, color, LINE_NORMAL,
+                         canvas_x + start_x, canvas_y + start_y,
+                         end_x - start_x, end_y - start_y);
+       }
+      }
     }
   }
 }
Index: client/options.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.c,v
retrieving revision 1.119
diff -u -r1.119 options.c
--- client/options.c    7 Feb 2005 08:09:10 -0000       1.119
+++ client/options.c    8 Feb 2005 20:21:04 -0000
@@ -210,6 +210,7 @@
 
 /** View Options: **/
 
+bool draw_city_outlines = TRUE;
 bool draw_map_grid = FALSE;
 bool draw_city_names = TRUE;
 bool draw_city_growth = TRUE;
Index: client/options.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.h,v
retrieving revision 1.47
diff -u -r1.47 options.h
--- client/options.h    5 Feb 2005 19:46:32 -0000       1.47
+++ client/options.h    8 Feb 2005 20:21:04 -0000
@@ -119,6 +119,7 @@
 
 /** View Options: **/
 
+extern bool draw_city_outlines;
 extern bool draw_map_grid;
 extern bool draw_city_names;
 extern bool draw_city_growth;
Index: client/gui-gtk-2.0/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/menu.c,v
retrieving revision 1.61
diff -u -r1.61 menu.c
--- client/gui-gtk-2.0/menu.c   7 Feb 2005 22:52:40 -0000       1.61
+++ client/gui-gtk-2.0/menu.c   8 Feb 2005 20:21:04 -0000
@@ -90,6 +90,7 @@
   MENU_GOVERNMENT_WORKLISTS,
   MENU_GOVERNMENT_REVOLUTION,
 
+  MENU_VIEW_SHOW_CITY_OUTLINES,
   MENU_VIEW_SHOW_MAP_GRID,
   MENU_VIEW_SHOW_NATIONAL_BORDERS,
   MENU_VIEW_SHOW_CITY_NAMES,
@@ -284,6 +285,11 @@
                               GtkWidget *widget)
 {
   switch(callback_action) {
+  case MENU_VIEW_SHOW_CITY_OUTLINES:
+    if (draw_city_outlines ^ GTK_CHECK_MENU_ITEM(widget)->active) {
+      key_city_outlines_toggle();
+    }
+    break;
   case MENU_VIEW_SHOW_MAP_GRID:
     if (draw_map_grid ^ GTK_CHECK_MENU_ITEM(widget)->active)
       key_map_grid_toggle();
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.312
diff -u -r1.312 city.c
--- common/city.c       5 Feb 2005 05:36:00 -0000       1.312
+++ common/city.c       8 Feb 2005 20:21:06 -0000
@@ -75,9 +75,9 @@
   Finds the city map coordinate for a given map position and a city
   center. Returns whether the map position is inside of the city map.
 **************************************************************************/
-static bool base_map_to_city_map(int *city_map_x, int *city_map_y,
-                                const struct tile *city_tile,
-                                const struct tile *map_tile)
+bool base_map_to_city_map(int *city_map_x, int *city_map_y,
+                         const struct tile *city_tile,
+                         const struct tile *map_tile)
 {
   map_distance_vector(city_map_x, city_map_y, city_tile, map_tile);
   *city_map_x += CITY_MAP_RADIUS;
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.199
diff -u -r1.199 city.h
--- common/city.h       3 Feb 2005 08:38:55 -0000       1.199
+++ common/city.h       8 Feb 2005 20:21:06 -0000
@@ -407,6 +407,9 @@
 bool map_to_city_map(int *city_map_x, int *city_map_y,
                     const struct city *const pcity,
                     const struct tile *ptile);
+bool base_map_to_city_map(int *city_map_x, int *city_map_y,
+                         const struct tile *city_tile,
+                         const struct tile *map_tile);
 
 struct tile *base_city_map_to_map(const struct tile *city_center_tile,
                                  int city_map_x, int city_map_y);

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