Freeciv-3.1
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
107bool vision_reveal_tiles(struct vision *vision, bool reveal_tiles);
108
110 char *name;
111 struct tile *location; /* Cannot be NULL */
112 struct player *owner; /* May be NULL, always check! */
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;
123 enum capital_type capital;
124
125 bv_imprs improvements;
126};
127
128#define vision_site_owner(v) ((v)->owner)
129void vision_site_destroy(struct vision_site *psite);
131 struct player *owner);
132struct vision_site *vision_site_new_from_city(const struct city *pcity);
134 const struct city *pcity);
135struct vision_site *vision_site_copy(const struct vision_site *psite);
136
137citizens vision_site_size_get(const struct vision_site *psite);
138void vision_site_size_set(struct vision_site *psite, citizens size);
139
140#ifdef __cplusplus
141}
142#endif /* __cplusplus */
143
144#endif /* FC__VISION_H */
unsigned char citizens
Definition fc_types.h:358
struct city * owner
Definition citydlg.c:219
size_t size
Definition specvec.h:72
Definition city.h:309
Definition tile.h:49
char * name
Definition vision.h:110
bool happy
Definition vision.h:119
bv_imprs improvements
Definition vision.h:125
citizens size
Definition vision.h:115
struct tile * location
Definition vision.h:111
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:112
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: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
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
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