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