Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2003:
[Freeciv-Dev] Re: (PR#717) WISHLIST: Goto cursor shows movecost
Home

[Freeciv-Dev] Re: (PR#717) WISHLIST: Goto cursor shows movecost

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: sigra@xxxxxxx, stepan@xxxxxxxx, Brett.Albertson@xxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#717) WISHLIST: Goto cursor shows movecost
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 15 Aug 2003 07:08:46 -0700
Reply-to: rt@xxxxxxxxxxxxxx

Gregory Berkolaiko wrote:
> On Thu, 14 Aug 2003, Jason Short wrote:
> 
> 
>>A new version of this patch.
>>
>>Changes:
>>
>>- Drop hundreds and thousands' place; these are totally unnecessary.
>>- Fix the sprite name for the tens' place.
>>- Remove unnecessary #include.
>>
>>Problems:
>>
>>- Doesn't work with waypoints.  How can this be solved with PF?  We
> 
> 
> int get_length(void)
> {
>   int i, time = 0;
> 
>   for(i = 0; i < goto_map.num_parts; i++) {
>     time += goto_map.parts[goto_map.num_parts - 1].time;
>   }
> 
>   return time;
> }
> 
> should do the trick imo.

Indeed.  Of course PF is cleverer than I had thought...

jason

? rc
Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.58
diff -u -r1.58 goto.c
--- client/goto.c       2003/08/12 21:31:03     1.58
+++ client/goto.c       2003/08/15 14:06:27
@@ -43,6 +43,7 @@
   int start_moves_left;
   int start_x, start_y;
   int end_moves_left;
+  int time;
   int end_x, end_y;
   struct pf_path *path;
   struct pf_map *map;
@@ -131,7 +132,7 @@
 {
   struct part *p = &goto_map.parts[goto_map.num_parts - 1];
   struct pf_path *new_path;
-  int i, start_index = 0;
+  int i, start_index = 0, old_x = -1, old_y = -1;
 
   freelog(LOG_DEBUG, "update_last_part(%d,%d) old (%d,%d)-(%d,%d)", x, y,
           p->start_x, p->start_y, p->end_x, p->end_y);
@@ -174,6 +175,9 @@
     }
     pf_destroy_path(p->path);
     p->path = NULL;
+
+    old_x = p->end_x;
+    old_y = p->end_y;
   }
 
   /* Draw the new path */
@@ -192,6 +196,13 @@
   p->end_x = x;
   p->end_y = y;
   p->end_moves_left = pf_last_position(p->path)->moves_left;
+  p->time = pf_last_position(p->path)->turn;
+
+  /* Refresh tiles so turn information is shown. */
+  if (old_x != -1) {
+    refresh_tile_mapcanvas(old_x, old_y, FALSE);
+  }
+  refresh_tile_mapcanvas(x, y, FALSE);
 }
 
 /********************************************************************** 
@@ -630,6 +641,32 @@
   }
 
   return *get_drawn_char(x, y, dir);
+}
+
+/**************************************************************************
+  Return TRUE iff this is the endpoint of the path.
+***************************************************************************/
+bool is_endpoint(int x, int y)
+{
+  struct part *p = &goto_map.parts[goto_map.num_parts - 1];
+
+  return (is_active
+         && same_pos(p->end_x, p->end_y, x, y)
+         && !same_pos(p->start_x, p->start_y, x, y));
+}
+
+/**************************************************************************
+  Return the path length.
+***************************************************************************/
+int get_length(void)
+{
+  int time = 0, i;
+
+  for(i = 0; i < goto_map.num_parts; i++) {
+    time += goto_map.parts[i].time;
+  }
+
+  return time;
 }
 
 /**************************************************************************
Index: client/goto.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.h,v
retrieving revision 1.10
diff -u -r1.10 goto.h
--- client/goto.h       2003/08/11 02:31:38     1.10
+++ client/goto.h       2003/08/15 14:06:27
@@ -28,6 +28,9 @@
 
 void draw_line(int dest_x, int dest_y);
 int get_drawn(int x, int y, int dir);
+ 
+bool is_endpoint(int x, int y);
+int get_length(void);
 
 void send_goto_path(struct unit *punit, struct pf_path *path);
 void send_patrol_route(struct unit *punit);
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.58
diff -u -r1.58 mapview_common.c
--- client/mapview_common.c     2003/08/12 18:54:37     1.58
+++ client/mapview_common.c     2003/08/15 14:06:27
@@ -17,6 +17,7 @@
 
 #include <assert.h>
 
+#include "fcintl.h"
 #include "log.h"
 #include "map.h"
 #include "support.h"
@@ -405,6 +406,36 @@
 }
 
 /**************************************************************************
+  Draw the length of the path on top of the tile.
+**************************************************************************/
+void put_path_length(int map_x, int map_y, int length,
+                    int offset_x, int offset_y,
+                    int width, int height)
+{
+  int units = length % NUM_TILES_DIGITS;
+  int tens = (length / 10) % NUM_TILES_DIGITS;
+  int canvas_x, canvas_y;
+
+  if (length >= 100) {
+    freelog(LOG_ERROR, _("Paths longer than 99 steps are not supported.\n"
+                        "Report this bug to bugs@xxxxxxxxxxxxxxxxxxx."));
+  }
+
+  if (map_to_canvas_pos(&canvas_x, &canvas_y, map_x, map_y)) {
+    if (sprites.path.turns[units]) {
+      gui_put_sprite(mapview_canvas.store, canvas_x, canvas_y,
+                    sprites.path.turns[units],
+                    offset_x, offset_y, width, height);
+    }
+    if (tens > 0 && sprites.path.turns_tens[tens]) {
+      gui_put_sprite(mapview_canvas.store, canvas_x, canvas_y,
+                    sprites.path.turns_tens[tens],
+                    offset_x, offset_y, width, height);
+    }
+  }
+}
+
+/**************************************************************************
   Draw the given unit onto the canvas store at the given location.
 
   unit_offset_x, unit_offset_y, unit_width, unit_height are used
@@ -603,6 +634,11 @@
        draw_segment(line_x, line_y, DIR8_NORTHEAST);
       }
     }
+
+    if (is_endpoint(map_x, map_y)) {
+      put_path_length(map_x, map_y, get_length(),
+                     0, 0, NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT);
+    }
   }
 }
 
@@ -736,6 +772,10 @@
                           offset_x, offset_y, offset_y_unit,
                           width, height, height_unit,
                           draw);
+      if (is_endpoint(map_x, map_y)) {
+       put_path_length(map_x, map_y, get_length(),
+                       offset_x, offset_y, width, height);
+      }
     } else {
       gui_put_sprite(mapview_canvas.store, canvas_x, canvas_y,
                     sprites.black_tile, offset_x, offset_y, width, height);
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.37
diff -u -r1.37 mapview_common.h
--- client/mapview_common.h     2003/07/25 18:59:45     1.37
+++ client/mapview_common.h     2003/08/15 14:06:27
@@ -144,6 +144,10 @@
 bool tile_visible_mapcanvas(int map_x, int map_y);
 bool tile_visible_and_not_on_border_mapcanvas(int map_x, int map_y);
 
+void put_path_length(int map_x, int map_y, int length,
+                    int offset_x, int offset_y,
+                    int width, int height);
+
 void put_unit(struct unit *punit, struct canvas_store *pcanvas_store,
              int canvas_x, int canvas_y,
              int unit_offset_x, int unit_offset_y,
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.130
diff -u -r1.130 tilespec.c
--- client/tilespec.c   2003/08/14 18:49:56     1.130
+++ client/tilespec.c   2003/08/15 14:06:28
@@ -165,6 +165,11 @@
 */
 static bool no_backdrop = FALSE;
 
+
+static struct Sprite* lookup_sprite_tag_alt(const char *tag, const char *alt,
+                                           bool required, const char *what,
+                                           const char *name);
+
 /**********************************************************************
   Returns a static list of tilesets available on the system by
   searching all data directories for files matching TILESPEC_SUFFIX.
@@ -742,6 +747,11 @@
 #define SET_SPRITE_OPT(field, tag) \
   sprites.field = load_sprite(tag)
 
+#define SET_SPRITE_ALT_OPT(field, tag, alt) do {               \
+      sprites.field = lookup_sprite_tag_alt(tag, alt, FALSE,   \
+                                           "sprite", #field); \
+    } while (FALSE)
+
 /**********************************************************************
   Initialize 'sprites' structure based on hardwired tags which
   freeciv always requires. 
@@ -917,11 +927,18 @@
   SET_SPRITE(city.disorder, "city.disorder");
 
   for(i=0; i<NUM_TILES_DIGITS; i++) {
+    char buffer2[512];
+
     my_snprintf(buffer, sizeof(buffer), "city.size_%d", i);
     SET_SPRITE(city.size[i], buffer);
+    my_snprintf(buffer2, sizeof(buffer2), "path.turns_%d", i);
+    SET_SPRITE_ALT_OPT(path.turns[i], buffer2, buffer);
+
     if(i!=0) {
       my_snprintf(buffer, sizeof(buffer), "city.size_%d", i*10);
       SET_SPRITE(city.size_tens[i], buffer);
+      my_snprintf(buffer2, sizeof(buffer2), "path.turns_%d", i * 10);
+      SET_SPRITE_ALT_OPT(path.turns_tens[i], buffer2, buffer);
     }
     my_snprintf(buffer, sizeof(buffer), "city.t_food_%d", i);
     SET_SPRITE(city.tile_foodnum[i], buffer);
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.47
diff -u -r1.47 tilespec.h
--- client/tilespec.h   2003/08/12 18:54:37     1.47
+++ client/tilespec.h   2003/08/15 14:06:28
@@ -182,6 +182,11 @@
       ***tile;
   } city;
   struct {
+    struct Sprite
+      *turns[NUM_TILES_DIGITS],
+      *turns_tens[NUM_TILES_DIGITS];
+  } path;
+  struct {
     struct Sprite *attention;
   } user;
   struct {

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