Freeciv-3.2
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 = NULL;
62 }
63}
64
65/**********************************************************************/
68static void improvement_free(struct impr_type *p)
69{
70 if (NULL != p->helptext) {
72 p->helptext = NULL;
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 return NULL;
148}
149
150/**********************************************************************/
154{
155 if (game.control.num_impr_types > 0) {
157 }
158 return NULL;
159}
160
161/**********************************************************************/
168
169/**********************************************************************/
176{
177 fc_assert_ret_val(NULL != pimprove, -1);
178 return pimprove - improvement_types;
179}
180
181/**********************************************************************/
185{
186 fc_assert_ret_val(NULL != pimprove, -1);
187 return pimprove->item_number;
188}
189
190/**********************************************************************/
195{
197 return NULL;
198 }
199 return &improvement_types[id];
200}
201
202/**********************************************************************/
211const struct impr_type *valid_improvement(const struct impr_type *pimprove)
212{
213 if (NULL == pimprove) {
214 return NULL;
215 }
216
220 || building_has_effect(pimprove, EFT_SS_MODULE))) {
221 /* This assumes that space parts don't have any other effects. */
222 return NULL;
223 }
224
225 return pimprove;
226}
227
228/**********************************************************************/
238
239/**********************************************************************/
243const char *improvement_name_translation(const struct impr_type *pimprove)
244{
245 return name_translation_get(&pimprove->name);
246}
247
248/**********************************************************************/
252const char *improvement_rule_name(const struct impr_type *pimprove)
253{
254 return rule_name_get(&pimprove->name);
255}
256
257/**********************************************************************/
261int impr_base_build_shield_cost(const struct impr_type *pimprove)
262{
263 int base = pimprove->build_cost;
264
265 return MAX(base * game.info.shieldbox / 100, 1);
266}
267
268/**********************************************************************/
273int impr_estimate_build_shield_cost(const struct player *pplayer,
274 const struct tile *ptile,
275 const struct impr_type *pimprove)
276{
277 int base = pimprove->build_cost
278 * (100 +
280 &(const struct req_context) {
281 .player = pplayer,
282 .building = pimprove,
283 .tile = ptile,
284 },
285 NULL,
287
288 return MAX(base * game.info.shieldbox / 100, 1);
289}
290
291/**********************************************************************/
294int impr_build_shield_cost(const struct city *pcity,
295 const struct impr_type *pimprove)
296{
297 int base = pimprove->build_cost
298 * (100 + get_building_bonus(pcity, pimprove, EFT_IMPR_BUILD_COST_PCT)) / 100;
299
300 return MAX(base * game.info.shieldbox / 100, 1);
301}
302
303/**********************************************************************/
306int impr_buy_gold_cost(const struct city *pcity,
307 const struct impr_type *pimprove, int shields_in_stock)
308{
309 int cost = 0;
310 const int missing = impr_build_shield_cost(pcity, pimprove) - shields_in_stock;
311
312 if (is_convert_improvement(pimprove)) {
313 /* Can't buy coinage-like improvements. */
314 return 0;
315 }
316
317 if (missing > 0) {
318 cost = 2 * missing;
319 }
320
321 if (shields_in_stock == 0) {
322 cost *= 2;
323 }
324
325 cost = cost
326 * (100 + get_building_bonus(pcity, pimprove, EFT_IMPR_BUY_COST_PCT)) / 100;
327
328 return cost;
329}
330
331/**********************************************************************/
334int impr_sell_gold(const struct impr_type *pimprove)
335{
336 return MAX(pimprove->build_cost * game.info.shieldbox / 100, 1);
337}
338
339/**********************************************************************/
343bool is_wonder(const struct impr_type *pimprove)
344{
345 return (is_great_wonder(pimprove) || is_small_wonder(pimprove));
346}
347
348/**********************************************************************/
353{
354 improvement_iterate(pimprove) {
355 if (0 == strcmp(improvement_name_translation(pimprove), name)) {
356 return pimprove;
357 }
359
360 return NULL;
361}
362
363/**********************************************************************/
368{
369 const char *qname = Qn_(name);
370
371 improvement_iterate(pimprove) {
372 if (0 == fc_strcasecmp(improvement_rule_name(pimprove), qname)) {
373 return pimprove;
374 }
376
377 return NULL;
378}
379
380/**********************************************************************/
383bool improvement_has_flag(const struct impr_type *pimprove,
384 enum impr_flag_id flag)
385{
387 return BV_ISSET(pimprove->flags, flag);
388}
389
390/**********************************************************************/
393bool is_improvement_visible(const struct impr_type *pimprove)
394{
395 return (is_wonder(pimprove)
397}
398
399/**********************************************************************/
403bool can_improvement_go_obsolete(const struct impr_type *pimprove)
404{
405 return requirement_vector_size(&pimprove->obsolete_by) > 0;
406}
407
408/**********************************************************************/
411bool improvement_obsolete(const struct player *pplayer,
412 const struct impr_type *pimprove,
413 const struct city *pcity)
414{
415 const struct req_context context = {
416 .player = pplayer,
417 .city = pcity,
418 .tile = pcity ? city_tile(pcity) : NULL,
419 .building = pimprove,
420 };
421
424 return TRUE;
425 }
427
428 return FALSE;
429}
430
431/**********************************************************************/
434static bool impr_provides_buildable_units(const struct city *pcity,
435 const struct impr_type *pimprove)
436{
437 const struct civ_map *nmap = &(wld.map);
438
439 /* Fast check */
440 if (!pimprove->allows_units) {
441 return FALSE;
442 }
443
445 if (requirement_needs_improvement(pimprove, &ut->build_reqs)
446 && can_city_build_unit_now(nmap, pcity, ut)) {
447 return TRUE;
448 }
450
451 return FALSE;
452}
453
454/**********************************************************************/
457static bool impr_provides_buildable_extras(const struct city *pcity,
458 const struct impr_type *pimprove)
459{
460 const struct civ_map *nmap = &(wld.map);
461
462 /* Fast check */
463 if (!pimprove->allows_extras) {
464 return FALSE;
465 }
466
467 extra_type_iterate(pextra) {
468 if (requirement_needs_improvement(pimprove, &pextra->reqs)) {
470 city_tile(pcity), ptile) {
471 if (player_can_build_extra(pextra, city_owner(pcity), ptile)) {
472 return TRUE;
473 }
475 }
477
478 return FALSE;
479}
480
481/**********************************************************************/
484static bool impr_prevents_disaster(const struct city *pcity,
485 const struct impr_type *pimprove)
486{
487 /* Fast check */
488 if (!pimprove->prevents_disaster) {
489 return FALSE;
490 }
491
494 && !can_disaster_happen(pdis, pcity)) {
495 return TRUE;
496 }
498
499 return FALSE;
500}
501
502/**********************************************************************/
508static bool impr_protects_vs_actions(const struct city *pcity,
509 const struct impr_type *pimprove)
510{
511 /* Fast check */
512 if (!pimprove->protects_vs_actions) {
513 return FALSE;
514 }
515
517 if (!requirement_fulfilled_by_improvement(pimprove, &enabler->target_reqs)
519 NULL, pcity)) {
520 return TRUE;
521 }
523
524 return FALSE;
525}
526
527/**********************************************************************/
530static bool impr_allows_actions(const struct city *pcity,
531 const struct impr_type *pimprove)
532{
533 const struct civ_map *nmap = &(wld.map);
534
535 /* Fast check */
536 if (!pimprove->allows_actions) {
537 return FALSE;
538 }
539
541 if (requirement_needs_improvement(pimprove, &enabler->actor_reqs)) {
543
544 switch (action_id_get_actor_kind(act)) {
545 case AAK_UNIT:
547 if (!utype_can_do_action(ut, act)) {
548 /* Not relevant */
549 continue;
550 }
551
553 /* The player has a unit that may use the building */
554 return TRUE;
555 }
556
557 if (can_city_build_unit_now(nmap, pcity, ut)) {
558 /* This city can build a unit that uses the building */
559 return TRUE;
560 }
562 break;
563 case AAK_COUNT:
565 break;
566 }
567 }
569
570 return FALSE;
571}
572
573/**********************************************************************/
583static bool improvement_has_side_effects(const struct city *pcity,
584 const struct impr_type *pimprove)
585{
586 return (impr_provides_buildable_units(pcity, pimprove)
587 || impr_provides_buildable_extras(pcity, pimprove)
588 || impr_prevents_disaster(pcity, pimprove)
589 || impr_allows_actions(pcity, pimprove)
590 || impr_protects_vs_actions(pcity, pimprove));
591}
592
593/**********************************************************************/
596static bool improvement_has_effects(const struct city *pcity,
597 const struct impr_type *pimprove)
598{
599 struct universal source = { .kind = VUT_IMPROVEMENT,
600 .value = { .building = pimprove } };
602
603 if (!plist || improvement_obsolete(city_owner(pcity), pimprove, pcity)) {
604 return FALSE;
605 }
606
608 if (0 != get_potential_improvement_bonus(pimprove, pcity,
609 peffect->type, RPT_CERTAIN, TRUE)) {
610 return TRUE;
611 }
613
614 return FALSE;
615}
616
617/**********************************************************************/
624bool is_improvement_productive(const struct city *pcity,
625 const struct impr_type *pimprove)
626{
627 return (!improvement_obsolete(city_owner(pcity), pimprove, pcity)
628 && (improvement_has_flag(pimprove, IF_GOLD)
629 || improvement_has_side_effects(pcity, pimprove)
630 || improvement_has_effects(pcity, pimprove)));
631}
632
633/**********************************************************************/
645bool is_improvement_redundant(const struct city *pcity,
646 const struct impr_type *pimprove)
647{
648 /* A capitalization production is never redundant. */
649 if (improvement_has_flag(pimprove, IF_GOLD)) {
650 return FALSE;
651 }
652
653 /* If an improvement has side effects, don't claim it's redundant. */
654 if (improvement_has_side_effects(pcity, pimprove)) {
655 return FALSE;
656 }
657
658 /* Otherwise, it's redundant if its effects are available by other means,
659 * or if it's an obsolete wonder (great or small). */
660 return is_building_replaced(pcity, pimprove, RPT_CERTAIN)
661 || improvement_obsolete(city_owner(pcity), pimprove, pcity);
662}
663
664/**********************************************************************/
669 const struct impr_type *pimprove)
670{
671 const struct req_context context = { .player = p };
672
673 bool space_part = FALSE;
674
675 if (!valid_improvement(pimprove)) {
676 return FALSE;
677 }
678
680 if (preq->range >= REQ_RANGE_PLAYER
682 return FALSE;
683 }
685
686 /* Check for space part construction. This assumes that space parts have
687 * no other effects. */
688 if (building_has_effect(pimprove, EFT_SS_STRUCTURAL)) {
691 return FALSE;
692 }
693 }
694 if (building_has_effect(pimprove, EFT_SS_COMPONENT)) {
697 return FALSE;
698 }
699 }
700 if (building_has_effect(pimprove, EFT_SS_MODULE)) {
702 if (p->spaceship.modules >= NUM_SS_MODULES) {
703 return FALSE;
704 }
705 }
706 if (space_part
708 || p->spaceship.state >= SSHIP_LAUNCHED)) {
709 return FALSE;
710 }
711
712 if (is_great_wonder(pimprove)) {
713 /* Can't build wonder if already built */
714 if (!great_wonder_is_available(pimprove)) {
715 return FALSE;
716 }
717 }
718
719 return TRUE;
720}
721
722/**********************************************************************/
727 struct impr_type *pimprove)
728{
729 if (!can_player_build_improvement_direct(p, pimprove)) {
730 return FALSE;
731 }
732 if (improvement_obsolete(p, pimprove, NULL)) {
733 return FALSE;
734 }
735 return TRUE;
736}
737
738/**********************************************************************/
744 const struct impr_type *pimprove)
745{
746 const struct req_context context = { .player = p };
747
748 if (!valid_improvement(pimprove)) {
749 return FALSE;
750 }
751 if (improvement_obsolete(p, pimprove, NULL)) {
752 return FALSE;
753 }
754 if (is_great_wonder(pimprove) && !great_wonder_is_available(pimprove)) {
755 /* Can't build wonder if already built */
756 return FALSE;
757 }
758
759 /* Check for requirements that aren't met and that are unchanging (so
760 * they can never be met). */
762 if (preq->range >= REQ_RANGE_PLAYER
764 return FALSE;
765 }
767 /* FIXME: should check some "unchanging" reqs here - like if there's
768 * a nation requirement, we can go ahead and check it now. */
769
770 return TRUE;
771}
772
773/**********************************************************************/
776bool is_great_wonder(const struct impr_type *pimprove)
777{
778 return (pimprove->genus == IG_GREAT_WONDER);
779}
780
781/**********************************************************************/
784bool is_small_wonder(const struct impr_type *pimprove)
785{
786 return (pimprove->genus == IG_SMALL_WONDER);
787}
788
789/**********************************************************************/
792bool is_improvement(const struct impr_type *pimprove)
793{
794 return (pimprove->genus == IG_IMPROVEMENT);
795}
796
797/**********************************************************************/
801bool is_special_improvement(const struct impr_type *pimprove)
802{
803 /* TODO: Find either a new term for traditional "special" improvements
804 * (maybe "project"?), or a new umbrella term for all improvements that
805 * can't be present in the city as a finished building (including special
806 * and convert improvements). */
807 return (pimprove->genus == IG_SPECIAL)
808 || is_convert_improvement(pimprove);
809}
810
811/**********************************************************************/
815bool is_convert_improvement(const struct impr_type *pimprove)
816{
817 return (pimprove->genus == IG_CONVERT);
818}
819
820/**********************************************************************/
823void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
824{
825 struct player *pplayer;
826 int windex = improvement_number(pimprove);
827
828 fc_assert_ret(NULL != pcity);
829 fc_assert_ret(is_wonder(pimprove));
830
831 pplayer = city_owner(pcity);
832 pplayer->wonders[windex] = pcity->id;
833
834 if (is_great_wonder(pimprove)) {
836 }
837}
838
839/**********************************************************************/
843void wonder_destroyed(const struct city *pcity,
844 const struct impr_type *pimprove)
845{
846 struct player *pplayer;
847 int windex = improvement_number(pimprove);
848
849 fc_assert_ret(NULL != pcity);
850 fc_assert_ret(is_wonder(pimprove));
851
852 pplayer = city_owner(pcity);
853 fc_assert_ret(pplayer->wonders[windex] == pcity->id);
854 pplayer->wonders[windex] = WONDER_LOST;
855
856 if (is_great_wonder(pimprove)) {
858 == player_number(pplayer));
860 }
861}
862
863/**********************************************************************/
867bool wonder_is_lost(const struct player *pplayer,
868 const struct impr_type *pimprove)
869{
870 fc_assert_ret_val(NULL != pplayer, FALSE);
872
873 return pplayer->wonders[improvement_index(pimprove)] == WONDER_LOST;
874}
875
876/**********************************************************************/
880bool wonder_is_built(const struct player *pplayer,
881 const struct impr_type *pimprove)
882{
883 fc_assert_ret_val(NULL != pplayer, FALSE);
885
886 return WONDER_BUILT(pplayer->wonders[improvement_index(pimprove)]);
887}
888
889/**********************************************************************/
895struct city *city_from_wonder(const struct player *pplayer,
896 const struct impr_type *pimprove)
897{
898 int idx = improvement_index(pimprove);
899 int city_id;
900
901 if (idx < 0) {
902 return NULL;
903 }
904
905 city_id = pplayer->wonders[idx];
906
907 fc_assert_ret_val(NULL != pplayer, NULL);
908 fc_assert_ret_val(is_wonder(pimprove), NULL);
909
910 if (!WONDER_BUILT(city_id)) {
911 return NULL;
912 }
913
914#ifdef FREECIV_DEBUG
915 if (is_server()) {
916 /* On client side, this info is not always known. */
917 struct city *pcity = player_city_by_number(pplayer, city_id);
918
919 if (NULL == pcity) {
920 log_error("Player %s (nb %d) has outdated wonder info for "
921 "%s (nb %d), it points to city nb %d.",
922 player_name(pplayer), player_number(pplayer),
923 improvement_rule_name(pimprove),
924 improvement_number(pimprove), city_id);
925 } else if (!city_has_building(pcity, pimprove)) {
926 log_error("Player %s (nb %d) has outdated wonder info for "
927 "%s (nb %d), the city %s (nb %d) doesn't have this wonder.",
928 player_name(pplayer), player_number(pplayer),
929 improvement_rule_name(pimprove),
930 improvement_number(pimprove), city_name_get(pcity), pcity->id);
931 return NULL;
932 }
933
934 return pcity;
935 }
936#endif /* FREECIV_DEBUG */
937
938 return player_city_by_number(pplayer, city_id);
939}
940
941/**********************************************************************/
949 const struct player *pplayer,
950 const struct player *owner,
951 enum fc_tristate embassy)
952{
953 if (pplayer == owner) {
954 /* Can see all own wonders,
955 * even improvements if that matters. */
956 return TRUE;
957 }
958
959 if (is_great_wonder(wonder)) {
960 return TRUE;
961 }
962
963 if (is_small_wonder(wonder)) {
965 case WV_ALWAYS:
966 return TRUE;
967 case WV_NEVER:
968 return FALSE;
969 case WV_EMBASSY:
970 return embassy == TRI_YES
971 || (embassy == TRI_MAYBE && team_has_embassy(pplayer->team, owner));
972 }
973
975
976 return FALSE;
977 }
978
979 /* Now a wonder, but regular improvement */
980 return FALSE;
981}
982
983/**********************************************************************/
986bool great_wonder_is_built(const struct impr_type *pimprove)
987{
989
991 [improvement_index(pimprove)]);
992}
993
994/**********************************************************************/
997bool great_wonder_is_destroyed(const struct impr_type *pimprove)
998{
1000
1001 return (WONDER_DESTROYED
1003}
1004
1005/**********************************************************************/
1008bool great_wonder_is_available(const struct impr_type *pimprove)
1009{
1011
1012 return (WONDER_NOT_OWNED
1014}
1015
1016/**********************************************************************/
1020struct city *city_from_great_wonder(const struct impr_type *pimprove)
1021{
1022 int player_id = game.info.great_wonder_owners[improvement_index(pimprove)];
1023
1025
1026 if (WONDER_OWNED(player_id)) {
1027#ifdef FREECIV_DEBUG
1028 const struct player *pplayer = player_by_number(player_id);
1029 struct city *pcity = city_from_wonder(pplayer, pimprove);
1030
1031 if (is_server() && NULL == pcity) {
1032 log_error("Game has outdated wonder info for %s (nb %d), "
1033 "the player %s (nb %d) doesn't have this wonder.",
1034 improvement_rule_name(pimprove),
1035 improvement_number(pimprove),
1036 player_name(pplayer), player_number(pplayer));
1037 }
1038
1039 return pcity;
1040#else
1041 return city_from_wonder(player_by_number(player_id), pimprove);
1042#endif /* FREECIV_DEBUG */
1043 } else {
1044 return NULL;
1045 }
1046}
1047
1048/**********************************************************************/
1052struct player *great_wonder_owner(const struct impr_type *pimprove)
1053{
1054 int player_id = game.info.great_wonder_owners[improvement_index(pimprove)];
1055
1057
1058 if (WONDER_OWNED(player_id)) {
1059 return player_by_number(player_id);
1060 } else {
1061 return NULL;
1062 }
1063}
1064
1065/**********************************************************************/
1068bool small_wonder_is_built(const struct player *pplayer,
1069 const struct impr_type *pimprove)
1070{
1072
1073 return (NULL != pplayer
1074 && wonder_is_built(pplayer, pimprove));
1075}
1076
1077/**********************************************************************/
1080struct city *city_from_small_wonder(const struct player *pplayer,
1081 const struct impr_type *pimprove)
1082{
1084
1085 if (NULL == pplayer) {
1086 return NULL; /* Used in some places in the client. */
1087 } else {
1088 return city_from_wonder(pplayer, pimprove);
1089 }
1090}
1091
1092/**********************************************************************/
1095bool can_sell_building(const struct impr_type *pimprove)
1096{
1097 return (valid_improvement(pimprove)
1098 && is_building_sellable(pimprove));
1099}
1100
1101/**********************************************************************/
1104bool can_city_sell_building(const struct city *pcity,
1105 const struct impr_type *pimprove)
1106{
1107 return (city_has_building(pcity, pimprove)
1108 && is_building_sellable(pimprove));
1109}
1110
1111/**********************************************************************/
1114bool is_building_sellable(const struct impr_type *pimprove)
1115{
1116 return is_improvement(pimprove);
1117}
1118
1119/**********************************************************************/
1125 struct city *pcity,
1126 const struct impr_type *pimprove)
1127{
1128 /* Check if player can sell anything from this city */
1129 if (pcity->owner != pplayer) {
1130 return TR_OTHER_FAILURE;
1131 }
1132
1133 if (pcity->did_sell) {
1134 return TR_ALREADY_SOLD;
1135 }
1136
1137 /* Check if particular building can be solt */
1138 if (pimprove != NULL
1139 && !can_city_sell_building(pcity, pimprove)) {
1140 return TR_OTHER_FAILURE;
1141 }
1142
1143 return TR_SUCCESS;
1144}
1145
1146/**********************************************************************/
1150const struct impr_type *improvement_replacement(const struct impr_type *pimprove)
1151{
1153 if (pobs->source.kind == VUT_IMPROVEMENT && pobs->present) {
1154 return pobs->source.value.building;
1155 }
1157
1158 return NULL;
1159}
1160
1161/************************************************************************/
1165{
1166 int i;
1167
1168 for (i = 0; i < MAX_NUM_USER_BUILDING_FLAGS; i++) {
1170 }
1171}
1172
1173/************************************************************************/
1177{
1178 int i;
1179
1180 for (i = 0; i < MAX_NUM_USER_BUILDING_FLAGS; i++) {
1182 }
1183}
1184
1185/************************************************************************/
1189 const char *helptxt)
1190{
1191 int bfid = id - IF_USER_FLAG_1;
1192
1194
1195 if (user_impr_flags[bfid].name != NULL) {
1198 }
1199
1200 if (name && name[0] != '\0') {
1202 }
1203
1204 if (user_impr_flags[bfid].helptxt != NULL) {
1205 free(user_impr_flags[bfid].helptxt);
1207 }
1208
1209 if (helptxt && helptxt[0] != '\0') {
1211 }
1212}
1213
1214/************************************************************************/
1218{
1220 return NULL;
1221 }
1222
1223 return user_impr_flags[flag - IF_USER_FLAG_1].name;
1224}
1225
1226/************************************************************************/
1230{
1232
1234}
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:6214
#define action_enablers_iterate_end
Definition actions.h:519
#define enabler_get_action_id(_enabler_)
Definition actions.h:434
#define action_id_get_actor_kind(act_id)
Definition actions.h:648
#define action_enablers_iterate(_enabler_)
Definition actions.h:513
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1240
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
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:947
#define city_tile(_pcity_)
Definition city.h:564
#define city_owner(_pcity_)
Definition city.h:563
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:230
#define city_tile_iterate_end
Definition city.h:238
char * incite_cost
Definition comments.c:75
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2931
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:80
#define disaster_type_iterate_end
Definition disaster.h:86
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:698
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:748
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:1204
int get_building_bonus(const struct city *pcity, const struct impr_type *building, enum effect_type effect_type)
Definition effects.c:1008
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:644
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
#define effect_list_iterate_end
Definition effects.h:406
#define effect_list_iterate(effect_list, peffect)
Definition effects.h:404
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:678
int Impr_type_id
Definition fc_types.h:376
@ RPT_CERTAIN
Definition fc_types.h:701
@ RPT_POSSIBLE
Definition fc_types.h:700
int action_id
Definition fc_types.h:389
test_result
Definition fc_types.h:1245
@ TR_ALREADY_SOLD
Definition fc_types.h:1248
@ TR_OTHER_FAILURE
Definition fc_types.h:1247
@ TR_SUCCESS
Definition fc_types.h:1246
#define IF_LAST_USER_FLAG
Definition fc_types.h:677
@ VC_SPACERACE
Definition fc_types.h:1271
#define Qn_(String)
Definition fcintl.h:89
void user_flag_init(struct user_flag *flag)
Definition game.c:824
void user_flag_free(struct user_flag *flag)
Definition game.c:833
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 can_player_build_improvement_direct(const struct player *p, 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 can_player_build_improvement_now(const struct player *p, 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)
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 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:191
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_error(message,...)
Definition log.h:103
#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:849
int player_number(const struct player *pplayer)
Definition player.c:837
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
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1203
bool is_req_active(const struct req_context *context, const struct player *other_player, 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 player *other_player, 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:320
bool did_sell
Definition city.h:380
int id
Definition city.h:326
struct player * owner
Definition city.h:323
struct tile * tile
Definition city.h:322
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:303
struct team * team
Definition player.h:259
struct player_spaceship spaceship
Definition player.h:284
const struct player * player
Definition tile.h:50
enum universals_n kind
Definition fc_types.h:902
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:189
#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:1941
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:371
#define unit_type_iterate(_p)
Definition unittype.h:855
#define unit_type_iterate_end
Definition unittype.h:862
bool victory_enabled(enum victory_condition_type victory)
Definition victory.c:26