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.58 by elmex, Tue Jul 11 16:50:16 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 52
53typedef object object_ornull; 53typedef object object_ornull;
54typedef mapstruct mapstruct_ornull; 54typedef mapstruct mapstruct_ornull;
55 55
65typedef struct 65typedef struct
66{ 66{
67 object* who; 67 object* who;
68 object* activator; 68 object* activator;
69 object* third; 69 object* third;
70 object* event;
70 mapstruct* map; 71 mapstruct* map;
71 char message[1024]; 72 char message[1024];
72 int fix; // seems to be python-only, and should not be part of the API 73 int fix; // seems to be python-only, and should not be part of the API
73 int event_code; 74 int event_code;
74 char extension[1024]; // name field, should invoke specific perl extension 75 char extension[1024]; // name field, should invoke specific perl extension
77} CFPContext; 78} CFPContext;
78 79
79static HV *obj_cache; 80static HV *obj_cache;
80static PerlInterpreter *perl; 81static PerlInterpreter *perl;
81 82
83#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)))) 84#define PUSHcfapi_va(type,ctype) PUSHcfapi (type, va_arg (args, ctype))
83#define PUSH_OB PUSHcfapi(CFAPI_POBJECT, object *) 85#define PUSH_OB PUSHcfapi_va(POBJECT, object *)
84#define PUSH_PL PUSHcfapi(CFAPI_PPLAYER, player *) 86#define PUSH_PL PUSHcfapi_va(PPLAYER, player *)
85#define PUSH_MAP PUSHcfapi(CFAPI_PMAP, mapstruct *) 87#define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *)
86#define PUSH_PV PUSHcfapi(CFAPI_STRING, const char *) 88#define PUSH_PV PUSHcfapi_va(STRING, const char *)
87#define PUSH_IV PUSHcfapi(CFAPI_INT, int) 89#define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int))))
90
91extern void pay_player(object *op, uint64 amount);
92extern uint64 pay_player_arch(object *op, const char *arch, uint64 amount);
88 93
89////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 94//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90 95
91// garbage collect some perl objects, if possible 96// garbage collect some perl objects, if possible
92// all objects no longer referenced and empty are 97// all objects no longer referenced and empty are
228 case CFAPI_LONG: 233 case CFAPI_LONG:
229 sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */ 234 sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */
230 break; 235 break;
231 236
232 case CFAPI_DOUBLE: 237 case CFAPI_DOUBLE:
233 sv = newSViv (*va_arg (args, double *)); 238 sv = newSVnv (*va_arg (args, double *));
234 break; 239 break;
235 240
236 case CFAPI_STRING: 241 case CFAPI_STRING:
237 { 242 {
238 char *str = va_arg (args, char *); 243 char *str = va_arg (args, char *);
245 object *obj = va_arg (args, object *); 250 object *obj = va_arg (args, object *);
246 251
247 if (!obj) 252 if (!obj)
248 sv = &PL_sv_undef; 253 sv = &PL_sv_undef;
249 else 254 else
250 switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) 255 switch (obj->type)
251 { 256 {
252 case MAP: 257 case MAP:
253 sv = newSVptr_cached (obj, "cf::object::map"); 258 sv = newSVptr_cached (obj, "cf::object::map");
254 break; 259 break;
255 260
291 va_end (args); 296 va_end (args);
292 297
293 return sv; 298 return sv;
294} 299}
295 300
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///////////////////////////////////////////////////////////////////////////// 301/////////////////////////////////////////////////////////////////////////////
339 302
340int 303int
341initPlugin (const char *iversion, f_plug_api gethooksptr) 304initPlugin (const char *iversion, f_plug_api gethooksptr)
342{ 305{
468 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); 431 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener);
469 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); 432 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener);
470 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); 433 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener);
471 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); 434 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener);
472 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); 435 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener);
436 registerGlobalEvent (NULL, EVENT_EXTCMD, PLUGIN_NAME, globalEventListener);
473 437
474 char *argv[] = { 438 char *argv[] = {
475 "", 439 "",
476 "-e" 440 "-e"
477 "BEGIN {" 441 "BEGIN {"
483 }; 447 };
484 448
485 perl = perl_alloc (); 449 perl = perl_alloc ();
486 perl_construct (perl); 450 perl_construct (perl);
487 451
452 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
453
488 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 454 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
489 { 455 {
490 printf ("unable to initialize perl-interpreter, continuing without.\n"); 456 printf ("unable to initialize perl-interpreter, continuing without.\n");
491 457
492 perl_destruct (perl); 458 perl_destruct (perl);
526 if (sv) 492 if (sv)
527 clearSVptr (sv); 493 clearSVptr (sv);
528 494
529 rv = 0; 495 rv = 0;
530 } 496 }
497 else if (event_code == EVENT_CLOCK)
498 {
499 dSP;
500 int i, count;
501
502 clean_obj_cache ();
503
504 ENTER;
505 SAVETMPS;
506
507 // service up to 8 events per tick better would be
508 // to check for elapsed time and stop processing after
509 // 0.25 * server_tick or so
510 for (i = 9; --i; )
511 {
512 PUSHMARK (SP);
513 XPUSHs (sv_2mortal (newSViv (0)));
514 PUTBACK;
515 count = call_pv ("Event::one_event", G_SCALAR | G_EVAL);
516 SPAGAIN;
517
518 if (!count || !POPi)
519 break;
520 }
521
522 FREETMPS;
523 LEAVE;
524 }
531 else 525 else
532 { 526 {
533 dSP; 527 dSP;
534 528
535 ENTER; 529 ENTER;
583 case EVENT_KICK: 577 case EVENT_KICK:
584 PUSH_OB; 578 PUSH_OB;
585 PUSH_PV; 579 PUSH_PV;
586 break; 580 break;
587 581
588 case EVENT_CLOCK: 582 case EVENT_EXTCMD:
589 clean_obj_cache (); 583 PUSH_PL;
584 {
585 char *buf = va_arg (args, char *);
586 int len = va_arg (args, int);
587 PUSHs (sv_2mortal (newSVpvn (buf, len)));
588 }
590 break; 589 break;
591 590
592 case EVENT_TELL: 591 case EVENT_TELL:
593 break; 592 break;
594 } 593 }
598 PUTBACK; 597 PUTBACK;
599 int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL); 598 int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL);
600 SPAGAIN; 599 SPAGAIN;
601 600
602 if (SvTRUE (ERRSV)) 601 if (SvTRUE (ERRSV))
603 LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); 602 LOG (llevError, "global event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV));
604 603
605 rv = count > 0 ? POPi : 0; 604 rv = count > 0 ? POPi : 0;
606 605
607 PUTBACK; 606 PUTBACK;
608 FREETMPS; 607 FREETMPS;
613} 612}
614 613
615void * 614void *
616eventListener (int *type, ...) 615eventListener (int *type, ...)
617{ 616{
618 static int rv = 0; 617 static int rv;
619 va_list args; 618 va_list args;
620 char *buf; 619 int event_code;
621 CFPContext context; 620 object *who, *activator, *third, *event;
622 object *eob; 621 char *message, *extension, *options;
623 622
624 if (!perl) 623 if (!perl)
625 return; 624 return;
626 625
627 memset (&context, 0, sizeof (context));
628
629 va_start (args, type); 626 va_start (args, type);
630
631 context.who = va_arg (args, object *); 627 who = va_arg (args, object *);
632 context.event_code = va_arg (args, int); 628 event_code = va_arg (args, int);
633 context.activator = va_arg (args, object *); 629 activator = va_arg (args, object *);
634 context.third = va_arg (args, object *); 630 third = va_arg (args, object *);
635
636 buf = va_arg (args, char *); 631 message = va_arg (args, char *);
637 if (buf != 0) 632 va_arg (args, int); // fix yourself
638 strncpy (context.message, buf, sizeof (context.message)); 633 extension = va_arg (args, char *);
639 634 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 *); 635 event = va_arg (args, object *);
644 context.returnvalue = 0;
645 va_end (args); 636 va_end (args);
646 637
647 inject_event ("cf::inject_event", &context); 638 {
639 dSP;
640
641 ENTER;
642 SAVETMPS;
643
644 PUSHMARK (SP);
645 EXTEND (SP, 10);
646
647 PUSHcfapi (STRING, extension);
648 PUSHs (sv_2mortal (newSViv (event_code)));
649
650 PUSHcfapi (POBJECT, event);
651 PUSHcfapi (POBJECT, who);
652
653 switch (event_code)
654 {
655 case EVENT_STOP: // $ob (e.g. arrow)
656 case EVENT_TIME: // $ob
657 case EVENT_TIMER: // $ob
658 break;
659
660 case EVENT_APPLY: // $ob, $who
661 case EVENT_DROP: // $ob, $who
662 case EVENT_CLOSE: // $ob, $who
663 case EVENT_DEATH: // $ob[, $killer]
664 case EVENT_MOVE: // $ob, $enemy
665 case EVENT_THROW: // $ob, $thrower
666 PUSHcfapi (POBJECT, activator);
667 break;
668
669 case EVENT_ATTACK: // $ob, $who, $victim (?? please god enlighten me)
670 PUSHcfapi (POBJECT, activator);
671 PUSHcfapi (POBJECT, third);
672 break;
673
674 case EVENT_TRIGGER: // $ob, $originator, [$victim], [$msg]
675 PUSHcfapi (POBJECT, activator);
676 PUSHcfapi (POBJECT, third);
677 PUSHcfapi (POBJECT, message);
678 break;
679
680 case EVENT_SAY: // $ob, $who, $msg
681 PUSHcfapi (POBJECT, activator);
682 PUSHcfapi (STRING, message);
683 break;
684
685 default:
686 LOG (llevError, "perl plugin called for unsupported event type %d", event_code);
687 break;
688 }
689
690 PUTBACK;
691 int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL);
692 SPAGAIN;
693
694 if (SvTRUE (ERRSV))
695 LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV));
696
697 rv = count > 0 ? POPi : 0;
698
699 PUTBACK;
700 FREETMPS;
701 LEAVE;
702 }
648 703
649 rv = context.returnvalue;
650 return &rv; 704 return &rv;
651} 705}
652 706
653int 707int
654closePlugin () 708closePlugin ()
1074 const_iv (SK_SUMMONING) 1128 const_iv (SK_SUMMONING)
1075 const_iv (SK_PYROMANCY) 1129 const_iv (SK_PYROMANCY)
1076 const_iv (SK_EVOCATION) 1130 const_iv (SK_EVOCATION)
1077 const_iv (SK_SORCERY) 1131 const_iv (SK_SORCERY)
1078 const_iv (SK_TWO_HANDED_WEAPON) 1132 const_iv (SK_TWO_HANDED_WEAPON)
1133 const_iv (SK_SPARK_TOUCH)
1134 const_iv (SK_SHIVER)
1135 const_iv (SK_ACID_SPLASH)
1136 const_iv (SK_POISON_NAIL)
1079 1137
1080 const_iv (SOUND_NEW_PLAYER) 1138 const_iv (SOUND_NEW_PLAYER)
1081 const_iv (SOUND_FIRE_ARROW) 1139 const_iv (SOUND_FIRE_ARROW)
1082 const_iv (SOUND_LEARN_SPELL) 1140 const_iv (SOUND_LEARN_SPELL)
1083 const_iv (SOUND_FUMBLE_SPELL) 1141 const_iv (SOUND_FUMBLE_SPELL)
1099 const_iv (SOUND_CLOCK) 1157 const_iv (SOUND_CLOCK)
1100 const_iv (SOUND_TURN_HANDLE) 1158 const_iv (SOUND_TURN_HANDLE)
1101 const_iv (SOUND_FALL_HOLE) 1159 const_iv (SOUND_FALL_HOLE)
1102 const_iv (SOUND_DRINK_POISON) 1160 const_iv (SOUND_DRINK_POISON)
1103 const_iv (SOUND_CAST_SPELL_0) 1161 const_iv (SOUND_CAST_SPELL_0)
1162
1163 const_iv (MAP_FLUSH)
1164 const_iv (MAP_PLAYER_UNIQUE)
1165 const_iv (MAP_BLOCK)
1166 const_iv (MAP_STYLE)
1167 const_iv (MAP_OVERLAY)
1168
1169 const_iv (MAP_IN_MEMORY)
1170 const_iv (MAP_SWAPPED)
1171 const_iv (MAP_LOADING)
1172 const_iv (MAP_SAVING)
1104 }; 1173 };
1105 1174
1106 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1175 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1107 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1176 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1108 1177
1125 const_event (CLOSE) 1194 const_event (CLOSE)
1126 const_event (TIMER) 1195 const_event (TIMER)
1127 const_event (MOVE) 1196 const_event (MOVE)
1128 1197
1129 const_event (BORN) 1198 const_event (BORN)
1130 const_event (CLOCK) 1199 //const_event (CLOCK)
1131 const_event (CRASH) 1200 const_event (CRASH)
1132 const_event (PLAYER_DEATH) 1201 const_event (PLAYER_DEATH)
1133 const_event (PLAYER_LOAD) 1202 const_event (PLAYER_LOAD)
1134 const_event (PLAYER_SAVE) 1203 const_event (PLAYER_SAVE)
1135 const_event (GKILL) 1204 const_event (GKILL)
1145 const_event (REMOVE) 1214 const_event (REMOVE)
1146 const_event (SHOUT) 1215 const_event (SHOUT)
1147 const_event (TELL) 1216 const_event (TELL)
1148 const_event (MUZZLE) 1217 const_event (MUZZLE)
1149 const_event (KICK) 1218 const_event (KICK)
1219 const_event (EXTCMD)
1150 //const_event (FREE_OB) 1220 //const_event (FREE_OB)
1151 }; 1221 };
1152 1222
1153 AV *av = get_av ("cf::EVENT", 1); 1223 AV *av = get_av ("cf::EVENT", 1);
1154 1224
1288 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) 1358 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; )
1289 { 1359 {
1290 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); 1360 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); 1361 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0);
1292 } 1362 }
1363
1364 //I_EVENT_API (PACKAGE);
1293} 1365}
1294 1366
1295void 1367void
1296LOG (int level, char *msg) 1368LOG (int level, char *msg)
1297 PROTOTYPE: $$ 1369 PROTOTYPE: $$
1298 C_ARGS: level, "%s", msg 1370 C_ARGS: level, "%s", msg
1371
1372char *path_combine (char *base, char *path)
1373 PROTOTYPE: $$
1374
1375char *path_combine_and_normalize (char *base, char *path)
1376 PROTOTYPE: $$
1299 1377
1300char * 1378char *
1301cf_get_maps_directory (char *path) 1379cf_get_maps_directory (char *path)
1302 PROTOTYPE: $ 1380 PROTOTYPE: $
1303 ALIAS: maps_directory = 0 1381 ALIAS: maps_directory = 0
1472 1550
1473void cf_object_update (object *op, int flags) 1551void cf_object_update (object *op, int flags)
1474 1552
1475void cf_object_pickup (object *op, object *what) 1553void cf_object_pickup (object *op, object *what)
1476 1554
1477char *cf_object_get_key (object *op, char *keyname)
1478 ALIAS: key = 0
1479
1480void cf_object_set_key (object *op, char *keyname, char *value)
1481
1482object *cf_create_object_by_name (const char *name) 1555object *cf_create_object_by_name (const char *name)
1483 1556
1484void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) 1557void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0)
1485 1558
1559void pay_player (object *op, double amount)
1560
1561double pay_player_arch (object *op, const char *arch, double amount)
1562
1486void player_lvl_adj (object *who, object *skill = 0) 1563void player_lvl_adj (object *who, object *skill = 0)
1487 1564
1565int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1488 1566
1489MODULE = cf PACKAGE = cf::object PREFIX = cf_ 1567MODULE = cf PACKAGE = cf::object PREFIX = cf_
1490 1568
1491void cf_fix_object (object *pl) 1569void cf_fix_object (object *pl)
1492 ALIAS: fix = 0 1570 ALIAS: fix = 0
1508 CODE: 1586 CODE:
1509{ 1587{
1510 int unused_type; 1588 int unused_type;
1511 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 1589 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
1512} 1590}
1591
1592# syntatic sugar for easier use in event callbacks.
1593const char *options (object *op)
1594 CODE:
1595 RETVAL = op->name;
1596 OUTPUT:
1597 RETVAL
1513 1598
1514const char *get_ob_key_value (object *op, const char *key) 1599const char *get_ob_key_value (object *op, const char *key)
1515 1600
1516bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) 1601bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1)
1517 1602
1554 1639
1555MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 1640MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
1556 1641
1557player *player (object *op) 1642player *player (object *op)
1558 CODE: 1643 CODE:
1559 RETVAL = cf_player_find (cf_query_name (op)); 1644 RETVAL = op->contr;
1560 OUTPUT: RETVAL 1645 OUTPUT: RETVAL
1561 1646
1562void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) 1647void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1563 1648
1564object *cf_player_send_inventory (object *op) 1649object *cf_player_send_inventory (object *op)
1581 1666
1582void cf_player_set_party (object *op, partylist *party) 1667void cf_player_set_party (object *op, partylist *party)
1583 1668
1584void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) 1669void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0)
1585 1670
1671void kill_player (object *op)
1672
1586MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ 1673MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1587 1674
1588MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 1675MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1589 1676
1590player *cf_player_find (char *name) 1677player *cf_player_find (char *name)
1609 1696
1610player *next (player *pl) 1697player *next (player *pl)
1611 CODE: 1698 CODE:
1612 RETVAL = pl->next; 1699 RETVAL = pl->next;
1613 OUTPUT: RETVAL 1700 OUTPUT: RETVAL
1701
1702bool
1703cell_visible (player *pl, int dx, int dy)
1704 CODE:
1705 RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2
1706 && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2];
1707 OUTPUT:
1708 RETVAL
1709
1710void
1711send (player *pl, SV *packet)
1712 CODE:
1713{
1714 STRLEN len;
1715 char *buf = SvPVbyte (packet, len);
1716
1717 Write_String_To_Socket (&pl->socket, buf, len);
1718}
1719
1720int
1721listening (player *pl, int new_value = -1)
1722 CODE:
1723 RETVAL = pl->listening;
1724 if (new_value >= 0)
1725 pl->listening = new_value;
1726 OUTPUT:
1727 RETVAL
1614 1728
1615void get_savebed (player *pl) 1729void get_savebed (player *pl)
1616 ALIAS: 1730 ALIAS:
1617 savebed = 0 1731 savebed = 0
1618 PPCODE: 1732 PPCODE:
1634 player *pl; 1748 player *pl;
1635 for (pl = first_player; pl; pl = pl->next) 1749 for (pl = first_player; pl; pl = pl->next)
1636 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); 1750 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl));
1637} 1751}
1638 1752
1753bool
1754peaceful (player *pl, bool new_setting = 0)
1755 PROTOTYPE: $;$
1756 CODE:
1757 RETVAL = pl->peaceful;
1758 if (items > 1)
1759 pl->peaceful = new_setting;
1760 OUTPUT:
1761 RETVAL
1762
1639living * 1763living *
1640orig_stats (player *pl) 1764orig_stats (player *pl)
1641 CODE: 1765 CODE:
1642 RETVAL = &pl->orig_stats; 1766 RETVAL = &pl->orig_stats;
1643 OUTPUT: RETVAL 1767 OUTPUT: RETVAL
1683 1807
1684void clean_tmp_map (mapstruct *map) 1808void clean_tmp_map (mapstruct *map)
1685 1809
1686void play_sound_map (mapstruct *map, int x, int y, int sound_num) 1810void play_sound_map (mapstruct *map, int x, int y, int sound_num)
1687 1811
1812mapstruct *tile_map (mapstruct *map, unsigned int dir)
1813 CODE:
1814 RETVAL = dir < 4 ? map->tile_map [dir] : 0;
1815 OUTPUT:
1816 RETVAL
1817
1818char *tile_path (mapstruct *map, unsigned int dir)
1819 CODE:
1820 if (dir >= 4)
1821 XSRETURN_UNDEF;
1822 RETVAL = map->tile_path [dir];
1823 OUTPUT:
1824 RETVAL
1825
1688mapstruct *cf_map_get_map (char *name) 1826mapstruct *cf_map_get_map (char *name)
1689 PROTOTYPE: $ 1827 PROTOTYPE: $
1690 ALIAS: map = 0 1828 ALIAS: map = 0
1691 1829
1830mapstruct *has_been_loaded (char *name)
1831 PROTOTYPE: $
1832
1692mapstruct *cf_map_get_first () 1833mapstruct *cf_map_get_first ()
1693 PROTOTYPE: 1834 PROTOTYPE:
1694 ALIAS: first = 0 1835 ALIAS: first = 0
1695 1836
1696# whoever "designed" the plug-in api should have wasted 1837# whoever "designed" the plug-in api should have wasted
1697# his/her time with staying away form the project - would have 1838# his/her time with staying away from the project - would have
1698# saved others a lot of time, without doubt. 1839# saved others a lot of time, without doubt.
1699void set_path (mapstruct *where, char *path) 1840void set_path (mapstruct *where, char *path)
1700 CODE: 1841 CODE:
1701 strcpy (where->path, path); 1842 strcpy (where->path, path);
1843
1844int in_memory (mapstruct *map)
1845 CODE:
1846 RETVAL = map->in_memory;
1847 OUTPUT:
1848 RETVAL
1702 1849
1703bool unique (mapstruct *map) 1850bool unique (mapstruct *map)
1704 CODE: 1851 CODE:
1705 RETVAL = map->unique; 1852 RETVAL = map->unique;
1706 OUTPUT: 1853 OUTPUT:
1715object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) 1862object *cf_map_insert_object (mapstruct *where, object* op, int x, int y)
1716 1863
1717object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) 1864object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny)
1718 C_ARGS: str, map, nx, ny 1865 C_ARGS: str, map, nx, ny
1719 1866
1720#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1721
1722void 1867void
1868cf_map_normalise (mapstruct *map, int x, int y)
1869 PPCODE:
1870{
1871 mapstruct *nmap = 0;
1872 I16 nx = 0, ny = 0;
1873 int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1874
1875 EXTEND (SP, 4);
1876 PUSHs (sv_2mortal (newSViv (flags)));
1877
1878 if (GIMME_V == G_ARRAY)
1879 {
1880 PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap)));
1881 PUSHs (sv_2mortal (newSViv (nx)));
1882 PUSHs (sv_2mortal (newSViv (ny)));
1883 }
1884}
1885
1886void
1723at (mapstruct *obj, unsigned int x, unsigned int y) 1887at (mapstruct *map, unsigned int x, unsigned int y)
1724 PROTOTYPE: $$$ 1888 PROTOTYPE: $$$
1725 INIT:
1726 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY;
1727 PPCODE: 1889 PPCODE:
1728{ 1890{
1729 object *o; 1891 object *o;
1730 1892 mapstruct *nmap = 0;
1893 I16 nx, ny;
1894
1895 cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1896
1897 if (nmap)
1731 for (o = GET_MAP_OB (obj, x, y); o; o = o->above) 1898 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
1732 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1899 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1733} 1900}
1734 1901
1735SV * 1902SV *
1736bot_at (mapstruct *obj, unsigned int x, unsigned int y) 1903bot_at (mapstruct *obj, unsigned int x, unsigned int y)
1737 PROTOTYPE: $$$ 1904 PROTOTYPE: $$$

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines