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

Comparing deliantra/server/plugins/cfperl/cfperl.xs (file contents):
Revision 1.49 by pippijn, Mon May 1 12:56:18 2006 UTC vs.
Revision 1.57 by root, Tue Jul 11 15:25:00 2006 UTC

45#include <plugin_common.h> 45#include <plugin_common.h>
46#include <sounds.h> 46#include <sounds.h>
47 47
48#include <stdarg.h> 48#include <stdarg.h>
49 49
50//#include "EventAPI.h"
50#include "perlxsi.c" 51#include "perlxsi.c"
51 52
52typedef object object_ornull; 53typedef object object_ornull;
53typedef mapstruct mapstruct_ornull; 54typedef mapstruct mapstruct_ornull;
54 55
427 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); 428 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener);
428 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); 429 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener);
429 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); 430 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener);
430 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); 431 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener);
431 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); 432 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener);
433 registerGlobalEvent (NULL, EVENT_EXTCMD, PLUGIN_NAME, globalEventListener);
432 434
433 char *argv[] = { 435 char *argv[] = {
434 "", 436 "",
435 "-e" 437 "-e"
436 "BEGIN {" 438 "BEGIN {"
442 }; 444 };
443 445
444 perl = perl_alloc (); 446 perl = perl_alloc ();
445 perl_construct (perl); 447 perl_construct (perl);
446 448
449 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
450
447 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 451 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
448 { 452 {
449 printf ("unable to initialize perl-interpreter, continuing without.\n"); 453 printf ("unable to initialize perl-interpreter, continuing without.\n");
450 454
451 perl_destruct (perl); 455 perl_destruct (perl);
485 if (sv) 489 if (sv)
486 clearSVptr (sv); 490 clearSVptr (sv);
487 491
488 rv = 0; 492 rv = 0;
489 } 493 }
494 else if (event_code == EVENT_CLOCK)
495 {
496 dSP;
497 int i, count;
498
499 clean_obj_cache ();
500
501 ENTER;
502 SAVETMPS;
503
504 // service up to 8 events per tick better would be
505 // to check for elapsed time and stop processing after
506 // 0.25 * server_tick or so
507 for (i = 9; --i; )
508 {
509 PUSHMARK (SP);
510 XPUSHs (sv_2mortal (newSViv (0)));
511 PUTBACK;
512 count = call_pv ("Event::one_event", G_SCALAR | G_EVAL);
513 SPAGAIN;
514
515 if (!count || !POPi)
516 break;
517 }
518
519 FREETMPS;
520 LEAVE;
521 }
490 else 522 else
491 { 523 {
492 dSP; 524 dSP;
493 525
494 ENTER; 526 ENTER;
542 case EVENT_KICK: 574 case EVENT_KICK:
543 PUSH_OB; 575 PUSH_OB;
544 PUSH_PV; 576 PUSH_PV;
545 break; 577 break;
546 578
547 case EVENT_CLOCK: 579 case EVENT_EXTCMD:
548 clean_obj_cache (); 580 PUSH_PL;
581 {
582 char *buf = va_arg (args, char *);
583 int len = va_arg (args, int);
584 PUSHs (sv_2mortal (newSVpvn (buf, len)));
585 }
549 break; 586 break;
550 587
551 case EVENT_TELL: 588 case EVENT_TELL:
552 break; 589 break;
553 } 590 }
1117 const_iv (SOUND_CLOCK) 1154 const_iv (SOUND_CLOCK)
1118 const_iv (SOUND_TURN_HANDLE) 1155 const_iv (SOUND_TURN_HANDLE)
1119 const_iv (SOUND_FALL_HOLE) 1156 const_iv (SOUND_FALL_HOLE)
1120 const_iv (SOUND_DRINK_POISON) 1157 const_iv (SOUND_DRINK_POISON)
1121 const_iv (SOUND_CAST_SPELL_0) 1158 const_iv (SOUND_CAST_SPELL_0)
1159
1160 const_iv (MAP_FLUSH)
1161 const_iv (MAP_PLAYER_UNIQUE)
1162 const_iv (MAP_BLOCK)
1163 const_iv (MAP_STYLE)
1164 const_iv (MAP_OVERLAY)
1165
1166 const_iv (MAP_IN_MEMORY)
1167 const_iv (MAP_SWAPPED)
1168 const_iv (MAP_LOADING)
1169 const_iv (MAP_SAVING)
1122 }; 1170 };
1123 1171
1124 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1172 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1125 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1173 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1126 1174
1143 const_event (CLOSE) 1191 const_event (CLOSE)
1144 const_event (TIMER) 1192 const_event (TIMER)
1145 const_event (MOVE) 1193 const_event (MOVE)
1146 1194
1147 const_event (BORN) 1195 const_event (BORN)
1148 const_event (CLOCK) 1196 //const_event (CLOCK)
1149 const_event (CRASH) 1197 const_event (CRASH)
1150 const_event (PLAYER_DEATH) 1198 const_event (PLAYER_DEATH)
1151 const_event (PLAYER_LOAD) 1199 const_event (PLAYER_LOAD)
1152 const_event (PLAYER_SAVE) 1200 const_event (PLAYER_SAVE)
1153 const_event (GKILL) 1201 const_event (GKILL)
1163 const_event (REMOVE) 1211 const_event (REMOVE)
1164 const_event (SHOUT) 1212 const_event (SHOUT)
1165 const_event (TELL) 1213 const_event (TELL)
1166 const_event (MUZZLE) 1214 const_event (MUZZLE)
1167 const_event (KICK) 1215 const_event (KICK)
1216 const_event (EXTCMD)
1168 //const_event (FREE_OB) 1217 //const_event (FREE_OB)
1169 }; 1218 };
1170 1219
1171 AV *av = get_av ("cf::EVENT", 1); 1220 AV *av = get_av ("cf::EVENT", 1);
1172 1221
1306 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) 1355 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; )
1307 { 1356 {
1308 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); 1357 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0);
1309 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); 1358 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0);
1310 } 1359 }
1360
1361 //I_EVENT_API (PACKAGE);
1311} 1362}
1312 1363
1313void 1364void
1314LOG (int level, char *msg) 1365LOG (int level, char *msg)
1315 PROTOTYPE: $$ 1366 PROTOTYPE: $$
1316 C_ARGS: level, "%s", msg 1367 C_ARGS: level, "%s", msg
1368
1369char *path_combine (char *base, char *path)
1370 PROTOTYPE: $$
1371
1372char *path_combine_and_normalize (char *base, char *path)
1373 PROTOTYPE: $$
1317 1374
1318char * 1375char *
1319cf_get_maps_directory (char *path) 1376cf_get_maps_directory (char *path)
1320 PROTOTYPE: $ 1377 PROTOTYPE: $
1321 ALIAS: maps_directory = 0 1378 ALIAS: maps_directory = 0
1490 1547
1491void cf_object_update (object *op, int flags) 1548void cf_object_update (object *op, int flags)
1492 1549
1493void cf_object_pickup (object *op, object *what) 1550void cf_object_pickup (object *op, object *what)
1494 1551
1495char *cf_object_get_key (object *op, char *keyname)
1496 ALIAS: key = 0
1497
1498void cf_object_set_key (object *op, char *keyname, char *value)
1499
1500object *cf_create_object_by_name (const char *name) 1552object *cf_create_object_by_name (const char *name)
1501 1553
1502void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) 1554void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0)
1503 1555
1504void player_lvl_adj (object *who, object *skill = 0) 1556void player_lvl_adj (object *who, object *skill = 0)
1505 1557
1558int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1506 1559
1507MODULE = cf PACKAGE = cf::object PREFIX = cf_ 1560MODULE = cf PACKAGE = cf::object PREFIX = cf_
1508 1561
1509void cf_fix_object (object *pl) 1562void cf_fix_object (object *pl)
1510 ALIAS: fix = 0 1563 ALIAS: fix = 0
1606 1659
1607void cf_player_set_party (object *op, partylist *party) 1660void cf_player_set_party (object *op, partylist *party)
1608 1661
1609void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) 1662void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0)
1610 1663
1664void kill_player (object *op)
1665
1611MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ 1666MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1612 1667
1613MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 1668MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1614 1669
1615player *cf_player_find (char *name) 1670player *cf_player_find (char *name)
1634 1689
1635player *next (player *pl) 1690player *next (player *pl)
1636 CODE: 1691 CODE:
1637 RETVAL = pl->next; 1692 RETVAL = pl->next;
1638 OUTPUT: RETVAL 1693 OUTPUT: RETVAL
1694
1695bool
1696cell_visible (player *pl, int dx, int dy)
1697 CODE:
1698 RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2
1699 && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2];
1700 OUTPUT:
1701 RETVAL
1702
1703void
1704send (player *pl, SV *packet)
1705 CODE:
1706{
1707 STRLEN len;
1708 char *buf = SvPVbyte (packet, len);
1709
1710 Write_String_To_Socket (&pl->socket, buf, len);
1711}
1712
1713int
1714listening (player *pl, int new_value = -1)
1715 CODE:
1716 RETVAL = pl->listening;
1717 if (new_value >= 0)
1718 pl->listening = new_value;
1719 OUTPUT:
1720 RETVAL
1639 1721
1640void get_savebed (player *pl) 1722void get_savebed (player *pl)
1641 ALIAS: 1723 ALIAS:
1642 savebed = 0 1724 savebed = 0
1643 PPCODE: 1725 PPCODE:
1718 1800
1719void clean_tmp_map (mapstruct *map) 1801void clean_tmp_map (mapstruct *map)
1720 1802
1721void play_sound_map (mapstruct *map, int x, int y, int sound_num) 1803void play_sound_map (mapstruct *map, int x, int y, int sound_num)
1722 1804
1805mapstruct *tile_map (mapstruct *map, unsigned int dir)
1806 CODE:
1807 RETVAL = dir < 4 ? map->tile_map [dir] : 0;
1808 OUTPUT:
1809 RETVAL
1810
1811char *tile_path (mapstruct *map, unsigned int dir)
1812 CODE:
1813 if (dir >= 4)
1814 XSRETURN_UNDEF;
1815 RETVAL = map->tile_path [dir];
1816 OUTPUT:
1817 RETVAL
1818
1723mapstruct *cf_map_get_map (char *name) 1819mapstruct *cf_map_get_map (char *name)
1724 PROTOTYPE: $ 1820 PROTOTYPE: $
1725 ALIAS: map = 0 1821 ALIAS: map = 0
1726 1822
1823mapstruct *has_been_loaded (char *name)
1824 PROTOTYPE: $
1825
1727mapstruct *cf_map_get_first () 1826mapstruct *cf_map_get_first ()
1728 PROTOTYPE: 1827 PROTOTYPE:
1729 ALIAS: first = 0 1828 ALIAS: first = 0
1730 1829
1731# whoever "designed" the plug-in api should have wasted 1830# whoever "designed" the plug-in api should have wasted
1732# his/her time with staying away form the project - would have 1831# his/her time with staying away from the project - would have
1733# saved others a lot of time, without doubt. 1832# saved others a lot of time, without doubt.
1734void set_path (mapstruct *where, char *path) 1833void set_path (mapstruct *where, char *path)
1735 CODE: 1834 CODE:
1736 strcpy (where->path, path); 1835 strcpy (where->path, path);
1836
1837int in_memory (mapstruct *map)
1838 CODE:
1839 RETVAL = map->in_memory;
1840 OUTPUT:
1841 RETVAL
1737 1842
1738bool unique (mapstruct *map) 1843bool unique (mapstruct *map)
1739 CODE: 1844 CODE:
1740 RETVAL = map->unique; 1845 RETVAL = map->unique;
1741 OUTPUT: 1846 OUTPUT:
1750object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) 1855object *cf_map_insert_object (mapstruct *where, object* op, int x, int y)
1751 1856
1752object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) 1857object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny)
1753 C_ARGS: str, map, nx, ny 1858 C_ARGS: str, map, nx, ny
1754 1859
1755#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1756
1757void 1860void
1861cf_map_normalise (mapstruct *map, int x, int y)
1862 PPCODE:
1863{
1864 mapstruct *nmap = 0;
1865 I16 nx = 0, ny = 0;
1866 int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1867
1868 EXTEND (SP, 4);
1869 PUSHs (sv_2mortal (newSViv (flags)));
1870
1871 if (GIMME_V == G_ARRAY)
1872 {
1873 PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap)));
1874 PUSHs (sv_2mortal (newSViv (nx)));
1875 PUSHs (sv_2mortal (newSViv (ny)));
1876 }
1877}
1878
1879void
1758at (mapstruct *obj, unsigned int x, unsigned int y) 1880at (mapstruct *map, unsigned int x, unsigned int y)
1759 PROTOTYPE: $$$ 1881 PROTOTYPE: $$$
1760 INIT:
1761 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY;
1762 PPCODE: 1882 PPCODE:
1763{ 1883{
1764 object *o; 1884 object *o;
1765 1885 mapstruct *nmap = 0;
1886 I16 nx, ny;
1887
1888 cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1889
1890 if (nmap)
1766 for (o = GET_MAP_OB (obj, x, y); o; o = o->above) 1891 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
1767 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1892 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1768} 1893}
1769 1894
1770SV * 1895SV *
1771bot_at (mapstruct *obj, unsigned int x, unsigned int y) 1896bot_at (mapstruct *obj, unsigned int x, unsigned int y)
1772 PROTOTYPE: $$$ 1897 PROTOTYPE: $$$

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines