Freeciv-3.3
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#define SPECENUM_VALUE3 TECH_USER_1
88#define SPECENUM_VALUE4 TECH_USER_2
89#define SPECENUM_VALUE5 TECH_USER_3
90#define SPECENUM_VALUE6 TECH_USER_4
91#define SPECENUM_VALUE7 TECH_USER_5
92#define SPECENUM_VALUE8 TECH_USER_6
93#define SPECENUM_VALUE9 TECH_USER_7
94#define SPECENUM_VALUE10 TECH_USER_8
95#define SPECENUM_VALUE11 TECH_USER_9
96#define SPECENUM_VALUE12 TECH_USER_LAST
97/* Keep this last. */
98#define SPECENUM_COUNT TF_COUNT
99#define SPECENUM_BITVECTOR bv_tech_flags
100#define SPECENUM_NAMEOVERRIDE
101#include "specenum_gen.h"
102
103#define MAX_NUM_USER_TECH_FLAGS (TECH_USER_LAST - TECH_USER_1 + 1)
104
111
118
119struct advance {
123 char graphic_str[MAX_LEN_NAME]; /* Which named sprite to use */
124 char graphic_alt[MAX_LEN_NAME]; /* Alternate icon name */
126
129
130 /* Required to start researching this tech. For shared research it must
131 * be fulfilled for at least one player that shares the research. */
133
136
137 /*
138 * Message displayed to the first player to get a bonus tech
139 */
141
142 /* Cost of advance in bulbs. It may be specified in ruleset, or
143 * calculated in techs_precalc_data(). However, this value wouldn't
144 * be right if game.info.tech_cost_style is TECH_COST_CIV1CIV2. */
145 double cost;
146
147 /*
148 * Number of requirements this technology has _including_
149 * itself. Precalculated at server then send to client.
150 */
152};
153
155
156/* General advance/technology accessor functions. */
158
159/**********************************************************************/
165static inline Tech_type_id advance_count(void)
166{
168
169 return MIN(rc, A_LAST);
170}
171
174
176
177struct advance *valid_advance(struct advance *padvance);
179
180struct advance *advance_by_rule_name(const char *name);
181struct advance *advance_by_translated_name(const char *name);
182
183const char *advance_rule_name(const struct advance *padvance);
184const char *advance_name_translation(const struct advance *padvance);
185
186void tech_classes_init(void);
187struct tech_class *tech_class_by_number(const int idx);
188#define tech_class_index(_ptclass_) (_ptclass_)->idx
189const char *tech_class_name_translation(const struct tech_class *ptclass);
190const char *tech_class_rule_name(const struct tech_class *ptclass);
191struct tech_class *tech_class_by_rule_name(const char *name);
192
193#define tech_class_iterate(_p) \
194{ \
195 int _i_##_p; \
196 for (_i_##_p = 0; _i_##_p < game.control.num_tech_classes; _i_##_p++) { \
197 struct tech_class *_p = tech_class_by_number(_i_##_p);
198
199#define tech_class_iterate_end \
200 } \
201}
202
203#define tech_class_re_active_iterate(_p) \
204 tech_class_iterate(_p) { \
205 if (!_p->ruledit_disabled) {
206
207#define tech_class_re_active_iterate_end \
208 } \
209 } tech_class_iterate_end;
210
211void user_tech_flags_init(void);
212void user_tech_flags_free(void);
213void set_user_tech_flag_name(enum tech_flag_id id, const char *name, const char *helptxt);
214const char *tech_flag_helptxt(enum tech_flag_id id);
215
216/* General advance/technology flag accessor routines */
217bool advance_has_flag(Tech_type_id tech, enum tech_flag_id flag);
218
219/* Ancillary routines */
221 enum tech_req require);
222struct advance *advance_requires(const struct advance *padvance,
223 enum tech_req require);
224
225bool techs_have_fixed_costs(void);
226
229
230/* Initialization */
231void techs_init(void);
232void techs_free(void);
233
234void techs_precalc_data(void);
235
236/* Iteration */
237
238/* This iterates over almost all technologies. It includes non-existent
239 * technologies, but not A_FUTURE. */
240#define advance_index_iterate(_start, _index) \
241{ \
242 advance_index_iterate_max(_start, _index, advance_count())
243
244#define advance_index_iterate_end \
245 advance_index_iterate_max_end \
246}
247
248#define advance_index_iterate_max(_start, _index, _max) \
249{ \
250 Tech_type_id _index = (_start); \
251 Tech_type_id _aco_##_index = (_max); \
252 for (; _index < _aco_##_index; _index++) {
253
254#define advance_index_iterate_max_end \
255 } \
256}
257
258const struct advance *advance_array_last(void);
259
260#define advance_iterate_base(_start, _p) \
261{ \
262 struct advance *_p = advance_by_number(_start); \
263 if (NULL != _p) { \
264 for (; _p <= advance_array_last(); _p++) {
265
266#define advance_iterate_base_end \
267 } \
268 } \
269}
270
271#define advance_iterate(_p) advance_iterate_base(A_FIRST, _p)
272#define advance_iterate_end advance_iterate_base_end
273
274#define advance_iterate_all(_p) advance_iterate_base(A_NONE, _p)
275#define advance_iterate_all_end advance_iterate_base_end
276
277#define advance_re_active_iterate(_p) \
278 advance_iterate(_p) { \
279 if (_p->require[AR_ONE] != A_NEVER) {
280
281#define advance_re_active_iterate_end \
282 } \
283 } advance_iterate_end;
284
285
286/* Advance requirements iterator.
287 * Iterates over 'goal' and all its requirements (including root_reqs),
288 * recursively. */
289struct advance_req_iter;
290
291size_t advance_req_iter_sizeof(void);
293 const struct advance *goal);
294
295#define advance_req_iterate(_goal, _padvance) \
296 generic_iterate(struct advance_req_iter, const struct advance *, \
297 _padvance, advance_req_iter_sizeof, advance_req_iter_init,\
298 _goal)
299#define advance_req_iterate_end generic_iterate_end
300
301/* Iterates over all the root requirements of 'goal'.
302 * (Not including 'goal' itself, unless it is the special case of a
303 * self-root-req technology.) */
305
308 const struct advance *goal);
309
310#define advance_root_req_iterate(_goal, _padvance) \
311 generic_iterate(struct advance_root_req_iter, const struct advance *, \
312 _padvance, advance_root_req_iter_sizeof, \
313 advance_root_req_iter_init, \
314 _goal)
315#define advance_root_req_iterate_end generic_iterate_end
316
317#ifdef __cplusplus
318}
319#endif /* __cplusplus */
320
321#endif /* FC__TECH_H */
#define BV_DEFINE(name, bits)
Definition bitvector.h:140
char * incite_cost
Definition comments.c:76
int Tech_type_id
Definition fc_types.h:236
#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:122
struct requirement_vector research_reqs
Definition tech.h:132
struct tech_class * tclass
Definition tech.h:125
double cost
Definition tech.h:145
struct advance * require[AR_SIZE]
Definition tech.h:127
struct name_translation name
Definition tech.h:121
char * bonus_message
Definition tech.h:140
struct strvec * helptext
Definition tech.h:135
bool inherited_root_req
Definition tech.h:128
bv_tech_flags flags
Definition tech.h:134
int num_reqs
Definition tech.h:151
char graphic_str[MAX_LEN_NAME]
Definition tech.h:123
char graphic_alt[MAX_LEN_NAME]
Definition tech.h:124
Tech_type_id item_number
Definition tech.h:120
struct name_translation name
Definition tech.h:114
int cost_pct
Definition tech.h:116
bool ruledit_disabled
Definition tech.h:115
int idx
Definition tech.h:113
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:317
const char * tech_class_rule_name(const struct tech_class *ptclass)
Definition tech.c:352
void set_user_tech_flag_name(enum tech_flag_id id, const char *name, const char *helptxt)
Definition tech.c:404
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:612
const char * tech_class_name_translation(const struct tech_class *ptclass)
Definition tech.c:343
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:695
struct iterator * advance_req_iter_init(struct advance_req_iter *it, const struct advance *goal)
Definition tech.c:592
tech_req
Definition tech.h:105
@ AR_TWO
Definition tech.h:107
@ AR_ROOT
Definition tech.h:108
@ AR_ONE
Definition tech.h:106
@ AR_SIZE
Definition tech.h:109
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:300
bool techs_have_fixed_costs(void)
Definition tech.c:460
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:330
void techs_init(void)
Definition tech.c:469
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:309
static Tech_type_id advance_count(void)
Definition tech.h:165
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:445
void techs_free(void)
Definition tech.c:520
struct advance * advance_by_rule_name(const char *name)
Definition tech.c:200
void user_tech_flags_init(void)
Definition tech.c:380
size_t advance_req_iter_sizeof(void)
Definition tech.c:536
#define A_LAST
Definition tech.h:45
struct tech_class * tech_class_by_rule_name(const char *name)
Definition tech.c:361
bool is_regular_advance(struct advance *padvance)
Definition tech.c:290
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
void user_tech_flags_free(void)
Definition tech.c:392