added jumping ability to adventure control.

develop
Japa 2017-12-25 22:00:45 +05:30
parent 58cbdcca80
commit 5d32253b6e
3 changed files with 68 additions and 2 deletions

@ -5,11 +5,23 @@
#include "modules/Gui.h" #include "modules/Gui.h"
#include <queue>
using namespace AdventureControl; using namespace AdventureControl;
using namespace df::enums; using namespace df::enums;
using namespace DFHack; using namespace DFHack;
using namespace Gui; using namespace Gui;
std::queue<interface_key::interface_key> keyQueue;
void KeyUpdate()
{
if (!keyQueue.empty())
{
getCurViewscreen()->feed_key(keyQueue.front());
keyQueue.pop();
}
}
command_result MoveCommand(DFHack::color_ostream &stream, const MoveCommandParams *in) command_result MoveCommand(DFHack::color_ostream &stream, const MoveCommandParams *in)
{ {
@ -159,4 +171,43 @@ command_result MoveCommand(DFHack::color_ostream &stream, const MoveCommandParam
break; break;
} }
return CR_OK; 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;
} }

@ -5,5 +5,8 @@
#include "AdventureControl.pb.h" #include "AdventureControl.pb.h"
DFHack::command_result MoveCommand(DFHack::color_ostream &stream, const AdventureControl::MoveCommandParams *in); 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 #endif // !ADVENTURE_CONTROL_H

@ -234,6 +234,8 @@ command_result RemoteFortressReader_version(color_ostream &out, vector<string> &
return CR_OK; return CR_OK;
} }
DFHACK_PLUGIN_IS_ENABLED(enableUpdates);
// Mandatory init function. If you have some global state, create it here. // Mandatory init function. If you have some global state, create it here.
DFhackCExport command_result plugin_init(color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init(color_ostream &out, std::vector <PluginCommand> &commands)
{ {
@ -248,7 +250,8 @@ DFhackCExport command_result plugin_init(color_ostream &out, std::vector <Plugin
" Does nothing.\n" " Does nothing.\n"
)); ));
commands.push_back(PluginCommand("RemoteFortressReader_version", "List the loaded RemoteFortressReader version", RemoteFortressReader_version, false, "This is used for plugin version checking.")); commands.push_back(PluginCommand("RemoteFortressReader_version", "List the loaded RemoteFortressReader version", RemoteFortressReader_version, false, "This is used for plugin version checking."));
return CR_OK; enableUpdates = true;
return CR_OK;
} }
#ifndef SF_ALLOW_REMOTE #ifndef SF_ALLOW_REMOTE
@ -288,7 +291,8 @@ DFhackCExport RPCService *plugin_rpcconnect(color_ostream &)
svc->addFunction("GetVersionInfo", GetVersionInfo, SF_ALLOW_REMOTE); svc->addFunction("GetVersionInfo", GetVersionInfo, SF_ALLOW_REMOTE);
svc->addFunction("GetReports", GetReports, SF_ALLOW_REMOTE); svc->addFunction("GetReports", GetReports, SF_ALLOW_REMOTE);
svc->addFunction("MoveCommand", MoveCommand, 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. // 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; 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 fletcher16(uint8_t const *data, size_t bytes)
{ {
uint16_t sum1 = 0xff, sum2 = 0xff; uint16_t sum1 = 0xff, sum2 = 0xff;