Freeciv-3.2
Loading...
Searching...
No Matches
overview_common.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996-2005 - Freeciv Development Team
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#include <math.h> /* floor */
19
20/* utility */
21#include "log.h"
22
23/* client */
24#include "client_main.h" /* can_client_change_view() */
25#include "climap.h"
26#include "control.h"
27#include "mapview_g.h"
28#include "options.h"
29#include "zoom.h"
30
31#include "overview_common.h"
32
34#if 0
35struct overview overview = {
36 /* These are the default values. All others are zeroed automatically. */
37 .fog = TRUE,
38 .layers = {[OLAYER_BACKGROUND] = TRUE,
42};
43#endif
44
45/*
46 * Set to TRUE if the backing store is more recent than the version
47 * drawn into overview.window.
48 */
49static bool overview_dirty = FALSE;
50
51/************************************************************************/
56static void gui_to_natural_pos(const struct tileset *t,
57 double *ntl_x, double *ntl_y,
58 int gui_x, int gui_y)
59{
60 const double gui_xd = gui_x, gui_yd = gui_y;
61 const double W = tileset_tile_width(t) * map_zoom;
62 const double H = tileset_tile_height(t) * map_zoom;
63 double map_x, map_y;
64
65 /* First convert to map positions. This ignores hex conversions; we're
66 * not looking for an exact tile. */
67 if (tileset_is_isometric(t)) {
68 /* Includes hex cases. */
69 map_x = (gui_xd * H + gui_yd * W) / (W * H);
70 map_y = (gui_yd * W - gui_xd * H) / (W * H);
71 } else {
72 map_x = gui_xd / W;
73 map_y = gui_yd / H;
74 }
75
76 /* Now convert to natural positions. Note this assumes the macro form
77 * of the conversion will work with floating-point values. */
79
80}
81
82/************************************************************************/
85static void gui_to_overview_pos(const struct tileset *t,
86 int *ovr_x, int *ovr_y,
87 int gui_x, int gui_y)
88{
89 double ntl_x, ntl_y;
90
92
93 /* Now convert straight to overview coordinates. */
96
97 /* Now do additional adjustments. See map_to_overview_pos(). */
100 } else {
101 if (MAP_IS_ISOMETRIC) {
102 /* HACK: For iso-maps that don't wrap in the X direction we clip
103 * a half-tile off of the left and right of the overview. This
104 * means some tiles only are halfway shown. However it means we
105 * don't show any unreal tiles, which we'd otherwise be doing. The
106 * rest of the code can't handle unreal tiles in the overview. */
108 }
109 }
110
113 }
114}
115
116/************************************************************************/
119static struct color *overview_tile_color(struct tile *ptile)
120{
122 struct city *pcity = tile_city(ptile);
123
124 if (pcity) {
125 if (NULL == client.conn.playing
126 || city_owner(pcity) == client.conn.playing) {
128 } else if (pplayers_allied(city_owner(pcity), client.conn.playing)) {
129 /* Includes teams. */
131 } else {
133 }
134 }
135 }
137 struct unit *punit = find_visible_unit(ptile);
138
139 if (punit) {
140 if (NULL == client.conn.playing
144 /* Includes teams. */
146 } else {
148 }
149 }
150 }
152 struct player *owner = tile_owner(ptile);
153
154 if (owner) {
157 } else if (!is_ocean_tile(ptile)) {
159 }
160 }
161 }
163 && tile_terrain(ptile) != T_UNKNOWN) {
164 return get_terrain_color(tileset, tile_terrain(ptile));
165 }
167 && tile_terrain(ptile) != T_UNKNOWN) {
170 } else {
171 if (is_ocean_tile(ptile)) {
173 } else {
175 }
176 }
177 }
178
180}
181
182/************************************************************************/
187{
188 struct canvas *dest = get_overview_window();
189
190 if (!dest) {
191 return;
192 }
194 0, 0, 0, 0,
196}
197
198/************************************************************************/
202static void redraw_overview(void)
203{
204 int i, x[4], y[4];
205
206 if (!gui_options.overview.map) {
207 return;
208 }
209
210 {
211 struct canvas *src = gui_options.overview.map;
212 struct canvas *dst = gui_options.overview.window;
217
218 canvas_copy(dst, src, 0, 0, ix, iy, x_left, y_top);
219 canvas_copy(dst, src, 0, y_top, ix, 0, x_left, iy);
220 canvas_copy(dst, src, x_left, 0, 0, iy, ix, y_top);
221 canvas_copy(dst, src, x_left, y_top, 0, 0, ix, iy);
222 }
223
224 gui_to_overview_pos(tileset, &x[0], &y[0],
226 gui_to_overview_pos(tileset, &x[1], &y[1],
228 gui_to_overview_pos(tileset, &x[2], &y[2],
231 gui_to_overview_pos(tileset, &x[3], &y[3],
233
234 for (i = 0; i < 4; i++) {
235 int src_x = x[i];
236 int src_y = y[i];
237 int dst_x = x[(i + 1) % 4];
238 int dst_y = y[(i + 1) % 4];
239
244 }
245
247
249}
250
251/************************************************************************/
254static void dirty_overview(void)
255{
257}
258
259/************************************************************************/
263{
264 /* Currently this function is called from mapview_common. However it
265 * should be made static eventually. */
266 if (overview_dirty) {
268 }
269}
270
271/************************************************************************/
274static double wrap_double(double value, double wrap)
275{
276 while (value < 0) {
277 value += wrap;
278 }
279 while (value >= wrap) {
280 value -= wrap;
281 }
282 return value;
283}
284
285/************************************************************************/
289{
290 double ntl_x, ntl_y;
291 int ox, oy;
292
296
297 /* NOTE: this embeds the map wrapping in the overview code. This is
298 * basically necessary for the overview to be efficiently
299 * updated. */
303 } else {
305 }
309 } else {
311 }
312
314
318}
319
320/************************************************************************/
324 int map_x, int map_y)
325{
326 /* The map position may not be normal, for instance when the mapview
327 * origin is not a normal position.
328 *
329 * NOTE: this embeds the map wrapping in the overview code. */
333
336 } else {
337 if (MAP_IS_ISOMETRIC) {
338 /* HACK: For iso-maps that don't wrap in the X direction we clip
339 * a half-tile off of the left and right of the overview. This
340 * means some tiles only are halfway shown. However it means we
341 * don't show any unreal tiles, which we'd otherwise be doing. The
342 * rest of the code can't handle unreal tiles in the overview. */
343 ovr_x--;
344 }
345 }
348 }
352}
353
354/************************************************************************/
358 int overview_x, int overview_y)
359{
362
364 /* Clip half tile left and right. See comment in map_to_overview_pos. */
365 ntl_x++;
366 }
367
369 /* All positions on the overview should be valid. */
371}
372
373/************************************************************************/
377{
378 if (!can_client_change_view()) {
379 return;
380 }
381 whole_map_iterate(&(wld.map), ptile) {
385}
386
387/************************************************************************/
394 struct tile *ptile,
395 int x, int y, int w, int h)
396{
398 overview_tile_color(ptile),
399 x, y, w, h);
403 0, 0, w, h);
404 }
405}
406
407/************************************************************************/
410void overview_update_tile(struct tile *ptile)
411{
412 int tile_x, tile_y;
413
414 /* Base overview positions are just like natural positions, but scaled to
415 * the overview tile dimensions. */
420
421 if (MAP_IS_ISOMETRIC) {
424 /* This tile is shown half on the left and half on the right
425 * side of the overview. So we have to draw it in two parts. */
430 }
431 } else {
432 /* Clip half tile left and right.
433 * See comment in map_to_overview_pos. */
435 }
436 }
437
441
444}
445
446/************************************************************************/
450{
451 int w, h;
452 int xfact = MAP_IS_ISOMETRIC ? 2 : 1;
453
454 static int recursion = 0; /* Just to be safe. */
455
456 /* Clip half tile left and right. See comment in map_to_overview_pos. */
458
459 if (recursion > 0 || wld.map.xsize <= 0 || wld.map.ysize <= 0) {
460 return;
461 }
462 recursion++;
463
466
467 /* Set the scale of the overview map. This attempts to limit the
468 * overview to the size of the area available.
469 *
470 * It rounds up since this gives good results with the default settings.
471 * It may need tweaking if the panel resizes itself. */
472 OVERVIEW_TILE_SIZE = MIN((w - 1) / (wld.map.xsize * xfact) + 1,
473 (h - 1) / wld.map.ysize + 1);
475
476 log_debug("Map size %d,%d - area size %d,%d - scale: %d", wld.map.xsize,
478
482
486 }
493 0, 0,
496
497 /* Call gui specific function. */
499
502 }
503
504 recursion--;
505}
506
507/************************************************************************/
519
520/************************************************************************/
524{
525 /* This is called once for each option changed so it is slower than
526 * necessary. If this becomes a problem it could be switched to use a
527 * queue system like the mapview drawing code does. */
529}
struct canvas int int int int struct sprite *sprite canvas_put_rectangle
Definition canvas_g.h:55
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
@ LINE_NORMAL
Definition canvas_g.h:26
#define city_owner(_pcity_)
Definition city.h:563
struct civclient client
bool can_client_change_view(void)
enum known_type client_tile_get_known(const struct tile *ptile)
Definition climap.c:36
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)
struct color * get_terrain_color(const struct tileset *t, const struct terrain *pterrain)
char * incite_cost
Definition comments.c:75
struct unit * find_visible_unit(struct tile *ptile)
Definition control.c:822
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 world wld
Definition game.c:63
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
struct city * owner
Definition citydlg.c:226
void update_map_canvas_scrollbars_size(void)
Definition mapview.c:696
void get_overview_area_dimensions(int *width, int *height)
Definition mapview.c:317
void update_overview_scroll_window_pos(int x, int y)
Definition mapview.c:657
void overview_size_changed(void)
Definition mapview.c:326
struct canvas * get_overview_window(void)
Definition mapview.c:337
#define fc_assert(condition)
Definition log.h:176
#define log_debug(message,...)
Definition log.h:115
bool normalize_map_pos(const struct civ_map *nmap, int *x, int *y)
Definition map.c:979
#define NATURAL_TO_MAP_POS(pmap_x, pmap_y, nat_x, nat_y)
Definition map.h:178
#define do_in_natural_pos(ntl_x, ntl_y, map_x, map_y)
Definition map.h:210
#define NATURAL_HEIGHT
Definition map.h:227
#define MAP_IS_ISOMETRIC
Definition map.h:42
#define MAP_TO_NATURAL_POS(pnat_x, pnat_y, map_x, map_y)
Definition map.h:184
#define whole_map_iterate(_map, _tile)
Definition map.h:545
#define current_wrap_has_flag(flag)
Definition map.h:51
#define NATURAL_WIDTH
Definition map.h:226
#define do_in_natural_pos_end
Definition map.h:217
#define whole_map_iterate_end
Definition map.h:554
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:233
struct view mapview
#define H(x, y, z)
Definition md5.c:92
struct client_options gui_options
Definition options.c:71
@ OLAYER_BORDERS
Definition options.h:83
@ OLAYER_BACKGROUND
Definition options.h:81
@ OLAYER_CITIES
Definition options.h:86
@ OLAYER_BORDERS_ON_OCEAN
Definition options.h:84
@ OLAYER_UNITS
Definition options.h:85
@ OLAYER_RELIEF
Definition options.h:82
static double wrap_double(double value, double wrap)
static void gui_to_overview_pos(const struct tileset *t, int *ovr_x, int *ovr_y, int gui_x, int gui_y)
void flush_dirty_overview(void)
void overview_to_map_pos(int *map_x, int *map_y, int overview_x, int overview_y)
static void gui_to_natural_pos(const struct tileset *t, double *ntl_x, double *ntl_y, int gui_x, int gui_y)
void overview_redraw_callback(struct option *option)
void refresh_overview_canvas(void)
static bool overview_dirty
void center_tile_overviewcanvas(void)
void refresh_overview_from_canvas(void)
static void redraw_overview(void)
static struct color * overview_tile_color(struct tile *ptile)
void overview_update_tile(struct tile *ptile)
int OVERVIEW_TILE_SIZE
static void put_overview_tile_area(struct canvas *pcanvas, struct tile *ptile, int x, int y, int w, int h)
void calculate_overview_dimensions(void)
void overview_free(void)
static void dirty_overview(void)
void map_to_overview_pos(int *overview_x, int *overview_y, int map_x, int map_y)
#define OVERVIEW_TILE_WIDTH
#define OVERVIEW_TILE_HEIGHT
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
#define FC_WRAP(value, range)
Definition shared.h:65
#define MIN(x, y)
Definition shared.h:55
#define MAX(x, y)
Definition shared.h:54
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
static int recursion[AIT_LAST]
Definition srv_log.c:45
Definition city.h:320
int xsize
Definition map_types.h:78
int ysize
Definition map_types.h:78
struct connection conn
Definition client_main.h:96
struct overview overview
Definition options.h:425
Definition colors.h:21
struct player * playing
Definition connection.h:151
double map_y0
Definition options.h:93
double map_x0
Definition options.h:93
bool fog
Definition options.h:102
bool layers[OLAYER_COUNT]
Definition options.h:103
struct canvas * map
Definition options.h:97
int width
Definition options.h:94
struct canvas * window
Definition options.h:100
int height
Definition options.h:94
Definition tile.h:50
Definition unit.h:138
int height
float gui_x0
float gui_y0
int width
struct civ_map map
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define T_UNKNOWN
Definition terrain.h:57
#define is_ocean_tile(ptile)
Definition terrain.h:303
#define terrain_has_flag(terr, flag)
Definition terrain.h:283
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:88
@ TILE_KNOWN_UNSEEN
Definition tile.h:37
#define tile_terrain(_tile)
Definition tile.h:110
#define tile_owner(_tile)
Definition tile.h:96
struct sprite * get_basic_fog_sprite(const struct tileset *t)
Definition tilespec.c:7053
bool tileset_is_isometric(const struct tileset *t)
Definition tilespec.c:712
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:765
int tileset_tile_width(const struct tileset *t)
Definition tilespec.c:753
#define unit_owner(_pu)
Definition unit.h:396
float map_zoom
Definition zoom.c:25