Freeciv-3.2
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;
43
44 return vision;
45}
46
47/************************************************************************/
57
58/************************************************************************/
63{
65
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;
95
96 return psite;
97}
98
99/************************************************************************/
102struct vision_site *vision_site_new_from_city(const struct city *pcity,
103 const struct player *watcher)
104{
105 struct vision_site *psite
106 = vision_site_new(pcity->id, city_tile(pcity), city_owner(pcity));
107
109 psite->name = fc_strdup(city_name_get(pcity));
110
111 if (watcher == pcity->original) {
112 psite->original = pcity->original;
113 } else {
114 psite->original = NULL;
115 }
116
117 return psite;
118}
119
120/************************************************************************/
124 const struct city *pcity,
125 const struct player *watcher)
126{
127 /* Should be same identity and location */
128 fc_assert_ret(psite->identity == pcity->id);
129 fc_assert_ret(psite->location == pcity->tile);
130
131 psite->owner = city_owner(pcity);
132
133 if (watcher == pcity->original) {
134 psite->original = pcity->original;
135 } else {
136 psite->original = NULL;
137 }
138
140
141 if (psite->name != NULL) {
142 free(psite->name);
143 }
144 psite->name = fc_strdup(city_name_get(pcity));
145}
146
147/************************************************************************/
151{
152 /* Unlike in _new(), we don't need to use zeroing calloc() here
153 * as we overwrite everything. */
154 struct vision_site *copy = fc_malloc(sizeof(*psite));
155
156 /* Copy everything. */
157 *copy = *psite;
158
159 /* Then allocate things that aren't shared */
160 if (psite->name != NULL) {
161 copy->name = fc_strdup(psite->name);
162 }
163
164 return copy;
165}
166
167/************************************************************************/
171{
173
174 return psite->size;
175}
176
177/************************************************************************/
181{
183
184 psite->size = size;
185}
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
#define city_tile(_pcity_)
Definition city.h:564
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
#define city_owner(_pcity_)
Definition city.h:563
char * incite_cost
Definition comments.c:75
unsigned char citizens
Definition fc_types.h:388
struct city * owner
Definition citydlg.c:226
#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:320
struct player * original
Definition city.h:324
int id
Definition city.h:326
struct tile * tile
Definition city.h:322
Definition tile.h:50
struct player * owner
Definition tile.h:60
char * name
Definition vision.h:110
struct tile * location
Definition vision.h:111
int identity
Definition vision.h:115
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
struct vision_site * vision_site_new_from_city(const struct city *pcity, const struct player *watcher)
Definition vision.c:102
void vision_site_size_set(struct vision_site *psite, citizens size)
Definition vision.c:180
citizens vision_site_size_get(const struct vision_site *psite)
Definition vision.c:170
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_site_update_from_city(struct vision_site *psite, const struct city *pcity, const struct player *watcher)
Definition vision.c:123
void vision_free(struct vision *vision)
Definition vision.c:50
struct vision_site * vision_site_copy(const struct vision_site *psite)
Definition vision.c:150
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