Freeciv-3.2
Loading...
Searching...
No Matches
research.c
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#ifdef HAVE_CONFIG_H
14#include <fc_config.h>
15#endif
16
17/* utility */
18#include "iterator.h"
19#include "log.h"
20#include "shared.h"
21#include "string_vector.h"
22#include "support.h"
23
24/* common */
25#include "fc_types.h"
26#include "game.h"
27#include "nation.h"
28#include "player.h"
29#include "name_translation.h"
30#include "team.h"
31#include "tech.h"
32
33#include "research.h"
34
35
38 int index;
39};
40#define RESEARCH_ITER(p) ((struct research_iter *) p)
41
44 union {
45 struct player *pplayer;
47 };
48};
49#define RESEARCH_PLAYER_ITER(p) ((struct research_player_iter *) p)
50
51#define RESEARCH_ARRAY_SIZE MAX(MAX_NUM_PLAYER_SLOTS, MAX_NUM_TEAM_SLOTS)
53
57
58static struct strvec *future_rule_name;
60
61/************************************************************************/
65{
66 int i;
67
68 /* Ensure we have enough space for players or teams. */
71
73 for (i = 0; i < ARRAY_SIZE(research_array); i++) {
82 }
83
85
86 /* Set technology names. */
87 /* TRANS: "None" tech */
88 name_set(&advance_unset_name, NULL, N_("?tech:None"));
89 name_set(&advance_future_name, NULL, N_("Future Tech."));
90 /* TRANS: "Unknown" advance/technology */
91 name_set(&advance_unknown_name, NULL, N_("(Unknown)"));
92
95}
96
97/************************************************************************/
105
106/************************************************************************/
110{
112 return presearch - research_array;
113}
114
115/************************************************************************/
118struct research *research_by_number(int number)
119{
120 fc_assert_ret_val(0 <= number, NULL);
122 return &research_array[number];
123}
124
125/************************************************************************/
128struct research *research_get(const struct player *pplayer)
129{
130 if (NULL == pplayer) {
131 /* Special case used at client side. */
132 return NULL;
133 } else if (game.info.team_pooled_research) {
134 return &research_array[team_number(pplayer->team)];
135 } else {
136 return &research_array[player_number(pplayer)];
137 }
138}
139
140/************************************************************************/
151
152/************************************************************************/
164
165/************************************************************************/
170 size_t buf_len)
171{
172 const struct player *pplayer;
173
176
178 char buf2[buf_len];
179
180 team_pretty_name(pteam, buf2, sizeof(buf2));
181 /* TRANS: e.g. "members of team 1", or even "members of team Red".
182 * Used in many places where a nation plural might be used. */
183 return fc_snprintf(buf, buf_len, _("members of %s"), buf2);
184 } else {
186 }
187 } else {
189 }
190
192}
193
194/************************************************************************/
198static inline const struct name_translation *
200{
201 if (A_UNSET == tech) {
202 return &advance_unset_name;
203 } else if (A_FUTURE == tech) {
204 return &advance_future_name;
205 } else if (A_UNKNOWN == tech) {
206 return &advance_unknown_name;
207 } else {
208 const struct advance *padvance = advance_by_number(tech);
209
211 return &padvance->name;
212 }
213}
214
215/************************************************************************/
219static const char *research_future_set_name(struct strvec *psv, int no,
220 const char *new_name)
221{
222 if (strvec_size(psv) <= no) {
223 /* Increase the size of the vector if needed. */
224 strvec_reserve(psv, no + 1);
225 }
226
227 /* Set in vector. */
228 strvec_set(psv, no, new_name);
229
230 /* Return duplicate of 'new_name'. */
231 return strvec_get(psv, no);
232}
233
234/************************************************************************/
241 Tech_type_id tech)
242{
243 if (A_FUTURE == tech && NULL != presearch) {
244 const int no = presearch->future_tech;
245 const char *name;
246
248 if (name == NULL) {
249 char buffer[256];
250
251 /* NB: 'presearch->future_tech == 0' means "Future Tech. 1". */
252 fc_snprintf(buffer, sizeof(buffer), "%s %d",
254 no + 1);
256 }
257
258 fc_assert(name != NULL);
259
260 return name;
261 }
262
264}
265
266/************************************************************************/
272const char *
274 Tech_type_id tech)
275{
276 if (A_FUTURE == tech && NULL != presearch) {
277 const int no = presearch->future_tech;
278 const char *name;
279
281 if (name == NULL) {
282 char buffer[256];
283
284 /* NB: 'presearch->future_tech == 0' means "Future Tech. 1". */
285 fc_snprintf(buffer, sizeof(buffer), _("Future Tech. %d"), no + 1);
287 }
288
289 fc_assert(name != NULL);
290
291 return name;
292 }
293
295}
296
297/************************************************************************/
303static bool reqs_may_activate(const struct req_context *context,
304 const struct player *other_player,
305 const struct requirement_vector *reqs,
306 const enum req_problem_type prob_type)
307{
309 if (is_req_preventing(context, other_player, preq, prob_type)) {
310 return FALSE;
311 }
313 return TRUE;
314}
315
316/************************************************************************/
326static bool
328 Tech_type_id tech,
329 bool (*reqs_eval)(const struct req_context *context,
330 const struct player *oplr,
331 const struct requirement_vector *reqs,
332 const enum req_problem_type ptype))
333{
334 struct advance *adv;
335
336 adv = valid_advance_by_number(tech);
337
338 if (adv == NULL) {
339 /* Not a valid advance. */
340 return FALSE;
341 }
342
344 if (reqs_eval(&(const struct req_context) { .player = pplayer },
345 NULL, &(adv->research_reqs), RPT_CERTAIN)) {
346 /* It is enough that one player that shares research is allowed to
347 * research it.
348 * Reasoning: Imagine a tech with that requires a nation in the
349 * player range. If the requirement applies to all players sharing
350 * research it will be illegal in research sharing games. To require
351 * that the player that fulfills the requirement must order it to be
352 * researched creates unnecessary bureaucracy. */
353 return TRUE;
354 }
356
357 return FALSE;
358}
359
360/************************************************************************/
366#define research_is_allowed(presearch, tech) \
367 research_allowed(presearch, tech, are_reqs_active)
368
369/************************************************************************/
375#define research_may_become_allowed(presearch, tech) \
376 research_allowed(presearch, tech, reqs_may_activate)
377
378/************************************************************************/
385 Tech_type_id tech)
386{
387 bv_techs done;
389 enum tech_req req;
390 int techs_num;
391 int i;
392
393 techs[0] = tech;
394 BV_CLR_ALL(done);
395 BV_SET(done, A_NONE);
396 BV_SET(done, tech);
397 techs_num = 1;
398
399 /* Check that all recursive requirements have their research_reqs
400 * in order. */
401 for (i = 0; i < techs_num; i++) {
402 if (presearch->inventions[techs[i]].state == TECH_KNOWN) {
403 /* This tech is already reached. What is required to research it and
404 * the techs it depends on is therefore irrelevant. */
405 continue;
406 }
407
409 /* It will always be illegal to start researching this tech because
410 * of unchanging requirements. Since it isn't already known and can't
411 * be researched it must be unreachable. */
412 return FALSE;
413 }
414
415 /* Check if required techs are research_reqs reachable. */
416 for (req = 0; req < AR_SIZE; req++) {
418
420 return FALSE;
421 } else if (!BV_ISSET(done, req_tech)) {
424 techs_num++;
425
426 BV_SET(done, req_tech);
427 }
428 }
429 }
430
431 return TRUE;
432}
433
434/************************************************************************/
440static bool research_get_reachable(const struct research *presearch,
441 Tech_type_id tech)
442{
443 if (valid_advance_by_number(tech) == NULL) {
444 return FALSE;
445 } else {
448 /* This tech requires itself; it can only be reached by special
449 * means (init_techs, lua script, ...).
450 * If you already know it, you can "reach" it; if not, not. (This
451 * case is needed for descendants of this tech.) */
452 if (presearch->inventions[advance_number(proot)].state != TECH_KNOWN) {
453 return FALSE;
454 }
455 } else {
456 enum tech_req req;
457
458 for (req = 0; req < AR_SIZE; req++) {
460 return FALSE;
461 }
462 }
463 }
465 }
466
467 /* Check research reqs reachability. */
469 return FALSE;
470 }
471
472 return TRUE;
473}
474
475/************************************************************************/
483 Tech_type_id tech)
484{
486 if (presearch->inventions[advance_number(proot)].state != TECH_KNOWN) {
487 return FALSE;
488 }
490
491 return TRUE;
492}
493
494/************************************************************************/
502{
503 enum tech_flag_id flag;
504 int techs_researched;
506
508 enum tech_state state = presearch->inventions[i].state;
509 bool root_reqs_known = TRUE;
510 bool reachable = research_get_reachable(presearch, i);
511
512 /* Finding if the root reqs of an unreachable tech isn't redundant.
513 * A tech can be unreachable via research but have known root reqs
514 * because of unfilfilled research_reqs. Unfulfilled research_reqs
515 * doesn't prevent the player from aquiring the tech by other means. */
516 root_reqs_known = research_get_root_reqs_known(presearch, i);
517
518 if (reachable) {
519 if (state != TECH_KNOWN) {
520 /* Update state. */
521 state = (root_reqs_known
522 && (presearch->inventions[advance_required(i, AR_ONE)].state
523 == TECH_KNOWN)
524 && (presearch->inventions[advance_required(i, AR_TWO)].state
525 == TECH_KNOWN)
528 }
529 } else {
530 /* We used to assert here that state already is TECH_UNKNOWN. However, there is
531 * a special case where it can be e.g. TECH_PREREQS_KNOWN and still
532 * unreachable (like in above research_get_reachable() call) because
533 * player is dead. Dead player's don't research anything. More accurately
534 * research_players_iterate() for a dead player's research iterates over
535 * zero players in research_allowed(), so it falls through to default of FALSE.
536 *
537 * Now we set the state to TECH_UNKNOWN instead of asserting that it already is. */
538 state = TECH_UNKNOWN;
539 }
540 presearch->inventions[i].state = state;
541 presearch->inventions[i].reachable = reachable;
542 presearch->inventions[i].root_reqs_known = root_reqs_known;
543
544 /* Updates required_techs, num_required_techs and bulbs_required. */
545 BV_CLR_ALL(presearch->inventions[i].required_techs);
546 presearch->inventions[i].num_required_techs = 0;
547 presearch->inventions[i].bulbs_required = 0;
548
549 if (!reachable || state == TECH_KNOWN) {
550 continue;
551 }
552
553 techs_researched = presearch->techs_researched;
556
558 continue;
559 }
560
561 BV_SET(presearch->inventions[i].required_techs, j);
562 presearch->inventions[i].num_required_techs++;
563 presearch->inventions[i].bulbs_required +=
565 /* This is needed to get a correct result for the
566 * research_total_bulbs_required() call when
567 * game.info.game.info.tech_cost_style is TECH_COST_CIV1CIV2. */
568 presearch->techs_researched++;
570 presearch->techs_researched = techs_researched;
572
573#ifdef FREECIV_DEBUG
575 char buf[advance_count() + 1];
576
578 if (BV_ISSET(presearch->inventions[i].required_techs, j)) {
579 buf[j] = '1';
580 } else {
581 buf[j] = '0';
582 }
584 buf[advance_count()] = '\0';
585
586 log_debug("%s: [%3d] %-25s => %s%s%s",
588 i,
591 presearch->inventions[i].reachable ? "" : " [unrechable]",
592 presearch->inventions[i].root_reqs_known
593 ? "" : " [root reqs aren't known]");
594 log_debug("%s: [%3d] %s", research_rule_name(presearch), i, buf);
596#endif /* FREECIV_DEBUG */
597
598 for (flag = 0; flag <= tech_flag_id_max(); flag++) {
599 /* Iterate over all possible tech flags (0..max). */
600 presearch->num_known_tech_with_flag[flag] = 0;
601
604 && advance_has_flag(i, flag)) {
605 presearch->num_known_tech_with_flag[flag]++;
606 }
608 }
609}
610
611/************************************************************************/
620 Tech_type_id tech)
621{
624
625 if (NULL != presearch) {
626 return presearch->inventions[tech].state;
627 } else if (game.info.global_advances[tech]) {
628 return TECH_KNOWN;
629 } else {
630 return TECH_UNKNOWN;
631 }
632}
633
634/************************************************************************/
638 Tech_type_id tech,
639 enum tech_state value)
640{
641 enum tech_state old;
642
644
645 old = presearch->inventions[tech].state;
646 if (old == value) {
647 return old;
648 }
649 presearch->inventions[tech].state = value;
650
651 if (value == TECH_KNOWN) {
652 if (!game.info.global_advances[tech]) {
655 }
656 }
657
658 return old;
659}
660
661/************************************************************************/
669 const Tech_type_id tech)
670{
671 if (valid_advance_by_number(tech) == NULL) {
672 return FALSE;
673 } else if (presearch != NULL) {
674 return presearch->inventions[tech].reachable;
675 } else {
677 if (research_iter->inventions[tech].reachable) {
678 return TRUE;
679 }
681
682 return FALSE;
683 }
684}
685
686/************************************************************************/
694 const Tech_type_id tech,
695 bool allow_holes)
696{
697 if (valid_advance_by_number(tech) == NULL) {
698 return FALSE;
699 } else if (presearch != NULL) {
700 return (allow_holes
701 ? presearch->inventions[tech].root_reqs_known
702 : presearch->inventions[tech].state == TECH_PREREQS_KNOWN);
703 } else {
705 if (allow_holes
706 ? research_iter->inventions[tech].root_reqs_known
707 : research_iter->inventions[tech].state == TECH_PREREQS_KNOWN) {
708 return TRUE;
709 }
711
712 return FALSE;
713 }
714}
715
716/************************************************************************/
721 Tech_type_id goal)
722{
723 const struct advance *pgoal = valid_advance_by_number(goal);
724
725 if (NULL == pgoal
727 return A_UNSET;
728 }
729
733 return advance_number(preq);
734 case TECH_KNOWN:
735 case TECH_UNKNOWN:
736 break;
737 };
739 return A_UNSET;
740}
741
742/************************************************************************/
751 Tech_type_id goal)
752{
753 const struct advance *pgoal = valid_advance_by_number(goal);
754
755 if (NULL == pgoal) {
756 return 0;
757 } else if (NULL != presearch) {
758 return presearch->inventions[goal].num_required_techs;
759 } else {
760 return pgoal->num_reqs;
761 }
762}
763
764/************************************************************************/
773 Tech_type_id goal)
774{
775 const struct advance *pgoal = valid_advance_by_number(goal);
776
777 if (NULL == pgoal) {
778 return 0;
779 } else if (NULL != presearch) {
780 return presearch->inventions[goal].bulbs_required;
782 int base_cost = game.info.base_tech_cost * pgoal->num_reqs
783 * (pgoal->num_reqs + 1) / 2;
784
786 return game.info.min_tech_cost;
787 } else {
788 return base_cost;
789 }
790 } else {
791 int bulbs_required = 0;
792
794 bulbs_required += preq->cost;
796
797 return bulbs_required;
798 }
799}
800
801/************************************************************************/
808 Tech_type_id goal, Tech_type_id tech)
809{
810 const struct advance *pgoal, *ptech;
811
812 if (tech == goal
813 || NULL == (pgoal = valid_advance_by_number(goal))
814 || NULL == (ptech = valid_advance_by_number(tech))) {
815 return FALSE;
816 } else if (NULL != presearch) {
817 return BV_ISSET(presearch->inventions[goal].required_techs, tech);
818 } else {
820 if (preq == ptech) {
821 return TRUE;
822 }
824 return FALSE;
825 }
826}
827
828/************************************************************************/
869 Tech_type_id tech, bool loss_value)
870{
871 enum tech_cost_style tech_cost_style = game.info.tech_cost_style;
872 int members;
873 double base_cost, total_cost;
874 double leak = 0.0;
875
876 if (valid_advance_by_number(tech) == NULL) {
877 return 0;
878 }
879
880 if (!loss_value
881 && NULL != presearch
882 && !is_future_tech(tech)
884 /* A non-future tech which is already known costs nothing. */
885 return 0;
886 }
887
888 if (is_future_tech(tech)) {
889 /* Future techs use style TECH_COST_CIV1CIV2. */
890 tech_cost_style = TECH_COST_CIV1CIV2;
891 }
892
894 "Invalid tech_cost_style %d", tech_cost_style);
895 base_cost = 0.0;
896 switch (tech_cost_style) {
898 if (NULL != presearch) {
899 base_cost = game.info.base_tech_cost * presearch->techs_researched;
900 break;
901 }
902
904 fc__fallthrough; /* No break; Fallback to using preset cost. */
909 case TECH_COST_LINEAR:
910 {
911 const struct advance *padvance = valid_advance_by_number(tech);
912
913 if (NULL != padvance) {
914 base_cost = padvance->cost;
915 } else {
916 fc_assert(NULL != padvance); /* Always fails. */
917 }
918 }
919 break;
920 }
921
922 total_cost = 0.0;
923 members = 0;
925 members++;
926 total_cost += (base_cost
929 if (0 == members) {
930 /* There is no more alive players for this research, no need to apply
931 * complicated modifiers. */
932 return base_cost * (double) game.info.sciencebox / 100.0;
933 }
934 base_cost = total_cost / members;
935
937 "Invalid tech_leakage %d", game.info.tech_leakage);
938 switch (game.info.tech_leakage) {
940 /* no change */
941 break;
942
944 {
945 int players = 0, players_with_tech_and_embassy = 0;
946
948 const struct research *aresearch = research_get(aplayer);
949
950 players++;
951 if (aresearch == presearch
952 || (A_FUTURE == tech
953 ? aresearch->future_tech <= presearch->future_tech
955 continue;
956 }
957
959 if (player_has_embassy(pplayer, aplayer)) {
961 break;
962 }
965
966 fc_assert_ret_val(0 < players, base_cost);
969 * game.info.tech_leak_pct / players / 100;
970 }
971 break;
972
974 {
975 int players = 0, players_with_tech = 0;
976
978 players++;
979 if (A_FUTURE == tech
982 tech)) {
984 }
986
987 fc_assert_ret_val(0 < players, base_cost);
988 fc_assert(players >= players_with_tech);
990 / players / 100;
991 }
992 break;
993
995 {
996 int players = 0, players_with_tech = 0;
997
999 if (is_barbarian(aplayer)) {
1000 continue;
1001 }
1002 players++;
1003 if (A_FUTURE == tech
1006 tech)) {
1008 }
1010
1011 fc_assert_ret_val(0 < players, base_cost);
1012 fc_assert(players >= players_with_tech);
1014 / players / 100;
1015 }
1016 break;
1017 }
1018
1019 if (leak > base_cost) {
1020 base_cost = 0.0;
1021 } else {
1022 base_cost -= leak;
1023 }
1024
1025 /* Assign a science penalty to the AI at easier skill levels. This code
1026 * can also be adopted to create an extra-hard AI skill level where the AI
1027 * gets science benefits. */
1028
1029 total_cost = 0.0;
1031 if (is_ai(pplayer)) {
1032 fc_assert(0 < pplayer->ai_common.science_cost);
1033 total_cost += base_cost * pplayer->ai_common.science_cost / 100.0;
1034 } else {
1035 total_cost += base_cost;
1036 }
1038 base_cost = total_cost / members;
1039
1040 base_cost *= (double) game.info.sciencebox / 100.0;
1041
1042 return MAX(base_cost, 1);
1043}
1044
1045
1046/************************************************************************/
1050int player_tech_upkeep(const struct player *pplayer)
1051{
1052 const struct research *presearch = research_get(pplayer);
1053 int f = presearch->future_tech, t = presearch->techs_researched;
1054 double tech_upkeep = 0.0;
1055 double total_research_factor;
1056 int members;
1057
1059 return 0;
1060 }
1061
1063 members = 0;
1066 + (is_ai(contributor)
1067 ? contributor->ai_common.science_cost / 100.0
1068 : 1));
1069 members++;
1071 if (0 == members) {
1072 /* No player still alive. */
1073 return 0;
1074 }
1075
1076 /* Upkeep cost for 'normal' techs (t). */
1078 "Invalid tech_cost_style %d", game.info.tech_cost_style);
1079 switch (game.info.tech_cost_style) {
1080 case TECH_COST_CIV1CIV2:
1081 /* sum_1^t x = t * (t + 1) / 2 */
1082 tech_upkeep += game.info.base_tech_cost * t * (t + 1) / 2;
1083 break;
1084 case TECH_COST_CLASSIC:
1088 case TECH_COST_LINEAR:
1092 tech_upkeep += padvance->cost;
1093 }
1095 if (0 < f) {
1096 /* Upkeep cost for future techs (f) are calculated using style 0:
1097 * sum_t^(t+f) x = (f * (2 * t + f + 1) + 2 * t) / 2 */
1098 tech_upkeep += (double) (game.info.base_tech_cost
1099 * (f * (2 * t + f + 1) + 2 * t) / 2);
1100 }
1101 break;
1102 }
1103
1104 tech_upkeep *= total_research_factor / members;
1105 tech_upkeep *= (double) game.info.sciencebox / 100.0;
1106 /* We only want to calculate the upkeep part of one player, not the
1107 * whole team! */
1108 tech_upkeep /= members;
1109 tech_upkeep /= game.info.tech_upkeep_divider;
1110
1111 switch (game.info.tech_upkeep_style) {
1112 case TECH_UPKEEP_BASIC:
1113 tech_upkeep -= get_player_bonus(pplayer, EFT_TECH_UPKEEP_FREE);
1114 break;
1116 tech_upkeep -= get_player_bonus(pplayer, EFT_TECH_UPKEEP_FREE);
1117 tech_upkeep *= city_list_size(pplayer->cities);
1118 break;
1119 case TECH_UPKEEP_NONE:
1121 tech_upkeep = 0.0;
1122 }
1123
1124 if (0.0 > tech_upkeep) {
1125 tech_upkeep = 0.0;
1126 }
1127
1128 log_debug("[%s (%d)] tech upkeep: %d", player_name(pplayer),
1129 player_number(pplayer), (int) tech_upkeep);
1130 return (int) tech_upkeep;
1131}
1132
1133
1134/************************************************************************/
1138{
1139 return sizeof(struct research_iter);
1140}
1141
1142/************************************************************************/
1145static void *research_iter_get(const struct iterator *it)
1146{
1147 return &research_array[RESEARCH_ITER(it)->index];
1148}
1149
1150/************************************************************************/
1153static void research_iter_team_next(struct iterator *it)
1154{
1155 struct research_iter *rit = RESEARCH_ITER(it);
1156
1157 if (team_slots_initialised()) {
1158 do {
1159 rit->index++;
1160 } while (rit->index < ARRAY_SIZE(research_array) && !it->valid(it));
1161 }
1162}
1163
1164/************************************************************************/
1167static bool research_iter_team_valid(const struct iterator *it)
1168{
1169 struct research_iter *rit = RESEARCH_ITER(it);
1170
1171 return (0 <= rit->index
1172 && ARRAY_SIZE(research_array) > rit->index
1173 && NULL != team_by_number(rit->index));
1174}
1175
1176/************************************************************************/
1180{
1181 struct research_iter *rit = RESEARCH_ITER(it);
1182
1184 do {
1185 rit->index++;
1186 } while (rit->index < ARRAY_SIZE(research_array) && !it->valid(it));
1187 }
1188}
1189
1190/************************************************************************/
1193static bool research_iter_player_valid(const struct iterator *it)
1194{
1195 struct research_iter *rit = RESEARCH_ITER(it);
1196
1197 return (0 <= rit->index
1198 && ARRAY_SIZE(research_array) > rit->index
1199 && NULL != player_by_number(rit->index));
1200}
1201
1202/************************************************************************/
1206{
1207 struct iterator *base = ITERATOR(it);
1208
1209 base->get = research_iter_get;
1210 it->index = -1;
1211
1215 } else {
1218 }
1219
1220 base->next(base);
1221 return base;
1222}
1223
1224/************************************************************************/
1228{
1229 return sizeof(struct research_player_iter);
1230}
1231
1232/************************************************************************/
1235static inline bool research_player_iter_valid_state(struct iterator *it)
1236{
1237 const struct player *pplayer = iterator_get(it);
1238
1239 return (NULL == pplayer || pplayer->is_alive);
1240}
1241
1242/************************************************************************/
1245static void *research_player_iter_pooled_get(const struct iterator *it)
1246{
1248}
1249
1250/************************************************************************/
1254{
1256
1257 do {
1258 rpit->plink = player_list_link_next(rpit->plink);
1259 } while (!research_player_iter_valid_state(it));
1260}
1261
1262/************************************************************************/
1265static bool research_player_iter_pooled_valid(const struct iterator *it)
1266{
1267 return NULL != RESEARCH_PLAYER_ITER(it)->plink;
1268}
1269
1270/************************************************************************/
1273static void *research_player_iter_not_pooled_get(const struct iterator *it)
1274{
1275 return RESEARCH_PLAYER_ITER(it)->pplayer;
1276}
1277
1278/************************************************************************/
1282{
1283 RESEARCH_PLAYER_ITER(it)->pplayer = NULL;
1284}
1285
1286/************************************************************************/
1290{
1291 return NULL != RESEARCH_PLAYER_ITER(it)->pplayer;
1292}
1293
1294/************************************************************************/
1298 const struct research *presearch)
1299{
1300 struct iterator *base = ITERATOR(it);
1301
1307 (presearch))));
1308 } else {
1312 it->pplayer = (NULL != presearch
1314 }
1315
1316 /* Ensure we have consistent data. */
1319 }
1320
1321 return base;
1322}
1323
1324/************************************************************************/
1329{
1330 /* TODO: Should have the value stored at the time researches are created */
1331 int count = 0;
1332
1333 researches_iterate(dummy) {
1334 (void) dummy; /* To silence warning about unused 'dummy' */
1335 count++;
1337
1338 return count;
1339}
1340
1341/************************************************************************/
1346{
1347 int techs = 1; /* A_NONE known, and not part of below iteration */
1348
1349 advance_iterate(t) {
1350 if (valid_advance(t) != NULL
1352 techs++;
1353 }
1355
1356 return techs + presearch->future_tech;
1357}
1358
1359/************************************************************************/
1363{
1366 return FALSE;
1367 }
1369
1370 return TRUE;
1371}
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
char * techs
Definition comments.c:31
char * incite_cost
Definition comments.c:75
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2931
struct @21::@22 reqs
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
int Tech_type_id
Definition fc_types.h:377
req_problem_type
Definition fc_types.h:699
@ RPT_CERTAIN
Definition fc_types.h:701
#define _(String)
Definition fcintl.h:67
#define N_(String)
Definition fcintl.h:69
struct civ_game game
Definition game.c:62
const char * name
Definition inputfile.c:127
static void * iterator_get(const struct iterator *it)
Definition iterator.h:53
#define ITERATOR(p)
Definition iterator.h:37
static void iterator_next(struct iterator *it)
Definition iterator.h:42
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_debug(message,...)
Definition log.h:115
#define NAME_INIT
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)
Definition nation.c:178
struct player * player_by_number(const int player_id)
Definition player.c:849
int player_slot_count(void)
Definition player.c:418
int player_number(const struct player *pplayer)
Definition player.c:837
const char * player_name(const struct player *pplayer)
Definition player.c:895
bool player_slots_initialised(void)
Definition player.c:378
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:208
static bool is_barbarian(const struct player *pplayer)
Definition player.h:489
#define is_ai(plr)
Definition player.h:230
#define players_iterate_alive_end
Definition player.h:547
#define players_iterate_alive(_pplayer)
Definition player.h:542
enum req_unchanging_status is_req_preventing(const struct req_context *context, const struct player *other_player, const struct requirement *req, enum req_problem_type prob_type)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
int research_goal_unknown_techs(const struct research *presearch, Tech_type_id goal)
Definition research.c:750
static struct research research_array[RESEARCH_ARRAY_SIZE]
Definition research.c:52
bool research_invention_reachable(const struct research *presearch, const Tech_type_id tech)
Definition research.c:668
bool research_goal_tech_req(const struct research *presearch, Tech_type_id goal, Tech_type_id tech)
Definition research.c:807
const char * research_name_translation(const struct research *presearch)
Definition research.c:156
#define research_may_become_allowed(presearch, tech)
Definition research.c:375
enum tech_state research_invention_set(struct research *presearch, Tech_type_id tech, enum tech_state value)
Definition research.c:637
static struct name_translation advance_unknown_name
Definition research.c:56
struct research * research_by_number(int number)
Definition research.c:118
#define RESEARCH_ARRAY_SIZE
Definition research.c:51
const char * research_advance_rule_name(const struct research *presearch, Tech_type_id tech)
Definition research.c:240
int player_tech_upkeep(const struct player *pplayer)
Definition research.c:1050
bool research_future_next(const struct research *presearch)
Definition research.c:1362
static void * research_player_iter_not_pooled_get(const struct iterator *it)
Definition research.c:1273
static void * research_iter_get(const struct iterator *it)
Definition research.c:1145
static bool research_iter_player_valid(const struct iterator *it)
Definition research.c:1193
static void * research_player_iter_pooled_get(const struct iterator *it)
Definition research.c:1245
static struct name_translation advance_unset_name
Definition research.c:54
static void research_player_iter_not_pooled_next(struct iterator *it)
Definition research.c:1281
size_t research_iter_sizeof(void)
Definition research.c:1137
static bool reqs_may_activate(const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
Definition research.c:303
#define research_is_allowed(presearch, tech)
Definition research.c:366
void researches_init(void)
Definition research.c:64
static void research_player_iter_pooled_next(struct iterator *it)
Definition research.c:1253
int research_count(void)
Definition research.c:1328
static void research_iter_player_next(struct iterator *it)
Definition research.c:1179
static struct name_translation advance_future_name
Definition research.c:55
static bool research_get_root_reqs_known(const struct research *presearch, Tech_type_id tech)
Definition research.c:482
int research_number(const struct research *presearch)
Definition research.c:109
static bool research_player_iter_valid_state(struct iterator *it)
Definition research.c:1235
int research_goal_bulbs_required(const struct research *presearch, Tech_type_id goal)
Definition research.c:772
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:273
int research_total_bulbs_required(const struct research *presearch, Tech_type_id tech, bool loss_value)
Definition research.c:868
static const struct name_translation * research_advance_name(Tech_type_id tech)
Definition research.c:199
struct iterator * research_iter_init(struct research_iter *it)
Definition research.c:1205
int recalculate_techs_researched(const struct research *presearch)
Definition research.c:1345
#define RESEARCH_ITER(p)
Definition research.c:40
const char * research_rule_name(const struct research *presearch)
Definition research.c:143
static struct strvec * future_rule_name
Definition research.c:58
static bool research_get_reachable_rreqs(const struct research *presearch, Tech_type_id tech)
Definition research.c:384
struct research * research_get(const struct player *pplayer)
Definition research.c:128
void researches_free(void)
Definition research.c:100
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
static bool research_get_reachable(const struct research *presearch, Tech_type_id tech)
Definition research.c:440
static bool research_player_iter_not_pooled_valid(const struct iterator *it)
Definition research.c:1289
static bool research_iter_team_valid(const struct iterator *it)
Definition research.c:1167
Tech_type_id research_goal_step(const struct research *presearch, Tech_type_id goal)
Definition research.c:720
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:693
static bool research_player_iter_pooled_valid(const struct iterator *it)
Definition research.c:1265
#define RESEARCH_PLAYER_ITER(p)
Definition research.c:49
size_t research_player_iter_sizeof(void)
Definition research.c:1227
static const char * research_future_set_name(struct strvec *psv, int no, const char *new_name)
Definition research.c:219
static bool research_allowed(const struct research *presearch, Tech_type_id tech, bool(*reqs_eval)(const struct req_context *context, const struct player *oplr, const struct requirement_vector *reqs, const enum req_problem_type ptype))
Definition research.c:327
struct iterator * research_player_iter_init(struct research_player_iter *it, const struct research *presearch)
Definition research.c:1297
static struct strvec * future_name_translation
Definition research.c:59
void research_update(struct research *presearch)
Definition research.c:501
static void research_iter_team_next(struct iterator *it)
Definition research.c:1153
int research_pretty_name(const struct research *presearch, char *buf, size_t buf_len)
Definition research.c:169
#define research_players_iterate(_presearch, _pplayer)
Definition research.h:166
#define researches_iterate(_presearch)
Definition research.h:155
#define research_players_iterate_end
Definition research.h:170
#define researches_iterate_end
Definition research.h:158
#define ARRAY_SIZE(x)
Definition shared.h:85
#define MAX(x, y)
Definition shared.h:54
void strvec_destroy(struct strvec *psv)
bool strvec_set(struct strvec *psv, size_t svindex, const char *string)
void strvec_reserve(struct strvec *psv, size_t reserve)
const char * strvec_get(const struct strvec *psv, size_t svindex)
struct strvec * strvec_new(void)
size_t strvec_size(const struct strvec *psv)
struct requirement_vector research_reqs
Definition tech.h:137
struct packet_ruleset_control control
Definition game.h:83
struct packet_game_info info
Definition game.h:89
bool(* valid)(const struct iterator *it)
Definition iterator.h:34
enum tech_upkeep_style tech_upkeep_style
bool global_advances[A_LAST]
enum tech_leakage_style tech_leakage
enum tech_cost_style tech_cost_style
struct city_list * cities
Definition player.h:279
struct team * team
Definition player.h:259
bool is_alive
Definition player.h:266
enum tech_state state
Definition research.h:71
struct iterator vtable
Definition research.c:37
struct iterator vtable
Definition research.c:43
struct player * pplayer
Definition research.c:45
struct player_list_link * plink
Definition research.c:46
Tech_type_id researching
Definition research.h:52
int future_tech
Definition research.h:42
Tech_type_id tech_goal
Definition research.h:83
struct research::research_invention inventions[A_ARRAY_SIZE]
Tech_type_id researching_saved
Definition research.h:62
Definition team.c:40
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:791
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define fc__fallthrough
Definition support.h:119
struct team * team_by_number(const int team_id)
Definition team.c:400
const char * team_name_translation(const struct team *pteam)
Definition team.c:420
const char * team_rule_name(const struct team *pteam)
Definition team.c:410
int team_number(const struct team *pteam)
Definition team.c:391
bool team_slots_initialised(void)
Definition team.c:77
int team_pretty_name(const struct team *pteam, char *buf, size_t buf_len)
Definition team.c:432
const struct player_list * team_members(const struct team *pteam)
Definition team.c:456
int team_slot_count(void)
Definition team.c:112
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
bool is_future_tech(Tech_type_id tech)
Definition tech.c:281
struct advance * valid_advance(struct advance *padvance)
Definition tech.c:152
bool advance_has_flag(Tech_type_id tech, enum tech_flag_id flag)
Definition tech.c:216
struct advance * advance_requires(const struct advance *padvance, enum tech_req require)
Definition tech.c:136
struct advance * valid_advance_by_number(const Tech_type_id id)
Definition tech.c:176
Tech_type_id advance_required(const Tech_type_id tech, enum tech_req require)
Definition tech.c:121
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:299
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
#define A_FUTURE
Definition tech.h:46
#define advance_index_iterate_max(_start, _index, _max)
Definition tech.h:252
#define advance_index_iterate_end
Definition tech.h:248
#define advance_req_iterate(_goal, _padvance)
Definition tech.h:299
tech_req
Definition tech.h:110
@ AR_TWO
Definition tech.h:112
@ AR_ROOT
Definition tech.h:113
@ AR_ONE
Definition tech.h:111
@ AR_SIZE
Definition tech.h:114
#define advance_index_iterate_max_end
Definition tech.h:258
#define advance_req_iterate_end
Definition tech.h:303
static Tech_type_id advance_count(void)
Definition tech.h:170
#define A_FIRST
Definition tech.h:44
#define A_NONE
Definition tech.h:43
#define advance_root_req_iterate_end
Definition tech.h:319
#define advance_iterate(_p)
Definition tech.h:275
#define A_UNSET
Definition tech.h:48
#define advance_iterate_end
Definition tech.h:276
#define A_UNKNOWN
Definition tech.h:49
#define advance_index_iterate(_start, _index)
Definition tech.h:244
#define advance_root_req_iterate(_goal, _padvance)
Definition tech.h:314