Crossfire Server, Trunk  R22047
plugins.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
22 #if 0
23 
24 #define PLUGIN_DEBUG
25 #endif
26 
27 /*****************************************************************************/
28 /* First, the headers. We only include plugin.h, because all other includes */
29 /* are done into it, and plugproto.h (which is used only by this file). */
30 /*****************************************************************************/
31 
32 #include <assert.h>
33 #include <stdlib.h>
34 #include <string.h>
35 
36 #include "plugin.h"
37 #include "shop.h"
38 #include "sproto.h"
39 #include "svnversion.h"
40 #include "timers.h"
41 
43 #define NR_OF_HOOKS (sizeof(plug_hooks)/sizeof(*plug_hooks))
44 
45 static void cfapi_cost_string_from_value(int *type, ...);
46 static void cfapi_system_find_animation(int *type, ...);
47 static void cfapi_system_find_face(int *type, ...);
48 static void cfapi_system_strdup_local(int *type, ...);
49 static void cfapi_system_register_global_event(int *type, ...);
50 static void cfapi_system_unregister_global_event(int *type, ...);
51 static void cfapi_system_add_string(int *type, ...);
52 static void cfapi_system_remove_string(int *type, ...);
53 static void cfapi_system_find_string(int *type, ...);
54 static void cfapi_system_check_path(int *type, ...);
55 static void cfapi_system_re_cmp(int *type, ...);
56 static void cfapi_system_directory(int *type, ...);
57 static void cfapi_get_time(int *type, ...);
58 static void cfapi_get_season_name(int *type, ...);
59 static void cfapi_get_weekday_name(int *type, ...);
60 static void cfapi_get_month_name(int *type, ...);
61 static void cfapi_get_periodofday_name(int *type, ...);
62 static void cfapi_timer_create(int *type, ...);
63 static void cfapi_timer_destroy(int *type, ...);
64 static void cfapi_log(int *type, ...);
65 static void cfapi_map_get_map(int *type, ...);
66 static void cfapi_map_has_been_loaded(int *type, ...);
67 static void cfapi_map_create_path(int *type, ...);
68 static void cfapi_map_get_map_property(int *type, ...);
69 static void cfapi_map_set_map_property(int *type, ...);
70 static void cfapi_map_out_of_map(int *type, ...);
71 static void cfapi_map_update_position(int *type, ...);
72 static void cfapi_map_delete_map(int *type, ...);
73 static void cfapi_map_message(int *type, ...);
74 static void cfapi_map_get_object_at(int *type, ...);
75 static void cfapi_map_find_by_archetype_name(int *type, ...);
76 static void cfapi_map_change_light(int *type, ...);
77 static void cfapi_object_move(int *type, ...);
78 static void cfapi_object_get_key(int *type, ...);
79 static void cfapi_object_set_key(int *type, ...);
80 static void cfapi_object_get_property(int *type, ...);
81 static void cfapi_object_set_property(int *type, ...);
82 static void cfapi_object_apply_below(int *type, ...);
83 static void cfapi_object_apply(int *type, ...);
84 static void cfapi_object_identify(int *type, ...);
85 static void cfapi_object_describe(int *type, ...);
86 static void cfapi_object_drain(int *type, ...);
87 static void cfapi_object_remove_depletion(int *type, ...);
88 static void cfapi_object_fix(int *type, ...);
89 static void cfapi_object_give_skill(int *type, ...);
90 static void cfapi_object_transmute(int *type, ...);
91 static void cfapi_object_remove(int *type, ...);
92 static void cfapi_object_delete(int *type, ...);
93 static void cfapi_object_clone(int *type, ...);
94 static void cfapi_object_create(int *type, ...);
95 static void cfapi_object_insert(int *type, ...);
96 static void cfapi_object_split(int *type, ...);
97 static void cfapi_object_merge(int *type, ...);
98 static void cfapi_object_distance(int *type, ...);
99 static void cfapi_object_update(int *type, ...);
100 static void cfapi_object_clear(int *type, ...);
101 static void cfapi_object_reset(int *type, ...);
102 static void cfapi_object_clean_object(int *type, ...);
103 static void cfapi_object_on_same_map(int *type, ...);
104 static void cfapi_object_spring_trap(int *type, ...);
105 static void cfapi_object_check_trigger(int *type, ...);
106 static void cfapi_map_trigger_connected(int *type, ...);
107 static void cfapi_object_query_money(int *type, ...);
108 static void cfapi_object_cast(int *type, ...);
109 static void cfapi_object_learn_spell(int *type, ...);
110 static void cfapi_object_forget_spell(int *type, ...);
111 static void cfapi_object_check_spell(int *type, ...);
112 static void cfapi_object_pay_amount(int *type, ...);
113 static void cfapi_object_pay_item(int *type, ...);
114 static void cfapi_object_transfer(int *type, ...);
115 static void cfapi_object_find_archetype_inside(int *type, ...);
116 static void cfapi_object_find_by_arch_name(int *type, ...);
117 static void cfapi_object_find_by_name(int *type, ...);
118 static void cfapi_object_drop(int *type, ...);
119 static void cfapi_object_change_abil(int *type, ...);
120 static void cfapi_object_say(int *type, ...);
121 static void cfapi_player_find(int *type, ...);
122 static void cfapi_player_message(int *type, ...);
123 static void cfapi_object_change_exp(int *type, ...);
124 static void cfapi_player_can_pay(int *type, ...);
125 static void cfapi_player_knowledge(int *type, ...);
126 static void cfapi_object_teleport(int *type, ...);
127 static void cfapi_object_pickup(int *type, ...);
128 static void cfapi_archetype_get_property(int *type, ...);
129 static void cfapi_party_get_property(int *type, ...);
130 static void cfapi_region_get_property(int *type, ...);
131 static void cfapi_friendlylist_get_next(int *type, ...);
132 static void cfapi_set_random_map_variable(int *type, ...);
133 static void cfapi_generate_random_map(int *type, ...);
134 static void cfapi_object_user_event(int *type, ...);
135 static void cfapi_player_quest(int *type, ...);
136 static void cfapi_object_perm_exp(int *type, ...);
137 
141 static const hook_entry plug_hooks[] = {
142  { cfapi_system_add_string, 0, "cfapi_system_add_string" },
143  { cfapi_system_register_global_event, 1, "cfapi_system_register_global_event" },
144  { cfapi_system_remove_string, 2, "cfapi_system_remove_string" },
145  { cfapi_system_unregister_global_event, 3, "cfapi_system_unregister_global_event" },
146  { cfapi_system_check_path, 4, "cfapi_system_check_path" },
147  { cfapi_system_re_cmp, 5, "cfapi_system_re_cmp" },
148  { cfapi_system_strdup_local, 6, "cfapi_system_strdup_local" },
149  { cfapi_system_directory, 7, "cfapi_system_directory" },
150  { cfapi_system_find_animation, 8, "cfapi_system_find_animation" },
151  { cfapi_object_clean_object, 9, "cfapi_object_clean_object" },
152  { cfapi_object_on_same_map, 10, "cfapi_object_on_same_map" },
153  { cfapi_object_get_key, 11, "cfapi_object_get_key" },
154  { cfapi_object_set_key, 12, "cfapi_object_set_key" },
155  { cfapi_object_get_property, 13, "cfapi_object_get_property" },
156  { cfapi_object_set_property, 14, "cfapi_object_set_property" },
157  { cfapi_object_apply, 15, "cfapi_object_apply" },
158  { cfapi_object_identify, 16, "cfapi_object_identify" },
159  { cfapi_object_describe, 17, "cfapi_object_describe" },
160  { cfapi_object_drain, 18, "cfapi_object_drain" },
161  { cfapi_object_fix, 19, "cfapi_object_fix" },
162  { cfapi_object_give_skill, 20, "cfapi_object_give_skill" },
163  { cfapi_object_transmute, 21, "cfapi_object_transmute" },
164  { cfapi_object_remove, 22, "cfapi_object_remove" },
165  { cfapi_object_delete, 23, "cfapi_object_delete" },
166  { cfapi_object_clone, 24, "cfapi_object_clone" },
167  { cfapi_object_create, 26, "cfapi_object_create" },
168  { cfapi_object_insert, 27, "cfapi_object_insert" },
169  { cfapi_object_split, 28, "cfapi_object_split" },
170  { cfapi_object_merge, 29, "cfapi_object_merge" },
171  { cfapi_object_distance, 30, "cfapi_object_distance" },
172  { cfapi_object_update, 31, "cfapi_object_update" },
173  { cfapi_object_clear, 32, "cfapi_object_clear" },
174  { cfapi_object_reset, 33, "cfapi_object_reset" },
175  { cfapi_object_spring_trap, 35, "cfapi_object_spring_trap" },
176  { cfapi_object_check_trigger, 36, "cfapi_object_check_trigger" },
177  { cfapi_object_query_money, 38, "cfapi_object_query_money" },
178  { cfapi_object_cast, 39, "cfapi_object_cast" },
179  { cfapi_object_learn_spell, 40, "cfapi_object_learn_spell" },
180  { cfapi_object_forget_spell, 41, "cfapi_object_forget_spell" },
181  { cfapi_object_check_spell, 42, "cfapi_object_check_spell" },
182  { cfapi_object_pay_amount, 43, "cfapi_object_pay_amount" },
183  { cfapi_object_pay_item, 44, "cfapi_object_pay_item" },
184  { cfapi_object_transfer, 45, "cfapi_object_transfer" },
185  { cfapi_object_drop, 46, "cfapi_object_drop" },
186  { cfapi_object_change_abil, 47, "cfapi_object_change_abil" },
187  { cfapi_object_find_archetype_inside, 48, "cfapi_object_find_archetype_inside" },
188  { cfapi_object_say, 49, "cfapi_object_say" },
189  { cfapi_map_get_map, 50, "cfapi_map_get_map" },
190  { cfapi_map_has_been_loaded, 51, "cfapi_map_has_been_loaded" },
191  { cfapi_map_create_path, 52, "cfapi_map_create_path" },
192  { cfapi_map_get_map_property, 53, "cfapi_map_get_property" },
193  { cfapi_map_set_map_property, 54, "cfapi_map_set_property" },
194  { cfapi_map_out_of_map, 55, "cfapi_map_out_of_map" },
195  { cfapi_map_update_position, 56, "cfapi_map_update_position" },
196  { cfapi_map_delete_map, 57, "cfapi_map_delete_map" },
197  { cfapi_map_message, 58, "cfapi_map_message" },
198  { cfapi_map_get_object_at, 59, "cfapi_map_get_object_at" },
199  { cfapi_map_change_light, 60, "cfapi_map_change_light" },
200  { cfapi_map_find_by_archetype_name, 61, "cfapi_map_find_by_archetype_name" },
201  { cfapi_player_find, 62, "cfapi_player_find" },
202  { cfapi_player_message, 63, "cfapi_player_message" },
203  { cfapi_object_change_exp, 64, "cfapi_object_change_exp" },
204  { cfapi_object_teleport, 65, "cfapi_object_teleport" },
205  { cfapi_object_pickup, 67, "cfapi_object_pickup" },
206  { cfapi_object_move, 68, "cfapi_object_move" },
207  { cfapi_object_apply_below, 69, "cfapi_object_apply_below" },
208  { cfapi_generate_random_map, 70, "cfapi_generate_random_map" },
209  { cfapi_archetype_get_property, 71, "cfapi_archetype_get_property" },
210  { cfapi_party_get_property, 72, "cfapi_party_get_property" },
211  { cfapi_region_get_property, 73, "cfapi_region_get_property" },
212  { cfapi_player_can_pay, 74, "cfapi_player_can_pay" },
213  { cfapi_log, 75, "cfapi_log" },
214  { cfapi_get_time, 76, "cfapi_system_get_time" },
215  { cfapi_timer_create, 77, "cfapi_system_timer_create" },
216  { cfapi_timer_destroy, 78, "cfapi_system_timer_destroy" },
217  { cfapi_friendlylist_get_next, 79, "cfapi_friendlylist_get_next" },
218  { cfapi_set_random_map_variable, 80, "cfapi_set_random_map_variable" },
219  { cfapi_system_find_face, 81, "cfapi_system_find_face" },
220  { cfapi_get_season_name, 82, "cfapi_system_get_season_name" },
221  { cfapi_get_month_name, 83, "cfapi_system_get_month_name" },
222  { cfapi_get_weekday_name, 84, "cfapi_system_get_weekday_name" },
223  { cfapi_get_periodofday_name, 85, "cfapi_system_get_periodofday_name" },
224  { cfapi_map_trigger_connected, 86, "cfapi_map_trigger_connected" },
225  { cfapi_object_user_event, 87, "cfapi_object_user_event" },
226  { cfapi_system_find_string, 88, "cfapi_system_find_string" },
227  { cfapi_cost_string_from_value, 90, "cfapi_cost_string_from_value" },
228  { cfapi_player_quest, 91, "cfapi_player_quest" },
229  { cfapi_object_remove_depletion, 92, "cfapi_object_remove_depletion" },
230  { cfapi_object_find_by_arch_name, 93, "cfapi_object_find_by_arch_name" },
231  { cfapi_object_find_by_name, 94, "cfapi_object_find_by_name" },
232  { cfapi_player_knowledge, 95, "cfapi_player_knowledge" },
233  { cfapi_object_perm_exp, 96, "cfapi_object_perm_exp" },
234 };
235 
238 
239 /*****************************************************************************/
240 /* NEW PLUGIN STUFF STARTS HERE */
241 /*****************************************************************************/
242 
248 static crossfire_plugin *plugins_find_plugin(const char *id) {
249  crossfire_plugin *cp;
250 
251  if (plugins_list == NULL)
252  return NULL;
253 
254  for (cp = plugins_list; cp != NULL; cp = cp->next) {
255  if (!strcmp(id, cp->id)) {
256  return cp;
257  }
258  }
259  return NULL;
260 }
261 
262 #ifdef WIN32
263 static const char *plugins_dlerror(void) {
264  static char buf[256];
265  DWORD err;
266  char *p;
267 
268  err = GetLastError();
269  if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, buf, sizeof(buf), NULL) == 0)
270  snprintf(buf, sizeof(buf), "error %lu", err);
271  p = strchr(buf, '\0');
272  while (p > buf && (p[-1] == '\r' || p[-1] == '\n'))
273  p--;
274  *p = '\0';
275  return buf;
276 }
277 #endif /* WIN32 */
278 
284 static void send_changed_object(object *op) {
285  object *tmp;
286  player *pl;
287 
288  if (op->env != NULL) {
289  tmp = object_get_player_container(op->env);
290  if (!tmp) {
291  for (pl = first_player; pl; pl = pl->next)
292  if (pl->ob->container == op->env)
293  break;
294  if (pl)
295  tmp = pl->ob;
296  else
297  tmp = NULL;
298  }
299  if (tmp)
300  /* We don't know what changed, so we send everything. */
301  esrv_update_item(UPD_ALL, tmp, op);
302  } else {
303  FOR_ABOVE_PREPARE(op, tmp)
304  if (tmp->type == PLAYER)
305  tmp->contr->socket.update_look = 1;
307  }
308 }
309 
310 static void cfapi_get_hooks(int *type, ...) {
311  va_list args;
312  int request_type;
313  char *buf;
314  f_plug_api *rapi;
315 
316  *type = CFAPI_NONE;
317 
318  va_start(args, type);
319  request_type = va_arg(args, int);
320  if (request_type == 0) { /* By nr */
321  size_t fid;
322 
323  fid = va_arg(args, int);
324  rapi = va_arg(args, f_plug_api *);
325  if (fid >= NR_OF_HOOKS) {
326  *rapi = NULL;
327  *type = CFAPI_NONE;
328  } else {
329  *rapi = plug_hooks[fid].func;
330  *type = CFAPI_FUNC;
331  }
332  } else { /* by name */
333  size_t i;
334 
335  buf = va_arg(args, char *);
336  rapi = va_arg(args, f_plug_api *);
337  *rapi = NULL;
338  *type = CFAPI_NONE;
339  for (i = 0; i < NR_OF_HOOKS; i++) {
340  if (!strcmp(buf, plug_hooks[i].fname)) {
341  *rapi = plug_hooks[i].func;
342  *type = CFAPI_FUNC;
343  break;
344  }
345  }
346  }
347  va_end(args);
348 }
349 
356 int plugins_init_plugin(const char *libfile) {
357  LIBPTRTYPE ptr;
358  f_plug_init initfunc;
359  f_plug_property propfunc;
360  f_plug_event eventfunc;
361  f_plug_postinit postfunc;
362  f_plug_postinit closefunc;
363  int i;
364  crossfire_plugin *cp;
365  crossfire_plugin *ccp;
366  char *svn_rev;
367 
368 
369  /* Open the plugin lib and load the required functions */
370  ptr = plugins_dlopen(libfile);
371  if (ptr == NULL) {
372  LOG(llevError, "Error trying to load %s: %s\n", libfile, plugins_dlerror());
373  return -1;
374  }
375  svn_rev = (char*) plugins_dlsym(ptr, "SvnRevPlugin");
376  if (svn_rev == NULL) {
377  LOG(llevError, "Unable to find SvnRevPlugin in %s\n", libfile);
378  plugins_dlclose(ptr);
379  return -1;
380  }
381  if (settings.ignore_plugin_compatibility == 0 && strcmp(svn_rev, SVN_REV)) {
382  LOG(llevError, "SVN Version mismatch in in %s (%s != %s)\n", libfile, svn_rev, SVN_REV);
383  plugins_dlclose(ptr);
384  return -1;
385  }
386 
387  initfunc = (f_plug_init)plugins_dlsym(ptr, "initPlugin");
388  if (initfunc == NULL) {
389  LOG(llevError, "Plugin error while requesting %s.initPlugin: %s\n", libfile, plugins_dlerror());
390  plugins_dlclose(ptr);
391  return -1;
392  }
393  propfunc = (f_plug_property)plugins_dlsym(ptr, "getPluginProperty");
394  if (propfunc == NULL) {
395  LOG(llevError, "Plugin error while requesting %s.getPluginProperty: %s\n", libfile, plugins_dlerror());
396  plugins_dlclose(ptr);
397  return -1;
398  }
399  eventfunc = (f_plug_event)plugins_dlsym(ptr, "eventListener");
400  if (eventfunc == NULL) {
401  LOG(llevError, "Plugin error while requesting %s.eventListener: %s\n", libfile, plugins_dlerror());
402  plugins_dlclose(ptr);
403  return -1;
404  }
405  postfunc = (f_plug_postinit)plugins_dlsym(ptr, "postInitPlugin");
406  if (postfunc == NULL) {
407  LOG(llevError, "Plugin error while requesting %s.postInitPlugin: %s\n", libfile, plugins_dlerror());
408  plugins_dlclose(ptr);
409  return -1;
410  }
411  closefunc = (f_plug_postinit)plugins_dlsym(ptr, "closePlugin");
412  if (closefunc == NULL) {
413  LOG(llevError, "Plugin error while requesting %s.closePlugin: %s\n", libfile, plugins_dlerror());
414  plugins_dlclose(ptr);
415  return -1;
416  }
417  i = initfunc("2.0", cfapi_get_hooks);
418  cp = malloc(sizeof(crossfire_plugin));
419  for (i = 0; i < NR_EVENTS; i++)
420  cp->global_registration[i] = 0;
421  cp->propfunc = propfunc;
422  cp->closefunc = closefunc;
423  cp->libptr = ptr;
424  propfunc(&i, "Identification", cp->id, sizeof(cp->id));
425  propfunc(&i, "FullName", cp->fullname, sizeof(cp->fullname));
426  events_register_object_handler(cp->id, eventfunc);
427  cp->next = NULL;
428  cp->prev = NULL;
429  if (plugins_list == NULL) {
430  plugins_list = cp;
431  } else {
432  for (ccp = plugins_list; ccp->next != NULL; ccp = ccp->next)
433  ;
434  ccp->next = cp;
435  cp->prev = ccp;
436  }
437  postfunc();
438  return 0;
439 }
440 
447 int plugins_remove_plugin(const char *id) {
448  crossfire_plugin *cp;
449 
450  if (plugins_list == NULL)
451  return -1;
452 
453  for (cp = plugins_list; cp != NULL; cp = cp->next) {
454  if (!strcmp(id, cp->id)) {
455  crossfire_plugin *n;
456  crossfire_plugin *p;
457 
458  for (int eventcode = 0; eventcode < NR_EVENTS; eventcode++) {
459  if (cp->global_registration[eventcode]) {
460  events_unregister_global_handler(eventcode, cp->global_registration[eventcode]);
461  }
462  }
464 
465  n = cp->next;
466  p = cp->prev;
467  if (cp->closefunc)
468  cp->closefunc();
469  plugins_dlclose(cp->libptr);
470  if (n != NULL) {
471  if (p != NULL) {
472  n->prev = p;
473  p->next = n;
474  } else {
475  n->prev = NULL;
476  plugins_list = n;
477  }
478  } else {
479  if (p != NULL)
480  p->next = NULL;
481  else
482  plugins_list = NULL;
483  }
484  free(cp);
485  return 0;
486  }
487  }
488  return -1;
489 }
490 
496 void plugins_display_list(object *op) {
497  crossfire_plugin *cp;
498 
500  "List of loaded plugins:\n-----------------------");
501 
502  if (plugins_list == NULL)
503  return;
504 
505  for (cp = plugins_list; cp != NULL; cp = cp->next) {
507  "%s, %s",
508  cp->id, cp->fullname);
509  }
510 }
511 
512 /* SYSTEM-RELATED HOOKS */
513 
519 static void cfapi_cost_string_from_value(int *type, ...) {
520  uint64_t cost;
521  char *buffer, *final;
522  int length, largest_coin;
523  va_list args;
524 
525  va_start(args, type);
526  cost = va_arg(args, uint64_t);
527  largest_coin = va_arg(args, int);
528  buffer = va_arg(args, char*);
529  length = va_arg(args, int);
530  va_end(args);
531 
532  *type = CFAPI_NONE;
533 
534  if (length < 1)
535  return;
536 
537  final = cost_string_from_value(cost, largest_coin);
538 
539  strncpy(buffer, final, length - 1);
540  buffer[length - 1] = '\0';
541  free(final);
542 }
543 
549 static void cfapi_system_find_animation(int *type, ...) {
550  va_list args;
551  const char *name;
552  int *num;
553  const Animations *anim;
554 
555  va_start(args, type);
556  name = va_arg(args, const char *);
557  num = va_arg(args, int *);
558  va_end(args);
559 
560  anim = try_find_animation(name);
561  (*num) = anim ? anim->num : 0;
562  *type = CFAPI_INT;
563 }
564 
570 static void cfapi_system_find_face(int *type, ...) {
571  va_list args;
572  const char *face;
573  int error;
574  int *num;
575  const Face *f;
576 
577  va_start(args, type);
578  face = va_arg(args, const char *);
579  error = va_arg(args, int);
580  num = va_arg(args, int *);
581  va_end(args);
582 
583  f = try_find_face(face, get_face_by_id(error));
584  (*num) = f ? f->number : 0;
585  *type = CFAPI_INT;
586 }
587 
593 static void cfapi_system_strdup_local(int *type, ...) {
594  va_list args;
595  const char *txt;
596  char **ret;
597 
598  va_start(args, type);
599  txt = va_arg(args, const char *);
600  ret = va_arg(args, char **);
601  va_end(args);
602 
603  *ret = strdup_local(txt);
604  *type = CFAPI_STRING;
605 }
606 
607 static void cfapi_system_register_global_event(int *type, ...) {
608  va_list args;
609  int eventcode;
610  char *pname;
611  f_plug_event hook;
612  crossfire_plugin *cp;
613 
614  va_start(args, type);
615  eventcode = va_arg(args, int);
616  pname = va_arg(args, char *);
617  hook = va_arg(args, f_plug_event);
618  va_end(args);
619 
620  *type = CFAPI_NONE;
621 
622  cp = plugins_find_plugin(pname);
623  if (!cp->global_registration[eventcode]) {
624  cp->global_registration[eventcode] = events_register_global_handler(eventcode, hook);
625  }
626 }
627 
628 static void cfapi_system_unregister_global_event(int *type, ...) {
629  va_list args;
630  int eventcode;
631  char *pname;
632  crossfire_plugin *cp;
633 
634  va_start(args, type);
635  eventcode = va_arg(args, int);
636  pname = va_arg(args, char *);
637  va_end(args);
638 
639  *type = CFAPI_NONE;
640 
641  cp = plugins_find_plugin(pname);
642  if (cp->global_registration[eventcode]) {
643  events_unregister_global_handler(eventcode, cp->global_registration[eventcode]);
644  cp->global_registration[eventcode] = 0;
645  }
646 }
647 
654 static void cfapi_system_add_string(int *type, ...) {
655  va_list args;
656  const char *str;
657  sstring *rv;
658 
659  va_start(args, type);
660  str = va_arg(args, const char *);
661  rv = va_arg(args, sstring *);
662  va_end(args);
663 
664  *rv = add_string(str);
665  *type = CFAPI_SSTRING;
666 }
667 
674 static void cfapi_system_remove_string(int *type, ...) {
675  va_list args;
676  sstring str;
677 
678  va_start(args, type);
679  str = va_arg(args, sstring);
680  va_end(args);
681 
682  free_string(str);
683  *type = CFAPI_NONE;
684 }
685 
692 static void cfapi_system_find_string(int *type, ...) {
693  va_list args;
694  const char *str;
695  sstring *rv;
696 
697  va_start(args, type);
698  str = va_arg(args, const char *);
699  rv = va_arg(args, sstring *);
700  va_end(args);
701 
702  *rv = find_string(str);
703  *type = CFAPI_SSTRING;
704 }
705 
711 static void cfapi_system_check_path(int *type, ...) {
712  va_list args;
713  const char *name;
714  int prepend_dir;
715  int *ret;
716 
717  va_start(args, type);
718 
719  name = va_arg(args, char *);
720  prepend_dir = va_arg(args, int);
721  ret = va_arg(args, int *);
722 
723  *ret = check_path(name, prepend_dir);
724 
725  va_end(args);
726  *type = CFAPI_INT;
727 }
728 
734 static void cfapi_system_re_cmp(int *type, ...) {
735  va_list args;
736  const char *str;
737  const char *regexp;
738  const char **rv;
739 
740  va_start(args, type);
741 
742  str = va_arg(args, char *);
743  regexp = va_arg(args, char *);
744  rv = va_arg(args, const char **);
745 
746  *rv = re_cmp(str, regexp);
747 
748  va_end(args);
749  *type = CFAPI_STRING;
750 }
751 
752 static void cfapi_system_directory(int *type, ...) {
753  va_list args;
754  int dirtype;
755  const char **str;
756 
757  va_start(args, type);
758 
759  dirtype = va_arg(args, int);
760  str = va_arg(args, const char **);
761  va_end(args);
762 
763  *type = CFAPI_STRING;
764 
765  switch (dirtype) {
766  case 0:
767  *str = settings.mapdir;
768  break;
769 
770  case 1:
771  *str = settings.uniquedir;
772  break;
773 
774  case 2:
775  *str = settings.tmpdir;
776  break;
777 
778  case 3:
779  *str = settings.confdir;
780  break;
781 
782  case 4:
783  *str = settings.localdir;
784  break;
785 
786  case 5:
787  *str = settings.playerdir;
788  break;
789 
790  case 6:
791  *str = settings.datadir;
792  break;
793 
794  default:
795  *str = NULL;
796  }
797 }
798 
805 static void cfapi_get_time(int *type, ...) {
806  va_list args;
807  timeofday_t *tod;
808 
809  va_start(args, type);
810  tod = va_arg(args, timeofday_t *);
811  va_end(args);
812 
813  get_tod(tod);
814  *type = CFAPI_NONE;
815 }
816 
817 #define string_get_int(name) \
818  va_list args; \
819  int index; \
820  const char **str; \
821  va_start(args, type); \
822  index = va_arg(args, int); \
823  str = va_arg(args, const char **); \
824  va_end(args); \
825  *str = name(index); \
826  *type = CFAPI_STRING; \
827 
828 
836 static void cfapi_get_season_name(int *type, ...) {
838 }
839 
848 static void cfapi_get_weekday_name(int *type, ...) {
850 }
851 
860 static void cfapi_get_month_name(int *type, ...) {
862 }
863 
872 static void cfapi_get_periodofday_name(int *type, ...) {
874 }
875 
887 static void cfapi_timer_create(int *type, ...) {
888  va_list args;
889  int res;
890  object *ob;
891  long delay;
892  int mode;
893  int *timer;
894 
895  va_start(args, type);
896  ob = va_arg(args, object *);
897  delay = va_arg(args, long);
898  mode = va_arg(args, int);
899  timer = va_arg(args, int *);
900  va_end(args);
901  *type = CFAPI_INT;
902 
903  *timer = cftimer_find_free_id();
904  if (*timer != TIMER_ERR_ID) {
905  res = cftimer_create(*timer, delay, ob, mode);
906  if (res != TIMER_ERR_NONE)
907  *timer = res;
908  }
909 }
910 
920 static void cfapi_timer_destroy(int *type, ...) {
921  va_list args;
922  int id;
923  int *err;
924 
925  va_start(args, type);
926  id = va_arg(args, int);
927  err = va_arg(args, int *);
928  va_end(args);
929  *type = CFAPI_INT;
930 
931  *err = cftimer_destroy(id);
932 }
933 
939 static void cfapi_log(int *type, ...) {
940  va_list args;
941  LogLevel logLevel;
942  const char *message;
943 
944  va_start(args, type);
945  logLevel = va_arg(args, LogLevel);
946  message = va_arg(args, const char *);
947  LOG(logLevel, "%s", message);
948  va_end(args);
949 
950  *type = CFAPI_NONE;
951 }
952 
953 /* MAP RELATED HOOKS */
954 
963 static void cfapi_map_get_map(int *type, ...) {
964  va_list args;
965  mapstruct **ret;
966  int ctype;
967  int x, y;
968  int16_t nx, ny;
969  const char *name;
970  mapstruct *m;
971 
972  va_start(args, type);
973 
974  ctype = va_arg(args, int);
975 
976  switch (ctype) {
977  case 0:
978  x = va_arg(args, int);
979  y = va_arg(args, int);
980  ret = va_arg(args, mapstruct **);
981  *ret = get_empty_map(x, y);
982  break;
983 
984  case 1:
985  name = va_arg(args, const char *);
986  x = va_arg(args, int);
987  ret = va_arg(args, mapstruct **);
988  *ret = ready_map_name(name, x);
989  break;
990 
991  case 2:
992  m = va_arg(args, mapstruct *);
993  nx = va_arg(args, int);
994  ny = va_arg(args, int);
995  ret = va_arg(args, mapstruct **);
996  *ret = get_map_from_coord(m, &nx, &ny);
997  break;
998 
999  default:
1000  *type = CFAPI_NONE;
1001  va_end(args);
1002  return;
1003  break;
1004  }
1005  va_end(args);
1006  *type = CFAPI_PMAP;
1007 }
1008 
1014 static void cfapi_map_has_been_loaded(int *type, ...) {
1015  va_list args;
1016  mapstruct **map;
1017  char *string;
1018 
1019  va_start(args, type);
1020  string = va_arg(args, char *);
1021  map = va_arg(args, mapstruct **);
1022  *map = has_been_loaded(string);
1023  va_end(args);
1024  *type = CFAPI_PMAP;
1025 }
1026 
1032 static void cfapi_map_create_path(int *type, ...) {
1033  va_list args;
1034  int ctype, size;
1035  const char *str;
1036  char *name;
1037 
1038  va_start(args, type);
1039 
1040  ctype = va_arg(args, int);
1041  str = va_arg(args, const char *);
1042  name = va_arg(args, char *);
1043  size = va_arg(args, int);
1044  *type = CFAPI_STRING;
1045 
1046  switch (ctype) {
1047  case 0:
1048  create_pathname(str, name, size);
1049  break;
1050 
1051  case 1:
1052  create_overlay_pathname(str, name, MAX_BUF);
1053  break;
1054 
1055 /* case 2:
1056  rv = create_items_path(str);
1057  break;*/
1058 
1059  default:
1060  *type = CFAPI_NONE;
1061  break;
1062  }
1063  va_end(args);
1064 }
1065 
1066 static void cfapi_map_get_map_property(int *type, ...) {
1067  va_list args;
1068  mapstruct *map;
1069  int property;
1070 
1071  int *rint;
1072  mapstruct **rmap;
1073  sstring *rstr;
1074  region **rreg;
1075  int16_t *nx, *ny;
1076  int x, y;
1077 
1078  va_start(args, type);
1079 
1080  map = va_arg(args, mapstruct *);
1081  property = va_arg(args, int);
1082 
1083  switch (property) {
1084  case CFAPI_MAP_PROP_FLAGS:
1085  rmap = va_arg(args, mapstruct **);
1086  x = va_arg(args, int);
1087  y = va_arg(args, int);
1088  nx = va_arg(args, int16_t *);
1089  ny = va_arg(args, int16_t *);
1090  rint = va_arg(args, int *);
1091  *rint = get_map_flags(map, rmap, x, y, nx, ny);
1092  *type = CFAPI_INT;
1093  break;
1094 
1096  rint = va_arg(args, int *);
1097  *rint = calculate_difficulty(map);
1098  *type = CFAPI_INT;
1099  break;
1100 
1101  case CFAPI_MAP_PROP_PATH:
1102  rstr = va_arg(args, sstring *);
1103  *rstr = map->path;
1104  *type = CFAPI_SSTRING;
1105  break;
1106 
1108  rstr = va_arg(args, sstring *);
1109  *rstr = map->tmpname;
1110  *type = CFAPI_SSTRING;
1111  break;
1112 
1113  case CFAPI_MAP_PROP_NAME:
1114  rstr = va_arg(args, sstring *);
1115  *rstr = map->name;
1116  *type = CFAPI_SSTRING;
1117  break;
1118 
1120  rint = va_arg(args, int *);
1121  *rint = map->reset_time;
1122  *type = CFAPI_INT;
1123  break;
1124 
1126  rint = va_arg(args, int *);
1127  *rint = map->reset_timeout;
1128  *type = CFAPI_INT;
1129  break;
1130 
1132  rint = va_arg(args, int *);
1133  *rint = map->players;
1134  *type = CFAPI_INT;
1135  break;
1136 
1138  rint = va_arg(args, int *);
1139  *rint = map->darkness;
1140  *type = CFAPI_INT;
1141  break;
1142 
1143  case CFAPI_MAP_PROP_WIDTH:
1144  rint = va_arg(args, int *);
1145  *rint = map->width;
1146  *type = CFAPI_INT;
1147  break;
1148 
1149  case CFAPI_MAP_PROP_HEIGHT:
1150  rint = va_arg(args, int *);
1151  *rint = map->height;
1152  *type = CFAPI_INT;
1153  break;
1154 
1156  rint = va_arg(args, int *);
1157  *rint = map->enter_x;
1158  *type = CFAPI_INT;
1159  break;
1160 
1162  rint = va_arg(args, int *);
1163  *rint = map->enter_y;
1164  *type = CFAPI_INT;
1165  break;
1166 
1168  rstr = va_arg(args, sstring *);
1169  *rstr = map->msg;
1170  *type = CFAPI_SSTRING;
1171  break;
1172 
1173  case CFAPI_MAP_PROP_NEXT:
1174  rmap = va_arg(args, mapstruct **);
1175  *rmap = map ? map->next : first_map;
1176  *type = CFAPI_PMAP;
1177  break;
1178 
1179  case CFAPI_MAP_PROP_REGION:
1180  rreg = va_arg(args, region **);
1181  *rreg = get_region_by_map(map);
1182  *type = CFAPI_PREGION;
1183  break;
1184 
1185  case CFAPI_MAP_PROP_UNIQUE:
1186  rint = va_arg(args, int *);
1187  *rint = map->unique;
1188  *type = CFAPI_INT;
1189  break;
1190 
1191  default:
1192  *type = CFAPI_NONE;
1193  break;
1194  }
1195  va_end(args);
1196 }
1197 
1198 static void cfapi_map_set_map_property(int *type, ...) {
1199  va_list args;
1200  mapstruct *map;
1201  int property;
1202  const char *buf;
1203 
1204  va_start(args, type);
1205 
1206  map = va_arg(args, mapstruct *);
1207  property = va_arg(args, int);
1208 
1209  switch (property) {
1210  case CFAPI_MAP_PROP_PATH:
1211  buf = va_arg(args, const char *);
1212  strlcpy(map->path, buf, sizeof(map->path));
1213  *type = CFAPI_STRING;
1214  break;
1215 
1216  default:
1217  *type = CFAPI_NONE;
1218  break;
1219  }
1220  va_end(args);
1221 }
1222 
1228 static void cfapi_map_out_of_map(int *type, ...) {
1229  va_list args;
1230  mapstruct *map;
1231  int x, y;
1232  int *rint;
1233 
1234  va_start(args, type);
1235  map = va_arg(args, mapstruct *);
1236  x = va_arg(args, int);
1237  y = va_arg(args, int);
1238  rint = va_arg(args, int *);
1239 
1240  *rint = out_of_map(map, x, y);
1241  va_end(args);
1242  *type = CFAPI_INT;
1243 }
1244 
1250 static void cfapi_map_update_position(int *type, ...) {
1251  va_list args;
1252  mapstruct *map;
1253  int x, y;
1254 
1255  va_start(args, type);
1256 
1257  map = va_arg(args, mapstruct *);
1258  x = va_arg(args, int);
1259  y = va_arg(args, int);
1260 
1261  update_position(map, x, y);
1262  va_end(args);
1263  *type = CFAPI_NONE;
1264 }
1265 
1266 static void cfapi_map_delete_map(int *type, ...) {
1267  va_list args;
1268  mapstruct *map;
1269  va_start(args, type);
1270 
1271  map = va_arg(args, mapstruct *);
1272 
1273  delete_map(map);
1274 
1275  va_end(args);
1276  *type = CFAPI_NONE;
1277 }
1278 
1279 static void cfapi_map_message(int *type, ...) {
1280  va_list args;
1281  mapstruct *map;
1282  const char *string;
1283  int color;
1284 
1285  va_start(args, type);
1286  map = va_arg(args, mapstruct *);
1287  string = va_arg(args, const char *);
1288  color = va_arg(args, int);
1289  va_end(args);
1290 
1291  /* function should be extended to take message types probably */
1292  ext_info_map(color, map, MSG_TYPE_MISC, MSG_SUBTYPE_NONE, string);
1293  *type = CFAPI_NONE;
1294 }
1295 
1301 static void cfapi_map_get_object_at(int *type, ...) {
1302  va_list args;
1303  mapstruct *map;
1304  int x, y;
1305  int16_t sx, sy;
1306  object **robj;
1307 
1308  va_start(args, type);
1309  map = va_arg(args, mapstruct *);
1310  x = va_arg(args, int);
1311  y = va_arg(args, int);
1312  robj = va_arg(args, object **);
1313  va_end(args);
1314 
1315  sx = x;
1316  sy = y;
1317  if (get_map_flags(map, &map, x, y, &sx, &sy)&P_OUT_OF_MAP)
1318  *robj = NULL;
1319  else
1320  *robj = GET_MAP_OB(map, sx, sy);
1321  *type = CFAPI_POBJECT;
1322 }
1323 
1330 static void cfapi_map_find_by_archetype_name(int *type, ...) {
1331  va_list args;
1332  int x, y;
1333  mapstruct *map;
1334  char *msg;
1335  object **robj;
1336 
1337  va_start(args, type);
1338 
1339  msg = va_arg(args, char *);
1340  map = va_arg(args, mapstruct *);
1341  x = va_arg(args, int);
1342  y = va_arg(args, int);
1343  robj = va_arg(args, object **);
1344 
1345  va_end(args);
1346 
1347  archetype *at = try_find_archetype(msg);
1348  *robj = at == NULL ? NULL : map_find_by_archetype(map, x, y, at);
1349  *type = CFAPI_POBJECT;
1350 }
1351 
1357 static void cfapi_map_change_light(int *type, ...) {
1358  va_list args;
1359  int change;
1360  mapstruct *map;
1361  int *rint;
1362 
1363  va_start(args, type);
1364  map = va_arg(args, mapstruct *);
1365  change = va_arg(args, int);
1366  rint = va_arg(args, int *);
1367  va_end(args);
1368 
1369  *type = CFAPI_INT;
1370  *rint = change_map_light(map, change);
1371 }
1372 
1373 /* OBJECT-RELATED HOOKS */
1374 
1388 static void cfapi_object_move(int *type, ...) {
1389  va_list args;
1390  int kind;
1391  object *op;
1392  object *activator;
1393  player *pl;
1394  int direction;
1395  int *ret;
1396 
1397  va_start(args, type);
1398  kind = va_arg(args, int);
1399  switch (kind) {
1400  case 0:
1401  op = va_arg(args, object *);
1402  direction = va_arg(args, int);
1403  activator = va_arg(args, object *);
1404  ret = va_arg(args, int *);
1405  va_end(args);
1406  *ret = move_ob(op, direction, activator);
1407  break;
1408 
1409  case 1:
1410  pl = va_arg(args, player *);
1411  direction = va_arg(args, int);
1412  ret = va_arg(args, int *);
1413  va_end(args);
1414  *ret = move_player(pl->ob, direction);
1415  break;
1416 
1417  case 2:
1418  op = va_arg(args, object *);
1419  ret = va_arg(args, int *);
1420  va_end(args);
1421  *ret = player_arrest(op);
1422  break;
1423 
1424  default:
1425  // Just end the use of variable args. We got a wrong type.
1426  va_end(args);
1427  }
1428  *type = CFAPI_INT;
1429 }
1430 
1438 static void cfapi_object_get_key(int *type, ...) {
1439  va_list args;
1440  const char *keyname;
1441  const char **value;
1442  object *op;
1443 
1444  va_start(args, type);
1445  op = va_arg(args, object *);
1446  keyname = va_arg(args, const char *);
1447  value = va_arg(args, const char **);
1448  va_end(args);
1449 
1450  *value = object_get_value(op, keyname);
1451  *type = CFAPI_SSTRING;
1452 }
1453 
1460 static void cfapi_object_set_key(int *type, ...) {
1461  va_list args;
1462  const char *keyname;
1463  const char *value;
1464  int *ret;
1465  object *op;
1466  int add_key;
1467 
1468  va_start(args, type);
1469  op = va_arg(args, object *);
1470  keyname = va_arg(args, char *);
1471  value = va_arg(args, char *);
1472  add_key = va_arg(args, int);
1473  ret = va_arg(args, int *);
1474  va_end(args);
1475 
1476  *ret = object_set_value(op, keyname, value, add_key);
1477  *type = CFAPI_INT;
1478 }
1479 
1483 static void cfapi_object_get_property(int *type, ...) {
1484  va_list args;
1485  int property;
1486  object *op;
1487  int *rint;
1488  object **robject;
1489  mapstruct **rmap;
1490  float *rfloat;
1491  archetype **rarch;
1492  sstring *rsstring;
1493  char *rbuffer;
1494  int rbufsize;
1495  MoveType *rmove;
1496  int64_t *rint64;
1497  partylist **rparty;
1498  double *rdouble;
1499  long *rlong;
1500 
1501  va_start(args, type);
1502 
1503  op = va_arg(args, object *);
1504  property = va_arg(args, int);
1505  switch (property) {
1507  robject = va_arg(args, object **);
1508  *robject = op->above;
1509  *type = CFAPI_POBJECT;
1510  break;
1511 
1513  robject = va_arg(args, object **);
1514  *robject = op->below;
1515  *type = CFAPI_POBJECT;
1516  break;
1517 
1519  robject = va_arg(args, object **);
1520  *robject = op->active_next;
1521  *type = CFAPI_POBJECT;
1522  break;
1523 
1525  robject = va_arg(args, object **);
1526  *robject = op->active_prev;
1527  *type = CFAPI_POBJECT;
1528  break;
1529 
1531  robject = va_arg(args, object **);
1532  *robject = op->inv;
1533  *type = CFAPI_POBJECT;
1534  break;
1535 
1537  robject = va_arg(args, object **);
1538  *robject = op->env;
1539  *type = CFAPI_POBJECT;
1540  break;
1541 
1543  robject = va_arg(args, object **);
1544  *robject = op->head;
1545  *type = CFAPI_POBJECT;
1546  break;
1547 
1549  robject = va_arg(args, object **);
1550  *robject = op->container;
1551  *type = CFAPI_POBJECT;
1552  break;
1553 
1554  case CFAPI_OBJECT_PROP_MAP:
1555  rmap = va_arg(args, mapstruct **);
1556  *rmap = op->map;
1557  *type = CFAPI_PMAP;
1558  break;
1559 
1561  rint = va_arg(args, int *);
1562  *rint = op->count;
1563  *type = CFAPI_INT;
1564  break;
1565 
1567  rbuffer = va_arg(args, char *);
1568  rbufsize = va_arg(args, int);
1569  query_name(op, rbuffer, rbufsize);
1570  *type = CFAPI_STRING;
1571  break;
1572 
1574  rsstring = va_arg(args, sstring *);
1575  *rsstring = op->name_pl;
1576  *type = CFAPI_SSTRING;
1577  break;
1578 
1580  rsstring = va_arg(args, sstring *);
1581  *rsstring = op->title;
1582  *type = CFAPI_SSTRING;
1583  break;
1584 
1586  rsstring = va_arg(args, sstring *);
1587  *rsstring = op->race;
1588  *type = CFAPI_SSTRING;
1589  break;
1590 
1592  rsstring = va_arg(args, sstring *);
1593  *rsstring = op->slaying;
1594  *type = CFAPI_SSTRING;
1595  break;
1596 
1598  rsstring = va_arg(args, sstring *);
1599  *rsstring = op->skill;
1600  *type = CFAPI_SSTRING;
1601  break;
1602 
1604  rsstring = va_arg(args, sstring *);
1605  *rsstring = op->msg;
1606  *type = CFAPI_SSTRING;
1607  break;
1608 
1610  rsstring = va_arg(args, sstring *);
1611  *rsstring = op->lore;
1612  *type = CFAPI_SSTRING;
1613  break;
1614 
1615  case CFAPI_OBJECT_PROP_X:
1616  rint = va_arg(args, int *);
1617  *rint = op->x;
1618  *type = CFAPI_INT;
1619  break;
1620 
1621  case CFAPI_OBJECT_PROP_Y:
1622  rint = va_arg(args, int *);
1623  *rint = op->y;
1624  *type = CFAPI_INT;
1625  break;
1626 
1628  rfloat = va_arg(args, float *);
1629  *rfloat = op->speed;
1630  *type = CFAPI_FLOAT;
1631  break;
1632 
1634  rfloat = va_arg(args, float *);
1635  *rfloat = op->speed_left;
1636  *type = CFAPI_FLOAT;
1637  break;
1638 
1640  rint = va_arg(args, int *);
1641  *rint = op->nrof;
1642  *type = CFAPI_INT;
1643  break;
1644 
1646  rint = va_arg(args, int *);
1647  *rint = op->direction;
1648  *type = CFAPI_INT;
1649  break;
1650 
1652  rint = va_arg(args, int *);
1653  *rint = op->facing;
1654  *type = CFAPI_INT;
1655  break;
1656 
1658  rint = va_arg(args, int *);
1659  *rint = op->type;
1660  *type = CFAPI_INT;
1661  break;
1662 
1664  rint = va_arg(args, int *);
1665  *rint = op->subtype;
1666  *type = CFAPI_INT;
1667  break;
1668 
1670  rint = va_arg(args, int *);
1671  *rint = op->client_type;
1672  *type = CFAPI_INT;
1673  break;
1674 
1675  case CFAPI_OBJECT_PROP_RESIST: {
1676  int idx;
1677  int16_t *resist;
1678 
1679  idx = va_arg(args, int);
1680  resist = va_arg(args, int16_t *);
1681  *resist = op->resist[idx];
1682  }
1683  *type = CFAPI_INT16;
1684  break;
1685 
1687  rint = va_arg(args, int *);
1688  *rint = op->attacktype;
1689  *type = CFAPI_INT;
1690  break;
1691 
1693  rint = va_arg(args, int *);
1694  *rint = op->path_attuned;
1695  *type = CFAPI_INT;
1696  break;
1697 
1699  rint = va_arg(args, int *);
1700  *rint = op->path_repelled;
1701  *type = CFAPI_INT;
1702  break;
1703 
1705  rint = va_arg(args, int *);
1706  *rint = op->path_denied;
1707  *type = CFAPI_INT;
1708  break;
1709 
1711  rint = va_arg(args, int *);
1712  *rint = op->material;
1713  *type = CFAPI_INT;
1714  break;
1715 
1717  rsstring = va_arg(args, sstring *);
1718  *rsstring = op->materialname;
1719  *type = CFAPI_SSTRING;
1720  break;
1721 
1723  rint = va_arg(args, int *);
1724  *rint = op->magic;
1725  *type = CFAPI_INT;
1726  break;
1727 
1729  rlong = va_arg(args, long *);
1730  *rlong = op->value;
1731  *type = CFAPI_LONG;
1732  break;
1733 
1735  rint = va_arg(args, int *);
1736  *rint = op->level;
1737  *type = CFAPI_INT;
1738  break;
1739 
1741  rint = va_arg(args, int *);
1742  *rint = op->last_heal;
1743  *type = CFAPI_INT;
1744  break;
1745 
1747  rint = va_arg(args, int *);
1748  *rint = op->last_sp;
1749  *type = CFAPI_INT;
1750  break;
1751 
1753  rint = va_arg(args, int *);
1754  *rint = op->last_grace;
1755  *type = CFAPI_INT;
1756  break;
1757 
1759  rint = va_arg(args, int *);
1760  *rint = op->last_eat;
1761  *type = CFAPI_INT;
1762  break;
1763 
1765  rint = va_arg(args, int *);
1766  *rint = op->invisible;
1767  *type = CFAPI_INT;
1768  break;
1769 
1771  rint = va_arg(args, int *);
1772  *rint = op->pick_up;
1773  *type = CFAPI_INT;
1774  break;
1775 
1777  rint = va_arg(args, int *);
1778  *rint = op->item_power;
1779  *type = CFAPI_INT;
1780  break;
1781 
1783  rint = va_arg(args, int *);
1784  *rint = op->gen_sp_armour;
1785  *type = CFAPI_INT;
1786  break;
1787 
1789  rint = va_arg(args, int *);
1790  *rint = op->weight;
1791  *type = CFAPI_INT;
1792  break;
1793 
1795  rint = va_arg(args, int *);
1796  *rint = op->weight_limit;
1797  *type = CFAPI_INT;
1798  break;
1799 
1801  rint = va_arg(args, int *);
1802  *rint = op->carrying;
1803  *type = CFAPI_INT;
1804  break;
1805 
1807  rint = va_arg(args, int *);
1808  *rint = op->glow_radius;
1809  *type = CFAPI_INT;
1810  break;
1811 
1813  rint64 = va_arg(args, int64_t *);
1814  *rint64 = op->total_exp;
1815  *type = CFAPI_SINT64;
1816  break;
1817 
1819  robject = va_arg(args, object **);
1820  *robject = op->current_weapon;
1821  *type = CFAPI_POBJECT;
1822  break;
1823 
1825  robject = va_arg(args, object **);
1826  *robject = op->enemy;
1827  *type = CFAPI_POBJECT;
1828  break;
1829 
1831  robject = va_arg(args, object **);
1832  *robject = op->attacked_by;
1833  *type = CFAPI_POBJECT;
1834  break;
1835 
1837  rint = va_arg(args, int *);
1838  *rint = op->run_away;
1839  *type = CFAPI_INT;
1840  break;
1841 
1843  robject = va_arg(args, object **);
1844  *robject = op->chosen_skill;
1845  *type = CFAPI_POBJECT;
1846  break;
1847 
1849  rint = va_arg(args, int *);
1850  *rint = op->hide;
1851  *type = CFAPI_INT;
1852  break;
1853 
1855  rint = va_arg(args, int *);
1856  *rint = op->move_status;
1857  *type = CFAPI_INT;
1858  break;
1859 
1861  rint = va_arg(args, int *);
1862  *rint = op->attack_movement;
1863  *type = CFAPI_INT;
1864  break;
1865 
1867  robject = va_arg(args, object **);
1868  *robject = op->spellitem;
1869  *type = CFAPI_POBJECT;
1870  break;
1871 
1873  rdouble = va_arg(args, double *);
1874  *rdouble = op->expmul;
1875  *type = CFAPI_DOUBLE;
1876  break;
1877 
1879  rarch = va_arg(args, archetype **);
1880  *rarch = op->arch;
1881  *type = CFAPI_PARCH;
1882  break;
1883 
1885  rarch = va_arg(args, archetype **);
1886  *rarch = op->other_arch;
1887  *type = CFAPI_PARCH;
1888  break;
1889 
1891  rsstring = va_arg(args, sstring *);
1892  *rsstring = op->custom_name;
1893  *type = CFAPI_SSTRING;
1894  break;
1895 
1897  rint = va_arg(args, int *);
1898  *rint = op->anim_speed;
1899  *type = CFAPI_INT;
1900  break;
1901 
1903  rint = va_arg(args, int *);
1904  *rint = is_friendly(op);
1905  *type = CFAPI_INT;
1906  break;
1907 
1909  rbuffer = va_arg(args, char *);
1910  rbufsize = va_arg(args, int);
1911  query_short_name(op, rbuffer, rbufsize);
1912  *type = CFAPI_STRING;
1913  break;
1914 
1916  int i;
1917 
1918  i = va_arg(args, int);
1919  rbuffer = va_arg(args, char *);
1920  rbufsize = va_arg(args, int);
1921  query_base_name(op, i, rbuffer, rbufsize);
1922  *type = CFAPI_STRING;
1923  }
1924  break;
1925 
1927  rsstring = va_arg(args, sstring *);
1928  *rsstring = op->name;
1929  *type = CFAPI_SSTRING;
1930  break;
1931 
1933  rint = va_arg(args, int *);
1934  *rint = is_magical(op);
1935  *type = CFAPI_INT;
1936  break;
1937 
1939  rint = va_arg(args, int *);
1940  *rint = op->stats.luck;
1941  *type = CFAPI_INT;
1942  break;
1943 
1944  case CFAPI_OBJECT_PROP_EXP:
1945  rint64 = va_arg(args, int64_t *);
1946  *rint64 = op->stats.exp;
1947  *type = CFAPI_SINT64;
1948  break;
1949 
1951  robject = va_arg(args, object **);
1952  *robject = object_get_owner(op);
1953  *type = CFAPI_POBJECT;
1954  break;
1955 
1957  int stype;
1958 
1959  stype = va_arg(args, int);
1960  switch (stype) {
1961  unsigned char ptype;
1962  char *buf;
1963  archetype *at;
1964 
1965  case 0: /* present_in_ob */
1966  ptype = (unsigned char)(va_arg(args, int));
1967  robject = va_arg(args, object **);
1968  *robject = object_present_in_ob(ptype, op);
1969  break;
1970 
1971  case 1: /* present_in_ob_by_name */
1972  ptype = (unsigned char)(va_arg(args, int));
1973  buf = va_arg(args, char *);
1974  robject = va_arg(args, object **);
1975  *robject = object_present_in_ob_by_name(ptype, buf, op);
1976  break;
1977 
1978  case 2: /* arch_present_in_ob */
1979  at = va_arg(args, archetype *);
1980  robject = va_arg(args, object **);
1981  *robject = arch_present_in_ob(at, op);
1982  break;
1983  }
1984  }
1985  *type = CFAPI_POBJECT;
1986  break;
1987 
1989  rint = va_arg(args, int *);
1990  *rint = (QUERY_FLAG(op, FLAG_WAS_WIZ));
1991  *type = CFAPI_INT;
1992  break;
1993 
1995  object *op2;
1996 
1997  op2 = va_arg(args, object *);
1998  rint = va_arg(args, int *);
1999  *rint = object_can_merge(op, op2);
2000  }
2001  *type = CFAPI_INT;
2002  break;
2003 
2005  object *op2;
2006 
2007  op2 = va_arg(args, object *);
2008  rint = va_arg(args, int *);
2009  *rint = object_can_pick(op2, op);
2010  }
2011  *type = CFAPI_INT;
2012  break;
2013 
2014  case CFAPI_OBJECT_PROP_FLAGS: {
2015  int fl;
2016 
2017  fl = va_arg(args, int);
2018  rint = va_arg(args, int *);
2019  *rint = QUERY_FLAG(op, fl);
2020  }
2021  *type = CFAPI_INT;
2022  break;
2023 
2024  case CFAPI_OBJECT_PROP_STR:
2025  rint = va_arg(args, int *);
2026  *rint = op->stats.Str;
2027  *type = CFAPI_INT;
2028  break;
2029 
2030  case CFAPI_OBJECT_PROP_DEX:
2031  rint = va_arg(args, int *);
2032  *rint = op->stats.Dex;
2033  *type = CFAPI_INT;
2034  break;
2035 
2036  case CFAPI_OBJECT_PROP_CON:
2037  rint = va_arg(args, int *);
2038  *rint = op->stats.Con;
2039  *type = CFAPI_INT;
2040  break;
2041 
2042  case CFAPI_OBJECT_PROP_WIS:
2043  rint = va_arg(args, int *);
2044  *rint = op->stats.Wis;
2045  *type = CFAPI_INT;
2046  break;
2047 
2048  case CFAPI_OBJECT_PROP_INT:
2049  rint = va_arg(args, int *);
2050  *rint = op->stats.Int;
2051  *type = CFAPI_INT;
2052  break;
2053 
2054  case CFAPI_OBJECT_PROP_POW:
2055  rint = va_arg(args, int *);
2056  *rint = op->stats.Pow;
2057  *type = CFAPI_INT;
2058  break;
2059 
2060  case CFAPI_OBJECT_PROP_CHA:
2061  rint = va_arg(args, int *);
2062  *rint = op->stats.Cha;
2063  *type = CFAPI_INT;
2064  break;
2065 
2066  case CFAPI_OBJECT_PROP_WC:
2067  rint = va_arg(args, int *);
2068  *rint = op->stats.wc;
2069  *type = CFAPI_INT;
2070  break;
2071 
2072  case CFAPI_OBJECT_PROP_AC:
2073  rint = va_arg(args, int *);
2074  *rint = op->stats.ac;
2075  *type = CFAPI_INT;
2076  break;
2077 
2078  case CFAPI_OBJECT_PROP_HP:
2079  rint = va_arg(args, int *);
2080  *rint = op->stats.hp;
2081  *type = CFAPI_INT;
2082  break;
2083 
2084  case CFAPI_OBJECT_PROP_SP:
2085  rint = va_arg(args, int *);
2086  *rint = op->stats.sp;
2087  *type = CFAPI_INT;
2088  break;
2089 
2090  case CFAPI_OBJECT_PROP_GP:
2091  rint = va_arg(args, int *);
2092  *rint = op->stats.grace;
2093  *type = CFAPI_INT;
2094  break;
2095 
2096  case CFAPI_OBJECT_PROP_FP:
2097  rint = va_arg(args, int *);
2098  *rint = op->stats.food;
2099  *type = CFAPI_INT;
2100  break;
2101 
2103  rint = va_arg(args, int *);
2104  *rint = op->stats.maxhp;
2105  *type = CFAPI_INT;
2106  break;
2107 
2109  rint = va_arg(args, int *);
2110  *rint = op->stats.maxsp;
2111  *type = CFAPI_INT;
2112  break;
2113 
2115  rint = va_arg(args, int *);
2116  *rint = op->stats.maxgrace;
2117  *type = CFAPI_INT;
2118  break;
2119 
2120  case CFAPI_OBJECT_PROP_DAM:
2121  rint = va_arg(args, int *);
2122  *rint = op->stats.dam;
2123  *type = CFAPI_INT;
2124  break;
2125 
2126  case CFAPI_OBJECT_PROP_GOD:
2127  rsstring = va_arg(args, sstring *);
2128  *rsstring = determine_god(op);
2129  *type = CFAPI_SSTRING;
2130  break;
2131 
2133  rsstring = va_arg(args, sstring *);
2134  *rsstring = op->arch->name;
2135  *type = CFAPI_SSTRING;
2136  break;
2137 
2139  rint = va_arg(args, int *);
2140  *rint = op->invisible;
2141  *type = CFAPI_INT;
2142  break;
2143 
2145  rbuffer = va_arg(args, char *);
2146  rbufsize = va_arg(args, int);
2147  if (rbufsize > 0) {
2148  strncpy(rbuffer, op->face->name, rbufsize);
2149  rbuffer[rbufsize - 1] = '\0';
2150  }
2151  *type = CFAPI_STRING;
2152  break;
2153 
2155  rbuffer = va_arg(args, char *);
2156  rbufsize = va_arg(args, int);
2157  if (rbufsize > 0) {
2158  if (op->animation != NULL) {
2159  strncpy(rbuffer, op->animation->name, rbufsize);
2160  rbuffer[rbufsize - 1] = '\0';
2161  }
2162  else
2163  rbuffer[0] = '\0';
2164  }
2165  *type = CFAPI_STRING;
2166  break;
2167 
2168  case CFAPI_PLAYER_PROP_IP:
2169  rsstring = va_arg(args, sstring *);
2170  *rsstring = op->contr->socket.host;
2171  *type = CFAPI_SSTRING;
2172  break;
2173 
2175  robject = va_arg(args, object **);
2176  *robject = find_marked_object(op);
2177  *type = CFAPI_POBJECT;
2178  break;
2179 
2181  rparty = va_arg(args, partylist **);
2182  *rparty = (op->contr ? op->contr->party : NULL);
2183  *type = CFAPI_PPARTY;
2184  break;
2185 
2187  robject = va_arg(args, object **);
2188  if (op)
2189  *robject = op->contr->next ? op->contr->next->ob : NULL;
2190  else
2191  /* This can be called when there is no player. */
2192  *robject = first_player ? first_player->ob : NULL;
2193  *type = CFAPI_POBJECT;
2194  break;
2195 
2197  rbuffer = va_arg(args, char *);
2198  rbufsize = va_arg(args, int);
2199  player_get_title(op->contr, rbuffer, rbufsize);
2200  *type = CFAPI_STRING;
2201  break;
2202 
2204  rmove = va_arg(args, MoveType *);
2205  *rmove = op->move_type;
2206  *type = CFAPI_MOVETYPE;
2207  break;
2208 
2210  rmove = va_arg(args, MoveType *);
2211  *rmove = op->move_block;
2212  *type = CFAPI_MOVETYPE;
2213  break;
2214 
2216  rmove = va_arg(args, MoveType *);
2217  *rmove = op->move_allow;
2218  *type = CFAPI_MOVETYPE;
2219  break;
2220 
2222  rmove = va_arg(args, MoveType *);
2223  *rmove = op->move_on;
2224  *type = CFAPI_MOVETYPE;
2225  break;
2226 
2228  rmove = va_arg(args, MoveType *);
2229  *rmove = op->move_off;
2230  *type = CFAPI_MOVETYPE;
2231  break;
2232 
2234  rmove = va_arg(args, MoveType *);
2235  *rmove = op->move_type;
2236  *type = CFAPI_MOVETYPE;
2237  break;
2238 
2240  rfloat = va_arg(args, float *);
2241  *rfloat = op->move_slow_penalty;
2242  *type = CFAPI_FLOAT;
2243  break;
2244 
2246  rbuffer = va_arg(args, char *);
2247  rbufsize = va_arg(args, int);
2248  strlcpy(rbuffer, op->contr->savebed_map, rbufsize);
2249  *type = CFAPI_STRING;
2250  break;
2251 
2253  rint = va_arg(args, int *);
2254  *rint = op->contr->bed_x;
2255  *type = CFAPI_INT;
2256  break;
2257 
2259  rint = va_arg(args, int *);
2260  *rint = op->contr->bed_y;
2261  *type = CFAPI_INT;
2262  break;
2263 
2265  rint = va_arg(args, int *);
2266  *rint = op->duration;
2267  *type = CFAPI_INT;
2268  break;
2269 
2270  default:
2271  *type = CFAPI_NONE;
2272  break;
2273  }
2274  va_end(args);
2275 }
2276 
2285 static void copy_message(object *op, const char *msg) {
2286  /* need to reset parsed dialog information */
2288  if (strlen(msg) == 0) {
2289  msg = NULL;
2290  }
2291  object_set_msg(op, msg);
2292 }
2293 
2302 static void cfapi_object_set_property(int *type, ...) {
2303  va_list args;
2304  int iarg, *ret;
2305  long larg;
2306  char *sarg;
2307  double darg;
2308  object *oparg;
2309  object *op;
2310  int property;
2311  int64_t s64arg;
2312  partylist *partyarg;
2313  float farg;
2314  MoveType *move; /* MoveType can't be used through va_arg so use MoveType * */
2315 
2316  va_start(args, type);
2317  op = va_arg(args, object *);
2318  property = va_arg(args, int);
2319  *type = CFAPI_NONE;
2320 
2321  if (op != NULL && (!op->arch || (op != &op->arch->clone))) {
2322  switch (property) {
2324  sarg = va_arg(args, char *);
2325  *type = CFAPI_STRING;
2326  FREE_AND_COPY(op->name, sarg);
2327  send_changed_object(op);
2328  break;
2329 
2331  sarg = va_arg(args, char *);
2332  *type = CFAPI_STRING;
2333  FREE_AND_COPY(op->name_pl, sarg);
2334  send_changed_object(op);
2335  break;
2336 
2338  sarg = va_arg(args, char *);
2339  *type = CFAPI_STRING;
2340  FREE_AND_COPY(op->title, sarg);
2341  break;
2342 
2344  sarg = va_arg(args, char *);
2345  *type = CFAPI_STRING;
2346  FREE_AND_COPY(op->race, sarg);
2347  break;
2348 
2350  sarg = va_arg(args, char *);
2351  *type = CFAPI_STRING;
2352  FREE_AND_COPY(op->slaying, sarg);
2353  break;
2354 
2356  sarg = va_arg(args, char *);
2357  *type = CFAPI_STRING;
2358  FREE_AND_COPY(op->skill, sarg);
2359  break;
2360 
2362  sarg = va_arg(args, char *);
2363  *type = CFAPI_STRING;
2364  copy_message(op, sarg);
2365  break;
2366 
2368  sarg = va_arg(args, char *);
2369  *type = CFAPI_STRING;
2370  FREE_AND_COPY(op->lore, sarg);
2371  break;
2372 
2374  farg = va_arg(args, double);
2375  *type = CFAPI_FLOAT;
2376  if (farg != op->speed) {
2377  op->speed = farg;
2378  object_update_speed(op);
2379  }
2380  break;
2381 
2383  farg = va_arg(args, double);
2384  *type = CFAPI_FLOAT;
2385  op->speed_left = farg;
2386  break;
2387 
2389  iarg = va_arg(args, int);
2390  *type = CFAPI_INT;
2391  if (iarg < 0)
2392  iarg = 0;
2393  if (op->nrof > (uint32_t)iarg)
2394  object_decrease_nrof(op, op->nrof-iarg);
2395  else if (op->nrof < (uint32_t)iarg) {
2396  object *tmp;
2397  player *pl;
2398 
2399  op->nrof = iarg;
2400  if (op->env != NULL) {
2401  tmp = object_get_player_container(op->env);
2402  if (!tmp) {
2403  for (pl = first_player; pl; pl = pl->next)
2404  if (pl->ob->container == op->env)
2405  break;
2406  if (pl)
2407  tmp = pl->ob;
2408  else
2409  tmp = NULL;
2410  } else {
2411  object_sum_weight(tmp);
2412  fix_object(tmp);
2413  }
2414  if (tmp)
2415  esrv_update_item(UPD_NROF, tmp, op);
2416  } else {
2417  FOR_ABOVE_PREPARE(op, tmp)
2418  if (tmp->type == PLAYER)
2419  tmp->contr->socket.update_look = 1;
2420  FOR_ABOVE_FINISH();
2421  }
2422  }
2423  break;
2424 
2426  iarg = va_arg(args, int);
2427  *type = CFAPI_INT;
2428  op->direction = iarg;
2429  break;
2430 
2432  iarg = va_arg(args, int);
2433  *type = CFAPI_INT;
2434  op->facing = iarg;
2435  break;
2436 
2437  case CFAPI_OBJECT_PROP_RESIST: {
2438  int iargbis = va_arg(args, int);
2439 
2440  *type = CFAPI_INT16;
2441  iarg = va_arg(args, int);
2442  op->resist[iargbis] = iarg;
2443  }
2444  break;
2445 
2447  iarg = va_arg(args, int);
2448  *type = CFAPI_INT;
2449  op->attacktype = iarg;
2450  break;
2451 
2453  iarg = va_arg(args, int);
2454  *type = CFAPI_INT;
2455  op->path_attuned = iarg;
2456  break;
2457 
2459  iarg = va_arg(args, int);
2460  *type = CFAPI_INT;
2461  op->path_repelled = iarg;
2462  break;
2463 
2465  iarg = va_arg(args, int);
2466  *type = CFAPI_INT;
2467  op->path_denied = iarg;
2468  break;
2469 
2471  iarg = va_arg(args, int);
2472  *type = CFAPI_INT;
2473  op->material = iarg;
2474  break;
2475 
2477  break;
2478 
2480  iarg = va_arg(args, int);
2481  *type = CFAPI_INT;
2482  op->magic = iarg;
2483  break;
2484 
2486  larg = va_arg(args, long);
2487  *type = CFAPI_LONG;
2488  op->value = larg;
2489  break;
2490 
2492  iarg = va_arg(args, int);
2493  *type = CFAPI_INT;
2494  op->level = iarg;
2495  send_changed_object(op);
2496  break;
2497 
2499  iarg = va_arg(args, int);
2500  *type = CFAPI_INT;
2501  op->last_heal = iarg;
2502  break;
2503 
2505  iarg = va_arg(args, int);
2506  *type = CFAPI_INT;
2507  op->last_sp = iarg;
2508  break;
2509 
2511  iarg = va_arg(args, int);
2512  *type = CFAPI_INT;
2513  op->last_grace = iarg;
2514  break;
2515 
2517  iarg = va_arg(args, int);
2518  *type = CFAPI_INT;
2519  op->last_eat = iarg;
2520  break;
2521 
2523  iarg = va_arg(args, int);
2524  *type = CFAPI_INT;
2525  op->invisible = iarg;
2526  break;
2527 
2529  iarg = va_arg(args, int);
2530  *type = CFAPI_INT;
2531  op->pick_up = iarg;
2532  break;
2533 
2535  iarg = va_arg(args, int);
2536  *type = CFAPI_INT;
2537  op->item_power = iarg;
2538  break;
2539 
2541  iarg = va_arg(args, int);
2542  *type = CFAPI_INT;
2543  op->gen_sp_armour = iarg;
2544  break;
2545 
2547  iarg = va_arg(args, int);
2548  *type = CFAPI_INT;
2549  if (op->weight != iarg) {
2550  object *tmp;
2551  player *pl;
2552 
2553  op->weight = iarg;
2554  if (op->env != NULL) {
2555  tmp = object_get_player_container(op->env);
2556  if (!tmp) {
2557  for (pl = first_player; pl; pl = pl->next)
2558  if (pl->ob->container == op->env)
2559  break;
2560  if (pl)
2561  tmp = pl->ob;
2562  else
2563  tmp = NULL;
2564  } else {
2565  object_sum_weight(tmp);
2566  fix_object(tmp);
2567  }
2568  if (tmp)
2569  esrv_update_item(UPD_WEIGHT, tmp, op);
2570  } else {
2571  FOR_ABOVE_PREPARE(op, tmp)
2572  if (tmp->type == PLAYER)
2573  esrv_update_item(UPD_WEIGHT, tmp, op);
2574  FOR_ABOVE_FINISH();
2575  }
2576  }
2577  break;
2578 
2580  iarg = va_arg(args, int);
2581  *type = CFAPI_INT;
2582  op->weight_limit = iarg;
2583  break;
2584 
2586  iarg = va_arg(args, int);
2587  *type = CFAPI_INT;
2588  if (op->glow_radius != iarg) {
2589  object *tmp;
2590 
2591  op->glow_radius = iarg;
2592  tmp = object_get_env_recursive(op);
2593  if (tmp->map != NULL) {
2594  SET_MAP_FLAGS(tmp->map, tmp->x, tmp->y, P_NEED_UPDATE);
2595  update_position(tmp->map, tmp->x, tmp->y);
2596  update_all_los(tmp->map, tmp->x, tmp->y);
2597  }
2598  }
2599  break;
2600 
2602  s64arg = va_arg(args, int64_t);
2603  *type = CFAPI_SINT64;
2604  op->total_exp = s64arg;
2605  break;
2606 
2608  oparg = va_arg(args, object *);
2609  *type = CFAPI_POBJECT;
2610  object_set_enemy(op, oparg);
2611  break;
2612 
2614  iarg = va_arg(args, int);
2615  *type = CFAPI_INT;
2616  op->run_away = iarg;
2617  break;
2618 
2620  oparg = va_arg(args, object *);
2621  *type = CFAPI_POBJECT;
2622  op->chosen_skill = oparg;
2623  break;
2624 
2626  iarg = va_arg(args, int);
2627  *type = CFAPI_INT;
2628  op->hide = iarg;
2629  break;
2630 
2632  iarg = va_arg(args, int);
2633  *type = CFAPI_INT;
2634  op->move_status = iarg;
2635  break;
2636 
2638  iarg = va_arg(args, int);
2639  *type = CFAPI_INT;
2640  op->attack_movement = iarg;
2641  break;
2642 
2644  oparg = va_arg(args, object *);
2645  *type = CFAPI_POBJECT;
2646  op->spellitem = oparg;
2647  break;
2648 
2650  darg = va_arg(args, double);
2651  *type = CFAPI_DOUBLE;
2652  op->expmul = darg;
2653  break;
2654 
2656  sarg = va_arg(args, char *);
2657  *type = CFAPI_STRING;
2658  FREE_AND_COPY(op->custom_name, sarg);
2659  send_changed_object(op);
2660  break;
2661 
2663  iarg = va_arg(args, int);
2664  *type = CFAPI_INT;
2665  op->anim_speed = iarg;
2666  break;
2667 
2669  iarg = va_arg(args, int);
2670  *type = CFAPI_INT;
2671  if (iarg == 1 && is_friendly(op) == 0)
2672  add_friendly_object(op);
2673  else if (iarg == 0 && is_friendly(op) == 1)
2675  break;
2676 
2678  iarg = va_arg(args, int);
2679  *type = CFAPI_INT;
2680  op->stats.luck = iarg;
2681  break;
2682 
2683  case CFAPI_OBJECT_PROP_EXP:
2684  s64arg = va_arg(args, int64_t);
2685  *type = CFAPI_SINT64;
2686  op->stats.exp = s64arg;
2687  break;
2688 
2690  oparg = va_arg(args, object *);
2691  *type = CFAPI_POBJECT;
2692  object_set_owner(op, oparg);
2693  break;
2694 
2696  object_set_cheat(op);
2697  *type = CFAPI_NONE;
2698  break;
2699 
2700  case CFAPI_OBJECT_PROP_FLAGS: {
2701  int iargbis;
2702 
2703  iarg = va_arg(args, int);
2704  iargbis = va_arg(args, int);
2705  *type = CFAPI_INT;
2706 
2707  if (iargbis == 1)
2708  SET_FLAG(op, iarg);
2709  else
2710  CLEAR_FLAG(op, iarg);
2711  }
2712  break;
2713 
2714  case CFAPI_OBJECT_PROP_STR:
2715  iarg = va_arg(args, int);
2716  *type = CFAPI_INT;
2717  op->stats.Str = iarg;
2718  break;
2719 
2720  case CFAPI_OBJECT_PROP_DEX:
2721  iarg = va_arg(args, int);
2722  *type = CFAPI_INT;
2723  op->stats.Dex = iarg;
2724  break;
2725 
2726  case CFAPI_OBJECT_PROP_CON:
2727  iarg = va_arg(args, int);
2728  *type = CFAPI_INT;
2729  op->stats.Con = iarg;
2730  break;
2731 
2732  case CFAPI_OBJECT_PROP_WIS:
2733  iarg = va_arg(args, int);
2734  *type = CFAPI_INT;
2735  op->stats.Wis = iarg;
2736  break;
2737 
2738  case CFAPI_OBJECT_PROP_INT:
2739  iarg = va_arg(args, int);
2740  *type = CFAPI_INT;
2741  op->stats.Int = iarg;
2742  break;
2743 
2744  case CFAPI_OBJECT_PROP_POW:
2745  iarg = va_arg(args, int);
2746  *type = CFAPI_INT;
2747  op->stats.Pow = iarg;
2748  break;
2749 
2750  case CFAPI_OBJECT_PROP_CHA:
2751  iarg = va_arg(args, int);
2752  *type = CFAPI_INT;
2753  op->stats.Cha = iarg;
2754  break;
2755 
2756  case CFAPI_OBJECT_PROP_WC:
2757  iarg = va_arg(args, int);
2758  *type = CFAPI_INT;
2759  op->stats.wc = iarg;
2760  break;
2761 
2762  case CFAPI_OBJECT_PROP_AC:
2763  iarg = va_arg(args, int);
2764  *type = CFAPI_INT;
2765  op->stats.ac = iarg;
2766  break;
2767 
2768  case CFAPI_OBJECT_PROP_HP:
2769  iarg = va_arg(args, int);
2770  *type = CFAPI_INT;
2771  op->stats.hp = iarg;
2772  break;
2773 
2774  case CFAPI_OBJECT_PROP_SP:
2775  iarg = va_arg(args, int);
2776  *type = CFAPI_INT;
2777  op->stats.sp = iarg;
2778  break;
2779 
2780  case CFAPI_OBJECT_PROP_GP:
2781  iarg = va_arg(args, int);
2782  *type = CFAPI_INT;
2783  op->stats.grace = iarg;
2784  break;
2785 
2786  case CFAPI_OBJECT_PROP_FP:
2787  iarg = va_arg(args, int);
2788  *type = CFAPI_INT;
2789  op->stats.food = iarg;
2790  break;
2791 
2793  iarg = va_arg(args, int);
2794  *type = CFAPI_INT;
2795  op->stats.maxhp = iarg;
2796  break;
2797 
2799  iarg = va_arg(args, int);
2800  *type = CFAPI_INT;
2801  op->stats.maxsp = iarg;
2802  break;
2803 
2805  iarg = va_arg(args, int);
2806  *type = CFAPI_INT;
2807  op->stats.maxgrace = iarg;
2808  break;
2809 
2810  case CFAPI_OBJECT_PROP_DAM:
2811  iarg = va_arg(args, int);
2812  *type = CFAPI_INT;
2813  op->stats.dam = iarg;
2814  break;
2815 
2816  case CFAPI_OBJECT_PROP_FACE: {
2817  const Face *face;
2818  sarg = va_arg(args, char *);
2819  ret = va_arg(args, int *);
2820  *type = CFAPI_INT;
2821  face = try_find_face(sarg, 0);
2822  if (face != NULL) {
2823  op->face = face;
2824  op->state = 0;
2825  object_update(op, UP_OBJ_FACE);
2826  (*ret) = face->number;
2827  } else
2828  (*ret) = 0;
2829  break;
2830  }
2831 
2833  const Animations *anim;
2834  sarg = va_arg(args, char *);
2835  ret = va_arg(args, int *);
2836  *type = CFAPI_INT;
2837  anim = try_find_animation(sarg);
2838  if (anim != NULL) {
2839  op->animation = anim;
2840  SET_ANIMATION(op, 0);
2841  object_update(op, UP_OBJ_FACE);
2842  (*ret) = anim->num;
2843  } else {
2844  (*ret) = 0;
2845  }
2846  break;
2847  }
2848 
2850  iarg = va_arg(args, int);
2851  *type = CFAPI_INT;
2852  op->duration = iarg;
2853  break;
2854 
2856  if (op->contr) {
2857  oparg = va_arg(args, object *);
2858  *type = CFAPI_POBJECT;
2859  op->contr->mark = oparg;
2860  if (oparg) {
2861  op->contr->mark_count = oparg->count;
2862  } else {
2863  op->contr->mark_count = 0;
2864  }
2865  }
2866  break;
2867 
2869  if (op->contr) {
2870  partyarg = va_arg(args, partylist *);
2871  *type = CFAPI_PPARTY;
2872  party_join(op, partyarg);
2873  }
2874  break;
2875 
2877  sarg = va_arg(args, char *);
2878  *type = CFAPI_STRING;
2879  safe_strncpy(op->contr->savebed_map, sarg, MAX_BUF);
2880  break;
2881 
2883  iarg = va_arg(args, int);
2884  *type = CFAPI_INT;
2885  op->contr->bed_x = iarg;
2886  break;
2887 
2889  iarg = va_arg(args, int);
2890  *type = CFAPI_INT;
2891  op->contr->bed_y = iarg;
2892  break;
2893 
2895  sarg = va_arg(args, char *);
2896  *type = CFAPI_STRING;
2897  player_set_own_title(op->contr, sarg);
2898  break;
2899 
2901  move = va_arg(args, MoveType *);
2902  op->move_type = *move & MOVE_ALL;
2903  object_update(op, UP_OBJ_INSERT);
2904  *type = CFAPI_MOVETYPE;
2905  break;
2906 
2908  move = va_arg(args, MoveType *);
2909  op->move_block = *move & MOVE_ALL;
2910  object_update(op, UP_OBJ_INSERT);
2911  *type = CFAPI_MOVETYPE;
2912  break;
2913 
2915  move = va_arg(args, MoveType *);
2916  op->move_allow = *move & MOVE_ALL;
2917  object_update(op, UP_OBJ_INSERT);
2918  *type = CFAPI_MOVETYPE;
2919  break;
2920 
2922  move = va_arg(args, MoveType *);
2923  op->move_on = *move & MOVE_ALL;
2924  object_update(op, UP_OBJ_INSERT);
2925  *type = CFAPI_MOVETYPE;
2926  break;
2927 
2929  move = va_arg(args, MoveType *);
2930  op->move_off = *move & MOVE_ALL;
2931  object_update(op, UP_OBJ_INSERT);
2932  *type = CFAPI_MOVETYPE;
2933  break;
2934 
2936  move = va_arg(args, MoveType *);
2937  op->move_type = *move & MOVE_ALL;
2938  object_update(op, UP_OBJ_INSERT);
2939  *type = CFAPI_MOVETYPE;
2940  break;
2941 
2942  default:
2943  break;
2944  }
2945  }
2946  va_end(args);
2947 }
2948 
2955 static void cfapi_object_apply_below(int *type, ...) {
2956  va_list args;
2957  object *applier;
2958 
2959  va_start(args, type);
2960 
2961  applier = va_arg(args, object *);
2962 
2963  va_end(args);
2964 
2965  apply_by_living_below(applier);
2966  *type = CFAPI_NONE;
2967 }
2968 
2975 static void cfapi_object_apply(int *type, ...) {
2976  va_list args;
2977  object *applied;
2978  object *applier;
2979  int aflags;
2980  int *ret;
2981 
2982  va_start(args, type);
2983 
2984  applier = va_arg(args, object *);
2985  applied = va_arg(args, object *);
2986  aflags = va_arg(args, int);
2987  ret = va_arg(args, int *);
2988 
2989  va_end(args);
2990 
2991  *type = CFAPI_INT;
2992  *ret = apply_manual(applier, applied, aflags);
2993 }
2994 
3000 static void cfapi_object_identify(int *type, ...) {
3001  va_list args;
3002  object *op, **result;
3003 
3004  va_start(args, type);
3005 
3006  op = va_arg(args, object *);
3007  result = va_arg(args, object **);
3008 
3009  va_end(args);
3010 
3011  (*result) = identify(op);
3012  *type = CFAPI_POBJECT;
3013 }
3014 
3020 static void cfapi_object_describe(int *type, ...) {
3021  va_list args;
3022  object *op;
3023  object *owner;
3024  char *desc, *final;
3025  int size;
3026 
3027  va_start(args, type);
3028 
3029  op = va_arg(args, object *);
3030  owner = va_arg(args, object *);
3031  desc = va_arg(args, char *);
3032  size = va_arg(args, int);
3033  va_end(args);
3034 
3035  *type = CFAPI_STRING;
3036  final = stringbuffer_finish(describe_item(op, owner, 0, NULL));
3037  strncpy(desc, final, size);
3038  desc[size - 1] = '\0';
3039  free(final);
3040 }
3041 
3042 static void cfapi_object_drain(int *type, ...) {
3043  va_list args;
3044 
3045  object *op;
3046  int ds;
3047 
3048  va_start(args, type);
3049 
3050  op = va_arg(args, object *);
3051  ds = va_arg(args, int);
3052 
3053  va_end(args);
3054 
3055  drain_specific_stat(op, ds);
3056 
3057  *type = CFAPI_NONE;
3058 }
3059 
3060 static void cfapi_object_remove_depletion(int *type, ...) {
3061  va_list args;
3062 
3063  object *op;
3064  int level, *result;
3065 
3066  va_start(args, type);
3067 
3068  op = va_arg(args, object *);
3069  level = va_arg(args, int);
3070  result = va_arg(args, int*);
3071 
3072  va_end(args);
3073 
3074  *result = remove_depletion(op, level);
3075 
3076  *type = CFAPI_INT;
3077 }
3078 
3079 static void cfapi_object_fix(int *type, ...) {
3080  va_list args;
3081  object *op;
3082 
3083  va_start(args, type);
3084 
3085  op = va_arg(args, object *);
3086 
3087  va_end(args);
3088 
3089  fix_object(op);
3090 
3091  *type = CFAPI_NONE;
3092 }
3093 
3095 static void cfapi_object_give_skill(int *type, ...) {
3096  va_list args;
3097 
3098  object *op;
3099  char *skillname;
3100 
3101  va_start(args, type);
3102 
3103  op = va_arg(args, object *);
3104  skillname = va_arg(args, char *);
3105 
3106  va_end(args);
3107 
3108  *type = CFAPI_POBJECT;
3109  give_skill_by_name(op, skillname);
3110 }
3111 
3112 static void cfapi_object_transmute(int *type, ...) {
3113  va_list args;
3114 
3115  object *op;
3116  object *chg;
3117 
3118  va_start(args, type);
3119 
3120  op = va_arg(args, object *);
3121  chg = va_arg(args, object *);
3122 
3123  va_end(args);
3124 
3125  transmute_materialname(op, chg);
3126  *type = CFAPI_NONE;
3127 }
3128 
3129 static void cfapi_object_remove(int *type, ...) {
3130  va_list args;
3131  object *op;
3132 
3133  va_start(args, type);
3134 
3135  op = va_arg(args, object *);
3136 
3137  if (QUERY_FLAG(op, FLAG_REMOVED)) {
3138  LOG(llevError, "Plugin trying to remove removed object %s\n", op->name);
3139  va_end(args);
3140  *type = CFAPI_NONE;
3141  return;
3142  }
3143 
3144  va_end(args);
3145 
3146  object_remove(op);
3147  *type = CFAPI_NONE;
3148 }
3149 
3150 static void cfapi_object_delete(int *type, ...) {
3151  va_list args;
3152  object *op;
3153 
3154  va_start(args, type);
3155 
3156  op = va_arg(args, object *);
3157 
3158  if (QUERY_FLAG(op, FLAG_FREED) || !QUERY_FLAG(op, FLAG_REMOVED)) {
3159  LOG(llevError, "Plugin trying to free freed/non removed object %s\n", op->name);
3160  *type = CFAPI_NONE;
3161  va_end(args);
3162  return;
3163  }
3164 
3165  va_end(args);
3166 
3168 
3169  *type = CFAPI_NONE;
3170 }
3171 
3177 static void cfapi_object_clone(int *type, ...) {
3178  va_list args;
3179  object *op;
3180  int kind;
3181  object **robj;
3182 
3183  va_start(args, type);
3184 
3185  op = va_arg(args, object *);
3186  kind = va_arg(args, int);
3187  robj = va_arg(args, object **);
3188 
3189  va_end(args);
3190 
3191  if (kind == 0) {
3192  *type = CFAPI_POBJECT;
3193  *robj = object_create_clone(op);
3194  } else {
3195  object *tmp;
3196  tmp = object_new();
3197  object_copy(op, tmp);
3198  *type = CFAPI_POBJECT;
3199  *robj = tmp;
3200  }
3201  return;
3202 }
3203 
3209 static void cfapi_object_create(int *type, ...) {
3210  va_list args;
3211  int ival;
3212  object **robj;
3213  va_start(args, type);
3214  ival = va_arg(args, int);
3215 
3216  *type = CFAPI_POBJECT;
3217  switch (ival) {
3218  case 0:
3219  robj = va_arg(args, object **);
3220  *robj = object_new();
3221  break;
3222 
3223  case 1: { /* Named object. Nearly the old plugin behavior, but we don't add artifact suffixes */
3224  const char *sval;
3225  archetype *at;
3226 
3227  sval = va_arg(args, const char *);
3228  robj = va_arg(args, object **);
3229  va_end(args);
3230 
3231  at = try_find_archetype(sval);
3232  if (!at)
3233  at = find_archetype_by_object_name(sval);
3234  if (at) {
3235  *robj = object_create_arch(at);
3236  } else
3237  *robj = NULL;
3238  }
3239  break;
3240 
3241  default:
3242  *type = CFAPI_NONE;
3243  break;
3244  }
3245  va_end(args);
3246 }
3247 
3248 static void cfapi_object_insert(int *type, ...) {
3249  va_list args;
3250  object *op;
3251  object *orig;
3252  mapstruct *map;
3253  int flag, x, y;
3254  int itype;
3255  object **robj;
3256 
3257  va_start(args, type);
3258 
3259  op = va_arg(args, object *);
3260  if (!op) {
3261  LOG(llevError, "cfapi_object_insert: called with NULL object!\n");
3262  va_end(args);
3263  return;
3264  }
3265  if (QUERY_FLAG(op, FLAG_FREED)) {
3266  LOG(llevError, "cfapi_object_insert: called with FREED object!\n");
3267  va_end(args);
3268  return;
3269  }
3270  if (!QUERY_FLAG(op, FLAG_REMOVED)) {
3271  LOG(llevError, "cfapi_object_insert: called with not removed object %s!\n", op->name);
3272  object_remove(op);
3273  }
3274  itype = va_arg(args, int);
3275 
3276  switch (itype) {
3277  case 0:
3278  map = va_arg(args, mapstruct *);
3279  orig = va_arg(args, object *);
3280  flag = va_arg(args, int);
3281  x = va_arg(args, int);
3282  y = va_arg(args, int);
3283  robj = va_arg(args, object **);
3284  if (!map) {
3285  LOG(llevError, "cfapi_object_insert (0): called with NULL map, object %s!\n", op->name);
3286  object_free(op, FREE_OBJ_NO_DESTROY_CALLBACK);
3287  *robj = NULL;
3288  } else
3289  *robj = object_insert_in_map_at(op, map, orig, flag, x, y);
3290  *type = CFAPI_POBJECT;
3291  break;
3292 
3293  case 1:
3294  map = va_arg(args, mapstruct *);
3295  orig = va_arg(args, object *);
3296  flag = va_arg(args, int);
3297  robj = va_arg(args, object **);
3298  if (!map) {
3299  LOG(llevError, "cfapi_object_insert (1): called with NULL map, object %s!\n", op->name);
3300  object_free(op, FREE_OBJ_NO_DESTROY_CALLBACK);
3301  *robj = NULL;
3302  } else
3303  *robj = object_insert_in_map_at(op, map, orig, flag, op->x, op->y);
3304  *type = CFAPI_POBJECT;
3305  break;
3306 
3307  case 2:
3308  map = va_arg(args, mapstruct *);
3309  orig = va_arg(args, object *);
3310  flag = va_arg(args, int);
3311  x = va_arg(args, int);
3312  y = va_arg(args, int);
3313  robj = va_arg(args, object **);
3314  if (!map) {
3315  LOG(llevError, "cfapi_object_insert (0): called with NULL map, object %s!\n", op->name);
3316  object_free(op, FREE_OBJ_NO_DESTROY_CALLBACK);
3317  *robj = NULL;
3318  } else {
3319  int dir = object_find_free_spot(op, map, x, y, 0, SIZEOFFREE);
3320  if (dir != -1) {
3321  *robj = object_insert_in_map_at(op, map, orig, flag, x + freearr_x[dir], y + freearr_y[dir]);
3322  } else {
3324  *robj = NULL;
3325  }
3326  }
3327  *type = CFAPI_POBJECT;
3328  break;
3329 
3330  case 3:
3331  orig = va_arg(args, object *);
3332  robj = va_arg(args, object **);
3333  if (!orig) {
3334  LOG(llevError, "cfapi_object_insert (3): called with NULL orig, object %s!\n", op->name);
3335  object_free(op, FREE_OBJ_NO_DESTROY_CALLBACK);
3336  *robj = NULL;
3337  } else
3338  *robj = object_insert_in_ob(op, orig);
3339  *type = CFAPI_POBJECT;
3340  break;
3341 
3342  default:
3343  LOG(llevError, "cfapi_object_insert (1): called with itype %d which is not valid, object %s!\n", itype, op->name);
3344  object_free(op, FREE_OBJ_NO_DESTROY_CALLBACK);
3345  *type = CFAPI_NONE;
3346  break;
3347  }
3348 
3349  va_end(args);
3350 }
3356 static void cfapi_object_split(int *type, ...) {
3357  va_list args;
3358 
3359  int nr, size;
3360  object *op;
3361  char *buf;
3362  object **split;
3363 
3364  va_start(args, type);
3365 
3366  op = va_arg(args, object *);
3367  nr = va_arg(args, int);
3368  buf = va_arg(args, char *);
3369  size = va_arg(args, int);
3370  split = va_arg(args, object **);
3371  va_end(args);
3372 
3373  *split = object_split(op, nr, buf, size);
3374  if (*split != NULL)
3375  {
3376  *type = CFAPI_POBJECT;
3377  }
3378  else
3379  {
3380  *type = CFAPI_NONE;
3381  }
3382 }
3383 
3389 static void cfapi_object_merge(int *type, ...) {
3390  va_list args;
3391  object *op;
3392  object *op2;
3393  object **merge;
3394 
3395  va_start(args, type);
3396 
3397  op = va_arg(args, object *);
3398  op2 = va_arg(args, object *);
3399  merge = va_arg(args, object **);
3400 
3401  va_end(args);
3402 
3403  *type = CFAPI_POBJECT;
3404  *merge = object_merge(op, op2);
3405 }
3406 
3412 static void cfapi_object_distance(int *type, ...) {
3413  va_list args;
3414  object *op;
3415  object *op2;
3416  int *rint;
3417  va_start(args, type);
3418 
3419  op = va_arg(args, object *);
3420  op2 = va_arg(args, object *);
3421  rint = va_arg(args, int *);
3422 
3423  va_end(args);
3424 
3425  *type = CFAPI_INT;
3426  *rint = object_distance(op, op2);
3427 }
3433 static void cfapi_object_update(int *type, ...) {
3434  va_list args;
3435  int action;
3436  object *op;
3437  va_start(args, type);
3438 
3439  op = va_arg(args, object *);
3440  action = va_arg(args, int);
3441 
3442  va_end(args);
3443 
3444  object_update(op, action);
3445  *type = CFAPI_NONE;
3446 }
3447 
3453 static void cfapi_object_clear(int *type, ...) {
3454  va_list args;
3455  object *op;
3456  va_start(args, type);
3457 
3458  op = va_arg(args, object *);
3459 
3460  va_end(args);
3461 
3462  object_clear(op);
3463  *type = CFAPI_NONE;
3464 }
3465 
3471 static void cfapi_object_reset(int *type, ...) {
3472  va_list args;
3473  object *op;
3474 
3475  va_start(args, type);
3476 
3477  op = va_arg(args, object *);
3478 
3479  va_end(args);
3480 
3481  object_reset(op);
3482  *type = CFAPI_NONE;
3483 }
3484 
3485 static void cfapi_object_clean_object(int *type, ...) {
3486  va_list args;
3487  object *op;
3488 
3489  va_start(args, type);
3490  op = va_arg(args, object *);
3491  clean_object(op);
3492  va_end(args);
3493  *type = CFAPI_NONE;
3494 }
3495 
3496 static void cfapi_object_on_same_map(int *type, ...) {
3497  va_list args;
3498  object *op1;
3499  object *op2;
3500  int *rint;
3501 
3502  va_start(args, type);
3503  op1 = va_arg(args, object *);
3504  op2 = va_arg(args, object *);
3505  rint = va_arg(args, int *);
3506  va_end(args);
3507 
3508  *type = CFAPI_INT;
3509  *rint = on_same_map(op1, op2);
3510 }
3511 
3512 static void cfapi_object_spring_trap(int *type, ...) {
3513  object *trap;
3514  object *victim;
3515  va_list args;
3516 
3517  va_start(args, type);
3518  trap = va_arg(args, object *);
3519  victim = va_arg(args, object *);
3520  va_end(args);
3521 
3522  spring_trap(trap, victim);
3523  *type = CFAPI_NONE;
3524 }
3525 
3531 static void cfapi_object_check_trigger(int *type, ...) {
3532  object *op;
3533  object *cause;
3534  va_list args;
3535  int *rint;
3536 
3537  va_start(args, type);
3538  op = va_arg(args, object *);
3539  cause = va_arg(args, object *);
3540  rint = va_arg(args, int *);
3541  va_end(args);
3542 
3543  *rint = check_trigger(op, cause);
3544  *type = CFAPI_INT;
3545 }
3546 
3558 static void cfapi_map_trigger_connected(int *type, ...) {
3559  objectlink *ol;
3560  object *cause;
3561  int state;
3562  va_list args;
3563 
3564  va_start(args, type);
3565  ol = va_arg(args, objectlink *);
3566  cause = va_arg(args, object *);
3567  state = va_arg(args, int);
3568  va_end(args);
3569  trigger_connected(ol, cause, state);
3570  *type = CFAPI_NONE;
3571 }
3572 
3578 static void cfapi_object_query_money(int *type, ...) {
3579  object *op;
3580  va_list args;
3581  int *rint;
3582 
3583  va_start(args, type);
3584  op = va_arg(args, object *);
3585  rint = va_arg(args, int *);
3586  va_end(args);
3587 
3588  *rint = query_money(op);
3589  *type = CFAPI_INT;
3590 }
3591 
3597 static void cfapi_object_cast(int *type, ...) {
3598  object *op;
3599  object *sp;
3600  int dir;
3601  char *str;
3602  object *caster;
3603  va_list args;
3604  int *rint;
3605 
3606  va_start(args, type);
3607  op = va_arg(args, object *);
3608  caster = va_arg(args, object *);
3609  dir = va_arg(args, int);
3610  sp = va_arg(args, object *);
3611  str = va_arg(args, char *);
3612  rint = va_arg(args, int *);
3613  va_end(args);
3614 
3615  *type = CFAPI_INT;
3616 
3617  if (!op->map) {
3618  *rint = -1;
3619  return;
3620  }
3621 
3622  *rint = cast_spell(op, caster, dir, sp, str);
3623 }
3624 
3625 static void cfapi_object_learn_spell(int *type, ...) {
3626  object *op;
3627  object *sp;
3628  int prayer;
3629  va_list args;
3630 
3631  va_start(args, type);
3632  op = va_arg(args, object *);
3633  sp = va_arg(args, object *);
3634  prayer = va_arg(args, int);
3635  va_end(args);
3636  do_learn_spell(op, sp, prayer);
3637  *type = CFAPI_NONE;
3638 }
3639 
3640 static void cfapi_object_forget_spell(int *type, ...) {
3641  object *op;
3642  object *sp;
3643  va_list args;
3644  char name[MAX_BUF];
3645 
3646  va_start(args, type);
3647  op = va_arg(args, object *);
3648  sp = va_arg(args, object *);
3649  va_end(args);
3650  query_name(sp, name, MAX_BUF);
3651  do_forget_spell(op, name);
3652  *type = CFAPI_NONE;
3653 }
3654 
3660 static void cfapi_object_check_spell(int *type, ...) {
3661  object *op;
3662  char *spellname;
3663  va_list args;
3664  object **robj;
3665 
3666  va_start(args, type);
3667  op = va_arg(args, object *);
3668  spellname = va_arg(args, char *);
3669  robj = va_arg(args, object **);
3670  va_end(args);
3671  *robj = check_spell_known(op, spellname);
3672  *type = CFAPI_POBJECT;
3673 }
3674 
3680 static void cfapi_object_pay_amount(int *type, ...) {
3681  object *op;
3682  uint64_t amount;
3683  va_list args;
3684  int *rint;
3685 
3686  va_start(args, type);
3687  op = va_arg(args, object *);
3688  amount = va_arg(args, uint64_t);
3689  rint = va_arg(args, int *);
3690  va_end(args);
3691 
3692  *rint = pay_for_amount(amount, op);
3693  *type = CFAPI_INT;
3694 }
3695 
3701 static void cfapi_object_pay_item(int *type, ...) {
3702  object *op;
3703  object *tobuy;
3704  int *rint;
3705 
3706  va_list args;
3707 
3708  va_start(args, type);
3709  tobuy = va_arg(args, object *);
3710  op = va_arg(args, object *);
3711  rint = va_arg(args, int *);
3712  va_end(args);
3713 
3714  *rint = pay_for_item(tobuy, op, 0);
3715  *type = CFAPI_INT;
3716 }
3717 
3725 static void cfapi_object_transfer(int *type, ...) {
3726  object *op;
3727  object *originator;
3728  int x, y, randompos, ttype, flag;
3729  va_list args;
3730  mapstruct *map;
3731  int *rint;
3732  object **robj;
3733 
3734  va_start(args, type);
3735  op = va_arg(args, object *);
3736  ttype = va_arg(args, int);
3737  switch (ttype) {
3738  case 0:
3739  x = va_arg(args, int);
3740  y = va_arg(args, int);
3741  randompos = va_arg(args, int);
3742  originator = va_arg(args, object *);
3743  rint = va_arg(args, int *);
3744  va_end(args);
3745 
3746  *rint = transfer_ob(op, x, y, randompos, originator);
3747  *type = CFAPI_INT;
3748  return;
3749  break;
3750 
3751  case 1:
3752  map = va_arg(args, mapstruct *);
3753  originator = va_arg(args, object *);
3754  flag = va_arg(args, int);
3755  x = va_arg(args, int);
3756  y = va_arg(args, int);
3757  robj = va_arg(args, object **);
3758  va_end(args);
3759  if (x < 0 || y < 0) {
3760  x = map->enter_x;
3761  y = map->enter_y;
3762  }
3763  *robj = object_insert_in_map_at(op, map, originator, flag, x, y);
3764  *type = CFAPI_POBJECT;
3765  return;
3766  break;
3767 
3768  case 2:
3769  x = va_arg(args, int);
3770  y = va_arg(args, int);
3771  rint = va_arg(args, int *);
3772  va_end(args);
3773 
3774  *rint = move_to(op, x, y);
3775  *type = CFAPI_INT;
3776  return;
3777 
3778  default:
3779  va_end(args);
3780  *type = CFAPI_NONE;
3781  return;
3782  break;
3783  }
3784 }
3785 
3789 static void cfapi_object_find_archetype_inside(int *type, ...) {
3790  object *op;
3791  char *str;
3792  va_list args;
3793  object **robj;
3794 
3795  *type = CFAPI_POBJECT;
3796  va_start(args, type);
3797  op = va_arg(args, object *);
3798 
3799  str = va_arg(args, char *);
3800  robj = va_arg(args, object **);
3801  archetype *at = try_find_archetype(str);
3802  *robj = at == NULL ? NULL : arch_present_in_ob(at, op);
3803  if (*robj == NULL) {
3804  char name[MAX_BUF];
3805 
3806  /* Search by name or slaying instead */
3807  FOR_INV_PREPARE(op, tmp) {
3808  query_name(tmp, name, MAX_BUF);
3809  if (!strncmp(name, str, strlen(str)))
3810  *robj = tmp;
3811  if (!strncmp(tmp->name, str, strlen(str)))
3812  *robj = tmp;
3813  if (tmp->slaying && !strcmp(tmp->slaying, str))
3814  *robj = tmp;
3815  if (*robj != NULL)
3816  break;
3817  } FOR_INV_FINISH();
3818  }
3819  va_end(args);
3820 }
3821 
3822 static void cfapi_object_find_by_arch_name(int *type, ...) {
3823  const object *who;
3824  object **result;
3825  const char *name;
3826  va_list args;
3827 
3828  va_start(args, type);
3829  who = va_arg(args, const object *);
3830  name = va_arg(args, const char *);
3831  result = va_arg(args, object **);
3832  va_end(args);
3833  *type = CFAPI_POBJECT;
3834 
3835  *result = object_find_by_arch_name(who, name);
3836 }
3837 
3838 static void cfapi_object_find_by_name(int *type, ...) {
3839  const object *who;
3840  object **result;
3841  const char *name;
3842  va_list args;
3843 
3844  va_start(args, type);
3845  who = va_arg(args, const object *);
3846  name = va_arg(args, const char *);
3847  result = va_arg(args, object **);
3848  va_end(args);
3849  *type = CFAPI_POBJECT;
3850 
3851  *result = object_find_by_name(who, name);
3852 }
3853 
3859 static void cfapi_object_drop(int *type, ...) {
3860  object *op;
3861  object *author;
3862  va_list args;
3863 
3864  va_start(args, type);
3865  op = va_arg(args, object *);
3866  author = va_arg(args, object *);
3867  va_end(args);
3868  *type = CFAPI_NONE;
3869 
3870  if (QUERY_FLAG(op, FLAG_NO_DROP))
3871  return;
3872  drop(author, op);
3873 
3874  if (author->type == PLAYER) {
3875  author->contr->count = 0;
3876  author->contr->socket.update_look = 1;
3877  }
3878 }
3879 
3883 static void cfapi_object_change_abil(int *type, ...) {
3884  object *op, *tmp;
3885  int *rint;
3886  va_list args;
3887 
3888  va_start(args, type);
3889  op = va_arg(args, object *);
3890  tmp = va_arg(args, object *);
3891  rint = va_arg(args, int *);
3892  va_end(args);
3893 
3894  *type = CFAPI_INT;
3895  *rint = change_abil(op, tmp);
3896 }
3897 
3898 static void cfapi_object_say(int *type, ...) {
3899  object *op;
3900  char *msg;
3901  va_list args;
3902  int *rint;
3903  char empty[] = "";
3904 
3905  va_start(args, type);
3906  op = va_arg(args, object *);
3907  msg = va_arg(args, char *);
3908  rint = va_arg(args, int *);
3909  va_end(args);
3910 
3911  if (op->type == PLAYER) {
3912  command_say(op, msg == NULL ? empty : msg);
3913  } else {
3914  monster_npc_say(op, msg);
3915  }
3916  *rint = 0;
3917  *type = CFAPI_INT;
3918 }
3919 
3920 /* PLAYER SUBCLASS */
3921 
3927 static void cfapi_player_find(int *type, ...) {
3928  va_list args;
3929  char *sval;
3930  player **rpl;
3931  va_start(args, type);
3932 
3933  sval = va_arg(args, char *);
3934  rpl = va_arg(args, player **);
3935  va_end(args);
3936 
3937  *rpl = find_player_partial_name(sval);
3938 
3939  *type = CFAPI_PPLAYER;
3940 }
3941 
3942 static void cfapi_player_message(int *type, ...) {
3943  va_list args;
3944  int flags;
3945  int pri;
3946  object *pl;
3947  char *buf;
3948 
3949  va_start(args, type);
3950 
3951  flags = va_arg(args, int);
3952  pri = va_arg(args, int);
3953  pl = va_arg(args, object *);
3954  buf = va_arg(args, char *);
3955  va_end(args);
3956 
3957  draw_ext_info(flags, pri, pl, MSG_TYPE_MISC, MSG_SUBTYPE_NONE,
3958  buf);
3959  *type = CFAPI_NONE;
3960 }
3961 
3968 static void cfapi_object_perm_exp(int *type, ...) {
3969  va_list args;
3970  object *op;
3971  int64_t *rlong;
3972 
3973  va_start(args, type);
3974  op = va_arg(args, object *);
3975  rlong = va_arg(args, int64_t *);
3976  va_end(args);
3977 
3978  *type = CFAPI_SINT64;
3979  *rlong = PERM_EXP(op->total_exp);
3980 }
3981 
3987 static void cfapi_object_change_exp(int *type, ...) {
3988  va_list args;
3989  int flag;
3990  object *ob;
3991  const char *skill;
3992  int64_t exp;
3993 
3994  va_start(args, type);
3995  ob = va_arg(args, object *);
3996  exp = va_arg(args, int64_t);
3997  skill = va_arg(args, const char *);
3998  flag = va_arg(args, int);
3999  va_end(args);
4000 
4001  *type = CFAPI_NONE;
4002  change_exp(ob, exp, skill, flag);
4003 }
4004 
4010 static void cfapi_player_can_pay(int *type, ...) {
4011  va_list args;
4012  object *pl;
4013  int *rint;
4014 
4015  va_start(args, type);
4016  pl = va_arg(args, object *);
4017  rint = va_arg(args, int *);
4018  va_end(args);
4019 
4020  *rint = can_pay(pl);
4021  *type = CFAPI_INT;
4022 }
4023 
4029 static void cfapi_player_knowledge(int *type, ...) {
4030  va_list args;
4031  object *pl;
4032  int *rint, what;
4033  const char *knowledge;
4034 
4035  va_start(args, type);
4036  what = va_arg(args, int);
4037 
4038  switch(what)
4039  {
4040  case 1:
4041  pl = va_arg(args, object *);
4042  knowledge = va_arg(args, const char *);
4043  rint = va_arg(args, int *);
4044 
4045  *type = CFAPI_INT;
4046 
4047  if (pl->contr == NULL) {
4048  LOG(llevError, "cfapi_player_knowledge: 'has' called for non player object %s", pl->name);
4049  *rint = 0;
4050  va_end(args);
4051  return;
4052  }
4053 
4054  *rint = knowledge_player_knows(pl->contr, knowledge);
4055  break;
4056 
4057  case 2:
4058  pl = va_arg(args, object *);
4059  knowledge = va_arg(args, const char *);
4060  *type = CFAPI_NONE;
4061  if (pl->contr != NULL)
4062  knowledge_give(pl->contr, knowledge, NULL);
4063 
4064  break;
4065 
4066  default:
4067  LOG(llevError, "cfapi_player_knowledge: invalid what %d", what);
4068  }
4069 
4070  va_end(args);
4071 }
4072 
4078 static void cfapi_object_teleport(int *type, ...) {
4079  mapstruct *map;
4080  int x, y;
4081  object *who;
4082  int *res;
4083  va_list args;
4084 
4085  va_start(args, type);
4086  who = va_arg(args, object *);
4087  map = va_arg(args, mapstruct *);
4088  x = va_arg(args, int);
4089  y = va_arg(args, int);
4090  res = va_arg(args, int *);
4091  *type = CFAPI_INT;
4092 
4093  if (!out_of_map(map, x, y)) {
4094  int k;
4095  k = object_find_first_free_spot(who, map, x, y);
4096  if (k == -1) {
4097  *res = 1;
4098  va_end(args);
4099  return;
4100  }
4101 
4102  if (!QUERY_FLAG(who, FLAG_REMOVED)) {
4103  object_remove(who);
4104  }
4105 
4106  object_insert_in_map_at(who, map, NULL, 0, x, y);
4107  if (who->type == PLAYER) {
4108  map_newmap_cmd(&who->contr->socket);
4110  }
4111  *res = 0;
4112  }
4113 
4114  va_end(args);
4115 }
4116 
4117 static void cfapi_object_pickup(int *type, ...) {
4118  object *who;
4119  object *what;
4120  va_list args;
4121 
4122  va_start(args, type);
4123  who = va_arg(args, object *);
4124  what = va_arg(args, object *);
4125  va_end(args);
4126 
4127  pick_up(who, what);
4128  *type = CFAPI_NONE;
4129 }
4130 
4131 /* Archetype-related functions */
4132 static void cfapi_archetype_get_property(int *type, ...) {
4133  int prop;
4134  archetype *arch;
4135  va_list args;
4136  sstring *rsstring;
4137  archetype **rarch;
4138  object **robject;
4139 
4140  va_start(args, type);
4141  arch = va_arg(args, archetype *);
4142  prop = va_arg(args, int);
4143  switch (prop) {
4144  case CFAPI_ARCH_PROP_NAME:
4145  *type = CFAPI_SSTRING;
4146  rsstring = va_arg(args, sstring *);
4147  *rsstring = arch->name;
4148  break;
4149 
4150  case CFAPI_ARCH_PROP_NEXT:
4151  *type = CFAPI_PARCH;
4152  rarch = va_arg(args, archetype **);
4153  *rarch = get_next_archetype(arch);
4154  break;
4155 
4156  case CFAPI_ARCH_PROP_HEAD:
4157  *type = CFAPI_PARCH;
4158  rarch = va_arg(args, archetype **);
4159  *rarch = arch->head;
4160  break;
4161 
4162  case CFAPI_ARCH_PROP_MORE:
4163  *type = CFAPI_PARCH;
4164  rarch = va_arg(args, archetype **);
4165  *rarch = arch->more;
4166  break;
4167 
4168  case CFAPI_ARCH_PROP_CLONE:
4169  *type = CFAPI_POBJECT;
4170  robject = va_arg(args, object **);
4171  *robject = &arch->clone;
4172  break;
4173 
4174  default:
4175  *type = CFAPI_NONE;
4176  break;
4177  }
4178  va_end(args);
4179 }
4180 
4187 static void cfapi_party_get_property(int *type, ...) {
4188  partylist *party;
4189  int prop;
4190  va_list args;
4191  object *obarg;
4192  sstring *rsstring;
4193  player **rplayer;
4194  partylist **rparty;
4195 
4196  va_start(args, type);
4197  party = va_arg(args, partylist *);
4198  prop = va_arg(args, int);
4199  switch (prop) {
4200  case CFAPI_PARTY_PROP_NAME:
4201  rsstring = va_arg(args, sstring *);
4202  *rsstring = party->partyname;
4203  *type = CFAPI_SSTRING;
4204  break;
4205 
4206  case CFAPI_PARTY_PROP_NEXT:
4207  rparty = va_arg(args, partylist **);
4208  *rparty = (party ? party_get_next(party) : party_get_first());
4209  *type = CFAPI_PPARTY;
4210  break;
4211 
4213  rsstring = va_arg(args, sstring *);
4214  *rsstring = party_get_password(party);
4215  *type = CFAPI_SSTRING;
4216  break;
4217 
4219  *type = CFAPI_PPLAYER;
4220  obarg = va_arg(args, object *);
4221  rplayer = va_arg(args, player **);
4222  *rplayer = (obarg ? obarg->contr : first_player);
4223  for (; *rplayer != NULL; (*rplayer) = (*rplayer)->next)
4224  if ((*rplayer)->ob->contr->party == party) {
4225  break;
4226  }
4227  break;
4228 
4229  default:
4230  *type = CFAPI_NONE;
4231  break;
4232  }
4233  va_end(args);
4234 }
4235 
4242 static void cfapi_region_get_property(int *type, ...) {
4243  region *reg;
4244  int prop, *rint;
4245  va_list args;
4247  sstring *rsstring;
4248  region **rregion;
4249 
4250  va_start(args, type);
4251  reg = va_arg(args, region *);
4252  prop = va_arg(args, int);
4253  switch (prop) {
4255  rsstring = va_arg(args, sstring *);
4256  *rsstring = reg->name;
4257  *type = CFAPI_SSTRING;
4258  break;
4259 
4261  rregion = va_arg(args, region **);
4262  *rregion = (reg ? reg->next : first_region);
4263  *type = CFAPI_PREGION;
4264  break;
4265 
4267  rregion = va_arg(args, region **);
4268  *rregion = reg->parent;
4269  *type = CFAPI_PREGION;
4270  break;
4271 
4273  rsstring = va_arg(args, sstring *);
4274  *rsstring = reg->longname;
4275  *type = CFAPI_SSTRING;
4276  break;
4277 
4279  rsstring = va_arg(args, sstring *);
4280  *rsstring = reg->msg;
4281  *type = CFAPI_SSTRING;
4282  break;
4283 
4286  rint = va_arg(args, int*);
4287  *rint = (prop == CFAPI_REGION_PROP_JAIL_X ? reg->jailx : reg->jaily);
4288  *type = CFAPI_INT;
4289  break;
4290 
4292  rsstring = va_arg(args, sstring *);
4293  *rsstring = reg->jailmap;
4294  *type = CFAPI_SSTRING;
4295  break;
4296 
4297  default:
4298  *type = CFAPI_NONE;
4299  break;
4300  }
4301  va_end(args);
4302 }
4303 
4315 static void cfapi_friendlylist_get_next(int *type, ...) {
4316  object *ob;
4317  va_list args;
4318  objectlink *link;
4319  object **robject;
4320 
4321  va_start(args, type);
4322  ob = va_arg(args, object *);
4323  robject = va_arg(args, object **);
4324  va_end(args);
4325 
4326  *type = CFAPI_POBJECT;
4327  *robject = NULL;
4328 
4329  if (ob) {
4330  for (link = first_friendly_object; link; link = link->next) {
4331  if (ob == link->ob) {
4332  if (link->next) {
4333  *robject = link->next->ob;
4334  return;
4335  } else {
4336  return;
4337  }
4338  }
4339  }
4340  return;
4341  }
4342 
4344  *robject = first_friendly_object->ob;
4345 }
4346 
4347 /*
4348  * Random-map related stuff.
4349  */
4350 
4357 static void cfapi_set_random_map_variable(int *type, ...) {
4358  va_list args;
4359  RMParms *rp;
4360  const char *buf;
4361  int *ret;
4362 
4363  va_start(args, type);
4364  rp = va_arg(args, RMParms *);
4365  buf = va_arg(args, const char *);
4366  ret = va_arg(args, int *);
4367  va_end(args);
4368 
4369  *ret = set_random_map_variable(rp, buf);
4370  *type = CFAPI_INT;
4371 }
4372 
4379 static void cfapi_generate_random_map(int *type, ...) {
4380  va_list args;
4381  const char *name;
4382  RMParms *rp;
4383  char **use_layout;
4384  mapstruct **ret;
4385 
4386  va_start(args, type);
4387  name = va_arg(args, const char *);
4388  rp = va_arg(args, RMParms *);
4389  use_layout = va_arg(args, char **);
4390  ret = va_arg(args, mapstruct **);
4391  va_end(args);
4392 
4393  *ret = generate_random_map(name, rp, use_layout);
4394 }
4395 
4396 static void cfapi_object_user_event(int *type, ...) {
4397  object *op;
4398  object *activator;
4399  object *third;
4400  const char *message;
4401  int fix;
4402  int *ret;
4403  va_list args;
4404 
4405  va_start(args, type);
4406  op = va_arg(args, object *);
4407  activator = va_arg(args, object *);
4408  third = va_arg(args, object *);
4409  message = va_arg(args, const char *);
4410  fix = va_arg(args, int);
4411  ret = va_arg(args, int *);
4412  va_end(args);
4413 
4414  *ret = events_execute_object_user(op, activator, third, message, fix);
4415  *type = CFAPI_INT;
4416 }
4417 
4420 static void cfapi_player_quest(int *type, ...) {
4421  int op;
4422  va_list args;
4423  object *player;
4424  sstring code;
4425 
4426  va_start(args, type);
4427  op = va_arg(args, int);
4428  player = va_arg(args, object *);
4429  code = va_arg(args, sstring);
4430 
4431  if (player->contr == NULL) {
4432  LOG(llevError, "cfapi_player_quest called with non player object %s!\n", player->name);
4433  va_end(args);
4434  /* crash/quit? */
4435  return;
4436  }
4437 
4438  switch(op) {
4439  case CFAPI_PLAYER_QUEST_START: {
4440  int state = va_arg(args, int);
4441  quest_start(player->contr, code, state);
4442  *type = CFAPI_NONE;
4443  break;
4444  }
4446  int *ret = va_arg(args, int *);
4447  *ret = quest_get_player_state(player->contr, code);
4448  *type = CFAPI_INT;
4449  break;
4450  }
4452  int state = va_arg(args, int);
4453  quest_set_player_state(player->contr, code, state);
4454  *type = CFAPI_NONE;
4455  break;
4456  }
4458  int *ret = va_arg(args, int*);
4459  *ret = quest_was_completed(player->contr, code);
4460  *type = CFAPI_INT;
4461  break;
4462  }
4463  default:
4464  LOG(llevError, "invalid quest type: %d\n", op);
4465  *type = CFAPI_NONE;
4466  }
4467 
4468  va_end(args);
4469 }
4470 
4471 /*****************************************************************************/
4472 /* NEW PLUGIN STUFF ENDS HERE */
4473 /*****************************************************************************/
4474 
4475 
4488  int i;
4489  crossfire_plugin *cp;
4490 
4491  assert(cmd != NULL);
4492  assert(command != NULL);
4493 
4494  if (plugins_list == NULL)
4495  return NULL;
4496 
4497  for (cp = plugins_list; cp != NULL; cp = cp->next) {
4498  if (cp->propfunc(&i, "command?", cmd, command) != NULL)
4499  return command;
4500  }
4501  return NULL;
4502 }
4503 
4508 void initPlugins(void) {
4509  struct dirent *currentfile;
4510  DIR *plugdir;
4511  size_t l;
4512  char buf[MAX_BUF];
4513 
4514  snprintf(buf, sizeof(buf), "%s/plugins/", LIBDIR);
4515  LOG(llevDebug, "plugins: loading from %s\n", buf);
4516 
4517  plugdir = opendir(buf);
4518  if (plugdir == NULL)
4519  return;
4520 
4521  while ((currentfile = readdir(plugdir)) != NULL) {
4522  l = strlen(currentfile->d_name);
4523  if (l > strlen(PLUGIN_SUFFIX)) {
4525  int ignore = 0;
4526 
4527  if (strcmp(currentfile->d_name+l-strlen(PLUGIN_SUFFIX), PLUGIN_SUFFIX) != 0)
4528  continue;
4529 
4530  while (disable) {
4531  if (strcmp(disable->name, "All") == 0) {
4532  LOG(llevInfo, "plugins: disabling (all) %s\n", currentfile->d_name);
4533  ignore = 1;
4534  break;
4535  }
4536  if (strncmp(disable->name, currentfile->d_name, strlen(disable->name)) == 0 && strlen(currentfile->d_name) == strlen(PLUGIN_SUFFIX) + strlen(disable->name)) {
4537  LOG(llevInfo, "plugins: disabling %s\n", currentfile->d_name);
4538  ignore = 1;
4539  break;
4540  }
4541  disable = disable->next;
4542  }
4543  if (ignore == 0) {
4544  snprintf(buf, sizeof(buf), "%s/plugins/%s", LIBDIR, currentfile->d_name);
4545  LOG(llevInfo, "plugins: loading %s\n", currentfile->d_name);
4546  plugins_init_plugin(buf);
4547  }
4548  }
4549  }
4550 
4551  closedir(plugdir);
4552 }
4553 
4558 void cleanupPlugins(void) {
4559  crossfire_plugin *cp;
4560 
4561  if (!plugins_list)
4562  return;
4563 
4564  for (cp = plugins_list; cp != NULL; ) {
4565  crossfire_plugin *next = cp->next;
4566  if (cp->closefunc)
4567  cp->closefunc();
4568  /* Don't actually unload plugins, it makes backtraces for memory
4569  * debugging (printed at exit) messed up. And it doesn't matter if we
4570  * don't free it here. The OS will do it for us.
4571  */
4572  /* plugins_dlclose(cp->libptr); */
4573  free(cp);
4574  cp = next;
4575  }
4576  plugins_list = NULL;
4577 }
#define CFAPI_OBJECT_PROP_STR
Definition: plugin.h:201
#define CFAPI_OBJECT_PROP_MAP
Definition: plugin.h:132
#define CFAPI_OBJECT_PROP_RUN_AWAY
Definition: plugin.h:178
static void cfapi_object_clear(int *type,...)
Definition: plugins.c:3453
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Definition: main.c:313
int object_distance(const object *ob1, const object *ob2)
Definition: object.c:3451
void spring_trap(object *trap, object *victim)
Definition: rune.c:205
static void cfapi_map_trigger_connected(int *type,...)
Definition: plugins.c:3558
static void copy_message(object *op, const char *msg)
Definition: plugins.c:2285
static void cfapi_set_random_map_variable(int *type,...)
Definition: plugins.c:4357
char path[HUGE_BUF]
Definition: map.h:366
#define CFAPI_OBJECT_PROP_MAGIC
Definition: plugin.h:159
void apply_by_living_below(object *pl)
Definition: apply.c:695
#define CFAPI_PLAYER_QUEST_GET_STATE
Definition: plugin.h:244
#define MSG_TYPE_MISC
Definition: newclient.h:389
#define FLAG_NO_DROP
Definition: define.h:289
#define CFAPI_PARTY_PROP_PASSWORD
Definition: plugin.h:275
Definition: player.h:92
int apply_manual(object *op, object *tmp, int aflag)
Definition: apply.c:597
#define CFAPI_OBJECT_PROP_MATERIAL
Definition: plugin.h:157
const char * determine_god(object *op)
Definition: gods.c:106
#define CFAPI_OBJECT_PROP_ANIMATION
Definition: plugin.h:222
mapstruct * generate_random_map(const char *OutFileName, RMParms *RP, char **use_layout)
Definition: random_map.c:74
#define CFAPI_OBJECT_PROP_SP
Definition: plugin.h:211
void events_register_object_handler(const char *id, f_plug_event handler)
Definition: events.cpp:249
#define CFAPI_OBJECT_PROP_CARRYING
Definition: plugin.h:172
#define plugins_dlopen(fname)
Definition: plugin.h:116
#define CFAPI_OBJECT_PROP_NAME
Definition: plugin.h:134
#define CFAPI_OBJECT_PROP_OB_BELOW
Definition: plugin.h:125
#define CFAPI_PREGION
Definition: plugin.h:73
#define CFAPI_PLAYER_PROP_TITLE
Definition: plugin.h:241
#define CFAPI_MAP_PROP_NAME
Definition: plugin.h:252
int16_t jaily
Definition: map.h:299
void object_free(object *ob, int flags)
Definition: object.c:1348
int move_player(object *op, int dir)
Definition: player.c:2913
static void cfapi_object_drain(int *type,...)
Definition: plugins.c:3042
static void cfapi_system_register_global_event(int *type,...)
Definition: plugins.c:607
void quest_start(player *pl, sstring quest_code, int state)
Definition: quest.c:1088
static void cfapi_system_find_animation(int *type,...)
Definition: plugins.c:549
static void cfapi_object_move(int *type,...)
Definition: plugins.c:1388
#define CFAPI_OBJECT_PROP_RACE
Definition: plugin.h:137
object * check_spell_known(object *op, const char *name)
Definition: spell_util.c:433
#define CFAPI_MAP_PROP_ENTER_Y
Definition: plugin.h:261
static void cfapi_object_check_spell(int *type,...)
Definition: plugins.c:3660
#define CFAPI_REGION_PROP_MESSAGE
Definition: plugin.h:282
#define P_NEED_UPDATE
Definition: map.h:240
int is_magical(const object *op)
Definition: item.c:1195
#define CFAPI_MAP_PROP_FLAGS
Definition: plugin.h:248
#define CFAPI_MAP_PROP_DARKNESS
Definition: plugin.h:257
#define CFAPI_OBJECT_PROP_ARCHETYPE
Definition: plugin.h:185
#define CFAPI_OBJECT_PROP_WEIGHT
Definition: plugin.h:170
static void cfapi_get_month_name(int *type,...)
Definition: plugins.c:860
#define CFAPI_OBJECT_PROP_ATTACK_TYPE
Definition: plugin.h:153
static void cfapi_object_pickup(int *type,...)
Definition: plugins.c:4117
#define CFAPI_OBJECT_PROP_FACE
Definition: plugin.h:221
mapstruct * get_empty_map(int sizex, int sizey)
Definition: map.c:870
static void cfapi_archetype_get_property(int *type,...)
Definition: plugins.c:4132
static void cfapi_object_pay_amount(int *type,...)
Definition: plugins.c:3680
#define SET_FLAG(xyz, p)
Definition: define.h:223
#define NR_OF_HOOKS
Definition: plugins.c:43
void do_forget_spell(object *op, const char *spell)
Definition: apply.c:525
linked_char * disabled_plugins
Definition: global.h:326
static void cfapi_object_get_property(int *type,...)
Definition: plugins.c:1483
#define plugins_dlsym(lib, name)
Definition: plugin.h:118
StringBuffer * buf
Definition: readable.c:1591
#define CFAPI_FUNC
Definition: plugin.h:70
#define PLUGIN_SUFFIX
Definition: win32.h:106
static void cfapi_object_spring_trap(int *type,...)
Definition: plugins.c:3512
#define CFAPI_OBJECT_PROP_GOD
Definition: plugin.h:218
#define CFAPI_OBJECT_PROP_PICK_UP
Definition: plugin.h:167
#define CFAPI_MAP_PROP_DIFFICULTY
Definition: plugin.h:249
void player_get_title(const struct pl *pl, char *buf, size_t bufsize)
Definition: player.c:224
#define CFAPI_MAP_PROP_HEIGHT
Definition: plugin.h:259
#define CFAPI_OBJECT_PROP_DIRECTION
Definition: plugin.h:147
#define strdup_local
Definition: compat.h:25
object * object_get_env_recursive(object *op)
Definition: object.c:360
EXTERN objectlink * first_friendly_object
Definition: global.h:119
#define CFAPI_OBJECT_PROP_NEXT_ACTIVE_OB
Definition: plugin.h:126
#define CFAPI_OBJECT_PROP_MAXGP
Definition: plugin.h:216
int player_arrest(object *who)
Definition: c_wiz.c:792
#define CFAPI_OBJECT_PROP_HIDDEN
Definition: plugin.h:180
static void cfapi_region_get_property(int *type,...)
Definition: plugins.c:4242
static void cfapi_object_on_same_map(int *type,...)
Definition: plugins.c:3496
static void cfapi_system_find_face(int *type,...)
Definition: plugins.c:570
int16_t players
Definition: map.h:345
static void cfapi_object_give_skill(int *type,...)
Definition: plugins.c:3095
#define CFAPI_OBJECT_PROP_MOVE_STATUS
Definition: plugin.h:181
const char * get_season_name(const int index)
Definition: time.c:123
char * create_pathname(const char *name, char *buf, size_t size)
Definition: map.c:113
Definition: face.h:14
void knowledge_give(player *pl, const char *marker, const object *book)
Definition: knowledge.c:1021
mapstruct * ready_map_name(const char *name, int flags)
Definition: map.c:1797
const char * playerdir
Definition: global.h:247
unsigned char MoveType
Definition: define.h:432
#define CFAPI_OBJECT_PROP_SUBTYPE
Definition: plugin.h:150
partylist * party_get_next(const partylist *party)
Definition: party.c:208
void free_string(sstring str)
Definition: shstr.c:280
signed long object_sum_weight(object *op)
Definition: object.c:338
#define TIMER_ERR_ID
Definition: timers.h:67
#define CFAPI_REGION_PROP_JAIL_X
Definition: plugin.h:283
static void cfapi_get_periodofday_name(int *type,...)
Definition: plugins.c:872
#define CFAPI_ARCH_PROP_MORE
Definition: plugin.h:270
#define SET_ANIMATION(ob, newanim)
Definition: global.h:160
static void cfapi_object_find_by_arch_name(int *type,...)
Definition: plugins.c:3822
mapstruct * get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y)
Definition: map.c:2394
void esrv_update_item(int flags, object *pl, object *op)
Definition: main.c:340
#define CFAPI_OBJECT_PROP_CONTAINER
Definition: plugin.h:131
const char * object_get_value(const object *op, const char *const key)
Definition: object.c:4136
#define CFAPI_INT16
Definition: plugin.h:74
void pick_up(object *op, object *alt)
Definition: c_object.c:509
f_plug_api func
Definition: plugin.h:304
#define CFAPI_OBJECT_PROP_INVENTORY
Definition: plugin.h:128
void query_base_name(const object *op, int plural, char *buf, size_t size)
Definition: item.c:680
struct pl player
#define NR_EVENTS
Definition: events.h:57
static void cfapi_object_set_property(int *type,...)
Definition: plugins.c:2302
#define CFAPI_OBJECT_PROP_FLAGS
Definition: plugin.h:200
static void cfapi_get_season_name(int *type,...)
Definition: plugins.c:836
short freearr_x[SIZEOFFREE]
Definition: object.c:65
uint32_t reset_time
Definition: map.h:333
int calculate_difficulty(mapstruct *m)
Definition: map.c:1920
#define CFAPI_SINT64
Definition: plugin.h:76
#define CFAPI_OBJECT_PROP_NAME_PLURAL
Definition: plugin.h:135
static void cfapi_log(int *type,...)
Definition: plugins.c:939
const char * get_weekday(const int index)
Definition: time.c:116
region * get_region_by_map(mapstruct *m)
Definition: region.c:74
static void cfapi_object_find_archetype_inside(int *type,...)
Definition: plugins.c:3789
DIR * opendir(const char *)
Definition: win32.c:37
#define CFAPI_OBJECT_PROP_OWNER
Definition: plugin.h:195
static void cfapi_object_teleport(int *type,...)
Definition: plugins.c:4078
static void cfapi_system_re_cmp(int *type,...)
Definition: plugins.c:734
const char * party_get_password(const partylist *party)
Definition: party.c:232
crossfire_plugin * plugins_list
Definition: plugins.c:237
#define CFAPI_OBJECT_PROP_MOVE_ON
Definition: plugin.h:227
static void cfapi_map_get_map_property(int *type,...)
Definition: plugins.c:1066
#define CFAPI_OBJECT_PROP_MESSAGE
Definition: plugin.h:140
static void cfapi_map_delete_map(int *type,...)
Definition: plugins.c:1266
#define CFAPI_OBJECT_PROP_EXP_MULTIPLIER
Definition: plugin.h:184
#define plugins_dlclose(lib)
Definition: plugin.h:117
#define CFAPI_MAP_PROP_RESET_TIMEOUT
Definition: plugin.h:254
char id[MAX_BUF]
Definition: plugin.h:101
void initPlugins(void)
Definition: plugins.c:4508
object * arch_present_in_ob(const archetype *at, const object *op)
Definition: object.c:2954
#define CFAPI_PLAYER_QUEST_START
Definition: plugin.h:243
#define CFAPI_DOUBLE
Definition: plugin.h:68
static void cfapi_object_insert(int *type,...)
Definition: plugins.c:3248
void remove_friendly_object(object *op)
Definition: friend.c:56
#define CFAPI_REGION_PROP_NEXT
Definition: plugin.h:279
void object_update(object *op, int action)
Definition: object.c:1190
static void cfapi_object_drop(int *type,...)
Definition: plugins.c:3859
static void cfapi_object_fix(int *type,...)
Definition: plugins.c:3079
static void cfapi_map_set_map_property(int *type,...)
Definition: plugins.c:1198
static void cfapi_object_set_key(int *type,...)
Definition: plugins.c:1460
#define CFAPI_MAP_PROP_NEXT
Definition: plugin.h:263
static void cfapi_party_get_property(int *type,...)
Definition: plugins.c:4187
int object_can_merge(object *ob1, object *ob2)
Definition: object.c:199
#define CFAPI_OBJECT_PROP_SLAYING
Definition: plugin.h:138
static void cfapi_map_create_path(int *type,...)
Definition: plugins.c:1032
Definition: win32.h:110
#define safe_strncpy
Definition: compat.h:23
void free_dialog_information(object *op)
Definition: dialog.c:32
char * partyname
Definition: party.h:14
static void cfapi_system_find_string(int *type,...)
Definition: plugins.c:692
object * object_find_by_name(const object *who, const char *name)
Definition: object.c:3746
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:308
#define CFAPI_PMAP
Definition: plugin.h:66
static void cfapi_object_apply_below(int *type,...)
Definition: plugins.c:2955
void transmute_materialname(object *op, const object *change)
Definition: utils.c:267
static void cfapi_timer_create(int *type,...)
Definition: plugins.c:887
Definition: plugin.h:303
static void cfapi_player_quest(int *type,...)
Definition: plugins.c:4420
#define CFAPI_POBJECT
Definition: plugin.h:65
static void cfapi_object_split(int *type,...)
Definition: plugins.c:3356
#define CFAPI_OBJECT_PROP_CHOSEN_SKILL
Definition: plugin.h:179
#define CFAPI_OBJECT_PROP_OTHER_ARCH
Definition: plugin.h:186
#define CFAPI_OBJECT_PROP_LAST_SP
Definition: plugin.h:163
archetype * try_find_archetype(const char *name)
Definition: assets.cpp:257
int change_map_light(mapstruct *m, int change)
Definition: map.c:2018
#define CFAPI_REGION_PROP_JAIL_PATH
Definition: plugin.h:285
#define FLAG_REMOVED
Definition: define.h:232
static void cfapi_object_delete(int *type,...)
Definition: plugins.c:3150
#define CFAPI_OBJECT_PROP_LAST_GRACE
Definition: plugin.h:164
static void cfapi_object_find_by_name(int *type,...)
Definition: plugins.c:3838
#define CFAPI_OBJECT_PROP_COUNT
Definition: plugin.h:133
short freearr_y[SIZEOFFREE]
Definition: object.c:71
static void cfapi_object_remove(int *type,...)
Definition: plugins.c:3129
#define CFAPI_NONE
Definition: plugin.h:60
#define UPD_ALL
Definition: newclient.h:297
void command_say(object *op, const char *params)
Definition: c_chat.c:34
#define MOVE_ALL
Definition: define.h:413
uint16_t height
Definition: map.h:348
object * give_skill_by_name(object *op, const char *skill_name)
Definition: living.c:1777
static void cfapi_object_transmute(int *type,...)
Definition: plugins.c:3112
const char * get_month_name(const int index)
Definition: time.c:109
event_registration global_registration[NR_EVENTS]
Definition: plugin.h:103
#define CFAPI_FLOAT
Definition: plugin.h:67
void map_newmap_cmd(socket_struct *ns)
Definition: request.c:618
struct _crossfire_plugin * next
Definition: plugin.h:104
const Face * try_find_face(const char *name, const Face *error)
Definition: assets.cpp:281
void object_set_owner(object *op, object *owner)
Definition: object.c:604
#define CFAPI_PLAYER_PROP_BED_X
Definition: plugin.h:238
char * name
Definition: map.h:329
#define CFAPI_PARCH
Definition: plugin.h:69
static void cfapi_object_identify(int *type,...)
Definition: plugins.c:3000
int object_set_value(object *op, const char *key, const char *value, int add_key)
Definition: object.c:4259
void object_free_drop_inventory(object *ob)
Definition: object.c:1316
int change_abil(object *op, object *tmp)
Definition: living.c:395
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.c:1849
#define CFAPI_MAP_PROP_PLAYERS
Definition: plugin.h:255
int move_to(object *op, int x, int y)
Definition: move.c:551
int is_friendly(const object *op)
Definition: friend.c:144
sstring find_string(const char *str)
Definition: shstr.c:236
char * name
Definition: map.h:279
#define CFAPI_OBJECT_PROP_FACING
Definition: plugin.h:148
#define MSG_TYPE_COMMAND
Definition: newclient.h:379
static void cfapi_object_say(int *type,...)
Definition: plugins.c:3898
static void cfapi_system_remove_string(int *type,...)
Definition: plugins.c:674
static void cfapi_object_change_exp(int *type,...)
Definition: plugins.c:3987
#define CFAPI_PLAYER_PROP_IP
Definition: plugin.h:234
#define CFAPI_OBJECT_PROP_ENVIRONMENT
Definition: plugin.h:129
Definition: win32.h:120
static void cfapi_object_merge(int *type,...)
Definition: plugins.c:3389
#define CFAPI_OBJECT_PROP_GP
Definition: plugin.h:212
LIBPTRTYPE libptr
Definition: plugin.h:100
#define CFAPI_OBJECT_PROP_CHA
Definition: plugin.h:207
#define CFAPI_PARTY_PROP_PLAYER
Definition: plugin.h:276
object * object_new(void)
Definition: object.c:1011
static void cfapi_player_knowledge(int *type,...)
Definition: plugins.c:4029
#define LIBDIR
Definition: win32.h:99
#define CFAPI_OBJECT_PROP_ATTACKED_BY
Definition: plugin.h:177
#define CFAPI_STRING
Definition: plugin.h:64
void player_set_own_title(struct pl *pl, const char *title)
Definition: player.c:264
int object_can_pick(const object *who, const object *item)
Definition: object.c:3657
object * object_insert_in_ob(object *op, object *where)
Definition: object.c:2602
#define CFAPI_OBJECT_PROP_MOVE_SLOW_PENALTY
Definition: plugin.h:230
#define CFAPI_MAP_PROP_UNIQUE
Definition: plugin.h:265
int knowledge_player_knows(const player *pl, const char *knowledge)
Definition: knowledge.c:1323
void *(* f_plug_property)(int *type,...)
Definition: plugin.h:87
#define CFAPI_OBJECT_PROP_INT
Definition: plugin.h:205
signed short int16_t
Definition: win32.h:160
#define CFAPI_MAP_PROP_RESET_TIME
Definition: plugin.h:253
#define CFAPI_ARCH_PROP_HEAD
Definition: plugin.h:269
void monster_npc_say(object *npc, const char *cp)
Definition: monster.c:2307
static void cfapi_timer_destroy(int *type,...)
Definition: plugins.c:920
int16_t enter_x
Definition: map.h:349
uint32_t unique
Definition: map.h:338
#define CFAPI_OBJECT_PROP_LEVEL
Definition: plugin.h:161
#define FOR_ABOVE_FINISH()
Definition: define.h:731
void update_all_los(const mapstruct *map, int x, int y)
Definition: los.c:536
const char * tmpdir
Definition: global.h:254
#define CFAPI_OBJECT_PROP_HEAD
Definition: plugin.h:130
#define CFAPI_PLAYER_PROP_BED_MAP
Definition: plugin.h:237
#define CFAPI_OBJECT_PROP_MOVE_ALLOW
Definition: plugin.h:226
static void cfapi_player_message(int *type,...)
Definition: plugins.c:3942
struct regiondef * next
Definition: map.h:278
Definition: map.h:277
#define CFAPI_OBJECT_PROP_RAW_NAME
Definition: plugin.h:232
#define snprintf
Definition: win32.h:46
void drain_specific_stat(object *op, int deplete_stats)
Definition: living.c:729
static void cfapi_object_user_event(int *type,...)
Definition: plugins.c:4396
#define CFAPI_ARCH_PROP_NEXT
Definition: plugin.h:268
f_plug_postinit closefunc
Definition: plugin.h:99
#define PERM_EXP(exptotal)
Definition: global.h:230
struct linked_char * next
Definition: global.h:88
int plugins_init_plugin(const char *libfile)
Definition: plugins.c:356
uint16_t num
Definition: face.h:29
uint64_t query_money(const object *op)
Definition: shop.c:475
int(* f_plug_postinit)(void)
Definition: plugin.h:83
#define FOR_INV_FINISH()
Definition: define.h:714
char * msg
Definition: map.h:362
void update_position(mapstruct *m, int x, int y)
Definition: map.c:2142
void add_friendly_object(object *op)
Definition: friend.c:30
#define CFAPI_OBJECT_PROP_FP
Definition: plugin.h:213
#define FOR_ABOVE_PREPARE(op_, it_)
Definition: define.h:724
#define CFAPI_OBJECT_PROP_MAGICAL
Definition: plugin.h:192
static void cfapi_map_find_by_archetype_name(int *type,...)
Definition: plugins.c:1330
#define LIBPTRTYPE
Definition: plugin.h:90
static void cfapi_object_pay_item(int *type,...)
Definition: plugins.c:3701
#define CFAPI_OBJECT_PROP_LAST_EAT
Definition: plugin.h:165
object * object_present_in_ob(uint8_t type, const object *op)
Definition: object.c:2900
void trigger_connected(objectlink *ol, object *cause, const int state)
Definition: button.c:41
const char * re_cmp(const char *, const char *)
Definition: re-cmp.c:69
void object_reset(object *op)
Definition: object.c:698
int pay_for_amount(uint64_t to_pay, object *pl)
Definition: shop.c:506
#define CFAPI_OBJECT_PROP_MOVE_OFF
Definition: plugin.h:228
#define CFAPI_OBJECT_PROP_WEIGHT_LIMIT
Definition: plugin.h:171
#define CFAPI_PLAYER_QUEST_SET_STATE
Definition: plugin.h:245
#define CFAPI_LONG
Definition: plugin.h:62
object * object_create_clone(object *asrc)
Definition: object.c:3699
#define string_get_int(name)
Definition: plugins.c:817
#define CFAPI_OBJECT_PROP_CURRENT_WEAPON
Definition: plugin.h:175
#define CFAPI_SSTRING
Definition: plugin.h:77
static void cfapi_player_can_pay(int *type,...)
Definition: plugins.c:4010
static void cfapi_system_check_path(int *type,...)
Definition: plugins.c:711
#define CFAPI_PPLAYER
Definition: plugin.h:71
#define SIZEOFFREE
Definition: define.h:154
#define P_OUT_OF_MAP
Definition: map.h:252
int move_ob(object *op, int dir, object *originator)
Definition: move.c:58
int cftimer_destroy(int id)
Definition: timers.c:128
#define CFAPI_OBJECT_PROP_X
Definition: plugin.h:142
void do_learn_spell(object *op, object *spell, int special_prayer)
Definition: apply.c:484
static void cfapi_map_out_of_map(int *type,...)
Definition: plugins.c:1228
#define CFAPI_OBJECT_PROP_CHEATER
Definition: plugin.h:197
static void cfapi_object_get_key(int *type,...)
Definition: plugins.c:1438
int pay_for_item(object *op, object *pl, uint64_t reduction)
Definition: shop.c:546
#define CFAPI_OBJECT_PROP_PICKABLE
Definition: plugin.h:199
static void cfapi_system_directory(int *type,...)
Definition: plugins.c:752
void cleanupPlugins(void)
Definition: plugins.c:4558
uint8_t ignore_plugin_compatibility
Definition: global.h:327
archetype * get_next_archetype(archetype *current)
Definition: assets.cpp:249
uint8_t darkness
Definition: map.h:347
#define CFAPI_MAP_PROP_MESSAGE
Definition: plugin.h:262
void object_clear(object *op)
Definition: object.c:747
command_array_struct * find_plugin_command(const char *cmd, command_array_struct *command)
Definition: plugins.c:4487
static crossfire_plugin * plugins_find_plugin(const char *id)
Definition: plugins.c:248
#define CFAPI_OBJECT_PROP_ENEMY
Definition: plugin.h:176
#define CFAPI_REGION_PROP_JAIL_Y
Definition: plugin.h:284
object * find_marked_object(object *op)
Definition: c_object.c:1509
#define CFAPI_OBJECT_PROP_PATH_REPELLED
Definition: plugin.h:155
void plugins_display_list(object *op)
Definition: plugins.c:496
static void cfapi_object_learn_spell(int *type,...)
Definition: plugins.c:3625
uint16_t number
Definition: face.h:15
#define UPD_WEIGHT
Definition: newclient.h:291
char d_name[_MAX_FNAME+1]
Definition: win32.h:114
static void cfapi_object_create(int *type,...)
Definition: plugins.c:3209
#define CFAPI_MAP_PROP_TMPNAME
Definition: plugin.h:251
unsigned __int64 uint64_t
Definition: win32.h:167
char fullname[MAX_BUF]
Definition: plugin.h:102
struct regiondef * parent
Definition: map.h:287
int on_same_map(const object *op1, const object *op2)
Definition: map.c:2666
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
f_plug_property propfunc
Definition: plugin.h:98
#define CLEAR_FLAG(xyz, p)
Definition: define.h:224
#define CFAPI_OBJECT_PROP_LORE
Definition: plugin.h:141
static void cfapi_player_find(int *type,...)
Definition: plugins.c:3927
partylist * party_get_first(void)
Definition: party.c:196
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Definition: living.c:2166
#define CFAPI_OBJECT_PROP_ITEM_POWER
Definition: plugin.h:168
#define CFAPI_REGION_PROP_LONGNAME
Definition: plugin.h:281
#define MSG_TYPE_COMMAND_DEBUG
Definition: newclient.h:508
static void cfapi_object_apply(int *type,...)
Definition: plugins.c:2975
static void cfapi_system_unregister_global_event(int *type,...)
Definition: plugins.c:628
#define MAX_BUF
Definition: define.h:35
int quest_get_player_state(player *pl, sstring quest_code)
Definition: quest.c:1068
#define CFAPI_PARTY_PROP_NAME
Definition: plugin.h:273
#define CFAPI_PLAYER_PROP_PARTY
Definition: plugin.h:236
LogLevel
Definition: logger.h:10
int16_t jailx
Definition: map.h:299
int16_t enter_y
Definition: map.h:349
void drop(object *op, object *tmp)
Definition: c_object.c:1156
#define CFAPI_OBJECT_PROP_EXP
Definition: plugin.h:194
static void cfapi_object_describe(int *type,...)
Definition: plugins.c:3020
#define plugins_dlerror()
Definition: plugin.h:119
const char * confdir
Definition: global.h:244
int object_find_first_free_spot(const object *ob, mapstruct *m, int x, int y)
Definition: object.c:3331
signed __int64 int64_t
Definition: win32.h:168
#define CFAPI_OBJECT_PROP_TOTAL_EXP
Definition: plugin.h:174
static const flag_definition flags[]
static void cfapi_system_strdup_local(int *type,...)
Definition: plugins.c:593
object * object_create_arch(archetype *at)
Definition: arch.cpp:301
const char * uniquedir
Definition: global.h:252
char * tmpname
Definition: map.h:328
object * ob
Definition: player.h:158
const char * sstring
Definition: global.h:40
#define CFAPI_OBJECT_PROP_DAM
Definition: plugin.h:217
unsigned int uint32_t
Definition: win32.h:162
#define CFAPI_OBJECT_PROP_MOVE_TYPE
Definition: plugin.h:224
const char * datadir
Definition: global.h:245
#define CFAPI_OBJECT_PROP_SKILL
Definition: plugin.h:139
#define CFAPI_PLAYER_PROP_NEXT
Definition: plugin.h:240
#define CFAPI_OBJECT_PROP_AC
Definition: plugin.h:209
static void cfapi_object_check_trigger(int *type,...)
Definition: plugins.c:3531
#define SET_MAP_FLAGS(M, X, Y, C)
Definition: map.h:164
#define CFAPI_OBJECT_PROP_BASE_NAME
Definition: plugin.h:191
#define TIMER_ERR_NONE
Definition: timers.h:66
const char * name
Definition: global.h:87
#define CFAPI_REGION_PROP_PARENT
Definition: plugin.h:280
#define CFAPI_INT
Definition: plugin.h:61
static void cfapi_friendlylist_get_next(int *type,...)
Definition: plugins.c:4315
object * object_split(object *orig_ob, uint32_t nr, char *err, size_t size)
Definition: object.c:2382
#define CFAPI_ARCH_PROP_NAME
Definition: plugin.h:267
StringBuffer * describe_item(const object *op, const object *owner, int use_media_tags, StringBuffer *buf)
Definition: item.c:935
void quest_set_player_state(player *pl, sstring quest_code, int state)
Definition: quest.c:1124
object * object_decrease_nrof(object *op, uint32_t i)
Definition: object.c:2421
static void cfapi_object_perm_exp(int *type,...)
Definition: plugins.c:3968
int set_random_map_variable(RMParms *rp, const char *buf)
#define CFAPI_OBJECT_PROP_SPEED_LEFT
Definition: plugin.h:145
#define FREE_AND_COPY(sv, nv)
Definition: global.h:204
#define UPD_NROF
Definition: newclient.h:296
int(* f_plug_event)(int *type,...)
Definition: events.h:60
void get_tod(timeofday_t *tod)
Definition: time.c:215
static void cfapi_object_query_money(int *type,...)
Definition: plugins.c:3578
int cftimer_create(int id, long delay, object *ob, int mode)
Definition: timers.c:97
const char * localdir
Definition: global.h:246
Animations * try_find_animation(const char *name)
Definition: assets.cpp:269
static void cfapi_map_has_been_loaded(int *type,...)
Definition: plugins.c:1014
mapstruct * has_been_loaded(const char *name)
Definition: map.c:88
char * jailmap
Definition: map.h:298
#define CFAPI_OBJECT_PROP_HP
Definition: plugin.h:210
static void cfapi_object_cast(int *type,...)
Definition: plugins.c:3597
#define CFAPI_OBJECT_PROP_TITLE
Definition: plugin.h:136
int cftimer_find_free_id(void)
Definition: timers.c:144
const char * mapdir
Definition: global.h:248
uint32_t reset_timeout
Definition: map.h:334
#define CFAPI_PLAYER_PROP_BED_Y
Definition: plugin.h:239
uint16_t width
Definition: map.h:348
#define CFAPI_OBJECT_PROP_SPEED
Definition: plugin.h:144
Definition: tod.h:34
struct Settings settings
Definition: init.c:39
#define CFAPI_MAP_PROP_PATH
Definition: plugin.h:250
static void cfapi_get_hooks(int *type,...)
Definition: plugins.c:310
void object_set_enemy(object *op, object *enemy)
Definition: object.c:679
int remove_depletion(object *op, int level)
Definition: living.c:756
#define CFAPI_OBJECT_PROP_FRIENDLY
Definition: plugin.h:189
#define CFAPI_OBJECT_PROP_ANIM_SPEED
Definition: plugin.h:188
#define CFAPI_OBJECT_PROP_LUCK
Definition: plugin.h:193
void party_join(object *op, partylist *party)
Definition: party.c:85
struct dirent * readdir(DIR *)
Definition: win32.c:75
const char * get_periodofday(const int index)
Definition: time.c:102
object * object_merge(object *op, object *top)
Definition: object.c:1800
#define CFAPI_OBJECT_PROP_ARCH_NAME
Definition: plugin.h:219
void query_short_name(const object *op, char *buf, size_t size)
Definition: item.c:508
object * object_get_player_container(object *op)
Definition: object.c:377
static void cfapi_system_add_string(int *type,...)
Definition: plugins.c:654
int out_of_map(mapstruct *m, int x, int y)
Definition: map.c:2321
#define CFAPI_OBJECT_PROP_INVISIBLE_TIME
Definition: plugin.h:166
static void cfapi_get_time(int *type,...)
Definition: plugins.c:805
static void cfapi_map_get_object_at(int *type,...)
Definition: plugins.c:1301
#define CFAPI_OBJECT_PROP_DEX
Definition: plugin.h:202
#define CFAPI_MOVETYPE
Definition: plugin.h:78
#define CFAPI_OBJECT_PROP_ATTACK_MOVEMENT
Definition: plugin.h:182
#define CFAPI_MAP_PROP_REGION
Definition: plugin.h:264
static void cfapi_object_change_abil(int *type,...)
Definition: plugins.c:3883
void delete_map(mapstruct *m)
Definition: map.c:1735
void events_unregister_global_handler(int eventcode, event_registration id)
Definition: events.cpp:23
#define CFAPI_MAP_PROP_WIDTH
Definition: plugin.h:258
#define CFAPI_OBJECT_PROP_CON
Definition: plugin.h:203
sstring add_string(const char *str)
Definition: shstr.c:124
#define CFAPI_PLAYER_QUEST_WAS_COMPLETED
Definition: plugin.h:246
EXTERN player * first_player
Definition: global.h:115
char * cost_string_from_value(uint64_t cost, int largest_coin)
Definition: shop.c:327
#define CFAPI_PARTY_PROP_NEXT
Definition: plugin.h:274
object * identify(object *op)
Definition: item.c:1386
struct pl * next
Definition: player.h:93
static void cfapi_object_clean_object(int *type,...)
Definition: plugins.c:3485
archetype * find_archetype_by_object_name(const char *name)
Definition: arch.cpp:55
#define GET_MAP_OB(M, X, Y)
Definition: map.h:173
int check_path(const char *name, int prepend_dir)
Definition: map.c:212
#define CFAPI_OBJECT_PROP_NROF
Definition: plugin.h:146
#define CFAPI_OBJECT_PROP_MAXSP
Definition: plugin.h:215
void object_copy(const object *src_ob, object *dest_ob)
Definition: object.c:824
#define CFAPI_ARCH_PROP_CLONE
Definition: plugin.h:271
struct _crossfire_plugin * prev
Definition: plugin.h:105
static void cfapi_object_transfer(int *type,...)
Definition: plugins.c:3725
static void cfapi_object_remove_depletion(int *type,...)
Definition: plugins.c:3060
int closedir(DIR *)
Definition: win32.c:108
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
Definition: map.c:311
void object_set_cheat(object *op)
Definition: object.c:3006
#define NDI_UNIQUE
Definition: newclient.h:245
#define CFAPI_PLAYER_PROP_MARKED_ITEM
Definition: plugin.h:235
static void cfapi_map_get_map(int *type,...)
Definition: plugins.c:963
#define MSG_SUBTYPE_NONE
Definition: newclient.h:398
static void cfapi_object_distance(int *type,...)
Definition: plugins.c:3412
#define CFAPI_OBJECT_PROP_LAST_HEAL
Definition: plugin.h:162
#define CFAPI_OBJECT_PROP_CLIENT_TYPE
Definition: plugin.h:151
#define CFAPI_OBJECT_PROP_INVISIBLE
Definition: plugin.h:220
void player_update_bg_music(object *player)
void events_unregister_object_handler(const char *id)
Definition: events.cpp:254
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
#define CFAPI_OBJECT_PROP_TYPE
Definition: plugin.h:149
event_registration events_register_global_handler(int eventcode, f_plug_event hook)
Definition: events.cpp:16
static const hook_entry plug_hooks[]
Definition: plugins.c:141
char * msg
Definition: map.h:294
static void cfapi_object_forget_spell(int *type,...)
Definition: plugins.c:3640
#define CFAPI_OBJECT_PROP_POW
Definition: plugin.h:206
static void cfapi_get_weekday_name(int *type,...)
Definition: plugins.c:848
static void cfapi_map_message(int *type,...)
Definition: plugins.c:1279
static void cfapi_object_update(int *type,...)
Definition: plugins.c:3433
#define FLAG_WAS_WIZ
Definition: define.h:234
EXTERN region * first_region
Definition: global.h:117
#define CFAPI_OBJECT_PROP_GEN_SP_ARMOUR
Definition: plugin.h:169
int transfer_ob(object *op, int x, int y, int randomly, object *originator)
Definition: move.c:150
#define CFAPI_OBJECT_PROP_GLOW_RADIUS
Definition: plugin.h:173
struct mapdef * next
Definition: map.h:327
static void cfapi_object_clone(int *type,...)
Definition: plugins.c:3177
static void cfapi_object_reset(int *type,...)
Definition: plugins.c:3471
void object_set_msg(object *op, const char *msg)
Definition: object.c:4570
int events_execute_object_user(object *op, object *activator, object *third, const char *message, int fix)
Definition: events.cpp:267
int object_find_free_spot(const object *ob, mapstruct *m, int x, int y, int start, int stop)
Definition: object.c:3291
int check_trigger(object *op, object *cause)
Definition: button.c:518
#define CFAPI_OBJECT_PROP_PRESENT
Definition: plugin.h:196
#define CFAPI_OBJECT_PROP_MERGEABLE
Definition: plugin.h:198
#define CFAPI_OBJECT_PROP_WC
Definition: plugin.h:208
void query_name(const object *op, char *buf, size_t size)
Definition: item.c:583
#define CFAPI_OBJECT_PROP_RESIST
Definition: plugin.h:152
#define CFAPI_OBJECT_PROP_SHORT_NAME
Definition: plugin.h:190
#define CFAPI_OBJECT_PROP_MOVE_SLOW
Definition: plugin.h:229
#define CFAPI_OBJECT_PROP_MATERIAL_NAME
Definition: plugin.h:158
void create_overlay_pathname(const char *name, char *buf, size_t size)
Definition: map.c:134
object * map_find_by_archetype(mapstruct *m, int x, int y, const archetype *at)
Definition: object.c:2850
Definition: map.h:326
#define CFAPI_OBJECT_PROP_MAXHP
Definition: plugin.h:214
int can_pay(object *pl)
Definition: shop.c:835
#define CFAPI_OBJECT_PROP_VALUE
Definition: plugin.h:160
static void cfapi_cost_string_from_value(int *type,...)
Definition: plugins.c:519
void ext_info_map(int color, const mapstruct *map, uint8_t type, uint8_t subtype, const char *str1)
Definition: main.c:323
#define CFAPI_OBJECT_PROP_SPELL_ITEM
Definition: plugin.h:183
#define CFAPI_OBJECT_PROP_PATH_ATTUNED
Definition: plugin.h:154
int(* f_plug_init)(const char *iversion, f_plug_api gethooksptr)
Definition: plugin.h:85
void fix_object(object *op)
Definition: living.c:1124
static void send_changed_object(object *op)
Definition: plugins.c:284
player * find_player_partial_name(const char *plname)
Definition: player.c:110
#define CFAPI_OBJECT_PROP_WIS
Definition: plugin.h:204
EXTERN mapstruct * first_map
Definition: global.h:116
int quest_was_completed(player *pl, sstring quest_code)
Definition: quest.c:1134
#define CFAPI_OBJECT_PROP_DURATION
Definition: plugin.h:231
char * longname
Definition: map.h:292
void object_update_speed(object *op)
Definition: object.c:1086
#define CFAPI_MAP_PROP_ENTER_X
Definition: plugin.h:260
void clean_object(object *op)
Definition: map.c:1626
object * object_get_owner(object *op)
Definition: object.c:568
#define CFAPI_OBJECT_PROP_OB_ABOVE
Definition: plugin.h:124
#define CFAPI_OBJECT_PROP_Y
Definition: plugin.h:143
#define CFAPI_OBJECT_PROP_CUSTOM_NAME
Definition: plugin.h:187
int level
Definition: readable.c:1589
char * stringbuffer_finish(StringBuffer *sb)
Definition: stringbuffer.c:76
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: porting.c:370
int plugins_remove_plugin(const char *id)
Definition: plugins.c:447
void(* f_plug_api)(int *type,...)
Definition: plugin.h:81
object * object_find_by_arch_name(const object *who, const char *name)
Definition: object.c:4042
object * object_present_in_ob_by_name(int type, const char *str, const object *op)
Definition: object.c:2935
#define CFAPI_OBJECT_PROP_PREV_ACTIVE_OB
Definition: plugin.h:127
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:707
int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg)
Definition: spell_util.c:1459
void object_remove(object *op)
Definition: object.c:1588
static void cfapi_generate_random_map(int *type,...)
Definition: plugins.c:4379
#define CFAPI_OBJECT_PROP_PATH_DENIED
Definition: plugin.h:156
static void cfapi_map_update_position(int *type,...)
Definition: plugins.c:1250
#define CFAPI_OBJECT_PROP_MOVE_BLOCK
Definition: plugin.h:225
#define CFAPI_REGION_PROP_NAME
Definition: plugin.h:278
#define CFAPI_PPARTY
Definition: plugin.h:72
const Face * get_face_by_id(uint16_t id)
Definition: assets.cpp:314
static void cfapi_map_change_light(int *type,...)
Definition: plugins.c:1357
#define FLAG_FREED
Definition: define.h:233