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.40 by root, Sun Mar 26 15:52:03 2006 UTC vs.
Revision 1.55 by root, Mon Jun 26 15:40:15 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
65typedef struct 64typedef struct
66{ 65{
67 object* who; 66 object* who;
68 object* activator; 67 object* activator;
69 object* third; 68 object* third;
69 object* event;
70 mapstruct* map; 70 mapstruct* map;
71 char message[1024]; 71 char message[1024];
72 int fix; // seems to be python-only, and should not be part of the API 72 int fix; // seems to be python-only, and should not be part of the API
73 int event_code; 73 int event_code;
74 char extension[1024]; // name field, should invoke specific perl extension 74 char extension[1024]; // name field, should invoke specific perl extension
76 int returnvalue; 76 int returnvalue;
77} CFPContext; 77} CFPContext;
78 78
79static HV *obj_cache; 79static HV *obj_cache;
80static PerlInterpreter *perl; 80static PerlInterpreter *perl;
81
82#define PUSHcfapi(type,value) PUSHs (sv_2mortal (newSVcfapi (CFAPI_ ## type, (value))))
83#define PUSHcfapi_va(type,ctype) PUSHcfapi (type, va_arg (args, ctype))
84#define PUSH_OB PUSHcfapi_va(POBJECT, object *)
85#define PUSH_PL PUSHcfapi_va(PPLAYER, player *)
86#define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *)
87#define PUSH_PV PUSHcfapi_va(STRING, const char *)
88#define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int))))
81 89
82////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 90//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
83 91
84// garbage collect some perl objects, if possible 92// garbage collect some perl objects, if possible
85// all objects no longer referenced and empty are 93// all objects no longer referenced and empty are
221 case CFAPI_LONG: 229 case CFAPI_LONG:
222 sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */ 230 sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */
223 break; 231 break;
224 232
225 case CFAPI_DOUBLE: 233 case CFAPI_DOUBLE:
226 sv = newSViv (*va_arg (args, double *)); 234 sv = newSVnv (*va_arg (args, double *));
227 break; 235 break;
228 236
229 case CFAPI_STRING: 237 case CFAPI_STRING:
230 { 238 {
231 char *str = va_arg (args, char *); 239 char *str = va_arg (args, char *);
238 object *obj = va_arg (args, object *); 246 object *obj = va_arg (args, object *);
239 247
240 if (!obj) 248 if (!obj)
241 sv = &PL_sv_undef; 249 sv = &PL_sv_undef;
242 else 250 else
243 switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) 251 switch (obj->type)
244 { 252 {
245 case MAP: 253 case MAP:
246 sv = newSVptr_cached (obj, "cf::object::map"); 254 sv = newSVptr_cached (obj, "cf::object::map");
247 break; 255 break;
248 256
284 va_end (args); 292 va_end (args);
285 293
286 return sv; 294 return sv;
287} 295}
288 296
289/////////////////////////////////////////////////////////////////////////////
290
291void
292inject_event (const char *func, CFPContext *context)
293{
294 dSP;
295
296 ENTER;
297 SAVETMPS;
298
299 PUSHMARK (SP);
300
301 HV *hv = newHV ();
302#define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0)
303 hv_context (CFAPI_POBJECT, ,who);
304 hv_context (CFAPI_POBJECT, ,activator);
305 hv_context (CFAPI_POBJECT, ,third);
306 hv_context (CFAPI_PMAP, ,map);
307 hv_context (CFAPI_STRING , ,message);
308 hv_context (CFAPI_INT ,&,fix);
309 hv_context (CFAPI_INT ,&,event_code);
310 hv_context (CFAPI_STRING , ,options);
311 hv_context (CFAPI_STRING , ,extension);
312
313 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
314
315 PUTBACK;
316 int count = call_pv (func, G_SCALAR | G_EVAL);
317 SPAGAIN;
318
319 if (SvTRUE (ERRSV))
320 LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV));
321
322 context->returnvalue = count > 0 ? POPi : 0;
323
324 PUTBACK;
325 FREETMPS;
326 LEAVE;
327}
328
329///////////////////////////////////////////////////////////////////////////// 297/////////////////////////////////////////////////////////////////////////////
330 298
331int 299int
332initPlugin (const char *iversion, f_plug_api gethooksptr) 300initPlugin (const char *iversion, f_plug_api gethooksptr)
333{ 301{
459 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); 427 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener);
460 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); 428 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener);
461 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); 429 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener);
462 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); 430 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener);
463 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); 431 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener);
432 registerGlobalEvent (NULL, EVENT_EXTCMD, PLUGIN_NAME, globalEventListener);
464 433
465 char *argv[] = { 434 char *argv[] = {
466 "", 435 "",
467 "-e" 436 "-e"
468 "BEGIN {" 437 "BEGIN {"
474 }; 443 };
475 444
476 perl = perl_alloc (); 445 perl = perl_alloc ();
477 perl_construct (perl); 446 perl_construct (perl);
478 447
448 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
449
479 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 450 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
480 { 451 {
481 printf ("unable to initialize perl-interpreter, continuing without.\n"); 452 printf ("unable to initialize perl-interpreter, continuing without.\n");
482 453
483 perl_destruct (perl); 454 perl_destruct (perl);
494 465
495void * 466void *
496globalEventListener (int *type, ...) 467globalEventListener (int *type, ...)
497{ 468{
498 va_list args; 469 va_list args;
499 static int rv = 0; 470 static int rv;
500 CFPContext context; 471 int event_code;
501 char *buf;
502 player *pl;
503 object *op;
504 472
505 if (!perl) 473 if (!perl)
506 return; 474 return;
507 475
508 memset (&context, 0, sizeof (context));
509
510 va_start (args, type); 476 va_start (args, type);
511 context.event_code = va_arg (args, int); 477 event_code = va_arg (args, int);
512 478
513 switch (context.event_code) 479 if (event_code == EVENT_FREE_OB)
514 { 480 {
515 case EVENT_CRASH: 481 player *pl;
516 printf ("Unimplemented for now\n"); 482 object *op;
517 break; 483 SV *sv;
518 484
519 case EVENT_PLAYER_LOAD:
520 case EVENT_PLAYER_SAVE:
521 context.who = va_arg (args, object *); 485 op = va_arg (args, object *);
522 buf = va_arg (args, char *);
523 if (buf != 0)
524 strncpy (context.message, buf, sizeof (context.message));
525 break;
526
527 case EVENT_MAPLOAD:
528 case EVENT_MAPOUT:
529 case EVENT_MAPIN:
530 case EVENT_MAPCLEAN:
531 context.map = va_arg (args, mapstruct *);
532 break;
533
534 case EVENT_MAPENTER:
535 case EVENT_MAPLEAVE:
536 case EVENT_FREE_OB:
537 case EVENT_BORN:
538 case EVENT_REMOVE:
539 context.activator = va_arg (args, object *);
540 break;
541
542 case EVENT_PLAYER_DEATH:
543 context.who = va_arg (args, object *);
544 break;
545
546 case EVENT_GKILL:
547 context.who = va_arg (args, object *);
548 context.activator = va_arg (args, object *);
549 break;
550
551 case EVENT_LOGIN:
552 case EVENT_LOGOUT:
553 pl = va_arg (args, player *);
554 context.activator = pl->ob;
555 buf = va_arg (args, char *);
556 if (buf != 0)
557 strncpy (context.message, buf, sizeof (context.message));
558 break;
559
560 case EVENT_SHOUT:
561 case EVENT_MUZZLE:
562 case EVENT_KICK:
563 context.activator = va_arg (args, object *);
564 buf = va_arg (args, char *);
565 if (buf != 0)
566 strncpy (context.message, buf, sizeof (context.message));
567 break;
568
569 case EVENT_CLOCK:
570 clean_obj_cache ();
571 break;
572
573 case EVENT_TELL:
574 break;
575
576 case EVENT_MAPRESET:
577 /* stupid, should be the map itself, not "message"??? */
578 buf = va_arg (args, char *);
579 if (buf != 0)
580 strncpy (context.message, buf, sizeof (context.message));
581 break;
582 }
583
584 va_end (args);
585
586 if (context.event_code == EVENT_FREE_OB)
587 {
588 SV *sv = hv_delete (obj_cache, (char *)&context.activator, sizeof (void *), 0); 486 sv = hv_delete (obj_cache, (char *)&op, sizeof (void *), 0);
589 487
590 if (sv) 488 if (sv)
591 clearSVptr (sv); 489 clearSVptr (sv);
490
491 rv = 0;
592 } 492 }
593 else 493 else
594 inject_event ("cf::inject_global_event", &context); 494 {
595 495 dSP;
596 rv = context.returnvalue; 496
497 ENTER;
498 SAVETMPS;
499
500 PUSHMARK (SP);
501
502 EXTEND (SP, 10);
503 PUSHs (sv_2mortal (newSViv (event_code)));
504
505 switch (event_code)
506 {
507 case EVENT_CRASH:
508 break;
509
510 case EVENT_PLAYER_LOAD:
511 case EVENT_PLAYER_SAVE:
512 PUSH_OB;
513 PUSH_PV;
514 break;
515
516 case EVENT_MAPLOAD:
517 case EVENT_MAPOUT:
518 case EVENT_MAPIN:
519 case EVENT_MAPCLEAN:
520 case EVENT_MAPRESET:
521 PUSH_MAP;
522 break;
523
524 case EVENT_MAPENTER:
525 case EVENT_MAPLEAVE:
526 case EVENT_BORN:
527 case EVENT_REMOVE:
528 case EVENT_PLAYER_DEATH:
529 PUSH_OB;
530 break;
531
532 case EVENT_GKILL:
533 PUSH_OB;
534 PUSH_OB;
535 break;
536
537 case EVENT_LOGIN:
538 case EVENT_LOGOUT:
539 PUSH_PL;
540 PUSH_PV;
541 break;
542
543 case EVENT_SHOUT:
544 case EVENT_MUZZLE:
545 case EVENT_KICK:
546 PUSH_OB;
547 PUSH_PV;
548 break;
549
550 case EVENT_EXTCMD:
551 PUSH_PL;
552 {
553 char *buf = va_arg (args, char *);
554 int len = va_arg (args, int);
555 PUSHs (sv_2mortal (newSVpvn (buf, len)));
556 }
557 break;
558
559 case EVENT_CLOCK:
560 clean_obj_cache ();
561 break;
562
563 case EVENT_TELL:
564 break;
565 }
566
567 va_end (args);
568
569 PUTBACK;
570 int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL);
571 SPAGAIN;
572
573 if (SvTRUE (ERRSV))
574 LOG (llevError, "global event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV));
575
576 rv = count > 0 ? POPi : 0;
577
578 PUTBACK;
579 FREETMPS;
580 LEAVE;
581 }
597 582
598 return &rv; 583 return &rv;
599} 584}
600 585
601void * 586void *
602eventListener (int *type, ...) 587eventListener (int *type, ...)
603{ 588{
604 static int rv = 0; 589 static int rv;
605 va_list args; 590 va_list args;
606 char *buf; 591 int event_code;
607 CFPContext context; 592 object *who, *activator, *third, *event;
593 char *message, *extension, *options;
608 594
609 if (!perl) 595 if (!perl)
610 return; 596 return;
611 597
612 memset (&context, 0, sizeof (context));
613
614 va_start (args, type); 598 va_start (args, type);
615
616 context.who = va_arg (args, object *); 599 who = va_arg (args, object *);
617 context.event_code = va_arg (args, int); 600 event_code = va_arg (args, int);
618 context.activator = va_arg (args, object *); 601 activator = va_arg (args, object *);
619 context.third = va_arg (args, object *); 602 third = va_arg (args, object *);
620
621 buf = va_arg (args, char *); 603 message = va_arg (args, char *);
622 if (buf != 0) 604 va_arg (args, int); // fix yourself
623 strncpy (context.message, buf, sizeof (context.message)); 605 extension = va_arg (args, char *);
624 606 options = va_arg (args, char *);
625 context.fix = va_arg (args, int); 607 event = va_arg (args, object *);
626 strncpy (context.extension, va_arg (args, char *), sizeof (context.extension));
627 strncpy (context.options, va_arg (args, char *), sizeof (context.options));
628 context.returnvalue = 0;
629 va_end (args); 608 va_end (args);
630 609
631 inject_event ("cf::inject_event", &context); 610 {
611 dSP;
612
613 ENTER;
614 SAVETMPS;
615
616 PUSHMARK (SP);
617 EXTEND (SP, 10);
618
619 PUSHcfapi (STRING, extension);
620 PUSHs (sv_2mortal (newSViv (event_code)));
621
622 PUSHcfapi (POBJECT, event);
623 PUSHcfapi (POBJECT, who);
624
625 switch (event_code)
626 {
627 case EVENT_STOP: // $ob (e.g. arrow)
628 case EVENT_TIME: // $ob
629 case EVENT_TIMER: // $ob
630 break;
631
632 case EVENT_APPLY: // $ob, $who
633 case EVENT_DROP: // $ob, $who
634 case EVENT_CLOSE: // $ob, $who
635 case EVENT_DEATH: // $ob[, $killer]
636 case EVENT_MOVE: // $ob, $enemy
637 case EVENT_THROW: // $ob, $thrower
638 PUSHcfapi (POBJECT, activator);
639 break;
640
641 case EVENT_ATTACK: // $ob, $who, $victim (?? please god enlighten me)
642 PUSHcfapi (POBJECT, activator);
643 PUSHcfapi (POBJECT, third);
644 break;
645
646 case EVENT_TRIGGER: // $ob, $originator, [$victim], [$msg]
647 PUSHcfapi (POBJECT, activator);
648 PUSHcfapi (POBJECT, third);
649 PUSHcfapi (POBJECT, message);
650 break;
651
652 case EVENT_SAY: // $ob, $who, $msg
653 PUSHcfapi (POBJECT, activator);
654 PUSHcfapi (STRING, message);
655 break;
656
657 default:
658 LOG (llevError, "perl plugin called for unsupported event type %d", event_code);
659 break;
660 }
661
662 PUTBACK;
663 int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL);
664 SPAGAIN;
665
666 if (SvTRUE (ERRSV))
667 LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV));
668
669 rv = count > 0 ? POPi : 0;
670
671 PUTBACK;
672 FREETMPS;
673 LEAVE;
674 }
632 675
633 rv = context.returnvalue;
634 return &rv; 676 return &rv;
635} 677}
636 678
637int 679int
638closePlugin () 680closePlugin ()
1058 const_iv (SK_SUMMONING) 1100 const_iv (SK_SUMMONING)
1059 const_iv (SK_PYROMANCY) 1101 const_iv (SK_PYROMANCY)
1060 const_iv (SK_EVOCATION) 1102 const_iv (SK_EVOCATION)
1061 const_iv (SK_SORCERY) 1103 const_iv (SK_SORCERY)
1062 const_iv (SK_TWO_HANDED_WEAPON) 1104 const_iv (SK_TWO_HANDED_WEAPON)
1105 const_iv (SK_SPARK_TOUCH)
1106 const_iv (SK_SHIVER)
1107 const_iv (SK_ACID_SPLASH)
1108 const_iv (SK_POISON_NAIL)
1063 1109
1064 const_iv (SOUND_NEW_PLAYER) 1110 const_iv (SOUND_NEW_PLAYER)
1065 const_iv (SOUND_FIRE_ARROW) 1111 const_iv (SOUND_FIRE_ARROW)
1066 const_iv (SOUND_LEARN_SPELL) 1112 const_iv (SOUND_LEARN_SPELL)
1067 const_iv (SOUND_FUMBLE_SPELL) 1113 const_iv (SOUND_FUMBLE_SPELL)
1083 const_iv (SOUND_CLOCK) 1129 const_iv (SOUND_CLOCK)
1084 const_iv (SOUND_TURN_HANDLE) 1130 const_iv (SOUND_TURN_HANDLE)
1085 const_iv (SOUND_FALL_HOLE) 1131 const_iv (SOUND_FALL_HOLE)
1086 const_iv (SOUND_DRINK_POISON) 1132 const_iv (SOUND_DRINK_POISON)
1087 const_iv (SOUND_CAST_SPELL_0) 1133 const_iv (SOUND_CAST_SPELL_0)
1134
1135 const_iv (MAP_FLUSH)
1136 const_iv (MAP_PLAYER_UNIQUE)
1137 const_iv (MAP_BLOCK)
1138 const_iv (MAP_STYLE)
1139 const_iv (MAP_OVERLAY)
1140
1141 const_iv (MAP_IN_MEMORY)
1142 const_iv (MAP_SWAPPED)
1143 const_iv (MAP_LOADING)
1144 const_iv (MAP_SAVING)
1088 }; 1145 };
1089 1146
1090 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1147 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1091 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1148 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1092 1149
1129 const_event (REMOVE) 1186 const_event (REMOVE)
1130 const_event (SHOUT) 1187 const_event (SHOUT)
1131 const_event (TELL) 1188 const_event (TELL)
1132 const_event (MUZZLE) 1189 const_event (MUZZLE)
1133 const_event (KICK) 1190 const_event (KICK)
1191 const_event (EXTCMD)
1134 //const_event (FREE_OB) 1192 //const_event (FREE_OB)
1135 }; 1193 };
1136 1194
1137 AV *av = get_av ("cf::EVENT", 1); 1195 AV *av = get_av ("cf::EVENT", 1);
1138 1196
1279void 1337void
1280LOG (int level, char *msg) 1338LOG (int level, char *msg)
1281 PROTOTYPE: $$ 1339 PROTOTYPE: $$
1282 C_ARGS: level, "%s", msg 1340 C_ARGS: level, "%s", msg
1283 1341
1342char *path_combine (char *base, char *path)
1343 PROTOTYPE: $$
1344
1345char *path_combine_and_normalize (char *base, char *path)
1346 PROTOTYPE: $$
1347
1284char * 1348char *
1285cf_get_maps_directory (char *path) 1349cf_get_maps_directory (char *path)
1286 PROTOTYPE: $ 1350 PROTOTYPE: $
1287 ALIAS: maps_directory = 0 1351 ALIAS: maps_directory = 0
1288 1352
1456 1520
1457void cf_object_update (object *op, int flags) 1521void cf_object_update (object *op, int flags)
1458 1522
1459void cf_object_pickup (object *op, object *what) 1523void cf_object_pickup (object *op, object *what)
1460 1524
1461char *cf_object_get_key (object *op, char *keyname)
1462 ALIAS: key = 0
1463
1464void cf_object_set_key (object *op, char *keyname, char *value)
1465
1466object *cf_create_object_by_name (const char *name) 1525object *cf_create_object_by_name (const char *name)
1467 1526
1468void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) 1527void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0)
1469 1528
1470void player_lvl_adj (object *who, object *skill = 0) 1529void player_lvl_adj (object *who, object *skill = 0)
1471 1530
1531int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1472 1532
1473MODULE = cf PACKAGE = cf::object PREFIX = cf_ 1533MODULE = cf PACKAGE = cf::object PREFIX = cf_
1474 1534
1475void cf_fix_object (object *pl) 1535void cf_fix_object (object *pl)
1476 ALIAS: fix = 0 1536 ALIAS: fix = 0
1492 CODE: 1552 CODE:
1493{ 1553{
1494 int unused_type; 1554 int unused_type;
1495 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 1555 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
1496} 1556}
1557
1558# syntatic sugar for easier use in event callbacks.
1559const char *options (object *op)
1560 CODE:
1561 RETVAL = op->name;
1562 OUTPUT:
1563 RETVAL
1497 1564
1498const char *get_ob_key_value (object *op, const char *key) 1565const char *get_ob_key_value (object *op, const char *key)
1499 1566
1500bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) 1567bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1)
1501 1568
1538 1605
1539MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 1606MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
1540 1607
1541player *player (object *op) 1608player *player (object *op)
1542 CODE: 1609 CODE:
1543 RETVAL = cf_player_find (cf_query_name (op)); 1610 RETVAL = op->contr;
1544 OUTPUT: RETVAL 1611 OUTPUT: RETVAL
1545 1612
1546void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) 1613void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1547 1614
1548object *cf_player_send_inventory (object *op) 1615object *cf_player_send_inventory (object *op)
1565 1632
1566void cf_player_set_party (object *op, partylist *party) 1633void cf_player_set_party (object *op, partylist *party)
1567 1634
1568void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) 1635void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0)
1569 1636
1637void kill_player (object *op)
1638
1570MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ 1639MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1571 1640
1572MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 1641MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1573 1642
1574player *cf_player_find (char *name) 1643player *cf_player_find (char *name)
1593 1662
1594player *next (player *pl) 1663player *next (player *pl)
1595 CODE: 1664 CODE:
1596 RETVAL = pl->next; 1665 RETVAL = pl->next;
1597 OUTPUT: RETVAL 1666 OUTPUT: RETVAL
1667
1668bool
1669cell_visible (player *pl, int dx, int dy)
1670 CODE:
1671 RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2
1672 && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2];
1673 OUTPUT:
1674 RETVAL
1675
1676void
1677send (player *pl, SV *packet)
1678 CODE:
1679{
1680 STRLEN len;
1681 char *buf = SvPVbyte (packet, len);
1682
1683 Write_String_To_Socket (&pl->socket, buf, len);
1684}
1685
1686int
1687listening (player *pl, int new_value = -1)
1688 CODE:
1689 RETVAL = pl->listening;
1690 if (new_value >= 0)
1691 pl->listening = new_value;
1692 OUTPUT:
1693 RETVAL
1598 1694
1599void get_savebed (player *pl) 1695void get_savebed (player *pl)
1600 ALIAS: 1696 ALIAS:
1601 savebed = 0 1697 savebed = 0
1602 PPCODE: 1698 PPCODE:
1618 player *pl; 1714 player *pl;
1619 for (pl = first_player; pl; pl = pl->next) 1715 for (pl = first_player; pl; pl = pl->next)
1620 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); 1716 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl));
1621} 1717}
1622 1718
1719bool
1720peaceful (player *pl, bool new_setting = 0)
1721 PROTOTYPE: $;$
1722 CODE:
1723 RETVAL = pl->peaceful;
1724 if (items > 1)
1725 pl->peaceful = new_setting;
1726 OUTPUT:
1727 RETVAL
1728
1623living * 1729living *
1624orig_stats (player *pl) 1730orig_stats (player *pl)
1625 CODE: 1731 CODE:
1626 RETVAL = &pl->orig_stats; 1732 RETVAL = &pl->orig_stats;
1627 OUTPUT: RETVAL 1733 OUTPUT: RETVAL
1671 1777
1672mapstruct *cf_map_get_map (char *name) 1778mapstruct *cf_map_get_map (char *name)
1673 PROTOTYPE: $ 1779 PROTOTYPE: $
1674 ALIAS: map = 0 1780 ALIAS: map = 0
1675 1781
1782mapstruct *has_been_loaded (char *name)
1783 PROTOTYPE: $
1784
1676mapstruct *cf_map_get_first () 1785mapstruct *cf_map_get_first ()
1677 PROTOTYPE: 1786 PROTOTYPE:
1678 ALIAS: first = 0 1787 ALIAS: first = 0
1679 1788
1680# whoever "designed" the plug-in api should have wasted 1789# whoever "designed" the plug-in api should have wasted
1681# his/her time with staying away form the project - would have 1790# his/her time with staying away from the project - would have
1682# saved others a lot of time, without doubt. 1791# saved others a lot of time, without doubt.
1683void set_path (mapstruct *where, char *path) 1792void set_path (mapstruct *where, char *path)
1684 CODE: 1793 CODE:
1685 strcpy (where->path, path); 1794 strcpy (where->path, path);
1795
1796int in_memory (mapstruct *map)
1797 CODE:
1798 RETVAL = map->in_memory;
1799 OUTPUT:
1800 RETVAL
1686 1801
1687bool unique (mapstruct *map) 1802bool unique (mapstruct *map)
1688 CODE: 1803 CODE:
1689 RETVAL = map->unique; 1804 RETVAL = map->unique;
1690 OUTPUT: 1805 OUTPUT:
1699object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) 1814object *cf_map_insert_object (mapstruct *where, object* op, int x, int y)
1700 1815
1701object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) 1816object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny)
1702 C_ARGS: str, map, nx, ny 1817 C_ARGS: str, map, nx, ny
1703 1818
1704#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1705
1706void 1819void
1820cf_map_normalise (mapstruct *map, int x, int y)
1821 PPCODE:
1822{
1823 mapstruct *nmap = 0;
1824 I16 nx = 0, ny = 0;
1825 int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1826
1827 EXTEND (SP, 4);
1828 PUSHs (sv_2mortal (newSViv (flags)));
1829
1830 if (GIMME_V == G_ARRAY)
1831 {
1832 PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap)));
1833 PUSHs (sv_2mortal (newSViv (nx)));
1834 PUSHs (sv_2mortal (newSViv (ny)));
1835 }
1836}
1837
1838void
1707at (mapstruct *obj, unsigned int x, unsigned int y) 1839at (mapstruct *map, unsigned int x, unsigned int y)
1708 PROTOTYPE: $$$ 1840 PROTOTYPE: $$$
1709 INIT:
1710 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY;
1711 PPCODE: 1841 PPCODE:
1712{ 1842{
1713 object *o; 1843 object *o;
1714 1844 mapstruct *nmap = 0;
1845 I16 nx, ny;
1846
1847 cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1848
1849 if (nmap)
1715 for (o = GET_MAP_OB (obj, x, y); o; o = o->above) 1850 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
1716 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1851 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1717} 1852}
1718 1853
1719SV * 1854SV *
1720bot_at (mapstruct *obj, unsigned int x, unsigned int y) 1855bot_at (mapstruct *obj, unsigned int x, unsigned int y)
1721 PROTOTYPE: $$$ 1856 PROTOTYPE: $$$

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines