Freeciv-3.3
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 req_context *other_context,
305 const struct requirement_vector *reqs,
306 const enum req_problem_type prob_type)
307{
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 req_context *ocontext,
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 bool leakage = FALSE;
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
928 if (!leakage && get_player_bonus(pplayer, EFT_TECH_LEAKAGE)) {
929 leakage = TRUE;
930 }
932 if (0 == members) {
933 /* There is no more alive players for this research, no need to apply
934 * complicated modifiers. */
935 return base_cost * (double) game.info.sciencebox / 100.0;
936 }
937 base_cost = total_cost / members;
938
939 if (leakage) {
940 double leak = 0.0;
941
943 "Invalid tech_leakage %d", game.info.tech_leakage);
944
945 switch (game.info.tech_leakage) {
947 /* No change */
948 break;
949
951 {
952 int players = 0, players_with_tech_and_embassy = 0;
953
955 const struct research *aresearch = research_get(aplayer);
956
957 players++;
958 if (aresearch == presearch
959 || (A_FUTURE == tech
960 ? aresearch->future_tech <= presearch->future_tech
962 continue;
963 }
964
966 if (player_has_embassy(pplayer, aplayer)) {
968 break;
969 }
972
973 fc_assert_ret_val(0 < players, base_cost);
976 * game.info.tech_leak_pct / players / 100;
977 }
978 break;
979
981 {
982 int players = 0, players_with_tech = 0;
983
985 players++;
986 if (A_FUTURE == tech
989 tech)) {
991 }
993
994 fc_assert_ret_val(0 < players, base_cost);
995 fc_assert(players >= players_with_tech);
997 / players / 100;
998 }
999 break;
1000
1002 {
1003 int players = 0, players_with_tech = 0;
1004
1006 if (is_barbarian(aplayer)) {
1007 continue;
1008 }
1009 players++;
1010 if (A_FUTURE == tech
1013 tech)) {
1015 }
1017
1018 fc_assert_ret_val(0 < players, base_cost);
1019 fc_assert(players >= players_with_tech);
1021 / players / 100;
1022 }
1023 break;
1024 }
1025
1026 if (leak > base_cost) {
1027 base_cost = 0.0;
1028 } else {
1029 base_cost -= leak;
1030 }
1031 }
1032
1033 /* Assign a science penalty to the AI at easier skill levels. This code
1034 * can also be adopted to create an extra-hard AI skill level where the AI
1035 * gets science benefits. */
1036
1037 total_cost = 0.0;
1039 if (is_ai(pplayer)) {
1040 fc_assert(0 < pplayer->ai_common.science_cost);
1041 total_cost += base_cost * pplayer->ai_common.science_cost / 100.0;
1042 } else {
1043 total_cost += base_cost;
1044 }
1046 base_cost = total_cost / members;
1047
1048 base_cost *= (double) game.info.sciencebox / 100.0;
1049
1050 return MAX(base_cost, 1);
1051}
1052
1053
1054/************************************************************************/
1058int player_tech_upkeep(const struct player *pplayer)
1059{
1060 const struct research *presearch = research_get(pplayer);
1061 int f = presearch->future_tech, t = presearch->techs_researched;
1062 double tech_upkeep = 0.0;
1063 double total_research_factor;
1064 int members;
1065
1067 return 0;
1068 }
1069
1071 members = 0;
1074 + (is_ai(contributor)
1075 ? contributor->ai_common.science_cost / 100.0
1076 : 1));
1077 members++;
1079 if (0 == members) {
1080 /* No player still alive. */
1081 return 0;
1082 }
1083
1084 /* Upkeep cost for 'normal' techs (t). */
1086 "Invalid tech_cost_style %d", game.info.tech_cost_style);
1087 switch (game.info.tech_cost_style) {
1088 case TECH_COST_CIV1CIV2:
1089 /* sum_1^t x = t * (t + 1) / 2 */
1090 tech_upkeep += game.info.base_tech_cost * t * (t + 1) / 2;
1091 break;
1092 case TECH_COST_CLASSIC:
1096 case TECH_COST_LINEAR:
1100 tech_upkeep += padvance->cost;
1101 }
1103 if (0 < f) {
1104 /* Upkeep cost for future techs (f) are calculated using style 0:
1105 * sum_t^(t+f) x = (f * (2 * t + f + 1) + 2 * t) / 2 */
1106 tech_upkeep += (double) (game.info.base_tech_cost
1107 * (f * (2 * t + f + 1) + 2 * t) / 2);
1108 }
1109 break;
1110 }
1111
1112 tech_upkeep *= total_research_factor / members;
1113 tech_upkeep *= (double) game.info.sciencebox / 100.0;
1114 /* We only want to calculate the upkeep part of one player, not the
1115 * whole team! */
1116 tech_upkeep /= members;
1117 tech_upkeep /= game.info.tech_upkeep_divider;
1118
1119 switch (game.info.tech_upkeep_style) {
1120 case TECH_UPKEEP_BASIC:
1121 tech_upkeep -= get_player_bonus(pplayer, EFT_TECH_UPKEEP_FREE);
1122 break;
1124 tech_upkeep -= get_player_bonus(pplayer, EFT_TECH_UPKEEP_FREE);
1125 tech_upkeep *= city_list_size(pplayer->cities);
1126 break;
1127 case TECH_UPKEEP_NONE:
1129 tech_upkeep = 0.0;
1130 }
1131
1132 if (0.0 > tech_upkeep) {
1133 tech_upkeep = 0.0;
1134 }
1135
1136 log_debug("[%s (%d)] tech upkeep: %d", player_name(pplayer),
1137 player_number(pplayer), (int) tech_upkeep);
1138 return (int) tech_upkeep;
1139}
1140
1141
1142/************************************************************************/
1146{
1147 return sizeof(struct research_iter);
1148}
1149
1150/************************************************************************/
1153static void *research_iter_get(const struct iterator *it)
1154{
1155 return &research_array[RESEARCH_ITER(it)->index];
1156}
1157
1158/************************************************************************/
1161static void research_iter_team_next(struct iterator *it)
1162{
1163 struct research_iter *rit = RESEARCH_ITER(it);
1164
1165 if (team_slots_initialised()) {
1166 do {
1167 rit->index++;
1168 } while (rit->index < ARRAY_SIZE(research_array) && !it->valid(it));
1169 }
1170}
1171
1172/************************************************************************/
1175static bool research_iter_team_valid(const struct iterator *it)
1176{
1177 struct research_iter *rit = RESEARCH_ITER(it);
1178
1179 return (0 <= rit->index
1180 && ARRAY_SIZE(research_array) > rit->index
1181 && NULL != team_by_number(rit->index));
1182}
1183
1184/************************************************************************/
1188{
1189 struct research_iter *rit = RESEARCH_ITER(it);
1190
1192 do {
1193 rit->index++;
1194 } while (rit->index < ARRAY_SIZE(research_array) && !it->valid(it));
1195 }
1196}
1197
1198/************************************************************************/
1201static bool research_iter_player_valid(const struct iterator *it)
1202{
1203 struct research_iter *rit = RESEARCH_ITER(it);
1204
1205 return (0 <= rit->index
1206 && ARRAY_SIZE(research_array) > rit->index
1207 && NULL != player_by_number(rit->index));
1208}
1209
1210/************************************************************************/
1214{
1215 struct iterator *base = ITERATOR(it);
1216
1217 base->get = research_iter_get;
1218 it->index = -1;
1219
1223 } else {
1226 }
1227
1228 base->next(base);
1229 return base;
1230}
1231
1232/************************************************************************/
1236{
1237 return sizeof(struct research_player_iter);
1238}
1239
1240/************************************************************************/
1243static inline bool research_player_iter_valid_state(struct iterator *it)
1244{
1245 const struct player *pplayer = iterator_get(it);
1246
1247 return (NULL == pplayer || pplayer->is_alive);
1248}
1249
1250/************************************************************************/
1253static void *research_player_iter_pooled_get(const struct iterator *it)
1254{
1256}
1257
1258/************************************************************************/
1262{
1264
1265 do {
1266 rpit->plink = player_list_link_next(rpit->plink);
1267 } while (!research_player_iter_valid_state(it));
1268}
1269
1270/************************************************************************/
1273static bool research_player_iter_pooled_valid(const struct iterator *it)
1274{
1275 return NULL != RESEARCH_PLAYER_ITER(it)->plink;
1276}
1277
1278/************************************************************************/
1281static void *research_player_iter_not_pooled_get(const struct iterator *it)
1282{
1283 return RESEARCH_PLAYER_ITER(it)->pplayer;
1284}
1285
1286/************************************************************************/
1290{
1291 RESEARCH_PLAYER_ITER(it)->pplayer = NULL;
1292}
1293
1294/************************************************************************/
1298{
1299 return NULL != RESEARCH_PLAYER_ITER(it)->pplayer;
1300}
1301
1302/************************************************************************/
1306 const struct research *presearch)
1307{
1308 struct iterator *base = ITERATOR(it);
1309
1315 (presearch))));
1316 } else {
1320 it->pplayer = (NULL != presearch
1322 }
1323
1324 /* Ensure we have consistent data. */
1327 }
1328
1329 return base;
1330}
1331
1332/************************************************************************/
1337{
1338 /* TODO: Should have the value stored at the time researches are created */
1339 int count = 0;
1340
1341 researches_iterate(dummy) {
1342 (void) dummy; /* To silence warning about unused 'dummy' */
1343 count++;
1345
1346 return count;
1347}
1348
1349/************************************************************************/
1354{
1355 int techs = 1; /* A_NONE known, and not part of below iteration */
1356
1357 advance_iterate(t) {
1358 if (valid_advance(t) != NULL
1360 techs++;
1361 }
1363
1364 return techs + presearch->future_tech;
1365}
1366
1367/************************************************************************/
1371{
1374 return FALSE;
1375 }
1377
1378 return TRUE;
1379}
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
char * techs
Definition comments.c:31
char * incite_cost
Definition comments.c:76
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2956
struct @22::@23 reqs
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
int Tech_type_id
Definition fc_types.h:236
req_problem_type
Definition fc_types.h:531
@ RPT_CERTAIN
Definition fc_types.h:533
#define _(String)
Definition fcintl.h:67
#define N_(String)
Definition fcintl.h:69
struct civ_game game
Definition game.c:61
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:182
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_debug(message,...)
Definition log.h:116
#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:491
#define is_ai(plr)
Definition player.h:232
#define players_iterate_alive_end
Definition player.h:552
#define players_iterate_alive(_pplayer)
Definition player.h:547
enum req_unchanging_status is_req_preventing(const struct req_context *context, const struct req_context *other_context, 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:1058
bool research_future_next(const struct research *presearch)
Definition research.c:1370
static void * research_player_iter_not_pooled_get(const struct iterator *it)
Definition research.c:1281
static void * research_iter_get(const struct iterator *it)
Definition research.c:1153
static bool research_iter_player_valid(const struct iterator *it)
Definition research.c:1201
static void * research_player_iter_pooled_get(const struct iterator *it)
Definition research.c:1253
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:1289
size_t research_iter_sizeof(void)
Definition research.c:1145
#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:1261
int research_count(void)
Definition research.c:1336
static void research_iter_player_next(struct iterator *it)
Definition research.c:1187
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:1243
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
static bool research_allowed(const struct research *presearch, Tech_type_id tech, bool(*reqs_eval)(const struct req_context *context, const struct req_context *ocontext, const struct requirement_vector *reqs, const enum req_problem_type ptype))
Definition research.c:327
struct iterator * research_iter_init(struct research_iter *it)
Definition research.c:1213
int recalculate_techs_researched(const struct research *presearch)
Definition research.c:1353
#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:1297
static bool research_iter_team_valid(const struct iterator *it)
Definition research.c:1175
Tech_type_id research_goal_step(const struct research *presearch, Tech_type_id goal)
Definition research.c:720
static bool reqs_may_activate(const struct req_context *context, const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
Definition research.c:303
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:1273
#define RESEARCH_PLAYER_ITER(p)
Definition research.c:49
size_t research_player_iter_sizeof(void)
Definition research.c:1235
static const char * research_future_set_name(struct strvec *psv, int no, const char *new_name)
Definition research.c:219
struct iterator * research_player_iter_init(struct research_player_iter *it, const struct research *presearch)
Definition research.c:1305
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:1161
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:132
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:281
struct team * team
Definition player.h:261
bool is_alive
Definition player.h:268
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:960
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:777
#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:309
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:248
#define advance_index_iterate_end
Definition tech.h:244
#define advance_req_iterate(_goal, _padvance)
Definition tech.h:295
tech_req
Definition tech.h:105
@ AR_TWO
Definition tech.h:107
@ AR_ROOT
Definition tech.h:108
@ AR_ONE
Definition tech.h:106
@ AR_SIZE
Definition tech.h:109
#define advance_index_iterate_max_end
Definition tech.h:254
#define advance_req_iterate_end
Definition tech.h:299
static Tech_type_id advance_count(void)
Definition tech.h:165
#define A_FIRST
Definition tech.h:44
#define A_NONE
Definition tech.h:43
#define advance_root_req_iterate_end
Definition tech.h:315
#define advance_iterate(_p)
Definition tech.h:271
#define A_UNSET
Definition tech.h:48
#define advance_iterate_end
Definition tech.h:272
#define A_UNKNOWN
Definition tech.h:49
#define advance_index_iterate(_start, _index)
Definition tech.h:240
#define advance_root_req_iterate(_goal, _padvance)
Definition tech.h:310