Freeciv-3.1
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
43/**********************************************************************/
47{
48 int i;
49
50 /* Can't use improvement_iterate() or improvement_by_number() here
51 * because num_impr_types isn't known yet. */
52 for (i = 0; i < ARRAY_SIZE(improvement_types); i++) {
53 struct impr_type *p = &improvement_types[i];
54
55 p->item_number = i;
56 requirement_vector_init(&p->reqs);
57 requirement_vector_init(&p->obsolete_by);
59 p->ruledit_dlg = NULL;
60 }
61}
62
63/**********************************************************************/
66static void improvement_free(struct impr_type *p)
67{
68 if (NULL != p->helptext) {
70 p->helptext = NULL;
71 }
72
73 requirement_vector_free(&p->reqs);
74 requirement_vector_free(&p->obsolete_by);
75}
76
77/**********************************************************************/
86
87/**********************************************************************/
91{
92 improvement_iterate(pimprove) {
93 pimprove->allows_units = FALSE;
94 unit_type_iterate(putype) {
95 if (requirement_needs_improvement(pimprove, &putype->build_reqs)) {
96 pimprove->allows_units = TRUE;
97 break;
98 }
100
101 pimprove->allows_extras = FALSE;
102 extra_type_iterate(pextra) {
103 if (requirement_needs_improvement(pimprove, &pextra->reqs)) {
104 pimprove->allows_extras = TRUE;
105 break;
106 }
108
109 pimprove->prevents_disaster = FALSE;
111 if (!requirement_fulfilled_by_improvement(pimprove, &pdis->reqs)) {
112 pimprove->prevents_disaster = TRUE;
113 break;
114 }
116
117 pimprove->protects_vs_actions = FALSE;
120 &act->target_reqs)) {
121 pimprove->protects_vs_actions = TRUE;
122 break;
123 }
125
126 pimprove->allows_actions = FALSE;
128 if (requirement_needs_improvement(pimprove, &act->actor_reqs)) {
129 pimprove->allows_actions = TRUE;
130 break;
131 }
133
135}
136
137/**********************************************************************/
141{
142 if (game.control.num_impr_types > 0) {
143 return improvement_types;
144 }
145 return NULL;
146}
147
148/**********************************************************************/
152{
153 if (game.control.num_impr_types > 0) {
155 }
156 return NULL;
157}
158
159/**********************************************************************/
166
167/**********************************************************************/
174{
175 fc_assert_ret_val(NULL != pimprove, -1);
176 return pimprove - improvement_types;
177}
178
179/**********************************************************************/
183{
184 fc_assert_ret_val(NULL != pimprove, -1);
185 return pimprove->item_number;
186}
187
188/**********************************************************************/
193{
194 if (id < 0 || id >= improvement_count()) {
195 return NULL;
196 }
197 return &improvement_types[id];
198}
199
200/**********************************************************************/
209const struct impr_type *valid_improvement(const struct impr_type *pimprove)
210{
211 if (NULL == pimprove) {
212 return NULL;
213 }
214
216 && (building_has_effect(pimprove, EFT_SS_STRUCTURAL)
217 || building_has_effect(pimprove, EFT_SS_COMPONENT)
218 || building_has_effect(pimprove, EFT_SS_MODULE))) {
219 /* This assumes that space parts don't have any other effects. */
220 return NULL;
221 }
222
223 return pimprove;
224}
225
226/**********************************************************************/
236
237/**********************************************************************/
241const char *improvement_name_translation(const struct impr_type *pimprove)
242{
243 return name_translation_get(&pimprove->name);
244}
245
246/**********************************************************************/
250const char *improvement_rule_name(const struct impr_type *pimprove)
251{
252 return rule_name_get(&pimprove->name);
253}
254
255/**********************************************************************/
259int impr_base_build_shield_cost(const struct impr_type *pimprove)
260{
261 int base = pimprove->build_cost;
262
263 return MAX(base * game.info.shieldbox / 100, 1);
264}
265
266/**********************************************************************/
271int impr_estimate_build_shield_cost(const struct player *pplayer,
272 const struct tile *ptile,
273 const struct impr_type *pimprove)
274{
275 int base = pimprove->build_cost
276 * (100 +
278 &(const struct req_context) {
279 .player = pplayer,
280 .building = pimprove,
281 .tile = ptile,
282 },
283 NULL,
284 EFT_IMPR_BUILD_COST_PCT)) / 100;
285
286 return MAX(base * game.info.shieldbox / 100, 1);
287}
288
289/**********************************************************************/
292int impr_build_shield_cost(const struct city *pcity,
293 const struct impr_type *pimprove)
294{
295 int base = pimprove->build_cost
296 * (100 + get_building_bonus(pcity, pimprove, EFT_IMPR_BUILD_COST_PCT)) / 100;
297
298 return MAX(base * game.info.shieldbox / 100, 1);
299}
300
301/**********************************************************************/
304int impr_buy_gold_cost(const struct city *pcity,
305 const struct impr_type *pimprove, int shields_in_stock)
306{
307 int cost = 0;
308 const int missing = impr_build_shield_cost(pcity, pimprove) - shields_in_stock;
309
310 if (improvement_has_flag(pimprove, IF_GOLD)) {
311 /* Can't buy capitalization. */
312 return 0;
313 }
314
315 if (missing > 0) {
316 cost = 2 * missing;
317 }
318
319 if (shields_in_stock == 0) {
320 cost *= 2;
321 }
322
323 cost = cost
324 * (100 + get_building_bonus(pcity, pimprove, EFT_IMPR_BUY_COST_PCT)) / 100;
325
326 return cost;
327}
328
329/**********************************************************************/
332int impr_sell_gold(const struct impr_type *pimprove)
333{
334 return MAX(pimprove->build_cost * game.info.shieldbox / 100, 1);
335}
336
337/**********************************************************************/
341bool is_wonder(const struct impr_type *pimprove)
342{
343 return (is_great_wonder(pimprove) || is_small_wonder(pimprove));
344}
345
346/**********************************************************************/
351{
352 improvement_iterate(pimprove) {
353 if (0 == strcmp(improvement_name_translation(pimprove), name)) {
354 return pimprove;
355 }
357
358 return NULL;
359}
360
361/**********************************************************************/
366{
367 const char *qname = Qn_(name);
368
369 improvement_iterate(pimprove) {
370 if (0 == fc_strcasecmp(improvement_rule_name(pimprove), qname)) {
371 return pimprove;
372 }
374
375 return NULL;
376}
377
378/**********************************************************************/
381bool improvement_has_flag(const struct impr_type *pimprove,
382 enum impr_flag_id flag)
383{
384 fc_assert_ret_val(impr_flag_id_is_valid(flag), FALSE);
385 return BV_ISSET(pimprove->flags, flag);
386}
387
388/**********************************************************************/
391bool is_improvement_visible(const struct impr_type *pimprove)
392{
393 return (is_wonder(pimprove)
394 || improvement_has_flag(pimprove, IF_VISIBLE_BY_OTHERS));
395}
396
397/**********************************************************************/
401bool can_improvement_go_obsolete(const struct impr_type *pimprove)
402{
403 return requirement_vector_size(&pimprove->obsolete_by) > 0;
404}
405
406/**********************************************************************/
409bool improvement_obsolete(const struct player *pplayer,
410 const struct impr_type *pimprove,
411 const struct city *pcity)
412{
413 const struct req_context context = {
414 .player = pplayer,
415 .city = pcity,
416 .tile = pcity ? city_tile(pcity) : NULL,
417 .building = pimprove,
418 };
419
420 requirement_vector_iterate(&pimprove->obsolete_by, preq) {
421 if (is_req_active(&context, NULL, preq, RPT_CERTAIN)) {
422 return TRUE;
423 }
425
426 return FALSE;
427}
428
429/**********************************************************************/
432static bool impr_provides_buildable_units(const struct city *pcity,
433 const struct impr_type *pimprove)
434{
435 /* Fast check */
436 if (!pimprove->allows_units) {
437 return FALSE;
438 }
439
441 if (requirement_needs_improvement(pimprove, &ut->build_reqs)
442 && can_city_build_unit_now(pcity, ut)) {
443 return TRUE;
444 }
446
447 return FALSE;
448}
449
450/**********************************************************************/
453static bool impr_provides_buildable_extras(const struct city *pcity,
454 const struct impr_type *pimprove)
455{
456 const struct civ_map *nmap = &(wld.map);
457
458 /* Fast check */
459 if (!pimprove->allows_extras) {
460 return FALSE;
461 }
462
463 extra_type_iterate(pextra) {
464 if (requirement_needs_improvement(pimprove, &pextra->reqs)) {
466 city_tile(pcity), ptile) {
467 if (player_can_build_extra(pextra, city_owner(pcity), ptile)) {
468 return TRUE;
469 }
471 }
473
474 return FALSE;
475}
476
477/**********************************************************************/
480static bool impr_prevents_disaster(const struct city *pcity,
481 const struct impr_type *pimprove)
482{
483 /* Fast check */
484 if (!pimprove->prevents_disaster) {
485 return FALSE;
486 }
487
489 if (!requirement_fulfilled_by_improvement(pimprove, &pdis->reqs)
490 && !can_disaster_happen(pdis, pcity)) {
491 return TRUE;
492 }
494
495 return FALSE;
496}
497
498/**********************************************************************/
504static bool impr_protects_vs_actions(const struct city *pcity,
505 const struct impr_type *pimprove)
506{
507 /* Fast check */
508 if (!pimprove->protects_vs_actions) {
509 return FALSE;
510 }
511
513 if (!requirement_fulfilled_by_improvement(pimprove, &act->target_reqs)
514 && !is_action_possible_on_city(act->action, NULL, pcity)) {
515 return TRUE;
516 }
518
519 return FALSE;
520}
521
522/**********************************************************************/
525static bool impr_allows_actions(const struct city *pcity,
526 const struct impr_type *pimprove)
527{
528 /* Fast check */
529 if (!pimprove->allows_actions) {
530 return FALSE;
531 }
532
534 if (requirement_needs_improvement(pimprove, &act->actor_reqs)) {
535 switch (action_id_get_actor_kind(act->action)) {
536 case AAK_UNIT:
538 if (!utype_can_do_action(ut, act->action)) {
539 /* Not relevant */
540 continue;
541 }
542
544 /* The player has a unit that may use the building */
545 return TRUE;
546 }
547
548 if (can_city_build_unit_now(pcity, ut)) {
549 /* This city can build a unit that uses the building */
550 return TRUE;
551 }
553 break;
554 case AAK_COUNT:
555 fc_assert(action_id_get_actor_kind(act->action) != AAK_COUNT);
556 break;
557 }
558 }
560
561 return FALSE;
562}
563
564/**********************************************************************/
574static bool improvement_has_side_effects(const struct city *pcity,
575 const struct impr_type *pimprove)
576{
577 return (impr_provides_buildable_units(pcity, pimprove)
578 || impr_provides_buildable_extras(pcity, pimprove)
579 || impr_prevents_disaster(pcity, pimprove)
580 || impr_allows_actions(pcity, pimprove)
581 || impr_protects_vs_actions(pcity, pimprove));
582}
583
584/**********************************************************************/
587static bool improvement_has_effects(const struct city *pcity,
588 const struct impr_type *pimprove)
589{
590 struct universal source = { .kind = VUT_IMPROVEMENT,
591 .value = { .building = pimprove } };
592 struct effect_list *plist = get_req_source_effects(&source);
593
594 if (!plist || improvement_obsolete(city_owner(pcity), pimprove, pcity)) {
595 return FALSE;
596 }
597
598 effect_list_iterate(plist, peffect) {
599 if (0 != get_potential_improvement_bonus(pimprove, pcity,
600 peffect->type, RPT_CERTAIN, TRUE)) {
601 return TRUE;
602 }
604
605 return FALSE;
606}
607
608/**********************************************************************/
615bool is_improvement_productive(const struct city *pcity,
616 const struct impr_type *pimprove)
617{
618 return (!improvement_obsolete(city_owner(pcity), pimprove, pcity)
619 && (improvement_has_flag(pimprove, IF_GOLD)
620 || improvement_has_side_effects(pcity, pimprove)
621 || improvement_has_effects(pcity, pimprove)));
622}
623
624/**********************************************************************/
636bool is_improvement_redundant(const struct city *pcity,
637 const struct impr_type *pimprove)
638{
639 /* A capitalization production is never redundant. */
640 if (improvement_has_flag(pimprove, IF_GOLD)) {
641 return FALSE;
642 }
643
644 /* If an improvement has side effects, don't claim it's redundant. */
645 if (improvement_has_side_effects(pcity, pimprove)) {
646 return FALSE;
647 }
648
649 /* Otherwise, it's redundant if its effects are available by other means,
650 * or if it's an obsolete wonder (great or small). */
651 return is_building_replaced(pcity, pimprove, RPT_CERTAIN)
652 || improvement_obsolete(city_owner(pcity), pimprove, pcity);
653}
654
655/**********************************************************************/
660 const struct impr_type *pimprove)
661{
662 const struct req_context context = { .player = p };
663
664 bool space_part = FALSE;
665
666 if (!valid_improvement(pimprove)) {
667 return FALSE;
668 }
669
670 requirement_vector_iterate(&pimprove->reqs, preq) {
671 if (preq->range >= REQ_RANGE_PLAYER
672 && !is_req_active(&context, NULL, preq, RPT_CERTAIN)) {
673 return FALSE;
674 }
676
677 /* Check for space part construction. This assumes that space parts have
678 * no other effects. */
679 if (building_has_effect(pimprove, EFT_SS_STRUCTURAL)) {
680 space_part = TRUE;
682 return FALSE;
683 }
684 }
685 if (building_has_effect(pimprove, EFT_SS_COMPONENT)) {
686 space_part = TRUE;
688 return FALSE;
689 }
690 }
691 if (building_has_effect(pimprove, EFT_SS_MODULE)) {
692 space_part = TRUE;
693 if (p->spaceship.modules >= NUM_SS_MODULES) {
694 return FALSE;
695 }
696 }
697 if (space_part
698 && (get_player_bonus(p, EFT_ENABLE_SPACE) <= 0
699 || p->spaceship.state >= SSHIP_LAUNCHED)) {
700 return FALSE;
701 }
702
703 if (is_great_wonder(pimprove)) {
704 /* Can't build wonder if already built */
705 if (!great_wonder_is_available(pimprove)) {
706 return FALSE;
707 }
708 }
709
710 return TRUE;
711}
712
713/**********************************************************************/
718 struct impr_type *pimprove)
719{
720 if (!can_player_build_improvement_direct(p, pimprove)) {
721 return FALSE;
722 }
723 if (improvement_obsolete(p, pimprove, NULL)) {
724 return FALSE;
725 }
726 return TRUE;
727}
728
729/**********************************************************************/
735 const struct impr_type *pimprove)
736{
737 const struct req_context context = { .player = p };
738
739 if (!valid_improvement(pimprove)) {
740 return FALSE;
741 }
742 if (improvement_obsolete(p, pimprove, NULL)) {
743 return FALSE;
744 }
745 if (is_great_wonder(pimprove) && !great_wonder_is_available(pimprove)) {
746 /* Can't build wonder if already built */
747 return FALSE;
748 }
749
750 /* Check for requirements that aren't met and that are unchanging (so
751 * they can never be met). */
752 requirement_vector_iterate(&pimprove->reqs, preq) {
753 if (preq->range >= REQ_RANGE_PLAYER
754 && is_req_preventing(&context, NULL, preq, RPT_POSSIBLE)) {
755 return FALSE;
756 }
758 /* FIXME: should check some "unchanging" reqs here - like if there's
759 * a nation requirement, we can go ahead and check it now. */
760
761 return TRUE;
762}
763
764/**********************************************************************/
767bool is_great_wonder(const struct impr_type *pimprove)
768{
769 return (pimprove->genus == IG_GREAT_WONDER);
770}
771
772/**********************************************************************/
775bool is_small_wonder(const struct impr_type *pimprove)
776{
777 return (pimprove->genus == IG_SMALL_WONDER);
778}
779
780/**********************************************************************/
783bool is_improvement(const struct impr_type *pimprove)
784{
785 return (pimprove->genus == IG_IMPROVEMENT);
786}
787
788/**********************************************************************/
792bool is_special_improvement(const struct impr_type *pimprove)
793{
794 return pimprove->genus == IG_SPECIAL;
795}
796
797/**********************************************************************/
800void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
801{
802 struct player *pplayer;
803 int windex = improvement_number(pimprove);
804
805 fc_assert_ret(NULL != pcity);
806 fc_assert_ret(is_wonder(pimprove));
807
808 pplayer = city_owner(pcity);
809 pplayer->wonders[windex] = pcity->id;
810
811 if (is_great_wonder(pimprove)) {
812 game.info.great_wonder_owners[windex] = player_number(pplayer);
813 }
814}
815
816/**********************************************************************/
820void wonder_destroyed(const struct city *pcity,
821 const struct impr_type *pimprove)
822{
823 struct player *pplayer;
824 int windex = improvement_number(pimprove);
825
826 fc_assert_ret(NULL != pcity);
827 fc_assert_ret(is_wonder(pimprove));
828
829 pplayer = city_owner(pcity);
830 fc_assert_ret(pplayer->wonders[windex] == pcity->id);
831 pplayer->wonders[windex] = WONDER_LOST;
832
833 if (is_great_wonder(pimprove)) {
835 == player_number(pplayer));
837 }
838}
839
840/**********************************************************************/
844bool wonder_is_lost(const struct player *pplayer,
845 const struct impr_type *pimprove)
846{
847 fc_assert_ret_val(NULL != pplayer, FALSE);
849
850 return pplayer->wonders[improvement_index(pimprove)] == WONDER_LOST;
851}
852
853/**********************************************************************/
857bool wonder_is_built(const struct player *pplayer,
858 const struct impr_type *pimprove)
859{
860 fc_assert_ret_val(NULL != pplayer, FALSE);
862
863 return WONDER_BUILT(pplayer->wonders[improvement_index(pimprove)]);
864}
865
866/**********************************************************************/
872struct city *city_from_wonder(const struct player *pplayer,
873 const struct impr_type *pimprove)
874{
875 int idx = improvement_index(pimprove);
876 int city_id;
877
878 if (idx < 0) {
879 return NULL;
880 }
881
882 city_id = pplayer->wonders[idx];
883
884 fc_assert_ret_val(NULL != pplayer, NULL);
885 fc_assert_ret_val(is_wonder(pimprove), NULL);
886
887 if (!WONDER_BUILT(city_id)) {
888 return NULL;
889 }
890
891#ifdef FREECIV_DEBUG
892 if (is_server()) {
893 /* On client side, this info is not always known. */
894 struct city *pcity = player_city_by_number(pplayer, city_id);
895
896 if (NULL == pcity) {
897 log_error("Player %s (nb %d) has outdated wonder info for "
898 "%s (nb %d), it points to city nb %d.",
899 player_name(pplayer), player_number(pplayer),
900 improvement_rule_name(pimprove),
901 improvement_number(pimprove), city_id);
902 } else if (!city_has_building(pcity, pimprove)) {
903 log_error("Player %s (nb %d) has outdated wonder info for "
904 "%s (nb %d), the city %s (nb %d) doesn't have this wonder.",
905 player_name(pplayer), player_number(pplayer),
906 improvement_rule_name(pimprove),
907 improvement_number(pimprove), city_name_get(pcity), pcity->id);
908 return NULL;
909 }
910
911 return pcity;
912 }
913#endif /* FREECIV_DEBUG */
914
915 return player_city_by_number(pplayer, city_id);
916}
917
918/**********************************************************************/
921bool wonder_visible_to_player(const struct impr_type *wonder,
922 const struct player *pplayer,
923 const struct player *owner)
924{
925 if (pplayer == owner) {
926 /* Can see all own wonders,
927 * even improvements if that matters. */
928 return TRUE;
929 }
930
931 if (is_great_wonder(wonder)) {
932 return TRUE;
933 }
934
935 if (is_small_wonder(wonder)) {
937 case WV_ALWAYS:
938 return TRUE;
939 case WV_NEVER:
940 return FALSE;
941 }
942
944
945 return FALSE;
946 }
947
948 /* Now a wonder, but regular improvement */
949 return FALSE;
950}
951
952/**********************************************************************/
955bool great_wonder_is_built(const struct impr_type *pimprove)
956{
958
960 [improvement_index(pimprove)]);
961}
962
963/**********************************************************************/
966bool great_wonder_is_destroyed(const struct impr_type *pimprove)
967{
969
970 return (WONDER_DESTROYED
972}
973
974/**********************************************************************/
977bool great_wonder_is_available(const struct impr_type *pimprove)
978{
980
981 return (WONDER_NOT_OWNED
983}
984
985/**********************************************************************/
989struct city *city_from_great_wonder(const struct impr_type *pimprove)
990{
991 int player_id = game.info.great_wonder_owners[improvement_index(pimprove)];
992
993 fc_assert_ret_val(is_great_wonder(pimprove), NULL);
994
995 if (WONDER_OWNED(player_id)) {
996#ifdef FREECIV_DEBUG
997 const struct player *pplayer = player_by_number(player_id);
998 struct city *pcity = city_from_wonder(pplayer, pimprove);
999
1000 if (is_server() && NULL == pcity) {
1001 log_error("Game has outdated wonder info for %s (nb %d), "
1002 "the player %s (nb %d) doesn't have this wonder.",
1003 improvement_rule_name(pimprove),
1004 improvement_number(pimprove),
1005 player_name(pplayer), player_number(pplayer));
1006 }
1007
1008 return pcity;
1009#else
1010 return city_from_wonder(player_by_number(player_id), pimprove);
1011#endif /* FREECIV_DEBUG */
1012 } else {
1013 return NULL;
1014 }
1015}
1016
1017/**********************************************************************/
1021struct player *great_wonder_owner(const struct impr_type *pimprove)
1022{
1023 int player_id = game.info.great_wonder_owners[improvement_index(pimprove)];
1024
1025 fc_assert_ret_val(is_great_wonder(pimprove), NULL);
1026
1027 if (WONDER_OWNED(player_id)) {
1028 return player_by_number(player_id);
1029 } else {
1030 return NULL;
1031 }
1032}
1033
1034/**********************************************************************/
1037bool small_wonder_is_built(const struct player *pplayer,
1038 const struct impr_type *pimprove)
1039{
1041
1042 return (NULL != pplayer
1043 && wonder_is_built(pplayer, pimprove));
1044}
1045
1046/**********************************************************************/
1049struct city *city_from_small_wonder(const struct player *pplayer,
1050 const struct impr_type *pimprove)
1051{
1052 fc_assert_ret_val(is_small_wonder(pimprove), NULL);
1053
1054 if (NULL == pplayer) {
1055 return NULL; /* Used in some places in the client. */
1056 } else {
1057 return city_from_wonder(pplayer, pimprove);
1058 }
1059}
1060
1061/**********************************************************************/
1064bool can_sell_building(const struct impr_type *pimprove)
1065{
1066 return (valid_improvement(pimprove) && is_improvement(pimprove));
1067}
1068
1069/**********************************************************************/
1072bool can_city_sell_building(const struct city *pcity,
1073 const struct impr_type *pimprove)
1074{
1075 return (city_has_building(pcity, pimprove) && is_improvement(pimprove));
1076}
1077
1078/**********************************************************************/
1084 struct city *pcity,
1085 const struct impr_type *pimprove)
1086{
1087 /* Check if player can sell anything from this city */
1088 if (pcity->owner != pplayer) {
1089 return TR_OTHER_FAILURE;
1090 }
1091
1092 if (pcity->did_sell) {
1093 return TR_ALREADY_SOLD;
1094 }
1095
1096 /* Check if particular building can be solt */
1097 if (pimprove != NULL
1098 && !can_city_sell_building(pcity, pimprove)) {
1099 return TR_OTHER_FAILURE;
1100 }
1101
1102 return TR_SUCCESS;
1103}
1104
1105/**********************************************************************/
1109const struct impr_type *improvement_replacement(const struct impr_type *pimprove)
1110{
1111 requirement_vector_iterate(&pimprove->obsolete_by, pobs) {
1112 if (pobs->source.kind == VUT_IMPROVEMENT && pobs->present) {
1113 return pobs->source.value.building;
1114 }
1116
1117 return NULL;
1118}
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:7146
#define action_enablers_iterate_end
Definition actions.h:526
#define action_id_get_actor_kind(act_id)
Definition actions.h:651
#define action_enablers_iterate(_enabler_)
Definition actions.h:520
#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:1212
const char * city_name_get(const struct city *pcity)
Definition city.c:1111
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:132
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:928
#define city_tile(_pcity_)
Definition city.h:544
#define city_owner(_pcity_)
Definition city.h:543
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:222
#define city_tile_iterate_end
Definition city.h:230
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2839
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:73
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
struct effect_list * get_req_source_effects(struct universal *psource)
Definition effects.c:146
bool is_building_replaced(const struct city *pcity, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Definition effects.c:641
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:691
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:1126
int get_building_bonus(const struct city *pcity, const struct impr_type *building, enum effect_type effect_type)
Definition effects.c:930
bool building_has_effect(const struct impr_type *pimprove, enum effect_type effect_type)
Definition effects.c:587
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:771
#define effect_list_iterate_end
Definition effects.h:375
#define effect_list_iterate(effect_list, peffect)
Definition effects.h:373
bool player_can_build_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:442
#define extra_type_iterate(_p)
Definition extras.h:291
#define extra_type_iterate_end
Definition extras.h:297
static bool is_server(void)
int Impr_type_id
Definition fc_types.h:346
@ RPT_CERTAIN
Definition fc_types.h:586
@ RPT_POSSIBLE
Definition fc_types.h:585
test_result
Definition fc_types.h:1097
@ TR_ALREADY_SOLD
Definition fc_types.h:1100
@ TR_OTHER_FAILURE
Definition fc_types.h:1099
@ TR_SUCCESS
Definition fc_types.h:1098
@ VC_SPACERACE
Definition fc_types.h:1123
#define Qn_(String)
Definition fcintl.h:89
struct civ_game game
Definition game.c:57
struct world wld
Definition game.c:58
struct city * owner
Definition citydlg.c:219
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:46
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)
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 * 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:66
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:90
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)
static struct impr_type improvement_types[B_LAST]
Definition improvement.c:41
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)
bool wonder_visible_to_player(const struct impr_type *wonder, const struct player *pplayer, const struct player *owner)
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:80
bool is_improvement_productive(const struct city *pcity, const struct impr_type *pimprove)
#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
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:840
int player_number(const struct player *pplayer)
Definition player.c:828
const char * player_name(const struct player *pplayer)
Definition player.c:886
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1179
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_)
#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:309
bool did_sell
Definition city.h:367
int id
Definition city.h:315
struct player * owner
Definition city.h:312
struct tile * tile
Definition city.h:311
struct packet_ruleset_control control
Definition game.h:83
struct packet_game_info info
Definition game.h:89
bool allows_actions
Definition improvement.h:91
int build_cost
Definition improvement.h:77
enum impr_genus_id genus
Definition improvement.h:80
bool ruledit_disabled
Definition improvement.h:71
bool protects_vs_actions
Definition improvement.h:90
struct requirement_vector obsolete_by
Definition improvement.h:76
Impr_type_id item_number
Definition improvement.h:69
bool prevents_disaster
Definition improvement.h:89
struct requirement_vector reqs
Definition improvement.h:75
bool allows_extras
Definition improvement.h:88
struct strvec * helptext
Definition improvement.h:82
bool allows_units
Definition improvement.h:87
struct name_translation name
Definition improvement.h:70
bv_impr_flags flags
Definition improvement.h:81
void * ruledit_dlg
Definition improvement.h:72
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:301
struct player_spaceship spaceship
Definition player.h:286
const struct player * player
Definition tile.h:49
enum universals_n kind
Definition fc_types.h:758
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:1993
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:443
#define unit_type_iterate(_p)
Definition unittype.h:838
#define unit_type_iterate_end
Definition unittype.h:845
bool victory_enabled(enum victory_condition_type victory)
Definition victory.c:26