Debian Codegraph @

plugins/common/plugin_common.c

raw symbols SCIP
1 /*****************************************************************************/
2 /* Crossfire Plugin Interface Common Parts */
3 /* Version: 2.0beta8 (also known as "Alexander") */
4 /* Contact: [email protected] */
5 /*****************************************************************************/
6 /* The CPICP are the various functions of the server that can be used by all */
7 /* plugins. It is recommended that plugins do not call the server-provided */
8 /* functions directly, but instead use the wrappers provided here by the */
9 /* CPICP interface. By doing so, various validity checks can be performed */
10 /* by CPICP, protecting the server from potential nasty effects of passing */
11 /* it wrong parameter values. */
12 /*****************************************************************************/
13 /* That code is placed under the GNU General Public Licence (GPL) */
14 /* (C)2001-2005 by Chachkoff Yann (Feel free to deliver your complaints) */
15 /*****************************************************************************/
16 /* CrossFire, A Multiplayer game for X-windows */
17 /* */
18 /* Copyright (C) 2000 Mark Wedel */
19 /* Copyright (C) 1992 Frank Tore Johansen */
20 /* */
21 /* This program is free software; you can redistribute it and/or modify */
22 /* it under the terms of the GNU General Public License as published by */
23 /* the Free Software Foundation; either version 2 of the License, or */
24 /* (at your option) any later version. */
25 /* */
26 /* This program is distributed in the hope that it will be useful, */
27 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
28 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
29 /* GNU General Public License for more details. */
30 /* */
31 /* You should have received a copy of the GNU General Public License */
32 /* along with this program; if not, write to the Free Software */
33 /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
34 /* */
35 /*****************************************************************************/
36
37 #include <assert.h>
38 #include <string.h>
39
40 #include "plugin_common.h"
41
42 static f_plug_api cfapiSystem_add_string = NULL;
43 static f_plug_api cfapiSystem_find_string = NULL;
44 static f_plug_api cfapiSystem_register_global_event = NULL;
45 static f_plug_api cfapiSystem_remove_string = NULL;
46 static f_plug_api cfapiSystem_unregister_global_event = NULL;
47 static f_plug_api cfapiSystem_strdup_local = NULL;
48 static f_plug_api cfapiSystem_find_animation = NULL;
49 static f_plug_api cfapiSystem_find_face = NULL;
50 static f_plug_api cfapiSystem_log = NULL;
51 static f_plug_api cfapiSystem_get_time = NULL;
52 static f_plug_api cfapiSystem_timer_create = NULL;
53 static f_plug_api cfapiSystem_timer_destroy = NULL;
54 static f_plug_api cfapiSystem_directory = NULL;
55 static f_plug_api cfapiSystem_re_cmp = NULL;
56
57 static f_plug_api cfapiObject_get_property = NULL;
58 static f_plug_api cfapiObject_set_property = NULL;
59 static f_plug_api cfapiObject_apply = NULL;
60 static f_plug_api cfapiObject_identify = NULL;
61 static f_plug_api cfapiObject_describe = NULL;
62 static f_plug_api cfapiObject_drain = NULL;
63 static f_plug_api cfapiObject_fix = NULL;
64 static f_plug_api cfapiObject_give_skill = NULL;
65 static f_plug_api cfapiObject_transmute = NULL;
66 static f_plug_api cfapiObject_remove = NULL;
67 static f_plug_api cfapiObject_delete = NULL;
68 static f_plug_api cfapiObject_clone = NULL;
69 static f_plug_api cfapiObject_create = NULL;
70 static f_plug_api cfapiObject_insert = NULL;
71 static f_plug_api cfapiObject_split = NULL;
72 static f_plug_api cfapiObject_merge = NULL;
73 static f_plug_api cfapiObject_distance = NULL;
74 static f_plug_api cfapiObject_update = NULL;
75 static f_plug_api cfapiObject_clear = NULL;
76 static f_plug_api cfapiObject_reset = NULL;
77 static f_plug_api cfapiObject_activate_rune = NULL;
78 static f_plug_api cfapiObject_check_trigger = NULL;
79 static f_plug_api cfapiObject_query_money = NULL;
80 static f_plug_api cfapiObject_cast = NULL;
81 static f_plug_api cfapiObject_learn_spell = NULL;
82 static f_plug_api cfapiObject_forget_spell = NULL;
83 static f_plug_api cfapiObject_check_spell = NULL;
84 static f_plug_api cfapiObject_pay_amount = NULL;
85 static f_plug_api cfapiObject_pay_item = NULL;
86 static f_plug_api cfapiObject_transfer = NULL;
87 static f_plug_api cfapiObject_find_archetype_inside = NULL;
88 static f_plug_api cfapiObject_find_by_arch_name = NULL;
89 static f_plug_api cfapiObject_find_by_name = NULL;
90 static f_plug_api cfapiObject_out_of_map = NULL;
91 static f_plug_api cfapiObject_drop = NULL;
92 static f_plug_api cfapiObject_change_abil = NULL;
93 static f_plug_api cfapiObject_say = NULL;
94 static f_plug_api cfapiMap_get_property = NULL;
95 static f_plug_api cfapiMap_set_property = NULL;
96 static f_plug_api cfapiMap_get_map = NULL;
97 static f_plug_api cfapiMap_message = NULL;
98 static f_plug_api cfapiMap_get_object_at = NULL;
99 static f_plug_api cfapiMap_find_by_archetype_name = NULL;
100 static f_plug_api cfapiMap_create_path = NULL;
101 static f_plug_api cfapiMap_has_been_loaded = NULL;
102 static f_plug_api cfapiMap_change_light = NULL;
103 static f_plug_api cfapiMap_trigger_connected = NULL;
104 static f_plug_api cfapiPlayer_find = NULL;
105 static f_plug_api cfapiPlayer_message = NULL;
106 static f_plug_api cfapiObject_teleport = NULL;
107 static f_plug_api cfapiObject_pickup = NULL;
108 static f_plug_api cfapiObject_get_key = NULL;
109 static f_plug_api cfapiObject_set_key = NULL;
110 static f_plug_api cfapiObject_move = NULL;
111 static f_plug_api cfapiObject_apply_below = NULL;
112 static f_plug_api cfapiArchetype_get_property = NULL;
113 static f_plug_api cfapiParty_get_property = NULL;
114 static f_plug_api cfapiRegion_get_property = NULL;
115 static f_plug_api cfapiPlayer_can_pay = NULL;
116 static f_plug_api cfapiFriendlylist_get_next = NULL;
117 static f_plug_api cfapiSet_random_map_variable = NULL;
118 static f_plug_api cfapiGenerate_random_map = NULL;
119 static f_plug_api cfapiObject_change_exp = NULL;
120 static f_plug_api cfapiSystem_get_month_name = NULL;
121 static f_plug_api cfapiSystem_get_season_name = NULL;
122 static f_plug_api cfapiSystem_get_weekday_name = NULL;
123 static f_plug_api cfapiSystem_get_periodofday_name = NULL;
124 static f_plug_api cfapiObject_user_event = NULL;
125 static f_plug_api cfapiCost_string_from_value = NULL;
126 static f_plug_api cfapiPlayer_quest = NULL;
127 static f_plug_api cfapiObject_remove_depletion = NULL;
128 static f_plug_api cfapiPlayer_knowledge = NULL;
129 static f_plug_api cfapiObject_perm_exp = NULL;
130
131 #define GET_HOOK(x, y, z) { \
132 getHooks(&z, 1, y, &x); \
133 if (z != CFAPI_FUNC) { \
134 printf("unable to find hook %s!\n", y); \
135 return 0; \
136 } \
137 }
138
139 int cf_init_plugin(f_plug_api getHooks) {
140 int z;
141
142 GET_HOOK(cfapiSystem_strdup_local, "cfapi_system_strdup_local", z);
143 GET_HOOK(cfapiSystem_add_string, "cfapi_system_add_string", z);
144 GET_HOOK(cfapiSystem_register_global_event, "cfapi_system_register_global_event", z);
145 GET_HOOK(cfapiSystem_remove_string, "cfapi_system_remove_string", z);
146 GET_HOOK(cfapiSystem_directory, "cfapi_system_directory", z);
147 GET_HOOK(cfapiSystem_unregister_global_event, "cfapi_system_unregister_global_event", z);
148 GET_HOOK(cfapiSystem_find_animation, "cfapi_system_find_animation", z);
149 GET_HOOK(cfapiSystem_find_face, "cfapi_system_find_face", z);
150 GET_HOOK(cfapiSystem_re_cmp, "cfapi_system_re_cmp", z);
151 GET_HOOK(cfapiObject_get_property, "cfapi_object_get_property", z);
152 GET_HOOK(cfapiObject_set_property, "cfapi_object_set_property", z);
153 GET_HOOK(cfapiObject_apply, "cfapi_object_apply", z);
154 GET_HOOK(cfapiObject_identify, "cfapi_object_identify", z);
155 GET_HOOK(cfapiObject_describe, "cfapi_object_describe", z);
156 GET_HOOK(cfapiObject_drain, "cfapi_object_drain", z);
157 GET_HOOK(cfapiObject_fix, "cfapi_object_fix", z);
158 GET_HOOK(cfapiObject_give_skill, "cfapi_object_give_skill", z);
159 GET_HOOK(cfapiObject_transmute, "cfapi_object_transmute", z);
160 GET_HOOK(cfapiObject_remove, "cfapi_object_remove", z);
161 GET_HOOK(cfapiObject_delete, "cfapi_object_delete", z);
162 GET_HOOK(cfapiObject_clone, "cfapi_object_clone", z);
163 GET_HOOK(cfapiObject_create, "cfapi_object_create", z);
164 GET_HOOK(cfapiObject_insert, "cfapi_object_insert", z);
165 GET_HOOK(cfapiObject_split, "cfapi_object_split", z);
166 GET_HOOK(cfapiObject_merge, "cfapi_object_merge", z);
167 GET_HOOK(cfapiObject_distance, "cfapi_object_distance", z);
168 GET_HOOK(cfapiObject_update, "cfapi_object_update", z);
169 GET_HOOK(cfapiObject_clear, "cfapi_object_clear", z);
170 GET_HOOK(cfapiObject_reset, "cfapi_object_reset", z);
171 GET_HOOK(cfapiObject_activate_rune, "cfapi_object_spring_trap", z);
172 GET_HOOK(cfapiObject_check_trigger, "cfapi_object_check_trigger", z);
173 GET_HOOK(cfapiObject_query_money, "cfapi_object_query_money", z);
174 GET_HOOK(cfapiObject_cast, "cfapi_object_cast", z);
175 GET_HOOK(cfapiObject_learn_spell, "cfapi_object_learn_spell", z);
176 GET_HOOK(cfapiObject_forget_spell, "cfapi_object_forget_spell", z);
177 GET_HOOK(cfapiObject_check_spell, "cfapi_object_check_spell", z);
178 GET_HOOK(cfapiObject_pay_amount, "cfapi_object_pay_amount", z);
179 GET_HOOK(cfapiObject_pay_item, "cfapi_object_pay_item", z);
180 GET_HOOK(cfapiObject_transfer, "cfapi_object_transfer", z);
181 GET_HOOK(cfapiObject_find_archetype_inside, "cfapi_object_find_archetype_inside", z);
182 GET_HOOK(cfapiObject_remove, "cfapi_object_remove", z);
183 GET_HOOK(cfapiObject_delete, "cfapi_object_delete", z);
184 GET_HOOK(cfapiObject_out_of_map, "cfapi_map_out_of_map", z);
185 GET_HOOK(cfapiObject_drop, "cfapi_object_drop", z);
186 GET_HOOK(cfapiObject_change_abil, "cfapi_object_change_abil", z);
187 GET_HOOK(cfapiObject_say, "cfapi_object_say", z);
188 GET_HOOK(cfapiMap_create_path, "cfapi_map_create_path", z);
189 GET_HOOK(cfapiMap_get_property, "cfapi_map_get_property", z);
190 GET_HOOK(cfapiMap_set_property, "cfapi_map_set_property", z);
191 GET_HOOK(cfapiMap_get_map, "cfapi_map_get_map", z);
192 GET_HOOK(cfapiMap_message, "cfapi_map_message", z);
193 GET_HOOK(cfapiMap_get_object_at, "cfapi_map_get_object_at", z);
194 GET_HOOK(cfapiMap_find_by_archetype_name, "cfapi_map_find_by_archetype_name", z);
195 GET_HOOK(cfapiMap_change_light, "cfapi_map_change_light", z);
196 GET_HOOK(cfapiMap_has_been_loaded, "cfapi_map_has_been_loaded", z);
197 GET_HOOK(cfapiMap_trigger_connected, "cfapi_map_trigger_connected", z);
198 GET_HOOK(cfapiPlayer_find, "cfapi_player_find", z);
199 GET_HOOK(cfapiPlayer_message, "cfapi_player_message", z);
200 GET_HOOK(cfapiObject_teleport, "cfapi_object_teleport", z);
201 GET_HOOK(cfapiObject_pickup, "cfapi_object_pickup", z);
202 GET_HOOK(cfapiObject_get_key, "cfapi_object_get_key", z);
203 GET_HOOK(cfapiObject_set_key, "cfapi_object_set_key", z);
204 GET_HOOK(cfapiObject_move, "cfapi_object_move", z);
205 GET_HOOK(cfapiObject_apply_below, "cfapi_object_apply_below", z);
206 GET_HOOK(cfapiArchetype_get_property, "cfapi_archetype_get_property", z);
207 GET_HOOK(cfapiParty_get_property, "cfapi_party_get_property", z);
208 GET_HOOK(cfapiRegion_get_property, "cfapi_region_get_property", z);
209 GET_HOOK(cfapiPlayer_can_pay, "cfapi_player_can_pay", z);
210 GET_HOOK(cfapiSystem_log, "cfapi_log", z);
211 GET_HOOK(cfapiSystem_get_time, "cfapi_system_get_time", z);
212 GET_HOOK(cfapiSystem_timer_create, "cfapi_system_timer_create", z);
213 GET_HOOK(cfapiSystem_timer_destroy, "cfapi_system_timer_destroy", z);
214 GET_HOOK(cfapiFriendlylist_get_next, "cfapi_friendlylist_get_next", z);
215 GET_HOOK(cfapiSet_random_map_variable, "cfapi_set_random_map_variable", z);
216 GET_HOOK(cfapiGenerate_random_map, "cfapi_generate_random_map", z);
217 GET_HOOK(cfapiObject_change_exp, "cfapi_object_change_exp", z);
218 GET_HOOK(cfapiSystem_get_season_name, "cfapi_system_get_season_name", z);
219 GET_HOOK(cfapiSystem_get_month_name, "cfapi_system_get_month_name", z);
220 GET_HOOK(cfapiSystem_get_weekday_name, "cfapi_system_get_weekday_name", z);
221 GET_HOOK(cfapiSystem_get_periodofday_name, "cfapi_system_get_periodofday_name", z);
222 GET_HOOK(cfapiObject_user_event, "cfapi_object_user_event", z);
223 GET_HOOK(cfapiSystem_find_string, "cfapi_system_find_string", z);
224 GET_HOOK(cfapiCost_string_from_value, "cfapi_cost_string_from_value", z);
225 GET_HOOK(cfapiPlayer_quest, "cfapi_player_quest", z);
226 GET_HOOK(cfapiObject_remove_depletion, "cfapi_object_remove_depletion", z);
227 GET_HOOK(cfapiObject_find_by_arch_name, "cfapi_object_find_by_arch_name", z);
228 GET_HOOK(cfapiObject_find_by_name, "cfapi_object_find_by_name", z);
229 GET_HOOK(cfapiPlayer_knowledge, "cfapi_player_knowledge", z);
230 GET_HOOK(cfapiObject_perm_exp, "cfapi_object_perm_exp", z);
231 return 1;
232 }
233
234 /* Should get replaced by tons of more explicit wrappers */
235 /*void *cf_map_get_property(mapstruct *map, int propcode) {
236 int type;
237 return cfapiMap_get_property(&type, propcode, map);
238 }*/
239
240 int cf_map_get_int_property(mapstruct *map, int property) {
241 int type, value;
242
243 cfapiMap_get_property(&type, map, property, &value);
244 assert(type == CFAPI_INT);
245 return value;
246 }
247
248 int cf_object_user_event(object *op, object *activator, object *third, const char *message, int fix) {
249 int type, value;
250
251 cfapiObject_user_event(&type, op, activator, third, message, fix, &value);
252 assert(type == CFAPI_INT);
253 return value;
254 }
255
256 sstring cf_map_get_sstring_property(mapstruct *map, int propcode) {
257 int type;
258 sstring value;
259
260 cfapiMap_get_property(&type, map, propcode, &value);
261 assert(type == CFAPI_SSTRING);
262 return value;
263 }
264
265 mapstruct *cf_map_get_map_property(mapstruct *map, int propcode) {
266 int type;
267 mapstruct *value;
268
269 cfapiMap_get_property(&type, map, propcode, &value);
270 assert(type == CFAPI_PMAP);
271 return value;
272 }
273
274 region *cf_map_get_region_property(mapstruct *map, int propcode) {
275 int type;
276 region *value;
277
278 cfapiMap_get_property(&type, map, propcode, &value);
279 assert(type == CFAPI_PREGION);
280 return value;
281 }
282
283 /* Should get replaced by tons of more explicit wrappers */
284 void cf_map_set_int_property(mapstruct *map, int propcode, int value) {
285 int type;
286
287 cfapiMap_set_property(&type, map, propcode, value);
288 assert(type == CFAPI_INT);
289 }
290
291 void cf_map_set_string_property(mapstruct *map, int propcode, const char *value) {
292 int type;
293
294 cfapiMap_set_property(&type, map, propcode, value);
295 assert(type == CFAPI_STRING);
296 }
297
298 /* Should get replaced by tons of more explicit wrappers */
299 int16_t cf_object_get_resistance(object *op, int rtype) {
300 int type;
301 int16_t resist;
302
303 cfapiObject_get_property(&type, op, CFAPI_OBJECT_PROP_RESIST, rtype, &resist);
304 assert(type == CFAPI_INT16);
305 return resist;
306 }
307 void cf_object_set_resistance(object *op, int rtype, int16_t value) {
308 int type;
309
310 cfapiObject_set_property(&type, op, CFAPI_OBJECT_PROP_RESIST, rtype, value);
311 assert(type == CFAPI_INT16);
312 }
313
314 /* Should get replaced by tons of more explicit wrappers */
315 void cf_object_set_int_property(object *op, int propcode, int value) {
316 int type;
317
318 cfapiObject_set_property(&type, op, propcode, value);
319 assert(type == CFAPI_INT);
320 }
321 int cf_object_get_int_property(object *op, int propcode) {
322 int type, value;
323
324 cfapiObject_get_property(&type, op, propcode, &value);
325 assert(type == CFAPI_INT);
326 return value;
327 }
328 long cf_object_get_long_property(object *op, long propcode) {
329 int type;
330 long value;
331
332 cfapiObject_get_property(&type, op, propcode, &value);
333 assert(type == CFAPI_LONG);
334 return value;
335 }
336 void cf_object_set_movetype_property(object *op, int propcode, MoveType value) {
337 int type;
338
339 /* note: MoveType can't be used through va_arg, so use MoveType * */
340 cfapiObject_set_property(&type, op, propcode, &value);
341 assert(type == CFAPI_MOVETYPE);
342 }
343 MoveType cf_object_get_movetype_property(object *op, int propcode) {
344 int type;
345 MoveType value;
346
347 cfapiObject_get_property(&type, op, propcode, &value);
348 assert(type == CFAPI_MOVETYPE);
349 return value;
350 }
351 object *cf_object_get_object_property(object *op, int propcode) {
352 int type;
353 object *value;
354
355 cfapiObject_get_property(&type, op, propcode, &value);
356 assert(type == CFAPI_POBJECT);
357 return value;
358 }
359 mapstruct *cf_object_get_map_property(object *op, int propcode) {
360 int type;
361 mapstruct *value;
362
363 cfapiObject_get_property(&type, op, propcode, &value);
364 assert(type == CFAPI_PMAP);
365 return value;
366 }
367 int64_t cf_object_get_int64_property(object *op, int propcode) {
368 int type;
369 int64_t value;
370
371 cfapiObject_get_property(&type, op, propcode, &value);
372 assert(type == CFAPI_SINT64);
373 return value;
374 }
375 /* Should get replaced by tons of more explicit wrappers */
376 void cf_object_set_long_property(object *op, int propcode, long value) {
377 int type;
378
379 cfapiObject_set_property(&type, op, propcode, value);
380 assert(type == CFAPI_LONG);
381 }
382 void cf_object_set_float_property(object *op, int propcode, float value) {
383 int type;
384
385 cfapiObject_set_property(&type, op, propcode, value);
386 assert(type == CFAPI_FLOAT);
387 }
388 void cf_object_set_int64_property(object *op, int propcode, int64_t value) {
389 int type;
390
391 cfapiObject_set_property(&type, op, propcode, value);
392 assert(type == CFAPI_SINT64);
393 }
394 float cf_object_get_float_property(object *op, int propcode) {
395 int type;
396 float value;
397
398 cfapiObject_get_property(&type, op, propcode, &value);
399 assert(type == CFAPI_FLOAT);
400 return value;
401 }
402 archetype *cf_object_get_archetype_property(object *op, int propcode) {
403 int type;
404 archetype *value;
405
406 cfapiObject_get_property(&type, op, propcode, &value);
407 assert(type == CFAPI_PARCH);
408 return value;
409 }
410 partylist *cf_object_get_partylist_property(object *op, int propcode) {
411 int type;
412 partylist *value;
413
414 cfapiObject_get_property(&type, op, propcode, &value);
415 assert(type == CFAPI_PPARTY);
416 return value;
417 }
418 double cf_object_get_double_property(object *op, int propcode) {
419 int type;
420 double value;
421
422 cfapiObject_get_property(&type, op, propcode, &value);
423 assert(type == CFAPI_DOUBLE);
424 return value;
425 }
426 sstring cf_object_get_sstring_property(object *op, int propcode) {
427 int type;
428 sstring value;
429
430 cfapiObject_get_property(&type, op, propcode, &value);
431 assert(type == CFAPI_SSTRING);
432 return value;
433 }
434 char *cf_object_get_string_property(object *op, int propcode, char *buf, int size) {
435 int type;
436
437 cfapiObject_get_property(&type, op, propcode, buf, size);
438 assert(type == CFAPI_STRING);
439 return buf;
440 }
441 /* Should get replaced by tons of more explicit wrappers */
442 void cf_object_set_string_property(object *op, int propcode, const char *value) {
443 int type;
444
445 /* use cf_object_set_face() for changing the face! */
446 assert(propcode != CFAPI_OBJECT_PROP_FACE);
447 /* use cf_object_set_animation() to change the animation */
448 assert(propcode != CFAPI_OBJECT_PROP_ANIMATION);
449
450 cfapiObject_set_property(&type, op, propcode, value);
451 assert(type == CFAPI_STRING);
452 }
453
454 /**
455 * Set the object's face.
456 * @param op who to change the face for.
457 * @param face face to set.
458 * @return 0 if invalid face, non zero is set.
459 */
460 int cf_object_set_face(object *op, const char *face) {
461 int type, ret;
462 cfapiObject_set_property(&type, op, CFAPI_OBJECT_PROP_FACE, face, &ret);
463 assert(type == CFAPI_INT);
464 return ret;
465 }
466 /**
467 * Set the object's animation.
468 * @param op who to change the animation for.
469 * @param animation animation's name to set.
470 * @return 0 if invalid animation, non zero is set.
471 */
472 int cf_object_set_animation(object *op, const char *animation) {
473 int type, ret;
474 cfapiObject_set_property(&type, op, CFAPI_OBJECT_PROP_ANIMATION, animation, &ret);
475 assert(type == CFAPI_INT);
476 return ret;
477 }
478
479 void cf_object_set_object_property(object *op, int propcode, object *value) {
480 int type;
481
482 cfapiObject_set_property(&type, op, propcode, value);
483 assert(type == CFAPI_POBJECT);
484 }
485
486 /**
487 * Wrapper for change_exp().
488 * @copydoc change_exp().
489 */
490 void cf_object_change_exp(object *op, int64_t exp, const char *skill_name, int flag) {
491 int type;
492
493 cfapiObject_change_exp(&type, op, exp, skill_name && strlen(skill_name) > 0 ? skill_name : NULL, flag);
494 assert(type == CFAPI_NONE);
495 }
496
497 /**
498 * Wrapper for PERM_EXP macro.
499 * @return The amount of total experience that is permanent experience
500 */
501 int64_t cf_object_perm_exp(object *op) {
502 int type, ret;
503
504 cfapiObject_perm_exp(&type, op, &ret);
505 assert(type == CFAPI_SINT64);
506 return ret;
507 }
508
509 int cf_player_move(player *pl, int dir) {
510 int type, ret;
511
512 cfapiObject_move(&type, 1, pl, dir, &ret);
513 assert(type == CFAPI_INT);
514 return ret;
515 }
516 int cf_object_move(object *op, int dir, object*originator) {
517 int type, ret;
518
519 cfapiObject_move(&type, 0, op, dir, originator, &ret);
520 assert(type == CFAPI_INT);
521 return ret;
522 }
523 /**
524 * Wrapper for apply_manual().
525 * @copydoc apply_manual()
526 */
527 int cf_object_apply(object *op, object *tmp, int aflag) {
528 int type, ret;
529
530 cfapiObject_apply(&type, op, tmp, aflag, &ret);
531 return ret;
532 }
533
534 /**
535 * Wrapper for apply_by_living_below().
536 * @copydoc apply_by_living_below()
537 */
538 void cf_object_apply_below(object *pl) {
539 int type;
540
541 cfapiObject_apply_below(&type, pl);
542 }
543 /**
544 * Wrapper for object_remove().
545 * @copydoc object_remove()
546 */
547 void cf_object_remove(object *op) {
548 int type;
549
550 cfapiObject_remove(&type, op);
551 }
552 /**
553 * Wrapper for object_free_drop_inventory().
554 * @copydoc object_free_drop_inventory()
555 */
556 void cf_object_free_drop_inventory(object *ob) {
557 int type;
558
559 cfapiObject_delete(&type, ob);
560 }
561 /**
562 * Kinda wrapper for arch_present_in_ob().
563 */
564 object *cf_object_present_archname_inside(object *op, char *whatstr) {
565 int type;
566 object *value;
567
568 cfapiObject_find_archetype_inside(&type, op, whatstr, &value);
569 assert(type == CFAPI_POBJECT);
570 return value;
571 }
572
573 /**
574 * Wrapper for object_find_by_arch_name().
575 * @copydoc object_find_by_arch_name()
576 */
577 object *cf_object_find_by_arch_name(const object *who, const char *name) {
578 int type;
579 object *result;
580
581 cfapiObject_find_by_arch_name(&type, who, name, &result);
582 assert(type == CFAPI_POBJECT);
583 return result;
584 }
585
586 /**
587 * Wrapper for object_find_by_name().
588 * @copydoc object_find_by_name()
589 */
590 object *cf_object_find_by_name(const object *who, const char *name) {
591 int type;
592 object *result;
593
594 cfapiObject_find_by_name(&type, who, name, &result);
595 assert(type == CFAPI_POBJECT);
596 return result;
597 }
598
599 /**
600 * Wrapper for transfer_ob().
601 * @copydoc transfer_ob()
602 */
603 int cf_object_transfer(object *op, int x, int y, int randomly, object *originator) {
604 int type, value;
605
606 cfapiObject_transfer(&type, op, 0, x, y, randomly, originator, &value);
607 assert(type == CFAPI_INT);
608 return value;
609 }
610
611 /**
612 * Wrapper for move_to().
613 * @copydoc move_to()
614 */
615 int cf_object_move_to(object *op, int x, int y) {
616 int type, value;
617
618 cfapiObject_transfer(&type, op, 2, x, y, &value);
619 assert(type == CFAPI_INT);
620 return value;
621 }
622
623 /**
624 * Wrapper for object_insert_in_map_at().
625 * @copydoc object_insert_in_map_at().
626 */
627 object *cf_object_change_map(object *op, mapstruct *m, object *originator, int flag, int x, int y) {
628 int type;
629 object *value;
630
631 cfapiObject_transfer(&type, op, 1, m, originator, flag, x, y, &value);
632 assert(type == CFAPI_POBJECT);
633 return value;
634 }
635
636 /**
637 * Wrapper for GET_MAP_OB().
638 * @copydoc GET_MAP_OB()
639 */
640 object *cf_map_get_object_at(mapstruct *m, int x, int y) {
641 int type;
642 object *value;
643
644 cfapiMap_get_object_at(&type, m, x, y, &value);
645 assert(type == CFAPI_POBJECT);
646 return value;
647 }
648 /**
649 * Partial wrapper for ext_info_map().
650 * @todo add missing parameters.
651 */
652 void cf_map_message(mapstruct *m, const char *msg, int color) {
653 int type;
654
655 cfapiMap_message(&type, m, msg, color);
656 }
657
658 /**
659 * Clone an object.
660 * @param op
661 * what to clone.
662 * @param clonetype
663 * - 0 means to clone through object_create_clone().
664 * - 1 means to clone through object_copy().
665 * @return
666 * clone.
667 */
668 object *cf_object_clone(object *op, int clonetype) {
669 int type;
670 object *value;
671
672 cfapiObject_clone(&type, op, clonetype, &value);
673 assert(type == CFAPI_POBJECT);
674 return value;
675 }
676
677
678 /**
679 * Wrapper for object_split().
680 * @copydoc object_split().
681 */
682 object *cf_object_split(object *orig_ob, uint32_t nr, char *err, size_t size) {
683 int type;
684 object *value;
685
686 cfapiObject_split(&type, orig_ob, nr, err, size, &value);
687
688 if (value == NULL)
689 {
690 assert(type == CFAPI_NONE);
691 }
692 else
693 {
694 assert(type == CFAPI_POBJECT);
695 }
696
697 return value;
698 }
699
700
701 /**
702 * Wrapper for pay_for_item().
703 * @copydoc pay_for_item().
704 */
705 int cf_object_pay_item(object *op, object *pl) {
706 int type, value;
707
708 cfapiObject_pay_item(&type, op, pl, &value);
709 assert(type == CFAPI_INT);
710 return value;
711 }
712
713 /**
714 * Wrapper for pay_for_amount().
715 * @copydoc pay_for_amount().
716 */
717 int cf_object_pay_amount(object *pl, uint64_t to_pay) {
718 int type, value;
719
720 cfapiObject_pay_amount(&type, pl, to_pay, &value);
721 assert(type == CFAPI_INT);
722 return value;
723 }
724
725 /**
726 * Wrapper for cast_spell().
727 * @copydoc cast_spell().
728 */
729 int cf_object_cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg) {
730 int type, value;
731
732 cfapiObject_cast(&type, op, caster, dir, spell_ob, stringarg, &value);
733 assert(type == CFAPI_INT);
734 return value;
735 }
736
737 /**
738 * Wrapper for do_learn_spell().
739 * @copydoc do_learn_spell().
740 */
741 void cf_object_learn_spell(object *op, object *spell, int special_prayer) {
742 int type;
743
744 cfapiObject_learn_spell(&type, op, spell, special_prayer);
745 assert(type == CFAPI_NONE);
746 }
747
748 /**
749 * Wrapper for do_forget_spell(), except takes an object, not a string.
750 * @todo
751 * make coherent with do_forget_spell() (string instead of ob).
752 */
753 void cf_object_forget_spell(object *op, object *sp) {
754 int type;
755
756 cfapiObject_forget_spell(&type, op, sp);
757 }
758
759 /**
760 * Wrapper for check_spell_known().
761 * @copydoc check_spell_known()
762 */
763 object *cf_object_check_for_spell(object *op, const char *name) {
764 int type;
765 object *value;
766
767 cfapiObject_check_spell(&type, op, name, &value);
768 assert(type == CFAPI_POBJECT);
769 return value;
770 }
771
772 void cf_player_message(object *op, char *txt, int flags) {
773 int type;
774
775 cfapiPlayer_message(&type, flags, 0, op, txt);
776 assert(type == CFAPI_NONE);
777 }
778
779 /**
780 * Wrapper for remove_depletion().
781 * @copydoc remove_depletion()
782 */
783 int cf_object_remove_depletion(object *op, int level) {
784 int type, result;
785
786 cfapiObject_remove_depletion(&type, op, level, &result);
787 assert(type == CFAPI_INT);
788 return result;
789 }
790
791 /**
792 * Wrapper for identify().
793 * @copydoc identify()
794 * @param op
795 * @return
796 */
797 object *cf_identify(object *op) {
798 int type;
799 object *result;
800
801 cfapiObject_identify(&type, op, &result);
802 assert(type == CFAPI_POBJECT);
803 return result;
804 }
805
806 /**
807 * Wrapper for find_player_partial_name().
808 * @copydoc find_player_partial_name().
809 */
810 player *cf_player_find(const char *plname) {
811 int type;
812 player *value;
813
814 cfapiPlayer_find(&type, plname, &value);
815 assert(type == CFAPI_PPLAYER);
816 return value;
817 }
818
819 char *cf_player_get_title(object *op, char *title, int size) {
820 int type;
821
822 cfapiObject_get_property(&type, op, CFAPI_PLAYER_PROP_TITLE, title, size);
823 assert(type == CFAPI_STRING);
824 return title;
825 }
826
827 void cf_player_set_title(object *op, const char *title) {
828 int type;
829
830 cfapiObject_set_property(&type, op, CFAPI_PLAYER_PROP_TITLE, title);
831 }
832
833 sstring cf_player_get_ip(object *op) {
834 int type;
835 sstring value;
836
837 cfapiObject_get_property(&type, op, CFAPI_PLAYER_PROP_IP, &value);
838 assert(type == CFAPI_SSTRING);
839 return value;
840 }
841
842 object *cf_player_get_marked_item(object *op) {
843 int type;
844 object *value;
845
846 cfapiObject_get_property(&type, op, CFAPI_PLAYER_PROP_MARKED_ITEM, &value);
847 assert(type == CFAPI_POBJECT);
848 return value;
849 }
850
851 void cf_player_set_marked_item(object *op, object *ob) {
852 int type;
853
854 cfapiObject_set_property(&type, op, CFAPI_PLAYER_PROP_MARKED_ITEM, ob);
855 }
856
857 partylist *cf_player_get_party(object *op) {
858 return cf_object_get_partylist_property(op, CFAPI_PLAYER_PROP_PARTY);
859 }
860
861 void cf_player_set_party(object *op, partylist *party) {
862 int type;
863
864 cfapiObject_set_property(&type, op, CFAPI_PLAYER_PROP_PARTY, party);
865 }
866
867 /**
868 * Wrapper for can_pay().
869 * @copydoc can_pay().
870 */
871 int cf_player_can_pay(object *pl) {
872 int type, value;
873
874 cfapiPlayer_can_pay(&type, pl, &value);
875 assert(type == CFAPI_INT);
876 return value;
877 }
878
879 /**
880 * Wrapper for knowledge_player_has().
881 * @param op who to check knowledge for.
882 * @param knowledge what to check for.
883 * @return 0 if op is not a player or knowledge is not known, 1 else.
884 */
885 int cf_player_knowledge_has(object *op, const char *knowledge) {
886 int type, value;
887
888 cfapiPlayer_knowledge(&type, 1, op, knowledge, &value);
889 assert(type == CFAPI_INT);
890 return value;
891 }
892
893 /**
894 * Wrapper for knowledge_give();
895 * @param op who to give knowledge to.
896 * @param knowledge knowledge to give, internal value.
897 */
898 void cf_player_knowledge_give(object *op, const char *knowledge) {
899 int type;
900
901 cfapiPlayer_knowledge(&type, 2, op, knowledge);
902 assert(type == CFAPI_NONE);
903 }
904
905 /**
906 * Wrapper for player_arrest().
907 * @copydoc player_arrest()
908 */
909 int cf_player_arrest(object *who) {
910 int type, value;
911 cfapiObject_move(&type, 2, who, &value);
912 assert(type == CFAPI_INT);
913 return value;
914 }
915
916 /**
917 * Wrapper for ready_map_name().
918 * @copydoc ready_map_name()
919 */
920 mapstruct *cf_map_get_map(const char *name, int flags) {
921 int type;
922 mapstruct *ret;
923
924 cfapiMap_get_map(&type, 1, name, flags, &ret);
925 assert(type == CFAPI_PMAP);
926 return ret;
927 }
928
929 /**
930 * Wrapper for get_empty_map().
931 * @copydoc get_empty_map().
932 */
933 mapstruct *cf_get_empty_map(int sizex, int sizey) {
934 int type;
935 mapstruct *ret;
936
937 cfapiMap_get_map(&type, 0, sizex, sizey, &ret);
938 assert(type == CFAPI_PMAP);
939 return ret;
940 }
941
942 /**
943 * Wrapper for has_been_loaded().
944 * @copydoc has_been_loaded()
945 */
946 mapstruct *cf_map_has_been_loaded(const char *name) {
947 int type;
948 mapstruct *ret;
949
950 cfapiMap_has_been_loaded(&type, name, &ret);
951 assert(type == CFAPI_PMAP);
952 return ret;
953 }
954
955 /**
956 * Gives access to ::first_map.
957 * @return
958 * ::first_map.
959 */
960 mapstruct *cf_map_get_first(void) {
961 return cf_map_get_map_property(NULL, CFAPI_MAP_PROP_NEXT);
962 }
963
964 /**
965 * Wrapper for query_money().
966 * @copydoc query_money().
967 */
968 int cf_object_query_money(const object *op) {
969 int type, value;
970
971 cfapiObject_query_money(&type, op, &value);
972 assert(type == CFAPI_INT);
973 return value;
974 }
975
976 /**
977 * Wrapper for cost_string_from_value modified to take a char* and length instead of a StringBuffer.
978 */
979 void cf_cost_string_from_value(uint64_t cost, int largest_coin, char *buffer, int length) {
980 int type;
981
982 cfapiCost_string_from_value(&type, cost, largest_coin, buffer, length);
983 assert(type == CFAPI_NONE);
984 }
985
986 /**
987 * Wrapper for spring_trap().
988 * @copydoc spring_trap().
989 */
990 void cf_spring_trap(object *trap, object *victim) {
991 int type;
992
993 if (trap)
994 cfapiObject_activate_rune(&type, trap, victim);
995 }
996
997 /**
998 * Wrapper for check_trigger().
999 * @copydoc check_trigger().
1000 */
1001 int cf_object_check_trigger(object *op, object *cause) {
1002 int type, value;
1003
1004 cfapiObject_check_trigger(&type, op, cause, &value);
1005 assert(type == CFAPI_INT);
1006 return value;
1007 }
1008
1009 /**
1010 * Wrapper for trigger_connected().
1011 * @copydoc trigger_connected().
1012 */
1013 void cf_map_trigger_connected(objectlink *ol, object *cause, int state) {
1014 int type;
1015
1016 cfapiMap_trigger_connected(&type, ol, cause, state);
1017 assert(type == CFAPI_NONE);
1018 }
1019
1020 int cf_object_out_of_map(object *op, int x, int y) {
1021 int type, value;
1022
1023 cfapiObject_out_of_map(&type, op->map, x, y, &value);
1024 assert(type == CFAPI_INT);
1025 return value;
1026 }
1027
1028 void cf_object_drop(object *op, object *author) {
1029 int type;
1030
1031 cfapiObject_drop(&type, op, author);
1032 }
1033
1034 void cf_object_say(object *op, char *msg) {
1035 int type, value;
1036
1037 cfapiObject_say(&type, op, msg, &value);
1038 assert(type == CFAPI_INT);
1039 }
1040
1041 object *cf_object_insert_object(object *op, object *container) {
1042 int type;
1043 object *value;
1044
1045 cfapiObject_insert(&type, op, 3, container, &value);
1046 assert(type == CFAPI_POBJECT);
1047 return value;
1048 }
1049
1050 /**
1051 * Wrapper for create_pathname().
1052 * @copydoc create_pathname()
1053 */
1054 char *cf_get_maps_directory(const char *name, char *buf, int size) {
1055 int type;
1056
1057 cfapiMap_create_path(&type, 0, name, buf, size);
1058 assert(type == CFAPI_STRING);
1059 return buf;
1060 }
1061
1062 /**
1063 * Wrapper for object_new().
1064 * @copydoc object_new().
1065 */
1066 object *cf_create_object(void) {
1067 int type;
1068 object *value;
1069
1070 cfapiObject_create(&type, 0, &value);
1071 assert(type == CFAPI_POBJECT);
1072 return value;
1073 }
1074
1075 /**
1076 * Wrapper for create_archetype() and create_archetype_by_object_name().
1077 */
1078 object *cf_create_object_by_name(const char *name) {
1079 int type;
1080 object *value;
1081
1082 cfapiObject_create(&type, 1, name, &value);
1083 assert(type == CFAPI_POBJECT);
1084 return value;
1085 }
1086
1087 void cf_system_register_global_event(int event, const char *name, f_plug_event hook) {
1088 int type;
1089
1090 cfapiSystem_register_global_event(&type, event, name, hook);
1091 assert(type == CFAPI_NONE);
1092 }
1093
1094 void cf_system_unregister_global_event(int event, const char *name) {
1095 int type;
1096
1097 cfapiSystem_unregister_global_event(&type, event, name);
1098 assert(type == CFAPI_NONE);
1099 }
1100
1101 /**
1102 * Gets a directory Crossfire uses.
1103 * @param id
1104 * what directory to return:
1105 * -# @copydoc Settings::mapdir
1106 * -# @copydoc Settings::uniquedir
1107 * -# @copydoc Settings::tmpdir
1108 * -# @copydoc Settings::confdir
1109 * -# @copydoc Settings::localdir
1110 * -# @copydoc Settings::playerdir
1111 * -# @copydoc Settings::datadir
1112 * @return
1113 * directory. Must not be altered. NULL if invalid value.
1114 */
1115 const char *cf_get_directory(int id) {
1116 int type;
1117 const char *ret;
1118
1119 cfapiSystem_directory(&type, id, &ret);
1120 assert(type == CFAPI_STRING);
1121 return ret;
1122 }
1123
1124 /**
1125 * Wrapper for re_cmp().
1126 * @copydoc re_cmp()
1127 */
1128 const char *cf_re_cmp(const char *str, const char *regexp) {
1129 int type;
1130 const char *result;
1131
1132 cfapiSystem_re_cmp(&type, str, regexp, &result);
1133 assert(type == CFAPI_STRING);
1134 return result;
1135 }
1136
1137 /**
1138 * Wrapper for fix_object().
1139 * @copydoc fix_object()
1140 */
1141 void cf_fix_object(object *op) {
1142 int type;
1143
1144 if (op)
1145 cfapiObject_fix(&type, op);
1146 }
1147
1148 /**
1149 * Wrapper for add_string().
1150 * @copydoc add_string()
1151 */
1152 sstring cf_add_string(const char *str) {
1153 int type;
1154 sstring ret;
1155
1156 if (!str)
1157 return NULL;
1158 cfapiSystem_add_string(&type, str, &ret);
1159 assert(type == CFAPI_SSTRING);
1160 return ret;
1161 }
1162
1163 /**
1164 * Wrapper for free_string().
1165 * @copydoc free_string()
1166 */
1167 void cf_free_string(sstring str) {
1168 int type;
1169
1170 if (str)
1171 cfapiSystem_remove_string(&type, str);
1172 }
1173
1174 sstring cf_find_string(const char *str) {
1175 int type;
1176 sstring ret;
1177
1178 if (!str)
1179 return NULL;
1180
1181 cfapiSystem_find_string(&type, str, &ret);
1182 assert(type == CFAPI_SSTRING);
1183 return ret;
1184 }
1185
1186 char *cf_query_name(object *ob, char *name, int size) {
1187 int type;
1188
1189 cfapiObject_get_property(&type, ob, CFAPI_OBJECT_PROP_NAME, name, size);
1190 assert(type == CFAPI_STRING);
1191 return name;
1192 }
1193
1194 sstring cf_query_name_pl(object *ob) {
1195 int type;
1196 sstring value;
1197
1198 cfapiObject_get_property(&type, ob, CFAPI_OBJECT_PROP_NAME_PLURAL, &value);
1199 assert(type == CFAPI_SSTRING);
1200 return value;
1201 }
1202
1203 char *cf_query_base_name(object *ob, int plural, char *name, int size) {
1204 int type;
1205
1206 cfapiObject_get_property(&type, ob, CFAPI_OBJECT_PROP_BASE_NAME, name, size);
1207 assert(type == CFAPI_STRING);
1208 return name;
1209 }
1210
1211 sstring cf_object_get_msg(object *ob) {
1212 int type;
1213 sstring value;
1214
1215 cfapiObject_get_property(&type, ob, CFAPI_OBJECT_PROP_MESSAGE, &value);
1216 assert(type == CFAPI_SSTRING);
1217 return value;
1218 }
1219
1220 void cf_object_set_weight(object *ob, int weight) {
1221 int type;
1222
1223 cfapiObject_set_property(&type, ob, CFAPI_OBJECT_PROP_WEIGHT, weight);
1224 assert(type == CFAPI_INT);
1225 }
1226
1227 void cf_object_set_weight_limit(object *ob, int weight_limit) {
1228 int type;
1229
1230 cfapiObject_set_property(&type, ob, CFAPI_OBJECT_PROP_WEIGHT_LIMIT, weight_limit);
1231 assert(type == CFAPI_INT);
1232 }
1233
1234 int cf_object_get_weight(object *ob) {
1235 int type, weight;
1236
1237 cfapiObject_get_property(&type, ob, CFAPI_OBJECT_PROP_WEIGHT, &weight);
1238 assert(type == CFAPI_INT);
1239 return weight;
1240 }
1241
1242 int cf_object_get_weight_limit(object *ob) {
1243 int type, limit;
1244
1245 cfapiObject_get_property(&type, ob, CFAPI_OBJECT_PROP_WEIGHT_LIMIT, &limit);
1246 assert(type == CFAPI_INT);
1247 return limit;
1248 }
1249
1250 /**
1251 * @return -1=nrof is invalid, 0=nrof is ok#
1252 */
1253 int cf_object_set_nrof(object *ob, int nrof) {
1254 int type;
1255
1256 if (nrof < 0)
1257 return -1;
1258
1259 cfapiObject_set_property(&type, ob, CFAPI_OBJECT_PROP_NROF, nrof);
1260 return 0;
1261 }
1262
1263 int cf_object_get_nrof(object *ob) {
1264 int type, nrof;
1265
1266 cfapiObject_get_property(&type, ob, CFAPI_OBJECT_PROP_NROF, &nrof);
1267 return nrof;
1268 }
1269
1270 int cf_object_get_flag(object *ob, int flag) {
1271 int type;
1272 int rv;
1273
1274 cfapiObject_get_property(&type, ob, CFAPI_OBJECT_PROP_FLAGS, flag, &rv);
1275 if (rv != 0)
1276 return 1;
1277 else
1278 return 0;
1279 }
1280
1281 void cf_object_set_flag(object *ob, int flag, int value) {
1282 int type;
1283
1284 cfapiObject_set_property(&type, ob, CFAPI_OBJECT_PROP_FLAGS, flag, value ? 1 : 0);
1285 }
1286
1287 /**
1288 * Wrapper for object_insert_in_ob().
1289 * @copydoc object_insert_in_ob().
1290 */
1291 object *cf_object_insert_in_ob(object *op, object *where) {
1292 int type;
1293 object *value;
1294
1295 if (!cf_object_get_flag(op, FLAG_REMOVED)) {
1296 cfapiObject_remove(&type, op);
1297 }
1298
1299 cfapiObject_insert(&type, op, 3, where, &value);
1300 assert(type == CFAPI_POBJECT);
1301 return value;
1302 }
1303
1304 /**
1305 * Wrapper for object_insert_in_map().
1306 * @copydoc object_insert_in_map().
1307 */
1308 object *cf_map_insert_object_there(object *op, mapstruct *m, object *originator, int flag) {
1309 int type;
1310 object *value;
1311
1312 cfapiObject_insert(&type, op, 1, m, originator, flag, &value);
1313 assert(type == CFAPI_POBJECT);
1314 return value;
1315 }
1316
1317 /**
1318 * Wrapper for object_insert_in_map_at().
1319 * @todo
1320 * merge/replace with cf_object_change_map
1321 */
1322 object *cf_map_insert_object(mapstruct *where, object *op, int x, int y) {
1323 int type;
1324 object *value;
1325
1326 cfapiObject_insert(&type, op, 0, where, NULL, 0 , x, y, &value);
1327 assert(type == CFAPI_POBJECT);
1328 return value;
1329 }
1330
1331 /**
1332 * Will insert op in the map where around the spot x, y.
1333 * Combination of object_find_free_spot and object_insert_in_map_at.
1334 * @param where
1335 * map to insert into.
1336 * @param op
1337 * what to insert.
1338 * @param x
1339 * @param y
1340 * where to insert op.
1341 * @return
1342 * NULL if op couldn't be inserted around the spot, else op or an object it merged with.
1343 */
1344 object *cf_map_insert_object_around(mapstruct *where, object *op, int x, int y) {
1345 int type;
1346 object *value;
1347
1348 cfapiObject_insert(&type, op, 2, where, NULL, 0 , x, y, &value);
1349 assert(type == CFAPI_POBJECT);
1350 return value;
1351 }
1352
1353 int cf_object_teleport(object *op, mapstruct *map, int x, int y) {
1354 int type, value;
1355
1356 cfapiObject_teleport(&type, op, map, x, y, &value);
1357 assert(type == CFAPI_INT);
1358 return value;
1359 }
1360
1361 /**
1362 * Kinda wrapper for map_find_by_archetype_name().
1363 */
1364 object *cf_map_find_by_archetype_name(const char *str, mapstruct *map, int nx, int ny) {
1365 int type;
1366 object *value;
1367
1368 cfapiMap_find_by_archetype_name(&type, str, map, nx, ny, &value);
1369 assert(type == CFAPI_POBJECT);
1370 return value;
1371 }
1372
1373 int cf_map_get_difficulty(mapstruct *map) {
1374 return cf_map_get_int_property(map, CFAPI_MAP_PROP_DIFFICULTY);
1375 }
1376
1377 int cf_map_get_reset_time(mapstruct *map) {
1378 return cf_map_get_int_property(map, CFAPI_MAP_PROP_RESET_TIME);
1379 }
1380
1381 int cf_map_get_reset_timeout(mapstruct *map) {
1382 return cf_map_get_int_property(map, CFAPI_MAP_PROP_RESET_TIMEOUT);
1383 }
1384
1385 int cf_map_get_players(mapstruct *map) {
1386 return cf_map_get_int_property(map, CFAPI_MAP_PROP_PLAYERS);
1387 }
1388
1389 int cf_map_get_darkness(mapstruct *map) {
1390 return cf_map_get_int_property(map, CFAPI_MAP_PROP_DARKNESS);
1391 }
1392
1393 int cf_map_get_width(mapstruct *map) {
1394 return cf_map_get_int_property(map, CFAPI_MAP_PROP_WIDTH);
1395 }
1396
1397 int cf_map_get_height(mapstruct *map) {
1398 return cf_map_get_int_property(map, CFAPI_MAP_PROP_HEIGHT);
1399 }
1400
1401 int cf_map_get_enter_x(mapstruct *map) {
1402 return cf_map_get_int_property(map, CFAPI_MAP_PROP_ENTER_X);
1403 }
1404
1405 int cf_map_get_enter_y(mapstruct *map) {
1406 return cf_map_get_int_property(map, CFAPI_MAP_PROP_ENTER_Y);
1407 }
1408
1409 /**
1410 * Wrapper for change_map_light().
1411 * @copydoc change_map_light().
1412 */
1413 int cf_map_change_light(mapstruct *m, int change) {
1414 int type, value;
1415
1416 cfapiMap_change_light(&type, m, change, &value);
1417 assert(type == CFAPI_INT);
1418 return value;
1419 }
1420
1421 void cf_object_update(object *op, int flags) {
1422 int type;
1423
1424 cfapiObject_update(&type, op, flags);
1425 }
1426
1427 void cf_object_pickup(object *op, object *what) {
1428 int type;
1429
1430 cfapiObject_pickup(&type, op, what);
1431 assert(type == CFAPI_NONE);
1432 }
1433
1434 /**
1435 * Wrapper for strdup_local().
1436 *
1437 * @copydoc strdup_local().
1438 */
1439 char *cf_strdup_local(const char *str) {
1440 int type;
1441 char *dup;
1442
1443 if (str == NULL)
1444 return NULL;
1445 cfapiSystem_strdup_local(&type, str, &dup);
1446 assert(type == CFAPI_STRING);
1447 return dup;
1448 }
1449
1450 /**
1451 * Wrapper for get_map_flags().
1452 * @copydoc get_map_flags()
1453 */
1454 int cf_map_get_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny) {
1455 int type, value;
1456
1457 cfapiMap_get_property(&type, oldmap, CFAPI_MAP_PROP_FLAGS, newmap, x, y, nx, ny, &value);
1458 assert(type == CFAPI_INT);
1459 return value;
1460 }
1461
1462 /**
1463 * Wrapper for set_random_map_variable().
1464 * @copydoc set_random_map_variable()
1465 */
1466 int cf_random_map_set_variable(RMParms *rp, const char *buf) {
1467 int type, ret;
1468
1469 cfapiSet_random_map_variable(&type, rp, buf, &ret);
1470 assert(type == CFAPI_INT);
1471 return ret;
1472 }
1473
1474 /**
1475 * Wrapper for generate_random_map().
1476 * @copydoc generate_random_map()
1477 */
1478 mapstruct *cf_random_map_generate(const char *OutFileName, RMParms *RP, char **use_layout) {
1479 int type;
1480 mapstruct *map;
1481
1482 cfapiGenerate_random_map(&type, OutFileName, RP, use_layout, &map);
1483 assert(type == CFAPI_PMAP);
1484 return map;
1485 }
1486
1487 /**
1488 * Wrapper for find_animation().
1489 * @copydoc find_animation().
1490 */
1491 int cf_find_animation(const char *name) {
1492 int type, anim;
1493
1494 cfapiSystem_find_animation(&type, name, &anim);
1495 assert(type == CFAPI_INT);
1496 return anim;
1497 }
1498
1499 /**
1500 * Wrapper for find_face().
1501 * @copydoc find_face().
1502 */
1503 int cf_find_face(const char *name, int error) {
1504 int type, anim;
1505
1506 cfapiSystem_find_face(&type, name, error, &anim);
1507 assert(type == CFAPI_INT);
1508 return anim;
1509 }
1510
1511 /**
1512 * Wrapper for LOG().
1513 * @copydoc LOG().
1514 */
1515 void cf_log(LogLevel logLevel, const char *format, ...) {
1516 int type;
1517 /* Copied from common/logger.c */
1518 char buf[20480]; /* This needs to be really really big - larger than any other buffer, since that buffer may
1519 need to be put in this one. */
1520 va_list ap;
1521
1522 va_start(ap, format);
1523 buf[0] = '\0';
1524 vsprintf(buf, format, ap);
1525 va_end(ap);
1526
1527 cfapiSystem_log(&type, logLevel, buf);
1528 assert(type == CFAPI_NONE);
1529 }
1530
1531 /**
1532 * Wrapper for LOG() that
1533 * uses directly a buffer, without format
1534 */
1535 void cf_log_plain(LogLevel logLevel, const char *message) {
1536 int type;
1537
1538 cfapiSystem_log(&type, logLevel, message);
1539 assert(type == CFAPI_NONE);
1540 }
1541
1542 void cf_get_time(timeofday_t *tod) {
1543 int type;
1544
1545 cfapiSystem_get_time(&type, tod);
1546 assert(type == CFAPI_NONE);
1547 }
1548
1549 const char *cf_get_season_name(int index) {
1550 int type;
1551 char *result;
1552
1553 cfapiSystem_get_season_name(&type, index, &result);
1554 assert(type == CFAPI_STRING);
1555 return result;
1556 }
1557
1558 const char *cf_get_month_name(int index) {
1559 int type;
1560 char *result;
1561
1562 cfapiSystem_get_month_name(&type, index, &result);
1563 assert(type == CFAPI_STRING);
1564 return result;
1565 }
1566
1567 const char *cf_get_weekday_name(int index) {
1568 int type;
1569 char *result;
1570
1571 cfapiSystem_get_weekday_name(&type, index, &result);
1572 assert(type == CFAPI_STRING);
1573 return result;
1574 }
1575
1576 const char *cf_get_periodofday_name(int index) {
1577 int type;
1578 char *result;
1579
1580 cfapiSystem_get_periodofday_name(&type, index, &result);
1581 assert(type == CFAPI_STRING);
1582 return result;
1583 }
1584
1585 /**
1586 * Creates a timer, equivalent of calling cftimer_create().
1587 *
1588 * @param ob
1589 * ::object that will get called. Should handle ::EVENT_TIMER.
1590 * @param delay
1591 * delay, seconds or ticks.
1592 * @param mode
1593 * timer mode, ::TIMER_MODE_SECONDS or ::TIMER_MODE_CYCLES
1594 * @return
1595 * timer identifier, or one of ::TIMER_ERR_ID, ::TIMER_ERR_OBJ or ::TIMER_ERR_MODE
1596 */
1597 int cf_timer_create(object *ob, long delay, int mode) {
1598 int type, timer;
1599
1600 cfapiSystem_timer_create(&type, ob, delay, mode, &timer);
1601 assert(type == CFAPI_INT);
1602 return timer;
1603 }
1604
1605 /**
1606 * Destroys specified timer, equivalent of calling cftimer_destroy().
1607 *
1608 * @param id
1609 * timer to destroy
1610 * @return
1611 * ::TIMER_ERR_ID if invalid id, ::TIMER_ERR_NONE else.
1612 */
1613 int cf_timer_destroy(int id) {
1614 int type, code;
1615
1616 cfapiSystem_timer_destroy(&type, id, &code);
1617 assert(type == CFAPI_INT);
1618 return code;
1619 }
1620
1621 /**
1622 * Gets value for specified key, equivalent of object_get_value().
1623 * @param op
1624 * ::object for which we search a key.
1625 * @param keyname
1626 * key to look for. Not required to be a shared string.
1627 * @return
1628 * value (shared string), or NULL if not found.
1629 */
1630 const char *cf_object_get_key(object *op, const char *keyname) {
1631 int type;
1632 const char *value;
1633
1634 cfapiObject_get_key(&type, op, keyname, &value);
1635 assert(type == CFAPI_SSTRING);
1636 return value;
1637 }
1638
1639 /**
1640 * Sets a value for specified key, equivalent to object_set_value().
1641 * @param op
1642 * ::object which will contain the key/value
1643 * @param keyname
1644 * key
1645 * @param value
1646 * value
1647 * @param add_key
1648 * if 0, key is only updated if it exists, else it's updated or added.
1649 * @return
1650 * TRUE or FALSE.
1651 */
1652 int cf_object_set_key(object *op, const char *keyname, const char *value, int add_key) {
1653 int type, ret;
1654
1655 cfapiObject_set_key(&type, op, keyname, value, add_key, &ret);
1656 assert(type == CFAPI_INT);
1657 return ret;
1658 }
1659
1660 /**
1661 * Wrapper for change_abil().
1662 * @copydoc change_abil().
1663 */
1664 int cf_object_change_abil(object *op, object *tmp) {
1665 int type, ret;
1666
1667 cfapiObject_change_abil(&type, op, tmp, &ret);
1668 assert(type == CFAPI_INT);
1669 return ret;
1670 }
1671
1672 /* Archetype-related functions */
1673
1674 /**
1675 * Get first archetype.
1676 * @return
1677 * first archetype in the archetype list.
1678 */
1679 archetype *cf_archetype_get_first(void) {
1680 int type;
1681 archetype *value;
1682
1683 cfapiArchetype_get_property(&type, NULL, CFAPI_ARCH_PROP_NEXT, &value);
1684 assert(type == CFAPI_PARCH);
1685 return value;
1686 }
1687
1688 /**
1689 * Get archetype's name.
1690 * @param arch
1691 * archetype, mustn't be NULL.
1692 * @return
1693 * archetype's name.
1694 */
1695 sstring cf_archetype_get_name(archetype *arch) {
1696 int type;
1697 sstring name;
1698
1699 cfapiArchetype_get_property(&type, arch, CFAPI_ARCH_PROP_NAME, &name);
1700 assert(type == CFAPI_SSTRING);
1701 return name;
1702 }
1703
1704 /**
1705 * Get next archetype in linked list.
1706 * @param arch
1707 * archetype for which we want the next. Can be NULL, in which case it is equivalent
1708 * to calling cf_archetype_get_first().
1709 * @return
1710 * next archetype.
1711 */
1712 archetype *cf_archetype_get_next(archetype *arch) {
1713 int type;
1714 archetype *value;
1715
1716 cfapiArchetype_get_property(&type, arch, CFAPI_ARCH_PROP_NEXT, &value);
1717 assert(type == CFAPI_PARCH);
1718 return value;
1719 }
1720
1721 /**
1722 * Get next part of archetype.
1723 * @param arch
1724 * archetype, mustn't be NULL.
1725 * @return
1726 * archetype's more field.
1727 */
1728 archetype *cf_archetype_get_more(archetype *arch) {
1729 int type;
1730 archetype *value;
1731
1732 cfapiArchetype_get_property(&type, arch, CFAPI_ARCH_PROP_MORE, &value);
1733 assert(type == CFAPI_PARCH);
1734 return value;
1735 }
1736
1737 /**
1738 * Get head of archetype.
1739 * @param arch
1740 * archetype, mustn't be NULL.
1741 * @return
1742 * archetype's head field.
1743 */
1744 archetype *cf_archetype_get_head(archetype *arch) {
1745 int type;
1746 archetype *value;
1747
1748 cfapiArchetype_get_property(&type, arch, CFAPI_ARCH_PROP_HEAD, &value);
1749 assert(type == CFAPI_PARCH);
1750 return value;
1751 }
1752
1753 /**
1754 * Get clone of archetype.
1755 * @param arch
1756 * archetype, mustn't be NULL.
1757 * @return
1758 * archetype's clone. Will never be NULL.
1759 */
1760 object *cf_archetype_get_clone(archetype *arch) {
1761 int type;
1762 object *value;
1763
1764 cfapiArchetype_get_property(&type, arch, CFAPI_ARCH_PROP_CLONE, &value);
1765 assert(type == CFAPI_POBJECT);
1766 return value;
1767 }
1768
1769 /* Party-related functions */
1770
1771 /**
1772 * Get first party.
1773 * @return
1774 * first party in partylist.
1775 */
1776 partylist *cf_party_get_first(void) {
1777 int type;
1778 partylist *value;
1779
1780 cfapiParty_get_property(&type, NULL, CFAPI_PARTY_PROP_NEXT, &value);
1781 assert(type == CFAPI_PPARTY);
1782 return value;
1783 }
1784
1785 /**
1786 * @param party
1787 * party, mustn't be NULL.
1788 * @return
1789 * party's name.
1790 */
1791 const char *cf_party_get_name(partylist *party) {
1792 int type;
1793 sstring value;
1794
1795 cfapiParty_get_property(&type, party, CFAPI_PARTY_PROP_NAME, &value);
1796 assert(type == CFAPI_SSTRING);
1797 return value;
1798 }
1799
1800 /**
1801 * Get next party in party list.
1802 * @param party
1803 * party, can be NULL in which case behaves like cf_party_get_first().
1804 * @return
1805 * party's next field.
1806 */
1807 partylist *cf_party_get_next(partylist *party) {
1808 int type;
1809 partylist *value;
1810
1811 cfapiParty_get_property(&type, party, CFAPI_PARTY_PROP_NEXT, &value);
1812 assert(type == CFAPI_PPARTY);
1813 return value;
1814 }
1815
1816 /**
1817 * Get party's password.
1818 * @param party
1819 * party, mustn't be NULL.
1820 * @return
1821 * party's password field.
1822 */
1823 const char *cf_party_get_password(partylist *party) {
1824 int type;
1825 sstring value;
1826
1827 cfapiParty_get_property(&type, party, CFAPI_PARTY_PROP_PASSWORD, &value);
1828 assert(type == CFAPI_SSTRING);
1829 return value;
1830 }
1831
1832 /**
1833 * Get first player in party.
1834 * @param party
1835 * party, mustn't be NULL.
1836 * @return
1837 * party's first player.
1838 */
1839 player *cf_party_get_first_player(partylist *party) {
1840 int type;
1841 player *value;
1842
1843 cfapiParty_get_property(&type, party, CFAPI_PARTY_PROP_PLAYER, NULL, &value);
1844 assert(type == CFAPI_PPLAYER);
1845 return value;
1846 }
1847
1848 /**
1849 * Get next player in party.
1850 * @param party
1851 * party, mustn't be NULL.
1852 * @param op
1853 * player we want the next of. Can be NULL, in this case behaves like cf_party_get_first_player().
1854 * @return
1855 * party's name.
1856 */
1857 player *cf_party_get_next_player(partylist *party, player *op) {
1858 int type;
1859 player *value;
1860
1861 cfapiParty_get_property(&type, party, CFAPI_PARTY_PROP_PLAYER, op, &value);
1862 assert(type == CFAPI_PPLAYER);
1863 return value;
1864 }
1865
1866 /**
1867 * Get first region in region list.
1868 * @return
1869 * first region.
1870 */
1871 region *cf_region_get_first(void) {
1872 int type;
1873 region *value;
1874
1875 cfapiRegion_get_property(&type, NULL, CFAPI_REGION_PROP_NEXT, &value);
1876 assert(type == CFAPI_PREGION);
1877 return value;
1878 }
1879
1880 /**
1881 * Get name of region.
1882 * @param reg
1883 * region. Mustn't be NULL.
1884 * @return
1885 * region's name.
1886 */
1887 const char *cf_region_get_name(region *reg) {
1888 int type;
1889 sstring value;
1890
1891 cfapiRegion_get_property(&type, reg, CFAPI_REGION_PROP_NAME, &value);
1892 assert(type == CFAPI_SSTRING);
1893 return value;
1894 }
1895
1896 /**
1897 * Get next region in region list.
1898 * @param reg
1899 * region. Can be NULL in which case equivalent of cf_region_get_first().
1900 * @return
1901 * next region.
1902 */
1903 region *cf_region_get_next(region *reg) {
1904 int type;
1905 region *value;
1906
1907 cfapiRegion_get_property(&type, reg, CFAPI_REGION_PROP_NEXT, &value);
1908 assert(type == CFAPI_PREGION);
1909 return value;
1910 }
1911
1912 /**
1913 * Get parent of region.
1914 * @param reg
1915 * region. Mustn't be NULL.
1916 * @return
1917 * region's parent.
1918 */
1919 region *cf_region_get_parent(region *reg) {
1920 int type;
1921 region *value;
1922
1923 cfapiRegion_get_property(&type, reg, CFAPI_REGION_PROP_PARENT, &value);
1924 assert(type == CFAPI_PREGION);
1925 return value;
1926 }
1927
1928 /**
1929 * Get longname of region.
1930 * @param reg
1931 * region. Mustn't be NULL.
1932 * @return
1933 * region's longname.
1934 */
1935 const char *cf_region_get_longname(region *reg) {
1936 int type;
1937 sstring value;
1938
1939 cfapiRegion_get_property(&type, reg, CFAPI_REGION_PROP_LONGNAME, &value);
1940 assert(type == CFAPI_SSTRING);
1941 return value;
1942 }
1943
1944 /**
1945 * Get message of region.
1946 * @param reg
1947 * region. Mustn't be NULL.
1948 * @return
1949 * region's message.
1950 */
1951 const char *cf_region_get_message(region *reg) {
1952 int type;
1953 sstring value;
1954
1955 cfapiRegion_get_property(&type, reg, CFAPI_REGION_PROP_MESSAGE, &value);
1956 assert(type == CFAPI_SSTRING);
1957 return value;
1958 }
1959
1960 /**
1961 * Get region's jail x coordinate.
1962 * @param reg
1963 * region. Mustn't be NULL.
1964 * @return
1965 * region's x coordinate for jail.
1966 */
1967 int cf_region_get_jail_x(region *reg) {
1968 int type, value;
1969
1970 cfapiRegion_get_property(&type, reg, CFAPI_REGION_PROP_JAIL_X, &value);
1971 assert(type == CFAPI_INT);
1972 return value;
1973 }
1974
1975 /**
1976 * Get region's jail y coordinate.
1977 * @param reg
1978 * region. Mustn't be NULL.
1979 * @return
1980 * region's y coordinate for jail.
1981 */
1982 int cf_region_get_jail_y(region *reg) {
1983 int type, value;
1984
1985 cfapiRegion_get_property(&type, reg, CFAPI_REGION_PROP_JAIL_Y, &value);
1986 assert(type == CFAPI_INT);
1987 return value;
1988 }
1989
1990 /**
1991 * Get jail path of region.
1992 * @param reg
1993 * region. Mustn't be NULL.
1994 * @return
1995 * region's jail path, can be NULL.
1996 */
1997 const char *cf_region_get_jail_path(region *reg) {
1998 int type;
1999 sstring value;
2000
2001 cfapiRegion_get_property(&type, reg, CFAPI_REGION_PROP_JAIL_PATH, &value);
2002 assert(type == CFAPI_SSTRING);
2003 return value;
2004 }
2005
2006 /* Friendlylist functions. */
2007
2008 /**
2009 * Get first object on friendly list.
2010 * @return
2011 * first object on friendly list.
2012 */
2013 object *cf_friendlylist_get_first(void) {
2014 int type;
2015 object *value;
2016
2017 cfapiFriendlylist_get_next(&type, NULL, &value);
2018 assert(type == CFAPI_POBJECT);
2019 return value;
2020 }
2021
2022 /**
2023 * Get next object on friendly list.
2024 * @param ob
2025 * object we want the next of. If NULL then equivalent of cf_friendlylist_get_first().
2026 * @return
2027 * next object.
2028 */
2029 object *cf_friendlylist_get_next(object *ob) {
2030 int type;
2031 object *value;
2032
2033 cfapiFriendlylist_get_next(&type, ob, &value);
2034 assert(type == CFAPI_POBJECT);
2035 return value;
2036 }
2037
2038 /* Quest-related functions */
2039
2040 /**
2041 * Wrapper for quest_get_player_state().
2042 * @copydoc quest_get_player_state()
2043 */
2044 int cf_quest_get_player_state(object *pl, sstring quest_code) {
2045 int type, ret;
2046
2047 cfapiPlayer_quest(&type, CFAPI_PLAYER_QUEST_GET_STATE, pl, quest_code, &ret);
2048 assert(type == CFAPI_INT);
2049
2050 return ret;
2051 }
2052
2053 /**
2054 * Wrapper for quest_start().
2055 * @copydoc quest_start()
2056 */
2057 void cf_quest_start(object *pl, sstring quest_code, int state) {
2058 int type;
2059
2060 cfapiPlayer_quest(&type, CFAPI_PLAYER_QUEST_START, pl, quest_code, state);
2061 assert(type == CFAPI_NONE);
2062 }
2063
2064 /**
2065 * Wrapper for quest_set_player_state();
2066 * @copydoc quest_set_player_state()
2067 */
2068 void cf_quest_set_player_state(object *pl, sstring quest_code, int state) {
2069 int type;
2070
2071 cfapiPlayer_quest(&type, CFAPI_PLAYER_QUEST_SET_STATE, pl, quest_code, state);
2072 assert(type == CFAPI_NONE);
2073 }
2074
2075 /**
2076 * Wrapper for quest_was_completed().
2077 * @copydoc quest_was_completed()
2078 */
2079 int cf_quest_was_completed(object *pl, sstring quest_code) {
2080 int type, ret;
2081
2082 cfapiPlayer_quest(&type, CFAPI_PLAYER_QUEST_WAS_COMPLETED, pl, quest_code, &ret);
2083 assert(type == CFAPI_INT);
2084
2085 return ret;
2086 }