Freeciv21
Develop your civilization from humble roots to a global empire
barbarian.cpp File Reference
#include "fcintl.h"
#include "log.h"
#include "rand.h"
#include "support.h"
#include "effects.h"
#include "events.h"
#include "game.h"
#include "government.h"
#include "map.h"
#include "movement.h"
#include "nation.h"
#include "research.h"
#include "terrain.h"
#include "aiiface.h"
#include "citytools.h"
#include "maphand.h"
#include "notify.h"
#include "plrhand.h"
#include "srv_main.h"
#include "techtools.h"
#include "unithand.h"
#include "unittools.h"
#include "advdata.h"
#include "difficulty.h"
#include "barbarian.h"
+ Include dependency graph for barbarian.cpp:

Go to the source code of this file.

Macros

#define BARBARIAN_INITIAL_VISION_RADIUS   3
 Functions for creating barbarians in huts, land and sea Started by Jerzy Klek jekl@.nosp@m.alta.nosp@m.vista.nosp@m..net with more ideas from Falk Hueffner. More...
 
#define BARBARIAN_INITIAL_VISION_RADIUS_SQ   9
 

Functions

bool is_land_barbarian (struct player *pplayer)
 Is player a land barbarian? More...
 
bool is_sea_barbarian (struct player *pplayer)
 Is player a sea barbarian? More...
 
struct playercreate_barbarian_player (enum barbarian_type type)
 Creates the land/sea barbarian player and inits some stuff. More...
 
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. More...
 
static int random_unchecked_direction (int possibilities, const bool *checked)
 Return random directory from not yet checked ones. More...
 
bool unleash_barbarians (struct tile *ptile)
 Unleash barbarians means give barbarian player some units and move them out of the hut, unless there's no place to go. More...
 
static bool is_near_land (struct tile *tile0)
 Is sea not further than a couple of tiles away from land? More...
 
static struct tilefind_empty_tile_nearby (struct tile *ptile)
 Return this or a neighbouring tile that is free of any units. More...
 
static void try_summon_barbarians ()
 The barbarians are summoned at a randomly chosen place if: More...
 
void summon_barbarians ()
 Summon barbarians out of the blue. More...
 

Macro Definition Documentation

◆ BARBARIAN_INITIAL_VISION_RADIUS

#define BARBARIAN_INITIAL_VISION_RADIUS   3

Functions for creating barbarians in huts, land and sea Started by Jerzy Klek jekl@.nosp@m.alta.nosp@m.vista.nosp@m..net with more ideas from Falk Hueffner.

Definition at line 54 of file barbarian.cpp.

◆ BARBARIAN_INITIAL_VISION_RADIUS_SQ

#define BARBARIAN_INITIAL_VISION_RADIUS_SQ   9

Definition at line 55 of file barbarian.cpp.

Function Documentation

◆ create_barbarian_player()

struct player* create_barbarian_player ( enum barbarian_type  type)

Creates the land/sea barbarian player and inits some stuff.

If barbarian player already exists, return player pointer. If barbarians are dead, revive them with a new leader :-)

Dead barbarians forget the map and lose the money.

Definition at line 82 of file barbarian.cpp.

Referenced by kill_player(), try_summon_barbarians(), and unleash_barbarians().

◆ find_empty_tile_nearby()

static struct tile* find_empty_tile_nearby ( struct tile ptile)
static

Return this or a neighbouring tile that is free of any units.

Definition at line 477 of file barbarian.cpp.

Referenced by try_summon_barbarians().

◆ init_dir_checked_status()

static void init_dir_checked_status ( bool *  checked,
enum terrain_class *  terrainc,
enum terrain_class  tclass 
)
static

(Re)initialize direction checked status array based on terrain class.

Definition at line 203 of file barbarian.cpp.

Referenced by unleash_barbarians().

◆ is_land_barbarian()

bool is_land_barbarian ( struct player pplayer)

Is player a land barbarian?

Definition at line 60 of file barbarian.cpp.

Referenced by create_barbarian_player(), dai_military_findjob(), raze_city(), and try_summon_barbarians().

◆ is_near_land()

static bool is_near_land ( struct tile tile0)
static

Is sea not further than a couple of tiles away from land?

Definition at line 461 of file barbarian.cpp.

Referenced by try_summon_barbarians().

◆ is_sea_barbarian()

bool is_sea_barbarian ( struct player pplayer)

Is player a sea barbarian?

Definition at line 69 of file barbarian.cpp.

Referenced by create_barbarian_player().

◆ random_unchecked_direction()

static int random_unchecked_direction ( int  possibilities,
const bool *  checked 
)
static

Return random directory from not yet checked ones.

Definition at line 221 of file barbarian.cpp.

Referenced by unleash_barbarians().

◆ summon_barbarians()

void summon_barbarians ( )

Summon barbarians out of the blue.

Try more times for more difficult levels - which means there can be more than one uprising in one year!

Definition at line 710 of file barbarian.cpp.

Referenced by end_turn().

◆ try_summon_barbarians()

static void try_summon_barbarians ( )
static

The barbarians are summoned at a randomly chosen place if:

  1. It's not closer than MIN_UNREST_DIST and not further than MAX_UNREST_DIST from the nearest city. City owner is called 'victim' here.
  2. The place or a neighbouring tile must be empty to deploy the units.
  3. If it's the sea it shouldn't be far from the land. (questionable)
  4. Place must be known to the victim
  5. The uprising chance depends also on the victim empire size, its government (civil_war_chance) and barbarian difficulty level.
  6. The number of land units also depends slightly on victim's empire size and barbarian difficulty level. Q: The empire size is used so there are no uprisings in the beginning of the game (year is not good as it can be customized), but it seems a bit unjust if someone is always small. So maybe it should rather be an average number of cities (all cities/player num)? Depending on the victim government type is also questionable.

Definition at line 508 of file barbarian.cpp.

Referenced by summon_barbarians().

◆ unleash_barbarians()

bool unleash_barbarians ( struct tile ptile)

Unleash barbarians means give barbarian player some units and move them out of the hut, unless there's no place to go.

Barbarian unit deployment algorithm: If enough free land around, deploy on land, if not enough land but some sea free, load some of them on boats, otherwise (not much land and no sea) kill enemy unit and stay in a village. The return value indicates if the explorer survived entering the vilage.

Definition at line 248 of file barbarian.cpp.

Referenced by api_edit_unleash_barbarians().