Freeciv-3.2
Loading...
Searching...
No Matches
validity.c
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
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "support.h"
20
21/* common */
22#include "disaster.h"
23#include "game.h"
24#include "government.h"
25#include "improvement.h"
26#include "requirements.h"
27#include "specialist.h"
28#include "style.h"
29#include "tech.h"
30
31#include "validity.h"
32
40
41/**********************************************************************/
45 void *data)
46{
47 struct effect_list_cb_data *cbdata = (struct effect_list_cb_data *)data;
48
50 cbdata->cb(R__("Effect"), cbdata->requirers_data);
51 cbdata->needed = TRUE;
52 }
53
54 /* Always continue to next until all effects checked */
55 return TRUE;
56}
57
58/**********************************************************************/
62 void *data)
63{
64 bool needed = FALSE;
66 int i;
68
72 needed = TRUE;
73 }
75
78 || universal_is_mentioned_by_requirements(&pimprove->obsolete_by,
79 uni)) {
80 cb(improvement_rule_name(pimprove), data);
81 needed = TRUE;
82 }
84
88 needed = TRUE;
89 }
91
94 cb(specialist_rule_name(psp), data);
95 needed = TRUE;
96 }
98
102 || universal_is_mentioned_by_requirements(&pextra->appearance_reqs, uni)
103 || universal_is_mentioned_by_requirements(&pextra->disappearance_reqs, uni)) {
104 cb(extra_rule_name(pextra), data);
105 needed = TRUE;
106 } else {
107 struct road_type *proad = extra_road_get(pextra);
108
109 if (proad != NULL
110 && universal_is_mentioned_by_requirements(&proad->first_reqs, uni)) {
111 cb(extra_rule_name(pextra), data);
112 needed = TRUE;
113 }
114 }
116
119 cb(goods_rule_name(pgood), data);
120 needed = TRUE;
121 }
123
124 action_iterate(act) {
127 uni)
129 uni)) {
130 char buf[1024];
131
132 fc_snprintf(buf, sizeof(buf), R__("%s action enabler"),
134 cb(buf, data);
135 needed = TRUE;
136 }
139
140 for (i = 0; i < game.control.num_city_styles; i++) {
142 cb(city_style_rule_name(i), data);
143 needed = TRUE;
144 }
145 }
146
150 }
152
154 cb(R__("Music Style"), data);
155 needed = TRUE;
156 }
157
158 for (i = 0; i < CLAUSE_COUNT; i++) {
159 struct clause_info *info = clause_info_get(i);
160
161 if (info->enabled) {
164 char buf[1024];
165
166 /* TRANS: e.g. "Advance clause" */
167 fc_snprintf(buf, sizeof(buf), R__("%s clause"),
168 clause_type_name(info->type));
169 cb(buf, data);
170 needed = TRUE;
171 }
172 }
173 }
174
175 cb_data.needed = FALSE;
176 cb_data.uni = uni;
177 cb_data.cb = cb;
178 cb_data.requirers_data = data;
179
181 needed |= cb_data.needed;
182
183 return needed;
184}
185
186/**********************************************************************/
189bool is_counter_needed(struct counter *pcount, requirers_cb cb, void *data)
190{
191 struct universal uni = { .value.counter = pcount, .kind = VUT_COUNTER };
192
193 return is_universal_needed(&uni, cb, data);
194}
195
196/**********************************************************************/
199bool is_tech_needed(struct advance *padv, requirers_cb cb, void *data)
200{
201 struct universal uni = { .value.advance = padv, .kind = VUT_ADVANCE };
202 bool needed = FALSE;
203
205 if (pdependant->require[AR_ONE] == padv
206 || pdependant->require[AR_TWO] == padv
207 || pdependant->require[AR_ROOT] == padv) {
208 cb(advance_rule_name(pdependant), data);
209 needed = TRUE;
210 }
212
215 cb(utype_rule_name(ptype), data);
216 needed = TRUE;
217 }
219
221 if (pextra->visibility_req == advance_number(padv)) {
222 char buf[512];
223
224 fc_snprintf(buf, sizeof(buf), "%s visibility",
225 extra_rule_name(pextra));
226 cb(buf, data);
227 }
229
230 needed |= is_universal_needed(&uni, cb, data);
231
232 return needed;
233}
234
235/**********************************************************************/
239 void *data)
240{
241 struct universal uni = { .value.building = pimpr, .kind = VUT_IMPROVEMENT };
242 bool needed = FALSE;
243
244 needed |= is_universal_needed(&uni, cb, data);
245
246 return needed;
247}
248
249/**********************************************************************/
253 void *data)
254{
255 struct universal uni = { .value.utype = ptype, .kind = VUT_UTYPE };
256 bool needed = FALSE;
257
258 needed |= is_universal_needed(&uni, cb, data);
259
261 if (pterr->animal == ptype) {
262 cb(terrain_rule_name(pterr), data);
263 needed = TRUE;
264 }
266
267 return needed;
268}
269
270/**********************************************************************/
274 void *data)
275{
276 struct universal uni = { .value.achievement = pach, .kind = VUT_ACHIEVEMENT };
277 bool needed = FALSE;
278
279 needed |= is_universal_needed(&uni, cb, data);
280
281 return needed;
282}
283
284/**********************************************************************/
288 void *data)
289{
290 struct universal uni = { .value.good = pgood, .kind = VUT_GOOD };
291 bool needed = FALSE;
292
293 needed |= is_universal_needed(&uni, cb, data);
294
295 return needed;
296}
297
298/**********************************************************************/
302 void *data)
303{
304 struct universal uni = { .value.extra = pextra, .kind = VUT_EXTRA };
305 bool needed = FALSE;
306 bool conflicts = FALSE;
307 bool hides = FALSE;
308 int id = extra_index(pextra);
309
311 conflicts |= BV_ISSET(requirer->conflicts, id);
312 hides |= BV_ISSET(requirer->hidden_by, id);
314
315 if (conflicts) {
316 cb(R__("Conflicting extra"), data);
317 }
318 if (hides) {
319 cb(R__("Hidden extra"), data);
320 }
321 needed |= conflicts | hides;
322
323 needed |= is_universal_needed(&uni, cb, data);
324
325 return needed;
326}
327
328/**********************************************************************/
331bool is_terrain_needed(struct terrain *pterr, requirers_cb cb, void *data)
332{
333 struct universal uni = { .value.terrain = pterr, .kind = VUT_TERRAIN };
334 bool needed = FALSE;
335
336 needed |= is_universal_needed(&uni, cb, data);
337
339 if (pother != pterr
340 && (pother->cultivate_result == pterr
341 || pother->plant_result == pterr
342 || pother->transform_result == pterr
343 || pother->warmer_wetter_result == pterr
344 || pother->warmer_drier_result == pterr
345 || pother->cooler_wetter_result == pterr
346 || pother->cooler_drier_result == pterr)) {
347 cb(terrain_rule_name(pother), data);
348 needed = TRUE;
349 }
351
352 return needed;
353}
354
355/**********************************************************************/
359{
360 struct universal uni = { .value.govern = pgov, .kind = VUT_GOVERNMENT };
361 bool needed = FALSE;
362
363 needed |= is_universal_needed(&uni, cb, data);
364
365 return needed;
366}
367
375
376/**********************************************************************/
380 void *data)
381{
383
384 if (peffect->multiplier == cbdata->pmul) {
385 cbdata->cb(R__("Effect"), cbdata->requirers_data);
386 cbdata->needed = TRUE;
387 }
388
389 /* Always continue to next until all effects checked */
390 return TRUE;
391}
392
393/**********************************************************************/
397{
399 bool needed = FALSE;
400
402 cb_data.pmul = pmul;
403 cb_data.cb = cb;
404 cb_data.requirers_data = data;
405
407 needed |= cb_data.needed;
408
409 return needed;
410}
const char * action_rule_name(const struct action *action)
Definition actions.c:1977
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:2315
#define enabler_get_action(_enabler_)
Definition actions.h:433
#define action_enabler_list_re_iterate_end
Definition actions.h:447
#define action_enabler_list_re_iterate(action_enabler_list, aenabler)
Definition actions.h:443
#define action_iterate_end
Definition actions.h:465
#define action_iterate(_act_)
Definition actions.h:461
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
const char * city_style_rule_name(const int style)
Definition city.c:1765
static const struct city struct citystyle * city_styles
Definition city.c:84
char * incite_cost
Definition comments.c:75
struct clause_info * clause_info_get(enum clause_type type)
Definition diptreaty.c:276
const char * disaster_rule_name(struct disaster_type *pdis)
Definition disaster.c:105
#define disaster_type_iterate(_p)
Definition disaster.h:80
#define disaster_type_iterate_end
Definition disaster.h:86
struct @21::@22 reqs
bool iterate_effect_cache(iec_cb cb, void *data)
Definition effects.c:1323
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:203
#define extra_index(_e_)
Definition extras.h:183
#define extra_type_re_active_iterate_end
Definition extras.h:329
#define extra_road_get(_e_)
Definition extras.h:191
#define extra_type_re_active_iterate(_p)
Definition extras.h:325
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:62
const char * government_rule_name(const struct government *pgovern)
Definition government.c:133
#define governments_re_active_iterate(_p)
Definition government.h:129
#define governments_re_active_iterate_end
Definition government.h:133
const char * improvement_rule_name(const struct impr_type *pimprove)
#define improvement_re_active_iterate_end
#define improvement_re_active_iterate(_p)
bool universal_is_mentioned_by_requirements(const struct requirement_vector *reqs, const struct universal *psource)
const char * specialist_rule_name(const struct specialist *sp)
Definition specialist.c:146
#define specialist_type_re_active_iterate_end
Definition specialist.h:88
#define specialist_type_re_active_iterate(_p)
Definition specialist.h:83
struct packet_ruleset_control control
Definition game.h:83
struct requirement_vector receiver_reqs
Definition diptreaty.h:59
struct requirement_vector giver_reqs
Definition diptreaty.h:58
enum clause_type type
Definition diptreaty.h:56
bool enabled
Definition diptreaty.h:57
void * requirers_data
Definition validity.c:38
requirers_cb cb
Definition validity.c:37
struct universal * uni
Definition validity.c:36
struct multiplier * pmul
Definition validity.c:371
universals_u value
Definition fc_types.h:901
#define music_styles_iterate(_p)
Definition style.h:72
#define music_styles_iterate_end
Definition style.h:79
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:299
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
#define advance_re_active_iterate(_p)
Definition tech.h:281
@ AR_TWO
Definition tech.h:112
@ AR_ROOT
Definition tech.h:113
@ AR_ONE
Definition tech.h:111
#define advance_re_active_iterate_end
Definition tech.h:285
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:247
#define terrain_re_active_iterate_end
Definition terrain.h:388
#define terrain_re_active_iterate(_p)
Definition terrain.h:384
const char * goods_rule_name(struct goods_type *pgood)
#define goods_type_re_active_iterate_end
#define goods_type_re_active_iterate(_p)
const struct unit_type * utype
Definition fc_types.h:721
struct extra_type * extra
Definition fc_types.h:722
struct government * govern
Definition fc_types.h:713
const struct impr_type * building
Definition fc_types.h:714
struct achievement * achievement
Definition fc_types.h:723
struct advance * advance
Definition fc_types.h:711
struct goods_type * good
Definition fc_types.h:727
struct terrain * terrain
Definition fc_types.h:719
struct counter * counter
Definition fc_types.h:712
bool is_tech_req_for_utype(const struct unit_type *ptype, struct advance *padv)
Definition unittype.c:2724
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
#define unit_type_re_active_iterate(_p)
Definition unittype.h:867
#define unit_type_re_active_iterate_end
Definition unittype.h:871
static bool is_universal_needed(struct universal *uni, requirers_cb cb, void *data)
Definition validity.c:61
bool is_achievement_needed(struct achievement *pach, requirers_cb cb, void *data)
Definition validity.c:273
bool is_multiplier_needed(struct multiplier *pmul, requirers_cb cb, void *data)
Definition validity.c:396
bool is_counter_needed(struct counter *pcount, requirers_cb cb, void *data)
Definition validity.c:189
bool is_tech_needed(struct advance *padv, requirers_cb cb, void *data)
Definition validity.c:199
static bool effect_list_multiplier_cb(struct effect *peffect, void *data)
Definition validity.c:379
bool is_terrain_needed(struct terrain *pterr, requirers_cb cb, void *data)
Definition validity.c:331
bool is_good_needed(struct goods_type *pgood, requirers_cb cb, void *data)
Definition validity.c:287
bool is_government_needed(struct government *pgov, requirers_cb cb, void *data)
Definition validity.c:358
static bool effect_list_universal_needed_cb(struct effect *peffect, void *data)
Definition validity.c:44
bool is_utype_needed(struct unit_type *ptype, requirers_cb cb, void *data)
Definition validity.c:252
bool is_extra_needed(struct extra_type *pextra, requirers_cb cb, void *data)
Definition validity.c:301
bool is_building_needed(struct impr_type *pimpr, requirers_cb cb, void *data)
Definition validity.c:238
void(* requirers_cb)(const char *msg, void *data)
Definition validity.h:20