Freeciv-3.1: /fast/freeciv/nightly/S3_1/common/tech.h Source File

Freeciv-3.1

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
110 enum tech_req {
111 AR_ONE = 0,
112 AR_TWO = 1,
113 AR_ROOT = 2,
114 AR_SIZE
115};
116
117 struct tech_class {
118 int idx;
119 struct name_translation name;
120 bool ruledit_disabled;
121 int cost_pct;
122};
123
124 struct advance {
125 Tech_type_id item_number;
126 struct name_translation name;
127 void *ruledit_dlg;
128 char graphic_str[MAX_LEN_NAME]; /* Which named sprite to use */
129 char graphic_alt[MAX_LEN_NAME]; /* Alternate icon name */
130 struct tech_class *tclass;
131
132 struct advance *require[AR_SIZE];
133 bool inherited_root_req;
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. */
137 struct requirement_vector research_reqs;
138
139 bv_tech_flags flags;
140 struct strvec *helptext;
141
142 /*
143 * Message displayed to the first player to get a bonus tech
144 */
145 char *bonus_message;
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 */
156 int num_reqs;
157};
158
159 BV_DEFINE(bv_techs, A_ARRAY_SIZE);
160
161/* General advance/technology accessor functions. */
162 Tech_type_id advance_count_real(void);
163
164/**********************************************************************/
170 static inline Tech_type_id advance_count(void)
171{
172 Tech_type_id rc = advance_count_real();
173
174 return MIN(rc, A_LAST);
175}
176
177 Tech_type_id advance_index(const struct advance *padvance);
178 Tech_type_id advance_number(const struct advance *padvance);
179
180struct advance *advance_by_number(const Tech_type_id atype);
181
182struct advance *valid_advance(struct advance *padvance);
183struct advance *valid_advance_by_number(const Tech_type_id atype);
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 */
225 Tech_type_id advance_required(const Tech_type_id tech,
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
232bool is_future_tech(Tech_type_id tech);
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(_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_end \
271 } \
272 } \
273}
274
275#define advance_re_active_iterate(_p) \
276 advance_iterate(A_FIRST, _p) { \
277 if (_p->require[AR_ONE] != A_NEVER) {
278
279#define advance_re_active_iterate_end \
280 } \
281 } advance_iterate_end;
282
283
284/* Advance requirements iterator.
285 * Iterates over 'goal' and all its requirements (including root_reqs),
286 * recursively. */
287struct advance_req_iter;
288
289size_t advance_req_iter_sizeof(void);
290struct iterator *advance_req_iter_init(struct advance_req_iter *it,
291 const struct advance *goal);
292
293#define advance_req_iterate(_goal, _padvance) \
294 generic_iterate(struct advance_req_iter, const struct advance *, \
295 _padvance, advance_req_iter_sizeof, advance_req_iter_init,\
296 _goal)
297#define advance_req_iterate_end generic_iterate_end
298
299/* Iterates over all the root requirements of 'goal'.
300 * (Not including 'goal' itself, unless it is the special case of a
301 * self-root-req technology.) */
302struct advance_root_req_iter;
303
304size_t advance_root_req_iter_sizeof(void);
305struct iterator *advance_root_req_iter_init(struct advance_root_req_iter *it,
306 const struct advance *goal);
307
308#define advance_root_req_iterate(_goal, _padvance) \
309 generic_iterate(struct advance_root_req_iter, const struct advance *, \
310 _padvance, advance_root_req_iter_sizeof, \
311 advance_root_req_iter_init, \
312 _goal)
313#define advance_root_req_iterate_end generic_iterate_end
314
315#ifdef __cplusplus
316}
317#endif /* __cplusplus */
318
319#endif /* FC__TECH_H */
bitvector.h
BV_DEFINE
#define BV_DEFINE(name, bits)
Definition bitvector.h:132
fc_types.h
Tech_type_id
int Tech_type_id
Definition fc_types.h:347
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
name
const char * name
Definition inputfile.c:127
name_translation.h
requirements.h
shared.h
MIN
#define MIN(x, y)
Definition shared.h:55
specenum_gen.h
advance_req_iter
Definition tech.c:38
advance_root_req_iter
Definition tech.c:46
advance
Definition tech.h:124
advance::ruledit_dlg
void * ruledit_dlg
Definition tech.h:127
advance::research_reqs
struct requirement_vector research_reqs
Definition tech.h:137
advance::tclass
struct tech_class * tclass
Definition tech.h:130
advance::cost
double cost
Definition tech.h:150
advance::require
struct advance * require[AR_SIZE]
Definition tech.h:132
advance::name
struct name_translation name
Definition tech.h:126
advance::bonus_message
char * bonus_message
Definition tech.h:145
advance::helptext
struct strvec * helptext
Definition tech.h:140
advance::inherited_root_req
bool inherited_root_req
Definition tech.h:133
advance::flags
bv_tech_flags flags
Definition tech.h:139
advance::num_reqs
int num_reqs
Definition tech.h:156
advance::graphic_str
char graphic_str[MAX_LEN_NAME]
Definition tech.h:128
advance::graphic_alt
char graphic_alt[MAX_LEN_NAME]
Definition tech.h:129
advance::item_number
Tech_type_id item_number
Definition tech.h:125
iterator
Definition iterator.h:31
name_translation
Definition name_translation.h:35
strvec
Definition string_vector.c:29
tech_class
Definition tech.h:117
tech_class::name
struct name_translation name
Definition tech.h:119
tech_class::cost_pct
int cost_pct
Definition tech.h:121
tech_class::ruledit_disabled
bool ruledit_disabled
Definition tech.h:120
tech_class::idx
int idx
Definition tech.h:118
advance_count_real
Tech_type_id advance_count_real(void)
Definition tech.c:78
A_ARRAY_SIZE
#define A_ARRAY_SIZE
Definition tech.h:47
advance_by_number
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
tech_classes_init
void tech_classes_init(void)
Definition tech.c:307
tech_class_rule_name
const char * tech_class_rule_name(const struct tech_class *ptclass)
Definition tech.c:342
set_user_tech_flag_name
void set_user_tech_flag_name(enum tech_flag_id id, const char *name, const char *helptxt)
Definition tech.c:394
is_future_tech
bool is_future_tech(Tech_type_id tech)
Definition tech.c:281
valid_advance
struct advance * valid_advance(struct advance *padvance)
Definition tech.c:152
techs_precalc_data
void techs_precalc_data(void)
Definition tech.c:225
advance_by_translated_name
struct advance * advance_by_translated_name(const char *name)
Definition tech.c:185
advance_has_flag
bool advance_has_flag(Tech_type_id tech, enum tech_flag_id flag)
Definition tech.c:216
advance_root_req_iter_sizeof
size_t advance_root_req_iter_sizeof(void)
Definition tech.c:602
tech_class_name_translation
const char * tech_class_name_translation(const struct tech_class *ptclass)
Definition tech.c:333
valid_advance_by_number
struct advance * valid_advance_by_number(const Tech_type_id atype)
Definition tech.c:176
advance_root_req_iter_init
struct iterator * advance_root_req_iter_init(struct advance_root_req_iter *it, const struct advance *goal)
Definition tech.c:685
advance_req_iter_init
struct iterator * advance_req_iter_init(struct advance_req_iter *it, const struct advance *goal)
Definition tech.c:582
tech_req
tech_req
Definition tech.h:110
AR_TWO
@ AR_TWO
Definition tech.h:112
AR_ROOT
@ AR_ROOT
Definition tech.h:113
AR_ONE
@ AR_ONE
Definition tech.h:111
AR_SIZE
@ AR_SIZE
Definition tech.h:114
advance_requires
struct advance * advance_requires(const struct advance *padvance, enum tech_req require)
Definition tech.c:136
advance_name_translation
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:290
techs_have_fixed_costs
bool techs_have_fixed_costs(void)
Definition tech.c:450
advance_required
Tech_type_id advance_required(const Tech_type_id tech, enum tech_req require)
Definition tech.c:121
tech_class_by_number
struct tech_class * tech_class_by_number(const int idx)
Definition tech.c:320
techs_init
void techs_init(void)
Definition tech.c:459
advance_rule_name
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:299
advance_count
static Tech_type_id advance_count(void)
Definition tech.h:170
advance_array_last
const struct advance * advance_array_last(void)
Definition tech.c:67
advance_index
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
tech_flag_helptxt
const char * tech_flag_helptxt(enum tech_flag_id id)
Definition tech.c:435
techs_free
void techs_free(void)
Definition tech.c:510
advance_by_rule_name
struct advance * advance_by_rule_name(const char *name)
Definition tech.c:200
user_tech_flags_init
void user_tech_flags_init(void)
Definition tech.c:370
advance_req_iter_sizeof
size_t advance_req_iter_sizeof(void)
Definition tech.c:526
A_LAST
#define A_LAST
Definition tech.h:45
tech_class_by_rule_name
struct tech_class * tech_class_by_rule_name(const char *name)
Definition tech.c:351
advance_number
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
user_tech_flags_free
void user_tech_flags_free(void)
Definition tech.c:382