File: climap.c

package info (click to toggle)
freeciv 2.6.2-1~bpo10+1
  • links: PTS, VCS
  • area: main
  • in suites: buster-backports
  • size: 212,500 kB
  • sloc: ansic: 443,831; cpp: 29,541; sh: 7,982; makefile: 7,886; python: 1,933; xml: 945
file content (138 lines) | stat: -rw-r--r-- 4,526 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/********************************************************************** 
 Freeciv - Copyright (C) 2002 - The Freeciv Project
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
***********************************************************************/

#ifdef HAVE_CONFIG_H
#include <fc_config.h>
#endif

/* common */
#include "map.h"
#include "shared.h"

/* client */
#include "client_main.h"
#include "climap.h"
#include "tilespec.h"           /* tileset_is_isometric(tileset) */

/************************************************************************
 A tile's "known" field is used by the server to store whether _each_
 player knows the tile.  Client-side, it's used as an enum known_type
 to track whether the tile is known/fogged/unknown.

 Judicious use of this function also makes things very convenient for
 civworld, since it uses both client and server-style storage; since it
 uses the stock tilespec.c file, this function serves as a wrapper.

*************************************************************************/
enum known_type client_tile_get_known(const struct tile *ptile)
{
  if (NULL == client.conn.playing) {
    if (client_is_observer()) {
      return TILE_KNOWN_SEEN;
    } else {
      return TILE_UNKNOWN;
    }
  }
  return tile_get_known(ptile, client.conn.playing);
}

/**************************************************************************
  Convert the given GUI direction into a map direction.

  GUI directions correspond to the current viewing interface, so that
  DIR8_NORTH is up on the mapview.  map directions correspond to the
  underlying map tiles, so that DIR8_NORTH means moving with a vector of
  (0,-1).  Neither necessarily corresponds to "north" on the underlying
  world (once iso-maps are possible).

  See also map_to_gui_dir().
**************************************************************************/
enum direction8 gui_to_map_dir(enum direction8 gui_dir)
{
  if (tileset_is_isometric(tileset)) {
    return dir_ccw(gui_dir);
  } else {
    return gui_dir;
  }
}

/**************************************************************************
  Convert the given GUI direction into a map direction.

  See also gui_to_map_dir().
**************************************************************************/
enum direction8 map_to_gui_dir(enum direction8 map_dir)
{
  if (tileset_is_isometric(tileset)) {
    return dir_cw(map_dir);
  } else {
    return map_dir;
  }
}

/***************************************************************************
  Client variant of city_tile().  This include the case of this could a
  ghost city (see client/packhand.c).  In a such case, the returned tile
  is an approximative position of the city on the map.
***************************************************************************/
struct tile *client_city_tile(const struct city *pcity)
{
  int dx, dy;
  double x = 0, y = 0;
  size_t num = 0;

  if (NULL == pcity) {
    return NULL;
  }

  if (NULL != city_tile(pcity)) {
    /* Normal city case. */
    return city_tile(pcity);
  }

  whole_map_iterate(ptile) {
    int tile_x, tile_y;

    index_to_map_pos(&tile_x, &tile_y, tile_index(ptile));
    if (pcity == tile_worked(ptile)) {
      if (0 == num) {
        x = tile_x;
        y = tile_y;
        num = 1;
      } else {
        num++;
        base_map_distance_vector(&dx, &dy, (int)x, (int)y, tile_x, tile_y);
        x += (double) dx / num;
        y += (double) dy / num;
      }
    }
  } whole_map_iterate_end;

  if (0 < num) {
    return map_pos_to_tile((int) x, (int) y);
  } else {
    return NULL;
  }
}

/**************************************************************************
  Returns TRUE when a tile is available to be worked, or the city itself
  is currently working the tile (and can continue).

  See also city_can_work_tile() (common/city.[ch]).
**************************************************************************/
bool client_city_can_work_tile(const struct city *pcity,
                               const struct tile *ptile)
{
  return base_city_can_work_tile(client_player(), pcity, ptile);
}