54 #define BARBARIAN_INITIAL_VISION_RADIUS 3
55 #define BARBARIAN_INITIAL_VISION_RADIUS_SQ 9
92 if (!old_barbs->is_alive) {
93 old_barbs->economic.gold = 0;
94 old_barbs->is_alive =
true;
100 old_barbs->name[0] =
'\0';
104 old_barbs->unassigned_user =
true;
112 old_barbs->economic.gold += 100;
127 if (type == LAND_BARBARIAN || type == SEA_BARBARIAN) {
131 nation =
pick_a_nation(
nullptr,
false,
false, LAND_AND_SEA_BARBARIAN);
132 if (nation !=
nullptr) {
133 type = LAND_AND_SEA_BARBARIAN;
137 if (nation ==
nullptr) {
158 barbarians->
server.got_first_city =
false;
175 if (pplayer != barbarians) {
184 qDebug(
"Created barbarian %s, player %d",
player_name(barbarians),
187 _(
"%s gain a leader by the name %s. Dangerous "
188 "times may lie ahead."),
204 enum terrain_class *terrainc,
205 enum terrain_class tclass)
209 for (dir = 0; dir < 8; dir++) {
210 if (terrainc[dir] == tclass) {
211 checked[dir] =
false;
226 int num =
fc_rand(possibilities);
227 for (i = 0; i <= num; i++) {
250 struct player *barbarians;
254 enum terrain_class terrainc[8];
255 struct tile *dir_tiles[8];
261 bool barbarian_stays =
false;
272 wipe_unit(punit, ULR_BARB_UNLEASH,
nullptr);
287 for (i = 0; i < unit_cnt; i++) {
295 struct unit *barb_unit;
297 barb_unit =
create_unit(barbarians, ptile, punittype, 0, 0, -1);
305 for (dir = 0; dir < 8; dir++) {
306 dir_tiles[dir] =
mapstep(&(
wld.
map), ptile, direction8(dir));
307 if (dir_tiles[dir] ==
nullptr) {
308 terrainc[dir] = terrain_class_invalid();
311 terrainc[dir] = TC_OCEAN;
314 terrainc[dir] = TC_LAND;
318 terrainc[dir] = terrain_class_invalid();
322 if (land_tiles >= 3) {
327 bool dest_found =
false;
333 for (checked_count = 0; !dest_found && checked_count < land_tiles;
342 log_debug(
"Moved barbarian unit from (%d, %d) to (%d, %d)",
347 checked[rdir] =
true;
351 barbarian_stays =
true;
358 if (ocean_tiles > 0) {
360 struct unit *boat =
nullptr;
366 for (checked_count = 0; boat ==
nullptr && checked_count < ocean_tiles;
375 create_unit(barbarians, dir_tiles[rdir], candidate, 0, 0, -1);
378 checked[rdir] =
true;
390 ACTION_TRANSPORT_EMBARK);
401 bool dest_found =
false;
407 for (checked_count = 0; !dest_found && checked_count < land_tiles;
421 checked[rdir] =
true;
425 barbarian_stays =
true;
432 barbarian_stays =
true;
436 if (barbarian_stays) {
441 wipe_unit(punit2, ULR_BARB_UNLEASH,
nullptr);
481 if (unit_list_size(tile1->units) == 0) {
510 struct tile *ptile, *utile;
514 struct player *barbarians, *victim;
516 int barb_count, really_created = 0;
517 bool hut_present =
false;
542 log_debug(
"Closest city (to %d,%d) is %s (at %d,%d) distance %d.",
559 if (
static_cast<int>(
fc_rand(30)) + 1
564 log_debug(
"Barbarians are willing to fight");
581 city_count = city_list_size(victim->
cities);
585 while (city_max <= city_count) {
599 for (i = 0; i < barb_count; i++) {
607 (void)
create_unit(barbarians, utile, punittype, 0, 0, -1);
614 (void)
create_unit(barbarians, utile, leader_type, 0, 0, -1);
648 ptrans =
create_unit(barbarians, utile, boat, 0, 0, -1);
654 for (i = 0; i < cap - 1 && i < barb_count; i++) {
679 if (really_created == 0) {
698 _(
"Native unrest near %s led by %s."),
city_link(pc),
702 _(
"Sea raiders seen near %s!"),
city_link(pc));
729 for (i = 0; i < n * (
game.
server.barbarianrate - 1); i++) {
bool is_action_enabled_unit_on_unit(const action_id wanted_action, const struct unit *actor_unit, const struct unit *target_unit)
Returns TRUE if actor_unit can do wanted_action to target_unit as far as action enablers are concerne...
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
Make and cache lots of calculations needed for other functions.
void adv_data_phase_done(struct player *pplayer)
Clean up our mess.
#define CALL_PLR_AI_FUNC(_func, _player,...)
const char * default_ai_type_name()
Return name of default ai type.
struct player * create_barbarian_player(enum barbarian_type type)
Creates the land/sea barbarian player and inits some stuff.
static struct tile * find_empty_tile_nearby(struct tile *ptile)
Return this or a neighbouring tile that is free of any units.
bool unleash_barbarians(struct tile *ptile)
Unleash barbarians means give barbarian player some units and move them out of the hut,...
static void try_summon_barbarians()
The barbarians are summoned at a randomly chosen place if:
#define BARBARIAN_INITIAL_VISION_RADIUS_SQ
static void init_dir_checked_status(bool *checked, enum terrain_class *terrainc, enum terrain_class tclass)
(Re)initialize direction checked status array based on terrain class.
bool is_sea_barbarian(struct player *pplayer)
Is player a sea barbarian?
void summon_barbarians()
Summon barbarians out of the blue.
static bool is_near_land(struct tile *tile0)
Is sea not further than a couple of tiles away from land?
bool is_land_barbarian(struct player *pplayer)
Is player a land barbarian?
static int random_unchecked_direction(int possibilities, const bool *checked)
Return random directory from not yet checked ones.
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
const char * city_name_get(const struct city *pcity)
Return the name of the city.
void set_ai_level_directer(struct player *pplayer, enum ai_level level)
Set an AI level and related quantities, with no feedback.
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Returns the effect bonus for a player.
const struct ft_color ftc_server
const char * city_link(const struct city *pcity)
Get a text link to a city.
#define fc_assert(condition)
#define log_debug(message,...)
struct tile * rand_map_pos(const struct civ_map *nmap)
Random square anywhere on the map.
int map_num_tiles()
Returns the total number of (real) positions (or tiles) on the map.
bool is_safe_ocean(const struct civ_map *nmap, const struct tile *ptile)
Return TRUE if this ocean terrain is adjacent to a safe coastline.
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Return real distance between two tiles.
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Step from the given tile in the given direction.
#define square_iterate(nmap, center_tile, radius, tile_itr)
#define square_iterate_end
#define whole_map_iterate(_map, _tile)
#define whole_map_iterate_end
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Return whether the player knows the tile.
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Returns whether the layer 'vlayer' of the tile 'ptile' is known and seen by the player 'pplayer'.
void map_show_circle(struct player *pplayer, struct tile *ptile, int radius_sq)
Shows the area to the player.
void update_tile_knowledge(struct tile *ptile)
Update playermap knowledge for everybody who sees the tile, and send a packet to everyone whose info ...
void map_clear_known(struct tile *ptile, struct player *pplayer)
Clear known status of the tile.
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
This tile is native to unit.
bool unit_can_move_to_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *dst_tile, bool igzoc, bool enter_enemy_city)
Returns whether the unit can move from its current tile to the destination tile.
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Return TRUE iff transporter type has ability to transport transported class.
struct government * init_government_of_nation(const struct nation_type *pnation)
Returns initial government type for this nation.
const char * nation_plural_for_player(const struct player *pplayer)
Return the (translated) plural noun of the given nation of a player.
struct nation_type * nation_of_player(const struct player *pplayer)
Return the nation of a player.
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Similar to notify_conn_packet (see also), but takes player as "destination".
int player_number(const struct player *pplayer)
Return the player index/number/id.
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Returns diplomatic state type between two players.
#define players_iterate_end
#define players_iterate(_pplayer)
void server_player_set_name(struct player *pplayer, const char *name)
Try to set the player name to 'name'.
void send_player_all_c(struct player *src, struct conn_list *dest)
Send all information about a player (player_info and all player_diplstates) to the given connections.
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Creates a new, uninitialized, used player slot.
void assign_player_colors()
Permanently assign colors to any players that don't already have them.
void player_status_reset(struct player *plr)
Reset player status to 'normal'.
struct nation_type * pick_a_nation(const struct nation_list *choices, bool ignore_conflicts, bool needs_startpos, enum barbarian_type barb_type)
This function returns a random-ish nation that is suitable for 'barb_type' and is usable (not already...
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Initialize ANY newly-created player on the server.
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Set nation for player with nation default values.
bool game_was_started()
Returns iff the game was started once upon a time.
const char * pick_random_player_name(const struct nation_type *pnation)
Returns a random ruler name picked from given nation's ruler names that is not already in use.
struct civ_game::@28::@32 server
struct packet_game_info info
enum barbarian_type barbarian_type
struct city_list * cities
struct player_ai ai_common
char username[MAX_LEN_NAME]
struct player::@65::@67 server
struct government * government
struct player_economic economic
#define sz_strlcpy(dest, src)
#define is_ocean_tile(ptile)
#define terrain_has_flag(terr, flag)
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Remove extra and adjust other extras accordingly.
#define tile_terrain(_tile)
#define tile_has_extra(ptile, pextra)
struct unit * is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non-allied unit on this tile?
int get_transporter_capacity(const struct unit *punit)
Return the number of units the transporter can hold (or 0).
bool unit_move_handling(struct unit *punit, struct tile *pdesttile, bool igzoc, bool move_do_not_act)
Will try to move to/attack the tile dest_x,dest_y.
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)
Handle unit action.
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_safe(unitlist, _unit)
#define unit_list_iterate_end
#define unit_list_iterate_safe_end
const char * utype_rule_name(const struct unit_type *punittype)
Return the (untranslated) rule name of the unit type.
int num_role_units(int role)
How many unit types have specified role/flag.
struct unit_type * get_role_unit(int role, int role_index)
Return index-th unit with specified role/flag.
static bool utype_has_flag(const struct unit_type *punittype, int flag)