… | |
… | |
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@schmorpd.e> |
9 | * Copyright (C) 2006 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. |
… | |
… | |
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 | /* this is a stupid way to do things, and awkward to use for plug-in authors */ |
|
|
57 | typedef struct |
|
|
58 | { |
|
|
59 | object* who; |
|
|
60 | object* activator; |
|
|
61 | object* third; |
|
|
62 | object* event; |
|
|
63 | mapstruct* map; |
|
|
64 | char message[1024]; |
|
|
65 | int fix; // seems to be python-only, and should not be part of the API |
|
|
66 | int event_code; |
|
|
67 | char extension[1024]; // name field, should invoke specific perl extension |
|
|
68 | char options[1024]; // slaying field of event_connectors |
|
|
69 | int returnvalue; |
|
|
70 | } CFPContext; |
|
|
71 | |
|
|
72 | static HV *obj_cache; |
56 | static HV *obj_cache; |
73 | static PerlInterpreter *perl; |
57 | static PerlInterpreter *perl; |
74 | |
58 | |
75 | 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; |
76 | |
60 | |
… | |
… | |
176 | return SvPTR (sv, klass); |
160 | return SvPTR (sv, klass); |
177 | else |
161 | else |
178 | return 0; |
162 | return 0; |
179 | } |
163 | } |
180 | |
164 | |
|
|
165 | inline SV *to_sv (const shstr & v) { return v ? newSVpvn ((const char *)v, v.length ()) : &PL_sv_undef; } |
|
|
166 | inline SV *to_sv (const char * v) { return newSVpv (v, 0); } |
|
|
167 | inline SV *to_sv (bool v) { return newSViv (v); } |
|
|
168 | inline SV *to_sv ( signed char v) { return newSViv (v); } |
|
|
169 | inline SV *to_sv (unsigned char v) { return newSViv (v); } |
|
|
170 | inline SV *to_sv ( signed short v) { return newSViv (v); } |
|
|
171 | inline SV *to_sv (unsigned short v) { return newSVuv (v); } |
|
|
172 | inline SV *to_sv ( signed int v) { return newSViv (v); } |
|
|
173 | inline SV *to_sv (unsigned int v) { return newSVuv (v); } |
|
|
174 | inline SV *to_sv ( signed long v) { return newSViv (v); } |
|
|
175 | inline SV *to_sv (unsigned long v) { return newSVuv (v); } |
|
|
176 | inline SV *to_sv ( signed long long v) { return newSVval64 (v); } |
|
|
177 | inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
|
|
178 | inline SV *to_sv (float v) { return newSVnv (v); } |
|
|
179 | inline SV *to_sv (double v) { return newSVnv (v); } |
|
|
180 | 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"); } |
|
|
182 | inline SV *to_sv (mapstruct * v) { return newSVattachable (v, "cf::map::wrap"); } |
|
|
183 | 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"); } |
|
|
185 | 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"); } |
|
|
187 | |
|
|
188 | inline SV *to_sv (object & v) { return to_sv (&v); } |
|
|
189 | inline SV *to_sv (living & v) { return to_sv (&v); } |
|
|
190 | |
|
|
191 | //TODO: |
|
|
192 | inline SV *to_sv (New_Face * v) { return to_sv (v->name); } |
|
|
193 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
|
|
194 | |
|
|
195 | inline void sv_to (SV *sv, shstr &v) { v = SvPV_nolen (sv); } |
|
|
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 |
|
|
197 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
|
|
198 | 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); } |
|
|
200 | 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); } |
|
|
202 | inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); } |
|
|
203 | inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); } |
|
|
204 | inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); } |
|
|
205 | inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
|
|
206 | inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } |
|
|
207 | inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } |
|
|
208 | inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
|
|
209 | 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"); } |
|
|
211 | 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"); } |
|
|
213 | inline void sv_to (SV *sv, mapstruct * &v) { v = (mapstruct *)SvPTR_ornull (sv, "cf::map"); } |
|
|
214 | 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"); } |
|
|
216 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
|
|
217 | |
|
|
218 | inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO |
|
|
219 | inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } // TODO |
|
|
220 | |
|
|
221 | template<class T> |
|
|
222 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
|
|
223 | |
|
|
224 | template<int N> |
|
|
225 | inline void sv_to (SV *sv, char (&v)[N]) { snprintf (v, N, "%s", SvPV_nolen (sv)); } |
|
|
226 | |
181 | static SV * |
227 | static SV * |
182 | newSVdt_va (va_list &ap, data_type type) |
228 | newSVdt_va (va_list &ap, data_type type) |
183 | { |
229 | { |
184 | SV *sv; |
230 | SV *sv; |
185 | |
231 | |
… | |
… | |
211 | sv = str ? newSVpv (str, len) : &PL_sv_undef; |
257 | sv = str ? newSVpv (str, len) : &PL_sv_undef; |
212 | } |
258 | } |
213 | break; |
259 | break; |
214 | |
260 | |
215 | case DT_OBJECT: |
261 | case DT_OBJECT: |
216 | { |
262 | sv = to_sv (va_arg (ap, object *)); |
217 | object *obj = va_arg (ap, object *); |
|
|
218 | sv = newSVattachable (obj, obj && obj->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); |
|
|
219 | } |
|
|
220 | break; |
263 | break; |
221 | |
264 | |
222 | case DT_MAP: |
265 | case DT_MAP: |
223 | // va_arg (object *) when void * is passed is an XSI extension |
266 | // va_arg (object *) when void * is passed is an XSI extension |
224 | sv = newSVattachable (va_arg (ap, mapstruct *), "cf::map::wrap"); |
267 | sv = to_sv (va_arg (ap, mapstruct *)); |
225 | break; |
268 | break; |
226 | |
269 | |
227 | case DT_PLAYER: |
270 | case DT_PLAYER: |
228 | sv = newSVattachable (va_arg (ap, player *), "cf::player::wrap"); |
271 | sv = to_sv (va_arg (ap, player *)); |
229 | break; |
272 | break; |
230 | |
273 | |
231 | case DT_ARCH: |
274 | case DT_ARCH: |
232 | sv = newSVptr (va_arg (ap, archetype *), "cf::arch::wrap"); |
275 | sv = to_sv (va_arg (ap, archetype *)); |
233 | break; |
276 | break; |
234 | |
277 | |
235 | case DT_PARTY: |
278 | case DT_PARTY: |
236 | sv = newSVptr (va_arg (ap, partylist *), "cf::party::wrap"); |
279 | sv = to_sv (va_arg (ap, partylist *)); |
237 | break; |
280 | break; |
238 | |
281 | |
239 | case DT_REGION: |
282 | case DT_REGION: |
240 | sv = newSVptr (va_arg (ap, region *), "cf::region::wrap"); |
283 | sv = to_sv (va_arg (ap, region *)); |
241 | break; |
284 | break; |
242 | |
285 | |
243 | default: |
286 | default: |
244 | assert (("unhandled type in newSVdt_va", 0)); |
287 | assert (("unhandled type in newSVdt_va", 0)); |
245 | } |
288 | } |
… | |
… | |
585 | int klen = p - line; |
628 | int klen = p - line; |
586 | |
629 | |
587 | if (*p++ != '\n') |
630 | if (*p++ != '\n') |
588 | { |
631 | { |
589 | // parse value |
632 | // parse value |
590 | while (*p <= ' ' && *p != '\n') // skip 0x01 .. 0x20 |
633 | while (*(unsigned char *)p <= ' ' && *p != '\n') // skip 0x01 .. 0x20 |
591 | ++p; |
634 | ++p; |
592 | |
635 | |
593 | last_value = p; |
636 | last_value = p; |
594 | |
637 | |
595 | while (*p != '\n') |
638 | while (*p != '\n') |
… | |
… | |
633 | |
676 | |
634 | void object_thawer::get_ml (keyword kend, shstr &sh) |
677 | void object_thawer::get_ml (keyword kend, shstr &sh) |
635 | { |
678 | { |
636 | char kw[128]; |
679 | char kw[128]; |
637 | |
680 | |
638 | // multi-line strings are delimited by "\nendXXX\n" |
681 | int klen = keyword_len [kend]; |
|
|
682 | |
639 | kw [0] = '\n'; |
683 | kw [0] = '\n'; |
640 | strcpy (kw + 1, keyword_str [kend]); |
684 | memcpy (kw + 1, keyword_str [kend], klen); |
|
|
685 | kw [klen + 1] = '\n'; |
|
|
686 | kw [klen + 2] = 0; |
641 | |
687 | |
642 | char *end = strstr (line, kw); |
688 | // first test for completely empty msg... "endXXX\n" |
643 | |
689 | if (!strncmp (line, kw + 1, klen + 1)) |
644 | if (!end) |
|
|
645 | { |
690 | { |
646 | sh = 0; |
691 | sh = 0; |
|
|
692 | |
|
|
693 | line += klen + 1; |
|
|
694 | |
647 | return; |
695 | return; |
648 | } |
696 | } |
|
|
697 | else |
|
|
698 | { |
|
|
699 | // multi-line strings are delimited by "\nendXXX\n" or "endXXX\n" (NULL) |
649 | |
700 | |
|
|
701 | char *end = strstr (line, kw); |
|
|
702 | |
|
|
703 | if (!end) |
|
|
704 | { |
|
|
705 | sh = 0; |
|
|
706 | return; |
|
|
707 | } |
|
|
708 | |
650 | *end = 0; |
709 | *end = 0; |
651 | sh = line; |
710 | sh = line; |
652 | |
711 | |
653 | line = end + keyword_len [kend] + 1; |
712 | line = end + keyword_len [kend] + 1; |
654 | |
713 | |
655 | while (*line++ != '\n') |
714 | while (*line++ != '\n') |
|
|
715 | ; |
656 | ; |
716 | } |
657 | } |
717 | } |
658 | |
718 | |
659 | sint32 object_thawer::get_sint32 () const |
719 | sint32 object_thawer::get_sint32 () const |
660 | { |
720 | { |
661 | char *p = last_value; |
721 | char *p = last_value; |
… | |
… | |
1201 | const_iv (AT_BLIND) |
1261 | const_iv (AT_BLIND) |
1202 | const_iv (AT_INTERNAL) |
1262 | const_iv (AT_INTERNAL) |
1203 | const_iv (AT_LIFE_STEALING) |
1263 | const_iv (AT_LIFE_STEALING) |
1204 | const_iv (AT_DISEASE) |
1264 | const_iv (AT_DISEASE) |
1205 | |
1265 | |
1206 | const_iv (QUEST_IN_PROGRESS) |
|
|
1207 | const_iv (QUEST_DONE_QUEST) |
|
|
1208 | const_iv (QUEST_DONE_TASK) |
|
|
1209 | const_iv (QUEST_START_QUEST) |
|
|
1210 | const_iv (QUEST_END_QUEST) |
|
|
1211 | const_iv (QUEST_START_TASK) |
|
|
1212 | const_iv (QUEST_END_TASK) |
|
|
1213 | const_iv (QUEST_OVERRIDE) |
|
|
1214 | const_iv (QUEST_ON_ACTIVATE) |
|
|
1215 | |
|
|
1216 | const_iv (WEAP_HIT) |
1266 | const_iv (WEAP_HIT) |
1217 | const_iv (WEAP_SLASH) |
1267 | const_iv (WEAP_SLASH) |
1218 | const_iv (WEAP_PIERCE) |
1268 | const_iv (WEAP_PIERCE) |
1219 | const_iv (WEAP_CLEAVE) |
1269 | const_iv (WEAP_CLEAVE) |
1220 | const_iv (WEAP_SLICE) |
1270 | const_iv (WEAP_SLICE) |
… | |
… | |
1545 | av_push (event, newSViv (eiv->klass)); |
1595 | av_push (event, newSViv (eiv->klass)); |
1546 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1596 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1547 | newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv)); |
1597 | newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv)); |
1548 | } |
1598 | } |
1549 | |
1599 | |
1550 | static const struct { |
|
|
1551 | int dtype; |
|
|
1552 | const char *name; |
|
|
1553 | IV idx; |
|
|
1554 | } *cprop, prop_table[] = { |
|
|
1555 | # define prop(type, name) { type, # name, (IV) CFAPI_ ## name }, |
|
|
1556 | prop (CFAPI_INT, MAP_PROP_FLAGS) |
|
|
1557 | prop (CFAPI_INT, MAP_PROP_DIFFICULTY) |
|
|
1558 | prop (CFAPI_STRING, MAP_PROP_PATH) |
|
|
1559 | prop (CFAPI_STRING, MAP_PROP_TMPNAME) |
|
|
1560 | prop (CFAPI_STRING, MAP_PROP_NAME) |
|
|
1561 | prop (CFAPI_INT, MAP_PROP_RESET_TIME) |
|
|
1562 | prop (CFAPI_INT, MAP_PROP_RESET_TIMEOUT) |
|
|
1563 | prop (CFAPI_INT, MAP_PROP_PLAYERS) |
|
|
1564 | prop (CFAPI_INT, MAP_PROP_DARKNESS) |
|
|
1565 | prop (CFAPI_INT, MAP_PROP_WIDTH) |
|
|
1566 | prop (CFAPI_INT, MAP_PROP_HEIGHT) |
|
|
1567 | prop (CFAPI_INT, MAP_PROP_ENTER_X) |
|
|
1568 | prop (CFAPI_INT, MAP_PROP_ENTER_Y) |
|
|
1569 | prop (CFAPI_INT, MAP_PROP_TEMPERATURE) |
|
|
1570 | prop (CFAPI_INT, MAP_PROP_PRESSURE) |
|
|
1571 | prop (CFAPI_INT, MAP_PROP_HUMIDITY) |
|
|
1572 | prop (CFAPI_INT, MAP_PROP_WINDSPEED) |
|
|
1573 | prop (CFAPI_INT, MAP_PROP_WINDDIR) |
|
|
1574 | prop (CFAPI_INT, MAP_PROP_SKY) |
|
|
1575 | prop (CFAPI_INT, MAP_PROP_WPARTX) |
|
|
1576 | prop (CFAPI_INT, MAP_PROP_WPARTY) |
|
|
1577 | prop (CFAPI_STRING, MAP_PROP_MESSAGE) |
|
|
1578 | prop (CFAPI_PREGION, MAP_PROP_REGION) |
|
|
1579 | prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB) |
|
|
1580 | prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB) |
|
|
1581 | prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY) |
|
|
1582 | prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT) |
|
|
1583 | prop (CFAPI_POBJECT, OBJECT_PROP_CONTAINER) |
|
|
1584 | prop (CFAPI_PMAP, OBJECT_PROP_MAP) |
|
|
1585 | prop (CFAPI_INT, OBJECT_PROP_COUNT) |
|
|
1586 | prop (CFAPI_INT, OBJECT_PROP_REFCOUNT) |
|
|
1587 | prop (CFAPI_STRING, OBJECT_PROP_NAME) |
|
|
1588 | prop (CFAPI_STRING, OBJECT_PROP_NAME_PLURAL) |
|
|
1589 | prop (CFAPI_STRING, OBJECT_PROP_TITLE) |
|
|
1590 | prop (CFAPI_STRING, OBJECT_PROP_RACE) |
|
|
1591 | prop (CFAPI_STRING, OBJECT_PROP_SLAYING) |
|
|
1592 | prop (CFAPI_STRING, OBJECT_PROP_SKILL) |
|
|
1593 | prop (CFAPI_STRING, OBJECT_PROP_MESSAGE) |
|
|
1594 | prop (CFAPI_STRING, OBJECT_PROP_LORE) |
|
|
1595 | prop (CFAPI_INT, OBJECT_PROP_X) |
|
|
1596 | prop (CFAPI_INT, OBJECT_PROP_Y) |
|
|
1597 | prop (CFAPI_DOUBLE, OBJECT_PROP_SPEED) |
|
|
1598 | prop (CFAPI_DOUBLE, OBJECT_PROP_SPEED_LEFT) |
|
|
1599 | prop (CFAPI_INT, OBJECT_PROP_NROF) |
|
|
1600 | prop (CFAPI_INT, OBJECT_PROP_DIRECTION) |
|
|
1601 | prop (CFAPI_INT, OBJECT_PROP_FACING) |
|
|
1602 | prop (CFAPI_INT, OBJECT_PROP_TYPE) |
|
|
1603 | prop (CFAPI_INT, OBJECT_PROP_SUBTYPE) |
|
|
1604 | prop (CFAPI_INT, OBJECT_PROP_CLIENT_TYPE) |
|
|
1605 | prop (CFAPI_INT, OBJECT_PROP_ATTACK_TYPE) |
|
|
1606 | prop (CFAPI_INT, OBJECT_PROP_PATH_ATTUNED) |
|
|
1607 | prop (CFAPI_INT, OBJECT_PROP_PATH_REPELLED) |
|
|
1608 | prop (CFAPI_INT, OBJECT_PROP_PATH_DENIED) |
|
|
1609 | prop (CFAPI_INT, OBJECT_PROP_MATERIAL) |
|
|
1610 | prop (CFAPI_STRING, OBJECT_PROP_MATERIAL_NAME) |
|
|
1611 | prop (CFAPI_INT, OBJECT_PROP_MAGIC) |
|
|
1612 | prop (CFAPI_INT, OBJECT_PROP_VALUE) |
|
|
1613 | prop (CFAPI_INT, OBJECT_PROP_LEVEL) |
|
|
1614 | prop (CFAPI_INT, OBJECT_PROP_LAST_HEAL) |
|
|
1615 | prop (CFAPI_INT, OBJECT_PROP_LAST_SP) |
|
|
1616 | prop (CFAPI_INT, OBJECT_PROP_LAST_GRACE) |
|
|
1617 | prop (CFAPI_INT, OBJECT_PROP_LAST_EAT) |
|
|
1618 | prop (CFAPI_INT, OBJECT_PROP_INVISIBLE_TIME) |
|
|
1619 | prop (CFAPI_INT, OBJECT_PROP_PICK_UP) |
|
|
1620 | prop (CFAPI_INT, OBJECT_PROP_ITEM_POWER) |
|
|
1621 | prop (CFAPI_INT, OBJECT_PROP_GEN_SP_ARMOUR) |
|
|
1622 | prop (CFAPI_INT, OBJECT_PROP_WEIGHT) |
|
|
1623 | prop (CFAPI_INT, OBJECT_PROP_WEIGHT_LIMIT) |
|
|
1624 | prop (CFAPI_INT, OBJECT_PROP_CARRYING) |
|
|
1625 | prop (CFAPI_INT, OBJECT_PROP_GLOW_RADIUS) |
|
|
1626 | prop (CFAPI_LONG, OBJECT_PROP_PERM_EXP) |
|
|
1627 | prop (CFAPI_POBJECT, OBJECT_PROP_CURRENT_WEAPON) |
|
|
1628 | prop (CFAPI_POBJECT, OBJECT_PROP_ENEMY) |
|
|
1629 | prop (CFAPI_POBJECT, OBJECT_PROP_ATTACKED_BY) |
|
|
1630 | prop (CFAPI_INT, OBJECT_PROP_RUN_AWAY) |
|
|
1631 | prop (CFAPI_POBJECT, OBJECT_PROP_CHOSEN_SKILL) |
|
|
1632 | prop (CFAPI_INT, OBJECT_PROP_HIDDEN) |
|
|
1633 | prop (CFAPI_INT, OBJECT_PROP_MOVE_STATUS) |
|
|
1634 | prop (CFAPI_INT, OBJECT_PROP_MOVE_TYPE) |
|
|
1635 | prop (CFAPI_POBJECT, OBJECT_PROP_SPELL_ITEM) |
|
|
1636 | prop (CFAPI_DOUBLE, OBJECT_PROP_EXP_MULTIPLIER) |
|
|
1637 | prop (CFAPI_PARCH, OBJECT_PROP_ARCHETYPE) |
|
|
1638 | prop (CFAPI_PARCH, OBJECT_PROP_OTHER_ARCH) |
|
|
1639 | prop (CFAPI_STRING, OBJECT_PROP_CUSTOM_NAME) |
|
|
1640 | prop (CFAPI_INT, OBJECT_PROP_ANIM_SPEED) |
|
|
1641 | prop (CFAPI_INT, OBJECT_PROP_FRIENDLY) |
|
|
1642 | prop (CFAPI_STRING, OBJECT_PROP_SHORT_NAME) |
|
|
1643 | prop (CFAPI_INT, OBJECT_PROP_MAGICAL) |
|
|
1644 | prop (CFAPI_INT, OBJECT_PROP_LUCK) |
|
|
1645 | prop (CFAPI_POBJECT, OBJECT_PROP_OWNER) |
|
|
1646 | prop (CFAPI_POBJECT, OBJECT_PROP_PRESENT) |
|
|
1647 | prop (CFAPI_INT, OBJECT_PROP_CHEATER) |
|
|
1648 | prop (CFAPI_INT, OBJECT_PROP_MERGEABLE) |
|
|
1649 | prop (CFAPI_INT, OBJECT_PROP_PICKABLE) |
|
|
1650 | prop (CFAPI_INT, OBJECT_PROP_STR) |
|
|
1651 | prop (CFAPI_INT, OBJECT_PROP_DEX) |
|
|
1652 | prop (CFAPI_INT, OBJECT_PROP_CON) |
|
|
1653 | prop (CFAPI_INT, OBJECT_PROP_WIS) |
|
|
1654 | prop (CFAPI_INT, OBJECT_PROP_INT) |
|
|
1655 | prop (CFAPI_INT, OBJECT_PROP_POW) |
|
|
1656 | prop (CFAPI_INT, OBJECT_PROP_CHA) |
|
|
1657 | prop (CFAPI_INT, OBJECT_PROP_WC) |
|
|
1658 | prop (CFAPI_INT, OBJECT_PROP_AC) |
|
|
1659 | prop (CFAPI_INT, OBJECT_PROP_HP) |
|
|
1660 | prop (CFAPI_INT, OBJECT_PROP_SP) |
|
|
1661 | prop (CFAPI_INT, OBJECT_PROP_GP) |
|
|
1662 | prop (CFAPI_INT, OBJECT_PROP_FP) |
|
|
1663 | prop (CFAPI_INT, OBJECT_PROP_MAXHP) |
|
|
1664 | prop (CFAPI_INT, OBJECT_PROP_MAXSP) |
|
|
1665 | prop (CFAPI_INT, OBJECT_PROP_MAXGP) |
|
|
1666 | prop (CFAPI_INT, OBJECT_PROP_DAM) |
|
|
1667 | prop (CFAPI_STRING, OBJECT_PROP_GOD) |
|
|
1668 | prop (CFAPI_STRING, OBJECT_PROP_ARCH_NAME) |
|
|
1669 | prop (CFAPI_INT, OBJECT_PROP_INVISIBLE) |
|
|
1670 | prop (CFAPI_INT, OBJECT_PROP_FACE) |
|
|
1671 | }; |
|
|
1672 | |
|
|
1673 | HV *prop_type = get_hv ("cf::PROP_TYPE", 1); |
|
|
1674 | HV *prop_idx = get_hv ("cf::PROP_IDX", 1); |
|
|
1675 | |
|
|
1676 | for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) |
|
|
1677 | { |
|
|
1678 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
|
|
1679 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
|
|
1680 | } |
|
|
1681 | |
|
|
1682 | //I_EVENT_API (PACKAGE); |
1600 | //I_EVENT_API (PACKAGE); |
1683 | } |
1601 | } |
1684 | |
1602 | |
1685 | void _reload_1 () |
1603 | void _init_vars () |
1686 | CODE: |
1604 | CODE: |
1687 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1605 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1688 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1606 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1689 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1607 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1690 | cb_type = get_av ("cf::CB_TYPE" , 1); |
1608 | cb_type = get_av ("cf::CB_TYPE" , 1); |
1691 | cb_map = get_av ("cf::CB_MAP" , 1); |
1609 | cb_map = get_av ("cf::CB_MAP" , 1); |
1692 | |
1610 | |
1693 | void _reload_2 () |
1611 | void _global_reattach () |
1694 | CODE: |
1612 | CODE: |
1695 | { |
1613 | { |
1696 | // reattach to all attachable objects in the game. |
1614 | // reattach to all attachable objects in the game. |
1697 | for (player *pl = first_player; pl; pl = pl->next) |
1615 | for (player *pl = first_player; pl; pl = pl->next) |
1698 | reattach (pl); |
1616 | reattach (pl); |
… | |
… | |
1834 | CODE: |
1752 | CODE: |
1835 | RETVAL = registry_of (op); |
1753 | RETVAL = registry_of (op); |
1836 | OUTPUT: |
1754 | OUTPUT: |
1837 | RETVAL |
1755 | RETVAL |
1838 | |
1756 | |
1839 | object *head (object *op) |
1757 | INCLUDE: $PERL genacc object ../include/object.h | |
1840 | PROTOTYPE: $ |
|
|
1841 | ALIAS: |
|
|
1842 | more = 1 |
|
|
1843 | above = 2 |
|
|
1844 | below = 3 |
|
|
1845 | CODE: |
|
|
1846 | switch (ix) |
|
|
1847 | { |
|
|
1848 | case 0: RETVAL = op->head ? op->head : op; break; // DOH! |
|
|
1849 | case 1: RETVAL = op->more; break; |
|
|
1850 | case 2: RETVAL = op->above; break; |
|
|
1851 | case 3: RETVAL = op->below; break; |
|
|
1852 | } |
|
|
1853 | OUTPUT: |
|
|
1854 | RETVAL |
|
|
1855 | |
|
|
1856 | SV * |
|
|
1857 | get_property (object *obj, int type, int idx) |
|
|
1858 | CODE: |
|
|
1859 | RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx)); |
|
|
1860 | OUTPUT: RETVAL |
|
|
1861 | |
|
|
1862 | SV * |
|
|
1863 | set_property (object *obj, int type, int idx, SV *newval) |
|
|
1864 | CODE: |
|
|
1865 | switch (type) |
|
|
1866 | { |
|
|
1867 | case CFAPI_INT: |
|
|
1868 | cf_object_set_int_property (obj, idx, SvIV (newval)); |
|
|
1869 | break; |
|
|
1870 | case CFAPI_LONG: |
|
|
1871 | cf_object_set_long_property (obj, idx, (long) SvVAL64 (newval)); |
|
|
1872 | break; |
|
|
1873 | case CFAPI_DOUBLE: |
|
|
1874 | { |
|
|
1875 | int unused_type; |
|
|
1876 | object_set_property (&unused_type, obj, idx, (double)SvNV (newval)); |
|
|
1877 | } |
|
|
1878 | break; |
|
|
1879 | case CFAPI_STRING: |
|
|
1880 | cf_object_set_string_property (obj, idx, SvOK (newval) ? SvPV_nolen (newval) : 0); |
|
|
1881 | break; |
|
|
1882 | case CFAPI_POBJECT: |
|
|
1883 | { |
|
|
1884 | int unused_type; |
|
|
1885 | object_set_property (&unused_type, obj, idx, (object *)SvPTR_ornull (newval, "cf::object")); |
|
|
1886 | } |
|
|
1887 | break; |
|
|
1888 | default: |
|
|
1889 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
|
|
1890 | } |
|
|
1891 | |
1758 | |
1892 | # missing properties |
1759 | # missing properties |
1893 | |
1760 | |
1894 | void |
1761 | int flag (object *op, int flag, int value = 1) |
1895 | set_attacktype (object *obj, U32 attacktype) |
1762 | PROTOTYPE: $$;$ |
1896 | CODE: |
1763 | CODE: |
1897 | obj->attacktype = attacktype; |
1764 | RETVAL = QUERY_FLAG (op, flag); |
1898 | |
1765 | if (items >= 3) |
1899 | U32 |
1766 | if (value) |
1900 | get_attacktype (object *obj) |
1767 | SET_FLAG (op, flag); |
1901 | ALIAS: |
1768 | else |
1902 | attacktype = 0 |
1769 | CLEAR_FLAG (op, flag); |
1903 | CODE: |
|
|
1904 | RETVAL = obj->attacktype; |
|
|
1905 | OUTPUT: RETVAL |
1770 | OUTPUT: RETVAL |
1906 | |
|
|
1907 | # missing in plug-in api, of course |
|
|
1908 | void |
|
|
1909 | set_food (object *obj, int food) |
|
|
1910 | CODE: |
|
|
1911 | obj->stats.food = food; |
|
|
1912 | |
|
|
1913 | int |
|
|
1914 | get_food (object *obj) |
|
|
1915 | ALIAS: |
|
|
1916 | food = 0 |
|
|
1917 | CODE: |
|
|
1918 | RETVAL = obj->stats.food; |
|
|
1919 | OUTPUT: RETVAL |
|
|
1920 | |
1771 | |
1921 | void |
1772 | void |
1922 | inv (object *obj) |
1773 | inv (object *obj) |
1923 | PROTOTYPE: $ |
1774 | PROTOTYPE: $ |
1924 | PPCODE: |
1775 | PPCODE: |
… | |
… | |
1929 | } |
1780 | } |
1930 | |
1781 | |
1931 | int cf_object_get_resistance (object *op, int rtype) |
1782 | int cf_object_get_resistance (object *op, int rtype) |
1932 | ALIAS: resistance = 0 |
1783 | ALIAS: resistance = 0 |
1933 | |
1784 | |
1934 | int cf_object_get_flag (object *op, int flag) |
|
|
1935 | ALIAS: flag = 0 |
|
|
1936 | |
|
|
1937 | void cf_object_set_flag (object *op, int flag, int value) |
|
|
1938 | |
|
|
1939 | int need_identify (const object *obj); |
1785 | int need_identify (const object *obj); |
1940 | |
1786 | |
1941 | int apply_shop_mat (object *shop_mat, object *op); |
1787 | int apply_shop_mat (object *shop_mat, object *op); |
1942 | |
1788 | |
1943 | int move (object *op, int dir, object *originator = op) |
1789 | int move (object *op, int dir, object *originator = op) |
… | |
… | |
1995 | void cf_object_drop (object *op, object *author) |
1841 | void cf_object_drop (object *op, object *author) |
1996 | |
1842 | |
1997 | void cf_object_take (object *op, object *author) |
1843 | void cf_object_take (object *op, object *author) |
1998 | |
1844 | |
1999 | object *cf_object_insert_object (object *op, object *container) |
1845 | object *cf_object_insert_object (object *op, object *container) |
2000 | |
|
|
2001 | const char *cf_object_get_msg (object *ob) |
|
|
2002 | ALIAS: msg = 0 |
|
|
2003 | |
1846 | |
2004 | object *cf_object_insert_in_ob (object *ob, object *where) |
1847 | object *cf_object_insert_in_ob (object *ob, object *where) |
2005 | |
1848 | |
2006 | int cf_object_teleport (object *op, mapstruct *map, int x, int y) |
1849 | int cf_object_teleport (object *op, mapstruct *map, int x, int y) |
2007 | |
1850 | |
… | |
… | |
2103 | base_name (object *ob, int plural) |
1946 | base_name (object *ob, int plural) |
2104 | CODE: |
1947 | CODE: |
2105 | RETVAL = cf_query_base_name (ob, plural); |
1948 | RETVAL = cf_query_base_name (ob, plural); |
2106 | OUTPUT: RETVAL |
1949 | OUTPUT: RETVAL |
2107 | |
1950 | |
2108 | living * |
|
|
2109 | stats (object *ob) |
|
|
2110 | CODE: |
|
|
2111 | RETVAL = &ob->stats; |
|
|
2112 | OUTPUT: RETVAL |
|
|
2113 | |
|
|
2114 | |
|
|
2115 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1951 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
2116 | |
1952 | |
2117 | player *player (object *op) |
1953 | player *player (object *op) |
2118 | CODE: |
1954 | CODE: |
2119 | RETVAL = op->contr; |
1955 | RETVAL = op->contr; |
… | |
… | |
2230 | if (new_value >= 0) |
2066 | if (new_value >= 0) |
2231 | pl->listening = new_value; |
2067 | pl->listening = new_value; |
2232 | OUTPUT: |
2068 | OUTPUT: |
2233 | RETVAL |
2069 | RETVAL |
2234 | |
2070 | |
2235 | void get_savebed (player *pl) |
2071 | void savebed (player *pl, SV *map_path = 0, SV *x = 0, SV *y = 0) |
2236 | ALIAS: |
2072 | PROTOTYPE: $;$$$ |
2237 | savebed = 0 |
|
|
2238 | PPCODE: |
2073 | PPCODE: |
|
|
2074 | if (GIMME_V != G_VOID) |
|
|
2075 | { |
2239 | EXTEND (SP, 3); |
2076 | EXTEND (SP, 3); |
2240 | PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0))); |
2077 | PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0))); |
2241 | PUSHs (sv_2mortal (newSViv (pl->bed_x))); |
2078 | PUSHs (sv_2mortal (newSViv (pl->bed_x))); |
2242 | PUSHs (sv_2mortal (newSViv (pl->bed_y))); |
2079 | PUSHs (sv_2mortal (newSViv (pl->bed_y))); |
2243 | |
2080 | } |
2244 | void set_savebed (player *pl, char *map_path, int x, int y) |
2081 | if (map_path) sv_to (map_path, pl->savebed_map); |
2245 | CODE: |
2082 | if (x) sv_to (x, pl->bed_x); |
2246 | strcpy (pl->savebed_map, map_path); |
2083 | if (y) sv_to (y, pl->bed_y); |
2247 | pl->bed_x = x; |
|
|
2248 | pl->bed_y = y; |
|
|
2249 | |
2084 | |
2250 | void |
2085 | void |
2251 | list () |
2086 | list () |
2252 | PPCODE: |
2087 | PPCODE: |
2253 | { |
2088 | { |
… | |
… | |
2285 | PROTOTYPE: |
2120 | PROTOTYPE: |
2286 | CODE: |
2121 | CODE: |
2287 | RETVAL = first_map; |
2122 | RETVAL = first_map; |
2288 | OUTPUT: RETVAL |
2123 | OUTPUT: RETVAL |
2289 | |
2124 | |
2290 | mapstruct *next (mapstruct *map) |
|
|
2291 | PROTOTYPE: |
|
|
2292 | CODE: |
|
|
2293 | RETVAL = map->next; |
|
|
2294 | OUTPUT: RETVAL |
|
|
2295 | |
|
|
2296 | int invoke (mapstruct *map, int event, ...) |
2125 | int invoke (mapstruct *map, int event, ...) |
2297 | CODE: |
2126 | CODE: |
2298 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2127 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2299 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2128 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2300 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2129 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
… | |
… | |
2305 | CODE: |
2134 | CODE: |
2306 | RETVAL = registry_of (map); |
2135 | RETVAL = registry_of (map); |
2307 | OUTPUT: |
2136 | OUTPUT: |
2308 | RETVAL |
2137 | RETVAL |
2309 | |
2138 | |
2310 | SV * |
2139 | INCLUDE: $PERL genacc mapstruct ../include/map.h | |
2311 | get_property (mapstruct *obj, int type, int idx) |
|
|
2312 | CODE: |
|
|
2313 | RETVAL = newSVcfapi (type, cf_map_get_property (obj, idx)); |
|
|
2314 | OUTPUT: RETVAL |
|
|
2315 | |
|
|
2316 | SV * |
|
|
2317 | set_property (mapstruct *obj, int type, int idx, SV *newval) |
|
|
2318 | CODE: |
|
|
2319 | switch (type) |
|
|
2320 | { |
|
|
2321 | case CFAPI_INT: |
|
|
2322 | cf_map_set_int_property (obj, idx, SvIV (newval)); |
|
|
2323 | break; |
|
|
2324 | default: |
|
|
2325 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
|
|
2326 | } |
|
|
2327 | |
2140 | |
2328 | mapstruct *new (int width, int height) |
2141 | mapstruct *new (int width, int height) |
2329 | PROTOTYPE: |
2142 | PROTOTYPE: |
2330 | CODE: |
2143 | CODE: |
2331 | { |
2144 | { |
… | |
… | |
2361 | get_map = 1 |
2174 | get_map = 1 |
2362 | |
2175 | |
2363 | mapstruct *has_been_loaded (char *name) |
2176 | mapstruct *has_been_loaded (char *name) |
2364 | PROTOTYPE: $ |
2177 | PROTOTYPE: $ |
2365 | |
2178 | |
2366 | # whoever "designed" the plug-in api should have wasted |
|
|
2367 | # his/her time with staying away from the project - would have |
|
|
2368 | # saved others a lot of time, without doubt. |
|
|
2369 | void set_path (mapstruct *where, char *path) |
|
|
2370 | CODE: |
|
|
2371 | strcpy (where->path, path); |
|
|
2372 | |
|
|
2373 | int in_memory (mapstruct *map) |
2179 | int in_memory (mapstruct *map) |
2374 | CODE: |
2180 | CODE: |
2375 | RETVAL = map->in_memory; |
2181 | RETVAL = map->in_memory; |
2376 | OUTPUT: |
2182 | OUTPUT: |
2377 | RETVAL |
2183 | RETVAL |
2378 | |
|
|
2379 | bool unique (mapstruct *map) |
|
|
2380 | CODE: |
|
|
2381 | RETVAL = map->unique; |
|
|
2382 | OUTPUT: |
|
|
2383 | RETVAL |
|
|
2384 | |
|
|
2385 | void set_unique (mapstruct *map, bool unique) |
|
|
2386 | CODE: |
|
|
2387 | map->unique = unique; |
|
|
2388 | |
2184 | |
2389 | void |
2185 | void |
2390 | trigger (mapstruct *map, long connection, bool state = true) |
2186 | trigger (mapstruct *map, long connection, bool state = true) |
2391 | CODE: |
2187 | CODE: |
2392 | activate_connection (map, connection, state); |
2188 | activate_connection (map, connection, state); |
… | |
… | |
2482 | PROTOTYPE: |
2278 | PROTOTYPE: |
2483 | CODE: |
2279 | CODE: |
2484 | RETVAL = first_archetype; |
2280 | RETVAL = first_archetype; |
2485 | OUTPUT: RETVAL |
2281 | OUTPUT: RETVAL |
2486 | |
2282 | |
2487 | archetype *next (archetype *arch) |
2283 | INCLUDE: $PERL genacc archetype ../include/object.h | |
2488 | CODE: |
|
|
2489 | RETVAL = arch->next; |
|
|
2490 | OUTPUT: RETVAL |
|
|
2491 | |
|
|
2492 | archetype *head (archetype *arch) |
|
|
2493 | CODE: |
|
|
2494 | RETVAL = arch->head; |
|
|
2495 | OUTPUT: RETVAL |
|
|
2496 | |
|
|
2497 | archetype *more (archetype *arch) |
|
|
2498 | CODE: |
|
|
2499 | RETVAL = arch->more; |
|
|
2500 | OUTPUT: RETVAL |
|
|
2501 | |
|
|
2502 | const char *name (archetype *arch) |
|
|
2503 | CODE: |
|
|
2504 | RETVAL = arch->name; |
|
|
2505 | OUTPUT: RETVAL |
|
|
2506 | |
|
|
2507 | object *clone (archetype *arch) |
|
|
2508 | CODE: |
|
|
2509 | RETVAL = &arch->clone; |
|
|
2510 | OUTPUT: RETVAL |
|
|
2511 | |
2284 | |
2512 | MODULE = cf PACKAGE = cf::party |
2285 | MODULE = cf PACKAGE = cf::party |
2513 | |
2286 | |
2514 | partylist *first () |
2287 | partylist *first () |
2515 | PROTOTYPE: |
2288 | PROTOTYPE: |
… | |
… | |
2565 | RETVAL = reg->msg; |
2338 | RETVAL = reg->msg; |
2566 | OUTPUT: RETVAL |
2339 | OUTPUT: RETVAL |
2567 | |
2340 | |
2568 | MODULE = cf PACKAGE = cf::living |
2341 | MODULE = cf PACKAGE = cf::living |
2569 | |
2342 | |
2570 | val64 |
2343 | INCLUDE: $PERL genacc living ../include/living.h | |
2571 | exp (living *liv, val64 new_val = 0) |
|
|
2572 | PROTOTYPE: $;$ |
|
|
2573 | ALIAS: |
|
|
2574 | Str = 1 |
|
|
2575 | Dex = 2 |
|
|
2576 | Con = 3 |
|
|
2577 | Wis = 4 |
|
|
2578 | Cha = 5 |
|
|
2579 | Int = 6 |
|
|
2580 | Pow = 7 |
|
|
2581 | wc = 8 |
|
|
2582 | ac = 9 |
|
|
2583 | hp = 10 |
|
|
2584 | maxhp = 11 |
|
|
2585 | sp = 12 |
|
|
2586 | maxsp = 13 |
|
|
2587 | grace = 14 |
|
|
2588 | maxgrace = 15 |
|
|
2589 | food = 16 |
|
|
2590 | dam = 17 |
|
|
2591 | luck = 18 |
|
|
2592 | CODE: |
|
|
2593 | # define LIVING_ACC(acc,idx) case idx: RETVAL = liv->acc; if (items > 1) liv->acc = (sint64)new_val; break |
|
|
2594 | switch (ix) |
|
|
2595 | { |
|
|
2596 | LIVING_ACC (exp , 0); |
|
|
2597 | LIVING_ACC (Str , 1); |
|
|
2598 | LIVING_ACC (Dex , 2); |
|
|
2599 | LIVING_ACC (Con , 3); |
|
|
2600 | LIVING_ACC (Wis , 4); |
|
|
2601 | LIVING_ACC (Cha , 5); |
|
|
2602 | LIVING_ACC (Int , 6); |
|
|
2603 | LIVING_ACC (Pow , 7); |
|
|
2604 | LIVING_ACC (wc , 8); |
|
|
2605 | LIVING_ACC (ac , 9); |
|
|
2606 | LIVING_ACC (hp , 10); |
|
|
2607 | LIVING_ACC (maxhp , 11); |
|
|
2608 | LIVING_ACC (sp , 12); |
|
|
2609 | LIVING_ACC (maxsp , 13); |
|
|
2610 | LIVING_ACC (grace , 14); |
|
|
2611 | LIVING_ACC (maxgrace, 15); |
|
|
2612 | LIVING_ACC (food , 16); |
|
|
2613 | LIVING_ACC (dam , 17); |
|
|
2614 | LIVING_ACC (luck , 18); |
|
|
2615 | } |
|
|
2616 | # undef LIVING_ACC |
|
|
2617 | OUTPUT: |
|
|
2618 | RETVAL |
|
|
2619 | |
2344 | |