38 #include "svnversion.h" 52 if (!strcmp(name,
"north"))
54 if (!strcmp(name,
"north_east"))
56 if (!strcmp(name,
"east"))
58 if (!strcmp(name,
"south_east"))
60 if (!strcmp(name,
"south"))
62 if (!strcmp(name,
"south_west"))
64 if (!strcmp(name,
"west"))
66 if (!strcmp(name,
"north_west"))
81 object *op = animation->
victim;
121 object *op = animation->
victim;
163 cf_log(
llevError,
"CFAnim: Error in animation - possible values for 'invisible' are 'yes' and 'no'\n");
182 cf_log(
llevError,
"CFAnim: Error in animation - possible values for 'wizard' are 'yes' and 'no'\n");
201 cf_log(
llevDebug,
"CFAnim: init say: parameters: %s\n", parameters ? parameters :
"null");
211 cf_log(
llevError,
"CFAnim: Error in animation: nothing to say with say function\n");
223 object *current_container;
251 if (current->
name == parameters)
270 (
void *)
cf_add_string(static_cast<sstring>(parameters)) : NULL;
316 if (current->name == parameters) {
332 cf_log(
llevError,
"CFAnim: Error in animation: possible values for 'ghosted' are 'yes' and 'no'\n");
340 || (!
id && !animation->
ghosted))
348 corpse->
contr = NULL;
352 animation->
corpse = corpse;
385 mapname = strstr(parameters,
" ");
390 mapx = atoi(parameters);
393 assert(parameters != NULL);
395 mapname = strstr(parameters,
" ");
400 mapy = atoi(parameters);
402 if (mapname[0] ==
'\0')
464 if (sscanf(parameters,
"%d %d", &x, &y) != 2)
507 if (parameters && animation->
victim->
map) {
520 if (sscanf(parameters,
"%ld", &connection) != 1 || connection <= 0) {
546 if (olp->
value ==
id) {
572 {
"fire_north_east",
initfire, runfire },
574 {
"fire_south_east",
initfire, runfire },
575 {
"fire_south",
initfire, runfire },
576 {
"fire_south_west",
initfire, runfire },
578 {
"fire_north_west",
initfire, runfire },
580 {
"turn_north_east",
initturn, runturn },
582 {
"turn_south_east",
initturn, runturn },
583 {
"turn_south",
initturn, runturn },
584 {
"turn_south_west",
initturn, runturn },
586 {
"turn_north_west",
initturn, runturn },
588 {
"camera_north_east",
initcamera, runcamera },
590 {
"camera_south_east",
initcamera, runcamera },
592 {
"camera_south_west",
initcamera, runcamera },
594 {
"camera_north_west",
initcamera, runcamera },
622 ordered_commands = 1;
628 dummy.
name = command;
629 if (!ordered_commands)
654 while (fgets(buffer, buffer_size, fichier)) {
655 if (buffer[0] ==
'[')
657 if (buffer[0] ==
'#')
659 buffer[strlen(buffer)-strlen(
"\n")] =
'\0';
660 while (buffer[strlen(buffer)-1] ==
' ')
661 buffer[strlen(buffer)-1] =
'\0';
662 if (strlen(buffer) <= 0)
666 name = strstr(buffer,
" ");
678 parameters = strstr(name,
" ");
682 while (*parameters ==
' ')
684 if (*parameters ==
'\0')
693 if (!animationhook) {
706 next->
id = animationhook->
funcinit(name, parameters, next);
709 current->
next = next;
728 if (!strcmp(&buffer[strlen(buffer)-strlen(
"\n")],
"\n"))
729 buffer[strlen(buffer)-strlen(
"\n")] =
'\0';
730 *value = strstr(buffer,
"=");
736 while ((strlen(*variable) > 0) && ((*variable)[strlen(*variable)-1] ==
' '))
737 (*variable)[strlen(*variable)-1] =
'\0';
738 while ((strlen(*value) > 0) && ((*value)[strlen(*value)-1] ==
' '))
739 (*value)[strlen(*value)-1] =
'\0';
740 while (**value ==
' ')
742 if ((**variable ==
'\0') || (**value ==
'\0'))
769 else if (*strg ==
'n')
771 else if (*strg ==
'Y')
773 else if (*strg ==
'N')
775 else if (*strg ==
'1')
777 else if (*strg ==
'0')
792 for (current = first_animation; current; current = current->
nextanimation)
793 if (current->
victim == ob) {
819 first_animation = anim;
834 while (origin && !origin->
map)
835 origin = origin->
env;
837 if (!origin || !origin->
map)
845 for (x = 0; x < w; x++) {
846 for (y = 0; y < h; y++) {
848 if (ob->name == sname)
868 static int start_animation(
object *who,
object *activator,
object *event,
const char *file,
const char *message) {
872 object *victim = NULL;
874 int always_delete = 0;
881 int errors_allowed = 0;
883 const char *animationitem = NULL;
887 int errors_found = 0;
890 fichier = fopen(file,
"r");
891 if (fichier == NULL) {
895 while (fgets(buffer,
HUGE_BUF, fichier)) {
896 if (buffer[0] ==
'[')
898 if (buffer[0] ==
'#')
900 if (!strcmp(buffer,
"\n"))
909 if (strncmp(buffer,
"[Config]", 8)) {
910 cf_log(
llevError,
"CFAnim: Fatal error in %s: [Config] must be the first group defined.\n", file);
914 while (fgets(buffer,
HUGE_BUF, fichier)) {
915 if (buffer[0] ==
'[')
917 if (buffer[0] ==
'#')
919 if (!strcmp(buffer,
"\n"))
924 if (!strcmp(variable,
"name")) {
927 if (value[strlen(value)-1] ==
'"')
928 value[strlen(value)-1] =
'\0';
930 }
else if (!strcmp(variable,
"victimtype")) {
931 if (!strcmp(value,
"player"))
933 else if (!strcmp(value,
"object"))
935 else if (!strcmp(value,
"any"))
937 else if (!strcmp(value,
"byname"))
941 }
else if (!strcmp(variable,
"victim")) {
943 if (!strcmp(value,
"who"))
945 else if (!strcmp(value,
"activator"))
947 else if (!strcmp(value,
"who_owner"))
950 cf_log(
llevError,
"CFAnim: Warning: object \"who\" doesn't exist and you're victimized it's owner\n");
953 else if (!strcmp(value,
"activator_owner"))
956 cf_log(
llevError,
"CFAnim: Warning: object \"activator\" doesn't exist and you're victimized it's owner\n");
958 victim = activator->
env;
959 else if (victimtype == 3) {
963 }
else if (!strcmp(variable,
"unique")) {
966 }
else if (!strcmp(variable,
"always_delete")) {
969 }
else if (!strcmp(variable,
"delete_event_end")) {
972 }
else if (!strcmp(variable,
"parallel")) {
975 }
else if (!strcmp(variable,
"paralyzed")) {
978 }
else if (!strcmp(variable,
"invisible")) {
981 }
else if (!strcmp(variable,
"wizard")) {
984 }
else if (!strcmp(variable,
"errors_allowed")) {
987 }
else if (!strcmp(variable,
"verbose")) {
990 }
else if (!strcmp(variable,
"time_representation")) {
991 if (!strcmp(value,
"second"))
993 else if (!strcmp(value,
"tick"))
997 }
else if (!strcmp(variable,
"animation")) {
1004 if (message && message[0] !=
'\0') {
1009 if (buffer[0] ==
'\0') {
1012 cf_log(
llevError,
"CFAnim: Errors occurred during the parsing of %s\n", file);
1016 if (!animationitem) {
1017 cf_log(
llevError,
"CFAnim: no animation specified when using %s\n", file);
1035 if (always_delete) {
1040 if (((victim->
type ==
PLAYER) && (victimtype == 1))
1041 || ((victim->
type !=
PLAYER) && (victimtype == 0))
1042 || (errors_found && !errors_allowed)) {
1044 cf_log(
llevError,
"CFAnim: No correct victim found or errors found, aborting.\n");
1051 if (unique && !always_delete) {
1056 current_anim->
name = name;
1057 current_anim->
victim = victim;
1058 current_anim->
event = event;
1059 current_anim->
paralyze = paralyzed;
1061 current_anim->
wizard = wizard;
1062 current_anim->
unique = unique;
1065 current_anim->
corpse = NULL;
1067 current_anim->
verbose = verbose;
1071 while (buffer[0] ==
'[') {
1072 while (strncmp(&buffer[1], animationitem, strlen(animationitem))) {
1073 while ((value = fgets(buffer,
HUGE_BUF, fichier)) != NULL)
1074 if (buffer[0] ==
'[')
1076 if (value == NULL) {
1077 cf_log(
llevError,
"CFAnim: no matching animation %s in file.\n", animationitem);
1150 time_t sec_elapsed = second.tv_sec - first.tv_sec;
1151 long nsec_elapsed = second.tv_nsec - first.tv_nsec;
1152 return (sec_elapsed * 1e6) + (nsec_elapsed / 1e3);
1162 struct timespec now;
1163 static struct timespec yesterday;
1164 static int already_passed = 0;
1165 long int delta_milli;
1167 clock_gettime(CLOCK_MONOTONIC, &now);
1168 if (!already_passed) {
1176 for (current = first_animation; current; current = current->
nextanimation)
1184 if (first_animation == current)
1185 first_animation = next;
1191 free(current->
name);
1195 previous_anim = current;
1214 const char *propname;
1218 va_start(args, type);
1219 propname = va_arg(args,
const char *);
1221 if (!strcmp(propname,
"Identification")) {
1222 buf = va_arg(args,
char *);
1223 size = va_arg(args,
int);
1227 }
else if (!strcmp(propname,
"FullName")) {
1228 buf = va_arg(args,
char *);
1229 size = va_arg(args,
int);
1259 va_start(args, type);
1260 event_code = va_arg(args,
int);
1275 object *who, *activator, *event;
1278 va_start(args, type);
1280 who = va_arg(args,
object *);
1281 activator = va_arg(args,
object *);
1282 va_arg(args,
object *);
1283 buf = va_arg(args,
char *);
1286 snprintf(message,
sizeof(message),
"%s", buf);
1291 query = va_arg(args,
int);
1292 event = va_arg(args,
object *);
1294 if (query == 1 && strcmp(message,
"query_object_is_animated") == 0) {
1305 if (activator != NULL) {
1307 }
else if (who != NULL) {
static anim_move_result runapplyobject(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)
void cf_object_free_drop_inventory(object *ob)
Wrapper for object_free_drop_inventory().
void cf_map_message(mapstruct *m, const char *msg, int color)
Partial wrapper for ext_info_map().
static int compareAnims(const void *a, const void *b)
static anim_move_result runfire(CFanimation *animation, long int id, void *parameters)
CFAnimInitFunc funcinit
Function to process the parameters of the move.
static long int initsay(const char *name, char *parameters, CFmovement *move_entity)
static int get_dir_from_name(const char *name)
Returns the direction from its name.
void cf_free_string(sstring str)
Wrapper for free_string().
CF_PLUGIN char SvnRevPlugin[]
static object * find_by_name(object *origin, const char *name)
oblinkpt * next
Next value in the list.
void cf_object_set_flag(object *ob, int flag, int value)
int tick
Move duration, units depending on parent's time_representation.
static long int initapplyobject(const char *name, char *parameters, CFmovement *move_entity)
static anim_move_result runpickup(CFanimation *animation, long int id, void *parameters)
static long int initpickupobject(const char *name, char *parameters, CFmovement *move_entity)
object * below
Pointer to the object stacked below this one.
static anim_move_result runapply(CFanimation *animation, long int id, void *parameters)
#define HUGE_BUF
Used for messages - some can be quite long.
long int id
Identifier, used for various things.
CFanimationHook animationbox[]
Available animation commands.
sstring slaying
Which race to do double damage to.
static anim_move_result runpickupobject(CFanimation *animation, long int id, void *parameters)
static anim_move_result runnotice(CFanimation *animation, long int id, void *parameters)
int cf_map_get_height(mapstruct *map)
static long int initnotice(const char *name, char *parameters, CFmovement *move_entity)
CFAnimRunFunc funcrun
Function to run the move.
int16_t y
Position in the map for this object.
void cf_object_apply_below(object *pl)
Wrapper for apply_by_living_below().
void cf_object_update(object *op, int flags)
int cf_player_move(player *pl, int dir)
static anim_move_result rundropobject(CFanimation *animation, long int id, void *parameters)
static anim_move_result runstop(CFanimation *animation, long int id, void *parameters)
CF_PLUGIN int initPlugin(const char *iversion, f_plug_api gethooksptr)
The server calls this function after loading the plugin.
CFanimation * nextanimation
sstring cf_add_string(const char *str)
Wrapper for add_string().
#define AP_APPLY
Item is to be applied.
struct player * contr
Pointer to the player which control this object.
oblinkpt * buttons
Linked list of linked lists of buttons.
long value
Used as connected value in buttons/gates.
#define FOR_OB_AND_BELOW_FINISH()
Finishes FOR_OB_AND_BELOW_PREPARE().
CF_PLUGIN int postInitPlugin(void)
The server calls this function to actually initialize the plugin here, after object handlers are regi...
Used to link together several object links.
void cf_log(LogLevel logLevel, const char *format,...)
Wrapper for LOG().
static anim_move_result runturn(CFanimation *animation, long int id, void *parameters)
static anim_move_result runmessage(CFanimation *animation, long int id, void *parameters)
void cf_object_say(object *op, const char *msg)
static CFmovement * parse_animation_block(char *buffer, size_t buffer_size, FILE *fichier, CFanimation *parent)
Parse an animation block in the animation file.
char * cf_strdup_local(const char *str)
Wrapper for strdup_local().
CF_PLUGIN int eventListener(int *type,...)
Handles an object-related event.
static void prepare_commands(void)
static void animate(void)
Animates all currently running animations.
int cf_init_plugin(f_plug_api getHooks)
static anim_move_result runcamera(CFanimation *animation, long int id, void *parameters)
object * cf_object_find_by_name(const object *who, const char *name)
Wrapper for object_find_by_name().
float speed
Frequency of object 'moves' relative to server tick rate.
static anim_move_result runvisible(CFanimation *animation, long int id, void *parameters)
CF_PLUGIN int closePlugin(void)
called before the plugin gets unloaded from memory.
object * cf_object_clone(object *op, int clonetype)
Clone an object.
object * env
Pointer to the object which is the environment.
mapstruct * cf_map_get_map(const char *name, int flags)
Wrapper for ready_map_name().
CF_PLUGIN anim_move_result cfanim_runPluginCommand(object *op, char *params)
One move in an animation.
#define EVENT_CLOCK
Global time event.
static int ordered_commands
sstring cf_find_string(const char *str)
void * parameters
Parameters to the function.
#define NDI_GREEN
SeaGreen.
static long int initwizard(const char *name, char *parameters, CFmovement *move_entity)
void cf_player_message(object *op, const char *txt, int flags)
void cf_system_register_global_event(int event, const char *name, f_plug_event hook)
Used to link together several objects.
static anim_move_result runsay(CFanimation *animation, long int id, void *parameters)
int teleport(object *teleporter, uint8_t tele_type, object *user)
Teleport an item around a nearby random teleporter of specified type.
anim_move_result
Result of one animation move.
static long int initcamera(const char *name, char *parameters, CFmovement *move_entity)
static long int initteleport(const char *name, char *parameters, CFmovement *move_entity)
objectlink * link
Items for this value.
CF_PLUGIN int cfanim_globalEventListener(int *type,...)
static anim_move_result runmovement(CFanimation *animation, long int id, void *parameters)
char * cf_get_maps_directory(const char *name, char *buf, int size)
Wrapper for create_pathname().
static long int initapply(const char *name, char *parameters, CFmovement *move_entity)
CFAnimRunFunc func
Function to run for this move.
#define FLAG_WIZ
Object has special privilegies.
#define MAX_BUF
Used for all kinds of things.
static void animate_one(CFanimation *animation, long int milliseconds)
Checks if an animation can execute one or more moves, and if so does them.
int16_t invisible
How much longer the object will be invis.
CFmovement * next
Next move in the animation.
float speed_left
How much speed is left to spend this round.
void cf_object_remove(object *op)
Wrapper for object_remove().
struct mapstruct * map
Pointer to the map in which this object is present.
static long int initturn(const char *name, char *parameters, CFmovement *move_entity)
void cf_map_trigger_connected(objectlink *ol, object *cause, int state)
Wrapper for trigger_connected().
long usec_elapsed(struct timespec first, struct timespec second)
Return the number of microseconds between two timespec structures.
static anim_move_result runmoveto(CFanimation *animation, long int id, void *parameters)
static long int initfire(const char *name, char *parameters, CFmovement *move_entity)
int cf_object_apply(object *op, object *author, int flags)
Wrapper for apply_manual().
#define FOR_MAP_FINISH()
Finishes FOR_MAP_PREPARE().
int8_t facing
Object is oriented/facing that way.
struct CFanimation * parent
Animation this move is linked to.
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...
CFmovement * nextmovement
static anim_move_result runteleport(CFanimation *animation, long int id, void *parameters)
static long int initvisible(const char *name, char *parameters, CFmovement *move_entity)
object * container
Current container being used.
#define UP_OBJ_CHANGE
Object changed.
CF_PLUGIN void * getPluginProperty(int *type,...)
The server calls this function to get information about the plugin, notably the name and version...
int cf_object_move(object *op, int dir, object *originator)
Destination for moveto command.
#define FLAG_WIZCAST
The wizard can cast spells in no-magic area.
sstring name
The name of the object, obviously...
Only for debugging purposes.
static long int inittrigger(const char *name, char *parameters, CFmovement *move_entity)
#define CFAPI_MAP_PROP_PATH
static anim_move_result runtrigger(CFanimation *animation, long int id, void *parameters)
#define CLEAR_FLAG(xyz, p)
uint8_t type
PLAYER, BULLET, etc.
static anim_move_result runghosted(CFanimation *animation, long int id, void *parameters)
int cf_object_pickup(object *op, object *what)
void cf_object_drop(object *op, object *author)
static long int initpickup(const char *name, char *parameters, CFmovement *move_entity)
static long int initmoveto(const char *name, char *parameters, CFmovement *move_entity)
sstring cf_map_get_sstring_property(mapstruct *map, int propcode)
static long int initmovement(const char *name, char *parameters, CFmovement *move_entity)
static CFanimation * create_animation(void)
Create a new animation.
static CFanimationHook * get_command(char *command)
#define FOR_OB_AND_BELOW_PREPARE(op_)
Constructs a loop iterating over an object and all objects below it in the same pile.
static long int initstop(const char *name, char *parameters, CFmovement *move_entity)
const char * name
Name as it appears in the animation file.
#define NDI_UNIQUE
Print immediately, don't buffer.
Move should continue next time.
int cf_object_teleport(object *ob, mapstruct *map, int x, int y)
enum time_enum time_representation
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Constructs a loop iterating over all objects of a map tile.
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 CFanimation * first_animation
Animations we're currently processing.
#define FOR_BELOW_PREPARE(op_, it_)
Constructs a loop iterating over all objects below an object.
static int is_animated_object(const object *ob)
Is specified object currently being animated?
static int equality_split(char *buffer, char **variable, char **value)
This function take buffer with a value like "blabla= things" and extracts some things.
static long int initdropobject(const char *name, char *parameters, CFmovement *move_entity)
static anim_move_result runwizard(CFanimation *animation, long int id, void *parameters)
#define FLAG_WIZPASS
The wizard can go through walls.
object * cf_map_insert_object_there(object *op, mapstruct *m, object *originator, int flag)
Wrapper for object_insert_in_map().
Available animation move.
int cf_map_get_width(mapstruct *map)
int cf_object_move_to(object *op, int x, int y)
Wrapper for move_to().
time_enum
Time units the animation can use.
#define FOR_BELOW_FINISH()
Finishes FOR_BELOW_PREPARE().
void(* f_plug_api)(int *type,...)
General API function.