--- deliantra/server/server/cfperl.xs 2006/08/27 15:24:22 1.16 +++ deliantra/server/server/cfperl.xs 2006/11/18 23:16:19 1.68 @@ -6,7 +6,7 @@ * This code is placed under the GNU General Public Licence (GPL) * * Copyright (C) 2001-2005 by Chachkoff Yann - * Copyright (C) 2006 by Marc Lehmann + * 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 @@ -23,25 +23,9 @@ * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include -#include - -#undef save_long // clashes with libproto.h - #define PLUGIN_NAME "perl" #define PLUGIN_VERSION "cfperl 0.5" -#ifndef __CEXTRACT__ -#include -#endif - -#undef MODULEAPI -#ifdef WIN32 -#else -#define MODULEAPI -#endif - #include #include #include @@ -50,52 +34,30 @@ #include "cfperl.h" #include "shstr.h" +#include +#include +#include + #include "perlxsi.c" extern sint64 *levels; // the experience table -typedef object object_ornull; -typedef mapstruct mapstruct_ornull; +typedef object object_ornull; +typedef maptile maptile_ornull; typedef double val64; #define newSVval64 newSVnv #define SvVAL64 SvNV -static f_plug_api gethook; -static f_plug_api systemDirectory; -static f_plug_api object_set_property; -static f_plug_api map_get_map; -static f_plug_api object_insert; - -/* this is a stupid way to do things, and awkward to use for plug-in authors */ -typedef struct -{ - object* who; - object* activator; - object* third; - object* event; - mapstruct* map; - char message[1024]; - int fix; // seems to be python-only, and should not be part of the API - int event_code; - char extension[1024]; // name field, should invoke specific perl extension - char options[1024]; // slaying field of event_connectors - int returnvalue; -} CFPContext; +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; -#define PUSHcfapi(type,value) PUSHs (sv_2mortal (newSVcfapi (CFAPI_ ## type, (value)))) -#define PUSHcfapi_va(type,ctype) PUSHcfapi (type, va_arg (args, ctype)) -#define PUSH_OB PUSHcfapi_va(POBJECT, object *) -#define PUSH_PL PUSHcfapi_va(PPLAYER, player *) -#define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *) -#define PUSH_PV PUSHcfapi_va(STRING, const char *) -#define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int)))) - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// static SV * @@ -110,9 +72,9 @@ return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); } -template +template SV * -newSVextendable (extendable *obj, const char *klass) +newSVattachable (attachable *obj, const char *klass) { if (!obj) return &PL_sv_undef; @@ -120,7 +82,7 @@ if (!obj->self) obj->self = newSVptr (obj, klass); - return newSVsv (static_cast(obj->self)); + return newSVsv (obj->self); } static void @@ -192,6 +154,90 @@ return 0; } +inline SV *to_sv (const shstr & v) { return v ? newSVpvn ((const char *)v, v.length ()) : &PL_sv_undef; } +inline SV *to_sv (const char * v) { return newSVpv (v, 0); } +inline SV *to_sv (bool v) { return newSViv (v); } +inline SV *to_sv ( signed char v) { return newSViv (v); } +inline SV *to_sv (unsigned char v) { return newSViv (v); } +inline SV *to_sv ( signed short v) { return newSViv (v); } +inline SV *to_sv (unsigned short v) { return newSVuv (v); } +inline SV *to_sv ( signed int v) { return newSViv (v); } +inline SV *to_sv (unsigned int v) { return newSVuv (v); } +inline SV *to_sv ( signed long v) { return newSViv (v); } +inline SV *to_sv (unsigned long v) { return newSVuv (v); } +inline SV *to_sv ( signed long long v) { return newSVval64 (v); } +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 (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 (UUID v) { + char buf[128]; + snprintf (buf, 128, "<1,%llx>", (unsigned long long)v.seq + UUID_SKIP * 2); + 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, 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); } +inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } +inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } +inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); } +inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); } +inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); } +inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } +inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } +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, 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 + +template +inline void sv_to (SV *sv, refptr &v) { T *tmp; sv_to (sv, tmp); v = tmp; } + +template +inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } + +inline void sv_to (SV *sv, UUID &v) { + char *sv_str = SvOK (sv) ? SvPV_nolen (sv) : 0; + unsigned int version = 0; + unsigned long long seq = 0; + + if (!sv_str) + return; + + if (2 == sscanf (sv_str, "<%d.%llx>", &version, &seq) && version == 1) + { + v.seq = seq; + } + + return; +} + static SV * newSVdt_va (va_list &ap, data_type type) { @@ -227,31 +273,28 @@ break; case DT_OBJECT: - { - object *obj = va_arg (ap, object *); - sv = newSVextendable (obj, obj && obj->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); - } + sv = to_sv (va_arg (ap, object *)); break; case DT_MAP: // va_arg (object *) when void * is passed is an XSI extension - sv = newSVextendable (va_arg (ap, mapstruct *), "cf::map::wrap"); + sv = to_sv (va_arg (ap, maptile *)); break; case DT_PLAYER: - sv = newSVextendable (va_arg (ap, player *), "cf::player::wrap"); + sv = to_sv (va_arg (ap, player *)); break; case DT_ARCH: - sv = newSVptr (va_arg (ap, archetype *), "cf::arch::wrap"); + sv = to_sv (va_arg (ap, archetype *)); break; case DT_PARTY: - sv = newSVptr (va_arg (ap, partylist *), "cf::party::wrap"); + sv = to_sv (va_arg (ap, partylist *)); break; case DT_REGION: - sv = newSVptr (va_arg (ap, region *), "cf::region::wrap"); + sv = to_sv (va_arg (ap, region *)); break; default: @@ -306,7 +349,7 @@ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// SV * -registry_of (extendable_base *ext) +registry_of (attachable_base *ext) { if (!ext->cb) ext->cb = newAV (); @@ -314,21 +357,36 @@ return newRV_inc ((SV *)ext->cb); } -void extendable_base::clear () +void attachable_base::clear () { - //if (self) fprintf (stderr, "free_ob_self %p %s (%p,%p)\n", this, ((object *)this)->name, self, cb);//D + 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); - if (self) SvREFCNT_dec (self); - if (cb) SvREFCNT_dec (cb); + // clear the perl hash, might or might not be a good idea + hv_clear ((HV *)SvRV ((SV *)self)); - if (attach) free_string (attach); + SvREFCNT_dec (self); + self = 0; + } + + if (cb) + { + SvREFCNT_dec (cb); + cb = 0; + } - self = 0; - cb = 0; - attach = 0; + attach = 0; } -void extendable_base::optimise () +void attachable_base::optimise () { if (!self) return; @@ -344,151 +402,407 @@ } } -void -object::instantiate_ () +void attachable_base::instantiate (data_type type, void *obj) { dSP; ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2); - PUSHs (sv_2mortal (newSVdt (DT_OBJECT, static_cast(this)))); + 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; - INVOKE_OBJECT (INSTANTIATE, this); + switch (type) + { + case DT_OBJECT: INVOKE_OBJECT (INSTANTIATE, obj); break; + case DT_MAP: INVOKE_MAP (INSTANTIATE, obj); break; + } } ///////////////////////////////////////////////////////////////////////////// -object_freezer::object_freezer (const char *filename) -: filename (filename) +void reattach (data_type type, void *obj) { - av = (AV *)newAV (); - idx = 0; - av_extend ((AV *)av, 1024); -} + //TODO only do this when the object has _attachment's -object_freezer::~object_freezer () -{ dSP; ENTER; SAVETMPS; PUSHMARK (SP); - XPUSHs (sv_2mortal (newSVpv (filename, 0))); - XPUSHs (sv_2mortal (newRV_noinc ((SV *)av))); + XPUSHs (sv_2mortal (newSVdt (type, obj))); PUTBACK; - call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); + 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; + } } -void object_freezer::put (extendable_base *ext) +template +void reattach (attachable *obj) { - ext->optimise (); + obj->optimise (); - if (ext->self) - av_store ((AV *)av, idx, SvREFCNT_inc ((SV *)ext->self)); + if (obj->self) + reattach ((data_type) cftype::dt, (subclass *)obj); +} + +#include "kw_hash.h" - ++idx; +object_freezer::object_freezer () +: dynbuf (128 * 1024, 64 * 1024) +{ + av = newAV (); } -object_thawer::object_thawer (const char *filename) +object_freezer::~object_freezer () { - av = 0; - idx = 0; + SvREFCNT_dec (av); +} - if (!filename) - return; +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); - XPUSHs (sv_2mortal (newSVpv (filename, 0))); + 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; - - if (0 < call_pv ("cf::object_thawer_load", G_SCALAR | G_EVAL)) - { - SPAGAIN; - SV *sv = POPs; - if (SvROK (sv)) - av = SvREFCNT_inc (SvRV (sv)); - } - + call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); FREETMPS; LEAVE; } -void reattach (data_type type, void *obj) +char *object_freezer::as_string () { dSP; ENTER; SAVETMPS; PUSHMARK (SP); - XPUSHs (sv_2mortal (newSVdt (type, obj))); + EXTEND (SP, 3); + PUSHs (sv_2mortal (newRV_noinc (newSVpvn ((char *)linearise (), size ())))); + PUSHs (sv_2mortal (newRV_inc ((SV *)av))); PUTBACK; - call_pv ("cf::reattach", G_DISCARD | G_VOID | G_EVAL); + + char *res = call_pv ("cf::object_freezer_as_string", G_SCALAR | G_EVAL) > 0 + ? strdup (SvPVbyte_nolen (POPs)) + : strdup ("[fatal error]"); + FREETMPS; LEAVE; - switch (type) + 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) { - case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break; - case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break; - case DT_MAP: INVOKE_MAP (REATTACH, obj); break; + 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; } } -template -void reattach (extendable *obj) +object_thawer::object_thawer (const char *data, AV *perlav) { - obj->optimise (); - - if (obj->self) - reattach (subclass::get_dt (), (subclass *)obj); + av = perlav; + text = newSVpv (data, 0); + sv_catpv (text, thawer_eof); + line = SvPVbyte_nolen (text); } -void object_thawer::get (data_type type, void *obj, extendable_base *ext) +void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) { - if (!av) + 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, idx, 0); + SV **svp = av_fetch ((AV *)av, oid, 0); - ++idx; + if (!svp || !SvROK (*svp)) + { + printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); + return; + } - if (!svp) - return; + ext->self = *svp; *svp = &PL_sv_undef; + sv_magic (SvRV (ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); + + reattach (type, obj); +} - if (SvROK (*svp)) +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) { - ext->self = SvREFCNT_inc (*svp); - sv_magic (SvRV ((SV *)ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); + if (!*p) + break; - reattach (type, obj); + *q++ = *p; + + if (*p++ == '\n') + break; } + + *q = 0; + thawer.line = p; + + return s == q ? 0 : s; } -object_thawer::~object_thawer () +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) { - if (av) - SvREFCNT_dec ((SV *)av); + 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) { - gethook = gethooksptr; - printf (PLUGIN_VERSION " init\n"); - return 0; } @@ -578,13 +892,6 @@ int hooktype = 1; int rtype = 0; - printf (PLUGIN_VERSION " post init\n"); - - systemDirectory = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_directory"); - object_set_property = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_set_property"); - map_get_map = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_map_get_map"); - object_insert = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_insert"); - cf_init_plugin (gethook); return 0; @@ -598,31 +905,24 @@ void cfperl_init () { - char *argv[] = { - "", - "-e" - "BEGIN {" - " cf->bootstrap;" - " unshift @INC, cf::datadir ();" - "}" - "" - "use cf;" - }; - + PERL_SYS_INIT3 (&settings.argc, &settings.argv, 0); perl = perl_alloc (); perl_construct (perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; + char *argv[] = { + "", + "-e" + "cf->bootstrap;" + "unshift @INC, cf::datadir ();" + "require cf;" + }; + if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) { printf ("unable to initialize perl-interpreter, aborting.\n"); - exit (EXIT_FAILURE); - //perl_destruct (perl); - //perl_free (perl); - //perl = 0; - //return; } obj_cache = newHV (); @@ -643,6 +943,8 @@ # undef def }; +#define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) + static void gather_callbacks (AV *&callbacks, AV *registry, event_type event) { @@ -684,7 +986,7 @@ object *op; player *pl; - mapstruct *map; + maptile *map; // callback call ordering is: // 1. per-object callback (NYI) @@ -694,7 +996,7 @@ gather_callbacks (callbacks, cb_global, event); - switch (klass_of [event]) + switch (KLASS_OF (event)) { case KLASS_GLOBAL: break; @@ -705,7 +1007,7 @@ op = va_arg (ap, object *); if (op->cb) - gather_callbacks (callbacks, (AV *)op->cb, event); + gather_callbacks (callbacks, op->cb, event); if (op->type) { @@ -736,7 +1038,7 @@ pl = va_arg (ap, player *); if (pl->cb) - gather_callbacks (callbacks, (AV *)pl->cb, event); + gather_callbacks (callbacks, pl->cb, event); gather_callbacks (callbacks, cb_player, event); break; @@ -744,10 +1046,10 @@ 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, mapstruct *); + map = va_arg (ap, maptile *); if (map->cb) - gather_callbacks (callbacks, (AV *)map->cb, event); + gather_callbacks (callbacks, map->cb, event); gather_callbacks (callbacks, cb_map, event); break; @@ -770,7 +1072,7 @@ PUSHs (sv_2mortal (newSViv (event))); // only used for debugging nowadays PUSHs (sv_2mortal (newRV_noinc ((SV *)callbacks))); - switch (klass_of [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; @@ -835,6 +1137,8 @@ { HV *stash = gv_stashpv ("cf", 1); + newCONSTSUB (stash, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); + static const struct { const char *name; IV iv; @@ -1006,16 +1310,6 @@ const_iv (AT_LIFE_STEALING) const_iv (AT_DISEASE) - const_iv (QUEST_IN_PROGRESS) - const_iv (QUEST_DONE_QUEST) - const_iv (QUEST_DONE_TASK) - const_iv (QUEST_START_QUEST) - const_iv (QUEST_END_QUEST) - const_iv (QUEST_START_TASK) - const_iv (QUEST_END_TASK) - const_iv (QUEST_OVERRIDE) - const_iv (QUEST_ON_ACTIVATE) - const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) @@ -1146,6 +1440,19 @@ 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) @@ -1209,6 +1516,7 @@ 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) @@ -1349,146 +1657,10 @@ newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv)); } - static const struct { - int dtype; - const char *name; - IV idx; - } *cprop, prop_table[] = { -# define prop(type, name) { type, # name, (IV) CFAPI_ ## name }, - prop (CFAPI_INT, MAP_PROP_FLAGS) - prop (CFAPI_INT, MAP_PROP_DIFFICULTY) - prop (CFAPI_STRING, MAP_PROP_PATH) - prop (CFAPI_STRING, MAP_PROP_TMPNAME) - prop (CFAPI_STRING, MAP_PROP_NAME) - prop (CFAPI_INT, MAP_PROP_RESET_TIME) - prop (CFAPI_INT, MAP_PROP_RESET_TIMEOUT) - prop (CFAPI_INT, MAP_PROP_PLAYERS) - prop (CFAPI_INT, MAP_PROP_DARKNESS) - prop (CFAPI_INT, MAP_PROP_WIDTH) - prop (CFAPI_INT, MAP_PROP_HEIGHT) - prop (CFAPI_INT, MAP_PROP_ENTER_X) - prop (CFAPI_INT, MAP_PROP_ENTER_Y) - prop (CFAPI_INT, MAP_PROP_TEMPERATURE) - prop (CFAPI_INT, MAP_PROP_PRESSURE) - prop (CFAPI_INT, MAP_PROP_HUMIDITY) - prop (CFAPI_INT, MAP_PROP_WINDSPEED) - prop (CFAPI_INT, MAP_PROP_WINDDIR) - prop (CFAPI_INT, MAP_PROP_SKY) - prop (CFAPI_INT, MAP_PROP_WPARTX) - prop (CFAPI_INT, MAP_PROP_WPARTY) - prop (CFAPI_STRING, MAP_PROP_MESSAGE) - prop (CFAPI_PMAP, MAP_PROP_NEXT) - prop (CFAPI_PREGION, MAP_PROP_REGION) - prop (CFAPI_POBJECT, OBJECT_PROP_OB_ABOVE) - prop (CFAPI_POBJECT, OBJECT_PROP_OB_BELOW) - prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB) - prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB) - prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY) - prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT) - prop (CFAPI_POBJECT, OBJECT_PROP_HEAD) - prop (CFAPI_POBJECT, OBJECT_PROP_CONTAINER) - prop (CFAPI_PMAP, OBJECT_PROP_MAP) - prop (CFAPI_INT, OBJECT_PROP_COUNT) - prop (CFAPI_INT, OBJECT_PROP_REFCOUNT) - prop (CFAPI_STRING, OBJECT_PROP_NAME) - prop (CFAPI_STRING, OBJECT_PROP_NAME_PLURAL) - prop (CFAPI_STRING, OBJECT_PROP_TITLE) - prop (CFAPI_STRING, OBJECT_PROP_RACE) - prop (CFAPI_STRING, OBJECT_PROP_SLAYING) - prop (CFAPI_STRING, OBJECT_PROP_SKILL) - prop (CFAPI_STRING, OBJECT_PROP_MESSAGE) - prop (CFAPI_STRING, OBJECT_PROP_LORE) - prop (CFAPI_INT, OBJECT_PROP_X) - prop (CFAPI_INT, OBJECT_PROP_Y) - prop (CFAPI_DOUBLE, OBJECT_PROP_SPEED) - prop (CFAPI_DOUBLE, OBJECT_PROP_SPEED_LEFT) - prop (CFAPI_INT, OBJECT_PROP_NROF) - prop (CFAPI_INT, OBJECT_PROP_DIRECTION) - prop (CFAPI_INT, OBJECT_PROP_FACING) - prop (CFAPI_INT, OBJECT_PROP_TYPE) - prop (CFAPI_INT, OBJECT_PROP_SUBTYPE) - prop (CFAPI_INT, OBJECT_PROP_CLIENT_TYPE) - prop (CFAPI_INT, OBJECT_PROP_ATTACK_TYPE) - prop (CFAPI_INT, OBJECT_PROP_PATH_ATTUNED) - prop (CFAPI_INT, OBJECT_PROP_PATH_REPELLED) - prop (CFAPI_INT, OBJECT_PROP_PATH_DENIED) - prop (CFAPI_INT, OBJECT_PROP_MATERIAL) - prop (CFAPI_STRING, OBJECT_PROP_MATERIAL_NAME) - prop (CFAPI_INT, OBJECT_PROP_MAGIC) - prop (CFAPI_INT, OBJECT_PROP_VALUE) - prop (CFAPI_INT, OBJECT_PROP_LEVEL) - prop (CFAPI_INT, OBJECT_PROP_LAST_HEAL) - prop (CFAPI_INT, OBJECT_PROP_LAST_SP) - prop (CFAPI_INT, OBJECT_PROP_LAST_GRACE) - prop (CFAPI_INT, OBJECT_PROP_LAST_EAT) - prop (CFAPI_INT, OBJECT_PROP_INVISIBLE_TIME) - prop (CFAPI_INT, OBJECT_PROP_PICK_UP) - prop (CFAPI_INT, OBJECT_PROP_ITEM_POWER) - prop (CFAPI_INT, OBJECT_PROP_GEN_SP_ARMOUR) - prop (CFAPI_INT, OBJECT_PROP_WEIGHT) - prop (CFAPI_INT, OBJECT_PROP_WEIGHT_LIMIT) - prop (CFAPI_INT, OBJECT_PROP_CARRYING) - prop (CFAPI_INT, OBJECT_PROP_GLOW_RADIUS) - prop (CFAPI_LONG, OBJECT_PROP_PERM_EXP) - prop (CFAPI_POBJECT, OBJECT_PROP_CURRENT_WEAPON) - prop (CFAPI_POBJECT, OBJECT_PROP_ENEMY) - prop (CFAPI_POBJECT, OBJECT_PROP_ATTACKED_BY) - prop (CFAPI_INT, OBJECT_PROP_RUN_AWAY) - prop (CFAPI_POBJECT, OBJECT_PROP_CHOSEN_SKILL) - prop (CFAPI_INT, OBJECT_PROP_HIDDEN) - prop (CFAPI_INT, OBJECT_PROP_MOVE_STATUS) - prop (CFAPI_INT, OBJECT_PROP_MOVE_TYPE) - prop (CFAPI_POBJECT, OBJECT_PROP_SPELL_ITEM) - prop (CFAPI_DOUBLE, OBJECT_PROP_EXP_MULTIPLIER) - prop (CFAPI_PARCH, OBJECT_PROP_ARCHETYPE) - prop (CFAPI_PARCH, OBJECT_PROP_OTHER_ARCH) - prop (CFAPI_STRING, OBJECT_PROP_CUSTOM_NAME) - prop (CFAPI_INT, OBJECT_PROP_ANIM_SPEED) - prop (CFAPI_INT, OBJECT_PROP_FRIENDLY) - prop (CFAPI_STRING, OBJECT_PROP_SHORT_NAME) - prop (CFAPI_INT, OBJECT_PROP_MAGICAL) - prop (CFAPI_INT, OBJECT_PROP_LUCK) - prop (CFAPI_POBJECT, OBJECT_PROP_OWNER) - prop (CFAPI_POBJECT, OBJECT_PROP_PRESENT) - prop (CFAPI_INT, OBJECT_PROP_CHEATER) - prop (CFAPI_INT, OBJECT_PROP_MERGEABLE) - prop (CFAPI_INT, OBJECT_PROP_PICKABLE) - prop (CFAPI_INT, OBJECT_PROP_STR) - prop (CFAPI_INT, OBJECT_PROP_DEX) - prop (CFAPI_INT, OBJECT_PROP_CON) - prop (CFAPI_INT, OBJECT_PROP_WIS) - prop (CFAPI_INT, OBJECT_PROP_INT) - prop (CFAPI_INT, OBJECT_PROP_POW) - prop (CFAPI_INT, OBJECT_PROP_CHA) - prop (CFAPI_INT, OBJECT_PROP_WC) - prop (CFAPI_INT, OBJECT_PROP_AC) - prop (CFAPI_INT, OBJECT_PROP_HP) - prop (CFAPI_INT, OBJECT_PROP_SP) - prop (CFAPI_INT, OBJECT_PROP_GP) - prop (CFAPI_INT, OBJECT_PROP_FP) - prop (CFAPI_INT, OBJECT_PROP_MAXHP) - prop (CFAPI_INT, OBJECT_PROP_MAXSP) - prop (CFAPI_INT, OBJECT_PROP_MAXGP) - prop (CFAPI_INT, OBJECT_PROP_DAM) - prop (CFAPI_STRING, OBJECT_PROP_GOD) - prop (CFAPI_STRING, OBJECT_PROP_ARCH_NAME) - prop (CFAPI_INT, OBJECT_PROP_INVISIBLE) - prop (CFAPI_INT, OBJECT_PROP_FACE) - }; - - HV *prop_type = get_hv ("cf::PROP_TYPE", 1); - HV *prop_idx = get_hv ("cf::PROP_IDX", 1); - - for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) - { - hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); - hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); - } - //I_EVENT_API (PACKAGE); } -void _reload_1 () +void _init_vars () CODE: cb_global = get_av ("cf::CB_GLOBAL", 1); cb_object = get_av ("cf::CB_OBJECT", 1); @@ -1496,17 +1668,17 @@ cb_type = get_av ("cf::CB_TYPE" , 1); cb_map = get_av ("cf::CB_MAP" , 1); -void _reload_2 () +void _global_reattach () CODE: { // reattach to all attachable objects in the game. for (player *pl = first_player; pl; pl = pl->next) reattach (pl); - for (mapstruct *map = first_map; map; map = map->next) + for (maptile *map = first_map; map; map = map->next) reattach (map); - for (object *op = objects; op; op = op->next) + for (object *op = object::first; op; op = op->next) reattach (op); } @@ -1527,10 +1699,13 @@ char *path_combine_and_normalize (char *base, char *path) PROTOTYPE: $$ -char * -cf_get_maps_directory (char *path) +const char * +get_maps_directory (char *path) PROTOTYPE: $ ALIAS: maps_directory = 0 + CODE: + RETVAL = create_pathname (path); + OUTPUT: RETVAL void sub_generation_inc () @@ -1549,27 +1724,34 @@ playerdir = 5 datadir = 6 CODE: -{ - int unused_type; - RETVAL = (char *)systemDirectory (&unused_type, ix); -} + switch (ix) + { + case 0: RETVAL = settings.mapdir ; break; + case 1: RETVAL = settings.uniquedir; break; + case 2: RETVAL = settings.tmpdir ; break; + case 3: RETVAL = settings.confdir ; break; + case 4: RETVAL = settings.localdir ; break; + case 5: RETVAL = settings.playerdir; break; + case 6: RETVAL = settings.datadir ; break; + } OUTPUT: RETVAL -int -cf_find_animation (char *text) +void _exit (int status = 0) + +int cf_find_animation (char *text) PROTOTYPE: $ int random_roll(int min, int max, object *op, int goodbad); const char *cost_string_from_value(uint64 cost, int approx = 0) -int invoke (int event, SV *arg1, ...) +int invoke (int event, ...) CODE: -{ - // parse first arg and call invoke_object etc as seen fit - //TODO - //cfperl_invoke (event, -} + 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 int exp_to_level (val64 exp) @@ -1610,72 +1792,66 @@ XSRETURN_UNDEF; OUTPUT: RETVAL +int +_valid (SV *obj) + CODE: + RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); + OUTPUT: + RETVAL + MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ -SV * -get_property (object *obj, int type, int idx) +INCLUDE: $PERL genacc object ../include/object.h | + +int invoke (object *op, int event, ...) CODE: - RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx)); + 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)); OUTPUT: RETVAL -SV * -set_property (object *obj, int type, int idx, SV *newval) +SV *registry (object *op) CODE: - switch (type) - { - case CFAPI_INT: - cf_object_set_int_property (obj, idx, SvIV (newval)); - break; - case CFAPI_LONG: - cf_object_set_long_property (obj, idx, (long) SvVAL64 (newval)); - break; - case CFAPI_DOUBLE: - { - int unused_type; - object_set_property (&unused_type, obj, idx, (double)SvNV (newval)); - } - break; - case CFAPI_STRING: - cf_object_set_string_property (obj, idx, SvOK (newval) ? SvPV_nolen (newval) : 0); - break; - case CFAPI_POBJECT: - { - int unused_type; - object_set_property (&unused_type, obj, idx, (object *)SvPTR_ornull (newval, "cf::object")); - } - break; - default: - croak ("unhandled type '%d' in set_property '%d'", type, idx); - } - -# missing properties + RETVAL = registry_of (op); + OUTPUT: + RETVAL -void -set_attacktype (object *obj, U32 attacktype) - CODE: - obj->attacktype = attacktype; +void mortals () + PPCODE: + EXTEND (SP, object::mortals.size ()); + for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) + PUSHs (to_sv (*i)); -U32 -get_attacktype (object *obj) - ALIAS: - attacktype = 0 +object *first () CODE: - RETVAL = obj->attacktype; + RETVAL = object::first; OUTPUT: RETVAL -# missing in plug-in api, of course -void -set_food (object *obj, int food) +# missing properties + +int flag (object *op, int flag, int value = 1) + PROTOTYPE: $$;$ CODE: - obj->stats.food = food; + RETVAL = QUERY_FLAG (op, flag); + if (items >= 3) + if (value) + SET_FLAG (op, flag); + else + CLEAR_FLAG (op, flag); + OUTPUT: RETVAL -int -get_food (object *obj) - ALIAS: - food = 0 +object *head (object *op) + PROTOTYPE: $ CODE: - RETVAL = obj->stats.food; - OUTPUT: RETVAL + RETVAL = op->head ? op->head : op; + OUTPUT: RETVAL + +int is_head (object *op) + PROTOTYPE: $ + CODE: + RETVAL = !op->head; + OUTPUT: RETVAL void inv (object *obj) @@ -1687,19 +1863,22 @@ XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); } -int cf_object_get_resistance (object *op, int rtype) - ALIAS: resistance = 0 +object *find_best_object_match (object *op, const char *match) -int cf_object_get_flag (object *op, int flag) - ALIAS: flag = 0 +object *find_marked_object (object *op) -void cf_object_set_flag (object *op, int flag, int value) +int cf_object_get_resistance (object *op, int rtype) + ALIAS: resistance = 0 int need_identify (const object *obj); int apply_shop_mat (object *shop_mat, object *op); -void cf_object_move (object *op, int dir, object *originator = op) +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) @@ -1713,7 +1892,7 @@ 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, mapstruct *map) +int cf_object_change_map (object *op, int x, int y, maptile *map) object *cf_object_clone (object *op, int clonetype = 0) @@ -1751,18 +1930,11 @@ void cf_object_take (object *op, object *author) -void cf_object_say (object *op, char *msg) - -void cf_object_speak (object *op, char *msg) - object *cf_object_insert_object (object *op, object *container) -const char *cf_object_get_msg (object *ob) - ALIAS: msg = 0 - object *cf_object_insert_in_ob (object *ob, object *where) -int cf_object_teleport (object *op, mapstruct *map, int x, int y) +int cf_object_teleport (object *op, maptile *map, int x, int y) void cf_object_update (object *op, int flags) @@ -1782,7 +1954,7 @@ void use_trigger (object *op); -void add_button_link (object *button, mapstruct *map, int connected); +void add_button_link (object *button, maptile *map, int connected); void remove_button_link (object *op); @@ -1810,7 +1982,7 @@ OUTPUT: RETVAL -object *insert_ob_in_map_at (object *ob, mapstruct *where, object_ornull *orig, int flag, int x, int y) +object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) PROTOTYPE: $$$$$$ CODE: { @@ -1818,12 +1990,6 @@ RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); } -SV *registry (object *op) - CODE: - RETVAL = registry_of (op); - OUTPUT: - RETVAL - # syntatic sugar for easier use in event callbacks. const char *options (object *op) CODE: @@ -1864,19 +2030,12 @@ RETVAL = on_same_map (ob, other); OUTPUT: RETVAL -char * -base_name (object *ob, int plural) +const char * +base_name (object *op, int plural = op->nrof > 1) CODE: - RETVAL = cf_query_base_name (ob, plural); + RETVAL = query_base_name (op, plural); OUTPUT: RETVAL -living * -stats (object *ob) - CODE: - RETVAL = &ob->stats; - OUTPUT: RETVAL - - MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ player *player (object *op) @@ -1903,8 +2062,50 @@ void kill_player (object *op) +void esrv_update_item (object *op, int what, object *item) + C_ARGS: what, op, item + +void clear_los (object *op) + +int command_reset (object *op, char *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) + + 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 + +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)); + OUTPUT: RETVAL + SV *registry (player *pl) CODE: RETVAL = registry_of (pl); @@ -1918,12 +2119,6 @@ void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); -# nonstandard -object *ob (player *pl) - CODE: - RETVAL = pl->ob; - OUTPUT: RETVAL - player *first () CODE: RETVAL = first_player; @@ -1942,29 +2137,6 @@ OUTPUT: RETVAL -char * -client (player *pl) - CODE: - RETVAL = pl->socket.client; - OUTPUT: - RETVAL - -char * -host (player *pl) - CODE: - RETVAL = pl->socket.host; - OUTPUT: - RETVAL - -char * -killer (player *pl, char *killer = 0) - CODE: - if (killer) - snprintf (pl->killer, sizeof (pl->killer), "%s", killer); - RETVAL = pl->killer; - OUTPUT: - RETVAL - void buggy_mapscroll (player *pl, int value = 1) CODE: @@ -1989,20 +2161,19 @@ OUTPUT: RETVAL -void get_savebed (player *pl) - ALIAS: - savebed = 0 +void savebed (player *pl, SV *map_path = 0, SV *x = 0, SV *y = 0) + PROTOTYPE: $;$$$ PPCODE: - EXTEND (SP, 3); - PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0))); - PUSHs (sv_2mortal (newSViv (pl->bed_x))); - PUSHs (sv_2mortal (newSViv (pl->bed_y))); - -void set_savebed (player *pl, char *map_path, int x, int y) - CODE: - strcpy (pl->savebed_map, map_path); - pl->bed_x = x; - pl->bed_y = y; + if (GIMME_V != G_VOID) + { + EXTEND (SP, 3); + PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0))); + PUSHs (sv_2mortal (newSViv (pl->bed_x))); + PUSHs (sv_2mortal (newSViv (pl->bed_y))); + } + if (map_path) sv_to (map_path, pl->savebed_map); + if (x) sv_to (x, pl->bed_x); + if (y) sv_to (y, pl->bed_y); void list () @@ -2038,53 +2209,50 @@ MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ -SV *registry (mapstruct *map) - CODE: - RETVAL = registry_of (map); - OUTPUT: - RETVAL +maptile *first () + PROTOTYPE: + CODE: + RETVAL = first_map; + OUTPUT: RETVAL -SV * -get_property (mapstruct *obj, int type, int idx) +int invoke (maptile *map, int event, ...) CODE: - RETVAL = newSVcfapi (type, cf_map_get_property (obj, idx)); + 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)); OUTPUT: RETVAL -SV * -set_property (mapstruct *obj, int type, int idx, SV *newval) +SV *registry (maptile *map) CODE: - switch (type) - { - case CFAPI_INT: - cf_map_set_int_property (obj, idx, SvIV (newval)); - break; - default: - croak ("unhandled type '%d' in set_property '%d'", type, idx); - } + RETVAL = registry_of (map); + OUTPUT: + RETVAL -mapstruct *new (int width, int height) +INCLUDE: $PERL genacc maptile ../include/map.h | + +maptile *new (int width, int height) PROTOTYPE: CODE: { - int unused_type; - RETVAL = (mapstruct*) map_get_map (&unused_type, 0, width, height); + RETVAL = get_empty_map (width, height); } OUTPUT: RETVAL -void delete_map (mapstruct *map) +void delete_map (maptile *map) -void clean_tmp_map (mapstruct *map) +void clean_tmp_map (maptile *map) -void play_sound_map (mapstruct *map, int x, int y, int sound_num) +void play_sound_map (maptile *map, int x, int y, int sound_num) -mapstruct *tile_map (mapstruct *map, unsigned int dir) +maptile *tile_map (maptile *map, unsigned int dir) CODE: RETVAL = dir < 4 ? map->tile_map [dir] : 0; OUTPUT: RETVAL -char *tile_path (mapstruct *map, unsigned int dir) +char *tile_path (maptile *map, unsigned int dir) CODE: if (dir >= 4) XSRETURN_UNDEF; @@ -2092,54 +2260,48 @@ OUTPUT: RETVAL -mapstruct *cf_map_get_map (char *name) - PROTOTYPE: $ - ALIAS: map = 0 +maptile *ready_map_name (char *name, int flags = 0) + PROTOTYPE: $;$ + ALIAS: + find = 0 + get_map = 1 -mapstruct *has_been_loaded (char *name) +maptile *has_been_loaded (char *name) PROTOTYPE: $ -mapstruct *cf_map_get_first () - PROTOTYPE: - ALIAS: first = 0 - -# whoever "designed" the plug-in api should have wasted -# his/her time with staying away from the project - would have -# saved others a lot of time, without doubt. -void set_path (mapstruct *where, char *path) - CODE: - strcpy (where->path, path); - -int in_memory (mapstruct *map) +int in_memory (maptile *map) CODE: RETVAL = map->in_memory; OUTPUT: RETVAL -bool unique (mapstruct *map) - CODE: - RETVAL = map->unique; - OUTPUT: - RETVAL +void +trigger (maptile *map, long connection, bool state = true) + CODE: + activate_connection (map, connection, state); -void set_unique (mapstruct *map, bool unique) - CODE: - map->unique = unique; +void +get_connection (maptile *map, long connection) + PPCODE: + oblinkpt *obp = get_connection_links (map, connection); + if (obp) + for (objectlink *ol = obp->link; ol; ol = ol->next) + XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, (object *)ol->ob))); -object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) +object *cf_map_insert_object_there (maptile *where, object *op, object *originator, int flags) -object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) +object *cf_map_insert_object (maptile *where, object* op, int x, int y) -object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) +object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny) C_ARGS: str, map, nx, ny void -cf_map_normalise (mapstruct *map, int x, int y) +cf_map_normalise (maptile *map, int x, int y) PPCODE: { - mapstruct *nmap = 0; + maptile *nmap = 0; I16 nx = 0, ny = 0; - int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny); + int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); EXTEND (SP, 4); PUSHs (sv_2mortal (newSViv (flags))); @@ -2153,15 +2315,15 @@ } void -at (mapstruct *map, unsigned int x, unsigned int y) +at (maptile *map, unsigned int x, unsigned int y) PROTOTYPE: $$$ PPCODE: { object *o; - mapstruct *nmap = 0; + maptile *nmap = 0; I16 nx, ny; - cf_map_get_flags (map, &nmap, x, y, &nx, &ny); + get_map_flags (map, &nmap, x, y, &nx, &ny); if (nmap) for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) @@ -2169,7 +2331,7 @@ } SV * -bot_at (mapstruct *obj, unsigned int x, unsigned int y) +bot_at (maptile *obj, unsigned int x, unsigned int y) PROTOTYPE: $$$ ALIAS: top_at = 1 @@ -2196,153 +2358,80 @@ OUTPUT: RETVAL -# "deserialise" perl map data into the map # TODO# compatibility cruft, remove -void -_set_obs (mapstruct *map, SV *sv) - CODE: -{ - object *o; - AV *av; - int x, y; - AV *obs = (AV *)SvRV (sv); - - for (y = 0; y < MAP_HEIGHT (map); y++) - for (x = 0; x < MAP_WIDTH (map); x++) - { - sv = *av_fetch (obs, x + y * MAP_HEIGHT (map), 1); - - if (!SvROK (sv)) - continue; - - av = (AV *)SvRV (sv); - for (o = GET_MAP_OB (map, x, y); o; o = o->above) - { - sv = av_shift (av); +MODULE = cf PACKAGE = cf::arch - if (SvROK (sv)) - { - sv_magic ((SV *)SvRV (sv), 0, PERL_MAGIC_ext, (char *)o, 0); - SVptr_cache_set (o, sv); - } - } - } -} - - -MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ +archetype *find (const char *name) + CODE: + RETVAL = archetype::find (name); + OUTPUT: + RETVAL -archetype *cf_archetype_get_first() +archetype *first() PROTOTYPE: - ALIAS: first = 0 - -archetype *cf_archetype_get_next (archetype *arch) - ALIAS: next = 0 - -archetype *cf_archetype_get_head (archetype *arch) - ALIAS: head = 0 - -archetype *cf_archetype_get_more (archetype *arch) - ALIAS: more = 0 - -const char *cf_archetype_get_name (archetype *arch) - ALIAS: name = 0 + CODE: + RETVAL = first_archetype; + OUTPUT: RETVAL -object *cf_archetype_get_clone (archetype *arch) - ALIAS: clone = 0 +INCLUDE: $PERL genacc archetype ../include/object.h | -MODULE = cf PACKAGE = cf::party PREFIX = cf_party_ +MODULE = cf PACKAGE = cf::party -partylist *cf_party_get_first () +partylist *first () PROTOTYPE: - ALIAS: first = 0 - -partylist *cf_party_get_next (partylist *party) - ALIAS: next = 0 - -const char *cf_party_get_name (partylist *party) - -const char *cf_party_get_password (partylist *party) - ALIAS: password = 0 + CODE: + RETVAL = get_firstparty (); + OUTPUT: RETVAL -player *cf_party_get_first_player (partylist *party) - ALIAS: first_player = 0 +partylist *next (partylist *party) + CODE: + RETVAL = party->next; + OUTPUT: RETVAL -player *cf_party_get_next_player (partylist *party, player *op) - ALIAS: next_player = 0 +const char *name (partylist *party) + CODE: + RETVAL = party->partyname; + OUTPUT: RETVAL +const char *password (partylist *party) + CODE: + RETVAL = party->passwd; + OUTPUT: RETVAL -MODULE = cf PACKAGE = cf::region PREFIX = cf_region_ +MODULE = cf PACKAGE = cf::region -region *cf_region_get_first () +region *first () PROTOTYPE: - ALIAS: first = 0 - -const char *cf_region_get_name (region *reg) - ALIAS: name = 0 + CODE: + RETVAL = first_region; + OUTPUT: RETVAL -region *cf_region_get_next (region *reg) - ALIAS: next = 0 +region *next (region *reg) + CODE: + RETVAL = reg->next; + OUTPUT: RETVAL -region *cf_region_get_parent (region *reg) - ALIAS: parent = 0 +const char *name (region *reg) + CODE: + RETVAL = reg->name; + OUTPUT: RETVAL -const char *cf_region_get_longname (region *reg) - ALIAS: longname = 0 +region *parent (region *reg) + CODE: + RETVAL = reg->parent; + OUTPUT: RETVAL -const char *cf_region_get_message (region *reg) - ALIAS: message = 0 +const char *longname (region *reg) + CODE: + RETVAL = reg->longname; + OUTPUT: RETVAL +const char *msg (region *reg) + CODE: + RETVAL = reg->msg; + OUTPUT: RETVAL -MODULE = cf PACKAGE = cf::living PREFIX = cf_living_ +MODULE = cf PACKAGE = cf::living -val64 -exp (living *liv, val64 new_val = 0) - PROTOTYPE: $;$ - ALIAS: - Str = 1 - Dex = 2 - Con = 3 - Wis = 4 - Cha = 5 - Int = 6 - Pow = 7 - wc = 8 - ac = 9 - hp = 10 - maxhp = 11 - sp = 12 - maxsp = 13 - grace = 14 - maxgrace = 15 - food = 16 - dam = 17 - luck = 18 - CODE: -# define LIVING_ACC(acc,idx) case idx: RETVAL = liv->acc; if (items > 1) liv->acc = (sint64)new_val; break - switch (ix) - { - LIVING_ACC (exp , 0); - LIVING_ACC (Str , 1); - LIVING_ACC (Dex , 2); - LIVING_ACC (Con , 3); - LIVING_ACC (Wis , 4); - LIVING_ACC (Cha , 5); - LIVING_ACC (Int , 6); - LIVING_ACC (Pow , 7); - LIVING_ACC (wc , 8); - LIVING_ACC (ac , 9); - LIVING_ACC (hp , 10); - LIVING_ACC (maxhp , 11); - LIVING_ACC (sp , 12); - LIVING_ACC (maxsp , 13); - LIVING_ACC (grace , 14); - LIVING_ACC (maxgrace, 15); - LIVING_ACC (food , 16); - LIVING_ACC (dam , 17); - LIVING_ACC (luck , 18); - } -# undef LIVING_ACC - OUTPUT: - RETVAL +INCLUDE: $PERL genacc living ../include/living.h |