ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.256 by root, Wed Sep 12 11:10:11 2007 UTC vs.
Revision 1.257 by root, Sun Sep 30 16:24:31 2007 UTC

30 30
31#if HAVE_EXECINFO_H 31#if HAVE_EXECINFO_H
32# include <execinfo.h> 32# include <execinfo.h>
33#endif 33#endif
34 34
35#include <plugin_common.h>
36#include <sounds.h>
37#include <cstdarg> 35#include <cstdarg>
36
37#include "global.h"
38#include "loader.h"
39#include "../random_maps/random_map.h"
38#include <sproto.h> 40#include <sproto.h>
39
40#include "loader.h"
41#include "cfperl.h"
42#include "shstr.h"
43 41
44#include <unistd.h> 42#include <unistd.h>
45#if _POSIX_MEMLOCK 43#if _POSIX_MEMLOCK
46# include <sys/mman.h> 44# include <sys/mman.h>
47#endif 45#endif
67#else 65#else
68 typedef double val64; 66 typedef double val64;
69# define newSVval64 newSVnv 67# define newSVval64 newSVnv
70# define SvVAL64 SvNV 68# define SvVAL64 SvNV
71#endif 69#endif
72
73static f_plug_api gethook = cfapi_get_hooks;
74static f_plug_api object_insert = cfapi_object_insert;
75 70
76static PerlInterpreter *perl; 71static PerlInterpreter *perl;
77 72
78tstamp NOW, runtime; 73tstamp NOW, runtime;
79 74
590 va_end (ap); 585 va_end (ap);
591 586
592 return sv; 587 return sv;
593} 588}
594 589
595static SV *
596newSVcfapi (int type, ...)
597{
598 SV *sv;
599
600 va_list ap;
601 va_start (ap, type);
602
603 switch (type)
604 {
605 case CFAPI_INT: sv = newSViv (*va_arg (ap, int * )); break;
606 case CFAPI_LONG: sv = newSVval64 (*va_arg (ap, sint64 *)); break;
607 case CFAPI_DOUBLE: sv = newSVnv (*va_arg (ap, double *)); break;
608 case CFAPI_STRING: sv = newSVdt_va (ap, DT_STRING); break;
609 case CFAPI_POBJECT: sv = newSVdt_va (ap, DT_OBJECT); break;
610 case CFAPI_PMAP: sv = newSVdt_va (ap, DT_MAP ); break;
611 case CFAPI_PPLAYER: sv = newSVdt_va (ap, DT_PLAYER); break;
612 case CFAPI_PARCH: sv = newSVdt_va (ap, DT_ARCH ); break;
613 case CFAPI_PPARTY: sv = newSVdt_va (ap, DT_PARTY ); break;
614 case CFAPI_PREGION: sv = newSVdt_va (ap, DT_REGION); break;
615
616 default:
617 assert (("unhandled type in newSVcfapi", 0));
618 }
619
620 va_end (ap);
621
622 return sv;
623}
624
625////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 590//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
626 591
627SV * 592SV *
628registry (attachable *ext) 593registry (attachable *ext)
629{ 594{
632 597
633 return newRV_inc ((SV *)ext->cb); 598 return newRV_inc ((SV *)ext->cb);
634} 599}
635 600
636///////////////////////////////////////////////////////////////////////////// 601/////////////////////////////////////////////////////////////////////////////
637
638extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr)
639{
640 return 0;
641}
642
643static CommArray_s rtn_cmd;
644
645static int
646runPluginCommand (object *obj, char *params)
647{
648 return -1;
649}
650
651extern "C" void *cfperl_getPluginProperty (int *type, ...)
652{
653 va_list args;
654 char *propname;
655 int i;
656 va_start (args, type);
657 propname = va_arg (args, char *);
658 //printf ("Property name: %s\n", propname);
659
660 if (!strcmp (propname, "command?"))
661 return NULL;
662 else if (!strcmp (propname, "Identification"))
663 {
664 va_end (args);
665 return (void *)PLUGIN_NAME;
666 }
667 else if (!strcmp (propname, "FullName"))
668 {
669 va_end (args);
670 return (void *)PLUGIN_VERSION;
671 }
672 else
673 va_end (args);
674
675 return NULL;
676}
677
678extern "C" int cfperl_postInitPlugin ()
679{
680 int hooktype = 1;
681 int rtype = 0;
682
683 cf_init_plugin (gethook);
684
685 return 0;
686}
687
688extern "C" int cfperl_closePlugin ()
689{
690 return 0;
691}
692 602
693void 603void
694cfperl_init () 604cfperl_init ()
695{ 605{
696 PERL_SYS_INIT3 (&settings.argc, &settings.argv, 0); 606 PERL_SYS_INIT3 (&settings.argc, &settings.argv, 0);
1981 1891
1982int need_identify (object *obj); 1892int need_identify (object *obj);
1983 1893
1984int apply_shop_mat (object *shop_mat, object *op); 1894int apply_shop_mat (object *shop_mat, object *op);
1985 1895
1986int move_player (object *op, int dir)
1987 CODE:
1988 RETVAL = move_player (op, dir);
1989 OUTPUT:
1990 RETVAL
1991
1992int move (object *op, int dir, object *originator = op) 1896int move (object *op, int dir, object *originator = op)
1993 CODE: 1897 CODE:
1994 RETVAL = move_ob (op, dir, originator); 1898 RETVAL = move_ob (op, dir, originator);
1995 OUTPUT: 1899 OUTPUT:
1996 RETVAL 1900 RETVAL
2002void apply_below (object *op) 1906void apply_below (object *op)
2003 CODE: 1907 CODE:
2004 player_apply_below (op); 1908 player_apply_below (op);
2005 1909
2006int cast_heal (object *op, object *caster, object *spell, int dir = 0) 1910int cast_heal (object *op, object *caster, object *spell, int dir = 0)
2007
2008object *cf_object_present_archname_inside (object *op, utf8_string whatstr)
2009
2010int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
2011
2012int cf_object_change_map (object *op, int x, int y, maptile *map)
2013 1911
2014#//TODO 1912#//TODO
2015object *clone_ (object *op, int recursive = 0) 1913object *clone_ (object *op, int recursive = 0)
2016 CODE: 1914 CODE:
2017 if (recursive) 1915 if (recursive)
2064 1962
2065void drop (object *who, object *op) 1963void drop (object *who, object *op)
2066 1964
2067void pick_up (object *who, object *op) 1965void pick_up (object *who, object *op)
2068 1966
2069int cf_object_teleport (object *op, maptile *map, int x, int y)
2070
2071void update_object (object *op, int action) 1967void update_object (object *op, int action)
2072 1968
2073object *cf_create_object_by_name (utf8_string name)
2074
2075void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 1969void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0)
2076 1970
2077void player_lvl_adj (object *who, object *skill = 0) 1971void player_lvl_adj (object *who, object *skill = 0)
2078 1972
2079int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 1973int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2090 1984
2091void handle_apply_yield (object *op); 1985void handle_apply_yield (object *op);
2092 1986
2093 1987
2094MODULE = cf PACKAGE = cf::object PREFIX = cf_ 1988MODULE = cf PACKAGE = cf::object PREFIX = cf_
2095
2096object *cf_insert_ob_in_ob (object *ob, object *where)
2097 1989
2098# no clean way to get an object from an archetype - stupid idiotic 1990# no clean way to get an object from an archetype - stupid idiotic
2099# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 1991# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2100 1992
2101object *new (utf8_string archetype = 0) 1993object *new (utf8_string archetype = 0)
2110# TODO: nuke 2002# TODO: nuke
2111object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) 2003object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
2112 PROTOTYPE: $$$$$$ 2004 PROTOTYPE: $$$$$$
2113 CODE: 2005 CODE:
2114{ 2006{
2115 int unused_type; 2007 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2116 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
2117} 2008}
2118 2009
2119const_utf8_string get_ob_key_value (object *op, utf8_string key) 2010const_utf8_string get_ob_key_value (object *op, utf8_string key)
2120 2011
2121bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) 2012bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1)
2134 EXTEND (SP, 5); 2025 EXTEND (SP, 5);
2135 PUSHs (newSVuv (rv.distance)); 2026 PUSHs (newSVuv (rv.distance));
2136 PUSHs (newSViv (rv.distance_x)); 2027 PUSHs (newSViv (rv.distance_x));
2137 PUSHs (newSViv (rv.distance_y)); 2028 PUSHs (newSViv (rv.distance_y));
2138 PUSHs (newSViv (rv.direction)); 2029 PUSHs (newSViv (rv.direction));
2139 PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part)); 2030 PUSHs (to_sv (rv.part));
2140} 2031}
2141 2032
2142bool on_same_map_as (object *ob, object *other) 2033bool on_same_map_as (object *ob, object *other)
2143 CODE: 2034 CODE:
2144 RETVAL = on_same_map (ob, other); 2035 RETVAL = on_same_map (ob, other);
2164player *player (object *op) 2055player *player (object *op)
2165 CODE: 2056 CODE:
2166 RETVAL = op->contr; 2057 RETVAL = op->contr;
2167 OUTPUT: RETVAL 2058 OUTPUT: RETVAL
2168 2059
2060bool move_player (object *op, int dir)
2061
2169void check_score (object *op) 2062void check_score (object *op)
2170 2063
2171void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2064void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
2172 CODE: 2065 CODE:
2173 new_draw_info (flags, 0, op, txt); 2066 new_draw_info (flags, 0, op, txt);
2174 2067
2175void kill_player (object *op) 2068void kill_player (object *op)
2176 2069
2070void esrv_send_item (object *pl, object *item)
2071
2177void esrv_update_item (object *op, int what, object *item) 2072void esrv_update_item (object *pl, int what, object *item)
2178 C_ARGS: what, op, item 2073 C_ARGS: what, pl, item
2074
2075void esrv_del_item (object *pl, int tag)
2076 C_ARGS: pl->contr, tag
2179 2077
2180int command_summon (object *op, utf8_string params) 2078int command_summon (object *op, utf8_string params)
2181 2079
2182int command_arrest (object *op, utf8_string params) 2080int command_arrest (object *op, utf8_string params)
2183 2081
2203 pl->ob->stats.sp = pl->ob->stats.maxsp; 2101 pl->ob->stats.sp = pl->ob->stats.maxsp;
2204 pl->ob->stats.grace = pl->ob->stats.maxgrace; 2102 pl->ob->stats.grace = pl->ob->stats.maxgrace;
2205 pl->orig_stats = pl->ob->stats; 2103 pl->orig_stats = pl->ob->stats;
2206 2104
2207void clear_los (player *pl) 2105void clear_los (player *pl)
2208
2209void cf_player_move (player *pl, int dir)
2210 2106
2211bool 2107bool
2212cell_visible (player *pl, int dx, int dy) 2108cell_visible (player *pl, int dx, int dy)
2213 CODE: 2109 CODE:
2214 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2110 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2432get_connection (maptile *map, long connection) 2328get_connection (maptile *map, long connection)
2433 PPCODE: 2329 PPCODE:
2434 oblinkpt *obp = get_connection_links (map, connection); 2330 oblinkpt *obp = get_connection_links (map, connection);
2435 if (obp) 2331 if (obp)
2436 for (objectlink *ol = obp->link; ol; ol = ol->next) 2332 for (objectlink *ol = obp->link; ol; ol = ol->next)
2437 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, (object *)ol->ob))); 2333 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2438
2439object *cf_map_insert_object_there (maptile *where, object *op, object *originator, int flags)
2440
2441object *cf_map_insert_object (maptile *where, object* op, int x, int y)
2442
2443object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny)
2444 C_ARGS: str, map, nx, ny
2445 2334
2446void 2335void
2447get_map_flags (maptile *map, int x, int y) 2336get_map_flags (maptile *map, int x, int y)
2448 PPCODE: 2337 PPCODE:
2449{ 2338{
2454 EXTEND (SP, 4); 2343 EXTEND (SP, 4);
2455 PUSHs (sv_2mortal (newSViv (flags))); 2344 PUSHs (sv_2mortal (newSViv (flags)));
2456 2345
2457 if (GIMME_V == G_ARRAY) 2346 if (GIMME_V == G_ARRAY)
2458 { 2347 {
2459 PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap))); 2348 PUSHs (sv_2mortal (to_sv (nmap)));
2460 PUSHs (sv_2mortal (newSViv (nx))); 2349 PUSHs (sv_2mortal (newSViv (nx)));
2461 PUSHs (sv_2mortal (newSViv (ny))); 2350 PUSHs (sv_2mortal (newSViv (ny)));
2462 } 2351 }
2463} 2352}
2464 2353
2473 2362
2474 get_map_flags (map, &nmap, x, y, &nx, &ny); 2363 get_map_flags (map, &nmap, x, y, &nx, &ny);
2475 2364
2476 if (nmap) 2365 if (nmap)
2477 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) 2366 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
2478 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 2367 XPUSHs (sv_2mortal (to_sv (o)));
2479} 2368}
2480 2369
2481SV * 2370SV *
2482bot_at (maptile *obj, unsigned int x, unsigned int y) 2371bot_at (maptile *obj, unsigned int x, unsigned int y)
2483 PROTOTYPE: $$$ 2372 PROTOTYPE: $$$
2492 INIT: 2381 INIT:
2493 if (x >= obj->width || y >= obj->height) XSRETURN_UNDEF; 2382 if (x >= obj->width || y >= obj->height) XSRETURN_UNDEF;
2494 CODE: 2383 CODE:
2495 switch (ix) 2384 switch (ix)
2496 { 2385 {
2497 case 0: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_OB (obj, x, y)); break; 2386 case 0: RETVAL = to_sv (GET_MAP_OB (obj, x, y)); break;
2498 case 1: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_TOP (obj, x, y)); break; 2387 case 1: RETVAL = to_sv (GET_MAP_TOP (obj, x, y)); break;
2499 case 2: RETVAL = newSVuv ( GET_MAP_FLAGS (obj, x, y)); break; 2388 case 2: RETVAL = newSVuv (GET_MAP_FLAGS (obj, x, y)); break;
2500 case 3: RETVAL = newSViv ( GET_MAP_LIGHT (obj, x, y)); break; 2389 case 3: RETVAL = newSViv (GET_MAP_LIGHT (obj, x, y)); break;
2501 case 4: RETVAL = newSVuv ( GET_MAP_MOVE_BLOCK (obj, x, y)); break; 2390 case 4: RETVAL = newSVuv (GET_MAP_MOVE_BLOCK (obj, x, y)); break;
2502 case 5: RETVAL = newSVuv ( GET_MAP_MOVE_SLOW (obj, x, y)); break; 2391 case 5: RETVAL = newSVuv (GET_MAP_MOVE_SLOW (obj, x, y)); break;
2503 case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break; 2392 case 6: RETVAL = newSVuv (GET_MAP_MOVE_ON (obj, x, y)); break;
2504 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; 2393 case 7: RETVAL = newSVuv (GET_MAP_MOVE_OFF (obj, x, y)); break;
2505 } 2394 }
2506 OUTPUT: RETVAL 2395 OUTPUT: RETVAL
2507 2396
2508void fix_walls (maptile *map, int x, int y) 2397void fix_walls (maptile *map, int x, int y)
2509 2398

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines