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.153 by root, Fri Jan 26 20:59:57 2007 UTC vs.
Revision 1.183 by root, Mon Apr 9 04:40:39 2007 UTC

4 4
5/* 5/*
6 * This code is placed under the GNU General Public Licence (GPL) 6 * This code is placed under the GNU General Public Licence (GPL)
7 * 7 *
8 * Copyright (C) 2001-2005 by Chachkoff Yann 8 * Copyright (C) 2001-2005 by Chachkoff Yann
9 * Copyright (C) 2006 by Marc Lehmann <cf@schmorp.de> 9 * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de>
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. 14 * (at your option) any later version.
29#include <plugin_common.h> 29#include <plugin_common.h>
30#include <sounds.h> 30#include <sounds.h>
31#include <cstdarg> 31#include <cstdarg>
32#include <sproto.h> 32#include <sproto.h>
33 33
34#include "loader.h"
34#include "cfperl.h" 35#include "cfperl.h"
35#include "shstr.h" 36#include "shstr.h"
36 37
37#include <unistd.h> 38#include <unistd.h>
38#if _POSIX_MEMLOCK 39#if _POSIX_MEMLOCK
48 49
49extern sint64 *levels; // the experience table 50extern sint64 *levels; // the experience table
50 51
51typedef object object_ornull; 52typedef object object_ornull;
52typedef maptile maptile_ornull; 53typedef maptile maptile_ornull;
54
55typedef char *octet_string;
56typedef char *utf8_string;
57typedef const char *const_octet_string;
58typedef const char *const_utf8_string;
53 59
54#if IVSIZE >= 8 60#if IVSIZE >= 8
55 typedef IV val64; 61 typedef IV val64;
56# define newSVval64 newSViv 62# define newSVval64 newSViv
57# define SvVAL64 SvIV 63# define SvVAL64 SvIV
101 107
102unordered_vector<attachable *> attachable::mortals; 108unordered_vector<attachable *> attachable::mortals;
103 109
104attachable::~attachable () 110attachable::~attachable ()
105{ 111{
112 flags |=0x3300;//D
106 assert (!self); 113 assert (!self);
107 assert (!cb); 114 assert (!cb);
108} 115}
109 116
110int 117int
111attachable::refcnt_cnt () const 118attachable::refcnt_cnt () const
112{ 119{
113 return refcnt + (self ? SvREFCNT (self) - 1 : 0); 120 return refcnt + (self ? SvREFCNT (self) - 1 : 0);
121}
122
123void
124attachable::sever_self ()
125{
126 if (HV *self = this->self)
127 {
128 // keep a refcount because sv_unmagic might call attachable_free,
129 // which might clear self, causing sv_unmagic to crash on a now
130 // invalid object.
131 SvREFCNT_inc (self);
132 hv_clear (self);
133 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
134 SvREFCNT_dec (self);
135
136 // self *must* be null now because thats sv_unmagic's job.
137 assert (!this->self);
138 flags |= 0x80; // severed //D
139 }
114} 140}
115 141
116void 142void
117attachable::optimise () 143attachable::optimise ()
118{ 144{
119 if (self 145 if (self
120 && SvREFCNT (self) == 1 146 && SvREFCNT (self) == 1
121 && !HvTOTALKEYS (self)) 147 && !HvTOTALKEYS (self))
122 { 148 flags |= 0x40,//D
123 sv_unmagic ((SV *)self, PERL_MAGIC_ext); 149 sever_self ();
124 assert (!self);
125 }
126} 150}
127 151
128// check wether the object really is dead 152// check wether the object really is dead
129void 153void
130attachable::do_check () 154attachable::do_check ()
145 SvREFCNT_dec (cb); 169 SvREFCNT_dec (cb);
146 cb = 0; 170 cb = 0;
147 } 171 }
148 172
149 if (self) 173 if (self)
150 { 174 sever_self ();
151 hv_clear (self);
152 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
153 // self is now 0
154 assert (!self);//D//TODO remove soon
155 }
156 175
176 flags |= 0x20; //D
157 mortals.push_back (this); 177 mortals.push_back (this);
158} 178}
159 179
160void 180void
161attachable::destroy () 181attachable::destroy ()
256 276
257 if (!obj->self) 277 if (!obj->self)
258 { 278 {
259 obj->self = newHV (); 279 obj->self = newHV ();
260 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 280 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
281 obj->flags |= (obj->flags & 0xc0) << 8;
282 obj->flags &= ~0xc0;//D
283 obj->flags |= 0x10;//D
261 284
262 // now bless the object _once_ 285 // now bless the object _once_
263 return sv_bless (newRV_inc ((SV *)obj->self), stash); 286 return sv_bless (newRV_inc ((SV *)obj->self), stash);
264 } 287 }
265 else 288 else
331inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 354inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
332 355
333inline SV *to_sv (object & v) { return to_sv (&v); } 356inline SV *to_sv (object & v) { return to_sv (&v); }
334inline SV *to_sv (living & v) { return to_sv (&v); } 357inline SV *to_sv (living & v) { return to_sv (&v); }
335 358
336inline SV *to_sv (facetile * v) { return to_sv (v->name); } 359//inline SV *to_sv (faceinfo * v) { return to_sv (v->name); }
337inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } 360inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
361inline SV *to_sv (std::string & v) { return newSVpvn (v.data (), v.size ()); }
338 362
339inline SV *to_sv (UUID v) 363inline SV *to_sv (UUID v)
340{ 364{
341 char buf[128]; 365 char buf[128];
342 snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); 366 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
343 return newSVpv (buf, 0); 367 return newSVpv (buf, 0);
344} 368}
345 369
346inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } 370inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; }
347inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } 371inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
366inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 390inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
367inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 391inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
368inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } 392inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
369inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 393inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
370 394
371inline void sv_to (SV *sv, facetile * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } 395//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
372inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } 396inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); }
373 397
374template<class T> 398template<class T>
375inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 399inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
376 400
380inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); } 404inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
381inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } 405inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); }
382inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } 406inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); }
383inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } 407inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
384inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } 408inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
409
410inline void sv_to (SV *sv, std::string &v)
411{
412 STRLEN len;
413 char *data = SvPVbyte (sv, len);
414 v.assign (data, len);
415}
385 416
386inline void sv_to (SV *sv, UUID &v) 417inline void sv_to (SV *sv, UUID &v)
387{ 418{
388 unsigned int version; 419 unsigned int version;
389 420
580 perl = perl_alloc (); 611 perl = perl_alloc ();
581 perl_construct (perl); 612 perl_construct (perl);
582 613
583 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 614 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
584 615
585 char *argv[] = { 616 const char *argv[] = {
586 "", 617 "",
587 "-e" 618 "-e"
588 "use Event; use Coro;" // required for bootstrap 619 "use Event; use Coro;" // required for bootstrap
589 "cf->bootstrap;" // required for datadir :*> 620 "cf->bootstrap;" // required for datadir :*>
590 "unshift @INC, cf::datadir ();" 621 "unshift @INC, cf::datadir ();"
591 "require cf;" 622 "require cf;"
592 }; 623 };
593 624
594 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 625 if (perl_parse (perl, xs_init, 2, (char **)argv, (char **)NULL)
626 || perl_run (perl))
595 { 627 {
596 printf ("unable to initialize perl-interpreter, aborting.\n"); 628 printf ("unable to initialize perl-interpreter, aborting.\n");
597 exit (EXIT_FAILURE); 629 exit (EXIT_FAILURE);
598 } 630 }
631
632 {
633 dSP;
634
635 PUSHMARK (SP);
636 PUTBACK;
637 call_pv ("cf::init", G_DISCARD | G_VOID);
638 }
599} 639}
600 640
601void cfperl_main () 641void cfperl_main ()
602{ 642{
603 dSP; 643 dSP;
824 CALL_BEGIN (0); 864 CALL_BEGIN (0);
825 CALL_CALL ("cf::emergency_save", G_VOID); 865 CALL_CALL ("cf::emergency_save", G_VOID);
826 CALL_END; 866 CALL_END;
827} 867}
828 868
869void
870cfperl_cleanup (int make_core)
871{
872 CALL_BEGIN (1);
873 CALL_ARG (make_core);
874 CALL_CALL ("cf::post_cleanup", G_VOID);
875 CALL_END;
876}
877
829maptile * 878maptile *
830maptile::find_sync (const char *path, maptile *origin) 879maptile::find_sync (const char *path, maptile *origin)
831{ 880{
832 CALL_BEGIN (2); 881 CALL_BEGIN (2);
833 CALL_ARG (path); 882 CALL_ARG (path);
1007# define const_iv(name) { # name, (IV)name }, 1056# define const_iv(name) { # name, (IV)name },
1008 const_iv (llevError) 1057 const_iv (llevError)
1009 const_iv (llevInfo) 1058 const_iv (llevInfo)
1010 const_iv (llevDebug) 1059 const_iv (llevDebug)
1011 const_iv (llevMonster) 1060 const_iv (llevMonster)
1061
1062 const_iv (Map0Cmd)
1063 const_iv (Map1Cmd)
1064 const_iv (Map1aCmd)
1065
1066 const_iv (MAP_CLIENT_X)
1067 const_iv (MAP_CLIENT_Y)
1012 1068
1013 const_iv (MAX_TIME) 1069 const_iv (MAX_TIME)
1014 const_iv (PLAYER) 1070 const_iv (PLAYER)
1015 const_iv (TRANSPORT) 1071 const_iv (TRANSPORT)
1016 const_iv (ROD) 1072 const_iv (ROD)
1551{ 1607{
1552 // reattach to all attachable objects in the game. 1608 // reattach to all attachable objects in the game.
1553 for_all_clients (ns) 1609 for_all_clients (ns)
1554 ns->reattach (); 1610 ns->reattach ();
1555 1611
1556 for_all_players (pl)
1557 pl->reattach ();
1558
1559 //TODO
1560 //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i)
1561 // i->second->reattach ();
1562
1563 for_all_objects (op) 1612 for_all_objects (op)
1564 op->reattach (); 1613 op->reattach ();
1565} 1614}
1566 1615
1567NV floor (NV x) 1616NV floor (NV x)
1584 CODE: 1633 CODE:
1585 runtime = SvNVx (sv_runtime); 1634 runtime = SvNVx (sv_runtime);
1586 server_tick (); 1635 server_tick ();
1587 1636
1588void 1637void
1589LOG (int level, char *msg) 1638LOG (int level, utf8_string msg)
1590 PROTOTYPE: $$ 1639 PROTOTYPE: $$
1591 C_ARGS: (LogLevel)level, "%s", msg 1640 C_ARGS: (LogLevel)level, "%s", msg
1592 1641
1593char *path_combine (char *base, char *path) 1642octet_string path_combine (octet_string base, octet_string path)
1594 PROTOTYPE: $$ 1643 PROTOTYPE: $$
1595 1644
1596char *path_combine_and_normalize (char *base, char *path) 1645octet_string path_combine_and_normalize (octet_string base, octet_string path)
1597 PROTOTYPE: $$ 1646 PROTOTYPE: $$
1598 1647
1599const char * 1648const_octet_string
1600get_maps_directory (char *path) 1649get_maps_directory (octet_string path)
1601 PROTOTYPE: $ 1650 PROTOTYPE: $
1602 ALIAS: maps_directory = 0 1651 ALIAS: maps_directory = 0
1603 CODE: 1652 CODE:
1604 RETVAL = create_pathname (path); 1653 RETVAL = create_pathname (path);
1605 OUTPUT: RETVAL 1654 OUTPUT: RETVAL
1607void 1656void
1608sub_generation_inc () 1657sub_generation_inc ()
1609 CODE: 1658 CODE:
1610 PL_sub_generation++; 1659 PL_sub_generation++;
1611 1660
1612char * 1661const_octet_string
1613mapdir () 1662mapdir ()
1614 PROTOTYPE: 1663 PROTOTYPE:
1615 ALIAS: 1664 ALIAS:
1616 mapdir = 0 1665 mapdir = 0
1617 uniquedir = 1 1666 uniquedir = 1
1633 } 1682 }
1634 OUTPUT: RETVAL 1683 OUTPUT: RETVAL
1635 1684
1636void abort () 1685void abort ()
1637 1686
1638void fork_abort (char *cause = "cf::fork_abort") 1687void fork_abort (octet_string cause = "cf::fork_abort")
1639 1688
1640void cleanup (const char *cause, bool make_core = false) 1689void cleanup (octet_string cause, bool make_core = false)
1641 1690
1642void emergency_save () 1691void emergency_save ()
1692
1693void _exit (int status = EXIT_SUCCESS)
1643 1694
1644UV sv_2watcher (SV *w) 1695UV sv_2watcher (SV *w)
1645 CODE: 1696 CODE:
1646 RETVAL = (UV)GEventAPI->sv_2watcher (w); 1697 RETVAL = (UV)GEventAPI->sv_2watcher (w);
1647 OUTPUT: 1698 OUTPUT:
1648 RETVAL 1699 RETVAL
1649 1700
1650void _exit (int status = 0)
1651
1652#if _POSIX_MEMLOCK 1701#if _POSIX_MEMLOCK
1653 1702
1654int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1703int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1655 1704
1656int munlockall () 1705int munlockall ()
1657 1706
1658#endif 1707#endif
1659 1708
1660int find_animation (char *text) 1709int find_animation (utf8_string text)
1661 PROTOTYPE: $ 1710 PROTOTYPE: $
1662 1711
1663int random_roll (int min, int max, object *op, int goodbad); 1712int random_roll (int min, int max, object *op, int goodbad);
1664 1713
1665const char *cost_string_from_value(uint64 cost, int approx = 0) 1714const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1666 1715
1667int 1716int
1668exp_to_level (val64 exp) 1717exp_to_level (val64 exp)
1669 CODE: 1718 CODE:
1670{ 1719{
1701 RETVAL = newSVpv (resist_plus[atnr], 0); 1750 RETVAL = newSVpv (resist_plus[atnr], 0);
1702 else 1751 else
1703 XSRETURN_UNDEF; 1752 XSRETURN_UNDEF;
1704 OUTPUT: RETVAL 1753 OUTPUT: RETVAL
1705 1754
1755bool
1756load_resource_file (octet_string filename)
1757
1706MODULE = cf PACKAGE = cf::attachable 1758MODULE = cf PACKAGE = cf::attachable
1707 1759
1708int 1760int
1709valid (SV *obj) 1761valid (SV *obj)
1710 CODE: 1762 CODE:
1711 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1763 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1712 OUTPUT: 1764 OUTPUT:
1713 RETVAL 1765 RETVAL
1766
1767void
1768debug_trace (attachable *obj, bool on = true)
1769 CODE:
1770 obj->flags &= ~attachable::F_DEBUG_TRACE;
1771 if (on)
1772 obj->flags |= attachable::F_DEBUG_TRACE;
1714 1773
1715int mortals_size () 1774int mortals_size ()
1716 CODE: 1775 CODE:
1717 RETVAL = attachable::mortals.size (); 1776 RETVAL = attachable::mortals.size ();
1718 OUTPUT: RETVAL 1777 OUTPUT: RETVAL
1720#object *mortals (U32 index) 1779#object *mortals (U32 index)
1721# CODE: 1780# CODE:
1722# RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0; 1781# RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0;
1723# OUTPUT: RETVAL 1782# OUTPUT: RETVAL
1724 1783
1725INCLUDE: $PERL genacc attachable ../include/cfperl.h | 1784INCLUDE: $PERL $srcdir/genacc attachable ../include/cfperl.h |
1726 1785
1727MODULE = cf PACKAGE = cf::global 1786MODULE = cf PACKAGE = cf::global
1728 1787
1729int invoke (SV *klass, int event, ...) 1788int invoke (SV *klass, int event, ...)
1730 CODE: 1789 CODE:
1734 RETVAL = gbl_ev.invoke ((event_type)event, ARG_AV (av), DT_END); 1793 RETVAL = gbl_ev.invoke ((event_type)event, ARG_AV (av), DT_END);
1735 OUTPUT: RETVAL 1794 OUTPUT: RETVAL
1736 1795
1737MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1796MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1738 1797
1739INCLUDE: $PERL genacc object ../include/object.h | 1798INCLUDE: $PERL $srcdir/genacc object ../include/object.h |
1740 1799
1741int invoke (object *op, int event, ...) 1800int invoke (object *op, int event, ...)
1742 CODE: 1801 CODE:
1743 if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); 1802 if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT");
1744 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 1803 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1795void 1854void
1796set_animation (object *op, int idx) 1855set_animation (object *op, int idx)
1797 CODE: 1856 CODE:
1798 SET_ANIMATION (op, idx); 1857 SET_ANIMATION (op, idx);
1799 1858
1859int
1860num_animations (object *op)
1861 CODE:
1862 RETVAL = NUM_ANIMATIONS (op);
1863 OUTPUT: RETVAL
1864
1800object *find_best_object_match (object *op, const char *match) 1865object *find_best_object_match (object *op, utf8_string match)
1801 1866
1802object *find_marked_object (object *op) 1867object *find_marked_object (object *op)
1803 1868
1804int need_identify (object *obj); 1869int need_identify (object *obj);
1805 1870
1806int apply_shop_mat (object *shop_mat, object *op); 1871int apply_shop_mat (object *shop_mat, object *op);
1872
1873int move_player (object *op, int dir)
1874 CODE:
1875 RETVAL = move_player (op, dir);
1876 OUTPUT:
1877 RETVAL
1807 1878
1808int move (object *op, int dir, object *originator = op) 1879int move (object *op, int dir, object *originator = op)
1809 CODE: 1880 CODE:
1810 RETVAL = move_ob (op, dir, originator); 1881 RETVAL = move_ob (op, dir, originator);
1811 OUTPUT: 1882 OUTPUT:
1817 1888
1818void apply_below (object *op) 1889void apply_below (object *op)
1819 CODE: 1890 CODE:
1820 player_apply_below (op); 1891 player_apply_below (op);
1821 1892
1893int cast_heal (object *op, object *caster, object *spell, int dir = 0)
1894
1822object *cf_object_present_archname_inside (object *op, char *whatstr) 1895object *cf_object_present_archname_inside (object *op, utf8_string whatstr)
1823 1896
1824int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) 1897int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1825 1898
1826int cf_object_change_map (object *op, int x, int y, maptile *map) 1899int cf_object_change_map (object *op, int x, int y, maptile *map)
1827 1900
1847 RETVAL = pay_for_amount (amount, op); 1920 RETVAL = pay_for_amount (amount, op);
1848 OUTPUT: RETVAL 1921 OUTPUT: RETVAL
1849 1922
1850void pay_player (object *op, uint64 amount) 1923void pay_player (object *op, uint64 amount)
1851 1924
1852val64 pay_player_arch (object *op, const char *arch, uint64 amount) 1925val64 pay_player_arch (object *op, utf8_string arch, uint64 amount)
1853 1926
1854int cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg = 0) 1927int cast_spell (object *op, object *caster, int dir, object *spell_ob, utf8_string stringarg = 0)
1855 1928
1856void learn_spell (object *op, object *sp, int special_prayer = 0) 1929void learn_spell (object *op, object *sp, int special_prayer = 0)
1857 CODE: 1930 CODE:
1858 do_learn_spell (op, sp, special_prayer); 1931 do_learn_spell (op, sp, special_prayer);
1859 1932
1860void forget_spell (object *op, object *sp) 1933void forget_spell (object *op, object *sp)
1861 CODE: 1934 CODE:
1862 do_forget_spell (op, query_name (sp)); 1935 do_forget_spell (op, query_name (sp));
1863 1936
1864object *check_for_spell (object *op, char *spellname) 1937object *check_for_spell (object *op, utf8_string spellname)
1865 CODE: 1938 CODE:
1866 RETVAL = check_spell_known (op, spellname); 1939 RETVAL = check_spell_known (op, spellname);
1867 OUTPUT: RETVAL 1940 OUTPUT: RETVAL
1868 1941
1869int query_money (object *op) 1942int query_money (object *op)
1882 1955
1883int cf_object_teleport (object *op, maptile *map, int x, int y) 1956int cf_object_teleport (object *op, maptile *map, int x, int y)
1884 1957
1885void update_object (object *op, int action) 1958void update_object (object *op, int action)
1886 1959
1887object *cf_create_object_by_name (const char *name) 1960object *cf_create_object_by_name (utf8_string name)
1888 1961
1889void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) 1962void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0)
1890 1963
1891void player_lvl_adj (object *who, object *skill = 0) 1964void player_lvl_adj (object *who, object *skill = 0)
1892 1965
1893int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 1966int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1894 1967
1908object *cf_insert_ob_in_ob (object *ob, object *where) 1981object *cf_insert_ob_in_ob (object *ob, object *where)
1909 1982
1910# no clean way to get an object from an archetype - stupid idiotic 1983# no clean way to get an object from an archetype - stupid idiotic
1911# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 1984# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
1912 1985
1913object *new (const char *archetype = 0) 1986object *new (utf8_string archetype = 0)
1914 PROTOTYPE: ;$ 1987 PROTOTYPE: ;$
1915 CODE: 1988 CODE:
1916 RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); 1989 RETVAL = archetype ? get_archetype (archetype) : cf_create_object ();
1917 OUTPUT: 1990 OUTPUT:
1918 RETVAL 1991 RETVAL
1923{ 1996{
1924 int unused_type; 1997 int unused_type;
1925 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 1998 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
1926} 1999}
1927 2000
1928# syntatic sugar for easier use in event callbacks.
1929const char *options (object *op)
1930 CODE:
1931 RETVAL = op->name;
1932 OUTPUT:
1933 RETVAL
1934
1935player *contr (object *op) 2001player *contr (object *op)
1936 CODE: 2002 CODE:
1937 RETVAL = op->contr; 2003 RETVAL = op->contr;
1938 OUTPUT: RETVAL 2004 OUTPUT: RETVAL
1939 2005
1940const char *get_ob_key_value (object *op, const char *key) 2006const_utf8_string get_ob_key_value (object *op, utf8_string key)
1941 2007
1942bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) 2008bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1)
1943 2009
1944object *get_nearest_player (object *ob) 2010object *get_nearest_player (object *ob)
1945 ALIAS: nearest_player = 0 2011 ALIAS: nearest_player = 0
1946 PREINIT: 2012 PREINIT:
1947 extern object *get_nearest_player (object *); 2013 extern object *get_nearest_player (object *);
1963bool on_same_map_as (object *ob, object *other) 2029bool on_same_map_as (object *ob, object *other)
1964 CODE: 2030 CODE:
1965 RETVAL = on_same_map (ob, other); 2031 RETVAL = on_same_map (ob, other);
1966 OUTPUT: RETVAL 2032 OUTPUT: RETVAL
1967 2033
1968const char * 2034const_utf8_string
1969base_name (object *op, int plural = op->nrof > 1) 2035base_name (object *op, int plural = op->nrof > 1)
1970 CODE: 2036 CODE:
1971 RETVAL = query_base_name (op, plural); 2037 RETVAL = query_base_name (op, plural);
1972 OUTPUT: RETVAL 2038 OUTPUT: RETVAL
1973 2039
1980 RETVAL = op->contr; 2046 RETVAL = op->contr;
1981 OUTPUT: RETVAL 2047 OUTPUT: RETVAL
1982 2048
1983void check_score (object *op) 2049void check_score (object *op)
1984 2050
1985void message (object *op, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2051void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1986 CODE: 2052 CODE:
1987 new_draw_info (flags, 0, op, txt); 2053 new_draw_info (flags, 0, op, txt);
1988 2054
1989object *cf_player_send_inventory (object *op) 2055object *cf_player_send_inventory (object *op)
1990 2056
1991char *cf_player_get_ip (object *op) 2057octet_string cf_player_get_ip (object *op)
1992 ALIAS: ip = 0 2058 ALIAS: ip = 0
1993 2059
1994object *cf_player_get_marked_item (object *op) 2060object *cf_player_get_marked_item (object *op)
1995 ALIAS: marked_item = 0 2061 ALIAS: marked_item = 0
1996 2062
2006void esrv_update_item (object *op, int what, object *item) 2072void esrv_update_item (object *op, int what, object *item)
2007 C_ARGS: what, op, item 2073 C_ARGS: what, op, item
2008 2074
2009void clear_los (object *op) 2075void clear_los (object *op)
2010 2076
2011int command_summon (object *op, char *params) 2077int command_summon (object *op, utf8_string params)
2012 2078
2013int command_arrest (object *op, char *params) 2079int command_arrest (object *op, utf8_string params)
2014
2015int command_kick (object *op, char *params)
2016
2017int command_banish (object *op, char *params)
2018 2080
2019 2081
2020MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 2082MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
2021 2083
2022INCLUDE: $PERL genacc player ../include/player.h | 2084INCLUDE: $PERL $srcdir/genacc player ../include/player.h |
2023 2085
2024int invoke (player *pl, int event, ...) 2086int invoke (player *pl, int event, ...)
2025 CODE: 2087 CODE:
2026 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); 2088 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER");
2027 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2089 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2040 pl->orig_stats = pl->ob->stats; 2102 pl->orig_stats = pl->ob->stats;
2041 2103
2042void cf_player_move (player *pl, int dir) 2104void cf_player_move (player *pl, int dir)
2043 2105
2044void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2106void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
2045
2046player *first ()
2047 CODE:
2048 RETVAL = first_player;
2049 OUTPUT: RETVAL
2050 2107
2051bool 2108bool
2052cell_visible (player *pl, int dx, int dy) 2109cell_visible (player *pl, int dx, int dy)
2053 CODE: 2110 CODE:
2054 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2111 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2107 RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); 2164 RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END);
2108 OUTPUT: RETVAL 2165 OUTPUT: RETVAL
2109 2166
2110SV *registry (maptile *map) 2167SV *registry (maptile *map)
2111 2168
2112INCLUDE: $PERL genacc maptile ../include/map.h | 2169INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h |
2113 2170
2114void 2171void
2115maptile::instantiate () 2172maptile::instantiate ()
2116 2173
2117maptile *new () 2174maptile *new ()
2131 EXTEND (SP, THIS->players); 2188 EXTEND (SP, THIS->players);
2132 for_all_players (pl) 2189 for_all_players (pl)
2133 if (pl->ob && pl->ob->map == THIS) 2190 if (pl->ob && pl->ob->map == THIS)
2134 PUSHs (sv_2mortal (to_sv (pl->ob))); 2191 PUSHs (sv_2mortal (to_sv (pl->ob)));
2135 } 2192 }
2193
2194void
2195maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2196 CODE:
2197{
2198 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2199 croak ("maptile::add_underlay: palette must be arrayref");
2200
2201 palette = SvRV (palette);
2202
2203 STRLEN idxlen;
2204 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2205
2206 for (int x = 0; x < THIS->width; ++x)
2207 for (int y = 0; y < THIS->height; ++y)
2208 {
2209 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2210 if (op->flag [FLAG_IS_FLOOR])
2211 goto skip_space;
2212
2213 {
2214 int offs = offset + y * stride + x;
2215 if (IN_RANGE_EXC (offs, 0, idxlen))
2216 {
2217 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2218 {
2219 object *ob = get_archetype (SvPVutf8_nolen (*elem));
2220 ob->flag [FLAG_NO_MAP_SAVE] = true;
2221 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2222 }
2223 }
2224 }
2225
2226 skip_space: ;
2227 }
2228}
2229
2230void
2231maptile::set_regiondata (SV *data, int offset, int stride, SV *palette)
2232 CODE:
2233{
2234 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2235 croak ("maptile::set_regiondata: palette must be arrayref");
2236
2237 palette = SvRV (palette);
2238
2239 STRLEN idxlen;
2240 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2241
2242 region **regionmap = (region **)malloc (
2243 (av_len ((AV *)palette) + 1) * sizeof (region *));
2244 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2245
2246 for (int i = av_len ((AV *)palette) + 1; i--; )
2247 regionmap [i] = region::find (
2248 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2249
2250 for (int y = 0; y < THIS->height; ++y)
2251 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2252
2253 sfree (THIS->regions, THIS->size ());
2254 free (THIS->regionmap);
2255
2256 THIS->regions = regions;
2257 THIS->regionmap = regionmap;
2258}
2136 2259
2137void play_sound_map (maptile *map, int x, int y, int sound_num) 2260void play_sound_map (maptile *map, int x, int y, int sound_num)
2138 2261
2139int out_of_map (maptile *map, int x, int y) 2262int out_of_map (maptile *map, int x, int y)
2140 2263
2222 2345
2223void fix_walls (maptile *map, int x, int y) 2346void fix_walls (maptile *map, int x, int y)
2224 2347
2225void fix_walls_around (maptile *map, int x, int y) 2348void fix_walls_around (maptile *map, int x, int y)
2226 2349
2227const char *
2228region_name (maptile *m)
2229 CODE:
2230 RETVAL = get_name_of_region_for_map (m);
2231 OUTPUT: RETVAL
2232
2233# worst xs function of my life 2350# worst xs function of my life
2234bool 2351bool
2235_create_random_map (\ 2352_create_random_map (\
2236 maptile *self,\ 2353 maptile *self,\
2237 char *wallstyle,\ 2354 utf8_string wallstyle,\
2238 char *wall_name,\ 2355 utf8_string wall_name,\
2239 char *floorstyle,\ 2356 utf8_string floorstyle,\
2240 char *monsterstyle,\ 2357 utf8_string monsterstyle,\
2241 char *treasurestyle,\ 2358 utf8_string treasurestyle,\
2242 char *layoutstyle,\ 2359 utf8_string layoutstyle,\
2243 char *doorstyle,\ 2360 utf8_string doorstyle,\
2244 char *decorstyle,\ 2361 utf8_string decorstyle,\
2245 char *origin_map,\ 2362 utf8_string origin_map,\
2246 char *final_map,\ 2363 utf8_string final_map,\
2247 char *exitstyle,\ 2364 utf8_string exitstyle,\
2248 char *this_map,\ 2365 utf8_string this_map,\
2249 char *exit_on_final_map,\ 2366 utf8_string exit_on_final_map,\
2250 int xsize,\ 2367 int xsize,\
2251 int ysize,\ 2368 int ysize,\
2252 int expand2x,\ 2369 int expand2x,\
2253 int layoutoptions1,\ 2370 int layoutoptions1,\
2254 int layoutoptions2,\ 2371 int layoutoptions2,\
2267 val64 total_map_hp,\ 2384 val64 total_map_hp,\
2268 int map_layout_style,\ 2385 int map_layout_style,\
2269 int treasureoptions,\ 2386 int treasureoptions,\
2270 int symmetry_used,\ 2387 int symmetry_used,\
2271 region *region,\ 2388 region *region,\
2272 char *custom\ 2389 utf8_string custom\
2273) 2390)
2274 CODE: 2391 CODE:
2275{ 2392{
2276 random_map_params rmp; 2393 random_map_params rmp;
2277 2394
2318 OUTPUT: 2435 OUTPUT:
2319 RETVAL 2436 RETVAL
2320 2437
2321MODULE = cf PACKAGE = cf::arch 2438MODULE = cf PACKAGE = cf::arch
2322 2439
2323archetype *find (const char *name) 2440archetype *find (utf8_string name)
2324 CODE: 2441 CODE:
2325 RETVAL = archetype::find (name); 2442 RETVAL = archetype::find (name);
2326 OUTPUT: 2443 OUTPUT:
2327 RETVAL 2444 RETVAL
2328 2445
2330 PROTOTYPE: 2447 PROTOTYPE:
2331 CODE: 2448 CODE:
2332 RETVAL = first_archetype; 2449 RETVAL = first_archetype;
2333 OUTPUT: RETVAL 2450 OUTPUT: RETVAL
2334 2451
2335INCLUDE: $PERL genacc archetype ../include/object.h | 2452INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h |
2336 2453
2337MODULE = cf PACKAGE = cf::party 2454MODULE = cf PACKAGE = cf::party
2338 2455
2339partylist *first () 2456partylist *first ()
2340 PROTOTYPE: 2457 PROTOTYPE:
2341 CODE: 2458 CODE:
2342 RETVAL = get_firstparty (); 2459 RETVAL = get_firstparty ();
2343 OUTPUT: RETVAL 2460 OUTPUT: RETVAL
2344 2461
2345INCLUDE: $PERL genacc partylist ../include/player.h | 2462INCLUDE: $PERL $srcdir/genacc partylist ../include/player.h |
2346 2463
2347MODULE = cf PACKAGE = cf::region 2464MODULE = cf PACKAGE = cf::region
2348 2465
2349region *first () 2466void
2350 PROTOTYPE: 2467list ()
2351 CODE: 2468 PPCODE:
2352 RETVAL = first_region; 2469 for_all_regions (rgn)
2353 OUTPUT: RETVAL 2470 XPUSHs (sv_2mortal (to_sv (rgn)));
2354 2471
2355region *find (char *name) 2472region *find (utf8_string name)
2356 PROTOTYPE: $ 2473 PROTOTYPE: $
2357 CODE: 2474 CODE:
2358 RETVAL = get_region_by_name (name); 2475 RETVAL = region::find (name);
2359 OUTPUT: RETVAL 2476 OUTPUT: RETVAL
2360 2477
2478region *find_fuzzy (utf8_string name)
2479 PROTOTYPE: $
2480 CODE:
2481 RETVAL = region::find_fuzzy (name);
2482 OUTPUT: RETVAL
2483
2361INCLUDE: $PERL genacc region ../include/map.h | 2484INCLUDE: $PERL $srcdir/genacc region ../include/map.h |
2362 2485
2363MODULE = cf PACKAGE = cf::living 2486MODULE = cf PACKAGE = cf::living
2364 2487
2365INCLUDE: $PERL genacc living ../include/living.h | 2488INCLUDE: $PERL $srcdir/genacc living ../include/living.h |
2366 2489
2367MODULE = cf PACKAGE = cf::settings 2490MODULE = cf PACKAGE = cf::settings
2368 2491
2369INCLUDE: $PERL genacc Settings ../include/global.h | 2492INCLUDE: $PERL $srcdir/genacc Settings ../include/global.h |
2370 2493
2371MODULE = cf PACKAGE = cf::client 2494MODULE = cf PACKAGE = cf::client
2372 2495
2373INCLUDE: $PERL genacc client ../include/client.h | 2496INCLUDE: $PERL $srcdir/genacc client ../include/client.h |
2374 2497
2375int invoke (client *ns, int event, ...) 2498int invoke (client *ns, int event, ...)
2376 CODE: 2499 CODE:
2377 if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT"); 2500 if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT");
2378 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2501 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2397 char *buf = SvPVbyte (packet, len); 2520 char *buf = SvPVbyte (packet, len);
2398 2521
2399 THIS->send_packet (buf, len); 2522 THIS->send_packet (buf, len);
2400} 2523}
2401 2524
2525MODULE = cf PACKAGE = cf::face PREFIX = face_
2526
2527INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h |
2528
2529faceidx face_find (utf8_string name, faceidx defidx = 0)
2530
2531faceidx alloc (utf8_string name)
2532 CODE:
2533{
2534 do
2535 {
2536 RETVAL = faces.size ();
2537 faces.resize (RETVAL + 1);
2538 }
2539 while (!RETVAL); // crude way to leave index 0
2540
2541 faces [RETVAL].name = name;
2542 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2543
2544 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL;
2545 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL;
2546}
2547 OUTPUT: RETVAL
2548
2549void set (faceidx idx, int visibility, int magicmap)
2550 CODE:
2551 faceinfo *f = face_info (idx);
2552 assert (f);
2553 f->visibility = visibility;
2554 f->magicmap = magicmap;
2555
2556void set_smooth (faceidx idx, faceidx smooth)
2557 CODE:
2558 faceinfo *f = face_info (idx);
2559 assert (f);
2560 f->smooth = smooth;
2561
2562void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2563 CODE:
2564{
2565 facedata *d = face_data (idx, faceset);
2566 assert (d);
2567 sv_to (data, d->data);
2568 STRLEN clen;
2569 char *cdata = SvPVbyte (chksum, clen);
2570 clen = min (CHKSUM_SIZE, clen);
2571
2572 if (memcmp (d->chksum, cdata, clen))
2573 {
2574 memcpy (d->chksum, cdata, clen);
2575
2576 // invalidate existing client face info
2577 for_all_clients (ns)
2578 if (ns->faceset == faceset)
2579 {
2580 ns->faces_sent [idx] = false;
2581 ns->force_newmap = true;
2582 }
2583 }
2584}
2585
2586void invalidate (faceidx idx)
2587 CODE:
2588 for_all_clients (ns)
2589 {
2590 ns->faces_sent [idx] = false;
2591 ns->force_newmap = true;
2592 }
2593
2594void invalidate_all ()
2595 CODE:
2596 for_all_clients (ns)
2597 {
2598 ns->faces_sent.reset ();
2599 ns->force_newmap = true;
2600 }
2601

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines