Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2005:
[Freeciv-Dev] (PR#7152) tile markers
Home

[Freeciv-Dev] (PR#7152) tile markers

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: caspar-freeciv@xxxxxxxxxxxx, rf13@xxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#7152) tile markers
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 19 Aug 2005 01:05:18 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Attached is my preliminary tile markers patch.  It's very simple, just
start the game and press ctrl-t on a tile...

-jason

Index: client/mapctrl_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.c,v
retrieving revision 1.61
diff -p -u -r1.61 mapctrl_common.c
--- client/mapctrl_common.c     3 Aug 2005 16:19:07 -0000       1.61
+++ client/mapctrl_common.c     19 Aug 2005 08:02:07 -0000
@@ -317,6 +317,18 @@ void key_city_overlay(int canvas_x, int 
   }
 }
 
+void key_marker_toggle(int canvas_x, int canvas_y)
+{
+  struct tile *ptile = canvas_pos_to_tile(canvas_x, canvas_y);
+
+  if (can_client_change_view() && ptile) {
+    int old_marker = ptile->markers[game.player_ptr->team->index];
+
+    dsend_packet_tile_set_marker(&aconnection, ptile->x, ptile->y,
+                                old_marker + 1);
+  }
+}
+
 /**************************************************************************
  Shift-Left-Click on owned city or any visible unit to copy.
 **************************************************************************/
Index: client/mapctrl_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.h,v
retrieving revision 1.20
diff -p -u -r1.20 mapctrl_common.h
--- client/mapctrl_common.h     25 Dec 2004 20:38:14 -0000      1.20
+++ client/mapctrl_common.h     19 Aug 2005 08:02:07 -0000
@@ -36,6 +36,7 @@ void cancel_tile_hiliting(void);
 void toggle_tile_hilite(struct tile *ptile);
 
 void key_city_overlay(int canvas_x, int canvas_y);
+void key_marker_toggle(int canvas_x, int canvas_y);
 
 void clipboard_copy_production(struct tile *ptile);
 void clipboard_paste_production(struct city *pcity);
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.242
diff -p -u -r1.242 mapview_common.c
--- client/mapview_common.c     1 Aug 2005 23:09:35 -0000       1.242
+++ client/mapview_common.c     19 Aug 2005 08:02:08 -0000
@@ -1067,6 +1067,35 @@ static void put_one_tile(struct canvas *
 }
 
 /**************************************************************************
+  Show descriptions for all cities visible on the map canvas.
+**************************************************************************/
+static void show_markers(int canvas_x, int canvas_y, int width, int height)
+{
+  const int dx = tileset_tile_width(tileset);
+  const int dy = tileset_tile_height(tileset);
+
+  gui_rect_iterate(mapview.gui_x0 + canvas_x,
+                  mapview.gui_y0 + canvas_y,
+                  width, height,
+                  ptile, pedge, pcorner, gui_x, gui_y) {
+    const int canvas_x = gui_x - mapview.gui_x0;
+    const int canvas_y = gui_y - mapview.gui_y0;
+
+    if (ptile) {
+      int marker = ptile->markers[game.player_ptr->team->index];
+
+      if (marker != MARKER_NONE) {
+       canvas_put_rectangle(mapview.store,
+                            get_color(tileset, COLOR_MAPVIEW_GOTO),
+                            canvas_x + dx / 4,
+                            canvas_y + dy / 4,
+                            dx / 2, dy / 2);
+      }
+    }
+  } gui_rect_iterate_end;
+}
+
+/**************************************************************************
   Update (refresh) the map canvas starting at the given tile (in map
   coordinates) and with the given dimensions (also in map coordinates).
 
@@ -1127,6 +1156,9 @@ void update_map_canvas(int canvas_x, int
     if (layer == LAYER_CITYBAR) {
       show_city_descriptions(canvas_x, canvas_y, width, height);
       continue;
+    } else if (layer == LAYER_MARKERS) {
+      show_markers(canvas_x, canvas_y, width, height);
+      continue;
     }
     gui_rect_iterate(gui_x0, gui_y0, width,
                     height + (tileset_is_isometric(tileset)
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.542
diff -p -u -r1.542 packhand.c
--- client/packhand.c   18 Aug 2005 06:44:27 -0000      1.542
+++ client/packhand.c   19 Aug 2005 08:02:08 -0000
@@ -1919,6 +1919,11 @@ void handle_tile_info(struct packet_tile
     break;
   }
 
+  if (packet->marker != ptile->markers[game.player_ptr->team->index]) {
+    ptile->markers[game.player_ptr->team->index] = packet->marker;
+    tile_changed = TRUE;
+  }
+
   if (packet->spec_sprite[0] != '\0') {
     if (!ptile->spec_sprite
        || strcmp(ptile->spec_sprite, packet->spec_sprite) != 0) {
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.321
diff -p -u -r1.321 tilespec.c
--- client/tilespec.c   2 Aug 2005 02:40:58 -0000       1.321
+++ client/tilespec.c   19 Aug 2005 08:02:09 -0000
@@ -4014,6 +4014,7 @@ int fill_sprite_array(struct tileset *t,
     break;
 
   case LAYER_CITYBAR:
+  case LAYER_MARKERS:
     /* Nothing.  This is just a placeholder. */
     break;
 
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.158
diff -p -u -r1.158 tilespec.h
--- client/tilespec.h   2 Aug 2005 02:40:58 -0000       1.158
+++ client/tilespec.h   19 Aug 2005 08:02:09 -0000
@@ -77,6 +77,7 @@ enum mapview_layer {
   LAYER_UNIT,
   LAYER_SPECIAL3,
   LAYER_GRID2,
+  LAYER_MARKERS,
   LAYER_OVERLAYS,
   LAYER_CITYBAR,
   LAYER_FOCUS_UNIT,
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.135
diff -p -u -r1.135 gui_main.c
--- client/gui-gtk-2.0/gui_main.c       18 Aug 2005 06:53:30 -0000      1.135
+++ client/gui-gtk-2.0/gui_main.c       19 Aug 2005 08:02:10 -0000
@@ -476,7 +476,11 @@ static gboolean keyboard_handler(GtkWidg
         break;
   
       case GDK_t:
-        key_city_workers(w, ev);
+       if (ev->state & GDK_CONTROL_MASK) {
+         gui_key_marker_toggle(w, ev);
+       } else {
+         key_city_workers(w, ev);
+       }
         break;
 
       case GDK_KP_Divide:
Index: client/gui-gtk-2.0/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapctrl.c,v
retrieving revision 1.53
diff -p -u -r1.53 mapctrl.c
--- client/gui-gtk-2.0/mapctrl.c        27 Jul 2005 20:22:13 -0000      1.53
+++ client/gui-gtk-2.0/mapctrl.c        19 Aug 2005 08:02:10 -0000
@@ -423,3 +423,11 @@ void key_city_workers(GtkWidget *w, GdkE
   gdk_window_get_pointer(map_canvas->window, &x, &y, NULL);
   key_city_overlay(x, y);
 }
+
+void gui_key_marker_toggle(GtkWidget *w, GdkEventKey *ev)
+{
+  int x, y;
+
+  gdk_window_get_pointer(map_canvas->window, &x, &y, NULL);
+  key_marker_toggle(x, y);
+}
Index: client/gui-gtk-2.0/mapctrl.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapctrl.h,v
retrieving revision 1.10
diff -p -u -r1.10 mapctrl.h
--- client/gui-gtk-2.0/mapctrl.h        14 May 2005 22:49:02 -0000      1.10
+++ client/gui-gtk-2.0/mapctrl.h        19 Aug 2005 08:02:10 -0000
@@ -20,6 +20,7 @@
 #include "mapctrl_g.h"
 
 void key_city_workers(GtkWidget *w, GdkEventKey *ev);
+void gui_key_marker_toggle(GtkWidget *w, GdkEventKey *ev);
 
 gboolean butt_release_mapcanvas(GtkWidget *w, GdkEventButton *ev, gpointer 
data);
 gboolean butt_down_mapcanvas(GtkWidget *w, GdkEventButton *ev, gpointer data);
Index: common/fc_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/fc_types.h,v
retrieving revision 1.32
diff -p -u -r1.32 fc_types.h
--- common/fc_types.h   8 Aug 2005 16:30:23 -0000       1.32
+++ common/fc_types.h   19 Aug 2005 08:02:10 -0000
@@ -29,6 +29,7 @@
 /* MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS <= 32 !!!! */
 #define MAX_NUM_PLAYERS  30
 #define MAX_NUM_BARBARIANS   2
+#define MAX_NUM_TEAMS (MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS)
 #define MAX_NUM_CONNECTIONS (2 * (MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS))
 #define MAX_NUM_ITEMS   200     /* eg, unit_types */
 #define MAX_NUM_TECH_LIST 10
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.232
diff -p -u -r1.232 map.c
--- common/map.c        14 Jul 2005 19:25:45 -0000      1.232
+++ common/map.c        19 Aug 2005 08:02:12 -0000
@@ -276,6 +276,7 @@ static void tile_init(struct tile *ptile
   ptile->worked   = NULL; /* pointer to city working tile */
   ptile->owner    = NULL; /* Tile not claimed by any nation. */
   ptile->spec_sprite = NULL;
+  memset(ptile->markers, 0, sizeof(ptile->markers));
 }
 
 /****************************************************************************
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.152
diff -p -u -r1.152 packets.def
--- common/packets.def  18 Aug 2005 06:53:30 -0000      1.152
+++ common/packets.def  19 Aug 2005 08:02:13 -0000
@@ -241,7 +241,7 @@ grouped together. There are the followin
   Spaceship
   Ruleset
 
-The last used packet number is 116.
+The last used packet number is 117.
 ****************************************************/
 
 
@@ -346,6 +346,13 @@ PACKET_TILE_INFO=14; sc,lsend
   PLAYER owner;
   CONTINENT continent;
   STRING spec_sprite[MAX_LEN_NAME];
+  UINT8 marker;
+end
+
+PACKET_TILE_SET_MARKER=117; cs,dsend
+  COORD x, y; key
+
+  UINT8 marker;
 end
 
 # This packet used to have is_info set but that doesn't work with the
Index: common/team.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/team.h,v
retrieving revision 1.4
diff -p -u -r1.4 team.h
--- common/team.h       18 Aug 2005 06:53:30 -0000      1.4
+++ common/team.h       19 Aug 2005 08:02:13 -0000
@@ -18,7 +18,6 @@
 
 #include "tech.h"
 
-#define MAX_NUM_TEAMS (MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS)
 #define NUM_TEAMS (game.info.num_teams)
 
 struct team {
Index: common/tile.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tile.h,v
retrieving revision 1.12
diff -p -u -r1.12 tile.h
--- common/tile.h       11 Aug 2005 04:51:09 -0000      1.12
+++ common/tile.h       19 Aug 2005 08:02:13 -0000
@@ -37,6 +37,10 @@ struct tile {
   Continent_id continent;
   struct player *owner;     /* Player owning this tile, or NULL. */
   char *spec_sprite;
+
+#define MARKER_NONE 0
+#define MARKER_MAX 1
+  unsigned char markers[MAX_NUM_TEAMS];
 };
 
 /* get 'struct tile_list' and related functions: */
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.172
diff -p -u -r1.172 maphand.c
--- server/maphand.c    13 Aug 2005 05:27:24 -0000      1.172
+++ server/maphand.c    19 Aug 2005 08:02:13 -0000
@@ -484,6 +484,11 @@ void send_tile_info(struct conn_list *de
     if (!pplayer && !pconn->observer) {
       continue;
     }
+    if (pplayer && pplayer->team) {
+      info.marker = ptile->markers[pplayer->team->index];
+    } else {
+      info.marker = MARKER_NONE;
+    }
     if (!pplayer || map_is_known_and_seen(ptile, pplayer)) {
       info.known = TILE_KNOWN;
       info.type = ptile->terrain->index;
@@ -534,6 +539,11 @@ static void send_tile_info_always(struct
   } else {
     info.spec_sprite[0] = '\0';
   }
+  if (pplayer && pplayer->team) {
+    info.marker = ptile->markers[pplayer->team->index];
+  } else {
+    info.marker = MARKER_NONE;
+  }
 
   if (!pplayer) {
     /* Observer sees all. */
@@ -569,6 +579,25 @@ static void send_tile_info_always(struct
   lsend_packet_tile_info(dest, &info);
 }
 
+/****************************************************************************
+  Handle a set-marker packet.
+****************************************************************************/
+void handle_tile_set_marker(struct player *pplayer, int x, int y, int marker)
+{
+  struct tile *ptile = map_pos_to_tile(x, y);
+
+  if (!ptile || !pplayer->team) {
+    return;
+  }
+
+  if (marker < 0 || marker > MARKER_MAX) {
+    marker = MARKER_NONE;
+  }
+
+  ptile->markers[pplayer->team->index] = marker;
+  send_tile_info(pplayer->connections, ptile);
+}
+
 /**************************************************************************
 ...
 **************************************************************************/
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.275
diff -p -u -r1.275 savegame.c
--- server/savegame.c   18 Aug 2005 06:44:29 -0000      1.275
+++ server/savegame.c   19 Aug 2005 08:02:14 -0000
@@ -608,6 +608,14 @@ static void map_tiles_load(struct sectio
     if (ptile->spec_sprite) {
       ptile->spec_sprite = mystrdup(ptile->spec_sprite);
     }
+
+    team_iterate(pteam) {
+      ptile->markers[pteam->index]
+       = secfile_lookup_int_default(file, MARKER_NONE,
+                                    "map.marker_%d_%d_%d",
+                                    ptile->nat_x, ptile->nat_y,
+                                    pteam->index);
+    } team_iterate_end;
   } whole_map_iterate_end;
 }
 
@@ -812,6 +820,13 @@ static void map_save(struct section_file
       secfile_insert_str(file, ptile->spec_sprite, "map.spec_sprite_%d_%d",
                         ptile->nat_x, ptile->nat_y);
     }
+    team_iterate(pteam) {
+      if (ptile->markers[pteam->index] != MARKER_NONE) {
+       secfile_insert_int(file, ptile->markers[pteam->index],
+                          "map.marker_%d_%d_%d",
+                          ptile->nat_x, ptile->nat_y, pteam->index);
+      }
+    } team_iterate_end;
   } whole_map_iterate_end;
     
   /* put the terrain type */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#7152) tile markers, Jason Short <=