Freeciv-3.1
Loading...
Searching...
No Matches
vision.c
Go to the documentation of this file.
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.
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/* utility */
19#include "log.h"
20#include "mem.h"
21#include "shared.h"
22
23/* common */
24#include "game.h"
25#include "player.h"
26#include "tile.h"
27#include "vision.h"
28
29
30/************************************************************************/
33struct vision *vision_new(struct player *pplayer, struct tile *ptile)
34{
35 struct vision *vision = fc_malloc(sizeof(*vision));
36
37 vision->player = pplayer;
38 vision->tile = ptile;
40 vision->radius_sq[V_MAIN] = -1;
41 vision->radius_sq[V_INVIS] = -1;
42 vision->radius_sq[V_SUBSURFACE] = -1;
43
44 return vision;
45}
46
47/************************************************************************/
51{
52 fc_assert(-1 == vision->radius_sq[V_MAIN]);
53 fc_assert(-1 == vision->radius_sq[V_INVIS]);
54 fc_assert(-1 == vision->radius_sq[V_SUBSURFACE]);
55 free(vision);
56}
57
58/************************************************************************/
62bool vision_reveal_tiles(struct vision *vision, bool reveal_tiles)
63{
64 bool was = vision->can_reveal_tiles;
65
66 vision->can_reveal_tiles = reveal_tiles;
67
68 return was;
69}
70
71/************************************************************************/
75{
76 if (psite->name != NULL) {
77 free(psite->name);
78 }
79
80 free(psite);
81}
82
83/************************************************************************/
87 struct player *owner)
88{
89 struct vision_site *psite = fc_calloc(1, sizeof(*psite));
90
91 psite->identity = identity;
92 psite->location = location;
93 psite->owner = owner;
94
95 return psite;
96}
97
98/************************************************************************/
101struct vision_site *vision_site_new_from_city(const struct city *pcity)
102{
103 struct vision_site *psite =
104 vision_site_new(pcity->id, city_tile(pcity), city_owner(pcity));
105
106 vision_site_size_set(psite, city_size_get(pcity));
107 psite->name = fc_strdup(city_name_get(pcity));
108
109 return psite;
110}
111
112/************************************************************************/
116 const struct city *pcity)
117{
118 /* Should be same identity and location */
119 fc_assert_ret(psite->identity == pcity->id);
120 fc_assert_ret(psite->location == pcity->tile);
121
122 psite->owner = city_owner(pcity);
123
124 vision_site_size_set(psite, city_size_get(pcity));
125
126 if (psite->name != NULL) {
127 free(psite->name);
128 }
129 psite->name = fc_strdup(city_name_get(pcity));
130}
131
132/************************************************************************/
135struct vision_site *vision_site_copy(const struct vision_site *psite)
136{
137 /* Unlike in _new(), we don't need to use zeroing calloc() here
138 * as we overwrite everything. */
139 struct vision_site *copy = fc_malloc(sizeof(*psite));
140
141 /* Copy everything. */
142 *copy = *psite;
143
144 /* Then allocate things that aren't shared */
145 if (psite->name != NULL) {
146 copy->name = fc_strdup(psite->name);
147 }
148
149 return copy;
150}
151
152/************************************************************************/
156{
157 fc_assert_ret_val(psite != NULL, 0);
158
159 return psite->size;
160}
161
162/************************************************************************/
166{
167 fc_assert_ret(psite != NULL);
168
169 psite->size = size;
170}
const char * city_name_get(const struct city *pcity)
Definition city.c:1115
#define city_tile(_pcity_)
Definition city.h:544
static citizens city_size_get(const struct city *pcity)
Definition city.h:549
#define city_owner(_pcity_)
Definition city.h:543
unsigned char citizens
Definition fc_types.h:358
struct city * owner
Definition citydlg.c:219
#define fc_assert_ret(condition)
Definition log.h:191
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define fc_calloc(n, esz)
Definition mem.h:38
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
size_t size
Definition specvec.h:72
Definition city.h:309
int id
Definition city.h:315
struct tile * tile
Definition city.h:311
Definition tile.h:49
char * name
Definition vision.h:110
citizens size
Definition vision.h:115
struct tile * location
Definition vision.h:111
int identity
Definition vision.h:114
struct player * owner
Definition vision.h:112
struct tile * tile
Definition vision.h:88
bool can_reveal_tiles
Definition vision.h:89
v_radius_t radius_sq
Definition vision.h:92
struct player * player
Definition vision.h:87
#define TRUE
Definition support.h:46
void vision_site_update_from_city(struct vision_site *psite, const struct city *pcity)
Definition vision.c:115
void vision_site_size_set(struct vision_site *psite, citizens size)
Definition vision.c:165
citizens vision_site_size_get(const struct vision_site *psite)
Definition vision.c:155
struct vision * vision_new(struct player *pplayer, struct tile *ptile)
Definition vision.c:33
bool vision_reveal_tiles(struct vision *vision, bool reveal_tiles)
Definition vision.c:62
void vision_free(struct vision *vision)
Definition vision.c:50
struct vision_site * vision_site_new_from_city(const struct city *pcity)
Definition vision.c:101
struct vision_site * vision_site_copy(const struct vision_site *psite)
Definition vision.c:135
struct vision_site * vision_site_new(int identity, struct tile *location, struct player *owner)
Definition vision.c:86
void vision_site_destroy(struct vision_site *psite)
Definition vision.c:74