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.44 by root, Fri Mar 31 20:21:53 2006 UTC vs.
Revision 1.57 by root, Tue Jul 11 15:25:00 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
78} CFPContext; 78} CFPContext;
79 79
80static HV *obj_cache; 80static HV *obj_cache;
81static PerlInterpreter *perl; 81static PerlInterpreter *perl;
82 82
83#define PUSHcfapi(type,value) PUSHs (sv_2mortal (newSVcfapi (CFAPI_ ## type, (value))))
83#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))
84#define PUSH_OB PUSHcfapi(CFAPI_POBJECT, object *) 85#define PUSH_OB PUSHcfapi_va(POBJECT, object *)
85#define PUSH_PL PUSHcfapi(CFAPI_PPLAYER, player *) 86#define PUSH_PL PUSHcfapi_va(PPLAYER, player *)
86#define PUSH_MAP PUSHcfapi(CFAPI_PMAP, mapstruct *) 87#define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *)
87#define PUSH_PV PUSHcfapi(CFAPI_STRING, const char *) 88#define PUSH_PV PUSHcfapi_va(STRING, const char *)
88#define PUSH_IV PUSHcfapi(CFAPI_INT, int) 89#define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int))))
89 90
90////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 91//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
91 92
92// garbage collect some perl objects, if possible 93// garbage collect some perl objects, if possible
93// all objects no longer referenced and empty are 94// all objects no longer referenced and empty are
229 case CFAPI_LONG: 230 case CFAPI_LONG:
230 sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */ 231 sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */
231 break; 232 break;
232 233
233 case CFAPI_DOUBLE: 234 case CFAPI_DOUBLE:
234 sv = newSViv (*va_arg (args, double *)); 235 sv = newSVnv (*va_arg (args, double *));
235 break; 236 break;
236 237
237 case CFAPI_STRING: 238 case CFAPI_STRING:
238 { 239 {
239 char *str = va_arg (args, char *); 240 char *str = va_arg (args, char *);
246 object *obj = va_arg (args, object *); 247 object *obj = va_arg (args, object *);
247 248
248 if (!obj) 249 if (!obj)
249 sv = &PL_sv_undef; 250 sv = &PL_sv_undef;
250 else 251 else
251 switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) 252 switch (obj->type)
252 { 253 {
253 case MAP: 254 case MAP:
254 sv = newSVptr_cached (obj, "cf::object::map"); 255 sv = newSVptr_cached (obj, "cf::object::map");
255 break; 256 break;
256 257
292 va_end (args); 293 va_end (args);
293 294
294 return sv; 295 return sv;
295} 296}
296 297
297/////////////////////////////////////////////////////////////////////////////
298
299void
300inject_event (const char *func, CFPContext *context)
301{
302 dSP;
303
304 ENTER;
305 SAVETMPS;
306
307 PUSHMARK (SP);
308
309 EXTEND (SP, 10);
310
311 HV *hv = newHV ();
312#define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0)
313 hv_context (CFAPI_POBJECT, ,who);
314 hv_context (CFAPI_POBJECT, ,activator);
315 hv_context (CFAPI_POBJECT, ,third);
316 hv_context (CFAPI_POBJECT, ,event);
317 hv_context (CFAPI_PMAP, ,map);
318 hv_context (CFAPI_STRING , ,message);
319 hv_context (CFAPI_INT ,&,fix);
320 hv_context (CFAPI_INT ,&,event_code);
321 hv_context (CFAPI_STRING , ,options);
322 hv_context (CFAPI_STRING , ,extension);
323
324 PUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
325
326 PUTBACK;
327 int count = call_pv (func, G_SCALAR | G_EVAL);
328 SPAGAIN;
329
330 if (SvTRUE (ERRSV))
331 LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV));
332
333 context->returnvalue = count > 0 ? POPi : 0;
334
335 PUTBACK;
336 FREETMPS;
337 LEAVE;
338}
339
340///////////////////////////////////////////////////////////////////////////// 298/////////////////////////////////////////////////////////////////////////////
341 299
342int 300int
343initPlugin (const char *iversion, f_plug_api gethooksptr) 301initPlugin (const char *iversion, f_plug_api gethooksptr)
344{ 302{
470 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); 428 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener);
471 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); 429 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener);
472 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); 430 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener);
473 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); 431 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener);
474 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); 432 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener);
433 registerGlobalEvent (NULL, EVENT_EXTCMD, PLUGIN_NAME, globalEventListener);
475 434
476 char *argv[] = { 435 char *argv[] = {
477 "", 436 "",
478 "-e" 437 "-e"
479 "BEGIN {" 438 "BEGIN {"
485 }; 444 };
486 445
487 perl = perl_alloc (); 446 perl = perl_alloc ();
488 perl_construct (perl); 447 perl_construct (perl);
489 448
449 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
450
490 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 451 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
491 { 452 {
492 printf ("unable to initialize perl-interpreter, continuing without.\n"); 453 printf ("unable to initialize perl-interpreter, continuing without.\n");
493 454
494 perl_destruct (perl); 455 perl_destruct (perl);
528 if (sv) 489 if (sv)
529 clearSVptr (sv); 490 clearSVptr (sv);
530 491
531 rv = 0; 492 rv = 0;
532 } 493 }
494 else if (event_code == EVENT_CLOCK)
495 {
496 dSP;
497 int i, count;
498
499 clean_obj_cache ();
500
501 ENTER;
502 SAVETMPS;
503
504 // service up to 8 events per tick better would be
505 // to check for elapsed time and stop processing after
506 // 0.25 * server_tick or so
507 for (i = 9; --i; )
508 {
509 PUSHMARK (SP);
510 XPUSHs (sv_2mortal (newSViv (0)));
511 PUTBACK;
512 count = call_pv ("Event::one_event", G_SCALAR | G_EVAL);
513 SPAGAIN;
514
515 if (!count || !POPi)
516 break;
517 }
518
519 FREETMPS;
520 LEAVE;
521 }
533 else 522 else
534 { 523 {
535 dSP; 524 dSP;
536 525
537 ENTER; 526 ENTER;
585 case EVENT_KICK: 574 case EVENT_KICK:
586 PUSH_OB; 575 PUSH_OB;
587 PUSH_PV; 576 PUSH_PV;
588 break; 577 break;
589 578
590 case EVENT_CLOCK: 579 case EVENT_EXTCMD:
591 clean_obj_cache (); 580 PUSH_PL;
581 {
582 char *buf = va_arg (args, char *);
583 int len = va_arg (args, int);
584 PUSHs (sv_2mortal (newSVpvn (buf, len)));
585 }
592 break; 586 break;
593 587
594 case EVENT_TELL: 588 case EVENT_TELL:
595 break; 589 break;
596 } 590 }
600 PUTBACK; 594 PUTBACK;
601 int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL); 595 int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL);
602 SPAGAIN; 596 SPAGAIN;
603 597
604 if (SvTRUE (ERRSV)) 598 if (SvTRUE (ERRSV))
605 LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); 599 LOG (llevError, "global event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV));
606 600
607 rv = count > 0 ? POPi : 0; 601 rv = count > 0 ? POPi : 0;
608 602
609 PUTBACK; 603 PUTBACK;
610 FREETMPS; 604 FREETMPS;
615} 609}
616 610
617void * 611void *
618eventListener (int *type, ...) 612eventListener (int *type, ...)
619{ 613{
620 static int rv = 0; 614 static int rv;
621 va_list args; 615 va_list args;
622 char *buf; 616 int event_code;
623 CFPContext context; 617 object *who, *activator, *third, *event;
618 char *message, *extension, *options;
624 619
625 if (!perl) 620 if (!perl)
626 return; 621 return;
627 622
628 memset (&context, 0, sizeof (context));
629
630 va_start (args, type); 623 va_start (args, type);
631
632 context.who = va_arg (args, object *); 624 who = va_arg (args, object *);
633 context.event_code = va_arg (args, int); 625 event_code = va_arg (args, int);
634 context.activator = va_arg (args, object *); 626 activator = va_arg (args, object *);
635 context.third = va_arg (args, object *); 627 third = va_arg (args, object *);
636
637 buf = va_arg (args, char *); 628 message = va_arg (args, char *);
638 if (buf != 0) 629 va_arg (args, int); // fix yourself
639 strncpy (context.message, buf, sizeof (context.message)); 630 extension = va_arg (args, char *);
640 631 options = va_arg (args, char *);
641 context.fix = va_arg (args, int);
642 strncpy (context.extension, va_arg (args, char *), sizeof (context.extension));
643 strncpy (context.options, va_arg (args, char *), sizeof (context.options));
644 context.event = va_arg (args, object *); 632 event = va_arg (args, object *);
645 va_end (args); 633 va_end (args);
646 634
647 context.returnvalue = 0; 635 {
636 dSP;
648 637
649 inject_event ("cf::inject_event", &context); 638 ENTER;
639 SAVETMPS;
640
641 PUSHMARK (SP);
642 EXTEND (SP, 10);
643
644 PUSHcfapi (STRING, extension);
645 PUSHs (sv_2mortal (newSViv (event_code)));
646
647 PUSHcfapi (POBJECT, event);
648 PUSHcfapi (POBJECT, who);
649
650 switch (event_code)
651 {
652 case EVENT_STOP: // $ob (e.g. arrow)
653 case EVENT_TIME: // $ob
654 case EVENT_TIMER: // $ob
655 break;
656
657 case EVENT_APPLY: // $ob, $who
658 case EVENT_DROP: // $ob, $who
659 case EVENT_CLOSE: // $ob, $who
660 case EVENT_DEATH: // $ob[, $killer]
661 case EVENT_MOVE: // $ob, $enemy
662 case EVENT_THROW: // $ob, $thrower
663 PUSHcfapi (POBJECT, activator);
664 break;
665
666 case EVENT_ATTACK: // $ob, $who, $victim (?? please god enlighten me)
667 PUSHcfapi (POBJECT, activator);
668 PUSHcfapi (POBJECT, third);
669 break;
670
671 case EVENT_TRIGGER: // $ob, $originator, [$victim], [$msg]
672 PUSHcfapi (POBJECT, activator);
673 PUSHcfapi (POBJECT, third);
674 PUSHcfapi (POBJECT, message);
675 break;
676
677 case EVENT_SAY: // $ob, $who, $msg
678 PUSHcfapi (POBJECT, activator);
679 PUSHcfapi (STRING, message);
680 break;
681
682 default:
683 LOG (llevError, "perl plugin called for unsupported event type %d", event_code);
684 break;
685 }
686
687 PUTBACK;
688 int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL);
689 SPAGAIN;
690
691 if (SvTRUE (ERRSV))
692 LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV));
693
694 rv = count > 0 ? POPi : 0;
695
696 PUTBACK;
697 FREETMPS;
698 LEAVE;
699 }
650 700
651 rv = context.returnvalue;
652 return &rv; 701 return &rv;
653} 702}
654 703
655int 704int
656closePlugin () 705closePlugin ()
1076 const_iv (SK_SUMMONING) 1125 const_iv (SK_SUMMONING)
1077 const_iv (SK_PYROMANCY) 1126 const_iv (SK_PYROMANCY)
1078 const_iv (SK_EVOCATION) 1127 const_iv (SK_EVOCATION)
1079 const_iv (SK_SORCERY) 1128 const_iv (SK_SORCERY)
1080 const_iv (SK_TWO_HANDED_WEAPON) 1129 const_iv (SK_TWO_HANDED_WEAPON)
1130 const_iv (SK_SPARK_TOUCH)
1131 const_iv (SK_SHIVER)
1132 const_iv (SK_ACID_SPLASH)
1133 const_iv (SK_POISON_NAIL)
1081 1134
1082 const_iv (SOUND_NEW_PLAYER) 1135 const_iv (SOUND_NEW_PLAYER)
1083 const_iv (SOUND_FIRE_ARROW) 1136 const_iv (SOUND_FIRE_ARROW)
1084 const_iv (SOUND_LEARN_SPELL) 1137 const_iv (SOUND_LEARN_SPELL)
1085 const_iv (SOUND_FUMBLE_SPELL) 1138 const_iv (SOUND_FUMBLE_SPELL)
1101 const_iv (SOUND_CLOCK) 1154 const_iv (SOUND_CLOCK)
1102 const_iv (SOUND_TURN_HANDLE) 1155 const_iv (SOUND_TURN_HANDLE)
1103 const_iv (SOUND_FALL_HOLE) 1156 const_iv (SOUND_FALL_HOLE)
1104 const_iv (SOUND_DRINK_POISON) 1157 const_iv (SOUND_DRINK_POISON)
1105 const_iv (SOUND_CAST_SPELL_0) 1158 const_iv (SOUND_CAST_SPELL_0)
1159
1160 const_iv (MAP_FLUSH)
1161 const_iv (MAP_PLAYER_UNIQUE)
1162 const_iv (MAP_BLOCK)
1163 const_iv (MAP_STYLE)
1164 const_iv (MAP_OVERLAY)
1165
1166 const_iv (MAP_IN_MEMORY)
1167 const_iv (MAP_SWAPPED)
1168 const_iv (MAP_LOADING)
1169 const_iv (MAP_SAVING)
1106 }; 1170 };
1107 1171
1108 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1172 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1109 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1173 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1110 1174
1127 const_event (CLOSE) 1191 const_event (CLOSE)
1128 const_event (TIMER) 1192 const_event (TIMER)
1129 const_event (MOVE) 1193 const_event (MOVE)
1130 1194
1131 const_event (BORN) 1195 const_event (BORN)
1132 const_event (CLOCK) 1196 //const_event (CLOCK)
1133 const_event (CRASH) 1197 const_event (CRASH)
1134 const_event (PLAYER_DEATH) 1198 const_event (PLAYER_DEATH)
1135 const_event (PLAYER_LOAD) 1199 const_event (PLAYER_LOAD)
1136 const_event (PLAYER_SAVE) 1200 const_event (PLAYER_SAVE)
1137 const_event (GKILL) 1201 const_event (GKILL)
1147 const_event (REMOVE) 1211 const_event (REMOVE)
1148 const_event (SHOUT) 1212 const_event (SHOUT)
1149 const_event (TELL) 1213 const_event (TELL)
1150 const_event (MUZZLE) 1214 const_event (MUZZLE)
1151 const_event (KICK) 1215 const_event (KICK)
1216 const_event (EXTCMD)
1152 //const_event (FREE_OB) 1217 //const_event (FREE_OB)
1153 }; 1218 };
1154 1219
1155 AV *av = get_av ("cf::EVENT", 1); 1220 AV *av = get_av ("cf::EVENT", 1);
1156 1221
1290 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) 1355 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; )
1291 { 1356 {
1292 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); 1357 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0);
1293 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); 1358 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0);
1294 } 1359 }
1360
1361 //I_EVENT_API (PACKAGE);
1295} 1362}
1296 1363
1297void 1364void
1298LOG (int level, char *msg) 1365LOG (int level, char *msg)
1299 PROTOTYPE: $$ 1366 PROTOTYPE: $$
1300 C_ARGS: level, "%s", msg 1367 C_ARGS: level, "%s", msg
1368
1369char *path_combine (char *base, char *path)
1370 PROTOTYPE: $$
1371
1372char *path_combine_and_normalize (char *base, char *path)
1373 PROTOTYPE: $$
1301 1374
1302char * 1375char *
1303cf_get_maps_directory (char *path) 1376cf_get_maps_directory (char *path)
1304 PROTOTYPE: $ 1377 PROTOTYPE: $
1305 ALIAS: maps_directory = 0 1378 ALIAS: maps_directory = 0
1474 1547
1475void cf_object_update (object *op, int flags) 1548void cf_object_update (object *op, int flags)
1476 1549
1477void cf_object_pickup (object *op, object *what) 1550void cf_object_pickup (object *op, object *what)
1478 1551
1479char *cf_object_get_key (object *op, char *keyname)
1480 ALIAS: key = 0
1481
1482void cf_object_set_key (object *op, char *keyname, char *value)
1483
1484object *cf_create_object_by_name (const char *name) 1552object *cf_create_object_by_name (const char *name)
1485 1553
1486void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) 1554void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0)
1487 1555
1488void player_lvl_adj (object *who, object *skill = 0) 1556void player_lvl_adj (object *who, object *skill = 0)
1489 1557
1558int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1490 1559
1491MODULE = cf PACKAGE = cf::object PREFIX = cf_ 1560MODULE = cf PACKAGE = cf::object PREFIX = cf_
1492 1561
1493void cf_fix_object (object *pl) 1562void cf_fix_object (object *pl)
1494 ALIAS: fix = 0 1563 ALIAS: fix = 0
1510 CODE: 1579 CODE:
1511{ 1580{
1512 int unused_type; 1581 int unused_type;
1513 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 1582 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
1514} 1583}
1584
1585# syntatic sugar for easier use in event callbacks.
1586const char *options (object *op)
1587 CODE:
1588 RETVAL = op->name;
1589 OUTPUT:
1590 RETVAL
1515 1591
1516const char *get_ob_key_value (object *op, const char *key) 1592const char *get_ob_key_value (object *op, const char *key)
1517 1593
1518bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) 1594bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1)
1519 1595
1556 1632
1557MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 1633MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
1558 1634
1559player *player (object *op) 1635player *player (object *op)
1560 CODE: 1636 CODE:
1561 RETVAL = cf_player_find (cf_query_name (op)); 1637 RETVAL = op->contr;
1562 OUTPUT: RETVAL 1638 OUTPUT: RETVAL
1563 1639
1564void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) 1640void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1565 1641
1566object *cf_player_send_inventory (object *op) 1642object *cf_player_send_inventory (object *op)
1583 1659
1584void cf_player_set_party (object *op, partylist *party) 1660void cf_player_set_party (object *op, partylist *party)
1585 1661
1586void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) 1662void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0)
1587 1663
1664void kill_player (object *op)
1665
1588MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ 1666MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1589 1667
1590MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 1668MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1591 1669
1592player *cf_player_find (char *name) 1670player *cf_player_find (char *name)
1611 1689
1612player *next (player *pl) 1690player *next (player *pl)
1613 CODE: 1691 CODE:
1614 RETVAL = pl->next; 1692 RETVAL = pl->next;
1615 OUTPUT: RETVAL 1693 OUTPUT: RETVAL
1694
1695bool
1696cell_visible (player *pl, int dx, int dy)
1697 CODE:
1698 RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2
1699 && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2];
1700 OUTPUT:
1701 RETVAL
1702
1703void
1704send (player *pl, SV *packet)
1705 CODE:
1706{
1707 STRLEN len;
1708 char *buf = SvPVbyte (packet, len);
1709
1710 Write_String_To_Socket (&pl->socket, buf, len);
1711}
1712
1713int
1714listening (player *pl, int new_value = -1)
1715 CODE:
1716 RETVAL = pl->listening;
1717 if (new_value >= 0)
1718 pl->listening = new_value;
1719 OUTPUT:
1720 RETVAL
1616 1721
1617void get_savebed (player *pl) 1722void get_savebed (player *pl)
1618 ALIAS: 1723 ALIAS:
1619 savebed = 0 1724 savebed = 0
1620 PPCODE: 1725 PPCODE:
1695 1800
1696void clean_tmp_map (mapstruct *map) 1801void clean_tmp_map (mapstruct *map)
1697 1802
1698void play_sound_map (mapstruct *map, int x, int y, int sound_num) 1803void play_sound_map (mapstruct *map, int x, int y, int sound_num)
1699 1804
1805mapstruct *tile_map (mapstruct *map, unsigned int dir)
1806 CODE:
1807 RETVAL = dir < 4 ? map->tile_map [dir] : 0;
1808 OUTPUT:
1809 RETVAL
1810
1811char *tile_path (mapstruct *map, unsigned int dir)
1812 CODE:
1813 if (dir >= 4)
1814 XSRETURN_UNDEF;
1815 RETVAL = map->tile_path [dir];
1816 OUTPUT:
1817 RETVAL
1818
1700mapstruct *cf_map_get_map (char *name) 1819mapstruct *cf_map_get_map (char *name)
1701 PROTOTYPE: $ 1820 PROTOTYPE: $
1702 ALIAS: map = 0 1821 ALIAS: map = 0
1703 1822
1823mapstruct *has_been_loaded (char *name)
1824 PROTOTYPE: $
1825
1704mapstruct *cf_map_get_first () 1826mapstruct *cf_map_get_first ()
1705 PROTOTYPE: 1827 PROTOTYPE:
1706 ALIAS: first = 0 1828 ALIAS: first = 0
1707 1829
1708# whoever "designed" the plug-in api should have wasted 1830# whoever "designed" the plug-in api should have wasted
1709# his/her time with staying away form the project - would have 1831# his/her time with staying away from the project - would have
1710# saved others a lot of time, without doubt. 1832# saved others a lot of time, without doubt.
1711void set_path (mapstruct *where, char *path) 1833void set_path (mapstruct *where, char *path)
1712 CODE: 1834 CODE:
1713 strcpy (where->path, path); 1835 strcpy (where->path, path);
1836
1837int in_memory (mapstruct *map)
1838 CODE:
1839 RETVAL = map->in_memory;
1840 OUTPUT:
1841 RETVAL
1714 1842
1715bool unique (mapstruct *map) 1843bool unique (mapstruct *map)
1716 CODE: 1844 CODE:
1717 RETVAL = map->unique; 1845 RETVAL = map->unique;
1718 OUTPUT: 1846 OUTPUT:
1727object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) 1855object *cf_map_insert_object (mapstruct *where, object* op, int x, int y)
1728 1856
1729object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) 1857object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny)
1730 C_ARGS: str, map, nx, ny 1858 C_ARGS: str, map, nx, ny
1731 1859
1732#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1733
1734void 1860void
1861cf_map_normalise (mapstruct *map, int x, int y)
1862 PPCODE:
1863{
1864 mapstruct *nmap = 0;
1865 I16 nx = 0, ny = 0;
1866 int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1867
1868 EXTEND (SP, 4);
1869 PUSHs (sv_2mortal (newSViv (flags)));
1870
1871 if (GIMME_V == G_ARRAY)
1872 {
1873 PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap)));
1874 PUSHs (sv_2mortal (newSViv (nx)));
1875 PUSHs (sv_2mortal (newSViv (ny)));
1876 }
1877}
1878
1879void
1735at (mapstruct *obj, unsigned int x, unsigned int y) 1880at (mapstruct *map, unsigned int x, unsigned int y)
1736 PROTOTYPE: $$$ 1881 PROTOTYPE: $$$
1737 INIT:
1738 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY;
1739 PPCODE: 1882 PPCODE:
1740{ 1883{
1741 object *o; 1884 object *o;
1742 1885 mapstruct *nmap = 0;
1886 I16 nx, ny;
1887
1888 cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1889
1890 if (nmap)
1743 for (o = GET_MAP_OB (obj, x, y); o; o = o->above) 1891 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
1744 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1892 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1745} 1893}
1746 1894
1747SV * 1895SV *
1748bot_at (mapstruct *obj, unsigned int x, unsigned int y) 1896bot_at (mapstruct *obj, unsigned int x, unsigned int y)
1749 PROTOTYPE: $$$ 1897 PROTOTYPE: $$$

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines