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