Freeciv-3.2
Loading...
Searching...
No Matches
techtools.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2005 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 "astring.h"
19#include "fcintl.h"
20#include "log.h"
21#include "mem.h"
22#include "rand.h"
23#include "shared.h"
24#include "support.h"
25
26/* common */
27#include "game.h"
28#include "government.h"
29#include "movement.h"
30#include "player.h"
31#include "research.h"
32#include "tech.h"
33#include "unit.h"
34
35/* common/scriptcore */
36#include "luascript_types.h"
37
38/* server */
39#include "citytools.h"
40#include "cityturn.h"
41#include "connecthand.h"
42#include "gamehand.h"
43#include "maphand.h"
44#include "notify.h"
45#include "plrhand.h"
46#include "unittools.h"
47
48/* server/scripting */
49#include "script_server.h"
50
51#include "techtools.h"
52
53/* Define this to add information about tech upkeep. */
54#undef TECH_UPKEEP_DEBUGGING
55
56static Tech_type_id
60static void research_tech_lost(struct research *presearch,
61 Tech_type_id tech);
62static void forget_tech_transferred(struct player *pplayer, Tech_type_id tech);
63
64/************************************************************************/
69{
71 return;
72 }
73 presearch->bulbs_researched -=
75 * penalty_percent) / 100;
76 presearch->researching_saved = A_UNKNOWN;
77}
78
79/************************************************************************/
85 struct player *originating_plr, struct advance *tech,
86 const char *reason)
87{
88 /* Emit signal for individual player whose action triggered the
89 * tech first */
90 if (originating_plr) {
92 script_server_signal_emit("tech_researched", tech, originating_plr,
93 reason);
94 }
95
96 /* Emit signal to remaining research teammates, if any */
98 if (member != originating_plr) {
99 script_server_signal_emit("tech_researched", tech, member, reason);
100 }
102}
103
104/************************************************************************/
108{
109 char research_name[MAX_LEN_NAME * 2];
110 /* Cache researched technology for event signal, because found_new_tech()
111 * changes the research target. */
113
115 /* Players will be notified when new tech is chosen. */
118 _("The %s have researched %s."),
121
122 /* Deduct tech cost. */
124 FALSE);
126 if (j == research->researching) {
129 }
131
132
133 /* Do all the updates needed after finding new tech. */
135
136 script_tech_learned(research, NULL, advance_by_number(tech), "researched");
137}
138
139/************************************************************************/
143void do_tech_parasite_effects(struct player *pplayer)
144{
147 struct effect_list *plist;
148 struct astring effects;
149 struct research *plr_research;
150 char research_name[MAX_LEN_NAME * 2];
151 const char *advance_name;
152 Tech_type_id tech;
153 /* Note that two EFT_TECH_PARASITE* effects will combine into a single,
154 * much worse effect. */
155 int mod_abs;
156 int mod_pct;
157 int mod;
158 int num_techs;
159 int rcount = research_count();
160
163
164 mod = (rcount * mod_pct) / 100;
165
166 if (mod <= 0 && mod_abs <= 0) {
167 /* No effects. */
170 return;
171 }
172
173 if (mod > 0 && (mod_abs <= 0 || mod_abs > mod)) {
176 } else {
177 mod = mod_abs;
180 }
181
182 /* Pick a random technology. */
183 tech = A_UNSET;
184 num_techs = 0;
185 plr_research = research_get(pplayer);
187 int num_teams;
188
192 continue;
193 }
194
195 num_teams = 0;
198 if (mod <= ++num_teams) {
199 if (0 == fc_rand(++num_techs)) {
200 tech = i;
201 }
202 break;
203 }
204 }
207
208 if (A_UNSET == tech) {
209 /* No tech found. */
211 return;
212 }
213
214 /* Notify. */
219
221 /* TRANS: Tech from source of an effect
222 * (Great Library) */
223 Q_("?fromeffect:%s acquired from %s!"),
225 astr_str(&effects));
227 /* TRANS: Tech from source of an effect
228 * (Great Library) */
229 Q_("?fromeffect:%s acquired from %s's %s!"),
231 player_name(pplayer),
232 astr_str(&effects));
234 /* TRANS: Tech from source of an effect
235 * (Great Library) */
236 Q_("?fromeffect:The %s have acquired %s from %s."),
239 astr_str(&effects));
240
243
244 /* Really get tech. */
247
249 script_server_signal_emit("tech_researched", advance_by_number(tech),
250 member, "stolen");
252}
253
254/************************************************************************/
257static inline void
259 const struct research *presearch)
260{
261 packet->id = research_number(presearch);
262 packet->techs_researched = presearch->techs_researched;
263 packet->future_tech = presearch->future_tech;
264 packet->researching = presearch->researching;
265 packet->researching_cost =
266 (packet->researching != A_UNSET
268 FALSE) : 0);
269 packet->bulbs_researched = presearch->bulbs_researched;
270 packet->tech_goal = presearch->tech_goal;
271 packet->total_bulbs_prod = 0;
273 city_list_iterate(pplayer->cities, pcity) {
274 packet->total_bulbs_prod += pcity->surplus[O_SCIENCE];
278 packet->inventions[i] = presearch->inventions[i].state + '0';
280 packet->inventions[advance_count()] = '\0';
281 packet->tech_goal = presearch->tech_goal;
282#ifdef FREECIV_DEBUG
283 log_verbose("Research nb %d inventions: %s",
285 packet->inventions);
286#endif /* FREECIV_DEBUG */
287}
288
289/************************************************************************/
294 const struct conn_list *dest)
295{
298 const struct player *pplayer;
299
301 if (NULL == dest) {
302 dest = game.est_connections;
303 }
304
305 /* Packaging */
308 restricted_info.tech_goal = A_UNSET;
309 restricted_info.total_bulbs_prod = 0;
311
312 conn_list_iterate(dest, pconn) {
313 pplayer = conn_get_player(pconn);
314 if (NULL != pplayer) {
315 if (presearch == research_get(pplayer)) {
316 /* Case research owner. */
318 } else {
319 /* 'pplayer' may have an embassy for looking to 'presearch'. */
320 bool embassy = FALSE;
321
323 if (team_has_embassy(pplayer->team, powner)) {
324 embassy = TRUE;
325 break;
326 }
328
329 if (embassy) {
331 } else {
333 }
334 }
335 } else if (pconn->observer) {
336 /* Case global observer. */
338 }
340}
341
342/************************************************************************/
348 bool was_discovery, bool saving_bulbs)
349{
352 bool was_first = FALSE;
353 bool bonus_tech_hack = FALSE;
354 int i;
355 const char *advance_name;
357 struct city *pcity;
358
360
361#ifndef FREECIV_NDEBUG
362 fc_assert(NULL != vap);
364#endif /* FREECIV_NDEBUG */
365
367 }
368
369 /* Assign 'advance_name' before we increase the future tech counter. */
371
372 if (was_first && vap) {
373 /* Alert the owners of any wonders that have been made obsolete */
374 improvement_iterate(pimprove) {
375 requirement_vector_iterate(&pimprove->obsolete_by, pobs) {
376 if (pobs->source.kind == VUT_ADVANCE
377 && pobs->source.value.advance == vap
378 && pobs->range >= REQ_RANGE_WORLD
379 && pobs->present
380 && pobs->survives
381 && is_great_wonder(pimprove)
382 && (pcity = city_from_great_wonder(pimprove))) {
384 _("Discovery of %s OBSOLETES %s in %s!"),
388 city_link(pcity));
389 }
392 }
393
394 if (was_first
398 }
399
400 /* Memorize some values before the tech is marked as researched.
401 * We will check what has changed later. */
404
405 /* Count EFT_HAVE_EMBASSIES effect for each player. */
408
410
411 /* Getting tech allows us to change research without applying techpenalty
412 * (without losing bulbs) */
413 if (tech_found == presearch->researching) {
414 presearch->free_bulbs = presearch->bulbs_researched;
415 }
416 presearch->researching_saved = A_UNKNOWN;
417 presearch->techs_researched++;
418
419 /* Mark the tech as known in the research struct and update
420 * global_advances array. */
422 presearch->future_tech++;
423 } else {
426 }
427
428 /* Inform players about their new tech. */
430
431 if (was_first) {
432 /* Inform all players about new global advances to give them a
433 * chance for obsolete buildings. */
435 }
436
437 /* Make proper changes for all players. Use shuffled order, in case
438 * a script would detect a signal. */
442
443 if (shares_research) {
444 char buf[250];
445
446 /* Only for players sharing the research. */
448
449 /* Give free infrastructure in every city */
450 if (tech_found != A_FUTURE) {
452
453 /* Revealing of extras with visibility_req */
454 whole_map_iterate(&(wld.map), ptile) {
455 if (map_is_known_and_seen(ptile, aplayer, V_MAIN)) {
457 send_tile_info(aplayer->connections, ptile, FALSE);
458 }
459 }
461 }
462
463 /* Enhance vision of units if a player-ranged effect has changed. Note
464 * that world-ranged effects will not be updated immediately. */
466
467 if (shares_research) {
468 fc_snprintf(buf, sizeof(buf), _("Discovery of %s"), advance_name);
469
471 }
472 }
473
474 /* For any player. */
475 /* Update all cities in case the tech changed some effects. This is
476 * inefficient; it could be optimized if it's found to be a problem.
477 * But techs aren't researched that often. */
479 /* Refresh the city data; this also updates the squared city radius. */
484
485 /* Send all player an updated info of the owner of the Marco Polo
486 * Wonder if this wonder has become obsolete. */
487 if (0 < had_embassies[i]
489 send_player_all_c(aplayer, aplayer->connections);
491 if (aplayer != pother_player) {
494 }
496 }
498
500
501 if (tech_found == presearch->tech_goal) {
502 presearch->tech_goal = A_UNSET;
503 }
504
505 if (tech_found == presearch->researching) {
506 /* Try to pick new tech to research. */
508 presearch->tech_goal);
509
510 /* As this function can be recursive, we need to print the messages
511 * before really picking the new technology. */
512 if (A_UNSET != next_tech) {
514 _("Learned %s. Our scientists focus on %s; "
515 "goal is %s."),
518 next_tech),
520 (presearch, presearch->tech_goal));
521 } else {
523 /* Use pick_random_tech() to determine if there now is
524 * a regular tech to research, e.g., if one was lost
525 * due to tech upkeep since we started researching future techs. */
527
528 /* Continue researching future tech, if possible. */
529 if (next_tech != A_FUTURE) {
530 bool ai_found = FALSE;
531
532 /* Otherwise check if there's an AI player to support
533 * randomly selected tech (one that "made" the decision) */
535 if (is_ai(aplayer)) {
536 ai_found = TRUE;
537 }
539
540 if (!ai_found) {
541 /* Decision is humans' to make */
543 }
544 }
545 } else {
546 /* If there is at least one AI player still alive, then pick
547 * a random tech, else keep A_UNSET. */
549 if (is_ai(aplayer)) {
551 break;
552 }
554 }
555
556 if (A_UNSET == next_tech) {
558 _("Learned %s. Scientists "
559 "do not know what to research next."),
561 } else {
563 _("Learned %s. Scientists choose to research %s."),
566 next_tech));
567 }
568 }
569
570 if (A_UNSET != next_tech) {
572 } else {
573 presearch->researching = A_UNSET;
574 }
575 }
576
577 if (!saving_bulbs && presearch->bulbs_researched > 0) {
578 presearch->bulbs_researched = 0;
579 }
580
581 if (bonus_tech_hack) {
583 char research_name[MAX_LEN_NAME * 2];
584 const char *radv_name;
585
587
589
591
593 if (advance_by_number(tech_found)->bonus_message != NULL
594 && additional_tech != A_UNSET) {
596 _(advance_by_number(tech_found)->bonus_message),
597 radv_name);
598 } else if (additional_tech != A_UNSET) {
599 /* FIXME: "your" when it was just civilization of one of the players
600 * sharing the research. */
602 _("Great scientists from all the "
603 "world join your civilization: you learn "
604 "%s immediately."), radv_name);
605 }
606 /* TODO: Ruleset should be able to customize this message too */
608 _("%s acquire %s as a result of learning %s."),
610 }
611}
612
613/************************************************************************/
616static bool lose_tech(struct research *research)
617{
619 /* Tech loss disabled */
620 return FALSE;
621 }
622
623 if (research->techs_researched == 0) {
624 /* No tech to lose */
626 return FALSE;
627 }
628
629 /* First check is not for optimization only - it protects
630 * research_total_bulbs_required() from getting called before research
631 * has even been set to value other than A_UNSET. */
635 * game.info.techloss_forgiveness / 100)) {
636 return TRUE;
637 }
638
639 return FALSE;
640}
641
642/************************************************************************/
654void update_bulbs(struct player *pplayer, int bulbs, bool check_tech,
655 bool free_bulbs)
656{
657 struct research *research = research_get(pplayer);
658
659 if (!pplayer->is_alive) {
660 /* Dead players do not produce research */
661 return;
662 }
664
665 /* Count our research contribution this turn */
666 pplayer->server.bulbs_last_turn += bulbs;
671 }
675 }
677 if (j == research->researching) {
679 }
681
682
683 do {
684 /* If we have a negative number of bulbs we do try to:
685 * - reduce the number of future techs;
686 * - or lose one random tech.
687 * After that the number of bulbs available is increased based on the
688 * value of the lost tech. */
689 if (lose_tech(research)) {
692
693 if (tech != A_NONE) {
694 if (game.server.techloss_restore >= 0) {
698 } else {
700 }
702
703 log_debug("%s: tech loss (%s)",
705 (is_future_tech(tech) ? "Future Tech"
708 /* Make notification after losing the research, in case it is
709 * a future tech (for getting the right tech number). */
711 _("Insufficient science output. We lost %s."),
713 }
714 }
715
716 /* Check for finished research. */
717 if (!check_tech
721 FALSE))) {
722 break;
723 }
724
726 } while (research->researching != A_UNSET);
727}
728
729/************************************************************************/
732static Tech_type_id
734{
737 /* A_NONE included in advance_count(). */
738 int eligible = full_count - 1;
739 int chosen;
740
742
745 if (BV_ISSET(eligible_techs, i)) {
746 eligible--;
748 }
749 } else {
750 /* Knowing this tech may make others ineligible */
752
753 /* Never lose techs that are root_req for a currently known tech
754 * (including self root_req) */
755 if (root != A_NONE && BV_ISSET(eligible_techs, root)) {
756 eligible--;
758 }
760 /* Ruleset can prevent this kind of tech loss from opening up
761 * holes in the tech tree */
763
766 eligible--;
768 }
771 eligible--;
773 }
774 }
775 }
777
778 if (eligible == 0) {
779 /* no researched technology at all */
780 return A_NONE;
781 }
782
783 chosen = fc_rand(eligible) + 1;
784
786 if (BV_ISSET(eligible_techs, i)) {
787 chosen--;
788 if (chosen == 0) {
789 return i;
790 }
791 }
793
794 /* should never be reached */
795 fc_assert_msg(chosen == 0, "internal error (eligible=%d, chosen=%d)",
797 return A_NONE;
798}
799
800/************************************************************************/
803static inline struct government *
805{
806 struct government *picked = NULL;
807 int gov_nb = 0;
808
810 if (can_change_to_government(pplayer, pgov) && 0 == fc_rand(++gov_nb)) {
811 picked = pgov;
812 }
815 return picked;
816}
817
818/************************************************************************/
822{
823 char research_name[MAX_LEN_NAME * 2];
824 /* Research members will be notified when new tech is chosen. */
825 const struct civ_map *nmap = &(wld.map);
826
828
829 presearch->techs_researched--;
830 if (is_future_tech(tech)) {
831 presearch->future_tech--;
833 /* Notify after decreasing the future tech counter, to get the right
834 * tech number in the message. */
836 _("The %s have lost %s."),
839 tech));
840 /* Inform players about their technology loss. */
842 return;
843 }
844
847 /* TRANS: technology loss */
848 _("The %s have lost %s."),
851 tech));
852
853 /* Remove technology. */
856 log_debug("%s lost tech id %d (%s)", research_rule_name(presearch), tech,
858
859 /* Inform players about their technology loss. */
861
863 /* Check government. */
864 if (!can_change_to_government(pplayer, government_of_player(pplayer))) {
865 /* Lost the technology for the government; switch to random
866 * available government. */
867 struct government *pgov = pick_random_government(pplayer);
868
870 _("The required technology for our government '%s' "
871 "was lost. The citizens have started a "
872 "revolution into '%s'."),
874 (pplayer)),
877 send_player_info_c(pplayer, NULL);
878 } else if (NULL != pplayer->target_government
879 && !can_change_to_government(pplayer,
880 pplayer->target_government)) {
881 /* Lost the technology for the target government; use a random
882 * available government as new target government. */
883 struct government *pgov = pick_random_government(pplayer);
884
886 _("The required technology for our new government "
887 "'%s' was lost. The citizens chose '%s' as new "
888 "target government."),
889 government_name_translation(pplayer->target_government),
891 pplayer->target_government = pgov;
892 send_player_info_c(pplayer, pplayer->connections);
893 }
894
895 /* Check all units for valid activities. */
897
898 /* Check city production */
899 city_list_iterate(pplayer->cities, pcity) {
900 bool update = FALSE;
901
902 if (pcity->production.kind == VUT_UTYPE
903 && !can_city_build_unit_now(nmap, pcity, pcity->production.value.utype)) {
904 notify_player(pplayer, city_tile(pcity),
906 _("%s can't build %s. The required technology was "
907 "lost."),
908 city_link(pcity),
909 utype_name_translation(pcity->production.value.utype));
910 choose_build_target(pplayer, pcity);
911 update = TRUE;
912 }
913
914 if (pcity->production.kind == VUT_IMPROVEMENT
916 pcity->production.value.building)) {
917 notify_player(pplayer, city_tile(pcity),
919 _("%s can't build %s. The required technology was "
920 "lost."),
921 city_link(pcity),
923 (pcity->production.value.building));
924 choose_build_target(pplayer, pcity);
925 update = TRUE;
926 }
927
928 if (update) {
929 city_refresh(pcity);
930 send_city_info(pplayer, pcity);
931 }
934}
935
936/************************************************************************/
940{
941 Tech_type_id tech = A_FUTURE;
942 int num_techs = 0;
943
946 if (fc_rand(++num_techs) == 0) {
947 tech = i;
948 }
949 }
951
952 return tech;
953}
954
955/************************************************************************/
959{
960 int cheapest_cost = -1;
961 int cheapest_amount = 0;
962 Tech_type_id cheapest = A_FUTURE; /* If no real tech is found to be missing */
963
967
968 if (cost < cheapest_cost || cheapest_cost == -1) {
970 cheapest_amount = 1;
971 cheapest = i;
972 } else if (cost == cheapest_cost && fc_rand(++cheapest_amount) == 0) {
973 cheapest = i;
974 }
975 }
977
978 return cheapest;
979}
980
981/************************************************************************/
996
997/************************************************************************/
1006{
1007 int bulbs_res = 0;
1008
1009 if (is_future_tech(tech)) {
1014 }
1015 } else {
1016 if (research->researching == tech) {
1017 return;
1018 }
1020 /* Can't research this. */
1021 return;
1022 }
1023 }
1024
1027 /* Save old tech research */
1028 if (j == research->researching) {
1030 }
1031 /* New tech*/
1032 if (j == tech) {
1034 }
1036 research->researching = tech;
1038 research->free_bulbs = 0;
1042 }
1043 return;
1044 }
1045
1046 /* The first check implies we have NOT recently got a technology
1047 * and are changing from one we were researching at tc. */
1052 /* Subtract a penalty because we changed subject. */
1053 if (research->bulbs_researched > 0) {
1056 * game.server.techpenalty) / 100;
1057 /* If free_bulbs were for some reason negative... */
1059 }
1060 } else if (tech == research->researching_saved) {
1063 }
1064 research->researching = tech;
1068 }
1069}
1070
1071/************************************************************************/
1076{
1078
1079 if (tech == presearch->tech_goal) {
1080 return;
1081 }
1082
1083 /* It's been suggested that if the research target is empty then
1084 * choose_random_tech() should be called here. */
1085 presearch->tech_goal = tech;
1087 _("Technology goal is %s."),
1089}
1090
1091/************************************************************************/
1094void init_tech(struct research *research, bool update)
1095{
1097
1099
1103
1104#ifdef TECH_UPKEEP_DEBUGGING
1105 /* Print a list of the needed upkeep if 'i' techs are researched.
1106 * If the ruleset contains self-rooted techs this can not work! */
1107 {
1108 bool global_state[A_LAST];
1109 Tech_type_id tech = A_LAST;
1110
1111 /* Save the game research state. */
1115
1118
1119 /* Show research costs. */
1121 log_debug("[research %d] %-25s (ID: %3d) cost: %6d - reachable: %-3s "
1122 "(now) / %-3s (ever)", research_number(research),
1126 ? "yes" : "no",
1127 research_invention_reachable(research, i) ? "yes" : "no");
1129
1130 /* Update step for step each tech as known and print the upkeep. */
1131 while (tech != A_NONE) {
1132 tech = A_NONE;
1136 /* Found a tech which can be researched. */
1137 tech = i;
1138 break;
1139 }
1141
1142 if (tech != A_NONE) {
1145
1146 /* This will change the game state! */
1148
1150 log_debug("[player %d] researched: %-25s (ID: %4d) techs: %3d "
1151 "upkeep: %4d", research_number(research),
1155 }
1156 }
1157
1158 /* Reset the changes done. */
1163 }
1164#endif /* TECH_UPKEEP_DEBUGGING */
1165
1167
1168 if (update) {
1170
1171 /* Mark the reachable techs */
1173
1175 if (A_UNSET != next_tech) {
1177 } else {
1179 }
1180 }
1181}
1182
1183/************************************************************************/
1189{
1190 int i;
1191
1192 /* Global techs. */
1193 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
1195 break;
1196 }
1197 /* Maybe the player already got this tech by an other way (e.g. team). */
1199 != TECH_KNOWN) {
1201 FALSE, TRUE);
1202 }
1203 }
1204
1205 /* Nation techs. */
1207 const struct nation_type *pnation = nation_of_player(pplayer);
1208
1209 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
1210 if (pnation->init_techs[i] == A_LAST) {
1211 break;
1212 }
1213 /* Maybe the player already got this tech by an other way. */
1215 != TECH_KNOWN) {
1217 }
1218 }
1220
1221 /* Random free techs (N.B.: freecost penalty not applied). */
1222 for (i = 0; i < num_random_techs; i++) {
1224 }
1225}
1226
1227/************************************************************************/
1236{
1237 struct research *presearch, *vresearch;
1239 const char *advance_name;
1240 char research_name[MAX_LEN_NAME * 2];
1241
1243 return A_NONE;
1244 }
1245
1246 presearch = research_get(pplayer);
1248
1249 if (preferred == A_UNSET) {
1250 int j = 0;
1252
1258 j++;
1259 }
1261
1262 if (j == 0) {
1263 /* We've moved on to future tech */
1264 if (vresearch->future_tech > presearch->future_tech) {
1266 } else {
1267 return A_NONE;
1268 }
1269 } else {
1270 /* Pick random tech */
1271 j = fc_rand(j) + 1;
1272 stolen_tech = A_NONE; /* Avoid compiler warning */
1278 j--;
1279 }
1280 if (j == 0) {
1281 stolen_tech = i;
1282 break;
1283 }
1286 }
1287 } else { /* preferred != A_UNSET */
1288#ifndef FREECIV_NDEBUG
1289 if (!is_future_tech(preferred)) {
1292 preferred));
1293 }
1294#endif /* FREECIV_NDEBUG */
1296 }
1297
1301 _("You steal %s from the %s."),
1305 _("The %s stole %s from the %s and shared it with you."),
1306 nation_plural_for_player(pplayer),
1309
1311 _("The %s stole %s from you!"),
1312 nation_plural_for_player(pplayer),
1313 advance_name);
1314
1316 _("The %s have stolen %s from the %s."),
1320
1321 if (tech_transfer(pplayer, victim, stolen_tech)) {
1325 "stolen");
1326 return stolen_tech;
1327 }
1328
1329 return A_NONE;
1330}
1331
1332/************************************************************************/
1339void handle_player_research(struct player *pplayer, int tech)
1340{
1341 struct research *research = research_get(pplayer);
1342
1343 if (tech != A_FUTURE && !valid_advance_by_number(tech)) {
1344 return;
1345 }
1346
1347 if (tech != A_FUTURE
1349 return;
1350 }
1351
1352 choose_tech(research, tech);
1353
1354 /* Notify players sharing the same research. */
1356}
1357
1358/************************************************************************/
1362void handle_player_tech_goal(struct player *pplayer, int tech_goal)
1363{
1364 struct research *research = research_get(pplayer);
1365
1366 /* Set the tech goal to a defined state if it is
1367 * - not a future tech and not a valid goal
1368 * - not a future tech and not a valid advance
1369 * - not defined
1370 * - known (i.e. due to EFT_GIVE_IMM_TECH). */
1371 if ((tech_goal != A_FUTURE
1374 || (tech_goal == A_NONE)
1377 }
1378
1380
1381 /* Notify players sharing the same research. */
1383}
1384
1385/************************************************************************/
1389{
1390 Tech_type_id tech;
1391
1394 } else if (presearch->researching == A_UNSET
1397 } else {
1398 tech = presearch->researching;
1399 }
1400 return tech;
1401}
1402
1403/************************************************************************/
1412
1413/************************************************************************/
1416static void forget_tech_transferred(struct player *pplayer, Tech_type_id tech)
1417{
1418 struct research *presearch = research_get(pplayer);
1419
1421 /* Make notification after losing the research, in case it is a future
1422 * tech (for getting the right tech number). */
1424 _("Too bad! You made a mistake transferring the tech %s and "
1425 "lost it."),
1428 _("Too bad! The %s made a mistake transferring the tech "
1429 "%s and lost it."),
1430 nation_plural_for_player(pplayer),
1432}
1433
1434/************************************************************************/
1439 Tech_type_id tech)
1440{
1441 if (game.server.techlost_donor > 0) {
1443 bool donor_can_lose = TRUE;
1444
1446 /* Never let donor lose tech if it's root_req for some other known
1447 * tech */
1449 && (advance_required(i, AR_ROOT) == tech
1451 && (advance_required(i, AR_ONE) == tech
1452 || advance_required(i, AR_TWO) == tech)))) {
1454 break;
1455 }
1459 }
1460 }
1461
1462 if (fc_rand(100) < game.server.techlost_recv) {
1464
1465 /* We've not received the tech yet, and never will.
1466 * Do not call forget_tech_transferred() that would handle it
1467 * as something we had and now lose.
1468 * (e.g. subtracting techs_researched counter) */
1470 _("Too bad! You made a mistake transferring the tech %s and "
1471 "didn't get it."),
1474 _("Too bad! The %s made a mistake transferring the tech "
1475 "%s and didn't get it."),
1478 return FALSE;
1479 }
1480
1481 return TRUE;
1482}
1483
1484/************************************************************************/
1491{
1492 struct cur_govs_data *data = fc_malloc(sizeof(struct cur_govs_data));
1493
1494 data->players = fc_malloc(sizeof(*data->players) * player_slot_count());
1495
1496 players_iterate(pplayer) {
1497 data->players[player_index(pplayer)].govs = fc_malloc(sizeof(bool) * government_count());
1499
1501 /* Memorize for the players sharing the research what government
1502 * they could switch on. */
1505 = can_change_to_government(pplayer, pgov);
1508
1509 return data;
1510}
1511
1512/************************************************************************/
1519{
1520 struct cur_govs_data *data = fc_malloc(sizeof(struct cur_govs_data));
1521
1522 data->players = fc_malloc(sizeof(*data->players) * player_slot_count());
1523
1524 players_iterate(pplayer) {
1525 data->players[player_index(pplayer)].govs = fc_malloc(sizeof(bool) * government_count());
1528 = can_change_to_government(pplayer, pgov);
1531
1532 return data;
1533}
1534
1535/************************************************************************/
1539{
1540 players_iterate(pplayer) {
1541 free(data->players[player_index(pplayer)].govs);
1543
1544 free(data->players);
1545 free(data);
1546}
1547
1548/************************************************************************/
1553 struct cur_govs_data *data,
1554 const char *reason)
1555{
1556 struct government *available = NULL;
1557
1559 if (!data->players[player_index(pplayer)].govs[government_index(pgov)]
1560 && can_change_to_government(pplayer, pgov)) {
1561 if (available != NULL) {
1563 /* TRANS: "Discovery of <tech>" */
1564 _("%s makes several new government forms"
1565 " available. You may want to start a revolution."),
1566 reason);
1567 return;
1568 }
1569
1570 available = pgov;
1571 }
1573
1574 if (available != NULL) {
1576 /* TRANS: "Discovery of <tech>" */
1577 _("%s makes the government form %s"
1578 " available. You may want to start a revolution."),
1579 reason,
1581 }
1582}
void astr_free(struct astring *astr)
Definition astring.c:153
void astr_init(struct astring *astr)
Definition astring.c:144
static const char * astr_str(const struct astring *astr) fc__attribute((nonnull(1)))
Definition astring.h:93
#define BV_SET_ALL(bv)
Definition bitvector.h:99
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_CLR(bv, bit)
Definition bitvector.h:86
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:854
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:947
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:564
#define city_owner(_pcity_)
Definition city.h:563
#define city_list_iterate_end
Definition city.h:510
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2363
void city_refresh_vision(struct city *pcity)
Definition citytools.c:3442
void remove_obsolete_buildings(struct player *pplayer)
Definition cityturn.c:271
void choose_build_target(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2387
bool city_refresh(struct city *pcity)
Definition cityturn.c:159
char * incite_cost
Definition comments.c:75
struct player * conn_get_player(const struct connection *pconn)
Definition connection.c:763
#define conn_list_iterate(connlist, pconn)
Definition connection.h:108
#define conn_list_iterate_end
Definition connection.h:110
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
struct effect_list * effects[EFT_COUNT]
Definition effects.c:127
struct effect_list * govs[G_LAST]
Definition effects.c:133
int get_player_bonus_effects(struct effect_list *plist, const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:1130
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
void get_effect_list_req_text(const struct effect_list *plist, struct astring *astr)
Definition effects.c:1303
int Tech_type_id
Definition fc_types.h:377
#define MAX_LEN_NAME
Definition fc_types.h:66
#define MAX_NUM_TECH_LIST
Definition fc_types.h:44
@ O_SCIENCE
Definition fc_types.h:101
#define Q_(String)
Definition fcintl.h:70
#define _(String)
Definition fcintl.h:67
const struct ft_color ftc_server
const char * city_link(const struct city *pcity)
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
void send_game_info(struct conn_list *dest)
Definition gamehand.c:907
const char * government_name_translation(const struct government *pgovern)
Definition government.c:143
Government_type_id government_count(void)
Definition government.c:71
struct government * government_of_player(const struct player *pplayer)
Definition government.c:114
bool can_change_to_government(struct player *pplayer, const struct government *gov)
Definition government.c:166
Government_type_id government_number(const struct government *pgovern)
Definition government.c:91
Government_type_id government_index(const struct government *pgovern)
Definition government.c:82
#define governments_iterate(NAME_pgov)
Definition government.h:124
#define governments_iterate_end
Definition government.h:127
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:566
bool is_great_wonder(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
struct city * city_from_great_wonder(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert_ret(condition)
Definition log.h:191
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define log_debug(message,...)
Definition log.h:115
#define whole_map_iterate(_map, _tile)
Definition map.h:545
#define whole_map_iterate_end
Definition map.h:554
void send_tile_info(struct conn_list *dest, struct tile *ptile, bool send_unknown)
Definition maphand.c:491
bool update_player_tile_knowledge(struct player *pplayer, struct tile *ptile)
Definition maphand.c:1398
void upgrade_all_city_extras(struct player *pplayer, bool discovery)
Definition maphand.c:276
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:920
#define fc_malloc(sz)
Definition mem.h:34
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:444
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
void notify_research(const struct research *presearch, const struct player *exclude, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:393
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:291
void notify_research_embassies(const struct research *presearch, const struct player *exclude, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:433
int send_packet_unknown_research(struct connection *pc, const struct packet_unknown_research *packet)
int send_packet_research_info(struct connection *pc, const struct packet_research_info *packet)
int player_slot_count(void)
Definition player.c:418
const char * player_name(const struct player *pplayer)
Definition player.c:895
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:220
int player_index(const struct player *pplayer)
Definition player.c:829
#define players_iterate_end
Definition player.h:537
#define players_iterate(_pplayer)
Definition player.h:532
#define is_ai(plr)
Definition player.h:230
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1129
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1146
#define shuffled_players_iterate_end
Definition plrhand.h:108
#define shuffled_players_iterate(NAME_pplayer)
Definition plrhand.h:98
#define fc_rand(_size)
Definition rand.h:56
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
bool research_invention_reachable(const struct research *presearch, const Tech_type_id tech)
Definition research.c:668
enum tech_state research_invention_set(struct research *presearch, Tech_type_id tech, enum tech_state value)
Definition research.c:637
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
int research_count(void)
Definition research.c:1328
int research_number(const struct research *presearch)
Definition research.c:109
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
const char * research_rule_name(const struct research *presearch)
Definition research.c:143
struct research * research_get(const struct player *pplayer)
Definition research.c:128
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
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
void research_update(struct research *presearch)
Definition research.c:501
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
void script_server_signal_emit(const char *signal_name,...)
#define MAX(x, y)
Definition shared.h:54
Definition city.h:320
bool multiresearch
Definition game.h:167
int techlost_recv
Definition game.h:198
struct conn_list * est_connections
Definition game.h:97
int global_init_techs[MAX_NUM_TECH_LIST]
Definition game.h:110
struct packet_game_info info
Definition game.h:89
int conquercost
Definition game.h:140
int techloss_restore
Definition game.h:196
int freecost
Definition game.h:152
struct civ_game::@31::@35 server
struct civ_game::@30 rgame
int techlost_donor
Definition game.h:197
int techpenalty
Definition game.h:200
bool * govs
Definition techtools.h:25
struct cur_govs_data::@123 * players
int init_techs[MAX_NUM_TECH_LIST]
Definition nation.h:122
bool tech_steal_allow_holes
bool tech_trade_loss_allow_holes
enum free_tech_method free_tech_method
bool global_advances[A_LAST]
bool tech_parasite_allow_holes
char inventions[A_LAST+1]
int bulbs_last_turn
Definition player.h:349
struct team * team
Definition player.h:259
bool is_alive
Definition player.h:266
struct player::@70::@72 server
enum tech_state state
Definition research.h:71
Tech_type_id researching
Definition research.h:52
int future_tech
Definition research.h:42
Tech_type_id tech_goal
Definition research.h:83
int bulbs_researching_saved
Definition research.h:63
struct research::research_invention inventions[A_ARRAY_SIZE]
Tech_type_id researching_saved
Definition research.h:62
int techs_researched
Definition research.h:42
int bulbs_researched
Definition research.h:53
int free_bulbs
Definition research.h:67
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
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
bool advance_has_flag(Tech_type_id tech, enum tech_flag_id flag)
Definition tech.c:216
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
#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
@ AR_TWO
Definition tech.h:112
@ AR_ROOT
Definition tech.h:113
@ AR_ONE
Definition tech.h:111
#define advance_index_iterate_max_end
Definition tech.h:258
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 A_UNSET
Definition tech.h:48
#define A_UNKNOWN
Definition tech.h:49
#define A_LAST
Definition tech.h:45
#define advance_index_iterate(_start, _index)
Definition tech.h:244
static Tech_type_id pick_cheapest_tech(const struct research *presearch)
Definition techtools.c:958
void handle_player_tech_goal(struct player *pplayer, int tech_goal)
Definition techtools.c:1362
void init_tech(struct research *research, bool update)
Definition techtools.c:1094
static struct government * pick_random_government(struct player *pplayer)
Definition techtools.c:804
void found_new_tech(struct research *presearch, Tech_type_id tech_found, bool was_discovery, bool saving_bulbs)
Definition techtools.c:347
void free_current_governments_data(struct cur_govs_data *data)
Definition techtools.c:1538
static bool lose_tech(struct research *research)
Definition techtools.c:616
void choose_tech_goal(struct research *presearch, Tech_type_id tech)
Definition techtools.c:1075
void research_apply_penalty(struct research *presearch, Tech_type_id tech, int penalty_percent)
Definition techtools.c:67
static void tech_researched(struct research *research)
Definition techtools.c:107
void choose_tech(struct research *research, Tech_type_id tech)
Definition techtools.c:1005
static Tech_type_id pick_random_tech_to_lose(const struct research *presearch)
Definition techtools.c:733
static void package_research_info(struct packet_research_info *packet, const struct research *presearch)
Definition techtools.c:258
static void forget_tech_transferred(struct player *pplayer, Tech_type_id tech)
Definition techtools.c:1416
Tech_type_id steal_a_tech(struct player *pplayer, struct player *victim, Tech_type_id preferred)
Definition techtools.c:1234
void notify_new_government_options(struct player *pplayer, struct cur_govs_data *data, const char *reason)
Definition techtools.c:1552
void handle_player_research(struct player *pplayer, int tech)
Definition techtools.c:1339
Tech_type_id pick_free_tech(struct research *presearch)
Definition techtools.c:1388
void give_immediate_free_tech(struct research *presearch, Tech_type_id tech)
Definition techtools.c:1407
struct cur_govs_data * create_current_governments_data(struct research *presearch)
Definition techtools.c:1490
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:293
void choose_random_tech(struct research *research)
Definition techtools.c:990
struct cur_govs_data * create_current_governments_data_all(void)
Definition techtools.c:1518
static void research_tech_lost(struct research *presearch, Tech_type_id tech)
Definition techtools.c:821
void script_tech_learned(struct research *presearch, struct player *originating_plr, struct advance *tech, const char *reason)
Definition techtools.c:84
void give_initial_techs(struct research *presearch, int num_random_techs)
Definition techtools.c:1188
bool tech_transfer(struct player *plr_recv, struct player *plr_donor, Tech_type_id tech)
Definition techtools.c:1438
static Tech_type_id pick_random_tech(const struct research *presearch)
Definition techtools.c:939
void do_tech_parasite_effects(struct player *pplayer)
Definition techtools.c:143
void update_bulbs(struct player *pplayer, int bulbs, bool check_tech, bool free_bulbs)
Definition techtools.c:654
void unit_activities_cancel_all_illegal_plr(const struct player *pplayer)
Definition unittools.c:814
void unit_list_refresh_vision(struct unit_list *punitlist)
Definition unittools.c:4857
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1560