Atrinik Server  4.0
Data Structures | Typedefs | Functions | Variables
faction.c File Reference
#include <global.h>
#include <faction.h>
#include <toolkit/string.h>
#include <player.h>
#include <object.h>

Go to the source code of this file.

Data Structures

struct  faction_parent
 
struct  faction_enemy
 
struct  faction
 

Typedefs

typedef struct faction_parent faction_parent_t
 
typedef struct faction_enemy faction_enemy_t
 

Functions

static faction_t faction_create (const char *name, faction_t parent)
 
static void faction_free (faction_t faction)
 
static void faction_add_parent (faction_t faction, shstr *name)
 
static void faction_assign_names (void)
 
 TOOLKIT_API (DEPENDS(shstr))
 
 TOOLKIT_INIT_FUNC (faction)
 
TOOLKIT_INIT_FUNC_FINISH TOOLKIT_DEINIT_FUNC (faction)
 
faction_t faction_find (shstr *name)
 
static void faction_add_parent (faction_t faction, const char *name)
 
static void _faction_update (faction_t faction, player *pl, double reputation, bool override_spill)
 
void faction_update (faction_t faction, player *pl, double reputation)
 
void faction_update_kill (faction_t faction, player *pl)
 
static bool _faction_is_friend (faction_t faction, object *op, bool check_enemies, double attention)
 
bool faction_is_friend (faction_t faction, object *op)
 
static faction_t faction_get_alliance (faction_t faction)
 
bool faction_is_alliance (faction_t faction, faction_t faction2)
 
static double _faction_get_bounty (faction_t faction, player *pl)
 
double faction_get_bounty (faction_t faction, player *pl)
 
static void _faction_clear_bounty (faction_t faction, player *pl)
 
void faction_clear_bounty (faction_t faction, player *pl)
 

Variables

static faction_t factions
 

Detailed Description

Handles faction related code.

Author
Alex Tokar

Definition in file faction.c.

Typedef Documentation

Faction enemy structure. Holds information about a faction enemy.

Faction parent structure. Holds information about the parent faction, data like spill percentage, etc.

Function Documentation

static void _faction_clear_bounty ( faction_t  faction,
player pl 
)
static

Helper function for faction_clear_bounty().

Parameters
factionFaction.
plPlayer.

Definition at line 756 of file faction.c.

static double _faction_get_bounty ( faction_t  faction,
player pl 
)
static

Helper function for faction_get_bounty().

Parameters
factionFaction.
plPlayer.
Returns
Bounty.

Definition at line 693 of file faction.c.

static bool _faction_is_friend ( faction_t  faction,
object op,
bool  check_enemies,
double  attention 
)
static

Checks whether the specified object is a friend of the specified faction.

Parameters
factionFaction.
opObject to check.
check_enemiesIf true, check faction's enemies as well.
attentionParent's attention value.
Returns
Whether the object is a friend of the faction.

Definition at line 550 of file faction.c.

static void _faction_update ( faction_t  faction,
player pl,
double  reputation,
bool  override_spill 
)
static

Updates player's reputation with the specified faction and all its parents.

Parameters
factionFaction.
plPlayer.
reputationReputation value to add.
override_spillIf true, spill value of parents will not be considered.

Definition at line 472 of file faction.c.

static void faction_add_parent ( faction_t  faction,
const char *  name 
)
static

Add a parent to the specified faction.

Parameters
factionFaction.
nameName of the parent.

Definition at line 400 of file faction.c.

static void faction_assign_names ( void  )
static

Assign pointers to faction parents and enemies.

Definition at line 419 of file faction.c.

void faction_clear_bounty ( faction_t  faction,
player pl 
)

Clear player's bounty for the specified faction.

If the faction is part of an alliance, the bounty will be cleared in the entire alliance.

Parameters
factionFaction.
plPlayer.

Definition at line 790 of file faction.c.

static TOOLKIT_DEINIT_FUNC_FINISH faction_t faction_create ( const char *  name,
faction_t  parent 
)
static

Create a new faction with the specified name, adding it to the factions hash table.

Warning
Make sure this is NEVER called with duplicate names.
Parameters
nameName of the faction.
parentFaction's parent. May be NULL.
Returns
The created faction.

Definition at line 324 of file faction.c.

faction_t faction_find ( shstr *  name)

Find a faction in the factions hash table, identified by its name.

Parameters
nameName to find.
Returns
Faction if found, NULL otherwise.

Definition at line 382 of file faction.c.

static void faction_free ( faction_t  faction)
static

Frees data associated with the specified faction structure, removing it from the factions hash table.

Parameters
factionFaction to free.

Definition at line 351 of file faction.c.

static faction_t faction_get_alliance ( faction_t  faction)
static

Acquire the first faction alliance, recursively iterating its primary parents.

Parameters
factionFaction.
Returns
Faction with the alliance flag. Can be NULL.

Definition at line 636 of file faction.c.

double faction_get_bounty ( faction_t  faction,
player pl 
)

Acquire player's bounty for the specified faction.

If the faction is part of an alliance, the entire alliance will be checked instead.

Parameters
factionFaction.
plPlayer.
Returns
Bounty.

Definition at line 734 of file faction.c.

bool faction_is_alliance ( faction_t  faction,
faction_t  faction2 
)

Checks whether the two specified factions are in an alliance.

In order to be in an alliance, the first parent with an alliance flag must be the same for both factions.

Parameters
factionFirst faction.
faction2Second faction.
Returns
True if the two factions are in an alliance, false otherwise.

Definition at line 663 of file faction.c.

bool faction_is_friend ( faction_t  faction,
object op 
)

Checks whether the specified object is a friend of the given faction.

Parameters
factionFaction.
opObject to check.
Returns
Whether the object is a friend of the faction.

Definition at line 618 of file faction.c.

void faction_update ( faction_t  faction,
player pl,
double  reputation 
)

Update player's reputation with the specified faction.

Parameters
factionFaction.
plPlayer.
reputationReputation value to add.

Definition at line 509 of file faction.c.

void faction_update_kill ( faction_t  faction,
player pl 
)

Update player's reputation with the specified faction, triggered by killing a member of the faction.

Parameters
factionFaction.
plPlayer.

Definition at line 527 of file faction.c.

Variable Documentation

faction_t factions
static

Hashtable of the factions.

Definition at line 132 of file faction.c.