Freeciv-3.1
Loading...
Searching...
No Matches
barbarian.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2003 - 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/***********************************************************************
15 Functions for creating barbarians in huts, land and sea
16 Started by Jerzy Klek <jekl@altavista.net>
17 with more ideas from Falk Hueffner
18***********************************************************************/
19
20#ifdef HAVE_CONFIG_H
21#include <fc_config.h>
22#endif
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27
28/* utility */
29#include "fcintl.h"
30#include "log.h"
31#include "rand.h"
32#include "support.h"
33
34/* common */
35#include "effects.h"
36#include "events.h"
37#include "game.h"
38#include "government.h"
39#include "map.h"
40#include "movement.h"
41#include "nation.h"
42#include "research.h"
43#include "tech.h"
44#include "terrain.h"
45#include "unitlist.h"
46
47/* server */
48#include "aiiface.h"
49#include "citytools.h"
50#include "diplhand.h"
51#include "gamehand.h"
52#include "maphand.h"
53#include "notify.h"
54#include "plrhand.h"
55#include "srv_main.h"
56#include "stdinhand.h"
57#include "techtools.h"
58#include "unithand.h"
59#include "unittools.h"
60
61/* server/advisors */
62#include "advdata.h"
63
64/* ai */
65#include "difficulty.h"
66
67#include "barbarian.h"
68
69#define BARBARIAN_INITIAL_VISION_RADIUS 3
70#define BARBARIAN_INITIAL_VISION_RADIUS_SQ 9
71
72/**********************************************************************/
75bool is_land_barbarian(struct player *pplayer)
76{
77 return (pplayer->ai_common.barbarian_type == LAND_BARBARIAN
78 || pplayer->ai_common.barbarian_type == LAND_AND_SEA_BARBARIAN);
79}
80
81/**********************************************************************/
84bool is_sea_barbarian(struct player *pplayer)
85{
86 return (pplayer->ai_common.barbarian_type == SEA_BARBARIAN
87 || pplayer->ai_common.barbarian_type == LAND_AND_SEA_BARBARIAN);
88}
89
90/**********************************************************************/
97struct player *create_barbarian_player(enum barbarian_type type)
98{
99 struct player *barbarians;
100 struct nation_type *nation = NULL;
101 struct research *presearch;
102
103 players_iterate(old_barbs) {
104 if ((type == LAND_BARBARIAN && is_land_barbarian(old_barbs))
105 || (type == SEA_BARBARIAN && is_sea_barbarian(old_barbs))) {
106 if (!old_barbs->is_alive) {
107 old_barbs->economic.gold = 0;
108 old_barbs->is_alive = TRUE;
109 player_status_reset(old_barbs);
110
111 /* Free old name so pick_random_player_name() can select it again.
112 * This is needed in case ruleset defines just one leader for
113 * barbarian nation. */
114 old_barbs->name[0] = '\0';
115 server_player_set_name(old_barbs,
117 sz_strlcpy(old_barbs->username, _(ANON_USER_NAME));
118 old_barbs->unassigned_user = TRUE;
119 /* I need to make them to forget the map, I think */
120 whole_map_iterate(&(wld.map), ptile) {
121 map_clear_known(ptile, old_barbs);
123 }
124 old_barbs->economic.gold += 100; /* New leader, new money */
125
126 return old_barbs;
127 }
129
130 /* make a new player, or not */
131 barbarians = server_create_player(-1, default_ai_type_name(), NULL, FALSE);
132 if (!barbarians) {
133 return NULL;
134 }
135 server_player_init(barbarians, TRUE, TRUE);
136
137 if (type == LAND_BARBARIAN || type == SEA_BARBARIAN) {
138 /* Try LAND_AND_SEA *FIRST*, so that we don't end up
139 * with one of the Land/Sea barbarians created first and
140 * then LAND_AND_SEA created instead of the second. */
141 nation = pick_a_nation(NULL, FALSE, FALSE, LAND_AND_SEA_BARBARIAN);
142 if (nation != NULL) {
143 type = LAND_AND_SEA_BARBARIAN;
144 }
145 }
146
147 if (nation == NULL) {
148 nation = pick_a_nation(NULL, FALSE, FALSE, type);
149 }
150
151 /* Ruleset loading time checks should guarantee that there always is
152 suitable nation available */
153 fc_assert(nation != NULL);
154
155 player_nation_defaults(barbarians, nation, TRUE);
156 if (game_was_started()) {
157 /* Find a color for the new player. */
159 }
160
161 server.nbarbarians++;
162
163 sz_strlcpy(barbarians->username, _(ANON_USER_NAME));
164 barbarians->unassigned_user = TRUE;
165 barbarians->is_connected = FALSE;
166 barbarians->government = init_government_of_nation(nation);
167 fc_assert(barbarians->revolution_finishes < 0);
168 barbarians->server.got_first_city = FALSE;
169 barbarians->economic.gold = 100;
170
171 barbarians->phase_done = TRUE;
172
173 /* Do the ai */
174 set_as_ai(barbarians);
175 barbarians->ai_common.barbarian_type = type;
177
178 presearch = research_get(barbarians);
179 init_tech(presearch, TRUE);
180 give_initial_techs(presearch, 0);
181
182 /* Ensure that we are at war with everyone else */
183 barbarian_initial_wars(barbarians);
184
185 CALL_PLR_AI_FUNC(gained_control, barbarians, barbarians);
186
187 log_verbose("Created barbarian %s, player %d", player_name(barbarians),
188 player_number(barbarians));
189 notify_player(NULL, NULL, E_UPRISING, ftc_server,
190 _("%s gain a leader by the name %s. Dangerous "
191 "times may lie ahead."),
192 nation_plural_for_player(barbarians),
193 player_name(barbarians));
194
195 send_player_all_c(barbarians, NULL);
196 /* Send research info after player info, else the client will complain
197 * about invalid team. */
198 send_research_info(presearch, NULL);
199
200 return barbarians;
201}
202
203/**********************************************************************/
206static void init_dir_checked_status(bool *checked,
207 enum terrain_class *terrainc,
208 enum terrain_class tclass)
209{
210 int dir;
211
212 for (dir = 0; dir < 8; dir++) {
213 if (terrainc[dir] == tclass) {
214 checked[dir] = FALSE;
215 } else {
216 checked[dir] = TRUE;
217 }
218 }
219}
220
221/**********************************************************************/
224static int random_unchecked_direction(int possibilities, const bool *checked)
225{
226 int j = -1;
227 int i;
228
229 int num = fc_rand(possibilities);
230 for (i = 0; i <= num; i++) {
231 j++;
232 while (checked[j]) {
233 j++;
234 fc_assert(j < 8);
235 }
236 }
237
238 return j;
239}
240
241/**********************************************************************/
244static void unit_move_pay(struct unit *punit, struct tile *pdesttile)
245{
246 int move_cost = map_move_cost_unit(&(wld.map), punit, pdesttile);
247
248 unit_move(punit, pdesttile, move_cost,
249 /* Don't override "Transport Embark" */
250 NULL, FALSE,
251 /* Don't override "Conquer City" */
252 FALSE,
253 /* Don't override "Conquer Extras" */
254 FALSE,
255 /* Don't override "Enter Hut" */
256 FALSE,
257 /* Don't override "Frighten Hut" */
258 FALSE);
259}
260
261/**********************************************************************/
271bool unleash_barbarians(struct tile *ptile)
272{
273 struct player *barbarians;
274 int unit_cnt;
275 int i;
276 bool alive = TRUE; /* explorer survived */
277 enum terrain_class terrainc[8];
278 struct tile *dir_tiles[8];
279 int land_tiles = 0;
280 int ocean_tiles = 0;
281 bool checked[8];
282 int checked_count;
283 int dir;
284 bool barbarian_stays = FALSE;
285 const struct civ_map *nmap = &(wld.map);
286
287 /* FIXME: When there is no L_BARBARIAN unit,
288 * but L_BARBARIAN_TECH is already available,
289 * we should unleash those.
290 * Doesn't affect any ruleset I'm aware of. */
293 || num_role_units(L_BARBARIAN) == 0) {
294 unit_list_iterate_safe((ptile)->units, punit) {
295 wipe_unit(punit, ULR_BARB_UNLEASH, NULL);
297 return FALSE;
298 }
299
300 barbarians = create_barbarian_player(LAND_BARBARIAN);
301 if (!barbarians) {
302 return FALSE;
303 }
304
305 adv_data_phase_init(barbarians, TRUE);
306 CALL_PLR_AI_FUNC(phase_begin, barbarians, barbarians, TRUE);
307
308 unit_cnt = 3 + fc_rand(4);
309 for (i = 0; i < unit_cnt; i++) {
310 struct unit_type *punittype
311 = find_a_unit_type(L_BARBARIAN, L_BARBARIAN_TECH);
312
313 /* If unit cannot live on this tile, we just don't create one.
314 * Maybe find_a_unit_type() should take tile parameter, so
315 * we could get suitable unit if one exist. */
316 if (is_native_tile(punittype, ptile)
317 && !utype_player_already_has_this_unique(barbarians, punittype)) {
318 struct unit *barb_unit;
319
320 barb_unit = create_unit(barbarians, ptile, punittype, 0, 0, -1);
321 log_debug("Created barbarian unit %s", utype_rule_name(punittype));
322 send_unit_info(NULL, barb_unit);
323 }
324 }
325
326 /* Get information about surrounding terrains in terrain class level.
327 * Only needed if we consider moving units away to random directions. */
328 for (dir = 0; dir < 8; dir++) {
329 dir_tiles[dir] = mapstep(nmap, ptile, dir);
330 if (dir_tiles[dir] == NULL) {
331 terrainc[dir] = terrain_class_invalid();
332 } else if (!is_non_allied_unit_tile(dir_tiles[dir], barbarians)) {
333 if (is_ocean_tile(dir_tiles[dir])) {
334 terrainc[dir] = TC_OCEAN;
335 ocean_tiles++;
336 } else {
337 terrainc[dir] = TC_LAND;
338 land_tiles++;
339 }
340 } else {
341 terrainc[dir] = terrain_class_invalid();
342 }
343 }
344
345 if (land_tiles >= 3) {
346 /* Enough land, scatter guys around */
347 unit_list_iterate_safe((ptile)->units, punit2) {
348 if (unit_owner(punit2) == barbarians) {
349 bool dest_found = FALSE;
350
351 /* Initialize checked status for checking free land tiles */
352 init_dir_checked_status(checked, terrainc, TC_LAND);
353
354 /* Search tile to move to */
355 for (checked_count = 0; !dest_found && checked_count < land_tiles;
356 checked_count++) {
357 int rdir = random_unchecked_direction(land_tiles - checked_count, checked);
358
359 if (unit_can_move_to_tile(nmap, punit2, dir_tiles[rdir],
360 TRUE, FALSE, FALSE)) {
361 /* Move */
362 (void) unit_move_pay(punit2, dir_tiles[rdir]);
363 log_debug("Moved barbarian unit from (%d, %d) to (%d, %d)",
364 TILE_XY(ptile), TILE_XY(dir_tiles[rdir]));
365 dest_found = TRUE;
366 }
367
368 checked[rdir] = TRUE;
369 }
370 if (!dest_found) {
371 /* This barbarian failed to move out of hut tile. */
372 barbarian_stays = TRUE;
373 }
374 }
376
377 } else {
378 if (ocean_tiles > 0) {
379 /* maybe it's an island, try to get on boats */
380 struct unit *boat = NULL; /* Boat */
381
382 /* Initialize checked status for checking Ocean tiles */
383 init_dir_checked_status(checked, terrainc, TC_OCEAN);
384
385 /* Search tile for boat. We always create just one boat. */
386 for (checked_count = 0; boat == NULL && checked_count < ocean_tiles;
387 checked_count++) {
388 struct unit_type *candidate;
389 int rdir = random_unchecked_direction(ocean_tiles - checked_count, checked);
390
391 candidate = find_a_unit_type(L_BARBARIAN_BOAT, -1);
392 if (is_native_tile(candidate, dir_tiles[rdir])
393 && !utype_player_already_has_this_unique(barbarians, candidate)) {
394 boat = create_unit(barbarians, dir_tiles[rdir], candidate,
395 0, 0, -1);
396 }
397
398 checked[rdir] = TRUE;
399 }
400
401 if (boat) {
402 /* We do have a boat. Try to get everybody in */
403 unit_list_iterate_safe((ptile)->units, punit2) {
404 if (unit_owner(punit2) == barbarians) {
405 if (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK,
406 punit2, boat)) {
407 /* Load */
408 unit_do_action(unit_owner(punit2), punit2->id, boat->id,
409 0, "", ACTION_TRANSPORT_EMBARK);
410 } else if (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK2,
411 punit2, boat)) {
412 /* Load */
413 unit_do_action(unit_owner(punit2), punit2->id, boat->id,
414 0, "", ACTION_TRANSPORT_EMBARK2);
415 } else if (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK3,
416 punit2, boat)) {
417 /* Load */
418 unit_do_action(unit_owner(punit2), punit2->id, boat->id,
419 0, "", ACTION_TRANSPORT_EMBARK3);
420 }
421 }
423 }
424
425 /* Move rest of the barbarians to random land tiles */
426 unit_list_iterate_safe((ptile)->units, punit2) {
427 if (unit_owner(punit2) == barbarians) {
428 bool dest_found = FALSE;
429
430 /* Initialize checked status for checking Land tiles */
431 init_dir_checked_status(checked, terrainc, TC_LAND);
432
433 /* Search tile to move to */
434 for (checked_count = 0; !dest_found && checked_count < land_tiles;
435 checked_count++) {
436 int rdir;
437
438 rdir = random_unchecked_direction(land_tiles - checked_count, checked);
439
440 if (unit_can_move_to_tile(nmap, punit2, dir_tiles[rdir],
441 TRUE, FALSE, FALSE)) {
442 /* Move */
443 (void) unit_move_pay(punit2, dir_tiles[rdir]);
444 dest_found = TRUE;
445 }
446
447 checked[rdir] = TRUE;
448 }
449 if (!dest_found) {
450 /* This barbarian failed to move out of hut tile. */
451 barbarian_stays = TRUE;
452 }
453 }
455 } else {
456 /* The village is surrounded! Barbarians cannot leave. */
457 barbarian_stays = TRUE;
458 }
459 }
460
461 if (barbarian_stays) {
462 /* There's barbarian in this village! Kill the explorer. */
463 unit_list_iterate_safe((ptile)->units, punit2) {
464 if (unit_owner(punit2) != barbarians) {
465 wipe_unit(punit2, ULR_BARB_UNLEASH, NULL);
466 alive = FALSE;
467 } else {
468 send_unit_info(NULL, punit2);
469 }
471 }
472
473 /* FIXME: I don't know if this is needed */
474 if (ptile) {
476 }
477
478 return alive;
479}
480
481/**********************************************************************/
484static bool is_near_land(struct tile *tile0)
485{
486 square_iterate(&(wld.map), tile0, 4, ptile) {
487 if (!is_ocean_tile(ptile)) {
488 return TRUE;
489 }
491
492 return FALSE;
493}
494
495/**********************************************************************/
498static struct tile *find_empty_tile_nearby(struct tile *ptile)
499{
500 square_iterate(&(wld.map), ptile, 1, tile1) {
501 if (unit_list_size(tile1->units) == 0) {
502 return tile1;
503 }
505
506 return NULL;
507}
508
509/**********************************************************************/
527static void try_summon_barbarians(void)
528{
529 struct tile *ptile, *utile;
530 int i, dist;
531 int uprise;
532 struct city *pc;
533 struct player *barbarians, *victim;
534 struct unit_type *leader_type;
535 int barb_count, really_created = 0;
536 bool hut_present = FALSE;
537 int city_count;
538 int city_max;
539 const struct civ_map *nmap = &(wld.map);
540
541 /* We attempt the summons on a particular, random position. If this is
542 * an invalid position then the summons simply fails this time. This means
543 * that a particular tile's chance of being summoned on is independent of
544 * all the other tiles on the map - which is essential for balanced
545 * gameplay. */
546 ptile = rand_map_pos(nmap);
547
548 if (terrain_has_flag(tile_terrain(ptile), TER_NO_BARBS)) {
549 return;
550 }
551
552 if (!(pc = find_closest_city(ptile, NULL, NULL, FALSE, FALSE, FALSE, FALSE,
553 FALSE, NULL))) {
554 /* any city */
555 return;
556 }
557
558 victim = city_owner(pc);
559
560 dist = real_map_distance(ptile, pc->tile);
561 log_debug("Closest city (to %d,%d) is %s (at %d,%d) distance %d.",
562 TILE_XY(ptile), city_name_get(pc), TILE_XY(pc->tile), dist);
563 if (dist > MAX_UNREST_DIST || dist < MIN_UNREST_DIST) {
564 return;
565 }
566
567 /* I think Sea Raiders can come out of unknown sea territory */
568 if (!(utile = find_empty_tile_nearby(ptile))
569 || (!map_is_known(utile, victim)
570 && !is_ocean_tile(utile))
571 || !is_near_land(utile)) {
572 return;
573 }
574
576
577 /* do not harass small civs - in practice: do not uprise at the beginning */
578 if ((int)fc_rand(30) + 1 >
579 (int)city_list_size(victim->cities) * (game.server.barbarianrate - 1)
580 || fc_rand(100) > get_player_bonus(victim, EFT_CIVIL_WAR_CHANCE)) {
581 return;
582 }
583 log_debug("Barbarians are willing to fight");
584
585 /* Remove huts in place of uprising */
586 /* FIXME: Should we really always do it? */
587 extra_type_by_rmcause_iterate(ERM_ENTER, pextra) {
588 if (tile_has_extra(utile, pextra)) {
589 tile_extra_rm_apply(utile, pextra);
590 hut_present = TRUE;
591 }
593
594 if (hut_present) {
596 }
597
598 city_count = city_list_size(victim->cities);
599 city_max = UPRISE_CIV_SIZE;
600 uprise = 1;
601
602 while (city_max <= city_count) {
603 uprise++;
604 city_max += (city_max * 1.2) + UPRISE_CIV_SIZE;
605 }
606
607 barb_count = fc_rand(3) + uprise * game.server.barbarianrate;
608 leader_type = get_role_unit(L_BARBARIAN_LEADER, 0);
609
610 if (!is_ocean_tile(utile)) {
611 /* land (disembark) barbarians */
612 barbarians = create_barbarian_player(LAND_BARBARIAN);
613 if (!barbarians) {
614 return;
615 }
616 for (i = 0; i < barb_count; i++) {
617 struct unit_type *punittype
618 = find_a_unit_type(L_BARBARIAN, L_BARBARIAN_TECH);
619
620 /* If unit cannot live on this tile, we just don't create one.
621 * Maybe find_a_unit_type() should take tile parameter, so
622 * we could get suitable unit if one exist. */
623 if (is_native_tile(punittype, utile)
624 && !utype_player_already_has_this_unique(barbarians, punittype)) {
625 (void) create_unit(barbarians, utile, punittype, 0, 0, -1);
626 really_created++;
627 log_debug("Created barbarian unit %s", utype_rule_name(punittype));
628 }
629 }
630
631 if (is_native_tile(leader_type, utile)
632 && !utype_player_already_has_this_unique(barbarians, leader_type)) {
633 (void) create_unit(barbarians, utile,
634 leader_type, 0, 0, -1);
635 really_created++;
636 }
637 } else { /* Sea raiders - their units will be veteran */
638 struct unit *ptrans;
639 struct unit_type *boat;
640 bool miniphase;
641
642 barbarians = create_barbarian_player(SEA_BARBARIAN);
643 if (!barbarians) {
644 return;
645 }
646 /* Setup data phase if it's not already set up. Created ferries may
647 need that data.
648 We don't know if create_barbarian_player() above created completely
649 new player or did it just return existing one. If it was existing
650 one, phase has already been set up at turn begin and will be closed
651 at turn end. If this is completely new player, we have to take care
652 of both opening and closing the data phase. Return value of
653 adv_data_phase_init() tells us if data phase was already initialized
654 at turn beginning. */
655 miniphase = adv_data_phase_init(barbarians, TRUE);
656 if (miniphase) {
657 CALL_PLR_AI_FUNC(phase_begin, barbarians, barbarians, TRUE);
658 }
659
660 boat = find_a_unit_type(L_BARBARIAN_BOAT,-1);
661
662 if (is_native_tile(boat, utile)
663 && !utype_player_already_has_this_unique(barbarians, boat)
664 && (is_safe_ocean(nmap, utile)
665 || (!utype_has_flag(boat, UTYF_COAST_STRICT)
666 && !utype_has_flag(boat, UTYF_COAST)))) {
667 int cap;
668
669 ptrans = create_unit(barbarians, utile, boat, 0, 0, -1);
670 really_created++;
671 cap = get_transporter_capacity(ptrans);
672
673 /* Fill boat with barb_count barbarians at max, leave space for leader */
674 for (i = 0; i < cap - 1 && i < barb_count; i++) {
675 struct unit_type *barb
676 = find_a_unit_type(L_BARBARIAN_SEA, L_BARBARIAN_SEA_TECH);
677
678 if (can_unit_type_transport(boat, utype_class(barb))
679 && !utype_player_already_has_this_unique(barbarians, barb)) {
680 (void) create_unit_full(barbarians, utile, barb, 0, 0, -1, -1,
681 ptrans);
682 really_created++;
683 log_debug("Created barbarian unit %s", utype_rule_name(barb));
684 }
685 }
686
687 if (can_unit_type_transport(boat, utype_class(leader_type))
688 && !utype_player_already_has_this_unique(barbarians, leader_type)) {
689 (void) create_unit_full(barbarians, utile, leader_type, 0, 0,
690 -1, -1, ptrans);
691 really_created++;
692 }
693 }
694
695 if (miniphase) {
696 CALL_PLR_AI_FUNC(phase_finished, barbarians, barbarians);
697 adv_data_phase_done(barbarians);
698 }
699 }
700
701 if (really_created == 0) {
702 /* No barbarians found suitable spot */
703 return;
704 }
705
706 /* Is this necessary? create_unit_full() already sends unit info. */
707 unit_list_iterate(utile->units, punit2) {
708 send_unit_info(NULL, punit2);
710
711 /* to let them know where to get you */
714
715 /* There should probably be a different message about Sea Raiders */
716 if (is_land_barbarian(barbarians)) {
717 notify_player(victim, utile, E_UPRISING, ftc_server,
718 _("Native unrest near %s led by %s."),
719 city_link(pc),
720 player_name(barbarians));
721 } else if (map_is_known_and_seen(utile, victim, V_MAIN)) {
722 notify_player(victim, utile, E_UPRISING, ftc_server,
723 _("Sea raiders seen near %s!"),
724 city_link(pc));
725 }
726}
727
728/**********************************************************************/
733{
734 int i, n;
735
738 return;
739 }
740
742 return;
743 }
744
746 if (n == 0) {
747 /* Allow barbarians on maps smaller than MAP_FACTOR */
748 n = 1;
749 }
750
751 for (i = 0; i < n * (game.server.barbarianrate - 1); i++) {
753 }
754}
755
756/**********************************************************************/
759void barbarian_initial_wars(struct player *barbarians)
760{
761 /* It would be nice to get rid of this special case,
762 * and make barbarians to switch from "No Contact" to "War"
763 * upon first contact like everyone else. Then other parts
764 * of the code would not need to be prepared to the possibility
765 * of a war between no-contact nations.
766 * The problem is that if barbarians were not in War, they would
767 * likely not to head to attack towards yet-unknown players
768 * as aggressively */
769
770 players_iterate(pplayer) {
771 if (pplayer != barbarians) {
772 set_diplstate_type(player_diplstate_get(pplayer, barbarians),
773 player_diplstate_get(barbarians, pplayer),
774 DS_WAR);
775 }
777}
bool is_action_enabled_unit_on_unit(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct unit *target_unit)
Definition actions.c:4832
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
Definition advdata.c:262
void adv_data_phase_done(struct player *pplayer)
Definition advdata.c:553
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:374
const char * default_ai_type_name(void)
Definition aiiface.c:262
#define n
Definition astring.c:77
static struct tile * find_empty_tile_nearby(struct tile *ptile)
Definition barbarian.c:498
static void try_summon_barbarians(void)
Definition barbarian.c:527
void barbarian_initial_wars(struct player *barbarians)
Definition barbarian.c:759
bool unleash_barbarians(struct tile *ptile)
Definition barbarian.c:271
void summon_barbarians(void)
Definition barbarian.c:732
#define BARBARIAN_INITIAL_VISION_RADIUS_SQ
Definition barbarian.c:70
static void init_dir_checked_status(bool *checked, enum terrain_class *terrainc, enum terrain_class tclass)
Definition barbarian.c:206
bool is_sea_barbarian(struct player *pplayer)
Definition barbarian.c:84
static bool is_near_land(struct tile *tile0)
Definition barbarian.c:484
static void unit_move_pay(struct unit *punit, struct tile *pdesttile)
Definition barbarian.c:244
bool is_land_barbarian(struct player *pplayer)
Definition barbarian.c:75
static int random_unchecked_direction(int possibilities, const bool *checked)
Definition barbarian.c:224
struct player * create_barbarian_player(enum barbarian_type type)
Definition barbarian.c:97
#define MAP_FACTOR
Definition barbarian.h:28
#define UPRISE_CIV_SIZE
Definition barbarian.h:26
#define MIN_UNREST_DIST
Definition barbarian.h:23
#define MAX_UNREST_DIST
Definition barbarian.h:24
const char * city_name_get(const struct city *pcity)
Definition city.c:1115
#define city_owner(_pcity_)
Definition city.h:543
struct city * find_closest_city(const struct tile *ptile, const struct city *pexclcity, const struct player *pplayer, bool only_ocean, bool only_continent, bool only_known, bool only_player, bool only_enemy, const struct unit_class *pclass)
Definition citytools.c:854
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
void set_ai_level_directer(struct player *pplayer, enum ai_level level)
Definition difficulty.c:39
void set_diplstate_type(struct player_diplstate *state1, struct player_diplstate *state2, enum diplstate_type type)
Definition diplhand.c:159
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:771
#define extra_type_by_rmcause_iterate_end
Definition extras.h:334
#define extra_type_by_rmcause_iterate(_rmcause, _extra)
Definition extras.h:329
#define _(String)
Definition fcintl.h:67
const struct ft_color ftc_server
const char * city_link(const struct city *pcity)
struct civ_game game
Definition game.c:57
struct world wld
Definition game.c:58
@ BARBS_HUTS_ONLY
Definition game.h:53
@ BARBS_DISABLED
Definition game.h:52
GType type
Definition repodlgs.c:1312
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define log_debug(message,...)
Definition log.h:115
int map_num_tiles(void)
Definition map.c:1012
struct tile * rand_map_pos(const struct civ_map *nmap)
Definition map.c:1086
bool is_safe_ocean(const struct civ_map *nmap, const struct tile *ptile)
Definition map.c:665
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:628
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Definition map.c:369
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:385
#define square_iterate_end
Definition map.h:388
static int map_move_cost_unit(const struct civ_map *nmap, struct unit *punit, const struct tile *ptile)
Definition map.h:287
#define whole_map_iterate(_map, _tile)
Definition map.h:539
#define whole_map_iterate_end
Definition map.h:548
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:886
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:900
void map_show_circle(struct player *pplayer, struct tile *ptile, int radius_sq)
Definition maphand.c:856
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1427
void map_clear_known(struct tile *ptile, struct player *pplayer)
Definition maphand.c:1167
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:316
bool unit_can_move_to_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *dst_tile, bool igzoc, bool enter_transport, bool enter_enemy_city)
Definition movement.c:557
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:826
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:177
struct government * init_government_of_nation(const struct nation_type *pnation)
Definition nation.c:658
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:291
int player_number(const struct player *pplayer)
Definition player.c:828
const char * player_name(const struct player *pplayer)
Definition player.c:886
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:317
#define players_iterate_end
Definition player.h:535
#define players_iterate(_pplayer)
Definition player.h:530
#define ANON_USER_NAME
Definition player.h:48
#define set_as_ai(plr)
Definition player.h:236
void server_player_set_name(struct player *pplayer, const char *name)
Definition plrhand.c:2097
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:983
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1723
struct nation_type * pick_a_nation(const struct nation_list *choices, bool ignore_conflicts, bool needs_startpos, enum barbarian_type barb_type)
Definition plrhand.c:2282
void player_status_reset(struct player *plr)
Definition plrhand.c:3058
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Definition plrhand.c:1450
void assign_player_colors(void)
Definition plrhand.c:1563
#define fc_rand(_size)
Definition rand.h:34
struct research * research_get(const struct player *pplayer)
Definition research.c:126
const char * pick_random_player_name(const struct nation_type *pnation)
Definition srv_main.c:2733
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2510
bool game_was_started(void)
Definition srv_main.c:339
Definition city.h:309
struct tile * tile
Definition city.h:311
enum barbarians_rate barbarianrate
Definition game.h:132
struct civ_game::@30::@34 server
int onsetbarbarian
Definition game.h:170
struct packet_game_info info
Definition game.h:89
enum ai_level skill_level
enum barbarian_type barbarian_type
Definition player.h:128
struct city_list * cities
Definition player.h:281
struct player_ai ai_common
Definition player.h:288
bool got_first_city
Definition player.h:320
char username[MAX_LEN_NAME]
Definition player.h:252
bool is_connected
Definition player.h:296
int revolution_finishes
Definition player.h:273
struct government * government
Definition player.h:258
struct player_economic economic
Definition player.h:284
bool phase_done
Definition player.h:263
struct player::@69::@71 server
bool unassigned_user
Definition player.h:253
Definition tile.h:49
struct unit_list * units
Definition tile.h:57
Definition unit.h:138
int id
Definition unit.h:145
struct civ_map map
#define sz_strlcpy(dest, src)
Definition support.h:167
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
void init_tech(struct research *research, bool update)
Definition techtools.c:1070
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:273
void give_initial_techs(struct research *presearch, int num_random_techs)
Definition techtools.c:1162
#define is_ocean_tile(ptile)
Definition terrain.h:289
#define terrain_has_flag(terr, flag)
Definition terrain.h:269
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:578
#define tile_terrain(_tile)
Definition tile.h:109
#define TILE_XY(ptile)
Definition tile.h:42
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
int get_transporter_capacity(const struct unit *punit)
Definition unit.c:299
#define unit_owner(_pu)
Definition unit.h:394
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:430
void unit_do_action(struct player *pplayer, const int actor_id, const int target_id, const int sub_tgt_id, const char *name, const action_id action_type)
Definition unithand.c:3155
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
#define unit_list_iterate_end
Definition unitlist.h:33
#define unit_list_iterate_safe_end
Definition unitlist.h:61
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2794
struct unit * create_unit_full(struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left, int hp_left, struct unit *ptrans)
Definition unittools.c:1642
struct unit * create_unit(struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left)
Definition unittools.c:1615
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2247
struct unit_type * find_a_unit_type(enum unit_role_id role, enum unit_role_id role_tech)
Definition unittools.c:174
bool unit_move(struct unit *punit, struct tile *pdesttile, int move_cost, struct unit *embark_to, bool find_embark_target, bool conquer_city_allowed, bool conquer_extras_allowed, bool enter_hut, bool frighten_hut)
Definition unittools.c:3884
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2301
int num_role_units(int role)
Definition unittype.c:2251
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1979
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1630
#define utype_class(_t_)
Definition unittype.h:736
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:604