Freeciv21
Develop your civilization from humble roots to a global empire
sanitycheck.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 "bitvector.h"
16 #include "log.h"
17 
18 // common
19 #include "city.h"
20 #include "game.h"
21 #include "government.h"
22 #include "map.h"
23 #include "movement.h"
24 #include "nation.h"
25 #include "player.h"
26 #include "research.h"
27 #include "specialist.h"
28 #include "terrain.h"
29 #include "unit.h"
30 #include "unitlist.h"
31 
32 // server
33 #include "cityturn.h" // city_repair_size()
34 #include "maphand.h"
35 #include "plrhand.h"
36 #include "srv_main.h"
37 #include "unittools.h"
38 
39 #include "sanitycheck.h"
40 
41 #ifdef SANITY_CHECKING
42 
43 #define SANITY_FAIL(format, ...) fc_assert_msg(false, format, ##__VA_ARGS__)
44 
45 #define SANITY_CHECK(check) fc_assert(check)
46 
47 #define SANITY_CITY(_city, check) \
48  fc_assert_msg(check, "(%4d, %4d) in \"%s\"[%d]", TILE_XY((_city)->tile), \
49  city_name_get(_city), city_size_get(_city))
50 
51 #define SANITY_TERRAIN(_tile, check) \
52  fc_assert_msg(check, "(%4d, %4d) at \"%s\"", TILE_XY(_tile), \
53  terrain_rule_name(tile_terrain(_tile)))
54 
55 #define SANITY_TILE(_tile, check) \
56  do { \
57  struct city *_tile##_city = tile_city(_tile); \
58  if (nullptr != _tile##_city) { \
59  SANITY_CITY(_tile##_city, check); \
60  } else { \
61  SANITY_TERRAIN(_tile, check); \
62  } \
63  } while (false)
64 
65 static void check_city_feelings(const struct city *pcity, const char *file,
66  const char *function, int line);
67 
71 static void check_specials(const char *file, const char *function, int line)
72 {
73  whole_map_iterate(&(wld.map), ptile)
74  {
75  const struct terrain *pterrain = tile_terrain(ptile);
76 
77  extra_type_iterate(pextra)
78  {
79  if (tile_has_extra(ptile, pextra)) {
80  extra_deps_iterate(&(pextra->reqs), pdep)
81  {
82  SANITY_TILE(ptile, tile_has_extra(ptile, pdep));
83  }
85  }
86  }
88 
89  extra_type_by_cause_iterate(EC_MINE, pextra)
90  {
91  if (tile_has_extra(ptile, pextra)) {
92  SANITY_TILE(ptile, pterrain->mining_result == pterrain);
93  }
94  }
96  extra_type_by_cause_iterate(EC_IRRIGATION, pextra)
97  {
98  if (tile_has_extra(ptile, pextra)) {
99  SANITY_TILE(ptile, pterrain->irrigation_result == pterrain);
100  }
101  }
103 
104  SANITY_TILE(ptile, terrain_index(pterrain) >= T_FIRST
105  && terrain_index(pterrain) < terrain_count());
106  }
108 }
109 
113 static void check_fow(const char *file, const char *function, int line)
114 {
115  if (!game_was_started()) {
116  // The private map of the players is only allocated at game start.
117  return;
118  }
119 
120  whole_map_iterate(&(wld.map), ptile)
121  {
122  players_iterate(pplayer)
123  {
124  struct player_tile *plr_tile = map_get_player_tile(ptile, pplayer);
125 
127  {
128  // underflow of unsigned int
129  SANITY_TILE(ptile, plr_tile->seen_count[v] < 30000);
130  SANITY_TILE(ptile, plr_tile->own_seen[v] < 30000);
131  SANITY_TILE(ptile, plr_tile->own_seen[v] <= plr_tile->seen_count[v]);
132  }
134 
135  // Lots of server bits depend on this.
136  SANITY_TILE(ptile, plr_tile->seen_count[V_INVIS]
137  <= plr_tile->seen_count[V_MAIN]);
138  SANITY_TILE(ptile,
139  plr_tile->own_seen[V_INVIS] <= plr_tile->own_seen[V_MAIN]);
140  }
142  }
144 
145  SANITY_CHECK(game.government_during_revolution != nullptr);
146  SANITY_CHECK(
148  == government_by_number(game.info.government_during_revolution_id));
149 }
150 
154 static void check_misc(const char *file, const char *function, int line)
155 {
156  int nplayers = 0, nbarbs = 0;
157 
158  // Do not use player_slots_iterate as we want to check the index!
159  player_slots_iterate(pslot)
160  {
161  if (player_slot_is_used(pslot)) {
162  if (is_barbarian(player_slot_get_player(pslot))) {
163  nbarbs++;
164  }
165  nplayers++;
166  }
167  }
169 
170  SANITY_CHECK(nplayers == player_count());
171  SANITY_CHECK(nbarbs == server.nbarbarians);
172 
173  SANITY_CHECK(player_count() <= MAX_NUM_PLAYER_SLOTS);
174  SANITY_CHECK(team_count() <= MAX_NUM_TEAM_SLOTS);
175  SANITY_CHECK(normal_player_count() <= game.server.max_players);
176 }
177 
181 static void check_map(const char *file, const char *function, int line)
182 {
183  whole_map_iterate(&(wld.map), ptile)
184  {
185  struct city *pcity = tile_city(ptile);
186  int cont = tile_continent(ptile);
187 
188  CHECK_INDEX(tile_index(ptile));
189 
190  if (nullptr != pcity) {
191  SANITY_TILE(ptile, same_pos(pcity->tile, ptile));
192  SANITY_TILE(ptile, tile_owner(ptile) != nullptr);
193  }
194 
195  if (nullptr == pcity && BORDERS_DISABLED == game.info.borders) {
196  // Only city tiles are claimed when borders are disabled
197  SANITY_TILE(ptile, tile_owner(ptile) == nullptr);
198  }
199 
200  if (is_ocean_tile(ptile)) {
201  SANITY_TILE(ptile, cont < 0);
202  adjc_iterate(&(wld.map), ptile, tile1)
203  {
204  if (is_ocean_tile(tile1)) {
205  SANITY_TILE(ptile, tile_continent(tile1) == cont);
206  }
207  }
209  } else {
210  SANITY_TILE(ptile, cont > 0);
211  adjc_iterate(&(wld.map), ptile, tile1)
212  {
213  if (!is_ocean_tile(tile1)) {
214  SANITY_TILE(ptile, tile_continent(tile1) == cont);
215  }
216  }
218  }
219 
220  unit_list_iterate(ptile->units, punit)
221  {
222  SANITY_TILE(ptile, same_pos(unit_tile(punit), ptile));
223 
224  // Check diplomatic status of stacked units.
225  unit_list_iterate(ptile->units, punit2)
226  {
227  SANITY_TILE(ptile,
228  pplayers_allied(unit_owner(punit), unit_owner(punit2)));
229  }
231  if (pcity) {
232  SANITY_TILE(ptile,
233  pplayers_allied(unit_owner(punit), city_owner(pcity)));
234  }
235  }
237  }
239 }
240 
244 static bool check_city_good(struct city *pcity, const char *file,
245  const char *function, int line)
246 {
247  struct player *pplayer = city_owner(pcity);
248  struct tile *pcenter = city_tile(pcity);
249 
250  if (nullptr == pcenter) {
251  // Editor!
252  SANITY_FAIL("(----,----) city has no tile (skipping remaining tests), "
253  "at %s \"%s\"[%d]%s",
255  city_name_get(pcity), city_size_get(pcity), "{city center}");
256  return false;
257  }
258 
259  SANITY_CITY(pcity,
260  !terrain_has_flag(tile_terrain(pcenter), TER_NO_CITIES));
261 
262  SANITY_CITY(pcity, nullptr != tile_owner(pcenter));
263  SANITY_CITY(pcity, city_owner(pcity) == tile_owner(pcenter));
264 
265  if (nullptr != tile_owner(pcenter)) {
266  if (tile_owner(pcenter) != pplayer) {
267  SANITY_FAIL(
268  "(%4d,%4d) tile owned by %s, at %s \"%s\"[%d]%s", TILE_XY(pcenter),
271  city_size_get(pcity), "{city center}");
272  }
273  }
274 
275  unit_list_iterate(pcity->units_supported, punit)
276  {
277  SANITY_CITY(pcity, punit->homecity == pcity->id);
278  SANITY_CITY(pcity, unit_owner(punit) == pplayer);
279  }
281 
282  city_built_iterate(pcity, pimprove)
283  {
284  if (is_small_wonder(pimprove)) {
285  SANITY_CITY(pcity, city_from_small_wonder(pplayer, pimprove) == pcity);
286  } else if (is_great_wonder(pimprove)) {
287  SANITY_CITY(pcity, city_from_great_wonder(pimprove) == pcity);
288  }
289  }
291 
292  trade_routes_iterate(pcity, proute)
293  {
294  struct city *partner = game_city_by_number(proute->partner);
295 
296  if (partner != nullptr) {
297  struct trade_route *back_route = nullptr;
298 
300  {
301  if (pback->partner == pcity->id) {
302  back_route = pback;
303  break;
304  }
305  }
307 
308  SANITY_CITY(pcity, back_route != nullptr);
309 
310  if (back_route != nullptr) {
311  switch (back_route->dir) {
312  case RDIR_TO:
313  SANITY_CITY(pcity, proute->dir == RDIR_FROM);
314  break;
315  case RDIR_FROM:
316  SANITY_CITY(pcity, proute->dir == RDIR_TO);
317  break;
318  case RDIR_BIDIRECTIONAL:
319  SANITY_CITY(pcity, proute->dir == RDIR_BIDIRECTIONAL);
320  break;
321  }
322 
323  SANITY_CITY(pcity, proute->goods == back_route->goods);
324  }
325  }
326  }
328 
329  return true;
330 }
331 
335 static void check_city_size(struct city *pcity, const char *file,
336  const char *function, int line)
337 {
338  int delta;
339  int citizen_count = 0;
340  struct tile *pcenter = city_tile(pcity);
341 
342  SANITY_CITY(pcity, city_size_get(pcity) >= 1);
343 
345  ptile, _index, _x, _y)
346  {
347  if (tile_worked(ptile) == pcity) {
348  citizen_count++;
349  }
350  }
352 
353  citizen_count += city_specialists(pcity);
354  delta = city_size_get(pcity) - citizen_count;
355  if (0 != delta) {
356  SANITY_FAIL("(%4d,%4d) %d citizens not equal [size], "
357  "repairing \"%s\"[%d]",
358  TILE_XY(pcity->tile), citizen_count, city_name_get(pcity),
359  city_size_get(pcity));
360 
362  log_debug("[%s (%d)] specialists: %d", city_name_get(pcity), pcity->id,
363  city_specialists(pcity));
364 
365  city_repair_size(pcity, delta);
366  city_refresh_from_main_map(pcity, nullptr,
368  }
369 }
370 
375 static void check_city_feelings(const struct city *pcity, const char *file,
376  const char *function, int line)
377 {
378  int feel;
379  int spe = city_specialists(pcity);
380 
381  for (feel = FEELING_BASE; feel < FEELING_LAST; feel++) {
382  int sum = 0;
383  int ccategory;
384 
385  for (ccategory = CITIZEN_HAPPY; ccategory < CITIZEN_LAST; ccategory++) {
386  sum += pcity->feel[ccategory][feel];
387  }
388 
389  /* While loading savegame, we want to check sanity of values read from
390  * the savegame despite the fact that city workers_frozen level of the
391  * city is above zero -> can't limit sanitycheck callpoints by that.
392  * Instead we check even more relevant needs_arrange. */
393  SANITY_CITY(pcity, !pcity->server.needs_arrange);
394 
395  SANITY_CITY(pcity, city_size_get(pcity) - spe == sum);
396  }
397 }
398 
402 void real_sanity_check_city(struct city *pcity, const char *file,
403  const char *function, int line)
404 {
405  if (check_city_good(pcity, file, function, line)) {
406  check_city_size(pcity, file, function, line);
407  check_city_feelings(pcity, file, function, line);
408  }
409 }
410 
414 static void check_cities(const char *file, const char *function, int line)
415 {
416  players_iterate(pplayer)
417  {
418  city_list_iterate(pplayer->cities, pcity)
419  {
420  SANITY_CITY(pcity, city_owner(pcity) == pplayer);
421 
422  real_sanity_check_city(pcity, file, function, line);
423  }
425  }
427 }
428 
432 static void check_units(const char *file, const char *function, int line)
433 {
434  players_iterate(pplayer)
435  {
436  unit_list_iterate(pplayer->units, punit)
437  {
438  struct tile *ptile = unit_tile(punit);
439  struct terrain *pterr = tile_terrain(ptile);
440  struct city *pcity;
441  struct city *phome;
442  struct unit *ptrans = unit_transport_get(punit);
443 
444  SANITY_CHECK(unit_owner(punit) == pplayer);
445 
446  if (IDENTITY_NUMBER_ZERO != punit->homecity) {
447  SANITY_CHECK(phome =
448  player_city_by_number(pplayer, punit->homecity));
449  if (phome) {
450  SANITY_CHECK(city_owner(phome) == pplayer);
451  }
452  }
453 
454  // Unit in the correct player list?
455  SANITY_CHECK(player_unit_by_number(unit_owner(punit), punit->id)
456  != nullptr);
457 
459  SANITY_FAIL("(%4d,%4d) %s has activity %s, "
460  "but it can't continue at %s",
461  TILE_XY(ptile), unit_rule_name(punit),
462  get_activity_text(punit->activity),
463  tile_get_info_text(ptile, true, 0));
464  }
465 
466  if (activity_requires_target(punit->activity)
467  && (punit->activity != ACTIVITY_IRRIGATE
468  || pterr->irrigation_result == pterr)
469  && (punit->activity != ACTIVITY_MINE
470  || pterr->mining_result == pterr)) {
471  SANITY_CHECK(punit->activity_target != nullptr);
472  }
473 
474  pcity = tile_city(ptile);
475  if (pcity) {
476  SANITY_CHECK(pplayers_allied(city_owner(pcity), pplayer));
477  }
478 
479  SANITY_CHECK(punit->moves_left >= 0);
480  SANITY_CHECK(punit->hp > 0);
481 
482  // Check for ground units in the ocean.
483  SANITY_CHECK(can_unit_exist_at_tile(&(wld.map), punit, ptile)
484  || ptrans != nullptr);
485 
486  // Check for over-full transports.
487  SANITY_CHECK(get_transporter_occupancy(punit)
488  <= get_transporter_capacity(punit));
489 
490  /* Check transporter. This should be last as the pointer ptrans will
491  * be modified. */
492  if (ptrans != nullptr) {
493  struct unit *plevel = punit;
494  int level = 0;
495 
496  // Make sure the transporter is on the tile.
497  SANITY_CHECK(same_pos(unit_tile(punit), unit_tile(ptrans)));
498 
499  // Can punit be cargo for its transporter?
500  SANITY_CHECK(unit_transport_check(punit, ptrans));
501 
502  // Check that the unit is listed as transported.
503  SANITY_CHECK(unit_list_search(unit_transport_cargo(ptrans), punit)
504  != nullptr);
505 
506  // Check the depth of the transportation.
507  while (ptrans) {
508  struct unit_list *pcargos = unit_transport_cargo(ptrans);
509 
510  SANITY_CHECK(pcargos != nullptr);
511  SANITY_CHECK(level < GAME_TRANSPORT_MAX_RECURSIVE);
512 
513  // Check for next level.
514  plevel = ptrans;
515  ptrans = unit_transport_get(plevel);
516  level++;
517  }
518 
519  /* Transporter capacity will be checked when transporter itself
520  * is checked */
521  }
522 
523  // Check that cargo is marked as transported with this unit
525  {
526  SANITY_CHECK(unit_transport_get(pcargo) == punit);
527  }
529  }
531  }
533 }
534 
538 static void check_players(const char *file, const char *function, int line)
539 {
540  players_iterate(pplayer)
541  {
542  int found_primary_capital = 0;
543 
544  if (!pplayer->is_alive) {
545  // Dead players' units and cities are disbanded in kill_player().
546  SANITY_CHECK(unit_list_size(pplayer->units) == 0);
547  SANITY_CHECK(city_list_size(pplayer->cities) == 0);
548 
549  continue;
550  }
551 
552  SANITY_CHECK(pplayer->server.adv != nullptr);
553  SANITY_CHECK(!pplayer->nation || pplayer->nation->player == pplayer);
554  SANITY_CHECK(player_list_search(team_members(pplayer->team), pplayer));
555 
556  SANITY_CHECK(!(city_list_size(pplayer->cities) > 0
557  && !pplayer->server.got_first_city));
558 
559  city_list_iterate(pplayer->cities, pcity)
560  {
561  if (pcity->capital == CAPITAL_PRIMARY) {
562  found_primary_capital++;
563  }
564  SANITY_CITY(pcity, found_primary_capital <= 1);
565  }
567 
568  players_iterate(pplayer2)
569  {
570  struct player_diplstate *state1, *state2;
571 
572  if (pplayer2 == pplayer) {
573  break; // Do diplomatic sanity check only once per player couple.
574  }
575 
576  state1 = player_diplstate_get(pplayer, pplayer2);
577  state2 = player_diplstate_get(pplayer2, pplayer);
578  SANITY_CHECK(state1->type == state2->type);
579  SANITY_CHECK(state1->max_state == state2->max_state);
580  if (state1->type == DS_CEASEFIRE || state1->type == DS_ARMISTICE) {
581  SANITY_CHECK(state1->turns_left == state2->turns_left);
582  }
583  if (state1->type == DS_TEAM) {
584  SANITY_CHECK(players_on_same_team(pplayer, pplayer2));
585  SANITY_CHECK(player_has_real_embassy(pplayer, pplayer2));
586  SANITY_CHECK(player_has_real_embassy(pplayer2, pplayer));
587  if (pplayer->is_alive && pplayer2->is_alive) {
588  SANITY_CHECK(really_gives_vision(pplayer, pplayer2));
589  SANITY_CHECK(really_gives_vision(pplayer2, pplayer));
590  }
591  }
592  if (pplayer->is_alive && pplayer2->is_alive
593  && pplayers_allied(pplayer, pplayer2)) {
594  enum dipl_reason allied_players_can_be_allied =
595  pplayer_can_make_treaty(pplayer, pplayer2, DS_ALLIANCE);
596  SANITY_CHECK(allied_players_can_be_allied
598  SANITY_CHECK(allied_players_can_be_allied
600  }
601  }
603 
604  if (pplayer->revolution_finishes == -1) {
605  if (government_of_player(pplayer)
607  SANITY_FAIL("%s government is anarchy, but does not finish!",
609  }
610  SANITY_CHECK(government_of_player(pplayer)
612  } else if (pplayer->revolution_finishes > game.info.turn) {
613  SANITY_CHECK(government_of_player(pplayer)
615  } else {
616  /* Things may vary in this case depending on when the sanity_check
617  * call is made. No better check is possible. */
618  }
619 
620  // Dying players shouldn't be left around. But they are.
621  SANITY_CHECK(!BV_ISSET(pplayer->server.status, PSTATUS_DYING));
622  }
624 
625  for (const auto &pnation : nations) {
626  SANITY_CHECK(!pnation.player || pnation.player->nation == &pnation);
627  }
628 
629  teams_iterate(pteam)
630  {
631  player_list_iterate(team_members(pteam), pplayer)
632  {
633  SANITY_CHECK(pplayer->team == pteam);
634  }
636  }
638 }
639 
643 static void check_teams(const char *file, const char *function, int line)
644 {
645  int count[MAX_NUM_TEAM_SLOTS];
646 
647  memset(count, 0, sizeof(count));
648  players_iterate(pplayer)
649  {
650  // For the moment, all players have teams.
651  SANITY_CHECK(pplayer->team != nullptr);
652  if (pplayer->team) {
653  count[team_index(pplayer->team)]++;
654  }
655  }
657 
658  team_slots_iterate(tslot)
659  {
660  if (team_slot_is_used(tslot)) {
661  struct team *pteam = team_slot_get_team(tslot);
662  fc_assert_exit(pteam);
663  SANITY_CHECK(player_list_size(team_members(pteam))
664  == count[team_slot_index(tslot)]);
665  }
666  }
668 }
669 
673 static void check_researches(const char *file, const char *function,
674  int line)
675 {
676  for (const auto &presearch : research_array) {
677  if (research_is_valid(presearch)) {
678  SANITY_CHECK(S_S_RUNNING != server_state()
679  || A_UNSET == presearch.researching
680  || is_future_tech(presearch.researching)
681  || (A_NONE != presearch.researching
682  && valid_advance_by_number(presearch.researching)));
683  SANITY_CHECK(A_UNSET == presearch.tech_goal
684  || (A_NONE != presearch.tech_goal
685  && valid_advance_by_number(presearch.tech_goal)));
686  }
687  };
688 }
689 
693 static void check_connections(const char *file, const char *function,
694  int line)
695 {
696  // est_connections is a subset of all_connections
697  SANITY_CHECK(conn_list_size(game.all_connections)
698  >= conn_list_size(game.est_connections));
699 }
700 
710 void real_sanity_check(const char *file, const char *function, int line)
711 {
712  if (!map_is_empty()) {
713  /* Don't sanity-check the map if it hasn't been created yet (this
714  * happens when loading scenarios). */
715  check_specials(file, function, line);
716  check_map(file, function, line);
717  check_cities(file, function, line);
718  check_units(file, function, line);
719  check_fow(file, function, line);
720  }
721  check_misc(file, function, line);
722  check_players(file, function, line);
723  check_teams(file, function, line);
724  check_researches(file, function, line);
725  check_connections(file, function, line);
726 }
727 
732 void real_sanity_check_tile(struct tile *ptile, const char *file,
733  const char *function, int line)
734 {
735  SANITY_CHECK(ptile != nullptr);
736  SANITY_CHECK(ptile->terrain != nullptr);
737 
738  unit_list_iterate(ptile->units, punit)
739  {
740  /* Check if the units can survive on the tile (terrain). Here only the
741  * 'easy' test if the unit is transported is done. A complete check is
742  * done by check_units() in real_sanity_check(). */
743  if (!can_unit_exist_at_tile(&(wld.map), punit, ptile)
744  && !unit_transported(punit)) {
745  SANITY_FAIL("(%4d,%4d) %s can't survive on %s", TILE_XY(ptile),
746  unit_rule_name(punit), tile_get_info_text(ptile, true, 0));
747  }
748  }
750 }
751 
752 #endif // SANITY_CHECKING
bool BV_ISSET(const BV &bv, int bit)
Definition: bitvector.h:37
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
Definition: city.cpp:1083
void citylog_map_workers(QtMsgType level, struct city *pcity)
Display the location of the workers within the city map of pcity.
Definition: city.cpp:435
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
citizens city_specialists(const struct city *pcity)
Give the number of specialists in a city.
Definition: city.cpp:3228
void city_refresh_from_main_map(struct city *pcity, bool *workers_map, const std::vector< city * > &gov_centers, const std::array< cached_waste, O_LAST > *pcwaste, const std::vector< std::array< int, O_LAST >> *pcsoutputs)
Refreshes the internal cached data in the city structure.
Definition: city.cpp:3052
citizens city_size_get(const struct city *pcity)
Get the city size.
Definition: city.cpp:1101
#define city_list_iterate(citylist, pcity)
Definition: city.h:482
@ CITIZEN_LAST
Definition: city.h:244
@ CITIZEN_HAPPY
Definition: city.h:240
#define city_list_iterate_end
Definition: city.h:484
@ FEELING_LAST
Definition: city.h:257
@ FEELING_BASE
Definition: city.h:251
#define city_tile_iterate_skip_center_end
Definition: city.h:193
#define city_tile_iterate_skip_center(_radius_sq, _city_tile, _tile, _index, _x, _y)
Definition: city.h:183
#define city_built_iterate(_pcity, _p)
Definition: city.h:752
#define city_built_iterate_end
Definition: city.h:759
void city_repair_size(struct city *pcity, int change)
Repair the city population without affecting city size.
Definition: cityturn.cpp:895
#define extra_type_iterate(_p)
Definition: extras.h:279
#define extra_deps_iterate(_reqs, _dep)
Definition: extras.h:335
#define extra_type_iterate_end
Definition: extras.h:285
#define extra_deps_iterate_end
Definition: extras.h:343
#define extra_type_by_cause_iterate_end
Definition: extras.h:307
#define extra_type_by_cause_iterate(_cause, _extra)
Definition: extras.h:299
#define MAX_NUM_PLAYER_SLOTS
Definition: fc_types.h:24
@ BORDERS_DISABLED
Definition: fc_types.h:863
#define IDENTITY_NUMBER_ZERO
Definition: fc_types.h:76
struct civ_game game
Definition: game.cpp:47
struct world wld
Definition: game.cpp:48
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
Definition: game.cpp:103
#define GAME_TRANSPORT_MAX_RECURSIVE
Definition: game.h:695
struct government * government_of_player(const struct player *pplayer)
Return the government of a player.
Definition: government.cpp:107
struct government * government_by_number(const Government_type_id gov)
Return the government with the given index.
Definition: government.cpp:96
struct city * city_from_great_wonder(const struct impr_type *pimprove)
Get the world city with this great wonder.
struct city * city_from_small_wonder(const struct player *pplayer, const struct impr_type *pimprove)
Get the player city with this small wonder.
bool is_great_wonder(const struct impr_type *pimprove)
Is this building a great wonder?
bool is_small_wonder(const struct impr_type *pimprove)
Is this building a small wonder?
constexpr auto LOG_DEBUG
Definition: log.h:27
#define log_debug(message,...)
Definition: log.h:65
#define fc_assert_exit(condition)
Definition: log.h:117
bool map_is_empty()
Returns TRUE if we are at a stage of the game where the map has not yet been generated/loaded.
Definition: map.cpp:124
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Are (x1,y1) and (x2,y2) really the same when adjusted? This function might be necessary ALOT of place...
Definition: map.cpp:887
#define adjc_iterate_end
Definition: map.h:358
#define CHECK_INDEX(mindex)
Definition: map.h:103
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition: map.h:351
#define whole_map_iterate(_map, _tile)
Definition: map.h:473
#define whole_map_iterate_end
Definition: map.h:480
bool really_gives_vision(struct player *me, struct player *them)
Return TRUE iff the player me really gives shared vision to player them.
Definition: maphand.cpp:325
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Players' information of tiles is tracked so that fogged area can be kept consistent even when the cli...
Definition: maphand.cpp:1341
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Return TRUE iff the unit can "exist" at this location.
Definition: movement.cpp:267
const char * nation_rule_name(const struct nation_type *pnation)
Return the (untranslated) rule name of the nation (adjective form).
Definition: nation.cpp:115
std::vector< nation_type > nations
Definition: nation.cpp:38
struct nation_type * nation_of_player(const struct player *pplayer)
Return the nation of a player.
Definition: nation.cpp:419
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
If the specified player owns the unit with the specified id, return pointer to the unit struct.
Definition: player.cpp:1139
bool player_slot_is_used(const struct player_slot *pslot)
Returns TRUE is this slot is "used" i.e.
Definition: player.cpp:395
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Return TRUE if players are in the same team.
Definition: player.cpp:1405
enum dipl_reason pplayer_can_make_treaty(const struct player *p1, const struct player *p2, enum diplstate_type treaty)
Returns true iff p1 can make given treaty with p2.
Definition: player.cpp:150
int player_count()
Return the number of players.
Definition: player.cpp:739
std::vector< city * > player_gov_centers(const struct player *pplayer)
Locate the player's government centers.
Definition: player.cpp:1264
bool player_has_real_embassy(const struct player *pplayer, const struct player *pplayer2)
Returns whether pplayer has a real embassy with pplayer2, established from a diplomat,...
Definition: player.cpp:206
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
struct player * player_slot_get_player(const struct player_slot *pslot)
Returns the team corresponding to the slot.
Definition: player.cpp:384
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players are allied.
Definition: player.cpp:1334
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Returns diplomatic state type between two players.
Definition: player.cpp:288
#define players_iterate_end
Definition: player.h:520
dipl_reason
Definition: player.h:183
@ DIPL_ALLIANCE_PROBLEM_THEM
Definition: player.h:188
@ DIPL_ALLIANCE_PROBLEM_US
Definition: player.h:187
#define players_iterate(_pplayer)
Definition: player.h:514
#define player_list_iterate(playerlist, pplayer)
Definition: player.h:541
static bool is_barbarian(const struct player *pplayer)
Definition: player.h:474
#define player_slots_iterate(_pslot)
Definition: player.h:505
#define player_list_iterate_end
Definition: player.h:543
#define player_slots_iterate_end
Definition: player.h:509
int normal_player_count()
Return the number of non-barbarian players.
Definition: plrhand.cpp:3140
bool research_is_valid(const struct research &presearch)
Checks whether the research object is valid in the current game.
Definition: research.cpp:125
std::vector< research > research_array
struct setting_list * level[OLEVELS_NUM]
Definition: settings.cpp:167
bool game_was_started()
Returns iff the game was started once upon a time.
Definition: srv_main.cpp:251
enum server_states server_state()
Return current server state.
Definition: srv_main.cpp:238
Definition: city.h:291
int id
Definition: city.h:296
enum capital_type capital
Definition: city.h:298
struct city::@15::@17 server
citizens feel[CITIZEN_LAST][FEELING_LAST]
Definition: city.h:302
struct tile * tile
Definition: city.h:293
struct unit_list * units_supported
Definition: city.h:377
struct civ_game::@28::@32 server
struct conn_list * est_connections
Definition: game.h:88
struct packet_game_info info
Definition: game.h:80
struct conn_list * all_connections
Definition: game.h:87
struct government * government_during_revolution
Definition: game.h:85
struct player * player
Definition: nation.h:97
enum diplstate_type max_state
Definition: player.h:194
enum diplstate_type type
Definition: player.h:193
v_radius_t seen_count
Definition: maphand.h:40
v_radius_t own_seen
Definition: maphand.h:39
Definition: player.h:231
struct city_list * cities
Definition: player.h:263
int revolution_finishes
Definition: player.h:255
struct player::@65::@67 server
struct team * team
Definition: player.h:243
struct unit_list * units
Definition: player.h:264
bool is_alive
Definition: player.h:250
struct nation_type * nation
Definition: player.h:242
Definition: servers.h:55
Definition: team.cpp:35
struct terrain * irrigation_result
Definition: terrain.h:200
struct terrain * mining_result
Definition: terrain.h:204
Definition: tile.h:42
struct unit_list * units
Definition: tile.h:50
struct terrain * terrain
Definition: tile.h:49
enum route_direction dir
Definition: traderoutes.h:75
struct goods_type * goods
Definition: traderoutes.h:76
Definition: unit.h:134
struct civ_map map
Definition: world_object.h:21
int team_index(const struct team *pteam)
Return the team index.
Definition: team.cpp:359
int team_count()
Return the current number of teams.
Definition: team.cpp:354
struct team * team_slot_get_team(const struct team_slot *tslot)
Returns the team corresponding to the slot.
Definition: team.cpp:132
const struct player_list * team_members(const struct team *pteam)
Returns the member list of the team.
Definition: team.cpp:427
int team_slot_index(const struct team_slot *tslot)
Returns the index of the team slots.
Definition: team.cpp:120
bool team_slot_is_used(const struct team_slot *tslot)
Returns TRUE is this slot is "used" i.e.
Definition: team.cpp:144
#define team_slots_iterate_end
Definition: team.h:66
#define team_slots_iterate(_tslot)
Definition: team.h:62
#define teams_iterate_end
Definition: team.h:76
#define teams_iterate(_pteam)
Definition: team.h:71
#define MAX_NUM_TEAM_SLOTS
Definition: team.h:17
bool is_future_tech(Tech_type_id tech)
Is the given tech a future tech.
Definition: tech.cpp:268
struct advance * valid_advance_by_number(const Tech_type_id id)
Returns pointer when the advance "exists" in this game, returns nullptr otherwise.
Definition: tech.cpp:154
#define A_NONE
Definition: tech.h:36
#define A_UNSET
Definition: tech.h:41
Terrain_type_id terrain_count()
Return the number of terrains.
Definition: terrain.cpp:93
Terrain_type_id terrain_index(const struct terrain *pterrain)
Return the terrain index.
Definition: terrain.cpp:110
#define is_ocean_tile(ptile)
Definition: terrain.h:279
#define terrain_has_flag(terr, flag)
Definition: terrain.h:260
#define T_FIRST
Definition: terrain.h:54
const char * tile_get_info_text(const struct tile *ptile, bool include_nuisances, int linebreaks)
Return a (static) string with tile name describing terrain and extras of some categories.
Definition: tile.cpp:799
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
Definition: tile.cpp:72
#define tile_index(_pt_)
Definition: tile.h:70
#define tile_worked(_tile)
Definition: tile.h:97
#define tile_terrain(_tile)
Definition: tile.h:93
#define TILE_XY(ptile)
Definition: tile.h:36
#define tile_continent(_tile)
Definition: tile.h:74
#define tile_has_extra(ptile, pextra)
Definition: tile.h:130
#define tile_owner(_tile)
Definition: tile.h:78
#define trade_routes_iterate_end
Definition: traderoutes.h:127
#define trade_routes_iterate(c, proute)
Definition: traderoutes.h:122
int get_transporter_occupancy(const struct unit *ptrans)
Return how many units are in the transport.
Definition: unit.cpp:1647
bool unit_transport_check(const struct unit *pcargo, const struct unit *ptrans)
Returns whether 'pcargo' in 'ptrans' is a valid transport.
Definition: unit.cpp:2227
struct unit * unit_transport_get(const struct unit *pcargo)
Returns the transporter of the unit or nullptr if it is not transported.
Definition: unit.cpp:2189
bool can_unit_continue_current_activity(struct unit *punit)
Check if the unit's current activity is actually legal.
Definition: unit.cpp:780
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
Returns the list of cargo units.
Definition: unit.cpp:2199
int get_transporter_capacity(const struct unit *punit)
Return the number of units the transporter can hold (or 0).
Definition: unit.cpp:280
const char * get_activity_text(enum unit_activity activity)
Return the name of the activity in a static buffer.
Definition: unit.cpp:586
bool unit_transported(const struct unit *pcargo)
Returns TRUE iff the unit is transported.
Definition: unit.cpp:2176
bool activity_requires_target(enum unit_activity activity)
Return TRUE if activity requires some sort of target to be specified.
Definition: unit.cpp:506
#define unit_tile(_pu)
Definition: unit.h:371
#define unit_owner(_pu)
Definition: unit.h:370
#define unit_list_iterate(unitlist, punit)
Definition: unitlist.h:25
#define unit_list_iterate_end
Definition: unitlist.h:27
const char * unit_rule_name(const struct unit *punit)
Return the (untranslated) rule name of the unit.
Definition: unittype.cpp:1283
#define vision_layer_iterate(v)
Definition: vision.h:72
#define vision_layer_iterate_end
Definition: vision.h:77