… | |
… | |
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 | |
53 | extern sint64 *levels; // the experience table |
55 | extern 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 | |
97 | extern void pay_player(object *op, uint64 amount); |
|
|
98 | extern 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 | |
309 | int |
|
|
310 | initPlugin (const char *iversion, f_plug_api gethooksptr) |
308 | extern "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 | |
353 | void * |
|
|
354 | getPluginProperty (int *type, ...) |
351 | extern "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 | |
400 | void *globalEventListener (int *type, ...); |
397 | void *globalEventListener (int *type, ...); |
401 | |
398 | |
402 | int |
399 | extern "C" int postInitPlugin () |
403 | postInitPlugin () |
|
|
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 | |
638 | void * |
|
|
639 | eventListener (int *type, ...) |
634 | extern "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 | |
731 | int |
727 | extern "C" int closePlugin () |
732 | closePlugin () |
|
|
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 | |
|
|
1425 | NV floor (NV x) |
|
|
1426 | |
|
|
1427 | NV ceil (NV x) |
|
|
1428 | |
1425 | void |
1429 | void |
1426 | LOG (int level, char *msg) |
1430 | LOG (int level, char *msg) |
1427 | PROTOTYPE: $$ |
1431 | PROTOTYPE: $$ |
1428 | C_ARGS: level, "%s", msg |
1432 | C_ARGS: (LogLevel)level, "%s", msg |
1429 | |
1433 | |
1430 | char *path_combine (char *base, char *path) |
1434 | char *path_combine (char *base, char *path) |
1431 | PROTOTYPE: $$ |
1435 | PROTOTYPE: $$ |
1432 | |
1436 | |
1433 | char *path_combine_and_normalize (char *base, char *path) |
1437 | char *path_combine_and_normalize (char *base, char *path) |
… | |
… | |
1465 | cf_find_animation (char *text) |
1469 | cf_find_animation (char *text) |
1466 | PROTOTYPE: $ |
1470 | PROTOTYPE: $ |
1467 | |
1471 | |
1468 | int random_roll(int min, int max, object *op, int goodbad); |
1472 | int random_roll(int min, int max, object *op, int goodbad); |
1469 | |
1473 | |
|
|
1474 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
|
|
1475 | |
1470 | int |
1476 | int |
1471 | exp_to_level (val64 exp) |
1477 | exp_to_level (val64 exp) |
1472 | CODE: |
1478 | CODE: |
1473 | { |
1479 | { |
1474 | int i = 0; |
1480 | int i = 0; |
… | |
… | |
1521 | { |
1527 | { |
1522 | case CFAPI_INT: |
1528 | case CFAPI_INT: |
1523 | cf_object_set_int_property (obj, idx, SvIV (newval)); |
1529 | cf_object_set_int_property (obj, idx, SvIV (newval)); |
1524 | break; |
1530 | break; |
1525 | case CFAPI_LONG: |
1531 | case CFAPI_LONG: |
1526 | cf_object_set_long_property (obj, idx, SvVAL64 (newval)); |
1532 | cf_object_set_long_property (obj, idx, (long) SvVAL64 (newval)); |
1527 | break; |
1533 | break; |
1528 | case CFAPI_DOUBLE: |
1534 | case CFAPI_DOUBLE: |
1529 | { |
1535 | { |
1530 | int unused_type; |
1536 | int unused_type; |
1531 | object_set_property (&unused_type, obj, idx, (double)SvNV (newval)); |
1537 | object_set_property (&unused_type, obj, idx, (double)SvNV (newval)); |
… | |
… | |
1589 | int cf_object_get_flag (object *op, int flag) |
1595 | int cf_object_get_flag (object *op, int flag) |
1590 | ALIAS: flag = 0 |
1596 | ALIAS: flag = 0 |
1591 | |
1597 | |
1592 | void cf_object_set_flag (object *op, int flag, int value) |
1598 | void cf_object_set_flag (object *op, int flag, int value) |
1593 | |
1599 | |
|
|
1600 | int need_identify (const object *obj); |
|
|
1601 | |
|
|
1602 | int apply_shop_mat (object *shop_mat, object *op); |
|
|
1603 | |
1594 | void cf_object_move (object *op, int dir, object *originator = op) |
1604 | void cf_object_move (object *op, int dir, object *originator = op) |
1595 | |
1605 | |
1596 | void cf_object_apply (object *op, object *author, int flags = 0) |
1606 | void cf_object_apply (object *op, object *author, int flags = 0) |
1597 | |
1607 | |
1598 | void cf_object_apply_below (object *op) |
1608 | void cf_object_apply_below (object *op) |
… | |
… | |
1609 | |
1619 | |
1610 | object *cf_object_clone (object *op, int clonetype = 0) |
1620 | object *cf_object_clone (object *op, int clonetype = 0) |
1611 | |
1621 | |
1612 | int cf_object_pay_item (object *op, object *buyer) |
1622 | int cf_object_pay_item (object *op, object *buyer) |
1613 | |
1623 | |
1614 | int cf_object_pay_amount (object *op, val64 amount) |
1624 | int cf_object_pay_amount (object *op, uint64 amount) |
1615 | |
1625 | |
1616 | void pay_player (object *op, val64 amount) |
1626 | void pay_player (object *op, uint64 amount) |
1617 | |
1627 | |
1618 | val64 pay_player_arch (object *op, const char *arch, val64 amount) |
1628 | val64 pay_player_arch (object *op, const char *arch, uint64 amount) |
1619 | |
1629 | |
1620 | int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0) |
1630 | int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0) |
1621 | |
1631 | |
1622 | int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0) |
1632 | int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0) |
1623 | |
1633 | |
… | |
… | |
1660 | |
1670 | |
1661 | void cf_object_pickup (object *op, object *what) |
1671 | void cf_object_pickup (object *op, object *what) |
1662 | |
1672 | |
1663 | object *cf_create_object_by_name (const char *name) |
1673 | object *cf_create_object_by_name (const char *name) |
1664 | |
1674 | |
1665 | void change_exp (object *op, val64 exp, const char *skill_name = 0, int flag = 0) |
1675 | void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) |
1666 | |
1676 | |
1667 | void player_lvl_adj (object *who, object *skill = 0) |
1677 | void player_lvl_adj (object *who, object *skill = 0) |
1668 | |
1678 | |
1669 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
1679 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
1670 | |
1680 | |
… | |
… | |
1784 | |
1794 | |
1785 | partylist *cf_player_get_party (object *op) |
1795 | partylist *cf_player_get_party (object *op) |
1786 | ALIAS: party = 0 |
1796 | ALIAS: party = 0 |
1787 | |
1797 | |
1788 | void cf_player_set_party (object *op, partylist *party) |
1798 | void cf_player_set_party (object *op, partylist *party) |
1789 | |
|
|
1790 | void change_skill (object *op, val64 exp, char *skill_name = 0, int flag = 0) |
|
|
1791 | |
1799 | |
1792 | void kill_player (object *op) |
1800 | void kill_player (object *op) |
1793 | |
1801 | |
1794 | MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ |
1802 | MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ |
1795 | |
1803 | |
… | |
… | |
1917 | mapstruct *new (int width, int height) |
1925 | mapstruct *new (int width, int height) |
1918 | PROTOTYPE: |
1926 | PROTOTYPE: |
1919 | CODE: |
1927 | CODE: |
1920 | { |
1928 | { |
1921 | int unused_type; |
1929 | int unused_type; |
1922 | RETVAL = map_get_map (&unused_type, 0, width, height); |
1930 | RETVAL = (mapstruct*) map_get_map (&unused_type, 0, width, height); |
1923 | } |
1931 | } |
1924 | OUTPUT: |
1932 | OUTPUT: |
1925 | RETVAL |
1933 | RETVAL |
1926 | |
1934 | |
1927 | void delete_map (mapstruct *map) |
1935 | void delete_map (mapstruct *map) |
… | |
… | |
2208 | maxgrace = 15 |
2216 | maxgrace = 15 |
2209 | food = 16 |
2217 | food = 16 |
2210 | dam = 17 |
2218 | dam = 17 |
2211 | luck = 18 |
2219 | luck = 18 |
2212 | CODE: |
2220 | CODE: |
2213 | # define LIVING_ACC(acc,idx) case idx: RETVAL = liv->acc; if (items > 1) liv->acc = new_val; break |
2221 | # define LIVING_ACC(acc,idx) case idx: RETVAL = liv->acc; if (items > 1) liv->acc = (sint64)new_val; break |
2214 | switch (ix) |
2222 | switch (ix) |
2215 | { |
2223 | { |
2216 | LIVING_ACC (exp , 0); |
2224 | LIVING_ACC (exp , 0); |
2217 | LIVING_ACC (Str , 1); |
2225 | LIVING_ACC (Str , 1); |
2218 | LIVING_ACC (Dex , 2); |
2226 | LIVING_ACC (Dex , 2); |