ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.210 by root, Sat May 19 00:08:12 2007 UTC vs.
Revision 1.220 by root, Sat Jun 9 22:54:03 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * 3 *
4 * This code is placed under the GNU General Public Licence (GPL) 4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 *
6 * Copyright (C) 2001-2005 by Chachkoff Yann 5 * Copyright (©) 2001-2005,2007 by Chachkoff Yann
7 * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de> 6 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de>
8 * 7 *
9 * This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software; you can redistribute it and/or modify it
10 * it under the terms of the GNU General Public License as published by 9 * under the terms of the GNU General Public License as published by the Free
11 * the Free Software Foundation; either version 2 of the License, or 10 * Software Foundation; either version 2 of the License, or (at your option)
12 * (at your option) any later version. 11 * any later version.
13 * 12 *
14 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful, but
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * GNU General Public License for more details. 16 * for more details.
18 * 17 *
19 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License along
20 * along with this program; if not, write to the Free Software 19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
21 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de>
22 */ 23 */
23 24
24#include "autoconf.h" 25#include "autoconf.h"
25 26
26#define PLUGIN_NAME "perl" 27#define PLUGIN_NAME "perl"
74# define newSVval64 newSVnv 75# define newSVval64 newSVnv
75# define SvVAL64 SvNV 76# define SvVAL64 SvNV
76#endif 77#endif
77 78
78static f_plug_api gethook = cfapi_get_hooks; 79static f_plug_api gethook = cfapi_get_hooks;
79static f_plug_api object_set_property = cfapi_object_set_property;
80static f_plug_api object_insert = cfapi_object_insert; 80static f_plug_api object_insert = cfapi_object_insert;
81 81
82static PerlInterpreter *perl; 82static PerlInterpreter *perl;
83 83
84double runtime; 84tstamp NOW, runtime;
85 85
86global gbl_ev; 86global gbl_ev;
87static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; 87static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
88static SV *sv_runtime, *sv_next_tick; 88static SV *sv_runtime, *sv_next_tick;
89 89
168} 168}
169 169
170void 170void
171attachable::do_destroy () 171attachable::do_destroy ()
172{ 172{
173 invoke (EVENT_ATTACHABLE_DESTROY, DT_END); 173 INVOKE_ATTACHABLE (DESTROY, this);
174 174
175 if (cb) 175 if (cb)
176 { 176 {
177 SvREFCNT_dec (cb); 177 SvREFCNT_dec (cb);
178 cb = 0; 178 cb = 0;
655void 655void
656attachable::instantiate () 656attachable::instantiate ()
657{ 657{
658 if (attach) 658 if (attach)
659 { 659 {
660 invoke (EVENT_ATTACHABLE_INSTANTIATE, ARG_STRING (attach), DT_END); 660 INVOKE_ATTACHABLE (INSTANTIATE, this, ARG_STRING (attach));
661 attach = 0; 661 attach = 0;
662 } 662 }
663} 663}
664 664
665void 665void
666attachable::reattach () 666attachable::reattach ()
667{ 667{
668 optimise (); 668 optimise ();
669 //TODO: check for _attachment's, very important for restarts 669 //TODO: check for _attachment's, very important for restarts
670 invoke (EVENT_ATTACHABLE_REATTACH, DT_END); 670 INVOKE_ATTACHABLE (REATTACH, this);
671} 671}
672 672
673static event_klass klass_of[NUM_EVENT_TYPES] = { 673static event_klass klass_of[NUM_EVENT_TYPES] = {
674# define def(type,name) KLASS_ ## type, 674# define def(type,name) KLASS_ ## type,
675# include "eventinc.h" 675# include "eventinc.h"
823 } 823 }
824 } 824 }
825} 825}
826 826
827bool 827bool
828attachable::vinvoke (event_type event, va_list &ap) 828attachable::invoke (event_type event, ...)
829{ 829{
830 data_type dt; 830 data_type dt;
831 831
832 // callback call ordering should be: 832 // callback call ordering should be:
833 // 1. per-object callback 833 // 1. per-object callback
839 gather_callbacks (callbacks, event); 839 gather_callbacks (callbacks, event);
840 840
841 // short-circuit processing if no callbacks found/defined 841 // short-circuit processing if no callbacks found/defined
842 if (!callbacks) 842 if (!callbacks)
843 return 0; 843 return 0;
844
845 va_list ap;
846 va_start (ap, event);
844 847
845 CALL_BEGIN (3); 848 CALL_BEGIN (3);
846 CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays 849 CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays
847 CALL_ARG_SV (newRV_noinc ((SV *)callbacks)); 850 CALL_ARG_SV (newRV_noinc ((SV *)callbacks));
848 851
925 CALL_ARG (make_core); 928 CALL_ARG (make_core);
926 CALL_CALL ("cf::post_cleanup", G_VOID); 929 CALL_CALL ("cf::post_cleanup", G_VOID);
927 CALL_END; 930 CALL_END;
928} 931}
929 932
933void
934cfperl_make_book (object *book, int level)
935{
936 CALL_BEGIN (2);
937 CALL_ARG (book);
938 CALL_ARG (level);
939 CALL_CALL ("ext::books::make_book", G_VOID);
940 CALL_END;
941}
942
930maptile * 943maptile *
931maptile::find_sync (const char *path, maptile *origin) 944maptile::find_sync (const char *path, maptile *origin)
932{ 945{
933 CALL_BEGIN (2); 946 CALL_BEGIN (2);
934 CALL_ARG (path); 947 CALL_ARG (path);
1018 1031
1019struct EventAPI *watcher_base::GEventAPI; 1032struct EventAPI *watcher_base::GEventAPI;
1020struct CoroAPI *coroapi::GCoroAPI; 1033struct CoroAPI *coroapi::GCoroAPI;
1021 1034
1022int coroapi::cede_counter; 1035int coroapi::cede_counter;
1023double (*coroapi::time)();
1024double coroapi::next_cede; 1036tstamp coroapi::next_cede;
1025 1037
1026void coroapi::do_cede_to_tick () 1038void coroapi::do_cede_to_tick ()
1027{ 1039{
1028 cede_counter = 0; 1040 cede_counter = 0;
1029 1041
1160 1172
1161 _connect_to_perl (); 1173 _connect_to_perl ();
1162 1174
1163 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1175 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1164 1176
1165 { 1177 //{
1166 require_pv ("Time::HiRes"); 1178 // require_pv ("Time::HiRes");
1167 1179 //
1168 SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); 1180 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1169 if (!svp) croak ("Time::HiRes is required"); 1181 // if (!svp) croak ("Time::HiRes is required");
1170 if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); 1182 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1171 coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); 1183 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1172 } 1184 //}
1173 1185
1174 static const struct { 1186 static const struct {
1175 const char *name; 1187 const char *name;
1176 IV iv; 1188 IV iv;
1177 } *civ, const_iv[] = { 1189 } *civ, const_iv[] = {
1274 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) 1286 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE)
1275 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) 1287 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF)
1276 1288
1277 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) 1289 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE)
1278 1290
1291 const_iv (SP_RAISE_DEAD)
1292 const_iv (SP_RUNE)
1293 const_iv (SP_MAKE_MARK)
1294 const_iv (SP_BOLT)
1295 const_iv (SP_BULLET)
1296 const_iv (SP_EXPLOSION)
1297 const_iv (SP_CONE)
1298 const_iv (SP_BOMB)
1299 const_iv (SP_WONDER)
1300 const_iv (SP_SMITE)
1301 const_iv (SP_MAGIC_MISSILE)
1302 const_iv (SP_SUMMON_GOLEM)
1303 const_iv (SP_DIMENSION_DOOR)
1304 const_iv (SP_MAGIC_MAPPING)
1305 const_iv (SP_MAGIC_WALL)
1306 const_iv (SP_DESTRUCTION)
1307 const_iv (SP_PERCEIVE_SELF)
1308 const_iv (SP_WORD_OF_RECALL)
1309 const_iv (SP_INVISIBLE)
1310 const_iv (SP_PROBE)
1311 const_iv (SP_HEALING)
1312 const_iv (SP_CREATE_FOOD)
1313 const_iv (SP_EARTH_TO_DUST)
1314 const_iv (SP_CHANGE_ABILITY)
1315 const_iv (SP_BLESS)
1316 const_iv (SP_CURSE)
1317 const_iv (SP_SUMMON_MONSTER)
1318 const_iv (SP_CHARGING)
1319 const_iv (SP_POLYMORPH)
1320 const_iv (SP_ALCHEMY)
1321 const_iv (SP_REMOVE_CURSE)
1322 const_iv (SP_IDENTIFY)
1323 const_iv (SP_DETECTION)
1324 const_iv (SP_MOOD_CHANGE)
1325 const_iv (SP_MOVING_BALL)
1326 const_iv (SP_SWARM)
1327 const_iv (SP_CHANGE_MANA)
1328 const_iv (SP_DISPEL_RUNE)
1329 const_iv (SP_CREATE_MISSILE)
1330 const_iv (SP_CONSECRATE)
1331 const_iv (SP_ANIMATE_WEAPON)
1332 const_iv (SP_LIGHT)
1333 const_iv (SP_CHANGE_MAP_LIGHT)
1334 const_iv (SP_FAERY_FIRE)
1335 const_iv (SP_CAUSE_DISEASE)
1336 const_iv (SP_AURA)
1337 const_iv (SP_TOWN_PORTAL)
1338 const_iv (SP_PARTY_SPELL)
1339
1279 const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC) 1340 const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC)
1280 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK) 1341 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK)
1281 const_iv (F_LOCKED) 1342 const_iv (F_LOCKED)
1282 1343
1283 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL) 1344 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL)
1478 CODE: 1539 CODE:
1479 coroapi::cede_to_tick (); 1540 coroapi::cede_to_tick ();
1480 1541
1481void server_tick () 1542void server_tick ()
1482 CODE: 1543 CODE:
1544 NOW = now ();
1483 runtime = SvNVx (sv_runtime); 1545 runtime = SvNVx (sv_runtime);
1484 server_tick (); 1546 server_tick ();
1485 1547
1486void 1548void
1487log_backtrace (utf8_string msg) 1549log_backtrace (utf8_string msg)
1679object *actives (U32 index) 1741object *actives (U32 index)
1680 CODE: 1742 CODE:
1681 RETVAL = index < actives.size () ? actives [index] : 0; 1743 RETVAL = index < actives.size () ? actives [index] : 0;
1682 OUTPUT: RETVAL 1744 OUTPUT: RETVAL
1683 1745
1684const char *slot_save_name (U32 slot) 1746const char *slot_use_name (U32 slot)
1685 ALIAS: 1747 ALIAS:
1686 slot_use_name = 1
1687 slot_nonuse_name = 2 1748 slot_nonuse_name = 1
1688 CODE: 1749 CODE:
1689{ 1750{
1690 if (slot >= NUM_BODY_LOCATIONS) 1751 if (slot >= NUM_BODY_LOCATIONS)
1691 croak ("body slot index out of range"); 1752 croak ("body slot index out of range");
1692 1753
1693 switch (ix) 1754 switch (ix)
1694 { 1755 {
1695 case 0: RETVAL = body_locations[slot].save_name; break;
1696 case 1: RETVAL = body_locations[slot].use_name; break; 1756 case 0: RETVAL = body_locations[slot].use_name; break;
1697 case 2: RETVAL = body_locations[slot].nonuse_name; break; 1757 case 1: RETVAL = body_locations[slot].nonuse_name; break;
1698 } 1758 }
1699} 1759}
1700 OUTPUT: 1760 OUTPUT:
1701 RETVAL 1761 RETVAL
1702 1762
1704 1764
1705object *head (object *op) 1765object *head (object *op)
1706 PROTOTYPE: $ 1766 PROTOTYPE: $
1707 CODE: 1767 CODE:
1708 RETVAL = op->head_ (); 1768 RETVAL = op->head_ ();
1709 OUTPUT: RETVAL
1710
1711int is_head (object *op)
1712 PROTOTYPE: $
1713 CODE:
1714 RETVAL = op->head_ () == op;
1715 OUTPUT: RETVAL 1769 OUTPUT: RETVAL
1716 1770
1717void 1771void
1718inv (object *obj) 1772inv (object *obj)
1719 PROTOTYPE: $ 1773 PROTOTYPE: $
1876# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 1930# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
1877 1931
1878object *new (utf8_string archetype = 0) 1932object *new (utf8_string archetype = 0)
1879 PROTOTYPE: ;$ 1933 PROTOTYPE: ;$
1880 CODE: 1934 CODE:
1881 RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); 1935 RETVAL = archetype ? get_archetype (archetype) : object::create ();
1882 OUTPUT: 1936 OUTPUT:
1883 RETVAL 1937 RETVAL
1884 1938
1939# TODO: nuke
1885object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) 1940object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
1886 PROTOTYPE: $$$$$$ 1941 PROTOTYPE: $$$$$$
1887 CODE: 1942 CODE:
1888{ 1943{
1889 int unused_type; 1944 int unused_type;
1942 1997
1943void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) 1998void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1944 CODE: 1999 CODE:
1945 new_draw_info (flags, 0, op, txt); 2000 new_draw_info (flags, 0, op, txt);
1946 2001
1947object *cf_player_send_inventory (object *op)
1948
1949octet_string cf_player_get_ip (object *op)
1950 ALIAS: ip = 0
1951
1952object *cf_player_get_marked_item (object *op)
1953 ALIAS: marked_item = 0
1954
1955void cf_player_set_marked_item (object *op, object *ob)
1956
1957partylist *cf_player_get_party (object *op)
1958 ALIAS: party = 0
1959
1960void cf_player_set_party (object *op, partylist *party)
1961
1962void kill_player (object *op) 2002void kill_player (object *op)
1963 2003
1964void esrv_update_item (object *op, int what, object *item) 2004void esrv_update_item (object *op, int what, object *item)
1965 C_ARGS: what, op, item 2005 C_ARGS: what, op, item
1966
1967void clear_los (object *op)
1968 2006
1969int command_summon (object *op, utf8_string params) 2007int command_summon (object *op, utf8_string params)
1970 2008
1971int command_arrest (object *op, utf8_string params) 2009int command_arrest (object *op, utf8_string params)
1972 2010
1990 CODE: 2028 CODE:
1991 pl->ob->stats.hp = pl->ob->stats.maxhp; 2029 pl->ob->stats.hp = pl->ob->stats.maxhp;
1992 pl->ob->stats.sp = pl->ob->stats.maxsp; 2030 pl->ob->stats.sp = pl->ob->stats.maxsp;
1993 pl->ob->stats.grace = pl->ob->stats.maxgrace; 2031 pl->ob->stats.grace = pl->ob->stats.maxgrace;
1994 pl->orig_stats = pl->ob->stats; 2032 pl->orig_stats = pl->ob->stats;
2033
2034void clear_los (player *pl)
1995 2035
1996void cf_player_move (player *pl, int dir) 2036void cf_player_move (player *pl, int dir)
1997 2037
1998void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2038void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
1999 2039
2351 rmp.decoroptions = decoroptions; 2391 rmp.decoroptions = decoroptions;
2352 rmp.orientation = orientation; 2392 rmp.orientation = orientation;
2353 rmp.origin_y = origin_y; 2393 rmp.origin_y = origin_y;
2354 rmp.origin_x = origin_x; 2394 rmp.origin_x = origin_x;
2355 rmp.random_seed = random_seed; 2395 rmp.random_seed = random_seed;
2356 rmp.total_map_hp = total_map_hp; 2396 rmp.total_map_hp = (uint64_t) total_map_hp;
2357 rmp.map_layout_style = map_layout_style; 2397 rmp.map_layout_style = map_layout_style;
2358 rmp.treasureoptions = treasureoptions; 2398 rmp.treasureoptions = treasureoptions;
2359 rmp.symmetry_used = symmetry_used; 2399 rmp.symmetry_used = symmetry_used;
2360 rmp.region = region; 2400 rmp.region = region;
2361 rmp.custom = custom; 2401 rmp.custom = custom;
2371 CODE: 2411 CODE:
2372 RETVAL = archetype::find (name); 2412 RETVAL = archetype::find (name);
2373 OUTPUT: 2413 OUTPUT:
2374 RETVAL 2414 RETVAL
2375 2415
2376archetype *first() 2416int archetypes_size ()
2377 PROTOTYPE: 2417 CODE:
2378 CODE:
2379 RETVAL = first_archetype; 2418 RETVAL = archetypes.size ();
2419 OUTPUT: RETVAL
2420
2421archetype *archetypes (U32 index)
2422 CODE:
2423 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2424 OUTPUT: RETVAL
2425
2426object *instantiate (archetype *arch)
2427 CODE:
2428 RETVAL = arch_to_object (arch);
2429 OUTPUT:
2380 OUTPUT: RETVAL 2430 RETVAL
2381 2431
2382INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | 2432INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h |
2383 2433
2384MODULE = cf PACKAGE = cf::party 2434MODULE = cf PACKAGE = cf::party
2385 2435

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines