… | |
… | |
40 | |
40 | |
41 | #include "perlxsi.c" |
41 | #include "perlxsi.c" |
42 | |
42 | |
43 | extern sint64 *levels; // the experience table |
43 | extern sint64 *levels; // the experience table |
44 | |
44 | |
45 | typedef object object_ornull; |
45 | typedef object object_ornull; |
46 | typedef mapstruct mapstruct_ornull; |
46 | typedef maptile maptile_ornull; |
47 | |
47 | |
48 | typedef double val64; |
48 | typedef double val64; |
49 | #define newSVval64 newSVnv |
49 | #define newSVval64 newSVnv |
50 | #define SvVAL64 SvNV |
50 | #define SvVAL64 SvNV |
51 | |
51 | |
… | |
… | |
55 | |
55 | |
56 | static HV *obj_cache; |
56 | static HV *obj_cache; |
57 | static PerlInterpreter *perl; |
57 | static PerlInterpreter *perl; |
58 | |
58 | |
59 | static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; |
59 | static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; |
60 | |
|
|
61 | #define PUSHcfapi(type,value) PUSHs (sv_2mortal (newSVcfapi (CFAPI_ ## type, (value)))) |
|
|
62 | #define PUSHcfapi_va(type,ctype) PUSHcfapi (type, va_arg (args, ctype)) |
|
|
63 | #define PUSH_OB PUSHcfapi_va(POBJECT, object *) |
|
|
64 | #define PUSH_PL PUSHcfapi_va(PPLAYER, player *) |
|
|
65 | #define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *) |
|
|
66 | #define PUSH_PV PUSHcfapi_va(STRING, const char *) |
|
|
67 | #define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int)))) |
|
|
68 | |
60 | |
69 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
70 | |
62 | |
71 | static SV * |
63 | static SV * |
72 | newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) |
64 | newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) |
… | |
… | |
177 | inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
169 | inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
178 | inline SV *to_sv (float v) { return newSVnv (v); } |
170 | inline SV *to_sv (float v) { return newSVnv (v); } |
179 | inline SV *to_sv (double v) { return newSVnv (v); } |
171 | inline SV *to_sv (double v) { return newSVnv (v); } |
180 | inline SV *to_sv (player * v) { return newSVattachable (v, "cf::player::wrap"); } |
172 | inline SV *to_sv (player * v) { return newSVattachable (v, "cf::player::wrap"); } |
181 | inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); } |
173 | inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); } |
182 | inline SV *to_sv (mapstruct * v) { return newSVattachable (v, "cf::map::wrap"); } |
174 | inline SV *to_sv (maptile * v) { return newSVattachable (v, "cf::map::wrap"); } |
183 | inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); } |
175 | inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); } |
184 | inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); } |
176 | inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); } |
185 | inline SV *to_sv (region * v) { return newSVptr (v, "cf::region::wrap"); } |
177 | inline SV *to_sv (region * v) { return newSVptr (v, "cf::region::wrap"); } |
186 | inline SV *to_sv (living * v) { return newSVptr (v, "cf::living::wrap"); } |
178 | inline SV *to_sv (living * v) { return newSVptr (v, "cf::living::wrap"); } |
187 | |
179 | |
… | |
… | |
190 | |
182 | |
191 | //TODO: |
183 | //TODO: |
192 | inline SV *to_sv (New_Face * v) { return to_sv (v->name); } |
184 | inline SV *to_sv (New_Face * v) { return to_sv (v->name); } |
193 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
185 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
194 | |
186 | |
|
|
187 | inline SV *to_sv (UUID v) { |
|
|
188 | char buf[128]; |
|
|
189 | snprintf (buf, 128, "<1,%llx>", (unsigned long long)v.seq + UUID_SKIP * 2); |
|
|
190 | return newSVpv (buf, 0); |
|
|
191 | } |
|
|
192 | |
195 | inline void sv_to (SV *sv, shstr &v) { v = SvPV_nolen (sv); } |
193 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
196 | inline void sv_to (SV *sv, char * &v) { free (v); v = strdup (SvPV_nolen (sv)); } //TODO: verify that all simple pointers are strdup-managed |
194 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } //TODO: verify that all simple pointers are strdup-managed |
197 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
195 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
198 | inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
196 | inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
199 | inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
197 | inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
200 | inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } |
198 | inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } |
201 | inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } |
199 | inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } |
… | |
… | |
208 | inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
206 | inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
209 | inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
207 | inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
210 | inline void sv_to (SV *sv, player * &v) { v = (player *)SvPTR_ornull (sv, "cf::player"); } |
208 | inline void sv_to (SV *sv, player * &v) { v = (player *)SvPTR_ornull (sv, "cf::player"); } |
211 | inline void sv_to (SV *sv, object * &v) { v = (object *)SvPTR_ornull (sv, "cf::object"); } |
209 | inline void sv_to (SV *sv, object * &v) { v = (object *)SvPTR_ornull (sv, "cf::object"); } |
212 | inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)SvPTR_ornull (sv, "cf::arch"); } |
210 | inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)SvPTR_ornull (sv, "cf::arch"); } |
213 | inline void sv_to (SV *sv, mapstruct * &v) { v = (mapstruct *)SvPTR_ornull (sv, "cf::map"); } |
211 | inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)SvPTR_ornull (sv, "cf::map"); } |
214 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
212 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
215 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
213 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
216 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
214 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
217 | |
215 | |
218 | inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO |
216 | inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO |
… | |
… | |
221 | template<class T> |
219 | template<class T> |
222 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
220 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
223 | |
221 | |
224 | template<int N> |
222 | template<int N> |
225 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
223 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
|
|
224 | |
|
|
225 | inline void sv_to (SV *sv, UUID &v) { |
|
|
226 | char *sv_str = SvOK (sv) ? SvPV_nolen (sv) : 0; |
|
|
227 | unsigned int version = 0; |
|
|
228 | unsigned long long seq = 0; |
|
|
229 | |
|
|
230 | if (!sv_str) |
|
|
231 | return; |
|
|
232 | |
|
|
233 | if (2 == sscanf (sv_str, "<%d.%llx>", &version, &seq) && version == 1) |
|
|
234 | { |
|
|
235 | v.seq = seq; |
|
|
236 | } |
|
|
237 | |
|
|
238 | return; |
|
|
239 | } |
226 | |
240 | |
227 | static SV * |
241 | static SV * |
228 | newSVdt_va (va_list &ap, data_type type) |
242 | newSVdt_va (va_list &ap, data_type type) |
229 | { |
243 | { |
230 | SV *sv; |
244 | SV *sv; |
… | |
… | |
262 | sv = to_sv (va_arg (ap, object *)); |
276 | sv = to_sv (va_arg (ap, object *)); |
263 | break; |
277 | break; |
264 | |
278 | |
265 | case DT_MAP: |
279 | case DT_MAP: |
266 | // va_arg (object *) when void * is passed is an XSI extension |
280 | // va_arg (object *) when void * is passed is an XSI extension |
267 | sv = to_sv (va_arg (ap, mapstruct *)); |
281 | sv = to_sv (va_arg (ap, maptile *)); |
268 | break; |
282 | break; |
269 | |
283 | |
270 | case DT_PLAYER: |
284 | case DT_PLAYER: |
271 | sv = to_sv (va_arg (ap, player *)); |
285 | sv = to_sv (va_arg (ap, player *)); |
272 | break; |
286 | break; |
… | |
… | |
349 | { |
363 | { |
350 | if (cb) |
364 | if (cb) |
351 | if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) |
365 | if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) |
352 | INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); |
366 | INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); |
353 | else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) |
367 | else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) |
354 | INVOKE_MAP (DESTROY, static_cast<mapstruct *>(this)); |
368 | INVOKE_MAP (DESTROY, static_cast<maptile *>(this)); |
355 | |
369 | |
356 | // disconnect Perl from C, to avoid crashes |
370 | // disconnect Perl from C, to avoid crashes |
357 | sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); |
371 | sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); |
358 | |
372 | |
359 | // clear the perl hash, might or might not be a good idea |
373 | // clear the perl hash, might or might not be a good idea |
… | |
… | |
487 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
501 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
488 | FREETMPS; |
502 | FREETMPS; |
489 | LEAVE; |
503 | LEAVE; |
490 | } |
504 | } |
491 | |
505 | |
|
|
506 | char *object_freezer::as_string () |
|
|
507 | { |
|
|
508 | dSP; |
|
|
509 | ENTER; |
|
|
510 | SAVETMPS; |
|
|
511 | PUSHMARK (SP); |
|
|
512 | EXTEND (SP, 3); |
|
|
513 | PUSHs (sv_2mortal (newRV_noinc (newSVpvn ((char *)linearise (), size ())))); |
|
|
514 | PUSHs (sv_2mortal (newRV_inc ((SV *)av))); |
|
|
515 | PUTBACK; |
|
|
516 | |
|
|
517 | char *res = call_pv ("cf::object_freezer_as_string", G_SCALAR | G_EVAL) > 0 |
|
|
518 | ? strdup (SvPVbyte_nolen (POPs)) |
|
|
519 | : strdup ("[fatal error]"); |
|
|
520 | |
|
|
521 | FREETMPS; |
|
|
522 | LEAVE; |
|
|
523 | |
|
|
524 | return res; |
|
|
525 | } |
|
|
526 | |
492 | int fprintf (object_freezer &freezer, const char *format, ...) |
527 | int fprintf (object_freezer &freezer, const char *format, ...) |
493 | { |
528 | { |
494 | va_list ap; |
529 | va_list ap; |
495 | |
530 | |
496 | va_start (ap, format); |
531 | va_start (ap, format); |
… | |
… | |
505 | |
540 | |
506 | int fputs (const char *s, object_freezer &freezer) |
541 | int fputs (const char *s, object_freezer &freezer) |
507 | { |
542 | { |
508 | freezer.add (s); |
543 | freezer.add (s); |
509 | } |
544 | } |
|
|
545 | |
|
|
546 | static const char thawer_eof[] = "\n\n\n\0\0\0"; |
510 | |
547 | |
511 | object_thawer::object_thawer (const char *filename) |
548 | object_thawer::object_thawer (const char *filename) |
512 | { |
549 | { |
513 | static const char eof[] = "\n\n\n\0\0\0"; |
550 | static const char eof[] = "\n\n\n\0\0\0"; |
514 | |
551 | |
… | |
… | |
552 | |
589 | |
553 | PUTBACK; |
590 | PUTBACK; |
554 | FREETMPS; |
591 | FREETMPS; |
555 | LEAVE; |
592 | LEAVE; |
556 | } |
593 | } |
|
|
594 | } |
|
|
595 | |
|
|
596 | object_thawer::object_thawer (const char *data, AV *perlav) |
|
|
597 | { |
|
|
598 | av = perlav; |
|
|
599 | text = newSVpv (data, 0); |
|
|
600 | sv_catpv (text, thawer_eof); |
|
|
601 | line = SvPVbyte_nolen (text); |
557 | } |
602 | } |
558 | |
603 | |
559 | void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) |
604 | void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) |
560 | { |
605 | { |
561 | if (!av || oid < 0) // this is actually an error of sorts |
606 | if (!av || oid < 0) // this is actually an error of sorts |
… | |
… | |
939 | |
984 | |
940 | AV *callbacks = 0; |
985 | AV *callbacks = 0; |
941 | |
986 | |
942 | object *op; |
987 | object *op; |
943 | player *pl; |
988 | player *pl; |
944 | mapstruct *map; |
989 | maptile *map; |
945 | |
990 | |
946 | // callback call ordering is: |
991 | // callback call ordering is: |
947 | // 1. per-object callback (NYI) |
992 | // 1. per-object callback (NYI) |
948 | // 2. per-class object |
993 | // 2. per-class object |
949 | // 2a. per-type callback |
994 | // 2a. per-type callback |
… | |
… | |
999 | break; |
1044 | break; |
1000 | |
1045 | |
1001 | case KLASS_MAP: |
1046 | case KLASS_MAP: |
1002 | dt = (data_type) va_arg (ap, int); |
1047 | dt = (data_type) va_arg (ap, int); |
1003 | assert (("first argument must be of type object", dt == DT_MAP)); |
1048 | assert (("first argument must be of type object", dt == DT_MAP)); |
1004 | map = va_arg (ap, mapstruct *); |
1049 | map = va_arg (ap, maptile *); |
1005 | |
1050 | |
1006 | if (map->cb) |
1051 | if (map->cb) |
1007 | gather_callbacks (callbacks, map->cb, event); |
1052 | gather_callbacks (callbacks, map->cb, event); |
1008 | |
1053 | |
1009 | gather_callbacks (callbacks, cb_map, event); |
1054 | gather_callbacks (callbacks, cb_map, event); |
… | |
… | |
1089 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1134 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1090 | |
1135 | |
1091 | BOOT: |
1136 | BOOT: |
1092 | { |
1137 | { |
1093 | HV *stash = gv_stashpv ("cf", 1); |
1138 | HV *stash = gv_stashpv ("cf", 1); |
|
|
1139 | |
|
|
1140 | newCONSTSUB (stash, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1094 | |
1141 | |
1095 | static const struct { |
1142 | static const struct { |
1096 | const char *name; |
1143 | const char *name; |
1097 | IV iv; |
1144 | IV iv; |
1098 | } *civ, const_iv[] = { |
1145 | } *civ, const_iv[] = { |
… | |
… | |
1391 | const_iv (NDI_MAX_COLOR) |
1438 | const_iv (NDI_MAX_COLOR) |
1392 | const_iv (NDI_COLOR_MASK) |
1439 | const_iv (NDI_COLOR_MASK) |
1393 | const_iv (NDI_UNIQUE) |
1440 | const_iv (NDI_UNIQUE) |
1394 | const_iv (NDI_ALL) |
1441 | const_iv (NDI_ALL) |
1395 | |
1442 | |
|
|
1443 | const_iv (UPD_LOCATION) |
|
|
1444 | const_iv (UPD_FLAGS) |
|
|
1445 | const_iv (UPD_WEIGHT) |
|
|
1446 | const_iv (UPD_FACE) |
|
|
1447 | const_iv (UPD_NAME) |
|
|
1448 | const_iv (UPD_ANIM) |
|
|
1449 | const_iv (UPD_ANIMSPEED) |
|
|
1450 | const_iv (UPD_NROF) |
|
|
1451 | |
|
|
1452 | const_iv (UPD_SP_MANA) |
|
|
1453 | const_iv (UPD_SP_GRACE) |
|
|
1454 | const_iv (UPD_SP_DAMAGE) |
|
|
1455 | |
1396 | const_iv (F_APPLIED) |
1456 | const_iv (F_APPLIED) |
1397 | const_iv (F_LOCATION) |
1457 | const_iv (F_LOCATION) |
1398 | const_iv (F_UNPAID) |
1458 | const_iv (F_UNPAID) |
1399 | const_iv (F_MAGIC) |
1459 | const_iv (F_MAGIC) |
1400 | const_iv (F_CURSED) |
1460 | const_iv (F_CURSED) |
… | |
… | |
1613 | { |
1673 | { |
1614 | // reattach to all attachable objects in the game. |
1674 | // reattach to all attachable objects in the game. |
1615 | for (player *pl = first_player; pl; pl = pl->next) |
1675 | for (player *pl = first_player; pl; pl = pl->next) |
1616 | reattach (pl); |
1676 | reattach (pl); |
1617 | |
1677 | |
1618 | for (mapstruct *map = first_map; map; map = map->next) |
1678 | for (maptile *map = first_map; map; map = map->next) |
1619 | reattach (map); |
1679 | reattach (map); |
1620 | |
1680 | |
1621 | for (object *op = objects; op; op = op->next) |
1681 | for (object *op = object::first; op; op = op->next) |
1622 | reattach (op); |
1682 | reattach (op); |
1623 | } |
1683 | } |
1624 | |
1684 | |
1625 | NV floor (NV x) |
1685 | NV floor (NV x) |
1626 | |
1686 | |
… | |
… | |
1739 | OUTPUT: |
1799 | OUTPUT: |
1740 | RETVAL |
1800 | RETVAL |
1741 | |
1801 | |
1742 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1802 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1743 | |
1803 | |
|
|
1804 | INCLUDE: $PERL genacc object ../include/object.h | |
|
|
1805 | |
1744 | int invoke (object *op, int event, ...) |
1806 | int invoke (object *op, int event, ...) |
1745 | CODE: |
1807 | CODE: |
1746 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1808 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1747 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1809 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1748 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1810 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
… | |
… | |
1753 | CODE: |
1815 | CODE: |
1754 | RETVAL = registry_of (op); |
1816 | RETVAL = registry_of (op); |
1755 | OUTPUT: |
1817 | OUTPUT: |
1756 | RETVAL |
1818 | RETVAL |
1757 | |
1819 | |
1758 | INCLUDE: $PERL genacc object ../include/object.h | |
1820 | void mortals () |
|
|
1821 | PPCODE: |
|
|
1822 | EXTEND (SP, object::mortals.size ()); |
|
|
1823 | for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) |
|
|
1824 | PUSHs (to_sv (*i)); |
|
|
1825 | |
|
|
1826 | object *first () |
|
|
1827 | CODE: |
|
|
1828 | RETVAL = object::first; |
|
|
1829 | OUTPUT: RETVAL |
1759 | |
1830 | |
1760 | # missing properties |
1831 | # missing properties |
1761 | |
1832 | |
1762 | int flag (object *op, int flag, int value = 1) |
1833 | int flag (object *op, int flag, int value = 1) |
1763 | PROTOTYPE: $$;$ |
1834 | PROTOTYPE: $$;$ |
… | |
… | |
1790 | object *o; |
1861 | object *o; |
1791 | for (o = obj->inv; o; o = o->below) |
1862 | for (o = obj->inv; o; o = o->below) |
1792 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
1863 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
1793 | } |
1864 | } |
1794 | |
1865 | |
|
|
1866 | object *find_best_object_match (object *op, const char *match) |
|
|
1867 | |
|
|
1868 | object *find_marked_object (object *op) |
|
|
1869 | |
1795 | int cf_object_get_resistance (object *op, int rtype) |
1870 | int cf_object_get_resistance (object *op, int rtype) |
1796 | ALIAS: resistance = 0 |
1871 | ALIAS: resistance = 0 |
1797 | |
1872 | |
1798 | int need_identify (const object *obj); |
1873 | int need_identify (const object *obj); |
1799 | |
1874 | |
… | |
… | |
1815 | |
1890 | |
1816 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
1891 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
1817 | |
1892 | |
1818 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
1893 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
1819 | |
1894 | |
1820 | int cf_object_change_map (object *op, int x, int y, mapstruct *map) |
1895 | int cf_object_change_map (object *op, int x, int y, maptile *map) |
1821 | |
1896 | |
1822 | object *cf_object_clone (object *op, int clonetype = 0) |
1897 | object *cf_object_clone (object *op, int clonetype = 0) |
1823 | |
1898 | |
1824 | int cf_object_pay_item (object *op, object *buyer) |
1899 | int cf_object_pay_item (object *op, object *buyer) |
1825 | |
1900 | |
… | |
… | |
1857 | |
1932 | |
1858 | object *cf_object_insert_object (object *op, object *container) |
1933 | object *cf_object_insert_object (object *op, object *container) |
1859 | |
1934 | |
1860 | object *cf_object_insert_in_ob (object *ob, object *where) |
1935 | object *cf_object_insert_in_ob (object *ob, object *where) |
1861 | |
1936 | |
1862 | int cf_object_teleport (object *op, mapstruct *map, int x, int y) |
1937 | int cf_object_teleport (object *op, maptile *map, int x, int y) |
1863 | |
1938 | |
1864 | void cf_object_update (object *op, int flags) |
1939 | void cf_object_update (object *op, int flags) |
1865 | |
1940 | |
1866 | void cf_object_pickup (object *op, object *what) |
1941 | void cf_object_pickup (object *op, object *what) |
1867 | |
1942 | |
… | |
… | |
1877 | |
1952 | |
1878 | void push_button (object *op); |
1953 | void push_button (object *op); |
1879 | |
1954 | |
1880 | void use_trigger (object *op); |
1955 | void use_trigger (object *op); |
1881 | |
1956 | |
1882 | void add_button_link (object *button, mapstruct *map, int connected); |
1957 | void add_button_link (object *button, maptile *map, int connected); |
1883 | |
1958 | |
1884 | void remove_button_link (object *op); |
1959 | void remove_button_link (object *op); |
1885 | |
1960 | |
1886 | void |
1961 | void |
1887 | cf_object_set_resistance (object *op, int rtype, int val) |
1962 | cf_object_set_resistance (object *op, int rtype, int val) |
… | |
… | |
1905 | CODE: |
1980 | CODE: |
1906 | RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); |
1981 | RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); |
1907 | OUTPUT: |
1982 | OUTPUT: |
1908 | RETVAL |
1983 | RETVAL |
1909 | |
1984 | |
1910 | object *insert_ob_in_map_at (object *ob, mapstruct *where, object_ornull *orig, int flag, int x, int y) |
1985 | object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) |
1911 | PROTOTYPE: $$$$$$ |
1986 | PROTOTYPE: $$$$$$ |
1912 | CODE: |
1987 | CODE: |
1913 | { |
1988 | { |
1914 | int unused_type; |
1989 | int unused_type; |
1915 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1990 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
… | |
… | |
1953 | bool on_same_map_as (object *ob, object *other) |
2028 | bool on_same_map_as (object *ob, object *other) |
1954 | CODE: |
2029 | CODE: |
1955 | RETVAL = on_same_map (ob, other); |
2030 | RETVAL = on_same_map (ob, other); |
1956 | OUTPUT: RETVAL |
2031 | OUTPUT: RETVAL |
1957 | |
2032 | |
1958 | char * |
2033 | const char * |
1959 | base_name (object *ob, int plural) |
2034 | base_name (object *op, int plural = op->nrof > 1) |
1960 | CODE: |
2035 | CODE: |
1961 | RETVAL = cf_query_base_name (ob, plural); |
2036 | RETVAL = query_base_name (op, plural); |
1962 | OUTPUT: RETVAL |
2037 | OUTPUT: RETVAL |
1963 | |
2038 | |
1964 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
2039 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1965 | |
2040 | |
1966 | player *player (object *op) |
2041 | player *player (object *op) |
… | |
… | |
1985 | |
2060 | |
1986 | void cf_player_set_party (object *op, partylist *party) |
2061 | void cf_player_set_party (object *op, partylist *party) |
1987 | |
2062 | |
1988 | void kill_player (object *op) |
2063 | void kill_player (object *op) |
1989 | |
2064 | |
|
|
2065 | void esrv_update_item (object *op, int what, object *item) |
|
|
2066 | C_ARGS: what, op, item |
|
|
2067 | |
|
|
2068 | void clear_los (object *op) |
|
|
2069 | |
|
|
2070 | int command_reset (object *op, char *params) |
|
|
2071 | |
|
|
2072 | int command_teleport (object *op, char *params) |
|
|
2073 | |
|
|
2074 | int command_summon (object *op, char *params) |
|
|
2075 | |
|
|
2076 | int command_arrest (object *op, char *params) |
|
|
2077 | |
|
|
2078 | int command_kick (object *op, char *params) |
|
|
2079 | |
|
|
2080 | int command_banish (object *op, char *params) |
|
|
2081 | |
|
|
2082 | |
1990 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2083 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
|
|
2084 | |
|
|
2085 | INCLUDE: $PERL genacc player ../include/newserver.h ../include/player.h | |
|
|
2086 | |
|
|
2087 | char * |
|
|
2088 | client (player *pl) |
|
|
2089 | CODE: |
|
|
2090 | RETVAL = pl->socket.client; |
|
|
2091 | OUTPUT: |
|
|
2092 | RETVAL |
|
|
2093 | |
|
|
2094 | char * |
|
|
2095 | host (player *pl) |
|
|
2096 | CODE: |
|
|
2097 | RETVAL = pl->socket.host; |
|
|
2098 | OUTPUT: |
|
|
2099 | RETVAL |
1991 | |
2100 | |
1992 | int invoke (player *pl, int event, ...) |
2101 | int invoke (player *pl, int event, ...) |
1993 | CODE: |
2102 | CODE: |
1994 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
2103 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
1995 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2104 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
… | |
… | |
2008 | |
2117 | |
2009 | void cf_player_move (player *pl, int dir) |
2118 | void cf_player_move (player *pl, int dir) |
2010 | |
2119 | |
2011 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2120 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2012 | |
2121 | |
2013 | # nonstandard |
|
|
2014 | object *ob (player *pl) |
|
|
2015 | CODE: |
|
|
2016 | RETVAL = pl->ob; |
|
|
2017 | OUTPUT: RETVAL |
|
|
2018 | |
|
|
2019 | player *first () |
2122 | player *first () |
2020 | CODE: |
2123 | CODE: |
2021 | RETVAL = first_player; |
2124 | RETVAL = first_player; |
2022 | OUTPUT: RETVAL |
2125 | OUTPUT: RETVAL |
2023 | |
2126 | |
… | |
… | |
2029 | bool |
2132 | bool |
2030 | cell_visible (player *pl, int dx, int dy) |
2133 | cell_visible (player *pl, int dx, int dy) |
2031 | CODE: |
2134 | CODE: |
2032 | RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2 |
2135 | RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2 |
2033 | && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]; |
2136 | && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]; |
2034 | OUTPUT: |
|
|
2035 | RETVAL |
|
|
2036 | |
|
|
2037 | char * |
|
|
2038 | client (player *pl) |
|
|
2039 | CODE: |
|
|
2040 | RETVAL = pl->socket.client; |
|
|
2041 | OUTPUT: |
|
|
2042 | RETVAL |
|
|
2043 | |
|
|
2044 | char * |
|
|
2045 | host (player *pl) |
|
|
2046 | CODE: |
|
|
2047 | RETVAL = pl->socket.host; |
|
|
2048 | OUTPUT: |
|
|
2049 | RETVAL |
|
|
2050 | |
|
|
2051 | char * |
|
|
2052 | killer (player *pl, char *killer = 0) |
|
|
2053 | CODE: |
|
|
2054 | if (killer) |
|
|
2055 | snprintf (pl->killer, sizeof (pl->killer), "%s", killer); |
|
|
2056 | RETVAL = pl->killer; |
|
|
2057 | OUTPUT: |
2137 | OUTPUT: |
2058 | RETVAL |
2138 | RETVAL |
2059 | |
2139 | |
2060 | void |
2140 | void |
2061 | buggy_mapscroll (player *pl, int value = 1) |
2141 | buggy_mapscroll (player *pl, int value = 1) |
… | |
… | |
2127 | OUTPUT: RETVAL |
2207 | OUTPUT: RETVAL |
2128 | |
2208 | |
2129 | |
2209 | |
2130 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2210 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2131 | |
2211 | |
2132 | mapstruct *first () |
2212 | maptile *first () |
2133 | PROTOTYPE: |
2213 | PROTOTYPE: |
2134 | CODE: |
2214 | CODE: |
2135 | RETVAL = first_map; |
2215 | RETVAL = first_map; |
2136 | OUTPUT: RETVAL |
2216 | OUTPUT: RETVAL |
2137 | |
2217 | |
2138 | int invoke (mapstruct *map, int event, ...) |
2218 | int invoke (maptile *map, int event, ...) |
2139 | CODE: |
2219 | CODE: |
2140 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2220 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2141 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2221 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2142 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2222 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2143 | RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); |
2223 | RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); |
2144 | OUTPUT: RETVAL |
2224 | OUTPUT: RETVAL |
2145 | |
2225 | |
2146 | SV *registry (mapstruct *map) |
2226 | SV *registry (maptile *map) |
2147 | CODE: |
2227 | CODE: |
2148 | RETVAL = registry_of (map); |
2228 | RETVAL = registry_of (map); |
2149 | OUTPUT: |
2229 | OUTPUT: |
2150 | RETVAL |
2230 | RETVAL |
2151 | |
2231 | |
2152 | INCLUDE: $PERL genacc mapstruct ../include/map.h | |
2232 | INCLUDE: $PERL genacc maptile ../include/map.h | |
2153 | |
2233 | |
2154 | mapstruct *new (int width, int height) |
2234 | maptile *new (int width, int height) |
2155 | PROTOTYPE: |
2235 | PROTOTYPE: |
2156 | CODE: |
2236 | CODE: |
2157 | { |
2237 | { |
2158 | RETVAL = get_empty_map (width, height); |
2238 | RETVAL = get_empty_map (width, height); |
2159 | } |
2239 | } |
2160 | OUTPUT: |
2240 | OUTPUT: |
2161 | RETVAL |
2241 | RETVAL |
2162 | |
2242 | |
2163 | void delete_map (mapstruct *map) |
2243 | void delete_map (maptile *map) |
2164 | |
2244 | |
2165 | void clean_tmp_map (mapstruct *map) |
2245 | void clean_tmp_map (maptile *map) |
2166 | |
2246 | |
2167 | void play_sound_map (mapstruct *map, int x, int y, int sound_num) |
2247 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2168 | |
2248 | |
2169 | mapstruct *tile_map (mapstruct *map, unsigned int dir) |
2249 | maptile *tile_map (maptile *map, unsigned int dir) |
2170 | CODE: |
2250 | CODE: |
2171 | RETVAL = dir < 4 ? map->tile_map [dir] : 0; |
2251 | RETVAL = dir < 4 ? map->tile_map [dir] : 0; |
2172 | OUTPUT: |
2252 | OUTPUT: |
2173 | RETVAL |
2253 | RETVAL |
2174 | |
2254 | |
2175 | char *tile_path (mapstruct *map, unsigned int dir) |
2255 | char *tile_path (maptile *map, unsigned int dir) |
2176 | CODE: |
2256 | CODE: |
2177 | if (dir >= 4) |
2257 | if (dir >= 4) |
2178 | XSRETURN_UNDEF; |
2258 | XSRETURN_UNDEF; |
2179 | RETVAL = map->tile_path [dir]; |
2259 | RETVAL = map->tile_path [dir]; |
2180 | OUTPUT: |
2260 | OUTPUT: |
2181 | RETVAL |
2261 | RETVAL |
2182 | |
2262 | |
2183 | mapstruct *ready_map_name (char *name, int flags = 0) |
2263 | maptile *ready_map_name (char *name, int flags = 0) |
2184 | PROTOTYPE: $;$ |
2264 | PROTOTYPE: $;$ |
2185 | ALIAS: |
2265 | ALIAS: |
2186 | find = 0 |
2266 | find = 0 |
2187 | get_map = 1 |
2267 | get_map = 1 |
2188 | |
2268 | |
2189 | mapstruct *has_been_loaded (char *name) |
2269 | maptile *has_been_loaded (char *name) |
2190 | PROTOTYPE: $ |
2270 | PROTOTYPE: $ |
2191 | |
2271 | |
2192 | int in_memory (mapstruct *map) |
2272 | int in_memory (maptile *map) |
2193 | CODE: |
2273 | CODE: |
2194 | RETVAL = map->in_memory; |
2274 | RETVAL = map->in_memory; |
2195 | OUTPUT: |
2275 | OUTPUT: |
2196 | RETVAL |
2276 | RETVAL |
2197 | |
2277 | |
2198 | void |
2278 | void |
2199 | trigger (mapstruct *map, long connection, bool state = true) |
2279 | trigger (maptile *map, long connection, bool state = true) |
2200 | CODE: |
2280 | CODE: |
2201 | activate_connection (map, connection, state); |
2281 | activate_connection (map, connection, state); |
2202 | |
2282 | |
2203 | void |
2283 | void |
2204 | get_connection (mapstruct *map, long connection) |
2284 | get_connection (maptile *map, long connection) |
2205 | PPCODE: |
2285 | PPCODE: |
2206 | oblinkpt *obp = get_connection_links (map, connection); |
2286 | oblinkpt *obp = get_connection_links (map, connection); |
2207 | if (obp) |
2287 | if (obp) |
2208 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2288 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2209 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, ol->ob))); |
2289 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, (object *)ol->ob))); |
2210 | |
2290 | |
2211 | object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) |
2291 | object *cf_map_insert_object_there (maptile *where, object *op, object *originator, int flags) |
2212 | |
2292 | |
2213 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
2293 | object *cf_map_insert_object (maptile *where, object* op, int x, int y) |
2214 | |
2294 | |
2215 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
2295 | object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny) |
2216 | C_ARGS: str, map, nx, ny |
2296 | C_ARGS: str, map, nx, ny |
2217 | |
2297 | |
2218 | void |
2298 | void |
2219 | cf_map_normalise (mapstruct *map, int x, int y) |
2299 | cf_map_normalise (maptile *map, int x, int y) |
2220 | PPCODE: |
2300 | PPCODE: |
2221 | { |
2301 | { |
2222 | mapstruct *nmap = 0; |
2302 | maptile *nmap = 0; |
2223 | I16 nx = 0, ny = 0; |
2303 | I16 nx = 0, ny = 0; |
2224 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
2304 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
2225 | |
2305 | |
2226 | EXTEND (SP, 4); |
2306 | EXTEND (SP, 4); |
2227 | PUSHs (sv_2mortal (newSViv (flags))); |
2307 | PUSHs (sv_2mortal (newSViv (flags))); |
… | |
… | |
2233 | PUSHs (sv_2mortal (newSViv (ny))); |
2313 | PUSHs (sv_2mortal (newSViv (ny))); |
2234 | } |
2314 | } |
2235 | } |
2315 | } |
2236 | |
2316 | |
2237 | void |
2317 | void |
2238 | at (mapstruct *map, unsigned int x, unsigned int y) |
2318 | at (maptile *map, unsigned int x, unsigned int y) |
2239 | PROTOTYPE: $$$ |
2319 | PROTOTYPE: $$$ |
2240 | PPCODE: |
2320 | PPCODE: |
2241 | { |
2321 | { |
2242 | object *o; |
2322 | object *o; |
2243 | mapstruct *nmap = 0; |
2323 | maptile *nmap = 0; |
2244 | I16 nx, ny; |
2324 | I16 nx, ny; |
2245 | |
2325 | |
2246 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2326 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2247 | |
2327 | |
2248 | if (nmap) |
2328 | if (nmap) |
2249 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2329 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2250 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2330 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2251 | } |
2331 | } |
2252 | |
2332 | |
2253 | SV * |
2333 | SV * |
2254 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
2334 | bot_at (maptile *obj, unsigned int x, unsigned int y) |
2255 | PROTOTYPE: $$$ |
2335 | PROTOTYPE: $$$ |
2256 | ALIAS: |
2336 | ALIAS: |
2257 | top_at = 1 |
2337 | top_at = 1 |
2258 | flags_at = 2 |
2338 | flags_at = 2 |
2259 | light_at = 3 |
2339 | light_at = 3 |
… | |
… | |
2281 | |
2361 | |
2282 | MODULE = cf PACKAGE = cf::arch |
2362 | MODULE = cf PACKAGE = cf::arch |
2283 | |
2363 | |
2284 | archetype *find (const char *name) |
2364 | archetype *find (const char *name) |
2285 | CODE: |
2365 | CODE: |
2286 | RETVAL = find_archetype (name); |
2366 | RETVAL = archetype::find (name); |
2287 | OUTPUT: |
2367 | OUTPUT: |
2288 | RETVAL |
2368 | RETVAL |
2289 | |
2369 | |
2290 | archetype *first() |
2370 | archetype *first() |
2291 | PROTOTYPE: |
2371 | PROTOTYPE: |