Crossfire Server, Trunk  R20513
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  rv = plugin->eventfunc(&rvt, op, activator, third, message, fix, tmp, talk);
356  if (QUERY_FLAG(tmp, FLAG_UNIQUE)) {
357 #ifdef PLUGIN_DEBUG
358  LOG(llevDebug, "Removing unique event %s\n", tmp->slaying);
359 #endif
360  object_remove(tmp);
362  }
363  return rv;
364  }
365  }
366  }
367  } FOR_INV_FINISH();
368  return rv;
369 }
370 
371 int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix) {
372  return do_execute_event(op, eventcode, activator, third, message, fix, NULL);
373 }
374 
375 int plugin_event_say(object *npc, talk_info *talk) {
376  return do_execute_event(npc, EVENT_SAY, talk->who, NULL, talk->text, SCRIPT_FIX_ALL, talk);
377 }
378 
379 int execute_global_event(int eventcode, ...) {
380  va_list args;
381  mapstruct *map;
382  object *op;
383  object *op2;
384  player *pl;
385  const char *buf;
386  int i, rt;
387  crossfire_plugin *cp;
388 
389  if (plugins_list == NULL)
390  return -1;
391 
392  va_start(args, eventcode);
393 
394  switch (eventcode) {
395  case EVENT_BORN:
396  /*BORN: op*/
397  op = va_arg(args, object *);
398  for (cp = plugins_list; cp != NULL; cp = cp->next) {
399  if (cp->gevent[eventcode] != NULL)
400  cp->gevent[eventcode](&rt, eventcode, op);
401  }
402  break;
403 
404  case EVENT_CLOCK:
405  /*CLOCK: -*/
406  for (cp = plugins_list; cp != NULL; cp = cp->next) {
407  if (cp->gevent[eventcode] != NULL)
408  cp->gevent[eventcode](&rt, eventcode);
409  }
410  break;
411 
412  case EVENT_CRASH:
413  for (cp = plugins_list; cp != NULL; cp = cp->next) {
414  if (cp->gevent[eventcode] != NULL)
415  cp->gevent[eventcode](&rt, eventcode);
416  }
417  break;
418 
419  case EVENT_PLAYER_DEATH:
420  /*PLAYER_DEATH: op*/
421  op = va_arg(args, object *);
422  op2 = va_arg(args, object *);
423  for (cp = plugins_list; cp != NULL; cp = cp->next) {
424  if (cp->gevent[eventcode] != NULL)
425  cp->gevent[eventcode](&rt, eventcode, op, op2);
426  }
427  break;
428 
429  case EVENT_GKILL:
430  /*GKILL: op, hitter*/
431  op = va_arg(args, object *);
432  op2 = va_arg(args, object *);
433  for (cp = plugins_list; cp != NULL; cp = cp->next) {
434  if (cp->gevent[eventcode] != NULL)
435  cp->gevent[eventcode](&rt, eventcode, op, op2);
436  }
437  break;
438 
439  case EVENT_LOGIN:
440  /*LOGIN: pl, pl->socket.host*/
441  pl = va_arg(args, player *);
442  buf = va_arg(args, char *);
443  for (cp = plugins_list; cp != NULL; cp = cp->next) {
444  if (cp->gevent[eventcode] != NULL)
445  cp->gevent[eventcode](&rt, eventcode, pl, buf);
446  }
447  break;
448 
449  case EVENT_LOGOUT:
450  /*LOGOUT: pl, pl->socket.host*/
451  pl = va_arg(args, player *);
452  buf = va_arg(args, char *);
453  for (cp = plugins_list; cp != NULL; cp = cp->next) {
454  if (cp->gevent[eventcode] != NULL)
455  cp->gevent[eventcode](&rt, eventcode, pl, buf);
456  }
457  break;
458 
459  case EVENT_MAPENTER:
460  /*MAPENTER: op, map*/
461  op = va_arg(args, object *);
462  map = va_arg(args, mapstruct *);
463  for (cp = plugins_list; cp != NULL; cp = cp->next) {
464  if (cp->gevent[eventcode] != NULL)
465  cp->gevent[eventcode](&rt, eventcode, op, map);
466  }
467  break;
468 
469  case EVENT_MAPLEAVE:
470  /*MAPLEAVE: op, map*/
471  op = va_arg(args, object *);
472  map = va_arg(args, mapstruct *);
473  for (cp = plugins_list; cp != NULL; cp = cp->next) {
474  if (cp->gevent[eventcode] != NULL)
475  cp->gevent[eventcode](&rt, eventcode, op, map);
476  }
477  break;
478 
479  case EVENT_MAPRESET:
480  /*MAPRESET: map*/
481  map = va_arg(args, mapstruct *);
482  for (cp = plugins_list; cp != NULL; cp = cp->next) {
483  if (cp->gevent[eventcode] != NULL)
484  cp->gevent[eventcode](&rt, eventcode, map);
485  }
486  break;
487 
488  case EVENT_REMOVE:
489  /*REMOVE: op*/
490  op = va_arg(args, object *);
491  for (cp = plugins_list; cp != NULL; cp = cp->next) {
492  if (cp->gevent[eventcode] != NULL)
493  cp->gevent[eventcode](&rt, eventcode, op);
494  }
495  break;
496 
497  case EVENT_SHOUT:
498  /*SHOUT: op, parms, priority*/
499  op = va_arg(args, object *);
500  buf = va_arg(args, char *);
501  i = va_arg(args, int);
502  for (cp = plugins_list; cp != NULL; cp = cp->next) {
503  if (cp->gevent[eventcode] != NULL)
504  cp->gevent[eventcode](&rt, eventcode, op, buf, i);
505  }
506  break;
507 
508  case EVENT_TELL:
509  /* Tell: who, what, to who */
510  op = va_arg(args, object *);
511  buf = va_arg(args, const char *);
512  op2 = va_arg(args, object *);
513  for (cp = plugins_list; cp != NULL; cp = cp->next) {
514  if (cp->gevent[eventcode] != NULL)
515  cp->gevent[eventcode](&rt, eventcode, op, buf, op2);
516  }
517  break;
518 
519  case EVENT_MUZZLE:
520  /*MUZZLE: op, parms*/
521  op = va_arg(args, object *);
522  buf = va_arg(args, char *);
523  for (cp = plugins_list; cp != NULL; cp = cp->next) {
524  if (cp->gevent[eventcode] != NULL)
525  cp->gevent[eventcode](&rt, eventcode, op, buf);
526  }
527  break;
528 
529  case EVENT_KICK:
530  /*KICK: op, parms*/
531  op = va_arg(args, object *);
532  buf = va_arg(args, char *);
533  for (cp = plugins_list; cp != NULL; cp = cp->next) {
534  if (cp->gevent[eventcode] != NULL)
535  cp->gevent[eventcode](&rt, eventcode, op, buf);
536  }
537  break;
538 
539  case EVENT_MAPUNLOAD:
540  /*MAPUNLOAD: map*/
541  map = va_arg(args, mapstruct *);
542  for (cp = plugins_list; cp != NULL; cp = cp->next) {
543  if (cp->gevent[eventcode] != NULL)
544  cp->gevent[eventcode](&rt, eventcode, map);
545  }
546  break;
547 
548  case EVENT_MAPLOAD:
549  /*MAPLOAD: map*/
550  map = va_arg(args, mapstruct *);
551  for (cp = plugins_list; cp != NULL; cp = cp->next) {
552  if (cp->gevent[eventcode] != NULL)
553  cp->gevent[eventcode](&rt, eventcode, map);
554  }
555  break;
556  }
557  va_end(args);
558  return 0;
559 }
560 
561 static void cfapi_get_hooks(int *type, ...) {
562  va_list args;
563  int request_type;
564  char *buf;
565  f_plug_api *rapi;
566 
567  *type = CFAPI_NONE;
568 
569  va_start(args, type);
570  request_type = va_arg(args, int);
571  if (request_type == 0) { /* By nr */
572  size_t fid;
573 
574  fid = va_arg(args, int);
575  rapi = va_arg(args, f_plug_api *);
576  if (fid >= NR_OF_HOOKS) {
577  *rapi = NULL;
578  *type = CFAPI_NONE;
579  } else {
580  *rapi = plug_hooks[fid].func;
581  *type = CFAPI_FUNC;
582  }
583  } else { /* by name */
584  size_t i;
585 
586  buf = va_arg(args, char *);
587  rapi = va_arg(args, f_plug_api *);
588  *rapi = NULL;
589  *type = CFAPI_NONE;
590  for (i = 0; i < NR_OF_HOOKS; i++) {
591  if (!strcmp(buf, plug_hooks[i].fname)) {
592  *rapi = plug_hooks[i].func;
593  *type = CFAPI_FUNC;
594  break;
595  }
596  }
597  }
598  va_end(args);
599 }
600 
607 int plugins_init_plugin(const char *libfile) {
608  LIBPTRTYPE ptr;
609  f_plug_init initfunc;
610  f_plug_property propfunc;
611  f_plug_event eventfunc;
612  f_plug_postinit postfunc;
613  f_plug_postinit closefunc;
614  int i;
615  crossfire_plugin *cp;
616  crossfire_plugin *ccp;
617  char *svn_rev;
618 
619 
620  /* Open the plugin lib and load the required functions */
621  ptr = plugins_dlopen(libfile);
622  if (ptr == NULL) {
623  LOG(llevError, "Error trying to load %s: %s\n", libfile, plugins_dlerror());
624  return -1;
625  }
626  svn_rev = (char*) plugins_dlsym(ptr, "SvnRevPlugin");
627  if (svn_rev == NULL) {
628  LOG(llevError, "Unable to find SvnRevPlugin in %s\n", libfile);
629  plugins_dlclose(ptr);
630  return -1;
631  }
632  if (settings.ignore_plugin_compatibility == 0 && strcmp(svn_rev, SVN_REV)) {
633  LOG(llevError, "SVN Version mismatch in in %s (%s != %s)\n", libfile, svn_rev, SVN_REV);
634  plugins_dlclose(ptr);
635  return -1;
636  }
637 
638  initfunc = (f_plug_init)plugins_dlsym(ptr, "initPlugin");
639  if (initfunc == NULL) {
640  LOG(llevError, "Plugin error while requesting %s.initPlugin: %s\n", libfile, plugins_dlerror());
641  plugins_dlclose(ptr);
642  return -1;
643  }
644  propfunc = (f_plug_property)plugins_dlsym(ptr, "getPluginProperty");
645  if (propfunc == NULL) {
646  LOG(llevError, "Plugin error while requesting %s.getPluginProperty: %s\n", libfile, plugins_dlerror());
647  plugins_dlclose(ptr);
648  return -1;
649  }
650  eventfunc = (f_plug_event)plugins_dlsym(ptr, "eventListener");
651  if (eventfunc == NULL) {
652  LOG(llevError, "Plugin error while requesting %s.eventListener: %s\n", libfile, plugins_dlerror());
653  plugins_dlclose(ptr);
654  return -1;
655  }
656  postfunc = (f_plug_postinit)plugins_dlsym(ptr, "postInitPlugin");
657  if (postfunc == NULL) {
658  LOG(llevError, "Plugin error while requesting %s.postInitPlugin: %s\n", libfile, plugins_dlerror());
659  plugins_dlclose(ptr);
660  return -1;
661  }
662  closefunc = (f_plug_postinit)plugins_dlsym(ptr, "closePlugin");
663  if (closefunc == NULL) {
664  LOG(llevError, "Plugin error while requesting %s.closePlugin: %s\n", libfile, plugins_dlerror());
665  plugins_dlclose(ptr);
666  return -1;
667  }
668  i = initfunc("2.0", cfapi_get_hooks);
669  cp = malloc(sizeof(crossfire_plugin));
670  for (i = 0; i < NR_EVENTS; i++)
671  cp->gevent[i] = NULL;
672  cp->eventfunc = eventfunc;
673  cp->propfunc = propfunc;
674  cp->closefunc = closefunc;
675  cp->libptr = ptr;
676  propfunc(&i, "Identification", cp->id, sizeof(cp->id));
677  propfunc(&i, "FullName", cp->fullname, sizeof(cp->fullname));
678  cp->next = NULL;
679  cp->prev = NULL;
680  if (plugins_list == NULL) {
681  plugins_list = cp;
682  } else {
683  for (ccp = plugins_list; ccp->next != NULL; ccp = ccp->next)
684  ;
685  ccp->next = cp;
686  cp->prev = ccp;
687  }
688  postfunc();
689  return 0;
690 }
691 
698 int plugins_remove_plugin(const char *id) {
699  crossfire_plugin *cp;
700 
701  if (plugins_list == NULL)
702  return -1;
703 
704  for (cp = plugins_list; cp != NULL; cp = cp->next) {
705  if (!strcmp(id, cp->id)) {
706  crossfire_plugin *n;
707  crossfire_plugin *p;
708 
709  n = cp->next;
710  p = cp->prev;
711  if (cp->closefunc)
712  cp->closefunc();
713  plugins_dlclose(cp->libptr);
714  if (n != NULL) {
715  if (p != NULL) {
716  n->prev = p;
717  p->next = n;
718  } else {
719  n->prev = NULL;
720  plugins_list = n;
721  }
722  } else {
723  if (p != NULL)
724  p->next = NULL;
725  else
726  plugins_list = NULL;
727  }
728  free(cp);
729  return 0;
730  }
731  }
732  return -1;
733 }
734 
740 void plugins_display_list(object *op) {
741  crossfire_plugin *cp;
742 
744  "List of loaded plugins:\n-----------------------");
745 
746  if (plugins_list == NULL)
747  return;
748 
749  for (cp = plugins_list; cp != NULL; cp = cp->next) {
751  "%s, %s",
752  cp->id, cp->fullname);
753  }
754 }
755 
756 /* SYSTEM-RELATED HOOKS */
757 
763 static void cfapi_cost_string_from_value(int *type, ...) {
764  uint64_t cost;
765  char *buffer, *final;
766  int length, largest_coin;
767  va_list args;
768 
769  va_start(args, type);
770  cost = va_arg(args, uint64_t);
771  largest_coin = va_arg(args, int);
772  buffer = va_arg(args, char*);
773  length = va_arg(args, int);
774  va_end(args);
775 
776  *type = CFAPI_NONE;
777 
778  if (length < 1)
779  return;
780 
781  final = cost_string_from_value(cost, largest_coin);
782 
783  strncpy(buffer, final, length - 1);
784  buffer[length - 1] = '\0';
785  free(final);
786 }
787 
793 static void cfapi_system_find_animation(int *type, ...) {
794  va_list args;
795  const char *anim;
796  int *num;
797 
798  va_start(args, type);
799  anim = va_arg(args, const char *);
800  num = va_arg(args, int *);
801  va_end(args);
802 
803  *num = find_animation(anim);
804  *type = CFAPI_INT;
805 }
806 
812 static void cfapi_system_find_face(int *type, ...) {
813  va_list args;
814  const char *face;
815  int error;
816  int *num;
817 
818  va_start(args, type);
819  face = va_arg(args, const char *);
820  error = va_arg(args, int);
821  num = va_arg(args, int *);
822  va_end(args);
823 
824  *num = find_face(face, error);
825  *type = CFAPI_INT;
826 }
827 
833 static void cfapi_system_strdup_local(int *type, ...) {
834  va_list args;
835  const char *txt;
836  char **ret;
837 
838  va_start(args, type);
839  txt = va_arg(args, const char *);
840  ret = va_arg(args, char **);
841  va_end(args);
842 
843  *ret = strdup_local(txt);
844  *type = CFAPI_STRING;
845 }
846 
847 static void cfapi_system_register_global_event(int *type, ...) {
848  va_list args;
849  int eventcode;
850  char *pname;
851  f_plug_event hook;
852  crossfire_plugin *cp;
853 
854  va_start(args, type);
855  eventcode = va_arg(args, int);
856  pname = va_arg(args, char *);
857  hook = va_arg(args, f_plug_event);
858  va_end(args);
859 
860  *type = CFAPI_NONE;
861 
862  cp = plugins_find_plugin(pname);
863  cp->gevent[eventcode] = hook;
864 }
865 
866 static void cfapi_system_unregister_global_event(int *type, ...) {
867  va_list args;
868  int eventcode;
869  char *pname;
870  crossfire_plugin *cp;
871 
872  va_start(args, type);
873  eventcode = va_arg(args, int);
874  pname = va_arg(args, char *);
875  va_end(args);
876 
877  *type = CFAPI_NONE;
878 
879  cp = plugins_find_plugin(pname);
880  cp->gevent[eventcode] = NULL;
881 }
882 
889 static void cfapi_system_add_string(int *type, ...) {
890  va_list args;
891  const char *str;
892  sstring *rv;
893 
894  va_start(args, type);
895  str = va_arg(args, const char *);
896  rv = va_arg(args, sstring *);
897  va_end(args);
898 
899  *rv = add_string(str);
900  *type = CFAPI_SSTRING;
901 }
902 
909 static void cfapi_system_remove_string(int *type, ...) {
910  va_list args;
911  sstring str;
912 
913  va_start(args, type);
914  str = va_arg(args, sstring);
915  va_end(args);
916 
917  free_string(str);
918  *type = CFAPI_NONE;
919 }
920 
927 static void cfapi_system_find_string(int *type, ...) {
928  va_list args;
929  const char *str;
930  sstring *rv;
931 
932  va_start(args, type);
933  str = va_arg(args, const char *);
934  rv = va_arg(args, sstring *);
935  va_end(args);
936 
937  *rv = find_string(str);
938  *type = CFAPI_SSTRING;
939 }
940 
946 static void cfapi_system_check_path(int *type, ...) {
947  va_list args;
948  const char *name;
949  int prepend_dir;
950  int *ret;
951 
952  va_start(args, type);
953 
954  name = va_arg(args, char *);
955  prepend_dir = va_arg(args, int);
956  ret = va_arg(args, int *);
957 
958  *ret = check_path(name, prepend_dir);
959 
960  va_end(args);
961  *type = CFAPI_INT;
962 }
963 
969 static void cfapi_system_re_cmp(int *type, ...) {
970  va_list args;
971  const char *str;
972  const char *regexp;
973  const char **rv;
974 
975  va_start(args, type);
976 
977  str = va_arg(args, char *);
978  regexp = va_arg(args, char *);
979  rv = va_arg(args, const char **);
980 
981  *rv = re_cmp(str, regexp);
982 
983  va_end(args);
984  *type = CFAPI_STRING;
985 }
986 
987 static void cfapi_system_directory(int *type, ...) {
988  va_list args;
989  int dirtype;
990  const char **str;
991 
992  va_start(args, type);
993 
994  dirtype = va_arg(args, int);
995  str = va_arg(args, const char **);
996  va_end(args);
997 
998  *type = CFAPI_STRING;
999 
1000  switch (dirtype) {
1001  case 0:
1002  *str = settings.mapdir;
1003  break;
1004 
1005  case 1:
1006  *str = settings.uniquedir;
1007  break;
1008 
1009  case 2:
1010  *str = settings.tmpdir;
1011  break;
1012 
1013  case 3:
1014  *str = settings.confdir;
1015  break;
1016 
1017  case 4:
1018  *str = settings.localdir;
1019  break;
1020 
1021  case 5:
1022  *str = settings.playerdir;
1023  break;
1024 
1025  case 6:
1026  *str = settings.datadir;
1027  break;
1028 
1029  default:
1030  *str = NULL;
1031  }
1032 }
1033 
1040 static void cfapi_get_time(int *type, ...) {
1041  va_list args;
1042  timeofday_t *tod;
1043 
1044  va_start(args, type);
1045  tod = va_arg(args, timeofday_t *);
1046  va_end(args);
1047 
1048  get_tod(tod);
1049  *type = CFAPI_NONE;
1050 }
1051 
1052 #define string_get_int(name) \
1053  va_list args; \
1054  int index; \
1055  const char **str; \
1056  va_start(args, type); \
1057  index = va_arg(args, int); \
1058  str = va_arg(args, const char **); \
1059  va_end(args); \
1060  *str = name(index); \
1061  *type = CFAPI_STRING; \
1062 
1063 
1071 static void cfapi_get_season_name(int *type, ...) {
1073 }
1074 
1083 static void cfapi_get_weekday_name(int *type, ...) {
1085 }
1086 
1095 static void cfapi_get_month_name(int *type, ...) {
1097 }
1098 
1107 static void cfapi_get_periodofday_name(int *type, ...) {
1109 }
1110 
1122 static void cfapi_timer_create(int *type, ...) {
1123  va_list args;
1124  int res;
1125  object *ob;
1126  long delay;
1127  int mode;
1128  int *timer;
1129 
1130  va_start(args, type);
1131  ob = va_arg(args, object *);
1132  delay = va_arg(args, long);
1133  mode = va_arg(args, int);
1134  timer = va_arg(args, int *);
1135  va_end(args);
1136  *type = CFAPI_INT;
1137 
1138  *timer = cftimer_find_free_id();
1139  if (*timer != TIMER_ERR_ID) {
1140  res = cftimer_create(*timer, delay, ob, mode);
1141  if (res != TIMER_ERR_NONE)
1142  *timer = res;
1143  }
1144 }
1145 
1155 static void cfapi_timer_destroy(int *type, ...) {
1156  va_list args;
1157  int id;
1158  int *err;
1159 
1160  va_start(args, type);
1161  id = va_arg(args, int);
1162  err = va_arg(args, int *);
1163  va_end(args);
1164  *type = CFAPI_INT;
1165 
1166  *err = cftimer_destroy(id);
1167 }
1168 
1174 static void cfapi_log(int *type, ...) {
1175  va_list args;
1176  LogLevel logLevel;
1177  const char *message;
1178 
1179  va_start(args, type);
1180  logLevel = va_arg(args, LogLevel);
1181  message = va_arg(args, const char *);
1182  LOG(logLevel, "%s", message);
1183  va_end(args);
1184 
1185  *type = CFAPI_NONE;
1186 }
1187 
1188 /* MAP RELATED HOOKS */
1189 
1198 static void cfapi_map_get_map(int *type, ...) {
1199  va_list args;
1200  mapstruct **ret;
1201  int ctype;
1202  int x, y;
1203  int16_t nx, ny;
1204  const char *name;
1205  mapstruct *m;
1206 
1207  va_start(args, type);
1208 
1209  ctype = va_arg(args, int);
1210 
1211  switch (ctype) {
1212  case 0:
1213  x = va_arg(args, int);
1214  y = va_arg(args, int);
1215  ret = va_arg(args, mapstruct **);
1216  *ret = get_empty_map(x, y);
1217  break;
1218 
1219  case 1:
1220  name = va_arg(args, const char *);
1221  x = va_arg(args, int);
1222  ret = va_arg(args, mapstruct **);
1223  *ret = ready_map_name(name, x);
1224  break;
1225 
1226  case 2:
1227  m = va_arg(args, mapstruct *);
1228  nx = va_arg(args, int);
1229  ny = va_arg(args, int);
1230  ret = va_arg(args, mapstruct **);
1231  *ret = get_map_from_coord(m, &nx, &ny);
1232  break;
1233 
1234  default:
1235  *type = CFAPI_NONE;
1236  va_end(args);
1237  return;
1238  break;
1239  }
1240  va_end(args);
1241  *type = CFAPI_PMAP;
1242 }
1243 
1249 static void cfapi_map_has_been_loaded(int *type, ...) {
1250  va_list args;
1251  mapstruct **map;
1252  char *string;
1253 
1254  va_start(args, type);
1255  string = va_arg(args, char *);
1256  map = va_arg(args, mapstruct **);
1257  *map = has_been_loaded(string);
1258  va_end(args);
1259  *type = CFAPI_PMAP;
1260 }
1261 
1267 static void cfapi_map_create_path(int *type, ...) {
1268  va_list args;
1269  int ctype, size;
1270  const char *str;
1271  char *name;
1272 
1273  va_start(args, type);
1274 
1275  ctype = va_arg(args, int);
1276  str = va_arg(args, const char *);
1277  name = va_arg(args, char *);
1278  size = va_arg(args, int);
1279  *type = CFAPI_STRING;
1280 
1281  switch (ctype) {
1282  case 0:
1283  create_pathname(str, name, size);
1284  break;
1285 
1286  case 1:
1287  create_overlay_pathname(str, name, MAX_BUF);
1288  break;
1289 
1290 /* case 2:
1291  rv = create_items_path(str);
1292  break;*/
1293 
1294  default:
1295  *type = CFAPI_NONE;
1296  break;
1297  }
1298  va_end(args);
1299 }
1300 
1301 static void cfapi_map_get_map_property(int *type, ...) {
1302  va_list args;
1303  mapstruct *map;
1304  int property;
1305 
1306  int *rint;
1307  mapstruct **rmap;
1308  sstring *rstr;
1309  region **rreg;
1310  int16_t *nx, *ny;
1311  int x, y;
1312 
1313  va_start(args, type);
1314 
1315  map = va_arg(args, mapstruct *);
1316  property = va_arg(args, int);
1317 
1318  switch (property) {
1319  case CFAPI_MAP_PROP_FLAGS:
1320  rmap = va_arg(args, mapstruct **);
1321  x = va_arg(args, int);
1322  y = va_arg(args, int);
1323  nx = va_arg(args, int16_t *);
1324  ny = va_arg(args, int16_t *);
1325  rint = va_arg(args, int *);
1326  *rint = get_map_flags(map, rmap, x, y, nx, ny);
1327  *type = CFAPI_INT;
1328  break;
1329 
1331  rint = va_arg(args, int *);
1332  *rint = calculate_difficulty(map);
1333  *type = CFAPI_INT;
1334  break;
1335 
1336  case CFAPI_MAP_PROP_PATH:
1337  rstr = va_arg(args, sstring *);
1338  *rstr = map->path;
1339  *type = CFAPI_SSTRING;
1340  break;
1341 
1343  rstr = va_arg(args, sstring *);
1344  *rstr = map->tmpname;
1345  *type = CFAPI_SSTRING;
1346  break;
1347 
1348  case CFAPI_MAP_PROP_NAME:
1349  rstr = va_arg(args, sstring *);
1350  *rstr = map->name;
1351  *type = CFAPI_SSTRING;
1352  break;
1353 
1355  rint = va_arg(args, int *);
1356  *rint = map->reset_time;
1357  *type = CFAPI_INT;
1358  break;
1359 
1361  rint = va_arg(args, int *);
1362  *rint = map->reset_timeout;
1363  *type = CFAPI_INT;
1364  break;
1365 
1367  rint = va_arg(args, int *);
1368  *rint = map->players;
1369  *type = CFAPI_INT;
1370  break;
1371 
1373  rint = va_arg(args, int *);
1374  *rint = map->darkness;
1375  *type = CFAPI_INT;
1376  break;
1377 
1378  case CFAPI_MAP_PROP_WIDTH:
1379  rint = va_arg(args, int *);
1380  *rint = map->width;
1381  *type = CFAPI_INT;
1382  break;
1383 
1384  case CFAPI_MAP_PROP_HEIGHT:
1385  rint = va_arg(args, int *);
1386  *rint = map->height;
1387  *type = CFAPI_INT;
1388  break;
1389 
1391  rint = va_arg(args, int *);
1392  *rint = map->enter_x;
1393  *type = CFAPI_INT;
1394  break;
1395 
1397  rint = va_arg(args, int *);
1398  *rint = map->enter_y;
1399  *type = CFAPI_INT;
1400  break;
1401 
1403  rstr = va_arg(args, sstring *);
1404  *rstr = map->msg;
1405  *type = CFAPI_SSTRING;
1406  break;
1407 
1408  case CFAPI_MAP_PROP_NEXT:
1409  rmap = va_arg(args, mapstruct **);
1410  *rmap = map ? map->next : first_map;
1411  *type = CFAPI_PMAP;
1412  break;
1413 
1414  case CFAPI_MAP_PROP_REGION:
1415  rreg = va_arg(args, region **);
1416  *rreg = get_region_by_map(map);
1417  *type = CFAPI_PREGION;
1418  break;
1419 
1420  case CFAPI_MAP_PROP_UNIQUE:
1421  rint = va_arg(args, int *);
1422  *rint = map->unique;
1423  *type = CFAPI_INT;
1424  break;
1425 
1426  default:
1427  *type = CFAPI_NONE;
1428  break;
1429  }
1430  va_end(args);
1431 }
1432 
1433 static void cfapi_map_set_map_property(int *type, ...) {
1434  va_list args;
1435  mapstruct *map;
1436  int property;
1437  const char *buf;
1438 
1439  va_start(args, type);
1440 
1441  map = va_arg(args, mapstruct *);
1442  property = va_arg(args, int);
1443 
1444  switch (property) {
1445  case CFAPI_MAP_PROP_PATH:
1446  buf = va_arg(args, const char *);
1447  snprintf(map->path, sizeof(map->path), "%s", buf);
1448  *type = CFAPI_STRING;
1449  break;
1450 
1451  default:
1452  *type = CFAPI_NONE;
1453  break;
1454  }
1455  va_end(args);
1456 }
1457 
1463 static void cfapi_map_out_of_map(int *type, ...) {
1464  va_list args;
1465  mapstruct *map;
1466  int x, y;
1467  int *rint;
1468 
1469  va_start(args, type);
1470  map = va_arg(args, mapstruct *);
1471  x = va_arg(args, int);
1472  y = va_arg(args, int);
1473  rint = va_arg(args, int *);
1474 
1475  *rint = out_of_map(map, x, y);
1476  va_end(args);
1477  *type = CFAPI_INT;
1478 }
1479 
1485 static void cfapi_map_update_position(int *type, ...) {
1486  va_list args;
1487  mapstruct *map;
1488  int x, y;
1489 
1490  va_start(args, type);
1491 
1492  map = va_arg(args, mapstruct *);
1493  x = va_arg(args, int);
1494  y = va_arg(args, int);
1495 
1496  update_position(map, x, y);
1497  va_end(args);
1498  *type = CFAPI_NONE;
1499 }
1500 
1501 static void cfapi_map_delete_map(int *type, ...) {
1502  va_list args;
1503  mapstruct *map;
1504  va_start(args, type);
1505 
1506  map = va_arg(args, mapstruct *);
1507 
1508  delete_map(map);
1509 
1510  va_end(args);
1511  *type = CFAPI_NONE;
1512 }
1513 
1514 static void cfapi_map_message(int *type, ...) {
1515  va_list args;
1516  mapstruct *map;
1517  const char *string;
1518  int color;
1519 
1520  va_start(args, type);
1521  map = va_arg(args, mapstruct *);
1522  string = va_arg(args, const char *);
1523  color = va_arg(args, int);
1524  va_end(args);
1525 
1526  /* function should be extended to take message types probably */
1527  ext_info_map(color, map, MSG_TYPE_MISC, MSG_SUBTYPE_NONE, string);
1528  *type = CFAPI_NONE;
1529 }
1530 
1536 static void cfapi_map_get_object_at(int *type, ...) {
1537  va_list args;
1538  mapstruct *map;
1539  int x, y;
1540  int16_t sx, sy;
1541  object **robj;
1542 
1543  va_start(args, type);
1544  map = va_arg(args, mapstruct *);
1545  x = va_arg(args, int);
1546  y = va_arg(args, int);
1547  robj = va_arg(args, object **);
1548  va_end(args);
1549 
1550  sx = x;
1551  sy = y;
1552  if (get_map_flags(map, &map, x, y, &sx, &sy)&P_OUT_OF_MAP)
1553  *robj = NULL;
1554  else
1555  *robj = GET_MAP_OB(map, sx, sy);
1556  *type = CFAPI_POBJECT;
1557 }
1558 
1565 static void cfapi_map_find_by_archetype_name(int *type, ...) {
1566  va_list args;
1567  int x, y;
1568  mapstruct *map;
1569  char *msg;
1570  object **robj;
1571 
1572  va_start(args, type);
1573 
1574  msg = va_arg(args, char *);
1575  map = va_arg(args, mapstruct *);
1576  x = va_arg(args, int);
1577  y = va_arg(args, int);
1578  robj = va_arg(args, object **);
1579 
1580  va_end(args);
1581 
1582  *robj = map_find_by_archetype(map, x, y, try_find_archetype(msg));
1583  *type = CFAPI_POBJECT;
1584 }
1585 
1591 static void cfapi_map_change_light(int *type, ...) {
1592  va_list args;
1593  int change;
1594  mapstruct *map;
1595  int *rint;
1596 
1597  va_start(args, type);
1598  map = va_arg(args, mapstruct *);
1599  change = va_arg(args, int);
1600  rint = va_arg(args, int *);
1601  va_end(args);
1602 
1603  *type = CFAPI_INT;
1604  *rint = change_map_light(map, change);
1605 }
1606 
1607 /* OBJECT-RELATED HOOKS */
1608 
1622 static void cfapi_object_move(int *type, ...) {
1623  va_list args;
1624  int kind;
1625  object *op;
1626  object *activator;
1627  player *pl;
1628  int direction;
1629  int *ret;
1630 
1631  va_start(args, type);
1632  kind = va_arg(args, int);
1633  switch (kind) {
1634  case 0:
1635  op = va_arg(args, object *);
1636  direction = va_arg(args, int);
1637  activator = va_arg(args, object *);
1638  ret = va_arg(args, int *);
1639  va_end(args);
1640  *ret = move_ob(op, direction, activator);
1641  break;
1642 
1643  case 1:
1644  pl = va_arg(args, player *);
1645  direction = va_arg(args, int);
1646  ret = va_arg(args, int *);
1647  va_end(args);
1648  *ret = move_player(pl->ob, direction);
1649  break;
1650 
1651  case 2:
1652  op = va_arg(args, object *);
1653  ret = va_arg(args, int *);
1654  va_end(args);
1655  *ret = player_arrest(op);
1656  }
1657 
1658  va_end(args);
1659  *type = CFAPI_INT;
1660 }
1661 
1669 static void cfapi_object_get_key(int *type, ...) {
1670  va_list args;
1671  const char *keyname;
1672  const char **value;
1673  object *op;
1674 
1675  va_start(args, type);
1676  op = va_arg(args, object *);
1677  keyname = va_arg(args, const char *);
1678  value = va_arg(args, const char **);
1679  va_end(args);
1680 
1681  *value = object_get_value(op, keyname);
1682  *type = CFAPI_SSTRING;
1683 }
1684 
1691 static void cfapi_object_set_key(int *type, ...) {
1692  va_list args;
1693  const char *keyname;
1694  const char *value;
1695  int *ret;
1696  object *op;
1697  int add_key;
1698 
1699  va_start(args, type);
1700  op = va_arg(args, object *);
1701  keyname = va_arg(args, char *);
1702  value = va_arg(args, char *);
1703  add_key = va_arg(args, int);
1704  ret = va_arg(args, int *);
1705  va_end(args);
1706 
1707  *ret = object_set_value(op, keyname, value, add_key);
1708  *type = CFAPI_INT;
1709 }
1710 
1714 static void cfapi_object_get_property(int *type, ...) {
1715  va_list args;
1716  int property;
1717  object *op;
1718  int *rint;
1719  object **robject;
1720  mapstruct **rmap;
1721  float *rfloat;
1722  archetype **rarch;
1723  sstring *rsstring;
1724  char *rbuffer;
1725  int rbufsize;
1726  MoveType *rmove;
1727  int64_t *rint64;
1728  partylist **rparty;
1729  double *rdouble;
1730  long *rlong;
1731 
1732  va_start(args, type);
1733 
1734  op = va_arg(args, object *);
1735  property = va_arg(args, int);
1736  switch (property) {
1738  robject = va_arg(args, object **);
1739  *robject = op->above;
1740  *type = CFAPI_POBJECT;
1741  break;
1742 
1744  robject = va_arg(args, object **);
1745  *robject = op->below;
1746  *type = CFAPI_POBJECT;
1747  break;
1748 
1750  robject = va_arg(args, object **);
1751  *robject = op->active_next;
1752  *type = CFAPI_POBJECT;
1753  break;
1754 
1756  robject = va_arg(args, object **);
1757  *robject = op->active_prev;
1758  *type = CFAPI_POBJECT;
1759  break;
1760 
1762  robject = va_arg(args, object **);
1763  *robject = op->inv;
1764  *type = CFAPI_POBJECT;
1765  break;
1766 
1768  robject = va_arg(args, object **);
1769  *robject = op->env;
1770  *type = CFAPI_POBJECT;
1771  break;
1772 
1774  robject = va_arg(args, object **);
1775  *robject = op->head;
1776  *type = CFAPI_POBJECT;
1777  break;
1778 
1780  robject = va_arg(args, object **);
1781  *robject = op->container;
1782  *type = CFAPI_POBJECT;
1783  break;
1784 
1785  case CFAPI_OBJECT_PROP_MAP:
1786  rmap = va_arg(args, mapstruct **);
1787  *rmap = op->map;
1788  *type = CFAPI_PMAP;
1789  break;
1790 
1792  rint = va_arg(args, int *);
1793  *rint = op->count;
1794  *type = CFAPI_INT;
1795  break;
1796 
1798  rbuffer = va_arg(args, char *);
1799  rbufsize = va_arg(args, int);
1800  query_name(op, rbuffer, rbufsize);
1801  *type = CFAPI_STRING;
1802  break;
1803 
1805  rsstring = va_arg(args, sstring *);
1806  *rsstring = op->name_pl;
1807  *type = CFAPI_SSTRING;
1808  break;
1809 
1811  rsstring = va_arg(args, sstring *);
1812  *rsstring = op->title;
1813  *type = CFAPI_SSTRING;
1814  break;
1815 
1817  rsstring = va_arg(args, sstring *);
1818  *rsstring = op->race;
1819  *type = CFAPI_SSTRING;
1820  break;
1821 
1823  rsstring = va_arg(args, sstring *);
1824  *rsstring = op->slaying;
1825  *type = CFAPI_SSTRING;
1826  break;
1827 
1829  rsstring = va_arg(args, sstring *);
1830  *rsstring = op->skill;
1831  *type = CFAPI_SSTRING;
1832  break;
1833 
1835  rsstring = va_arg(args, sstring *);
1836  *rsstring = op->msg;
1837  *type = CFAPI_SSTRING;
1838  break;
1839 
1841  rsstring = va_arg(args, sstring *);
1842  *rsstring = op->lore;
1843  *type = CFAPI_SSTRING;
1844  break;
1845 
1846  case CFAPI_OBJECT_PROP_X:
1847  rint = va_arg(args, int *);
1848  *rint = op->x;
1849  *type = CFAPI_INT;
1850  break;
1851 
1852  case CFAPI_OBJECT_PROP_Y:
1853  rint = va_arg(args, int *);
1854  *rint = op->y;
1855  *type = CFAPI_INT;
1856  break;
1857 
1859  rfloat = va_arg(args, float *);
1860  *rfloat = op->speed;
1861  *type = CFAPI_FLOAT;
1862  break;
1863 
1865  rfloat = va_arg(args, float *);
1866  *rfloat = op->speed_left;
1867  *type = CFAPI_FLOAT;
1868  break;
1869 
1871  rint = va_arg(args, int *);
1872  *rint = op->nrof;
1873  *type = CFAPI_INT;
1874  break;
1875 
1877  rint = va_arg(args, int *);
1878  *rint = op->direction;
1879  *type = CFAPI_INT;
1880  break;
1881 
1883  rint = va_arg(args, int *);
1884  *rint = op->facing;
1885  *type = CFAPI_INT;
1886  break;
1887 
1889  rint = va_arg(args, int *);
1890  *rint = op->type;
1891  *type = CFAPI_INT;
1892  break;
1893 
1895  rint = va_arg(args, int *);
1896  *rint = op->subtype;
1897  *type = CFAPI_INT;
1898  break;
1899 
1901  rint = va_arg(args, int *);
1902  *rint = op->client_type;
1903  *type = CFAPI_INT;
1904  break;
1905 
1906  case CFAPI_OBJECT_PROP_RESIST: {
1907  int idx;
1908  int16_t *resist;
1909 
1910  idx = va_arg(args, int);
1911  resist = va_arg(args, int16_t *);
1912  *resist = op->resist[idx];
1913  }
1914  *type = CFAPI_INT16;
1915  break;
1916 
1918  rint = va_arg(args, int *);
1919  *rint = op->attacktype;
1920  *type = CFAPI_INT;
1921  break;
1922 
1924  rint = va_arg(args, int *);
1925  *rint = op->path_attuned;
1926  *type = CFAPI_INT;
1927  break;
1928 
1930  rint = va_arg(args, int *);
1931  *rint = op->path_repelled;
1932  *type = CFAPI_INT;
1933  break;
1934 
1936  rint = va_arg(args, int *);
1937  *rint = op->path_denied;
1938  *type = CFAPI_INT;
1939  break;
1940 
1942  rint = va_arg(args, int *);
1943  *rint = op->material;
1944  *type = CFAPI_INT;
1945  break;
1946 
1948  rsstring = va_arg(args, sstring *);
1949  *rsstring = op->materialname;
1950  *type = CFAPI_SSTRING;
1951  break;
1952 
1954  rint = va_arg(args, int *);
1955  *rint = op->magic;
1956  *type = CFAPI_INT;
1957  break;
1958 
1960  rlong = va_arg(args, long *);
1961  *rlong = op->value;
1962  *type = CFAPI_LONG;
1963  break;
1964 
1966  rint = va_arg(args, int *);
1967  *rint = op->level;
1968  *type = CFAPI_INT;
1969  break;
1970 
1972  rint = va_arg(args, int *);
1973  *rint = op->last_heal;
1974  *type = CFAPI_INT;
1975  break;
1976 
1978  rint = va_arg(args, int *);
1979  *rint = op->last_sp;
1980  *type = CFAPI_INT;
1981  break;
1982 
1984  rint = va_arg(args, int *);
1985  *rint = op->last_grace;
1986  *type = CFAPI_INT;
1987  break;
1988 
1990  rint = va_arg(args, int *);
1991  *rint = op->last_eat;
1992  *type = CFAPI_INT;
1993  break;
1994 
1996  rint = va_arg(args, int *);
1997  *rint = op->invisible;
1998  *type = CFAPI_INT;
1999  break;
2000 
2002  rint = va_arg(args, int *);
2003  *rint = op->pick_up;
2004  *type = CFAPI_INT;
2005  break;
2006 
2008  rint = va_arg(args, int *);
2009  *rint = op->item_power;
2010  *type = CFAPI_INT;
2011  break;
2012 
2014  rint = va_arg(args, int *);
2015  *rint = op->gen_sp_armour;
2016  *type = CFAPI_INT;
2017  break;
2018 
2020  rint = va_arg(args, int *);
2021  *rint = op->weight;
2022  *type = CFAPI_INT;
2023  break;
2024 
2026  rint = va_arg(args, int *);
2027  *rint = op->weight_limit;
2028  *type = CFAPI_INT;
2029  break;
2030 
2032  rint = va_arg(args, int *);
2033  *rint = op->carrying;
2034  *type = CFAPI_INT;
2035  break;
2036 
2038  rint = va_arg(args, int *);
2039  *rint = op->glow_radius;
2040  *type = CFAPI_INT;
2041  break;
2042 
2044  rint64 = va_arg(args, int64_t *);
2045  *rint64 = op->perm_exp;
2046  *type = CFAPI_SINT64;
2047  break;
2048 
2050  robject = va_arg(args, object **);
2051  *robject = op->current_weapon;
2052  *type = CFAPI_POBJECT;
2053  break;
2054 
2056  robject = va_arg(args, object **);
2057  *robject = op->enemy;
2058  *type = CFAPI_POBJECT;
2059  break;
2060 
2062  robject = va_arg(args, object **);
2063  *robject = op->attacked_by;
2064  *type = CFAPI_POBJECT;
2065  break;
2066 
2068  rint = va_arg(args, int *);
2069  *rint = op->run_away;
2070  *type = CFAPI_INT;
2071  break;
2072 
2074  robject = va_arg(args, object **);
2075  *robject = op->chosen_skill;
2076  *type = CFAPI_POBJECT;
2077  break;
2078 
2080  rint = va_arg(args, int *);
2081  *rint = op->hide;
2082  *type = CFAPI_INT;
2083  break;
2084 
2086  rint = va_arg(args, int *);
2087  *rint = op->move_status;
2088  *type = CFAPI_INT;
2089  break;
2090 
2092  rint = va_arg(args, int *);
2093  *rint = op->attack_movement;
2094  *type = CFAPI_INT;
2095  break;
2096 
2098  robject = va_arg(args, object **);
2099  *robject = op->spellitem;
2100  *type = CFAPI_POBJECT;
2101  break;
2102 
2104  rdouble = va_arg(args, double *);
2105  *rdouble = op->expmul;
2106  *type = CFAPI_DOUBLE;
2107  break;
2108 
2110  rarch = va_arg(args, archetype **);
2111  *rarch = op->arch;
2112  *type = CFAPI_PARCH;
2113  break;
2114 
2116  rarch = va_arg(args, archetype **);
2117  *rarch = op->other_arch;
2118  *type = CFAPI_PARCH;
2119  break;
2120 
2122  rsstring = va_arg(args, sstring *);
2123  *rsstring = op->custom_name;
2124  *type = CFAPI_SSTRING;
2125  break;
2126 
2128  rint = va_arg(args, int *);
2129  *rint = op->anim_speed;
2130  *type = CFAPI_INT;
2131  break;
2132 
2134  rint = va_arg(args, int *);
2135  *rint = is_friendly(op);
2136  *type = CFAPI_INT;
2137  break;
2138 
2140  rbuffer = va_arg(args, char *);
2141  rbufsize = va_arg(args, int);
2142  query_short_name(op, rbuffer, rbufsize);
2143  *type = CFAPI_STRING;
2144  break;
2145 
2147  int i;
2148 
2149  i = va_arg(args, int);
2150  rbuffer = va_arg(args, char *);
2151  rbufsize = va_arg(args, int);
2152  query_base_name(op, i, rbuffer, rbufsize);
2153  *type = CFAPI_STRING;
2154  }
2155  break;
2156 
2158  rsstring = va_arg(args, sstring *);
2159  *rsstring = op->name;
2160  *type = CFAPI_SSTRING;
2161  break;
2162 
2164  rint = va_arg(args, int *);
2165  *rint = is_magical(op);
2166  *type = CFAPI_INT;
2167  break;
2168 
2170  rint = va_arg(args, int *);
2171  *rint = op->stats.luck;
2172  *type = CFAPI_INT;
2173  break;
2174 
2175  case CFAPI_OBJECT_PROP_EXP:
2176  rint64 = va_arg(args, int64_t *);
2177  *rint64 = op->stats.exp;
2178  *type = CFAPI_SINT64;
2179  break;
2180 
2182  robject = va_arg(args, object **);
2183  *robject = object_get_owner(op);
2184  *type = CFAPI_POBJECT;
2185  break;
2186 
2188  int stype;
2189 
2190  stype = va_arg(args, int);
2191  switch (stype) {
2192  unsigned char ptype;
2193  char *buf;
2194  archetype *at;
2195 
2196  case 0: /* present_in_ob */
2197  ptype = (unsigned char)(va_arg(args, int));
2198  robject = va_arg(args, object **);
2199  *robject = object_present_in_ob(ptype, op);
2200  break;
2201 
2202  case 1: /* present_in_ob_by_name */
2203  ptype = (unsigned char)(va_arg(args, int));
2204  buf = va_arg(args, char *);
2205  robject = va_arg(args, object **);
2206  *robject = object_present_in_ob_by_name(ptype, buf, op);
2207  break;
2208 
2209  case 2: /* arch_present_in_ob */
2210  at = va_arg(args, archetype *);
2211  robject = va_arg(args, object **);
2212  *robject = arch_present_in_ob(at, op);
2213  break;
2214  }
2215  }
2216  *type = CFAPI_POBJECT;
2217  break;
2218 
2220  rint = va_arg(args, int *);
2221  *rint = (QUERY_FLAG(op, FLAG_WAS_WIZ));
2222  *type = CFAPI_INT;
2223  break;
2224 
2226  object *op2;
2227 
2228  op2 = va_arg(args, object *);
2229  rint = va_arg(args, int *);
2230  *rint = object_can_merge(op, op2);
2231  }
2232  *type = CFAPI_INT;
2233  break;
2234 
2236  object *op2;
2237 
2238  op2 = va_arg(args, object *);
2239  rint = va_arg(args, int *);
2240  *rint = object_can_pick(op2, op);
2241  }
2242  *type = CFAPI_INT;
2243  break;
2244 
2245  case CFAPI_OBJECT_PROP_FLAGS: {
2246  int fl;
2247 
2248  fl = va_arg(args, int);
2249  rint = va_arg(args, int *);
2250  *rint = QUERY_FLAG(op, fl);
2251  }
2252  *type = CFAPI_INT;
2253  break;
2254 
2255  case CFAPI_OBJECT_PROP_STR:
2256  rint = va_arg(args, int *);
2257  *rint = op->stats.Str;
2258  *type = CFAPI_INT;
2259  break;
2260 
2261  case CFAPI_OBJECT_PROP_DEX:
2262  rint = va_arg(args, int *);
2263  *rint = op->stats.Dex;
2264  *type = CFAPI_INT;
2265  break;
2266 
2267  case CFAPI_OBJECT_PROP_CON:
2268  rint = va_arg(args, int *);
2269  *rint = op->stats.Con;
2270  *type = CFAPI_INT;
2271  break;
2272 
2273  case CFAPI_OBJECT_PROP_WIS:
2274  rint = va_arg(args, int *);
2275  *rint = op->stats.Wis;
2276  *type = CFAPI_INT;
2277  break;
2278 
2279  case CFAPI_OBJECT_PROP_INT:
2280  rint = va_arg(args, int *);
2281  *rint = op->stats.Int;
2282  *type = CFAPI_INT;
2283  break;
2284 
2285  case CFAPI_OBJECT_PROP_POW:
2286  rint = va_arg(args, int *);
2287  *rint = op->stats.Pow;
2288  *type = CFAPI_INT;
2289  break;
2290 
2291  case CFAPI_OBJECT_PROP_CHA:
2292  rint = va_arg(args, int *);
2293  *rint = op->stats.Cha;
2294  *type = CFAPI_INT;
2295  break;
2296 
2297  case CFAPI_OBJECT_PROP_WC:
2298  rint = va_arg(args, int *);
2299  *rint = op->stats.wc;
2300  *type = CFAPI_INT;
2301  break;
2302 
2303  case CFAPI_OBJECT_PROP_AC:
2304  rint = va_arg(args, int *);
2305  *rint = op->stats.ac;
2306  *type = CFAPI_INT;
2307  break;
2308 
2309  case CFAPI_OBJECT_PROP_HP:
2310  rint = va_arg(args, int *);
2311  *rint = op->stats.hp;
2312  *type = CFAPI_INT;
2313  break;
2314 
2315  case CFAPI_OBJECT_PROP_SP:
2316  rint = va_arg(args, int *);
2317  *rint = op->stats.sp;
2318  *type = CFAPI_INT;
2319  break;
2320 
2321  case CFAPI_OBJECT_PROP_GP:
2322  rint = va_arg(args, int *);
2323  *rint = op->stats.grace;
2324  *type = CFAPI_INT;
2325  break;
2326 
2327  case CFAPI_OBJECT_PROP_FP:
2328  rint = va_arg(args, int *);
2329  *rint = op->stats.food;
2330  *type = CFAPI_INT;
2331  break;
2332 
2334  rint = va_arg(args, int *);
2335  *rint = op->stats.maxhp;
2336  *type = CFAPI_INT;
2337  break;
2338 
2340  rint = va_arg(args, int *);
2341  *rint = op->stats.maxsp;
2342  *type = CFAPI_INT;
2343  break;
2344 
2346  rint = va_arg(args, int *);
2347  *rint = op->stats.maxgrace;
2348  *type = CFAPI_INT;
2349  break;
2350 
2351  case CFAPI_OBJECT_PROP_DAM:
2352  rint = va_arg(args, int *);
2353  *rint = op->stats.dam;
2354  *type = CFAPI_INT;
2355  break;
2356 
2357  case CFAPI_OBJECT_PROP_GOD:
2358  rsstring = va_arg(args, sstring *);
2359  *rsstring = determine_god(op);
2360  *type = CFAPI_SSTRING;
2361  break;
2362 
2364  rsstring = va_arg(args, sstring *);
2365  *rsstring = op->arch->name;
2366  *type = CFAPI_SSTRING;
2367  break;
2368 
2370  rint = va_arg(args, int *);
2371  *rint = op->invisible;
2372  *type = CFAPI_INT;
2373  break;
2374 
2376  rbuffer = va_arg(args, char *);
2377  rbufsize = va_arg(args, int);
2378  if (rbufsize > 0) {
2379  strncpy(rbuffer, op->face->name, rbufsize);
2380  rbuffer[rbufsize - 1] = '\0';
2381  }
2382  *type = CFAPI_STRING;
2383  break;
2384 
2386  rbuffer = va_arg(args, char *);
2387  rbufsize = va_arg(args, int);
2388  if (rbufsize > 0) {
2389  if (op->animation_id != 0) {
2390  strncpy(rbuffer, animations[op->animation_id].name, rbufsize);
2391  rbuffer[rbufsize - 1] = '\0';
2392  }
2393  else
2394  rbuffer[0] = '\0';
2395  }
2396  *type = CFAPI_STRING;
2397  break;
2398 
2399  case CFAPI_PLAYER_PROP_IP:
2400  rsstring = va_arg(args, sstring *);
2401  *rsstring = op->contr->socket.host;
2402  *type = CFAPI_SSTRING;
2403  break;
2404 
2406  robject = va_arg(args, object **);
2407  *robject = find_marked_object(op);
2408  *type = CFAPI_POBJECT;
2409  break;
2410 
2412  rparty = va_arg(args, partylist **);
2413  *rparty = (op->contr ? op->contr->party : NULL);
2414  *type = CFAPI_PPARTY;
2415  break;
2416 
2418  robject = va_arg(args, object **);
2419  if (op)
2420  *robject = op->contr->next ? op->contr->next->ob : NULL;
2421  else
2422  /* This can be called when there is no player. */
2423  *robject = first_player ? first_player->ob : NULL;
2424  *type = CFAPI_POBJECT;
2425  break;
2426 
2428  rbuffer = va_arg(args, char *);
2429  rbufsize = va_arg(args, int);
2430  player_get_title(op->contr, rbuffer, rbufsize);
2431  *type = CFAPI_STRING;
2432  break;
2433 
2435  rmove = va_arg(args, MoveType *);
2436  *rmove = op->move_type;
2437  *type = CFAPI_MOVETYPE;
2438  break;
2439 
2441  rmove = va_arg(args, MoveType *);
2442  *rmove = op->move_block;
2443  *type = CFAPI_MOVETYPE;
2444  break;
2445 
2447  rmove = va_arg(args, MoveType *);
2448  *rmove = op->move_allow;
2449  *type = CFAPI_MOVETYPE;
2450  break;
2451 
2453  rmove = va_arg(args, MoveType *);
2454  *rmove = op->move_on;
2455  *type = CFAPI_MOVETYPE;
2456  break;
2457 
2459  rmove = va_arg(args, MoveType *);
2460  *rmove = op->move_off;
2461  *type = CFAPI_MOVETYPE;
2462  break;
2463 
2465  rmove = va_arg(args, MoveType *);
2466  *rmove = op->move_type;
2467  *type = CFAPI_MOVETYPE;
2468  break;
2469 
2471  rfloat = va_arg(args, float *);
2472  *rfloat = op->move_slow_penalty;
2473  *type = CFAPI_FLOAT;
2474  break;
2475 
2477  rbuffer = va_arg(args, char *);
2478  rbufsize = va_arg(args, int);
2479  snprintf(rbuffer, rbufsize, "%s", op->contr->savebed_map);
2480  *type = CFAPI_STRING;
2481  break;
2482 
2484  rint = va_arg(args, int *);
2485  *rint = op->contr->bed_x;
2486  *type = CFAPI_INT;
2487  break;
2488 
2490  rint = va_arg(args, int *);
2491  *rint = op->contr->bed_y;
2492  *type = CFAPI_INT;
2493  break;
2494 
2496  rint = va_arg(args, int *);
2497  *rint = op->duration;
2498  *type = CFAPI_INT;
2499  break;
2500 
2501  default:
2502  *type = CFAPI_NONE;
2503  break;
2504  }
2505  va_end(args);
2506 }
2507 
2516 static void copy_message(object *op, const char *msg) {
2517  char *temp;
2518  int size;
2519 
2520  if (!msg)
2521  return;
2522 
2523  /* need to reset parsed dialog information */
2525 
2526  size = strlen(msg);
2527 
2528  if (msg[0] != 0 && msg[size-1] == '\n') {
2529  object_set_msg(op, msg);
2530  return;
2531  }
2532 
2533  temp = malloc(size+2);
2534  if (!temp)
2536  snprintf(temp, size+2, "%s\n", msg);
2537  object_set_msg(op, temp);
2538  free(temp);
2539 }
2540 
2549 static void cfapi_object_set_property(int *type, ...) {
2550  va_list args;
2551  int iarg, *ret;
2552  long larg;
2553  char *sarg;
2554  double darg;
2555  object *oparg;
2556  object *op;
2557  int property;
2558  int64_t s64arg;
2559  partylist *partyarg;
2560  float farg;
2561  MoveType *move; /* MoveType can't be used through va_arg so use MoveType * */
2562 
2563  va_start(args, type);
2564  op = va_arg(args, object *);
2565  property = va_arg(args, int);
2566  *type = CFAPI_NONE;
2567 
2568  if (op != NULL && (!op->arch || (op != &op->arch->clone))) {
2569  switch (property) {
2571  sarg = va_arg(args, char *);
2572  *type = CFAPI_STRING;
2573  FREE_AND_COPY(op->name, sarg);
2574  send_changed_object(op);
2575  break;
2576 
2578  sarg = va_arg(args, char *);
2579  *type = CFAPI_STRING;
2580  FREE_AND_COPY(op->name_pl, sarg);
2581  send_changed_object(op);
2582  break;
2583 
2585  sarg = va_arg(args, char *);
2586  *type = CFAPI_STRING;
2587  FREE_AND_COPY(op->title, sarg);
2588  break;
2589 
2591  sarg = va_arg(args, char *);
2592  *type = CFAPI_STRING;
2593  FREE_AND_COPY(op->race, sarg);
2594  break;
2595 
2597  sarg = va_arg(args, char *);
2598  *type = CFAPI_STRING;
2599  FREE_AND_COPY(op->slaying, sarg);
2600  break;
2601 
2603  sarg = va_arg(args, char *);
2604  *type = CFAPI_STRING;
2605  FREE_AND_COPY(op->skill, sarg);
2606  break;
2607 
2609  sarg = va_arg(args, char *);
2610  *type = CFAPI_STRING;
2611  copy_message(op, sarg);
2612  break;
2613 
2615  sarg = va_arg(args, char *);
2616  *type = CFAPI_STRING;
2617  FREE_AND_COPY(op->lore, sarg);
2618  break;
2619 
2621  farg = va_arg(args, double);
2622  *type = CFAPI_FLOAT;
2623  if (farg != op->speed) {
2624  op->speed = farg;
2625  object_update_speed(op);
2626  }
2627  break;
2628 
2630  farg = va_arg(args, double);
2631  *type = CFAPI_FLOAT;
2632  op->speed_left = farg;
2633  break;
2634 
2636  iarg = va_arg(args, int);
2637  *type = CFAPI_INT;
2638  if (iarg < 0)
2639  iarg = 0;
2640  if (op->nrof > (uint32_t)iarg)
2641  object_decrease_nrof(op, op->nrof-iarg);
2642  else if (op->nrof < (uint32_t)iarg) {
2643  object *tmp;
2644  player *pl;
2645 
2646  op->nrof = iarg;
2647  if (op->env != NULL) {
2648  tmp = object_get_player_container(op->env);
2649  if (!tmp) {
2650  for (pl = first_player; pl; pl = pl->next)
2651  if (pl->ob->container == op->env)
2652  break;
2653  if (pl)
2654  tmp = pl->ob;
2655  else
2656  tmp = NULL;
2657  } else {
2658  object_sum_weight(tmp);
2659  fix_object(tmp);
2660  }
2661  if (tmp)
2662  esrv_update_item(UPD_NROF, tmp, op);
2663  } else {
2664  FOR_ABOVE_PREPARE(op, tmp)
2665  if (tmp->type == PLAYER)
2666  tmp->contr->socket.update_look = 1;
2667  FOR_ABOVE_FINISH();
2668  }
2669  }
2670  break;
2671 
2673  iarg = va_arg(args, int);
2674  *type = CFAPI_INT;
2675  op->direction = iarg;
2676  break;
2677 
2679  iarg = va_arg(args, int);
2680  *type = CFAPI_INT;
2681  op->facing = iarg;
2682  break;
2683 
2684  case CFAPI_OBJECT_PROP_RESIST: {
2685  int iargbis = va_arg(args, int);
2686 
2687  *type = CFAPI_INT16;
2688  iarg = va_arg(args, int);
2689  op->resist[iargbis] = iarg;
2690  }
2691  break;
2692 
2694  iarg = va_arg(args, int);
2695  *type = CFAPI_INT;
2696  op->attacktype = iarg;
2697  break;
2698 
2700  iarg = va_arg(args, int);
2701  *type = CFAPI_INT;
2702  op->path_attuned = iarg;
2703  break;
2704 
2706  iarg = va_arg(args, int);
2707  *type = CFAPI_INT;
2708  op->path_repelled = iarg;
2709  break;
2710 
2712  iarg = va_arg(args, int);
2713  *type = CFAPI_INT;
2714  op->path_denied = iarg;
2715  break;
2716 
2718  iarg = va_arg(args, int);
2719  *type = CFAPI_INT;
2720  op->material = iarg;
2721  break;
2722 
2724  break;
2725 
2727  iarg = va_arg(args, int);
2728  *type = CFAPI_INT;
2729  op->magic = iarg;
2730  break;
2731 
2733  larg = va_arg(args, long);
2734  *type = CFAPI_LONG;
2735  op->value = larg;
2736  break;
2737 
2739  iarg = va_arg(args, int);
2740  *type = CFAPI_INT;
2741  op->level = iarg;
2742  break;
2743 
2745  iarg = va_arg(args, int);
2746  *type = CFAPI_INT;
2747  op->last_heal = iarg;
2748  break;
2749 
2751  iarg = va_arg(args, int);
2752  *type = CFAPI_INT;
2753  op->last_sp = iarg;
2754  break;
2755 
2757  iarg = va_arg(args, int);
2758  *type = CFAPI_INT;
2759  op->last_grace = iarg;
2760  break;
2761 
2763  iarg = va_arg(args, int);
2764  *type = CFAPI_INT;
2765  op->last_eat = iarg;
2766  break;
2767 
2769  iarg = va_arg(args, int);
2770  *type = CFAPI_INT;
2771  op->invisible = iarg;
2772  break;
2773 
2775  iarg = va_arg(args, int);
2776  *type = CFAPI_INT;
2777  op->pick_up = iarg;
2778  break;
2779 
2781  iarg = va_arg(args, int);
2782  *type = CFAPI_INT;
2783  op->item_power = iarg;
2784  break;
2785 
2787  iarg = va_arg(args, int);
2788  *type = CFAPI_INT;
2789  op->gen_sp_armour = iarg;
2790  break;
2791 
2793  iarg = va_arg(args, int);
2794  *type = CFAPI_INT;
2795  if (op->weight != iarg) {
2796  object *tmp;
2797  player *pl;
2798 
2799  op->weight = iarg;
2800  if (op->env != NULL) {
2801  tmp = object_get_player_container(op->env);
2802  if (!tmp) {
2803  for (pl = first_player; pl; pl = pl->next)
2804  if (pl->ob->container == op->env)
2805  break;
2806  if (pl)
2807  tmp = pl->ob;
2808  else
2809  tmp = NULL;
2810  } else {
2811  object_sum_weight(tmp);
2812  fix_object(tmp);
2813  }
2814  if (tmp)
2815  esrv_update_item(UPD_WEIGHT, tmp, op);
2816  } else {
2817  FOR_ABOVE_PREPARE(op, tmp)
2818  if (tmp->type == PLAYER)
2819  esrv_update_item(UPD_WEIGHT, tmp, op);
2820  FOR_ABOVE_FINISH();
2821  }
2822  }
2823  break;
2824 
2826  iarg = va_arg(args, int);
2827  *type = CFAPI_INT;
2828  op->weight_limit = iarg;
2829  break;
2830 
2832  iarg = va_arg(args, int);
2833  *type = CFAPI_INT;
2834  if (op->glow_radius != iarg) {
2835  object *tmp;
2836 
2837  op->glow_radius = iarg;
2838  tmp = object_get_env_recursive(op);
2839  if (tmp->map != NULL) {
2840  SET_MAP_FLAGS(tmp->map, tmp->x, tmp->y, P_NEED_UPDATE);
2841  update_position(tmp->map, tmp->x, tmp->y);
2842  update_all_los(tmp->map, tmp->x, tmp->y);
2843  }
2844  }
2845  break;
2846 
2848  s64arg = va_arg(args, int64_t);
2849  *type = CFAPI_SINT64;
2850  op->perm_exp = s64arg;
2851  break;
2852 
2854  oparg = va_arg(args, object *);
2855  *type = CFAPI_POBJECT;
2856  object_set_enemy(op, oparg);
2857  break;
2858 
2860  iarg = va_arg(args, int);
2861  *type = CFAPI_INT;
2862  op->run_away = iarg;
2863  break;
2864 
2866  oparg = va_arg(args, object *);
2867  *type = CFAPI_POBJECT;
2868  op->chosen_skill = oparg;
2869  break;
2870 
2872  iarg = va_arg(args, int);
2873  *type = CFAPI_INT;
2874  op->hide = iarg;
2875  break;
2876 
2878  iarg = va_arg(args, int);
2879  *type = CFAPI_INT;
2880  op->move_status = iarg;
2881  break;
2882 
2884  iarg = va_arg(args, int);
2885  *type = CFAPI_INT;
2886  op->attack_movement = iarg;
2887  break;
2888 
2890  oparg = va_arg(args, object *);
2891  *type = CFAPI_POBJECT;
2892  op->spellitem = oparg;
2893  break;
2894 
2896  darg = va_arg(args, double);
2897  *type = CFAPI_DOUBLE;
2898  op->expmul = darg;
2899  break;
2900 
2902  sarg = va_arg(args, char *);
2903  *type = CFAPI_STRING;
2904  FREE_AND_COPY(op->custom_name, sarg);
2905  send_changed_object(op);
2906  break;
2907 
2909  iarg = va_arg(args, int);
2910  *type = CFAPI_INT;
2911  op->anim_speed = iarg;
2912  break;
2913 
2915  iarg = va_arg(args, int);
2916  *type = CFAPI_INT;
2917  if (iarg == 1 && is_friendly(op) == 0)
2918  add_friendly_object(op);
2919  else if (iarg == 0 && is_friendly(op) == 1)
2921  break;
2922 
2924  iarg = va_arg(args, int);
2925  *type = CFAPI_INT;
2926  op->stats.luck = iarg;
2927  break;
2928 
2929  case CFAPI_OBJECT_PROP_EXP:
2930  s64arg = va_arg(args, int64_t);
2931  *type = CFAPI_SINT64;
2932  op->stats.exp = s64arg;
2933  break;
2934 
2936  oparg = va_arg(args, object *);
2937  *type = CFAPI_POBJECT;
2938  object_set_owner(op, oparg);
2939  break;
2940 
2942  object_set_cheat(op);
2943  *type = CFAPI_NONE;
2944  break;
2945 
2946  case CFAPI_OBJECT_PROP_FLAGS: {
2947  int iargbis;
2948 
2949  iarg = va_arg(args, int);
2950  iargbis = va_arg(args, int);
2951  *type = CFAPI_INT;
2952 
2953  if (iargbis == 1)
2954  SET_FLAG(op, iarg);
2955  else
2956  CLEAR_FLAG(op, iarg);
2957  }
2958  break;
2959 
2960  case CFAPI_OBJECT_PROP_STR:
2961  iarg = va_arg(args, int);
2962  *type = CFAPI_INT;
2963  op->stats.Str = iarg;
2964  break;
2965 
2966  case CFAPI_OBJECT_PROP_DEX:
2967  iarg = va_arg(args, int);
2968  *type = CFAPI_INT;
2969  op->stats.Dex = iarg;
2970  break;
2971 
2972  case CFAPI_OBJECT_PROP_CON:
2973  iarg = va_arg(args, int);
2974  *type = CFAPI_INT;
2975  op->stats.Con = iarg;
2976  break;
2977 
2978  case CFAPI_OBJECT_PROP_WIS:
2979  iarg = va_arg(args, int);
2980  *type = CFAPI_INT;
2981  op->stats.Wis = iarg;
2982  break;
2983 
2984  case CFAPI_OBJECT_PROP_INT:
2985  iarg = va_arg(args, int);
2986  *type = CFAPI_INT;
2987  op->stats.Int = iarg;
2988  break;
2989 
2990  case CFAPI_OBJECT_PROP_POW:
2991  iarg = va_arg(args, int);
2992  *type = CFAPI_INT;
2993  op->stats.Pow = iarg;
2994  break;
2995 
2996  case CFAPI_OBJECT_PROP_CHA:
2997  iarg = va_arg(args, int);
2998  *type = CFAPI_INT;
2999  op->stats.Cha = iarg;
3000  break;
3001 
3002  case CFAPI_OBJECT_PROP_WC:
3003  iarg = va_arg(args, int);
3004  *type = CFAPI_INT;
3005  op->stats.wc = iarg;
3006  break;
3007 
3008  case CFAPI_OBJECT_PROP_AC:
3009  iarg = va_arg(args, int);
3010  *type = CFAPI_INT;
3011  op->stats.ac = iarg;
3012  break;
3013 
3014  case CFAPI_OBJECT_PROP_HP:
3015  iarg = va_arg(args, int);
3016  *type = CFAPI_INT;
3017  op->stats.hp = iarg;
3018  break;
3019 
3020  case CFAPI_OBJECT_PROP_SP:
3021  iarg = va_arg(args, int);
3022  *type = CFAPI_INT;
3023  op->stats.sp = iarg;
3024  break;
3025 
3026  case CFAPI_OBJECT_PROP_GP:
3027  iarg = va_arg(args, int);
3028  *type = CFAPI_INT;
3029  op->stats.grace = iarg;
3030  break;
3031 
3032  case CFAPI_OBJECT_PROP_FP:
3033  iarg = va_arg(args, int);
3034  *type = CFAPI_INT;
3035  op->stats.food = iarg;
3036  break;
3037 
3039  iarg = va_arg(args, int);
3040  *type = CFAPI_INT;
3041  op->stats.maxhp = iarg;
3042  break;
3043 
3045  iarg = va_arg(args, int);
3046  *type = CFAPI_INT;
3047  op->stats.maxsp = iarg;
3048  break;
3049 
3051  iarg = va_arg(args, int);
3052  *type = CFAPI_INT;
3053  op->stats.maxgrace = iarg;
3054  break;
3055 
3056  case CFAPI_OBJECT_PROP_DAM:
3057  iarg = va_arg(args, int);
3058  *type = CFAPI_INT;
3059  op->stats.dam = iarg;
3060  break;
3061 
3062  case CFAPI_OBJECT_PROP_FACE: {
3063  sarg = va_arg(args, char *);
3064  ret = va_arg(args, int *);
3065  *type = CFAPI_INT;
3066  *ret = find_face(sarg, 0);
3067  if (*ret != 0) {
3068  op->face = &new_faces[*ret];
3069  op->state = 0;
3071  }
3072  break;
3073  }
3074 
3076  sarg = va_arg(args, char *);
3077  ret = va_arg(args, int *);
3078  *type = CFAPI_INT;
3079  *ret = try_find_animation(sarg);
3080  if (*ret != 0) {
3081  op->animation_id = *ret;
3082  SET_ANIMATION(op, 0);
3084  }
3085  break;
3086 
3088  iarg = va_arg(args, int);
3089  *type = CFAPI_INT;
3090  op->duration = iarg;
3091  break;
3092 
3094  if (op->contr) {
3095  oparg = va_arg(args, object *);
3096  *type = CFAPI_POBJECT;
3097  op->contr->mark = oparg;
3098  if (oparg) {
3099  op->contr->mark_count = oparg->count;
3100  } else {
3101  op->contr->mark_count = 0;
3102  }
3103  }
3104  break;
3105 
3107  if (op->contr) {
3108  partyarg = va_arg(args, partylist *);
3109  *type = CFAPI_PPARTY;
3110  party_join(op, partyarg);
3111  }
3112  break;
3113 
3115  sarg = va_arg(args, char *);
3116  *type = CFAPI_STRING;
3117  safe_strncpy(op->contr->savebed_map, sarg, MAX_BUF);
3118  break;
3119 
3121  iarg = va_arg(args, int);
3122  *type = CFAPI_INT;
3123  op->contr->bed_x = iarg;
3124  break;
3125 
3127  iarg = va_arg(args, int);
3128  *type = CFAPI_INT;
3129  op->contr->bed_y = iarg;
3130  break;
3131 
3133  sarg = va_arg(args, char *);
3134  *type = CFAPI_STRING;
3135  player_set_own_title(op->contr, sarg);
3136  break;
3137 
3139  move = va_arg(args, MoveType *);
3140  op->move_type = *move & MOVE_ALL;
3142  *type = CFAPI_MOVETYPE;
3143  break;
3144 
3146  move = va_arg(args, MoveType *);
3147  op->move_block = *move & MOVE_ALL;
3149  *type = CFAPI_MOVETYPE;
3150  break;
3151 
3153  move = va_arg(args, MoveType *);
3154  op->move_allow = *move & MOVE_ALL;
3156  *type = CFAPI_MOVETYPE;
3157  break;
3158 
3160  move = va_arg(args, MoveType *);
3161  op->move_on = *move & MOVE_ALL;
3163  *type = CFAPI_MOVETYPE;
3164  break;
3165 
3167  move = va_arg(args, MoveType *);
3168  op->move_off = *move & MOVE_ALL;
3170  *type = CFAPI_MOVETYPE;
3171  break;
3172 
3174  move = va_arg(args, MoveType *);
3175  op->move_type = *move & MOVE_ALL;
3177  *type = CFAPI_MOVETYPE;
3178  break;
3179 
3180  default:
3181  break;
3182  }
3183  }
3184  va_end(args);
3185 }
3186 
3193 static void cfapi_object_apply_below(int *type, ...) {
3194  va_list args;
3195  object *applier;
3196 
3197  va_start(args, type);
3198 
3199  applier = va_arg(args, object *);
3200 
3201  va_end(args);
3202 
3203  apply_by_living_below(applier);
3204  *type = CFAPI_NONE;
3205 }
3206 
3213 static void cfapi_object_apply(int *type, ...) {
3214  va_list args;
3215  object *applied;
3216  object *applier;
3217  int aflags;
3218  int *ret;
3219 
3220  va_start(args, type);
3221 
3222  applier = va_arg(args, object *);
3223  applied = va_arg(args, object *);
3224  aflags = va_arg(args, int);
3225  ret = va_arg(args, int *);
3226 
3227  va_end(args);
3228 
3229  *type = CFAPI_INT;
3230  *ret = apply_manual(applier, applied, aflags);
3231 }
3232 
3238 static void cfapi_object_identify(int *type, ...) {
3239  va_list args;
3240  object *op, **result;
3241 
3242  va_start(args, type);
3243 
3244  op = va_arg(args, object *);
3245  result = va_arg(args, object **);
3246 
3247  va_end(args);
3248 
3249  (*result) = identify(op);
3250  *type = CFAPI_POBJECT;
3251 }
3252 
3258 static void cfapi_object_describe(int *type, ...) {
3259  va_list args;
3260  object *op;
3261  object *owner;
3262  char *desc, *final;
3263  int size;
3264 
3265  va_start(args, type);
3266 
3267  op = va_arg(args, object *);
3268  owner = va_arg(args, object *);
3269  desc = va_arg(args, char *);
3270  size = va_arg(args, int);
3271  va_end(args);
3272 
3273  *type = CFAPI_STRING;
3274  final = stringbuffer_finish(describe_item(op, owner, 0, NULL));
3275  strncpy(desc, final, size);
3276  desc[size - 1] = '\0';
3277  free(final);
3278 }
3279 
3280 static void cfapi_object_drain(int *type, ...) {
3281  va_list args;
3282 
3283  object *op;
3284  int ds;
3285 
3286  va_start(args, type);
3287 
3288  op = va_arg(args, object *);
3289  ds = va_arg(args, int);
3290 
3291  va_end(args);
3292 
3293  drain_specific_stat(op, ds);
3294 
3295  *type = CFAPI_NONE;
3296 }
3297 
3298 static void cfapi_object_remove_depletion(int *type, ...) {
3299  va_list args;
3300 
3301  object *op;
3302  int level, *result;
3303 
3304  va_start(args, type);
3305 
3306  op = va_arg(args, object *);
3307  level = va_arg(args, int);
3308  result = va_arg(args, int*);
3309 
3310  va_end(args);
3311 
3312  *result = remove_depletion(op, level);
3313 
3314  *type = CFAPI_INT;
3315 }
3316 
3317 static void cfapi_object_fix(int *type, ...) {
3318  va_list args;
3319  object *op;
3320 
3321  va_start(args, type);
3322 
3323  op = va_arg(args, object *);
3324 
3325  va_end(args);
3326 
3327  fix_object(op);
3328 
3329  *type = CFAPI_NONE;
3330 }
3331 
3333 static void cfapi_object_give_skill(int *type, ...) {
3334  va_list args;
3335 
3336  object *op;
3337  char *skillname;
3338 
3339  va_start(args, type);
3340 
3341  op = va_arg(args, object *);
3342  skillname = va_arg(args, char *);
3343 
3344  va_end(args);
3345 
3346  *type = CFAPI_POBJECT;
3347  give_skill_by_name(op, skillname);
3348 }
3349 
3350 static void cfapi_object_transmute(int *type, ...) {
3351  va_list args;
3352 
3353  object *op;
3354  object *chg;
3355 
3356  va_start(args, type);
3357 
3358  op = va_arg(args, object *);
3359  chg = va_arg(args, object *);
3360 
3361  va_end(args);
3362 
3363  transmute_materialname(op, chg);
3364  *type = CFAPI_NONE;
3365 }
3366 
3367 static void cfapi_object_remove(int *type, ...) {
3368  va_list args;
3369  object *op;
3370 
3371  va_start(args, type);
3372 
3373  op = va_arg(args, object *);
3374 
3375  if (QUERY_FLAG(op, FLAG_REMOVED)) {
3376  LOG(llevError, "Plugin trying to remove removed object %s\n", op->name);
3377  va_end(args);
3378  *type = CFAPI_NONE;
3379  return;
3380  }
3381 
3382  va_end(args);
3383 
3384  object_remove(op);
3385  *type = CFAPI_NONE;
3386 }
3387 
3388 static void cfapi_object_delete(int *type, ...) {
3389  va_list args;
3390  object *op;
3391 
3392  va_start(args, type);
3393 
3394  op = va_arg(args, object *);
3395 
3396  if (QUERY_FLAG(op, FLAG_FREED) || !QUERY_FLAG(op, FLAG_REMOVED)) {
3397  LOG(llevError, "Plugin trying to free freed/non removed object %s\n", op->name);
3398  *type = CFAPI_NONE;
3399  va_end(args);
3400  return;
3401  }
3402 
3403  va_end(args);
3404 
3406 
3407  *type = CFAPI_NONE;
3408 }
3409 
3415 static void cfapi_object_clone(int *type, ...) {
3416  va_list args;
3417  object *op;
3418  int kind;
3419  object **robj;
3420 
3421  va_start(args, type);
3422 
3423  op = va_arg(args, object *);
3424  kind = va_arg(args, int);
3425  robj = va_arg(args, object **);
3426 
3427  va_end(args);
3428 
3429  if (kind == 0) {
3430  *type = CFAPI_POBJECT;
3431  *robj = object_create_clone(op);
3432  } else {
3433  object *tmp;
3434  tmp = object_new();
3435  object_copy(op, tmp);
3436  *type = CFAPI_POBJECT;
3437  *robj = tmp;
3438  }
3439  return;
3440 }
3441 
3447 static void cfapi_object_create(int *type, ...) {
3448  va_list args;
3449  int ival;
3450  object **robj;
3451  va_start(args, type);
3452  ival = va_arg(args, int);
3453 
3454  *type = CFAPI_POBJECT;
3455  switch (ival) {
3456  case 0:
3457  robj = va_arg(args, object **);
3458  *robj = object_new();
3459  break;
3460 
3461  case 1: { /* Named object. Nearly the old plugin behavior, but we don't add artifact suffixes */
3462  const char *sval;
3463  archetype *at;
3464 
3465  sval = va_arg(args, const char *);
3466  robj = va_arg(args, object **);
3467  va_end(args);
3468 
3469  at = try_find_archetype(sval);
3470  if (!at)
3471  at = find_archetype_by_object_name(sval);
3472  if (at) {
3473  *robj = object_create_arch(at);
3474  } else
3475  *robj = NULL;
3476  }
3477  break;
3478 
3479  default:
3480  *type = CFAPI_NONE;
3481  break;
3482  }
3483  va_end(args);
3484 }
3485 
3486 static void cfapi_object_insert(int *type, ...) {
3487  va_list args;
3488  object *op;
3489  object *orig;
3490  mapstruct *map;
3491  int flag, x, y;
3492  int itype;
3493  object **robj;
3494 
3495  va_start(args, type);
3496 
3497  op = va_arg(args, object *);
3498  if (!op) {
3499  LOG(llevError, "cfapi_object_insert: called with NULL object!\n");
3500  va_end(args);
3501  return;
3502  }
3503  if (QUERY_FLAG(op, FLAG_FREED)) {
3504  LOG(llevError, "cfapi_object_insert: called with FREED object!\n");
3505  va_end(args);
3506  return;
3507  }
3508  if (!QUERY_FLAG(op, FLAG_REMOVED)) {
3509  LOG(llevError, "cfapi_object_insert: called with not removed object %s!\n", op->name);
3510  object_remove(op);
3511  }
3512  itype = va_arg(args, int);
3513 
3514  switch (itype) {
3515  case 0:
3516  map = va_arg(args, mapstruct *);
3517  orig = va_arg(args, object *);
3518  flag = va_arg(args, int);
3519  x = va_arg(args, int);
3520  y = va_arg(args, int);
3521  robj = va_arg(args, object **);
3522  if (!map) {
3523  LOG(llevError, "cfapi_object_insert (0): called with NULL map, object %s!\n", op->name);
3525  *robj = NULL;
3526  } else
3527  *robj = object_insert_in_map_at(op, map, orig, flag, x, y);
3528  *type = CFAPI_POBJECT;
3529  break;
3530 
3531  case 1:
3532  map = va_arg(args, mapstruct *);
3533  orig = va_arg(args, object *);
3534  flag = va_arg(args, int);
3535  robj = va_arg(args, object **);
3536  if (!map) {
3537  LOG(llevError, "cfapi_object_insert (1): called with NULL map, object %s!\n", op->name);
3539  *robj = NULL;
3540  } else
3541  *robj = object_insert_in_map_at(op, map, orig, flag, op->x, op->y);
3542  *type = CFAPI_POBJECT;
3543  break;
3544 
3545  case 2:
3546  map = va_arg(args, mapstruct *);
3547  orig = va_arg(args, object *);
3548  flag = va_arg(args, int);
3549  x = va_arg(args, int);
3550  y = va_arg(args, int);
3551  robj = va_arg(args, object **);
3552  if (!map) {
3553  LOG(llevError, "cfapi_object_insert (0): called with NULL map, object %s!\n", op->name);
3555  *robj = NULL;
3556  } else {
3557  int dir = object_find_free_spot(op, map, x, y, 0, SIZEOFFREE);
3558  if (dir != -1) {
3559  *robj = object_insert_in_map_at(op, map, orig, flag, x + freearr_x[dir], y + freearr_y[dir]);
3560  } else {
3562  *robj = NULL;
3563  }
3564  }
3565  *type = CFAPI_POBJECT;
3566  break;
3567 
3568  case 3:
3569  orig = va_arg(args, object *);
3570  robj = va_arg(args, object **);
3571  if (!orig) {
3572  LOG(llevError, "cfapi_object_insert (3): called with NULL orig, object %s!\n", op->name);
3574  *robj = NULL;
3575  } else
3576  *robj = object_insert_in_ob(op, orig);
3577  *type = CFAPI_POBJECT;
3578  break;
3579 
3580  default:
3581  LOG(llevError, "cfapi_object_insert (1): called with itype %d which is not valid, object %s!\n", itype, op->name);
3583  *type = CFAPI_NONE;
3584  break;
3585  }
3586 
3587  va_end(args);
3588 }
3594 static void cfapi_object_split(int *type, ...) {
3595  va_list args;
3596 
3597  int nr, size;
3598  object *op;
3599  char *buf;
3600  object **split;
3601 
3602  va_start(args, type);
3603 
3604  op = va_arg(args, object *);
3605  nr = va_arg(args, int);
3606  buf = va_arg(args, char *);
3607  size = va_arg(args, int);
3608  split = va_arg(args, object **);
3609  va_end(args);
3610 
3611  *split = object_split(op, nr, buf, size);
3612  if (*split != NULL)
3613  {
3614  *type = CFAPI_POBJECT;
3615  }
3616  else
3617  {
3618  *type = CFAPI_NONE;
3619  }
3620 }
3621 
3627 static void cfapi_object_merge(int *type, ...) {
3628  va_list args;
3629  object *op;
3630  object *op2;
3631  object **merge;
3632 
3633  va_start(args, type);
3634 
3635  op = va_arg(args, object *);
3636  op2 = va_arg(args, object *);
3637  merge = va_arg(args, object **);
3638 
3639  va_end(args);
3640 
3641  *type = CFAPI_POBJECT;
3642  *merge = object_merge(op, op2);
3643 }
3644 
3650 static void cfapi_object_distance(int *type, ...) {
3651  va_list args;
3652  object *op;
3653  object *op2;
3654  int *rint;
3655  va_start(args, type);
3656 
3657  op = va_arg(args, object *);
3658  op2 = va_arg(args, object *);
3659  rint = va_arg(args, int *);
3660 
3661  va_end(args);
3662 
3663  *type = CFAPI_INT;
3664  *rint = object_distance(op, op2);
3665 }
3671 static void cfapi_object_update(int *type, ...) {
3672  va_list args;
3673  int action;
3674  object *op;
3675  va_start(args, type);
3676 
3677  op = va_arg(args, object *);
3678  action = va_arg(args, int);
3679 
3680  va_end(args);
3681 
3682  object_update(op, action);
3683  *type = CFAPI_NONE;
3684 }
3685 
3691 static void cfapi_object_clear(int *type, ...) {
3692  va_list args;
3693  object *op;
3694  va_start(args, type);
3695 
3696  op = va_arg(args, object *);
3697 
3698  va_end(args);
3699 
3700  object_clear(op);
3701  *type = CFAPI_NONE;
3702 }
3703 
3709 static void cfapi_object_reset(int *type, ...) {
3710  va_list args;
3711  object *op;
3712 
3713  va_start(args, type);
3714 
3715  op = va_arg(args, object *);
3716 
3717  va_end(args);
3718 
3719  object_reset(op);
3720  *type = CFAPI_NONE;
3721 }
3722 
3723 static void cfapi_object_clean_object(int *type, ...) {
3724  va_list args;
3725  object *op;
3726 
3727  va_start(args, type);
3728  op = va_arg(args, object *);
3729  clean_object(op);
3730  va_end(args);
3731  *type = CFAPI_NONE;
3732 }
3733 
3734 static void cfapi_object_on_same_map(int *type, ...) {
3735  va_list args;
3736  object *op1;
3737  object *op2;
3738  int *rint;
3739 
3740  va_start(args, type);
3741  op1 = va_arg(args, object *);
3742  op2 = va_arg(args, object *);
3743  rint = va_arg(args, int *);
3744  va_end(args);
3745 
3746  *type = CFAPI_INT;
3747  *rint = on_same_map(op1, op2);
3748 }
3749 
3750 static void cfapi_object_spring_trap(int *type, ...) {
3751  object *trap;
3752  object *victim;
3753  va_list args;
3754 
3755  va_start(args, type);
3756  trap = va_arg(args, object *);
3757  victim = va_arg(args, object *);
3758  va_end(args);
3759 
3760  spring_trap(trap, victim);
3761  *type = CFAPI_NONE;
3762 }
3763 
3769 static void cfapi_object_check_trigger(int *type, ...) {
3770  object *op;
3771  object *cause;
3772  va_list args;
3773  int *rint;
3774 
3775  va_start(args, type);
3776  op = va_arg(args, object *);
3777  cause = va_arg(args, object *);
3778  rint = va_arg(args, int *);
3779  va_end(args);
3780 
3781  *rint = check_trigger(op, cause);
3782  *type = CFAPI_INT;
3783 }
3784 
3796 static void cfapi_map_trigger_connected(int *type, ...) {
3797  objectlink *ol;
3798  object *cause;
3799  int state;
3800  va_list args;
3801 
3802  va_start(args, type);
3803  ol = va_arg(args, objectlink *);
3804  cause = va_arg(args, object *);
3805  state = va_arg(args, int);
3806  va_end(args);
3807  trigger_connected(ol, cause, state);
3808  *type = CFAPI_NONE;
3809 }
3810 
3816 static void cfapi_object_query_money(int *type, ...) {
3817  object *op;
3818  va_list args;
3819  int *rint;
3820 
3821  va_start(args, type);
3822  op = va_arg(args, object *);
3823  rint = va_arg(args, int *);
3824  va_end(args);
3825 
3826  *rint = query_money(op);
3827  *type = CFAPI_INT;
3828 }
3829 
3835 static void cfapi_object_cast(int *type, ...) {
3836  object *op;
3837  object *sp;
3838  int dir;
3839  char *str;
3840  object *caster;
3841  va_list args;
3842  int *rint;
3843 
3844  va_start(args, type);
3845  op = va_arg(args, object *);
3846  caster = va_arg(args, object *);
3847  dir = va_arg(args, int);
3848  sp = va_arg(args, object *);
3849  str = va_arg(args, char *);
3850  rint = va_arg(args, int *);
3851  va_end(args);
3852 
3853  *type = CFAPI_INT;
3854 
3855  if (!op->map) {
3856  *rint = -1;
3857  return;
3858  }
3859 
3860  *rint = cast_spell(op, caster, dir, sp, str);
3861 }
3862 
3863 static void cfapi_object_learn_spell(int *type, ...) {
3864  object *op;
3865  object *sp;
3866  int prayer;
3867  va_list args;
3868 
3869  va_start(args, type);
3870  op = va_arg(args, object *);
3871  sp = va_arg(args, object *);
3872  prayer = va_arg(args, int);
3873  va_end(args);
3874  do_learn_spell(op, sp, prayer);
3875  *type = CFAPI_NONE;
3876 }
3877 
3878 static void cfapi_object_forget_spell(int *type, ...) {
3879  object *op;
3880  object *sp;
3881  va_list args;
3882  char name[MAX_BUF];
3883 
3884  va_start(args, type);
3885  op = va_arg(args, object *);
3886  sp = va_arg(args, object *);
3887  va_end(args);
3888  query_name(sp, name, MAX_BUF);
3889  do_forget_spell(op, name);
3890  *type = CFAPI_NONE;
3891 }
3892 
3898 static void cfapi_object_check_spell(int *type, ...) {
3899  object *op;
3900  char *spellname;
3901  va_list args;
3902  object **robj;
3903 
3904  va_start(args, type);
3905  op = va_arg(args, object *);
3906  spellname = va_arg(args, char *);
3907  robj = va_arg(args, object **);
3908  va_end(args);
3909  *robj = check_spell_known(op, spellname);
3910  *type = CFAPI_POBJECT;
3911 }
3912 
3918 static void cfapi_object_pay_amount(int *type, ...) {
3919  object *op;
3920  uint64_t amount;
3921  va_list args;
3922  int *rint;
3923 
3924  va_start(args, type);
3925  op = va_arg(args, object *);
3926  amount = va_arg(args, uint64_t);
3927  rint = va_arg(args, int *);
3928  va_end(args);
3929 
3930  *rint = pay_for_amount(amount, op);
3931  *type = CFAPI_INT;
3932 }
3933 
3939 static void cfapi_object_pay_item(int *type, ...) {
3940  object *op;
3941  object *tobuy;
3942  int *rint;
3943 
3944  va_list args;
3945 
3946  va_start(args, type);
3947  tobuy = va_arg(args, object *);
3948  op = va_arg(args, object *);
3949  rint = va_arg(args, int *);
3950  va_end(args);
3951 
3952  *rint = pay_for_item(tobuy, op);
3953  *type = CFAPI_INT;
3954 }
3955 
3963 static void cfapi_object_transfer(int *type, ...) {
3964  object *op;
3965  object *originator;
3966  int x, y, randompos, ttype, flag;
3967  va_list args;
3968  mapstruct *map;
3969  int *rint;
3970  object **robj;
3971 
3972  va_start(args, type);
3973  op = va_arg(args, object *);
3974  ttype = va_arg(args, int);
3975  switch (ttype) {
3976  case 0:
3977  x = va_arg(args, int);
3978  y = va_arg(args, int);
3979  randompos = va_arg(args, int);
3980  originator = va_arg(args, object *);
3981  rint = va_arg(args, int *);
3982  va_end(args);
3983 
3984  *rint = transfer_ob(op, x, y, randompos, originator);
3985  *type = CFAPI_INT;
3986  return;
3987  break;
3988 
3989  case 1:
3990  map = va_arg(args, mapstruct *);
3991  originator = va_arg(args, object *);
3992  flag = va_arg(args, int);
3993  x = va_arg(args, int);
3994  y = va_arg(args, int);
3995  robj = va_arg(args, object **);
3996  va_end(args);
3997  if (x < 0 || y < 0) {
3998  x = map->enter_x;
3999  y = map->enter_y;
4000  }
4001  *robj = object_insert_in_map_at(op, map, originator, flag, x, y);
4002  *type = CFAPI_POBJECT;
4003  return;
4004  break;
4005 
4006  case 2:
4007  x = va_arg(args, int);
4008  y = va_arg(args, int);
4009  rint = va_arg(args, int *);
4010  va_end(args);
4011 
4012  *rint = move_to(op, x, y);
4013  *type = CFAPI_INT;
4014  return;
4015 
4016  default:
4017  va_end(args);
4018  *type = CFAPI_NONE;
4019  return;
4020  break;
4021  }
4022 }
4023 
4027 static void cfapi_object_find_archetype_inside(int *type, ...) {
4028  object *op;
4029  char *str;
4030  va_list args;
4031  object **robj;
4032 
4033  *type = CFAPI_POBJECT;
4034  va_start(args, type);
4035  op = va_arg(args, object *);
4036 
4037  str = va_arg(args, char *);
4038  robj = va_arg(args, object **);
4039  *robj = arch_present_in_ob(try_find_archetype(str), op);
4040  if (*robj == NULL) {
4041  char name[MAX_BUF];
4042 
4043  /* Search by name or slaying instead */
4044  FOR_INV_PREPARE(op, tmp) {
4045  query_name(tmp, name, MAX_BUF);
4046  if (!strncmp(name, str, strlen(str)))
4047  *robj = tmp;
4048  if (!strncmp(tmp->name, str, strlen(str)))
4049  *robj = tmp;
4050  if (tmp->slaying && !strcmp(tmp->slaying, str))
4051  *robj = tmp;
4052  if (*robj != NULL)
4053  break;
4054  } FOR_INV_FINISH();
4055  }
4056  va_end(args);
4057 }
4058 
4059 static void cfapi_object_find_by_arch_name(int *type, ...) {
4060  const object *who;
4061  object **result;
4062  const char *name;
4063  va_list args;
4064 
4065  va_start(args, type);
4066  who = va_arg(args, const object *);
4067  name = va_arg(args, const char *);
4068  result = va_arg(args, object **);
4069  va_end(args);
4070  *type = CFAPI_POBJECT;
4071 
4072  *result = object_find_by_arch_name(who, name);
4073 }
4074 
4075 static void cfapi_object_find_by_name(int *type, ...) {
4076  const object *who;
4077  object **result;
4078  const char *name;
4079  va_list args;
4080 
4081  va_start(args, type);
4082  who = va_arg(args, const object *);
4083  name = va_arg(args, const char *);
4084  result = va_arg(args, object **);
4085  va_end(args);
4086  *type = CFAPI_POBJECT;
4087 
4088  *result = object_find_by_name(who, name);
4089 }
4090 
4096 static void cfapi_object_drop(int *type, ...) {
4097  object *op;
4098  object *author;
4099  va_list args;
4100 
4101  va_start(args, type);
4102  op = va_arg(args, object *);
4103  author = va_arg(args, object *);
4104  va_end(args);
4105  *type = CFAPI_NONE;
4106 
4107  if (QUERY_FLAG(op, FLAG_NO_DROP))
4108  return;
4109  drop(author, op);
4110 
4111  if (author->type == PLAYER) {
4112  author->contr->count = 0;
4113  author->contr->socket.update_look = 1;
4114  }
4115 }
4116 
4120 static void cfapi_object_change_abil(int *type, ...) {
4121  object *op, *tmp;
4122  int *rint;
4123  va_list args;
4124 
4125  va_start(args, type);
4126  op = va_arg(args, object *);
4127  tmp = va_arg(args, object *);
4128  rint = va_arg(args, int *);
4129  va_end(args);
4130 
4131  *type = CFAPI_INT;
4132  *rint = change_abil(op, tmp);
4133 }
4134 
4135 static void cfapi_object_say(int *type, ...) {
4136  object *op;
4137  char *msg;
4138  va_list args;
4139  int *rint;
4140  char empty[] = "";
4141 
4142  va_start(args, type);
4143  op = va_arg(args, object *);
4144  msg = va_arg(args, char *);
4145  rint = va_arg(args, int *);
4146  va_end(args);
4147 
4148  if (op->type == PLAYER) {
4149  command_say(op, msg == NULL ? empty : msg);
4150  } else {
4151  monster_npc_say(op, msg);
4152  }
4153  *rint = 0;
4154  *type = CFAPI_INT;
4155 }
4156 
4157 /* PLAYER SUBCLASS */
4158 
4164 static void cfapi_player_find(int *type, ...) {
4165  va_list args;
4166  char *sval;
4167  player **rpl;
4168  va_start(args, type);
4169 
4170  sval = va_arg(args, char *);
4171  rpl = va_arg(args, player **);
4172  va_end(args);
4173 
4174  *rpl = find_player_partial_name(sval);
4175 
4176  *type = CFAPI_PPLAYER;
4177 }
4178 
4179 static void cfapi_player_message(int *type, ...) {
4180  va_list args;
4181  int flags;
4182  int pri;
4183  object *pl;
4184  char *buf;
4185 
4186  va_start(args, type);
4187 
4188  flags = va_arg(args, int);
4189  pri = va_arg(args, int);
4190  pl = va_arg(args, object *);
4191  buf = va_arg(args, char *);
4192  va_end(args);
4193 
4194  draw_ext_info(flags, pri, pl, MSG_TYPE_MISC, MSG_SUBTYPE_NONE,
4195  buf);
4196  *type = CFAPI_NONE;
4197 }
4198 
4204 static void cfapi_object_change_exp(int *type, ...) {
4205  va_list args;
4206  int flag;
4207  object *ob;
4208  const char *skill;
4209  int64_t exp;
4210 
4211  va_start(args, type);
4212  ob = va_arg(args, object *);
4213  exp = va_arg(args, int64_t);
4214  skill = va_arg(args, const char *);
4215  flag = va_arg(args, int);
4216  va_end(args);
4217 
4218  *type = CFAPI_NONE;
4219  change_exp(ob, exp, skill, flag);
4220 }
4221 
4227 static void cfapi_player_can_pay(int *type, ...) {
4228  va_list args;
4229  object *pl;
4230  int *rint;
4231 
4232  va_start(args, type);
4233  pl = va_arg(args, object *);
4234  rint = va_arg(args, int *);
4235  va_end(args);
4236 
4237  *rint = can_pay(pl);
4238  *type = CFAPI_INT;
4239 }
4240 
4246 static void cfapi_player_knowledge(int *type, ...) {
4247  va_list args;
4248  object *pl;
4249  int *rint, what;
4250  const char *knowledge;
4251 
4252  va_start(args, type);
4253  what = va_arg(args, int);
4254 
4255  switch(what)
4256  {
4257  case 1:
4258  pl = va_arg(args, object *);
4259  knowledge = va_arg(args, const char *);
4260  rint = va_arg(args, int *);
4261 
4262  *type = CFAPI_INT;
4263 
4264  if (pl->contr == NULL) {
4265  LOG(llevError, "cfapi_player_knowledge: 'has' called for non player object %s", pl->name);
4266  *rint = 0;
4267  va_end(args);
4268  return;
4269  }
4270 
4271  *rint = knowledge_player_knows(pl->contr, knowledge);
4272  break;
4273 
4274  case 2:
4275  pl = va_arg(args, object *);
4276  knowledge = va_arg(args, const char *);
4277  *type = CFAPI_NONE;
4278  if (pl->contr != NULL)
4279  knowledge_give(pl->contr, knowledge, NULL);
4280 
4281  break;
4282 
4283  default:
4284  LOG(llevError, "cfapi_player_knowledge: invalid what %d", what);
4285  }
4286 
4287  va_end(args);
4288 }
4289 
4295 static void cfapi_object_teleport(int *type, ...) {
4296  mapstruct *map;
4297  int x, y;
4298  object *who;
4299  int *res;
4300  va_list args;
4301 
4302  va_start(args, type);
4303  who = va_arg(args, object *);
4304  map = va_arg(args, mapstruct *);
4305  x = va_arg(args, int);
4306  y = va_arg(args, int);
4307  res = va_arg(args, int *);
4308  *type = CFAPI_INT;
4309 
4310  if (!out_of_map(map, x, y)) {
4311  int k;
4312  k = object_find_first_free_spot(who, map, x, y);
4313  if (k == -1) {
4314  *res = 1;
4315  va_end(args);
4316  return;
4317  }
4318 
4319  if (!QUERY_FLAG(who, FLAG_REMOVED)) {
4320  object_remove(who);
4321  }
4322 
4323  object_insert_in_map_at(who, map, NULL, 0, x, y);
4324  if (who->type == PLAYER) {
4325  map_newmap_cmd(&who->contr->socket);
4327  }
4328  *res = 0;
4329  }
4330 
4331  va_end(args);
4332 }
4333 
4334 static void cfapi_object_pickup(int *type, ...) {
4335  object *who;
4336  object *what;
4337  va_list args;
4338 
4339  va_start(args, type);
4340  who = va_arg(args, object *);
4341  what = va_arg(args, object *);
4342  va_end(args);
4343 
4344  pick_up(who, what);
4345  *type = CFAPI_NONE;
4346 }
4347 
4348 /* Archetype-related functions */
4349 static void cfapi_archetype_get_property(int *type, ...) {
4350  int prop;
4351  archetype *arch;
4352  va_list args;
4353  sstring *rsstring;
4354  archetype **rarch;
4355  object **robject;
4356 
4357  va_start(args, type);
4358  arch = va_arg(args, archetype *);
4359  prop = va_arg(args, int);
4360  switch (prop) {
4361  case CFAPI_ARCH_PROP_NAME:
4362  *type = CFAPI_SSTRING;
4363  rsstring = va_arg(args, sstring *);
4364  *rsstring = arch->name;
4365  break;
4366 
4367  case CFAPI_ARCH_PROP_NEXT:
4368  *type = CFAPI_PARCH;
4369  rarch = va_arg(args, archetype **);
4370  *rarch = arch ? arch->next : first_archetype;
4371  break;
4372 
4373  case CFAPI_ARCH_PROP_HEAD:
4374  *type = CFAPI_PARCH;
4375  rarch = va_arg(args, archetype **);
4376  *rarch = arch->head;
4377  break;
4378 
4379  case CFAPI_ARCH_PROP_MORE:
4380  *type = CFAPI_PARCH;
4381  rarch = va_arg(args, archetype **);
4382  *rarch = arch->more;
4383  break;
4384 
4385  case CFAPI_ARCH_PROP_CLONE:
4386  *type = CFAPI_POBJECT;
4387  robject = va_arg(args, object **);
4388  *robject = &arch->clone;
4389  break;
4390 
4391  default:
4392  *type = CFAPI_NONE;
4393  break;
4394  }
4395  va_end(args);
4396 }
4397 
4404 static void cfapi_party_get_property(int *type, ...) {
4405  partylist *party;
4406  int prop;
4407  va_list args;
4408  object *obarg;
4409  sstring *rsstring;
4410  player **rplayer;
4411  partylist **rparty;
4412 
4413  va_start(args, type);
4414  party = va_arg(args, partylist *);
4415  prop = va_arg(args, int);
4416  switch (prop) {
4417  case CFAPI_PARTY_PROP_NAME:
4418  rsstring = va_arg(args, sstring *);
4419  *rsstring = party->partyname;
4420  *type = CFAPI_SSTRING;
4421  break;
4422 
4423  case CFAPI_PARTY_PROP_NEXT:
4424  rparty = va_arg(args, partylist **);
4425  *rparty = (party ? party_get_next(party) : party_get_first());
4426  *type = CFAPI_PPARTY;
4427  break;
4428 
4430  rsstring = va_arg(args, sstring *);
4431  *rsstring = party_get_password(party);
4432  *type = CFAPI_SSTRING;
4433  break;
4434 
4436  *type = CFAPI_PPLAYER;
4437  obarg = va_arg(args, object *);
4438  rplayer = va_arg(args, player **);
4439  *rplayer = (obarg ? obarg->contr : first_player);
4440  for (; *rplayer != NULL; (*rplayer) = (*rplayer)->next)
4441  if ((*rplayer)->ob->contr->party == party) {
4442  break;
4443  }
4444  break;
4445 
4446  default:
4447  *type = CFAPI_NONE;
4448  break;
4449  }
4450  va_end(args);
4451 }
4452 
4459 static void cfapi_region_get_property(int *type, ...) {
4460  region *reg;
4461  int prop, *rint;
4462  va_list args;
4464  sstring *rsstring;
4465  region **rregion;
4466 
4467  va_start(args, type);
4468  reg = va_arg(args, region *);
4469  prop = va_arg(args, int);
4470  switch (prop) {
4472  rsstring = va_arg(args, sstring *);
4473  *rsstring = reg->name;
4474  *type = CFAPI_SSTRING;
4475  break;
4476 
4478  rregion = va_arg(args, region **);
4479  *rregion = (reg ? reg->next : first_region);
4480  *type = CFAPI_PREGION;
4481  break;
4482 
4484  rregion = va_arg(args, region **);
4485  *rregion = reg->parent;
4486  *type = CFAPI_PREGION;
4487  break;
4488 
4490  rsstring = va_arg(args, sstring *);
4491  *rsstring = reg->longname;
4492  *type = CFAPI_SSTRING;
4493  break;
4494 
4496  rsstring = va_arg(args, sstring *);
4497  *rsstring = reg->msg;
4498  *type = CFAPI_SSTRING;
4499  break;
4500 
4503  rint = va_arg(args, int*);
4504  *rint = (prop == CFAPI_REGION_PROP_JAIL_X ? reg->jailx : reg->jaily);
4505  *type = CFAPI_INT;
4506  break;
4507 
4509  rsstring = va_arg(args, sstring *);
4510  *rsstring = reg->jailmap;
4511  *type = CFAPI_SSTRING;
4512  break;
4513 
4514  default:
4515  *type = CFAPI_NONE;
4516  break;
4517  }
4518  va_end(args);
4519 }
4520 
4532 static void cfapi_friendlylist_get_next(int *type, ...) {
4533  object *ob;
4534  va_list args;
4535  objectlink *link;
4536  object **robject;
4537 
4538  va_start(args, type);
4539  ob = va_arg(args, object *);
4540  robject = va_arg(args, object **);
4541  va_end(args);
4542 
4543  *type = CFAPI_POBJECT;
4544  *robject = NULL;
4545 
4546  if (ob) {
4547  for (link = first_friendly_object; link; link = link->next) {
4548  if (ob == link->ob) {
4549  if (link->next) {
4550  *robject = link->next->ob;
4551  return;
4552  } else {
4553  return;
4554  }
4555  }
4556  }
4557  return;
4558  }
4559 
4561  *robject = first_friendly_object->ob;
4562 }
4563 
4564 /*
4565  * Random-map related stuff.
4566  */
4567 
4574 static void cfapi_set_random_map_variable(int *type, ...) {
4575  va_list args;
4576  RMParms *rp;
4577  const char *buf;
4578  int *ret;
4579 
4580  va_start(args, type);
4581  rp = va_arg(args, RMParms *);
4582  buf = va_arg(args, const char *);
4583  ret = va_arg(args, int *);
4584  va_end(args);
4585 
4586  *ret = set_random_map_variable(rp, buf);
4587  *type = CFAPI_INT;
4588 }
4589 
4596 static void cfapi_generate_random_map(int *type, ...) {
4597  va_list args;
4598  const char *name;
4599  RMParms *rp;
4600  char **use_layout;
4601  mapstruct **ret;
4602 
4603  va_start(args, type);
4604  name = va_arg(args, const char *);
4605  rp = va_arg(args, RMParms *);
4606  use_layout = va_arg(args, char **);
4607  ret = va_arg(args, mapstruct **);
4608  va_end(args);
4609 
4610  *ret = generate_random_map(name, rp, use_layout);
4611 }
4612 
4613 static void cfapi_object_user_event(int *type, ...) {
4614  object *op;
4615  object *activator;
4616  object *third;
4617  const char *message;
4618  int fix;
4619  int *ret;
4620  va_list args;
4621 
4622  va_start(args, type);
4623  op = va_arg(args, object *);
4624  activator = va_arg(args, object *);
4625  third = va_arg(args, object *);
4626  message = va_arg(args, const char *);
4627  fix = va_arg(args, int);
4628  ret = va_arg(args, int *);
4629  va_end(args);
4630 
4631  *ret = user_event(op, activator, third, message, fix);
4632  *type = CFAPI_INT;
4633 }
4634 
4637 static void cfapi_player_quest(int *type, ...) {
4638  int op;
4639  va_list args;
4640  object *player;
4641  sstring code;
4642 
4643  va_start(args, type);
4644  op = va_arg(args, int);
4645  player = va_arg(args, object *);
4646  code = va_arg(args, sstring);
4647 
4648  if (player->contr == NULL) {
4649  LOG(llevError, "cfapi_player_quest called with non player object %s!\n", player->name);
4650  va_end(args);
4651  /* crash/quit? */
4652  return;
4653  }
4654 
4655  switch(op) {
4656  case CFAPI_PLAYER_QUEST_START: {
4657  int state = va_arg(args, int);
4658  quest_start(player->contr, code, state);
4659  *type = CFAPI_NONE;
4660  break;
4661  }
4663  int *ret = va_arg(args, int *);
4664  *ret = quest_get_player_state(player->contr, code);
4665  *type = CFAPI_INT;
4666  break;
4667  }
4669  int state = va_arg(args, int);
4670  quest_set_player_state(player->contr, code, state);
4671  *type = CFAPI_NONE;
4672  break;
4673  }
4675  int *ret = va_arg(args, int*);
4676  *ret = quest_was_completed(player->contr, code);
4677  *type = CFAPI_INT;
4678  break;
4679  }
4680  default:
4681  LOG(llevError, "invalid quest type: %d\n", op);
4682  *type = CFAPI_NONE;
4683  }
4684 
4685  va_end(args);
4686 }
4687 
4688 /*****************************************************************************/
4689 /* NEW PLUGIN STUFF ENDS HERE */
4690 /*****************************************************************************/
4691 
4692 
4705  int i;
4706  crossfire_plugin *cp;
4707 
4708  assert(cmd != NULL);
4709  assert(command != NULL);
4710 
4711  if (plugins_list == NULL)
4712  return NULL;
4713 
4714  for (cp = plugins_list; cp != NULL; cp = cp->next) {
4715  if (cp->propfunc(&i, "command?", cmd, command) != NULL)
4716  return command;
4717  }
4718  return NULL;
4719 }
4720 
4725 void initPlugins(void) {
4726  struct dirent *currentfile;
4727  DIR *plugdir;
4728  size_t l;
4729  char buf[MAX_BUF];
4730 
4731  snprintf(buf, sizeof(buf), "%s/plugins/", LIBDIR);
4732  LOG(llevDebug, "plugins: loading from %s\n", buf);
4733 
4734  plugdir = opendir(buf);
4735  if (plugdir == NULL)
4736  return;
4737 
4738  while ((currentfile = readdir(plugdir)) != NULL) {
4739  l = strlen(currentfile->d_name);
4740  if (l > strlen(PLUGIN_SUFFIX)) {
4742  int ignore = 0;
4743 
4744  if (strcmp(currentfile->d_name+l-strlen(PLUGIN_SUFFIX), PLUGIN_SUFFIX) != 0)
4745  continue;
4746 
4747  while (disable) {
4748  if (strcmp(disable->name, "All") == 0) {
4749  LOG(llevInfo, "plugins: disabling (all) %s\n", currentfile->d_name);
4750  ignore = 1;
4751  break;
4752  }
4753  if (strncmp(disable->name, currentfile->d_name, strlen(disable->name)) == 0 && strlen(currentfile->d_name) == strlen(PLUGIN_SUFFIX) + strlen(disable->name)) {
4754  LOG(llevInfo, "plugins: disabling %s\n", currentfile->d_name);
4755  ignore = 1;
4756  break;
4757  }
4758  disable = disable->next;
4759  }
4760  if (ignore == 0) {
4761  snprintf(buf, sizeof(buf), "%s/plugins/%s", LIBDIR, currentfile->d_name);
4762  LOG(llevInfo, "plugins: loading %s\n", currentfile->d_name);
4763  plugins_init_plugin(buf);
4764  }
4765  }
4766  }
4767 
4768  closedir(plugdir);
4769 }
4770 
4775 void cleanupPlugins(void) {
4776  crossfire_plugin *cp;
4777 
4778  if (!plugins_list)
4779  return;
4780 
4781  for (cp = plugins_list; cp != NULL; ) {
4782  crossfire_plugin *next = cp->next;
4783  if (cp->closefunc)
4784  cp->closefunc();
4785  /* Don't actually unload plugins, it makes backtraces for memory
4786  * debugging (printed at exit) messed up. And it doesn't matter if we
4787  * don't free it here. The OS will do it for us.
4788  */
4789  /* plugins_dlclose(cp->libptr); */
4790  free(cp);
4791  cp = next;
4792  }
4793  plugins_list = NULL;
4794 }
#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,...)
Wrapper for object_clear().
Definition: plugins.c:3691
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Sends message to player(s).
Definition: main.c:315
Error, serious thing.
Definition: logger.h:11
int object_distance(const object *ob1, const object *ob2)
Return the square of the distance between the two given objects.
Definition: object.c:3584
void spring_trap(object *trap, object *victim)
This function generalizes attacks by runes/traps.
Definition: rune.c:205
static void cfapi_map_trigger_connected(int *type,...)
Wrapper for trigger_connected().
Definition: plugins.c:3796
static void copy_message(object *op, const char *msg)
Utility function to copy the string to op->msg and ensure there is a final newline.
Definition: plugins.c:2516
static void cfapi_set_random_map_variable(int *type,...)
Wrapper for set_random_map_variable().
Definition: plugins.c:4574
char path[HUGE_BUF]
Filename of the map.
Definition: map.h:365
#define CFAPI_OBJECT_PROP_MAGIC
Definition: plugin.h:206
void apply_by_living_below(object *pl)
Attempt to apply the object &#39;below&#39; the player.
Definition: apply.c:618
#define CFAPI_PLAYER_QUEST_GET_STATE
Definition: plugin.h:291
#define MSG_TYPE_MISC
Messages that don&#39;t go elsewhere.
Definition: newclient.h:389
#define FLAG_NO_DROP
Object can&#39;t be dropped.
Definition: define.h:289
int8_t Int
Definition: living.h:35
#define CFAPI_PARTY_PROP_PASSWORD
Definition: plugin.h:322
One player.
Definition: player.h:92
int apply_manual(object *op, object *tmp, int aflag)
Main apply handler.
Definition: apply.c:510
#define CFAPI_OBJECT_PROP_MATERIAL
Definition: plugin.h:204
const char * determine_god(object *op)
Determines if op worships a god.
Definition: gods.c:106
Random map parameters.
Definition: random_map.h:14
#define CFAPI_OBJECT_PROP_ANIMATION
Definition: plugin.h:269
mapstruct * generate_random_map(const char *OutFileName, RMParms *RP, char **use_layout)
Main random map routine.
Definition: random_map.c:74
int8_t ac
Armour Class, how hard to hit, the lower the better.
Definition: living.h:37
#define CFAPI_OBJECT_PROP_SP
Definition: plugin.h:258
int32_t weight_limit
Weight-limit of object.
Definition: object.h:366
#define UP_OBJ_FACE
Only thing that changed was the face.
Definition: object.h:519
#define CFAPI_OBJECT_PROP_CARRYING
Definition: plugin.h:219
MoveType move_type
Type of movement this object uses.
Definition: object.h:424
#define plugins_dlopen(fname)
Load a shared library.
Definition: plugin.h:163
#define EVENT_REMOVE
A Player character has been removed.
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
A player &#39;shout&#39; something.
Definition: plugin.h:94
#define CFAPI_MAP_PROP_NAME
Definition: plugin.h:299
int16_t jaily
The coodinates in jailmap to which the player should be sent.
Definition: map.h:298
int move_player(object *op, int dir)
Player gave us a direction, check whether to move or fire.
Definition: player.c:3007
MoveType move_on
Move types affected moving on to this space.
Definition: object.h:427
Information.
Definition: logger.h:12
static void cfapi_object_drain(int *type,...)
Definition: plugins.c:3280
static void cfapi_system_register_global_event(int *type,...)
Definition: plugins.c:847
void quest_start(player *pl, sstring quest_code, int state)
Start a quest for a player.
Definition: quest.c:1096
static void cfapi_system_find_animation(int *type,...)
Wrapper for find_animation().
Definition: plugins.c:793
static void cfapi_object_move(int *type,...)
Moves an object.
Definition: plugins.c:1622
#define CFAPI_OBJECT_PROP_RACE
Definition: plugin.h:184
object * check_spell_known(object *op, const char *name)
Checks to see if player knows the spell.
Definition: spell_util.c:435
#define CFAPI_MAP_PROP_ENTER_Y
Definition: plugin.h:308
static void cfapi_object_check_spell(int *type,...)
Wrapper for check_spell_known().
Definition: plugins.c:3898
Used to link together several objects.
Definition: object.h:442
#define CFAPI_REGION_PROP_MESSAGE
Definition: plugin.h:329
const char * race
Human, goblin, dragon, etc.
Definition: object.h:318
#define P_NEED_UPDATE
This space is out of date.
Definition: map.h:239
int is_magical(const object *op)
Checks whether object is magical.
Definition: item.c:1242
#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,...)
Wrapper for get_season_name().
Definition: plugins.c:1095
uint16_t attack_movement
What kind of 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:4334
#define CFAPI_OBJECT_PROP_FACE
Definition: plugin.h:268
mapstruct * get_empty_map(int sizex, int sizey)
Creates and returns a map of the specific size.
Definition: map.c:874
static void cfapi_archetype_get_property(int *type,...)
Definition: plugins.c:4349
static void cfapi_object_pay_amount(int *type,...)
Wrapper for pay_for_amount().
Definition: plugins.c:3918
#define SET_FLAG(xyz, p)
Definition: define.h:223
#define NR_OF_HOOKS
Number of hooked functions a plugin can call.
Definition: plugins.c:43
#define EVENT_KICK
A player was Kicked by a DM.
Definition: plugin.h:97
void do_forget_spell(object *op, const char *spell)
Erases spell from player&#39;s inventory.
Definition: apply.c:432
MoveType move_allow
What movement types explicitly allowed.
Definition: object.h:426
int16_t bed_x
Definition: player.h:98
linked_char * disabled_plugins
List of disabled plugins, &#39;All&#39; means all.
Definition: global.h:324
static void cfapi_object_get_property(int *type,...)
Main object property getter.
Definition: plugins.c:1714
#define plugins_dlsym(lib, name)
Get a function from a shared library.
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:3750
New_Face * new_faces
Contains face information, with names, numbers, magicmap color and such.
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)
Returns the player&#39;s title.
Definition: player.c:224
uint16_t animation_id
An index into the animation array.
Definition: object.h:416
#define CFAPI_MAP_PROP_HEIGHT
Definition: plugin.h:306
uint16_t material
What materials this object consist of.
Definition: object.h:347
#define CFAPI_OBJECT_PROP_DIRECTION
Definition: plugin.h:194
const char * name
Name of the animation sequence.
Definition: face.h:27
#define strdup_local
Definition: compat.h:25
uint8_t anim_speed
Ticks between animation-frames.
Definition: object.h:417
object * object_get_env_recursive(object *op)
Utility function.
Definition: object.c:333
One party.
Definition: party.h:10
EXTERN objectlink * first_friendly_object
Objects monsters will go after.
Definition: global.h:123
#define CFAPI_OBJECT_PROP_NEXT_ACTIVE_OB
Definition: plugin.h:173
struct obj * container
Current container being used.
Definition: object.h:291
#define CFAPI_OBJECT_PROP_MAXGP
Definition: plugin.h:263
#define EVENT_LOGIN
Player login.
Definition: plugin.h:88
int player_arrest(object *who)
Put a player into jail, taking into account cursed exits and player&#39;s region.
Definition: c_wiz.c:806
#define CFAPI_OBJECT_PROP_HIDDEN
Definition: plugin.h:227
static void cfapi_region_get_property(int *type,...)
Regions-related functions.
Definition: plugins.c:4459
static void cfapi_object_on_same_map(int *type,...)
Definition: plugins.c:3734
static void cfapi_system_find_face(int *type,...)
Wrapper for find_face().
Definition: plugins.c:812
int16_t players
How many players are on this level right now.
Definition: map.h:344
void player_update_bg_music(object player[static 1])
Definition: sounds.c:152
void fatal(enum fatal_error err)
fatal() is meant to be called whenever a fatal signal is intercepted.
Definition: utils.c:596
struct obj * who
Player saying something.
Definition: dialog.h:52
static void cfapi_object_give_skill(int *type,...)
Definition: plugins.c:3333
#define CFAPI_OBJECT_PROP_MOVE_STATUS
Definition: plugin.h:228
const char * get_season_name(const int index)
give access to season names
Definition: time.c:123
int pay_for_item(object *op, object *pl)
DAMN: This is now a wrapper for pay_from_container, which is called for the player, then for each active container that can hold money until op is paid for.
Definition: shop.c:529
char * create_pathname(const char *name, char *buf, size_t size)
Get the full path to a map file.
Definition: map.c:104
void knowledge_give(player *pl, const char *marker, const object *book)
Give a knowledge item from its code.
Definition: knowledge.c:1009
mapstruct * ready_map_name(const char *name, int flags)
Makes sure the given map is loaded and swapped in.
Definition: map.c:1803
const char * playerdir
Where the player files are.
Definition: global.h:246
unsigned char MoveType
Typdef here to define type large enough to hold bitmask of all movement types.
Definition: define.h:432
int32_t last_heal
Last healed.
Definition: object.h:357
#define CFAPI_OBJECT_PROP_SUBTYPE
Definition: plugin.h:197
partylist * party_get_next(const partylist *party)
Returns the next party from the list of all parties.
Definition: party.c:229
int16_t maxgrace
Maximum grace.
Definition: living.h:44
void free_string(sstring str)
This will reduce the refcount, and if it has reached 0, str will be freed.
Definition: shstr.c:280
#define UP_OBJ_INSERT
Object was inserted.
Definition: object.h:516
signed long object_sum_weight(object *op)
object_sum_weight() is a recursive function which calculates the weight an object is carrying...
Definition: object.c:311
#define TIMER_ERR_ID
Invalid timer id.
Definition: timers.h:67
#define CFAPI_REGION_PROP_JAIL_X
Definition: plugin.h:330
static void cfapi_get_periodofday_name(int *type,...)
Wrapper for get_season_name().
Definition: plugins.c:1107
#define CFAPI_ARCH_PROP_MORE
Definition: plugin.h:317
#define SET_ANIMATION(ob, newanim)
Definition: global.h:171
static void cfapi_object_find_by_arch_name(int *type,...)
Definition: plugins.c:4059
mapstruct * get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y)
This is basically the same as out_of_map above(), but instead we return NULL if no map is valid (coor...
Definition: map.c:2366
#define NR_EVENTS
Definition: plugin.h:100
#define EVENT_MAPLEAVE
A player left a map.
Definition: plugin.h:91
void esrv_update_item(int flags, object *pl, object *op)
Updates object *op for player *pl.
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)
Get an extra value by key.
Definition: object.c:4246
#define CFAPI_INT16
Definition: plugin.h:118
void pick_up(object *op, object *alt)
Try to pick up an item.
Definition: c_object.c:446
f_plug_api func
Function itself.
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)
Query a short name for the item.
Definition: item.c:722
struct pl player
One player.
static void cfapi_object_set_property(int *type,...)
Sets the property of an object.
Definition: plugins.c:2549
object clone
An object from which to do object_copy()
Definition: object.h:470
int16_t duration
How long the spell lasts.
Definition: object.h:403
#define CFAPI_OBJECT_PROP_FLAGS
Definition: plugin.h:247
static void cfapi_get_season_name(int *type,...)
Wrapper for get_season_name().
Definition: plugins.c:1071
socket_struct socket
Socket information for this player.
Definition: player.h:94
int16_t invisible
How much longer the object will be invis.
Definition: object.h:360
short freearr_x[SIZEOFFREE]
X offset when searching around a spot.
Definition: object.c:65
#define EVENT_LOGOUT
Player logout.
Definition: plugin.h:89
uint32_t reset_time
When this map should reset.
Definition: map.h:332
int calculate_difficulty(mapstruct *m)
This routine is supposed to find out the difficulty of the map.
Definition: map.c:1913
#define CFAPI_SINT64
Definition: plugin.h:120
#define CFAPI_OBJECT_PROP_NAME_PLURAL
Definition: plugin.h:182
static void cfapi_log(int *type,...)
Wrapper for LOG().
Definition: plugins.c:1174
const char * get_weekday(const int index)
give access to weekday names
Definition: time.c:116
const char * slaying
Which race to do double damage to.
Definition: object.h:319
region * get_region_by_map(mapstruct *m)
Gets a region from a map.
Definition: region.c:74
static void cfapi_object_find_archetype_inside(int *type,...)
Kinda wrapper for arch__present_in_ob().
Definition: plugins.c:4027
Definitions for the plugin system.
DIR * opendir(const char *)
Opens a directory for reading.
Definition: win32.c:37
int32_t last_sp
As last_heal, but for spell points.
Definition: object.h:358
#define CFAPI_OBJECT_PROP_OWNER
Definition: plugin.h:242
static void cfapi_object_teleport(int *type,...)
Teleports an object at a specified destination if possible.
Definition: plugins.c:4295
static void cfapi_system_re_cmp(int *type,...)
Wrapper for re_cmp().
Definition: plugins.c:969
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)
Returns the party&#39;s password.
Definition: party.c:263
uint8_t subtype
Subtype of object.
Definition: object.h:339
crossfire_plugin * plugins_list
Linked list of loaded plugins.
Definition: plugins.c:235
uint32_t mark_count
Count of marked object.
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:1301
uint8_t hide
The object is hidden, not invisible.
Definition: object.h:387
int64_t exp
Experience.
Definition: living.h:46
#define CFAPI_OBJECT_PROP_MESSAGE
Definition: plugin.h:187
#define FREE_OBJ_NO_DESTROY_CALLBACK
Do not run the destroy callback.
Definition: object.h:533
static void cfapi_map_delete_map(int *type,...)
Definition: plugins.c:1501
#define CFAPI_OBJECT_PROP_EXP_MULTIPLIER
Definition: plugin.h:231
struct obj * above
Pointer to the object stacked above this one.
Definition: object.h:288
double expmul
needed experience = (calc_exp*expmul) - means some races/classes can need less/more exp to gain level...
Definition: object.h:395
#define plugins_dlclose(lib)
Unload a shared library.
Definition: plugin.h:164
#define CFAPI_MAP_PROP_RESET_TIMEOUT
Definition: plugin.h:301
char id[MAX_BUF]
Plugin identification string.
Definition: plugin.h:148
void initPlugins(void)
Plugins initialization.
Definition: plugins.c:4725
object * arch_present_in_ob(const archetype *at, const object *op)
Searches for any objects with a matching archetype in the inventory of the given object.
Definition: object.c:3061
#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:3486
void remove_friendly_object(object *op)
Removes the specified object from the linked list of friendly objects.
Definition: friend.c:56
#define CFAPI_REGION_PROP_NEXT
Definition: plugin.h:326
uint32_t path_attuned
Paths the object is attuned to.
Definition: object.h:343
void object_update(object *op, int action)
object_update() updates the array which represents the map.
Definition: object.c:1239
static void cfapi_object_drop(int *type,...)
Wrapper for drop().
Definition: plugins.c:4096
static void cfapi_object_fix(int *type,...)
Definition: plugins.c:3317
int16_t sp
Spell points.
Definition: living.h:41
static void cfapi_map_set_map_property(int *type,...)
Definition: plugins.c:1433
#define EVENT_TELL
A player &#39;tell&#39; something.
Definition: plugin.h:95
static void cfapi_object_set_key(int *type,...)
Write a key/value for an object.
Definition: plugins.c:1691
#define EVENT_CRASH
Triggered when the server crashes.
Definition: plugin.h:85
#define CFAPI_MAP_PROP_NEXT
Definition: plugin.h:310
static void cfapi_party_get_property(int *type,...)
Party-related functions.
Definition: plugins.c:4404
int object_can_merge(object *ob1, object *ob2)
Examines the 2 objects given to it, and returns true if they can be merged together, including inventory.
Definition: object.c:171
#define CFAPI_OBJECT_PROP_SLAYING
Definition: plugin.h:185
static void cfapi_map_create_path(int *type,...)
Wrapper for create_pathname() and create_overlay_pathname().
Definition: plugins.c:1267
int plugin_event_say(object *npc, talk_info *talk)
Definition: plugins.c:375
Definition: win32.h:110
uint32_t path_repelled
Paths the object is repelled from.
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)
Frees obj::dialog_information.
Definition: dialog.c:32
char * partyname
Party name.
Definition: party.h:14
struct obj * enemy
Monster/player to follow even if not closest.
Definition: object.h:381
struct archt * other_arch
Pointer used for various things - mostly used for what this objects turns into or what this object cr...
Definition: object.h:413
static void cfapi_system_find_string(int *type,...)
Wrapper for find_string().
Definition: plugins.c:927
object * object_find_by_name(const object *who, const char *name)
Finds an object in inventory name.
Definition: object.c:3879
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Sends message to player(s).
Definition: main.c:310
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:465
#define CFAPI_PMAP
Definition: plugin.h:110
static void cfapi_object_apply_below(int *type,...)
Applies an object below.
Definition: plugins.c:3193
void transmute_materialname(object *op, const object *change)
When doing transmutation of objects, we have to recheck the resistances, as some that did not apply p...
Definition: utils.c:266
char savebed_map[MAX_BUF]
Map where player will respawn after death.
Definition: player.h:97
static void cfapi_timer_create(int *type,...)
Wrapper for cfapi_timer_create().
Definition: plugins.c:1122
One function the server exposes to plugins.
Definition: plugin.h:350
char * host
Which host it is connected from (ip address).
Definition: newserver.h:110
static void cfapi_player_quest(int *type,...)
Quest-related wrappers, for all quest-related operations.
Definition: plugins.c:4637
#define CFAPI_POBJECT
Definition: plugin.h:109
static void cfapi_object_split(int *type,...)
Wrapper for object_split().
Definition: plugins.c:3594
#define CFAPI_OBJECT_PROP_CHOSEN_SKILL
Definition: plugin.h:226
#define CFAPI_OBJECT_PROP_OTHER_ARCH
Definition: plugin.h:233
int16_t maxsp
Max spell points.
Definition: living.h:42
#define CFAPI_OBJECT_PROP_LAST_SP
Definition: plugin.h:210
int8_t Con
Definition: living.h:35
int change_map_light(mapstruct *m, int change)
Used to change map light level (darkness) up or down.
Definition: map.c:1995
#define CFAPI_REGION_PROP_JAIL_PATH
Definition: plugin.h:332
#define FLAG_REMOVED
Object is not in any map or invenory.
Definition: define.h:232
static void cfapi_object_delete(int *type,...)
Definition: plugins.c:3388
int16_t hp
Hit Points.
Definition: living.h:39
#define CFAPI_OBJECT_PROP_LAST_GRACE
Definition: plugin.h:211
static void cfapi_object_find_by_name(int *type,...)
Definition: plugins.c:4075
#define CFAPI_OBJECT_PROP_COUNT
Definition: plugin.h:180
short freearr_y[SIZEOFFREE]
Y offset when searching around a spot.
Definition: object.c:71
partylist * party
Party this player is part of.
Definition: player.h:186
static void cfapi_object_remove(int *type,...)
Definition: plugins.c:3367
#define CFAPI_NONE
Definition: plugin.h:104
#define UPD_ALL
Definition: newclient.h:297
void command_say(object *op, const char *params)
&#39;say&#39; command.
Definition: c_chat.c:34
object * ob
Item to link to.
Definition: object.h:443
#define MOVE_ALL
Mask of all movement types.
Definition: define.h:413
uint16_t height
Width and height of map.
Definition: map.h:347
object * give_skill_by_name(object *op, const char *skill_name)
Given the skill name skill_name, we find the skill archetype/object, set appropriate values...
Definition: living.c:1727
static void cfapi_object_transmute(int *type,...)
Definition: plugins.c:3350
const char * get_month_name(const int index)
give access to month names
Definition: time.c:109
#define CFAPI_FLOAT
Definition: plugin.h:111
void map_newmap_cmd(socket_struct *ns)
Sound related function.
Definition: request.c:615
struct _crossfire_plugin * next
Next plugin in list.
Definition: plugin.h:151
void object_set_owner(object *op, object *owner)
Sets the owner and sets the skill and exp pointers to owner&#39;s current skill and experience objects...
Definition: object.c:601
#define CFAPI_PLAYER_PROP_BED_X
Definition: plugin.h:285
char * name
Name of map as given by its creator.
Definition: map.h:328
#define CFAPI_PARCH
Definition: plugin.h:113
const char * lore
Obscure information about this object, to get put into books and the like.
Definition: object.h:323
static void cfapi_object_identify(int *type,...)
Wrapper for identify().
Definition: plugins.c:3238
struct obj * chosen_skill
The skill chosen to use.
Definition: object.h:386
int object_set_value(object *op, const char *key, const char *value, int add_key)
Updates the key in op to value.
Definition: object.c:4375
uint32_t update_look
If true, we need to send the look window.
Definition: newserver.h:115
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
Definition: object.c:1368
int change_abil(object *op, object *tmp)
Permanently alters an object&#39;s stats/flags based on another object.
Definition: living.c:394
const char * name
Face name, as used by archetypes and such.
Definition: face.h:20
const char * title
Of foo, etc.
Definition: object.h:317
int16_t y
Position in the map for this object.
Definition: object.h:326
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Same as object_insert_in_map() except it handle separate coordinates and do a clean job preparing mul...
Definition: object.c:1921
#define CFAPI_MAP_PROP_PLAYERS
Definition: plugin.h:302
int move_to(object *op, int x, int y)
Move an object one square toward a specified destination on the same map.
Definition: move.c:545
int is_friendly(const object *op)
Checks if the given object is already in the friendly list or not Lauwenmark - 31/07/05.
Definition: friend.c:144
int16_t maxhp
Max hit points.
Definition: living.h:40
sstring find_string(const char *str)
Searches a string in the shared strings.
Definition: shstr.c:236
char * name
Shortend name of the region as maps refer to it.
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
Responses to commands, eg, who.
Definition: newclient.h:379
static void cfapi_object_say(int *type,...)
Definition: plugins.c:4135
#define EVENT_MAPENTER
A player entered a map.
Definition: plugin.h:90
static void cfapi_system_remove_string(int *type,...)
Wrapper for free_string().
Definition: plugins.c:909
uint32_t path_denied
Paths the object is denied access to.
Definition: object.h:345
static void cfapi_object_change_exp(int *type,...)
Wrapper for change_exp().
Definition: plugins.c:4204
#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,...)
Wrapper for object_merge().
Definition: plugins.c:3627
#define CFAPI_OBJECT_PROP_GP
Definition: plugin.h:259
LIBPTRTYPE libptr
Pointer to the plugin library.
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)
Grabs an object from the list of unused objects, makes sure it is initialised, and returns it...
Definition: object.c:1037
const char * name_pl
The plural name of the object.
Definition: object.h:315
static void cfapi_player_knowledge(int *type,...)
Wrapper for knowledge-related functions().
Definition: plugins.c:4246
#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)
Sets the custom title.
Definition: player.c:264
int object_can_pick(const object *who, const object *item)
Finds out if an object can be picked up.
Definition: object.c:3793
object * object_insert_in_ob(object *op, object *where)
This function inserts the object op in the linked list inside the object environment.
Definition: object.c:2690
#define CFAPI_OBJECT_PROP_MOVE_SLOW_PENALTY
Definition: plugin.h:277
#define CFAPI_MAP_PROP_UNIQUE
Definition: plugin.h:312
float speed_left
How much speed is left to spend this round.
Definition: object.h:329
int knowledge_player_knows(const player *pl, const char *knowledge)
Determines whether a player knows a specific knowledge or not.
Definition: knowledge.c:1306
void *(* f_plug_property)(int *type,...)
Get various plugin properties.
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)
Simple function to have some NPC say something.
Definition: monster.c:2237
static void cfapi_timer_destroy(int *type,...)
Wrapper for cftimer_destroy().
Definition: plugins.c:1155
const char * materialname
Specific material name.
Definition: object.h:346
int16_t enter_x
Definition: map.h:348
int32_t weight
Attributes of the object.
Definition: object.h:365
uint32_t unique
If set, this is a per player unique map.
Definition: map.h:337
#define CFAPI_OBJECT_PROP_LEVEL
Definition: plugin.h:208
Structure used to build up dialog information when a player says something.
Definition: dialog.h:51
#define FOR_ABOVE_FINISH()
Finishes FOR_ABOVE_PREPARE().
Definition: define.h:729
void update_all_los(const mapstruct *map, int x, int y)
This function makes sure that update_los() will be called for all players on the given map within the...
Definition: los.c:532
const char * tmpdir
Directory to use for temporary files.
Definition: global.h:253
int8_t Wis
Definition: living.h:35
const char * text
What the player actually said.
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:4179
struct mapdef * map
Pointer to the map in which this object is present.
Definition: object.h:297
struct regiondef * next
Pointer to next region, NULL for the last one.
Definition: map.h:277
This is a game region.
Definition: map.h:276
#define CFAPI_OBJECT_PROP_RAW_NAME
Definition: plugin.h:279
#define snprintf
Definition: win32.h:46
struct obj * active_prev
Previous object in the &#39;active list This is used in process_events so that the entire object list doe...
Definition: object.h:283
void drain_specific_stat(object *op, int deplete_stats)
Drain a specified stat from op.
Definition: living.c:724
static void cfapi_object_user_event(int *type,...)
Definition: plugins.c:4613
#define CFAPI_ARCH_PROP_NEXT
Definition: plugin.h:315
f_plug_postinit closefunc
Plugin Termination function.
Definition: plugin.h:146
struct linked_char * next
Definition: global.h:88
int plugins_init_plugin(const char *libfile)
Try to load the specified plugin.
Definition: plugins.c:607
uint64_t query_money(const object *op)
Determine the amount of money the given object contains, including what is inside containers...
Definition: shop.c:459
int(* f_plug_postinit)(void)
Function called after the plugin was initialized.
Definition: plugin.h:127
#define FOR_INV_FINISH()
Finishes FOR_INV_PREPARE().
Definition: define.h:712
char * msg
Message map creator may have left.
Definition: map.h:361
void update_position(mapstruct *m, int x, int y)
This function updates various attributes about a specific space on the map (what it looks like...
Definition: map.c:2119
int16_t dam
How much damage this object does when hitting.
Definition: living.h:45
int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: plugins.c:371
void add_friendly_object(object *op)
Add a new friendly object to the linked list of friendly objects.
Definition: friend.c:30
#define CFAPI_OBJECT_PROP_FP
Definition: plugin.h:260
int32_t carrying
How much weight this object contains.
Definition: object.h:367
const char * name
The name of the object, obviously...
Definition: object.h:311
int16_t bed_y
x,y - coordinates of respawn (savebed).
Definition: player.h:98
struct obj * env
Pointer to the object which is the environment.
Definition: object.h:293
#define FOR_ABOVE_PREPARE(op_, it_)
Constructs a loop iterating over all objects above an object.
Definition: define.h:722
#define CFAPI_OBJECT_PROP_MAGICAL
Definition: plugin.h:239
int64_t perm_exp
Permanent exp.
Definition: object.h:369
int8_t gen_sp_armour
Sp regen penalty this object has (was last_heal)
Definition: object.h:363
static void cfapi_map_find_by_archetype_name(int *type,...)
Kinda wrapper for map_find_by_archetype() (but uses a string, not an archetype*). ...
Definition: plugins.c:1565
#define LIBPTRTYPE
Definition: plugin.h:136
uint8_t state
How the object was last drawn (animation)
Definition: object.h:349
struct obj * below
Pointer to the object stacked below this one.
Definition: object.h:287
struct archt * more
Next part of a linked object.
Definition: object.h:469
static void cfapi_object_pay_item(int *type,...)
Wrapper for pay_for_item().
Definition: plugins.c:3939
archetype * find_archetype_by_object_name(const char *name)
This function retrieves an archetype given the name that appears during the game (for example...
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)
Searches for any objects with a matching type variable in the inventory of the given object...
Definition: object.c:3001
void trigger_connected(objectlink *ol, object *cause, const int state)
Trigger every object in an objectlink.
Definition: button.c:41
int16_t last_grace
As last_sp, except for grace.
Definition: object.h:359
void object_reset(object *op)
Sets to 0 vital variables in an object.
Definition: object.c:704
int pay_for_amount(uint64_t to_pay, object *pl)
Takes the amount of money from the the player inventory and from it&#39;s various pouches using the pay_f...
Definition: shop.c:490
#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
Pointer to the weapon currently used.
Definition: object.h:370
int8_t direction
Means the object is moving that way.
Definition: object.h:334
#define CFAPI_LONG
Definition: plugin.h:106
object * object_create_clone(object *asrc)
Create clone from object to another.
Definition: object.c:3832
uint32_t nrof
How many of the objects.
Definition: object.h:333
#define string_get_int(name)
Definition: plugins.c:1052
#define CFAPI_OBJECT_PROP_CURRENT_WEAPON
Definition: plugin.h:222
#define CFAPI_SSTRING
Definition: plugin.h:121
int8_t Cha
Definition: living.h:35
struct archt * head
The main part of a linked object.
Definition: object.h:468
int find_animation(const char *name)
Finds the animation id that matches name.
Definition: anim.c:144
static void cfapi_player_can_pay(int *type,...)
Wrapper for can_pay().
Definition: plugins.c:4227
static void cfapi_system_check_path(int *type,...)
Wrapper for check_path().
Definition: plugins.c:946
#define CFAPI_PPLAYER
Definition: plugin.h:115
#define SIZEOFFREE
Definition: define.h:154
#define P_OUT_OF_MAP
This space is outside the map.
Definition: map.h:251
MoveType move_off
Move types affected moving off this space.
Definition: object.h:428
int move_ob(object *op, int dir, object *originator)
Op is trying to move in direction dir.
Definition: move.c:58
int cftimer_destroy(int id)
Destroys an existing timer.
Definition: timers.c:128
#define CFAPI_OBJECT_PROP_X
Definition: plugin.h:189
EXTERN Animations * animations
Definition: global.h:165
void do_learn_spell(object *op, object *spell, int special_prayer)
Actually makes op learn spell.
Definition: apply.c:391
static void cfapi_map_out_of_map(int *type,...)
Wrapper for out_of_map().
Definition: plugins.c:1463
struct pl * contr
Pointer to the player which control this object.
Definition: object.h:276
#define CFAPI_OBJECT_PROP_CHEATER
Definition: plugin.h:244
static void cfapi_object_get_key(int *type,...)
Gets a key/value value for an object.
Definition: plugins.c:1669
#define CFAPI_OBJECT_PROP_PICKABLE
Definition: plugin.h:246
int8_t item_power
Power rating of the object.
Definition: object.h:362
static void cfapi_system_directory(int *type,...)
Definition: plugins.c:987
void cleanupPlugins(void)
Call the crossfire_plugin::closefunc on the various plugins, used at server shutdown.
Definition: plugins.c:4775
uint8_t ignore_plugin_compatibility
If set, don&#39;t check plugin version.
Definition: global.h:325
uint8_t darkness
Indicates level of darkness of map.
Definition: map.h:346
#define CFAPI_MAP_PROP_MESSAGE
Definition: plugin.h:309
int try_find_animation(const char *name)
Tries to find the animation id that matches name, don&#39;t LOG() an error if not found.
Definition: anim.c:159
void object_clear(object *op)
Frees everything allocated by an object, and also clears all variables and flags to default settings...
Definition: object.c:759
command_array_struct * find_plugin_command(const char *cmd, command_array_struct *command)
Tries to find if a given command is handled by a plugin.
Definition: plugins.c:4704
static crossfire_plugin * plugins_find_plugin(const char *id)
Find a plugin from its internal name.
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)
Return the object the player has marked with the &#39;mark&#39; command below.
Definition: c_object.c:1256
#define CFAPI_OBJECT_PROP_PATH_REPELLED
Definition: plugin.h:202
void plugins_display_list(object *op)
Displays a list of loaded plugins (keystrings and description) in the game log window.
Definition: plugins.c:740
static void cfapi_object_learn_spell(int *type,...)
Definition: plugins.c:3863
archetype * try_find_archetype(const char *name)
Finds, using the hashtable, which archetype matches the given name.
Definition: arch.c:666
#define UPD_WEIGHT
Definition: newclient.h:291
#define EVENT_SAY
Someone speaks.
Definition: plugin.h:70
char d_name[_MAX_FNAME+1]
Definition: win32.h:114
static void cfapi_object_create(int *type,...)
Wrapper for object_new(), create_archetype() and create_archetype_by_object_name().
Definition: plugins.c:3447
int8_t luck
Affects thaco and ac from time to time.
Definition: living.h:38
#define CFAPI_MAP_PROP_TMPNAME
Definition: plugin.h:298
float speed
The overall speed of this object.
Definition: object.h:328
unsigned __int64 uint64_t
Definition: win32.h:167
char fullname[MAX_BUF]
Plugin full name.
Definition: plugin.h:149
struct regiondef * parent
Pointer to the region that is a parent of the current region, if a value isn&#39;t defined in the current...
Definition: map.h:286
int on_same_map(const object *op1, const object *op2)
Checks whether 2 objects are on the same map or not.
Definition: map.c:2627
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
f_plug_property propfunc
Plugin getProperty function.
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,...)
Wrapper for find_player_partial_name().
Definition: plugins.c:4164
#define EVENT_MAPLOAD
A map is loaded.
Definition: plugin.h:99
partylist * party_get_first(void)
Returns the first party from the list of all parties.
Definition: party.c:217
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Changes experience to a player/monster.
Definition: living.c:2076
#define CFAPI_OBJECT_PROP_ITEM_POWER
Definition: plugin.h:215
#define CFAPI_REGION_PROP_LONGNAME
Definition: plugin.h:328
#define MSG_TYPE_COMMAND_DEBUG
Various debug type commands.
Definition: newclient.h:508
static void cfapi_object_apply(int *type,...)
Applies an object.
Definition: plugins.c:3213
static void cfapi_system_unregister_global_event(int *type,...)
Definition: plugins.c:866
#define MAX_BUF
Used for all kinds of things.
Definition: define.h:35
int quest_get_player_state(player *pl, sstring quest_code)
Get the quest state for a player.
Definition: quest.c:1076
#define CFAPI_PARTY_PROP_NAME
Definition: plugin.h:320
struct obj * active_next
Next object in the &#39;active&#39; list This is used in process_events so that the entire object list does n...
Definition: object.h:279
#define CFAPI_PLAYER_PROP_PARTY
Definition: plugin.h:283
LogLevel
Log levels for the LOG() function.
Definition: logger.h:10
object * object_create_arch(archetype *at)
Create a full object using the given archetype.
Definition: arch.c:736
int16_t jailx
Definition: map.h:298
int16_t enter_y
Enter_x and enter_y are default entrance coordinates to use for a map such that when an exit specifie...
Definition: map.h:348
int16_t x
Definition: object.h:326
#define EVENT_MAPUNLOAD
A map is freed (includes swapping out)
Definition: plugin.h:98
void drop(object *op, object *tmp)
Drop an item, either on the floor or in a container.
Definition: c_object.c:910
#define CFAPI_OBJECT_PROP_EXP
Definition: plugin.h:241
const char * skill
Name of the skill this object uses/grants.
Definition: object.h:321
int32_t last_eat
How long since we last ate.
Definition: object.h:356
static void cfapi_object_describe(int *type,...)
Wrapper for describe_item().
Definition: plugins.c:3258
#define plugins_dlerror()
Library error.
Definition: plugin.h:166
#define EVENT_MAPRESET
A map is resetting.
Definition: plugin.h:92
const char * re_cmp(const char *, const char *)
re-cmp - get regular expression match.
Definition: re-cmp.c:69
int8_t wc
Weapon Class, how skilled, the lower the better.
Definition: living.h:36
const char * confdir
Configuration files.
Definition: global.h:243
int object_find_first_free_spot(const object *ob, mapstruct *m, int x, int y)
object_find_first_free_spot(archetype, mapstruct, x, y) works like object_find_free_spot(), but it will search max number of squares.
Definition: object.c:3458
int(* f_plug_event)(int *type,...)
Function to call to handle global or object-related events.
Definition: plugin.h:131
signed __int64 int64_t
Definition: win32.h:168
static const flag_definition flags[]
Flag mapping.
#define EVENT_GKILL
Triggered when anything got killed by anyone.
Definition: plugin.h:87
static void cfapi_system_strdup_local(int *type,...)
Wrapper for strdup_local().
Definition: plugins.c:833
#define CFAPI_OBJECT_PROP_PERM_EXP
Definition: plugin.h:221
const char * uniquedir
Directory for the unique items.
Definition: global.h:251
int8_t Str
Definition: living.h:35
char * tmpname
Name of temporary file.
Definition: map.h:327
int16_t resist[NROFATTACKS]
Resistance adjustments for attacks.
Definition: object.h:341
object * ob
The object representing the player.
Definition: player.h:158
const char * sstring
Strings that should be manipulated through add_string() and free_string().
Definition: global.h:40
#define EVENT_CLOCK
Global time event.
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
See Player.
Definition: object.h:107
const char * datadir
Read only data files.
Definition: global.h:244
#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,...)
Wrapper for check_trigger().
Definition: plugins.c:3769
#define SET_MAP_FLAGS(M, X, Y, C)
Sets map flags.
Definition: map.h:163
#define CFAPI_OBJECT_PROP_BASE_NAME
Definition: plugin.h:238
Represents one command.
Definition: commands.h:37
#define TIMER_ERR_NONE
No error.
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
Bitmask of attacks this object does.
Definition: object.h:342
struct obj * spellitem
Spell ability monster is choosing to use.
Definition: object.h:394
static void cfapi_friendlylist_get_next(int *type,...)
Friend list access, to get objects on it.
Definition: plugins.c:4532
object * object_split(object *orig_ob, uint32_t nr, char *err, size_t size)
object_split(ob,nr) splits up ob into two parts.
Definition: object.c:2463
#define CFAPI_ARCH_PROP_NAME
Definition: plugin.h:314
StringBuffer * describe_item(const object *op, const object *owner, int use_media_tags, StringBuffer *buf)
Describes an item, in all its details.
Definition: item.c:980
void quest_set_player_state(player *pl, sstring quest_code, int state)
Set the state of a quest for a player.
Definition: quest.c:1132
Variables for the custom timers.
object * object_decrease_nrof(object *op, uint32_t i)
Decreases a specified number from the amount of an object.
Definition: object.c:2505
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)
Release the shared string if not NULL, and make it a reference to nv.
Definition: global.h:213
int16_t grace
Grace.
Definition: living.h:43
#define UPD_NROF
Definition: newclient.h:296
void get_tod(timeofday_t *tod)
Computes the ingame time of the day.
Definition: time.c:215
static void cfapi_object_query_money(int *type,...)
Wrapper for query_money().
Definition: plugins.c:3816
const char * custom_name
Custom name assigned by player.
Definition: object.h:432
int cftimer_create(int id, long delay, object *ob, int mode)
Creates a new timer.
Definition: timers.c:97
const char * localdir
Read/write data files.
Definition: global.h:245
tag_t count
Unique object number for this object.
Definition: object.h:299
living stats
Str, Con, Dex, etc.
Definition: object.h:368
static void cfapi_map_has_been_loaded(int *type,...)
Wrapper for has_been_loaded().
Definition: plugins.c:1249
uint16_t client_type
Public type information.
Definition: object.h:340
mapstruct * has_been_loaded(const char *name)
Checks whether map has been loaded.
Definition: map.c:79
int8_t Dex
Definition: living.h:35
char * jailmap
Where a player that is arrested in this region should be imprisoned.
Definition: map.h:297
struct archt * arch
Pointer to archetype.
Definition: object.h:412
#define CFAPI_OBJECT_PROP_HP
Definition: plugin.h:257
struct oblnk * next
Next item to link to.
Definition: object.h:444
Only for debugging purposes.
Definition: logger.h:13
static void cfapi_object_cast(int *type,...)
Wrapper for query_money().
Definition: plugins.c:3835
#define CFAPI_OBJECT_PROP_TITLE
Definition: plugin.h:183
int cftimer_find_free_id(void)
Finds a free ID for a new timer.
Definition: timers.c:144
const char * mapdir
Where the map files are.
Definition: global.h:247
uint32_t reset_timeout
How many seconds must elapse before this map should be reset.
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
Represents the ingame time.
Definition: tod.h:32
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
struct Settings settings
Server settings.
Definition: init.c:40
#define CFAPI_MAP_PROP_PATH
Definition: plugin.h:297
static void cfapi_get_hooks(int *type,...)
Definition: plugins.c:561
void object_set_enemy(object *op, object *enemy)
Sets the enemy of an object.
Definition: object.c:679
int remove_depletion(object *op, int level)
Remove depletion from op, if present, and warn player of such restorations.
Definition: living.c:751
#define CFAPI_OBJECT_PROP_FRIENDLY
Definition: plugin.h:236
void object_free2(object *ob, int flags)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
Definition: object.c:1391
#define CFAPI_OBJECT_PROP_ANIM_SPEED
Definition: plugin.h:235
struct archt * next
Next archetype in a linked list.
Definition: object.h:467
#define CFAPI_OBJECT_PROP_LUCK
Definition: plugin.h:240
void party_join(object *op, partylist *party)
Makes a player join a party.
Definition: party.c:84
struct dirent * readdir(DIR *)
Returns the next file/directory for specified directory handle, obtained through a call to opendir()...
Definition: win32.c:75
const char * get_periodofday(const int index)
give access to weekday names
Definition: time.c:102
object * object_merge(object *op, object *top)
This function goes through all objects below and including top, and merges op to the first matching o...
Definition: object.c:1869
#define CFAPI_OBJECT_PROP_ARCH_NAME
Definition: plugin.h:266
void query_short_name(const object *op, char *buf, size_t size)
query_short_name(object) is similar to query_name(), but doesn&#39;t contain any information about object...
Definition: item.c:547
object * object_get_player_container(object *op)
Finds the player carrying an object.
Definition: object.c:353
static void cfapi_system_add_string(int *type,...)
Wrapper for add_string().
Definition: plugins.c:889
int out_of_map(mapstruct *m, int x, int y)
this returns TRUE if the coordinates (x,y) are out of map m.
Definition: map.c:2294
#define CFAPI_OBJECT_PROP_INVISIBLE_TIME
Definition: plugin.h:213
static void cfapi_get_time(int *type,...)
Wrapper for get_tod().
Definition: plugins.c:1040
static void cfapi_map_get_object_at(int *type,...)
Wrapper for GET_MAP_OB().
Definition: plugins.c:1536
#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,...)
Wrapper for change_abil().
Definition: plugins.c:4120
void delete_map(mapstruct *m)
Frees the map, including the mapstruct.
Definition: map.c:1741
const char * msg
If this is a book/sign/magic mouth/etc.
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)
This will add &#39;str&#39; to the hash table.
Definition: shstr.c:124
#define CFAPI_PLAYER_QUEST_WAS_COMPLETED
Definition: plugin.h:293
EXTERN player * first_player
First player.
Definition: global.h:117
char * cost_string_from_value(uint64_t cost, int largest_coin)
Return the textual representation of a cost in a newly-allocated string.
Definition: shop.c:311
Lauwenmark: an invisible object holding a plugin event hook.
Definition: object.h:227
#define CFAPI_PARTY_PROP_NEXT
Definition: plugin.h:321
object * identify(object *op)
Identifies an item.
Definition: item.c:1437
struct pl * next
Pointer to next player, NULL if this is last.
Definition: player.h:93
static void cfapi_object_clean_object(int *type,...)
Definition: plugins.c:3723
#define GET_MAP_OB(M, X, Y)
Gets the bottom object on a map.
Definition: map.h:172
int check_path(const char *name, int prepend_dir)
This function checks if a file with the given path exists.
Definition: map.c:203
#define CFAPI_OBJECT_PROP_NROF
Definition: plugin.h:193
int8_t glow_radius
indicates the glow radius of the object
Definition: object.h:364
#define CFAPI_OBJECT_PROP_MAXSP
Definition: plugin.h:262
f_plug_event eventfunc
Event Handler function.
Definition: plugin.h:144
void object_copy(const object *src_ob, object *dest_ob)
Copy object first frees everything allocated by the second object, and then copies the contents of th...
Definition: object.c:838
#define CFAPI_ARCH_PROP_CLONE
Definition: plugin.h:318
struct _crossfire_plugin * prev
Previous plugin in list.
Definition: plugin.h:152
static void cfapi_object_transfer(int *type,...)
Object transfer.
Definition: plugins.c:3963
#define EVENT_PLAYER_DEATH
Global Death event.
Definition: plugin.h:86
static void cfapi_object_remove_depletion(int *type,...)
Definition: plugins.c:3298
int8_t Pow
Definition: living.h:35
int closedir(DIR *)
Dispose of a directory handle.
Definition: win32.c:108
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
This rolls up wall, blocks_magic, blocks_view, etc, all into one function that just returns a P_...
Definition: map.c:302
struct obj * inv
Pointer to the first object in the inventory.
Definition: object.h:290
void object_set_cheat(object *op)
object_set_cheat(object) sets the cheat flag (WAS_WIZ) in the object and in all it&#39;s inventory (recur...
Definition: object.c:3122
#define NDI_UNIQUE
Print immediately, don&#39;t buffer.
Definition: newclient.h:245
#define CFAPI_PLAYER_PROP_MARKED_ITEM
Definition: plugin.h:282
static void cfapi_map_get_map(int *type,...)
Gets map information.
Definition: plugins.c:1198
struct obj * head
Points to the main object of a large body.
Definition: object.h:296
#define MSG_SUBTYPE_NONE
Definition: newclient.h:398
static void cfapi_object_distance(int *type,...)
Wrapper for object_distance().
Definition: plugins.c:3650
#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 LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.c:51
#define CFAPI_OBJECT_PROP_TYPE
Definition: plugin.h:196
static const hook_entry plug_hooks[]
All hooked functions plugins can call.
Definition: plugins.c:140
char * msg
The description of the region.
Definition: map.h:293
static void cfapi_object_forget_spell(int *type,...)
Definition: plugins.c:3878
#define CFAPI_OBJECT_PROP_POW
Definition: plugin.h:253
static void cfapi_get_weekday_name(int *type,...)
Wrapper for get_season_name().
Definition: plugins.c:1083
static void cfapi_map_message(int *type,...)
Definition: plugins.c:1514
static void cfapi_object_update(int *type,...)
Wrapper for object_update().
Definition: plugins.c:3671
object * mark
Marked object.
Definition: player.h:194
#define FLAG_WAS_WIZ
Player was once a wiz.
Definition: define.h:234
EXTERN region * first_region
First region.
Definition: global.h:119
uint8_t pick_up
See crossfire.doc.
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)
Move an object (even linked objects) to another spot on the same map.
Definition: move.c:144
MoveType move_block
What movement types this blocks.
Definition: object.h:425
uint8_t run_away
Monster runs away if it&#39;s hp goes below this percentage.
Definition: object.h:384
#define CFAPI_OBJECT_PROP_GLOW_RADIUS
Definition: plugin.h:220
struct mapdef * next
Next map, linked list.
Definition: map.h:326
static void cfapi_object_clone(int *type,...)
Clone an object, either through object_create_clone() or object_copy().
Definition: plugins.c:3415
static void cfapi_object_reset(int *type,...)
Wrapper for clear_reset().
Definition: plugins.c:3709
void object_set_msg(object *op, const char *msg)
Set the message field of an object.
Definition: object.c:4695
int object_find_free_spot(const object *ob, mapstruct *m, int x, int y, int start, int stop)
object_find_free_spot(object, map, x, y, start, stop) will search for a spot at the given map and coo...
Definition: object.c:3415
int check_trigger(object *op, object *cause)
Definition: button.c:523
#define CFAPI_OBJECT_PROP_PRESENT
Definition: plugin.h:243
float move_slow_penalty
How much this slows down the object.
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)
Describes an item.
Definition: item.c:625
#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)
Same as create_pathname(), but for the overlay maps.
Definition: map.c:125
object * map_find_by_archetype(mapstruct *m, int x, int y, const archetype *at)
Searches for any objects with a matching archetype at the given map and coordinates.
Definition: object.c:2944
This is a game-map.
Definition: map.h:325
const New_Face * face
Face with colors.
Definition: object.h:332
#define CFAPI_OBJECT_PROP_MAXHP
Definition: plugin.h:261
int can_pay(object *pl)
Checks all unpaid items in op&#39;s inventory, adds up all the money they have, and checks that they can ...
Definition: shop.c:812
#define FLAG_UNIQUE
Item is really unique (UNIQUE_ITEMS)
Definition: define.h:288
#define CFAPI_OBJECT_PROP_VALUE
Definition: plugin.h:207
static void cfapi_cost_string_from_value(int *type,...)
Wrapper for cost_string_from_value, modified to take a buffer and length instead of a StringBuffer...
Definition: plugins.c:763
void ext_info_map(int color, const mapstruct *map, uint8_t type, uint8_t subtype, const char *str1)
Writes to everyone on the specified map.
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)
First function called in a plugin.
Definition: plugin.h:129
int32_t move_status
What stage in attack mode.
Definition: object.h:390
int16_t level
Level of creature or object.
Definition: object.h:351
int8_t facing
Object is oriented/facing that way.
Definition: object.h:335
void fix_object(object *op)
Updates all abilities given by applied objects in the inventory of the given object.
Definition: living.c:1120
static void send_changed_object(object *op)
Notify clients about a changed object.
Definition: plugins.c:282
unsigned find_face(const char *name, unsigned error)
This returns an the face number of face &#39;name&#39;.
Definition: image.c:303
player * find_player_partial_name(const char *plname)
Find a player by a partial name.
Definition: player.c:109
#define CFAPI_OBJECT_PROP_WIS
Definition: plugin.h:251
EXTERN mapstruct * first_map
First map.
Definition: global.h:118
int quest_was_completed(player *pl, sstring quest_code)
Check if a quest was completed once for a player, without taking account the current state...
Definition: quest.c:1142
#define CFAPI_OBJECT_PROP_DURATION
Definition: plugin.h:278
EXTERN archetype * first_archetype
First archetype.
Definition: global.h:122
char * longname
Official title of the region, this might be defined to be the same as name.
Definition: map.h:291
void object_update_speed(object *op)
Updates the speed of an object.
Definition: object.c:1129
#define CFAPI_MAP_PROP_ENTER_X
Definition: plugin.h:307
void clean_object(object *op)
Remove and free all objects in the inventory of the given object.
Definition: map.c:1631
int32_t value
How much money it is worth (or contains)
Definition: object.h:350
object * object_get_owner(object *op)
Returns the object which this object marks as being the owner.
Definition: object.c:559
#define CFAPI_OBJECT_PROP_OB_ABOVE
Definition: plugin.h:171
int8_t magic
Any magical bonuses to this item.
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
More definite name, like "generate_kobold".
Definition: object.h:466
#define EVENT_BORN
A new character has been created.
Definition: plugin.h:83
char * stringbuffer_finish(StringBuffer *sb)
Deallocate the string buffer instance and return the string.
Definition: stringbuffer.c:76
f_plug_event gevent[NR_EVENTS]
Global events registered.
Definition: plugin.h:150
int plugins_remove_plugin(const char *id)
Unload the specified plugin.
Definition: plugins.c:698
void(* f_plug_api)(int *type,...)
General API function.
Definition: plugin.h:125
One loaded plugin.
Definition: plugin.h:143
int execute_global_event(int eventcode,...)
Definition: plugins.c:379
object * object_find_by_arch_name(const object *who, const char *name)
Find object in inventory by archetype name.
Definition: object.c:4143
object * object_present_in_ob_by_name(int type, const char *str, const object *op)
Searches for any objects with a matching type & name variable in the inventory of the given object...
Definition: object.c:3039
#define CFAPI_OBJECT_PROP_PREV_ACTIVE_OB
Definition: plugin.h:174
#define FOR_INV_PREPARE(op_, it_)
Constructs a loop iterating over the inventory of an object.
Definition: define.h:705
int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg)
Main dispatch when someone casts a spell.
Definition: spell_util.c:1471
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to...
Definition: object.c:1654
#define EVENT_USER
User-defined event.
Definition: plugin.h:78
static void cfapi_generate_random_map(int *type,...)
Wrapper for generate_random_map().
Definition: plugins.c:4596
#define CFAPI_OBJECT_PROP_PATH_DENIED
Definition: plugin.h:203
static void cfapi_map_update_position(int *type,...)
Wrapper for update_position().
Definition: plugins.c:1485
#define CFAPI_OBJECT_PROP_MOVE_BLOCK
Definition: plugin.h:272
#define CFAPI_REGION_PROP_NAME
Definition: plugin.h:325
struct obj * attacked_by
This object start to attack us! only player & monster.
Definition: object.h:382
#define CFAPI_PPARTY
Definition: plugin.h:116
static void cfapi_map_change_light(int *type,...)
Wrapper for change_map_light().
Definition: plugins.c:1591
int32_t food
How much food in stomach.
Definition: living.h:47
#define FLAG_FREED
Object is in the list of free objects.
Definition: define.h:233
#define EVENT_MUZZLE
A player was Muzzled (no_shout set).
Definition: plugin.h:96
uint32_t count
Any numbers typed before a command.
Definition: player.h:109