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.365 by root, Sun Apr 11 04:09:56 2010 UTC vs.
Revision 1.391 by root, Sat Jul 3 01:49:18 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_cf_layout_wrap,
90 *stash_ext_map_world;
91 91
92static SV 92static SV
93 *cv_cf_do_invoke, 93 *cv_cf_do_invoke,
94 *cv_cf__can_merge, 94 *cv_cf__can_merge,
95 *cv_cf_client_send_msg, 95 *cv_cf_client_send_msg,
123 123
124 return sv; 124 return sv;
125} 125}
126#endif 126#endif
127 127
128static noinline utf8_string 128noinline utf8_string
129cfSvPVutf8_nolen (SV *sv) 129cfSvPVutf8_nolen (SV *sv)
130{ 130{
131 SvGETMAGIC (sv); 131 SvGETMAGIC (sv);
132 132
133 if (SvPOK (sv)) 133 if (SvPOK (sv))
230 do_destroy (); 230 do_destroy ();
231 sever_self (); 231 sever_self ();
232} 232}
233 233
234void 234void
235attachable::do_delete ()
236{
237 delete this;
238}
239
240void
235attachable::check_mortals () 241attachable::check_mortals ()
236{ 242{
237 static int i = 0; 243 static int i = 0;
238 244
239 for (;;) 245 for (;;)
252 258
253 if (0) 259 if (0)
254 { 260 {
255 for (int j = 0; j < mortals.size (); ++j)//D 261 for (int j = 0; j < mortals.size (); ++j)//D
256 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 262 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
263
257 fprintf (stderr, "\n");//D 264 fprintf (stderr, "\n");//D
258 } 265 }
259 } 266 }
260 } 267 }
261 268
281 } 288 }
282 else 289 else
283 { 290 {
284 mortals.erase (i); 291 mortals.erase (i);
285 obj->sever_self (); 292 obj->sever_self ();
286 delete obj; 293 obj->do_delete ();
287 } 294 }
288 } 295 }
289} 296}
290 297
291void 298void
346#endif 353#endif
347 354
348////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 355//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
349 356
350static SV * 357static SV *
351newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 358newSVptr (void *ptr, HV *stash, HV *hv)
352{ 359{
353 SV *sv;
354
355 if (!ptr) 360 if (!ptr)
356 return newSV (0); 361 return newSV (0);
357 362
358 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 363 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
359 return sv_bless (newRV_noinc ((SV *)hv), stash); 364 return sv_bless (newRV_noinc ((SV *)hv), stash);
365}
366
367static SV * noinline
368newSVptr (void *ptr, HV *stash)
369{
370 return newSVptr (ptr, stash, newHV ());
360} 371}
361 372
362static int 373static int
363attachable_free (pTHX_ SV *sv, MAGIC *mg) 374attachable_free (pTHX_ SV *sv, MAGIC *mg)
364{ 375{
376 return 0; 387 return 0;
377} 388}
378 389
379MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 390MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
380 391
381static SV * 392static SV * noinline
382newSVattachable (attachable *obj, HV *stash) 393newSVattachable (attachable *obj, HV *stash)
383{ 394{
384 if (!obj) 395 if (!obj)
385 return newSV (0); 396 return newSV (0);
386 397
472 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap 483 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap
473 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap 484 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap
474 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap 485 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap
475 && !sv_derived_from (sv, "cf::object"))) 486 && !sv_derived_from (sv, "cf::object")))
476 croak ("object of type cf::object expected"); 487 croak ("object of type cf::object expected");
488
489 return SvPTR_nc (sv);
490}
491
492static long noinline
493SvPTR_ornull_maptile (SV *sv)
494{
495 if (expect_false (!SvOK (sv))) return 0;
496
497 if (!SvROK (sv)
498 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap
499 && SvSTASH (SvRV (sv)) != stash_ext_map_world
500 && !sv_derived_from (sv, "cf::map")))
501 croak ("object of type cf::map expected");
477 502
478 return SvPTR_nc (sv); 503 return SvPTR_nc (sv);
479} 504}
480 505
481static long noinline 506static long noinline
506static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 531static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
507static inline SV *to_sv (float v) { return newSVnv (v); } 532static inline SV *to_sv (float v) { return newSVnv (v); }
508static inline SV *to_sv (double v) { return newSVnv (v); } 533static inline SV *to_sv (double v) { return newSVnv (v); }
509static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 534static 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); } 535static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
536// 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); } 537static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
538static 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); } 539static 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); } 540static 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); } 541static 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); } 542static 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); } 543static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
517static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } 544static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
545static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
518 546
519static inline SV *to_sv (object & v) { return to_sv (&v); } 547static inline SV *to_sv (object & v) { return to_sv (&v); }
520static inline SV *to_sv (living & v) { return to_sv (&v); } 548static inline SV *to_sv (living & v) { return to_sv (&v); }
521 549
522static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 550static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
558static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 586static 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); } 587static 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); } 588static 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); } 589static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
562static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 590static 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); } 591static 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); } 592static 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); } 593static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); }
594static 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"); } 595static 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"); } 596static 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"); } 597static 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"); } 598static 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"); } 599static 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"); } 600static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
601static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); }
573static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } 602static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
574static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } 603static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
575 604
576//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 605//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
577static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 606static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
688template<class type> 717template<class type>
689static void noinline 718static void noinline
690cf_obj_to (SV *arg, type &var) 719cf_obj_to (SV *arg, type &var)
691{ 720{
692 sv_to (arg, var); 721 sv_to (arg, var);
693 if (!var) 722 if (expect_false (!var))
694 croak ("must not pass invalid/null cf_obj here"); 723 croak ("must not pass invalid/null cf_obj here");
695} 724}
696 725
697template<class object> 726template<class object>
698static void noinline 727static void noinline
699cf_obj_ornull_to (SV *arg, object *&var) 728cf_obj_ornull_to (SV *arg, object *&var)
700{ 729{
701 if (SvOK (arg)) 730 if (SvOK (arg))
702 { 731 {
703 sv_to (arg, var); 732 sv_to (arg, var);
704 if (!var) 733 if (expect_false (!var))
705 croak ("unable to convert perl object to C++ object"); 734 croak ("unable to convert perl object to C++ object");
706 } 735 }
707 else 736 else
708 var = 0; 737 var = 0;
709} 738}
744 exit (EXIT_FAILURE); 773 exit (EXIT_FAILURE);
745 } 774 }
746 775
747 eval_pv ( 776 eval_pv (
748 "#line 1 'cfperl init'\n" 777 "#line 1 'cfperl init'\n"
749 "use EV ();\n" 778 "use EV ();\n" // required by bootstrap
750 "use Coro ();\n" 779 "use Coro ();\n" // required by bootstrap
751 "cf->bootstrap;\n" 780 "cf->bootstrap;\n" // required for cf::datadir
752 "unshift @INC, cf::datadir ();\n" 781 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
753 "require cf;\n", 782 "require cf;\n",
754 0 783 0
755 ); 784 );
756 785
757 if (SvTRUE (ERRSV)) 786 if (SvTRUE (ERRSV))
1132 1161
1133 return retval; 1162 return retval;
1134} 1163}
1135 1164
1136maptile * 1165maptile *
1137find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty) 1166find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty, bool recurse)
1138{ 1167{
1139 CALL_BEGIN (3); 1168 CALL_BEGIN (4);
1140 CALL_ARG (dirname); 1169 CALL_ARG (dirname);
1141 CALL_ARG (stylename); 1170 CALL_ARG (stylename);
1142 CALL_ARG (difficulty); 1171 CALL_ARG (difficulty);
1172 CALL_ARG (recurse);
1143 CALL_CALL ("ext::map_random::find_style", G_SCALAR); 1173 CALL_CALL ("ext::map_random::find_style", G_SCALAR);
1144 1174
1145 maptile *retval = 0; 1175 maptile *retval = 0;
1146 if (count) sv_to (POPs, retval); 1176 if (count) sv_to (POPs, retval);
1147 1177
1370 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1400 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1371 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1401 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1372 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1402 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1373 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1403 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1374 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1404 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1405 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1406 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1375 1407
1376 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1408 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); 1409 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); 1410 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); 1411 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1428# undef def 1460# undef def
1429# define def(uc, flags) const_iv (SK_ ## uc) 1461# define def(uc, flags) const_iv (SK_ ## uc)
1430# include "skillinc.h" 1462# include "skillinc.h"
1431# undef def 1463# undef def
1432 1464
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) 1465 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1437 1466
1438 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1467 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1439 1468
1440 const_iv (MAX_TIME) 1469 const_iv (MAX_TIME)
1466 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1495 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1467 1496
1468 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1497 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1469 }; 1498 };
1470 1499
1471 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1500 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1472 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1501 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1473 1502
1474 static const struct { 1503 static const struct {
1475 const char *name; 1504 const char *name;
1476 int skip; 1505 int skip;
1482# undef def 1511# undef def
1483 }; 1512 };
1484 1513
1485 AV *av = get_av ("cf::EVENT", 1); 1514 AV *av = get_av ("cf::EVENT", 1);
1486 1515
1487 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1516 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1488 { 1517 {
1489 AV *event = newAV (); 1518 AV *event = newAV ();
1490 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1519 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1491 av_push (event, newSViv (eiv->klass)); 1520 av_push (event, newSViv (eiv->klass));
1492 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1521 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1573 1602
1574void init_anim () 1603void init_anim ()
1575 1604
1576void init_globals () 1605void init_globals ()
1577 1606
1578void init_experience ()
1579
1580void init_attackmess () 1607void init_attackmess ()
1581 1608
1582void init_dynamic () 1609void init_dynamic ()
1583 1610
1584void load_settings () 1611void load_settings ()
1585 1612
1613void reload_exp_table ()
1614
1586void load_materials () 1615void reload_materials ()
1587 1616
1588void init_uuid () 1617void init_uuid ()
1589 CODE: 1618 CODE:
1590 UUID::init (); 1619 UUID::init ();
1591 1620
1657 switch (items) 1686 switch (items)
1658 { 1687 {
1659 case 0: RETVAL = gen (); break; 1688 case 0: RETVAL = gen (); break;
1660 case 1: RETVAL = gen (SvUV (ST (0))); break; 1689 case 1: RETVAL = gen (SvUV (ST (0))); break;
1661 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1690 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1662 default: croak ("cf::rndm requires none, one or two parameters."); break; 1691 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1663 } 1692 }
1664} 1693}
1665 OUTPUT: 1694 OUTPUT:
1666 RETVAL 1695 RETVAL
1667 1696
1683 PROTOTYPE: @ 1712 PROTOTYPE: @
1684 CODE: 1713 CODE:
1685 while (items > 0) 1714 while (items > 0)
1686 sv_rvweaken (ST (--items)); 1715 sv_rvweaken (ST (--items));
1687 1716
1688void 1717void log_suspend ()
1718
1719void log_resume ()
1720
1689log_backtrace (utf8_string msg) 1721void log_backtrace (utf8_string msg)
1690 1722
1691void
1692LOG (int flags, utf8_string msg) 1723void LOG (int flags, utf8_string msg)
1693 PROTOTYPE: $$ 1724 PROTOTYPE: $$
1694 C_ARGS: flags, "%s", msg 1725 C_ARGS: flags, "%s", msg
1695 1726
1696octet_string path_combine (octet_string base, octet_string path) 1727octet_string path_combine (octet_string base, octet_string path)
1697 PROTOTYPE: $$ 1728 PROTOTYPE: $$
1789 1820
1790int random_roll (int min, int max, object *op, int goodbad); 1821int random_roll (int min, int max, object *op, int goodbad);
1791 1822
1792const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1823const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1793 1824
1794int
1795exp_to_level (val64 exp) 1825int exp_to_level (val64 exp)
1796 CODE:
1797{
1798 int i = 0;
1799 1826
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) 1827val64 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 1828
1824SV * 1829SV *
1825resistance_to_string (int atnr) 1830resistance_to_string (int atnr)
1826 CODE: 1831 CODE:
1827 if (atnr >= 0 && atnr < NROFATTACKS) 1832 if (atnr >= 0 && atnr < NROFATTACKS)
1885 CODE: 1890 CODE:
1886 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1891 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1887 OUTPUT: 1892 OUTPUT:
1888 RETVAL 1893 RETVAL
1889 1894
1895bool should_invoke (attachable *obj, int event)
1896 CODE:
1897 RETVAL = obj->should_invoke ((event_type)event);
1898 OUTPUT: RETVAL
1899
1890void 1900void
1891debug_trace (attachable *obj, bool on = true) 1901debug_trace (attachable *obj, bool on = true)
1892 CODE: 1902 CODE:
1893 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1903 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1894 if (on) 1904 if (on)
2019 OUTPUT: 2029 OUTPUT:
2020 RETVAL 2030 RETVAL
2021 2031
2022object *find_best_object_match (object *op, utf8_string match) 2032object *find_best_object_match (object *op, utf8_string match)
2023 2033
2024object *find_marked_object (object *op)
2025
2026int need_identify (object *obj);
2027
2028int apply_shop_mat (object *shop_mat, object *op); 2034int apply_shop_mat (object *shop_mat, object *op);
2029 2035
2030int move (object *op, int dir, object *originator = op) 2036int move (object *op, int dir, object *originator = op)
2031 CODE: 2037 CODE:
2032 RETVAL = op->move (dir, originator); 2038 RETVAL = op->move (dir, originator);
2084 2090
2085void pick_up (object *who, object *op) 2091void pick_up (object *who, object *op)
2086 2092
2087void update_object (object *op, int action) 2093void update_object (object *op, int action)
2088 2094
2089void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2095void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2090 2096
2091void player_lvl_adj (object *who, object *skill = 0) 2097void player_lvl_adj (object *who, object *skill = 0)
2092 2098
2093int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2099int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2094 2100
2459 if (oblinkpt *obp = map->find_link (connection)) 2465 if (oblinkpt *obp = map->find_link (connection))
2460 for (objectlink *ol = obp->link; ol; ol = ol->next) 2466 for (objectlink *ol = obp->link; ol; ol = ol->next)
2461 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2467 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2462 2468
2463void 2469void
2464get_map_flags (maptile *map, int x, int y) 2470xy_normalise (maptile *map, int x, int y, int dir = 0)
2465 PPCODE: 2471 PPCODE:
2466{ 2472{
2467 maptile *nmap = 0; 2473 mapxy pos (map, x, y);
2468 I16 nx = 0, ny = 0; 2474 if (!pos.move (dir).normalise ())
2475 XSRETURN_EMPTY;
2469 2476
2470 PUTBACK;
2471 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2472 SPAGAIN;
2473
2474 EXTEND (SP, 4); 2477 EXTEND (SP, 3);
2475 PUSHs (sv_2mortal (newSViv (flags)));
2476
2477 if (GIMME_V == G_ARRAY)
2478 {
2479 PUSHs (sv_2mortal (to_sv (nmap))); 2478 PUSHs (sv_2mortal (to_sv (pos.m)));
2480 PUSHs (sv_2mortal (newSViv (nx))); 2479 PUSHs (sv_2mortal (to_sv (pos.x)));
2481 PUSHs (sv_2mortal (newSViv (ny))); 2480 PUSHs (sv_2mortal (to_sv (pos.y)));
2482 }
2483} 2481}
2484 2482
2485mapspace * 2483mapspace *
2486ms (maptile *map, unsigned int x, unsigned int y) 2484ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2487 PROTOTYPE: $$$ 2485 PROTOTYPE: $$$;$
2488 CODE: 2486 CODE:
2489{ 2487{
2490 maptile *nmap = 0; 2488 mapxy pos (map, x, y);
2491 I16 nx, ny; 2489 if (!pos.move (dir).normalise ())
2492
2493 PUTBACK;
2494 get_map_flags (map, &nmap, x, y, &nx, &ny);
2495 SPAGAIN;
2496
2497 if (!nmap)
2498 XSRETURN_UNDEF; 2490 XSRETURN_UNDEF;
2499 2491
2500 RETVAL = &nmap->at (nx, ny); 2492 RETVAL = &*pos;
2501} 2493}
2502 OUTPUT: 2494 OUTPUT:
2503 RETVAL 2495 RETVAL
2504 2496
2505void 2497void
2506at (maptile *map, unsigned int x, unsigned int y) 2498at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2507 PROTOTYPE: $$$ 2499 PROTOTYPE: $$$;$
2508 PPCODE: 2500 PPCODE:
2509{ 2501 mapxy pos (map, x, y);
2510 maptile *nmap = 0; 2502 if (pos.move (dir).normalise ())
2511 I16 nx, ny;
2512
2513 PUTBACK;
2514 get_map_flags (map, &nmap, x, y, &nx, &ny);
2515 SPAGAIN;
2516
2517 if (nmap)
2518 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2503 for (object *o = pos->bot; o; o = o->above)
2519 XPUSHs (sv_2mortal (to_sv (o))); 2504 XPUSHs (sv_2mortal (to_sv (o)));
2520}
2521 2505
2522SV * 2506SV *
2523bot_at (maptile *map, unsigned int x, unsigned int y) 2507bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2524 PROTOTYPE: $$$ 2508 PROTOTYPE: $$$;$
2525 ALIAS: 2509 ALIAS:
2526 top_at = 1 2510 top_at = 1
2527 flags_at = 2 2511 flags_at = 2
2528 light_at = 3 2512 light_at = 3
2529 move_block_at = 4 2513 move_block_at = 4
2530 move_slow_at = 5 2514 move_slow_at = 5
2531 move_on_at = 6 2515 move_on_at = 6
2532 move_off_at = 7 2516 move_off_at = 7
2533 CODE: 2517 CODE:
2534{ 2518{
2535 sint16 nx = x; 2519 mapxy pos (map, x, y);
2536 sint16 ny = y; 2520 if (!pos.move (dir).normalise ())
2537
2538 if (!xy_normalise (map, nx, ny))
2539 XSRETURN_UNDEF; 2521 XSRETURN_UNDEF;
2540 2522
2541 mapspace &ms = map->at (nx, ny); 2523 mapspace &ms = *pos;
2542 2524
2543 ms.update (); 2525 ms.update ();
2544 2526
2545 switch (ix) 2527 switch (ix)
2546 { 2528 {
2556} 2538}
2557 OUTPUT: RETVAL 2539 OUTPUT: RETVAL
2558 2540
2559# worst xs function of my life 2541# worst xs function of my life
2560bool 2542bool
2561_create_random_map (\ 2543_create_random_map (maptile *self, SV *options)
2562 maptile *self,\
2563 utf8_string wallstyle,\
2564 utf8_string wall_name,\
2565 utf8_string floorstyle,\
2566 utf8_string monsterstyle,\
2567 utf8_string treasurestyle,\
2568 utf8_string layoutstyle,\
2569 utf8_string doorstyle,\
2570 utf8_string decorstyle,\
2571 utf8_string miningstyle,\
2572 utf8_string origin_map,\
2573 utf8_string final_map,\
2574 utf8_string exitstyle,\
2575 utf8_string this_map,\
2576 utf8_string exit_on_final_map,\
2577 int xsize,\
2578 int ysize,\
2579 int expand2x,\
2580 int layoutoptions1,\
2581 int layoutoptions2,\
2582 int layoutoptions3,\
2583 int symmetry,\
2584 int difficulty,\
2585 int difficulty_given,\
2586 float difficulty_increase,\
2587 int dungeon_level,\
2588 int dungeon_depth,\
2589 int decoroptions,\
2590 int orientation,\
2591 int origin_y,\
2592 int origin_x,\
2593 U32 random_seed,\
2594 val64 total_map_hp,\
2595 int map_layout_style,\
2596 int treasureoptions,\
2597 int symmetry_used,\
2598 region *region,\
2599 utf8_string custom\
2600)
2601 CODE: 2544 CODE:
2602{ 2545{
2603 random_map_params rmp; 2546 random_map_params rmp ((HV *)SvRV (options));
2604
2605 assign (rmp.wallstyle , wallstyle);
2606 assign (rmp.wall_name , wall_name);
2607 assign (rmp.floorstyle , floorstyle);
2608 assign (rmp.monsterstyle , monsterstyle);
2609 assign (rmp.treasurestyle , treasurestyle);
2610 assign (rmp.layoutstyle , layoutstyle);
2611 assign (rmp.doorstyle , doorstyle);
2612 assign (rmp.decorstyle , decorstyle);
2613 assign (rmp.miningstyle , miningstyle);
2614 assign (rmp.exitstyle , exitstyle);
2615 assign (rmp.exit_on_final_map, exit_on_final_map);
2616
2617 rmp.origin_map = origin_map;
2618 rmp.final_map = final_map;
2619 rmp.this_map = this_map;
2620 rmp.xsize = xsize;
2621 rmp.ysize = ysize;
2622 rmp.expand2x = expand2x;
2623 rmp.layoutoptions1 = layoutoptions1;
2624 rmp.layoutoptions2 = layoutoptions2;
2625 rmp.layoutoptions3 = layoutoptions3;
2626 rmp.symmetry = symmetry;
2627 rmp.difficulty = difficulty;
2628 rmp.difficulty_given = difficulty_given;
2629 rmp.difficulty_increase = difficulty_increase;
2630 rmp.dungeon_level = dungeon_level;
2631 rmp.dungeon_depth = dungeon_depth;
2632 rmp.decoroptions = decoroptions;
2633 rmp.orientation = orientation;
2634 rmp.origin_y = origin_y;
2635 rmp.origin_x = origin_x;
2636 rmp.random_seed = random_seed;
2637 rmp.total_map_hp = (uint64_t) total_map_hp;
2638 rmp.map_layout_style = map_layout_style;
2639 rmp.treasureoptions = treasureoptions;
2640 rmp.symmetry_used = symmetry_used;
2641 rmp.region = region;
2642 rmp.custom = custom;
2643
2644 RETVAL = self->generate_random_map (&rmp); 2547 RETVAL = self->generate_random_map (&rmp);
2645} 2548}
2646 OUTPUT: 2549 OUTPUT:
2647 RETVAL 2550 RETVAL
2648 2551
2679void 2582void
2680list () 2583list ()
2681 PPCODE: 2584 PPCODE:
2682 for_all_regions (rgn) 2585 for_all_regions (rgn)
2683 XPUSHs (sv_2mortal (to_sv (rgn))); 2586 XPUSHs (sv_2mortal (to_sv (rgn)));
2684
2685region *find (utf8_string name)
2686 PROTOTYPE: $
2687 CODE:
2688 RETVAL = region::find (name);
2689 OUTPUT: RETVAL
2690 2587
2691int specificity (region *rgn) 2588int specificity (region *rgn)
2692 CODE: 2589 CODE:
2693 RETVAL = 0; 2590 RETVAL = 0;
2694 while (rgn = rgn->parent) 2591 while (rgn = rgn->parent)
2798 while (!RETVAL); // crude way to leave index 0 2695 while (!RETVAL); // crude way to leave index 0
2799 2696
2800 faces [RETVAL].name = name; 2697 faces [RETVAL].name = name;
2801 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2698 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2802 2699
2803 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2700 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2804 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2701 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2702 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2805} 2703}
2806 OUTPUT: RETVAL 2704 OUTPUT: RETVAL
2807 2705
2808void set_type (faceidx idx, int value) 2706void set_type (faceidx idx, int value)
2809 ALIAS: 2707 ALIAS:
2943 sv_to (sv, self); 2841 sv_to (sv, self);
2944 delete self; 2842 delete self;
2945 2843
2946MODULE = cf PACKAGE = cf::object::thawer 2844MODULE = cf PACKAGE = cf::object::thawer
2947 2845
2948INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | 2846INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h |
2847
2848bool
2849errors_are_fatal (bool fatal)
2850 CODE:
2851 RETVAL = object_thawer::errors_are_fatal;
2852 object_thawer::errors_are_fatal = fatal;
2853 OUTPUT:
2854 RETVAL
2949 2855
2950SV * 2856SV *
2951new_from_file (char *klass, octet_string path) 2857new_from_file (char *klass, octet_string path)
2952 CODE: 2858 CODE:
2953 object_thawer *f = new object_thawer (path); 2859 object_thawer *f = new object_thawer (path);
2979 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2885 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2980 2886
2981 self->skip (); 2887 self->skip ();
2982 } 2888 }
2983 2889
2890MODULE = cf PACKAGE = cf::layout
2891
2892INCLUDE: $PERL $srcdir/genacc layout $srcdir/../random_maps/random_map.h |
2893

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines