Freeciv-3.2: /fast/freeciv/nightly/S3_2/common/research.h Source File

Freeciv-3.2

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 /* For this amount of bulbs, changing targets this turn
66 * may be done without penalty. */
67 int free_bulbs;
68
69 struct research_invention {
70 /* One of TECH_UNKNOWN, TECH_KNOWN or TECH_PREREQS_KNOWN. */
71 enum tech_state state;
72
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, bulbs_researched_saved;
79 } inventions[A_ARRAY_SIZE];
80
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;
84
85 /*
86 * Cached values. Updated by research_update().
87 */
88 int num_known_tech_with_flag[TF_COUNT];
89
90 union {
91 /* Add server side when needed */
92
93 struct {
94 /* Only used at the client (the server is omniscient; ./client/). */
95
96 int researching_cost;
97 int total_bulbs_prod;
98 } client;
99 };
100};
101
102/* Common functions. */
103void researches_init(void);
104void researches_free(void);
105
106int research_number(const struct research *presearch);
107const char *research_rule_name(const struct research *presearch);
108const char *research_name_translation(const struct research *presearch);
109int research_pretty_name(const struct research *presearch, char *buf,
110 size_t buf_len);
111
112struct research *research_by_number(int number);
113struct research *research_get(const struct player *pplayer);
114
115const char *research_advance_rule_name(const struct research *presearch,
116 Tech_type_id tech);
117const char *
118 research_advance_name_translation(const struct research *presearch,
119 Tech_type_id tech);
120
121/* Ancillary routines */
122void research_update(struct research *presearch);
123
124enum tech_state research_invention_state(const struct research *presearch,
125 Tech_type_id tech);
126enum tech_state research_invention_set(struct research *presearch,
127 Tech_type_id tech,
128 enum tech_state value);
129bool research_invention_reachable(const struct research *presearch,
130 const Tech_type_id tech);
131bool research_invention_gettable(const struct research *presearch,
132 const Tech_type_id tech,
133 bool allow_holes);
134
135 Tech_type_id research_goal_step(const struct research *presearch,
136 Tech_type_id goal);
137int research_goal_unknown_techs(const struct research *presearch,
138 Tech_type_id goal);
139int research_goal_bulbs_required(const struct research *presearch,
140 Tech_type_id goal);
141bool research_goal_tech_req(const struct research *presearch,
142 Tech_type_id goal, Tech_type_id tech);
143
144int research_total_bulbs_required(const struct research *presearch,
145 Tech_type_id tech, bool loss_value);
146
147int player_tech_upkeep(const struct player *pplayer);
148
149/* Iterating utilities. */
150struct research_iter;
151
152size_t research_iter_sizeof(void);
153struct iterator *research_iter_init(struct research_iter *it);
154
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
159
160struct research_player_iter;
161
162size_t research_player_iter_sizeof(void);
163struct iterator *research_player_iter_init(struct research_player_iter *it,
164 const struct research *presearch);
165
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
171
172int research_count(void);
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 */
incite_cost
char * incite_cost
Definition comments.c:74
fc_types.h
Tech_type_id
int Tech_type_id
Definition fc_types.h:380
iterator.h
research_goal_unknown_techs
int research_goal_unknown_techs(const struct research *presearch, Tech_type_id goal)
Definition research.c:750
research_invention_reachable
bool research_invention_reachable(const struct research *presearch, const Tech_type_id tech)
Definition research.c:668
research_goal_tech_req
bool research_goal_tech_req(const struct research *presearch, Tech_type_id goal, Tech_type_id tech)
Definition research.c:807
research_name_translation
const char * research_name_translation(const struct research *presearch)
Definition research.c:156
research_invention_set
enum tech_state research_invention_set(struct research *presearch, Tech_type_id tech, enum tech_state value)
Definition research.c:637
research_by_number
struct research * research_by_number(int number)
Definition research.c:118
research_advance_rule_name
const char * research_advance_rule_name(const struct research *presearch, Tech_type_id tech)
Definition research.c:240
player_tech_upkeep
int player_tech_upkeep(const struct player *pplayer)
Definition research.c:1050
research_future_next
bool research_future_next(const struct research *presearch)
Definition research.c:1362
research_iter_sizeof
size_t research_iter_sizeof(void)
Definition research.c:1137
researches_init
void researches_init(void)
Definition research.c:64
research_count
int research_count(void)
Definition research.c:1328
research_number
int research_number(const struct research *presearch)
Definition research.c:109
research_goal_bulbs_required
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Definition research.c:772
research_advance_name_translation
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:273
research_total_bulbs_required
int research_total_bulbs_required(const struct research *presearch, Tech_type_id tech, bool loss_value)
Definition research.c:868
research_iter_init
struct iterator * research_iter_init(struct research_iter *it)
Definition research.c:1205
recalculate_techs_researched
int recalculate_techs_researched(const struct research *presearch)
Definition research.c:1345
research_rule_name
const char * research_rule_name(const struct research *presearch)
Definition research.c:143
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:128
researches_free
void researches_free(void)
Definition research.c:100
research_invention_state
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
research_goal_step
Tech_type_id research_goal_step(const struct research *presearch, Tech_type_id goal)
Definition research.c:720
research_invention_gettable
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:693
research_player_iter_sizeof
size_t research_player_iter_sizeof(void)
Definition research.c:1227
research_player_iter_init
struct iterator * research_player_iter_init(struct research_player_iter *it, const struct research *presearch)
Definition research.c:1297
research_update
void research_update(struct research *presearch)
Definition research.c:501
research_pretty_name
int research_pretty_name(const struct research *presearch, char *buf, size_t buf_len)
Definition research.c:169
specenum_gen.h
iterator
Definition iterator.h:31
player
Definition player.h:247
research::research_invention
Definition research.h:69
research::research_invention::bulbs_required
int bulbs_required
Definition research.h:78
research::research_invention::root_reqs_known
bool root_reqs_known
Definition research.h:76
research::research_invention::bulbs_researched_saved
int bulbs_researched_saved
Definition research.h:78
research::research_invention::state
enum tech_state state
Definition research.h:71
research::research_invention::num_required_techs
int num_required_techs
Definition research.h:78
research::research_invention::reachable
bool reachable
Definition research.h:75
research::research_invention::required_techs
bv_techs required_techs
Definition research.h:77
research_iter
Definition research.c:36
research_player_iter
Definition research.c:42
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:83
research::client
struct research::@76::@78 client
research::bulbs_researching_saved
int bulbs_researching_saved
Definition research.h:63
research::inventions
struct research::research_invention inventions[A_ARRAY_SIZE]
research::researching_saved
Tech_type_id researching_saved
Definition research.h:62
research::techs_researched
int techs_researched
Definition research.h:42
research::total_bulbs_prod
int total_bulbs_prod
Definition research.h:97
research::researching_cost
int researching_cost
Definition research.h:96
research::bulbs_researched
int bulbs_researched
Definition research.h:53
research::free_bulbs
int free_bulbs
Definition research.h:67
research::num_known_tech_with_flag
int num_known_tech_with_flag[TF_COUNT]
Definition research.h:88
support.h
tech.h
A_ARRAY_SIZE
#define A_ARRAY_SIZE
Definition tech.h:47