Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/climap.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
climap.c
Go to the documentation of this file.
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)
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/* common */
19#include "map.h"
20#include "shared.h"
21
22/* client */
23#include "client_main.h"
24#include "climap.h"
25#include "tilespec.h" /* tileset_is_isometric(tileset) */
26
27/**********************************************************************/
36 enum known_type client_tile_get_known(const struct tile *ptile)
37{
38 if (NULL == client.conn.playing) {
39 if (client_is_observer()) {
40 return TILE_KNOWN_SEEN;
41 } else {
42 return TILE_UNKNOWN;
43 }
44 }
45 return tile_get_known(ptile, client.conn.playing);
46}
47
48/**********************************************************************/
59 enum direction8 gui_to_map_dir(enum direction8 gui_dir)
60{
61 if (tileset_is_isometric(tileset)) {
62 return dir_ccw(gui_dir);
63 } else {
64 return gui_dir;
65 }
66}
67
68/**********************************************************************/
73 enum direction8 map_to_gui_dir(enum direction8 map_dir)
74{
75 if (tileset_is_isometric(tileset)) {
76 return dir_cw(map_dir);
77 } else {
78 return map_dir;
79 }
80}
81
82/**********************************************************************/
87 struct tile *client_city_tile(const struct city *pcity)
88{
89 int dx, dy;
90 double x = 0, y = 0;
91 size_t num = 0;
92
93 if (NULL == pcity) {
94 return NULL;
95 }
96
97 if (NULL != city_tile(pcity)) {
98 /* Normal city case. */
99 return city_tile(pcity);
100 }
101
102 whole_map_iterate(&(wld.map), ptile) {
103 int tile_x, tile_y;
104
105 index_to_map_pos(&tile_x, &tile_y, tile_index(ptile));
106 if (pcity == tile_worked(ptile)) {
107 if (0 == num) {
108 x = tile_x;
109 y = tile_y;
110 num = 1;
111 } else {
112 num++;
113 base_map_distance_vector(&dx, &dy, (int)x, (int)y, tile_x, tile_y);
114 x += (double) dx / num;
115 y += (double) dy / num;
116 }
117 }
118 } whole_map_iterate_end;
119
120 if (0 < num) {
121 return map_pos_to_tile(&(wld.map), (int) x, (int) y);
122 } else {
123 return NULL;
124 }
125}
126
127/**********************************************************************/
133 bool client_city_can_work_tile(const struct city *pcity,
134 const struct tile *ptile)
135{
136 return base_city_can_work_tile(client_player(), pcity, ptile);
137}
base_city_can_work_tile
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Definition city.c:1368
city_tile
#define city_tile(_pcity_)
Definition city.h:544
client_is_observer
bool client_is_observer(void)
Definition client_main.c:1086
client
struct civclient client
Definition client_main.c:149
client_main.h
client_player
#define client_player()
Definition client_main.h:106
client_tile_get_known
enum known_type client_tile_get_known(const struct tile *ptile)
Definition climap.c:36
client_city_tile
struct tile * client_city_tile(const struct city *pcity)
Definition climap.c:87
gui_to_map_dir
enum direction8 gui_to_map_dir(enum direction8 gui_dir)
Definition climap.c:59
map_to_gui_dir
enum direction8 map_to_gui_dir(enum direction8 map_dir)
Definition climap.c:73
client_city_can_work_tile
bool client_city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition climap.c:133
climap.h
wld
struct world wld
Definition game.c:58
dir_ccw
enum direction8 dir_ccw(enum direction8 dir)
Definition map.c:1201
map_pos_to_tile
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:417
base_map_distance_vector
void base_map_distance_vector(int *dx, int *dy, int x0dv, int y0dv, int x1dv, int y1dv)
Definition map.c:1022
dir_cw
enum direction8 dir_cw(enum direction8 dir)
Definition map.c:1172
map.h
whole_map_iterate
#define whole_map_iterate(_map, _tile)
Definition map.h:539
whole_map_iterate_end
#define whole_map_iterate_end
Definition map.h:548
index_to_map_pos
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:227
shared.h
city
Definition city.h:309
civclient::conn
struct connection conn
Definition client_main.h:96
connection::playing
struct player * playing
Definition connection.h:156
tile
Definition tile.h:49
tileset
Definition tilespec.c:459
world::map
struct civ_map map
Definition world_object.h:38
tile_get_known
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:386
tile_index
#define tile_index(_pt_)
Definition tile.h:87
tile_worked
#define tile_worked(_tile)
Definition tile.h:113
known_type
known_type
Definition tile.h:34
TILE_UNKNOWN
@ TILE_UNKNOWN
Definition tile.h:35
TILE_KNOWN_SEEN
@ TILE_KNOWN_SEEN
Definition tile.h:37
tileset_is_isometric
bool tileset_is_isometric(const struct tileset *t)
Definition tilespec.c:675
tilespec.h