Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2004:
[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: Brett.Albertson@xxxxxxxxxxxxxx, sigra@xxxxxxx, stepan@xxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#717) WISHLIST: Goto cursor shows movecost
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 7 Jun 2004 22:36:45 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=717 >

Jason Short wrote:

> This version of the patch does the text and the graphics.  But
> personally I think the text is rather useless.

And the patch.

I changed the internal design a bit.  It's simpler now, and should be 
faster as well.

jason

Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.69
diff -u -r1.69 goto.c
--- client/goto.c       11 May 2004 17:40:06 -0000      1.69
+++ client/goto.c       8 Jun 2004 05:27:19 -0000
@@ -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);
 }
 
 /********************************************************************** 
@@ -450,6 +461,20 @@
   *y = p->end_y;
 }
 
+/**************************************************************************
+  Return the path length (in turns).
+***************************************************************************/
+int get_goto_turns(void)
+{
+  int time = 0, i;
+
+  for(i = 0; i < goto_map.num_parts; i++) {
+    time += goto_map.parts[i].time;
+  }
+
+  return time;
+}
+
 /********************************************************************** 
   Puts a line to dest_x, dest_y on the map according to the current
   goto_map.
@@ -464,6 +489,9 @@
   normalize_map_pos(&dest_x, &dest_y);
 
   update_last_part(dest_x, dest_y);
+
+  /* Update goto data in info label. */
+  update_unit_info_label(get_unit_in_focus());
 }
 
 /****************************************************************************
Index: client/goto.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.h,v
retrieving revision 1.12
diff -u -r1.12 goto.h
--- client/goto.h       11 May 2004 17:40:06 -0000      1.12
+++ client/goto.h       8 Jun 2004 05:27:19 -0000
@@ -23,11 +23,14 @@
 void exit_goto_state(void);
 bool goto_is_active(void);
 void get_line_dest(int *x, int *y);
+int get_goto_turns(void);
 void goto_add_waypoint(void);
 bool goto_pop_waypoint(void);
 
 void draw_line(int dest_x, int dest_y);
 bool is_drawn_line(int x, int y, int dir);
+ 
+bool is_endpoint(int x, int y);
 
 void request_orders_cleared(struct unit *punit);
 void send_goto_path(struct unit *punit, struct pf_path *path);
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.122
diff -u -r1.122 mapview_common.c
--- client/mapview_common.c     4 Jun 2004 05:03:27 -0000       1.122
+++ client/mapview_common.c     8 Jun 2004 05:27:19 -0000
@@ -17,6 +17,7 @@
 
 #include <assert.h>
 
+#include "fcintl.h"
 #include "log.h"
 #include "map.h"
 #include "rand.h"
@@ -683,6 +684,39 @@
 }
 
 /**************************************************************************
+  Draw the length of the path on top of the tile.
+**************************************************************************/
+static void put_path_length(void)
+{
+  if (goto_is_active()) {
+    int length = get_goto_turns();
+    int units = length % NUM_TILES_DIGITS;
+    int tens = (length / 10) % NUM_TILES_DIGITS;
+    int canvas_x, canvas_y, map_x, map_y;
+
+
+    get_line_dest(&map_x, &map_y);
+    length = get_goto_turns();
+
+    if (length >= 100) {
+      freelog(LOG_ERROR, _("Paths longer than 99 turns 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]) {
+       canvas_put_sprite_full(mapview_canvas.store, canvas_x, canvas_y,
+                              sprites.path.turns[units]);
+      }
+      if (tens > 0 && sprites.path.turns_tens[tens]) {
+       canvas_put_sprite_full(mapview_canvas.store, canvas_x, canvas_y,
+                              sprites.path.turns_tens[tens]);
+      }
+    }
+  }
+}
+
+/**************************************************************************
   Draw the given unit onto the canvas store at the given location.
 
   unit_offset_x, unit_offset_y, unit_width, unit_height are used
@@ -1426,6 +1460,9 @@
     } gui_rect_iterate_end;
   }
 
+  /* Put goto target. */
+  put_path_length();
+
   show_city_descriptions(canvas_x, canvas_y, width, height);
 
   if (!full) {
Index: client/text.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.c,v
retrieving revision 1.2
diff -u -r1.2 text.c
--- client/text.c       14 May 2004 15:34:45 -0000      1.2
+++ client/text.c       8 Jun 2004 05:27:20 -0000
@@ -28,7 +28,7 @@
 #include "civclient.h"
 
 #include "control.h"
-
+#include "goto.h"
 #include "text.h"
 
 /*
@@ -483,7 +483,7 @@
        get_tile_infrastructure_set(map_get_tile(punit->x, punit->y));
 
     if (hover_unit == punit->id) {
-      add_line(_("Select destination"));
+      add_line(_("Turns to target: %d"), get_goto_turns());
     } else {
       add_line("%s", unit_activity_text(punit));
     }
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.174
diff -u -r1.174 tilespec.c
--- client/tilespec.c   6 Jun 2004 06:09:46 -0000       1.174
+++ client/tilespec.c   8 Jun 2004 05:27:22 -0000
@@ -184,6 +184,10 @@
 */
 static bool focus_unit_hidden = 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.
@@ -958,6 +962,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. 
@@ -1132,11 +1141,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.70
diff -u -r1.70 tilespec.h
--- client/tilespec.h   6 Jun 2004 06:09:46 -0000       1.70
+++ client/tilespec.h   8 Jun 2004 05:27:22 -0000
@@ -228,6 +228,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]