Freeciv-3.4
Loading...
Searching...
No Matches
vision.h
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#ifndef FC__VISION_H
14#define FC__VISION_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/* common */
21#include "fc_types.h"
22#include "improvement.h" /* bv_imprs */
23
24/****************************************************************************
25 Vision for cities and units:
26
27 A vision source has a fixed owner and tile; it changes only in range.
28 Vision range is given in radius squared; most such values will come from
29 the ruleset. All vision is circular.
30
31 A vision source is created using vision_new(); this creates the source
32 without any sight points. Call vision_change_sight() to change the sight
33 points of a vision source (generally called from city_refresh_vision()
34 and unit_refresh_vision(); this can be called liberally to do updates after
35 an effect may have changed the source's vision range). Clear the sight
36 using vision_clear_sight() before freeing it with vision_free().
37
38 vision_get_sight() returns the sight points of the source. This should
39 only rarely be necessary since all fogging and unfogging operations
40 are taken care of internally.
41
42 vision_reveal_tiles() controls whether the vision source can discover
43 new (unknown) tiles or simply maintain vision on already-known tiles.
44 By default, cities should pass FALSE for this since they cannot
45 discover new tiles.
46
47 ***** IMPORTANT *****
48 To change any of the parameters given to vision_new() - that is, to change
49 the vision source's position (tile) or owner - you must create a new
50 vision and then clear and free the old vision. Order is very important
51 here since you do not want to fog tiles intermediately. You must store
52 a copy of the old vision source, then create and attach and fill out the
53 sight for a new vision source, and only then may you clear and free the
54 old vision source. In most operations you'll want to stick some other
55 code in between so that for the bulk of the operation all tiles are
56 visible. For instance to move a unit:
57
58 old_vision = punit->server.vision;
59 punit->server.vision = vision_new(unit_owner(punit), dest_tile);
60 vision_change_sight(punit->server.vision,
61 get_unit_vision_at(punit, dest_tile));
62
63 ...then do all the work of moving the unit...
64
65 vision_clear_sight(old_vision);
66 vision_free(old_vision);
67
68 note that for all the code in the middle both the new and the old
69 vision sources are active. The same process applies when transferring
70 a unit or city between players, etc.
71****************************************************************************/
72
73/* Invariants: V_MAIN vision ranges must always be more than V_INVIS
74 * ranges. */
75
76#define vision_layer_iterate(v) { \
77 enum vision_layer v; \
78 for (v = 0; v < V_COUNT; v++) {
79#define vision_layer_iterate_end }}
80
81
82typedef short int v_radius_t[V_COUNT];
83
84struct vision {
85 /* These values cannot be changed after initialization. */
86 struct player *player;
87 struct tile *tile;
89
90 /* The radius of the vision source. */
92};
93
94/* Initialize a vision radius array. */
95#define V_RADIUS(main_sq, invis_sq, subs_sq) { (main_sq), (invis_sq), (subs_sq) }
96
97#define ASSERT_VISION(v) \
98 do { \
99 fc_assert((v)->radius_sq[V_MAIN] >= (v)->radius_sq[V_INVIS]); \
100 fc_assert((v)->radius_sq[V_MAIN] >= (v)->radius_sq[V_SUBSURFACE]); \
101 } while (FALSE);
102
103struct vision *vision_new(struct player *pplayer, struct tile *ptile);
104void vision_free(struct vision *vision);
105
107
109 char *name;
110 struct tile *location; /* Cannot be nullptr */
111 struct player *owner; /* May be nullptr, always check! */
112 struct player *original; /* Can be nullptr, even in case of a city */
113
114 int identity; /* city > IDENTITY_NUMBER_ZERO */
115 citizens size; /* city size (0 <= size <= MAX_CITY_SIZE) */
116
118 int walls;
119 bool happy;
121 int style;
124
126};
127
128#define vision_site_owner(v) ((v)->owner)
131 struct player *owner);
132 struct vision_site *vision_site_new_from_city(const struct city *pcity,
133 const struct player *watcher);
135 const struct city *pcity,
136 const struct player *watcher);
137struct vision_site *vision_site_copy(const struct vision_site *psite);
138
141
142#ifdef __cplusplus
143}
144#endif /* __cplusplus */
145
146#endif /* FC__VISION_H */
char * incite_cost
Definition comments.c:77
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
unsigned char citizens
Definition fc_types.h:249
struct city * owner
Definition citydlg.c:226
size_t size
Definition specvec.h:72
Definition city.h:318
Definition tile.h:50
char * name
Definition vision.h:109
bool happy
Definition vision.h:119
bv_imprs improvements
Definition vision.h:125
struct player * original
Definition vision.h:112
citizens size
Definition vision.h:115
struct tile * location
Definition vision.h:110
int identity
Definition vision.h:114
int walls
Definition vision.h:118
int style
Definition vision.h:121
bool unhappy
Definition vision.h:120
struct player * owner
Definition vision.h:111
int city_image
Definition vision.h:122
bool occupied
Definition vision.h:117
enum capital_type capital
Definition vision.h:123
struct tile * tile
Definition vision.h:87
bool can_reveal_tiles
Definition vision.h:88
v_radius_t radius_sq
Definition vision.h:91
struct player * player
Definition vision.h:86
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
short int v_radius_t[V_COUNT]
Definition vision.h:82
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