Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_ai_hook.c
Go to the documentation of this file.
1
10#include "sf_ai_hook.h"
11
12#include "../sf_wrappers.h"
13#include "../sf_hooks.h"
14
18
19// #include <stdio.h>
20
22{
23 _this->type = 0xffff;
24 _this->subtype = 0;
25 _this->unkn2 = 0;
26 _this->unkn3 = 0;
27 _this->unkn4 = 0;
28 _this->unkn5 = 0;
29}
30
32{
33 if ((_this->type != 0) && (_this->type < 10000))
34 {
35 return true;
36 }
37 return false;
38}
39
40uint16_t __thiscall getSector(SF_CGdWorld *_this, SF_Coord *position)
41{
42 uint32_t index = position->X + position->Y * 0x400;
43 return _this->cells[index].sector;
44}
45
46uint32_t GetEuclideanDistanceFromRing(int x1, int y1, int x2, int y2,
47 int inner_radius, int outer_radius)
48{
49 int iVar1;
50
51 iVar1 = (y1 - y2) * (y1 - y2) + (x1 - x2) * (x1 - x2);
52 if (iVar1 < (inner_radius * inner_radius - 1))
53 {
54 return inner_radius * inner_radius - iVar1;
55 }
56 if ((outer_radius * outer_radius + 1) < iVar1)
57 {
58 return iVar1 - outer_radius * outer_radius;
59 }
60 return 0;
61}
62
63uint32_t signum(uint32_t param_1)
64{
65 return (param_1 ^ (int)param_1 >> 0x1f) - ((int)param_1 >> 0x1f);
66}
67
72 uint16_t target_index,
73 uint16_t spell_line,
74 SF_CGdResourceSpell *spell_data)
75{
76 bool isStackable = hasSpellTag(spell_line, SpellTag::STACKABLE_SPELL);
77
78 /* char message[256];
79 sprintf(message, "SpellLine: %hd Target: %hd isStackable: %d", spell_line, target_index, isStackable);
80 log_info(message);
81 */
82 ai_single_handler_ptr handler = get_single_ai_handler(spell_line);
83 uint32_t rank = handler(_this, target_index, spell_line, spell_data);
85 target_index, spell_line)) && (!isStackable))
86 {
87 rank = 0;
88 }
89 return rank;
90}
91
93 uint16_t target_index,
94 uint16_t spell_line,
95 SF_CGdResourceSpell *spell_data)
96{
97 bool isStackable = hasSpellTag(spell_line, SpellTag::STACKABLE_SPELL);
98
99 /* char message[256];
100 sprintf(message, "SpellLine: %hd Target: %hd isStackable: %d", spell_line, target_index, isStackable);
101 log_info(message);
102 */
103 ai_single_handler_ptr handler = get_single_ai_handler(spell_line);
104 if (handler == &default_support_ai_handler)
105 {
107 }
108 uint32_t rank = handler(_this, target_index, spell_line, spell_data);
110 target_index, spell_line)) && (!isStackable))
111 {
112 rank = 0;
113 }
114 return rank;
115}
116
118 uint16_t figure_index)
119{
120 uint16_t spell_node =
122 figure_index);
123 uint32_t result = 100;
124 while (spell_node != 0)
125 {
126 uint16_t spell_index =
128 (uint32_t *) _this->battleData.CGdDoubleLinkList, spell_node);
129 uint16_t spell_line = spellAPI.getSpellLine(_this->battleData.CGdSpell,
130 spell_index);
132 uint32_t current_result = handler(&_this->battleData, figure_index,
133 spell_line);
134 if (current_result >= result)
135 {
136 result = current_result;
137 }
138 spell_node =
140 (uint32_t *)_this->battleData.CGdDoubleLinkList, spell_node);
141 }
142 return result;
143}
144
145
146uint32_t __thiscall ai_AOE_hook(SF_CGdBattleDevelopment *_this,
147 SF_Coord cast_pos, uint16_t spell_line,
148 SF_CGdResourceSpell *spell_data)
149{
150 ai_aoe_handler_ptr handler = get_ai_aoe_handler(spell_line);
151 return handler(_this, &cast_pos, spell_line, spell_data);
152}
SpellFunctions * spellAPI
Definition TestMod.cpp:11
FigureFunctions * figureAPI
Definition TestMod.cpp:13
ToolboxFunctions * toolboxAPI
Definition TestMod.cpp:12
uint32_t __thiscall rank_support_spell_hook(SF_CGdBattleDevelopment *_this, uint16_t target_index, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
Injects into the ranking system for a single target AI spell.
Definition sf_ai_hook.c:71
uint32_t __thiscall avoidance_penalty_hook(SF_CGdBattleDevelopment *_this, uint16_t figure_index)
Definition sf_ai_hook.c:117
void clearAction(SF_SGtFigureAction *_this)
Definition sf_ai_hook.c:21
uint32_t signum(uint32_t param_1)
Definition sf_ai_hook.c:63
uint32_t __thiscall rank_offensive_spell_hook(SF_CGdBattleDevelopment *_this, uint16_t target_index, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
Definition sf_ai_hook.c:92
uint32_t GetEuclideanDistanceFromRing(int x1, int y1, int x2, int y2, int inner_radius, int outer_radius)
Definition sf_ai_hook.c:46
uint32_t __thiscall ai_AOE_hook(SF_CGdBattleDevelopment *_this, SF_Coord cast_pos, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
Definition sf_ai_hook.c:146
bool isSpellAction(SF_SGtFigureAction *_this)
Definition sf_ai_hook.c:31
uint16_t __thiscall getSector(SF_CGdWorld *_this, SF_Coord *position)
Definition sf_ai_hook.c:40
bool __thiscall hasSpellTag(uint16_t spell_id, SpellTag tag)
ai_aoe_handler_ptr get_ai_aoe_handler(uint16_t spell_line)
ai_avoidance_handler_ptr get_ai_avoidance_handler(uint16_t spell_line)
ai_single_handler_ptr get_single_ai_handler(uint16_t spell_line)
uint32_t __thiscall default_support_ai_handler(SF_CGdBattleDevelopment *_this, uint16_t target_index, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
uint32_t __thiscall default_offensive_ai_handler(SF_CGdBattleDevelopment *_this, uint16_t target_index, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
@ STACKABLE_SPELL
uint32_t(__thiscall * ai_single_handler_ptr)(SF_CGdBattleDevelopment *_this, uint16_t target_index, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
uint32_t(__thiscall * ai_aoe_handler_ptr)(SF_CGdBattleDevelopment *_this, SF_Coord *position, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
uint32_t(__thiscall * ai_avoidance_handler_ptr)(CGdAIBattleData *_this, uint16_t figure_index, uint16_t spell_line)
SF_CGdFigureToolbox * CGdFigureToolBox
SF_CGdFigure * CGdFigure
SF_CGdSpell * CGdSpell
getSpellJobStartNode_ptr getSpellJobStartNode
High-level structure managing AI battle development.
SF_world_unkn_2 cells[1048576]
getSpellLine_ptr getSpellLine
Retrieves the spell type ID of a given spell.
hasSpellOnIt_ptr hasSpellOnIt
getNextNode_ptr getNextNode
getSpellIndexFromDLL_ptr getSpellIndexFromDLL