[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]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=717 >
Gregory Berkolaiko wrote:
> the turns sprites at waypoints
> sometimes appear and sometimes get erased (not sure which one is a bug).
And here's the fix.
jason
? gmon.out
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 20 Jun 2004 22:08:43 -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 = p->start_x, old_y = p->start_y;
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,11 @@
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. */
+ refresh_tile_mapcanvas(old_x, old_y, FALSE);
+ refresh_tile_mapcanvas(x, y, FALSE);
}
/**********************************************************************
@@ -241,6 +250,7 @@
p->path = NULL;
p->end_x = p->start_x;
p->end_y = p->start_y;
+ p->time = 0;
parameter.start_x = p->start_x;
parameter.start_y = p->start_y;
parameter.moves_left_initially = p->start_moves_left;
@@ -450,6 +460,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 +488,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 20 Jun 2004 22:08:43 -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.129
diff -u -r1.129 mapview_common.c
--- client/mapview_common.c 20 Jun 2004 13:24:10 -0000 1.129
+++ client/mapview_common.c 20 Jun 2004 22:08:43 -0000
@@ -17,6 +17,7 @@
#include <assert.h>
+#include "fcintl.h"
#include "log.h"
#include "map.h"
#include "rand.h"
@@ -699,6 +700,38 @@
}
/**************************************************************************
+ 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
@@ -1482,6 +1515,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.3
diff -u -r1.3 text.c
--- client/text.c 20 Jun 2004 13:16:04 -0000 1.3
+++ client/text.c 20 Jun 2004 22:08:44 -0000
@@ -28,7 +28,7 @@
#include "civclient.h"
#include "control.h"
-
+#include "goto.h"
#include "text.h"
/*
@@ -485,7 +485,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.175
diff -u -r1.175 tilespec.c
--- client/tilespec.c 16 Jun 2004 22:45:39 -0000 1.175
+++ client/tilespec.c 20 Jun 2004 22:08:44 -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.
@@ -959,6 +963,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.
@@ -1133,11 +1142,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 20 Jun 2004 22:08:44 -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 {
|
|