ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
Revision: 1.129
Committed: Sun Jan 7 21:54:59 2007 UTC (17 years, 4 months ago) by root
Branch: MAIN
Changes since 1.128: +27 -34 lines
Log Message:
implement quit

File Contents

# Content
1 /*****************************************************************************/
2 /* CrossFire, A Multiplayer game for the X Window System */
3 /*****************************************************************************/
4
5 /*
6 * This code is placed under the GNU General Public Licence (GPL)
7 *
8 * Copyright (C) 2001-2005 by Chachkoff Yann
9 * Copyright (C) 2006 by Marc Lehmann <cf@schmorp.de>
10 *
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
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #define PLUGIN_NAME "perl"
27 #define PLUGIN_VERSION "cfperl 0.5"
28
29 #include <plugin_common.h>
30 #include <sounds.h>
31 #include <cstdarg>
32 #include <sproto.h>
33
34 #include "cfperl.h"
35 #include "shstr.h"
36
37 #include <unistd.h>
38 #if _POSIX_MEMLOCK
39 # include <sys/mman.h>
40 #endif
41
42 #include <EXTERN.h>
43 #include <perl.h>
44 #include <XSUB.h>
45
46 #include "CoroAPI.h"
47 #include "perlxsi.c"
48
49 extern sint64 *levels; // the experience table
50
51 typedef object object_ornull;
52 typedef maptile maptile_ornull;
53
54 #if IVSIZE >= 8
55 typedef IV val64;
56 # define newSVval64 newSViv
57 # define SvVAL64 SvIV
58 #else
59 typedef double val64;
60 # define newSVval64 newSVnv
61 # define SvVAL64 SvNV
62 #endif
63
64 static f_plug_api gethook = cfapi_get_hooks;
65 static f_plug_api object_set_property = cfapi_object_set_property;
66 static f_plug_api object_insert = cfapi_object_insert;
67
68 static PerlInterpreter *perl;
69
70 double runtime;
71
72 global gbl_ev;
73 static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
74 static SV *sv_runtime;
75
76 static HV
77 *stash_cf,
78 *stash_cf_object_wrap,
79 *stash_cf_object_player_wrap,
80 *stash_cf_player_wrap,
81 *stash_cf_map_wrap,
82 *stash_cf_client_wrap,
83 *stash_cf_arch_wrap,
84 *stash_cf_party_wrap,
85 *stash_cf_region_wrap,
86 *stash_cf_living_wrap;
87
88 // helper cast function, returns super class * or 0
89 template<class super>
90 static super *
91 is_a (attachable *at)
92 {
93 //return dynamic_cast<super *>(at); // slower, safer
94 if (typeid (*at) == typeid (super))
95 return static_cast<super *>(at);
96 else
97 return 0;
98 }
99
100 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
101
102 unordered_vector<attachable *> attachable::mortals;
103
104 attachable::~attachable ()
105 {
106 assert (!(flags & F_BORROWED));
107 }
108
109 void attachable::optimise ()
110 {
111 if (self
112 && SvREFCNT (self) == 1
113 && !HvTOTALKEYS (self))
114 {
115 flags &= ~F_BORROWED;
116 refcnt_inc ();
117 SvREFCNT_dec ((SV *)self);
118 }
119 }
120
121 // check wether the object really is dead
122 void
123 attachable::do_check ()
124 {
125 if (refcnt > 0)
126 return;
127
128 optimise ();
129
130 if (self)
131 {
132 if (refcnt + SvREFCNT (self) > 0)
133 return;
134
135 assert (flags & F_BORROWED);
136
137 flags &= ~F_BORROWED;
138 refcnt_inc ();
139 SvREFCNT_dec (self);
140 self = 0;
141 }
142
143 if (refcnt > 0)
144 return;
145
146 destroy ();
147 }
148
149 void
150 attachable::do_destroy ()
151 {
152 invoke (EVENT_ATTACHABLE_DESTROY, DT_END);
153
154 if (self)
155 hv_clear (self);
156
157 mortals.push_back (this);
158 }
159
160 void
161 attachable::destroy ()
162 {
163 if (destroyed ())
164 return;
165
166 flags |= F_DESTROYED;
167 do_destroy ();
168 }
169
170 void attachable::check_mortals ()
171 {
172 for (int i = 0; i < mortals.size (); )
173 {
174 attachable *obj = mortals [i];
175
176 obj->refcnt_chk (); // unborrow from perl, if necessary
177
178 if (obj->refcnt || obj->self)
179 {
180 #if 0
181 if (mortals.size() > 5)fprintf (stderr, "%d delaying %d:%p:%s %d (self %p:%d)\n", time(0),i, obj, typeid (*obj).name (),
182 obj->refcnt, obj->self, obj->self ? SvREFCNT(obj->self): - 1);//D
183 #endif
184
185 ++i; // further delay freeing
186 }//D
187 else
188 {
189 //Dfprintf (stderr, "deleteing %d:%p:%s\n", i, obj,typeid (*obj).name ());//D
190 mortals.erase (i);
191 delete obj;
192 }
193 }
194 }
195
196 attachable &
197 attachable::operator =(const attachable &src)
198 {
199 //if (self || cb)
200 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst));
201
202 attach = src.attach;
203 return *this;
204 }
205
206 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
207
208 static SV *
209 newSVptr (void *ptr, HV *stash, HV *hv = newHV ())
210 {
211 SV *sv;
212
213 if (!ptr)
214 return &PL_sv_undef;
215
216 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
217 return sv_bless (newRV_noinc ((SV *)hv), stash);
218 }
219
220 static int
221 attachable_free (pTHX_ SV *sv, MAGIC *mg)
222 {
223 attachable *at = (attachable *)mg->mg_ptr;
224 assert (!(at->flags & attachable::F_BORROWED));
225 at->self = 0;
226 // next line makes sense, but most objects still have refcnt 0 by default
227 //at->refcnt_chk ();
228 return 0;
229 }
230
231 MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
232
233 static SV *
234 newSVattachable (attachable *obj, HV *stash)
235 {
236 if (!obj)
237 return &PL_sv_undef;
238
239 if (!obj->self)
240 {
241 obj->self = newHV ();
242 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
243
244 // borrow the refcnt from the object
245 obj->flags |= attachable::F_BORROWED;
246 obj->refcnt_dec ();
247
248 // now bless the object _once_
249 return sv_bless (newRV_inc ((SV *)obj->self), stash);
250 }
251 else
252 return newRV_inc ((SV *)obj->self);
253 }
254
255 static void
256 clearSVptr (SV *sv)
257 {
258 if (SvROK (sv))
259 sv = SvRV (sv);
260
261 hv_clear ((HV *)sv);
262 sv_unmagic (sv, PERL_MAGIC_ext);
263 }
264
265 static long
266 SvPTR (SV *sv, const char *klass)
267 {
268 if (!sv_derived_from (sv, klass))
269 croak ("object of type %s expected", klass);
270
271 MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
272
273 if (!mg)
274 croak ("perl code used %s object, but C object is already destroyed, caught", klass);
275
276 return (long)mg->mg_ptr;
277 }
278
279 static long
280 SvPTR_ornull (SV *sv, const char *klass)
281 {
282 if (SvOK (sv))
283 return SvPTR (sv, klass);
284 else
285 return 0;
286 }
287
288 inline SV *to_sv (const shstr & v) { return v ? newSVpvn ((const char *)v, v.length ()) : &PL_sv_undef; }
289 inline SV *to_sv (const char * v) { return newSVpv (v, 0); }
290 inline SV *to_sv (bool v) { return newSViv (v); }
291 inline SV *to_sv ( signed char v) { return newSViv (v); }
292 inline SV *to_sv (unsigned char v) { return newSViv (v); }
293 inline SV *to_sv ( signed short v) { return newSViv (v); }
294 inline SV *to_sv (unsigned short v) { return newSVuv (v); }
295 inline SV *to_sv ( signed int v) { return newSViv (v); }
296 inline SV *to_sv (unsigned int v) { return newSVuv (v); }
297 inline SV *to_sv ( signed long v) { return newSViv (v); }
298 inline SV *to_sv (unsigned long v) { return newSVuv (v); }
299 inline SV *to_sv ( signed long long v) { return newSVval64 (v); }
300 inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
301 inline SV *to_sv (float v) { return newSVnv (v); }
302 inline SV *to_sv (double v) { return newSVnv (v); }
303 inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
304 inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
305 inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
306 inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
307 inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
308 inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
309 inline SV *to_sv (region * v) { return newSVptr (v, stash_cf_region_wrap); }
310 inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
311
312 inline SV *to_sv (object & v) { return to_sv (&v); }
313 inline SV *to_sv (living & v) { return to_sv (&v); }
314
315 //TODO:
316 inline SV *to_sv (New_Face * v) { return to_sv (v->name); }
317 inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
318
319 inline SV *to_sv (UUID v)
320 {
321 char buf[128];
322 snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq);
323 return newSVpv (buf, 0);
324 }
325
326 inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; }
327 inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
328 inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
329 inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); }
330 inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); }
331 inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); }
332 inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); }
333 inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); }
334 inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); }
335 inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); }
336 inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
337 inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
338 inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
339 inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
340 inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
341 inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); }
342 inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); }
343 inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); }
344 inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
345 inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); }
346 inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
347 inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
348 inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
349 inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
350
351 inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO
352 inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } // TODO
353
354 template<class T>
355 inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
356
357 template<int N>
358 inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
359
360 inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
361 inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); }
362 inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); }
363 inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
364 inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
365
366 inline void sv_to (SV *sv, UUID &v)
367 {
368 unsigned int version;
369
370 if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version)
371 croak ("unparsable uuid: %s", SvPV_nolen (sv));
372 }
373
374 inline void sv_to (SV *sv, object::flags_t::reference v) { v = SvTRUE (sv); }
375
376 static SV *
377 newSVdt_va (va_list &ap, data_type type)
378 {
379 SV *sv;
380
381 switch (type)
382 {
383 case DT_INT:
384 sv = newSViv (va_arg (ap, int));
385 break;
386
387 case DT_INT64:
388 sv = newSVval64 ((val64)va_arg (ap, sint64));
389 break;
390
391 case DT_DOUBLE:
392 sv = newSVnv (va_arg (ap, double));
393 break;
394
395 case DT_STRING:
396 {
397 char *str = (char *)va_arg (ap, const char *);
398 sv = str ? newSVpv (str, 0) : &PL_sv_undef;
399 }
400 break;
401
402 case DT_DATA:
403 {
404 char *str = (char *)va_arg (ap, const void *);
405 int len = va_arg (ap, int);
406 sv = str ? newSVpv (str, len) : &PL_sv_undef;
407 }
408 break;
409
410 case DT_OBJECT:
411 sv = to_sv (va_arg (ap, object *));
412 break;
413
414 case DT_MAP:
415 // va_arg (object *) when void * is passed is an XSI extension
416 sv = to_sv (va_arg (ap, maptile *));
417 break;
418
419 case DT_CLIENT:
420 sv = to_sv (va_arg (ap, client *));
421 break;
422
423 case DT_PLAYER:
424 sv = to_sv (va_arg (ap, player *));
425 break;
426
427 case DT_ARCH:
428 sv = to_sv (va_arg (ap, archetype *));
429 break;
430
431 case DT_PARTY:
432 sv = to_sv (va_arg (ap, partylist *));
433 break;
434
435 case DT_REGION:
436 sv = to_sv (va_arg (ap, region *));
437 break;
438
439 default:
440 assert (("unhandled type in newSVdt_va", 0));
441 }
442
443 return sv;
444 }
445
446 static SV *
447 newSVdt (data_type type, ...)
448 {
449 va_list ap;
450
451 va_start (ap, type);
452 SV *sv = newSVdt_va (ap, type);
453 va_end (ap);
454
455 return sv;
456 }
457
458 static SV *
459 newSVcfapi (int type, ...)
460 {
461 SV *sv;
462
463 va_list ap;
464 va_start (ap, type);
465
466 switch (type)
467 {
468 case CFAPI_INT: sv = newSViv (*va_arg (ap, int * )); break;
469 case CFAPI_LONG: sv = newSVval64 (*va_arg (ap, sint64 *)); break;
470 case CFAPI_DOUBLE: sv = newSVnv (*va_arg (ap, double *)); break;
471 case CFAPI_STRING: sv = newSVdt_va (ap, DT_STRING); break;
472 case CFAPI_POBJECT: sv = newSVdt_va (ap, DT_OBJECT); break;
473 case CFAPI_PMAP: sv = newSVdt_va (ap, DT_MAP ); break;
474 case CFAPI_PPLAYER: sv = newSVdt_va (ap, DT_PLAYER); break;
475 case CFAPI_PARCH: sv = newSVdt_va (ap, DT_ARCH ); break;
476 case CFAPI_PPARTY: sv = newSVdt_va (ap, DT_PARTY ); break;
477 case CFAPI_PREGION: sv = newSVdt_va (ap, DT_REGION); break;
478
479 default:
480 assert (("unhandled type in newSVcfapi", 0));
481 }
482
483 va_end (ap);
484
485 return sv;
486 }
487
488 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
489
490 SV *
491 registry (attachable *ext)
492 {
493 if (!ext->cb)
494 ext->cb = newAV ();
495
496 return newRV_inc ((SV *)ext->cb);
497 }
498
499 #if 0
500 void attachable::clear ()
501 {
502 if (self)
503 {
504 // disconnect Perl from C, to avoid crashes
505 sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext);
506
507 // clear the perl hash, might or might not be a good idea
508 hv_clear ((HV *)SvRV ((SV *)self));
509
510 SvREFCNT_dec (self);
511 self = 0;
512 }
513
514 if (cb)
515 {
516 SvREFCNT_dec (cb);
517 cb = 0;
518 }
519
520 attach = 0;
521 }
522 #endif
523
524 /////////////////////////////////////////////////////////////////////////////
525
526 extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr)
527 {
528 return 0;
529 }
530
531 static CommArray_s rtn_cmd;
532
533 static int
534 runPluginCommand (object *obj, char *params)
535 {
536 return -1;
537 }
538
539 extern "C" void *cfperl_getPluginProperty (int *type, ...)
540 {
541 va_list args;
542 char *propname;
543 int i;
544 va_start (args, type);
545 propname = va_arg (args, char *);
546 //printf ("Property name: %s\n", propname);
547
548 if (!strcmp (propname, "command?"))
549 return NULL;
550 else if (!strcmp (propname, "Identification"))
551 {
552 va_end (args);
553 return (void *)PLUGIN_NAME;
554 }
555 else if (!strcmp (propname, "FullName"))
556 {
557 va_end (args);
558 return (void *)PLUGIN_VERSION;
559 }
560 else
561 va_end (args);
562
563 return NULL;
564 }
565
566 extern "C" int cfperl_postInitPlugin ()
567 {
568 int hooktype = 1;
569 int rtype = 0;
570
571 cf_init_plugin (gethook);
572
573 return 0;
574 }
575
576 extern "C" int cfperl_closePlugin ()
577 {
578 return 0;
579 }
580
581 void
582 cfperl_init ()
583 {
584 PERL_SYS_INIT3 (&settings.argc, &settings.argv, 0);
585 perl = perl_alloc ();
586 perl_construct (perl);
587
588 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
589
590 char *argv[] = {
591 "",
592 "-e"
593 "use Event; use Coro;" // required for bootstrap
594 "cf->bootstrap;" // required for datadir :*>
595 "unshift @INC, cf::datadir ();"
596 "require cf;"
597 };
598
599 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
600 {
601 printf ("unable to initialize perl-interpreter, aborting.\n");
602 exit (EXIT_FAILURE);
603 }
604 }
605
606 void cfperl_main ()
607 {
608 dSP;
609
610 PUSHMARK (SP);
611 PUTBACK;
612 call_pv ("cf::main", G_DISCARD | G_VOID);
613 }
614
615 void
616 attachable::instantiate ()
617 {
618 if (attach)
619 {
620 invoke (EVENT_ATTACHABLE_INSTANTIATE, ARG_STRING (attach), DT_END);
621 attach = 0;
622 }
623 }
624
625 void
626 attachable::reattach ()
627 {
628 optimise ();
629 //TODO: check for _attachment's, very important for restarts
630 invoke (EVENT_ATTACHABLE_REATTACH, DT_END);
631 }
632
633 static event_klass klass_of[NUM_EVENT_TYPES] = {
634 # define def(type,name) KLASS_ ## type,
635 # include "eventinc.h"
636 # undef def
637 };
638
639 #define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE)
640
641 static void
642 gather_callbacks (AV *&callbacks, AV *registry, event_type event)
643 {
644 // event must be in array
645 if (event >= 0 && event <= AvFILLp (registry))
646 {
647 SV *cbs_ = AvARRAY (registry)[event];
648
649 // element must be list of callback entries
650 if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV)
651 {
652 AV *cbs = (AV *)SvRV (cbs_);
653
654 // no callback entries, no callbacks to call
655 if (AvFILLp (cbs) >= 0)
656 {
657 if (!callbacks)
658 {
659 callbacks = newAV ();
660 av_extend (callbacks, 16);
661 }
662
663 // never use SvREFCNT_inc to copy values, but its ok here :)
664 for (int i = 0; i <= AvFILLp (cbs); ++i)
665 av_push (callbacks, SvREFCNT_inc (AvARRAY (cbs)[i]));
666 }
667 }
668 }
669 }
670
671 void
672 attachable::gather_callbacks (AV *&callbacks, event_type event) const
673 {
674 ::gather_callbacks (callbacks, cb_attachable, event);
675
676 if (cb)
677 ::gather_callbacks (callbacks, cb, event);
678 }
679
680 void
681 global::gather_callbacks (AV *&callbacks, event_type event) const
682 {
683 ::gather_callbacks (callbacks, cb_object, event);
684 }
685
686 void
687 object::gather_callbacks (AV *&callbacks, event_type event) const
688 {
689 if (subtype && type + subtype * NUM_SUBTYPES <= AvFILLp (cb_type))
690 {
691 SV *registry = AvARRAY (cb_type)[type + subtype * NUM_SUBTYPES];
692
693 if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV)
694 ::gather_callbacks (callbacks, (AV *)SvRV (registry), event);
695 }
696
697 if (type <= AvFILLp (cb_type))
698 {
699 SV *registry = AvARRAY (cb_type)[type];
700
701 if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV)
702 ::gather_callbacks (callbacks, (AV *)SvRV (registry), event);
703 }
704
705 attachable::gather_callbacks (callbacks, event);
706 ::gather_callbacks (callbacks, cb_object, event);
707 }
708
709 void
710 archetype::gather_callbacks (AV *&callbacks, event_type event) const
711 {
712 attachable::gather_callbacks (callbacks, event);
713 //TODO//::gather_callbacks (callbacks, cb_archetype, event);
714 }
715
716 void
717 client::gather_callbacks (AV *&callbacks, event_type event) const
718 {
719 attachable::gather_callbacks (callbacks, event);
720 ::gather_callbacks (callbacks, cb_client, event);
721 }
722
723 void
724 player::gather_callbacks (AV *&callbacks, event_type event) const
725 {
726 attachable::gather_callbacks (callbacks, event);
727 ::gather_callbacks (callbacks, cb_player, event);
728 }
729
730 void
731 maptile::gather_callbacks (AV *&callbacks, event_type event) const
732 {
733 attachable::gather_callbacks (callbacks, event);
734 ::gather_callbacks (callbacks, cb_map, event);
735 }
736
737 bool
738 attachable::invoke (event_type event, ...)
739 {
740 data_type dt;
741 va_list ap;
742
743 va_start (ap, event);
744
745 // callback call ordering should be:
746 // 1. per-object callback
747 // 2. per-class object
748 // 3. per-type callback
749 // 4. global callbacks
750
751 AV *callbacks = 0;
752 gather_callbacks (callbacks, event);
753
754 // short-circuit processing if no callbacks found/defined
755 if (!callbacks)
756 return 0;
757
758 CALL_BEGIN (3);
759 CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays
760 CALL_ARG_SV (newRV_noinc ((SV *)callbacks));
761
762 //TODO: unhack
763 if (object *op = is_a<object>(this)) CALL_ARG_SV (newSVdt (DT_OBJECT, op));
764 else if (player *pl = is_a<player>(this)) CALL_ARG_SV (newSVdt (DT_PLAYER, pl));
765 else if (client *ns = is_a<client>(this)) CALL_ARG_SV (newSVdt (DT_CLIENT, ns));
766 else if (maptile *m = is_a<maptile>(this)) CALL_ARG_SV (newSVdt (DT_MAP, m));
767 else if (global *gl = is_a<global>(this)) /*nop*/;
768 else
769 abort (); //TODO
770
771 for (;;)
772 {
773 dt = (data_type) va_arg (ap, int);
774
775 if (dt == DT_END)
776 break;
777 else if (dt == DT_AV)
778 {
779 AV *av = va_arg (ap, AV *);
780
781 for (int i = 0; i <= av_len (av); ++i)
782 XPUSHs (*av_fetch (av, i, 1));
783 }
784 else
785 XPUSHs (sv_2mortal (newSVdt_va (ap, dt)));
786 }
787
788 va_end (ap);
789
790 CALL_CALL ("cf::do_invoke", G_SCALAR);
791 count = count > 0 ? POPi : 0;
792
793 CALL_END;
794
795 return count;
796 }
797
798 SV *
799 cfperl_result (int idx)
800 {
801 AV *av = get_av ("cfperl::invoke_results", 0);
802 if (!av)
803 return &PL_sv_undef;
804
805 SV **sv = av_fetch (av, idx, 0);
806 if (!sv)
807 return &PL_sv_undef;
808
809 return *sv;
810 }
811
812 int
813 cfperl_result_INT (int idx)
814 {
815 return SvIV (cfperl_result (idx));
816 }
817
818 double
819 cfperl_result_DOUBLE (int idx)
820 {
821 return SvNV (cfperl_result (idx));
822 }
823
824 /////////////////////////////////////////////////////////////////////////////
825
826 void
827 maptile::emergency_save ()
828 {
829 CALL_BEGIN (0);
830 CALL_CALL ("cf::map::emergency_save", G_VOID);
831 CALL_END;
832 }
833
834 maptile *
835 maptile::find_sync (const char *path, maptile *origin)
836 {
837 CALL_BEGIN (2);
838 CALL_ARG (path);
839 CALL_ARG (origin);
840 CALL_CALL ("cf::map::find_sync", G_SCALAR);
841
842 maptile *retval;
843
844 if (count)
845 sv_to (POPs, retval);
846 else
847 retval = 0;
848
849 CALL_END;
850
851 return retval;
852 }
853
854 void
855 maptile::do_load_sync ()
856 {
857 CALL_BEGIN (1);
858 CALL_ARG (this);
859 CALL_CALL ("cf::map::do_load_sync", G_SCALAR);
860 CALL_END;
861 }
862
863 void
864 maptile::change_all_map_light (int change)
865 {
866 CALL_BEGIN (1);
867 CALL_ARG (change);
868 CALL_CALL ("cf::map::change_all_map_light", G_VOID);
869 CALL_END;
870 }
871
872 void
873 object::enter_exit (object *exit)
874 {
875 if (type != PLAYER)
876 return;
877
878 CALL_BEGIN (2);
879 CALL_ARG (this);
880 CALL_ARG (exit);
881 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
882 CALL_END;
883 }
884
885 /////////////////////////////////////////////////////////////////////////////
886
887 struct EventAPI *watcher_base::GEventAPI;
888 struct CoroAPI *coroapi::GCoroAPI;
889
890 int coroapi::cede_counter;
891
892 static void iw_dispatch (pe_event *ev)
893 {
894 iw *w = (iw *)ev->ext_data;
895 w->call (*w);
896 }
897
898 void
899 iw::alloc ()
900 {
901 pe = GEventAPI->new_idle (0, 0);
902
903 pe->base.callback = (void *)iw_dispatch;
904 pe->base.ext_data = (void *)this;
905 }
906
907 static void iow_dispatch (pe_event *ev)
908 {
909 iow *w = (iow *)ev->ext_data;
910 w->call (*w, ((pe_ioevent *)ev)->got);
911 }
912
913 void
914 iow::alloc ()
915 {
916 pe = GEventAPI->new_io (0, 0);
917
918 pe->base.callback = (void *)iow_dispatch;
919 pe->base.ext_data = (void *)this;
920
921 pe->fd = -1;
922 pe->poll = 0;
923 }
924
925 void
926 iow::fd (int fd)
927 {
928 pe->fd = fd;
929 }
930
931 int
932 iow::poll ()
933 {
934 return pe->poll;
935 }
936
937 void
938 iow::poll (int events)
939 {
940 if (pe->poll != events)
941 {
942 if (pe->poll) stop ();
943 pe->poll = events;
944 if (pe->poll) start ();
945 }
946 }
947
948 void
949 _connect_to_perl ()
950 {
951 stash_cf = gv_stashpv ("cf" , 1);
952
953 stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1);
954 stash_cf_object_player_wrap = gv_stashpv ("cf::object::player::wrap", 1);
955 stash_cf_player_wrap = gv_stashpv ("cf::player::wrap", 1);
956 stash_cf_map_wrap = gv_stashpv ("cf::map::wrap" , 1);
957 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
958 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
959 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
960 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
961 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
962
963 sv_runtime = get_sv ("cf::RUNTIME", 1);
964 sv_upgrade (sv_runtime, SVt_NV);
965
966 cb_global = get_av ("cf::CB_GLOBAL", 1);
967 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
968 cb_object = get_av ("cf::CB_OBJECT", 1);
969 cb_player = get_av ("cf::CB_PLAYER", 1);
970 cb_client = get_av ("cf::CB_CLIENT", 1);
971 cb_type = get_av ("cf::CB_TYPE" , 1);
972 cb_map = get_av ("cf::CB_MAP" , 1);
973 }
974
975 MODULE = cf PACKAGE = cf PREFIX = cf_
976
977 BOOT:
978 {
979 _connect_to_perl ();
980
981 I_EVENT_API (PACKAGE); watcher_base::GEventAPI = GEventAPI;
982 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
983
984 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
985
986 static const struct {
987 const char *name;
988 IV iv;
989 } *civ, const_iv[] = {
990 # define const_iv(name) { # name, (IV)name },
991 const_iv (llevError)
992 const_iv (llevInfo)
993 const_iv (llevDebug)
994 const_iv (llevMonster)
995
996 const_iv (MAX_TIME)
997 const_iv (PLAYER)
998 const_iv (TRANSPORT)
999 const_iv (ROD)
1000 const_iv (TREASURE)
1001 const_iv (POTION)
1002 const_iv (FOOD)
1003 const_iv (POISON)
1004 const_iv (BOOK)
1005 const_iv (CLOCK)
1006 const_iv (ARROW)
1007 const_iv (BOW)
1008 const_iv (WEAPON)
1009 const_iv (ARMOUR)
1010 const_iv (PEDESTAL)
1011 const_iv (ALTAR)
1012 const_iv (LOCKED_DOOR)
1013 const_iv (SPECIAL_KEY)
1014 const_iv (MAP)
1015 const_iv (DOOR)
1016 const_iv (KEY)
1017 const_iv (TIMED_GATE)
1018 const_iv (TRIGGER)
1019 const_iv (GRIMREAPER)
1020 const_iv (MAGIC_EAR)
1021 const_iv (TRIGGER_BUTTON)
1022 const_iv (TRIGGER_ALTAR)
1023 const_iv (TRIGGER_PEDESTAL)
1024 const_iv (SHIELD)
1025 const_iv (HELMET)
1026 const_iv (HORN)
1027 const_iv (MONEY)
1028 const_iv (CLASS)
1029 const_iv (GRAVESTONE)
1030 const_iv (AMULET)
1031 const_iv (PLAYERMOVER)
1032 const_iv (TELEPORTER)
1033 const_iv (CREATOR)
1034 const_iv (SKILL)
1035 const_iv (EARTHWALL)
1036 const_iv (GOLEM)
1037 const_iv (THROWN_OBJ)
1038 const_iv (BLINDNESS)
1039 const_iv (GOD)
1040 const_iv (DETECTOR)
1041 const_iv (TRIGGER_MARKER)
1042 const_iv (DEAD_OBJECT)
1043 const_iv (DRINK)
1044 const_iv (MARKER)
1045 const_iv (HOLY_ALTAR)
1046 const_iv (PLAYER_CHANGER)
1047 const_iv (BATTLEGROUND)
1048 const_iv (PEACEMAKER)
1049 const_iv (GEM)
1050 const_iv (FIREWALL)
1051 const_iv (ANVIL)
1052 const_iv (CHECK_INV)
1053 const_iv (MOOD_FLOOR)
1054 const_iv (EXIT)
1055 const_iv (ENCOUNTER)
1056 const_iv (SHOP_FLOOR)
1057 const_iv (SHOP_MAT)
1058 const_iv (RING)
1059 const_iv (FLOOR)
1060 const_iv (FLESH)
1061 const_iv (INORGANIC)
1062 const_iv (SKILL_TOOL)
1063 const_iv (LIGHTER)
1064 const_iv (BUILDABLE_WALL)
1065 const_iv (MISC_OBJECT)
1066 const_iv (LAMP)
1067 const_iv (DUPLICATOR)
1068 const_iv (SPELLBOOK)
1069 const_iv (CLOAK)
1070 const_iv (SPINNER)
1071 const_iv (GATE)
1072 const_iv (BUTTON)
1073 const_iv (CF_HANDLE)
1074 const_iv (HOLE)
1075 const_iv (TRAPDOOR)
1076 const_iv (SIGN)
1077 const_iv (BOOTS)
1078 const_iv (GLOVES)
1079 const_iv (SPELL)
1080 const_iv (SPELL_EFFECT)
1081 const_iv (CONVERTER)
1082 const_iv (BRACERS)
1083 const_iv (POISONING)
1084 const_iv (SAVEBED)
1085 const_iv (WAND)
1086 const_iv (SCROLL)
1087 const_iv (DIRECTOR)
1088 const_iv (GIRDLE)
1089 const_iv (FORCE)
1090 const_iv (POTION_EFFECT)
1091 const_iv (EVENT_CONNECTOR)
1092 const_iv (CLOSE_CON)
1093 const_iv (CONTAINER)
1094 const_iv (ARMOUR_IMPROVER)
1095 const_iv (WEAPON_IMPROVER)
1096 const_iv (SKILLSCROLL)
1097 const_iv (DEEP_SWAMP)
1098 const_iv (IDENTIFY_ALTAR)
1099 const_iv (MENU)
1100 const_iv (RUNE)
1101 const_iv (TRAP)
1102 const_iv (POWER_CRYSTAL)
1103 const_iv (CORPSE)
1104 const_iv (DISEASE)
1105 const_iv (SYMPTOM)
1106 const_iv (BUILDER)
1107 const_iv (MATERIAL)
1108 const_iv (ITEM_TRANSFORMER)
1109
1110 const_iv (NUM_SUBTYPES)
1111
1112 const_iv (ST_BD_BUILD)
1113 const_iv (ST_BD_REMOVE)
1114
1115 const_iv (ST_MAT_FLOOR)
1116 const_iv (ST_MAT_WALL)
1117 const_iv (ST_MAT_ITEM)
1118
1119 const_iv (AT_PHYSICAL)
1120 const_iv (AT_MAGIC)
1121 const_iv (AT_FIRE)
1122 const_iv (AT_ELECTRICITY)
1123 const_iv (AT_COLD)
1124 const_iv (AT_CONFUSION)
1125 const_iv (AT_ACID)
1126 const_iv (AT_DRAIN)
1127 const_iv (AT_WEAPONMAGIC)
1128 const_iv (AT_GHOSTHIT)
1129 const_iv (AT_POISON)
1130 const_iv (AT_SLOW)
1131 const_iv (AT_PARALYZE)
1132 const_iv (AT_TURN_UNDEAD)
1133 const_iv (AT_FEAR)
1134 const_iv (AT_CANCELLATION)
1135 const_iv (AT_DEPLETE)
1136 const_iv (AT_DEATH)
1137 const_iv (AT_CHAOS)
1138 const_iv (AT_COUNTERSPELL)
1139 const_iv (AT_GODPOWER)
1140 const_iv (AT_HOLYWORD)
1141 const_iv (AT_BLIND)
1142 const_iv (AT_INTERNAL)
1143 const_iv (AT_LIFE_STEALING)
1144 const_iv (AT_DISEASE)
1145
1146 const_iv (WEAP_HIT)
1147 const_iv (WEAP_SLASH)
1148 const_iv (WEAP_PIERCE)
1149 const_iv (WEAP_CLEAVE)
1150 const_iv (WEAP_SLICE)
1151 const_iv (WEAP_STAB)
1152 const_iv (WEAP_WHIP)
1153 const_iv (WEAP_CRUSH)
1154 const_iv (WEAP_BLUD)
1155
1156 const_iv (FLAG_ALIVE)
1157 const_iv (FLAG_WIZ)
1158 const_iv (FLAG_REMOVED)
1159 const_iv (FLAG_FREED)
1160 const_iv (FLAG_WAS_WIZ)
1161 const_iv (FLAG_APPLIED)
1162 const_iv (FLAG_UNPAID)
1163 const_iv (FLAG_USE_SHIELD)
1164 const_iv (FLAG_NO_PICK)
1165 const_iv (FLAG_ANIMATE)
1166 const_iv (FLAG_MONSTER)
1167 const_iv (FLAG_FRIENDLY)
1168 const_iv (FLAG_GENERATOR)
1169 const_iv (FLAG_IS_THROWN)
1170 const_iv (FLAG_AUTO_APPLY)
1171 const_iv (FLAG_PLAYER_SOLD)
1172 const_iv (FLAG_SEE_INVISIBLE)
1173 const_iv (FLAG_CAN_ROLL)
1174 const_iv (FLAG_OVERLAY_FLOOR)
1175 const_iv (FLAG_IS_TURNABLE)
1176 const_iv (FLAG_IS_USED_UP)
1177 const_iv (FLAG_IDENTIFIED)
1178 const_iv (FLAG_REFLECTING)
1179 const_iv (FLAG_CHANGING)
1180 const_iv (FLAG_SPLITTING)
1181 const_iv (FLAG_HITBACK)
1182 const_iv (FLAG_STARTEQUIP)
1183 const_iv (FLAG_BLOCKSVIEW)
1184 const_iv (FLAG_UNDEAD)
1185 const_iv (FLAG_SCARED)
1186 const_iv (FLAG_UNAGGRESSIVE)
1187 const_iv (FLAG_REFL_MISSILE)
1188 const_iv (FLAG_REFL_SPELL)
1189 const_iv (FLAG_NO_MAGIC)
1190 const_iv (FLAG_NO_FIX_PLAYER)
1191 const_iv (FLAG_IS_LIGHTABLE)
1192 const_iv (FLAG_TEAR_DOWN)
1193 const_iv (FLAG_RUN_AWAY)
1194 const_iv (FLAG_PICK_UP)
1195 const_iv (FLAG_UNIQUE)
1196 const_iv (FLAG_NO_DROP)
1197 const_iv (FLAG_WIZCAST)
1198 const_iv (FLAG_CAST_SPELL)
1199 const_iv (FLAG_USE_SCROLL)
1200 const_iv (FLAG_USE_RANGE)
1201 const_iv (FLAG_USE_BOW)
1202 const_iv (FLAG_USE_ARMOUR)
1203 const_iv (FLAG_USE_WEAPON)
1204 const_iv (FLAG_USE_RING)
1205 const_iv (FLAG_READY_RANGE)
1206 const_iv (FLAG_READY_BOW)
1207 const_iv (FLAG_XRAYS)
1208 const_iv (FLAG_NO_APPLY)
1209 const_iv (FLAG_IS_FLOOR)
1210 const_iv (FLAG_LIFESAVE)
1211 const_iv (FLAG_NO_STRENGTH)
1212 const_iv (FLAG_SLEEP)
1213 const_iv (FLAG_STAND_STILL)
1214 const_iv (FLAG_RANDOM_MOVE)
1215 const_iv (FLAG_ONLY_ATTACK)
1216 const_iv (FLAG_CONFUSED)
1217 const_iv (FLAG_STEALTH)
1218 const_iv (FLAG_WIZPASS)
1219 const_iv (FLAG_IS_LINKED)
1220 const_iv (FLAG_CURSED)
1221 const_iv (FLAG_DAMNED)
1222 const_iv (FLAG_SEE_ANYWHERE)
1223 const_iv (FLAG_KNOWN_MAGICAL)
1224 const_iv (FLAG_KNOWN_CURSED)
1225 const_iv (FLAG_CAN_USE_SKILL)
1226 const_iv (FLAG_BEEN_APPLIED)
1227 const_iv (FLAG_READY_SCROLL)
1228 const_iv (FLAG_USE_ROD)
1229 const_iv (FLAG_USE_HORN)
1230 const_iv (FLAG_MAKE_INVIS)
1231 const_iv (FLAG_INV_LOCKED)
1232 const_iv (FLAG_IS_WOODED)
1233 const_iv (FLAG_IS_HILLY)
1234 const_iv (FLAG_READY_SKILL)
1235 const_iv (FLAG_READY_WEAPON)
1236 const_iv (FLAG_NO_SKILL_IDENT)
1237 const_iv (FLAG_BLIND)
1238 const_iv (FLAG_SEE_IN_DARK)
1239 const_iv (FLAG_IS_CAULDRON)
1240 const_iv (FLAG_NO_STEAL)
1241 const_iv (FLAG_ONE_HIT)
1242 const_iv (FLAG_CLIENT_SENT)
1243 const_iv (FLAG_BERSERK)
1244 const_iv (FLAG_NEUTRAL)
1245 const_iv (FLAG_NO_ATTACK)
1246 const_iv (FLAG_NO_DAMAGE)
1247 const_iv (FLAG_OBJ_ORIGINAL)
1248 const_iv (FLAG_OBJ_SAVE_ON_OVL)
1249 const_iv (FLAG_ACTIVATE_ON_PUSH)
1250 const_iv (FLAG_ACTIVATE_ON_RELEASE)
1251 const_iv (FLAG_IS_WATER)
1252 const_iv (FLAG_CONTENT_ON_GEN)
1253 const_iv (FLAG_IS_A_TEMPLATE)
1254 const_iv (FLAG_IS_BUILDABLE)
1255
1256 const_iv (NDI_BLACK)
1257 const_iv (NDI_WHITE)
1258 const_iv (NDI_NAVY)
1259 const_iv (NDI_RED)
1260 const_iv (NDI_ORANGE)
1261 const_iv (NDI_BLUE)
1262 const_iv (NDI_DK_ORANGE)
1263 const_iv (NDI_GREEN)
1264 const_iv (NDI_LT_GREEN)
1265 const_iv (NDI_GREY)
1266 const_iv (NDI_BROWN)
1267 const_iv (NDI_GOLD)
1268 const_iv (NDI_TAN)
1269 const_iv (NDI_MAX_COLOR)
1270 const_iv (NDI_COLOR_MASK)
1271 const_iv (NDI_UNIQUE)
1272 const_iv (NDI_ALL)
1273
1274 const_iv (UPD_LOCATION)
1275 const_iv (UPD_FLAGS)
1276 const_iv (UPD_WEIGHT)
1277 const_iv (UPD_FACE)
1278 const_iv (UPD_NAME)
1279 const_iv (UPD_ANIM)
1280 const_iv (UPD_ANIMSPEED)
1281 const_iv (UPD_NROF)
1282
1283 const_iv (UPD_SP_MANA)
1284 const_iv (UPD_SP_GRACE)
1285 const_iv (UPD_SP_DAMAGE)
1286
1287 const_iv (F_APPLIED)
1288 const_iv (F_LOCATION)
1289 const_iv (F_UNPAID)
1290 const_iv (F_MAGIC)
1291 const_iv (F_CURSED)
1292 const_iv (F_DAMNED)
1293 const_iv (F_OPEN)
1294 const_iv (F_NOPICK)
1295 const_iv (F_LOCKED)
1296
1297 const_iv (F_BUY)
1298 const_iv (F_SHOP)
1299 const_iv (F_SELL)
1300
1301 const_iv (P_BLOCKSVIEW)
1302 const_iv (P_PLAYER)
1303 const_iv (P_NO_MAGIC)
1304 const_iv (P_IS_ALIVE)
1305 const_iv (P_NO_CLERIC)
1306 const_iv (P_OUT_OF_MAP)
1307 const_iv (P_NEW_MAP)
1308 const_iv (P_UPTODATE)
1309
1310 const_iv (UP_OBJ_INSERT)
1311 const_iv (UP_OBJ_REMOVE)
1312 const_iv (UP_OBJ_CHANGE)
1313 const_iv (UP_OBJ_FACE)
1314
1315 const_iv (INS_NO_MERGE)
1316 const_iv (INS_ABOVE_FLOOR_ONLY)
1317 const_iv (INS_NO_WALK_ON)
1318 const_iv (INS_ON_TOP)
1319 const_iv (INS_BELOW_ORIGINATOR)
1320 const_iv (INS_MAP_LOAD)
1321
1322 const_iv (WILL_APPLY_HANDLE)
1323 const_iv (WILL_APPLY_TREASURE)
1324 const_iv (WILL_APPLY_EARTHWALL)
1325 const_iv (WILL_APPLY_DOOR)
1326 const_iv (WILL_APPLY_FOOD)
1327
1328 const_iv (SAVE_MODE)
1329 const_iv (SAVE_DIR_MODE)
1330
1331 const_iv (M_PAPER)
1332 const_iv (M_IRON)
1333 const_iv (M_GLASS)
1334 const_iv (M_LEATHER)
1335 const_iv (M_WOOD)
1336 const_iv (M_ORGANIC)
1337 const_iv (M_STONE)
1338 const_iv (M_CLOTH)
1339 const_iv (M_ADAMANT)
1340 const_iv (M_LIQUID)
1341 const_iv (M_SOFT_METAL)
1342 const_iv (M_BONE)
1343 const_iv (M_ICE)
1344 const_iv (M_SPECIAL)
1345
1346 const_iv (SK_EXP_ADD_SKILL)
1347 const_iv (SK_EXP_TOTAL)
1348 const_iv (SK_EXP_NONE)
1349 const_iv (SK_SUBTRACT_SKILL_EXP)
1350 const_iv (SK_EXP_SKILL_ONLY)
1351
1352 const_iv (SK_LOCKPICKING)
1353 const_iv (SK_HIDING)
1354 const_iv (SK_SMITHERY)
1355 const_iv (SK_BOWYER)
1356 const_iv (SK_JEWELER)
1357 const_iv (SK_ALCHEMY)
1358 const_iv (SK_STEALING)
1359 const_iv (SK_LITERACY)
1360 const_iv (SK_BARGAINING)
1361 const_iv (SK_JUMPING)
1362 const_iv (SK_DET_MAGIC)
1363 const_iv (SK_ORATORY)
1364 const_iv (SK_SINGING)
1365 const_iv (SK_DET_CURSE)
1366 const_iv (SK_FIND_TRAPS)
1367 const_iv (SK_MEDITATION)
1368 const_iv (SK_PUNCHING)
1369 const_iv (SK_FLAME_TOUCH)
1370 const_iv (SK_KARATE)
1371 const_iv (SK_CLIMBING)
1372 const_iv (SK_WOODSMAN)
1373 const_iv (SK_INSCRIPTION)
1374 const_iv (SK_ONE_HANDED_WEAPON)
1375 const_iv (SK_MISSILE_WEAPON)
1376 const_iv (SK_THROWING)
1377 const_iv (SK_USE_MAGIC_ITEM)
1378 const_iv (SK_DISARM_TRAPS)
1379 const_iv (SK_SET_TRAP)
1380 const_iv (SK_THAUMATURGY)
1381 const_iv (SK_PRAYING)
1382 const_iv (SK_CLAWING)
1383 const_iv (SK_LEVITATION)
1384 const_iv (SK_SUMMONING)
1385 const_iv (SK_PYROMANCY)
1386 const_iv (SK_EVOCATION)
1387 const_iv (SK_SORCERY)
1388 const_iv (SK_TWO_HANDED_WEAPON)
1389 const_iv (SK_SPARK_TOUCH)
1390 const_iv (SK_SHIVER)
1391 const_iv (SK_ACID_SPLASH)
1392 const_iv (SK_POISON_NAIL)
1393
1394 const_iv (SOUND_NEW_PLAYER)
1395 const_iv (SOUND_FIRE_ARROW)
1396 const_iv (SOUND_LEARN_SPELL)
1397 const_iv (SOUND_FUMBLE_SPELL)
1398 const_iv (SOUND_WAND_POOF)
1399 const_iv (SOUND_OPEN_DOOR)
1400 const_iv (SOUND_PUSH_PLAYER)
1401 const_iv (SOUND_PLAYER_HITS1)
1402 const_iv (SOUND_PLAYER_HITS2)
1403 const_iv (SOUND_PLAYER_HITS3)
1404 const_iv (SOUND_PLAYER_HITS4)
1405 const_iv (SOUND_PLAYER_IS_HIT1)
1406 const_iv (SOUND_PLAYER_IS_HIT2)
1407 const_iv (SOUND_PLAYER_IS_HIT3)
1408 const_iv (SOUND_PLAYER_KILLS)
1409 const_iv (SOUND_PET_IS_KILLED)
1410 const_iv (SOUND_PLAYER_DIES)
1411 const_iv (SOUND_OB_EVAPORATE)
1412 const_iv (SOUND_OB_EXPLODE)
1413 const_iv (SOUND_CLOCK)
1414 const_iv (SOUND_TURN_HANDLE)
1415 const_iv (SOUND_FALL_HOLE)
1416 const_iv (SOUND_DRINK_POISON)
1417 const_iv (SOUND_CAST_SPELL_0)
1418
1419 const_iv (PREFER_LOW)
1420 const_iv (PREFER_HIGH)
1421
1422 const_iv (ATNR_PHYSICAL)
1423 const_iv (ATNR_MAGIC)
1424 const_iv (ATNR_FIRE)
1425 const_iv (ATNR_ELECTRICITY)
1426 const_iv (ATNR_COLD)
1427 const_iv (ATNR_CONFUSION)
1428 const_iv (ATNR_ACID)
1429 const_iv (ATNR_DRAIN)
1430 const_iv (ATNR_WEAPONMAGIC)
1431 const_iv (ATNR_GHOSTHIT)
1432 const_iv (ATNR_POISON)
1433 const_iv (ATNR_SLOW)
1434 const_iv (ATNR_PARALYZE)
1435 const_iv (ATNR_TURN_UNDEAD)
1436 const_iv (ATNR_FEAR)
1437 const_iv (ATNR_CANCELLATION)
1438 const_iv (ATNR_DEPLETE)
1439 const_iv (ATNR_DEATH)
1440 const_iv (ATNR_CHAOS)
1441 const_iv (ATNR_COUNTERSPELL)
1442 const_iv (ATNR_GODPOWER)
1443 const_iv (ATNR_HOLYWORD)
1444 const_iv (ATNR_BLIND)
1445 const_iv (ATNR_INTERNAL)
1446 const_iv (ATNR_LIFE_STEALING)
1447 const_iv (ATNR_DISEASE)
1448
1449 const_iv (MAP_FLUSH)
1450 const_iv (MAP_PLAYER_UNIQUE)
1451 const_iv (MAP_BLOCK)
1452 const_iv (MAP_STYLE)
1453 const_iv (MAP_OVERLAY)
1454
1455 const_iv (MAP_IN_MEMORY)
1456 const_iv (MAP_SWAPPED)
1457 const_iv (MAP_LOADING)
1458 const_iv (MAP_SAVING)
1459
1460 const_iv (KLASS_ATTACHABLE)
1461 const_iv (KLASS_GLOBAL)
1462 const_iv (KLASS_OBJECT)
1463 const_iv (KLASS_CLIENT)
1464 const_iv (KLASS_PLAYER)
1465 const_iv (KLASS_MAP)
1466
1467 const_iv (CS_QUERY_YESNO)
1468 const_iv (CS_QUERY_SINGLECHAR)
1469 const_iv (CS_QUERY_HIDEINPUT)
1470
1471 const_iv (ST_DEAD)
1472 const_iv (ST_SETUP)
1473 const_iv (ST_PLAYING)
1474 const_iv (ST_CUSTOM)
1475
1476 const_iv (ST_CHANGE_CLASS)
1477
1478 const_iv (IO_HEADER)
1479 const_iv (IO_OBJECTS)
1480 const_iv (IO_UNIQUES)
1481
1482 // random map generator
1483 const_iv (LAYOUT_NONE)
1484 const_iv (LAYOUT_ONION)
1485 const_iv (LAYOUT_MAZE)
1486 const_iv (LAYOUT_SPIRAL)
1487 const_iv (LAYOUT_ROGUELIKE)
1488 const_iv (LAYOUT_SNAKE)
1489 const_iv (LAYOUT_SQUARE_SPIRAL)
1490
1491 const_iv (RMOPT_RANDOM)
1492 const_iv (RMOPT_CENTERED)
1493 const_iv (RMOPT_LINEAR)
1494 const_iv (RMOPT_BOTTOM_C)
1495 const_iv (RMOPT_BOTTOM_R)
1496 const_iv (RMOPT_IRR_SPACE)
1497 const_iv (RMOPT_WALL_OFF)
1498 const_iv (RMOPT_WALLS_ONLY)
1499 const_iv (RMOPT_NO_DOORS)
1500
1501 const_iv (SYMMETRY_RANDOM)
1502 const_iv (SYMMETRY_NONE)
1503 const_iv (SYMMETRY_X)
1504 const_iv (SYMMETRY_Y)
1505 const_iv (SYMMETRY_XY)
1506 };
1507
1508 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1509 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1510
1511 static const struct {
1512 const char *name;
1513 int skip;
1514 IV klass;
1515 IV iv;
1516 } *eiv, event_iv[] = {
1517 # define def(klass,name) { "EVENT_" # klass "_" # name, sizeof ("EVENT_" # klass), (IV)KLASS_ ## klass, (IV)EVENT_ ## klass ## _ ## name },
1518 # include "eventinc.h"
1519 # undef def
1520 };
1521
1522 AV *av = get_av ("cf::EVENT", 1);
1523
1524 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; )
1525 {
1526 AV *event = newAV ();
1527 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1528 av_push (event, newSViv (eiv->klass));
1529 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1530 newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv));
1531 }
1532 }
1533
1534 void _connect_to_perl ()
1535
1536 void _global_reattach ()
1537 CODE:
1538 {
1539 // reattach to all attachable objects in the game.
1540 for_all_clients (ns)
1541 ns->reattach ();
1542
1543 for_all_players (pl)
1544 pl->reattach ();
1545
1546 //TODO
1547 //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i)
1548 // i->second->reattach ();
1549
1550 for_all_objects (op)
1551 op->reattach ();
1552 }
1553
1554 NV floor (NV x)
1555
1556 NV ceil (NV x)
1557
1558 void server_tick ()
1559 CODE:
1560 runtime = SvNVx (sv_runtime);
1561 server_tick ();
1562
1563 void
1564 LOG (int level, char *msg)
1565 PROTOTYPE: $$
1566 C_ARGS: (LogLevel)level, "%s", msg
1567
1568 char *path_combine (char *base, char *path)
1569 PROTOTYPE: $$
1570
1571 char *path_combine_and_normalize (char *base, char *path)
1572 PROTOTYPE: $$
1573
1574 const char *
1575 get_maps_directory (char *path)
1576 PROTOTYPE: $
1577 ALIAS: maps_directory = 0
1578 CODE:
1579 RETVAL = create_pathname (path);
1580 OUTPUT: RETVAL
1581
1582 void
1583 sub_generation_inc ()
1584 CODE:
1585 PL_sub_generation++;
1586
1587 char *
1588 mapdir ()
1589 PROTOTYPE:
1590 ALIAS:
1591 mapdir = 0
1592 uniquedir = 1
1593 tmpdir = 2
1594 confdir = 3
1595 localdir = 4
1596 playerdir = 5
1597 datadir = 6
1598 CODE:
1599 switch (ix)
1600 {
1601 case 0: RETVAL = settings.mapdir ; break;
1602 case 1: RETVAL = settings.uniquedir; break;
1603 case 2: RETVAL = settings.tmpdir ; break;
1604 case 3: RETVAL = settings.confdir ; break;
1605 case 4: RETVAL = settings.localdir ; break;
1606 case 5: RETVAL = settings.playerdir; break;
1607 case 6: RETVAL = settings.datadir ; break;
1608 }
1609 OUTPUT: RETVAL
1610
1611 void abort ()
1612
1613 void emergency_save ()
1614
1615 void _exit (int status = 0)
1616
1617 #if _POSIX_MEMLOCK
1618
1619 int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1620
1621 int munlockall ()
1622
1623 #endif
1624
1625 int find_animation (char *text)
1626 PROTOTYPE: $
1627
1628 int random_roll (int min, int max, object *op, int goodbad);
1629
1630 const char *cost_string_from_value(uint64 cost, int approx = 0)
1631
1632 int
1633 exp_to_level (val64 exp)
1634 CODE:
1635 {
1636 int i = 0;
1637
1638 RETVAL = settings.max_level;
1639
1640 for (i = 1; i <= settings.max_level; i++)
1641 {
1642 if (levels[i] > exp)
1643 {
1644 RETVAL = i - 1;
1645 break;
1646 }
1647 }
1648 }
1649 OUTPUT: RETVAL
1650
1651 val64
1652 level_to_min_exp (int level)
1653 CODE:
1654 if (level > settings.max_level)
1655 RETVAL = levels[settings.max_level];
1656 else if (level < 1)
1657 RETVAL = 0;
1658 else
1659 RETVAL = levels[level];
1660 OUTPUT: RETVAL
1661
1662 SV *
1663 resistance_to_string (int atnr)
1664 CODE:
1665 if (atnr >= 0 && atnr < NROFATTACKS)
1666 RETVAL = newSVpv (resist_plus[atnr], 0);
1667 else
1668 XSRETURN_UNDEF;
1669 OUTPUT: RETVAL
1670
1671 MODULE = cf PACKAGE = cf::attachable
1672
1673 int
1674 valid (SV *obj)
1675 CODE:
1676 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1677 OUTPUT:
1678 RETVAL
1679
1680 INCLUDE: $PERL genacc attachable ../include/cfperl.h |
1681
1682 MODULE = cf PACKAGE = cf::global
1683
1684 int invoke (SV *klass, int event, ...)
1685 CODE:
1686 if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL");
1687 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1688 for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1689 RETVAL = gbl_ev.invoke ((event_type)event, ARG_AV (av), DT_END);
1690 OUTPUT: RETVAL
1691
1692 MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1693
1694 INCLUDE: $PERL genacc object ../include/object.h |
1695
1696 int invoke (object *op, int event, ...)
1697 CODE:
1698 if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT");
1699 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1700 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1701 RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END);
1702 OUTPUT: RETVAL
1703
1704 SV *registry (object *op)
1705
1706 void mortals ()
1707 PPCODE:
1708 EXTEND (SP, object::mortals.size ());
1709 for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i)
1710 PUSHs (to_sv (*i));
1711
1712 object *first ()
1713 CODE:
1714 RETVAL = object::first;
1715 OUTPUT: RETVAL
1716
1717 # missing properties
1718
1719 object *head (object *op)
1720 PROTOTYPE: $
1721 CODE:
1722 RETVAL = op->head ? op->head : op;
1723 OUTPUT: RETVAL
1724
1725 int is_head (object *op)
1726 PROTOTYPE: $
1727 CODE:
1728 RETVAL = !op->head;
1729 OUTPUT: RETVAL
1730
1731 void
1732 inv (object *obj)
1733 PROTOTYPE: $
1734 PPCODE:
1735 {
1736 object *o;
1737 for (o = obj->inv; o; o = o->below)
1738 XPUSHs (sv_2mortal (to_sv (o)));
1739 }
1740
1741 void
1742 set_animation (object *op, int idx)
1743 CODE:
1744 SET_ANIMATION (op, idx);
1745
1746 object *find_best_object_match (object *op, const char *match)
1747
1748 object *find_marked_object (object *op)
1749
1750 int need_identify (object *obj);
1751
1752 int apply_shop_mat (object *shop_mat, object *op);
1753
1754 int move (object *op, int dir, object *originator = op)
1755 CODE:
1756 RETVAL = move_ob (op, dir, originator);
1757 OUTPUT:
1758 RETVAL
1759
1760 void apply (object *applier, object *applied, int flags = 0)
1761 CODE:
1762 manual_apply (applied, applier, flags);
1763
1764 void apply_below (object *op)
1765 CODE:
1766 player_apply_below (op);
1767
1768 object *cf_object_present_archname_inside (object *op, char *whatstr)
1769
1770 int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1771
1772 int cf_object_change_map (object *op, int x, int y, maptile *map)
1773
1774 #//TODO
1775 object *clone_ (object *op, int recursive = 0)
1776 CODE:
1777 if (recursive)
1778 RETVAL = object_create_clone (op);
1779 else
1780 {
1781 RETVAL = object::create ();
1782 op->copy_to (RETVAL);
1783 }
1784 OUTPUT: RETVAL
1785
1786 int pay_item (object *op, object *buyer)
1787 CODE:
1788 RETVAL = pay_for_item (op, buyer);
1789 OUTPUT: RETVAL
1790
1791 int pay_amount (object *op, uint64 amount)
1792 CODE:
1793 RETVAL = pay_for_amount (amount, op);
1794 OUTPUT: RETVAL
1795
1796 void pay_player (object *op, uint64 amount)
1797
1798 val64 pay_player_arch (object *op, const char *arch, uint64 amount)
1799
1800 int cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg = 0)
1801
1802 void learn_spell (object *op, object *sp, int special_prayer = 0)
1803 CODE:
1804 do_learn_spell (op, sp, special_prayer);
1805
1806 void forget_spell (object *op, object *sp)
1807 CODE:
1808 do_forget_spell (op, query_name (sp));
1809
1810 object *check_for_spell (object *op, char *spellname)
1811 CODE:
1812 RETVAL = check_spell_known (op, spellname);
1813 OUTPUT: RETVAL
1814
1815 int query_money (object *op)
1816 ALIAS: money = 0
1817
1818 val64 query_cost (object *op, object *who, int flags)
1819 ALIAS: cost = 0
1820
1821 void spring_trap (object *op, object *victim)
1822
1823 int check_trigger (object *op, object *cause)
1824
1825 void drop (object *who, object *op)
1826
1827 void pick_up (object *who, object *op)
1828
1829 object *cf_object_insert_object (object *op, object *container)
1830
1831 object *cf_object_insert_in_ob (object *ob, object *where)
1832
1833 int cf_object_teleport (object *op, maptile *map, int x, int y)
1834
1835 void update_object (object *op, int action)
1836
1837 object *cf_create_object_by_name (const char *name)
1838
1839 void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0)
1840
1841 void player_lvl_adj (object *who, object *skill = 0)
1842
1843 int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1844
1845 int calc_skill_exp (object *who, object *op, object *skill);
1846
1847 void push_button (object *op);
1848
1849 void use_trigger (object *op);
1850
1851 void add_button_link (object *button, maptile *map, int connected);
1852
1853 void remove_button_link (object *op);
1854
1855
1856 MODULE = cf PACKAGE = cf::object PREFIX = cf_
1857
1858 object *cf_insert_ob_in_ob (object *ob, object *where)
1859
1860 # no clean way to get an object from an archetype - stupid idiotic
1861 # dumb kludgy misdesigned plug-in api slowly gets on my nerves.
1862
1863 object *new (const char *archetype = 0)
1864 PROTOTYPE: ;$
1865 CODE:
1866 RETVAL = archetype ? get_archetype (archetype) : cf_create_object ();
1867 OUTPUT:
1868 RETVAL
1869
1870 object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
1871 PROTOTYPE: $$$$$$
1872 CODE:
1873 {
1874 int unused_type;
1875 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
1876 }
1877
1878 # syntatic sugar for easier use in event callbacks.
1879 const char *options (object *op)
1880 CODE:
1881 RETVAL = op->name;
1882 OUTPUT:
1883 RETVAL
1884
1885 player *contr (object *op)
1886 CODE:
1887 RETVAL = op->contr;
1888 OUTPUT: RETVAL
1889
1890 const char *get_ob_key_value (object *op, const char *key)
1891
1892 bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1)
1893
1894 object *get_nearest_player (object *ob)
1895 ALIAS: nearest_player = 0
1896 PREINIT:
1897 extern object *get_nearest_player (object *);
1898
1899 void rangevector (object *ob, object *other, int flags = 0)
1900 PROTOTYPE: $$;$
1901 PPCODE:
1902 {
1903 rv_vector rv;
1904 get_rangevector (ob, other, &rv, flags);
1905 EXTEND (SP, 5);
1906 PUSHs (newSVuv (rv.distance));
1907 PUSHs (newSViv (rv.distance_x));
1908 PUSHs (newSViv (rv.distance_y));
1909 PUSHs (newSViv (rv.direction));
1910 PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part));
1911 }
1912
1913 bool on_same_map_as (object *ob, object *other)
1914 CODE:
1915 RETVAL = on_same_map (ob, other);
1916 OUTPUT: RETVAL
1917
1918 const char *
1919 base_name (object *op, int plural = op->nrof > 1)
1920 CODE:
1921 RETVAL = query_base_name (op, plural);
1922 OUTPUT: RETVAL
1923
1924 object *decrease_ob_nr (object *op, unsigned long i)
1925
1926 MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
1927
1928 player *player (object *op)
1929 CODE:
1930 RETVAL = op->contr;
1931 OUTPUT: RETVAL
1932
1933 void check_score (object *op)
1934
1935 void message (object *op, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1936 CODE:
1937 new_draw_info (flags, 0, op, txt);
1938
1939 object *cf_player_send_inventory (object *op)
1940
1941 char *cf_player_get_ip (object *op)
1942 ALIAS: ip = 0
1943
1944 object *cf_player_get_marked_item (object *op)
1945 ALIAS: marked_item = 0
1946
1947 void cf_player_set_marked_item (object *op, object *ob)
1948
1949 partylist *cf_player_get_party (object *op)
1950 ALIAS: party = 0
1951
1952 void cf_player_set_party (object *op, partylist *party)
1953
1954 void kill_player (object *op)
1955
1956 void esrv_update_item (object *op, int what, object *item)
1957 C_ARGS: what, op, item
1958
1959 void clear_los (object *op)
1960
1961 int command_teleport (object *op, char *params)
1962
1963 int command_summon (object *op, char *params)
1964
1965 int command_arrest (object *op, char *params)
1966
1967 int command_kick (object *op, char *params)
1968
1969 int command_banish (object *op, char *params)
1970
1971
1972 MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1973
1974 INCLUDE: $PERL genacc player ../include/player.h |
1975
1976 int invoke (player *pl, int event, ...)
1977 CODE:
1978 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER");
1979 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1980 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1981 RETVAL = pl->invoke ((event_type)event, ARG_AV (av), DT_END);
1982 OUTPUT: RETVAL
1983
1984 SV *registry (player *pl)
1985
1986 void
1987 save_stats (player *pl)
1988 CODE:
1989 pl->ob->stats.hp = pl->ob->stats.maxhp;
1990 pl->ob->stats.sp = pl->ob->stats.maxsp;
1991 pl->ob->stats.grace = pl->ob->stats.maxgrace;
1992 pl->orig_stats = pl->ob->stats;
1993
1994 void cf_player_move (player *pl, int dir)
1995
1996 void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
1997
1998 player *first ()
1999 CODE:
2000 RETVAL = first_player;
2001 OUTPUT: RETVAL
2002
2003 bool
2004 cell_visible (player *pl, int dx, int dy)
2005 CODE:
2006 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2007 && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2];
2008 OUTPUT:
2009 RETVAL
2010
2011 void
2012 send (player *pl, SV *packet)
2013 CODE:
2014 {
2015 STRLEN len;
2016 char *buf = SvPVbyte (packet, len);
2017
2018 if (pl->ns)
2019 pl->ns->send_packet (buf, len);
2020 }
2021
2022 int
2023 listening (player *pl, int new_value = -1)
2024 CODE:
2025 RETVAL = pl->listening;
2026 if (new_value >= 0)
2027 pl->listening = new_value;
2028 OUTPUT:
2029 RETVAL
2030
2031 void savebed (player *pl, SV *map_path = 0, SV *x = 0, SV *y = 0)
2032 PROTOTYPE: $;$$$
2033 PPCODE:
2034 if (GIMME_V != G_VOID)
2035 {
2036 EXTEND (SP, 3);
2037 PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0)));
2038 PUSHs (sv_2mortal (newSViv (pl->bed_x)));
2039 PUSHs (sv_2mortal (newSViv (pl->bed_y)));
2040 }
2041 if (map_path) sv_to (map_path, pl->savebed_map);
2042 if (x) sv_to (x, pl->bed_x);
2043 if (y) sv_to (y, pl->bed_y);
2044
2045 void
2046 list ()
2047 PPCODE:
2048 for_all_players (pl)
2049 XPUSHs (sv_2mortal (to_sv (pl)));
2050
2051 bool
2052 peaceful (player *pl, bool new_setting = 0)
2053 PROTOTYPE: $;$
2054 CODE:
2055 RETVAL = pl->peaceful;
2056 if (items > 1)
2057 pl->peaceful = new_setting;
2058 OUTPUT:
2059 RETVAL
2060
2061 living *
2062 orig_stats (player *pl)
2063 CODE:
2064 RETVAL = &pl->orig_stats;
2065 OUTPUT: RETVAL
2066
2067 living *
2068 last_stats (player *pl)
2069 CODE:
2070 RETVAL = &pl->last_stats;
2071 OUTPUT: RETVAL
2072
2073
2074 MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
2075
2076 int invoke (maptile *map, int event, ...)
2077 CODE:
2078 if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP");
2079 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2080 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
2081 RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END);
2082 OUTPUT: RETVAL
2083
2084 SV *registry (maptile *map)
2085
2086 INCLUDE: $PERL genacc maptile ../include/map.h |
2087
2088 void
2089 maptile::instantiate ()
2090
2091 maptile *new ()
2092 PROTOTYPE:
2093 CODE:
2094 RETVAL = new maptile;
2095 OUTPUT:
2096 RETVAL
2097
2098 void
2099 maptile::players ()
2100 PPCODE:
2101 if (GIMME_V == G_SCALAR)
2102 XPUSHs (sv_2mortal (to_sv (THIS->players)));
2103 else if (GIMME_V == G_ARRAY)
2104 {
2105 EXTEND (SP, THIS->players);
2106 for_all_players (pl)
2107 if (pl->ob && pl->ob->map == THIS)
2108 PUSHs (sv_2mortal (to_sv (pl->ob)));
2109 }
2110
2111 void play_sound_map (maptile *map, int x, int y, int sound_num)
2112
2113 int out_of_map (maptile *map, int x, int y)
2114
2115 void
2116 trigger (maptile *map, long connection, bool state = true)
2117 CODE:
2118 activate_connection (map, connection, state);
2119
2120 void
2121 get_connection (maptile *map, long connection)
2122 PPCODE:
2123 oblinkpt *obp = get_connection_links (map, connection);
2124 if (obp)
2125 for (objectlink *ol = obp->link; ol; ol = ol->next)
2126 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, (object *)ol->ob)));
2127
2128 object *cf_map_insert_object_there (maptile *where, object *op, object *originator, int flags)
2129
2130 object *cf_map_insert_object (maptile *where, object* op, int x, int y)
2131
2132 object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny)
2133 C_ARGS: str, map, nx, ny
2134
2135 void
2136 cf_map_normalise (maptile *map, int x, int y)
2137 PPCODE:
2138 {
2139 maptile *nmap = 0;
2140 I16 nx = 0, ny = 0;
2141 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2142
2143 EXTEND (SP, 4);
2144 PUSHs (sv_2mortal (newSViv (flags)));
2145
2146 if (GIMME_V == G_ARRAY)
2147 {
2148 PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap)));
2149 PUSHs (sv_2mortal (newSViv (nx)));
2150 PUSHs (sv_2mortal (newSViv (ny)));
2151 }
2152 }
2153
2154 void
2155 at (maptile *map, unsigned int x, unsigned int y)
2156 PROTOTYPE: $$$
2157 PPCODE:
2158 {
2159 object *o;
2160 maptile *nmap = 0;
2161 I16 nx, ny;
2162
2163 get_map_flags (map, &nmap, x, y, &nx, &ny);
2164
2165 if (nmap)
2166 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
2167 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
2168 }
2169
2170 SV *
2171 bot_at (maptile *obj, unsigned int x, unsigned int y)
2172 PROTOTYPE: $$$
2173 ALIAS:
2174 top_at = 1
2175 flags_at = 2
2176 light_at = 3
2177 move_block_at = 4
2178 move_slow_at = 5
2179 move_on_at = 6
2180 move_off_at = 7
2181 INIT:
2182 if (x >= obj->width || y >= obj->height) XSRETURN_UNDEF;
2183 CODE:
2184 switch (ix)
2185 {
2186 case 0: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_OB (obj, x, y)); break;
2187 case 1: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_TOP (obj, x, y)); break;
2188 case 2: RETVAL = newSVuv ( GET_MAP_FLAGS (obj, x, y)); break;
2189 case 3: RETVAL = newSViv ( GET_MAP_LIGHT (obj, x, y)); break;
2190 case 4: RETVAL = newSVuv ( GET_MAP_MOVE_BLOCK (obj, x, y)); break;
2191 case 5: RETVAL = newSVuv ( GET_MAP_MOVE_SLOW (obj, x, y)); break;
2192 case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break;
2193 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break;
2194 }
2195 OUTPUT: RETVAL
2196
2197 void fix_walls (maptile *map, int x, int y)
2198
2199 void fix_walls_around (maptile *map, int x, int y)
2200
2201 const char *
2202 region_name (maptile *m)
2203 CODE:
2204 RETVAL = get_name_of_region_for_map (m);
2205 OUTPUT: RETVAL
2206
2207 # worst xs function of my life
2208 maptile *
2209 _create_random_map (\
2210 char *path,\
2211 char *wallstyle,\
2212 char *wall_name,\
2213 char *floorstyle,\
2214 char *monsterstyle,\
2215 char *treasurestyle,\
2216 char *layoutstyle,\
2217 char *doorstyle,\
2218 char *decorstyle,\
2219 char *origin_map,\
2220 char *final_map,\
2221 char *exitstyle,\
2222 char *this_map,\
2223 char *exit_on_final_map,\
2224 int Xsize,\
2225 int Ysize,\
2226 int expand2x,\
2227 int layoutoptions1,\
2228 int layoutoptions2,\
2229 int layoutoptions3,\
2230 int symmetry,\
2231 int difficulty,\
2232 int difficulty_given,\
2233 float difficulty_increase,\
2234 int dungeon_level,\
2235 int dungeon_depth,\
2236 int decoroptions,\
2237 int orientation,\
2238 int origin_y,\
2239 int origin_x,\
2240 int random_seed,\
2241 val64 total_map_hp,\
2242 int map_layout_style,\
2243 int treasureoptions,\
2244 int symmetry_used,\
2245 region *region\
2246 )
2247 CODE:
2248 {
2249 random_map_params rmp;
2250
2251 assign (rmp.wallstyle , wallstyle);
2252 assign (rmp.wall_name , wall_name);
2253 assign (rmp.floorstyle , floorstyle);
2254 assign (rmp.monsterstyle , monsterstyle);
2255 assign (rmp.treasurestyle , treasurestyle);
2256 assign (rmp.layoutstyle , layoutstyle);
2257 assign (rmp.doorstyle , doorstyle);
2258 assign (rmp.decorstyle , decorstyle);
2259 assign (rmp.exitstyle , exitstyle);
2260 assign (rmp.exit_on_final_map, exit_on_final_map);
2261
2262 rmp.origin_map = origin_map;
2263 rmp.final_map = final_map;
2264 rmp.this_map = this_map;
2265 rmp.Xsize = Xsize;
2266 rmp.Ysize = Ysize;
2267 rmp.expand2x = expand2x;
2268 rmp.layoutoptions1 = layoutoptions1;
2269 rmp.layoutoptions2 = layoutoptions2;
2270 rmp.layoutoptions3 = layoutoptions3;
2271 rmp.symmetry = symmetry;
2272 rmp.difficulty = difficulty;
2273 rmp.difficulty_given = difficulty_given;
2274 rmp.difficulty_increase = difficulty_increase;
2275 rmp.dungeon_level = dungeon_level;
2276 rmp.dungeon_depth = dungeon_depth;
2277 rmp.decoroptions = decoroptions;
2278 rmp.orientation = orientation;
2279 rmp.origin_y = origin_y;
2280 rmp.origin_x = origin_x;
2281 rmp.random_seed = random_seed;
2282 rmp.total_map_hp = total_map_hp;
2283 rmp.map_layout_style = map_layout_style;
2284 rmp.treasureoptions = treasureoptions;
2285 rmp.symmetry_used = symmetry_used;
2286 rmp.region = region;
2287
2288 RETVAL = generate_random_map (path, &rmp);
2289 }
2290 OUTPUT:
2291 RETVAL
2292
2293 MODULE = cf PACKAGE = cf::arch
2294
2295 archetype *find (const char *name)
2296 CODE:
2297 RETVAL = archetype::find (name);
2298 OUTPUT:
2299 RETVAL
2300
2301 archetype *first()
2302 PROTOTYPE:
2303 CODE:
2304 RETVAL = first_archetype;
2305 OUTPUT: RETVAL
2306
2307 INCLUDE: $PERL genacc archetype ../include/object.h |
2308
2309 MODULE = cf PACKAGE = cf::party
2310
2311 partylist *first ()
2312 PROTOTYPE:
2313 CODE:
2314 RETVAL = get_firstparty ();
2315 OUTPUT: RETVAL
2316
2317 INCLUDE: $PERL genacc partylist ../include/player.h |
2318
2319 MODULE = cf PACKAGE = cf::region
2320
2321 region *first ()
2322 PROTOTYPE:
2323 CODE:
2324 RETVAL = first_region;
2325 OUTPUT: RETVAL
2326
2327 region *find (char *name)
2328 PROTOTYPE: $
2329 CODE:
2330 RETVAL = get_region_by_name (name);
2331 OUTPUT: RETVAL
2332
2333 INCLUDE: $PERL genacc region ../include/map.h |
2334
2335 MODULE = cf PACKAGE = cf::living
2336
2337 INCLUDE: $PERL genacc living ../include/living.h |
2338
2339 MODULE = cf PACKAGE = cf::settings
2340
2341 INCLUDE: $PERL genacc Settings ../include/global.h |
2342
2343 MODULE = cf PACKAGE = cf::client
2344
2345 INCLUDE: $PERL genacc client ../include/client.h |
2346
2347 int invoke (client *ns, int event, ...)
2348 CODE:
2349 if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT");
2350 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2351 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
2352 RETVAL = ns->invoke ((event_type)event, ARG_AV (av), DT_END);
2353 OUTPUT: RETVAL
2354
2355 SV *registry (client *ns)
2356
2357 void
2358 list ()
2359 PPCODE:
2360 EXTEND (SP, clients.size ());
2361 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2362 PUSHs (sv_2mortal (to_sv (*i)));
2363
2364 void
2365 client::send_packet (SV *packet)
2366 CODE:
2367 {
2368 STRLEN len;
2369 char *buf = SvPVbyte (packet, len);
2370
2371 THIS->send_packet (buf, len);
2372 }
2373