Freeciv-3.2
Loading...
Searching...
No Matches
tech.h
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#ifndef FC__TECH_H
14#define FC__TECH_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/* utility */
21#include "bitvector.h"
22#include "shared.h"
23
24/* common */
25#include "fc_types.h"
26#include "name_translation.h"
27#include "requirements.h"
28
29struct strvec; /* Actually defined in "utility/string_vector.h". */
30
31/*
32 [kept for amusement and posterity]
33typedef int Tech_type_id;
34 Above typedef replaces old "enum tech_type_id"; see comments about
35 Unit_type_id in unit.h, since mainly apply here too, except don't
36 use Tech_type_id very widely, and don't use (-1) flag values. (?)
37*/
38/* [more accurately]
39 * Unlike most other indices, the Tech_type_id is widely used, because it
40 * so frequently passed to packet and scripting. The client menu routines
41 * sometimes add and subtract these numbers.
42 */
43#define A_NONE 0
44#define A_FIRST 1
45#define A_LAST (MAX_NUM_ADVANCES + 1) /* Used in the network protocol. */
46#define A_FUTURE (A_LAST + 1)
47#define A_ARRAY_SIZE (A_FUTURE + 1)
48#define A_UNSET (A_LAST + 2)
49#define A_UNKNOWN (A_LAST + 3)
50
51#define A_NEVER (NULL)
52
53/*
54 A_NONE is the root tech. All players always know this tech. It is
55 used as a flag in various cases where there is no tech-requirement.
56
57 A_FIRST is the first real tech id value
58
59 A_UNSET indicates that no tech is selected (for research).
60
61 A_FUTURE indicates that the player is researching a future tech.
62
63 A_UNKNOWN may be passed to other players instead of the actual value.
64
65 A_LAST is a value that is guaranteed to be larger than all
66 actual Tech_type_id values. It is used as a flag value; it can
67 also be used for fixed allocations to ensure ability to hold the
68 full number of techs.
69
70 A_NEVER is the pointer equivalent replacement for A_LAST flag value.
71*/
72
73/* Changing these breaks network compatibility. */
74/* If a new flag is added techtools.c:research_tech_lost() should be checked */
75#define SPECENUM_NAME tech_flag_id
76/* player gets extra tech if rearched first */
77#define SPECENUM_VALUE0 TF_BONUS_TECH
78/* TRANS: this and following strings are 'tech flags', which may rarely
79 * be presented to the player in ruleset help text */
80#define SPECENUM_VALUE0NAME N_("Bonus_Tech")
81/* "Settler" unit types can build bridges over rivers */
82#define SPECENUM_VALUE1 TF_BRIDGE
83#define SPECENUM_VALUE1NAME N_("Bridge")
84/* Player can build air units */
85#define SPECENUM_VALUE2 TF_BUILD_AIRBORNE
86#define SPECENUM_VALUE2NAME N_("Build_Airborne")
87/* Player can claim ocean tiles non-adjacent to border source */
88#define SPECENUM_VALUE3 TF_CLAIM_OCEAN
89#define SPECENUM_VALUE3NAME N_("Claim_Ocean")
90/* Player can claim ocean tiles non-adjacent to border source as long
91 * as source is ocean tile */
92#define SPECENUM_VALUE4 TF_CLAIM_OCEAN_LIMITED
93#define SPECENUM_VALUE4NAME N_("Claim_Ocean_Limited")
94#define SPECENUM_VALUE5 TECH_USER_1
95#define SPECENUM_VALUE6 TECH_USER_2
96#define SPECENUM_VALUE7 TECH_USER_3
97#define SPECENUM_VALUE8 TECH_USER_4
98#define SPECENUM_VALUE9 TECH_USER_5
99#define SPECENUM_VALUE10 TECH_USER_6
100#define SPECENUM_VALUE11 TECH_USER_7
101#define SPECENUM_VALUE12 TECH_USER_LAST
102/* Keep this last. */
103#define SPECENUM_COUNT TF_COUNT
104#define SPECENUM_BITVECTOR bv_tech_flags
105#define SPECENUM_NAMEOVERRIDE
106#include "specenum_gen.h"
107
108#define MAX_NUM_USER_TECH_FLAGS (TECH_USER_LAST - TECH_USER_1 + 1)
109
116
123
124struct advance {
128 char graphic_str[MAX_LEN_NAME]; /* Which named sprite to use */
129 char graphic_alt[MAX_LEN_NAME]; /* Alternate icon name */
131
134
135 /* Required to start researching this tech. For shared research it must
136 * be fulfilled for at least one player that shares the research. */
138
141
142 /*
143 * Message displayed to the first player to get a bonus tech
144 */
146
147 /* Cost of advance in bulbs. It may be specified in ruleset, or
148 * calculated in techs_precalc_data(). However, this value wouldn't
149 * be right if game.info.tech_cost_style is TECH_COST_CIV1CIV2. */
150 double cost;
151
152 /*
153 * Number of requirements this technology has _including_
154 * itself. Precalculated at server then send to client.
155 */
157};
158
160
161/* General advance/technology accessor functions. */
163
164/**********************************************************************/
170static inline Tech_type_id advance_count(void)
171{
173
174 return MIN(rc, A_LAST);
175}
176
179
181
182struct advance *valid_advance(struct advance *padvance);
184
185struct advance *advance_by_rule_name(const char *name);
186struct advance *advance_by_translated_name(const char *name);
187
188const char *advance_rule_name(const struct advance *padvance);
189const char *advance_name_translation(const struct advance *padvance);
190
191void tech_classes_init(void);
192struct tech_class *tech_class_by_number(const int idx);
193#define tech_class_index(_ptclass_) (_ptclass_)->idx
194const char *tech_class_name_translation(const struct tech_class *ptclass);
195const char *tech_class_rule_name(const struct tech_class *ptclass);
196struct tech_class *tech_class_by_rule_name(const char *name);
197
198#define tech_class_iterate(_p) \
199{ \
200 int _i_##_p; \
201 for (_i_##_p = 0; _i_##_p < game.control.num_tech_classes; _i_##_p++) { \
202 struct tech_class *_p = tech_class_by_number(_i_##_p);
203
204#define tech_class_iterate_end \
205 } \
206}
207
208#define tech_class_re_active_iterate(_p) \
209 tech_class_iterate(_p) { \
210 if (!_p->ruledit_disabled) {
211
212#define tech_class_re_active_iterate_end \
213 } \
214 } tech_class_iterate_end;
215
216void user_tech_flags_init(void);
217void user_tech_flags_free(void);
218void set_user_tech_flag_name(enum tech_flag_id id, const char *name, const char *helptxt);
219const char *tech_flag_helptxt(enum tech_flag_id id);
220
221/* General advance/technology flag accessor routines */
222bool advance_has_flag(Tech_type_id tech, enum tech_flag_id flag);
223
224/* Ancillary routines */
226 enum tech_req require);
227struct advance *advance_requires(const struct advance *padvance,
228 enum tech_req require);
229
230bool techs_have_fixed_costs(void);
231
233
234/* Initialization */
235void techs_init(void);
236void techs_free(void);
237
238void techs_precalc_data(void);
239
240/* Iteration */
241
242/* This iterates over almost all technologies. It includes non-existent
243 * technologies, but not A_FUTURE. */
244#define advance_index_iterate(_start, _index) \
245{ \
246 advance_index_iterate_max(_start, _index, advance_count())
247
248#define advance_index_iterate_end \
249 advance_index_iterate_max_end \
250}
251
252#define advance_index_iterate_max(_start, _index, _max) \
253{ \
254 Tech_type_id _index = (_start); \
255 Tech_type_id _aco_##_index = (_max); \
256 for (; _index < _aco_##_index; _index++) {
257
258#define advance_index_iterate_max_end \
259 } \
260}
261
262const struct advance *advance_array_last(void);
263
264#define advance_iterate_base(_start, _p) \
265{ \
266 struct advance *_p = advance_by_number(_start); \
267 if (NULL != _p) { \
268 for (; _p <= advance_array_last(); _p++) {
269
270#define advance_iterate_base_end \
271 } \
272 } \
273}
274
275#define advance_iterate(_p) advance_iterate_base(A_FIRST, _p)
276#define advance_iterate_end advance_iterate_base_end
277
278#define advance_iterate_all(_p) advance_iterate_base(A_NONE, _p)
279#define advance_iterate_all_end advance_iterate_base_end
280
281#define advance_re_active_iterate(_p) \
282 advance_iterate(_p) { \
283 if (_p->require[AR_ONE] != A_NEVER) {
284
285#define advance_re_active_iterate_end \
286 } \
287 } advance_iterate_end;
288
289
290/* Advance requirements iterator.
291 * Iterates over 'goal' and all its requirements (including root_reqs),
292 * recursively. */
293struct advance_req_iter;
294
295size_t advance_req_iter_sizeof(void);
297 const struct advance *goal);
298
299#define advance_req_iterate(_goal, _padvance) \
300 generic_iterate(struct advance_req_iter, const struct advance *, \
301 _padvance, advance_req_iter_sizeof, advance_req_iter_init,\
302 _goal)
303#define advance_req_iterate_end generic_iterate_end
304
305/* Iterates over all the root requirements of 'goal'.
306 * (Not including 'goal' itself, unless it is the special case of a
307 * self-root-req technology.) */
309
312 const struct advance *goal);
313
314#define advance_root_req_iterate(_goal, _padvance) \
315 generic_iterate(struct advance_root_req_iter, const struct advance *, \
316 _padvance, advance_root_req_iter_sizeof, \
317 advance_root_req_iter_init, \
318 _goal)
319#define advance_root_req_iterate_end generic_iterate_end
320
321#ifdef __cplusplus
322}
323#endif /* __cplusplus */
324
325#endif /* FC__TECH_H */
#define BV_DEFINE(name, bits)
Definition bitvector.h:132
char * incite_cost
Definition comments.c:75
int Tech_type_id
Definition fc_types.h:377
#define MAX_LEN_NAME
Definition fc_types.h:66
const char * name
Definition inputfile.c:127
#define MIN(x, y)
Definition shared.h:55
void * ruledit_dlg
Definition tech.h:127
struct requirement_vector research_reqs
Definition tech.h:137
struct tech_class * tclass
Definition tech.h:130
double cost
Definition tech.h:150
struct advance * require[AR_SIZE]
Definition tech.h:132
struct name_translation name
Definition tech.h:126
char * bonus_message
Definition tech.h:145
struct strvec * helptext
Definition tech.h:140
bool inherited_root_req
Definition tech.h:133
bv_tech_flags flags
Definition tech.h:139
int num_reqs
Definition tech.h:156
char graphic_str[MAX_LEN_NAME]
Definition tech.h:128
char graphic_alt[MAX_LEN_NAME]
Definition tech.h:129
Tech_type_id item_number
Definition tech.h:125
struct name_translation name
Definition tech.h:119
int cost_pct
Definition tech.h:121
bool ruledit_disabled
Definition tech.h:120
int idx
Definition tech.h:118
Tech_type_id advance_count_real(void)
Definition tech.c:78
#define A_ARRAY_SIZE
Definition tech.h:47
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
void tech_classes_init(void)
Definition tech.c:307
const char * tech_class_rule_name(const struct tech_class *ptclass)
Definition tech.c:342
void set_user_tech_flag_name(enum tech_flag_id id, const char *name, const char *helptxt)
Definition tech.c:394
bool is_future_tech(Tech_type_id tech)
Definition tech.c:281
struct advance * valid_advance(struct advance *padvance)
Definition tech.c:152
void techs_precalc_data(void)
Definition tech.c:225
struct advance * advance_by_translated_name(const char *name)
Definition tech.c:185
bool advance_has_flag(Tech_type_id tech, enum tech_flag_id flag)
Definition tech.c:216
size_t advance_root_req_iter_sizeof(void)
Definition tech.c:602
const char * tech_class_name_translation(const struct tech_class *ptclass)
Definition tech.c:333
struct advance * valid_advance_by_number(const Tech_type_id atype)
Definition tech.c:176
struct iterator * advance_root_req_iter_init(struct advance_root_req_iter *it, const struct advance *goal)
Definition tech.c:685
struct iterator * advance_req_iter_init(struct advance_req_iter *it, const struct advance *goal)
Definition tech.c:582
tech_req
Definition tech.h:110
@ AR_TWO
Definition tech.h:112
@ AR_ROOT
Definition tech.h:113
@ AR_ONE
Definition tech.h:111
@ AR_SIZE
Definition tech.h:114
struct advance * advance_requires(const struct advance *padvance, enum tech_req require)
Definition tech.c:136
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:290
bool techs_have_fixed_costs(void)
Definition tech.c:450
Tech_type_id advance_required(const Tech_type_id tech, enum tech_req require)
Definition tech.c:121
struct tech_class * tech_class_by_number(const int idx)
Definition tech.c:320
void techs_init(void)
Definition tech.c:459
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:299
static Tech_type_id advance_count(void)
Definition tech.h:170
const struct advance * advance_array_last(void)
Definition tech.c:67
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
const char * tech_flag_helptxt(enum tech_flag_id id)
Definition tech.c:435
void techs_free(void)
Definition tech.c:510
struct advance * advance_by_rule_name(const char *name)
Definition tech.c:200
void user_tech_flags_init(void)
Definition tech.c:370
size_t advance_req_iter_sizeof(void)
Definition tech.c:526
#define A_LAST
Definition tech.h:45
struct tech_class * tech_class_by_rule_name(const char *name)
Definition tech.c:351
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
void user_tech_flags_free(void)
Definition tech.c:382