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.362 by root, Thu Apr 8 19:31:22 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
1224object::ref () const 1251object::ref () const
1225{ 1252{
1226 if (type == PLAYER) 1253 if (type == PLAYER)
1227 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); 1254 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name);
1228 else 1255 else
1256 // TODO: should be able to save references within the same map, at least
1229 return 0; 1257 return 0;
1230} 1258}
1231 1259
1232object * 1260object *
1233object::deref (const_utf8_string ref) 1261object::deref (const_utf8_string ref)
1369 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1397 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1370 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1398 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1371 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1399 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1372 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1400 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1373 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);
1374 1403
1375 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);
1376 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);
1377 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);
1378 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);
1427# undef def 1456# undef def
1428# define def(uc, flags) const_iv (SK_ ## uc) 1457# define def(uc, flags) const_iv (SK_ ## uc)
1429# include "skillinc.h" 1458# include "skillinc.h"
1430# undef def 1459# undef def
1431 1460
1432 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster)
1433 const_iv (logBacktrace)
1434
1435 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1461 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1436 1462
1437 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1463 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1438 1464
1439 const_iv (MAX_TIME) 1465 const_iv (MAX_TIME)
1465 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)
1466 1492
1467 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)
1468 }; 1494 };
1469 1495
1470 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; )
1471 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1497 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1472 1498
1473 static const struct { 1499 static const struct {
1474 const char *name; 1500 const char *name;
1475 int skip; 1501 int skip;
1481# undef def 1507# undef def
1482 }; 1508 };
1483 1509
1484 AV *av = get_av ("cf::EVENT", 1); 1510 AV *av = get_av ("cf::EVENT", 1);
1485 1511
1486 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; )
1487 { 1513 {
1488 AV *event = newAV (); 1514 AV *event = newAV ();
1489 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1515 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1490 av_push (event, newSViv (eiv->klass)); 1516 av_push (event, newSViv (eiv->klass));
1491 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1517 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1572 1598
1573void init_anim () 1599void init_anim ()
1574 1600
1575void init_globals () 1601void init_globals ()
1576 1602
1577void init_experience ()
1578
1579void init_attackmess () 1603void init_attackmess ()
1580 1604
1581void init_dynamic () 1605void init_dynamic ()
1582 1606
1583void load_settings () 1607void load_settings ()
1584 1608
1609void reload_exp_table ()
1610
1585void load_materials () 1611void reload_materials ()
1586 1612
1587void init_uuid () 1613void init_uuid ()
1588 CODE: 1614 CODE:
1589 UUID::init (); 1615 UUID::init ();
1590 1616
1656 switch (items) 1682 switch (items)
1657 { 1683 {
1658 case 0: RETVAL = gen (); break; 1684 case 0: RETVAL = gen (); break;
1659 case 1: RETVAL = gen (SvUV (ST (0))); break; 1685 case 1: RETVAL = gen (SvUV (ST (0))); break;
1660 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1686 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1661 default: croak ("cf::rndm requires none, one or two parameters."); break; 1687 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1662 } 1688 }
1663} 1689}
1664 OUTPUT: 1690 OUTPUT:
1665 RETVAL 1691 RETVAL
1666 1692
1682 PROTOTYPE: @ 1708 PROTOTYPE: @
1683 CODE: 1709 CODE:
1684 while (items > 0) 1710 while (items > 0)
1685 sv_rvweaken (ST (--items)); 1711 sv_rvweaken (ST (--items));
1686 1712
1687void 1713void log_suspend ()
1714
1715void log_resume ()
1716
1688log_backtrace (utf8_string msg) 1717void log_backtrace (utf8_string msg)
1689 1718
1690void
1691LOG (int flags, utf8_string msg) 1719void LOG (int flags, utf8_string msg)
1692 PROTOTYPE: $$ 1720 PROTOTYPE: $$
1693 C_ARGS: flags, "%s", msg 1721 C_ARGS: flags, "%s", msg
1694 1722
1695octet_string path_combine (octet_string base, octet_string path) 1723octet_string path_combine (octet_string base, octet_string path)
1696 PROTOTYPE: $$ 1724 PROTOTYPE: $$
1788 1816
1789int random_roll (int min, int max, object *op, int goodbad); 1817int random_roll (int min, int max, object *op, int goodbad);
1790 1818
1791const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1819const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1792 1820
1793int
1794exp_to_level (val64 exp) 1821int exp_to_level (val64 exp)
1795 CODE:
1796{
1797 int i = 0;
1798 1822
1799 RETVAL = settings.max_level;
1800
1801 for (i = 1; i <= settings.max_level; i++)
1802 {
1803 if (levels[i] > exp)
1804 {
1805 RETVAL = i - 1;
1806 break;
1807 }
1808 }
1809}
1810 OUTPUT: RETVAL
1811
1812val64
1813level_to_min_exp (int level) 1823val64 level_to_min_exp (int level)
1814 CODE:
1815 if (level > settings.max_level)
1816 RETVAL = levels[settings.max_level];
1817 else if (level < 1)
1818 RETVAL = 0;
1819 else
1820 RETVAL = levels[level];
1821 OUTPUT: RETVAL
1822 1824
1823SV * 1825SV *
1824resistance_to_string (int atnr) 1826resistance_to_string (int atnr)
1825 CODE: 1827 CODE:
1826 if (atnr >= 0 && atnr < NROFATTACKS) 1828 if (atnr >= 0 && atnr < NROFATTACKS)
1884 CODE: 1886 CODE:
1885 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1887 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1886 OUTPUT: 1888 OUTPUT:
1887 RETVAL 1889 RETVAL
1888 1890
1891bool should_invoke (attachable *obj, int event)
1892 CODE:
1893 RETVAL = obj->should_invoke ((event_type)event);
1894 OUTPUT: RETVAL
1895
1889void 1896void
1890debug_trace (attachable *obj, bool on = true) 1897debug_trace (attachable *obj, bool on = true)
1891 CODE: 1898 CODE:
1892 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1899 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1893 if (on) 1900 if (on)
2018 OUTPUT: 2025 OUTPUT:
2019 RETVAL 2026 RETVAL
2020 2027
2021object *find_best_object_match (object *op, utf8_string match) 2028object *find_best_object_match (object *op, utf8_string match)
2022 2029
2023object *find_marked_object (object *op)
2024
2025int need_identify (object *obj);
2026
2027int apply_shop_mat (object *shop_mat, object *op); 2030int apply_shop_mat (object *shop_mat, object *op);
2028 2031
2029int move (object *op, int dir, object *originator = op) 2032int move (object *op, int dir, object *originator = op)
2030 CODE: 2033 CODE:
2031 RETVAL = op->move (dir, originator); 2034 RETVAL = op->move (dir, originator);
2083 2086
2084void pick_up (object *who, object *op) 2087void pick_up (object *who, object *op)
2085 2088
2086void update_object (object *op, int action) 2089void update_object (object *op, int action)
2087 2090
2088void 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)
2089 2092
2090void player_lvl_adj (object *who, object *skill = 0) 2093void player_lvl_adj (object *who, object *skill = 0)
2091 2094
2092int 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)
2093 2096
2156 PROTOTYPE: $$;$ 2159 PROTOTYPE: $$;$
2157 PPCODE: 2160 PPCODE:
2158{ 2161{
2159 rv_vector rv; 2162 rv_vector rv;
2160 2163
2161 PUTBACK;
2162 get_rangevector (ob, other, &rv, flags); 2164 get_rangevector (ob, other, &rv, flags);
2163 SPAGAIN;
2164 2165
2165 EXTEND (SP, 5); 2166 EXTEND (SP, 5);
2166 PUSHs (newSVuv (rv.distance)); 2167 PUSHs (sv_2mortal (newSVuv (rv.distance)));
2167 PUSHs (newSViv (rv.distance_x)); 2168 PUSHs (sv_2mortal (newSViv (rv.distance_x)));
2168 PUSHs (newSViv (rv.distance_y)); 2169 PUSHs (sv_2mortal (newSViv (rv.distance_y)));
2169 PUSHs (newSViv (rv.direction)); 2170 PUSHs (sv_2mortal (newSViv (rv.direction)));
2170 PUSHs (to_sv (rv.part)); 2171 PUSHs (sv_2mortal (to_sv (rv.part)));
2171} 2172}
2172 2173
2173bool on_same_map_as (object *ob, object *other) 2174bool on_same_map_as (object *ob, object *other)
2174 CODE: 2175 CODE:
2175 RETVAL = on_same_map (ob, other); 2176 RETVAL = on_same_map (ob, other);
2460 if (oblinkpt *obp = map->find_link (connection)) 2461 if (oblinkpt *obp = map->find_link (connection))
2461 for (objectlink *ol = obp->link; ol; ol = ol->next) 2462 for (objectlink *ol = obp->link; ol; ol = ol->next)
2462 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2463 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2463 2464
2464void 2465void
2465get_map_flags (maptile *map, int x, int y) 2466xy_normalise (maptile *map, int x, int y, int dir = 0)
2466 PPCODE: 2467 PPCODE:
2467{ 2468{
2468 maptile *nmap = 0; 2469 mapxy pos (map, x, y);
2469 I16 nx = 0, ny = 0; 2470 if (!pos.move (dir).normalise ())
2471 XSRETURN_EMPTY;
2470 2472
2471 PUTBACK;
2472 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2473 SPAGAIN;
2474
2475 EXTEND (SP, 4); 2473 EXTEND (SP, 3);
2476 PUSHs (sv_2mortal (newSViv (flags)));
2477
2478 if (GIMME_V == G_ARRAY)
2479 {
2480 PUSHs (sv_2mortal (to_sv (nmap))); 2474 PUSHs (sv_2mortal (to_sv (pos.m)));
2481 PUSHs (sv_2mortal (newSViv (nx))); 2475 PUSHs (sv_2mortal (to_sv (pos.x)));
2482 PUSHs (sv_2mortal (newSViv (ny))); 2476 PUSHs (sv_2mortal (to_sv (pos.y)));
2483 }
2484} 2477}
2485 2478
2486mapspace * 2479mapspace *
2487ms (maptile *map, unsigned int x, unsigned int y) 2480ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2488 PROTOTYPE: $$$ 2481 PROTOTYPE: $$$;$
2489 CODE: 2482 CODE:
2490{ 2483{
2491 maptile *nmap = 0; 2484 mapxy pos (map, x, y);
2492 I16 nx, ny; 2485 if (!pos.move (dir).normalise ())
2493
2494 PUTBACK;
2495 get_map_flags (map, &nmap, x, y, &nx, &ny);
2496 SPAGAIN;
2497
2498 if (!nmap)
2499 XSRETURN_UNDEF; 2486 XSRETURN_UNDEF;
2500 2487
2501 RETVAL = &nmap->at (nx, ny); 2488 RETVAL = &*pos;
2502} 2489}
2503 OUTPUT: 2490 OUTPUT:
2504 RETVAL 2491 RETVAL
2505 2492
2506void 2493void
2507at (maptile *map, unsigned int x, unsigned int y) 2494at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2508 PROTOTYPE: $$$ 2495 PROTOTYPE: $$$;$
2509 PPCODE: 2496 PPCODE:
2510{ 2497 mapxy pos (map, x, y);
2511 maptile *nmap = 0; 2498 if (pos.move (dir).normalise ())
2512 I16 nx, ny;
2513
2514 PUTBACK;
2515 get_map_flags (map, &nmap, x, y, &nx, &ny);
2516 SPAGAIN;
2517
2518 if (nmap)
2519 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2499 for (object *o = pos->bot; o; o = o->above)
2520 XPUSHs (sv_2mortal (to_sv (o))); 2500 XPUSHs (sv_2mortal (to_sv (o)));
2521}
2522 2501
2523SV * 2502SV *
2524bot_at (maptile *map, unsigned int x, unsigned int y) 2503bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2525 PROTOTYPE: $$$ 2504 PROTOTYPE: $$$;$
2526 ALIAS: 2505 ALIAS:
2527 top_at = 1 2506 top_at = 1
2528 flags_at = 2 2507 flags_at = 2
2529 light_at = 3 2508 light_at = 3
2530 move_block_at = 4 2509 move_block_at = 4
2531 move_slow_at = 5 2510 move_slow_at = 5
2532 move_on_at = 6 2511 move_on_at = 6
2533 move_off_at = 7 2512 move_off_at = 7
2534 CODE: 2513 CODE:
2535{ 2514{
2536 sint16 nx = x; 2515 mapxy pos (map, x, y);
2537 sint16 ny = y; 2516 if (!pos.move (dir).normalise ())
2538
2539 if (!xy_normalise (map, nx, ny))
2540 XSRETURN_UNDEF; 2517 XSRETURN_UNDEF;
2541 2518
2542 mapspace &ms = map->at (nx, ny); 2519 mapspace &ms = *pos;
2543 2520
2544 ms.update (); 2521 ms.update ();
2545 2522
2546 switch (ix) 2523 switch (ix)
2547 { 2524 {
2559 2536
2560# worst xs function of my life 2537# worst xs function of my life
2561bool 2538bool
2562_create_random_map (\ 2539_create_random_map (\
2563 maptile *self,\ 2540 maptile *self,\
2564 utf8_string wallstyle,\ 2541 SV *options,\
2565 utf8_string wall_name,\
2566 utf8_string floorstyle,\
2567 utf8_string monsterstyle,\
2568 utf8_string treasurestyle,\
2569 utf8_string layoutstyle,\
2570 utf8_string doorstyle,\
2571 utf8_string decorstyle,\
2572 utf8_string miningstyle,\
2573 utf8_string origin_map,\
2574 utf8_string final_map,\
2575 utf8_string exitstyle,\
2576 utf8_string this_map,\
2577 utf8_string exit_on_final_map,\
2578 int xsize,\
2579 int ysize,\
2580 int expand2x,\
2581 int layoutoptions1,\
2582 int layoutoptions2,\
2583 int layoutoptions3,\
2584 int symmetry,\
2585 int difficulty,\
2586 int difficulty_given,\
2587 float difficulty_increase,\
2588 int dungeon_level,\
2589 int dungeon_depth,\
2590 int decoroptions,\
2591 int orientation,\
2592 int origin_y,\
2593 int origin_x,\
2594 U32 random_seed,\
2595 val64 total_map_hp,\ 2542 val64 total_map_hp,\
2596 int map_layout_style,\
2597 int treasureoptions,\
2598 int symmetry_used,\
2599 region *region,\ 2543 region *region\
2600 utf8_string custom\
2601) 2544)
2602 CODE: 2545 CODE:
2603{ 2546{
2604 random_map_params rmp; 2547 random_map_params rmp;
2605 2548
2606 assign (rmp.wallstyle , wallstyle); 2549 rmp.hv = (HV *)SvREFCNT_inc_NN (SvRV (options));
2550
2607 assign (rmp.wall_name , wall_name); 2551 assign (rmp.wall_name , rmp.get_str ("wall_name"));
2608 assign (rmp.floorstyle , floorstyle);
2609 assign (rmp.monsterstyle , monsterstyle); 2552 assign (rmp.monsterstyle , rmp.get_str ("monsterstyle"));
2610 assign (rmp.treasurestyle , treasurestyle);
2611 assign (rmp.layoutstyle , layoutstyle); 2553 assign (rmp.layoutstyle , rmp.get_str ("layoutstyle"));
2612 assign (rmp.doorstyle , doorstyle); 2554 assign (rmp.doorstyle , rmp.get_str ("doorstyle"));
2613 assign (rmp.decorstyle , decorstyle);
2614 assign (rmp.miningstyle , miningstyle);
2615 assign (rmp.exitstyle , exitstyle);
2616 assign (rmp.exit_on_final_map, exit_on_final_map); 2555 assign (rmp.exit_on_final_map, rmp.get_str ("exit_on_final_map"));
2617 2556
2618 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");
2619 rmp.final_map = final_map; 2560 rmp.final_map = rmp.get_str ("final_map");
2620 rmp.this_map = this_map; 2561 rmp.this_map = rmp.get_str ("this_map");
2621 rmp.xsize = xsize; 2562 rmp.xsize = rmp.get_iv ("xsize");
2622 rmp.ysize = ysize; 2563 rmp.ysize = rmp.get_iv ("ysize");
2623 rmp.expand2x = expand2x; 2564 rmp.expand2x = rmp.get_iv ("expand2x");
2624 rmp.layoutoptions1 = layoutoptions1; 2565 rmp.layoutoptions1 = rmp.get_iv ("layoutoptions1");
2625 rmp.layoutoptions2 = layoutoptions2; 2566 rmp.layoutoptions2 = rmp.get_iv ("layoutoptions2");
2626 rmp.layoutoptions3 = layoutoptions3; 2567 rmp.layoutoptions3 = rmp.get_iv ("layoutoptions3");
2627 rmp.symmetry = symmetry; 2568 rmp.symmetry = rmp.get_iv ("symmetry");
2628 rmp.difficulty = difficulty; 2569 rmp.difficulty = rmp.get_iv ("difficulty");
2629 rmp.difficulty_given = difficulty_given; 2570 rmp.difficulty_given = rmp.get_iv ("difficulty_given");
2630 rmp.difficulty_increase = difficulty_increase; 2571 rmp.difficulty_increase = rmp.get_nv ("difficulty_increase");
2631 rmp.dungeon_level = dungeon_level; 2572 rmp.dungeon_level = rmp.get_iv ("dungeon_level");
2632 rmp.dungeon_depth = dungeon_depth; 2573 rmp.dungeon_depth = rmp.get_iv ("dungeon_depth");
2633 rmp.decoroptions = decoroptions;
2634 rmp.orientation = orientation; 2574 rmp.orientation = rmp.get_iv ("orientation");
2635 rmp.origin_y = origin_y;
2636 rmp.origin_x = origin_x;
2637 rmp.random_seed = random_seed; 2575 rmp.random_seed = rmp.get_uv ("random_seed");
2638 rmp.total_map_hp = (uint64_t) total_map_hp; 2576 rmp.total_map_hp = (uint64_t)total_map_hp;
2639 rmp.map_layout_style = map_layout_style; 2577 rmp.map_layout_style = rmp.get_iv ("map_layout_style");
2640 rmp.treasureoptions = treasureoptions;
2641 rmp.symmetry_used = symmetry_used; 2578 rmp.symmetry_used = rmp.get_iv ("symmetry_used");
2642 rmp.region = region; 2579 rmp.region = region;
2643 rmp.custom = custom;
2644 2580
2645 RETVAL = self->generate_random_map (&rmp); 2581 RETVAL = self->generate_random_map (&rmp);
2646} 2582}
2647 OUTPUT: 2583 OUTPUT:
2648 RETVAL 2584 RETVAL
2680void 2616void
2681list () 2617list ()
2682 PPCODE: 2618 PPCODE:
2683 for_all_regions (rgn) 2619 for_all_regions (rgn)
2684 XPUSHs (sv_2mortal (to_sv (rgn))); 2620 XPUSHs (sv_2mortal (to_sv (rgn)));
2685
2686region *find (utf8_string name)
2687 PROTOTYPE: $
2688 CODE:
2689 RETVAL = region::find (name);
2690 OUTPUT: RETVAL
2691 2621
2692int specificity (region *rgn) 2622int specificity (region *rgn)
2693 CODE: 2623 CODE:
2694 RETVAL = 0; 2624 RETVAL = 0;
2695 while (rgn = rgn->parent) 2625 while (rgn = rgn->parent)
2799 while (!RETVAL); // crude way to leave index 0 2729 while (!RETVAL); // crude way to leave index 0
2800 2730
2801 faces [RETVAL].name = name; 2731 faces [RETVAL].name = name;
2802 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2732 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2803 2733
2804 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2734 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2805 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;
2806} 2737}
2807 OUTPUT: RETVAL 2738 OUTPUT: RETVAL
2808 2739
2809void set_type (faceidx idx, int value) 2740void set_type (faceidx idx, int value)
2810 ALIAS: 2741 ALIAS:
2944 sv_to (sv, self); 2875 sv_to (sv, self);
2945 delete self; 2876 delete self;
2946 2877
2947MODULE = cf PACKAGE = cf::object::thawer 2878MODULE = cf PACKAGE = cf::object::thawer
2948 2879
2949INCLUDE: $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
2950 2889
2951SV * 2890SV *
2952new_from_file (char *klass, octet_string path) 2891new_from_file (char *klass, octet_string path)
2953 CODE: 2892 CODE:
2954 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