Freeciv-3.3
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_MINCITIES:
247 src->value.min_cities = 0;
248 return TRUE;
249 case VUT_EXTRAFLAG:
251 return TRUE;
252 case VUT_MINLATITUDE:
253 case VUT_MAXLATITUDE:
254 src->value.latitude = 0;
255 return TRUE;
257 src->value.distance_sq = 0;
258 return TRUE;
260 src->value.region_tiles = 0;
261 return TRUE;
262 case VUT_TILE_REL:
264 return TRUE;
265 case VUT_COUNT:
266 fc_assert(src->kind != VUT_COUNT);
267 return FALSE;
268 }
269
270 return FALSE;
271}
272
273/********************************************************************/
277 univ_kind_values_cb cb, void *data)
278{
279 int i;
280
281 switch (univ->kind) {
282 case VUT_NONE:
283 break;
284 case VUT_ADVANCE:
286 cb(advance_rule_name(padv), univ->value.advance == padv, data);
288 break;
289 case VUT_COUNTER:
291 cb(counter_rule_name(pcount), univ->value.counter == pcount, data);
293 break;
294 case VUT_GOVERNMENT:
296 cb(government_rule_name(pgov), univ->value.govern == pgov, data);
298 break;
299 case VUT_IMPROVEMENT:
300 case VUT_SITE:
302 cb(improvement_rule_name(pimpr), univ->value.building == pimpr, data);
304 break;
305 case VUT_TERRAIN:
307 cb(terrain_rule_name(pterr), univ->value.terrain == pterr, data);
309 break;
310 case VUT_NATION:
312 cb(nation_rule_name(pnat), univ->value.nation == pnat, data);
314 break;
315 case VUT_UTYPE:
317 cb(utype_rule_name(putype), univ->value.utype == putype, data);
319 break;
320 case VUT_UCLASS:
322 cb(uclass_rule_name(pclass), univ->value.uclass == pclass, data);
324 break;
325 case VUT_OTYPE:
327 cb(get_output_name(otype), univ->value.outputtype == otype, data);
329 break;
330 case VUT_GOOD:
332 cb(goods_rule_name(pgood), univ->value.good == pgood, data);
334 break;
335 case VUT_NATIONALITY:
337 cb(nation_rule_name(pnat), univ->value.nationality == pnat, data);
339 break;
342 cb(nation_rule_name(pnat), univ->value.origowner == pnat, data);
344 break;
345 case VUT_EXTRA:
347 cb(extra_rule_name(pextra), univ->value.extra == pextra, data);
349 break;
350 case VUT_STYLE:
352 cb(style_rule_name(pstyle), univ->value.style == pstyle, data);
354 break;
355 case VUT_AI_LEVEL:
356 for (i = 0; i < AI_LEVEL_COUNT; i++) {
357 cb(ai_level_name(i), univ->value.ai_level == i, data);
358 }
359 break;
360 case VUT_SPECIALIST:
362 cb(specialist_rule_name(pspe), univ->value.specialist == pspe, data);
364 break;
365 case VUT_TERRAINCLASS:
366 for (i = 0; i < TC_COUNT; i++) {
367 cb(terrain_class_name(i), univ->value.terrainclass == i, data);
368 }
369 break;
370 case VUT_UTFLAG:
371 for (i = 0; i < UTYF_LAST_USER_FLAG; i++) {
372 cb(unit_type_flag_id_name(i), univ->value.unitflag == i, data);
373 }
374 break;
375 case VUT_UCFLAG:
376 for (i = 0; i < UCF_COUNT; i++) {
377 cb(unit_class_flag_id_name(i), univ->value.unitclassflag == i, data);
378 }
379 break;
380 case VUT_TERRFLAG:
381 for (i = 0; i < TER_USER_LAST; i++) {
382 cb(terrain_flag_id_name(i), univ->value.terrainflag == i, data);
383 }
384 break;
385 case VUT_ROADFLAG:
386 for (i = 0; i < RF_COUNT; i++) {
387 cb(road_flag_id_name(i), univ->value.roadflag == i, data);
388 }
389 break;
390 case VUT_TECHFLAG:
391 for (i = 0; i < TF_COUNT; i++) {
392 cb(tech_flag_id_name(i), univ->value.techflag == i, data);
393 }
394 break;
395 case VUT_EXTRAFLAG:
396 for (i = 0; i < EF_COUNT; i++) {
397 cb(extra_flag_id_name(i), univ->value.extraflag == i, data);
398 }
399 break;
400 case VUT_TERRAINALTER:
401 for (i = 0; i < TA_COUNT; i++) {
402 cb(terrain_alteration_name(i), univ->value.terrainalter == i, data);
403 }
404 break;
405 case VUT_CITYTILE:
406 for (i = 0; i < CITYT_LAST; i++) {
407 cb(citytile_type_name(i), univ->value.citytile == i, data);
408 }
409 break;
410 case VUT_CITYSTATUS:
411 for (i = 0; i < CITYS_LAST; i++) {
412 cb(citystatus_type_name(i), univ->value.citystatus == i, data);
413 }
414 break;
415 case VUT_TILE_REL:
416 for (i = 0; i < TREL_COUNT; i++) {
417 cb(tilerel_type_name(i), univ->value.tilerel == i, data);
418 }
419 break;
420 case VUT_ACHIEVEMENT:
422 cb(achievement_rule_name(pach), univ->value.achievement == pach, data);
424 break;
425 case VUT_DIPLREL:
426 case VUT_DIPLREL_TILE:
430 for (i = 0; i < DS_LAST; i++) {
431 cb(diplstate_type_name(i), univ->value.diplrel == i, data);
432 }
433 for (; i < DRO_LAST; i++) {
434 cb(diplrel_other_name(i), univ->value.diplrel == i, data);
435 }
436 break;
437 case VUT_UNITSTATE:
438 for (i = 0; i < USP_COUNT; i++) {
439 cb(ustate_prop_name(i), univ->value.unit_state == i, data);
440 }
441 break;
442 case VUT_ACTIVITY:
445 &(struct universal){.kind = VUT_ACTIVITY,
446 .value = {.activity = act}})) {
447 /* This activity is excluded from appearing in requirement
448 * vectors. */
449 continue;
450 }
451 cb(unit_activity_name(act), univ->value.activity == act, data);
453 break;
454 case VUT_NATIONGROUP:
458 break;
459 case VUT_TOPO:
460 for (i = 0; i < TOPO_FLAG_BITS; i++) {
461 cb(topo_flag_name(1 << i), univ->value.topo_property == 1 << i, data);
462 }
463 break;
464 case VUT_WRAP:
465 for (i = 0; i < WRAP_FLAG_BITS; i++) {
466 cb(wrap_flag_name(1 << i), univ->value.wrap_property == 1 << i, data);
467 }
468 break;
470 for (i = 0;
471 /* Only binary settings with the value TRUE are currently
472 * supported. */
473 i < settings_number();
474 i++) {
476 cb(ssetv_rule_name(i),
477 univ->value.ssetval == ssetv_from_values(i, TRUE), data);
478 }
479 }
480 break;
481 case VUT_IMPR_GENUS:
482 genus_iterate(genus) {
483 cb(impr_genus_id_name(genus), univ->value.impr_genus == genus, data);
485 break;
486 case VUT_IMPR_FLAG:
487 for (i = 0; i < IF_COUNT; i++) {
488 cb(impr_flag_id_name(i), univ->value.impr_flag == i, data);
489 }
490 break;
491 case VUT_PLAYER_FLAG:
492 for (i = 0; i < PLRF_COUNT; i++) {
493 cb(plr_flag_id_name(i), univ->value.plr_flag == i, data);
494 }
495 break;
496 case VUT_PLAYER_STATE:
497 for (i = 0; i < PLRS_LAST; i++) {
498 cb(plrstate_type_name(i), univ->value.plrstate == i, data);
499 }
500 break;
501 case VUT_ACTION:
502 action_iterate(act) {
503 struct action *pact = action_by_number(act);
504
505 cb(action_rule_name(pact), univ->value.action == pact, data);
507 break;
508 case VUT_MINSIZE:
509 case VUT_MINYEAR:
510 case VUT_MINCALFRAG:
511 case VUT_MAXTILEUNITS:
512 case VUT_MINCULTURE:
514 case VUT_MINMOVES:
515 case VUT_MINVETERAN:
516 case VUT_MINHP:
517 case VUT_AGE:
518 case VUT_FORM_AGE:
519 case VUT_MINTECHS:
520 case VUT_MINCITIES:
521 case VUT_MINLATITUDE:
522 case VUT_MAXLATITUDE:
525 /* Requirement types having numerical value */
526 cb(nullptr, FALSE, data);
527 break;
528 case VUT_COUNT:
529 fc_assert(univ->kind != VUT_COUNT);
530 break;
531 }
532}
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:1216
static struct action * action_by_number(action_id act_id)
Definition actions.h:396
#define action_iterate_end
Definition actions.h:214
#define action_iterate(_act_)
Definition actions.h:210
const char * get_output_name(Output_type_id output)
Definition city.c:629
#define output_type_iterate(output)
Definition city.h:842
#define output_type_iterate_end
Definition city.h:848
char * incite_cost
Definition comments.c:76
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:480
@ CTGT_CITY
Definition fc_types.h:126
#define WRAP_FLAG_BITS
Definition fc_types.h:489
output_type_id
Definition fc_types.h:100
struct civ_game game
Definition game.c:61
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:177
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:143
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:5266
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:608
universals_u value
Definition fc_types.h:607
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:309
#define advance_re_active_iterate(_p)
Definition tech.h:277
#define advance_re_active_iterate_end
Definition tech.h:281
#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:281
#define terrain_re_active_iterate(_p)
Definition terrain.h:277
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:553
int region_tiles
Definition fc_types.h:597
struct nation_style * style
Definition fc_types.h:557
enum ai_level ai_level
Definition fc_types.h:561
struct specialist * specialist
Definition fc_types.h:550
enum impr_genus_id impr_genus
Definition fc_types.h:584
enum citytile_type citytile
Definition fc_types.h:562
struct nation_group * nationgroup
Definition fc_types.h:556
struct extra_type * extra
Definition fc_types.h:554
enum wrap_flag wrap_property
Definition fc_types.h:600
enum plrstate_type plrstate
Definition fc_types.h:564
enum tilerel_type tilerel
Definition fc_types.h:565
struct nation_type * nation
Definition fc_types.h:547
int terrainclass
Definition fc_types.h:572
int unitclassflag
Definition fc_types.h:574
struct government * govern
Definition fc_types.h:545
struct nation_type * origowner
Definition fc_types.h:549
enum impr_flag_id impr_flag
Definition fc_types.h:585
int max_tile_units
Definition fc_types.h:588
int terrainalter
Definition fc_types.h:573
enum citystatus_type citystatus
Definition fc_types.h:563
int minforeignpct
Definition fc_types.h:568
const struct impr_type * building
Definition fc_types.h:546
struct achievement * achievement
Definition fc_types.h:555
ssetv ssetval
Definition fc_types.h:601
struct advance * advance
Definition fc_types.h:543
enum unit_activity activity
Definition fc_types.h:583
struct goods_type * good
Definition fc_types.h:559
struct terrain * terrain
Definition fc_types.h:551
int terrainflag
Definition fc_types.h:576
enum ustate_prop unit_state
Definition fc_types.h:582
Output_type_id outputtype
Definition fc_types.h:571
int distance_sq
Definition fc_types.h:596
enum topo_flag topo_property
Definition fc_types.h:599
struct counter * counter
Definition fc_types.h:544
int min_hit_points
Definition fc_types.h:590
struct unit_class * uclass
Definition fc_types.h:552
struct nation_type * nationality
Definition fc_types.h:548
struct action * action
Definition fc_types.h:558
enum plr_flag_id plr_flag
Definition fc_types.h:586
#define activity_type_iterate(_act_)
Definition unit.h:287
#define activity_type_iterate_end
Definition unit.h:292
struct unit_class * uclass_by_number(const Unit_Class_id id)
Definition unittype.c:2483
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1584
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:1647
#define unit_type_re_active_iterate(_p)
Definition unittype.h:874
#define unit_class_re_active_iterate_end
Definition unittype.h:931
#define UTYF_LAST_USER_FLAG
Definition unittype.h:337
#define unit_class_re_active_iterate(_p)
Definition unittype.h:927
#define unit_type_re_active_iterate_end
Definition unittype.h:878
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:276
void(* univ_kind_values_cb)(const char *value, bool current, void *data)
Definition univ_value.h:20