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.360 by root, Mon Apr 5 20:33:13 2010 UTC vs.
Revision 1.384 by root, Fri Apr 30 21:00:40 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,
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; 359 SV *sv;
354 360
355 if (!ptr) 361 if (!ptr)
356 return newSV (0); 362 return newSV (0);
357 363
358 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);
359 return sv_bless (newRV_noinc ((SV *)hv), stash); 365 return sv_bless (newRV_noinc ((SV *)hv), stash);
366}
367
368static SV *
369newSVptr (void *ptr, HV *stash)
370{
371 return newSVptr (ptr, stash, newHV ());
360} 372}
361 373
362static int 374static int
363attachable_free (pTHX_ SV *sv, MAGIC *mg) 375attachable_free (pTHX_ SV *sv, MAGIC *mg)
364{ 376{
472 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap 484 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap
473 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap 485 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap
474 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap 486 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap
475 && !sv_derived_from (sv, "cf::object"))) 487 && !sv_derived_from (sv, "cf::object")))
476 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");
477 503
478 return SvPTR_nc (sv); 504 return SvPTR_nc (sv);
479} 505}
480 506
481static long noinline 507static long noinline
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)
1460 const_iv (MAP_INACTIVE) 1486 const_iv (MAP_INACTIVE)
1461 1487
1462 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1488 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT)
1463 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) 1489 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1464 1490
1465 const_iv (VERSION_CS) const_iv (VERSION_SC)
1466
1467 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)
1468 1492
1469 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)
1470 }; 1494 };
1471 1495
1472 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; )
1473 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1497 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1474 1498
1475 static const struct { 1499 static const struct {
1476 const char *name; 1500 const char *name;
1477 int skip; 1501 int skip;
1483# undef def 1507# undef def
1484 }; 1508 };
1485 1509
1486 AV *av = get_av ("cf::EVENT", 1); 1510 AV *av = get_av ("cf::EVENT", 1);
1487 1511
1488 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; )
1489 { 1513 {
1490 AV *event = newAV (); 1514 AV *event = newAV ();
1491 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1515 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1492 av_push (event, newSViv (eiv->klass)); 1516 av_push (event, newSViv (eiv->klass));
1493 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1517 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1590 CODE: 1614 CODE:
1591 UUID::init (); 1615 UUID::init ();
1592 1616
1593void init_signals () 1617void init_signals ()
1594 1618
1595void init_commands ()
1596
1597void init_skills () 1619void init_skills ()
1598 1620
1599void init_beforeplay () 1621void init_beforeplay ()
1600 1622
1601void evthread_start (int aiofd) 1623void evthread_start (int aiofd)
1660 switch (items) 1682 switch (items)
1661 { 1683 {
1662 case 0: RETVAL = gen (); break; 1684 case 0: RETVAL = gen (); break;
1663 case 1: RETVAL = gen (SvUV (ST (0))); break; 1685 case 1: RETVAL = gen (SvUV (ST (0))); break;
1664 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1686 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1665 default: croak ("cf::rndm requires none, one or two parameters."); break; 1687 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1666 } 1688 }
1667} 1689}
1668 OUTPUT: 1690 OUTPUT:
1669 RETVAL 1691 RETVAL
1670 1692
1686 PROTOTYPE: @ 1708 PROTOTYPE: @
1687 CODE: 1709 CODE:
1688 while (items > 0) 1710 while (items > 0)
1689 sv_rvweaken (ST (--items)); 1711 sv_rvweaken (ST (--items));
1690 1712
1691void 1713void log_suspend ()
1714
1715void log_resume ()
1716
1692log_backtrace (utf8_string msg) 1717void log_backtrace (utf8_string msg)
1693 1718
1694void
1695LOG (int flags, utf8_string msg) 1719void LOG (int flags, utf8_string msg)
1696 PROTOTYPE: $$ 1720 PROTOTYPE: $$
1697 C_ARGS: flags, "%s", msg 1721 C_ARGS: flags, "%s", msg
1698 1722
1699octet_string path_combine (octet_string base, octet_string path) 1723octet_string path_combine (octet_string base, octet_string path)
1700 PROTOTYPE: $$ 1724 PROTOTYPE: $$
1792 1816
1793int random_roll (int min, int max, object *op, int goodbad); 1817int random_roll (int min, int max, object *op, int goodbad);
1794 1818
1795const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1819const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1796 1820
1797int
1798exp_to_level (val64 exp) 1821int exp_to_level (val64 exp)
1799 CODE:
1800{
1801 int i = 0;
1802 1822
1803 RETVAL = settings.max_level;
1804
1805 for (i = 1; i <= settings.max_level; i++)
1806 {
1807 if (levels[i] > exp)
1808 {
1809 RETVAL = i - 1;
1810 break;
1811 }
1812 }
1813}
1814 OUTPUT: RETVAL
1815
1816val64
1817level_to_min_exp (int level) 1823val64 level_to_min_exp (int level)
1818 CODE:
1819 if (level > settings.max_level)
1820 RETVAL = levels[settings.max_level];
1821 else if (level < 1)
1822 RETVAL = 0;
1823 else
1824 RETVAL = levels[level];
1825 OUTPUT: RETVAL
1826 1824
1827SV * 1825SV *
1828resistance_to_string (int atnr) 1826resistance_to_string (int atnr)
1829 CODE: 1827 CODE:
1830 if (atnr >= 0 && atnr < NROFATTACKS) 1828 if (atnr >= 0 && atnr < NROFATTACKS)
1888 CODE: 1886 CODE:
1889 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1887 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1890 OUTPUT: 1888 OUTPUT:
1891 RETVAL 1889 RETVAL
1892 1890
1891bool should_invoke (attachable *obj, int event)
1892 CODE:
1893 RETVAL = obj->should_invoke ((event_type)event);
1894 OUTPUT: RETVAL
1895
1893void 1896void
1894debug_trace (attachable *obj, bool on = true) 1897debug_trace (attachable *obj, bool on = true)
1895 CODE: 1898 CODE:
1896 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1899 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1897 if (on) 1900 if (on)
2022 OUTPUT: 2025 OUTPUT:
2023 RETVAL 2026 RETVAL
2024 2027
2025object *find_best_object_match (object *op, utf8_string match) 2028object *find_best_object_match (object *op, utf8_string match)
2026 2029
2027object *find_marked_object (object *op)
2028
2029int need_identify (object *obj);
2030
2031int apply_shop_mat (object *shop_mat, object *op); 2030int apply_shop_mat (object *shop_mat, object *op);
2032 2031
2033int move (object *op, int dir, object *originator = op) 2032int move (object *op, int dir, object *originator = op)
2034 CODE: 2033 CODE:
2035 RETVAL = op->move (dir, originator); 2034 RETVAL = op->move (dir, originator);
2087 2086
2088void pick_up (object *who, object *op) 2087void pick_up (object *who, object *op)
2089 2088
2090void update_object (object *op, int action) 2089void update_object (object *op, int action)
2091 2090
2092void 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)
2093 2092
2094void player_lvl_adj (object *who, object *skill = 0) 2093void player_lvl_adj (object *who, object *skill = 0)
2095 2094
2096int 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)
2097 2096
2160 PROTOTYPE: $$;$ 2159 PROTOTYPE: $$;$
2161 PPCODE: 2160 PPCODE:
2162{ 2161{
2163 rv_vector rv; 2162 rv_vector rv;
2164 2163
2165 PUTBACK;
2166 get_rangevector (ob, other, &rv, flags); 2164 get_rangevector (ob, other, &rv, flags);
2167 SPAGAIN;
2168 2165
2169 EXTEND (SP, 5); 2166 EXTEND (SP, 5);
2170 PUSHs (newSVuv (rv.distance)); 2167 PUSHs (sv_2mortal (newSVuv (rv.distance)));
2171 PUSHs (newSViv (rv.distance_x)); 2168 PUSHs (sv_2mortal (newSViv (rv.distance_x)));
2172 PUSHs (newSViv (rv.distance_y)); 2169 PUSHs (sv_2mortal (newSViv (rv.distance_y)));
2173 PUSHs (newSViv (rv.direction)); 2170 PUSHs (sv_2mortal (newSViv (rv.direction)));
2174 PUSHs (to_sv (rv.part)); 2171 PUSHs (sv_2mortal (to_sv (rv.part)));
2175} 2172}
2176 2173
2177bool on_same_map_as (object *ob, object *other) 2174bool on_same_map_as (object *ob, object *other)
2178 CODE: 2175 CODE:
2179 RETVAL = on_same_map (ob, other); 2176 RETVAL = on_same_map (ob, other);
2464 if (oblinkpt *obp = map->find_link (connection)) 2461 if (oblinkpt *obp = map->find_link (connection))
2465 for (objectlink *ol = obp->link; ol; ol = ol->next) 2462 for (objectlink *ol = obp->link; ol; ol = ol->next)
2466 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2463 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2467 2464
2468void 2465void
2469get_map_flags (maptile *map, int x, int y) 2466xy_normalise (maptile *map, int x, int y, int dir = 0)
2470 PPCODE: 2467 PPCODE:
2471{ 2468{
2472 maptile *nmap = 0; 2469 mapxy pos (map, x, y);
2473 I16 nx = 0, ny = 0; 2470 if (!pos.move (dir).normalise ())
2471 XSRETURN_EMPTY;
2474 2472
2475 PUTBACK;
2476 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2477 SPAGAIN;
2478
2479 EXTEND (SP, 4); 2473 EXTEND (SP, 3);
2480 PUSHs (sv_2mortal (newSViv (flags)));
2481
2482 if (GIMME_V == G_ARRAY)
2483 {
2484 PUSHs (sv_2mortal (to_sv (nmap))); 2474 PUSHs (sv_2mortal (to_sv (pos.m)));
2485 PUSHs (sv_2mortal (newSViv (nx))); 2475 PUSHs (sv_2mortal (to_sv (pos.x)));
2486 PUSHs (sv_2mortal (newSViv (ny))); 2476 PUSHs (sv_2mortal (to_sv (pos.y)));
2487 }
2488} 2477}
2489 2478
2490mapspace * 2479mapspace *
2491ms (maptile *map, unsigned int x, unsigned int y) 2480ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2492 PROTOTYPE: $$$ 2481 PROTOTYPE: $$$;$
2493 CODE: 2482 CODE:
2494{ 2483{
2495 maptile *nmap = 0; 2484 mapxy pos (map, x, y);
2496 I16 nx, ny; 2485 if (!pos.move (dir).normalise ())
2497
2498 PUTBACK;
2499 get_map_flags (map, &nmap, x, y, &nx, &ny);
2500 SPAGAIN;
2501
2502 if (!nmap)
2503 XSRETURN_UNDEF; 2486 XSRETURN_UNDEF;
2504 2487
2505 RETVAL = &nmap->at (nx, ny); 2488 RETVAL = &*pos;
2506} 2489}
2507 OUTPUT: 2490 OUTPUT:
2508 RETVAL 2491 RETVAL
2509 2492
2510void 2493void
2511at (maptile *map, unsigned int x, unsigned int y) 2494at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2512 PROTOTYPE: $$$ 2495 PROTOTYPE: $$$;$
2513 PPCODE: 2496 PPCODE:
2514{ 2497 mapxy pos (map, x, y);
2515 maptile *nmap = 0; 2498 if (pos.move (dir).normalise ())
2516 I16 nx, ny;
2517
2518 PUTBACK;
2519 get_map_flags (map, &nmap, x, y, &nx, &ny);
2520 SPAGAIN;
2521
2522 if (nmap)
2523 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2499 for (object *o = pos->bot; o; o = o->above)
2524 XPUSHs (sv_2mortal (to_sv (o))); 2500 XPUSHs (sv_2mortal (to_sv (o)));
2525}
2526 2501
2527SV * 2502SV *
2528bot_at (maptile *map, unsigned int x, unsigned int y) 2503bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2529 PROTOTYPE: $$$ 2504 PROTOTYPE: $$$;$
2530 ALIAS: 2505 ALIAS:
2531 top_at = 1 2506 top_at = 1
2532 flags_at = 2 2507 flags_at = 2
2533 light_at = 3 2508 light_at = 3
2534 move_block_at = 4 2509 move_block_at = 4
2535 move_slow_at = 5 2510 move_slow_at = 5
2536 move_on_at = 6 2511 move_on_at = 6
2537 move_off_at = 7 2512 move_off_at = 7
2538 CODE: 2513 CODE:
2539{ 2514{
2540 sint16 nx = x; 2515 mapxy pos (map, x, y);
2541 sint16 ny = y; 2516 if (!pos.move (dir).normalise ())
2542
2543 if (!xy_normalise (map, nx, ny))
2544 XSRETURN_UNDEF; 2517 XSRETURN_UNDEF;
2545 2518
2546 mapspace &ms = map->at (nx, ny); 2519 mapspace &ms = *pos;
2547 2520
2548 ms.update (); 2521 ms.update ();
2549 2522
2550 switch (ix) 2523 switch (ix)
2551 { 2524 {
2685list () 2658list ()
2686 PPCODE: 2659 PPCODE:
2687 for_all_regions (rgn) 2660 for_all_regions (rgn)
2688 XPUSHs (sv_2mortal (to_sv (rgn))); 2661 XPUSHs (sv_2mortal (to_sv (rgn)));
2689 2662
2690region *find (utf8_string name)
2691 PROTOTYPE: $
2692 CODE:
2693 RETVAL = region::find (name);
2694 OUTPUT: RETVAL
2695
2696int specificity (region *rgn) 2663int specificity (region *rgn)
2697 CODE: 2664 CODE:
2698 RETVAL = 0; 2665 RETVAL = 0;
2699 while (rgn = rgn->parent) 2666 while (rgn = rgn->parent)
2700 RETVAL++; 2667 RETVAL++;
2803 while (!RETVAL); // crude way to leave index 0 2770 while (!RETVAL); // crude way to leave index 0
2804 2771
2805 faces [RETVAL].name = name; 2772 faces [RETVAL].name = name;
2806 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2773 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2807 2774
2808 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2775 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2809 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2776 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2777 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2810} 2778}
2811 OUTPUT: RETVAL 2779 OUTPUT: RETVAL
2812 2780
2813void set_type (faceidx idx, int value) 2781void set_type (faceidx idx, int value)
2814 ALIAS: 2782 ALIAS:
2948 sv_to (sv, self); 2916 sv_to (sv, self);
2949 delete self; 2917 delete self;
2950 2918
2951MODULE = cf PACKAGE = cf::object::thawer 2919MODULE = cf PACKAGE = cf::object::thawer
2952 2920
2953INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | 2921INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h |
2922
2923bool
2924errors_are_fatal (bool fatal)
2925 CODE:
2926 RETVAL = object_thawer::errors_are_fatal;
2927 object_thawer::errors_are_fatal = fatal;
2928 OUTPUT:
2929 RETVAL
2954 2930
2955SV * 2931SV *
2956new_from_file (char *klass, octet_string path) 2932new_from_file (char *klass, octet_string path)
2957 CODE: 2933 CODE:
2958 object_thawer *f = new object_thawer (path); 2934 object_thawer *f = new object_thawer (path);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines