Crossfire Server  1.75.0
cfanim.cpp File Reference
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "cfanim.h"
#include "svnversion.h"

Go to the source code of this file.

Data Structures

struct  param_moveto
 Destination for moveto command. More...
 
struct  teleport_params
 

Functions

static void animate (void)
 Animates all currently running animations. More...
 
static void animate_one (CFanimation *animation, long int milliseconds)
 Checks if an animation can execute one or more moves, and if so does them. More...
 
CF_PLUGIN int cfanim_globalEventListener (int *type,...)
 
CF_PLUGIN anim_move_result cfanim_runPluginCommand (object *op, char *params)
 
CF_PLUGIN int closePlugin (void)
 called before the plugin gets unloaded from memory. More...
 
static int compareAnims (const void *a, const void *b)
 
static CFanimationcreate_animation (void)
 Create a new animation. More...
 
static int equality_split (char *buffer, char **variable, char **value)
 This function take buffer with a value like "blabla= things" and extracts some things. More...
 
CF_PLUGIN int eventListener (int *type,...)
 Handles an object-related event. More...
 
static objectfind_by_name (object *origin, const char *name)
 
static int get_boolean (const char *strg, int *bl)
 This function gets a string containing [Y/y](es)/[N/n](o), 1/0 and set bl according to what's read if return value is true, strg was set successfully else, an error occured and bl was not touched. More...
 
static CFanimationHookget_command (char *command)
 
static int get_dir_from_name (const char *name)
 Returns the direction from its name. More...
 
CF_PLUGIN void * getPluginProperty (int *type,...)
 The server calls this function to get information about the plugin, notably the name and version. More...
 
static long int initapply (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initapplyobject (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initcamera (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initdropobject (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initfire (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initghosted (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initmessage (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initmovement (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initmoveto (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initnotice (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initpickup (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initpickupobject (const char *name, char *parameters, CFmovement *move_entity)
 
CF_PLUGIN int initPlugin (const char *iversion, f_plug_api gethooksptr)
 The server calls this function after loading the plugin. More...
 
static long int initsay (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initstop (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initteleport (const char *name, char *parameters, CFmovement *move_entity)
 
static long int inittrigger (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initturn (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initvisible (const char *name, char *parameters, CFmovement *move_entity)
 
static long int initwizard (const char *name, char *parameters, CFmovement *move_entity)
 
static int is_animated_object (const object *ob)
 Is specified object currently being animated? More...
 
static CFmovementparse_animation_block (char *buffer, size_t buffer_size, FILE *fichier, CFanimation *parent)
 Parse an animation block in the animation file. More...
 
CF_PLUGIN int postInitPlugin (void)
 The server calls this function to actually initialize the plugin here, after object handlers are registered. More...
 
static void prepare_commands (void)
 
static anim_move_result runapply (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runapplyobject (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runcamera (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result rundropobject (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runfire (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runghosted (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runmessage (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runmovement (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runmoveto (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runnotice (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runpickup (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runpickupobject (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runsay (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runstop (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runteleport (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runtrigger (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runturn (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runvisible (CFanimation *animation, long int id, void *parameters)
 
static anim_move_result runwizard (CFanimation *animation, long int id, void *parameters)
 
static int start_animation (object *who, object *activator, object *event, const char *file, const char *message)
 Create a new animation object according to file, option and activator (who) More...
 
long usec_elapsed (struct timespec first, struct timespec second)
 Return the number of microseconds between two timespec structures. More...
 

Variables

CFanimationHook animationbox []
 Available animation commands. More...
 
int animationcount = sizeof(animationbox)/sizeof(CFanimationHook)
 
static CFanimationfirst_animation = NULL
 Animations we're currently processing. More...
 
static int ordered_commands = 0
 
CF_PLUGIN char SvnRevPlugin [] = SVN_REV
 

Function Documentation

◆ animate()

◆ animate_one()

static void animate_one ( CFanimation animation,
long int  milliseconds 
)
static

◆ cfanim_globalEventListener()

CF_PLUGIN int cfanim_globalEventListener ( int *  type,
  ... 
)

Definition at line 1254 of file cfanim.cpp.

References animate(), and EVENT_CLOCK.

Referenced by postInitPlugin().

◆ cfanim_runPluginCommand()

CF_PLUGIN anim_move_result cfanim_runPluginCommand ( object op,
char *  params 
)

Definition at line 1239 of file cfanim.cpp.

References mr_finished.

◆ compareAnims()

static int compareAnims ( const void *  a,
const void *  b 
)
static

Definition at line 616 of file cfanim.cpp.

Referenced by get_command(), and prepare_commands().

◆ create_animation()

static CFanimation* create_animation ( void  )
static

Create a new animation.

Returns
new animation pointer inserted in the list of animations.

Definition at line 803 of file cfanim.cpp.

References CFanimation::delete_end, CFanimation::event, CFanimation::name, CFanimation::nextanimation, CFanimation::nextmovement, and CFanimation::victim.

Referenced by start_animation().

◆ equality_split()

static int equality_split ( char *  buffer,
char **  variable,
char **  value 
)
static

This function take buffer with a value like "blabla= things" and extracts some things.

Parameters
bufferwhere equality is written
[out]variablewill be positionned to where in buffer the variable name starts. leading spaces will be converted to \0
[out]valuesame as above but for the value part
Note
variable and value become pointers to internals of buffer. If buffer chages, they will change too and/or become invalid!

Definition at line 727 of file cfanim.cpp.

Referenced by start_animation().

◆ find_by_name()

static object* find_by_name ( object origin,
const char *  name 
)
static

◆ get_boolean()

static int get_boolean ( const char *  strg,
int *  bl 
)
static

This function gets a string containing [Y/y](es)/[N/n](o), 1/0 and set bl according to what's read if return value is true, strg was set successfully else, an error occured and bl was not touched.

Parameters
strgstring to process.
blvalue strg meant.
Returns
1 if strg was processed, 0 else.

Definition at line 758 of file cfanim.cpp.

Referenced by initghosted(), initvisible(), initwizard(), and start_animation().

◆ get_command()

static CFanimationHook* get_command ( char *  command)
static

Definition at line 625 of file cfanim.cpp.

References animationcount, compareAnims(), CFanimationHook::name, and prepare_commands().

Referenced by parse_animation_block().

◆ get_dir_from_name()

static int get_dir_from_name ( const char *  name)
static

Returns the direction from its name.

Parameters
namedirection's name
Returns
direction or -1 if unknown.

Definition at line 51 of file cfanim.cpp.

Referenced by initcamera(), initfire(), initmovement(), and initturn().

◆ initapply()

static long int initapply ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 215 of file cfanim.cpp.

◆ initapplyobject()

static long int initapplyobject ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 236 of file cfanim.cpp.

References cf_add_string(), and CFmovement::parameters.

◆ initcamera()

static long int initcamera ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 134 of file cfanim.cpp.

References get_dir_from_name(), and CFmovement::parameters.

◆ initdropobject()

static long int initdropobject ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 267 of file cfanim.cpp.

References cf_add_string(), and CFmovement::parameters.

◆ initfire()

static long int initfire ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 94 of file cfanim.cpp.

References get_dir_from_name(), and CFmovement::parameters.

◆ initghosted()

static long int initghosted ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 325 of file cfanim.cpp.

References cf_log(), get_boolean(), and llevError.

◆ initmessage()

static long int initmessage ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 496 of file cfanim.cpp.

References CFmovement::parameters.

◆ initmovement()

static long int initmovement ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 71 of file cfanim.cpp.

References get_dir_from_name(), and CFmovement::parameters.

◆ initmoveto()

static long int initmoveto ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 459 of file cfanim.cpp.

References CFmovement::parameters, param_moveto::x, and param_moveto::y.

◆ initnotice()

static long int initnotice ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 423 of file cfanim.cpp.

References cf_strdup_local(), and CFmovement::parameters.

◆ initpickup()

static long int initpickup ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 286 of file cfanim.cpp.

◆ initpickupobject()

static long int initpickupobject ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 305 of file cfanim.cpp.

References cf_add_string(), and CFmovement::parameters.

◆ initsay()

static long int initsay ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

◆ initstop()

static long int initstop ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 438 of file cfanim.cpp.

◆ initteleport()

static long int initteleport ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

◆ inittrigger()

static long int inittrigger ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 515 of file cfanim.cpp.

References cf_log(), llevError, and CFmovement::parameters.

◆ initturn()

static long int initturn ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 111 of file cfanim.cpp.

References get_dir_from_name(), and CFmovement::parameters.

◆ initvisible()

static long int initvisible ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 156 of file cfanim.cpp.

References cf_log(), get_boolean(), and llevError.

◆ initwizard()

static long int initwizard ( const char *  name,
char *  parameters,
CFmovement move_entity 
)
static

Definition at line 175 of file cfanim.cpp.

References cf_log(), get_boolean(), llevError, and mr_finished.

◆ is_animated_object()

static int is_animated_object ( const object ob)
static

Is specified object currently being animated?

Parameters
obobject to search for.
Returns
1 if ob is part of animation, 0 else.

Definition at line 789 of file cfanim.cpp.

References CFanimation::nextanimation, and CFanimation::victim.

Referenced by eventListener().

◆ parse_animation_block()

static CFmovement* parse_animation_block ( char *  buffer,
size_t  buffer_size,
FILE *  fichier,
CFanimation parent 
)
static

Parse an animation block in the animation file.

Parameters
bufferbuffer to read data info, will have been modified when function exits.
buffer_sizesize of buffer.
fichierfile to read from.
parentanimation we're reading the block for.
Returns
one animation frame.

Definition at line 642 of file cfanim.cpp.

References cf_log(), CFanimation::errors_allowed, CFmovement::func, CFanimationHook::funcinit, CFanimationHook::funcrun, get_command(), CFmovement::id, llevDebug, llevError, CFmovement::next, CFmovement::parent, CFmovement::tick, and CFanimation::verbose.

Referenced by start_animation().

◆ prepare_commands()

static void prepare_commands ( void  )
static

Definition at line 620 of file cfanim.cpp.

References animationcount, and compareAnims().

Referenced by get_command().

◆ runapply()

static anim_move_result runapply ( CFanimation animation,
long int  id,
void *  parameters 
)
static

◆ runapplyobject()

static anim_move_result runapplyobject ( CFanimation animation,
long int  id,
void *  parameters 
)
static

◆ runcamera()

static anim_move_result runcamera ( CFanimation animation,
long int  id,
void *  parameters 
)
static
Todo:
fix

Definition at line 144 of file cfanim.cpp.

References cf_log(), llevDebug, mr_finished, and CFanimation::verbose.

◆ rundropobject()

static anim_move_result rundropobject ( CFanimation animation,
long int  id,
void *  parameters 
)
static

◆ runfire()

static anim_move_result runfire ( CFanimation animation,
long int  id,
void *  parameters 
)
static
Todo:
fix

Definition at line 104 of file cfanim.cpp.

References cf_log(), llevDebug, mr_finished, and CFanimation::verbose.

◆ runghosted()

◆ runmessage()

static anim_move_result runmessage ( CFanimation animation,
long int  id,
void *  parameters 
)
static

◆ runmovement()

static anim_move_result runmovement ( CFanimation animation,
long int  id,
void *  parameters 
)
static

◆ runmoveto()

static anim_move_result runmoveto ( CFanimation animation,
long int  id,
void *  parameters 
)
static

◆ runnotice()

static anim_move_result runnotice ( CFanimation animation,
long int  id,
void *  parameters 
)
static

Definition at line 428 of file cfanim.cpp.

References cf_player_message(), mr_finished, NDI_NAVY, NDI_UNIQUE, and CFanimation::victim.

◆ runpickup()

static anim_move_result runpickup ( CFanimation animation,
long int  id,
void *  parameters 
)
static

Definition at line 293 of file cfanim.cpp.

References object::below, cf_object_pickup(), mr_finished, and CFanimation::victim.

◆ runpickupobject()

static anim_move_result runpickupobject ( CFanimation animation,
long int  id,
void *  parameters 
)
static

◆ runsay()

static anim_move_result runsay ( CFanimation animation,
long int  id,
void *  parameters 
)
static

Definition at line 205 of file cfanim.cpp.

References cf_log(), cf_object_say(), llevError, mr_finished, and CFanimation::victim.

◆ runstop()

static anim_move_result runstop ( CFanimation animation,
long int  id,
void *  parameters 
)
static
Todo:
fix

Definition at line 446 of file cfanim.cpp.

References cf_log(), llevDebug, mr_finished, and CFanimation::verbose.

◆ runteleport()

static anim_move_result runteleport ( CFanimation animation,
long int  id,
void *  parameters 
)
static

◆ runtrigger()

◆ runturn()

static anim_move_result runturn ( CFanimation animation,
long int  id,
void *  parameters 
)
static
Todo:
fix suspicious or missing call

Definition at line 120 of file cfanim.cpp.

References cf_log(), object::facing, llevDebug, mr_finished, CFanimation::verbose, and CFanimation::victim.

◆ runvisible()

static anim_move_result runvisible ( CFanimation animation,
long int  id,
void *  parameters 
)
static

Definition at line 167 of file cfanim.cpp.

References CFanimation::invisible, and mr_finished.

◆ runwizard()

static anim_move_result runwizard ( CFanimation animation,
long int  id,
void *  parameters 
)
static

Definition at line 186 of file cfanim.cpp.

References mr_finished, and CFanimation::wizard.

◆ start_animation()

static int start_animation ( object who,
object activator,
object event,
const char *  file,
const char *  message 
)
static

Create a new animation object according to file, option and activator (who)

Parameters
whoobject that raised the event leading to the plugin.
activatorobject that caused who to get an event.
eventactual event object linking who and this plugin. Can be removed.
filefile name to read from, should be accessible from the current path.
messageif non empty, will be the name of the used animation instead of the one specified in the file.
Returns
1 if the animation was created, 0 else.
Todo:
fix memory leaks in case of errors.

Definition at line 868 of file cfanim.cpp.

References cf_add_string(), cf_free_string(), cf_log(), cf_object_remove(), cf_strdup_local(), CFanimation::corpse, create_animation(), CFanimation::delete_end, object::env, equality_split(), CFanimation::errors_allowed, CFanimation::event, find_by_name(), get_boolean(), CFanimation::ghosted, HUGE_BUF, CFanimation::invisible, llevDebug, llevError, CFanimation::name, CFanimation::nextmovement, CFanimation::paralyze, parse_animation_block(), PLAYER, CFanimation::tick_left, CFanimation::time_representation, time_second, time_tick, object::type, CFanimation::unique, CFanimation::verbose, CFanimation::victim, and CFanimation::wizard.

Referenced by eventListener().

◆ usec_elapsed()

long usec_elapsed ( struct timespec  first,
struct timespec  second 
)

Return the number of microseconds between two timespec structures.

This function was copied from common/time.c since linking is too hard.

Definition at line 1149 of file cfanim.cpp.

Referenced by animate().

Variable Documentation

◆ animationbox

CFanimationHook animationbox[]

Available animation commands.

Definition at line 562 of file cfanim.cpp.

◆ animationcount

int animationcount = sizeof(animationbox)/sizeof(CFanimationHook)

Definition at line 612 of file cfanim.cpp.

Referenced by get_command(), and prepare_commands().

◆ first_animation

CFanimation* first_animation = NULL
static

Animations we're currently processing.

Definition at line 42 of file cfanim.cpp.

Referenced by animate().

◆ ordered_commands

int ordered_commands = 0
static

Definition at line 614 of file cfanim.cpp.

◆ SvnRevPlugin

CF_PLUGIN char SvnRevPlugin[] = SVN_REV

Definition at line 40 of file cfanim.cpp.