ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/plugins/cfperl/cfperl.xs
(Generate patch)

Comparing deliantra/server/plugins/cfperl/cfperl.xs (file contents):
Revision 1.42 by root, Tue Mar 28 16:48:12 2006 UTC vs.
Revision 1.59 by elmex, Sat Jul 15 11:57:02 2006 UTC

1/*****************************************************************************/ 1/*****************************************************************************/
2/* CrossFire, A Multiplayer game for the X Window System */ 2/* CrossFire, A Multiplayer game for the X Window System */
3/* */
4/*****************************************************************************/ 3/*****************************************************************************/
5 4
6/* 5/*
7 * This code is placed under the GNU General Public Licence (GPL) 6 * This code is placed under the GNU General Public Licence (GPL)
8 * 7 *
29#include <XSUB.h> 28#include <XSUB.h>
30 29
31#undef save_long // clashes with libproto.h 30#undef save_long // clashes with libproto.h
32 31
33#define PLUGIN_NAME "perl" 32#define PLUGIN_NAME "perl"
34#define PLUGIN_VERSION "cfperl 0.2" 33#define PLUGIN_VERSION "cfperl 0.3"
35 34
36#ifndef __CEXTRACT__ 35#ifndef __CEXTRACT__
37#include <plugin.h> 36#include <plugin.h>
38#endif 37#endif
39 38
46#include <plugin_common.h> 45#include <plugin_common.h>
47#include <sounds.h> 46#include <sounds.h>
48 47
49#include <stdarg.h> 48#include <stdarg.h>
50 49
50//#include "EventAPI.h"
51#include "perlxsi.c" 51#include "perlxsi.c"
52
53extern sint64 *levels; // the experience table
52 54
53typedef object object_ornull; 55typedef object object_ornull;
54typedef mapstruct mapstruct_ornull; 56typedef mapstruct mapstruct_ornull;
55 57
56static f_plug_api gethook; 58static f_plug_api gethook;
65typedef struct 67typedef struct
66{ 68{
67 object* who; 69 object* who;
68 object* activator; 70 object* activator;
69 object* third; 71 object* third;
72 object* event;
70 mapstruct* map; 73 mapstruct* map;
71 char message[1024]; 74 char message[1024];
72 int fix; // seems to be python-only, and should not be part of the API 75 int fix; // seems to be python-only, and should not be part of the API
73 int event_code; 76 int event_code;
74 char extension[1024]; // name field, should invoke specific perl extension 77 char extension[1024]; // name field, should invoke specific perl extension
77} CFPContext; 80} CFPContext;
78 81
79static HV *obj_cache; 82static HV *obj_cache;
80static PerlInterpreter *perl; 83static PerlInterpreter *perl;
81 84
85#define PUSHcfapi(type,value) PUSHs (sv_2mortal (newSVcfapi (CFAPI_ ## type, (value))))
82#define PUSHcfapi(type,ctype) PUSHs (sv_2mortal (newSVcfapi ((type), va_arg (args, ctype)))) 86#define PUSHcfapi_va(type,ctype) PUSHcfapi (type, va_arg (args, ctype))
83#define PUSH_OB PUSHcfapi(CFAPI_POBJECT, object *) 87#define PUSH_OB PUSHcfapi_va(POBJECT, object *)
84#define PUSH_PL PUSHcfapi(CFAPI_PPLAYER, player *) 88#define PUSH_PL PUSHcfapi_va(PPLAYER, player *)
85#define PUSH_MAP PUSHcfapi(CFAPI_PMAP, mapstruct *) 89#define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *)
86#define PUSH_PV PUSHcfapi(CFAPI_STRING, const char *) 90#define PUSH_PV PUSHcfapi_va(STRING, const char *)
87#define PUSH_IV PUSHcfapi(CFAPI_INT, int) 91#define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int))))
92
93extern void pay_player(object *op, uint64 amount);
94extern uint64 pay_player_arch(object *op, const char *arch, uint64 amount);
88 95
89////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 96//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90 97
91// garbage collect some perl objects, if possible 98// garbage collect some perl objects, if possible
92// all objects no longer referenced and empty are 99// all objects no longer referenced and empty are
228 case CFAPI_LONG: 235 case CFAPI_LONG:
229 sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */ 236 sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */
230 break; 237 break;
231 238
232 case CFAPI_DOUBLE: 239 case CFAPI_DOUBLE:
233 sv = newSViv (*va_arg (args, double *)); 240 sv = newSVnv (*va_arg (args, double *));
234 break; 241 break;
235 242
236 case CFAPI_STRING: 243 case CFAPI_STRING:
237 { 244 {
238 char *str = va_arg (args, char *); 245 char *str = va_arg (args, char *);
245 object *obj = va_arg (args, object *); 252 object *obj = va_arg (args, object *);
246 253
247 if (!obj) 254 if (!obj)
248 sv = &PL_sv_undef; 255 sv = &PL_sv_undef;
249 else 256 else
250 switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) 257 switch (obj->type)
251 { 258 {
252 case MAP: 259 case MAP:
253 sv = newSVptr_cached (obj, "cf::object::map"); 260 sv = newSVptr_cached (obj, "cf::object::map");
254 break; 261 break;
255 262
291 va_end (args); 298 va_end (args);
292 299
293 return sv; 300 return sv;
294} 301}
295 302
296/////////////////////////////////////////////////////////////////////////////
297
298void
299inject_event (const char *func, CFPContext *context)
300{
301 dSP;
302
303 ENTER;
304 SAVETMPS;
305
306 PUSHMARK (SP);
307
308 EXTEND (SP, 10);
309
310 HV *hv = newHV ();
311#define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0)
312 hv_context (CFAPI_POBJECT, ,who);
313 hv_context (CFAPI_POBJECT, ,activator);
314 hv_context (CFAPI_POBJECT, ,third);
315 hv_context (CFAPI_PMAP, ,map);
316 hv_context (CFAPI_STRING , ,message);
317 hv_context (CFAPI_INT ,&,fix);
318 hv_context (CFAPI_INT ,&,event_code);
319 hv_context (CFAPI_STRING , ,options);
320 hv_context (CFAPI_STRING , ,extension);
321
322 PUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
323
324 PUTBACK;
325 int count = call_pv (func, G_SCALAR | G_EVAL);
326 SPAGAIN;
327
328 if (SvTRUE (ERRSV))
329 LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV));
330
331 context->returnvalue = count > 0 ? POPi : 0;
332
333 PUTBACK;
334 FREETMPS;
335 LEAVE;
336}
337
338///////////////////////////////////////////////////////////////////////////// 303/////////////////////////////////////////////////////////////////////////////
339 304
340int 305int
341initPlugin (const char *iversion, f_plug_api gethooksptr) 306initPlugin (const char *iversion, f_plug_api gethooksptr)
342{ 307{
449 414
450 /* Pick the global events you want to monitor from this plugin */ 415 /* Pick the global events you want to monitor from this plugin */
451 registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); 416 registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener);
452 registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener); 417 registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener);
453 //registerGlobalEvent (NULL, EVENT_CRASH, PLUGIN_NAME, globalEventListener); 418 //registerGlobalEvent (NULL, EVENT_CRASH, PLUGIN_NAME, globalEventListener);
419 registerGlobalEvent (NULL, EVENT_FIND_UNARMED_SKILL, PLUGIN_NAME, globalEventListener);
420 registerGlobalEvent (NULL, EVENT_PLAYER_USE_SKILL, PLUGIN_NAME, globalEventListener);
421 registerGlobalEvent (NULL, EVENT_MONSTER_USE_SKILL, PLUGIN_NAME, globalEventListener);
454 registerGlobalEvent (NULL, EVENT_PLAYER_DEATH, PLUGIN_NAME, globalEventListener); 422 registerGlobalEvent (NULL, EVENT_PLAYER_DEATH, PLUGIN_NAME, globalEventListener);
455 registerGlobalEvent (NULL, EVENT_GKILL, PLUGIN_NAME, globalEventListener); 423 registerGlobalEvent (NULL, EVENT_GKILL, PLUGIN_NAME, globalEventListener);
456 registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener); 424 registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener);
457 registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener); 425 registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener);
458 registerGlobalEvent (NULL, EVENT_MAPENTER, PLUGIN_NAME, globalEventListener); 426 registerGlobalEvent (NULL, EVENT_MAPENTER, PLUGIN_NAME, globalEventListener);
468 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); 436 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener);
469 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); 437 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener);
470 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); 438 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener);
471 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); 439 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener);
472 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); 440 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener);
441 registerGlobalEvent (NULL, EVENT_EXTCMD, PLUGIN_NAME, globalEventListener);
473 442
474 char *argv[] = { 443 char *argv[] = {
475 "", 444 "",
476 "-e" 445 "-e"
477 "BEGIN {" 446 "BEGIN {"
483 }; 452 };
484 453
485 perl = perl_alloc (); 454 perl = perl_alloc ();
486 perl_construct (perl); 455 perl_construct (perl);
487 456
457 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
458
488 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 459 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
489 { 460 {
490 printf ("unable to initialize perl-interpreter, continuing without.\n"); 461 printf ("unable to initialize perl-interpreter, continuing without.\n");
491 462
492 perl_destruct (perl); 463 perl_destruct (perl);
526 if (sv) 497 if (sv)
527 clearSVptr (sv); 498 clearSVptr (sv);
528 499
529 rv = 0; 500 rv = 0;
530 } 501 }
502 else if (event_code == EVENT_CLOCK)
503 {
504 dSP;
505 int i, count;
506
507 clean_obj_cache ();
508
509 ENTER;
510 SAVETMPS;
511
512 // service up to 8 events per tick better would be
513 // to check for elapsed time and stop processing after
514 // 0.25 * server_tick or so
515 for (i = 9; --i; )
516 {
517 PUSHMARK (SP);
518 XPUSHs (sv_2mortal (newSViv (0)));
519 PUTBACK;
520 count = call_pv ("Event::one_event", G_SCALAR | G_EVAL);
521 SPAGAIN;
522
523 if (!count || !POPi)
524 break;
525 }
526
527 FREETMPS;
528 LEAVE;
529 }
531 else 530 else
532 { 531 {
533 dSP; 532 dSP;
534 533
535 ENTER; 534 ENTER;
583 case EVENT_KICK: 582 case EVENT_KICK:
584 PUSH_OB; 583 PUSH_OB;
585 PUSH_PV; 584 PUSH_PV;
586 break; 585 break;
587 586
587 case EVENT_FIND_UNARMED_SKILL:
588 PUSH_OB;
589 break;
590
591 case EVENT_PLAYER_USE_SKILL:
592 case EVENT_MONSTER_USE_SKILL:
593 PUSH_OB;
594 PUSH_OB;
595 PUSH_OB;
596 PUSH_IV;
597 PUSH_PV;
598 break;
599
588 case EVENT_CLOCK: 600 case EVENT_EXTCMD:
589 clean_obj_cache (); 601 PUSH_PL;
602 {
603 char *buf = va_arg (args, char *);
604 int len = va_arg (args, int);
605 PUSHs (sv_2mortal (newSVpvn (buf, len)));
606 }
590 break; 607 break;
591 608
592 case EVENT_TELL: 609 case EVENT_TELL:
593 break; 610 break;
594 } 611 }
598 PUTBACK; 615 PUTBACK;
599 int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL); 616 int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL);
600 SPAGAIN; 617 SPAGAIN;
601 618
602 if (SvTRUE (ERRSV)) 619 if (SvTRUE (ERRSV))
603 LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); 620 LOG (llevError, "global event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV));
604 621
605 rv = count > 0 ? POPi : 0; 622 rv = count > 0 ? POPi : 0;
606 623
607 PUTBACK; 624 PUTBACK;
608 FREETMPS; 625 FREETMPS;
613} 630}
614 631
615void * 632void *
616eventListener (int *type, ...) 633eventListener (int *type, ...)
617{ 634{
618 static int rv = 0; 635 static int rv;
619 va_list args; 636 va_list args;
620 char *buf; 637 int event_code;
621 CFPContext context; 638 object *who, *activator, *third, *event;
622 object *eob; 639 char *message, *extension, *options;
623 640
624 if (!perl) 641 if (!perl)
625 return; 642 return;
626 643
627 memset (&context, 0, sizeof (context));
628
629 va_start (args, type); 644 va_start (args, type);
630
631 context.who = va_arg (args, object *); 645 who = va_arg (args, object *);
632 context.event_code = va_arg (args, int); 646 event_code = va_arg (args, int);
633 context.activator = va_arg (args, object *); 647 activator = va_arg (args, object *);
634 context.third = va_arg (args, object *); 648 third = va_arg (args, object *);
635
636 buf = va_arg (args, char *); 649 message = va_arg (args, char *);
637 if (buf != 0) 650 va_arg (args, int); // fix yourself
638 strncpy (context.message, buf, sizeof (context.message)); 651 extension = va_arg (args, char *);
639 652 options = va_arg (args, char *);
640 context.fix = va_arg (args, int);
641 strncpy (context.extension, va_arg (args, char *), sizeof (context.extension));
642 strncpy (context.options, va_arg (args, char *), sizeof (context.options));
643 eob = va_arg (args, object *); 653 event = va_arg (args, object *);
644 context.returnvalue = 0;
645 va_end (args); 654 va_end (args);
646 655
647 inject_event ("cf::inject_event", &context); 656 {
657 dSP;
658
659 ENTER;
660 SAVETMPS;
661
662 PUSHMARK (SP);
663 EXTEND (SP, 10);
664
665 PUSHcfapi (STRING, extension);
666 PUSHs (sv_2mortal (newSViv (event_code)));
667
668 PUSHcfapi (POBJECT, event);
669 PUSHcfapi (POBJECT, who);
670
671 switch (event_code)
672 {
673 case EVENT_STOP: // $ob (e.g. arrow)
674 case EVENT_TIME: // $ob
675 case EVENT_TIMER: // $ob
676 break;
677
678 case EVENT_APPLY: // $ob, $who
679 case EVENT_DROP: // $ob, $who
680 case EVENT_CLOSE: // $ob, $who
681 case EVENT_DEATH: // $ob[, $killer]
682 case EVENT_MOVE: // $ob, $enemy
683 case EVENT_THROW: // $ob, $thrower
684 PUSHcfapi (POBJECT, activator);
685 break;
686
687 case EVENT_ATTACK: // $ob, $who, $victim (?? please god enlighten me)
688 PUSHcfapi (POBJECT, activator);
689 PUSHcfapi (POBJECT, third);
690 break;
691
692 case EVENT_TRIGGER: // $ob, $originator, [$victim], [$msg]
693 PUSHcfapi (POBJECT, activator);
694 PUSHcfapi (POBJECT, third);
695 PUSHcfapi (POBJECT, message);
696 break;
697
698 case EVENT_SAY: // $ob, $who, $msg
699 PUSHcfapi (POBJECT, activator);
700 PUSHcfapi (STRING, message);
701 break;
702
703 default:
704 LOG (llevError, "perl plugin called for unsupported event type %d", event_code);
705 break;
706 }
707
708 PUTBACK;
709 int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL);
710 SPAGAIN;
711
712 if (SvTRUE (ERRSV))
713 LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV));
714
715 rv = count > 0 ? POPi : 0;
716
717 PUTBACK;
718 FREETMPS;
719 LEAVE;
720 }
648 721
649 rv = context.returnvalue;
650 return &rv; 722 return &rv;
651} 723}
652 724
653int 725int
654closePlugin () 726closePlugin ()
1074 const_iv (SK_SUMMONING) 1146 const_iv (SK_SUMMONING)
1075 const_iv (SK_PYROMANCY) 1147 const_iv (SK_PYROMANCY)
1076 const_iv (SK_EVOCATION) 1148 const_iv (SK_EVOCATION)
1077 const_iv (SK_SORCERY) 1149 const_iv (SK_SORCERY)
1078 const_iv (SK_TWO_HANDED_WEAPON) 1150 const_iv (SK_TWO_HANDED_WEAPON)
1151 const_iv (SK_SPARK_TOUCH)
1152 const_iv (SK_SHIVER)
1153 const_iv (SK_ACID_SPLASH)
1154 const_iv (SK_POISON_NAIL)
1079 1155
1080 const_iv (SOUND_NEW_PLAYER) 1156 const_iv (SOUND_NEW_PLAYER)
1081 const_iv (SOUND_FIRE_ARROW) 1157 const_iv (SOUND_FIRE_ARROW)
1082 const_iv (SOUND_LEARN_SPELL) 1158 const_iv (SOUND_LEARN_SPELL)
1083 const_iv (SOUND_FUMBLE_SPELL) 1159 const_iv (SOUND_FUMBLE_SPELL)
1099 const_iv (SOUND_CLOCK) 1175 const_iv (SOUND_CLOCK)
1100 const_iv (SOUND_TURN_HANDLE) 1176 const_iv (SOUND_TURN_HANDLE)
1101 const_iv (SOUND_FALL_HOLE) 1177 const_iv (SOUND_FALL_HOLE)
1102 const_iv (SOUND_DRINK_POISON) 1178 const_iv (SOUND_DRINK_POISON)
1103 const_iv (SOUND_CAST_SPELL_0) 1179 const_iv (SOUND_CAST_SPELL_0)
1180
1181 const_iv (PREFER_LOW)
1182 const_iv (PREFER_HIGH)
1183
1184 const_iv (ATNR_PHYSICAL)
1185 const_iv (ATNR_MAGIC)
1186 const_iv (ATNR_FIRE)
1187 const_iv (ATNR_ELECTRICITY)
1188 const_iv (ATNR_COLD)
1189 const_iv (ATNR_CONFUSION)
1190 const_iv (ATNR_ACID)
1191 const_iv (ATNR_DRAIN)
1192 const_iv (ATNR_WEAPONMAGIC)
1193 const_iv (ATNR_GHOSTHIT)
1194 const_iv (ATNR_POISON)
1195 const_iv (ATNR_SLOW)
1196 const_iv (ATNR_PARALYZE)
1197 const_iv (ATNR_TURN_UNDEAD)
1198 const_iv (ATNR_FEAR)
1199 const_iv (ATNR_CANCELLATION)
1200 const_iv (ATNR_DEPLETE)
1201 const_iv (ATNR_DEATH)
1202 const_iv (ATNR_CHAOS)
1203 const_iv (ATNR_COUNTERSPELL)
1204 const_iv (ATNR_GODPOWER)
1205 const_iv (ATNR_HOLYWORD)
1206 const_iv (ATNR_BLIND)
1207 const_iv (ATNR_INTERNAL)
1208 const_iv (ATNR_LIFE_STEALING)
1209 const_iv (ATNR_DISEASE)
1210
1211 const_iv (MAP_FLUSH)
1212 const_iv (MAP_PLAYER_UNIQUE)
1213 const_iv (MAP_BLOCK)
1214 const_iv (MAP_STYLE)
1215 const_iv (MAP_OVERLAY)
1216
1217 const_iv (MAP_IN_MEMORY)
1218 const_iv (MAP_SWAPPED)
1219 const_iv (MAP_LOADING)
1220 const_iv (MAP_SAVING)
1104 }; 1221 };
1105 1222
1106 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1223 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1107 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1224 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1108 1225
1125 const_event (CLOSE) 1242 const_event (CLOSE)
1126 const_event (TIMER) 1243 const_event (TIMER)
1127 const_event (MOVE) 1244 const_event (MOVE)
1128 1245
1129 const_event (BORN) 1246 const_event (BORN)
1130 const_event (CLOCK) 1247 //const_event (CLOCK)
1131 const_event (CRASH) 1248 const_event (CRASH)
1132 const_event (PLAYER_DEATH) 1249 const_event (PLAYER_DEATH)
1133 const_event (PLAYER_LOAD) 1250 const_event (PLAYER_LOAD)
1134 const_event (PLAYER_SAVE) 1251 const_event (PLAYER_SAVE)
1135 const_event (GKILL) 1252 const_event (GKILL)
1145 const_event (REMOVE) 1262 const_event (REMOVE)
1146 const_event (SHOUT) 1263 const_event (SHOUT)
1147 const_event (TELL) 1264 const_event (TELL)
1148 const_event (MUZZLE) 1265 const_event (MUZZLE)
1149 const_event (KICK) 1266 const_event (KICK)
1267 const_event (PLAYER_USE_SKILL)
1268 const_event (MONSTER_USE_SKILL)
1269 const_event (FIND_UNARMED_SKILL)
1270 const_event (EXTCMD)
1150 //const_event (FREE_OB) 1271 //const_event (FREE_OB)
1151 }; 1272 };
1152 1273
1153 AV *av = get_av ("cf::EVENT", 1); 1274 AV *av = get_av ("cf::EVENT", 1);
1154 1275
1288 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) 1409 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; )
1289 { 1410 {
1290 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); 1411 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0);
1291 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); 1412 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0);
1292 } 1413 }
1414
1415 //I_EVENT_API (PACKAGE);
1293} 1416}
1294 1417
1295void 1418void
1296LOG (int level, char *msg) 1419LOG (int level, char *msg)
1297 PROTOTYPE: $$ 1420 PROTOTYPE: $$
1298 C_ARGS: level, "%s", msg 1421 C_ARGS: level, "%s", msg
1422
1423char *path_combine (char *base, char *path)
1424 PROTOTYPE: $$
1425
1426char *path_combine_and_normalize (char *base, char *path)
1427 PROTOTYPE: $$
1299 1428
1300char * 1429char *
1301cf_get_maps_directory (char *path) 1430cf_get_maps_directory (char *path)
1302 PROTOTYPE: $ 1431 PROTOTYPE: $
1303 ALIAS: maps_directory = 0 1432 ALIAS: maps_directory = 0
1321 OUTPUT: RETVAL 1450 OUTPUT: RETVAL
1322 1451
1323int 1452int
1324cf_find_animation (char *text) 1453cf_find_animation (char *text)
1325 PROTOTYPE: $ 1454 PROTOTYPE: $
1455
1456int random_roll(int min, int max, object *op, int goodbad);
1457
1458int
1459exp_to_level (double exp)
1460 CODE:
1461 int i = 0;
1462 RETVAL = 0;
1463 for (i = 1; i <= settings.max_level; i++)
1464 {
1465 if (levels[i] > exp)
1466 {
1467 RETVAL = i - 1;
1468 break;
1469 }
1470 }
1471 OUTPUT: RETVAL
1472
1473double
1474level_to_min_exp (int level)
1475 CODE:
1476 RETVAL = 0;
1477 if (level > settings.max_level)
1478 RETVAL = levels[settings.max_level];
1479 else if (level < 1)
1480 RETVAL = 0;
1481 else
1482 RETVAL = levels[level];
1483 OUTPUT: RETVAL
1484
1485SV *
1486resistance_to_string (int atnr)
1487 CODE:
1488 if (atnr >= 0 && atnr < NROFATTACKS)
1489 {
1490 RETVAL = newSVpv (resist_plus[atnr], 0);
1491 }
1492 else
1493 {
1494 XSRETURN_UNDEF;
1495 }
1496 OUTPUT: RETVAL
1326 1497
1327MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1498MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1328 1499
1329SV * 1500SV *
1330get_property (object *obj, int type, int idx) 1501get_property (object *obj, int type, int idx)
1472 1643
1473void cf_object_update (object *op, int flags) 1644void cf_object_update (object *op, int flags)
1474 1645
1475void cf_object_pickup (object *op, object *what) 1646void cf_object_pickup (object *op, object *what)
1476 1647
1648object *cf_create_object_by_name (const char *name)
1649
1650void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0)
1651
1652void pay_player (object *op, double amount)
1653
1654double pay_player_arch (object *op, const char *arch, double amount)
1655
1656void player_lvl_adj (object *who, object *skill = 0)
1657
1658int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1659
1660int calc_skill_exp (object *who, object *op, object *skill);
1661
1477char *cf_object_get_key (object *op, char *keyname) 1662char *cf_object_get_key (object *op, char *keyname)
1478 ALIAS: key = 0 1663 ALIAS: key = 0
1479 1664
1480void cf_object_set_key (object *op, char *keyname, char *value) 1665void cf_object_set_key (object *op, char *keyname, char *value)
1481 1666
1482object *cf_create_object_by_name (const char *name) 1667void
1483 1668cf_object_set_resistance (object *op, int rtype, int val)
1484void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) 1669 CODE:
1485 1670 if (rtype >= 0 && rtype < NROFATTACKS)
1486void player_lvl_adj (object *who, object *skill = 0) 1671 op->resist[rtype] = val;
1487 1672
1488 1673
1489MODULE = cf PACKAGE = cf::object PREFIX = cf_ 1674MODULE = cf PACKAGE = cf::object PREFIX = cf_
1490 1675
1491void cf_fix_object (object *pl) 1676void cf_fix_object (object *pl)
1508 CODE: 1693 CODE:
1509{ 1694{
1510 int unused_type; 1695 int unused_type;
1511 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 1696 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
1512} 1697}
1698
1699# syntatic sugar for easier use in event callbacks.
1700const char *options (object *op)
1701 CODE:
1702 RETVAL = op->name;
1703 OUTPUT:
1704 RETVAL
1513 1705
1514const char *get_ob_key_value (object *op, const char *key) 1706const char *get_ob_key_value (object *op, const char *key)
1515 1707
1516bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) 1708bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1)
1517 1709
1554 1746
1555MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 1747MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
1556 1748
1557player *player (object *op) 1749player *player (object *op)
1558 CODE: 1750 CODE:
1559 RETVAL = cf_player_find (cf_query_name (op)); 1751 RETVAL = op->contr;
1560 OUTPUT: RETVAL 1752 OUTPUT: RETVAL
1561 1753
1562void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) 1754void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1563 1755
1564object *cf_player_send_inventory (object *op) 1756object *cf_player_send_inventory (object *op)
1581 1773
1582void cf_player_set_party (object *op, partylist *party) 1774void cf_player_set_party (object *op, partylist *party)
1583 1775
1584void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) 1776void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0)
1585 1777
1778void kill_player (object *op)
1779
1586MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ 1780MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1587 1781
1588MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 1782MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1589 1783
1590player *cf_player_find (char *name) 1784player *cf_player_find (char *name)
1609 1803
1610player *next (player *pl) 1804player *next (player *pl)
1611 CODE: 1805 CODE:
1612 RETVAL = pl->next; 1806 RETVAL = pl->next;
1613 OUTPUT: RETVAL 1807 OUTPUT: RETVAL
1808
1809bool
1810cell_visible (player *pl, int dx, int dy)
1811 CODE:
1812 RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2
1813 && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2];
1814 OUTPUT:
1815 RETVAL
1816
1817void
1818send (player *pl, SV *packet)
1819 CODE:
1820{
1821 STRLEN len;
1822 char *buf = SvPVbyte (packet, len);
1823
1824 Write_String_To_Socket (&pl->socket, buf, len);
1825}
1826
1827int
1828listening (player *pl, int new_value = -1)
1829 CODE:
1830 RETVAL = pl->listening;
1831 if (new_value >= 0)
1832 pl->listening = new_value;
1833 OUTPUT:
1834 RETVAL
1614 1835
1615void get_savebed (player *pl) 1836void get_savebed (player *pl)
1616 ALIAS: 1837 ALIAS:
1617 savebed = 0 1838 savebed = 0
1618 PPCODE: 1839 PPCODE:
1634 player *pl; 1855 player *pl;
1635 for (pl = first_player; pl; pl = pl->next) 1856 for (pl = first_player; pl; pl = pl->next)
1636 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); 1857 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl));
1637} 1858}
1638 1859
1860bool
1861peaceful (player *pl, bool new_setting = 0)
1862 PROTOTYPE: $;$
1863 CODE:
1864 RETVAL = pl->peaceful;
1865 if (items > 1)
1866 pl->peaceful = new_setting;
1867 OUTPUT:
1868 RETVAL
1869
1639living * 1870living *
1640orig_stats (player *pl) 1871orig_stats (player *pl)
1641 CODE: 1872 CODE:
1642 RETVAL = &pl->orig_stats; 1873 RETVAL = &pl->orig_stats;
1643 OUTPUT: RETVAL 1874 OUTPUT: RETVAL
1683 1914
1684void clean_tmp_map (mapstruct *map) 1915void clean_tmp_map (mapstruct *map)
1685 1916
1686void play_sound_map (mapstruct *map, int x, int y, int sound_num) 1917void play_sound_map (mapstruct *map, int x, int y, int sound_num)
1687 1918
1919mapstruct *tile_map (mapstruct *map, unsigned int dir)
1920 CODE:
1921 RETVAL = dir < 4 ? map->tile_map [dir] : 0;
1922 OUTPUT:
1923 RETVAL
1924
1925char *tile_path (mapstruct *map, unsigned int dir)
1926 CODE:
1927 if (dir >= 4)
1928 XSRETURN_UNDEF;
1929 RETVAL = map->tile_path [dir];
1930 OUTPUT:
1931 RETVAL
1932
1688mapstruct *cf_map_get_map (char *name) 1933mapstruct *cf_map_get_map (char *name)
1689 PROTOTYPE: $ 1934 PROTOTYPE: $
1690 ALIAS: map = 0 1935 ALIAS: map = 0
1691 1936
1937mapstruct *has_been_loaded (char *name)
1938 PROTOTYPE: $
1939
1692mapstruct *cf_map_get_first () 1940mapstruct *cf_map_get_first ()
1693 PROTOTYPE: 1941 PROTOTYPE:
1694 ALIAS: first = 0 1942 ALIAS: first = 0
1695 1943
1696# whoever "designed" the plug-in api should have wasted 1944# whoever "designed" the plug-in api should have wasted
1697# his/her time with staying away form the project - would have 1945# his/her time with staying away from the project - would have
1698# saved others a lot of time, without doubt. 1946# saved others a lot of time, without doubt.
1699void set_path (mapstruct *where, char *path) 1947void set_path (mapstruct *where, char *path)
1700 CODE: 1948 CODE:
1701 strcpy (where->path, path); 1949 strcpy (where->path, path);
1950
1951int in_memory (mapstruct *map)
1952 CODE:
1953 RETVAL = map->in_memory;
1954 OUTPUT:
1955 RETVAL
1702 1956
1703bool unique (mapstruct *map) 1957bool unique (mapstruct *map)
1704 CODE: 1958 CODE:
1705 RETVAL = map->unique; 1959 RETVAL = map->unique;
1706 OUTPUT: 1960 OUTPUT:
1715object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) 1969object *cf_map_insert_object (mapstruct *where, object* op, int x, int y)
1716 1970
1717object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) 1971object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny)
1718 C_ARGS: str, map, nx, ny 1972 C_ARGS: str, map, nx, ny
1719 1973
1720#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1721
1722void 1974void
1975cf_map_normalise (mapstruct *map, int x, int y)
1976 PPCODE:
1977{
1978 mapstruct *nmap = 0;
1979 I16 nx = 0, ny = 0;
1980 int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1981
1982 EXTEND (SP, 4);
1983 PUSHs (sv_2mortal (newSViv (flags)));
1984
1985 if (GIMME_V == G_ARRAY)
1986 {
1987 PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap)));
1988 PUSHs (sv_2mortal (newSViv (nx)));
1989 PUSHs (sv_2mortal (newSViv (ny)));
1990 }
1991}
1992
1993void
1723at (mapstruct *obj, unsigned int x, unsigned int y) 1994at (mapstruct *map, unsigned int x, unsigned int y)
1724 PROTOTYPE: $$$ 1995 PROTOTYPE: $$$
1725 INIT:
1726 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY;
1727 PPCODE: 1996 PPCODE:
1728{ 1997{
1729 object *o; 1998 object *o;
1730 1999 mapstruct *nmap = 0;
2000 I16 nx, ny;
2001
2002 cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
2003
2004 if (nmap)
1731 for (o = GET_MAP_OB (obj, x, y); o; o = o->above) 2005 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
1732 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 2006 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1733} 2007}
1734 2008
1735SV * 2009SV *
1736bot_at (mapstruct *obj, unsigned int x, unsigned int y) 2010bot_at (mapstruct *obj, unsigned int x, unsigned int y)
1737 PROTOTYPE: $$$ 2011 PROTOTYPE: $$$

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines