… | |
… | |
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 | |
52 | typedef object object_ornull; |
53 | typedef object object_ornull; |
53 | typedef mapstruct mapstruct_ornull; |
54 | typedef 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 | |
|
|
91 | extern void pay_player(object *op, uint64 amount); |
|
|
92 | extern 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 |
… | |
… | |
443 | }; |
447 | }; |
444 | |
448 | |
445 | perl = perl_alloc (); |
449 | perl = perl_alloc (); |
446 | perl_construct (perl); |
450 | perl_construct (perl); |
447 | |
451 | |
|
|
452 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
453 | |
448 | 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)) |
449 | { |
455 | { |
450 | printf ("unable to initialize perl-interpreter, continuing without.\n"); |
456 | printf ("unable to initialize perl-interpreter, continuing without.\n"); |
451 | |
457 | |
452 | perl_destruct (perl); |
458 | perl_destruct (perl); |
… | |
… | |
486 | if (sv) |
492 | if (sv) |
487 | clearSVptr (sv); |
493 | clearSVptr (sv); |
488 | |
494 | |
489 | rv = 0; |
495 | rv = 0; |
490 | } |
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 | } |
491 | else |
525 | else |
492 | { |
526 | { |
493 | dSP; |
527 | dSP; |
494 | |
528 | |
495 | ENTER; |
529 | ENTER; |
… | |
… | |
550 | { |
584 | { |
551 | char *buf = va_arg (args, char *); |
585 | char *buf = va_arg (args, char *); |
552 | int len = va_arg (args, int); |
586 | int len = va_arg (args, int); |
553 | PUSHs (sv_2mortal (newSVpvn (buf, len))); |
587 | PUSHs (sv_2mortal (newSVpvn (buf, len))); |
554 | } |
588 | } |
555 | break; |
|
|
556 | |
|
|
557 | case EVENT_CLOCK: |
|
|
558 | clean_obj_cache (); |
|
|
559 | break; |
589 | break; |
560 | |
590 | |
561 | case EVENT_TELL: |
591 | case EVENT_TELL: |
562 | break; |
592 | break; |
563 | } |
593 | } |
… | |
… | |
1127 | const_iv (SOUND_CLOCK) |
1157 | const_iv (SOUND_CLOCK) |
1128 | const_iv (SOUND_TURN_HANDLE) |
1158 | const_iv (SOUND_TURN_HANDLE) |
1129 | const_iv (SOUND_FALL_HOLE) |
1159 | const_iv (SOUND_FALL_HOLE) |
1130 | const_iv (SOUND_DRINK_POISON) |
1160 | const_iv (SOUND_DRINK_POISON) |
1131 | 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) |
1132 | }; |
1173 | }; |
1133 | |
1174 | |
1134 | 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; ) |
1135 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1176 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1136 | |
1177 | |
… | |
… | |
1153 | const_event (CLOSE) |
1194 | const_event (CLOSE) |
1154 | const_event (TIMER) |
1195 | const_event (TIMER) |
1155 | const_event (MOVE) |
1196 | const_event (MOVE) |
1156 | |
1197 | |
1157 | const_event (BORN) |
1198 | const_event (BORN) |
1158 | const_event (CLOCK) |
1199 | //const_event (CLOCK) |
1159 | const_event (CRASH) |
1200 | const_event (CRASH) |
1160 | const_event (PLAYER_DEATH) |
1201 | const_event (PLAYER_DEATH) |
1161 | const_event (PLAYER_LOAD) |
1202 | const_event (PLAYER_LOAD) |
1162 | const_event (PLAYER_SAVE) |
1203 | const_event (PLAYER_SAVE) |
1163 | const_event (GKILL) |
1204 | const_event (GKILL) |
… | |
… | |
1317 | 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; ) |
1318 | { |
1359 | { |
1319 | 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); |
1320 | 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); |
1321 | } |
1362 | } |
|
|
1363 | |
|
|
1364 | //I_EVENT_API (PACKAGE); |
1322 | } |
1365 | } |
1323 | |
1366 | |
1324 | void |
1367 | void |
1325 | LOG (int level, char *msg) |
1368 | LOG (int level, char *msg) |
1326 | PROTOTYPE: $$ |
1369 | PROTOTYPE: $$ |
1327 | C_ARGS: level, "%s", msg |
1370 | C_ARGS: level, "%s", msg |
|
|
1371 | |
|
|
1372 | char *path_combine (char *base, char *path) |
|
|
1373 | PROTOTYPE: $$ |
|
|
1374 | |
|
|
1375 | char *path_combine_and_normalize (char *base, char *path) |
|
|
1376 | PROTOTYPE: $$ |
1328 | |
1377 | |
1329 | char * |
1378 | char * |
1330 | cf_get_maps_directory (char *path) |
1379 | cf_get_maps_directory (char *path) |
1331 | PROTOTYPE: $ |
1380 | PROTOTYPE: $ |
1332 | ALIAS: maps_directory = 0 |
1381 | ALIAS: maps_directory = 0 |
… | |
… | |
1505 | |
1554 | |
1506 | object *cf_create_object_by_name (const char *name) |
1555 | object *cf_create_object_by_name (const char *name) |
1507 | |
1556 | |
1508 | void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) |
1557 | void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) |
1509 | |
1558 | |
|
|
1559 | void pay_player (object *op, double amount) |
|
|
1560 | |
|
|
1561 | double pay_player_arch (object *op, const char *arch, double amount) |
|
|
1562 | |
1510 | void player_lvl_adj (object *who, object *skill = 0) |
1563 | void player_lvl_adj (object *who, object *skill = 0) |
1511 | |
1564 | |
1512 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
1565 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
1513 | |
1566 | |
1514 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1567 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
… | |
… | |
1643 | |
1696 | |
1644 | player *next (player *pl) |
1697 | player *next (player *pl) |
1645 | CODE: |
1698 | CODE: |
1646 | RETVAL = pl->next; |
1699 | RETVAL = pl->next; |
1647 | OUTPUT: RETVAL |
1700 | OUTPUT: RETVAL |
|
|
1701 | |
|
|
1702 | bool |
|
|
1703 | cell_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 |
1648 | |
1709 | |
1649 | void |
1710 | void |
1650 | send (player *pl, SV *packet) |
1711 | send (player *pl, SV *packet) |
1651 | CODE: |
1712 | CODE: |
1652 | { |
1713 | { |
… | |
… | |
1746 | |
1807 | |
1747 | void clean_tmp_map (mapstruct *map) |
1808 | void clean_tmp_map (mapstruct *map) |
1748 | |
1809 | |
1749 | void play_sound_map (mapstruct *map, int x, int y, int sound_num) |
1810 | void play_sound_map (mapstruct *map, int x, int y, int sound_num) |
1750 | |
1811 | |
|
|
1812 | mapstruct *tile_map (mapstruct *map, unsigned int dir) |
|
|
1813 | CODE: |
|
|
1814 | RETVAL = dir < 4 ? map->tile_map [dir] : 0; |
|
|
1815 | OUTPUT: |
|
|
1816 | RETVAL |
|
|
1817 | |
|
|
1818 | char *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 | |
1751 | mapstruct *cf_map_get_map (char *name) |
1826 | mapstruct *cf_map_get_map (char *name) |
1752 | PROTOTYPE: $ |
1827 | PROTOTYPE: $ |
1753 | ALIAS: map = 0 |
1828 | ALIAS: map = 0 |
1754 | |
1829 | |
|
|
1830 | mapstruct *has_been_loaded (char *name) |
|
|
1831 | PROTOTYPE: $ |
|
|
1832 | |
1755 | mapstruct *cf_map_get_first () |
1833 | mapstruct *cf_map_get_first () |
1756 | PROTOTYPE: |
1834 | PROTOTYPE: |
1757 | ALIAS: first = 0 |
1835 | ALIAS: first = 0 |
1758 | |
1836 | |
1759 | # whoever "designed" the plug-in api should have wasted |
1837 | # whoever "designed" the plug-in api should have wasted |
1760 | # his/her time with staying away form the project - would have |
1838 | # his/her time with staying away from the project - would have |
1761 | # saved others a lot of time, without doubt. |
1839 | # saved others a lot of time, without doubt. |
1762 | void set_path (mapstruct *where, char *path) |
1840 | void set_path (mapstruct *where, char *path) |
1763 | CODE: |
1841 | CODE: |
1764 | strcpy (where->path, path); |
1842 | strcpy (where->path, path); |
|
|
1843 | |
|
|
1844 | int in_memory (mapstruct *map) |
|
|
1845 | CODE: |
|
|
1846 | RETVAL = map->in_memory; |
|
|
1847 | OUTPUT: |
|
|
1848 | RETVAL |
1765 | |
1849 | |
1766 | bool unique (mapstruct *map) |
1850 | bool unique (mapstruct *map) |
1767 | CODE: |
1851 | CODE: |
1768 | RETVAL = map->unique; |
1852 | RETVAL = map->unique; |
1769 | OUTPUT: |
1853 | OUTPUT: |
… | |
… | |
1778 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
1862 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
1779 | |
1863 | |
1780 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1864 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1781 | C_ARGS: str, map, nx, ny |
1865 | C_ARGS: str, map, nx, ny |
1782 | |
1866 | |
1783 | #int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny) |
|
|
1784 | |
|
|
1785 | void |
1867 | void |
|
|
1868 | cf_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 | |
|
|
1886 | void |
1786 | at (mapstruct *obj, unsigned int x, unsigned int y) |
1887 | at (mapstruct *map, unsigned int x, unsigned int y) |
1787 | PROTOTYPE: $$$ |
1888 | PROTOTYPE: $$$ |
1788 | INIT: |
|
|
1789 | if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY; |
|
|
1790 | PPCODE: |
1889 | PPCODE: |
1791 | { |
1890 | { |
1792 | object *o; |
1891 | object *o; |
1793 | |
1892 | mapstruct *nmap = 0; |
|
|
1893 | I16 nx, ny; |
|
|
1894 | |
|
|
1895 | cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
|
|
1896 | |
|
|
1897 | if (nmap) |
1794 | 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) |
1795 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
1899 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
1796 | } |
1900 | } |
1797 | |
1901 | |
1798 | SV * |
1902 | SV * |
1799 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
1903 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
1800 | PROTOTYPE: $$$ |
1904 | PROTOTYPE: $$$ |