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.56 by root, Tue Jul 11 14:24: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))))
88 90
89////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 91//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90 92
91// garbage collect some perl objects, if possible 93// garbage collect some perl objects, if possible
92// all objects no longer referenced and empty are 94// all objects no longer referenced and empty are
228 case CFAPI_LONG: 230 case CFAPI_LONG:
229 sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */ 231 sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */
230 break; 232 break;
231 233
232 case CFAPI_DOUBLE: 234 case CFAPI_DOUBLE:
233 sv = newSViv (*va_arg (args, double *)); 235 sv = newSVnv (*va_arg (args, double *));
234 break; 236 break;
235 237
236 case CFAPI_STRING: 238 case CFAPI_STRING:
237 { 239 {
238 char *str = va_arg (args, char *); 240 char *str = va_arg (args, char *);
245 object *obj = va_arg (args, object *); 247 object *obj = va_arg (args, object *);
246 248
247 if (!obj) 249 if (!obj)
248 sv = &PL_sv_undef; 250 sv = &PL_sv_undef;
249 else 251 else
250 switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) 252 switch (obj->type)
251 { 253 {
252 case MAP: 254 case MAP:
253 sv = newSVptr_cached (obj, "cf::object::map"); 255 sv = newSVptr_cached (obj, "cf::object::map");
254 break; 256 break;
255 257
291 va_end (args); 293 va_end (args);
292 294
293 return sv; 295 return sv;
294} 296}
295 297
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///////////////////////////////////////////////////////////////////////////// 298/////////////////////////////////////////////////////////////////////////////
339 299
340int 300int
341initPlugin (const char *iversion, f_plug_api gethooksptr) 301initPlugin (const char *iversion, f_plug_api gethooksptr)
342{ 302{
468 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); 428 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener);
469 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); 429 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener);
470 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); 430 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener);
471 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); 431 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener);
472 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);
473 434
474 char *argv[] = { 435 char *argv[] = {
475 "", 436 "",
476 "-e" 437 "-e"
477 "BEGIN {" 438 "BEGIN {"
483 }; 444 };
484 445
485 perl = perl_alloc (); 446 perl = perl_alloc ();
486 perl_construct (perl); 447 perl_construct (perl);
487 448
449 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
450
488 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))
489 { 452 {
490 printf ("unable to initialize perl-interpreter, continuing without.\n"); 453 printf ("unable to initialize perl-interpreter, continuing without.\n");
491 454
492 perl_destruct (perl); 455 perl_destruct (perl);
526 if (sv) 489 if (sv)
527 clearSVptr (sv); 490 clearSVptr (sv);
528 491
529 rv = 0; 492 rv = 0;
530 } 493 }
494 else if (event_code == EVENT_CLOCK)
495 {
496 dSP;
497
498 clean_obj_cache ();
499
500 ENTER;
501 SAVETMPS;
502 PUSHMARK (SP);
503 XPUSHs (sv_2mortal (newSViv (0)));
504 PUTBACK;
505 call_pv ("Event::one_event", G_DISCARD | G_EVAL);
506 SPAGAIN;
507 FREETMPS;
508 LEAVE;
509 }
531 else 510 else
532 { 511 {
533 dSP; 512 dSP;
534 513
535 ENTER; 514 ENTER;
583 case EVENT_KICK: 562 case EVENT_KICK:
584 PUSH_OB; 563 PUSH_OB;
585 PUSH_PV; 564 PUSH_PV;
586 break; 565 break;
587 566
588 case EVENT_CLOCK: 567 case EVENT_EXTCMD:
589 clean_obj_cache (); 568 PUSH_PL;
569 {
570 char *buf = va_arg (args, char *);
571 int len = va_arg (args, int);
572 PUSHs (sv_2mortal (newSVpvn (buf, len)));
573 }
590 break; 574 break;
591 575
592 case EVENT_TELL: 576 case EVENT_TELL:
593 break; 577 break;
594 } 578 }
598 PUTBACK; 582 PUTBACK;
599 int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL); 583 int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL);
600 SPAGAIN; 584 SPAGAIN;
601 585
602 if (SvTRUE (ERRSV)) 586 if (SvTRUE (ERRSV))
603 LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); 587 LOG (llevError, "global event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV));
604 588
605 rv = count > 0 ? POPi : 0; 589 rv = count > 0 ? POPi : 0;
606 590
607 PUTBACK; 591 PUTBACK;
608 FREETMPS; 592 FREETMPS;
613} 597}
614 598
615void * 599void *
616eventListener (int *type, ...) 600eventListener (int *type, ...)
617{ 601{
618 static int rv = 0; 602 static int rv;
619 va_list args; 603 va_list args;
620 char *buf; 604 int event_code;
621 CFPContext context; 605 object *who, *activator, *third, *event;
622 object *eob; 606 char *message, *extension, *options;
623 607
624 if (!perl) 608 if (!perl)
625 return; 609 return;
626 610
627 memset (&context, 0, sizeof (context));
628
629 va_start (args, type); 611 va_start (args, type);
630
631 context.who = va_arg (args, object *); 612 who = va_arg (args, object *);
632 context.event_code = va_arg (args, int); 613 event_code = va_arg (args, int);
633 context.activator = va_arg (args, object *); 614 activator = va_arg (args, object *);
634 context.third = va_arg (args, object *); 615 third = va_arg (args, object *);
635
636 buf = va_arg (args, char *); 616 message = va_arg (args, char *);
637 if (buf != 0) 617 va_arg (args, int); // fix yourself
638 strncpy (context.message, buf, sizeof (context.message)); 618 extension = va_arg (args, char *);
639 619 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 *); 620 event = va_arg (args, object *);
644 context.returnvalue = 0;
645 va_end (args); 621 va_end (args);
646 622
647 inject_event ("cf::inject_event", &context); 623 {
624 dSP;
625
626 ENTER;
627 SAVETMPS;
628
629 PUSHMARK (SP);
630 EXTEND (SP, 10);
631
632 PUSHcfapi (STRING, extension);
633 PUSHs (sv_2mortal (newSViv (event_code)));
634
635 PUSHcfapi (POBJECT, event);
636 PUSHcfapi (POBJECT, who);
637
638 switch (event_code)
639 {
640 case EVENT_STOP: // $ob (e.g. arrow)
641 case EVENT_TIME: // $ob
642 case EVENT_TIMER: // $ob
643 break;
644
645 case EVENT_APPLY: // $ob, $who
646 case EVENT_DROP: // $ob, $who
647 case EVENT_CLOSE: // $ob, $who
648 case EVENT_DEATH: // $ob[, $killer]
649 case EVENT_MOVE: // $ob, $enemy
650 case EVENT_THROW: // $ob, $thrower
651 PUSHcfapi (POBJECT, activator);
652 break;
653
654 case EVENT_ATTACK: // $ob, $who, $victim (?? please god enlighten me)
655 PUSHcfapi (POBJECT, activator);
656 PUSHcfapi (POBJECT, third);
657 break;
658
659 case EVENT_TRIGGER: // $ob, $originator, [$victim], [$msg]
660 PUSHcfapi (POBJECT, activator);
661 PUSHcfapi (POBJECT, third);
662 PUSHcfapi (POBJECT, message);
663 break;
664
665 case EVENT_SAY: // $ob, $who, $msg
666 PUSHcfapi (POBJECT, activator);
667 PUSHcfapi (STRING, message);
668 break;
669
670 default:
671 LOG (llevError, "perl plugin called for unsupported event type %d", event_code);
672 break;
673 }
674
675 PUTBACK;
676 int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL);
677 SPAGAIN;
678
679 if (SvTRUE (ERRSV))
680 LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV));
681
682 rv = count > 0 ? POPi : 0;
683
684 PUTBACK;
685 FREETMPS;
686 LEAVE;
687 }
648 688
649 rv = context.returnvalue;
650 return &rv; 689 return &rv;
651} 690}
652 691
653int 692int
654closePlugin () 693closePlugin ()
1074 const_iv (SK_SUMMONING) 1113 const_iv (SK_SUMMONING)
1075 const_iv (SK_PYROMANCY) 1114 const_iv (SK_PYROMANCY)
1076 const_iv (SK_EVOCATION) 1115 const_iv (SK_EVOCATION)
1077 const_iv (SK_SORCERY) 1116 const_iv (SK_SORCERY)
1078 const_iv (SK_TWO_HANDED_WEAPON) 1117 const_iv (SK_TWO_HANDED_WEAPON)
1118 const_iv (SK_SPARK_TOUCH)
1119 const_iv (SK_SHIVER)
1120 const_iv (SK_ACID_SPLASH)
1121 const_iv (SK_POISON_NAIL)
1079 1122
1080 const_iv (SOUND_NEW_PLAYER) 1123 const_iv (SOUND_NEW_PLAYER)
1081 const_iv (SOUND_FIRE_ARROW) 1124 const_iv (SOUND_FIRE_ARROW)
1082 const_iv (SOUND_LEARN_SPELL) 1125 const_iv (SOUND_LEARN_SPELL)
1083 const_iv (SOUND_FUMBLE_SPELL) 1126 const_iv (SOUND_FUMBLE_SPELL)
1099 const_iv (SOUND_CLOCK) 1142 const_iv (SOUND_CLOCK)
1100 const_iv (SOUND_TURN_HANDLE) 1143 const_iv (SOUND_TURN_HANDLE)
1101 const_iv (SOUND_FALL_HOLE) 1144 const_iv (SOUND_FALL_HOLE)
1102 const_iv (SOUND_DRINK_POISON) 1145 const_iv (SOUND_DRINK_POISON)
1103 const_iv (SOUND_CAST_SPELL_0) 1146 const_iv (SOUND_CAST_SPELL_0)
1147
1148 const_iv (MAP_FLUSH)
1149 const_iv (MAP_PLAYER_UNIQUE)
1150 const_iv (MAP_BLOCK)
1151 const_iv (MAP_STYLE)
1152 const_iv (MAP_OVERLAY)
1153
1154 const_iv (MAP_IN_MEMORY)
1155 const_iv (MAP_SWAPPED)
1156 const_iv (MAP_LOADING)
1157 const_iv (MAP_SAVING)
1104 }; 1158 };
1105 1159
1106 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1160 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1107 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1161 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1108 1162
1125 const_event (CLOSE) 1179 const_event (CLOSE)
1126 const_event (TIMER) 1180 const_event (TIMER)
1127 const_event (MOVE) 1181 const_event (MOVE)
1128 1182
1129 const_event (BORN) 1183 const_event (BORN)
1130 const_event (CLOCK) 1184 //const_event (CLOCK)
1131 const_event (CRASH) 1185 const_event (CRASH)
1132 const_event (PLAYER_DEATH) 1186 const_event (PLAYER_DEATH)
1133 const_event (PLAYER_LOAD) 1187 const_event (PLAYER_LOAD)
1134 const_event (PLAYER_SAVE) 1188 const_event (PLAYER_SAVE)
1135 const_event (GKILL) 1189 const_event (GKILL)
1145 const_event (REMOVE) 1199 const_event (REMOVE)
1146 const_event (SHOUT) 1200 const_event (SHOUT)
1147 const_event (TELL) 1201 const_event (TELL)
1148 const_event (MUZZLE) 1202 const_event (MUZZLE)
1149 const_event (KICK) 1203 const_event (KICK)
1204 const_event (EXTCMD)
1150 //const_event (FREE_OB) 1205 //const_event (FREE_OB)
1151 }; 1206 };
1152 1207
1153 AV *av = get_av ("cf::EVENT", 1); 1208 AV *av = get_av ("cf::EVENT", 1);
1154 1209
1288 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) 1343 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; )
1289 { 1344 {
1290 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); 1345 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); 1346 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0);
1292 } 1347 }
1348
1349 //I_EVENT_API (PACKAGE);
1293} 1350}
1294 1351
1295void 1352void
1296LOG (int level, char *msg) 1353LOG (int level, char *msg)
1297 PROTOTYPE: $$ 1354 PROTOTYPE: $$
1298 C_ARGS: level, "%s", msg 1355 C_ARGS: level, "%s", msg
1356
1357char *path_combine (char *base, char *path)
1358 PROTOTYPE: $$
1359
1360char *path_combine_and_normalize (char *base, char *path)
1361 PROTOTYPE: $$
1299 1362
1300char * 1363char *
1301cf_get_maps_directory (char *path) 1364cf_get_maps_directory (char *path)
1302 PROTOTYPE: $ 1365 PROTOTYPE: $
1303 ALIAS: maps_directory = 0 1366 ALIAS: maps_directory = 0
1472 1535
1473void cf_object_update (object *op, int flags) 1536void cf_object_update (object *op, int flags)
1474 1537
1475void cf_object_pickup (object *op, object *what) 1538void cf_object_pickup (object *op, object *what)
1476 1539
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) 1540object *cf_create_object_by_name (const char *name)
1483 1541
1484void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) 1542void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0)
1485 1543
1486void player_lvl_adj (object *who, object *skill = 0) 1544void player_lvl_adj (object *who, object *skill = 0)
1487 1545
1546int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1488 1547
1489MODULE = cf PACKAGE = cf::object PREFIX = cf_ 1548MODULE = cf PACKAGE = cf::object PREFIX = cf_
1490 1549
1491void cf_fix_object (object *pl) 1550void cf_fix_object (object *pl)
1492 ALIAS: fix = 0 1551 ALIAS: fix = 0
1508 CODE: 1567 CODE:
1509{ 1568{
1510 int unused_type; 1569 int unused_type;
1511 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 1570 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
1512} 1571}
1572
1573# syntatic sugar for easier use in event callbacks.
1574const char *options (object *op)
1575 CODE:
1576 RETVAL = op->name;
1577 OUTPUT:
1578 RETVAL
1513 1579
1514const char *get_ob_key_value (object *op, const char *key) 1580const char *get_ob_key_value (object *op, const char *key)
1515 1581
1516bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) 1582bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1)
1517 1583
1554 1620
1555MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 1621MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
1556 1622
1557player *player (object *op) 1623player *player (object *op)
1558 CODE: 1624 CODE:
1559 RETVAL = cf_player_find (cf_query_name (op)); 1625 RETVAL = op->contr;
1560 OUTPUT: RETVAL 1626 OUTPUT: RETVAL
1561 1627
1562void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) 1628void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1563 1629
1564object *cf_player_send_inventory (object *op) 1630object *cf_player_send_inventory (object *op)
1581 1647
1582void cf_player_set_party (object *op, partylist *party) 1648void cf_player_set_party (object *op, partylist *party)
1583 1649
1584void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) 1650void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0)
1585 1651
1652void kill_player (object *op)
1653
1586MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ 1654MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1587 1655
1588MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 1656MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1589 1657
1590player *cf_player_find (char *name) 1658player *cf_player_find (char *name)
1609 1677
1610player *next (player *pl) 1678player *next (player *pl)
1611 CODE: 1679 CODE:
1612 RETVAL = pl->next; 1680 RETVAL = pl->next;
1613 OUTPUT: RETVAL 1681 OUTPUT: RETVAL
1682
1683bool
1684cell_visible (player *pl, int dx, int dy)
1685 CODE:
1686 RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2
1687 && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2];
1688 OUTPUT:
1689 RETVAL
1690
1691void
1692send (player *pl, SV *packet)
1693 CODE:
1694{
1695 STRLEN len;
1696 char *buf = SvPVbyte (packet, len);
1697
1698 Write_String_To_Socket (&pl->socket, buf, len);
1699}
1700
1701int
1702listening (player *pl, int new_value = -1)
1703 CODE:
1704 RETVAL = pl->listening;
1705 if (new_value >= 0)
1706 pl->listening = new_value;
1707 OUTPUT:
1708 RETVAL
1614 1709
1615void get_savebed (player *pl) 1710void get_savebed (player *pl)
1616 ALIAS: 1711 ALIAS:
1617 savebed = 0 1712 savebed = 0
1618 PPCODE: 1713 PPCODE:
1634 player *pl; 1729 player *pl;
1635 for (pl = first_player; pl; pl = pl->next) 1730 for (pl = first_player; pl; pl = pl->next)
1636 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); 1731 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl));
1637} 1732}
1638 1733
1734bool
1735peaceful (player *pl, bool new_setting = 0)
1736 PROTOTYPE: $;$
1737 CODE:
1738 RETVAL = pl->peaceful;
1739 if (items > 1)
1740 pl->peaceful = new_setting;
1741 OUTPUT:
1742 RETVAL
1743
1639living * 1744living *
1640orig_stats (player *pl) 1745orig_stats (player *pl)
1641 CODE: 1746 CODE:
1642 RETVAL = &pl->orig_stats; 1747 RETVAL = &pl->orig_stats;
1643 OUTPUT: RETVAL 1748 OUTPUT: RETVAL
1683 1788
1684void clean_tmp_map (mapstruct *map) 1789void clean_tmp_map (mapstruct *map)
1685 1790
1686void play_sound_map (mapstruct *map, int x, int y, int sound_num) 1791void play_sound_map (mapstruct *map, int x, int y, int sound_num)
1687 1792
1793mapstruct *tile_map (mapstruct *map, unsigned int dir)
1794 CODE:
1795 RETVAL = dir < 4 ? map->tile_map [dir] : 0;
1796 OUTPUT:
1797 RETVAL
1798
1799char *tile_path (mapstruct *map, unsigned int dir)
1800 CODE:
1801 if (dir >= 4)
1802 XSRETURN_UNDEF;
1803 RETVAL = map->tile_path [dir];
1804 OUTPUT:
1805 RETVAL
1806
1688mapstruct *cf_map_get_map (char *name) 1807mapstruct *cf_map_get_map (char *name)
1689 PROTOTYPE: $ 1808 PROTOTYPE: $
1690 ALIAS: map = 0 1809 ALIAS: map = 0
1691 1810
1811mapstruct *has_been_loaded (char *name)
1812 PROTOTYPE: $
1813
1692mapstruct *cf_map_get_first () 1814mapstruct *cf_map_get_first ()
1693 PROTOTYPE: 1815 PROTOTYPE:
1694 ALIAS: first = 0 1816 ALIAS: first = 0
1695 1817
1696# whoever "designed" the plug-in api should have wasted 1818# whoever "designed" the plug-in api should have wasted
1697# his/her time with staying away form the project - would have 1819# his/her time with staying away from the project - would have
1698# saved others a lot of time, without doubt. 1820# saved others a lot of time, without doubt.
1699void set_path (mapstruct *where, char *path) 1821void set_path (mapstruct *where, char *path)
1700 CODE: 1822 CODE:
1701 strcpy (where->path, path); 1823 strcpy (where->path, path);
1824
1825int in_memory (mapstruct *map)
1826 CODE:
1827 RETVAL = map->in_memory;
1828 OUTPUT:
1829 RETVAL
1702 1830
1703bool unique (mapstruct *map) 1831bool unique (mapstruct *map)
1704 CODE: 1832 CODE:
1705 RETVAL = map->unique; 1833 RETVAL = map->unique;
1706 OUTPUT: 1834 OUTPUT:
1715object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) 1843object *cf_map_insert_object (mapstruct *where, object* op, int x, int y)
1716 1844
1717object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) 1845object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny)
1718 C_ARGS: str, map, nx, ny 1846 C_ARGS: str, map, nx, ny
1719 1847
1720#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1721
1722void 1848void
1849cf_map_normalise (mapstruct *map, int x, int y)
1850 PPCODE:
1851{
1852 mapstruct *nmap = 0;
1853 I16 nx = 0, ny = 0;
1854 int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1855
1856 EXTEND (SP, 4);
1857 PUSHs (sv_2mortal (newSViv (flags)));
1858
1859 if (GIMME_V == G_ARRAY)
1860 {
1861 PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap)));
1862 PUSHs (sv_2mortal (newSViv (nx)));
1863 PUSHs (sv_2mortal (newSViv (ny)));
1864 }
1865}
1866
1867void
1723at (mapstruct *obj, unsigned int x, unsigned int y) 1868at (mapstruct *map, unsigned int x, unsigned int y)
1724 PROTOTYPE: $$$ 1869 PROTOTYPE: $$$
1725 INIT:
1726 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY;
1727 PPCODE: 1870 PPCODE:
1728{ 1871{
1729 object *o; 1872 object *o;
1730 1873 mapstruct *nmap = 0;
1874 I16 nx, ny;
1875
1876 cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1877
1878 if (nmap)
1731 for (o = GET_MAP_OB (obj, x, y); o; o = o->above) 1879 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
1732 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1880 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1733} 1881}
1734 1882
1735SV * 1883SV *
1736bot_at (mapstruct *obj, unsigned int x, unsigned int y) 1884bot_at (mapstruct *obj, unsigned int x, unsigned int y)
1737 PROTOTYPE: $$$ 1885 PROTOTYPE: $$$

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines