1 /*
2  * OpenBOR - http://www.chronocrash.com
3  * -----------------------------------------------------------------------
4  * All rights reserved. See LICENSE in OpenBOR root for license details.
5  *
6  * Copyright (c) 2004 - 2017 OpenBOR Team
7  */
8 
9 // Body Properties
10 // 2017-04-26
11 // Caskey, Damon V.
12 //
13 // Access to body collision properties.
14 
15 #include "scriptcommon.h"
16 
17 // Body collision properties.
18 // Caskey, Damon V.
19 // 2016-10-31
20 //
21 // get_body_collision_collection(void handle, int frame)
openbor_get_body_collision_collection(ScriptVariant ** varlist,ScriptVariant ** pretvar,int paramCount)22 HRESULT openbor_get_body_collision_collection(ScriptVariant **varlist, ScriptVariant **pretvar, int paramCount)
23 {
24     #define SELF_NAME       "get_body_collision_collection(void handle, int frame)"
25     #define ARG_MINIMUM     2   // Minimum required arguments.
26     #define ARG_HANDLE      0   // Handle (pointer to property structure).
27     #define ARG_FRAME       1   // Frame to access.
28 
29 
30     int                 result      = S_OK; // Success or error?
31     s_collision_body    **handle    = NULL; // Property handle.
32     int                 frame       = 0;    // Property argument.
33 
34     // Clear pass by reference argument used to send
35     // property data back to calling script.     .
36     ScriptVariant_Clear(*pretvar);
37 
38     // Verify incoming arguments. There should at least
39     // be a pointer for the property handle and an integer
40     // to determine which frame is accessed.
41     if(paramCount < ARG_MINIMUM
42        || varlist[ARG_HANDLE]->vt != VT_PTR
43        || varlist[ARG_FRAME]->vt != VT_INTEGER)
44     {
45         *pretvar = NULL;
46         goto error_local;
47     }
48 
49     // Populate local handle and frame vars.
50     handle  = (s_collision_body **)varlist[ARG_HANDLE]->ptrVal;
51     frame   = (LONG)varlist[ARG_FRAME]->lVal;
52 
53     // If this frame has property, send value back to user.
54     if(handle[frame])
55     {
56         ScriptVariant_ChangeType(*pretvar, VT_PTR);
57         (*pretvar)->ptrVal = handle[frame];
58     }
59 
60     return result;
61 
62     // Error trapping.
63     error_local:
64 
65     printf("You must provide a valid handle and frame: " SELF_NAME "\n");
66 
67     result = E_FAIL;
68     return result;
69 
70     #undef SELF_NAME
71     #undef ARG_MINIMUM
72     #undef ARG_HANDLE
73     #undef ARG_FRAME
74 }
75 
76 // get_body_collision_instance(void handle, int index)
openbor_get_body_collision_instance(ScriptVariant ** varlist,ScriptVariant ** pretvar,int paramCount)77 HRESULT openbor_get_body_collision_instance(ScriptVariant **varlist, ScriptVariant **pretvar, int paramCount)
78 {
79     #define SELF_NAME       "get_body_collision_instance(void handle, int index)"
80     #define ARG_MINIMUM     2   // Minimum required arguments.
81     #define ARG_HANDLE      0   // Handle (pointer to property structure).
82     #define ARG_INDEX       1   // Index to access.
83 
84     int                 result      = S_OK; // Success or error?
85     s_collision_body    **handle    = NULL; // Property handle.
86     int                 index       = 0;    // Property argument.
87 
88     // Clear pass by reference argument used to send
89     // property data back to calling script.     .
90     ScriptVariant_Clear(*pretvar);
91 
92     // Verify incoming arguments. There should at least
93     // be a pointer for the property handle and an integer
94     // to determine which frame is accessed.
95     if(paramCount < ARG_MINIMUM
96        || varlist[ARG_HANDLE]->vt != VT_PTR
97        || varlist[ARG_INDEX]->vt != VT_INTEGER)
98     {
99         *pretvar = NULL;
100         goto error_local;
101     }
102 
103     // Populate local handle and property vars.
104     handle  = (s_collision_body **)varlist[ARG_HANDLE]->ptrVal;
105     index   = (LONG)varlist[ARG_INDEX]->lVal;
106 
107     // If this index has property, send value back to user.
108     if(handle[index])
109     {
110         ScriptVariant_ChangeType(*pretvar, VT_PTR);
111         (*pretvar)->ptrVal = handle[index];
112     }
113 
114     return result;
115 
116     // Error trapping.
117     error_local:
118 
119     printf("You must provide a valid handle and index: " SELF_NAME "\n");
120 
121     result = E_FAIL;
122     return result;
123 
124     #undef SELF_NAME
125     #undef ARG_MINIMUM
126     #undef ARG_HANDLE
127     #undef ARG_INDEX
128 }
129 
130 // get_body_collision_property(void handle, int property)
openbor_get_body_collision_property(ScriptVariant ** varlist,ScriptVariant ** pretvar,int paramCount)131 HRESULT openbor_get_body_collision_property(ScriptVariant **varlist, ScriptVariant **pretvar, int paramCount)
132 {
133     #define SELF_NAME       "get_body_collision_property(void handle, int property)"
134     #define ARG_MINIMUM     2   // Minimum required arguments.
135     #define ARG_HANDLE      0   // Handle (pointer to property structure).
136     #define ARG_PROPERTY    1   // Property to access.
137 
138     int                         result      = S_OK; // Success or error?
139     s_collision_body            *handle     = NULL; // Property handle.
140     e_body_collision_properties property    = 0;    // Property argument.
141 
142     // Clear pass by reference argument used to send
143     // property data back to calling script.     .
144     ScriptVariant_Clear(*pretvar);
145 
146     // Verify incoming arguments. There should at least
147     // be a pointer for the property handle and an integer
148     // to determine which property is accessed.
149     if(paramCount < ARG_MINIMUM
150        || varlist[ARG_HANDLE]->vt != VT_PTR
151        || varlist[ARG_PROPERTY]->vt != VT_INTEGER)
152     {
153         *pretvar = NULL;
154         goto error_local;
155     }
156 
157     // Populate local handle and property vars.
158     handle      = (s_collision_body *)varlist[ARG_HANDLE]->ptrVal;
159     property    = (LONG)varlist[ARG_PROPERTY]->lVal;
160 
161     // Which property to get?
162     switch(property)
163     {
164         case BODY_COLLISION_PROP_COORDINATES:
165 
166             // Verify handle and pass it on.
167             if(handle->coords)
168             {
169                 ScriptVariant_ChangeType(*pretvar, VT_PTR);
170                 (*pretvar)->ptrVal = (VOID *)handle->coords;
171             }
172 
173             break;
174 
175         case BODY_COLLISION_PROP_DEFENSE:
176 
177 
178             // Verify animation has any defense.
179             if(handle->defense)
180             {
181                 ScriptVariant_ChangeType(*pretvar, VT_PTR);
182                 (*pretvar)->ptrVal = (VOID *)handle->defense;
183             }
184 
185             break;
186 
187         case BODY_COLLISION_PROP_TAG:
188 
189             ScriptVariant_ChangeType(*pretvar, VT_INTEGER);
190             (*pretvar)->lVal = (LONG)handle->tag;
191             break;
192 
193         default:
194 
195             printf("Unsupported property.\n");
196             goto error_local;
197             break;
198     }
199 
200     return result;
201 
202     // Error trapping.
203     error_local:
204 
205     printf("You must provide a valid handle and property: " SELF_NAME "\n");
206 
207     result = E_FAIL;
208     return result;
209 
210     #undef SELF_NAME
211     #undef ARG_MINIMUM
212     #undef ARG_HANDLE
213     #undef ARG_PROPERTY
214 }
215 
216 // set_body_collision_property(void handle, int property, value)
openbor_set_body_collision_property(ScriptVariant ** varlist,ScriptVariant ** pretvar,int paramCount)217 HRESULT openbor_set_body_collision_property(ScriptVariant **varlist, ScriptVariant **pretvar, int paramCount)
218 {
219     #define SELF_NAME           "set_body_collision_property(void handle, int property, value)"
220     #define ARG_MINIMUM         3   // Minimum required arguments.
221     #define ARG_HANDLE          0   // Handle (pointer to property structure).
222     #define ARG_PROPERTY        1   // Property to access.
223     #define ARG_VALUE           2   // New value to apply.
224 
225     int                         result      = S_OK; // Success or error?
226     s_collision_body            *handle     = NULL; // Property handle.
227     e_body_collision_properties property    = 0;    // Property to access.
228 
229     // Value carriers to apply on properties after
230     // taken from argument.
231     LONG         temp_int;
232 
233     // Verify incoming arguments. There should at least
234     // be a pointer for the property handle and an integer
235     // to determine which property is accessed.
236     if(paramCount < ARG_MINIMUM
237        || varlist[ARG_HANDLE]->vt != VT_PTR
238        || varlist[ARG_PROPERTY]->vt != VT_INTEGER)
239     {
240         *pretvar = NULL;
241         goto error_local;
242     }
243 
244     // Populate local handle and property vars.
245     handle      = (s_collision_body *)varlist[ARG_HANDLE]->ptrVal;
246     property    = (LONG)varlist[ARG_PROPERTY]->lVal;
247 
248     // Which property to modify?
249     switch(property)
250     {
251         case BODY_COLLISION_PROP_COORDINATES:
252 
253             handle->coords = (s_hitbox *)varlist[ARG_VALUE]->ptrVal;
254 
255             break;
256 
257         case BODY_COLLISION_PROP_DEFENSE:
258 
259             handle->defense = (s_defense *)varlist[ARG_VALUE]->ptrVal;
260 
261             break;
262 
263         case BODY_COLLISION_PROP_TAG:
264 
265             if(SUCCEEDED(ScriptVariant_IntegerValue(varlist[ARG_VALUE], &temp_int)))
266             {
267                 handle->tag = temp_int;
268             }
269             break;
270 
271         default:
272 
273             printf("Unsupported property.\n");
274             goto error_local;
275             break;
276     }
277 
278     return result;
279 
280     // Error trapping.
281     error_local:
282 
283     printf("You must provide a valid handle, property, and new value: " SELF_NAME "\n");
284 
285     result = E_FAIL;
286     return result;
287 
288     #undef SELF_NAME
289     #undef ARG_MINIMUM
290     #undef ARG_HANDLE
291     #undef ARG_PROPERTY
292     #undef ARG_VALUE
293 }
294 
295 
296