Freeciv21
Develop your civilization from humble roots to a global empire
research.h
Go to the documentation of this file.
1 /***********************************************************************
2 _ ._ Copyright (c) 1996-2021 Freeciv21 and Freeciv contributors.
3  \ | This file is part of Freeciv21. Freeciv21 is free software: you
4  \_| can redistribute it and/or modify it under the terms of the
5  .' '. GNU General Public License as published by the Free
6  :O O: Software Foundation, either version 3 of the License,
7  '/ \' or (at your option) any later version. You should have
8  :X: received a copy of the GNU General Public License along with
9  :X: Freeciv21. If not, see https://www.gnu.org/licenses/.
10 ***********************************************************************/
11 #pragma once
12 
13 // utility
14 #include "iterator.h"
15 #include "support.h"
16 
17 // common
18 #include "fc_types.h"
19 #include "tech.h"
20 
21 /* TECH_KNOWN is self-explanatory, TECH_PREREQS_KNOWN are those for which all
22  * requirements are fulfilled; all others (including those which can never
23  * be reached) are TECH_UNKNOWN. */
24 #define SPECENUM_NAME tech_state
25 /* TECH_UNKNOWN must be 0 as the code does no special initialisation after
26  * memset(0), See researches_init(). */
27 #define SPECENUM_VALUE0 TECH_UNKNOWN
28 #define SPECENUM_VALUE1 TECH_PREREQS_KNOWN
29 #define SPECENUM_VALUE2 TECH_KNOWN
30 #include "specenum_gen.h"
31 
32 struct research {
33  /* The number of techs and future techs the player has
34  * researched/acquired. */
36 
37  /* Invention being researched in. Valid values for researching are:
38  * - any existing tech (not A_NONE)
39  * - A_FUTURE
40  * - A_UNSET (indicates need for choosing new research)
41  * For enemies, A_UNKNOWN is sent to the client, but not on server.
42  *
43  * bulbs_researched tracks how many bulbs have been accumulated toward
44  * this research target. */
47 
48  /* If the player changes his research target in a turn, he loses some or
49  * all of the bulbs he's accumulated toward that target. We save the
50  * original info from the start of the turn so that if he changes back
51  * he will get the bulbs back.
52  *
53  * Has the same values as researching, plus A_UNKNOWN used between turns
54  * (not -1 anymore) for savegames. */
57 
58  /* If the player completed a research this turn, this value is turned on
59  * and changing targets may be done without penalty. */
60  bool got_tech;
61  // The same as got_tech but flipped back in choose_tech()
63 
65  // One of TECH_UNKNOWN, TECH_KNOWN or TECH_PREREQS_KNOWN.
66  enum tech_state state;
67 
68  /* Following fields are cached values. They are updated by
69  * research_update()). */
70  bool reachable;
72  bv_techs required_techs;
75 
76  /* Tech goal (similar to worklists; when one tech is researched the next
77  * tech toward the goal will be chosen). May be A_NONE. */
79 
80  /*
81  * Cached values. Updated by research_update().
82  */
83  int num_known_tech_with_flag[TF_COUNT];
84 
85  union {
86  // Add server side when needed
87 
88  struct {
89  /* Only used at the client (the server is omniscient; ./client/). */
90 
93  } client;
94  };
95 };
96 
97 extern std::vector<research> research_array;
98 // Common functions.
99 void researches_init();
100 void researches_free();
101 
102 int research_number(const struct research *presearch);
103 const char *research_rule_name(const struct research *presearch);
104 const char *research_name_translation(const struct research *presearch);
105 int research_pretty_name(const struct research *presearch, char *buf,
106  size_t buf_len);
107 
108 struct research *research_by_number(int number);
109 struct research *research_get(const struct player *pplayer);
110 bool research_is_valid(const struct research &presearch);
111 
112 QString research_advance_rule_name(const struct research *presearch,
113  Tech_type_id tech);
114 QString research_advance_name_translation(const struct research *presearch,
115  Tech_type_id tech);
116 
117 // Ancillary routines
118 void research_update(struct research *presearch);
119 
120 enum tech_state research_invention_state(const struct research *presearch,
121  Tech_type_id tech);
122 enum tech_state research_invention_set(struct research *presearch,
123  Tech_type_id tech,
124  enum tech_state value);
125 bool research_invention_reachable(const struct research *presearch,
126  const Tech_type_id tech);
127 bool research_invention_gettable(const struct research *presearch,
128  const Tech_type_id tech, bool allow_holes);
129 
130 Tech_type_id research_goal_step(const struct research *presearch,
131  Tech_type_id goal);
132 int research_goal_unknown_techs(const struct research *presearch,
133  Tech_type_id goal);
134 int research_goal_bulbs_required(const struct research *presearch,
135  Tech_type_id goal);
136 bool research_goal_tech_req(const struct research *presearch,
137  Tech_type_id goal, Tech_type_id tech);
138 
139 int research_total_bulbs_required(const struct research *presearch,
140  Tech_type_id tech, bool loss_value);
141 
142 int player_tech_upkeep(const struct player *pplayer);
143 
144 // Iterating utilities.
145 struct research_player_iter;
146 
149  const struct research *presearch);
150 
151 #define research_players_iterate(_presearch, _pplayer) \
152  generic_iterate(struct research_player_iter, struct player *, _pplayer, \
153  research_player_iter_sizeof, research_player_iter_init, \
154  _presearch)
155 #define research_players_iterate_end generic_iterate_end
int Tech_type_id
Definition: fc_types.h:294
void researches_init()
Initializes all player research structure.
Definition: research.cpp:50
int research_goal_unknown_techs(const struct research *presearch, Tech_type_id goal)
Returns the number of technologies the player need to research to get the goal technology.
Definition: research.cpp:745
bool research_invention_reachable(const struct research *presearch, const Tech_type_id tech)
Returns TRUE iff the given tech is ever reachable via research by the players sharing the research by...
Definition: research.cpp:659
bool research_goal_tech_req(const struct research *presearch, Tech_type_id goal, Tech_type_id tech)
Returns if the given tech has to be researched to reach the goal.
Definition: research.cpp:794
enum tech_state research_invention_set(struct research *presearch, Tech_type_id tech, enum tech_state value)
Set research knowledge about tech to given state.
Definition: research.cpp:627
int player_tech_upkeep(const struct player *pplayer)
Calculate the bulb upkeep needed for all techs of a player.
Definition: research.cpp:1037
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
Definition: research.cpp:110
size_t research_player_iter_sizeof()
Returns the real size of the research player iterator.
Definition: research.cpp:1127
QString research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Store the translated name of the given tech (including A_FUTURE) in 'buf'.
Definition: research.cpp:257
const char * research_name_translation(const struct research *presearch)
Returns the name of the research owner: a player name or a team name.
Definition: research.cpp:150
QString research_advance_rule_name(const struct research *presearch, Tech_type_id tech)
Store the rule name of the given tech (including A_FUTURE) in 'buf'.
Definition: research.cpp:233
int research_number(const struct research *presearch)
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Function to determine cost (in bulbs) of reaching goal technology.
Definition: research.cpp:767
int research_total_bulbs_required(const struct research *presearch, Tech_type_id tech, bool loss_value)
Function to determine cost for technology.
Definition: research.cpp:855
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Returns state of the tech for current research.
Definition: research.cpp:609
struct research * research_by_number(int number)
Returns the research for the given index.
Definition: research.cpp:100
Tech_type_id research_goal_step(const struct research *presearch, Tech_type_id goal)
Return the next tech we should research to advance towards our goal.
Definition: research.cpp:714
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Returns TRUE iff the given tech can be given to the players sharing the research immediately.
Definition: research.cpp:686
std::vector< research > research_array
void researches_free()
Free all resources allocated for the research system.
Definition: research.cpp:82
struct iterator * research_player_iter_init(struct research_player_iter *it, const struct research *presearch)
Initializes a research player iterator.
Definition: research.cpp:1197
bool research_is_valid(const struct research &presearch)
Checks whether the research object is valid in the current game.
Definition: research.cpp:125
void research_update(struct research *presearch)
Mark as TECH_PREREQS_KNOWN each tech which is available, not known and which has all requirements ful...
Definition: research.cpp:486
const char * research_rule_name(const struct research *presearch)
Returns the name of the research owner: a player name or a team name.
Definition: research.cpp:137
int research_pretty_name(const struct research *presearch, char *buf, size_t buf_len)
Set in 'buf' the name of the research owner.
Definition: research.cpp:163
Definition: player.h:231
enum tech_state state
Definition: research.h:66
Tech_type_id researching
Definition: research.h:45
struct research::@71::@73 client
int future_tech
Definition: research.h:35
Tech_type_id tech_goal
Definition: research.h:78
int bulbs_researching_saved
Definition: research.h:56
bool got_tech_multi
Definition: research.h:62
Tech_type_id researching_saved
Definition: research.h:55
bool got_tech
Definition: research.h:60
int techs_researched
Definition: research.h:35
int total_bulbs_prod
Definition: research.h:92
int researching_cost
Definition: research.h:91
struct research::research_invention inventions[A_LAST]
int bulbs_researched
Definition: research.h:46
int num_known_tech_with_flag[TF_COUNT]
Definition: research.h:83
#define A_LAST
Definition: tech.h:38