Freeciv-3.4
Loading...
Searching...
No Matches
improvement.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "fcintl.h"
20#include "log.h"
21#include "mem.h"
22#include "shared.h" /* ARRAY_SIZE */
23#include "string_vector.h"
24#include "support.h"
25
26/* common */
27#include "game.h"
28#include "map.h"
29#include "tech.h"
30#include "victory.h"
31
32#include "improvement.h"
33
34/**************************************************************************
35All the city improvements:
36Use improvement_by_number(id) to access the array.
37The improvement_types array is now setup in:
38 server/ruleset.c (for the server)
39 client/packhand.c (for the client)
40**************************************************************************/
42
44
45/**********************************************************************/
49{
50 int i;
51
52 /* Can't use improvement_iterate() or improvement_by_number() here
53 * because num_impr_types isn't known yet. */
54 for (i = 0; i < ARRAY_SIZE(improvement_types); i++) {
55 struct impr_type *p = &improvement_types[i];
56
57 p->item_number = i;
61 p->ruledit_dlg = nullptr;
62 }
63}
64
65/**********************************************************************/
68static void improvement_free(struct impr_type *p)
69{
70 if (p->helptext != nullptr) {
72 p->helptext = nullptr;
73 }
74
77}
78
79/**********************************************************************/
88
89/**********************************************************************/
93{
94 improvement_iterate(pimprove) {
95 pimprove->allows_units = FALSE;
97 if (requirement_needs_improvement(pimprove, &putype->build_reqs)) {
98 pimprove->allows_units = TRUE;
99 break;
100 }
102
103 pimprove->allows_extras = FALSE;
104 extra_type_iterate(pextra) {
105 if (requirement_needs_improvement(pimprove, &pextra->reqs)) {
106 pimprove->allows_extras = TRUE;
107 break;
108 }
110
111 pimprove->prevents_disaster = FALSE;
113 if (!requirement_fulfilled_by_improvement(pimprove, &pdis->reqs)) {
114 pimprove->prevents_disaster = TRUE;
115 break;
116 }
118
119 pimprove->protects_vs_actions = FALSE;
122 &act->target_reqs)) {
123 pimprove->protects_vs_actions = TRUE;
124 break;
125 }
127
128 pimprove->allows_actions = FALSE;
130 if (requirement_needs_improvement(pimprove, &act->actor_reqs)) {
131 pimprove->allows_actions = TRUE;
132 break;
133 }
135
137}
138
139/**********************************************************************/
143{
144 if (game.control.num_impr_types > 0) {
145 return improvement_types;
146 }
147
148 return nullptr;
149}
150
151/**********************************************************************/
155{
156 if (game.control.num_impr_types > 0) {
158 }
159
160 return nullptr;
161}
162
163/**********************************************************************/
170
171/**********************************************************************/
178{
179 return pimprove - improvement_types;
180}
181
182/**********************************************************************/
186{
187 return pimprove->item_number;
188}
189
190/**********************************************************************/
195{
197 return nullptr;
198 }
199
200 return &improvement_types[id];
201}
202
203/**********************************************************************/
212const struct impr_type *valid_improvement(const struct impr_type *pimprove)
213{
214 if (pimprove == nullptr) {
215 return nullptr;
216 }
217
221 || building_has_effect(pimprove, EFT_SS_MODULE))) {
222 /* This assumes that space parts don't have any other effects. */
223 return nullptr;
224 }
225
226 return pimprove;
227}
228
229/**********************************************************************/
239
240/**********************************************************************/
244const char *improvement_name_translation(const struct impr_type *pimprove)
245{
246 return name_translation_get(&pimprove->name);
247}
248
249/**********************************************************************/
253const char *improvement_rule_name(const struct impr_type *pimprove)
254{
255 return rule_name_get(&pimprove->name);
256}
257
258/**********************************************************************/
262int impr_base_build_shield_cost(const struct impr_type *pimprove)
263{
264 int base = pimprove->build_cost;
265
266 return MAX(base * game.info.shieldbox / 100, 1);
267}
268
269/**********************************************************************/
274int impr_estimate_build_shield_cost(const struct player *pplayer,
275 const struct tile *ptile,
276 const struct impr_type *pimprove)
277{
278 int base = pimprove->build_cost
279 * (100 +
281 &(const struct req_context) {
282 .player = pplayer,
283 .building = pimprove,
284 .tile = ptile,
285 },
286 nullptr,
288
289 return MAX(base * game.info.shieldbox / 100, 1);
290}
291
292/**********************************************************************/
296 const struct impr_type *pimprove)
297{
298 int base = pimprove->build_cost
299 * (100 + get_building_bonus(pcity, pimprove, EFT_IMPR_BUILD_COST_PCT)) / 100;
300
301 return MAX(base * game.info.shieldbox / 100, 1);
302}
303
304/**********************************************************************/
307int impr_buy_gold_cost(const struct city *pcity,
308 const struct impr_type *pimprove, int shields_in_stock)
309{
310 int cost = 0;
311 const int missing = impr_build_shield_cost(pcity, pimprove) - shields_in_stock;
312
313 if (is_convert_improvement(pimprove)) {
314 /* Can't buy coinage-like improvements. */
315 return 0;
316 }
317
318 if (missing > 0) {
319 cost = 2 * missing;
320 }
321
322 if (shields_in_stock == 0) {
323 cost *= 2;
324 }
325
326 cost = cost
327 * (100 + get_building_bonus(pcity, pimprove, EFT_IMPR_BUY_COST_PCT)) / 100;
328
329 return cost;
330}
331
332/**********************************************************************/
335int impr_sell_gold(const struct impr_type *pimprove)
336{
337 return MAX(pimprove->build_cost * game.info.shieldbox / 100, 1);
338}
339
340/**********************************************************************/
344bool is_wonder(const struct impr_type *pimprove)
345{
346 return (is_great_wonder(pimprove) || is_small_wonder(pimprove));
347}
348
349/**********************************************************************/
354{
355 improvement_iterate(pimprove) {
356 if (0 == strcmp(improvement_name_translation(pimprove), name)) {
357 return pimprove;
358 }
360
361 return nullptr;
362}
363
364/**********************************************************************/
369{
370 const char *qname = Qn_(name);
371
372 improvement_iterate(pimprove) {
373 if (0 == fc_strcasecmp(improvement_rule_name(pimprove), qname)) {
374 return pimprove;
375 }
377
378 return nullptr;
379}
380
381/**********************************************************************/
384bool improvement_has_flag(const struct impr_type *pimprove,
385 enum impr_flag_id flag)
386{
388
389 return BV_ISSET(pimprove->flags, flag);
390}
391
392/**********************************************************************/
395bool is_improvement_visible(const struct impr_type *pimprove)
396{
397 return (is_wonder(pimprove)
399}
400
401/**********************************************************************/
405bool can_improvement_go_obsolete(const struct impr_type *pimprove)
406{
407 return requirement_vector_size(&pimprove->obsolete_by) > 0;
408}
409
410/**********************************************************************/
413bool improvement_obsolete(const struct player *pplayer,
414 const struct impr_type *pimprove,
415 const struct city *pcity)
416{
417 const struct req_context context = {
418 .player = pplayer,
419 .city = pcity,
420 .tile = pcity ? city_tile(pcity) : nullptr,
421 .building = pimprove,
422 };
423
425 if (is_req_active(&context, nullptr, preq, RPT_CERTAIN)) {
426 return TRUE;
427 }
429
430 return FALSE;
431}
432
433/**********************************************************************/
436static bool impr_provides_buildable_units(const struct city *pcity,
437 const struct impr_type *pimprove)
438{
439 const struct civ_map *nmap = &(wld.map);
440
441 /* Fast check */
442 if (!pimprove->allows_units) {
443 return FALSE;
444 }
445
447 if (requirement_needs_improvement(pimprove, &ut->build_reqs)
449 return TRUE;
450 }
452
453 return FALSE;
454}
455
456/**********************************************************************/
459static bool impr_provides_buildable_extras(const struct city *pcity,
460 const struct impr_type *pimprove)
461{
462 const struct civ_map *nmap = &(wld.map);
463
464 /* Fast check */
465 if (!pimprove->allows_extras) {
466 return FALSE;
467 }
468
469 extra_type_iterate(pextra) {
470 if (requirement_needs_improvement(pimprove, &pextra->reqs)) {
472 city_tile(pcity), ptile) {
473 if (player_can_build_extra(pextra, city_owner(pcity), ptile)) {
474 return TRUE;
475 }
477 }
479
480 return FALSE;
481}
482
483/**********************************************************************/
486static bool impr_prevents_disaster(const struct city *pcity,
487 const struct impr_type *pimprove)
488{
489 /* Fast check */
490 if (!pimprove->prevents_disaster) {
491 return FALSE;
492 }
493
497 return TRUE;
498 }
500
501 return FALSE;
502}
503
504/**********************************************************************/
510static bool impr_protects_vs_actions(const struct city *pcity,
511 const struct impr_type *pimprove)
512{
513 /* Fast check */
514 if (!pimprove->protects_vs_actions) {
515 return FALSE;
516 }
517
519 if (!requirement_fulfilled_by_improvement(pimprove, &enabler->target_reqs)
521 nullptr, pcity)) {
522 return TRUE;
523 }
525
526 return FALSE;
527}
528
529/**********************************************************************/
532static bool impr_allows_actions(const struct city *pcity,
533 const struct impr_type *pimprove)
534{
535 const struct civ_map *nmap = &(wld.map);
536
537 /* Fast check */
538 if (!pimprove->allows_actions) {
539 return FALSE;
540 }
541
543 if (requirement_needs_improvement(pimprove, &enabler->actor_reqs)) {
545
546 switch (action_id_get_actor_kind(act)) {
547 case AAK_UNIT:
549 if (!utype_can_do_action(ut, act)) {
550 /* Not relevant */
551 continue;
552 }
553
555 /* The player has a unit that may use the building */
556 return TRUE;
557 }
558
560 /* This city can build a unit that uses the building */
561 return TRUE;
562 }
564 break;
565 case AAK_CITY:
566 case AAK_PLAYER:
567 /* No traceable limitations */
568 return TRUE;
569 case AAK_COUNT:
571 break;
572 }
573 }
575
576 return FALSE;
577}
578
579/**********************************************************************/
589static bool improvement_has_side_effects(const struct city *pcity,
590 const struct impr_type *pimprove)
591{
592 return (impr_provides_buildable_units(pcity, pimprove)
594 || impr_prevents_disaster(pcity, pimprove)
595 || impr_allows_actions(pcity, pimprove)
596 || impr_protects_vs_actions(pcity, pimprove));
597}
598
599/**********************************************************************/
602static bool improvement_has_effects(const struct city *pcity,
603 const struct impr_type *pimprove)
604{
605 struct universal source = { .kind = VUT_IMPROVEMENT,
606 .value = { .building = pimprove } };
608
609 if (!plist || improvement_obsolete(city_owner(pcity), pimprove, pcity)) {
610 return FALSE;
611 }
612
614 if (0 != get_potential_improvement_bonus(pimprove, pcity,
615 peffect->type, RPT_CERTAIN, TRUE)) {
616 return TRUE;
617 }
619
620 return FALSE;
621}
622
623/**********************************************************************/
631 const struct impr_type *pimprove)
632{
633 return (!improvement_obsolete(city_owner(pcity), pimprove, pcity)
634 && (improvement_has_flag(pimprove, IF_GOLD)
635 || improvement_has_flag(pimprove, IF_INFRA)
637 || improvement_has_effects(pcity, pimprove)));
638}
639
640/**********************************************************************/
653 const struct impr_type *pimprove)
654{
655 /* A capitalization production is never redundant. */
656 if (improvement_has_flag(pimprove, IF_GOLD)) {
657 return FALSE;
658 }
659 if (improvement_has_flag(pimprove, IF_INFRA)) {
660 return FALSE;
661 }
662
663 /* If an improvement has side effects, don't claim it's redundant. */
664 if (improvement_has_side_effects(pcity, pimprove)) {
665 return FALSE;
666 }
667
668 /* Otherwise, it's redundant if its effects are available by other means,
669 * or if it's an obsolete wonder (great or small). */
670 return is_building_replaced(pcity, pimprove, RPT_CERTAIN)
672}
673
674/**********************************************************************/
679 const struct impr_type *pimprove,
680 const enum req_problem_type prob_type)
681{
682 const struct req_context context = { .player = p };
683
684 bool space_part = FALSE;
685
686 if (!valid_improvement(pimprove)) {
687 return FALSE;
688 }
689
691 if (preq->range >= REQ_RANGE_PLAYER
692 && !is_req_active(&context, nullptr, preq, prob_type)) {
693 return FALSE;
694 }
696
697 /* Check for space part construction. This assumes that space parts have
698 * no other effects. */
699 if (building_has_effect(pimprove, EFT_SS_STRUCTURAL)) {
702 return FALSE;
703 }
704 }
705 if (building_has_effect(pimprove, EFT_SS_COMPONENT)) {
708 return FALSE;
709 }
710 }
711 if (building_has_effect(pimprove, EFT_SS_MODULE)) {
713 if (p->spaceship.modules >= NUM_SS_MODULES) {
714 return FALSE;
715 }
716 }
717 if (space_part
719 || p->spaceship.state >= SSHIP_LAUNCHED)) {
720 return FALSE;
721 }
722
723 if (is_great_wonder(pimprove)) {
724 /* Can't build wonder if already built */
725 if (!great_wonder_is_available(pimprove)) {
726 return FALSE;
727 }
728 }
729
730 return TRUE;
731}
732
733/**********************************************************************/
738 struct impr_type *pimprove,
739 const enum req_problem_type prob_type)
740{
742 return FALSE;
743 }
744 if (improvement_obsolete(p, pimprove, nullptr)) {
745 return FALSE;
746 }
747
748 return TRUE;
749}
750
751/**********************************************************************/
757 const struct impr_type *pimprove)
758{
759 const struct req_context context = { .player = p };
760
761 if (!valid_improvement(pimprove)) {
762 return FALSE;
763 }
764 if (improvement_obsolete(p, pimprove, nullptr)) {
765 return FALSE;
766 }
767 if (is_great_wonder(pimprove) && !great_wonder_is_available(pimprove)) {
768 /* Can't build wonder if already built */
769 return FALSE;
770 }
771
772 /* Check for requirements that aren't met and that are unchanging (so
773 * they can never be met). */
775 if (preq->range >= REQ_RANGE_PLAYER
776 && is_req_preventing(&context, nullptr, preq, RPT_POSSIBLE)) {
777 return FALSE;
778 }
780 /* FIXME: should check some "unchanging" reqs here - like if there's
781 * a nation requirement, we can go ahead and check it now. */
782
783 return TRUE;
784}
785
786/**********************************************************************/
789bool is_great_wonder(const struct impr_type *pimprove)
790{
791 return (pimprove->genus == IG_GREAT_WONDER);
792}
793
794/**********************************************************************/
797bool is_small_wonder(const struct impr_type *pimprove)
798{
799 return (pimprove->genus == IG_SMALL_WONDER);
800}
801
802/**********************************************************************/
805bool is_improvement(const struct impr_type *pimprove)
806{
807 return (pimprove->genus == IG_IMPROVEMENT);
808}
809
810/**********************************************************************/
814bool is_special_improvement(const struct impr_type *pimprove)
815{
816 /* TODO: Find either a new term for traditional "special" improvements
817 * (maybe "project"?), or a new umbrella term for all improvements that
818 * can't be present in the city as a finished building (including special
819 * and convert improvements). */
820 return (pimprove->genus == IG_SPECIAL)
821 || is_convert_improvement(pimprove);
822}
823
824/**********************************************************************/
828bool is_convert_improvement(const struct impr_type *pimprove)
829{
830 return (pimprove->genus == IG_CONVERT);
831}
832
833/**********************************************************************/
836void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
837{
838 struct player *pplayer;
839 int windex = improvement_number(pimprove);
840
841 fc_assert_ret(is_wonder(pimprove));
842
843 pplayer = city_owner(pcity);
844 pplayer->wonders[windex] = pcity->id;
845
846 if (is_great_wonder(pimprove)) {
848 }
849}
850
851/**********************************************************************/
855void wonder_destroyed(const struct city *pcity,
856 const struct impr_type *pimprove)
857{
858 struct player *pplayer;
859 int windex = improvement_number(pimprove);
860
861 fc_assert_ret(is_wonder(pimprove));
862
863 pplayer = city_owner(pcity);
864 fc_assert_ret(pplayer->wonders[windex] == pcity->id);
865 pplayer->wonders[windex] = WONDER_LOST;
866
867 if (is_great_wonder(pimprove)) {
869 == player_number(pplayer));
871 }
872}
873
874/**********************************************************************/
878bool wonder_is_lost(const struct player *pplayer,
879 const struct impr_type *pimprove)
880{
882
883 return pplayer->wonders[improvement_index(pimprove)] == WONDER_LOST;
884}
885
886/**********************************************************************/
890bool wonder_is_built(const struct player *pplayer,
891 const struct impr_type *pimprove)
892{
894
895 return WONDER_BUILT(pplayer->wonders[improvement_index(pimprove)]);
896}
897
898/**********************************************************************/
904struct city *city_from_wonder(const struct player *pplayer,
905 const struct impr_type *pimprove)
906{
907 int idx = improvement_index(pimprove);
908 int city_id;
909
910 if (idx < 0) {
911 return nullptr;
912 }
913
914 city_id = pplayer->wonders[idx];
915
916 fc_assert_ret_val(is_wonder(pimprove), nullptr);
917
918 if (!WONDER_BUILT(city_id)) {
919 return nullptr;
920 }
921
922#ifdef FREECIV_DEBUG
923 if (is_server()) {
924 /* On client side, this info is not always known. */
925 struct city *pcity = player_city_by_number(pplayer, city_id);
926
927 if (pcity == nullptr) {
928 log_error("Player %s (nb %d) has outdated wonder info for "
929 "%s (nb %d), it points to city nb %d.",
930 player_name(pplayer), player_number(pplayer),
931 improvement_rule_name(pimprove),
932 improvement_number(pimprove), city_id);
933 } else if (!city_has_building(pcity, pimprove)) {
934 log_error("Player %s (nb %d) has outdated wonder info for "
935 "%s (nb %d), the city %s (nb %d) doesn't have this wonder.",
936 player_name(pplayer), player_number(pplayer),
937 improvement_rule_name(pimprove),
939 return nullptr;
940 }
941
942 return pcity;
943 }
944#endif /* FREECIV_DEBUG */
945
946 return player_city_by_number(pplayer, city_id);
947}
948
949/**********************************************************************/
957 const struct player *pplayer,
958 const struct player *owner,
959 enum fc_tristate embassy)
960{
961 if (pplayer == owner) {
962 /* Can see all own wonders,
963 * even improvements if that matters. */
964 return TRUE;
965 }
966
967 if (is_great_wonder(wonder)) {
968 return TRUE;
969 }
970
971 if (is_small_wonder(wonder)) {
973 case WV_ALWAYS:
974 return TRUE;
975 case WV_NEVER:
976 return FALSE;
977 case WV_EMBASSY:
978 return embassy == TRI_YES
979 || (embassy == TRI_MAYBE && team_has_embassy(pplayer->team, owner));
980 }
981
983
984 return FALSE;
985 }
986
987 /* Now a wonder, but regular improvement */
988 return FALSE;
989}
990
991/**********************************************************************/
994bool great_wonder_is_built(const struct impr_type *pimprove)
995{
997
999 [improvement_index(pimprove)]);
1000}
1001
1002/**********************************************************************/
1005bool great_wonder_is_destroyed(const struct impr_type *pimprove)
1006{
1008
1009 return (WONDER_DESTROYED
1011}
1012
1013/**********************************************************************/
1016bool great_wonder_is_available(const struct impr_type *pimprove)
1017{
1019
1020 return (WONDER_NOT_OWNED
1022}
1023
1024/**********************************************************************/
1028struct city *city_from_great_wonder(const struct impr_type *pimprove)
1029{
1030 int player_id = game.info.great_wonder_owners[improvement_index(pimprove)];
1031
1032 fc_assert_ret_val(is_great_wonder(pimprove), nullptr);
1033
1034 if (WONDER_OWNED(player_id)) {
1035#ifdef FREECIV_DEBUG
1036 const struct player *pplayer = player_by_number(player_id);
1037 struct city *pcity = city_from_wonder(pplayer, pimprove);
1038
1039 if (is_server() && pcity == nullptr) {
1040 log_error("Game has outdated wonder info for %s (nb %d), "
1041 "the player %s (nb %d) doesn't have this wonder.",
1042 improvement_rule_name(pimprove),
1043 improvement_number(pimprove),
1044 player_name(pplayer), player_number(pplayer));
1045 }
1046
1047 return pcity;
1048#else
1049 return city_from_wonder(player_by_number(player_id), pimprove);
1050#endif /* FREECIV_DEBUG */
1051 } else {
1052 return nullptr;
1053 }
1054}
1055
1056/**********************************************************************/
1060struct player *great_wonder_owner(const struct impr_type *pimprove)
1061{
1062 int player_id = game.info.great_wonder_owners[improvement_index(pimprove)];
1063
1064 fc_assert_ret_val(is_great_wonder(pimprove), nullptr);
1065
1066 if (WONDER_OWNED(player_id)) {
1067 return player_by_number(player_id);
1068 } else {
1069 return nullptr;
1070 }
1071}
1072
1073/**********************************************************************/
1076bool small_wonder_is_built(const struct player *pplayer,
1077 const struct impr_type *pimprove)
1078{
1080
1081 return (pplayer != nullptr
1082 && wonder_is_built(pplayer, pimprove));
1083}
1084
1085/**********************************************************************/
1088struct city *city_from_small_wonder(const struct player *pplayer,
1089 const struct impr_type *pimprove)
1090{
1091 fc_assert_ret_val(is_small_wonder(pimprove), nullptr);
1092
1093 if (pplayer == nullptr) {
1094 return nullptr; /* Used in some places in the client. */
1095 } else {
1096 return city_from_wonder(pplayer, pimprove);
1097 }
1098}
1099
1100/**********************************************************************/
1103bool can_sell_building(const struct impr_type *pimprove)
1104{
1105 return (valid_improvement(pimprove)
1106 && is_building_sellable(pimprove));
1107}
1108
1109/**********************************************************************/
1113 const struct impr_type *pimprove)
1114{
1115 return (city_has_building(pcity, pimprove)
1116 && is_building_sellable(pimprove));
1117}
1118
1119/**********************************************************************/
1122bool is_building_sellable(const struct impr_type *pimprove)
1123{
1124 return is_improvement(pimprove);
1125}
1126
1127/**********************************************************************/
1133 struct city *pcity,
1134 const struct impr_type *pimprove)
1135{
1136 /* Check if player can sell anything from this city */
1137 if (pcity->owner != pplayer) {
1138 return TR_OTHER_FAILURE;
1139 }
1140
1141 if (pcity->did_sell) {
1142 return TR_ALREADY_SOLD;
1143 }
1144
1145 /* Check if particular building can be solt */
1146 if (pimprove != nullptr
1147 && !can_city_sell_building(pcity, pimprove)) {
1148 return TR_OTHER_FAILURE;
1149 }
1150
1151 return TR_SUCCESS;
1152}
1153
1154/**********************************************************************/
1158const struct impr_type *improvement_replacement(const struct impr_type *pimprove)
1159{
1161 if (pobs->source.kind == VUT_IMPROVEMENT && pobs->present) {
1162 return pobs->source.value.building;
1163 }
1165
1166 return nullptr;
1167}
1168
1169/************************************************************************/
1173{
1174 int i;
1175
1176 for (i = 0; i < MAX_NUM_USER_BUILDING_FLAGS; i++) {
1178 }
1179}
1180
1181/************************************************************************/
1185{
1186 int i;
1187
1188 for (i = 0; i < MAX_NUM_USER_BUILDING_FLAGS; i++) {
1190 }
1191}
1192
1193/************************************************************************/
1197 const char *helptxt)
1198{
1199 int bfid = id - IF_USER_FLAG_1;
1200
1202
1203 if (user_impr_flags[bfid].name != nullptr) {
1205 user_impr_flags[bfid].name = nullptr;
1206 }
1207
1208 if (name && name[0] != '\0') {
1210 }
1211
1212 if (user_impr_flags[bfid].helptxt != nullptr) {
1213 free(user_impr_flags[bfid].helptxt);
1214 user_impr_flags[bfid].helptxt = nullptr;
1215 }
1216
1217 if (helptxt && helptxt[0] != '\0') {
1219 }
1220}
1221
1222/************************************************************************/
1226{
1228 return nullptr;
1229 }
1230
1231 return user_impr_flags[flag - IF_USER_FLAG_1].name;
1232}
1233
1234/************************************************************************/
1238{
1240
1242}
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:5717
#define action_enablers_iterate_end
Definition actions.h:283
#define enabler_get_action_id(_enabler_)
Definition actions.h:187
#define action_id_get_actor_kind(act_id)
Definition actions.h:413
#define action_enablers_iterate(_enabler_)
Definition actions.h:277
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1287
const char * city_name_get(const struct city *pcity)
Definition city.c:1148
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:137
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:955
#define city_tile(_pcity_)
Definition city.h:565
#define city_owner(_pcity_)
Definition city.h:564
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:228
#define city_tile_iterate_end
Definition city.h:236
char * incite_cost
Definition comments.c:77
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2977
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 const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
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
bool can_disaster_happen(const struct disaster_type *pdis, const struct city *pcity)
Definition disaster.c:139
#define disaster_type_iterate(_p)
Definition disaster.h:82
#define disaster_type_iterate_end
Definition disaster.h:88
int int id
Definition editgui_g.h:28
bool is_building_replaced(const struct city *pcity, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Definition effects.c:693
int get_potential_improvement_bonus(const struct impr_type *pimprove, const struct city *pcity, enum effect_type effect_type, const enum req_problem_type prob_type, bool consider_multipliers)
Definition effects.c:1210
int get_building_bonus(const struct city *pcity, const struct impr_type *building, enum effect_type effect_type)
Definition effects.c:1008
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct req_context *other_context, enum effect_type effect_type)
Definition effects.c:744
struct effect_list * get_req_source_effects(const struct universal *psource)
Definition effects.c:153
bool building_has_effect(const struct impr_type *pimprove, enum effect_type effect_type)
Definition effects.c:639
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
#define effect_list_iterate_end
Definition effects.h:81
#define effect_list_iterate(effect_list, peffect)
Definition effects.h:79
bool player_can_build_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:468
#define extra_type_iterate(_p)
Definition extras.h:315
#define extra_type_iterate_end
Definition extras.h:321
static bool is_server(void)
#define MAX_NUM_USER_BUILDING_FLAGS
Definition fc_types.h:493
int Impr_type_id
Definition fc_types.h:237
req_problem_type
Definition fc_types.h:514
@ RPT_CERTAIN
Definition fc_types.h:516
@ RPT_POSSIBLE
Definition fc_types.h:515
int action_id
Definition fc_types.h:250
test_result
Definition fc_types.h:940
@ TR_ALREADY_SOLD
Definition fc_types.h:943
@ TR_OTHER_FAILURE
Definition fc_types.h:942
@ TR_SUCCESS
Definition fc_types.h:941
#define IF_LAST_USER_FLAG
Definition fc_types.h:492
@ VC_SPACERACE
Definition fc_types.h:966
#define Qn_(String)
Definition fcintl.h:89
void user_flag_init(struct user_flag *flag)
Definition game.c:834
void user_flag_free(struct user_flag *flag)
Definition game.c:843
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct city * owner
Definition citydlg.c:226
static GtkWidget * source
Definition gotodlg.c:58
const struct impr_type * valid_improvement(const struct impr_type *pimprove)
struct impr_type * improvement_by_number(const Impr_type_id id)
bool can_sell_building(const struct impr_type *pimprove)
int impr_sell_gold(const struct impr_type *pimprove)
void improvements_init(void)
Definition improvement.c:48
bool is_building_sellable(const struct impr_type *pimprove)
const struct impr_type * improvement_array_last(void)
const struct impr_type * valid_improvement_by_number(const Impr_type_id id)
bool can_city_sell_building(const struct city *pcity, const struct impr_type *pimprove)
bool great_wonder_is_built(const struct impr_type *pimprove)
static bool improvement_has_side_effects(const struct city *pcity, const struct impr_type *pimprove)
enum test_result test_player_sell_building_now(struct player *pplayer, struct city *pcity, const struct impr_type *pimprove)
void user_impr_flags_init(void)
bool is_special_improvement(const struct impr_type *pimprove)
static bool impr_prevents_disaster(const struct city *pcity, const struct impr_type *pimprove)
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
bool can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
bool wonder_is_lost(const struct player *pplayer, const struct impr_type *pimprove)
bool is_improvement(const struct impr_type *pimprove)
static bool improvement_has_effects(const struct city *pcity, const struct impr_type *pimprove)
bool wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove)
int impr_base_build_shield_cost(const struct impr_type *pimprove)
Impr_type_id improvement_number(const struct impr_type *pimprove)
static bool impr_provides_buildable_extras(const struct city *pcity, const struct impr_type *pimprove)
bool small_wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove)
bool can_improvement_go_obsolete(const struct impr_type *pimprove)
const char * impr_flag_id_name_cb(enum impr_flag_id flag)
const char * improvement_rule_name(const struct impr_type *pimprove)
bool is_improvement_visible(const struct impr_type *pimprove)
bool can_player_build_improvement_direct(const struct player *p, const struct impr_type *pimprove, const enum req_problem_type prob_type)
struct city * city_from_wonder(const struct player *pplayer, const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove, int shields_in_stock)
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
static void improvement_free(struct impr_type *p)
Definition improvement.c:68
bool is_wonder(const struct impr_type *pimprove)
static bool impr_protects_vs_actions(const struct city *pcity, const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
static bool impr_allows_actions(const struct city *pcity, const struct impr_type *pimprove)
struct impr_type * improvement_by_translated_name(const char *name)
void improvement_feature_cache_init(void)
Definition improvement.c:92
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
struct impr_type * improvement_by_rule_name(const char *name)
struct city * city_from_small_wonder(const struct player *pplayer, const struct impr_type *pimprove)
void wonder_destroyed(const struct city *pcity, const struct impr_type *pimprove)
void set_user_impr_flag_name(enum impr_flag_id id, const char *name, const char *helptxt)
bool can_player_build_improvement_now(const struct player *p, struct impr_type *pimprove, const enum req_problem_type prob_type)
bool is_convert_improvement(const struct impr_type *pimprove)
void impr_flags_free(void)
static struct impr_type improvement_types[B_LAST]
Definition improvement.c:41
bool wonder_visible_to_player(const struct impr_type *wonder, const struct player *pplayer, const struct player *owner, enum fc_tristate embassy)
const char * impr_flag_helptxt(enum impr_flag_id id)
const char * improvement_name_translation(const struct impr_type *pimprove)
struct city * city_from_great_wonder(const struct impr_type *pimprove)
Impr_type_id improvement_count(void)
static bool impr_provides_buildable_units(const struct city *pcity, const struct impr_type *pimprove)
bool is_small_wonder(const struct impr_type *pimprove)
struct impr_type * improvement_array_first(void)
int impr_estimate_build_shield_cost(const struct player *pplayer, const struct tile *ptile, const struct impr_type *pimprove)
const struct impr_type * improvement_replacement(const struct impr_type *pimprove)
struct player * great_wonder_owner(const struct impr_type *pimprove)
bool great_wonder_is_available(const struct impr_type *pimprove)
void improvements_free(void)
Definition improvement.c:82
bool is_improvement_productive(const struct city *pcity, const struct impr_type *pimprove)
static struct user_flag user_impr_flags[MAX_NUM_USER_BUILDING_FLAGS]
Definition improvement.c:43
#define WONDER_NOT_OWNED
#define WONDER_BUILT(city_id)
#define improvement_iterate_end
#define WONDER_DESTROYED
#define improvement_iterate(_p)
#define WONDER_LOST
#define B_LAST
Definition improvement.h:42
#define WONDER_OWNED(player_id)
const char * name
Definition inputfile.c:127
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_error(message,...)
Definition log.h:104
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
struct player * player_by_number(const int player_id)
Definition player.c:837
int player_number(const struct player *pplayer)
Definition player.c:826
const char * player_name(const struct player *pplayer)
Definition player.c:885
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:225
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1191
bool is_req_active(const struct req_context *context, const struct req_context *other_context, const struct requirement *req, const enum req_problem_type prob_type)
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_fulfilled_by_improvement(_imp_, _rqs_)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
#define requirement_needs_improvement(_imp_, _rqs_)
fc_tristate
Definition shared.h:46
@ TRI_YES
Definition shared.h:46
@ TRI_MAYBE
Definition shared.h:46
#define ARRAY_SIZE(x)
Definition shared.h:85
#define MAX(x, y)
Definition shared.h:54
#define NUM_SS_MODULES
Definition spaceship.h:89
#define NUM_SS_COMPONENTS
Definition spaceship.h:88
#define NUM_SS_STRUCTURALS
Definition spaceship.h:87
@ SSHIP_LAUNCHED
Definition spaceship.h:85
void strvec_destroy(struct strvec *psv)
Definition city.h:318
struct packet_ruleset_control control
Definition game.h:83
struct packet_game_info info
Definition game.h:89
bool allows_actions
Definition improvement.h:75
int build_cost
Definition improvement.h:60
enum impr_genus_id genus
Definition improvement.h:63
bool ruledit_disabled
Definition improvement.h:53
bool protects_vs_actions
Definition improvement.h:74
struct requirement_vector obsolete_by
Definition improvement.h:59
Impr_type_id item_number
Definition improvement.h:51
bool prevents_disaster
Definition improvement.h:73
struct requirement_vector reqs
Definition improvement.h:58
bool allows_extras
Definition improvement.h:72
struct strvec * helptext
Definition improvement.h:65
bool allows_units
Definition improvement.h:71
struct name_translation name
Definition improvement.h:52
bv_impr_flags flags
Definition improvement.h:64
void * ruledit_dlg
Definition improvement.h:54
int great_wonder_owners[B_LAST]
enum wonder_visib_type small_wonder_visibility
enum spaceship_state state
Definition spaceship.h:108
int wonders[B_LAST]
Definition player.h:305
struct team * team
Definition player.h:261
struct player_spaceship spaceship
Definition player.h:286
const struct player * player
Definition tile.h:50
int id
Definition unit.h:147
struct tile * tile
Definition unit.h:142
struct player * owner
Definition unit.h:145
enum universals_n kind
Definition fc_types.h:595
char * name
Definition game.h:74
char * helptxt
Definition game.h:75
struct civ_map map
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
bool utype_player_already_has_this(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1967
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:396
#define unit_type_iterate(_p)
Definition unittype.h:863
#define unit_type_iterate_end
Definition unittype.h:870
bool victory_enabled(enum victory_condition_type victory)
Definition victory.c:26