Freeciv21
Develop your civilization from humble roots to a global empire
climisc.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2023 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 
19 #include <QBitArray>
20 #include <algorithm>
21 #include <cstdarg>
22 #include <cstdlib>
23 #include <cstring>
24 
25 // utility
26 #include "fcintl.h"
27 #include "log.h"
28 #include "support.h"
29 
30 // common
31 #include "city.h"
32 #include "diptreaty.h"
33 #include "featured_text.h"
34 #include "game.h"
35 #include "government.h"
36 #include "map.h"
37 #include "mapimg.h"
38 #include "packets.h"
39 #include "research.h"
40 #include "spaceship.h"
41 #include "unitlist.h"
42 
43 /* client/include */
44 #include "citydlg_g.h"
45 #include "cityrep_g.h"
46 #include "dialogs_g.h"
47 #include "mapview_g.h"
48 
49 // client
50 #include "chatline_common.h"
51 #include "citydlg_common.h"
52 #include "client_main.h"
53 #include "climap.h"
54 #include "climisc.h"
55 #include "control.h"
56 #include "messagewin_common.h"
57 #include "options.h"
58 #include "packhand.h"
59 #include "page_game.h"
60 #include "qtg_cxxside.h"
61 #include "tileset/tilespec.h"
62 #include "views/view_map.h"
63 #include "views/view_map_common.h"
64 
65 extern void flush_dirty_overview();
69 void client_remove_unit(struct unit *punit)
70 {
71  struct city *pcity;
72  struct tile *ptile = unit_tile(punit);
73  int hc = punit->homecity;
74  struct unit old_unit = *punit;
75  int old = get_num_units_in_focus();
76  bool update;
77 
78  log_debug("removing unit %d, %s %s (%d %d) hcity %d", punit->id,
80  TILE_XY(unit_tile(punit)), hc);
81 
82  update = (get_focus_unit_on_tile(unit_tile(punit)) != nullptr);
83 
84  // Check transport status.
85  unit_transport_unload(punit);
86  if (get_transporter_occupancy(punit) > 0) {
88  {
89  /* The server should take care that the unit is on the right terrain.
90  */
91  unit_transport_unload(pcargo);
92  }
94  }
95 
96  control_unit_killed(punit);
97  game_remove_unit(&wld, punit);
98  punit = nullptr;
99  if (old > 0 && get_num_units_in_focus() == 0) {
101  } else if (update) {
103  }
104 
105  pcity = tile_city(ptile);
106  if (nullptr != pcity) {
108  pcity->client.occupied = (0 < unit_list_size(pcity->tile->units));
109  refresh_city_dialog(pcity);
110  }
111 
112  log_debug("map city %s, %s, (%d %d)", city_name_get(pcity),
114  TILE_XY(city_tile(pcity)));
115  }
116 
117  if (!client_has_player() || unit_owner(&old_unit) == client_player()) {
118  pcity = game_city_by_number(hc);
119  if (nullptr != pcity) {
120  refresh_city_dialog(pcity);
121  log_debug("home city %s, %s, (%d %d)", city_name_get(pcity),
123  TILE_XY(city_tile(pcity)));
124  }
125  }
126 
127  refresh_unit_mapcanvas(&old_unit, ptile, true);
129 }
130 
134 void client_remove_city(struct city *pcity)
135 {
136  bool effect_update;
137  struct tile *ptile = city_tile(pcity);
138  struct city old_city = *pcity;
139 
140  log_debug("client_remove_city() %d, %s", pcity->id, city_name_get(pcity));
141 
142  /* Explicitly remove all improvements, to properly remove any global
143  effects and to handle the preservation of "destroyed" effects. */
144  effect_update = false;
145 
146  city_built_iterate(pcity, pimprove)
147  {
148  effect_update = true;
149  city_remove_improvement(pcity, pimprove);
150  }
152 
153  if (effect_update) {
154  // nothing yet
155  }
156 
157  if (auto dialog = is_any_city_dialog_open();
158  dialog && pcity->id == dialog->id) {
160  }
161  game_remove_city(&wld, pcity);
163  refresh_city_mapcanvas(&old_city, ptile, true);
164 }
165 
169 const char *get_embassy_status(const struct player *me,
170  const struct player *them)
171 {
172  if (!me || !them || me == them || !them->is_alive || !me->is_alive) {
173  return "-";
174  }
175  if (player_has_embassy(me, them)) {
176  if (player_has_embassy(them, me)) {
177  return Q_("?embassy:Both");
178  } else {
179  return Q_("?embassy:Yes");
180  }
181  } else if (player_has_embassy(them, me)) {
182  return Q_("?embassy:With Us");
183  } else if (player_diplstate_get(me, them)->contact_turns_left > 0
184  || player_diplstate_get(them, me)->contact_turns_left > 0) {
185  return Q_("?embassy:Contact");
186  } else {
187  return Q_("?embassy:No Contact");
188  }
189 }
190 
194 const char *get_vision_status(const struct player *me,
195  const struct player *them)
196 {
197  if (me && them && gives_shared_vision(me, them)) {
198  if (gives_shared_vision(them, me)) {
199  return Q_("?vision:Both");
200  } else {
201  return Q_("?vision:To Them");
202  }
203  } else if (me && them && gives_shared_vision(them, me)) {
204  return Q_("?vision:To Us");
205  } else {
206  return "";
207  }
208 }
209 
213 void client_diplomacy_clause_string(char *buf, int bufsiz,
214  struct Clause *pclause)
215 {
216  struct city *pcity;
217 
218  switch (pclause->type) {
219  case CLAUSE_ADVANCE:
220  fc_snprintf(buf, bufsiz, _("The %s give %s"),
221  nation_plural_for_player(pclause->from),
223  break;
224  case CLAUSE_CITY:
225  pcity = game_city_by_number(pclause->value);
226  if (pcity) {
227  fc_snprintf(buf, bufsiz, _("The %s give %s"),
228  nation_plural_for_player(pclause->from),
229  city_name_get(pcity));
230  } else {
231  fc_snprintf(buf, bufsiz, _("The %s give an unknown city"),
232  nation_plural_for_player(pclause->from));
233  }
234  break;
235  case CLAUSE_GOLD:
236  fc_snprintf(
237  buf, bufsiz,
238  PL_("The %s give %d gold", "The %s give %d gold", pclause->value),
239  nation_plural_for_player(pclause->from), pclause->value);
240  break;
241  case CLAUSE_MAP:
242  fc_snprintf(buf, bufsiz, _("The %s give their worldmap"),
243  nation_plural_for_player(pclause->from));
244  break;
245  case CLAUSE_SEAMAP:
246  fc_snprintf(buf, bufsiz, _("The %s give their seamap"),
247  nation_plural_for_player(pclause->from));
248  break;
249  case CLAUSE_CEASEFIRE:
250  fc_snprintf(buf, bufsiz, _("The parties agree on a cease-fire"));
251  break;
252  case CLAUSE_PEACE:
253  fc_snprintf(buf, bufsiz, _("The parties agree on a peace"));
254  break;
255  case CLAUSE_ALLIANCE:
256  fc_snprintf(buf, bufsiz, _("The parties create an alliance"));
257  break;
258  case CLAUSE_VISION:
259  fc_snprintf(buf, bufsiz, _("The %s give shared vision"),
260  nation_plural_for_player(pclause->from));
261  break;
262  case CLAUSE_EMBASSY:
263  fc_snprintf(buf, bufsiz, _("The %s give an embassy"),
264  nation_plural_for_player(pclause->from));
265  break;
266  default:
267  fc_assert(false);
268  if (bufsiz > 0) {
269  *buf = '\0';
270  }
271  break;
272  }
273 }
274 
280 static void catastrophe_scaled(int *chance, int *rate, int max, int current,
281  int accum, int level)
282 {
283  // 20 from factor in update_environmental_upset()
284  int numer = 20 * max;
285  int denom = map_num_tiles();
286 
287  if (chance) {
288  *chance =
289  CLIP(0, (int) ((((long) accum * numer) + (denom - 1)) / denom), max);
290  }
291  if (rate) {
292  *rate = DIVIDE(((long) (current - level) * numer) + (denom - 1), denom);
293  }
294 }
295 
299 void global_warming_scaled(int *chance, int *rate, int max)
300 {
301  return catastrophe_scaled(chance, rate, max, game.info.heating,
302  game.info.globalwarming, game.info.warminglevel);
303 }
304 
308 void nuclear_winter_scaled(int *chance, int *rate, int max)
309 {
310  return catastrophe_scaled(chance, rate, max, game.info.cooling,
311  game.info.nuclearwinter, game.info.coolinglevel);
312 }
313 
317 const QPixmap *client_research_sprite()
318 {
319  if (nullptr != client.conn.playing && can_client_change_view()) {
320  const struct research *presearch = research_get(client_player());
321  int idx = 0;
322 
323  if (A_UNSET != presearch->researching) {
324  idx = (NUM_TILES_PROGRESS * presearch->bulbs_researched
325  / (presearch->client.researching_cost + 1));
326  }
327 
328  /* This clipping can be necessary since we can end up with excess
329  * research */
330  idx = CLIP(0, idx, NUM_TILES_PROGRESS - 1);
332  } else {
334  }
335 }
336 
340 const QPixmap *client_warming_sprite()
341 {
342  int idx;
343 
344  if (can_client_change_view()) {
345  // Highest sprite kicks in at about 25% risk
346  global_warming_scaled(&idx, nullptr, (NUM_TILES_PROGRESS - 1) * 4);
347  idx = CLIP(0, idx, NUM_TILES_PROGRESS - 1);
348  } else {
349  idx = 0;
350  }
352 }
353 
357 const QPixmap *client_cooling_sprite()
358 {
359  int idx;
360 
361  if (can_client_change_view()) {
362  // Highest sprite kicks in at about 25% risk
363  nuclear_winter_scaled(&idx, nullptr, (NUM_TILES_PROGRESS - 1) * 4);
364  idx = CLIP(0, idx, NUM_TILES_PROGRESS - 1);
365  } else {
366  idx = 0;
367  }
369 }
370 
374 const QPixmap *client_government_sprite()
375 {
376  if (nullptr != client.conn.playing && can_client_change_view()
377  && government_count() > 0) {
379 
380  return get_government_sprite(tileset, gov);
381  } else {
382  /* HACK: the UNHAPPY citizen is used for the government
383  * when we don't know any better. */
384  return get_citizen_sprite(tileset, CITIZEN_UNHAPPY, 0, nullptr);
385  }
386 }
387 
393 {
394  struct city *pcity;
395  struct unit *punit;
396 
397  if (!can_client_change_view()) {
398  return;
399  }
400 
401  if (get_num_units_in_focus() > 0) {
403  false);
404  } else if (client_has_player()
405  && nullptr
406  != (pcity = player_primary_capital(client_player()))) {
407  // Else focus on the capital.
408  queen()->mapview_wdg->center_on_tile(pcity->tile, false);
409  } else if (nullptr != client.conn.playing
410  && 0 < city_list_size(client.conn.playing->cities)) {
411  // Just focus on any city.
412  pcity = city_list_get(client.conn.playing->cities, 0);
413  fc_assert_ret(pcity != nullptr);
414  queen()->mapview_wdg->center_on_tile(pcity->tile, false);
415  } else if (nullptr != client.conn.playing
416  && 0 < unit_list_size(client.conn.playing->units)) {
417  // Just focus on any unit.
418  punit = unit_list_get(client.conn.playing->units, 0);
419  fc_assert_ret(punit != nullptr);
420  queen()->mapview_wdg->center_on_tile(unit_tile(punit), false);
421  } else {
422  struct tile *ctile =
424 
425  // Just any known tile will do; search near the middle first.
426  /* Iterate outward from the center tile. We have to give a radius that
427  * is guaranteed to be larger than the map will be. Although this is
428  * a misuse of map.xsize and map.ysize (which are native dimensions),
429  * it should give a sufficiently large radius. */
430  iterate_outward(&(wld.map), ctile, wld.map.xsize + wld.map.ysize, ptile)
431  {
432  if (client_tile_get_known(ptile) != TILE_UNKNOWN) {
433  ctile = ptile;
434  break;
435  }
436  }
438 
439  queen()->mapview_wdg->center_on_tile(ctile, false);
440  }
441 }
442 
446 cid cid_encode(struct universal target)
447 {
448  return VUT_UTYPE == target.kind
449  ? B_LAST + utype_number(target.value.utype)
451 }
452 
456 cid cid_encode_unit(const struct unit_type *punittype)
457 {
458  struct universal target = {.value = {.utype = punittype},
459  .kind = VUT_UTYPE};
460 
461  return cid_encode(target);
462 }
463 
467 cid cid_encode_building(const struct impr_type *pimprove)
468 {
469  struct universal target = {.value = {.building = pimprove},
470  .kind = VUT_IMPROVEMENT};
471 
472  return cid_encode(target);
473 }
474 
478 struct universal cid_decode(cid id)
479 {
480  struct universal target;
481 
482  if (id >= B_LAST) {
483  target.kind = VUT_UTYPE;
484  target.value.utype = utype_by_number(id - B_LAST);
485  } else {
486  target.kind = VUT_IMPROVEMENT;
487  target.value.building = improvement_by_number(id);
488  }
489 
490  return target;
491 }
492 
497 bool city_unit_supported(const struct city *pcity,
498  const struct universal *target)
499 {
500  if (VUT_UTYPE == target->kind) {
501  const struct unit_type *tvtype = target->value.utype;
502 
503  unit_list_iterate(pcity->units_supported, punit)
504  {
505  if (unit_type_get(punit) == tvtype) {
506  return true;
507  }
508  }
510  }
511  return false;
512 }
513 
518 bool city_unit_present(const struct city *pcity,
519  const struct universal *target)
520 {
521  if (VUT_UTYPE == target->kind) {
522  const struct unit_type *tvtype = target->value.utype;
523 
524  unit_list_iterate(pcity->tile->units, punit)
525  {
526  if (unit_type_get(punit) == tvtype) {
527  return true;
528  }
529  }
531  }
532  return false;
533 }
534 
538 bool city_building_present(const struct city *pcity,
539  const struct universal *target)
540 {
541  return VUT_IMPROVEMENT == target->kind
542  && city_has_building(pcity, target->value.building);
543 }
544 
548 static int target_get_section(struct universal target)
549 {
550  if (VUT_UTYPE == target.kind) {
551  if (utype_has_flag(target.value.utype, UTYF_CIVILIAN)) {
552  return 2;
553  } else {
554  return 3;
555  }
556  } else {
557  if (improvement_has_flag(target.value.building, IF_GOLD)) {
558  return 1;
559  } else if (is_small_wonder(target.value.building)) {
560  return 4;
561  } else if (is_great_wonder(target.value.building)) {
562  return 5;
563  } else {
564  return 0;
565  }
566  }
567 }
568 
572 static int fc_cmp(const void *p1, const void *p2)
573 {
574  const struct item *i1 = static_cast<const item *>(p1),
575  *i2 = static_cast<const item *>(p2);
576  int s1 = target_get_section(i1->item);
577  int s2 = target_get_section(i2->item);
578 
579  if (s1 == s2) {
580  return fc_strcasecmp(i1->descr, i2->descr);
581  }
582  return s1 - s2;
583 }
584 
596 void name_and_sort_items(struct universal *targets, int num_targets,
597  struct item *items, bool show_cost,
598  struct city *pcity)
599 {
600  int i;
601 
602  for (i = 0; i < num_targets; i++) {
603  struct universal target = targets[i];
604  int cost;
605  struct item *pitem = &items[i];
606  const char *name;
607 
608  pitem->item = target;
609 
610  if (VUT_UTYPE == target.kind) {
612  cost = utype_build_shield_cost(pcity, target.value.utype);
613  } else {
615  if (improvement_has_flag(target.value.building, IF_GOLD)) {
616  cost = -1;
617  } else {
618  if (pcity != nullptr) {
619  cost = impr_build_shield_cost(pcity, target.value.building);
620  } else {
621  cost = MAX(target.value.building->build_cost * game.info.shieldbox
622  / 100,
623  1);
624  }
625  }
626  }
627 
628  if (show_cost) {
629  if (cost < 0) {
630  fc_snprintf(pitem->descr, sizeof(pitem->descr), "%s (XX)", name);
631  } else {
632  fc_snprintf(pitem->descr, sizeof(pitem->descr), "%s (%d)", name,
633  cost);
634  }
635  } else {
636  (void) fc_strlcpy(pitem->descr, name, sizeof(pitem->descr));
637  }
638  }
639 
640  qsort(items, num_targets, sizeof(struct item), fc_cmp);
641 }
642 
649  struct city **selected_cities,
650  int num_selected_cities, bool append_units,
651  bool append_wonders, bool change_prod,
653 {
654  cid first = append_units ? B_LAST : 0;
655  cid last = (append_units ? utype_count() + B_LAST : improvement_count());
656  cid id;
657  int items_used = 0;
658 
659  for (id = first; id < last; id++) {
660  bool append = false;
661  struct universal target = cid_decode(id);
662 
663  if (!append_units
664  && (append_wonders != is_wonder(target.value.building))) {
665  continue;
666  }
667 
668  if (!change_prod) {
669  if (client_has_player()) {
671  {
672  append |= test_func(pcity, &target);
673  }
675  } else {
676  cities_iterate(pcity) { append |= test_func(pcity, &target); }
678  }
679  } else {
680  int i;
681 
682  for (i = 0; i < num_selected_cities; i++) {
683  append |= test_func(selected_cities[i], &target);
684  }
685  }
686 
687  if (!append) {
688  continue;
689  }
690 
691  targets[items_used] = target;
692  items_used++;
693  }
694  return items_used;
695 }
696 
702  struct city *pcity,
703  bool advanced_tech)
704 {
705  struct player *pplayer = client_player();
706  int cids_used = 0;
707 
708  improvement_iterate(pimprove)
709  {
710  bool can_build;
711  bool can_eventually_build;
712 
713  if (nullptr != pcity) {
714  // Can the city build?
715  can_build = can_city_build_improvement_now(pcity, pimprove);
716  can_eventually_build =
717  can_city_build_improvement_later(pcity, pimprove);
718  } else if (nullptr != pplayer) {
719  // Can our player build?
720  can_build = can_player_build_improvement_now(pplayer, pimprove);
721  can_eventually_build =
722  can_player_build_improvement_later(pplayer, pimprove);
723  } else {
724  // Global observer case: can any player build?
725  can_build = false;
726  players_iterate(aplayer)
727  {
728  if (can_player_build_improvement_now(aplayer, pimprove)) {
729  can_build = true;
730  break;
731  }
732  }
734 
735  can_eventually_build = false;
736  players_iterate(aplayer)
737  {
738  if (can_player_build_improvement_later(aplayer, pimprove)) {
739  can_eventually_build = true;
740  break;
741  }
742  }
744  }
745 
746  if ((advanced_tech && can_eventually_build)
747  || (!advanced_tech && can_build)) {
748  targets[cids_used].kind = VUT_IMPROVEMENT;
749  targets[cids_used].value.building = pimprove;
750  cids_used++;
751  }
752  }
754 
755  unit_type_iterate(punittype)
756  {
757  bool can_build;
758  bool can_eventually_build;
759 
760  if (nullptr != pcity) {
761  // Can the city build?
762  can_build = can_city_build_unit_now(pcity, punittype);
763  can_eventually_build = can_city_build_unit_later(pcity, punittype);
764  } else if (nullptr != pplayer) {
765  // Can our player build?
766  can_build = can_player_build_unit_now(pplayer, punittype);
767  can_eventually_build = can_player_build_unit_later(pplayer, punittype);
768  } else {
769  // Global observer case: can any player build?
770  can_build = false;
771  players_iterate(aplayer)
772  {
773  if (can_player_build_unit_now(aplayer, punittype)) {
774  can_build = true;
775  break;
776  }
777  }
779 
780  can_eventually_build = false;
781  players_iterate(aplayer)
782  {
783  if (can_player_build_unit_later(aplayer, punittype)) {
784  can_eventually_build = true;
785  break;
786  }
787  }
789  }
790 
791  if ((advanced_tech && can_eventually_build)
792  || (!advanced_tech && can_build)) {
793  targets[cids_used].kind = VUT_UTYPE;
794  targets[cids_used].value.utype = punittype;
795  cids_used++;
796  }
797  }
799 
800  return cids_used;
801 }
802 
807  struct city *pcity)
808 {
809  int cids_used = 0;
810 
811  fc_assert_ret_val(pcity != nullptr, 0);
812 
813  city_built_iterate(pcity, pimprove)
814  {
815  targets[cids_used].kind = VUT_IMPROVEMENT;
816  targets[cids_used].value.building = pimprove;
817  cids_used++;
818  }
820 
821  return cids_used;
822 }
823 
827 void handle_event(const char *featured_text, struct tile *ptile,
828  enum event_type event, int turn, int phase, int conn_id)
829 {
830  char plain_text[MAX_LEN_MSG];
831  struct text_tag_list *tags;
832  int where = MW_OUTPUT; // where to display the message
833  bool fallback_needed = false; /* we want fallback if actual 'where' is not
834  * usable */
835  bool shown = false; // Message displayed somewhere at least
836 
837  if (!event_type_is_valid(event)) {
838  // Server may have added a new event; leave as MW_OUTPUT
839  qDebug("Unknown event type %d!", event);
840  } else {
841  where = messages_where[event];
842  }
843 
844  // Get the original text.
845  featured_text_to_plain_text(featured_text, plain_text, sizeof(plain_text),
846  &tags, conn_id != -1);
847 
848  // Display link marks when an user is pointed us something.
849  if (conn_id != -1) {
850  text_tag_list_iterate(tags, ptag)
851  {
852  if (text_tag_type(ptag) == TTT_LINK) {
854  }
855  }
857  }
858 
859  /* Maybe highlight our player and user names if someone is talking
860  * about us. */
861  if (-1 != conn_id && client.conn.id != conn_id
863  const char *username = client.conn.username;
864  size_t userlen = qstrlen(username);
865  const char *playername = ((client_player() && !client_is_observer())
867  : nullptr);
868  size_t playerlen = playername ? qstrlen(playername) : 0;
869  const char *p;
870 
871  if (playername && playername[0] == '\0') {
872  playername = nullptr;
873  }
874 
875  if (username && username[0] == '\0') {
876  username = nullptr;
877  }
878 
879  for (p = plain_text; *p != '\0'; p++) {
880  if (nullptr != username && 0 == fc_strncasecmp(p, username, userlen)) {
881  struct text_tag *ptag =
882  text_tag_new(TTT_COLOR, p - plain_text, p - plain_text + userlen,
884 
885  fc_assert(ptag != nullptr);
886 
887  if (ptag != nullptr) {
888  // Appends to be sure it will be applied at last.
889  text_tag_list_append(tags, ptag);
890  }
891  } else if (nullptr != playername
892  && 0 == fc_strncasecmp(p, playername, playerlen)) {
893  struct text_tag *ptag = text_tag_new(
894  TTT_COLOR, p - plain_text, p - plain_text + playerlen,
896 
897  fc_assert(ptag != nullptr);
898 
899  if (ptag != nullptr) {
900  // Appends to be sure it will be applied at last.
901  text_tag_list_append(tags, ptag);
902  }
903  }
904  }
905  }
906 
907  // Popup
908  if (BOOL_VAL(where & MW_POPUP)) {
909  /* Popups are usually not shown if player is under AI control.
910  * Server operator messages are shown always. */
911  if (nullptr == client.conn.playing || is_human(client.conn.playing)
912  || event == E_MESSAGE_WALL) {
913  popup_notify_goto_dialog(_("Message"), plain_text, tags, ptile);
914  shown = true;
915  } else {
916  /* Force to chatline so it will be visible somewhere at least.
917  * Messages window may still handle this so chatline is not needed
918  * after all. */
919  fallback_needed = true;
920  }
921  }
922 
923  // Message window
924  if (BOOL_VAL(where & MW_MESSAGES)) {
925  // When the game isn't running, the messages dialog isn't present.
926  if (C_S_RUNNING <= client_state()) {
927  meswin_add(plain_text, tags, ptile, event, turn, phase);
928  shown = true;
929  } else {
930  // Force to chatline instead.
931  fallback_needed = true;
932  }
933  }
934 
935  // Chatline
936  if (BOOL_VAL(where & MW_OUTPUT) || (fallback_needed && !shown)) {
937  output_window_event(plain_text, tags);
938  }
939 
940  if (turn == game.info.turn) {
942  }
943 
944  // Free tags
945  text_tag_list_destroy(tags);
946 }
947 
952 void create_event(struct tile *ptile, enum event_type event,
953  const struct ft_color color, const char *format, ...)
954 {
955  va_list ap;
956  char message[MAX_LEN_MSG];
957 
958  va_start(ap, format);
959  fc_vsnprintf(message, sizeof(message), format, ap);
960  va_end(ap);
961 
962  if (ft_color_requested(color)) {
963  char colored_text[MAX_LEN_MSG];
964 
965  featured_text_apply_tag(message, colored_text, sizeof(colored_text),
967  handle_event(colored_text, ptile, event, game.info.turn, game.info.phase,
968  -1);
969  } else {
970  handle_event(message, ptile, event, game.info.turn, game.info.phase, -1);
971  }
972 }
973 
980 struct city *get_nearest_city(const struct unit *punit, int *sq_dist)
981 {
982  struct city *pcity_near = tile_city(unit_tile(punit));
983  int pcity_near_dist;
984 
985  if (pcity_near) {
986  pcity_near_dist = 0;
987  } else {
988  pcity_near = nullptr;
989  pcity_near_dist = -1;
990  players_iterate(pplayer)
991  {
992  city_list_iterate(pplayer->cities, pcity_current)
993  {
994  int dist = sq_map_distance(pcity_current->tile, unit_tile(punit));
995  if (pcity_near_dist == -1 || dist < pcity_near_dist
996  || (dist == pcity_near_dist
997  && unit_owner(punit) == city_owner(pcity_current))) {
998  pcity_near = pcity_current;
999  pcity_near_dist = dist;
1000  }
1001  }
1003  }
1005  }
1006 
1007  if (sq_dist) {
1008  *sq_dist = pcity_near_dist;
1009  }
1010 
1011  return pcity_near;
1012 }
1013 
1019 void cityrep_buy(struct city *pcity)
1020 {
1021  int value;
1022 
1023  if (city_production_has_flag(pcity, IF_GOLD)) {
1024  create_event(
1025  pcity->tile, E_BAD_COMMAND, ftc_client, _("You can't buy %s in %s!"),
1027  city_link(pcity));
1028  return;
1029  }
1030  value = pcity->client.buy_cost;
1031 
1032  if (city_owner(pcity)->economic.gold >= value) {
1033  city_buy_production(pcity);
1034  } else {
1035  // Split into two to allow localization of two pluralisations.
1036  char buf[MAX_LEN_MSG];
1037  /* TRANS: %s is a production type; this whole string is a sentence
1038  * fragment that is only ever included in one other string
1039  * (search comments for this string to find it) */
1040  fc_snprintf(buf, ARRAY_SIZE(buf),
1041  PL_("%s costs %d gold", "%s costs %d gold", value),
1042  city_production_name_translation(pcity), value);
1043  create_event(nullptr, E_BAD_COMMAND, ftc_client,
1044  /* TRANS: %s is a pre-pluralised sentence fragment:
1045  * "%s costs %d gold" */
1046  PL_("%s and you only have %d gold.",
1047  "%s and you only have %d gold.",
1048  city_owner(pcity)->economic.gold),
1049  buf, city_owner(pcity)->economic.gold);
1050  }
1051 }
1052 
1056 bool can_units_do_connect(const std::vector<unit *> &units,
1057  enum unit_activity activity,
1058  struct extra_type *tgt)
1059 {
1060  return std::any_of(units.begin(), units.end(), [&](const auto unit) {
1061  return can_unit_do_connect(unit, activity, tgt);
1062  });
1063 }
1064 
1070 {
1071  // A double init would cause a leak.
1072  fc_assert_ret(punit->client.act_prob_cache == nullptr);
1073 
1074  punit->client.act_prob_cache = new act_prob[NUM_ACTIONS]();
1075 }
1076 
1080 void unit_focus_set_status(struct player *pplayer)
1081 {
1082  unit_list_iterate(pplayer->units, punit)
1083  {
1084  punit->client.focus_status = FOCUS_AVAIL;
1085  }
1087 }
1088 
1092 void client_player_init(struct player *pplayer)
1093 {
1095  {
1096  pplayer->client.tile_vision[v] = new QBitArray();
1097  }
1099 }
1100 
1105 {
1106  players_iterate(pplayer)
1107  {
1108  int new_size;
1109 
1110  if (pplayer == client.conn.playing) {
1111  new_size = MAP_INDEX_SIZE;
1112  } else {
1113  /* We don't need (or have) information about players other
1114  * than user of the client. Allocate just one bit as that's
1115  * the minimum bitvector size (cannot allocate 0 bits)*/
1116  new_size = 1;
1117  }
1118 
1120  {
1121  pplayer->client.tile_vision[v]->resize(new_size);
1122  }
1124 
1125  pplayer->tile_known->resize(new_size);
1126  }
1128 }
1129 
1134 {
1135  char str[MAX_LEN_MAPDEF];
1136  char mi_map[MAPIMG_LAYER_COUNT + 1];
1137  enum mapimg_layer layer;
1138  int map_pos = 0;
1139 
1140  // Only one definition allowed.
1141  while (mapimg_count() != 0) {
1142  mapimg_delete(0);
1143  }
1144 
1145  // Map image definition: zoom, turns
1146  fc_snprintf(str, sizeof(str), "zoom=%d:turns=0:format=%s",
1148 
1149  // Map image definition: show
1150  if (client_is_global_observer()) {
1151  cat_snprintf(str, sizeof(str), ":show=all");
1152  // use all available knowledge
1153  gui_options->mapimg_layer[MAPIMG_LAYER_KNOWLEDGE] = false;
1154  } else {
1155  cat_snprintf(str, sizeof(str), ":show=plrid:plrid=%d",
1157  // use only player knowledge
1158  gui_options->mapimg_layer[MAPIMG_LAYER_KNOWLEDGE] = true;
1159  }
1160 
1161  // Map image definition: map
1162  for (layer = mapimg_layer_begin(); layer != mapimg_layer_end();
1163  layer = mapimg_layer_next(layer)) {
1164  if (gui_options->mapimg_layer[layer]) {
1165  mi_map[map_pos++] = mapimg_layer_name(layer)[0];
1166  }
1167  }
1168  mi_map[map_pos] = '\0';
1169 
1170  if (map_pos == 0) {
1171  // no value set - use dummy setting
1172  sz_strlcpy(mi_map, "-");
1173  }
1174  cat_snprintf(str, sizeof(str), ":map=%s", mi_map);
1175 
1176  log_debug("client map image definition: %s", str);
1177 
1178  if (!mapimg_define(str, false) || !mapimg_isvalid(0)) {
1179  /* An error in the definition string or an error validation the string.
1180  * The error message is available via mapimg_error(). */
1181  return false;
1182  }
1183 
1184  return true;
1185 }
1186 
1191 {
1192  if (client_state() < C_S_RUNNING) {
1193  return nullptr;
1194  }
1195 
1196  struct option *poption = optset_option_by_name(server_optset, "nationset");
1197  const char *setting_str;
1198 
1199  if (poption == nullptr || option_type(poption) != OT_STRING
1200  || (setting_str = option_str_get(poption)) == nullptr) {
1201  setting_str = "";
1202  }
1203  return nation_set_by_setting_value(setting_str);
1204 }
1205 
1211 enum ai_level server_ai_level()
1212 {
1213  enum ai_level lvl = static_cast<ai_level>(game.info.skill_level);
1214 
1215  players_iterate(pplayer)
1216  {
1217  if (is_ai(pplayer) && pplayer->ai_common.skill_level != lvl) {
1218  return ai_level_invalid();
1219  }
1220  }
1222 
1223  if (!is_settable_ai_level(lvl)) {
1224  return ai_level_invalid();
1225  }
1226 
1227  return lvl;
1228 }
#define NUM_ACTIONS
Definition: actions.h:224
void output_window_event(const char *plain_text, const struct text_tag_list *tags)
Add a line of text to the output ("chatline") window from server event.
bool can_city_build_unit_later(const struct city *pcity, const struct unit_type *punittype)
Returns whether player can eventually build given unit in the city; returns FALSE if unit can never p...
Definition: city.cpp:912
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
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Removes an improvement (and its effects) from a city.
Definition: city.cpp:3287
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
Definition: city.cpp:1095
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Return TRUE when the current production has this flag.
Definition: city.cpp:691
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Return whether given city can build given building; returns FALSE if the building is obsolete.
Definition: city.cpp:815
const char * city_name_get(const struct city *pcity)
Return the name of the city.
Definition: city.cpp:1077
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Return the extended name of the building.
Definition: city.cpp:635
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Return whether player can eventually build given building in the city; returns FALSE if improvement c...
Definition: city.cpp:832
const char * city_production_name_translation(const struct city *pcity)
Return the extended name of the current production.
Definition: city.cpp:672
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 cities_iterate_end
Definition: city.h:493
#define city_list_iterate(citylist, pcity)
Definition: city.h:482
#define cities_iterate(pcity)
Definition: city.h:486
@ CITIZEN_UNHAPPY
Definition: city.h:242
#define city_list_iterate_end
Definition: city.h:484
#define city_built_iterate(_pcity, _p)
Definition: city.h:752
#define city_built_iterate_end
Definition: city.h:759
struct city * is_any_city_dialog_open()
Definition: citydlg.cpp:2315
void popdown_city_dialog()
Closes the city overlay.
Definition: citydlg.cpp:2264
int city_buy_production(struct city *pcity)
Buy the current production item in a given city.
void refresh_city_dialog(struct city *pcity)
void city_report_dialog_update()
void center_on_tile(tile *tile, bool animate=true)
Centers the view on a tile.
Definition: view_map.cpp:197
map_view * mapview_wdg
Definition: page_game.h:81
enum client_states client_state()
Return current client state.
bool client_has_player()
Either controlling or observing.
bool client_is_global_observer()
Returns whether client is global observer.
struct player * client_player()
Either controlling or observing.
struct civclient client
bool client_is_observer()
Returns whether client is observer.
bool can_client_change_view()
Return TRUE if the client can change the view; i.e.
@ C_S_RUNNING
Definition: client_main.h:43
enum known_type client_tile_get_known(const struct tile *ptile)
A tile's "known" field is used by the server to store whether each player knows the tile.
Definition: climap.cpp:29
static int target_get_section(struct universal target)
Return the numerical "section" of an item.
Definition: climisc.cpp:548
const char * get_vision_status(const struct player *me, const struct player *them)
Return a string indicating one nation's shaed vision status with another.
Definition: climisc.cpp:194
int collect_eventually_buildable_targets(struct universal *targets, struct city *pcity, bool advanced_tech)
Collect the cids of all targets which can be build by this city or in general.
Definition: climisc.cpp:701
void client_player_maps_reset()
Reset the private maps of all players.
Definition: climisc.cpp:1104
bool city_unit_supported(const struct city *pcity, const struct universal *target)
Return TRUE if the city supports at least one unit of the given production type (returns FALSE if the...
Definition: climisc.cpp:497
cid cid_encode_building(const struct impr_type *pimprove)
Encode a CID for the target building.
Definition: climisc.cpp:467
void create_event(struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Creates a struct packet_generic_message packet and injects it via handle_chat_msg.
Definition: climisc.cpp:952
void client_player_init(struct player *pplayer)
Initialize a player on the client side.
Definition: climisc.cpp:1092
const QPixmap * client_government_sprite()
Return the sprite for the government indicator.
Definition: climisc.cpp:374
void client_remove_city(struct city *pcity)
Remove city, client end version.
Definition: climisc.cpp:134
void client_unit_init_act_prob_cache(struct unit *punit)
Initialize the action probability cache.
Definition: climisc.cpp:1069
void nuclear_winter_scaled(int *chance, int *rate, int max)
Return nuclear winter chance and rate of change, scaled to max.
Definition: climisc.cpp:308
bool mapimg_client_define()
Create a map image definition on the client.
Definition: climisc.cpp:1133
void flush_dirty_overview()
This module contains various general - mostly highlevel - functions used throughout the client.
const QPixmap * client_research_sprite()
Return the sprite for the research indicator.
Definition: climisc.cpp:317
void cityrep_buy(struct city *pcity)
Called when the "Buy" button is pressed in the city report for every selected city.
Definition: climisc.cpp:1019
void global_warming_scaled(int *chance, int *rate, int max)
Return global warming chance and rate of change, scaled to max.
Definition: climisc.cpp:299
struct nation_set * client_current_nation_set()
Returns the nation set in use.
Definition: climisc.cpp:1190
void name_and_sort_items(struct universal *targets, int num_targets, struct item *items, bool show_cost, struct city *pcity)
Takes an array of compound ids (cids).
Definition: climisc.cpp:596
static int fc_cmp(const void *p1, const void *p2)
Helper for name_and_sort_items().
Definition: climisc.cpp:572
cid cid_encode(struct universal target)
Encode a CID for the target production.
Definition: climisc.cpp:446
void client_remove_unit(struct unit *punit)
Remove unit, client end version.
Definition: climisc.cpp:69
bool can_units_do_connect(const std::vector< unit * > &units, enum unit_activity activity, struct extra_type *tgt)
Returns TRUE if any of the units can do the connect activity.
Definition: climisc.cpp:1056
bool city_building_present(const struct city *pcity, const struct universal *target)
A TestCityFunc to tell whether the item is a building and is present.
Definition: climisc.cpp:538
int collect_already_built_targets(struct universal *targets, struct city *pcity)
Collect the cids of all improvements which are built in the given city.
Definition: climisc.cpp:806
void center_on_something()
Find something sensible to display.
Definition: climisc.cpp:392
struct city * get_nearest_city(const struct unit *punit, int *sq_dist)
Find city nearest to given unit and optionally return squared city distance Parameter sq_dist may be ...
Definition: climisc.cpp:980
struct universal cid_decode(cid id)
Decode the CID into a city_production structure.
Definition: climisc.cpp:478
enum ai_level server_ai_level()
Returns the current AI skill level on the server, if the same level is currently used for all current...
Definition: climisc.cpp:1211
void unit_focus_set_status(struct player *pplayer)
Set focus status of all player units to FOCUS_AVAIL.
Definition: climisc.cpp:1080
void handle_event(const char *featured_text, struct tile *ptile, enum event_type event, int turn, int phase, int conn_id)
Handles a chat or event message.
Definition: climisc.cpp:827
cid cid_encode_unit(const struct unit_type *punittype)
Encode a CID for the target unit type.
Definition: climisc.cpp:456
void client_diplomacy_clause_string(char *buf, int bufsiz, struct Clause *pclause)
Copy a string that describes the given clause into the return buffer.
Definition: climisc.cpp:213
const QPixmap * client_warming_sprite()
Return the sprite for the global-warming indicator.
Definition: climisc.cpp:340
const QPixmap * client_cooling_sprite()
Return the sprite for the global-cooling indicator.
Definition: climisc.cpp:357
static void catastrophe_scaled(int *chance, int *rate, int max, int current, int accum, int level)
Return global catastrophe chance and rate of change, scaled to some maximum (e.g.
Definition: climisc.cpp:280
bool city_unit_present(const struct city *pcity, const struct universal *target)
Return TRUE if the city has present at least one unit of the given production type (returns FALSE if ...
Definition: climisc.cpp:518
const char * get_embassy_status(const struct player *me, const struct player *them)
Return a string indicating one nation's embassy status with another.
Definition: climisc.cpp:169
int collect_production_targets(struct universal *targets, struct city **selected_cities, int num_selected_cities, bool append_units, bool append_wonders, bool change_prod, TestCityFunc test_func)
Return possible production targets for the current player's cities.
Definition: climisc.cpp:648
int cid
Definition: climisc.h:21
bool(* TestCityFunc)(const struct city *, const struct universal *)
Definition: climisc.h:71
std::vector< unit * > & get_units_in_focus()
Returns list of units currently in focus.
Definition: control.cpp:169
int get_num_units_in_focus()
Return the number of units currently in focus (0 or more).
Definition: control.cpp:174
struct unit * get_focus_unit_on_tile(const struct tile *ptile)
Return TRUE iff a unit on this tile is in focus.
Definition: control.cpp:373
void unit_focus_advance()
This function may be called from packhand.c, via unit_focus_update(), as a result of packets indicati...
Definition: control.cpp:617
void control_unit_killed(struct unit *punit)
Called when a unit is killed; this removes it from the control lists.
Definition: control.cpp:212
struct unit * head_of_units_in_focus()
Return head of focus units list.
Definition: control.cpp:387
void popup_notify_goto_dialog(const char *headline, const char *lines, const struct text_tag_list *tags, struct tile *ptile)
Popup a dialog to display information about an event that has a specific location.
Definition: dialogs.cpp:944
enum event_type event
Definition: events.cpp:68
#define Q_(String)
Definition: fcintl.h:53
#define PL_(String1, String2, n)
Definition: fcintl.h:54
#define _(String)
Definition: fcintl.h:50
size_t featured_text_apply_tag(const char *text_source, char *featured_text, size_t featured_text_len, enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
Apply a tag to a text.
enum text_link_type text_tag_link_type(const struct text_tag *ptag)
Return the link target type suggested by this text tag.
size_t featured_text_to_plain_text(const char *featured_text, char *plain_text, size_t plain_text_len, struct text_tag_list **tags, bool replace_link_text)
Separate the text from the text features.
struct text_tag * text_tag_new(enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
Returns a new text_tag or nullptr on error.
const struct ft_color ftc_client
const char * city_link(const struct city *pcity)
Get a text link to a city.
int text_tag_link_id(const struct text_tag *ptag)
Return the link target id suggested by this text tag (city id, tile index or unit id).
#define text_tag_list_iterate_end
#define text_tag_list_iterate(tags, ptag)
#define FT_OFFSET_UNSET
Definition: featured_text.h:95
static bool ft_color_requested(const struct ft_color color)
text_tag_type
@ TTT_LINK
@ TTT_COLOR
struct civ_game game
Definition: game.cpp:47
struct world wld
Definition: game.cpp:48
void game_remove_unit(struct world *gworld, struct unit *punit)
In the server call wipe_unit(), and never this function directly.
Definition: game.cpp:120
void game_remove_city(struct world *gworld, struct city *pcity)
Remove city from game.
Definition: game.cpp:166
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
Definition: game.cpp:103
struct government * government_of_player(const struct player *pplayer)
Return the government of a player.
Definition: government.cpp:107
Government_type_id government_count()
Return the number of governments.
Definition: government.cpp:64
Impr_type_id improvement_count()
Return the number of improvements.
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...
bool can_player_build_improvement_now(const struct player *p, struct impr_type *pimprove)
Whether player can build given building somewhere immediately.
struct impr_type * improvement_by_number(const Impr_type_id id)
Returns the improvement type for the given index/ID.
Impr_type_id improvement_number(const struct impr_type *pimprove)
Return the improvement index.
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.
bool is_wonder(const struct impr_type *pimprove)
Returns whether improvement is some kind of wonder.
bool is_great_wonder(const struct impr_type *pimprove)
Is this building a great 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.
const char * improvement_name_translation(const struct impr_type *pimprove)
Return the (translated) name of the given improvement.
bool is_small_wonder(const struct impr_type *pimprove)
Is this building a small wonder?
#define improvement_iterate_end
Definition: improvement.h:199
#define improvement_iterate(_p)
Definition: improvement.h:193
#define B_LAST
Definition: improvement.h:33
const char * name
Definition: inputfile.cpp:118
#define fc_assert_ret(condition)
Definition: log.h:112
#define fc_assert(condition)
Definition: log.h:89
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
#define log_debug(message,...)
Definition: log.h:65
int sq_map_distance(const struct tile *tile0, const struct tile *tile1)
Return squared distance between two tiles.
Definition: map.cpp:610
int map_num_tiles()
Returns the total number of (real) positions (or tiles) on the map.
Definition: map.cpp:954
struct tile * native_pos_to_tile(const struct civ_map *nmap, int nat_x, int nat_y)
Return the tile for the given native position.
Definition: map.cpp:416
#define iterate_outward(nmap, start_tile, max_dist, itr_tile)
Definition: map.h:288
#define iterate_outward_end
Definition: map.h:291
#define MAP_INDEX_SIZE
Definition: map.h:91
int mapimg_count()
Return the number of map image definitions.
Definition: mapimg.cpp:420
struct mapdef * mapimg_isvalid(int id)
Check if a map image definition is valid.
Definition: mapimg.cpp:886
bool mapimg_define(const char *maparg, bool check)
Define on map image.
Definition: mapimg.cpp:590
bool mapimg_delete(int id)
Delete a map image definition.
Definition: mapimg.cpp:918
#define MAX_LEN_MAPDEF
Definition: mapimg.h:52
void update_unit_info_label(const std::vector< unit * > &unit_list)
Update the information label which gives info on the current unit and the tile under the current unit...
Definition: view_map.cpp:446
void meswin_add(const char *message, const struct text_tag_list *tags, struct tile *ptile, enum event_type event, int turn, int phase)
Add a message.
struct nation_type * nation_of_city(const struct city *pcity)
Return the nation of the player who owns the city.
Definition: nation.cpp:429
const char * nation_rule_name(const struct nation_type *pnation)
Return the (untranslated) rule name of the nation (adjective form).
Definition: nation.cpp:115
struct nation_set * nation_set_by_setting_value(const char *setting)
Returns the nation set that would be selected by the given value of the 'nationset' server setting.
Definition: nation.cpp:736
const char * nation_plural_for_player(const struct player *pplayer)
Return the (translated) plural noun of the given nation of a player.
Definition: nation.cpp:155
struct nation_type * nation_of_unit(const struct unit *punit)
Return the nation of the player who owns the unit.
Definition: nation.cpp:438
const struct option_set * server_optset
Definition: options.cpp:2430
const char * option_str_get(const struct option *poption)
Returns the current value of this string option.
Definition: options.cpp:553
client_options * gui_options
Definition: options.cpp:74
struct option * optset_option_by_name(const struct option_set *poptset, const char *name)
Returns the option corresponding of the name in this option set.
Definition: options.cpp:110
enum option_type option_type(const struct option *poption)
Returns the type of the option.
Definition: options.cpp:330
int messages_where[E_COUNT]
Message Options:
Definition: options.cpp:3383
#define MW_POPUP
Definition: options.h:317
#define MW_OUTPUT
Definition: options.h:315
#define MW_MESSAGES
Definition: options.h:316
#define MAX_LEN_MSG
Definition: packets.h:37
void play_sound_for_event(enum event_type type)
Plays sound associated with event.
Definition: packhand.cpp:1486
struct city_list * cities
Definition: packhand.cpp:122
pageGame * queen()
Return game instandce.
Definition: page_game.cpp:557
bool is_settable_ai_level(enum ai_level level)
Return is AI can be set to given level.
Definition: player.cpp:1825
int player_index(const struct player *pplayer)
Return the player index.
Definition: player.cpp:748
struct city * player_primary_capital(const struct player *pplayer)
Locate the player's primary capital city, (nullptr Otherwise)
Definition: player.cpp:1247
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
Definition: player.cpp:816
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Return TRUE iff the player can see units in the city.
Definition: player.cpp:1045
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Check if pplayer has an embassy with pplayer2.
Definition: player.cpp:195
bool gives_shared_vision(const struct player *me, const struct player *them)
Return TRUE iff the player me gives shared vision to player them.
Definition: player.cpp:1414
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
#define players_iterate(_pplayer)
Definition: player.h:514
#define is_ai(plr)
Definition: player.h:227
#define is_human(plr)
Definition: player.h:226
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
Definition: research.cpp:110
struct setting_list * level[OLEVELS_NUM]
Definition: settings.cpp:167
#define CLIP(lower, current, upper)
Definition: shared.h:51
#define DIVIDE(n, d)
Definition: shared.h:71
#define ARRAY_SIZE(x)
Definition: shared.h:79
#define BOOL_VAL(x)
Definition: shared.h:63
#define MAX(x, y)
Definition: shared.h:48
enum clause_type type
Definition: diptreaty.h:64
struct player * from
Definition: diptreaty.h:65
int value
Definition: diptreaty.h:66
Definition: city.h:291
struct city::@15::@18 client
int id
Definition: city.h:296
struct universal production
Definition: city.h:368
struct tile * tile
Definition: city.h:293
struct unit_list * units_supported
Definition: city.h:377
struct packet_game_info info
Definition: game.h:80
int xsize
Definition: map_types.h:73
int ysize
Definition: map_types.h:73
struct connection conn
Definition: client_main.h:89
bool mapimg_layer[MAPIMG_LAYER_COUNT]
Definition: options.h:152
struct ft_color highlight_our_names
Definition: options.h:104
int mapimg_zoom
Definition: options.h:151
char mapimg_format[64]
Definition: options.h:150
struct player * playing
Definition: connection.h:142
char username[MAX_LEN_NAME]
Definition: connection.h:151
int build_cost
Definition: improvement.h:68
Definition: climisc.h:66
struct universal item
Definition: climisc.h:67
char descr[MAX_LEN_NAME+40]
Definition: climisc.h:68
Functions for handling the nations.
Definition: nation.cpp:33
The base class for options.
Definition: options.cpp:209
Definition: player.h:231
struct city_list * cities
Definition: player.h:263
struct player::@65::@68 client
struct unit_list * units
Definition: player.h:264
bool is_alive
Definition: player.h:250
Tech_type_id researching
Definition: research.h:45
struct research::@71::@73 client
int bulbs_researched
Definition: research.h:46
struct text_tag::@23::@25 color
Definition: tile.h:42
struct unit_list * units
Definition: tile.h:50
Definition: unit.h:134
struct unit::@76::@78 client
int id
Definition: unit.h:141
int homecity
Definition: unit.h:142
enum universals_n kind
Definition: fc_types.h:740
universals_u value
Definition: fc_types.h:739
struct civ_map map
Definition: world_object.h:21
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
Definition: support.cpp:537
size_t fc_strlcpy(char *dest, const char *src, size_t n)
fc_strlcpy() provides utf-8 version of (non-standard) function strlcpy() It is intended as more user-...
Definition: support.cpp:412
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
Definition: support.cpp:89
int cat_snprintf(char *str, size_t n, const char *format,...)
cat_snprintf is like a combination of fc_snprintf and fc_strlcat; it does snprintf to the end of an e...
Definition: support.cpp:564
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
Definition: support.cpp:512
int fc_strncasecmp(const char *str0, const char *str1, size_t n)
Compare strings like strncmp(), but ignoring case.
Definition: support.cpp:100
#define sz_strlcpy(dest, src)
Definition: support.h:140
struct advance * advance_by_number(const Tech_type_id atype)
Return the advance for the given advance index.
Definition: tech.cpp:94
const char * advance_name_translation(const struct advance *padvance)
Return the (translated) name of the given advance/technology.
Definition: tech.cpp:274
#define A_UNSET
Definition: tech.h:41
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
Definition: tile.cpp:72
@ TILE_UNKNOWN
Definition: tile.h:29
#define TILE_XY(ptile)
Definition: tile.h:36
const QPixmap * get_citizen_sprite(const struct tileset *t, enum citizen_category type, int citizen_index, const struct city *pcity)
Return a sprite for the given citizen.
Definition: tilespec.cpp:3337
const QPixmap * get_indicator_sprite(const struct tileset *t, enum indicator_type indicator, int idx)
Returns a sprite for the given indicator with the given index.
Definition: tilespec.cpp:3566
const QPixmap * get_government_sprite(const struct tileset *t, const struct government *gov)
Return the sprite for the government.
Definition: tilespec.cpp:3404
@ INDICATOR_COOLING
Definition: tilespec.h:174
@ INDICATOR_WARMING
Definition: tilespec.h:173
@ INDICATOR_BULB
Definition: tilespec.h:172
#define NUM_TILES_PROGRESS
Definition: tilespec.h:43
const struct unit_type * utype
Definition: fc_types.h:585
const struct impr_type * building
Definition: fc_types.h:579
int get_transporter_occupancy(const struct unit *ptrans)
Return how many units are in the transport.
Definition: unit.cpp:1647
bool unit_transport_unload(struct unit *pcargo)
Unload pcargo from ptrans.
Definition: unit.cpp:2144
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
Returns the list of cargo units.
Definition: unit.cpp:2199
#define unit_tile(_pu)
Definition: unit.h:371
@ FOCUS_AVAIL
Definition: unit.h:46
#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
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
Definition: unittype.cpp:114
struct unit_type * utype_by_number(const Unit_type_id id)
Return a pointer for the unit type struct for the given unit type id.
Definition: unittype.cpp:103
const char * utype_values_translation(const struct unit_type *punittype)
Return string with translated unit name and list of its values.
Definition: unittype.cpp:1310
int utype_build_shield_cost(const struct city *pcity, const struct unit_type *punittype)
Returns the number of shields it takes to build this unit type.
Definition: unittype.cpp:1141
Unit_type_id utype_count()
Return the number of unit types.
Definition: unittype.cpp:74
Unit_type_id utype_number(const struct unit_type *punittype)
Return the unit type index.
Definition: unittype.cpp:91
bool can_player_build_unit_later(const struct player *p, const struct unit_type *punittype)
Whether player can eventually build given unit somewhere – ie, returns TRUE if unit is available with...
Definition: unittype.cpp:1761
bool can_player_build_unit_now(const struct player *p, const struct unit_type *punittype)
Whether player can build given unit somewhere; returns FALSE if unit is obsolete.
Definition: unittype.cpp:1742
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition: unittype.h:584
#define unit_type_iterate(_p)
Definition: unittype.h:785
#define unit_type_iterate_end
Definition: unittype.h:791
void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile, bool full_refresh)
Refreshes a single city on the map canvas.
void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile, bool full_refresh)
Refreshes a single unit on the map canvas.
void link_mark_add_new(enum text_link_type type, int id)
Add a visible link for 2 turns.
#define vision_layer_iterate(v)
Definition: vision.h:72
#define vision_layer_iterate_end
Definition: vision.h:77