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"
|
2013-10-20 12:14:02 -06:00
|
|
|
#include "DataDefs.h"
|
|
|
|
|
2014-06-28 00:31:34 -06:00
|
|
|
#include "df/coord.h"
|
|
|
|
#include "df/unit.h"
|
|
|
|
#include "df/unit_inventory_item.h"
|
|
|
|
#include "df/unit_wound.h"
|
2012-12-14 21:29:28 -07:00
|
|
|
|
|
|
|
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,
|
2013-10-24 17:32:52 -06:00
|
|
|
INVENTORY_CHANGE,
|
2014-06-23 07:15:46 -06:00
|
|
|
REPORT,
|
2014-06-28 00:31:34 -06:00
|
|
|
UNIT_ATTACK,
|
2014-06-29 08:03:55 -06:00
|
|
|
UNLOAD,
|
2014-07-01 06:58:48 -06:00
|
|
|
INTERACTION,
|
2012-12-15 14:49:13 -07:00
|
|
|
EVENT_MAX
|
2012-12-14 21:29:28 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
struct EventHandler {
|
2013-10-20 12:44:07 -06:00
|
|
|
typedef void (*callback_t)(color_ostream&, void*); //called when the event happens
|
|
|
|
callback_t eventHandler;
|
2013-01-03 17:31:29 -07:00
|
|
|
int32_t freq;
|
2012-12-14 21:29:28 -07:00
|
|
|
|
2013-10-20 12:44:07 -06:00
|
|
|
EventHandler(callback_t eventHandlerIn, int32_t freqIn): eventHandler(eventHandlerIn), freq(freqIn) {
|
2012-12-14 21:29:28 -07:00
|
|
|
}
|
|
|
|
|
2013-10-20 20:49:22 -06:00
|
|
|
bool operator==(const 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
|
|
|
}
|
2013-10-20 20:49:22 -06:00
|
|
|
bool operator!=(const EventHandler& handle) const {
|
2012-12-14 21:29:28 -07:00
|
|
|
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) {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2013-10-24 17:32:52 -06:00
|
|
|
struct InventoryItem {
|
|
|
|
//it has to keep the id of an item because the item itself may have been deallocated
|
|
|
|
int32_t itemId;
|
|
|
|
df::unit_inventory_item item;
|
|
|
|
InventoryItem() {}
|
|
|
|
InventoryItem(int32_t id_in, df::unit_inventory_item item_in): itemId(id_in), item(item_in) {}
|
|
|
|
};
|
|
|
|
struct InventoryChangeData {
|
2013-06-15 15:59:55 -06:00
|
|
|
int32_t unitId;
|
2013-10-24 17:32:52 -06:00
|
|
|
InventoryItem* item_old;
|
|
|
|
InventoryItem* item_new;
|
|
|
|
InventoryChangeData() {}
|
|
|
|
InventoryChangeData(int32_t id_in, InventoryItem* old_in, InventoryItem* new_in): unitId(id_in), item_old(old_in), item_new(new_in) {}
|
|
|
|
};
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2014-06-28 00:31:34 -06:00
|
|
|
struct UnitAttackData {
|
|
|
|
int32_t attacker;
|
|
|
|
int32_t defender;
|
|
|
|
int32_t wound;
|
|
|
|
};
|
2014-07-03 02:55:12 -06:00
|
|
|
|
|
|
|
struct InteractionData {
|
|
|
|
std::string attackVerb;
|
|
|
|
std::string defendVerb;
|
|
|
|
int32_t attacker;
|
|
|
|
int32_t defender;
|
2014-11-09 16:36:21 -07:00
|
|
|
int32_t attackReport;
|
|
|
|
int32_t defendReport;
|
2014-07-03 02:55:12 -06:00
|
|
|
};
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2013-01-03 17:31:29 -07:00
|
|
|
DFHACK_EXPORT void registerListener(EventType::EventType e, EventHandler handler, Plugin* plugin);
|
2013-10-20 20:49:22 -06:00
|
|
|
DFHACK_EXPORT int32_t 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-20 12:14:02 -06:00
|
|
|
namespace std {
|
|
|
|
template <>
|
|
|
|
struct hash<df::coord> {
|
|
|
|
std::size_t operator()(const df::coord& c) const {
|
|
|
|
size_t r = 17;
|
|
|
|
const size_t m = 65537;
|
|
|
|
r = m*(r+c.x);
|
|
|
|
r = m*(r+c.y);
|
|
|
|
r = m*(r+c.z);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
};
|
2013-10-20 20:49:22 -06:00
|
|
|
template <>
|
|
|
|
struct hash<DFHack::EventManager::EventHandler> {
|
|
|
|
std::size_t operator()(const DFHack::EventManager::EventHandler& h) const {
|
|
|
|
size_t r = 17;
|
|
|
|
const size_t m = 65537;
|
|
|
|
r = m*(r+(int32_t)h.eventHandler);
|
|
|
|
r = m*(r+h.freq);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
};
|
2013-10-20 12:14:02 -06:00
|
|
|
}
|
|
|
|
|
2012-12-14 21:29:28 -07:00
|
|
|
#endif
|