Freeciv-3.2: /fast/freeciv/nightly/S3_2/common/player.c Source File

Freeciv-3.2

Loading...
Searching...
No Matches
player.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "fcintl.h"
20#include "log.h"
21#include "mem.h"
22#include "shared.h"
23#include "support.h"
24
25/* common */
26#include "ai.h"
27#include "city.h"
28#include "fc_interface.h"
29#include "featured_text.h"
30#include "game.h"
31#include "government.h"
32#include "idex.h"
33#include "improvement.h"
34#include "map.h"
35#include "nation.h"
36#include "research.h"
37#include "rgbcolor.h"
38#include "tech.h"
39#include "unit.h"
40#include "unitlist.h"
41#include "vision.h"
42
43#include "player.h"
44
45
46 struct player_slot {
47 struct player *player;
48};
49
50static struct {
51 struct player_slot *slots;
52 int used_slots; /* number of used/allocated players in the player slots */
53} 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/*******************************************************************/
68 enum diplstate_type cancel_pact_result(enum diplstate_type oldstate)
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:
83 fc_assert(oldstate != DS_LAST);
84 return DS_WAR; /* Arbitrary */
85 }
86
87 fc_assert(FALSE);
88
89 return DS_WAR; /* Arbitrary */
90}
91
92/*******************************************************************/
98 enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1,
99 const struct player *p2)
100{
101 enum diplstate_type ds = player_diplstate_get(p1, p2)->type;
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
113 && get_player_bonus(p1, EFT_HAS_SENATE) > 0
114 && get_player_bonus(p1, EFT_NO_ANARCHY) <= 0) {
115 return DIPL_SENATE_BLOCKING;
116 }
117
118 return DIPL_OK;
119}
120
121/*******************************************************************/
132 static 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 }
144 } players_iterate_alive_end;
145
146 return TRUE;
147}
148
149/*******************************************************************/
159 enum dipl_reason pplayer_can_make_treaty(const struct player *p1,
160 const struct player *p2,
161 enum diplstate_type treaty)
162{
163 enum diplstate_type existing = player_diplstate_get(p1, p2)->type;
164
165 if (players_on_same_team(p1, p2)) {
166 /* This includes the case p1 == p2 */
167 return DIPL_ERROR;
168 }
169 if (get_player_bonus(p1, EFT_NO_DIPLOMACY) > 0
170 || get_player_bonus(p2, EFT_NO_DIPLOMACY) > 0) {
171 return DIPL_ERROR;
172 }
173 if (treaty == DS_WAR
174 || treaty == DS_NO_CONTACT
175 || treaty == DS_ARMISTICE
176 || treaty == DS_TEAM
177 || treaty == DS_LAST) {
178 return DIPL_ERROR; /* These are not negotiable treaties */
179 }
180 if (treaty == DS_CEASEFIRE && existing != DS_WAR) {
181 return DIPL_ERROR; /* Only available from war */
182 }
183 if (treaty == DS_PEACE
184 && (existing != DS_WAR && existing != DS_CEASEFIRE)) {
185 return DIPL_ERROR;
186 }
187 if (treaty == DS_ALLIANCE) {
188 if (!is_valid_alliance(p1, p2)) {
189 /* Our war with a third party prevents entry to alliance. */
190 return DIPL_ALLIANCE_PROBLEM_US;
191 } else if (!is_valid_alliance(p2, p1)) {
192 /* Their war with a third party prevents entry to alliance. */
193 return DIPL_ALLIANCE_PROBLEM_THEM;
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/*******************************************************************/
208 bool player_has_embassy(const struct player *pplayer,
209 const struct player *pplayer2)
210{
211 return (pplayer == pplayer2
212 || player_has_real_embassy(pplayer, pplayer2)
213 || player_has_embassy_from_effect(pplayer, pplayer2));
214}
215
216/*******************************************************************/
220 bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
221{
222 if (tgt_player->team == pteam) {
223 return TRUE;
224 }
225
226 player_list_iterate(team_members(pteam), teammate) {
227 if (player_has_real_embassy(teammate, tgt_player)
228 || player_has_embassy_from_effect(teammate, tgt_player)) {
229 return TRUE;
230 }
231 } player_list_iterate_end;
232
233 return FALSE;
234}
235
236/*******************************************************************/
240 bool 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/*******************************************************************/
250 bool 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
254 && player_diplstate_get(pplayer, pplayer2)->type != DS_NO_CONTACT
255 && !is_barbarian(pplayer2));
256}
257
258/*******************************************************************/
261 bool player_owns_city(const struct player *pplayer, const struct city *pcity)
262{
263 return (pcity && pplayer && city_owner(pcity) == pplayer);
264}
265
266/*******************************************************************/
270 bool 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
277 || terrain_has_flag(tile_terrain(ptile), TER_ENTER_BORDERS)
278 || !players_non_invade(pplayer, ptile_owner));
279}
280
281/*******************************************************************/
285 static void player_diplstate_new(const struct player *plr1,
286 const struct player *plr2)
287{
288 struct player_diplstate *diplstate;
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
296 fc_assert_ret(*diplstate_slot == NULL);
297
298 diplstate = fc_calloc(1, sizeof(*diplstate));
299 *diplstate_slot = diplstate;
300}
301
302/*******************************************************************/
305 static 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
310 fc_assert_ret(diplstate != NULL);
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/*******************************************************************/
324 struct player_diplstate *player_diplstate_get(const struct player *plr1,
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
333 fc_assert_ret_val(*diplstate_slot != NULL, NULL);
334
335 return (struct player_diplstate *) *diplstate_slot;
336}
337
338/*******************************************************************/
341 static 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
354 *diplstate_slot = NULL;
355}
356
357/*******************************************************************/
360 void player_slots_init(void)
361{
362 int i;
363
364 /* Init player slots. */
365 player_slots.slots = fc_calloc(player_slot_count(),
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/*******************************************************************/
378 bool player_slots_initialised(void)
379{
380 return (player_slots.slots != NULL);
381}
382
383/*******************************************************************/
386 void player_slots_free(void)
387{
388 players_iterate(pplayer) {
389 player_destroy(pplayer);
390 } players_iterate_end;
391 free(player_slots.slots);
392 player_slots.slots = NULL;
393 player_slots.used_slots = 0;
394}
395
396/*******************************************************************/
399 struct player_slot *player_slot_first(void)
400{
401 return player_slots.slots;
402}
403
404/*******************************************************************/
407 struct player_slot *player_slot_next(struct player_slot *pslot)
408{
409 pslot++;
410 return (pslot < player_slots.slots + player_slot_count() ? pslot : NULL);
411}
412
413/*******************************************************************/
418 int player_slot_count(void)
419{
420 return (MAX_NUM_PLAYER_SLOTS);
421}
422
423/*******************************************************************/
426 int 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/*******************************************************************/
437 struct 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/*******************************************************************/
448 bool 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. */
453 if (!player_slots_initialised()) {
454 return FALSE;
455 }
456
457 return NULL != pslot->player;
458}
459
460/*******************************************************************/
463 struct player_slot *player_slot_by_number(int player_id)
464{
465 if (!player_slots_initialised()
466 || !(0 <= player_id && player_id < player_slot_count())) {
467 return NULL;
468 }
469
470 return player_slots.slots + player_id;
471}
472
473/*******************************************************************/
476 int player_slot_max_used_number(void)
477{
478 int max_pslot = 0;
479
480 player_slots_iterate(pslot) {
481 if (player_slot_is_used(pslot)) {
482 max_pslot = player_slot_index(pslot);
483 }
484 } player_slots_iterate_end;
485
486 return max_pslot;
487}
488
489/*******************************************************************/
493 struct player *player_new(struct player_slot *pslot)
494{
495 struct player *pplayer;
496
497 fc_assert_ret_val(player_slots_initialised(), NULL);
498
499 if (pslot == NULL) {
500 player_slots_iterate(aslot) {
501 if (!player_slot_is_used(aslot)) {
502 pslot = aslot;
503 break;
504 }
505 } player_slots_iterate_end;
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
520 pplayer->diplstates = fc_calloc(player_slot_count(),
521 sizeof(*pplayer->diplstates));
522 player_slots_iterate(dslot) {
523 const struct player_diplstate **diplstate_slot
524 = pplayer->diplstates + player_slot_index(dslot);
525
526 *diplstate_slot = NULL;
527 } player_slots_iterate_end;
528
529 players_iterate(aplayer) {
530 /* Create diplomatic states for all other players. */
531 player_diplstate_new(pplayer, aplayer);
532 /* Create diplomatic state of this player. */
533 if (aplayer != pplayer) {
534 player_diplstate_new(aplayer, pplayer);
535 }
536 } players_iterate_end;
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/*******************************************************************/
551 static void player_defaults(struct player *pplayer)
552{
553 int i;
554
555 sz_strlcpy(pplayer->name, ANON_PLAYER_NAME);
556 sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
557 pplayer->unassigned_user = TRUE;
558 sz_strlcpy(pplayer->ranked_username, _(ANON_USER_NAME));
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);
578 players_iterate(aplayer) {
579 /* create diplomatic states for all other players */
580 player_diplstate_defaults(pplayer, aplayer);
581 /* create diplomatic state of this player */
582 if (aplayer != pplayer) {
583 player_diplstate_defaults(aplayer, pplayer);
584 }
585 } players_iterate_end;
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;
593 pplayer->economic.tax = PLAYER_DEFAULT_TAX_RATE;
594 pplayer->economic.science = PLAYER_DEFAULT_SCIENCE_RATE;
595 pplayer->economic.luxury = PLAYER_DEFAULT_LUXURY_RATE;
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);
603 pplayer->ai_common.skill_level = ai_level_invalid();
604 pplayer->ai_common.fuzzy = 0;
605 pplayer->ai_common.expand = 100;
606 pplayer->ai_common.barbarian_type = NOT_A_BARBARIAN;
607 player_slots_iterate(pslot) {
608 pplayer->ai_common.love[player_slot_index(pslot)] = 1;
609 } player_slots_iterate_end;
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;
620 BV_CLR_ALL(pplayer->gives_shared_vision);
621 BV_CLR_ALL(pplayer->gives_shared_tiles);
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;
628 pplayer->attribute_block_buffer.data = NULL;
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/*******************************************************************/
648 void 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/*******************************************************************/
669 void 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) {
690 free(pplayer->attribute_block_buffer.data);
691 pplayer->attribute_block_buffer.data = NULL;
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. */
698 unit_list_iterate(unit_transport_cargo(punit), pcargo) {
699 unit_transport_unload(pcargo);
700 if (client) {
701 pcargo->client.transported_by = -1;
702 }
703 } unit_list_iterate_end;
704 /* Unload the unit. */
705 unit_transport_unload(punit);
706 if (client) {
707 punit->client.transported_by = -1;
708 }
709
710 game_remove_unit(&wld, punit);
711 } unit_list_iterate_end;
712
713 city_list_iterate(pplayer->cities, pcity) {
714 if (fc_funcs->destroy_city != NULL) {
715 fc_funcs->destroy_city(pcity);
716 } else {
717 game_remove_city(&wld, pcity);
718 }
719 } city_list_iterate_end;
720
721 if (full) {
722 team_remove_player(pplayer);
723
724 players_iterate_alive(owner) {
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 }
730 } unit_list_iterate_end;
731 } players_iterate_alive_end;
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/*******************************************************************/
745 void 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/*******************************************************************/
756 void 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);
774 conn_list_destroy(pplayer->connections);
775
776 players_iterate(aplayer) {
777 /* Destroy the diplomatic states of this player with others ... */
778 player_diplstate_destroy(pplayer, aplayer);
779 /* ...and of others with this player. */
780 if (aplayer != pplayer) {
781 player_diplstate_destroy(aplayer, pplayer);
782
783 /* Check if any cities of the other player have been founded
784 * by the removed player. */
785 city_list_iterate(aplayer->cities, pcity) {
786 if (pcity->original == pplayer) {
787 /* Unknown origin is better than giving baseless
788 * benefits to current owner */
789 pcity->original = NULL;
790 }
791 } city_list_iterate_end;
792 }
793 } players_iterate_end;
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()) {
804 vision_layer_iterate(v) {
805 dbv_free(&pplayer->client.tile_vision[v]);
806 } vision_layer_iterate_end;
807 }
808
809 free(pplayer);
810 pslot->player = NULL;
811 player_slots.used_slots--;
812}
813
814/*******************************************************************/
817 int player_count(void)
818{
819 return player_slots.used_slots;
820}
821
822/*******************************************************************/
829 int player_index(const struct player *pplayer)
830{
831 return player_number(pplayer);
832}
833
834/*******************************************************************/
837 int 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/*******************************************************************/
849 struct 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/*******************************************************************/
861 bool 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/*******************************************************************/
881 struct player *player_by_name(const char *name)
882{
883 players_iterate(pplayer) {
884 if (fc_strcasecmp(name, pplayer->name) == 0) {
885 return pplayer;
886 }
887 } players_iterate_end;
888
889 return NULL;
890}
891
892/*******************************************************************/
895 const char *player_name(const struct player *pplayer)
896{
897 if (!pplayer) {
898 return NULL;
899 }
900 return pplayer->name;
901}
902
903/*******************************************************************/
909 static 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/*******************************************************************/
920 struct player *player_by_name_prefix(const char *name,
921 enum m_pre_result *result)
922{
923 int ind;
924
925 *result = match_prefix(player_name_by_number,
926 player_slot_count(), MAX_LEN_NAME - 1,
927 fc_strncasequotecmp, effectivestrlenquote,
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/*******************************************************************/
940 struct player *player_by_user(const char *name)
941{
942 players_iterate(pplayer) {
943 if (fc_strcasecmp(name, pplayer->username) == 0) {
944 return pplayer;
945 }
946 } players_iterate_end;
947
948 return NULL;
949}
950
951/*******************************************************************/
954 int player_age(const struct player *pplayer)
955{
956 fc_assert_ret_val(pplayer != NULL, 0);
957 return pplayer->turns_alive;
958}
959
960/*******************************************************************/
967 bool player_can_trust_tile_has_no_units(const struct player *pplayer,
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)) {
978 extra_type_list_iterate(extra_type_list_of_unit_hiders(), pextra) {
979 if (tile_has_extra(ptile, pextra)) {
980 return FALSE;
981 }
982 } extra_type_list_iterate_end;
983 }
984
985 return TRUE;
986}
987
988/*******************************************************************/
993 bool 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 }
1020 } unit_list_iterate_end;
1021
1022 return TRUE;
1023}
1024
1025/*******************************************************************/
1034 bool 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. */
1051 allied = pplayers_allied(pplayer, unit_owner(punit));
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. */
1069 pclass = unit_class_get(punit);
1070
1071 extra_type_list_iterate(pclass->cache.hiding_extras, pextra) {
1072 if (tile_has_extra(ptile, pextra)) {
1073 return FALSE;
1074 }
1075 } extra_type_list_iterate_end;
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/**********************************************************************/
1091 bool 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/*******************************************************************/
1104 bool 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),
1108 unit_transported(punit));
1109}
1110
1111/*******************************************************************/
1133 bool can_player_see_units_in_city(const struct player *pplayer,
1134 const struct city *pcity)
1135{
1136 return (!pplayer
1137 || can_player_see_city_internals(pplayer, pcity)
1138 || pplayers_allied(pplayer, city_owner(pcity)));
1139}
1140
1141/*******************************************************************/
1149 bool 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/*******************************************************************/
1164 bool player_can_see_city_externals(const struct player *pow_player,
1165 const struct city *target_city)
1166{
1167 fc_assert_ret_val(target_city, FALSE);
1168 fc_assert_ret_val(pow_player, FALSE);
1169
1170 if (can_player_see_city_internals(pow_player, target_city)) {
1171 /* City internals includes city externals. */
1172 return TRUE;
1173 }
1174
1175 if (tile_is_seen(city_tile(target_city), pow_player)) {
1176 /* The tile is being observed. */
1177 return TRUE;
1178 }
1179
1180 fc_assert_ret_val(target_city->routes, FALSE);
1181
1182 if (game.info.reveal_trade_partner) {
1183 trade_partners_iterate(target_city, trade_city) {
1184 if (city_owner(trade_city) == pow_player) {
1185 /* Revealed because of the trade route. */
1186 return TRUE;
1187 }
1188 } trade_partners_iterate_end;
1189 }
1190
1191 return FALSE;
1192}
1193
1194/*******************************************************************/
1203 struct 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/*******************************************************************/
1229 struct 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/*******************************************************************/
1249 bool player_in_city_map(const struct player *pplayer,
1250 const struct tile *ptile)
1251{
1252 const struct civ_map *nmap = &(wld.map);
1253
1254 city_tile_iterate(nmap, CITY_MAP_MAX_RADIUS_SQ, ptile, ptile1) {
1255 struct city *pcity = tile_city(ptile1);
1256
1257 if (pcity
1258 && (pplayer == NULL || city_owner(pcity) == pplayer)
1259 && city_map_radius_sq_get(pcity) >= sq_map_distance(ptile,
1260 ptile1)) {
1261 return TRUE;
1262 }
1263 } city_tile_iterate_end;
1264
1265 return FALSE;
1266}
1267
1268/*******************************************************************/
1273 int 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/*******************************************************************/
1286 int 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). */
1307 income -= city_total_impr_gold_upkeep(pcity);
1308 fc__fallthrough; /* No break. */
1309 case GOLD_UPKEEP_MIXED:
1310 /* Nation pays for units. */
1311 income -= city_total_unit_gold_upkeep(pcity);
1312 break;
1313 }
1314
1315 /* Capitalization income. */
1316 if (city_production_has_flag(pcity, IF_GOLD)) {
1317 income += pcity->shield_stock + pcity->surplus[O_SHIELD];
1318 }
1319 } city_list_iterate_end;
1320
1321 return income;
1322}
1323
1324/*******************************************************************/
1328 bool 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/*******************************************************************/
1337 struct 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
1346 capital = player_city_by_number(pplayer, pplayer->primary_capital_id);
1347
1348 return capital;
1349}
1350
1351/*******************************************************************/
1354 const 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/*******************************************************************/
1388 bool pplayers_at_war(const struct player *pplayer,
1389 const struct player *pplayer2)
1390{
1391 enum diplstate_type ds;
1392
1393 if (pplayer == pplayer2) {
1394 return FALSE;
1395 }
1396
1397 ds = player_diplstate_get(pplayer, pplayer2)->type;
1398
1399 return ds == DS_WAR || ds == DS_NO_CONTACT;
1400}
1401
1402/*******************************************************************/
1405 bool pplayers_allied(const struct player *pplayer,
1406 const struct player *pplayer2)
1407{
1408 enum diplstate_type ds;
1409
1410 if (!pplayer || !pplayer2) {
1411 return FALSE;
1412 }
1413
1414 if (pplayer == pplayer2) {
1415 return TRUE;
1416 }
1417
1418 ds = player_diplstate_get(pplayer, pplayer2)->type;
1419
1420 return (ds == DS_ALLIANCE || ds == DS_TEAM);
1421}
1422
1423/*******************************************************************/
1426 bool pplayers_in_peace(const struct player *pplayer,
1427 const struct player *pplayer2)
1428{
1429 enum diplstate_type ds = player_diplstate_get(pplayer, pplayer2)->type;
1430
1431 if (pplayer == pplayer2) {
1432 return TRUE;
1433 }
1434
1435 return (ds == DS_PEACE || ds == DS_ALLIANCE
1436 || ds == DS_ARMISTICE || ds == DS_TEAM);
1437}
1438
1439/*******************************************************************/
1442 bool players_non_invade(const struct player *pplayer1,
1443 const struct player *pplayer2)
1444{
1445 if (pplayer1 == pplayer2 || !pplayer1 || !pplayer2) {
1446 return FALSE;
1447 }
1448
1449 /* Movement during armistice is allowed so that player can withdraw
1450 units deeper inside opponent territory. */
1451
1452 return player_diplstate_get(pplayer1, pplayer2)->type == DS_PEACE;
1453}
1454
1455/*******************************************************************/
1459 bool pplayers_non_attack(const struct player *pplayer,
1460 const struct player *pplayer2)
1461{
1462 enum diplstate_type ds;
1463
1464 if (pplayer == pplayer2) {
1465 return FALSE;
1466 }
1467
1468 ds = player_diplstate_get(pplayer, pplayer2)->type;
1469
1470 return (ds == DS_PEACE || ds == DS_CEASEFIRE || ds == DS_ARMISTICE);
1471}
1472
1473/*******************************************************************/
1476 bool players_on_same_team(const struct player *pplayer1,
1477 const struct player *pplayer2)
1478{
1479 return pplayer1->team == pplayer2->team;
1480}
1481
1482/*******************************************************************/
1485 bool gives_shared_vision(const struct player *me, const struct player *them)
1486{
1487 return BV_ISSET(me->gives_shared_vision, player_index(them));
1488}
1489
1490/*******************************************************************/
1493 bool gives_shared_tiles(const struct player *me, const struct player *them)
1494{
1495 return BV_ISSET(me->gives_shared_tiles, player_index(them));
1496}
1497
1498/*******************************************************************/
1501 bool are_diplstates_equal(const struct player_diplstate *pds1,
1502 const struct player_diplstate *pds2)
1503{
1504 return (pds1->type == pds2->type && pds1->turns_left == pds2->turns_left
1505 && pds1->has_reason_to_cancel == pds2->has_reason_to_cancel
1506 && pds1->contact_turns_left == pds2->contact_turns_left);
1507}
1508
1509/*******************************************************************/
1512 bool is_diplrel_between(const struct player *player1,
1513 const struct player *player2,
1514 int diplrel)
1515{
1516 fc_assert(player1 != NULL);
1517 fc_assert(player2 != NULL);
1518
1519 /* No relationship to it self. */
1520 if (player1 == player2 && diplrel != DRO_FOREIGN) {
1521 return FALSE;
1522 }
1523
1524 if (diplrel < DS_LAST) {
1525 return player_diplstate_get(player1, player2)->type == diplrel;
1526 }
1527
1528 switch (diplrel) {
1529 case DRO_GIVES_SHARED_VISION:
1530 return gives_shared_vision(player1, player2);
1531 case DRO_RECEIVES_SHARED_VISION:
1532 return gives_shared_vision(player2, player1);
1533 case DRO_HOSTS_EMBASSY:
1534 return player_has_embassy(player2, player1);
1535 case DRO_HOSTS_TEAM_EMBASSY:
1536 return team_has_embassy(player2->team, player1);
1537 case DRO_HAS_EMBASSY:
1538 return player_has_embassy(player1, player2);
1539 case DRO_HAS_TEAM_EMBASSY:
1540 return team_has_embassy(player1->team, player2);
1541 case DRO_HOSTS_REAL_EMBASSY:
1542 return player_has_real_embassy(player2, player1);
1543 case DRO_HAS_REAL_EMBASSY:
1544 return player_has_real_embassy(player1, player2);
1545 case DRO_HAS_CASUS_BELLI:
1546 return 0 < player_diplstate_get(player1, player2)->has_reason_to_cancel;
1547 case DRO_PROVIDED_CASUS_BELLI:
1548 return 0 < player_diplstate_get(player2, player1)->has_reason_to_cancel;
1549 case DRO_FOREIGN:
1550 return player1 != player2;
1551 }
1552
1553 fc_assert_msg(FALSE, "diplrel_between(): invalid diplrel number %d.",
1554 diplrel);
1555
1556 return FALSE;
1557}
1558
1559/*******************************************************************/
1562 bool is_diplrel_to_other(const struct player *pplayer, int diplrel)
1563{
1564 fc_assert(pplayer != NULL);
1565
1566 players_iterate_alive(oplayer) {
1567 if (oplayer == pplayer) {
1568 continue;
1569 }
1570 if (is_diplrel_between(pplayer, oplayer, diplrel)) {
1571 return TRUE;
1572 }
1573 } players_iterate_alive_end;
1574 return FALSE;
1575}
1576
1577/*******************************************************************/
1581 int diplrel_by_rule_name(const char *value)
1582{
1583 /* Look for asymmetric diplomatic relations */
1584 int diplrel = diplrel_other_by_name(value, fc_strcasecmp);
1585
1586 if (diplrel != diplrel_other_invalid()) {
1587 return diplrel;
1588 }
1589
1590 /* Look for symmetric diplomatic relations */
1591 diplrel = diplstate_type_by_name(value, fc_strcasecmp);
1592
1593 /*
1594 * Make sure DS_LAST isn't returned as DS_LAST is the first diplrel_other.
1595 *
1596 * Can't happend now. This is in case that changes in the future. */
1597 fc_assert_ret_val(diplrel != DS_LAST, diplrel_other_invalid());
1598
1599 /*
1600 * Make sure that diplrel_other_invalid() is returned.
1601 *
1602 * Can't happen now. At the moment dpilrel_asym_invalid() is the same as
1603 * diplstate_type_invalid(). This is in case that changes in the future.
1604 */
1605 if (diplrel != diplstate_type_invalid()) {
1606 return diplrel;
1607 }
1608
1609 return diplrel_other_invalid();
1610}
1611
1612/*******************************************************************/
1615 const char *diplrel_rule_name(int value)
1616{
1617 if (value < DS_LAST) {
1618 return diplstate_type_name(value);
1619 } else {
1620 return diplrel_other_name(value);
1621 }
1622}
1623
1624/*******************************************************************/
1627 const char *diplrel_name_translation(int value)
1628{
1629 if (value < DS_LAST) {
1630 return diplstate_type_translated_name(value);
1631 } else {
1632 return _(diplrel_other_name(value));
1633 }
1634}
1635
1636/**************************************************************************
1637 Return the Casus Belli range when offender performs paction to tgt_plr
1638 at tgt_tile and the outcome is outcome.
1639**************************************************************************/
1640 enum casus_belli_range casus_belli_range_for(const struct player *offender,
1641 const struct unit_type *off_ut,
1642 const struct player *tgt_plr,
1643 const enum effect_type outcome,
1644 const struct action *paction,
1645 const struct tile *tgt_tile)
1646{
1647 int casus_belli_amount;
1648
1649 /* The victim gets a casus belli if CASUS_BELLI_VICTIM or above. Everyone
1650 * gets a casus belli if CASUS_BELLI_OUTRAGE or above. */
1651 casus_belli_amount =
1652 get_target_bonus_effects(NULL,
1653 &(const struct req_context) {
1654 .player = offender,
1655 .city = tile_city(tgt_tile),
1656 .tile = tgt_tile,
1657 .unittype = off_ut,
1658 .action = paction,
1659 },
1660 tgt_plr,
1661 outcome);
1662
1663 if (casus_belli_amount >= CASUS_BELLI_OUTRAGE) {
1664 /* International outrage: This isn't just between the offender and the
1665 * victim. */
1666 return CBR_INTERNATIONAL_OUTRAGE;
1667 }
1668
1669 if (casus_belli_amount >= CASUS_BELLI_VICTIM) {
1670 /* In this situation the specified action provides a casus belli
1671 * against the actor. */
1672 return CBR_VICTIM_ONLY;
1673 }
1674
1675 return CBR_NONE;
1676}
1677
1678/* The number of mutually exclusive requirement sets that
1679 * diplrel_mess_gen() creates for the DiplRel requirement type. */
1680#define DIPLREL_MESS_SIZE (3 + (DRO_LAST * (5 + 4 + 3 + 2 + 1)))
1681
1682/*******************************************************************/
1690 static bv_diplrel_all_reqs *diplrel_mess_gen(void)
1691{
1692 /* The ranges supported by the DiplRel requiremnt type. */
1693 const enum req_range legal_ranges[] = {
1694 REQ_RANGE_LOCAL,
1695 REQ_RANGE_PLAYER,
1696 REQ_RANGE_ALLIANCE,
1697 REQ_RANGE_TEAM,
1698 REQ_RANGE_WORLD
1699 };
1700
1701 /* Iterators. */
1702 int rel;
1703 int i;
1704 int j;
1705
1706 /* Storage for the mutually exclusive requirement sets. */
1707 bv_diplrel_all_reqs *mess = fc_malloc(DIPLREL_MESS_SIZE
1708 * sizeof(bv_diplrel_all_reqs));
1709
1710 /* Position in mess. */
1711 int mess_pos = 0;
1712
1713 /* The first mutually exclusive set is about local diplstate. */
1714 BV_CLR_ALL(mess[mess_pos]);
1715
1716 /* It is not possible to have more than one diplstate to a nation. */
1717 BV_SET(mess[mess_pos],
1718 requirement_diplrel_ereq(DS_ARMISTICE, REQ_RANGE_LOCAL, TRUE));
1719 BV_SET(mess[mess_pos],
1720 requirement_diplrel_ereq(DS_WAR, REQ_RANGE_LOCAL, TRUE));
1721 BV_SET(mess[mess_pos],
1722 requirement_diplrel_ereq(DS_CEASEFIRE, REQ_RANGE_LOCAL, TRUE));
1723 BV_SET(mess[mess_pos],
1724 requirement_diplrel_ereq(DS_PEACE, REQ_RANGE_LOCAL, TRUE));
1725 BV_SET(mess[mess_pos],
1726 requirement_diplrel_ereq(DS_ALLIANCE, REQ_RANGE_LOCAL, TRUE));
1727 BV_SET(mess[mess_pos],
1728 requirement_diplrel_ereq(DS_NO_CONTACT, REQ_RANGE_LOCAL, TRUE));
1729 BV_SET(mess[mess_pos],
1730 requirement_diplrel_ereq(DS_TEAM, REQ_RANGE_LOCAL, TRUE));
1731
1732 /* It is not possible to have a diplstate to your self. */
1733 BV_SET(mess[mess_pos],
1734 requirement_diplrel_ereq(DRO_FOREIGN, REQ_RANGE_LOCAL, FALSE));
1735
1736 mess_pos++;
1737
1738 /* Having a real embassy excludes not having an embassy. */
1739 BV_CLR_ALL(mess[mess_pos]);
1740
1741 BV_SET(mess[mess_pos],
1742 requirement_diplrel_ereq(DRO_HAS_REAL_EMBASSY, REQ_RANGE_LOCAL,
1743 TRUE));
1744 BV_SET(mess[mess_pos],
1745 requirement_diplrel_ereq(DRO_HAS_EMBASSY, REQ_RANGE_LOCAL,
1746 FALSE));
1747
1748 mess_pos++;
1749
1750 /* Hosting a real embassy excludes not hosting an embassy. */
1751 BV_CLR_ALL(mess[mess_pos]);
1752
1753 BV_SET(mess[mess_pos],
1754 requirement_diplrel_ereq(DRO_HOSTS_REAL_EMBASSY, REQ_RANGE_LOCAL,
1755 TRUE));
1756 BV_SET(mess[mess_pos],
1757 requirement_diplrel_ereq(DRO_HOSTS_EMBASSY, REQ_RANGE_LOCAL,
1758 FALSE));
1759
1760 mess_pos++;
1761
1762 /* Loop over diplstate_type and diplrel_other. */
1763 for (rel = 0; rel < DRO_LAST; rel++) {
1764 /* The presence of a DiplRel at a more local range proves that it can't
1765 * be absent in a more global range. (The alliance range includes the
1766 * Team range) */
1767 for (i = 0; i < 5; i++) {
1768 for (j = i; j < 5; j++) {
1769 BV_CLR_ALL(mess[mess_pos]);
1770
1771 BV_SET(mess[mess_pos],
1772 requirement_diplrel_ereq(rel, legal_ranges[i], TRUE));
1773 BV_SET(mess[mess_pos],
1774 requirement_diplrel_ereq(rel, legal_ranges[j], FALSE));
1775
1776 mess_pos++;
1777 }
1778 }
1779 }
1780
1781 /* No uninitialized element exists. */
1782 fc_assert(mess_pos == DIPLREL_MESS_SIZE);
1783
1784 return mess;
1785}
1786
1787/* An array of mutually exclusive requirement sets for the DiplRel
1788 * requirement type. Is initialized the first time diplrel_mess_get() is
1789 * called. */
1790 static bv_diplrel_all_reqs *diplrel_mess = NULL;
1791
1792/*******************************************************************/
1795 static bv_diplrel_all_reqs *diplrel_mess_get(void)
1796{
1797 if (diplrel_mess == NULL) {
1798 /* This is the first call. Initialize diplrel_mess. */
1799 diplrel_mess = diplrel_mess_gen();
1800 }
1801
1802 return diplrel_mess;
1803}
1804
1805/*******************************************************************/
1808 void diplrel_mess_close(void)
1809{
1810 if (diplrel_mess != NULL) {
1811 free(diplrel_mess);
1812 diplrel_mess = NULL;
1813 }
1814}
1815
1816/*******************************************************************/
1823 bv_diplrel_all_reqs diplrel_req_contradicts(const struct requirement *req)
1824{
1825 int diplrel_req_num;
1826 bv_diplrel_all_reqs *mess;
1827 bv_diplrel_all_reqs known;
1828 int set;
1829
1830 /* Nothing is known to contradict the requirement yet. */
1831 BV_CLR_ALL(known);
1832
1833 if (!(req->source.kind == VUT_DIPLREL
1834 || req->source.kind == VUT_DIPLREL_TILE
1835 || req->source.kind == VUT_DIPLREL_TILE_O
1836 || req->source.kind == VUT_DIPLREL_UNITANY
1837 || req->source.kind == VUT_DIPLREL_UNITANY_O)) {
1838 /* No known contradiction of a requirement of any other kind. */
1839 fc_assert(req->source.kind == VUT_DIPLREL
1840 || req->source.kind == VUT_DIPLREL_TILE
1841 || req->source.kind == VUT_DIPLREL_TILE_O
1842 || req->source.kind == VUT_DIPLREL_UNITANY
1843 || req->source.kind == VUT_DIPLREL_UNITANY_O);
1844
1845 return known;
1846 }
1847
1848 /* Convert the requirement to its position in the enumeration of all
1849 * DiplRel requirements. */
1850 diplrel_req_num = requirement_diplrel_ereq(req->source.value.diplrel,
1851 req->range, req->present);
1852
1853 /* Get the mutually exclusive requirement sets for DiplRel. */
1854 mess = diplrel_mess_get();
1855
1856 /* Add all known contradictions. */
1857 for (set = 0; set < DIPLREL_MESS_SIZE; set++) {
1858 if (BV_ISSET(mess[set], diplrel_req_num)) {
1859 /* The requirement req is mentioned in the set. It is therefore known
1860 * that all other requirements in the set contradicts it. They should
1861 * therefore be added to the known contradictions. */
1862 BV_SET_ALL_FROM(known, mess[set]);
1863 }
1864 }
1865
1866 /* The requirement isn't self contradicting. It was set by the mutually
1867 * exclusive requirement sets that mentioned it. Remove it. */
1868 BV_CLR(known, diplrel_req_num);
1869
1870 return known;
1871}
1872
1873/*******************************************************************/
1878 int player_in_territory(const struct player *pplayer,
1879 const struct player *pplayer2)
1880{
1881 int in_territory = 0;
1882
1883 /* This algorithm should work at server or client. It only returns the
1884 * number of visible units (a unit can potentially hide inside the
1885 * transport of a different player).
1886 *
1887 * Note this may be quite slow. An even slower alternative is to iterate
1888 * over the entire map, checking all units inside the player's territory
1889 * to see if they're owned by the enemy. */
1890 unit_list_iterate(pplayer2->units, punit) {
1891 /* Get the owner of the tile/territory. */
1892 struct player *owner = tile_owner(unit_tile(punit));
1893
1894 if (owner == pplayer && can_player_see_unit(pplayer, punit)) {
1895 /* Found one! */
1896 in_territory += 1;
1897 }
1898 } unit_list_iterate_end;
1899
1900 return in_territory;
1901}
1902
1903/*******************************************************************/
1908 bool is_valid_username(const char *name)
1909{
1910 return (strlen(name) > 0
1911 && !fc_isdigit(name[0])
1912 && is_ascii_name(name)
1913 && fc_strcasecmp(name, ANON_USER_NAME) != 0);
1914}
1915
1916/*******************************************************************/
1919 bool is_settable_ai_level(enum ai_level level)
1920{
1921 if (level == AI_LEVEL_AWAY) {
1922 /* Cannot set away level for AI */
1923 return FALSE;
1924 }
1925
1926 return TRUE;
1927}
1928
1929/*******************************************************************/
1932 int number_of_ai_levels(void)
1933{
1934 return AI_LEVEL_COUNT - 1; /* AI_LEVEL_AWAY is not real AI */
1935}
1936
1937/*******************************************************************/
1940 void *player_ai_data(const struct player *pplayer, const struct ai_type *ai)
1941{
1942 return pplayer->server.ais[ai_type_number(ai)];
1943}
1944
1945/*******************************************************************/
1948 void player_set_ai_data(struct player *pplayer, const struct ai_type *ai,
1949 void *data)
1950{
1951 pplayer->server.ais[ai_type_number(ai)] = data;
1952}
1953
1954/*******************************************************************/
1958 int player_multiplier_value(const struct player *pplayer,
1959 const struct multiplier *pmul)
1960{
1961 return pplayer->multipliers[multiplier_index(pmul)].value;
1962}
1963
1964/*******************************************************************/
1969 int player_multiplier_effect_value(const struct player *pplayer,
1970 const struct multiplier *pmul)
1971{
1972 return (player_multiplier_value(pplayer, pmul) + pmul->offset)
1973 * pmul->factor;
1974}
1975
1976/*******************************************************************/
1981 int player_multiplier_target_value(const struct player *pplayer,
1982 const struct multiplier *pmul)
1983{
1984 return pplayer->multipliers[multiplier_index(pmul)].target;
1985}
1986
1987/*******************************************************************/
1990 bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
1991{
1992 return BV_ISSET(pplayer->flags, flag);
1993}
1994
1995/*******************************************************************/
1998 bool player_has_state(const struct player *pplayer,
1999 enum plrstate_type state)
2000{
2001 switch (state) {
2002 case PLRS_BARBARIAN:
2003 return is_barbarian(pplayer);
2004 case PLRS_HAS_CAPITAL:
2005 return player_primary_capital(pplayer) != NULL;
2006 case PLRS_LAST:
2007 fc_assert(state != PLRS_LAST);
2008 break;
2009 }
2010
2011 fc_assert(plrstate_type_is_valid(state));
2012 return FALSE;
2013}
ai_type_number
int ai_type_number(const struct ai_type *ai)
Definition ai.c:278
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:726
city_map_radius_sq_get
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:136
city_total_unit_gold_upkeep
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1213
city_total_impr_gold_upkeep
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1192
city.h
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:508
city_tile
#define city_tile(_pcity_)
Definition city.h:564
CITY_MAP_MAX_RADIUS_SQ
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:86
city_owner
#define city_owner(_pcity_)
Definition city.h:563
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:510
city_tile_iterate
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:230
city_tile_iterate_end
#define city_tile_iterate_end
Definition city.h:238
trade_city
Definition menu.h:139
client
struct civclient client
Definition client_main.c:150
incite_cost
char * incite_cost
Definition comments.c:74
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:74
target_city
struct unit struct city * target_city
Definition dialogs_g.h:56
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:748
get_player_bonus
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
extra_type_list_of_unit_hiders
struct extra_type_list * extra_type_list_of_unit_hiders(void)
Definition extras.c:259
extra_type_list_iterate
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:165
extra_type_list_iterate_end
#define extra_type_list_iterate_end
Definition extras.h:167
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:487
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:481
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
O_SHIELD
@ O_SHIELD
Definition fc_types.h:101
O_GOLD
@ O_GOLD
Definition fc_types.h:101
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:62
wld
struct world wld
Definition game.c:63
game_remove_unit
void game_remove_unit(struct world *gworld, struct unit *punit)
Definition game.c:124
game_remove_city
void game_remove_city(struct world *gworld, struct city *pcity)
Definition game.c:178
game.h
government.h
owner
struct city * owner
Definition citydlg.c:220
type
GType type
Definition repodlgs.c:1313
idex_lookup_city
struct city * idex_lookup_city(struct world *iworld, int id)
Definition idex.c:133
idex_lookup_unit
struct unit * idex_lookup_unit(struct world *iworld, int id)
Definition idex.c:146
idex.h
improvement.h
WONDER_NOT_BUILT
#define WONDER_NOT_BUILT
Definition improvement.h:145
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
sq_map_distance
int sq_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:641
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
nation.h
NO_NATION_SELECTED
#define NO_NATION_SELECTED
Definition nation.h:30
is_settable_ai_level
bool is_settable_ai_level(enum ai_level level)
Definition player.c:1919
are_diplstates_equal
bool are_diplstates_equal(const struct player_diplstate *pds1, const struct player_diplstate *pds2)
Definition player.c:1501
player_can_invade_tile
bool player_can_invade_tile(const struct player *pplayer, const struct tile *ptile)
Definition player.c:270
player_knows_techs_with_flag
bool player_knows_techs_with_flag(const struct player *pplayer, enum tech_flag_id flag)
Definition player.c:1328
player_multiplier_effect_value
int player_multiplier_effect_value(const struct player *pplayer, const struct multiplier *pmul)
Definition player.c:1969
player_ai_data
void * player_ai_data(const struct player *pplayer, const struct ai_type *ai)
Definition player.c:1940
player_has_state
bool player_has_state(const struct player *pplayer, enum plrstate_type state)
Definition player.c:1998
player_slot_is_used
bool player_slot_is_used(const struct player_slot *pslot)
Definition player.c:448
diplrel_req_contradicts
bv_diplrel_all_reqs diplrel_req_contradicts(const struct requirement *req)
Definition player.c:1823
diplrel_mess_get
static bv_diplrel_all_reqs * diplrel_mess_get(void)
Definition player.c:1795
num_known_tech_with_flag
int num_known_tech_with_flag(const struct player *pplayer, enum tech_flag_id flag)
Definition player.c:1273
player_slots
static struct @69 player_slots
is_valid_username
bool is_valid_username(const char *name)
Definition player.c:1908
player_diplstate_new
static void player_diplstate_new(const struct player *plr1, const struct player *plr2)
Definition player.c:285
player_multiplier_target_value
int player_multiplier_target_value(const struct player *pplayer, const struct multiplier *pmul)
Definition player.c:1981
can_player_see_tile
bool can_player_see_tile(const struct player *plr, const struct tile *ptile)
Definition player.c:1091
player_unit_by_number
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
Definition player.c:1229
diplrel_mess
static bv_diplrel_all_reqs * diplrel_mess
Definition player.c:1790
player_by_name_prefix
struct player * player_by_name_prefix(const char *name, enum m_pre_result *result)
Definition player.c:920
diplrel_by_rule_name
int diplrel_by_rule_name(const char *value)
Definition player.c:1581
player_new
struct player * player_new(struct player_slot *pslot)
Definition player.c:493
player_by_number
struct player * player_by_number(const int player_id)
Definition player.c:849
player_in_city_map
bool player_in_city_map(const struct player *pplayer, const struct tile *ptile)
Definition player.c:1249
players_on_same_team
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1476
diplrel_mess_gen
static bv_diplrel_all_reqs * diplrel_mess_gen(void)
Definition player.c:1690
used_slots
int used_slots
Definition player.c:52
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:1034
player_count
int player_count(void)
Definition player.c:817
cancel_pact_result
enum diplstate_type cancel_pact_result(enum diplstate_type oldstate)
Definition player.c:68
player_slot_count
int player_slot_count(void)
Definition player.c:418
player_slot_by_number
struct player_slot * player_slot_by_number(int player_id)
Definition player.c:463
player_multiplier_value
int player_multiplier_value(const struct player *pplayer, const struct multiplier *pmul)
Definition player.c:1958
player_get_expected_income
int player_get_expected_income(const struct player *pplayer)
Definition player.c:1286
player_number
int player_number(const struct player *pplayer)
Definition player.c:837
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:159
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:895
player_diplstate_defaults
static void player_diplstate_defaults(const struct player *plr1, const struct player *plr2)
Definition player.c:305
player_slots_free
void player_slots_free(void)
Definition player.c:386
is_diplrel_to_other
bool is_diplrel_to_other(const struct player *pplayer, int diplrel)
Definition player.c:1562
player_slot_max_used_number
int player_slot_max_used_number(void)
Definition player.c:476
is_valid_alliance
static bool is_valid_alliance(const struct player *p1, const struct player *p2)
Definition player.c:132
can_player_see_unit
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1104
pplayers_at_war
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1388
player_set_ai_data
void player_set_ai_data(struct player *pplayer, const struct ai_type *ai, void *data)
Definition player.c:1948
player_diplstate_destroy
static void player_diplstate_destroy(const struct player *plr1, const struct player *plr2)
Definition player.c:341
player_ruleset_close
void player_ruleset_close(struct player *pplayer)
Definition player.c:745
player_clear
void player_clear(struct player *pplayer, bool full)
Definition player.c:669
player_slot_index
int player_slot_index(const struct player_slot *pslot)
Definition player.c:426
player_by_name
struct player * player_by_name(const char *name)
Definition player.c:881
player_slots_init
void player_slots_init(void)
Definition player.c:360
player_has_flag
bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
Definition player.c:1990
player_has_real_embassy
bool player_has_real_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:240
team_has_embassy
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:220
player_set_color
void player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Definition player.c:648
player_city_by_number
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1203
player_primary_capital
struct city * player_primary_capital(const struct player *pplayer)
Definition player.c:1337
player_index
int player_index(const struct player *pplayer)
Definition player.c:829
player_in_territory
int player_in_territory(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1878
player_by_user
struct player * player_by_user(const char *name)
Definition player.c:940
diplrel_name_translation
const char * diplrel_name_translation(int value)
Definition player.c:1627
is_diplrel_between
bool is_diplrel_between(const struct player *player1, const struct player *player2, int diplrel)
Definition player.c:1512
player_set_nation
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:861
DIPLREL_MESS_SIZE
#define DIPLREL_MESS_SIZE
Definition player.c:1680
player_can_see_city_externals
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Definition player.c:1164
player_age
int player_age(const struct player *pplayer)
Definition player.c:954
pplayer_can_cancel_treaty
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
Definition player.c:98
player_diplstate_get
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
number_of_ai_levels
int number_of_ai_levels(void)
Definition player.c:1932
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
player_defaults
static void player_defaults(struct player *pplayer)
Definition player.c:551
can_player_see_hypotetic_units_at
bool can_player_see_hypotetic_units_at(const struct player *pplayer, const struct tile *ptile)
Definition player.c:993
slots
struct player_slot * slots
Definition player.c:51
player_has_embassy_from_effect
bool player_has_embassy_from_effect(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:250
diplrel_mess_close
void diplrel_mess_close(void)
Definition player.c:1808
players_non_invade
bool players_non_invade(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1442
pplayers_non_attack
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1459
can_player_see_units_in_city
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:1133
player_slot_get_player
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:437
player_name_by_number
static const char * player_name_by_number(int i)
Definition player.c:909
can_player_see_city_internals
bool can_player_see_city_internals(const struct player *pplayer, const struct city *pcity)
Definition player.c:1149
player_slot_next
struct player_slot * player_slot_next(struct player_slot *pslot)
Definition player.c:407
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:967
player_slots_initialised
bool player_slots_initialised(void)
Definition player.c:378
love_text
const char * love_text(const int love)
Definition player.c:1354
gives_shared_tiles
bool gives_shared_tiles(const struct player *me, const struct player *them)
Definition player.c:1493
player_has_embassy
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:208
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:1640
diplrel_rule_name
const char * diplrel_rule_name(int value)
Definition player.c:1615
gives_shared_vision
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1485
player_owns_city
bool player_owns_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:261
player_slot_first
struct player_slot * player_slot_first(void)
Definition player.c:399
player_destroy
void player_destroy(struct player *pplayer)
Definition player.c:756
pplayers_in_peace
bool pplayers_in_peace(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1426
player.h
players_iterate_end
#define players_iterate_end
Definition player.h:537
dipl_reason
dipl_reason
Definition player.h:190
DIPL_SENATE_BLOCKING
@ DIPL_SENATE_BLOCKING
Definition player.h:191
DIPL_ALLIANCE_PROBLEM_THEM
@ DIPL_ALLIANCE_PROBLEM_THEM
Definition player.h:192
DIPL_ALLIANCE_PROBLEM_US
@ DIPL_ALLIANCE_PROBLEM_US
Definition player.h:192
DIPL_OK
@ DIPL_OK
Definition player.h:191
DIPL_ERROR
@ DIPL_ERROR
Definition player.h:191
players_iterate
#define players_iterate(_pplayer)
Definition player.h:532
player_list_iterate
#define player_list_iterate(playerlist, pplayer)
Definition player.h:555
MAX_AI_LOVE
#define MAX_AI_LOVE
Definition player.h:561
ANON_USER_NAME
#define ANON_USER_NAME
Definition player.h:48
is_barbarian
static bool is_barbarian(const struct player *pplayer)
Definition player.h:489
player_slots_iterate
#define player_slots_iterate(_pslot)
Definition player.h:523
player_list_iterate_end
#define player_list_iterate_end
Definition player.h:557
PLAYER_DEFAULT_SCIENCE_RATE
#define PLAYER_DEFAULT_SCIENCE_RATE
Definition player.h:40
set_as_human
#define set_as_human(plr)
Definition player.h:231
players_iterate_alive_end
#define players_iterate_alive_end
Definition player.h:547
player_slots_iterate_end
#define player_slots_iterate_end
Definition player.h:527
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:542
requirement_diplrel_ereq
#define requirement_diplrel_ereq(_id_, _range_, _present_)
Definition requirements.h:449
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:128
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:190
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:1587
is_ascii_name
bool is_ascii_name(const char *name)
Definition shared.c:283
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:360
ai_type
Definition ai.h:50
attribute_block_s::data
void * data
Definition player.h:219
attribute_block_s::length
int length
Definition player.h:220
city
Definition city.h:320
city::capital
enum capital_type capital
Definition city.h:328
city::tile
struct tile * tile
Definition city.h:322
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:239
multiplier_value::target
int target
Definition player.h:241
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:98
nation_type::player
struct player * player
Definition nation.h:118
packet_game_info::gold_upkeep_style
enum gold_upkeep_style gold_upkeep_style
Definition packets_gen.h:166
packet_game_info::reveal_trade_partner
bool reveal_trade_partner
Definition packets_gen.h:159
player_ai::skill_level
enum ai_level skill_level
Definition player.h:114
player_ai::traits
struct ai_trait * traits
Definition player.h:124
player_ai::barbarian_type
enum barbarian_type barbarian_type
Definition player.h:120
player_ai::love
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:122
player_ai::expand
int expand
Definition player.h:116
player_ai::fuzzy
int fuzzy
Definition player.h:115
player_diplstate
Definition player.h:196
player_diplstate::type
enum diplstate_type type
Definition player.h:197
player_diplstate::has_reason_to_cancel
char has_reason_to_cancel
Definition player.h:201
player_economic::luxury
int luxury
Definition player.h:64
player_economic::science
int science
Definition player.h:63
player_economic::tax
int tax
Definition player.h:62
player_economic::infra_points
int infra_points
Definition player.h:65
player_economic::gold
int gold
Definition player.h:61
player_slot
Definition player.c:46
player_slot::player
struct player * player
Definition player.c:47
player
Definition player.h:247
player::cities
struct city_list * cities
Definition player.h:279
player::random_name
bool random_name
Definition player.h:293
player::ai_common
struct player_ai ai_common
Definition player.h:286
player::flags
bv_plr_flags flags
Definition player.h:290
player::tile_vision
struct dbv tile_vision[V_COUNT]
Definition player.h:357
player::primary_capital_id
int primary_capital_id
Definition player.h:273
player::is_male
bool is_male
Definition player.h:255
player::wonders
int wonders[B_LAST]
Definition player.h:303
player::diplstates
const struct player_diplstate ** diplstates
Definition player.h:276
player::unassigned_ranked
bool unassigned_ranked
Definition player.h:253
player::target_government
struct government * target_government
Definition player.h:257
player::autoselect_weight
int autoselect_weight
Definition player.h:297
player::username
char username[MAX_LEN_NAME]
Definition player.h:250
player::is_winner
bool is_winner
Definition player.h:267
player::is_connected
bool is_connected
Definition player.h:294
player::revolution_finishes
int revolution_finishes
Definition player.h:271
player::ais
void * ais[FREECIV_AI_MOD_LAST]
Definition player.h:334
player::nturns_idle
int nturns_idle
Definition player.h:263
player::government
struct government * government
Definition player.h:256
player::tile_known
struct dbv tile_known
Definition player.h:308
player::current_conn
struct connection * current_conn
Definition player.h:295
player::team
struct team * team
Definition player.h:259
player::savegame_ai_type_name
char * savegame_ai_type_name
Definition player.h:288
player::turns_alive
int turns_alive
Definition player.h:264
player::was_created
bool was_created
Definition player.h:292
player::ai
const struct ai_type * ai
Definition player.h:287
player::units
struct unit_list * units
Definition player.h:280
player::ranked_username
char ranked_username[MAX_LEN_NAME]
Definition player.h:252
player::connections
struct conn_list * connections
Definition player.h:296
player::is_alive
bool is_alive
Definition player.h:266
player::real_embassy
bv_player real_embassy
Definition player.h:275
player::client
struct player::@70::@73 client
player::economic
struct player_economic economic
Definition player.h:282
player::spaceship
struct player_spaceship spaceship
Definition player.h:284
player::attribute_block
struct attribute_block_s attribute_block
Definition player.h:305
player::name
char name[MAX_LEN_NAME]
Definition player.h:249
player::gives_shared_vision
bv_player gives_shared_vision
Definition player.h:300
player::attribute_block_buffer
struct attribute_block_s attribute_block_buffer
Definition player.h:306
player::multipliers
struct multiplier_value multipliers[MAX_NUM_MULTIPLIERS]
Definition player.h:312
player::nation
struct nation_type * nation
Definition player.h:258
player::music_style
int music_style
Definition player.h:278
player::style
struct nation_style * style
Definition player.h:277
player::phase_done
bool phase_done
Definition player.h:261
player::slot
struct player_slot * slot
Definition player.h:248
player::gives_shared_tiles
bv_player gives_shared_tiles
Definition player.h:302
player::is_ready
bool is_ready
Definition player.h:260
player::server
struct player::@70::@72 server
player::user_turns
int user_turns
Definition player.h:254
player::last_war_action
int last_war_action
Definition player.h:268
player::rgb
struct rgbcolor * rgb
Definition player.h:310
player::unassigned_user
bool unassigned_user
Definition player.h:251
req_context
Definition requirements.h:100
requirement
Definition requirements.h:81
requirement::present
bool present
Definition requirements.h:85
requirement::range
enum req_range range
Definition requirements.h:83
requirement::source
struct universal source
Definition requirements.h:82
research::num_known_tech_with_flag
int num_known_tech_with_flag[TF_COUNT]
Definition research.h:88
rgbcolor
Definition rgbcolor.h:33
team
Definition team.c:40
tile
Definition tile.h:50
tile::units
struct unit_list * units
Definition tile.h:58
tile::extras_owner
struct player * extras_owner
Definition tile.h:63
unit_class
Definition unittype.h:149
unit_type
Definition unittype.h:500
unit
Definition unit.h:138
unit::client
struct unit::@81::@83 client
unit::transporting
struct unit_list * transporting
Definition unit.h:184
unit::transported_by
int transported_by
Definition unit.h:216
universal::kind
enum universals_n kind
Definition fc_types.h:903
universal::value
universals_u value
Definition fc_types.h:902
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:1232
fc_strncasequotecmp
int fc_strncasequotecmp(const char *str0, const char *str1, size_t n)
Definition support.c:380
effectivestrlenquote
size_t effectivestrlenquote(const char *str)
Definition support.c:359
support.h
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:189
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
fc__fallthrough
#define fc__fallthrough
Definition support.h:119
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
terrain_has_flag
#define terrain_has_flag(terr, flag)
Definition terrain.h:283
tile_is_seen
bool tile_is_seen(const struct tile *target_tile, const struct player *pow_player)
Definition tile.c:407
tile_get_known
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:392
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
TILE_KNOWN_SEEN
@ TILE_KNOWN_SEEN
Definition tile.h:38
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:110
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
tile_owner
#define tile_owner(_tile)
Definition tile.h:96
trade_partners_iterate_end
#define trade_partners_iterate_end
Definition traderoutes.h:166
trade_partners_iterate
#define trade_partners_iterate(c, p)
Definition traderoutes.h:161
universals_u::diplrel
int diplrel
Definition fc_types.h:750
is_hiding_unit
bool is_hiding_unit(const struct unit *punit)
Definition unit.c:428
unit_nationality
struct player * unit_nationality(const struct unit *punit)
Definition unit.c:1242
unit_transport_unload
bool unit_transport_unload(struct unit *pcargo)
Definition unit.c:2386
unit_transported
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2421
unit_transport_cargo
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
Definition unit.c:2447
unit.h
unit_tile
#define unit_tile(_pu)
Definition unit.h:390
unit_owner
#define unit_owner(_pu)
Definition unit.h:389
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:2498
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