version 1.44 | | version 1.45 |
---|
| | |
/* | | /* |
* static char *rcsid_plugins_c = | | * static char *rcsid_plugins_c = |
* "$Id: plugins.c,v 1.44 2005/10/07 17:54:48 akirschbaum Exp $"; | | * "$Id: plugins.c,v 1.45 2005/10/18 16:54:31 gros Exp $"; |
*/ | | */ |
| | |
/*****************************************************************************/ | | /*****************************************************************************/ |
| | |
#include <sproto.h> | | #include <sproto.h> |
#endif | | #endif |
| | |
#include <plugproto.h> | | #define NR_OF_HOOKS 70 |
CFPlugin PlugList[32]; | | |
int PlugNR = 0; | | |
| | |
/*****************************************************************************/ | | hook_entry plug_hooks[NR_OF_HOOKS] = |
/* Tries to find if a given command is handled by a plugin. */ | | |
/* Note that find_plugin_command is called *before* the internal commands are*/ | | |
/* checked, meaning that you can "overwrite" them. */ | | |
/*****************************************************************************/ | | |
CommArray_s *find_plugin_command(char *cmd, object *op) | | |
{ | | |
CFParm CmdParm; | | |
CFParm* RTNValue; | | |
int i; | | |
char cmdchar[10]; | | |
static CommArray_s RTNCmd; | | |
| | |
strcpy(cmdchar,"command?"); | | |
CmdParm.Value[0] = cmdchar; | | |
CmdParm.Value[1] = cmd; | | |
CmdParm.Value[2] = op; | | |
| | |
for(i=0;i<PlugNR;i++) | | |
{ | | |
RTNValue = (PlugList[i].propfunc(&CmdParm)); | | |
if (RTNValue!=NULL) | | |
{ | | |
RTNCmd.name = (char *)(RTNValue->Value[0]); | | |
RTNCmd.func = (CommFunc)(RTNValue->Value[1]); | | |
RTNCmd.time = *(double *)(RTNValue->Value[2]); | | |
LOG(llevDebug, "RTNCMD: name %s, time %f\n", RTNCmd.name, RTNCmd.time); | | |
return &RTNCmd; | | |
}; | | |
}; | | |
return NULL; | | |
}; | | |
| | |
/*****************************************************************************/ | | |
/* Displays a list of loaded plugins (keystrings and description) in the */ | | |
/* game log window. */ | | |
/*****************************************************************************/ | | |
void displayPluginsList(object *op) | | |
{ | | |
char buf[MAX_BUF]; | | |
int i; | | |
| | |
new_draw_info (NDI_UNIQUE, 0, op, "List of loaded plugins:"); | | |
new_draw_info (NDI_UNIQUE, 0, op, "-----------------------"); | | |
for (i=0;i<PlugNR;i++) | | |
{ | | { |
strcpy(buf, PlugList[i].id); | | {cfapi_system_add_string, 0, "cfapi_system_add_string"}, |
strcat(buf, ", "); | | {cfapi_system_register_global_event, 1, "cfapi_system_register_global_event"}, |
strcat(buf, PlugList[i].fullname); | | {cfapi_system_remove_string, 2, "cfapi_system_remove_string"}, |
new_draw_info (NDI_UNIQUE, 0, op, buf); | | {cfapi_system_unregister_global_event, 3, "cfapi_system_unregister_global_event"}, |
}; | | {cfapi_system_check_path, 4, "cfapi_system_check_path"}, |
| | {cfapi_system_re_cmp, 5, "cfapi_system_re_cmp"}, |
| | {cfapi_system_strdup_local, 6, "cfapi_system_strdup_local"}, |
| | {cfapi_system_directory, 7, "cfapi_system_directory"}, |
| | {cfapi_system_find_animation, 8, "cfapi_system_find_animation"}, |
| | {cfapi_object_clean_object, 9, "cfapi_object_clean_object"}, |
| | {cfapi_object_on_same_map, 10, "cfapi_object_on_same_map"}, |
| | {cfapi_object_get_key, 11, "cfapi_object_get_key"}, |
| | {cfapi_object_set_key, 12, "cfapi_object_set_key"}, |
| | {cfapi_object_get_property, 13, "cfapi_object_get_property"}, |
| | {cfapi_object_set_property, 14,"cfapi_object_set_property"}, |
| | {cfapi_object_apply, 15, "cfapi_object_apply"}, |
| | {cfapi_object_identify, 16, "cfapi_object_identify"}, |
| | {cfapi_object_describe, 17, "cfapi_object_describe"}, |
| | {cfapi_object_drain, 18, "cfapi_object_drain"}, |
| | {cfapi_object_fix, 19, "cfapi_object_fix"}, |
| | {cfapi_object_give_skill, 20, "cfapi_object_give_skill"}, |
| | {cfapi_object_transmute, 21, "cfapi_object_transmute"}, |
| | {cfapi_object_remove, 22, "cfapi_object_remove"}, |
| | {cfapi_object_delete, 23, "cfapi_object_delete"}, |
| | {cfapi_object_clone, 24, "cfapi_object_clone"}, |
| | {cfapi_object_find, 25, "cfapi_object_find"}, |
| | {cfapi_object_create, 26, "cfapi_object_create"}, |
| | {cfapi_object_insert, 27, "cfapi_object_insert"}, |
| | {cfapi_object_split, 28, "cfapi_object_split"}, |
| | {cfapi_object_merge, 29, "cfapi_object_merge"}, |
| | {cfapi_object_distance, 30, "cfapi_object_distance"}, |
| | {cfapi_object_update, 31, "cfapi_object_update"}, |
| | {cfapi_object_clear, 32, "cfapi_object_clear"}, |
| | {cfapi_object_reset, 33, "cfapi_object_reset"}, |
| | {cfapi_object_check_inventory, 34, "cfapi_object_check_inventory"}, |
| | {cfapi_object_spring_trap, 35, "cfapi_object_spring_trap"}, |
| | {cfapi_object_check_trigger, 36, "cfapi_object_check_trigger"}, |
| | {cfapi_object_query_cost, 37, "cfapi_object_query_cost"}, |
| | {cfapi_object_query_money, 38, "cfapi_object_query_money"}, |
| | {cfapi_object_cast, 39, "cfapi_object_cast"}, |
| | {cfapi_object_learn_spell, 40, "cfapi_object_learn_spell"}, |
| | {cfapi_object_forget_spell, 41, "cfapi_object_forget_spell"}, |
| | {cfapi_object_check_spell, 42, "cfapi_object_check_spell"}, |
| | {cfapi_object_pay_amount, 43, "cfapi_object_pay_amount"}, |
| | {cfapi_object_pay_item, 44, "cfapi_object_pay_item"}, |
| | {cfapi_object_transfer, 45, "cfapi_object_transfer"}, |
| | {cfapi_object_drop, 46, "cfapi_object_drop"}, |
| | {cfapi_object_take, 47, "cfapi_object_take"}, |
| | {cfapi_object_find_archetype_inside, 48, "cfapi_object_find_archetype_inside"}, |
| | {cfapi_object_say, 49, "cfapi_object_say"}, |
| | {cfapi_map_get_map, 50, "cfapi_map_get_map"}, |
| | {cfapi_map_has_been_loaded, 51, "cfapi_map_has_been_loaded"}, |
| | {cfapi_map_create_path, 52, "cfapi_map_create_path"}, |
| | {cfapi_map_get_map_property, 53, "cfapi_map_get_property"}, |
| | {cfapi_map_set_map_property, 54, "cfapi_map_set_property"}, |
| | {cfapi_map_out_of_map, 55, "cfapi_map_out_of_map"}, |
| | {cfapi_map_update_position, 56, "cfapi_map_update_position"}, |
| | {cfapi_map_delete_map, 57, "cfapi_map_delete_map"}, |
| | {cfapi_map_message, 58, "cfapi_map_message"}, |
| | {cfapi_map_get_object_at, 59, "cfapi_map_get_object_at"}, |
| | {cfapi_map_get_flags, 60, "cfapi_map_get_flags"}, |
| | {cfapi_map_present_arch_by_name,61, "cfapi_map_present_arch_by_name"}, |
| | {cfapi_player_find, 62, "cfapi_player_find"}, |
| | {cfapi_player_message, 63, "cfapi_player_message"}, |
| | {cfapi_player_send_inventory, 64, "cfapi_player_send_inventory"}, |
| | {cfapi_object_teleport, 65, "cfapi_object_teleport"}, |
| | {cfapi_object_speak, 66, "cfapi_object_speak"}, |
| | {cfapi_object_pickup, 67, "cfapi_object_pickup"}, |
| | {cfapi_object_move, 68, "cfapi_object_move"}, |
| | {cfapi_object_apply_below, 69, "cfapi_object_apply_below"} |
}; | | }; |
| | int plugin_number = 0; |
| | crossfire_plugin* plugins_list = NULL; |
| | |
/*****************************************************************************/ | | /*****************************************************************************/ |
/* Searches in the loaded plugins list for a plugin with a keyname of id. */ | | /* NEW PLUGIN STUFF STARTS HERE */ |
/* Returns the position of the plugin in the list if a matching one was found*/ | | |
/* or -1 if no correct plugin was detected. */ | | |
/*****************************************************************************/ | | /*****************************************************************************/ |
int findPlugin(const char* id) | | |
{ | | |
int i; | | |
for(i=0; i<PlugNR; i++) | | |
if(!strcmp(id,PlugList[i].id)) | | |
return i; | | |
return -1; | | |
}; | | |
| | |
static LIBPTRTYPE cf_dlopen(char *fname) | | |
{ | | |
#ifdef WIN32 | | #ifdef WIN32 |
return(LoadLibrary(fname)); | | static const char *plugins_dlerror() |
#else | | |
return(dlopen(fname, RTLD_NOW|RTLD_GLOBAL)); | | |
#endif | | |
} | | |
| | |
static const char *cf_dlerror(void) | | |
{ | | { |
#ifdef WIN32 | | |
static char buf[256]; | | static char buf[256]; |
DWORD err; | | DWORD err; |
char *p; | | char *p; |
| | |
err = GetLastError(); | | err = GetLastError(); |
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, buf, sizeof(buf), NULL) == 0) | | if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, buf, sizeof(buf), NULL) == 0) |
snprintf(buf, sizeof(buf), "error %lu", err); | | snprintf(buf, sizeof(buf), "error %lu", err); |
| | |
p = strchr(buf, '\0'); | | p = strchr(buf, '\0'); |
while(p > buf && (p[-1] == '\r' || p[-1] == '\n')) | | while(p > buf && (p[-1] == '\r' || p[-1] == '\n')) |
p--; | | p--; |
*p = '\0'; | | *p = '\0'; |
| | return buf; |
return(buf); | | |
#else | | |
return(dlerror()); | | |
#endif | | |
} | | } |
| | #endif /* WIN32 */ |
| | |
static void cf_dlclose(LIBPTRTYPE lib) | | int execute_event(object* op, int eventcode, object* activator, object* third, const char* message, int fix) |
{ | | { |
#ifdef WIN32 | | object *tmp, *next; |
FreeLibrary(lib); | | crossfire_plugin* plugin; |
#else | | int rv = 0; |
dlclose(lib); | | for (tmp = op->inv; tmp != NULL; tmp=next) |
#endif | | { |
| | next = tmp->below; |
| | if ((tmp->type == EVENT_CONNECTOR)&&(tmp->subtype==eventcode)) |
| | { |
| | LOG(llevDebug, "********** EVENT HANDLER **********\n"); |
| | LOG(llevDebug, " - Who am I :%s\n",op->name); |
| | if (activator != NULL) |
| | LOG(llevDebug, " - Activator :%s\n",activator->name); |
| | if (third != NULL) |
| | LOG(llevDebug, " - Other object :%s\n",third->name); |
| | LOG(llevDebug, " - Event code :%d\n",tmp->subtype); |
| | LOG(llevDebug, " - Event plugin :%s\n",tmp->title); |
| | LOG(llevDebug, " - Event hook :%s\n",tmp->slaying); |
| | LOG(llevDebug, " - Event options :%s\n",tmp->name); |
| | plugin = plugins_find_plugin(tmp->title); |
| | if (plugin != NULL) |
| | { |
| | int rvt=0; |
| | rv = *(int*)(plugin->eventfunc( |
| | &rvt,op,eventcode,activator,third,message,fix,tmp->slaying, tmp->name)); |
| | return rv; |
} | | } |
| | else |
static f_plugin cf_dlsym(LIBPTRTYPE lib, const char *name) | | |
{ | | { |
#ifdef WIN32 | | LOG(llevError, "The requested plugin doesn't exist: %s",tmp->title); |
return((f_plugin)GetProcAddress(lib, name)); | | return 0; |
#else | | } |
return((f_plugin)dlsym(lib, name)); | | } |
#endif | | } |
| | return rv; |
} | | } |
| | |
/*****************************************************************************/ | | int execute_global_event(int eventcode, ...) |
/* Plugins initialization. Browses the plugins directory and call */ | | |
/* initOnePlugin for each file found. */ | | |
/* Returns 0 if at least one plugin was successfully loaded, -1 if not */ | | |
/*****************************************************************************/ | | |
int initPlugins(void) | | |
{ | | { |
struct dirent *currentfile; | | va_list args; |
DIR *plugdir; | | object* op; |
size_t l; | | object* op2; |
char buf[MAX_BUF]; | | player* pl; |
char buf2[MAX_BUF]; | | char* buf; |
int result; | | int i, rt; |
| | crossfire_plugin* cp; |
LOG(llevInfo,"Initializing plugins\n"); | | if (plugins_list == NULL) |
strcpy(buf,LIBDIR); | | |
strcat(buf,"/plugins/"); | | |
LOG(llevInfo,"Plugins directory is %s\n",buf); | | |
| | |
plugdir = opendir(buf); | | |
if (plugdir == NULL) | | |
return -1; | | return -1; |
| | |
result = -1; | | va_start(args,eventcode); |
while((currentfile = readdir(plugdir)) != NULL) | | |
{ | | switch (eventcode) |
l = strlen(currentfile->d_name); | | |
if (l > strlen(PLUGIN_SUFFIX)) | | |
{ | | |
if (strcmp(currentfile->d_name+l-strlen(PLUGIN_SUFFIX), PLUGIN_SUFFIX) == 0) | | |
{ | | { |
strcpy(buf2,buf); | | case EVENT_BORN: |
strcat(buf2,currentfile->d_name); | | /*BORN: op*/ |
LOG(llevInfo," -> Loading plugin : %s\n",currentfile->d_name); | | op = va_arg(args, object*); |
if (initOnePlugin(buf2) == 0) | | for(cp=plugins_list; cp != NULL; cp=cp->next) |
| | { |
| | if (cp->gevent[eventcode]!=NULL) |
| | cp->gevent[eventcode](&rt,eventcode,op); |
| | } |
| | break; |
| | case EVENT_CLOCK: |
| | /*CLOCK: -*/ |
| | for(cp=plugins_list; cp != NULL; cp=cp->next) |
| | { |
| | if (cp->gevent[eventcode]!=NULL) |
| | cp->gevent[eventcode](&rt,eventcode,op); |
| | } |
| | break; |
| | case EVENT_CRASH: |
| | for(cp=plugins_list; cp != NULL; cp=cp->next) |
| | { |
| | if (cp->gevent[eventcode]!=NULL) |
| | cp->gevent[eventcode](&rt,eventcode,op); |
| | } |
| | break; |
| | case EVENT_PLAYER_DEATH: |
| | /*PLAYER_DEATH: op*/ |
| | op = va_arg(args, object*); |
| | for(cp=plugins_list; cp != NULL; cp=cp->next) |
| | { |
| | if (cp->gevent[eventcode]!=NULL) |
| | cp->gevent[eventcode](&rt,eventcode,op); |
| | } |
| | break; |
| | case EVENT_GKILL: |
| | /*GKILL: op, hitter*/ |
| | op = va_arg(args, object*); |
| | op2 = va_arg(args, object*); |
| | for(cp=plugins_list; cp != NULL; cp=cp->next) |
| | { |
| | if (cp->gevent[eventcode]!=NULL) |
| | cp->gevent[eventcode](&rt,eventcode,op,op2); |
| | } |
| | break; |
| | case EVENT_LOGIN: |
| | /*LOGIN: pl, pl->socket.host*/ |
| | pl = va_arg(args, player*); |
| | buf = va_arg(args, char*); |
| | for(cp=plugins_list; cp != NULL; cp=cp->next) |
| | { |
| | if (cp->gevent[eventcode]!=NULL) |
| | cp->gevent[eventcode](&rt,eventcode,pl,buf); |
| | } |
| | break; |
| | case EVENT_LOGOUT: |
| | /*LOGOUT: pl, pl->socket.host*/ |
| | pl = va_arg(args, player*); |
| | buf = va_arg(args, char*); |
| | for(cp=plugins_list; cp != NULL; cp=cp->next) |
| | { |
| | if (cp->gevent[eventcode]!=NULL) |
| | cp->gevent[eventcode](&rt,eventcode,pl,buf); |
| | } |
| | break; |
| | case EVENT_MAPENTER: |
| | /*MAPENTER: op*/ |
| | op = va_arg(args, object*); |
| | for(cp=plugins_list; cp != NULL; cp=cp->next) |
| | { |
| | if (cp->gevent[eventcode]!=NULL) |
| | cp->gevent[eventcode](&rt,eventcode,op); |
| | } |
| | break; |
| | case EVENT_MAPLEAVE: |
| | /*MAPLEAVE: op*/ |
| | op = va_arg(args, object*); |
| | for(cp=plugins_list; cp != NULL; cp=cp->next) |
| | { |
| | if (cp->gevent[eventcode]!=NULL) |
| | cp->gevent[eventcode](&rt,eventcode,op); |
| | } |
| | break; |
| | case EVENT_MAPRESET: |
| | /*MAPRESET: map->path*/ |
| | buf = va_arg(args, char*); |
| | for(cp=plugins_list; cp != NULL; cp=cp->next) |
| | { |
| | if (cp->gevent[eventcode]!=NULL) |
| | cp->gevent[eventcode](&rt,eventcode,buf); |
| | } |
| | break; |
| | case EVENT_REMOVE: |
| | /*REMOVE: op*/ |
| | op = va_arg(args, object*); |
| | for(cp=plugins_list; cp != NULL; cp=cp->next) |
| | { |
| | if (cp->gevent[eventcode]!=NULL) |
| | cp->gevent[eventcode](&rt,eventcode,op); |
| | } |
| | break; |
| | case EVENT_SHOUT: |
| | /*SHOUT: op, parms, priority*/ |
| | op = va_arg(args, object*); |
| | buf = va_arg(args, char*); |
| | i = va_arg(args, int); |
| | for(cp=plugins_list; cp != NULL; cp=cp->next) |
| | { |
| | if (cp->gevent[eventcode]!=NULL) |
| | cp->gevent[eventcode](&rt,eventcode,op,buf,i); |
| | } |
| | break; |
| | case EVENT_TELL: |
| | for(cp=plugins_list; cp != NULL; cp=cp->next) |
| | { |
| | if (cp->gevent[eventcode]!=NULL) |
| | cp->gevent[eventcode](&rt,eventcode,NULL); |
| | } |
| | break; |
| | case EVENT_MUZZLE: |
| | /*MUZZLE: op, parms*/ |
| | op = va_arg(args, object*); |
| | buf = va_arg(args, char*); |
| | for(cp=plugins_list; cp != NULL; cp=cp->next) |
| | { |
| | if (cp->gevent[eventcode]!=NULL) |
| | cp->gevent[eventcode](&rt,eventcode,op,buf); |
| | } |
| | break; |
| | case EVENT_KICK: |
| | /*KICK: op, parms*/ |
| | op = va_arg(args, object*); |
| | buf = va_arg(args, char*); |
| | for(cp=plugins_list; cp != NULL; cp=cp->next) |
{ | | { |
result = 0; | | if (cp->gevent[eventcode]!=NULL) |
} | | cp->gevent[eventcode](&rt,eventcode,op,buf); |
} | | } |
| | break; |
} | | } |
| | va_end(args); |
| | return 0; |
} | | } |
| | |
closedir(plugdir); | | int plugins_init_plugin(char* libfile) |
return result; | | |
} | | |
| | |
/*****************************************************************************/ | | |
/* Plugin initialization. Initializes a plugin known by its filename. */ | | |
/* The initialization process has several stages: */ | | |
/* - Loading of the DLL itself; */ | | |
/* - Basical plugin information request; */ | | |
/* - CF-Plugin specific initialization tasks (call to initPlugin()); */ | | |
/* - Hook bindings; */ | | |
/* Returns 0 if the plugin was successfully loaded, -1 if not */ | | |
/*****************************************************************************/ | | |
int initOnePlugin(char* pluginfile) | | |
{ | | { |
int i; | | |
int j; | | |
LIBPTRTYPE ptr; | | LIBPTRTYPE ptr; |
CFParm HookParm; | | f_plug_init initfunc; |
CFParm *InitParm; | | f_plug_api propfunc; |
| | f_plug_api eventfunc; |
if (PlugNR >= sizeof(PlugList)/sizeof(*PlugList)) | | f_plug_postinit postfunc; |
{ | | f_plug_postinit closefunc; |
LOG(llevError, "Error while trying to load %s: %s\n", pluginfile, "too many plugins"); | | int i; |
return -1; | | crossfire_plugin* cp; |
} | | crossfire_plugin* ccp; |
| | |
ptr = cf_dlopen(pluginfile); | | /* Open the plugin lib and load the required functions */ |
| | ptr = plugins_dlopen(libfile); |
if (ptr == NULL) | | if (ptr == NULL) |
{ | | { |
LOG(llevError, "Error while trying to load %s: %s\n", pluginfile, cf_dlerror()); | | LOG(llevError, "Error trying to load %s: %s\n", libfile, plugins_dlerror()); |
return -1; | | return -1; |
} | | } |
PlugList[PlugNR].libptr = ptr; | | initfunc = (f_plug_init) plugins_dlsym(ptr, "initPlugin"); |
PlugList[PlugNR].initfunc = cf_dlsym(ptr, "initPlugin"); | | if (initfunc == NULL) |
if (PlugList[PlugNR].initfunc==NULL) | | |
{ | | { |
LOG(llevError,"Plugin init error: %s\n", cf_dlerror()); | | LOG(llevError, "Plugin error while requesting %s.initPlugin: %s\n", |
cf_dlclose(ptr); | | libfile, plugins_dlerror()); |
| | plugins_dlclose(ptr); |
return -1; | | return -1; |
} | | } |
| | propfunc = (f_plug_api) plugins_dlsym(ptr, "getPluginProperty"); |
InitParm = PlugList[PlugNR].initfunc(NULL); | | if (propfunc == NULL) |
LOG(llevInfo,"Plugin name: %s, known as %s\n", | | |
(char *)(InitParm->Value[1]), | | |
(char *)(InitParm->Value[0]) | | |
); | | |
strcpy(PlugList[PlugNR].id,(char *)(InitParm->Value[0])); | | |
strcpy(PlugList[PlugNR].fullname,(char *)(InitParm->Value[1])); | | |
if (findPlugin(PlugList[PlugNR].id) >= 0) | | |
{ | | { |
LOG(llevError, "Error while trying to load %s: plugin %s already loaded\n", pluginfile, PlugList[PlugNR].id); | | LOG(llevError, "Plugin error while requesting %s.getPluginProperty: %s\n", |
cf_dlclose(ptr); | | libfile, plugins_dlerror()); |
| | plugins_dlclose(ptr); |
return -1; | | return -1; |
} | | } |
PlugList[PlugNR].hookfunc = cf_dlsym(ptr, "registerHook"); | | eventfunc = (f_plug_api) plugins_dlsym(ptr, "eventListener"); |
PlugList[PlugNR].eventfunc = cf_dlsym(ptr, "triggerEvent"); | | if (eventfunc == NULL) |
PlugList[PlugNR].pinitfunc = cf_dlsym(ptr, "postinitPlugin"); | | |
PlugList[PlugNR].propfunc = cf_dlsym(ptr, "getPluginProperty"); | | |
if (PlugList[PlugNR].hookfunc==NULL) | | |
{ | | { |
LOG(llevError, "registerHook error: %s\n", cf_dlerror()); | | LOG(llevError, "Plugin error while requesting %s.eventListener: %s\n", |
cf_dlclose(ptr); | | libfile, plugins_dlerror()); |
| | plugins_dlclose(ptr); |
return -1; | | return -1; |
} | | } |
if (PlugList[PlugNR].eventfunc==NULL) | | postfunc = (f_plug_postinit) plugins_dlsym(ptr, "postInitPlugin"); |
| | if (postfunc == NULL) |
{ | | { |
LOG(llevError,"triggerEvent error: %s\n", cf_dlerror()); | | LOG(llevError, "Plugin error while requesting %s.postInitPlugin: %s\n", |
cf_dlclose(ptr); | | libfile, plugins_dlerror()); |
| | plugins_dlclose(ptr); |
return -1; | | return -1; |
} | | } |
if (PlugList[PlugNR].pinitfunc==NULL) | | closefunc = (f_plug_postinit) plugins_dlsym(ptr, "closePlugin"); |
| | if (postfunc == NULL) |
{ | | { |
LOG(llevError,"postinitPlugin error: %s\n", cf_dlerror()); | | LOG(llevError, "Plugin error while requesting %s.closePlugin: %s\n", |
cf_dlclose(ptr); | | libfile, plugins_dlerror()); |
| | plugins_dlclose(ptr); |
return -1; | | return -1; |
} | | } |
if (PlugList[PlugNR].propfunc==NULL) | | if (postfunc == NULL) |
{ | | { |
LOG(llevError,"getPluginProperty error: %s\n", cf_dlerror()); | | LOG(llevError, "Plugin error while requesting %s.closePlugin: %s\n", |
cf_dlclose(ptr); | | libfile, plugins_dlerror()); |
| | plugins_dlclose(ptr); |
return -1; | | return -1; |
} | | } |
| | i = initfunc("2.0", cfapi_get_hooks); |
| | cp = malloc(sizeof(crossfire_plugin)); |
for(i=0;i<NR_EVENTS;i++) | | for(i=0;i<NR_EVENTS;i++) |
PlugList[PlugNR].gevent[i] = 0; | | cp->gevent[i]=NULL; |
| | cp->eventfunc = eventfunc; |
| | cp->propfunc = propfunc; |
| | cp->closefunc = closefunc; |
| | cp->libptr = ptr; |
| | strcpy(cp->id,propfunc(&i,"Identification")); |
| | strcpy(cp->fullname,propfunc(&i, "FullName")); |
| | cp->next = NULL; |
| | cp->prev = NULL; |
| | if (plugins_list == NULL) |
| | { |
| | plugins_list = cp; |
| | } |
| | else |
| | { |
| | for(ccp=plugins_list; ccp->next!=NULL; ccp=ccp->next); |
| | ccp->next = cp; |
| | cp->prev = ccp; |
| | } |
| | postfunc(); |
| | plugin_number++; |
| | return 0; |
| | } |
| | |
for(j=1; j<NR_OF_HOOKS;j++) | | void* cfapi_get_hooks(int* type, ...) |
{ | | { |
int tmp = j; | | va_list args; |
HookParm.Value[0] = &tmp; | | int request_type; |
HookParm.Value[1] = HookList[j]; | | char* buf; |
PlugList[PlugNR].hookfunc(&HookParm); | | int fid; |
} | | f_plug_api rv; |
PlugNR++; | | int i; |
PlugList[PlugNR-1].pinitfunc(NULL); | | *type = CFAPI_NONE; |
LOG(llevInfo,"[Done]\n"); | | |
| | |
return 0; | | va_start(args,type); |
| | request_type = va_arg(args, int); |
| | if (request_type == 0) /* By nr */ |
| | { |
| | fid = va_arg(args, int); |
| | if ((fid < 0)||(fid >= NR_OF_HOOKS)) |
| | { |
| | rv = NULL; |
| | *type = CFAPI_NONE; |
} | | } |
| | else |
/*****************************************************************************/ | | |
/* Removes one plugin from memory. The plugin is identified by its keyname. */ | | |
/* Returns 0 if the plugin was removed, -1 if not. */ | | |
/*****************************************************************************/ | | |
int removeOnePlugin(char *id) | | |
{ | | { |
int plid; | | rv = plug_hooks[fid].func; |
int j; | | *type = CFAPI_FUNC; |
plid = findPlugin(id); | | } |
if (plid<0) | | } |
return -1; | | else /* by name */ |
/* We unload the library... */ | | { |
cf_dlclose(PlugList[plid].libptr); | | buf = va_arg(args, char*); |
/* Then we copy the rest on the list back one position */ | | for(i=0; i<NR_OF_HOOKS; i++) |
PlugNR--; | | { |
for (j=plid+1;j<sizeof(PlugList)/sizeof(*PlugList);j++) | | if (!strcmp(buf, plug_hooks[i].fname)) |
{ | | { |
PlugList[j-1] = PlugList[j]; | | rv = plug_hooks[i].func; |
| | *type = CFAPI_FUNC; |
} | | } |
| | } |
return 0; | | } |
| | va_end(args); |
| | return rv; |
} | | } |
| | |
/*****************************************************************************/ | | int plugins_remove_plugin(char* id) |
/* Hook functions. Those are wrappers to crosslib functions, used by plugins.*/ | | |
/* Remember : NEVER call crosslib functions directly from a plugin if a hook */ | | |
/* exists. */ | | |
/*****************************************************************************/ | | |
| | |
/*****************************************************************************/ | | |
/* LOG wrapper */ | | |
/*****************************************************************************/ | | |
/* 0 - Level of logging; */ | | |
/* 1 - Message. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWLog(CFParm* PParm) | | |
{ | | { |
LOG(*(int *)(PParm->Value[0]),(char *)(PParm->Value[1])); | | crossfire_plugin* cp; |
return NULL; | | |
}; | | |
| | |
/*****************************************************************************/ | | if (plugins_list == NULL) |
/* new_info_map wrapper. */ | | return -1; |
/*****************************************************************************/ | | |
/* 0 - Color information; */ | | |
/* 1 - Map where the message should be heard; */ | | |
/* 2 - Message. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWNewInfoMap(CFParm* PParm) | | |
{ | | |
new_info_map(*(int *)(PParm->Value[0]), (struct mapdef *)(PParm->Value[1]), | | |
(char*)(PParm->Value[2])); | | |
return NULL; | | |
}; | | |
| | |
/*****************************************************************************/ | | for(cp=plugins_list; cp != NULL; cp=cp->next) |
/* spring_trap wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - Trap; */ | | |
/* 1 - Victim. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWSpringTrap(CFParm* PParm) | | |
{ | | { |
spring_trap((object *)(PParm->Value[0]),(object *)(PParm->Value[1])); | | if(!strcmp(id,cp->id)) |
return NULL; | | |
}; | | |
| | |
/* | | |
* type of firing express how the dir parameter was parsed | | |
* if type is FIRE_DIRECTIONAL, it is a value from 0 to 8 corresponding to a direction | | |
* if type is FIRE_POSITIONAL, the 16bits dir parameters is separated into 2 signed shorts | | |
* 8 lower bits : signed, relative x value from caster | | |
* 8 higher bits: signed, relative y value from caster | | |
* use the following macros defined in <define.h> with FIRE_POSITIONAL: | | |
* GET_X_FROM_DIR(dir) extract the x value | | |
* GET_Y_FROM_DIR(dir) extract they value | | |
* SET_DIR_FROM_XY(X,Y) get dir from x,y values | | |
*/ | | |
/*****************************************************************************/ | | |
/* cast_spell wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - op; */ | | |
/* 1 - caster; */ | | |
/* 2 - direction; */ | | |
/* 3 - spell object */ | | |
/* 4 - optional args; */ | | |
/*****************************************************************************/ | | |
CFParm* CFWCastSpell(CFParm* PParm) | | |
{ | | { |
static int val; | | crossfire_plugin* n; |
CFParm *CFP; | | crossfire_plugin* p; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | n = cp->next; |
val = cast_spell((object *)(PParm->Value[0]),(object *)(PParm->Value[1]), | | p = cp->prev; |
*(int*)(PParm->Value[2]), (object*)(PParm->Value[3]), | | plugins_dlclose(cp->libptr); |
(char *)(PParm->Value[4])); | | if (n != NULL) |
CFP->Value[0] = (void *)(&val); | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | |
/* command_rskill wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - player; */ | | |
/* 1 - parameters. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWCmdRSkill(CFParm* PParm) | | |
{ | | { |
static int val; | | if (p != NULL) |
CFParm *CFP; | | { |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | n->prev = p; |
val = command_rskill((object *)(PParm->Value[0]), | | p->next = n; |
(char *)(PParm->Value[1])); | | } |
CFP->Value[0] = (void *)(&val); | | else |
return CFP; | | { |
}; | | n->prev = NULL; |
| | plugins_list = n; |
| | } |
| | } |
| | else |
| | { |
| | if (p != NULL) |
| | p->next = NULL; |
| | else |
| | plugins_list = NULL; |
| | } |
| | free(cp); |
| | plugin_number --; |
| | return 0; |
| | } |
| | } |
| | return -1; |
| | } |
| | |
/*****************************************************************************/ | | crossfire_plugin* plugins_find_plugin(const char* id) |
/* become_follower wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - object to change; */ | | |
/* 1 - new god object. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWBecomeFollower(CFParm* PParm) | | |
{ | | { |
become_follower((object *)(PParm->Value[0]),(object *)(PParm->Value[1])); | | crossfire_plugin* cp; |
| | |
| | if (plugins_list == NULL) |
return NULL; | | return NULL; |
}; | | |
| | |
/*****************************************************************************/ | | for(cp=plugins_list; cp != NULL; cp=cp->next) |
/* pick_up wrapper. */ | | { |
/*****************************************************************************/ | | if(!strcmp(id,cp->id)) |
/* 0 - picker object; */ | | |
/* 1 - picked object. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWPickup(CFParm* PParm) | | |
{ | | { |
pick_up((object *)(PParm->Value[0]),(object *)(PParm->Value[1])); | | return cp; |
| | } |
| | } |
return NULL; | | return NULL; |
}; | | } |
| | |
/*****************************************************************************/ | | /*****************************************************************************/ |
/* pick_up wrapper. */ | | /* Displays a list of loaded plugins (keystrings and description) in the */ |
/*****************************************************************************/ | | /* game log window. */ |
/* 0 - map */ | | |
/* 1 - x position */ | | |
/* 2 - y position */ | | |
/*****************************************************************************/ | | /*****************************************************************************/ |
CFParm* CFWGetMapObject(CFParm* PParm) | | void plugins_display_list(object *op) |
{ | | { |
object* val; | | char buf[MAX_BUF]; |
CFParm *CFP; | | int i; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | crossfire_plugin* cp; |
val = get_map_ob( | | |
(mapstruct *)(PParm->Value[0]), | | |
*(int *)(PParm->Value[1]), | | |
*(int *)(PParm->Value[2]) | | |
); | | |
CFP->Value[0] = (void *)(val); | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | new_draw_info (NDI_UNIQUE, 0, op, "List of loaded plugins:"); |
/* esrv_send_item wrapper. */ | | new_draw_info (NDI_UNIQUE, 0, op, "-----------------------"); |
/*****************************************************************************/ | | |
/* 0 - Player object; */ | | |
/* 1 - Object to update. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWESRVSendItem(CFParm* PParm) | | |
{ | | |
esrv_send_item( | | |
(object *)(PParm->Value[0]), | | |
(object *)(PParm->Value[1]) | | |
); | | |
return(NULL); | | |
}; | | |
| | |
/*****************************************************************************/ | | if (plugins_list == NULL) |
/* find_player wrapper. */ | | return; |
/*****************************************************************************/ | | |
/* 0 - name of the player to find. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWFindPlayer(CFParm* PParm) | | |
{ | | |
player *pl; | | |
CFParm *CFP; | | |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | |
pl = find_player((char *)(PParm->Value[0])); | | |
CFP->Value[0] = (void *)(pl); | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | for(cp=plugins_list; cp != NULL; cp=cp->next) |
/* manual_apply wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - object applying; */ | | |
/* 1 - object to apply; */ | | |
/* 2 - apply flags. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWManualApply(CFParm* PParm) | | |
{ | | { |
CFParm *CFP; | | strcpy(buf, cp->id); |
static int val; | | strcat(buf, ", "); |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | strcat(buf, cp->fullname); |
val = manual_apply((object *)(PParm->Value[0]), | | new_draw_info (NDI_UNIQUE, 0, op, buf); |
(object *)(PParm->Value[1]),*(int *)(PParm->Value[2])); | | } |
CFP->Value[0] = &val; | | } |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | /* SYSTEM-RELATED HOOKS */ |
/* command_drop wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - player; */ | | |
/* 1 - parameters string. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWCmdDrop(CFParm* PParm) | | |
{ | | |
CFParm *CFP; | | |
static int val; | | |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | |
val = command_drop((object *)(PParm->Value[0]),(char *)(PParm->Value[1])); | | |
CFP->Value[0] = &val; | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | void* cfapi_system_find_animation(int *type, ...) |
/* command_take wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - player; */ | | |
/* 1 - parameters string. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWCmdTake(CFParm* PParm) | | |
{ | | { |
CFParm *CFP; | | va_list args; |
static int val; | | static int rv; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | char* anim; |
val = command_take((object *)(PParm->Value[0]),(char *)(PParm->Value[1])); | | va_start(args, type); |
CFP->Value[0] = &val; | | anim = va_arg(args, char*); |
return CFP; | | va_end(args); |
}; | | |
| | |
/*****************************************************************************/ | | rv = find_animation(anim); |
/* transfer_ob wrapper. */ | | *type = CFAPI_INT; |
/*****************************************************************************/ | | return &rv; |
/* 0 - object to transfer; */ | | } |
/* 1 - x position; */ | | |
/* 2 - y position; */ | | |
/* 3 - random param; */ | | |
/* 4 - originator object; */ | | |
/*****************************************************************************/ | | |
CFParm* CFWTransferObject(CFParm* PParm) | | |
{ | | |
CFParm *CFP; | | |
static int val; | | |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | |
val = transfer_ob( | | |
(object *)(PParm->Value[0]), | | |
*(int *)(PParm->Value[1]), | | |
*(int *)(PParm->Value[2]), | | |
*(int *)(PParm->Value[3]), | | |
(object *)(PParm->Value[4]) | | |
); | | |
CFP->Value[0] = &val; | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | void* cfapi_system_strdup_local(int *type, ...) |
/* command_title wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - object; */ | | |
/* 1 - params string. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWCmdTitle(CFParm* PParm) | | |
{ | | { |
CFParm *CFP; | | va_list args; |
static int val; | | char* txt; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | va_start(args, type); |
val = command_title((object *)(PParm->Value[0]),(char *)(PParm->Value[1])); | | txt = va_arg(args, char*); |
CFP->Value[0] = &val; | | va_end(args); |
return CFP; | | *type = CFAPI_STRING; |
}; | | return strdup_local(txt); |
| | } |
| | |
/*****************************************************************************/ | | void* cfapi_system_register_global_event(int *type, ...) |
/* kill_object wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - killed object; */ | | |
/* 1 - damage done; */ | | |
/* 2 - killer object; */ | | |
/* 3 - type of killing. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWKillObject(CFParm* PParm) | | |
{ | | { |
CFParm *CFP; | | va_list args; |
static int val; | | int eventcode; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | char* pname; |
val = kill_object( | | f_plug_api hook; |
(object *)(PParm->Value[0]), | | crossfire_plugin* cp; |
*(int *)(PParm->Value[1]), | | |
(object *)(PParm->Value[2]), | | |
*(int *)(PParm->Value[3]) | | |
); | | |
CFP->Value[0] = &val; | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | va_start(args,type); |
/* do_forget_spell wrapper. */ | | eventcode = va_arg(args, int); |
/*****************************************************************************/ | | pname = va_arg(args, char*); |
/* 0 - object to affect; */ | | hook = va_arg(args, f_plug_api); |
/* 1 - spell name to forget. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWDoForgetSpell(CFParm* PParm) | | |
{ | | |
do_forget_spell( | | |
(object *)(PParm->Value[0]), | | |
(char *)(PParm->Value[1]) | | |
); | | |
return NULL; | | |
}; | | |
| | |
/*****************************************************************************/ | | va_end(args); |
/* do_learn_spell wrapper. */ | | cp = plugins_find_plugin(pname); |
/*****************************************************************************/ | | cp->gevent[eventcode] = hook; |
/* 0 - object to affect; */ | | |
/* 1 - spell index to learn; */ | | |
/* 2 - special prayer integer flag. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWDoLearnSpell(CFParm* PParm) | | |
{ | | |
do_learn_spell( | | |
(object *)(PParm->Value[0]), | | |
(object *)(PParm->Value[1]), | | |
*(int *)(PParm->Value[2]) | | |
); | | |
return NULL; | | return NULL; |
}; | | } |
| | |
/*****************************************************************************/ | | void* cfapi_system_unregister_global_event(int *type, ...) |
/* check_spell_known wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - object to check; */ | | |
/* 1 - spell name to search. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWCheckSpellKnown(CFParm* PParm) | | |
{ | | { |
CFParm *CFP; | | va_list args; |
object *val; | | int eventcode; |
| | char* pname; |
| | crossfire_plugin* cp; |
| | |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | va_start(args,type); |
val = check_spell_known( | | eventcode = va_arg(args, int); |
(object *)(PParm->Value[0]), | | pname = va_arg(args, char*); |
(char *)(PParm->Value[1]) | | |
); | | |
CFP->Value[0] = val; | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | cp = plugins_find_plugin(pname); |
/* esrv_send_inventory wrapper. */ | | cp->gevent[eventcode] = NULL; |
/*****************************************************************************/ | | |
/* 0 - player object. */ | | |
/* 1 - updated object. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWESRVSendInventory(CFParm* PParm) | | |
{ | | |
esrv_send_inventory( | | |
(object *)(PParm->Value[0]), | | |
(object *)(PParm->Value[1]) | | |
); | | |
return NULL; | | |
}; | | |
| | |
/*****************************************************************************/ | | va_end(args); |
/* create_artifact wrapper. */ | | } |
/*****************************************************************************/ | | |
/* 0 - op; */ | | |
/* 1 - name of the artifact to create. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWCreateArtifact(CFParm* PParm) | | |
{ | | |
CFParm *CFP; | | |
static int val; | | |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | |
val = create_artifact( | | |
(object *)(PParm->Value[0]), | | |
(char *)(PParm->Value[1]) | | |
); | | |
CFP->Value[0] = &val; | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | void* cfapi_system_add_string(int *type, ...) |
/* get_archetype wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - Name of the archetype to search for. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWGetArchetype(CFParm* PParm) | | |
{ | | { |
CFParm *CFP; | | va_list args; |
object* val; | | const char* str; |
| | char* rv; |
| | |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | va_start(args,type); |
val = get_archetype( (char *)(PParm->Value[0]) ); | | str = va_arg(args, char*); |
| | va_end(args); |
| | |
CFP->Value[0] = (void *)(val); | | rv = (char*)add_string(str); |
return CFP; | | *type = CFAPI_STRING; |
}; | | return rv; |
| | } |
| | |
/*****************************************************************************/ | | void* cfapi_system_remove_string(int *type, ...) |
/* update_ob_speed wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - object to update. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWUpdateSpeed(CFParm* PParm) | | |
{ | | { |
update_ob_speed( | | va_list args; |
(object *)(PParm->Value[0]) | | char* str; |
); | | |
| | va_start(args,type); |
| | str = va_arg(args, char*); |
| | va_end(args); |
| | |
| | free_string(str); |
| | *type = CFAPI_NONE; |
return NULL; | | return NULL; |
}; | | } |
| | void* cfapi_system_check_path(int* type, ...) |
| | { |
| | va_list args; |
| | static int rv; |
| | char* name; |
| | int prepend_dir; |
| | |
/*****************************************************************************/ | | va_start(args,type); |
/* update_object wrapper. */ | | |
/*****************************************************************************/ | | name = va_arg(args, char*); |
/* 0 - object to update. */ | | prepend_dir = va_arg(args, int); |
/*****************************************************************************/ | | |
CFParm* CFWUpdateObject(CFParm* PParm) | | rv = check_path (name, prepend_dir); |
| | |
| | va_end(args); |
| | *type = CFAPI_INT; |
| | return &rv; |
| | } |
| | |
| | void* cfapi_system_re_cmp(int* type, ...) |
| | { |
| | va_list args; |
| | char* rv; |
| | char* name; |
| | int prepend_dir; |
| | const char* str; |
| | const char* regexp; |
| | |
| | va_start(args,type); |
| | |
| | str = va_arg(args, char*); |
| | regexp = va_arg(args, char*); |
| | |
| | rv = (char*)re_cmp (str,regexp); |
| | |
| | va_end(args); |
| | *type = CFAPI_STRING; |
| | return rv; |
| | } |
| | |
| | void* cfapi_system_directory(int* type, ...) |
| | { |
| | va_list args; |
| | char* rv; |
| | int dirtype; |
| | |
| | va_start(args,type); |
| | |
| | dirtype = va_arg(args, int); |
| | va_end(args); |
| | |
| | *type = CFAPI_STRING; |
| | |
| | switch (dirtype) |
{ | | { |
update_object( | | case 0: |
(object *)(PParm->Value[0]), | | return settings.mapdir; |
*(int *)(PParm->Value[1]) | | break; |
); | | case 1: |
| | return settings.uniquedir; |
| | break; |
| | case 2: |
| | return settings.tmpdir; |
| | break; |
| | case 3: |
| | return settings.confdir; |
| | break; |
| | case 4: |
| | return settings.localdir; |
| | break; |
| | case 5: |
| | return settings.playerdir; |
| | break; |
| | case 6: |
| | return settings.datadir; |
| | break; |
| | } |
| | } |
| | |
| | |
| | /* MAP RELATED HOOKS */ |
| | |
| | void* cfapi_map_get_map(int* type, ...) |
| | { |
| | va_list args; |
| | mapstruct* rv; |
| | int ctype; |
| | int x,y; |
| | sint16 nx,ny; |
| | char* name; |
| | mapstruct* m; |
| | |
| | va_start(args,type); |
| | |
| | ctype = va_arg(args, int); |
| | |
| | switch (ctype) |
| | { |
| | case 0: |
| | x = va_arg(args, int); |
| | y = va_arg(args, int); |
| | rv = get_empty_map(x,y); |
| | break; |
| | case 1: |
| | name = va_arg(args, char*); |
| | x = va_arg(args, int); |
| | rv = ready_map_name(name, x); |
| | break; |
| | case 2: |
| | m = va_arg(args, mapstruct*); |
| | nx = va_arg(args, int); |
| | ny = va_arg(args, int); |
| | rv = get_map_from_coord(m, &nx,&ny); |
| | break; |
| | } |
| | va_end(args); |
| | *type = CFAPI_PMAP; |
| | return rv; |
| | } |
| | void* cfapi_map_has_been_loaded(int* type, ...) |
| | { |
| | va_list args; |
| | mapstruct* map; |
| | char* string; |
| | |
| | va_start(args,type); |
| | string = va_arg(args, char*); |
| | map=has_been_loaded (string); |
| | va_end(args); |
| | *type = CFAPI_PMAP; |
| | return map; |
| | } |
| | void* cfapi_map_create_path(int* type, ...) |
| | { |
| | va_list args; |
| | int ctype; |
| | const char* str; |
| | char* rv; |
| | printf("create_map_path\n"); |
| | va_start(args,type); |
| | |
| | ctype = va_arg(args, int); |
| | str = va_arg(args, char*); |
| | *type = CFAPI_STRING; |
| | |
| | switch (ctype) |
| | { |
| | case 0: |
| | printf("create_map_path:%s\n",str); |
| | rv = (char*)create_pathname(str); |
| | break; |
| | case 1: |
| | rv = (char*)create_overlay_pathname(str); |
| | break; |
| | /*case 2: |
| | rv = create_items_path(str); |
| | break;*/ |
| | } |
| | va_end(args); |
| | return rv; |
| | } |
| | void* cfapi_map_get_map_property(int* type, ...) |
| | { |
| | va_list args; |
| | int x,y; |
| | sint16 nx,ny; |
| | mapstruct* map; |
| | mapstruct* newmap; |
| | static int rv; |
| | int property; |
| | char* buf; |
| | |
| | va_start(args,type); |
| | |
| | property = va_arg(args, int); |
| | switch (property) |
| | { |
| | case CFAPI_MAP_PROP_FLAGS: |
| | map = va_arg(args, mapstruct*); |
| | newmap = va_arg(args, mapstruct*); |
| | x = va_arg(args, int); |
| | y = va_arg(args, int); |
| | nx = va_arg(args, int); |
| | ny = va_arg(args, int); |
| | rv = get_map_flags(map, &newmap, x, y, &nx, &ny); |
| | va_end(args); |
| | *type = CFAPI_INT; |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_DIFFICULTY: |
| | map = va_arg(args, mapstruct*); |
| | rv = calculate_difficulty(map); |
| | va_end(args); |
| | *type = CFAPI_INT; |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_PATH: |
| | map = va_arg(args, mapstruct*); |
| | buf = map->path; |
| | *type = CFAPI_STRING; |
| | va_end(args); |
| | return buf; |
| | break; |
| | case CFAPI_MAP_PROP_TMPNAME: |
| | map = va_arg(args, mapstruct*); |
| | buf = map->tmpname; |
| | *type = CFAPI_STRING; |
| | va_end(args); |
| | return buf; |
| | break; |
| | case CFAPI_MAP_PROP_NAME: |
| | map = va_arg(args, mapstruct*); |
| | buf = map->name; |
| | *type = CFAPI_STRING; |
| | va_end(args); |
| | return buf; |
| | break; |
| | case CFAPI_MAP_PROP_RESET_TIME: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->reset_time; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_RESET_TIMEOUT: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->reset_timeout; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_PLAYERS: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->players; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_DARKNESS: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->darkness; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_WIDTH: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->width; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_HEIGHT: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->height; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_ENTER_X: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->enter_x; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_ENTER_Y: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->enter_y; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_TEMPERATURE: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->temp; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_PRESSURE: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->pressure; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_HUMIDITY: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->humid; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_WINDSPEED: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->windspeed; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_WINDDIR: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->winddir; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_SKY: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->sky; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_WPARTX: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->wpartx; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_WPARTY: |
| | map = va_arg(args, mapstruct*); |
| | rv = map->wparty; |
| | *type = CFAPI_INT; |
| | va_end(args); |
| | return &rv; |
| | break; |
| | case CFAPI_MAP_PROP_MESSAGE: |
| | map = va_arg(args, mapstruct*); |
| | buf = map->msg; |
| | *type = CFAPI_STRING; |
| | va_end(args); |
| | return buf; |
| | break; |
| | default: |
| | *type = CFAPI_NONE; |
| | va_end(args); |
return NULL; | | return NULL; |
}; | | } |
| | } |
| | |
/*****************************************************************************/ | | void* cfapi_map_set_map_property(int* type, ...) |
/* find_animation wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - name of the animation to find. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWFindAnimation(CFParm* PParm) | | |
{ | | { |
CFParm *CFP; | | va_list args; |
static int val; | | static int rv; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | mapstruct* map; |
LOG(llevInfo,"CFWFindAnimation: %s\n",(char *)(PParm->Value[0])); | | int val; |
val = find_animation((char *)(PParm->Value[0])); | | int property; |
LOG(llevInfo,"Returned val: %i\n",val); | | |
CFP->Value[0] = (void *)(&val); | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | va_start(args,type); |
/* get_archetype_by_object_name wrapper */ | | |
/*****************************************************************************/ | | property = va_arg(args, int); |
/* 0 - name to search for. */ | | |
/*****************************************************************************/ | | switch (property) |
CFParm* CFWGetArchetypeByObjectName(CFParm* PParm) | | |
{ | | { |
CFParm *CFP; | | case CFAPI_MAP_PROP_LIGHT: |
object* val; | | map = va_arg(args, mapstruct*); |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | val = va_arg(args, int); |
val = get_archetype_by_object_name( | | rv = change_map_light(map, val); |
(char *)(PParm->Value[0]) | | *type = CFAPI_INT; |
); | | va_end(args); |
CFP->Value[0] = (void *)(val); | | return &rv; |
return CFP; | | break; |
}; | | case CFAPI_MAP_PROP_RESET_TIME: |
| | map = va_arg(args, mapstruct*); |
| | *type = CFAPI_NONE; |
| | va_end(args); |
| | return NULL; |
| | break; |
| | default: |
| | *type = CFAPI_NONE; |
| | va_end(args); |
| | return NULL; |
| | } |
| | } |
| | void* cfapi_map_out_of_map(int* type, ...) |
| | { |
| | va_list args; |
| | static int rv; |
| | mapstruct* map; |
| | int x,y; |
| | |
/*****************************************************************************/ | | va_start(args,type); |
/* insert_ob_in_map wrapper. */ | | map = va_arg(args, mapstruct*); |
/*****************************************************************************/ | | x = va_arg(args, int); |
/* 0 - object to insert; */ | | y = va_arg(args, int); |
/* 1 - map; */ | | |
/* 2 - originator of the insertion; */ | | rv = out_of_map(map, x, y); |
/* 3 - integer flags. */ | | va_end(args); |
/*****************************************************************************/ | | *type = CFAPI_INT; |
CFParm* CFWInsertObjectInMap(CFParm* PParm) | | return &rv; |
| | } |
| | void* cfapi_map_update_position(int* type, ...) |
{ | | { |
CFParm *CFP; | | va_list args; |
object* val; | | mapstruct* map; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | int x,y; |
val = insert_ob_in_map( | | |
(object *)(PParm->Value[0]), | | |
(mapstruct *)(PParm->Value[1]), | | |
(object *)(PParm->Value[2]), | | |
*(int *)(PParm->Value[3]) | | |
); | | |
CFP->Value[0] = (void *)(val); | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | va_start(args,type); |
/* ready_map_name wrapper. */ | | |
/*****************************************************************************/ | | map = va_arg(args, mapstruct*); |
/* 0 - name of the map to ready; */ | | x = va_arg(args, int); |
/* 1 - integer flags. */ | | y = va_arg(args, int); |
/*****************************************************************************/ | | |
CFParm* CFWReadyMapName(CFParm* PParm) | | update_position (map, x, y); |
| | va_end(args); |
| | *type = CFAPI_NONE; |
| | return NULL; |
| | } |
| | void* cfapi_map_delete_map(int* type, ...) |
{ | | { |
CFParm* CFP; | | va_list args; |
mapstruct* val; | | mapstruct* map; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | va_start(args,type); |
val = ready_map_name( | | |
(char *)(PParm->Value[0]), | | |
*(int *)(PParm->Value[1]) | | |
); | | |
CFP->Value[0] = (void *)(val); | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | map = va_arg(args, mapstruct*); |
/* add_exp wrapper. */ | | |
/*****************************************************************************/ | | delete_map(map); |
/* 0 - object to increase experience of. */ | | |
/* 1 - amount of experience to add. */ | | va_end(args); |
/* 2 - skill name to add it to */ | | *type = CFAPI_NONE; |
/* 3 - flags for this */ | | return NULL; |
/*****************************************************************************/ | | } |
CFParm* CFWAddExp(CFParm* PParm) | | void* cfapi_map_message(int* type, ...) |
{ | | { |
change_exp( | | va_list args; |
(object *)(PParm->Value[0]), | | mapstruct* map; |
*(sint64 *)(PParm->Value[1]), | | char* string; |
(char*)(PParm->Value[2]), | | int color; |
*(int *)(PParm->Value[3]) | | |
); | | |
return(NULL); | | |
}; | | |
| | |
/*****************************************************************************/ | | va_start(args,type); |
/* determine_god wrapper. */ | | map = va_arg(args, mapstruct*); |
/*****************************************************************************/ | | string = va_arg(args, char*); |
/* 0 - object to determine the god of. */ | | color = va_arg(args, int); |
/*****************************************************************************/ | | va_end(args); |
CFParm* CFWDetermineGod(CFParm* PParm) | | |
| | new_info_map(color, map, string); |
| | *type = CFAPI_NONE; |
| | return NULL; |
| | } |
| | void* cfapi_map_get_object_at(int* type, ...) |
{ | | { |
CFParm* CFP; | | va_list args; |
char* val; | | mapstruct* map; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | int x, y; |
val = (char*)determine_god( | | object* rv; |
(object *)(PParm->Value[0]) | | |
); | | |
CFP->Value[0] = (void *)(val); | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | va_start(args,type); |
/* find_god wrapper. */ | | map = va_arg(args, mapstruct*); |
/*****************************************************************************/ | | x = va_arg(args, int); |
/* 0 - Name of the god to search for. */ | | y = va_arg(args, int); |
/*****************************************************************************/ | | va_end(args); |
CFParm* CFWFindGod(CFParm* PParm) | | |
| | rv = get_map_ob(map, x, y); |
| | *type = CFAPI_POBJECT; |
| | return rv; |
| | } |
| | void* cfapi_map_get_flags(int* type, ...) |
| | { |
| | va_list args; |
| | sint16 x, y; |
| | sint16 *nx, *ny; |
| | static mapstruct* map; |
| | mapstruct** newmap; |
| | static int rv; |
| | |
| | va_start(args,type); |
| | |
| | map = va_arg(args, mapstruct*); |
| | newmap = va_arg(args, mapstruct**); |
| | x = va_arg(args, int); |
| | y = va_arg(args, int); |
| | nx = va_arg(args, sint16*); |
| | ny = va_arg(args, sint16*); |
| | va_end(args); |
| | |
| | rv = get_map_flags(map, newmap, x, y, nx, ny); |
| | |
| | *type = CFAPI_INT; |
| | return &rv; |
| | } |
| | void* cfapi_map_present_arch_by_name(int* type, ...) |
{ | | { |
CFParm* CFP; | | va_list args; |
object* val; | | object* rv; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | int x, y; |
val = find_god( | | mapstruct* map; |
(char *)(PParm->Value[0]) | | char* msg; |
); | | |
CFP->Value[0] = (void *)(val); | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | va_start(args, type); |
/* dump_me wrapper. */ | | |
/*****************************************************************************/ | | msg = va_arg(args, char*); |
/* 0 - object to dump; */ | | map = va_arg(args, mapstruct*); |
/*****************************************************************************/ | | x = va_arg(args, int); |
CFParm* CFWDumpObject(CFParm* PParm) | | y = va_arg(args, int); |
| | |
| | va_end(args); |
| | |
| | rv = present_arch(find_archetype(msg), map, x, y); |
| | *type = CFAPI_POBJECT; |
| | return rv; |
| | } |
| | |
| | /* OBJECT-RELATED HOOKS */ |
| | |
| | void* cfapi_object_move(int* type, ...) |
{ | | { |
CFParm* CFP; | | va_list args; |
static char val[10240]; | | int kind; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | object* op; |
dump_me((object *)(PParm->Value[0]),val); | | object* activator; |
CFP->Value[0] = (void *)(val); | | player* pl; |
return CFP; | | int direction; |
}; | | static int rv=0; |
| | |
/*****************************************************************************/ | | va_start(args, type); |
/* load_object_str wrapper. */ | | kind = va_arg(args, int); |
/*****************************************************************************/ | | switch (kind) |
/* 0 - object dump string to load. */ | | { |
/*****************************************************************************/ | | case 0: |
CFParm* CFWLoadObject(CFParm* PParm) | | op = va_arg(args, object*); |
| | direction= va_arg(args, int); |
| | activator = va_arg(args, object*); |
| | va_end(args); |
| | rv = move_ob(op,direction,activator); |
| | break; |
| | case 1: |
| | pl = va_arg(args, player*); |
| | direction = va_arg(args, int); |
| | va_end(args); |
| | rv = move_player(pl, direction); |
| | break; |
| | } |
| | *type = CFAPI_INT; |
| | return &rv; |
| | } |
| | |
| | void* cfapi_object_get_key(int* type,...) |
| | { |
| | va_list args; |
| | char* rv; |
| | char* keyname; |
| | object* op; |
| | |
| | va_start(args,type); |
| | op = va_arg(args, object*); |
| | keyname = va_arg(args, char*); |
| | va_end(args); |
| | |
| | rv = (char*)get_ob_key_value(op, keyname); |
| | *type = CFAPI_STRING; |
| | return rv; |
| | } |
| | void* cfapi_object_set_key(int* type,...) |
| | { |
| | va_list args; |
| | char* keyname; |
| | char* value; |
| | object* op; |
| | |
| | va_start(args,type); |
| | op = va_arg(args, object*); |
| | keyname = va_arg(args, char*); |
| | value = va_arg(args, char*); |
| | va_end(args); |
| | |
| | set_ob_key_value(op, keyname, value,0); |
| | *type = CFAPI_NONE; |
| | return NULL; |
| | } |
| | void* cfapi_object_get_property(int* type, ...) |
| | { |
| | va_list args; |
| | int property; |
| | object* op; |
| | void* rv; |
| | static int ri; |
| | |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | property = va_arg(args, int); |
| | rv = NULL; |
| | if (op != NULL) |
| | switch (property) |
| | { |
| | case CFAPI_OBJECT_PROP_OB_ABOVE : |
| | rv = op->above; |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_OB_BELOW : |
| | rv = op->below; |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_NEXT_ACTIVE_OB : |
| | rv = op->active_next; |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_PREV_ACTIVE_OB : |
| | rv = op->active_prev; |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_INVENTORY : |
| | rv = op->inv; |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_ENVIRONMENT : |
| | rv = op->env; |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_HEAD : |
| | rv = op->head; |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_CONTAINER : |
| | rv = op->container; |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_MAP : |
| | rv = op->map; |
| | *type = CFAPI_PMAP; |
| | break; |
| | case CFAPI_OBJECT_PROP_COUNT : |
| | rv = &op->count; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_REFCOUNT : |
| | rv = &op->refcount; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_NAME : |
| | rv = query_name(op); |
| | *type = CFAPI_STRING; |
| | break; |
| | case CFAPI_OBJECT_PROP_NAME_PLURAL : |
| | rv = (char*)op->name_pl; |
| | *type = CFAPI_STRING; |
| | break; |
| | case CFAPI_OBJECT_PROP_TITLE : |
| | rv = (char*)op->title; |
| | *type = CFAPI_STRING; |
| | break; |
| | case CFAPI_OBJECT_PROP_RACE : |
| | rv = (char*)op->race; |
| | *type = CFAPI_STRING; |
| | break; |
| | case CFAPI_OBJECT_PROP_SLAYING : |
| | rv = (char*)op->slaying; |
| | *type = CFAPI_STRING; |
| | break; |
| | case CFAPI_OBJECT_PROP_SKILL : |
| | rv = (char*)op->skill; |
| | *type = CFAPI_STRING; |
| | break; |
| | case CFAPI_OBJECT_PROP_MESSAGE : |
| | rv = (char*)op->msg; |
| | *type = CFAPI_STRING; |
| | break; |
| | case CFAPI_OBJECT_PROP_LORE : |
| | rv = (char*)op->lore; |
| | *type = CFAPI_STRING; |
| | break; |
| | case CFAPI_OBJECT_PROP_X : |
| | ri = op->x; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_Y : |
| | ri = op->y; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_SPEED : |
| | rv = &op->speed; |
| | *type = CFAPI_DOUBLE; |
| | break; |
| | case CFAPI_OBJECT_PROP_SPEED_LEFT : |
| | rv = &op->speed_left; |
| | *type = CFAPI_DOUBLE; |
| | break; |
| | case CFAPI_OBJECT_PROP_NROF : |
| | rv = &op->nrof; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_DIRECTION : |
| | rv = &op->direction; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_FACING : |
| | rv = &op->facing; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_TYPE : |
| | rv = &op->type; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_SUBTYPE : |
| | rv = &op->subtype; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_CLIENT_TYPE : |
| | rv = &op->client_type; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_RESIST : |
| | { |
| | int idx; |
| | idx = va_arg(args, int); |
| | rv = &op->resist[idx]; |
| | } |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_ATTACK_TYPE : |
| | rv = &op->attacktype; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_PATH_ATTUNED : |
| | rv = &op->path_attuned; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_PATH_REPELLED : |
| | rv = &op->path_repelled; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_PATH_DENIED : |
| | rv = &op->path_denied; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_MATERIAL : |
| | rv = &op->material; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_MATERIAL_NAME : |
| | rv = (char*)op->materialname; |
| | *type = CFAPI_STRING; |
| | break; |
| | case CFAPI_OBJECT_PROP_MAGIC : |
| | rv = &op->magic; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_VALUE : |
| | rv = &op->value; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_LEVEL : |
| | rv = &op->level; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_LAST_HEAL : |
| | rv = &op->last_heal; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_LAST_SP : |
| | rv = &op->last_sp; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_LAST_GRACE : |
| | rv = &op->last_grace; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_LAST_EAT : |
| | rv = &op->last_eat; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_INVISIBLE_TIME : |
| | rv = &op->invisible; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_PICK_UP : |
| | rv = &op->pick_up; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_ITEM_POWER : |
| | rv = &op->item_power; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_GEN_SP_ARMOUR : |
| | rv = &op->gen_sp_armour; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_WEIGHT : |
| | rv = &op->weight; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_WEIGHT_LIMIT : |
| | rv = &op->weight_limit; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_CARRYING : |
| | rv = &op->carrying; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_GLOW_RADIUS : |
| | rv = &op->glow_radius; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_PERM_EXP : |
| | rv = &op->perm_exp; |
| | *type = CFAPI_LONG; |
| | break; |
| | case CFAPI_OBJECT_PROP_CURRENT_WEAPON : |
| | rv = op->current_weapon; |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_ENEMY : |
| | rv = op->enemy; |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_ATTACKED_BY : |
| | rv = op->attacked_by; |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_RUN_AWAY : |
| | rv = &op->run_away; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_CHOSEN_SKILL : |
| | rv = op->chosen_skill; |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_HIDDEN : |
| | rv = &op->hide; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_MOVE_STATUS : |
| | rv = &op->move_status; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_MOVE_TYPE : |
| | rv = &op->attack_movement; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_SPELL_ITEM : |
| | rv = op->spellitem; |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_EXP_MULTIPLIER : |
| | rv = &op->expmul; |
| | *type = CFAPI_DOUBLE; |
| | break; |
| | case CFAPI_OBJECT_PROP_ARCHETYPE : |
| | rv = op->arch; |
| | *type = CFAPI_PARCH; |
| | break; |
| | case CFAPI_OBJECT_PROP_OTHER_ARCH : |
| | rv = op->other_arch; |
| | *type = CFAPI_PARCH; |
| | break; |
| | case CFAPI_OBJECT_PROP_CUSTOM_NAME : |
| | rv = (char*)op->custom_name; |
| | *type = CFAPI_STRING; |
| | break; |
| | case CFAPI_OBJECT_PROP_ANIM_SPEED : |
| | rv = &op->anim_speed; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_FRIENDLY : |
| | ri = is_friendly(op); |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_SHORT_NAME : |
| | rv = (char*)query_short_name(op); |
| | *type = CFAPI_STRING; |
| | break; |
| | case CFAPI_OBJECT_PROP_BASE_NAME : |
{ | | { |
CFParm* CFP; | | int i; |
object* val; | | i = va_arg(args, int); |
| | rv = (char*)query_base_name(op, i); |
| | *type = CFAPI_STRING; |
| | } |
| | break; |
| | case CFAPI_OBJECT_PROP_MAGICAL : |
| | ri = is_magical(op); |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_LUCK : |
| | rv = &op->stats.luck; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_EXP : |
| | rv = &op->stats.exp; |
| | *type = CFAPI_LONG; |
| | break; |
| | case CFAPI_OBJECT_PROP_OWNER : |
| | rv = get_owner(op); |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_PRESENT : |
| | { |
| | int stype; |
| | rv = 0; |
| | stype = va_arg(args, int); |
| | switch (stype) |
| | { |
| | unsigned char ptype; |
| | char* buf; |
| | archetype* at; |
| | case 0: /* present_in_ob */ |
| | ptype = (unsigned char)(va_arg(args, int)); |
| | rv = present_in_ob(ptype, op); |
| | break; |
| | case 1: /* present_in_ob_by_name */ |
| | ptype = (unsigned char)(va_arg(args, int)); |
| | buf = va_arg(args, char*); |
| | rv = present_in_ob_by_name(ptype, buf, op); |
| | break; |
| | case 2: /* present_arch_in_ob */ |
| | at = va_arg(args, archetype*); |
| | rv = present_arch_in_ob(at, op); |
| | break; |
| | } |
| | } |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case CFAPI_OBJECT_PROP_CHEATER : |
| | ri = (QUERY_FLAG(op, FLAG_WAS_WIZ)); |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_MERGEABLE : |
| | { |
| | object* op2; |
| | ri = 0; |
| | op2 = va_arg(args, object*); |
| | ri = CAN_MERGE(op,op2); |
| | rv = &ri; |
| | } |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_PICKABLE : |
| | { |
| | object* op2; |
| | rv = 0; |
| | op2 = va_arg(args, object*); |
| | ri = can_pick(op2,op); |
| | rv = &ri; |
| | } |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_FLAGS : |
| | { |
| | int fl; |
| | ri = 0; |
| | fl = va_arg(args, int); |
| | ri = QUERY_FLAG(op, fl); |
| | rv = &ri; |
| | } |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_STR: |
| | ri = op->stats.Str; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_DEX: |
| | ri = op->stats.Dex; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_CON: |
| | ri = op->stats.Con; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_WIS: |
| | ri = op->stats.Wis; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_INT: |
| | ri = op->stats.Int; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_POW: |
| | ri = op->stats.Pow; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_CHA: |
| | ri = op->stats.Cha; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_WC: |
| | ri = op->stats.wc; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_AC: |
| | ri = op->stats.ac; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_HP: |
| | ri = op->stats.hp; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_SP: |
| | ri = op->stats.sp; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_GP: |
| | ri = op->stats.grace; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_FP: |
| | ri = op->stats.food; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_MAXHP: |
| | ri = op->stats.maxhp; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_MAXSP: |
| | ri = op->stats.maxsp; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_MAXGP: |
| | ri = op->stats.maxgrace; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_DAM: |
| | ri = op->stats.dam; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_GOD: |
| | rv = (char*)determine_god(op); |
| | *type = CFAPI_STRING; |
| | break; |
| | case CFAPI_OBJECT_PROP_ARCH_NAME: |
| | rv = (char*)op->arch->name; |
| | *type = CFAPI_STRING; |
| | case CFAPI_PLAYER_PROP_IP : |
| | rv = op->contr->socket.host; |
| | *type = CFAPI_STRING; |
| | break; |
| | case CFAPI_OBJECT_PROP_INVISIBLE: |
| | ri = op->invisible; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | case CFAPI_OBJECT_PROP_FACE : |
| | ri = op->animation_id; |
| | rv = &ri; |
| | *type = CFAPI_INT; |
| | break; |
| | default: |
| | *type = CFAPI_NONE; |
| | break; |
| | } |
| | va_end(args); |
| | return rv; |
| | } |
| | |
| | void* cfapi_object_set_property(int* type, ...) |
| | { |
| | va_list args; |
| | int iarg; |
| | long larg; |
| | char* sarg; |
| | double darg; |
| | object* oparg; |
| | object* op; |
| | int property; |
| | void* rv; |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | property = va_arg(args, int); |
| | rv = NULL; |
| | |
| | if (op != NULL) |
| | switch (property) |
| | { |
| | case CFAPI_OBJECT_PROP_NAME : |
| | sarg = va_arg(args, char*); |
| | FREE_AND_COPY(op->name, sarg); |
| | break; |
| | case CFAPI_OBJECT_PROP_NAME_PLURAL : |
| | sarg = va_arg(args, char*); |
| | FREE_AND_COPY(op->name_pl, sarg); |
| | break; |
| | case CFAPI_OBJECT_PROP_TITLE : |
| | sarg = va_arg(args, char*); |
| | FREE_AND_COPY(op->title, sarg); |
| | break; |
| | case CFAPI_OBJECT_PROP_RACE : |
| | sarg = va_arg(args, char*); |
| | FREE_AND_COPY(op->race, sarg); |
| | break; |
| | case CFAPI_OBJECT_PROP_SLAYING : |
| | sarg = va_arg(args, char*); |
| | FREE_AND_COPY(op->slaying, sarg); |
| | break; |
| | case CFAPI_OBJECT_PROP_SKILL : |
| | sarg = va_arg(args, char*); |
| | FREE_AND_COPY(op->skill, sarg); |
| | break; |
| | case CFAPI_OBJECT_PROP_MESSAGE : |
| | sarg = va_arg(args, char*); |
| | FREE_AND_COPY(op->msg, sarg); |
| | break; |
| | case CFAPI_OBJECT_PROP_LORE : |
| | sarg = va_arg(args, char*); |
| | FREE_AND_COPY(op->lore, sarg); |
| | break; |
| | case CFAPI_OBJECT_PROP_SPEED : |
| | darg = va_arg(args, double); |
| | op->speed = darg; |
| | break; |
| | case CFAPI_OBJECT_PROP_SPEED_LEFT : |
| | darg = va_arg(args, double); |
| | op->speed_left = darg; |
| | break; |
| | case CFAPI_OBJECT_PROP_NROF : |
| | iarg = va_arg(args, int); |
| | if (op->nrof > iarg) |
| | decrease_ob_nr(op,op->nrof-iarg); |
| | else |
| | { |
| | object* tmp; |
| | player *pl; |
| | op->nrof = iarg; |
| | if (op->env != NULL) |
| | { |
| | tmp = is_player_inv(op->env); |
| | if (!tmp) |
| | { |
| | for (pl=first_player; pl; pl=pl->next) |
| | if (pl->ob->container == op->env) break; |
| | if (pl) tmp=pl->ob; |
| | else tmp=NULL; |
| | } |
| | if (tmp) |
| | esrv_send_item(tmp, op); |
| | } |
| | else |
| | { |
| | object *above = op->above; |
| | |
| | for (tmp = above; tmp != NULL; tmp = tmp->above) |
| | if (tmp->type == PLAYER) |
| | esrv_send_item(tmp, op); |
| | } |
| | } |
| | break; |
| | case CFAPI_OBJECT_PROP_DIRECTION : |
| | iarg = va_arg(args, int); |
| | op->direction = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_FACING : |
| | iarg = va_arg(args, int); |
| | op->facing = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_RESIST : |
| | { |
| | int iargbis = va_arg(args, int); |
| | iarg = va_arg(args, int); |
| | op->resist[iargbis] = iarg; |
| | } |
| | break; |
| | case CFAPI_OBJECT_PROP_ATTACK_TYPE : |
| | iarg = va_arg(args, int); |
| | op->attacktype = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_PATH_ATTUNED : |
| | iarg = va_arg(args, int); |
| | op->path_attuned = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_PATH_REPELLED : |
| | iarg = va_arg(args, int); |
| | op->path_repelled = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_PATH_DENIED : |
| | iarg = va_arg(args, int); |
| | op->path_denied = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_MATERIAL : |
| | iarg = va_arg(args, int); |
| | op->material = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_MATERIAL_NAME : |
| | break; |
| | case CFAPI_OBJECT_PROP_MAGIC : |
| | iarg = va_arg(args, int); |
| | op->magic = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_VALUE : |
| | iarg = va_arg(args, int); |
| | op->value = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_LEVEL : |
| | iarg = va_arg(args, int); |
| | op->level = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_LAST_HEAL : |
| | iarg = va_arg(args, int); |
| | op->last_heal = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_LAST_SP : |
| | iarg = va_arg(args, int); |
| | op->last_sp = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_LAST_GRACE : |
| | iarg = va_arg(args, int); |
| | op->last_grace = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_LAST_EAT : |
| | iarg = va_arg(args, int); |
| | op->last_eat = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_INVISIBLE_TIME : |
| | iarg = va_arg(args, int); |
| | op->invisible = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_PICK_UP : |
| | iarg = va_arg(args, int); |
| | op->pick_up = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_ITEM_POWER : |
| | iarg = va_arg(args, int); |
| | op->item_power = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_GEN_SP_ARMOUR : |
| | iarg = va_arg(args, int); |
| | op->gen_sp_armour = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_WEIGHT : |
| | iarg = va_arg(args, int); |
| | op->weight = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_WEIGHT_LIMIT : |
| | iarg = va_arg(args, int); |
| | op->weight_limit = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_GLOW_RADIUS : |
| | iarg = va_arg(args, int); |
| | op->glow_radius = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_PERM_EXP : |
| | larg = va_arg(args, long); |
| | op->perm_exp = larg; |
| | break; |
| | case CFAPI_OBJECT_PROP_ENEMY : |
| | oparg = va_arg(args, object*); |
| | op->enemy = oparg; |
| | break; |
| | case CFAPI_OBJECT_PROP_RUN_AWAY : |
| | iarg = va_arg(args, int); |
| | op->run_away = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_CHOSEN_SKILL : |
| | oparg = va_arg(args, object*); |
| | op->chosen_skill = oparg; |
| | break; |
| | case CFAPI_OBJECT_PROP_HIDDEN : |
| | iarg = va_arg(args, int); |
| | op->hide = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_MOVE_STATUS : |
| | iarg = va_arg(args, int); |
| | op->move_status = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_MOVE_TYPE : |
| | iarg = va_arg(args, int); |
| | op->attack_movement = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_SPELL_ITEM : |
| | oparg = va_arg(args, object*); |
| | op->spellitem = oparg; |
| | break; |
| | case CFAPI_OBJECT_PROP_EXP_MULTIPLIER : |
| | darg = va_arg(args, double); |
| | op->expmul = darg; |
| | break; |
| | case CFAPI_OBJECT_PROP_CUSTOM_NAME : |
| | sarg = va_arg(args, char*); |
| | FREE_AND_COPY(op->custom_name, sarg); |
| | break; |
| | case CFAPI_OBJECT_PROP_ANIM_SPEED : |
| | iarg = va_arg(args, int); |
| | op->anim_speed = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_FRIENDLY : |
| | iarg = va_arg(args, int); |
| | if ((iarg == 1) && (is_friendly(op) == 0)) |
| | add_friendly_object(op); |
| | else if ((iarg == 0) && (is_friendly(op) == 1)) |
| | remove_friendly_object(op); |
| | break; |
| | case CFAPI_OBJECT_PROP_LUCK : |
| | iarg = va_arg(args, int); |
| | op->stats.luck = iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_EXP : |
| | { |
| | char* skillname; |
| | |
| | larg = va_arg(args, long); |
| | skillname = va_arg(args, char*); |
| | iarg = va_arg(args, int); |
| | change_exp(op, larg, skillname, iarg); |
| | } |
| | break; |
| | case CFAPI_OBJECT_PROP_OWNER : |
| | oparg = va_arg(args, object*); |
| | set_owner(op, oparg); |
| | break; |
| | case CFAPI_OBJECT_PROP_CHEATER : |
| | set_cheat(op); |
| | break; |
| | case CFAPI_OBJECT_PROP_FLAGS : |
| | { |
| | int iargbis; |
| | iarg = va_arg(args, int); |
| | iargbis = va_arg(args, int); |
| | if (iargbis == 1) |
| | SET_FLAG(op, iarg); |
| | else |
| | CLEAR_FLAG(op, iarg); |
| | } |
| | break; |
| | case CFAPI_OBJECT_PROP_STR: |
| | iarg = va_arg(args, int); |
| | op->stats.Str=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_DEX: |
| | iarg = va_arg(args, int); |
| | op->stats.Dex=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_CON: |
| | iarg = va_arg(args, int); |
| | op->stats.Con=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_WIS: |
| | iarg = va_arg(args, int); |
| | op->stats.Wis=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_INT: |
| | iarg = va_arg(args, int); |
| | op->stats.Int=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_POW: |
| | iarg = va_arg(args, int); |
| | op->stats.Pow=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_CHA: |
| | iarg = va_arg(args, int); |
| | op->stats.Cha=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_WC: |
| | iarg = va_arg(args, int); |
| | op->stats.wc=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_AC: |
| | iarg = va_arg(args, int); |
| | op->stats.ac=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_HP: |
| | iarg = va_arg(args, int); |
| | op->stats.hp=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_SP: |
| | iarg = va_arg(args, int); |
| | op->stats.sp=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_GP: |
| | iarg = va_arg(args, int); |
| | op->stats.grace=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_FP: |
| | iarg = va_arg(args, int); |
| | op->stats.food=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_MAXHP: |
| | iarg = va_arg(args, int); |
| | op->stats.maxhp=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_MAXSP: |
| | iarg = va_arg(args, int); |
| | op->stats.maxsp=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_MAXGP: |
| | iarg = va_arg(args, int); |
| | op->stats.maxgrace=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_DAM: |
| | iarg = va_arg(args, int); |
| | op->stats.dam=iarg; |
| | break; |
| | case CFAPI_OBJECT_PROP_FACE: |
| | iarg = va_arg(args, int); |
| | op->animation_id = iarg; |
| | update_object(op, UP_OBJ_FACE); |
| | break; |
| | case CFAPI_OBJECT_ANIMATION: |
| | iarg = va_arg(args, int); |
| | if (iarg!=-1) |
| | { |
| | SET_ANIMATION(op,iarg); |
| | } |
| | update_object(op, UP_OBJ_FACE); |
| | break; |
| | default: |
| | *type = CFAPI_NONE; |
| | break; |
| | } |
| | va_end(args); |
| | |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | *type = CFAPI_NONE; |
val = load_object_str((char *)(PParm->Value[0])); | | return NULL; |
CFP->Value[0] = (void *)(val); | | } |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | void* cfapi_object_apply_below(int* type, ...) |
/* remove_ob wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - object to remove. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWRemoveObject(CFParm* PParm) | | |
{ | | { |
remove_ob((object *)(PParm->Value[0])); | | va_list args; |
| | object* applier; |
| | |
| | va_start(args,type); |
| | |
| | applier = va_arg(args, object*); |
| | |
| | va_end(args); |
| | |
| | player_apply_below(applier); |
| | *type = CFAPI_NONE; |
return NULL; | | return NULL; |
}; | | } |
| | |
/*****************************************************************************/ | | void* cfapi_object_apply(int* type, ...) |
/* add_string wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - string to add. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWAddString(CFParm* PParm) | | |
{ | | { |
CFParm* CFP; | | va_list args; |
char* val; | | object* applied; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | object* applier; |
val = (char *)(PParm->Value[0]); | | int aflags; |
CFP->Value[0] = (void*) add_string (val); | | static int rv; |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | va_start(args,type); |
/* add_refcount wrapper. */ | | |
/*****************************************************************************/ | | applied = va_arg(args, object*); |
/* 0 - string to increment refcount. */ | | applier = va_arg(args, object*); |
/*****************************************************************************/ | | aflags = va_arg(args, int); |
CFParm* CFWAddRefcount(CFParm* PParm) | | |
| | va_end(args); |
| | |
| | *type = CFAPI_INT; |
| | rv = manual_apply(applier, applied, aflags); |
| | return &rv; |
| | } |
| | void* cfapi_object_identify(int* type, ...) |
{ | | { |
CFParm* CFP; | | va_list args; |
char* val; | | object* op; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | |
val = (char *)(PParm->Value[0]); | | |
CFP->Value[0] = (void*) add_refcount (val); | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | va_start(args,type); |
/* free_string wrapper. */ | | |
/*****************************************************************************/ | | op = va_arg(args, object*); |
/* 0 - string to free. */ | | |
/*****************************************************************************/ | | va_end(args); |
CFParm* CFWFreeString(CFParm* PParm) | | |
| | identify(op); |
| | *type = CFAPI_NONE; |
| | return NULL; |
| | } |
| | void* cfapi_object_describe(int* type, ...) |
| | { |
| | va_list args; |
| | object* op; |
| | object* owner; |
| | |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | owner = va_arg(args, object*); |
| | va_end(args); |
| | |
| | *type = CFAPI_STRING; |
| | return describe_item(op,owner); |
| | } |
| | void* cfapi_object_drain(int* type, ...) |
{ | | { |
char* val; | | va_list args; |
val = (char *)(PParm->Value[0]); | | |
free_string (val); | | object* op; |
| | int ds; |
| | |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | ds = va_arg(args, int); |
| | |
| | va_end(args); |
| | |
| | drain_specific_stat(op, ds); |
| | |
| | *type = CFAPI_NONE; |
return NULL; | | return NULL; |
}; | | } |
| | void* cfapi_object_fix(int* type, ...) |
| | { |
| | va_list args; |
| | object* op; |
| | |
/*****************************************************************************/ | | va_start(args,type); |
/* first_map wrapper. */ | | |
/*****************************************************************************/ | | op = va_arg(args, object*); |
CFParm* CFWGetFirstMap(CFParm* PParm) | | |
| | va_end(args); |
| | |
| | fix_player(op); |
| | |
| | *type = CFAPI_NONE; |
| | return NULL; |
| | } |
| | void* cfapi_object_give_skill(int* type, ...) |
{ | | { |
CFParm* CFP; | | va_list args; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | |
CFP->Value[0] = (void*)(first_map) ; | | object* op; |
return CFP; | | char* skillname; |
}; | | |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | skillname = va_arg(args, char*); |
| | |
| | va_end(args); |
| | |
| | *type = CFAPI_POBJECT; |
| | return give_skill_by_name(op, skillname); |
| | } |
| | void* cfapi_object_transmute(int* type, ...) |
| | { |
| | va_list args; |
| | |
| | object* op; |
| | object* chg; |
| | |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | chg = va_arg(args, object*); |
| | |
| | va_end(args); |
| | |
| | transmute_materialname(op, chg); |
| | *type = CFAPI_NONE; |
| | return NULL; |
| | } |
| | void* cfapi_object_remove(int* type, ...) |
| | { |
| | va_list args; |
| | object* op; |
| | |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | |
| | va_end(args); |
| | |
| | remove_ob(op); |
| | *type = CFAPI_NONE; |
| | return NULL; |
| | } |
| | void* cfapi_object_delete(int* type, ...) |
| | { |
| | va_list args; |
| | object* op; |
| | |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | |
| | va_end(args); |
| | |
| | free_object(op); |
| | |
| | *type = CFAPI_NONE; |
| | return NULL; |
| | } |
| | void* cfapi_object_clone(int* type, ...) |
| | { |
| | va_list args; |
| | object* op; |
| | int kind; |
| | |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | kind = va_arg(args, int); |
| | |
| | va_end(args); |
| | |
| | if (kind == 0) |
| | { |
| | *type = CFAPI_POBJECT; |
| | return object_create_clone(op); |
| | } |
| | else |
| | { |
| | object* tmp; |
| | tmp = get_object(); |
| | copy_object(op,tmp); |
| | *type = CFAPI_POBJECT; |
| | return tmp; |
| | } |
| | } |
| | void* cfapi_object_find(int* type, ...) |
| | { |
| | va_list args; |
| | int ftype; |
| | void* rv; |
| | int ival; |
| | int ival2; |
| | char* sval; |
| | object* op; |
| | va_start(args,type); |
| | |
| | ftype = va_arg(args, int); |
| | switch (ftype) |
| | { |
| | case 0: |
| | ival = va_arg(args, int); |
| | rv = find_object(ival); |
| | break; |
| | case 1: |
| | sval = va_arg(args, char*); |
| | rv = find_object_name(sval); |
| | break; |
| | case 2: |
| | op = va_arg(args, object*); |
| | ival = va_arg(args, int); |
| | ival2 = va_arg(args, int); |
| | rv = find_obj_by_type_subtype(op, ival, ival2); |
| | break; |
| | case 3: |
| | op = va_arg(args, object*); |
| | rv = is_player_inv(op); |
| | break; |
| | } |
| | |
| | va_end(args); |
| | |
| | *type = CFAPI_POBJECT; |
| | return rv; |
| | } |
| | void* cfapi_object_create(int* type, ...) |
| | { |
| | va_list args; |
| | int ival; |
| | va_start(args,type); |
| | ival = va_arg(args, int); |
| | |
| | *type = CFAPI_POBJECT; |
| | switch (ival) |
| | { |
| | case 0: |
| | va_end(args); |
| | return get_object(); |
| | break; |
| | case 1: /* Named object. Nearly the old plugin behavior, but we don't add artifact suffixes */ |
| | { |
| | char* sval; |
| | object* op; |
| | sval = va_arg(args, char*); |
| | |
| | printf("Object creation: name=%s\n", sval); |
| | |
| | op = get_archetype_by_object_name(sval); |
| | |
| | printf("op found: %p\n", op); |
| | |
| | if (strncmp(query_name(op),ARCH_SINGULARITY, ARCH_SINGULARITY_LEN)==0) |
| | { |
| | free_object(op); |
| | /* Try with archetype names... */ |
| | op = get_archetype(sval); |
| | if (strncmp(query_name(op),ARCH_SINGULARITY, ARCH_SINGULARITY_LEN)==0) |
| | { |
| | free_object(op); |
| | *type = CFAPI_NONE; |
| | va_end(args); |
| | return NULL; |
| | } |
| | } |
| | va_end(args); |
| | return op; |
| | } |
| | break; |
| | } |
| | } |
| | void* cfapi_object_insert(int* type, ...) |
| | { |
| | va_list args; |
| | object* op; |
| | object* orig; |
| | mapstruct* map; |
| | int flag, x, y; |
| | int itype; |
| | char* arch_string; |
| | void* rv = NULL; |
| | |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | itype = va_arg(args, int); |
| | |
| | switch (itype) |
| | { |
| | case 0: |
| | map = va_arg(args, mapstruct*); |
| | orig = va_arg(args, object*); |
| | flag = va_arg(args, int); |
| | x = va_arg(args, int); |
| | y = va_arg(args, int); |
| | rv = insert_ob_in_map_at(op, map, orig, flag,x,y); |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case 1: |
| | map = va_arg(args, mapstruct*); |
| | orig = va_arg(args, object*); |
| | flag = va_arg(args, int); |
| | rv = insert_ob_in_map(op, map, orig, flag); |
| | *type = CFAPI_POBJECT; |
| | break; |
| | case 2: |
| | arch_string = va_arg(args, char*); |
| | replace_insert_ob_in_map(arch_string, op); |
| | *type = CFAPI_NONE; |
| | break; |
| | case 3: |
| | orig = va_arg(args, object*); |
| | rv = insert_ob_in_ob(op, orig); |
| | if (orig->type == PLAYER) |
| | { |
| | esrv_send_item(orig,op); |
| | } |
| | *type = CFAPI_POBJECT; |
| | break; |
| | } |
| | |
| | va_end(args); |
| | |
| | return rv; |
| | } |
| | void* cfapi_object_split(int* type, ...) |
| | { |
| | va_list args; |
| | |
| | int nr; |
| | object* op; |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | nr = va_arg(args, int); |
| | |
| | va_end(args); |
| | *type = CFAPI_POBJECT; |
| | return get_split_ob(op, nr); |
| | } |
| | void* cfapi_object_merge(int* type, ...) |
| | { |
| | va_list args; |
| | object* op; |
| | object* op2; |
| | |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | op2 = va_arg(args, object*); |
| | |
| | va_end(args); |
| | |
| | |
| | *type = CFAPI_POBJECT; |
| | return merge_ob(op, op2); |
| | } |
| | void* cfapi_object_distance(int* type, ...) |
| | { |
| | va_list args; |
| | static int rv; |
| | object* op; |
| | object* op2; |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | op2 = va_arg(args, object*); |
| | |
| | va_end(args); |
| | |
| | *type = CFAPI_INT; |
| | rv = distance(op, op2); |
| | return &rv; |
| | } |
| | void* cfapi_object_update(int* type, ...) |
| | { |
| | va_list args; |
| | int action; |
| | object* op; |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | action = va_arg(args, int); |
| | |
| | va_end(args); |
| | |
| | update_object(op, action); |
| | *type = CFAPI_NONE; |
| | return NULL; |
| | } |
| | void* cfapi_object_clear(int* type, ...) |
| | { |
| | va_list args; |
| | object* op; |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | |
| | va_end(args); |
| | |
| | clear_object(op); |
| | *type = CFAPI_NONE; |
| | return NULL; |
| | } |
| | void* cfapi_object_reset(int* type, ...) |
| | { |
| | va_list args; |
| | object* op; |
| | |
| | va_start(args,type); |
| | |
| | op = va_arg(args, object*); |
| | |
| | va_end(args); |
| | |
| | reset_object(op); |
| | *type = CFAPI_NONE; |
| | return NULL; |
| | } |
| | |
/*****************************************************************************/ | | void* cfapi_object_check_inventory(int* type, ...) |
/* first_player wrapper. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWGetFirstPlayer(CFParm* PParm) | | |
{ | | { |
CFParm* CFP; | | va_list args; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | object* op; |
CFP->Value[0] = (void*)(first_player) ; | | object* op2; |
return CFP; | | int checktype; |
}; | | object* ret = NULL; |
| | |
/*****************************************************************************/ | | va_start(args,type); |
/* first_archetype wrapper. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWGetFirstArchetype(CFParm* PParm) | | |
{ | | |
CFParm* CFP; | | |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | |
CFP->Value[0] = (void*)(first_archetype) ; | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | op = va_arg(args, object*); |
/* query_cost wrapper. */ | | op2 = va_arg(args, object*); |
/*****************************************************************************/ | | checktype = va_arg(args, int); |
/* 0 - object to evaluate. */ | | |
/* 1 - who tries to sell of buy it */ | | |
/* 2 - F_SELL F_BUY or F_TRUE */ | | |
/*****************************************************************************/ | | |
CFParm* CFWQueryCost(CFParm* PParm) | | |
{ | | |
CFParm* CFP; | | |
object* whatptr; | | |
object* whoptr; | | |
int flag; | | |
static uint64 val; | | |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | |
whatptr = (object *)(PParm->Value[0]); | | |
whoptr = (object *)(PParm->Value[1]); | | |
flag = *(int*)(PParm->Value[2]); | | |
val=query_cost (whatptr,whoptr,flag); | | |
CFP->Value[0] = (void*) &val; | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | if (checktype == 0) |
/* query_money wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - object we are looking for solvability at. */ | | |
/*****************************************************************************/ | | |
CFParm* CFWQueryMoney(CFParm* PParm) | | |
{ | | { |
CFParm* CFP; | | check_inv(op,op2); |
object* whoptr; | | *type = CFAPI_NONE; |
static uint64 val; | | } |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | else |
whoptr = (object *)(PParm->Value[0]); | | |
val=query_money (whoptr); | | |
CFP->Value[0] = (void*) &val; | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | |
/* pay_for_item wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - object to pay. */ | | |
/* 1 - who tries to buy it */ | | |
/*****************************************************************************/ | | |
CFParm* CFWPayForItem(CFParm* PParm) | | |
{ | | { |
CFParm* CFP; | | ret = check_inv_recursive(op,op); |
object* whatptr; | | *type = CFAPI_POBJECT; |
object* whoptr; | | } |
static int val; | | |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | |
whatptr = (object *)(PParm->Value[0]); | | |
whoptr = (object *)(PParm->Value[1]); | | |
val= pay_for_item (whatptr,whoptr); | | |
CFP->Value[0] = (void*) &val; | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | va_end(args); |
/* pay_for_amount wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - amount to pay. */ | | |
/* 1 - who tries to pay it */ | | |
/*****************************************************************************/ | | |
CFParm* CFWPayForAmount(CFParm* PParm) | | |
{ | | |
CFParm* CFP; | | |
uint64 amount; | | |
object* whoptr; | | |
static int val; | | |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | |
amount = *(uint64 *)(PParm->Value[0]); | | |
whoptr = (object *)(PParm->Value[1]); | | |
val= pay_for_amount (amount,whoptr); | | |
CFP->Value[0] = (void*) &val; | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | return ret; |
/* new_draw_info wrapper. */ | | } |
/*****************************************************************************/ | | |
/* 0 - flags */ | | |
/* 1 - pri */ | | |
/* 2 - pl */ | | |
/* 3 - buf */ | | |
/*****************************************************************************/ | | |
CFParm* CFWNewDrawInfo(CFParm* PParm) | | |
{ | | |
new_draw_info(*(int *)(PParm->Value[0]), | | |
*(int *)(PParm->Value[1]), | | |
(object *)(PParm->Value[2]), | | |
(char *)(PParm->Value[3])); | | |
return NULL; | | |
}; | | |
| | |
/*****************************************************************************/ | | void* cfapi_object_clean_object(int* type, ...) |
/* move_player wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - player to move */ | | |
/* 1 - direction of move */ | | |
/*****************************************************************************/ | | |
CFParm* CFWMovePlayer (CFParm* PParm) | | |
{ | | { |
CFParm* CFP; | | va_list args; |
static int val; | | object* op; |
val=move_player ((object*)PParm->Value[0], | | va_start(args,type); |
*(int*)PParm->Value[1]); | | op = va_arg(args, object*); |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | clean_object(op); |
CFP->Value[0] = (void*) &val; | | va_end(args); |
return(CFP); | | *type = CFAPI_NONE; |
| | return NULL; |
} | | } |
| | void* cfapi_object_on_same_map(int* type, ...) |
/*****************************************************************************/ | | |
/* move_object wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - object to move */ | | |
/* 1 - direction of move */ | | |
/* 2 - originator */ | | |
/*****************************************************************************/ | | |
CFParm* CFWMoveObject (CFParm* PParm) | | |
{ | | { |
CFParm* CFP; | | va_list args; |
static int val; | | static int rv; |
val=move_ob ((object*)PParm->Value[0], | | object* op1; |
*(int*)PParm->Value[1], | | object* op2; |
(object*)PParm->Value[2]); | | |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | va_start(args,type); |
CFP->Value[0] = (void*) &val; | | op1 = va_arg(args, object*); |
| | op2 = va_arg(args, object*); |
| | |
return(CFP); | | rv = on_same_map(op1, op2); |
| | va_end(args); |
| | |
| | *type = CFAPI_INT; |
| | return &rv; |
} | | } |
| | |
/*****************************************************************************/ | | void* cfapi_object_spring_trap(int* type, ...) |
/* send_plugin_custom_message wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - player to send command to */ | | |
/* 1 - command to send */ | | |
/*****************************************************************************/ | | |
CFParm* CFWSendCustomCommand(CFParm* PParm) | | |
{ | | { |
send_plugin_custom_message((object *)(PParm->Value[0]),(char *)(PParm->Value[1])); | | object* trap; |
| | object* victim; |
| | va_list args; |
| | |
| | va_start(args,type); |
| | trap = va_arg(args, object*); |
| | victim = va_arg(args, object*); |
| | va_end(args); |
| | |
| | spring_trap(trap,victim); |
| | *type = CFAPI_NONE; |
return NULL; | | return NULL; |
}; | | } |
| | |
/*****************************************************************************/ | | void* cfapi_object_check_trigger(int* type, ...) |
/* cftimer_create wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - id */ | | |
/* 1 - delay */ | | |
/* 2 - object */ | | |
/* 3 - mode */ | | |
/*****************************************************************************/ | | |
CFParm* CFWCFTimerCreate(CFParm* PParm) | | |
{ | | { |
CFParm* CFP; | | object* op; |
static int val; | | object* cause; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | va_list args; |
val = cftimer_create(*(int *)(PParm->Value[0]), | | static int rv; |
*(long *)(PParm->Value[1]), | | |
(object *)(PParm->Value[2]), | | |
*(int *)(PParm->Value[3])); | | |
CFP->Value[0] = (void *)(&val); | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | va_start(args,type); |
/* cftimer_destroy wrapper. */ | | op = va_arg(args, object*); |
/*****************************************************************************/ | | cause = va_arg(args, object*); |
/* 0 - id */ | | va_end(args); |
/*****************************************************************************/ | | |
CFParm* CFWCFTimerDestroy(CFParm* PParm) | | |
{ | | |
CFParm* CFP; | | |
static int val; | | |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | |
val = cftimer_destroy(*(int *)(PParm->Value[0])); | | |
CFP->Value[0] = (void *)(&val); | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | rv = check_trigger(op,cause); |
/* SET_ANIMATION wrapper. */ | | *type = CFAPI_INT; |
/*****************************************************************************/ | | return &rv; |
/* 0 - object */ | | } |
/* 1 - face */ | | |
/*****************************************************************************/ | | void* cfapi_object_query_cost(int* type,...) |
CFParm* CFWSetAnimation (CFParm* PParm) | | |
{ | | { |
object* op=(object*)PParm->Value[0]; | | object* op; |
int face=*(int*)PParm->Value[1]; | | object* who; |
if (face!=-1) | | int flags; |
| | va_list args; |
| | static int rv; |
| | |
| | va_start(args, type); |
| | op = va_arg(args, object*); |
| | who = va_arg(args, object*); |
| | flags = va_arg(args, int); |
| | va_end(args); |
| | |
| | rv = query_cost(op,who,flags); |
| | *type = CFAPI_INT; |
| | return &rv; |
| | } |
| | |
| | void* cfapi_object_query_money(int* type,...) |
| | { |
| | object* op; |
| | va_list args; |
| | static int rv; |
| | |
| | va_start(args, type); |
| | op = va_arg(args, object*); |
| | va_end(args); |
| | |
| | rv = query_money(op); |
| | *type = CFAPI_INT; |
| | return &rv; |
| | } |
| | void* cfapi_object_cast(int* type,...) |
| | { |
| | object* op; |
| | object* sp; |
| | int dir; |
| | char* str; |
| | object* caster; |
| | va_list args; |
| | static int rv; |
| | va_start(args, type); |
| | op = va_arg(args, object*); |
| | caster = va_arg(args, object*); |
| | dir = va_arg(args,int); |
| | sp = va_arg(args, object*); |
| | str = va_arg(args, char*); |
| | va_end(args); |
| | rv = cast_spell(op, caster, dir, sp, str); |
| | *type = CFAPI_INT; |
| | return &rv; |
| | } |
| | void* cfapi_object_learn_spell(int* type,...) |
| | { |
| | object* op; |
| | object* sp; |
| | int prayer; |
| | va_list args; |
| | |
| | va_start(args, type); |
| | op = va_arg(args, object*); |
| | sp = va_arg(args, object*); |
| | prayer = va_arg(args, int); |
| | va_end(args); |
| | do_learn_spell(op,sp,prayer); |
| | *type = CFAPI_NONE; |
| | return NULL; |
| | } |
| | void* cfapi_object_forget_spell(int* type,...) |
| | { |
| | object* op; |
| | object* sp; |
| | va_list args; |
| | |
| | va_start(args, type); |
| | op = va_arg(args, object*); |
| | sp = va_arg(args, object*); |
| | va_end(args); |
| | do_forget_spell(op, query_name(sp)); |
| | *type = CFAPI_NONE; |
| | return NULL; |
| | } |
| | void* cfapi_object_check_spell(int* type,...) |
| | { |
| | object* op; |
| | char* spellname; |
| | va_list args; |
| | object* rv; |
| | |
| | va_start(args, type); |
| | op = va_arg(args, object*); |
| | spellname = va_arg(args, char*); |
| | va_end(args); |
| | rv = check_spell_known(op, spellname); |
| | *type = CFAPI_POBJECT; |
| | return rv; |
| | } |
| | void* cfapi_object_pay_amount(int* type,...) |
{ | | { |
SET_ANIMATION (op,face); | | object* op; |
| | uint64 amount; |
| | va_list args; |
| | static int rv; |
| | |
| | va_start(args, type); |
| | op = va_arg(args, object*); |
| | amount = va_arg(args, uint64); |
| | va_end(args); |
| | |
| | rv = pay_for_amount(amount,op); |
| | *type = CFAPI_INT; |
| | return &rv; |
| | } |
| | void* cfapi_object_pay_item(int* type,...) |
| | { |
| | object* op; |
| | object* tobuy; |
| | |
| | va_list args; |
| | static int rv; |
| | |
| | va_start(args, type); |
| | tobuy = va_arg(args, object*); |
| | op = va_arg(args, object*); |
| | va_end(args); |
| | |
| | rv = pay_for_item(tobuy, op); |
| | *type = CFAPI_INT; |
| | return &rv; |
| | } |
| | void* cfapi_object_transfer(int* type,...) |
| | { |
| | object* op; |
| | object* originator; |
| | int x,y, randompos, ttype; |
| | va_list args; |
| | static int rv=0; |
| | mapstruct* map; |
| | |
| | va_start(args, type); |
| | op = va_arg(args, object*); |
| | ttype = va_arg(args, int); |
| | printf("Transfer in progress\n"); |
| | switch (ttype) |
| | { |
| | case 0: |
| | x = va_arg(args, int); |
| | y = va_arg(args, int); |
| | randompos = va_arg(args, int); |
| | originator = va_arg(args, object*); |
| | va_end(args); |
| | |
| | rv = transfer_ob(op,x,y,randompos,originator); |
| | *type = CFAPI_INT; |
| | return &rv; |
| | break; |
| | case 1: |
| | x = va_arg(args, int); |
| | y = va_arg(args, int); |
| | map = va_arg(args, mapstruct*); |
| | va_end(args); |
| | if ((x<0)||(y<0)) |
| | { |
| | x = map->enter_x; |
| | y = map->enter_y; |
| | } |
| | /* originator = get_object(); |
| | EXIT_PATH(originator)=add_string(map->path); |
| | EXIT_X(originator)=x; |
| | EXIT_Y(originator)=y; |
| | printf("B Transfer: X=%d, Y=%d, OP=%s\n",x,y,op->name);*/ |
| | /*enter_exit(op,originator);*/ |
| | insert_ob_in_map_at(op, map, NULL, 0, x, y); |
| | /*printf("A Transfer: X=%d, Y=%d, MAP=%s\n",x,y,op->map->name); |
| | free_object(originator);*/ |
| | *type = CFAPI_INT; |
| | return &rv; |
| | break; |
} | | } |
update_object(op, UP_OBJ_FACE); | | |
return(NULL); | | |
} | | } |
| | |
/*****************************************************************************/ | | void* cfapi_object_find_archetype_inside(int* type,...) |
/* communicate wrapper. */ | | { |
/*****************************************************************************/ | | object* op; |
/* 0 - object */ | | int critera; |
/* 1 - string */ | | char* str; |
/*****************************************************************************/ | | va_list args; |
CFParm* CFWCommunicate (CFParm* PParm) | | object* rv; |
| | |
| | va_start(args, type); |
| | op = va_arg(args, object*); |
| | critera = va_arg(args, int); |
| | |
| | switch(critera) |
| | { |
| | case 0: /* By name, either exact or from query_name */ |
| | str = va_arg(args, char*); |
| | rv = present_arch_in_ob(find_archetype(str),op); |
| | if (rv == NULL) |
{ | | { |
char buf[MAX_BUF]; | | object* tmp; |
object* op=(object*)PParm->Value[0]; | | /* Search by query_name instead */ |
char* string=(char*)PParm->Value[1]; | | for(tmp = op->inv; tmp; tmp = tmp->below) |
if ((!op) || (!string)) return NULL; | | |
sprintf(buf, "%s says: ",op->name); | | |
strncat(buf, string, MAX_BUF - strlen(buf)-1); | | |
buf[MAX_BUF-1]=0; | | |
new_info_map(NDI_WHITE,op->map, buf); | | |
communicate (op,string); | | |
return NULL; | | |
} | | |
| | |
/*****************************************************************************/ | | |
/* find_best_object_match wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - object to find object in inventory */ | | |
/* 1 - name */ | | |
/*****************************************************************************/ | | |
CFParm* CFWFindBestObjectMatch (CFParm* PParm) | | |
{ | | { |
CFParm* CFP; | | if (!strncmp(query_name(tmp),str,strlen(str))) |
object* op=(object*)PParm->Value[0]; | | rv = tmp; |
char* param=(char*)PParm->Value[1]; | | if (!strncmp(tmp->name,str,strlen(str))) |
object* result; | | rv = tmp; |
result=(object*)find_best_object_match(op,param); | | if (rv != NULL) break; |
CFP = (CFParm*)(malloc(sizeof(CFParm))); | | } |
CFP->Value[0] = (void*) result; | | } |
| | break; |
| | default: |
| | break; |
| | } |
| | va_end(args); |
| | |
return(CFP); | | *type = CFAPI_POBJECT; |
| | return rv; |
} | | } |
| | |
/*****************************************************************************/ | | void* cfapi_object_drop(int* type,...) |
/* player_apply_below wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - object player */ | | |
/*****************************************************************************/ | | |
CFParm* CFWApplyBelow (CFParm* PParm) | | |
{ | | { |
object* op=(object*)PParm->Value[0]; | | object* op; |
if (!op) return NULL; | | object* author; |
player_apply_below (op); | | va_list args; |
return NULL; | | |
} | | |
| | |
/*****************************************************************************/ | | va_start(args, type); |
/* free_object wrapper. */ | | op = va_arg(args, object*); |
/*****************************************************************************/ | | author = va_arg(args, object*); |
/* 0 - object */ | | va_end(args); |
/*****************************************************************************/ | | |
CFParm* CFWFreeObject (CFParm* PParm) | | if (QUERY_FLAG(op, FLAG_NO_DROP)) return NULL; |
| | drop(author,op); |
| | |
| | if (author->type==PLAYER) |
{ | | { |
object* op=(object*)PParm->Value[0]; | | author->contr->count=0; |
if (op) free_object(op); | | author->contr->socket.update_look=1; |
return NULL; | | |
} | | } |
| | |
/*****************************************************************************/ | | *type = CFAPI_NONE; |
/* fix_player wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - object */ | | |
/*****************************************************************************/ | | |
CFParm* CFWFixPlayer (CFParm* PParm) | | |
{ | | |
object* op=(object*)PParm->Value[ 0 ]; | | |
if (op) fix_player(op); | | |
return NULL; | | return NULL; |
} | | } |
| | |
/*****************************************************************************/ | | void* cfapi_object_take(int* type,...) |
/* free wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - pointer */ | | |
/*****************************************************************************/ | | |
CFParm* CFWFreeMemory(CFParm* PParm) | | |
{ | | { |
void* op = PParm->Value[ 0 ]; | | object *op; |
if (op) free(op); | | object *author; |
| | va_list args; |
| | |
| | va_start(args, type); |
| | op = va_arg(args, object*); |
| | author = va_arg(args, object*); |
| | va_end(args); |
| | pick_up(author,op); |
| | |
| | *type = CFAPI_NONE; |
return NULL; | | return NULL; |
} | | } |
| | |
/*****************************************************************************/ | | void* cfapi_object_say(int* type,...) |
/* object_create_clone object_copy wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - object */ | | |
/* 1 - type 0 = clone with inventory */ | | |
/* 1 = only duplicate the object without its content and op->more */ | | |
/*****************************************************************************/ | | |
CFParm* CFWObjectCreateClone (CFParm* PParm) | | |
{ | | |
CFParm* CFP=(CFParm*)malloc(sizeof (CFParm)); | | |
if (*(int*)PParm->Value[1]==0) | | |
CFP->Value[0]=object_create_clone ((object*)PParm->Value[0]); | | |
else if (*(int*)PParm->Value[1]==1) | | |
{ | | { |
object* tmp; | | static int rv; |
tmp = get_object(); | | object* op; |
copy_object((object*)PParm->Value[0],tmp); | | char* msg; |
CFP->Value[0]=tmp; | | va_list args; |
| | |
| | va_start(args, type); |
| | op = va_arg(args, object*); |
| | msg = va_arg(args, char*); |
| | va_end(args); |
| | |
| | rv = command_say (op, msg); |
| | *type = CFAPI_INT; |
| | return &rv; |
} | | } |
return CFP; | | void* cfapi_object_speak(int* type,...) |
| | { |
| | static int rv; |
| | object* op; |
| | char* msg; |
| | va_list args; |
| | static char buf[MAX_BUF]; |
| | |
| | va_start(args, type); |
| | op = va_arg(args, object*); |
| | msg = va_arg(args, char*); |
| | va_end(args); |
| | |
| | if ((!op) || (!msg)) |
| | return NULL; |
| | sprintf(buf, "%s says: ",op->name); |
| | strncat(buf, msg, MAX_BUF - strlen(buf)-1); |
| | buf[MAX_BUF-1]=0; |
| | new_info_map(NDI_WHITE,op->map, buf); |
| | communicate(op, msg); |
| | *type = CFAPI_NONE; |
| | return NULL; |
} | | } |
| | /* PLAYER SUBCLASS */ |
| | void* cfapi_player_find(int* type, ...) |
| | { |
| | va_list args; |
| | void* rv; |
| | char* sval; |
| | va_start(args,type); |
| | |
/*****************************************************************************/ | | sval = va_arg(args, char*); |
/* set_variable wrapper -- Sets a variable in a given object. */ | | va_end(args); |
/*****************************************************************************/ | | |
/* 0 - object to change */ | | rv = find_player(sval); |
/* 1 - string describing the change to make. */ | | |
/*****************************************************************************/ | | *type = CFAPI_PPLAYER; |
CFParm* CFWSetVariable(CFParm* PParm) | | return rv; |
| | } |
| | void* cfapi_player_message(int* type, ...) |
{ | | { |
set_variable((object*)(PParm->Value[0]), (char *)(PParm->Value[1])); | | va_list args; |
| | int flags; |
| | int pri; |
| | object* pl; |
| | char* buf; |
| | |
| | va_start(args,type); |
| | |
| | flags = va_arg(args, int); |
| | pri = va_arg(args, int); |
| | pl = va_arg(args, object*); |
| | buf = va_arg(args, char*); |
| | va_end(args); |
| | |
| | new_draw_info(flags, pri, pl, buf); |
| | *type = CFAPI_NONE; |
return NULL; | | return NULL; |
} | | } |
| | void *cfapi_player_send_inventory(int *type, ...) |
/*****************************************************************************/ | | |
/* decrease_ob_nr wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - object to change */ | | |
/* 1 - nrof */ | | |
/*****************************************************************************/ | | |
CFParm* CFWDecreaseObjectNR(CFParm* PParm) | | |
{ | | { |
CFParm* CFP=(CFParm*)malloc(sizeof (CFParm)); | | /* Currently a stub. Do we really need this anymore ? */ |
object* op=(object*)PParm->Value[0]; | | *type = CFAPI_NONE; |
int i=*(int*)PParm->Value[1]; | | return NULL; |
object* ob; | | |
| | |
ob = decrease_ob_nr (op, i); | | |
CFP->Value[0] = ob; | | |
return CFP; | | |
} | | } |
| | |
/*****************************************************************************/ | | void* cfapi_object_teleport(int *type, ...) |
/* teleport an object to another map */ | | |
/*****************************************************************************/ | | |
/* 0 - object */ | | |
/* 1 - map structure */ | | |
/* 2 - mapx */ | | |
/* 3 - mapy */ | | |
/* return value: */ | | |
/* 0: ok */ | | |
/* 1: can't find a free spot */ | | |
/* 2: out of map */ | | |
/*****************************************************************************/ | | |
CFParm* CFWTeleportObject (CFParm* PParm) | | |
{ | | { |
mapstruct* map; | | mapstruct* map; |
int x, y; | | int x, y; |
object* who; | | object* who; |
CFParm* CFP=(CFParm*)malloc(sizeof (CFParm)); | | |
static int result; | | static int result; |
object* env; | | va_list args; |
| | |
who = ( object* )PParm->Value[ 0 ]; | | va_start(args,type); |
map = ( mapstruct* )PParm->Value[ 1 ]; | | who = va_arg(args, object*); |
x = *( int* )PParm->Value[ 2 ]; | | map = va_arg(args, mapstruct*); |
y = *( int* )PParm->Value[ 3 ]; | | x = va_arg(args,int); |
env = who->env; | | y = va_arg(args,int); |
| | |
CFP->Value[ 0 ] = (void *)&result; | | if (!out_of_map( map,x,y )) |
if ( ( out_of_map( map,x,y ) ) == 0 ) | | |
{ | | { |
int k; | | int k; |
object *tmp; | | object *tmp; |
| | |
if (k==-1) | | if (k==-1) |
{ | | { |
result = 1; | | result = 1; |
return CFP; | | return &result; |
} | | } |
| | |
remove_ob( who ); | | remove_ob( who ); |
| | |
| | |
insert_ob_in_map( who, map, NULL, 0 ); | | insert_ob_in_map( who, map, NULL, 0 ); |
result = 0; | | result = 0; |
if ( env->type == PLAYER && env->contr ) | | |
esrv_del_item(env->contr,who->count); | | |
}; | | |
| | |
return CFP; | | |
} | | } |
| | |
/*****************************************************************************/ | | return &result; |
/* check_trigger wrapper. */ | | } |
/*****************************************************************************/ | | void* cfapi_object_pickup(int *type, ...) |
/* 0 - item to check */ | | |
/* 1 - cause */ | | |
/*****************************************************************************/ | | |
CFParm* CFWCheckTrigger(CFParm* PParm) | | |
{ | | |
check_trigger( ( object* )( PParm->Value[ 0 ] ), ( object* )( PParm->Value[ 1 ] ) ); | | |
return NULL; | | |
}; | | |
| | |
/*****************************************************************************/ | | |
/* out_of_map wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - map */ | | |
/* 1 - x */ | | |
/* 2 - y */ | | |
/*****************************************************************************/ | | |
CFParm* CFWOutOfMap(CFParm* PParm) | | |
{ | | { |
static int val; | | object* who; |
CFParm* CFP = (CFParm*)malloc(sizeof (CFParm)); | | object* what; |
val = out_of_map( ( mapstruct* )PParm->Value[ 0 ], *( int* )PParm->Value[ 1 ], *( int* )PParm->Value[ 2 ] ); | | va_list args; |
CFP->Value[ 0 ] = ( void* )&val; | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | va_start(args, type); |
/* query_name wrapper. */ | | who = va_arg(args, object*); |
/*****************************************************************************/ | | what = va_arg(args, object*); |
/* 0 - item */ | | va_end(args); |
/*****************************************************************************/ | | |
CFParm* CFWQueryName(CFParm* PParm) | | |
{ | | |
CFParm* CFP = (CFParm*)malloc(sizeof (CFParm)); | | |
CFP->Value[ 0 ] = query_name( ( object* )PParm->Value[ 0 ] ); | | |
return CFP; | | |
}; | | |
| | |
| | pick_up(who,what); |
| | *type = CFAPI_NONE; |
| | return NULL; |
| | } |
/*****************************************************************************/ | | /*****************************************************************************/ |
/* query_base_name wrapper. */ | | /* NEW PLUGIN STUFF ENDS HERE */ |
/*****************************************************************************/ | | |
/* 0 - item */ | | |
/* 1 - plural */ | | |
/*****************************************************************************/ | | /*****************************************************************************/ |
CFParm* CFWQueryBaseName(CFParm* PParm) | | |
{ | | |
CFParm* CFP = (CFParm*)malloc(sizeof (CFParm)); | | |
CFP->Value[ 0 ] = (char*)query_base_name( ( object* )PParm->Value[ 0 ], *( int* )PParm->Value[ 1 ] ); | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | |
/* insert_ob_ino_b wrapper. */ | | |
/*****************************************************************************/ | | |
/* 0 - item */ | | |
/* 1 - plural */ | | |
/*****************************************************************************/ | | |
CFParm* CFWInsertObInOb(CFParm* PParm) | | |
{ | | |
CFParm* CFP = (CFParm*)malloc(sizeof (CFParm)); | | |
CFP->Value[ 0 ] = ( void* )insert_ob_in_ob( ( object* )PParm->Value[ 0 ], ( object* )PParm->Value[ 1 ] ); | | |
return CFP; | | |
}; | | |
| | |
/*****************************************************************************/ | | /*****************************************************************************/ |
/* Returns the settings variable. */ | | /* Tries to find if a given command is handled by a plugin. */ |
/*****************************************************************************/ | | /* Note that find_plugin_command is called *before* the internal commands are*/ |
/* no parameter */ | | /* checked, meaning that you can "overwrite" them. */ |
/*****************************************************************************/ | | /*****************************************************************************/ |
CFParm* CFWGetSettings(CFParm* PParm) | | CommArray_s *find_plugin_command(char *cmd, object *op) |
{ | | |
CFParm* CFP = (CFParm*)malloc(sizeof (CFParm)); | | |
CFP->Value[ 0 ] = ( void* )&settings; | | |
return CFP; | | |
}; | | |
| | |
| | |
CFParm* CFWGetMapFlags(CFParm* PParm) | | |
{ | | |
static sint16 nx, ny; | | |
static mapstruct* newmap; | | |
static val; | | |
CFParm* CFP = (CFParm*)malloc(sizeof (CFParm)); | | |
| | |
val = get_map_flags( | | |
( mapstruct* )PParm->Value[ 0 ], | | |
&newmap, | | |
*( sint16* )PParm->Value[ 1 ], | | |
*( sint16* )PParm->Value[ 2 ], | | |
&nx, | | |
&ny ); | | |
| | |
CFP->Value[ 0 ] = ( void* )&val; | | |
CFP->Value[ 1 ] = ( void* )&newmap; | | |
CFP->Value[ 2 ] = ( void* )&nx; | | |
CFP->Value[ 3 ] = ( void* )&ny; | | |
return CFP; | | |
} | | |
| | |
CFParm* CFWReCmp(CFParm* PParm) | | |
{ | | |
CFParm* CFP = (CFParm*)malloc(sizeof (CFParm)); | | |
CFP->Value[ 0 ] = ( void* )re_cmp( PParm->Value[ 0 ], PParm->Value[ 1 ] ); | | |
return CFP; | | |
} | | |
| | |
CFParm* CFWStrdupLocal(CFParm* PParm) | | |
{ | | |
CFParm* CFP = (CFParm*)malloc(sizeof (CFParm)); | | |
CFP->Value[ 0 ] = strdup_local( ( char* )PParm->Value[ 0 ] ); | | |
return CFP; | | |
} | | |
| | |
CFParm* CFWCreatePathname(CFParm* PParm) | | |
{ | | { |
CFParm* CFP = (CFParm*)malloc(sizeof (CFParm)); | | int i; |
CFP->Value[ 0 ] = ( void* )create_pathname( ( char* )PParm->Value[ 0 ] ); | | crossfire_plugin* cp; |
return CFP; | | CommArray_s* rtn_cmd; |
} | | |
| | |
CFParm* CFWUpdateObSpeed(CFParm* PParm) | | if (plugins_list == NULL) |
{ | | |
update_ob_speed( ( object* )PParm->Value[ 0 ] ); | | |
return NULL; | | return NULL; |
} | | |
| | |
CFParm* CFWPresentArchByName(CFParm* PParm) | | for(cp=plugins_list; cp != NULL; cp=cp->next) |
{ | | { |
int x, y; | | rtn_cmd = cp->propfunc(&i, "command?"); |
CFParm* CFP = (CFParm*)malloc(sizeof (CFParm)); | | return rtn_cmd; |
x = *( int* )PParm->Value[ 2 ]; | | |
y = *( int* )PParm->Value[ 1 ]; | | |
CFP->Value[ 0 ] = ( void* )present_arch( find_archetype( ( const char* )PParm->Value[ 0 ] ), ( mapstruct* )PParm->Value[ 1 ], x, y ); | | |
return CFP; | | |
} | | |
| | |
CFParm* CFWPresentArchNameInOb(CFParm* PParm) | | |
{ | | |
CFParm* CFP = (CFParm*)malloc(sizeof (CFParm)); | | |
CFP->Value[ 0 ] = present_arch_in_ob( find_archetype( PParm->Value[ 0 ] ), PParm->Value[ 1 ] ); | | |
return CFP; | | |
} | | } |
| | |
CFParm* CFWSetDirection(CFParm* PParm) | | |
{ | | |
object* who = ( object* )PParm->Value[ 0 ]; | | |
who->direction = ( char )PParm->Value[ 1 ]; | | |
SET_ANIMATION(who, who->direction); | | |
return NULL; | | return NULL; |
} | | } |
| | |
/*****************************************************************************/ | | /*****************************************************************************/ |
/* The following is not really a wrapper like the others are. */ | | /* Plugins initialization. Browses the plugins directory and call */ |
/* It is in fact used to allow the plugin to request the global events it */ | | /* initOnePlugin for each file found. */ |
/* wants to be aware of. All events can be seen as global; on the contrary, */ | | /* Returns 0 if at least one plugin was successfully loaded, -1 if not */ |
/* some events can't be used as local: for example, BORN is only global. */ | | |
/*****************************************************************************/ | | |
/* 0 - Number of the event to register; */ | | |
/* 1 - String ID of the requesting plugin. */ | | |
/*****************************************************************************/ | | /*****************************************************************************/ |
CFParm* RegisterGlobalEvent(CFParm* PParm) | | int initPlugins(void) |
{ | | { |
int PNR = findPlugin((char *)(PParm->Value[1])); | | struct dirent *currentfile; |
#ifdef LOG_VERBOSE | | DIR *plugdir; |
LOG(llevDebug,"Plugin %s (%i) registered the event %i\n",(char *)(PParm->Value[1]),PNR,*(int *)(PParm->Value[0])); | | int l; |
#endif | | char buf[MAX_BUF]; |
LOG(llevDebug,"Plugin %s (%i) registered the event %i\n",(char *)(PParm->Value[1]),PNR,*(int *)(PParm->Value[0])); | | char buf2[MAX_BUF]; |
PlugList[PNR].gevent[*(int *)(PParm->Value[0])] = 1; | | int result; |
return NULL; | | |
}; | | |
| | |
/*****************************************************************************/ | | LOG(llevInfo,"Initializing plugins\n"); |
/* The following unregisters a global event. */ | | strcpy(buf,LIBDIR); |
/*****************************************************************************/ | | strcat(buf,"/plugins/"); |
/* 0 - Number of the event to unregister; */ | | LOG(llevInfo,"Plugins directory is %s\n",buf); |
/* 1 - String ID of the requesting plugin. */ | | |
/*****************************************************************************/ | | |
CFParm* UnregisterGlobalEvent(CFParm* PParm) | | |
{ | | |
int PNR = findPlugin((char *)(PParm->Value[1])); | | |
PlugList[PNR].gevent[*(int *)(PParm->Value[0])] = 0; | | |
return NULL; | | |
}; | | |
| | |
/*****************************************************************************/ | | plugdir = opendir(buf); |
/* When a specific global event occurs, this function is called. */ | | if (plugdir == NULL) |
/* Concerns events: BORN, QUIT, LOGIN, LOGOUT, SHOUT, MUZZLE, KICK for now. */ | | return -1; |
/*****************************************************************************/ | | |
/* 0 - Number of the event */ | | result = -1; |
/*****************************************************************************/ | | while((currentfile = readdir(plugdir)) != NULL) |
void GlobalEvent(CFParm *PParm) | | |
{ | | { |
int i; | | l = strlen(currentfile->d_name); |
for(i=0;i<PlugNR;i++) | | if (l > strlen(PLUGIN_SUFFIX)) |
{ | | { |
if (PlugList[i].gevent[*(int *)(PParm->Value[0])] != 0) | | if (strcmp(currentfile->d_name+l-strlen(PLUGIN_SUFFIX), PLUGIN_SUFFIX) == 0) |
{ | | { |
/* That plugin registered the event ! Then we pass it the event */ | | strcpy(buf2,buf); |
(PlugList[i].eventfunc)(PParm); | | strcat(buf2,currentfile->d_name); |
}; | | LOG(llevInfo," -> Loading plugin : %s\n",currentfile->d_name); |
}; | | if (plugins_init_plugin(buf2) == 0) |
}; | | result = 0; |
| | } |
| | } |
| | } |
| | |
| | closedir(plugdir); |
| | return result; |
| | } |