Atrinik Server  4.0
Functions | Variables
player.c File Reference
#include <global.h>
#include <loader.h>
#include <toolkit/string.h>
#include <plugin.h>
#include <monster_data.h>
#include <arch.h>
#include <ban.h>
#include <player.h>
#include <object.h>
#include <exp.h>
#include <object_methods.h>
#include <disease.h>
#include <container.h>
#include <server.h>
#include <toolkit/path.h>

Go to the source code of this file.

Functions

static int save_life (object *op)
 
static void remove_unpaid_objects (object *op, object *env)
 
void player_init (void)
 
void player_deinit (void)
 
void player_disconnect_all (void)
 
playerfind_player (const char *plname)
 
playerfind_player_sh (shstr *plname)
 
void display_motd (object *op)
 
static playerget_player (player *p)
 
void free_player (player *pl)
 
void give_initial_items (object *pl, treasure_list_t *items)
 
int handle_newcs_player (player *pl)
 
static int get_regen_amount (uint16_t regen, uint16_t *regen_remainder)
 
static uint16_t get_regen_value (double speed, double rate)
 
static void player_do_some_living (object *op)
 
static void player_death_deplete_stats (object *op)
 
void kill_player (object *op)
 
void cast_dust (object *op, object *throw_ob, int dir)
 
int pvp_area (object *attacker, object *victim)
 
objectfind_skill (object *op, int skillnr)
 
int player_can_carry (object *pl, uint32_t weight)
 
void player_path_add (player *pl, mapstruct *map, int16_t x, int16_t y)
 
void player_path_clear (player *pl)
 
void player_path_handle (player *pl)
 
player_faction_tplayer_faction_create (player *pl, shstr *name)
 
void player_faction_free (player *pl, player_faction_t *faction)
 
player_faction_tplayer_faction_find (player *pl, shstr *name)
 
void player_faction_update (player *pl, shstr *name, double reputation)
 
double player_faction_reputation (player *pl, shstr *name)
 
char * player_sanitize_input (char *str)
 
void player_cleanup_name (char *str)
 
static objectfind_marked_object_rec (object *op, object **marked, uint32_t *marked_count)
 
objectfind_marked_object (object *op)
 
static void examine_living (object *op, object *tmp, StringBuffer *sb_capture)
 
void examine (object *op, object *tmp, StringBuffer *sb_capture)
 
int sack_can_hold (object *pl, object *sack, object *op, int nrof)
 
static objectget_pickup_object (object *pl, object *op, int nrof)
 
static void pick_up_object (object *pl, object *op, object *tmp, int nrof, int no_mevent)
 
void pick_up (object *op, object *alt, int no_mevent)
 
void put_object_in_sack (object *op, object *sack, object *tmp, long nrof)
 
void drop_object (object *op, object *tmp, long nrof, int no_mevent)
 
void drop (object *op, object *tmp, int no_mevent)
 
char * player_make_path (const char *name, const char *ext)
 
int player_exists (const char *name)
 
void player_save (object *op)
 
static void player_load (player *pl, FILE *fp)
 
static void player_create (player *pl, archetype_t *at, const char *name)
 
objectplayer_get_dummy (const char *name, const char *host)
 
objectplayer_find_spell (object *op, spell_struct *spell)
 
void player_set_talking_to (player *pl, object *npc)
 
const char * player_get_killer (player *pl)
 
void player_set_killer (player *pl, const char *killer)
 
void player_clear_killer (player *pl)
 
void player_login (socket_struct *ns, const char *name, struct archetype *at)
 
void player_logout (player *pl)
 
static void player_item_power_effects (object *op)
 
static void remove_map_func (object *op)
 
static void process_func (object *op)
 
 OBJECT_TYPE_INIT_DEFINE (player)
 

Variables

mempool_struct * pool_player
 

Detailed Description

Player related functions.

Definition in file player.c.

Function Documentation

void cast_dust ( object op,
object throw_ob,
int  dir 
)

Handles object throwing objects of type "DUST".

Todo:
This function needs to be rewritten. Works for area effect spells only now.
Parameters
opObject throwing.
throw_obWhat to throw.
dirDirection to throw into.

Definition at line 918 of file player.c.

void display_motd ( object op)

Grab the Message of the Day from a file.

First motd_custom is tried, and if that doesn't exist, motd is used instead.

Parameters
opPlayer object to print the message to.

Definition at line 136 of file player.c.

void drop ( object op,
object tmp,
int  no_mevent 
)

Drop an item, either on the floor or in a container.

Parameters
opWho is dropping an item.
tmpWhat object to drop.
no_meventIf 1, no drop map-wide event will be triggered.

Definition at line 2304 of file player.c.

void drop_object ( object op,
object tmp,
long  nrof,
int  no_mevent 
)

Drop an object onto the floor.

Parameters
opPlayer object.
tmpThe object to drop.
nrofNumber of items to drop (0 for all).
no_meventIf 1, no map-wide event will be triggered.

Definition at line 2195 of file player.c.

void examine ( object op,
object tmp,
StringBuffer *  sb_capture 
)

Player examines some object.

Parameters
opPlayer.
tmpObject to examine.

Definition at line 1521 of file player.c.

static void examine_living ( object op,
object tmp,
StringBuffer *  sb_capture 
)
static

Player examines a living object.

Parameters
opPlayer.
tmpObject being examined.

Definition at line 1410 of file player.c.

object* find_marked_object ( object op)

Return the object the player has marked.

Parameters
opObject. Should be a player.
Returns
Marked object if still valid, NULL otherwise.

Definition at line 1393 of file player.c.

static object* find_marked_object_rec ( object op,
object **  marked,
uint32_t *  marked_count 
)
static

Recursive helper function for find_marked_object() to search for marked object in containers.

Parameters
opObject. Should be a player.
markedMarked object.
marked_countMarked count.
Returns
The object if found, NULL otherwise.

Definition at line 1349 of file player.c.

player* find_player ( const char *  plname)

Loop through the player list and find player specified by plname.

Parameters
plnameThe player name to find.
Returns
Player structure if found, NULL otherwise.

Definition at line 96 of file player.c.

player* find_player_sh ( shstr *  plname)

Loop through the player list and find player specified by plname.

Parameters
plnameThe player name to find. Must be a shared string.
Returns
Player structure if found, NULL otherwise.

Definition at line 116 of file player.c.

object* find_skill ( object op,
int  skillnr 
)

Looks for the skill and returns a pointer to it if found.

Parameters
opThe object to look for the skill in.
skillnrSkill ID.
Returns
The skill if found, NULL otherwise.

Definition at line 1013 of file player.c.

void free_player ( player pl)

Free a player structure. Takes care of removing this player from the list of players, and frees the socket for this player.

Parameters
plThe player structure to free.

Definition at line 219 of file player.c.

static player* get_player ( player p)
static

Returns the player structure. If 'p' is null, we create a new one. Otherwise, we recycle the one that is passed.

Parameters
pPlayer structure to recycle or NULL for new structure.
Returns
The player structure.

Definition at line 180 of file player.c.

static int get_regen_amount ( uint16_t  regen,
uint16_t *  regen_remainder 
)
inlinestatic

Figures out how much hp/mana points to regenerate.

Parameters
regenRegeneration value used for client (for example, player::gen_client_hp).
regen_remainderPointer to regen remainder (for example, player::gen_hp_remainder).
Returns
How much to regenerate.

Definition at line 486 of file player.c.

static uint16_t get_regen_value ( double  speed,
double  rate 
)
inlinestatic

Calculate HP/SP regeneration value.

Parameters
speedRegeneration speed.
rateRegeneration rate.
Returns
Calculated regeneration value.

Definition at line 527 of file player.c.

void give_initial_items ( object pl,
treasure_list_t items 
)

Give initial items to object pl. This is used when player creates a new character.

Parameters
plThe player object.
itemsTreasure list of items to give.

Definition at line 292 of file player.c.

int handle_newcs_player ( player pl)

This is similar to handle_player(), but is only used by the new client/server stuff.

This is sort of special, in that the new client/server actually uses the new speed values for commands.

Parameters
plPlayer to handle.
Return values
-1Player is invalid.
0No more actions to do.
1There are more actions we can do.

Definition at line 347 of file player.c.

void kill_player ( object op)

If the player should die (lack of hp, food, etc), we call this.

Will remove diseases, apply death penalties, and so on.

Parameters
opThe player in jeopardy.

Definition at line 765 of file player.c.

OBJECT_TYPE_INIT_DEFINE ( player  )

Initialize the player type object methods.

Definition at line 3211 of file player.c.

void pick_up ( object op,
object alt,
int  no_mevent 
)

Try to pick up an item.

Parameters
opObject trying to pick up.
altOptional object op is trying to pick. If NULL, try to pick first item under op.
no_meventIf 1, no map-wide pickup event will be triggered.

Definition at line 2019 of file player.c.

static void pick_up_object ( object pl,
object op,
object tmp,
int  nrof,
int  no_mevent 
)
static

Pick up object.

Parameters
plObject that is picking up the object.
opObject to put tmp into.
tmpObject to pick up.
nrofNumber to pick up (0 means all of them).
no_meventIf 1, no map-wide pickup event will be triggered.

Definition at line 1966 of file player.c.

int player_can_carry ( object pl,
uint32_t  weight 
)

Check whether player can carry the specified weight.

Parameters
plPlayer.
weightWeight to check.
Returns
1 if the player can carry that weight, 0 otherwise.

Definition at line 1036 of file player.c.

void player_cleanup_name ( char *  str)

Cleans up a string that is, presumably, a player name.

Parameters
strThe player name to clean up.

Definition at line 1330 of file player.c.

void player_clear_killer ( player pl)

Clear the specified player's killer, if any.

Parameters
plPlayer.

Definition at line 2715 of file player.c.

static void player_create ( player pl,
archetype_t at,
const char *  name 
)
static

Create a new player character.

Parameters
plPlayer.
atCharacter's archetype.
nameName of the player character.

Definition at line 2551 of file player.c.

static void player_death_deplete_stats ( object op)
static

Deplete player's stats due to dying.

Parameters
opPlayer.

Definition at line 693 of file player.c.

void player_deinit ( void  )

Deinitialize the player API.

Definition at line 68 of file player.c.

void player_disconnect_all ( void  )

Disconnect all currently connected players.

Definition at line 79 of file player.c.

static void player_do_some_living ( object op)
static

Regenerate player's hp/mana, decrease food, etc.

We will only regenerate HP and mana if the player has some food in their stomach.

Parameters
opPlayer.

Definition at line 545 of file player.c.

player_faction_t* player_faction_create ( player pl,
shstr *  name 
)

Creates a new ::player_faction_t structure and adds it to the specified player.

Parameters
plPlayer.
nameName of the faction to create a structure for.
Returns
New ::player_faction_t structure.

Definition at line 1202 of file player.c.

player_faction_t* player_faction_find ( player pl,
shstr *  name 
)

Find the specified faction name in the player's factions hash table.

Parameters
plPlayer.
nameName of the faction to find.
Returns
::player_faction_t if found, NULL otherwise.

Definition at line 1243 of file player.c.

void player_faction_free ( player pl,
player_faction_t faction 
)

Frees the specified ::player_faction_t structure, removing it from the player's hash table of factions.

Parameters
plPlayer.
faction::player_faction_t to free.

Definition at line 1223 of file player.c.

double player_faction_reputation ( player pl,
shstr *  name 
)

Get player's reputation with a particular faction.

Parameters
plPlayer.
nameName of the faction.
Returns
Player's reputation with the specified faction.

Definition at line 1287 of file player.c.

void player_faction_update ( player pl,
shstr *  name,
double  reputation 
)

Update the player's reputation with a particular faction.

Parameters
plPlayer.
nameName of the faction to update.
reputationReputation to add/subtract.

Definition at line 1263 of file player.c.

object* player_get_dummy ( const char *  name,
const char *  host 
)

Creates a dummy player structure and returns a pointer to the player's object.

Parameters
nameName of the player to create.
hostIP address of the player.
Returns
Created player object, never NULL. Will abort() in case of failure.

Definition at line 2583 of file player.c.

const char* player_get_killer ( player pl)

Acquire the name of the player's killer, if any.

Parameters
plPlayer.
Returns
Name of the killer, NULL if none.

Definition at line 2676 of file player.c.

void player_init ( void  )

Initialize the player API.

Definition at line 58 of file player.c.

static void player_item_power_effects ( object op)
static

Handle negative effects caused by equipping items with an item power sum higher than player's maximum item power.

Parameters
opPlayer.

Definition at line 2939 of file player.c.

static void player_load ( player pl,
FILE *  fp 
)
static

Loads player data from the specified file into the player.

Parameters
plPlayer.
pathPath to load the data from.

Definition at line 2478 of file player.c.

void player_login ( socket_struct ns,
const char *  name,
struct archetype at 
)

Perform player login.

Parameters
nsClient that wants to log in.
nameCharacter name to log in to.
atCharacter archetype. Will be used to perform new character creation if this is the first time the player is logging in to this character.

Definition at line 2738 of file player.c.

void player_logout ( player pl)

Remove a player from the game that has been disconnected by logging out, the socket connection was interrupted, etc.

Parameters
plThe player to remove.

Definition at line 2895 of file player.c.

void player_path_add ( player pl,
mapstruct map,
int16_t  x,
int16_t  y 
)

Add a new path to player's paths queue.

Parameters
plPlayer to add the path for.
mapMap we want to reach.
xX we want to reach.
yY we want to reach.

Definition at line 1061 of file player.c.

void player_path_clear ( player pl)

Clear all queued paths.

Parameters
plPlayer to clear paths for.

Definition at line 1086 of file player.c.

void player_path_handle ( player pl)

Handle player moving along pre-calculated path.

Parameters
plPlayer.

Definition at line 1109 of file player.c.

char* player_sanitize_input ( char *  str)

Sanitize player's text input, removing extraneous whitespace, unprintable characters, etc.

Parameters
strInput to sanitize.
Returns
Sanitized input; can be NULL if there's nothing in the string left.

Definition at line 1311 of file player.c.

void player_save ( object op)

Saves the specified player.

Parameters
opPlayer object to save.

Definition at line 2379 of file player.c.

void player_set_killer ( player pl,
const char *  killer 
)

Store the name of the player's killer.

Parameters
plPlayer.
killerName of the killer to store. Will be copied.

Definition at line 2696 of file player.c.

void player_set_talking_to ( player pl,
object npc 
)

Updates who the player is talking to.

Parameters
plPlayer.
npcNPC the player is now talking to.

Definition at line 2647 of file player.c.

static void process_func ( object op)
static

Processes an object, giving it the opportunity to move or react.

Parameters
opThe object to process.

Definition at line 3103 of file player.c.

void put_object_in_sack ( object op,
object sack,
object tmp,
long  nrof 
)

Player tries to put object into sack, if nrof is non zero, then nrof objects is tried to put into sack.

Parameters
opPlayer object.
sackThe sack.
tmpThe object to put into sack.
nrofNumber of items to put into sack (0 for all).

Definition at line 2122 of file player.c.

int pvp_area ( object attacker,
object victim 
)

Test for PVP area.

If only one object is given, it tests for that. Otherwise if two objects are given, both objects must be in PVP area.

Considers parties.

Parameters
attackerFirst object.
victimSecond object.
Returns
1 if PVP is possible, 0 otherwise.

Definition at line 977 of file player.c.

static void remove_map_func ( object op)
static

Called when an object is removed from map.

Parameters
opThe object being removed.

Definition at line 3069 of file player.c.

static void remove_unpaid_objects ( object op,
object env 
)
static

This goes through the inventory and removes unpaid objects, and puts them back in the map (location and map determined by values of env). This function will descend into containers.

Parameters
opObject to start the search from.
envMap location determined by this object.

Definition at line 452 of file player.c.

int sack_can_hold ( object pl,
object sack,
object op,
int  nrof 
)

Check if an item op can be put into a sack. If pl exists then tell a player the reason of failure.

Parameters
plPlayer object.
sackThe sack.
opThe object to check.
nrofNumber of objects we want to put in.
Returns
1 if the object will fit, 0 if it will not.

Definition at line 1870 of file player.c.

static int save_life ( object op)
static

Can the player be saved by an item?

Parameters
opPlayer to try to save.
Return values
1Player had his life saved by an item, first item saving life is removed.
0Player had no life-saving item.

Definition at line 391 of file player.c.

Variable Documentation

mempool_struct* pool_player

Player memory pool.

Definition at line 52 of file player.c.