Freeciv-3.4
Loading...
Searching...
No Matches
mapview_common.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "fcintl.h"
20#include "log.h"
21#include "rand.h"
22#include "support.h"
23#include "timing.h"
24
25/* common */
26#include "featured_text.h"
27#include "game.h"
28#include "map.h"
29#include "traderoutes.h"
30#include "unitlist.h"
31
32/* client/include */
33#include "graphics_g.h"
34#include "gui_main_g.h"
35#include "mapctrl_g.h"
36#include "mapview_g.h"
37
38/* client */
39#include "client_main.h"
40#include "climap.h"
41#include "control.h"
42#include "editor.h"
43#include "goto.h"
44#include "citydlg_common.h"
45#include "overview_common.h"
46#include "svgflag.h"
47#include "tilespec.h"
48#include "zoom.h"
49
50#include "mapview_common.h"
51
52
53struct tile_hash *mapdeco_highlight_table;
54struct tile_hash *mapdeco_crosshair_table;
55
59
60static inline struct gotoline_counter *gotoline_counter_new(void);
62
63#define SPECHASH_TAG gotoline
64#define SPECHASH_IKEY_TYPE struct tile *
65#define SPECHASH_IDATA_TYPE struct gotoline_counter *
66#define SPECHASH_IDATA_FREE gotoline_counter_destroy
67#include "spechash.h"
68#define gotoline_hash_iterate(hash, ptile, pglc) \
69 TYPED_HASH_ITERATE(struct tile *, struct gotoline_counter *, \
70 hash, ptile, pglc)
71#define gotoline_hash_iterate_end HASH_ITERATE_END
72
74
77
79
80const struct tile *center_tile = NULL;
81
83
84static void base_canvas_to_map_pos(float zoom, int *map_x, int *map_y,
85 float canvas_x, float canvas_y);
86
87static void show_full_citybar(struct canvas *pcanvas,
88 const int canvas_x0, const int canvas_y0,
89 struct city *pcity, int *width, int *height)
90 fc__attribute((nonnull(5, 6)));
91static void show_city_desc(struct canvas *pcanvas,
92 int canvas_x, int canvas_y,
93 struct city *pcity, int *width, int *height)
94 fc__attribute((nonnull(5, 6)));
95
103
104/* A tile update has a tile associated with it as well as an area type.
105 * See unqueue_mapview_updates() for a thorough explanation. */
115
116static void queue_mapview_update(enum update_type update);
117static void queue_mapview_tile_update(struct tile *ptile,
119
120/* Helper struct for drawing trade routes. */
122 float x, y, width, height;
123};
124
125/* A trade route line might need to be drawn in two parts. */
126static const int MAX_TRADE_ROUTE_DRAW_LINES = 2;
127
128static struct timer *anim_timer = NULL;
129
131
133{
135 int id;
137 int old_x;
138 int old_y;
139 int width;
141 union {
142 struct {
143 struct unit *mover;
144 struct tile *src;
145 struct tile *dest;
149 struct {
158 int steps;
160 struct {
161 struct tile *tile;
162 const struct sprite_vector *sprites;
165 struct {
166 bool shown;
169 };
170};
171
172#define SPECLIST_TAG animation
173#define SPECLIST_TYPE struct animation
174#include "speclist.h"
175
177
178/************************************************************************/
182{
184}
185
186/************************************************************************/
190{
191 if (animations != NULL) {
192 int i;
193 size_t last = animation_list_size(animations);
194
195 for (i = 0; i < last; i++) {
197
198 switch (anim->type) {
199 case ANIM_MOVEMENT:
200 unit_virtual_destroy(anim->movement.mover);
201 break;
202 case ANIM_BATTLE:
203 unit_virtual_destroy(anim->battle.virt_winner);
204 unit_virtual_destroy(anim->battle.virt_loser);
205 break;
206 case ANIM_EXPL:
207 case ANIM_NUKE:
208 /* Nothing to free */
209 break;
210 }
211
212 free(anim);
213 }
214
217 }
218}
219
220/************************************************************************/
229
230/************************************************************************/
233static void animation_add(struct animation *anim)
234{
237 }
238
239 anim->finished = FALSE;
240 anim->old_x = -1; /* Initial frame */
242}
243
244/************************************************************************/
247static bool movement_animation(struct animation *anim, double time_gone)
248{
249 float start_x, start_y;
250 int new_x, new_y;
252 double mytime = MIN(time_gone, timing_sec);
253 struct unit *punit = anim->movement.mover;
254
255 if (punit != NULL) {
256 tile_to_canvas_pos(&start_x, &start_y, map_zoom, anim->movement.src);
260 }
261 new_x = start_x + anim->movement.canvas_dx * (mytime / timing_sec);
262 new_y = start_y + anim->movement.canvas_dy * (mytime / timing_sec);
263
264 if (anim->old_x >= 0) {
265 update_map_canvas(anim->old_x, anim->old_y,
266 anim->width, anim->height);
267 }
269 dirty_rect(new_x, new_y, anim->width, anim->height);
270 anim->old_x = new_x;
271 anim->old_y = new_y;
272
273 if (time_gone >= timing_sec) {
274 /* Animation over */
275 unit_virtual_destroy(anim->movement.mover);
276
277 return TRUE;
278 }
279 } else {
280 return TRUE;
281 }
282
283 return FALSE;
284}
285
286/************************************************************************/
289static bool battle_animation(struct animation *anim, double time_gone)
290{
291 double time_per_step;
292 int step;
293 float canvas_x, canvas_y;
295 * anim->battle.steps / 1000.0;
296
297 if (time_gone >= timing_sec) {
298 /* Animation over */
299
300 unit_virtual_destroy(anim->battle.virt_winner);
301 unit_virtual_destroy(anim->battle.virt_loser);
302
303 return TRUE;
304 }
305
306 time_per_step = timing_sec / anim->battle.steps;
308
309 if (tile_to_canvas_pos(&canvas_x, &canvas_y, map_zoom, anim->battle.loser_tile)) {
310 anim->battle.virt_loser->hp
311 = anim->battle.loser_hp_start - ((anim->battle.loser_hp_start
312 - anim->battle.loser_hp_end)
313 * step / anim->battle.steps);
314
318 }
319
320 put_unit(anim->battle.virt_loser, mapview.store, map_zoom,
325 }
326
327 if (tile_to_canvas_pos(&canvas_x, &canvas_y, map_zoom, anim->battle.winner_tile)) {
328 anim->battle.virt_winner->hp
329 = anim->battle.winner_hp_start - ((anim->battle.winner_hp_start
330 - anim->battle.winner_hp_end)
331 * step / anim->battle.steps);
332
336 }
337 put_unit(anim->battle.virt_winner, mapview.store, map_zoom,
342 }
343
344 return FALSE;
345}
346
347/************************************************************************/
350static bool explosion_animation(struct animation *anim, double time_gone)
351{
352 float canvas_x, canvas_y;
353 double timing_sec;
354
355 if (anim->expl.sprite_count <= 0) {
356 return TRUE;
357 }
358
360 * anim->expl.sprite_count / 1000.0;
361
362 if (tile_to_canvas_pos(&canvas_x, &canvas_y, map_zoom, anim->expl.tile)) {
363 double time_per_frame = timing_sec / anim->expl.sprite_count;
364 int frame = time_gone / time_per_frame;
365 struct sprite *spr;
366 int w, h;
367
368 frame = MIN(frame, anim->expl.sprite_count - 1);
369
370 if (anim->old_x >= 0) {
371 update_map_canvas(anim->old_x, anim->old_y,
372 anim->width, anim->height);
373 }
374
375 spr = *sprite_vector_get(anim->expl.sprites, frame);
376 get_sprite_dimensions(spr, &w, &h);
377
380 - w / 2,
382 - h / 2,
383 spr);
386
387 anim->old_x = canvas_x;
388 anim->old_y = canvas_y;
389 }
390
391 if (time_gone >= timing_sec) {
392 /* Animation over */
393 return TRUE;
394 }
395
396 return FALSE;
397}
398
399/************************************************************************/
402static bool nuke_animation(struct animation *anim, double time_gone)
403{
404 if (!anim->nuke.shown) {
405 float canvas_x, canvas_y;
407 int w, h;
408
409 (void) tile_to_canvas_pos(&canvas_x, &canvas_y, map_zoom, anim->nuke.nuke_tile);
411
414 - w / 2,
416 - h / 2,
417 nuke_spr);
420
421 anim->old_x = canvas_x;
422 anim->old_y = canvas_y;
423
424 anim->nuke.shown = TRUE;
425
426 return FALSE;
427 }
428
429 if (time_gone > 1.0) {
431
432 return TRUE;
433 }
434
435 return FALSE;
436}
437
438/************************************************************************/
442{
445
446 if (anim->finished) {
447 /* Animation over */
448
449 anim->id = -1;
450 if (anim->old_x >= 0) {
451 update_map_canvas(anim->old_x, anim->old_y, anim->width, anim->height);
452 }
454 free(anim);
455
457 /* Start next */
459 }
460 } else {
462 bool finished = FALSE;
463
464 switch (anim->type) {
465 case ANIM_MOVEMENT:
467 break;
468 case ANIM_BATTLE:
470 break;
471 case ANIM_EXPL:
473 break;
474 case ANIM_NUKE:
476 }
477
478 if (finished) {
479 anim->finished = TRUE;
480 }
481 }
482 }
483}
484
485/************************************************************************/
488static inline struct gotoline_counter *gotoline_counter_new(void)
489{
490 struct gotoline_counter *pglc = fc_calloc(1, sizeof(*pglc));
491 return pglc;
492}
493
494/************************************************************************/
498{
500 free(pglc);
501}
502
503/************************************************************************/
506void refresh_tile_mapcanvas(struct tile *ptile,
507 bool full_refresh, bool write_to_screen)
508{
509 if (full_refresh) {
511 } else {
513 }
514 if (write_to_screen) {
516 }
517}
518
519/************************************************************************/
522void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile,
523 bool full_refresh, bool write_to_screen)
524{
525 if (full_refresh && gui_options.draw_native) {
527 } else if (full_refresh && unit_drawn_with_city_outline(punit, TRUE)) {
529 } else {
531 }
532 if (write_to_screen) {
534 }
535}
536
537/************************************************************************/
543void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile,
544 bool full_refresh, bool write_to_screen)
545{
546 if (full_refresh && (gui_options.draw_map_grid || gui_options.draw_borders)) {
548 } else {
550 }
551 if (write_to_screen) {
553 }
554}
555
556/************************************************************************/
565void map_to_gui_vector(const struct tileset *t, float zoom,
566 float *gui_dx, float *gui_dy, int map_dx, int map_dy)
567{
568 if (tileset_is_isometric(t)) {
569 /*
570 * Convert the map coordinates to isometric GUI
571 * coordinates. We'll make tile map(0,0) be the origin, and
572 * transform like this:
573 *
574 * 3
575 * 123 2 6
576 * 456 -> becomes -> 1 5 9
577 * 789 4 8
578 * 7
579 */
580 *gui_dx = (map_dx - map_dy) * tileset_tile_width(t) / 2 * zoom;
581 *gui_dy = (map_dx + map_dy) * tileset_tile_height(t) / 2 * zoom;
582 } else {
583 *gui_dx = map_dx * tileset_tile_height(t) * zoom;
584 *gui_dy = map_dy * tileset_tile_width(t) * zoom;
585 }
586}
587
588/************************************************************************/
594static void map_to_gui_pos(const struct tileset *t, float zoom,
595 float *gui_x, float *gui_y, int map_x, int map_y)
596{
597 /* Since the GUI origin is the same as the map origin we can just do a
598 * vector conversion. */
600}
601
602/************************************************************************/
609static void gui_to_map_pos(const struct tileset *t, float zoom,
610 int *map_x, int *map_y, float gui_x, float gui_y)
611{
612 const float W = tileset_tile_width(t) * zoom, H = tileset_tile_height(t) * zoom;
613 const float HH = tileset_hex_height(t) * zoom, HW = tileset_hex_width(t) * zoom;
614
615 if (HH > 0 || HW > 0) {
616 /* To handle hexagonal cases we have to revert to a less elegant method
617 * of calculation. */
618 float x, y;
619 int dx, dy;
620 int xmult, ymult, mod, compar;
621
623
624 x = DIVIDE((int)gui_x, (int)W);
625 y = DIVIDE((int)gui_y, (int)H);
626 dx = gui_x - x * W;
627 dy = gui_y - y * H;
628 fc_assert(dx >= 0 && dx < W);
629 fc_assert(dy >= 0 && dy < H);
630
631 /* Now fold so we consider only one-quarter tile. */
632 xmult = (dx >= W / 2) ? -1 : 1;
633 ymult = (dy >= H / 2) ? -1 : 1;
634 dx = (dx >= W / 2) ? (W - 1 - dx) : dx;
635 dy = (dy >= H / 2) ? (H - 1 - dy) : dy;
636
637 /* Next compare to see if we're across onto the next tile. */
638 if (HW > 0) {
639 compar = (dx - HW / 2) * (H / 2) - (H / 2 - 1 - dy) * (W / 2 - HW);
640 } else {
641 compar = (dy - HH / 2) * (W / 2) - (W / 2 - 1 - dx) * (H / 2 - HH);
642 }
643 mod = (compar < 0) ? -1 : 0;
644
645 *map_x = (x + y) + mod * (xmult + ymult) / 2;
646 *map_y = (y - x) + mod * (ymult - xmult) / 2;
647 } else if (tileset_is_isometric(t)) {
648 /* The basic operation here is a simple pi/4 rotation; however, we
649 * have to first scale because the tiles have different width and
650 * height. Mathematically, this looks like
651 * | 1/W 1/H | |x| |x`|
652 * | | | | -> | |
653 * |-1/W 1/H | |y| |y`|
654 *
655 * Where W is the tile width and H the height.
656 *
657 * In simple terms, this is
658 * map_x = [ x / W + y / H ]
659 * map_y = [ - x / W + y / H ]
660 * where [q] stands for integer part of q.
661 *
662 * Here the division is proper mathematical floating point division.
663 *
664 * We have to subtract off a half-tile in the X direction before doing
665 * the transformation. This is because, although the origin of the tile
666 * is the top-left corner of the bounding box, after the transformation
667 * the top corner of the diamond-shaped tile moves into this position.
668 *
669 * The calculation is complicated somewhat because of two things: we
670 * only use integer math, and C integer division rounds toward zero
671 * instead of rounding down.
672 *
673 * For another example of this math, see canvas_to_city_pos().
674 */
675 gui_x -= W / 2;
676 *map_x = DIVIDE((int)(gui_x * H + gui_y * W), (int)(W * H));
677 *map_y = DIVIDE((int)(gui_y * W - gui_x * H), (int)(W * H));
678 } else { /* tileset_is_isometric(t) */
679 /* We use DIVIDE so that we will get the correct result even
680 * for negative coordinates. */
681 *map_x = DIVIDE((int)gui_x, (int)W);
682 *map_y = DIVIDE((int)gui_y, (int)H);
683 }
684}
685
686/************************************************************************/
708bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, float zoom,
709 const struct tile *ptile)
710{
711 int center_map_x, center_map_y, dx, dy, tile_x, tile_y;
712
713 /*
714 * First we wrap the coordinates to hopefully be within the mapview
715 * window. We do this by finding the position closest to the center
716 * of the window.
717 */
718 /* TODO: Cache the value of this position */
720 mapview.width / 2,
721 mapview.height / 2);
724 tile_y);
725
730
731 /*
732 * Finally we clip.
733 *
734 * This check is tailored to work for both iso-view and classic view.
735 * Note that (canvas_x, canvas_y) need not be aligned to a tile boundary, and
736 * that the position is at the top-left of the NORMAL (not UNIT) tile.
737 * This checks to see if _any part_ of the tile is present on the backing
738 * store. Even if it's not visible on the canvas, if it's present on the
739 * backing store we need to draw it in case the canvas is resized.
740 */
747}
748
749/************************************************************************/
753static void base_canvas_to_map_pos(float zoom, int *map_x, int *map_y,
754 float canvas_x, float canvas_y)
755{
757 canvas_x + mapview.gui_x0 / map_zoom * zoom,
758 canvas_y + mapview.gui_y0 / map_zoom * zoom);
759}
760
761/************************************************************************/
766 float zoom)
767{
768 int map_x, map_y;
769
771 if (normalize_map_pos(&(wld.map), &map_x, &map_y)) {
772 return map_pos_to_tile(&(wld.map), map_x, map_y);
773 } else {
774 return NULL;
775 }
776}
777
778/************************************************************************/
783 float zoom)
784{
785 int map_x, map_y;
786
788
789 return nearest_real_tile(&(wld.map), map_x, map_y);
790}
791
792/************************************************************************/
796static void normalize_gui_pos(const struct tileset *t, float zoom,
797 float *gui_x, float *gui_y)
798{
800 float gui_x0, gui_y0;
801
802 /* Convert the (gui_x, gui_y) into a (map_x, map_y) plus a GUI offset
803 * from this tile. */
804 gui_to_map_pos(t, zoom, &map_x, &map_y, *gui_x, *gui_y);
805 map_to_gui_pos(t, zoom, &gui_x0, &gui_y0, map_x, map_y);
806 diff_x = *gui_x - gui_x0;
807 diff_y = *gui_y - gui_y0;
808
809 /* Perform wrapping without any realness check. It's important that
810 * we wrap even if the map position is unreal, which normalize_map_pos()
811 * doesn't necessarily do. */
815 }
818 }
820
821 /* Now convert the wrapped map position back to a GUI position and add the
822 * offset back on. */
823 map_to_gui_pos(t, zoom, gui_x, gui_y, map_x, map_y);
824 *gui_x += diff_x;
825 *gui_y += diff_y;
826}
827
828/************************************************************************/
832static void gui_distance_vector(const struct tileset *t, float zoom,
833 float *gui_dx, float *gui_dy,
834 float gui_x0, float gui_y0,
835 float gui_x1, float gui_y1)
836{
837 int map_x0, map_y0, map_x1, map_y1;
840 int map_dx, map_dy;
841
842 /* Make sure positions are canonical. Yes, this is the only way. */
843 normalize_gui_pos(t, zoom, &gui_x0, &gui_y0);
844 normalize_gui_pos(t, zoom, &gui_x1, &gui_y1);
845
846 /* Now we have to find the offset of each GUI position from its tile
847 * origin. This is complicated: it means converting to a map position and
848 * then back to the GUI position to find the tile origin, then subtracting
849 * to get the offset. */
850 gui_to_map_pos(t, zoom, &map_x0, &map_y0, gui_x0, gui_y0);
852
853 map_to_gui_pos(t, zoom, &gui_x0_base, &gui_y0_base, map_x0, map_y0);
855
856 gui_x0_diff = gui_x0 - gui_x0_base;
857 gui_y0_diff = gui_y0 - gui_y0_base;
860
861 /* Next we find the map distance vector and convert this into a GUI
862 * vector. */
863 base_map_distance_vector(&map_dx, &map_dy, map_x0, map_y0, map_x1, map_y1);
865
866 /* Finally we add on the difference in offsets to retain pixel
867 * resolution. */
870}
871
872/************************************************************************/
876static void base_set_mapview_origin(float gui_x0, float gui_y0, float zoom)
877{
878 float old_gui_x0, old_gui_y0;
879 float dx, dy;
880 const int width = mapview.width, height = mapview.height;
883
884 /* Then update everything. This does some tricky math to avoid having
885 * to do unnecessary redraws in update_map_canvas(). This makes for ugly
886 * code but speeds up the mapview by a large factor. */
887
888 /* We need to calculate the vector of movement of the mapview. So
889 * we find the GUI distance vector and then use this to calculate
890 * the original mapview origin relative to the current position. Thus
891 * if we move one tile to the left, even if this causes GUI positions
892 * to wrap the distance vector is only one tile. */
893 normalize_gui_pos(tileset, zoom, &gui_x0, &gui_y0);
894 gui_distance_vector(tileset, zoom, &dx, &dy,
896 gui_x0, gui_y0);
897 old_gui_x0 = gui_x0 - dx;
898 old_gui_y0 = gui_y0 - dy;
899
900 mapview.gui_x0 = gui_x0;
901 mapview.gui_y0 = gui_y0;
902
903 /* Find the overlapping area of the new and old mapview. This is
904 * done in GUI coordinates. Note that if the GUI coordinates wrap
905 * no overlap will be found. */
906 common_x0 = MAX(old_gui_x0, gui_x0);
907 common_x1 = MIN(old_gui_x0, gui_x0) + width;
908 common_y0 = MAX(old_gui_y0, gui_y0);
909 common_y1 = MIN(old_gui_y0, gui_y0) + height;
910
913 /* Do a partial redraw only. This means the area of overlap (a
914 * rectangle) is copied. Then the remaining areas (two rectangles)
915 * are updated through update_map_canvas(). */
916 struct canvas *target = mapview.tmp_store;
917
918 if (old_gui_x0 < gui_x0) {
919 update_x0 = MAX(old_gui_x0 + width, gui_x0);
920 update_x1 = gui_x0 + width;
921 } else {
922 update_x0 = gui_x0;
923 update_x1 = MIN(old_gui_x0, gui_x0 + width);
924 }
925 if (old_gui_y0 < gui_y0) {
926 update_y0 = MAX(old_gui_y0 + height, gui_y0);
927 update_y1 = gui_y0 + height;
928 } else {
929 update_y0 = gui_y0;
930 update_y1 = MIN(old_gui_y0, gui_y0 + height);
931 }
932
933 dirty_all();
934 canvas_copy(target, mapview.store,
937 common_x0 - gui_x0, common_y0 - gui_y0,
940 mapview.store = target;
941
942 if (update_y1 > update_y0) {
943 update_map_canvas(0, update_y0 - gui_y0,
945 }
946 if (update_x1 > update_x0) {
947 update_map_canvas(update_x0 - gui_x0, common_y0 - gui_y0,
949 }
950 } else {
951 dirty_all();
953 }
954
956
957 switch (hover_state) {
958 case HOVER_GOTO:
959 case HOVER_PATROL:
960 case HOVER_CONNECT:
962 break;
964 case HOVER_NONE:
965 case HOVER_TELEPORT:
966 case HOVER_PARADROP:
968 break;
969 }
970
971 if (rectangle_active) {
973 }
974}
975
976/************************************************************************/
980static bool calc_mapview_origin(float *gui_x0, float *gui_y0, float zoom)
981{
982 float xmin, ymin, xmax, ymax;
983 int xsize, ysize;
984
985 /* Normalize (wrap) the mapview origin. */
986 normalize_gui_pos(tileset, zoom, gui_x0, gui_y0);
987
988 /* First wrap/clip the position. Wrapping is done in native positions
989 * while clipping is done in scroll (native) positions. */
990 get_mapview_scroll_window(&xmin, &ymin, &xmax, &ymax, &xsize, &ysize);
991
993 *gui_x0 = CLIP(xmin, *gui_x0, xmax - xsize);
994 }
995
997 *gui_y0 = CLIP(ymin, *gui_y0, ymax - ysize);
998 }
999
1000 if (mapview.gui_x0 == *gui_x0 && mapview.gui_y0 == *gui_y0) {
1001 return FALSE;
1002 }
1003
1004 return TRUE;
1005}
1006
1007/************************************************************************/
1010void set_mapview_origin(float gui_x0, float gui_y0, float zoom)
1011{
1012 if (!calc_mapview_origin(&gui_x0, &gui_y0, zoom)) {
1013 return;
1014 }
1015
1018 /* TODO: Implement animation */
1019 base_set_mapview_origin(gui_x0, gui_y0, zoom);
1020 } else {
1021 int start_x = mapview.gui_x0, start_y = mapview.gui_y0;
1022 float diff_x, diff_y;
1024 double currtime;
1025 int frames = 0;
1026
1027 /* We track the average FPS, which is used to predict how long the
1028 * next draw will take. We start with a 100 FPS estimate - this
1029 * value will quickly become irrelevant as the correct value is
1030 * calculated, but it's needed to give an estimate of the FPS for
1031 * the first draw.
1032 *
1033 * Note that the initial value shouldn't be larger than the sliding
1034 * time, or we'll jump straight to the last frame. The FPS should
1035 * therefore be a "high" estimate. */
1036 static double total_frames = 0.01;
1037 static double total_time = 0.0001;
1038
1040 &diff_x, &diff_y, start_x, start_y, gui_x0, gui_y0);
1042
1044
1045 do {
1046 double mytime;
1047
1048 /* Get the current time, and add on the average 1/FPS, which is the
1049 * expected time this frame will take. This is done so that the
1050 * frame's position is calculated from the expected time when the
1051 * frame will complete, rather than the time when the frame drawing
1052 * is started. */
1055
1059 zoom);
1060 flush_dirty();
1061 gui_flush();
1062 frames++;
1063 } while (currtime < timing_sec);
1064
1066 total_frames += frames;
1068 log_debug("Got %d frames in %f seconds: %f FPS (avg %f).",
1069 frames, currtime, (double)frames / currtime,
1071
1072 /* A very small decay factor to make things more accurate when something
1073 * changes (mapview size, tileset change, etc.). This gives a
1074 * half-life of 68 slides. */
1075 total_frames *= 0.99;
1076 total_time *= 0.99;
1077 }
1078 } else {
1079 base_set_mapview_origin(gui_x0, gui_y0, zoom);
1080 }
1081
1083}
1084
1085/************************************************************************/
1111 float *xmax, float *ymax,
1112 int *xsize, int *ysize)
1113{
1114 int diff;
1115
1116 *xsize = mapview.width;
1117 *ysize = mapview.height;
1118
1120 /* If the map and view line up, it's easy. */
1121 NATIVE_TO_MAP_POS(xmin, ymin, 0, 0);
1123
1128
1129 /* To be able to center on positions near the edges, we have to be
1130 * allowed to scroll all the way to those edges. To allow wrapping the
1131 * clipping boundary needs to extend past the edge - a half-tile in
1132 * iso-view or a full tile in non-iso view. The above math already has
1133 * taken care of some of this so all that's left is to fix the corner
1134 * cases. */
1136 *xmax += *xsize;
1137
1138 /* We need to be able to scroll a little further to the left. */
1140 }
1142 *ymax += *ysize;
1143
1144 /* We need to be able to scroll a little further up. */
1146 }
1147 } else {
1148 /* Otherwise it's hard. Very hard. Impossible, in fact. This is just
1149 * an approximation - a huge bounding box. */
1151 int map_x, map_y;
1152
1153 NATIVE_TO_MAP_POS(&map_x, &map_y, 0, 0);
1155
1158
1161
1164
1165 *xmin = MIN(gui_x1, MIN(gui_x2, gui_x3)) - mapview.width / 2;
1167
1168 *xmax = MAX(gui_x4, MAX(gui_x2, gui_x3)) + mapview.width / 2;
1170 }
1171
1172 /* Make sure the scroll window is big enough to hold the mapview. If
1173 * not scrolling will be very ugly and the GUI may become confused. */
1174 diff = *xsize - (*xmax - *xmin);
1175 if (diff > 0) {
1176 *xmin -= diff / 2;
1177 *xmax += (diff + 1) / 2;
1178 }
1179
1180 diff = *ysize - (*ymax - *ymin);
1181 if (diff > 0) {
1182 *ymin -= diff / 2;
1183 *ymax += (diff + 1) / 2;
1184 }
1185
1186 log_debug("x: %f<-%d->%f; y: %f<-%f->%d",
1187 *xmin, *xsize, *xmax, *ymin, *ymax, *ysize);
1188}
1189
1190/************************************************************************/
1195{
1198
1200 *xstep /= 2;
1201 *ystep /= 2;
1202 }
1203}
1204
1205/************************************************************************/
1213
1214/************************************************************************/
1218{
1219 int gui_x0 = scroll_x, gui_y0 = scroll_y;
1220
1221 can_slide = FALSE;
1222 set_mapview_origin(gui_x0, gui_y0, zoom);
1223 can_slide = TRUE;
1224}
1225
1226/************************************************************************/
1230{
1232 mapview.height / 2,
1233 map_zoom);
1234}
1235
1236/************************************************************************/
1239void center_tile_mapcanvas(const struct tile *ptile)
1240{
1241 float gui_x, gui_y;
1242 int tile_x, tile_y;
1243 static bool first = TRUE;
1244
1245 if (first && can_slide) {
1246 return;
1247 }
1248 first = FALSE;
1249
1252
1253 /* Put the center pixel of the tile at the exact center of the mapview. */
1256
1258
1259 center_tile = ptile;
1260}
1261
1262/************************************************************************/
1266bool tile_visible_mapcanvas(struct tile *ptile)
1267{
1268 float dummy_x, dummy_y; /* Well, it needs two pointers... */
1269
1270 return tile_to_canvas_pos(&dummy_x, &dummy_y, map_zoom, ptile);
1271}
1272
1273/************************************************************************/
1285{
1286 float canvas_x, canvas_y;
1287 float xmin, ymin, xmax, ymax;
1288 int xsize, ysize, scroll_x, scroll_y;
1294
1295 get_mapview_scroll_window(&xmin, &ymin, &xmax, &ymax, &xsize, &ysize);
1297
1298 if (!tile_to_canvas_pos(&canvas_x, &canvas_y, map_zoom, ptile)) {
1299 /* The tile isn't visible at all. */
1300 return FALSE;
1301 }
1302
1303 /* For each direction: if the tile is too close to the mapview border
1304 * in that direction, and scrolling can get us any closer to the
1305 * border, then it's a border tile. We can only really check the
1306 * scrolling when the mapview window lines up with the map. */
1307 if (canvas_x < border_x
1309 return FALSE;
1310 }
1311 if (canvas_y < border_y
1313 return FALSE;
1314 }
1316 && (!same || scroll_x + xsize < xmax || current_wrap_has_flag(WRAP_X))) {
1317 return FALSE;
1318 }
1320 && (!same || scroll_y + ysize < ymax || current_wrap_has_flag(WRAP_Y))) {
1321 return FALSE;
1322 }
1323
1324 return TRUE;
1325}
1326
1327/************************************************************************/
1330void put_drawn_sprites(struct canvas *pcanvas, float zoom,
1331 int canvas_x, int canvas_y,
1332 int count, struct drawn_sprite *pdrawn,
1333 bool fog)
1334{
1335 int i;
1336
1337 for (i = 0; i < count; i++) {
1338 if (!pdrawn[i].sprite) {
1339 /* This can happen, although it should probably be avoided. */
1340 continue;
1341 }
1342
1343 if (pdrawn[i].w > 0) {
1344 /* TODO: Fog support */
1346 canvas_x / zoom + pdrawn[i].offset_x,
1347 canvas_y / zoom + pdrawn[i].offset_y,
1348 pdrawn[i].w / zoom,
1349 pdrawn[i].h / zoom,
1350 pdrawn[i].sprite);
1351 } else if (fog && pdrawn[i].foggable) {
1353 canvas_x / zoom + pdrawn[i].offset_x,
1354 canvas_y / zoom + pdrawn[i].offset_y,
1355 pdrawn[i].sprite,
1356 TRUE,
1358 } else {
1359 /* We avoid calling canvas_put_sprite_fogged(), even though it
1360 * should be a valid thing to do, because gui-gtk-2.0 doesn't have
1361 * a full implementation. */
1363 canvas_x / zoom + pdrawn[i].offset_x,
1364 canvas_y / zoom + pdrawn[i].offset_y,
1365 pdrawn[i].sprite);
1366 }
1367 }
1368}
1369
1370/************************************************************************/
1374void put_one_element(struct canvas *pcanvas, float zoom,
1375 enum mapview_layer layer,
1376 const struct tile *ptile,
1377 const struct tile_edge *pedge,
1378 const struct tile_corner *pcorner,
1379 const struct unit *punit, const struct city *pcity,
1380 int canvas_x, int canvas_y,
1381 const struct city *citymode,
1382 const struct unit_type *putype)
1383{
1384 struct drawn_sprite tile_sprs[80];
1385 int count = fill_sprite_array(tileset, tile_sprs, layer,
1386 ptile, pedge, pcorner,
1388 bool fog = (ptile && gui_options.draw_fog_of_war
1390
1391 /*** Draw terrain and specials ***/
1392 put_drawn_sprites(pcanvas, zoom, canvas_x, canvas_y, count, tile_sprs, fog);
1393}
1394
1395/************************************************************************/
1399void put_unit(const struct unit *punit, struct canvas *pcanvas, float zoom,
1400 int canvas_x, int canvas_y)
1401{
1403 mapview_layer_iterate(layer) {
1404 put_one_element(pcanvas, zoom, layer, NULL, NULL, NULL,
1407}
1408
1409/************************************************************************/
1413void put_unittype(const struct unit_type *putype, struct canvas *pcanvas, float zoom,
1414 int canvas_x, int canvas_y)
1415{
1417 mapview_layer_iterate(layer) {
1418 put_one_element(pcanvas, zoom, layer, NULL, NULL, NULL,
1421}
1422
1423/************************************************************************/
1428void put_city(struct city *pcity, struct canvas *pcanvas, float zoom,
1429 int canvas_x, int canvas_y)
1430{
1432 mapview_layer_iterate(layer) {
1433 put_one_element(pcanvas, zoom, layer,
1434 NULL, NULL, NULL, NULL, pcity,
1437}
1438
1439/************************************************************************/
1445void put_terrain(struct tile *ptile, struct canvas *pcanvas, float zoom,
1446 int canvas_x, int canvas_y)
1447{
1448 /* Use full tile height, even for terrains. */
1450 mapview_layer_iterate(layer) {
1451 put_one_element(pcanvas, zoom, layer, ptile, NULL, NULL, NULL, NULL,
1454}
1455
1456/************************************************************************/
1464 struct canvas *pcanvas,
1465 int canvas_x, int canvas_y, int *upkeep_cost,
1466 int happy_cost)
1467{
1468 struct sprite *sprite;
1469
1471 if (sprite) {
1473 }
1474
1477 if (sprite) {
1479 }
1481}
1482
1483/*
1484 * pcity->client.color_index is an index into the city_colors array.
1485 * When toggle_city_color is called the city's coloration is toggled. When
1486 * a city is newly colored its color is taken from color_index and
1487 * color_index is moved forward one position. Each color in the array
1488 * tells what color the citymap will be drawn on the mapview.
1489 *
1490 * This array can be added to without breaking anything elsewhere.
1491 */
1492static int color_index = 0;
1493#define NUM_CITY_COLORS tileset_num_city_colors(tileset)
1494
1495
1496/************************************************************************/
1502{
1503 if (pcity->client.colored) {
1505 } else {
1509 }
1510
1512}
1513
1514/************************************************************************/
1520{
1521 if (punit->client.colored) {
1523 } else {
1527 }
1528
1530}
1531
1532/************************************************************************/
1536{
1537 float canvas_x, canvas_y;
1539 int width, height;
1540
1542
1544 struct animation *anim = fc_malloc(sizeof(struct animation));
1545
1546 anim->type = ANIM_NUKE;
1547 anim->id = -1;
1548 anim->nuke.shown = FALSE;
1549 anim->nuke.nuke_tile = ptile;
1550
1553
1554 anim->width = width * map_zoom;
1555 anim->height = height * map_zoom;
1557 } else {
1558 /* We can't count on the return value of tile_to_canvas_pos() since the
1559 * sprite may span multiple tiles. */
1561
1564
1565 /* Make sure everything is flushed and synced before proceeding. First
1566 * we update everything to the store, but don't write this to screen.
1567 * Then add the nuke graphic to the store. Finally flush everything to
1568 * the screen and wait 1 second. */
1570
1573
1574 flush_dirty();
1575 gui_flush();
1576
1577 fc_usleep(1000000);
1578
1580 }
1581}
1582
1583/************************************************************************/
1586static void put_one_tile(struct canvas *pcanvas, enum mapview_layer layer,
1587 struct tile *ptile, int canvas_x, int canvas_y,
1588 const struct city *citymode)
1589{
1591 || (editor_is_active() && editor_tile_is_selected(ptile))) {
1592 struct unit *punit = get_drawable_unit(tileset, ptile, citymode);
1593 struct animation *anim = NULL;
1594
1597 }
1598
1599 if (anim != NULL && punit != NULL
1600 && punit->id == anim->id) {
1601 punit = NULL;
1602 }
1603
1604 put_one_element(pcanvas, map_zoom, layer, ptile, NULL, NULL, punit,
1606 }
1607}
1608
1609/************************************************************************/
1620static int trade_route_to_canvas_lines(const struct tile *ptile1,
1621 const struct tile *ptile2,
1622 struct trade_route_line *lines)
1623{
1624 int dx, dy;
1625
1626 if (!ptile1 || !ptile2 || !lines) {
1627 return 0;
1628 }
1629
1632
1633 /* FIXME: Remove these casts. */
1634 tile_to_canvas_pos(&lines[0].x, &lines[0].y, map_zoom, (struct tile *)ptile1);
1635 tile_to_canvas_pos(&lines[1].x, &lines[1].y, map_zoom, (struct tile *)ptile2);
1636
1637 if (lines[1].x - lines[0].x == lines[0].width
1638 && lines[1].y - lines[0].y == lines[0].height) {
1639 return 1;
1640 }
1641
1642 lines[1].width = -lines[0].width;
1643 lines[1].height = -lines[0].height;
1644 return 2;
1645}
1646
1647/************************************************************************/
1650static void draw_trade_route_line(const struct tile *ptile1,
1651 const struct tile *ptile2,
1652 enum color_std color)
1653{
1655 int line_count, i;
1656 struct color *pcolor;
1657
1658 if (!ptile1 || !ptile2) {
1659 return;
1660 }
1661
1663 if (!pcolor) {
1664 return;
1665 }
1666
1667 /* Order the source and destination tiles consistently
1668 * so that if a line is drawn twice it does not produce
1669 * ugly effects due to dashes not lining up. */
1671 const struct tile *tmp;
1672 tmp = ptile1;
1673 ptile1 = ptile2;
1674 ptile2 = tmp;
1675 }
1676
1678 for (i = 0; i < line_count; i++) {
1679 /* XXX: canvas_put_line doesn't currently take map_zoom into account
1680 * itself, but it probably should? */
1684 lines[i].width, lines[i].height);
1685 }
1686}
1687
1688/************************************************************************/
1692{
1693 if (!pcity_src) {
1694 return;
1695 }
1696
1698 if (pcity_dest != NULL) {
1701 }
1703}
1704
1705/************************************************************************/
1708static void draw_trade_routes(void)
1709{
1711 return;
1712 }
1713
1718 } else {
1719 struct player *pplayer = client_player();
1720
1721 if (!pplayer) {
1722 return;
1723 }
1724
1725 city_list_iterate(pplayer->cities, pcity) {
1728 }
1729}
1730
1731/************************************************************************/
1747{
1748 int gui_x0, gui_y0;
1749 bool full;
1750 struct canvas *tmp;
1751
1752 if (canvas_x < 0) {
1753 width += canvas_x;
1754 canvas_x = 0;
1755 } else if (canvas_x > mapview.store_width) {
1758 }
1759
1760 if (canvas_y < 0) {
1761 height += canvas_y;
1762 canvas_y = 0;
1763 } else if (canvas_y > mapview.store_height) {
1766 }
1767
1768 if (width <= 0 || height <= 0) {
1769 /* Area outside mapview */
1770 return;
1771 }
1772
1773 gui_x0 = mapview.gui_x0 + canvas_x;
1774 gui_y0 = mapview.gui_y0 + canvas_y;
1775 full = (canvas_x == 0 && canvas_y == 0
1778
1779 log_debug("update_map_canvas(pos=(%d,%d), size=(%d,%d))",
1781
1782 /* If a full redraw is done, we just draw everything onto the canvas.
1783 * However if a partial redraw is done we draw everything onto the
1784 * tmp_canvas then copy *just* the area of update onto the canvas. */
1785 if (!full) {
1786 /* Swap store and tmp_store. */
1787 tmp = mapview.store;
1790 }
1791
1792 /* Clear the area. This is necessary since some parts of the rectangle
1793 * may not actually have any tiles drawn on them. This will happen when
1794 * the mapview is large enough so that the tile is visible in multiple
1795 * locations. In this case it will only be drawn in one place.
1796 *
1797 * Of course it's necessary to draw to the whole area to cover up any old
1798 * drawing that was done there. */
1802
1803 mapview_layer_iterate(layer) {
1804 if (layer == LAYER_TILELABEL) {
1806 }
1807 if (layer == LAYER_CITYBAR) {
1809 continue;
1810 }
1811 gui_rect_iterate_coord(gui_x0, gui_y0, width,
1813 ? (tileset_tile_height(tileset) / 2 * map_zoom) : 0),
1814 ptile, pedge, pcorner, gui_x, gui_y, map_zoom) {
1815 const int cx = gui_x - mapview.gui_x0, cy = gui_y - mapview.gui_y0;
1816
1817 if (ptile) {
1818 put_one_tile(mapview.store, layer, ptile, cx, cy, NULL);
1819 } else if (pedge) {
1821 NULL, NULL, cx, cy, NULL, NULL);
1822 } else if (pcorner) {
1824 NULL, NULL, cx, cy, NULL, NULL);
1825 } else {
1826 /* This can happen, for instance for unreal tiles. */
1827 }
1830
1833
1834 /* Draw the goto lines on top of the whole thing. This is done last as
1835 * we want it completely on top.
1836 *
1837 * Note that a pixel right on the border of a tile may actually contain a
1838 * goto line from an adjacent tile. Thus we draw any extra goto lines
1839 * from adjacent tiles (if they're close enough). */
1840 gui_rect_iterate(gui_x0 - GOTO_WIDTH, gui_y0 - GOTO_WIDTH,
1841 width + 2 * GOTO_WIDTH, height + 2 * GOTO_WIDTH,
1842 ptile, pedge, pcorner, map_zoom) {
1843 if (!ptile) {
1844 continue;
1845 }
1846 adjc_dir_base_iterate(&(wld.map), ptile, dir) {
1847 if (mapdeco_is_gotoline_set(ptile, dir)) {
1848 draw_segment(ptile, dir);
1849 }
1852
1853 if (!full) {
1854 /* Swap store and tmp_store back. */
1855 tmp = mapview.store;
1858
1859 /* And copy store to tmp_store. */
1862 }
1863
1865}
1866
1867/************************************************************************/
1874
1875/* The maximum city description width and height. This gives the dimensions
1876 * of a rectangle centered directly beneath the tile a city is on, that
1877 * contains the city description.
1878 *
1879 * These values are increased when drawing is done. This may mean that
1880 * the change (from increasing the value) won't take place until the
1881 * next redraw. */
1883
1884/* Same for tile labels */
1886
1887/************************************************************************/
1894
1895/************************************************************************/
1898void update_tile_label(struct tile *ptile)
1899{
1901}
1902
1903/************************************************************************/
1908 const int canvas_x0, const int canvas_y0,
1909 struct city *pcity, int *width, int *height)
1910{
1911 const struct citybar_sprites *citybar = get_citybar_sprites(tileset);
1912 static char name[512], growth[32], prod[512], size[32], trade_routes[32];
1915 /* trade_routes_color initialized just to get rid of gcc warning
1916 * on optimization level 3 when it misdiagnoses that it would be used
1917 * uninitialized otherwise. Funny thing here is that warning would
1918 * go away also by *not* setting it to values other than
1919 * COLOR_MAPVIEW_CITYTEXT in get_city_mapview_trade_routes() */
1921 struct color *owner_color;
1922 struct area_rect
1923 name_rect = {0, 0, 0, 0}, growth_rect = {0, 0, 0, 0},
1924 prod_rect = {0, 0, 0, 0}, size_rect = {0, 0, 0, 0},
1925 flag_rect = {0, 0, 0, 0}, occupy_rect = {0, 0, 0, 0},
1926 food_rect = {0, 0, 0, 0}, shield_rect = {0, 0, 0, 0},
1927 trade_routes_rect = {0,}, trade_rect = {0,};
1928 int width1 = 0, width2 = 0, height1 = 0, height2 = 0;
1929 struct sprite *bg = citybar->background;
1930 struct sprite *flag = get_city_flag_sprite(tileset, pcity);
1931 struct sprite *occupy = NULL;
1932 int bg_w, bg_h, x, y;
1935 const int border = 6;
1936 const enum client_font FONT_CITY_SIZE = FONT_CITY_NAME; /* TODO: new font */
1937
1938 /* We can see the city's production or growth values if
1939 * we are observing or playing as the owner of the city. */
1940 const bool can_see_inside
1942 const bool should_draw_productions
1947 const bool should_draw_lower_bar
1950
1951
1952 *width = 0;
1953 *height = 0;
1954
1956 return;
1957 }
1958
1959
1960 /* First: calculate rect dimensions (but not positioning). */
1961
1963 bg_w *= map_zoom;
1964 bg_h *= map_zoom;
1966 growth, sizeof(growth),
1968
1970 fc_snprintf(size, sizeof(size), "%d", city_size_get(pcity));
1971
1974
1976 int count = unit_list_size(pcity->tile->units);
1977
1978 count = CLIP(0, count, citybar->occupancy.size - 1);
1979 occupy = citybar->occupancy.p[count];
1980 } else {
1981 if (pcity->client.occupied) {
1982 occupy = citybar->occupied;
1983 } else {
1984 occupy = citybar->occupancy.p[0];
1985 }
1986 }
1987
1992
1994 + 2 * border + size_rect.w);
1995 height1 = MAX(flag_rect.h,
1996 MAX(occupy_rect.h,
1997 MAX(name_rect.h + border,
1998 size_rect.h + border)));
1999 }
2000
2002 width2 = 0;
2003 height2 = 0;
2004
2006 get_city_mapview_production(pcity, prod, sizeof(prod));
2008
2014 }
2015
2016 if (should_draw_growth) {
2023 }
2024
2027 sizeof(trade_routes),
2036 }
2037 }
2038
2039 *width = MAX(width1, width2);
2040 *height = height1 + height2;
2041
2042 /* Next fill in X and Y locations. */
2043
2045 flag_rect.x = canvas_x - *width / 2;
2046 flag_rect.y = canvas_y + (height1 - flag_rect.h) / 2;
2047
2049 occupy_rect.y = canvas_y + (height1 - occupy_rect.h) / 2;
2050
2052 - name_rect.w - size_rect.w - border) / 2;
2053 name_rect.y = canvas_y + (height1 - name_rect.h) / 2;
2054
2055 size_rect.x = canvas_x + (*width + 1) / 2 - size_rect.w - border / 2;
2056 size_rect.y = canvas_y + (height1 - size_rect.h) / 2;
2057 }
2058
2061 shield_rect.x = canvas_x - *width / 2;
2063
2064 prod_rect.x = shield_rect.x + shield_rect.w + border / 2;
2065 prod_rect.y = canvas_y + height1 + (height2 - prod_rect.h) / 2;
2066 }
2067
2069 trade_routes_rect.x = canvas_x + (*width + 1) / 2
2070 - trade_routes_rect.w - border / 2;
2072 + (height2 - trade_routes_rect.h) / 2;
2073
2075 trade_rect.y = canvas_y + height1 + (height2 - trade_rect.h) / 2;
2076 }
2077
2078 if (should_draw_growth) {
2079 growth_rect.x = canvas_x + (*width + 1) / 2
2080 - growth_rect.w - border / 2;
2081 if (trade_routes_rect.w > 0) {
2083 - trade_routes_rect.w - border / 2 - trade_rect.w - border / 2;
2084 }
2086
2087 food_rect.x = growth_rect.x - border / 2 - food_rect.w;
2088 food_rect.y = canvas_y + height1 + (height2 - food_rect.h) / 2;
2089 }
2090 }
2091
2092
2093 /* Now draw. */
2094
2095 /* Draw the city bar's background. */
2096 for (x = 0; x < *width; x += bg_w) {
2097 for (y = 0; y < *height; y += bg_h) {
2099 (canvas_y + y) / map_zoom,
2100 bg, 0, 0,
2101 (*width - x) / map_zoom, (*height - y) / map_zoom);
2102 }
2103 }
2104
2106
2111 flag);
2112 /* XXX: canvas_put_line() doesn't currently take map_zoom into account.
2113 * Should it?
2114 * In the meantime, don't compensate with '/ map_zoom' here, unlike
2115 * for canvas_put_sprite/text/rectangle */
2117 (flag_rect.x + flag_rect.w) /* / map_zoom */ - 1,
2118 canvas_y /* / map_zoom */,
2119 0, height1 /* / map_zoom */);
2122 occupy);
2127 (size_rect.x - border / 2) / map_zoom,
2129 (size_rect.w + border) / map_zoom,
2130 height1 / map_zoom);
2131 {
2132 /* Try to pick a color for city size text that contrasts with
2133 * player color */
2134 struct color *textcolors[2] = {
2137 };
2138
2143 }
2144 }
2145
2147
2151 citybar->shields);
2155 }
2156
2160 citybar->trade);
2165 }
2166
2167 if (should_draw_growth) {
2170 citybar->food);
2174 }
2175 }
2176
2177 /* Draw the city bar's outline. */
2178 /* XXX not scaling by map_zoom, see above */
2180 (canvas_x - *width / 2) /* / map_zoom */,
2181 canvas_y /* / map_zoom */,
2182 *width /* / map_zoom */, 0);
2184 (canvas_x - *width / 2) /* / map_zoom */,
2185 canvas_y /* / map_zoom */,
2186 0, *height /* / map_zoom */);
2188 (canvas_x - *width / 2) /* / map_zoom */,
2189 (canvas_y + *height) /* / map_zoom */ - 1,
2190 *width /* / map_zoom */, 0);
2192 (canvas_x - *width / 2 + *width) /* / map_zoom */,
2193 canvas_y /* / map_zoom */,
2194 0, *height /* / map_zoom */);
2195
2196 /* Draw the dividing line if we drew both the
2197 * upper and lower parts. */
2200 (canvas_x - *width / 2) /* / map_zoom */,
2201 (canvas_y + height1) /* / map_zoom */ - 1,
2202 *width /* / map_zoom */, 0);
2203 }
2204}
2205
2206/************************************************************************/
2212 int canvas_x, int canvas_y,
2213 struct city *pcity, int *width, int *height)
2214{
2215 static char name[512], growth[32], prod[512], trade_routes[32];
2218 /* trade_routes_color initialized just to get rid off gcc warning
2219 * on optimization level 3 when it misdiagnoses that it would be used
2220 * uninitialized otherwise. Funny thing here is that warning would
2221 * go away also by *not* setting it to values other than
2222 * COLOR_MAPVIEW_CITYTEXT in get_city_mapview_trade_routes() */
2224 struct {
2225 int x, y, w, h;
2226 } name_rect = {0, 0, 0, 0}, growth_rect = {0, 0, 0, 0},
2227 prod_rect = {0, 0, 0, 0}, trade_routes_rect = {0,};
2229 int spacer_width = 0;
2231 || city_owner(pcity) == client_player());
2232
2233 *width = *height = 0;
2234
2237
2239 growth, sizeof(growth), &growth_color,
2241
2243 int drawposx;
2244
2245 /* HACK: put a character's worth of space between the two
2246 * strings if needed. */
2248
2249 total_width = 0;
2250 total_height = 0;
2251
2255
2260 }
2261
2264 sizeof(trade_routes),
2270 }
2271
2273 drawposx -= total_width / 2;
2277 drawposx += name_rect.w;
2278
2285 drawposx += growth_rect.w;
2286 }
2287
2294 }
2295
2296 canvas_y += total_height + 3;
2297
2298 *width = MAX(*width, total_width);
2299 *height += total_height + 3;
2300 }
2301
2303 get_city_mapview_production(pcity, prod, sizeof(prod));
2305
2308
2313
2314 *width = MAX(*width, total_width);
2315 *height += total_height;
2316 }
2317}
2318
2319/************************************************************************/
2331static void show_city_desc(struct canvas *pcanvas,
2332 int canvas_x, int canvas_y,
2333 struct city *pcity, int *width, int *height)
2334{
2337 } else {
2339 }
2340}
2341
2342/************************************************************************/
2352static void show_tile_label(struct canvas *pcanvas,
2353 int canvas_x, int canvas_y,
2354 struct tile *ptile, int *width, int *height)
2355{
2356 const enum client_font FONT_TILE_LABEL = FONT_CITY_NAME; /* TODO: new font */
2357#define COLOR_MAPVIEW_TILELABEL COLOR_MAPVIEW_CITYTEXT
2358
2361
2363
2367#undef COLOR_MAPVIEW_TILELABEL
2368}
2369
2370/************************************************************************/
2374 int width_base, int height_base)
2375{
2377 const int dy = max_desc_height;
2380
2384 return;
2385 }
2386
2389 return;
2390 }
2391
2392 /* A city description is shown below the city. It has a specified
2393 * maximum width and height (although these are only estimates). Thus
2394 * we need to update some tiles above the mapview and some to the left
2395 * and right.
2396 *
2397 * /--W1--\ (W1 = tileset_tile_width(tileset))
2398 * -------- \
2399 * | CITY | H1 (H1 = tileset_tile_height(tileset))
2400 * | | /
2401 * ------------------ \
2402 * | DESCRIPTION | H2 (H2 = MAX_CITY_DESC_HEIGHT)
2403 * | | /
2404 * ------------------
2405 * \-------W2-------/ (W2 = MAX_CITY_DESC_WIDTH)
2406 *
2407 * We must draw H2 extra pixels above and (W2 - W1) / 2 extra pixels
2408 * to each side of the mapview.
2409 */
2412 width_base + dx, height_base + dy - offset_y,
2413 ptile, pedge, pcorner, gui_x, gui_y, map_zoom) {
2414 const int canvas_x = gui_x - mapview.gui_x0;
2415 const int canvas_y = gui_y - mapview.gui_y0;
2416
2417 if (ptile && tile_city(ptile)) {
2418 int width = 0, height = 0;
2419 struct city *pcity = tile_city(ptile);
2420
2422 pcity, &width, &height);
2423 log_debug("Drawing %s.", city_name_get(pcity));
2424
2426 /* The update was incomplete! We queue a new update. Note that
2427 * this is recursively queueing an update within a dequeuing of an
2428 * update. This is allowed specifically because of the code in
2429 * unqueue_mapview_updates. See that function for more. */
2430 log_debug("Re-queuing %s.", city_name_get(pcity));
2432 }
2435 }
2437
2438 /* We don't update the new max values until the end, so that the
2439 * check above to see what cities need redrawing will be complete. */
2442}
2443
2444/************************************************************************/
2448 int width_base, int height_base)
2449{
2451 const int dy = max_label_height;
2453
2456 width_base + dx, height_base + dy,
2457 ptile, pedge, pcorner, gui_x, gui_y, map_zoom) {
2458 const int canvas_x = gui_x - mapview.gui_x0;
2459 const int canvas_y = gui_y - mapview.gui_y0;
2460
2461 if (ptile && ptile->label != NULL) {
2462 int width = 0, height = 0;
2463
2465 ptile, &width, &height);
2466 log_debug("Drawing label %s.", ptile->label);
2467
2469 /* The update was incomplete! We queue a new update. Note that
2470 * this is recursively queueing an update within a dequeuing of an
2471 * update. This is allowed specifically because of the code in
2472 * unqueue_mapview_updates(). See that function for more. */
2473 log_debug("Re-queuing tile label %s drawing.", ptile->label);
2474 update_tile_label(ptile);
2475 }
2478 }
2480
2481 /* We don't update the new max values until the end, so that the
2482 * check above to see what cities need redrawing will be complete. */
2485}
2486
2487/************************************************************************/
2491void draw_segment(struct tile *src_tile, enum direction8 dir)
2492{
2493 float canvas_x, canvas_y, canvas_dx, canvas_dy;
2494
2495 /* Determine the source position of the segment. */
2499
2500 /* Determine the vector of the segment. */
2501 map_to_gui_vector(tileset, map_zoom, &canvas_dx, &canvas_dy,
2502 DIR_DX[dir], DIR_DY[dir]);
2503
2504 /* Draw the segment. */
2505 /* XXX: canvas_put_line doesn't currently take map_zoom into account
2506 * itself, but it probably should? If so this will need adjusting */
2509 canvas_x, canvas_y, canvas_dx, canvas_dy);
2510
2511 /* The actual area drawn will extend beyond the base rectangle, since
2512 * the goto lines have width. */
2513 dirty_rect(MIN(canvas_x, canvas_x + canvas_dx) - GOTO_WIDTH,
2514 MIN(canvas_y, canvas_y + canvas_dy) - GOTO_WIDTH,
2515 ABS(canvas_dx) + 2 * GOTO_WIDTH,
2516 ABS(canvas_dy) + 2 * GOTO_WIDTH);
2517
2518 /* It is possible that the mapview wraps between the source and dest
2519 * tiles. In this case they will not be next to each other; they'll be
2520 * on the opposite sides of the screen. If this happens then the dest
2521 * tile will not be updated. This is consistent with the mapview design
2522 * which fails when the size of the mapview approaches that of the map. */
2523}
2524
2525/************************************************************************/
2530 struct unit *punit1, int hp1)
2531{
2532 struct unit *losing_unit = (hp0 == 0 ? punit0 : punit1);
2533 float canvas_x, canvas_y;
2534 int i;
2535
2537
2538 /* Make sure we don't start out with fewer HP than we're supposed to
2539 * end up with (which would cause the following loop to break). */
2540 punit0->hp = MAX(punit0->hp, hp0);
2541 punit1->hp = MAX(punit1->hp, hp1);
2542
2544
2546 struct animation *anim = fc_malloc(sizeof(struct animation));
2547 struct unit *winning_unit;
2548 int winner_end_hp;
2549 int loser_end_hp;
2552
2553 if (losing_unit == punit1) {
2556 loser_end_hp = hp1;
2557 } else {
2560 loser_end_hp = hp0;
2561 }
2562
2563 anim->type = ANIM_BATTLE;
2564 anim->id = -1;
2565 anim->battle.virt_loser = unit_virtual_create(unit_owner(losing_unit),
2568 anim->battle.loser_tile = unit_tile(losing_unit);
2569 anim->battle.virt_loser->facing = losing_unit->facing;
2570 anim->battle.loser_hp_start = losing_unit->hp;
2571 anim->battle.loser_hp_end = loser_end_hp;
2572 anim->battle.virt_winner = unit_virtual_create(unit_owner(winning_unit),
2575 anim->battle.winner_tile = unit_tile(winning_unit);
2576 anim->battle.virt_winner->facing = winning_unit->facing;
2577 anim->battle.winner_hp_start = MAX(winning_unit->hp, winner_end_hp);
2578 anim->battle.winner_hp_end = winner_end_hp;
2579 anim->battle.steps = MAX(losing_unit->hp,
2580 anim->battle.winner_hp_start - winner_end_hp);
2581 anim->width = aw;
2582 anim->height = ah;
2584
2585 if (loser_end_hp <= 0) {
2586 anim = fc_malloc(sizeof(struct animation));
2587 anim->type = ANIM_EXPL;
2588 anim->id = winning_unit->id;
2589 anim->expl.tile = losing_unit->tile;
2591 anim->expl.sprite_count = sprite_vector_size(anim->expl.sprites);
2592 anim->width = aw;
2593 anim->height = ah;
2595 }
2596 } else {
2599
2600 while (punit0->hp > hp0 || punit1->hp > hp1) {
2601 const int diff0 = punit0->hp - hp0, diff1 = punit1->hp - hp1;
2602
2604
2605 if (fc_rand(diff0 + diff1) < diff0) {
2606 punit0->hp--;
2608 } else {
2609 punit1->hp--;
2611 }
2612
2614 gui_flush();
2615
2618 }
2619
2629
2630 for (i = 0; i < num_tiles_explode_unit; i++) {
2631 int w, h;
2632 struct sprite *sprite = *sprite_vector_get(anim, i);
2633
2636
2637 /* We first draw the explosion onto the unit and draw draw the
2638 * complete thing onto the map canvas window. This avoids
2639 * flickering. */
2646 - w / 2,
2648 - h / 2,
2649 sprite);
2652
2653 flush_dirty();
2654 gui_flush();
2655
2658 }
2659 }
2660 }
2661
2665}
2666
2667/************************************************************************/
2672 struct tile *src_tile, int dx, int dy)
2673{
2674 struct tile *dest_tile;
2675 int dest_x, dest_y, src_x, src_y;
2676 int prev_x = -1;
2677 int prev_y = -1;
2678 int tuw;
2679 int tuh;
2680
2681 /* Only works for adjacent-square moves */
2682 if (dx < -1 || dx > 1 || dy < -1 || dy > 1 || (dx == 0 && dy == 0)) {
2683 return;
2684 }
2685
2686 index_to_map_pos(&src_x, &src_y, tile_index(src_tile));
2687 dest_x = src_x + dx;
2688 dest_y = src_y + dy;
2689 dest_tile = map_pos_to_tile(&(wld.map), dest_x, dest_y);
2690 if (!dest_tile) {
2691 return;
2692 }
2693
2694 if (tile_visible_mapcanvas(src_tile)
2695 || tile_visible_mapcanvas(dest_tile)) {
2696 float start_x, start_y;
2697 float canvas_dx, canvas_dy;
2699 double mytime;
2700
2702
2703 map_to_gui_vector(tileset, map_zoom, &canvas_dx, &canvas_dy, dx, dy);
2704
2705 tile_to_canvas_pos(&start_x, &start_y, map_zoom, src_tile);
2709 }
2710
2711 /* Bring the backing store up to date, but don't flush. */
2713
2716
2718 struct animation *anim = fc_malloc(sizeof(struct animation));
2719
2720 anim->type = ANIM_MOVEMENT;
2721 anim->id = punit->id;
2722 anim->movement.mover = unit_virtual_create(unit_owner(punit),
2724 punit->veteran);
2725 anim->movement.mover->hp = punit->hp;
2726 anim->movement.mover->facing = punit->facing;
2727 anim->movement.src = src_tile;
2728 anim->movement.dest = dest_tile;
2729 anim->movement.canvas_dx = canvas_dx;
2730 anim->movement.canvas_dy = canvas_dy;
2731 anim->width = tuw;
2732 anim->height = tuh;
2734 } else {
2735
2736 /* Start the timer (AFTER the unqueue above). */
2738
2739 do {
2740 int new_x, new_y;
2742
2744
2745 new_x = start_x + canvas_dx * (mytime / timing_sec);
2747
2748 if (new_x != prev_x || new_y != prev_y) {
2749 /* Backup the canvas store to the temp store. */
2752 tuw, tuh);
2753
2754 /* Draw */
2757
2758 /* Flush. */
2759 flush_dirty();
2760 gui_flush();
2761
2762 /* Restore the backup. It won't take effect until the next flush. */
2765 tuw, tuh);
2767
2768 prev_x = new_x;
2769 prev_y = new_y;
2770 } else {
2771 fc_usleep(500);
2772 }
2773 } while (mytime < timing_sec);
2774 }
2775 }
2776}
2777
2778/************************************************************************/
2790struct city *find_city_or_settler_near_tile(const struct tile *ptile,
2791 struct unit **punit)
2792{
2793 struct city *closest_city;
2794 struct city *pcity;
2797
2798 if (punit) {
2799 *punit = NULL;
2800 }
2801
2802 /* Check if there is visible city working that tile */
2803 pcity = tile_worked(ptile);
2804 if (pcity && pcity->tile) {
2805 if (NULL == client.conn.playing
2807 /* Rule a */
2808 return pcity;
2809 } else {
2810 /* Rule b */
2811 return NULL;
2812 }
2813 }
2814
2815 /* Rule e */
2817
2818 /* Check within maximum (squared) city radius */
2819 city_tile_iterate(&(wld.map), max_rad, ptile, tile1) {
2821 if (pcity
2822 && (NULL == client.conn.playing
2825 /*
2826 * Note, we must explicitly check if the tile is workable (with
2827 * city_can_work_tile() above), since it is possible that another
2828 * city (perhaps an UNSEEN city) may be working it!
2829 */
2830
2832 /* Rule c */
2833 return pcity;
2834 }
2835 if (!closest_city) {
2837 }
2838 }
2840
2841 /* Rule d */
2842 if (closest_city || !punit) {
2843 return closest_city;
2844 }
2845
2847 /* Check within maximum (squared) city radius */
2848 city_tile_iterate(&(wld.map), max_rad, ptile, tile1) {
2850 if ((NULL == client.conn.playing
2854 psettler, FALSE)) {
2855 if (closest_settler == NULL) {
2857 }
2858 if (best_settler == NULL && psettler->client.colored) {
2860 }
2861 }
2864
2865 if (best_settler != NULL) {
2866 /* Rule e */
2868 } else if (closest_settler != NULL) {
2869 /* Rule f */
2871 }
2872 }
2873
2874 /* Rule g */
2875 return NULL;
2876}
2877
2878/************************************************************************/
2881struct city *find_city_near_tile(const struct tile *ptile)
2882{
2883 return find_city_or_settler_near_tile(ptile, NULL);
2884}
2885
2886/************************************************************************/
2892static void append_city_buycost_string(const struct city *pcity,
2893 char *buffer, int buffer_len)
2894{
2895 if (!pcity || !buffer || buffer_len < 1) {
2896 return;
2897 }
2898
2900 return;
2901 }
2902
2903 cat_snprintf(buffer, buffer_len, "/%d", pcity->client.buy_cost);
2904}
2905
2906/************************************************************************/
2911 char *buffer, size_t buffer_len)
2912{
2913 int turns;
2914
2915 universal_name_translation(&pcity->production, buffer, buffer_len);
2916
2918 return;
2919 }
2921
2922 if (999 < turns) {
2923 cat_snprintf(buffer, buffer_len, " -");
2924 } else {
2925 cat_snprintf(buffer, buffer_len, " %d", turns);
2926 }
2927
2929}
2930
2931/************************************************************************/
2937 char *trade_routes_buffer,
2939 enum color_std *pcolor)
2940{
2941 int num_trade_routes;
2942 int max_routes;
2943
2945 return;
2946 }
2947
2948 if (!pcity) {
2949 trade_routes_buffer[0] = '\0';
2950 if (pcolor) {
2952 }
2953 return;
2954 }
2955
2958
2960 "%d/%d", num_trade_routes, max_routes);
2961
2962 if (pcolor) {
2965 } else if (num_trade_routes == 0) {
2967 } else {
2969 }
2970 }
2971}
2972
2973/***************************************************************************/
2976
2977/* These values hold the tiles that need city, unit, or tile updates.
2978 * These different types of updates just tell what area need to be updated,
2979 * not necessarily what's sitting on the tile. A city update covers the
2980 * whole citymap area. A unit update covers just the "full" unit tile
2981 * area. A tile update covers the base tile plus half a tile in each
2982 * direction. */
2984
2985/************************************************************************/
2989static void queue_callback(void *data)
2990{
2993}
2994
2995/************************************************************************/
2999static void queue_add_callback(void)
3000{
3001 if (!callback_queued) {
3004 }
3005}
3006
3007/************************************************************************/
3025{
3026 if (can_client_change_view()) {
3027 needed_updates |= update;
3029 }
3030}
3031
3032/************************************************************************/
3041{
3042 if (can_client_change_view()) {
3043 if (!tile_updates[type]) {
3045 }
3048 }
3049}
3050
3051/************************************************************************/
3055{
3056 /* Calculate the area covered by each update type. The area array gives
3057 * the offset from the tile origin as well as the width and height of the
3058 * area to be updated. This is initialized each time when entering the
3059 * function from the existing tileset variables.
3060 *
3061 * A TILE update covers the base tile (W x H) plus a half-tile in each
3062 * direction (for edge/corner graphics), making its area 2W x 2H.
3063 *
3064 * A UNIT update covers a UW x UH area. This is centered horizontally
3065 * over the tile but extends up above the tile (e.g., units in iso-view).
3066 *
3067 * A CITYMAP update covers the whole citymap of a tile. This includes
3068 * the citymap area itself plus an extra half-tile in each direction (for
3069 * edge/corner graphics).
3070 */
3071 const float W = tileset_tile_width(tileset) * map_zoom;
3072 const float H = tileset_tile_height(tileset) * map_zoom;
3073 const float UW = tileset_unit_width(tileset) * map_zoom;
3074 const float UH = tileset_unit_height(tileset) * map_zoom;
3075 const float city_width = get_citydlg_canvas_width() * map_zoom + W;
3076 const float city_height = get_citydlg_canvas_height() * map_zoom + H;
3077 const struct {
3078 float dx, dy, w, h;
3079 } area[TILE_UPDATE_COUNT] = {
3080 {0, 0, W, H},
3081 {-W / 2, -H / 2, 2 * W, 2 * H},
3082 {(W - UW) / 2, H - UH, UW, UH},
3084 {-(city_width - W) / 2, -(city_height - H) / 2, city_width, city_height},
3086 };
3088
3089 int i;
3090
3091 if (!can_client_change_view()) {
3092 /* Double sanity check: make sure we don't unqueue an invalid update
3093 * after we've already detached. */
3094 return;
3095 }
3096
3097 log_debug("unqueue_mapview_update: needed_updates=%d",
3099
3100 /* This code "pops" the lists of tile updates off of the static array and
3101 * stores them locally. This allows further updates to be queued within
3102 * the function itself (namely, within update_map_canvas() ). */
3103 for (i = 0; i < TILE_UPDATE_COUNT; i++) {
3105 tile_updates[i] = NULL;
3106 }
3107
3108 if (!map_is_empty()) {
3112 dirty_all();
3115 /* Have to update the overview too, since some tiles may have changed. */
3117 } else {
3119 int max_x = 0, max_y = 0;
3120
3121 for (i = 0; i < TILE_UPDATE_COUNT; i++) {
3122 if (my_tile_updates[i]) {
3124 float xl, yt;
3125 int xr, yb;
3126
3127 (void) tile_to_canvas_pos(&xl, &yt, map_zoom, ptile);
3128
3129 xl += area[i].dx;
3130 yt += area[i].dy;
3131 xr = xl + area[i].w;
3132 yb = yt + area[i].h;
3133
3134 if (xr > 0 && xl < mapview.width
3135 && yb > 0 && yt < mapview.height) {
3136 min_x = MIN(min_x, xl);
3137 min_y = MIN(min_y, yt);
3138 max_x = MAX(max_x, xr);
3139 max_y = MAX(max_y, yb);
3140 }
3141
3142 /* FIXME: These overview updates should be batched as well.
3143 * Right now they account for as much as 90% of the runtime of
3144 * the unqueue. */
3145 overview_update_tile(ptile);
3147 }
3148 }
3149
3150 if (min_x < max_x && min_y < max_y) {
3152 }
3153 }
3154 }
3155
3156 for (i = 0; i < TILE_UPDATE_COUNT; i++) {
3157 if (my_tile_updates[i]) {
3159 }
3160 }
3162
3163 if (write_to_screen) {
3164 flush_dirty();
3166 }
3167}
3168
3169/************************************************************************/
3174 char *name_buffer,
3175 size_t name_buffer_len,
3176 char *growth_buffer,
3177 size_t growth_buffer_len,
3178 enum color_std *growth_color,
3180{
3182
3184 if (NULL == client.conn.playing
3186 int turns = city_turns_to_grow(pcity);
3187
3188 if (turns == 0) {
3190 } else if (turns == FC_INFINITY) {
3192 } else {
3193 /* Negative turns means we're shrinking, but that's handled
3194 down below. */
3196 }
3197
3198 if (turns <= 0) {
3199 /* A blocked or shrinking city has its growth status shown in red. */
3201 } else {
3203 }
3204
3205 if (pcity->surplus[O_SHIELD] < 0) {
3207 }
3208 } else {
3209 growth_buffer[0] = '\0';
3211 }
3212}
3213
3214/************************************************************************/
3218static bool can_do_cached_drawing(void)
3219{
3220 const int W = tileset_tile_width(tileset) * map_zoom;
3221 const int H = tileset_tile_height(tileset) * map_zoom;
3223
3224 /* If the mapview window is too large, cached drawing is not possible.
3225 *
3226 * BACKGROUND: cached drawing occurs when the mapview is scrolled just
3227 * a short distance. The majority of the mapview window can simply be
3228 * copied while the newly visible areas must be drawn from scratch. This
3229 * speeds up drawing significantly, especially when using the scrollbars
3230 * or mapview sliding.
3231 *
3232 * When the mapview is larger than the map, however, some tiles may become
3233 * visible twice. In this case one instance of the tile will be drawn
3234 * while all others are drawn black. When this happens the cached drawing
3235 * system breaks since it assumes the mapview canvas is an "ideal" window
3236 * over the map. So black tiles may be scrolled from the edges of the
3237 * mapview into the center, while drawn tiles may be scrolled from the
3238 * center of the mapview out to the edges. The result is very bad.
3239 *
3240 * There are a few different ways this could be solved. One way is simply
3241 * to turn off cached drawing, which is what we do now. If the mapview
3242 * window gets to be too large, the caching is disabled. Another would
3243 * be to prevent the window from getting too large in the first place -
3244 * but because the window boundaries aren't at an even tile this would
3245 * mean the entire map could never be shown. Yet another way would be
3246 * to draw tiles more than once if they are visible in multiple locations
3247 * on the mapview.
3248 *
3249 * The logic below is complicated and determined in part by
3250 * trial-and-error. */
3252 /* An unwrapping map: no limitation. On an unwrapping map no tile can
3253 * be visible twice so there's no problem. */
3254 return TRUE;
3255 }
3258 /* Non-matching. In this case the mapview does not line up with the
3259 * map's axis of wrapping. This will give very bad results for the
3260 * player!
3261 * We can never show more than half of the map.
3262 *
3263 * We divide by 4 below because we have to divide by 2 twice. The
3264 * first division by 2 is because the square must be half the size
3265 * of the (width+height). The second division by two is because for
3266 * an iso-map, MAP_NATURAL_XXX has a scale of 2, whereas for iso-view
3267 * NORMAL_TILE_XXX has a scale of 2. */
3268 return (w <= (MAP_NATURAL_WIDTH + MAP_NATURAL_HEIGHT) * W / 4
3269 && h <= (MAP_NATURAL_WIDTH + MAP_NATURAL_HEIGHT) * H / 4);
3270 } else {
3271 /* Matching. */
3272 const int isofactor = (tileset_is_isometric(tileset) ? 2 : 1);
3273 const int isodiff = (tileset_is_isometric(tileset) ? 6 : 2);
3274
3275 /* Now we can use the full width and height, with the exception of a small
3276 * area on each side. */
3278 && w > (MAP_NATURAL_WIDTH - isodiff) * W / isofactor) {
3279 return FALSE;
3280 }
3282 && h > (MAP_NATURAL_HEIGHT - isodiff) * H / isofactor) {
3283 return FALSE;
3284 }
3285
3286 return TRUE;
3287 }
3288}
3289
3290/************************************************************************/
3295{
3296 /* HACK: this must be called on a map_info packet. */
3298
3299 mapdeco_free();
3303}
3304
3305/************************************************************************/
3323
3324/************************************************************************/
3328void mapdeco_set_highlight(const struct tile *ptile, bool highlight)
3329{
3330 bool changed = FALSE;
3331
3332 if (!ptile || !mapdeco_highlight_table) {
3333 return;
3334 }
3335
3336 if (highlight) {
3338 } else {
3339 changed = tile_hash_remove(mapdeco_highlight_table, ptile);
3340 }
3341
3342 if (changed) {
3343 /* FIXME: Remove the cast. */
3344 refresh_tile_mapcanvas((struct tile *) ptile, TRUE, FALSE);
3345 }
3346}
3347
3348/************************************************************************/
3351bool mapdeco_is_highlight_set(const struct tile *ptile)
3352{
3353 if (!ptile || !mapdeco_highlight_table) {
3354 return FALSE;
3355 }
3357}
3358
3359/************************************************************************/
3375
3376/************************************************************************/
3379void mapdeco_set_crosshair(const struct tile *ptile, bool crosshair)
3380{
3381 bool changed;
3382
3383 if (!mapdeco_crosshair_table || !ptile) {
3384 return;
3385 }
3386
3387 if (crosshair) {
3389 } else {
3390 changed = tile_hash_remove(mapdeco_crosshair_table, ptile);
3391 }
3392
3393 if (changed) {
3394 /* FIXME: Remove the cast. */
3395 refresh_tile_mapcanvas((struct tile *) ptile, FALSE, FALSE);
3396 }
3397}
3398
3399/************************************************************************/
3402bool mapdeco_is_crosshair_set(const struct tile *ptile)
3403{
3404 if (!mapdeco_crosshair_table || !ptile) {
3405 return FALSE;
3406 }
3408}
3409
3410/************************************************************************/
3426
3427/************************************************************************/
3432void mapdeco_add_gotoline(const struct tile *ptile, enum direction8 dir)
3433{
3434 struct gotoline_counter *pglc;
3435 const struct tile *ptile_dest;
3436 bool changed;
3437
3438 if (!mapdeco_gotoline_table || !ptile
3439 || !(dir <= direction8_max())) {
3440 return;
3441 }
3442 ptile_dest = mapstep(&(wld.map), ptile, dir);
3443 if (!ptile_dest) {
3444 return;
3445 }
3446
3450 }
3451 changed = (pglc->line_count[dir] < 1);
3452 pglc->line_count[dir]++;
3453
3454 if (changed) {
3455 /* FIXME: Remove cast. */
3456 refresh_tile_mapcanvas((struct tile *) ptile, FALSE, FALSE);
3458 }
3459}
3460
3461/************************************************************************/
3466void mapdeco_remove_gotoline(const struct tile *ptile,
3467 enum direction8 dir)
3468{
3469 struct gotoline_counter *pglc;
3470 bool changed = FALSE;
3471
3472 if (!mapdeco_gotoline_table || !ptile
3473 || !(dir <= direction8_max())) {
3474 return;
3475 }
3476
3478 return;
3479 }
3480
3481 pglc->line_count[dir]--;
3482 if (pglc->line_count[dir] <= 0) {
3483 pglc->line_count[dir] = 0;
3484 changed = TRUE;
3485 }
3486
3487 if (changed) {
3488 /* FIXME: Remove the casts. */
3489 refresh_tile_mapcanvas((struct tile *) ptile, FALSE, FALSE);
3490 ptile = mapstep(&(wld.map), ptile, dir);
3491 if (ptile != NULL) {
3492 refresh_tile_mapcanvas((struct tile *) ptile, FALSE, FALSE);
3493 }
3494 }
3495}
3496
3497/************************************************************************/
3503{
3504 const struct unit_order *porder;
3505 const struct tile *ptile;
3506 int i, ind;
3507
3509 || punit->orders.length < 1) {
3510 return;
3511 }
3512
3513 ptile = unit_tile(punit);
3514
3515 for (i = 0; ptile != NULL && i < punit->orders.length; i++) {
3516 if (punit->orders.index + i >= punit->orders.length
3517 && !punit->orders.repeat) {
3518 break;
3519 }
3520
3522 porder = &punit->orders.list[ind];
3523 if (porder->order != ORDER_MOVE) {
3524 /* FIXME: should display some indication of non-move orders here. */
3525 continue;
3526 }
3527
3528 mapdeco_add_gotoline(ptile, porder->dir);
3529 ptile = mapstep(&(wld.map), ptile, porder->dir);
3530 }
3531}
3532
3533/************************************************************************/
3537bool mapdeco_is_gotoline_set(const struct tile *ptile,
3538 enum direction8 dir)
3539{
3540 struct gotoline_counter *pglc;
3541
3542 if (!ptile || !(dir <= direction8_max())
3544 return FALSE;
3545 }
3546
3548 return FALSE;
3549 }
3550
3551 return pglc->line_count[dir] > 0;
3552}
3553
3554/************************************************************************/
3559{
3561 return;
3562 }
3563
3566 adjc_dir_iterate(&(wld.map), ptile, ptile_dest, dir) {
3567 if (pglc->line_count[dir] > 0) {
3569 }
3573}
3574
3575/************************************************************************/
3581{
3585 int tile_width = (width + tileset_tile_width(tileset) * map_zoom - 1) /
3587 int tile_height = (height + tileset_tile_height(tileset) * map_zoom - 1) /
3589 int full_width = tile_width * tileset_tile_width(tileset) * map_zoom;
3590 int full_height = tile_height * tileset_tile_height(tileset) * map_zoom;
3592
3593 /* Resized */
3594
3595 /* Since a resize is only triggered when the tile_*** changes, the canvas
3596 * width and height must include the entire backing store - otherwise
3597 * small resizings may lead to undrawn tiles. */
3598 mapview.tile_width = tile_width;
3599 mapview.tile_height = tile_height;
3604
3605 /* Check for what's changed. */
3606 tile_size_changed = (tile_width != old_tile_width
3607 || tile_height != old_tile_height);
3609
3610 /* If the tile size has changed, resize the canvas. */
3611 if (tile_size_changed) {
3612 if (mapview.store) {
3615 }
3622
3626 }
3627
3629 if (tile_size_changed) {
3630 if (center_tile != NULL) {
3631 int x_left, y_top;
3632 float gui_x, gui_y;
3633
3636
3637 /* Put the center pixel of the tile at the exact center of the mapview. */
3640
3644 }
3647
3648 /* Do not draw to the screen here as that could cause problems
3649 * when we are only initially setting up the view and some widgets
3650 * are not yet ready. */
3652 redrawn = TRUE;
3653 }
3654
3655 /* If the width/height has changed, update the scrollbars even if
3656 * the backing store is not resized. */
3657 if (size_changed) {
3660 }
3661 }
3662
3664
3665 return redrawn;
3666}
3667
3668/************************************************************************/
3672{
3673 /* Create a dummy map to make sure mapview.store is never NULL. */
3674 map_canvas_resized(1, 1);
3675}
3676
3677/************************************************************************/
3685
3686/************************************************************************/
3690{
3691 struct sprite *sprite
3693
3695 *width *= 7;
3696 *height *= 7;
3697}
3698
3699/************************************************************************/
3703 const struct player *pplayer)
3704{
3705 int i, x, y;
3706 const struct player_spaceship *ship = &pplayer->spaceship;
3707 int w, h;
3708 struct sprite *spr;
3709 struct tileset *t = tileset;
3710
3712 get_sprite_dimensions(spr, &w, &h);
3713
3716 0, 0, w * 7, h * 7);
3717
3718 for (i = 0; i < NUM_SS_MODULES; i++) {
3719 const int j = i / 3;
3720 const int k = i % 3;
3721
3722 if ((k == 0 && j >= ship->habitation)
3723 || (k == 1 && j >= ship->life_support)
3724 || (k == 2 && j >= ship->solar_panels)) {
3725 continue;
3726 }
3727 x = modules_info[i].x * w / 4 - w / 2;
3728 y = modules_info[i].y * h / 4 - h / 2;
3729
3734 }
3735
3736 for (i = 0; i < NUM_SS_COMPONENTS; i++) {
3737 const int j = i / 2;
3738 const int k = i % 2;
3739
3740 if ((k == 0 && j >= ship->fuel)
3741 || (k == 1 && j >= ship->propulsion)) {
3742 continue;
3743 }
3744 x = components_info[i].x * w / 4 - w / 2;
3745 y = components_info[i].y * h / 4 - h / 2;
3746
3747 spr = ((k == 0) ? get_spaceship_sprite(t, SPACESHIP_FUEL)
3749
3751
3752 if (k && ship->state == SSHIP_LAUNCHED) {
3755 }
3756 }
3757
3758 for (i = 0; i < NUM_SS_STRUCTURALS; i++) {
3759 if (!BV_ISSET(ship->structure, i)) {
3760 continue;
3761 }
3762 x = structurals_info[i].x * w / 4 - w / 2;
3763 y = structurals_info[i].y * h / 4 - h / 2;
3764
3767 }
3768}
3769
3770/****************************************************************************
3771 Map link mark module: it makes link marks when a link is sent by chating,
3772 or restore a mark with clicking a link on the chatline.
3773****************************************************************************/
3775 enum text_link_type type; /* The target type. */
3776 int id; /* The city or unit id, or tile index. */
3777 int turn_counter; /* The turn counter before it disappears. */
3778};
3779
3780#define SPECLIST_TAG link_mark
3781#define SPECLIST_TYPE struct link_mark
3782#include "speclist.h"
3783#define link_marks_iterate(pmark) \
3784 TYPED_LIST_ITERATE(struct link_mark, link_marks, pmark)
3785#define link_marks_iterate_end LIST_ITERATE_END
3786
3788
3789/************************************************************************/
3792static struct link_mark *link_mark_find(enum text_link_type type, int id)
3793{
3795 if (pmark->type == type && pmark->id == id) {
3796 return pmark;
3797 }
3799
3800 return NULL;
3801}
3802
3803/************************************************************************/
3807 int id, int turns)
3808{
3809 struct link_mark *pmark = fc_malloc(sizeof(struct link_mark));
3810
3811 pmark->type = type;
3812 pmark->id = id;
3813 pmark->turn_counter = turns;
3814
3815 return pmark;
3816}
3817
3818/************************************************************************/
3822{
3823 free(pmark);
3824}
3825
3826/************************************************************************/
3829static struct tile *link_mark_tile(const struct link_mark *pmark)
3830{
3831 switch (pmark->type) {
3832 case TLT_CITY:
3833 {
3834 struct city *pcity = game_city_by_number(pmark->id);
3835 return pcity ? pcity->tile : NULL;
3836 }
3837 case TLT_TILE:
3838 return index_to_tile(&(wld.map), pmark->id);
3839 case TLT_UNIT:
3840 {
3841 struct unit *punit = game_unit_by_number(pmark->id);
3842 return punit ? unit_tile(punit) : NULL;
3843 }
3844 }
3845
3846 return NULL;
3847}
3848
3849/************************************************************************/
3852static struct color *link_mark_color(const struct link_mark *pmark)
3853{
3854 switch (pmark->type) {
3855 case TLT_CITY:
3857 case TLT_TILE:
3859 case TLT_UNIT:
3861 }
3862
3863 return NULL;
3864}
3865
3866/************************************************************************/
3869static void link_mark_draw(const struct link_mark *pmark)
3870{
3873 int xd = width / 20, yd = height / 20;
3874 int xlen = width / 3, ylen = height / 3;
3875 float canvas_x, canvas_y;
3877 struct tile *ptile = link_mark_tile(pmark);
3878 struct color *pcolor = link_mark_color(pmark);
3879
3880 if (!ptile || !tile_to_canvas_pos(&canvas_x, &canvas_y, map_zoom, ptile)) {
3881 return;
3882 }
3883
3884 x_left = canvas_x + xd;
3885 x_right = canvas_x + width - xd;
3886 y_top = canvas_y + yd;
3887 y_bottom = canvas_y + height - yd;
3888
3889 /* XXX: canvas_put_line() doesn't currently take map_zoom into account
3890 * itself, but it probably should? If so these will need adjusting */
3892 xlen, 0);
3894 0, ylen);
3895
3897 -xlen, 0);
3899 0, ylen);
3900
3902 xlen, 0);
3904 0, -ylen);
3905
3907 -xlen, 0);
3909 0, -ylen);
3910}
3911
3912/************************************************************************/
3916{
3917 if (link_marks) {
3919 }
3920
3922}
3923
3924/************************************************************************/
3928{
3929 if (!link_marks) {
3930 return;
3931 }
3932
3934 link_marks = NULL;
3935}
3936
3937/************************************************************************/
3946
3947/************************************************************************/
3955
3956/************************************************************************/
3960{
3962 if (--pmark->turn_counter <= 0) {
3964 }
3966
3967 /* update_map_canvas_visible(); not needed here. */
3968}
3969
3970/************************************************************************/
3974{
3975 struct link_mark *pmark = link_mark_find(type, id);
3976 struct tile *ptile;
3977
3978 if (pmark) {
3979 /* Already displayed, but maybe increase the turn counter. */
3980 pmark->turn_counter = MAX(pmark->turn_counter, 2);
3981 return;
3982 }
3983
3984 pmark = link_mark_new(type, id, 2);
3986 ptile = link_mark_tile(pmark);
3987 if (ptile && tile_visible_mapcanvas(ptile)) {
3989 }
3990}
3991
3992/************************************************************************/
3996{
3997 struct link_mark *pmark;
3998 struct tile *ptile;
3999
4000 if (link_mark_find(type, id)) {
4001 return;
4002 }
4003
4004 pmark = link_mark_new(type, id, 1);
4006 ptile = link_mark_tile(pmark);
4007 if (ptile && tile_visible_mapcanvas(ptile)) {
4009 }
4010}
4011
4012/************************************************************************/
4016 struct tileset *tset,
4017 int *tset_topo)
4018{
4019 int tileset_topology;
4020
4021 if (tileset_hex_width(tset) > 0) {
4024 } else if (tileset_hex_height(tset) > 0) {
4027 } else if (tileset_is_isometric(tset)) {
4029 } else {
4030 tileset_topology = 0;
4031 }
4032
4033 if (tset_topo != NULL) {
4035 }
4036
4037 if (tileset_topology & TF_HEX) {
4038 if ((topology_id & (TF_HEX | TF_ISO)) == tileset_topology) {
4039 return TOPO_COMPATIBLE;
4040 }
4041
4042 /* Hex topology must match for both hexness and iso/non-iso */
4043 return TOPO_INCOMP_HARD;
4044 }
4045
4046 if (topology_id & TF_HEX) {
4047 return TOPO_INCOMP_HARD;
4048 }
4049
4050 if ((topology_id & TF_ISO) != (tileset_topology & TF_ISO)) {
4051 /* Non-hex iso/non-iso incompatibility is a soft one */
4052 return TOPO_INCOMP_SOFT;
4053 }
4054
4055 return TOPO_COMPATIBLE;
4056}
4057
4058/************************************************************************/
4061const char *describe_topology(int topo)
4062{
4063 if (topo & TF_ISO) {
4064 if (topo & TF_HEX) {
4065 return _("ISO|Hex");
4066 }
4067 return _("ISO");
4068 }
4069 if (topo & TF_HEX) {
4070 return _("Hex");
4071 }
4072
4073 return _("Overhead");
4074}
4075
4076/************************************************************************/
4083
4084/************************************************************************/
4088{
4089 return infratile;
4090}
4091
4092/************************************************************************/
4095void client_infratile_set(struct tile *ptile)
4096{
4097 struct tile *old_tile = infratile;
4098
4099 infratile = ptile;
4100
4101 if (old_tile != NULL) {
4103 }
4104 if (ptile != NULL) {
4106 }
4107}
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int int int struct sprite *sprite struct canvas struct color * pcolor
Definition canvas_g.h:56
struct canvas int int int int struct sprite *sprite canvas_put_rectangle
Definition canvas_g.h:55
struct canvas int int canvas_y
Definition canvas_g.h:43
struct canvas int canvas_x
Definition canvas_g.h:43
struct canvas int int int int struct sprite *sprite struct canvas struct color int int int int height canvas_put_line
Definition canvas_g.h:62
canvas_put_sprite
Definition canvas_g.h:42
struct canvas * pcanvas
Definition canvas_g.h:42
canvas_put_text
Definition canvas_g.h:80
struct canvas int int struct sprite int int offset_y
Definition canvas_g.h:44
struct canvas int int struct sprite int offset_x
Definition canvas_g.h:44
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
@ LINE_GOTO
Definition canvas_g.h:26
@ LINE_TILE_FRAME
Definition canvas_g.h:26
@ LINE_BORDER
Definition canvas_g.h:26
@ LINE_NORMAL
Definition canvas_g.h:26
const char * city_name_getx(const struct city *pcity)
Definition city.c:1150
const char * city_name_get(const struct city *pcity)
Definition city.c:1141
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Definition city.c:824
bool city_can_be_built_here(const struct civ_map *nmap, const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1528
int rs_max_city_radius_sq(void)
Definition city.c:159
bool city_production_is_genus(const struct city *pcity, enum impr_genus_id genus)
Definition city.c:720
int city_turns_to_grow(const struct city *pcity)
Definition city.c:2037
#define cities_iterate_end
Definition city.h:517
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:565
#define cities_iterate(pcity)
Definition city.h:512
static citizens city_size_get(const struct city *pcity)
Definition city.h:570
#define output_type_iterate(output)
Definition city.h:847
#define city_owner(_pcity_)
Definition city.h:564
#define city_list_iterate_end
Definition city.h:510
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:228
#define city_tile_iterate_end
Definition city.h:236
#define output_type_iterate_end
Definition city.h:853
int get_citydlg_canvas_width(void)
bool city_can_buy(const struct city *pcity)
int get_citydlg_canvas_height(void)
bool client_is_global_observer(void)
struct civclient client
bool can_client_change_view(void)
#define client_player()
enum known_type client_tile_get_known(const struct tile *ptile)
Definition climap.c:36
bool client_city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition climap.c:133
struct color * color_best_contrast(struct color *subject, struct color **candidates, int ncandidates)
struct color * get_player_color(const struct tileset *t, const struct player *pplayer)
struct color * get_color(const struct tileset *t, enum color_std stdcolor)
char * incite_cost
Definition comments.c:77
void set_units_in_combat(struct unit *pattacker, struct unit *pdefender)
Definition control.c:1044
enum cursor_hover_state hover_state
Definition control.c:89
@ HOVER_GOTO
Definition control.h:27
@ HOVER_PARADROP
Definition control.h:29
@ HOVER_TELEPORT
Definition control.h:28
@ HOVER_ACT_SEL_TGT
Definition control.h:32
@ HOVER_NONE
Definition control.h:26
@ HOVER_CONNECT
Definition control.h:30
@ HOVER_PATROL
Definition control.h:31
@ HOVER_GOTO_SEL_TGT
Definition control.h:33
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
int int id
Definition editgui_g.h:28
bool editor_is_active(void)
Definition editor.c:346
bool editor_tile_is_selected(const struct tile *ptile)
Definition editor.c:1117
#define DIR8_MAGIC_MAX
Definition fc_types.h:330
@ O_SHIELD
Definition fc_types.h:103
#define _(String)
Definition fcintl.h:67
text_link_type
@ TLT_TILE
@ TLT_UNIT
@ TLT_CITY
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct unit * game_unit_by_number(int id)
Definition game.c:115
struct city * game_city_by_number(int id)
Definition game.c:106
void canvas_put_sprite_full(struct canvas *pcanvas, int canvas_x, int canvas_y, struct sprite *sprite)
Definition canvas.c:144
void canvas_set_zoom(struct canvas *store, float zoom)
Definition canvas.c:53
void canvas_mapview_init(struct canvas *store)
Definition canvas.c:69
void get_text_size(int *width, int *height, enum client_font font, const char *text)
Definition canvas.c:341
void canvas_free(struct canvas *store)
Definition canvas.c:44
void canvas_copy(struct canvas *dest, struct canvas *src, int src_x, int src_y, int dest_x, int dest_y, int width, int height)
Definition canvas.c:76
struct canvas * canvas_create(int width, int height)
Definition canvas.c:28
void canvas_put_sprite_fogged(struct canvas *pcanvas, int canvas_x, int canvas_y, struct sprite *psprite, bool fog, int fog_x, int fog_y)
Definition canvas.c:170
void add_idle_callback(void(callback)(void *), void *data)
Definition gui_main.c:2405
void create_line_at_mouse_pos(void)
Definition mapctrl.c:355
void update_rect_at_mouse_pos(void)
Definition mapctrl.c:380
void flush_dirty(void)
Definition mapview.c:468
void dirty_all(void)
Definition mapview.c:456
void update_map_canvas_scrollbars_size(void)
Definition mapview.c:696
void gui_flush(void)
Definition mapview.c:480
void update_map_canvas_scrollbars(void)
Definition mapview.c:681
GType type
Definition repodlgs.c:1313
const char * name
Definition inputfile.c:127
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
#define log_debug(message,...)
Definition log.h:116
const int DIR_DY[8]
Definition map.c:86
#define nat_x
#define nat_y
const int DIR_DX[8]
Definition map.c:85
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:471
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:434
void base_map_distance_vector(int *dx, int *dy, int x0dv, int y0dv, int x1dv, int y1dv)
Definition map.c:1171
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Definition map.c:384
struct tile * nearest_real_tile(const struct civ_map *nmap, int x, int y)
Definition map.c:1142
bool map_is_empty(void)
Definition map.c:148
bool normalize_map_pos(const struct civ_map *nmap, int *x, int *y)
Definition map.c:1126
#define current_topo_has_flag(flag)
Definition map.h:43
#define adjc_dir_iterate(nmap, center_tile, itr_tile, dir_itr)
Definition map.h:444
#define MAP_TO_NATIVE_POS(pnat_x, pnat_y, map_x, map_y)
Definition map.h:176
#define NATIVE_TO_MAP_POS(pmap_x, pmap_y, nat_x, nat_y)
Definition map.h:170
#define adjc_dir_iterate_end
Definition map.h:448
#define current_wrap_has_flag(flag)
Definition map.h:46
#define adjc_dir_base_iterate(nmap, center_tile, dir_itr)
Definition map.h:451
#define adjc_dir_base_iterate_end
Definition map.h:455
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:229
bool rectangle_active
void mapdeco_set_highlight(const struct tile *ptile, bool highlight)
void link_mark_restore(enum text_link_type type, int id)
void put_nuke_mushroom_pixmaps(struct tile *ptile)
void init_mapcanvas_and_overview(void)
static struct gotoline_counter * gotoline_counter_new(void)
struct city * find_city_or_settler_near_tile(const struct tile *ptile, struct unit **punit)
void put_drawn_sprites(struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y, int count, struct drawn_sprite *pdrawn, bool fog)
void update_map_canvas_visible(void)
static void anim_timer_renew(void)
bool tile_visible_mapcanvas(struct tile *ptile)
void set_mapview_origin(float gui_x0, float gui_y0, float zoom)
void put_terrain(struct tile *ptile, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
static const int MAX_TRADE_ROUTE_DRAW_LINES
void map_to_gui_vector(const struct tileset *t, float zoom, float *gui_dx, float *gui_dy, int map_dx, int map_dy)
void update_tile_label(struct tile *ptile)
tile_update_type
@ TILE_UPDATE_COUNT
@ TILE_UPDATE_TILE_SINGLE
@ TILE_UPDATE_TILE_LABEL
@ TILE_UPDATE_UNIT
@ TILE_UPDATE_CITY_DESC
@ TILE_UPDATE_CITYMAP
@ TILE_UPDATE_TILE_FULL
#define COLOR_MAPVIEW_TILELABEL
#define gotoline_hash_iterate(hash, ptile, pglc)
void mapdeco_set_crosshair(const struct tile *ptile, bool crosshair)
enum topo_comp_lvl tileset_map_topo_compatible(int topology_id, struct tileset *tset, int *tset_topo)
static int color_index
static int max_desc_width
static void link_mark_draw(const struct link_mark *pmark)
static void base_set_mapview_origin(float gui_x0, float gui_y0, float zoom)
static void queue_callback(void *data)
struct view mapview
void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile, bool full_refresh, bool write_to_screen)
static void draw_trade_routes(void)
static void draw_trade_routes_for_city(const struct city *pcity_src)
void put_city(struct city *pcity, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
struct tile * get_center_tile_mapcanvas(void)
static struct link_mark * link_mark_new(enum text_link_type type, int id, int turns)
struct tile * canvas_pos_to_tile(float canvas_x, float canvas_y, float zoom)
update_type
@ UPDATE_TILE_LABELS
@ UPDATE_NONE
@ UPDATE_CITY_DESCRIPTIONS
@ UPDATE_MAP_CANVAS_VISIBLE
void put_unit(const struct unit *punit, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
struct city * find_city_near_tile(const struct tile *ptile)
void mapdeco_free(void)
void free_mapcanvas_and_overview(void)
struct gotoline_hash * mapdeco_gotoline_table
static bool movement_animation(struct animation *anim, double time_gone)
void get_mapview_scroll_pos(int *scroll_x, int *scroll_y)
bool mapdeco_is_highlight_set(const struct tile *ptile)
static void put_one_tile(struct canvas *pcanvas, enum mapview_layer layer, struct tile *ptile, int canvas_x, int canvas_y, const struct city *citymode)
void get_mapview_scroll_window(float *xmin, float *ymin, float *xmax, float *ymax, int *xsize, int *ysize)
static void show_small_citybar(struct canvas *pcanvas, int canvas_x, int canvas_y, struct city *pcity, int *width, int *height)
static bool frame_by_frame_animation
void move_unit_map_canvas(struct unit *punit, struct tile *src_tile, int dx, int dy)
animation_type
@ ANIM_NUKE
@ ANIM_MOVEMENT
@ ANIM_BATTLE
@ ANIM_EXPL
static void link_mark_destroy(struct link_mark *pmark)
void mapdeco_set_gotoroute(const struct unit *punit)
void unqueue_mapview_updates(bool write_to_screen)
void get_mapview_scroll_step(int *xstep, int *ystep)
void draw_segment(struct tile *src_tile, enum direction8 dir)
void show_city_descriptions(int canvas_base_x, int canvas_base_y, int width_base, int height_base)
void set_mapview_scroll_pos(int scroll_x, int scroll_y, float zoom)
static void gui_distance_vector(const struct tileset *t, float zoom, float *gui_dx, float *gui_dy, float gui_x0, float gui_y0, float gui_x1, float gui_y1)
void mapdeco_init(void)
void client_infratile_set(struct tile *ptile)
static void queue_add_callback(void)
static void static void show_city_desc(struct canvas *pcanvas, int canvas_x, int canvas_y, struct city *pcity, int *width, int *height) fc__attribute((nonnull(5
void get_city_mapview_trade_routes(struct city *pcity, char *trade_routes_buffer, size_t trade_routes_buffer_len, enum color_std *pcolor)
#define NUM_CITY_COLORS
void put_unittype(const struct unit_type *putype, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
void mapdeco_clear_gotoroutes(void)
static enum update_type needed_updates
void put_unit_city_overlays(struct unit *punit, struct canvas *pcanvas, int canvas_x, int canvas_y, int *upkeep_cost, int happy_cost)
void put_one_element(struct canvas *pcanvas, float zoom, enum mapview_layer layer, const struct tile *ptile, const struct tile_edge *pedge, const struct tile_corner *pcorner, const struct unit *punit, const struct city *pcity, int canvas_x, int canvas_y, const struct city *citymode, const struct unit_type *putype)
bool mapdeco_is_gotoline_set(const struct tile *ptile, enum direction8 dir)
#define link_marks_iterate(pmark)
struct tile * infratile
static bool nuke_animation(struct animation *anim, double time_gone)
void center_tile_mapcanvas(const struct tile *ptile)
void animations_init(void)
static int max_label_height
static bool battle_animation(struct animation *anim, double time_gone)
void update_animation(void)
void toggle_city_color(struct city *pcity)
struct tile * canvas_pos_to_nearest_tile(float canvas_x, float canvas_y, float zoom)
void mapdeco_add_gotoline(const struct tile *ptile, enum direction8 dir)
void update_map_canvas(int canvas_x, int canvas_y, int width, int height)
static struct color * link_mark_color(const struct link_mark *pmark)
const struct tile * center_tile
void link_marks_decrease_turn_counters(void)
static void normalize_gui_pos(const struct tileset *t, float zoom, float *gui_x, float *gui_y)
#define link_marks_iterate_end
void mapdeco_clear_crosshairs(void)
void get_city_mapview_production(struct city *pcity, char *buffer, size_t buffer_len)
static void base_canvas_to_map_pos(float zoom, int *map_x, int *map_y, float canvas_x, float canvas_y)
void link_marks_draw_all(void)
void update_city_description(struct city *pcity)
void link_marks_init(void)
struct tile * client_infratile(void)
void set_frame_by_frame_animation(void)
void mapdeco_clear_highlights(void)
void link_marks_clear_all(void)
const char * describe_topology(int topo)
static int trade_route_to_canvas_lines(const struct tile *ptile1, const struct tile *ptile2, struct trade_route_line *lines)
static void queue_mapview_update(enum update_type update)
static int max_label_width
struct animation_list * animations
void toggle_unit_color(struct unit *punit)
static struct link_mark * link_mark_find(enum text_link_type type, int id)
void animations_free(void)
struct tile_hash * mapdeco_highlight_table
static struct timer * anim_timer
static void queue_mapview_tile_update(struct tile *ptile, enum tile_update_type type)
static bool callback_queued
static void show_full_citybar(struct canvas *pcanvas, const int canvas_x0, const int canvas_y0, struct city *pcity, int *width, int *height) fc__attribute((nonnull(5
static void map_to_gui_pos(const struct tileset *t, float zoom, float *gui_x, float *gui_y, int map_x, int map_y)
static int max_desc_height
bool map_canvas_resized(int width, int height)
void link_mark_add_new(enum text_link_type type, int id)
bool can_slide
void refresh_tile_mapcanvas(struct tile *ptile, bool full_refresh, bool write_to_screen)
static void draw_trade_route_line(const struct tile *ptile1, const struct tile *ptile2, enum color_std color)
void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile, bool full_refresh, bool write_to_screen)
static bool explosion_animation(struct animation *anim, double time_gone)
struct tile_list * tile_updates[TILE_UPDATE_COUNT]
bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, float zoom, const struct tile *ptile)
static struct link_mark_list * link_marks
void get_spaceship_dimensions(int *width, int *height)
void decrease_unit_hp_smooth(struct unit *punit0, int hp0, struct unit *punit1, int hp1)
static void show_tile_label(struct canvas *pcanvas, int canvas_x, int canvas_y, struct tile *ptile, int *width, int *height)
static void animation_add(struct animation *anim)
void get_city_mapview_name_and_growth(struct city *pcity, char *name_buffer, size_t name_buffer_len, char *growth_buffer, size_t growth_buffer_len, enum color_std *growth_color, enum color_std *production_color)
bool tile_visible_and_not_on_border_mapcanvas(struct tile *ptile)
struct tile_hash * mapdeco_crosshair_table
void put_spaceship(struct canvas *pcanvas, int canvas_x, int canvas_y, const struct player *pplayer)
static struct tile * link_mark_tile(const struct link_mark *pmark)
static void append_city_buycost_string(const struct city *pcity, char *buffer, int buffer_len)
void mapdeco_remove_gotoline(const struct tile *ptile, enum direction8 dir)
#define gotoline_hash_iterate_end
static bool can_do_cached_drawing(void)
bool mapdeco_is_crosshair_set(const struct tile *ptile)
void link_marks_free(void)
void show_tile_labels(int canvas_base_x, int canvas_base_y, int width_base, int height_base)
static bool calc_mapview_origin(float *gui_x0, float *gui_y0, float zoom)
static void gotoline_counter_destroy(struct gotoline_counter *pglc)
static void gui_to_map_pos(const struct tileset *t, float zoom, int *map_x, int *map_y, float gui_x, float gui_y)
#define gui_rect_iterate_coord(GRI_x0, GRI_y0, GRI_width, GRI_height, _t, _e, _c, _x, _y, _zoom)
#define gui_rect_iterate_coord_end
#define gui_rect_iterate_end
#define GOTO_WIDTH
topo_comp_lvl
@ TOPO_COMPATIBLE
@ TOPO_INCOMP_HARD
@ TOPO_INCOMP_SOFT
#define gui_rect_iterate(GRI_x0, GRI_y0, GRI_width, GRI_height, _t, _e, _c, _zoom)
dirty_rect
Definition mapview_g.h:47
#define H(x, y, z)
Definition md5.c:92
#define fc_calloc(n, esz)
Definition mem.h:38
#define fc_malloc(sz)
Definition mem.h:34
struct client_options gui_options
Definition options.c:71
void flush_dirty_overview(void)
void refresh_overview_canvas(void)
void center_tile_overviewcanvas(void)
void overview_update_tile(struct tile *ptile)
char * lines
Definition packhand.c:132
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:1124
#define fc_rand(_size)
Definition rand.h:56
const char * universal_name_translation(const struct universal *psource, char *buf, size_t bufsz)
#define CLIP(lower, current, upper)
Definition shared.h:57
#define DIVIDE(n, d)
Definition shared.h:78
#define ARRAY_SIZE(x)
Definition shared.h:85
#define FC_WRAP(value, range)
Definition shared.h:65
#define MIN(x, y)
Definition shared.h:55
#define FC_INFINITY
Definition shared.h:36
#define ABS(x)
Definition shared.h:61
#define MAX(x, y)
Definition shared.h:54
#define XOR(p, q)
Definition shared.h:71
const struct sship_part_info structurals_info[NUM_SS_STRUCTURALS]
Definition spaceship.c:23
const struct sship_part_info modules_info[NUM_SS_MODULES]
Definition spaceship.c:77
const struct sship_part_info components_info[NUM_SS_COMPONENTS]
Definition spaceship.c:58
#define NUM_SS_MODULES
Definition spaceship.h:89
#define NUM_SS_COMPONENTS
Definition spaceship.h:88
#define NUM_SS_STRUCTURALS
Definition spaceship.h:87
@ SSHIP_LAUNCHED
Definition spaceship.h:85
int step
Definition specpq.h:92
size_t size
Definition specvec.h:72
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
struct sprite int int int int struct sprite int int float bool smooth get_sprite_dimensions
Definition sprite_g.h:36
struct sprite ** sprites
Definition tilespec.c:172
const struct sprite_vector * sprites
struct tile * loser_tile
struct tile * dest
struct unit * virt_loser
struct tile * winner_tile
struct tile * nuke_tile
struct tile * tile
struct tile * src
struct animation::@228::@230 movement
struct unit * mover
struct animation::@228::@232 expl
enum animation_type type
struct animation::@228::@233 nuke
struct unit * virt_winner
struct animation::@228::@231 battle
float zoom
Definition canvas.h:25
Definition city.h:318
struct sprite * food
Definition tilespec.h:335
struct sprite * trade
Definition tilespec.h:336
struct sprite * shields
Definition tilespec.h:333
struct sprite * background
Definition tilespec.h:338
struct sprite * occupied
Definition tilespec.h:337
struct sprite_vector occupancy
Definition tilespec.h:339
struct packet_scenario_info scenario
Definition game.h:87
struct connection conn
Definition client_main.h:96
bool draw_native
Definition options.h:216
int smooth_center_slide_msec
Definition options.h:153
bool draw_city_names
Definition options.h:197
bool draw_city_productions
Definition options.h:199
int smooth_move_unit_msec
Definition options.h:152
bool draw_borders
Definition options.h:215
bool draw_city_buycost
Definition options.h:200
bool draw_fog_of_war
Definition options.h:214
bool draw_city_trade_routes
Definition options.h:201
bool draw_map_grid
Definition options.h:196
bool draw_city_growth
Definition options.h:198
int smooth_combat_step_msec
Definition options.h:154
bool draw_full_citybar
Definition options.h:217
Definition colors.h:21
struct player * playing
Definition connection.h:151
int line_count[DIR8_MAGIC_MAX]
struct city_list * cities
Definition player.h:281
struct player_spaceship spaceship
Definition player.h:286
Definition tile.h:50
char * label
Definition tile.h:66
struct unit_list * units
Definition tile.h:58
Definition timing.c:81
struct veteran_system * veteran
Definition unittype.h:551
Definition unit.h:140
int length
Definition unit.h:198
bool occupied
Definition unit.h:222
int id
Definition unit.h:147
struct unit::@83 orders
int index
Definition unit.h:198
int hp
Definition unit.h:153
bool colored
Definition unit.h:225
enum direction8 facing
Definition unit.h:144
struct tile * tile
Definition unit.h:142
struct unit::@84::@86 client
struct unit_order * list
Definition unit.h:201
bool repeat
Definition unit.h:199
int color_index
Definition unit.h:226
int veteran
Definition unit.h:154
int height
int store_width
float gui_x0
int tile_height
bool can_do_cached_drawing
int store_height
struct canvas * store
struct canvas * tmp_store
float gui_y0
int width
int tile_width
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:777
void fc_usleep(unsigned long usec)
Definition support.c:639
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:986
#define fc__attribute(x)
Definition support.h:99
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
void canvas_put_flag_sprite(struct canvas *pcanvas, int canvas_x, int canvas_y, int canvas_w, int canvas_h, struct sprite *flag)
Definition svgflag.c:137
void get_flag_dimensions(struct sprite *flag, struct area_rect *rect, int svg_height)
Definition svgflag.c:123
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:89
#define tile_hash_iterate(hash, ptile)
Definition tile.h:83
#define tile_worked(_tile)
Definition tile.h:119
@ TILE_KNOWN_UNSEEN
Definition tile.h:37
@ TILE_UNKNOWN
Definition tile.h:36
#define tile_list_iterate(tile_list, ptile)
Definition tile.h:74
#define tile_hash_iterate_end
Definition tile.h:85
#define TILE_XY(ptile)
Definition tile.h:43
#define tile_list_iterate_end
Definition tile.h:76
struct sprite * get_nuke_explode_sprite(const struct tileset *t)
Definition tilespec.c:7187
int tileset_hex_width(const struct tileset *t)
Definition tilespec.c:747
int tileset_unit_width(const struct tileset *t)
Definition tilespec.c:823
struct unit * get_drawable_unit(const struct tileset *t, struct tile *ptile, const struct city *citymode)
Definition tilespec.c:6792
int tileset_unit_height(const struct tileset *t)
Definition tilespec.c:831
int tileset_svg_flag_height(struct tileset *t)
Definition tilespec.c:7833
struct sprite * get_city_flag_sprite(const struct tileset *t, const struct city *pcity)
Definition tilespec.c:4658
int tileset_full_tile_height(const struct tileset *t)
Definition tilespec.c:815
struct sprite * get_unit_upkeep_sprite(const struct tileset *t, Output_type_id otype, const struct unit *punit, const int *upkeep_cost)
Definition tilespec.c:7293
int tileset_citybar_offset_y(const struct tileset *t)
Definition tilespec.c:936
bool unit_drawn_with_city_outline(const struct unit *punit, bool check_focus)
Definition tilespec.c:5718
const struct sprite_vector * get_unit_explode_animation(const struct tileset *t)
Definition tilespec.c:7176
bool tileset_is_isometric(const struct tileset *t)
Definition tilespec.c:738
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:791
struct sprite * get_spaceship_sprite(const struct tileset *t, enum spaceship_part part)
Definition tilespec.c:6941
int tileset_hex_height(const struct tileset *t)
Definition tilespec.c:756
const struct citybar_sprites * get_citybar_sprites(const struct tileset *t)
Definition tilespec.c:7195
struct sprite * get_unit_unhappy_sprite(const struct tileset *t, const struct unit *punit, int happy_cost)
Definition tilespec.c:7274
int fill_sprite_array(struct tileset *t, struct drawn_sprite *sprs, enum mapview_layer layer, const struct tile *ptile, const struct tile_edge *pedge, const struct tile_corner *pcorner, const struct unit *punit, const struct city *pcity, const struct city *citymode, const struct unit_type *putype)
Definition tilespec.c:6020
int tileset_tile_width(const struct tileset *t)
Definition tilespec.c:779
int tileset_tilelabel_offset_y(const struct tileset *t)
Definition tilespec.c:945
#define mapview_layer_iterate(layer)
Definition tilespec.h:178
#define mapview_layer_iterate_end
Definition tilespec.h:186
@ SPACESHIP_STRUCTURAL
Definition tilespec.h:325
@ SPACESHIP_HABITATION
Definition tilespec.h:324
@ SPACESHIP_EXHAUST
Definition tilespec.h:328
@ SPACESHIP_FUEL
Definition tilespec.h:326
@ SPACESHIP_PROPULSION
Definition tilespec.h:327
@ SPACESHIP_SOLAR_PANEL
Definition tilespec.h:322
@ SPACESHIP_LIFE_SUPPORT
Definition tilespec.h:323
void timer_usleep_since_start(struct timer *t, long usec)
Definition timing.c:398
void timer_start(struct timer *t)
Definition timing.c:263
double timer_read_seconds(struct timer *t)
Definition timing.c:379
struct timer * timer_renew(struct timer *t, enum timer_timetype type, enum timer_use use, const char *name)
Definition timing.c:180
@ TIMER_ACTIVE
Definition timing.h:46
@ TIMER_USER
Definition timing.h:42
unsigned max_trade_routes(const struct city *pcity)
Definition traderoutes.c:48
#define trade_partners_iterate_end
#define trade_partners_iterate(c, p)
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:402
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1682
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1786
bool unit_has_orders(const struct unit *punit)
Definition unit.c:221
#define unit_tile(_pu)
Definition unit.h:408
@ ORDER_MOVE
Definition unit.h:40
#define unit_owner(_pu)
Definition unit.h:407
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:126
#define MAP_NATIVE_WIDTH
#define MAP_IS_ISOMETRIC
#define MAP_NATURAL_HEIGHT
#define MAP_NATURAL_WIDTH
#define MAP_NATIVE_HEIGHT
float mouse_zoom
Definition zoom.c:28
float map_zoom
Definition zoom.c:25
#define zoom_is_enabled()
Definition zoom.h:26