Stop sharing requirement_unit_state_ereq().
[freeciv.git] / common / vision.c
blobd43942cea6341422831718cf414f65ddcb9ca60f
1 /***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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.
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 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 /* utility */
19 #include "log.h"
20 #include "mem.h"
21 #include "shared.h"
23 /* common */
24 #include "game.h"
25 #include "player.h"
26 #include "tile.h"
27 #include "vision.h"
30 /****************************************************************************
31 Create a new vision source.
32 ****************************************************************************/
33 struct vision *vision_new(struct player *pplayer, struct tile *ptile)
35 struct vision *vision = fc_malloc(sizeof(*vision));
37 vision->player = pplayer;
38 vision->tile = ptile;
39 vision->can_reveal_tiles = TRUE;
40 vision->radius_sq[V_MAIN] = -1;
41 vision->radius_sq[V_INVIS] = -1;
43 return vision;
46 /****************************************************************************
47 Free the vision source.
48 ****************************************************************************/
49 void vision_free(struct vision *vision)
51 fc_assert(-1 == vision->radius_sq[V_MAIN]);
52 fc_assert(-1 == vision->radius_sq[V_INVIS]);
53 free(vision);
56 /****************************************************************************
57 Sets the can_reveal_tiles flag.
58 Returns the old flag.
59 ****************************************************************************/
60 bool vision_reveal_tiles(struct vision *vision, bool reveal_tiles)
62 bool was = vision->can_reveal_tiles;
64 vision->can_reveal_tiles = reveal_tiles;
65 return was;
68 /****************************************************************************
69 Frees vision site structure.
70 ****************************************************************************/
71 void vision_site_destroy(struct vision_site *psite)
73 free(psite);
76 /****************************************************************************
77 Returns the basic structure.
78 ****************************************************************************/
79 struct vision_site *vision_site_new(int identity, struct tile *location,
80 struct player *owner)
82 struct vision_site *psite = fc_calloc(1, sizeof(*psite));
84 psite->identity = identity;
85 psite->location = location;
86 psite->owner = owner;
88 return psite;
91 /****************************************************************************
92 Returns the basic structure filled with initial elements.
93 ****************************************************************************/
94 struct vision_site *vision_site_new_from_city(const struct city *pcity)
96 struct vision_site *psite =
97 vision_site_new(pcity->id, city_tile(pcity), city_owner(pcity));
99 vision_site_size_set(psite, city_size_get(pcity));
100 sz_strlcpy(psite->name, city_name_get(pcity));
102 return psite;
105 /****************************************************************************
106 Returns the basic structure filled with current elements.
107 ****************************************************************************/
108 void vision_site_update_from_city(struct vision_site *psite,
109 const struct city *pcity)
111 /* should be same identity and location */
112 fc_assert_ret(psite->identity == pcity->id);
113 fc_assert_ret(psite->location == pcity->tile);
115 psite->owner = city_owner(pcity);
117 vision_site_size_set(psite, city_size_get(pcity));
118 sz_strlcpy(psite->name, city_name_get(pcity));
121 /*****************************************************************************
122 Get the city size.
123 *****************************************************************************/
124 citizens vision_site_size_get(const struct vision_site *psite)
126 fc_assert_ret_val(psite != NULL, 0);
128 return psite->size;
131 /*****************************************************************************
132 Set the city size.
133 *****************************************************************************/
134 void vision_site_size_set(struct vision_site *psite, citizens size)
136 fc_assert_ret(psite != NULL);
138 psite->size = size;