Add a command to remotely send simple movement commands to an adventurer.

develop
Japa 2017-12-24 18:33:25 +05:30
parent 73c6209f87
commit 1408f7bfb3
5 changed files with 187 additions and 0 deletions

@ -0,0 +1,11 @@
package AdventureControl;
//Attempts to provide a complete framework for reading everything from a fortress needed for vizualization
option optimize_for = LITE_RUNTIME;
import "RemoteFortressReader.proto";
message MoveCommandParams
{
optional RemoteFortressReader.Coord direction = 1;
}

@ -2,16 +2,19 @@ PROJECT (remotefortressreader)
# A list of source files # A list of source files
SET(PROJECT_SRCS SET(PROJECT_SRCS
remotefortressreader.cpp remotefortressreader.cpp
adventure_control.cpp
building_reader.cpp building_reader.cpp
) )
# A list of headers # A list of headers
SET(PROJECT_HDRS SET(PROJECT_HDRS
adventure_control.h
building_reader.h building_reader.h
df_version_int.h df_version_int.h
) )
#proto files to include. #proto files to include.
SET(PROJECT_PROTO SET(PROJECT_PROTO
../../proto/RemoteFortressReader ../../proto/RemoteFortressReader
../../proto/AdventureControl
) )
SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE) SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE)

@ -0,0 +1,162 @@
#include "adventure_control.h"
#include "DataDefs.h"
#include "df/viewscreen.h"
#include "modules/Gui.h"
using namespace AdventureControl;
using namespace df::enums;
using namespace DFHack;
using namespace Gui;
command_result MoveCommand(DFHack::color_ostream &stream, const MoveCommandParams *in)
{
auto viewScreen = getCurViewscreen();
if (!in->has_direction())
return CR_WRONG_USAGE;
auto dir = in->direction();
switch (dir.x())
{
case -1:
switch (dir.y())
{
case -1:
switch (dir.z())
{
case -1:
viewScreen->feed_key(interface_key::A_MOVE_NW_DOWN);
break;
case 0:
viewScreen->feed_key(interface_key::A_MOVE_NW);
break;
case 1:
viewScreen->feed_key(interface_key::A_MOVE_NW_UP);
break;
}
break;
case 0:
switch (dir.z())
{
case -1:
viewScreen->feed_key(interface_key::A_MOVE_W_DOWN);
break;
case 0:
viewScreen->feed_key(interface_key::A_MOVE_W);
break;
case 1:
viewScreen->feed_key(interface_key::A_MOVE_W_UP);
break;
}
break;
case 1:
switch (dir.z())
{
case -1:
viewScreen->feed_key(interface_key::A_MOVE_SW_DOWN);
break;
case 0:
viewScreen->feed_key(interface_key::A_MOVE_SW);
break;
case 1:
viewScreen->feed_key(interface_key::A_MOVE_SW_UP);
break;
}
break;
}
break;
case 0:
switch (dir.y())
{
case -1:
switch (dir.z())
{
case -1:
viewScreen->feed_key(interface_key::A_MOVE_N_DOWN);
break;
case 0:
viewScreen->feed_key(interface_key::A_MOVE_N);
break;
case 1:
viewScreen->feed_key(interface_key::A_MOVE_N_UP);
break;
}
break;
case 0:
switch (dir.z())
{
case -1:
viewScreen->feed_key(interface_key::A_MOVE_DOWN);
break;
case 1:
viewScreen->feed_key(interface_key::A_MOVE_UP);
break;
}
break;
case 1:
switch (dir.z())
{
case -1:
viewScreen->feed_key(interface_key::A_MOVE_S_DOWN);
break;
case 0:
viewScreen->feed_key(interface_key::A_MOVE_S);
break;
case 1:
viewScreen->feed_key(interface_key::A_MOVE_S_UP);
break;
}
break;
}
break;
case 1:
switch (dir.y())
{
case -1:
switch (dir.z())
{
case -1:
viewScreen->feed_key(interface_key::A_MOVE_NE_DOWN);
break;
case 0:
viewScreen->feed_key(interface_key::A_MOVE_NE);
break;
case 1:
viewScreen->feed_key(interface_key::A_MOVE_NE_UP);
break;
}
break;
case 0:
switch (dir.z())
{
case -1:
viewScreen->feed_key(interface_key::A_MOVE_E_DOWN);
break;
case 0:
viewScreen->feed_key(interface_key::A_MOVE_E);
break;
case 1:
viewScreen->feed_key(interface_key::A_MOVE_E_UP);
break;
}
break;
case 1:
switch (dir.z())
{
case -1:
viewScreen->feed_key(interface_key::A_MOVE_SE_DOWN);
break;
case 0:
viewScreen->feed_key(interface_key::A_MOVE_SE);
break;
case 1:
viewScreen->feed_key(interface_key::A_MOVE_SE_UP);
break;
}
break;
}
break;
}
return CR_OK;
}

@ -0,0 +1,9 @@
#ifndef ADVENTURE_CONTROL_H
#define ADVENTURE_CONTROL_H
#include "RemoteClient.h"
#include "AdventureControl.pb.h"
DFHack::command_result MoveCommand(DFHack::color_ostream &stream, const AdventureControl::MoveCommandParams *in);
#endif // !ADVENTURE_CONTROL_H

@ -113,6 +113,7 @@
#include "df/unit_relationship_type.h" #include "df/unit_relationship_type.h"
#include "adventure_control.h"
#include "building_reader.h" #include "building_reader.h"
using namespace DFHack; using namespace DFHack;
@ -286,6 +287,7 @@ DFhackCExport RPCService *plugin_rpcconnect(color_ostream &)
svc->addFunction("GetPauseState", GetPauseState, SF_ALLOW_REMOTE); svc->addFunction("GetPauseState", GetPauseState, SF_ALLOW_REMOTE);
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);
return svc; return svc;
} }