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; |
56 | |
57 | |
57 | typedef struct |
58 | typedef struct |
58 | { |
59 | { |
59 | object* who; |
60 | object* who; |
60 | object* activator; |
61 | object* activator; |
… | |
… | |
128 | case CFAPI_DOUBLE: |
129 | case CFAPI_DOUBLE: |
129 | sv = newSViv (*va_arg (args, double *)); |
130 | sv = newSViv (*va_arg (args, double *)); |
130 | break; |
131 | break; |
131 | |
132 | |
132 | case CFAPI_STRING: |
133 | case CFAPI_STRING: |
133 | sv = newSVpv (va_arg (args, char *), 0); |
134 | { |
|
|
135 | char *str = va_arg (args, char *); |
|
|
136 | sv = str ? newSVpv (str, 0) : &PL_sv_undef; |
|
|
137 | } |
134 | break; |
138 | break; |
135 | |
139 | |
136 | case CFAPI_POBJECT: |
140 | case CFAPI_POBJECT: |
137 | { |
141 | { |
138 | object *obj = va_arg (args, object *); |
142 | object *obj = va_arg (args, object *); |
… | |
… | |
331 | printf (PLUGIN_VERSION " post init\n"); |
335 | printf (PLUGIN_VERSION " post init\n"); |
332 | |
336 | |
333 | registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); |
337 | registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); |
334 | unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); |
338 | unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); |
335 | systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); |
339 | systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); |
|
|
340 | object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property"); |
336 | cf_init_plugin (gethook); |
341 | cf_init_plugin (gethook); |
337 | |
342 | |
338 | /* Pick the global events you want to monitor from this plugin */ |
343 | /* Pick the global events you want to monitor from this plugin */ |
339 | registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); |
344 | registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); |
340 | registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener); |
345 | registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener); |
… | |
… | |
540 | |
545 | |
541 | BOOT: |
546 | BOOT: |
542 | { |
547 | { |
543 | HV *stash = gv_stashpv ("cf", 1); |
548 | HV *stash = gv_stashpv ("cf", 1); |
544 | |
549 | |
545 | const struct { |
550 | static const struct { |
546 | const char *name; |
551 | const char *name; |
547 | IV iv; |
552 | IV iv; |
548 | } *civ, const_iv[] = { |
553 | } *civ, const_iv[] = { |
549 | # define const_iv(name) { # name, (IV)name }, |
554 | # define const_iv(name) { # name, (IV)name }, |
550 | const_iv (llevError) |
555 | const_iv (llevError) |
… | |
… | |
834 | }; |
839 | }; |
835 | |
840 | |
836 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
841 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
837 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
842 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
838 | |
843 | |
839 | const struct { |
844 | static const struct { |
840 | const char *name; |
845 | const char *name; |
841 | IV iv; |
846 | IV iv; |
842 | } *event, event_list[] = { |
847 | } *event, event_list[] = { |
843 | # define const_event(name) { # name, (IV)EVENT_ ## name }, |
848 | # define const_event(name) { # name, (IV)EVENT_ ## name }, |
844 | const_event (NONE) |
849 | const_event (NONE) |
… | |
… | |
875 | AV *av = get_av ("cf::EVENT", 1); |
880 | AV *av = get_av ("cf::EVENT", 1); |
876 | |
881 | |
877 | for (event = event_list + sizeof (event_list) / sizeof (event_list [0]); event-- > event_list; ) |
882 | 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)); |
883 | av_store (av, event->iv, newSVpv ((char *)event->name, 0)); |
879 | |
884 | |
880 | const struct { |
885 | static const struct { |
881 | int dtype; |
886 | int dtype; |
882 | const char *name; |
887 | const char *name; |
883 | IV idx; |
888 | IV idx; |
884 | } *cprop, prop_table[] = { |
889 | } *cprop, prop_table[] = { |
885 | # define prop(type, name) { type, # name, (IV) CFAPI_ ## name }, |
890 | # define prop(type, name) { type, # name, (IV) CFAPI_ ## name }, |
… | |
… | |
1064 | cf_object_set_int_property (obj, idx, SvIV (newval)); |
1069 | cf_object_set_int_property (obj, idx, SvIV (newval)); |
1065 | break; |
1070 | break; |
1066 | case CFAPI_LONG: |
1071 | case CFAPI_LONG: |
1067 | cf_object_set_long_property (obj, idx, SvNV (newval)); |
1072 | cf_object_set_long_property (obj, idx, SvNV (newval)); |
1068 | break; |
1073 | break; |
|
|
1074 | case CFAPI_DOUBLE: |
|
|
1075 | { |
|
|
1076 | int unused_type; |
|
|
1077 | object_set_property (&unused_type, obj, idx, (double)SvNV (newval)); |
|
|
1078 | } |
|
|
1079 | break; |
1069 | case CFAPI_STRING: |
1080 | case CFAPI_STRING: |
1070 | cf_object_set_string_property (obj, idx, SvPV_nolen (newval)); |
1081 | cf_object_set_string_property (obj, idx, SvPV_nolen (newval)); |
1071 | break; |
1082 | break; |
1072 | default: |
1083 | default: |
1073 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
1084 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
… | |
… | |
1157 | RETVAL = cf_query_base_name (ob, plural); |
1168 | RETVAL = cf_query_base_name (ob, plural); |
1158 | OUTPUT: RETVAL |
1169 | OUTPUT: RETVAL |
1159 | |
1170 | |
1160 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1171 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1161 | |
1172 | |
1162 | object *cf_create_object () |
|
|
1163 | PROTOTYPE: |
|
|
1164 | ALIAS: new = 0 |
|
|
1165 | |
|
|
1166 | object *cf_create_object_by_name (const char *name) |
1173 | object *cf_create_object_by_name (const char *name = 0) |
1167 | PROTOTYPE: $ |
1174 | PROTOTYPE: ;$ |
1168 | ALIAS: new_from_name = 0 |
1175 | ALIAS: |
1169 | |
1176 | create_object = 0 |
1170 | void cf_free_object (object *ob) |
1177 | new = 0 |
|
|
1178 | CODE: |
|
|
1179 | RETVAL = name ? cf_create_object_by_name (name) : cf_create_object (); |
|
|
1180 | OUTPUT: |
|
|
1181 | RETVAL |
1171 | |
1182 | |
1172 | void cf_fix_object (object *pl) |
1183 | void cf_fix_object (object *pl) |
|
|
1184 | ALIAS: fix = 0 |
1173 | |
1185 | |
1174 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1186 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1175 | |
1187 | |
1176 | |
1188 | |
1177 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1189 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |