ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/plugins.C
(Generate patch)

Comparing deliantra/server/server/plugins.C (file contents):
Revision 1.2 by root, Tue Aug 15 17:10:46 2006 UTC vs.
Revision 1.11 by root, Fri Sep 8 16:51:44 2006 UTC

1/* 1/*
2 * static char *rcsid_plugins_c = 2 * static char *rcsid_plugins_c =
3 * "$Id: plugins.C,v 1.2 2006/08/15 17:10:46 root Exp $"; 3 * "$Id: plugins.C,v 1.11 2006/09/08 16:51:44 root Exp $";
4 */ 4 */
5 5
6/*****************************************************************************/ 6/*****************************************************************************/
7/* CrossFire, A Multiplayer game for X-windows */ 7/* CrossFire, A Multiplayer game for X-windows */
8/* */ 8/* */
45 45
46#define NR_OF_HOOKS 74 46#define NR_OF_HOOKS 74
47 47
48static const hook_entry plug_hooks[NR_OF_HOOKS] = 48static const hook_entry plug_hooks[NR_OF_HOOKS] =
49{ 49{
50 {cfapi_system_add_string, 0, "cfapi_system_add_string"},
51 {cfapi_system_register_global_event, 1, "cfapi_system_register_global_event"}, 50 {cfapi_system_register_global_event, 1, "cfapi_system_register_global_event"},
52 {cfapi_system_remove_string, 2, "cfapi_system_remove_string"},
53 {cfapi_system_unregister_global_event, 3, "cfapi_system_unregister_global_event"}, 51 {cfapi_system_unregister_global_event, 3, "cfapi_system_unregister_global_event"},
54 {cfapi_system_check_path, 4, "cfapi_system_check_path"}, 52 {cfapi_system_check_path, 4, "cfapi_system_check_path"},
55 {cfapi_system_re_cmp, 5, "cfapi_system_re_cmp"}, 53 {cfapi_system_re_cmp, 5, "cfapi_system_re_cmp"},
56 {cfapi_system_strdup_local, 6, "cfapi_system_strdup_local"}, 54 {cfapi_system_strdup_local, 6, "cfapi_system_strdup_local"},
57 {cfapi_system_directory, 7, "cfapi_system_directory"}, 55 {cfapi_system_directory, 7, "cfapi_system_directory"},
127 125
128/*****************************************************************************/ 126/*****************************************************************************/
129/* NEW PLUGIN STUFF STARTS HERE */ 127/* NEW PLUGIN STUFF STARTS HERE */
130/*****************************************************************************/ 128/*****************************************************************************/
131 129
132static void plugin_load_original_map(mapstruct *map)
133{
134 execute_global_event (EVENT_MAPLOAD, map);
135}
136
137static void plugin_load_temporary_map(mapstruct *map)
138{
139 execute_global_event (EVENT_MAPIN, map);
140}
141
142static void plugin_clean_temporary_map(mapstruct *map)
143{
144 execute_global_event (EVENT_MAPCLEAN, map);
145}
146
147static void plugin_object_free(object *ob)
148{
149 execute_global_event (EVENT_FREE_OB, ob);
150}
151
152#ifdef WIN32 130#ifdef WIN32
153static const char *plugins_dlerror(void) 131static const char *plugins_dlerror(void)
154{ 132{
155 static char buf[256]; 133 static char buf[256];
156 DWORD err; 134 DWORD err;
224 } 202 }
225 if (tmp) 203 if (tmp)
226 esrv_del_item(tmp->contr, op->count); 204 esrv_del_item(tmp->contr, op->count);
227} 205}
228 206
229int execute_event(object* op, int eventcode, object* activator, object* third, const char* message, int fix)
230{
231 object *tmp, *next;
232 crossfire_plugin* plugin;
233 int rv = 0;
234 for (tmp = op->inv; tmp != NULL; tmp = next) {
235 next = tmp->below;
236 if (tmp->type == EVENT_CONNECTOR && tmp->subtype == eventcode) {
237#if 0
238 LOG(llevDebug, "********** EVENT HANDLER **********\n");
239 LOG(llevDebug, " - Who am I :%s\n", op->name);
240 if (activator != NULL)
241 LOG(llevDebug, " - Activator :%s\n", activator->name);
242 if (third != NULL)
243 LOG(llevDebug, " - Other object :%s\n", third->name);
244 LOG(llevDebug, " - Event code :%d\n", tmp->subtype);
245 if (tmp->title != NULL)
246 LOG(llevDebug, " - Event plugin :%s\n", tmp->title);
247 if (tmp->slaying != NULL)
248 LOG(llevDebug, " - Event hook :%s\n", tmp->slaying);
249 if (tmp->name != NULL)
250 LOG(llevDebug, " - Event options :%s\n", tmp->name);
251#endif
252
253 if (tmp->title == NULL) {
254 object *env = object_get_env_recursive(tmp);
255 LOG(llevError, "Event object without title at %d/%d in map %s\n", env->x, env->y, env->map->name);
256 send_removed_object(tmp);
257 remove_ob(tmp);
258 free_object(tmp);
259 } else if (tmp->slaying == NULL) {
260 object *env = object_get_env_recursive(tmp);
261 LOG(llevError, "Event object without slaying at %d/%d in map %s\n", env->x, env->y, env->map->name);
262 send_removed_object(tmp);
263 remove_ob(tmp);
264 free_object(tmp);
265 } else {
266 plugin = plugins_find_plugin(tmp->title);
267 if (plugin == NULL) {
268 object *env = object_get_env_recursive(tmp);
269 LOG(llevError, "The requested plugin doesn't exist: %s at %d/%d in map %s\n", tmp->title, env->x, env->y, env->map->name);
270 send_removed_object(tmp);
271 remove_ob(tmp);
272 free_object(tmp);
273 } else {
274 int rvt = 0;
275 int *rv;
276
277 rv = (int*) plugin->eventfunc(&rvt, op, eventcode, activator, third, message, fix, tmp->slaying, tmp->name, tmp);
278 return *rv;
279 }
280 }
281 }
282 }
283 return rv;
284}
285
286int execute_global_event(int eventcode, ...)
287{
288 va_list args;
289 object* op;
290 object* op2;
291 object* op3;
292 mapstruct *map;
293 player* pl;
294 char* buf;
295 int i, rt, retval = 0, *tmpretval = NULL, fix;
296 crossfire_plugin* cp;
297 if (plugins_list == NULL)
298 return -1;
299
300 va_start(args, eventcode);
301
302 switch (eventcode) {
303
304 case EVENT_CLOCK:
305 case EVENT_CRASH:
306 case EVENT_TELL:
307 /* no additional arguments */
308 for (cp = plugins_list; cp != NULL; cp = cp->next) {
309 if (cp->gevent[eventcode] != NULL)
310 cp->gevent[eventcode](&rt, eventcode);
311 }
312 break;
313
314 case EVENT_PLAYER_LOAD:
315 case EVENT_PLAYER_SAVE:
316 /* object, filename */
317 op = va_arg(args, object*);
318 buf = va_arg(args, char*);
319 for (cp = plugins_list; cp != NULL; cp = cp->next) {
320 if (cp->gevent[eventcode] != NULL)
321 cp->gevent[eventcode](&rt, eventcode, op, buf);
322 }
323 break;
324
325 case EVENT_MAPLOAD:
326 case EVENT_MAPOUT:
327 case EVENT_MAPIN:
328 case EVENT_MAPCLEAN:
329 /* map argument */
330 map = va_arg(args, mapstruct*);
331 for (cp = plugins_list; cp != NULL; cp = cp->next) {
332 if (cp->gevent[eventcode] != NULL)
333 cp->gevent[eventcode](&rt, eventcode, map);
334 }
335 break;
336
337 case EVENT_REMOVE:
338 case EVENT_MAPENTER:
339 case EVENT_MAPLEAVE:
340 case EVENT_BORN:
341 case EVENT_PLAYER_DEATH:
342 case EVENT_FREE_OB:
343 /* op argument */
344 op = va_arg(args, object*);
345 for (cp = plugins_list; cp != NULL; cp = cp->next) {
346 if (cp->gevent[eventcode] != NULL)
347 cp->gevent[eventcode](&rt, eventcode, op);
348 }
349 break;
350
351 case EVENT_GKILL:
352 /*GKILL: op, hitter*/
353 op = va_arg(args, object*);
354 op2 = va_arg(args, object*);
355 for (cp = plugins_list; cp != NULL; cp = cp->next) {
356 if (cp->gevent[eventcode] != NULL)
357 cp->gevent[eventcode](&rt, eventcode, op, op2);
358 }
359 break;
360
361 case EVENT_LOGIN:
362 /*LOGIN: pl, pl->socket.host*/
363 pl = va_arg(args, player*);
364 buf = va_arg(args, char*);
365 for (cp = plugins_list; cp != NULL; cp = cp->next) {
366 if (cp->gevent[eventcode] != NULL)
367 cp->gevent[eventcode](&rt, eventcode, pl, buf);
368 }
369 break;
370
371 case EVENT_LOGOUT:
372 /*LOGOUT: pl, pl->socket.host*/
373 pl = va_arg(args, player*);
374 buf = va_arg(args, char*);
375 for (cp = plugins_list; cp != NULL; cp = cp->next) {
376 if (cp->gevent[eventcode] != NULL)
377 cp->gevent[eventcode](&rt, eventcode, pl, buf);
378 }
379 break;
380
381 case EVENT_MAPRESET:
382 /*MAPRESET: map->path*/
383 buf = va_arg(args, char*);
384 for (cp = plugins_list; cp != NULL; cp = cp->next) {
385 if (cp->gevent[eventcode] != NULL)
386 cp->gevent[eventcode](&rt, eventcode, buf);
387 }
388 break;
389
390 case EVENT_SHOUT:
391 /*SHOUT: op, parms, priority*/
392 op = va_arg(args, object*);
393 buf = va_arg(args, char*);
394 i = va_arg(args, int);
395 for (cp = plugins_list; cp != NULL; cp = cp->next) {
396 if (cp->gevent[eventcode] != NULL)
397 cp->gevent[eventcode](&rt, eventcode, op, buf, i);
398 }
399 break;
400
401 case EVENT_MUZZLE:
402 /*MUZZLE: op, parms*/
403 op = va_arg(args, object*);
404 buf = va_arg(args, char*);
405 for (cp = plugins_list; cp != NULL; cp = cp->next) {
406 if (cp->gevent[eventcode] != NULL)
407 cp->gevent[eventcode](&rt, eventcode, op, buf);
408 }
409 break;
410
411 case EVENT_KICK:
412 /*KICK: op, parms*/
413 op = va_arg(args, object*);
414 buf = va_arg(args, char*);
415 for (cp = plugins_list; cp != NULL; cp = cp->next) {
416 if (cp->gevent[eventcode] != NULL)
417 cp->gevent[eventcode](&rt, eventcode, op, buf);
418 }
419 break;
420
421 case EVENT_FIND_UNARMED_SKILL:
422 op = va_arg(args, object*);
423 for (cp = plugins_list; cp != NULL; cp = cp->next) {
424 if (cp->gevent[eventcode] != NULL)
425 if ((tmpretval = (int*) cp->gevent[eventcode](&rt, eventcode, op)) && *tmpretval > 0) {
426 retval = *tmpretval;
427 }
428 }
429 break;
430
431 case EVENT_PLAYER_USE_SKILL:
432 case EVENT_MONSTER_USE_SKILL:
433 op = va_arg(args, object*);
434 op2 = va_arg(args, object*);
435 op3 = va_arg(args, object*);
436 fix = va_arg(args, int);
437 buf = va_arg(args, char*);
438 for (cp = plugins_list; cp != NULL; cp = cp->next) {
439 if (cp->gevent[eventcode] != NULL)
440 if ((tmpretval = (int*) cp->gevent[eventcode](&rt, eventcode, op, op2, op3, fix, buf)) && *tmpretval != 0) {
441 retval = *tmpretval;
442 }
443 }
444 break;
445
446 case EVENT_CAST_SPELL:
447 op = va_arg(args, object*);
448 op2 = va_arg(args, object*);
449 op3 = va_arg(args, object*);
450 fix = va_arg(args, int);
451 buf = va_arg(args, char*);
452 for (cp = plugins_list; cp != NULL; cp = cp->next) {
453 if (cp->gevent[eventcode] != NULL)
454 if ((tmpretval = (int*) cp->gevent[eventcode](&rt, eventcode, op, op2, op3, fix, buf)) && *tmpretval != 0) {
455 retval = *tmpretval;
456 break; /* The first who did something wins! */
457 }
458 }
459 break;
460
461 case EVENT_EXTCMD:
462 /*KICK: op, parms*/
463 pl = va_arg (args, player *);
464 buf = va_arg (args, char *);
465 i = va_arg (args, int);
466 for (cp = plugins_list; cp != NULL; cp = cp->next) {
467 if (cp->gevent[eventcode] != NULL)
468 cp->gevent[eventcode](&rt, eventcode, pl, buf, i, buf);
469 }
470 break;
471 }
472 va_end(args);
473
474 return retval;
475}
476
477extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr); 207extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr);
478extern "C" void *cfperl_getPluginProperty (int *type, ...); 208extern "C" void *cfperl_getPluginProperty (int *type, ...);
479extern "C" int cfperl_postInitPlugin (); 209extern "C" int cfperl_postInitPlugin ();
480extern "C" void *cfperl_eventListener (int *type, ...);
481extern "C" int cfperl_closePlugin (); 210extern "C" int cfperl_closePlugin ();
482 211
212// this is a temporary hack till the old plugin stuff is removed
483int plugins_init_perl() 213int plugins_init_perl()
484{ 214{
485 f_plug_init initfunc; 215 f_plug_init initfunc;
486 f_plug_api propfunc; 216 f_plug_api propfunc;
487 f_plug_api eventfunc;
488 f_plug_postinit postfunc; 217 f_plug_postinit postfunc;
489 f_plug_postinit closefunc; 218 f_plug_postinit closefunc;
490 int i; 219 int i;
491 crossfire_plugin* cp; 220 crossfire_plugin* cp;
492 crossfire_plugin* ccp; 221 crossfire_plugin* ccp;
493 222
494 load_original_map_callback = plugin_load_original_map;
495 load_temporary_map_callback = plugin_load_temporary_map;
496 clean_temporary_map_callback = plugin_clean_temporary_map;
497 object_free_callback = plugin_object_free;
498
499 initfunc = (f_plug_init)cfperl_initPlugin; 223 initfunc = (f_plug_init)cfperl_initPlugin;
500 propfunc = (f_plug_api)cfperl_getPluginProperty; 224 propfunc = (f_plug_api)cfperl_getPluginProperty;
501 eventfunc = (f_plug_api)cfperl_eventListener;
502 postfunc = (f_plug_postinit)cfperl_postInitPlugin; 225 postfunc = (f_plug_postinit)cfperl_postInitPlugin;
503 closefunc = (f_plug_postinit)cfperl_closePlugin; 226 closefunc = (f_plug_postinit)cfperl_closePlugin;
504 i = initfunc("2.0", cfapi_get_hooks); 227 i = initfunc("2.0", cfapi_get_hooks);
505 cp = (crossfire_plugin*) malloc(sizeof(crossfire_plugin)); 228 cp = (crossfire_plugin*) malloc(sizeof(crossfire_plugin));
506 for (i = 0; i < NR_EVENTS; i++) 229 for (i = 0; i < NR_EVENTS; i++)
507 cp->gevent[i] = NULL; 230 cp->gevent[i] = NULL;
508 cp->eventfunc = eventfunc; 231 cp->eventfunc = 0;
509 cp->propfunc = propfunc; 232 cp->propfunc = propfunc;
510 cp->closefunc = closefunc; 233 cp->closefunc = closefunc;
511 cp->libptr = 0; 234 cp->libptr = 0;
512 strcpy(cp->id, (const char*) propfunc(&i, "Identification")); 235 strcpy(cp->id, (const char*) propfunc(&i, "Identification"));
513 strcpy(cp->fullname, (const char*) propfunc(&i, "FullName")); 236 strcpy(cp->fullname, (const char*) propfunc(&i, "FullName"));
526 return 0; 249 return 0;
527} 250}
528 251
529int plugins_init_plugin(const char* libfile) 252int plugins_init_plugin(const char* libfile)
530{ 253{
254 return 0;
255
531 LIBPTRTYPE ptr; 256 LIBPTRTYPE ptr;
532 f_plug_init initfunc; 257 f_plug_init initfunc;
533 f_plug_api propfunc; 258 f_plug_api propfunc;
534 f_plug_api eventfunc; 259 f_plug_api eventfunc;
535 f_plug_postinit postfunc; 260 f_plug_postinit postfunc;
536 f_plug_postinit closefunc; 261 f_plug_postinit closefunc;
537 int i; 262 int i;
538 crossfire_plugin* cp; 263 crossfire_plugin* cp;
539 crossfire_plugin* ccp; 264 crossfire_plugin* ccp;
540
541 load_original_map_callback = plugin_load_original_map;
542 load_temporary_map_callback = plugin_load_temporary_map;
543 clean_temporary_map_callback = plugin_clean_temporary_map;
544 object_free_callback = plugin_object_free;
545 265
546 /* Open the plugin lib and load the required functions */ 266 /* Open the plugin lib and load the required functions */
547 ptr = plugins_dlopen(libfile); 267 ptr = plugins_dlopen(libfile);
548 if (ptr == NULL) { 268 if (ptr == NULL) {
549 LOG(llevError, "Error trying to load %s: %s\n", libfile, plugins_dlerror()); 269 LOG(llevError, "Error trying to load %s: %s\n", libfile, plugins_dlerror());
779 499
780 va_end(args); 500 va_end(args);
781 return NULL; 501 return NULL;
782} 502}
783 503
784void* cfapi_system_add_string(int *type, ...)
785{
786 va_list args;
787 const char* str;
788 char* rv;
789
790 va_start(args, type);
791 str = va_arg(args, char*);
792 va_end(args);
793
794 rv = (char*)add_string(str);
795 *type = CFAPI_STRING;
796 return rv;
797}
798
799void* cfapi_system_remove_string(int *type, ...)
800{
801 va_list args;
802 char* str;
803
804 va_start(args, type);
805 str = va_arg(args, char*);
806 va_end(args);
807
808 free_string(str);
809 *type = CFAPI_NONE;
810 return NULL;
811}
812void* cfapi_system_check_path(int* type, ...) 504void* cfapi_system_check_path(int* type, ...)
813{ 505{
814 va_list args; 506 va_list args;
815 static int rv; 507 static int rv;
816 char* name; 508 char* name;
1520 rv = query_name(op); 1212 rv = query_name(op);
1521 *type = CFAPI_STRING; 1213 *type = CFAPI_STRING;
1522 break; 1214 break;
1523 1215
1524 case CFAPI_OBJECT_PROP_NAME_PLURAL: 1216 case CFAPI_OBJECT_PROP_NAME_PLURAL:
1525 rv = (char*)op->name_pl; 1217 rv = (char*)&op->name_pl;
1526 *type = CFAPI_STRING; 1218 *type = CFAPI_STRING;
1527 break; 1219 break;
1528 1220
1529 case CFAPI_OBJECT_PROP_TITLE: 1221 case CFAPI_OBJECT_PROP_TITLE:
1530 rv = (char*)op->title; 1222 rv = (char*)&op->title;
1531 *type = CFAPI_STRING; 1223 *type = CFAPI_STRING;
1532 break; 1224 break;
1533 1225
1534 case CFAPI_OBJECT_PROP_RACE: 1226 case CFAPI_OBJECT_PROP_RACE:
1535 rv = (char*)op->race; 1227 rv = (char*)&op->race;
1536 *type = CFAPI_STRING; 1228 *type = CFAPI_STRING;
1537 break; 1229 break;
1538 1230
1539 case CFAPI_OBJECT_PROP_SLAYING: 1231 case CFAPI_OBJECT_PROP_SLAYING:
1540 rv = (char*)op->slaying; 1232 rv = (char*)&op->slaying;
1541 *type = CFAPI_STRING; 1233 *type = CFAPI_STRING;
1542 break; 1234 break;
1543 1235
1544 case CFAPI_OBJECT_PROP_SKILL: 1236 case CFAPI_OBJECT_PROP_SKILL:
1545 rv = (char*)op->skill; 1237 rv = (char*)&op->skill;
1546 *type = CFAPI_STRING; 1238 *type = CFAPI_STRING;
1547 break; 1239 break;
1548 1240
1549 case CFAPI_OBJECT_PROP_MESSAGE: 1241 case CFAPI_OBJECT_PROP_MESSAGE:
1550 rv = (char*)op->msg; 1242 rv = (char*)&op->msg;
1551 if (rv == NULL) 1243 if (rv == NULL)
1552 rv = (void*)""; 1244 rv = (void*)"";
1553 *type = CFAPI_STRING; 1245 *type = CFAPI_STRING;
1554 break; 1246 break;
1555 1247
1556 case CFAPI_OBJECT_PROP_LORE: 1248 case CFAPI_OBJECT_PROP_LORE:
1557 rv = (char*)op->lore; 1249 rv = (char*)&op->lore;
1558 *type = CFAPI_STRING; 1250 *type = CFAPI_STRING;
1559 break; 1251 break;
1560 1252
1561 case CFAPI_OBJECT_PROP_X: 1253 case CFAPI_OBJECT_PROP_X:
1562 ri = op->x; 1254 ri = op->x;
1642 case CFAPI_OBJECT_PROP_MATERIAL: 1334 case CFAPI_OBJECT_PROP_MATERIAL:
1643 ri = op->material; rv = &ri; 1335 ri = op->material; rv = &ri;
1644 *type = CFAPI_INT; 1336 *type = CFAPI_INT;
1645 break; 1337 break;
1646 1338
1647 case CFAPI_OBJECT_PROP_MATERIAL_NAME:
1648 rv = (char*)op->materialname;
1649 *type = CFAPI_STRING;
1650 break;
1651
1652 case CFAPI_OBJECT_PROP_MAGIC: 1339 case CFAPI_OBJECT_PROP_MAGIC:
1653 ri = op->magic; rv = &ri; 1340 ri = op->magic; rv = &ri;
1654 *type = CFAPI_INT; 1341 *type = CFAPI_INT;
1655 break; 1342 break;
1656 1343
1787 case CFAPI_OBJECT_PROP_OTHER_ARCH: 1474 case CFAPI_OBJECT_PROP_OTHER_ARCH:
1788 rv = op->other_arch; 1475 rv = op->other_arch;
1789 *type = CFAPI_PARCH; 1476 *type = CFAPI_PARCH;
1790 break; 1477 break;
1791 1478
1792 case CFAPI_OBJECT_PROP_CUSTOM_NAME:
1793 rv = (char*)op->custom_name;
1794 *type = CFAPI_STRING;
1795 break;
1796
1797 case CFAPI_OBJECT_PROP_ANIM_SPEED: 1479 case CFAPI_OBJECT_PROP_ANIM_SPEED:
1798 ri = op->anim_speed; rv = &ri; 1480 ri = op->anim_speed; rv = &ri;
1799 *type = CFAPI_INT; 1481 *type = CFAPI_INT;
1800 break; 1482 break;
1801 1483
1802 case CFAPI_OBJECT_PROP_FRIENDLY: 1484 case CFAPI_OBJECT_PROP_FRIENDLY:
1803 ri = is_friendly(op); 1485 ri = is_friendly(op);
1804 rv = &ri; 1486 rv = &ri;
1805 *type = CFAPI_INT; 1487 *type = CFAPI_INT;
1806 break;
1807
1808 case CFAPI_OBJECT_PROP_SHORT_NAME:
1809 rv = (char*)query_short_name(op);
1810 *type = CFAPI_STRING;
1811 break; 1488 break;
1812 1489
1813 case CFAPI_OBJECT_PROP_BASE_NAME: 1490 case CFAPI_OBJECT_PROP_BASE_NAME:
1814 { 1491 {
1815 int i; 1492 int i;
2015 rv = (char*)determine_god(op); 1692 rv = (char*)determine_god(op);
2016 *type = CFAPI_STRING; 1693 *type = CFAPI_STRING;
2017 break; 1694 break;
2018 1695
2019 case CFAPI_OBJECT_PROP_ARCH_NAME: 1696 case CFAPI_OBJECT_PROP_ARCH_NAME:
2020 rv = (char*)op->arch->name; 1697 rv = (char*)&op->arch->name;
2021 *type = CFAPI_STRING; 1698 *type = CFAPI_STRING;
2022 break; 1699 break;
2023 1700
2024 case CFAPI_OBJECT_PROP_INVISIBLE: 1701 case CFAPI_OBJECT_PROP_INVISIBLE:
2025 ri = op->invisible; 1702 ri = op->invisible;
2077 if (op != NULL && (!op->arch || (op != &op->arch->clone))) { 1754 if (op != NULL && (!op->arch || (op != &op->arch->clone))) {
2078 switch (property) 1755 switch (property)
2079 { 1756 {
2080 case CFAPI_OBJECT_PROP_NAME: 1757 case CFAPI_OBJECT_PROP_NAME:
2081 sarg = va_arg(args, char*); 1758 sarg = va_arg(args, char*);
1759#define FREE_AND_COPY(a,b) (a) = (b) // TODO: remove, but plugins.C is considered zombie code
2082 FREE_AND_COPY(op->name, sarg); 1760 FREE_AND_COPY(op->name, sarg);
2083 send_changed_object(op); 1761 send_changed_object(op);
2084 break; 1762 break;
2085 1763
2086 case CFAPI_OBJECT_PROP_NAME_PLURAL: 1764 case CFAPI_OBJECT_PROP_NAME_PLURAL:
2959 *type = CFAPI_NONE; 2637 *type = CFAPI_NONE;
2960 return NULL; 2638 return NULL;
2961} 2639}
2962void* cfapi_object_reset(int* type, ...) 2640void* cfapi_object_reset(int* type, ...)
2963{ 2641{
2964 va_list args; 2642abort ();
2965 object* op;
2966
2967 va_start(args, type);
2968
2969 op = va_arg(args, object*);
2970
2971 va_end(args);
2972
2973 reset_object(op);
2974 *type = CFAPI_NONE;
2975 return NULL;
2976} 2643}
2977 2644
2978void* cfapi_object_check_inventory(int* type, ...) 2645void* cfapi_object_check_inventory(int* type, ...)
2979{ 2646{
2980 va_list args; 2647 va_list args;
3335 *type = CFAPI_NONE; 3002 *type = CFAPI_NONE;
3336 return NULL; 3003 return NULL;
3337} 3004}
3338 3005
3339void* cfapi_object_say(int* type, ...) 3006void* cfapi_object_say(int* type, ...)
3340{ 3007{ abort(); }
3341 static int rv;
3342 object* op;
3343 char* msg;
3344 va_list args;
3345
3346 va_start(args, type);
3347 op = va_arg(args, object*);
3348 msg = va_arg(args, char*);
3349 va_end(args);
3350
3351 rv = command_say(op, msg);
3352 *type = CFAPI_INT;
3353 return &rv;
3354}
3355void* cfapi_object_speak(int* type, ...) 3008void* cfapi_object_speak(int* type, ...)
3356{ 3009{ abort(); }
3357 object* op;
3358 char* msg;
3359 va_list args;
3360 static char buf[MAX_BUF];
3361
3362 va_start(args, type);
3363 op = va_arg(args, object*);
3364 msg = va_arg(args, char*);
3365 va_end(args);
3366
3367 if (!op || !msg)
3368 return NULL;
3369 sprintf(buf, "%s says: ", op->name);
3370 strncat(buf, msg, MAX_BUF-strlen(buf)-1);
3371 buf[MAX_BUF-1]=0;
3372 new_info_map(NDI_WHITE, op->map, buf);
3373 communicate(op, msg);
3374 *type = CFAPI_NONE;
3375 return NULL;
3376}
3377/* PLAYER SUBCLASS */ 3010/* PLAYER SUBCLASS */
3378void* cfapi_player_find(int* type, ...) 3011void* cfapi_player_find(int* type, ...)
3379{ 3012{
3380 va_list args; 3013 va_list args;
3381 void* rv; 3014 void* rv;
3490 arch = va_arg(args, archetype*); 3123 arch = va_arg(args, archetype*);
3491 prop = va_arg(args, int); 3124 prop = va_arg(args, int);
3492 switch (prop) { 3125 switch (prop) {
3493 case CFAPI_ARCH_PROP_NAME: 3126 case CFAPI_ARCH_PROP_NAME:
3494 *type = CFAPI_STRING; 3127 *type = CFAPI_STRING;
3495 rv = (void*)arch->name; 3128 rv = (void*)&arch->name;
3496 break; 3129 break;
3497 3130
3498 case CFAPI_ARCH_PROP_NEXT: 3131 case CFAPI_ARCH_PROP_NEXT:
3499 *type = CFAPI_PARCH; 3132 *type = CFAPI_PARCH;
3500 rv = arch->next; 3133 rv = arch->next;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines