Spellforce-Spell-framework
Toggle main menu visibility
Loading...
Searching...
No Matches
sf_spelltype_registry.cpp
Go to the documentation of this file.
1
#include "
../../handlers/sf_spelltype_handlers.h
"
2
#include "
../../core/sf_hooks.h
"
3
#include "
../../core/sf_wrappers.h
"
4
#include "
../../core/sf_modloader.h
"
5
6
#include "
sf_spelltype_registry.h
"
7
#include "
../sf_registry.h
"
8
#include <map>
9
#include <cstdio>
10
11
static
std::map<uint16_t, handler_ptr> s_handler_map;
12
13
void
__thiscall
initializeSpellData
(
SF_CGdSpell
*_this, uint16_t spell_id,
14
SpellDataKey
key)
15
{
16
spellAPI
.setXData(_this, spell_id, key, 0);
17
}
18
19
handler_ptr
get_spell_handler
(
const
uint16_t key)
20
{
21
auto
it = s_handler_map.find(key);
22
if
(it == s_handler_map.end())
23
{
24
// Element doesn't exist, insert the default value
25
it = s_handler_map.emplace(key, &
default_handler
).first;
26
}
27
return
it->second;
28
}
29
30
// Exposed in sf_registry.h
31
void
registerSpellTypeHandler
(uint16_t spell_index,
handler_ptr
handler)
32
{
33
auto
check = s_handler_map.find(spell_index);
34
if
(check != s_handler_map.end())
35
{
36
if
(check->second != &
default_handler
)
37
{
38
char
message[256];
// Assuming a maximum message length of 255 characters
39
sprintf(message,
40
"%s (v%s) has replaced a Spelltype Handler! [%d] (Was this on purpose?)"
,
41
g_current_mod
->mod_id,
g_current_mod
->mod_version,
42
spell_index);
43
log_warning
(message);
44
}
45
}
46
47
s_handler_map[spell_index] = handler;
48
}
spellAPI
SpellFunctions * spellAPI
Definition
TestMod.cpp:11
log_warning
void log_warning(const char *format,...)
Logs a warning at DEBUG_INFO, i.e. always shown.
Definition
sf_wrappers.c:124
SpellDataKey
SpellDataKey
Definition
sf_general_structures.h:462
sf_hooks.h
sf_modloader.h
g_current_mod
SFMod * g_current_mod
Definition
sf_registry.cpp:45
sf_registry.h
default_handler
void __thiscall default_handler(SF_CGdSpell *_this, uint16_t spell_index)
Definition
sf_spelltype_handlers.cpp:7
sf_spelltype_handlers.h
initializeSpellData
void __thiscall initializeSpellData(SF_CGdSpell *_this, uint16_t spell_id, SpellDataKey key)
Definition
sf_spelltype_registry.cpp:13
registerSpellTypeHandler
void registerSpellTypeHandler(uint16_t spell_index, handler_ptr handler)
Definition
sf_spelltype_registry.cpp:31
get_spell_handler
handler_ptr get_spell_handler(const uint16_t key)
Definition
sf_spelltype_registry.cpp:19
sf_spelltype_registry.h
sf_wrappers.h
handler_ptr
void(__thiscall * handler_ptr)(SF_CGdSpell *, uint16_t)
Definition
sfsf.h:30
SF_CGdSpell
Definition
sf_spell_structures.h:26
src
internal
registry
spell_data_registries
sf_spelltype_registry.cpp
Generated by
1.17.0