Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_ai_hook.c
Go to the documentation of this file.
1
9
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->cooldown_action = 0;
26 _this->cooldown_global = 0;
27}
28
30{
31 if ((_this->type != 0) && (_this->type < 10000))
32 {
33 return true;
34 }
35 return false;
36}
37
38uint16_t __thiscall getSector(SF_CGdWorld *_this, SF_Coord *position)
39{
40 uint32_t index = position->X + position->Y * 0x400;
41 return _this->cells[index].sector;
42}
43
44uint32_t GetEuclideanDistanceFromRing(int x1, int y1, int x2, int y2,
45 int inner_radius, int outer_radius)
46{
47 int iVar1;
48
49 iVar1 = (y1 - y2) * (y1 - y2) + (x1 - x2) * (x1 - x2);
50 if (iVar1 < (inner_radius * inner_radius - 1))
51 {
52 return inner_radius * inner_radius - iVar1;
53 }
54 if ((outer_radius * outer_radius + 1) < iVar1)
55 {
56 return iVar1 - outer_radius * outer_radius;
57 }
58 return 0;
59}
60
61uint32_t signum(uint32_t param_1)
62{
63 return (param_1 ^ (int)param_1 >> 0x1f) - ((int)param_1 >> 0x1f);
64}
65
70 uint16_t target_index,
71 uint16_t spell_line,
72 SF_CGdResourceSpell *spell_data)
73{
74 bool isStackable = hasSpellTag(spell_line, SpellTag::STACKABLE_SPELL);
75
76 ai_single_handler_ptr handler = get_single_ai_handler(spell_line);
77 uint32_t rank = handler(_this, target_index, spell_line, spell_data);
78 if ((toolboxAPI.hasSpellOnIt(_this->battleData.CGdFigureToolBox,
79 target_index, spell_line)) && (!isStackable))
80 {
81 rank = 0;
82 }
83 return rank;
84}
85
87 uint16_t target_index,
88 uint16_t spell_line,
89 SF_CGdResourceSpell *spell_data)
90{
91 bool isStackable = hasSpellTag(spell_line, SpellTag::STACKABLE_SPELL);
92
93 ai_single_handler_ptr handler = get_single_ai_handler(spell_line);
94 if (handler == &default_support_ai_handler)
95 {
97 }
98 uint32_t rank = handler(_this, target_index, spell_line, spell_data);
99 if ((toolboxAPI.hasSpellOnIt(_this->battleData.CGdFigureToolBox,
100 target_index, spell_line)) && (!isStackable))
101 {
102 rank = 0;
103 }
104 return rank;
105}
106
108 uint16_t figure_index)
109{
110 uint16_t spell_node =
111 figureAPI.getSpellJobStartNode(_this->battleData.CGdFigure,
112 figure_index);
113 uint32_t result = 100;
114 while (spell_node != 0)
115 {
116 uint16_t spell_index =
117 toolboxAPI.getSpellIndexFromDLL(
118 (uint32_t *) _this->battleData.CGdDoubleLinkList, spell_node);
119 uint16_t spell_line = spellAPI.getSpellLine(_this->battleData.CGdSpell,
120 spell_index);
122 uint32_t current_result = handler(&_this->battleData, figure_index,
123 spell_line);
124 if (current_result >= result)
125 {
126 result = current_result;
127 }
128 spell_node =
129 toolboxAPI.getNextNode(
130 (uint32_t *)_this->battleData.CGdDoubleLinkList, spell_node);
131 }
132 return result;
133}
134
135uint32_t __thiscall ai_AOE2_hook(SF_CGdBattleDevelopment *_this,
136 SF_Coord *cast_pos, uint16_t spell_line,
137 SF_CGdResourceSpell *spell_data)
138{
139 ai_aoe_handler_ptr handler = get_ai_aoe_handler(spell_line);
140 return handler(_this, cast_pos, spell_line, spell_data);
141
142}
143uint32_t __thiscall ai_AOE_hook(SF_CGdBattleDevelopment *_this,
144 SF_Coord cast_pos, uint16_t spell_line,
145 SF_CGdResourceSpell *spell_data)
146{
147 ai_aoe_handler_ptr handler = get_ai_aoe_handler(spell_line);
148 return handler(_this, &cast_pos, spell_line, spell_data);
149}
150
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:69
uint32_t __thiscall avoidance_penalty_hook(SF_CGdBattleDevelopment *_this, uint16_t figure_index)
Definition sf_ai_hook.c:107
void clearAction(SF_SGtFigureAction *_this)
Definition sf_ai_hook.c:21
uint32_t signum(uint32_t param_1)
Definition sf_ai_hook.c:61
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:86
uint32_t __thiscall ai_AOE2_hook(SF_CGdBattleDevelopment *_this, SF_Coord *cast_pos, uint16_t spell_line, SF_CGdResourceSpell *spell_data)
Definition sf_ai_hook.c:135
uint32_t GetEuclideanDistanceFromRing(int x1, int y1, int x2, int y2, int inner_radius, int outer_radius)
Definition sf_ai_hook.c:44
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:143
bool isSpellAction(SF_SGtFigureAction *_this)
Definition sf_ai_hook.c:29
uint16_t __thiscall getSector(SF_CGdWorld *_this, SF_Coord *position)
Definition sf_ai_hook.c:38
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
High-level structure managing AI battle development.
SF_world_unkn_2 cells[1048576]