Freeciv21
Develop your civilization from humble roots to a global empire
improvement.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 // utility
15 #include "fcintl.h"
16 #include "log.h"
17 #include "shared.h" // ARRAY_SIZE
18 #include "support.h"
19 
20 // common
21 #include "game.h"
22 #include "victory.h"
23 
24 #include "improvement.h"
25 
33 static struct impr_type improvement_types[B_LAST];
34 
39 {
40  int i;
41 
42  /* Can't use improvement_iterate() or improvement_by_number() here
43  * because num_impr_types isn't known yet. */
44  for (i = 0; i < ARRAY_SIZE(improvement_types); i++) {
45  struct impr_type *p = &improvement_types[i];
46 
47  p->item_number = i;
48  requirement_vector_init(&p->reqs);
49  requirement_vector_init(&p->obsolete_by);
50  p->ruledit_disabled = false;
51  }
52 }
53 
57 static void improvement_free(struct impr_type *p)
58 {
59  delete p->helptext;
60  p->helptext = nullptr;
61  requirement_vector_free(&p->reqs);
62  requirement_vector_free(&p->obsolete_by);
63 }
64 
69 {
72 }
73 
78 {
79  improvement_iterate(pimprove)
80  {
81  pimprove->allows_units = false;
82  unit_type_iterate(putype)
83  {
84  if (requirement_needs_improvement(pimprove, &putype->build_reqs)) {
85  pimprove->allows_units = true;
86  break;
87  }
88  }
90 
91  pimprove->allows_extras = false;
92  extra_type_iterate(pextra)
93  {
94  if (requirement_needs_improvement(pimprove, &pextra->reqs)) {
95  pimprove->allows_extras = true;
96  break;
97  }
98  }
100 
101  pimprove->prevents_disaster = false;
103  {
104  if (!requirement_fulfilled_by_improvement(pimprove, &pdis->reqs)) {
105  pimprove->prevents_disaster = true;
106  break;
107  }
108  }
110 
111  pimprove->protects_vs_actions = false;
113  {
115  &act->target_reqs)) {
116  pimprove->protects_vs_actions = true;
117  break;
118  }
119  }
121  }
123 }
124 
129 {
130  if (game.control.num_impr_types > 0) {
131  return improvement_types;
132  }
133  return nullptr;
134 }
135 
140 {
141  if (game.control.num_impr_types > 0) {
142  return &improvement_types[game.control.num_impr_types - 1];
143  }
144  return nullptr;
145 }
146 
150 Impr_type_id improvement_count() { return game.control.num_impr_types; }
151 
158 Impr_type_id improvement_index(const struct impr_type *pimprove)
159 {
160  fc_assert_ret_val(nullptr != pimprove, 0);
161  return pimprove - improvement_types;
162 }
163 
168 {
169  fc_assert_ret_val(nullptr != pimprove, 0);
170  return pimprove->item_number;
171 }
172 
178 {
179  if (id < 0 || id >= improvement_count()) {
180  return nullptr;
181  }
182  return &improvement_types[id];
183 }
184 
194 const struct impr_type *valid_improvement(const struct impr_type *pimprove)
195 {
196  if (nullptr == pimprove) {
197  return nullptr;
198  }
199 
201  && (building_has_effect(pimprove, EFT_SS_STRUCTURAL)
202  || building_has_effect(pimprove, EFT_SS_COMPONENT)
203  || building_has_effect(pimprove, EFT_SS_MODULE))) {
204  // This assumes that space parts don't have any other effects.
205  return nullptr;
206  }
207 
208  return pimprove;
209 }
210 
215 const char *improvement_name_translation(const struct impr_type *pimprove)
216 {
217  return name_translation_get(&pimprove->name);
218 }
219 
224 const char *improvement_rule_name(const struct impr_type *pimprove)
225 {
226  return rule_name_get(&pimprove->name);
227 }
228 
233 int impr_base_build_shield_cost(const struct impr_type *pimprove)
234 {
235  int base = pimprove->build_cost;
236 
237  return MAX(base * game.info.shieldbox / 100, 1);
238 }
239 
245 int impr_estimate_build_shield_cost(const struct player *pplayer,
246  const struct tile *ptile,
247  const struct impr_type *pimprove)
248 {
249  int base = pimprove->build_cost
250  * (100
251  + get_target_bonus_effects(nullptr, pplayer, nullptr,
252  nullptr, pimprove, ptile, nullptr,
253  nullptr, nullptr, nullptr,
254  nullptr, EFT_IMPR_BUILD_COST_PCT))
255  / 100;
256 
257  return MAX(base * game.info.shieldbox / 100, 1);
258 }
259 
263 int impr_build_shield_cost(const struct city *pcity,
264  const struct impr_type *pimprove)
265 {
266  int base =
267  pimprove->build_cost
268  * (100 + get_building_bonus(pcity, pimprove, EFT_IMPR_BUILD_COST_PCT))
269  / 100;
270 
271  return MAX(base * game.info.shieldbox / 100, 1);
272 }
273 
277 int impr_buy_gold_cost(const struct city *pcity,
278  const struct impr_type *pimprove,
279  int shields_in_stock)
280 {
281  int cost = 0;
282  const int missing =
283  impr_build_shield_cost(pcity, pimprove) - shields_in_stock;
284 
285  if (improvement_has_flag(pimprove, IF_GOLD)) {
286  // Can't buy capitalization.
287  return 0;
288  }
289 
290  if (missing > 0) {
291  cost = 2 * missing;
292  }
293 
294  if (shields_in_stock == 0) {
295  cost *= 2;
296  }
297 
298  cost = cost
299  * (100 + get_building_bonus(pcity, pimprove, EFT_IMPR_BUY_COST_PCT))
300  / 100;
301 
302  return cost;
303 }
304 
308 int impr_sell_gold(const struct impr_type *pimprove)
309 {
310  return MAX(pimprove->build_cost * game.info.shieldbox / 100, 1);
311 }
312 
317 bool is_wonder(const struct impr_type *pimprove)
318 {
319  return (is_great_wonder(pimprove) || is_small_wonder(pimprove));
320 }
321 
327 {
328  improvement_iterate(pimprove)
329  {
330  if (0 == strcmp(improvement_name_translation(pimprove), name)) {
331  return pimprove;
332  }
333  }
335 
336  return nullptr;
337 }
338 
344 {
345  const char *qname = Qn_(name);
346 
347  improvement_iterate(pimprove)
348  {
349  if (0 == fc_strcasecmp(improvement_rule_name(pimprove), qname)) {
350  return pimprove;
351  }
352  }
354 
355  return nullptr;
356 }
357 
361 bool improvement_has_flag(const struct impr_type *pimprove,
362  enum impr_flag_id flag)
363 {
364  fc_assert_ret_val(impr_flag_id_is_valid(flag), false);
365  return BV_ISSET(pimprove->flags, flag);
366 }
367 
371 bool is_improvement_visible(const struct impr_type *pimprove)
372 {
373  return (is_wonder(pimprove)
374  || improvement_has_flag(pimprove, IF_VISIBLE_BY_OTHERS));
375 }
376 
381 bool can_improvement_go_obsolete(const struct impr_type *pimprove)
382 {
383  return requirement_vector_size(&pimprove->obsolete_by) > 0;
384 }
385 
389 bool improvement_obsolete(const struct player *pplayer,
390  const struct impr_type *pimprove,
391  const struct city *pcity)
392 {
393  struct tile *ptile = nullptr;
394 
395  if (pcity != nullptr) {
396  ptile = city_tile(pcity);
397  }
398 
399  requirement_vector_iterate(&pimprove->obsolete_by, preq)
400  {
401  if (is_req_active(pplayer, nullptr, pcity, pimprove, ptile, nullptr,
402  nullptr, nullptr, nullptr, nullptr, preq,
403  RPT_CERTAIN)) {
404  return true;
405  }
406  }
408 
409  return false;
410 }
411 
415 static bool impr_provides_buildable_units(const struct city *pcity,
416  const struct impr_type *pimprove)
417 {
418  // Fast check
419  if (!pimprove->allows_units) {
420  return false;
421  }
422 
424  {
425  if (requirement_needs_improvement(pimprove, &ut->build_reqs)
426  && can_city_build_unit_now(pcity, ut)) {
427  return true;
428  }
429  }
431 
432  return false;
433 }
434 
438 static bool impr_provides_buildable_extras(const struct city *pcity,
439  const struct impr_type *pimprove)
440 {
441  // Fast check
442  if (!pimprove->allows_extras) {
443  return false;
444  }
445 
446  extra_type_iterate(pextra)
447  {
448  if (requirement_needs_improvement(pimprove, &pextra->reqs)) {
450  ptile)
451  {
452  if (player_can_build_extra(pextra, city_owner(pcity), ptile)) {
453  return true;
454  }
455  }
457  }
458  }
460 
461  return false;
462 }
463 
467 static bool impr_prevents_disaster(const struct city *pcity,
468  const struct impr_type *pimprove)
469 {
470  // Fast check
471  if (!pimprove->prevents_disaster) {
472  return false;
473  }
474 
476  {
477  if (!requirement_fulfilled_by_improvement(pimprove, &pdis->reqs)
478  && !can_disaster_happen(pdis, pcity)) {
479  return true;
480  }
481  }
483 
484  return false;
485 }
486 
493 static bool impr_protects_vs_actions(const struct city *pcity,
494  const struct impr_type *pimprove)
495 {
496  // Fast check
497  if (!pimprove->protects_vs_actions) {
498  return false;
499  }
500 
502  {
503  if (!requirement_fulfilled_by_improvement(pimprove, &act->target_reqs)
504  && !is_action_possible_on_city(act->action, nullptr, pcity)) {
505  return true;
506  }
507  }
509 
510  return false;
511 }
512 
523 static bool improvement_has_side_effects(const struct city *pcity,
524  const struct impr_type *pimprove)
525 {
526  /* FIXME: There should probably also be a test as to whether
527  * the improvement *enables* an action (somewhere else),
528  * but this is hard to determine at city scope. */
529 
530  return (impr_provides_buildable_units(pcity, pimprove)
531  || impr_provides_buildable_extras(pcity, pimprove)
532  || impr_prevents_disaster(pcity, pimprove)
533  || impr_protects_vs_actions(pcity, pimprove));
534 }
535 
539 static bool improvement_has_effects(const struct city *pcity,
540  const struct impr_type *pimprove)
541 {
542  struct universal source = {.value = {.building = pimprove},
543  .kind = VUT_IMPROVEMENT};
544  struct effect_list *plist = get_req_source_effects(&source);
545 
546  if (!plist || improvement_obsolete(city_owner(pcity), pimprove, pcity)) {
547  return false;
548  }
549 
550  effect_list_iterate(plist, peffect)
551  {
552  if (0
553  != get_potential_improvement_bonus(pimprove, pcity, peffect->type,
554  RPT_CERTAIN)) {
555  return true;
556  }
557  }
559 
560  return false;
561 }
562 
570 bool is_improvement_productive(const struct city *pcity,
571  const struct impr_type *pimprove)
572 {
573  return (!improvement_obsolete(city_owner(pcity), pimprove, pcity)
574  && (improvement_has_flag(pimprove, IF_GOLD)
575  || improvement_has_side_effects(pcity, pimprove)
576  || improvement_has_effects(pcity, pimprove)));
577 }
578 
591 bool is_improvement_redundant(const struct city *pcity,
592  const struct impr_type *pimprove)
593 {
594  // A capitalization production is never redundant.
595  if (improvement_has_flag(pimprove, IF_GOLD)) {
596  return false;
597  }
598 
599  // If an improvement has side effects, don't claim it's redundant.
600  if (improvement_has_side_effects(pcity, pimprove)) {
601  return false;
602  }
603 
604  /* Otherwise, it's redundant if its effects are available by other means,
605  * or if it's an obsolete wonder (great or small). */
606  return is_building_replaced(pcity, pimprove, RPT_CERTAIN)
607  || improvement_obsolete(city_owner(pcity), pimprove, pcity);
608 }
609 
615  const struct impr_type *pimprove)
616 {
617  bool space_part = false;
618 
619  if (!valid_improvement(pimprove)) {
620  return false;
621  }
622 
623  requirement_vector_iterate(&pimprove->reqs, preq)
624  {
625  if (preq->range >= REQ_RANGE_PLAYER
626  && !is_req_active(p, nullptr, nullptr, nullptr, nullptr, nullptr,
627  nullptr, nullptr, nullptr, nullptr, preq,
628  RPT_CERTAIN)) {
629  return false;
630  }
631  }
633 
634  /* Check for space part construction. This assumes that space parts have
635  * no other effects. */
636  if (building_has_effect(pimprove, EFT_SS_STRUCTURAL)) {
637  space_part = true;
639  return false;
640  }
641  }
642  if (building_has_effect(pimprove, EFT_SS_COMPONENT)) {
643  space_part = true;
645  return false;
646  }
647  }
648  if (building_has_effect(pimprove, EFT_SS_MODULE)) {
649  space_part = true;
650  if (p->spaceship.modules >= NUM_SS_MODULES) {
651  return false;
652  }
653  }
654  if (space_part
655  && (get_player_bonus(p, EFT_ENABLE_SPACE) <= 0
656  || p->spaceship.state >= SSHIP_LAUNCHED)) {
657  return false;
658  }
659 
660  if (is_great_wonder(pimprove)) {
661  // Can't build wonder if already built
662  if (!great_wonder_is_available(pimprove)) {
663  return false;
664  }
665  }
666 
667  return true;
668 }
669 
675  struct impr_type *pimprove)
676 {
677  if (!can_player_build_improvement_direct(p, pimprove)) {
678  return false;
679  }
680  if (improvement_obsolete(p, pimprove, nullptr)) {
681  return false;
682  }
683  return true;
684 }
685 
692  const struct impr_type *pimprove)
693 {
694  if (!valid_improvement(pimprove)) {
695  return false;
696  }
697  if (improvement_obsolete(p, pimprove, nullptr)) {
698  return false;
699  }
700  if (is_great_wonder(pimprove) && !great_wonder_is_available(pimprove)) {
701  // Can't build wonder if already built
702  return false;
703  }
704 
705  /* Check for requirements that aren't met and that are unchanging (so
706  * they can never be met). */
707  requirement_vector_iterate(&pimprove->reqs, preq)
708  {
709  if (preq->range >= REQ_RANGE_PLAYER && is_req_unchanging(preq)
710  && !is_req_active(p, nullptr, nullptr, nullptr, nullptr, nullptr,
711  nullptr, nullptr, nullptr, nullptr, preq,
712  RPT_POSSIBLE)) {
713  return false;
714  }
715  }
717  /* FIXME: should check some "unchanging" reqs here - like if there's
718  * a nation requirement, we can go ahead and check it now. */
719 
720  return true;
721 }
722 
726 bool is_great_wonder(const struct impr_type *pimprove)
727 {
728  return (pimprove->genus == IG_GREAT_WONDER);
729 }
730 
734 bool is_small_wonder(const struct impr_type *pimprove)
735 {
736  return (pimprove->genus == IG_SMALL_WONDER);
737 }
738 
742 bool is_improvement(const struct impr_type *pimprove)
743 {
744  return (pimprove->genus == IG_IMPROVEMENT);
745 }
746 
751 bool is_special_improvement(const struct impr_type *pimprove)
752 {
753  return pimprove->genus == IG_SPECIAL;
754 }
755 
759 void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
760 {
761  struct player *pplayer;
762  int windex = improvement_number(pimprove);
763 
764  fc_assert_ret(nullptr != pcity);
765  fc_assert_ret(is_wonder(pimprove));
766 
767  pplayer = city_owner(pcity);
768  pplayer->wonders[windex] = pcity->id;
769 
770  /* Build turn is set with wonder_set_build_turn() only when
771  * actually building it in-game. But this is called also when
772  * loading savegames etc., so initialize to something known. */
773  pplayer->wonder_build_turn[windex] = -1;
774 
775  if (is_great_wonder(pimprove)) {
776  game.info.great_wonder_owners[windex] = player_number(pplayer);
777  }
778 }
779 
784 void wonder_destroyed(const struct city *pcity,
785  const struct impr_type *pimprove)
786 {
787  struct player *pplayer;
788  int windex = improvement_number(pimprove);
789 
790  fc_assert_ret(nullptr != pcity);
791  fc_assert_ret(is_wonder(pimprove));
792 
793  pplayer = city_owner(pcity);
794  fc_assert_ret(pplayer->wonders[windex] == pcity->id);
795  pplayer->wonders[windex] = WONDER_LOST;
796 
797  if (is_great_wonder(pimprove)) {
798  fc_assert_ret(game.info.great_wonder_owners[windex]
799  == player_number(pplayer));
800  game.info.great_wonder_owners[windex] = WONDER_DESTROYED;
801  }
802 }
803 
808 bool wonder_is_lost(const struct player *pplayer,
809  const struct impr_type *pimprove)
810 {
811  fc_assert_ret_val(nullptr != pplayer, false);
812  fc_assert_ret_val(is_wonder(pimprove), false);
813 
814  return pplayer->wonders[improvement_index(pimprove)] == WONDER_LOST;
815 }
816 
821 bool wonder_is_built(const struct player *pplayer,
822  const struct impr_type *pimprove)
823 {
824  int windex = improvement_index(pimprove);
825 
826  fc_assert_ret_val(nullptr != pplayer, false);
827  fc_assert_ret_val(is_wonder(pimprove), false);
828 
829  /* New city turn: Wonders don't take effect until the next
830  * turn after building */
831 
832  if (!WONDER_BUILT(pplayer->wonders[windex])) {
833  return false;
834  }
835 
836  return (pplayer->wonder_build_turn[windex] != game.info.turn);
837 }
838 
845 struct city *city_from_wonder(const struct player *pplayer,
846  const struct impr_type *pimprove)
847 {
848  int city_id = pplayer->wonders[improvement_index(pimprove)];
849 
850  fc_assert_ret_val(nullptr != pplayer, nullptr);
851  fc_assert_ret_val(is_wonder(pimprove), nullptr);
852 
853  if (!WONDER_BUILT(city_id)) {
854  return nullptr;
855  }
856 
857 #ifdef FREECIV_DEBUG
858  if (is_server()) {
859  // On client side, this info is not always known.
860  struct city *pcity = player_city_by_number(pplayer, city_id);
861 
862  if (nullptr == pcity) {
863  qCritical("Player %s (nb %d) has outdated wonder info for "
864  "%s (nb %d), it points to city nb %d.",
865  player_name(pplayer), player_number(pplayer),
866  improvement_rule_name(pimprove),
867  improvement_number(pimprove), city_id);
868  } else if (!city_has_building(pcity, pimprove)) {
869  qCritical("Player %s (nb %d) has outdated wonder info for "
870  "%s (nb %d), the city %s (nb %d) doesn't have this wonder.",
871  player_name(pplayer), player_number(pplayer),
872  improvement_rule_name(pimprove),
873  improvement_number(pimprove), city_name_get(pcity),
874  pcity->id);
875  return nullptr;
876  }
877 
878  return pcity;
879  }
880 #endif // FREECIV_DEBUG
881 
882  return player_city_by_number(pplayer, city_id);
883 }
884 
888 bool great_wonder_is_built(const struct impr_type *pimprove)
889 {
890  int windex = improvement_index(pimprove);
891  int owner;
892  fc_assert_ret_val(is_great_wonder(pimprove), false);
893 
894  owner = game.info.great_wonder_owners[windex];
895  /* call wonder_is_built() to check the build turn */
896  return (WONDER_OWNED(owner)
897  && wonder_is_built(player_by_number(owner), pimprove));
898 }
899 
903 bool great_wonder_is_destroyed(const struct impr_type *pimprove)
904 {
905  fc_assert_ret_val(is_great_wonder(pimprove), false);
906 
907  return (WONDER_DESTROYED
908  == game.info.great_wonder_owners[improvement_index(pimprove)]);
909 }
910 
914 bool great_wonder_is_available(const struct impr_type *pimprove)
915 {
916  fc_assert_ret_val(is_great_wonder(pimprove), false);
917 
918  return (WONDER_NOT_OWNED
919  == game.info.great_wonder_owners[improvement_index(pimprove)]);
920 }
921 
926 struct city *city_from_great_wonder(const struct impr_type *pimprove)
927 {
928  int player_id = game.info.great_wonder_owners[improvement_index(pimprove)];
929 
930  fc_assert_ret_val(is_great_wonder(pimprove), nullptr);
931 
932  if (WONDER_OWNED(player_id)) {
933 #ifdef FREECIV_DEBUG
934  const struct player *pplayer = player_by_number(player_id);
935  struct city *pcity = city_from_wonder(pplayer, pimprove);
936 
937  if (is_server() && nullptr == pcity) {
938  qCritical("Game has outdated wonder info for %s (nb %d), "
939  "the player %s (nb %d) doesn't have this wonder.",
940  improvement_rule_name(pimprove),
941  improvement_number(pimprove), player_name(pplayer),
942  player_number(pplayer));
943  }
944 
945  return pcity;
946 #else
947  return city_from_wonder(player_by_number(player_id), pimprove);
948 #endif // FREECIV_DEBUG
949  } else {
950  return nullptr;
951  }
952 }
953 
958 struct player *great_wonder_owner(const struct impr_type *pimprove)
959 {
960  int player_id = game.info.great_wonder_owners[improvement_index(pimprove)];
961 
962  fc_assert_ret_val(is_great_wonder(pimprove), nullptr);
963 
964  if (WONDER_OWNED(player_id)) {
965  return player_by_number(player_id);
966  } else {
967  return nullptr;
968  }
969 }
970 
974 struct city *city_from_small_wonder(const struct player *pplayer,
975  const struct impr_type *pimprove)
976 {
977  fc_assert_ret_val(is_small_wonder(pimprove), nullptr);
978 
979  if (nullptr == pplayer) {
980  return nullptr; // Used in some places in the client.
981  } else {
982  return city_from_wonder(pplayer, pimprove);
983  }
984 }
985 
989 bool can_sell_building(const struct impr_type *pimprove)
990 {
991  return (valid_improvement(pimprove) && is_improvement(pimprove));
992 }
993 
997 bool can_city_sell_building(const struct city *pcity,
998  const struct impr_type *pimprove)
999 {
1000  return (city_has_building(pcity, pimprove) && is_improvement(pimprove));
1001 }
1002 
1008 enum test_result
1009 test_player_sell_building_now(struct player *pplayer, const city *pcity,
1010  const struct impr_type *pimprove)
1011 {
1012  // Check if player can sell anything from this city
1013  if (pcity->owner != pplayer) {
1014  return TR_OTHER_FAILURE;
1015  }
1016 
1017  if (pcity->did_sell) {
1018  return TR_ALREADY_SOLD;
1019  }
1020 
1021  // Check if particular building can be solt
1022  if (pimprove != nullptr && !can_city_sell_building(pcity, pimprove)) {
1023  return TR_OTHER_FAILURE;
1024  }
1025 
1026  return TR_SUCCESS;
1027 }
1028 
1033 const struct impr_type *
1034 improvement_replacement(const struct impr_type *pimprove)
1035 {
1036  requirement_vector_iterate(&pimprove->obsolete_by, pobs)
1037  {
1038  if (pobs->source.kind == VUT_IMPROVEMENT && pobs->present) {
1039  return pobs->source.value.building;
1040  }
1041  }
1043 
1044  return nullptr;
1045 }
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Returns TRUE if the wanted action can be done to the target city.
Definition: actions.cpp:5734
#define action_enablers_iterate_end
Definition: actions.h:425
#define action_enablers_iterate(_enabler_)
Definition: actions.h:417
bool BV_ISSET(const BV &bv, int bit)
Definition: bitvector.h:37
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Return TRUE iff the city has this building in it.
Definition: city.cpp:1189
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
Definition: city.cpp:1083
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
Definition: city.cpp:1095
const char * city_name_get(const struct city *pcity)
Return the name of the city.
Definition: city.cpp:1077
int city_map_radius_sq_get(const struct city *pcity)
Returns the current squared radius of the city.
Definition: city.cpp:130
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Return whether given city can build given unit; returns FALSE if unit is obsolete.
Definition: city.cpp:894
#define city_tile_iterate(_radius_sq, _city_tile, _tile)
Definition: city.h:202
#define city_tile_iterate_end
Definition: city.h:209
static void base(QVariant data1, QVariant data2)
Action "Build Base" for choice dialog.
Definition: dialogs.cpp:2393
bool can_disaster_happen(const struct disaster_type *pdis, const struct city *pcity)
Whether disaster can happen in given city.
Definition: disaster.cpp:108
#define disaster_type_iterate(_p)
Definition: disaster.h:70
#define disaster_type_iterate_end
Definition: disaster.h:76
int get_target_bonus_effects(struct effect_list *plist, const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, enum effect_type effect_type, enum vision_layer vision_layer, enum national_intelligence nintel)
Returns the effect bonus of a given type for any target.
Definition: effects.cpp:611
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)
Returns the effect bonus the improvement would or does provide if present.
Definition: effects.cpp:954
bool is_building_replaced(const struct city *pcity, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Returns TRUE if a building is replaced.
Definition: effects.cpp:566
struct effect_list * get_req_source_effects(struct universal *psource)
Get a list of effects with this requirement source.
Definition: effects.cpp:132
int get_building_bonus(const struct city *pcity, const struct impr_type *building, enum effect_type effect_type)
Returns the effect bonus at a building.
Definition: effects.cpp:819
bool building_has_effect(const struct impr_type *pimprove, enum effect_type effect_type)
Returns TRUE if the building has any effect bonuses of the given type.
Definition: effects.cpp:504
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Returns the effect bonus for a player.
Definition: effects.cpp:673
#define effect_list_iterate_end
Definition: effects.h:349
#define effect_list_iterate(effect_list, peffect)
Definition: effects.h:347
bool player_can_build_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Tells if player can build extra to tile with suitable unit.
Definition: extras.cpp:414
#define extra_type_iterate(_p)
Definition: extras.h:279
#define extra_type_iterate_end
Definition: extras.h:285
int Impr_type_id
Definition: fc_types.h:293
@ RPT_CERTAIN
Definition: fc_types.h:568
@ RPT_POSSIBLE
Definition: fc_types.h:567
test_result
Definition: fc_types.h:1063
@ TR_ALREADY_SOLD
Definition: fc_types.h:1063
@ TR_OTHER_FAILURE
Definition: fc_types.h:1063
@ TR_SUCCESS
Definition: fc_types.h:1063
@ VC_SPACERACE
Definition: fc_types.h:1083
#define Qn_(String)
Definition: fcintl.h:66
struct civ_game game
Definition: game.cpp:47
bool is_server()
Is program type server?
Definition: game.cpp:57
void improvements_free()
Frees the memory associated with all improvements.
Definition: improvement.cpp:68
bool can_sell_building(const struct impr_type *pimprove)
Return TRUE iff the improvement can be sold.
int impr_sell_gold(const struct impr_type *pimprove)
Returns the amount of gold received when this improvement is sold.
Impr_type_id improvement_count()
Return the number of improvements.
struct city * city_from_great_wonder(const struct impr_type *pimprove)
Get the world city with this great wonder.
bool can_city_sell_building(const struct city *pcity, const struct impr_type *pimprove)
Return TRUE iff the city can sell the given improvement.
bool can_player_build_improvement_direct(const struct player *p, const struct impr_type *pimprove)
Whether player can build given building somewhere, ignoring whether it is obsolete.
bool great_wonder_is_built(const struct impr_type *pimprove)
Returns whether this wonder is currently built.
static bool improvement_has_side_effects(const struct city *pcity, const struct impr_type *pimprove)
Check if an improvement has side effects for a city.
const char * improvement_rule_name(const struct impr_type *pimprove)
Return the (untranslated) rule name of the improvement.
struct impr_type * improvement_array_first()
Return the first item of improvements.
bool is_special_improvement(const struct impr_type *pimprove)
Returns TRUE if this is a "special" improvement.
static bool impr_prevents_disaster(const struct city *pcity, const struct impr_type *pimprove)
Returns TRUE iff improvement prevents a disaster in city.
struct impr_type * improvement_by_rule_name(const char *name)
Does a linear search of improvement_types[].name.vernacular Returns nullptr when none match.
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
Returns TRUE if an improvement in a city is redundant, that is, the city wouldn't lose anything by lo...
bool can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
Whether player can eventually build given building somewhere – i.e., returns TRUE if building is avai...
void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
Build a wonder in the city.
struct city * city_from_small_wonder(const struct player *pplayer, const struct impr_type *pimprove)
Get the player city with this small wonder.
void improvements_init()
Initialize building structures.
Definition: improvement.cpp:38
void improvement_feature_cache_init()
Cache features of the improvement.
Definition: improvement.cpp:77
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
Returns whether this wonder has been destroyed.
const struct impr_type * valid_improvement(const struct impr_type *pimprove)
Returns pointer when the improvement_type "exists" in this game, returns nullptr otherwise.
bool wonder_is_lost(const struct player *pplayer, const struct impr_type *pimprove)
Returns whether the player has lost this wonder after having owned it (small or great).
bool can_player_build_improvement_now(const struct player *p, struct impr_type *pimprove)
Whether player can build given building somewhere immediately.
bool is_improvement(const struct impr_type *pimprove)
Is this building a regular improvement?
struct impr_type * improvement_by_number(const Impr_type_id id)
Returns the improvement type for the given index/ID.
static bool improvement_has_effects(const struct city *pcity, const struct impr_type *pimprove)
Returns TRUE iff improvement provides some effect (good or bad).
bool wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove)
Returns whether the player is currently in possession of this wonder (small or great) and it hasn't b...
int impr_base_build_shield_cost(const struct impr_type *pimprove)
Returns the base number of shields it takes to build this improvement.
Impr_type_id improvement_number(const struct impr_type *pimprove)
Return the improvement index.
const struct impr_type * improvement_array_last()
Return the last item of improvements.
static bool impr_provides_buildable_extras(const struct city *pcity, const struct impr_type *pimprove)
Returns TRUE iff improvement provides extras buildable in city.
bool can_improvement_go_obsolete(const struct impr_type *pimprove)
Return TRUE if the improvement can ever go obsolete.
bool is_improvement_visible(const struct impr_type *pimprove)
Return TRUE if the improvement should be visible to others without spying.
Impr_type_id improvement_index(const struct impr_type *pimprove)
Return the improvement index.
int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove, int shields_in_stock)
Returns the amount of gold it takes to rush this improvement.
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
Returns the number of shields it takes to build this improvement.
struct impr_type * improvement_by_translated_name(const char *name)
Does a linear search of improvement_types[].name.translated Returns nullptr when none match.
static void improvement_free(struct impr_type *p)
Frees the memory associated with this improvement.
Definition: improvement.cpp:57
bool is_wonder(const struct impr_type *pimprove)
Returns whether improvement is some kind of wonder.
static bool impr_protects_vs_actions(const struct city *pcity, const struct impr_type *pimprove)
Returns TRUE iff improvement protects against an action on the city FIXME: This is prone to false pos...
bool is_great_wonder(const struct impr_type *pimprove)
Is this building a great wonder?
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
Returns TRUE if the improvement or wonder is obsolete.
struct player * great_wonder_owner(const struct impr_type *pimprove)
Get the player owning this small wonder.
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
Return TRUE if the impr has this flag otherwise FALSE.
void wonder_destroyed(const struct city *pcity, const struct impr_type *pimprove)
Remove a wonder from a city and destroy it if it's a great wonder.
const struct impr_type * improvement_replacement(const struct impr_type *pimprove)
Try to find a sensible replacement building, based on other buildings that may have caused this one t...
struct city * city_from_wonder(const struct player *pplayer, const struct impr_type *pimprove)
Get the world city with this wonder (small or great).
const char * improvement_name_translation(const struct impr_type *pimprove)
Return the (translated) name of the given improvement.
static struct impr_type improvement_types[B_LAST]
All the city improvements: Use improvement_by_number(id) to access the array.
Definition: improvement.cpp:33
static bool impr_provides_buildable_units(const struct city *pcity, const struct impr_type *pimprove)
Returns TRUE iff improvement provides units buildable in city.
bool is_small_wonder(const struct impr_type *pimprove)
Is this building a small wonder?
enum test_result test_player_sell_building_now(struct player *pplayer, const city *pcity, const struct impr_type *pimprove)
Return TRUE iff the player can sell the given improvement from city.
int impr_estimate_build_shield_cost(const struct player *pplayer, const struct tile *ptile, const struct impr_type *pimprove)
Returns estimate of the number of shields it takes to build this improvement.
bool great_wonder_is_available(const struct impr_type *pimprove)
Returns whether this wonder can be currently built.
bool is_improvement_productive(const struct city *pcity, const struct impr_type *pimprove)
Returns TRUE if an improvement in a city is productive, in some way.
#define WONDER_NOT_OWNED
Definition: improvement.h:138
#define WONDER_BUILT(city_id)
Definition: improvement.h:145
#define improvement_iterate_end
Definition: improvement.h:199
#define WONDER_DESTROYED
Definition: improvement.h:136
#define improvement_iterate(_p)
Definition: improvement.h:193
#define WONDER_LOST
Definition: improvement.h:143
#define B_LAST
Definition: improvement.h:33
#define WONDER_OWNED(player_id)
Definition: improvement.h:140
const char * name
Definition: inputfile.cpp:118
#define fc_assert_ret(condition)
Definition: log.h:112
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
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)
Return struct player pointer for the given player index.
Definition: player.cpp:768
int player_number(const struct player *pplayer)
Return the player index/number/id.
Definition: player.cpp:756
struct city * player_city_by_number(const struct player *pplayer, int city_id)
If the specified player owns the city with the specified id, return pointer to the city struct.
Definition: player.cpp:1113
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
Definition: player.cpp:816
bool is_req_active(const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, const struct requirement *req, const enum req_problem_type prob_type, const enum vision_layer vision_layer, const enum national_intelligence nintel)
Checks the requirement to see if it is active on the given target.
bool is_req_unchanging(const struct requirement *req)
Return TRUE if this is an "unchanging" requirement.
#define requirement_fulfilled_by_improvement(_imp_, _rqs_)
Definition: requirements.h:292
#define requirement_vector_iterate_end
Definition: requirements.h:80
#define requirement_vector_iterate(req_vec, preq)
Definition: requirements.h:78
#define requirement_needs_improvement(_imp_, _rqs_)
Definition: requirements.h:311
#define ARRAY_SIZE(x)
Definition: shared.h:79
#define MAX(x, y)
Definition: shared.h:48
#define NUM_SS_MODULES
Definition: spaceship.h:86
#define NUM_SS_COMPONENTS
Definition: spaceship.h:85
#define NUM_SS_STRUCTURALS
Definition: spaceship.h:84
@ SSHIP_LAUNCHED
Definition: spaceship.h:80
Definition: city.h:291
bool did_sell
Definition: city.h:352
int id
Definition: city.h:296
struct player * owner
Definition: city.h:294
struct packet_ruleset_control control
Definition: game.h:74
struct packet_game_info info
Definition: game.h:80
int build_cost
Definition: improvement.h:68
enum impr_genus_id genus
Definition: improvement.h:71
bool ruledit_disabled
Definition: improvement.h:62
bool protects_vs_actions
Definition: improvement.h:81
struct requirement_vector obsolete_by
Definition: improvement.h:67
Impr_type_id item_number
Definition: improvement.h:60
bool prevents_disaster
Definition: improvement.h:80
struct requirement_vector reqs
Definition: improvement.h:66
bool allows_extras
Definition: improvement.h:79
bool allows_units
Definition: improvement.h:78
struct name_translation name
Definition: improvement.h:61
bv_impr_flags flags
Definition: improvement.h:72
QVector< QString > * helptext
Definition: improvement.h:73
enum spaceship_state state
Definition: spaceship.h:105
Definition: player.h:231
int wonders[B_LAST]
Definition: player.h:283
int wonder_build_turn[B_LAST]
Definition: player.h:286
struct player_spaceship spaceship
Definition: player.h:268
Definition: tile.h:42
universals_u value
Definition: fc_types.h:739
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
Definition: support.cpp:89
const struct impr_type * building
Definition: fc_types.h:579
#define unit_type_iterate(_p)
Definition: unittype.h:785
#define unit_type_iterate_end
Definition: unittype.h:791
bool victory_enabled(enum victory_condition_type victory)
Whether victory condition is enabled.
Definition: victory.cpp:20