Freeciv-3.2
Loading...
Searching...
No Matches
univ_value.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/* common */
19#include "achievements.h"
20#include "counters.h"
21#include "game.h"
22#include "government.h"
23#include "nation.h"
24#include "requirements.h"
25#include "server_settings.h"
26#include "specialist.h"
27#include "tech.h"
28#include "traderoutes.h"
29
30/* server */
31#include "rssanity.h"
32#include "settings.h"
33
34#include "univ_value.h"
35
36/********************************************************************/
43{
44 switch (src->kind) {
45 case VUT_NONE:
46 /* Value of None should never be used */
47 return TRUE;
48 case VUT_ADVANCE:
49 if (game.control.num_tech_types <= 0) {
50 return FALSE;
51 }
53 return TRUE;
54 case VUT_COUNTER:
56 return FALSE;
57 }
59 return TRUE;
60 case VUT_GOVERNMENT:
62 return TRUE;
63 case VUT_IMPROVEMENT:
64 case VUT_SITE:
65 if (game.control.num_impr_types <= 0) {
66 return FALSE;
67 }
69 return TRUE;
70 case VUT_TERRAIN:
72 return TRUE;
73 case VUT_NATION:
74 if (game.control.nation_count <= 0) {
75 return FALSE;
76 }
78 return TRUE;
79 case VUT_UTYPE:
80 if (game.control.num_unit_types <= 0) {
81 return FALSE;
82 }
83 src->value.utype = utype_by_number(0);
84 return TRUE;
85 case VUT_UTFLAG:
86 src->value.unitflag = (enum unit_type_flag_id)0;
87 return TRUE;
88 case VUT_UCLASS:
89 if (game.control.num_unit_classes <= 0) {
90 return FALSE;
91 }
93 return TRUE;
94 case VUT_UCFLAG:
96 return TRUE;
97 case VUT_OTYPE:
98 src->value.outputtype = (enum output_type_id)0;
99 return TRUE;
100 case VUT_SPECIALIST:
102 return FALSE;
103 }
105 return TRUE;
106 case VUT_MINSIZE:
107 src->value.minsize = 0;
108 return TRUE;
109 case VUT_AI_LEVEL:
111 return TRUE;
112 case VUT_TERRAINCLASS:
114 return TRUE;
115 case VUT_MINYEAR:
116 src->value.minyear = 0;
117 return TRUE;
118 case VUT_MINCALFRAG:
119 src->value.mincalfrag = 0;
120 return TRUE;
121 case VUT_TERRAINALTER:
123 return TRUE;
124 case VUT_CITYTILE:
126 return TRUE;
127 case VUT_CITYSTATUS:
129 return TRUE;
130 case VUT_GOOD:
131 if (game.control.num_goods_types <= 0) {
132 return FALSE;
133 }
134 src->value.good = goods_by_number(0);
135 return TRUE;
136 case VUT_TERRFLAG:
138 return TRUE;
139 case VUT_NATIONALITY:
140 if (game.control.nation_count <= 0) {
141 return FALSE;
142 }
144 return TRUE;
146 if (game.control.nation_count <= 0) {
147 return FALSE;
148 }
150 return TRUE;
151 case VUT_ROADFLAG:
152 src->value.roadflag = RF_RIVER;
153 return TRUE;
154 case VUT_EXTRA:
155 if (game.control.num_extra_types <= 0) {
156 return FALSE;
157 }
158 src->value.extra = extra_by_number(0);
159 return TRUE;
160 case VUT_TECHFLAG:
162 return TRUE;
163 case VUT_ACHIEVEMENT:
165 return FALSE;
166 }
168 return TRUE;
169 case VUT_DIPLREL:
170 case VUT_DIPLREL_TILE:
174 src->value.diplrel = DS_WAR;
175 return TRUE;
176 case VUT_MAXTILEUNITS:
177 src->value.max_tile_units = 0;
178 return TRUE;
179 case VUT_STYLE:
180 if (game.control.num_styles <= 0) {
181 return FALSE;
182 }
183 src->value.style = style_by_number(0);
184 return TRUE;
185 case VUT_MINCULTURE:
186 src->value.minculture = 0;
187 return TRUE;
189 src->value.minforeignpct = 0;
190 return TRUE;
191 case VUT_UNITSTATE:
193 return TRUE;
194 case VUT_ACTIVITY:
196 return TRUE;
197 case VUT_MINMOVES:
198 src->value.minmoves = 0;
199 return TRUE;
200 case VUT_MINVETERAN:
201 src->value.minveteran = 0;
202 return TRUE;
203 case VUT_MINHP:
204 src->value.min_hit_points = 0;
205 return TRUE;
206 case VUT_AGE:
207 src->value.age = 0;
208 return TRUE;
209 case VUT_FORM_AGE:
210 src->value.form_age = 0;
211 return TRUE;
212 case VUT_NATIONGROUP:
213 if (nation_group_count() <= 0) {
214 return FALSE;
215 }
217 return TRUE;
218 case VUT_TOPO:
220 return TRUE;
221 case VUT_WRAP:
223 return TRUE;
225 src->value.ssetval
227 return TRUE;
228 case VUT_IMPR_GENUS:
230 return TRUE;
231 case VUT_IMPR_FLAG:
233 return TRUE;
234 case VUT_PLAYER_FLAG:
235 src->value.plr_flag = PLRF_AI;
236 return TRUE;
237 case VUT_PLAYER_STATE:
239 return TRUE;
240 case VUT_ACTION:
241 src->value.action = action_by_number(0);
242 return TRUE;
243 case VUT_MINTECHS:
244 src->value.min_techs = 0;
245 return TRUE;
246 case VUT_EXTRAFLAG:
248 return TRUE;
249 case VUT_MINLATITUDE:
250 case VUT_MAXLATITUDE:
251 src->value.latitude = 0;
252 return TRUE;
253 case VUT_COUNT:
254 fc_assert(src->kind != VUT_COUNT);
255 return FALSE;
256 }
257
258 return FALSE;
259}
260
261/********************************************************************/
265 univ_kind_values_cb cb, void *data)
266{
267 int i;
268
269 switch (univ->kind) {
270 case VUT_NONE:
271 break;
272 case VUT_ADVANCE:
274 cb(advance_rule_name(padv), univ->value.advance == padv, data);
276 break;
277 case VUT_COUNTER:
279 cb(counter_rule_name(pcount), univ->value.counter == pcount, data);
281 break;
282 case VUT_GOVERNMENT:
284 cb(government_rule_name(pgov), univ->value.govern == pgov, data);
286 break;
287 case VUT_IMPROVEMENT:
288 case VUT_SITE:
290 cb(improvement_rule_name(pimpr), univ->value.building == pimpr, data);
292 break;
293 case VUT_TERRAIN:
295 cb(terrain_rule_name(pterr), univ->value.terrain == pterr, data);
297 break;
298 case VUT_NATION:
300 cb(nation_rule_name(pnat), univ->value.nation == pnat, data);
302 break;
303 case VUT_UTYPE:
305 cb(utype_rule_name(putype), univ->value.utype == putype, data);
307 break;
308 case VUT_UCLASS:
310 cb(uclass_rule_name(pclass), univ->value.uclass == pclass, data);
312 break;
313 case VUT_OTYPE:
315 cb(get_output_name(otype), univ->value.outputtype == otype, data);
317 break;
318 case VUT_GOOD:
320 cb(goods_rule_name(pgood), univ->value.good == pgood, data);
322 break;
323 case VUT_NATIONALITY:
325 cb(nation_rule_name(pnat), univ->value.nationality == pnat, data);
327 break;
330 cb(nation_rule_name(pnat), univ->value.origowner == pnat, data);
332 break;
333 case VUT_EXTRA:
335 cb(extra_rule_name(pextra), univ->value.extra == pextra, data);
337 break;
338 case VUT_STYLE:
340 cb(style_rule_name(pstyle), univ->value.style == pstyle, data);
342 break;
343 case VUT_AI_LEVEL:
344 for (i = 0; i < AI_LEVEL_COUNT; i++) {
345 cb(ai_level_name(i), univ->value.ai_level == i, data);
346 }
347 break;
348 case VUT_SPECIALIST:
350 cb(specialist_rule_name(pspe), univ->value.specialist == pspe, data);
352 break;
353 case VUT_TERRAINCLASS:
354 for (i = 0; i < TC_COUNT; i++) {
355 cb(terrain_class_name(i), univ->value.terrainclass == i, data);
356 }
357 break;
358 case VUT_UTFLAG:
359 for (i = 0; i < UTYF_LAST_USER_FLAG; i++) {
360 cb(unit_type_flag_id_name(i), univ->value.unitflag == i, data);
361 }
362 break;
363 case VUT_UCFLAG:
364 for (i = 0; i < UCF_COUNT; i++) {
365 cb(unit_class_flag_id_name(i), univ->value.unitclassflag == i, data);
366 }
367 break;
368 case VUT_TERRFLAG:
369 for (i = 0; i < TER_USER_LAST; i++) {
370 cb(terrain_flag_id_name(i), univ->value.terrainflag == i, data);
371 }
372 break;
373 case VUT_ROADFLAG:
374 for (i = 0; i < RF_COUNT; i++) {
375 cb(road_flag_id_name(i), univ->value.roadflag == i, data);
376 }
377 break;
378 case VUT_TECHFLAG:
379 for (i = 0; i < TF_COUNT; i++) {
380 cb(tech_flag_id_name(i), univ->value.techflag == i, data);
381 }
382 break;
383 case VUT_EXTRAFLAG:
384 for (i = 0; i < EF_COUNT; i++) {
385 cb(extra_flag_id_name(i), univ->value.extraflag == i, data);
386 }
387 break;
388 case VUT_TERRAINALTER:
389 for (i = 0; i < TA_COUNT; i++) {
390 cb(terrain_alteration_name(i), univ->value.terrainalter == i, data);
391 }
392 break;
393 case VUT_CITYTILE:
394 for (i = 0; i < CITYT_LAST; i++) {
395 cb(citytile_type_name(i), univ->value.citytile == i, data);
396 }
397 break;
398 case VUT_CITYSTATUS:
399 for (i = 0; i < CITYS_LAST; i++) {
400 cb(citystatus_type_name(i), univ->value.citystatus == i, data);
401 }
402 break;
403 case VUT_ACHIEVEMENT:
405 cb(achievement_rule_name(pach), univ->value.achievement == pach, data);
407 break;
408 case VUT_DIPLREL:
409 case VUT_DIPLREL_TILE:
413 for (i = 0; i < DS_LAST; i++) {
414 cb(diplstate_type_name(i), univ->value.diplrel == i, data);
415 }
416 for (; i < DRO_LAST; i++) {
417 cb(diplrel_other_name(i), univ->value.diplrel == i, data);
418 }
419 break;
420 case VUT_UNITSTATE:
421 for (i = 0; i < USP_COUNT; i++) {
422 cb(ustate_prop_name(i), univ->value.unit_state == i, data);
423 }
424 break;
425 case VUT_ACTIVITY:
428 &(struct universal){.kind = VUT_ACTIVITY,
429 .value = {.activity = act}})) {
430 /* This activity is excluded from appearing in requirement
431 * vectors. */
432 continue;
433 }
434 cb(unit_activity_name(act), univ->value.activity == act, data);
436 break;
437 case VUT_NATIONGROUP:
441 break;
442 case VUT_TOPO:
443 for (i = 0; i < TOPO_FLAG_BITS; i++) {
444 cb(topo_flag_name(1 << i), univ->value.topo_property == 1 << i, data);
445 }
446 break;
447 case VUT_WRAP:
448 for (i = 0; i < WRAP_FLAG_BITS; i++) {
449 cb(wrap_flag_name(1 << i), univ->value.wrap_property == 1 << i, data);
450 }
451 break;
453 for (i = 0;
454 /* Only binary settings with the value TRUE are currently
455 * supported. */
456 i < settings_number();
457 i++) {
459 cb(ssetv_rule_name(i),
460 univ->value.ssetval == ssetv_from_values(i, TRUE), data);
461 }
462 }
463 break;
464 case VUT_IMPR_GENUS:
465 genus_iterate(genus) {
466 cb(impr_genus_id_name(genus), univ->value.impr_genus == genus, data);
468 break;
469 case VUT_IMPR_FLAG:
470 for (i = 0; i < IF_COUNT; i++) {
471 cb(impr_flag_id_name(i), univ->value.impr_flag == i, data);
472 }
473 break;
474 case VUT_PLAYER_FLAG:
475 for (i = 0; i < PLRF_COUNT; i++) {
476 cb(plr_flag_id_name(i), univ->value.plr_flag == i, data);
477 }
478 break;
479 case VUT_PLAYER_STATE:
480 for (i = 0; i < PLRS_LAST; i++) {
481 cb(plrstate_type_name(i), univ->value.plrstate == i, data);
482 }
483 break;
484 case VUT_ACTION:
485 action_iterate(act) {
486 struct action *pact = action_by_number(act);
487
488 cb(action_rule_name(pact), univ->value.action == pact, data);
490 break;
491 case VUT_MINSIZE:
492 case VUT_MINYEAR:
493 case VUT_MINCALFRAG:
494 case VUT_MAXTILEUNITS:
495 case VUT_MINCULTURE:
497 case VUT_MINMOVES:
498 case VUT_MINVETERAN:
499 case VUT_MINHP:
500 case VUT_AGE:
501 case VUT_FORM_AGE:
502 case VUT_MINTECHS:
503 case VUT_MINLATITUDE:
504 case VUT_MAXLATITUDE:
505 /* Requirement types having numerical value */
506 cb(NULL, FALSE, data);
507 break;
508 case VUT_COUNT:
509 fc_assert(univ->kind != VUT_COUNT);
510 break;
511 }
512}
struct achievement * achievement_by_number(int id)
const char * achievement_rule_name(struct achievement *pach)
#define achievements_re_active_iterate(_p)
#define achievements_re_active_iterate_end
const char * action_rule_name(const struct action *action)
Definition actions.c:1977
static struct action * action_by_number(action_id act_id)
Definition actions.h:635
#define action_iterate_end
Definition actions.h:465
#define action_iterate(_act_)
Definition actions.h:461
const char * get_output_name(Output_type_id output)
Definition city.c:629
#define output_type_iterate(output)
Definition city.h:845
#define output_type_iterate_end
Definition city.h:851
char * incite_cost
Definition comments.c:75
struct counter * counter_by_index(int index, enum counter_target target)
Definition counters.c:183
const char * counter_rule_name(struct counter *pcount)
Definition counters.c:165
int counters_get_city_counters_count(void)
Definition counters.c:74
#define city_counters_iterate_end
Definition counters.h:64
#define city_counters_iterate(pcount)
Definition counters.h:57
struct extra_type * extra_by_number(int id)
Definition extras.c:183
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:203
#define extra_type_re_active_iterate_end
Definition extras.h:329
#define extra_type_re_active_iterate(_p)
Definition extras.h:325
#define TOPO_FLAG_BITS
Definition fc_types.h:623
@ CTGT_CITY
Definition fc_types.h:126
#define WRAP_FLAG_BITS
Definition fc_types.h:632
output_type_id
Definition fc_types.h:100
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
struct impr_type * improvement_by_number(const Impr_type_id id)
const char * improvement_rule_name(const struct impr_type *pimprove)
#define genus_iterate_end
#define improvement_re_active_iterate_end
#define genus_iterate(_p)
#define improvement_re_active_iterate(_p)
#define fc_assert(condition)
Definition log.h:176
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
struct nation_type * nation_by_number(const Nation_type_id nation)
Definition nation.c:475
const char * nation_group_rule_name(const struct nation_group *pgroup)
Definition nation.c:1079
struct nation_group * nation_group_by_number(int id)
Definition nation.c:1004
int nation_group_count(void)
Definition nation.c:935
#define nations_iterate_end
Definition nation.h:336
#define nations_iterate(NAME_pnation)
Definition nation.h:333
#define nation_groups_iterate(NAME_pgroup)
Definition nation.h:311
#define nation_groups_iterate_end
Definition nation.h:315
bool universal_is_legal_in_requirement(const struct universal *univ)
bool sanity_check_server_setting_value_in_req(ssetv ssetval)
Definition rssanity.c:142
server_setting_id server_setting_by_name(const char *name)
const char * ssetv_rule_name(ssetv val)
ssetv ssetv_from_values(server_setting_id setting, int value)
int settings_number(void)
Definition settings.c:5299
struct specialist * specialist_by_number(const Specialist_type_id id)
Definition specialist.c:100
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 government * government_during_revolution
Definition game.h:94
enum universals_n kind
Definition fc_types.h:902
universals_u value
Definition fc_types.h:901
struct nation_style * style_by_number(int id)
Definition style.c:88
const char * style_rule_name(const struct nation_style *pstyle)
Definition style.c:108
#define styles_re_active_iterate_end
Definition style.h:60
#define styles_re_active_iterate(_p)
Definition style.h:56
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:299
#define advance_re_active_iterate(_p)
Definition tech.h:281
#define advance_re_active_iterate_end
Definition tech.h:285
#define A_NONE
Definition tech.h:43
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:156
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)
struct goods_type * goods_by_number(Goods_type_id id)
#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 nation_style * style
Definition fc_types.h:725
enum ai_level ai_level
Definition fc_types.h:729
struct specialist * specialist
Definition fc_types.h:718
enum impr_genus_id impr_genus
Definition fc_types.h:751
enum citytile_type citytile
Definition fc_types.h:730
struct nation_group * nationgroup
Definition fc_types.h:724
struct extra_type * extra
Definition fc_types.h:722
enum wrap_flag wrap_property
Definition fc_types.h:764
enum plrstate_type plrstate
Definition fc_types.h:732
struct nation_type * nation
Definition fc_types.h:715
int terrainclass
Definition fc_types.h:739
int unitclassflag
Definition fc_types.h:741
struct government * govern
Definition fc_types.h:713
struct nation_type * origowner
Definition fc_types.h:717
enum impr_flag_id impr_flag
Definition fc_types.h:752
int max_tile_units
Definition fc_types.h:755
int terrainalter
Definition fc_types.h:740
enum citystatus_type citystatus
Definition fc_types.h:731
int minforeignpct
Definition fc_types.h:735
const struct impr_type * building
Definition fc_types.h:714
struct achievement * achievement
Definition fc_types.h:723
ssetv ssetval
Definition fc_types.h:765
struct advance * advance
Definition fc_types.h:711
enum unit_activity activity
Definition fc_types.h:750
struct goods_type * good
Definition fc_types.h:727
struct terrain * terrain
Definition fc_types.h:719
int terrainflag
Definition fc_types.h:743
enum ustate_prop unit_state
Definition fc_types.h:749
Output_type_id outputtype
Definition fc_types.h:738
enum topo_flag topo_property
Definition fc_types.h:763
struct counter * counter
Definition fc_types.h:712
int min_hit_points
Definition fc_types.h:757
struct unit_class * uclass
Definition fc_types.h:720
struct nation_type * nationality
Definition fc_types.h:716
struct action * action
Definition fc_types.h:726
enum plr_flag_id plr_flag
Definition fc_types.h:753
#define activity_type_iterate(_act_)
Definition unit.h:284
#define activity_type_iterate_end
Definition unit.h:289
struct unit_class * uclass_by_number(const Unit_Class_id id)
Definition unittype.c:2477
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
struct unit_type * utype_by_number(const Unit_type_id id)
Definition unittype.c:112
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1641
#define unit_type_re_active_iterate(_p)
Definition unittype.h:867
#define unit_class_re_active_iterate_end
Definition unittype.h:924
#define UTYF_LAST_USER_FLAG
Definition unittype.h:331
#define unit_class_re_active_iterate(_p)
Definition unittype.h:920
#define unit_type_re_active_iterate_end
Definition unittype.h:871
bool universal_value_initial(struct universal *src)
Definition univ_value.c:42
void universal_kind_values(struct universal *univ, univ_kind_values_cb cb, void *data)
Definition univ_value.c:264
void(* univ_kind_values_cb)(const char *value, bool current, void *data)
Definition univ_value.h:20