… | |
… | |
4 | |
4 | |
5 | /* |
5 | /* |
6 | * This code is placed under the GNU General Public Licence (GPL) |
6 | * This code is placed under the GNU General Public Licence (GPL) |
7 | * |
7 | * |
8 | * Copyright (C) 2001-2005 by Chachkoff Yann |
8 | * Copyright (C) 2001-2005 by Chachkoff Yann |
9 | * Copyright (C) 2006 by Marc Lehmann <cf@schmorp.de> |
9 | * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de> |
10 | * |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License as published by |
12 | * it under the terms of the GNU General Public License as published by |
13 | * the Free Software Foundation; either version 2 of the License, or |
13 | * the Free Software Foundation; either version 2 of the License, or |
14 | * (at your option) any later version. |
14 | * (at your option) any later version. |
… | |
… | |
102 | |
102 | |
103 | unordered_vector<attachable *> attachable::mortals; |
103 | unordered_vector<attachable *> attachable::mortals; |
104 | |
104 | |
105 | attachable::~attachable () |
105 | attachable::~attachable () |
106 | { |
106 | { |
|
|
107 | flags |=0x3300;//D |
107 | assert (!self); |
108 | assert (!self); |
108 | assert (!cb); |
109 | assert (!cb); |
109 | } |
110 | } |
110 | |
111 | |
111 | int |
112 | int |
… | |
… | |
348 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
349 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
349 | |
350 | |
350 | inline SV *to_sv (object & v) { return to_sv (&v); } |
351 | inline SV *to_sv (object & v) { return to_sv (&v); } |
351 | inline SV *to_sv (living & v) { return to_sv (&v); } |
352 | inline SV *to_sv (living & v) { return to_sv (&v); } |
352 | |
353 | |
353 | inline SV *to_sv (facetile * v) { return to_sv (v->name); } |
354 | //inline SV *to_sv (faceinfo * v) { return to_sv (v->name); } |
354 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
355 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
|
|
356 | inline SV *to_sv (std::string & v) { return newSVpvn (v.data (), v.size ()); } |
355 | |
357 | |
356 | inline SV *to_sv (UUID v) |
358 | inline SV *to_sv (UUID v) |
357 | { |
359 | { |
358 | char buf[128]; |
360 | char buf[128]; |
359 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
361 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
… | |
… | |
383 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
385 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
384 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
386 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
385 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
387 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
386 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
388 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
387 | |
389 | |
388 | inline void sv_to (SV *sv, facetile * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } |
390 | //inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
389 | inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } |
391 | inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } |
390 | |
392 | |
391 | template<class T> |
393 | template<class T> |
392 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
394 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
393 | |
395 | |
… | |
… | |
397 | inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); } |
399 | inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); } |
398 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
400 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
399 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
401 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
400 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
402 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
401 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
403 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
|
|
404 | |
|
|
405 | inline void sv_to (SV *sv, std::string &v) |
|
|
406 | { |
|
|
407 | STRLEN len; |
|
|
408 | char *data = SvPVbyte (sv, len); |
|
|
409 | v.assign (data, len); |
|
|
410 | } |
402 | |
411 | |
403 | inline void sv_to (SV *sv, UUID &v) |
412 | inline void sv_to (SV *sv, UUID &v) |
404 | { |
413 | { |
405 | unsigned int version; |
414 | unsigned int version; |
406 | |
415 | |
… | |
… | |
597 | perl = perl_alloc (); |
606 | perl = perl_alloc (); |
598 | perl_construct (perl); |
607 | perl_construct (perl); |
599 | |
608 | |
600 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
609 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
601 | |
610 | |
602 | char *argv[] = { |
611 | const char *argv[] = { |
603 | "", |
612 | "", |
604 | "-e" |
613 | "-e" |
605 | "use Event; use Coro;" // required for bootstrap |
614 | "use Event; use Coro;" // required for bootstrap |
606 | "cf->bootstrap;" // required for datadir :*> |
615 | "cf->bootstrap;" // required for datadir :*> |
607 | "unshift @INC, cf::datadir ();" |
616 | "unshift @INC, cf::datadir ();" |
608 | "require cf;" |
617 | "require cf;" |
609 | }; |
618 | }; |
610 | |
619 | |
611 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
620 | if (perl_parse (perl, xs_init, 2, (char **)argv, (char **)NULL) |
|
|
621 | || perl_run (perl)) |
612 | { |
622 | { |
613 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
623 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
614 | exit (EXIT_FAILURE); |
624 | exit (EXIT_FAILURE); |
615 | } |
625 | } |
616 | |
626 | |
… | |
… | |
1041 | # define const_iv(name) { # name, (IV)name }, |
1051 | # define const_iv(name) { # name, (IV)name }, |
1042 | const_iv (llevError) |
1052 | const_iv (llevError) |
1043 | const_iv (llevInfo) |
1053 | const_iv (llevInfo) |
1044 | const_iv (llevDebug) |
1054 | const_iv (llevDebug) |
1045 | const_iv (llevMonster) |
1055 | const_iv (llevMonster) |
|
|
1056 | |
|
|
1057 | const_iv (Map0Cmd) |
|
|
1058 | const_iv (Map1Cmd) |
|
|
1059 | const_iv (Map1aCmd) |
|
|
1060 | |
|
|
1061 | const_iv (MAP_CLIENT_X) |
|
|
1062 | const_iv (MAP_CLIENT_Y) |
1046 | |
1063 | |
1047 | const_iv (MAX_TIME) |
1064 | const_iv (MAX_TIME) |
1048 | const_iv (PLAYER) |
1065 | const_iv (PLAYER) |
1049 | const_iv (TRANSPORT) |
1066 | const_iv (TRANSPORT) |
1050 | const_iv (ROD) |
1067 | const_iv (ROD) |
… | |
… | |
1585 | { |
1602 | { |
1586 | // reattach to all attachable objects in the game. |
1603 | // reattach to all attachable objects in the game. |
1587 | for_all_clients (ns) |
1604 | for_all_clients (ns) |
1588 | ns->reattach (); |
1605 | ns->reattach (); |
1589 | |
1606 | |
1590 | for_all_players (pl) |
|
|
1591 | pl->reattach (); |
|
|
1592 | |
|
|
1593 | //TODO |
|
|
1594 | //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i) |
|
|
1595 | // i->second->reattach (); |
|
|
1596 | |
|
|
1597 | for_all_objects (op) |
1607 | for_all_objects (op) |
1598 | op->reattach (); |
1608 | op->reattach (); |
1599 | } |
1609 | } |
1600 | |
1610 | |
1601 | NV floor (NV x) |
1611 | NV floor (NV x) |
… | |
… | |
1641 | void |
1651 | void |
1642 | sub_generation_inc () |
1652 | sub_generation_inc () |
1643 | CODE: |
1653 | CODE: |
1644 | PL_sub_generation++; |
1654 | PL_sub_generation++; |
1645 | |
1655 | |
1646 | char * |
1656 | const char * |
1647 | mapdir () |
1657 | mapdir () |
1648 | PROTOTYPE: |
1658 | PROTOTYPE: |
1649 | ALIAS: |
1659 | ALIAS: |
1650 | mapdir = 0 |
1660 | mapdir = 0 |
1651 | uniquedir = 1 |
1661 | uniquedir = 1 |
… | |
… | |
1736 | else |
1746 | else |
1737 | XSRETURN_UNDEF; |
1747 | XSRETURN_UNDEF; |
1738 | OUTPUT: RETVAL |
1748 | OUTPUT: RETVAL |
1739 | |
1749 | |
1740 | bool |
1750 | bool |
1741 | load_regions (const char *filename) |
1751 | load_resource_file (const char *filename) |
1742 | CODE: |
|
|
1743 | RETVAL = loader_region ().load (filename); |
|
|
1744 | OUTPUT: RETVAL |
|
|
1745 | |
1752 | |
1746 | MODULE = cf PACKAGE = cf::attachable |
1753 | MODULE = cf PACKAGE = cf::attachable |
1747 | |
1754 | |
1748 | int |
1755 | int |
1749 | valid (SV *obj) |
1756 | valid (SV *obj) |
… | |
… | |
1767 | #object *mortals (U32 index) |
1774 | #object *mortals (U32 index) |
1768 | # CODE: |
1775 | # CODE: |
1769 | # RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0; |
1776 | # RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0; |
1770 | # OUTPUT: RETVAL |
1777 | # OUTPUT: RETVAL |
1771 | |
1778 | |
1772 | INCLUDE: $PERL genacc attachable ../include/cfperl.h | |
1779 | INCLUDE: $PERL $srcdir/genacc attachable ../include/cfperl.h | |
1773 | |
1780 | |
1774 | MODULE = cf PACKAGE = cf::global |
1781 | MODULE = cf PACKAGE = cf::global |
1775 | |
1782 | |
1776 | int invoke (SV *klass, int event, ...) |
1783 | int invoke (SV *klass, int event, ...) |
1777 | CODE: |
1784 | CODE: |
… | |
… | |
1781 | RETVAL = gbl_ev.invoke ((event_type)event, ARG_AV (av), DT_END); |
1788 | RETVAL = gbl_ev.invoke ((event_type)event, ARG_AV (av), DT_END); |
1782 | OUTPUT: RETVAL |
1789 | OUTPUT: RETVAL |
1783 | |
1790 | |
1784 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1791 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1785 | |
1792 | |
1786 | INCLUDE: $PERL genacc object ../include/object.h | |
1793 | INCLUDE: $PERL $srcdir/genacc object ../include/object.h | |
1787 | |
1794 | |
1788 | int invoke (object *op, int event, ...) |
1795 | int invoke (object *op, int event, ...) |
1789 | CODE: |
1796 | CODE: |
1790 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1797 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1791 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1798 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
… | |
… | |
1855 | object *find_marked_object (object *op) |
1862 | object *find_marked_object (object *op) |
1856 | |
1863 | |
1857 | int need_identify (object *obj); |
1864 | int need_identify (object *obj); |
1858 | |
1865 | |
1859 | int apply_shop_mat (object *shop_mat, object *op); |
1866 | int apply_shop_mat (object *shop_mat, object *op); |
|
|
1867 | |
|
|
1868 | int move_player (object *op, int dir) |
|
|
1869 | CODE: |
|
|
1870 | RETVAL = move_player (op, dir); |
|
|
1871 | OUTPUT: |
|
|
1872 | RETVAL |
1860 | |
1873 | |
1861 | int move (object *op, int dir, object *originator = op) |
1874 | int move (object *op, int dir, object *originator = op) |
1862 | CODE: |
1875 | CODE: |
1863 | RETVAL = move_ob (op, dir, originator); |
1876 | RETVAL = move_ob (op, dir, originator); |
1864 | OUTPUT: |
1877 | OUTPUT: |
… | |
… | |
2065 | |
2078 | |
2066 | int command_summon (object *op, char *params) |
2079 | int command_summon (object *op, char *params) |
2067 | |
2080 | |
2068 | int command_arrest (object *op, char *params) |
2081 | int command_arrest (object *op, char *params) |
2069 | |
2082 | |
2070 | int command_kick (object *op, char *params) |
|
|
2071 | |
|
|
2072 | int command_banish (object *op, char *params) |
|
|
2073 | |
|
|
2074 | |
2083 | |
2075 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2084 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2076 | |
2085 | |
2077 | INCLUDE: $PERL genacc player ../include/player.h | |
2086 | INCLUDE: $PERL $srcdir/genacc player ../include/player.h | |
2078 | |
2087 | |
2079 | int invoke (player *pl, int event, ...) |
2088 | int invoke (player *pl, int event, ...) |
2080 | CODE: |
2089 | CODE: |
2081 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
2090 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
2082 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2091 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
… | |
… | |
2157 | RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); |
2166 | RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); |
2158 | OUTPUT: RETVAL |
2167 | OUTPUT: RETVAL |
2159 | |
2168 | |
2160 | SV *registry (maptile *map) |
2169 | SV *registry (maptile *map) |
2161 | |
2170 | |
2162 | INCLUDE: $PERL genacc maptile ../include/map.h | |
2171 | INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h | |
2163 | |
2172 | |
2164 | void |
2173 | void |
2165 | maptile::instantiate () |
2174 | maptile::instantiate () |
2166 | |
2175 | |
2167 | maptile *new () |
2176 | maptile *new () |
… | |
… | |
2440 | PROTOTYPE: |
2449 | PROTOTYPE: |
2441 | CODE: |
2450 | CODE: |
2442 | RETVAL = first_archetype; |
2451 | RETVAL = first_archetype; |
2443 | OUTPUT: RETVAL |
2452 | OUTPUT: RETVAL |
2444 | |
2453 | |
2445 | INCLUDE: $PERL genacc archetype ../include/object.h | |
2454 | INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | |
2446 | |
2455 | |
2447 | MODULE = cf PACKAGE = cf::party |
2456 | MODULE = cf PACKAGE = cf::party |
2448 | |
2457 | |
2449 | partylist *first () |
2458 | partylist *first () |
2450 | PROTOTYPE: |
2459 | PROTOTYPE: |
2451 | CODE: |
2460 | CODE: |
2452 | RETVAL = get_firstparty (); |
2461 | RETVAL = get_firstparty (); |
2453 | OUTPUT: RETVAL |
2462 | OUTPUT: RETVAL |
2454 | |
2463 | |
2455 | INCLUDE: $PERL genacc partylist ../include/player.h | |
2464 | INCLUDE: $PERL $srcdir/genacc partylist ../include/player.h | |
2456 | |
2465 | |
2457 | MODULE = cf PACKAGE = cf::region |
2466 | MODULE = cf PACKAGE = cf::region |
2458 | |
2467 | |
2459 | void |
2468 | void |
2460 | list () |
2469 | list () |
… | |
… | |
2472 | PROTOTYPE: $ |
2481 | PROTOTYPE: $ |
2473 | CODE: |
2482 | CODE: |
2474 | RETVAL = region::find_fuzzy (name); |
2483 | RETVAL = region::find_fuzzy (name); |
2475 | OUTPUT: RETVAL |
2484 | OUTPUT: RETVAL |
2476 | |
2485 | |
2477 | INCLUDE: $PERL genacc region ../include/map.h | |
2486 | INCLUDE: $PERL $srcdir/genacc region ../include/map.h | |
2478 | |
2487 | |
2479 | MODULE = cf PACKAGE = cf::living |
2488 | MODULE = cf PACKAGE = cf::living |
2480 | |
2489 | |
2481 | INCLUDE: $PERL genacc living ../include/living.h | |
2490 | INCLUDE: $PERL $srcdir/genacc living ../include/living.h | |
2482 | |
2491 | |
2483 | MODULE = cf PACKAGE = cf::settings |
2492 | MODULE = cf PACKAGE = cf::settings |
2484 | |
2493 | |
2485 | INCLUDE: $PERL genacc Settings ../include/global.h | |
2494 | INCLUDE: $PERL $srcdir/genacc Settings ../include/global.h | |
2486 | |
2495 | |
2487 | MODULE = cf PACKAGE = cf::client |
2496 | MODULE = cf PACKAGE = cf::client |
2488 | |
2497 | |
2489 | INCLUDE: $PERL genacc client ../include/client.h | |
2498 | INCLUDE: $PERL $srcdir/genacc client ../include/client.h | |
2490 | |
2499 | |
2491 | int invoke (client *ns, int event, ...) |
2500 | int invoke (client *ns, int event, ...) |
2492 | CODE: |
2501 | CODE: |
2493 | if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT"); |
2502 | if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT"); |
2494 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2503 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
… | |
… | |
2513 | char *buf = SvPVbyte (packet, len); |
2522 | char *buf = SvPVbyte (packet, len); |
2514 | |
2523 | |
2515 | THIS->send_packet (buf, len); |
2524 | THIS->send_packet (buf, len); |
2516 | } |
2525 | } |
2517 | |
2526 | |
|
|
2527 | MODULE = cf PACKAGE = cf::face PREFIX = face_ |
|
|
2528 | |
|
|
2529 | INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | |
|
|
2530 | |
|
|
2531 | faceidx face_find (const char *name, faceidx defidx = 0) |
|
|
2532 | |
|
|
2533 | faceidx alloc (const char *name) |
|
|
2534 | CODE: |
|
|
2535 | { |
|
|
2536 | do |
|
|
2537 | { |
|
|
2538 | RETVAL = faces.size (); |
|
|
2539 | faces.resize (RETVAL + 1); |
|
|
2540 | } |
|
|
2541 | while (!RETVAL); // crude way to leave index 0 |
|
|
2542 | |
|
|
2543 | faces [RETVAL].name = name; |
|
|
2544 | facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); |
|
|
2545 | |
|
|
2546 | if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; |
|
|
2547 | if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; |
|
|
2548 | } |
|
|
2549 | OUTPUT: RETVAL |
|
|
2550 | |
|
|
2551 | void set (faceidx idx, int visibility, int magicmap) |
|
|
2552 | CODE: |
|
|
2553 | faceinfo *f = face_info (idx); |
|
|
2554 | assert (f); |
|
|
2555 | f->visibility = visibility; |
|
|
2556 | f->magicmap = magicmap; |
|
|
2557 | |
|
|
2558 | void set_smooth (faceidx idx, faceidx smooth) |
|
|
2559 | CODE: |
|
|
2560 | faceinfo *f = face_info (idx); |
|
|
2561 | assert (f); |
|
|
2562 | f->smooth = smooth; |
|
|
2563 | |
|
|
2564 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
|
|
2565 | CODE: |
|
|
2566 | facedata *d = face_data (idx, faceset); |
|
|
2567 | assert (d); |
|
|
2568 | sv_to (data, d->data); |
|
|
2569 | STRLEN clen; |
|
|
2570 | char *cdata = SvPVbyte (chksum, clen); |
|
|
2571 | memcpy (d->chksum, cdata, min (CHKSUM_SIZE, clen)); |
|
|
2572 | |
|
|
2573 | void invalidate (faceidx idx) |
|
|
2574 | CODE: |
|
|
2575 | for_all_clients (ns) |
|
|
2576 | ns->faces_sent [idx] = false; |
|
|
2577 | |
|
|
2578 | void invalidate_all () |
|
|
2579 | CODE: |
|
|
2580 | for_all_clients (ns) |
|
|
2581 | ns->faces_sent.reset (); |
|
|
2582 | |