Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_spelltype_registry.cpp
Go to the documentation of this file.
5
7#include "../sf_registry.h"
8#include <map>
9#include <cstdio>
10
11static std::map<uint16_t, handler_ptr> s_handler_map;
12
13void __thiscall initializeSpellData(SF_CGdSpell *_this, uint16_t spell_id,
14 SpellDataKey key)
15{
16 spellAPI.setXData(_this, spell_id, key, 0);
17}
18
19handler_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
31void 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?)",
42 spell_index);
43 log_warning(message);
44 }
45 }
46
47 s_handler_map[spell_index] = handler;
48}
SpellFunctions * spellAPI
Definition TestMod.cpp:11
void log_warning(const char *message)
Definition sf_wrappers.c:81
SFMod * g_current_mod
void(__thiscall * handler_ptr)(SF_CGdSpell *, uint16_t)
void __thiscall default_handler(SF_CGdSpell *_this, uint16_t spell_index)
void __thiscall initializeSpellData(SF_CGdSpell *_this, uint16_t spell_id, SpellDataKey key)
void registerSpellTypeHandler(uint16_t spell_index, handler_ptr handler)
handler_ptr get_spell_handler(const uint16_t key)
char mod_id[64]
char mod_version[24]
setXData_ptr setXData
This function is used to assign specific value to an XData key of a given spell.