Freeciv-3.3: /fast/freeciv/nightly/main/tools/ruledit/validity.c Source File

Freeciv-3.3

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 != nullptr
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_rule_name(enabler_get_action(enabler)));
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.num_city_styles; 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_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/**********************************************************************/
199 bool 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
204 advance_re_active_iterate(pdependant) {
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 }
211 } advance_re_active_iterate_end;
212
213 unit_type_re_active_iterate(ptype) {
214 if (is_tech_req_for_utype(ptype, padv)) {
215 cb(utype_rule_name(ptype), data);
216 needed = TRUE;
217 }
218 } unit_type_re_active_iterate_end;
219
220 extra_type_re_active_iterate(pextra) {
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 }
228 } extra_type_re_active_iterate_end;
229
230 needed |= is_universal_needed(&uni, cb, data);
231
232 return needed;
233}
234
235/**********************************************************************/
238 bool is_building_needed(struct impr_type *pimpr, requirers_cb cb,
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/**********************************************************************/
252 bool is_utype_needed(struct unit_type *ptype, requirers_cb cb,
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
260 terrain_re_active_iterate(pterr) {
261 if (pterr->animal == ptype) {
262 cb(terrain_rule_name(pterr), data);
263 needed = TRUE;
264 }
265 } terrain_re_active_iterate_end;
266
267 return needed;
268}
269
270/**********************************************************************/
273 bool is_achievement_needed(struct achievement *pach, requirers_cb cb,
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/**********************************************************************/
287 bool is_good_needed(struct goods_type *pgood, requirers_cb cb,
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/**********************************************************************/
301 bool is_extra_needed(struct extra_type *pextra, requirers_cb cb,
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
310 extra_type_re_active_iterate(requirer) {
311 conflicts |= BV_ISSET(requirer->conflicts, id);
312 hides |= BV_ISSET(requirer->hidden_by, id);
313 } extra_type_re_active_iterate_end;
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/**********************************************************************/
331 bool 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
338 terrain_re_active_iterate(pother) {
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 }
350 } terrain_re_active_iterate_end;
351
352 return needed;
353}
354
355/**********************************************************************/
358 bool is_government_needed(struct government *pgov, requirers_cb cb, void *data)
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
368 struct effect_list_multiplier_data
369{
370 bool needed;
371 struct multiplier *pmul;
372 requirers_cb cb;
373 void *requirers_data;
374};
375
376/**********************************************************************/
379 static bool effect_list_multiplier_cb(struct effect *peffect,
380 void *data)
381{
382 struct effect_list_multiplier_data *cbdata = (struct effect_list_multiplier_data *)data;
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/**********************************************************************/
396 bool is_multiplier_needed(struct multiplier *pmul, requirers_cb cb, void *data)
397{
398 struct effect_list_multiplier_data cb_data;
399 bool needed = FALSE;
400
401 cb_data.needed = FALSE;
402 cb_data.pmul = pmul;
403 cb_data.cb = cb;
404 cb_data.requirers_data = data;
405
406 iterate_effect_cache(effect_list_multiplier_cb, &cb_data);
407 needed |= cb_data.needed;
408
409 return needed;
410}
action_rule_name
const char * action_rule_name(const struct action *action)
Definition actions.c:1181
action_enablers_for_action
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:1519
enabler_get_action
#define enabler_get_action(_enabler_)
Definition actions.h:177
action_enabler_list_re_iterate_end
#define action_enabler_list_re_iterate_end
Definition actions.h:191
action_enabler_list_re_iterate
#define action_enabler_list_re_iterate(action_enabler_list, aenabler)
Definition actions.h:187
action_iterate_end
#define action_iterate_end
Definition actions.h:209
action_iterate
#define action_iterate(_act_)
Definition actions.h:205
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
city_style_rule_name
const char * city_style_rule_name(const int style)
Definition city.c:1757
city_styles
static const struct city struct citystyle * city_styles
Definition city.c:83
incite_cost
char * incite_cost
Definition comments.c:74
clause_info_get
struct clause_info * clause_info_get(enum clause_type type)
Definition diptreaty.c:288
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:82
disaster_type_iterate_end
#define disaster_type_iterate_end
Definition disaster.h:88
reqs
struct @21::@22 reqs
iterate_effect_cache
bool iterate_effect_cache(iec_cb cb, void *data)
Definition effects.c:1323
extra_rule_name
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:203
extra_index
#define extra_index(_e_)
Definition extras.h:183
extra_type_re_active_iterate_end
#define extra_type_re_active_iterate_end
Definition extras.h:329
extra_road_get
#define extra_road_get(_e_)
Definition extras.h:191
extra_type_re_active_iterate
#define extra_type_re_active_iterate(_p)
Definition extras.h:325
R__
#define R__(String)
Definition fcintl.h:75
game
struct civ_game game
Definition game.c:62
game.h
government_rule_name
const char * government_rule_name(const struct government *pgovern)
Definition government.c:133
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:252
improvement.h
improvement_re_active_iterate_end
#define improvement_re_active_iterate_end
Definition improvement.h:214
improvement_re_active_iterate
#define improvement_re_active_iterate(_p)
Definition improvement.h:210
universal_is_mentioned_by_requirements
bool universal_is_mentioned_by_requirements(const struct requirement_vector *reqs, const struct universal *psource)
Definition requirements.c:7360
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
civ_game::control
struct packet_ruleset_control control
Definition game.h:83
clause_info
Definition diptreaty.h:55
clause_info::receiver_reqs
struct requirement_vector receiver_reqs
Definition diptreaty.h:59
clause_info::giver_reqs
struct requirement_vector giver_reqs
Definition diptreaty.h:58
clause_info::type
enum clause_type type
Definition diptreaty.h:56
clause_info::enabled
bool enabled
Definition diptreaty.h:57
counter
Definition counters.h:27
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:369
effect_list_multiplier_data::needed
bool needed
Definition validity.c:370
effect_list_multiplier_data::requirers_data
void * requirers_data
Definition validity.c:373
effect_list_multiplier_data::cb
requirers_cb cb
Definition validity.c:372
effect_list_multiplier_data::pmul
struct multiplier * pmul
Definition validity.c:371
effect
Definition effects.h:40
extra_type
Definition extras.h:88
goods_type
Definition traderoutes.h:187
government
Definition government.h:52
impr_type
Definition improvement.h:50
multiplier
Definition multipliers.h:31
packet_ruleset_control::num_city_styles
int num_city_styles
Definition packets_gen.h:1475
road_type
Definition road.h:71
terrain
Definition terrain.h:75
unit_type
Definition unittype.h:507
universal
Definition fc_types.h:908
universal::value
universals_u value
Definition fc_types.h:909
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:960
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:309
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:282
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:286
terrain_rule_name
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:247
terrain_re_active_iterate_end
#define terrain_re_active_iterate_end
Definition terrain.h:281
terrain_re_active_iterate
#define terrain_re_active_iterate(_p)
Definition terrain.h:277
goods_rule_name
const char * goods_rule_name(struct goods_type *pgood)
Definition traderoutes.c:633
goods_type_re_active_iterate_end
#define goods_type_re_active_iterate_end
Definition traderoutes.h:244
goods_type_re_active_iterate
#define goods_type_re_active_iterate(_p)
Definition traderoutes.h:240
universals_u::utype
const struct unit_type * utype
Definition fc_types.h:728
universals_u::extra
struct extra_type * extra
Definition fc_types.h:729
universals_u::govern
struct government * govern
Definition fc_types.h:720
universals_u::building
const struct impr_type * building
Definition fc_types.h:721
universals_u::achievement
struct achievement * achievement
Definition fc_types.h:730
universals_u::advance
struct advance * advance
Definition fc_types.h:718
universals_u::good
struct goods_type * good
Definition fc_types.h:734
universals_u::terrain
struct terrain * terrain
Definition fc_types.h:726
universals_u::counter
struct counter * counter
Definition fc_types.h:719
is_tech_req_for_utype
bool is_tech_req_for_utype(const struct unit_type *ptype, struct advance *padv)
Definition unittype.c:2710
utype_rule_name
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
unit_type_re_active_iterate
#define unit_type_re_active_iterate(_p)
Definition unittype.h:871
unit_type_re_active_iterate_end
#define unit_type_re_active_iterate_end
Definition unittype.h:875
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:273
is_multiplier_needed
bool is_multiplier_needed(struct multiplier *pmul, requirers_cb cb, void *data)
Definition validity.c:396
is_counter_needed
bool is_counter_needed(struct counter *pcount, requirers_cb cb, void *data)
Definition validity.c:189
is_tech_needed
bool is_tech_needed(struct advance *padv, requirers_cb cb, void *data)
Definition validity.c:199
effect_list_multiplier_cb
static bool effect_list_multiplier_cb(struct effect *peffect, void *data)
Definition validity.c:379
is_terrain_needed
bool is_terrain_needed(struct terrain *pterr, requirers_cb cb, void *data)
Definition validity.c:331
is_good_needed
bool is_good_needed(struct goods_type *pgood, requirers_cb cb, void *data)
Definition validity.c:287
is_government_needed
bool is_government_needed(struct government *pgov, requirers_cb cb, void *data)
Definition validity.c:358
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:252
is_extra_needed
bool is_extra_needed(struct extra_type *pextra, requirers_cb cb, void *data)
Definition validity.c:301
is_building_needed
bool is_building_needed(struct impr_type *pimpr, requirers_cb cb, void *data)
Definition validity.c:238
validity.h
requirers_cb
void(* requirers_cb)(const char *msg, void *data)
Definition validity.h:20