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.363 by root, Sun Apr 11 01:35:51 2010 UTC vs.
Revision 1.388 by root, Wed Jun 30 01:57:54 2010 UTC

52#include <XSUB.h> 52#include <XSUB.h>
53 53
54#include "CoroAPI.h" 54#include "CoroAPI.h"
55#include "perlxsi.c" 55#include "perlxsi.c"
56 56
57extern sint64 *levels; // the experience table
58
59typedef object_thawer &object_thawer_ref; 57typedef object_thawer &object_thawer_ref;
60typedef object_freezer &object_freezer_ref; 58typedef object_freezer &object_freezer_ref;
61 59
62typedef std::string std__string; 60typedef std::string std__string;
63 61
85 *stash_cf_mapspace_wrap, 83 *stash_cf_mapspace_wrap,
86 *stash_cf_client_wrap, 84 *stash_cf_client_wrap,
87 *stash_cf_arch_wrap, 85 *stash_cf_arch_wrap,
88 *stash_cf_party_wrap, 86 *stash_cf_party_wrap,
89 *stash_cf_region_wrap, 87 *stash_cf_region_wrap,
90 *stash_cf_living_wrap; 88 *stash_cf_living_wrap,
89 *stash_ext_map_world;
91 90
92static SV 91static SV
93 *cv_cf_do_invoke, 92 *cv_cf_do_invoke,
94 *cv_cf__can_merge, 93 *cv_cf__can_merge,
95 *cv_cf_client_send_msg, 94 *cv_cf_client_send_msg,
123 122
124 return sv; 123 return sv;
125} 124}
126#endif 125#endif
127 126
128static noinline utf8_string 127noinline utf8_string
129cfSvPVutf8_nolen (SV *sv) 128cfSvPVutf8_nolen (SV *sv)
130{ 129{
131 SvGETMAGIC (sv); 130 SvGETMAGIC (sv);
132 131
133 if (SvPOK (sv)) 132 if (SvPOK (sv))
230 do_destroy (); 229 do_destroy ();
231 sever_self (); 230 sever_self ();
232} 231}
233 232
234void 233void
234attachable::do_delete ()
235{
236 delete this;
237}
238
239void
235attachable::check_mortals () 240attachable::check_mortals ()
236{ 241{
237 static int i = 0; 242 static int i = 0;
238 243
239 for (;;) 244 for (;;)
252 257
253 if (0) 258 if (0)
254 { 259 {
255 for (int j = 0; j < mortals.size (); ++j)//D 260 for (int j = 0; j < mortals.size (); ++j)//D
256 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 261 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
262
257 fprintf (stderr, "\n");//D 263 fprintf (stderr, "\n");//D
258 } 264 }
259 } 265 }
260 } 266 }
261 267
281 } 287 }
282 else 288 else
283 { 289 {
284 mortals.erase (i); 290 mortals.erase (i);
285 obj->sever_self (); 291 obj->sever_self ();
286 delete obj; 292 obj->do_delete ();
287 } 293 }
288 } 294 }
289} 295}
290 296
291void 297void
346#endif 352#endif
347 353
348////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 354//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
349 355
350static SV * 356static SV *
351newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 357newSVptr (void *ptr, HV *stash, HV *hv)
352{ 358{
353 SV *sv;
354
355 if (!ptr) 359 if (!ptr)
356 return newSV (0); 360 return newSV (0);
357 361
358 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 362 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
359 return sv_bless (newRV_noinc ((SV *)hv), stash); 363 return sv_bless (newRV_noinc ((SV *)hv), stash);
364}
365
366static SV * noinline
367newSVptr (void *ptr, HV *stash)
368{
369 return newSVptr (ptr, stash, newHV ());
360} 370}
361 371
362static int 372static int
363attachable_free (pTHX_ SV *sv, MAGIC *mg) 373attachable_free (pTHX_ SV *sv, MAGIC *mg)
364{ 374{
376 return 0; 386 return 0;
377} 387}
378 388
379MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 389MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
380 390
381static SV * 391static SV * noinline
382newSVattachable (attachable *obj, HV *stash) 392newSVattachable (attachable *obj, HV *stash)
383{ 393{
384 if (!obj) 394 if (!obj)
385 return newSV (0); 395 return newSV (0);
386 396
472 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap 482 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap
473 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap 483 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap
474 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap 484 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap
475 && !sv_derived_from (sv, "cf::object"))) 485 && !sv_derived_from (sv, "cf::object")))
476 croak ("object of type cf::object expected"); 486 croak ("object of type cf::object expected");
487
488 return SvPTR_nc (sv);
489}
490
491static long noinline
492SvPTR_ornull_maptile (SV *sv)
493{
494 if (expect_false (!SvOK (sv))) return 0;
495
496 if (!SvROK (sv)
497 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap
498 && SvSTASH (SvRV (sv)) != stash_ext_map_world
499 && !sv_derived_from (sv, "cf::map")))
500 croak ("object of type cf::map expected");
477 501
478 return SvPTR_nc (sv); 502 return SvPTR_nc (sv);
479} 503}
480 504
481static long noinline 505static long noinline
506static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 530static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
507static inline SV *to_sv (float v) { return newSVnv (v); } 531static inline SV *to_sv (float v) { return newSVnv (v); }
508static inline SV *to_sv (double v) { return newSVnv (v); } 532static inline SV *to_sv (double v) { return newSVnv (v); }
509static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 533static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
510static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 534static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
535// gcc dislikes noilnine on to_sv
511static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 536static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
537static inline SV *to_sv (object * v) { return to_sv_ni (v); }
512static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 538static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
513static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 539static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
514static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 540static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
515static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 541static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
516static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 542static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
558static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 584static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
559static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } 585static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
560static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } 586static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
561static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 587static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
562static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 588static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
563static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } 589static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); }
564static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } 590static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); }
565static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } 591static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); }
592static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull_maptile (sv); }
566static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 593static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
567static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); }
568static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 594static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
569static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 595static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
570static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 596static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
571static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 597static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
572static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 598static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
688template<class type> 714template<class type>
689static void noinline 715static void noinline
690cf_obj_to (SV *arg, type &var) 716cf_obj_to (SV *arg, type &var)
691{ 717{
692 sv_to (arg, var); 718 sv_to (arg, var);
693 if (!var) 719 if (expect_false (!var))
694 croak ("must not pass invalid/null cf_obj here"); 720 croak ("must not pass invalid/null cf_obj here");
695} 721}
696 722
697template<class object> 723template<class object>
698static void noinline 724static void noinline
699cf_obj_ornull_to (SV *arg, object *&var) 725cf_obj_ornull_to (SV *arg, object *&var)
700{ 726{
701 if (SvOK (arg)) 727 if (SvOK (arg))
702 { 728 {
703 sv_to (arg, var); 729 sv_to (arg, var);
704 if (!var) 730 if (expect_false (!var))
705 croak ("unable to convert perl object to C++ object"); 731 croak ("unable to convert perl object to C++ object");
706 } 732 }
707 else 733 else
708 var = 0; 734 var = 0;
709} 735}
744 exit (EXIT_FAILURE); 770 exit (EXIT_FAILURE);
745 } 771 }
746 772
747 eval_pv ( 773 eval_pv (
748 "#line 1 'cfperl init'\n" 774 "#line 1 'cfperl init'\n"
749 "use EV ();\n" 775 "use EV ();\n" // required by bootstrap
750 "use Coro ();\n" 776 "use Coro ();\n" // required by bootstrap
751 "cf->bootstrap;\n" 777 "cf->bootstrap;\n" // required for cf::datadir
752 "unshift @INC, cf::datadir ();\n" 778 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
753 "require cf;\n", 779 "require cf;\n",
754 0 780 0
755 ); 781 );
756 782
757 if (SvTRUE (ERRSV)) 783 if (SvTRUE (ERRSV))
1132 1158
1133 return retval; 1159 return retval;
1134} 1160}
1135 1161
1136maptile * 1162maptile *
1137find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty) 1163find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty, bool recurse)
1138{ 1164{
1139 CALL_BEGIN (3); 1165 CALL_BEGIN (4);
1140 CALL_ARG (dirname); 1166 CALL_ARG (dirname);
1141 CALL_ARG (stylename); 1167 CALL_ARG (stylename);
1142 CALL_ARG (difficulty); 1168 CALL_ARG (difficulty);
1169 CALL_ARG (recurse);
1143 CALL_CALL ("ext::map_random::find_style", G_SCALAR); 1170 CALL_CALL ("ext::map_random::find_style", G_SCALAR);
1144 1171
1145 maptile *retval = 0; 1172 maptile *retval = 0;
1146 if (count) sv_to (POPs, retval); 1173 if (count) sv_to (POPs, retval);
1147 1174
1370 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1397 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1371 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1398 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1372 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1399 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1373 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1400 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1374 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1401 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1402 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1375 1403
1376 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1404 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1377 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1405 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1378 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1406 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV);
1379 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1407 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1428# undef def 1456# undef def
1429# define def(uc, flags) const_iv (SK_ ## uc) 1457# define def(uc, flags) const_iv (SK_ ## uc)
1430# include "skillinc.h" 1458# include "skillinc.h"
1431# undef def 1459# undef def
1432 1460
1433 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster)
1434 const_iv (logBacktrace)
1435
1436 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1461 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1437 1462
1438 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1463 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1439 1464
1440 const_iv (MAX_TIME) 1465 const_iv (MAX_TIME)
1466 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1491 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1467 1492
1468 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1493 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1469 }; 1494 };
1470 1495
1471 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1496 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1472 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1497 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1473 1498
1474 static const struct { 1499 static const struct {
1475 const char *name; 1500 const char *name;
1476 int skip; 1501 int skip;
1482# undef def 1507# undef def
1483 }; 1508 };
1484 1509
1485 AV *av = get_av ("cf::EVENT", 1); 1510 AV *av = get_av ("cf::EVENT", 1);
1486 1511
1487 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1512 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1488 { 1513 {
1489 AV *event = newAV (); 1514 AV *event = newAV ();
1490 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1515 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1491 av_push (event, newSViv (eiv->klass)); 1516 av_push (event, newSViv (eiv->klass));
1492 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1517 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1573 1598
1574void init_anim () 1599void init_anim ()
1575 1600
1576void init_globals () 1601void init_globals ()
1577 1602
1578void init_experience ()
1579
1580void init_attackmess () 1603void init_attackmess ()
1581 1604
1582void init_dynamic () 1605void init_dynamic ()
1583 1606
1584void load_settings () 1607void load_settings ()
1585 1608
1609void reload_exp_table ()
1610
1586void load_materials () 1611void reload_materials ()
1587 1612
1588void init_uuid () 1613void init_uuid ()
1589 CODE: 1614 CODE:
1590 UUID::init (); 1615 UUID::init ();
1591 1616
1657 switch (items) 1682 switch (items)
1658 { 1683 {
1659 case 0: RETVAL = gen (); break; 1684 case 0: RETVAL = gen (); break;
1660 case 1: RETVAL = gen (SvUV (ST (0))); break; 1685 case 1: RETVAL = gen (SvUV (ST (0))); break;
1661 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1686 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1662 default: croak ("cf::rndm requires none, one or two parameters."); break; 1687 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1663 } 1688 }
1664} 1689}
1665 OUTPUT: 1690 OUTPUT:
1666 RETVAL 1691 RETVAL
1667 1692
1683 PROTOTYPE: @ 1708 PROTOTYPE: @
1684 CODE: 1709 CODE:
1685 while (items > 0) 1710 while (items > 0)
1686 sv_rvweaken (ST (--items)); 1711 sv_rvweaken (ST (--items));
1687 1712
1688void 1713void log_suspend ()
1714
1715void log_resume ()
1716
1689log_backtrace (utf8_string msg) 1717void log_backtrace (utf8_string msg)
1690 1718
1691void
1692LOG (int flags, utf8_string msg) 1719void LOG (int flags, utf8_string msg)
1693 PROTOTYPE: $$ 1720 PROTOTYPE: $$
1694 C_ARGS: flags, "%s", msg 1721 C_ARGS: flags, "%s", msg
1695 1722
1696octet_string path_combine (octet_string base, octet_string path) 1723octet_string path_combine (octet_string base, octet_string path)
1697 PROTOTYPE: $$ 1724 PROTOTYPE: $$
1789 1816
1790int random_roll (int min, int max, object *op, int goodbad); 1817int random_roll (int min, int max, object *op, int goodbad);
1791 1818
1792const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1819const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1793 1820
1794int
1795exp_to_level (val64 exp) 1821int exp_to_level (val64 exp)
1796 CODE:
1797{
1798 int i = 0;
1799 1822
1800 RETVAL = settings.max_level;
1801
1802 for (i = 1; i <= settings.max_level; i++)
1803 {
1804 if (levels[i] > exp)
1805 {
1806 RETVAL = i - 1;
1807 break;
1808 }
1809 }
1810}
1811 OUTPUT: RETVAL
1812
1813val64
1814level_to_min_exp (int level) 1823val64 level_to_min_exp (int level)
1815 CODE:
1816 if (level > settings.max_level)
1817 RETVAL = levels[settings.max_level];
1818 else if (level < 1)
1819 RETVAL = 0;
1820 else
1821 RETVAL = levels[level];
1822 OUTPUT: RETVAL
1823 1824
1824SV * 1825SV *
1825resistance_to_string (int atnr) 1826resistance_to_string (int atnr)
1826 CODE: 1827 CODE:
1827 if (atnr >= 0 && atnr < NROFATTACKS) 1828 if (atnr >= 0 && atnr < NROFATTACKS)
1885 CODE: 1886 CODE:
1886 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1887 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1887 OUTPUT: 1888 OUTPUT:
1888 RETVAL 1889 RETVAL
1889 1890
1891bool should_invoke (attachable *obj, int event)
1892 CODE:
1893 RETVAL = obj->should_invoke ((event_type)event);
1894 OUTPUT: RETVAL
1895
1890void 1896void
1891debug_trace (attachable *obj, bool on = true) 1897debug_trace (attachable *obj, bool on = true)
1892 CODE: 1898 CODE:
1893 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1899 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1894 if (on) 1900 if (on)
2019 OUTPUT: 2025 OUTPUT:
2020 RETVAL 2026 RETVAL
2021 2027
2022object *find_best_object_match (object *op, utf8_string match) 2028object *find_best_object_match (object *op, utf8_string match)
2023 2029
2024object *find_marked_object (object *op)
2025
2026int need_identify (object *obj);
2027
2028int apply_shop_mat (object *shop_mat, object *op); 2030int apply_shop_mat (object *shop_mat, object *op);
2029 2031
2030int move (object *op, int dir, object *originator = op) 2032int move (object *op, int dir, object *originator = op)
2031 CODE: 2033 CODE:
2032 RETVAL = op->move (dir, originator); 2034 RETVAL = op->move (dir, originator);
2084 2086
2085void pick_up (object *who, object *op) 2087void pick_up (object *who, object *op)
2086 2088
2087void update_object (object *op, int action) 2089void update_object (object *op, int action)
2088 2090
2089void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2091void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2090 2092
2091void player_lvl_adj (object *who, object *skill = 0) 2093void player_lvl_adj (object *who, object *skill = 0)
2092 2094
2093int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2095int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2094 2096
2157 PROTOTYPE: $$;$ 2159 PROTOTYPE: $$;$
2158 PPCODE: 2160 PPCODE:
2159{ 2161{
2160 rv_vector rv; 2162 rv_vector rv;
2161 2163
2162 PUTBACK;
2163 get_rangevector (ob, other, &rv, flags); 2164 get_rangevector (ob, other, &rv, flags);
2164 SPAGAIN;
2165 2165
2166 EXTEND (SP, 5); 2166 EXTEND (SP, 5);
2167 PUSHs (newSVuv (rv.distance)); 2167 PUSHs (sv_2mortal (newSVuv (rv.distance)));
2168 PUSHs (newSViv (rv.distance_x)); 2168 PUSHs (sv_2mortal (newSViv (rv.distance_x)));
2169 PUSHs (newSViv (rv.distance_y)); 2169 PUSHs (sv_2mortal (newSViv (rv.distance_y)));
2170 PUSHs (newSViv (rv.direction)); 2170 PUSHs (sv_2mortal (newSViv (rv.direction)));
2171 PUSHs (to_sv (rv.part)); 2171 PUSHs (sv_2mortal (to_sv (rv.part)));
2172} 2172}
2173 2173
2174bool on_same_map_as (object *ob, object *other) 2174bool on_same_map_as (object *ob, object *other)
2175 CODE: 2175 CODE:
2176 RETVAL = on_same_map (ob, other); 2176 RETVAL = on_same_map (ob, other);
2461 if (oblinkpt *obp = map->find_link (connection)) 2461 if (oblinkpt *obp = map->find_link (connection))
2462 for (objectlink *ol = obp->link; ol; ol = ol->next) 2462 for (objectlink *ol = obp->link; ol; ol = ol->next)
2463 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2463 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2464 2464
2465void 2465void
2466get_map_flags (maptile *map, int x, int y) 2466xy_normalise (maptile *map, int x, int y, int dir = 0)
2467 PPCODE: 2467 PPCODE:
2468{ 2468{
2469 maptile *nmap = 0; 2469 mapxy pos (map, x, y);
2470 I16 nx = 0, ny = 0; 2470 if (!pos.move (dir).normalise ())
2471 XSRETURN_EMPTY;
2471 2472
2472 PUTBACK;
2473 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2474 SPAGAIN;
2475
2476 EXTEND (SP, 4); 2473 EXTEND (SP, 3);
2477 PUSHs (sv_2mortal (newSViv (flags)));
2478
2479 if (GIMME_V == G_ARRAY)
2480 {
2481 PUSHs (sv_2mortal (to_sv (nmap))); 2474 PUSHs (sv_2mortal (to_sv (pos.m)));
2482 PUSHs (sv_2mortal (newSViv (nx))); 2475 PUSHs (sv_2mortal (to_sv (pos.x)));
2483 PUSHs (sv_2mortal (newSViv (ny))); 2476 PUSHs (sv_2mortal (to_sv (pos.y)));
2484 }
2485} 2477}
2486 2478
2487mapspace * 2479mapspace *
2488ms (maptile *map, unsigned int x, unsigned int y) 2480ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2489 PROTOTYPE: $$$ 2481 PROTOTYPE: $$$;$
2490 CODE: 2482 CODE:
2491{ 2483{
2492 maptile *nmap = 0; 2484 mapxy pos (map, x, y);
2493 I16 nx, ny; 2485 if (!pos.move (dir).normalise ())
2494
2495 PUTBACK;
2496 get_map_flags (map, &nmap, x, y, &nx, &ny);
2497 SPAGAIN;
2498
2499 if (!nmap)
2500 XSRETURN_UNDEF; 2486 XSRETURN_UNDEF;
2501 2487
2502 RETVAL = &nmap->at (nx, ny); 2488 RETVAL = &*pos;
2503} 2489}
2504 OUTPUT: 2490 OUTPUT:
2505 RETVAL 2491 RETVAL
2506 2492
2507void 2493void
2508at (maptile *map, unsigned int x, unsigned int y) 2494at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2509 PROTOTYPE: $$$ 2495 PROTOTYPE: $$$;$
2510 PPCODE: 2496 PPCODE:
2511{ 2497 mapxy pos (map, x, y);
2512 maptile *nmap = 0; 2498 if (pos.move (dir).normalise ())
2513 I16 nx, ny;
2514
2515 PUTBACK;
2516 get_map_flags (map, &nmap, x, y, &nx, &ny);
2517 SPAGAIN;
2518
2519 if (nmap)
2520 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2499 for (object *o = pos->bot; o; o = o->above)
2521 XPUSHs (sv_2mortal (to_sv (o))); 2500 XPUSHs (sv_2mortal (to_sv (o)));
2522}
2523 2501
2524SV * 2502SV *
2525bot_at (maptile *map, unsigned int x, unsigned int y) 2503bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2526 PROTOTYPE: $$$ 2504 PROTOTYPE: $$$;$
2527 ALIAS: 2505 ALIAS:
2528 top_at = 1 2506 top_at = 1
2529 flags_at = 2 2507 flags_at = 2
2530 light_at = 3 2508 light_at = 3
2531 move_block_at = 4 2509 move_block_at = 4
2532 move_slow_at = 5 2510 move_slow_at = 5
2533 move_on_at = 6 2511 move_on_at = 6
2534 move_off_at = 7 2512 move_off_at = 7
2535 CODE: 2513 CODE:
2536{ 2514{
2537 sint16 nx = x; 2515 mapxy pos (map, x, y);
2538 sint16 ny = y; 2516 if (!pos.move (dir).normalise ())
2539
2540 if (!xy_normalise (map, nx, ny))
2541 XSRETURN_UNDEF; 2517 XSRETURN_UNDEF;
2542 2518
2543 mapspace &ms = map->at (nx, ny); 2519 mapspace &ms = *pos;
2544 2520
2545 ms.update (); 2521 ms.update ();
2546 2522
2547 switch (ix) 2523 switch (ix)
2548 { 2524 {
2560 2536
2561# worst xs function of my life 2537# worst xs function of my life
2562bool 2538bool
2563_create_random_map (\ 2539_create_random_map (\
2564 maptile *self,\ 2540 maptile *self,\
2565 utf8_string wallstyle,\ 2541 SV *options,\
2566 utf8_string wall_name,\
2567 utf8_string floorstyle,\
2568 utf8_string monsterstyle,\
2569 utf8_string treasurestyle,\
2570 utf8_string layoutstyle,\
2571 utf8_string doorstyle,\
2572 utf8_string decorstyle,\
2573 utf8_string miningstyle,\
2574 utf8_string origin_map,\
2575 utf8_string final_map,\
2576 utf8_string exitstyle,\
2577 utf8_string this_map,\
2578 utf8_string exit_on_final_map,\
2579 int xsize,\
2580 int ysize,\
2581 int expand2x,\
2582 int layoutoptions1,\
2583 int layoutoptions2,\
2584 int layoutoptions3,\
2585 int symmetry,\
2586 int difficulty,\
2587 int difficulty_given,\
2588 float difficulty_increase,\
2589 int dungeon_level,\
2590 int dungeon_depth,\
2591 int decoroptions,\
2592 int orientation,\
2593 int origin_y,\
2594 int origin_x,\
2595 U32 random_seed,\
2596 val64 total_map_hp,\ 2542 val64 total_map_hp,\
2597 int map_layout_style,\
2598 int treasureoptions,\
2599 int symmetry_used,\
2600 region *region,\ 2543 region *region\
2601 utf8_string custom\
2602) 2544)
2603 CODE: 2545 CODE:
2604{ 2546{
2605 random_map_params rmp; 2547 random_map_params rmp;
2606 2548
2607 assign (rmp.wallstyle , wallstyle); 2549 rmp.hv = (HV *)SvREFCNT_inc_NN (SvRV (options));
2550
2608 assign (rmp.wall_name , wall_name); 2551 assign (rmp.wall_name , rmp.get_str ("wall_name"));
2609 assign (rmp.floorstyle , floorstyle);
2610 assign (rmp.monsterstyle , monsterstyle); 2552 assign (rmp.monsterstyle , rmp.get_str ("monsterstyle"));
2611 assign (rmp.treasurestyle , treasurestyle);
2612 assign (rmp.layoutstyle , layoutstyle); 2553 assign (rmp.layoutstyle , rmp.get_str ("layoutstyle"));
2613 assign (rmp.doorstyle , doorstyle); 2554 assign (rmp.doorstyle , rmp.get_str ("doorstyle"));
2614 assign (rmp.decorstyle , decorstyle);
2615 assign (rmp.miningstyle , miningstyle);
2616 assign (rmp.exitstyle , exitstyle);
2617 assign (rmp.exit_on_final_map, exit_on_final_map); 2555 assign (rmp.exit_on_final_map, rmp.get_str ("exit_on_final_map"));
2618 2556
2619 rmp.origin_map = origin_map; 2557 rmp.origin_map = rmp.get_str ("origin_map");
2558 rmp.origin_x = rmp.get_iv ("origin_x");
2559 rmp.origin_y = rmp.get_iv ("origin_y");
2620 rmp.final_map = final_map; 2560 rmp.final_map = rmp.get_str ("final_map");
2621 rmp.this_map = this_map; 2561 rmp.this_map = rmp.get_str ("this_map");
2622 rmp.xsize = xsize; 2562 rmp.xsize = rmp.get_iv ("xsize");
2623 rmp.ysize = ysize; 2563 rmp.ysize = rmp.get_iv ("ysize");
2624 rmp.expand2x = expand2x; 2564 rmp.expand2x = rmp.get_iv ("expand2x");
2625 rmp.layoutoptions1 = layoutoptions1; 2565 rmp.layoutoptions1 = rmp.get_iv ("layoutoptions1");
2626 rmp.layoutoptions2 = layoutoptions2; 2566 rmp.layoutoptions2 = rmp.get_iv ("layoutoptions2");
2627 rmp.layoutoptions3 = layoutoptions3; 2567 rmp.layoutoptions3 = rmp.get_iv ("layoutoptions3");
2628 rmp.symmetry = symmetry; 2568 rmp.symmetry = rmp.get_iv ("symmetry");
2629 rmp.difficulty = difficulty; 2569 rmp.difficulty = rmp.get_iv ("difficulty");
2630 rmp.difficulty_given = difficulty_given; 2570 rmp.difficulty_given = rmp.get_iv ("difficulty_given");
2631 rmp.difficulty_increase = difficulty_increase; 2571 rmp.difficulty_increase = rmp.get_nv ("difficulty_increase");
2632 rmp.dungeon_level = dungeon_level; 2572 rmp.dungeon_level = rmp.get_iv ("dungeon_level");
2633 rmp.dungeon_depth = dungeon_depth; 2573 rmp.dungeon_depth = rmp.get_iv ("dungeon_depth");
2634 rmp.decoroptions = decoroptions;
2635 rmp.orientation = orientation; 2574 rmp.orientation = rmp.get_iv ("orientation");
2636 rmp.origin_y = origin_y;
2637 rmp.origin_x = origin_x;
2638 rmp.random_seed = random_seed; 2575 rmp.random_seed = rmp.get_uv ("random_seed");
2639 rmp.total_map_hp = (uint64_t) total_map_hp; 2576 rmp.total_map_hp = (uint64_t)total_map_hp;
2640 rmp.map_layout_style = map_layout_style; 2577 rmp.map_layout_style = rmp.get_iv ("map_layout_style");
2641 rmp.treasureoptions = treasureoptions;
2642 rmp.symmetry_used = symmetry_used; 2578 rmp.symmetry_used = rmp.get_iv ("symmetry_used");
2643 rmp.region = region; 2579 rmp.region = region;
2644 rmp.custom = custom;
2645 2580
2646 RETVAL = self->generate_random_map (&rmp); 2581 RETVAL = self->generate_random_map (&rmp);
2647} 2582}
2648 OUTPUT: 2583 OUTPUT:
2649 RETVAL 2584 RETVAL
2681void 2616void
2682list () 2617list ()
2683 PPCODE: 2618 PPCODE:
2684 for_all_regions (rgn) 2619 for_all_regions (rgn)
2685 XPUSHs (sv_2mortal (to_sv (rgn))); 2620 XPUSHs (sv_2mortal (to_sv (rgn)));
2686
2687region *find (utf8_string name)
2688 PROTOTYPE: $
2689 CODE:
2690 RETVAL = region::find (name);
2691 OUTPUT: RETVAL
2692 2621
2693int specificity (region *rgn) 2622int specificity (region *rgn)
2694 CODE: 2623 CODE:
2695 RETVAL = 0; 2624 RETVAL = 0;
2696 while (rgn = rgn->parent) 2625 while (rgn = rgn->parent)
2800 while (!RETVAL); // crude way to leave index 0 2729 while (!RETVAL); // crude way to leave index 0
2801 2730
2802 faces [RETVAL].name = name; 2731 faces [RETVAL].name = name;
2803 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2732 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2804 2733
2805 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2734 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2806 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2735 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2736 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2807} 2737}
2808 OUTPUT: RETVAL 2738 OUTPUT: RETVAL
2809 2739
2810void set_type (faceidx idx, int value) 2740void set_type (faceidx idx, int value)
2811 ALIAS: 2741 ALIAS:
2945 sv_to (sv, self); 2875 sv_to (sv, self);
2946 delete self; 2876 delete self;
2947 2877
2948MODULE = cf PACKAGE = cf::object::thawer 2878MODULE = cf PACKAGE = cf::object::thawer
2949 2879
2950INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | 2880INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h |
2881
2882bool
2883errors_are_fatal (bool fatal)
2884 CODE:
2885 RETVAL = object_thawer::errors_are_fatal;
2886 object_thawer::errors_are_fatal = fatal;
2887 OUTPUT:
2888 RETVAL
2951 2889
2952SV * 2890SV *
2953new_from_file (char *klass, octet_string path) 2891new_from_file (char *klass, octet_string path)
2954 CODE: 2892 CODE:
2955 object_thawer *f = new object_thawer (path); 2893 object_thawer *f = new object_thawer (path);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines