Freeciv-3.1
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/**********************************************************************/
44static bool effect_list_universal_needed_cb(struct effect *peffect,
45 void *data)
46{
47 struct effect_list_cb_data *cbdata = (struct effect_list_cb_data *)data;
48
49 if (universal_is_mentioned_by_requirements(&peffect->reqs, cbdata->uni)) {
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;
65 bool needed_by_music_style = FALSE;
66 int i;
67 struct effect_list_cb_data cb_data;
68
71 cb(disaster_rule_name(pdis), data);
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
87 cb(government_rule_name(pgov), data);
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
111 cb(extra_rule_name(pextra), data);
112 needed = TRUE;
113 }
114 }
116
118 if (universal_is_mentioned_by_requirements(&pgood->reqs, uni)) {
119 cb(goods_rule_name(pgood), data);
120 needed = TRUE;
121 }
123
124 action_iterate(act) {
126 if (universal_is_mentioned_by_requirements(&(enabler->actor_reqs),
127 uni)
128 || universal_is_mentioned_by_requirements(&(enabler->target_reqs),
129 uni)) {
130 char buf[1024];
131
132 fc_snprintf(buf, sizeof(buf), R__("%s action enabler"),
133 action_id_rule_name(enabler->action));
134 cb(buf, data);
135 needed = TRUE;
136 }
139
140 for (i = 0; i < game.control.styles_count; i++) {
142 cb(city_style_rule_name(i), data);
143 needed = TRUE;
144 }
145 }
146
148 if (universal_is_mentioned_by_requirements(&pmus->reqs, uni)) {
149 needed_by_music_style = TRUE;
150 }
152
153 if (needed_by_music_style) {
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_tech_needed(struct advance *padv, requirers_cb cb, void *data)
190{
191 struct universal uni = { .value.advance = padv, .kind = VUT_ADVANCE };
192 bool needed = FALSE;
193
194 advance_re_active_iterate(pdependant) {
195 if (pdependant->require[AR_ONE] == padv
196 || pdependant->require[AR_TWO] == padv
197 || pdependant->require[AR_ROOT] == padv) {
198 cb(advance_rule_name(pdependant), data);
199 needed = TRUE;
200 }
202
204 if (ptype->require_advance == padv) {
205 cb(utype_rule_name(ptype), data);
206 needed = TRUE;
207 }
209
211 if (pextra->visibility_req == advance_number(padv)) {
212 char buf[512];
213
214 fc_snprintf(buf, sizeof(buf), "%s visibility",
215 extra_rule_name(pextra));
216 cb(buf, data);
217 }
219
220 needed |= is_universal_needed(&uni, cb, data);
221
222 return needed;
223}
224
225/**********************************************************************/
229 void *data)
230{
231 struct universal uni = { .value.building = pimpr, .kind = VUT_IMPROVEMENT };
232 bool needed = FALSE;
233
234 needed |= is_universal_needed(&uni, cb, data);
235
236 return needed;
237}
238
239/**********************************************************************/
243 void *data)
244{
245 struct universal uni = { .value.utype = ptype, .kind = VUT_UTYPE };
246 bool needed = FALSE;
247
248 needed |= is_universal_needed(&uni, cb, data);
249
251 if (pterr->animal == ptype) {
252 cb(terrain_rule_name(pterr), data);
253 needed = TRUE;
254 }
256
257 return needed;
258}
259
260/**********************************************************************/
264 void *data)
265{
266 struct universal uni = { .value.achievement = pach, .kind = VUT_ACHIEVEMENT };
267 bool needed = FALSE;
268
269 needed |= is_universal_needed(&uni, cb, data);
270
271 return needed;
272}
273
274/**********************************************************************/
278 void *data)
279{
280 struct universal uni = { .value.good = pgood, .kind = VUT_GOOD };
281 bool needed = FALSE;
282
283 needed |= is_universal_needed(&uni, cb, data);
284
285 return needed;
286}
287
288/**********************************************************************/
292 void *data)
293{
294 struct universal uni = { .value.extra = pextra, .kind = VUT_EXTRA };
295 bool needed = FALSE;
296 bool conflicts = FALSE;
297 bool hides = FALSE;
298 int id = extra_index(pextra);
299
301 conflicts |= BV_ISSET(requirer->conflicts, id);
302 hides |= BV_ISSET(requirer->hidden_by, id);
304
305 if (conflicts) {
306 cb(R__("Conflicting extra"), data);
307 }
308 if (hides) {
309 cb(R__("Hidden extra"), data);
310 }
311 needed |= conflicts | hides;
312
313 needed |= is_universal_needed(&uni, cb, data);
314
315 return needed;
316}
317
318/**********************************************************************/
321bool is_terrain_needed(struct terrain *pterr, requirers_cb cb, void *data)
322{
323 struct universal uni = { .value.terrain = pterr, .kind = VUT_TERRAIN };
324 bool needed = FALSE;
325
326 needed |= is_universal_needed(&uni, cb, data);
327
329 if (pother != pterr
330 && (pother->cultivate_result == pterr
331 || pother->plant_result == pterr
332 || pother->transform_result == pterr
333 || pother->warmer_wetter_result == pterr
334 || pother->warmer_drier_result == pterr
335 || pother->cooler_wetter_result == pterr
336 || pother->cooler_drier_result == pterr)) {
337 cb(terrain_rule_name(pother), data);
338 needed = TRUE;
339 }
341
342 return needed;
343}
344
345/**********************************************************************/
348bool is_government_needed(struct government *pgov, requirers_cb cb, void *data)
349{
350 struct universal uni = { .value.govern = pgov, .kind = VUT_GOVERNMENT };
351 bool needed = FALSE;
352
353 needed |= is_universal_needed(&uni, cb, data);
354
355 return needed;
356}
357
365
366/**********************************************************************/
369static bool effect_list_multiplier_cb(struct effect *peffect,
370 void *data)
371{
372 struct effect_list_multiplier_data *cbdata = (struct effect_list_multiplier_data *)data;
373
374 if (peffect->multiplier == cbdata->pmul) {
375 cbdata->cb(R__("Effect"), cbdata->requirers_data);
376 cbdata->needed = TRUE;
377 }
378
379 /* Always continue to next until all effects checked */
380 return TRUE;
381}
382
383/**********************************************************************/
387{
388 struct effect_list_multiplier_data cb_data;
389 bool needed = FALSE;
390
391 cb_data.needed = FALSE;
392 cb_data.pmul = pmul;
393 cb_data.cb = cb;
394 cb_data.requirers_data = data;
395
397 needed |= cb_data.needed;
398
399 return needed;
400}
const char * action_id_rule_name(action_id act_id)
Definition actions.c:1899
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:2475
#define action_enabler_list_re_iterate_end
Definition actions.h:463
#define action_enabler_list_re_iterate(action_enabler_list, aenabler)
Definition actions.h:459
#define action_iterate_end
Definition actions.h:472
#define action_iterate(_act_)
Definition actions.h:467
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
struct citystyle * city_styles
Definition city.c:79
const char * city_style_rule_name(const int style)
Definition city.c:1738
struct clause_info * clause_info_get(enum clause_type type)
Definition diptreaty.c:273
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:1245
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:195
#define extra_index(_e_)
Definition extras.h:177
#define extra_type_re_active_iterate_end
Definition extras.h:305
#define extra_road_get(_e_)
Definition extras.h:185
#define extra_type_re_active_iterate(_p)
Definition extras.h:301
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:57
const char * government_rule_name(const struct government *pgovern)
Definition government.c:132
#define governments_re_active_iterate(_p)
Definition government.h:126
#define governments_re_active_iterate_end
Definition government.h:130
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 advance * require[AR_SIZE]
Definition tech.h:132
struct packet_ruleset_control control
Definition game.h:83
struct requirement_vector receiver_reqs
Definition diptreaty.h:57
struct requirement_vector giver_reqs
Definition diptreaty.h:56
enum clause_type type
Definition diptreaty.h:54
bool enabled
Definition diptreaty.h:55
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:361
struct multiplier * multiplier
Definition effects.h:344
struct requirement_vector reqs
Definition effects.h:353
struct requirement_vector first_reqs
Definition road.h:86
struct terrain * cooler_wetter_result
Definition terrain.h:227
struct terrain * cooler_drier_result
Definition terrain.h:227
struct terrain * warmer_wetter_result
Definition terrain.h:226
struct terrain * plant_result
Definition terrain.h:206
struct terrain * warmer_drier_result
Definition terrain.h:226
struct terrain * transform_result
Definition terrain.h:217
universals_u value
Definition fc_types.h:757
#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:969
#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:275
@ 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:279
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:235
#define terrain_re_active_iterate_end
Definition terrain.h:373
#define terrain_re_active_iterate(_p)
Definition terrain.h:369
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:604
struct extra_type * extra
Definition fc_types.h:605
struct government * govern
Definition fc_types.h:597
const struct impr_type * building
Definition fc_types.h:598
struct achievement * achievement
Definition fc_types.h:606
struct advance * advance
Definition fc_types.h:596
struct goods_type * good
Definition fc_types.h:610
struct terrain * terrain
Definition fc_types.h:602
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1630
#define unit_type_re_active_iterate(_p)
Definition unittype.h:853
#define unit_type_re_active_iterate_end
Definition unittype.h:857
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:263
bool is_multiplier_needed(struct multiplier *pmul, requirers_cb cb, void *data)
Definition validity.c:386
bool is_tech_needed(struct advance *padv, requirers_cb cb, void *data)
Definition validity.c:189
static bool effect_list_multiplier_cb(struct effect *peffect, void *data)
Definition validity.c:369
bool is_terrain_needed(struct terrain *pterr, requirers_cb cb, void *data)
Definition validity.c:321
bool is_good_needed(struct goods_type *pgood, requirers_cb cb, void *data)
Definition validity.c:277
bool is_government_needed(struct government *pgov, requirers_cb cb, void *data)
Definition validity.c:348
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:242
bool is_extra_needed(struct extra_type *pextra, requirers_cb cb, void *data)
Definition validity.c:291
bool is_building_needed(struct impr_type *pimpr, requirers_cb cb, void *data)
Definition validity.c:228
void(* requirers_cb)(const char *msg, void *data)
Definition validity.h:20