2012-12-14 21:29:28 -07:00
|
|
|
#pragma once
|
|
|
|
#ifndef EVENT_MANAGER_H_INCLUDED
|
|
|
|
#define EVENT_MANAGER_H_INCLUDED
|
|
|
|
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "ColorText.h"
|
|
|
|
#include "PluginManager.h"
|
|
|
|
#include "Console.h"
|
|
|
|
|
|
|
|
namespace DFHack {
|
|
|
|
namespace EventManager {
|
|
|
|
namespace EventType {
|
|
|
|
enum EventType {
|
|
|
|
TICK,
|
|
|
|
JOB_INITIATED,
|
|
|
|
JOB_COMPLETED,
|
2012-12-15 12:40:11 -07:00
|
|
|
UNIT_DEATH,
|
2012-12-15 14:49:13 -07:00
|
|
|
ITEM_CREATED,
|
2012-12-18 16:34:38 -07:00
|
|
|
BUILDING,
|
|
|
|
CONSTRUCTION,
|
2013-01-02 16:30:15 -07:00
|
|
|
SYNDROME,
|
2013-01-03 13:52:56 -07:00
|
|
|
INVASION,
|
2012-12-15 14:49:13 -07:00
|
|
|
EVENT_MAX
|
2012-12-14 21:29:28 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
struct EventHandler {
|
|
|
|
void (*eventHandler)(color_ostream&, void*); //called when the event happens
|
2013-01-03 17:31:29 -07:00
|
|
|
int32_t freq;
|
2012-12-14 21:29:28 -07:00
|
|
|
|
2013-01-03 17:31:29 -07:00
|
|
|
EventHandler(void (*eventHandlerIn)(color_ostream&, void*), int32_t freqIn): eventHandler(eventHandlerIn), freq(freqIn) {
|
2012-12-14 21:29:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(EventHandler& handle) const {
|
2013-01-03 17:31:29 -07:00
|
|
|
return eventHandler == handle.eventHandler && freq == handle.freq;
|
2012-12-14 21:29:28 -07:00
|
|
|
}
|
|
|
|
bool operator!=(EventHandler& handle) const {
|
|
|
|
return !( *this == handle);
|
|
|
|
}
|
|
|
|
};
|
2013-01-02 16:30:15 -07:00
|
|
|
|
|
|
|
struct SyndromeData {
|
|
|
|
int32_t unitId;
|
|
|
|
int32_t syndromeIndex;
|
|
|
|
SyndromeData(int32_t unitId_in, int32_t syndromeIndex_in): unitId(unitId_in), syndromeIndex(syndromeIndex_in) {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
2012-12-14 21:29:28 -07:00
|
|
|
|
2013-01-03 17:31:29 -07:00
|
|
|
DFHACK_EXPORT void registerListener(EventType::EventType e, EventHandler handler, Plugin* plugin);
|
2012-12-15 16:08:59 -07:00
|
|
|
DFHACK_EXPORT void registerTick(EventHandler handler, int32_t when, Plugin* plugin, bool absolute=false);
|
2013-01-03 17:31:29 -07:00
|
|
|
DFHACK_EXPORT void unregister(EventType::EventType e, EventHandler handler, Plugin* plugin);
|
2012-12-14 21:29:28 -07:00
|
|
|
DFHACK_EXPORT void unregisterAll(Plugin* plugin);
|
|
|
|
void manageEvents(color_ostream& out);
|
|
|
|
void onStateChange(color_ostream& out, state_change_event event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|