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.65 by elmex, Sat Aug 12 11:51:38 2006 UTC vs.
Revision 1.67 by elmex, Mon Aug 14 04:22:05 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);
483 va_list args; 479 va_list args;
484 static int rv; 480 static int rv;
485 int event_code; 481 int event_code;
486 482
487 if (!perl) 483 if (!perl)
488 return; 484 return NULL;
489 485
490 va_start (args, type); 486 va_start (args, type);
491 event_code = va_arg (args, int); 487 event_code = va_arg (args, int);
492 488
493 if (event_code == EVENT_FREE_OB) 489 if (event_code == EVENT_FREE_OB)
633 } 629 }
634 630
635 return &rv; 631 return &rv;
636} 632}
637 633
638void *
639eventListener (int *type, ...) 634extern "C" void * eventListener (int *type, ...)
640{ 635{
641 static int rv; 636 static int rv;
642 va_list args; 637 va_list args;
643 int event_code; 638 int event_code;
644 object *who, *activator, *third, *event; 639 object *who, *activator, *third, *event;
645 char *message, *extension, *options; 640 char *message, *extension, *options;
646 641
647 if (!perl) 642 if (!perl)
648 return; 643 return NULL;
649 644
650 va_start (args, type); 645 va_start (args, type);
651 who = va_arg (args, object *); 646 who = va_arg (args, object *);
652 event_code = va_arg (args, int); 647 event_code = va_arg (args, int);
653 activator = va_arg (args, object *); 648 activator = va_arg (args, object *);
679 case EVENT_STOP: // $ob (e.g. arrow) 674 case EVENT_STOP: // $ob (e.g. arrow)
680 case EVENT_TIME: // $ob 675 case EVENT_TIME: // $ob
681 case EVENT_TIMER: // $ob 676 case EVENT_TIMER: // $ob
682 break; 677 break;
683 678
684 case EVENT_APPLY: // $ob, $who 679 case EVENT_APPLY: // $ob, $who
685 case EVENT_DROP: // $ob, $who 680 case EVENT_DROP: // $ob, $who
686 case EVENT_CLOSE: // $ob, $who 681 case EVENT_CLOSE: // $ob, $who
687 case EVENT_DEATH: // $ob[, $killer] 682 case EVENT_DEATH: // $ob[, $killer]
688 case EVENT_MOVE: // $ob, $enemy 683 case EVENT_MOVE: // $ob, $enemy
689 case EVENT_THROW: // $ob, $thrower 684 case EVENT_THROW: // $ob, $thrower
690 PUSHcfapi (POBJECT, activator); 685 PUSHcfapi (POBJECT, activator);
691 break; 686 break;
692 687
688 case EVENT_DROP_ON: // $ob, $who, $what
693 case EVENT_ATTACK: // $ob, $who, $victim (?? please god enlighten me) 689 case EVENT_ATTACK: // $ob, $who, $victim (?? please god enlighten me)
694 PUSHcfapi (POBJECT, activator); 690 PUSHcfapi (POBJECT, activator);
695 PUSHcfapi (POBJECT, third); 691 PUSHcfapi (POBJECT, third);
696 break; 692 break;
697 693
726 } 722 }
727 723
728 return &rv; 724 return &rv;
729} 725}
730 726
731int 727extern "C" int closePlugin ()
732closePlugin ()
733{ 728{
734 printf (PLUGIN_VERSION " closing\n"); 729 printf (PLUGIN_VERSION " closing\n");
735 730
736 if (perl) 731 if (perl)
737 { 732 {
1065 const_iv (F_DAMNED) 1060 const_iv (F_DAMNED)
1066 const_iv (F_OPEN) 1061 const_iv (F_OPEN)
1067 const_iv (F_NOPICK) 1062 const_iv (F_NOPICK)
1068 const_iv (F_LOCKED) 1063 const_iv (F_LOCKED)
1069 1064
1065 const_iv (F_BUY)
1066 const_iv (F_SHOP)
1067 const_iv (F_SELL)
1068
1070 const_iv (P_BLOCKSVIEW) 1069 const_iv (P_BLOCKSVIEW)
1071 const_iv (P_NO_MAGIC) 1070 const_iv (P_NO_MAGIC)
1072 const_iv (P_IS_ALIVE) 1071 const_iv (P_IS_ALIVE)
1073 const_iv (P_NO_CLERIC) 1072 const_iv (P_NO_CLERIC)
1074 const_iv (P_NEED_UPDATE) 1073 const_iv (P_NEED_UPDATE)
1237 const_event (NONE) 1236 const_event (NONE)
1238 const_event (APPLY) 1237 const_event (APPLY)
1239 const_event (ATTACK) 1238 const_event (ATTACK)
1240 const_event (DEATH) 1239 const_event (DEATH)
1241 const_event (DROP) 1240 const_event (DROP)
1241 const_event (DROP_ON)
1242 const_event (PICKUP) 1242 const_event (PICKUP)
1243 const_event (SAY) 1243 const_event (SAY)
1244 const_event (STOP) 1244 const_event (STOP)
1245 const_event (TIME) 1245 const_event (TIME)
1246 const_event (THROW) 1246 const_event (THROW)
1420 } 1420 }
1421 1421
1422 //I_EVENT_API (PACKAGE); 1422 //I_EVENT_API (PACKAGE);
1423} 1423}
1424 1424
1425NV floor (NV x)
1426
1427NV ceil (NV x)
1428
1425void 1429void
1426LOG (int level, char *msg) 1430LOG (int level, char *msg)
1427 PROTOTYPE: $$ 1431 PROTOTYPE: $$
1428 C_ARGS: level, "%s", msg 1432 C_ARGS: (LogLevel)level, "%s", msg
1429 1433
1430char *path_combine (char *base, char *path) 1434char *path_combine (char *base, char *path)
1431 PROTOTYPE: $$ 1435 PROTOTYPE: $$
1432 1436
1433char *path_combine_and_normalize (char *base, char *path) 1437char *path_combine_and_normalize (char *base, char *path)
1521 { 1525 {
1522 case CFAPI_INT: 1526 case CFAPI_INT:
1523 cf_object_set_int_property (obj, idx, SvIV (newval)); 1527 cf_object_set_int_property (obj, idx, SvIV (newval));
1524 break; 1528 break;
1525 case CFAPI_LONG: 1529 case CFAPI_LONG:
1526 cf_object_set_long_property (obj, idx, SvVAL64 (newval)); 1530 cf_object_set_long_property (obj, idx, (long) SvVAL64 (newval));
1527 break; 1531 break;
1528 case CFAPI_DOUBLE: 1532 case CFAPI_DOUBLE:
1529 { 1533 {
1530 int unused_type; 1534 int unused_type;
1531 object_set_property (&unused_type, obj, idx, (double)SvNV (newval)); 1535 object_set_property (&unused_type, obj, idx, (double)SvNV (newval));
1609 1613
1610object *cf_object_clone (object *op, int clonetype = 0) 1614object *cf_object_clone (object *op, int clonetype = 0)
1611 1615
1612int cf_object_pay_item (object *op, object *buyer) 1616int cf_object_pay_item (object *op, object *buyer)
1613 1617
1614int cf_object_pay_amount (object *op, val64 amount) 1618int cf_object_pay_amount (object *op, uint64 amount)
1615 1619
1616void pay_player (object *op, val64 amount) 1620void pay_player (object *op, uint64 amount)
1617 1621
1618val64 pay_player_arch (object *op, const char *arch, val64 amount) 1622val64 pay_player_arch (object *op, const char *arch, uint64 amount)
1619 1623
1620int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0) 1624int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0)
1621 1625
1622int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0) 1626int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0)
1623 1627
1660 1664
1661void cf_object_pickup (object *op, object *what) 1665void cf_object_pickup (object *op, object *what)
1662 1666
1663object *cf_create_object_by_name (const char *name) 1667object *cf_create_object_by_name (const char *name)
1664 1668
1665void change_exp (object *op, val64 exp, const char *skill_name = 0, int flag = 0) 1669void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0)
1666 1670
1667void player_lvl_adj (object *who, object *skill = 0) 1671void player_lvl_adj (object *who, object *skill = 0)
1668 1672
1669int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 1673int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1670 1674
1784 1788
1785partylist *cf_player_get_party (object *op) 1789partylist *cf_player_get_party (object *op)
1786 ALIAS: party = 0 1790 ALIAS: party = 0
1787 1791
1788void cf_player_set_party (object *op, partylist *party) 1792void cf_player_set_party (object *op, partylist *party)
1789
1790void change_skill (object *op, val64 exp, char *skill_name = 0, int flag = 0)
1791 1793
1792void kill_player (object *op) 1794void kill_player (object *op)
1793 1795
1794MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ 1796MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1795 1797
1917mapstruct *new (int width, int height) 1919mapstruct *new (int width, int height)
1918 PROTOTYPE: 1920 PROTOTYPE:
1919 CODE: 1921 CODE:
1920{ 1922{
1921 int unused_type; 1923 int unused_type;
1922 RETVAL = map_get_map (&unused_type, 0, width, height); 1924 RETVAL = (mapstruct*) map_get_map (&unused_type, 0, width, height);
1923} 1925}
1924 OUTPUT: 1926 OUTPUT:
1925 RETVAL 1927 RETVAL
1926 1928
1927void delete_map (mapstruct *map) 1929void delete_map (mapstruct *map)
2208 maxgrace = 15 2210 maxgrace = 15
2209 food = 16 2211 food = 16
2210 dam = 17 2212 dam = 17
2211 luck = 18 2213 luck = 18
2212 CODE: 2214 CODE:
2213# define LIVING_ACC(acc,idx) case idx: RETVAL = liv->acc; if (items > 1) liv->acc = new_val; break 2215# define LIVING_ACC(acc,idx) case idx: RETVAL = liv->acc; if (items > 1) liv->acc = (sint64)new_val; break
2214 switch (ix) 2216 switch (ix)
2215 { 2217 {
2216 LIVING_ACC (exp , 0); 2218 LIVING_ACC (exp , 0);
2217 LIVING_ACC (Str , 1); 2219 LIVING_ACC (Str , 1);
2218 LIVING_ACC (Dex , 2); 2220 LIVING_ACC (Dex , 2);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines