1 /**********************************************************************
2 Freeciv - Copyright (C) 2002 - The Freeciv Project
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)
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 ***********************************************************************/
15 #include <fc_config.h>
23 #include "client_main.h"
25 #include "tilespec.h" /* tileset_is_isometric(tileset) */
27 /************************************************************************
28 A tile's "known" field is used by the server to store whether _each_
29 player knows the tile. Client-side, it's used as an enum known_type
30 to track whether the tile is known/fogged/unknown.
32 Judicious use of this function also makes things very convenient for
33 civworld, since it uses both client and server-style storage; since it
34 uses the stock tilespec.c file, this function serves as a wrapper.
36 *************************************************************************/
37 enum known_type
client_tile_get_known(const struct tile
*ptile
)
39 if (NULL
== client
.conn
.playing
) {
40 if (client_is_observer()) {
41 return TILE_KNOWN_SEEN
;
46 return tile_get_known(ptile
, client
.conn
.playing
);
49 /**************************************************************************
50 Convert the given GUI direction into a map direction.
52 GUI directions correspond to the current viewing interface, so that
53 DIR8_NORTH is up on the mapview. map directions correspond to the
54 underlying map tiles, so that DIR8_NORTH means moving with a vector of
55 (0,-1). Neither necessarily corresponds to "north" on the underlying
56 world (once iso-maps are possible).
58 See also map_to_gui_dir().
59 **************************************************************************/
60 enum direction8
gui_to_map_dir(enum direction8 gui_dir
)
62 if (tileset_is_isometric(tileset
)) {
63 return dir_ccw(gui_dir
);
69 /**************************************************************************
70 Convert the given GUI direction into a map direction.
72 See also gui_to_map_dir().
73 **************************************************************************/
74 enum direction8
map_to_gui_dir(enum direction8 map_dir
)
76 if (tileset_is_isometric(tileset
)) {
77 return dir_cw(map_dir
);
83 /***************************************************************************
84 Client variant of city_tile(). This include the case of this could a
85 ghost city (see client/packhand.c). In a such case, the returned tile
86 is an approximative position of the city on the map.
87 ***************************************************************************/
88 struct tile
*client_city_tile(const struct city
*pcity
)
98 if (NULL
!= city_tile(pcity
)) {
99 /* Normal city case. */
100 return city_tile(pcity
);
103 whole_map_iterate(ptile
) {
106 index_to_map_pos(&tile_x
, &tile_y
, tile_index(ptile
));
107 if (pcity
== tile_worked(ptile
)) {
114 base_map_distance_vector(&dx
, &dy
, (int)x
, (int)y
, tile_x
, tile_y
);
115 x
+= (double) dx
/ num
;
116 y
+= (double) dy
/ num
;
119 } whole_map_iterate_end
;
122 return map_pos_to_tile((int) x
, (int) y
);
128 /**************************************************************************
129 Returns TRUE when a tile is available to be worked, or the city itself
130 is currently working the tile (and can continue).
132 See also city_can_work_tile() (common/city.[ch]).
133 **************************************************************************/
134 bool client_city_can_work_tile(const struct city
*pcity
,
135 const struct tile
*ptile
)
137 return base_city_can_work_tile(client_player(), pcity
, ptile
);