… | |
… | |
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 | |
52 | static f_plug_api gethook = cfapi_get_hooks; |
52 | static f_plug_api gethook = cfapi_get_hooks; |
53 | static f_plug_api object_set_property = cfapi_object_set_property; |
53 | static f_plug_api object_set_property = cfapi_object_set_property; |
54 | static f_plug_api object_insert = cfapi_object_insert; |
54 | static f_plug_api object_insert = cfapi_object_insert; |
55 | |
55 | |
56 | static HV *obj_cache; |
|
|
57 | static PerlInterpreter *perl; |
56 | static PerlInterpreter *perl; |
58 | |
57 | |
59 | static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; |
58 | 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 | |
59 | |
69 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
60 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
70 | |
61 | |
71 | static SV * |
62 | static SV * |
72 | newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) |
63 | newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) |
… | |
… | |
89 | |
80 | |
90 | if (!obj->self) |
81 | if (!obj->self) |
91 | obj->self = newSVptr (obj, klass); |
82 | obj->self = newSVptr (obj, klass); |
92 | |
83 | |
93 | return newSVsv (obj->self); |
84 | return newSVsv (obj->self); |
94 | } |
|
|
95 | |
|
|
96 | static void |
|
|
97 | SVptr_cache_set (void *ptr, SV *sv) |
|
|
98 | { |
|
|
99 | hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0); |
|
|
100 | } |
|
|
101 | |
|
|
102 | static SV * |
|
|
103 | SVptr_cache_get (void *ptr) |
|
|
104 | { |
|
|
105 | SV **he = hv_fetch (obj_cache, (char *)&ptr, sizeof (ptr), 0); |
|
|
106 | |
|
|
107 | return he ? *he : 0; |
|
|
108 | } |
|
|
109 | |
|
|
110 | static SV * |
|
|
111 | newSVptr_cached (void *ptr, const char *klass) |
|
|
112 | { |
|
|
113 | SV *sv; |
|
|
114 | |
|
|
115 | if (!ptr) |
|
|
116 | return &PL_sv_undef; |
|
|
117 | |
|
|
118 | sv = SVptr_cache_get (ptr); |
|
|
119 | |
|
|
120 | if (!sv) |
|
|
121 | { |
|
|
122 | HV *hv = newHV (); |
|
|
123 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
|
|
124 | sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
|
|
125 | |
|
|
126 | SVptr_cache_set (ptr, sv); |
|
|
127 | } |
|
|
128 | |
|
|
129 | return newSVsv (sv); |
|
|
130 | } |
85 | } |
131 | |
86 | |
132 | static void |
87 | static void |
133 | clearSVptr (SV *sv) |
88 | clearSVptr (SV *sv) |
134 | { |
89 | { |
… | |
… | |
177 | inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
132 | inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
178 | inline SV *to_sv (float v) { return newSVnv (v); } |
133 | inline SV *to_sv (float v) { return newSVnv (v); } |
179 | inline SV *to_sv (double v) { return newSVnv (v); } |
134 | inline SV *to_sv (double v) { return newSVnv (v); } |
180 | inline SV *to_sv (player * v) { return newSVattachable (v, "cf::player::wrap"); } |
135 | 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"); } |
136 | 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"); } |
137 | 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"); } |
138 | 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"); } |
139 | 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"); } |
140 | 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"); } |
141 | inline SV *to_sv (living * v) { return newSVptr (v, "cf::living::wrap"); } |
187 | |
142 | |
… | |
… | |
189 | inline SV *to_sv (living & v) { return to_sv (&v); } |
144 | inline SV *to_sv (living & v) { return to_sv (&v); } |
190 | |
145 | |
191 | //TODO: |
146 | //TODO: |
192 | inline SV *to_sv (New_Face * v) { return to_sv (v->name); } |
147 | inline SV *to_sv (New_Face * v) { return to_sv (v->name); } |
193 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
148 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
|
|
149 | |
|
|
150 | inline SV *to_sv (UUID v) |
|
|
151 | { |
|
|
152 | char buf[128]; |
|
|
153 | snprintf (buf, 128, "<1,%llx>", (unsigned long long)v.seq); |
|
|
154 | return newSVpv (buf, 0); |
|
|
155 | } |
194 | |
156 | |
195 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
157 | 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 = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } //TODO: verify that all simple pointers are strdup-managed |
158 | 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); } |
159 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
198 | inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
160 | inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
… | |
… | |
208 | inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
170 | inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
209 | inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
171 | 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"); } |
172 | 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"); } |
173 | 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"); } |
174 | 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"); } |
175 | 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"); } |
176 | 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"); } |
177 | 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"); } |
178 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
217 | |
179 | |
218 | inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO |
180 | inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO |
… | |
… | |
221 | template<class T> |
183 | template<class T> |
222 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
184 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
223 | |
185 | |
224 | template<int N> |
186 | template<int N> |
225 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
187 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
|
|
188 | |
|
|
189 | inline void sv_to (SV *sv, UUID &v) |
|
|
190 | { |
|
|
191 | unsigned int version; |
|
|
192 | unsigned long long seq; |
|
|
193 | |
|
|
194 | if (2 != sscanf (SvPV_nolen (sv), "<%d.%llx>", &version, &seq) || 1 != version) |
|
|
195 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
|
|
196 | |
|
|
197 | v.seq = seq; |
|
|
198 | } |
226 | |
199 | |
227 | static SV * |
200 | static SV * |
228 | newSVdt_va (va_list &ap, data_type type) |
201 | newSVdt_va (va_list &ap, data_type type) |
229 | { |
202 | { |
230 | SV *sv; |
203 | SV *sv; |
… | |
… | |
262 | sv = to_sv (va_arg (ap, object *)); |
235 | sv = to_sv (va_arg (ap, object *)); |
263 | break; |
236 | break; |
264 | |
237 | |
265 | case DT_MAP: |
238 | case DT_MAP: |
266 | // va_arg (object *) when void * is passed is an XSI extension |
239 | // va_arg (object *) when void * is passed is an XSI extension |
267 | sv = to_sv (va_arg (ap, mapstruct *)); |
240 | sv = to_sv (va_arg (ap, maptile *)); |
268 | break; |
241 | break; |
269 | |
242 | |
270 | case DT_PLAYER: |
243 | case DT_PLAYER: |
271 | sv = to_sv (va_arg (ap, player *)); |
244 | sv = to_sv (va_arg (ap, player *)); |
272 | break; |
245 | break; |
… | |
… | |
349 | { |
322 | { |
350 | if (cb) |
323 | if (cb) |
351 | if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) |
324 | if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) |
352 | INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); |
325 | INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); |
353 | else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) |
326 | else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) |
354 | INVOKE_MAP (DESTROY, static_cast<mapstruct *>(this)); |
327 | INVOKE_MAP (DESTROY, static_cast<maptile *>(this)); |
355 | |
328 | |
356 | // disconnect Perl from C, to avoid crashes |
329 | // disconnect Perl from C, to avoid crashes |
357 | sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); |
330 | sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); |
358 | |
331 | |
359 | // clear the perl hash, might or might not be a good idea |
332 | // 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); |
460 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
488 | FREETMPS; |
461 | FREETMPS; |
489 | LEAVE; |
462 | LEAVE; |
490 | } |
463 | } |
491 | |
464 | |
|
|
465 | char *object_freezer::as_string () |
|
|
466 | { |
|
|
467 | dSP; |
|
|
468 | ENTER; |
|
|
469 | SAVETMPS; |
|
|
470 | PUSHMARK (SP); |
|
|
471 | EXTEND (SP, 3); |
|
|
472 | PUSHs (sv_2mortal (newRV_noinc (newSVpvn ((char *)linearise (), size ())))); |
|
|
473 | PUSHs (sv_2mortal (newRV_inc ((SV *)av))); |
|
|
474 | PUTBACK; |
|
|
475 | |
|
|
476 | char *res = call_pv ("cf::object_freezer_as_string", G_SCALAR | G_EVAL) > 0 |
|
|
477 | ? strdup (SvPVbyte_nolen (POPs)) |
|
|
478 | : strdup ("[fatal error]"); |
|
|
479 | |
|
|
480 | FREETMPS; |
|
|
481 | LEAVE; |
|
|
482 | |
|
|
483 | return res; |
|
|
484 | } |
|
|
485 | |
492 | int fprintf (object_freezer &freezer, const char *format, ...) |
486 | int fprintf (object_freezer &freezer, const char *format, ...) |
493 | { |
487 | { |
494 | va_list ap; |
488 | va_list ap; |
495 | |
489 | |
496 | va_start (ap, format); |
490 | va_start (ap, format); |
… | |
… | |
505 | |
499 | |
506 | int fputs (const char *s, object_freezer &freezer) |
500 | int fputs (const char *s, object_freezer &freezer) |
507 | { |
501 | { |
508 | freezer.add (s); |
502 | freezer.add (s); |
509 | } |
503 | } |
|
|
504 | |
|
|
505 | static const char thawer_eof[] = "\n\n\n\0\0\0"; |
510 | |
506 | |
511 | object_thawer::object_thawer (const char *filename) |
507 | object_thawer::object_thawer (const char *filename) |
512 | { |
508 | { |
513 | static const char eof[] = "\n\n\n\0\0\0"; |
509 | static const char eof[] = "\n\n\n\0\0\0"; |
514 | |
510 | |
… | |
… | |
552 | |
548 | |
553 | PUTBACK; |
549 | PUTBACK; |
554 | FREETMPS; |
550 | FREETMPS; |
555 | LEAVE; |
551 | LEAVE; |
556 | } |
552 | } |
|
|
553 | } |
|
|
554 | |
|
|
555 | object_thawer::object_thawer (const char *data, AV *perlav) |
|
|
556 | { |
|
|
557 | av = perlav; |
|
|
558 | text = newSVpv (data, 0); |
|
|
559 | sv_catpv (text, thawer_eof); |
|
|
560 | line = SvPVbyte_nolen (text); |
557 | } |
561 | } |
558 | |
562 | |
559 | void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) |
563 | void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) |
560 | { |
564 | { |
561 | if (!av || oid < 0) // this is actually an error of sorts |
565 | if (!av || oid < 0) // this is actually an error of sorts |
… | |
… | |
877 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
881 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
878 | { |
882 | { |
879 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
883 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
880 | exit (EXIT_FAILURE); |
884 | exit (EXIT_FAILURE); |
881 | } |
885 | } |
882 | |
|
|
883 | obj_cache = newHV (); |
|
|
884 | } |
886 | } |
885 | |
887 | |
886 | void cfperl_main () |
888 | void cfperl_main () |
887 | { |
889 | { |
888 | dSP; |
890 | dSP; |
… | |
… | |
939 | |
941 | |
940 | AV *callbacks = 0; |
942 | AV *callbacks = 0; |
941 | |
943 | |
942 | object *op; |
944 | object *op; |
943 | player *pl; |
945 | player *pl; |
944 | mapstruct *map; |
946 | maptile *map; |
945 | |
947 | |
946 | // callback call ordering is: |
948 | // callback call ordering is: |
947 | // 1. per-object callback (NYI) |
949 | // 1. per-object callback (NYI) |
948 | // 2. per-class object |
950 | // 2. per-class object |
949 | // 2a. per-type callback |
951 | // 2a. per-type callback |
… | |
… | |
999 | break; |
1001 | break; |
1000 | |
1002 | |
1001 | case KLASS_MAP: |
1003 | case KLASS_MAP: |
1002 | dt = (data_type) va_arg (ap, int); |
1004 | dt = (data_type) va_arg (ap, int); |
1003 | assert (("first argument must be of type object", dt == DT_MAP)); |
1005 | assert (("first argument must be of type object", dt == DT_MAP)); |
1004 | map = va_arg (ap, mapstruct *); |
1006 | map = va_arg (ap, maptile *); |
1005 | |
1007 | |
1006 | if (map->cb) |
1008 | if (map->cb) |
1007 | gather_callbacks (callbacks, map->cb, event); |
1009 | gather_callbacks (callbacks, map->cb, event); |
1008 | |
1010 | |
1009 | gather_callbacks (callbacks, cb_map, event); |
1011 | gather_callbacks (callbacks, cb_map, event); |
… | |
… | |
1089 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1091 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1090 | |
1092 | |
1091 | BOOT: |
1093 | BOOT: |
1092 | { |
1094 | { |
1093 | HV *stash = gv_stashpv ("cf", 1); |
1095 | HV *stash = gv_stashpv ("cf", 1); |
|
|
1096 | |
|
|
1097 | newCONSTSUB (stash, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1094 | |
1098 | |
1095 | static const struct { |
1099 | static const struct { |
1096 | const char *name; |
1100 | const char *name; |
1097 | IV iv; |
1101 | IV iv; |
1098 | } *civ, const_iv[] = { |
1102 | } *civ, const_iv[] = { |
… | |
… | |
1626 | { |
1630 | { |
1627 | // reattach to all attachable objects in the game. |
1631 | // reattach to all attachable objects in the game. |
1628 | for (player *pl = first_player; pl; pl = pl->next) |
1632 | for (player *pl = first_player; pl; pl = pl->next) |
1629 | reattach (pl); |
1633 | reattach (pl); |
1630 | |
1634 | |
1631 | for (mapstruct *map = first_map; map; map = map->next) |
1635 | for (maptile *map = first_map; map; map = map->next) |
1632 | reattach (map); |
1636 | reattach (map); |
1633 | |
1637 | |
1634 | for (object *op = object::first; op; op = op->next) |
1638 | for (object *op = object::first; op; op = op->next) |
1635 | reattach (op); |
1639 | reattach (op); |
1636 | } |
1640 | } |
… | |
… | |
1752 | OUTPUT: |
1756 | OUTPUT: |
1753 | RETVAL |
1757 | RETVAL |
1754 | |
1758 | |
1755 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1759 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1756 | |
1760 | |
|
|
1761 | INCLUDE: $PERL genacc object ../include/object.h | |
|
|
1762 | |
1757 | int invoke (object *op, int event, ...) |
1763 | int invoke (object *op, int event, ...) |
1758 | CODE: |
1764 | CODE: |
1759 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1765 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1760 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1766 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1761 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1767 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
… | |
… | |
1776 | |
1782 | |
1777 | object *first () |
1783 | object *first () |
1778 | CODE: |
1784 | CODE: |
1779 | RETVAL = object::first; |
1785 | RETVAL = object::first; |
1780 | OUTPUT: RETVAL |
1786 | OUTPUT: RETVAL |
1781 | |
|
|
1782 | INCLUDE: $PERL genacc object ../include/object.h | |
|
|
1783 | |
1787 | |
1784 | # missing properties |
1788 | # missing properties |
1785 | |
1789 | |
1786 | int flag (object *op, int flag, int value = 1) |
1790 | int flag (object *op, int flag, int value = 1) |
1787 | PROTOTYPE: $$;$ |
1791 | PROTOTYPE: $$;$ |
… | |
… | |
1843 | |
1847 | |
1844 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
1848 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
1845 | |
1849 | |
1846 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
1850 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
1847 | |
1851 | |
1848 | int cf_object_change_map (object *op, int x, int y, mapstruct *map) |
1852 | int cf_object_change_map (object *op, int x, int y, maptile *map) |
1849 | |
1853 | |
1850 | object *cf_object_clone (object *op, int clonetype = 0) |
1854 | object *cf_object_clone (object *op, int clonetype = 0) |
1851 | |
1855 | |
1852 | int cf_object_pay_item (object *op, object *buyer) |
1856 | int cf_object_pay_item (object *op, object *buyer) |
1853 | |
1857 | |
… | |
… | |
1885 | |
1889 | |
1886 | object *cf_object_insert_object (object *op, object *container) |
1890 | object *cf_object_insert_object (object *op, object *container) |
1887 | |
1891 | |
1888 | object *cf_object_insert_in_ob (object *ob, object *where) |
1892 | object *cf_object_insert_in_ob (object *ob, object *where) |
1889 | |
1893 | |
1890 | int cf_object_teleport (object *op, mapstruct *map, int x, int y) |
1894 | int cf_object_teleport (object *op, maptile *map, int x, int y) |
1891 | |
1895 | |
1892 | void cf_object_update (object *op, int flags) |
1896 | void cf_object_update (object *op, int flags) |
1893 | |
1897 | |
1894 | void cf_object_pickup (object *op, object *what) |
1898 | void cf_object_pickup (object *op, object *what) |
1895 | |
1899 | |
… | |
… | |
1905 | |
1909 | |
1906 | void push_button (object *op); |
1910 | void push_button (object *op); |
1907 | |
1911 | |
1908 | void use_trigger (object *op); |
1912 | void use_trigger (object *op); |
1909 | |
1913 | |
1910 | void add_button_link (object *button, mapstruct *map, int connected); |
1914 | void add_button_link (object *button, maptile *map, int connected); |
1911 | |
1915 | |
1912 | void remove_button_link (object *op); |
1916 | void remove_button_link (object *op); |
1913 | |
1917 | |
1914 | void |
1918 | void |
1915 | cf_object_set_resistance (object *op, int rtype, int val) |
1919 | cf_object_set_resistance (object *op, int rtype, int val) |
… | |
… | |
1933 | CODE: |
1937 | CODE: |
1934 | RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); |
1938 | RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); |
1935 | OUTPUT: |
1939 | OUTPUT: |
1936 | RETVAL |
1940 | RETVAL |
1937 | |
1941 | |
1938 | object *insert_ob_in_map_at (object *ob, mapstruct *where, object_ornull *orig, int flag, int x, int y) |
1942 | object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) |
1939 | PROTOTYPE: $$$$$$ |
1943 | PROTOTYPE: $$$$$$ |
1940 | CODE: |
1944 | CODE: |
1941 | { |
1945 | { |
1942 | int unused_type; |
1946 | int unused_type; |
1943 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1947 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
… | |
… | |
2016 | void kill_player (object *op) |
2020 | void kill_player (object *op) |
2017 | |
2021 | |
2018 | void esrv_update_item (object *op, int what, object *item) |
2022 | void esrv_update_item (object *op, int what, object *item) |
2019 | C_ARGS: what, op, item |
2023 | C_ARGS: what, op, item |
2020 | |
2024 | |
|
|
2025 | void clear_los (object *op) |
|
|
2026 | |
|
|
2027 | int command_reset (object *op, char *params) |
|
|
2028 | |
|
|
2029 | int command_teleport (object *op, char *params) |
|
|
2030 | |
|
|
2031 | int command_summon (object *op, char *params) |
|
|
2032 | |
|
|
2033 | int command_arrest (object *op, char *params) |
|
|
2034 | |
|
|
2035 | int command_kick (object *op, char *params) |
|
|
2036 | |
|
|
2037 | int command_banish (object *op, char *params) |
|
|
2038 | |
|
|
2039 | |
2021 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2040 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
|
|
2041 | |
|
|
2042 | INCLUDE: $PERL genacc player ../include/newserver.h ../include/player.h | |
|
|
2043 | |
|
|
2044 | char * |
|
|
2045 | client (player *pl) |
|
|
2046 | CODE: |
|
|
2047 | RETVAL = pl->socket.client; |
|
|
2048 | OUTPUT: |
|
|
2049 | RETVAL |
|
|
2050 | |
|
|
2051 | char * |
|
|
2052 | host (player *pl) |
|
|
2053 | CODE: |
|
|
2054 | RETVAL = pl->socket.host; |
|
|
2055 | OUTPUT: |
|
|
2056 | RETVAL |
2022 | |
2057 | |
2023 | int invoke (player *pl, int event, ...) |
2058 | int invoke (player *pl, int event, ...) |
2024 | CODE: |
2059 | CODE: |
2025 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
2060 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
2026 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2061 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
… | |
… | |
2039 | |
2074 | |
2040 | void cf_player_move (player *pl, int dir) |
2075 | void cf_player_move (player *pl, int dir) |
2041 | |
2076 | |
2042 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2077 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2043 | |
2078 | |
2044 | # nonstandard |
|
|
2045 | object *ob (player *pl) |
|
|
2046 | CODE: |
|
|
2047 | RETVAL = pl->ob; |
|
|
2048 | OUTPUT: RETVAL |
|
|
2049 | |
|
|
2050 | player *first () |
2079 | player *first () |
2051 | CODE: |
2080 | CODE: |
2052 | RETVAL = first_player; |
2081 | RETVAL = first_player; |
2053 | OUTPUT: RETVAL |
2082 | OUTPUT: RETVAL |
2054 | |
2083 | |
… | |
… | |
2060 | bool |
2089 | bool |
2061 | cell_visible (player *pl, int dx, int dy) |
2090 | cell_visible (player *pl, int dx, int dy) |
2062 | CODE: |
2091 | CODE: |
2063 | RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2 |
2092 | RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2 |
2064 | && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]; |
2093 | && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]; |
2065 | OUTPUT: |
|
|
2066 | RETVAL |
|
|
2067 | |
|
|
2068 | char * |
|
|
2069 | client (player *pl) |
|
|
2070 | CODE: |
|
|
2071 | RETVAL = pl->socket.client; |
|
|
2072 | OUTPUT: |
|
|
2073 | RETVAL |
|
|
2074 | |
|
|
2075 | char * |
|
|
2076 | host (player *pl) |
|
|
2077 | CODE: |
|
|
2078 | RETVAL = pl->socket.host; |
|
|
2079 | OUTPUT: |
|
|
2080 | RETVAL |
|
|
2081 | |
|
|
2082 | char * |
|
|
2083 | killer (player *pl, char *killer = 0) |
|
|
2084 | CODE: |
|
|
2085 | if (killer) |
|
|
2086 | snprintf (pl->killer, sizeof (pl->killer), "%s", killer); |
|
|
2087 | RETVAL = pl->killer; |
|
|
2088 | OUTPUT: |
2094 | OUTPUT: |
2089 | RETVAL |
2095 | RETVAL |
2090 | |
2096 | |
2091 | void |
2097 | void |
2092 | buggy_mapscroll (player *pl, int value = 1) |
2098 | buggy_mapscroll (player *pl, int value = 1) |
… | |
… | |
2158 | OUTPUT: RETVAL |
2164 | OUTPUT: RETVAL |
2159 | |
2165 | |
2160 | |
2166 | |
2161 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2167 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2162 | |
2168 | |
2163 | mapstruct *first () |
2169 | maptile *first () |
2164 | PROTOTYPE: |
2170 | PROTOTYPE: |
2165 | CODE: |
2171 | CODE: |
2166 | RETVAL = first_map; |
2172 | RETVAL = first_map; |
2167 | OUTPUT: RETVAL |
2173 | OUTPUT: RETVAL |
2168 | |
2174 | |
2169 | int invoke (mapstruct *map, int event, ...) |
2175 | int invoke (maptile *map, int event, ...) |
2170 | CODE: |
2176 | CODE: |
2171 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2177 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2172 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2178 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2173 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2179 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2174 | RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); |
2180 | RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); |
2175 | OUTPUT: RETVAL |
2181 | OUTPUT: RETVAL |
2176 | |
2182 | |
2177 | SV *registry (mapstruct *map) |
2183 | SV *registry (maptile *map) |
2178 | CODE: |
2184 | CODE: |
2179 | RETVAL = registry_of (map); |
2185 | RETVAL = registry_of (map); |
2180 | OUTPUT: |
2186 | OUTPUT: |
2181 | RETVAL |
2187 | RETVAL |
2182 | |
2188 | |
2183 | INCLUDE: $PERL genacc mapstruct ../include/map.h | |
2189 | INCLUDE: $PERL genacc maptile ../include/map.h | |
2184 | |
2190 | |
2185 | mapstruct *new (int width, int height) |
2191 | maptile *new (int width, int height) |
2186 | PROTOTYPE: |
2192 | PROTOTYPE: |
2187 | CODE: |
2193 | CODE: |
2188 | { |
2194 | { |
2189 | RETVAL = get_empty_map (width, height); |
2195 | RETVAL = get_empty_map (width, height); |
2190 | } |
2196 | } |
2191 | OUTPUT: |
2197 | OUTPUT: |
2192 | RETVAL |
2198 | RETVAL |
2193 | |
2199 | |
2194 | void delete_map (mapstruct *map) |
2200 | void delete_map (maptile *map) |
2195 | |
2201 | |
2196 | void clean_tmp_map (mapstruct *map) |
2202 | void clean_tmp_map (maptile *map) |
2197 | |
2203 | |
2198 | void play_sound_map (mapstruct *map, int x, int y, int sound_num) |
2204 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2199 | |
2205 | |
2200 | mapstruct *tile_map (mapstruct *map, unsigned int dir) |
2206 | maptile *tile_map (maptile *map, unsigned int dir) |
2201 | CODE: |
2207 | CODE: |
2202 | RETVAL = dir < 4 ? map->tile_map [dir] : 0; |
2208 | RETVAL = dir < 4 ? map->tile_map [dir] : 0; |
2203 | OUTPUT: |
2209 | OUTPUT: |
2204 | RETVAL |
2210 | RETVAL |
2205 | |
2211 | |
2206 | char *tile_path (mapstruct *map, unsigned int dir) |
2212 | char *tile_path (maptile *map, unsigned int dir) |
2207 | CODE: |
2213 | CODE: |
2208 | if (dir >= 4) |
2214 | if (dir >= 4) |
2209 | XSRETURN_UNDEF; |
2215 | XSRETURN_UNDEF; |
2210 | RETVAL = map->tile_path [dir]; |
2216 | RETVAL = map->tile_path [dir]; |
2211 | OUTPUT: |
2217 | OUTPUT: |
2212 | RETVAL |
2218 | RETVAL |
2213 | |
2219 | |
2214 | mapstruct *ready_map_name (char *name, int flags = 0) |
2220 | maptile *ready_map_name (char *name, int flags = 0) |
2215 | PROTOTYPE: $;$ |
2221 | PROTOTYPE: $;$ |
2216 | ALIAS: |
2222 | ALIAS: |
2217 | find = 0 |
2223 | find = 0 |
2218 | get_map = 1 |
2224 | get_map = 1 |
2219 | |
2225 | |
2220 | mapstruct *has_been_loaded (char *name) |
2226 | maptile *has_been_loaded (char *name) |
2221 | PROTOTYPE: $ |
2227 | PROTOTYPE: $ |
2222 | |
2228 | |
2223 | int in_memory (mapstruct *map) |
2229 | int in_memory (maptile *map) |
2224 | CODE: |
2230 | CODE: |
2225 | RETVAL = map->in_memory; |
2231 | RETVAL = map->in_memory; |
2226 | OUTPUT: |
2232 | OUTPUT: |
2227 | RETVAL |
2233 | RETVAL |
2228 | |
2234 | |
2229 | void |
2235 | void |
2230 | trigger (mapstruct *map, long connection, bool state = true) |
2236 | trigger (maptile *map, long connection, bool state = true) |
2231 | CODE: |
2237 | CODE: |
2232 | activate_connection (map, connection, state); |
2238 | activate_connection (map, connection, state); |
2233 | |
2239 | |
2234 | void |
2240 | void |
2235 | get_connection (mapstruct *map, long connection) |
2241 | get_connection (maptile *map, long connection) |
2236 | PPCODE: |
2242 | PPCODE: |
2237 | oblinkpt *obp = get_connection_links (map, connection); |
2243 | oblinkpt *obp = get_connection_links (map, connection); |
2238 | if (obp) |
2244 | if (obp) |
2239 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2245 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2240 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, ol->ob))); |
2246 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, (object *)ol->ob))); |
2241 | |
2247 | |
2242 | object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) |
2248 | object *cf_map_insert_object_there (maptile *where, object *op, object *originator, int flags) |
2243 | |
2249 | |
2244 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
2250 | object *cf_map_insert_object (maptile *where, object* op, int x, int y) |
2245 | |
2251 | |
2246 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
2252 | object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny) |
2247 | C_ARGS: str, map, nx, ny |
2253 | C_ARGS: str, map, nx, ny |
2248 | |
2254 | |
2249 | void |
2255 | void |
2250 | cf_map_normalise (mapstruct *map, int x, int y) |
2256 | cf_map_normalise (maptile *map, int x, int y) |
2251 | PPCODE: |
2257 | PPCODE: |
2252 | { |
2258 | { |
2253 | mapstruct *nmap = 0; |
2259 | maptile *nmap = 0; |
2254 | I16 nx = 0, ny = 0; |
2260 | I16 nx = 0, ny = 0; |
2255 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
2261 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
2256 | |
2262 | |
2257 | EXTEND (SP, 4); |
2263 | EXTEND (SP, 4); |
2258 | PUSHs (sv_2mortal (newSViv (flags))); |
2264 | PUSHs (sv_2mortal (newSViv (flags))); |
… | |
… | |
2264 | PUSHs (sv_2mortal (newSViv (ny))); |
2270 | PUSHs (sv_2mortal (newSViv (ny))); |
2265 | } |
2271 | } |
2266 | } |
2272 | } |
2267 | |
2273 | |
2268 | void |
2274 | void |
2269 | at (mapstruct *map, unsigned int x, unsigned int y) |
2275 | at (maptile *map, unsigned int x, unsigned int y) |
2270 | PROTOTYPE: $$$ |
2276 | PROTOTYPE: $$$ |
2271 | PPCODE: |
2277 | PPCODE: |
2272 | { |
2278 | { |
2273 | object *o; |
2279 | object *o; |
2274 | mapstruct *nmap = 0; |
2280 | maptile *nmap = 0; |
2275 | I16 nx, ny; |
2281 | I16 nx, ny; |
2276 | |
2282 | |
2277 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2283 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2278 | |
2284 | |
2279 | if (nmap) |
2285 | if (nmap) |
2280 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2286 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2281 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2287 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2282 | } |
2288 | } |
2283 | |
2289 | |
2284 | SV * |
2290 | SV * |
2285 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
2291 | bot_at (maptile *obj, unsigned int x, unsigned int y) |
2286 | PROTOTYPE: $$$ |
2292 | PROTOTYPE: $$$ |
2287 | ALIAS: |
2293 | ALIAS: |
2288 | top_at = 1 |
2294 | top_at = 1 |
2289 | flags_at = 2 |
2295 | flags_at = 2 |
2290 | light_at = 3 |
2296 | light_at = 3 |
… | |
… | |
2307 | case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; |
2313 | case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; |
2308 | } |
2314 | } |
2309 | OUTPUT: |
2315 | OUTPUT: |
2310 | RETVAL |
2316 | RETVAL |
2311 | |
2317 | |
|
|
2318 | void fix_walls (maptile *map, int x, int y) |
|
|
2319 | |
|
|
2320 | void fix_walls_around (maptile *map, int x, int y) |
2312 | |
2321 | |
2313 | MODULE = cf PACKAGE = cf::arch |
2322 | MODULE = cf PACKAGE = cf::arch |
2314 | |
2323 | |
2315 | archetype *find (const char *name) |
2324 | archetype *find (const char *name) |
2316 | CODE: |
2325 | CODE: |
2317 | RETVAL = find_archetype (name); |
2326 | RETVAL = archetype::find (name); |
2318 | OUTPUT: |
2327 | OUTPUT: |
2319 | RETVAL |
2328 | RETVAL |
2320 | |
2329 | |
2321 | archetype *first() |
2330 | archetype *first() |
2322 | PROTOTYPE: |
2331 | PROTOTYPE: |