Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_endspell_hook.c
Go to the documentation of this file.
1
6
7#include "../sf_wrappers.h"
8#include "../sf_hooks.h"
10
11#include <stdint.h>
12#include <stdlib.h>
13#include <stdio.h>
14#include <string.h>
15
16#include "sf_endspell_hook.h"
17
18
22void __thiscall sf_endspell_hook(SF_CGdSpell *_this, uint16_t spell_index)
23{
24 // We need a map of end spell handlers?
25 // And a default handler that does nothing
26 // handler takes (SF_CGdSpell *_this, uint16_t spell_index) as params
27 uint16_t spell_line = _this->active_spell_list[spell_index].spell_line;
28 handler_ptr spellend_handler = get_spell_end(spell_line);
29 if (spellend_handler != NULL)
30 {
31 spellend_handler(_this, spell_index);
32 }
33}
34
35void __thiscall sf_figure_end_spells_hook(SF_CGdFigureToolbox *_this, uint16_t figure_id)
36{
37 for (uint16_t spell_node = figureAPI.getSpellJobStartNode(_this->CGdFigure, figure_id);
38 spell_node != 0; spell_node = figureAPI.getSpellJobStartNode(_this->CGdFigure, figure_id))
39 {
40 uint16_t spell_index = toolboxAPI.getSpellIndexFromDLL(_this->CGdDoubleLinkedList, spell_node);
41 uint16_t spell_line = _this->CGdSpell->active_spell_list[spell_index].spell_line;
42 if (!spellAPI.hasSpellTag(spell_line, SpellTag::AOE_SPELL))
43 {
44 sf_endspell_hook(_this->CGdSpell, spell_index);
45 }
46 else
47 {
48 log_debug(DEBUG_HIGH, "AOE spell [%d] type [%d]", spell_index, spell_line);
49 if (toolboxAPI.removeSpellFromList(_this, figure_id, spell_index))
50 {
51 uint16_t spell_line = spellAPI.getSpellLine(_this->CGdSpell, spell_index);
52 if (spell_line == kGdSpellLineFreezeArea)
53 {
54 spellAPI.figTryUnfreeze(_this->CGdSpell, spell_index, figure_id);
55 spellAPI.figClrChkSplBfrChkBattle(_this->CGdSpell, spell_index, figure_id);
56 }
57 if (spell_line == kGdSpellLineHypnotizeArea)
58 {
59 spellAPI.figTryUnfreeze(_this->CGdSpell, spell_index, figure_id);
60 tryClearCheckSpellsBeforeJob(_this->CGdSpell, spell_index, figure_id);
61 spellAPI.figClrChkSplBfrChkBattle(_this->CGdSpell, spell_index, figure_id);
62 }
63 }
64 }
65 if ((toolboxAPI.hasSpellOnIt(_this, figure_id, spell_line)) &&
66 (_this->CGdSpell->active_spell_list[spell_index].target.entity_index == 0) &&
67 (_this->CGdSpell->active_spell_list[spell_index].source.entity_index == 0))
68 {
69 log_debug(DEBUG_HIGH, "Broken spell [%d] on figure [%d] spell type [%d]",
70 spell_index, figure_id, spell_line);
71 toolboxAPI.removeSpellFromList(_this, figure_id, spell_index);
72 }
73 }
74}
SpellFunctions * spellAPI
Definition TestMod.cpp:11
FigureFunctions * figureAPI
Definition TestMod.cpp:13
ToolboxFunctions * toolboxAPI
Definition TestMod.cpp:12
void __thiscall sf_endspell_hook(SF_CGdSpell *_this, uint16_t spell_index)
void log_debug(DebugLevel level, const char *format,...)
void __thiscall tryClearCheckSpellsBeforeJob(SF_CGdSpell *_this, uint16_t spell_index, uint16_t figure_index)
void __thiscall sf_figure_end_spells_hook(SF_CGdFigureToolbox *_this, uint16_t figure_id)
@ kGdSpellLineHypnotizeArea
@ kGdSpellLineFreezeArea
handler_ptr get_spell_end(uint16_t spell_line)
void(__thiscall * handler_ptr)(SF_CGdSpell *, uint16_t)
Definition sfsf.h:30
SF_GdSpell active_spell_list[800]
SF_CGdTargetData source
SF_CGdTargetData target