Stop sharing requirement_unit_state_ereq().
[freeciv.git] / common / research.h
blobfc4315fbfcc1a12634ff117103e43f5fa5420e99
1 /****************************************************************************
2 Freeciv - Copyright (C) 2004 - The Freeciv Team
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.
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__RESEARCH_H
14 #define FC__RESEARCH_H
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
20 /* utility */
21 #include "iterator.h"
22 #include "support.h"
24 /* common */
25 #include "fc_types.h"
26 #include "tech.h"
28 /* TECH_KNOWN is self-explanatory, TECH_PREREQS_KNOWN are those for which all
29 * requirements are fulfilled; all others (including those which can never
30 * be reached) are TECH_UNKNOWN. */
31 #define SPECENUM_NAME tech_state
32 /* TECH_UNKNOWN must be 0 as the code does no special initialisation after
33 * memset(0), See researches_init(). */
34 #define SPECENUM_VALUE0 TECH_UNKNOWN
35 #define SPECENUM_VALUE1 TECH_PREREQS_KNOWN
36 #define SPECENUM_VALUE2 TECH_KNOWN
37 #include "specenum_gen.h"
39 struct research {
40 /* The number of techs and future techs the player has
41 * researched/acquired. */
42 int techs_researched, future_tech;
44 /* Invention being researched in. Valid values for researching are:
45 * - any existing tech (not A_NONE)
46 * - A_FUTURE
47 * - A_UNSET (indicates need for choosing new research)
48 * For enemies, A_UNKNOWN is sent to the client, but not on server.
50 * bulbs_researched tracks how many bulbs have been accumulated toward
51 * this research target. */
52 Tech_type_id researching;
53 int bulbs_researched;
55 /* If the player changes his research target in a turn, he loses some or
56 * all of the bulbs he's accumulated toward that target. We save the
57 * original info from the start of the turn so that if he changes back
58 * he will get the bulbs back.
60 * Has the same values as researching, plus A_UNKNOWN used between turns
61 * (not -1 anymore) for savegames. */
62 Tech_type_id researching_saved;
63 int bulbs_researching_saved;
65 /* If the player completed a research this turn, this value is turned on
66 * and changing targets may be done without penalty. */
67 bool got_tech;
69 struct research_invention {
70 /* One of TECH_UNKNOWN, TECH_KNOWN or TECH_PREREQS_KNOWN. */
71 enum tech_state state;
73 /* Following fields are cached values. They are updated by
74 * research_update()). */
75 bool reachable;
76 bool root_reqs_known;
77 bv_techs required_techs;
78 int num_required_techs, bulbs_required;
79 } inventions[A_LAST];
81 /* Tech goal (similar to worklists; when one tech is researched the next
82 * tech toward the goal will be chosen). May be A_NONE. */
83 Tech_type_id tech_goal;
86 * Cached values. Updated by research_update().
88 int num_known_tech_with_flag[TF_COUNT];
90 union {
91 /* Add server side when needed */
93 struct {
94 /* Only used at the client (the server is omniscient; ./client/). */
96 int researching_cost;
97 int total_bulbs_prod;
98 } client;
102 /* Common functions. */
103 void researches_init(void);
104 void researches_free(void);
106 int research_number(const struct research *presearch);
107 const char *research_rule_name(const struct research *presearch);
108 const char *research_name_translation(const struct research *presearch);
109 int research_pretty_name(const struct research *presearch, char *buf,
110 size_t buf_len);
112 struct research *research_by_number(int number);
113 struct research *research_get(const struct player *pplayer);
115 const char *research_advance_rule_name(const struct research *presearch,
116 Tech_type_id tech);
117 const char *
118 research_advance_name_translation(const struct research *presearch,
119 Tech_type_id tech);
121 /* Ancillary routines */
122 void research_update(struct research *presearch);
124 enum tech_state research_invention_state(const struct research *presearch,
125 Tech_type_id tech);
126 enum tech_state research_invention_set(struct research *presearch,
127 Tech_type_id tech,
128 enum tech_state value);
129 bool research_invention_reachable(const struct research *presearch,
130 const Tech_type_id tech);
131 bool research_invention_gettable(const struct research *presearch,
132 const Tech_type_id tech,
133 bool allow_holes);
135 Tech_type_id research_goal_step(const struct research *presearch,
136 Tech_type_id goal);
137 int research_goal_unknown_techs(const struct research *presearch,
138 Tech_type_id goal);
139 int research_goal_bulbs_required(const struct research *presearch,
140 Tech_type_id goal);
141 bool research_goal_tech_req(const struct research *presearch,
142 Tech_type_id goal, Tech_type_id tech);
144 int research_total_bulbs_required(const struct research *presearch,
145 Tech_type_id tech, bool loss_value);
147 int player_tech_upkeep(const struct player *pplayer);
149 /* Iterating utilities. */
150 struct research_iter;
152 size_t research_iter_sizeof(void);
153 struct iterator *research_iter_init(struct research_iter *it);
155 #define researches_iterate(_presearch) \
156 generic_iterate(struct research_iter, struct research *, \
157 _presearch, research_iter_sizeof, research_iter_init)
158 #define researches_iterate_end generic_iterate_end
160 struct research_player_iter;
162 size_t research_player_iter_sizeof(void);
163 struct iterator *research_player_iter_init(struct research_player_iter *it,
164 const struct research *presearch);
166 #define research_players_iterate(_presearch, _pplayer) \
167 generic_iterate(struct research_player_iter, struct player *, _pplayer, \
168 research_player_iter_sizeof, research_player_iter_init, \
169 _presearch)
170 #define research_players_iterate_end generic_iterate_end
172 #ifdef __cplusplus
174 #endif /* __cplusplus */
176 #endif /* FC__RESEARCH_H */