Freeciv21
Develop your civilization from humble roots to a global empire
vision.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 // utility
15 #include "log.h"
16 #include "shared.h"
17 
18 // common
19 #include "game.h"
20 #include "player.h"
21 #include "tile.h"
22 #include "vision.h"
23 
27 struct vision *vision_new(struct player *pplayer, struct tile *ptile)
28 {
29  auto *vision = new struct vision;
30 
31  vision->player = pplayer;
32  vision->tile = ptile;
33  vision->can_reveal_tiles = true;
34  vision->radius_sq[V_MAIN] = -1;
35  vision->radius_sq[V_INVIS] = -1;
36  vision->radius_sq[V_SUBSURFACE] = -1;
37 
38  return vision;
39 }
40 
44 void vision_free(struct vision *vision)
45 {
46  fc_assert(-1 == vision->radius_sq[V_MAIN]);
47  fc_assert(-1 == vision->radius_sq[V_INVIS]);
48  fc_assert(-1 == vision->radius_sq[V_SUBSURFACE]);
49  delete vision;
50 }
51 
56 bool vision_reveal_tiles(struct vision *vision, bool reveal_tiles)
57 {
58  bool was = vision->can_reveal_tiles;
59 
60  vision->can_reveal_tiles = reveal_tiles;
61  return was;
62 }
63 
68  struct player *owner)
69 {
70  vision_site *psite = new vision_site();
71 
72  psite->identity = identity;
73  psite->location = location;
74  psite->owner = owner;
75 
76  return psite;
77 }
78 
82 struct vision_site *vision_site_new_from_city(const struct city *pcity)
83 {
84  struct vision_site *psite =
85  vision_site_new(pcity->id, city_tile(pcity), city_owner(pcity));
86 
87  vision_site_size_set(psite, city_size_get(pcity));
88  sz_strlcpy(psite->name, city_name_get(pcity));
89 
90  return psite;
91 }
92 
97  const struct city *pcity)
98 {
99  // should be same identity and location
100  fc_assert_ret(psite->identity == pcity->id);
101  fc_assert_ret(psite->location == pcity->tile);
102 
103  psite->owner = city_owner(pcity);
104 
105  vision_site_size_set(psite, city_size_get(pcity));
106  sz_strlcpy(psite->name, city_name_get(pcity));
107 }
108 
113 {
114  fc_assert_ret_val(psite != nullptr, 0);
115 
116  return psite->size;
117 }
118 
123 {
124  fc_assert_ret(psite != nullptr);
125 
126  psite->size = size;
127 }
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
Definition: city.cpp:1083
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
Definition: city.cpp:1095
const char * city_name_get(const struct city *pcity)
Return the name of the city.
Definition: city.cpp:1077
citizens city_size_get(const struct city *pcity)
Get the city size.
Definition: city.cpp:1101
unsigned char citizens
Definition: fc_types.h:305
#define fc_assert_ret(condition)
Definition: log.h:112
#define fc_assert(condition)
Definition: log.h:89
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
size_t size
Definition: specvec.h:64
Definition: city.h:291
int id
Definition: city.h:296
struct tile * tile
Definition: city.h:293
Definition: player.h:231
Definition: tile.h:42
char name[MAX_LEN_NAME]
Definition: vision.h:114
citizens size
Definition: vision.h:119
struct tile * location
Definition: vision.h:115
int identity
Definition: vision.h:118
struct player * owner
Definition: vision.h:116
Definition: vision.h:83
struct tile * tile
Definition: vision.h:86
bool can_reveal_tiles
Definition: vision.h:87
v_radius_t radius_sq
Definition: vision.h:90
struct player * player
Definition: vision.h:85
#define sz_strlcpy(dest, src)
Definition: support.h:140
void vision_site_update_from_city(struct vision_site *psite, const struct city *pcity)
Returns the basic structure filled with current elements.
Definition: vision.cpp:96
struct vision * vision_new(struct player *pplayer, struct tile *ptile)
Create a new vision source.
Definition: vision.cpp:27
void vision_site_size_set(struct vision_site *psite, citizens size)
Set the city size.
Definition: vision.cpp:122
citizens vision_site_size_get(const struct vision_site *psite)
Get the city size.
Definition: vision.cpp:112
bool vision_reveal_tiles(struct vision *vision, bool reveal_tiles)
Sets the can_reveal_tiles flag.
Definition: vision.cpp:56
struct vision_site * vision_site_new_from_city(const struct city *pcity)
Returns the basic structure filled with initial elements.
Definition: vision.cpp:82
void vision_free(struct vision *vision)
Free the vision source.
Definition: vision.cpp:44
struct vision_site * vision_site_new(int identity, struct tile *location, struct player *owner)
Returns the basic structure.
Definition: vision.cpp:67