ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/plugins.C
Revision: 1.26
Committed: Tue Dec 19 05:12:52 2006 UTC (17 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.25: +1 -1 lines
Log Message:
- hide floorbox implementation details
- use meaning (hopefully) names

File Contents

# User Rev Content
1 elmex 1.1 /*****************************************************************************/
2     /* CrossFire, A Multiplayer game for X-windows */
3     /* */
4     /* Copyright (C) 2000 Mark Wedel */
5     /* Copyright (C) 1992 Frank Tore Johansen */
6     /* */
7     /* This program is free software; you can redistribute it and/or modify */
8     /* it under the terms of the GNU General Public License as published by */
9     /* the Free Software Foundation; either version 2 of the License, or */
10     /* (at your option) any later version. */
11     /* */
12     /* This program is distributed in the hope that it will be useful, */
13     /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
14     /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
15     /* GNU General Public License for more details. */
16     /* */
17     /* You should have received a copy of the GNU General Public License */
18     /* along with this program; if not, write to the Free Software */
19     /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20     /* */
21     /*****************************************************************************/
22     /* This is the server-side plugin management part. */
23     /*****************************************************************************/
24     /* Original code by Yann Chachkoff (yann.chachkoff@mailandnews.com). */
25     /* Special thanks to: */
26     /* David Delbecq (david.delbecq@mailandnews.com); */
27     /* Joris Bontje (jbontje@suespammers.org); */
28     /* Philip Currlin (?); */
29     /*****************************************************************************/
30     /*****************************************************************************/
31     /* First, the headers. We only include plugin.h, because all other includes */
32     /* are done into it, and plugproto.h (which is used only by this file). */
33 root 1.15 /*****************************************************************************/
34 root 1.12
35 elmex 1.1 #include <plugin.h>
36    
37     #ifndef __CEXTRACT__
38 root 1.12 # include <sproto.h>
39 elmex 1.1 #endif
40    
41     #define NR_OF_HOOKS 74
42    
43 root 1.12 static const hook_entry plug_hooks[NR_OF_HOOKS] = {
44     {cfapi_system_register_global_event, 1, "cfapi_system_register_global_event"},
45     {cfapi_system_unregister_global_event, 3, "cfapi_system_unregister_global_event"},
46     {cfapi_system_check_path, 4, "cfapi_system_check_path"},
47 pippijn 1.18 {NULL, 5, "cfapi_system_re_cmp"},
48 root 1.25 {cfapi_system_strdup, 6, "cfapi_system_strdup"},
49 root 1.12 {cfapi_system_directory, 7, "cfapi_system_directory"},
50     {cfapi_system_find_animation, 8, "cfapi_system_find_animation"},
51     {cfapi_object_clean_object, 9, "cfapi_object_clean_object"},
52     {cfapi_object_on_same_map, 10, "cfapi_object_on_same_map"},
53     {cfapi_object_get_key, 11, "cfapi_object_get_key"},
54     {cfapi_object_set_key, 12, "cfapi_object_set_key"},
55     {cfapi_object_get_property, 13, "cfapi_object_get_property"},
56     {cfapi_object_set_property, 14, "cfapi_object_set_property"},
57     {cfapi_object_apply, 15, "cfapi_object_apply"},
58     {cfapi_object_identify, 16, "cfapi_object_identify"},
59     {cfapi_object_describe, 17, "cfapi_object_describe"},
60     {cfapi_object_drain, 18, "cfapi_object_drain"},
61     {cfapi_object_fix, 19, "cfapi_object_fix"},
62     {cfapi_object_give_skill, 20, "cfapi_object_give_skill"},
63     {cfapi_object_transmute, 21, "cfapi_object_transmute"},
64     {cfapi_object_remove, 22, "cfapi_object_remove"},
65     {cfapi_object_delete, 23, "cfapi_object_delete"},
66     {cfapi_object_clone, 24, "cfapi_object_clone"},
67     {cfapi_object_find, 25, "cfapi_object_find"},
68     {cfapi_object_create, 26, "cfapi_object_create"},
69     {cfapi_object_insert, 27, "cfapi_object_insert"},
70     {cfapi_object_split, 28, "cfapi_object_split"},
71     {cfapi_object_merge, 29, "cfapi_object_merge"},
72     {cfapi_object_distance, 30, "cfapi_object_distance"},
73     {cfapi_object_update, 31, "cfapi_object_update"},
74     {cfapi_object_clear, 32, "cfapi_object_clear"},
75     {cfapi_object_reset, 33, "cfapi_object_reset"},
76     {cfapi_object_check_inventory, 34, "cfapi_object_check_inventory"},
77     {cfapi_object_spring_trap, 35, "cfapi_object_spring_trap"},
78     {cfapi_object_check_trigger, 36, "cfapi_object_check_trigger"},
79     {cfapi_object_query_cost, 37, "cfapi_object_query_cost"},
80     {cfapi_object_query_money, 38, "cfapi_object_query_money"},
81     {cfapi_object_cast, 39, "cfapi_object_cast"},
82     {cfapi_object_learn_spell, 40, "cfapi_object_learn_spell"},
83     {cfapi_object_forget_spell, 41, "cfapi_object_forget_spell"},
84     {cfapi_object_check_spell, 42, "cfapi_object_check_spell"},
85     {cfapi_object_pay_amount, 43, "cfapi_object_pay_amount"},
86     {cfapi_object_pay_item, 44, "cfapi_object_pay_item"},
87     {cfapi_object_transfer, 45, "cfapi_object_transfer"},
88     {cfapi_object_drop, 46, "cfapi_object_drop"},
89     {cfapi_object_take, 47, "cfapi_object_take"},
90     {cfapi_object_find_archetype_inside, 48, "cfapi_object_find_archetype_inside"},
91     {cfapi_object_say, 49, "cfapi_object_say"},
92     {cfapi_map_get_map, 50, "cfapi_map_get_map"},
93     {cfapi_map_has_been_loaded, 51, "cfapi_map_has_been_loaded"},
94     {cfapi_map_create_path, 52, "cfapi_map_create_path"},
95     {cfapi_map_get_map_property, 53, "cfapi_map_get_property"},
96     {cfapi_map_set_map_property, 54, "cfapi_map_set_property"},
97     {cfapi_map_out_of_map, 55, "cfapi_map_out_of_map"},
98     {cfapi_map_update_position, 56, "cfapi_map_update_position"},
99     {cfapi_map_delete_map, 57, "cfapi_map_delete_map"},
100     {cfapi_map_message, 58, "cfapi_map_message"},
101     {cfapi_map_get_object_at, 59, "cfapi_map_get_object_at"},
102     {cfapi_map_get_flags, 60, "cfapi_map_get_flags"},
103     {cfapi_map_present_arch_by_name, 61, "cfapi_map_present_arch_by_name"},
104     {cfapi_player_find, 62, "cfapi_player_find"},
105     {cfapi_player_message, 63, "cfapi_player_message"},
106     {cfapi_player_send_inventory, 64, "cfapi_player_send_inventory"},
107     {cfapi_object_teleport, 65, "cfapi_object_teleport"},
108     {cfapi_object_speak, 66, "cfapi_object_speak"},
109     {cfapi_object_pickup, 67, "cfapi_object_pickup"},
110     {cfapi_object_move, 68, "cfapi_object_move"},
111     {cfapi_object_apply_below, 69, "cfapi_object_apply_below"},
112     {cfapi_archetype_get_first, 70, "cfapi_archetype_get_first"},
113     {cfapi_archetype_get_property, 71, "cfapi_archetype_get_property"},
114     {cfapi_party_get_property, 72, "cfapi_party_get_property"},
115     {cfapi_region_get_property, 73, "cfapi_region_get_property"},
116 elmex 1.1 };
117     int plugin_number = 0;
118 root 1.12 crossfire_plugin *plugins_list = NULL;
119 elmex 1.1
120     /*****************************************************************************/
121 root 1.12
122 elmex 1.1 /* NEW PLUGIN STUFF STARTS HERE */
123 root 1.12
124 elmex 1.1 /*****************************************************************************/
125    
126     /**
127     * Notify clients about a changed object.
128     *
129     * @param op the object that has changed
130     */
131 root 1.12 static void
132     send_changed_object (object *op)
133 elmex 1.1 {
134 root 1.12 object *tmp;
135     player *pl;
136 elmex 1.1
137 root 1.12 if (op->env != NULL)
138     {
139     tmp = is_player_inv (op->env);
140     if (!tmp)
141     {
142     for (pl = first_player; pl; pl = pl->next)
143     if (pl->ob->container == op->env)
144     break;
145     if (pl)
146     tmp = pl->ob;
147     else
148     tmp = NULL;
149 elmex 1.1 }
150 root 1.12 if (tmp)
151     esrv_send_item (tmp, op);
152     }
153     else
154     {
155     for (tmp = op->above; tmp != NULL; tmp = tmp->above)
156     if (tmp->type == PLAYER)
157     esrv_send_item (tmp, op);
158 elmex 1.1 }
159     }
160    
161     /**
162     * Notify clients about a removed object.
163     *
164     * @param op the object about to be removed from its environment; it must still
165     * be present in its environment
166     */
167 root 1.12 static void
168     send_removed_object (object *op)
169 elmex 1.1 {
170 root 1.12 object *tmp;
171     player *pl;
172 elmex 1.1
173 root 1.12 if (op->env == NULL)
174     {
175     /* no action necessary: remove_ob() notifies the client */
176     return;
177 elmex 1.1 }
178    
179 root 1.12 tmp = is_player_inv (op->env);
180     if (!tmp)
181     {
182     for (pl = first_player; pl; pl = pl->next)
183     if (pl->ob->container == op->env)
184     break;
185     if (pl)
186     tmp = pl->ob;
187     else
188     tmp = NULL;
189 elmex 1.1 }
190 root 1.12 if (tmp)
191     esrv_del_item (tmp->contr, op->count);
192 elmex 1.1 }
193    
194 root 1.2 extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr);
195     extern "C" void *cfperl_getPluginProperty (int *type, ...);
196     extern "C" int cfperl_postInitPlugin ();
197     extern "C" int cfperl_closePlugin ();
198    
199 root 1.3 // this is a temporary hack till the old plugin stuff is removed
200 root 1.12 int
201     plugins_init_perl ()
202 root 1.2 {
203 root 1.12 f_plug_init initfunc;
204     f_plug_api propfunc;
205     f_plug_postinit postfunc;
206     f_plug_postinit closefunc;
207     int i;
208     crossfire_plugin *cp;
209     crossfire_plugin *ccp;
210    
211     initfunc = (f_plug_init) cfperl_initPlugin;
212     propfunc = (f_plug_api) cfperl_getPluginProperty;
213     postfunc = (f_plug_postinit) cfperl_postInitPlugin;
214     closefunc = (f_plug_postinit) cfperl_closePlugin;
215     i = initfunc ("2.0", cfapi_get_hooks);
216     cp = (crossfire_plugin *) malloc (sizeof (crossfire_plugin));
217     for (i = 0; i < NR_EVENTS; i++)
218     cp->gevent[i] = NULL;
219     cp->eventfunc = 0;
220     cp->propfunc = propfunc;
221     cp->closefunc = closefunc;
222     cp->libptr = 0;
223     strcpy (cp->id, (const char *) propfunc (&i, "Identification"));
224     strcpy (cp->fullname, (const char *) propfunc (&i, "FullName"));
225     cp->next = NULL;
226     cp->prev = NULL;
227     if (plugins_list == NULL)
228     {
229     plugins_list = cp;
230     }
231     else
232     {
233     for (ccp = plugins_list; ccp->next != NULL; ccp = ccp->next)
234     ;
235     ccp->next = cp;
236     cp->prev = ccp;
237     }
238     postfunc ();
239     plugin_number++;
240     return 0;
241     }
242    
243     int
244     plugins_init_plugin (const char *libfile)
245     {
246     return 0;
247    
248     LIBPTRTYPE ptr;
249     f_plug_init initfunc;
250     f_plug_api propfunc;
251     f_plug_api eventfunc;
252     f_plug_postinit postfunc;
253     f_plug_postinit closefunc;
254     int i;
255     crossfire_plugin *cp;
256     crossfire_plugin *ccp;
257    
258     /* Open the plugin lib and load the required functions */
259     ptr = plugins_dlopen (libfile);
260     if (ptr == NULL)
261     {
262     LOG (llevError, "Error trying to load %s: %s\n", libfile, plugins_dlerror ());
263     return -1;
264     }
265     initfunc = (f_plug_init) plugins_dlsym (ptr, "initPlugin");
266     if (initfunc == NULL)
267     {
268     LOG (llevError, "Plugin error while requesting %s.initPlugin: %s\n", libfile, plugins_dlerror ());
269     plugins_dlclose (ptr);
270     return -1;
271     }
272     propfunc = (f_plug_api) plugins_dlsym (ptr, "getPluginProperty");
273     if (propfunc == NULL)
274     {
275     LOG (llevError, "Plugin error while requesting %s.getPluginProperty: %s\n", libfile, plugins_dlerror ());
276     plugins_dlclose (ptr);
277     return -1;
278     }
279     eventfunc = (f_plug_api) plugins_dlsym (ptr, "eventListener");
280     if (eventfunc == NULL)
281     {
282     LOG (llevError, "Plugin error while requesting %s.eventListener: %s\n", libfile, plugins_dlerror ());
283     plugins_dlclose (ptr);
284     return -1;
285     }
286     postfunc = (f_plug_postinit) plugins_dlsym (ptr, "postInitPlugin");
287     if (postfunc == NULL)
288     {
289     LOG (llevError, "Plugin error while requesting %s.postInitPlugin: %s\n", libfile, plugins_dlerror ());
290     plugins_dlclose (ptr);
291     return -1;
292     }
293     closefunc = (f_plug_postinit) plugins_dlsym (ptr, "closePlugin");
294     if (postfunc == NULL)
295     {
296     LOG (llevError, "Plugin error while requesting %s.closePlugin: %s\n", libfile, plugins_dlerror ());
297     plugins_dlclose (ptr);
298     return -1;
299     }
300     i = initfunc ("2.0", cfapi_get_hooks);
301     cp = (crossfire_plugin *) malloc (sizeof (crossfire_plugin));
302     for (i = 0; i < NR_EVENTS; i++)
303     cp->gevent[i] = NULL;
304     cp->eventfunc = eventfunc;
305     cp->propfunc = propfunc;
306     cp->closefunc = closefunc;
307     cp->libptr = ptr;
308     strcpy (cp->id, (const char *) propfunc (&i, "Identification"));
309     strcpy (cp->fullname, (const char *) propfunc (&i, "FullName"));
310     cp->next = NULL;
311     cp->prev = NULL;
312     if (plugins_list == NULL)
313     {
314     plugins_list = cp;
315     }
316     else
317     {
318     for (ccp = plugins_list; ccp->next != NULL; ccp = ccp->next)
319     ;
320     ccp->next = cp;
321     cp->prev = ccp;
322     }
323     postfunc ();
324     plugin_number++;
325     return 0;
326     }
327    
328     void *
329     cfapi_get_hooks (int *type, ...)
330     {
331     va_list args;
332     int request_type;
333     char *buf;
334     int fid;
335     f_plug_api rv;
336     int i;
337    
338     va_start (args, type);
339     request_type = va_arg (args, int);
340    
341     if (request_type == 0)
342     { /* By nr */
343     fid = va_arg (args, int);
344    
345     if (fid < 0 || fid >= NR_OF_HOOKS)
346     {
347     rv = NULL;
348     *type = CFAPI_NONE;
349     }
350     else
351     {
352     rv = plug_hooks[fid].func;
353     *type = CFAPI_FUNC;
354 elmex 1.1 }
355 root 1.12 }
356     else
357     { /* by name */
358     buf = va_arg (args, char *);
359    
360     rv = NULL;
361     for (i = 0; i < NR_OF_HOOKS; i++)
362     {
363     if (!strcmp (buf, plug_hooks[i].fname))
364     {
365     rv = plug_hooks[i].func;
366     *type = CFAPI_FUNC;
367     break;
368 elmex 1.1 }
369     }
370 root 1.12 if (rv == NULL)
371     {
372     *type = CFAPI_NONE;
373 elmex 1.1 }
374     }
375 root 1.12 va_end (args);
376     return (void *) rv;
377 elmex 1.1 }
378    
379 root 1.12 int
380     plugins_remove_plugin (const char *id)
381 elmex 1.1 {
382 root 1.12 crossfire_plugin *cp;
383 elmex 1.1
384 root 1.12 if (plugins_list == NULL)
385     return -1;
386    
387     for (cp = plugins_list; cp != NULL; cp = cp->next)
388     {
389     if (!strcmp (id, cp->id) && cp->libptr)
390     {
391     crossfire_plugin *n;
392     crossfire_plugin *p;
393    
394     n = cp->next;
395     p = cp->prev;
396     plugins_dlclose (cp->libptr);
397     if (n != NULL)
398     {
399     if (p != NULL)
400     {
401     n->prev = p;
402     p->next = n;
403 elmex 1.1 }
404 root 1.12 else
405     {
406     n->prev = NULL;
407     plugins_list = n;
408     }
409     }
410     else
411     {
412     if (p != NULL)
413     p->next = NULL;
414     else
415     plugins_list = NULL;
416 elmex 1.1 }
417 root 1.12 free (cp);
418     plugin_number--;
419     return 0;
420 elmex 1.1 }
421     }
422 root 1.12 return -1;
423 elmex 1.1 }
424    
425 root 1.12 crossfire_plugin *
426     plugins_find_plugin (const char *id)
427 elmex 1.1 {
428 root 1.12 crossfire_plugin *cp;
429 elmex 1.1
430 root 1.12 if (plugins_list == NULL)
431     return NULL;
432 elmex 1.1
433 root 1.12 for (cp = plugins_list; cp != NULL; cp = cp->next)
434     {
435     if (!strcmp (id, cp->id))
436     {
437     return cp;
438 elmex 1.1 }
439     }
440 root 1.12 return NULL;
441 elmex 1.1 }
442    
443     /*****************************************************************************/
444 root 1.12
445 elmex 1.1 /* Displays a list of loaded plugins (keystrings and description) in the */
446 root 1.12
447 elmex 1.1 /* game log window. */
448 root 1.12
449 elmex 1.1 /*****************************************************************************/
450 root 1.12 void
451     plugins_display_list (object *op)
452 elmex 1.1 {
453 root 1.12 crossfire_plugin *cp;
454 elmex 1.1
455 root 1.12 new_draw_info (NDI_UNIQUE, 0, op, "List of loaded plugins:");
456     new_draw_info (NDI_UNIQUE, 0, op, "-----------------------");
457 elmex 1.1
458 root 1.12 if (plugins_list == NULL)
459     return;
460 elmex 1.1
461 root 1.12 for (cp = plugins_list; cp != NULL; cp = cp->next)
462     {
463     new_draw_info_format (NDI_UNIQUE, 0, op, "%s, %s", cp->id, cp->fullname);
464 elmex 1.1 }
465     }
466    
467     /* SYSTEM-RELATED HOOKS */
468    
469 root 1.12 void *
470     cfapi_system_find_animation (int *type, ...)
471     {
472     va_list args;
473     static int rv;
474     char *anim;
475    
476     va_start (args, type);
477     anim = va_arg (args, char *);
478    
479     va_end (args);
480    
481     rv = find_animation (anim);
482     *type = CFAPI_INT;
483     return &rv;
484     }
485    
486     void *
487 root 1.25 cfapi_system_strdup (int *type, ...)
488 root 1.12 {
489     va_list args;
490     char *txt;
491    
492     va_start (args, type);
493     txt = va_arg (args, char *);
494    
495     va_end (args);
496     *type = CFAPI_STRING;
497 root 1.25 return strdup (txt);
498 root 1.12 }
499    
500     void *
501     cfapi_system_register_global_event (int *type, ...)
502 elmex 1.1 {
503 root 1.12 va_list args;
504     int eventcode;
505     char *pname;
506     f_plug_api hook;
507     crossfire_plugin *cp;
508    
509     va_start (args, type);
510     eventcode = va_arg (args, int);
511     pname = va_arg (args, char *);
512    
513     hook = va_arg (args, f_plug_api);
514    
515     va_end (args);
516     cp = plugins_find_plugin (pname);
517     cp->gevent[eventcode] = hook;
518     return NULL;
519 elmex 1.1 }
520    
521 root 1.12 void *
522     cfapi_system_unregister_global_event (int *type, ...)
523 elmex 1.1 {
524 root 1.12 va_list args;
525     int eventcode;
526     char *pname;
527     crossfire_plugin *cp;
528 elmex 1.1
529 root 1.12 va_start (args, type);
530     eventcode = va_arg (args, int);
531     pname = va_arg (args, char *);
532 elmex 1.1
533 root 1.12 cp = plugins_find_plugin (pname);
534     cp->gevent[eventcode] = NULL;
535 elmex 1.1
536 root 1.12 va_end (args);
537     return NULL;
538 elmex 1.1 }
539    
540 root 1.12 void *
541     cfapi_system_check_path (int *type, ...)
542 elmex 1.1 {
543 root 1.12 va_list args;
544     static int rv;
545     char *name;
546     int prepend_dir;
547 elmex 1.1
548 root 1.12 va_start (args, type);
549 elmex 1.1
550 root 1.12 name = va_arg (args, char *);
551     prepend_dir = va_arg (args, int);
552 elmex 1.1
553 root 1.12 rv = check_path (name, prepend_dir);
554 elmex 1.1
555 root 1.12 va_end (args);
556     *type = CFAPI_INT;
557     return &rv;
558 elmex 1.1 }
559    
560 root 1.12 void *
561     cfapi_system_directory (int *type, ...)
562 elmex 1.1 {
563 root 1.12 va_list args;
564     int dirtype;
565    
566     va_start (args, type);
567 elmex 1.1
568 root 1.12 dirtype = va_arg (args, int);
569 elmex 1.1
570 root 1.12 va_end (args);
571 elmex 1.1
572 root 1.12 *type = CFAPI_STRING;
573 elmex 1.1
574 root 1.12 switch (dirtype)
575 elmex 1.1 {
576 root 1.12 case 0:
577     return settings.mapdir;
578     break;
579 elmex 1.1
580 root 1.12 case 1:
581     return settings.uniquedir;
582     break;
583 elmex 1.1
584 root 1.12 case 2:
585     return settings.tmpdir;
586     break;
587 elmex 1.1
588 root 1.12 case 3:
589     return settings.confdir;
590     break;
591 elmex 1.1
592 root 1.12 case 4:
593     return settings.localdir;
594     break;
595 elmex 1.1
596 root 1.12 case 5:
597     return settings.playerdir;
598     break;
599 elmex 1.1
600 root 1.12 case 6:
601     return settings.datadir;
602     break;
603 elmex 1.1 }
604    
605 root 1.12 *type = CFAPI_NONE;
606     return NULL;
607 elmex 1.1 }
608    
609    
610     /* MAP RELATED HOOKS */
611    
612 root 1.12 void *
613     cfapi_map_get_map (int *type, ...)
614 elmex 1.1 {
615 root 1.12 va_list args;
616 root 1.16 maptile *rv;
617 root 1.12 int ctype;
618     int x, y;
619     sint16 nx, ny;
620     char *name;
621 root 1.16 maptile *m;
622 root 1.12
623     va_start (args, type);
624    
625     ctype = va_arg (args, int);
626    
627     switch (ctype)
628     {
629     case 0:
630     x = va_arg (args, int);
631     y = va_arg (args, int);
632    
633     rv = get_empty_map (x, y);
634     break;
635    
636     case 1:
637     name = va_arg (args, char *);
638     x = va_arg (args, int);
639    
640     rv = ready_map_name (name, x);
641     break;
642    
643     case 2:
644 root 1.16 m = va_arg (args, maptile *);
645 root 1.12 nx = va_arg (args, int);
646     ny = va_arg (args, int);
647    
648     rv = get_map_from_coord (m, &nx, &ny);
649     break;
650    
651     case 3:
652     rv = first_map;
653     break;
654    
655     default:
656     *type = CFAPI_NONE;
657     va_end (args);
658     return NULL;
659     break;
660     }
661     va_end (args);
662     *type = CFAPI_PMAP;
663     return rv;
664     }
665    
666     void *
667     cfapi_map_has_been_loaded (int *type, ...)
668     {
669     va_list args;
670 root 1.16 maptile *map;
671 root 1.12 char *string;
672    
673     va_start (args, type);
674     string = va_arg (args, char *);
675    
676     map = has_been_loaded (string);
677     va_end (args);
678     *type = CFAPI_PMAP;
679     return map;
680     }
681    
682     void *
683     cfapi_map_create_path (int *type, ...)
684     {
685     va_list args;
686     int ctype;
687     const char *str;
688     char *rv;
689    
690     va_start (args, type);
691    
692     ctype = va_arg (args, int);
693     str = va_arg (args, char *);
694    
695     *type = CFAPI_STRING;
696    
697     switch (ctype)
698     {
699     case 0:
700     rv = (char *) create_pathname (str);
701     break;
702    
703     case 1:
704     rv = (char *) create_overlay_pathname (str);
705     break;
706    
707     /*case 2:
708     rv = create_items_path(str);
709     break; */
710    
711     default:
712     rv = NULL;
713     *type = CFAPI_NONE;
714     break;
715     }
716     va_end (args);
717     return rv;
718     }
719    
720     void *
721     cfapi_map_get_map_property (int *type, ...)
722     {
723     va_list args;
724     int x, y;
725     sint16 nx, ny;
726 root 1.16 maptile *map;
727     maptile *newmap;
728 root 1.12 static int rv;
729     int property;
730     char *buf;
731    
732     va_start (args, type);
733    
734     property = va_arg (args, int);
735    
736     switch (property)
737     {
738     case CFAPI_MAP_PROP_FLAGS:
739 root 1.16 map = va_arg (args, maptile *);
740     newmap = va_arg (args, maptile *);
741 root 1.12 x = va_arg (args, int);
742     y = va_arg (args, int);
743     nx = va_arg (args, int);
744     ny = va_arg (args, int);
745    
746     rv = get_map_flags (map, &newmap, x, y, &nx, &ny);
747     va_end (args);
748     *type = CFAPI_INT;
749     return &rv;
750     break;
751    
752     case CFAPI_MAP_PROP_DIFFICULTY:
753 root 1.16 map = va_arg (args, maptile *);
754 root 1.12
755     rv = calculate_difficulty (map);
756     va_end (args);
757     *type = CFAPI_INT;
758     return &rv;
759     break;
760    
761     case CFAPI_MAP_PROP_PATH:
762 root 1.16 map = va_arg (args, maptile *);
763 root 1.12
764     buf = map->path;
765     *type = CFAPI_STRING;
766     va_end (args);
767     return buf;
768     break;
769    
770     case CFAPI_MAP_PROP_TMPNAME:
771 root 1.16 map = va_arg (args, maptile *);
772 root 1.12
773     buf = map->tmpname;
774     *type = CFAPI_STRING;
775     va_end (args);
776     return buf;
777     break;
778    
779     case CFAPI_MAP_PROP_NAME:
780 root 1.16 map = va_arg (args, maptile *);
781 root 1.12
782     buf = map->name;
783     *type = CFAPI_STRING;
784     va_end (args);
785     return buf;
786     break;
787    
788     case CFAPI_MAP_PROP_RESET_TIME:
789 root 1.16 map = va_arg (args, maptile *);
790 root 1.12
791     rv = map->reset_time;
792     *type = CFAPI_INT;
793     va_end (args);
794     return &rv;
795     break;
796    
797     case CFAPI_MAP_PROP_RESET_TIMEOUT:
798 root 1.16 map = va_arg (args, maptile *);
799 root 1.12
800     rv = map->reset_timeout;
801     *type = CFAPI_INT;
802     va_end (args);
803     return &rv;
804     break;
805    
806     case CFAPI_MAP_PROP_PLAYERS:
807 root 1.16 map = va_arg (args, maptile *);
808 root 1.12
809     rv = map->players;
810     *type = CFAPI_INT;
811     va_end (args);
812     return &rv;
813     break;
814    
815     case CFAPI_MAP_PROP_DARKNESS:
816 root 1.16 map = va_arg (args, maptile *);
817 root 1.12
818     rv = map->darkness;
819     *type = CFAPI_INT;
820     va_end (args);
821     return &rv;
822     break;
823    
824     case CFAPI_MAP_PROP_WIDTH:
825 root 1.16 map = va_arg (args, maptile *);
826 root 1.12
827     rv = map->width;
828     *type = CFAPI_INT;
829     va_end (args);
830     return &rv;
831     break;
832    
833     case CFAPI_MAP_PROP_HEIGHT:
834 root 1.16 map = va_arg (args, maptile *);
835 root 1.12
836     rv = map->height;
837     *type = CFAPI_INT;
838     va_end (args);
839     return &rv;
840     break;
841    
842     case CFAPI_MAP_PROP_ENTER_X:
843 root 1.16 map = va_arg (args, maptile *);
844 root 1.12
845     rv = map->enter_x;
846     *type = CFAPI_INT;
847     va_end (args);
848     return &rv;
849     break;
850    
851     case CFAPI_MAP_PROP_ENTER_Y:
852 root 1.16 map = va_arg (args, maptile *);
853 root 1.12
854     rv = map->enter_y;
855     *type = CFAPI_INT;
856     va_end (args);
857     return &rv;
858     break;
859    
860     case CFAPI_MAP_PROP_TEMPERATURE:
861 root 1.16 map = va_arg (args, maptile *);
862 root 1.12
863     rv = map->temp;
864     *type = CFAPI_INT;
865     va_end (args);
866     return &rv;
867     break;
868    
869     case CFAPI_MAP_PROP_PRESSURE:
870 root 1.16 map = va_arg (args, maptile *);
871 root 1.12
872     rv = map->pressure;
873     *type = CFAPI_INT;
874     va_end (args);
875     return &rv;
876     break;
877    
878     case CFAPI_MAP_PROP_HUMIDITY:
879 root 1.16 map = va_arg (args, maptile *);
880 root 1.12
881     rv = map->humid;
882     *type = CFAPI_INT;
883     va_end (args);
884     return &rv;
885     break;
886    
887     case CFAPI_MAP_PROP_WINDSPEED:
888 root 1.16 map = va_arg (args, maptile *);
889 root 1.12
890     rv = map->windspeed;
891     *type = CFAPI_INT;
892     va_end (args);
893     return &rv;
894     break;
895    
896     case CFAPI_MAP_PROP_WINDDIR:
897 root 1.16 map = va_arg (args, maptile *);
898 root 1.12
899     rv = map->winddir;
900     *type = CFAPI_INT;
901     va_end (args);
902     return &rv;
903     break;
904    
905     case CFAPI_MAP_PROP_SKY:
906 root 1.16 map = va_arg (args, maptile *);
907 root 1.12
908     rv = map->sky;
909     *type = CFAPI_INT;
910     va_end (args);
911     return &rv;
912     break;
913    
914     case CFAPI_MAP_PROP_WPARTX:
915 root 1.16 map = va_arg (args, maptile *);
916 root 1.12
917     rv = map->wpartx;
918     *type = CFAPI_INT;
919     va_end (args);
920     return &rv;
921     break;
922    
923     case CFAPI_MAP_PROP_WPARTY:
924 root 1.16 map = va_arg (args, maptile *);
925 root 1.12
926     rv = map->wparty;
927     *type = CFAPI_INT;
928     va_end (args);
929     return &rv;
930     break;
931    
932     case CFAPI_MAP_PROP_MESSAGE:
933 root 1.16 map = va_arg (args, maptile *);
934 root 1.12
935     buf = map->msg;
936     *type = CFAPI_STRING;
937     va_end (args);
938     return buf;
939     break;
940    
941     case CFAPI_MAP_PROP_NEXT:
942 root 1.16 map = va_arg (args, maptile *);
943 root 1.12
944     *type = CFAPI_PMAP;
945     va_end (args);
946     return map->next;
947     break;
948    
949     case CFAPI_MAP_PROP_REGION:
950 root 1.16 map = va_arg (args, maptile *);
951 root 1.12
952     *type = CFAPI_PREGION;
953     va_end (args);
954     return get_region_by_map (map);
955     break;
956    
957     default:
958     *type = CFAPI_NONE;
959     va_end (args);
960     return NULL;
961     break;
962     }
963     }
964    
965     void *
966     cfapi_map_set_map_property (int *type, ...)
967     {
968     va_list args;
969     static int rv;
970 root 1.16 maptile *map;
971 root 1.12 int val;
972     int property;
973    
974     va_start (args, type);
975    
976     property = va_arg (args, int);
977    
978     switch (property)
979     {
980     case CFAPI_MAP_PROP_LIGHT:
981 root 1.16 map = va_arg (args, maptile *);
982 root 1.12 val = va_arg (args, int);
983    
984     rv = change_map_light (map, val);
985     *type = CFAPI_INT;
986     va_end (args);
987     return &rv;
988     break;
989    
990     case CFAPI_MAP_PROP_RESET_TIME:
991 root 1.16 map = va_arg (args, maptile *);
992 root 1.12
993     *type = CFAPI_NONE;
994     va_end (args);
995     return NULL;
996     break;
997    
998     default:
999     *type = CFAPI_NONE;
1000     va_end (args);
1001     return NULL;
1002     break;
1003     }
1004     }
1005     void *
1006     cfapi_map_out_of_map (int *type, ...)
1007     {
1008     va_list args;
1009     static int rv;
1010 root 1.16 maptile *map;
1011 root 1.12 int x, y;
1012    
1013     va_start (args, type);
1014 root 1.16 map = va_arg (args, maptile *);
1015 root 1.12 x = va_arg (args, int);
1016     y = va_arg (args, int);
1017    
1018     rv = out_of_map (map, x, y);
1019     va_end (args);
1020     *type = CFAPI_INT;
1021     return &rv;
1022     }
1023    
1024     void *
1025     cfapi_map_update_position (int *type, ...)
1026     {
1027     va_list args;
1028 root 1.16 maptile *map;
1029 root 1.12 int x, y;
1030    
1031     va_start (args, type);
1032    
1033 root 1.16 map = va_arg (args, maptile *);
1034 root 1.12 x = va_arg (args, int);
1035     y = va_arg (args, int);
1036    
1037     update_position (map, x, y);
1038     va_end (args);
1039     *type = CFAPI_NONE;
1040     return NULL;
1041     }
1042    
1043     void *
1044     cfapi_map_delete_map (int *type, ...)
1045     {
1046     va_list args;
1047 root 1.16 maptile *map;
1048 root 1.12
1049     va_start (args, type);
1050    
1051 root 1.16 map = va_arg (args, maptile *);
1052 root 1.12
1053     delete_map (map);
1054    
1055     va_end (args);
1056     *type = CFAPI_NONE;
1057     return NULL;
1058     }
1059    
1060     void *
1061     cfapi_map_message (int *type, ...)
1062     {
1063     va_list args;
1064 root 1.16 maptile *map;
1065 root 1.12 char *string;
1066     int color;
1067    
1068     va_start (args, type);
1069 root 1.16 map = va_arg (args, maptile *);
1070 root 1.12 string = va_arg (args, char *);
1071     color = va_arg (args, int);
1072    
1073     va_end (args);
1074    
1075     new_info_map (color, map, string);
1076     *type = CFAPI_NONE;
1077     return NULL;
1078 elmex 1.1 }
1079 root 1.12
1080     void *
1081     cfapi_map_get_object_at (int *type, ...)
1082 elmex 1.1 {
1083 root 1.12 va_list args;
1084 root 1.16 maptile *map;
1085 root 1.12 int x, y;
1086     object *rv;
1087 elmex 1.1
1088 root 1.12 va_start (args, type);
1089 root 1.16 map = va_arg (args, maptile *);
1090 root 1.12 x = va_arg (args, int);
1091     y = va_arg (args, int);
1092 elmex 1.1
1093 root 1.12 va_end (args);
1094 elmex 1.1
1095 root 1.12 rv = get_map_ob (map, x, y);
1096     *type = CFAPI_POBJECT;
1097     return rv;
1098 elmex 1.1 }
1099 root 1.12
1100     void *
1101     cfapi_map_get_flags (int *type, ...)
1102 elmex 1.1 {
1103 root 1.12 va_list args;
1104     sint16 x, y;
1105     sint16 *nx, *ny;
1106 root 1.16 static maptile *map;
1107     maptile **newmap;
1108 root 1.12 static int rv;
1109    
1110     va_start (args, type);
1111    
1112 root 1.16 map = va_arg (args, maptile *);
1113     newmap = va_arg (args, maptile **);
1114 root 1.12 x = va_arg (args, int);
1115     y = va_arg (args, int);
1116 elmex 1.1
1117 root 1.12 nx = va_arg (args, sint16 *);
1118     ny = va_arg (args, sint16 *);
1119     va_end (args);
1120    
1121     rv = get_map_flags (map, newmap, x, y, nx, ny);
1122    
1123     *type = CFAPI_INT;
1124     return &rv;
1125 elmex 1.1 }
1126 root 1.12
1127     void *
1128     cfapi_map_present_arch_by_name (int *type, ...)
1129 elmex 1.1 {
1130 root 1.12 va_list args;
1131     object *rv;
1132     int x, y;
1133 root 1.16 maptile *map;
1134 root 1.12 char *msg;
1135    
1136     va_start (args, type);
1137    
1138     msg = va_arg (args, char *);
1139 root 1.16 map = va_arg (args, maptile *);
1140 root 1.12 x = va_arg (args, int);
1141     y = va_arg (args, int);
1142    
1143     va_end (args);
1144    
1145 root 1.14 rv = present_arch (archetype::find (msg), map, x, y);
1146 root 1.12 *type = CFAPI_POBJECT;
1147     return rv;
1148 elmex 1.1 }
1149    
1150     /* OBJECT-RELATED HOOKS */
1151    
1152 root 1.12 void *
1153     cfapi_object_move (int *type, ...)
1154     {
1155     va_list args;
1156     int kind;
1157     object *op;
1158     object *activator;
1159     player *pl;
1160     int direction;
1161     static int rv = 0;
1162    
1163     va_start (args, type);
1164     kind = va_arg (args, int);
1165    
1166     switch (kind)
1167     {
1168     case 0:
1169     op = va_arg (args, object *);
1170     direction = va_arg (args, int);
1171     activator = va_arg (args, object *);
1172    
1173     va_end (args);
1174     rv = move_ob (op, direction, activator);
1175     break;
1176    
1177     case 1:
1178     pl = va_arg (args, player *);
1179     direction = va_arg (args, int);
1180    
1181     va_end (args);
1182     rv = move_player (pl->ob, direction);
1183     break;
1184     }
1185     *type = CFAPI_INT;
1186     return &rv;
1187     }
1188    
1189     void *
1190     cfapi_object_get_key (int *type, ...)
1191 elmex 1.1 {
1192 root 1.12 va_list args;
1193     char *rv;
1194     char *keyname;
1195     object *op;
1196    
1197     va_start (args, type);
1198     op = va_arg (args, object *);
1199     keyname = va_arg (args, char *);
1200    
1201     va_end (args);
1202    
1203     rv = (char *) get_ob_key_value (op, keyname);
1204     *type = CFAPI_STRING;
1205     return rv;
1206     }
1207 elmex 1.1
1208 root 1.12 void *
1209     cfapi_object_set_key (int *type, ...)
1210     {
1211     va_list args;
1212     char *keyname;
1213     char *value;
1214     object *op;
1215    
1216     va_start (args, type);
1217     op = va_arg (args, object *);
1218     keyname = va_arg (args, char *);
1219     value = va_arg (args, char *);
1220    
1221     va_end (args);
1222    
1223     set_ob_key_value (op, keyname, value, 0);
1224     *type = CFAPI_NONE;
1225     return NULL;
1226 elmex 1.1 }
1227 root 1.12
1228     void *
1229     cfapi_object_get_property (int *type, ...)
1230 elmex 1.1 {
1231 root 1.12 va_list args;
1232     int property;
1233     object *op;
1234     void *rv;
1235     static int ri;
1236    
1237     va_start (args, type);
1238    
1239     op = va_arg (args, object *);
1240     property = va_arg (args, int);
1241    
1242     rv = NULL;
1243     if (op != NULL)
1244     {
1245     switch (property)
1246 elmex 1.1 {
1247 root 1.12 case CFAPI_OBJECT_PROP_OB_ABOVE:
1248     rv = op->above;
1249     *type = CFAPI_POBJECT;
1250     break;
1251    
1252     case CFAPI_OBJECT_PROP_OB_BELOW:
1253     rv = op->below;
1254     *type = CFAPI_POBJECT;
1255     break;
1256    
1257     case CFAPI_OBJECT_PROP_NEXT_ACTIVE_OB:
1258     rv = op->active_next;
1259     *type = CFAPI_POBJECT;
1260     break;
1261    
1262     case CFAPI_OBJECT_PROP_PREV_ACTIVE_OB:
1263     rv = op->active_prev;
1264     *type = CFAPI_POBJECT;
1265     break;
1266    
1267     case CFAPI_OBJECT_PROP_INVENTORY:
1268     rv = op->inv;
1269     *type = CFAPI_POBJECT;
1270     break;
1271    
1272     case CFAPI_OBJECT_PROP_ENVIRONMENT:
1273     rv = op->env;
1274     *type = CFAPI_POBJECT;
1275     break;
1276    
1277     case CFAPI_OBJECT_PROP_HEAD:
1278     rv = op->head;
1279     *type = CFAPI_POBJECT;
1280     break;
1281    
1282     case CFAPI_OBJECT_PROP_CONTAINER:
1283     rv = op->container;
1284     *type = CFAPI_POBJECT;
1285     break;
1286    
1287     case CFAPI_OBJECT_PROP_MAP:
1288     rv = op->map;
1289     *type = CFAPI_PMAP;
1290     break;
1291    
1292     case CFAPI_OBJECT_PROP_COUNT:
1293     ri = op->count;
1294     rv = &ri;
1295     *type = CFAPI_INT;
1296     break;
1297    
1298     case CFAPI_OBJECT_PROP_REFCOUNT:
1299 root 1.13 abort ();
1300 root 1.12 break;
1301    
1302     case CFAPI_OBJECT_PROP_NAME:
1303     rv = query_name (op);
1304     *type = CFAPI_STRING;
1305     break;
1306    
1307     case CFAPI_OBJECT_PROP_NAME_PLURAL:
1308     rv = (char *) &op->name_pl;
1309     *type = CFAPI_STRING;
1310     break;
1311    
1312     case CFAPI_OBJECT_PROP_TITLE:
1313     rv = (char *) &op->title;
1314     *type = CFAPI_STRING;
1315     break;
1316    
1317     case CFAPI_OBJECT_PROP_RACE:
1318     rv = (char *) &op->race;
1319     *type = CFAPI_STRING;
1320     break;
1321    
1322     case CFAPI_OBJECT_PROP_SLAYING:
1323     rv = (char *) &op->slaying;
1324     *type = CFAPI_STRING;
1325     break;
1326    
1327     case CFAPI_OBJECT_PROP_SKILL:
1328     rv = (char *) &op->skill;
1329     *type = CFAPI_STRING;
1330     break;
1331    
1332     case CFAPI_OBJECT_PROP_MESSAGE:
1333     rv = (char *) &op->msg;
1334     if (rv == NULL)
1335     rv = (void *) "";
1336     *type = CFAPI_STRING;
1337     break;
1338    
1339     case CFAPI_OBJECT_PROP_LORE:
1340     rv = (char *) &op->lore;
1341     *type = CFAPI_STRING;
1342     break;
1343    
1344     case CFAPI_OBJECT_PROP_X:
1345     ri = op->x;
1346     rv = &ri;
1347     *type = CFAPI_INT;
1348     break;
1349    
1350     case CFAPI_OBJECT_PROP_Y:
1351     ri = op->y;
1352     rv = &ri;
1353     *type = CFAPI_INT;
1354     break;
1355    
1356     case CFAPI_OBJECT_PROP_SPEED:
1357     rv = &op->speed;
1358     *type = CFAPI_DOUBLE;
1359     break;
1360    
1361     case CFAPI_OBJECT_PROP_SPEED_LEFT:
1362     rv = &op->speed_left;
1363     *type = CFAPI_DOUBLE;
1364     break;
1365    
1366     case CFAPI_OBJECT_PROP_NROF:
1367     ri = op->nrof;
1368     rv = &ri;
1369     *type = CFAPI_INT;
1370     break;
1371    
1372     case CFAPI_OBJECT_PROP_DIRECTION:
1373     ri = op->direction;
1374     rv = &ri;
1375     *type = CFAPI_INT;
1376     break;
1377    
1378     case CFAPI_OBJECT_PROP_FACING:
1379     ri = op->facing;
1380     rv = &ri;
1381     *type = CFAPI_INT;
1382     break;
1383    
1384     case CFAPI_OBJECT_PROP_TYPE:
1385     ri = op->type;
1386     rv = &ri;
1387     *type = CFAPI_INT;
1388     break;
1389    
1390     case CFAPI_OBJECT_PROP_SUBTYPE:
1391     ri = op->subtype;
1392     rv = &ri;
1393     *type = CFAPI_INT;
1394     break;
1395    
1396     case CFAPI_OBJECT_PROP_CLIENT_TYPE:
1397     ri = op->client_type;
1398     rv = &ri;
1399     *type = CFAPI_INT;
1400     break;
1401 elmex 1.1
1402 root 1.12 case CFAPI_OBJECT_PROP_RESIST:
1403     {
1404 elmex 1.1 int idx;
1405 root 1.12 idx = va_arg (args, int);
1406 elmex 1.1
1407 root 1.12 ri = op->resist[idx];
1408     rv = &ri;
1409     }
1410     *type = CFAPI_INT;
1411     break;
1412    
1413     case CFAPI_OBJECT_PROP_ATTACK_TYPE:
1414     ri = op->attacktype;
1415     rv = &ri;
1416     *type = CFAPI_INT;
1417     break;
1418    
1419     case CFAPI_OBJECT_PROP_PATH_ATTUNED:
1420     ri = op->path_attuned;
1421     rv = &ri;
1422     *type = CFAPI_INT;
1423     break;
1424    
1425     case CFAPI_OBJECT_PROP_PATH_REPELLED:
1426     ri = op->path_repelled;
1427     rv = &ri;
1428     *type = CFAPI_INT;
1429     break;
1430    
1431     case CFAPI_OBJECT_PROP_PATH_DENIED:
1432     ri = op->path_denied;
1433     rv = &ri;
1434     *type = CFAPI_INT;
1435     break;
1436    
1437     case CFAPI_OBJECT_PROP_MATERIAL:
1438     ri = op->material;
1439     rv = &ri;
1440     *type = CFAPI_INT;
1441     break;
1442    
1443     case CFAPI_OBJECT_PROP_MAGIC:
1444     ri = op->magic;
1445     rv = &ri;
1446     *type = CFAPI_INT;
1447     break;
1448    
1449     case CFAPI_OBJECT_PROP_VALUE:
1450     ri = op->value;
1451     rv = &ri;
1452     *type = CFAPI_INT;
1453     break;
1454    
1455     case CFAPI_OBJECT_PROP_LEVEL:
1456     ri = op->level;
1457     rv = &ri;
1458     *type = CFAPI_INT;
1459     break;
1460    
1461     case CFAPI_OBJECT_PROP_LAST_HEAL:
1462     ri = op->last_heal;
1463     rv = &ri;
1464     *type = CFAPI_INT;
1465     break;
1466    
1467     case CFAPI_OBJECT_PROP_LAST_SP:
1468     ri = op->last_sp;
1469     rv = &ri;
1470     *type = CFAPI_INT;
1471     break;
1472    
1473     case CFAPI_OBJECT_PROP_LAST_GRACE:
1474     ri = op->last_grace;
1475     rv = &ri;
1476     *type = CFAPI_INT;
1477     break;
1478    
1479     case CFAPI_OBJECT_PROP_LAST_EAT:
1480     ri = op->last_eat;
1481     rv = &ri;
1482     *type = CFAPI_INT;
1483     break;
1484    
1485     case CFAPI_OBJECT_PROP_INVISIBLE_TIME:
1486     ri = op->invisible;
1487     rv = &ri;
1488     *type = CFAPI_INT;
1489     break;
1490    
1491     case CFAPI_OBJECT_PROP_PICK_UP:
1492     ri = op->pick_up;
1493     rv = &ri;
1494     *type = CFAPI_INT;
1495     break;
1496    
1497     case CFAPI_OBJECT_PROP_ITEM_POWER:
1498     ri = op->item_power;
1499     rv = &ri;
1500     *type = CFAPI_INT;
1501     break;
1502    
1503     case CFAPI_OBJECT_PROP_GEN_SP_ARMOUR:
1504     ri = op->gen_sp_armour;
1505     rv = &ri;
1506     *type = CFAPI_INT;
1507     break;
1508    
1509     case CFAPI_OBJECT_PROP_WEIGHT:
1510     ri = op->weight;
1511     rv = &ri;
1512     *type = CFAPI_INT;
1513     break;
1514    
1515     case CFAPI_OBJECT_PROP_WEIGHT_LIMIT:
1516     ri = op->weight_limit;
1517     rv = &ri;
1518     *type = CFAPI_INT;
1519     break;
1520    
1521     case CFAPI_OBJECT_PROP_CARRYING:
1522     ri = op->carrying;
1523     rv = &ri;
1524     *type = CFAPI_INT;
1525     break;
1526    
1527     case CFAPI_OBJECT_PROP_GLOW_RADIUS:
1528     ri = op->glow_radius;
1529     rv = &ri;
1530     *type = CFAPI_INT;
1531     break;
1532    
1533     case CFAPI_OBJECT_PROP_PERM_EXP:
1534     rv = &op->perm_exp;
1535     *type = CFAPI_LONG;
1536     break;
1537    
1538     case CFAPI_OBJECT_PROP_CURRENT_WEAPON:
1539     rv = op->current_weapon;
1540     *type = CFAPI_POBJECT;
1541     break;
1542    
1543     case CFAPI_OBJECT_PROP_ENEMY:
1544     rv = op->enemy;
1545     *type = CFAPI_POBJECT;
1546     break;
1547    
1548     case CFAPI_OBJECT_PROP_ATTACKED_BY:
1549     rv = op->attacked_by;
1550     *type = CFAPI_POBJECT;
1551     break;
1552    
1553     case CFAPI_OBJECT_PROP_RUN_AWAY:
1554     ri = op->run_away;
1555     rv = &ri;
1556     *type = CFAPI_INT;
1557     break;
1558    
1559     case CFAPI_OBJECT_PROP_CHOSEN_SKILL:
1560     rv = op->chosen_skill;
1561     *type = CFAPI_POBJECT;
1562     break;
1563    
1564     case CFAPI_OBJECT_PROP_HIDDEN:
1565     ri = op->hide;
1566     rv = &ri;
1567     *type = CFAPI_INT;
1568     break;
1569    
1570     case CFAPI_OBJECT_PROP_MOVE_STATUS:
1571     ri = op->move_status;
1572     rv = &ri;
1573     *type = CFAPI_INT;
1574     break;
1575    
1576     case CFAPI_OBJECT_PROP_MOVE_TYPE:
1577     ri = op->attack_movement;
1578     rv = &ri;
1579     *type = CFAPI_INT;
1580     break;
1581    
1582     case CFAPI_OBJECT_PROP_SPELL_ITEM:
1583     rv = op->spellitem;
1584     *type = CFAPI_POBJECT;
1585     break;
1586    
1587     case CFAPI_OBJECT_PROP_EXP_MULTIPLIER:
1588     rv = &op->expmul;
1589     *type = CFAPI_DOUBLE;
1590     break;
1591    
1592     case CFAPI_OBJECT_PROP_ARCHETYPE:
1593     rv = op->arch;
1594     *type = CFAPI_PARCH;
1595     break;
1596    
1597     case CFAPI_OBJECT_PROP_OTHER_ARCH:
1598     rv = op->other_arch;
1599     *type = CFAPI_PARCH;
1600     break;
1601    
1602     case CFAPI_OBJECT_PROP_ANIM_SPEED:
1603     ri = op->anim_speed;
1604     rv = &ri;
1605     *type = CFAPI_INT;
1606     break;
1607    
1608     case CFAPI_OBJECT_PROP_FRIENDLY:
1609     ri = is_friendly (op);
1610     rv = &ri;
1611     *type = CFAPI_INT;
1612     break;
1613 elmex 1.1
1614 root 1.12 case CFAPI_OBJECT_PROP_BASE_NAME:
1615     {
1616 elmex 1.1 int i;
1617 root 1.12 i = va_arg (args, int);
1618    
1619     rv = (char *) query_base_name (op, i);
1620 elmex 1.1 *type = CFAPI_STRING;
1621 root 1.12 }
1622     break;
1623 elmex 1.1
1624 root 1.12 case CFAPI_OBJECT_PROP_MAGICAL:
1625     ri = is_magical (op);
1626     rv = &ri;
1627     *type = CFAPI_INT;
1628     break;
1629    
1630     case CFAPI_OBJECT_PROP_LUCK:
1631     ri = op->stats.luck;
1632     rv = &ri;
1633     *type = CFAPI_INT;
1634     break;
1635    
1636     case CFAPI_OBJECT_PROP_EXP:
1637     rv = &op->stats.exp;
1638     *type = CFAPI_LONG;
1639     break;
1640    
1641     case CFAPI_OBJECT_PROP_OWNER:
1642 root 1.23 rv = op->owner;
1643 root 1.12 *type = CFAPI_POBJECT;
1644     break;
1645 elmex 1.1
1646 root 1.12 case CFAPI_OBJECT_PROP_PRESENT:
1647     {
1648 elmex 1.1 int stype;
1649 root 1.12
1650 elmex 1.1 rv = 0;
1651 root 1.12 stype = va_arg (args, int);
1652 elmex 1.1
1653 root 1.12 switch (stype)
1654     {
1655 elmex 1.1
1656 root 1.12 unsigned char ptype;
1657     char *buf;
1658     archetype *at;
1659    
1660     case 0: /* present_in_ob */
1661     ptype = (unsigned char) (va_arg (args, int));
1662    
1663     rv = present_in_ob (ptype, op);
1664     break;
1665    
1666     case 1: /* present_in_ob_by_name */
1667     ptype = (unsigned char) (va_arg (args, int));
1668     buf = va_arg (args, char *);
1669    
1670     rv = present_in_ob_by_name (ptype, buf, op);
1671     break;
1672    
1673     case 2: /* present_arch_in_ob */
1674     at = va_arg (args, archetype *);
1675    
1676     rv = present_arch_in_ob (at, op);
1677     break;
1678     }
1679     }
1680     *type = CFAPI_POBJECT;
1681     break;
1682    
1683     case CFAPI_OBJECT_PROP_CHEATER:
1684     ri = (QUERY_FLAG (op, FLAG_WAS_WIZ));
1685     rv = &ri;
1686     *type = CFAPI_INT;
1687     break;
1688    
1689     case CFAPI_OBJECT_PROP_MERGEABLE:
1690     {
1691     object *op2;
1692     op2 = va_arg (args, object *);
1693 elmex 1.1
1694 root 1.23 ri = object::can_merge_slow (op, op2);
1695 elmex 1.1 rv = &ri;
1696 root 1.12 }
1697     *type = CFAPI_INT;
1698     break;
1699    
1700     case CFAPI_OBJECT_PROP_PICKABLE:
1701     {
1702     object *op2;
1703 elmex 1.1
1704     rv = 0;
1705 root 1.12 op2 = va_arg (args, object *);
1706    
1707     ri = can_pick (op2, op);
1708 elmex 1.1 rv = &ri;
1709 root 1.12 }
1710     *type = CFAPI_INT;
1711     break;
1712 elmex 1.1
1713 root 1.12 case CFAPI_OBJECT_PROP_FLAGS:
1714     {
1715 elmex 1.1 int fl;
1716 root 1.12
1717 elmex 1.1 ri = 0;
1718 root 1.12 fl = va_arg (args, int);
1719    
1720     ri = QUERY_FLAG (op, fl);
1721 elmex 1.1 rv = &ri;
1722 root 1.12 }
1723     *type = CFAPI_INT;
1724     break;
1725    
1726     case CFAPI_OBJECT_PROP_STR:
1727     ri = op->stats.Str;
1728     rv = &ri;
1729     *type = CFAPI_INT;
1730     break;
1731    
1732     case CFAPI_OBJECT_PROP_DEX:
1733     ri = op->stats.Dex;
1734     rv = &ri;
1735     *type = CFAPI_INT;
1736     break;
1737    
1738     case CFAPI_OBJECT_PROP_CON:
1739     ri = op->stats.Con;
1740     rv = &ri;
1741     *type = CFAPI_INT;
1742     break;
1743    
1744     case CFAPI_OBJECT_PROP_WIS:
1745     ri = op->stats.Wis;
1746     rv = &ri;
1747     *type = CFAPI_INT;
1748     break;
1749    
1750     case CFAPI_OBJECT_PROP_INT:
1751     ri = op->stats.Int;
1752     rv = &ri;
1753     *type = CFAPI_INT;
1754     break;
1755    
1756     case CFAPI_OBJECT_PROP_POW:
1757     ri = op->stats.Pow;
1758     rv = &ri;
1759     *type = CFAPI_INT;
1760     break;
1761    
1762     case CFAPI_OBJECT_PROP_CHA:
1763     ri = op->stats.Cha;
1764     rv = &ri;
1765     *type = CFAPI_INT;
1766     break;
1767    
1768     case CFAPI_OBJECT_PROP_WC:
1769     ri = op->stats.wc;
1770     rv = &ri;
1771     *type = CFAPI_INT;
1772     break;
1773    
1774     case CFAPI_OBJECT_PROP_AC:
1775     ri = op->stats.ac;
1776     rv = &ri;
1777     *type = CFAPI_INT;
1778     break;
1779    
1780     case CFAPI_OBJECT_PROP_HP:
1781     ri = op->stats.hp;
1782     rv = &ri;
1783     *type = CFAPI_INT;
1784     break;
1785    
1786     case CFAPI_OBJECT_PROP_SP:
1787     ri = op->stats.sp;
1788     rv = &ri;
1789     *type = CFAPI_INT;
1790     break;
1791    
1792     case CFAPI_OBJECT_PROP_GP:
1793     ri = op->stats.grace;
1794     rv = &ri;
1795     *type = CFAPI_INT;
1796     break;
1797    
1798     case CFAPI_OBJECT_PROP_FP:
1799     ri = op->stats.food;
1800     rv = &ri;
1801     *type = CFAPI_INT;
1802     break;
1803    
1804     case CFAPI_OBJECT_PROP_MAXHP:
1805     ri = op->stats.maxhp;
1806     rv = &ri;
1807     *type = CFAPI_INT;
1808     break;
1809    
1810     case CFAPI_OBJECT_PROP_MAXSP:
1811     ri = op->stats.maxsp;
1812     rv = &ri;
1813     *type = CFAPI_INT;
1814     break;
1815    
1816     case CFAPI_OBJECT_PROP_MAXGP:
1817     ri = op->stats.maxgrace;
1818     rv = &ri;
1819     *type = CFAPI_INT;
1820     break;
1821    
1822     case CFAPI_OBJECT_PROP_DAM:
1823     ri = op->stats.dam;
1824     rv = &ri;
1825     *type = CFAPI_INT;
1826     break;
1827    
1828     case CFAPI_OBJECT_PROP_GOD:
1829     rv = (char *) determine_god (op);
1830     *type = CFAPI_STRING;
1831     break;
1832    
1833     case CFAPI_OBJECT_PROP_ARCH_NAME:
1834     rv = (char *) &op->arch->name;
1835     *type = CFAPI_STRING;
1836     break;
1837    
1838     case CFAPI_OBJECT_PROP_INVISIBLE:
1839     ri = op->invisible;
1840     rv = &ri;
1841     *type = CFAPI_INT;
1842     break;
1843    
1844     case CFAPI_OBJECT_PROP_FACE:
1845     ri = op->animation_id;
1846     rv = &ri;
1847     *type = CFAPI_INT;
1848     break;
1849    
1850     case CFAPI_PLAYER_PROP_IP:
1851 root 1.24 rv = op->contr->socket->host;
1852 root 1.12 *type = CFAPI_STRING;
1853     break;
1854    
1855     case CFAPI_PLAYER_PROP_MARKED_ITEM:
1856     rv = find_marked_object (op);
1857     *type = CFAPI_POBJECT;
1858     break;
1859    
1860     case CFAPI_PLAYER_PROP_PARTY:
1861     rv = (op->contr ? op->contr->party : NULL);
1862     *type = CFAPI_PPARTY;
1863     break;
1864     default:
1865     *type = CFAPI_NONE;
1866     break;
1867     }
1868     }
1869     va_end (args);
1870     return rv;
1871     }
1872    
1873     void *
1874     cfapi_object_set_property (int *type, ...)
1875     {
1876     va_list args;
1877     int iarg;
1878     long larg;
1879     char *sarg;
1880     double darg;
1881     object *oparg;
1882     object *op;
1883     int property;
1884     void *rv;
1885     partylist *partyarg;
1886    
1887     va_start (args, type);
1888    
1889     op = va_arg (args, object *);
1890     property = va_arg (args, int);
1891    
1892     rv = NULL;
1893    
1894     if (op != NULL && (!op->arch || (op != &op->arch->clone)))
1895     {
1896     switch (property)
1897     {
1898     case CFAPI_OBJECT_PROP_NAME:
1899     sarg = va_arg (args, char *);
1900    
1901     #define FREE_AND_COPY(a,b) (a) = (b) // TODO: remove, but plugins.C is considered zombie code
1902     FREE_AND_COPY (op->name, sarg);
1903     send_changed_object (op);
1904     break;
1905    
1906     case CFAPI_OBJECT_PROP_NAME_PLURAL:
1907     sarg = va_arg (args, char *);
1908    
1909     FREE_AND_COPY (op->name_pl, sarg);
1910     send_changed_object (op);
1911     break;
1912    
1913     case CFAPI_OBJECT_PROP_TITLE:
1914     sarg = va_arg (args, char *);
1915    
1916     FREE_AND_COPY (op->title, sarg);
1917     break;
1918    
1919     case CFAPI_OBJECT_PROP_RACE:
1920     sarg = va_arg (args, char *);
1921    
1922     FREE_AND_COPY (op->race, sarg);
1923     break;
1924    
1925     case CFAPI_OBJECT_PROP_SLAYING:
1926     sarg = va_arg (args, char *);
1927    
1928     FREE_AND_COPY (op->slaying, sarg);
1929     break;
1930    
1931     case CFAPI_OBJECT_PROP_SKILL:
1932     sarg = va_arg (args, char *);
1933    
1934     FREE_AND_COPY (op->skill, sarg);
1935     break;
1936    
1937     case CFAPI_OBJECT_PROP_MESSAGE:
1938     sarg = va_arg (args, char *);
1939    
1940     FREE_AND_COPY (op->msg, sarg);
1941     break;
1942    
1943     case CFAPI_OBJECT_PROP_LORE:
1944     sarg = va_arg (args, char *);
1945    
1946     FREE_AND_COPY (op->lore, sarg);
1947     break;
1948    
1949     case CFAPI_OBJECT_PROP_SPEED:
1950     darg = va_arg (args, double);
1951    
1952     op->speed = darg;
1953     break;
1954    
1955     case CFAPI_OBJECT_PROP_SPEED_LEFT:
1956     darg = va_arg (args, double);
1957    
1958     op->speed_left = darg;
1959     break;
1960    
1961     case CFAPI_OBJECT_PROP_NROF:
1962     iarg = va_arg (args, int);
1963    
1964     if (iarg < 0)
1965     iarg = 0;
1966     if (op->nrof > (uint32) iarg)
1967     decrease_ob_nr (op, op->nrof - iarg);
1968     else if (op->nrof < (uint32) iarg)
1969     {
1970     object *tmp;
1971     player *pl;
1972    
1973     op->nrof = iarg;
1974     if (op->env != NULL)
1975     {
1976     tmp = is_player_inv (op->env);
1977     if (!tmp)
1978     {
1979     for (pl = first_player; pl; pl = pl->next)
1980     if (pl->ob->container == op->env)
1981     break;
1982     if (pl)
1983     tmp = pl->ob;
1984     else
1985     tmp = NULL;
1986     }
1987     else
1988     {
1989     sum_weight (tmp);
1990     fix_player (tmp);
1991     }
1992     if (tmp)
1993     esrv_send_item (tmp, op);
1994     }
1995     else
1996     {
1997     object *above = op->above;
1998    
1999     for (tmp = above; tmp != NULL; tmp = tmp->above)
2000     if (tmp->type == PLAYER)
2001     esrv_send_item (tmp, op);
2002     }
2003     }
2004     break;
2005    
2006     case CFAPI_OBJECT_PROP_DIRECTION:
2007     iarg = va_arg (args, int);
2008    
2009     op->direction = iarg;
2010     break;
2011    
2012     case CFAPI_OBJECT_PROP_FACING:
2013     iarg = va_arg (args, int);
2014    
2015     op->facing = iarg;
2016     break;
2017    
2018     case CFAPI_OBJECT_PROP_RESIST:
2019     {
2020     int iargbis = va_arg (args, int);
2021     iarg = va_arg (args, int);
2022    
2023     op->resist[iargbis] = iarg;
2024     }
2025     break;
2026    
2027     case CFAPI_OBJECT_PROP_ATTACK_TYPE:
2028     iarg = va_arg (args, int);
2029    
2030     op->attacktype = iarg;
2031     break;
2032    
2033     case CFAPI_OBJECT_PROP_PATH_ATTUNED:
2034     iarg = va_arg (args, int);
2035    
2036     op->path_attuned = iarg;
2037     break;
2038    
2039     case CFAPI_OBJECT_PROP_PATH_REPELLED:
2040     iarg = va_arg (args, int);
2041    
2042     op->path_repelled = iarg;
2043     break;
2044    
2045     case CFAPI_OBJECT_PROP_PATH_DENIED:
2046     iarg = va_arg (args, int);
2047    
2048     op->path_denied = iarg;
2049     break;
2050    
2051     case CFAPI_OBJECT_PROP_MATERIAL:
2052     iarg = va_arg (args, int);
2053    
2054     op->material = iarg;
2055     break;
2056    
2057     case CFAPI_OBJECT_PROP_MATERIAL_NAME:
2058     break;
2059    
2060     case CFAPI_OBJECT_PROP_MAGIC:
2061     iarg = va_arg (args, int);
2062    
2063     op->magic = iarg;
2064     break;
2065    
2066     case CFAPI_OBJECT_PROP_VALUE:
2067     iarg = va_arg (args, int);
2068    
2069     op->value = iarg;
2070     break;
2071    
2072     case CFAPI_OBJECT_PROP_LEVEL:
2073     iarg = va_arg (args, int);
2074    
2075     op->level = iarg;
2076     break;
2077    
2078     case CFAPI_OBJECT_PROP_LAST_HEAL:
2079     iarg = va_arg (args, int);
2080    
2081     op->last_heal = iarg;
2082     break;
2083    
2084     case CFAPI_OBJECT_PROP_LAST_SP:
2085     iarg = va_arg (args, int);
2086    
2087     op->last_sp = iarg;
2088     break;
2089    
2090     case CFAPI_OBJECT_PROP_LAST_GRACE:
2091     iarg = va_arg (args, int);
2092    
2093     op->last_grace = iarg;
2094     break;
2095    
2096     case CFAPI_OBJECT_PROP_LAST_EAT:
2097     iarg = va_arg (args, int);
2098    
2099     op->last_eat = iarg;
2100     break;
2101    
2102     case CFAPI_OBJECT_PROP_INVISIBLE_TIME:
2103     iarg = va_arg (args, int);
2104    
2105     op->invisible = iarg;
2106     break;
2107    
2108     case CFAPI_OBJECT_PROP_PICK_UP:
2109     iarg = va_arg (args, int);
2110    
2111     op->pick_up = iarg;
2112     break;
2113    
2114     case CFAPI_OBJECT_PROP_ITEM_POWER:
2115     iarg = va_arg (args, int);
2116    
2117     op->item_power = iarg;
2118     break;
2119    
2120     case CFAPI_OBJECT_PROP_GEN_SP_ARMOUR:
2121     iarg = va_arg (args, int);
2122    
2123     op->gen_sp_armour = iarg;
2124     break;
2125    
2126     case CFAPI_OBJECT_PROP_WEIGHT:
2127     iarg = va_arg (args, int);
2128    
2129     if (op->weight != iarg)
2130     {
2131     object *tmp;
2132     player *pl;
2133    
2134     op->weight = iarg;
2135     if (op->env != NULL)
2136     {
2137     tmp = is_player_inv (op->env);
2138     if (!tmp)
2139     {
2140     for (pl = first_player; pl; pl = pl->next)
2141     if (pl->ob->container == op->env)
2142     break;
2143     if (pl)
2144     tmp = pl->ob;
2145     else
2146     tmp = NULL;
2147     }
2148     else
2149     {
2150     sum_weight (tmp);
2151     fix_player (tmp);
2152     }
2153     if (tmp)
2154     esrv_send_item (tmp, op);
2155     }
2156     else
2157     {
2158     object *above = op->above;
2159    
2160     for (tmp = above; tmp != NULL; tmp = tmp->above)
2161     if (tmp->type == PLAYER)
2162     esrv_send_item (tmp, op);
2163     }
2164     }
2165     break;
2166    
2167     case CFAPI_OBJECT_PROP_WEIGHT_LIMIT:
2168     iarg = va_arg (args, int);
2169    
2170     op->weight_limit = iarg;
2171     break;
2172    
2173     case CFAPI_OBJECT_PROP_GLOW_RADIUS:
2174     iarg = va_arg (args, int);
2175    
2176     op->glow_radius = iarg;
2177     break;
2178    
2179     case CFAPI_OBJECT_PROP_PERM_EXP:
2180     larg = va_arg (args, long);
2181    
2182     op->perm_exp = larg;
2183     break;
2184    
2185     case CFAPI_OBJECT_PROP_ENEMY:
2186     oparg = va_arg (args, object *);
2187    
2188     op->enemy = oparg;
2189     break;
2190    
2191     case CFAPI_OBJECT_PROP_RUN_AWAY:
2192     iarg = va_arg (args, int);
2193    
2194     op->run_away = iarg;
2195     break;
2196    
2197     case CFAPI_OBJECT_PROP_CHOSEN_SKILL:
2198     oparg = va_arg (args, object *);
2199    
2200     op->chosen_skill = oparg;
2201     break;
2202    
2203     case CFAPI_OBJECT_PROP_HIDDEN:
2204     iarg = va_arg (args, int);
2205    
2206     op->hide = iarg;
2207     break;
2208    
2209     case CFAPI_OBJECT_PROP_MOVE_STATUS:
2210     iarg = va_arg (args, int);
2211    
2212     op->move_status = iarg;
2213     break;
2214    
2215     case CFAPI_OBJECT_PROP_MOVE_TYPE:
2216     iarg = va_arg (args, int);
2217    
2218     op->attack_movement = iarg;
2219     break;
2220    
2221     case CFAPI_OBJECT_PROP_SPELL_ITEM:
2222     oparg = va_arg (args, object *);
2223    
2224     op->spellitem = oparg;
2225     break;
2226    
2227     case CFAPI_OBJECT_PROP_EXP_MULTIPLIER:
2228     darg = va_arg (args, double);
2229    
2230     op->expmul = darg;
2231     break;
2232    
2233     case CFAPI_OBJECT_PROP_CUSTOM_NAME:
2234     sarg = va_arg (args, char *);
2235    
2236     FREE_AND_COPY (op->custom_name, sarg);
2237     send_changed_object (op);
2238     break;
2239    
2240     case CFAPI_OBJECT_PROP_ANIM_SPEED:
2241     iarg = va_arg (args, int);
2242    
2243     op->anim_speed = iarg;
2244     break;
2245    
2246     case CFAPI_OBJECT_PROP_FRIENDLY:
2247     iarg = va_arg (args, int);
2248    
2249     if (iarg == 1 && is_friendly (op) == 0)
2250     add_friendly_object (op);
2251     else if (iarg == 0 && is_friendly (op) == 1)
2252     remove_friendly_object (op);
2253     break;
2254    
2255     case CFAPI_OBJECT_PROP_LUCK:
2256     iarg = va_arg (args, int);
2257    
2258     op->stats.luck = iarg;
2259     break;
2260    
2261     case CFAPI_OBJECT_PROP_EXP:
2262     {
2263     char *skillname;
2264    
2265     larg = va_arg (args, long);
2266     skillname = va_arg (args, char *);
2267     iarg = va_arg (args, int);
2268    
2269     change_exp (op, larg, skillname, iarg);
2270     }
2271     break;
2272    
2273     case CFAPI_OBJECT_PROP_OWNER:
2274     oparg = va_arg (args, object *);
2275    
2276 root 1.23 op->set_owner (oparg);
2277 root 1.12 break;
2278    
2279     case CFAPI_OBJECT_PROP_CHEATER:
2280     set_cheat (op);
2281     break;
2282    
2283     case CFAPI_OBJECT_PROP_FLAGS:
2284     {
2285     int iargbis;
2286     iarg = va_arg (args, int);
2287     iargbis = va_arg (args, int);
2288    
2289     if (iargbis == 1)
2290     SET_FLAG (op, iarg);
2291     else
2292     CLEAR_FLAG (op, iarg);
2293     }
2294     break;
2295    
2296     case CFAPI_OBJECT_PROP_STR:
2297     iarg = va_arg (args, int);
2298    
2299     op->stats.Str = iarg;
2300     break;
2301    
2302     case CFAPI_OBJECT_PROP_DEX:
2303     iarg = va_arg (args, int);
2304    
2305     op->stats.Dex = iarg;
2306     break;
2307    
2308     case CFAPI_OBJECT_PROP_CON:
2309     iarg = va_arg (args, int);
2310    
2311     op->stats.Con = iarg;
2312     break;
2313    
2314     case CFAPI_OBJECT_PROP_WIS:
2315     iarg = va_arg (args, int);
2316    
2317     op->stats.Wis = iarg;
2318     break;
2319    
2320     case CFAPI_OBJECT_PROP_INT:
2321     iarg = va_arg (args, int);
2322    
2323     op->stats.Int = iarg;
2324     break;
2325    
2326     case CFAPI_OBJECT_PROP_POW:
2327     iarg = va_arg (args, int);
2328    
2329     op->stats.Pow = iarg;
2330     break;
2331    
2332     case CFAPI_OBJECT_PROP_CHA:
2333     iarg = va_arg (args, int);
2334    
2335     op->stats.Cha = iarg;
2336     break;
2337    
2338     case CFAPI_OBJECT_PROP_WC:
2339     iarg = va_arg (args, int);
2340    
2341     op->stats.wc = iarg;
2342     break;
2343    
2344     case CFAPI_OBJECT_PROP_AC:
2345     iarg = va_arg (args, int);
2346    
2347     op->stats.ac = iarg;
2348     break;
2349    
2350     case CFAPI_OBJECT_PROP_HP:
2351     iarg = va_arg (args, int);
2352    
2353     op->stats.hp = iarg;
2354     break;
2355    
2356     case CFAPI_OBJECT_PROP_SP:
2357     iarg = va_arg (args, int);
2358    
2359     op->stats.sp = iarg;
2360     break;
2361    
2362     case CFAPI_OBJECT_PROP_GP:
2363     iarg = va_arg (args, int);
2364    
2365     op->stats.grace = iarg;
2366     break;
2367    
2368     case CFAPI_OBJECT_PROP_FP:
2369     iarg = va_arg (args, int);
2370 elmex 1.1
2371 root 1.12 op->stats.food = iarg;
2372     break;
2373 elmex 1.1
2374 root 1.12 case CFAPI_OBJECT_PROP_MAXHP:
2375     iarg = va_arg (args, int);
2376 elmex 1.1
2377 root 1.12 op->stats.maxhp = iarg;
2378     break;
2379 elmex 1.1
2380 root 1.12 case CFAPI_OBJECT_PROP_MAXSP:
2381     iarg = va_arg (args, int);
2382 elmex 1.1
2383 root 1.12 op->stats.maxsp = iarg;
2384     break;
2385 elmex 1.1
2386 root 1.12 case CFAPI_OBJECT_PROP_MAXGP:
2387     iarg = va_arg (args, int);
2388 elmex 1.1
2389 root 1.12 op->stats.maxgrace = iarg;
2390     break;
2391 elmex 1.1
2392 root 1.12 case CFAPI_OBJECT_PROP_DAM:
2393     iarg = va_arg (args, int);
2394 elmex 1.1
2395 root 1.12 op->stats.dam = iarg;
2396     break;
2397 elmex 1.1
2398 root 1.12 case CFAPI_OBJECT_PROP_FACE:
2399     iarg = va_arg (args, int);
2400 elmex 1.1
2401 root 1.12 op->animation_id = iarg;
2402     update_object (op, UP_OBJ_FACE);
2403     break;
2404 elmex 1.1
2405 root 1.12 case CFAPI_OBJECT_ANIMATION:
2406     iarg = va_arg (args, int);
2407 elmex 1.1
2408 root 1.12 if (iarg != -1)
2409     {
2410     SET_ANIMATION (op, iarg);
2411     }
2412     update_object (op, UP_OBJ_FACE);
2413     break;
2414 elmex 1.1
2415 root 1.12 case CFAPI_PLAYER_PROP_MARKED_ITEM:
2416     if (op->contr)
2417     {
2418     oparg = va_arg (args, object *);
2419 elmex 1.1
2420 root 1.12 op->contr->mark = oparg;
2421     }
2422     break;
2423    
2424     case CFAPI_PLAYER_PROP_PARTY:
2425     if (op->contr)
2426     {
2427     partyarg = va_arg (args, partylist *);
2428 elmex 1.1
2429 root 1.12 op->contr->party = partyarg;
2430     }
2431     break;
2432 elmex 1.1
2433 root 1.12 default:
2434     *type = CFAPI_NONE;
2435     break;
2436 elmex 1.1 }
2437     }
2438 root 1.12 va_end (args);
2439 elmex 1.1
2440 root 1.12 *type = CFAPI_NONE;
2441     return NULL;
2442 elmex 1.1 }
2443    
2444 root 1.12 void *
2445     cfapi_object_apply_below (int *type, ...)
2446 elmex 1.1 {
2447 root 1.12 va_list args;
2448     object *applier;
2449 elmex 1.1
2450 root 1.12 va_start (args, type);
2451 elmex 1.1
2452 root 1.12 applier = va_arg (args, object *);
2453 elmex 1.1
2454 root 1.12 va_end (args);
2455 elmex 1.1
2456 root 1.12 player_apply_below (applier);
2457     *type = CFAPI_NONE;
2458     return NULL;
2459 elmex 1.1 }
2460    
2461 root 1.12 void *
2462     cfapi_object_apply (int *type, ...)
2463 elmex 1.1 {
2464 root 1.12 va_list args;
2465     object *applied;
2466     object *applier;
2467     int aflags;
2468     static int rv;
2469 elmex 1.1
2470 root 1.12 va_start (args, type);
2471 elmex 1.1
2472 root 1.12 applied = va_arg (args, object *);
2473     applier = va_arg (args, object *);
2474     aflags = va_arg (args, int);
2475 elmex 1.1
2476 root 1.12 va_end (args);
2477 elmex 1.1
2478 root 1.12 *type = CFAPI_INT;
2479     rv = manual_apply (applier, applied, aflags);
2480     return &rv;
2481 elmex 1.1 }
2482 root 1.12
2483     void *
2484     cfapi_object_identify (int *type, ...)
2485 elmex 1.1 {
2486 root 1.12 va_list args;
2487     object *op;
2488 elmex 1.1
2489 root 1.12 va_start (args, type);
2490 elmex 1.1
2491 root 1.12 op = va_arg (args, object *);
2492 elmex 1.1
2493 root 1.12 va_end (args);
2494 elmex 1.1
2495 root 1.12 identify (op);
2496     *type = CFAPI_NONE;
2497     return NULL;
2498 elmex 1.1 }
2499 root 1.12
2500     void *
2501     cfapi_object_describe (int *type, ...)
2502 elmex 1.1 {
2503 root 1.12 va_list args;
2504     object *op;
2505     object *owner;
2506 elmex 1.1
2507 root 1.12 va_start (args, type);
2508 elmex 1.1
2509 root 1.12 op = va_arg (args, object *);
2510     owner = va_arg (args, object *);
2511 elmex 1.1
2512 root 1.12 va_end (args);
2513    
2514     *type = CFAPI_STRING;
2515     return describe_item (op, owner);
2516 elmex 1.1 }
2517 root 1.12
2518     void *
2519     cfapi_object_drain (int *type, ...)
2520 elmex 1.1 {
2521 root 1.12 va_list args;
2522 elmex 1.1
2523 root 1.12 object *op;
2524     int ds;
2525 elmex 1.1
2526 root 1.12 va_start (args, type);
2527 elmex 1.1
2528 root 1.12 op = va_arg (args, object *);
2529     ds = va_arg (args, int);
2530 elmex 1.1
2531 root 1.12 va_end (args);
2532 elmex 1.1
2533 root 1.12 drain_specific_stat (op, ds);
2534 elmex 1.1
2535 root 1.12 *type = CFAPI_NONE;
2536     return NULL;
2537 elmex 1.1 }
2538 root 1.12
2539     void *
2540     cfapi_object_fix (int *type, ...)
2541 elmex 1.1 {
2542 root 1.12 va_list args;
2543     object *op;
2544 elmex 1.1
2545 root 1.12 va_start (args, type);
2546 elmex 1.1
2547 root 1.12 op = va_arg (args, object *);
2548 elmex 1.1
2549 root 1.12 va_end (args);
2550 elmex 1.1
2551 root 1.12 fix_player (op);
2552 elmex 1.1
2553 root 1.12 *type = CFAPI_NONE;
2554     return NULL;
2555 elmex 1.1 }
2556 root 1.12
2557     void *
2558     cfapi_object_give_skill (int *type, ...)
2559 elmex 1.1 {
2560 root 1.12 va_list args;
2561 elmex 1.1
2562 root 1.12 object *op;
2563     char *skillname;
2564 elmex 1.1
2565 root 1.12 va_start (args, type);
2566 elmex 1.1
2567 root 1.12 op = va_arg (args, object *);
2568     skillname = va_arg (args, char *);
2569 elmex 1.1
2570 root 1.12 va_end (args);
2571 elmex 1.1
2572 root 1.12 *type = CFAPI_POBJECT;
2573     return give_skill_by_name (op, skillname);
2574 elmex 1.1 }
2575 root 1.12
2576     void *
2577     cfapi_object_transmute (int *type, ...)
2578 elmex 1.1 {
2579 root 1.12 va_list args;
2580 elmex 1.1
2581 root 1.12 object *op;
2582     object *chg;
2583 elmex 1.1
2584 root 1.12 va_start (args, type);
2585 elmex 1.1
2586 root 1.12 op = va_arg (args, object *);
2587     chg = va_arg (args, object *);
2588 elmex 1.1
2589 root 1.12 va_end (args);
2590 elmex 1.1
2591 root 1.12 transmute_materialname (op, chg);
2592     *type = CFAPI_NONE;
2593     return NULL;
2594 elmex 1.1 }
2595 root 1.12
2596     void *
2597     cfapi_object_remove (int *type, ...)
2598 elmex 1.1 {
2599 root 1.12 va_list args;
2600     object *op;
2601 elmex 1.1
2602 root 1.12 va_start (args, type);
2603 elmex 1.1
2604 root 1.12 op = va_arg (args, object *);
2605 elmex 1.1
2606 root 1.12 va_end (args);
2607 elmex 1.1
2608 root 1.12 send_removed_object (op);
2609 root 1.20 op->remove ();
2610 root 1.12 *type = CFAPI_NONE;
2611     return NULL;
2612 elmex 1.1 }
2613 root 1.12
2614     void *
2615     cfapi_object_delete (int *type, ...)
2616 elmex 1.1 {
2617 root 1.12 va_list args;
2618     object *op;
2619 elmex 1.1
2620 root 1.12 va_start (args, type);
2621 elmex 1.1
2622 root 1.12 op = va_arg (args, object *);
2623 elmex 1.1
2624 root 1.12 va_end (args);
2625 elmex 1.1
2626 root 1.21 op->destroy ();
2627 elmex 1.1
2628 root 1.12 *type = CFAPI_NONE;
2629     return NULL;
2630 elmex 1.1 }
2631 root 1.12
2632     void *
2633     cfapi_object_clone (int *type, ...)
2634 elmex 1.1 {
2635 root 1.12 va_list args;
2636     object *op;
2637     int kind;
2638    
2639     va_start (args, type);
2640 elmex 1.1
2641 root 1.12 op = va_arg (args, object *);
2642     kind = va_arg (args, int);
2643 elmex 1.1
2644 root 1.12 va_end (args);
2645 elmex 1.1
2646 root 1.12 if (kind == 0)
2647     {
2648     *type = CFAPI_POBJECT;
2649     return object_create_clone (op);
2650     }
2651     else
2652     {
2653 root 1.22 object *tmp = op->clone ();
2654 root 1.12 *type = CFAPI_POBJECT;
2655     return tmp;
2656 elmex 1.1 }
2657     }
2658 root 1.12 void *
2659     cfapi_object_find (int *type, ...)
2660 elmex 1.1 {
2661 root 1.12 va_list args;
2662     int ftype;
2663     void *rv;
2664     int ival;
2665     int ival2;
2666     char *sval;
2667     object *op;
2668    
2669     va_start (args, type);
2670 elmex 1.1
2671 root 1.12 *type = CFAPI_POBJECT;
2672     ftype = va_arg (args, int);
2673    
2674     switch (ftype)
2675 elmex 1.1 {
2676 root 1.12 case 0:
2677     ival = va_arg (args, int);
2678    
2679     rv = find_object (ival);
2680     break;
2681    
2682     case 1:
2683     sval = va_arg (args, char *);
2684    
2685     rv = find_object_name (sval);
2686     break;
2687 elmex 1.1
2688 root 1.12 case 2:
2689     op = va_arg (args, object *);
2690     ival = va_arg (args, int);
2691     ival2 = va_arg (args, int);
2692 elmex 1.1
2693 root 1.12 rv = find_obj_by_type_subtype (op, ival, ival2);
2694     break;
2695 elmex 1.1
2696 root 1.12 case 3:
2697     op = va_arg (args, object *);
2698 elmex 1.1
2699 root 1.12 rv = is_player_inv (op);
2700     break;
2701    
2702     default:
2703     rv = NULL;
2704     *type = CFAPI_NONE;
2705     break;
2706 elmex 1.1 }
2707    
2708 root 1.12 va_end (args);
2709 elmex 1.1
2710 root 1.12 return rv;
2711 elmex 1.1 }
2712 root 1.12
2713     void *
2714     cfapi_object_create (int *type, ...)
2715 elmex 1.1 {
2716 root 1.12 va_list args;
2717     int ival;
2718    
2719     va_start (args, type);
2720     ival = va_arg (args, int);
2721 elmex 1.1
2722 root 1.12 *type = CFAPI_POBJECT;
2723     switch (ival)
2724 elmex 1.1 {
2725 root 1.12 case 0:
2726     va_end (args);
2727 root 1.21 return object::create ();
2728 root 1.12 break;
2729    
2730     case 1: /* Named object. Nearly the old plugin behavior, but we don't add artifact suffixes */
2731     {
2732     char *sval;
2733     object *op;
2734     sval = va_arg (args, char *);
2735    
2736     op = get_archetype_by_object_name (sval);
2737    
2738     if (strncmp (query_name (op), ARCH_SINGULARITY, ARCH_SINGULARITY_LEN) == 0)
2739     {
2740 root 1.21 op->destroy ();
2741 elmex 1.1 /* Try with archetype names... */
2742 root 1.12 op = get_archetype (sval);
2743     if (strncmp (query_name (op), ARCH_SINGULARITY, ARCH_SINGULARITY_LEN) == 0)
2744     {
2745 root 1.21 op->destroy ();
2746 elmex 1.1 *type = CFAPI_NONE;
2747 root 1.12 va_end (args);
2748 elmex 1.1 return NULL;
2749 root 1.12 }
2750     }
2751     va_end (args);
2752 elmex 1.1 return op;
2753 root 1.12 }
2754     break;
2755    
2756     default:
2757     *type = CFAPI_NONE;
2758     va_end (args);
2759     return NULL;
2760     break;
2761     }
2762     }
2763     void *
2764     cfapi_object_insert (int *type, ...)
2765     {
2766     va_list args;
2767     object *op;
2768     object *orig;
2769 root 1.16 maptile *map;
2770 root 1.12 int flag, x, y;
2771     int itype;
2772     char *arch_string;
2773     void *rv = NULL;
2774    
2775     va_start (args, type);
2776    
2777     op = va_arg (args, object *);
2778     itype = va_arg (args, int);
2779    
2780     switch (itype)
2781     {
2782     case 0:
2783 root 1.16 map = va_arg (args, maptile *);
2784 root 1.12 orig = va_arg (args, object *);
2785     flag = va_arg (args, int);
2786     x = va_arg (args, int);
2787     y = va_arg (args, int);
2788    
2789     rv = insert_ob_in_map_at (op, map, orig, flag, x, y);
2790     *type = CFAPI_POBJECT;
2791     break;
2792    
2793     case 1:
2794 root 1.16 map = va_arg (args, maptile *);
2795 root 1.12 orig = va_arg (args, object *);
2796     flag = va_arg (args, int);
2797    
2798     rv = insert_ob_in_map (op, map, orig, flag);
2799     *type = CFAPI_POBJECT;
2800     break;
2801    
2802     case 2:
2803     arch_string = va_arg (args, char *);
2804    
2805     replace_insert_ob_in_map (arch_string, op);
2806     *type = CFAPI_NONE;
2807     break;
2808    
2809     case 3:
2810     orig = va_arg (args, object *);
2811 elmex 1.1
2812 root 1.12 rv = insert_ob_in_ob (op, orig);
2813     if (orig->type == PLAYER)
2814     {
2815     esrv_send_item (orig, op);
2816     }
2817     *type = CFAPI_POBJECT;
2818     break;
2819 elmex 1.1 }
2820    
2821 root 1.12 va_end (args);
2822 elmex 1.1
2823 root 1.12 return rv;
2824 elmex 1.1 }
2825 root 1.12
2826     void *
2827     cfapi_object_split (int *type, ...)
2828 elmex 1.1 {
2829 root 1.12 va_list args;
2830 elmex 1.1
2831 root 1.12 int nr;
2832     object *op;
2833 elmex 1.1
2834 root 1.12 va_start (args, type);
2835 elmex 1.1
2836 root 1.12 op = va_arg (args, object *);
2837     nr = va_arg (args, int);
2838    
2839     va_end (args);
2840     *type = CFAPI_POBJECT;
2841     return get_split_ob (op, nr);
2842 elmex 1.1 }
2843 root 1.12
2844     void *
2845     cfapi_object_merge (int *type, ...)
2846 elmex 1.1 {
2847 root 1.12 va_list args;
2848     object *op;
2849     object *op2;
2850 elmex 1.1
2851 root 1.12 va_start (args, type);
2852 elmex 1.1
2853 root 1.12 op = va_arg (args, object *);
2854     op2 = va_arg (args, object *);
2855 elmex 1.1
2856 root 1.12 va_end (args);
2857 elmex 1.1
2858    
2859 root 1.12 *type = CFAPI_POBJECT;
2860     return merge_ob (op, op2);
2861 elmex 1.1 }
2862 root 1.12
2863     void *
2864     cfapi_object_distance (int *type, ...)
2865 elmex 1.1 {
2866 root 1.12 va_list args;
2867     static int rv;
2868     object *op;
2869     object *op2;
2870    
2871     va_start (args, type);
2872 elmex 1.1
2873 root 1.12 op = va_arg (args, object *);
2874     op2 = va_arg (args, object *);
2875 elmex 1.1
2876 root 1.12 va_end (args);
2877 elmex 1.1
2878 root 1.12 *type = CFAPI_INT;
2879     rv = distance (op, op2);
2880     return &rv;
2881 elmex 1.1 }
2882 root 1.12
2883     void *
2884     cfapi_object_update (int *type, ...)
2885 elmex 1.1 {
2886 root 1.12 va_list args;
2887     int action;
2888     object *op;
2889    
2890     va_start (args, type);
2891 elmex 1.1
2892 root 1.12 op = va_arg (args, object *);
2893     action = va_arg (args, int);
2894 elmex 1.1
2895 root 1.12 va_end (args);
2896 elmex 1.1
2897 root 1.12 update_object (op, action);
2898     *type = CFAPI_NONE;
2899     return NULL;
2900 elmex 1.1 }
2901 root 1.12
2902     void *
2903     cfapi_object_clear (int *type, ...)
2904 elmex 1.1 {
2905 root 1.12 va_list args;
2906     object *op;
2907 elmex 1.1
2908 root 1.12 va_start (args, type);
2909 elmex 1.1
2910 root 1.12 op = va_arg (args, object *);
2911 elmex 1.1
2912 root 1.12 va_end (args);
2913    
2914 root 1.23 op->clear ();
2915 root 1.12 *type = CFAPI_NONE;
2916     return NULL;
2917 elmex 1.1 }
2918 root 1.12
2919     void *
2920     cfapi_object_reset (int *type, ...)
2921 elmex 1.1 {
2922 root 1.12 abort ();
2923 elmex 1.1 }
2924    
2925 root 1.12 void *
2926     cfapi_object_check_inventory (int *type, ...)
2927 elmex 1.1 {
2928 root 1.12 va_list args;
2929     object *op;
2930     object *op2;
2931     int checktype;
2932     object *ret = NULL;
2933 elmex 1.1
2934 root 1.12 va_start (args, type);
2935 elmex 1.1
2936 root 1.12 op = va_arg (args, object *);
2937     op2 = va_arg (args, object *);
2938     checktype = va_arg (args, int);
2939 elmex 1.1
2940 root 1.12 if (checktype == 0)
2941     {
2942     check_inv (op, op2);
2943     *type = CFAPI_NONE;
2944     }
2945     else
2946     {
2947     ret = check_inv_recursive (op, op2);
2948     *type = CFAPI_POBJECT;
2949 elmex 1.1 }
2950    
2951 root 1.12 va_end (args);
2952    
2953     return ret;
2954     }
2955    
2956     void *
2957     cfapi_object_clean_object (int *type, ...)
2958     {
2959     va_list args;
2960     object *op;
2961    
2962     va_start (args, type);
2963     op = va_arg (args, object *);
2964    
2965     clean_object (op);
2966     va_end (args);
2967     *type = CFAPI_NONE;
2968     return NULL;
2969     }
2970    
2971     void *
2972     cfapi_object_on_same_map (int *type, ...)
2973     {
2974     va_list args;
2975     static int rv;
2976     object *op1;
2977     object *op2;
2978    
2979     va_start (args, type);
2980     op1 = va_arg (args, object *);
2981     op2 = va_arg (args, object *);
2982    
2983     rv = on_same_map (op1, op2);
2984     va_end (args);
2985    
2986     *type = CFAPI_INT;
2987     return &rv;
2988     }
2989    
2990     void *
2991     cfapi_object_spring_trap (int *type, ...)
2992     {
2993     object *trap;
2994     object *victim;
2995     va_list args;
2996    
2997     va_start (args, type);
2998     trap = va_arg (args, object *);
2999     victim = va_arg (args, object *);
3000 elmex 1.1
3001 root 1.12 va_end (args);
3002    
3003     spring_trap (trap, victim);
3004     *type = CFAPI_NONE;
3005     return NULL;
3006     }
3007    
3008     void *
3009     cfapi_object_check_trigger (int *type, ...)
3010     {
3011     object *op;
3012     object *cause;
3013     va_list args;
3014     static int rv;
3015    
3016     va_start (args, type);
3017     op = va_arg (args, object *);
3018     cause = va_arg (args, object *);
3019    
3020     va_end (args);
3021    
3022     rv = check_trigger (op, cause);
3023     *type = CFAPI_INT;
3024     return &rv;
3025     }
3026    
3027     void *
3028     cfapi_object_query_cost (int *type, ...)
3029     {
3030     object *op;
3031     object *who;
3032     int flags;
3033     va_list args;
3034     static int rv;
3035    
3036     va_start (args, type);
3037     op = va_arg (args, object *);
3038     who = va_arg (args, object *);
3039     flags = va_arg (args, int);
3040    
3041     va_end (args);
3042    
3043     rv = query_cost (op, who, flags);
3044     *type = CFAPI_INT;
3045     return &rv;
3046     }
3047    
3048     void *
3049     cfapi_object_query_money (int *type, ...)
3050     {
3051     object *op;
3052     va_list args;
3053     static int rv;
3054    
3055     va_start (args, type);
3056     op = va_arg (args, object *);
3057    
3058     va_end (args);
3059    
3060     rv = query_money (op);
3061     *type = CFAPI_INT;
3062     return &rv;
3063 elmex 1.1 }
3064    
3065 root 1.12 void *
3066     cfapi_object_cast (int *type, ...)
3067 elmex 1.1 {
3068 root 1.12 object *op;
3069     object *sp;
3070     int dir;
3071     char *str;
3072     object *caster;
3073     va_list args;
3074     static int rv;
3075    
3076     va_start (args, type);
3077     op = va_arg (args, object *);
3078     caster = va_arg (args, object *);
3079     dir = va_arg (args, int);
3080     sp = va_arg (args, object *);
3081     str = va_arg (args, char *);
3082    
3083     va_end (args);
3084     rv = cast_spell (op, caster, dir, sp, str);
3085     *type = CFAPI_INT;
3086     return &rv;
3087 elmex 1.1 }
3088 root 1.12
3089     void *
3090     cfapi_object_learn_spell (int *type, ...)
3091 elmex 1.1 {
3092 root 1.12 object *op;
3093     object *sp;
3094     int prayer;
3095     va_list args;
3096    
3097     va_start (args, type);
3098     op = va_arg (args, object *);
3099     sp = va_arg (args, object *);
3100     prayer = va_arg (args, int);
3101 elmex 1.1
3102 root 1.12 va_end (args);
3103     do_learn_spell (op, sp, prayer);
3104     *type = CFAPI_NONE;
3105     return NULL;
3106     }
3107    
3108     void *
3109     cfapi_object_forget_spell (int *type, ...)
3110     {
3111     object *op;
3112     object *sp;
3113     va_list args;
3114 elmex 1.1
3115 root 1.12 va_start (args, type);
3116     op = va_arg (args, object *);
3117     sp = va_arg (args, object *);
3118 elmex 1.1
3119 root 1.12 va_end (args);
3120     do_forget_spell (op, query_name (sp));
3121     *type = CFAPI_NONE;
3122     return NULL;
3123 elmex 1.1 }
3124    
3125 root 1.12 void *
3126     cfapi_object_check_spell (int *type, ...)
3127 elmex 1.1 {
3128 root 1.12 object *op;
3129     char *spellname;
3130     va_list args;
3131     object *rv;
3132 elmex 1.1
3133 root 1.12 va_start (args, type);
3134     op = va_arg (args, object *);
3135     spellname = va_arg (args, char *);
3136 elmex 1.1
3137 root 1.12 va_end (args);
3138     rv = check_spell_known (op, spellname);
3139     *type = CFAPI_POBJECT;
3140     return rv;
3141 elmex 1.1 }
3142    
3143 root 1.12 void *
3144     cfapi_object_pay_amount (int *type, ...)
3145 elmex 1.1 {
3146 root 1.12 object *op;
3147     uint64 amount;
3148     va_list args;
3149     static int rv;
3150    
3151     va_start (args, type);
3152     op = va_arg (args, object *);
3153    
3154     amount = va_arg (args, uint64);
3155     va_end (args);
3156    
3157     rv = pay_for_amount (amount, op);
3158     *type = CFAPI_INT;
3159     return &rv;
3160 elmex 1.1 }
3161 root 1.12
3162     void *
3163     cfapi_object_pay_item (int *type, ...)
3164 elmex 1.1 {
3165 root 1.12 object *op;
3166     object *tobuy;
3167    
3168     va_list args;
3169     static int rv;
3170    
3171     va_start (args, type);
3172     tobuy = va_arg (args, object *);
3173     op = va_arg (args, object *);
3174    
3175     va_end (args);
3176    
3177     rv = pay_for_item (tobuy, op);
3178     *type = CFAPI_INT;
3179     return &rv;
3180 elmex 1.1 }
3181 root 1.12
3182     void *
3183     cfapi_object_transfer (int *type, ...)
3184 elmex 1.1 {
3185 root 1.12 object *op;
3186     object *originator;
3187     int x, y, randompos, ttype;
3188     va_list args;
3189     static int rv = 0;
3190 root 1.16 maptile *map;
3191 root 1.12
3192     va_start (args, type);
3193     op = va_arg (args, object *);
3194     ttype = va_arg (args, int);
3195    
3196     switch (ttype)
3197     {
3198     case 0:
3199     x = va_arg (args, int);
3200     y = va_arg (args, int);
3201     randompos = va_arg (args, int);
3202     originator = va_arg (args, object *);
3203    
3204     va_end (args);
3205    
3206     rv = transfer_ob (op, x, y, randompos, originator);
3207     *type = CFAPI_INT;
3208     return &rv;
3209     break;
3210    
3211     case 1:
3212     x = va_arg (args, int);
3213     y = va_arg (args, int);
3214 root 1.16 map = va_arg (args, maptile *);
3215 root 1.12
3216     va_end (args);
3217     if (x < 0 || y < 0)
3218     {
3219     x = map->enter_x;
3220     y = map->enter_y;
3221     }
3222    
3223 elmex 1.1 /*
3224 root 1.21 originator = object::create();
3225 elmex 1.1 EXIT_PATH(originator) = add_string(map->path);
3226     EXIT_X(originator) = x;
3227     EXIT_Y(originator) = y;
3228     printf("B Transfer: X=%d, Y=%d, OP=%s\n", x, y, op->name);*/
3229 root 1.12 /*enter_exit(op, originator); */
3230     insert_ob_in_map_at (op, map, NULL, 0, x, y);
3231     /*printf("A Transfer: X=%d, Y=%d, MAP=%s\n", x, y, op->map->name);
3232 root 1.21 originator->destroy ();
3233 root 1.12 */
3234     *type = CFAPI_INT;
3235     return &rv;
3236     break;
3237    
3238     default:
3239     *type = CFAPI_NONE;
3240     return NULL;
3241     break;
3242 elmex 1.1 }
3243     }
3244    
3245 root 1.12 void *
3246     cfapi_object_find_archetype_inside (int *type, ...)
3247     {
3248     object *op;
3249     int critera;
3250     char *str;
3251     va_list args;
3252     object *rv;
3253    
3254     *type = CFAPI_POBJECT;
3255     va_start (args, type);
3256     op = va_arg (args, object *);
3257     critera = va_arg (args, int);
3258    
3259     switch (critera)
3260     {
3261     case 0: /* By name, either exact or from query_name */
3262     str = va_arg (args, char *);
3263    
3264 root 1.14 rv = present_arch_in_ob (archetype::find (str), op);
3265 root 1.12 if (rv == NULL)
3266     {
3267     object *tmp;
3268    
3269     /* Search by query_name instead */
3270     for (tmp = op->inv; tmp; tmp = tmp->below)
3271     {
3272     if (!strncmp (query_name (tmp), str, strlen (str)))
3273 elmex 1.1 rv = tmp;
3274 root 1.12 if (!strncmp (tmp->name, str, strlen (str)))
3275 elmex 1.1 rv = tmp;
3276 root 1.12 if (rv != NULL)
3277 elmex 1.1 break;
3278 root 1.12 }
3279 elmex 1.1 }
3280 root 1.12 break;
3281 elmex 1.1
3282 root 1.12 default:
3283     rv = NULL;
3284     break;
3285 elmex 1.1 }
3286 root 1.12 va_end (args);
3287 elmex 1.1
3288 root 1.12 if (rv == NULL)
3289     {
3290     *type = CFAPI_NONE;
3291 elmex 1.1 }
3292 root 1.12 return rv;
3293 elmex 1.1 }
3294    
3295 root 1.12 void *
3296     cfapi_object_drop (int *type, ...)
3297 elmex 1.1 {
3298 root 1.12 object *op;
3299     object *author;
3300     va_list args;
3301    
3302     va_start (args, type);
3303     op = va_arg (args, object *);
3304     author = va_arg (args, object *);
3305 elmex 1.1
3306 root 1.12 va_end (args);
3307 elmex 1.1
3308 root 1.12 if (QUERY_FLAG (op, FLAG_NO_DROP))
3309     return NULL;
3310     drop (author, op);
3311 elmex 1.1
3312 root 1.12 if (author->type == PLAYER)
3313     {
3314     author->contr->count = 0;
3315 root 1.26 author->contr->socket->floorbox_update ();
3316 elmex 1.1 }
3317    
3318 root 1.12 *type = CFAPI_NONE;
3319     return NULL;
3320     }
3321    
3322     void *
3323     cfapi_object_take (int *type, ...)
3324     {
3325     object *op;
3326     object *author;
3327     va_list args;
3328    
3329     va_start (args, type);
3330     op = va_arg (args, object *);
3331     author = va_arg (args, object *);
3332    
3333     va_end (args);
3334     pick_up (author, op);
3335    
3336     *type = CFAPI_NONE;
3337     return NULL;
3338 elmex 1.1 }
3339    
3340 root 1.12 void *
3341     cfapi_object_say (int *type, ...)
3342 elmex 1.1 {
3343 root 1.12 abort ();
3344     }
3345 elmex 1.1
3346 root 1.12 void *
3347     cfapi_object_speak (int *type, ...)
3348     {
3349     abort ();
3350 elmex 1.1 }
3351    
3352     /* PLAYER SUBCLASS */
3353 root 1.12 void *
3354     cfapi_player_find (int *type, ...)
3355 elmex 1.1 {
3356 root 1.12 va_list args;
3357     void *rv;
3358     char *sval;
3359    
3360     va_start (args, type);
3361    
3362     sval = va_arg (args, char *);
3363 elmex 1.1
3364 root 1.12 va_end (args);
3365 elmex 1.1
3366 root 1.12 rv = find_player (sval);
3367 elmex 1.1
3368 root 1.12 *type = CFAPI_PPLAYER;
3369     return rv;
3370 elmex 1.1 }
3371 root 1.12
3372     void *
3373     cfapi_player_message (int *type, ...)
3374 elmex 1.1 {
3375 root 1.12 va_list args;
3376     int flags;
3377     int pri;
3378     object *pl;
3379     char *buf;
3380    
3381     va_start (args, type);
3382 elmex 1.1
3383 root 1.12 flags = va_arg (args, int);
3384     pri = va_arg (args, int);
3385     pl = va_arg (args, object *);
3386     buf = va_arg (args, char *);
3387 elmex 1.1
3388 root 1.12 va_end (args);
3389 elmex 1.1
3390 root 1.12 new_draw_info (flags, pri, pl, buf);
3391     *type = CFAPI_NONE;
3392     return NULL;
3393 elmex 1.1 }
3394 root 1.12
3395     void *
3396     cfapi_player_send_inventory (int *type, ...)
3397 elmex 1.1 {
3398 root 1.12 /* Currently a stub. Do we really need this anymore ? */
3399     *type = CFAPI_NONE;
3400     return NULL;
3401 elmex 1.1 }
3402    
3403 root 1.12 void *
3404     cfapi_object_teleport (int *type, ...)
3405 elmex 1.1 {
3406 root 1.16 maptile *map;
3407 root 1.12 int x, y;
3408     object *who;
3409     static int result;
3410     va_list args;
3411    
3412     va_start (args, type);
3413     who = va_arg (args, object *);
3414 root 1.16 map = va_arg (args, maptile *);
3415 root 1.12 x = va_arg (args, int);
3416     y = va_arg (args, int);
3417    
3418     if (!out_of_map (map, x, y))
3419     {
3420     int k;
3421     object *tmp;
3422    
3423     k = find_first_free_spot (who, map, x, y);
3424     if (k == -1)
3425     {
3426     result = 1;
3427     return &result;
3428 elmex 1.1 }
3429    
3430 root 1.12 send_removed_object (who);
3431 root 1.20 who->remove ();
3432 elmex 1.1
3433 root 1.12 for (tmp = who; tmp != NULL; tmp = tmp->more)
3434     tmp->x = x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x),
3435     tmp->y = y + freearr_y[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y);
3436 elmex 1.1
3437 root 1.12 insert_ob_in_map (who, map, NULL, 0);
3438     result = 0;
3439 elmex 1.1 }
3440    
3441 root 1.12 return &result;
3442 elmex 1.1 }
3443 root 1.12
3444     void *
3445     cfapi_object_pickup (int *type, ...)
3446 elmex 1.1 {
3447 root 1.12 object *who;
3448     object *what;
3449     va_list args;
3450    
3451     va_start (args, type);
3452     who = va_arg (args, object *);
3453     what = va_arg (args, object *);
3454 elmex 1.1
3455 root 1.12 va_end (args);
3456 elmex 1.1
3457 root 1.12 pick_up (who, what);
3458     *type = CFAPI_NONE;
3459     return NULL;
3460 elmex 1.1 }
3461    
3462     /* Archetype-related functions */
3463 root 1.12 void *
3464     cfapi_archetype_get_first (int *type, ...)
3465     {
3466     va_list args;
3467    
3468     va_start (args, type);
3469     va_end (args);
3470     *type = CFAPI_PARCH;
3471     return first_archetype;
3472     }
3473    
3474     void *
3475     cfapi_archetype_get_property (int *type, ...)
3476 elmex 1.1 {
3477 root 1.12 archetype *arch;
3478     int prop;
3479     va_list args;
3480     void *rv;
3481    
3482     va_start (args, type);
3483     arch = va_arg (args, archetype *);
3484     prop = va_arg (args, int);
3485    
3486     switch (prop)
3487     {
3488     case CFAPI_ARCH_PROP_NAME:
3489     *type = CFAPI_STRING;
3490     rv = (void *) &arch->name;
3491     break;
3492    
3493     case CFAPI_ARCH_PROP_NEXT:
3494     *type = CFAPI_PARCH;
3495     rv = arch->next;
3496     break;
3497    
3498     case CFAPI_ARCH_PROP_HEAD:
3499     *type = CFAPI_PARCH;
3500     rv = arch->head;
3501     break;
3502    
3503     case CFAPI_ARCH_PROP_MORE:
3504     *type = CFAPI_PARCH;
3505     rv = arch->more;
3506     break;
3507    
3508     case CFAPI_ARCH_PROP_CLONE:
3509     *type = CFAPI_POBJECT;
3510     rv = &arch->clone;
3511     break;
3512    
3513     default:
3514     *type = CFAPI_NONE;
3515     rv = NULL;
3516     break;
3517 elmex 1.1 }
3518 root 1.12 va_end (args);
3519     return rv;
3520 elmex 1.1 }
3521    
3522     /* Party-related functions */
3523 root 1.12 void *
3524     cfapi_party_get_property (int *type, ...)
3525 elmex 1.1 {
3526 root 1.12 partylist *party;
3527     int prop;
3528     va_list args;
3529     void *rv;
3530     object *obarg;
3531     player *pl;
3532    
3533     va_start (args, type);
3534     party = va_arg (args, partylist *);
3535     prop = va_arg (args, int);
3536    
3537     switch (prop)
3538     {
3539     case CFAPI_PARTY_PROP_NAME:
3540     *type = CFAPI_STRING;
3541     rv = (void *) party->partyname;
3542     break;
3543    
3544     case CFAPI_PARTY_PROP_NEXT:
3545     *type = CFAPI_PPARTY;
3546     rv = (party ? party->next : get_firstparty ());
3547     break;
3548    
3549     case CFAPI_PARTY_PROP_PASSWORD:
3550     *type = CFAPI_STRING;
3551     rv = (void *) party->passwd;
3552     break;
3553    
3554     case CFAPI_PARTY_PROP_PLAYER:
3555     *type = CFAPI_PPLAYER;
3556     obarg = va_arg (args, object *);
3557    
3558     pl = (obarg ? obarg->contr : first_player);
3559     rv = NULL;
3560     for (; pl != NULL; pl = pl->next)
3561     if (pl->ob->contr->party == party)
3562     {
3563     rv = (void *) pl;
3564 elmex 1.1 break;
3565 root 1.12 }
3566     break;
3567 elmex 1.1
3568 root 1.12 default:
3569     *type = CFAPI_NONE;
3570     rv = NULL;
3571     break;
3572 elmex 1.1 }
3573 root 1.12 va_end (args);
3574     return rv;
3575 elmex 1.1 }
3576    
3577     /* Regions-related functions */
3578 root 1.12 void *
3579     cfapi_region_get_property (int *type, ...)
3580 elmex 1.1 {
3581 root 1.12 region *reg;
3582     int prop;
3583     va_list args;
3584     void *rv;
3585    
3586     va_start (args, type);
3587     reg = va_arg (args, region *);
3588     prop = va_arg (args, int);
3589    
3590     switch (prop)
3591     {
3592     case CFAPI_REGION_PROP_NAME:
3593     *type = CFAPI_STRING;
3594     rv = (void *) reg->name;
3595     break;
3596    
3597     case CFAPI_REGION_PROP_NEXT:
3598     *type = CFAPI_PREGION;
3599     rv = (reg ? reg->next : first_region);
3600     break;
3601    
3602     case CFAPI_REGION_PROP_PARENT:
3603     *type = CFAPI_PREGION;
3604     rv = (void *) reg->parent;
3605     break;
3606    
3607     case CFAPI_REGION_PROP_LONGNAME:
3608     *type = CFAPI_STRING;
3609     rv = (void *) reg->longname;
3610     break;
3611    
3612     case CFAPI_REGION_PROP_MESSAGE:
3613     *type = CFAPI_STRING;
3614     rv = (void *) reg->msg;
3615     break;
3616    
3617     default:
3618     *type = CFAPI_NONE;
3619     rv = NULL;
3620     break;
3621 elmex 1.1 }
3622 root 1.12 va_end (args);
3623     return rv;
3624 elmex 1.1 }
3625    
3626     /*****************************************************************************/
3627 root 1.12
3628 elmex 1.1 /* NEW PLUGIN STUFF ENDS HERE */
3629 root 1.12
3630 elmex 1.1 /*****************************************************************************/
3631    
3632    
3633     /*****************************************************************************/
3634 root 1.12
3635 elmex 1.1 /* Tries to find if a given command is handled by a plugin. */
3636 root 1.12
3637 elmex 1.1 /* Note that find_plugin_command is called *before* the internal commands are*/
3638 root 1.12
3639 elmex 1.1 /* checked, meaning that you can "overwrite" them. */
3640 root 1.12
3641 elmex 1.1 /*****************************************************************************/
3642 root 1.12 CommArray_s *
3643     find_plugin_command (char *cmd, object *op)
3644 elmex 1.1 {
3645 root 1.12 int i;
3646     crossfire_plugin *cp;
3647     CommArray_s *rtn_cmd;
3648    
3649     if (plugins_list == NULL)
3650     return NULL;
3651    
3652     for (cp = plugins_list; cp != NULL; cp = cp->next)
3653     {
3654     rtn_cmd = (CommArray_s *) cp->propfunc (&i, "command?", cmd);
3655     if (rtn_cmd)
3656     return rtn_cmd;
3657 elmex 1.1 }
3658 root 1.12 return NULL;
3659 elmex 1.1 }
3660    
3661     /*****************************************************************************/
3662 root 1.12
3663 elmex 1.1 /* Plugins initialization. Browses the plugins directory and call */
3664 root 1.12
3665 elmex 1.1 /* initOnePlugin for each file found. */
3666 root 1.12
3667 elmex 1.1 /* Returns 0 if at least one plugin was successfully loaded, -1 if not */
3668 root 1.12
3669 elmex 1.1 /*****************************************************************************/
3670 root 1.12 int
3671     initPlugins (void)
3672 elmex 1.1 {
3673 root 1.12 struct dirent *currentfile;
3674     DIR *plugdir;
3675     size_t l;
3676     char buf[MAX_BUF];
3677     char buf2[MAX_BUF];
3678     int result;
3679    
3680     LOG (llevInfo, "Initializing plugins\n");
3681     strcpy (buf, LIBDIR);
3682     strcat (buf, "/plugins/");
3683     LOG (llevInfo, "Plugins directory is %s\n", buf);
3684    
3685     plugins_init_perl ();
3686    
3687     plugdir = opendir (buf);
3688     if (plugdir == NULL)
3689     return -1;
3690    
3691     result = -1;
3692     while ((currentfile = readdir (plugdir)) != NULL)
3693     {
3694     l = strlen (currentfile->d_name);
3695     if (l > strlen (PLUGIN_SUFFIX))
3696     {
3697     if (strcmp (currentfile->d_name + l - strlen (PLUGIN_SUFFIX), PLUGIN_SUFFIX) == 0)
3698     {
3699     strcpy (buf2, buf);
3700     strcat (buf2, currentfile->d_name);
3701     LOG (llevInfo, " -> Loading plugin : %s\n", currentfile->d_name);
3702     if (plugins_init_plugin (buf2) == 0)
3703     result = 0;
3704 elmex 1.1 }
3705     }
3706     }
3707    
3708 root 1.12 closedir (plugdir);
3709     return result;
3710 elmex 1.1 }