Freeciv-3.3
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,
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
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) {
716 } else {
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. */
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
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)
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. */
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 == nullptr || pplayer2 == nullptr) {
1394 return TRUE;
1395 }
1396
1397 if (pplayer == pplayer2) {
1398 return FALSE;
1399 }
1400
1401 ds = player_diplstate_get(pplayer, pplayer2)->type;
1402
1403 return ds == DS_WAR || ds == DS_NO_CONTACT;
1404}
1405
1406/*******************************************************************/
1409bool pplayers_allied(const struct player *pplayer,
1410 const struct player *pplayer2)
1411{
1412 enum diplstate_type ds;
1413
1414 if (!pplayer || !pplayer2) {
1415 return FALSE;
1416 }
1417
1418 if (pplayer == pplayer2) {
1419 return TRUE;
1420 }
1421
1422 ds = player_diplstate_get(pplayer, pplayer2)->type;
1423
1424 return (ds == DS_ALLIANCE || ds == DS_TEAM);
1425}
1426
1427/*******************************************************************/
1430bool pplayers_in_peace(const struct player *pplayer,
1431 const struct player *pplayer2)
1432{
1434
1435 if (pplayer == pplayer2) {
1436 return TRUE;
1437 }
1438
1439 return (ds == DS_PEACE || ds == DS_ALLIANCE
1440 || ds == DS_ARMISTICE || ds == DS_TEAM);
1441}
1442
1443/*******************************************************************/
1447 const struct player *pplayer2)
1448{
1449 if (pplayer1 == pplayer2 || !pplayer1 || !pplayer2) {
1450 return FALSE;
1451 }
1452
1453 /* Movement during armistice is allowed so that player can withdraw
1454 units deeper inside opponent territory. */
1455
1457}
1458
1459/*******************************************************************/
1463bool pplayers_non_attack(const struct player *pplayer,
1464 const struct player *pplayer2)
1465{
1466 enum diplstate_type ds;
1467
1468 if (pplayer == pplayer2) {
1469 return FALSE;
1470 }
1471
1472 ds = player_diplstate_get(pplayer, pplayer2)->type;
1473
1474 return (ds == DS_PEACE || ds == DS_CEASEFIRE || ds == DS_ARMISTICE);
1475}
1476
1477/*******************************************************************/
1481 const struct player *pplayer2)
1482{
1483 return pplayer1->team == pplayer2->team;
1484}
1485
1486/*******************************************************************/
1489bool gives_shared_vision(const struct player *me, const struct player *them)
1490{
1491 return BV_ISSET(me->gives_shared_vision, player_index(them));
1492}
1493
1494/*******************************************************************/
1497bool gives_shared_tiles(const struct player *me, const struct player *them)
1498{
1499 return BV_ISSET(me->gives_shared_tiles, player_index(them));
1500}
1501
1502/*******************************************************************/
1506 const struct player_diplstate *pds2)
1507{
1508 return (pds1->type == pds2->type && pds1->turns_left == pds2->turns_left
1509 && pds1->has_reason_to_cancel == pds2->has_reason_to_cancel
1510 && pds1->contact_turns_left == pds2->contact_turns_left);
1511}
1512
1513/*******************************************************************/
1517 const struct player *player2,
1518 int diplrel)
1519{
1522
1523 /* No relationship to it self. */
1524 if (player1 == player2 && diplrel != DRO_FOREIGN) {
1525 return FALSE;
1526 }
1527
1528 if (diplrel < DS_LAST) {
1529 return player_diplstate_get(player1, player2)->type == diplrel;
1530 }
1531
1532 switch (diplrel) {
1537 case DRO_HOSTS_EMBASSY:
1540 return team_has_embassy(player2->team, player1);
1541 case DRO_HAS_EMBASSY:
1544 return team_has_embassy(player1->team, player2);
1553 case DRO_FOREIGN:
1554 return player1 != player2;
1555 }
1556
1557 fc_assert_msg(FALSE, "diplrel_between(): invalid diplrel number %d.",
1558 diplrel);
1559
1560 return FALSE;
1561}
1562
1563/*******************************************************************/
1566bool is_diplrel_to_other(const struct player *pplayer, int diplrel)
1567{
1568 fc_assert(pplayer != NULL);
1569
1571 if (oplayer == pplayer) {
1572 continue;
1573 }
1574 if (is_diplrel_between(pplayer, oplayer, diplrel)) {
1575 return TRUE;
1576 }
1578 return FALSE;
1579}
1580
1581/*******************************************************************/
1585int diplrel_by_rule_name(const char *value)
1586{
1587 /* Look for asymmetric diplomatic relations */
1588 int diplrel = diplrel_other_by_name(value, fc_strcasecmp);
1589
1590 if (diplrel != diplrel_other_invalid()) {
1591 return diplrel;
1592 }
1593
1594 /* Look for symmetric diplomatic relations */
1595 diplrel = diplstate_type_by_name(value, fc_strcasecmp);
1596
1597 /*
1598 * Make sure DS_LAST isn't returned as DS_LAST is the first diplrel_other.
1599 *
1600 * Can't happend now. This is in case that changes in the future. */
1602
1603 /*
1604 * Make sure that diplrel_other_invalid() is returned.
1605 *
1606 * Can't happen now. At the moment dpilrel_asym_invalid() is the same as
1607 * diplstate_type_invalid(). This is in case that changes in the future.
1608 */
1609 if (diplrel != diplstate_type_invalid()) {
1610 return diplrel;
1611 }
1612
1613 return diplrel_other_invalid();
1614}
1615
1616/*******************************************************************/
1619const char *diplrel_rule_name(int value)
1620{
1621 if (value < DS_LAST) {
1622 return diplstate_type_name(value);
1623 } else {
1624 return diplrel_other_name(value);
1625 }
1626}
1627
1628/*******************************************************************/
1631const char *diplrel_name_translation(int value)
1632{
1633 if (value < DS_LAST) {
1634 return diplstate_type_translated_name(value);
1635 } else {
1636 return _(diplrel_other_name(value));
1637 }
1638}
1639
1640/**************************************************************************
1641 Return the Casus Belli range when offender performs paction to tgt_plr
1642 at tgt_tile and the outcome is outcome.
1643**************************************************************************/
1645 const struct unit_type *off_ut,
1646 const struct player *tgt_plr,
1647 const enum effect_type outcome,
1648 const struct action *paction,
1649 const struct tile *tgt_tile)
1650{
1652
1653 /* The victim gets a casus belli if CASUS_BELLI_VICTIM or above. Everyone
1654 * gets a casus belli if CASUS_BELLI_OUTRAGE or above. */
1657 &(const struct req_context) {
1658 .player = offender,
1659 .city = tile_city(tgt_tile),
1660 .tile = tgt_tile,
1661 .unittype = off_ut,
1662 .action = paction,
1663 },
1664 &(const struct req_context) {
1665 .player = tgt_plr,
1666 },
1667 outcome);
1668
1670 /* International outrage: This isn't just between the offender and the
1671 * victim. */
1673 }
1674
1676 /* In this situation the specified action provides a casus belli
1677 * against the actor. */
1678 return CBR_VICTIM_ONLY;
1679 }
1680
1681 return CBR_NONE;
1682}
1683
1684/* The number of mutually exclusive requirement sets that
1685 * diplrel_mess_gen() creates for the DiplRel requirement type. */
1686#define DIPLREL_MESS_SIZE (3 + (DRO_LAST * (5 + 4 + 3 + 2 + 1)))
1687
1688/*******************************************************************/
1697{
1698 /* The ranges supported by the DiplRel requiremnt type. */
1699 const enum req_range legal_ranges[] = {
1705 };
1706
1707 /* Iterators. */
1708 int rel;
1709 int i;
1710 int j;
1711
1712 /* Storage for the mutually exclusive requirement sets. */
1714 * sizeof(bv_diplrel_all_reqs));
1715
1716 /* Position in mess. */
1717 int mess_pos = 0;
1718
1719 /* The first mutually exclusive set is about local diplstate. */
1721
1722 /* It is not possible to have more than one diplstate to a nation. */
1737
1738 /* It is not possible to have a diplstate to your self. */
1741
1742 mess_pos++;
1743
1744 /* Having a real embassy excludes not having an embassy. */
1746
1749 TRUE));
1752 FALSE));
1753
1754 mess_pos++;
1755
1756 /* Hosting a real embassy excludes not hosting an embassy. */
1758
1761 TRUE));
1764 FALSE));
1765
1766 mess_pos++;
1767
1768 /* Loop over diplstate_type and diplrel_other. */
1769 for (rel = 0; rel < DRO_LAST; rel++) {
1770 /* The presence of a DiplRel at a more local range proves that it can't
1771 * be absent in a more global range. (The alliance range includes the
1772 * Team range) */
1773 for (i = 0; i < 5; i++) {
1774 for (j = i; j < 5; j++) {
1776
1781
1782 mess_pos++;
1783 }
1784 }
1785 }
1786
1787 /* No uninitialized element exists. */
1789
1790 return mess;
1791}
1792
1793/* An array of mutually exclusive requirement sets for the DiplRel
1794 * requirement type. Is initialized the first time diplrel_mess_get() is
1795 * called. */
1797
1798/*******************************************************************/
1802{
1803 if (diplrel_mess == NULL) {
1804 /* This is the first call. Initialize diplrel_mess. */
1806 }
1807
1808 return diplrel_mess;
1809}
1810
1811/*******************************************************************/
1815{
1816 if (diplrel_mess != NULL) {
1819 }
1820}
1821
1822/*******************************************************************/
1830{
1831 int diplrel_req_num;
1833 bv_diplrel_all_reqs known;
1834 int set;
1835
1836 /* Nothing is known to contradict the requirement yet. */
1837 BV_CLR_ALL(known);
1838
1839 if (!(req->source.kind == VUT_DIPLREL
1840 || req->source.kind == VUT_DIPLREL_TILE
1841 || req->source.kind == VUT_DIPLREL_TILE_O
1843 || req->source.kind == VUT_DIPLREL_UNITANY_O)) {
1844 /* No known contradiction of a requirement of any other kind. */
1846 || req->source.kind == VUT_DIPLREL_TILE
1847 || req->source.kind == VUT_DIPLREL_TILE_O
1849 || req->source.kind == VUT_DIPLREL_UNITANY_O);
1850
1851 return known;
1852 }
1853
1854 /* Convert the requirement to its position in the enumeration of all
1855 * DiplRel requirements. */
1857 req->range, req->present);
1858
1859 /* Get the mutually exclusive requirement sets for DiplRel. */
1861
1862 /* Add all known contradictions. */
1863 for (set = 0; set < DIPLREL_MESS_SIZE; set++) {
1864 if (BV_ISSET(mess[set], diplrel_req_num)) {
1865 /* The requirement req is mentioned in the set. It is therefore known
1866 * that all other requirements in the set contradicts it. They should
1867 * therefore be added to the known contradictions. */
1868 BV_SET_ALL_FROM(known, mess[set]);
1869 }
1870 }
1871
1872 /* The requirement isn't self contradicting. It was set by the mutually
1873 * exclusive requirement sets that mentioned it. Remove it. */
1874 BV_CLR(known, diplrel_req_num);
1875
1876 return known;
1877}
1878
1879/*******************************************************************/
1884int player_in_territory(const struct player *pplayer,
1885 const struct player *pplayer2)
1886{
1887 int in_territory = 0;
1888
1889 /* This algorithm should work at server or client. It only returns the
1890 * number of visible units (a unit can potentially hide inside the
1891 * transport of a different player).
1892 *
1893 * Note this may be quite slow. An even slower alternative is to iterate
1894 * over the entire map, checking all units inside the player's territory
1895 * to see if they're owned by the enemy. */
1897 /* Get the owner of the tile/territory. */
1899
1900 if (owner == pplayer && can_player_see_unit(pplayer, punit)) {
1901 /* Found one! */
1902 in_territory++;
1903 }
1905
1906 return in_territory;
1907}
1908
1909/*******************************************************************/
1914bool is_valid_username(const char *name)
1915{
1916 return (strlen(name) > 0
1917 && !fc_isdigit(name[0])
1920}
1921
1922/*******************************************************************/
1925bool is_settable_ai_level(enum ai_level level)
1926{
1927 if (level == AI_LEVEL_AWAY) {
1928 /* Cannot set away level for AI */
1929 return FALSE;
1930 }
1931
1932 return TRUE;
1933}
1934
1935/*******************************************************************/
1939{
1940 return AI_LEVEL_COUNT - 1; /* AI_LEVEL_AWAY is not real AI */
1941}
1942
1943/*******************************************************************/
1946void *player_ai_data(const struct player *pplayer, const struct ai_type *ai)
1947{
1948 return pplayer->server.ais[ai_type_number(ai)];
1949}
1950
1951/*******************************************************************/
1954void player_set_ai_data(struct player *pplayer, const struct ai_type *ai,
1955 void *data)
1956{
1957 pplayer->server.ais[ai_type_number(ai)] = data;
1958}
1959
1960/*******************************************************************/
1964int player_multiplier_value(const struct player *pplayer,
1965 const struct multiplier *pmul)
1966{
1967 return pplayer->multipliers[multiplier_index(pmul)].value;
1968}
1969
1970/*******************************************************************/
1975int player_multiplier_effect_value(const struct player *pplayer,
1976 const struct multiplier *pmul)
1977{
1978 return (player_multiplier_value(pplayer, pmul) + pmul->offset)
1979 * pmul->factor;
1980}
1981
1982/*******************************************************************/
1987int player_multiplier_target_value(const struct player *pplayer,
1988 const struct multiplier *pmul)
1989{
1990 return pplayer->multipliers[multiplier_index(pmul)].target;
1991}
1992
1993/*******************************************************************/
1996bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
1997{
1998 return BV_ISSET(pplayer->flags, flag);
1999}
2000
2001/*******************************************************************/
2004bool player_has_state(const struct player *pplayer,
2005 enum plrstate_type state)
2006{
2007 switch (state) {
2008 case PLRS_BARBARIAN:
2009 return is_barbarian(pplayer);
2010 case PLRS_HAS_CAPITAL:
2011 return player_primary_capital(pplayer) != NULL;
2012 case PLRS_LAST:
2013 fc_assert(state != PLRS_LAST);
2014 break;
2015 }
2016
2018 return FALSE;
2019}
2020
2021/*******************************************************************/
2029 enum action_result result)
2030{
2033 penabler) {
2034 struct universal u[2] = {
2035 {.kind = VUT_GOVERNMENT, .value = {.govern = (pplayer->government)}},
2036 {.kind = VUT_MINCITIES, .value = {.min_cities = (city_list_size(pplayer->cities))}},
2037 };
2038
2039 if (!universals_mean_unfulfilled(&(penabler->actor_reqs), u, 2)) {
2040 return TRUE;
2041 }
2044
2045 return FALSE;
2046}
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:1559
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:241
#define action_enabler_list_iterate_end
Definition actions.h:190
#define action_by_result_iterate_end
Definition actions.h:245
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:188
#define action_id(_act_)
Definition actions.h:422
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:128
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
#define BV_CLR(bv, bit)
Definition bitvector.h:94
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:505
#define city_tile(_pcity_)
Definition city.h:561
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:83
#define city_owner(_pcity_)
Definition city.h:560
#define city_list_iterate_end
Definition city.h:507
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:227
#define city_tile_iterate_end
Definition city.h:235
struct civclient client
char * incite_cost
Definition comments.c:76
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 struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
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 req_context *other_context, enum effect_type effect_type)
Definition effects.c:744
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
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:341
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
#define CASUS_BELLI_VICTIM
Definition fc_types.h:335
#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:61
struct world wld
Definition game.c:62
void game_remove_unit(struct world *gworld, struct unit *punit)
Definition game.c:123
void game_remove_city(struct world *gworld, struct city *pcity)
Definition game.c:184
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:182
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_debug(message,...)
Definition log.h:116
int sq_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:686
#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:1925
bool are_diplstates_equal(const struct player_diplstate *pds1, const struct player_diplstate *pds2)
Definition player.c:1505
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:1975
void * player_ai_data(const struct player *pplayer, const struct ai_type *ai)
Definition player.c:1946
bool player_has_state(const struct player *pplayer, enum plrstate_type state)
Definition player.c:2004
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:1829
static bv_diplrel_all_reqs * diplrel_mess_get(void)
Definition player.c:1801
int num_known_tech_with_flag(const struct player *pplayer, enum tech_flag_id flag)
Definition player.c:1273
bool is_valid_username(const char *name)
Definition player.c:1914
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:1987
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:1796
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:1585
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:1480
static bv_diplrel_all_reqs * diplrel_mess_gen(void)
Definition player.c:1696
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:1964
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:1566
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:1954
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:1996
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:1884
struct player * player_by_user(const char *name)
Definition player.c:940
const char * diplrel_name_translation(int value)
Definition player.c:1631
bool is_diplrel_between(const struct player *player1, const struct player *player2, int diplrel)
Definition player.c:1516
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:861
#define DIPLREL_MESS_SIZE
Definition player.c:1686
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:1938
static struct @72 player_slots
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1409
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:1814
bool players_non_invade(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1446
bool player_can_do_action_result(struct player *pplayer, enum action_result result)
Definition player.c:2028
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1463
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:1497
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:1644
const char * diplrel_rule_name(int value)
Definition player.c:1619
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1489
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:1430
#define players_iterate_end
Definition player.h:542
dipl_reason
Definition player.h:192
@ DIPL_SENATE_BLOCKING
Definition player.h:193
@ DIPL_ALLIANCE_PROBLEM_THEM
Definition player.h:194
@ DIPL_ALLIANCE_PROBLEM_US
Definition player.h:194
@ DIPL_OK
Definition player.h:193
@ DIPL_ERROR
Definition player.h:193
#define players_iterate(_pplayer)
Definition player.h:537
#define player_list_iterate(playerlist, pplayer)
Definition player.h:560
#define MAX_AI_LOVE
Definition player.h:566
#define ANON_USER_NAME
Definition player.h:48
static bool is_barbarian(const struct player *pplayer)
Definition player.h:491
#define player_slots_iterate(_pslot)
Definition player.h:528
#define player_list_iterate_end
Definition player.h:562
#define PLAYER_DEFAULT_SCIENCE_RATE
Definition player.h:40
#define set_as_human(plr)
Definition player.h:233
#define players_iterate_alive_end
Definition player.h:552
#define player_slots_iterate_end
Definition player.h:532
#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:547
bool universals_mean_unfulfilled(struct requirement_vector *reqs, struct universal *unis, size_t n_unis)
#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:1583
bool is_ascii_name(const char *name)
Definition shared.c:286
m_pre_result
Definition shared.h:213
@ M_PRE_AMBIGUOUS
Definition shared.h:216
void spaceship_init(struct player_spaceship *ship)
Definition spaceship.c:96
Definition ai.h:50
Definition city.h:317
enum capital_type capital
Definition city.h:325
struct tile * tile
Definition city.h:319
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:116
struct ai_trait * traits
Definition player.h:126
enum barbarian_type barbarian_type
Definition player.h:122
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:124
int expand
Definition player.h:118
int fuzzy
Definition player.h:117
enum diplstate_type type
Definition player.h:199
char has_reason_to_cancel
Definition player.h:203
int infra_points
Definition player.h:67
struct player * player
Definition player.c:47
struct city_list * cities
Definition player.h:281
bool random_name
Definition player.h:295
struct player_ai ai_common
Definition player.h:288
bv_plr_flags flags
Definition player.h:292
struct dbv tile_vision[V_COUNT]
Definition player.h:359
int primary_capital_id
Definition player.h:275
bool is_male
Definition player.h:257
int wonders[B_LAST]
Definition player.h:305
const struct player_diplstate ** diplstates
Definition player.h:278
bool unassigned_ranked
Definition player.h:255
struct government * target_government
Definition player.h:259
int autoselect_weight
Definition player.h:299
char username[MAX_LEN_NAME]
Definition player.h:252
bool is_winner
Definition player.h:269
bool is_connected
Definition player.h:296
int revolution_finishes
Definition player.h:273
void * ais[FREECIV_AI_MOD_LAST]
Definition player.h:336
int nturns_idle
Definition player.h:265
struct government * government
Definition player.h:258
struct dbv tile_known
Definition player.h:310
struct connection * current_conn
Definition player.h:297
struct team * team
Definition player.h:261
char * savegame_ai_type_name
Definition player.h:290
int turns_alive
Definition player.h:266
bool was_created
Definition player.h:294
const struct ai_type * ai
Definition player.h:289
struct unit_list * units
Definition player.h:282
char ranked_username[MAX_LEN_NAME]
Definition player.h:254
struct conn_list * connections
Definition player.h:298
bool is_alive
Definition player.h:268
bv_player real_embassy
Definition player.h:277
struct player::@73::@75 server
struct player_economic economic
Definition player.h:284
struct player_spaceship spaceship
Definition player.h:286
struct attribute_block_s attribute_block
Definition player.h:307
char name[MAX_LEN_NAME]
Definition player.h:251
bv_player gives_shared_vision
Definition player.h:302
struct attribute_block_s attribute_block_buffer
Definition player.h:308
struct multiplier_value multipliers[MAX_NUM_MULTIPLIERS]
Definition player.h:314
struct nation_type * nation
Definition player.h:260
int music_style
Definition player.h:280
struct nation_style * style
Definition player.h:279
bool phase_done
Definition player.h:263
struct player_slot * slot
Definition player.h:250
bv_player gives_shared_tiles
Definition player.h:304
bool is_ready
Definition player.h:262
int user_turns
Definition player.h:256
int last_war_action
Definition player.h:270
struct player::@73::@76 client
struct rgbcolor * rgb
Definition player.h:312
bool unassigned_user
Definition player.h:253
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:140
struct unit_list * transporting
Definition unit.h:187
struct unit::@84::@86 client
int transported_by
Definition unit.h:219
enum universals_n kind
Definition fc_types.h:608
universals_u value
Definition fc_types.h:607
struct civ_map map
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
bool fc_isdigit(char c)
Definition support.c:1218
int fc_strncasequotecmp(const char *str0, const char *str1, size_t n)
Definition support.c:377
size_t effectivestrlenquote(const char *str)
Definition support.c:356
#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:176
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:111
#define tile_has_extra(ptile, pextra)
Definition tile.h:148
#define tile_owner(_tile)
Definition tile.h:97
#define trade_partners_iterate_end
#define trade_partners_iterate(c, p)
bool is_hiding_unit(const struct unit *punit)
Definition unit.c:450
struct player * unit_nationality(const struct unit *punit)
Definition unit.c:1274
bool unit_transport_unload(struct unit *pcargo)
Definition unit.c:2467
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2502
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
Definition unit.c:2528
#define unit_tile(_pu)
Definition unit.h:404
#define unit_owner(_pu)
Definition unit.h:403
#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:2505
#define vision_layer_iterate(v)
Definition vision.h:77
#define vision_layer_iterate_end
Definition vision.h:80