Freeciv-3.1: /fast/freeciv/nightly/S3_1/common/player.c Source File

Freeciv-3.1

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 "research.h"
36#include "rgbcolor.h"
37#include "tech.h"
38#include "unit.h"
39#include "unitlist.h"
40#include "vision.h"
41
42#include "player.h"
43
44
45 struct player_slot {
46 struct player *player;
47};
48
49static struct {
50 struct player_slot *slots;
51 int used_slots; /* number of used/allocated players in the player slots */
52} player_slots;
53
54static void player_defaults(struct player *pplayer);
55
56static void player_diplstate_new(const struct player *plr1,
57 const struct player *plr2);
58static void player_diplstate_defaults(const struct player *plr1,
59 const struct player *plr2);
60static void player_diplstate_destroy(const struct player *plr1,
61 const struct player *plr2);
62
63/*******************************************************************/
67 enum diplstate_type cancel_pact_result(enum diplstate_type oldstate)
68{
69 switch (oldstate) {
70 case DS_NO_CONTACT: /* possible if someone declares war on our ally */
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 default:
81 log_error("non-pact diplstate %d in cancel_pact_result", oldstate);
82 return DS_WAR; /* arbitrary */
83 }
84}
85
86/*******************************************************************/
92 enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1,
93 const struct player *p2)
94{
95 enum diplstate_type ds = player_diplstate_get(p1, p2)->type;
96
97 if (p1 == p2 || ds == DS_WAR || ds == DS_NO_CONTACT) {
98 return DIPL_ERROR;
99 }
100 if (players_on_same_team(p1, p2)) {
101 return DIPL_ERROR;
102 }
103 if (!p1->is_alive || !p2->is_alive) {
104 return DIPL_ERROR;
105 }
106 if (player_diplstate_get(p1, p2)->has_reason_to_cancel == 0
107 && get_player_bonus(p1, EFT_HAS_SENATE) > 0
108 && get_player_bonus(p1, EFT_NO_ANARCHY) <= 0) {
109 return DIPL_SENATE_BLOCKING;
110 }
111
112 return DIPL_OK;
113}
114
115/*******************************************************************/
126 static bool is_valid_alliance(const struct player *p1,
127 const struct player *p2)
128{
129 players_iterate_alive(pplayer) {
130 enum diplstate_type ds = player_diplstate_get(p1, pplayer)->type;
131
132 if (pplayer != p1
133 && pplayer != p2
134 && ds == DS_WAR /* Do not count 'never met' as war here */
135 && pplayers_allied(p2, pplayer)) {
136 return FALSE;
137 }
138 } players_iterate_alive_end;
139
140 return TRUE;
141}
142
143/*******************************************************************/
153 enum dipl_reason pplayer_can_make_treaty(const struct player *p1,
154 const struct player *p2,
155 enum diplstate_type treaty)
156{
157 enum diplstate_type existing = player_diplstate_get(p1, p2)->type;
158
159 if (players_on_same_team(p1, p2)) {
160 /* This includes the case p1 == p2 */
161 return DIPL_ERROR;
162 }
163 if (get_player_bonus(p1, EFT_NO_DIPLOMACY) > 0
164 || get_player_bonus(p2, EFT_NO_DIPLOMACY) > 0) {
165 return DIPL_ERROR;
166 }
167 if (treaty == DS_WAR
168 || treaty == DS_NO_CONTACT
169 || treaty == DS_ARMISTICE
170 || treaty == DS_TEAM
171 || treaty == DS_LAST) {
172 return DIPL_ERROR; /* These are not negotiable treaties */
173 }
174 if (treaty == DS_CEASEFIRE && existing != DS_WAR) {
175 return DIPL_ERROR; /* Only available from war */
176 }
177 if (treaty == DS_PEACE
178 && (existing != DS_WAR && existing != DS_CEASEFIRE)) {
179 return DIPL_ERROR;
180 }
181 if (treaty == DS_ALLIANCE) {
182 if (!is_valid_alliance(p1, p2)) {
183 /* Our war with a third party prevents entry to alliance. */
184 return DIPL_ALLIANCE_PROBLEM_US;
185 } else if (!is_valid_alliance(p2, p1)) {
186 /* Their war with a third party prevents entry to alliance. */
187 return DIPL_ALLIANCE_PROBLEM_THEM;
188 }
189 }
190 /* This check must be last: */
191 if (treaty == existing) {
192 return DIPL_ERROR;
193 }
194
195 return DIPL_OK;
196}
197
198/*******************************************************************/
202 bool player_has_embassy(const struct player *pplayer,
203 const struct player *pplayer2)
204{
205 return (pplayer == pplayer2
206 || player_has_real_embassy(pplayer, pplayer2)
207 || player_has_embassy_from_effect(pplayer, pplayer2));
208}
209
210/*******************************************************************/
214 bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
215{
216 if (tgt_player->team == pteam) {
217 return TRUE;
218 }
219
220 player_list_iterate(team_members(pteam), teammate) {
221 if (player_has_real_embassy(teammate, tgt_player)
222 || player_has_embassy_from_effect(teammate, tgt_player)) {
223 return TRUE;
224 }
225 } player_list_iterate_end;
226
227 return FALSE;
228}
229
230/*******************************************************************/
234 bool player_has_real_embassy(const struct player *pplayer,
235 const struct player *pplayer2)
236{
237 return BV_ISSET(pplayer->real_embassy, player_index(pplayer2));
238}
239
240/*******************************************************************/
244 bool player_has_embassy_from_effect(const struct player *pplayer,
245 const struct player *pplayer2)
246{
247 return (get_player_bonus(pplayer, EFT_HAVE_EMBASSIES) > 0
248 && player_diplstate_get(pplayer, pplayer2)->type != DS_NO_CONTACT
249 && !is_barbarian(pplayer2));
250}
251
252/*******************************************************************/
255 bool player_owns_city(const struct player *pplayer, const struct city *pcity)
256{
257 return (pcity && pplayer && city_owner(pcity) == pplayer);
258}
259
260/*******************************************************************/
264 bool player_can_invade_tile(const struct player *pplayer,
265 const struct tile *ptile)
266{
267 const struct player *ptile_owner = tile_owner(ptile);
268
269 return (!ptile_owner
270 || ptile_owner == pplayer
271 || !players_non_invade(pplayer, ptile_owner));
272}
273
274/*******************************************************************/
278 static void player_diplstate_new(const struct player *plr1,
279 const struct player *plr2)
280{
281 struct player_diplstate *diplstate;
282
283 fc_assert_ret(plr1 != NULL);
284 fc_assert_ret(plr2 != NULL);
285
286 const struct player_diplstate **diplstate_slot
287 = plr1->diplstates + player_index(plr2);
288
289 fc_assert_ret(*diplstate_slot == NULL);
290
291 diplstate = fc_calloc(1, sizeof(*diplstate));
292 *diplstate_slot = diplstate;
293}
294
295/*******************************************************************/
298 static void player_diplstate_defaults(const struct player *plr1,
299 const struct player *plr2)
300{
301 struct player_diplstate *diplstate = player_diplstate_get(plr1, plr2);
302
303 fc_assert_ret(diplstate != NULL);
304
305 diplstate->type = DS_NO_CONTACT;
306 diplstate->max_state = DS_NO_CONTACT;
307 diplstate->first_contact_turn = 0;
308 diplstate->turns_left = 0;
309 diplstate->has_reason_to_cancel = 0;
310 diplstate->contact_turns_left = 0;
311 diplstate->auto_cancel_turn = -1;
312}
313
314/*******************************************************************/
317 struct player_diplstate *player_diplstate_get(const struct player *plr1,
318 const struct player *plr2)
319{
320 fc_assert_ret_val(plr1 != NULL, NULL);
321 fc_assert_ret_val(plr2 != NULL, NULL);
322
323 const struct player_diplstate **diplstate_slot
324 = plr1->diplstates + player_index(plr2);
325
326 fc_assert_ret_val(*diplstate_slot != NULL, NULL);
327
328 return (struct player_diplstate *) *diplstate_slot;
329}
330
331/*******************************************************************/
334 static void player_diplstate_destroy(const struct player *plr1,
335 const struct player *plr2)
336{
337 fc_assert_ret(plr1 != NULL);
338 fc_assert_ret(plr2 != NULL);
339
340 const struct player_diplstate **diplstate_slot
341 = plr1->diplstates + player_index(plr2);
342
343 if (*diplstate_slot != NULL) {
344 free(player_diplstate_get(plr1, plr2));
345 }
346
347 *diplstate_slot = NULL;
348}
349
350/*******************************************************************/
353 void player_slots_init(void)
354{
355 int i;
356
357 /* Init player slots. */
358 player_slots.slots = fc_calloc(player_slot_count(),
359 sizeof(*player_slots.slots));
360 /* Can't use the defined functions as the needed data will be
361 * defined here. */
362 for (i = 0; i < player_slot_count(); i++) {
363 player_slots.slots[i].player = NULL;
364 }
365 player_slots.used_slots = 0;
366}
367
368/*******************************************************************/
371 bool player_slots_initialised(void)
372{
373 return (player_slots.slots != NULL);
374}
375
376/*******************************************************************/
379 void player_slots_free(void)
380{
381 players_iterate(pplayer) {
382 player_destroy(pplayer);
383 } players_iterate_end;
384 free(player_slots.slots);
385 player_slots.slots = NULL;
386 player_slots.used_slots = 0;
387}
388
389/*******************************************************************/
392 struct player_slot *player_slot_first(void)
393{
394 return player_slots.slots;
395}
396
397/*******************************************************************/
400 struct player_slot *player_slot_next(struct player_slot *pslot)
401{
402 pslot++;
403 return (pslot < player_slots.slots + player_slot_count() ? pslot : NULL);
404}
405
406/*******************************************************************/
411 int player_slot_count(void)
412{
413 return (MAX_NUM_PLAYER_SLOTS);
414}
415
416/*******************************************************************/
419 int player_slot_index(const struct player_slot *pslot)
420{
421 fc_assert_ret_val(NULL != pslot, -1);
422
423 return pslot - player_slots.slots;
424}
425
426/*******************************************************************/
430 struct player *player_slot_get_player(const struct player_slot *pslot)
431{
432 fc_assert_ret_val(NULL != pslot, NULL);
433
434 return pslot->player;
435}
436
437/*******************************************************************/
441 bool player_slot_is_used(const struct player_slot *pslot)
442{
443 fc_assert_ret_val(NULL != pslot, FALSE);
444
445 /* No player slot available, if the game is not initialised. */
446 if (!player_slots_initialised()) {
447 return FALSE;
448 }
449
450 return NULL != pslot->player;
451}
452
453/*******************************************************************/
456 struct player_slot *player_slot_by_number(int player_id)
457{
458 if (!player_slots_initialised()
459 || !(0 <= player_id && player_id < player_slot_count())) {
460 return NULL;
461 }
462
463 return player_slots.slots + player_id;
464}
465
466/*******************************************************************/
469 int player_slot_max_used_number(void)
470{
471 int max_pslot = 0;
472
473 player_slots_iterate(pslot) {
474 if (player_slot_is_used(pslot)) {
475 max_pslot = player_slot_index(pslot);
476 }
477 } player_slots_iterate_end;
478
479 return max_pslot;
480}
481
482/*******************************************************************/
486 struct player *player_new(struct player_slot *pslot)
487{
488 struct player *pplayer;
489
490 fc_assert_ret_val(player_slots_initialised(), NULL);
491
492 if (pslot == NULL) {
493 player_slots_iterate(aslot) {
494 if (!player_slot_is_used(aslot)) {
495 pslot = aslot;
496 break;
497 }
498 } player_slots_iterate_end;
499
500 if (pslot == NULL) {
501 return NULL;
502 }
503 } else if (NULL != pslot->player) {
504 return pslot->player;
505 }
506
507 /* Now create the player. */
508 log_debug("Create player for slot %d.", player_slot_index(pslot));
509 pplayer = fc_calloc(1, sizeof(*pplayer));
510 pplayer->slot = pslot;
511 pslot->player = pplayer;
512
513 pplayer->diplstates = fc_calloc(player_slot_count(),
514 sizeof(*pplayer->diplstates));
515 player_slots_iterate(dslot) {
516 const struct player_diplstate **diplstate_slot
517 = pplayer->diplstates + player_slot_index(dslot);
518
519 *diplstate_slot = NULL;
520 } player_slots_iterate_end;
521
522 players_iterate(aplayer) {
523 /* Create diplomatic states for all other players. */
524 player_diplstate_new(pplayer, aplayer);
525 /* Create diplomatic state of this player. */
526 if (aplayer != pplayer) {
527 player_diplstate_new(aplayer, pplayer);
528 }
529 } players_iterate_end;
530
531 /* Set default values. */
532 player_defaults(pplayer);
533
534 /* Increase number of players. */
535 player_slots.used_slots++;
536
537 return pplayer;
538}
539
540/*******************************************************************/
544 static void player_defaults(struct player *pplayer)
545{
546 int i;
547
548 sz_strlcpy(pplayer->name, ANON_PLAYER_NAME);
549 sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
550 pplayer->unassigned_user = TRUE;
551 sz_strlcpy(pplayer->ranked_username, _(ANON_USER_NAME));
552 pplayer->unassigned_ranked = TRUE;
553 pplayer->user_turns = 0;
554 pplayer->is_male = TRUE;
555 pplayer->government = NULL;
556 pplayer->target_government = NULL;
557 pplayer->nation = NO_NATION_SELECTED;
558 pplayer->team = NULL;
559 pplayer->is_ready = FALSE;
560 pplayer->nturns_idle = 0;
561 pplayer->is_alive = TRUE;
562 pplayer->turns_alive = 0;
563 pplayer->is_winner = FALSE;
564 pplayer->last_war_action = -1;
565 pplayer->phase_done = FALSE;
566
567 pplayer->revolution_finishes = -1;
568 pplayer->primary_capital_id = 0;
569
570 BV_CLR_ALL(pplayer->real_embassy);
571 players_iterate(aplayer) {
572 /* create diplomatic states for all other players */
573 player_diplstate_defaults(pplayer, aplayer);
574 /* create diplomatic state of this player */
575 if (aplayer != pplayer) {
576 player_diplstate_defaults(aplayer, pplayer);
577 }
578 } players_iterate_end;
579
580 pplayer->style = 0;
581 pplayer->music_style = -1; /* even getting value 0 triggers change */
582 pplayer->cities = city_list_new();
583 pplayer->units = unit_list_new();
584
585 pplayer->economic.gold = 0;
586 pplayer->economic.tax = PLAYER_DEFAULT_TAX_RATE;
587 pplayer->economic.science = PLAYER_DEFAULT_SCIENCE_RATE;
588 pplayer->economic.luxury = PLAYER_DEFAULT_LUXURY_RATE;
589 pplayer->economic.infra_points = 0;
590
591 spaceship_init(&pplayer->spaceship);
592
593 BV_CLR_ALL(pplayer->flags);
594
595 set_as_human(pplayer);
596 pplayer->ai_common.skill_level = ai_level_invalid();
597 pplayer->ai_common.fuzzy = 0;
598 pplayer->ai_common.expand = 100;
599 pplayer->ai_common.barbarian_type = NOT_A_BARBARIAN;
600 player_slots_iterate(pslot) {
601 pplayer->ai_common.love[player_slot_index(pslot)] = 1;
602 } player_slots_iterate_end;
603 pplayer->ai_common.traits = NULL;
604
605 pplayer->ai = NULL;
606 pplayer->was_created = FALSE;
607 pplayer->savegame_ai_type_name = NULL;
608 pplayer->random_name = TRUE;
609 pplayer->is_connected = FALSE;
610 pplayer->current_conn = NULL;
611 pplayer->connections = conn_list_new();
612 BV_CLR_ALL(pplayer->gives_shared_vision);
613 for (i = 0; i < B_LAST; i++) {
614 pplayer->wonders[i] = WONDER_NOT_BUILT;
615 }
616
617 pplayer->attribute_block.data = NULL;
618 pplayer->attribute_block.length = 0;
619 pplayer->attribute_block_buffer.data = NULL;
620 pplayer->attribute_block_buffer.length = 0;
621
622 pplayer->tile_known.vec = NULL;
623 pplayer->tile_known.bits = 0;
624
625 pplayer->rgb = NULL;
626
627 memset(pplayer->multipliers, 0, sizeof(pplayer->multipliers));
628
629 /* pplayer->server is initialised in
630 ./server/plrhand.c:server_player_init()
631 and pplayer->client in
632 ./client/climisc.c:client_player_init() */
633}
634
635/*******************************************************************/
639 void player_set_color(struct player *pplayer,
640 const struct rgbcolor *prgbcolor)
641{
642 if (pplayer->rgb != NULL) {
643 rgbcolor_destroy(pplayer->rgb);
644 pplayer->rgb = NULL;
645 }
646
647 if (prgbcolor) {
648 pplayer->rgb = rgbcolor_copy(prgbcolor);
649 }
650}
651
652/*******************************************************************/
660 void player_clear(struct player *pplayer, bool full)
661{
662 bool client = !is_server();
663
664 if (pplayer == NULL) {
665 return;
666 }
667
668 if (pplayer->savegame_ai_type_name != NULL) {
669 free(pplayer->savegame_ai_type_name);
670 pplayer->savegame_ai_type_name = NULL;
671 }
672
673 /* Clears the attribute blocks. */
674 if (pplayer->attribute_block.data) {
675 free(pplayer->attribute_block.data);
676 pplayer->attribute_block.data = NULL;
677 }
678 pplayer->attribute_block.length = 0;
679
680 if (pplayer->attribute_block_buffer.data) {
681 free(pplayer->attribute_block_buffer.data);
682 pplayer->attribute_block_buffer.data = NULL;
683 }
684 pplayer->attribute_block_buffer.length = 0;
685
686 /* Clears units and cities. */
687 unit_list_iterate(pplayer->units, punit) {
688 /* Unload all cargos. */
689 unit_list_iterate(unit_transport_cargo(punit), pcargo) {
690 unit_transport_unload(pcargo);
691 if (client) {
692 pcargo->client.transported_by = -1;
693 }
694 } unit_list_iterate_end;
695 /* Unload the unit. */
696 unit_transport_unload(punit);
697 if (client) {
698 punit->client.transported_by = -1;
699 }
700
701 game_remove_unit(&wld, punit);
702 } unit_list_iterate_end;
703
704 city_list_iterate(pplayer->cities, pcity) {
705 if (fc_funcs->destroy_city != NULL) {
706 fc_funcs->destroy_city(pcity);
707 } else {
708 game_remove_city(&wld, pcity);
709 }
710 } city_list_iterate_end;
711
712 if (full) {
713 team_remove_player(pplayer);
714
715 players_iterate_alive(owner) {
716 unit_list_iterate(owner->units, owned) {
717 if (unit_nationality(owned) == pplayer) {
718 /* Switch nationality to that of current owner. */
719 owned->nationality = owner;
720 }
721 } unit_list_iterate_end;
722 } players_iterate_alive_end;
723
724 /* This comes last because log calls in the above functions
725 * may use it. */
726 if (pplayer->nation != NULL) {
727 player_set_nation(pplayer, NULL);
728 }
729 }
730}
731
732/*******************************************************************/
736 void player_ruleset_close(struct player *pplayer)
737{
738 pplayer->government = NULL;
739 pplayer->target_government = NULL;
740 player_set_nation(pplayer, NULL);
741 pplayer->style = NULL;
742}
743
744/*******************************************************************/
747 void player_destroy(struct player *pplayer)
748{
749 struct player_slot *pslot;
750
751 fc_assert_ret(NULL != pplayer);
752
753 pslot = pplayer->slot;
754 fc_assert(pslot->player == pplayer);
755
756 /* Remove all that is game-dependent in the player structure. */
757 player_clear(pplayer, TRUE);
758
759 fc_assert(0 == unit_list_size(pplayer->units));
760 unit_list_destroy(pplayer->units);
761 fc_assert(0 == city_list_size(pplayer->cities));
762 city_list_destroy(pplayer->cities);
763
764 fc_assert(conn_list_size(pplayer->connections) == 0);
765 conn_list_destroy(pplayer->connections);
766
767 players_iterate(aplayer) {
768 /* Destroy the diplomatic states of this player with others ... */
769 player_diplstate_destroy(pplayer, aplayer);
770 /* ...and of others with this player. */
771 if (aplayer != pplayer) {
772 player_diplstate_destroy(aplayer, pplayer);
773
774 /* Check if any cities of the other player have been founded
775 * by the removed player. */
776 city_list_iterate(aplayer->cities, pcity) {
777 if (pcity->original == pplayer) {
778 /* Unknown origin is better than giving baseless
779 * benefits to current owner */
780 pcity->original = NULL;
781 }
782 } city_list_iterate_end;
783 }
784 } players_iterate_end;
785 free(pplayer->diplstates);
786
787 /* Clear player color. */
788 if (pplayer->rgb) {
789 rgbcolor_destroy(pplayer->rgb);
790 }
791
792 dbv_free(&pplayer->tile_known);
793
794 if (!is_server()) {
795 vision_layer_iterate(v) {
796 dbv_free(&pplayer->client.tile_vision[v]);
797 } vision_layer_iterate_end;
798 }
799
800 free(pplayer);
801 pslot->player = NULL;
802 player_slots.used_slots--;
803}
804
805/*******************************************************************/
808 int player_count(void)
809{
810 return player_slots.used_slots;
811}
812
813/*******************************************************************/
820 int player_index(const struct player *pplayer)
821{
822 return player_number(pplayer);
823}
824
825/*******************************************************************/
828 int player_number(const struct player *pplayer)
829{
830 fc_assert_ret_val(NULL != pplayer, -1);
831 return player_slot_index(pplayer->slot);
832}
833
834/*******************************************************************/
840 struct player *player_by_number(const int player_id)
841{
842 struct player_slot *pslot = player_slot_by_number(player_id);
843
844 return (NULL != pslot ? player_slot_get_player(pslot) : NULL);
845}
846
847/*******************************************************************/
852 bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
853{
854 if (pplayer->nation != pnation) {
855 if (pplayer->nation) {
856 fc_assert(pplayer->nation->player == pplayer);
857 pplayer->nation->player = NULL;
858 }
859 if (pnation) {
860 fc_assert(pnation->player == NULL);
861 pnation->player = pplayer;
862 }
863 pplayer->nation = pnation;
864 return TRUE;
865 }
866 return FALSE;
867}
868
869/*******************************************************************/
872 struct player *player_by_name(const char *name)
873{
874 players_iterate(pplayer) {
875 if (fc_strcasecmp(name, pplayer->name) == 0) {
876 return pplayer;
877 }
878 } players_iterate_end;
879
880 return NULL;
881}
882
883/*******************************************************************/
886 const char *player_name(const struct player *pplayer)
887{
888 if (!pplayer) {
889 return NULL;
890 }
891 return pplayer->name;
892}
893
894/*******************************************************************/
900 static const char *player_name_by_number(int i)
901{
902 struct player *pplayer;
903
904 pplayer = player_by_number(i);
905 return player_name(pplayer);
906}
907
908/*******************************************************************/
911 struct player *player_by_name_prefix(const char *name,
912 enum m_pre_result *result)
913{
914 int ind;
915
916 *result = match_prefix(player_name_by_number,
917 player_slot_count(), MAX_LEN_NAME - 1,
918 fc_strncasequotecmp, effectivestrlenquote,
919 name, &ind);
920
921 if (*result < M_PRE_AMBIGUOUS) {
922 return player_by_number(ind);
923 } else {
924 return NULL;
925 }
926}
927
928/*******************************************************************/
931 struct player *player_by_user(const char *name)
932{
933 players_iterate(pplayer) {
934 if (fc_strcasecmp(name, pplayer->username) == 0) {
935 return pplayer;
936 }
937 } players_iterate_end;
938
939 return NULL;
940}
941
942/*******************************************************************/
945 int player_age(const struct player *pplayer)
946{
947 fc_assert_ret_val(pplayer != NULL, 0);
948 return pplayer->turns_alive;
949}
950
951/*******************************************************************/
958 bool player_can_trust_tile_has_no_units(const struct player *pplayer,
959 const struct tile *ptile)
960{
961 /* Can't see invisible units. */
962 if (!fc_funcs->player_tile_vision_get(ptile, pplayer, V_INVIS)
963 || !fc_funcs->player_tile_vision_get(ptile, pplayer, V_SUBSURFACE)) {
964 return FALSE;
965 }
966
967 /* Units within some extras may be hidden. */
968 if (!pplayers_allied(pplayer, ptile->extras_owner)) {
969 extra_type_list_iterate(extra_type_list_of_unit_hiders(), pextra) {
970 if (tile_has_extra(ptile, pextra)) {
971 return FALSE;
972 }
973 } extra_type_list_iterate_end;
974 }
975
976 return TRUE;
977}
978
979/*******************************************************************/
984 bool can_player_see_hypotetic_units_at(const struct player *pplayer,
985 const struct tile *ptile)
986{
987 struct city *pcity;
988
989 if (!player_can_trust_tile_has_no_units(pplayer, ptile)) {
990 /* The existence of any units at all is hidden from the player. */
991 return FALSE;
992 }
993
994 /* Can't see city units. */
995 pcity = tile_city(ptile);
996 if (pcity && !can_player_see_units_in_city(pplayer, pcity)
997 && unit_list_size(ptile->units) > 0) {
998 return FALSE;
999 }
1000
1001 /* Can't see non-allied units in transports. */
1002 unit_list_iterate(ptile->units, punit) {
1003 if (unit_type_get(punit)->transport_capacity > 0
1004 && unit_owner(punit) != pplayer) {
1005
1006 /* An ally could transport a non ally */
1007 if (unit_list_size(punit->transporting) > 0) {
1008 return FALSE;
1009 }
1010 }
1011 } unit_list_iterate_end;
1012
1013 return TRUE;
1014}
1015
1016/*******************************************************************/
1025 bool can_player_see_unit_at(const struct player *pplayer,
1026 const struct unit *punit,
1027 const struct tile *ptile,
1028 bool is_transported)
1029{
1030 struct city *pcity;
1031 bool allied;
1032 struct unit_class *pclass;
1033
1034 /* If the player can't even see the tile... */
1035 if (TILE_KNOWN_SEEN != tile_get_known(ptile, pplayer)) {
1036 return FALSE;
1037 }
1038
1039 /* Don't show non-allied units that are in transports. This is logical
1040 * because allied transports can also contain our units. Shared vision
1041 * isn't taken into account. */
1042 allied = pplayers_allied(pplayer, unit_owner(punit));
1043 if (is_transported && !allied) {
1044 return FALSE;
1045 }
1046
1047 /* Units in cities may be hidden. */
1048 pcity = tile_city(ptile);
1049 if (pcity && !can_player_see_units_in_city(pplayer, pcity)) {
1050 return FALSE;
1051 }
1052
1053 /* Allied units are always seen.
1054 * See also stealth unit hiding part in map_change_seen() */
1055 if (allied) {
1056 return TRUE;
1057 }
1058
1059 /* Units within some extras may be hidden. */
1060 pclass = unit_class_get(punit);
1061
1062 extra_type_list_iterate(pclass->cache.hiding_extras, pextra) {
1063 if (tile_has_extra(ptile, pextra)) {
1064 return FALSE;
1065 }
1066 } extra_type_list_iterate_end;
1067
1068 /* Non-hiding units are always seen.
1069 * See also stealth unit hiding part in map_change_seen() */
1070 if (!is_hiding_unit(punit)) {
1071 return TRUE;
1072 }
1073
1074 /* Hiding units are only seen by the V_INVIS fog layer. */
1075 return fc_funcs->player_tile_vision_get(ptile, pplayer,
1076 unit_type_get(punit)->vlayer);
1077}
1078
1079/*******************************************************************/
1084 bool can_player_see_unit(const struct player *pplayer,
1085 const struct unit *punit)
1086{
1087 return can_player_see_unit_at(pplayer, punit, unit_tile(punit),
1088 unit_transported(punit));
1089}
1090
1091/*******************************************************************/
1113 bool can_player_see_units_in_city(const struct player *pplayer,
1114 const struct city *pcity)
1115{
1116 return (!pplayer
1117 || can_player_see_city_internals(pplayer, pcity)
1118 || pplayers_allied(pplayer, city_owner(pcity)));
1119}
1120
1121/*******************************************************************/
1129 bool can_player_see_city_internals(const struct player *pplayer,
1130 const struct city *pcity)
1131{
1132 return (!pplayer || pplayer == city_owner(pcity));
1133}
1134
1135/*******************************************************************/
1143 bool player_can_see_city_externals(const struct player *pow_player,
1144 const struct city *target_city) {
1145 fc_assert_ret_val(target_city, FALSE);
1146 fc_assert_ret_val(pow_player, FALSE);
1147
1148 if (can_player_see_city_internals(pow_player, target_city)) {
1149 /* City internals includes city externals. */
1150 return TRUE;
1151 }
1152
1153 if (tile_is_seen(city_tile(target_city), pow_player)) {
1154 /* The tile is being observed. */
1155 return TRUE;
1156 }
1157
1158 fc_assert_ret_val(target_city->routes, FALSE);
1159
1160 trade_partners_iterate(target_city, trade_city) {
1161 if (city_owner(trade_city) == pow_player) {
1162 /* Revealed because of the trade route. */
1163 return TRUE;
1164 }
1165 } trade_partners_iterate_end;
1166
1167 return FALSE;
1168}
1169
1170/*******************************************************************/
1179 struct city *player_city_by_number(const struct player *pplayer, int city_id)
1180{
1181 /* We call idex directly. Should use game_city_by_number() instead? */
1182 struct city *pcity = idex_lookup_city(&wld, city_id);
1183
1184 if (!pcity) {
1185 return NULL;
1186 }
1187
1188 if (!pplayer || (city_owner(pcity) == pplayer)) {
1189 /* Correct owner */
1190 return pcity;
1191 }
1192
1193 return NULL;
1194}
1195
1196/*******************************************************************/
1205 struct unit *player_unit_by_number(const struct player *pplayer, int unit_id)
1206{
1207 /* We call idex directly. Should use game_unit_by_number() instead? */
1208 struct unit *punit = idex_lookup_unit(&wld, unit_id);
1209
1210 if (!punit) {
1211 return NULL;
1212 }
1213
1214 if (!pplayer || (unit_owner(punit) == pplayer)) {
1215 /* Correct owner */
1216 return punit;
1217 }
1218
1219 return NULL;
1220}
1221
1222/*******************************************************************/
1225 bool player_in_city_map(const struct player *pplayer,
1226 const struct tile *ptile)
1227{
1228 const struct civ_map *nmap = &(wld.map);
1229
1230 city_tile_iterate(nmap, CITY_MAP_MAX_RADIUS_SQ, ptile, ptile1) {
1231 struct city *pcity = tile_city(ptile1);
1232
1233 if (pcity
1234 && (pplayer == NULL || city_owner(pcity) == pplayer)
1235 && city_map_radius_sq_get(pcity) >= sq_map_distance(ptile,
1236 ptile1)) {
1237 return TRUE;
1238 }
1239 } city_tile_iterate_end;
1240
1241 return FALSE;
1242}
1243
1244/*******************************************************************/
1249 int num_known_tech_with_flag(const struct player *pplayer,
1250 enum tech_flag_id flag)
1251{
1252 return research_get(pplayer)->num_known_tech_with_flag[flag];
1253}
1254
1255/*******************************************************************/
1262 int player_get_expected_income(const struct player *pplayer)
1263{
1264 int income = 0;
1265
1266 /* City income/expenses. */
1267 city_list_iterate(pplayer->cities, pcity) {
1268 /* Gold suplus accounts for imcome plus building and unit upkeep. */
1269 income += pcity->surplus[O_GOLD];
1270
1271 /* Gold upkeep for buildings and units is defined by the setting
1272 * 'game.info.gold_upkeep_style':
1273 * GOLD_UPKEEP_CITY: Cities pay for buildings and units (this is
1274 * included in pcity->surplus[O_GOLD]).
1275 * GOLD_UPKEEP_MIXED: Cities pay only for buildings; the nation pays
1276 * for units.
1277 * GOLD_UPKEEP_NATION: The nation pays for buildings and units. */
1278 switch (game.info.gold_upkeep_style) {
1279 case GOLD_UPKEEP_CITY:
1280 break;
1281 case GOLD_UPKEEP_NATION:
1282 /* Nation pays for buildings (and units). */
1283 income -= city_total_impr_gold_upkeep(pcity);
1284 fc__fallthrough; /* No break. */
1285 case GOLD_UPKEEP_MIXED:
1286 /* Nation pays for units. */
1287 income -= city_total_unit_gold_upkeep(pcity);
1288 break;
1289 }
1290
1291 /* Capitalization income. */
1292 if (city_production_has_flag(pcity, IF_GOLD)) {
1293 income += pcity->shield_stock + pcity->surplus[O_SHIELD];
1294 }
1295 } city_list_iterate_end;
1296
1297 return income;
1298}
1299
1300/*******************************************************************/
1304 bool player_knows_techs_with_flag(const struct player *pplayer,
1305 enum tech_flag_id flag)
1306{
1307 return num_known_tech_with_flag(pplayer, flag) > 0;
1308}
1309
1310/*******************************************************************/
1313 struct city *player_primary_capital(const struct player *pplayer)
1314{
1315 struct city *capital;
1316
1317 if (!pplayer) {
1318 /* The client depends on this behavior in some places. */
1319 return NULL;
1320 }
1321
1322 capital = player_city_by_number(pplayer, pplayer->primary_capital_id);
1323
1324 return capital;
1325}
1326
1327/*******************************************************************/
1330 const char *love_text(const int love)
1331{
1332 if (love <= - MAX_AI_LOVE * 90 / 100) {
1333 /* TRANS: These words should be adjectives which can fit in the sentence
1334 "The x are y towards us"
1335 "The Babylonians are respectful towards us" */
1336 return Q_("?attitude:Genocidal");
1337 } else if (love <= - MAX_AI_LOVE * 70 / 100) {
1338 return Q_("?attitude:Belligerent");
1339 } else if (love <= - MAX_AI_LOVE * 50 / 100) {
1340 return Q_("?attitude:Hostile");
1341 } else if (love <= - MAX_AI_LOVE * 25 / 100) {
1342 return Q_("?attitude:Uncooperative");
1343 } else if (love <= - MAX_AI_LOVE * 10 / 100) {
1344 return Q_("?attitude:Uneasy");
1345 } else if (love <= MAX_AI_LOVE * 10 / 100) {
1346 return Q_("?attitude:Neutral");
1347 } else if (love <= MAX_AI_LOVE * 25 / 100) {
1348 return Q_("?attitude:Respectful");
1349 } else if (love <= MAX_AI_LOVE * 50 / 100) {
1350 return Q_("?attitude:Helpful");
1351 } else if (love <= MAX_AI_LOVE * 70 / 100) {
1352 return Q_("?attitude:Enthusiastic");
1353 } else if (love <= MAX_AI_LOVE * 90 / 100) {
1354 return Q_("?attitude:Admiring");
1355 } else {
1356 fc_assert(love > MAX_AI_LOVE * 90 / 100);
1357 return Q_("?attitude:Worshipful");
1358 }
1359}
1360
1361/*******************************************************************/
1364 bool pplayers_at_war(const struct player *pplayer,
1365 const struct player *pplayer2)
1366{
1367 enum diplstate_type ds;
1368
1369 if (pplayer == pplayer2) {
1370 return FALSE;
1371 }
1372
1373 ds = player_diplstate_get(pplayer, pplayer2)->type;
1374
1375 return ds == DS_WAR || ds == DS_NO_CONTACT;
1376}
1377
1378/*******************************************************************/
1381 bool pplayers_allied(const struct player *pplayer,
1382 const struct player *pplayer2)
1383{
1384 enum diplstate_type ds;
1385
1386 if (!pplayer || !pplayer2) {
1387 return FALSE;
1388 }
1389
1390 if (pplayer == pplayer2) {
1391 return TRUE;
1392 }
1393
1394 ds = player_diplstate_get(pplayer, pplayer2)->type;
1395
1396 return (ds == DS_ALLIANCE || ds == DS_TEAM);
1397}
1398
1399/*******************************************************************/
1402 bool pplayers_in_peace(const struct player *pplayer,
1403 const struct player *pplayer2)
1404{
1405 enum diplstate_type ds = player_diplstate_get(pplayer, pplayer2)->type;
1406
1407 if (pplayer == pplayer2) {
1408 return TRUE;
1409 }
1410
1411 return (ds == DS_PEACE || ds == DS_ALLIANCE
1412 || ds == DS_ARMISTICE || ds == DS_TEAM);
1413}
1414
1415/*******************************************************************/
1418 bool players_non_invade(const struct player *pplayer1,
1419 const struct player *pplayer2)
1420{
1421 if (pplayer1 == pplayer2 || !pplayer1 || !pplayer2) {
1422 return FALSE;
1423 }
1424
1425 /* Movement during armistice is allowed so that player can withdraw
1426 units deeper inside opponent territory. */
1427
1428 return player_diplstate_get(pplayer1, pplayer2)->type == DS_PEACE;
1429}
1430
1431/*******************************************************************/
1435 bool pplayers_non_attack(const struct player *pplayer,
1436 const struct player *pplayer2)
1437{
1438 enum diplstate_type ds;
1439
1440 if (pplayer == pplayer2) {
1441 return FALSE;
1442 }
1443
1444 ds = player_diplstate_get(pplayer, pplayer2)->type;
1445
1446 return (ds == DS_PEACE || ds == DS_CEASEFIRE || ds == DS_ARMISTICE);
1447}
1448
1449/*******************************************************************/
1452 bool players_on_same_team(const struct player *pplayer1,
1453 const struct player *pplayer2)
1454{
1455 return pplayer1->team == pplayer2->team;
1456}
1457
1458/*******************************************************************/
1461 bool gives_shared_vision(const struct player *me, const struct player *them)
1462{
1463 return BV_ISSET(me->gives_shared_vision, player_index(them));
1464}
1465
1466/*******************************************************************/
1469 bool are_diplstates_equal(const struct player_diplstate *pds1,
1470 const struct player_diplstate *pds2)
1471{
1472 return (pds1->type == pds2->type && pds1->turns_left == pds2->turns_left
1473 && pds1->has_reason_to_cancel == pds2->has_reason_to_cancel
1474 && pds1->contact_turns_left == pds2->contact_turns_left);
1475}
1476
1477/*******************************************************************/
1480 bool is_diplrel_between(const struct player *player1,
1481 const struct player *player2,
1482 int diplrel)
1483{
1484 fc_assert(player1 != NULL);
1485 fc_assert(player2 != NULL);
1486
1487 /* No relationship to it self. */
1488 if (player1 == player2 && diplrel != DRO_FOREIGN) {
1489 return FALSE;
1490 }
1491
1492 if (diplrel < DS_LAST) {
1493 return player_diplstate_get(player1, player2)->type == diplrel;
1494 }
1495
1496 switch (diplrel) {
1497 case DRO_GIVES_SHARED_VISION:
1498 return gives_shared_vision(player1, player2);
1499 case DRO_RECEIVES_SHARED_VISION:
1500 return gives_shared_vision(player2, player1);
1501 case DRO_HOSTS_EMBASSY:
1502 return player_has_embassy(player2, player1);
1503 case DRO_HAS_EMBASSY:
1504 return player_has_embassy(player1, player2);
1505 case DRO_HOSTS_REAL_EMBASSY:
1506 return player_has_real_embassy(player2, player1);
1507 case DRO_HAS_REAL_EMBASSY:
1508 return player_has_real_embassy(player1, player2);
1509 case DRO_HAS_CASUS_BELLI:
1510 return 0 < player_diplstate_get(player1, player2)->has_reason_to_cancel;
1511 case DRO_PROVIDED_CASUS_BELLI:
1512 return 0 < player_diplstate_get(player2, player1)->has_reason_to_cancel;
1513 case DRO_FOREIGN:
1514 return player1 != player2;
1515 }
1516
1517 fc_assert_msg(FALSE, "diplrel_between(): invalid diplrel number %d.",
1518 diplrel);
1519
1520 return FALSE;
1521}
1522
1523/*******************************************************************/
1526 bool is_diplrel_to_other(const struct player *pplayer, int diplrel)
1527{
1528 fc_assert(pplayer != NULL);
1529
1530 players_iterate_alive(oplayer) {
1531 if (oplayer == pplayer) {
1532 continue;
1533 }
1534 if (is_diplrel_between(pplayer, oplayer, diplrel)) {
1535 return TRUE;
1536 }
1537 } players_iterate_alive_end;
1538 return FALSE;
1539}
1540
1541/*******************************************************************/
1545 int diplrel_by_rule_name(const char *value)
1546{
1547 /* Look for asymmetric diplomatic relations */
1548 int diplrel = diplrel_other_by_name(value, fc_strcasecmp);
1549
1550 if (diplrel != diplrel_other_invalid()) {
1551 return diplrel;
1552 }
1553
1554 /* Look for symmetric diplomatic relations */
1555 diplrel = diplstate_type_by_name(value, fc_strcasecmp);
1556
1557 /*
1558 * Make sure DS_LAST isn't returned as DS_LAST is the first diplrel_other.
1559 *
1560 * Can't happend now. This is in case that changes in the future. */
1561 fc_assert_ret_val(diplrel != DS_LAST, diplrel_other_invalid());
1562
1563 /*
1564 * Make sure that diplrel_other_invalid() is returned.
1565 *
1566 * Can't happen now. At the moment dpilrel_asym_invalid() is the same as
1567 * diplstate_type_invalid(). This is in case that changes in the future.
1568 */
1569 if (diplrel != diplstate_type_invalid()) {
1570 return diplrel;
1571 }
1572
1573 return diplrel_other_invalid();
1574}
1575
1576/*******************************************************************/
1579 const char *diplrel_rule_name(int value)
1580{
1581 if (value < DS_LAST) {
1582 return diplstate_type_name(value);
1583 } else {
1584 return diplrel_other_name(value);
1585 }
1586}
1587
1588/*******************************************************************/
1591 const char *diplrel_name_translation(int value)
1592{
1593 if (value < DS_LAST) {
1594 return diplstate_type_translated_name(value);
1595 } else {
1596 return _(diplrel_other_name(value));
1597 }
1598}
1599
1600/**************************************************************************
1601 Return the Casus Belli range when offender performs paction to tgt_plr
1602 at tgt_tile and the outcome is outcome.
1603**************************************************************************/
1604 enum casus_belli_range casus_belli_range_for(const struct player *offender,
1605 const struct unit_type *off_ut,
1606 const struct player *tgt_plr,
1607 const enum effect_type outcome,
1608 const struct action *paction,
1609 const struct tile *tgt_tile)
1610{
1611 int casus_belli_amount;
1612
1613 /* The victim gets a casus belli if CASUS_BELLI_VICTIM or above. Everyone
1614 * gets a casus belli if CASUS_BELLI_OUTRAGE or above. */
1615 casus_belli_amount =
1616 get_target_bonus_effects(NULL,
1617 &(const struct req_context) {
1618 .player = offender,
1619 .city = tile_city(tgt_tile),
1620 .tile = tgt_tile,
1621 .unittype = off_ut,
1622 .action = paction,
1623 },
1624 tgt_plr,
1625 outcome);
1626
1627 if (casus_belli_amount >= CASUS_BELLI_OUTRAGE) {
1628 /* International outrage: This isn't just between the offender and the
1629 * victim. */
1630 return CBR_INTERNATIONAL_OUTRAGE;
1631 }
1632
1633 if (casus_belli_amount >= CASUS_BELLI_VICTIM) {
1634 /* In this situation the specified action provides a casus belli
1635 * against the actor. */
1636 return CBR_VICTIM_ONLY;
1637 }
1638
1639 return CBR_NONE;
1640}
1641
1642/* The number of mutually exclusive requirement sets that
1643 * diplrel_mess_gen() creates for the DiplRel requirement type. */
1644#define DIPLREL_MESS_SIZE (3 + (DRO_LAST * (5 + 4 + 3 + 2 + 1)))
1645
1646/*******************************************************************/
1654 static bv_diplrel_all_reqs *diplrel_mess_gen(void)
1655{
1656 /* The ranges supported by the DiplRel requiremnt type. */
1657 const enum req_range legal_ranges[] = {
1658 REQ_RANGE_LOCAL,
1659 REQ_RANGE_PLAYER,
1660 REQ_RANGE_ALLIANCE,
1661 REQ_RANGE_TEAM,
1662 REQ_RANGE_WORLD
1663 };
1664
1665 /* Iterators. */
1666 int rel;
1667 int i;
1668 int j;
1669
1670 /* Storage for the mutually exclusive requirement sets. */
1671 bv_diplrel_all_reqs *mess = fc_malloc(DIPLREL_MESS_SIZE
1672 * sizeof(bv_diplrel_all_reqs));
1673
1674 /* Position in mess. */
1675 int mess_pos = 0;
1676
1677 /* The first mutually exclusive set is about local diplstate. */
1678 BV_CLR_ALL(mess[mess_pos]);
1679
1680 /* It is not possible to have more than one diplstate to a nation. */
1681 BV_SET(mess[mess_pos],
1682 requirement_diplrel_ereq(DS_ARMISTICE, REQ_RANGE_LOCAL, TRUE));
1683 BV_SET(mess[mess_pos],
1684 requirement_diplrel_ereq(DS_WAR, REQ_RANGE_LOCAL, TRUE));
1685 BV_SET(mess[mess_pos],
1686 requirement_diplrel_ereq(DS_CEASEFIRE, REQ_RANGE_LOCAL, TRUE));
1687 BV_SET(mess[mess_pos],
1688 requirement_diplrel_ereq(DS_PEACE, REQ_RANGE_LOCAL, TRUE));
1689 BV_SET(mess[mess_pos],
1690 requirement_diplrel_ereq(DS_ALLIANCE, REQ_RANGE_LOCAL, TRUE));
1691 BV_SET(mess[mess_pos],
1692 requirement_diplrel_ereq(DS_NO_CONTACT, REQ_RANGE_LOCAL, TRUE));
1693 BV_SET(mess[mess_pos],
1694 requirement_diplrel_ereq(DS_TEAM, REQ_RANGE_LOCAL, TRUE));
1695
1696 /* It is not possible to have a diplstate to your self. */
1697 BV_SET(mess[mess_pos],
1698 requirement_diplrel_ereq(DRO_FOREIGN, REQ_RANGE_LOCAL, FALSE));
1699
1700 mess_pos++;
1701
1702 /* Having a real embassy excludes not having an embassy. */
1703 BV_CLR_ALL(mess[mess_pos]);
1704
1705 BV_SET(mess[mess_pos],
1706 requirement_diplrel_ereq(DRO_HAS_REAL_EMBASSY, REQ_RANGE_LOCAL,
1707 TRUE));
1708 BV_SET(mess[mess_pos],
1709 requirement_diplrel_ereq(DRO_HAS_EMBASSY, REQ_RANGE_LOCAL,
1710 FALSE));
1711
1712 mess_pos++;
1713
1714 /* Hosting a real embassy excludes not hosting an embassy. */
1715 BV_CLR_ALL(mess[mess_pos]);
1716
1717 BV_SET(mess[mess_pos],
1718 requirement_diplrel_ereq(DRO_HOSTS_REAL_EMBASSY, REQ_RANGE_LOCAL,
1719 TRUE));
1720 BV_SET(mess[mess_pos],
1721 requirement_diplrel_ereq(DRO_HOSTS_EMBASSY, REQ_RANGE_LOCAL,
1722 FALSE));
1723
1724 mess_pos++;
1725
1726 /* Loop over diplstate_type and diplrel_other. */
1727 for (rel = 0; rel < DRO_LAST; rel++) {
1728 /* The presence of a DiplRel at a more local range proves that it can't
1729 * be absent in a more global range. (The alliance range includes the
1730 * Team range) */
1731 for (i = 0; i < 5; i++) {
1732 for (j = i; j < 5; j++) {
1733 BV_CLR_ALL(mess[mess_pos]);
1734
1735 BV_SET(mess[mess_pos],
1736 requirement_diplrel_ereq(rel, legal_ranges[i], TRUE));
1737 BV_SET(mess[mess_pos],
1738 requirement_diplrel_ereq(rel, legal_ranges[j], FALSE));
1739
1740 mess_pos++;
1741 }
1742 }
1743 }
1744
1745 /* No uninitialized element exists. */
1746 fc_assert(mess_pos == DIPLREL_MESS_SIZE);
1747
1748 return mess;
1749}
1750
1751/* An array of mutually exclusive requirement sets for the DiplRel
1752 * requirement type. Is initialized the first time diplrel_mess_get() is
1753 * called. */
1754 static bv_diplrel_all_reqs *diplrel_mess = NULL;
1755
1756/*******************************************************************/
1759 static bv_diplrel_all_reqs *diplrel_mess_get(void)
1760{
1761 if (diplrel_mess == NULL) {
1762 /* This is the first call. Initialize diplrel_mess. */
1763 diplrel_mess = diplrel_mess_gen();
1764 }
1765
1766 return diplrel_mess;
1767}
1768
1769/*******************************************************************/
1772 void diplrel_mess_close(void)
1773{
1774 if (diplrel_mess != NULL) {
1775 free(diplrel_mess);
1776 diplrel_mess = NULL;
1777 }
1778}
1779
1780/*******************************************************************/
1787bv_diplrel_all_reqs diplrel_req_contradicts(const struct requirement *req)
1788{
1789 int diplrel_req_num;
1790 bv_diplrel_all_reqs *mess;
1791 bv_diplrel_all_reqs known;
1792 int set;
1793
1794 /* Nothing is known to contradict the requirement yet. */
1795 BV_CLR_ALL(known);
1796
1797 if (!(req->source.kind == VUT_DIPLREL
1798 || req->source.kind == VUT_DIPLREL_TILE
1799 || req->source.kind == VUT_DIPLREL_TILE_O
1800 || req->source.kind == VUT_DIPLREL_UNITANY
1801 || req->source.kind == VUT_DIPLREL_UNITANY_O)) {
1802 /* No known contradiction of a requirement of any other kind. */
1803 fc_assert(req->source.kind == VUT_DIPLREL
1804 || req->source.kind == VUT_DIPLREL_TILE
1805 || req->source.kind == VUT_DIPLREL_TILE_O
1806 || req->source.kind == VUT_DIPLREL_UNITANY
1807 || req->source.kind == VUT_DIPLREL_UNITANY_O);
1808
1809 return known;
1810 }
1811
1812 /* Convert the requirement to its position in the enumeration of all
1813 * DiplRel requirements. */
1814 diplrel_req_num = requirement_diplrel_ereq(req->source.value.diplrel,
1815 req->range, req->present);
1816
1817 /* Get the mutually exclusive requirement sets for DiplRel. */
1818 mess = diplrel_mess_get();
1819
1820 /* Add all known contradictions. */
1821 for (set = 0; set < DIPLREL_MESS_SIZE; set++) {
1822 if (BV_ISSET(mess[set], diplrel_req_num)) {
1823 /* The requirement req is mentioned in the set. It is therefore known
1824 * that all other requirements in the set contradicts it. They should
1825 * therefore be added to the known contradictions. */
1826 BV_SET_ALL_FROM(known, mess[set]);
1827 }
1828 }
1829
1830 /* The requirement isn't self contradicting. It was set by the mutually
1831 * exclusive requirement sets that mentioned it. Remove it. */
1832 BV_CLR(known, diplrel_req_num);
1833
1834 return known;
1835}
1836
1837/*******************************************************************/
1842 int player_in_territory(const struct player *pplayer,
1843 const struct player *pplayer2)
1844{
1845 int in_territory = 0;
1846
1847 /* This algorithm should work at server or client. It only returns the
1848 * number of visible units (a unit can potentially hide inside the
1849 * transport of a different player).
1850 *
1851 * Note this may be quite slow. An even slower alternative is to iterate
1852 * over the entire map, checking all units inside the player's territory
1853 * to see if they're owned by the enemy. */
1854 unit_list_iterate(pplayer2->units, punit) {
1855 /* Get the owner of the tile/territory. */
1856 struct player *owner = tile_owner(unit_tile(punit));
1857
1858 if (owner == pplayer && can_player_see_unit(pplayer, punit)) {
1859 /* Found one! */
1860 in_territory += 1;
1861 }
1862 } unit_list_iterate_end;
1863
1864 return in_territory;
1865}
1866
1867/*******************************************************************/
1872 bool is_valid_username(const char *name)
1873{
1874 return (strlen(name) > 0
1875 && !fc_isdigit(name[0])
1876 && is_ascii_name(name)
1877 && fc_strcasecmp(name, ANON_USER_NAME) != 0);
1878}
1879
1880/*******************************************************************/
1883 bool is_settable_ai_level(enum ai_level level)
1884{
1885 if (level == AI_LEVEL_AWAY) {
1886 /* Cannot set away level for AI */
1887 return FALSE;
1888 }
1889
1890 return TRUE;
1891}
1892
1893/*******************************************************************/
1896 int number_of_ai_levels(void)
1897{
1898 return AI_LEVEL_COUNT - 1; /* AI_LEVEL_AWAY is not real AI */
1899}
1900
1901/*******************************************************************/
1904 void *player_ai_data(const struct player *pplayer, const struct ai_type *ai)
1905{
1906 return pplayer->server.ais[ai_type_number(ai)];
1907}
1908
1909/*******************************************************************/
1912 void player_set_ai_data(struct player *pplayer, const struct ai_type *ai,
1913 void *data)
1914{
1915 pplayer->server.ais[ai_type_number(ai)] = data;
1916}
1917
1918/*******************************************************************/
1922 int player_multiplier_value(const struct player *pplayer,
1923 const struct multiplier *pmul)
1924{
1925 return pplayer->multipliers[multiplier_index(pmul)].value;
1926}
1927
1928/*******************************************************************/
1933 int player_multiplier_effect_value(const struct player *pplayer,
1934 const struct multiplier *pmul)
1935{
1936 return (player_multiplier_value(pplayer, pmul) + pmul->offset)
1937 * pmul->factor;
1938}
1939
1940/*******************************************************************/
1945 int player_multiplier_target_value(const struct player *pplayer,
1946 const struct multiplier *pmul)
1947{
1948 return pplayer->multipliers[multiplier_index(pmul)].target;
1949}
1950
1951/*******************************************************************/
1954 bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
1955{
1956 return BV_ISSET(pplayer->flags, flag);
1957}
ai_type_number
int ai_type_number(const struct ai_type *ai)
Definition ai.c:272
ai.h
dbv_free
void dbv_free(struct dbv *pdbv)
Definition bitvector.c:95
BV_SET_ALL_FROM
#define BV_SET_ALL_FROM(vec_to, vec_from)
Definition bitvector.h:120
BV_CLR_ALL
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
BV_SET
#define BV_SET(bv, bit)
Definition bitvector.h:81
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
BV_CLR
#define BV_CLR(bv, bit)
Definition bitvector.h:86
city_production_has_flag
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:712
city_map_radius_sq_get
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:132
city_total_unit_gold_upkeep
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1194
city_total_impr_gold_upkeep
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1175
city.h
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:488
city_tile
#define city_tile(_pcity_)
Definition city.h:544
CITY_MAP_MAX_RADIUS_SQ
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:78
city_owner
#define city_owner(_pcity_)
Definition city.h:543
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:490
city_tile_iterate
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:222
city_tile_iterate_end
#define city_tile_iterate_end
Definition city.h:230
trade_city
Definition menu.h:138
client
struct civclient client
Definition client_main.c:149
punit
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:73
target_city
struct unit struct city * target_city
Definition dialogs_g.h:55
get_target_bonus_effects
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:691
get_player_bonus
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:771
extra_type_list_of_unit_hiders
struct extra_type_list * extra_type_list_of_unit_hiders(void)
Definition extras.c:251
extra_type_list_iterate
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:159
extra_type_list_iterate_end
#define extra_type_list_iterate_end
Definition extras.h:161
fc_funcs
const struct functions * fc_funcs
Definition fc_interface.c:38
fc_interface.h
is_server
static bool is_server(void)
Definition fc_interface.h:69
CASUS_BELLI_OUTRAGE
#define CASUS_BELLI_OUTRAGE
Definition fc_types.h:454
MAX_NUM_PLAYER_SLOTS
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
CASUS_BELLI_VICTIM
#define CASUS_BELLI_VICTIM
Definition fc_types.h:448
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
O_SHIELD
@ O_SHIELD
Definition fc_types.h:91
O_GOLD
@ O_GOLD
Definition fc_types.h:91
fcintl.h
Q_
#define Q_(String)
Definition fcintl.h:70
_
#define _(String)
Definition fcintl.h:67
featured_text.h
game
struct civ_game game
Definition game.c:57
wld
struct world wld
Definition game.c:58
game_remove_unit
void game_remove_unit(struct world *gworld, struct unit *punit)
Definition game.c:119
game_remove_city
void game_remove_city(struct world *gworld, struct city *pcity)
Definition game.c:173
game.h
government.h
owner
struct city * owner
Definition citydlg.c:219
type
GType type
Definition repodlgs.c:1312
idex_lookup_city
struct city * idex_lookup_city(struct world *iworld, int id)
Definition idex.c:132
idex_lookup_unit
struct unit * idex_lookup_unit(struct world *iworld, int id)
Definition idex.c:145
idex.h
improvement.h
WONDER_NOT_BUILT
#define WONDER_NOT_BUILT
Definition improvement.h:152
B_LAST
#define B_LAST
Definition improvement.h:42
name
const char * name
Definition inputfile.c:127
log.h
fc_assert_msg
#define fc_assert_msg(condition, message,...)
Definition log.h:181
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
log_debug
#define log_debug(message,...)
Definition log.h:115
log_error
#define log_error(message,...)
Definition log.h:103
sq_map_distance
int sq_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:639
map.h
mem.h
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
multiplier_index
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Definition multipliers.c:80
NO_NATION_SELECTED
#define NO_NATION_SELECTED
Definition nation.h:29
is_settable_ai_level
bool is_settable_ai_level(enum ai_level level)
Definition player.c:1883
are_diplstates_equal
bool are_diplstates_equal(const struct player_diplstate *pds1, const struct player_diplstate *pds2)
Definition player.c:1469
player_can_invade_tile
bool player_can_invade_tile(const struct player *pplayer, const struct tile *ptile)
Definition player.c:264
player_knows_techs_with_flag
bool player_knows_techs_with_flag(const struct player *pplayer, enum tech_flag_id flag)
Definition player.c:1304
player_multiplier_effect_value
int player_multiplier_effect_value(const struct player *pplayer, const struct multiplier *pmul)
Definition player.c:1933
player_ai_data
void * player_ai_data(const struct player *pplayer, const struct ai_type *ai)
Definition player.c:1904
player_slot_is_used
bool player_slot_is_used(const struct player_slot *pslot)
Definition player.c:441
diplrel_req_contradicts
bv_diplrel_all_reqs diplrel_req_contradicts(const struct requirement *req)
Definition player.c:1787
diplrel_mess_get
static bv_diplrel_all_reqs * diplrel_mess_get(void)
Definition player.c:1759
num_known_tech_with_flag
int num_known_tech_with_flag(const struct player *pplayer, enum tech_flag_id flag)
Definition player.c:1249
is_valid_username
bool is_valid_username(const char *name)
Definition player.c:1872
player_diplstate_new
static void player_diplstate_new(const struct player *plr1, const struct player *plr2)
Definition player.c:278
player_multiplier_target_value
int player_multiplier_target_value(const struct player *pplayer, const struct multiplier *pmul)
Definition player.c:1945
player_unit_by_number
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
Definition player.c:1205
diplrel_mess
static bv_diplrel_all_reqs * diplrel_mess
Definition player.c:1754
player_by_name_prefix
struct player * player_by_name_prefix(const char *name, enum m_pre_result *result)
Definition player.c:911
diplrel_by_rule_name
int diplrel_by_rule_name(const char *value)
Definition player.c:1545
player_new
struct player * player_new(struct player_slot *pslot)
Definition player.c:486
player_by_number
struct player * player_by_number(const int player_id)
Definition player.c:840
player_in_city_map
bool player_in_city_map(const struct player *pplayer, const struct tile *ptile)
Definition player.c:1225
players_on_same_team
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1452
diplrel_mess_gen
static bv_diplrel_all_reqs * diplrel_mess_gen(void)
Definition player.c:1654
used_slots
int used_slots
Definition player.c:51
can_player_see_unit_at
bool can_player_see_unit_at(const struct player *pplayer, const struct unit *punit, const struct tile *ptile, bool is_transported)
Definition player.c:1025
player_count
int player_count(void)
Definition player.c:808
cancel_pact_result
enum diplstate_type cancel_pact_result(enum diplstate_type oldstate)
Definition player.c:67
player_slot_count
int player_slot_count(void)
Definition player.c:411
player_slot_by_number
struct player_slot * player_slot_by_number(int player_id)
Definition player.c:456
player_multiplier_value
int player_multiplier_value(const struct player *pplayer, const struct multiplier *pmul)
Definition player.c:1922
player_get_expected_income
int player_get_expected_income(const struct player *pplayer)
Definition player.c:1262
player_number
int player_number(const struct player *pplayer)
Definition player.c:828
pplayer_can_make_treaty
enum dipl_reason pplayer_can_make_treaty(const struct player *p1, const struct player *p2, enum diplstate_type treaty)
Definition player.c:153
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:886
player_diplstate_defaults
static void player_diplstate_defaults(const struct player *plr1, const struct player *plr2)
Definition player.c:298
player_slots_free
void player_slots_free(void)
Definition player.c:379
is_diplrel_to_other
bool is_diplrel_to_other(const struct player *pplayer, int diplrel)
Definition player.c:1526
player_slot_max_used_number
int player_slot_max_used_number(void)
Definition player.c:469
is_valid_alliance
static bool is_valid_alliance(const struct player *p1, const struct player *p2)
Definition player.c:126
can_player_see_unit
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1084
pplayers_at_war
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1364
player_set_ai_data
void player_set_ai_data(struct player *pplayer, const struct ai_type *ai, void *data)
Definition player.c:1912
player_diplstate_destroy
static void player_diplstate_destroy(const struct player *plr1, const struct player *plr2)
Definition player.c:334
player_ruleset_close
void player_ruleset_close(struct player *pplayer)
Definition player.c:736
player_clear
void player_clear(struct player *pplayer, bool full)
Definition player.c:660
player_slot_index
int player_slot_index(const struct player_slot *pslot)
Definition player.c:419
player_by_name
struct player * player_by_name(const char *name)
Definition player.c:872
player_slots_init
void player_slots_init(void)
Definition player.c:353
player_has_flag
bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
Definition player.c:1954
player_has_real_embassy
bool player_has_real_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:234
team_has_embassy
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:214
player_set_color
void player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Definition player.c:639
player_city_by_number
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1179
player_primary_capital
struct city * player_primary_capital(const struct player *pplayer)
Definition player.c:1313
player_index
int player_index(const struct player *pplayer)
Definition player.c:820
player_in_territory
int player_in_territory(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1842
player_by_user
struct player * player_by_user(const char *name)
Definition player.c:931
diplrel_name_translation
const char * diplrel_name_translation(int value)
Definition player.c:1591
is_diplrel_between
bool is_diplrel_between(const struct player *player1, const struct player *player2, int diplrel)
Definition player.c:1480
player_slots
static struct @68 player_slots
player_set_nation
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:852
DIPLREL_MESS_SIZE
#define DIPLREL_MESS_SIZE
Definition player.c:1644
player_can_see_city_externals
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Definition player.c:1143
player_age
int player_age(const struct player *pplayer)
Definition player.c:945
pplayer_can_cancel_treaty
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
Definition player.c:92
player_diplstate_get
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:317
number_of_ai_levels
int number_of_ai_levels(void)
Definition player.c:1896
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1381
player_defaults
static void player_defaults(struct player *pplayer)
Definition player.c:544
can_player_see_hypotetic_units_at
bool can_player_see_hypotetic_units_at(const struct player *pplayer, const struct tile *ptile)
Definition player.c:984
slots
struct player_slot * slots
Definition player.c:50
player_has_embassy_from_effect
bool player_has_embassy_from_effect(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:244
diplrel_mess_close
void diplrel_mess_close(void)
Definition player.c:1772
players_non_invade
bool players_non_invade(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1418
pplayers_non_attack
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1435
can_player_see_units_in_city
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:1113
player_slot_get_player
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:430
player_name_by_number
static const char * player_name_by_number(int i)
Definition player.c:900
can_player_see_city_internals
bool can_player_see_city_internals(const struct player *pplayer, const struct city *pcity)
Definition player.c:1129
player_slot_next
struct player_slot * player_slot_next(struct player_slot *pslot)
Definition player.c:400
player_can_trust_tile_has_no_units
bool player_can_trust_tile_has_no_units(const struct player *pplayer, const struct tile *ptile)
Definition player.c:958
player_slots_initialised
bool player_slots_initialised(void)
Definition player.c:371
love_text
const char * love_text(const int love)
Definition player.c:1330
player_has_embassy
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:202
casus_belli_range_for
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:1604
diplrel_rule_name
const char * diplrel_rule_name(int value)
Definition player.c:1579
gives_shared_vision
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1461
player_owns_city
bool player_owns_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:255
player_slot_first
struct player_slot * player_slot_first(void)
Definition player.c:392
player_destroy
void player_destroy(struct player *pplayer)
Definition player.c:747
pplayers_in_peace
bool pplayers_in_peace(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1402
player.h
players_iterate_end
#define players_iterate_end
Definition player.h:535
dipl_reason
dipl_reason
Definition player.h:194
DIPL_SENATE_BLOCKING
@ DIPL_SENATE_BLOCKING
Definition player.h:195
DIPL_ALLIANCE_PROBLEM_THEM
@ DIPL_ALLIANCE_PROBLEM_THEM
Definition player.h:196
DIPL_ALLIANCE_PROBLEM_US
@ DIPL_ALLIANCE_PROBLEM_US
Definition player.h:196
DIPL_OK
@ DIPL_OK
Definition player.h:195
DIPL_ERROR
@ DIPL_ERROR
Definition player.h:195
players_iterate
#define players_iterate(_pplayer)
Definition player.h:530
player_list_iterate
#define player_list_iterate(playerlist, pplayer)
Definition player.h:553
MAX_AI_LOVE
#define MAX_AI_LOVE
Definition player.h:559
ANON_USER_NAME
#define ANON_USER_NAME
Definition player.h:48
is_barbarian
static bool is_barbarian(const struct player *pplayer)
Definition player.h:488
player_slots_iterate
#define player_slots_iterate(_pslot)
Definition player.h:521
player_list_iterate_end
#define player_list_iterate_end
Definition player.h:555
PLAYER_DEFAULT_SCIENCE_RATE
#define PLAYER_DEFAULT_SCIENCE_RATE
Definition player.h:40
set_as_human
#define set_as_human(plr)
Definition player.h:235
players_iterate_alive_end
#define players_iterate_alive_end
Definition player.h:545
player_slots_iterate_end
#define player_slots_iterate_end
Definition player.h:525
ANON_PLAYER_NAME
#define ANON_PLAYER_NAME
Definition player.h:43
PLAYER_DEFAULT_TAX_RATE
#define PLAYER_DEFAULT_TAX_RATE
Definition player.h:39
PLAYER_DEFAULT_LUXURY_RATE
#define PLAYER_DEFAULT_LUXURY_RATE
Definition player.h:41
players_iterate_alive
#define players_iterate_alive(_pplayer)
Definition player.h:540
requirement_diplrel_ereq
#define requirement_diplrel_ereq(_id_, _range_, _present_)
Definition requirements.h:441
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:126
research.h
rgbcolor_destroy
void rgbcolor_destroy(struct rgbcolor *prgbcolor)
Definition rgbcolor.c:74
rgbcolor_copy
struct rgbcolor * rgbcolor_copy(const struct rgbcolor *prgbcolor)
Definition rgbcolor.c:51
rgbcolor.h
level
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:183
match_prefix
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:1578
is_ascii_name
bool is_ascii_name(const char *name)
Definition shared.c:282
shared.h
m_pre_result
m_pre_result
Definition shared.h:207
M_PRE_AMBIGUOUS
@ M_PRE_AMBIGUOUS
Definition shared.h:210
spaceship_init
void spaceship_init(struct player_spaceship *ship)
Definition spaceship.c:96
action
Definition actions.h:379
ai_type
Definition ai.h:50
attribute_block_s::data
void * data
Definition player.h:223
attribute_block_s::length
int length
Definition player.h:224
city
Definition city.h:309
city::capital
enum capital_type capital
Definition city.h:317
city::tile
struct tile * tile
Definition city.h:311
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_map
Definition map_types.h:71
dbv::bits
int bits
Definition bitvector.h:33
dbv::vec
unsigned char * vec
Definition bitvector.h:34
functions::player_tile_vision_get
bool(* player_tile_vision_get)(const struct tile *ptile, const struct player *pplayer, enum vision_layer vision)
Definition fc_interface.h:46
functions::destroy_city
void(* destroy_city)(struct city *pcity)
Definition fc_interface.h:43
multiplier_value::value
int value
Definition player.h:241
multiplier_value::target
int target
Definition player.h:243
multiplier
Definition multipliers.h:31
multiplier::offset
int offset
Definition multipliers.h:39
multiplier::factor
int factor
Definition multipliers.h:40
nation_type
Definition nation.h:97
nation_type::player
struct player * player
Definition nation.h:117
packet_game_info::gold_upkeep_style
enum gold_upkeep_style gold_upkeep_style
Definition packets_gen.h:167
player_ai::skill_level
enum ai_level skill_level
Definition player.h:122
player_ai::traits
struct ai_trait * traits
Definition player.h:132
player_ai::barbarian_type
enum barbarian_type barbarian_type
Definition player.h:128
player_ai::love
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:130
player_ai::expand
int expand
Definition player.h:124
player_ai::fuzzy
int fuzzy
Definition player.h:123
player_diplstate
Definition player.h:200
player_diplstate::contact_turns_left
char contact_turns_left
Definition player.h:206
player_diplstate::turns_left
char turns_left
Definition player.h:204
player_diplstate::auto_cancel_turn
int auto_cancel_turn
Definition player.h:208
player_diplstate::first_contact_turn
int first_contact_turn
Definition player.h:203
player_diplstate::max_state
enum diplstate_type max_state
Definition player.h:202
player_diplstate::type
enum diplstate_type type
Definition player.h:201
player_diplstate::has_reason_to_cancel
char has_reason_to_cancel
Definition player.h:205
player_economic::luxury
int luxury
Definition player.h:73
player_economic::science
int science
Definition player.h:72
player_economic::tax
int tax
Definition player.h:71
player_economic::infra_points
int infra_points
Definition player.h:74
player_economic::gold
int gold
Definition player.h:70
player_slot
Definition player.c:45
player_slot::player
struct player * player
Definition player.c:46
player
Definition player.h:249
player::cities
struct city_list * cities
Definition player.h:281
player::random_name
bool random_name
Definition player.h:295
player::ai_common
struct player_ai ai_common
Definition player.h:288
player::flags
bv_plr_flags flags
Definition player.h:292
player::tile_vision
struct dbv tile_vision[V_COUNT]
Definition player.h:359
player::primary_capital_id
int primary_capital_id
Definition player.h:275
player::is_male
bool is_male
Definition player.h:257
player::wonders
int wonders[B_LAST]
Definition player.h:301
player::diplstates
const struct player_diplstate ** diplstates
Definition player.h:278
player::unassigned_ranked
bool unassigned_ranked
Definition player.h:255
player::target_government
struct government * target_government
Definition player.h:259
player::username
char username[MAX_LEN_NAME]
Definition player.h:252
player::is_winner
bool is_winner
Definition player.h:269
player::is_connected
bool is_connected
Definition player.h:296
player::revolution_finishes
int revolution_finishes
Definition player.h:273
player::client
struct player::@69::@72 client
player::ais
void * ais[FREECIV_AI_MOD_LAST]
Definition player.h:336
player::nturns_idle
int nturns_idle
Definition player.h:265
player::government
struct government * government
Definition player.h:258
player::tile_known
struct dbv tile_known
Definition player.h:306
player::current_conn
struct connection * current_conn
Definition player.h:297
player::team
struct team * team
Definition player.h:261
player::savegame_ai_type_name
char * savegame_ai_type_name
Definition player.h:290
player::turns_alive
int turns_alive
Definition player.h:266
player::was_created
bool was_created
Definition player.h:294
player::ai
const struct ai_type * ai
Definition player.h:289
player::units
struct unit_list * units
Definition player.h:282
player::ranked_username
char ranked_username[MAX_LEN_NAME]
Definition player.h:254
player::connections
struct conn_list * connections
Definition player.h:298
player::is_alive
bool is_alive
Definition player.h:268
player::real_embassy
bv_player real_embassy
Definition player.h:277
player::economic
struct player_economic economic
Definition player.h:284
player::spaceship
struct player_spaceship spaceship
Definition player.h:286
player::attribute_block
struct attribute_block_s attribute_block
Definition player.h:303
player::name
char name[MAX_LEN_NAME]
Definition player.h:251
player::gives_shared_vision
bv_player gives_shared_vision
Definition player.h:299
player::attribute_block_buffer
struct attribute_block_s attribute_block_buffer
Definition player.h:304
player::multipliers
struct multiplier_value multipliers[MAX_NUM_MULTIPLIERS]
Definition player.h:310
player::nation
struct nation_type * nation
Definition player.h:260
player::music_style
int music_style
Definition player.h:280
player::style
struct nation_style * style
Definition player.h:279
player::phase_done
bool phase_done
Definition player.h:263
player::slot
struct player_slot * slot
Definition player.h:250
player::server
struct player::@69::@71 server
player::is_ready
bool is_ready
Definition player.h:262
player::user_turns
int user_turns
Definition player.h:256
player::last_war_action
int last_war_action
Definition player.h:270
player::rgb
struct rgbcolor * rgb
Definition player.h:308
player::unassigned_user
bool unassigned_user
Definition player.h:253
req_context
Definition requirements.h:99
requirement
Definition requirements.h:80
requirement::present
bool present
Definition requirements.h:84
requirement::range
enum req_range range
Definition requirements.h:82
requirement::source
struct universal source
Definition requirements.h:81
research::num_known_tech_with_flag
int num_known_tech_with_flag[TF_COUNT]
Definition research.h:90
rgbcolor
Definition rgbcolor.h:33
team
Definition team.c:40
tile
Definition tile.h:49
tile::units
struct unit_list * units
Definition tile.h:57
tile::extras_owner
struct player * extras_owner
Definition tile.h:62
unit_class
Definition unittype.h:136
unit_class::cache
struct unit_class::@85 cache
unit_class::hiding_extras
struct extra_type_list * hiding_extras
Definition unittype.h:159
unit_type
Definition unittype.h:481
unit
Definition unit.h:138
unit::transporting
struct unit_list * transporting
Definition unit.h:184
unit::client
struct unit::@80::@82 client
unit::transported_by
int transported_by
Definition unit.h:213
universal::kind
enum universals_n kind
Definition fc_types.h:758
universal::value
universals_u value
Definition fc_types.h:757
world::map
struct civ_map map
Definition world_object.h:38
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
fc_isdigit
bool fc_isdigit(char c)
Definition support.c:1227
fc_strncasequotecmp
int fc_strncasequotecmp(const char *str0, const char *str1, size_t n)
Definition support.c:379
effectivestrlenquote
size_t effectivestrlenquote(const char *str)
Definition support.c:359
support.h
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:161
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
fc__fallthrough
#define fc__fallthrough
Definition support.h:109
team_members
const struct player_list * team_members(const struct team *pteam)
Definition team.c:456
team_remove_player
void team_remove_player(struct player *pplayer)
Definition team.c:502
tech.h
tile_is_seen
bool tile_is_seen(const struct tile *target_tile, const struct player *pow_player)
Definition tile.c:401
tile_get_known
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:386
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
TILE_KNOWN_SEEN
@ TILE_KNOWN_SEEN
Definition tile.h:37
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
tile_owner
#define tile_owner(_tile)
Definition tile.h:95
trade_partners_iterate_end
#define trade_partners_iterate_end
Definition traderoutes.h:165
trade_partners_iterate
#define trade_partners_iterate(c, p)
Definition traderoutes.h:160
universals_u::diplrel
int diplrel
Definition fc_types.h:629
is_hiding_unit
bool is_hiding_unit(const struct unit *punit)
Definition unit.c:398
unit_nationality
struct player * unit_nationality(const struct unit *punit)
Definition unit.c:1272
unit_transport_unload
bool unit_transport_unload(struct unit *pcargo)
Definition unit.c:2376
unit_transported
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2411
unit_transport_cargo
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
Definition unit.c:2437
unit.h
unit_tile
#define unit_tile(_pu)
Definition unit.h:388
unit_owner
#define unit_owner(_pu)
Definition unit.h:387
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
unit_class_get
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2546
vision.h
vision_layer_iterate
#define vision_layer_iterate(v)
Definition vision.h:77
vision_layer_iterate_end
#define vision_layer_iterate_end
Definition vision.h:80