Crossfire Server, Trunk  R21017
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 
140 static const hook_entry plug_hooks[] = {
141  { cfapi_system_add_string, 0, "cfapi_system_add_string" },
142  { cfapi_system_register_global_event, 1, "cfapi_system_register_global_event" },
143  { cfapi_system_remove_string, 2, "cfapi_system_remove_string" },
144  { cfapi_system_unregister_global_event, 3, "cfapi_system_unregister_global_event" },
145  { cfapi_system_check_path, 4, "cfapi_system_check_path" },
146  { cfapi_system_re_cmp, 5, "cfapi_system_re_cmp" },
147  { cfapi_system_strdup_local, 6, "cfapi_system_strdup_local" },
148  { cfapi_system_directory, 7, "cfapi_system_directory" },
149  { cfapi_system_find_animation, 8, "cfapi_system_find_animation" },
150  { cfapi_object_clean_object, 9, "cfapi_object_clean_object" },
151  { cfapi_object_on_same_map, 10, "cfapi_object_on_same_map" },
152  { cfapi_object_get_key, 11, "cfapi_object_get_key" },
153  { cfapi_object_set_key, 12, "cfapi_object_set_key" },
154  { cfapi_object_get_property, 13, "cfapi_object_get_property" },
155  { cfapi_object_set_property, 14, "cfapi_object_set_property" },
156  { cfapi_object_apply, 15, "cfapi_object_apply" },
157  { cfapi_object_identify, 16, "cfapi_object_identify" },
158  { cfapi_object_describe, 17, "cfapi_object_describe" },
159  { cfapi_object_drain, 18, "cfapi_object_drain" },
160  { cfapi_object_fix, 19, "cfapi_object_fix" },
161  { cfapi_object_give_skill, 20, "cfapi_object_give_skill" },
162  { cfapi_object_transmute, 21, "cfapi_object_transmute" },
163  { cfapi_object_remove, 22, "cfapi_object_remove" },
164  { cfapi_object_delete, 23, "cfapi_object_delete" },
165  { cfapi_object_clone, 24, "cfapi_object_clone" },
166  { cfapi_object_create, 26, "cfapi_object_create" },
167  { cfapi_object_insert, 27, "cfapi_object_insert" },
168  { cfapi_object_split, 28, "cfapi_object_split" },
169  { cfapi_object_merge, 29, "cfapi_object_merge" },
170  { cfapi_object_distance, 30, "cfapi_object_distance" },
171  { cfapi_object_update, 31, "cfapi_object_update" },
172  { cfapi_object_clear, 32, "cfapi_object_clear" },
173  { cfapi_object_reset, 33, "cfapi_object_reset" },
174  { cfapi_object_spring_trap, 35, "cfapi_object_spring_trap" },
175  { cfapi_object_check_trigger, 36, "cfapi_object_check_trigger" },
176  { cfapi_object_query_money, 38, "cfapi_object_query_money" },
177  { cfapi_object_cast, 39, "cfapi_object_cast" },
178  { cfapi_object_learn_spell, 40, "cfapi_object_learn_spell" },
179  { cfapi_object_forget_spell, 41, "cfapi_object_forget_spell" },
180  { cfapi_object_check_spell, 42, "cfapi_object_check_spell" },
181  { cfapi_object_pay_amount, 43, "cfapi_object_pay_amount" },
182  { cfapi_object_pay_item, 44, "cfapi_object_pay_item" },
183  { cfapi_object_transfer, 45, "cfapi_object_transfer" },
184  { cfapi_object_drop, 46, "cfapi_object_drop" },
185  { cfapi_object_change_abil, 47, "cfapi_object_change_abil" },
186  { cfapi_object_find_archetype_inside, 48, "cfapi_object_find_archetype_inside" },
187  { cfapi_object_say, 49, "cfapi_object_say" },
188  { cfapi_map_get_map, 50, "cfapi_map_get_map" },
189  { cfapi_map_has_been_loaded, 51, "cfapi_map_has_been_loaded" },
190  { cfapi_map_create_path, 52, "cfapi_map_create_path" },
191  { cfapi_map_get_map_property, 53, "cfapi_map_get_property" },
192  { cfapi_map_set_map_property, 54, "cfapi_map_set_property" },
193  { cfapi_map_out_of_map, 55, "cfapi_map_out_of_map" },
194  { cfapi_map_update_position, 56, "cfapi_map_update_position" },
195  { cfapi_map_delete_map, 57, "cfapi_map_delete_map" },
196  { cfapi_map_message, 58, "cfapi_map_message" },
197  { cfapi_map_get_object_at, 59, "cfapi_map_get_object_at" },
198  { cfapi_map_change_light, 60, "cfapi_map_change_light" },
199  { cfapi_map_find_by_archetype_name, 61, "cfapi_map_find_by_archetype_name" },
200  { cfapi_player_find, 62, "cfapi_player_find" },
201  { cfapi_player_message, 63, "cfapi_player_message" },
202  { cfapi_object_change_exp, 64, "cfapi_object_change_exp" },
203  { cfapi_object_teleport, 65, "cfapi_object_teleport" },
204  { cfapi_object_pickup, 67, "cfapi_object_pickup" },
205  { cfapi_object_move, 68, "cfapi_object_move" },
206  { cfapi_object_apply_below, 69, "cfapi_object_apply_below" },
207  { cfapi_generate_random_map, 70, "cfapi_generate_random_map" },
208  { cfapi_archetype_get_property, 71, "cfapi_archetype_get_property" },
209  { cfapi_party_get_property, 72, "cfapi_party_get_property" },
210  { cfapi_region_get_property, 73, "cfapi_region_get_property" },
211  { cfapi_player_can_pay, 74, "cfapi_player_can_pay" },
212  { cfapi_log, 75, "cfapi_log" },
213  { cfapi_get_time, 76, "cfapi_system_get_time" },
214  { cfapi_timer_create, 77, "cfapi_system_timer_create" },
215  { cfapi_timer_destroy, 78, "cfapi_system_timer_destroy" },
216  { cfapi_friendlylist_get_next, 79, "cfapi_friendlylist_get_next" },
217  { cfapi_set_random_map_variable, 80, "cfapi_set_random_map_variable" },
218  { cfapi_system_find_face, 81, "cfapi_system_find_face" },
219  { cfapi_get_season_name, 82, "cfapi_system_get_season_name" },
220  { cfapi_get_month_name, 83, "cfapi_system_get_month_name" },
221  { cfapi_get_weekday_name, 84, "cfapi_system_get_weekday_name" },
222  { cfapi_get_periodofday_name, 85, "cfapi_system_get_periodofday_name" },
223  { cfapi_map_trigger_connected, 86, "cfapi_map_trigger_connected" },
224  { cfapi_object_user_event, 87, "cfapi_object_user_event" },
225  { cfapi_system_find_string, 88, "cfapi_system_find_string" },
226  { cfapi_cost_string_from_value, 90, "cfapi_cost_string_from_value" },
227  { cfapi_player_quest, 91, "cfapi_player_quest" },
228  { cfapi_object_remove_depletion, 92, "cfapi_object_remove_depletion" },
229  { cfapi_object_find_by_arch_name, 93, "cfapi_object_find_by_arch_name" },
230  { cfapi_object_find_by_name, 94, "cfapi_object_find_by_name" },
231  { cfapi_player_knowledge, 95, "cfapi_player_knowledge" }
232 };
233 
236 
237 /*****************************************************************************/
238 /* NEW PLUGIN STUFF STARTS HERE */
239 /*****************************************************************************/
240 
246 static crossfire_plugin *plugins_find_plugin(const char *id) {
247  crossfire_plugin *cp;
248 
249  if (plugins_list == NULL)
250  return NULL;
251 
252  for (cp = plugins_list; cp != NULL; cp = cp->next) {
253  if (!strcmp(id, cp->id)) {
254  return cp;
255  }
256  }
257  return NULL;
258 }
259 
260 #ifdef WIN32
261 static const char *plugins_dlerror(void) {
262  static char buf[256];
263  DWORD err;
264  char *p;
265 
266  err = GetLastError();
267  if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, buf, sizeof(buf), NULL) == 0)
268  snprintf(buf, sizeof(buf), "error %lu", err);
269  p = strchr(buf, '\0');
270  while (p > buf && (p[-1] == '\r' || p[-1] == '\n'))
271  p--;
272  *p = '\0';
273  return buf;
274 }
275 #endif /* WIN32 */
276 
282 static void send_changed_object(object *op) {
283  object *tmp;
284  player *pl;
285 
286  if (op->env != NULL) {
287  tmp = object_get_player_container(op->env);
288  if (!tmp) {
289  for (pl = first_player; pl; pl = pl->next)
290  if (pl->ob->container == op->env)
291  break;
292  if (pl)
293  tmp = pl->ob;
294  else
295  tmp = NULL;
296  }
297  if (tmp)
298  /* We don't know what changed, so we send everything. */
299  esrv_update_item(UPD_ALL, tmp, op);
300  } else {
301  FOR_ABOVE_PREPARE(op, tmp)
302  if (tmp->type == PLAYER)
303  tmp->contr->socket.update_look = 1;
305  }
306 }
307 
308 int user_event(object *op, object *activator, object *third, const char *message, int fix) {
309  return execute_event(op, EVENT_USER, activator, third, message, fix);
310 }
311 
312 static int do_execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix, talk_info *talk) {
313  crossfire_plugin *plugin;
314  int rv = 0;
315 
316  FOR_INV_PREPARE(op, tmp) {
317  if (tmp->type == EVENT_CONNECTOR && tmp->subtype == eventcode) {
318 #ifdef PLUGIN_DEBUG
319  LOG(llevDebug, "********** EVENT HANDLER **********\n");
320  LOG(llevDebug, " - Who am I :%s\n", op->name);
321  if (activator != NULL)
322  LOG(llevDebug, " - Activator :%s\n", activator->name);
323  if (third != NULL)
324  LOG(llevDebug, " - Other object :%s\n", third->name);
325  LOG(llevDebug, " - Event code :%d\n", tmp->subtype);
326  if (tmp->title != NULL)
327  LOG(llevDebug, " - Event plugin :%s\n", tmp->title);
328  if (tmp->slaying != NULL)
329  LOG(llevDebug, " - Event hook :%s\n", tmp->slaying);
330  if (tmp->name != NULL)
331  LOG(llevDebug, " - Event options :%s\n", tmp->name);
332 #endif
333 
334  if (tmp->title == NULL) {
335  object *env = object_get_env_recursive(tmp);
336  LOG(llevError, "Event object without title at %d/%d in map %s\n", env->x, env->y, env->map->name);
337  object_remove(tmp);
339  } else if (tmp->slaying == NULL) {
340  object *env = object_get_env_recursive(tmp);
341  LOG(llevError, "Event object without slaying at %d/%d in map %s\n", env->x, env->y, env->map->name);
342  object_remove(tmp);
344  } else {
345  plugin = plugins_find_plugin(tmp->title);
346  if (plugin == NULL) {
347  object *env = object_get_env_recursive(tmp);
348  LOG(llevError, "The requested plugin doesn't exist: %s at %d/%d in map %s\n", tmp->title, env->x, env->y, env->map->name);
349  object_remove(tmp);
351  } else {
352  int rvt = 0;
353  int rv;
354 
355  tag_t oldtag = op->count;
356  rv = plugin->eventfunc(&rvt, op, activator, third, message, fix, tmp, talk);
357  if (object_was_destroyed(op, oldtag)) {
358  return rv;
359  }
360  if (QUERY_FLAG(tmp, FLAG_UNIQUE)) {
361 #ifdef PLUGIN_DEBUG
362  LOG(llevDebug, "Removing unique event %s\n", tmp->slaying);
363 #endif
364  object_remove(tmp);
366  }
367  return rv;
368  }
369  }
370  }
371  } FOR_INV_FINISH();
372  return rv;
373 }
374 
375 int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix) {
376  return do_execute_event(op, eventcode, activator, third, message, fix, NULL);
377 }
378 
379 int plugin_event_say(object *npc, talk_info *talk) {
380  return do_execute_event(npc, EVENT_SAY, talk->who, NULL, talk->text, SCRIPT_FIX_ALL, talk);
381 }
382 
383 int execute_global_event(int eventcode, ...) {
384  va_list args;
385  mapstruct *map;
386  object *op;
387  object *op2;
388  player *pl;
389  const char *buf;
390  int i, rt;
391  crossfire_plugin *cp;
392 
393  if (plugins_list == NULL)
394  return -1;
395 
396  va_start(args, eventcode);
397 
398  switch (eventcode) {
399  case EVENT_BORN:
400  /*BORN: op*/
401  op = va_arg(args, object *);
402  for (cp = plugins_list; cp != NULL; cp = cp->next) {
403  if (cp->gevent[eventcode] != NULL)
404  cp->gevent[eventcode](&rt, eventcode, op);
405  }
406  break;
407 
408  case EVENT_CLOCK:
409  /*CLOCK: -*/
410  for (cp = plugins_list; cp != NULL; cp = cp->next) {
411  if (cp->gevent[eventcode] != NULL)
412  cp->gevent[eventcode](&rt, eventcode);
413  }
414  break;
415 
416  case EVENT_CRASH:
417  for (cp = plugins_list; cp != NULL; cp = cp->next) {
418  if (cp->gevent[eventcode] != NULL)
419  cp->gevent[eventcode](&rt, eventcode);
420  }
421  break;
422 
423  case EVENT_PLAYER_DEATH:
424  /*PLAYER_DEATH: op*/
425  op = va_arg(args, object *);
426  op2 = va_arg(args, object *);
427  for (cp = plugins_list; cp != NULL; cp = cp->next) {
428  if (cp->gevent[eventcode] != NULL)
429  cp->gevent[eventcode](&rt, eventcode, op, op2);
430  }
431  break;
432 
433  case EVENT_GKILL:
434  /*GKILL: op, hitter*/
435  op = va_arg(args, object *);
436  op2 = va_arg(args, object *);
437  for (cp = plugins_list; cp != NULL; cp = cp->next) {
438  if (cp->gevent[eventcode] != NULL)
439  cp->gevent[eventcode](&rt, eventcode, op, op2);
440  }
441  break;
442 
443  case EVENT_LOGIN:
444  /*LOGIN: pl, pl->socket.host*/
445  pl = va_arg(args, player *);
446  buf = va_arg(args, char *);
447  for (cp = plugins_list; cp != NULL; cp = cp->next) {
448  if (cp->gevent[eventcode] != NULL)
449  cp->gevent[eventcode](&rt, eventcode, pl, buf);
450  }
451  break;
452 
453  case EVENT_LOGOUT:
454  /*LOGOUT: pl, pl->socket.host*/
455  pl = va_arg(args, player *);
456  buf = va_arg(args, char *);
457  for (cp = plugins_list; cp != NULL; cp = cp->next) {
458  if (cp->gevent[eventcode] != NULL)
459  cp->gevent[eventcode](&rt, eventcode, pl, buf);
460  }
461  break;
462 
463  case EVENT_MAPENTER:
464  /*MAPENTER: op, map*/
465  op = va_arg(args, object *);
466  map = va_arg(args, mapstruct *);
467  for (cp = plugins_list; cp != NULL; cp = cp->next) {
468  if (cp->gevent[eventcode] != NULL)
469  cp->gevent[eventcode](&rt, eventcode, op, map);
470  }
471  break;
472 
473  case EVENT_MAPLEAVE:
474  /*MAPLEAVE: op, map*/
475  op = va_arg(args, object *);
476  map = va_arg(args, mapstruct *);
477  for (cp = plugins_list; cp != NULL; cp = cp->next) {
478  if (cp->gevent[eventcode] != NULL)
479  cp->gevent[eventcode](&rt, eventcode, op, map);
480  }
481  break;
482 
483  case EVENT_MAPRESET:
484  /*MAPRESET: map*/
485  map = va_arg(args, mapstruct *);
486  for (cp = plugins_list; cp != NULL; cp = cp->next) {
487  if (cp->gevent[eventcode] != NULL)
488  cp->gevent[eventcode](&rt, eventcode, map);
489  }
490  break;
491 
492  case EVENT_REMOVE:
493  /*REMOVE: op*/
494  op = va_arg(args, object *);
495  for (cp = plugins_list; cp != NULL; cp = cp->next) {
496  if (cp->gevent[eventcode] != NULL)
497  cp->gevent[eventcode](&rt, eventcode, op);
498  }
499  break;
500 
501  case EVENT_SHOUT:
502  /*SHOUT: op, parms, priority*/
503  op = va_arg(args, object *);
504  buf = va_arg(args, char *);
505  i = va_arg(args, int);
506  for (cp = plugins_list; cp != NULL; cp = cp->next) {
507  if (cp->gevent[eventcode] != NULL)
508  cp->gevent[eventcode](&rt, eventcode, op, buf, i);
509  }
510  break;
511 
512  case EVENT_TELL:
513  /* Tell: who, what, to who */
514  op = va_arg(args, object *);
515  buf = va_arg(args, const char *);
516  op2 = va_arg(args, object *);
517  for (cp = plugins_list; cp != NULL; cp = cp->next) {
518  if (cp->gevent[eventcode] != NULL)
519  cp->gevent[eventcode](&rt, eventcode, op, buf, op2);
520  }
521  break;
522 
523  case EVENT_MUZZLE:
524  /*MUZZLE: op, parms*/
525  op = va_arg(args, object *);
526  buf = va_arg(args, char *);
527  for (cp = plugins_list; cp != NULL; cp = cp->next) {
528  if (cp->gevent[eventcode] != NULL)
529  cp->gevent[eventcode](&rt, eventcode, op, buf);
530  }
531  break;
532 
533  case EVENT_KICK:
534  /*KICK: op, parms*/
535  op = va_arg(args, object *);
536  buf = va_arg(args, char *);
537  for (cp = plugins_list; cp != NULL; cp = cp->next) {
538  if (cp->gevent[eventcode] != NULL)
539  cp->gevent[eventcode](&rt, eventcode, op, buf);
540  }
541  break;
542 
543  case EVENT_MAPUNLOAD:
544  /*MAPUNLOAD: map*/
545  map = va_arg(args, mapstruct *);
546  for (cp = plugins_list; cp != NULL; cp = cp->next) {
547  if (cp->gevent[eventcode] != NULL)
548  cp->gevent[eventcode](&rt, eventcode, map);
549  }
550  break;
551 
552  case EVENT_MAPLOAD:
553  /*MAPLOAD: map*/
554  map = va_arg(args, mapstruct *);
555  for (cp = plugins_list; cp != NULL; cp = cp->next) {
556  if (cp->gevent[eventcode] != NULL)
557  cp->gevent[eventcode](&rt, eventcode, map);
558  }
559  break;
560  }
561  va_end(args);
562  return 0;
563 }
564 
565 static void cfapi_get_hooks(int *type, ...) {
566  va_list args;
567  int request_type;
568  char *buf;
569  f_plug_api *rapi;
570 
571  *type = CFAPI_NONE;
572 
573  va_start(args, type);
574  request_type = va_arg(args, int);
575  if (request_type == 0) { /* By nr */
576  size_t fid;
577 
578  fid = va_arg(args, int);
579  rapi = va_arg(args, f_plug_api *);
580  if (fid >= NR_OF_HOOKS) {
581  *rapi = NULL;
582  *type = CFAPI_NONE;
583  } else {
584  *rapi = plug_hooks[fid].func;
585  *type = CFAPI_FUNC;
586  }
587  } else { /* by name */
588  size_t i;
589 
590  buf = va_arg(args, char *);
591  rapi = va_arg(args, f_plug_api *);
592  *rapi = NULL;
593  *type = CFAPI_NONE;
594  for (i = 0; i < NR_OF_HOOKS; i++) {
595  if (!strcmp(buf, plug_hooks[i].fname)) {
596  *rapi = plug_hooks[i].func;
597  *type = CFAPI_FUNC;
598  break;
599  }
600  }
601  }
602  va_end(args);
603 }
604 
611 int plugins_init_plugin(const char *libfile) {
612  LIBPTRTYPE ptr;
613  f_plug_init initfunc;
614  f_plug_property propfunc;
615  f_plug_event eventfunc;
616  f_plug_postinit postfunc;
617  f_plug_postinit closefunc;
618  int i;
619  crossfire_plugin *cp;
620  crossfire_plugin *ccp;
621  char *svn_rev;
622 
623 
624  /* Open the plugin lib and load the required functions */
625  ptr = plugins_dlopen(libfile);
626  if (ptr == NULL) {
627  LOG(llevError, "Error trying to load %s: %s\n", libfile, plugins_dlerror());
628  return -1;
629  }
630  svn_rev = (char*) plugins_dlsym(ptr, "SvnRevPlugin");
631  if (svn_rev == NULL) {
632  LOG(llevError, "Unable to find SvnRevPlugin in %s\n", libfile);
633  plugins_dlclose(ptr);
634  return -1;
635  }
636  if (settings.ignore_plugin_compatibility == 0 && strcmp(svn_rev, SVN_REV)) {
637  LOG(llevError, "SVN Version mismatch in in %s (%s != %s)\n", libfile, svn_rev, SVN_REV);
638  plugins_dlclose(ptr);
639  return -1;
640  }
641 
642  initfunc = (f_plug_init)plugins_dlsym(ptr, "initPlugin");
643  if (initfunc == NULL) {
644  LOG(llevError, "Plugin error while requesting %s.initPlugin: %s\n", libfile, plugins_dlerror());
645  plugins_dlclose(ptr);
646  return -1;
647  }
648  propfunc = (f_plug_property)plugins_dlsym(ptr, "getPluginProperty");
649  if (propfunc == NULL) {
650  LOG(llevError, "Plugin error while requesting %s.getPluginProperty: %s\n", libfile, plugins_dlerror());
651  plugins_dlclose(ptr);
652  return -1;
653  }
654  eventfunc = (f_plug_event)plugins_dlsym(ptr, "eventListener");
655  if (eventfunc == NULL) {
656  LOG(llevError, "Plugin error while requesting %s.eventListener: %s\n", libfile, plugins_dlerror());
657  plugins_dlclose(ptr);
658  return -1;
659  }
660  postfunc = (f_plug_postinit)plugins_dlsym(ptr, "postInitPlugin");
661  if (postfunc == NULL) {
662  LOG(llevError, "Plugin error while requesting %s.postInitPlugin: %s\n", libfile, plugins_dlerror());
663  plugins_dlclose(ptr);
664  return -1;
665  }
666  closefunc = (f_plug_postinit)plugins_dlsym(ptr, "closePlugin");
667  if (closefunc == NULL) {
668  LOG(llevError, "Plugin error while requesting %s.closePlugin: %s\n", libfile, plugins_dlerror());
669  plugins_dlclose(ptr);
670  return -1;
671  }
672  i = initfunc("2.0", cfapi_get_hooks);
673  cp = malloc(sizeof(crossfire_plugin));
674  for (i = 0; i < NR_EVENTS; i++)
675  cp->gevent[i] = NULL;
676  cp->eventfunc = eventfunc;
677  cp->propfunc = propfunc;
678  cp->closefunc = closefunc;
679  cp->libptr = ptr;
680  propfunc(&i, "Identification", cp->id, sizeof(cp->id));
681  propfunc(&i, "FullName", cp->fullname, sizeof(cp->fullname));
682  cp->next = NULL;
683  cp->prev = NULL;
684  if (plugins_list == NULL) {
685  plugins_list = cp;
686  } else {
687  for (ccp = plugins_list; ccp->next != NULL; ccp = ccp->next)
688  ;
689  ccp->next = cp;
690  cp->prev = ccp;
691  }
692  postfunc();
693  return 0;
694 }
695 
702 int plugins_remove_plugin(const char *id) {
703  crossfire_plugin *cp;
704 
705  if (plugins_list == NULL)
706  return -1;
707 
708  for (cp = plugins_list; cp != NULL; cp = cp->next) {
709  if (!strcmp(id, cp->id)) {
710  crossfire_plugin *n;
711  crossfire_plugin *p;
712 
713  n = cp->next;
714  p = cp->prev;
715  if (cp->closefunc)
716  cp->closefunc();
717  plugins_dlclose(cp->libptr);
718  if (n != NULL) {
719  if (p != NULL) {
720  n->prev = p;
721  p->next = n;
722  } else {
723  n->prev = NULL;
724  plugins_list = n;
725  }
726  } else {
727  if (p != NULL)
728  p->next = NULL;
729  else
730  plugins_list = NULL;
731  }
732  free(cp);
733  return 0;
734  }
735  }
736  return -1;
737 }
738 
744 void plugins_display_list(object *op) {
745  crossfire_plugin *cp;
746 
748  "List of loaded plugins:\n-----------------------");
749 
750  if (plugins_list == NULL)
751  return;
752 
753  for (cp = plugins_list; cp != NULL; cp = cp->next) {
755  "%s, %s",
756  cp->id, cp->fullname);
757  }
758 }
759 
760 /* SYSTEM-RELATED HOOKS */
761 
767 static void cfapi_cost_string_from_value(int *type, ...) {
768  uint64_t cost;
769  char *buffer, *final;
770  int length, largest_coin;
771  va_list args;
772 
773  va_start(args, type);
774  cost = va_arg(args, uint64_t);
775  largest_coin = va_arg(args, int);
776  buffer = va_arg(args, char*);
777  length = va_arg(args, int);
778  va_end(args);
779 
780  *type = CFAPI_NONE;
781 
782  if (length < 1)
783  return;
784 
785  final = cost_string_from_value(cost, largest_coin);
786 
787  strncpy(buffer, final, length - 1);
788  buffer[length - 1] = '\0';
789  free(final);
790 }
791 
797 static void cfapi_system_find_animation(int *type, ...) {
798  va_list args;
799  const char *anim;
800  int *num;
801 
802  va_start(args, type);
803  anim = va_arg(args, const char *);
804  num = va_arg(args, int *);
805  va_end(args);
806 
807  *num = find_animation(anim);
808  *type = CFAPI_INT;
809 }
810 
816 static void cfapi_system_find_face(int *type, ...) {
817  va_list args;
818  const char *face;
819  int error;
820  int *num;
821 
822  va_start(args, type);
823  face = va_arg(args, const char *);
824  error = va_arg(args, int);
825  num = va_arg(args, int *);
826  va_end(args);
827 
828  *num = find_face(face, error);
829  *type = CFAPI_INT;
830 }
831 
837 static void cfapi_system_strdup_local(int *type, ...) {
838  va_list args;
839  const char *txt;
840  char **ret;
841 
842  va_start(args, type);
843  txt = va_arg(args, const char *);
844  ret = va_arg(args, char **);
845  va_end(args);
846 
847  *ret = strdup_local(txt);
848  *type = CFAPI_STRING;
849 }
850 
851 static void cfapi_system_register_global_event(int *type, ...) {
852  va_list args;
853  int eventcode;
854  char *pname;
855  f_plug_event hook;
856  crossfire_plugin *cp;
857 
858  va_start(args, type);
859  eventcode = va_arg(args, int);
860  pname = va_arg(args, char *);
861  hook = va_arg(args, f_plug_event);
862  va_end(args);
863 
864  *type = CFAPI_NONE;
865 
866  cp = plugins_find_plugin(pname);
867  cp->gevent[eventcode] = hook;
868 }
869 
870 static void cfapi_system_unregister_global_event(int *type, ...) {
871  va_list args;
872  int eventcode;
873  char *pname;
874  crossfire_plugin *cp;
875 
876  va_start(args, type);
877  eventcode = va_arg(args, int);
878  pname = va_arg(args, char *);
879  va_end(args);
880 
881  *type = CFAPI_NONE;
882 
883  cp = plugins_find_plugin(pname);
884  cp->gevent[eventcode] = NULL;
885 }
886 
893 static void cfapi_system_add_string(int *type, ...) {
894  va_list args;
895  const char *str;
896  sstring *rv;
897 
898  va_start(args, type);
899  str = va_arg(args, const char *);
900  rv = va_arg(args, sstring *);
901  va_end(args);
902 
903  *rv = add_string(str);
904  *type = CFAPI_SSTRING;
905 }
906 
913 static void cfapi_system_remove_string(int *type, ...) {
914  va_list args;
915  sstring str;
916 
917  va_start(args, type);
918  str = va_arg(args, sstring);
919  va_end(args);
920 
921  free_string(str);
922  *type = CFAPI_NONE;
923 }
924 
931 static void cfapi_system_find_string(int *type, ...) {
932  va_list args;
933  const char *str;
934  sstring *rv;
935 
936  va_start(args, type);
937  str = va_arg(args, const char *);
938  rv = va_arg(args, sstring *);
939  va_end(args);
940 
941  *rv = find_string(str);
942  *type = CFAPI_SSTRING;
943 }
944 
950 static void cfapi_system_check_path(int *type, ...) {
951  va_list args;
952  const char *name;
953  int prepend_dir;
954  int *ret;
955 
956  va_start(args, type);
957 
958  name = va_arg(args, char *);
959  prepend_dir = va_arg(args, int);
960  ret = va_arg(args, int *);
961 
962  *ret = check_path(name, prepend_dir);
963 
964  va_end(args);
965  *type = CFAPI_INT;
966 }
967 
973 static void cfapi_system_re_cmp(int *type, ...) {
974  va_list args;
975  const char *str;
976  const char *regexp;
977  const char **rv;
978 
979  va_start(args, type);
980 
981  str = va_arg(args, char *);
982  regexp = va_arg(args, char *);
983  rv = va_arg(args, const char **);
984 
985  *rv = re_cmp(str, regexp);
986 
987  va_end(args);
988  *type = CFAPI_STRING;
989 }
990 
991 static void cfapi_system_directory(int *type, ...) {
992  va_list args;
993  int dirtype;
994  const char **str;
995 
996  va_start(args, type);
997 
998  dirtype = va_arg(args, int);
999  str = va_arg(args, const char **);
1000  va_end(args);
1001 
1002  *type = CFAPI_STRING;
1003 
1004  switch (dirtype) {
1005  case 0:
1006  *str = settings.mapdir;
1007  break;
1008 
1009  case 1:
1010  *str = settings.uniquedir;
1011  break;
1012 
1013  case 2:
1014  *str = settings.tmpdir;
1015  break;
1016 
1017  case 3:
1018  *str = settings.confdir;
1019  break;
1020 
1021  case 4:
1022  *str = settings.localdir;
1023  break;
1024 
1025  case 5:
1026  *str = settings.playerdir;
1027  break;
1028 
1029  case 6:
1030  *str = settings.datadir;
1031  break;
1032 
1033  default:
1034  *str = NULL;
1035  }
1036 }
1037 
1044 static void cfapi_get_time(int *type, ...) {
1045  va_list args;
1046  timeofday_t *tod;
1047 
1048  va_start(args, type);
1049  tod = va_arg(args, timeofday_t *);
1050  va_end(args);
1051 
1052  get_tod(tod);
1053  *type = CFAPI_NONE;
1054 }
1055 
1056 #define string_get_int(name) \
1057  va_list args; \
1058  int index; \
1059  const char **str; \
1060  va_start(args, type); \
1061  index = va_arg(args, int); \
1062  str = va_arg(args, const char **); \
1063  va_end(args); \
1064  *str = name(index); \
1065  *type = CFAPI_STRING; \
1066 
1067 
1075 static void cfapi_get_season_name(int *type, ...) {
1077 }
1078 
1087 static void cfapi_get_weekday_name(int *type, ...) {
1089 }
1090 
1099 static void cfapi_get_month_name(int *type, ...) {
1101 }
1102 
1111 static void cfapi_get_periodofday_name(int *type, ...) {
1113 }
1114 
1126 static void cfapi_timer_create(int *type, ...) {
1127  va_list args;
1128  int res;
1129  object *ob;
1130  long delay;
1131  int mode;
1132  int *timer;
1133 
1134  va_start(args, type);
1135  ob = va_arg(args, object *);
1136  delay = va_arg(args, long);
1137  mode = va_arg(args, int);
1138  timer = va_arg(args, int *);
1139  va_end(args);
1140  *type = CFAPI_INT;
1141 
1142  *timer = cftimer_find_free_id();
1143  if (*timer != TIMER_ERR_ID) {
1144  res = cftimer_create(*timer, delay, ob, mode);
1145  if (res != TIMER_ERR_NONE)
1146  *timer = res;
1147  }
1148 }
1149 
1159 static void cfapi_timer_destroy(int *type, ...) {
1160  va_list args;
1161  int id;
1162  int *err;
1163 
1164  va_start(args, type);
1165  id = va_arg(args, int);
1166  err = va_arg(args, int *);
1167  va_end(args);
1168  *type = CFAPI_INT;
1169 
1170  *err = cftimer_destroy(id);
1171 }
1172 
1178 static void cfapi_log(int *type, ...) {
1179  va_list args;
1180  LogLevel logLevel;
1181  const char *message;
1182 
1183  va_start(args, type);
1184  logLevel = va_arg(args, LogLevel);
1185  message = va_arg(args, const char *);
1186  LOG(logLevel, "%s", message);
1187  va_end(args);
1188 
1189  *type = CFAPI_NONE;
1190 }
1191 
1192 /* MAP RELATED HOOKS */
1193 
1202 static void cfapi_map_get_map(int *type, ...) {
1203  va_list args;
1204  mapstruct **ret;
1205  int ctype;
1206  int x, y;
1207  int16_t nx, ny;
1208  const char *name;
1209  mapstruct *m;
1210 
1211  va_start(args, type);
1212 
1213  ctype = va_arg(args, int);
1214 
1215  switch (ctype) {
1216  case 0:
1217  x = va_arg(args, int);
1218  y = va_arg(args, int);
1219  ret = va_arg(args, mapstruct **);
1220  *ret = get_empty_map(x, y);
1221  break;
1222 
1223  case 1:
1224  name = va_arg(args, const char *);
1225  x = va_arg(args, int);
1226  ret = va_arg(args, mapstruct **);
1227  *ret = ready_map_name(name, x);
1228  break;
1229 
1230  case 2:
1231  m = va_arg(args, mapstruct *);
1232  nx = va_arg(args, int);
1233  ny = va_arg(args, int);
1234  ret = va_arg(args, mapstruct **);
1235  *ret = get_map_from_coord(m, &nx, &ny);
1236  break;
1237 
1238  default:
1239  *type = CFAPI_NONE;
1240  va_end(args);
1241  return;
1242  break;
1243  }
1244  va_end(args);
1245  *type = CFAPI_PMAP;
1246 }
1247 
1253 static void cfapi_map_has_been_loaded(int *type, ...) {
1254  va_list args;
1255  mapstruct **map;
1256  char *string;
1257 
1258  va_start(args, type);
1259  string = va_arg(args, char *);
1260  map = va_arg(args, mapstruct **);
1261  *map = has_been_loaded(string);
1262  va_end(args);
1263  *type = CFAPI_PMAP;
1264 }
1265 
1271 static void cfapi_map_create_path(int *type, ...) {
1272  va_list args;
1273  int ctype, size;
1274  const char *str;
1275  char *name;
1276 
1277  va_start(args, type);
1278 
1279  ctype = va_arg(args, int);
1280  str = va_arg(args, const char *);
1281  name = va_arg(args, char *);
1282  size = va_arg(args, int);
1283  *type = CFAPI_STRING;
1284 
1285  switch (ctype) {
1286  case 0:
1287  create_pathname(str, name, size);
1288  break;
1289 
1290  case 1:
1291  create_overlay_pathname(str, name, MAX_BUF);
1292  break;
1293 
1294 /* case 2:
1295  rv = create_items_path(str);
1296  break;*/
1297 
1298  default:
1299  *type = CFAPI_NONE;
1300  break;
1301  }
1302  va_end(args);
1303 }
1304 
1305 static void cfapi_map_get_map_property(int *type, ...) {
1306  va_list args;
1307  mapstruct *map;
1308  int property;
1309 
1310  int *rint;
1311  mapstruct **rmap;
1312  sstring *rstr;
1313  region **rreg;
1314  int16_t *nx, *ny;
1315  int x, y;
1316 
1317  va_start(args, type);
1318 
1319  map = va_arg(args, mapstruct *);
1320  property = va_arg(args, int);
1321 
1322  switch (property) {
1323  case CFAPI_MAP_PROP_FLAGS:
1324  rmap = va_arg(args, mapstruct **);
1325  x = va_arg(args, int);
1326  y = va_arg(args, int);
1327  nx = va_arg(args, int16_t *);
1328  ny = va_arg(args, int16_t *);
1329  rint = va_arg(args, int *);
1330  *rint = get_map_flags(map, rmap, x, y, nx, ny);
1331  *type = CFAPI_INT;
1332  break;
1333 
1335  rint = va_arg(args, int *);
1336  *rint = calculate_difficulty(map);
1337  *type = CFAPI_INT;
1338  break;
1339 
1340  case CFAPI_MAP_PROP_PATH:
1341  rstr = va_arg(args, sstring *);
1342  *rstr = map->path;
1343  *type = CFAPI_SSTRING;
1344  break;
1345 
1347  rstr = va_arg(args, sstring *);
1348  *rstr = map->tmpname;
1349  *type = CFAPI_SSTRING;
1350  break;
1351 
1352  case CFAPI_MAP_PROP_NAME:
1353  rstr = va_arg(args, sstring *);
1354  *rstr = map->name;
1355  *type = CFAPI_SSTRING;
1356  break;
1357 
1359  rint = va_arg(args, int *);
1360  *rint = map->reset_time;
1361  *type = CFAPI_INT;
1362  break;
1363 
1365  rint = va_arg(args, int *);
1366  *rint = map->reset_timeout;
1367  *type = CFAPI_INT;
1368  break;
1369 
1371  rint = va_arg(args, int *);
1372  *rint = map->players;
1373  *type = CFAPI_INT;
1374  break;
1375 
1377  rint = va_arg(args, int *);
1378  *rint = map->darkness;
1379  *type = CFAPI_INT;
1380  break;
1381 
1382  case CFAPI_MAP_PROP_WIDTH:
1383  rint = va_arg(args, int *);
1384  *rint = map->width;
1385  *type = CFAPI_INT;
1386  break;
1387 
1388  case CFAPI_MAP_PROP_HEIGHT:
1389  rint = va_arg(args, int *);
1390  *rint = map->height;
1391  *type = CFAPI_INT;
1392  break;
1393 
1395  rint = va_arg(args, int *);
1396  *rint = map->enter_x;
1397  *type = CFAPI_INT;
1398  break;
1399 
1401  rint = va_arg(args, int *);
1402  *rint = map->enter_y;
1403  *type = CFAPI_INT;
1404  break;
1405 
1407  rstr = va_arg(args, sstring *);
1408  *rstr = map->msg;
1409  *type = CFAPI_SSTRING;
1410  break;
1411 
1412  case CFAPI_MAP_PROP_NEXT:
1413  rmap = va_arg(args, mapstruct **);
1414  *rmap = map ? map->next : first_map;
1415  *type = CFAPI_PMAP;
1416  break;
1417 
1418  case CFAPI_MAP_PROP_REGION:
1419  rreg = va_arg(args, region **);
1420  *rreg = get_region_by_map(map);
1421  *type = CFAPI_PREGION;
1422  break;
1423 
1424  case CFAPI_MAP_PROP_UNIQUE:
1425  rint = va_arg(args, int *);
1426  *rint = map->unique;
1427  *type = CFAPI_INT;
1428  break;
1429 
1430  default:
1431  *type = CFAPI_NONE;
1432  break;
1433  }
1434  va_end(args);
1435 }
1436 
1437 static void cfapi_map_set_map_property(int *type, ...) {
1438  va_list args;
1439  mapstruct *map;
1440  int property;
1441  const char *buf;
1442 
1443  va_start(args, type);
1444 
1445  map = va_arg(args, mapstruct *);
1446  property = va_arg(args, int);
1447 
1448  switch (property) {
1449  case CFAPI_MAP_PROP_PATH:
1450  buf = va_arg(args, const char *);
1451  snprintf(map->path, sizeof(map->path), "%s", buf);
1452  *type = CFAPI_STRING;
1453  break;
1454 
1455  default:
1456  *type = CFAPI_NONE;
1457  break;
1458  }
1459  va_end(args);
1460 }
1461 
1467 static void cfapi_map_out_of_map(int *type, ...) {
1468  va_list args;
1469  mapstruct *map;
1470  int x, y;
1471  int *rint;
1472 
1473  va_start(args, type);
1474  map = va_arg(args, mapstruct *);
1475  x = va_arg(args, int);
1476  y = va_arg(args, int);
1477  rint = va_arg(args, int *);
1478 
1479  *rint = out_of_map(map, x, y);
1480  va_end(args);
1481  *type = CFAPI_INT;
1482 }
1483 
1489 static void cfapi_map_update_position(int *type, ...) {
1490  va_list args;
1491  mapstruct *map;
1492  int x, y;
1493 
1494  va_start(args, type);
1495 
1496  map = va_arg(args, mapstruct *);
1497  x = va_arg(args, int);
1498  y = va_arg(args, int);
1499 
1500  update_position(map, x, y);
1501  va_end(args);
1502  *type = CFAPI_NONE;
1503 }
1504 
1505 static void cfapi_map_delete_map(int *type, ...) {
1506  va_list args;
1507  mapstruct *map;
1508  va_start(args, type);
1509 
1510  map = va_arg(args, mapstruct *);
1511 
1512  delete_map(map);
1513 
1514  va_end(args);
1515  *type = CFAPI_NONE;
1516 }
1517 
1518 static void cfapi_map_message(int *type, ...) {
1519  va_list args;
1520  mapstruct *map;
1521  const char *string;
1522  int color;
1523 
1524  va_start(args, type);
1525  map = va_arg(args, mapstruct *);
1526  string = va_arg(args, const char *);
1527  color = va_arg(args, int);
1528  va_end(args);
1529 
1530  /* function should be extended to take message types probably */
1531  ext_info_map(color, map, MSG_TYPE_MISC, MSG_SUBTYPE_NONE, string);
1532  *type = CFAPI_NONE;
1533 }
1534 
1540 static void cfapi_map_get_object_at(int *type, ...) {
1541  va_list args;
1542  mapstruct *map;
1543  int x, y;
1544  int16_t sx, sy;
1545  object **robj;
1546 
1547  va_start(args, type);
1548  map = va_arg(args, mapstruct *);
1549  x = va_arg(args, int);
1550  y = va_arg(args, int);
1551  robj = va_arg(args, object **);
1552  va_end(args);
1553 
1554  sx = x;
1555  sy = y;
1556  if (get_map_flags(map, &map, x, y, &sx, &sy)&P_OUT_OF_MAP)
1557  *robj = NULL;
1558  else
1559  *robj = GET_MAP_OB(map, sx, sy);
1560  *type = CFAPI_POBJECT;
1561 }
1562 
1569 static void cfapi_map_find_by_archetype_name(int *type, ...) {
1570  va_list args;
1571  int x, y;
1572  mapstruct *map;
1573  char *msg;
1574  object **robj;
1575 
1576  va_start(args, type);
1577 
1578  msg = va_arg(args, char *);
1579  map = va_arg(args, mapstruct *);
1580  x = va_arg(args, int);
1581  y = va_arg(args, int);
1582  robj = va_arg(args, object **);
1583 
1584  va_end(args);
1585 
1586  *robj = map_find_by_archetype(map, x, y, try_find_archetype(msg));
1587  *type = CFAPI_POBJECT;
1588 }
1589 
1595 static void cfapi_map_change_light(int *type, ...) {
1596  va_list args;
1597  int change;
1598  mapstruct *map;
1599  int *rint;
1600 
1601  va_start(args, type);
1602  map = va_arg(args, mapstruct *);
1603  change = va_arg(args, int);
1604  rint = va_arg(args, int *);
1605  va_end(args);
1606 
1607  *type = CFAPI_INT;
1608  *rint = change_map_light(map, change);
1609 }
1610 
1611 /* OBJECT-RELATED HOOKS */
1612 
1626 static void cfapi_object_move(int *type, ...) {
1627  va_list args;
1628  int kind;
1629  object *op;
1630  object *activator;
1631  player *pl;
1632  int direction;
1633  int *ret;
1634 
1635  va_start(args, type);
1636  kind = va_arg(args, int);
1637  switch (kind) {
1638  case 0:
1639  op = va_arg(args, object *);
1640  direction = va_arg(args, int);
1641  activator = va_arg(args, object *);
1642  ret = va_arg(args, int *);
1643  va_end(args);
1644  *ret = move_ob(op, direction, activator);
1645  break;
1646 
1647  case 1:
1648  pl = va_arg(args, player *);
1649  direction = va_arg(args, int);
1650  ret = va_arg(args, int *);
1651  va_end(args);
1652  *ret = move_player(pl->ob, direction);
1653  break;
1654 
1655  case 2:
1656  op = va_arg(args, object *);
1657  ret = va_arg(args, int *);
1658  va_end(args);
1659  *ret = player_arrest(op);
1660  break;
1661 
1662  default:
1663  // Just end the use of variable args. We got a wrong type.
1664  va_end(args);
1665  }
1666  *type = CFAPI_INT;
1667 }
1668 
1676 static void cfapi_object_get_key(int *type, ...) {
1677  va_list args;
1678  const char *keyname;
1679  const char **value;
1680  object *op;
1681 
1682  va_start(args, type);
1683  op = va_arg(args, object *);
1684  keyname = va_arg(args, const char *);
1685  value = va_arg(args, const char **);
1686  va_end(args);
1687 
1688  *value = object_get_value(op, keyname);
1689  *type = CFAPI_SSTRING;
1690 }
1691 
1698 static void cfapi_object_set_key(int *type, ...) {
1699  va_list args;
1700  const char *keyname;
1701  const char *value;
1702  int *ret;
1703  object *op;
1704  int add_key;
1705 
1706  va_start(args, type);
1707  op = va_arg(args, object *);
1708  keyname = va_arg(args, char *);
1709  value = va_arg(args, char *);
1710  add_key = va_arg(args, int);
1711  ret = va_arg(args, int *);
1712  va_end(args);
1713 
1714  *ret = object_set_value(op, keyname, value, add_key);
1715  *type = CFAPI_INT;
1716 }
1717 
1721 static void cfapi_object_get_property(int *type, ...) {
1722  va_list args;
1723  int property;
1724  object *op;
1725  int *rint;
1726  object **robject;
1727  mapstruct **rmap;
1728  float *rfloat;
1729  archetype **rarch;
1730  sstring *rsstring;
1731  char *rbuffer;
1732  int rbufsize;
1733  MoveType *rmove;
1734  int64_t *rint64;
1735  partylist **rparty;
1736  double *rdouble;
1737  long *rlong;
1738 
1739  va_start(args, type);
1740 
1741  op = va_arg(args, object *);
1742  property = va_arg(args, int);
1743  switch (property) {
1745  robject = va_arg(args, object **);
1746  *robject = op->above;
1747  *type = CFAPI_POBJECT;
1748  break;
1749 
1751  robject = va_arg(args, object **);
1752  *robject = op->below;
1753  *type = CFAPI_POBJECT;
1754  break;
1755 
1757  robject = va_arg(args, object **);
1758  *robject = op->active_next;
1759  *type = CFAPI_POBJECT;
1760  break;
1761 
1763  robject = va_arg(args, object **);
1764  *robject = op->active_prev;
1765  *type = CFAPI_POBJECT;
1766  break;
1767 
1769  robject = va_arg(args, object **);
1770  *robject = op->inv;
1771  *type = CFAPI_POBJECT;
1772  break;
1773 
1775  robject = va_arg(args, object **);
1776  *robject = op->env;
1777  *type = CFAPI_POBJECT;
1778  break;
1779 
1781  robject = va_arg(args, object **);
1782  *robject = op->head;
1783  *type = CFAPI_POBJECT;
1784  break;
1785 
1787  robject = va_arg(args, object **);
1788  *robject = op->container;
1789  *type = CFAPI_POBJECT;
1790  break;
1791 
1792  case CFAPI_OBJECT_PROP_MAP:
1793  rmap = va_arg(args, mapstruct **);
1794  *rmap = op->map;
1795  *type = CFAPI_PMAP;
1796  break;
1797 
1799  rint = va_arg(args, int *);
1800  *rint = op->count;
1801  *type = CFAPI_INT;
1802  break;
1803 
1805  rbuffer = va_arg(args, char *);
1806  rbufsize = va_arg(args, int);
1807  query_name(op, rbuffer, rbufsize);
1808  *type = CFAPI_STRING;
1809  break;
1810 
1812  rsstring = va_arg(args, sstring *);
1813  *rsstring = op->name_pl;
1814  *type = CFAPI_SSTRING;
1815  break;
1816 
1818  rsstring = va_arg(args, sstring *);
1819  *rsstring = op->title;
1820  *type = CFAPI_SSTRING;
1821  break;
1822 
1824  rsstring = va_arg(args, sstring *);
1825  *rsstring = op->race;
1826  *type = CFAPI_SSTRING;
1827  break;
1828 
1830  rsstring = va_arg(args, sstring *);
1831  *rsstring = op->slaying;
1832  *type = CFAPI_SSTRING;
1833  break;
1834 
1836  rsstring = va_arg(args, sstring *);
1837  *rsstring = op->skill;
1838  *type = CFAPI_SSTRING;
1839  break;
1840 
1842  rsstring = va_arg(args, sstring *);
1843  *rsstring = op->msg;
1844  *type = CFAPI_SSTRING;
1845  break;
1846 
1848  rsstring = va_arg(args, sstring *);
1849  *rsstring = op->lore;
1850  *type = CFAPI_SSTRING;
1851  break;
1852 
1853  case CFAPI_OBJECT_PROP_X:
1854  rint = va_arg(args, int *);
1855  *rint = op->x;
1856  *type = CFAPI_INT;
1857  break;
1858 
1859  case CFAPI_OBJECT_PROP_Y:
1860  rint = va_arg(args, int *);
1861  *rint = op->y;
1862  *type = CFAPI_INT;
1863  break;
1864 
1866  rfloat = va_arg(args, float *);
1867  *rfloat = op->speed;
1868  *type = CFAPI_FLOAT;
1869  break;
1870 
1872  rfloat = va_arg(args, float *);
1873  *rfloat = op->speed_left;
1874  *type = CFAPI_FLOAT;
1875  break;
1876 
1878  rint = va_arg(args, int *);
1879  *rint = op->nrof;
1880  *type = CFAPI_INT;
1881  break;
1882 
1884  rint = va_arg(args, int *);
1885  *rint = op->direction;
1886  *type = CFAPI_INT;
1887  break;
1888 
1890  rint = va_arg(args, int *);
1891  *rint = op->facing;
1892  *type = CFAPI_INT;
1893  break;
1894 
1896  rint = va_arg(args, int *);
1897  *rint = op->type;
1898  *type = CFAPI_INT;
1899  break;
1900 
1902  rint = va_arg(args, int *);
1903  *rint = op->subtype;
1904  *type = CFAPI_INT;
1905  break;
1906 
1908  rint = va_arg(args, int *);
1909  *rint = op->client_type;
1910  *type = CFAPI_INT;
1911  break;
1912 
1913  case CFAPI_OBJECT_PROP_RESIST: {
1914  int idx;
1915  int16_t *resist;
1916 
1917  idx = va_arg(args, int);
1918  resist = va_arg(args, int16_t *);
1919  *resist = op->resist[idx];
1920  }
1921  *type = CFAPI_INT16;
1922  break;
1923 
1925  rint = va_arg(args, int *);
1926  *rint = op->attacktype;
1927  *type = CFAPI_INT;
1928  break;
1929 
1931  rint = va_arg(args, int *);
1932  *rint = op->path_attuned;
1933  *type = CFAPI_INT;
1934  break;
1935 
1937  rint = va_arg(args, int *);
1938  *rint = op->path_repelled;
1939  *type = CFAPI_INT;
1940  break;
1941 
1943  rint = va_arg(args, int *);
1944  *rint = op->path_denied;
1945  *type = CFAPI_INT;
1946  break;
1947 
1949  rint = va_arg(args, int *);
1950  *rint = op->material;
1951  *type = CFAPI_INT;
1952  break;
1953 
1955  rsstring = va_arg(args, sstring *);
1956  *rsstring = op->materialname;
1957  *type = CFAPI_SSTRING;
1958  break;
1959 
1961  rint = va_arg(args, int *);
1962  *rint = op->magic;
1963  *type = CFAPI_INT;
1964  break;
1965 
1967  rlong = va_arg(args, long *);
1968  *rlong = op->value;
1969  *type = CFAPI_LONG;
1970  break;
1971 
1973  rint = va_arg(args, int *);
1974  *rint = op->level;
1975  *type = CFAPI_INT;
1976  break;
1977 
1979  rint = va_arg(args, int *);
1980  *rint = op->last_heal;
1981  *type = CFAPI_INT;
1982  break;
1983 
1985  rint = va_arg(args, int *);
1986  *rint = op->last_sp;
1987  *type = CFAPI_INT;
1988  break;
1989 
1991  rint = va_arg(args, int *);
1992  *rint = op->last_grace;
1993  *type = CFAPI_INT;
1994  break;
1995 
1997  rint = va_arg(args, int *);
1998  *rint = op->last_eat;
1999  *type = CFAPI_INT;
2000  break;
2001 
2003  rint = va_arg(args, int *);
2004  *rint = op->invisible;
2005  *type = CFAPI_INT;
2006  break;
2007 
2009  rint = va_arg(args, int *);
2010  *rint = op->pick_up;
2011  *type = CFAPI_INT;
2012  break;
2013 
2015  rint = va_arg(args, int *);
2016  *rint = op->item_power;
2017  *type = CFAPI_INT;
2018  break;
2019 
2021  rint = va_arg(args, int *);
2022  *rint = op->gen_sp_armour;
2023  *type = CFAPI_INT;
2024  break;
2025 
2027  rint = va_arg(args, int *);
2028  *rint = op->weight;
2029  *type = CFAPI_INT;
2030  break;
2031 
2033  rint = va_arg(args, int *);
2034  *rint = op->weight_limit;
2035  *type = CFAPI_INT;
2036  break;
2037 
2039  rint = va_arg(args, int *);
2040  *rint = op->carrying;
2041  *type = CFAPI_INT;
2042  break;
2043 
2045  rint = va_arg(args, int *);
2046  *rint = op->glow_radius;
2047  *type = CFAPI_INT;
2048  break;
2049 
2051  rint64 = va_arg(args, int64_t *);
2052  *rint64 = op->perm_exp;
2053  *type = CFAPI_SINT64;
2054  break;
2055 
2057  robject = va_arg(args, object **);
2058  *robject = op->current_weapon;
2059  *type = CFAPI_POBJECT;
2060  break;
2061 
2063  robject = va_arg(args, object **);
2064  *robject = op->enemy;
2065  *type = CFAPI_POBJECT;
2066  break;
2067 
2069  robject = va_arg(args, object **);
2070  *robject = op->attacked_by;
2071  *type = CFAPI_POBJECT;
2072  break;
2073 
2075  rint = va_arg(args, int *);
2076  *rint = op->run_away;
2077  *type = CFAPI_INT;
2078  break;
2079 
2081  robject = va_arg(args, object **);
2082  *robject = op->chosen_skill;
2083  *type = CFAPI_POBJECT;
2084  break;
2085 
2087  rint = va_arg(args, int *);
2088  *rint = op->hide;
2089  *type = CFAPI_INT;
2090  break;
2091 
2093  rint = va_arg(args, int *);
2094  *rint = op->move_status;
2095  *type = CFAPI_INT;
2096  break;
2097 
2099  rint = va_arg(args, int *);
2100  *rint = op->attack_movement;
2101  *type = CFAPI_INT;
2102  break;
2103 
2105  robject = va_arg(args, object **);
2106  *robject = op->spellitem;
2107  *type = CFAPI_POBJECT;
2108  break;
2109 
2111  rdouble = va_arg(args, double *);
2112  *rdouble = op->expmul;
2113  *type = CFAPI_DOUBLE;
2114  break;
2115 
2117  rarch = va_arg(args, archetype **);
2118  *rarch = op->arch;
2119  *type = CFAPI_PARCH;
2120  break;
2121 
2123  rarch = va_arg(args, archetype **);
2124  *rarch = op->other_arch;
2125  *type = CFAPI_PARCH;
2126  break;
2127 
2129  rsstring = va_arg(args, sstring *);
2130  *rsstring = op->custom_name;
2131  *type = CFAPI_SSTRING;
2132  break;
2133 
2135  rint = va_arg(args, int *);
2136  *rint = op->anim_speed;
2137  *type = CFAPI_INT;
2138  break;
2139 
2141  rint = va_arg(args, int *);
2142  *rint = is_friendly(op);
2143  *type = CFAPI_INT;
2144  break;
2145 
2147  rbuffer = va_arg(args, char *);
2148  rbufsize = va_arg(args, int);
2149  query_short_name(op, rbuffer, rbufsize);
2150  *type = CFAPI_STRING;
2151  break;
2152 
2154  int i;
2155 
2156  i = va_arg(args, int);
2157  rbuffer = va_arg(args, char *);
2158  rbufsize = va_arg(args, int);
2159  query_base_name(op, i, rbuffer, rbufsize);
2160  *type = CFAPI_STRING;
2161  }
2162  break;
2163 
2165  rsstring = va_arg(args, sstring *);
2166  *rsstring = op->name;
2167  *type = CFAPI_SSTRING;
2168  break;
2169 
2171  rint = va_arg(args, int *);
2172  *rint = is_magical(op);
2173  *type = CFAPI_INT;
2174  break;
2175 
2177  rint = va_arg(args, int *);
2178  *rint = op->stats.luck;
2179  *type = CFAPI_INT;
2180  break;
2181 
2182  case CFAPI_OBJECT_PROP_EXP:
2183  rint64 = va_arg(args, int64_t *);
2184  *rint64 = op->stats.exp;
2185  *type = CFAPI_SINT64;
2186  break;
2187 
2189  robject = va_arg(args, object **);
2190  *robject = object_get_owner(op);
2191  *type = CFAPI_POBJECT;
2192  break;
2193 
2195  int stype;
2196 
2197  stype = va_arg(args, int);
2198  switch (stype) {
2199  unsigned char ptype;
2200  char *buf;
2201  archetype *at;
2202 
2203  case 0: /* present_in_ob */
2204  ptype = (unsigned char)(va_arg(args, int));
2205  robject = va_arg(args, object **);
2206  *robject = object_present_in_ob(ptype, op);
2207  break;
2208 
2209  case 1: /* present_in_ob_by_name */
2210  ptype = (unsigned char)(va_arg(args, int));
2211  buf = va_arg(args, char *);
2212  robject = va_arg(args, object **);
2213  *robject = object_present_in_ob_by_name(ptype, buf, op);
2214  break;
2215 
2216  case 2: /* arch_present_in_ob */
2217  at = va_arg(args, archetype *);
2218  robject = va_arg(args, object **);
2219  *robject = arch_present_in_ob(at, op);
2220  break;
2221  }
2222  }
2223  *type = CFAPI_POBJECT;
2224  break;
2225 
2227  rint = va_arg(args, int *);
2228  *rint = (QUERY_FLAG(op, FLAG_WAS_WIZ));
2229  *type = CFAPI_INT;
2230  break;
2231 
2233  object *op2;
2234 
2235  op2 = va_arg(args, object *);
2236  rint = va_arg(args, int *);
2237  *rint = object_can_merge(op, op2);
2238  }
2239  *type = CFAPI_INT;
2240  break;
2241 
2243  object *op2;
2244 
2245  op2 = va_arg(args, object *);
2246  rint = va_arg(args, int *);
2247  *rint = object_can_pick(op2, op);
2248  }
2249  *type = CFAPI_INT;
2250  break;
2251 
2252  case CFAPI_OBJECT_PROP_FLAGS: {
2253  int fl;
2254 
2255  fl = va_arg(args, int);
2256  rint = va_arg(args, int *);
2257  *rint = QUERY_FLAG(op, fl);
2258  }
2259  *type = CFAPI_INT;
2260  break;
2261 
2262  case CFAPI_OBJECT_PROP_STR:
2263  rint = va_arg(args, int *);
2264  *rint = op->stats.Str;
2265  *type = CFAPI_INT;
2266  break;
2267 
2268  case CFAPI_OBJECT_PROP_DEX:
2269  rint = va_arg(args, int *);
2270  *rint = op->stats.Dex;
2271  *type = CFAPI_INT;
2272  break;
2273 
2274  case CFAPI_OBJECT_PROP_CON:
2275  rint = va_arg(args, int *);
2276  *rint = op->stats.Con;
2277  *type = CFAPI_INT;
2278  break;
2279 
2280  case CFAPI_OBJECT_PROP_WIS:
2281  rint = va_arg(args, int *);
2282  *rint = op->stats.Wis;
2283  *type = CFAPI_INT;
2284  break;
2285 
2286  case CFAPI_OBJECT_PROP_INT:
2287  rint = va_arg(args, int *);
2288  *rint = op->stats.Int;
2289  *type = CFAPI_INT;
2290  break;
2291 
2292  case CFAPI_OBJECT_PROP_POW:
2293  rint = va_arg(args, int *);
2294  *rint = op->stats.Pow;
2295  *type = CFAPI_INT;
2296  break;
2297 
2298  case CFAPI_OBJECT_PROP_CHA:
2299  rint = va_arg(args, int *);
2300  *rint = op->stats.Cha;
2301  *type = CFAPI_INT;
2302  break;
2303 
2304  case CFAPI_OBJECT_PROP_WC:
2305  rint = va_arg(args, int *);
2306  *rint = op->stats.wc;
2307  *type = CFAPI_INT;
2308  break;
2309 
2310  case CFAPI_OBJECT_PROP_AC:
2311  rint = va_arg(args, int *);
2312  *rint = op->stats.ac;
2313  *type = CFAPI_INT;
2314  break;
2315 
2316  case CFAPI_OBJECT_PROP_HP:
2317  rint = va_arg(args, int *);
2318  *rint = op->stats.hp;
2319  *type = CFAPI_INT;
2320  break;
2321 
2322  case CFAPI_OBJECT_PROP_SP:
2323  rint = va_arg(args, int *);
2324  *rint = op->stats.sp;
2325  *type = CFAPI_INT;
2326  break;
2327 
2328  case CFAPI_OBJECT_PROP_GP:
2329  rint = va_arg(args, int *);
2330  *rint = op->stats.grace;
2331  *type = CFAPI_INT;
2332  break;
2333 
2334  case CFAPI_OBJECT_PROP_FP:
2335  rint = va_arg(args, int *);
2336  *rint = op->stats.food;
2337  *type = CFAPI_INT;
2338  break;
2339 
2341  rint = va_arg(args, int *);
2342  *rint = op->stats.maxhp;
2343  *type = CFAPI_INT;
2344  break;
2345 
2347  rint = va_arg(args, int *);
2348  *rint = op->stats.maxsp;
2349  *type = CFAPI_INT;
2350  break;
2351 
2353  rint = va_arg(args, int *);
2354  *rint = op->stats.maxgrace;
2355  *type = CFAPI_INT;
2356  break;
2357 
2358  case CFAPI_OBJECT_PROP_DAM:
2359  rint = va_arg(args, int *);
2360  *rint = op->stats.dam;
2361  *type = CFAPI_INT;
2362  break;
2363 
2364  case CFAPI_OBJECT_PROP_GOD:
2365  rsstring = va_arg(args, sstring *);
2366  *rsstring = determine_god(op);
2367  *type = CFAPI_SSTRING;
2368  break;
2369 
2371  rsstring = va_arg(args, sstring *);
2372  *rsstring = op->arch->name;
2373  *type = CFAPI_SSTRING;
2374  break;
2375 
2377  rint = va_arg(args, int *);
2378  *rint = op->invisible;
2379  *type = CFAPI_INT;
2380  break;
2381 
2383  rbuffer = va_arg(args, char *);
2384  rbufsize = va_arg(args, int);
2385  if (rbufsize > 0) {
2386  strncpy(rbuffer, op->face->name, rbufsize);
2387  rbuffer[rbufsize - 1] = '\0';
2388  }
2389  *type = CFAPI_STRING;
2390  break;
2391 
2393  rbuffer = va_arg(args, char *);
2394  rbufsize = va_arg(args, int);
2395  if (rbufsize > 0) {
2396  if (op->animation_id != 0) {
2397  strncpy(rbuffer, animations[op->animation_id].name, rbufsize);
2398  rbuffer[rbufsize - 1] = '\0';
2399  }
2400  else
2401  rbuffer[0] = '\0';
2402  }
2403  *type = CFAPI_STRING;
2404  break;
2405 
2406  case CFAPI_PLAYER_PROP_IP:
2407  rsstring = va_arg(args, sstring *);
2408  *rsstring = op->contr->socket.host;
2409  *type = CFAPI_SSTRING;
2410  break;
2411 
2413  robject = va_arg(args, object **);
2414  *robject = find_marked_object(op);
2415  *type = CFAPI_POBJECT;
2416  break;
2417 
2419  rparty = va_arg(args, partylist **);
2420  *rparty = (op->contr ? op->contr->party : NULL);
2421  *type = CFAPI_PPARTY;
2422  break;
2423 
2425  robject = va_arg(args, object **);
2426  if (op)
2427  *robject = op->contr->next ? op->contr->next->ob : NULL;
2428  else
2429  /* This can be called when there is no player. */
2430  *robject = first_player ? first_player->ob : NULL;
2431  *type = CFAPI_POBJECT;
2432  break;
2433 
2435  rbuffer = va_arg(args, char *);
2436  rbufsize = va_arg(args, int);
2437  player_get_title(op->contr, rbuffer, rbufsize);
2438  *type = CFAPI_STRING;
2439  break;
2440 
2442  rmove = va_arg(args, MoveType *);
2443  *rmove = op->move_type;
2444  *type = CFAPI_MOVETYPE;
2445  break;
2446 
2448  rmove = va_arg(args, MoveType *);
2449  *rmove = op->move_block;
2450  *type = CFAPI_MOVETYPE;
2451  break;
2452 
2454  rmove = va_arg(args, MoveType *);
2455  *rmove = op->move_allow;
2456  *type = CFAPI_MOVETYPE;
2457  break;
2458 
2460  rmove = va_arg(args, MoveType *);
2461  *rmove = op->move_on;
2462  *type = CFAPI_MOVETYPE;
2463  break;
2464 
2466  rmove = va_arg(args, MoveType *);
2467  *rmove = op->move_off;
2468  *type = CFAPI_MOVETYPE;
2469  break;
2470 
2472  rmove = va_arg(args, MoveType *);
2473  *rmove = op->move_type;
2474  *type = CFAPI_MOVETYPE;
2475  break;
2476 
2478  rfloat = va_arg(args, float *);
2479  *rfloat = op->move_slow_penalty;
2480  *type = CFAPI_FLOAT;
2481  break;
2482 
2484  rbuffer = va_arg(args, char *);
2485  rbufsize = va_arg(args, int);
2486  snprintf(rbuffer, rbufsize, "%s", op->contr->savebed_map);
2487  *type = CFAPI_STRING;
2488  break;
2489 
2491  rint = va_arg(args, int *);
2492  *rint = op->contr->bed_x;
2493  *type = CFAPI_INT;
2494  break;
2495 
2497  rint = va_arg(args, int *);
2498  *rint = op->contr->bed_y;
2499  *type = CFAPI_INT;
2500  break;
2501 
2503  rint = va_arg(args, int *);
2504  *rint = op->duration;
2505  *type = CFAPI_INT;
2506  break;
2507 
2508  default:
2509  *type = CFAPI_NONE;
2510  break;
2511  }
2512  va_end(args);
2513 }
2514 
2523 static void copy_message(object *op, const char *msg) {
2524  char *temp;
2525  int size;
2526 
2527  if (!msg)
2528  return;
2529 
2530  /* need to reset parsed dialog information */
2532 
2533  size = strlen(msg);
2534 
2535  if (msg[0] != 0 && msg[size-1] == '\n') {
2536  object_set_msg(op, msg);
2537  return;
2538  }
2539 
2540  temp = malloc(size+2);
2541  if (!temp)
2543  snprintf(temp, size+2, "%s\n", msg);
2544  object_set_msg(op, temp);
2545  free(temp);
2546 }
2547 
2556 static void cfapi_object_set_property(int *type, ...) {
2557  va_list args;
2558  int iarg, *ret;
2559  long larg;
2560  char *sarg;
2561  double darg;
2562  object *oparg;
2563  object *op;
2564  int property;
2565  int64_t s64arg;
2566  partylist *partyarg;
2567  float farg;
2568  MoveType *move; /* MoveType can't be used through va_arg so use MoveType * */
2569 
2570  va_start(args, type);
2571  op = va_arg(args, object *);
2572  property = va_arg(args, int);
2573  *type = CFAPI_NONE;
2574 
2575  if (op != NULL && (!op->arch || (op != &op->arch->clone))) {
2576  switch (property) {
2578  sarg = va_arg(args, char *);
2579  *type = CFAPI_STRING;
2580  FREE_AND_COPY(op->name, sarg);
2581  send_changed_object(op);
2582  break;
2583 
2585  sarg = va_arg(args, char *);
2586  *type = CFAPI_STRING;
2587  FREE_AND_COPY(op->name_pl, sarg);
2588  send_changed_object(op);
2589  break;
2590 
2592  sarg = va_arg(args, char *);
2593  *type = CFAPI_STRING;
2594  FREE_AND_COPY(op->title, sarg);
2595  break;
2596 
2598  sarg = va_arg(args, char *);
2599  *type = CFAPI_STRING;
2600  FREE_AND_COPY(op->race, sarg);
2601  break;
2602 
2604  sarg = va_arg(args, char *);
2605  *type = CFAPI_STRING;
2606  FREE_AND_COPY(op->slaying, sarg);
2607  break;
2608 
2610  sarg = va_arg(args, char *);
2611  *type = CFAPI_STRING;
2612  FREE_AND_COPY(op->skill, sarg);
2613  break;
2614 
2616  sarg = va_arg(args, char *);
2617  *type = CFAPI_STRING;
2618  copy_message(op, sarg);
2619  break;
2620 
2622  sarg = va_arg(args, char *);
2623  *type = CFAPI_STRING;
2624  FREE_AND_COPY(op->lore, sarg);
2625  break;
2626 
2628  farg = va_arg(args, double);
2629  *type = CFAPI_FLOAT;
2630  if (farg != op->speed) {
2631  op->speed = farg;
2632  object_update_speed(op);
2633  }
2634  break;
2635 
2637  farg = va_arg(args, double);
2638  *type = CFAPI_FLOAT;
2639  op->speed_left = farg;
2640  break;
2641 
2643  iarg = va_arg(args, int);
2644  *type = CFAPI_INT;
2645  if (iarg < 0)
2646  iarg = 0;
2647  if (op->nrof > (uint32_t)iarg)
2648  object_decrease_nrof(op, op->nrof-iarg);
2649  else if (op->nrof < (uint32_t)iarg) {
2650  object *tmp;
2651  player *pl;
2652 
2653  op->nrof = iarg;
2654  if (op->env != NULL) {
2655  tmp = object_get_player_container(op->env);
2656  if (!tmp) {
2657  for (pl = first_player; pl; pl = pl->next)
2658  if (pl->ob->container == op->env)
2659  break;
2660  if (pl)
2661  tmp = pl->ob;
2662  else
2663  tmp = NULL;
2664  } else {
2665  object_sum_weight(tmp);
2666  fix_object(tmp);
2667  }
2668  if (tmp)
2669  esrv_update_item(UPD_NROF, tmp, op);
2670  } else {
2671  FOR_ABOVE_PREPARE(op, tmp)
2672  if (tmp->type == PLAYER)
2673  tmp->contr->socket.update_look = 1;
2674  FOR_ABOVE_FINISH();
2675  }
2676  }
2677  break;
2678 
2680  iarg = va_arg(args, int);
2681  *type = CFAPI_INT;
2682  op->direction = iarg;
2683  break;
2684 
2686  iarg = va_arg(args, int);
2687  *type = CFAPI_INT;
2688  op->facing = iarg;
2689  break;
2690 
2691  case CFAPI_OBJECT_PROP_RESIST: {
2692  int iargbis = va_arg(args, int);
2693 
2694  *type = CFAPI_INT16;
2695  iarg = va_arg(args, int);
2696  op->resist[iargbis] = iarg;
2697  }
2698  break;
2699 
2701  iarg = va_arg(args, int);
2702  *type = CFAPI_INT;
2703  op->attacktype = iarg;
2704  break;
2705 
2707  iarg = va_arg(args, int);
2708  *type = CFAPI_INT;
2709  op->path_attuned = iarg;
2710  break;
2711 
2713  iarg = va_arg(args, int);
2714  *type = CFAPI_INT;
2715  op->path_repelled = iarg;
2716  break;
2717 
2719  iarg = va_arg(args, int);
2720  *type = CFAPI_INT;
2721  op->path_denied = iarg;
2722  break;
2723 
2725  iarg = va_arg(args, int);
2726  *type = CFAPI_INT;
2727  op->material = iarg;
2728  break;
2729 
2731  break;
2732 
2734  iarg = va_arg(args, int);
2735  *type = CFAPI_INT;
2736  op->magic = iarg;
2737  break;
2738 
2740  larg = va_arg(args, long);
2741  *type = CFAPI_LONG;
2742  op->value = larg;
2743  break;
2744 
2746  iarg = va_arg(args, int);
2747  *type = CFAPI_INT;
2748  op->level = iarg;
2749  break;
2750 
2752  iarg = va_arg(args, int);
2753  *type = CFAPI_INT;
2754  op->last_heal = iarg;
2755  break;
2756 
2758  iarg = va_arg(args, int);
2759  *type = CFAPI_INT;
2760  op->last_sp = iarg;
2761  break;
2762 
2764  iarg = va_arg(args, int);
2765  *type = CFAPI_INT;
2766  op->last_grace = iarg;
2767  break;
2768 
2770  iarg = va_arg(args, int);
2771  *type = CFAPI_INT;
2772  op->last_eat = iarg;
2773  break;
2774 
2776  iarg = va_arg(args, int);
2777  *type = CFAPI_INT;
2778  op->invisible = iarg;
2779  break;
2780 
2782  iarg = va_arg(args, int);
2783  *type = CFAPI_INT;
2784  op->pick_up = iarg;
2785  break;
2786 
2788  iarg = va_arg(args, int);
2789  *type = CFAPI_INT;
2790  op->item_power = iarg;
2791  break;
2792 
2794  iarg = va_arg(args, int);
2795  *type = CFAPI_INT;
2796  op->gen_sp_armour = iarg;
2797  break;
2798 
2800  iarg = va_arg(args, int);
2801  *type = CFAPI_INT;
2802  if (op->weight != iarg) {
2803  object *tmp;
2804  player *pl;
2805 
2806  op->weight = iarg;
2807  if (op->env != NULL) {
2808  tmp = object_get_player_container(op->env);
2809  if (!tmp) {
2810  for (pl = first_player; pl; pl = pl->next)
2811  if (pl->ob->container == op->env)
2812  break;
2813  if (pl)
2814  tmp = pl->ob;
2815  else
2816  tmp = NULL;
2817  } else {
2818  object_sum_weight(tmp);
2819  fix_object(tmp);
2820  }
2821  if (tmp)
2822  esrv_update_item(UPD_WEIGHT, tmp, op);
2823  } else {
2824  FOR_ABOVE_PREPARE(op, tmp)
2825  if (tmp->type == PLAYER)
2826  esrv_update_item(UPD_WEIGHT, tmp, op);
2827  FOR_ABOVE_FINISH();
2828  }
2829  }
2830  break;
2831 
2833  iarg = va_arg(args, int);
2834  *type = CFAPI_INT;
2835  op->weight_limit = iarg;
2836  break;
2837 
2839  iarg = va_arg(args, int);
2840  *type = CFAPI_INT;
2841  if (op->glow_radius != iarg) {
2842  object *tmp;
2843 
2844  op->glow_radius = iarg;
2845  tmp = object_get_env_recursive(op);
2846  if (tmp->map != NULL) {
2847  SET_MAP_FLAGS(tmp->map, tmp->x, tmp->y, P_NEED_UPDATE);
2848  update_position(tmp->map, tmp->x, tmp->y);
2849  update_all_los(tmp->map, tmp->x, tmp->y);
2850  }
2851  }
2852  break;
2853 
2855  s64arg = va_arg(args, int64_t);
2856  *type = CFAPI_SINT64;
2857  op->perm_exp = s64arg;
2858  break;
2859 
2861  oparg = va_arg(args, object *);
2862  *type = CFAPI_POBJECT;
2863  object_set_enemy(op, oparg);
2864  break;
2865 
2867  iarg = va_arg(args, int);
2868  *type = CFAPI_INT;
2869  op->run_away = iarg;
2870  break;
2871 
2873  oparg = va_arg(args, object *);
2874  *type = CFAPI_POBJECT;
2875  op->chosen_skill = oparg;
2876  break;
2877 
2879  iarg = va_arg(args, int);
2880  *type = CFAPI_INT;
2881  op->hide = iarg;
2882  break;
2883 
2885  iarg = va_arg(args, int);
2886  *type = CFAPI_INT;
2887  op->move_status = iarg;
2888  break;
2889 
2891  iarg = va_arg(args, int);
2892  *type = CFAPI_INT;
2893  op->attack_movement = iarg;
2894  break;
2895 
2897  oparg = va_arg(args, object *);
2898  *type = CFAPI_POBJECT;
2899  op->spellitem = oparg;
2900  break;
2901 
2903  darg = va_arg(args, double);
2904  *type = CFAPI_DOUBLE;
2905  op->expmul = darg;
2906  break;
2907 
2909  sarg = va_arg(args, char *);
2910  *type = CFAPI_STRING;
2911  FREE_AND_COPY(op->custom_name, sarg);
2912  send_changed_object(op);
2913  break;
2914 
2916  iarg = va_arg(args, int);
2917  *type = CFAPI_INT;
2918  op->anim_speed = iarg;
2919  break;
2920 
2922  iarg = va_arg(args, int);
2923  *type = CFAPI_INT;
2924  if (iarg == 1 && is_friendly(op) == 0)
2925  add_friendly_object(op);
2926  else if (iarg == 0 && is_friendly(op) == 1)
2928  break;
2929 
2931  iarg = va_arg(args, int);
2932  *type = CFAPI_INT;
2933  op->stats.luck = iarg;
2934  break;
2935 
2936  case CFAPI_OBJECT_PROP_EXP:
2937  s64arg = va_arg(args, int64_t);
2938  *type = CFAPI_SINT64;
2939  op->stats.exp = s64arg;
2940  break;
2941 
2943  oparg = va_arg(args, object *);
2944  *type = CFAPI_POBJECT;
2945  object_set_owner(op, oparg);
2946  break;
2947 
2949  object_set_cheat(op);
2950  *type = CFAPI_NONE;
2951  break;
2952 
2953  case CFAPI_OBJECT_PROP_FLAGS: {
2954  int iargbis;
2955 
2956  iarg = va_arg(args, int);
2957  iargbis = va_arg(args, int);
2958  *type = CFAPI_INT;
2959 
2960  if (iargbis == 1)
2961  SET_FLAG(op, iarg);
2962  else
2963  CLEAR_FLAG(op, iarg);
2964  }
2965  break;
2966 
2967  case CFAPI_OBJECT_PROP_STR:
2968  iarg = va_arg(args, int);
2969  *type = CFAPI_INT;
2970  op->stats.Str = iarg;
2971  break;
2972 
2973  case CFAPI_OBJECT_PROP_DEX:
2974  iarg = va_arg(args, int);
2975  *type = CFAPI_INT;
2976  op->stats.Dex = iarg;
2977  break;
2978 
2979  case CFAPI_OBJECT_PROP_CON:
2980  iarg = va_arg(args, int);
2981  *type = CFAPI_INT;
2982  op->stats.Con = iarg;
2983  break;
2984 
2985  case CFAPI_OBJECT_PROP_WIS:
2986  iarg = va_arg(args, int);
2987  *type = CFAPI_INT;
2988  op->stats.Wis = iarg;
2989  break;
2990 
2991  case CFAPI_OBJECT_PROP_INT:
2992  iarg = va_arg(args, int);
2993  *type = CFAPI_INT;
2994  op->stats.Int = iarg;
2995  break;
2996 
2997  case CFAPI_OBJECT_PROP_POW:
2998  iarg = va_arg(args, int);
2999  *type = CFAPI_INT;
3000  op->stats.Pow = iarg;
3001  break;
3002 
3003  case CFAPI_OBJECT_PROP_CHA:
3004  iarg = va_arg(args, int);
3005  *type = CFAPI_INT;
3006  op->stats.Cha = iarg;
3007  break;
3008 
3009  case CFAPI_OBJECT_PROP_WC:
3010  iarg = va_arg(args, int);
3011  *type = CFAPI_INT;
3012  op->stats.wc = iarg;
3013  break;
3014 
3015  case CFAPI_OBJECT_PROP_AC:
3016  iarg = va_arg(args, int);
3017  *type = CFAPI_INT;
3018  op->stats.ac = iarg;
3019  break;
3020 
3021  case CFAPI_OBJECT_PROP_HP:
3022  iarg = va_arg(args, int);
3023  *type = CFAPI_INT;
3024  op->stats.hp = iarg;
3025  break;
3026 
3027  case CFAPI_OBJECT_PROP_SP:
3028  iarg = va_arg(args, int);
3029  *type = CFAPI_INT;
3030  op->stats.sp = iarg;
3031  break;
3032 
3033  case CFAPI_OBJECT_PROP_GP:
3034  iarg = va_arg(args, int);
3035  *type = CFAPI_INT;
3036  op->stats.grace = iarg;
3037  break;
3038 
3039  case CFAPI_OBJECT_PROP_FP:
3040  iarg = va_arg(args, int);
3041  *type = CFAPI_INT;
3042  op->stats.food = iarg;
3043  break;
3044 
3046  iarg = va_arg(args, int);
3047  *type = CFAPI_INT;
3048  op->stats.maxhp = iarg;
3049  break;
3050 
3052  iarg = va_arg(args, int);
3053  *type = CFAPI_INT;
3054  op->stats.maxsp = iarg;
3055  break;
3056 
3058  iarg = va_arg(args, int);
3059  *type = CFAPI_INT;
3060  op->stats.maxgrace = iarg;
3061  break;
3062 
3063  case CFAPI_OBJECT_PROP_DAM:
3064  iarg = va_arg(args, int);
3065  *type = CFAPI_INT;
3066  op->stats.dam = iarg;
3067  break;
3068 
3069  case CFAPI_OBJECT_PROP_FACE: {
3070  sarg = va_arg(args, char *);
3071  ret = va_arg(args, int *);
3072  *type = CFAPI_INT;
3073  *ret = find_face(sarg, 0);
3074  if (*ret != 0) {
3075  op->face = &new_faces[*ret];
3076  op->state = 0;
3078  }
3079  break;
3080  }
3081 
3083  sarg = va_arg(args, char *);
3084  ret = va_arg(args, int *);
3085  *type = CFAPI_INT;
3086  *ret = try_find_animation(sarg);
3087  if (*ret != 0) {
3088  op->animation_id = *ret;
3089  SET_ANIMATION(op, 0);
3091  }
3092  break;
3093 
3095  iarg = va_arg(args, int);
3096  *type = CFAPI_INT;
3097  op->duration = iarg;
3098  break;
3099 
3101  if (op->contr) {
3102  oparg = va_arg(args, object *);
3103  *type = CFAPI_POBJECT;
3104  op->contr->mark = oparg;
3105  if (oparg) {
3106  op->contr->mark_count = oparg->count;
3107  } else {
3108  op->contr->mark_count = 0;
3109  }
3110  }
3111  break;
3112 
3114  if (op->contr) {
3115  partyarg = va_arg(args, partylist *);
3116  *type = CFAPI_PPARTY;
3117  party_join(op, partyarg);
3118  }
3119  break;
3120 
3122  sarg = va_arg(args, char *);
3123  *type = CFAPI_STRING;
3124  safe_strncpy(op->contr->savebed_map, sarg, MAX_BUF);
3125  break;
3126 
3128  iarg = va_arg(args, int);
3129  *type = CFAPI_INT;
3130  op->contr->bed_x = iarg;
3131  break;
3132 
3134  iarg = va_arg(args, int);
3135  *type = CFAPI_INT;
3136  op->contr->bed_y = iarg;
3137  break;
3138 
3140  sarg = va_arg(args, char *);
3141  *type = CFAPI_STRING;
3142  player_set_own_title(op->contr, sarg);
3143  break;
3144 
3146  move = va_arg(args, MoveType *);
3147  op->move_type = *move & MOVE_ALL;
3149  *type = CFAPI_MOVETYPE;
3150  break;
3151 
3153  move = va_arg(args, MoveType *);
3154  op->move_block = *move & MOVE_ALL;
3156  *type = CFAPI_MOVETYPE;
3157  break;
3158 
3160  move = va_arg(args, MoveType *);
3161  op->move_allow = *move & MOVE_ALL;
3163  *type = CFAPI_MOVETYPE;
3164  break;
3165 
3167  move = va_arg(args, MoveType *);
3168  op->move_on = *move & MOVE_ALL;
3170  *type = CFAPI_MOVETYPE;
3171  break;
3172 
3174  move = va_arg(args, MoveType *);
3175  op->move_off = *move & MOVE_ALL;
3177  *type = CFAPI_MOVETYPE;
3178  break;
3179 
3181  move = va_arg(args, MoveType *);
3182  op->move_type = *move & MOVE_ALL;
3184  *type = CFAPI_MOVETYPE;
3185  break;
3186 
3187  default:
3188  break;
3189  }
3190  }
3191  va_end(args);
3192 }
3193 
3200 static void cfapi_object_apply_below(int *type, ...) {
3201  va_list args;
3202  object *applier;
3203 
3204  va_start(args, type);
3205 
3206  applier = va_arg(args, object *);
3207 
3208  va_end(args);
3209 
3210  apply_by_living_below(applier);
3211  *type = CFAPI_NONE;
3212 }
3213 
3220 static void cfapi_object_apply(int *type, ...) {
3221  va_list args;
3222  object *applied;
3223  object *applier;
3224  int aflags;
3225  int *ret;
3226 
3227  va_start(args, type);
3228 
3229  applier = va_arg(args, object *);
3230  applied = va_arg(args, object *);
3231  aflags = va_arg(args, int);
3232  ret = va_arg(args, int *);
3233 
3234  va_end(args);
3235 
3236  *type = CFAPI_INT;
3237  *ret = apply_manual(applier, applied, aflags);
3238 }
3239 
3245 static void cfapi_object_identify(int *type, ...) {
3246  va_list args;
3247  object *op, **result;
3248 
3249  va_start(args, type);
3250 
3251  op = va_arg(args, object *);
3252  result = va_arg(args, object **);
3253 
3254  va_end(args);
3255 
3256  (*result) = identify(op);
3257  *type = CFAPI_POBJECT;
3258 }
3259 
3265 static void cfapi_object_describe(int *type, ...) {
3266  va_list args;
3267  object *op;
3268  object *owner;
3269  char *desc, *final;
3270  int size;
3271 
3272  va_start(args, type);
3273 
3274  op = va_arg(args, object *);
3275  owner = va_arg(args, object *);
3276  desc = va_arg(args, char *);
3277  size = va_arg(args, int);
3278  va_end(args);
3279 
3280  *type = CFAPI_STRING;
3281  final = stringbuffer_finish(describe_item(op, owner, 0, NULL));
3282  strncpy(desc, final, size);
3283  desc[size - 1] = '\0';
3284  free(final);
3285 }
3286 
3287 static void cfapi_object_drain(int *type, ...) {
3288  va_list args;
3289 
3290  object *op;
3291  int ds;
3292 
3293  va_start(args, type);
3294 
3295  op = va_arg(args, object *);
3296  ds = va_arg(args, int);
3297 
3298  va_end(args);
3299 
3300  drain_specific_stat(op, ds);
3301 
3302  *type = CFAPI_NONE;
3303 }
3304 
3305 static void cfapi_object_remove_depletion(int *type, ...) {
3306  va_list args;
3307 
3308  object *op;
3309  int level, *result;
3310 
3311  va_start(args, type);
3312 
3313  op = va_arg(args, object *);
3314  level = va_arg(args, int);
3315  result = va_arg(args, int*);
3316 
3317  va_end(args);
3318 
3319  *result = remove_depletion(op, level);
3320 
3321  *type = CFAPI_INT;
3322 }
3323 
3324 static void cfapi_object_fix(int *type, ...) {
3325  va_list args;
3326  object *op;
3327 
3328  va_start(args, type);
3329 
3330  op = va_arg(args, object *);
3331 
3332  va_end(args);
3333 
3334  fix_object(op);
3335 
3336  *type = CFAPI_NONE;
3337 }
3338 
3340 static void cfapi_object_give_skill(int *type, ...) {
3341  va_list args;
3342 
3343  object *op;
3344  char *skillname;
3345 
3346  va_start(args, type);
3347 
3348  op = va_arg(args, object *);
3349  skillname = va_arg(args, char *);
3350 
3351  va_end(args);
3352 
3353  *type = CFAPI_POBJECT;
3354  give_skill_by_name(op, skillname);
3355 }
3356 
3357 static void cfapi_object_transmute(int *type, ...) {
3358  va_list args;
3359 
3360  object *op;
3361  object *chg;
3362 
3363  va_start(args, type);
3364 
3365  op = va_arg(args, object *);
3366  chg = va_arg(args, object *);
3367 
3368  va_end(args);
3369 
3370  transmute_materialname(op, chg);
3371  *type = CFAPI_NONE;
3372 }
3373 
3374 static void cfapi_object_remove(int *type, ...) {
3375  va_list args;
3376  object *op;
3377 
3378  va_start(args, type);
3379 
3380  op = va_arg(args, object *);
3381 
3382  if (QUERY_FLAG(op, FLAG_REMOVED)) {
3383  LOG(llevError, "Plugin trying to remove removed object %s\n", op->name);
3384  va_end(args);
3385  *type = CFAPI_NONE;
3386  return;
3387  }
3388 
3389  va_end(args);
3390 
3391  object_remove(op);
3392  *type = CFAPI_NONE;
3393 }
3394 
3395 static void cfapi_object_delete(int *type, ...) {
3396  va_list args;
3397  object *op;
3398 
3399  va_start(args, type);
3400 
3401  op = va_arg(args, object *);
3402 
3403  if (QUERY_FLAG(op, FLAG_FREED) || !QUERY_FLAG(op, FLAG_REMOVED)) {
3404  LOG(llevError, "Plugin trying to free freed/non removed object %s\n", op->name);
3405  *type = CFAPI_NONE;
3406  va_end(args);
3407  return;
3408  }
3409 
3410  va_end(args);
3411 
3413 
3414  *type = CFAPI_NONE;
3415 }
3416 
3422 static void cfapi_object_clone(int *type, ...) {
3423  va_list args;
3424  object *op;
3425  int kind;
3426  object **robj;
3427 
3428  va_start(args, type);
3429 
3430  op = va_arg(args, object *);
3431  kind = va_arg(args, int);
3432  robj = va_arg(args, object **);
3433 
3434  va_end(args);
3435 
3436  if (kind == 0) {
3437  *type = CFAPI_POBJECT;
3438  *robj = object_create_clone(op);
3439  } else {
3440  object *tmp;
3441  tmp = object_new();
3442  object_copy(op, tmp);
3443  *type = CFAPI_POBJECT;
3444  *robj = tmp;
3445  }
3446  return;
3447 }
3448 
3454 static void cfapi_object_create(int *type, ...) {
3455  va_list args;
3456  int ival;
3457  object **robj;
3458  va_start(args, type);
3459  ival = va_arg(args, int);
3460 
3461  *type = CFAPI_POBJECT;
3462  switch (ival) {
3463  case 0:
3464  robj = va_arg(args, object **);
3465  *robj = object_new();
3466  break;
3467 
3468  case 1: { /* Named object. Nearly the old plugin behavior, but we don't add artifact suffixes */
3469  const char *sval;
3470  archetype *at;
3471 
3472  sval = va_arg(args, const char *);
3473  robj = va_arg(args, object **);
3474  va_end(args);
3475 
3476  at = try_find_archetype(sval);
3477  if (!at)
3478  at = find_archetype_by_object_name(sval);
3479  if (at) {
3480  *robj = object_create_arch(at);
3481  } else
3482  *robj = NULL;
3483  }
3484  break;
3485 
3486  default:
3487  *type = CFAPI_NONE;
3488  break;
3489  }
3490  va_end(args);
3491 }
3492 
3493 static void cfapi_object_insert(int *type, ...) {
3494  va_list args;
3495  object *op;
3496  object *orig;
3497  mapstruct *map;
3498  int flag, x, y;
3499  int itype;
3500  object **robj;
3501 
3502  va_start(args, type);
3503 
3504  op = va_arg(args, object *);
3505  if (!op) {
3506  LOG(llevError, "cfapi_object_insert: called with NULL object!\n");
3507  va_end(args);
3508  return;
3509  }
3510  if (QUERY_FLAG(op, FLAG_FREED)) {
3511  LOG(llevError, "cfapi_object_insert: called with FREED object!\n");
3512  va_end(args);
3513  return;
3514  }
3515  if (!QUERY_FLAG(op, FLAG_REMOVED)) {
3516  LOG(llevError, "cfapi_object_insert: called with not removed object %s!\n", op->name);
3517  object_remove(op);
3518  }
3519  itype = va_arg(args, int);
3520 
3521  switch (itype) {
3522  case 0:
3523  map = va_arg(args, mapstruct *);
3524  orig = va_arg(args, object *);
3525  flag = va_arg(args, int);
3526  x = va_arg(args, int);
3527  y = va_arg(args, int);
3528  robj = va_arg(args, object **);
3529  if (!map) {
3530  LOG(llevError, "cfapi_object_insert (0): called with NULL map, object %s!\n", op->name);
3532  *robj = NULL;
3533  } else
3534  *robj = object_insert_in_map_at(op, map, orig, flag, x, y);
3535  *type = CFAPI_POBJECT;
3536  break;
3537 
3538  case 1:
3539  map = va_arg(args, mapstruct *);
3540  orig = va_arg(args, object *);
3541  flag = va_arg(args, int);
3542  robj = va_arg(args, object **);
3543  if (!map) {
3544  LOG(llevError, "cfapi_object_insert (1): called with NULL map, object %s!\n", op->name);
3546  *robj = NULL;
3547  } else
3548  *robj = object_insert_in_map_at(op, map, orig, flag, op->x, op->y);
3549  *type = CFAPI_POBJECT;
3550  break;
3551 
3552  case 2:
3553  map = va_arg(args, mapstruct *);
3554  orig = va_arg(args, object *);
3555  flag = va_arg(args, int);
3556  x = va_arg(args, int);
3557  y = va_arg(args, int);
3558  robj = va_arg(args, object **);
3559  if (!map) {
3560  LOG(llevError, "cfapi_object_insert (0): called with NULL map, object %s!\n", op->name);
3562  *robj = NULL;
3563  } else {
3564  int dir = object_find_free_spot(op, map, x, y, 0, SIZEOFFREE);
3565  if (dir != -1) {
3566  *robj = object_insert_in_map_at(op, map, orig, flag, x + freearr_x[dir], y + freearr_y[dir]);
3567  } else {
3569  *robj = NULL;
3570  }
3571  }
3572  *type = CFAPI_POBJECT;
3573  break;
3574 
3575  case 3:
3576  orig = va_arg(args, object *);
3577  robj = va_arg(args, object **);
3578  if (!orig) {
3579  LOG(llevError, "cfapi_object_insert (3): called with NULL orig, object %s!\n", op->name);
3581  *robj = NULL;
3582  } else
3583  *robj = object_insert_in_ob(op, orig);
3584  *type = CFAPI_POBJECT;
3585  break;
3586 
3587  default:
3588  LOG(llevError, "cfapi_object_insert (1): called with itype %d which is not valid, object %s!\n", itype, op->name);
3590  *type = CFAPI_NONE;
3591  break;
3592  }
3593 
3594  va_end(args);
3595 }
3601 static void cfapi_object_split(int *type, ...) {
3602  va_list args;
3603 
3604  int nr, size;
3605  object *op;
3606  char *buf;
3607  object **split;
3608 
3609  va_start(args, type);
3610 
3611  op = va_arg(args, object *);
3612  nr = va_arg(args, int);
3613  buf = va_arg(args, char *);
3614  size = va_arg(args, int);
3615  split = va_arg(args, object **);
3616  va_end(args);
3617 
3618  *split = object_split(op, nr, buf, size);
3619  if (*split != NULL)
3620  {
3621  *type = CFAPI_POBJECT;
3622  }
3623  else
3624  {
3625  *type = CFAPI_NONE;
3626  }
3627 }
3628 
3634 static void cfapi_object_merge(int *type, ...) {
3635  va_list args;
3636  object *op;
3637  object *op2;
3638  object **merge;
3639 
3640  va_start(args, type);
3641 
3642  op = va_arg(args, object *);
3643  op2 = va_arg(args, object *);
3644  merge = va_arg(args, object **);
3645 
3646  va_end(args);
3647 
3648  *type = CFAPI_POBJECT;
3649  *merge = object_merge(op, op2);
3650 }
3651 
3657 static void cfapi_object_distance(int *type, ...) {
3658  va_list args;
3659  object *op;
3660  object *op2;
3661  int *rint;
3662  va_start(args, type);
3663 
3664  op = va_arg(args, object *);
3665  op2 = va_arg(args, object *);
3666  rint = va_arg(args, int *);
3667 
3668  va_end(args);
3669 
3670  *type = CFAPI_INT;
3671  *rint = object_distance(op, op2);
3672 }
3678 static void cfapi_object_update(int *type, ...) {
3679  va_list args;
3680  int action;
3681  object *op;
3682  va_start(args, type);
3683 
3684  op = va_arg(args, object *);
3685  action = va_arg(args, int);
3686 
3687  va_end(args);
3688 
3689  object_update(op, action);
3690  *type = CFAPI_NONE;
3691 }
3692 
3698 static void cfapi_object_clear(int *type, ...) {
3699  va_list args;
3700  object *op;
3701  va_start(args, type);
3702 
3703  op = va_arg(args, object *);
3704 
3705  va_end(args);
3706 
3707  object_clear(op);
3708  *type = CFAPI_NONE;
3709 }
3710 
3716 static void cfapi_object_reset(int *type, ...) {
3717  va_list args;
3718  object *op;
3719 
3720  va_start(args, type);
3721 
3722  op = va_arg(args, object *);
3723 
3724  va_end(args);
3725 
3726  object_reset(op);
3727  *type = CFAPI_NONE;
3728 }
3729 
3730 static void cfapi_object_clean_object(int *type, ...) {
3731  va_list args;
3732  object *op;
3733 
3734  va_start(args, type);
3735  op = va_arg(args, object *);
3736  clean_object(op);
3737  va_end(args);
3738  *type = CFAPI_NONE;
3739 }
3740 
3741 static void cfapi_object_on_same_map(int *type, ...) {
3742  va_list args;
3743  object *op1;
3744  object *op2;
3745  int *rint;
3746 
3747  va_start(args, type);
3748  op1 = va_arg(args, object *);
3749  op2 = va_arg(args, object *);
3750  rint = va_arg(args, int *);
3751  va_end(args);
3752 
3753  *type = CFAPI_INT;
3754  *rint = on_same_map(op1, op2);
3755 }
3756 
3757 static void cfapi_object_spring_trap(int *type, ...) {
3758  object *trap;
3759  object *victim;
3760  va_list args;
3761 
3762  va_start(args, type);
3763  trap = va_arg(args, object *);
3764  victim = va_arg(args, object *);
3765  va_end(args);
3766 
3767  spring_trap(trap, victim);
3768  *type = CFAPI_NONE;
3769 }
3770 
3776 static void cfapi_object_check_trigger(int *type, ...) {
3777  object *op;
3778  object *cause;
3779  va_list args;
3780  int *rint;
3781 
3782  va_start(args, type);
3783  op = va_arg(args, object *);
3784  cause = va_arg(args, object *);
3785  rint = va_arg(args, int *);
3786  va_end(args);
3787 
3788  *rint = check_trigger(op, cause);
3789  *type = CFAPI_INT;
3790 }
3791 
3803 static void cfapi_map_trigger_connected(int *type, ...) {
3804  objectlink *ol;
3805  object *cause;
3806  int state;
3807  va_list args;
3808 
3809  va_start(args, type);
3810  ol = va_arg(args, objectlink *);
3811  cause = va_arg(args, object *);
3812  state = va_arg(args, int);
3813  va_end(args);
3814  trigger_connected(ol, cause, state);
3815  *type = CFAPI_NONE;
3816 }
3817 
3823 static void cfapi_object_query_money(int *type, ...) {
3824  object *op;
3825  va_list args;
3826  int *rint;
3827 
3828  va_start(args, type);
3829  op = va_arg(args, object *);
3830  rint = va_arg(args, int *);
3831  va_end(args);
3832 
3833  *rint = query_money(op);
3834  *type = CFAPI_INT;
3835 }
3836 
3842 static void cfapi_object_cast(int *type, ...) {
3843  object *op;
3844  object *sp;
3845  int dir;
3846  char *str;
3847  object *caster;
3848  va_list args;
3849  int *rint;
3850 
3851  va_start(args, type);
3852  op = va_arg(args, object *);
3853  caster = va_arg(args, object *);
3854  dir = va_arg(args, int);
3855  sp = va_arg(args, object *);
3856  str = va_arg(args, char *);
3857  rint = va_arg(args, int *);
3858  va_end(args);
3859 
3860  *type = CFAPI_INT;
3861 
3862  if (!op->map) {
3863  *rint = -1;
3864  return;
3865  }
3866 
3867  *rint = cast_spell(op, caster, dir, sp, str);
3868 }
3869 
3870 static void cfapi_object_learn_spell(int *type, ...) {
3871  object *op;
3872  object *sp;
3873  int prayer;
3874  va_list args;
3875 
3876  va_start(args, type);
3877  op = va_arg(args, object *);
3878  sp = va_arg(args, object *);
3879  prayer = va_arg(args, int);
3880  va_end(args);
3881  do_learn_spell(op, sp, prayer);
3882  *type = CFAPI_NONE;
3883 }
3884 
3885 static void cfapi_object_forget_spell(int *type, ...) {
3886  object *op;
3887  object *sp;
3888  va_list args;
3889  char name[MAX_BUF];
3890 
3891  va_start(args, type);
3892  op = va_arg(args, object *);
3893  sp = va_arg(args, object *);
3894  va_end(args);
3895  query_name(sp, name, MAX_BUF);
3896  do_forget_spell(op, name);
3897  *type = CFAPI_NONE;
3898 }
3899 
3905 static void cfapi_object_check_spell(int *type, ...) {
3906  object *op;
3907  char *spellname;
3908  va_list args;
3909  object **robj;
3910 
3911  va_start(args, type);
3912  op = va_arg(args, object *);
3913  spellname = va_arg(args, char *);
3914  robj = va_arg(args, object **);
3915  va_end(args);
3916  *robj = check_spell_known(op, spellname);
3917  *type = CFAPI_POBJECT;
3918 }
3919 
3925 static void cfapi_object_pay_amount(int *type, ...) {
3926  object *op;
3927  uint64_t amount;
3928  va_list args;
3929  int *rint;
3930 
3931  va_start(args, type);
3932  op = va_arg(args, object *);
3933  amount = va_arg(args, uint64_t);
3934  rint = va_arg(args, int *);
3935  va_end(args);
3936 
3937  *rint = pay_for_amount(amount, op);
3938  *type = CFAPI_INT;
3939 }
3940 
3946 static void cfapi_object_pay_item(int *type, ...) {
3947  object *op;
3948  object *tobuy;
3949  int *rint;
3950 
3951  va_list args;
3952 
3953  va_start(args, type);
3954  tobuy = va_arg(args, object *);
3955  op = va_arg(args, object *);
3956  rint = va_arg(args, int *);
3957  va_end(args);
3958 
3959  *rint = pay_for_item(tobuy, op);
3960  *type = CFAPI_INT;
3961 }
3962 
3970 static void cfapi_object_transfer(int *type, ...) {
3971  object *op;
3972  object *originator;
3973  int x, y, randompos, ttype, flag;
3974  va_list args;
3975  mapstruct *map;
3976  int *rint;
3977  object **robj;
3978 
3979  va_start(args, type);
3980  op = va_arg(args, object *);
3981  ttype = va_arg(args, int);
3982  switch (ttype) {
3983  case 0:
3984  x = va_arg(args, int);
3985  y = va_arg(args, int);
3986  randompos = va_arg(args, int);
3987  originator = va_arg(args, object *);
3988  rint = va_arg(args, int *);
3989  va_end(args);
3990 
3991  *rint = transfer_ob(op, x, y, randompos, originator);
3992  *type = CFAPI_INT;
3993  return;
3994  break;
3995 
3996  case 1:
3997  map = va_arg(args, mapstruct *);
3998  originator = va_arg(args, object *);
3999  flag = va_arg(args, int);
4000  x = va_arg(args, int);
4001  y = va_arg(args, int);
4002  robj = va_arg(args, object **);
4003  va_end(args);
4004  if (x < 0 || y < 0) {
4005  x = map->enter_x;
4006  y = map->enter_y;
4007  }
4008  *robj = object_insert_in_map_at(op, map, originator, flag, x, y);
4009  *type = CFAPI_POBJECT;
4010  return;
4011  break;
4012 
4013  case 2:
4014  x = va_arg(args, int);
4015  y = va_arg(args, int);
4016  rint = va_arg(args, int *);
4017  va_end(args);
4018 
4019  *rint = move_to(op, x, y);
4020  *type = CFAPI_INT;
4021  return;
4022 
4023  default:
4024  va_end(args);
4025  *type = CFAPI_NONE;
4026  return;
4027  break;
4028  }
4029 }
4030 
4034 static void cfapi_object_find_archetype_inside(int *type, ...) {
4035  object *op;
4036  char *str;
4037  va_list args;
4038  object **robj;
4039 
4040  *type = CFAPI_POBJECT;
4041  va_start(args, type);
4042  op = va_arg(args, object *);
4043 
4044  str = va_arg(args, char *);
4045  robj = va_arg(args, object **);
4046  *robj = arch_present_in_ob(try_find_archetype(str), op);
4047  if (*robj == NULL) {
4048  char name[MAX_BUF];
4049 
4050  /* Search by name or slaying instead */
4051  FOR_INV_PREPARE(op, tmp) {
4052  query_name(tmp, name, MAX_BUF);
4053  if (!strncmp(name, str, strlen(str)))
4054  *robj = tmp;
4055  if (!strncmp(tmp->name, str, strlen(str)))
4056  *robj = tmp;
4057  if (tmp->slaying && !strcmp(tmp->slaying, str))
4058  *robj = tmp;
4059  if (*robj != NULL)
4060  break;
4061  } FOR_INV_FINISH();
4062  }
4063  va_end(args);
4064 }
4065 
4066 static void cfapi_object_find_by_arch_name(int *type, ...) {
4067  const object *who;
4068  object **result;
4069  const char *name;
4070  va_list args;
4071 
4072  va_start(args, type);
4073  who = va_arg(args, const object *);
4074  name = va_arg(args, const char *);
4075  result = va_arg(args, object **);
4076  va_end(args);
4077  *type = CFAPI_POBJECT;
4078 
4079  *result = object_find_by_arch_name(who, name);
4080 }
4081 
4082 static void cfapi_object_find_by_name(int *type, ...) {
4083  const object *who;
4084  object **result;
4085  const char *name;
4086  va_list args;
4087 
4088  va_start(args, type);
4089  who = va_arg(args, const object *);
4090  name = va_arg(args, const char *);
4091  result = va_arg(args, object **);
4092  va_end(args);
4093  *type = CFAPI_POBJECT;
4094 
4095  *result = object_find_by_name(who, name);
4096 }
4097 
4103 static void cfapi_object_drop(int *type, ...) {
4104  object *op;
4105  object *author;
4106  va_list args;
4107 
4108  va_start(args, type);
4109  op = va_arg(args, object *);
4110  author = va_arg(args, object *);
4111  va_end(args);
4112  *type = CFAPI_NONE;
4113 
4114  if (QUERY_FLAG(op, FLAG_NO_DROP))
4115  return;
4116  drop(author, op);
4117 
4118  if (author->type == PLAYER) {
4119  author->contr->count = 0;
4120  author->contr->socket.update_look = 1;
4121  }
4122 }
4123 
4127 static void cfapi_object_change_abil(int *type, ...) {
4128  object *op, *tmp;
4129  int *rint;
4130  va_list args;
4131 
4132  va_start(args, type);
4133  op = va_arg(args, object *);
4134  tmp = va_arg(args, object *);
4135  rint = va_arg(args, int *);
4136  va_end(args);
4137 
4138  *type = CFAPI_INT;
4139  *rint = change_abil(op, tmp);
4140 }
4141 
4142 static void cfapi_object_say(int *type, ...) {
4143  object *op;
4144  char *msg;
4145  va_list args;
4146  int *rint;
4147  char empty[] = "";
4148 
4149  va_start(args, type);
4150  op = va_arg(args, object *);
4151  msg = va_arg(args, char *);
4152  rint = va_arg(args, int *);
4153  va_end(args);
4154 
4155  if (op->type == PLAYER) {
4156  command_say(op, msg == NULL ? empty : msg);
4157  } else {
4158  monster_npc_say(op, msg);
4159  }
4160  *rint = 0;
4161  *type = CFAPI_INT;
4162 }
4163 
4164 /* PLAYER SUBCLASS */
4165 
4171 static void cfapi_player_find(int *type, ...) {
4172  va_list args;
4173  char *sval;
4174  player **rpl;
4175  va_start(args, type);
4176 
4177  sval = va_arg(args, char *);
4178  rpl = va_arg(args, player **);
4179  va_end(args);
4180 
4181  *rpl = find_player_partial_name(sval);
4182 
4183  *type = CFAPI_PPLAYER;
4184 }
4185 
4186 static void cfapi_player_message(int *type, ...) {
4187  va_list args;
4188  int flags;
4189  int pri;
4190  object *pl;
4191  char *buf;
4192 
4193  va_start(args, type);
4194 
4195  flags = va_arg(args, int);
4196  pri = va_arg(args, int);
4197  pl = va_arg(args, object *);
4198  buf = va_arg(args, char *);
4199  va_end(args);
4200 
4201  draw_ext_info(flags, pri, pl, MSG_TYPE_MISC, MSG_SUBTYPE_NONE,
4202  buf);
4203  *type = CFAPI_NONE;
4204 }
4205 
4211 static void cfapi_object_change_exp(int *type, ...) {
4212  va_list args;
4213  int flag;
4214  object *ob;
4215  const char *skill;
4216  int64_t exp;
4217 
4218  va_start(args, type);
4219  ob = va_arg(args, object *);
4220  exp = va_arg(args, int64_t);
4221  skill = va_arg(args, const char *);
4222  flag = va_arg(args, int);
4223  va_end(args);
4224 
4225  *type = CFAPI_NONE;
4226  change_exp(ob, exp, skill, flag);
4227 }
4228 
4234 static void cfapi_player_can_pay(int *type, ...) {
4235  va_list args;
4236  object *pl;
4237  int *rint;
4238 
4239  va_start(args, type);
4240  pl = va_arg(args, object *);
4241  rint = va_arg(args, int *);
4242  va_end(args);
4243 
4244  *rint = can_pay(pl);
4245  *type = CFAPI_INT;
4246 }
4247 
4253 static void cfapi_player_knowledge(int *type, ...) {
4254  va_list args;
4255  object *pl;
4256  int *rint, what;
4257  const char *knowledge;
4258 
4259  va_start(args, type);
4260  what = va_arg(args, int);
4261 
4262  switch(what)
4263  {
4264  case 1:
4265  pl = va_arg(args, object *);
4266  knowledge = va_arg(args, const char *);
4267  rint = va_arg(args, int *);
4268 
4269  *type = CFAPI_INT;
4270 
4271  if (pl->contr == NULL) {
4272  LOG(llevError, "cfapi_player_knowledge: 'has' called for non player object %s", pl->name);
4273  *rint = 0;
4274  va_end(args);
4275  return;
4276  }
4277 
4278  *rint = knowledge_player_knows(pl->contr, knowledge);
4279  break;
4280 
4281  case 2:
4282  pl = va_arg(args, object *);
4283  knowledge = va_arg(args, const char *);
4284  *type = CFAPI_NONE;
4285  if (pl->contr != NULL)
4286  knowledge_give(pl->contr, knowledge, NULL);
4287 
4288  break;
4289 
4290  default:
4291  LOG(llevError, "cfapi_player_knowledge: invalid what %d", what);
4292  }
4293 
4294  va_end(args);
4295 }
4296 
4302 static void cfapi_object_teleport(int *type, ...) {
4303  mapstruct *map;
4304  int x, y;
4305  object *who;
4306  int *res;
4307  va_list args;
4308 
4309  va_start(args, type);
4310  who = va_arg(args, object *);
4311  map = va_arg(args, mapstruct *);
4312  x = va_arg(args, int);
4313  y = va_arg(args, int);
4314  res = va_arg(args, int *);
4315  *type = CFAPI_INT;
4316 
4317  if (!out_of_map(map, x, y)) {
4318  int k;
4319  k = object_find_first_free_spot(who, map, x, y);
4320  if (k == -1) {
4321  *res = 1;
4322  va_end(args);
4323  return;
4324  }
4325 
4326  if (!QUERY_FLAG(who, FLAG_REMOVED)) {
4327  object_remove(who);
4328  }
4329 
4330  object_insert_in_map_at(who, map, NULL, 0, x, y);
4331  if (who->type == PLAYER) {
4332  map_newmap_cmd(&who->contr->socket);
4334  }
4335  *res = 0;
4336  }
4337 
4338  va_end(args);
4339 }
4340 
4341 static void cfapi_object_pickup(int *type, ...) {
4342  object *who;
4343  object *what;
4344  va_list args;
4345 
4346  va_start(args, type);
4347  who = va_arg(args, object *);
4348  what = va_arg(args, object *);
4349  va_end(args);
4350 
4351  pick_up(who, what);
4352  *type = CFAPI_NONE;
4353 }
4354 
4355 /* Archetype-related functions */
4356 static void cfapi_archetype_get_property(int *type, ...) {
4357  int prop;
4358  archetype *arch;
4359  va_list args;
4360  sstring *rsstring;
4361  archetype **rarch;
4362  object **robject;
4363 
4364  va_start(args, type);
4365  arch = va_arg(args, archetype *);
4366  prop = va_arg(args, int);
4367  switch (prop) {
4368  case CFAPI_ARCH_PROP_NAME:
4369  *type = CFAPI_SSTRING;
4370  rsstring = va_arg(args, sstring *);
4371  *rsstring = arch->name;
4372  break;
4373 
4374  case CFAPI_ARCH_PROP_NEXT:
4375  *type = CFAPI_PARCH;
4376  rarch = va_arg(args, archetype **);
4377  *rarch = arch ? arch->next : first_archetype;
4378  break;
4379 
4380  case CFAPI_ARCH_PROP_HEAD:
4381  *type = CFAPI_PARCH;
4382  rarch = va_arg(args, archetype **);
4383  *rarch = arch->head;
4384  break;
4385 
4386  case CFAPI_ARCH_PROP_MORE:
4387  *type = CFAPI_PARCH;
4388  rarch = va_arg(args, archetype **);
4389  *rarch = arch->more;
4390  break;
4391 
4392  case CFAPI_ARCH_PROP_CLONE:
4393  *type = CFAPI_POBJECT;
4394  robject = va_arg(args, object **);
4395  *robject = &arch->clone;
4396  break;
4397 
4398  default:
4399  *type = CFAPI_NONE;
4400  break;
4401  }
4402  va_end(args);
4403 }
4404 
4411 static void cfapi_party_get_property(int *type, ...) {
4412  partylist *party;
4413  int prop;
4414  va_list args;
4415  object *obarg;
4416  sstring *rsstring;
4417  player **rplayer;
4418  partylist **rparty;
4419 
4420  va_start(args, type);
4421  party = va_arg(args, partylist *);
4422  prop = va_arg(args, int);
4423  switch (prop) {
4424  case CFAPI_PARTY_PROP_NAME:
4425  rsstring = va_arg(args, sstring *);
4426  *rsstring = party->partyname;
4427  *type = CFAPI_SSTRING;
4428  break;
4429 
4430  case CFAPI_PARTY_PROP_NEXT:
4431  rparty = va_arg(args, partylist **);
4432  *rparty = (party ? party_get_next(party) : party_get_first());
4433  *type = CFAPI_PPARTY;
4434  break;
4435 
4437  rsstring = va_arg(args, sstring *);
4438  *rsstring = party_get_password(party);
4439  *type = CFAPI_SSTRING;
4440  break;
4441 
4443  *type = CFAPI_PPLAYER;
4444  obarg = va_arg(args, object *);
4445  rplayer = va_arg(args, player **);
4446  *rplayer = (obarg ? obarg->contr : first_player);
4447  for (; *rplayer != NULL; (*rplayer) = (*rplayer)->next)
4448  if ((*rplayer)->ob->contr->party == party) {
4449  break;
4450  }
4451  break;
4452 
4453  default:
4454  *type = CFAPI_NONE;
4455  break;
4456  }
4457  va_end(args);
4458 }
4459 
4466 static void cfapi_region_get_property(int *type, ...) {
4467  region *reg;
4468  int prop, *rint;
4469  va_list args;
4471  sstring *rsstring;
4472  region **rregion;
4473 
4474  va_start(args, type);
4475  reg = va_arg(args, region *);
4476  prop = va_arg(args, int);
4477  switch (prop) {
4479  rsstring = va_arg(args, sstring *);
4480  *rsstring = reg->name;
4481  *type = CFAPI_SSTRING;
4482  break;
4483 
4485  rregion = va_arg(args, region **);
4486  *rregion = (reg ? reg->next : first_region);
4487  *type = CFAPI_PREGION;
4488  break;
4489 
4491  rregion = va_arg(args, region **);
4492  *rregion = reg->parent;
4493  *type = CFAPI_PREGION;
4494  break;
4495 
4497  rsstring = va_arg(args, sstring *);
4498  *rsstring = reg->longname;
4499  *type = CFAPI_SSTRING;
4500  break;
4501 
4503  rsstring = va_arg(args, sstring *);
4504  *rsstring = reg->msg;
4505  *type = CFAPI_SSTRING;
4506  break;
4507 
4510  rint = va_arg(args, int*);
4511  *rint = (prop == CFAPI_REGION_PROP_JAIL_X ? reg->jailx : reg->jaily);
4512  *type = CFAPI_INT;
4513  break;
4514 
4516  rsstring = va_arg(args, sstring *);
4517  *rsstring = reg->jailmap;
4518  *type = CFAPI_SSTRING;
4519  break;
4520 
4521  default:
4522  *type = CFAPI_NONE;
4523  break;
4524  }
4525  va_end(args);
4526 }
4527 
4539 static void cfapi_friendlylist_get_next(int *type, ...) {
4540  object *ob;
4541  va_list args;
4542  objectlink *link;
4543  object **robject;
4544 
4545  va_start(args, type);
4546  ob = va_arg(args, object *);
4547  robject = va_arg(args, object **);
4548  va_end(args);
4549 
4550  *type = CFAPI_POBJECT;
4551  *robject = NULL;
4552 
4553  if (ob) {
4554  for (link = first_friendly_object; link; link = link->next) {
4555  if (ob == link->ob) {
4556  if (link->next) {
4557  *robject = link->next->ob;
4558  return;
4559  } else {
4560  return;
4561  }
4562  }
4563  }
4564  return;
4565  }
4566 
4568  *robject = first_friendly_object->ob;
4569 }
4570 
4571 /*
4572  * Random-map related stuff.
4573  */
4574 
4581 static void cfapi_set_random_map_variable(int *type, ...) {
4582  va_list args;
4583  RMParms *rp;
4584  const char *buf;
4585  int *ret;
4586 
4587  va_start(args, type);
4588  rp = va_arg(args, RMParms *);
4589  buf = va_arg(args, const char *);
4590  ret = va_arg(args, int *);
4591  va_end(args);
4592 
4593  *ret = set_random_map_variable(rp, buf);
4594  *type = CFAPI_INT;
4595 }
4596 
4603 static void cfapi_generate_random_map(int *type, ...) {
4604  va_list args;
4605  const char *name;
4606  RMParms *rp;
4607  char **use_layout;
4608  mapstruct **ret;
4609 
4610  va_start(args, type);
4611  name = va_arg(args, const char *);
4612  rp = va_arg(args, RMParms *);
4613  use_layout = va_arg(args, char **);
4614  ret = va_arg(args, mapstruct **);
4615  va_end(args);
4616 
4617  *ret = generate_random_map(name, rp, use_layout);
4618 }
4619 
4620 static void cfapi_object_user_event(int *type, ...) {
4621  object *op;
4622  object *activator;
4623  object *third;
4624  const char *message;
4625  int fix;
4626  int *ret;
4627  va_list args;
4628 
4629  va_start(args, type);
4630  op = va_arg(args, object *);
4631  activator = va_arg(args, object *);
4632  third = va_arg(args, object *);
4633  message = va_arg(args, const char *);
4634  fix = va_arg(args, int);
4635  ret = va_arg(args, int *);
4636  va_end(args);
4637 
4638  *ret = user_event(op, activator, third, message, fix);
4639  *type = CFAPI_INT;
4640 }
4641 
4644 static void cfapi_player_quest(int *type, ...) {
4645  int op;
4646  va_list args;
4647  object *player;
4648  sstring code;
4649 
4650  va_start(args, type);
4651  op = va_arg(args, int);
4652  player = va_arg(args, object *);
4653  code = va_arg(args, sstring);
4654 
4655  if (player->contr == NULL) {
4656  LOG(llevError, "cfapi_player_quest called with non player object %s!\n", player->name);
4657  va_end(args);
4658  /* crash/quit? */
4659  return;
4660  }
4661 
4662  switch(op) {
4663  case CFAPI_PLAYER_QUEST_START: {
4664  int state = va_arg(args, int);
4665  quest_start(player->contr, code, state);
4666  *type = CFAPI_NONE;
4667  break;
4668  }
4670  int *ret = va_arg(args, int *);
4671  *ret = quest_get_player_state(player->contr, code);
4672  *type = CFAPI_INT;
4673  break;
4674  }
4676  int state = va_arg(args, int);
4677  quest_set_player_state(player->contr, code, state);
4678  *type = CFAPI_NONE;
4679  break;
4680  }
4682  int *ret = va_arg(args, int*);
4683  *ret = quest_was_completed(player->contr, code);
4684  *type = CFAPI_INT;
4685  break;
4686  }
4687  default:
4688  LOG(llevError, "invalid quest type: %d\n", op);
4689  *type = CFAPI_NONE;
4690  }
4691 
4692  va_end(args);
4693 }
4694 
4695 /*****************************************************************************/
4696 /* NEW PLUGIN STUFF ENDS HERE */
4697 /*****************************************************************************/
4698 
4699 
4712  int i;
4713  crossfire_plugin *cp;
4714 
4715  assert(cmd != NULL);
4716  assert(command != NULL);
4717 
4718  if (plugins_list == NULL)
4719  return NULL;
4720 
4721  for (cp = plugins_list; cp != NULL; cp = cp->next) {
4722  if (cp->propfunc(&i, "command?", cmd, command) != NULL)
4723  return command;
4724  }
4725  return NULL;
4726 }
4727 
4732 void initPlugins(void) {
4733  struct dirent *currentfile;
4734  DIR *plugdir;
4735  size_t l;
4736  char buf[MAX_BUF];
4737 
4738  snprintf(buf, sizeof(buf), "%s/plugins/", LIBDIR);
4739  LOG(llevDebug, "plugins: loading from %s\n", buf);
4740 
4741  plugdir = opendir(buf);
4742  if (plugdir == NULL)
4743  return;
4744 
4745  while ((currentfile = readdir(plugdir)) != NULL) {
4746  l = strlen(currentfile->d_name);
4747  if (l > strlen(PLUGIN_SUFFIX)) {
4749  int ignore = 0;
4750 
4751  if (strcmp(currentfile->d_name+l-strlen(PLUGIN_SUFFIX), PLUGIN_SUFFIX) != 0)
4752  continue;
4753 
4754  while (disable) {
4755  if (strcmp(disable->name, "All") == 0) {
4756  LOG(llevInfo, "plugins: disabling (all) %s\n", currentfile->d_name);
4757  ignore = 1;
4758  break;
4759  }
4760  if (strncmp(disable->name, currentfile->d_name, strlen(disable->name)) == 0 && strlen(currentfile->d_name) == strlen(PLUGIN_SUFFIX) + strlen(disable->name)) {
4761  LOG(llevInfo, "plugins: disabling %s\n", currentfile->d_name);
4762  ignore = 1;
4763  break;
4764  }
4765  disable = disable->next;
4766  }
4767  if (ignore == 0) {
4768  snprintf(buf, sizeof(buf), "%s/plugins/%s", LIBDIR, currentfile->d_name);
4769  LOG(llevInfo, "plugins: loading %s\n", currentfile->d_name);
4770  plugins_init_plugin(buf);
4771  }
4772  }
4773  }
4774 
4775  closedir(plugdir);
4776 }
4777 
4782 void cleanupPlugins(void) {
4783  crossfire_plugin *cp;
4784 
4785  if (!plugins_list)
4786  return;
4787 
4788  for (cp = plugins_list; cp != NULL; ) {
4789  crossfire_plugin *next = cp->next;
4790  if (cp->closefunc)
4791  cp->closefunc();
4792  /* Don't actually unload plugins, it makes backtraces for memory
4793  * debugging (printed at exit) messed up. And it doesn't matter if we
4794  * don't free it here. The OS will do it for us.
4795  */
4796  /* plugins_dlclose(cp->libptr); */
4797  free(cp);
4798  cp = next;
4799  }
4800  plugins_list = NULL;
4801 }
#define CFAPI_OBJECT_PROP_STR
Definition: plugin.h:248
#define CFAPI_OBJECT_PROP_MAP
Definition: plugin.h:179
#define CFAPI_OBJECT_PROP_RUN_AWAY
Definition: plugin.h:225
static void cfapi_object_clear(int *type,...)
Definition: plugins.c:3698
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Definition: main.c:315
int object_distance(const object *ob1, const object *ob2)
Definition: object.c:3599
void spring_trap(object *trap, object *victim)
Definition: rune.c:205
static void cfapi_map_trigger_connected(int *type,...)
Definition: plugins.c:3803
static void copy_message(object *op, const char *msg)
Definition: plugins.c:2523
static void cfapi_set_random_map_variable(int *type,...)
Definition: plugins.c:4581
char path[HUGE_BUF]
Definition: map.h:365
#define CFAPI_OBJECT_PROP_MAGIC
Definition: plugin.h:206
void apply_by_living_below(object *pl)
Definition: apply.c:618
#define CFAPI_PLAYER_QUEST_GET_STATE
Definition: plugin.h:291
#define MSG_TYPE_MISC
Definition: newclient.h:389
#define FLAG_NO_DROP
Definition: define.h:289
int8_t Int
Definition: living.h:36
#define CFAPI_PARTY_PROP_PASSWORD
Definition: plugin.h:322
Definition: player.h:92
int apply_manual(object *op, object *tmp, int aflag)
Definition: apply.c:510
#define CFAPI_OBJECT_PROP_MATERIAL
Definition: plugin.h:204
const char * determine_god(object *op)
Definition: gods.c:106
#define CFAPI_OBJECT_PROP_ANIMATION
Definition: plugin.h:269
mapstruct * generate_random_map(const char *OutFileName, RMParms *RP, char **use_layout)
Definition: random_map.c:74
int8_t ac
Definition: living.h:38
#define CFAPI_OBJECT_PROP_SP
Definition: plugin.h:258
int32_t weight_limit
Definition: object.h:366
#define UP_OBJ_FACE
Definition: object.h:517
#define CFAPI_OBJECT_PROP_CARRYING
Definition: plugin.h:219
MoveType move_type
Definition: object.h:424
#define plugins_dlopen(fname)
Definition: plugin.h:163
#define EVENT_REMOVE
Definition: plugin.h:93
#define CFAPI_OBJECT_PROP_NAME
Definition: plugin.h:181
#define CFAPI_OBJECT_PROP_OB_BELOW
Definition: plugin.h:172
#define CFAPI_PREGION
Definition: plugin.h:117
#define CFAPI_PLAYER_PROP_TITLE
Definition: plugin.h:288
#define EVENT_SHOUT
Definition: plugin.h:94
#define CFAPI_MAP_PROP_NAME
Definition: plugin.h:299
int16_t jaily
Definition: map.h:298
int move_player(object *op, int dir)
Definition: player.c:3014
MoveType move_on
Definition: object.h:427
static void cfapi_object_drain(int *type,...)
Definition: plugins.c:3287
static void cfapi_system_register_global_event(int *type,...)
Definition: plugins.c:851
void quest_start(player *pl, sstring quest_code, int state)
Definition: quest.c:1096
static void cfapi_system_find_animation(int *type,...)
Definition: plugins.c:797
static void cfapi_object_move(int *type,...)
Definition: plugins.c:1626
#define CFAPI_OBJECT_PROP_RACE
Definition: plugin.h:184
object * check_spell_known(object *op, const char *name)
Definition: spell_util.c:435
#define CFAPI_MAP_PROP_ENTER_Y
Definition: plugin.h:308
static void cfapi_object_check_spell(int *type,...)
Definition: plugins.c:3905
Definition: object.h:442
#define CFAPI_REGION_PROP_MESSAGE
Definition: plugin.h:329
const char * race
Definition: object.h:318
#define P_NEED_UPDATE
Definition: map.h:239
int is_magical(const object *op)
Definition: item.c:1243
#define CFAPI_MAP_PROP_FLAGS
Definition: plugin.h:295
#define CFAPI_MAP_PROP_DARKNESS
Definition: plugin.h:304
#define CFAPI_OBJECT_PROP_ARCHETYPE
Definition: plugin.h:232
#define CFAPI_OBJECT_PROP_WEIGHT
Definition: plugin.h:217
static void cfapi_get_month_name(int *type,...)
Definition: plugins.c:1099
uint16_t attack_movement
Definition: object.h:391
#define CFAPI_OBJECT_PROP_ATTACK_TYPE
Definition: plugin.h:200
static void cfapi_object_pickup(int *type,...)
Definition: plugins.c:4341
#define CFAPI_OBJECT_PROP_FACE
Definition: plugin.h:268
mapstruct * get_empty_map(int sizex, int sizey)
Definition: map.c:872
static void cfapi_archetype_get_property(int *type,...)
Definition: plugins.c:4356
static void cfapi_object_pay_amount(int *type,...)
Definition: plugins.c:3925
#define SET_FLAG(xyz, p)
Definition: define.h:223
#define NR_OF_HOOKS
Definition: plugins.c:43
#define EVENT_KICK
Definition: plugin.h:97
void do_forget_spell(object *op, const char *spell)
Definition: apply.c:432
MoveType move_allow
Definition: object.h:426
int16_t bed_x
Definition: player.h:98
linked_char * disabled_plugins
Definition: global.h:323
static void cfapi_object_get_property(int *type,...)
Definition: plugins.c:1721
#define plugins_dlsym(lib, name)
Definition: plugin.h:165
#define CFAPI_FUNC
Definition: plugin.h:114
#define PLUGIN_SUFFIX
Definition: win32.h:106
static void cfapi_object_spring_trap(int *type,...)
Definition: plugins.c:3757
New_Face * new_faces
Definition: image.c:33
#define CFAPI_OBJECT_PROP_GOD
Definition: plugin.h:265
#define CFAPI_OBJECT_PROP_PICK_UP
Definition: plugin.h:214
#define CFAPI_MAP_PROP_DIFFICULTY
Definition: plugin.h:296
void player_get_title(const struct pl *pl, char *buf, size_t bufsize)
Definition: player.c:224
uint16_t animation_id
Definition: object.h:416
#define CFAPI_MAP_PROP_HEIGHT
Definition: plugin.h:306
uint16_t material
Definition: object.h:347
#define CFAPI_OBJECT_PROP_DIRECTION
Definition: plugin.h:194
const char * name
Definition: face.h:27
#define strdup_local
Definition: compat.h:25
uint8_t anim_speed
Definition: object.h:417
object * object_get_env_recursive(object *op)
Definition: object.c:364
EXTERN objectlink * first_friendly_object
Definition: global.h:123
#define CFAPI_OBJECT_PROP_NEXT_ACTIVE_OB
Definition: plugin.h:173
struct obj * container
Definition: object.h:291
#define CFAPI_OBJECT_PROP_MAXGP
Definition: plugin.h:263
#define EVENT_LOGIN
Definition: plugin.h:88
int player_arrest(object *who)
Definition: c_wiz.c:797
#define CFAPI_OBJECT_PROP_HIDDEN
Definition: plugin.h:227
static void cfapi_region_get_property(int *type,...)
Definition: plugins.c:4466
static void cfapi_object_on_same_map(int *type,...)
Definition: plugins.c:3741
static void cfapi_system_find_face(int *type,...)
Definition: plugins.c:816
int16_t players
Definition: map.h:344
void fatal(enum fatal_error err)
Definition: utils.c:597
struct obj * who
Definition: dialog.h:52
static void cfapi_object_give_skill(int *type,...)
Definition: plugins.c:3340
#define CFAPI_OBJECT_PROP_MOVE_STATUS
Definition: plugin.h:228
const char * get_season_name(const int index)
Definition: time.c:123
int pay_for_item(object *op, object *pl)
Definition: shop.c:551
char * create_pathname(const char *name, char *buf, size_t size)
Definition: map.c:102
void knowledge_give(player *pl, const char *marker, const object *book)
Definition: knowledge.c:1009
mapstruct * ready_map_name(const char *name, int flags)
Definition: map.c:1815
const char * playerdir
Definition: global.h:244
unsigned char MoveType
Definition: define.h:432
int32_t last_heal
Definition: object.h:357
#define CFAPI_OBJECT_PROP_SUBTYPE
Definition: plugin.h:197
partylist * party_get_next(const partylist *party)
Definition: party.c:229
int16_t maxgrace
Definition: living.h:45
void free_string(sstring str)
Definition: shstr.c:280
#define UP_OBJ_INSERT
Definition: object.h:514
signed long object_sum_weight(object *op)
Definition: object.c:342
#define TIMER_ERR_ID
Definition: timers.h:67
#define CFAPI_REGION_PROP_JAIL_X
Definition: plugin.h:330
static void cfapi_get_periodofday_name(int *type,...)
Definition: plugins.c:1111
#define CFAPI_ARCH_PROP_MORE
Definition: plugin.h:317
#define SET_ANIMATION(ob, newanim)
Definition: global.h:169
static void cfapi_object_find_by_arch_name(int *type,...)
Definition: plugins.c:4066
mapstruct * get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y)
Definition: map.c:2380
#define NR_EVENTS
Definition: plugin.h:100
#define EVENT_MAPLEAVE
Definition: plugin.h:91
void esrv_update_item(int flags, object *pl, object *op)
Definition: main.c:342
#define CFAPI_OBJECT_PROP_CONTAINER
Definition: plugin.h:178
const char * object_get_value(const object *op, const char *const key)
Definition: object.c:4264
#define CFAPI_INT16
Definition: plugin.h:118
void pick_up(object *op, object *alt)
Definition: c_object.c:446
f_plug_api func
Definition: plugin.h:351
#define CFAPI_OBJECT_PROP_INVENTORY
Definition: plugin.h:175
void query_base_name(const object *op, int plural, char *buf, size_t size)
Definition: item.c:723
struct pl player
static void cfapi_object_set_property(int *type,...)
Definition: plugins.c:2556
object clone
Definition: object.h:470
int16_t duration
Definition: object.h:403
#define CFAPI_OBJECT_PROP_FLAGS
Definition: plugin.h:247
static void cfapi_get_season_name(int *type,...)
Definition: plugins.c:1075
socket_struct socket
Definition: player.h:94
int16_t invisible
Definition: object.h:360
short freearr_x[SIZEOFFREE]
Definition: object.c:65
#define EVENT_LOGOUT
Definition: plugin.h:89
uint32_t reset_time
Definition: map.h:332
int calculate_difficulty(mapstruct *m)
Definition: map.c:1925
#define CFAPI_SINT64
Definition: plugin.h:120
#define CFAPI_OBJECT_PROP_NAME_PLURAL
Definition: plugin.h:182
static void cfapi_log(int *type,...)
Definition: plugins.c:1178
const char * get_weekday(const int index)
Definition: time.c:116
const char * slaying
Definition: object.h:319
region * get_region_by_map(mapstruct *m)
Definition: region.c:74
static void cfapi_object_find_archetype_inside(int *type,...)
Definition: plugins.c:4034
DIR * opendir(const char *)
Definition: win32.c:37
int32_t last_sp
Definition: object.h:358
#define CFAPI_OBJECT_PROP_OWNER
Definition: plugin.h:242
static void cfapi_object_teleport(int *type,...)
Definition: plugins.c:4302
static void cfapi_system_re_cmp(int *type,...)
Definition: plugins.c:973
static int do_execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix, talk_info *talk)
Definition: plugins.c:312
const char * party_get_password(const partylist *party)
Definition: party.c:263
uint8_t subtype
Definition: object.h:339
crossfire_plugin * plugins_list
Definition: plugins.c:235
uint32_t mark_count
Definition: player.h:193
#define CFAPI_OBJECT_PROP_MOVE_ON
Definition: plugin.h:274
static void cfapi_map_get_map_property(int *type,...)
Definition: plugins.c:1305
uint8_t hide
Definition: object.h:387
int64_t exp
Definition: living.h:47
#define CFAPI_OBJECT_PROP_MESSAGE
Definition: plugin.h:187
#define FREE_OBJ_NO_DESTROY_CALLBACK
Definition: object.h:531
static void cfapi_map_delete_map(int *type,...)
Definition: plugins.c:1505
#define CFAPI_OBJECT_PROP_EXP_MULTIPLIER
Definition: plugin.h:231
struct obj * above
Definition: object.h:288
double expmul
Definition: object.h:395
#define plugins_dlclose(lib)
Definition: plugin.h:164
#define CFAPI_MAP_PROP_RESET_TIMEOUT
Definition: plugin.h:301
#define object_was_destroyed(op, old_tag)
Definition: object.h:68
char id[MAX_BUF]
Definition: plugin.h:148
void initPlugins(void)
Definition: plugins.c:4732
object * arch_present_in_ob(const archetype *at, const object *op)
Definition: object.c:3076
#define CFAPI_PLAYER_QUEST_START
Definition: plugin.h:290
#define CFAPI_DOUBLE
Definition: plugin.h:112
static void cfapi_object_insert(int *type,...)
Definition: plugins.c:3493
void remove_friendly_object(object *op)
Definition: friend.c:56
#define CFAPI_REGION_PROP_NEXT
Definition: plugin.h:326
uint32_t path_attuned
Definition: object.h:343
void object_update(object *op, int action)
Definition: object.c:1260
static void cfapi_object_drop(int *type,...)
Definition: plugins.c:4103
static void cfapi_object_fix(int *type,...)
Definition: plugins.c:3324
int16_t sp
Definition: living.h:42
static void cfapi_map_set_map_property(int *type,...)
Definition: plugins.c:1437
#define EVENT_TELL
Definition: plugin.h:95
static void cfapi_object_set_key(int *type,...)
Definition: plugins.c:1698
#define EVENT_CRASH
Definition: plugin.h:85
#define CFAPI_MAP_PROP_NEXT
Definition: plugin.h:310
static void cfapi_party_get_property(int *type,...)
Definition: plugins.c:4411
int object_can_merge(object *ob1, object *ob2)
Definition: object.c:202
#define CFAPI_OBJECT_PROP_SLAYING
Definition: plugin.h:185
static void cfapi_map_create_path(int *type,...)
Definition: plugins.c:1271
int plugin_event_say(object *npc, talk_info *talk)
Definition: plugins.c:379
Definition: win32.h:110
uint32_t path_repelled
Definition: object.h:344
#define safe_strncpy
Definition: compat.h:23
#define SCRIPT_FIX_ALL
Definition: global.h:361
void free_dialog_information(object *op)
Definition: dialog.c:32
char * partyname
Definition: party.h:14
struct obj * enemy
Definition: object.h:381
struct archt * other_arch
Definition: object.h:413
static void cfapi_system_find_string(int *type,...)
Definition: plugins.c:931
object * object_find_by_name(const object *who, const char *name)
Definition: object.c:3897
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:310
Definition: object.h:465
#define CFAPI_PMAP
Definition: plugin.h:110
static void cfapi_object_apply_below(int *type,...)
Definition: plugins.c:3200
void transmute_materialname(object *op, const object *change)
Definition: utils.c:267
char savebed_map[MAX_BUF]
Definition: player.h:97
static void cfapi_timer_create(int *type,...)
Definition: plugins.c:1126
Definition: plugin.h:350
char * host
Definition: newserver.h:100
static void cfapi_player_quest(int *type,...)
Definition: plugins.c:4644
#define CFAPI_POBJECT
Definition: plugin.h:109
static void cfapi_object_split(int *type,...)
Definition: plugins.c:3601
#define CFAPI_OBJECT_PROP_CHOSEN_SKILL
Definition: plugin.h:226
#define CFAPI_OBJECT_PROP_OTHER_ARCH
Definition: plugin.h:233
int16_t maxsp
Definition: living.h:43
#define CFAPI_OBJECT_PROP_LAST_SP
Definition: plugin.h:210
int8_t Con
Definition: living.h:36
int change_map_light(mapstruct *m, int change)
Definition: map.c:2007
#define CFAPI_REGION_PROP_JAIL_PATH
Definition: plugin.h:332
#define FLAG_REMOVED
Definition: define.h:232
static void cfapi_object_delete(int *type,...)
Definition: plugins.c:3395
int16_t hp
Definition: living.h:40
#define CFAPI_OBJECT_PROP_LAST_GRACE
Definition: plugin.h:211
static void cfapi_object_find_by_name(int *type,...)
Definition: plugins.c:4082
#define CFAPI_OBJECT_PROP_COUNT
Definition: plugin.h:180
short freearr_y[SIZEOFFREE]
Definition: object.c:71
partylist * party
Definition: player.h:186
static void cfapi_object_remove(int *type,...)
Definition: plugins.c:3374
#define CFAPI_NONE
Definition: plugin.h:104
#define UPD_ALL
Definition: newclient.h:297
void command_say(object *op, const char *params)
Definition: c_chat.c:34
object * ob
Definition: object.h:443
#define MOVE_ALL
Definition: define.h:413
uint16_t height
Definition: map.h:347
object * give_skill_by_name(object *op, const char *skill_name)
Definition: living.c:1752
static void cfapi_object_transmute(int *type,...)
Definition: plugins.c:3357
const char * get_month_name(const int index)
Definition: time.c:109
#define CFAPI_FLOAT
Definition: plugin.h:111
void map_newmap_cmd(socket_struct *ns)
Definition: request.c:615
struct _crossfire_plugin * next
Definition: plugin.h:151
void object_set_owner(object *op, object *owner)
Definition: object.c:632
#define CFAPI_PLAYER_PROP_BED_X
Definition: plugin.h:285
char * name
Definition: map.h:328
#define CFAPI_PARCH
Definition: plugin.h:113
const char * lore
Definition: object.h:323
static void cfapi_object_identify(int *type,...)
Definition: plugins.c:3245
struct obj * chosen_skill
Definition: object.h:386
int object_set_value(object *op, const char *key, const char *value, int add_key)
Definition: object.c:4393
uint32_t update_look
Definition: newserver.h:104
void object_free_drop_inventory(object *ob)
Definition: object.c:1389
int change_abil(object *op, object *tmp)
Definition: living.c:394
const char * name
Definition: face.h:20
const char * title
Definition: object.h:317
int16_t y
Definition: object.h:326
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.c:1936
#define CFAPI_MAP_PROP_PLAYERS
Definition: plugin.h:302
int move_to(object *op, int x, int y)
Definition: move.c:545
int is_friendly(const object *op)
Definition: friend.c:144
int16_t maxhp
Definition: living.h:41
sstring find_string(const char *str)
Definition: shstr.c:236
char * name
Definition: map.h:278
#define CFAPI_OBJECT_PROP_FACING
Definition: plugin.h:195
int user_event(object *op, object *activator, object *third, const char *message, int fix)
Definition: plugins.c:308
#define MSG_TYPE_COMMAND
Definition: newclient.h:379
static void cfapi_object_say(int *type,...)
Definition: plugins.c:4142
#define EVENT_MAPENTER
Definition: plugin.h:90
static void cfapi_system_remove_string(int *type,...)
Definition: plugins.c:913
uint32_t path_denied
Definition: object.h:345
static void cfapi_object_change_exp(int *type,...)
Definition: plugins.c:4211
#define CFAPI_PLAYER_PROP_IP
Definition: plugin.h:281
#define CFAPI_OBJECT_PROP_ENVIRONMENT
Definition: plugin.h:176
Definition: win32.h:120
static void cfapi_object_merge(int *type,...)
Definition: plugins.c:3634
#define CFAPI_OBJECT_PROP_GP
Definition: plugin.h:259
LIBPTRTYPE libptr
Definition: plugin.h:147
#define CFAPI_OBJECT_PROP_CHA
Definition: plugin.h:254
#define CFAPI_PARTY_PROP_PLAYER
Definition: plugin.h:323
object * object_new(void)
Definition: object.c:1068
const char * name_pl
Definition: object.h:315
static void cfapi_player_knowledge(int *type,...)
Definition: plugins.c:4253
#define LIBDIR
Definition: win32.h:99
#define CFAPI_OBJECT_PROP_ATTACKED_BY
Definition: plugin.h:224
#define CFAPI_STRING
Definition: plugin.h:108
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:3808
object * object_insert_in_ob(object *op, object *where)
Definition: object.c:2705
#define CFAPI_OBJECT_PROP_MOVE_SLOW_PENALTY
Definition: plugin.h:277
#define CFAPI_MAP_PROP_UNIQUE
Definition: plugin.h:312
float speed_left
Definition: object.h:329
int knowledge_player_knows(const player *pl, const char *knowledge)
Definition: knowledge.c:1306
void *(* f_plug_property)(int *type,...)
Definition: plugin.h:133
#define CFAPI_OBJECT_PROP_INT
Definition: plugin.h:252
signed short int16_t
Definition: win32.h:160
#define CFAPI_MAP_PROP_RESET_TIME
Definition: plugin.h:300
#define CFAPI_ARCH_PROP_HEAD
Definition: plugin.h:316
void monster_npc_say(object *npc, const char *cp)
Definition: monster.c:2301
static void cfapi_timer_destroy(int *type,...)
Definition: plugins.c:1159
const char * materialname
Definition: object.h:346
int16_t enter_x
Definition: map.h:348
int32_t weight
Definition: object.h:365
uint32_t unique
Definition: map.h:337
#define CFAPI_OBJECT_PROP_LEVEL
Definition: plugin.h:208
#define FOR_ABOVE_FINISH()
Definition: define.h:731
void update_all_los(const mapstruct *map, int x, int y)
Definition: los.c:532
const char * tmpdir
Definition: global.h:251
int8_t Wis
Definition: living.h:36
const char * text
Definition: dialog.h:53
#define CFAPI_OBJECT_PROP_HEAD
Definition: plugin.h:177
#define CFAPI_PLAYER_PROP_BED_MAP
Definition: plugin.h:284
#define CFAPI_OBJECT_PROP_MOVE_ALLOW
Definition: plugin.h:273
static void cfapi_player_message(int *type,...)
Definition: plugins.c:4186
struct mapdef * map
Definition: object.h:297
struct regiondef * next
Definition: map.h:277
Definition: map.h:276
#define CFAPI_OBJECT_PROP_RAW_NAME
Definition: plugin.h:279
#define snprintf
Definition: win32.h:46
struct obj * active_prev
Definition: object.h:283
void drain_specific_stat(object *op, int deplete_stats)
Definition: living.c:724
static void cfapi_object_user_event(int *type,...)
Definition: plugins.c:4620
#define CFAPI_ARCH_PROP_NEXT
Definition: plugin.h:315
f_plug_postinit closefunc
Definition: plugin.h:146
struct linked_char * next
Definition: global.h:88
int plugins_init_plugin(const char *libfile)
Definition: plugins.c:611
uint64_t query_money(const object *op)
Definition: shop.c:481
int(* f_plug_postinit)(void)
Definition: plugin.h:127
#define FOR_INV_FINISH()
Definition: define.h:714
char * msg
Definition: map.h:361
void update_position(mapstruct *m, int x, int y)
Definition: map.c:2131
int16_t dam
Definition: living.h:46
int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: plugins.c:375
void add_friendly_object(object *op)
Definition: friend.c:30
#define CFAPI_OBJECT_PROP_FP
Definition: plugin.h:260
int32_t carrying
Definition: object.h:367
const char * name
Definition: object.h:311
int16_t bed_y
Definition: player.h:98
struct obj * env
Definition: object.h:293
#define FOR_ABOVE_PREPARE(op_, it_)
Definition: define.h:724
#define CFAPI_OBJECT_PROP_MAGICAL
Definition: plugin.h:239
int64_t perm_exp
Definition: object.h:369
int8_t gen_sp_armour
Definition: object.h:363
static void cfapi_map_find_by_archetype_name(int *type,...)
Definition: plugins.c:1569
#define LIBPTRTYPE
Definition: plugin.h:136
uint8_t state
Definition: object.h:349
struct obj * below
Definition: object.h:287
struct archt * more
Definition: object.h:469
static void cfapi_object_pay_item(int *type,...)
Definition: plugins.c:3946
archetype * find_archetype_by_object_name(const char *name)
Definition: arch.c:57
#define CFAPI_OBJECT_PROP_LAST_EAT
Definition: plugin.h:212
object * object_present_in_ob(uint8_t type, const object *op)
Definition: object.c:3016
void trigger_connected(objectlink *ol, object *cause, const int state)
Definition: button.c:41
int16_t last_grace
Definition: object.h:359
const char * re_cmp(const char *, const char *)
Definition: re-cmp.c:69
void object_reset(object *op)
Definition: object.c:735
int pay_for_amount(uint64_t to_pay, object *pl)
Definition: shop.c:512
#define CFAPI_OBJECT_PROP_MOVE_OFF
Definition: plugin.h:275
#define CFAPI_OBJECT_PROP_WEIGHT_LIMIT
Definition: plugin.h:218
#define CFAPI_PLAYER_QUEST_SET_STATE
Definition: plugin.h:292
struct obj * current_weapon
Definition: object.h:370
int8_t direction
Definition: object.h:334
#define CFAPI_LONG
Definition: plugin.h:106
object * object_create_clone(object *asrc)
Definition: object.c:3850
uint32_t nrof
Definition: object.h:333
#define string_get_int(name)
Definition: plugins.c:1056
#define CFAPI_OBJECT_PROP_CURRENT_WEAPON
Definition: plugin.h:222
#define CFAPI_SSTRING
Definition: plugin.h:121
int8_t Cha
Definition: living.h:36
struct archt * head
Definition: object.h:468
int find_animation(const char *name)
Definition: anim.c:170
static void cfapi_player_can_pay(int *type,...)
Definition: plugins.c:4234
static void cfapi_system_check_path(int *type,...)
Definition: plugins.c:950
#define CFAPI_PPLAYER
Definition: plugin.h:115
#define SIZEOFFREE
Definition: define.h:154
#define P_OUT_OF_MAP
Definition: map.h:251
MoveType move_off
Definition: object.h:428
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:189
EXTERN Animations * animations
Definition: global.h:163
void do_learn_spell(object *op, object *spell, int special_prayer)
Definition: apply.c:391
static void cfapi_map_out_of_map(int *type,...)
Definition: plugins.c:1467
struct pl * contr
Definition: object.h:276
#define CFAPI_OBJECT_PROP_CHEATER
Definition: plugin.h:244
static void cfapi_object_get_key(int *type,...)
Definition: plugins.c:1676
#define CFAPI_OBJECT_PROP_PICKABLE
Definition: plugin.h:246
int8_t item_power
Definition: object.h:362
static void cfapi_system_directory(int *type,...)
Definition: plugins.c:991
void cleanupPlugins(void)
Definition: plugins.c:4782
uint8_t ignore_plugin_compatibility
Definition: global.h:324
uint8_t darkness
Definition: map.h:346
#define CFAPI_MAP_PROP_MESSAGE
Definition: plugin.h:309
int try_find_animation(const char *name)
Definition: anim.c:185
void object_clear(object *op)
Definition: object.c:790
command_array_struct * find_plugin_command(const char *cmd, command_array_struct *command)
Definition: plugins.c:4711
static crossfire_plugin * plugins_find_plugin(const char *id)
Definition: plugins.c:246
#define CFAPI_OBJECT_PROP_ENEMY
Definition: plugin.h:223
#define CFAPI_REGION_PROP_JAIL_Y
Definition: plugin.h:331
object * find_marked_object(object *op)
Definition: c_object.c:1256
#define CFAPI_OBJECT_PROP_PATH_REPELLED
Definition: plugin.h:202
void plugins_display_list(object *op)
Definition: plugins.c:744
static void cfapi_object_learn_spell(int *type,...)
Definition: plugins.c:3870
archetype * try_find_archetype(const char *name)
Definition: arch.c:663
#define UPD_WEIGHT
Definition: newclient.h:291
uint32_t tag_t
Definition: object.h:12
#define EVENT_SAY
Definition: plugin.h:70
char d_name[_MAX_FNAME+1]
Definition: win32.h:114
static void cfapi_object_create(int *type,...)
Definition: plugins.c:3454
int8_t luck
Definition: living.h:39
#define CFAPI_MAP_PROP_TMPNAME
Definition: plugin.h:298
float speed
Definition: object.h:328
unsigned __int64 uint64_t
Definition: win32.h:167
char fullname[MAX_BUF]
Definition: plugin.h:149
struct regiondef * parent
Definition: map.h:286
int on_same_map(const object *op1, const object *op2)
Definition: map.c:2650
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
f_plug_property propfunc
Definition: plugin.h:145
#define CLEAR_FLAG(xyz, p)
Definition: define.h:224
#define CFAPI_OBJECT_PROP_LORE
Definition: plugin.h:188
static void cfapi_player_find(int *type,...)
Definition: plugins.c:4171
#define EVENT_MAPLOAD
Definition: plugin.h:99
partylist * party_get_first(void)
Definition: party.c:217
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Definition: living.c:2102
#define CFAPI_OBJECT_PROP_ITEM_POWER
Definition: plugin.h:215
#define CFAPI_REGION_PROP_LONGNAME
Definition: plugin.h:328
#define MSG_TYPE_COMMAND_DEBUG
Definition: newclient.h:508
static void cfapi_object_apply(int *type,...)
Definition: plugins.c:3220
static void cfapi_system_unregister_global_event(int *type,...)
Definition: plugins.c:870
#define MAX_BUF
Definition: define.h:35
int quest_get_player_state(player *pl, sstring quest_code)
Definition: quest.c:1076
#define CFAPI_PARTY_PROP_NAME
Definition: plugin.h:320
struct obj * active_next
Definition: object.h:279
#define CFAPI_PLAYER_PROP_PARTY
Definition: plugin.h:283
LogLevel
Definition: logger.h:10
object * object_create_arch(archetype *at)
Definition: arch.c:733
int16_t jailx
Definition: map.h:298
int16_t enter_y
Definition: map.h:348
int16_t x
Definition: object.h:326
#define EVENT_MAPUNLOAD
Definition: plugin.h:98
void drop(object *op, object *tmp)
Definition: c_object.c:910
#define CFAPI_OBJECT_PROP_EXP
Definition: plugin.h:241
const char * skill
Definition: object.h:321
int32_t last_eat
Definition: object.h:356
static void cfapi_object_describe(int *type,...)
Definition: plugins.c:3265
#define plugins_dlerror()
Definition: plugin.h:166
#define EVENT_MAPRESET
Definition: plugin.h:92
int8_t wc
Definition: living.h:37
const char * confdir
Definition: global.h:241
int object_find_first_free_spot(const object *ob, mapstruct *m, int x, int y)
Definition: object.c:3473
int(* f_plug_event)(int *type,...)
Definition: plugin.h:131
signed __int64 int64_t
Definition: win32.h:168
static const flag_definition flags[]
#define EVENT_GKILL
Definition: plugin.h:87
static void cfapi_system_strdup_local(int *type,...)
Definition: plugins.c:837
#define CFAPI_OBJECT_PROP_PERM_EXP
Definition: plugin.h:221
const char * uniquedir
Definition: global.h:249
int8_t Str
Definition: living.h:36
char * tmpname
Definition: map.h:327
int16_t resist[NROFATTACKS]
Definition: object.h:341
object * ob
Definition: player.h:158
const char * sstring
Definition: global.h:40
#define EVENT_CLOCK
Definition: plugin.h:84
#define CFAPI_OBJECT_PROP_DAM
Definition: plugin.h:264
unsigned int uint32_t
Definition: win32.h:162
#define CFAPI_OBJECT_PROP_MOVE_TYPE
Definition: plugin.h:271
Definition: object.h:107
const char * datadir
Definition: global.h:242
#define CFAPI_OBJECT_PROP_SKILL
Definition: plugin.h:186
#define CFAPI_PLAYER_PROP_NEXT
Definition: plugin.h:287
#define CFAPI_OBJECT_PROP_AC
Definition: plugin.h:256
static void cfapi_object_check_trigger(int *type,...)
Definition: plugins.c:3776
#define SET_MAP_FLAGS(M, X, Y, C)
Definition: map.h:163
#define CFAPI_OBJECT_PROP_BASE_NAME
Definition: plugin.h:238
#define TIMER_ERR_NONE
Definition: timers.h:66
const char * name
Definition: global.h:87
#define CFAPI_REGION_PROP_PARENT
Definition: plugin.h:327
#define CFAPI_INT
Definition: plugin.h:105
uint32_t attacktype
Definition: object.h:342
struct obj * spellitem
Definition: object.h:394
static void cfapi_friendlylist_get_next(int *type,...)
Definition: plugins.c:4539
object * object_split(object *orig_ob, uint32_t nr, char *err, size_t size)
Definition: object.c:2478
#define CFAPI_ARCH_PROP_NAME
Definition: plugin.h:314
StringBuffer * describe_item(const object *op, const object *owner, int use_media_tags, StringBuffer *buf)
Definition: item.c:981
void quest_set_player_state(player *pl, sstring quest_code, int state)
Definition: quest.c:1132
object * object_decrease_nrof(object *op, uint32_t i)
Definition: object.c:2520
int set_random_map_variable(RMParms *rp, const char *buf)
#define CFAPI_OBJECT_PROP_SPEED_LEFT
Definition: plugin.h:192
#define FREE_AND_COPY(sv, nv)
Definition: global.h:211
int16_t grace
Definition: living.h:44
#define UPD_NROF
Definition: newclient.h:296
void get_tod(timeofday_t *tod)
Definition: time.c:215
static void cfapi_object_query_money(int *type,...)
Definition: plugins.c:3823
const char * custom_name
Definition: object.h:432
int cftimer_create(int id, long delay, object *ob, int mode)
Definition: timers.c:97
const char * localdir
Definition: global.h:243
tag_t count
Definition: object.h:299
living stats
Definition: object.h:368
static void cfapi_map_has_been_loaded(int *type,...)
Definition: plugins.c:1253
uint16_t client_type
Definition: object.h:340
mapstruct * has_been_loaded(const char *name)
Definition: map.c:77
int8_t Dex
Definition: living.h:36
char * jailmap
Definition: map.h:297
struct archt * arch
Definition: object.h:412
#define CFAPI_OBJECT_PROP_HP
Definition: plugin.h:257
struct oblnk * next
Definition: object.h:444
static void cfapi_object_cast(int *type,...)
Definition: plugins.c:3842
#define CFAPI_OBJECT_PROP_TITLE
Definition: plugin.h:183
int cftimer_find_free_id(void)
Definition: timers.c:144
const char * mapdir
Definition: global.h:245
uint32_t reset_timeout
Definition: map.h:333
#define CFAPI_PLAYER_PROP_BED_Y
Definition: plugin.h:286
uint16_t width
Definition: map.h:347
#define CFAPI_OBJECT_PROP_SPEED
Definition: plugin.h:191
Definition: tod.h:34
uint8_t type
Definition: object.h:338
struct Settings settings
Definition: init.c:40
#define CFAPI_MAP_PROP_PATH
Definition: plugin.h:297
static void cfapi_get_hooks(int *type,...)
Definition: plugins.c:565
void object_set_enemy(object *op, object *enemy)
Definition: object.c:710
int remove_depletion(object *op, int level)
Definition: living.c:751
#define CFAPI_OBJECT_PROP_FRIENDLY
Definition: plugin.h:236
void object_free2(object *ob, int flags)
Definition: object.c:1412
#define CFAPI_OBJECT_PROP_ANIM_SPEED
Definition: plugin.h:235
struct archt * next
Definition: object.h:467
#define CFAPI_OBJECT_PROP_LUCK
Definition: plugin.h:240
void party_join(object *op, partylist *party)
Definition: party.c:84
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:1884
#define CFAPI_OBJECT_PROP_ARCH_NAME
Definition: plugin.h:266
void query_short_name(const object *op, char *buf, size_t size)
Definition: item.c:548
object * object_get_player_container(object *op)
Definition: object.c:384
static void cfapi_system_add_string(int *type,...)
Definition: plugins.c:893
int out_of_map(mapstruct *m, int x, int y)
Definition: map.c:2306
#define CFAPI_OBJECT_PROP_INVISIBLE_TIME
Definition: plugin.h:213
static void cfapi_get_time(int *type,...)
Definition: plugins.c:1044
static void cfapi_map_get_object_at(int *type,...)
Definition: plugins.c:1540
#define CFAPI_OBJECT_PROP_DEX
Definition: plugin.h:249
#define CFAPI_MOVETYPE
Definition: plugin.h:122
#define CFAPI_OBJECT_PROP_ATTACK_MOVEMENT
Definition: plugin.h:229
#define CFAPI_MAP_PROP_REGION
Definition: plugin.h:311
static void cfapi_object_change_abil(int *type,...)
Definition: plugins.c:4127
void delete_map(mapstruct *m)
Definition: map.c:1753
const char * msg
Definition: object.h:322
#define CFAPI_MAP_PROP_WIDTH
Definition: plugin.h:305
#define CFAPI_OBJECT_PROP_CON
Definition: plugin.h:250
sstring add_string(const char *str)
Definition: shstr.c:124
#define CFAPI_PLAYER_QUEST_WAS_COMPLETED
Definition: plugin.h:293
EXTERN player * first_player
Definition: global.h:117
char * cost_string_from_value(uint64_t cost, int largest_coin)
Definition: shop.c:333
#define CFAPI_PARTY_PROP_NEXT
Definition: plugin.h:321
object * identify(object *op)
Definition: item.c:1438
struct pl * next
Definition: player.h:93
static void cfapi_object_clean_object(int *type,...)
Definition: plugins.c:3730
#define GET_MAP_OB(M, X, Y)
Definition: map.h:172
int check_path(const char *name, int prepend_dir)
Definition: map.c:201
#define CFAPI_OBJECT_PROP_NROF
Definition: plugin.h:193
int8_t glow_radius
Definition: object.h:364
#define CFAPI_OBJECT_PROP_MAXSP
Definition: plugin.h:262
f_plug_event eventfunc
Definition: plugin.h:144
void object_copy(const object *src_ob, object *dest_ob)
Definition: object.c:869
#define CFAPI_ARCH_PROP_CLONE
Definition: plugin.h:318
struct _crossfire_plugin * prev
Definition: plugin.h:152
static void cfapi_object_transfer(int *type,...)
Definition: plugins.c:3970
#define EVENT_PLAYER_DEATH
Definition: plugin.h:86
static void cfapi_object_remove_depletion(int *type,...)
Definition: plugins.c:3305
int8_t Pow
Definition: living.h:36
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:300
struct obj * inv
Definition: object.h:290
void object_set_cheat(object *op)
Definition: object.c:3137
#define NDI_UNIQUE
Definition: newclient.h:245
#define CFAPI_PLAYER_PROP_MARKED_ITEM
Definition: plugin.h:282
static void cfapi_map_get_map(int *type,...)
Definition: plugins.c:1202
struct obj * head
Definition: object.h:296
#define MSG_SUBTYPE_NONE
Definition: newclient.h:398
static void cfapi_object_distance(int *type,...)
Definition: plugins.c:3657
#define CFAPI_OBJECT_PROP_LAST_HEAL
Definition: plugin.h:209
#define CFAPI_OBJECT_PROP_CLIENT_TYPE
Definition: plugin.h:198
#define CFAPI_OBJECT_PROP_INVISIBLE
Definition: plugin.h:267
void player_update_bg_music(object *player)
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
#define CFAPI_OBJECT_PROP_TYPE
Definition: plugin.h:196
static const hook_entry plug_hooks[]
Definition: plugins.c:140
char * msg
Definition: map.h:293
static void cfapi_object_forget_spell(int *type,...)
Definition: plugins.c:3885
#define CFAPI_OBJECT_PROP_POW
Definition: plugin.h:253
static void cfapi_get_weekday_name(int *type,...)
Definition: plugins.c:1087
static void cfapi_map_message(int *type,...)
Definition: plugins.c:1518
static void cfapi_object_update(int *type,...)
Definition: plugins.c:3678
object * mark
Definition: player.h:194
#define FLAG_WAS_WIZ
Definition: define.h:234
EXTERN region * first_region
Definition: global.h:119
uint8_t pick_up
Definition: object.h:361
#define CFAPI_OBJECT_PROP_GEN_SP_ARMOUR
Definition: plugin.h:216
int transfer_ob(object *op, int x, int y, int randomly, object *originator)
Definition: move.c:144
MoveType move_block
Definition: object.h:425
uint8_t run_away
Definition: object.h:384
#define CFAPI_OBJECT_PROP_GLOW_RADIUS
Definition: plugin.h:220
struct mapdef * next
Definition: map.h:326
static void cfapi_object_clone(int *type,...)
Definition: plugins.c:3422
static void cfapi_object_reset(int *type,...)
Definition: plugins.c:3716
void object_set_msg(object *op, const char *msg)
Definition: object.c:4713
int object_find_free_spot(const object *ob, mapstruct *m, int x, int y, int start, int stop)
Definition: object.c:3430
int check_trigger(object *op, object *cause)
Definition: button.c:523
#define CFAPI_OBJECT_PROP_PRESENT
Definition: plugin.h:243
float move_slow_penalty
Definition: object.h:430
#define CFAPI_OBJECT_PROP_MERGEABLE
Definition: plugin.h:245
#define CFAPI_OBJECT_PROP_WC
Definition: plugin.h:255
void query_name(const object *op, char *buf, size_t size)
Definition: item.c:626
#define CFAPI_OBJECT_PROP_RESIST
Definition: plugin.h:199
#define CFAPI_OBJECT_PROP_SHORT_NAME
Definition: plugin.h:237
#define CFAPI_OBJECT_PROP_MOVE_SLOW
Definition: plugin.h:276
#define CFAPI_OBJECT_PROP_MATERIAL_NAME
Definition: plugin.h:205
void create_overlay_pathname(const char *name, char *buf, size_t size)
Definition: map.c:123
object * map_find_by_archetype(mapstruct *m, int x, int y, const archetype *at)
Definition: object.c:2959
Definition: map.h:325
const New_Face * face
Definition: object.h:332
#define CFAPI_OBJECT_PROP_MAXHP
Definition: plugin.h:261
int can_pay(object *pl)
Definition: shop.c:834
#define FLAG_UNIQUE
Definition: define.h:288
#define CFAPI_OBJECT_PROP_VALUE
Definition: plugin.h:207
static void cfapi_cost_string_from_value(int *type,...)
Definition: plugins.c:767
void ext_info_map(int color, const mapstruct *map, uint8_t type, uint8_t subtype, const char *str1)
Definition: main.c:325
#define CFAPI_OBJECT_PROP_SPELL_ITEM
Definition: plugin.h:230
#define CFAPI_OBJECT_PROP_PATH_ATTUNED
Definition: plugin.h:201
int(* f_plug_init)(const char *iversion, f_plug_api gethooksptr)
Definition: plugin.h:129
int32_t move_status
Definition: object.h:390
int16_t level
Definition: object.h:351
int8_t facing
Definition: object.h:335
void fix_object(object *op)
Definition: living.c:1119
static void send_changed_object(object *op)
Definition: plugins.c:282
unsigned find_face(const char *name, unsigned error)
Definition: image.c:303
player * find_player_partial_name(const char *plname)
Definition: player.c:109
#define CFAPI_OBJECT_PROP_WIS
Definition: plugin.h:251
EXTERN mapstruct * first_map
Definition: global.h:118
int quest_was_completed(player *pl, sstring quest_code)
Definition: quest.c:1142
#define CFAPI_OBJECT_PROP_DURATION
Definition: plugin.h:278
EXTERN archetype * first_archetype
Definition: global.h:122
char * longname
Definition: map.h:291
void object_update_speed(object *op)
Definition: object.c:1150
#define CFAPI_MAP_PROP_ENTER_X
Definition: plugin.h:307
void clean_object(object *op)
Definition: map.c:1643
int32_t value
Definition: object.h:350
object * object_get_owner(object *op)
Definition: object.c:590
#define CFAPI_OBJECT_PROP_OB_ABOVE
Definition: plugin.h:171
int8_t magic
Definition: object.h:348
#define CFAPI_OBJECT_PROP_Y
Definition: plugin.h:190
#define CFAPI_OBJECT_PROP_CUSTOM_NAME
Definition: plugin.h:234
const char * name
Definition: object.h:466
#define EVENT_BORN
Definition: plugin.h:83
char * stringbuffer_finish(StringBuffer *sb)
Definition: stringbuffer.c:76
f_plug_event gevent[NR_EVENTS]
Definition: plugin.h:150
int plugins_remove_plugin(const char *id)
Definition: plugins.c:702
void(* f_plug_api)(int *type,...)
Definition: plugin.h:125
int execute_global_event(int eventcode,...)
Definition: plugins.c:383
object * object_find_by_arch_name(const object *who, const char *name)
Definition: object.c:4161
object * object_present_in_ob_by_name(int type, const char *str, const object *op)
Definition: object.c:3054
#define CFAPI_OBJECT_PROP_PREV_ACTIVE_OB
Definition: plugin.h:174
#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:1471
void object_remove(object *op)
Definition: object.c:1669
#define EVENT_USER
Definition: plugin.h:78
static void cfapi_generate_random_map(int *type,...)
Definition: plugins.c:4603
#define CFAPI_OBJECT_PROP_PATH_DENIED
Definition: plugin.h:203
static void cfapi_map_update_position(int *type,...)
Definition: plugins.c:1489
#define CFAPI_OBJECT_PROP_MOVE_BLOCK
Definition: plugin.h:272
#define CFAPI_REGION_PROP_NAME
Definition: plugin.h:325
struct obj * attacked_by
Definition: object.h:382
#define CFAPI_PPARTY
Definition: plugin.h:116
static void cfapi_map_change_light(int *type,...)
Definition: plugins.c:1595
int32_t food
Definition: living.h:48
#define FLAG_FREED
Definition: define.h:233
#define EVENT_MUZZLE
Definition: plugin.h:96
uint32_t count
Definition: player.h:109