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.47 by root, Sun Apr 2 15:57:54 2006 UTC vs.
Revision 1.56 by root, Tue Jul 11 14:24:16 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
498 clean_obj_cache ();
499
500 ENTER;
501 SAVETMPS;
502 PUSHMARK (SP);
503 XPUSHs (sv_2mortal (newSViv (0)));
504 PUTBACK;
505 call_pv ("Event::one_event", G_DISCARD | G_EVAL);
506 SPAGAIN;
507 FREETMPS;
508 LEAVE;
509 }
490 else 510 else
491 { 511 {
492 dSP; 512 dSP;
493 513
494 ENTER; 514 ENTER;
542 case EVENT_KICK: 562 case EVENT_KICK:
543 PUSH_OB; 563 PUSH_OB;
544 PUSH_PV; 564 PUSH_PV;
545 break; 565 break;
546 566
547 case EVENT_CLOCK: 567 case EVENT_EXTCMD:
548 clean_obj_cache (); 568 PUSH_PL;
569 {
570 char *buf = va_arg (args, char *);
571 int len = va_arg (args, int);
572 PUSHs (sv_2mortal (newSVpvn (buf, len)));
573 }
549 break; 574 break;
550 575
551 case EVENT_TELL: 576 case EVENT_TELL:
552 break; 577 break;
553 } 578 }
1088 const_iv (SK_SUMMONING) 1113 const_iv (SK_SUMMONING)
1089 const_iv (SK_PYROMANCY) 1114 const_iv (SK_PYROMANCY)
1090 const_iv (SK_EVOCATION) 1115 const_iv (SK_EVOCATION)
1091 const_iv (SK_SORCERY) 1116 const_iv (SK_SORCERY)
1092 const_iv (SK_TWO_HANDED_WEAPON) 1117 const_iv (SK_TWO_HANDED_WEAPON)
1118 const_iv (SK_SPARK_TOUCH)
1119 const_iv (SK_SHIVER)
1120 const_iv (SK_ACID_SPLASH)
1121 const_iv (SK_POISON_NAIL)
1093 1122
1094 const_iv (SOUND_NEW_PLAYER) 1123 const_iv (SOUND_NEW_PLAYER)
1095 const_iv (SOUND_FIRE_ARROW) 1124 const_iv (SOUND_FIRE_ARROW)
1096 const_iv (SOUND_LEARN_SPELL) 1125 const_iv (SOUND_LEARN_SPELL)
1097 const_iv (SOUND_FUMBLE_SPELL) 1126 const_iv (SOUND_FUMBLE_SPELL)
1113 const_iv (SOUND_CLOCK) 1142 const_iv (SOUND_CLOCK)
1114 const_iv (SOUND_TURN_HANDLE) 1143 const_iv (SOUND_TURN_HANDLE)
1115 const_iv (SOUND_FALL_HOLE) 1144 const_iv (SOUND_FALL_HOLE)
1116 const_iv (SOUND_DRINK_POISON) 1145 const_iv (SOUND_DRINK_POISON)
1117 const_iv (SOUND_CAST_SPELL_0) 1146 const_iv (SOUND_CAST_SPELL_0)
1147
1148 const_iv (MAP_FLUSH)
1149 const_iv (MAP_PLAYER_UNIQUE)
1150 const_iv (MAP_BLOCK)
1151 const_iv (MAP_STYLE)
1152 const_iv (MAP_OVERLAY)
1153
1154 const_iv (MAP_IN_MEMORY)
1155 const_iv (MAP_SWAPPED)
1156 const_iv (MAP_LOADING)
1157 const_iv (MAP_SAVING)
1118 }; 1158 };
1119 1159
1120 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1160 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1121 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1161 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1122 1162
1139 const_event (CLOSE) 1179 const_event (CLOSE)
1140 const_event (TIMER) 1180 const_event (TIMER)
1141 const_event (MOVE) 1181 const_event (MOVE)
1142 1182
1143 const_event (BORN) 1183 const_event (BORN)
1144 const_event (CLOCK) 1184 //const_event (CLOCK)
1145 const_event (CRASH) 1185 const_event (CRASH)
1146 const_event (PLAYER_DEATH) 1186 const_event (PLAYER_DEATH)
1147 const_event (PLAYER_LOAD) 1187 const_event (PLAYER_LOAD)
1148 const_event (PLAYER_SAVE) 1188 const_event (PLAYER_SAVE)
1149 const_event (GKILL) 1189 const_event (GKILL)
1159 const_event (REMOVE) 1199 const_event (REMOVE)
1160 const_event (SHOUT) 1200 const_event (SHOUT)
1161 const_event (TELL) 1201 const_event (TELL)
1162 const_event (MUZZLE) 1202 const_event (MUZZLE)
1163 const_event (KICK) 1203 const_event (KICK)
1204 const_event (EXTCMD)
1164 //const_event (FREE_OB) 1205 //const_event (FREE_OB)
1165 }; 1206 };
1166 1207
1167 AV *av = get_av ("cf::EVENT", 1); 1208 AV *av = get_av ("cf::EVENT", 1);
1168 1209
1302 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) 1343 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; )
1303 { 1344 {
1304 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); 1345 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0);
1305 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); 1346 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0);
1306 } 1347 }
1348
1349 //I_EVENT_API (PACKAGE);
1307} 1350}
1308 1351
1309void 1352void
1310LOG (int level, char *msg) 1353LOG (int level, char *msg)
1311 PROTOTYPE: $$ 1354 PROTOTYPE: $$
1312 C_ARGS: level, "%s", msg 1355 C_ARGS: level, "%s", msg
1356
1357char *path_combine (char *base, char *path)
1358 PROTOTYPE: $$
1359
1360char *path_combine_and_normalize (char *base, char *path)
1361 PROTOTYPE: $$
1313 1362
1314char * 1363char *
1315cf_get_maps_directory (char *path) 1364cf_get_maps_directory (char *path)
1316 PROTOTYPE: $ 1365 PROTOTYPE: $
1317 ALIAS: maps_directory = 0 1366 ALIAS: maps_directory = 0
1486 1535
1487void cf_object_update (object *op, int flags) 1536void cf_object_update (object *op, int flags)
1488 1537
1489void cf_object_pickup (object *op, object *what) 1538void cf_object_pickup (object *op, object *what)
1490 1539
1491char *cf_object_get_key (object *op, char *keyname)
1492 ALIAS: key = 0
1493
1494void cf_object_set_key (object *op, char *keyname, char *value)
1495
1496object *cf_create_object_by_name (const char *name) 1540object *cf_create_object_by_name (const char *name)
1497 1541
1498void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) 1542void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0)
1499 1543
1500void player_lvl_adj (object *who, object *skill = 0) 1544void player_lvl_adj (object *who, object *skill = 0)
1501 1545
1546int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1502 1547
1503MODULE = cf PACKAGE = cf::object PREFIX = cf_ 1548MODULE = cf PACKAGE = cf::object PREFIX = cf_
1504 1549
1505void cf_fix_object (object *pl) 1550void cf_fix_object (object *pl)
1506 ALIAS: fix = 0 1551 ALIAS: fix = 0
1602 1647
1603void cf_player_set_party (object *op, partylist *party) 1648void cf_player_set_party (object *op, partylist *party)
1604 1649
1605void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) 1650void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0)
1606 1651
1652void kill_player (object *op)
1653
1607MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ 1654MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1608 1655
1609MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 1656MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1610 1657
1611player *cf_player_find (char *name) 1658player *cf_player_find (char *name)
1630 1677
1631player *next (player *pl) 1678player *next (player *pl)
1632 CODE: 1679 CODE:
1633 RETVAL = pl->next; 1680 RETVAL = pl->next;
1634 OUTPUT: RETVAL 1681 OUTPUT: RETVAL
1682
1683bool
1684cell_visible (player *pl, int dx, int dy)
1685 CODE:
1686 RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2
1687 && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2];
1688 OUTPUT:
1689 RETVAL
1690
1691void
1692send (player *pl, SV *packet)
1693 CODE:
1694{
1695 STRLEN len;
1696 char *buf = SvPVbyte (packet, len);
1697
1698 Write_String_To_Socket (&pl->socket, buf, len);
1699}
1700
1701int
1702listening (player *pl, int new_value = -1)
1703 CODE:
1704 RETVAL = pl->listening;
1705 if (new_value >= 0)
1706 pl->listening = new_value;
1707 OUTPUT:
1708 RETVAL
1635 1709
1636void get_savebed (player *pl) 1710void get_savebed (player *pl)
1637 ALIAS: 1711 ALIAS:
1638 savebed = 0 1712 savebed = 0
1639 PPCODE: 1713 PPCODE:
1714 1788
1715void clean_tmp_map (mapstruct *map) 1789void clean_tmp_map (mapstruct *map)
1716 1790
1717void play_sound_map (mapstruct *map, int x, int y, int sound_num) 1791void play_sound_map (mapstruct *map, int x, int y, int sound_num)
1718 1792
1793mapstruct *tile_map (mapstruct *map, unsigned int dir)
1794 CODE:
1795 RETVAL = dir < 4 ? map->tile_map [dir] : 0;
1796 OUTPUT:
1797 RETVAL
1798
1799char *tile_path (mapstruct *map, unsigned int dir)
1800 CODE:
1801 if (dir >= 4)
1802 XSRETURN_UNDEF;
1803 RETVAL = map->tile_path [dir];
1804 OUTPUT:
1805 RETVAL
1806
1719mapstruct *cf_map_get_map (char *name) 1807mapstruct *cf_map_get_map (char *name)
1720 PROTOTYPE: $ 1808 PROTOTYPE: $
1721 ALIAS: map = 0 1809 ALIAS: map = 0
1722 1810
1811mapstruct *has_been_loaded (char *name)
1812 PROTOTYPE: $
1813
1723mapstruct *cf_map_get_first () 1814mapstruct *cf_map_get_first ()
1724 PROTOTYPE: 1815 PROTOTYPE:
1725 ALIAS: first = 0 1816 ALIAS: first = 0
1726 1817
1727# whoever "designed" the plug-in api should have wasted 1818# whoever "designed" the plug-in api should have wasted
1728# his/her time with staying away form the project - would have 1819# his/her time with staying away from the project - would have
1729# saved others a lot of time, without doubt. 1820# saved others a lot of time, without doubt.
1730void set_path (mapstruct *where, char *path) 1821void set_path (mapstruct *where, char *path)
1731 CODE: 1822 CODE:
1732 strcpy (where->path, path); 1823 strcpy (where->path, path);
1824
1825int in_memory (mapstruct *map)
1826 CODE:
1827 RETVAL = map->in_memory;
1828 OUTPUT:
1829 RETVAL
1733 1830
1734bool unique (mapstruct *map) 1831bool unique (mapstruct *map)
1735 CODE: 1832 CODE:
1736 RETVAL = map->unique; 1833 RETVAL = map->unique;
1737 OUTPUT: 1834 OUTPUT:
1746object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) 1843object *cf_map_insert_object (mapstruct *where, object* op, int x, int y)
1747 1844
1748object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) 1845object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny)
1749 C_ARGS: str, map, nx, ny 1846 C_ARGS: str, map, nx, ny
1750 1847
1751#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1752
1753void 1848void
1849cf_map_normalise (mapstruct *map, int x, int y)
1850 PPCODE:
1851{
1852 mapstruct *nmap = 0;
1853 I16 nx = 0, ny = 0;
1854 int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1855
1856 EXTEND (SP, 4);
1857 PUSHs (sv_2mortal (newSViv (flags)));
1858
1859 if (GIMME_V == G_ARRAY)
1860 {
1861 PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap)));
1862 PUSHs (sv_2mortal (newSViv (nx)));
1863 PUSHs (sv_2mortal (newSViv (ny)));
1864 }
1865}
1866
1867void
1754at (mapstruct *obj, unsigned int x, unsigned int y) 1868at (mapstruct *map, unsigned int x, unsigned int y)
1755 PROTOTYPE: $$$ 1869 PROTOTYPE: $$$
1756 INIT:
1757 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY;
1758 PPCODE: 1870 PPCODE:
1759{ 1871{
1760 object *o; 1872 object *o;
1761 1873 mapstruct *nmap = 0;
1874 I16 nx, ny;
1875
1876 cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1877
1878 if (nmap)
1762 for (o = GET_MAP_OB (obj, x, y); o; o = o->above) 1879 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
1763 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1880 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1764} 1881}
1765 1882
1766SV * 1883SV *
1767bot_at (mapstruct *obj, unsigned int x, unsigned int y) 1884bot_at (mapstruct *obj, unsigned int x, unsigned int y)
1768 PROTOTYPE: $$$ 1885 PROTOTYPE: $$$

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines