From 5d32253b6e028afb73fd8bdf62d2e5eae1f57225 Mon Sep 17 00:00:00 2001 From: Japa Date: Mon, 25 Dec 2017 22:00:45 +0530 Subject: [PATCH] added jumping ability to adventure control. --- .../adventure_control.cpp | 51 +++++++++++++++++++ .../remotefortressreader/adventure_control.h | 3 ++ .../remotefortressreader.cpp | 16 +++++- 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/plugins/remotefortressreader/adventure_control.cpp b/plugins/remotefortressreader/adventure_control.cpp index d5e713080..6e717ebd1 100644 --- a/plugins/remotefortressreader/adventure_control.cpp +++ b/plugins/remotefortressreader/adventure_control.cpp @@ -5,11 +5,23 @@ #include "modules/Gui.h" +#include + using namespace AdventureControl; using namespace df::enums; using namespace DFHack; using namespace Gui; +std::queue keyQueue; + +void KeyUpdate() +{ + if (!keyQueue.empty()) + { + getCurViewscreen()->feed_key(keyQueue.front()); + keyQueue.pop(); + } +} command_result MoveCommand(DFHack::color_ostream &stream, const MoveCommandParams *in) { @@ -159,4 +171,43 @@ command_result MoveCommand(DFHack::color_ostream &stream, const MoveCommandParam break; } return CR_OK; +} +command_result JumpCommand(DFHack::color_ostream &stream, const MoveCommandParams *in) +{ + if (!in->has_direction()) + return CR_WRONG_USAGE; + auto dir = in->direction(); + keyQueue.push(interface_key::A_JUMP); + int x = dir.x(); + int y = dir.y(); + if (x > 0) + { + for (int i = 0; i < x; i++) + { + keyQueue.push(interface_key::CURSOR_RIGHT); + } + } + if (x < 0) + { + for (int i = 0; i > x; i--) + { + keyQueue.push(interface_key::CURSOR_LEFT); + } + } + if (y > 0) + { + for (int i = 0; i < y; i++) + { + keyQueue.push(interface_key::CURSOR_DOWN); + } + } + if (y < 0) + { + for (int i = 0; i > y; i--) + { + keyQueue.push(interface_key::CURSOR_UP); + } + } + keyQueue.push(interface_key::SELECT); + return CR_OK; } \ No newline at end of file diff --git a/plugins/remotefortressreader/adventure_control.h b/plugins/remotefortressreader/adventure_control.h index f4d912019..c84fe9722 100644 --- a/plugins/remotefortressreader/adventure_control.h +++ b/plugins/remotefortressreader/adventure_control.h @@ -5,5 +5,8 @@ #include "AdventureControl.pb.h" DFHack::command_result MoveCommand(DFHack::color_ostream &stream, const AdventureControl::MoveCommandParams *in); +DFHack::command_result JumpCommand(DFHack::color_ostream &stream, const AdventureControl::MoveCommandParams *in); +void KeyUpdate(); + #endif // !ADVENTURE_CONTROL_H diff --git a/plugins/remotefortressreader/remotefortressreader.cpp b/plugins/remotefortressreader/remotefortressreader.cpp index 8eae24adb..8ebb75d79 100644 --- a/plugins/remotefortressreader/remotefortressreader.cpp +++ b/plugins/remotefortressreader/remotefortressreader.cpp @@ -234,6 +234,8 @@ command_result RemoteFortressReader_version(color_ostream &out, vector & return CR_OK; } +DFHACK_PLUGIN_IS_ENABLED(enableUpdates); + // Mandatory init function. If you have some global state, create it here. DFhackCExport command_result plugin_init(color_ostream &out, std::vector &commands) { @@ -248,7 +250,8 @@ DFhackCExport command_result plugin_init(color_ostream &out, std::vector addFunction("GetVersionInfo", GetVersionInfo, SF_ALLOW_REMOTE); svc->addFunction("GetReports", GetReports, SF_ALLOW_REMOTE); svc->addFunction("MoveCommand", MoveCommand, SF_ALLOW_REMOTE); - return svc; + svc->addFunction("JumpCommand", JumpCommand, SF_ALLOW_REMOTE); + return svc; } // This is called right before the plugin library is removed from memory. @@ -300,6 +304,14 @@ DFhackCExport command_result plugin_shutdown(color_ostream &out) return CR_OK; } +DFhackCExport command_result plugin_onupdate(color_ostream &out) +{ + if (!enableUpdates) + return CR_OK; + KeyUpdate(); + return CR_OK; +} + uint16_t fletcher16(uint8_t const *data, size_t bytes) { uint16_t sum1 = 0xff, sum2 = 0xff;