Freeciv-3.2: /fast/freeciv/nightly/S3_2/common/vision.h Source File

Freeciv-3.2

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
83 typedef short int v_radius_t[V_COUNT];
84
85 struct vision {
86 /* These values cannot be changed after initialization. */
87 struct player *player;
88 struct tile *tile;
89 bool can_reveal_tiles;
90
91 /* The radius of the vision source. */
92 v_radius_t radius_sq;
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
109 struct vision_site {
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
117 bool occupied;
118 int walls;
119 bool happy;
120 bool unhappy;
121 int style;
122 int city_image;
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);
130struct vision_site *vision_site_new(int identity, struct tile *location,
131 struct player *owner);
132struct vision_site *vision_site_new_from_city(const struct city *pcity);
133void vision_site_update_from_city(struct vision_site *psite,
134 const struct city *pcity);
135struct vision_site *vision_site_copy(const struct vision_site *psite);
136
137 citizens 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 */
incite_cost
char * incite_cost
Definition comments.c:74
fc_types.h
citizens
unsigned char citizens
Definition fc_types.h:391
owner
struct city * owner
Definition citydlg.c:220
improvement.h
size
size_t size
Definition specvec.h:72
city
Definition city.h:320
player
Definition player.h:247
tile
Definition tile.h:50
vision_site
Definition vision.h:109
vision_site::name
char * name
Definition vision.h:110
vision_site::happy
bool happy
Definition vision.h:119
vision_site::improvements
bv_imprs improvements
Definition vision.h:125
vision_site::size
citizens size
Definition vision.h:115
vision_site::location
struct tile * location
Definition vision.h:111
vision_site::identity
int identity
Definition vision.h:114
vision_site::walls
int walls
Definition vision.h:118
vision_site::style
int style
Definition vision.h:121
vision_site::unhappy
bool unhappy
Definition vision.h:120
vision_site::owner
struct player * owner
Definition vision.h:112
vision_site::city_image
int city_image
Definition vision.h:122
vision_site::occupied
bool occupied
Definition vision.h:117
vision_site::capital
enum capital_type capital
Definition vision.h:123
vision
Definition vision.h:85
vision::tile
struct tile * tile
Definition vision.h:88
vision::can_reveal_tiles
bool can_reveal_tiles
Definition vision.h:89
vision::radius_sq
v_radius_t radius_sq
Definition vision.h:92
vision::player
struct player * player
Definition vision.h:87
vision_site_update_from_city
void vision_site_update_from_city(struct vision_site *psite, const struct city *pcity)
Definition vision.c:115
vision_site_size_set
void vision_site_size_set(struct vision_site *psite, citizens size)
Definition vision.c:165
vision_site_size_get
citizens vision_site_size_get(const struct vision_site *psite)
Definition vision.c:155
vision_new
struct vision * vision_new(struct player *pplayer, struct tile *ptile)
Definition vision.c:33
vision_reveal_tiles
bool vision_reveal_tiles(struct vision *vision, bool reveal_tiles)
Definition vision.c:62
vision_free
void vision_free(struct vision *vision)
Definition vision.c:50
vision_site_new_from_city
struct vision_site * vision_site_new_from_city(const struct city *pcity)
Definition vision.c:101
vision_site_copy
struct vision_site * vision_site_copy(const struct vision_site *psite)
Definition vision.c:135
v_radius_t
short int v_radius_t[V_COUNT]
Definition vision.h:83
vision_site_new
struct vision_site * vision_site_new(int identity, struct tile *location, struct player *owner)
Definition vision.c:86
vision_site_destroy
void vision_site_destroy(struct vision_site *psite)
Definition vision.c:74