Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_enchant_registry.cpp
Go to the documentation of this file.
5
6#include <map>
7#include <utility>
8
9static std::map<uint16_t, enchant_handler_ptr> s_enchant_handlers_map;
10
11uint16_t __thiscall default_enchant_handler(SF_CGdFigure *_this, uint16_t figure_id)
12{
13 uint16_t dex_current = figureAPI.getCurrentStat(_this, figure_id, DEXTERITY);
14 uint16_t int_current = figureAPI.getCurrentStat(_this, figure_id, INTELLIGENCE);
15 return dex_current * 5 + int_current * 5 + 500;
16}
17
18uint16_t __thiscall poison_enchant_handler(SF_CGdFigure *_this, uint16_t figure_id)
19{
20 uint16_t dex_current = figureAPI.getCurrentStat(_this, figure_id, DEXTERITY);
21 uint16_t int_current = figureAPI.getCurrentStat(_this, figure_id, INTELLIGENCE);
22 return dex_current * 8 + int_current * 5 + 1400;
23}
24
25void registerEnchantHandler(uint16_t spell_line, enchant_handler_ptr handler)
26{
27 auto check = s_enchant_handlers_map.find(spell_line);
28 if (check != s_enchant_handlers_map.end())
29 {
30 log_warning_level(DEBUG_LOW, "%s (v%s) has replaced a Enchantment Chance Handler [%d]",
31 g_current_mod->mod_id, g_current_mod->mod_version, spell_line);
32 }
33 s_enchant_handlers_map[spell_line] = handler;
34}
35
37{
38 auto it = s_enchant_handlers_map.find(spell_line);
39 if (it == s_enchant_handlers_map.end())
40 {
41 log_debug(DEBUG_HIGH, "Using default handler for enchant [%d]", spell_line);
42 it = s_enchant_handlers_map.emplace(spell_line, &default_enchant_handler).first;
43 }
44 return it->second;
45}
46
FigureFunctions * figureAPI
Definition TestMod.cpp:13
void log_warning_level(DebugLevel level, const char *format,...)
Logs a warning that is only shown once the log level reaches level.
void log_debug(DebugLevel level, const char *format,...)
enchant_handler_ptr get_enchant_handler(uint16_t spell_line)
void registerEnchantHandler(uint16_t spell_line, enchant_handler_ptr handler)
void register_vanilla_enchants_handlers()
uint16_t __thiscall default_enchant_handler(SF_CGdFigure *_this, uint16_t figure_id)
uint16_t __thiscall poison_enchant_handler(SF_CGdFigure *_this, uint16_t figure_id)
@ kGdSpellLinePoison
SFMod * g_current_mod
uint16_t(__thiscall * enchant_handler_ptr)(SF_CGdFigure *_this, uint16_t figure_id)
A structure for the global list of figures and related statistics for them.