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)
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 ***********************************************************************/
15 #include <fc_config.h>
30 /****************************************************************************
31 Create a new vision source.
32 ****************************************************************************/
33 struct vision
*vision_new(struct player
*pplayer
, struct tile
*ptile
)
35 struct vision
*vision
= fc_malloc(sizeof(*vision
));
37 vision
->player
= pplayer
;
39 vision
->can_reveal_tiles
= TRUE
;
40 vision
->radius_sq
[V_MAIN
] = -1;
41 vision
->radius_sq
[V_INVIS
] = -1;
46 /****************************************************************************
47 Free the vision source.
48 ****************************************************************************/
49 void vision_free(struct vision
*vision
)
51 fc_assert(-1 == vision
->radius_sq
[V_MAIN
]);
52 fc_assert(-1 == vision
->radius_sq
[V_INVIS
]);
56 /****************************************************************************
57 Sets the can_reveal_tiles flag.
59 ****************************************************************************/
60 bool vision_reveal_tiles(struct vision
*vision
, bool reveal_tiles
)
62 bool was
= vision
->can_reveal_tiles
;
64 vision
->can_reveal_tiles
= reveal_tiles
;
68 /****************************************************************************
69 Frees vision site structure.
70 ****************************************************************************/
71 void vision_site_destroy(struct vision_site
*psite
)
76 /****************************************************************************
77 Returns the basic structure.
78 ****************************************************************************/
79 struct vision_site
*vision_site_new(int identity
, struct tile
*location
,
82 struct vision_site
*psite
= fc_calloc(1, sizeof(*psite
));
84 psite
->identity
= identity
;
85 psite
->location
= location
;
91 /****************************************************************************
92 Returns the basic structure filled with initial elements.
93 ****************************************************************************/
94 struct vision_site
*vision_site_new_from_city(const struct city
*pcity
)
96 struct vision_site
*psite
=
97 vision_site_new(pcity
->id
, city_tile(pcity
), city_owner(pcity
));
99 vision_site_size_set(psite
, city_size_get(pcity
));
100 sz_strlcpy(psite
->name
, city_name_get(pcity
));
105 /****************************************************************************
106 Returns the basic structure filled with current elements.
107 ****************************************************************************/
108 void vision_site_update_from_city(struct vision_site
*psite
,
109 const struct city
*pcity
)
111 /* should be same identity and location */
112 fc_assert_ret(psite
->identity
== pcity
->id
);
113 fc_assert_ret(psite
->location
== pcity
->tile
);
115 psite
->owner
= city_owner(pcity
);
117 vision_site_size_set(psite
, city_size_get(pcity
));
118 sz_strlcpy(psite
->name
, city_name_get(pcity
));
121 /*****************************************************************************
123 *****************************************************************************/
124 citizens
vision_site_size_get(const struct vision_site
*psite
)
126 fc_assert_ret_val(psite
!= NULL
, 0);
131 /*****************************************************************************
133 *****************************************************************************/
134 void vision_site_size_set(struct vision_site
*psite
, citizens size
)
136 fc_assert_ret(psite
!= NULL
);