--- deliantra/server/plugins/cfperl/cfperl.xs 2006/02/03 21:22:53 1.6 +++ deliantra/server/plugins/cfperl/cfperl.xs 2006/02/07 03:01:29 1.12 @@ -1,29 +1,29 @@ /*****************************************************************************/ -/* That code is placed under the GNU General Public Licence (GPL) */ -/* (C)2001-2005 by Chachkoff Yann (Feel free to deliver your complaints) */ -/*****************************************************************************/ -/* CrossFire, A Multiplayer game for X-windows */ -/* */ -/* Copyright (C) 2000 Mark Wedel */ -/* Copyright (C) 1992 Frank Tore Johansen */ -/* Copyright (C) 2006 perl plugin 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* 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 +*/ + #include #include #include @@ -53,6 +53,8 @@ static f_plug_api registerGlobalEvent; static f_plug_api unregisterGlobalEvent; static f_plug_api systemDirectory; +static f_plug_api object_set_property; +static f_plug_api map_get_map; typedef struct { @@ -130,7 +132,10 @@ break; case CFAPI_STRING: - sv = newSVpv (va_arg (args, char *), 0); + { + char *str = va_arg (args, char *); + sv = str ? newSVpv (str, 0) : &PL_sv_undef; + } break; case CFAPI_POBJECT: @@ -333,6 +338,9 @@ registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); + object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property"); + map_get_map = gethook (&rtype, hooktype, "cfapi_map_get_map"); + cf_init_plugin (gethook); /* Pick the global events you want to monitor from this plugin */ @@ -542,7 +550,7 @@ { HV *stash = gv_stashpv ("cf", 1); - const struct { + static const struct { const char *name; IV iv; } *civ, const_iv[] = { @@ -831,12 +839,21 @@ const_iv (F_OPEN) const_iv (F_NOPICK) const_iv (F_LOCKED) + + 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) }; for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); - const struct { + static const struct { const char *name; IV iv; } *event, event_list[] = { @@ -877,7 +894,7 @@ for (event = event_list + sizeof (event_list) / sizeof (event_list [0]); event-- > event_list; ) av_store (av, event->iv, newSVpv ((char *)event->name, 0)); - const struct { + static const struct { int dtype; const char *name; IV idx; @@ -1066,6 +1083,12 @@ case CFAPI_LONG: cf_object_set_long_property (obj, idx, SvNV (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, SvPV_nolen (newval)); break; @@ -1073,6 +1096,16 @@ croak ("unhandled type '%d' in set_property '%d'", type, idx); } +SV * +inv (object *obj) + PROTOTYPE: $ + PPCODE: +{ + object *o; + for (o = obj->inv; o; o = o->below) + XPUSHs (newSVcfapi (CFAPI_POBJECT, o)); +} + int cf_object_get_resistance (object *op, int rtype) ALIAS: resistance = 0 @@ -1159,17 +1192,18 @@ MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ -object *cf_create_object () - PROTOTYPE: - ALIAS: new = 0 - -object *cf_create_object_by_name (const char *name) - PROTOTYPE: $ - ALIAS: new_from_name = 0 - -void cf_free_object (object *ob) +object *cf_create_object_by_name (const char *name = 0) + PROTOTYPE: ;$ + ALIAS: + create_object = 0 + new = 0 + CODE: + RETVAL = name ? cf_create_object_by_name (name) : cf_create_object (); + OUTPUT: + RETVAL void cf_fix_object (object *pl) + ALIAS: fix = 0 object *cf_insert_ob_in_ob (object *ob, object *where) @@ -1235,6 +1269,16 @@ croak ("unhandled type '%d' in set_property '%d'", type, idx); } +mapstruct *new (int width, int height) + PROTOTYPE: + CODE: +{ + int unused_type; + RETVAL = map_get_map (&unused_type, 0, width, height); +} + OUTPUT: + RETVAL + mapstruct *cf_map_get_map (char *name) PROTOTYPE: $ ALIAS: map = 0 @@ -1252,11 +1296,50 @@ #int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny) +SV * +at (mapstruct *obj, unsigned int x, unsigned int y) + PROTOTYPE: $$$ + INIT: + if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_UNDEF; + PPCODE: +{ + object *o; + for (o = GET_MAP_OB (obj, x, y); o; o = o->above) + XPUSHs (newSVcfapi (CFAPI_POBJECT, o)); +} + +SV * +bot_at (mapstruct *obj, unsigned int x, unsigned int y) + PROTOTYPE: $$$ + ALIAS: + top_at = 1 + flags_at = 2 + light_at = 3 + move_block_at = 4 + move_slow_at = 5 + move_on_at = 6 + move_off_at = 7 + INIT: + if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_UNDEF; + CODE: + switch (ix) + { + case 0: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_OB (obj, x, y)); break; + case 1: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_TOP (obj, x, y)); break; + case 2: RETVAL = newSVuv ( GET_MAP_FLAGS (obj, x, y)); break; + case 3: RETVAL = newSViv ( GET_MAP_LIGHT (obj, x, y)); break; + case 4: RETVAL = newSVuv ( GET_MAP_MOVE_BLOCK (obj, x, y)); break; + case 5: RETVAL = newSVuv ( GET_MAP_MOVE_SLOW (obj, x, y)); break; + 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 MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ -archetype*cf_archetype_get_first() +archetype *cf_archetype_get_first() PROTOTYPE: ALIAS: first = 0