… | |
… | |
52 | #include <XSUB.h> |
52 | #include <XSUB.h> |
53 | |
53 | |
54 | #include "CoroAPI.h" |
54 | #include "CoroAPI.h" |
55 | #include "perlxsi.c" |
55 | #include "perlxsi.c" |
56 | |
56 | |
57 | extern sint64 *levels; // the experience table |
|
|
58 | |
|
|
59 | typedef object_thawer &object_thawer_ref; |
57 | typedef object_thawer &object_thawer_ref; |
60 | typedef object_freezer &object_freezer_ref; |
58 | typedef object_freezer &object_freezer_ref; |
61 | |
59 | |
62 | typedef std::string std__string; |
60 | typedef std::string std__string; |
63 | |
61 | |
… | |
… | |
85 | *stash_cf_mapspace_wrap, |
83 | *stash_cf_mapspace_wrap, |
86 | *stash_cf_client_wrap, |
84 | *stash_cf_client_wrap, |
87 | *stash_cf_arch_wrap, |
85 | *stash_cf_arch_wrap, |
88 | *stash_cf_party_wrap, |
86 | *stash_cf_party_wrap, |
89 | *stash_cf_region_wrap, |
87 | *stash_cf_region_wrap, |
90 | *stash_cf_living_wrap; |
88 | *stash_cf_living_wrap, |
|
|
89 | *stash_ext_map_world; |
91 | |
90 | |
92 | static SV |
91 | static SV |
93 | *cv_cf_do_invoke, |
92 | *cv_cf_do_invoke, |
94 | *cv_cf__can_merge, |
93 | *cv_cf__can_merge, |
95 | *cv_cf_client_send_msg, |
94 | *cv_cf_client_send_msg, |
… | |
… | |
353 | #endif |
352 | #endif |
354 | |
353 | |
355 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
354 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
356 | |
355 | |
357 | static SV * |
356 | static SV * |
358 | newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) |
357 | newSVptr (void *ptr, HV *stash, HV *hv) |
359 | { |
358 | { |
360 | SV *sv; |
359 | SV *sv; |
361 | |
360 | |
362 | if (!ptr) |
361 | if (!ptr) |
363 | return newSV (0); |
362 | return newSV (0); |
364 | |
363 | |
365 | sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); |
364 | sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); |
366 | return sv_bless (newRV_noinc ((SV *)hv), stash); |
365 | return sv_bless (newRV_noinc ((SV *)hv), stash); |
|
|
366 | } |
|
|
367 | |
|
|
368 | static SV * |
|
|
369 | newSVptr (void *ptr, HV *stash) |
|
|
370 | { |
|
|
371 | return newSVptr (ptr, stash, newHV ()); |
367 | } |
372 | } |
368 | |
373 | |
369 | static int |
374 | static int |
370 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
375 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
371 | { |
376 | { |
… | |
… | |
479 | || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap |
484 | || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap |
480 | && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap |
485 | && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap |
481 | && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap |
486 | && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap |
482 | && !sv_derived_from (sv, "cf::object"))) |
487 | && !sv_derived_from (sv, "cf::object"))) |
483 | croak ("object of type cf::object expected"); |
488 | croak ("object of type cf::object expected"); |
|
|
489 | |
|
|
490 | return SvPTR_nc (sv); |
|
|
491 | } |
|
|
492 | |
|
|
493 | static long noinline |
|
|
494 | SvPTR_ornull_maptile (SV *sv) |
|
|
495 | { |
|
|
496 | if (expect_false (!SvOK (sv))) return 0; |
|
|
497 | |
|
|
498 | if (!SvROK (sv) |
|
|
499 | || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap |
|
|
500 | && SvSTASH (SvRV (sv)) != stash_ext_map_world |
|
|
501 | && !sv_derived_from (sv, "cf::map"))) |
|
|
502 | croak ("object of type cf::map expected"); |
484 | |
503 | |
485 | return SvPTR_nc (sv); |
504 | return SvPTR_nc (sv); |
486 | } |
505 | } |
487 | |
506 | |
488 | static long noinline |
507 | static long noinline |
… | |
… | |
565 | static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
584 | static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
566 | static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } |
585 | static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } |
567 | static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } |
586 | static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } |
568 | static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
587 | static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
569 | static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
588 | static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
570 | static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } |
589 | static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } |
571 | static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } |
590 | static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } |
572 | static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } |
591 | static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } |
|
|
592 | static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull_maptile (sv); } |
573 | static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
593 | static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
574 | static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); } |
|
|
575 | static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } |
594 | static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } |
576 | static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
595 | static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
577 | static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } |
596 | static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } |
578 | static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } |
597 | static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } |
579 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } |
598 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } |
… | |
… | |
695 | template<class type> |
714 | template<class type> |
696 | static void noinline |
715 | static void noinline |
697 | cf_obj_to (SV *arg, type &var) |
716 | cf_obj_to (SV *arg, type &var) |
698 | { |
717 | { |
699 | sv_to (arg, var); |
718 | sv_to (arg, var); |
700 | if (!var) |
719 | if (expect_false (!var)) |
701 | croak ("must not pass invalid/null cf_obj here"); |
720 | croak ("must not pass invalid/null cf_obj here"); |
702 | } |
721 | } |
703 | |
722 | |
704 | template<class object> |
723 | template<class object> |
705 | static void noinline |
724 | static void noinline |
706 | cf_obj_ornull_to (SV *arg, object *&var) |
725 | cf_obj_ornull_to (SV *arg, object *&var) |
707 | { |
726 | { |
708 | if (SvOK (arg)) |
727 | if (SvOK (arg)) |
709 | { |
728 | { |
710 | sv_to (arg, var); |
729 | sv_to (arg, var); |
711 | if (!var) |
730 | if (expect_false (!var)) |
712 | croak ("unable to convert perl object to C++ object"); |
731 | croak ("unable to convert perl object to C++ object"); |
713 | } |
732 | } |
714 | else |
733 | else |
715 | var = 0; |
734 | var = 0; |
716 | } |
735 | } |
… | |
… | |
1378 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1397 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1379 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1398 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1380 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1399 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1381 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1400 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1382 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1401 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
|
|
1402 | stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1383 | |
1403 | |
1384 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1404 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1385 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
1405 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
1386 | sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); |
1406 | sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); |
1387 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1407 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
… | |
… | |
1799 | |
1819 | |
1800 | int random_roll (int min, int max, object *op, int goodbad); |
1820 | int random_roll (int min, int max, object *op, int goodbad); |
1801 | |
1821 | |
1802 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1822 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1803 | |
1823 | |
1804 | int |
|
|
1805 | exp_to_level (val64 exp) |
1824 | int exp_to_level (val64 exp) |
1806 | CODE: |
|
|
1807 | { |
|
|
1808 | int i = 0; |
|
|
1809 | |
1825 | |
1810 | RETVAL = settings.max_level; |
|
|
1811 | |
|
|
1812 | for (i = 1; i <= settings.max_level; i++) |
|
|
1813 | { |
|
|
1814 | if (levels[i] > exp) |
|
|
1815 | { |
|
|
1816 | RETVAL = i - 1; |
|
|
1817 | break; |
|
|
1818 | } |
|
|
1819 | } |
|
|
1820 | } |
|
|
1821 | OUTPUT: RETVAL |
|
|
1822 | |
|
|
1823 | val64 |
|
|
1824 | level_to_min_exp (int level) |
1826 | val64 level_to_min_exp (int level) |
1825 | CODE: |
|
|
1826 | if (level > settings.max_level) |
|
|
1827 | RETVAL = levels[settings.max_level]; |
|
|
1828 | else if (level < 1) |
|
|
1829 | RETVAL = 0; |
|
|
1830 | else |
|
|
1831 | RETVAL = levels[level]; |
|
|
1832 | OUTPUT: RETVAL |
|
|
1833 | |
1827 | |
1834 | SV * |
1828 | SV * |
1835 | resistance_to_string (int atnr) |
1829 | resistance_to_string (int atnr) |
1836 | CODE: |
1830 | CODE: |
1837 | if (atnr >= 0 && atnr < NROFATTACKS) |
1831 | if (atnr >= 0 && atnr < NROFATTACKS) |
… | |
… | |
1895 | CODE: |
1889 | CODE: |
1896 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1890 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1897 | OUTPUT: |
1891 | OUTPUT: |
1898 | RETVAL |
1892 | RETVAL |
1899 | |
1893 | |
|
|
1894 | bool should_invoke (attachable *obj, int event) |
|
|
1895 | CODE: |
|
|
1896 | RETVAL = obj->should_invoke ((event_type)event); |
|
|
1897 | OUTPUT: RETVAL |
|
|
1898 | |
1900 | void |
1899 | void |
1901 | debug_trace (attachable *obj, bool on = true) |
1900 | debug_trace (attachable *obj, bool on = true) |
1902 | CODE: |
1901 | CODE: |
1903 | obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; |
1902 | obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; |
1904 | if (on) |
1903 | if (on) |
… | |
… | |
2028 | } |
2027 | } |
2029 | OUTPUT: |
2028 | OUTPUT: |
2030 | RETVAL |
2029 | RETVAL |
2031 | |
2030 | |
2032 | object *find_best_object_match (object *op, utf8_string match) |
2031 | object *find_best_object_match (object *op, utf8_string match) |
2033 | |
|
|
2034 | object *find_marked_object (object *op) |
|
|
2035 | |
|
|
2036 | int need_identify (object *obj); |
|
|
2037 | |
2032 | |
2038 | int apply_shop_mat (object *shop_mat, object *op); |
2033 | int apply_shop_mat (object *shop_mat, object *op); |
2039 | |
2034 | |
2040 | int move (object *op, int dir, object *originator = op) |
2035 | int move (object *op, int dir, object *originator = op) |
2041 | CODE: |
2036 | CODE: |
… | |
… | |
2469 | if (oblinkpt *obp = map->find_link (connection)) |
2464 | if (oblinkpt *obp = map->find_link (connection)) |
2470 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2465 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2471 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2466 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2472 | |
2467 | |
2473 | void |
2468 | void |
2474 | get_map_flags (maptile *map, int x, int y) |
2469 | xy_normalise (maptile *map, int x, int y, int dir = 0) |
2475 | PPCODE: |
2470 | PPCODE: |
2476 | { |
2471 | { |
2477 | maptile *nmap = 0; |
2472 | mapxy pos (map, x, y); |
2478 | I16 nx = 0, ny = 0; |
2473 | if (!pos.move (dir).normalise ()) |
|
|
2474 | XSRETURN_EMPTY; |
2479 | |
2475 | |
2480 | PUTBACK; |
|
|
2481 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2482 | SPAGAIN; |
|
|
2483 | |
|
|
2484 | EXTEND (SP, 4); |
2476 | EXTEND (SP, 3); |
2485 | PUSHs (sv_2mortal (newSViv (flags))); |
|
|
2486 | |
|
|
2487 | if (GIMME_V == G_ARRAY) |
|
|
2488 | { |
|
|
2489 | PUSHs (sv_2mortal (to_sv (nmap))); |
2477 | PUSHs (sv_2mortal (to_sv (pos.m))); |
2490 | PUSHs (sv_2mortal (newSViv (nx))); |
2478 | PUSHs (sv_2mortal (to_sv (pos.x))); |
2491 | PUSHs (sv_2mortal (newSViv (ny))); |
2479 | PUSHs (sv_2mortal (to_sv (pos.y))); |
2492 | } |
|
|
2493 | } |
2480 | } |
2494 | |
2481 | |
2495 | mapspace * |
2482 | mapspace * |
2496 | ms (maptile *map, unsigned int x, unsigned int y) |
2483 | ms (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2497 | PROTOTYPE: $$$ |
2484 | PROTOTYPE: $$$;$ |
2498 | CODE: |
2485 | CODE: |
2499 | { |
2486 | { |
2500 | maptile *nmap = 0; |
2487 | mapxy pos (map, x, y); |
2501 | I16 nx, ny; |
2488 | if (!pos.move (dir).normalise ()) |
2502 | |
|
|
2503 | PUTBACK; |
|
|
2504 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2505 | SPAGAIN; |
|
|
2506 | |
|
|
2507 | if (!nmap) |
|
|
2508 | XSRETURN_UNDEF; |
2489 | XSRETURN_UNDEF; |
2509 | |
2490 | |
2510 | RETVAL = &nmap->at (nx, ny); |
2491 | RETVAL = &*pos; |
2511 | } |
2492 | } |
2512 | OUTPUT: |
2493 | OUTPUT: |
2513 | RETVAL |
2494 | RETVAL |
2514 | |
2495 | |
2515 | void |
2496 | void |
2516 | at (maptile *map, unsigned int x, unsigned int y) |
2497 | at (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2517 | PROTOTYPE: $$$ |
2498 | PROTOTYPE: $$$;$ |
2518 | PPCODE: |
2499 | PPCODE: |
2519 | { |
2500 | mapxy pos (map, x, y); |
2520 | maptile *nmap = 0; |
2501 | if (pos.move (dir).normalise ()) |
2521 | I16 nx, ny; |
|
|
2522 | |
|
|
2523 | PUTBACK; |
|
|
2524 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2525 | SPAGAIN; |
|
|
2526 | |
|
|
2527 | if (nmap) |
|
|
2528 | for (object *o = nmap->at (nx, ny).bot; o; o = o->above) |
2502 | for (object *o = pos->bot; o; o = o->above) |
2529 | XPUSHs (sv_2mortal (to_sv (o))); |
2503 | XPUSHs (sv_2mortal (to_sv (o))); |
2530 | } |
|
|
2531 | |
2504 | |
2532 | SV * |
2505 | SV * |
2533 | bot_at (maptile *map, unsigned int x, unsigned int y) |
2506 | bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2534 | PROTOTYPE: $$$ |
2507 | PROTOTYPE: $$$;$ |
2535 | ALIAS: |
2508 | ALIAS: |
2536 | top_at = 1 |
2509 | top_at = 1 |
2537 | flags_at = 2 |
2510 | flags_at = 2 |
2538 | light_at = 3 |
2511 | light_at = 3 |
2539 | move_block_at = 4 |
2512 | move_block_at = 4 |
2540 | move_slow_at = 5 |
2513 | move_slow_at = 5 |
2541 | move_on_at = 6 |
2514 | move_on_at = 6 |
2542 | move_off_at = 7 |
2515 | move_off_at = 7 |
2543 | CODE: |
2516 | CODE: |
2544 | { |
2517 | { |
2545 | sint16 nx = x; |
2518 | mapxy pos (map, x, y); |
2546 | sint16 ny = y; |
2519 | if (!pos.move (dir).normalise ()) |
2547 | |
|
|
2548 | if (!xy_normalise (map, nx, ny)) |
|
|
2549 | XSRETURN_UNDEF; |
2520 | XSRETURN_UNDEF; |
2550 | |
2521 | |
2551 | mapspace &ms = map->at (nx, ny); |
2522 | mapspace &ms = *pos; |
2552 | |
2523 | |
2553 | ms.update (); |
2524 | ms.update (); |
2554 | |
2525 | |
2555 | switch (ix) |
2526 | switch (ix) |
2556 | { |
2527 | { |
… | |
… | |
2954 | sv_to (sv, self); |
2925 | sv_to (sv, self); |
2955 | delete self; |
2926 | delete self; |
2956 | |
2927 | |
2957 | MODULE = cf PACKAGE = cf::object::thawer |
2928 | MODULE = cf PACKAGE = cf::object::thawer |
2958 | |
2929 | |
2959 | INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | |
2930 | INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h | |
|
|
2931 | |
|
|
2932 | bool |
|
|
2933 | errors_are_fatal (bool fatal) |
|
|
2934 | CODE: |
|
|
2935 | RETVAL = object_thawer::errors_are_fatal; |
|
|
2936 | object_thawer::errors_are_fatal = fatal; |
|
|
2937 | OUTPUT: |
|
|
2938 | RETVAL |
2960 | |
2939 | |
2961 | SV * |
2940 | SV * |
2962 | new_from_file (char *klass, octet_string path) |
2941 | new_from_file (char *klass, octet_string path) |
2963 | CODE: |
2942 | CODE: |
2964 | object_thawer *f = new object_thawer (path); |
2943 | object_thawer *f = new object_thawer (path); |