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 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> |
5 | * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de> |
7 | * |
6 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
7 | * 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 |
8 | * 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 |
9 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
10 | * option) any later version. |
12 | * |
11 | * |
13 | * This program is distributed in the hope that it will be useful, |
12 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
15 | * GNU General Public License for more details. |
17 | * |
16 | * |
18 | * You should have received a copy of the GNU General Public License |
17 | * 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/>. |
18 | * and the GNU General Public License along with this program. If not, see |
|
|
19 | * <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include "autoconf.h" |
24 | #include "autoconf.h" |
… | |
… | |
71 | static int tick_pending; |
71 | static int tick_pending; |
72 | |
72 | |
73 | global gbl_ev; |
73 | global gbl_ev; |
74 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
74 | 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; |
75 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; |
|
|
76 | static AV *av_reflect; |
76 | |
77 | |
77 | bitset<NUM_EVENT_TYPES> ev_want_event; |
78 | bitset<NUM_EVENT_TYPES> ev_want_event; |
78 | bitset<NUM_TYPES> ev_want_type; |
79 | bitset<NUM_TYPES> ev_want_type; |
79 | |
80 | |
80 | static HV |
81 | static HV |
… | |
… | |
88 | *stash_cf_arch_wrap, |
89 | *stash_cf_arch_wrap, |
89 | *stash_cf_party_wrap, |
90 | *stash_cf_party_wrap, |
90 | *stash_cf_region_wrap, |
91 | *stash_cf_region_wrap, |
91 | *stash_cf_living_wrap; |
92 | *stash_cf_living_wrap; |
92 | |
93 | |
|
|
94 | static SV |
|
|
95 | *cv_cf_do_invoke, |
|
|
96 | *cv_cf__can_merge, |
|
|
97 | *cv_cf_client_send_msg, |
|
|
98 | *cv_cf_tick, |
|
|
99 | *cv_cf_match_match; |
|
|
100 | |
93 | #ifndef newSVpv_utf8 |
101 | #ifndef newSVpv_utf8 |
94 | static inline SV * |
102 | static inline SV * |
95 | newSVpv_utf8 (const char *s) |
103 | newSVpv_utf8 (const char *s) |
96 | { |
104 | { |
97 | if (!s) |
105 | if (!s) |
… | |
… | |
202 | attachable::destroy () |
210 | attachable::destroy () |
203 | { |
211 | { |
204 | if (destroyed ()) |
212 | if (destroyed ()) |
205 | return; |
213 | return; |
206 | |
214 | |
207 | flags |= F_DESTROYED; |
215 | attachable_flags |= F_DESTROYED; |
208 | do_destroy (); |
216 | do_destroy (); |
209 | sever_self (); |
217 | sever_self (); |
210 | } |
218 | } |
211 | |
219 | |
212 | void |
220 | void |
… | |
… | |
286 | |
294 | |
287 | attach = src.attach; |
295 | attach = src.attach; |
288 | return *this; |
296 | return *this; |
289 | } |
297 | } |
290 | |
298 | |
|
|
299 | #if 0 |
291 | template<typename T> |
300 | template<typename T> |
292 | static bool |
301 | static bool |
293 | find_backref (void *ptr, T *obj) |
302 | find_backref (void *ptr, T *obj) |
294 | { |
303 | { |
295 | char *s = (char *)obj; |
304 | char *s = (char *)obj; |
… | |
… | |
303 | |
312 | |
304 | return false; |
313 | return false; |
305 | } |
314 | } |
306 | |
315 | |
307 | // for debugging, find "live" objects containing this ptr |
316 | // for debugging, find "live" objects containing this ptr |
308 | void |
317 | static void |
309 | find_backref (void *ptr) |
318 | find_backref (void *ptr) |
310 | { |
319 | { |
311 | for_all_objects (op) |
320 | for_all_objects (op) |
312 | if (find_backref (ptr, op)) |
321 | if (find_backref (ptr, op)) |
313 | fprintf (stderr, "O %p %d:'%s'\n", op, op->count, &op->name); |
322 | fprintf (stderr, "O %p %d:'%s'\n", op, op->count, &op->name); |
… | |
… | |
317 | fprintf (stderr, "P %p\n", pl); |
326 | fprintf (stderr, "P %p\n", pl); |
318 | |
327 | |
319 | for_all_clients (ns) |
328 | for_all_clients (ns) |
320 | if (find_backref (ptr, ns)) |
329 | if (find_backref (ptr, ns)) |
321 | fprintf (stderr, "C %p\n", ns); |
330 | fprintf (stderr, "C %p\n", ns); |
322 | |
|
|
323 | } |
331 | } |
|
|
332 | #endif |
324 | |
333 | |
325 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
334 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
326 | |
335 | |
327 | static SV * |
336 | static SV * |
328 | newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) |
337 | newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) |
… | |
… | |
381 | |
390 | |
382 | return sv; |
391 | return sv; |
383 | } |
392 | } |
384 | } |
393 | } |
385 | |
394 | |
|
|
395 | #if 0 // unused |
386 | static void |
396 | static void |
387 | clearSVptr (SV *sv) |
397 | clearSVptr (SV *sv) |
388 | { |
398 | { |
389 | if (SvROK (sv)) |
399 | if (SvROK (sv)) |
390 | sv = SvRV (sv); |
400 | sv = SvRV (sv); |
391 | |
401 | |
392 | hv_clear ((HV *)sv); |
402 | hv_clear ((HV *)sv); |
393 | sv_unmagic (sv, PERL_MAGIC_ext); |
403 | sv_unmagic (sv, PERL_MAGIC_ext); |
394 | } |
404 | } |
|
|
405 | #endif |
|
|
406 | |
|
|
407 | static long 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 noinline |
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; |
… | |
… | |
633 | var = 0; |
693 | var = 0; |
634 | } |
694 | } |
635 | |
695 | |
636 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
696 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
637 | |
697 | |
638 | SV * |
698 | static SV * |
639 | registry (attachable *ext) |
699 | registry (attachable *ext) |
640 | { |
700 | { |
641 | if (!ext->cb) |
701 | if (!ext->cb) |
642 | ext->cb = newAV (); |
702 | ext->cb = newAV (); |
643 | |
703 | |
… | |
… | |
919 | XPUSHs (sv_2mortal (newSVdt_va (ap, dt))); |
979 | XPUSHs (sv_2mortal (newSVdt_va (ap, dt))); |
920 | } |
980 | } |
921 | |
981 | |
922 | va_end (ap); |
982 | va_end (ap); |
923 | |
983 | |
924 | CALL_CALL ("cf::do_invoke", G_SCALAR); |
984 | CALL_CALL (cv_cf_do_invoke, G_SCALAR); |
925 | count = count > 0 ? POPi : 0; |
985 | count = count > 0 ? POPi : 0; |
926 | |
986 | |
927 | CALL_END; |
987 | CALL_END; |
928 | |
988 | |
929 | return count; |
989 | return count; |
930 | } |
990 | } |
931 | |
991 | |
932 | SV * |
992 | static SV * |
933 | cfperl_result (int idx) |
993 | cfperl_result (int idx) |
934 | { |
994 | { |
935 | AV *av = get_av ("cf::INVOKE_RESULTS", 0); |
995 | AV *av = get_av ("cf::INVOKE_RESULTS", 0); |
936 | if (!av) |
996 | if (!av) |
937 | return &PL_sv_undef; |
997 | return &PL_sv_undef; |
… | |
… | |
970 | |
1030 | |
971 | dSP; |
1031 | dSP; |
972 | |
1032 | |
973 | PUSHMARK (SP); |
1033 | PUSHMARK (SP); |
974 | PUTBACK; |
1034 | PUTBACK; |
975 | call_pv ("cf::tick", G_DISCARD | G_VOID); |
1035 | call_pvsv (cv_cf_tick, G_DISCARD | G_VOID); |
976 | |
1036 | |
977 | 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); |
978 | } |
1038 | } |
979 | |
1039 | |
980 | void |
1040 | void |
… | |
… | |
1010 | CALL_BEGIN (4); |
1070 | CALL_BEGIN (4); |
1011 | CALL_ARG (ns); |
1071 | CALL_ARG (ns); |
1012 | CALL_ARG (type); |
1072 | CALL_ARG (type); |
1013 | CALL_ARG_SV (newSVpv_utf8 (msg)); |
1073 | CALL_ARG_SV (newSVpv_utf8 (msg)); |
1014 | CALL_ARG (color); |
1074 | CALL_ARG (color); |
1015 | CALL_CALL ("cf::client::send_msg", G_VOID); |
1075 | CALL_CALL (cv_cf_client_send_msg, G_VOID); |
1016 | CALL_END; |
1076 | CALL_END; |
1017 | } |
1077 | } |
1018 | |
1078 | |
1019 | int |
1079 | int |
1020 | cfperl_can_merge (object *ob1, object *ob2) |
1080 | cfperl_can_merge (object *ob1, object *ob2) |
… | |
… | |
1022 | int can; |
1082 | int can; |
1023 | |
1083 | |
1024 | CALL_BEGIN (2); |
1084 | CALL_BEGIN (2); |
1025 | CALL_ARG (ob1); |
1085 | CALL_ARG (ob1); |
1026 | CALL_ARG (ob2); |
1086 | CALL_ARG (ob2); |
1027 | CALL_CALL ("cf::_can_merge", G_SCALAR); |
1087 | CALL_CALL (cv_cf__can_merge, G_SCALAR); |
1028 | can = count && SvTRUE (TOPs); |
1088 | can = count && SvTRUE (TOPs); |
1029 | CALL_END; |
1089 | CALL_END; |
1030 | |
1090 | |
1031 | return can; |
1091 | return can; |
1032 | } |
1092 | } |
1033 | |
1093 | |
1034 | void |
1094 | void |
1035 | cfperl_mapscript_activate (object *ob, object *activator, int state) |
1095 | cfperl_mapscript_activate (object *ob, int state, object *activator, object *originator) |
1036 | { |
1096 | { |
1037 | CALL_BEGIN (3); |
1097 | CALL_BEGIN (4); |
1038 | CALL_ARG (ob); |
1098 | CALL_ARG (ob); |
|
|
1099 | CALL_ARG (state); |
1039 | CALL_ARG (activator); |
1100 | CALL_ARG (activator); |
1040 | CALL_ARG (state); |
1101 | CALL_ARG (originator); |
1041 | CALL_CALL ("cf::mapscript::activate", G_VOID); |
1102 | CALL_CALL ("cf::mapscript::activate", G_VOID); |
1042 | CALL_END; |
1103 | CALL_END; |
1043 | } |
1104 | } |
1044 | |
1105 | |
1045 | player * |
1106 | player * |
… | |
… | |
1187 | CALL_CALL ("cf::_log_backtrace", G_VOID); |
1248 | CALL_CALL ("cf::_log_backtrace", G_VOID); |
1188 | CALL_END; |
1249 | CALL_END; |
1189 | #endif |
1250 | #endif |
1190 | } |
1251 | } |
1191 | |
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 | |
1192 | ///////////////////////////////////////////////////////////////////////////// |
1304 | ///////////////////////////////////////////////////////////////////////////// |
1193 | |
1305 | |
1194 | struct EVAPI *evapi::GEVAPI; |
1306 | struct EVAPI *evapi::GEVAPI; |
1195 | struct CoroAPI *coroapi::GCoroAPI; |
1307 | struct CoroAPI *coroapi::GCoroAPI; |
1196 | |
1308 | |
… | |
… | |
1228 | if (active) start (); |
1340 | if (active) start (); |
1229 | } |
1341 | } |
1230 | } |
1342 | } |
1231 | |
1343 | |
1232 | static void |
1344 | static void |
1233 | _connect_to_perl () |
1345 | _connect_to_perl_1 () |
1234 | { |
1346 | { |
1235 | stash_cf = gv_stashpv ("cf", 1); |
1347 | stash_cf = gv_stashpv ("cf", 1); |
1236 | |
1348 | |
1237 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
1349 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
1238 | 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); |
… | |
… | |
1257 | cb_client = get_av ("cf::CB_CLIENT", 1); |
1369 | cb_client = get_av ("cf::CB_CLIENT", 1); |
1258 | cb_type = get_av ("cf::CB_TYPE" , 1); |
1370 | cb_type = get_av ("cf::CB_TYPE" , 1); |
1259 | cb_map = get_av ("cf::CB_MAP" , 1); |
1371 | cb_map = get_av ("cf::CB_MAP" , 1); |
1260 | } |
1372 | } |
1261 | |
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 | |
1262 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1384 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1263 | |
1385 | |
1264 | BOOT: |
1386 | BOOT: |
1265 | { |
1387 | { |
1266 | I_EV_API (PACKAGE); evapi::GEVAPI = GEVAPI; |
1388 | I_EV_API (PACKAGE); evapi::GEVAPI = GEVAPI; |
1267 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1389 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1268 | |
1390 | |
1269 | _connect_to_perl (); |
1391 | _connect_to_perl_1 (); |
1270 | |
1392 | |
1271 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1393 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1272 | |
1394 | |
1273 | //{ |
1395 | //{ |
1274 | // require_pv ("Time::HiRes"); |
1396 | // require_pv ("Time::HiRes"); |
… | |
… | |
1318 | 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) |
1319 | 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) |
1320 | 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) |
1321 | 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) |
1322 | 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) |
1323 | 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) |
1324 | 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) |
1325 | 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) |
1326 | 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) |
1327 | 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) |
1328 | 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) |
… | |
… | |
1354 | 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) |
1355 | 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) |
1356 | 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) |
1357 | 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) |
1358 | 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) |
1359 | 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) |
1360 | 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) |
1361 | 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) |
1362 | 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) |
1363 | 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) |
1364 | 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) |
… | |
… | |
1546 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1668 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1547 | av_push (event, newSViv (eiv->klass)); |
1669 | av_push (event, newSViv (eiv->klass)); |
1548 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1670 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1549 | newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv)); |
1671 | newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv)); |
1550 | } |
1672 | } |
|
|
1673 | |
|
|
1674 | // used by autogenerated BOOT sections from genacc |
|
|
1675 | av_reflect = get_av ("cf::REFLECT", 1); |
1551 | } |
1676 | } |
1552 | |
1677 | |
1553 | void _gv_clear (SV *gv) |
1678 | void _gv_clear (SV *gv) |
1554 | CODE: |
1679 | CODE: |
1555 | assert (SvTYPE (gv) == SVt_PVGV); |
1680 | assert (SvTYPE (gv) == SVt_PVGV); |
… | |
… | |
1562 | f (GvGP (gv)->gp_cv); |
1687 | f (GvGP (gv)->gp_cv); |
1563 | GvCVGEN (gv) = 0; |
1688 | GvCVGEN (gv) = 0; |
1564 | GvMULTI_off (gv); |
1689 | GvMULTI_off (gv); |
1565 | # undef f |
1690 | # undef f |
1566 | |
1691 | |
1567 | void _connect_to_perl () |
1692 | void _connect_to_perl_1 () |
|
|
1693 | |
|
|
1694 | void _connect_to_perl_2 () |
1568 | |
1695 | |
1569 | void _recalc_want () |
1696 | void _recalc_want () |
1570 | |
1697 | |
1571 | # not used by default anymore |
1698 | # not used by default anymore |
1572 | void _global_reattach () |
1699 | void _global_reattach () |
… | |
… | |
1937 | RETVAL |
2064 | RETVAL |
1938 | |
2065 | |
1939 | void |
2066 | void |
1940 | debug_trace (attachable *obj, bool on = true) |
2067 | debug_trace (attachable *obj, bool on = true) |
1941 | CODE: |
2068 | CODE: |
1942 | obj->flags &= ~attachable::F_DEBUG_TRACE; |
2069 | obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; |
1943 | if (on) |
2070 | if (on) |
1944 | obj->flags |= attachable::F_DEBUG_TRACE; |
2071 | obj->attachable_flags |= attachable::F_DEBUG_TRACE; |
1945 | |
2072 | |
1946 | int mortals_size () |
2073 | int mortals_size () |
1947 | CODE: |
2074 | CODE: |
1948 | RETVAL = attachable::mortals.size (); |
2075 | RETVAL = attachable::mortals.size (); |
1949 | OUTPUT: RETVAL |
2076 | OUTPUT: RETVAL |
… | |
… | |
2090 | CODE: |
2217 | CODE: |
2091 | player_apply_below (op); |
2218 | player_apply_below (op); |
2092 | |
2219 | |
2093 | 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) |
2094 | |
2221 | |
|
|
2222 | int casting_level (object *caster, object *spell) |
|
|
2223 | |
2095 | int pay_item (object *op, object *buyer) |
2224 | int pay_item (object *op, object *buyer) |
2096 | CODE: |
2225 | CODE: |
2097 | RETVAL = pay_for_item (op, buyer); |
2226 | RETVAL = pay_for_item (op, buyer); |
2098 | OUTPUT: RETVAL |
2227 | OUTPUT: RETVAL |
2099 | |
2228 | |
… | |
… | |
2141 | |
2270 | |
2142 | void player_lvl_adj (object *who, object *skill = 0) |
2271 | void player_lvl_adj (object *who, object *skill = 0) |
2143 | |
2272 | |
2144 | 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) |
2145 | |
2274 | |
2146 | int calc_skill_exp (object *who, object *op, object *skill); |
2275 | int calc_skill_exp (object *who, object *op, object *skill) |
2147 | |
2276 | |
2148 | void push_button (object *op); |
2277 | void push_button (object *op, object *originator) |
2149 | |
2278 | |
2150 | void use_trigger (object *op); |
2279 | void use_trigger (object *op, object *originator) |
2151 | |
2280 | |
2152 | void handle_apply_yield (object *op); |
2281 | void handle_apply_yield (object *op) |
|
|
2282 | |
|
|
2283 | int convert_item (object *item, object *converter) |
2153 | |
2284 | |
2154 | |
2285 | |
2155 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2286 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2156 | |
2287 | |
2157 | # 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 |
… | |
… | |
2170 | 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) |
2171 | PROTOTYPE: $$$$$$ |
2302 | PROTOTYPE: $$$$$$ |
2172 | CODE: |
2303 | CODE: |
2173 | { |
2304 | { |
2174 | 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; |
2175 | } |
2309 | } |
2176 | |
2310 | |
2177 | shstr |
2311 | shstr |
2178 | object::kv_get (shstr key) |
2312 | object::kv_get (shstr key) |
2179 | |
2313 | |
… | |
… | |
2363 | void |
2497 | void |
2364 | adjust_daylight () |
2498 | adjust_daylight () |
2365 | CODE: |
2499 | CODE: |
2366 | maptile::adjust_daylight (); |
2500 | maptile::adjust_daylight (); |
2367 | |
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 | |
2368 | void |
2511 | void |
2369 | maptile::instantiate () |
2512 | maptile::instantiate () |
2370 | |
2513 | |
2371 | maptile *new () |
2514 | maptile *new () |
2372 | PROTOTYPE: |
2515 | PROTOTYPE: |
… | |
… | |
2403 | for (int x = 0; x < THIS->width; ++x) |
2546 | for (int x = 0; x < THIS->width; ++x) |
2404 | for (int y = 0; y < THIS->height; ++y) |
2547 | for (int y = 0; y < THIS->height; ++y) |
2405 | { |
2548 | { |
2406 | 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) |
2407 | if (op->flag [FLAG_IS_FLOOR]) |
2550 | if (op->flag [FLAG_IS_FLOOR]) |
2408 | goto skip_space; |
2551 | goto skip; |
2409 | |
2552 | |
2410 | { |
2553 | { |
2411 | int offs = offset + y * stride + x; |
2554 | int offs = offset + y * stride + x; |
|
|
2555 | |
2412 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2556 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2413 | { |
2557 | { |
2414 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2558 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2415 | { |
2559 | { |
2416 | object *ob = get_archetype (SvPVutf8_nolen (*elem)); |
2560 | object *ob = get_archetype (SvPVutf8_nolen (*elem)); |
2417 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2561 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2418 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2562 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2419 | |
2563 | |
2420 | if (ob->randomitems) |
2564 | if (ob->randomitems && !ob->above) |
2421 | { |
2565 | { |
2422 | if (!ob->above) |
|
|
2423 | { |
|
|
2424 | ob->create_treasure (ob->randomitems); |
2566 | ob->create_treasure (ob->randomitems); |
2425 | |
2567 | |
2426 | for (object *op = ob->above; op; op = op->above) |
2568 | for (object *op = ob->above; op; op = op->above) |
2427 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2569 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2428 | } |
2570 | // TODO: if this is a pickable object, then the item |
2429 | |
2571 | // will at a bit weird - saving inside the player |
2430 | 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. |
2431 | } |
2576 | } |
2432 | } |
2577 | } |
2433 | } |
2578 | } |
2434 | } |
2579 | } |
2435 | |
2580 | |
2436 | skip_space: ; |
2581 | skip: ; |
2437 | } |
2582 | } |
2438 | } |
2583 | } |
2439 | |
2584 | |
2440 | void |
2585 | void |
2441 | maptile::set_regiondata (SV *data, int offset, int stride, SV *palette) |
2586 | maptile::set_regiondata (SV *data, int offset, int stride, SV *palette) |
… | |
… | |
2581 | case 6: RETVAL = newSVuv (ms.move_on ); break; |
2726 | case 6: RETVAL = newSVuv (ms.move_on ); break; |
2582 | case 7: RETVAL = newSVuv (ms.move_off ); break; |
2727 | case 7: RETVAL = newSVuv (ms.move_off ); break; |
2583 | } |
2728 | } |
2584 | } |
2729 | } |
2585 | OUTPUT: RETVAL |
2730 | OUTPUT: RETVAL |
2586 | |
|
|
2587 | void fix_walls (maptile *map, int x, int y) |
|
|
2588 | |
|
|
2589 | void fix_walls_around (maptile *map, int x, int y) |
|
|
2590 | |
2731 | |
2591 | # worst xs function of my life |
2732 | # worst xs function of my life |
2592 | bool |
2733 | bool |
2593 | _create_random_map (\ |
2734 | _create_random_map (\ |
2594 | maptile *self,\ |
2735 | maptile *self,\ |
… | |
… | |
2865 | faceinfo *f = face_info (idx); assert (f); |
3006 | faceinfo *f = face_info (idx); assert (f); |
2866 | facedata *d = &(faceset ? f->data64 : f->data32); |
3007 | facedata *d = &(faceset ? f->data64 : f->data32); |
2867 | sv_to (data, d->data); |
3008 | sv_to (data, d->data); |
2868 | STRLEN clen; |
3009 | STRLEN clen; |
2869 | char *cdata = SvPVbyte (chksum, clen); |
3010 | char *cdata = SvPVbyte (chksum, clen); |
2870 | clen = min (CHKSUM_SIZE, clen); |
3011 | clen = min (CHKSUM_MAXLEN, clen); |
2871 | |
3012 | |
2872 | if (memcmp (d->chksum, cdata, clen)) |
3013 | if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) |
2873 | { |
3014 | { |
|
|
3015 | d->chksum_len = clen; |
2874 | memcpy (d->chksum, cdata, clen); |
3016 | memcpy (d->chksum, cdata, clen); |
2875 | |
3017 | |
2876 | // invalidate existing client face info |
3018 | // invalidate existing client face info |
2877 | for_all_clients (ns) |
3019 | for_all_clients (ns) |
2878 | if (ns->faceset == faceset) |
3020 | if (ns->faceset == faceset) |
… | |
… | |
2893 | |
3035 | |
2894 | SV *get_chksum (faceidx idx, int faceset = 0) |
3036 | SV *get_chksum (faceidx idx, int faceset = 0) |
2895 | CODE: |
3037 | CODE: |
2896 | facedata *d = face_data (idx, faceset); |
3038 | facedata *d = face_data (idx, faceset); |
2897 | if (!d) XSRETURN_UNDEF; |
3039 | if (!d) XSRETURN_UNDEF; |
2898 | RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE); |
3040 | RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); |
2899 | OUTPUT: |
3041 | OUTPUT: |
2900 | RETVAL |
3042 | RETVAL |
2901 | |
3043 | |
2902 | SV *get_data (faceidx idx, int faceset = 0) |
3044 | SV *get_data (faceidx idx, int faceset = 0) |
2903 | CODE: |
3045 | CODE: |