Freeciv-3.2
Loading...
Searching...
No Matches
player.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "fcintl.h"
20#include "log.h"
21#include "mem.h"
22#include "shared.h"
23#include "support.h"
24
25/* common */
26#include "ai.h"
27#include "city.h"
28#include "fc_interface.h"
29#include "featured_text.h"
30#include "game.h"
31#include "government.h"
32#include "idex.h"
33#include "improvement.h"
34#include "map.h"
35#include "nation.h"
36#include "research.h"
37#include "rgbcolor.h"
38#include "tech.h"
39#include "unit.h"
40#include "unitlist.h"
41#include "vision.h"
42
43#include "player.h"
44
45
47 struct player *player;
48};
49
50static struct {
52 int used_slots; /* number of used/allocated players in the player slots */
54
55static void player_defaults(struct player *pplayer);
56
57static void player_diplstate_new(const struct player *plr1,
58 const struct player *plr2);
59static void player_diplstate_defaults(const struct player *plr1,
60 const struct player *plr2);
61static void player_diplstate_destroy(const struct player *plr1,
62 const struct player *plr2);
63
64/*******************************************************************/
69{
70 switch (oldstate) {
71 case DS_WAR: /* no change */
72 case DS_ARMISTICE:
73 case DS_CEASEFIRE:
74 case DS_PEACE:
75 return DS_WAR;
76 case DS_ALLIANCE:
77 return DS_ARMISTICE;
78 case DS_TEAM: /* no change */
79 return DS_TEAM;
80 case DS_NO_CONTACT: /* Possible if someone declares war on our ally */
81 return DS_NO_CONTACT; /* Can't cancel lack of contact */
82 case DS_LAST:
84 return DS_WAR; /* Arbitrary */
85 }
86
88
89 return DS_WAR; /* Arbitrary */
90}
91
92/*******************************************************************/
99 const struct player *p2)
100{
102
103 if (p1 == p2 || ds == DS_WAR || ds == DS_NO_CONTACT) {
104 return DIPL_ERROR;
105 }
106 if (players_on_same_team(p1, p2)) {
107 return DIPL_ERROR;
108 }
109 if (!p1->is_alive || !p2->is_alive) {
110 return DIPL_ERROR;
111 }
112 if (player_diplstate_get(p1, p2)->has_reason_to_cancel == 0
116 }
117
118 return DIPL_OK;
119}
120
121/*******************************************************************/
132static bool is_valid_alliance(const struct player *p1,
133 const struct player *p2)
134{
135 players_iterate_alive(pplayer) {
136 enum diplstate_type ds = player_diplstate_get(p1, pplayer)->type;
137
138 if (pplayer != p1
139 && pplayer != p2
140 && ds == DS_WAR /* Do not count 'never met' as war here */
141 && pplayers_allied(p2, pplayer)) {
142 return FALSE;
143 }
145
146 return TRUE;
147}
148
149/*******************************************************************/
160 const struct player *p2,
161 enum diplstate_type treaty)
162{
164
165 if (players_on_same_team(p1, p2)) {
166 /* This includes the case p1 == p2 */
167 return DIPL_ERROR;
168 }
171 return DIPL_ERROR;
172 }
173 if (treaty == DS_WAR
174 || treaty == DS_NO_CONTACT
175 || treaty == DS_ARMISTICE
176 || treaty == DS_TEAM
177 || treaty == DS_LAST) {
178 return DIPL_ERROR; /* These are not negotiable treaties */
179 }
180 if (treaty == DS_CEASEFIRE && existing != DS_WAR) {
181 return DIPL_ERROR; /* Only available from war */
182 }
183 if (treaty == DS_PEACE
184 && (existing != DS_WAR && existing != DS_CEASEFIRE)) {
185 return DIPL_ERROR;
186 }
187 if (treaty == DS_ALLIANCE) {
188 if (!is_valid_alliance(p1, p2)) {
189 /* Our war with a third party prevents entry to alliance. */
191 } else if (!is_valid_alliance(p2, p1)) {
192 /* Their war with a third party prevents entry to alliance. */
194 }
195 }
196 /* This check must be last: */
197 if (treaty == existing) {
198 return DIPL_ERROR;
199 }
200
201 return DIPL_OK;
202}
203
204/*******************************************************************/
208bool player_has_embassy(const struct player *pplayer,
209 const struct player *pplayer2)
210{
211 return (pplayer == pplayer2
214}
215
216/*******************************************************************/
220bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
221{
222 if (tgt_player->team == pteam) {
223 return TRUE;
224 }
225
229 return TRUE;
230 }
232
233 return FALSE;
234}
235
236/*******************************************************************/
240bool player_has_real_embassy(const struct player *pplayer,
241 const struct player *pplayer2)
242{
243 return BV_ISSET(pplayer->real_embassy, player_index(pplayer2));
244}
245
246/*******************************************************************/
250bool player_has_embassy_from_effect(const struct player *pplayer,
251 const struct player *pplayer2)
252{
253 return (get_player_bonus(pplayer, EFT_HAVE_EMBASSIES) > 0
256}
257
258/*******************************************************************/
261bool player_owns_city(const struct player *pplayer, const struct city *pcity)
262{
263 return (pcity && pplayer && city_owner(pcity) == pplayer);
264}
265
266/*******************************************************************/
270bool player_can_invade_tile(const struct player *pplayer,
271 const struct tile *ptile)
272{
273 const struct player *ptile_owner = tile_owner(ptile);
274
275 return (!ptile_owner
276 || ptile_owner == pplayer
278 || !players_non_invade(pplayer, ptile_owner));
279}
280
281/*******************************************************************/
285static void player_diplstate_new(const struct player *plr1,
286 const struct player *plr2)
287{
289
290 fc_assert_ret(plr1 != NULL);
291 fc_assert_ret(plr2 != NULL);
292
293 const struct player_diplstate **diplstate_slot
294 = plr1->diplstates + player_index(plr2);
295
297
298 diplstate = fc_calloc(1, sizeof(*diplstate));
300}
301
302/*******************************************************************/
305static void player_diplstate_defaults(const struct player *plr1,
306 const struct player *plr2)
307{
308 struct player_diplstate *diplstate = player_diplstate_get(plr1, plr2);
309
311
312 diplstate->type = DS_NO_CONTACT;
313 diplstate->max_state = DS_NO_CONTACT;
314 diplstate->first_contact_turn = 0;
315 diplstate->turns_left = 0;
316 diplstate->has_reason_to_cancel = 0;
317 diplstate->contact_turns_left = 0;
318 diplstate->auto_cancel_turn = -1;
319}
320
321/*******************************************************************/
325 const struct player *plr2)
326{
327 fc_assert_ret_val(plr1 != NULL, NULL);
328 fc_assert_ret_val(plr2 != NULL, NULL);
329
330 const struct player_diplstate **diplstate_slot
331 = plr1->diplstates + player_index(plr2);
332
334
335 return (struct player_diplstate *) *diplstate_slot;
336}
337
338/*******************************************************************/
341static void player_diplstate_destroy(const struct player *plr1,
342 const struct player *plr2)
343{
344 fc_assert_ret(plr1 != NULL);
345 fc_assert_ret(plr2 != NULL);
346
347 const struct player_diplstate **diplstate_slot
348 = plr1->diplstates + player_index(plr2);
349
350 if (*diplstate_slot != NULL) {
351 free(player_diplstate_get(plr1, plr2));
352 }
353
355}
356
357/*******************************************************************/
361{
362 int i;
363
364 /* Init player slots. */
366 sizeof(*player_slots.slots));
367 /* Can't use the defined functions as the needed data will be
368 * defined here. */
369 for (i = 0; i < player_slot_count(); i++) {
370 player_slots.slots[i].player = NULL;
371 }
372 player_slots.used_slots = 0;
373}
374
375/*******************************************************************/
379{
380 return (player_slots.slots != NULL);
381}
382
383/*******************************************************************/
387{
388 players_iterate(pplayer) {
389 player_destroy(pplayer);
391 free(player_slots.slots);
392 player_slots.slots = NULL;
393 player_slots.used_slots = 0;
394}
395
396/*******************************************************************/
400{
401 return player_slots.slots;
402}
403
404/*******************************************************************/
408{
409 pslot++;
410 return (pslot < player_slots.slots + player_slot_count() ? pslot : NULL);
411}
412
413/*******************************************************************/
419{
420 return (MAX_NUM_PLAYER_SLOTS);
421}
422
423/*******************************************************************/
426int player_slot_index(const struct player_slot *pslot)
427{
428 fc_assert_ret_val(NULL != pslot, -1);
429
430 return pslot - player_slots.slots;
431}
432
433/*******************************************************************/
437struct player *player_slot_get_player(const struct player_slot *pslot)
438{
439 fc_assert_ret_val(NULL != pslot, NULL);
440
441 return pslot->player;
442}
443
444/*******************************************************************/
448bool player_slot_is_used(const struct player_slot *pslot)
449{
450 fc_assert_ret_val(NULL != pslot, FALSE);
451
452 /* No player slot available, if the game is not initialised. */
454 return FALSE;
455 }
456
457 return NULL != pslot->player;
458}
459
460/*******************************************************************/
463struct player_slot *player_slot_by_number(int player_id)
464{
466 || !(0 <= player_id && player_id < player_slot_count())) {
467 return NULL;
468 }
469
470 return player_slots.slots + player_id;
471}
472
473/*******************************************************************/
477{
478 int max_pslot = 0;
479
480 player_slots_iterate(pslot) {
481 if (player_slot_is_used(pslot)) {
483 }
485
486 return max_pslot;
487}
488
489/*******************************************************************/
493struct player *player_new(struct player_slot *pslot)
494{
495 struct player *pplayer;
496
498
499 if (pslot == NULL) {
502 pslot = aslot;
503 break;
504 }
506
507 if (pslot == NULL) {
508 return NULL;
509 }
510 } else if (NULL != pslot->player) {
511 return pslot->player;
512 }
513
514 /* Now create the player. */
515 log_debug("Create player for slot %d.", player_slot_index(pslot));
516 pplayer = fc_calloc(1, sizeof(*pplayer));
517 pplayer->slot = pslot;
518 pslot->player = pplayer;
519
521 sizeof(*pplayer->diplstates));
523 const struct player_diplstate **diplstate_slot
524 = pplayer->diplstates + player_slot_index(dslot);
525
528
530 /* Create diplomatic states for all other players. */
532 /* Create diplomatic state of this player. */
533 if (aplayer != pplayer) {
535 }
537
538 /* Set default values. */
539 player_defaults(pplayer);
540
541 /* Increase number of players. */
542 player_slots.used_slots++;
543
544 return pplayer;
545}
546
547/*******************************************************************/
551static void player_defaults(struct player *pplayer)
552{
553 int i;
554
557 pplayer->unassigned_user = TRUE;
559 pplayer->unassigned_ranked = TRUE;
560 pplayer->user_turns = 0;
561 pplayer->is_male = TRUE;
562 pplayer->government = NULL;
563 pplayer->target_government = NULL;
564 pplayer->nation = NO_NATION_SELECTED;
565 pplayer->team = NULL;
566 pplayer->is_ready = FALSE;
567 pplayer->nturns_idle = 0;
568 pplayer->is_alive = TRUE;
569 pplayer->turns_alive = 0;
570 pplayer->is_winner = FALSE;
571 pplayer->last_war_action = -1;
572 pplayer->phase_done = FALSE;
573
574 pplayer->revolution_finishes = -1;
575 pplayer->primary_capital_id = 0;
576
577 BV_CLR_ALL(pplayer->real_embassy);
579 /* create diplomatic states for all other players */
581 /* create diplomatic state of this player */
582 if (aplayer != pplayer) {
584 }
586
587 pplayer->style = 0;
588 pplayer->music_style = -1; /* even getting value 0 triggers change */
589 pplayer->cities = city_list_new();
590 pplayer->units = unit_list_new();
591
592 pplayer->economic.gold = 0;
596 pplayer->economic.infra_points = 0;
597
598 spaceship_init(&pplayer->spaceship);
599
600 BV_CLR_ALL(pplayer->flags);
601
602 set_as_human(pplayer);
604 pplayer->ai_common.fuzzy = 0;
605 pplayer->ai_common.expand = 100;
607 player_slots_iterate(pslot) {
608 pplayer->ai_common.love[player_slot_index(pslot)] = 1;
610 pplayer->ai_common.traits = NULL;
611
612 pplayer->ai = NULL;
613 pplayer->was_created = FALSE;
614 pplayer->savegame_ai_type_name = NULL;
615 pplayer->random_name = TRUE;
616 pplayer->is_connected = FALSE;
617 pplayer->current_conn = NULL;
618 pplayer->connections = conn_list_new();
619 pplayer->autoselect_weight = -1;
622 for (i = 0; i < B_LAST; i++) {
623 pplayer->wonders[i] = WONDER_NOT_BUILT;
624 }
625
626 pplayer->attribute_block.data = NULL;
627 pplayer->attribute_block.length = 0;
629 pplayer->attribute_block_buffer.length = 0;
630
631 pplayer->tile_known.vec = NULL;
632 pplayer->tile_known.bits = 0;
633
634 pplayer->rgb = NULL;
635
636 memset(pplayer->multipliers, 0, sizeof(pplayer->multipliers));
637
638 /* pplayer->server is initialised in
639 ./server/plrhand.c:server_player_init()
640 and pplayer->client in
641 ./client/climisc.c:client_player_init() */
642}
643
644/*******************************************************************/
648void player_set_color(struct player *pplayer,
649 const struct rgbcolor *prgbcolor)
650{
651 if (pplayer->rgb != NULL) {
652 rgbcolor_destroy(pplayer->rgb);
653 pplayer->rgb = NULL;
654 }
655
656 if (prgbcolor) {
657 pplayer->rgb = rgbcolor_copy(prgbcolor);
658 }
659}
660
661/*******************************************************************/
669void player_clear(struct player *pplayer, bool full)
670{
671 bool client = !is_server();
672
673 if (pplayer == NULL) {
674 return;
675 }
676
677 if (pplayer->savegame_ai_type_name != NULL) {
678 free(pplayer->savegame_ai_type_name);
679 pplayer->savegame_ai_type_name = NULL;
680 }
681
682 /* Clears the attribute blocks. */
683 if (pplayer->attribute_block.data) {
684 free(pplayer->attribute_block.data);
685 pplayer->attribute_block.data = NULL;
686 }
687 pplayer->attribute_block.length = 0;
688
689 if (pplayer->attribute_block_buffer.data) {
692 }
693 pplayer->attribute_block_buffer.length = 0;
694
695 /* Clears units and cities. */
696 unit_list_iterate(pplayer->units, punit) {
697 /* Unload all cargos. */
700 if (client) {
701 pcargo->client.transported_by = -1;
702 }
704 /* Unload the unit. */
706 if (client) {
708 }
709
712
713 city_list_iterate(pplayer->cities, pcity) {
714 if (fc_funcs->destroy_city != NULL) {
715 fc_funcs->destroy_city(pcity);
716 } else {
717 game_remove_city(&wld, pcity);
718 }
720
721 if (full) {
722 team_remove_player(pplayer);
723
725 unit_list_iterate(owner->units, owned) {
726 if (unit_nationality(owned) == pplayer) {
727 /* Switch nationality to that of current owner. */
728 owned->nationality = owner;
729 }
732
733 /* This comes last because log calls in the above functions
734 * may use it. */
735 if (pplayer->nation != NULL) {
736 player_set_nation(pplayer, NULL);
737 }
738 }
739}
740
741/*******************************************************************/
745void player_ruleset_close(struct player *pplayer)
746{
747 pplayer->government = NULL;
748 pplayer->target_government = NULL;
749 player_set_nation(pplayer, NULL);
750 pplayer->style = NULL;
751}
752
753/*******************************************************************/
756void player_destroy(struct player *pplayer)
757{
758 struct player_slot *pslot;
759
760 fc_assert_ret(NULL != pplayer);
761
762 pslot = pplayer->slot;
763 fc_assert(pslot->player == pplayer);
764
765 /* Remove all that is game-dependent in the player structure. */
766 player_clear(pplayer, TRUE);
767
768 fc_assert(0 == unit_list_size(pplayer->units));
769 unit_list_destroy(pplayer->units);
770 fc_assert(0 == city_list_size(pplayer->cities));
771 city_list_destroy(pplayer->cities);
772
773 fc_assert(conn_list_size(pplayer->connections) == 0);
775
777 /* Destroy the diplomatic states of this player with others ... */
779 /* ...and of others with this player. */
780 if (aplayer != pplayer) {
782
783 /* Check if any cities of the other player have been founded
784 * by the removed player. */
785 city_list_iterate(aplayer->cities, pcity) {
786 if (pcity->original == pplayer) {
787 /* Unknown origin is better than giving baseless
788 * benefits to current owner */
789 pcity->original = NULL;
790 }
792 }
794 free(pplayer->diplstates);
795
796 /* Clear player color. */
797 if (pplayer->rgb) {
798 rgbcolor_destroy(pplayer->rgb);
799 }
800
801 dbv_free(&pplayer->tile_known);
802
803 if (!is_server()) {
805 dbv_free(&pplayer->client.tile_vision[v]);
807 }
808
809 free(pplayer);
810 pslot->player = NULL;
811 player_slots.used_slots--;
812}
813
814/*******************************************************************/
818{
819 return player_slots.used_slots;
820}
821
822/*******************************************************************/
829int player_index(const struct player *pplayer)
830{
831 return player_number(pplayer);
832}
833
834/*******************************************************************/
837int player_number(const struct player *pplayer)
838{
839 fc_assert_ret_val(NULL != pplayer, -1);
840 return player_slot_index(pplayer->slot);
841}
842
843/*******************************************************************/
849struct player *player_by_number(const int player_id)
850{
851 struct player_slot *pslot = player_slot_by_number(player_id);
852
853 return (NULL != pslot ? player_slot_get_player(pslot) : NULL);
854}
855
856/*******************************************************************/
861bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
862{
863 if (pplayer->nation != pnation) {
864 if (pplayer->nation) {
865 fc_assert(pplayer->nation->player == pplayer);
866 pplayer->nation->player = NULL;
867 }
868 if (pnation) {
869 fc_assert(pnation->player == NULL);
870 pnation->player = pplayer;
871 }
872 pplayer->nation = pnation;
873 return TRUE;
874 }
875 return FALSE;
876}
877
878/*******************************************************************/
881struct player *player_by_name(const char *name)
882{
883 players_iterate(pplayer) {
884 if (fc_strcasecmp(name, pplayer->name) == 0) {
885 return pplayer;
886 }
888
889 return NULL;
890}
891
892/*******************************************************************/
895const char *player_name(const struct player *pplayer)
896{
897 if (!pplayer) {
898 return NULL;
899 }
900 return pplayer->name;
901}
902
903/*******************************************************************/
909static const char *player_name_by_number(int i)
910{
911 struct player *pplayer;
912
913 pplayer = player_by_number(i);
914 return player_name(pplayer);
915}
916
917/*******************************************************************/
921 enum m_pre_result *result)
922{
923 int ind;
924
928 name, &ind);
929
930 if (*result < M_PRE_AMBIGUOUS) {
931 return player_by_number(ind);
932 } else {
933 return NULL;
934 }
935}
936
937/*******************************************************************/
940struct player *player_by_user(const char *name)
941{
942 players_iterate(pplayer) {
943 if (fc_strcasecmp(name, pplayer->username) == 0) {
944 return pplayer;
945 }
947
948 return NULL;
949}
950
951/*******************************************************************/
954int player_age(const struct player *pplayer)
955{
956 fc_assert_ret_val(pplayer != NULL, 0);
957 return pplayer->turns_alive;
958}
959
960/*******************************************************************/
968 const struct tile *ptile)
969{
970 /* Can't see invisible units. */
971 if (!fc_funcs->player_tile_vision_get(ptile, pplayer, V_INVIS)
972 || !fc_funcs->player_tile_vision_get(ptile, pplayer, V_SUBSURFACE)) {
973 return FALSE;
974 }
975
976 /* Units within some extras may be hidden. */
977 if (!pplayers_allied(pplayer, ptile->extras_owner)) {
979 if (tile_has_extra(ptile, pextra)) {
980 return FALSE;
981 }
983 }
984
985 return TRUE;
986}
987
988/*******************************************************************/
993bool can_player_see_hypotetic_units_at(const struct player *pplayer,
994 const struct tile *ptile)
995{
996 struct city *pcity;
997
998 if (!player_can_trust_tile_has_no_units(pplayer, ptile)) {
999 /* The existence of any units at all is hidden from the player. */
1000 return FALSE;
1001 }
1002
1003 /* Can't see city units. */
1004 pcity = tile_city(ptile);
1005 if (pcity && !can_player_see_units_in_city(pplayer, pcity)
1006 && unit_list_size(ptile->units) > 0) {
1007 return FALSE;
1008 }
1009
1010 /* Can't see non-allied units in transports. */
1011 unit_list_iterate(ptile->units, punit) {
1012 if (unit_type_get(punit)->transport_capacity > 0
1013 && unit_owner(punit) != pplayer) {
1014
1015 /* An ally could transport a non ally */
1016 if (unit_list_size(punit->transporting) > 0) {
1017 return FALSE;
1018 }
1019 }
1021
1022 return TRUE;
1023}
1024
1025/*******************************************************************/
1034bool can_player_see_unit_at(const struct player *pplayer,
1035 const struct unit *punit,
1036 const struct tile *ptile,
1037 bool is_transported)
1038{
1039 struct city *pcity;
1040 bool allied;
1041 struct unit_class *pclass;
1042
1043 /* If the player can't even see the tile... */
1044 if (TILE_KNOWN_SEEN != tile_get_known(ptile, pplayer)) {
1045 return FALSE;
1046 }
1047
1048 /* Don't show non-allied units that are in transports. This is logical
1049 * because allied transports can also contain our units. Shared vision
1050 * isn't taken into account. */
1052 if (is_transported && !allied) {
1053 return FALSE;
1054 }
1055
1056 /* Units in cities may be hidden. */
1057 pcity = tile_city(ptile);
1058 if (pcity && !can_player_see_units_in_city(pplayer, pcity)) {
1059 return FALSE;
1060 }
1061
1062 /* Allied units are always seen.
1063 * See also stealth unit hiding part in map_change_seen() */
1064 if (allied) {
1065 return TRUE;
1066 }
1067
1068 /* Units within some extras may be hidden. */
1070
1071 extra_type_list_iterate(pclass->cache.hiding_extras, pextra) {
1072 if (tile_has_extra(ptile, pextra)) {
1073 return FALSE;
1074 }
1076
1077 /* Non-hiding units are always seen.
1078 * See also stealth unit hiding part in map_change_seen() */
1079 if (!is_hiding_unit(punit)) {
1080 return TRUE;
1081 }
1082
1083 /* Hiding units are only seen by the V_INVIS fog layer. */
1084 return fc_funcs->player_tile_vision_get(ptile, pplayer,
1085 unit_type_get(punit)->vlayer);
1086}
1087
1088/**********************************************************************/
1091bool can_player_see_tile(const struct player *plr,
1092 const struct tile *ptile)
1093{
1094 return plr != nullptr
1095 && ptile != nullptr
1096 && (tile_get_known(ptile, plr) == TILE_KNOWN_SEEN);
1097}
1098
1099/*******************************************************************/
1104bool can_player_see_unit(const struct player *pplayer,
1105 const struct unit *punit)
1106{
1107 return can_player_see_unit_at(pplayer, punit, unit_tile(punit),
1109}
1110
1111/*******************************************************************/
1133bool can_player_see_units_in_city(const struct player *pplayer,
1134 const struct city *pcity)
1135{
1136 return (!pplayer
1137 || can_player_see_city_internals(pplayer, pcity)
1138 || pplayers_allied(pplayer, city_owner(pcity)));
1139}
1140
1141/*******************************************************************/
1149bool can_player_see_city_internals(const struct player *pplayer,
1150 const struct city *pcity)
1151{
1152 return (!pplayer || pplayer == city_owner(pcity));
1153}
1154
1155/*******************************************************************/
1165 const struct city *target_city)
1166{
1169
1171 /* City internals includes city externals. */
1172 return TRUE;
1173 }
1174
1176 /* The tile is being observed. */
1177 return TRUE;
1178 }
1179
1181
1185 /* Revealed because of the trade route. */
1186 return TRUE;
1187 }
1189 }
1190
1191 return FALSE;
1192}
1193
1194/*******************************************************************/
1203struct city *player_city_by_number(const struct player *pplayer, int city_id)
1204{
1205 /* We call idex directly. Should use game_city_by_number() instead? */
1206 struct city *pcity = idex_lookup_city(&wld, city_id);
1207
1208 if (!pcity) {
1209 return NULL;
1210 }
1211
1212 if (!pplayer || (city_owner(pcity) == pplayer)) {
1213 /* Correct owner */
1214 return pcity;
1215 }
1216
1217 return NULL;
1218}
1219
1220/*******************************************************************/
1229struct unit *player_unit_by_number(const struct player *pplayer, int unit_id)
1230{
1231 /* We call idex directly. Should use game_unit_by_number() instead? */
1232 struct unit *punit = idex_lookup_unit(&wld, unit_id);
1233
1234 if (!punit) {
1235 return NULL;
1236 }
1237
1238 if (!pplayer || (unit_owner(punit) == pplayer)) {
1239 /* Correct owner */
1240 return punit;
1241 }
1242
1243 return NULL;
1244}
1245
1246/*******************************************************************/
1249bool player_in_city_map(const struct player *pplayer,
1250 const struct tile *ptile)
1251{
1252 const struct civ_map *nmap = &(wld.map);
1253
1255 struct city *pcity = tile_city(ptile1);
1256
1257 if (pcity
1258 && (pplayer == NULL || city_owner(pcity) == pplayer)
1259 && city_map_radius_sq_get(pcity) >= sq_map_distance(ptile,
1260 ptile1)) {
1261 return TRUE;
1262 }
1264
1265 return FALSE;
1266}
1267
1268/*******************************************************************/
1273int num_known_tech_with_flag(const struct player *pplayer,
1274 enum tech_flag_id flag)
1275{
1276 return research_get(pplayer)->num_known_tech_with_flag[flag];
1277}
1278
1279/*******************************************************************/
1286int player_get_expected_income(const struct player *pplayer)
1287{
1288 int income = 0;
1289
1290 /* City income/expenses. */
1291 city_list_iterate(pplayer->cities, pcity) {
1292 /* Gold suplus accounts for imcome plus building and unit upkeep. */
1293 income += pcity->surplus[O_GOLD];
1294
1295 /* Gold upkeep for buildings and units is defined by the setting
1296 * 'game.info.gold_upkeep_style':
1297 * GOLD_UPKEEP_CITY: Cities pay for buildings and units (this is
1298 * included in pcity->surplus[O_GOLD]).
1299 * GOLD_UPKEEP_MIXED: Cities pay only for buildings; the nation pays
1300 * for units.
1301 * GOLD_UPKEEP_NATION: The nation pays for buildings and units. */
1302 switch (game.info.gold_upkeep_style) {
1303 case GOLD_UPKEEP_CITY:
1304 break;
1305 case GOLD_UPKEEP_NATION:
1306 /* Nation pays for buildings (and units). */
1308 fc__fallthrough; /* No break. */
1309 case GOLD_UPKEEP_MIXED:
1310 /* Nation pays for units. */
1312 break;
1313 }
1314
1315 /* Capitalization income. */
1316 if (city_production_has_flag(pcity, IF_GOLD)) {
1317 income += pcity->shield_stock + pcity->surplus[O_SHIELD];
1318 }
1320
1321 return income;
1322}
1323
1324/*******************************************************************/
1328bool player_knows_techs_with_flag(const struct player *pplayer,
1329 enum tech_flag_id flag)
1330{
1331 return num_known_tech_with_flag(pplayer, flag) > 0;
1332}
1333
1334/*******************************************************************/
1337struct city *player_primary_capital(const struct player *pplayer)
1338{
1339 struct city *capital;
1340
1341 if (!pplayer) {
1342 /* The client depends on this behavior in some places. */
1343 return NULL;
1344 }
1345
1347
1348 return capital;
1349}
1350
1351/*******************************************************************/
1354const char *love_text(const int love)
1355{
1356 if (love <= - MAX_AI_LOVE * 90 / 100) {
1357 /* TRANS: These words should be adjectives which can fit in the sentence
1358 "The x are y towards us"
1359 "The Babylonians are respectful towards us" */
1360 return Q_("?attitude:Genocidal");
1361 } else if (love <= - MAX_AI_LOVE * 70 / 100) {
1362 return Q_("?attitude:Belligerent");
1363 } else if (love <= - MAX_AI_LOVE * 50 / 100) {
1364 return Q_("?attitude:Hostile");
1365 } else if (love <= - MAX_AI_LOVE * 25 / 100) {
1366 return Q_("?attitude:Uncooperative");
1367 } else if (love <= - MAX_AI_LOVE * 10 / 100) {
1368 return Q_("?attitude:Uneasy");
1369 } else if (love <= MAX_AI_LOVE * 10 / 100) {
1370 return Q_("?attitude:Neutral");
1371 } else if (love <= MAX_AI_LOVE * 25 / 100) {
1372 return Q_("?attitude:Respectful");
1373 } else if (love <= MAX_AI_LOVE * 50 / 100) {
1374 return Q_("?attitude:Helpful");
1375 } else if (love <= MAX_AI_LOVE * 70 / 100) {
1376 return Q_("?attitude:Enthusiastic");
1377 } else if (love <= MAX_AI_LOVE * 90 / 100) {
1378 return Q_("?attitude:Admiring");
1379 } else {
1380 fc_assert(love > MAX_AI_LOVE * 90 / 100);
1381 return Q_("?attitude:Worshipful");
1382 }
1383}
1384
1385/*******************************************************************/
1388bool pplayers_at_war(const struct player *pplayer,
1389 const struct player *pplayer2)
1390{
1391 enum diplstate_type ds;
1392
1393 if (pplayer == pplayer2) {
1394 return FALSE;
1395 }
1396
1397 ds = player_diplstate_get(pplayer, pplayer2)->type;
1398
1399 return ds == DS_WAR || ds == DS_NO_CONTACT;
1400}
1401
1402/*******************************************************************/
1405bool pplayers_allied(const struct player *pplayer,
1406 const struct player *pplayer2)
1407{
1408 enum diplstate_type ds;
1409
1410 if (!pplayer || !pplayer2) {
1411 return FALSE;
1412 }
1413
1414 if (pplayer == pplayer2) {
1415 return TRUE;
1416 }
1417
1418 ds = player_diplstate_get(pplayer, pplayer2)->type;
1419
1420 return (ds == DS_ALLIANCE || ds == DS_TEAM);
1421}
1422
1423/*******************************************************************/
1426bool pplayers_in_peace(const struct player *pplayer,
1427 const struct player *pplayer2)
1428{
1430
1431 if (pplayer == pplayer2) {
1432 return TRUE;
1433 }
1434
1435 return (ds == DS_PEACE || ds == DS_ALLIANCE
1436 || ds == DS_ARMISTICE || ds == DS_TEAM);
1437}
1438
1439/*******************************************************************/
1443 const struct player *pplayer2)
1444{
1445 if (pplayer1 == pplayer2 || !pplayer1 || !pplayer2) {
1446 return FALSE;
1447 }
1448
1449 /* Movement during armistice is allowed so that player can withdraw
1450 units deeper inside opponent territory. */
1451
1453}
1454
1455/*******************************************************************/
1459bool pplayers_non_attack(const struct player *pplayer,
1460 const struct player *pplayer2)
1461{
1462 enum diplstate_type ds;
1463
1464 if (pplayer == pplayer2) {
1465 return FALSE;
1466 }
1467
1468 ds = player_diplstate_get(pplayer, pplayer2)->type;
1469
1470 return (ds == DS_PEACE || ds == DS_CEASEFIRE || ds == DS_ARMISTICE);
1471}
1472
1473/*******************************************************************/
1477 const struct player *pplayer2)
1478{
1479 return pplayer1->team == pplayer2->team;
1480}
1481
1482/*******************************************************************/
1485bool gives_shared_vision(const struct player *me, const struct player *them)
1486{
1487 return BV_ISSET(me->gives_shared_vision, player_index(them));
1488}
1489
1490/*******************************************************************/
1493bool gives_shared_tiles(const struct player *me, const struct player *them)
1494{
1495 return BV_ISSET(me->gives_shared_tiles, player_index(them));
1496}
1497
1498/*******************************************************************/
1502 const struct player_diplstate *pds2)
1503{
1504 return (pds1->type == pds2->type && pds1->turns_left == pds2->turns_left
1505 && pds1->has_reason_to_cancel == pds2->has_reason_to_cancel
1506 && pds1->contact_turns_left == pds2->contact_turns_left);
1507}
1508
1509/*******************************************************************/
1513 const struct player *player2,
1514 int diplrel)
1515{
1518
1519 /* No relationship to it self. */
1520 if (player1 == player2 && diplrel != DRO_FOREIGN) {
1521 return FALSE;
1522 }
1523
1524 if (diplrel < DS_LAST) {
1525 return player_diplstate_get(player1, player2)->type == diplrel;
1526 }
1527
1528 switch (diplrel) {
1533 case DRO_HOSTS_EMBASSY:
1536 return team_has_embassy(player2->team, player1);
1537 case DRO_HAS_EMBASSY:
1540 return team_has_embassy(player1->team, player2);
1549 case DRO_FOREIGN:
1550 return player1 != player2;
1551 }
1552
1553 fc_assert_msg(FALSE, "diplrel_between(): invalid diplrel number %d.",
1554 diplrel);
1555
1556 return FALSE;
1557}
1558
1559/*******************************************************************/
1562bool is_diplrel_to_other(const struct player *pplayer, int diplrel)
1563{
1564 fc_assert(pplayer != NULL);
1565
1567 if (oplayer == pplayer) {
1568 continue;
1569 }
1570 if (is_diplrel_between(pplayer, oplayer, diplrel)) {
1571 return TRUE;
1572 }
1574 return FALSE;
1575}
1576
1577/*******************************************************************/
1581int diplrel_by_rule_name(const char *value)
1582{
1583 /* Look for asymmetric diplomatic relations */
1584 int diplrel = diplrel_other_by_name(value, fc_strcasecmp);
1585
1586 if (diplrel != diplrel_other_invalid()) {
1587 return diplrel;
1588 }
1589
1590 /* Look for symmetric diplomatic relations */
1591 diplrel = diplstate_type_by_name(value, fc_strcasecmp);
1592
1593 /*
1594 * Make sure DS_LAST isn't returned as DS_LAST is the first diplrel_other.
1595 *
1596 * Can't happend now. This is in case that changes in the future. */
1598
1599 /*
1600 * Make sure that diplrel_other_invalid() is returned.
1601 *
1602 * Can't happen now. At the moment dpilrel_asym_invalid() is the same as
1603 * diplstate_type_invalid(). This is in case that changes in the future.
1604 */
1605 if (diplrel != diplstate_type_invalid()) {
1606 return diplrel;
1607 }
1608
1609 return diplrel_other_invalid();
1610}
1611
1612/*******************************************************************/
1615const char *diplrel_rule_name(int value)
1616{
1617 if (value < DS_LAST) {
1618 return diplstate_type_name(value);
1619 } else {
1620 return diplrel_other_name(value);
1621 }
1622}
1623
1624/*******************************************************************/
1627const char *diplrel_name_translation(int value)
1628{
1629 if (value < DS_LAST) {
1630 return diplstate_type_translated_name(value);
1631 } else {
1632 return _(diplrel_other_name(value));
1633 }
1634}
1635
1636/**************************************************************************
1637 Return the Casus Belli range when offender performs paction to tgt_plr
1638 at tgt_tile and the outcome is outcome.
1639**************************************************************************/
1641 const struct unit_type *off_ut,
1642 const struct player *tgt_plr,
1643 const enum effect_type outcome,
1644 const struct action *paction,
1645 const struct tile *tgt_tile)
1646{
1648
1649 /* The victim gets a casus belli if CASUS_BELLI_VICTIM or above. Everyone
1650 * gets a casus belli if CASUS_BELLI_OUTRAGE or above. */
1653 &(const struct req_context) {
1654 .player = offender,
1655 .city = tile_city(tgt_tile),
1656 .tile = tgt_tile,
1657 .unittype = off_ut,
1658 .action = paction,
1659 },
1660 tgt_plr,
1661 outcome);
1662
1664 /* International outrage: This isn't just between the offender and the
1665 * victim. */
1667 }
1668
1670 /* In this situation the specified action provides a casus belli
1671 * against the actor. */
1672 return CBR_VICTIM_ONLY;
1673 }
1674
1675 return CBR_NONE;
1676}
1677
1678/* The number of mutually exclusive requirement sets that
1679 * diplrel_mess_gen() creates for the DiplRel requirement type. */
1680#define DIPLREL_MESS_SIZE (3 + (DRO_LAST * (5 + 4 + 3 + 2 + 1)))
1681
1682/*******************************************************************/
1691{
1692 /* The ranges supported by the DiplRel requiremnt type. */
1693 const enum req_range legal_ranges[] = {
1699 };
1700
1701 /* Iterators. */
1702 int rel;
1703 int i;
1704 int j;
1705
1706 /* Storage for the mutually exclusive requirement sets. */
1708 * sizeof(bv_diplrel_all_reqs));
1709
1710 /* Position in mess. */
1711 int mess_pos = 0;
1712
1713 /* The first mutually exclusive set is about local diplstate. */
1715
1716 /* It is not possible to have more than one diplstate to a nation. */
1731
1732 /* It is not possible to have a diplstate to your self. */
1735
1736 mess_pos++;
1737
1738 /* Having a real embassy excludes not having an embassy. */
1740
1743 TRUE));
1746 FALSE));
1747
1748 mess_pos++;
1749
1750 /* Hosting a real embassy excludes not hosting an embassy. */
1752
1755 TRUE));
1758 FALSE));
1759
1760 mess_pos++;
1761
1762 /* Loop over diplstate_type and diplrel_other. */
1763 for (rel = 0; rel < DRO_LAST; rel++) {
1764 /* The presence of a DiplRel at a more local range proves that it can't
1765 * be absent in a more global range. (The alliance range includes the
1766 * Team range) */
1767 for (i = 0; i < 5; i++) {
1768 for (j = i; j < 5; j++) {
1770
1775
1776 mess_pos++;
1777 }
1778 }
1779 }
1780
1781 /* No uninitialized element exists. */
1783
1784 return mess;
1785}
1786
1787/* An array of mutually exclusive requirement sets for the DiplRel
1788 * requirement type. Is initialized the first time diplrel_mess_get() is
1789 * called. */
1791
1792/*******************************************************************/
1796{
1797 if (diplrel_mess == NULL) {
1798 /* This is the first call. Initialize diplrel_mess. */
1800 }
1801
1802 return diplrel_mess;
1803}
1804
1805/*******************************************************************/
1809{
1810 if (diplrel_mess != NULL) {
1813 }
1814}
1815
1816/*******************************************************************/
1824{
1825 int diplrel_req_num;
1827 bv_diplrel_all_reqs known;
1828 int set;
1829
1830 /* Nothing is known to contradict the requirement yet. */
1831 BV_CLR_ALL(known);
1832
1833 if (!(req->source.kind == VUT_DIPLREL
1834 || req->source.kind == VUT_DIPLREL_TILE
1835 || req->source.kind == VUT_DIPLREL_TILE_O
1837 || req->source.kind == VUT_DIPLREL_UNITANY_O)) {
1838 /* No known contradiction of a requirement of any other kind. */
1840 || req->source.kind == VUT_DIPLREL_TILE
1841 || req->source.kind == VUT_DIPLREL_TILE_O
1843 || req->source.kind == VUT_DIPLREL_UNITANY_O);
1844
1845 return known;
1846 }
1847
1848 /* Convert the requirement to its position in the enumeration of all
1849 * DiplRel requirements. */
1851 req->range, req->present);
1852
1853 /* Get the mutually exclusive requirement sets for DiplRel. */
1855
1856 /* Add all known contradictions. */
1857 for (set = 0; set < DIPLREL_MESS_SIZE; set++) {
1858 if (BV_ISSET(mess[set], diplrel_req_num)) {
1859 /* The requirement req is mentioned in the set. It is therefore known
1860 * that all other requirements in the set contradicts it. They should
1861 * therefore be added to the known contradictions. */
1862 BV_SET_ALL_FROM(known, mess[set]);
1863 }
1864 }
1865
1866 /* The requirement isn't self contradicting. It was set by the mutually
1867 * exclusive requirement sets that mentioned it. Remove it. */
1868 BV_CLR(known, diplrel_req_num);
1869
1870 return known;
1871}
1872
1873/*******************************************************************/
1878int player_in_territory(const struct player *pplayer,
1879 const struct player *pplayer2)
1880{
1881 int in_territory = 0;
1882
1883 /* This algorithm should work at server or client. It only returns the
1884 * number of visible units (a unit can potentially hide inside the
1885 * transport of a different player).
1886 *
1887 * Note this may be quite slow. An even slower alternative is to iterate
1888 * over the entire map, checking all units inside the player's territory
1889 * to see if they're owned by the enemy. */
1891 /* Get the owner of the tile/territory. */
1893
1894 if (owner == pplayer && can_player_see_unit(pplayer, punit)) {
1895 /* Found one! */
1896 in_territory++;
1897 }
1899
1900 return in_territory;
1901}
1902
1903/*******************************************************************/
1908bool is_valid_username(const char *name)
1909{
1910 return (strlen(name) > 0
1911 && !fc_isdigit(name[0])
1914}
1915
1916/*******************************************************************/
1919bool is_settable_ai_level(enum ai_level level)
1920{
1921 if (level == AI_LEVEL_AWAY) {
1922 /* Cannot set away level for AI */
1923 return FALSE;
1924 }
1925
1926 return TRUE;
1927}
1928
1929/*******************************************************************/
1933{
1934 return AI_LEVEL_COUNT - 1; /* AI_LEVEL_AWAY is not real AI */
1935}
1936
1937/*******************************************************************/
1940void *player_ai_data(const struct player *pplayer, const struct ai_type *ai)
1941{
1942 return pplayer->server.ais[ai_type_number(ai)];
1943}
1944
1945/*******************************************************************/
1948void player_set_ai_data(struct player *pplayer, const struct ai_type *ai,
1949 void *data)
1950{
1951 pplayer->server.ais[ai_type_number(ai)] = data;
1952}
1953
1954/*******************************************************************/
1958int player_multiplier_value(const struct player *pplayer,
1959 const struct multiplier *pmul)
1960{
1961 return pplayer->multipliers[multiplier_index(pmul)].value;
1962}
1963
1964/*******************************************************************/
1969int player_multiplier_effect_value(const struct player *pplayer,
1970 const struct multiplier *pmul)
1971{
1972 return (player_multiplier_value(pplayer, pmul) + pmul->offset)
1973 * pmul->factor;
1974}
1975
1976/*******************************************************************/
1981int player_multiplier_target_value(const struct player *pplayer,
1982 const struct multiplier *pmul)
1983{
1984 return pplayer->multipliers[multiplier_index(pmul)].target;
1985}
1986
1987/*******************************************************************/
1990bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
1991{
1992 return BV_ISSET(pplayer->flags, flag);
1993}
1994
1995/*******************************************************************/
1998bool player_has_state(const struct player *pplayer,
1999 enum plrstate_type state)
2000{
2001 switch (state) {
2002 case PLRS_BARBARIAN:
2003 return is_barbarian(pplayer);
2004 case PLRS_HAS_CAPITAL:
2005 return player_primary_capital(pplayer) != NULL;
2006 case PLRS_LAST:
2007 fc_assert(state != PLRS_LAST);
2008 break;
2009 }
2010
2012 return FALSE;
2013}
int ai_type_number(const struct ai_type *ai)
Definition ai.c:278
void dbv_free(struct dbv *pdbv)
Definition bitvector.c:95
#define BV_SET_ALL_FROM(vec_to, vec_from)
Definition bitvector.h:120
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_CLR(bv, bit)
Definition bitvector.h:86
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:727
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:137
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1222
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1201
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:564
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:86
#define city_owner(_pcity_)
Definition city.h:563
#define city_list_iterate_end
Definition city.h:510
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:230
#define city_tile_iterate_end
Definition city.h:238
struct civclient client
char * incite_cost
Definition comments.c:75
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city * target_city
Definition dialogs_g.h:56
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:748
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
struct extra_type_list * extra_type_list_of_unit_hiders(void)
Definition extras.c:259
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:165
#define extra_type_list_iterate_end
Definition extras.h:167
const struct functions * fc_funcs
static bool is_server(void)
#define CASUS_BELLI_OUTRAGE
Definition fc_types.h:484
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
#define CASUS_BELLI_VICTIM
Definition fc_types.h:478
#define MAX_LEN_NAME
Definition fc_types.h:66
@ O_SHIELD
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
#define Q_(String)
Definition fcintl.h:70
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
void game_remove_unit(struct world *gworld, struct unit *punit)
Definition game.c:124
void game_remove_city(struct world *gworld, struct city *pcity)
Definition game.c:178
struct city * owner
Definition citydlg.c:226
GType type
Definition repodlgs.c:1313
struct city * idex_lookup_city(struct world *iworld, int id)
Definition idex.c:133
struct unit * idex_lookup_unit(struct world *iworld, int id)
Definition idex.c:146
#define WONDER_NOT_BUILT
#define B_LAST
Definition improvement.h:42
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert_ret(condition)
Definition log.h:191
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_debug(message,...)
Definition log.h:115
int sq_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:641
#define fc_calloc(n, esz)
Definition mem.h:38
#define fc_malloc(sz)
Definition mem.h:34
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Definition multipliers.c:80
#define NO_NATION_SELECTED
Definition nation.h:30
bool is_settable_ai_level(enum ai_level level)
Definition player.c:1919
bool are_diplstates_equal(const struct player_diplstate *pds1, const struct player_diplstate *pds2)
Definition player.c:1501
bool player_can_invade_tile(const struct player *pplayer, const struct tile *ptile)
Definition player.c:270
bool player_knows_techs_with_flag(const struct player *pplayer, enum tech_flag_id flag)
Definition player.c:1328
int player_multiplier_effect_value(const struct player *pplayer, const struct multiplier *pmul)
Definition player.c:1969
void * player_ai_data(const struct player *pplayer, const struct ai_type *ai)
Definition player.c:1940
bool player_has_state(const struct player *pplayer, enum plrstate_type state)
Definition player.c:1998
bool player_slot_is_used(const struct player_slot *pslot)
Definition player.c:448
bv_diplrel_all_reqs diplrel_req_contradicts(const struct requirement *req)
Definition player.c:1823
static bv_diplrel_all_reqs * diplrel_mess_get(void)
Definition player.c:1795
int num_known_tech_with_flag(const struct player *pplayer, enum tech_flag_id flag)
Definition player.c:1273
static struct @69 player_slots
bool is_valid_username(const char *name)
Definition player.c:1908
static void player_diplstate_new(const struct player *plr1, const struct player *plr2)
Definition player.c:285
int player_multiplier_target_value(const struct player *pplayer, const struct multiplier *pmul)
Definition player.c:1981
bool can_player_see_tile(const struct player *plr, const struct tile *ptile)
Definition player.c:1091
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
Definition player.c:1229
static bv_diplrel_all_reqs * diplrel_mess
Definition player.c:1790
struct player * player_by_name_prefix(const char *name, enum m_pre_result *result)
Definition player.c:920
int diplrel_by_rule_name(const char *value)
Definition player.c:1581
struct player * player_new(struct player_slot *pslot)
Definition player.c:493
struct player * player_by_number(const int player_id)
Definition player.c:849
bool player_in_city_map(const struct player *pplayer, const struct tile *ptile)
Definition player.c:1249
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1476
static bv_diplrel_all_reqs * diplrel_mess_gen(void)
Definition player.c:1690
int used_slots
Definition player.c:52
bool can_player_see_unit_at(const struct player *pplayer, const struct unit *punit, const struct tile *ptile, bool is_transported)
Definition player.c:1034
int player_count(void)
Definition player.c:817
enum diplstate_type cancel_pact_result(enum diplstate_type oldstate)
Definition player.c:68
int player_slot_count(void)
Definition player.c:418
struct player_slot * player_slot_by_number(int player_id)
Definition player.c:463
int player_multiplier_value(const struct player *pplayer, const struct multiplier *pmul)
Definition player.c:1958
int player_get_expected_income(const struct player *pplayer)
Definition player.c:1286
int player_number(const struct player *pplayer)
Definition player.c:837
enum dipl_reason pplayer_can_make_treaty(const struct player *p1, const struct player *p2, enum diplstate_type treaty)
Definition player.c:159
const char * player_name(const struct player *pplayer)
Definition player.c:895
static void player_diplstate_defaults(const struct player *plr1, const struct player *plr2)
Definition player.c:305
void player_slots_free(void)
Definition player.c:386
bool is_diplrel_to_other(const struct player *pplayer, int diplrel)
Definition player.c:1562
int player_slot_max_used_number(void)
Definition player.c:476
static bool is_valid_alliance(const struct player *p1, const struct player *p2)
Definition player.c:132
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1104
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1388
void player_set_ai_data(struct player *pplayer, const struct ai_type *ai, void *data)
Definition player.c:1948
static void player_diplstate_destroy(const struct player *plr1, const struct player *plr2)
Definition player.c:341
void player_ruleset_close(struct player *pplayer)
Definition player.c:745
void player_clear(struct player *pplayer, bool full)
Definition player.c:669
int player_slot_index(const struct player_slot *pslot)
Definition player.c:426
struct player * player_by_name(const char *name)
Definition player.c:881
void player_slots_init(void)
Definition player.c:360
bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
Definition player.c:1990
bool player_has_real_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:240
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:220
void player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Definition player.c:648
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1203
struct city * player_primary_capital(const struct player *pplayer)
Definition player.c:1337
int player_index(const struct player *pplayer)
Definition player.c:829
int player_in_territory(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1878
struct player * player_by_user(const char *name)
Definition player.c:940
const char * diplrel_name_translation(int value)
Definition player.c:1627
bool is_diplrel_between(const struct player *player1, const struct player *player2, int diplrel)
Definition player.c:1512
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:861
#define DIPLREL_MESS_SIZE
Definition player.c:1680
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Definition player.c:1164
int player_age(const struct player *pplayer)
Definition player.c:954
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
Definition player.c:98
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
int number_of_ai_levels(void)
Definition player.c:1932
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
static void player_defaults(struct player *pplayer)
Definition player.c:551
bool can_player_see_hypotetic_units_at(const struct player *pplayer, const struct tile *ptile)
Definition player.c:993
struct player_slot * slots
Definition player.c:51
bool player_has_embassy_from_effect(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:250
void diplrel_mess_close(void)
Definition player.c:1808
bool players_non_invade(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1442
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1459
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:1133
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:437
static const char * player_name_by_number(int i)
Definition player.c:909
bool can_player_see_city_internals(const struct player *pplayer, const struct city *pcity)
Definition player.c:1149
struct player_slot * player_slot_next(struct player_slot *pslot)
Definition player.c:407
bool player_can_trust_tile_has_no_units(const struct player *pplayer, const struct tile *ptile)
Definition player.c:967
bool player_slots_initialised(void)
Definition player.c:378
const char * love_text(const int love)
Definition player.c:1354
bool gives_shared_tiles(const struct player *me, const struct player *them)
Definition player.c:1493
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:208
enum casus_belli_range casus_belli_range_for(const struct player *offender, const struct unit_type *off_ut, const struct player *tgt_plr, const enum effect_type outcome, const struct action *paction, const struct tile *tgt_tile)
Definition player.c:1640
const char * diplrel_rule_name(int value)
Definition player.c:1615
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1485
bool player_owns_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:261
struct player_slot * player_slot_first(void)
Definition player.c:399
void player_destroy(struct player *pplayer)
Definition player.c:756
bool pplayers_in_peace(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1426
#define players_iterate_end
Definition player.h:537
dipl_reason
Definition player.h:190
@ DIPL_SENATE_BLOCKING
Definition player.h:191
@ DIPL_ALLIANCE_PROBLEM_THEM
Definition player.h:192
@ DIPL_ALLIANCE_PROBLEM_US
Definition player.h:192
@ DIPL_OK
Definition player.h:191
@ DIPL_ERROR
Definition player.h:191
#define players_iterate(_pplayer)
Definition player.h:532
#define player_list_iterate(playerlist, pplayer)
Definition player.h:555
#define MAX_AI_LOVE
Definition player.h:561
#define ANON_USER_NAME
Definition player.h:48
static bool is_barbarian(const struct player *pplayer)
Definition player.h:489
#define player_slots_iterate(_pslot)
Definition player.h:523
#define player_list_iterate_end
Definition player.h:557
#define PLAYER_DEFAULT_SCIENCE_RATE
Definition player.h:40
#define set_as_human(plr)
Definition player.h:231
#define players_iterate_alive_end
Definition player.h:547
#define player_slots_iterate_end
Definition player.h:527
#define ANON_PLAYER_NAME
Definition player.h:43
#define PLAYER_DEFAULT_TAX_RATE
Definition player.h:39
#define PLAYER_DEFAULT_LUXURY_RATE
Definition player.h:41
#define players_iterate_alive(_pplayer)
Definition player.h:542
#define requirement_diplrel_ereq(_id_, _range_, _present_)
struct research * research_get(const struct player *pplayer)
Definition research.c:128
void rgbcolor_destroy(struct rgbcolor *prgbcolor)
Definition rgbcolor.c:74
struct rgbcolor * rgbcolor_copy(const struct rgbcolor *prgbcolor)
Definition rgbcolor.c:51
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
enum m_pre_result match_prefix(m_pre_accessor_fn_t accessor_fn, size_t n_names, size_t max_len_name, m_pre_strncmp_fn_t cmp_fn, m_strlen_fn_t len_fn, const char *prefix, int *ind_result)
Definition shared.c:1590
bool is_ascii_name(const char *name)
Definition shared.c:283
m_pre_result
Definition shared.h:207
@ M_PRE_AMBIGUOUS
Definition shared.h:210
void spaceship_init(struct player_spaceship *ship)
Definition spaceship.c:96
Definition ai.h:50
Definition city.h:320
enum capital_type capital
Definition city.h:328
struct tile * tile
Definition city.h:322
struct packet_game_info info
Definition game.h:89
int bits
Definition bitvector.h:33
unsigned char * vec
Definition bitvector.h:34
bool(* player_tile_vision_get)(const struct tile *ptile, const struct player *pplayer, enum vision_layer vision)
void(* destroy_city)(struct city *pcity)
struct player * player
Definition nation.h:118
enum gold_upkeep_style gold_upkeep_style
enum ai_level skill_level
Definition player.h:114
struct ai_trait * traits
Definition player.h:124
enum barbarian_type barbarian_type
Definition player.h:120
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:122
int expand
Definition player.h:116
int fuzzy
Definition player.h:115
enum diplstate_type type
Definition player.h:197
char has_reason_to_cancel
Definition player.h:201
int infra_points
Definition player.h:65
struct player * player
Definition player.c:47
struct city_list * cities
Definition player.h:279
bool random_name
Definition player.h:293
struct player_ai ai_common
Definition player.h:286
bv_plr_flags flags
Definition player.h:290
struct dbv tile_vision[V_COUNT]
Definition player.h:357
int primary_capital_id
Definition player.h:273
bool is_male
Definition player.h:255
int wonders[B_LAST]
Definition player.h:303
const struct player_diplstate ** diplstates
Definition player.h:276
bool unassigned_ranked
Definition player.h:253
struct government * target_government
Definition player.h:257
int autoselect_weight
Definition player.h:297
char username[MAX_LEN_NAME]
Definition player.h:250
bool is_winner
Definition player.h:267
bool is_connected
Definition player.h:294
int revolution_finishes
Definition player.h:271
void * ais[FREECIV_AI_MOD_LAST]
Definition player.h:334
int nturns_idle
Definition player.h:263
struct government * government
Definition player.h:256
struct dbv tile_known
Definition player.h:308
struct connection * current_conn
Definition player.h:295
struct team * team
Definition player.h:259
char * savegame_ai_type_name
Definition player.h:288
int turns_alive
Definition player.h:264
bool was_created
Definition player.h:292
const struct ai_type * ai
Definition player.h:287
struct unit_list * units
Definition player.h:280
char ranked_username[MAX_LEN_NAME]
Definition player.h:252
struct conn_list * connections
Definition player.h:296
bool is_alive
Definition player.h:266
bv_player real_embassy
Definition player.h:275
struct player::@70::@73 client
struct player_economic economic
Definition player.h:282
struct player_spaceship spaceship
Definition player.h:284
struct attribute_block_s attribute_block
Definition player.h:305
char name[MAX_LEN_NAME]
Definition player.h:249
bv_player gives_shared_vision
Definition player.h:300
struct attribute_block_s attribute_block_buffer
Definition player.h:306
struct multiplier_value multipliers[MAX_NUM_MULTIPLIERS]
Definition player.h:312
struct nation_type * nation
Definition player.h:258
int music_style
Definition player.h:278
struct nation_style * style
Definition player.h:277
bool phase_done
Definition player.h:261
struct player_slot * slot
Definition player.h:248
bv_player gives_shared_tiles
Definition player.h:302
bool is_ready
Definition player.h:260
struct player::@70::@72 server
int user_turns
Definition player.h:254
int last_war_action
Definition player.h:268
struct rgbcolor * rgb
Definition player.h:310
bool unassigned_user
Definition player.h:251
enum req_range range
struct universal source
int num_known_tech_with_flag[TF_COUNT]
Definition research.h:88
Definition team.c:40
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
struct player * extras_owner
Definition tile.h:63
Definition unit.h:138
struct unit::@81::@83 client
struct unit_list * transporting
Definition unit.h:184
int transported_by
Definition unit.h:216
enum universals_n kind
Definition fc_types.h:902
universals_u value
Definition fc_types.h:901
struct civ_map map
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
bool fc_isdigit(char c)
Definition support.c:1232
int fc_strncasequotecmp(const char *str0, const char *str1, size_t n)
Definition support.c:380
size_t effectivestrlenquote(const char *str)
Definition support.c:359
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define fc__fallthrough
Definition support.h:119
const struct player_list * team_members(const struct team *pteam)
Definition team.c:456
void team_remove_player(struct player *pplayer)
Definition team.c:502
#define terrain_has_flag(terr, flag)
Definition terrain.h:283
bool tile_is_seen(const struct tile *target_tile, const struct player *pow_player)
Definition tile.c:407
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:392
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
@ TILE_KNOWN_SEEN
Definition tile.h:38
#define tile_terrain(_tile)
Definition tile.h:110
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
#define tile_owner(_tile)
Definition tile.h:96
#define trade_partners_iterate_end
#define trade_partners_iterate(c, p)
bool is_hiding_unit(const struct unit *punit)
Definition unit.c:426
struct player * unit_nationality(const struct unit *punit)
Definition unit.c:1245
bool unit_transport_unload(struct unit *pcargo)
Definition unit.c:2390
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2425
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
Definition unit.c:2451
#define unit_tile(_pu)
Definition unit.h:397
#define unit_owner(_pu)
Definition unit.h:396
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2499
#define vision_layer_iterate(v)
Definition vision.h:77
#define vision_layer_iterate_end
Definition vision.h:80