38 #define RESEARCH_PLAYER_ITER(p) ((struct research_player_iter *) p)
84 future_rule_name->clear();
85 future_name_translation->clear();
112 if (
nullptr == pplayer) {
115 }
else if (
game.
info.team_pooled_research) {
127 if (
game.
info.team_pooled_research) {
139 if (
game.
info.team_pooled_research) {
152 if (
game.
info.team_pooled_research) {
166 const struct player *pplayer;
168 if (
game.
info.team_pooled_research) {
178 qUtf8Printable(buf2));
206 return &padvance->
name;
215 const char *new_name)
217 if (psv->count() <= no) {
223 psv->replace(no, new_name);
226 return qstrdup(qUtf8Printable(psv->at(no)));
236 if (
A_FUTURE == tech &&
nullptr != presearch) {
239 if (no >= future_rule_name->size()) {
247 return future_rule_name->at(no);
260 if (
A_FUTURE == tech &&
nullptr != presearch) {
264 if (no < future_name_translation->count()) {
266 name = future_name_translation->at(no);
268 if (
name.isEmpty()) {
272 fc_snprintf(buffer,
sizeof(buffer),
_(
"Future Tech. %d"), no + 1);
291 const struct player *other_player,
292 const struct city *target_city,
294 const struct tile *target_tile,
295 const struct unit *target_unit,
299 const struct action *target_action,
300 const struct requirement_vector *
reqs,
302 const enum vision_layer vision_layer,
303 const enum national_intelligence nintel)
309 target_building, target_tile, target_unit,
310 target_unittype, target_output, target_specialist,
311 target_action, preq, prob_type, vision_layer,
335 const struct tile *ttile,
const struct unit *tunit,
338 const struct requirement_vector *
reqs,
340 const enum national_intelligence nintel))
346 if (adv ==
nullptr) {
353 if (reqs_eval(pplayer,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
381 std::vector<Tech_type_id>
techs{tech};
387 while (!
techs.empty()) {
404 for (
int req = 0; req <
AR_SIZE; req++) {
409 }
else if (!
BV_ISSET(done, req_tech)) {
410 techs.push_back(req_tech);
443 for (
int req = 0; req <
AR_SIZE; req++) {
488 int techs_researched;
493 bool root_reqs_known =
true;
503 if (state != TECH_KNOWN) {
529 if (!reachable || state == TECH_KNOWN) {
579 :
" [root reqs aren't known]");
581 qUtf8Printable(buf));
586 for (
int flag = 0; flag <= tech_flag_id_max(); flag++) {
615 if (
nullptr != presearch) {
617 }
else if (
game.
info.global_advances[tech]) {
629 enum tech_state value)
642 if (value == TECH_KNOWN) {
643 if (!
game.
info.global_advances[tech]) {
644 game.
info.global_advances[tech] =
true;
664 }
else if (presearch !=
nullptr) {
669 if (research_iter.inventions[tech].reachable) {
691 }
else if (presearch !=
nullptr) {
698 if (allow_holes ? research_iter.inventions[tech].root_reqs_known
699 : research_iter.inventions[tech].state
700 == TECH_PREREQS_KNOWN) {
726 case TECH_PREREQS_KNOWN:
750 if (
nullptr == pgoal) {
752 }
else if (
nullptr != presearch) {
772 if (
nullptr == pgoal) {
774 }
else if (
nullptr != presearch) {
776 }
else if (
game.
info.tech_cost_style == TECH_COST_CIV1CIV2) {
780 int bulbs_required = 0;
784 return bulbs_required;
797 const struct advance *pgoal, *ptech;
802 }
else if (
nullptr != presearch) {
858 enum tech_cost_style tech_cost_style =
game.
info.tech_cost_style;
860 double base_cost, total_cost;
871 tech_cost_style = TECH_COST_CIV1CIV2;
875 "Invalid tech_cost_style %d", tech_cost_style);
877 switch (tech_cost_style) {
878 case TECH_COST_CIV1CIV2:
879 if (
nullptr != presearch) {
886 case TECH_COST_CLASSIC:
887 case TECH_COST_CLASSIC_PRESET:
888 case TECH_COST_EXPERIMENTAL:
889 case TECH_COST_EXPERIMENTAL_PRESET:
890 case TECH_COST_LINEAR: {
893 if (
nullptr != padvance) {
894 base_cost = padvance->
cost;
913 return base_cost *
static_cast<double>(
game.
info.sciencebox) / 100.0;
915 base_cost = total_cost / members;
918 "Invalid tech_leakage %d",
game.
info.tech_leakage);
920 case TECH_LEAKAGE_NONE:
924 case TECH_LEAKAGE_EMBASSIES: {
925 int players = 0, players_with_tech_and_embassy = 0;
932 if (aresearch == presearch
943 players_with_tech_and_embassy++;
952 fc_assert(players >= players_with_tech_and_embassy);
953 leak = base_cost * players_with_tech_and_embassy
954 *
game.
info.tech_leak_pct / players / 100;
957 case TECH_LEAKAGE_PLAYERS: {
958 int players = 0, players_with_tech = 0;
975 leak = base_cost * players_with_tech *
game.
info.tech_leak_pct / players
979 case TECH_LEAKAGE_NO_BARBS: {
980 int players = 0, players_with_tech = 0;
1000 leak = base_cost * players_with_tech *
game.
info.tech_leak_pct / players
1005 if (leak > base_cost) {
1018 if (
is_ai(pplayer)) {
1019 fc_assert(0 < pplayer->ai_common.science_cost);
1020 total_cost += base_cost * pplayer->ai_common.science_cost / 100.0;
1022 total_cost += base_cost;
1026 base_cost = total_cost / members;
1028 base_cost *=
static_cast<double>(
game.
info.sciencebox) / 100.0;
1030 return MAX(base_cost, 1);
1041 double tech_upkeep = 0.0;
1042 double total_research_factor;
1045 if (TECH_UPKEEP_NONE ==
game.
info.tech_upkeep_style) {
1049 total_research_factor = 0.0;
1053 total_research_factor +=
1055 + (
is_ai(contributor) ? contributor->ai_common.science_cost / 100.0
1067 "Invalid tech_cost_style %d",
game.
info.tech_cost_style);
1068 switch (
game.
info.tech_cost_style) {
1069 case TECH_COST_CIV1CIV2:
1071 tech_upkeep +=
game.
info.base_tech_cost * t * (t + 1) / 2;
1073 case TECH_COST_CLASSIC:
1074 case TECH_COST_CLASSIC_PRESET:
1075 case TECH_COST_EXPERIMENTAL:
1076 case TECH_COST_EXPERIMENTAL_PRESET:
1077 case TECH_COST_LINEAR:
1082 tech_upkeep += padvance->cost;
1089 tech_upkeep +=
static_cast<double>(
1090 game.
info.base_tech_cost * (f * (2 * t + f + 1) + 2 * t) / 2);
1095 tech_upkeep *= total_research_factor / members;
1096 tech_upkeep *=
static_cast<double>(
game.
info.sciencebox) / 100.0;
1099 tech_upkeep /= members;
1100 tech_upkeep /=
game.
info.tech_upkeep_divider;
1102 switch (
game.
info.tech_upkeep_style) {
1103 case TECH_UPKEEP_BASIC:
1106 case TECH_UPKEEP_PER_CITY:
1108 tech_upkeep *= city_list_size(pplayer->
cities);
1110 case TECH_UPKEEP_NONE:
1115 if (0.0 > tech_upkeep) {
1121 return static_cast<int>(tech_upkeep);
1158 rpit->
plink = player_list_link_next(rpit->
plink);
1202 if (
game.
info.team_pooled_research &&
nullptr != presearch) {
1206 it->
plink = player_list_head(
bool BV_ISSET(const BV &bv, int bit)
static void base(QVariant data1, QVariant data2)
Action "Build Base" for choice dialog.
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Returns the effect bonus for a player.
#define MAX_NUM_PLAYER_SLOTS
static void * iterator_get(const struct iterator *it)
static void iterator_next(struct iterator *it)
#define fc_assert_msg(condition, message,...)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define log_debug(message,...)
static void name_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name)
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
const char * nation_plural_for_player(const struct player *pplayer)
Return the (translated) plural noun of the given nation of a player.
struct player * player_by_number(const int player_id)
Return struct player pointer for the given player index.
int player_number(const struct player *pplayer)
Return the player index/number/id.
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Check if pplayer has an embassy with pplayer2.
static bool is_barbarian(const struct player *pplayer)
#define players_iterate_alive_end
#define players_iterate_alive(_pplayer)
bool is_req_active(const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, const struct requirement *req, const enum req_problem_type prob_type, const enum vision_layer vision_layer, const enum national_intelligence nintel)
Checks the requirement to see if it is active on the given target.
bool is_req_unchanging(const struct requirement *req)
Return TRUE if this is an "unchanging" requirement.
bool are_reqs_active(const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, const struct requirement_vector *reqs, const enum req_problem_type prob_type, const enum vision_layer vision_layer, const enum national_intelligence nintel)
Checks the requirement(s) to see if they are active on the given target.
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
void researches_init()
Initializes all player research structure.
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.
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...
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.
static bool research_allowed(const struct research *presearch, Tech_type_id tech, bool(*reqs_eval)(const struct player *tplr, const struct player *oplr, const struct city *tcity, const struct impr_type *tbld, const struct tile *ttile, const struct unit *tunit, const struct unit_type *tutype, const struct output_type *top, const struct specialist *tspe, const struct action *tact, const struct requirement_vector *reqs, const enum req_problem_type ptype, const enum vision_layer vlayer, const enum national_intelligence nintel))
Evaluates the legality of starting to research this tech according to reqs_eval() and the tech's rese...
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.
static struct name_translation advance_unknown_name
int player_tech_upkeep(const struct player *pplayer)
Calculate the bulb upkeep needed for all techs of a player.
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
size_t research_player_iter_sizeof()
Returns the real size of the research player iterator.
static struct name_translation advance_unset_name
static void research_player_iter_not_pooled_next(struct iterator *it)
Invalidate the iterator.
Q_GLOBAL_STATIC(QVector< QString >, future_name_translation)
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'.
const char * research_name_translation(const struct research *presearch)
Returns the name of the research owner: a player name or a team name.
static void research_player_iter_pooled_next(struct iterator *it)
Returns the next player sharing the research.
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'.
int research_number(const research *presearch)
Returns the index of the research in the array.
static struct name_translation advance_future_name
static bool research_get_root_reqs_known(const struct research *presearch, Tech_type_id tech)
Returns TRUE iff the players sharing 'presearch' already have got the knowledge of all root requireme...
static bool research_player_iter_valid_state(struct iterator *it)
Returns whether the iterator is currently at a valid state.
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Function to determine cost (in bulbs) of reaching goal technology.
int research_total_bulbs_required(const struct research *presearch, Tech_type_id tech, bool loss_value)
Function to determine cost for technology.
static const struct name_translation * research_advance_name(Tech_type_id tech)
Return the name translation for 'tech'.
static bool research_get_reachable_rreqs(const struct research *presearch, Tech_type_id tech)
Returns TRUE iff the given tech is ever reachable by the players sharing the research as far as resea...
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Returns state of the tech for current research.
static bool research_get_reachable(const struct research *presearch, Tech_type_id tech)
Returns TRUE iff the given tech is ever reachable by the players sharing the research by checking tec...
struct research * research_by_number(int number)
Returns the research for the given index.
static bool research_player_iter_not_pooled_valid(const struct iterator *it)
Returns whether the iterate is valid.
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.
static void * research_player_iter_not_pooled_get(const struct iterator *it)
Returns player of the iterator.
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.
static bool research_player_iter_pooled_valid(const struct iterator *it)
Returns whether the iterate is valid.
#define RESEARCH_PLAYER_ITER(p)
void researches_free()
Free all resources allocated for the research system.
struct iterator * research_player_iter_init(struct research_player_iter *it, const struct research *presearch)
Initializes a research player iterator.
static bool reqs_may_activate(const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, const struct requirement_vector *reqs, const enum req_problem_type prob_type, const enum vision_layer vision_layer, const enum national_intelligence nintel)
Returns TRUE iff the requirement vector may become active against the given target.
bool research_is_valid(const struct research &presearch)
Checks whether the research object is valid in the current game.
void research_update(struct research *presearch)
Mark as TECH_PREREQS_KNOWN each tech which is available, not known and which has all requirements ful...
static void * research_player_iter_pooled_get(const struct iterator *it)
Returns player of the iterator.
static const char * research_future_set_name(QVector< QString > *psv, int no, const char *new_name)
Set a new future tech name in the string vector, and return the string duplicate stored inside the ve...
const char * research_rule_name(const struct research *presearch)
Returns the name of the research owner: a player name or a team name.
std::vector< research > research_array(MAX_NUM_PLAYER_SLOTS)
int research_pretty_name(const struct research *presearch, char *buf, size_t buf_len)
Set in 'buf' the name of the research owner.
#define research_players_iterate(_presearch, _pplayer)
#define research_players_iterate_end
struct requirement_vector research_reqs
struct name_translation name
struct packet_game_info info
struct city_list * cities
int bulbs_researched_saved
struct player_list_link * plink
Tech_type_id researching_saved
struct research::research_invention inventions[A_LAST]
int num_known_tech_with_flag[TF_COUNT]
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
size_t fc_strlcpy(char *dest, const char *src, size_t n)
fc_strlcpy() provides utf-8 version of (non-standard) function strlcpy() It is intended as more user-...
struct team * team_by_number(const int team_id)
Return struct team pointer for the given team index.
const char * team_name_translation(const struct team *pteam)
Returns the name (translated) of the team.
const char * team_rule_name(const struct team *pteam)
Returns the name (untranslated) of the team.
int team_pretty_name(const struct team *pteam, QString &buf)
Set in 'buf' the name of the team 'pteam' in a format like "team <team_name>".
int team_number(const struct team *pteam)
Return the team index/number/id.
const struct player_list * team_members(const struct team *pteam)
Returns the member list of the team.
int team_slot_count()
Returns the total number of team slots (including used slots).
bool is_future_tech(Tech_type_id tech)
Is the given tech a future tech.
bool advance_has_flag(Tech_type_id tech, enum tech_flag_id flag)
Return TRUE if the tech has this flag otherwise FALSE.
struct advance * valid_advance(struct advance *padvance)
Returns pointer when the advance "exists" in this game, returns nullptr otherwise.
struct advance * advance_requires(const struct advance *padvance, enum tech_req require)
Accessor for requirements.
const char * advance_rule_name(const struct advance *padvance)
Return the (untranslated) rule name of the advance/technology.
struct advance * advance_by_number(const Tech_type_id atype)
Return the advance for the given advance index.
Tech_type_id advance_required(const Tech_type_id tech, enum tech_req require)
Accessor for requirements.
struct advance * valid_advance_by_number(const Tech_type_id id)
Returns pointer when the advance "exists" in this game, returns nullptr otherwise.
Tech_type_id advance_count()
Return the number of advances/technologies.
Tech_type_id advance_number(const struct advance *padvance)
Return the advance index.
#define advance_index_iterate_end
#define advance_req_iterate(_goal, _padvance)
#define advance_iterate(_start, _p)
#define advance_req_iterate_end
#define advance_root_req_iterate_end
#define advance_iterate_end
#define advance_index_iterate(_start, _index)
#define advance_root_req_iterate(_goal, _padvance)