File: vision.h

package info (click to toggle)
freeciv 2.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 212,508 kB
  • sloc: ansic: 443,831; cpp: 29,541; sh: 7,982; makefile: 7,886; python: 1,933; xml: 945
file content (148 lines) | stat: -rw-r--r-- 5,436 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/********************************************************************** 
 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
***********************************************************************/
#ifndef FC__VISION_H
#define FC__VISION_H

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#include "fc_types.h"

#include "improvement.h"		/* bv_imprs */

/****************************************************************************
  Vision for cities and units:

  A vision source has a fixed owner and tile; it changes only in range.
  Vision range is given in radius squared; most such values will come from
  the ruleset.  All vision is circular.

  A vision source is created using vision_new; this creates the source
  without any sight points.  Call vision_change_sight to change the sight
  points of a vision source (generally called from city_refresh_vision
  and unit_refresh vision; this can be called liberally to do updates after
  an effect may have changed the source's vision range).  Clear the sight
  using vision_clear_sight before freeing it with vision_free.

  vision_get_sight returns the sight points of the source.  This should
  only rarely be necessary since all fogging and unfogging operations
  are taken care of internally.

  vision_reveal_tiles() controls whether the vision source can discover
  new (unknown) tiles or simply maintain vision on already-known tiles.
  By default, cities should pass FALSE for this since they cannot
  discover new tiles.

  ***** IMPORTANT *****
  To change any of the parameters given to vision_new - that is, to change
  the vision source's position (tile) or owner - you must create a new
  vision and then clear and free the old vision.  Order is very important
  here since you do not want to fog tiles intermediately.  You must store
  a copy of the old vision source, then create and attach and fill out the
  sight for a new vision source, and only then may you clear and free the
  old vision source.  In most operations you'll want to stick some other
  code in between so that for the bulk of the operation all tiles are
  visible.  For instance to move a unit:

    old_vision = punit->server.vision;
    punit->server.vision = vision_new(unit_owner(punit), dest_tile);
    vision_change_sight(punit->server.vision,
                        get_unit_vision_at(punit, dest_tile));

    ...then do all the work of moving the unit...

    vision_clear_sight(old_vision);
    vision_free(old_vision);

  note that for all the code in the middle both the new and the old
  vision sources are active.  The same process applies when transferring
  a unit or city between players, etc.
****************************************************************************/

/* Invariants: V_MAIN vision ranges must always be more than V_INVIS
 * ranges. */
enum vision_layer {
  V_MAIN,
  V_INVIS,
  V_COUNT
};

#define vision_layer_iterate(v) {                                           \
  enum vision_layer v;                                                      \
  for (v = 0; v < V_COUNT; v++) {
#define vision_layer_iterate_end }}


typedef short int v_radius_t[V_COUNT];

struct vision {
  /* These values cannot be changed after initialization. */
  struct player *player;
  struct tile *tile;
  bool can_reveal_tiles;

  /* The radius of the vision source. */
  v_radius_t radius_sq;
};

/* Initialize a vision radius array. */
#define V_RADIUS(main_sq, invis_sq) { (main_sq), (invis_sq) }

#define ASSERT_VISION(v)						\
 do {									\
   fc_assert((v)->radius_sq[V_MAIN] >= (v)->radius_sq[V_INVIS]);	\
 } while(FALSE);

struct vision *vision_new(struct player *pplayer, struct tile *ptile);
void vision_free(struct vision *vision);

bool vision_reveal_tiles(struct vision *vision, bool reveal_tiles);

/* This is copied in maphand.c really_give_tile_info_from_player_to_player(),
 * so be careful with pointers!
 */
struct vision_site {
  char name[MAX_LEN_NAME];
  struct tile *location; /* Cannot be NULL */
  struct player *owner;  /* May be NULL, always check! */

  int identity;          /* city > IDENTITY_NUMBER_ZERO */
  citizens size;         /* city size (0 <= size <= MAX_CITY_SIZE) */

  bool occupied;
  bool walls;
  bool happy;
  bool unhappy;
  int style;
  int city_image;

  bv_imprs improvements;
};

#define vision_site_owner(v) ((v)->owner)
void vision_site_destroy(struct vision_site *psite);
struct vision_site *vision_site_new(int identity, struct tile *location,
                                    struct player *owner);
struct vision_site *vision_site_new_from_city(const struct city *pcity);
void vision_site_update_from_city(struct vision_site *psite,
                                  const struct city *pcity);

citizens vision_site_size_get(const struct vision_site *psite);
void vision_site_size_set(struct vision_site *psite, citizens size);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif  /* FC__VISION_H */