Freeciv-3.1
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 "game.h"
21#include "government.h"
22#include "requirements.h"
23#include "server_settings.h"
24#include "specialist.h"
25#include "tech.h"
26#include "traderoutes.h"
27
28/* server */
29#include "rssanity.h"
30#include "settings.h"
31
32#include "univ_value.h"
33
34/********************************************************************/
41{
42 switch (src->kind) {
43 case VUT_NONE:
44 /* Value of None should never be used */
45 return TRUE;
46 case VUT_ADVANCE:
47 if (game.control.num_tech_types <= 0) {
48 return FALSE;
49 }
51 return TRUE;
52 case VUT_GOVERNMENT:
54 return TRUE;
55 case VUT_IMPROVEMENT:
56 if (game.control.num_impr_types <= 0) {
57 return FALSE;
58 }
60 return TRUE;
61 case VUT_TERRAIN:
63 return TRUE;
64 case VUT_NATION:
65 if (game.control.nation_count <= 0) {
66 return FALSE;
67 }
69 return TRUE;
70 case VUT_UTYPE:
71 if (game.control.num_unit_types <= 0) {
72 return FALSE;
73 }
74 src->value.utype = utype_by_number(0);
75 return TRUE;
76 case VUT_UTFLAG:
77 src->value.unitflag = (enum unit_type_flag_id)0;
78 return TRUE;
79 case VUT_UCLASS:
80 if (game.control.num_unit_classes <= 0) {
81 return FALSE;
82 }
84 return TRUE;
85 case VUT_UCFLAG:
86 src->value.unitclassflag = (enum unit_class_flag_id)0;
87 return TRUE;
88 case VUT_OTYPE:
89 src->value.outputtype = (enum output_type_id)0;
90 return TRUE;
91 case VUT_SPECIALIST:
93 return FALSE;
94 }
96 return TRUE;
97 case VUT_MINSIZE:
98 src->value.minsize = 0;
99 return TRUE;
100 case VUT_AI_LEVEL:
101 src->value.ai_level = AI_LEVEL_CHEATING;
102 return TRUE;
103 case VUT_TERRAINCLASS:
104 src->value.terrainclass = TC_LAND;
105 return TRUE;
106 case VUT_MINYEAR:
107 src->value.minyear = 0;
108 return TRUE;
109 case VUT_MINCALFRAG:
110 src->value.mincalfrag = 0;
111 return TRUE;
112 case VUT_TERRAINALTER:
113 src->value.terrainalter = TA_CAN_IRRIGATE;
114 return TRUE;
115 case VUT_CITYTILE:
116 src->value.citytile = CITYT_CENTER;
117 return TRUE;
118 case VUT_CITYSTATUS:
119 src->value.citystatus = CITYS_OWNED_BY_ORIGINAL;
120 return TRUE;
121 case VUT_GOOD:
122 if (game.control.num_goods_types <= 0) {
123 return FALSE;
124 }
125 src->value.good = goods_by_number(0);
126 return TRUE;
127 case VUT_TERRFLAG:
128 src->value.terrainflag = TER_NO_BARBS;
129 return TRUE;
130 case VUT_NATIONALITY:
131 if (game.control.nation_count <= 0) {
132 return FALSE;
133 }
135 return TRUE;
136 case VUT_ROADFLAG:
137 src->value.roadflag = RF_RIVER;
138 return TRUE;
139 case VUT_EXTRA:
140 if (game.control.num_extra_types <= 0) {
141 return FALSE;
142 }
143 src->value.extra = extra_by_number(0);
144 return TRUE;
145 case VUT_TECHFLAG:
146 src->value.techflag = TF_BONUS_TECH;
147 return TRUE;
148 case VUT_ACHIEVEMENT:
150 return FALSE;
151 }
153 return TRUE;
154 case VUT_DIPLREL:
155 case VUT_DIPLREL_TILE:
156 case VUT_DIPLREL_TILE_O:
157 case VUT_DIPLREL_UNITANY:
158 case VUT_DIPLREL_UNITANY_O:
159 src->value.diplrel = DS_WAR;
160 return TRUE;
161 case VUT_MAXTILEUNITS:
162 src->value.max_tile_units = 0;
163 return TRUE;
164 case VUT_STYLE:
165 if (game.control.num_styles <= 0) {
166 return FALSE;
167 }
168 src->value.style = style_by_number(0);
169 return TRUE;
170 case VUT_MINCULTURE:
171 src->value.minculture = 0;
172 return TRUE;
173 case VUT_MINFOREIGNPCT:
174 src->value.minforeignpct = 0;
175 return TRUE;
176 case VUT_UNITSTATE:
177 src->value.unit_state = USP_TRANSPORTED;
178 return TRUE;
179 case VUT_ACTIVITY:
180 src->value.activity = ACTIVITY_IDLE;
181 return TRUE;
182 case VUT_MINMOVES:
183 src->value.minmoves = 0;
184 return TRUE;
185 case VUT_MINVETERAN:
186 src->value.minveteran = 0;
187 return TRUE;
188 case VUT_MINHP:
189 src->value.min_hit_points = 0;
190 return TRUE;
191 case VUT_AGE:
192 src->value.age = 0;
193 return TRUE;
194 case VUT_NATIONGROUP:
195 if (nation_group_count() <= 0) {
196 return FALSE;
197 }
199 return TRUE;
200 case VUT_TOPO:
201 src->value.topo_property = TF_ISO;
202 return TRUE;
203 case VUT_SERVERSETTING:
204 src->value.ssetval
206 return TRUE;
207 case VUT_IMPR_GENUS:
208 src->value.impr_genus = IG_IMPROVEMENT;
209 return TRUE;
210 case VUT_ACTION:
211 src->value.action = action_by_number(0);
212 return TRUE;
213 case VUT_MINTECHS:
214 src->value.min_techs = 0;
215 return TRUE;
216 case VUT_EXTRAFLAG:
217 src->value.extraflag = EF_NATIVE_TILE;
218 return TRUE;
219 case VUT_COUNT:
220 fc_assert(src->kind != VUT_COUNT);
221 return FALSE;
222 }
223
224 return FALSE;
225}
226
227/********************************************************************/
231 univ_kind_values_cb cb, void *data)
232{
233 int i;
234
235 switch (univ->kind) {
236 case VUT_NONE:
237 break;
238 case VUT_ADVANCE:
240 cb(advance_rule_name(padv), univ->value.advance == padv, data);
242 break;
243 case VUT_GOVERNMENT:
245 cb(government_rule_name(pgov), univ->value.govern == pgov, data);
247 break;
248 case VUT_IMPROVEMENT:
250 cb(improvement_rule_name(pimpr), univ->value.building == pimpr, data);
252 break;
253 case VUT_TERRAIN:
255 cb(terrain_rule_name(pterr), univ->value.terrain == pterr, data);
257 break;
258 case VUT_NATION:
259 nations_iterate(pnat) {
260 cb(nation_rule_name(pnat), univ->value.nation == pnat, data);
262 break;
263 case VUT_UTYPE:
265 cb(utype_rule_name(putype), univ->value.utype == putype, data);
267 break;
268 case VUT_UCLASS:
270 cb(uclass_rule_name(pclass), univ->value.uclass == pclass, data);
272 break;
273 case VUT_OTYPE:
274 output_type_iterate(otype) {
275 cb(get_output_name(otype), univ->value.outputtype == otype, data);
277 break;
278 case VUT_GOOD:
280 cb(goods_rule_name(pgood), univ->value.good == pgood, data);
282 break;
283 case VUT_NATIONALITY:
284 nations_iterate(pnat) {
285 cb(nation_rule_name(pnat), univ->value.nationality == pnat, data);
287 break;
288 case VUT_EXTRA:
290 cb(extra_rule_name(pextra), univ->value.extra == pextra, data);
292 break;
293 case VUT_STYLE:
295 cb(style_rule_name(pstyle), univ->value.style == pstyle, data);
297 break;
298 case VUT_AI_LEVEL:
299 for (i = 0; i < AI_LEVEL_COUNT; i++) {
300 cb(ai_level_name(i), univ->value.ai_level == i, data);
301 }
302 break;
303 case VUT_SPECIALIST:
305 cb(specialist_rule_name(pspe), univ->value.specialist == pspe, data);
307 break;
308 case VUT_TERRAINCLASS:
309 for (i = 0; i < TC_COUNT; i++) {
310 cb(terrain_class_name(i), univ->value.terrainclass == i, data);
311 }
312 break;
313 case VUT_UTFLAG:
314 for (i = 0; i < UTYF_LAST_USER_FLAG; i++) {
315 cb(unit_type_flag_id_name(i), univ->value.unitflag == i, data);
316 }
317 break;
318 case VUT_UCFLAG:
319 for (i = 0; i < UCF_COUNT; i++) {
320 cb(unit_class_flag_id_name(i), univ->value.unitclassflag == i, data);
321 }
322 break;
323 case VUT_TERRFLAG:
324 for (i = 0; i < TER_USER_LAST; i++) {
325 cb(terrain_flag_id_name(i), univ->value.terrainflag == i, data);
326 }
327 break;
328 case VUT_ROADFLAG:
329 for (i = 0; i < RF_COUNT; i++) {
330 cb(road_flag_id_name(i), univ->value.roadflag == i, data);
331 }
332 break;
333 case VUT_TECHFLAG:
334 for (i = 0; i < TF_COUNT; i++) {
335 cb(tech_flag_id_name(i), univ->value.techflag == i, data);
336 }
337 break;
338 case VUT_EXTRAFLAG:
339 for (i = 0; i < EF_COUNT; i++) {
340 cb(extra_flag_id_name(i), univ->value.extraflag == i, data);
341 }
342 break;
343 case VUT_TERRAINALTER:
344 for (i = 0; i < TA_COUNT; i++) {
345 cb(terrain_alteration_name(i), univ->value.terrainalter == i, data);
346 }
347 break;
348 case VUT_CITYTILE:
349 for (i = 0; i < CITYT_LAST; i++) {
350 cb(citytile_type_name(i), univ->value.citytile == i, data);
351 }
352 break;
353 case VUT_CITYSTATUS:
354 for (i = 0; i < CITYS_LAST; i++) {
355 cb(citystatus_type_name(i), univ->value.citystatus == i, data);
356 }
357 break;
358 case VUT_ACHIEVEMENT:
360 cb(achievement_rule_name(pach), univ->value.achievement == pach, data);
362 break;
363 case VUT_DIPLREL:
364 case VUT_DIPLREL_TILE:
365 case VUT_DIPLREL_TILE_O:
366 case VUT_DIPLREL_UNITANY:
367 case VUT_DIPLREL_UNITANY_O:
368 for (i = 0; i < DS_LAST; i++) {
369 cb(diplstate_type_name(i), univ->value.diplrel == i, data);
370 }
371 for (; i < DRO_LAST; i++) {
372 cb(diplrel_other_name(i), univ->value.diplrel == i, data);
373 }
374 break;
375 case VUT_UNITSTATE:
376 for (i = 0; i < USP_COUNT; i++) {
377 cb(ustate_prop_name(i), univ->value.unit_state == i, data);
378 }
379 break;
380 case VUT_ACTIVITY:
383 &(struct universal){.kind = VUT_ACTIVITY,
384 .value = {.activity = act}})) {
385 /* This activity is excluded from appearing in requirement
386 * vectors. */
387 continue;
388 }
389 cb(unit_activity_name(act), univ->value.activity == act, data);
391 break;
392 case VUT_NATIONGROUP:
393 nation_groups_iterate(pgroup) {
394 cb(nation_group_rule_name(pgroup), univ->value.nationgroup == pgroup, data);
396 break;
397 case VUT_TOPO:
398 for (i = 0; i < TOPO_FLAG_BITS; i++) {
399 cb(topo_flag_name(1 << i), univ->value.topo_property == 1 << i, data);
400 }
401 break;
402 case VUT_SERVERSETTING:
403 for (i = 0;
404 /* Only binary settings with the value TRUE are currently
405 * supported. */
406 i < settings_number();
407 i++) {
409 cb(ssetv_rule_name(i),
410 univ->value.ssetval == ssetv_from_values(i, TRUE), data);
411 }
412 }
413 break;
414 case VUT_IMPR_GENUS:
415 genus_iterate(genus) {
416 cb(impr_genus_id_name(genus), univ->value.impr_genus == genus, data);
418 break;
419 case VUT_ACTION:
420 action_iterate(act) {
421 struct action *pact = action_by_number(act);
422
423 cb(action_rule_name(pact), univ->value.action == pact, data);
425 break;
426 case VUT_MINSIZE:
427 case VUT_MINYEAR:
428 case VUT_MINCALFRAG:
429 case VUT_MAXTILEUNITS:
430 case VUT_MINCULTURE:
431 case VUT_MINFOREIGNPCT:
432 case VUT_MINMOVES:
433 case VUT_MINVETERAN:
434 case VUT_MINHP:
435 case VUT_AGE:
436 case VUT_MINTECHS:
437 /* Requirement types having numerical value */
438 cb(NULL, FALSE, data);
439 break;
440 case VUT_COUNT:
441 fc_assert(univ->kind != VUT_COUNT);
442 break;
443 }
444}
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:1876
static struct action * action_by_number(action_id act_id)
Definition actions.h:638
#define action_iterate_end
Definition actions.h:472
#define action_iterate(_act_)
Definition actions.h:467
const char * get_output_name(Output_type_id output)
Definition city.c:624
#define output_type_iterate(output)
Definition city.h:821
#define output_type_iterate_end
Definition city.h:827
struct extra_type * extra_by_number(int id)
Definition extras.c:175
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:195
#define extra_type_re_active_iterate_end
Definition extras.h:305
#define extra_type_re_active_iterate(_p)
Definition extras.h:301
#define TOPO_FLAG_BITS
Definition fc_types.h:561
output_type_id
Definition fc_types.h:90
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
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:137
struct nation_type * nation_by_number(const Nation_type_id nation)
Definition nation.c:474
const char * nation_group_rule_name(const struct nation_group *pgroup)
Definition nation.c:1078
struct nation_group * nation_group_by_number(int id)
Definition nation.c:1003
int nation_group_count(void)
Definition nation.c:934
#define nations_iterate_end
Definition nation.h:335
#define nations_iterate(NAME_pnation)
Definition nation.h:332
#define nation_groups_iterate(NAME_pgroup)
Definition nation.h:310
#define nation_groups_iterate_end
Definition nation.h:314
bool universal_is_legal_in_requirement(const struct universal *univ)
bool sanity_check_server_setting_value_in_req(ssetv ssetval)
Definition rssanity.c:125
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:5005
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:758
universals_u value
Definition fc_types.h:757
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:275
#define advance_re_active_iterate_end
Definition tech.h:279
#define A_NONE
Definition tech.h:43
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:144
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)
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:604
struct nation_style * style
Definition fc_types.h:608
enum ai_level ai_level
Definition fc_types.h:612
struct specialist * specialist
Definition fc_types.h:601
enum impr_genus_id impr_genus
Definition fc_types.h:633
enum citytile_type citytile
Definition fc_types.h:613
struct nation_group * nationgroup
Definition fc_types.h:607
struct extra_type * extra
Definition fc_types.h:605
struct nation_type * nation
Definition fc_types.h:599
int terrainclass
Definition fc_types.h:621
int unitclassflag
Definition fc_types.h:623
struct government * govern
Definition fc_types.h:597
int max_tile_units
Definition fc_types.h:635
int terrainalter
Definition fc_types.h:622
enum citystatus_type citystatus
Definition fc_types.h:614
int minforeignpct
Definition fc_types.h:617
const struct impr_type * building
Definition fc_types.h:598
struct achievement * achievement
Definition fc_types.h:606
ssetv ssetval
Definition fc_types.h:642
struct advance * advance
Definition fc_types.h:596
enum unit_activity activity
Definition fc_types.h:632
struct goods_type * good
Definition fc_types.h:610
struct terrain * terrain
Definition fc_types.h:602
int terrainflag
Definition fc_types.h:625
enum ustate_prop unit_state
Definition fc_types.h:631
Output_type_id outputtype
Definition fc_types.h:620
enum topo_flag topo_property
Definition fc_types.h:641
int min_hit_points
Definition fc_types.h:637
struct unit_class * uclass
Definition fc_types.h:603
struct nation_type * nationality
Definition fc_types.h:600
struct action * action
Definition fc_types.h:609
#define activity_type_iterate(_act_)
Definition unit.h:288
#define activity_type_iterate_end
Definition unit.h:292
struct unit_class * uclass_by_number(const Unit_Class_id id)
Definition unittype.c:2525
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1630
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:1693
#define unit_type_re_active_iterate(_p)
Definition unittype.h:853
#define unit_class_re_active_iterate_end
Definition unittype.h:895
#define UTYF_LAST_USER_FLAG
Definition unittype.h:315
#define unit_class_re_active_iterate(_p)
Definition unittype.h:891
#define unit_type_re_active_iterate_end
Definition unittype.h:857
bool universal_value_initial(struct universal *src)
Definition univ_value.c:40
void universal_kind_values(struct universal *univ, univ_kind_values_cb cb, void *data)
Definition univ_value.c:230
void(* univ_kind_values_cb)(const char *value, bool current, void *data)
Definition univ_value.h:20