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