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

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.41 by root, Sun Sep 3 22:45:57 2006 UTC vs.
Revision 1.85 by root, Sat Dec 16 03:08:26 2006 UTC

4 4
5/* 5/*
6 * This code is placed under the GNU General Public Licence (GPL) 6 * This code is placed under the GNU General Public Licence (GPL)
7 * 7 *
8 * Copyright (C) 2001-2005 by Chachkoff Yann 8 * Copyright (C) 2001-2005 by Chachkoff Yann
9 * Copyright (C) 2006 by Marc Lehmann <cf@schmorpd.e> 9 * Copyright (C) 2006 by Marc Lehmann <cf@schmorp.de>
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. 14 * (at your option) any later version.
40 40
41#include "perlxsi.c" 41#include "perlxsi.c"
42 42
43extern sint64 *levels; // the experience table 43extern sint64 *levels; // the experience table
44 44
45typedef object object_ornull; 45typedef object object_ornull;
46typedef mapstruct mapstruct_ornull; 46typedef maptile maptile_ornull;
47 47
48#if IVSIZE >= 8
49 typedef IV val64;
50# define newSVval64 newSViv
51# define SvVAL64 SvIV
52#else
48typedef double val64; 53 typedef double val64;
49#define newSVval64 newSVnv 54# define newSVval64 newSVnv
50#define SvVAL64 SvNV 55# define SvVAL64 SvNV
56#endif
51 57
52static f_plug_api gethook = cfapi_get_hooks; 58static f_plug_api gethook = cfapi_get_hooks;
53static f_plug_api object_set_property = cfapi_object_set_property; 59static f_plug_api object_set_property = cfapi_object_set_property;
54static f_plug_api object_insert = cfapi_object_insert; 60static f_plug_api object_insert = cfapi_object_insert;
55 61
56/* this is a stupid way to do things, and awkward to use for plug-in authors */
57typedef struct
58{
59 object* who;
60 object* activator;
61 object* third;
62 object* event;
63 mapstruct* map;
64 char message[1024];
65 int fix; // seems to be python-only, and should not be part of the API
66 int event_code;
67 char extension[1024]; // name field, should invoke specific perl extension
68 char options[1024]; // slaying field of event_connectors
69 int returnvalue;
70} CFPContext;
71
72static HV *obj_cache;
73static PerlInterpreter *perl; 62static PerlInterpreter *perl;
74 63
75static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; 64static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map;
76
77#define PUSHcfapi(type,value) PUSHs (sv_2mortal (newSVcfapi (CFAPI_ ## type, (value))))
78#define PUSHcfapi_va(type,ctype) PUSHcfapi (type, va_arg (args, ctype))
79#define PUSH_OB PUSHcfapi_va(POBJECT, object *)
80#define PUSH_PL PUSHcfapi_va(PPLAYER, player *)
81#define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *)
82#define PUSH_PV PUSHcfapi_va(STRING, const char *)
83#define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int))))
84 65
85////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 66//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86 67
87static SV * 68static SV *
88newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) 69newSVptr (void *ptr, const char *klass, HV *hv = newHV ())
105 86
106 if (!obj->self) 87 if (!obj->self)
107 obj->self = newSVptr (obj, klass); 88 obj->self = newSVptr (obj, klass);
108 89
109 return newSVsv (obj->self); 90 return newSVsv (obj->self);
110}
111
112static void
113SVptr_cache_set (void *ptr, SV *sv)
114{
115 hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0);
116}
117
118static SV *
119SVptr_cache_get (void *ptr)
120{
121 SV **he = hv_fetch (obj_cache, (char *)&ptr, sizeof (ptr), 0);
122
123 return he ? *he : 0;
124}
125
126static SV *
127newSVptr_cached (void *ptr, const char *klass)
128{
129 SV *sv;
130
131 if (!ptr)
132 return &PL_sv_undef;
133
134 sv = SVptr_cache_get (ptr);
135
136 if (!sv)
137 {
138 HV *hv = newHV ();
139 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
140 sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
141
142 SVptr_cache_set (ptr, sv);
143 }
144
145 return newSVsv (sv);
146} 91}
147 92
148static void 93static void
149clearSVptr (SV *sv) 94clearSVptr (SV *sv)
150{ 95{
174{ 119{
175 if (SvOK (sv)) 120 if (SvOK (sv))
176 return SvPTR (sv, klass); 121 return SvPTR (sv, klass);
177 else 122 else
178 return 0; 123 return 0;
124}
125
126inline SV *to_sv (const shstr & v) { return v ? newSVpvn ((const char *)v, v.length ()) : &PL_sv_undef; }
127inline SV *to_sv (const char * v) { return newSVpv (v, 0); }
128inline SV *to_sv (bool v) { return newSViv (v); }
129inline SV *to_sv ( signed char v) { return newSViv (v); }
130inline SV *to_sv (unsigned char v) { return newSViv (v); }
131inline SV *to_sv ( signed short v) { return newSViv (v); }
132inline SV *to_sv (unsigned short v) { return newSVuv (v); }
133inline SV *to_sv ( signed int v) { return newSViv (v); }
134inline SV *to_sv (unsigned int v) { return newSVuv (v); }
135inline SV *to_sv ( signed long v) { return newSViv (v); }
136inline SV *to_sv (unsigned long v) { return newSVuv (v); }
137inline SV *to_sv ( signed long long v) { return newSVval64 (v); }
138inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
139inline SV *to_sv (float v) { return newSVnv (v); }
140inline SV *to_sv (double v) { return newSVnv (v); }
141inline SV *to_sv (client * v) { return newSVattachable (v, "cf::client::wrap"); }
142inline SV *to_sv (player * v) { return newSVattachable (v, "cf::player::wrap"); }
143inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); }
144inline SV *to_sv (maptile * v) { return newSVattachable (v, "cf::map::wrap"); }
145inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); }
146inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); }
147inline SV *to_sv (region * v) { return newSVptr (v, "cf::region::wrap"); }
148inline SV *to_sv (living * v) { return newSVptr (v, "cf::living::wrap"); }
149
150inline SV *to_sv (object & v) { return to_sv (&v); }
151inline SV *to_sv (living & v) { return to_sv (&v); }
152
153//TODO:
154inline SV *to_sv (New_Face * v) { return to_sv (v->name); }
155inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
156
157inline SV *to_sv (UUID v)
158{
159 char buf[128];
160 snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq);
161 return newSVpv (buf, 0);
162}
163
164inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; }
165inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
166inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
167inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); }
168inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); }
169inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); }
170inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); }
171inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); }
172inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); }
173inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); }
174inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
175inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
176inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
177inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
178inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
179inline void sv_to (SV *sv, client * &v) { v = (client *)SvPTR_ornull (sv, "cf::client"); }
180inline void sv_to (SV *sv, player * &v) { v = (player *)SvPTR_ornull (sv, "cf::player"); }
181inline void sv_to (SV *sv, object * &v) { v = (object *)SvPTR_ornull (sv, "cf::object"); }
182inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)SvPTR_ornull (sv, "cf::arch"); }
183inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)SvPTR_ornull (sv, "cf::map"); }
184inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
185inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
186inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
187
188inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO
189inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } // TODO
190
191template<class T>
192inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
193
194template<int N>
195inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
196
197inline void sv_to (SV *sv, UUID &v)
198{
199 unsigned int version;
200
201 if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version)
202 croak ("unparsable uuid: %s", SvPV_nolen (sv));
179} 203}
180 204
181static SV * 205static SV *
182newSVdt_va (va_list &ap, data_type type) 206newSVdt_va (va_list &ap, data_type type)
183{ 207{
211 sv = str ? newSVpv (str, len) : &PL_sv_undef; 235 sv = str ? newSVpv (str, len) : &PL_sv_undef;
212 } 236 }
213 break; 237 break;
214 238
215 case DT_OBJECT: 239 case DT_OBJECT:
216 { 240 sv = to_sv (va_arg (ap, object *));
217 object *obj = va_arg (ap, object *);
218 sv = newSVattachable (obj, obj && obj->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap");
219 }
220 break; 241 break;
221 242
222 case DT_MAP: 243 case DT_MAP:
223 // va_arg (object *) when void * is passed is an XSI extension 244 // va_arg (object *) when void * is passed is an XSI extension
224 sv = newSVattachable (va_arg (ap, mapstruct *), "cf::map::wrap"); 245 sv = to_sv (va_arg (ap, maptile *));
225 break; 246 break;
226 247
248 case DT_SOCKET:
249 sv = to_sv (va_arg (ap, client *));
250 break;
251
227 case DT_PLAYER: 252 case DT_PLAYER:
228 sv = newSVattachable (va_arg (ap, player *), "cf::player::wrap"); 253 sv = to_sv (va_arg (ap, player *));
229 break; 254 break;
230 255
231 case DT_ARCH: 256 case DT_ARCH:
232 sv = newSVptr (va_arg (ap, archetype *), "cf::arch::wrap"); 257 sv = to_sv (va_arg (ap, archetype *));
233 break; 258 break;
234 259
235 case DT_PARTY: 260 case DT_PARTY:
236 sv = newSVptr (va_arg (ap, partylist *), "cf::party::wrap"); 261 sv = to_sv (va_arg (ap, partylist *));
237 break; 262 break;
238 263
239 case DT_REGION: 264 case DT_REGION:
240 sv = newSVptr (va_arg (ap, region *), "cf::region::wrap"); 265 sv = to_sv (va_arg (ap, region *));
241 break; 266 break;
242 267
243 default: 268 default:
244 assert (("unhandled type in newSVdt_va", 0)); 269 assert (("unhandled type in newSVdt_va", 0));
245 } 270 }
290} 315}
291 316
292////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 317//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
293 318
294SV * 319SV *
295registry_of (attachable_base *ext) 320registry (attachable_base *ext)
296{ 321{
297 if (!ext->cb) 322 if (!ext->cb)
298 ext->cb = newAV (); 323 ext->cb = newAV ();
299 324
300 return newRV_inc ((SV *)ext->cb); 325 return newRV_inc ((SV *)ext->cb);
306 { 331 {
307 if (cb) 332 if (cb)
308 if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) 333 if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1)))
309 INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); 334 INVOKE_OBJECT (DESTROY, static_cast<object *>(this));
310 else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) 335 else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1)))
311 INVOKE_MAP (DESTROY, static_cast<mapstruct *>(this)); 336 INVOKE_MAP (DESTROY, static_cast<maptile *>(this));
312 337
313 // disconnect Perl from C, to avoid crashes 338 // disconnect Perl from C, to avoid crashes
314 sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); 339 sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext);
315 340
316 // clear the perl hash, might or might not be a good idea 341 // clear the perl hash, might or might not be a good idea
444 call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); 469 call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL);
445 FREETMPS; 470 FREETMPS;
446 LEAVE; 471 LEAVE;
447} 472}
448 473
474char *object_freezer::as_string ()
475{
476 dSP;
477 ENTER;
478 SAVETMPS;
479 PUSHMARK (SP);
480 EXTEND (SP, 3);
481 PUSHs (sv_2mortal (newRV_noinc (newSVpvn ((char *)linearise (), size ()))));
482 PUSHs (sv_2mortal (newRV_inc ((SV *)av)));
483 PUTBACK;
484
485 char *res = call_pv ("cf::object_freezer_as_string", G_SCALAR | G_EVAL) > 0
486 ? strdup (SvPVbyte_nolen (POPs))
487 : strdup ("[fatal error]");
488
489 FREETMPS;
490 LEAVE;
491
492 return res;
493}
494
449int fprintf (object_freezer &freezer, const char *format, ...) 495int fprintf (object_freezer &freezer, const char *format, ...)
450{ 496{
451 va_list ap; 497 va_list ap;
452 498
453 va_start (ap, format); 499 va_start (ap, format);
463int fputs (const char *s, object_freezer &freezer) 509int fputs (const char *s, object_freezer &freezer)
464{ 510{
465 freezer.add (s); 511 freezer.add (s);
466} 512}
467 513
514static const char thawer_eof[] = "\n\n\n\0\0\0";
515
468object_thawer::object_thawer (const char *filename) 516object_thawer::object_thawer (const char *filename)
469{ 517{
470 static const char eof[] = "\n\n\n\0\0\0"; 518 static const char eof[] = "\n\n\n\0\0\0";
471 519
472 av = 0; 520 av = 0;
473 text = 0; 521 text = 0;
522 line = 0;
474 523
475 if (filename) 524 if (filename)
476 { 525 {
477 dSP; 526 dSP;
478 ENTER; 527 ENTER;
499 char *sv_ = SvPVbyte (sv, len); 548 char *sv_ = SvPVbyte (sv, len);
500 text = newSV (len + sizeof (eof)); 549 text = newSV (len + sizeof (eof));
501 SvCUR_set (text, len); 550 SvCUR_set (text, len);
502 memcpy (SvPVX (text), sv_, len); 551 memcpy (SvPVX (text), sv_, len);
503 memcpy (SvEND (text), eof, sizeof (eof)); // just to be sure 552 memcpy (SvEND (text), eof, sizeof (eof)); // just to be sure
553
554 line = SvPVX (text);
504 } 555 }
505 } 556 }
506 557
507 PUTBACK; 558 PUTBACK;
508 FREETMPS; 559 FREETMPS;
509 LEAVE; 560 LEAVE;
510 } 561 }
562}
511 563
512 if (!text) 564object_thawer::object_thawer (const char *data, AV *perlav)
513 text = newSVpvn (eof, sizeof (eof)); 565{
514 566 av = perlav;
567 text = newSVpv (data, 0);
568 sv_catpv (text, thawer_eof);
515 line = SvPVX (text); 569 line = SvPVbyte_nolen (text);
516} 570}
517 571
518void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) 572void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid)
519{ 573{
520 if (!av || oid < 0) // this is actually an error of sorts 574 if (!av || oid < 0) // this is actually an error of sorts
546char *fgets (char *s, int n, object_thawer &thawer) 600char *fgets (char *s, int n, object_thawer &thawer)
547{ 601{
548 char *p = thawer.line; 602 char *p = thawer.line;
549 char *q = s; 603 char *q = s;
550 604
605 if (!p)
606 return 0;
607
551 while (--n) 608 while (--n)
552 { 609 {
553 if (!*p) 610 if (!*p)
554 break; 611 break;
555 612
565 return s == q ? 0 : s; 622 return s == q ? 0 : s;
566} 623}
567 624
568keyword object_thawer::get_kv () 625keyword object_thawer::get_kv ()
569{ 626{
627 if (!line)
628 return KW_EOF;
629
570 for (;;) 630 for (;;)
571 { 631 {
572 char *p = line; 632 char *p = line;
573 633
574 if (!*p) 634 if (!*p)
581 int klen = p - line; 641 int klen = p - line;
582 642
583 if (*p++ != '\n') 643 if (*p++ != '\n')
584 { 644 {
585 // parse value 645 // parse value
586 while (*p <= ' ' && *p != '\n') // skip 0x01 .. 0x20 646 while (*(unsigned char *)p <= ' ' && *p != '\n') // skip 0x01 .. 0x20
587 ++p; 647 ++p;
588 648
589 last_value = p; 649 last_value = p;
590 650
591 while (*p != '\n') 651 while (*p != '\n')
629 689
630void object_thawer::get_ml (keyword kend, shstr &sh) 690void object_thawer::get_ml (keyword kend, shstr &sh)
631{ 691{
632 char kw[128]; 692 char kw[128];
633 693
634 // multi-line strings are delimited by "\nendXXX\n" 694 int klen = keyword_len [kend];
695
635 kw [0] = '\n'; 696 kw [0] = '\n';
636 strcpy (kw + 1, keyword_str [kend]); 697 memcpy (kw + 1, keyword_str [kend], klen);
698 kw [klen + 1] = '\n';
699 kw [klen + 2] = 0;
637 700
638 char *end = strstr (line, kw); 701 // first test for completely empty msg... "endXXX\n"
639 702 if (!strncmp (line, kw + 1, klen + 1))
640 if (!end)
641 { 703 {
642 sh = 0; 704 sh = 0;
705
706 line += klen + 1;
707
643 return; 708 return;
644 } 709 }
710 else
711 {
712 // multi-line strings are delimited by "\nendXXX\n" or "endXXX\n" (NULL)
645 713
714 char *end = strstr (line, kw);
715
716 if (!end)
717 {
718 sh = 0;
719 return;
720 }
721
646 *end = 0; 722 *end = 0;
647 sh = line; 723 sh = line;
648 724
649 line = end + keyword_len [kend] + 1; 725 line = end + keyword_len [kend] + 1;
650 726
651 while (*line++ != '\n') 727 while (*line++ != '\n')
728 ;
652 ; 729 }
653} 730}
654 731
655sint32 object_thawer::get_sint32 () const 732sint32 object_thawer::get_sint32 () const
656{ 733{
657 char *p = last_value; 734 char *p = last_value;
700static CommArray_s rtn_cmd; 777static CommArray_s rtn_cmd;
701 778
702static int 779static int
703runPluginCommand (object *obj, char *params) 780runPluginCommand (object *obj, char *params)
704{ 781{
705 dSP; 782 return -1;
706
707 ENTER;
708 SAVETMPS;
709
710 PUSHMARK (SP);
711
712 EXTEND (SP, 3);
713 PUSHs (sv_2mortal (newSVpv (rtn_cmd.name, 0)));
714 PUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, obj)));
715
716 if (params)
717 PUSHs (sv_2mortal (newSVpv (params, 0)));
718
719 PUTBACK;
720 int count = call_pv ("cf::inject_command", G_SCALAR | G_EVAL);
721 SPAGAIN;
722
723 if (SvTRUE (ERRSV))
724 LOG (llevError, "command '%s' callback evaluation error: %s", rtn_cmd.name, SvPV_nolen (ERRSV));
725
726 int returnvalue = count > 0 ? POPi : -1;
727
728 PUTBACK;
729 FREETMPS;
730 LEAVE;
731
732 return returnvalue;
733} 783}
734 784
735extern "C" void *cfperl_getPluginProperty (int *type, ...) 785extern "C" void *cfperl_getPluginProperty (int *type, ...)
736{ 786{
737 va_list args; 787 va_list args;
740 va_start (args, type); 790 va_start (args, type);
741 propname = va_arg (args, char *); 791 propname = va_arg (args, char *);
742 //printf ("Property name: %s\n", propname); 792 //printf ("Property name: %s\n", propname);
743 793
744 if (!strcmp (propname, "command?")) 794 if (!strcmp (propname, "command?"))
745 {
746 if (!perl)
747 return NULL; 795 return NULL;
748 796 else if (!strcmp (propname, "Identification"))
749 const char *cmdname = va_arg (args, const char *); 797 {
750 HV *hv = get_hv ("cf::COMMAND", 1);
751 SV **svp = hv_fetch (hv, cmdname, strlen (cmdname) + 1, 0);
752
753 va_end (args); 798 va_end (args);
754 799 return (void *)PLUGIN_NAME;
755 if (svp)
756 {
757 // this is totaly broken, should stash it into %COMMAND
758 rtn_cmd.name = cmdname;
759 rtn_cmd.time = SvNV (*svp);
760 rtn_cmd.func = runPluginCommand;
761
762 return &rtn_cmd;
763 }
764 } 800 }
765 else if (!strcmp (propname, "Identification")) 801 else if (!strcmp (propname, "FullName"))
766 { 802 {
767 va_end (args); 803 va_end (args);
768 return (void*) PLUGIN_NAME;
769 }
770 else if (!strcmp (propname, "FullName"))
771 {
772 va_end (args);
773 return (void*) PLUGIN_VERSION; 804 return (void *)PLUGIN_VERSION;
774 } 805 }
775 else 806 else
776 va_end (args); 807 va_end (args);
777 808
778 return NULL; 809 return NULL;
803 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 834 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
804 835
805 char *argv[] = { 836 char *argv[] = {
806 "", 837 "",
807 "-e" 838 "-e"
808 "cf->bootstrap;" 839 "use Event;" // required for bootstrap
840 "cf->bootstrap;" // required for datadir :*>
809 "unshift @INC, cf::datadir ();" 841 "unshift @INC, cf::datadir ();"
810 "require cf;" 842 "require cf;"
811 }; 843 };
812 844
813 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 845 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
814 { 846 {
815 printf ("unable to initialize perl-interpreter, aborting.\n"); 847 printf ("unable to initialize perl-interpreter, aborting.\n");
816 exit (EXIT_FAILURE); 848 exit (EXIT_FAILURE);
817 } 849 }
818
819 obj_cache = newHV ();
820} 850}
821 851
822void cfperl_main () 852void cfperl_main ()
823{ 853{
824 dSP; 854 dSP;
875 905
876 AV *callbacks = 0; 906 AV *callbacks = 0;
877 907
878 object *op; 908 object *op;
879 player *pl; 909 player *pl;
880 mapstruct *map; 910 maptile *map;
881 911
882 // callback call ordering is: 912 // callback call ordering is:
883 // 1. per-object callback (NYI) 913 // 1. per-object callback
884 // 2. per-class object 914 // 2. per-class object
885 // 2a. per-type callback 915 // 3. per-type callback
886 // 4. global callbacks 916 // 4. global callbacks
887 917
888 gather_callbacks (callbacks, cb_global, event); 918 gather_callbacks (callbacks, cb_global, event);
889 919
890 switch (KLASS_OF (event)) 920 switch (KLASS_OF (event))
935 break; 965 break;
936 966
937 case KLASS_MAP: 967 case KLASS_MAP:
938 dt = (data_type) va_arg (ap, int); 968 dt = (data_type) va_arg (ap, int);
939 assert (("first argument must be of type object", dt == DT_MAP)); 969 assert (("first argument must be of type object", dt == DT_MAP));
940 map = va_arg (ap, mapstruct *); 970 map = va_arg (ap, maptile *);
941 971
942 if (map->cb) 972 if (map->cb)
943 gather_callbacks (callbacks, map->cb, event); 973 gather_callbacks (callbacks, map->cb, event);
944 974
945 gather_callbacks (callbacks, cb_map, event); 975 gather_callbacks (callbacks, cb_map, event);
1020cfperl_result_INT (int idx) 1050cfperl_result_INT (int idx)
1021{ 1051{
1022 return SvIV (cfperl_result (idx)); 1052 return SvIV (cfperl_result (idx));
1023} 1053}
1024 1054
1055double
1056cfperl_result_DOUBLE (int idx)
1057{
1058 return SvNV (cfperl_result (idx));
1059}
1060
1061/////////////////////////////////////////////////////////////////////////////
1062
1063struct EventAPI *watcher_base::GEventAPI;
1064
1065static void iw_dispatch (pe_event *ev)
1066{
1067 iw *w = (iw *)ev->ext_data;
1068 w->call (*w);
1069}
1070
1071void
1072iw::alloc ()
1073{
1074 pe = GEventAPI->new_idle (0, 0);
1075
1076 pe->base.callback = (void *)iw_dispatch;
1077 pe->base.ext_data = (void *)this;
1078}
1079
1080static void iow_dispatch (pe_event *ev)
1081{
1082 iow *w = (iow *)ev->ext_data;
1083 w->call (*w, ((pe_ioevent *)ev)->got);
1084}
1085
1086void
1087iow::alloc ()
1088{
1089 pe = GEventAPI->new_io (0, 0);
1090
1091 pe->base.callback = (void *)iow_dispatch;
1092 pe->base.ext_data = (void *)this;
1093
1094 pe->fd = -1;
1095 pe->poll = 0;
1096}
1097
1098void
1099iow::fd (int fd)
1100{
1101 pe->fd = fd;
1102}
1103
1104int
1105iow::poll ()
1106{
1107 return pe->poll;
1108}
1109
1110void
1111iow::poll (int events)
1112{
1113 if (pe->poll != events)
1114 {
1115 if (pe->poll) stop ();
1116 pe->poll = events;
1117 if (pe->poll) start ();
1118 }
1119}
1120
1025MODULE = cf PACKAGE = cf PREFIX = cf_ 1121MODULE = cf PACKAGE = cf PREFIX = cf_
1026 1122
1027BOOT: 1123BOOT:
1028{ 1124{
1029 HV *stash = gv_stashpv ("cf", 1); 1125 HV *stash = gv_stashpv ("cf", 1);
1126
1127 I_EVENT_API (PACKAGE);
1128 watcher_base::GEventAPI = GEventAPI;
1129
1130 newCONSTSUB (stash, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1030 1131
1031 static const struct { 1132 static const struct {
1032 const char *name; 1133 const char *name;
1033 IV iv; 1134 IV iv;
1034 } *civ, const_iv[] = { 1135 } *civ, const_iv[] = {
1197 const_iv (AT_BLIND) 1298 const_iv (AT_BLIND)
1198 const_iv (AT_INTERNAL) 1299 const_iv (AT_INTERNAL)
1199 const_iv (AT_LIFE_STEALING) 1300 const_iv (AT_LIFE_STEALING)
1200 const_iv (AT_DISEASE) 1301 const_iv (AT_DISEASE)
1201 1302
1202 const_iv (QUEST_IN_PROGRESS)
1203 const_iv (QUEST_DONE_QUEST)
1204 const_iv (QUEST_DONE_TASK)
1205 const_iv (QUEST_START_QUEST)
1206 const_iv (QUEST_END_QUEST)
1207 const_iv (QUEST_START_TASK)
1208 const_iv (QUEST_END_TASK)
1209 const_iv (QUEST_OVERRIDE)
1210 const_iv (QUEST_ON_ACTIVATE)
1211
1212 const_iv (WEAP_HIT) 1303 const_iv (WEAP_HIT)
1213 const_iv (WEAP_SLASH) 1304 const_iv (WEAP_SLASH)
1214 const_iv (WEAP_PIERCE) 1305 const_iv (WEAP_PIERCE)
1215 const_iv (WEAP_CLEAVE) 1306 const_iv (WEAP_CLEAVE)
1216 const_iv (WEAP_SLICE) 1307 const_iv (WEAP_SLICE)
1337 const_iv (NDI_MAX_COLOR) 1428 const_iv (NDI_MAX_COLOR)
1338 const_iv (NDI_COLOR_MASK) 1429 const_iv (NDI_COLOR_MASK)
1339 const_iv (NDI_UNIQUE) 1430 const_iv (NDI_UNIQUE)
1340 const_iv (NDI_ALL) 1431 const_iv (NDI_ALL)
1341 1432
1433 const_iv (UPD_LOCATION)
1434 const_iv (UPD_FLAGS)
1435 const_iv (UPD_WEIGHT)
1436 const_iv (UPD_FACE)
1437 const_iv (UPD_NAME)
1438 const_iv (UPD_ANIM)
1439 const_iv (UPD_ANIMSPEED)
1440 const_iv (UPD_NROF)
1441
1442 const_iv (UPD_SP_MANA)
1443 const_iv (UPD_SP_GRACE)
1444 const_iv (UPD_SP_DAMAGE)
1445
1342 const_iv (F_APPLIED) 1446 const_iv (F_APPLIED)
1343 const_iv (F_LOCATION) 1447 const_iv (F_LOCATION)
1344 const_iv (F_UNPAID) 1448 const_iv (F_UNPAID)
1345 const_iv (F_MAGIC) 1449 const_iv (F_MAGIC)
1346 const_iv (F_CURSED) 1450 const_iv (F_CURSED)
1540 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1644 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1541 av_push (event, newSViv (eiv->klass)); 1645 av_push (event, newSViv (eiv->klass));
1542 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1646 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1543 newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv)); 1647 newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv));
1544 } 1648 }
1545
1546 static const struct {
1547 int dtype;
1548 const char *name;
1549 IV idx;
1550 } *cprop, prop_table[] = {
1551# define prop(type, name) { type, # name, (IV) CFAPI_ ## name },
1552 prop (CFAPI_INT, MAP_PROP_FLAGS)
1553 prop (CFAPI_INT, MAP_PROP_DIFFICULTY)
1554 prop (CFAPI_STRING, MAP_PROP_PATH)
1555 prop (CFAPI_STRING, MAP_PROP_TMPNAME)
1556 prop (CFAPI_STRING, MAP_PROP_NAME)
1557 prop (CFAPI_INT, MAP_PROP_RESET_TIME)
1558 prop (CFAPI_INT, MAP_PROP_RESET_TIMEOUT)
1559 prop (CFAPI_INT, MAP_PROP_PLAYERS)
1560 prop (CFAPI_INT, MAP_PROP_DARKNESS)
1561 prop (CFAPI_INT, MAP_PROP_WIDTH)
1562 prop (CFAPI_INT, MAP_PROP_HEIGHT)
1563 prop (CFAPI_INT, MAP_PROP_ENTER_X)
1564 prop (CFAPI_INT, MAP_PROP_ENTER_Y)
1565 prop (CFAPI_INT, MAP_PROP_TEMPERATURE)
1566 prop (CFAPI_INT, MAP_PROP_PRESSURE)
1567 prop (CFAPI_INT, MAP_PROP_HUMIDITY)
1568 prop (CFAPI_INT, MAP_PROP_WINDSPEED)
1569 prop (CFAPI_INT, MAP_PROP_WINDDIR)
1570 prop (CFAPI_INT, MAP_PROP_SKY)
1571 prop (CFAPI_INT, MAP_PROP_WPARTX)
1572 prop (CFAPI_INT, MAP_PROP_WPARTY)
1573 prop (CFAPI_STRING, MAP_PROP_MESSAGE)
1574 prop (CFAPI_PREGION, MAP_PROP_REGION)
1575 prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB)
1576 prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB)
1577 prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY)
1578 prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT)
1579 prop (CFAPI_POBJECT, OBJECT_PROP_CONTAINER)
1580 prop (CFAPI_PMAP, OBJECT_PROP_MAP)
1581 prop (CFAPI_INT, OBJECT_PROP_COUNT)
1582 prop (CFAPI_INT, OBJECT_PROP_REFCOUNT)
1583 prop (CFAPI_STRING, OBJECT_PROP_NAME)
1584 prop (CFAPI_STRING, OBJECT_PROP_NAME_PLURAL)
1585 prop (CFAPI_STRING, OBJECT_PROP_TITLE)
1586 prop (CFAPI_STRING, OBJECT_PROP_RACE)
1587 prop (CFAPI_STRING, OBJECT_PROP_SLAYING)
1588 prop (CFAPI_STRING, OBJECT_PROP_SKILL)
1589 prop (CFAPI_STRING, OBJECT_PROP_MESSAGE)
1590 prop (CFAPI_STRING, OBJECT_PROP_LORE)
1591 prop (CFAPI_INT, OBJECT_PROP_X)
1592 prop (CFAPI_INT, OBJECT_PROP_Y)
1593 prop (CFAPI_DOUBLE, OBJECT_PROP_SPEED)
1594 prop (CFAPI_DOUBLE, OBJECT_PROP_SPEED_LEFT)
1595 prop (CFAPI_INT, OBJECT_PROP_NROF)
1596 prop (CFAPI_INT, OBJECT_PROP_DIRECTION)
1597 prop (CFAPI_INT, OBJECT_PROP_FACING)
1598 prop (CFAPI_INT, OBJECT_PROP_TYPE)
1599 prop (CFAPI_INT, OBJECT_PROP_SUBTYPE)
1600 prop (CFAPI_INT, OBJECT_PROP_CLIENT_TYPE)
1601 prop (CFAPI_INT, OBJECT_PROP_ATTACK_TYPE)
1602 prop (CFAPI_INT, OBJECT_PROP_PATH_ATTUNED)
1603 prop (CFAPI_INT, OBJECT_PROP_PATH_REPELLED)
1604 prop (CFAPI_INT, OBJECT_PROP_PATH_DENIED)
1605 prop (CFAPI_INT, OBJECT_PROP_MATERIAL)
1606 prop (CFAPI_STRING, OBJECT_PROP_MATERIAL_NAME)
1607 prop (CFAPI_INT, OBJECT_PROP_MAGIC)
1608 prop (CFAPI_INT, OBJECT_PROP_VALUE)
1609 prop (CFAPI_INT, OBJECT_PROP_LEVEL)
1610 prop (CFAPI_INT, OBJECT_PROP_LAST_HEAL)
1611 prop (CFAPI_INT, OBJECT_PROP_LAST_SP)
1612 prop (CFAPI_INT, OBJECT_PROP_LAST_GRACE)
1613 prop (CFAPI_INT, OBJECT_PROP_LAST_EAT)
1614 prop (CFAPI_INT, OBJECT_PROP_INVISIBLE_TIME)
1615 prop (CFAPI_INT, OBJECT_PROP_PICK_UP)
1616 prop (CFAPI_INT, OBJECT_PROP_ITEM_POWER)
1617 prop (CFAPI_INT, OBJECT_PROP_GEN_SP_ARMOUR)
1618 prop (CFAPI_INT, OBJECT_PROP_WEIGHT)
1619 prop (CFAPI_INT, OBJECT_PROP_WEIGHT_LIMIT)
1620 prop (CFAPI_INT, OBJECT_PROP_CARRYING)
1621 prop (CFAPI_INT, OBJECT_PROP_GLOW_RADIUS)
1622 prop (CFAPI_LONG, OBJECT_PROP_PERM_EXP)
1623 prop (CFAPI_POBJECT, OBJECT_PROP_CURRENT_WEAPON)
1624 prop (CFAPI_POBJECT, OBJECT_PROP_ENEMY)
1625 prop (CFAPI_POBJECT, OBJECT_PROP_ATTACKED_BY)
1626 prop (CFAPI_INT, OBJECT_PROP_RUN_AWAY)
1627 prop (CFAPI_POBJECT, OBJECT_PROP_CHOSEN_SKILL)
1628 prop (CFAPI_INT, OBJECT_PROP_HIDDEN)
1629 prop (CFAPI_INT, OBJECT_PROP_MOVE_STATUS)
1630 prop (CFAPI_INT, OBJECT_PROP_MOVE_TYPE)
1631 prop (CFAPI_POBJECT, OBJECT_PROP_SPELL_ITEM)
1632 prop (CFAPI_DOUBLE, OBJECT_PROP_EXP_MULTIPLIER)
1633 prop (CFAPI_PARCH, OBJECT_PROP_ARCHETYPE)
1634 prop (CFAPI_PARCH, OBJECT_PROP_OTHER_ARCH)
1635 prop (CFAPI_STRING, OBJECT_PROP_CUSTOM_NAME)
1636 prop (CFAPI_INT, OBJECT_PROP_ANIM_SPEED)
1637 prop (CFAPI_INT, OBJECT_PROP_FRIENDLY)
1638 prop (CFAPI_STRING, OBJECT_PROP_SHORT_NAME)
1639 prop (CFAPI_INT, OBJECT_PROP_MAGICAL)
1640 prop (CFAPI_INT, OBJECT_PROP_LUCK)
1641 prop (CFAPI_POBJECT, OBJECT_PROP_OWNER)
1642 prop (CFAPI_POBJECT, OBJECT_PROP_PRESENT)
1643 prop (CFAPI_INT, OBJECT_PROP_CHEATER)
1644 prop (CFAPI_INT, OBJECT_PROP_MERGEABLE)
1645 prop (CFAPI_INT, OBJECT_PROP_PICKABLE)
1646 prop (CFAPI_INT, OBJECT_PROP_STR)
1647 prop (CFAPI_INT, OBJECT_PROP_DEX)
1648 prop (CFAPI_INT, OBJECT_PROP_CON)
1649 prop (CFAPI_INT, OBJECT_PROP_WIS)
1650 prop (CFAPI_INT, OBJECT_PROP_INT)
1651 prop (CFAPI_INT, OBJECT_PROP_POW)
1652 prop (CFAPI_INT, OBJECT_PROP_CHA)
1653 prop (CFAPI_INT, OBJECT_PROP_WC)
1654 prop (CFAPI_INT, OBJECT_PROP_AC)
1655 prop (CFAPI_INT, OBJECT_PROP_HP)
1656 prop (CFAPI_INT, OBJECT_PROP_SP)
1657 prop (CFAPI_INT, OBJECT_PROP_GP)
1658 prop (CFAPI_INT, OBJECT_PROP_FP)
1659 prop (CFAPI_INT, OBJECT_PROP_MAXHP)
1660 prop (CFAPI_INT, OBJECT_PROP_MAXSP)
1661 prop (CFAPI_INT, OBJECT_PROP_MAXGP)
1662 prop (CFAPI_INT, OBJECT_PROP_DAM)
1663 prop (CFAPI_STRING, OBJECT_PROP_GOD)
1664 prop (CFAPI_STRING, OBJECT_PROP_ARCH_NAME)
1665 prop (CFAPI_INT, OBJECT_PROP_INVISIBLE)
1666 prop (CFAPI_INT, OBJECT_PROP_FACE)
1667 };
1668
1669 HV *prop_type = get_hv ("cf::PROP_TYPE", 1);
1670 HV *prop_idx = get_hv ("cf::PROP_IDX", 1);
1671
1672 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; )
1673 {
1674 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0);
1675 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0);
1676 }
1677
1678 //I_EVENT_API (PACKAGE);
1679} 1649}
1680 1650
1681void _reload_1 () 1651void _init_vars ()
1682 CODE: 1652 CODE:
1683 cb_global = get_av ("cf::CB_GLOBAL", 1); 1653 cb_global = get_av ("cf::CB_GLOBAL", 1);
1684 cb_object = get_av ("cf::CB_OBJECT", 1); 1654 cb_object = get_av ("cf::CB_OBJECT", 1);
1685 cb_player = get_av ("cf::CB_PLAYER", 1); 1655 cb_player = get_av ("cf::CB_PLAYER", 1);
1686 cb_type = get_av ("cf::CB_TYPE" , 1); 1656 cb_type = get_av ("cf::CB_TYPE" , 1);
1687 cb_map = get_av ("cf::CB_MAP" , 1); 1657 cb_map = get_av ("cf::CB_MAP" , 1);
1688 1658
1689void _reload_2 () 1659void _global_reattach ()
1690 CODE: 1660 CODE:
1691{ 1661{
1692 // reattach to all attachable objects in the game. 1662 // reattach to all attachable objects in the game.
1693 for (player *pl = first_player; pl; pl = pl->next) 1663 for (player *pl = first_player; pl; pl = pl->next)
1694 reattach (pl); 1664 reattach (pl);
1695 1665
1696 for (mapstruct *map = first_map; map; map = map->next) 1666 for (maptile *map = first_map; map; map = map->next)
1697 reattach (map); 1667 reattach (map);
1698 1668
1699 for (object *op = objects; op; op = op->next) 1669 for (object *op = object::first; op; op = op->next)
1700 reattach (op); 1670 reattach (op);
1701} 1671}
1672
1673bool
1674add_client (int fd, const char *peername)
1702 1675
1703NV floor (NV x) 1676NV floor (NV x)
1704 1677
1705NV ceil (NV x) 1678NV ceil (NV x)
1706 1679
1752 case 5: RETVAL = settings.playerdir; break; 1725 case 5: RETVAL = settings.playerdir; break;
1753 case 6: RETVAL = settings.datadir ; break; 1726 case 6: RETVAL = settings.datadir ; break;
1754 } 1727 }
1755 OUTPUT: RETVAL 1728 OUTPUT: RETVAL
1756 1729
1757int 1730void _exit (int status = 0)
1731
1758cf_find_animation (char *text) 1732int find_animation (char *text)
1759 PROTOTYPE: $ 1733 PROTOTYPE: $
1760 1734
1761int random_roll(int min, int max, object *op, int goodbad); 1735int random_roll (int min, int max, object *op, int goodbad);
1762 1736
1763const char *cost_string_from_value(uint64 cost, int approx = 0) 1737const char *cost_string_from_value(uint64 cost, int approx = 0)
1764 1738
1765int invoke (int event, ...) 1739int invoke (int event, ...)
1766 CODE: 1740 CODE:
1816 OUTPUT: 1790 OUTPUT:
1817 RETVAL 1791 RETVAL
1818 1792
1819MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1793MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1820 1794
1795INCLUDE: $PERL genacc object ../include/object.h |
1796
1821int invoke (object *op, int event, ...) 1797int invoke (object *op, int event, ...)
1822 CODE: 1798 CODE:
1823 if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); 1799 if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT");
1824 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 1800 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1825 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); 1801 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1826 RETVAL = INVOKE_((event_type)event, ARG_OBJECT (op), ARG_AV (av)); 1802 RETVAL = INVOKE_((event_type)event, ARG_OBJECT (op), ARG_AV (av));
1827 OUTPUT: RETVAL 1803 OUTPUT: RETVAL
1828 1804
1829SV *registry (object *op) 1805SV *registry (object *op)
1806
1807void mortals ()
1830 CODE: 1808 PPCODE:
1831 RETVAL = registry_of (op); 1809 EXTEND (SP, object::mortals.size ());
1810 for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i)
1811 PUSHs (to_sv (*i));
1812
1813object *first ()
1814 CODE:
1815 RETVAL = object::first;
1816 OUTPUT: RETVAL
1817
1818# missing properties
1819
1820int flag (object *op, int flag, int value = 1)
1821 PROTOTYPE: $$;$
1822 CODE:
1823 RETVAL = QUERY_FLAG (op, flag);
1824 if (items >= 3)
1825 if (value)
1826 SET_FLAG (op, flag);
1827 else
1828 CLEAR_FLAG (op, flag);
1832 OUTPUT: 1829 OUTPUT: RETVAL
1833 RETVAL
1834 1830
1835object *head (object *op) 1831object *head (object *op)
1836 PROTOTYPE: $ 1832 PROTOTYPE: $
1837 ALIAS:
1838 more = 1
1839 above = 2
1840 below = 3
1841 CODE: 1833 CODE:
1842 switch (ix)
1843 {
1844 case 0: RETVAL = op->head ? op->head : op; break; // DOH! 1834 RETVAL = op->head ? op->head : op;
1845 case 1: RETVAL = op->more; break;
1846 case 2: RETVAL = op->above; break;
1847 case 3: RETVAL = op->below; break;
1848 }
1849 OUTPUT:
1850 RETVAL 1835 OUTPUT: RETVAL
1851 1836
1852SV * 1837int is_head (object *op)
1853get_property (object *obj, int type, int idx) 1838 PROTOTYPE: $
1854 CODE: 1839 CODE:
1855 RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx));
1856 OUTPUT: RETVAL
1857
1858SV *
1859set_property (object *obj, int type, int idx, SV *newval)
1860 CODE:
1861 switch (type)
1862 {
1863 case CFAPI_INT:
1864 cf_object_set_int_property (obj, idx, SvIV (newval));
1865 break;
1866 case CFAPI_LONG:
1867 cf_object_set_long_property (obj, idx, (long) SvVAL64 (newval));
1868 break;
1869 case CFAPI_DOUBLE:
1870 {
1871 int unused_type;
1872 object_set_property (&unused_type, obj, idx, (double)SvNV (newval));
1873 }
1874 break;
1875 case CFAPI_STRING:
1876 cf_object_set_string_property (obj, idx, SvOK (newval) ? SvPV_nolen (newval) : 0);
1877 break;
1878 case CFAPI_POBJECT:
1879 {
1880 int unused_type;
1881 object_set_property (&unused_type, obj, idx, (object *)SvPTR_ornull (newval, "cf::object"));
1882 }
1883 break;
1884 default:
1885 croak ("unhandled type '%d' in set_property '%d'", type, idx);
1886 }
1887
1888# missing properties
1889
1890void
1891set_attacktype (object *obj, U32 attacktype)
1892 CODE:
1893 obj->attacktype = attacktype;
1894
1895U32
1896get_attacktype (object *obj)
1897 ALIAS:
1898 attacktype = 0
1899 CODE:
1900 RETVAL = obj->attacktype;
1901 OUTPUT: RETVAL
1902
1903# missing in plug-in api, of course
1904void
1905set_food (object *obj, int food)
1906 CODE:
1907 obj->stats.food = food;
1908
1909int
1910get_food (object *obj)
1911 ALIAS:
1912 food = 0
1913 CODE:
1914 RETVAL = obj->stats.food; 1840 RETVAL = !op->head;
1915 OUTPUT: RETVAL 1841 OUTPUT: RETVAL
1916 1842
1917void 1843void
1918inv (object *obj) 1844inv (object *obj)
1919 PROTOTYPE: $ 1845 PROTOTYPE: $
1920 PPCODE: 1846 PPCODE:
1922 object *o; 1848 object *o;
1923 for (o = obj->inv; o; o = o->below) 1849 for (o = obj->inv; o; o = o->below)
1924 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1850 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1925} 1851}
1926 1852
1927int cf_object_get_resistance (object *op, int rtype) 1853object *find_best_object_match (object *op, const char *match)
1928 ALIAS: resistance = 0
1929 1854
1930int cf_object_get_flag (object *op, int flag) 1855object *find_marked_object (object *op)
1931 ALIAS: flag = 0
1932 1856
1933void cf_object_set_flag (object *op, int flag, int value) 1857int resistance (object *op, int rtype, int newval = 0)
1858 CODE:
1859 if (rtype < 0 || rtype >= NROFATTACKS)
1860 croak ("resistance out of bounds");
1861 RETVAL = op->resist [rtype];
1862 if (items >= 3)
1863 op->resist [rtype] = newval;
1864 OUTPUT: RETVAL
1865
1866void set_resistance (object *op, int rtype, int val)
1867 CODE:
1868 if (rtype < 0 || rtype >= NROFATTACKS)
1869 op->resist[rtype] = val;
1934 1870
1935int need_identify (const object *obj); 1871int need_identify (const object *obj);
1936 1872
1937int apply_shop_mat (object *shop_mat, object *op); 1873int apply_shop_mat (object *shop_mat, object *op);
1938 1874
1940 CODE: 1876 CODE:
1941 RETVAL = move_ob (op, dir, originator); 1877 RETVAL = move_ob (op, dir, originator);
1942 OUTPUT: 1878 OUTPUT:
1943 RETVAL 1879 RETVAL
1944 1880
1945void cf_object_apply (object *op, object *author, int flags = 0) 1881void apply (object *applier, object *applied, int flags = 0)
1882 CODE:
1883 manual_apply (applied, applier, flags);
1946 1884
1947void cf_object_apply_below (object *op) 1885void apply_below (object *op)
1886 CODE:
1887 player_apply_below (op);
1948 1888
1949void cf_object_remove (object *op) 1889void remove (object *op)
1890 CODE:
1891 op->remove ();
1950 1892
1951void cf_object_free (object *op) 1893void destroy (object *op, int recursive = 0)
1894 CODE:
1895 op->destroy (recursive);
1952 1896
1953object *cf_object_present_archname_inside (object *op, char *whatstr) 1897object *cf_object_present_archname_inside (object *op, char *whatstr)
1954 1898
1955int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) 1899int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1956 1900
1957int cf_object_change_map (object *op, int x, int y, mapstruct *map) 1901int cf_object_change_map (object *op, int x, int y, maptile *map)
1958 1902
1959object *cf_object_clone (object *op, int clonetype = 0) 1903object *clone (object *op, int recursive = 0)
1904 CODE:
1905 if (recursive)
1906 RETVAL = object_create_clone (op);
1907 else
1908 {
1909 RETVAL = object::create ();
1910 op->copy_to (RETVAL);
1911 }
1912 OUTPUT: RETVAL
1960 1913
1961int cf_object_pay_item (object *op, object *buyer) 1914int pay_item (object *op, object *buyer)
1915 CODE:
1916 RETVAL = pay_for_item (op, buyer);
1917 OUTPUT: RETVAL
1962 1918
1963int cf_object_pay_amount (object *op, uint64 amount) 1919int pay_amount (object *op, uint64 amount)
1920 CODE:
1921 RETVAL = pay_for_amount (amount, op);
1922 OUTPUT: RETVAL
1964 1923
1965void pay_player (object *op, uint64 amount) 1924void pay_player (object *op, uint64 amount)
1966 1925
1967val64 pay_player_arch (object *op, const char *arch, uint64 amount) 1926val64 pay_player_arch (object *op, const char *arch, uint64 amount)
1968 1927
1969int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0) 1928int cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg = 0)
1970 1929
1971int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0) 1930void learn_spell (object *op, object *sp, int special_prayer = 0)
1931 CODE:
1932 do_learn_spell (op, sp, special_prayer);
1972 1933
1973void cf_object_learn_spell (object *op, object *sp)
1974
1975void cf_object_forget_spell (object *op, object *sp) 1934void forget_spell (object *op, object *sp)
1935 CODE:
1936 do_forget_spell (op, query_name (sp));
1976 1937
1977object *cf_object_check_for_spell (object *op, char *spellname) 1938object *check_for_spell (object *op, char *spellname)
1939 CODE:
1940 RETVAL = check_spell_known (op, spellname);
1941 OUTPUT: RETVAL
1978 1942
1979int cf_object_query_money (object *op) 1943int query_money (object *op)
1980 ALIAS: money = 0 1944 ALIAS: money = 0
1981 1945
1982int cf_object_query_cost (object *op, object *who, int flags) 1946int query_cost (object *op, object *who, int flags)
1983 ALIAS: cost = 0 1947 ALIAS: cost = 0
1984 1948
1985void cf_object_activate_rune (object *op , object *victim) 1949void spring_trap (object *op, object *victim)
1986 1950
1987int cf_object_check_trigger (object *op, object *cause) 1951int check_trigger (object *op, object *cause)
1988 1952
1989int cf_object_out_of_map (object *op, int x, int y)
1990
1991void cf_object_drop (object *op, object *author) 1953void drop (object *who, object *op)
1992 1954
1993void cf_object_take (object *op, object *author) 1955void pick_up (object *who, object *op)
1994 1956
1995object *cf_object_insert_object (object *op, object *container) 1957object *cf_object_insert_object (object *op, object *container)
1996 1958
1997const char *cf_object_get_msg (object *ob)
1998 ALIAS: msg = 0
1999
2000object *cf_object_insert_in_ob (object *ob, object *where) 1959object *cf_object_insert_in_ob (object *ob, object *where)
2001 1960
2002int cf_object_teleport (object *op, mapstruct *map, int x, int y) 1961int cf_object_teleport (object *op, maptile *map, int x, int y)
2003 1962
2004void cf_object_update (object *op, int flags) 1963void update (object *op, int action)
2005 1964 CODE:
2006void cf_object_pickup (object *op, object *what) 1965 update_object (op, action);
2007 1966
2008object *cf_create_object_by_name (const char *name) 1967object *cf_create_object_by_name (const char *name)
2009 1968
2010void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) 1969void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0)
2011 1970
2017 1976
2018void push_button (object *op); 1977void push_button (object *op);
2019 1978
2020void use_trigger (object *op); 1979void use_trigger (object *op);
2021 1980
2022void add_button_link (object *button, mapstruct *map, int connected); 1981void add_button_link (object *button, maptile *map, int connected);
2023 1982
2024void remove_button_link (object *op); 1983void remove_button_link (object *op);
2025
2026void
2027cf_object_set_resistance (object *op, int rtype, int val)
2028 CODE:
2029 if (rtype >= 0 && rtype < NROFATTACKS)
2030 op->resist[rtype] = val;
2031 1984
2032 1985
2033MODULE = cf PACKAGE = cf::object PREFIX = cf_ 1986MODULE = cf PACKAGE = cf::object PREFIX = cf_
2034 1987
2035void cf_fix_object (object *pl) 1988void cf_fix_object (object *pl)
2045 CODE: 1998 CODE:
2046 RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); 1999 RETVAL = archetype ? get_archetype (archetype) : cf_create_object ();
2047 OUTPUT: 2000 OUTPUT:
2048 RETVAL 2001 RETVAL
2049 2002
2050object *insert_ob_in_map_at (object *ob, mapstruct *where, object_ornull *orig, int flag, int x, int y) 2003object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
2051 PROTOTYPE: $$$$$$ 2004 PROTOTYPE: $$$$$$
2052 CODE: 2005 CODE:
2053{ 2006{
2054 int unused_type; 2007 int unused_type;
2055 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 2008 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
2093bool on_same_map_as (object *ob, object *other) 2046bool on_same_map_as (object *ob, object *other)
2094 CODE: 2047 CODE:
2095 RETVAL = on_same_map (ob, other); 2048 RETVAL = on_same_map (ob, other);
2096 OUTPUT: RETVAL 2049 OUTPUT: RETVAL
2097 2050
2098char * 2051const char *
2099base_name (object *ob, int plural) 2052base_name (object *op, int plural = op->nrof > 1)
2100 CODE: 2053 CODE:
2101 RETVAL = cf_query_base_name (ob, plural); 2054 RETVAL = query_base_name (op, plural);
2102 OUTPUT: RETVAL 2055 OUTPUT: RETVAL
2103
2104living *
2105stats (object *ob)
2106 CODE:
2107 RETVAL = &ob->stats;
2108 OUTPUT: RETVAL
2109
2110 2056
2111MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 2057MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
2112 2058
2113player *player (object *op) 2059player *player (object *op)
2114 CODE: 2060 CODE:
2132 2078
2133void cf_player_set_party (object *op, partylist *party) 2079void cf_player_set_party (object *op, partylist *party)
2134 2080
2135void kill_player (object *op) 2081void kill_player (object *op)
2136 2082
2083void esrv_update_item (object *op, int what, object *item)
2084 C_ARGS: what, op, item
2085
2086void clear_los (object *op)
2087
2088int command_reset (object *op, char *params)
2089
2090int command_teleport (object *op, char *params)
2091
2092int command_summon (object *op, char *params)
2093
2094int command_arrest (object *op, char *params)
2095
2096int command_kick (object *op, char *params)
2097
2098int command_banish (object *op, char *params)
2099
2100
2137MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 2101MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
2102
2103INCLUDE: $PERL genacc player ../include/player.h |
2138 2104
2139int invoke (player *pl, int event, ...) 2105int invoke (player *pl, int event, ...)
2140 CODE: 2106 CODE:
2141 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); 2107 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER");
2142 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2108 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2143 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); 2109 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
2144 RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); 2110 RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av));
2145 OUTPUT: RETVAL 2111 OUTPUT: RETVAL
2146 2112
2147SV *registry (player *pl) 2113SV *registry (player *pl)
2114
2115player *cf_player_find (char *name)
2116 PROTOTYPE: $
2117
2118void cf_player_move (player *pl, int dir)
2119
2120void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
2121
2122player *first ()
2148 CODE: 2123 CODE:
2149 RETVAL = registry_of (pl); 2124 RETVAL = first_player;
2125 OUTPUT: RETVAL
2126
2127player *next (player *pl)
2128 CODE:
2129 RETVAL = pl->next;
2130 OUTPUT: RETVAL
2131
2132bool
2133cell_visible (player *pl, int dx, int dy)
2134 CODE:
2135 RETVAL = FABS (dx) <= pl->socket->mapx / 2 && FABS (dy) <= pl->socket->mapy / 2
2136 && !pl->blocked_los [dx + pl->socket->mapx / 2][dy + pl->socket->mapy / 2];
2150 OUTPUT: 2137 OUTPUT:
2151 RETVAL 2138 RETVAL
2152 2139
2153player *cf_player_find (char *name)
2154 PROTOTYPE: $
2155
2156void cf_player_move (player *pl, int dir)
2157
2158void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
2159
2160# nonstandard
2161object *ob (player *pl)
2162 CODE:
2163 RETVAL = pl->ob;
2164 OUTPUT: RETVAL
2165
2166player *first ()
2167 CODE:
2168 RETVAL = first_player;
2169 OUTPUT: RETVAL
2170
2171player *next (player *pl)
2172 CODE:
2173 RETVAL = pl->next;
2174 OUTPUT: RETVAL
2175
2176bool
2177cell_visible (player *pl, int dx, int dy)
2178 CODE:
2179 RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2
2180 && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2];
2181 OUTPUT:
2182 RETVAL
2183
2184char *
2185client (player *pl)
2186 CODE:
2187 RETVAL = pl->socket.client;
2188 OUTPUT:
2189 RETVAL
2190
2191char *
2192host (player *pl)
2193 CODE:
2194 RETVAL = pl->socket.host;
2195 OUTPUT:
2196 RETVAL
2197
2198char *
2199killer (player *pl, char *killer = 0)
2200 CODE:
2201 if (killer)
2202 snprintf (pl->killer, sizeof (pl->killer), "%s", killer);
2203 RETVAL = pl->killer;
2204 OUTPUT:
2205 RETVAL
2206
2207void
2208buggy_mapscroll (player *pl, int value = 1)
2209 CODE:
2210 pl->socket.buggy_mapscroll = value;
2211
2212void 2140void
2213send (player *pl, SV *packet) 2141send (player *pl, SV *packet)
2214 CODE: 2142 CODE:
2215{ 2143{
2216 STRLEN len; 2144 STRLEN len;
2217 char *buf = SvPVbyte (packet, len); 2145 char *buf = SvPVbyte (packet, len);
2218 2146
2219 Write_String_To_Socket (&pl->socket, buf, len); 2147 pl->socket->send_packet (buf, len);
2220} 2148}
2221 2149
2222int 2150int
2223listening (player *pl, int new_value = -1) 2151listening (player *pl, int new_value = -1)
2224 CODE: 2152 CODE:
2226 if (new_value >= 0) 2154 if (new_value >= 0)
2227 pl->listening = new_value; 2155 pl->listening = new_value;
2228 OUTPUT: 2156 OUTPUT:
2229 RETVAL 2157 RETVAL
2230 2158
2231void get_savebed (player *pl) 2159void savebed (player *pl, SV *map_path = 0, SV *x = 0, SV *y = 0)
2232 ALIAS: 2160 PROTOTYPE: $;$$$
2233 savebed = 0
2234 PPCODE: 2161 PPCODE:
2162 if (GIMME_V != G_VOID)
2163 {
2235 EXTEND (SP, 3); 2164 EXTEND (SP, 3);
2236 PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0))); 2165 PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0)));
2237 PUSHs (sv_2mortal (newSViv (pl->bed_x))); 2166 PUSHs (sv_2mortal (newSViv (pl->bed_x)));
2238 PUSHs (sv_2mortal (newSViv (pl->bed_y))); 2167 PUSHs (sv_2mortal (newSViv (pl->bed_y)));
2239 2168 }
2240void set_savebed (player *pl, char *map_path, int x, int y) 2169 if (map_path) sv_to (map_path, pl->savebed_map);
2241 CODE: 2170 if (x) sv_to (x, pl->bed_x);
2242 strcpy (pl->savebed_map, map_path); 2171 if (y) sv_to (y, pl->bed_y);
2243 pl->bed_x = x;
2244 pl->bed_y = y;
2245 2172
2246void 2173void
2247list () 2174list ()
2248 PPCODE: 2175 PPCODE:
2249{ 2176{
2275 OUTPUT: RETVAL 2202 OUTPUT: RETVAL
2276 2203
2277 2204
2278MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ 2205MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
2279 2206
2280mapstruct *first () 2207maptile *first ()
2281 PROTOTYPE: 2208 PROTOTYPE:
2282 CODE: 2209 CODE:
2283 RETVAL = first_map; 2210 RETVAL = first_map;
2284 OUTPUT: RETVAL 2211 OUTPUT: RETVAL
2285 2212
2286mapstruct *next (mapstruct *map)
2287 PROTOTYPE:
2288 CODE:
2289 RETVAL = map->next;
2290 OUTPUT: RETVAL
2291
2292int invoke (mapstruct *map, int event, ...) 2213int invoke (maptile *map, int event, ...)
2293 CODE: 2214 CODE:
2294 if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); 2215 if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP");
2295 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2216 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2296 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); 2217 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
2297 RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); 2218 RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av));
2298 OUTPUT: RETVAL 2219 OUTPUT: RETVAL
2299 2220
2300SV *registry (mapstruct *map) 2221SV *registry (maptile *map)
2301 CODE:
2302 RETVAL = registry_of (map);
2303 OUTPUT:
2304 RETVAL
2305 2222
2306SV * 2223INCLUDE: $PERL genacc maptile ../include/map.h |
2307get_property (mapstruct *obj, int type, int idx)
2308 CODE:
2309 RETVAL = newSVcfapi (type, cf_map_get_property (obj, idx));
2310 OUTPUT: RETVAL
2311 2224
2312SV *
2313set_property (mapstruct *obj, int type, int idx, SV *newval)
2314 CODE:
2315 switch (type)
2316 {
2317 case CFAPI_INT:
2318 cf_map_set_int_property (obj, idx, SvIV (newval));
2319 break;
2320 default:
2321 croak ("unhandled type '%d' in set_property '%d'", type, idx);
2322 }
2323
2324mapstruct *new (int width, int height) 2225maptile *new (int width, int height)
2325 PROTOTYPE: 2226 PROTOTYPE:
2326 CODE: 2227 CODE:
2327{ 2228{
2328 RETVAL = get_empty_map (width, height); 2229 RETVAL = get_empty_map (width, height);
2329} 2230}
2330 OUTPUT: 2231 OUTPUT:
2331 RETVAL 2232 RETVAL
2332 2233
2333void delete_map (mapstruct *map) 2234void delete_map (maptile *map)
2334 2235
2335void clean_tmp_map (mapstruct *map) 2236void clean_tmp_map (maptile *map)
2336 2237
2337void play_sound_map (mapstruct *map, int x, int y, int sound_num) 2238void play_sound_map (maptile *map, int x, int y, int sound_num)
2338 2239
2240int out_of_map (maptile *map, int x, int y)
2241
2339mapstruct *tile_map (mapstruct *map, unsigned int dir) 2242maptile *tile_map (maptile *map, unsigned int dir)
2340 CODE: 2243 CODE:
2341 RETVAL = dir < 4 ? map->tile_map [dir] : 0; 2244 RETVAL = dir < 4 ? map->tile_map [dir] : 0;
2342 OUTPUT: 2245 OUTPUT:
2343 RETVAL 2246 RETVAL
2344 2247
2345char *tile_path (mapstruct *map, unsigned int dir) 2248char *tile_path (maptile *map, unsigned int dir)
2346 CODE: 2249 CODE:
2347 if (dir >= 4) 2250 if (dir >= 4)
2348 XSRETURN_UNDEF; 2251 XSRETURN_UNDEF;
2349 RETVAL = map->tile_path [dir]; 2252 RETVAL = map->tile_path [dir];
2350 OUTPUT: 2253 OUTPUT:
2351 RETVAL 2254 RETVAL
2352 2255
2353mapstruct *ready_map_name (char *name, int flags = 0) 2256maptile *ready_map_name (char *name, int flags = 0)
2354 PROTOTYPE: $;$ 2257 PROTOTYPE: $;$
2355 ALIAS: 2258 ALIAS:
2356 find = 0 2259 find = 0
2357 get_map = 1 2260 get_map = 1
2358 2261
2359mapstruct *has_been_loaded (char *name) 2262maptile *has_been_loaded (char *name)
2360 PROTOTYPE: $ 2263 PROTOTYPE: $
2361 2264
2362# whoever "designed" the plug-in api should have wasted
2363# his/her time with staying away from the project - would have
2364# saved others a lot of time, without doubt.
2365void set_path (mapstruct *where, char *path)
2366 CODE:
2367 strcpy (where->path, path);
2368
2369int in_memory (mapstruct *map) 2265int in_memory (maptile *map)
2370 CODE: 2266 CODE:
2371 RETVAL = map->in_memory; 2267 RETVAL = map->in_memory;
2372 OUTPUT: 2268 OUTPUT:
2373 RETVAL 2269 RETVAL
2374 2270
2375bool unique (mapstruct *map)
2376 CODE:
2377 RETVAL = map->unique;
2378 OUTPUT:
2379 RETVAL
2380
2381void set_unique (mapstruct *map, bool unique)
2382 CODE:
2383 map->unique = unique;
2384
2385void 2271void
2386trigger (mapstruct *map, long connection, bool state = true) 2272trigger (maptile *map, long connection, bool state = true)
2387 CODE: 2273 CODE:
2388 activate_connection (map, connection, state); 2274 activate_connection (map, connection, state);
2389 2275
2390void 2276void
2391get_connection (mapstruct *map, long connection) 2277get_connection (maptile *map, long connection)
2392 PPCODE: 2278 PPCODE:
2393 oblinkpt *obp = get_connection_links (map, connection); 2279 oblinkpt *obp = get_connection_links (map, connection);
2394 if (obp) 2280 if (obp)
2395 for (objectlink *ol = obp->link; ol; ol = ol->next) 2281 for (objectlink *ol = obp->link; ol; ol = ol->next)
2396 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, ol->ob))); 2282 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, (object *)ol->ob)));
2397 2283
2398object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) 2284object *cf_map_insert_object_there (maptile *where, object *op, object *originator, int flags)
2399 2285
2400object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) 2286object *cf_map_insert_object (maptile *where, object* op, int x, int y)
2401 2287
2402object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) 2288object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny)
2403 C_ARGS: str, map, nx, ny 2289 C_ARGS: str, map, nx, ny
2404 2290
2405void 2291void
2406cf_map_normalise (mapstruct *map, int x, int y) 2292cf_map_normalise (maptile *map, int x, int y)
2407 PPCODE: 2293 PPCODE:
2408{ 2294{
2409 mapstruct *nmap = 0; 2295 maptile *nmap = 0;
2410 I16 nx = 0, ny = 0; 2296 I16 nx = 0, ny = 0;
2411 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); 2297 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2412 2298
2413 EXTEND (SP, 4); 2299 EXTEND (SP, 4);
2414 PUSHs (sv_2mortal (newSViv (flags))); 2300 PUSHs (sv_2mortal (newSViv (flags)));
2420 PUSHs (sv_2mortal (newSViv (ny))); 2306 PUSHs (sv_2mortal (newSViv (ny)));
2421 } 2307 }
2422} 2308}
2423 2309
2424void 2310void
2425at (mapstruct *map, unsigned int x, unsigned int y) 2311at (maptile *map, unsigned int x, unsigned int y)
2426 PROTOTYPE: $$$ 2312 PROTOTYPE: $$$
2427 PPCODE: 2313 PPCODE:
2428{ 2314{
2429 object *o; 2315 object *o;
2430 mapstruct *nmap = 0; 2316 maptile *nmap = 0;
2431 I16 nx, ny; 2317 I16 nx, ny;
2432 2318
2433 get_map_flags (map, &nmap, x, y, &nx, &ny); 2319 get_map_flags (map, &nmap, x, y, &nx, &ny);
2434 2320
2435 if (nmap) 2321 if (nmap)
2436 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) 2322 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
2437 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 2323 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
2438} 2324}
2439 2325
2440SV * 2326SV *
2441bot_at (mapstruct *obj, unsigned int x, unsigned int y) 2327bot_at (maptile *obj, unsigned int x, unsigned int y)
2442 PROTOTYPE: $$$ 2328 PROTOTYPE: $$$
2443 ALIAS: 2329 ALIAS:
2444 top_at = 1 2330 top_at = 1
2445 flags_at = 2 2331 flags_at = 2
2446 light_at = 3 2332 light_at = 3
2463 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; 2349 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break;
2464 } 2350 }
2465 OUTPUT: 2351 OUTPUT:
2466 RETVAL 2352 RETVAL
2467 2353
2354void fix_walls (maptile *map, int x, int y)
2355
2356void fix_walls_around (maptile *map, int x, int y)
2468 2357
2469MODULE = cf PACKAGE = cf::arch 2358MODULE = cf PACKAGE = cf::arch
2470 2359
2471archetype *find (const char *name) 2360archetype *find (const char *name)
2472 CODE: 2361 CODE:
2473 RETVAL = find_archetype (name); 2362 RETVAL = archetype::find (name);
2474 OUTPUT: 2363 OUTPUT:
2475 RETVAL 2364 RETVAL
2476 2365
2477archetype *first() 2366archetype *first()
2478 PROTOTYPE: 2367 PROTOTYPE:
2479 CODE: 2368 CODE:
2480 RETVAL = first_archetype; 2369 RETVAL = first_archetype;
2481 OUTPUT: RETVAL 2370 OUTPUT: RETVAL
2482 2371
2483archetype *next (archetype *arch) 2372INCLUDE: $PERL genacc archetype ../include/object.h |
2484 CODE:
2485 RETVAL = arch->next;
2486 OUTPUT: RETVAL
2487
2488archetype *head (archetype *arch)
2489 CODE:
2490 RETVAL = arch->head;
2491 OUTPUT: RETVAL
2492
2493archetype *more (archetype *arch)
2494 CODE:
2495 RETVAL = arch->more;
2496 OUTPUT: RETVAL
2497
2498const char *name (archetype *arch)
2499 CODE:
2500 RETVAL = arch->name;
2501 OUTPUT: RETVAL
2502
2503object *clone (archetype *arch)
2504 CODE:
2505 RETVAL = &arch->clone;
2506 OUTPUT: RETVAL
2507 2373
2508MODULE = cf PACKAGE = cf::party 2374MODULE = cf PACKAGE = cf::party
2509 2375
2510partylist *first () 2376partylist *first ()
2511 PROTOTYPE: 2377 PROTOTYPE:
2561 RETVAL = reg->msg; 2427 RETVAL = reg->msg;
2562 OUTPUT: RETVAL 2428 OUTPUT: RETVAL
2563 2429
2564MODULE = cf PACKAGE = cf::living 2430MODULE = cf PACKAGE = cf::living
2565 2431
2566val64 2432INCLUDE: $PERL genacc living ../include/living.h |
2567exp (living *liv, val64 new_val = 0)
2568 PROTOTYPE: $;$
2569 ALIAS:
2570 Str = 1
2571 Dex = 2
2572 Con = 3
2573 Wis = 4
2574 Cha = 5
2575 Int = 6
2576 Pow = 7
2577 wc = 8
2578 ac = 9
2579 hp = 10
2580 maxhp = 11
2581 sp = 12
2582 maxsp = 13
2583 grace = 14
2584 maxgrace = 15
2585 food = 16
2586 dam = 17
2587 luck = 18
2588 CODE:
2589# define LIVING_ACC(acc,idx) case idx: RETVAL = liv->acc; if (items > 1) liv->acc = (sint64)new_val; break
2590 switch (ix)
2591 {
2592 LIVING_ACC (exp , 0);
2593 LIVING_ACC (Str , 1);
2594 LIVING_ACC (Dex , 2);
2595 LIVING_ACC (Con , 3);
2596 LIVING_ACC (Wis , 4);
2597 LIVING_ACC (Cha , 5);
2598 LIVING_ACC (Int , 6);
2599 LIVING_ACC (Pow , 7);
2600 LIVING_ACC (wc , 8);
2601 LIVING_ACC (ac , 9);
2602 LIVING_ACC (hp , 10);
2603 LIVING_ACC (maxhp , 11);
2604 LIVING_ACC (sp , 12);
2605 LIVING_ACC (maxsp , 13);
2606 LIVING_ACC (grace , 14);
2607 LIVING_ACC (maxgrace, 15);
2608 LIVING_ACC (food , 16);
2609 LIVING_ACC (dam , 17);
2610 LIVING_ACC (luck , 18);
2611 }
2612# undef LIVING_ACC
2613 OUTPUT:
2614 RETVAL
2615 2433
2434MODULE = cf PACKAGE = cf::settings
2435
2436INCLUDE: $PERL genacc Settings ../include/global.h |
2437
2438MODULE = cf PACKAGE = cf::client
2439
2440INCLUDE: $PERL genacc client ../include/client.h |
2441
2442int invoke (client *ns, int event, ...)
2443 CODE:
2444 if (KLASS_OF (event) != KLASS_SOCKET) croak ("event class must be SOCKET");
2445 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2446 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
2447 RETVAL = INVOKE_((event_type)event, ARG_SOCKET (ns), ARG_AV (av));
2448 OUTPUT: RETVAL
2449
2450SV *registry (client *ns)
2451

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines