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.51 by root, Sun May 7 19:24:27 2006 UTC vs.
Revision 1.58 by elmex, Tue Jul 11 16:50: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
84#define PUSH_OB PUSHcfapi_va(POBJECT, object *) 85#define PUSH_OB PUSHcfapi_va(POBJECT, object *)
85#define PUSH_PL PUSHcfapi_va(PPLAYER, player *) 86#define PUSH_PL PUSHcfapi_va(PPLAYER, player *)
86#define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *) 87#define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *)
87#define PUSH_PV PUSHcfapi_va(STRING, const char *) 88#define PUSH_PV PUSHcfapi_va(STRING, const char *)
88#define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int)))) 89#define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int))))
90
91extern void pay_player(object *op, uint64 amount);
92extern uint64 pay_player_arch(object *op, const char *arch, uint64 amount);
89 93
90////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 94//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
91 95
92// garbage collect some perl objects, if possible 96// garbage collect some perl objects, if possible
93// all objects no longer referenced and empty are 97// all objects no longer referenced and empty are
427 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); 431 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener);
428 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); 432 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener);
429 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); 433 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener);
430 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); 434 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener);
431 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); 435 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener);
436 registerGlobalEvent (NULL, EVENT_EXTCMD, PLUGIN_NAME, globalEventListener);
432 437
433 char *argv[] = { 438 char *argv[] = {
434 "", 439 "",
435 "-e" 440 "-e"
436 "BEGIN {" 441 "BEGIN {"
442 }; 447 };
443 448
444 perl = perl_alloc (); 449 perl = perl_alloc ();
445 perl_construct (perl); 450 perl_construct (perl);
446 451
452 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
453
447 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 454 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
448 { 455 {
449 printf ("unable to initialize perl-interpreter, continuing without.\n"); 456 printf ("unable to initialize perl-interpreter, continuing without.\n");
450 457
451 perl_destruct (perl); 458 perl_destruct (perl);
485 if (sv) 492 if (sv)
486 clearSVptr (sv); 493 clearSVptr (sv);
487 494
488 rv = 0; 495 rv = 0;
489 } 496 }
497 else if (event_code == EVENT_CLOCK)
498 {
499 dSP;
500 int i, count;
501
502 clean_obj_cache ();
503
504 ENTER;
505 SAVETMPS;
506
507 // service up to 8 events per tick better would be
508 // to check for elapsed time and stop processing after
509 // 0.25 * server_tick or so
510 for (i = 9; --i; )
511 {
512 PUSHMARK (SP);
513 XPUSHs (sv_2mortal (newSViv (0)));
514 PUTBACK;
515 count = call_pv ("Event::one_event", G_SCALAR | G_EVAL);
516 SPAGAIN;
517
518 if (!count || !POPi)
519 break;
520 }
521
522 FREETMPS;
523 LEAVE;
524 }
490 else 525 else
491 { 526 {
492 dSP; 527 dSP;
493 528
494 ENTER; 529 ENTER;
542 case EVENT_KICK: 577 case EVENT_KICK:
543 PUSH_OB; 578 PUSH_OB;
544 PUSH_PV; 579 PUSH_PV;
545 break; 580 break;
546 581
547 case EVENT_CLOCK: 582 case EVENT_EXTCMD:
548 clean_obj_cache (); 583 PUSH_PL;
584 {
585 char *buf = va_arg (args, char *);
586 int len = va_arg (args, int);
587 PUSHs (sv_2mortal (newSVpvn (buf, len)));
588 }
549 break; 589 break;
550 590
551 case EVENT_TELL: 591 case EVENT_TELL:
552 break; 592 break;
553 } 593 }
1117 const_iv (SOUND_CLOCK) 1157 const_iv (SOUND_CLOCK)
1118 const_iv (SOUND_TURN_HANDLE) 1158 const_iv (SOUND_TURN_HANDLE)
1119 const_iv (SOUND_FALL_HOLE) 1159 const_iv (SOUND_FALL_HOLE)
1120 const_iv (SOUND_DRINK_POISON) 1160 const_iv (SOUND_DRINK_POISON)
1121 const_iv (SOUND_CAST_SPELL_0) 1161 const_iv (SOUND_CAST_SPELL_0)
1162
1163 const_iv (MAP_FLUSH)
1164 const_iv (MAP_PLAYER_UNIQUE)
1165 const_iv (MAP_BLOCK)
1166 const_iv (MAP_STYLE)
1167 const_iv (MAP_OVERLAY)
1168
1169 const_iv (MAP_IN_MEMORY)
1170 const_iv (MAP_SWAPPED)
1171 const_iv (MAP_LOADING)
1172 const_iv (MAP_SAVING)
1122 }; 1173 };
1123 1174
1124 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1175 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1125 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1176 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1126 1177
1143 const_event (CLOSE) 1194 const_event (CLOSE)
1144 const_event (TIMER) 1195 const_event (TIMER)
1145 const_event (MOVE) 1196 const_event (MOVE)
1146 1197
1147 const_event (BORN) 1198 const_event (BORN)
1148 const_event (CLOCK) 1199 //const_event (CLOCK)
1149 const_event (CRASH) 1200 const_event (CRASH)
1150 const_event (PLAYER_DEATH) 1201 const_event (PLAYER_DEATH)
1151 const_event (PLAYER_LOAD) 1202 const_event (PLAYER_LOAD)
1152 const_event (PLAYER_SAVE) 1203 const_event (PLAYER_SAVE)
1153 const_event (GKILL) 1204 const_event (GKILL)
1163 const_event (REMOVE) 1214 const_event (REMOVE)
1164 const_event (SHOUT) 1215 const_event (SHOUT)
1165 const_event (TELL) 1216 const_event (TELL)
1166 const_event (MUZZLE) 1217 const_event (MUZZLE)
1167 const_event (KICK) 1218 const_event (KICK)
1219 const_event (EXTCMD)
1168 //const_event (FREE_OB) 1220 //const_event (FREE_OB)
1169 }; 1221 };
1170 1222
1171 AV *av = get_av ("cf::EVENT", 1); 1223 AV *av = get_av ("cf::EVENT", 1);
1172 1224
1306 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) 1358 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; )
1307 { 1359 {
1308 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); 1360 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); 1361 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0);
1310 } 1362 }
1363
1364 //I_EVENT_API (PACKAGE);
1311} 1365}
1312 1366
1313void 1367void
1314LOG (int level, char *msg) 1368LOG (int level, char *msg)
1315 PROTOTYPE: $$ 1369 PROTOTYPE: $$
1316 C_ARGS: level, "%s", msg 1370 C_ARGS: level, "%s", msg
1371
1372char *path_combine (char *base, char *path)
1373 PROTOTYPE: $$
1374
1375char *path_combine_and_normalize (char *base, char *path)
1376 PROTOTYPE: $$
1317 1377
1318char * 1378char *
1319cf_get_maps_directory (char *path) 1379cf_get_maps_directory (char *path)
1320 PROTOTYPE: $ 1380 PROTOTYPE: $
1321 ALIAS: maps_directory = 0 1381 ALIAS: maps_directory = 0
1490 1550
1491void cf_object_update (object *op, int flags) 1551void cf_object_update (object *op, int flags)
1492 1552
1493void cf_object_pickup (object *op, object *what) 1553void cf_object_pickup (object *op, object *what)
1494 1554
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) 1555object *cf_create_object_by_name (const char *name)
1501 1556
1502void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) 1557void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0)
1558
1559void pay_player (object *op, double amount)
1560
1561double pay_player_arch (object *op, const char *arch, double amount)
1503 1562
1504void player_lvl_adj (object *who, object *skill = 0) 1563void player_lvl_adj (object *who, object *skill = 0)
1505 1564
1506int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 1565int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1507 1566
1637 1696
1638player *next (player *pl) 1697player *next (player *pl)
1639 CODE: 1698 CODE:
1640 RETVAL = pl->next; 1699 RETVAL = pl->next;
1641 OUTPUT: RETVAL 1700 OUTPUT: RETVAL
1701
1702bool
1703cell_visible (player *pl, int dx, int dy)
1704 CODE:
1705 RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2
1706 && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2];
1707 OUTPUT:
1708 RETVAL
1709
1710void
1711send (player *pl, SV *packet)
1712 CODE:
1713{
1714 STRLEN len;
1715 char *buf = SvPVbyte (packet, len);
1716
1717 Write_String_To_Socket (&pl->socket, buf, len);
1718}
1642 1719
1643int 1720int
1644listening (player *pl, int new_value = -1) 1721listening (player *pl, int new_value = -1)
1645 CODE: 1722 CODE:
1646 RETVAL = pl->listening; 1723 RETVAL = pl->listening;
1730 1807
1731void clean_tmp_map (mapstruct *map) 1808void clean_tmp_map (mapstruct *map)
1732 1809
1733void play_sound_map (mapstruct *map, int x, int y, int sound_num) 1810void play_sound_map (mapstruct *map, int x, int y, int sound_num)
1734 1811
1812mapstruct *tile_map (mapstruct *map, unsigned int dir)
1813 CODE:
1814 RETVAL = dir < 4 ? map->tile_map [dir] : 0;
1815 OUTPUT:
1816 RETVAL
1817
1818char *tile_path (mapstruct *map, unsigned int dir)
1819 CODE:
1820 if (dir >= 4)
1821 XSRETURN_UNDEF;
1822 RETVAL = map->tile_path [dir];
1823 OUTPUT:
1824 RETVAL
1825
1735mapstruct *cf_map_get_map (char *name) 1826mapstruct *cf_map_get_map (char *name)
1736 PROTOTYPE: $ 1827 PROTOTYPE: $
1737 ALIAS: map = 0 1828 ALIAS: map = 0
1738 1829
1830mapstruct *has_been_loaded (char *name)
1831 PROTOTYPE: $
1832
1739mapstruct *cf_map_get_first () 1833mapstruct *cf_map_get_first ()
1740 PROTOTYPE: 1834 PROTOTYPE:
1741 ALIAS: first = 0 1835 ALIAS: first = 0
1742 1836
1743# whoever "designed" the plug-in api should have wasted 1837# whoever "designed" the plug-in api should have wasted
1744# his/her time with staying away form the project - would have 1838# his/her time with staying away from the project - would have
1745# saved others a lot of time, without doubt. 1839# saved others a lot of time, without doubt.
1746void set_path (mapstruct *where, char *path) 1840void set_path (mapstruct *where, char *path)
1747 CODE: 1841 CODE:
1748 strcpy (where->path, path); 1842 strcpy (where->path, path);
1843
1844int in_memory (mapstruct *map)
1845 CODE:
1846 RETVAL = map->in_memory;
1847 OUTPUT:
1848 RETVAL
1749 1849
1750bool unique (mapstruct *map) 1850bool unique (mapstruct *map)
1751 CODE: 1851 CODE:
1752 RETVAL = map->unique; 1852 RETVAL = map->unique;
1753 OUTPUT: 1853 OUTPUT:
1762object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) 1862object *cf_map_insert_object (mapstruct *where, object* op, int x, int y)
1763 1863
1764object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) 1864object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny)
1765 C_ARGS: str, map, nx, ny 1865 C_ARGS: str, map, nx, ny
1766 1866
1767#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1768
1769void 1867void
1868cf_map_normalise (mapstruct *map, int x, int y)
1869 PPCODE:
1870{
1871 mapstruct *nmap = 0;
1872 I16 nx = 0, ny = 0;
1873 int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1874
1875 EXTEND (SP, 4);
1876 PUSHs (sv_2mortal (newSViv (flags)));
1877
1878 if (GIMME_V == G_ARRAY)
1879 {
1880 PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap)));
1881 PUSHs (sv_2mortal (newSViv (nx)));
1882 PUSHs (sv_2mortal (newSViv (ny)));
1883 }
1884}
1885
1886void
1770at (mapstruct *obj, unsigned int x, unsigned int y) 1887at (mapstruct *map, unsigned int x, unsigned int y)
1771 PROTOTYPE: $$$ 1888 PROTOTYPE: $$$
1772 INIT:
1773 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY;
1774 PPCODE: 1889 PPCODE:
1775{ 1890{
1776 object *o; 1891 object *o;
1777 1892 mapstruct *nmap = 0;
1893 I16 nx, ny;
1894
1895 cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1896
1897 if (nmap)
1778 for (o = GET_MAP_OB (obj, x, y); o; o = o->above) 1898 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
1779 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1899 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1780} 1900}
1781 1901
1782SV * 1902SV *
1783bot_at (mapstruct *obj, unsigned int x, unsigned int y) 1903bot_at (mapstruct *obj, unsigned int x, unsigned int y)
1784 PROTOTYPE: $$$ 1904 PROTOTYPE: $$$

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines