Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_ai_aoe_handlers.cpp
Go to the documentation of this file.
3
4
6 SF_Coord *cast_position,
7 uint16_t spell_line,
8 SF_CGdResourceSpell *spell_data)
9{
10 uint32_t rank = 1;
12 iteratorAPI.figureIteratorInit(&iter, 0, 0, 0x3ff, 0x3ff);
13 iteratorAPI.figureIteratorSetPointers(&iter, _this->battleData.CGdFigure,
15 _this->battleData.CGdWorld);
16
17 iteratorAPI.iteratorSetArea(&iter, cast_position, spell_data->params[2]);
18 uint16_t count = 0;
19 uint32_t x_sum = 0;
20 uint32_t y_sum = 0;
21 SF_CGdFigure *sf_figures = _this->battleData.CGdFigure;
22
23 uint16_t figure_index = iteratorAPI.getNextFigure(&iter);
24 while (figure_index != 0)
25 {
26 if (sf_figures->figures[figure_index].owner != (uint16_t)(-1))
27 {
28 if (sf_figures->figures[figure_index].owner ==
29 sf_figures->figures[_this->battleData.current_figure].owner)
30 {
31 if ((sf_figures->figures[figure_index].flags &
33 {
34 if ((sf_figures->figures[figure_index].debug_flags & 0x2) ==
35 0)
36 {
37 x_sum += sf_figures->figures[figure_index].position.X;
38 y_sum += sf_figures->figures[figure_index].position.Y;
39 count++;
40 }
41 }
42 }
43 }
44 figure_index = iteratorAPI.getNextFigure(&iter);
45 }
46
47 if (count < 3)
48 {
49 rank = 0;
50 }
51 else
52 {
53 x_sum = x_sum / count;
54 y_sum = y_sum / count;
55 cast_position->X = x_sum;
56 cast_position->Y = y_sum;
57 }
58 iteratorAPI.disposeFigureIterator(&iter);
59 return rank;
60}
61
63 SF_Coord *cast_position,
64 uint16_t spell_line,
65 SF_CGdResourceSpell *spell_data)
66{
67 uint32_t rank = 1;
68 if (((_this->battleData.figures_missing_hp * 100) /
69 _this->battleData.figures_max_hp) >= 4)
70 {
71 rank = 0;
72 }
73 return rank;
74}
75
77 SF_Coord *cast_position,
78 uint16_t spell_line,
79 SF_CGdResourceSpell *spell_data)
80{
81 uint32_t rank = 1;
82 if (((_this->battleData.figures_missing_hp * 100) /
83 _this->battleData.figures_max_hp) < 5)
84 {
85 return 0;
86 }
88 iteratorAPI.figureIteratorInit(&iter, 0, 0, 0x3ff, 0x3ff);
89 iteratorAPI.figureIteratorSetPointers(&iter, _this->battleData.CGdFigure,
91 _this->battleData.CGdWorld);
92
93 iteratorAPI.iteratorSetArea(&iter, cast_position, spell_data->params[2]);
94 uint16_t count = 0;
95 SF_CGdFigure *sf_figures = _this->battleData.CGdFigure;
96 uint16_t figure_index = iteratorAPI.getNextFigure(&iter);
97 while (figure_index != 0)
98 {
99 if (sf_figures->figures[figure_index].owner != (uint16_t)(-1))
100 {
101 if (sf_figures->figures[figure_index].owner ==
102 sf_figures->figures[_this->battleData.current_figure].owner)
103 {
104 if ((sf_figures->figures[figure_index].flags &
106 {
107 if ((sf_figures->figures[figure_index].flags &
109 {
110 count++;
111 }
112 }
113 }
114 if (count >= 5)
115 {
116 break;
117 }
118 }
119 figure_index = iteratorAPI.getNextFigure(&iter);
120 }
121
122 if (count < 5)
123 {
124 rank = 0;
125 }
126 iteratorAPI.disposeFigureIterator(&iter);
127 return rank;
128}
129
131 SF_Coord *cast_position,
132 uint16_t spell_line,
133 SF_CGdResourceSpell *spell_data)
134{
135 uint32_t rank = 1;
137 iteratorAPI.figureIteratorInit(&iter, 0, 0, 0x3ff, 0x3ff);
138 iteratorAPI.figureIteratorSetPointers(&iter, _this->battleData.CGdFigure,
139 _this->battleData.autoclass22,
140 _this->battleData.CGdWorld);
141 iteratorAPI.iteratorSetArea(&iter, cast_position, spell_data->params[2]);
142 uint16_t count = 0;
143 SF_CGdFigure *sf_figures = _this->battleData.CGdFigure;
144 uint16_t figure_index = iteratorAPI.getNextFigure(&iter);
145 while (figure_index != 0)
146 {
147 if (sf_figures->figures[figure_index].owner != (uint16_t)(-1))
148 {
149 if (sf_figures->figures[figure_index].owner !=
150 sf_figures->figures[_this->battleData.current_figure].owner)
151 {
152 if ((sf_figures->figures[figure_index].flags &
154 {
155 if ((sf_figures->figures[figure_index].flags &
157 {
158 count++;
159 }
160 }
161 }
162 if (count >= 5)
163 {
164 break;
165 }
166 }
167 figure_index = iteratorAPI.getNextFigure(&iter);
168 }
169
170 if (count < 5)
171 {
172 rank = 0;
173 }
174 iteratorAPI.disposeFigureIterator(&iter);
175 return rank;
176}
177
178uint32_t __thiscall fog_ai_handler(SF_CGdBattleDevelopment *_this,
179 SF_Coord *cast_position, uint16_t spell_line,
180 SF_CGdResourceSpell *spell_data)
181{
182 uint32_t rank = 1;
183 uint16_t count = 0;
184 ushort_list_node *enemy_list =
186 uint16_t length = ((uint32_t)enemy_list->data -
187 (uint32_t)(enemy_list->first)) >> 1;
188
189 for (uint16_t i = 0; i < length; i++)
190 {
191 uint16_t target_index = enemy_list->first[i];
192 SF_Coord target_pos;
193 target_pos.X =
194 _this->battleData.CGdFigure->figures[target_index].position.X;
195 target_pos.Y =
196 _this->battleData.CGdFigure->figures[target_index].position.Y;
197 uint16_t distance = getDistance(cast_position, &target_pos);
198 if (figureAPI.getSpellJobStartNode(_this->battleData.CGdFigure,
199 target_index))
200 {
201 if (spell_data->params[0] >= distance)
202 {
203 count++;
204 }
205 }
206 else
207 {
208 if (!toolboxAPI.hasSpellOnIt(_this->battleData.CGdFigureToolBox,
209 target_index, spell_line))
210 {
211 if (spell_data->params[0] >= distance)
212 {
213 count++;
214 }
215 }
216 }
217 if (count > 2)
218 {
219 break;
220 }
221 }
222
223 if (count < 3)
224 {
225 rank = 0;
226 }
227
228 return rank;
229}
230
232 SF_Coord *cast_position,
233 uint16_t spell_line,
234 SF_CGdResourceSpell *spell_data)
235{
236 return 1;
237}
238
239uint32_t __thiscall rain_ai_handler(SF_CGdBattleDevelopment *_this,
240 SF_Coord *cast_position,
241 uint16_t spell_line,
242 SF_CGdResourceSpell *spell_data)
243{
244 uint32_t rank = 1;
245 uint16_t count = 0;
246 ushort_list_node *enemy_list =
248 uint16_t length = ((uint32_t)enemy_list->data -
249 (uint32_t)(enemy_list->first)) >> 1;
250 uint16_t limit = (length + 2) / 3;
251 for (uint16_t i = 0; i < length; i++)
252 {
253 uint16_t target_index = enemy_list->first[i];
254 SF_Coord target_pos;
255 target_pos.X =
256 _this->battleData.CGdFigure->figures[target_index].position.X;
257 target_pos.Y =
258 _this->battleData.CGdFigure->figures[target_index].position.Y;
259 uint16_t distance = getDistance(cast_position, &target_pos);
260 if (spell_data->params[2] >= distance)
261 {
262 count++;
263 }
264 if (count >= limit)
265 {
266 break;
267 }
268 }
269 if (count < limit)
270 {
271 rank = 0;
272 }
273 return rank;
274}
275
277 SF_Coord *cast_position,
278 uint16_t spell_line,
279 SF_CGdResourceSpell *spell_data)
280{
281 uint32_t rank = 1;
282 uint16_t count = 0;
283 ushort_list_node *enemy_list =
285 uint16_t length = ((uint32_t)enemy_list->data -
286 (uint32_t)(enemy_list->first)) >> 1;
287
288 for (uint16_t i = 0; i < length; i++)
289 {
290 uint16_t target_index = enemy_list->first[i];
291 SF_Coord target_pos;
292 target_pos.X =
293 _this->battleData.CGdFigure->figures[target_index].position.X;
294 target_pos.Y =
295 _this->battleData.CGdFigure->figures[target_index].position.Y;
296 uint16_t distance = getDistance(cast_position, &target_pos);
297 if (figureAPI.getSpellJobStartNode(_this->battleData.CGdFigure,
298 target_index))
299 {
300 if (spell_data->params[1] >= distance)
301 {
302 count++;
303 }
304 }
305 else
306 {
307 if (!toolboxAPI.hasSpellOnIt(_this->battleData.CGdFigureToolBox,
308 target_index, spell_line))
309 {
310 if (spell_data->params[1] >= distance)
311 {
312 count++;
313 }
314 }
315 }
316 if (count > 2)
317 {
318 break;
319 }
320 }
321
322 if (count < 3)
323 {
324 rank = 0;
325 }
326
327 return rank;
328}
329
331 SF_Coord *cast_position,
332 uint16_t spell_line,
333 SF_CGdResourceSpell *spell_data)
334{
335 uint32_t rank = 1;
336 uint16_t count = 0;
337 ushort_list_node *enemy_list =
339 uint16_t length = ((uint32_t)enemy_list->data -
340 (uint32_t)(enemy_list->first)) >> 1;
341
342 for (uint16_t i = 0; i < length; i++)
343 {
344 uint16_t target_index = enemy_list->first[i];
345 SF_Coord target_pos;
346 target_pos.X =
347 _this->battleData.CGdFigure->figures[target_index].position.X;
348 target_pos.Y =
349 _this->battleData.CGdFigure->figures[target_index].position.Y;
350 uint16_t distance = getDistance(cast_position, &target_pos);
351 if (figureAPI.getSpellJobStartNode(_this->battleData.CGdFigure,
352 target_index))
353 {
354 if (spell_data->params[3] >= distance)
355 {
356 count++;
357 }
358 }
359 else
360 {
361 if (!toolboxAPI.hasSpellOnIt(_this->battleData.CGdFigureToolBox,
362 target_index, spell_line))
363 {
364 if (spell_data->params[3] >= distance)
365 {
366 count++;
367 }
368 }
369 }
370 if (count > 2)
371 {
372 break;
373 }
374 }
375
376 if (count < 3)
377 {
378 rank = 0;
379 }
380
381 return rank;
382}
383
385 SF_CGdBattleDevelopment *_this, SF_Coord *cast_position,
386 uint16_t spell_line, SF_CGdResourceSpell *spell_data)
387{
388 uint32_t rank = 1;
389 uint16_t count = 0;
390 ushort_list_node *enemy_list =
392 uint16_t length = ((uint32_t)enemy_list->data -
393 (uint32_t)(enemy_list->first)) >> 1;
394
395 for (uint16_t i = 0; i < length; i++)
396 {
397 uint16_t target_index = enemy_list->first[i];
398 SF_Coord target_pos;
399 target_pos.X =
400 _this->battleData.CGdFigure->figures[target_index].position.X;
401 target_pos.Y =
402 _this->battleData.CGdFigure->figures[target_index].position.Y;
403 uint16_t distance = getDistance(cast_position, &target_pos);
404 if (figureAPI.getSpellJobStartNode(_this->battleData.CGdFigure,
405 target_index))
406 {
407 if (spell_data->params[2] >= distance)
408 {
409 count++;
410 }
411 }
412 else
413 {
414 if (!toolboxAPI.hasSpellOnIt(_this->battleData.CGdFigureToolBox,
415 target_index, spell_line))
416 {
417 if (spell_data->params[2] >= distance)
418 {
419 count++;
420 }
421 }
422 }
423 if (count > 2)
424 {
425 break;
426 }
427 }
428
429 if (count < 3)
430 {
431 rank = 0;
432 }
433
434 return rank;
435}
FigureFunctions * figureAPI
Definition TestMod.cpp:13
ToolboxFunctions * toolboxAPI
Definition TestMod.cpp:12
IteratorFunctions iteratorAPI
Definition sf_hooks.c:49
uint32_t __thiscall getDistance(SF_Coord *pointA, SF_Coord *pointB)
Definition sf_wrappers.c:41
uint32_t __thiscall revenge_ai_handler(SF_CGdBattleDevelopment *_this, SF_Coord *cast_position, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
uint32_t __thiscall raise_dead_ai_handler(SF_CGdBattleDevelopment *_this, SF_Coord *cast_position, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
uint32_t __thiscall area_heal_ai_handler(SF_CGdBattleDevelopment *_this, SF_Coord *cast_position, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
uint32_t __thiscall rain_ai_handler(SF_CGdBattleDevelopment *_this, SF_Coord *cast_position, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
uint32_t __thiscall default_aoe_offensive_ai_handler(SF_CGdBattleDevelopment *_this, SF_Coord *cast_position, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
uint32_t __thiscall area_pain_ai_handler(SF_CGdBattleDevelopment *_this, SF_Coord *cast_position, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
uint32_t __thiscall hypnotize_area_ai_handler(SF_CGdBattleDevelopment *_this, SF_Coord *cast_position, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
uint32_t __thiscall torture_ai_handler(SF_CGdBattleDevelopment *_this, SF_Coord *cast_position, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
uint32_t __thiscall fog_ai_handler(SF_CGdBattleDevelopment *_this, SF_Coord *cast_position, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
uint32_t __thiscall area_freeze_ai_handler(SF_CGdBattleDevelopment *_this, SF_Coord *cast_position, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
@ USED_FOR_REVENGE
uint32_t figures_missing_hp
SF_CGdFigureToolbox * CGdFigureToolBox
SF_CGdFigure * CGdFigure
ushort_list_node another_figure_list[2000]
SF_CGdWorld * CGdWorld
High-level structure managing AI battle development.
A structure for the global list of figures and related statistics for them.
GdFigure figures[2000]
Represents a node in a list of unsigned short values.