Freeciv-3.4
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 researched 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_10
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 TECH_USER_LAST TECH_USER_10
104
105#define MAX_NUM_USER_TECH_FLAGS (TECH_USER_LAST - TECH_USER_1 + 1)
106
113
120
121struct advance {
125 char graphic_str[MAX_LEN_NAME]; /* Which named sprite to use */
126 char graphic_alt[MAX_LEN_NAME]; /* Alternate icon name */
128
131
132 /* Required to start researching this tech. For shared research it must
133 * be fulfilled for at least one player that shares the research. */
135
138
139 /*
140 * Message displayed to the first player to get a bonus tech
141 */
143
144 /* Cost of advance in bulbs. It may be specified in ruleset, or
145 * calculated in techs_precalc_data(). However, this value wouldn't
146 * be right if game.info.tech_cost_style is TECH_COST_CIV1CIV2. */
147 double cost;
148
149 /*
150 * Number of requirements this technology has _including_
151 * itself. Precalculated at server then send to client.
152 */
154};
155
157
158/* General advance/technology accessor functions. */
160
161/**********************************************************************/
167static inline Tech_type_id advance_count(void)
168{
170
171 return MIN(rc, A_LAST);
172}
173
176
178
179struct advance *valid_advance(struct advance *padvance);
181
182struct advance *advance_by_rule_name(const char *name);
183struct advance *advance_by_translated_name(const char *name);
184
185const char *advance_rule_name(const struct advance *padvance);
186const char *advance_name_translation(const struct advance *padvance);
187
188void tech_classes_init(void);
189struct tech_class *tech_class_by_number(const int idx);
190#define tech_class_index(_ptclass_) (_ptclass_)->idx
191const char *tech_class_name_translation(const struct tech_class *ptclass);
192const char *tech_class_rule_name(const struct tech_class *ptclass);
193struct tech_class *tech_class_by_rule_name(const char *name);
194
195#define tech_class_iterate(_p) \
196{ \
197 int _i_##_p; \
198 for (_i_##_p = 0; _i_##_p < game.control.num_tech_classes; _i_##_p++) { \
199 struct tech_class *_p = tech_class_by_number(_i_##_p);
200
201#define tech_class_iterate_end \
202 } \
203}
204
205#define tech_class_re_active_iterate(_p) \
206 tech_class_iterate(_p) { \
207 if (!_p->ruledit_disabled) {
208
209#define tech_class_re_active_iterate_end \
210 } \
211 } tech_class_iterate_end;
212
213void user_tech_flags_init(void);
214void user_tech_flags_free(void);
215void set_user_tech_flag_name(enum tech_flag_id id, const char *name, const char *helptxt);
216const char *tech_flag_helptxt(enum tech_flag_id id);
217
218/* General advance/technology flag accessor routines */
219bool advance_has_flag(Tech_type_id tech, enum tech_flag_id flag);
220
221/* Ancillary routines */
223 enum tech_req require);
224struct advance *advance_requires(const struct advance *padvance,
225 enum tech_req require);
226
227bool techs_have_fixed_costs(void);
228
231
232/* Initialization */
233void techs_init(void);
234void techs_free(void);
235
236void techs_precalc_data(void);
237
238/* Iteration */
239
240/* This iterates over almost all technologies. It includes non-existent
241 * technologies, but not A_FUTURE. */
242#define advance_index_iterate(_start, _index) \
243{ \
244 advance_index_iterate_max(_start, _index, advance_count())
245
246#define advance_index_iterate_end \
247 advance_index_iterate_max_end \
248}
249
250#define advance_index_iterate_max(_start, _index, _max) \
251{ \
252 Tech_type_id _index = (_start); \
253 Tech_type_id _aco_##_index = (_max); \
254 for (; _index < _aco_##_index; _index++) {
255
256#define advance_index_iterate_max_end \
257 } \
258}
259
260const struct advance *advance_array_last(void);
261
262#define advance_iterate_base(_start, _p) \
263{ \
264 struct advance *_p = advance_by_number(_start); \
265 if (NULL != _p) { \
266 for (; _p <= advance_array_last(); _p++) {
267
268#define advance_iterate_base_end \
269 } \
270 } \
271}
272
273#define advance_iterate(_p) advance_iterate_base(A_FIRST, _p)
274#define advance_iterate_end advance_iterate_base_end
275
276#define advance_iterate_all(_p) advance_iterate_base(A_NONE, _p)
277#define advance_iterate_all_end advance_iterate_base_end
278
279#define advance_re_active_iterate(_p) \
280 advance_iterate(_p) { \
281 if (_p->require[AR_ONE] != A_NEVER) {
282
283#define advance_re_active_iterate_end \
284 } \
285 } advance_iterate_end;
286
287
288/* Advance requirements iterator.
289 * Iterates over 'goal' and all its requirements (including root_reqs),
290 * recursively. */
291struct advance_req_iter;
292
293size_t advance_req_iter_sizeof(void);
295 const struct advance *goal);
296
297#define advance_req_iterate(_goal, _padvance) \
298 generic_iterate(struct advance_req_iter, const struct advance *, \
299 _padvance, advance_req_iter_sizeof, advance_req_iter_init,\
300 _goal)
301#define advance_req_iterate_end generic_iterate_end
302
303/* Iterates over all the root requirements of 'goal'.
304 * (Not including 'goal' itself, unless it is the special case of a
305 * self-root-req technology.) */
307
310 const struct advance *goal);
311
312#define advance_root_req_iterate(_goal, _padvance) \
313 generic_iterate(struct advance_root_req_iter, const struct advance *, \
314 _padvance, advance_root_req_iter_sizeof, \
315 advance_root_req_iter_init, \
316 _goal)
317#define advance_root_req_iterate_end generic_iterate_end
318
319#ifdef __cplusplus
320}
321#endif /* __cplusplus */
322
323#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:237
#define MAX_LEN_NAME
Definition fc_types.h:67
const char * name
Definition inputfile.c:127
#define MIN(x, y)
Definition shared.h:55
void * ruledit_dlg
Definition tech.h:124
struct requirement_vector research_reqs
Definition tech.h:134
struct tech_class * tclass
Definition tech.h:127
double cost
Definition tech.h:147
struct advance * require[AR_SIZE]
Definition tech.h:129
struct name_translation name
Definition tech.h:123
char * bonus_message
Definition tech.h:142
struct strvec * helptext
Definition tech.h:137
bool inherited_root_req
Definition tech.h:130
bv_tech_flags flags
Definition tech.h:136
int num_reqs
Definition tech.h:153
char graphic_str[MAX_LEN_NAME]
Definition tech.h:125
char graphic_alt[MAX_LEN_NAME]
Definition tech.h:126
Tech_type_id item_number
Definition tech.h:122
struct name_translation name
Definition tech.h:116
int cost_pct
Definition tech.h:118
bool ruledit_disabled
Definition tech.h:117
int idx
Definition tech.h:115
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:107
@ AR_TWO
Definition tech.h:109
@ AR_ROOT
Definition tech.h:110
@ AR_ONE
Definition tech.h:108
@ AR_SIZE
Definition tech.h:111
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:167
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