ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
Revision: 1.128
Committed: Sun Jan 7 02:39:14 2007 UTC (17 years, 4 months ago) by root
Branch: MAIN
Changes since 1.127: +6 -20 lines
Log Message:
""

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