Freeciv-3.1: /fast/freeciv/nightly/S3_1/tools/ruledit/validity.c Source File

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
33 struct effect_list_cb_data
34{
35 bool needed;
36 struct universal *uni;
37 requirers_cb cb;
38 void *requirers_data;
39};
40
41/**********************************************************************/
44 static 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/**********************************************************************/
61 static bool is_universal_needed(struct universal *uni, requirers_cb cb,
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
69 disaster_type_iterate(pdis) {
70 if (universal_is_mentioned_by_requirements(&pdis->reqs, uni)) {
71 cb(disaster_rule_name(pdis), data);
72 needed = TRUE;
73 }
74 } disaster_type_iterate_end;
75
76 improvement_re_active_iterate(pimprove) {
77 if (universal_is_mentioned_by_requirements(&pimprove->reqs, uni)
78 || universal_is_mentioned_by_requirements(&pimprove->obsolete_by,
79 uni)) {
80 cb(improvement_rule_name(pimprove), data);
81 needed = TRUE;
82 }
83 } improvement_re_active_iterate_end;
84
85 governments_re_active_iterate(pgov) {
86 if (universal_is_mentioned_by_requirements(&pgov->reqs, uni)) {
87 cb(government_rule_name(pgov), data);
88 needed = TRUE;
89 }
90 } governments_re_active_iterate_end;
91
92 specialist_type_re_active_iterate(psp) {
93 if (universal_is_mentioned_by_requirements(&psp->reqs, uni)) {
94 cb(specialist_rule_name(psp), data);
95 needed = TRUE;
96 }
97 } specialist_type_re_active_iterate_end;
98
99 extra_type_re_active_iterate(pextra) {
100 if (universal_is_mentioned_by_requirements(&pextra->reqs, uni)
101 || universal_is_mentioned_by_requirements(&pextra->rmreqs, uni)
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 }
115 } extra_type_re_active_iterate_end;
116
117 goods_type_re_active_iterate(pgood) {
118 if (universal_is_mentioned_by_requirements(&pgood->reqs, uni)) {
119 cb(goods_rule_name(pgood), data);
120 needed = TRUE;
121 }
122 } goods_type_re_active_iterate_end;
123
124 action_iterate(act) {
125 action_enabler_list_re_iterate(action_enablers_for_action(act), enabler) {
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 }
137 } action_enabler_list_re_iterate_end;
138 } action_iterate_end;
139
140 for (i = 0; i < game.control.styles_count; i++) {
141 if (universal_is_mentioned_by_requirements(&city_styles[i].reqs, uni)) {
142 cb(city_style_rule_name(i), data);
143 needed = TRUE;
144 }
145 }
146
147 music_styles_iterate(pmus) {
148 if (universal_is_mentioned_by_requirements(&pmus->reqs, uni)) {
149 needed_by_music_style = TRUE;
150 }
151 } music_styles_iterate_end;
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) {
162 if (universal_is_mentioned_by_requirements(&info->giver_reqs, uni)
163 || universal_is_mentioned_by_requirements(&info->receiver_reqs, uni)) {
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
180 iterate_effect_cache(effect_list_universal_needed_cb, &cb_data);
181 needed |= cb_data.needed;
182
183 return needed;
184}
185
186/**********************************************************************/
189 bool 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 }
201 } advance_re_active_iterate_end;
202
203 unit_type_re_active_iterate(ptype) {
204 if (ptype->require_advance == padv) {
205 cb(utype_rule_name(ptype), data);
206 needed = TRUE;
207 }
208 } unit_type_re_active_iterate_end;
209
210 extra_type_re_active_iterate(pextra) {
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 }
218 } extra_type_re_active_iterate_end;
219
220 needed |= is_universal_needed(&uni, cb, data);
221
222 return needed;
223}
224
225/**********************************************************************/
228 bool is_building_needed(struct impr_type *pimpr, requirers_cb cb,
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/**********************************************************************/
242 bool is_utype_needed(struct unit_type *ptype, requirers_cb cb,
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
250 terrain_re_active_iterate(pterr) {
251 if (pterr->animal == ptype) {
252 cb(terrain_rule_name(pterr), data);
253 needed = TRUE;
254 }
255 } terrain_re_active_iterate_end;
256
257 return needed;
258}
259
260/**********************************************************************/
263 bool is_achievement_needed(struct achievement *pach, requirers_cb cb,
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/**********************************************************************/
277 bool is_good_needed(struct goods_type *pgood, requirers_cb cb,
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/**********************************************************************/
291 bool is_extra_needed(struct extra_type *pextra, requirers_cb cb,
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
300 extra_type_re_active_iterate(requirer) {
301 conflicts |= BV_ISSET(requirer->conflicts, id);
302 hides |= BV_ISSET(requirer->hidden_by, id);
303 } extra_type_re_active_iterate_end;
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/**********************************************************************/
321 bool 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
328 terrain_re_active_iterate(pother) {
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 }
340 } terrain_re_active_iterate_end;
341
342 return needed;
343}
344
345/**********************************************************************/
348 bool 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
358 struct effect_list_multiplier_data
359{
360 bool needed;
361 struct multiplier *pmul;
362 requirers_cb cb;
363 void *requirers_data;
364};
365
366/**********************************************************************/
369 static 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/**********************************************************************/
386 bool is_multiplier_needed(struct multiplier *pmul, requirers_cb cb, void *data)
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
396 iterate_effect_cache(effect_list_multiplier_cb, &cb_data);
397 needed |= cb_data.needed;
398
399 return needed;
400}
action_id_rule_name
const char * action_id_rule_name(action_id act_id)
Definition actions.c:1899
action_enablers_for_action
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:2475
action_enabler_list_re_iterate_end
#define action_enabler_list_re_iterate_end
Definition actions.h:463
action_enabler_list_re_iterate
#define action_enabler_list_re_iterate(action_enabler_list, aenabler)
Definition actions.h:459
action_iterate_end
#define action_iterate_end
Definition actions.h:472
action_iterate
#define action_iterate(_act_)
Definition actions.h:467
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
city_styles
struct citystyle * city_styles
Definition city.c:79
city_style_rule_name
const char * city_style_rule_name(const int style)
Definition city.c:1734
clause_info_get
struct clause_info * clause_info_get(enum clause_type type)
Definition diptreaty.c:273
disaster_rule_name
const char * disaster_rule_name(struct disaster_type *pdis)
Definition disaster.c:105
disaster.h
disaster_type_iterate
#define disaster_type_iterate(_p)
Definition disaster.h:80
disaster_type_iterate_end
#define disaster_type_iterate_end
Definition disaster.h:86
reqs
struct @21::@22 reqs
iterate_effect_cache
bool iterate_effect_cache(iec_cb cb, void *data)
Definition effects.c:1245
extra_rule_name
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:195
extra_index
#define extra_index(_e_)
Definition extras.h:177
extra_type_re_active_iterate_end
#define extra_type_re_active_iterate_end
Definition extras.h:305
extra_road_get
#define extra_road_get(_e_)
Definition extras.h:185
extra_type_re_active_iterate
#define extra_type_re_active_iterate(_p)
Definition extras.h:301
R__
#define R__(String)
Definition fcintl.h:75
game
struct civ_game game
Definition game.c:57
game.h
government_rule_name
const char * government_rule_name(const struct government *pgovern)
Definition government.c:132
government.h
governments_re_active_iterate
#define governments_re_active_iterate(_p)
Definition government.h:125
governments_re_active_iterate_end
#define governments_re_active_iterate_end
Definition government.h:129
improvement_rule_name
const char * improvement_rule_name(const struct impr_type *pimprove)
Definition improvement.c:250
improvement.h
improvement_re_active_iterate_end
#define improvement_re_active_iterate_end
Definition improvement.h:220
improvement_re_active_iterate
#define improvement_re_active_iterate(_p)
Definition improvement.h:216
universal_is_mentioned_by_requirements
bool universal_is_mentioned_by_requirements(const struct requirement_vector *reqs, const struct universal *psource)
Definition requirements.c:5858
requirements.h
specialist_rule_name
const char * specialist_rule_name(const struct specialist *sp)
Definition specialist.c:146
specialist.h
specialist_type_re_active_iterate_end
#define specialist_type_re_active_iterate_end
Definition specialist.h:88
specialist_type_re_active_iterate
#define specialist_type_re_active_iterate(_p)
Definition specialist.h:83
achievement
Definition achievements.h:26
advance
Definition tech.h:124
advance::require
struct advance * require[AR_SIZE]
Definition tech.h:132
civ_game::control
struct packet_ruleset_control control
Definition game.h:83
clause_info
Definition diptreaty.h:53
clause_info::receiver_reqs
struct requirement_vector receiver_reqs
Definition diptreaty.h:57
clause_info::giver_reqs
struct requirement_vector giver_reqs
Definition diptreaty.h:56
clause_info::type
enum clause_type type
Definition diptreaty.h:54
clause_info::enabled
bool enabled
Definition diptreaty.h:55
effect_list_cb_data
Definition validity.c:34
effect_list_cb_data::requirers_data
void * requirers_data
Definition validity.c:38
effect_list_cb_data::cb
requirers_cb cb
Definition validity.c:37
effect_list_cb_data::needed
bool needed
Definition validity.c:35
effect_list_cb_data::uni
struct universal * uni
Definition validity.c:36
effect_list_multiplier_data
Definition validity.c:359
effect_list_multiplier_data::needed
bool needed
Definition validity.c:360
effect_list_multiplier_data::requirers_data
void * requirers_data
Definition validity.c:363
effect_list_multiplier_data::cb
requirers_cb cb
Definition validity.c:362
effect_list_multiplier_data::pmul
struct multiplier * pmul
Definition validity.c:361
effect
Definition effects.h:340
effect::multiplier
struct multiplier * multiplier
Definition effects.h:344
effect::reqs
struct requirement_vector reqs
Definition effects.h:353
extra_type
Definition extras.h:85
goods_type
Definition traderoutes.h:180
government
Definition government.h:52
impr_type
Definition improvement.h:68
multiplier
Definition multipliers.h:31
packet_ruleset_control::styles_count
int styles_count
Definition packets_gen.h:1472
road_type
Definition road.h:75
road_type::first_reqs
struct requirement_vector first_reqs
Definition road.h:86
terrain
Definition terrain.h:176
terrain::cooler_wetter_result
struct terrain * cooler_wetter_result
Definition terrain.h:227
terrain::cooler_drier_result
struct terrain * cooler_drier_result
Definition terrain.h:227
terrain::warmer_wetter_result
struct terrain * warmer_wetter_result
Definition terrain.h:226
terrain::plant_result
struct terrain * plant_result
Definition terrain.h:206
terrain::warmer_drier_result
struct terrain * warmer_drier_result
Definition terrain.h:226
terrain::transform_result
struct terrain * transform_result
Definition terrain.h:217
unit_type
Definition unittype.h:481
universal
Definition fc_types.h:756
universal::value
universals_u value
Definition fc_types.h:757
style.h
music_styles_iterate
#define music_styles_iterate(_p)
Definition style.h:72
music_styles_iterate_end
#define music_styles_iterate_end
Definition style.h:79
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
support.h
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
advance_rule_name
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:299
advance_number
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
tech.h
advance_re_active_iterate
#define advance_re_active_iterate(_p)
Definition tech.h:275
AR_TWO
@ AR_TWO
Definition tech.h:112
AR_ROOT
@ AR_ROOT
Definition tech.h:113
AR_ONE
@ AR_ONE
Definition tech.h:111
advance_re_active_iterate_end
#define advance_re_active_iterate_end
Definition tech.h:279
terrain_rule_name
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:235
terrain_re_active_iterate_end
#define terrain_re_active_iterate_end
Definition terrain.h:373
terrain_re_active_iterate
#define terrain_re_active_iterate(_p)
Definition terrain.h:369
goods_rule_name
const char * goods_rule_name(struct goods_type *pgood)
Definition traderoutes.c:620
goods_type_re_active_iterate_end
#define goods_type_re_active_iterate_end
Definition traderoutes.h:231
goods_type_re_active_iterate
#define goods_type_re_active_iterate(_p)
Definition traderoutes.h:227
universals_u::utype
const struct unit_type * utype
Definition fc_types.h:604
universals_u::extra
struct extra_type * extra
Definition fc_types.h:605
universals_u::govern
struct government * govern
Definition fc_types.h:597
universals_u::building
const struct impr_type * building
Definition fc_types.h:598
universals_u::achievement
struct achievement * achievement
Definition fc_types.h:606
universals_u::advance
struct advance * advance
Definition fc_types.h:596
universals_u::good
struct goods_type * good
Definition fc_types.h:610
universals_u::terrain
struct terrain * terrain
Definition fc_types.h:602
utype_rule_name
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1630
unit_type_re_active_iterate
#define unit_type_re_active_iterate(_p)
Definition unittype.h:850
unit_type_re_active_iterate_end
#define unit_type_re_active_iterate_end
Definition unittype.h:854
is_universal_needed
static bool is_universal_needed(struct universal *uni, requirers_cb cb, void *data)
Definition validity.c:61
is_achievement_needed
bool is_achievement_needed(struct achievement *pach, requirers_cb cb, void *data)
Definition validity.c:263
is_multiplier_needed
bool is_multiplier_needed(struct multiplier *pmul, requirers_cb cb, void *data)
Definition validity.c:386
is_tech_needed
bool is_tech_needed(struct advance *padv, requirers_cb cb, void *data)
Definition validity.c:189
effect_list_multiplier_cb
static bool effect_list_multiplier_cb(struct effect *peffect, void *data)
Definition validity.c:369
is_terrain_needed
bool is_terrain_needed(struct terrain *pterr, requirers_cb cb, void *data)
Definition validity.c:321
is_good_needed
bool is_good_needed(struct goods_type *pgood, requirers_cb cb, void *data)
Definition validity.c:277
is_government_needed
bool is_government_needed(struct government *pgov, requirers_cb cb, void *data)
Definition validity.c:348
effect_list_universal_needed_cb
static bool effect_list_universal_needed_cb(struct effect *peffect, void *data)
Definition validity.c:44
is_utype_needed
bool is_utype_needed(struct unit_type *ptype, requirers_cb cb, void *data)
Definition validity.c:242
is_extra_needed
bool is_extra_needed(struct extra_type *pextra, requirers_cb cb, void *data)
Definition validity.c:291
is_building_needed
bool is_building_needed(struct impr_type *pimpr, requirers_cb cb, void *data)
Definition validity.c:228
validity.h
requirers_cb
void(* requirers_cb)(const char *msg, void *data)
Definition validity.h:20