Crossfire Client, Trunk
player.c File Reference
#include <stdint.h>
#include "client.h"
#include "external.h"
#include "script.h"
#include "mapdata.h"
+ Include dependency graph for player.c:

Go to the source code of this file.

Functions

void clear_fire ()
 
void clear_run ()
 
void client_send_apply (int tag)
 
void client_send_examine (int tag)
 
void client_send_move (int loc, int tag, int nrof)
 
void command_take (const char *command, const char *cpnext)
 
int command_to_direction (const char *dir)
 
void CompleteCmd (unsigned char *data, int len)
 
const char * dir_to_command (int dir)
 
void fire_dir (int dir)
 
void look_at (int x, int y)
 
void new_player (long tag, char *name, long weight, long face)
 
void predict_scroll (int dir)
 
void run_dir (int dir)
 
int send_command (const char *command, int repeat, int must_send)
 
static bool starts_with (const char *prefix, const char *str)
 
void stop_fire ()
 
void stop_run ()
 
void walk_dir (int dir)
 

Variables

static int dfire =-1
 
const char *const directions []
 
static int drun =-1
 
bool is_afk
 
time_t last_command_sent
 
bool profile_latency = false
 
int64_t * profile_time = NULL
 

Detailed Description

Handles various player related functions. This includes both things that operate on the player item, cpl structure, or various commands that the player issues.

Most of the handling of commands from the client to server (see commands.c for server->client) is handled here.

Most of the work for sending messages to the server is done here. Again, most of these appear self explanatory. Most send a bunch of commands like apply, examine, fire, run, etc. This looks like it was done by Mark to remove the old keypress stupidity I used.

Definition in file player.c.

Function Documentation

◆ clear_fire()

void clear_fire ( )

Definition at line 115 of file player.c.

References dfire, SC_FIRERUN, and send_command().

Referenced by focusoutfunc(), map_button_event(), and parse_key_release().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear_run()

void clear_run ( )

Definition at line 122 of file player.c.

References drun, SC_FIRERUN, and send_command().

Referenced by focusoutfunc(), and parse_key_release().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ client_send_apply()

void client_send_apply ( int  tag)

Definition at line 86 of file player.c.

References cs_print_string(), csocket, and ClientSocket::fd.

Referenced by list_item_action(), list_row_collapse(), ma_apply(), and script_process_cmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ client_send_examine()

void client_send_examine ( int  tag)

Definition at line 90 of file player.c.

References cs_print_string(), csocket, and ClientSocket::fd.

Referenced by list_item_action(), and ma_examine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ client_send_move()

void client_send_move ( int  loc,
int  tag,
int  nrof 
)

Request to move 'nrof' objects with 'tag' to 'loc'.

Definition at line 97 of file player.c.

References cs_print_string(), csocket, and ClientSocket::fd.

Referenced by list_item_drop(), and script_process_cmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ command_take()

void command_take ( const char *  command,
const char *  cpnext 
)

Definition at line 351 of file player.c.

References Player_Struct::container, Player_Struct::count, cpl, cs_print_string(), csocket, draw_ext_info(), ClientSocket::fd, item_struct::inv, MSG_TYPE_CLIENT, MSG_TYPE_CLIENT_NOTICE, NDI_BLACK, Player_Struct::ob, send_command(), and item_struct::tag.

Referenced by do_take().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ command_to_direction()

int command_to_direction ( const char *  dir)

Definition at line 164 of file player.c.

References directions.

Referenced by send_command().

+ Here is the caller graph for this function:

◆ CompleteCmd()

void CompleteCmd ( unsigned char *  data,
int  len 
)

◆ dir_to_command()

const char* dir_to_command ( int  dir)

Definition at line 173 of file player.c.

References directions.

Referenced by walk_dir().

+ Here is the caller graph for this function:

◆ fire_dir()

void fire_dir ( int  dir)

Definition at line 129 of file player.c.

References Player_Struct::count, cpl, dfire, Player_Struct::input_state, MAX_BUF, Playing, SC_NORMAL, and send_command().

Referenced by map_button_event(), and parse_key().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ look_at()

void look_at ( int  x,
int  y 
)

Definition at line 82 of file player.c.

References cs_print_string(), csocket, and ClientSocket::fd.

Referenced by map_button_event().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ new_player()

void new_player ( long  tag,
char *  name,
long  weight,
long  face 
)

Initialize player object using information from the server.

Definition at line 54 of file player.c.

References copy_name, cpl, item_struct::d_name, item_struct::face, is_afk, keybindings_init(), last_command_sent, Spell_struct::next, item_struct::nrof, Player_Struct::ob, Player_Struct::spelldata, item_struct::tag, and item_struct::weight.

Referenced by PlayerCmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ predict_scroll()

void predict_scroll ( int  dir)

Change map drawing offset to provide local movement prediction based on player's movement commands to the server.

Definition at line 185 of file player.c.

References want_offset_x, and want_offset_y.

Referenced by CompleteCmd(), and send_command().

+ Here is the caller graph for this function:

◆ run_dir()

void run_dir ( int  dir)

Definition at line 150 of file player.c.

References drun, MAX_BUF, SC_NORMAL, and send_command().

Referenced by parse_key(), and run_move_to().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ send_command()

◆ starts_with()

static bool starts_with ( const char *  prefix,
const char *  str 
)
static

Definition at line 222 of file player.c.

Referenced by send_command().

+ Here is the caller graph for this function:

◆ stop_fire()

void stop_fire ( )

Definition at line 108 of file player.c.

References cpl, dfire, Player_Struct::input_state, and Playing.

Referenced by keyfunc().

+ Here is the caller graph for this function:

◆ stop_run()

void stop_run ( )

Definition at line 145 of file player.c.

References drun, SC_FIRERUN, and send_command().

Referenced by keyfunc(), and run_move_to().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ walk_dir()

void walk_dir ( int  dir)

Definition at line 177 of file player.c.

References dir_to_command(), SC_MOVETO, and send_command().

Referenced by run_move_to().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ dfire

int dfire =-1
static

Definition at line 106 of file player.c.

Referenced by clear_fire(), fire_dir(), and stop_fire().

◆ directions

const char *const directions
Initial value:
= {"stay", "north", "northeast",
"east", "southeast", "south",
"southwest", "west", "northwest"}

256-length array to keep track of when commands were sent to the server Array for direction strings for each numeric direction.

Definition at line 41 of file player.c.

Referenced by command_to_direction(), dir_to_command(), and keybind_insert().

◆ drun

int drun =-1
static

Definition at line 106 of file player.c.

Referenced by clear_run(), CompleteCmd(), run_dir(), send_command(), and stop_run().

◆ is_afk

bool is_afk

Best guess whether or not we are currently AFK or not.

Definition at line 46 of file player.c.

Referenced by client_tick(), new_player(), on_auto_afk_response(), and send_command().

◆ last_command_sent

time_t last_command_sent

Time when last command was sent. Used to keep track of auto-AFK.

Definition at line 49 of file player.c.

Referenced by client_tick(), new_player(), and send_command().

◆ profile_latency

bool profile_latency = false

Definition at line 36 of file player.c.

Referenced by CompleteCmd(), and send_command().

◆ profile_time

int64_t* profile_time = NULL

Definition at line 37 of file player.c.

Referenced by CompleteCmd(), and send_command().