--- deliantra/server/server/cfperl.xs 2006/11/08 00:52:56 1.67 +++ deliantra/server/server/cfperl.xs 2007/05/28 21:28:36 1.216 @@ -1,43 +1,57 @@ -/*****************************************************************************/ -/* CrossFire, A Multiplayer game for the X Window System */ -/*****************************************************************************/ - /* - * This code is placed under the GNU General Public Licence (GPL) - * - * Copyright (C) 2001-2005 by Chachkoff Yann - * Copyright (C) 2006 by Marc Lehmann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. + * + * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 2001-2005,2007 by Chachkoff Yann + * Copyright (©) 2006,2007 by Marc Lehmann + * + * Crossfire TRT is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * The authors can be reached via e-mail to + */ + +#include "autoconf.h" #define PLUGIN_NAME "perl" #define PLUGIN_VERSION "cfperl 0.5" +#define CEDES_PER_TICK 5 + +#if HAVE_EXECINFO_H +# include +#endif + #include #include #include #include +#include "loader.h" #include "cfperl.h" #include "shstr.h" +#include +#if _POSIX_MEMLOCK +# include +#endif + #include #include #include +#include "CoroAPI.h" #include "perlxsi.c" extern sint64 *levels; // the experience table @@ -45,80 +59,249 @@ typedef object object_ornull; typedef maptile maptile_ornull; -typedef double val64; -#define newSVval64 newSVnv -#define SvVAL64 SvNV +typedef char *octet_string; +typedef char *utf8_string; +typedef const char *const_octet_string; +typedef const char *const_utf8_string; + +typedef std::string std__string; + +#if IVSIZE >= 8 + typedef IV val64; +# define newSVval64 newSViv +# define SvVAL64 SvIV +#else + typedef double val64; +# define newSVval64 newSVnv +# define SvVAL64 SvNV +#endif static f_plug_api gethook = cfapi_get_hooks; static f_plug_api object_set_property = cfapi_object_set_property; static f_plug_api object_insert = cfapi_object_insert; -static HV *obj_cache; static PerlInterpreter *perl; -static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; +double runtime; + +global gbl_ev; +static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; +static SV *sv_runtime, *sv_next_tick; + +bitset ev_want_event; +bitset ev_want_type; + +static HV + *stash_cf, + *stash_cf_object_wrap, + *stash_cf_object_player_wrap, + *stash_cf_player_wrap, + *stash_cf_map_wrap, + *stash_cf_client_wrap, + *stash_cf_arch_wrap, + *stash_cf_party_wrap, + *stash_cf_region_wrap, + *stash_cf_living_wrap; + +// helper cast function, returns super class * or 0 +template +static super * +is_a (attachable *at) +{ + //return dynamic_cast(at); // slower, safer + if (typeid (*at) == typeid (super)) + return static_cast(at); + else + return 0; +} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -static SV * -newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) +unordered_vector attachable::mortals; + +attachable::~attachable () { - SV *sv; + assert (!self); + assert (!cb); +} - if (!ptr) - return &PL_sv_undef; +int +attachable::refcnt_cnt () const +{ + return refcnt + (self ? SvREFCNT (self) - 1 : 0); +} + +void +attachable::sever_self () +{ + if (HV *self = this->self) + { + // keep a refcount because sv_unmagic might call attachable_free, + // which might clear self, causing sv_unmagic to crash on a now + // invalid object. + SvREFCNT_inc (self); + hv_clear (self); + sv_unmagic ((SV *)self, PERL_MAGIC_ext); + SvREFCNT_dec (self); - sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); - return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); + // self *must* be null now because thats sv_unmagic's job. + assert (!this->self); + } } -template -SV * -newSVattachable (attachable *obj, const char *klass) +void +attachable::optimise () { - if (!obj) - return &PL_sv_undef; + if (self + && SvREFCNT (self) == 1 + && !HvTOTALKEYS (self)) + sever_self (); +} - if (!obj->self) - obj->self = newSVptr (obj, klass); +// check wether the object really is dead +void +attachable::do_check () +{ + if (refcnt_cnt () > 0) + return; - return newSVsv (obj->self); + destroy (); } -static void -SVptr_cache_set (void *ptr, SV *sv) +void +attachable::do_destroy () { - hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0); + INVOKE_ATTACHABLE (DESTROY, this); + + if (cb) + { + SvREFCNT_dec (cb); + cb = 0; + } + + mortals.push_back (this); } -static SV * -SVptr_cache_get (void *ptr) +void +attachable::destroy () +{ + if (destroyed ()) + return; + + flags |= F_DESTROYED; + do_destroy (); + sever_self (); +} + +void +attachable::check_mortals () +{ + static int i = 0; + + for (;;) + { + if (i >= mortals.size ()) + { + i = 0; + + if (mortals.size () > 1000) + LOG (llevInfo, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); + + break; + } + + attachable *obj = mortals [i]; + +#if 0 + if (obj->self)//D make this an assert later + { + LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ()); + obj->sever_self (); + } +#endif + + if (obj->refcnt) + { + ++i; // further delay freeing + + if (!(i & 0x3ff)) + break; + } + else + { + mortals.erase (i); + obj->sever_self (); + delete obj; + } + } +} + +attachable & +attachable::operator =(const attachable &src) { - SV **he = hv_fetch (obj_cache, (char *)&ptr, sizeof (ptr), 0); + //if (self || cb) + //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); - return he ? *he : 0; + attach = src.attach; + return *this; } +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + static SV * -newSVptr_cached (void *ptr, const char *klass) +newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) { SV *sv; if (!ptr) return &PL_sv_undef; - sv = SVptr_cache_get (ptr); + sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); + return sv_bless (newRV_noinc ((SV *)hv), stash); +} - if (!sv) +static int +attachable_free (pTHX_ SV *sv, MAGIC *mg) +{ + attachable *at = (attachable *)mg->mg_ptr; + + //TODO: check if transaction behaviour is really required here + if (SV *self = (SV *)at->self) { - HV *hv = newHV (); - sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); - sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); + at->self = 0; + SvREFCNT_dec (self); + } - SVptr_cache_set (ptr, sv); + // next line makes sense, but most objects still have refcnt 0 by default + //at->refcnt_chk (); + return 0; +} + +MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; + +static SV * +newSVattachable (attachable *obj, HV *stash) +{ + if (!obj) + return &PL_sv_undef; + + if (!obj->self) + { + obj->self = newHV (); + sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); + + // now bless the object _once_ + return sv_bless (newRV_inc ((SV *)obj->self), stash); } + else + { + SV *sv = newRV_inc ((SV *)obj->self); - return newSVsv (sv); + if (Gv_AMG (stash)) // handle overload correctly, as the perl core does not + SvAMAGIC_on (sv); + + return sv; + } } static void @@ -169,23 +352,30 @@ inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } inline SV *to_sv (float v) { return newSVnv (v); } inline SV *to_sv (double v) { return newSVnv (v); } -inline SV *to_sv (player * v) { return newSVattachable (v, "cf::player::wrap"); } -inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); } -inline SV *to_sv (maptile * v) { return newSVattachable (v, "cf::map::wrap"); } -inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); } -inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); } -inline SV *to_sv (region * v) { return newSVptr (v, "cf::region::wrap"); } -inline SV *to_sv (living * v) { return newSVptr (v, "cf::living::wrap"); } +inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } +inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } +inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } +inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } +inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } +inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } +inline SV *to_sv (region * v) { return newSVptr (v, stash_cf_region_wrap); } +inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } inline SV *to_sv (object & v) { return to_sv (&v); } inline SV *to_sv (living & v) { return to_sv (&v); } -//TODO: -inline SV *to_sv (New_Face * v) { return to_sv (v->name); } -inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } +inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } +inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); } + +inline SV *to_sv (UUID v) +{ + char buf[128]; + snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); + return newSVpv (buf, 0); +} inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } -inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } //TODO: verify that all simple pointers are strdup-managed +inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } @@ -199,16 +389,18 @@ inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } -inline void sv_to (SV *sv, player * &v) { v = (player *)SvPTR_ornull (sv, "cf::player"); } -inline void sv_to (SV *sv, object * &v) { v = (object *)SvPTR_ornull (sv, "cf::object"); } -inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)SvPTR_ornull (sv, "cf::arch"); } -inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)SvPTR_ornull (sv, "cf::map"); } +inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } +inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } +inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } +inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } +inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } +inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } -inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO -inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } // TODO +//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } +inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } template inline void sv_to (SV *sv, refptr &v) { T *tmp; sv_to (sv, tmp); v = tmp; } @@ -216,6 +408,28 @@ template inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } +inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } +inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } +inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } +inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } + +inline void sv_to (SV *sv, std::string &v) +{ + STRLEN len; + char *data = SvPVbyte (sv, len); + v.assign (data, len); +} + +inline void sv_to (SV *sv, UUID &v) +{ + unsigned int version; + + if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version) + croak ("unparsable uuid: %s", SvPV_nolen (sv)); +} + +inline void sv_to (SV *sv, object::flags_t::reference v) { v = SvTRUE (sv); } + static SV * newSVdt_va (va_list &ap, data_type type) { @@ -259,6 +473,10 @@ sv = to_sv (va_arg (ap, maptile *)); break; + case DT_CLIENT: + sv = to_sv (va_arg (ap, client *)); + break; + case DT_PLAYER: sv = to_sv (va_arg (ap, player *)); break; @@ -327,7 +545,7 @@ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// SV * -registry_of (attachable_base *ext) +registry (attachable *ext) { if (!ext->cb) ext->cb = newAV (); @@ -335,448 +553,6 @@ return newRV_inc ((SV *)ext->cb); } -void attachable_base::clear () -{ - if (self) - { - if (cb) - if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) - INVOKE_OBJECT (DESTROY, static_cast(this)); - else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) - INVOKE_MAP (DESTROY, static_cast(this)); - - // disconnect Perl from C, to avoid crashes - sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); - - // clear the perl hash, might or might not be a good idea - hv_clear ((HV *)SvRV ((SV *)self)); - - SvREFCNT_dec (self); - self = 0; - } - - if (cb) - { - SvREFCNT_dec (cb); - cb = 0; - } - - attach = 0; -} - -void attachable_base::optimise () -{ - if (!self) - return; - - HV *hv = (HV *)SvRV ((SV *)self); - - if (SvREFCNT ((SV *)self) == 1 - && SvREFCNT ((SV *)hv) == 1 - && !HvKEYS (hv)) - { - SvREFCNT_dec ((SV *)self); - self = 0; - } -} - -void attachable_base::instantiate (data_type type, void *obj) -{ - dSP; - ENTER; - SAVETMPS; - PUSHMARK (SP); - EXTEND (SP, 2); - PUSHs (sv_2mortal (newSVdt (type, obj))); - PUSHs (sv_2mortal (newSVpv (attach, 0))); - - attach = 0; - - PUTBACK; - call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); - FREETMPS; - LEAVE; - - switch (type) - { - case DT_OBJECT: INVOKE_OBJECT (INSTANTIATE, obj); break; - case DT_MAP: INVOKE_MAP (INSTANTIATE, obj); break; - } -} - -///////////////////////////////////////////////////////////////////////////// - -void reattach (data_type type, void *obj) -{ - //TODO only do this when the object has _attachment's - - dSP; - ENTER; - SAVETMPS; - PUSHMARK (SP); - XPUSHs (sv_2mortal (newSVdt (type, obj))); - PUTBACK; - call_pv ("cf::reattach", G_DISCARD | G_VOID | G_EVAL); - FREETMPS; - LEAVE; - - switch (type) - { - case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break; - case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break; - case DT_MAP: INVOKE_MAP (REATTACH, obj); break; - } -} - -template -void reattach (attachable *obj) -{ - obj->optimise (); - - if (obj->self) - reattach ((data_type) cftype::dt, (subclass *)obj); -} - -#include "kw_hash.h" - -object_freezer::object_freezer () -: dynbuf (128 * 1024, 64 * 1024) -{ - av = newAV (); -} - -object_freezer::~object_freezer () -{ - SvREFCNT_dec (av); -} - -void object_freezer::put (attachable_base *ext) -{ - ext->optimise (); - - if (ext->self) - { - int idx = AvFILLp ((AV *)av) + 1; - av_store (av, idx, SvREFCNT_inc (ext->self)); - - add ((void *)"oid ", 4); - add ((sint32)idx); - add ('\n'); - } -} - -bool object_freezer::save (const char *filename) -{ - dSP; - ENTER; - SAVETMPS; - PUSHMARK (SP); - EXTEND (SP, 3); - PUSHs (sv_2mortal (newSVpv (filename, 0))); - PUSHs (sv_2mortal (newRV_noinc (newSVpvn ((char *)linearise (), size ())))); - PUSHs (sv_2mortal (newRV_inc ((SV *)av))); - PUTBACK; - call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); - FREETMPS; - LEAVE; -} - -char *object_freezer::as_string () -{ - dSP; - ENTER; - SAVETMPS; - PUSHMARK (SP); - EXTEND (SP, 3); - PUSHs (sv_2mortal (newRV_noinc (newSVpvn ((char *)linearise (), size ())))); - PUSHs (sv_2mortal (newRV_inc ((SV *)av))); - PUTBACK; - - char *res = call_pv ("cf::object_freezer_as_string", G_SCALAR | G_EVAL) > 0 - ? strdup (SvPVbyte_nolen (POPs)) - : strdup ("[fatal error]"); - - FREETMPS; - LEAVE; - - return res; -} - -int fprintf (object_freezer &freezer, const char *format, ...) -{ - va_list ap; - - va_start (ap, format); - - int len = vsnprintf ((char *)freezer.force (1024), 1024, format, ap); - - if (len >= 0) - freezer.alloc (len); - - va_end (ap); -} - -int fputs (const char *s, object_freezer &freezer) -{ - freezer.add (s); -} - -static const char thawer_eof[] = "\n\n\n\0\0\0"; - -object_thawer::object_thawer (const char *filename) -{ - static const char eof[] = "\n\n\n\0\0\0"; - - av = 0; - text = 0; - line = 0; - - if (filename) - { - dSP; - ENTER; - SAVETMPS; - PUSHMARK (SP); - XPUSHs (sv_2mortal (newSVpv (filename, 0))); - PUTBACK; - - if (2 == call_pv ("cf::object_thawer_load", G_ARRAY | G_EVAL)) - { - SPAGAIN; - - // second value - perl objects - { - SV *sv = POPs; - if (SvROK (sv)) - av = (AV *)SvREFCNT_inc (SvRV (sv)); - } - - // first value - text part, pad with 3 zeroes - { - SV *sv = POPs; - STRLEN len; - char *sv_ = SvPVbyte (sv, len); - text = newSV (len + sizeof (eof)); - SvCUR_set (text, len); - memcpy (SvPVX (text), sv_, len); - memcpy (SvEND (text), eof, sizeof (eof)); // just to be sure - - line = SvPVX (text); - } - } - - PUTBACK; - FREETMPS; - LEAVE; - } -} - -object_thawer::object_thawer (const char *data, AV *perlav) -{ - av = perlav; - text = newSVpv (data, 0); - sv_catpv (text, thawer_eof); - line = SvPVbyte_nolen (text); -} - -void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) -{ - if (!av || oid < 0) // this is actually an error of sorts - return; - - // we have to "re-instantiate"/reattach to an object, so nuke ext->attach - ext->clear (); - - SV **svp = av_fetch ((AV *)av, oid, 0); - - if (!svp || !SvROK (*svp)) - { - printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); - return; - } - - ext->self = *svp; *svp = &PL_sv_undef; - sv_magic (SvRV (ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); - - reattach (type, obj); -} - -object_thawer::~object_thawer () -{ - if (text) SvREFCNT_dec (text); - if (av) SvREFCNT_dec (av); -} - -char *fgets (char *s, int n, object_thawer &thawer) -{ - char *p = thawer.line; - char *q = s; - - if (!p) - return 0; - - while (--n) - { - if (!*p) - break; - - *q++ = *p; - - if (*p++ == '\n') - break; - } - - *q = 0; - thawer.line = p; - - return s == q ? 0 : s; -} - -keyword object_thawer::get_kv () -{ - if (!line) - return KW_EOF; - - for (;;) - { - char *p = line; - - if (!*p) - return KW_EOF; - - // parse keyword - while (*p > ' ') - p++; - - int klen = p - line; - - if (*p++ != '\n') - { - // parse value - while (*(unsigned char *)p <= ' ' && *p != '\n') // skip 0x01 .. 0x20 - ++p; - - last_value = p; - - while (*p != '\n') - p++; - - *p++ = 0; - } - else - last_value = 0; - - line [klen] = 0; - keyword_idx *kw = kw_lex::match (line, klen); - - //printf ("KV %d<%s,%s>\n", kw ? kw->index : 0, line, last_value);//D - - if (kw) - { - line = p; - return kw->index; - } - else if (!*line || *line == '#') - { - // empty/comment line - line = p; - } - else - return KW_ERROR; - } -} - -void object_thawer::get (shstr &sh) const -{ - if (last_value) - sh = last_value; - else - { - sh = ""; - LOG (llevError, "keyword requires value: <%s>\n", line);//TODO: add filename - } -} - -void object_thawer::get_ml (keyword kend, shstr &sh) -{ - char kw[128]; - - int klen = keyword_len [kend]; - - kw [0] = '\n'; - memcpy (kw + 1, keyword_str [kend], klen); - kw [klen + 1] = '\n'; - kw [klen + 2] = 0; - - // first test for completely empty msg... "endXXX\n" - if (!strncmp (line, kw + 1, klen + 1)) - { - sh = 0; - - line += klen + 1; - - return; - } - else - { - // multi-line strings are delimited by "\nendXXX\n" or "endXXX\n" (NULL) - - char *end = strstr (line, kw); - - if (!end) - { - sh = 0; - return; - } - - *end = 0; - sh = line; - - line = end + keyword_len [kend] + 1; - - while (*line++ != '\n') - ; - } -} - -sint32 object_thawer::get_sint32 () const -{ - char *p = last_value; - - if (!p) - return 0; - - sint32 val = 0; - bool negate; - - if (*p == '-') - { - negate = true; - ++p; - } - else - negate = false; - - do - { - val *= 10; - val += *p++ - '0'; - } - while (*p); - - return negate ? -val : val; -} - -sint64 object_thawer::get_sint64 () const -{ - return last_value ? atoll (last_value) : 0; -} - -double object_thawer::get_double () const -{ - return last_value ? atof (last_value) : 0; -} - ///////////////////////////////////////////////////////////////////////////// extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) @@ -789,34 +565,7 @@ static int runPluginCommand (object *obj, char *params) { - dSP; - - ENTER; - SAVETMPS; - - PUSHMARK (SP); - - EXTEND (SP, 3); - PUSHs (sv_2mortal (newSVpv (rtn_cmd.name, 0))); - PUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, obj))); - - if (params) - PUSHs (sv_2mortal (newSVpv (params, 0))); - - PUTBACK; - int count = call_pv ("cf::inject_command", G_SCALAR | G_EVAL); - SPAGAIN; - - if (SvTRUE (ERRSV)) - LOG (llevError, "command '%s' callback evaluation error: %s", rtn_cmd.name, SvPV_nolen (ERRSV)); - - int returnvalue = count > 0 ? POPi : -1; - - PUTBACK; - FREETMPS; - LEAVE; - - return returnvalue; + return -1; } extern "C" void *cfperl_getPluginProperty (int *type, ...) @@ -829,35 +578,16 @@ //printf ("Property name: %s\n", propname); if (!strcmp (propname, "command?")) - { - if (!perl) - return NULL; - - const char *cmdname = va_arg (args, const char *); - HV *hv = get_hv ("cf::COMMAND", 1); - SV **svp = hv_fetch (hv, cmdname, strlen (cmdname) + 1, 0); - - va_end (args); - - if (svp) - { - // this is totaly broken, should stash it into %COMMAND - rtn_cmd.name = cmdname; - rtn_cmd.time = SvNV (*svp); - rtn_cmd.func = runPluginCommand; - - return &rtn_cmd; - } - } + return NULL; else if (!strcmp (propname, "Identification")) { va_end (args); - return (void*) PLUGIN_NAME; + return (void *)PLUGIN_NAME; } else if (!strcmp (propname, "FullName")) { va_end (args); - return (void*) PLUGIN_VERSION; + return (void *)PLUGIN_VERSION; } else va_end (args); @@ -889,21 +619,29 @@ PL_exit_flags |= PERL_EXIT_DESTRUCT_END; - char *argv[] = { - "", + const char *argv[] = { + settings.argv [0], "-e" - "cf->bootstrap;" + "use Event; use Coro;" // required for bootstrap + "cf->bootstrap;" // required for datadir :*> "unshift @INC, cf::datadir ();" "require cf;" }; - if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) + if (perl_parse (perl, xs_init, 2, (char **)argv, (char **)NULL) + || perl_run (perl)) { printf ("unable to initialize perl-interpreter, aborting.\n"); exit (EXIT_FAILURE); } - obj_cache = newHV (); + { + dSP; + + PUSHMARK (SP); + PUTBACK; + call_pv ("cf::init", G_DISCARD | G_VOID); + } } void cfperl_main () @@ -915,6 +653,24 @@ call_pv ("cf::main", G_DISCARD | G_VOID); } +void +attachable::instantiate () +{ + if (attach) + { + INVOKE_ATTACHABLE (INSTANTIATE, this, ARG_STRING (attach)); + attach = 0; + } +} + +void +attachable::reattach () +{ + optimise (); + //TODO: check for _attachment's, very important for restarts + INVOKE_ATTACHABLE (REATTACH, this); +} + static event_klass klass_of[NUM_EVENT_TYPES] = { # define def(type,name) KLASS_ ## type, # include "eventinc.h" @@ -953,109 +709,155 @@ } } -bool cfperl_invoke (event_type event, ...) +void +attachable::gather_callbacks (AV *&callbacks, event_type event) const { - data_type dt; - va_list ap; + ::gather_callbacks (callbacks, cb_attachable, event); - va_start (ap, event); - - AV *callbacks = 0; + if (cb) + ::gather_callbacks (callbacks, cb, event); +} - object *op; - player *pl; - maptile *map; +void +global::gather_callbacks (AV *&callbacks, event_type event) const +{ + ::gather_callbacks (callbacks, cb_global, event); +} - // callback call ordering is: - // 1. per-object callback (NYI) - // 2. per-class object - // 2a. per-type callback - // 4. global callbacks +void +object::gather_callbacks (AV *&callbacks, event_type event) const +{ + if (subtype && type + subtype * NUM_TYPES <= AvFILLp (cb_type)) + { + SV *registry = AvARRAY (cb_type)[type + subtype * NUM_TYPES]; - gather_callbacks (callbacks, cb_global, event); + if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) + ::gather_callbacks (callbacks, (AV *)SvRV (registry), event); + } - switch (KLASS_OF (event)) + if (type <= AvFILLp (cb_type)) { - case KLASS_GLOBAL: - break; + SV *registry = AvARRAY (cb_type)[type]; - case KLASS_OBJECT: - dt = (data_type) va_arg (ap, int); - assert (("first argument must be of type object", dt == DT_OBJECT)); - op = va_arg (ap, object *); + if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) + ::gather_callbacks (callbacks, (AV *)SvRV (registry), event); + } - if (op->cb) - gather_callbacks (callbacks, op->cb, event); + attachable::gather_callbacks (callbacks, event); + ::gather_callbacks (callbacks, cb_object, event); +} - if (op->type) - { - if (op->subtype && op->type + op->subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) - { - SV *registry = AvARRAY (cb_type)[op->type + op->subtype * NUM_SUBTYPES]; +void +archetype::gather_callbacks (AV *&callbacks, event_type event) const +{ + attachable::gather_callbacks (callbacks, event); + //TODO//::gather_callbacks (callbacks, cb_archetype, event); +} - if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) - gather_callbacks (callbacks, (AV *)SvRV (registry), event); - } +void +client::gather_callbacks (AV *&callbacks, event_type event) const +{ + attachable::gather_callbacks (callbacks, event); + ::gather_callbacks (callbacks, cb_client, event); +} - if (op->type <= AvFILLp (cb_type)) - { - SV *registry = AvARRAY (cb_type)[op->type]; +void +player::gather_callbacks (AV *&callbacks, event_type event) const +{ + attachable::gather_callbacks (callbacks, event); + ::gather_callbacks (callbacks, cb_player, event); +} - if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) - gather_callbacks (callbacks, (AV *)SvRV (registry), event); - } - } +void +maptile::gather_callbacks (AV *&callbacks, event_type event) const +{ + attachable::gather_callbacks (callbacks, event); + ::gather_callbacks (callbacks, cb_map, event); +} - gather_callbacks (callbacks, cb_object, event); +void +_recalc_want (bitset &set, AV *registry) +{ + for (int event = 0; event <= AvFILLp (registry); ++event) + { + SV *cbs_ = AvARRAY (registry)[event]; - break; + // element must be list of callback entries + if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV) + { + AV *cbs = (AV *)SvRV (cbs_); - case KLASS_PLAYER: - dt = (data_type) va_arg (ap, int); - assert (("first argument must be of type player", dt == DT_PLAYER)); - pl = va_arg (ap, player *); + // no callback entries, no callbacks to call + if (AvFILLp (cbs) >= 0) + set.set (event); + } + } +} - if (pl->cb) - gather_callbacks (callbacks, pl->cb, event); +// very slow and inefficient way to recalculate the global want bitsets +void +_recalc_want () +{ + ev_want_event.reset (); - gather_callbacks (callbacks, cb_player, event); - break; + _recalc_want (ev_want_event, cb_global); + _recalc_want (ev_want_event, cb_attachable); + _recalc_want (ev_want_event, cb_object); + _recalc_want (ev_want_event, cb_client); + _recalc_want (ev_want_event, cb_player); + _recalc_want (ev_want_event, cb_map); - case KLASS_MAP: - dt = (data_type) va_arg (ap, int); - assert (("first argument must be of type object", dt == DT_MAP)); - map = va_arg (ap, maptile *); + ev_want_type.reset (); - if (map->cb) - gather_callbacks (callbacks, map->cb, event); + for (int type = 0; type <= AvFILLp (cb_type); ++type) + { + SV *cbs_ = AvARRAY (cb_type)[type]; - gather_callbacks (callbacks, cb_map, event); - break; + // element must be list of callback entries + if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV) + { + AV *cbs = (AV *)SvRV (cbs_); - default: - assert (("unsupported event klass in cfperl_invoke", 0)); + // no callback entries, no callbacks to call + if (AvFILLp (cbs) >= 0) + ev_want_type.set (type % NUM_TYPES); + } } +} + +bool +attachable::invoke (event_type event, ...) +{ + data_type dt; + + // callback call ordering should be: + // 1. per-object callback + // 2. per-class object + // 3. per-type callback + // 4. global callbacks + + AV *callbacks = 0; + gather_callbacks (callbacks, event); // short-circuit processing if no callbacks found/defined if (!callbacks) return 0; - dSP; - ENTER; - SAVETMPS; - - PUSHMARK (SP); - EXTEND (SP, 3); - - PUSHs (sv_2mortal (newSViv (event))); // only used for debugging nowadays - PUSHs (sv_2mortal (newRV_noinc ((SV *)callbacks))); + va_list ap; + va_start (ap, event); - switch (KLASS_OF (event)) - { - case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; - case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; - case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; - } + CALL_BEGIN (3); + CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays + CALL_ARG_SV (newRV_noinc ((SV *)callbacks)); + + //TODO: unhack + if (object *op = is_a(this)) CALL_ARG_SV (newSVdt (DT_OBJECT, op)); + else if (player *pl = is_a(this)) CALL_ARG_SV (newSVdt (DT_PLAYER, pl)); + else if (client *ns = is_a(this)) CALL_ARG_SV (newSVdt (DT_CLIENT, ns)); + else if (maptile *m = is_a(this)) CALL_ARG_SV (newSVdt (DT_MAP, m)); + else if (global *gl = is_a(this)) /*nop*/; + else + abort (); //TODO for (;;) { @@ -1063,8 +865,7 @@ if (dt == DT_END) break; - - if (dt == DT_AV) + else if (dt == DT_AV) { AV *av = va_arg (ap, AV *); @@ -1077,14 +878,10 @@ va_end (ap); - PUTBACK; - int count = call_pv ("cf::do_invoke", G_SCALAR | G_EVAL); - SPAGAIN; - + CALL_CALL ("cf::do_invoke", G_SCALAR); count = count > 0 ? POPi : 0; - FREETMPS; - LEAVE; + CALL_END; return count; } @@ -1109,509 +906,524 @@ return SvIV (cfperl_result (idx)); } +double +cfperl_result_DOUBLE (int idx) +{ + return SvNV (cfperl_result (idx)); +} + +///////////////////////////////////////////////////////////////////////////// + +void +cfperl_emergency_save () +{ + CALL_BEGIN (0); + CALL_CALL ("cf::emergency_save", G_VOID); + CALL_END; +} + +void +cfperl_cleanup (int make_core) +{ + CALL_BEGIN (1); + CALL_ARG (make_core); + CALL_CALL ("cf::post_cleanup", G_VOID); + CALL_END; +} + +void +cfperl_make_book (object *book, int level) +{ + CALL_BEGIN (2); + CALL_ARG (book); + CALL_ARG (level); + CALL_CALL ("ext::books::make_book", G_VOID); + CALL_END; +} + +maptile * +maptile::find_sync (const char *path, maptile *origin) +{ + CALL_BEGIN (2); + CALL_ARG (path); + CALL_ARG (origin); + CALL_CALL ("cf::map::find_sync", G_SCALAR); + + maptile *retval; + + if (count) + sv_to (POPs, retval); + else + retval = 0; + + CALL_END; + + return retval; +} + +maptile * +maptile::find_async (const char *path, maptile *origin) +{ + CALL_BEGIN (2); + CALL_ARG (path); + CALL_ARG (origin); + CALL_CALL ("cf::map::find_async", G_SCALAR); + + maptile *retval; + + if (count) + sv_to (POPs, retval); + else + retval = 0; + + CALL_END; + + return retval; +} + +void +maptile::do_load_sync () +{ + CALL_BEGIN (1); + CALL_ARG (this); + CALL_CALL ("cf::map::do_load_sync", G_SCALAR); + CALL_END; +} + +void +maptile::change_all_map_light (int change) +{ + CALL_BEGIN (1); + CALL_ARG (change); + CALL_CALL ("cf::map::change_all_map_light", G_VOID); + CALL_END; +} + +void +object::enter_exit (object *exit) +{ + if (type != PLAYER) + return; + + CALL_BEGIN (2); + CALL_ARG (this); + CALL_ARG (exit); + CALL_CALL ("cf::object::player::enter_exit", G_VOID); + CALL_END; +} + +void +log_backtrace (const char *msg) +{ +#if HAVE_BACKTRACE + void *addr [20]; + int size = backtrace (addr, 20); + + CALL_BEGIN (size); + CALL_ARG (msg); + for (int i = 0; i < size; ++i) + CALL_ARG ((IV)addr [i]); + CALL_CALL ("cf::_log_backtrace", G_VOID); + CALL_END; +#endif +} + +///////////////////////////////////////////////////////////////////////////// + +struct EventAPI *watcher_base::GEventAPI; +struct CoroAPI *coroapi::GCoroAPI; + +int coroapi::cede_counter; +double (*coroapi::time)(); +double coroapi::next_cede; + +void coroapi::do_cede_to_tick () +{ + cede_counter = 0; + + cede (); + + next_cede += (TICK / CEDES_PER_TICK) * 0.99; + if (next_cede > SvNV (sv_next_tick) - 0.02) + next_cede = SvNV (sv_next_tick); +} + +void coroapi::do_cede_every () +{ + cede_counter = 0; + + if (coroapi::nready ()) + coroapi::cede (); +} + +void coroapi::do_cede_to_tick_every () +{ + cede_counter = 0; + + cede_to_tick (); +} + +void +coroapi::wait_for_tick () +{ + CALL_BEGIN (0); + CALL_CALL ("cf::wait_for_tick", G_DISCARD); + CALL_END; +} + +void +coroapi::wait_for_tick_begin () +{ + CALL_BEGIN (0); + CALL_CALL ("cf::wait_for_tick_begin", G_DISCARD); + CALL_END; +} + +static void +iw_dispatch (pe_event *ev) +{ + iw *w = (iw *)ev->ext_data; + w->call (*w); +} + +void +iw::alloc () +{ + pe = GEventAPI->new_idle (0, 0); + + WaREENTRANT_off (pe); + pe->base.callback = (void *)iw_dispatch; + pe->base.ext_data = (void *)this; +} + +static void iow_dispatch (pe_event *ev) +{ + iow *w = (iow *)ev->ext_data; + w->call (*w, ((pe_ioevent *)ev)->got); +} + +void +iow::alloc () +{ + pe = GEventAPI->new_io (0, 0); + + WaREENTRANT_off (pe); + pe->base.callback = (void *)iow_dispatch; + pe->base.ext_data = (void *)this; + + pe->fd = -1; + pe->poll = 0; +} + +void +iow::fd (int fd) +{ + pe->fd = fd; +} + +int +iow::poll () +{ + return pe->poll; +} + +void +iow::poll (int events) +{ + if (pe->poll != events) + { + if (pe->poll) stop (); + pe->poll = events; + if (pe->poll) start (); + } +} + +void +_connect_to_perl () +{ + stash_cf = gv_stashpv ("cf" , 1); + + stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); + stash_cf_object_player_wrap = gv_stashpv ("cf::object::player::wrap", 1); + stash_cf_player_wrap = gv_stashpv ("cf::player::wrap", 1); + stash_cf_map_wrap = gv_stashpv ("cf::map::wrap" , 1); + stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); + stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); + stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); + stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); + stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); + + sv_runtime = get_sv ("cf::RUNTIME" , 1); sv_upgrade (sv_runtime , SVt_NV); + sv_next_tick = get_sv ("cf::NEXT_TICK", 1); sv_upgrade (sv_next_tick, SVt_NV); + + cb_global = get_av ("cf::CB_GLOBAL", 1); + cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); + cb_object = get_av ("cf::CB_OBJECT", 1); + cb_player = get_av ("cf::CB_PLAYER", 1); + cb_client = get_av ("cf::CB_CLIENT", 1); + cb_type = get_av ("cf::CB_TYPE" , 1); + cb_map = get_av ("cf::CB_MAP" , 1); +} + MODULE = cf PACKAGE = cf PREFIX = cf_ BOOT: { - HV *stash = gv_stashpv ("cf", 1); + I_EVENT_API (PACKAGE); watcher_base::GEventAPI = GEventAPI; + I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; + + _connect_to_perl (); + + newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); - newCONSTSUB (stash, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); + { + require_pv ("Time::HiRes"); + + SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); + if (!svp) croak ("Time::HiRes is required"); + if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); + coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); + } static const struct { const char *name; IV iv; } *civ, const_iv[] = { # define const_iv(name) { # name, (IV)name }, - const_iv (llevError) - const_iv (llevInfo) - const_iv (llevDebug) - const_iv (llevMonster) + const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) + const_iv (logBacktrace) + + const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) + + const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) const_iv (MAX_TIME) - const_iv (PLAYER) - const_iv (TRANSPORT) - const_iv (ROD) - const_iv (TREASURE) - const_iv (POTION) - const_iv (FOOD) - const_iv (POISON) - const_iv (BOOK) - const_iv (CLOCK) - const_iv (LIGHTNING) - const_iv (ARROW) - const_iv (BOW) - const_iv (WEAPON) - const_iv (ARMOUR) - const_iv (PEDESTAL) - const_iv (ALTAR) - const_iv (LOCKED_DOOR) - const_iv (SPECIAL_KEY) - const_iv (MAP) - const_iv (DOOR) - const_iv (KEY) - const_iv (TIMED_GATE) - const_iv (TRIGGER) - const_iv (GRIMREAPER) - const_iv (MAGIC_EAR) - const_iv (TRIGGER_BUTTON) - const_iv (TRIGGER_ALTAR) - const_iv (TRIGGER_PEDESTAL) - const_iv (SHIELD) - const_iv (HELMET) - const_iv (HORN) - const_iv (MONEY) - const_iv (CLASS) - const_iv (GRAVESTONE) - const_iv (AMULET) - const_iv (PLAYERMOVER) - const_iv (TELEPORTER) - const_iv (CREATOR) - const_iv (SKILL) - const_iv (EXPERIENCE) - const_iv (EARTHWALL) - const_iv (GOLEM) - const_iv (THROWN_OBJ) - const_iv (BLINDNESS) - const_iv (GOD) - const_iv (DETECTOR) - const_iv (TRIGGER_MARKER) - const_iv (DEAD_OBJECT) - const_iv (DRINK) - const_iv (MARKER) - const_iv (HOLY_ALTAR) - const_iv (PLAYER_CHANGER) - const_iv (BATTLEGROUND) - const_iv (PEACEMAKER) - const_iv (GEM) - const_iv (FIREWALL) - const_iv (ANVIL) - const_iv (CHECK_INV) - const_iv (MOOD_FLOOR) - const_iv (EXIT) - const_iv (ENCOUNTER) - const_iv (SHOP_FLOOR) - const_iv (SHOP_MAT) - const_iv (RING) - const_iv (FLOOR) - const_iv (FLESH) - const_iv (INORGANIC) - const_iv (SKILL_TOOL) - const_iv (LIGHTER) - const_iv (TRAP_PART) - const_iv (WALL) - const_iv (LIGHT_SOURCE) - const_iv (MISC_OBJECT) - const_iv (MONSTER) - const_iv (SPAWN_GENERATOR) - const_iv (LAMP) - const_iv (DUPLICATOR) - const_iv (TOOL) - const_iv (SPELLBOOK) - const_iv (BUILDFAC) - const_iv (CLOAK) - const_iv (SPINNER) - const_iv (GATE) - const_iv (BUTTON) - const_iv (CF_HANDLE) - const_iv (HOLE) - const_iv (TRAPDOOR) - const_iv (SIGN) - const_iv (BOOTS) - const_iv (GLOVES) - const_iv (SPELL) - const_iv (SPELL_EFFECT) - const_iv (CONVERTER) - const_iv (BRACERS) - const_iv (POISONING) - const_iv (SAVEBED) - const_iv (POISONCLOUD) - const_iv (FIREHOLES) - const_iv (WAND) - const_iv (SCROLL) - const_iv (DIRECTOR) - const_iv (GIRDLE) - const_iv (FORCE) - const_iv (POTION_EFFECT) - const_iv (EVENT_CONNECTOR) - const_iv (CLOSE_CON) - const_iv (CONTAINER) - const_iv (ARMOUR_IMPROVER) - const_iv (WEAPON_IMPROVER) - const_iv (SKILLSCROLL) - const_iv (DEEP_SWAMP) - const_iv (IDENTIFY_ALTAR) - const_iv (MENU) - const_iv (RUNE) - const_iv (TRAP) - const_iv (POWER_CRYSTAL) - const_iv (CORPSE) - const_iv (DISEASE) - const_iv (SYMPTOM) - const_iv (BUILDER) - const_iv (MATERIAL) - const_iv (ITEM_TRANSFORMER) - const_iv (QUEST) - - const_iv (NUM_SUBTYPES) - - const_iv (ST_BD_BUILD) - const_iv (ST_BD_REMOVE) - - const_iv (ST_MAT_FLOOR) - const_iv (ST_MAT_WALL) - const_iv (ST_MAT_ITEM) - - const_iv (AT_PHYSICAL) - const_iv (AT_MAGIC) - const_iv (AT_FIRE) - const_iv (AT_ELECTRICITY) - const_iv (AT_COLD) - const_iv (AT_CONFUSION) - const_iv (AT_ACID) - const_iv (AT_DRAIN) - const_iv (AT_WEAPONMAGIC) - const_iv (AT_GHOSTHIT) - const_iv (AT_POISON) - const_iv (AT_SLOW) - const_iv (AT_PARALYZE) - const_iv (AT_TURN_UNDEAD) - const_iv (AT_FEAR) - const_iv (AT_CANCELLATION) - const_iv (AT_DEPLETE) - const_iv (AT_DEATH) - const_iv (AT_CHAOS) - const_iv (AT_COUNTERSPELL) - const_iv (AT_GODPOWER) - const_iv (AT_HOLYWORD) - const_iv (AT_BLIND) - const_iv (AT_INTERNAL) - const_iv (AT_LIFE_STEALING) - const_iv (AT_DISEASE) - - const_iv (WEAP_HIT) - const_iv (WEAP_SLASH) - const_iv (WEAP_PIERCE) - const_iv (WEAP_CLEAVE) - const_iv (WEAP_SLICE) - const_iv (WEAP_STAB) - const_iv (WEAP_WHIP) - const_iv (WEAP_CRUSH) + + const_iv (NUM_BODY_LOCATIONS) + const_iv (body_range) const_iv (body_shield) const_iv (body_combat) + const_iv (body_arm) const_iv (body_torso) const_iv (body_head) + const_iv (body_neck) const_iv (body_skill) const_iv (body_finger) + const_iv (body_shoulder) const_iv (body_foot) const_iv (body_hand) + const_iv (body_wrist) const_iv (body_waist) + + const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) + const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK) + const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON) + const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR) + const_iv (SPECIAL_KEY) const_iv (MAP) const_iv (DOOR) const_iv (KEY) + const_iv (TIMED_GATE) const_iv (TRIGGER) const_iv (GRIMREAPER) const_iv (MAGIC_EAR) + const_iv (TRIGGER_BUTTON) const_iv (TRIGGER_ALTAR) const_iv (TRIGGER_PEDESTAL) const_iv (SHIELD) + const_iv (HELMET) const_iv (HORN) const_iv (MONEY) const_iv (CLASS) + const_iv (GRAVESTONE) const_iv (AMULET) const_iv (PLAYERMOVER) const_iv (TELEPORTER) + const_iv (CREATOR) const_iv (SKILL) const_iv (EARTHWALL) const_iv (GOLEM) + const_iv (THROWN_OBJ) const_iv (BLINDNESS) const_iv (GOD) const_iv (DETECTOR) + const_iv (TRIGGER_MARKER) const_iv (DEAD_OBJECT) const_iv (DRINK) const_iv (MARKER) + const_iv (HOLY_ALTAR) const_iv (PLAYER_CHANGER) const_iv (BATTLEGROUND) const_iv (PEACEMAKER) + const_iv (GEM) const_iv (FIREWALL) const_iv (ANVIL) const_iv (CHECK_INV) + const_iv (MOOD_FLOOR) const_iv (EXIT) const_iv (ENCOUNTER) const_iv (SHOP_FLOOR) + const_iv (SHOP_MAT) const_iv (RING) const_iv (FLOOR) const_iv (FLESH) + const_iv (INORGANIC) const_iv (SKILL_TOOL) const_iv (LIGHTER) const_iv (BUILDABLE_WALL) + const_iv (MISC_OBJECT) const_iv (LAMP) const_iv (DUPLICATOR) const_iv (SPELLBOOK) + const_iv (CLOAK) const_iv (SPINNER) const_iv (GATE) const_iv (BUTTON) + const_iv (CF_HANDLE) const_iv (HOLE) const_iv (TRAPDOOR) const_iv (SIGN) + const_iv (BOOTS) const_iv (GLOVES) const_iv (SPELL) const_iv (SPELL_EFFECT) + const_iv (CONVERTER) const_iv (BRACERS) const_iv (POISONING) const_iv (SAVEBED) + const_iv (WAND) const_iv (SCROLL) const_iv (DIRECTOR) const_iv (GIRDLE) + const_iv (FORCE) const_iv (POTION_EFFECT) const_iv (EVENT_CONNECTOR) const_iv (CLOSE_CON) + const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) + const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) + const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) + const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) + + const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES) + + const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) + const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) + + const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY) + const_iv (AT_COLD) const_iv (AT_CONFUSION) const_iv (AT_ACID) const_iv (AT_DRAIN) + const_iv (AT_WEAPONMAGIC) const_iv (AT_GHOSTHIT) const_iv (AT_POISON) const_iv (AT_SLOW) + const_iv (AT_PARALYZE) const_iv (AT_TURN_UNDEAD) const_iv (AT_FEAR) const_iv (AT_CANCELLATION) + const_iv (AT_DEPLETE) const_iv (AT_DEATH) const_iv (AT_CHAOS) const_iv (AT_COUNTERSPELL) + const_iv (AT_GODPOWER) const_iv (AT_HOLYWORD) const_iv (AT_BLIND) const_iv (AT_INTERNAL) + const_iv (AT_LIFE_STEALING) const_iv (AT_DISEASE) + + const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE) + const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH) const_iv (WEAP_BLUD) - const_iv (FLAG_ALIVE) - const_iv (FLAG_WIZ) - const_iv (FLAG_REMOVED) - const_iv (FLAG_FREED) - const_iv (FLAG_WAS_WIZ) - const_iv (FLAG_APPLIED) - const_iv (FLAG_UNPAID) - const_iv (FLAG_USE_SHIELD) - const_iv (FLAG_NO_PICK) - const_iv (FLAG_ANIMATE) - const_iv (FLAG_MONSTER) - const_iv (FLAG_FRIENDLY) - const_iv (FLAG_GENERATOR) - const_iv (FLAG_IS_THROWN) - const_iv (FLAG_AUTO_APPLY) - const_iv (FLAG_TREASURE) - const_iv (FLAG_PLAYER_SOLD) - const_iv (FLAG_SEE_INVISIBLE) - const_iv (FLAG_CAN_ROLL) - const_iv (FLAG_OVERLAY_FLOOR) - const_iv (FLAG_IS_TURNABLE) - const_iv (FLAG_IS_USED_UP) - const_iv (FLAG_IDENTIFIED) - const_iv (FLAG_REFLECTING) - const_iv (FLAG_CHANGING) - const_iv (FLAG_SPLITTING) - const_iv (FLAG_HITBACK) - const_iv (FLAG_STARTEQUIP) - const_iv (FLAG_BLOCKSVIEW) - const_iv (FLAG_UNDEAD) - const_iv (FLAG_SCARED) - const_iv (FLAG_UNAGGRESSIVE) - const_iv (FLAG_REFL_MISSILE) - const_iv (FLAG_REFL_SPELL) - const_iv (FLAG_NO_MAGIC) - const_iv (FLAG_NO_FIX_PLAYER) - const_iv (FLAG_IS_LIGHTABLE) - const_iv (FLAG_TEAR_DOWN) - const_iv (FLAG_RUN_AWAY) - const_iv (FLAG_PICK_UP) - const_iv (FLAG_UNIQUE) - const_iv (FLAG_NO_DROP) - const_iv (FLAG_WIZCAST) - const_iv (FLAG_CAST_SPELL) - const_iv (FLAG_USE_SCROLL) - const_iv (FLAG_USE_RANGE) - const_iv (FLAG_USE_BOW) - const_iv (FLAG_USE_ARMOUR) - const_iv (FLAG_USE_WEAPON) - const_iv (FLAG_USE_RING) - const_iv (FLAG_READY_RANGE) - const_iv (FLAG_READY_BOW) - const_iv (FLAG_XRAYS) - const_iv (FLAG_NO_APPLY) - const_iv (FLAG_IS_FLOOR) - const_iv (FLAG_LIFESAVE) - const_iv (FLAG_NO_STRENGTH) - const_iv (FLAG_SLEEP) - const_iv (FLAG_STAND_STILL) - const_iv (FLAG_RANDOM_MOVE) - const_iv (FLAG_ONLY_ATTACK) - const_iv (FLAG_CONFUSED) - const_iv (FLAG_STEALTH) - const_iv (FLAG_WIZPASS) - const_iv (FLAG_IS_LINKED) - const_iv (FLAG_CURSED) - const_iv (FLAG_DAMNED) - const_iv (FLAG_SEE_ANYWHERE) - const_iv (FLAG_KNOWN_MAGICAL) - const_iv (FLAG_KNOWN_CURSED) - const_iv (FLAG_CAN_USE_SKILL) - const_iv (FLAG_BEEN_APPLIED) - const_iv (FLAG_READY_SCROLL) - const_iv (FLAG_USE_ROD) - const_iv (FLAG_USE_HORN) - const_iv (FLAG_MAKE_INVIS) - const_iv (FLAG_INV_LOCKED) - const_iv (FLAG_IS_WOODED) - const_iv (FLAG_IS_HILLY) - const_iv (FLAG_READY_SKILL) - const_iv (FLAG_READY_WEAPON) - const_iv (FLAG_NO_SKILL_IDENT) - const_iv (FLAG_BLIND) - const_iv (FLAG_SEE_IN_DARK) - const_iv (FLAG_IS_CAULDRON) - const_iv (FLAG_NO_STEAL) - const_iv (FLAG_ONE_HIT) - const_iv (FLAG_CLIENT_SENT) - const_iv (FLAG_BERSERK) - const_iv (FLAG_NEUTRAL) - const_iv (FLAG_NO_ATTACK) - const_iv (FLAG_NO_DAMAGE) - const_iv (FLAG_OBJ_ORIGINAL) - const_iv (FLAG_OBJ_SAVE_ON_OVL) - const_iv (FLAG_ACTIVATE_ON_PUSH) - const_iv (FLAG_ACTIVATE_ON_RELEASE) - const_iv (FLAG_IS_WATER) - const_iv (FLAG_CONTENT_ON_GEN) - const_iv (FLAG_IS_A_TEMPLATE) - const_iv (FLAG_IS_BUILDABLE) - const_iv (FLAG_AFK) - - const_iv (NDI_BLACK) - const_iv (NDI_WHITE) - const_iv (NDI_NAVY) - const_iv (NDI_RED) - const_iv (NDI_ORANGE) - const_iv (NDI_BLUE) - const_iv (NDI_DK_ORANGE) - const_iv (NDI_GREEN) - const_iv (NDI_LT_GREEN) - const_iv (NDI_GREY) - const_iv (NDI_BROWN) - const_iv (NDI_GOLD) - const_iv (NDI_TAN) - const_iv (NDI_MAX_COLOR) - const_iv (NDI_COLOR_MASK) - const_iv (NDI_UNIQUE) + const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED) + const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD) + const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY) + const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD) + const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE) + const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING) + const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW) + const_iv (FLAG_UNDEAD) const_iv (FLAG_SCARED) const_iv (FLAG_UNAGGRESSIVE) const_iv (FLAG_REFL_MISSILE) + const_iv (FLAG_REFL_SPELL) const_iv (FLAG_NO_MAGIC) const_iv (FLAG_NO_FIX_PLAYER) const_iv (FLAG_IS_LIGHTABLE) + const_iv (FLAG_TEAR_DOWN) const_iv (FLAG_RUN_AWAY) const_iv (FLAG_PICK_UP) const_iv (FLAG_UNIQUE) + const_iv (FLAG_NO_DROP) const_iv (FLAG_WIZCAST) const_iv (FLAG_CAST_SPELL) const_iv (FLAG_USE_SCROLL) + const_iv (FLAG_USE_RANGE) const_iv (FLAG_USE_BOW) const_iv (FLAG_USE_ARMOUR) const_iv (FLAG_USE_WEAPON) + const_iv (FLAG_USE_RING) const_iv (FLAG_READY_RANGE) const_iv (FLAG_READY_BOW) const_iv (FLAG_XRAYS) + const_iv (FLAG_NO_APPLY) const_iv (FLAG_IS_FLOOR) const_iv (FLAG_LIFESAVE) const_iv (FLAG_NO_STRENGTH) + const_iv (FLAG_SLEEP) const_iv (FLAG_STAND_STILL) const_iv (FLAG_RANDOM_MOVE) const_iv (FLAG_ONLY_ATTACK) + const_iv (FLAG_CONFUSED) const_iv (FLAG_STEALTH) const_iv (FLAG_WIZPASS) const_iv (FLAG_IS_LINKED) + const_iv (FLAG_CURSED) const_iv (FLAG_DAMNED) const_iv (FLAG_SEE_ANYWHERE) const_iv (FLAG_KNOWN_MAGICAL) + const_iv (FLAG_KNOWN_CURSED) const_iv (FLAG_CAN_USE_SKILL) const_iv (FLAG_BEEN_APPLIED) const_iv (FLAG_READY_SCROLL) + const_iv (FLAG_USE_ROD) const_iv (FLAG_USE_HORN) const_iv (FLAG_MAKE_INVIS) const_iv (FLAG_INV_LOCKED) + const_iv (FLAG_IS_WOODED) const_iv (FLAG_IS_HILLY) const_iv (FLAG_READY_SKILL) const_iv (FLAG_READY_WEAPON) + const_iv (FLAG_NO_SKILL_IDENT) const_iv (FLAG_BLIND) const_iv (FLAG_SEE_IN_DARK) const_iv (FLAG_IS_CAULDRON) + const_iv (FLAG_NO_STEAL) const_iv (FLAG_ONE_HIT) const_iv (FLAG_CLIENT_SENT) const_iv (FLAG_BERSERK) + const_iv (FLAG_NEUTRAL) const_iv (FLAG_NO_ATTACK) const_iv (FLAG_NO_DAMAGE) const_iv (FLAG_OBJ_ORIGINAL) + const_iv (FLAG_OBJ_SAVE_ON_OVL) const_iv (FLAG_ACTIVATE_ON_PUSH) const_iv (FLAG_ACTIVATE_ON_RELEASE) const_iv (FLAG_IS_WATER) + const_iv (FLAG_CONTENT_ON_GEN) const_iv (FLAG_IS_A_TEMPLATE) const_iv (FLAG_IS_BUILDABLE) + const_iv (FLAG_DESTROY_ON_DEATH) const_iv (FLAG_NO_MAP_SAVE) + + const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED) + const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN) + const_iv (NDI_LT_GREEN) const_iv (NDI_GREY) const_iv (NDI_BROWN) const_iv (NDI_GOLD) + const_iv (NDI_TAN) const_iv (NDI_MAX_COLOR) const_iv (NDI_COLOR_MASK) const_iv (NDI_UNIQUE) const_iv (NDI_ALL) - const_iv (UPD_LOCATION) - const_iv (UPD_FLAGS) - const_iv (UPD_WEIGHT) - const_iv (UPD_FACE) - const_iv (UPD_NAME) - const_iv (UPD_ANIM) - const_iv (UPD_ANIMSPEED) - const_iv (UPD_NROF) - - const_iv (UPD_SP_MANA) - const_iv (UPD_SP_GRACE) - const_iv (UPD_SP_DAMAGE) - - const_iv (F_APPLIED) - const_iv (F_LOCATION) - const_iv (F_UNPAID) - const_iv (F_MAGIC) - const_iv (F_CURSED) - const_iv (F_DAMNED) - const_iv (F_OPEN) - const_iv (F_NOPICK) + const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) + const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) + + const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) + + const_iv (SP_RAISE_DEAD) + const_iv (SP_RUNE) + const_iv (SP_MAKE_MARK) + const_iv (SP_BOLT) + const_iv (SP_BULLET) + const_iv (SP_EXPLOSION) + const_iv (SP_CONE) + const_iv (SP_BOMB) + const_iv (SP_WONDER) + const_iv (SP_SMITE) + const_iv (SP_MAGIC_MISSILE) + const_iv (SP_SUMMON_GOLEM) + const_iv (SP_DIMENSION_DOOR) + const_iv (SP_MAGIC_MAPPING) + const_iv (SP_MAGIC_WALL) + const_iv (SP_DESTRUCTION) + const_iv (SP_PERCEIVE_SELF) + const_iv (SP_WORD_OF_RECALL) + const_iv (SP_INVISIBLE) + const_iv (SP_PROBE) + const_iv (SP_HEALING) + const_iv (SP_CREATE_FOOD) + const_iv (SP_EARTH_TO_DUST) + const_iv (SP_CHANGE_ABILITY) + const_iv (SP_BLESS) + const_iv (SP_CURSE) + const_iv (SP_SUMMON_MONSTER) + const_iv (SP_CHARGING) + const_iv (SP_POLYMORPH) + const_iv (SP_ALCHEMY) + const_iv (SP_REMOVE_CURSE) + const_iv (SP_IDENTIFY) + const_iv (SP_DETECTION) + const_iv (SP_MOOD_CHANGE) + const_iv (SP_MOVING_BALL) + const_iv (SP_SWARM) + const_iv (SP_CHANGE_MANA) + const_iv (SP_DISPEL_RUNE) + const_iv (SP_CREATE_MISSILE) + const_iv (SP_CONSECRATE) + const_iv (SP_ANIMATE_WEAPON) + const_iv (SP_LIGHT) + const_iv (SP_CHANGE_MAP_LIGHT) + const_iv (SP_FAERY_FIRE) + const_iv (SP_CAUSE_DISEASE) + const_iv (SP_AURA) + const_iv (SP_TOWN_PORTAL) + const_iv (SP_PARTY_SPELL) + + const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC) + const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK) const_iv (F_LOCKED) - const_iv (F_BUY) - const_iv (F_SHOP) - const_iv (F_SELL) - - const_iv (P_BLOCKSVIEW) - const_iv (P_NO_MAGIC) - const_iv (P_IS_ALIVE) - const_iv (P_NO_CLERIC) - const_iv (P_NEED_UPDATE) - const_iv (P_NO_ERROR) - const_iv (P_OUT_OF_MAP) - const_iv (P_NEW_MAP) - - const_iv (UP_OBJ_INSERT) - const_iv (UP_OBJ_REMOVE) - const_iv (UP_OBJ_CHANGE) - const_iv (UP_OBJ_FACE) - - const_iv (INS_NO_MERGE) - const_iv (INS_ABOVE_FLOOR_ONLY) - const_iv (INS_NO_WALK_ON) - const_iv (INS_ON_TOP) - const_iv (INS_BELOW_ORIGINATOR) - const_iv (INS_MAP_LOAD) - - const_iv (WILL_APPLY_HANDLE) - const_iv (WILL_APPLY_TREASURE) - const_iv (WILL_APPLY_EARTHWALL) - const_iv (WILL_APPLY_DOOR) - const_iv (WILL_APPLY_FOOD) - - const_iv (SAVE_MODE) - const_iv (SAVE_DIR_MODE) - - const_iv (M_PAPER) - const_iv (M_IRON) - const_iv (M_GLASS) - const_iv (M_LEATHER) - const_iv (M_WOOD) - const_iv (M_ORGANIC) - const_iv (M_STONE) - const_iv (M_CLOTH) - const_iv (M_ADAMANT) - const_iv (M_LIQUID) - const_iv (M_SOFT_METAL) - const_iv (M_BONE) - const_iv (M_ICE) - const_iv (M_SPECIAL) - - const_iv (SK_EXP_ADD_SKILL) - const_iv (SK_EXP_TOTAL) - const_iv (SK_EXP_NONE) - const_iv (SK_SUBTRACT_SKILL_EXP) - const_iv (SK_EXP_SKILL_ONLY) - - const_iv (SK_LOCKPICKING) - const_iv (SK_HIDING) - const_iv (SK_SMITHERY) - const_iv (SK_BOWYER) - const_iv (SK_JEWELER) - const_iv (SK_ALCHEMY) - const_iv (SK_STEALING) - const_iv (SK_LITERACY) - const_iv (SK_BARGAINING) - const_iv (SK_JUMPING) - const_iv (SK_DET_MAGIC) - const_iv (SK_ORATORY) - const_iv (SK_SINGING) - const_iv (SK_DET_CURSE) - const_iv (SK_FIND_TRAPS) - const_iv (SK_MEDITATION) - const_iv (SK_PUNCHING) - const_iv (SK_FLAME_TOUCH) - const_iv (SK_KARATE) - const_iv (SK_CLIMBING) - const_iv (SK_WOODSMAN) - const_iv (SK_INSCRIPTION) - const_iv (SK_ONE_HANDED_WEAPON) - const_iv (SK_MISSILE_WEAPON) - const_iv (SK_THROWING) - const_iv (SK_USE_MAGIC_ITEM) - const_iv (SK_DISARM_TRAPS) - const_iv (SK_SET_TRAP) - const_iv (SK_THAUMATURGY) - const_iv (SK_PRAYING) - const_iv (SK_CLAWING) - const_iv (SK_LEVITATION) - const_iv (SK_SUMMONING) - const_iv (SK_PYROMANCY) - const_iv (SK_EVOCATION) - const_iv (SK_SORCERY) - const_iv (SK_TWO_HANDED_WEAPON) - const_iv (SK_SPARK_TOUCH) - const_iv (SK_SHIVER) - const_iv (SK_ACID_SPLASH) + const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL) + + const_iv (P_BLOCKSVIEW) const_iv (P_PLAYER) const_iv (P_NO_MAGIC) const_iv (P_IS_ALIVE) + const_iv (P_NO_CLERIC) const_iv (P_OUT_OF_MAP) const_iv (P_NEW_MAP) const_iv (P_UPTODATE) + + const_iv (UP_OBJ_INSERT) const_iv (UP_OBJ_REMOVE) const_iv (UP_OBJ_CHANGE) const_iv (UP_OBJ_FACE) + + const_iv (INS_NO_MERGE) const_iv (INS_ABOVE_FLOOR_ONLY) const_iv (INS_NO_WALK_ON) + const_iv (INS_ON_TOP) const_iv (INS_BELOW_ORIGINATOR) const_iv (INS_MAP_LOAD) + + const_iv (WILL_APPLY_HANDLE) const_iv (WILL_APPLY_TREASURE) const_iv (WILL_APPLY_EARTHWALL) + const_iv (WILL_APPLY_DOOR) const_iv (WILL_APPLY_FOOD) + + const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) + + const_iv (M_PAPER) const_iv (M_IRON) const_iv (M_GLASS) const_iv (M_LEATHER) + const_iv (M_WOOD) const_iv (M_ORGANIC) const_iv (M_STONE) const_iv (M_CLOTH) + const_iv (M_ADAMANT) const_iv (M_LIQUID) const_iv (M_SOFT_METAL) const_iv (M_BONE) + const_iv (M_ICE) const_iv (M_SPECIAL) + + const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) + const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) + + const_iv (SK_LOCKPICKING) const_iv (SK_HIDING) const_iv (SK_SMITHERY) const_iv (SK_BOWYER) + const_iv (SK_JEWELER) const_iv (SK_ALCHEMY) const_iv (SK_STEALING) const_iv (SK_LITERACY) + const_iv (SK_BARGAINING) const_iv (SK_JUMPING) const_iv (SK_DET_MAGIC) const_iv (SK_ORATORY) + const_iv (SK_SINGING) const_iv (SK_DET_CURSE) const_iv (SK_FIND_TRAPS) const_iv (SK_MEDITATION) + const_iv (SK_PUNCHING) const_iv (SK_FLAME_TOUCH) const_iv (SK_KARATE) const_iv (SK_CLIMBING) + const_iv (SK_WOODSMAN) const_iv (SK_INSCRIPTION) const_iv (SK_ONE_HANDED_WEAPON) const_iv (SK_MISSILE_WEAPON) + const_iv (SK_THROWING) const_iv (SK_USE_MAGIC_ITEM) const_iv (SK_DISARM_TRAPS) const_iv (SK_SET_TRAP) + const_iv (SK_THAUMATURGY) const_iv (SK_PRAYING) const_iv (SK_CLAWING) const_iv (SK_LEVITATION) + const_iv (SK_SUMMONING) const_iv (SK_PYROMANCY) const_iv (SK_EVOCATION) const_iv (SK_SORCERY) + const_iv (SK_TWO_HANDED_WEAPON) const_iv (SK_SPARK_TOUCH) const_iv (SK_SHIVER) const_iv (SK_ACID_SPLASH) const_iv (SK_POISON_NAIL) - const_iv (SOUND_NEW_PLAYER) - const_iv (SOUND_FIRE_ARROW) - const_iv (SOUND_LEARN_SPELL) - const_iv (SOUND_FUMBLE_SPELL) - const_iv (SOUND_WAND_POOF) - const_iv (SOUND_OPEN_DOOR) - const_iv (SOUND_PUSH_PLAYER) - const_iv (SOUND_PLAYER_HITS1) - const_iv (SOUND_PLAYER_HITS2) - const_iv (SOUND_PLAYER_HITS3) - const_iv (SOUND_PLAYER_HITS4) - const_iv (SOUND_PLAYER_IS_HIT1) - const_iv (SOUND_PLAYER_IS_HIT2) - const_iv (SOUND_PLAYER_IS_HIT3) - const_iv (SOUND_PLAYER_KILLS) - const_iv (SOUND_PET_IS_KILLED) - const_iv (SOUND_PLAYER_DIES) - const_iv (SOUND_OB_EVAPORATE) - const_iv (SOUND_OB_EXPLODE) - const_iv (SOUND_CLOCK) - const_iv (SOUND_TURN_HANDLE) - const_iv (SOUND_FALL_HOLE) - const_iv (SOUND_DRINK_POISON) - const_iv (SOUND_CAST_SPELL_0) - - const_iv (PREFER_LOW) - const_iv (PREFER_HIGH) - - const_iv (ATNR_PHYSICAL) - const_iv (ATNR_MAGIC) - const_iv (ATNR_FIRE) - const_iv (ATNR_ELECTRICITY) - const_iv (ATNR_COLD) - const_iv (ATNR_CONFUSION) - const_iv (ATNR_ACID) - const_iv (ATNR_DRAIN) - const_iv (ATNR_WEAPONMAGIC) - const_iv (ATNR_GHOSTHIT) - const_iv (ATNR_POISON) - const_iv (ATNR_SLOW) - const_iv (ATNR_PARALYZE) - const_iv (ATNR_TURN_UNDEAD) - const_iv (ATNR_FEAR) - const_iv (ATNR_CANCELLATION) - const_iv (ATNR_DEPLETE) - const_iv (ATNR_DEATH) - const_iv (ATNR_CHAOS) - const_iv (ATNR_COUNTERSPELL) - const_iv (ATNR_GODPOWER) - const_iv (ATNR_HOLYWORD) - const_iv (ATNR_BLIND) - const_iv (ATNR_INTERNAL) - const_iv (ATNR_LIFE_STEALING) - const_iv (ATNR_DISEASE) - - const_iv (MAP_FLUSH) - const_iv (MAP_PLAYER_UNIQUE) - const_iv (MAP_BLOCK) - const_iv (MAP_STYLE) - const_iv (MAP_OVERLAY) - - const_iv (MAP_IN_MEMORY) - const_iv (MAP_SWAPPED) - const_iv (MAP_LOADING) - const_iv (MAP_SAVING) - - const_iv (KLASS_GLOBAL) - const_iv (KLASS_OBJECT) - const_iv (KLASS_PLAYER) - const_iv (KLASS_MAP) + const_iv (SOUND_NEW_PLAYER) const_iv (SOUND_FIRE_ARROW) const_iv (SOUND_LEARN_SPELL) const_iv (SOUND_FUMBLE_SPELL) + const_iv (SOUND_WAND_POOF) const_iv (SOUND_OPEN_DOOR) const_iv (SOUND_PUSH_PLAYER) const_iv (SOUND_PLAYER_HITS1) + const_iv (SOUND_PLAYER_HITS2) const_iv (SOUND_PLAYER_HITS3) const_iv (SOUND_PLAYER_HITS4) const_iv (SOUND_PLAYER_IS_HIT1) + const_iv (SOUND_PLAYER_IS_HIT2) const_iv (SOUND_PLAYER_IS_HIT3) const_iv (SOUND_PLAYER_KILLS) const_iv (SOUND_PET_IS_KILLED) + const_iv (SOUND_PLAYER_DIES) const_iv (SOUND_OB_EVAPORATE) const_iv (SOUND_OB_EXPLODE) const_iv (SOUND_CLOCK) + const_iv (SOUND_TURN_HANDLE) const_iv (SOUND_FALL_HOLE) const_iv (SOUND_DRINK_POISON) const_iv (SOUND_CAST_SPELL_0) + + const_iv (PREFER_LOW) const_iv (PREFER_HIGH) + + const_iv (ATNR_PHYSICAL) const_iv (ATNR_MAGIC) const_iv (ATNR_FIRE) const_iv (ATNR_ELECTRICITY) + const_iv (ATNR_COLD) const_iv (ATNR_CONFUSION) const_iv (ATNR_ACID) const_iv (ATNR_DRAIN) + const_iv (ATNR_WEAPONMAGIC) const_iv (ATNR_GHOSTHIT) const_iv (ATNR_POISON) const_iv (ATNR_SLOW) + const_iv (ATNR_PARALYZE) const_iv (ATNR_TURN_UNDEAD) const_iv (ATNR_FEAR) const_iv (ATNR_CANCELLATION) + const_iv (ATNR_DEPLETE) const_iv (ATNR_DEATH) const_iv (ATNR_CHAOS) const_iv (ATNR_COUNTERSPELL) + const_iv (ATNR_GODPOWER) const_iv (ATNR_HOLYWORD) const_iv (ATNR_BLIND) const_iv (ATNR_INTERNAL) + const_iv (ATNR_LIFE_STEALING) const_iv (ATNR_DISEASE) + + const_iv (MAP_IN_MEMORY) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING) + + const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) + const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) + + const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) + + const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) + + const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) + + // random map generator + const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL) + const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL) + + const_iv (RMOPT_RANDOM) const_iv (RMOPT_CENTERED) const_iv (RMOPT_LINEAR) + const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE) + const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS) + + const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) + const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) + + const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP) + const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV) + const_iv (GT_MINIMAL) }; for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) - newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); + newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); static const struct { const char *name; @@ -1632,53 +1444,124 @@ av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); av_push (event, newSViv (eiv->klass)); av_store (av, eiv->iv, newRV_noinc ((SV *)event)); - newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv)); + newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv)); } - - //I_EVENT_API (PACKAGE); } -void _init_vars () - CODE: - cb_global = get_av ("cf::CB_GLOBAL", 1); - cb_object = get_av ("cf::CB_OBJECT", 1); - cb_player = get_av ("cf::CB_PLAYER", 1); - cb_type = get_av ("cf::CB_TYPE" , 1); - cb_map = get_av ("cf::CB_MAP" , 1); +void _connect_to_perl () + +void _recalc_want () void _global_reattach () CODE: { // reattach to all attachable objects in the game. - for (player *pl = first_player; pl; pl = pl->next) - reattach (pl); + for_all_clients (ns) + ns->reattach (); - for (maptile *map = first_map; map; map = map->next) - reattach (map); + for_all_objects (op) + op->reattach (); +} + +void _post_tick () + CODE: + coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); + +# support function for map-world.ext +void _quantise (SV *data_sv, SV *plt_sv) + CODE: +{ + if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) + croak ("_quantise called with invalid agruments"); + + plt_sv = SvRV (plt_sv); + SV **plt = AvARRAY (plt_sv); + int plt_count = AvFILL (plt_sv) + 1; + + STRLEN len; + char *data = SvPVbyte (data_sv, len); + char *dst = data; + + while (len >= 3) + { + for (SV **val_sv = plt + plt_count; val_sv-- > plt; ) + { + char *val = SvPVX (*val_sv); - for (object *op = object::first; op; op = op->next) - reattach (op); + if (val [0] == data [0] + && val [1] == data [1] + && val [2] == data [2]) + { + *dst++ = val [3]; + goto next; + } + } + + croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d", + (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2], + dst - SvPVX (data_sv), len); + + next: + data += 3; + len -= 3; + } + + SvCUR_set (data_sv, dst - SvPVX (data_sv)); } NV floor (NV x) NV ceil (NV x) +NV rndm (...) + CODE: + switch (items) + { + case 0: RETVAL = rndm (); break; + case 1: RETVAL = rndm (SvUV (ST (0))); break; + case 2: RETVAL = rndm (SvIV (ST (0)), SvIV (ST (1))); break; + default: croak ("cf::rndm requires none, one or two parameters."); break; + } + OUTPUT: + RETVAL + +NV clamp (NV value, NV min_value, NV max_value) + CODE: + RETVAL = clamp (value, min_value, max_value); + OUTPUT: + RETVAL + +NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out) + CODE: + RETVAL = lerp (value, min_in, max_in, min_out, max_out); + OUTPUT: + RETVAL + +void cede_to_tick () + CODE: + coroapi::cede_to_tick (); + void server_tick () + CODE: + runtime = SvNVx (sv_runtime); + server_tick (); void -LOG (int level, char *msg) +log_backtrace (utf8_string msg) + +void +LOG (int flags, utf8_string msg) PROTOTYPE: $$ - C_ARGS: (LogLevel)level, "%s", msg + C_ARGS: flags, "%s", msg -char *path_combine (char *base, char *path) +octet_string path_combine (octet_string base, octet_string path) PROTOTYPE: $$ -char *path_combine_and_normalize (char *base, char *path) +octet_string path_combine_and_normalize (octet_string base, octet_string path) PROTOTYPE: $$ -const char * -get_maps_directory (char *path) +const_octet_string +get_maps_directory (octet_string path) PROTOTYPE: $ ALIAS: maps_directory = 0 CODE: @@ -1690,7 +1573,7 @@ CODE: PL_sub_generation++; -char * +const_octet_string mapdir () PROTOTYPE: ALIAS: @@ -1714,22 +1597,38 @@ } OUTPUT: RETVAL -void _exit (int status = 0) +void abort () -int cf_find_animation (char *text) - PROTOTYPE: $ +void reset_signals () + +void fork_abort (octet_string cause = "cf::fork_abort") + +void cleanup (octet_string cause, bool make_core = false) -int random_roll(int min, int max, object *op, int goodbad); +void emergency_save () -const char *cost_string_from_value(uint64 cost, int approx = 0) +void _exit (int status = EXIT_SUCCESS) -int invoke (int event, ...) +UV sv_2watcher (SV *w) CODE: - if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL"); - AV *av = (AV *)sv_2mortal ((SV *)newAV ()); - for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); - RETVAL = INVOKE_((event_type)event, ARG_AV (av)); - OUTPUT: RETVAL + RETVAL = (UV)GEventAPI->sv_2watcher (w); + OUTPUT: + RETVAL + +#if _POSIX_MEMLOCK + +int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) + +int munlockall () + +#endif + +int find_animation (utf8_string text) + PROTOTYPE: $ + +int random_roll (int min, int max, object *op, int goodbad); + +const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) int exp_to_level (val64 exp) @@ -1770,65 +1669,110 @@ XSRETURN_UNDEF; OUTPUT: RETVAL +bool +load_resource_file (octet_string filename) + +MODULE = cf PACKAGE = cf::attachable + int -_valid (SV *obj) +valid (SV *obj) CODE: RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); OUTPUT: RETVAL +void +debug_trace (attachable *obj, bool on = true) + CODE: + obj->flags &= ~attachable::F_DEBUG_TRACE; + if (on) + obj->flags |= attachable::F_DEBUG_TRACE; + +int mortals_size () + CODE: + RETVAL = attachable::mortals.size (); + OUTPUT: RETVAL + +#object *mortals (U32 index) +# CODE: +# RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0; +# OUTPUT: RETVAL + +INCLUDE: $PERL $srcdir/genacc attachable ../include/cfperl.h | + +MODULE = cf PACKAGE = cf::global + +int invoke (SV *klass, int event, ...) + CODE: + if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL"); + AV *av = (AV *)sv_2mortal ((SV *)newAV ()); + for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); + RETVAL = gbl_ev.invoke ((event_type)event, ARG_AV (av), DT_END); + OUTPUT: RETVAL + MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ -INCLUDE: $PERL genacc object ../include/object.h | +INCLUDE: $PERL $srcdir/genacc object ../include/object.h | int invoke (object *op, int event, ...) CODE: if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); - RETVAL = INVOKE_((event_type)event, ARG_OBJECT (op), ARG_AV (av)); + RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END); OUTPUT: RETVAL SV *registry (object *op) - CODE: - RETVAL = registry_of (op); - OUTPUT: - RETVAL -void mortals () - PPCODE: - EXTEND (SP, object::mortals.size ()); - for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) - PUSHs (to_sv (*i)); +int objects_size () + CODE: + RETVAL = objects.size (); + OUTPUT: RETVAL -object *first () +object *objects (U32 index) CODE: - RETVAL = object::first; + RETVAL = index < objects.size () ? objects [index] : 0; OUTPUT: RETVAL -# missing properties +int actives_size () + CODE: + RETVAL = actives.size (); + OUTPUT: RETVAL -int flag (object *op, int flag, int value = 1) - PROTOTYPE: $$;$ +object *actives (U32 index) CODE: - RETVAL = QUERY_FLAG (op, flag); - if (items >= 3) - if (value) - SET_FLAG (op, flag); - else - CLEAR_FLAG (op, flag); - OUTPUT: RETVAL + RETVAL = index < actives.size () ? actives [index] : 0; + OUTPUT: RETVAL + +const char *slot_use_name (U32 slot) + ALIAS: + slot_nonuse_name = 1 + CODE: +{ + if (slot >= NUM_BODY_LOCATIONS) + croak ("body slot index out of range"); + + switch (ix) + { + case 0: RETVAL = body_locations[slot].use_name; break; + case 1: RETVAL = body_locations[slot].nonuse_name; break; + } +} + OUTPUT: + RETVAL + +# missing properties object *head (object *op) PROTOTYPE: $ CODE: - RETVAL = op->head ? op->head : op; + RETVAL = op->head_ (); OUTPUT: RETVAL int is_head (object *op) PROTOTYPE: $ CODE: - RETVAL = !op->head; + RETVAL = op->head_ () == op; OUTPUT: RETVAL void @@ -1838,89 +1782,137 @@ { object *o; for (o = obj->inv; o; o = o->below) - XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); + XPUSHs (sv_2mortal (to_sv (o))); } -object *find_best_object_match (object *op, const char *match) +void +set_animation (object *op, int idx) + CODE: + SET_ANIMATION (op, idx); -object *find_marked_object (object *op) +int +num_animations (object *op) + CODE: + RETVAL = NUM_ANIMATIONS (op); + OUTPUT: RETVAL -int cf_object_get_resistance (object *op, int rtype) - ALIAS: resistance = 0 +int slot_info (object *op, UV slot, int value = 0) + ALIAS: + slot_used = 1 + CODE: +{ + if (slot >= NUM_BODY_LOCATIONS) + croak ("body slot index out of range"); -int need_identify (const object *obj); + RETVAL = ix ? op->slot[slot].used : op->slot[slot].info; + + if (items > 2) + if (ix) + op->slot[slot].used = value; + else + op->slot[slot].info = value; +} + OUTPUT: + RETVAL + +object *find_best_object_match (object *op, utf8_string match) + +object *find_marked_object (object *op) + +int need_identify (object *obj); int apply_shop_mat (object *shop_mat, object *op); +int move_player (object *op, int dir) + CODE: + RETVAL = move_player (op, dir); + OUTPUT: + RETVAL + int move (object *op, int dir, object *originator = op) CODE: RETVAL = move_ob (op, dir, originator); OUTPUT: RETVAL -void cf_object_apply (object *op, object *author, int flags = 0) - -void cf_object_apply_below (object *op) +void apply (object *applier, object *applied, int flags = 0) + CODE: + manual_apply (applied, applier, flags); -void cf_object_remove (object *op) +void apply_below (object *op) + CODE: + player_apply_below (op); -void cf_object_free (object *op) +int cast_heal (object *op, object *caster, object *spell, int dir = 0) -object *cf_object_present_archname_inside (object *op, char *whatstr) +object *cf_object_present_archname_inside (object *op, utf8_string whatstr) int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) int cf_object_change_map (object *op, int x, int y, maptile *map) -object *cf_object_clone (object *op, int clonetype = 0) +#//TODO +object *clone_ (object *op, int recursive = 0) + CODE: + if (recursive) + RETVAL = object_create_clone (op); + else + { + RETVAL = object::create (); + op->copy_to (RETVAL); + } + OUTPUT: RETVAL -int cf_object_pay_item (object *op, object *buyer) +int pay_item (object *op, object *buyer) + CODE: + RETVAL = pay_for_item (op, buyer); + OUTPUT: RETVAL -int cf_object_pay_amount (object *op, uint64 amount) +int pay_amount (object *op, uint64 amount) + CODE: + RETVAL = pay_for_amount (amount, op); + OUTPUT: RETVAL void pay_player (object *op, uint64 amount) -val64 pay_player_arch (object *op, const char *arch, uint64 amount) - -int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0) +val64 pay_player_arch (object *op, utf8_string arch, uint64 amount) -int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0) +int cast_spell (object *op, object *caster, int dir, object *spell_ob, utf8_string stringarg = 0) -void cf_object_learn_spell (object *op, object *sp) +void learn_spell (object *op, object *sp, int special_prayer = 0) + CODE: + do_learn_spell (op, sp, special_prayer); -void cf_object_forget_spell (object *op, object *sp) +void forget_spell (object *op, object *sp) + CODE: + do_forget_spell (op, query_name (sp)); -object *cf_object_check_for_spell (object *op, char *spellname) +object *check_for_spell (object *op, utf8_string spellname) + CODE: + RETVAL = check_spell_known (op, spellname); + OUTPUT: RETVAL -int cf_object_query_money (object *op) +int query_money (object *op) ALIAS: money = 0 -int cf_object_query_cost (object *op, object *who, int flags) +val64 query_cost (object *op, object *who, int flags) ALIAS: cost = 0 -void cf_object_activate_rune (object *op , object *victim) - -int cf_object_check_trigger (object *op, object *cause) - -int cf_object_out_of_map (object *op, int x, int y) - -void cf_object_drop (object *op, object *author) +void spring_trap (object *op, object *victim) -void cf_object_take (object *op, object *author) +int check_trigger (object *op, object *cause) -object *cf_object_insert_object (object *op, object *container) +void drop (object *who, object *op) -object *cf_object_insert_in_ob (object *ob, object *where) +void pick_up (object *who, object *op) int cf_object_teleport (object *op, maptile *map, int x, int y) -void cf_object_update (object *op, int flags) +void update_object (object *op, int action) -void cf_object_pickup (object *op, object *what) +object *cf_create_object_by_name (utf8_string name) -object *cf_create_object_by_name (const char *name) - -void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) +void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) void player_lvl_adj (object *who, object *skill = 0) @@ -1936,24 +1928,15 @@ void remove_button_link (object *op); -void -cf_object_set_resistance (object *op, int rtype, int val) - CODE: - if (rtype >= 0 && rtype < NROFATTACKS) - op->resist[rtype] = val; - MODULE = cf PACKAGE = cf::object PREFIX = cf_ -void cf_fix_object (object *pl) - ALIAS: fix = 0 - object *cf_insert_ob_in_ob (object *ob, object *where) # no clean way to get an object from an archetype - stupid idiotic # dumb kludgy misdesigned plug-in api slowly gets on my nerves. -object *new (const char *archetype = 0) +object *new (utf8_string archetype = 0) PROTOTYPE: ;$ CODE: RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); @@ -1968,21 +1951,14 @@ RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); } -# syntatic sugar for easier use in event callbacks. -const char *options (object *op) - CODE: - RETVAL = op->name; - OUTPUT: - RETVAL - player *contr (object *op) CODE: RETVAL = op->contr; OUTPUT: RETVAL -const char *get_ob_key_value (object *op, const char *key) +const_utf8_string get_ob_key_value (object *op, utf8_string key) -bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) +bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) object *get_nearest_player (object *ob) ALIAS: nearest_player = 0 @@ -2008,12 +1984,14 @@ RETVAL = on_same_map (ob, other); OUTPUT: RETVAL -const char * +const_utf8_string base_name (object *op, int plural = op->nrof > 1) CODE: RETVAL = query_base_name (op, plural); OUTPUT: RETVAL +object *decrease_ob_nr (object *op, unsigned long i) + MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ player *player (object *op) @@ -2021,22 +1999,11 @@ RETVAL = op->contr; OUTPUT: RETVAL -void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) - -object *cf_player_send_inventory (object *op) - -char *cf_player_get_ip (object *op) - ALIAS: ip = 0 - -object *cf_player_get_marked_item (object *op) - ALIAS: marked_item = 0 +void check_score (object *op) -void cf_player_set_marked_item (object *op, object *ob) - -partylist *cf_player_get_party (object *op) - ALIAS: party = 0 - -void cf_player_set_party (object *op, partylist *party) +void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) + CODE: + new_draw_info (flags, 0, op, txt); void kill_player (object *op) @@ -2045,89 +2012,54 @@ void clear_los (object *op) -int command_reset (object *op, char *params) +int command_summon (object *op, utf8_string params) -int command_teleport (object *op, char *params) - -int command_summon (object *op, char *params) - -int command_arrest (object *op, char *params) - -int command_kick (object *op, char *params) - -int command_banish (object *op, char *params) +int command_arrest (object *op, utf8_string params) MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ -INCLUDE: $PERL genacc player ../include/newserver.h ../include/player.h | - -char * -client (player *pl) - CODE: - RETVAL = pl->socket.client; - OUTPUT: - RETVAL - -char * -host (player *pl) - CODE: - RETVAL = pl->socket.host; - OUTPUT: - RETVAL +INCLUDE: $PERL $srcdir/genacc player ../include/player.h | int invoke (player *pl, int event, ...) CODE: if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); - RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); + RETVAL = pl->invoke ((event_type)event, ARG_AV (av), DT_END); OUTPUT: RETVAL SV *registry (player *pl) - CODE: - RETVAL = registry_of (pl); - OUTPUT: - RETVAL -player *cf_player_find (char *name) - PROTOTYPE: $ +void +save_stats (player *pl) + CODE: + pl->ob->stats.hp = pl->ob->stats.maxhp; + pl->ob->stats.sp = pl->ob->stats.maxsp; + pl->ob->stats.grace = pl->ob->stats.maxgrace; + pl->orig_stats = pl->ob->stats; void cf_player_move (player *pl, int dir) void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); -player *first () - CODE: - RETVAL = first_player; - OUTPUT: RETVAL - -player *next (player *pl) - CODE: - RETVAL = pl->next; - OUTPUT: RETVAL - bool cell_visible (player *pl, int dx, int dy) CODE: - RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2 - && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]; + RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 + && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2]; OUTPUT: RETVAL void -buggy_mapscroll (player *pl, int value = 1) - CODE: - pl->socket.buggy_mapscroll = value; - -void send (player *pl, SV *packet) CODE: { STRLEN len; char *buf = SvPVbyte (packet, len); - Write_String_To_Socket (&pl->socket, buf, len); + if (pl->ns) + pl->ns->send_packet (buf, len); } int @@ -2156,102 +2088,154 @@ void list () PPCODE: -{ - player *pl; - for (pl = first_player; pl; pl = pl->next) - XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); -} - -bool -peaceful (player *pl, bool new_setting = 0) - PROTOTYPE: $;$ - CODE: - RETVAL = pl->peaceful; - if (items > 1) - pl->peaceful = new_setting; - OUTPUT: - RETVAL - -living * -orig_stats (player *pl) - CODE: - RETVAL = &pl->orig_stats; - OUTPUT: RETVAL - -living * -last_stats (player *pl) - CODE: - RETVAL = &pl->last_stats; - OUTPUT: RETVAL + for_all_players (pl) + XPUSHs (sv_2mortal (to_sv (pl))); MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ -maptile *first () - PROTOTYPE: - CODE: - RETVAL = first_map; - OUTPUT: RETVAL - int invoke (maptile *map, int event, ...) CODE: if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); - RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); + RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); OUTPUT: RETVAL SV *registry (maptile *map) - CODE: - RETVAL = registry_of (map); - OUTPUT: - RETVAL -INCLUDE: $PERL genacc maptile ../include/map.h | +INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h | + +void +maptile::instantiate () -maptile *new (int width, int height) +maptile *new () PROTOTYPE: CODE: -{ - RETVAL = get_empty_map (width, height); -} + RETVAL = new maptile; OUTPUT: RETVAL -void delete_map (maptile *map) +void +maptile::players () + PPCODE: + if (GIMME_V == G_SCALAR) + XPUSHs (sv_2mortal (to_sv (THIS->players))); + else if (GIMME_V == G_ARRAY) + { + EXTEND (SP, THIS->players); + for_all_players (pl) + if (pl->ob && pl->ob->map == THIS) + PUSHs (sv_2mortal (to_sv (pl->ob))); + } -void clean_tmp_map (maptile *map) +void +maptile::add_underlay (SV *data, int offset, int stride, SV *palette) + CODE: +{ + if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) + croak ("maptile::add_underlay: palette must be arrayref"); -void play_sound_map (maptile *map, int x, int y, int sound_num) + palette = SvRV (palette); -maptile *tile_map (maptile *map, unsigned int dir) - CODE: - RETVAL = dir < 4 ? map->tile_map [dir] : 0; - OUTPUT: - RETVAL + STRLEN idxlen; + const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); + + for (int x = 0; x < THIS->width; ++x) + for (int y = 0; y < THIS->height; ++y) + { + for (object *op = THIS->at (x, y).bot; op; op = op->above) + if (op->flag [FLAG_IS_FLOOR]) + goto skip_space; + + { + int offs = offset + y * stride + x; + if (IN_RANGE_EXC (offs, 0, idxlen)) + { + if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) + { + object *ob = get_archetype (SvPVutf8_nolen (*elem)); + ob->flag [FLAG_NO_MAP_SAVE] = true; + THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); + + if (ob->randomitems) + { + if (!ob->above) + { + ob->create_treasure (ob->randomitems); + + for (object *op = ob->above; op; op = op->above) + op->flag [FLAG_NO_MAP_SAVE] = true; + } + + ob->randomitems = 0; + } + } + } + } -char *tile_path (maptile *map, unsigned int dir) + skip_space: ; + } +} + +void +maptile::set_regiondata (SV *data, int offset, int stride, SV *palette) CODE: - if (dir >= 4) - XSRETURN_UNDEF; - RETVAL = map->tile_path [dir]; - OUTPUT: - RETVAL +{ + if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) + croak ("maptile::set_regiondata: palette must be arrayref"); -maptile *ready_map_name (char *name, int flags = 0) - PROTOTYPE: $;$ - ALIAS: - find = 0 - get_map = 1 + palette = SvRV (palette); -maptile *has_been_loaded (char *name) - PROTOTYPE: $ + STRLEN idxlen; + const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); + + region **regionmap = (region **)malloc ( + (av_len ((AV *)palette) + 1) * sizeof (region *)); + uint8_t *regions = salloc (THIS->size ()); + + for (int i = av_len ((AV *)palette) + 1; i--; ) + regionmap [i] = region::find ( + SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); + + for (int y = 0; y < THIS->height; ++y) + memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); + + sfree (THIS->regions, THIS->size ()); + free (THIS->regionmap); -int in_memory (maptile *map) + THIS->regions = regions; + THIS->regionmap = regionmap; +} + +void +maptile::create_region_treasure () CODE: - RETVAL = map->in_memory; - OUTPUT: - RETVAL +{ + object *op = object::create (); + op->type = FLOOR; + op->map = THIS; + + for (int x = 0; x < THIS->width; ++x) + for (int y = 0; y < THIS->height; ++y) + { + region *rgn = THIS->region (x, y); + + //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D + if (rgn->treasure && rndm () < rgn->treasure_density) + { + op->x = x; + op->y = y; + create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); + } + } + + op->destroy (); +} + +void play_sound_map (maptile *map, int x, int y, int sound_num) + +int out_of_map (maptile *map, int x, int y) void trigger (maptile *map, long connection, bool state = true) @@ -2274,7 +2258,7 @@ C_ARGS: str, map, nx, ny void -cf_map_normalise (maptile *map, int x, int y) +get_map_flags (maptile *map, int x, int y) PPCODE: { maptile *nmap = 0; @@ -2320,7 +2304,7 @@ move_on_at = 6 move_off_at = 7 INIT: - if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_UNDEF; + if (x >= obj->width || y >= obj->height) XSRETURN_UNDEF; CODE: switch (ix) { @@ -2333,13 +2317,103 @@ case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break; case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; } - OUTPUT: - RETVAL + OUTPUT: RETVAL + +void fix_walls (maptile *map, int x, int y) + +void fix_walls_around (maptile *map, int x, int y) +# worst xs function of my life +bool +_create_random_map (\ + maptile *self,\ + utf8_string wallstyle,\ + utf8_string wall_name,\ + utf8_string floorstyle,\ + utf8_string monsterstyle,\ + utf8_string treasurestyle,\ + utf8_string layoutstyle,\ + utf8_string doorstyle,\ + utf8_string decorstyle,\ + utf8_string origin_map,\ + utf8_string final_map,\ + utf8_string exitstyle,\ + utf8_string this_map,\ + utf8_string exit_on_final_map,\ + int xsize,\ + int ysize,\ + int expand2x,\ + int layoutoptions1,\ + int layoutoptions2,\ + int layoutoptions3,\ + int symmetry,\ + int difficulty,\ + int difficulty_given,\ + float difficulty_increase,\ + int dungeon_level,\ + int dungeon_depth,\ + int decoroptions,\ + int orientation,\ + int origin_y,\ + int origin_x,\ + U32 random_seed,\ + val64 total_map_hp,\ + int map_layout_style,\ + int treasureoptions,\ + int symmetry_used,\ + region *region,\ + utf8_string custom\ +) + CODE: +{ + random_map_params rmp; + + assign (rmp.wallstyle , wallstyle); + assign (rmp.wall_name , wall_name); + assign (rmp.floorstyle , floorstyle); + assign (rmp.monsterstyle , monsterstyle); + assign (rmp.treasurestyle , treasurestyle); + assign (rmp.layoutstyle , layoutstyle); + assign (rmp.doorstyle , doorstyle); + assign (rmp.decorstyle , decorstyle); + assign (rmp.exitstyle , exitstyle); + assign (rmp.exit_on_final_map, exit_on_final_map); + + rmp.origin_map = origin_map; + rmp.final_map = final_map; + rmp.this_map = this_map; + rmp.xsize = xsize; + rmp.ysize = ysize; + rmp.expand2x = expand2x; + rmp.layoutoptions1 = layoutoptions1; + rmp.layoutoptions2 = layoutoptions2; + rmp.layoutoptions3 = layoutoptions3; + rmp.symmetry = symmetry; + rmp.difficulty = difficulty; + rmp.difficulty_given = difficulty_given; + rmp.difficulty_increase = difficulty_increase; + rmp.dungeon_level = dungeon_level; + rmp.dungeon_depth = dungeon_depth; + rmp.decoroptions = decoroptions; + rmp.orientation = orientation; + rmp.origin_y = origin_y; + rmp.origin_x = origin_x; + rmp.random_seed = random_seed; + rmp.total_map_hp = (uint64_t) total_map_hp; + rmp.map_layout_style = map_layout_style; + rmp.treasureoptions = treasureoptions; + rmp.symmetry_used = symmetry_used; + rmp.region = region; + rmp.custom = custom; + + RETVAL = self->generate_random_map (&rmp); +} + OUTPUT: + RETVAL MODULE = cf PACKAGE = cf::arch -archetype *find (const char *name) +archetype *find (utf8_string name) CODE: RETVAL = archetype::find (name); OUTPUT: @@ -2351,7 +2425,13 @@ RETVAL = first_archetype; OUTPUT: RETVAL -INCLUDE: $PERL genacc archetype ../include/object.h | +object *instantiate (archetype *arch) + CODE: + RETVAL = arch_to_object (arch); + OUTPUT: + RETVAL + +INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | MODULE = cf PACKAGE = cf::party @@ -2361,55 +2441,186 @@ RETVAL = get_firstparty (); OUTPUT: RETVAL -partylist *next (partylist *party) +INCLUDE: $PERL $srcdir/genacc partylist ../include/player.h | + +MODULE = cf PACKAGE = cf::region + +void +list () + PPCODE: + for_all_regions (rgn) + XPUSHs (sv_2mortal (to_sv (rgn))); + +region *find (utf8_string name) + PROTOTYPE: $ CODE: - RETVAL = party->next; + RETVAL = region::find (name); OUTPUT: RETVAL -const char *name (partylist *party) +region *find_fuzzy (utf8_string name) + PROTOTYPE: $ CODE: - RETVAL = party->partyname; + RETVAL = region::find_fuzzy (name); OUTPUT: RETVAL -const char *password (partylist *party) - CODE: - RETVAL = party->passwd; +int specificity (region *rgn) + CODE: + RETVAL = 0; + while (rgn = rgn->parent) + RETVAL++; OUTPUT: RETVAL -MODULE = cf PACKAGE = cf::region +INCLUDE: $PERL $srcdir/genacc region ../include/region.h | -region *first () - PROTOTYPE: - CODE: - RETVAL = first_region; - OUTPUT: RETVAL +MODULE = cf PACKAGE = cf::living -region *next (region *reg) - CODE: - RETVAL = reg->next; - OUTPUT: RETVAL +INCLUDE: $PERL $srcdir/genacc living ../include/living.h | -const char *name (region *reg) - CODE: - RETVAL = reg->name; - OUTPUT: RETVAL +MODULE = cf PACKAGE = cf::settings -region *parent (region *reg) - CODE: - RETVAL = reg->parent; - OUTPUT: RETVAL +INCLUDE: $PERL $srcdir/genacc Settings ../include/global.h | -const char *longname (region *reg) - CODE: - RETVAL = reg->longname; - OUTPUT: RETVAL +MODULE = cf PACKAGE = cf::client -const char *msg (region *reg) - CODE: - RETVAL = reg->msg; +INCLUDE: $PERL $srcdir/genacc client ../include/client.h | + +int invoke (client *ns, int event, ...) + CODE: + if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT"); + AV *av = (AV *)sv_2mortal ((SV *)newAV ()); + for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); + RETVAL = ns->invoke ((event_type)event, ARG_AV (av), DT_END); + OUTPUT: RETVAL + +SV *registry (client *ns) + +void +list () + PPCODE: + EXTEND (SP, clients.size ()); + for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) + PUSHs (sv_2mortal (to_sv (*i))); + +void +client::send_packet (SV *packet) + CODE: +{ + STRLEN len; + char *buf = SvPVbyte (packet, len); + + THIS->send_packet (buf, len); +} + +MODULE = cf PACKAGE = cf::face PREFIX = face_ + +#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | + +faceidx face_find (utf8_string name, faceidx defidx = 0) + +faceidx alloc (utf8_string name) + CODE: +{ + do + { + RETVAL = faces.size (); + faces.resize (RETVAL + 1); + } + while (!RETVAL); // crude way to leave index 0 + + faces [RETVAL].name = name; + facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); + + if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; + if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; +} + OUTPUT: RETVAL + +void set (faceidx idx, int visibility, int magicmap) + CODE: + faceinfo *f = face_info (idx); + assert (f); + f->visibility = visibility; + f->magicmap = magicmap; + +void set_smooth (faceidx idx, faceidx smooth, int smoothlevel) + CODE: + faceinfo *f = face_info (idx); assert (f); + f->smooth = smooth; + f->smoothlevel = smoothlevel; + +void set_data (faceidx idx, int faceset, SV *data, SV *chksum) + CODE: +{ + facedata *d = face_data (idx, faceset); + assert (d); + sv_to (data, d->data); + STRLEN clen; + char *cdata = SvPVbyte (chksum, clen); + clen = min (CHKSUM_SIZE, clen); + + if (memcmp (d->chksum, cdata, clen)) + { + memcpy (d->chksum, cdata, clen); + + // invalidate existing client face info + for_all_clients (ns) + if (ns->faceset == faceset) + { + ns->faces_sent [idx] = false; + ns->force_newmap = true; + } + } +} + +void invalidate (faceidx idx) + CODE: + for_all_clients (ns) + { + ns->faces_sent [idx] = false; + ns->force_newmap = true; + } + +void invalidate_all () + CODE: + for_all_clients (ns) + { + ns->faces_sent.reset (); + ns->force_newmap = true; + } + +MODULE = cf PACKAGE = cf::anim PREFIX = anim_ + +#INCLUDE: $PERL $srcdir/genacc faceset ../include/anim.h | + +animidx anim_find (utf8_string name) + CODE: + RETVAL = animation::find (name).number; OUTPUT: RETVAL -MODULE = cf PACKAGE = cf::living +animidx set (utf8_string name, SV *frames, int facings = 1) + CODE: +{ + if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) + croak ("frames must be an arrayref"); + + AV *av = (AV *)SvRV (frames); + + animation *anim = &animation::find (name); + if (anim->number) + { + anim->resize (av_len (av) + 1); + anim->facings = facings; + } + else + anim = &animation::create (name, av_len (av) + 1, facings); -INCLUDE: $PERL genacc living ../include/living.h | + for (int i = 0; i < anim->num_animations; ++i) + anim->faces [i] = face_find (SvPVutf8_nolen (*av_fetch (av, i, 1))); +} + OUTPUT: RETVAL + +void invalidate_all () + CODE: + for_all_clients (ns) + ns->anims_sent.reset ();