… | |
… | |
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 |
… | |
… | |
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 | |
57 | extern sint64 *levels; // the experience table |
|
|
58 | |
|
|
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; |
63 | |
62 | |
… | |
… | |
68 | static int tick_inhibit; |
67 | static int tick_inhibit; |
69 | static int tick_pending; |
68 | static int tick_pending; |
70 | |
69 | |
71 | global gbl_ev; |
70 | global gbl_ev; |
72 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
71 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
73 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; |
72 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now, *sv_server_tick; |
74 | static AV *av_reflect; |
73 | static AV *av_reflect; |
75 | |
74 | |
76 | bitset<NUM_EVENT_TYPES> ev_want_event; |
75 | bitset<NUM_EVENT_TYPES> ev_want_event; |
77 | bitset<NUM_TYPES> ev_want_type; |
76 | bitset<NUM_TYPES> ev_want_type; |
78 | |
77 | |
… | |
… | |
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)) |
… | |
… | |
252 | { |
253 | { |
253 | static int last_mortalcount; |
254 | static int last_mortalcount; |
254 | if (mortals.size () != last_mortalcount) |
255 | if (mortals.size () != last_mortalcount) |
255 | { |
256 | { |
256 | last_mortalcount = mortals.size (); |
257 | last_mortalcount = mortals.size (); |
257 | LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); |
258 | object *specimen = is_a<object> (mortals [rndm (mortals.size ())]); |
|
|
259 | |
|
|
260 | LOG (llevInfo, "%d mortals (random specimen: %s).\n", |
|
|
261 | (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)"); |
258 | |
262 | |
259 | if (0) |
263 | if (0) |
260 | { |
264 | { |
261 | for (int j = 0; j < mortals.size (); ++j)//D |
265 | for (int j = 0; j < mortals.size (); ++j)//D |
262 | fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
266 | fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
… | |
… | |
353 | #endif |
357 | #endif |
354 | |
358 | |
355 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
359 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
356 | |
360 | |
357 | static SV * |
361 | static SV * |
358 | newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) |
362 | newSVptr (void *ptr, HV *stash, HV *hv) |
359 | { |
363 | { |
360 | SV *sv; |
|
|
361 | |
|
|
362 | if (!ptr) |
364 | if (!ptr) |
363 | return newSV (0); |
365 | return newSV (0); |
364 | |
366 | |
365 | sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); |
367 | sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); |
366 | return sv_bless (newRV_noinc ((SV *)hv), stash); |
368 | return sv_bless (newRV_noinc ((SV *)hv), stash); |
|
|
369 | } |
|
|
370 | |
|
|
371 | static SV * noinline |
|
|
372 | newSVptr (void *ptr, HV *stash) |
|
|
373 | { |
|
|
374 | return newSVptr (ptr, stash, newHV ()); |
367 | } |
375 | } |
368 | |
376 | |
369 | static int |
377 | static int |
370 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
378 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
371 | { |
379 | { |
… | |
… | |
383 | return 0; |
391 | return 0; |
384 | } |
392 | } |
385 | |
393 | |
386 | MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; |
394 | MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; |
387 | |
395 | |
388 | static SV * |
396 | static SV * noinline |
389 | newSVattachable (attachable *obj, HV *stash) |
397 | newSVattachable (attachable *obj, HV *stash) |
390 | { |
398 | { |
391 | if (!obj) |
399 | if (!obj) |
392 | return newSV (0); |
400 | return newSV (0); |
393 | |
401 | |
… | |
… | |
479 | || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap |
487 | || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap |
480 | && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap |
488 | && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap |
481 | && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap |
489 | && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap |
482 | && !sv_derived_from (sv, "cf::object"))) |
490 | && !sv_derived_from (sv, "cf::object"))) |
483 | croak ("object of type cf::object expected"); |
491 | croak ("object of type cf::object expected"); |
|
|
492 | |
|
|
493 | return SvPTR_nc (sv); |
|
|
494 | } |
|
|
495 | |
|
|
496 | static long noinline |
|
|
497 | SvPTR_ornull_maptile (SV *sv) |
|
|
498 | { |
|
|
499 | if (expect_false (!SvOK (sv))) return 0; |
|
|
500 | |
|
|
501 | if (!SvROK (sv) |
|
|
502 | || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap |
|
|
503 | && SvSTASH (SvRV (sv)) != stash_ext_map_world |
|
|
504 | && !sv_derived_from (sv, "cf::map"))) |
|
|
505 | croak ("object of type cf::map expected"); |
484 | |
506 | |
485 | return SvPTR_nc (sv); |
507 | return SvPTR_nc (sv); |
486 | } |
508 | } |
487 | |
509 | |
488 | static long noinline |
510 | static long noinline |
… | |
… | |
513 | static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
535 | static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
514 | static inline SV *to_sv (float v) { return newSVnv (v); } |
536 | static inline SV *to_sv (float v) { return newSVnv (v); } |
515 | static inline SV *to_sv (double v) { return newSVnv (v); } |
537 | 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); } |
538 | 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); } |
539 | static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
|
|
540 | // 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); } |
541 | static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
|
|
542 | 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); } |
543 | 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); } |
544 | 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); } |
545 | 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); } |
546 | 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); } |
547 | 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); } |
548 | static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
|
|
549 | static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); } |
525 | |
550 | |
526 | static inline SV *to_sv (object & v) { return to_sv (&v); } |
551 | static inline SV *to_sv (object & v) { return to_sv (&v); } |
527 | static inline SV *to_sv (living & v) { return to_sv (&v); } |
552 | static inline SV *to_sv (living & v) { return to_sv (&v); } |
528 | |
553 | |
529 | static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
554 | 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); } |
590 | 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); } |
591 | 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); } |
592 | 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); } |
593 | 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); } |
594 | 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); } |
595 | 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); } |
596 | 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); } |
597 | static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } |
|
|
598 | 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"); } |
599 | 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"); } |
600 | 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"); } |
601 | 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"); } |
602 | 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"); } |
603 | 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"); } |
604 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } |
|
|
605 | 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"); } |
606 | 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" ); } |
607 | static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } |
582 | |
608 | |
583 | //static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
609 | //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)); } |
610 | static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
… | |
… | |
695 | template<class type> |
721 | template<class type> |
696 | static void noinline |
722 | static void noinline |
697 | cf_obj_to (SV *arg, type &var) |
723 | cf_obj_to (SV *arg, type &var) |
698 | { |
724 | { |
699 | sv_to (arg, var); |
725 | sv_to (arg, var); |
700 | if (!var) |
726 | if (expect_false (!var)) |
701 | croak ("must not pass invalid/null cf_obj here"); |
727 | croak ("must not pass invalid/null cf_obj here"); |
702 | } |
728 | } |
703 | |
729 | |
704 | template<class object> |
730 | template<class object> |
705 | static void noinline |
731 | static void noinline |
706 | cf_obj_ornull_to (SV *arg, object *&var) |
732 | cf_obj_ornull_to (SV *arg, object *&var) |
707 | { |
733 | { |
708 | if (SvOK (arg)) |
734 | if (SvOK (arg)) |
709 | { |
735 | { |
710 | sv_to (arg, var); |
736 | sv_to (arg, var); |
711 | if (!var) |
737 | if (expect_false (!var)) |
712 | croak ("unable to convert perl object to C++ object"); |
738 | croak ("unable to convert perl object to C++ object"); |
713 | } |
739 | } |
714 | else |
740 | else |
715 | var = 0; |
741 | var = 0; |
716 | } |
742 | } |
… | |
… | |
751 | exit (EXIT_FAILURE); |
777 | exit (EXIT_FAILURE); |
752 | } |
778 | } |
753 | |
779 | |
754 | eval_pv ( |
780 | eval_pv ( |
755 | "#line 1 'cfperl init'\n" |
781 | "#line 1 'cfperl init'\n" |
756 | "use EV ();\n" |
782 | "use EV ();\n" // required by bootstrap |
757 | "use Coro ();\n" |
783 | "use Coro ();\n" // required by bootstrap |
758 | "cf->bootstrap;\n" |
784 | "cf->bootstrap;\n" // required for cf::datadir |
759 | "unshift @INC, cf::datadir ();\n" |
785 | "unshift @INC, cf::datadir ();\n" // required for 'require' :) |
760 | "require cf;\n", |
786 | "require cf;\n", |
761 | 0 |
787 | 0 |
762 | ); |
788 | ); |
763 | |
789 | |
764 | if (SvTRUE (ERRSV)) |
790 | if (SvTRUE (ERRSV)) |
… | |
… | |
1378 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1404 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1379 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1405 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1380 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1406 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1381 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1407 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1382 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1408 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
|
|
1409 | stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); |
|
|
1410 | stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1383 | |
1411 | |
1384 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1412 | 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); |
1413 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
|
|
1414 | sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV); |
1386 | sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); |
1415 | 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); |
1416 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1388 | |
1417 | |
1389 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1418 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1390 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1419 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1391 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1420 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1392 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1421 | cb_player = get_av ("cf::CB_PLAYER", 1); |
… | |
… | |
1435 | # include "attackinc.h" |
1464 | # include "attackinc.h" |
1436 | # undef def |
1465 | # undef def |
1437 | # define def(uc, flags) const_iv (SK_ ## uc) |
1466 | # define def(uc, flags) const_iv (SK_ ## uc) |
1438 | # include "skillinc.h" |
1467 | # include "skillinc.h" |
1439 | # undef def |
1468 | # undef def |
1440 | |
1469 | # define def(name, use, nonuse) const_iv (body_ ## name) |
1441 | const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) |
1470 | # include "slotinc.h" |
1442 | const_iv (logBacktrace) |
1471 | # undef def |
1443 | |
|
|
1444 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
|
|
1445 | |
1472 | |
1446 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1473 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1447 | |
1474 | |
1448 | const_iv (MAX_TIME) |
1475 | const_iv (MAX_TIME) |
1449 | const_iv (MAXSOCKBUF) |
1476 | const_iv (MAXSOCKBUF) |
… | |
… | |
1463 | const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
1490 | const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
1464 | |
1491 | |
1465 | const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) |
1492 | const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) |
1466 | const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) |
1493 | const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) |
1467 | |
1494 | |
1468 | const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING) |
|
|
1469 | const_iv (MAP_INACTIVE) |
|
|
1470 | |
|
|
1471 | const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1495 | const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1472 | const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1496 | const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1473 | |
1497 | |
1474 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1498 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1475 | |
1499 | |
1476 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1500 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1477 | }; |
1501 | }; |
1478 | |
1502 | |
1479 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1503 | for (civ = const_iv + array_length (const_iv); civ-- > const_iv; ) |
1480 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1504 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1481 | |
1505 | |
1482 | static const struct { |
1506 | static const struct { |
1483 | const char *name; |
1507 | const char *name; |
1484 | int skip; |
1508 | int skip; |
… | |
… | |
1490 | # undef def |
1514 | # undef def |
1491 | }; |
1515 | }; |
1492 | |
1516 | |
1493 | AV *av = get_av ("cf::EVENT", 1); |
1517 | AV *av = get_av ("cf::EVENT", 1); |
1494 | |
1518 | |
1495 | for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) |
1519 | for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; ) |
1496 | { |
1520 | { |
1497 | AV *event = newAV (); |
1521 | AV *event = newAV (); |
1498 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1522 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1499 | av_push (event, newSViv (eiv->klass)); |
1523 | av_push (event, newSViv (eiv->klass)); |
1500 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1524 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
… | |
… | |
1535 | |
1559 | |
1536 | for_all_objects (op) |
1560 | for_all_objects (op) |
1537 | op->reattach (); |
1561 | op->reattach (); |
1538 | } |
1562 | } |
1539 | |
1563 | |
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 () |
1564 | void init_anim () |
1583 | |
1565 | |
1584 | void init_globals () |
1566 | void init_globals () |
1585 | |
1567 | |
1586 | void init_experience () |
|
|
1587 | |
|
|
1588 | void init_attackmess () |
1568 | void init_attackmess () |
1589 | |
1569 | |
1590 | void init_dynamic () |
1570 | void init_dynamic () |
1591 | |
1571 | |
1592 | void load_settings () |
1572 | void load_settings () |
1593 | |
1573 | |
|
|
1574 | void reload_exp_table () |
|
|
1575 | |
1594 | void load_materials () |
1576 | void reload_materials () |
1595 | |
1577 | |
1596 | void init_uuid () |
1578 | void init_uuid () |
1597 | CODE: |
1579 | CODE: |
1598 | UUID::init (); |
1580 | UUID::init (); |
1599 | |
1581 | |
… | |
… | |
1632 | { |
1614 | { |
1633 | ev_async_send (EV_DEFAULT, &tick_watcher); |
1615 | ev_async_send (EV_DEFAULT, &tick_watcher); |
1634 | coroapi::cede (); |
1616 | coroapi::cede (); |
1635 | } |
1617 | } |
1636 | |
1618 | |
1637 | void server_tick () |
1619 | void one_tick () |
1638 | CODE: |
1620 | CODE: |
1639 | { |
1621 | { |
1640 | ev_now_update (EV_DEFAULT); |
1622 | ev_now_update (EV_DEFAULT); |
1641 | NOW = ev_now (EV_DEFAULT); |
1623 | NOW = ev_now (EV_DEFAULT); |
1642 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1624 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1643 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1625 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1644 | runtime = SvNVX (sv_runtime); |
1626 | runtime = SvNVX (sv_runtime); |
1645 | |
1627 | |
|
|
1628 | one_tick (); |
|
|
1629 | |
1646 | server_tick (); |
1630 | ++server_tick; |
|
|
1631 | SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick); |
1647 | |
1632 | |
1648 | ev_now_update (EV_DEFAULT); |
1633 | ev_now_update (EV_DEFAULT); |
1649 | NOW = ev_now (EV_DEFAULT); |
1634 | NOW = ev_now (EV_DEFAULT); |
1650 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1635 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
|
|
1636 | |
1651 | runtime += TICK; |
1637 | runtime += TICK; |
1652 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1638 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1653 | } |
1639 | } |
1654 | |
1640 | |
1655 | NV floor (NV x) |
1641 | NV floor (NV x) |
… | |
… | |
1754 | |
1740 | |
1755 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1741 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1756 | INIT: |
1742 | INIT: |
1757 | #if __GLIBC__ |
1743 | #if __GLIBC__ |
1758 | mallopt (M_TOP_PAD, 1024 * 1024); |
1744 | mallopt (M_TOP_PAD, 1024 * 1024); |
1759 | mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); |
1745 | mallopt (M_MMAP_THRESHOLD, 1024 * 1024); |
1760 | mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory |
1746 | mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory |
|
|
1747 | if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10)) |
1761 | mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc |
1748 | mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc |
1762 | #endif |
1749 | #endif |
1763 | |
1750 | |
1764 | int munlockall () |
1751 | int munlockall () |
1765 | |
1752 | |
1766 | #endif |
1753 | #endif |
… | |
… | |
1799 | |
1786 | |
1800 | int random_roll (int min, int max, object *op, int goodbad); |
1787 | int random_roll (int min, int max, object *op, int goodbad); |
1801 | |
1788 | |
1802 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1789 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1803 | |
1790 | |
1804 | int |
|
|
1805 | exp_to_level (val64 exp) |
1791 | int exp_to_level (val64 exp) |
|
|
1792 | |
|
|
1793 | val64 level_to_min_exp (int level) |
|
|
1794 | |
|
|
1795 | SV * |
|
|
1796 | attacktype_name (int atnr) |
1806 | CODE: |
1797 | CODE: |
1807 | { |
1798 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
1808 | int i = 0; |
1799 | ? newSVpv (attacktype_name [atnr], 0) |
1809 | |
1800 | : &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 |
1801 | OUTPUT: RETVAL |
1822 | |
1802 | |
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 * |
1803 | SV * |
1835 | resistance_to_string (int atnr) |
1804 | attacktype_desc (int atnr) |
1836 | CODE: |
1805 | CODE: |
1837 | if (atnr >= 0 && atnr < NROFATTACKS) |
1806 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
|
|
1807 | ? newSVpv (attacktype_desc [atnr], 0) |
|
|
1808 | : &PL_sv_undef; |
|
|
1809 | OUTPUT: RETVAL |
|
|
1810 | |
|
|
1811 | SV * |
|
|
1812 | resist_plus (int atnr) |
|
|
1813 | CODE: |
|
|
1814 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
1838 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1815 | ? newSVpv (resist_plus [atnr], 0) |
1839 | else |
1816 | : &PL_sv_undef; |
1840 | XSRETURN_UNDEF; |
1817 | OUTPUT: RETVAL |
|
|
1818 | |
|
|
1819 | SV * |
|
|
1820 | change_resist_msg (int atnr) |
|
|
1821 | CODE: |
|
|
1822 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
|
|
1823 | ? newSVpv (change_resist_msg [atnr], 0) |
|
|
1824 | : &PL_sv_undef; |
1841 | OUTPUT: RETVAL |
1825 | OUTPUT: RETVAL |
1842 | |
1826 | |
1843 | UUID |
1827 | UUID |
1844 | uuid_cur () |
1828 | uuid_cur () |
1845 | CODE: |
1829 | CODE: |
… | |
… | |
1895 | CODE: |
1879 | CODE: |
1896 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1880 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1897 | OUTPUT: |
1881 | OUTPUT: |
1898 | RETVAL |
1882 | RETVAL |
1899 | |
1883 | |
|
|
1884 | bool should_invoke (attachable *obj, int event) |
|
|
1885 | CODE: |
|
|
1886 | RETVAL = obj->should_invoke ((event_type)event); |
|
|
1887 | OUTPUT: RETVAL |
|
|
1888 | |
1900 | void |
1889 | void |
1901 | debug_trace (attachable *obj, bool on = true) |
1890 | debug_trace (attachable *obj, bool on = true) |
1902 | CODE: |
1891 | CODE: |
1903 | obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; |
1892 | obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; |
1904 | if (on) |
1893 | if (on) |
… | |
… | |
1963 | int mortals_size () |
1952 | int mortals_size () |
1964 | CODE: |
1953 | CODE: |
1965 | RETVAL = attachable::mortals.size (); |
1954 | RETVAL = attachable::mortals.size (); |
1966 | OUTPUT: RETVAL |
1955 | OUTPUT: RETVAL |
1967 | |
1956 | |
1968 | const_utf8_string slot_use_name (U32 slot) |
1957 | const_utf8_string slot_name (U32 slot) |
1969 | ALIAS: |
1958 | ALIAS: |
|
|
1959 | slot_name = 0 |
|
|
1960 | slot_use_name = 1 |
1970 | slot_nonuse_name = 1 |
1961 | slot_nonuse_name = 2 |
1971 | CODE: |
1962 | CODE: |
1972 | { |
1963 | { |
1973 | if (slot >= NUM_BODY_LOCATIONS) |
1964 | if (slot >= NUM_BODY_LOCATIONS) |
1974 | croak ("body slot index out of range"); |
1965 | croak ("body slot index out of range"); |
1975 | |
1966 | |
1976 | switch (ix) |
1967 | switch (ix) |
1977 | { |
1968 | { |
|
|
1969 | case 0: RETVAL = body_locations[slot].name ; break; |
1978 | case 0: RETVAL = body_locations[slot].use_name; break; |
1970 | case 1: RETVAL = body_locations[slot].use_name ; break; |
1979 | case 1: RETVAL = body_locations[slot].nonuse_name; break; |
1971 | case 2: RETVAL = body_locations[slot].nonuse_name; break; |
1980 | } |
1972 | } |
1981 | } |
1973 | } |
1982 | OUTPUT: |
1974 | OUTPUT: |
1983 | RETVAL |
1975 | RETVAL |
1984 | |
1976 | |
… | |
… | |
2029 | OUTPUT: |
2021 | OUTPUT: |
2030 | RETVAL |
2022 | RETVAL |
2031 | |
2023 | |
2032 | object *find_best_object_match (object *op, utf8_string match) |
2024 | object *find_best_object_match (object *op, utf8_string match) |
2033 | |
2025 | |
2034 | object *find_marked_object (object *op) |
|
|
2035 | |
|
|
2036 | int need_identify (object *obj); |
|
|
2037 | |
|
|
2038 | int apply_shop_mat (object *shop_mat, object *op); |
2026 | int apply_shop_mat (object *shop_mat, object *op); |
2039 | |
2027 | |
2040 | int move (object *op, int dir, object *originator = op) |
2028 | int move (object *op, int dir, object *originator = op) |
2041 | CODE: |
2029 | CODE: |
2042 | RETVAL = op->move (dir, originator); |
2030 | RETVAL = op->move (dir, originator); |
… | |
… | |
2094 | |
2082 | |
2095 | void pick_up (object *who, object *op) |
2083 | void pick_up (object *who, object *op) |
2096 | |
2084 | |
2097 | void update_object (object *op, int action) |
2085 | void update_object (object *op, int action) |
2098 | |
2086 | |
2099 | void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) |
2087 | void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0) |
2100 | |
2088 | |
2101 | void player_lvl_adj (object *who, object *skill = 0) |
2089 | void player_lvl_adj (object *who, object *skill = 0) |
2102 | |
2090 | |
2103 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
2091 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
2104 | |
2092 | |
… | |
… | |
2120 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
2108 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
2121 | |
2109 | |
2122 | object *new (utf8_string archetype = 0) |
2110 | object *new (utf8_string archetype = 0) |
2123 | PROTOTYPE: ;$ |
2111 | PROTOTYPE: ;$ |
2124 | CODE: |
2112 | CODE: |
2125 | RETVAL = archetype ? get_archetype (archetype) : object::create (); |
2113 | RETVAL = archetype |
|
|
2114 | ? archetype::get (archetype) |
|
|
2115 | : object::create (); |
2126 | OUTPUT: |
2116 | OUTPUT: |
2127 | RETVAL |
2117 | RETVAL |
2128 | |
2118 | |
2129 | object *generate (utf8_string arch, object *creator) |
2119 | object *generate (utf8_string arch, object *creator) |
2130 | CODE: |
2120 | CODE: |
2131 | object *obj = get_archetype (arch); |
2121 | object *obj = archetype::get (arch); |
2132 | fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); |
2122 | fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); |
2133 | RETVAL = obj; |
2123 | RETVAL = obj; |
2134 | OUTPUT: |
2124 | OUTPUT: |
2135 | RETVAL |
2125 | RETVAL |
2136 | |
2126 | |
… | |
… | |
2146 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2136 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2147 | |
2137 | |
2148 | if (RETVAL->destroyed ()) |
2138 | if (RETVAL->destroyed ()) |
2149 | RETVAL = 0; |
2139 | RETVAL = 0; |
2150 | } |
2140 | } |
|
|
2141 | OUTPUT: |
|
|
2142 | RETVAL |
2151 | |
2143 | |
2152 | shstr |
2144 | shstr |
2153 | object::kv_get (shstr key) |
2145 | object::kv_get (shstr key) |
|
|
2146 | CODE: |
|
|
2147 | RETVAL = THIS->kv.get (key); |
|
|
2148 | OUTPUT: |
|
|
2149 | RETVAL |
2154 | |
2150 | |
2155 | void |
2151 | void |
2156 | object::kv_del (shstr key) |
2152 | object::kv_del (shstr key) |
|
|
2153 | CODE: |
|
|
2154 | THIS->kv.del (key); |
2157 | |
2155 | |
2158 | void |
2156 | void |
2159 | object::kv_set (shstr key, shstr value) |
2157 | object::kv_set (shstr key, shstr value) |
|
|
2158 | CODE: |
|
|
2159 | THIS->kv.set (key, value); |
2160 | |
2160 | |
2161 | object *get_nearest_player (object *ob) |
2161 | object *get_nearest_player (object *ob) |
2162 | ALIAS: nearest_player = 0 |
2162 | ALIAS: nearest_player = 0 |
2163 | PREINIT: |
2163 | PREINIT: |
2164 | extern object *get_nearest_player (object *); |
2164 | extern object *get_nearest_player (object *); |
… | |
… | |
2367 | if (pl->ob && pl->ob->map == THIS) |
2367 | if (pl->ob && pl->ob->map == THIS) |
2368 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2368 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2369 | } |
2369 | } |
2370 | |
2370 | |
2371 | void |
2371 | void |
|
|
2372 | maptile::gen_quadmap (int x, int y, int z) |
|
|
2373 | CODE: |
|
|
2374 | gen_quadmap (THIS, x * 50, y * 50, z); |
|
|
2375 | |
|
|
2376 | void |
2372 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2377 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2373 | CODE: |
2378 | CODE: |
2374 | { |
2379 | { |
2375 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2380 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2376 | croak ("maptile::add_underlay: palette must be arrayref"); |
2381 | croak ("maptile::add_underlay: palette must be arrayref"); |
… | |
… | |
2392 | |
2397 | |
2393 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2398 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2394 | { |
2399 | { |
2395 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2400 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2396 | { |
2401 | { |
2397 | object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); |
2402 | object *ob = archetype::get (cfSvPVutf8_nolen (*elem)); |
2398 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2403 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2399 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2404 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2400 | |
2405 | |
2401 | if (ob->randomitems && !ob->above) |
2406 | if (ob->randomitems && !ob->above) |
2402 | { |
2407 | { |
… | |
… | |
2406 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2411 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2407 | // TODO: if this is a pickable object, then the item |
2412 | // TODO: if this is a pickable object, then the item |
2408 | // will at a bit weird - saving inside the player |
2413 | // will at a bit weird - saving inside the player |
2409 | // will clear the flag, but when the player drops |
2414 | // will clear the flag, but when the player drops |
2410 | // it without logging out, it keeps the flag. |
2415 | // it without logging out, it keeps the flag. |
2411 | // nobody ahs reported this, but this can be rather |
2416 | // nobody has reported this, but this can be rather |
2412 | // annoying on persistent maps. |
2417 | // annoying on persistent maps. |
2413 | } |
2418 | } |
2414 | } |
2419 | } |
2415 | } |
2420 | } |
2416 | } |
2421 | } |
2417 | |
|
|
2418 | skip: ; |
2422 | skip: ; |
2419 | } |
2423 | } |
2420 | } |
2424 | } |
2421 | |
2425 | |
2422 | void |
2426 | void |
… | |
… | |
2453 | for (int x = 0; x < THIS->width; ++x) |
2457 | for (int x = 0; x < THIS->width; ++x) |
2454 | for (int y = 0; y < THIS->height; ++y) |
2458 | for (int y = 0; y < THIS->height; ++y) |
2455 | { |
2459 | { |
2456 | region *rgn = THIS->region (x, y); |
2460 | region *rgn = THIS->region (x, y); |
2457 | |
2461 | |
2458 | //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D |
|
|
2459 | if (object *op = THIS->at (x, y).top) |
2462 | if (object *op = THIS->at (x, y).top) |
2460 | if (rgn->treasure && rndm () < rgn->treasure_density) |
2463 | if (rgn->treasure && rndm () < rgn->treasure_density) |
2461 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2464 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2462 | } |
2465 | } |
2463 | |
2466 | |
… | |
… | |
2469 | if (oblinkpt *obp = map->find_link (connection)) |
2472 | if (oblinkpt *obp = map->find_link (connection)) |
2470 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2473 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2471 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2474 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2472 | |
2475 | |
2473 | void |
2476 | void |
2474 | get_map_flags (maptile *map, int x, int y) |
2477 | xy_normalise (maptile *map, int x, int y, int dir = 0) |
2475 | PPCODE: |
2478 | PPCODE: |
2476 | { |
2479 | { |
2477 | maptile *nmap = 0; |
2480 | mapxy pos (map, x, y); |
2478 | I16 nx = 0, ny = 0; |
2481 | if (!pos.move (dir).normalise ()) |
|
|
2482 | XSRETURN_EMPTY; |
2479 | |
2483 | |
2480 | PUTBACK; |
|
|
2481 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2482 | SPAGAIN; |
|
|
2483 | |
|
|
2484 | EXTEND (SP, 4); |
2484 | EXTEND (SP, 3); |
2485 | PUSHs (sv_2mortal (newSViv (flags))); |
|
|
2486 | |
|
|
2487 | if (GIMME_V == G_ARRAY) |
|
|
2488 | { |
|
|
2489 | PUSHs (sv_2mortal (to_sv (nmap))); |
2485 | PUSHs (sv_2mortal (to_sv (pos.m))); |
2490 | PUSHs (sv_2mortal (newSViv (nx))); |
2486 | PUSHs (sv_2mortal (to_sv (pos.x))); |
2491 | PUSHs (sv_2mortal (newSViv (ny))); |
2487 | PUSHs (sv_2mortal (to_sv (pos.y))); |
2492 | } |
|
|
2493 | } |
2488 | } |
2494 | |
2489 | |
2495 | mapspace * |
2490 | mapspace * |
2496 | ms (maptile *map, unsigned int x, unsigned int y) |
2491 | ms (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2497 | PROTOTYPE: $$$ |
2492 | PROTOTYPE: $$$;$ |
2498 | CODE: |
2493 | CODE: |
2499 | { |
2494 | { |
2500 | maptile *nmap = 0; |
2495 | mapxy pos (map, x, y); |
2501 | I16 nx, ny; |
2496 | 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; |
2497 | XSRETURN_UNDEF; |
2509 | |
2498 | |
2510 | RETVAL = &nmap->at (nx, ny); |
2499 | RETVAL = &*pos; |
2511 | } |
2500 | } |
2512 | OUTPUT: |
2501 | OUTPUT: |
2513 | RETVAL |
2502 | RETVAL |
2514 | |
2503 | |
2515 | void |
2504 | void |
2516 | at (maptile *map, unsigned int x, unsigned int y) |
2505 | at (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2517 | PROTOTYPE: $$$ |
2506 | PROTOTYPE: $$$;$ |
2518 | PPCODE: |
2507 | PPCODE: |
2519 | { |
2508 | mapxy pos (map, x, y); |
2520 | maptile *nmap = 0; |
2509 | 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) |
2510 | for (object *o = pos->bot; o; o = o->above) |
2529 | XPUSHs (sv_2mortal (to_sv (o))); |
2511 | XPUSHs (sv_2mortal (to_sv (o))); |
2530 | } |
|
|
2531 | |
2512 | |
2532 | SV * |
2513 | SV * |
2533 | bot_at (maptile *map, unsigned int x, unsigned int y) |
2514 | bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2534 | PROTOTYPE: $$$ |
2515 | PROTOTYPE: $$$;$ |
2535 | ALIAS: |
2516 | ALIAS: |
2536 | top_at = 1 |
2517 | top_at = 1 |
2537 | flags_at = 2 |
2518 | flags_at = 2 |
2538 | light_at = 3 |
2519 | light_at = 3 |
2539 | move_block_at = 4 |
2520 | move_block_at = 4 |
2540 | move_slow_at = 5 |
2521 | move_slow_at = 5 |
2541 | move_on_at = 6 |
2522 | move_on_at = 6 |
2542 | move_off_at = 7 |
2523 | move_off_at = 7 |
2543 | CODE: |
2524 | CODE: |
2544 | { |
2525 | { |
2545 | sint16 nx = x; |
2526 | mapxy pos (map, x, y); |
2546 | sint16 ny = y; |
2527 | if (!pos.move (dir).normalise ()) |
2547 | |
|
|
2548 | if (!xy_normalise (map, nx, ny)) |
|
|
2549 | XSRETURN_UNDEF; |
2528 | XSRETURN_UNDEF; |
2550 | |
2529 | |
2551 | mapspace &ms = map->at (nx, ny); |
2530 | mapspace &ms = *pos; |
2552 | |
2531 | |
2553 | ms.update (); |
2532 | ms.update (); |
2554 | |
2533 | |
2555 | switch (ix) |
2534 | switch (ix) |
2556 | { |
2535 | { |
… | |
… | |
2566 | } |
2545 | } |
2567 | OUTPUT: RETVAL |
2546 | OUTPUT: RETVAL |
2568 | |
2547 | |
2569 | # worst xs function of my life |
2548 | # worst xs function of my life |
2570 | bool |
2549 | bool |
2571 | _create_random_map (\ |
2550 | _create_random_map (maptile *self, SV *options) |
2572 | maptile *self,\ |
|
|
2573 | utf8_string wallstyle,\ |
|
|
2574 | utf8_string wall_name,\ |
|
|
2575 | utf8_string floorstyle,\ |
|
|
2576 | utf8_string monsterstyle,\ |
|
|
2577 | utf8_string treasurestyle,\ |
|
|
2578 | utf8_string layoutstyle,\ |
|
|
2579 | utf8_string doorstyle,\ |
|
|
2580 | utf8_string decorstyle,\ |
|
|
2581 | utf8_string miningstyle,\ |
|
|
2582 | utf8_string origin_map,\ |
|
|
2583 | utf8_string final_map,\ |
|
|
2584 | utf8_string exitstyle,\ |
|
|
2585 | utf8_string this_map,\ |
|
|
2586 | utf8_string exit_on_final_map,\ |
|
|
2587 | int xsize,\ |
|
|
2588 | int ysize,\ |
|
|
2589 | int expand2x,\ |
|
|
2590 | int layoutoptions1,\ |
|
|
2591 | int layoutoptions2,\ |
|
|
2592 | int layoutoptions3,\ |
|
|
2593 | int symmetry,\ |
|
|
2594 | int difficulty,\ |
|
|
2595 | int difficulty_given,\ |
|
|
2596 | float difficulty_increase,\ |
|
|
2597 | int dungeon_level,\ |
|
|
2598 | int dungeon_depth,\ |
|
|
2599 | int decoroptions,\ |
|
|
2600 | int orientation,\ |
|
|
2601 | int origin_y,\ |
|
|
2602 | int origin_x,\ |
|
|
2603 | U32 random_seed,\ |
|
|
2604 | val64 total_map_hp,\ |
|
|
2605 | int map_layout_style,\ |
|
|
2606 | int treasureoptions,\ |
|
|
2607 | int symmetry_used,\ |
|
|
2608 | region *region,\ |
|
|
2609 | utf8_string custom\ |
|
|
2610 | ) |
|
|
2611 | CODE: |
2551 | CODE: |
2612 | { |
2552 | { |
2613 | random_map_params rmp; |
2553 | random_map_params rmp ((HV *)SvRV (options)); |
2614 | |
|
|
2615 | assign (rmp.wallstyle , wallstyle); |
|
|
2616 | assign (rmp.wall_name , wall_name); |
|
|
2617 | assign (rmp.floorstyle , floorstyle); |
|
|
2618 | assign (rmp.monsterstyle , monsterstyle); |
|
|
2619 | assign (rmp.treasurestyle , treasurestyle); |
|
|
2620 | assign (rmp.layoutstyle , layoutstyle); |
|
|
2621 | assign (rmp.doorstyle , doorstyle); |
|
|
2622 | assign (rmp.decorstyle , decorstyle); |
|
|
2623 | assign (rmp.miningstyle , miningstyle); |
|
|
2624 | assign (rmp.exitstyle , exitstyle); |
|
|
2625 | assign (rmp.exit_on_final_map, exit_on_final_map); |
|
|
2626 | |
|
|
2627 | rmp.origin_map = origin_map; |
|
|
2628 | rmp.final_map = final_map; |
|
|
2629 | rmp.this_map = this_map; |
|
|
2630 | rmp.xsize = xsize; |
|
|
2631 | rmp.ysize = ysize; |
|
|
2632 | rmp.expand2x = expand2x; |
|
|
2633 | rmp.layoutoptions1 = layoutoptions1; |
|
|
2634 | rmp.layoutoptions2 = layoutoptions2; |
|
|
2635 | rmp.layoutoptions3 = layoutoptions3; |
|
|
2636 | rmp.symmetry = symmetry; |
|
|
2637 | rmp.difficulty = difficulty; |
|
|
2638 | rmp.difficulty_given = difficulty_given; |
|
|
2639 | rmp.difficulty_increase = difficulty_increase; |
|
|
2640 | rmp.dungeon_level = dungeon_level; |
|
|
2641 | rmp.dungeon_depth = dungeon_depth; |
|
|
2642 | rmp.decoroptions = decoroptions; |
|
|
2643 | rmp.orientation = orientation; |
|
|
2644 | rmp.origin_y = origin_y; |
|
|
2645 | rmp.origin_x = origin_x; |
|
|
2646 | rmp.random_seed = random_seed; |
|
|
2647 | rmp.total_map_hp = (uint64_t) total_map_hp; |
|
|
2648 | rmp.map_layout_style = map_layout_style; |
|
|
2649 | rmp.treasureoptions = treasureoptions; |
|
|
2650 | rmp.symmetry_used = symmetry_used; |
|
|
2651 | rmp.region = region; |
|
|
2652 | rmp.custom = custom; |
|
|
2653 | |
|
|
2654 | RETVAL = self->generate_random_map (&rmp); |
2554 | RETVAL = self->generate_random_map (&rmp); |
2655 | } |
2555 | } |
2656 | OUTPUT: |
2556 | OUTPUT: |
2657 | RETVAL |
2557 | RETVAL |
2658 | |
2558 | |
… | |
… | |
2689 | void |
2589 | void |
2690 | list () |
2590 | list () |
2691 | PPCODE: |
2591 | PPCODE: |
2692 | for_all_regions (rgn) |
2592 | for_all_regions (rgn) |
2693 | XPUSHs (sv_2mortal (to_sv (rgn))); |
2593 | XPUSHs (sv_2mortal (to_sv (rgn))); |
2694 | |
|
|
2695 | region *find (utf8_string name) |
|
|
2696 | PROTOTYPE: $ |
|
|
2697 | CODE: |
|
|
2698 | RETVAL = region::find (name); |
|
|
2699 | OUTPUT: RETVAL |
|
|
2700 | |
2594 | |
2701 | int specificity (region *rgn) |
2595 | int specificity (region *rgn) |
2702 | CODE: |
2596 | CODE: |
2703 | RETVAL = 0; |
2597 | RETVAL = 0; |
2704 | while (rgn = rgn->parent) |
2598 | while (rgn = rgn->parent) |
… | |
… | |
2836 | |
2730 | |
2837 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2731 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2838 | CODE: |
2732 | CODE: |
2839 | { |
2733 | { |
2840 | faceinfo *f = face_info (idx); assert (f); |
2734 | faceinfo *f = face_info (idx); assert (f); |
2841 | facedata *d = &(faceset ? f->data64 : f->data32); |
2735 | facedata *d = f->face + faceset; |
2842 | sv_to (data, d->data); |
2736 | sv_to (data, d->data); |
2843 | STRLEN clen; |
2737 | STRLEN clen; |
2844 | char *cdata = SvPVbyte (chksum, clen); |
2738 | char *cdata = SvPVbyte (chksum, clen); |
2845 | clen = min (CHKSUM_MAXLEN, clen); |
2739 | clen = min (CHKSUM_MAXLEN, clen); |
2846 | |
2740 | |
… | |
… | |
2954 | sv_to (sv, self); |
2848 | sv_to (sv, self); |
2955 | delete self; |
2849 | delete self; |
2956 | |
2850 | |
2957 | MODULE = cf PACKAGE = cf::object::thawer |
2851 | MODULE = cf PACKAGE = cf::object::thawer |
2958 | |
2852 | |
2959 | INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | |
2853 | INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h | |
|
|
2854 | |
|
|
2855 | bool |
|
|
2856 | errors_are_fatal (bool fatal) |
|
|
2857 | CODE: |
|
|
2858 | RETVAL = object_thawer::errors_are_fatal; |
|
|
2859 | object_thawer::errors_are_fatal = fatal; |
|
|
2860 | OUTPUT: |
|
|
2861 | RETVAL |
2960 | |
2862 | |
2961 | SV * |
2863 | SV * |
2962 | new_from_file (char *klass, octet_string path) |
2864 | new_from_file (char *klass, octet_string path) |
2963 | CODE: |
2865 | CODE: |
2964 | object_thawer *f = new object_thawer (path); |
2866 | object_thawer *f = new object_thawer (path); |
… | |
… | |
2990 | XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); |
2892 | XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); |
2991 | |
2893 | |
2992 | self->skip (); |
2894 | self->skip (); |
2993 | } |
2895 | } |
2994 | |
2896 | |
|
|
2897 | MODULE = cf PACKAGE = cf::layout |
|
|
2898 | |
|
|
2899 | INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h | |
|
|
2900 | |