… | |
… | |
28 | |
28 | |
29 | #include <cstdarg> |
29 | #include <cstdarg> |
30 | #include <typeinfo> |
30 | #include <typeinfo> |
31 | |
31 | |
32 | #include "global.h" |
32 | #include "global.h" |
33 | #include "../random_maps/random_map.h" |
33 | #include "rmg.h" |
|
|
34 | #include "noise.h" |
34 | #include "evthread.h" |
35 | #include "evthread.h" |
35 | #include "sproto.h" |
36 | #include "sproto.h" |
36 | |
37 | |
37 | #include <unistd.h> |
38 | #include <unistd.h> |
38 | #if _POSIX_MEMLOCK |
39 | #if _POSIX_MEMLOCK |
… | |
… | |
51 | #include <perl.h> |
52 | #include <perl.h> |
52 | #include <XSUB.h> |
53 | #include <XSUB.h> |
53 | |
54 | |
54 | #include "CoroAPI.h" |
55 | #include "CoroAPI.h" |
55 | #include "perlxsi.c" |
56 | #include "perlxsi.c" |
56 | |
|
|
57 | extern sint64 *levels; // the experience table |
|
|
58 | |
57 | |
59 | typedef object_thawer &object_thawer_ref; |
58 | typedef object_thawer &object_thawer_ref; |
60 | typedef object_freezer &object_freezer_ref; |
59 | typedef object_freezer &object_freezer_ref; |
61 | |
60 | |
62 | typedef std::string std__string; |
61 | typedef std::string std__string; |
… | |
… | |
85 | *stash_cf_mapspace_wrap, |
84 | *stash_cf_mapspace_wrap, |
86 | *stash_cf_client_wrap, |
85 | *stash_cf_client_wrap, |
87 | *stash_cf_arch_wrap, |
86 | *stash_cf_arch_wrap, |
88 | *stash_cf_party_wrap, |
87 | *stash_cf_party_wrap, |
89 | *stash_cf_region_wrap, |
88 | *stash_cf_region_wrap, |
90 | *stash_cf_living_wrap; |
89 | *stash_cf_living_wrap, |
|
|
90 | *stash_cf_layout_wrap, |
|
|
91 | *stash_ext_map_world; |
91 | |
92 | |
92 | static SV |
93 | static SV |
93 | *cv_cf_do_invoke, |
94 | *cv_cf_do_invoke, |
94 | *cv_cf__can_merge, |
95 | *cv_cf__can_merge, |
95 | *cv_cf_client_send_msg, |
96 | *cv_cf_client_send_msg, |
… | |
… | |
123 | |
124 | |
124 | return sv; |
125 | return sv; |
125 | } |
126 | } |
126 | #endif |
127 | #endif |
127 | |
128 | |
128 | static noinline utf8_string |
129 | noinline utf8_string |
129 | cfSvPVutf8_nolen (SV *sv) |
130 | cfSvPVutf8_nolen (SV *sv) |
130 | { |
131 | { |
131 | SvGETMAGIC (sv); |
132 | SvGETMAGIC (sv); |
132 | |
133 | |
133 | if (SvPOK (sv)) |
134 | if (SvPOK (sv)) |
… | |
… | |
353 | #endif |
354 | #endif |
354 | |
355 | |
355 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
356 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
356 | |
357 | |
357 | static SV * |
358 | static SV * |
358 | newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) |
359 | newSVptr (void *ptr, HV *stash, HV *hv) |
359 | { |
360 | { |
360 | SV *sv; |
|
|
361 | |
|
|
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 * noinline |
|
|
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 | { |
… | |
… | |
383 | return 0; |
388 | return 0; |
384 | } |
389 | } |
385 | |
390 | |
386 | MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; |
391 | MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; |
387 | |
392 | |
388 | static SV * |
393 | static SV * noinline |
389 | newSVattachable (attachable *obj, HV *stash) |
394 | newSVattachable (attachable *obj, HV *stash) |
390 | { |
395 | { |
391 | if (!obj) |
396 | if (!obj) |
392 | return newSV (0); |
397 | return newSV (0); |
393 | |
398 | |
… | |
… | |
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 |
… | |
… | |
513 | static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
532 | static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
514 | static inline SV *to_sv (float v) { return newSVnv (v); } |
533 | static inline SV *to_sv (float v) { return newSVnv (v); } |
515 | static inline SV *to_sv (double v) { return newSVnv (v); } |
534 | static inline SV *to_sv (double v) { return newSVnv (v); } |
516 | static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
535 | static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
517 | static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
536 | static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
|
|
537 | // gcc dislikes noilnine on to_sv |
518 | static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
538 | static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
|
|
539 | static inline SV *to_sv (object * v) { return to_sv_ni (v); } |
519 | static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
540 | static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
520 | static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
541 | static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
521 | static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
542 | static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
522 | static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
543 | static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
523 | static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
544 | static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
524 | static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
545 | static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
|
|
546 | static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); } |
525 | |
547 | |
526 | static inline SV *to_sv (object & v) { return to_sv (&v); } |
548 | static inline SV *to_sv (object & v) { return to_sv (&v); } |
527 | static inline SV *to_sv (living & v) { return to_sv (&v); } |
549 | static inline SV *to_sv (living & v) { return to_sv (&v); } |
528 | |
550 | |
529 | static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
551 | static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
… | |
… | |
565 | static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
587 | 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); } |
588 | 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); } |
589 | 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); } |
590 | 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); } |
591 | 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); } |
592 | 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); } |
593 | 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); } |
594 | static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } |
|
|
595 | 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"); } |
596 | 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"); } |
597 | 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"); } |
598 | 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"); } |
599 | 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"); } |
600 | 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"); } |
601 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } |
|
|
602 | static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); } |
580 | static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } |
603 | static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } |
581 | static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } |
604 | static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } |
582 | |
605 | |
583 | //static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
606 | //static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
584 | static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
607 | static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
… | |
… | |
695 | template<class type> |
718 | template<class type> |
696 | static void noinline |
719 | static void noinline |
697 | cf_obj_to (SV *arg, type &var) |
720 | cf_obj_to (SV *arg, type &var) |
698 | { |
721 | { |
699 | sv_to (arg, var); |
722 | sv_to (arg, var); |
700 | if (!var) |
723 | if (expect_false (!var)) |
701 | croak ("must not pass invalid/null cf_obj here"); |
724 | croak ("must not pass invalid/null cf_obj here"); |
702 | } |
725 | } |
703 | |
726 | |
704 | template<class object> |
727 | template<class object> |
705 | static void noinline |
728 | static void noinline |
706 | cf_obj_ornull_to (SV *arg, object *&var) |
729 | cf_obj_ornull_to (SV *arg, object *&var) |
707 | { |
730 | { |
708 | if (SvOK (arg)) |
731 | if (SvOK (arg)) |
709 | { |
732 | { |
710 | sv_to (arg, var); |
733 | sv_to (arg, var); |
711 | if (!var) |
734 | if (expect_false (!var)) |
712 | croak ("unable to convert perl object to C++ object"); |
735 | croak ("unable to convert perl object to C++ object"); |
713 | } |
736 | } |
714 | else |
737 | else |
715 | var = 0; |
738 | var = 0; |
716 | } |
739 | } |
… | |
… | |
751 | exit (EXIT_FAILURE); |
774 | exit (EXIT_FAILURE); |
752 | } |
775 | } |
753 | |
776 | |
754 | eval_pv ( |
777 | eval_pv ( |
755 | "#line 1 'cfperl init'\n" |
778 | "#line 1 'cfperl init'\n" |
756 | "use EV ();\n" |
779 | "use EV ();\n" // required by bootstrap |
757 | "use Coro ();\n" |
780 | "use Coro ();\n" // required by bootstrap |
758 | "cf->bootstrap;\n" |
781 | "cf->bootstrap;\n" // required for cf::datadir |
759 | "unshift @INC, cf::datadir ();\n" |
782 | "unshift @INC, cf::datadir ();\n" // required for 'require' :) |
760 | "require cf;\n", |
783 | "require cf;\n", |
761 | 0 |
784 | 0 |
762 | ); |
785 | ); |
763 | |
786 | |
764 | if (SvTRUE (ERRSV)) |
787 | if (SvTRUE (ERRSV)) |
… | |
… | |
1378 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1401 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1379 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1402 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1380 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1403 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1381 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1404 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1382 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1405 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
|
|
1406 | stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); |
|
|
1407 | stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1383 | |
1408 | |
1384 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1409 | 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); |
1410 | 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); |
1411 | 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); |
1412 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
… | |
… | |
1435 | # include "attackinc.h" |
1460 | # include "attackinc.h" |
1436 | # undef def |
1461 | # undef def |
1437 | # define def(uc, flags) const_iv (SK_ ## uc) |
1462 | # define def(uc, flags) const_iv (SK_ ## uc) |
1438 | # include "skillinc.h" |
1463 | # include "skillinc.h" |
1439 | # undef def |
1464 | # undef def |
1440 | |
1465 | # define def(name, use, nonuse) const_iv (body_ ## name) |
1441 | const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) |
1466 | # include "slotinc.h" |
1442 | const_iv (logBacktrace) |
1467 | # undef def |
1443 | |
|
|
1444 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
|
|
1445 | |
1468 | |
1446 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1469 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1447 | |
1470 | |
1448 | const_iv (MAX_TIME) |
1471 | const_iv (MAX_TIME) |
1449 | const_iv (MAXSOCKBUF) |
1472 | const_iv (MAXSOCKBUF) |
… | |
… | |
1474 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1497 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1475 | |
1498 | |
1476 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1499 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1477 | }; |
1500 | }; |
1478 | |
1501 | |
1479 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1502 | for (civ = const_iv + array_length (const_iv); civ-- > const_iv; ) |
1480 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1503 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1481 | |
1504 | |
1482 | static const struct { |
1505 | static const struct { |
1483 | const char *name; |
1506 | const char *name; |
1484 | int skip; |
1507 | int skip; |
… | |
… | |
1490 | # undef def |
1513 | # undef def |
1491 | }; |
1514 | }; |
1492 | |
1515 | |
1493 | AV *av = get_av ("cf::EVENT", 1); |
1516 | AV *av = get_av ("cf::EVENT", 1); |
1494 | |
1517 | |
1495 | for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) |
1518 | for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; ) |
1496 | { |
1519 | { |
1497 | AV *event = newAV (); |
1520 | AV *event = newAV (); |
1498 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1521 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1499 | av_push (event, newSViv (eiv->klass)); |
1522 | av_push (event, newSViv (eiv->klass)); |
1500 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1523 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
… | |
… | |
1535 | |
1558 | |
1536 | for_all_objects (op) |
1559 | for_all_objects (op) |
1537 | op->reattach (); |
1560 | op->reattach (); |
1538 | } |
1561 | } |
1539 | |
1562 | |
1540 | # support function for map-world.ext |
|
|
1541 | void _quantise (SV *data_sv, SV *plt_sv) |
|
|
1542 | CODE: |
|
|
1543 | { |
|
|
1544 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
|
|
1545 | croak ("_quantise called with invalid agruments"); |
|
|
1546 | |
|
|
1547 | plt_sv = SvRV (plt_sv); |
|
|
1548 | SV **plt = AvARRAY (plt_sv); |
|
|
1549 | int plt_count = AvFILL (plt_sv) + 1; |
|
|
1550 | |
|
|
1551 | STRLEN len; |
|
|
1552 | char *data = SvPVbyte (data_sv, len); |
|
|
1553 | char *dst = data; |
|
|
1554 | |
|
|
1555 | while (len >= 3) |
|
|
1556 | { |
|
|
1557 | for (SV **val_sv = plt + plt_count; val_sv-- > plt; ) |
|
|
1558 | { |
|
|
1559 | char *val = SvPVX (*val_sv); |
|
|
1560 | |
|
|
1561 | if (val [0] == data [0] |
|
|
1562 | && val [1] == data [1] |
|
|
1563 | && val [2] == data [2]) |
|
|
1564 | { |
|
|
1565 | *dst++ = val [3]; |
|
|
1566 | goto next; |
|
|
1567 | } |
|
|
1568 | } |
|
|
1569 | |
|
|
1570 | croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d", |
|
|
1571 | (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2], |
|
|
1572 | dst - SvPVX (data_sv), len); |
|
|
1573 | |
|
|
1574 | next: |
|
|
1575 | data += 3; |
|
|
1576 | len -= 3; |
|
|
1577 | } |
|
|
1578 | |
|
|
1579 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
|
|
1580 | } |
|
|
1581 | |
|
|
1582 | void init_anim () |
1563 | void init_anim () |
1583 | |
1564 | |
1584 | void init_globals () |
1565 | void init_globals () |
1585 | |
1566 | |
1586 | void init_experience () |
|
|
1587 | |
|
|
1588 | void init_attackmess () |
1567 | void init_attackmess () |
1589 | |
1568 | |
1590 | void init_dynamic () |
1569 | void init_dynamic () |
1591 | |
1570 | |
1592 | void load_settings () |
1571 | void load_settings () |
1593 | |
1572 | |
|
|
1573 | void reload_exp_table () |
|
|
1574 | |
1594 | void load_materials () |
1575 | void reload_materials () |
1595 | |
1576 | |
1596 | void init_uuid () |
1577 | void init_uuid () |
1597 | CODE: |
1578 | CODE: |
1598 | UUID::init (); |
1579 | UUID::init (); |
1599 | |
1580 | |
… | |
… | |
1754 | |
1735 | |
1755 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1736 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1756 | INIT: |
1737 | INIT: |
1757 | #if __GLIBC__ |
1738 | #if __GLIBC__ |
1758 | mallopt (M_TOP_PAD, 1024 * 1024); |
1739 | mallopt (M_TOP_PAD, 1024 * 1024); |
1759 | mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); |
1740 | mallopt (M_MMAP_THRESHOLD, 1024 * 1024); |
1760 | mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory |
1741 | mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory |
|
|
1742 | if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10)) |
1761 | mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc |
1743 | mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc |
1762 | #endif |
1744 | #endif |
1763 | |
1745 | |
1764 | int munlockall () |
1746 | int munlockall () |
1765 | |
1747 | |
1766 | #endif |
1748 | #endif |
… | |
… | |
1799 | |
1781 | |
1800 | int random_roll (int min, int max, object *op, int goodbad); |
1782 | int random_roll (int min, int max, object *op, int goodbad); |
1801 | |
1783 | |
1802 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1784 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1803 | |
1785 | |
1804 | int |
|
|
1805 | exp_to_level (val64 exp) |
1786 | int exp_to_level (val64 exp) |
|
|
1787 | |
|
|
1788 | val64 level_to_min_exp (int level) |
|
|
1789 | |
|
|
1790 | SV * |
|
|
1791 | attacktype_name (int atnr) |
1806 | CODE: |
1792 | CODE: |
1807 | { |
1793 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
1808 | int i = 0; |
1794 | ? newSVpv (attacktype_name [atnr], 0) |
1809 | |
1795 | : &PL_sv_undef; |
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 |
1796 | OUTPUT: RETVAL |
1822 | |
1797 | |
1823 | val64 |
|
|
1824 | 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 | |
|
|
1834 | SV * |
1798 | SV * |
1835 | resistance_to_string (int atnr) |
1799 | attacktype_desc (int atnr) |
1836 | CODE: |
1800 | CODE: |
1837 | if (atnr >= 0 && atnr < NROFATTACKS) |
1801 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
|
|
1802 | ? newSVpv (attacktype_desc [atnr], 0) |
|
|
1803 | : &PL_sv_undef; |
|
|
1804 | OUTPUT: RETVAL |
|
|
1805 | |
|
|
1806 | SV * |
|
|
1807 | resist_plus (int atnr) |
|
|
1808 | CODE: |
|
|
1809 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
1838 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1810 | ? newSVpv (resist_plus [atnr], 0) |
1839 | else |
1811 | : &PL_sv_undef; |
1840 | XSRETURN_UNDEF; |
1812 | OUTPUT: RETVAL |
|
|
1813 | |
|
|
1814 | SV * |
|
|
1815 | change_resist_msg (int atnr) |
|
|
1816 | CODE: |
|
|
1817 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
|
|
1818 | ? newSVpv (change_resist_msg [atnr], 0) |
|
|
1819 | : &PL_sv_undef; |
1841 | OUTPUT: RETVAL |
1820 | OUTPUT: RETVAL |
1842 | |
1821 | |
1843 | UUID |
1822 | UUID |
1844 | uuid_cur () |
1823 | uuid_cur () |
1845 | CODE: |
1824 | CODE: |
… | |
… | |
1895 | CODE: |
1874 | CODE: |
1896 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1875 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1897 | OUTPUT: |
1876 | OUTPUT: |
1898 | RETVAL |
1877 | RETVAL |
1899 | |
1878 | |
|
|
1879 | bool should_invoke (attachable *obj, int event) |
|
|
1880 | CODE: |
|
|
1881 | RETVAL = obj->should_invoke ((event_type)event); |
|
|
1882 | OUTPUT: RETVAL |
|
|
1883 | |
1900 | void |
1884 | void |
1901 | debug_trace (attachable *obj, bool on = true) |
1885 | debug_trace (attachable *obj, bool on = true) |
1902 | CODE: |
1886 | CODE: |
1903 | obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; |
1887 | obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; |
1904 | if (on) |
1888 | if (on) |
… | |
… | |
1963 | int mortals_size () |
1947 | int mortals_size () |
1964 | CODE: |
1948 | CODE: |
1965 | RETVAL = attachable::mortals.size (); |
1949 | RETVAL = attachable::mortals.size (); |
1966 | OUTPUT: RETVAL |
1950 | OUTPUT: RETVAL |
1967 | |
1951 | |
1968 | const_utf8_string slot_use_name (U32 slot) |
1952 | const_utf8_string slot_name (U32 slot) |
1969 | ALIAS: |
1953 | ALIAS: |
|
|
1954 | slot_name = 0 |
|
|
1955 | slot_use_name = 1 |
1970 | slot_nonuse_name = 1 |
1956 | slot_nonuse_name = 2 |
1971 | CODE: |
1957 | CODE: |
1972 | { |
1958 | { |
1973 | if (slot >= NUM_BODY_LOCATIONS) |
1959 | if (slot >= NUM_BODY_LOCATIONS) |
1974 | croak ("body slot index out of range"); |
1960 | croak ("body slot index out of range"); |
1975 | |
1961 | |
1976 | switch (ix) |
1962 | switch (ix) |
1977 | { |
1963 | { |
|
|
1964 | case 0: RETVAL = body_locations[slot].name ; break; |
1978 | case 0: RETVAL = body_locations[slot].use_name; break; |
1965 | case 1: RETVAL = body_locations[slot].use_name ; break; |
1979 | case 1: RETVAL = body_locations[slot].nonuse_name; break; |
1966 | case 2: RETVAL = body_locations[slot].nonuse_name; break; |
1980 | } |
1967 | } |
1981 | } |
1968 | } |
1982 | OUTPUT: |
1969 | OUTPUT: |
1983 | RETVAL |
1970 | RETVAL |
1984 | |
1971 | |
… | |
… | |
2090 | |
2077 | |
2091 | void pick_up (object *who, object *op) |
2078 | void pick_up (object *who, object *op) |
2092 | |
2079 | |
2093 | void update_object (object *op, int action) |
2080 | void update_object (object *op, int action) |
2094 | |
2081 | |
2095 | void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) |
2082 | void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0) |
2096 | |
2083 | |
2097 | void player_lvl_adj (object *who, object *skill = 0) |
2084 | void player_lvl_adj (object *who, object *skill = 0) |
2098 | |
2085 | |
2099 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
2086 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
2100 | |
2087 | |
… | |
… | |
2145 | RETVAL = 0; |
2132 | RETVAL = 0; |
2146 | } |
2133 | } |
2147 | |
2134 | |
2148 | shstr |
2135 | shstr |
2149 | object::kv_get (shstr key) |
2136 | object::kv_get (shstr key) |
|
|
2137 | CODE: |
|
|
2138 | RETVAL = THIS->kv.get (key); |
|
|
2139 | OUTPUT: |
|
|
2140 | RETVAL |
2150 | |
2141 | |
2151 | void |
2142 | void |
2152 | object::kv_del (shstr key) |
2143 | object::kv_del (shstr key) |
|
|
2144 | CODE: |
|
|
2145 | THIS->kv.del (key); |
2153 | |
2146 | |
2154 | void |
2147 | void |
2155 | object::kv_set (shstr key, shstr value) |
2148 | object::kv_set (shstr key, shstr value) |
|
|
2149 | CODE: |
|
|
2150 | THIS->kv.set (key, value); |
2156 | |
2151 | |
2157 | object *get_nearest_player (object *ob) |
2152 | object *get_nearest_player (object *ob) |
2158 | ALIAS: nearest_player = 0 |
2153 | ALIAS: nearest_player = 0 |
2159 | PREINIT: |
2154 | PREINIT: |
2160 | extern object *get_nearest_player (object *); |
2155 | extern object *get_nearest_player (object *); |
… | |
… | |
2362 | for_all_players (pl) |
2357 | for_all_players (pl) |
2363 | if (pl->ob && pl->ob->map == THIS) |
2358 | if (pl->ob && pl->ob->map == THIS) |
2364 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2359 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2365 | } |
2360 | } |
2366 | |
2361 | |
|
|
2362 | #if 0 |
|
|
2363 | |
|
|
2364 | void |
|
|
2365 | maptile::add_quadland (int mx, int my, int mz, SV *biome_map, SV *biome_plt) |
|
|
2366 | CODE: |
|
|
2367 | { |
|
|
2368 | static frac_gen<vec2d> frac; |
|
|
2369 | |
|
|
2370 | if (!SvROK (biome_plt) || SvTYPE (SvRV (biome_plt)) != SVt_PVAV) |
|
|
2371 | croak ("maptile::add_quadland: biome_plt must be arrayref"); |
|
|
2372 | |
|
|
2373 | biome_plt = SvRV (biome_plt); |
|
|
2374 | |
|
|
2375 | const uint8_t *bmap = (const uint8_t *)SvPVbyte_nolen (biome_map); |
|
|
2376 | |
|
|
2377 | for (int x = 0; x < THIS->width; ++x) |
|
|
2378 | for (int y = 0; y < THIS->height; ++y) |
|
|
2379 | { |
|
|
2380 | for (object *op = THIS->at (x, y).bot; op; op = op->above) |
|
|
2381 | if (op->flag [FLAG_IS_FLOOR]) |
|
|
2382 | goto skip; |
|
|
2383 | |
|
|
2384 | { |
|
|
2385 | float fx = mx * THIS->width + x; |
|
|
2386 | float fy = my * THIS->height + y; |
|
|
2387 | |
|
|
2388 | int temp = clamp (int (32 * frac.fBm (vec2d (fx * 0.001, fy * 0.001), 2) ) - 8, 0, 15); |
|
|
2389 | int rain = clamp (int (16 * frac.ridgedmultifractal (vec2d (fx * 0.01, fy * 0.01), 3, 1.03, 2)) - 8, 0, 15); |
|
|
2390 | |
|
|
2391 | rain = lerp (rain, 0, 15, 0, temp); |
|
|
2392 | printf ("rain %d\n", temp);//D |
|
|
2393 | |
|
|
2394 | int biome = bmap [rain * 16 + temp]; |
|
|
2395 | |
|
|
2396 | //printf ("%2d %2d => %s\n", temp, rain, SvPV_nolen (AvARRAY ((AV *)biome_plt)[biome]));//D |
|
|
2397 | #if 1 |
|
|
2398 | if (SV **elem = av_fetch ((AV *)biome_plt, bmap [rain * 16 + temp], 0)) |
|
|
2399 | { |
|
|
2400 | object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); |
|
|
2401 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
|
|
2402 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
|
|
2403 | |
|
|
2404 | if (ob->randomitems && !ob->above) |
|
|
2405 | { |
|
|
2406 | ob->create_treasure (ob->randomitems); |
|
|
2407 | |
|
|
2408 | for (object *op = ob->above; op; op = op->above) |
|
|
2409 | op->flag [FLAG_NO_MAP_SAVE] = true; |
|
|
2410 | } |
|
|
2411 | } |
|
|
2412 | #endif |
|
|
2413 | } |
|
|
2414 | skip: ; |
|
|
2415 | } |
|
|
2416 | } |
|
|
2417 | |
|
|
2418 | #endif |
|
|
2419 | |
2367 | void |
2420 | void |
2368 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2421 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2369 | CODE: |
2422 | CODE: |
2370 | { |
2423 | { |
2371 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2424 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
… | |
… | |
2402 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2455 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2403 | // TODO: if this is a pickable object, then the item |
2456 | // TODO: if this is a pickable object, then the item |
2404 | // will at a bit weird - saving inside the player |
2457 | // will at a bit weird - saving inside the player |
2405 | // will clear the flag, but when the player drops |
2458 | // will clear the flag, but when the player drops |
2406 | // it without logging out, it keeps the flag. |
2459 | // it without logging out, it keeps the flag. |
2407 | // nobody ahs reported this, but this can be rather |
2460 | // nobody has reported this, but this can be rather |
2408 | // annoying on persistent maps. |
2461 | // annoying on persistent maps. |
2409 | } |
2462 | } |
2410 | } |
2463 | } |
2411 | } |
2464 | } |
2412 | } |
2465 | } |
2413 | |
|
|
2414 | skip: ; |
2466 | skip: ; |
2415 | } |
2467 | } |
2416 | } |
2468 | } |
2417 | |
2469 | |
2418 | void |
2470 | void |
… | |
… | |
2449 | for (int x = 0; x < THIS->width; ++x) |
2501 | for (int x = 0; x < THIS->width; ++x) |
2450 | for (int y = 0; y < THIS->height; ++y) |
2502 | for (int y = 0; y < THIS->height; ++y) |
2451 | { |
2503 | { |
2452 | region *rgn = THIS->region (x, y); |
2504 | region *rgn = THIS->region (x, y); |
2453 | |
2505 | |
2454 | //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D |
|
|
2455 | if (object *op = THIS->at (x, y).top) |
2506 | if (object *op = THIS->at (x, y).top) |
2456 | if (rgn->treasure && rndm () < rgn->treasure_density) |
2507 | if (rgn->treasure && rndm () < rgn->treasure_density) |
2457 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2508 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2458 | } |
2509 | } |
2459 | |
2510 | |
… | |
… | |
2465 | if (oblinkpt *obp = map->find_link (connection)) |
2516 | if (oblinkpt *obp = map->find_link (connection)) |
2466 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2517 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2467 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2518 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2468 | |
2519 | |
2469 | void |
2520 | void |
2470 | get_map_flags (maptile *map, int x, int y) |
2521 | xy_normalise (maptile *map, int x, int y, int dir = 0) |
2471 | PPCODE: |
2522 | PPCODE: |
2472 | { |
2523 | { |
2473 | maptile *nmap = 0; |
2524 | mapxy pos (map, x, y); |
2474 | I16 nx = 0, ny = 0; |
2525 | if (!pos.move (dir).normalise ()) |
|
|
2526 | XSRETURN_EMPTY; |
2475 | |
2527 | |
2476 | PUTBACK; |
|
|
2477 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2478 | SPAGAIN; |
|
|
2479 | |
|
|
2480 | EXTEND (SP, 4); |
2528 | EXTEND (SP, 3); |
2481 | PUSHs (sv_2mortal (newSViv (flags))); |
|
|
2482 | |
|
|
2483 | if (GIMME_V == G_ARRAY) |
|
|
2484 | { |
|
|
2485 | PUSHs (sv_2mortal (to_sv (nmap))); |
2529 | PUSHs (sv_2mortal (to_sv (pos.m))); |
2486 | PUSHs (sv_2mortal (newSViv (nx))); |
2530 | PUSHs (sv_2mortal (to_sv (pos.x))); |
2487 | PUSHs (sv_2mortal (newSViv (ny))); |
2531 | PUSHs (sv_2mortal (to_sv (pos.y))); |
2488 | } |
|
|
2489 | } |
2532 | } |
2490 | |
2533 | |
2491 | mapspace * |
2534 | mapspace * |
2492 | ms (maptile *map, unsigned int x, unsigned int y) |
2535 | ms (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2493 | PROTOTYPE: $$$ |
2536 | PROTOTYPE: $$$;$ |
2494 | CODE: |
2537 | CODE: |
2495 | { |
2538 | { |
2496 | maptile *nmap = 0; |
2539 | mapxy pos (map, x, y); |
2497 | I16 nx, ny; |
2540 | if (!pos.move (dir).normalise ()) |
2498 | |
|
|
2499 | PUTBACK; |
|
|
2500 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2501 | SPAGAIN; |
|
|
2502 | |
|
|
2503 | if (!nmap) |
|
|
2504 | XSRETURN_UNDEF; |
2541 | XSRETURN_UNDEF; |
2505 | |
2542 | |
2506 | RETVAL = &nmap->at (nx, ny); |
2543 | RETVAL = &*pos; |
2507 | } |
2544 | } |
2508 | OUTPUT: |
2545 | OUTPUT: |
2509 | RETVAL |
2546 | RETVAL |
2510 | |
2547 | |
2511 | void |
2548 | void |
2512 | at (maptile *map, unsigned int x, unsigned int y) |
2549 | at (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2513 | PROTOTYPE: $$$ |
2550 | PROTOTYPE: $$$;$ |
2514 | PPCODE: |
2551 | PPCODE: |
2515 | { |
2552 | mapxy pos (map, x, y); |
2516 | maptile *nmap = 0; |
2553 | if (pos.move (dir).normalise ()) |
2517 | I16 nx, ny; |
|
|
2518 | |
|
|
2519 | PUTBACK; |
|
|
2520 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2521 | SPAGAIN; |
|
|
2522 | |
|
|
2523 | if (nmap) |
|
|
2524 | for (object *o = nmap->at (nx, ny).bot; o; o = o->above) |
2554 | for (object *o = pos->bot; o; o = o->above) |
2525 | XPUSHs (sv_2mortal (to_sv (o))); |
2555 | XPUSHs (sv_2mortal (to_sv (o))); |
2526 | } |
|
|
2527 | |
2556 | |
2528 | SV * |
2557 | SV * |
2529 | bot_at (maptile *map, unsigned int x, unsigned int y) |
2558 | bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2530 | PROTOTYPE: $$$ |
2559 | PROTOTYPE: $$$;$ |
2531 | ALIAS: |
2560 | ALIAS: |
2532 | top_at = 1 |
2561 | top_at = 1 |
2533 | flags_at = 2 |
2562 | flags_at = 2 |
2534 | light_at = 3 |
2563 | light_at = 3 |
2535 | move_block_at = 4 |
2564 | move_block_at = 4 |
2536 | move_slow_at = 5 |
2565 | move_slow_at = 5 |
2537 | move_on_at = 6 |
2566 | move_on_at = 6 |
2538 | move_off_at = 7 |
2567 | move_off_at = 7 |
2539 | CODE: |
2568 | CODE: |
2540 | { |
2569 | { |
2541 | sint16 nx = x; |
2570 | mapxy pos (map, x, y); |
2542 | sint16 ny = y; |
2571 | if (!pos.move (dir).normalise ()) |
2543 | |
|
|
2544 | if (!xy_normalise (map, nx, ny)) |
|
|
2545 | XSRETURN_UNDEF; |
2572 | XSRETURN_UNDEF; |
2546 | |
2573 | |
2547 | mapspace &ms = map->at (nx, ny); |
2574 | mapspace &ms = *pos; |
2548 | |
2575 | |
2549 | ms.update (); |
2576 | ms.update (); |
2550 | |
2577 | |
2551 | switch (ix) |
2578 | switch (ix) |
2552 | { |
2579 | { |
… | |
… | |
2562 | } |
2589 | } |
2563 | OUTPUT: RETVAL |
2590 | OUTPUT: RETVAL |
2564 | |
2591 | |
2565 | # worst xs function of my life |
2592 | # worst xs function of my life |
2566 | bool |
2593 | bool |
2567 | _create_random_map (\ |
2594 | _create_random_map (maptile *self, SV *options) |
2568 | maptile *self,\ |
|
|
2569 | utf8_string wallstyle,\ |
|
|
2570 | utf8_string wall_name,\ |
|
|
2571 | utf8_string floorstyle,\ |
|
|
2572 | utf8_string monsterstyle,\ |
|
|
2573 | utf8_string treasurestyle,\ |
|
|
2574 | utf8_string layoutstyle,\ |
|
|
2575 | utf8_string doorstyle,\ |
|
|
2576 | utf8_string decorstyle,\ |
|
|
2577 | utf8_string miningstyle,\ |
|
|
2578 | utf8_string origin_map,\ |
|
|
2579 | utf8_string final_map,\ |
|
|
2580 | utf8_string exitstyle,\ |
|
|
2581 | utf8_string this_map,\ |
|
|
2582 | utf8_string exit_on_final_map,\ |
|
|
2583 | int xsize,\ |
|
|
2584 | int ysize,\ |
|
|
2585 | int expand2x,\ |
|
|
2586 | int layoutoptions1,\ |
|
|
2587 | int layoutoptions2,\ |
|
|
2588 | int layoutoptions3,\ |
|
|
2589 | int symmetry,\ |
|
|
2590 | int difficulty,\ |
|
|
2591 | int difficulty_given,\ |
|
|
2592 | float difficulty_increase,\ |
|
|
2593 | int dungeon_level,\ |
|
|
2594 | int dungeon_depth,\ |
|
|
2595 | int decoroptions,\ |
|
|
2596 | int orientation,\ |
|
|
2597 | int origin_y,\ |
|
|
2598 | int origin_x,\ |
|
|
2599 | U32 random_seed,\ |
|
|
2600 | val64 total_map_hp,\ |
|
|
2601 | int map_layout_style,\ |
|
|
2602 | int treasureoptions,\ |
|
|
2603 | int symmetry_used,\ |
|
|
2604 | region *region,\ |
|
|
2605 | utf8_string custom\ |
|
|
2606 | ) |
|
|
2607 | CODE: |
2595 | CODE: |
2608 | { |
2596 | { |
2609 | random_map_params rmp; |
2597 | random_map_params rmp ((HV *)SvRV (options)); |
2610 | |
|
|
2611 | assign (rmp.wallstyle , wallstyle); |
|
|
2612 | assign (rmp.wall_name , wall_name); |
|
|
2613 | assign (rmp.floorstyle , floorstyle); |
|
|
2614 | assign (rmp.monsterstyle , monsterstyle); |
|
|
2615 | assign (rmp.treasurestyle , treasurestyle); |
|
|
2616 | assign (rmp.layoutstyle , layoutstyle); |
|
|
2617 | assign (rmp.doorstyle , doorstyle); |
|
|
2618 | assign (rmp.decorstyle , decorstyle); |
|
|
2619 | assign (rmp.miningstyle , miningstyle); |
|
|
2620 | assign (rmp.exitstyle , exitstyle); |
|
|
2621 | assign (rmp.exit_on_final_map, exit_on_final_map); |
|
|
2622 | |
|
|
2623 | rmp.origin_map = origin_map; |
|
|
2624 | rmp.final_map = final_map; |
|
|
2625 | rmp.this_map = this_map; |
|
|
2626 | rmp.xsize = xsize; |
|
|
2627 | rmp.ysize = ysize; |
|
|
2628 | rmp.expand2x = expand2x; |
|
|
2629 | rmp.layoutoptions1 = layoutoptions1; |
|
|
2630 | rmp.layoutoptions2 = layoutoptions2; |
|
|
2631 | rmp.layoutoptions3 = layoutoptions3; |
|
|
2632 | rmp.symmetry = symmetry; |
|
|
2633 | rmp.difficulty = difficulty; |
|
|
2634 | rmp.difficulty_given = difficulty_given; |
|
|
2635 | rmp.difficulty_increase = difficulty_increase; |
|
|
2636 | rmp.dungeon_level = dungeon_level; |
|
|
2637 | rmp.dungeon_depth = dungeon_depth; |
|
|
2638 | rmp.decoroptions = decoroptions; |
|
|
2639 | rmp.orientation = orientation; |
|
|
2640 | rmp.origin_y = origin_y; |
|
|
2641 | rmp.origin_x = origin_x; |
|
|
2642 | rmp.random_seed = random_seed; |
|
|
2643 | rmp.total_map_hp = (uint64_t) total_map_hp; |
|
|
2644 | rmp.map_layout_style = map_layout_style; |
|
|
2645 | rmp.treasureoptions = treasureoptions; |
|
|
2646 | rmp.symmetry_used = symmetry_used; |
|
|
2647 | rmp.region = region; |
|
|
2648 | rmp.custom = custom; |
|
|
2649 | |
|
|
2650 | RETVAL = self->generate_random_map (&rmp); |
2598 | RETVAL = self->generate_random_map (&rmp); |
2651 | } |
2599 | } |
2652 | OUTPUT: |
2600 | OUTPUT: |
2653 | RETVAL |
2601 | RETVAL |
2654 | |
2602 | |
… | |
… | |
2685 | void |
2633 | void |
2686 | list () |
2634 | list () |
2687 | PPCODE: |
2635 | PPCODE: |
2688 | for_all_regions (rgn) |
2636 | for_all_regions (rgn) |
2689 | XPUSHs (sv_2mortal (to_sv (rgn))); |
2637 | XPUSHs (sv_2mortal (to_sv (rgn))); |
2690 | |
|
|
2691 | region *find (utf8_string name) |
|
|
2692 | PROTOTYPE: $ |
|
|
2693 | CODE: |
|
|
2694 | RETVAL = region::find (name); |
|
|
2695 | OUTPUT: RETVAL |
|
|
2696 | |
2638 | |
2697 | int specificity (region *rgn) |
2639 | int specificity (region *rgn) |
2698 | CODE: |
2640 | CODE: |
2699 | RETVAL = 0; |
2641 | RETVAL = 0; |
2700 | while (rgn = rgn->parent) |
2642 | while (rgn = rgn->parent) |
… | |
… | |
2832 | |
2774 | |
2833 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2775 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2834 | CODE: |
2776 | CODE: |
2835 | { |
2777 | { |
2836 | faceinfo *f = face_info (idx); assert (f); |
2778 | faceinfo *f = face_info (idx); assert (f); |
2837 | facedata *d = &(faceset ? f->data64 : f->data32); |
2779 | facedata *d = f->face + faceset; |
2838 | sv_to (data, d->data); |
2780 | sv_to (data, d->data); |
2839 | STRLEN clen; |
2781 | STRLEN clen; |
2840 | char *cdata = SvPVbyte (chksum, clen); |
2782 | char *cdata = SvPVbyte (chksum, clen); |
2841 | clen = min (CHKSUM_MAXLEN, clen); |
2783 | clen = min (CHKSUM_MAXLEN, clen); |
2842 | |
2784 | |
… | |
… | |
2950 | sv_to (sv, self); |
2892 | sv_to (sv, self); |
2951 | delete self; |
2893 | delete self; |
2952 | |
2894 | |
2953 | MODULE = cf PACKAGE = cf::object::thawer |
2895 | MODULE = cf PACKAGE = cf::object::thawer |
2954 | |
2896 | |
2955 | INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | |
2897 | INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h | |
|
|
2898 | |
|
|
2899 | bool |
|
|
2900 | errors_are_fatal (bool fatal) |
|
|
2901 | CODE: |
|
|
2902 | RETVAL = object_thawer::errors_are_fatal; |
|
|
2903 | object_thawer::errors_are_fatal = fatal; |
|
|
2904 | OUTPUT: |
|
|
2905 | RETVAL |
2956 | |
2906 | |
2957 | SV * |
2907 | SV * |
2958 | new_from_file (char *klass, octet_string path) |
2908 | new_from_file (char *klass, octet_string path) |
2959 | CODE: |
2909 | CODE: |
2960 | object_thawer *f = new object_thawer (path); |
2910 | object_thawer *f = new object_thawer (path); |
… | |
… | |
2986 | XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); |
2936 | XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); |
2987 | |
2937 | |
2988 | self->skip (); |
2938 | self->skip (); |
2989 | } |
2939 | } |
2990 | |
2940 | |
|
|
2941 | MODULE = cf PACKAGE = cf::layout |
|
|
2942 | |
|
|
2943 | INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h | |
|
|
2944 | |