Spellforce-Spell-framework
Toggle main menu visibility
Loading...
Searching...
No Matches
sf_onhit_registry.cpp
Go to the documentation of this file.
1
2
#include "
sf_onhit_registry.h
"
3
#include "
../../core/sf_wrappers.h
"
4
#include "
../../handlers/sf_onhit_handlers.h
"
5
#include "
../../core/sf_modloader.h
"
6
7
#include <iostream>
8
#include <map>
9
#include <cstdint>
10
#include <list>
11
#include <utility>
12
13
static
std::map<OnHitPhase, std::list<std::pair<uint16_t, onhit_handler_ptr> > > s_onhit_handler_map;
14
15
void
registerOnHitHandler
(uint16_t spell_line_id,
onhit_handler_ptr
handler,
OnHitPhase
phase)
16
{
17
// Check if there are existing handlers for the specified phase
18
auto
&handler_list = s_onhit_handler_map[phase];
19
20
char
buffer[256];
21
sprintf(buffer,
"Mod [%s] setting on hit handler for Spell line ID [%d]"
,
g_current_mod
->mod_id, spell_line_id);
22
log_debug
(
DEBUG_LOW
, buffer);
23
24
for
(
auto
&entry : handler_list)
25
{
26
// Check if there's an existing handler for this spell_line_id
27
if
(entry.first == spell_line_id)
28
{
29
// Log a warning since we are replacing an existing handler
30
char
message[256];
31
sprintf(message,
"%s (v%s) has replaced an On Hit Handler [%d] (Was this on purpose?)"
,
32
g_current_mod
->mod_id,
g_current_mod
->mod_version, spell_line_id);
33
log_warning
(message);
34
35
// Replace the existing handler
36
entry.second = handler;
37
return
;
// Early exit since we updated an existing handler
38
}
39
}
40
41
// If we didn't find an existing handler, add a new handler to back of list. (we iterate in reverse)
42
handler_list.emplace_back(spell_line_id, handler);
43
}
44
45
std::list<std::pair<uint16_t, onhit_handler_ptr> >
get_onhit_phase
(
OnHitPhase
phase)
46
{
47
//int enumValue = static_cast<int>(phase);
48
auto
it = s_onhit_handler_map.find(phase);
49
if
(it == s_onhit_handler_map.end())
50
{
51
// Element doesn't exist, log a warning and return an empty list
52
// log_warning("Unknown Phase ID for On Hit Handler.");
53
return
{};
// Return an empty list
54
}
55
/* char info_msg[50];
56
sprintf(info_msg, "On Hit Handler Phase: %d", enumValue);
57
log_info(info_msg); */
58
return
it->second;
// Return the list associated with the phase
59
}
log_warning
void log_warning(const char *format,...)
Logs a warning at DEBUG_INFO, i.e. always shown.
Definition
sf_wrappers.c:124
log_debug
void log_debug(DebugLevel level, const char *format,...)
Definition
sf_wrappers.c:182
OnHitPhase
OnHitPhase
Definition
sf_general_structures.h:875
DEBUG_LOW
@ DEBUG_LOW
Definition
sf_general_structures.h:38
sf_modloader.h
g_current_mod
SFMod * g_current_mod
Definition
sf_registry.cpp:45
sf_onhit_handlers.h
get_onhit_phase
std::list< std::pair< uint16_t, onhit_handler_ptr > > get_onhit_phase(OnHitPhase phase)
Definition
sf_onhit_registry.cpp:45
registerOnHitHandler
void registerOnHitHandler(uint16_t spell_line_id, onhit_handler_ptr handler, OnHitPhase phase)
Definition
sf_onhit_registry.cpp:15
sf_onhit_registry.h
onhit_handler_ptr
uint16_t(__thiscall * onhit_handler_ptr)(SF_CGdFigureJobs *, uint16_t source, uint16_t target, uint16_t damage)
Definition
sf_registration_structures.h:17
sf_wrappers.h
src
internal
registry
spell_data_registries
sf_onhit_registry.cpp
Generated by
1.17.0