1 | /*****************************************************************************/ |
1 | /*****************************************************************************/ |
2 | /* That code is placed under the GNU General Public Licence (GPL) */ |
|
|
3 | /* (C)2001-2005 by Chachkoff Yann (Feel free to deliver your complaints) */ |
|
|
4 | /*****************************************************************************/ |
|
|
5 | /* CrossFire, A Multiplayer game for X-windows */ |
2 | /* CrossFire, A Multiplayer game for the X Window System */ |
6 | /* */ |
|
|
7 | /* Copyright (C) 2000 Mark Wedel */ |
|
|
8 | /* Copyright (C) 1992 Frank Tore Johansen */ |
|
|
9 | /* Copyright (C) 2006 perl plugin by Marc Lehmann <cf@schmorpd.e> */ |
|
|
10 | /* */ |
|
|
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 */ |
|
|
13 | /* the Free Software Foundation; either version 2 of the License, or */ |
|
|
14 | /* (at your option) any later version. */ |
|
|
15 | /* */ |
|
|
16 | /* This program is distributed in the hope that it will be useful, */ |
|
|
17 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
|
|
18 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
|
|
19 | /* GNU General Public License for more details. */ |
|
|
20 | /* */ |
|
|
21 | /* You should have received a copy of the GNU General Public License */ |
|
|
22 | /* along with this program; if not, write to the Free Software */ |
|
|
23 | /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
|
|
24 | /* */ |
3 | /* */ |
25 | /*****************************************************************************/ |
4 | /*****************************************************************************/ |
|
|
5 | |
|
|
6 | /* |
|
|
7 | * This code is placed under the GNU General Public Licence (GPL) |
|
|
8 | * |
|
|
9 | * Copyright (C) 2001-2005 by Chachkoff Yann |
|
|
10 | * Copyright (C) 2006 by Marc Lehmann <cf@schmorpd.e> |
|
|
11 | * |
|
|
12 | * This program is free software; you can redistribute it and/or modify |
|
|
13 | * it under the terms of the GNU General Public License as published by |
|
|
14 | * the Free Software Foundation; either version 2 of the License, or |
|
|
15 | * (at your option) any later version. |
|
|
16 | * |
|
|
17 | * This program is distributed in the hope that it will be useful, |
|
|
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
20 | * GNU General Public License for more details. |
|
|
21 | * |
|
|
22 | * You should have received a copy of the GNU General Public License |
|
|
23 | * along with this program; if not, write to the Free Software |
|
|
24 | * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
|
25 | */ |
26 | |
26 | |
27 | #include <EXTERN.h> |
27 | #include <EXTERN.h> |
28 | #include <perl.h> |
28 | #include <perl.h> |
29 | #include <XSUB.h> |
29 | #include <XSUB.h> |
30 | |
30 | |
… | |
… | |
51 | |
51 | |
52 | static f_plug_api gethook; |
52 | static f_plug_api gethook; |
53 | static f_plug_api registerGlobalEvent; |
53 | static f_plug_api registerGlobalEvent; |
54 | static f_plug_api unregisterGlobalEvent; |
54 | static f_plug_api unregisterGlobalEvent; |
55 | static f_plug_api systemDirectory; |
55 | static f_plug_api systemDirectory; |
|
|
56 | static f_plug_api object_set_property; |
|
|
57 | static f_plug_api map_get_map; |
56 | |
58 | |
57 | typedef struct |
59 | typedef struct |
58 | { |
60 | { |
59 | object* who; |
61 | object* who; |
60 | object* activator; |
62 | object* activator; |
… | |
… | |
128 | case CFAPI_DOUBLE: |
130 | case CFAPI_DOUBLE: |
129 | sv = newSViv (*va_arg (args, double *)); |
131 | sv = newSViv (*va_arg (args, double *)); |
130 | break; |
132 | break; |
131 | |
133 | |
132 | case CFAPI_STRING: |
134 | case CFAPI_STRING: |
133 | sv = newSVpv (va_arg (args, char *), 0); |
135 | { |
|
|
136 | char *str = va_arg (args, char *); |
|
|
137 | sv = str ? newSVpv (str, 0) : &PL_sv_undef; |
|
|
138 | } |
134 | break; |
139 | break; |
135 | |
140 | |
136 | case CFAPI_POBJECT: |
141 | case CFAPI_POBJECT: |
137 | { |
142 | { |
138 | object *obj = va_arg (args, object *); |
143 | object *obj = va_arg (args, object *); |
… | |
… | |
331 | printf (PLUGIN_VERSION " post init\n"); |
336 | printf (PLUGIN_VERSION " post init\n"); |
332 | |
337 | |
333 | registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); |
338 | registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); |
334 | unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); |
339 | unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); |
335 | systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); |
340 | systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); |
|
|
341 | object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property"); |
|
|
342 | map_get_map = gethook (&rtype, hooktype, "cfapi_map_get_map"); |
|
|
343 | |
336 | cf_init_plugin (gethook); |
344 | cf_init_plugin (gethook); |
337 | |
345 | |
338 | /* Pick the global events you want to monitor from this plugin */ |
346 | /* Pick the global events you want to monitor from this plugin */ |
339 | registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); |
347 | registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); |
340 | registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener); |
348 | registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener); |
… | |
… | |
540 | |
548 | |
541 | BOOT: |
549 | BOOT: |
542 | { |
550 | { |
543 | HV *stash = gv_stashpv ("cf", 1); |
551 | HV *stash = gv_stashpv ("cf", 1); |
544 | |
552 | |
545 | const struct { |
553 | static const struct { |
546 | const char *name; |
554 | const char *name; |
547 | IV iv; |
555 | IV iv; |
548 | } *civ, const_iv[] = { |
556 | } *civ, const_iv[] = { |
549 | # define const_iv(name) { # name, (IV)name }, |
557 | # define const_iv(name) { # name, (IV)name }, |
550 | const_iv (llevError) |
558 | const_iv (llevError) |
… | |
… | |
829 | const_iv (F_CURSED) |
837 | const_iv (F_CURSED) |
830 | const_iv (F_DAMNED) |
838 | const_iv (F_DAMNED) |
831 | const_iv (F_OPEN) |
839 | const_iv (F_OPEN) |
832 | const_iv (F_NOPICK) |
840 | const_iv (F_NOPICK) |
833 | const_iv (F_LOCKED) |
841 | const_iv (F_LOCKED) |
|
|
842 | |
|
|
843 | const_iv (P_BLOCKSVIEW) |
|
|
844 | const_iv (P_NO_MAGIC) |
|
|
845 | const_iv (P_IS_ALIVE) |
|
|
846 | const_iv (P_NO_CLERIC) |
|
|
847 | const_iv (P_NEED_UPDATE) |
|
|
848 | const_iv (P_NO_ERROR) |
|
|
849 | const_iv (P_OUT_OF_MAP) |
|
|
850 | const_iv (P_NEW_MAP) |
834 | }; |
851 | }; |
835 | |
852 | |
836 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
853 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
837 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
854 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
838 | |
855 | |
839 | const struct { |
856 | static const struct { |
840 | const char *name; |
857 | const char *name; |
841 | IV iv; |
858 | IV iv; |
842 | } *event, event_list[] = { |
859 | } *event, event_list[] = { |
843 | # define const_event(name) { # name, (IV)EVENT_ ## name }, |
860 | # define const_event(name) { # name, (IV)EVENT_ ## name }, |
844 | const_event (NONE) |
861 | const_event (NONE) |
… | |
… | |
875 | AV *av = get_av ("cf::EVENT", 1); |
892 | AV *av = get_av ("cf::EVENT", 1); |
876 | |
893 | |
877 | for (event = event_list + sizeof (event_list) / sizeof (event_list [0]); event-- > event_list; ) |
894 | for (event = event_list + sizeof (event_list) / sizeof (event_list [0]); event-- > event_list; ) |
878 | av_store (av, event->iv, newSVpv ((char *)event->name, 0)); |
895 | av_store (av, event->iv, newSVpv ((char *)event->name, 0)); |
879 | |
896 | |
880 | const struct { |
897 | static const struct { |
881 | int dtype; |
898 | int dtype; |
882 | const char *name; |
899 | const char *name; |
883 | IV idx; |
900 | IV idx; |
884 | } *cprop, prop_table[] = { |
901 | } *cprop, prop_table[] = { |
885 | # define prop(type, name) { type, # name, (IV) CFAPI_ ## name }, |
902 | # define prop(type, name) { type, # name, (IV) CFAPI_ ## name }, |
… | |
… | |
1064 | cf_object_set_int_property (obj, idx, SvIV (newval)); |
1081 | cf_object_set_int_property (obj, idx, SvIV (newval)); |
1065 | break; |
1082 | break; |
1066 | case CFAPI_LONG: |
1083 | case CFAPI_LONG: |
1067 | cf_object_set_long_property (obj, idx, SvNV (newval)); |
1084 | cf_object_set_long_property (obj, idx, SvNV (newval)); |
1068 | break; |
1085 | break; |
|
|
1086 | case CFAPI_DOUBLE: |
|
|
1087 | { |
|
|
1088 | int unused_type; |
|
|
1089 | object_set_property (&unused_type, obj, idx, (double)SvNV (newval)); |
|
|
1090 | } |
|
|
1091 | break; |
1069 | case CFAPI_STRING: |
1092 | case CFAPI_STRING: |
1070 | cf_object_set_string_property (obj, idx, SvPV_nolen (newval)); |
1093 | cf_object_set_string_property (obj, idx, SvPV_nolen (newval)); |
1071 | break; |
1094 | break; |
1072 | default: |
1095 | default: |
1073 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
1096 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
… | |
… | |
1157 | RETVAL = cf_query_base_name (ob, plural); |
1180 | RETVAL = cf_query_base_name (ob, plural); |
1158 | OUTPUT: RETVAL |
1181 | OUTPUT: RETVAL |
1159 | |
1182 | |
1160 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1183 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1161 | |
1184 | |
1162 | object *cf_create_object () |
|
|
1163 | PROTOTYPE: |
|
|
1164 | ALIAS: new = 0 |
|
|
1165 | |
|
|
1166 | object *cf_create_object_by_name (const char *name) |
1185 | object *cf_create_object_by_name (const char *name = 0) |
1167 | PROTOTYPE: $ |
1186 | PROTOTYPE: ;$ |
1168 | ALIAS: new_from_name = 0 |
1187 | ALIAS: |
1169 | |
1188 | create_object = 0 |
1170 | void cf_free_object (object *ob) |
1189 | new = 0 |
|
|
1190 | CODE: |
|
|
1191 | RETVAL = name ? cf_create_object_by_name (name) : cf_create_object (); |
|
|
1192 | OUTPUT: |
|
|
1193 | RETVAL |
1171 | |
1194 | |
1172 | void cf_fix_object (object *pl) |
1195 | void cf_fix_object (object *pl) |
|
|
1196 | ALIAS: fix = 0 |
1173 | |
1197 | |
1174 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1198 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1175 | |
1199 | |
1176 | |
1200 | |
1177 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1201 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
… | |
… | |
1233 | break; |
1257 | break; |
1234 | default: |
1258 | default: |
1235 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
1259 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
1236 | } |
1260 | } |
1237 | |
1261 | |
|
|
1262 | mapstruct *new (int width, int height) |
|
|
1263 | PROTOTYPE: |
|
|
1264 | CODE: |
|
|
1265 | { |
|
|
1266 | int unused_type; |
|
|
1267 | RETVAL = map_get_map (&unused_type, 0, width, height); |
|
|
1268 | } |
|
|
1269 | OUTPUT: |
|
|
1270 | RETVAL |
|
|
1271 | |
1238 | mapstruct *cf_map_get_map (char *name) |
1272 | mapstruct *cf_map_get_map (char *name) |
1239 | PROTOTYPE: $ |
1273 | PROTOTYPE: $ |
1240 | ALIAS: map = 0 |
1274 | ALIAS: map = 0 |
1241 | |
1275 | |
1242 | mapstruct *cf_map_get_first () |
1276 | mapstruct *cf_map_get_first () |
… | |
… | |
1250 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1284 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1251 | C_ARGS: str, map, nx, ny |
1285 | C_ARGS: str, map, nx, ny |
1252 | |
1286 | |
1253 | #int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny) |
1287 | #int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny) |
1254 | |
1288 | |
|
|
1289 | SV *at (mapstruct *obj, unsigned int x, unsigned int y) |
|
|
1290 | PROTOTYPE: $$$ |
|
|
1291 | INIT: |
|
|
1292 | if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_UNDEF; |
|
|
1293 | PPCODE: |
|
|
1294 | { |
|
|
1295 | object *o; |
|
|
1296 | for (o = GET_MAP_OB (obj, x, y); o; o = o->above) |
|
|
1297 | XPUSHs (newSVcfapi (CFAPI_POBJECT, o)); |
|
|
1298 | } |
|
|
1299 | |
|
|
1300 | SV *bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
|
|
1301 | PROTOTYPE: $$$ |
|
|
1302 | ALIAS: |
|
|
1303 | top_at = 1 |
|
|
1304 | flags_at = 2 |
|
|
1305 | light_at = 3 |
|
|
1306 | move_block_at = 4 |
|
|
1307 | move_slow_at = 5 |
|
|
1308 | move_on_at = 6 |
|
|
1309 | move_off_at = 7 |
|
|
1310 | INIT: |
|
|
1311 | if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_UNDEF; |
|
|
1312 | CODE: |
|
|
1313 | switch (ix) |
|
|
1314 | { |
|
|
1315 | case 0: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_OB (obj, x, y)); break; |
|
|
1316 | case 1: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_TOP (obj, x, y)); break; |
|
|
1317 | case 2: RETVAL = newSVuv ( GET_MAP_FLAGS (obj, x, y)); break; |
|
|
1318 | case 3: RETVAL = newSViv ( GET_MAP_LIGHT (obj, x, y)); break; |
|
|
1319 | case 4: RETVAL = newSVuv ( GET_MAP_MOVE_BLOCK (obj, x, y)); break; |
|
|
1320 | case 5: RETVAL = newSVuv ( GET_MAP_MOVE_SLOW (obj, x, y)); break; |
|
|
1321 | case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break; |
|
|
1322 | case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; |
|
|
1323 | } |
|
|
1324 | OUTPUT: |
|
|
1325 | RETVAL |
1255 | |
1326 | |
1256 | |
1327 | |
1257 | MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ |
1328 | MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ |
1258 | |
1329 | |
1259 | archetype*cf_archetype_get_first() |
1330 | archetype*cf_archetype_get_first() |