Freeciv-3.2
Loading...
Searching...
No Matches
requirements.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996-2004 - The Freeciv Project
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#ifndef FC__REQUIREMENTS_H
15#define FC__REQUIREMENTS_H
16
17#ifdef __cplusplus
18extern "C" {
19#endif /* __cplusplus */
20
21/* common */
22#include "fc_types.h"
23#include "map_types.h"
24
25struct astring;
26
27/* Range of requirements.
28 * Used in the network protocol.
29 * Order is important -- wider ranges should come later -- some code
30 * assumes a total order, or tests for e.g. >= REQ_RANGE_PLAYER.
31 * Ranges of similar types should be supersets, for example:
32 * - the set of Adjacent tiles contains the set of CAdjacent tiles,
33 * and both contain the center Local tile (a requirement on the local
34 * tile is also within Adjacent range);
35 * - World contains Alliance contains Player (a requirement we ourselves
36 * have is also within Alliance range). */
37#define SPECENUM_NAME req_range
38#define SPECENUM_VALUE0 REQ_RANGE_LOCAL
39#define SPECENUM_VALUE0NAME "Local"
40#define SPECENUM_VALUE1 REQ_RANGE_TILE
41#define SPECENUM_VALUE1NAME "Tile"
42#define SPECENUM_VALUE2 REQ_RANGE_CADJACENT
43#define SPECENUM_VALUE2NAME "CAdjacent"
44#define SPECENUM_VALUE3 REQ_RANGE_ADJACENT
45#define SPECENUM_VALUE3NAME "Adjacent"
46#define SPECENUM_VALUE4 REQ_RANGE_CITY
47#define SPECENUM_VALUE4NAME "City"
48#define SPECENUM_VALUE5 REQ_RANGE_TRADE_ROUTE
49/* FIXME: -> "Trade Route" */
50#define SPECENUM_VALUE5NAME "Traderoute"
51#define SPECENUM_VALUE6 REQ_RANGE_CONTINENT
52#define SPECENUM_VALUE6NAME "Continent"
53#define SPECENUM_VALUE7 REQ_RANGE_PLAYER
54#define SPECENUM_VALUE7NAME "Player"
55#define SPECENUM_VALUE8 REQ_RANGE_TEAM
56#define SPECENUM_VALUE8NAME "Team"
57#define SPECENUM_VALUE9 REQ_RANGE_ALLIANCE
58#define SPECENUM_VALUE9NAME "Alliance"
59#define SPECENUM_VALUE10 REQ_RANGE_WORLD
60#define SPECENUM_VALUE10NAME "World"
61#define SPECENUM_COUNT REQ_RANGE_COUNT /* Keep this last */
62#define REQ_RANGE_MAX (REQ_RANGE_COUNT - 1) /* REQ_RANGE_WORLD */
63#include "specenum_gen.h"
64
65#define req_range_iterate(_range_) \
66 { \
67 enum req_range _range_; \
68 for (_range_ = REQ_RANGE_LOCAL ; _range_ < REQ_RANGE_COUNT ; \
69 _range_ = (enum req_range)(_range_ + 1)) {
70
71#define req_range_iterate_end \
72 } \
73 }
74
75/* A requirement. This requirement is basically a conditional; it may or
76 * may not be active on a target. If it is active then something happens.
77 * For instance units and buildings have requirements to be built, techs
78 * have requirements to be researched, and effects have requirements to be
79 * active.
80 * Used in the network protocol. */
82 struct universal source; /* requirement source */
83 enum req_range range; /* requirement range */
84 bool survives; /* set if destroyed sources satisfy the req*/
85 bool present; /* set if the requirement is to be present */
86 bool quiet; /* do not list this in helptext */
87};
88
89#define SPECVEC_TAG requirement
90#define SPECVEC_TYPE struct requirement
91#include "specvec.h"
92#define requirement_vector_iterate(req_vec, preq) \
93 TYPED_VECTOR_ITERATE(struct requirement, req_vec, preq)
94#define requirement_vector_iterate_end VECTOR_ITERATE_END
95
96/* A set of targets to evaluate requirements against. Depending on what the
97 * requirements in question are for, most of these entries will usually be
98 * NULL. For instance, when evaluating the construction requirements for a
99 * building, there is no target unit, specialist etc. */
101 const struct player *player;
102 const struct city *city;
103 const struct tile *tile;
104
105 /* For local-ranged requirements only */
106 const struct unit *unit;
107 const struct unit_type *unittype;
108 const struct impr_type *building;
109 const struct extra_type *extra;
110 const struct output_type *output;
111 const struct specialist *specialist;
112 const struct action *action;
114};
115
117 REQUCH_NO = 0, /* Changes regularly */
118 REQUCH_CTRL, /* Can't be changed by game means as long as target player
119 * is in control of target city or unit */
120 REQUCH_ACT, /* Can't be easily changed by expected player's activity
121 * (without destroying teammates, inducing global warming...) */
122 REQUCH_SCRIPTS, /* May be changed by script callbacks */
123 REQUCH_HACK, /* May be changed by server commands/editor */
124 REQUCH_YES /* Really never changes unless savegame is edited */
126
127/* A callback that may transform kind-specific default unchanging status
128 * to another one (usually higher but not always)
129 * Passing other_player is just not needed for it in any known cases */
130typedef enum req_unchanging_status
131 (*req_unchanging_cond_cb)(const struct civ_map *nmap,
132 enum req_unchanging_status def,
133 const struct req_context *context,
134 const struct requirement *req);
135
136/* req_context-related functions */
137const struct req_context *req_context_empty(void);
138
139/* General requirement functions. */
140struct requirement req_from_str(const char *type, const char *range,
141 bool survives, bool present, bool quiet,
142 const char *value);
143const char *req_to_fstring(const struct requirement *req,
144 struct astring *astr);
145
146void req_get_values(const struct requirement *req, int *type,
147 int *range, bool *survives, bool *present, bool *quiet,
148 int *value);
151 int value);
152
153void req_copy(struct requirement *dst, const struct requirement *src);
154
155bool are_requirements_equal(const struct requirement *req1,
156 const struct requirement *req2);
157
158bool are_requirements_contradictions(const struct requirement *req1,
159 const struct requirement *req2);
160
161bool req_implies_req(const struct requirement *req1,
162 const struct requirement *req2);
163
164bool does_req_contradicts_reqs(const struct requirement *req,
165 const struct requirement_vector *vec);
166
168 const struct player *other_player,
169 const struct requirement *req);
170bool is_req_active(const struct req_context *context,
171 const struct player *other_player,
172 const struct requirement *req,
173 const enum req_problem_type prob_type);
174bool are_reqs_active(const struct req_context *context,
175 const struct player *other_player,
176 const struct requirement_vector *reqs,
177 const enum req_problem_type prob_type);
179 const enum req_range max_range,
180 const struct req_context *context,
181 const struct player *other_player,
182 const struct requirement_vector *reqs,
183 const enum req_problem_type prob_type);
184enum fc_tristate
186 const struct req_context *context,
187 const struct player *other_player,
188 const struct requirement *req);
189
190/* Type of a callback that tests requirements due to a context
191 * and something else in some manner different from tri_req_active() */
192typedef enum fc_tristate
193 (*req_tester_cb)(const struct req_context *context,
194 const struct player *other_player,
195 const struct requirement *req,
196 void *data, int n_data);
197
198enum fc_tristate
200 const struct player *other_player,
201 const struct requirement *req,
202 void *data, int n_data);
203enum fc_tristate
205 const struct player *other_player,
206 const struct requirement_vector *reqs,
209 void *data, int n_data);
210
213 const struct requirement *req);
216 const struct player *other_player,
217 const struct requirement *req,
219
220bool is_req_in_vec(const struct requirement *req,
221 const struct requirement_vector *vec);
222
224 enum universals_n kind);
225
226bool universal_never_there(const struct universal *source);
227bool req_is_impossible_to_fulfill(const struct requirement *req);
229
237typedef signed char req_vec_num_in_item;
238
239/**********************************************************************/
249 const struct requirement_vector *vec);
250
251/********************************************************************/
259typedef struct requirement_vector *
260(*requirement_vector_by_number)(const void *parent_item,
261 req_vec_num_in_item number);
262
263/*********************************************************************/
270typedef const char *(*requirement_vector_namer)(req_vec_num_in_item number);
271
274 const struct requirement_vector *vec);
275struct requirement_vector *
277
278/* Interactive friendly requirement vector change suggestions and
279 * reasoning. */
280#define SPECENUM_NAME req_vec_change_operation
281#define SPECENUM_VALUE0 RVCO_REMOVE
282#define SPECENUM_VALUE0NAME N_("Remove")
283#define SPECENUM_VALUE1 RVCO_APPEND
284#define SPECENUM_VALUE1NAME N_("Append")
285#define SPECENUM_COUNT RVCO_NOOP
286#include "specenum_gen.h"
287
294
296 /* Can't use name_translation because it is MAX_LEN_NAME long and a
297 * description may contain more than one name. */
298 char description[500];
300
303};
304
305const char *req_vec_change_translation(const struct req_vec_change *change,
307
310 const void *parent_item);
311
313 const char *description, ...);
314struct req_vec_problem *
316 const char *description,
317 const char *description_translated);
319
320struct req_vec_problem *
323 const void *parent_item);
324struct req_vec_problem *
327 const void *parent_item);
328struct req_vec_problem *
331 const void *parent_item);
332struct req_vec_problem *
335 const void *parent_item);
336struct req_vec_problem *
339 const void *parent_item);
340
341
342/* General universal functions. */
343int universal_number(const struct universal *source);
344
346 const int value);
348 const char *value);
349void universal_value_from_str(struct universal *source, const char *value);
350void universal_copy(struct universal *dst, const struct universal *src);
351void universal_extraction(const struct universal *source,
352 int *kind, int *value);
353
354bool are_universals_equal(const struct universal *psource1,
355 const struct universal *psource2);
356
357const char *universal_rule_name(const struct universal *psource);
358const char *universal_name_translation(const struct universal *psource,
359 char *buf, size_t bufsz);
360const char *universal_type_rule_name(const struct universal *psource);
361
362int universal_build_shield_cost(const struct city *pcity,
363 const struct universal *target);
364
366 const struct universal *to_replace,
367 const struct universal *replacement);
368
369bool universal_is_legal_in_requirement(const struct universal *univ);
370
371#define universal_is_mentioned_by_requirement(preq, psource) \
372 are_universals_equal(&preq->source, psource)
374 const struct requirement_vector *reqs,
375 const struct universal *psource);
376
377/* An item contradicts, fulfills or is irrelevant to the requirement */
379
383 const struct universal *source);
385 const struct requirement_vector *reqs,
386 const struct universal *source);
388 const struct universal *source);
390 struct universal *unis,
391 size_t n_unis);
393 struct universal *unis,
394 size_t n_unis);
395
396#define universals_iterate(_univ_) \
397 { \
398 enum universals_n _univ_; \
399 for (_univ_ = VUT_NONE; _univ_ < VUT_COUNT; _univ_ = (enum universals_n)(_univ_ + 1)) {
400
401#define universals_iterate_end \
402 } \
403 }
404
405/* Accessors to determine if a universal fulfills a requirement vector.
406 * When adding an additional accessor, be sure to add the appropriate
407 * item_found function in universal_found_functions_init(). */
408/* XXX Some versions of g++ can't cope with the struct literals */
409#define requirement_fulfilled_by_government(_gov_, _rqs_) \
410 universal_fulfills_requirements(FALSE, (_rqs_), \
411 &(struct universal){.kind = VUT_GOVERNMENT, .value = {.govern = (_gov_)}})
412#define requirement_fulfilled_by_nation(_nat_, _rqs_) \
413 universal_fulfills_requirements(FALSE, (_rqs_), \
414 &(struct universal){.kind = VUT_NATION, .value = {.nation = (_nat_)}})
415#define requirement_fulfilled_by_improvement(_imp_, _rqs_) \
416 universal_fulfills_requirements(FALSE, (_rqs_), \
417 &(struct universal){.kind = VUT_IMPROVEMENT, \
418 .value = {.building = (_imp_)}})
419#define requirement_fulfilled_by_terrain(_ter_, _rqs_) \
420 universal_fulfills_requirements(FALSE, (_rqs_), \
421 &(struct universal){.kind = VUT_TERRAIN, \
422 .value = {.terrain = (_ter_)}})
423#define requirement_fulfilled_by_unit_class(_uc_, _rqs_) \
424 universal_fulfills_requirements(FALSE, (_rqs_), \
425 &(struct universal){.kind = VUT_UCLASS, .value = {.uclass = (_uc_)}})
426#define requirement_fulfilled_by_unit_type(_ut_, _rqs_) \
427 universal_fulfills_requirements(FALSE, (_rqs_), \
428 &(struct universal){.kind = VUT_UTYPE, .value = {.utype = (_ut_)}})
429#define requirement_fulfilled_by_extra(_ex_, _rqs_) \
430 universal_fulfills_requirements(FALSE, (_rqs_), \
431 &(struct universal){.kind = VUT_EXTRA, .value = {.extra = (_ex_)}})
432#define requirement_fulfilled_by_output_type(_o_, _rqs_) \
433 universal_fulfills_requirements(FALSE, (_rqs_), \
434 &(struct universal){.kind = VUT_OTYPE, .value = {.outputtype = (_o_)}})
435#define requirement_fulfilled_by_action(_act_, _rqs_) \
436 universal_fulfills_requirements(FALSE, (_rqs_), \
437 &(struct universal){.kind = VUT_ACTION, .value = {.action = (_act_)}})
438
439#define requirement_needs_improvement(_imp_, _rqs_) \
440 universal_fulfills_requirements(TRUE, (_rqs_), \
441 &(struct universal){.kind = VUT_IMPROVEMENT, \
442 .value = {.building = (_imp_)}})
443
444int requirement_kind_ereq(const int value,
445 const enum req_range range,
446 const bool present,
447 const int max_value);
448
449#define requirement_diplrel_ereq(_id_, _range_, _present_) \
450 requirement_kind_ereq(_id_, _range_, _present_, DRO_LAST)
451
452#ifdef __cplusplus
453}
454#endif /* __cplusplus */
455
456#endif /* FC__REQUIREMENTS_H */
char * incite_cost
Definition comments.c:75
struct @21::@22 reqs
req_problem_type
Definition fc_types.h:699
static GtkWidget * source
Definition gotodlg.c:58
GType type
Definition repodlgs.c:1313
static const int bufsz
Definition helpdlg.c:70
bool universal_never_there(const struct universal *source)
struct req_vec_problem * req_vec_problem_new(int num_suggested_solutions, const char *description,...)
bool universal_is_relevant_to_requirement(const struct requirement *req, const struct universal *source)
bool is_req_in_vec(const struct requirement *req, const struct requirement_vector *vec)
int universal_build_shield_cost(const struct city *pcity, const struct universal *target)
struct req_vec_problem * req_vec_get_first_contradiction(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
const struct req_context * req_context_empty(void)
signed char req_vec_num_in_item
req_vec_num_in_item a requirement vectors number in an item.
void universal_extraction(const struct universal *source, int *kind, int *value)
req_vec_num_in_item(* requirement_vector_number)(const void *parent_item, const struct requirement_vector *vec)
const char * req_to_fstring(const struct requirement *req, struct astring *astr)
const char *(* requirement_vector_namer)(req_vec_num_in_item number)
req_vec_num_in_item req_vec_vector_number(const void *parent_item, const struct requirement_vector *vec)
struct requirement_vector * req_vec_by_number(const void *parent_item, req_vec_num_in_item number)
bool universal_fulfills_requirements(bool check_necessary, const struct requirement_vector *reqs, const struct universal *source)
bool req_vec_change_apply(const struct req_vec_change *modification, requirement_vector_by_number getter, const void *parent_item)
void universal_copy(struct universal *dst, const struct universal *src)
enum req_unchanging_status(* req_unchanging_cond_cb)(const struct civ_map *nmap, enum req_unchanging_status def, const struct req_context *context, const struct requirement *req)
bool are_requirements_equal(const struct requirement *req1, const struct requirement *req2)
bool are_reqs_active_ranges(const enum req_range min_range, const enum req_range max_range, const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
bool is_req_active(const struct req_context *context, const struct player *other_player, const struct requirement *req, const enum req_problem_type prob_type)
const char * req_vec_change_translation(const struct req_vec_change *change, const requirement_vector_namer namer)
struct requirement req_from_str(const char *type, const char *range, bool survives, bool present, bool quiet, const char *value)
struct req_vec_problem * req_vec_suggest_repair(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
void universal_value_from_str(struct universal *source, const char *value)
enum fc_tristate(* req_tester_cb)(const struct req_context *context, const struct player *other_player, const struct requirement *req, void *data, int n_data)
void req_get_values(const struct requirement *req, int *type, int *range, bool *survives, bool *present, bool *quiet, int *value)
struct requirement req_from_values(int type, int range, bool survives, bool present, bool quiet, int value)
bool are_reqs_active(const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
const char * universal_rule_name(const struct universal *psource)
bool universal_replace_in_req_vec(struct requirement_vector *reqs, const struct universal *to_replace, const struct universal *replacement)
enum fc_tristate default_tester_cb(const struct req_context *context, const struct player *other_player, const struct requirement *req, void *data, int n_data)
bool are_requirements_contradictions(const struct requirement *req1, const struct requirement *req2)
enum fc_tristate tri_req_active_turns(int pass, int period, const struct req_context *context, const struct player *other_player, const struct requirement *req)
bool universal_is_legal_in_requirement(const struct universal *univ)
int requirement_kind_ereq(const int value, const enum req_range range, const bool present, const int max_value)
void req_vec_problem_free(struct req_vec_problem *issue)
struct req_vec_problem * req_vec_get_first_missing_univ(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
struct universal universal_by_number(const enum universals_n kind, const int value)
enum req_item_found universal_fulfills_requirement(const struct requirement *preq, const struct universal *source)
bool req_vec_wants_type(const struct requirement_vector *reqs, enum universals_n kind)
struct requirement_vector *(* requirement_vector_by_number)(const void *parent_item, req_vec_num_in_item number)
enum fc_tristate tri_reqs_cb_active(const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, struct requirement_vector *maybe_reqs, req_tester_cb tester, void *data, int n_data)
struct req_vec_problem * req_vec_get_first_redundant_req(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
bool does_req_contradicts_reqs(const struct requirement *req, const struct requirement_vector *vec)
bool are_universals_equal(const struct universal *psource1, const struct universal *psource2)
struct req_vec_problem * req_vec_problem_new_transl(int num_suggested_solutions, const char *description, const char *description_translated)
enum fc_tristate tri_req_active(const struct req_context *context, const struct player *other_player, const struct requirement *req)
bool universals_say_everything(struct requirement_vector *reqs, struct universal *unis, size_t n_unis)
const char * universal_type_rule_name(const struct universal *psource)
void universal_found_functions_init(void)
int universal_number(const struct universal *source)
bool universal_is_mentioned_by_requirements(const struct requirement_vector *reqs, const struct universal *psource)
bool req_vec_is_impossible_to_fulfill(const struct requirement_vector *reqs)
bool req_implies_req(const struct requirement *req1, const struct requirement *req2)
void req_copy(struct requirement *dst, const struct requirement *src)
enum req_unchanging_status is_req_unchanging(const struct req_context *context, const struct requirement *req)
enum req_unchanging_status is_req_preventing(const struct req_context *context, const struct player *other_player, const struct requirement *req, enum req_problem_type prob_type)
req_item_found
@ ITF_NO
@ ITF_YES
@ ITF_NOT_APPLICABLE
bool req_is_impossible_to_fulfill(const struct requirement *req)
const char * universal_name_translation(const struct universal *psource, char *buf, size_t bufsz)
struct universal universal_by_rule_name(const char *kind, const char *value)
req_unchanging_status
@ REQUCH_ACT
@ REQUCH_NO
@ REQUCH_SCRIPTS
@ REQUCH_YES
@ REQUCH_HACK
@ REQUCH_CTRL
bool universals_mean_unfulfilled(struct requirement_vector *reqs, struct universal *unis, size_t n_unis)
struct req_vec_problem * req_vec_suggest_improvement(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
fc_tristate
Definition shared.h:46
Definition city.h:320
const struct impr_type * building
const struct action * action
const struct tile * tile
const struct player * player
enum unit_activity activity
const struct output_type * output
const struct unit_type * unittype
const struct unit * unit
const struct extra_type * extra
const struct city * city
const struct specialist * specialist
req_vec_num_in_item vector_number
enum req_vec_change_operation operation
struct requirement req
char description[500]
char description_translated[500]
struct req_vec_change * suggested_solutions
enum req_range range
struct universal source
Definition tile.h:50
Definition unit.h:138
enum universals_n kind
Definition fc_types.h:902
universals_u value
Definition fc_types.h:901
#define bool
Definition support.h:71