ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.374 by root, Thu Apr 15 06:05:52 2010 UTC vs.
Revision 1.402 by root, Sun May 1 13:18:24 2011 UTC

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
83 *stash_cf_mapspace_wrap, 84 *stash_cf_mapspace_wrap,
84 *stash_cf_client_wrap, 85 *stash_cf_client_wrap,
85 *stash_cf_arch_wrap, 86 *stash_cf_arch_wrap,
86 *stash_cf_party_wrap, 87 *stash_cf_party_wrap,
87 *stash_cf_region_wrap, 88 *stash_cf_region_wrap,
88 *stash_cf_living_wrap; 89 *stash_cf_living_wrap,
90 *stash_cf_layout_wrap,
91 *stash_ext_map_world;
89 92
90static SV 93static SV
91 *cv_cf_do_invoke, 94 *cv_cf_do_invoke,
92 *cv_cf__can_merge, 95 *cv_cf__can_merge,
93 *cv_cf_client_send_msg, 96 *cv_cf_client_send_msg,
121 124
122 return sv; 125 return sv;
123} 126}
124#endif 127#endif
125 128
126static noinline utf8_string 129noinline utf8_string
127cfSvPVutf8_nolen (SV *sv) 130cfSvPVutf8_nolen (SV *sv)
128{ 131{
129 SvGETMAGIC (sv); 132 SvGETMAGIC (sv);
130 133
131 if (SvPOK (sv)) 134 if (SvPOK (sv))
351#endif 354#endif
352 355
353////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 356//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
354 357
355static SV * 358static SV *
356newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 359newSVptr (void *ptr, HV *stash, HV *hv)
357{ 360{
358 SV *sv;
359
360 if (!ptr) 361 if (!ptr)
361 return newSV (0); 362 return newSV (0);
362 363
363 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);
364 return sv_bless (newRV_noinc ((SV *)hv), stash); 365 return sv_bless (newRV_noinc ((SV *)hv), stash);
366}
367
368static SV * noinline
369newSVptr (void *ptr, HV *stash)
370{
371 return newSVptr (ptr, stash, newHV ());
365} 372}
366 373
367static int 374static int
368attachable_free (pTHX_ SV *sv, MAGIC *mg) 375attachable_free (pTHX_ SV *sv, MAGIC *mg)
369{ 376{
381 return 0; 388 return 0;
382} 389}
383 390
384MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 391MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
385 392
386static SV * 393static SV * noinline
387newSVattachable (attachable *obj, HV *stash) 394newSVattachable (attachable *obj, HV *stash)
388{ 395{
389 if (!obj) 396 if (!obj)
390 return newSV (0); 397 return newSV (0);
391 398
477 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap 484 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap
478 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap 485 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap
479 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap 486 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap
480 && !sv_derived_from (sv, "cf::object"))) 487 && !sv_derived_from (sv, "cf::object")))
481 croak ("object of type cf::object expected"); 488 croak ("object of type cf::object expected");
489
490 return SvPTR_nc (sv);
491}
492
493static long noinline
494SvPTR_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");
482 503
483 return SvPTR_nc (sv); 504 return SvPTR_nc (sv);
484} 505}
485 506
486static long noinline 507static long noinline
511static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 532static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
512static inline SV *to_sv (float v) { return newSVnv (v); } 533static inline SV *to_sv (float v) { return newSVnv (v); }
513static inline SV *to_sv (double v) { return newSVnv (v); } 534static inline SV *to_sv (double v) { return newSVnv (v); }
514static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 535static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
515static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 536static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
537// gcc dislikes noilnine on to_sv
516static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 538static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
539static inline SV *to_sv (object * v) { return to_sv_ni (v); }
517static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 540static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
518static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 541static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
519static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 542static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
520static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 543static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
521static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 544static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
522static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } 545static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
546static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
523 547
524static inline SV *to_sv (object & v) { return to_sv (&v); } 548static inline SV *to_sv (object & v) { return to_sv (&v); }
525static inline SV *to_sv (living & v) { return to_sv (&v); } 549static inline SV *to_sv (living & v) { return to_sv (&v); }
526 550
527static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 551static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
563static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 587static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
564static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } 588static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
565static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } 589static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
566static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 590static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
567static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 591static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
568static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } 592static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); }
569static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } 593static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); }
570static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } 594static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); }
595static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull_maptile (sv); }
571static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 596static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
572static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); }
573static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 597static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
574static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 598static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
575static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 599static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
576static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 600static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
577static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 601static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
602static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); }
578static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } 603static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
579static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } 604static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
580 605
581//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)]; }
582static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 607static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
693template<class type> 718template<class type>
694static void noinline 719static void noinline
695cf_obj_to (SV *arg, type &var) 720cf_obj_to (SV *arg, type &var)
696{ 721{
697 sv_to (arg, var); 722 sv_to (arg, var);
698 if (!var) 723 if (expect_false (!var))
699 croak ("must not pass invalid/null cf_obj here"); 724 croak ("must not pass invalid/null cf_obj here");
700} 725}
701 726
702template<class object> 727template<class object>
703static void noinline 728static void noinline
704cf_obj_ornull_to (SV *arg, object *&var) 729cf_obj_ornull_to (SV *arg, object *&var)
705{ 730{
706 if (SvOK (arg)) 731 if (SvOK (arg))
707 { 732 {
708 sv_to (arg, var); 733 sv_to (arg, var);
709 if (!var) 734 if (expect_false (!var))
710 croak ("unable to convert perl object to C++ object"); 735 croak ("unable to convert perl object to C++ object");
711 } 736 }
712 else 737 else
713 var = 0; 738 var = 0;
714} 739}
749 exit (EXIT_FAILURE); 774 exit (EXIT_FAILURE);
750 } 775 }
751 776
752 eval_pv ( 777 eval_pv (
753 "#line 1 'cfperl init'\n" 778 "#line 1 'cfperl init'\n"
754 "use EV ();\n" 779 "use EV ();\n" // required by bootstrap
755 "use Coro ();\n" 780 "use Coro ();\n" // required by bootstrap
756 "cf->bootstrap;\n" 781 "cf->bootstrap;\n" // required for cf::datadir
757 "unshift @INC, cf::datadir ();\n" 782 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
758 "require cf;\n", 783 "require cf;\n",
759 0 784 0
760 ); 785 );
761 786
762 if (SvTRUE (ERRSV)) 787 if (SvTRUE (ERRSV))
1376 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1401 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1377 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1402 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1378 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1403 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1379 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1404 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1380 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);
1381 1408
1382 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);
1383 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);
1384 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);
1385 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);
1433# include "attackinc.h" 1460# include "attackinc.h"
1434# undef def 1461# undef def
1435# define def(uc, flags) const_iv (SK_ ## uc) 1462# define def(uc, flags) const_iv (SK_ ## uc)
1436# include "skillinc.h" 1463# include "skillinc.h"
1437# undef def 1464# undef def
1438 1465# define def(name, use, nonuse) const_iv (body_ ## name)
1439 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1466# include "slotinc.h"
1440 const_iv (logBacktrace) 1467# undef def
1441
1442 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1443 1468
1444 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1469 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1445 1470
1446 const_iv (MAX_TIME) 1471 const_iv (MAX_TIME)
1447 const_iv (MAXSOCKBUF) 1472 const_iv (MAXSOCKBUF)
1472 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)
1473 1498
1474 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)
1475 }; 1500 };
1476 1501
1477 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; )
1478 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1503 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1479 1504
1480 static const struct { 1505 static const struct {
1481 const char *name; 1506 const char *name;
1482 int skip; 1507 int skip;
1488# undef def 1513# undef def
1489 }; 1514 };
1490 1515
1491 AV *av = get_av ("cf::EVENT", 1); 1516 AV *av = get_av ("cf::EVENT", 1);
1492 1517
1493 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; )
1494 { 1519 {
1495 AV *event = newAV (); 1520 AV *event = newAV ();
1496 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1521 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1497 av_push (event, newSViv (eiv->klass)); 1522 av_push (event, newSViv (eiv->klass));
1498 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1523 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1533 1558
1534 for_all_objects (op) 1559 for_all_objects (op)
1535 op->reattach (); 1560 op->reattach ();
1536} 1561}
1537 1562
1538# support function for map-world.ext
1539void _quantise (SV *data_sv, SV *plt_sv)
1540 CODE:
1541{
1542 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1543 croak ("_quantise called with invalid agruments");
1544
1545 plt_sv = SvRV (plt_sv);
1546 SV **plt = AvARRAY (plt_sv);
1547 int plt_count = AvFILL (plt_sv) + 1;
1548
1549 STRLEN len;
1550 char *data = SvPVbyte (data_sv, len);
1551 char *dst = data;
1552
1553 while (len >= 3)
1554 {
1555 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1556 {
1557 char *val = SvPVX (*val_sv);
1558
1559 if (val [0] == data [0]
1560 && val [1] == data [1]
1561 && val [2] == data [2])
1562 {
1563 *dst++ = val [3];
1564 goto next;
1565 }
1566 }
1567
1568 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1569 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1570 dst - SvPVX (data_sv), len);
1571
1572 next:
1573 data += 3;
1574 len -= 3;
1575 }
1576
1577 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1578}
1579
1580void init_anim () 1563void init_anim ()
1581 1564
1582void init_globals () 1565void init_globals ()
1583 1566
1584void init_experience ()
1585
1586void init_attackmess () 1567void init_attackmess ()
1587 1568
1588void init_dynamic () 1569void init_dynamic ()
1589 1570
1590void load_settings () 1571void load_settings ()
1591 1572
1573void reload_exp_table ()
1574
1592void load_materials () 1575void reload_materials ()
1593 1576
1594void init_uuid () 1577void init_uuid ()
1595 CODE: 1578 CODE:
1596 UUID::init (); 1579 UUID::init ();
1597 1580
1752 1735
1753int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1736int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1754 INIT: 1737 INIT:
1755#if __GLIBC__ 1738#if __GLIBC__
1756 mallopt (M_TOP_PAD, 1024 * 1024); 1739 mallopt (M_TOP_PAD, 1024 * 1024);
1757 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1740 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1758 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))
1759 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1743 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1760#endif 1744#endif
1761 1745
1762int munlockall () 1746int munlockall ()
1763 1747
1764#endif 1748#endif
1802int exp_to_level (val64 exp) 1786int exp_to_level (val64 exp)
1803 1787
1804val64 level_to_min_exp (int level) 1788val64 level_to_min_exp (int level)
1805 1789
1806SV * 1790SV *
1807resistance_to_string (int atnr) 1791attacktype_name (int atnr)
1808 CODE: 1792 CODE:
1809 if (atnr >= 0 && atnr < NROFATTACKS) 1793 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1794 ? newSVpv (attacktype_name [atnr], 0)
1795 : &PL_sv_undef;
1796 OUTPUT: RETVAL
1797
1798SV *
1799attacktype_desc (int atnr)
1800 CODE:
1801 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1802 ? newSVpv (attacktype_desc [atnr], 0)
1803 : &PL_sv_undef;
1804 OUTPUT: RETVAL
1805
1806SV *
1807resist_plus (int atnr)
1808 CODE:
1809 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1810 RETVAL = newSVpv (resist_plus[atnr], 0); 1810 ? newSVpv (resist_plus [atnr], 0)
1811 else 1811 : &PL_sv_undef;
1812 XSRETURN_UNDEF; 1812 OUTPUT: RETVAL
1813
1814SV *
1815change_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;
1813 OUTPUT: RETVAL 1820 OUTPUT: RETVAL
1814 1821
1815UUID 1822UUID
1816uuid_cur () 1823uuid_cur ()
1817 CODE: 1824 CODE:
1867 CODE: 1874 CODE:
1868 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1875 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1869 OUTPUT: 1876 OUTPUT:
1870 RETVAL 1877 RETVAL
1871 1878
1879bool should_invoke (attachable *obj, int event)
1880 CODE:
1881 RETVAL = obj->should_invoke ((event_type)event);
1882 OUTPUT: RETVAL
1883
1872void 1884void
1873debug_trace (attachable *obj, bool on = true) 1885debug_trace (attachable *obj, bool on = true)
1874 CODE: 1886 CODE:
1875 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1887 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1876 if (on) 1888 if (on)
1935int mortals_size () 1947int mortals_size ()
1936 CODE: 1948 CODE:
1937 RETVAL = attachable::mortals.size (); 1949 RETVAL = attachable::mortals.size ();
1938 OUTPUT: RETVAL 1950 OUTPUT: RETVAL
1939 1951
1940const_utf8_string slot_use_name (U32 slot) 1952const_utf8_string slot_name (U32 slot)
1941 ALIAS: 1953 ALIAS:
1954 slot_name = 0
1955 slot_use_name = 1
1942 slot_nonuse_name = 1 1956 slot_nonuse_name = 2
1943 CODE: 1957 CODE:
1944{ 1958{
1945 if (slot >= NUM_BODY_LOCATIONS) 1959 if (slot >= NUM_BODY_LOCATIONS)
1946 croak ("body slot index out of range"); 1960 croak ("body slot index out of range");
1947 1961
1948 switch (ix) 1962 switch (ix)
1949 { 1963 {
1964 case 0: RETVAL = body_locations[slot].name ; break;
1950 case 0: RETVAL = body_locations[slot].use_name; break; 1965 case 1: RETVAL = body_locations[slot].use_name ; break;
1951 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1966 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1952 } 1967 }
1953} 1968}
1954 OUTPUT: 1969 OUTPUT:
1955 RETVAL 1970 RETVAL
1956 1971
2062 2077
2063void pick_up (object *who, object *op) 2078void pick_up (object *who, object *op)
2064 2079
2065void update_object (object *op, int action) 2080void update_object (object *op, int action)
2066 2081
2067void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2082void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2068 2083
2069void player_lvl_adj (object *who, object *skill = 0) 2084void player_lvl_adj (object *who, object *skill = 0)
2070 2085
2071int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2086int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2072 2087
2117 RETVAL = 0; 2132 RETVAL = 0;
2118} 2133}
2119 2134
2120shstr 2135shstr
2121object::kv_get (shstr key) 2136object::kv_get (shstr key)
2137 CODE:
2138 RETVAL = THIS->kv.get (key);
2139 OUTPUT:
2140 RETVAL
2122 2141
2123void 2142void
2124object::kv_del (shstr key) 2143object::kv_del (shstr key)
2144 CODE:
2145 THIS->kv.del (key);
2125 2146
2126void 2147void
2127object::kv_set (shstr key, shstr value) 2148object::kv_set (shstr key, shstr value)
2149 CODE:
2150 THIS->kv.set (key, value);
2128 2151
2129object *get_nearest_player (object *ob) 2152object *get_nearest_player (object *ob)
2130 ALIAS: nearest_player = 0 2153 ALIAS: nearest_player = 0
2131 PREINIT: 2154 PREINIT:
2132 extern object *get_nearest_player (object *); 2155 extern object *get_nearest_player (object *);
2334 for_all_players (pl) 2357 for_all_players (pl)
2335 if (pl->ob && pl->ob->map == THIS) 2358 if (pl->ob && pl->ob->map == THIS)
2336 PUSHs (sv_2mortal (to_sv (pl->ob))); 2359 PUSHs (sv_2mortal (to_sv (pl->ob)));
2337 } 2360 }
2338 2361
2362#if 0
2363
2364void
2365maptile::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
2339void 2420void
2340maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2421maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2341 CODE: 2422 CODE:
2342{ 2423{
2343 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2424 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2374 op->flag [FLAG_NO_MAP_SAVE] = true; 2455 op->flag [FLAG_NO_MAP_SAVE] = true;
2375 // TODO: if this is a pickable object, then the item 2456 // TODO: if this is a pickable object, then the item
2376 // will at a bit weird - saving inside the player 2457 // will at a bit weird - saving inside the player
2377 // will clear the flag, but when the player drops 2458 // will clear the flag, but when the player drops
2378 // it without logging out, it keeps the flag. 2459 // it without logging out, it keeps the flag.
2379 // nobody ahs reported this, but this can be rather 2460 // nobody has reported this, but this can be rather
2380 // annoying on persistent maps. 2461 // annoying on persistent maps.
2381 } 2462 }
2382 } 2463 }
2383 } 2464 }
2384 } 2465 }
2385
2386 skip: ; 2466 skip: ;
2387 } 2467 }
2388} 2468}
2389 2469
2390void 2470void
2421 for (int x = 0; x < THIS->width; ++x) 2501 for (int x = 0; x < THIS->width; ++x)
2422 for (int y = 0; y < THIS->height; ++y) 2502 for (int y = 0; y < THIS->height; ++y)
2423 { 2503 {
2424 region *rgn = THIS->region (x, y); 2504 region *rgn = THIS->region (x, y);
2425 2505
2426 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2427 if (object *op = THIS->at (x, y).top) 2506 if (object *op = THIS->at (x, y).top)
2428 if (rgn->treasure && rndm () < rgn->treasure_density) 2507 if (rgn->treasure && rndm () < rgn->treasure_density)
2429 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2508 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2430 } 2509 }
2431 2510
2437 if (oblinkpt *obp = map->find_link (connection)) 2516 if (oblinkpt *obp = map->find_link (connection))
2438 for (objectlink *ol = obp->link; ol; ol = ol->next) 2517 for (objectlink *ol = obp->link; ol; ol = ol->next)
2439 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2518 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2440 2519
2441void 2520void
2442get_map_flags (maptile *map, int x, int y) 2521xy_normalise (maptile *map, int x, int y, int dir = 0)
2443 PPCODE: 2522 PPCODE:
2444{ 2523{
2445 maptile *nmap = 0; 2524 mapxy pos (map, x, y);
2446 I16 nx = 0, ny = 0; 2525 if (!pos.move (dir).normalise ())
2526 XSRETURN_EMPTY;
2447 2527
2448 PUTBACK;
2449 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2450 SPAGAIN;
2451
2452 EXTEND (SP, 4); 2528 EXTEND (SP, 3);
2453 PUSHs (sv_2mortal (newSViv (flags)));
2454
2455 if (GIMME_V == G_ARRAY)
2456 {
2457 PUSHs (sv_2mortal (to_sv (nmap))); 2529 PUSHs (sv_2mortal (to_sv (pos.m)));
2458 PUSHs (sv_2mortal (newSViv (nx))); 2530 PUSHs (sv_2mortal (to_sv (pos.x)));
2459 PUSHs (sv_2mortal (newSViv (ny))); 2531 PUSHs (sv_2mortal (to_sv (pos.y)));
2460 }
2461} 2532}
2462 2533
2463mapspace * 2534mapspace *
2464ms (maptile *map, unsigned int x, unsigned int y) 2535ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2465 PROTOTYPE: $$$ 2536 PROTOTYPE: $$$;$
2466 CODE: 2537 CODE:
2467{ 2538{
2468 maptile *nmap = 0; 2539 mapxy pos (map, x, y);
2469 I16 nx, ny; 2540 if (!pos.move (dir).normalise ())
2470
2471 PUTBACK;
2472 get_map_flags (map, &nmap, x, y, &nx, &ny);
2473 SPAGAIN;
2474
2475 if (!nmap)
2476 XSRETURN_UNDEF; 2541 XSRETURN_UNDEF;
2477 2542
2478 RETVAL = &nmap->at (nx, ny); 2543 RETVAL = &*pos;
2479} 2544}
2480 OUTPUT: 2545 OUTPUT:
2481 RETVAL 2546 RETVAL
2482 2547
2483void 2548void
2484at (maptile *map, unsigned int x, unsigned int y) 2549at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2485 PROTOTYPE: $$$ 2550 PROTOTYPE: $$$;$
2486 PPCODE: 2551 PPCODE:
2487{ 2552 mapxy pos (map, x, y);
2488 maptile *nmap = 0; 2553 if (pos.move (dir).normalise ())
2489 I16 nx, ny;
2490
2491 PUTBACK;
2492 get_map_flags (map, &nmap, x, y, &nx, &ny);
2493 SPAGAIN;
2494
2495 if (nmap)
2496 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2554 for (object *o = pos->bot; o; o = o->above)
2497 XPUSHs (sv_2mortal (to_sv (o))); 2555 XPUSHs (sv_2mortal (to_sv (o)));
2498}
2499 2556
2500SV * 2557SV *
2501bot_at (maptile *map, unsigned int x, unsigned int y) 2558bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2502 PROTOTYPE: $$$ 2559 PROTOTYPE: $$$;$
2503 ALIAS: 2560 ALIAS:
2504 top_at = 1 2561 top_at = 1
2505 flags_at = 2 2562 flags_at = 2
2506 light_at = 3 2563 light_at = 3
2507 move_block_at = 4 2564 move_block_at = 4
2508 move_slow_at = 5 2565 move_slow_at = 5
2509 move_on_at = 6 2566 move_on_at = 6
2510 move_off_at = 7 2567 move_off_at = 7
2511 CODE: 2568 CODE:
2512{ 2569{
2513 sint16 nx = x; 2570 mapxy pos (map, x, y);
2514 sint16 ny = y; 2571 if (!pos.move (dir).normalise ())
2515
2516 if (!xy_normalise (map, nx, ny))
2517 XSRETURN_UNDEF; 2572 XSRETURN_UNDEF;
2518 2573
2519 mapspace &ms = map->at (nx, ny); 2574 mapspace &ms = *pos;
2520 2575
2521 ms.update (); 2576 ms.update ();
2522 2577
2523 switch (ix) 2578 switch (ix)
2524 { 2579 {
2534} 2589}
2535 OUTPUT: RETVAL 2590 OUTPUT: RETVAL
2536 2591
2537# worst xs function of my life 2592# worst xs function of my life
2538bool 2593bool
2539_create_random_map (\ 2594_create_random_map (maptile *self, SV *options)
2540 maptile *self,\
2541 utf8_string wallstyle,\
2542 utf8_string wall_name,\
2543 utf8_string floorstyle,\
2544 utf8_string monsterstyle,\
2545 utf8_string treasurestyle,\
2546 utf8_string layoutstyle,\
2547 utf8_string doorstyle,\
2548 utf8_string decorstyle,\
2549 utf8_string miningstyle,\
2550 utf8_string origin_map,\
2551 utf8_string final_map,\
2552 utf8_string exitstyle,\
2553 utf8_string this_map,\
2554 utf8_string exit_on_final_map,\
2555 int xsize,\
2556 int ysize,\
2557 int expand2x,\
2558 int layoutoptions1,\
2559 int layoutoptions2,\
2560 int layoutoptions3,\
2561 int symmetry,\
2562 int difficulty,\
2563 int difficulty_given,\
2564 float difficulty_increase,\
2565 int dungeon_level,\
2566 int dungeon_depth,\
2567 int decoroptions,\
2568 int orientation,\
2569 int origin_y,\
2570 int origin_x,\
2571 U32 random_seed,\
2572 val64 total_map_hp,\
2573 int map_layout_style,\
2574 int treasureoptions,\
2575 int symmetry_used,\
2576 region *region,\
2577 utf8_string custom\
2578)
2579 CODE: 2595 CODE:
2580{ 2596{
2581 random_map_params rmp; 2597 random_map_params rmp ((HV *)SvRV (options));
2582
2583 assign (rmp.wallstyle , wallstyle);
2584 assign (rmp.wall_name , wall_name);
2585 assign (rmp.floorstyle , floorstyle);
2586 assign (rmp.monsterstyle , monsterstyle);
2587 assign (rmp.treasurestyle , treasurestyle);
2588 assign (rmp.layoutstyle , layoutstyle);
2589 assign (rmp.doorstyle , doorstyle);
2590 assign (rmp.decorstyle , decorstyle);
2591 assign (rmp.miningstyle , miningstyle);
2592 assign (rmp.exitstyle , exitstyle);
2593 assign (rmp.exit_on_final_map, exit_on_final_map);
2594
2595 rmp.origin_map = origin_map;
2596 rmp.final_map = final_map;
2597 rmp.this_map = this_map;
2598 rmp.xsize = xsize;
2599 rmp.ysize = ysize;
2600 rmp.expand2x = expand2x;
2601 rmp.layoutoptions1 = layoutoptions1;
2602 rmp.layoutoptions2 = layoutoptions2;
2603 rmp.layoutoptions3 = layoutoptions3;
2604 rmp.symmetry = symmetry;
2605 rmp.difficulty = difficulty;
2606 rmp.difficulty_given = difficulty_given;
2607 rmp.difficulty_increase = difficulty_increase;
2608 rmp.dungeon_level = dungeon_level;
2609 rmp.dungeon_depth = dungeon_depth;
2610 rmp.decoroptions = decoroptions;
2611 rmp.orientation = orientation;
2612 rmp.origin_y = origin_y;
2613 rmp.origin_x = origin_x;
2614 rmp.random_seed = random_seed;
2615 rmp.total_map_hp = (uint64_t) total_map_hp;
2616 rmp.map_layout_style = map_layout_style;
2617 rmp.treasureoptions = treasureoptions;
2618 rmp.symmetry_used = symmetry_used;
2619 rmp.region = region;
2620 rmp.custom = custom;
2621
2622 RETVAL = self->generate_random_map (&rmp); 2598 RETVAL = self->generate_random_map (&rmp);
2623} 2599}
2624 OUTPUT: 2600 OUTPUT:
2625 RETVAL 2601 RETVAL
2626 2602
2657void 2633void
2658list () 2634list ()
2659 PPCODE: 2635 PPCODE:
2660 for_all_regions (rgn) 2636 for_all_regions (rgn)
2661 XPUSHs (sv_2mortal (to_sv (rgn))); 2637 XPUSHs (sv_2mortal (to_sv (rgn)));
2662
2663region *find (utf8_string name)
2664 PROTOTYPE: $
2665 CODE:
2666 RETVAL = region::find (name);
2667 OUTPUT: RETVAL
2668 2638
2669int specificity (region *rgn) 2639int specificity (region *rgn)
2670 CODE: 2640 CODE:
2671 RETVAL = 0; 2641 RETVAL = 0;
2672 while (rgn = rgn->parent) 2642 while (rgn = rgn->parent)
2804 2774
2805void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2775void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2806 CODE: 2776 CODE:
2807{ 2777{
2808 faceinfo *f = face_info (idx); assert (f); 2778 faceinfo *f = face_info (idx); assert (f);
2809 facedata *d = &(faceset ? f->data64 : f->data32); 2779 facedata *d = f->face + faceset;
2810 sv_to (data, d->data); 2780 sv_to (data, d->data);
2811 STRLEN clen; 2781 STRLEN clen;
2812 char *cdata = SvPVbyte (chksum, clen); 2782 char *cdata = SvPVbyte (chksum, clen);
2813 clen = min (CHKSUM_MAXLEN, clen); 2783 clen = min (CHKSUM_MAXLEN, clen);
2814 2784
2966 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2936 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2967 2937
2968 self->skip (); 2938 self->skip ();
2969 } 2939 }
2970 2940
2941MODULE = cf PACKAGE = cf::layout
2942
2943INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2944

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines