|
|
@ -6,6 +6,9 @@
|
|
|
|
#include "modules/EventManager.h"
|
|
|
|
#include "modules/EventManager.h"
|
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "DataDefs.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "df/item.h"
|
|
|
|
|
|
|
|
#include "df/world.h"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
|
|
|
|
DFHACK_PLUGIN("eventExample");
|
|
|
|
DFHACK_PLUGIN("eventExample");
|
|
|
@ -14,12 +17,14 @@ void jobInitiated(color_ostream& out, void* job);
|
|
|
|
void jobCompleted(color_ostream& out, void* job);
|
|
|
|
void jobCompleted(color_ostream& out, void* job);
|
|
|
|
void timePassed(color_ostream& out, void* ptr);
|
|
|
|
void timePassed(color_ostream& out, void* ptr);
|
|
|
|
void unitDeath(color_ostream& out, void* ptr);
|
|
|
|
void unitDeath(color_ostream& out, void* ptr);
|
|
|
|
|
|
|
|
void itemCreate(color_ostream& out, void* ptr);
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginCommand> &commands) {
|
|
|
|
DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginCommand> &commands) {
|
|
|
|
EventManager::EventHandler initiateHandler(jobInitiated);
|
|
|
|
EventManager::EventHandler initiateHandler(jobInitiated);
|
|
|
|
EventManager::EventHandler completeHandler(jobCompleted);
|
|
|
|
EventManager::EventHandler completeHandler(jobCompleted);
|
|
|
|
EventManager::EventHandler timeHandler(timePassed);
|
|
|
|
EventManager::EventHandler timeHandler(timePassed);
|
|
|
|
EventManager::EventHandler deathHandler(unitDeath);
|
|
|
|
EventManager::EventHandler deathHandler(unitDeath);
|
|
|
|
|
|
|
|
EventManager::EventHandler itemHandler(itemCreate);
|
|
|
|
Plugin* me = Core::getInstance().getPluginManager()->getPluginByName("eventExample");
|
|
|
|
Plugin* me = Core::getInstance().getPluginManager()->getPluginByName("eventExample");
|
|
|
|
|
|
|
|
|
|
|
|
EventManager::registerListener(EventManager::EventType::JOB_INITIATED, initiateHandler, me);
|
|
|
|
EventManager::registerListener(EventManager::EventType::JOB_INITIATED, initiateHandler, me);
|
|
|
@ -29,6 +34,7 @@ DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginC
|
|
|
|
EventManager::registerTick(timeHandler, 4, me);
|
|
|
|
EventManager::registerTick(timeHandler, 4, me);
|
|
|
|
EventManager::registerTick(timeHandler, 8, me);
|
|
|
|
EventManager::registerTick(timeHandler, 8, me);
|
|
|
|
EventManager::registerListener(EventManager::EventType::UNIT_DEATH, deathHandler, me);
|
|
|
|
EventManager::registerListener(EventManager::EventType::UNIT_DEATH, deathHandler, me);
|
|
|
|
|
|
|
|
EventManager::registerListener(EventManager::EventType::ITEM_CREATED, itemHandler, me);
|
|
|
|
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -48,3 +54,15 @@ void timePassed(color_ostream& out, void* ptr) {
|
|
|
|
void unitDeath(color_ostream& out, void* ptr) {
|
|
|
|
void unitDeath(color_ostream& out, void* ptr) {
|
|
|
|
out.print("Death: %d\n", (int32_t)(ptr));
|
|
|
|
out.print("Death: %d\n", (int32_t)(ptr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void itemCreate(color_ostream& out, void* ptr) {
|
|
|
|
|
|
|
|
int32_t item_index = df::item::binsearch_index(df::global::world->items.all, (int32_t)ptr);
|
|
|
|
|
|
|
|
if ( item_index == -1 ) {
|
|
|
|
|
|
|
|
out.print("%s, %d: Error.\n", __FILE__, __LINE__);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
df::item* item = df::global::world->items.all[item_index];
|
|
|
|
|
|
|
|
df::item_type type = item->getType();
|
|
|
|
|
|
|
|
df::coord pos = item->pos;
|
|
|
|
|
|
|
|
out.print("Item created: %d, %s, at (%d,%d,%d)\n", (int32_t)(ptr), ENUM_KEY_STR(item_type, type).c_str(), pos.x, pos.y, pos.z);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|