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.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 }
1088 const_iv (SK_SUMMONING) 1128 const_iv (SK_SUMMONING)
1089 const_iv (SK_PYROMANCY) 1129 const_iv (SK_PYROMANCY)
1090 const_iv (SK_EVOCATION) 1130 const_iv (SK_EVOCATION)
1091 const_iv (SK_SORCERY) 1131 const_iv (SK_SORCERY)
1092 const_iv (SK_TWO_HANDED_WEAPON) 1132 const_iv (SK_TWO_HANDED_WEAPON)
1133 const_iv (SK_SPARK_TOUCH)
1134 const_iv (SK_SHIVER)
1135 const_iv (SK_ACID_SPLASH)
1136 const_iv (SK_POISON_NAIL)
1093 1137
1094 const_iv (SOUND_NEW_PLAYER) 1138 const_iv (SOUND_NEW_PLAYER)
1095 const_iv (SOUND_FIRE_ARROW) 1139 const_iv (SOUND_FIRE_ARROW)
1096 const_iv (SOUND_LEARN_SPELL) 1140 const_iv (SOUND_LEARN_SPELL)
1097 const_iv (SOUND_FUMBLE_SPELL) 1141 const_iv (SOUND_FUMBLE_SPELL)
1113 const_iv (SOUND_CLOCK) 1157 const_iv (SOUND_CLOCK)
1114 const_iv (SOUND_TURN_HANDLE) 1158 const_iv (SOUND_TURN_HANDLE)
1115 const_iv (SOUND_FALL_HOLE) 1159 const_iv (SOUND_FALL_HOLE)
1116 const_iv (SOUND_DRINK_POISON) 1160 const_iv (SOUND_DRINK_POISON)
1117 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)
1118 }; 1173 };
1119 1174
1120 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; )
1121 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1176 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1122 1177
1139 const_event (CLOSE) 1194 const_event (CLOSE)
1140 const_event (TIMER) 1195 const_event (TIMER)
1141 const_event (MOVE) 1196 const_event (MOVE)
1142 1197
1143 const_event (BORN) 1198 const_event (BORN)
1144 const_event (CLOCK) 1199 //const_event (CLOCK)
1145 const_event (CRASH) 1200 const_event (CRASH)
1146 const_event (PLAYER_DEATH) 1201 const_event (PLAYER_DEATH)
1147 const_event (PLAYER_LOAD) 1202 const_event (PLAYER_LOAD)
1148 const_event (PLAYER_SAVE) 1203 const_event (PLAYER_SAVE)
1149 const_event (GKILL) 1204 const_event (GKILL)
1159 const_event (REMOVE) 1214 const_event (REMOVE)
1160 const_event (SHOUT) 1215 const_event (SHOUT)
1161 const_event (TELL) 1216 const_event (TELL)
1162 const_event (MUZZLE) 1217 const_event (MUZZLE)
1163 const_event (KICK) 1218 const_event (KICK)
1219 const_event (EXTCMD)
1164 //const_event (FREE_OB) 1220 //const_event (FREE_OB)
1165 }; 1221 };
1166 1222
1167 AV *av = get_av ("cf::EVENT", 1); 1223 AV *av = get_av ("cf::EVENT", 1);
1168 1224
1302 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; )
1303 { 1359 {
1304 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);
1305 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);
1306 } 1362 }
1363
1364 //I_EVENT_API (PACKAGE);
1307} 1365}
1308 1366
1309void 1367void
1310LOG (int level, char *msg) 1368LOG (int level, char *msg)
1311 PROTOTYPE: $$ 1369 PROTOTYPE: $$
1312 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: $$
1313 1377
1314char * 1378char *
1315cf_get_maps_directory (char *path) 1379cf_get_maps_directory (char *path)
1316 PROTOTYPE: $ 1380 PROTOTYPE: $
1317 ALIAS: maps_directory = 0 1381 ALIAS: maps_directory = 0
1486 1550
1487void cf_object_update (object *op, int flags) 1551void cf_object_update (object *op, int flags)
1488 1552
1489void cf_object_pickup (object *op, object *what) 1553void cf_object_pickup (object *op, object *what)
1490 1554
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) 1555object *cf_create_object_by_name (const char *name)
1497 1556
1498void 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)
1499 1558
1559void pay_player (object *op, double amount)
1560
1561double pay_player_arch (object *op, const char *arch, double amount)
1562
1500void player_lvl_adj (object *who, object *skill = 0) 1563void player_lvl_adj (object *who, object *skill = 0)
1501 1564
1565int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1502 1566
1503MODULE = cf PACKAGE = cf::object PREFIX = cf_ 1567MODULE = cf PACKAGE = cf::object PREFIX = cf_
1504 1568
1505void cf_fix_object (object *pl) 1569void cf_fix_object (object *pl)
1506 ALIAS: fix = 0 1570 ALIAS: fix = 0
1602 1666
1603void cf_player_set_party (object *op, partylist *party) 1667void cf_player_set_party (object *op, partylist *party)
1604 1668
1605void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) 1669void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0)
1606 1670
1671void kill_player (object *op)
1672
1607MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ 1673MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1608 1674
1609MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 1675MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1610 1676
1611player *cf_player_find (char *name) 1677player *cf_player_find (char *name)
1630 1696
1631player *next (player *pl) 1697player *next (player *pl)
1632 CODE: 1698 CODE:
1633 RETVAL = pl->next; 1699 RETVAL = pl->next;
1634 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}
1719
1720int
1721listening (player *pl, int new_value = -1)
1722 CODE:
1723 RETVAL = pl->listening;
1724 if (new_value >= 0)
1725 pl->listening = new_value;
1726 OUTPUT:
1727 RETVAL
1635 1728
1636void get_savebed (player *pl) 1729void get_savebed (player *pl)
1637 ALIAS: 1730 ALIAS:
1638 savebed = 0 1731 savebed = 0
1639 PPCODE: 1732 PPCODE:
1714 1807
1715void clean_tmp_map (mapstruct *map) 1808void clean_tmp_map (mapstruct *map)
1716 1809
1717void 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)
1718 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
1719mapstruct *cf_map_get_map (char *name) 1826mapstruct *cf_map_get_map (char *name)
1720 PROTOTYPE: $ 1827 PROTOTYPE: $
1721 ALIAS: map = 0 1828 ALIAS: map = 0
1722 1829
1830mapstruct *has_been_loaded (char *name)
1831 PROTOTYPE: $
1832
1723mapstruct *cf_map_get_first () 1833mapstruct *cf_map_get_first ()
1724 PROTOTYPE: 1834 PROTOTYPE:
1725 ALIAS: first = 0 1835 ALIAS: first = 0
1726 1836
1727# whoever "designed" the plug-in api should have wasted 1837# whoever "designed" the plug-in api should have wasted
1728# his/her time with staying away form the project - would have 1838# his/her time with staying away from the project - would have
1729# saved others a lot of time, without doubt. 1839# saved others a lot of time, without doubt.
1730void set_path (mapstruct *where, char *path) 1840void set_path (mapstruct *where, char *path)
1731 CODE: 1841 CODE:
1732 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
1733 1849
1734bool unique (mapstruct *map) 1850bool unique (mapstruct *map)
1735 CODE: 1851 CODE:
1736 RETVAL = map->unique; 1852 RETVAL = map->unique;
1737 OUTPUT: 1853 OUTPUT:
1746object *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)
1747 1863
1748object* 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)
1749 C_ARGS: str, map, nx, ny 1865 C_ARGS: str, map, nx, ny
1750 1866
1751#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1752
1753void 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
1754at (mapstruct *obj, unsigned int x, unsigned int y) 1887at (mapstruct *map, unsigned int x, unsigned int y)
1755 PROTOTYPE: $$$ 1888 PROTOTYPE: $$$
1756 INIT:
1757 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY;
1758 PPCODE: 1889 PPCODE:
1759{ 1890{
1760 object *o; 1891 object *o;
1761 1892 mapstruct *nmap = 0;
1893 I16 nx, ny;
1894
1895 cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1896
1897 if (nmap)
1762 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)
1763 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1899 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1764} 1900}
1765 1901
1766SV * 1902SV *
1767bot_at (mapstruct *obj, unsigned int x, unsigned int y) 1903bot_at (mapstruct *obj, unsigned int x, unsigned int y)
1768 PROTOTYPE: $$$ 1904 PROTOTYPE: $$$

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines