Freeciv-3.3: /fast/freeciv/nightly/main/server/barbarian.c Source File

Freeciv-3.3

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