1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001-2005,2007 by Chachkoff Yann |
|
|
6 | * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de> |
|
|
7 | * |
5 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
7 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
9 | * option) any later version. |
12 | * |
10 | * |
13 | * This program is distributed in the hope that it will be useful, |
11 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
14 | * GNU General Public License for more details. |
17 | * |
15 | * |
18 | * You should have received a copy of the GNU General Public License |
16 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | * and the GNU General Public License along with this program. If not, see |
|
|
18 | * <http://www.gnu.org/licenses/>. |
20 | * |
19 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
21 | */ |
23 | |
22 | |
24 | #include "autoconf.h" |
23 | #include "autoconf.h" |
… | |
… | |
71 | static int tick_pending; |
70 | static int tick_pending; |
72 | |
71 | |
73 | global gbl_ev; |
72 | global gbl_ev; |
74 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
73 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
75 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; |
74 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; |
|
|
75 | static AV *av_reflect; |
76 | |
76 | |
77 | bitset<NUM_EVENT_TYPES> ev_want_event; |
77 | bitset<NUM_EVENT_TYPES> ev_want_event; |
78 | bitset<NUM_TYPES> ev_want_type; |
78 | bitset<NUM_TYPES> ev_want_type; |
79 | |
79 | |
80 | static HV |
80 | static HV |
… | |
… | |
88 | *stash_cf_arch_wrap, |
88 | *stash_cf_arch_wrap, |
89 | *stash_cf_party_wrap, |
89 | *stash_cf_party_wrap, |
90 | *stash_cf_region_wrap, |
90 | *stash_cf_region_wrap, |
91 | *stash_cf_living_wrap; |
91 | *stash_cf_living_wrap; |
92 | |
92 | |
|
|
93 | static SV |
|
|
94 | *cv_cf_do_invoke, |
|
|
95 | *cv_cf__can_merge, |
|
|
96 | *cv_cf_client_send_msg, |
|
|
97 | *cv_cf_tick, |
|
|
98 | *cv_cf_match_match; |
|
|
99 | |
93 | #ifndef newSVpv_utf8 |
100 | #ifndef newSVpv_utf8 |
94 | static inline SV * |
101 | static inline SV * |
95 | newSVpv_utf8 (const char *s) |
102 | newSVpv_utf8 (const char *s) |
96 | { |
103 | { |
97 | if (!s) |
104 | if (!s) |
… | |
… | |
158 | SvREFCNT_inc (self); |
165 | SvREFCNT_inc (self); |
159 | hv_clear (self); |
166 | hv_clear (self); |
160 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
167 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
161 | SvREFCNT_dec (self); |
168 | SvREFCNT_dec (self); |
162 | |
169 | |
163 | // self *must* be null now because thats sv_unmagic's job. |
170 | // self *must* be null now because that's sv_unmagic's job. |
164 | assert (!this->self); |
171 | assert (!this->self); |
165 | } |
172 | } |
166 | } |
173 | } |
167 | |
174 | |
168 | void |
175 | void |
… | |
… | |
202 | attachable::destroy () |
209 | attachable::destroy () |
203 | { |
210 | { |
204 | if (destroyed ()) |
211 | if (destroyed ()) |
205 | return; |
212 | return; |
206 | |
213 | |
207 | flags |= F_DESTROYED; |
214 | attachable_flags |= F_DESTROYED; |
208 | do_destroy (); |
215 | do_destroy (); |
209 | sever_self (); |
216 | sever_self (); |
210 | } |
217 | } |
211 | |
218 | |
212 | void |
219 | void |
… | |
… | |
286 | |
293 | |
287 | attach = src.attach; |
294 | attach = src.attach; |
288 | return *this; |
295 | return *this; |
289 | } |
296 | } |
290 | |
297 | |
|
|
298 | #if 0 |
291 | template<typename T> |
299 | template<typename T> |
292 | static bool |
300 | static bool |
293 | find_backref (void *ptr, T *obj) |
301 | find_backref (void *ptr, T *obj) |
294 | { |
302 | { |
295 | char *s = (char *)obj; |
303 | char *s = (char *)obj; |
… | |
… | |
303 | |
311 | |
304 | return false; |
312 | return false; |
305 | } |
313 | } |
306 | |
314 | |
307 | // for debugging, find "live" objects containing this ptr |
315 | // for debugging, find "live" objects containing this ptr |
308 | void |
316 | static void |
309 | find_backref (void *ptr) |
317 | find_backref (void *ptr) |
310 | { |
318 | { |
311 | for_all_objects (op) |
319 | for_all_objects (op) |
312 | if (find_backref (ptr, op)) |
320 | if (find_backref (ptr, op)) |
313 | fprintf (stderr, "O %p %d:'%s'\n", op, op->count, &op->name); |
321 | fprintf (stderr, "O %p %d:'%s'\n", op, op->count, &op->name); |
… | |
… | |
317 | fprintf (stderr, "P %p\n", pl); |
325 | fprintf (stderr, "P %p\n", pl); |
318 | |
326 | |
319 | for_all_clients (ns) |
327 | for_all_clients (ns) |
320 | if (find_backref (ptr, ns)) |
328 | if (find_backref (ptr, ns)) |
321 | fprintf (stderr, "C %p\n", ns); |
329 | fprintf (stderr, "C %p\n", ns); |
322 | |
|
|
323 | } |
330 | } |
|
|
331 | #endif |
324 | |
332 | |
325 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
333 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
326 | |
334 | |
327 | static SV * |
335 | static SV * |
328 | newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) |
336 | newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) |
… | |
… | |
381 | |
389 | |
382 | return sv; |
390 | return sv; |
383 | } |
391 | } |
384 | } |
392 | } |
385 | |
393 | |
|
|
394 | #if 0 // unused |
386 | static void |
395 | static void |
387 | clearSVptr (SV *sv) |
396 | clearSVptr (SV *sv) |
388 | { |
397 | { |
389 | if (SvROK (sv)) |
398 | if (SvROK (sv)) |
390 | sv = SvRV (sv); |
399 | sv = SvRV (sv); |
391 | |
400 | |
392 | hv_clear ((HV *)sv); |
401 | hv_clear ((HV *)sv); |
393 | sv_unmagic (sv, PERL_MAGIC_ext); |
402 | sv_unmagic (sv, PERL_MAGIC_ext); |
394 | } |
403 | } |
|
|
404 | #endif |
|
|
405 | |
|
|
406 | static long |
|
|
407 | SvPTR_nc (SV *sv) |
|
|
408 | { |
|
|
409 | sv = SvRV (sv); |
|
|
410 | |
|
|
411 | // very important shortcut |
|
|
412 | if (expect_true (SvMAGIC (sv) && SvMAGIC (sv)->mg_type == PERL_MAGIC_ext)) |
|
|
413 | return (long)SvMAGIC (sv)->mg_ptr; |
|
|
414 | |
|
|
415 | if (MAGIC *mg = mg_find (sv, PERL_MAGIC_ext)) |
|
|
416 | return (long)mg->mg_ptr; |
|
|
417 | |
|
|
418 | croak ("perl code used object, but C object is already destroyed, caught"); |
|
|
419 | } |
395 | |
420 | |
396 | static long |
421 | static long |
397 | SvPTR (SV *sv, const char *klass) |
422 | SvPTR (SV *sv, const char *klass) |
398 | { |
423 | { |
399 | if (!sv_derived_from (sv, klass)) |
424 | if (!sv_derived_from (sv, klass)) |
400 | croak ("object of type %s expected", klass); |
425 | croak ("object of type %s expected", klass); |
401 | |
426 | |
402 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
427 | return SvPTR_nc (sv); |
403 | |
|
|
404 | if (!mg) |
|
|
405 | croak ("perl code used %s object, but C object is already destroyed, caught", klass); |
|
|
406 | |
|
|
407 | return (long)mg->mg_ptr; |
|
|
408 | } |
428 | } |
409 | |
429 | |
410 | static long |
430 | static long noinline |
411 | SvPTR_ornull (SV *sv, const char *klass) |
431 | SvPTR_ornull (SV *sv, const char *klass) |
412 | { |
432 | { |
413 | if (SvOK (sv)) |
433 | if (expect_false (!SvOK (sv))) return 0; |
|
|
434 | |
414 | return SvPTR (sv, klass); |
435 | return SvPTR (sv, klass); |
415 | else |
|
|
416 | return 0; |
|
|
417 | } |
436 | } |
418 | |
437 | |
|
|
438 | static long noinline |
|
|
439 | SvPTR_ornull_client (SV *sv) |
|
|
440 | { |
|
|
441 | if (expect_false (!SvOK (sv))) return 0; |
|
|
442 | |
|
|
443 | if (!SvROK (sv) |
|
|
444 | || (SvSTASH (SvRV (sv)) != stash_cf_client_wrap |
|
|
445 | && !sv_derived_from (sv, "cf::client"))) |
|
|
446 | croak ("object of type cf::client expected"); |
|
|
447 | |
|
|
448 | return SvPTR_nc (sv); |
|
|
449 | } |
|
|
450 | |
|
|
451 | static long noinline |
|
|
452 | SvPTR_ornull_object (SV *sv) |
|
|
453 | { |
|
|
454 | if (expect_false (!SvOK (sv))) return 0; |
|
|
455 | |
|
|
456 | if (!SvROK (sv) |
|
|
457 | || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap |
|
|
458 | && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap |
|
|
459 | && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap |
|
|
460 | && !sv_derived_from (sv, "cf::object"))) |
|
|
461 | croak ("object of type cf::object expected"); |
|
|
462 | |
|
|
463 | return SvPTR_nc (sv); |
|
|
464 | } |
|
|
465 | |
|
|
466 | static long noinline |
|
|
467 | SvPTR_ornull_player (SV *sv) |
|
|
468 | { |
|
|
469 | if (expect_false (!SvOK (sv))) return 0; |
|
|
470 | |
|
|
471 | if (!SvROK (sv) |
|
|
472 | || (SvSTASH (SvRV (sv)) != stash_cf_player_wrap |
|
|
473 | && !sv_derived_from (sv, "cf::player"))) |
|
|
474 | croak ("object of type cf::player expected"); |
|
|
475 | |
|
|
476 | return SvPTR_nc (sv); |
|
|
477 | } |
|
|
478 | |
419 | inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length (), 1); } |
479 | static inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length (), 1); } |
420 | inline SV *to_sv (const char * v) { return v ? newSVpv (v, 0) : newSV (0); } |
480 | static inline SV *to_sv (const char * v) { return v ? newSVpv (v, 0) : newSV (0); } |
421 | inline SV *to_sv (bool v) { return newSViv (v); } |
481 | static inline SV *to_sv (bool v) { return newSViv (v); } |
422 | inline SV *to_sv ( signed char v) { return newSViv (v); } |
482 | static inline SV *to_sv ( signed char v) { return newSViv (v); } |
423 | inline SV *to_sv (unsigned char v) { return newSViv (v); } |
483 | static inline SV *to_sv (unsigned char v) { return newSViv (v); } |
424 | inline SV *to_sv ( signed short v) { return newSViv (v); } |
484 | static inline SV *to_sv ( signed short v) { return newSViv (v); } |
425 | inline SV *to_sv (unsigned short v) { return newSVuv (v); } |
485 | static inline SV *to_sv (unsigned short v) { return newSVuv (v); } |
426 | inline SV *to_sv ( signed int v) { return newSViv (v); } |
486 | static inline SV *to_sv ( signed int v) { return newSViv (v); } |
427 | inline SV *to_sv (unsigned int v) { return newSVuv (v); } |
487 | static inline SV *to_sv (unsigned int v) { return newSVuv (v); } |
428 | inline SV *to_sv ( signed long v) { return newSViv (v); } |
488 | static inline SV *to_sv ( signed long v) { return newSViv (v); } |
429 | inline SV *to_sv (unsigned long v) { return newSVuv (v); } |
489 | static inline SV *to_sv (unsigned long v) { return newSVuv (v); } |
430 | inline SV *to_sv ( signed long long v) { return newSVval64 (v); } |
490 | static inline SV *to_sv ( signed long long v) { return newSVval64 (v); } |
431 | inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
491 | static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
432 | inline SV *to_sv (float v) { return newSVnv (v); } |
492 | static inline SV *to_sv (float v) { return newSVnv (v); } |
433 | inline SV *to_sv (double v) { return newSVnv (v); } |
493 | static inline SV *to_sv (double v) { return newSVnv (v); } |
434 | inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
494 | static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
435 | inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
495 | static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
436 | inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
496 | static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
437 | inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
497 | static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
438 | inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
498 | static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
439 | inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
499 | static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
440 | inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
500 | static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
441 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
501 | static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
442 | inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
502 | static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
443 | |
503 | |
444 | inline SV *to_sv (object & v) { return to_sv (&v); } |
504 | static inline SV *to_sv (object & v) { return to_sv (&v); } |
445 | inline SV *to_sv (living & v) { return to_sv (&v); } |
505 | static inline SV *to_sv (living & v) { return to_sv (&v); } |
446 | |
506 | |
447 | inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
507 | static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
448 | inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); } |
508 | static inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); } |
449 | |
509 | |
450 | inline SV *to_sv (UUID v) { return newSVpv (v.c_str (), 0); } |
510 | static inline SV *to_sv (UUID v) { return newSVpv (v.c_str (), 0); } |
451 | |
511 | |
452 | inline SV *to_sv (dynbuf * v) |
512 | static inline SV *to_sv (dynbuf * v) |
453 | { |
513 | { |
454 | SV *sv = newSV (0); |
514 | SV *sv = newSV (0); |
455 | |
515 | |
456 | sv_upgrade (sv, SVt_PV); |
516 | sv_upgrade (sv, SVt_PV); |
457 | SvGROW (sv, v->size () + 1); |
517 | SvGROW (sv, v->size () + 1); |
… | |
… | |
461 | *SvEND (sv) = 0; |
521 | *SvEND (sv) = 0; |
462 | |
522 | |
463 | return sv; |
523 | return sv; |
464 | } |
524 | } |
465 | |
525 | |
466 | inline SV *to_sv (dynbuf_text * v) |
526 | static inline SV *to_sv (dynbuf_text * v) |
467 | { |
527 | { |
468 | SV *sv = to_sv (static_cast<dynbuf *> (v)); |
528 | SV *sv = to_sv (static_cast<dynbuf *> (v)); |
469 | SvUTF8_on (sv); |
529 | SvUTF8_on (sv); |
470 | return sv; |
530 | return sv; |
471 | } |
531 | } |
472 | |
532 | |
473 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; } |
533 | static inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; } |
474 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
534 | static inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
475 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
535 | static inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
476 | inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
536 | static inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
477 | inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
537 | static inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
478 | inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } |
538 | static inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } |
479 | inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } |
539 | static inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } |
480 | inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); } |
540 | static inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); } |
481 | inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); } |
541 | static inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); } |
482 | inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); } |
542 | static inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); } |
483 | inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
543 | static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
484 | inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } |
544 | static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } |
485 | inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } |
545 | static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } |
486 | inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
546 | static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
487 | inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
547 | static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
488 | inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } |
548 | static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } |
489 | inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } |
549 | static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } |
490 | inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } |
550 | static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } |
491 | inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
551 | static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
492 | inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } |
552 | static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); } |
493 | inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); } |
553 | static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } |
494 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
554 | static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
495 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
555 | static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } |
496 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
556 | static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } |
497 | inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *)SvPTR_ornull (sv, "cf::mapspace"); } |
557 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } |
498 | inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *)SvPTR_ornull (sv, "cf::object::freezer"); } |
558 | static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } |
499 | inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *)SvPTR_ornull (sv, "cf::object::thawer" ); } |
559 | static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } |
500 | |
560 | |
501 | //inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
561 | //static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
502 | inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
562 | static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
503 | |
563 | |
504 | template<class T> |
564 | template<class T> |
505 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
565 | static inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
506 | |
566 | |
507 | template<int N> |
567 | template<int N> |
508 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
568 | static inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
509 | |
569 | |
510 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
570 | static inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
511 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
571 | static inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
512 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
572 | static inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
513 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
573 | static inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
514 | |
574 | |
515 | inline void sv_to (SV *sv, std::string &v) |
575 | static inline void sv_to (SV *sv, std::string &v) |
516 | { |
576 | { |
517 | STRLEN len; |
577 | STRLEN len; |
518 | char *data = SvPVbyte (sv, len); |
578 | char *data = SvPVbyte (sv, len); |
519 | v.assign (data, len); |
579 | v.assign (data, len); |
520 | } |
580 | } |
521 | |
581 | |
522 | inline void sv_to (SV *sv, UUID &v) |
582 | static inline void sv_to (SV *sv, UUID &v) |
523 | { |
583 | { |
524 | if (!v.parse (SvPV_nolen (sv))) |
584 | if (!v.parse (SvPV_nolen (sv))) |
525 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
585 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
526 | } |
586 | } |
527 | |
587 | |
528 | inline void sv_to (SV *sv, object::flags_t::reference v) { v = SvTRUE (sv); } |
588 | static inline void sv_to (SV *sv, object::flags_t::reference v) { v = SvTRUE (sv); } |
529 | |
589 | |
530 | static SV * |
590 | static SV * |
531 | newSVdt_va (va_list &ap, data_type type) |
591 | newSVdt_va (va_list &ap, data_type type) |
532 | { |
592 | { |
533 | SV *sv; |
593 | SV *sv; |
… | |
… | |
607 | va_end (ap); |
667 | va_end (ap); |
608 | |
668 | |
609 | return sv; |
669 | return sv; |
610 | } |
670 | } |
611 | |
671 | |
|
|
672 | // typemap support, mostly to avoid excessive inlining |
|
|
673 | template<class type> |
|
|
674 | static void noinline |
|
|
675 | cf_obj_to (SV *arg, type &var) |
|
|
676 | { |
|
|
677 | sv_to (arg, var); |
|
|
678 | if (!var) |
|
|
679 | croak ("must not pass invalid/null cf_obj here"); |
|
|
680 | } |
|
|
681 | |
|
|
682 | template<class object> |
|
|
683 | static void noinline |
|
|
684 | cf_obj_ornull_to (SV *arg, object *&var) |
|
|
685 | { |
|
|
686 | if (SvOK (arg)) |
|
|
687 | { |
|
|
688 | sv_to (arg, var); |
|
|
689 | if (!var) |
|
|
690 | croak ("unable to convert perl object to C++ object"); |
|
|
691 | } |
|
|
692 | else |
|
|
693 | var = 0; |
|
|
694 | } |
|
|
695 | |
612 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
696 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
613 | |
697 | |
614 | SV * |
698 | static SV * |
615 | registry (attachable *ext) |
699 | registry (attachable *ext) |
616 | { |
700 | { |
617 | if (!ext->cb) |
701 | if (!ext->cb) |
618 | ext->cb = newAV (); |
702 | ext->cb = newAV (); |
619 | |
703 | |
… | |
… | |
660 | printf ("unable to bootstrap perl, aborting:\n%s", SvPV_nolen (ERRSV)); |
744 | printf ("unable to bootstrap perl, aborting:\n%s", SvPV_nolen (ERRSV)); |
661 | exit (EXIT_FAILURE); |
745 | exit (EXIT_FAILURE); |
662 | } |
746 | } |
663 | } |
747 | } |
664 | |
748 | |
|
|
749 | void |
665 | void cfperl_main () |
750 | cfperl_main () |
666 | { |
751 | { |
667 | dSP; |
752 | dSP; |
668 | |
753 | |
669 | PUSHMARK (SP); |
754 | PUSHMARK (SP); |
670 | PUTBACK; |
755 | PUTBACK; |
… | |
… | |
695 | # undef def |
780 | # undef def |
696 | }; |
781 | }; |
697 | |
782 | |
698 | #define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) |
783 | #define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) |
699 | |
784 | |
700 | static void |
785 | static void noinline |
701 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
786 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
702 | { |
787 | { |
703 | // event must be in array |
788 | // event must be in array |
704 | if (event >= 0 && event <= AvFILLp (registry)) |
789 | if (event >= 0 && event <= AvFILLp (registry)) |
705 | { |
790 | { |
… | |
… | |
791 | { |
876 | { |
792 | attachable::gather_callbacks (callbacks, event); |
877 | attachable::gather_callbacks (callbacks, event); |
793 | ::gather_callbacks (callbacks, cb_map, event); |
878 | ::gather_callbacks (callbacks, cb_map, event); |
794 | } |
879 | } |
795 | |
880 | |
796 | void |
881 | static void noinline |
797 | _recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry) |
882 | _recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry) |
798 | { |
883 | { |
799 | for (int event = 0; event <= AvFILLp (registry); ++event) |
884 | for (int event = 0; event <= AvFILLp (registry); ++event) |
800 | { |
885 | { |
801 | SV *cbs_ = AvARRAY (registry)[event]; |
886 | SV *cbs_ = AvARRAY (registry)[event]; |
… | |
… | |
811 | } |
896 | } |
812 | } |
897 | } |
813 | } |
898 | } |
814 | |
899 | |
815 | // very slow and inefficient way to recalculate the global want bitsets |
900 | // very slow and inefficient way to recalculate the global want bitsets |
816 | void |
901 | static void |
817 | _recalc_want () |
902 | _recalc_want () |
818 | { |
903 | { |
819 | ev_want_event.reset (); |
904 | ev_want_event.reset (); |
820 | |
905 | |
821 | _recalc_want (ev_want_event, cb_global); |
906 | _recalc_want (ev_want_event, cb_global); |
… | |
… | |
894 | XPUSHs (sv_2mortal (newSVdt_va (ap, dt))); |
979 | XPUSHs (sv_2mortal (newSVdt_va (ap, dt))); |
895 | } |
980 | } |
896 | |
981 | |
897 | va_end (ap); |
982 | va_end (ap); |
898 | |
983 | |
899 | CALL_CALL ("cf::do_invoke", G_SCALAR); |
984 | CALL_CALL (cv_cf_do_invoke, G_SCALAR); |
900 | count = count > 0 ? POPi : 0; |
985 | count = count > 0 ? POPi : 0; |
901 | |
986 | |
902 | CALL_END; |
987 | CALL_END; |
903 | |
988 | |
904 | return count; |
989 | return count; |
905 | } |
990 | } |
906 | |
991 | |
907 | SV * |
992 | static SV * |
908 | cfperl_result (int idx) |
993 | cfperl_result (int idx) |
909 | { |
994 | { |
910 | AV *av = get_av ("cf::INVOKE_RESULTS", 0); |
995 | AV *av = get_av ("cf::INVOKE_RESULTS", 0); |
911 | if (!av) |
996 | if (!av) |
912 | return &PL_sv_undef; |
997 | return &PL_sv_undef; |
… | |
… | |
931 | } |
1016 | } |
932 | |
1017 | |
933 | ///////////////////////////////////////////////////////////////////////////// |
1018 | ///////////////////////////////////////////////////////////////////////////// |
934 | // various c++ => perl glue functions |
1019 | // various c++ => perl glue functions |
935 | |
1020 | |
|
|
1021 | void |
936 | void cfperl_tick () |
1022 | cfperl_tick () |
937 | { |
1023 | { |
938 | tick_pending = 1; |
1024 | tick_pending = 1; |
939 | |
1025 | |
940 | if (tick_inhibit) |
1026 | if (tick_inhibit) |
941 | return; |
1027 | return; |
… | |
… | |
944 | |
1030 | |
945 | dSP; |
1031 | dSP; |
946 | |
1032 | |
947 | PUSHMARK (SP); |
1033 | PUSHMARK (SP); |
948 | PUTBACK; |
1034 | PUTBACK; |
949 | call_pv ("cf::tick", G_DISCARD | G_VOID); |
1035 | call_pvsv (cv_cf_tick, G_DISCARD | G_VOID); |
950 | |
1036 | |
951 | SvNV_set (sv_next_tick, get_next_tick ()); SvNOK_only (sv_next_tick); |
1037 | SvNV_set (sv_next_tick, get_next_tick ()); SvNOK_only (sv_next_tick); |
952 | } |
1038 | } |
953 | |
1039 | |
954 | void |
1040 | void |
… | |
… | |
984 | CALL_BEGIN (4); |
1070 | CALL_BEGIN (4); |
985 | CALL_ARG (ns); |
1071 | CALL_ARG (ns); |
986 | CALL_ARG (type); |
1072 | CALL_ARG (type); |
987 | CALL_ARG_SV (newSVpv_utf8 (msg)); |
1073 | CALL_ARG_SV (newSVpv_utf8 (msg)); |
988 | CALL_ARG (color); |
1074 | CALL_ARG (color); |
989 | CALL_CALL ("cf::client::send_msg", G_VOID); |
1075 | CALL_CALL (cv_cf_client_send_msg, G_VOID); |
990 | CALL_END; |
1076 | CALL_END; |
991 | } |
1077 | } |
992 | |
1078 | |
993 | int |
1079 | int |
994 | cfperl_can_merge (object *ob1, object *ob2) |
1080 | cfperl_can_merge (object *ob1, object *ob2) |
… | |
… | |
996 | int can; |
1082 | int can; |
997 | |
1083 | |
998 | CALL_BEGIN (2); |
1084 | CALL_BEGIN (2); |
999 | CALL_ARG (ob1); |
1085 | CALL_ARG (ob1); |
1000 | CALL_ARG (ob2); |
1086 | CALL_ARG (ob2); |
1001 | CALL_CALL ("cf::_can_merge", G_SCALAR); |
1087 | CALL_CALL (cv_cf__can_merge, G_SCALAR); |
1002 | can = count && SvTRUE (TOPs); |
1088 | can = count && SvTRUE (TOPs); |
1003 | CALL_END; |
1089 | CALL_END; |
1004 | |
1090 | |
1005 | return can; |
1091 | return can; |
|
|
1092 | } |
|
|
1093 | |
|
|
1094 | void |
|
|
1095 | cfperl_mapscript_activate (object *ob, int state, object *activator, object *originator) |
|
|
1096 | { |
|
|
1097 | CALL_BEGIN (4); |
|
|
1098 | CALL_ARG (ob); |
|
|
1099 | CALL_ARG (state); |
|
|
1100 | CALL_ARG (activator); |
|
|
1101 | CALL_ARG (originator); |
|
|
1102 | CALL_CALL ("cf::mapscript::activate", G_VOID); |
|
|
1103 | CALL_END; |
1006 | } |
1104 | } |
1007 | |
1105 | |
1008 | player * |
1106 | player * |
1009 | player::find (const char *name) |
1107 | player::find (const char *name) |
1010 | { |
1108 | { |
… | |
… | |
1150 | CALL_CALL ("cf::_log_backtrace", G_VOID); |
1248 | CALL_CALL ("cf::_log_backtrace", G_VOID); |
1151 | CALL_END; |
1249 | CALL_END; |
1152 | #endif |
1250 | #endif |
1153 | } |
1251 | } |
1154 | |
1252 | |
|
|
1253 | bool |
|
|
1254 | is_match_expr (const char *expr) |
|
|
1255 | { |
|
|
1256 | return !strncmp (expr, "match ", sizeof ("match ") - 1); |
|
|
1257 | } |
|
|
1258 | |
|
|
1259 | bool |
|
|
1260 | match (const char *expr, object *ob, object *self, object *source, object *originator) |
|
|
1261 | { |
|
|
1262 | if (!strncmp (expr, "match ", sizeof ("match ") - 1)) |
|
|
1263 | expr += sizeof ("match ") - 1; |
|
|
1264 | |
|
|
1265 | CALL_BEGIN (5); |
|
|
1266 | CALL_ARG (expr); |
|
|
1267 | CALL_ARG (ob); |
|
|
1268 | CALL_ARG (self); |
|
|
1269 | CALL_ARG (source); |
|
|
1270 | CALL_ARG (originator); |
|
|
1271 | CALL_CALL (cv_cf_match_match, G_SCALAR); |
|
|
1272 | |
|
|
1273 | bool matched = count && SvTRUE (TOPs); |
|
|
1274 | |
|
|
1275 | CALL_END; |
|
|
1276 | |
|
|
1277 | return matched; |
|
|
1278 | } |
|
|
1279 | |
|
|
1280 | object * |
|
|
1281 | match_one (const char *expr, object *ob, object *self, object *source, object *originator) |
|
|
1282 | { |
|
|
1283 | if (!strncmp (expr, "match ", sizeof ("match ") - 1)) |
|
|
1284 | expr += sizeof ("match ") - 1; |
|
|
1285 | |
|
|
1286 | CALL_BEGIN (5); |
|
|
1287 | CALL_ARG (expr); |
|
|
1288 | CALL_ARG (ob); |
|
|
1289 | CALL_ARG (self); |
|
|
1290 | CALL_ARG (source); |
|
|
1291 | CALL_ARG (originator); |
|
|
1292 | CALL_CALL (cv_cf_match_match, G_ARRAY); |
|
|
1293 | |
|
|
1294 | object *one = 0; |
|
|
1295 | |
|
|
1296 | if (count) |
|
|
1297 | sv_to (TOPs, one); |
|
|
1298 | |
|
|
1299 | CALL_END; |
|
|
1300 | |
|
|
1301 | return one; |
|
|
1302 | } |
|
|
1303 | |
1155 | ///////////////////////////////////////////////////////////////////////////// |
1304 | ///////////////////////////////////////////////////////////////////////////// |
1156 | |
1305 | |
1157 | struct EVAPI *evapi::GEVAPI; |
1306 | struct EVAPI *evapi::GEVAPI; |
1158 | struct CoroAPI *coroapi::GCoroAPI; |
1307 | struct CoroAPI *coroapi::GCoroAPI; |
1159 | |
1308 | |
|
|
1309 | void |
1160 | void coroapi::do_cede_to_tick () |
1310 | coroapi::do_cede_to_tick () |
1161 | { |
1311 | { |
1162 | cede_pending = 0; |
1312 | cede_pending = 0; |
1163 | cede (); |
1313 | cede (); |
1164 | } |
1314 | } |
1165 | |
1315 | |
… | |
… | |
1189 | ev_io_set ((ev_io *)this, fd, events); |
1339 | ev_io_set ((ev_io *)this, fd, events); |
1190 | if (active) start (); |
1340 | if (active) start (); |
1191 | } |
1341 | } |
1192 | } |
1342 | } |
1193 | |
1343 | |
1194 | void |
1344 | static void |
1195 | _connect_to_perl () |
1345 | _connect_to_perl_1 () |
1196 | { |
1346 | { |
1197 | stash_cf = gv_stashpv ("cf", 1); |
1347 | stash_cf = gv_stashpv ("cf", 1); |
1198 | |
1348 | |
1199 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
1349 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
1200 | stash_cf_object_player_wrap = gv_stashpv ("cf::object::player::wrap", 1); |
1350 | stash_cf_object_player_wrap = gv_stashpv ("cf::object::player::wrap", 1); |
… | |
… | |
1219 | cb_client = get_av ("cf::CB_CLIENT", 1); |
1369 | cb_client = get_av ("cf::CB_CLIENT", 1); |
1220 | cb_type = get_av ("cf::CB_TYPE" , 1); |
1370 | cb_type = get_av ("cf::CB_TYPE" , 1); |
1221 | cb_map = get_av ("cf::CB_MAP" , 1); |
1371 | cb_map = get_av ("cf::CB_MAP" , 1); |
1222 | } |
1372 | } |
1223 | |
1373 | |
|
|
1374 | static void |
|
|
1375 | _connect_to_perl_2 () |
|
|
1376 | { |
|
|
1377 | cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); |
|
|
1378 | cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); |
|
|
1379 | cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); |
|
|
1380 | cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); |
|
|
1381 | cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); |
|
|
1382 | } |
|
|
1383 | |
1224 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1384 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1225 | |
1385 | |
1226 | BOOT: |
1386 | BOOT: |
1227 | { |
1387 | { |
1228 | I_EV_API (PACKAGE); evapi::GEVAPI = GEVAPI; |
1388 | I_EV_API (PACKAGE); evapi::GEVAPI = GEVAPI; |
1229 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1389 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1230 | |
1390 | |
1231 | _connect_to_perl (); |
1391 | _connect_to_perl_1 (); |
1232 | |
1392 | |
1233 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1393 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1234 | |
1394 | |
1235 | //{ |
1395 | //{ |
1236 | // require_pv ("Time::HiRes"); |
1396 | // require_pv ("Time::HiRes"); |
… | |
… | |
1280 | const_iv (MOOD_FLOOR) const_iv (EXIT) const_iv (ENCOUNTER) const_iv (SHOP_FLOOR) |
1440 | const_iv (MOOD_FLOOR) const_iv (EXIT) const_iv (ENCOUNTER) const_iv (SHOP_FLOOR) |
1281 | const_iv (SHOP_MAT) const_iv (RING) const_iv (FLOOR) const_iv (FLESH) |
1441 | const_iv (SHOP_MAT) const_iv (RING) const_iv (FLOOR) const_iv (FLESH) |
1282 | const_iv (INORGANIC) const_iv (SKILL_TOOL) const_iv (LIGHTER) const_iv (BUILDABLE_WALL) |
1442 | const_iv (INORGANIC) const_iv (SKILL_TOOL) const_iv (LIGHTER) const_iv (BUILDABLE_WALL) |
1283 | const_iv (MISC_OBJECT) const_iv (LAMP) const_iv (DUPLICATOR) const_iv (SPELLBOOK) |
1443 | const_iv (MISC_OBJECT) const_iv (LAMP) const_iv (DUPLICATOR) const_iv (SPELLBOOK) |
1284 | const_iv (CLOAK) const_iv (SPINNER) const_iv (GATE) const_iv (BUTTON) |
1444 | const_iv (CLOAK) const_iv (SPINNER) const_iv (GATE) const_iv (BUTTON) |
1285 | const_iv (CF_HANDLE) const_iv (HOLE) const_iv (TRAPDOOR) const_iv (SIGN) |
1445 | const_iv (T_HANDLE) const_iv (HOLE) const_iv (TRAPDOOR) const_iv (SIGN) |
1286 | const_iv (BOOTS) const_iv (GLOVES) const_iv (SPELL) const_iv (SPELL_EFFECT) |
1446 | const_iv (BOOTS) const_iv (GLOVES) const_iv (SPELL) const_iv (SPELL_EFFECT) |
1287 | const_iv (CONVERTER) const_iv (BRACERS) const_iv (POISONING) const_iv (SAVEBED) |
1447 | const_iv (CONVERTER) const_iv (BRACERS) const_iv (POISONING) const_iv (SAVEBED) |
1288 | const_iv (WAND) const_iv (SCROLL) const_iv (DIRECTOR) const_iv (GIRDLE) |
1448 | const_iv (WAND) const_iv (SCROLL) const_iv (DIRECTOR) const_iv (GIRDLE) |
1289 | const_iv (FORCE) const_iv (POTION_EFFECT) const_iv (EVENT_CONNECTOR) const_iv (CLOSE_CON) |
1449 | const_iv (FORCE) const_iv (POTION_EFFECT) const_iv (EVENT_CONNECTOR) const_iv (CLOSE_CON) |
1290 | const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) |
1450 | const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) |
1291 | const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) |
1451 | const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) |
1292 | const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) |
1452 | const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) |
1293 | const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) |
1453 | const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) |
|
|
1454 | const_iv (MAPSCRIPT) const_iv (SAFE_GROUND) |
1294 | |
1455 | |
1295 | const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES) |
1456 | const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES) |
1296 | |
1457 | |
1297 | const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) |
1458 | const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) |
1298 | const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) |
1459 | const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) |
… | |
… | |
1315 | const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD) |
1476 | const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD) |
1316 | const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE) |
1477 | const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE) |
1317 | const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING) |
1478 | const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING) |
1318 | const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW) |
1479 | const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW) |
1319 | const_iv (FLAG_UNDEAD) const_iv (FLAG_SCARED) const_iv (FLAG_UNAGGRESSIVE) const_iv (FLAG_REFL_MISSILE) |
1480 | const_iv (FLAG_UNDEAD) const_iv (FLAG_SCARED) const_iv (FLAG_UNAGGRESSIVE) const_iv (FLAG_REFL_MISSILE) |
1320 | const_iv (FLAG_REFL_SPELL) const_iv (FLAG_NO_MAGIC) const_iv (FLAG_NO_FIX_PLAYER) const_iv (FLAG_IS_LIGHTABLE) |
1481 | const_iv (FLAG_REFL_SPELL) const_iv (FLAG_NO_MAGIC) const_iv (FLAG_IS_LIGHTABLE) |
1321 | const_iv (FLAG_TEAR_DOWN) const_iv (FLAG_RUN_AWAY) const_iv (FLAG_PICK_UP) const_iv (FLAG_UNIQUE) |
1482 | const_iv (FLAG_TEAR_DOWN) const_iv (FLAG_RUN_AWAY) const_iv (FLAG_PICK_UP) const_iv (FLAG_UNIQUE) |
1322 | const_iv (FLAG_NO_DROP) const_iv (FLAG_WIZCAST) const_iv (FLAG_CAST_SPELL) const_iv (FLAG_USE_SCROLL) |
1483 | const_iv (FLAG_NO_DROP) const_iv (FLAG_WIZCAST) const_iv (FLAG_CAST_SPELL) const_iv (FLAG_USE_SCROLL) |
1323 | const_iv (FLAG_USE_RANGE) const_iv (FLAG_USE_BOW) const_iv (FLAG_USE_ARMOUR) const_iv (FLAG_USE_WEAPON) |
1484 | const_iv (FLAG_USE_RANGE) const_iv (FLAG_USE_BOW) const_iv (FLAG_USE_ARMOUR) const_iv (FLAG_USE_WEAPON) |
1324 | const_iv (FLAG_USE_RING) const_iv (FLAG_READY_RANGE) const_iv (FLAG_READY_BOW) const_iv (FLAG_XRAYS) |
1485 | const_iv (FLAG_USE_RING) const_iv (FLAG_READY_RANGE) const_iv (FLAG_READY_BOW) const_iv (FLAG_XRAYS) |
1325 | const_iv (FLAG_NO_APPLY) const_iv (FLAG_IS_FLOOR) const_iv (FLAG_LIFESAVE) const_iv (FLAG_NO_STRENGTH) |
1486 | const_iv (FLAG_NO_APPLY) const_iv (FLAG_IS_FLOOR) const_iv (FLAG_LIFESAVE) const_iv (FLAG_NO_STRENGTH) |
… | |
… | |
1507 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1668 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1508 | av_push (event, newSViv (eiv->klass)); |
1669 | av_push (event, newSViv (eiv->klass)); |
1509 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1670 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1510 | newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv)); |
1671 | newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv)); |
1511 | } |
1672 | } |
|
|
1673 | |
|
|
1674 | // used by autogenerated BOOT sections from genacc |
|
|
1675 | av_reflect = get_av ("cf::REFLECT", 1); |
1512 | } |
1676 | } |
1513 | |
1677 | |
1514 | void _gv_clear (SV *gv) |
1678 | void _gv_clear (SV *gv) |
1515 | CODE: |
1679 | CODE: |
1516 | assert (SvTYPE (gv) == SVt_PVGV); |
1680 | assert (SvTYPE (gv) == SVt_PVGV); |
… | |
… | |
1523 | f (GvGP (gv)->gp_cv); |
1687 | f (GvGP (gv)->gp_cv); |
1524 | GvCVGEN (gv) = 0; |
1688 | GvCVGEN (gv) = 0; |
1525 | GvMULTI_off (gv); |
1689 | GvMULTI_off (gv); |
1526 | # undef f |
1690 | # undef f |
1527 | |
1691 | |
1528 | void _connect_to_perl () |
1692 | void _connect_to_perl_1 () |
|
|
1693 | |
|
|
1694 | void _connect_to_perl_2 () |
1529 | |
1695 | |
1530 | void _recalc_want () |
1696 | void _recalc_want () |
1531 | |
1697 | |
1532 | # not used by default anymore |
1698 | # not used by default anymore |
1533 | void _global_reattach () |
1699 | void _global_reattach () |
… | |
… | |
1898 | RETVAL |
2064 | RETVAL |
1899 | |
2065 | |
1900 | void |
2066 | void |
1901 | debug_trace (attachable *obj, bool on = true) |
2067 | debug_trace (attachable *obj, bool on = true) |
1902 | CODE: |
2068 | CODE: |
1903 | obj->flags &= ~attachable::F_DEBUG_TRACE; |
2069 | obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; |
1904 | if (on) |
2070 | if (on) |
1905 | obj->flags |= attachable::F_DEBUG_TRACE; |
2071 | obj->attachable_flags |= attachable::F_DEBUG_TRACE; |
1906 | |
2072 | |
1907 | int mortals_size () |
2073 | int mortals_size () |
1908 | CODE: |
2074 | CODE: |
1909 | RETVAL = attachable::mortals.size (); |
2075 | RETVAL = attachable::mortals.size (); |
1910 | OUTPUT: RETVAL |
2076 | OUTPUT: RETVAL |
… | |
… | |
2051 | CODE: |
2217 | CODE: |
2052 | player_apply_below (op); |
2218 | player_apply_below (op); |
2053 | |
2219 | |
2054 | int cast_heal (object *op, object *caster, object *spell, int dir = 0) |
2220 | int cast_heal (object *op, object *caster, object *spell, int dir = 0) |
2055 | |
2221 | |
|
|
2222 | int casting_level (object *caster, object *spell) |
|
|
2223 | |
2056 | int pay_item (object *op, object *buyer) |
2224 | int pay_item (object *op, object *buyer) |
2057 | CODE: |
2225 | CODE: |
2058 | RETVAL = pay_for_item (op, buyer); |
2226 | RETVAL = pay_for_item (op, buyer); |
2059 | OUTPUT: RETVAL |
2227 | OUTPUT: RETVAL |
2060 | |
2228 | |
… | |
… | |
2102 | |
2270 | |
2103 | void player_lvl_adj (object *who, object *skill = 0) |
2271 | void player_lvl_adj (object *who, object *skill = 0) |
2104 | |
2272 | |
2105 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
2273 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
2106 | |
2274 | |
2107 | int calc_skill_exp (object *who, object *op, object *skill); |
2275 | int calc_skill_exp (object *who, object *op, object *skill) |
2108 | |
2276 | |
2109 | void push_button (object *op); |
2277 | void push_button (object *op, object *originator) |
2110 | |
2278 | |
2111 | void use_trigger (object *op); |
2279 | void use_trigger (object *op, object *originator) |
2112 | |
2280 | |
2113 | void add_button_link (object *button, maptile *map, int connected); |
|
|
2114 | |
|
|
2115 | void remove_button_link (object *op); |
|
|
2116 | |
|
|
2117 | void handle_apply_yield (object *op); |
2281 | void handle_apply_yield (object *op) |
|
|
2282 | |
|
|
2283 | int convert_item (object *item, object *converter) |
2118 | |
2284 | |
2119 | |
2285 | |
2120 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2286 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2121 | |
2287 | |
2122 | # no clean way to get an object from an archetype - stupid idiotic |
2288 | # no clean way to get an object from an archetype - stupid idiotic |
… | |
… | |
2135 | object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) |
2301 | object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) |
2136 | PROTOTYPE: $$$$$$ |
2302 | PROTOTYPE: $$$$$$ |
2137 | CODE: |
2303 | CODE: |
2138 | { |
2304 | { |
2139 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2305 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
|
|
2306 | |
|
|
2307 | if (RETVAL->destroyed ()) |
|
|
2308 | RETVAL = 0; |
2140 | } |
2309 | } |
2141 | |
2310 | |
2142 | shstr |
2311 | shstr |
2143 | object::kv_get (shstr key) |
2312 | object::kv_get (shstr key) |
2144 | |
2313 | |
… | |
… | |
2328 | void |
2497 | void |
2329 | adjust_daylight () |
2498 | adjust_daylight () |
2330 | CODE: |
2499 | CODE: |
2331 | maptile::adjust_daylight (); |
2500 | maptile::adjust_daylight (); |
2332 | |
2501 | |
|
|
2502 | int |
|
|
2503 | outdoor_darkness (int darkness = 0) |
|
|
2504 | CODE: |
|
|
2505 | RETVAL = maptile::outdoor_darkness; |
|
|
2506 | if (items) |
|
|
2507 | maptile::outdoor_darkness = darkness; |
|
|
2508 | OUTPUT: |
|
|
2509 | RETVAL |
|
|
2510 | |
2333 | void |
2511 | void |
2334 | maptile::instantiate () |
2512 | maptile::instantiate () |
2335 | |
2513 | |
2336 | maptile *new () |
2514 | maptile *new () |
2337 | PROTOTYPE: |
2515 | PROTOTYPE: |
… | |
… | |
2368 | for (int x = 0; x < THIS->width; ++x) |
2546 | for (int x = 0; x < THIS->width; ++x) |
2369 | for (int y = 0; y < THIS->height; ++y) |
2547 | for (int y = 0; y < THIS->height; ++y) |
2370 | { |
2548 | { |
2371 | for (object *op = THIS->at (x, y).bot; op; op = op->above) |
2549 | for (object *op = THIS->at (x, y).bot; op; op = op->above) |
2372 | if (op->flag [FLAG_IS_FLOOR]) |
2550 | if (op->flag [FLAG_IS_FLOOR]) |
2373 | goto skip_space; |
2551 | goto skip; |
2374 | |
2552 | |
2375 | { |
2553 | { |
2376 | int offs = offset + y * stride + x; |
2554 | int offs = offset + y * stride + x; |
|
|
2555 | |
2377 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2556 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2378 | { |
2557 | { |
2379 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2558 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2380 | { |
2559 | { |
2381 | object *ob = get_archetype (SvPVutf8_nolen (*elem)); |
2560 | object *ob = get_archetype (SvPVutf8_nolen (*elem)); |
2382 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2561 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2383 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2562 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2384 | |
2563 | |
2385 | if (ob->randomitems) |
2564 | if (ob->randomitems && !ob->above) |
2386 | { |
2565 | { |
2387 | if (!ob->above) |
|
|
2388 | { |
|
|
2389 | ob->create_treasure (ob->randomitems); |
2566 | ob->create_treasure (ob->randomitems); |
2390 | |
2567 | |
2391 | for (object *op = ob->above; op; op = op->above) |
2568 | for (object *op = ob->above; op; op = op->above) |
2392 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2569 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2393 | } |
2570 | // TODO: if this is a pickable object, then the item |
2394 | |
2571 | // will at a bit weird - saving inside the player |
2395 | ob->randomitems = 0; |
2572 | // will clear the flag, but when the player drops |
|
|
2573 | // it without logging out, it keeps the flag. |
|
|
2574 | // nobody ahs reported this, but this can be rather |
|
|
2575 | // annoying on persistent maps. |
2396 | } |
2576 | } |
2397 | } |
2577 | } |
2398 | } |
2578 | } |
2399 | } |
2579 | } |
2400 | |
2580 | |
2401 | skip_space: ; |
2581 | skip: ; |
2402 | } |
2582 | } |
2403 | } |
2583 | } |
2404 | |
2584 | |
2405 | void |
2585 | void |
2406 | maptile::set_regiondata (SV *data, int offset, int stride, SV *palette) |
2586 | maptile::set_regiondata (SV *data, int offset, int stride, SV *palette) |
… | |
… | |
2445 | } |
2625 | } |
2446 | |
2626 | |
2447 | int out_of_map (maptile *map, int x, int y) |
2627 | int out_of_map (maptile *map, int x, int y) |
2448 | |
2628 | |
2449 | void |
2629 | void |
2450 | trigger (maptile *map, long connection, bool state = true) |
2630 | find_link (maptile *map, shstr_tmp connection) |
2451 | CODE: |
|
|
2452 | activate_connection (map, connection, state); |
|
|
2453 | |
|
|
2454 | void |
|
|
2455 | get_connection (maptile *map, long connection) |
|
|
2456 | PPCODE: |
2631 | PPCODE: |
2457 | oblinkpt *obp = get_connection_links (map, connection); |
2632 | if (oblinkpt *obp = map->find_link (connection)) |
2458 | if (obp) |
|
|
2459 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2633 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2460 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2634 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2461 | |
2635 | |
2462 | void |
2636 | void |
2463 | get_map_flags (maptile *map, int x, int y) |
2637 | get_map_flags (maptile *map, int x, int y) |
… | |
… | |
2552 | case 6: RETVAL = newSVuv (ms.move_on ); break; |
2726 | case 6: RETVAL = newSVuv (ms.move_on ); break; |
2553 | case 7: RETVAL = newSVuv (ms.move_off ); break; |
2727 | case 7: RETVAL = newSVuv (ms.move_off ); break; |
2554 | } |
2728 | } |
2555 | } |
2729 | } |
2556 | OUTPUT: RETVAL |
2730 | OUTPUT: RETVAL |
2557 | |
|
|
2558 | void fix_walls (maptile *map, int x, int y) |
|
|
2559 | |
|
|
2560 | void fix_walls_around (maptile *map, int x, int y) |
|
|
2561 | |
2731 | |
2562 | # worst xs function of my life |
2732 | # worst xs function of my life |
2563 | bool |
2733 | bool |
2564 | _create_random_map (\ |
2734 | _create_random_map (\ |
2565 | maptile *self,\ |
2735 | maptile *self,\ |
… | |
… | |
2661 | archetype *archetypes (U32 index) |
2831 | archetype *archetypes (U32 index) |
2662 | CODE: |
2832 | CODE: |
2663 | RETVAL = index < archetypes.size () ? archetypes [index] : 0; |
2833 | RETVAL = index < archetypes.size () ? archetypes [index] : 0; |
2664 | OUTPUT: RETVAL |
2834 | OUTPUT: RETVAL |
2665 | |
2835 | |
2666 | object *instantiate (archetype *arch) |
|
|
2667 | CODE: |
|
|
2668 | RETVAL = arch_to_object (arch); |
|
|
2669 | OUTPUT: |
|
|
2670 | RETVAL |
|
|
2671 | |
|
|
2672 | INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | |
2836 | INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | |
2673 | |
2837 | |
2674 | MODULE = cf PACKAGE = cf::party |
2838 | MODULE = cf PACKAGE = cf::party |
2675 | |
2839 | |
2676 | partylist *first () |
2840 | partylist *first () |
… | |
… | |
2691 | |
2855 | |
2692 | region *find (utf8_string name) |
2856 | region *find (utf8_string name) |
2693 | PROTOTYPE: $ |
2857 | PROTOTYPE: $ |
2694 | CODE: |
2858 | CODE: |
2695 | RETVAL = region::find (name); |
2859 | RETVAL = region::find (name); |
2696 | OUTPUT: RETVAL |
|
|
2697 | |
|
|
2698 | region *find_fuzzy (utf8_string name) |
|
|
2699 | PROTOTYPE: $ |
|
|
2700 | CODE: |
|
|
2701 | RETVAL = region::find_fuzzy (name); |
|
|
2702 | OUTPUT: RETVAL |
2860 | OUTPUT: RETVAL |
2703 | |
2861 | |
2704 | int specificity (region *rgn) |
2862 | int specificity (region *rgn) |
2705 | CODE: |
2863 | CODE: |
2706 | RETVAL = 0; |
2864 | RETVAL = 0; |
… | |
… | |
2842 | faceinfo *f = face_info (idx); assert (f); |
3000 | faceinfo *f = face_info (idx); assert (f); |
2843 | facedata *d = &(faceset ? f->data64 : f->data32); |
3001 | facedata *d = &(faceset ? f->data64 : f->data32); |
2844 | sv_to (data, d->data); |
3002 | sv_to (data, d->data); |
2845 | STRLEN clen; |
3003 | STRLEN clen; |
2846 | char *cdata = SvPVbyte (chksum, clen); |
3004 | char *cdata = SvPVbyte (chksum, clen); |
2847 | clen = min (CHKSUM_SIZE, clen); |
3005 | clen = min (CHKSUM_MAXLEN, clen); |
2848 | |
3006 | |
2849 | if (memcmp (d->chksum, cdata, clen)) |
3007 | if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) |
2850 | { |
3008 | { |
|
|
3009 | d->chksum_len = clen; |
2851 | memcpy (d->chksum, cdata, clen); |
3010 | memcpy (d->chksum, cdata, clen); |
2852 | |
3011 | |
2853 | // invalidate existing client face info |
3012 | // invalidate existing client face info |
2854 | for_all_clients (ns) |
3013 | for_all_clients (ns) |
2855 | if (ns->faceset == faceset) |
3014 | if (ns->faceset == faceset) |
… | |
… | |
2870 | |
3029 | |
2871 | SV *get_chksum (faceidx idx, int faceset = 0) |
3030 | SV *get_chksum (faceidx idx, int faceset = 0) |
2872 | CODE: |
3031 | CODE: |
2873 | facedata *d = face_data (idx, faceset); |
3032 | facedata *d = face_data (idx, faceset); |
2874 | if (!d) XSRETURN_UNDEF; |
3033 | if (!d) XSRETURN_UNDEF; |
2875 | RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE); |
3034 | RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); |
2876 | OUTPUT: |
3035 | OUTPUT: |
2877 | RETVAL |
3036 | RETVAL |
2878 | |
3037 | |
2879 | SV *get_data (faceidx idx, int faceset = 0) |
3038 | SV *get_data (faceidx idx, int faceset = 0) |
2880 | CODE: |
3039 | CODE: |