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.63 by root, Thu Jul 20 07:22:41 2006 UTC vs.
Revision 1.66 by elmex, Sun Aug 13 17:16:02 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 <sproto.h>
51
50//#include "EventAPI.h" 52//#include "EventAPI.h"
51#include "perlxsi.c" 53#include "perlxsi.c"
52 54
53extern sint64 *levels; // the experience table 55extern sint64 *levels; // the experience table
54 56
92#define PUSH_PL PUSHcfapi_va(PPLAYER, player *) 94#define PUSH_PL PUSHcfapi_va(PPLAYER, player *)
93#define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *) 95#define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *)
94#define PUSH_PV PUSHcfapi_va(STRING, const char *) 96#define PUSH_PV PUSHcfapi_va(STRING, const char *)
95#define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int)))) 97#define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int))))
96 98
97extern void pay_player(object *op, uint64 amount);
98extern uint64 pay_player_arch(object *op, const char *arch, uint64 amount);
99
100////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 99//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
101 100
102// garbage collect some perl objects, if possible 101// garbage collect some perl objects, if possible
103// all objects no longer referenced and empty are 102// all objects no longer referenced and empty are
104// eligible for destruction. 103// eligible for destruction.
304 return sv; 303 return sv;
305} 304}
306 305
307///////////////////////////////////////////////////////////////////////////// 306/////////////////////////////////////////////////////////////////////////////
308 307
309int
310initPlugin (const char *iversion, f_plug_api gethooksptr) 308extern "C" int initPlugin (const char *iversion, f_plug_api gethooksptr)
311{ 309{
312 gethook = gethooksptr; 310 gethook = gethooksptr;
313 printf (PLUGIN_VERSION " init\n"); 311 printf (PLUGIN_VERSION " init\n");
314 312
315 return 0; 313 return 0;
348 LEAVE; 346 LEAVE;
349 347
350 return returnvalue; 348 return returnvalue;
351} 349}
352 350
353void *
354getPluginProperty (int *type, ...) 351extern "C" void *getPluginProperty (int *type, ...)
355{ 352{
356 va_list args; 353 va_list args;
357 char *propname; 354 char *propname;
358 int i; 355 int i;
359 va_start (args, type); 356 va_start (args, type);
382 } 379 }
383 } 380 }
384 else if (!strcmp (propname, "Identification")) 381 else if (!strcmp (propname, "Identification"))
385 { 382 {
386 va_end (args); 383 va_end (args);
387 return PLUGIN_NAME; 384 return (void*) PLUGIN_NAME;
388 } 385 }
389 else if (!strcmp (propname, "FullName")) 386 else if (!strcmp (propname, "FullName"))
390 { 387 {
391 va_end (args); 388 va_end (args);
392 return PLUGIN_VERSION; 389 return (void*) PLUGIN_VERSION;
393 } 390 }
394 else 391 else
395 va_end (args); 392 va_end (args);
396 393
397 return NULL; 394 return NULL;
398} 395}
399 396
400void *globalEventListener (int *type, ...); 397void *globalEventListener (int *type, ...);
401 398
402int 399extern "C" int postInitPlugin ()
403postInitPlugin ()
404{ 400{
405 int hooktype = 1; 401 int hooktype = 1;
406 int rtype = 0; 402 int rtype = 0;
407 403
408 printf (PLUGIN_VERSION " post init\n"); 404 printf (PLUGIN_VERSION " post init\n");
409 405
410 registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); 406 registerGlobalEvent = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_register_global_event");
411 unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); 407 unregisterGlobalEvent = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_unregister_global_event");
412 systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); 408 systemDirectory = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_directory");
413 object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property"); 409 object_set_property = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_set_property");
414 map_get_map = gethook (&rtype, hooktype, "cfapi_map_get_map"); 410 map_get_map = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_map_get_map");
415 object_insert = gethook (&rtype, hooktype, "cfapi_object_insert"); 411 object_insert = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_insert");
416 412
417 cf_init_plugin (gethook); 413 cf_init_plugin (gethook);
418 414
419 /* Pick the global events you want to monitor from this plugin */ 415 /* Pick the global events you want to monitor from this plugin */
420 registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); 416 registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener);
421 registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener); 417 registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener);
422 //registerGlobalEvent (NULL, EVENT_CRASH, PLUGIN_NAME, globalEventListener); 418 //registerGlobalEvent (NULL, EVENT_CRASH, PLUGIN_NAME, globalEventListener);
423 registerGlobalEvent (NULL, EVENT_FIND_UNARMED_SKILL, PLUGIN_NAME, globalEventListener); 419 registerGlobalEvent (NULL, EVENT_FIND_UNARMED_SKILL, PLUGIN_NAME, globalEventListener);
424 registerGlobalEvent (NULL, EVENT_PLAYER_USE_SKILL, PLUGIN_NAME, globalEventListener); 420 registerGlobalEvent (NULL, EVENT_PLAYER_USE_SKILL, PLUGIN_NAME, globalEventListener);
421 registerGlobalEvent (NULL, EVENT_CAST_SPELL, PLUGIN_NAME, globalEventListener);
425 registerGlobalEvent (NULL, EVENT_MONSTER_USE_SKILL, PLUGIN_NAME, globalEventListener); 422 registerGlobalEvent (NULL, EVENT_MONSTER_USE_SKILL, PLUGIN_NAME, globalEventListener);
426 registerGlobalEvent (NULL, EVENT_PLAYER_DEATH, PLUGIN_NAME, globalEventListener); 423 registerGlobalEvent (NULL, EVENT_PLAYER_DEATH, PLUGIN_NAME, globalEventListener);
427 registerGlobalEvent (NULL, EVENT_GKILL, PLUGIN_NAME, globalEventListener); 424 registerGlobalEvent (NULL, EVENT_GKILL, PLUGIN_NAME, globalEventListener);
428 registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener); 425 registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener);
429 registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener); 426 registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener);
482 va_list args; 479 va_list args;
483 static int rv; 480 static int rv;
484 int event_code; 481 int event_code;
485 482
486 if (!perl) 483 if (!perl)
487 return; 484 return NULL;
488 485
489 va_start (args, type); 486 va_start (args, type);
490 event_code = va_arg (args, int); 487 event_code = va_arg (args, int);
491 488
492 if (event_code == EVENT_FREE_OB) 489 if (event_code == EVENT_FREE_OB)
592 PUSH_OB; 589 PUSH_OB;
593 break; 590 break;
594 591
595 case EVENT_PLAYER_USE_SKILL: 592 case EVENT_PLAYER_USE_SKILL:
596 case EVENT_MONSTER_USE_SKILL: 593 case EVENT_MONSTER_USE_SKILL:
594 case EVENT_CAST_SPELL:
597 PUSH_OB; 595 PUSH_OB;
598 PUSH_OB; 596 PUSH_OB;
599 PUSH_OB; 597 PUSH_OB;
600 PUSH_IV; 598 PUSH_IV;
601 PUSH_PV; 599 PUSH_PV;
631 } 629 }
632 630
633 return &rv; 631 return &rv;
634} 632}
635 633
636void *
637eventListener (int *type, ...) 634extern "C" void * eventListener (int *type, ...)
638{ 635{
639 static int rv; 636 static int rv;
640 va_list args; 637 va_list args;
641 int event_code; 638 int event_code;
642 object *who, *activator, *third, *event; 639 object *who, *activator, *third, *event;
643 char *message, *extension, *options; 640 char *message, *extension, *options;
644 641
645 if (!perl) 642 if (!perl)
646 return; 643 return NULL;
647 644
648 va_start (args, type); 645 va_start (args, type);
649 who = va_arg (args, object *); 646 who = va_arg (args, object *);
650 event_code = va_arg (args, int); 647 event_code = va_arg (args, int);
651 activator = va_arg (args, object *); 648 activator = va_arg (args, object *);
724 } 721 }
725 722
726 return &rv; 723 return &rv;
727} 724}
728 725
729int 726extern "C" int closePlugin ()
730closePlugin ()
731{ 727{
732 printf (PLUGIN_VERSION " closing\n"); 728 printf (PLUGIN_VERSION " closing\n");
733 729
734 if (perl) 730 if (perl)
735 { 731 {
1268 const_event (TELL) 1264 const_event (TELL)
1269 const_event (MUZZLE) 1265 const_event (MUZZLE)
1270 const_event (KICK) 1266 const_event (KICK)
1271 const_event (PLAYER_USE_SKILL) 1267 const_event (PLAYER_USE_SKILL)
1272 const_event (MONSTER_USE_SKILL) 1268 const_event (MONSTER_USE_SKILL)
1269 const_event (CAST_SPELL)
1273 const_event (FIND_UNARMED_SKILL) 1270 const_event (FIND_UNARMED_SKILL)
1274 const_event (EXTCMD) 1271 const_event (EXTCMD)
1275 //const_event (FREE_OB) 1272 //const_event (FREE_OB)
1276 }; 1273 };
1277 1274
1420} 1417}
1421 1418
1422void 1419void
1423LOG (int level, char *msg) 1420LOG (int level, char *msg)
1424 PROTOTYPE: $$ 1421 PROTOTYPE: $$
1425 C_ARGS: level, "%s", msg 1422 C_ARGS: (LogLevel)level, "%s", msg
1426 1423
1427char *path_combine (char *base, char *path) 1424char *path_combine (char *base, char *path)
1428 PROTOTYPE: $$ 1425 PROTOTYPE: $$
1429 1426
1430char *path_combine_and_normalize (char *base, char *path) 1427char *path_combine_and_normalize (char *base, char *path)
1518 { 1515 {
1519 case CFAPI_INT: 1516 case CFAPI_INT:
1520 cf_object_set_int_property (obj, idx, SvIV (newval)); 1517 cf_object_set_int_property (obj, idx, SvIV (newval));
1521 break; 1518 break;
1522 case CFAPI_LONG: 1519 case CFAPI_LONG:
1523 cf_object_set_long_property (obj, idx, SvVAL64 (newval)); 1520 cf_object_set_long_property (obj, idx, (long) SvVAL64 (newval));
1524 break; 1521 break;
1525 case CFAPI_DOUBLE: 1522 case CFAPI_DOUBLE:
1526 { 1523 {
1527 int unused_type; 1524 int unused_type;
1528 object_set_property (&unused_type, obj, idx, (double)SvNV (newval)); 1525 object_set_property (&unused_type, obj, idx, (double)SvNV (newval));
1606 1603
1607object *cf_object_clone (object *op, int clonetype = 0) 1604object *cf_object_clone (object *op, int clonetype = 0)
1608 1605
1609int cf_object_pay_item (object *op, object *buyer) 1606int cf_object_pay_item (object *op, object *buyer)
1610 1607
1611int cf_object_pay_amount (object *op, val64 amount) 1608int cf_object_pay_amount (object *op, uint64 amount)
1609
1610void pay_player (object *op, uint64 amount)
1611
1612val64 pay_player_arch (object *op, const char *arch, uint64 amount)
1612 1613
1613int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0) 1614int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0)
1614 1615
1615int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0) 1616int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0)
1616 1617
1653 1654
1654void cf_object_pickup (object *op, object *what) 1655void cf_object_pickup (object *op, object *what)
1655 1656
1656object *cf_create_object_by_name (const char *name) 1657object *cf_create_object_by_name (const char *name)
1657 1658
1658void change_exp (object *op, val64 exp, const char *skill_name = 0, int flag = 0) 1659void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0)
1659
1660void pay_player (object *op, val64 amount)
1661
1662val64 pay_player_arch (object *op, const char *arch, val64 amount)
1663 1660
1664void player_lvl_adj (object *who, object *skill = 0) 1661void player_lvl_adj (object *who, object *skill = 0)
1665 1662
1666int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 1663int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1667 1664
1781 1778
1782partylist *cf_player_get_party (object *op) 1779partylist *cf_player_get_party (object *op)
1783 ALIAS: party = 0 1780 ALIAS: party = 0
1784 1781
1785void cf_player_set_party (object *op, partylist *party) 1782void cf_player_set_party (object *op, partylist *party)
1786
1787void change_skill (object *op, val64 exp, char *skill_name = 0, int flag = 0)
1788 1783
1789void kill_player (object *op) 1784void kill_player (object *op)
1790 1785
1791MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ 1786MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1792 1787
1914mapstruct *new (int width, int height) 1909mapstruct *new (int width, int height)
1915 PROTOTYPE: 1910 PROTOTYPE:
1916 CODE: 1911 CODE:
1917{ 1912{
1918 int unused_type; 1913 int unused_type;
1919 RETVAL = map_get_map (&unused_type, 0, width, height); 1914 RETVAL = (mapstruct*) map_get_map (&unused_type, 0, width, height);
1920} 1915}
1921 OUTPUT: 1916 OUTPUT:
1922 RETVAL 1917 RETVAL
1923 1918
1924void delete_map (mapstruct *map) 1919void delete_map (mapstruct *map)
2134 ALIAS: more = 0 2129 ALIAS: more = 0
2135 2130
2136const char *cf_archetype_get_name (archetype *arch) 2131const char *cf_archetype_get_name (archetype *arch)
2137 ALIAS: name = 0 2132 ALIAS: name = 0
2138 2133
2134object *cf_archetype_get_clone (archetype *arch)
2135 ALIAS: clone = 0
2136
2139MODULE = cf PACKAGE = cf::party PREFIX = cf_party_ 2137MODULE = cf PACKAGE = cf::party PREFIX = cf_party_
2140 2138
2141partylist *cf_party_get_first () 2139partylist *cf_party_get_first ()
2142 PROTOTYPE: 2140 PROTOTYPE:
2143 ALIAS: first = 0 2141 ALIAS: first = 0
2202 maxgrace = 15 2200 maxgrace = 15
2203 food = 16 2201 food = 16
2204 dam = 17 2202 dam = 17
2205 luck = 18 2203 luck = 18
2206 CODE: 2204 CODE:
2207# define LIVING_ACC(acc,idx) case idx: RETVAL = liv->acc; if (items > 1) liv->acc = new_val; break 2205# define LIVING_ACC(acc,idx) case idx: RETVAL = liv->acc; if (items > 1) liv->acc = (sint64)new_val; break
2208 switch (ix) 2206 switch (ix)
2209 { 2207 {
2210 LIVING_ACC (exp , 0); 2208 LIVING_ACC (exp , 0);
2211 LIVING_ACC (Str , 1); 2209 LIVING_ACC (Str , 1);
2212 LIVING_ACC (Dex , 2); 2210 LIVING_ACC (Dex , 2);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines