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

Freeciv-3.1

Loading...
Searching...
No Matches
research.h
Go to the documentation of this file.
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.
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__RESEARCH_H
14#define FC__RESEARCH_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/* utility */
21#include "iterator.h"
22#include "support.h"
23
24/* common */
25#include "fc_types.h"
26#include "tech.h"
27
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"
38
39 struct research {
40 /* The number of techs and future techs the player has
41 * researched/acquired. */
42 int techs_researched, future_tech;
43
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.
49 *
50 * bulbs_researched tracks how many bulbs have been accumulated toward
51 * this research target. */
52 Tech_type_id researching;
53 int bulbs_researched;
54
55 /* If the player changes their research target in a turn, they lose some
56 * or all of the bulbs they've accumulated toward that target. We save
57 * the original info from the start of the turn so that if they change
58 * back they will get the bulbs back.
59 *
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;
64
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;
68 /* The same as got_tech but flipped back in choose_tech() */
69 bool got_tech_multi;
70
71 struct research_invention {
72 /* One of TECH_UNKNOWN, TECH_KNOWN or TECH_PREREQS_KNOWN. */
73 enum tech_state state;
74
75 /* Following fields are cached values. They are updated by
76 * research_update()). */
77 bool reachable;
78 bool root_reqs_known;
79 bv_techs required_techs;
80 int num_required_techs, bulbs_required, bulbs_researched_saved;
81 } inventions[A_ARRAY_SIZE];
82
83 /* Tech goal (similar to worklists; when one tech is researched the next
84 * tech toward the goal will be chosen). May be A_NONE. */
85 Tech_type_id tech_goal;
86
87 /*
88 * Cached values. Updated by research_update().
89 */
90 int num_known_tech_with_flag[TF_COUNT];
91
92 union {
93 /* Add server side when needed */
94
95 struct {
96 /* Only used at the client (the server is omniscient; ./client/). */
97
98 int researching_cost;
99 int total_bulbs_prod;
100 } client;
101 };
102};
103
104/* Common functions. */
105void researches_init(void);
106void researches_free(void);
107
108int research_number(const struct research *presearch);
109const char *research_rule_name(const struct research *presearch);
110const char *research_name_translation(const struct research *presearch);
111int research_pretty_name(const struct research *presearch, char *buf,
112 size_t buf_len);
113
114struct research *research_by_number(int number);
115struct research *research_get(const struct player *pplayer);
116
117const char *research_advance_rule_name(const struct research *presearch,
118 Tech_type_id tech);
119const char *
120 research_advance_name_translation(const struct research *presearch,
121 Tech_type_id tech);
122
123/* Ancillary routines */
124void research_update(struct research *presearch);
125
126enum tech_state research_invention_state(const struct research *presearch,
127 Tech_type_id tech);
128enum tech_state research_invention_set(struct research *presearch,
129 Tech_type_id tech,
130 enum tech_state value);
131bool research_invention_reachable(const struct research *presearch,
132 const Tech_type_id tech);
133bool research_invention_gettable(const struct research *presearch,
134 const Tech_type_id tech,
135 bool allow_holes);
136
137 Tech_type_id research_goal_step(const struct research *presearch,
138 Tech_type_id goal);
139int research_goal_unknown_techs(const struct research *presearch,
140 Tech_type_id goal);
141int research_goal_bulbs_required(const struct research *presearch,
142 Tech_type_id goal);
143bool research_goal_tech_req(const struct research *presearch,
144 Tech_type_id goal, Tech_type_id tech);
145
146int research_total_bulbs_required(const struct research *presearch,
147 Tech_type_id tech, bool loss_value);
148
149int player_tech_upkeep(const struct player *pplayer);
150
151/* Iterating utilities. */
152struct research_iter;
153
154size_t research_iter_sizeof(void);
155struct iterator *research_iter_init(struct research_iter *it);
156
157#define researches_iterate(_presearch) \
158 generic_iterate(struct research_iter, struct research *, \
159 _presearch, research_iter_sizeof, research_iter_init)
160#define researches_iterate_end generic_iterate_end
161
162struct research_player_iter;
163
164size_t research_player_iter_sizeof(void);
165struct iterator *research_player_iter_init(struct research_player_iter *it,
166 const struct research *presearch);
167
168#define research_players_iterate(_presearch, _pplayer) \
169 generic_iterate(struct research_player_iter, struct player *, _pplayer, \
170 research_player_iter_sizeof, research_player_iter_init, \
171 _presearch)
172#define research_players_iterate_end generic_iterate_end
173
174int recalculate_techs_researched(const struct research *presearch);
175
176bool research_future_next(const struct research *presearch);
177
178#ifdef __cplusplus
179}
180#endif /* __cplusplus */
181
182#endif /* FC__RESEARCH_H */
fc_types.h
Tech_type_id
int Tech_type_id
Definition fc_types.h:347
iterator.h
research_goal_unknown_techs
int research_goal_unknown_techs(const struct research *presearch, Tech_type_id goal)
Definition research.c:747
research_invention_reachable
bool research_invention_reachable(const struct research *presearch, const Tech_type_id tech)
Definition research.c:665
research_goal_tech_req
bool research_goal_tech_req(const struct research *presearch, Tech_type_id goal, Tech_type_id tech)
Definition research.c:797
research_name_translation
const char * research_name_translation(const struct research *presearch)
Definition research.c:154
research_invention_set
enum tech_state research_invention_set(struct research *presearch, Tech_type_id tech, enum tech_state value)
Definition research.c:634
research_by_number
struct research * research_by_number(int number)
Definition research.c:116
research_advance_rule_name
const char * research_advance_rule_name(const struct research *presearch, Tech_type_id tech)
Definition research.c:238
player_tech_upkeep
int player_tech_upkeep(const struct player *pplayer)
Definition research.c:1040
research_future_next
bool research_future_next(const struct research *presearch)
Definition research.c:1335
research_iter_sizeof
size_t research_iter_sizeof(void)
Definition research.c:1127
researches_init
void researches_init(void)
Definition research.c:62
research_number
int research_number(const struct research *presearch)
Definition research.c:107
research_goal_bulbs_required
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Definition research.c:769
research_advance_name_translation
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:271
research_total_bulbs_required
int research_total_bulbs_required(const struct research *presearch, Tech_type_id tech, bool loss_value)
Definition research.c:858
research_iter_init
struct iterator * research_iter_init(struct research_iter *it)
Definition research.c:1195
recalculate_techs_researched
int recalculate_techs_researched(const struct research *presearch)
Definition research.c:1318
research_rule_name
const char * research_rule_name(const struct research *presearch)
Definition research.c:141
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:126
researches_free
void researches_free(void)
Definition research.c:98
research_invention_state
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:616
research_goal_step
Tech_type_id research_goal_step(const struct research *presearch, Tech_type_id goal)
Definition research.c:717
research_invention_gettable
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:690
research_player_iter_sizeof
size_t research_player_iter_sizeof(void)
Definition research.c:1217
research_player_iter_init
struct iterator * research_player_iter_init(struct research_player_iter *it, const struct research *presearch)
Definition research.c:1287
research_update
void research_update(struct research *presearch)
Definition research.c:499
research_pretty_name
int research_pretty_name(const struct research *presearch, char *buf, size_t buf_len)
Definition research.c:167
specenum_gen.h
iterator
Definition iterator.h:31
player
Definition player.h:249
research::research_invention
Definition research.h:71
research::research_invention::bulbs_required
int bulbs_required
Definition research.h:80
research::research_invention::root_reqs_known
bool root_reqs_known
Definition research.h:78
research::research_invention::bulbs_researched_saved
int bulbs_researched_saved
Definition research.h:80
research::research_invention::state
enum tech_state state
Definition research.h:73
research::research_invention::num_required_techs
int num_required_techs
Definition research.h:80
research::research_invention::reachable
bool reachable
Definition research.h:77
research::research_invention::required_techs
bv_techs required_techs
Definition research.h:79
research_iter
Definition research.c:35
research_player_iter
Definition research.c:41
research
Definition research.h:39
research::researching
Tech_type_id researching
Definition research.h:52
research::future_tech
int future_tech
Definition research.h:42
research::tech_goal
Tech_type_id tech_goal
Definition research.h:85
research::bulbs_researching_saved
int bulbs_researching_saved
Definition research.h:63
research::client
struct research::@75::@77 client
research::inventions
struct research::research_invention inventions[A_ARRAY_SIZE]
research::got_tech_multi
bool got_tech_multi
Definition research.h:69
research::researching_saved
Tech_type_id researching_saved
Definition research.h:62
research::got_tech
bool got_tech
Definition research.h:67
research::techs_researched
int techs_researched
Definition research.h:42
research::total_bulbs_prod
int total_bulbs_prod
Definition research.h:99
research::researching_cost
int researching_cost
Definition research.h:98
research::bulbs_researched
int bulbs_researched
Definition research.h:53
research::num_known_tech_with_flag
int num_known_tech_with_flag[TF_COUNT]
Definition research.h:90
support.h
tech.h
A_ARRAY_SIZE
#define A_ARRAY_SIZE
Definition tech.h:47