From dc367f212e7a569a80f514555c5feab6eaa634fb Mon Sep 17 00:00:00 2001 From: JapaMala Date: Mon, 18 Jun 2018 22:12:52 +0530 Subject: [PATCH] Move fortress mode control stuff into a different file. --- plugins/remotefortressreader/CMakeLists.txt | 2 + .../remotefortressreader/dwarf_control.cpp | 101 ++++++++++++++++++ plugins/remotefortressreader/dwarf_control.h | 12 +++ .../remotefortressreader.cpp | 88 +-------------- 4 files changed, 116 insertions(+), 87 deletions(-) create mode 100644 plugins/remotefortressreader/dwarf_control.cpp create mode 100644 plugins/remotefortressreader/dwarf_control.h diff --git a/plugins/remotefortressreader/CMakeLists.txt b/plugins/remotefortressreader/CMakeLists.txt index 1ff1cac7f..c7c9d74fe 100644 --- a/plugins/remotefortressreader/CMakeLists.txt +++ b/plugins/remotefortressreader/CMakeLists.txt @@ -4,12 +4,14 @@ SET(PROJECT_SRCS remotefortressreader.cpp adventure_control.cpp building_reader.cpp + dwarf_control.cpp item_reader.cpp ) # A list of headers SET(PROJECT_HDRS adventure_control.h building_reader.h + dwarf_control.h item_reader.h df_version_int.h ) diff --git a/plugins/remotefortressreader/dwarf_control.cpp b/plugins/remotefortressreader/dwarf_control.cpp new file mode 100644 index 000000000..461b2f89e --- /dev/null +++ b/plugins/remotefortressreader/dwarf_control.cpp @@ -0,0 +1,101 @@ +#include "dwarf_control.h" +#include "DataDefs.h" +#include "df_version_int.h" + +#include "df/job.h" +#include "df/job_list_link.h" +#include "df/world.h" + +#include "modules/Buildings.h" +#include "modules/Job.h" +#include "modules/MapCache.h" +#include "modules/Maps.h" +#include "modules/World.h" + +using namespace DFHack; +using namespace RemoteFortressReader; + +command_result SendDigCommand(color_ostream &stream, const DigCommand *in) +{ + MapExtras::MapCache mc; + + for (int i = 0; i < in->locations_size(); i++) + { + auto pos = in->locations(i); + auto des = mc.designationAt(DFCoord(pos.x(), pos.y(), pos.z())); + switch (in->designation()) + { + case NO_DIG: + des.bits.dig = tile_dig_designation::No; + break; + case DEFAULT_DIG: + des.bits.dig = tile_dig_designation::Default; + break; + case UP_DOWN_STAIR_DIG: + des.bits.dig = tile_dig_designation::UpDownStair; + break; + case CHANNEL_DIG: + des.bits.dig = tile_dig_designation::Channel; + break; + case RAMP_DIG: + des.bits.dig = tile_dig_designation::Ramp; + break; + case DOWN_STAIR_DIG: + des.bits.dig = tile_dig_designation::DownStair; + break; + case UP_STAIR_DIG: + des.bits.dig = tile_dig_designation::UpStair; + break; + default: + break; + } + mc.setDesignationAt(DFCoord(pos.x(), pos.y(), pos.z()), des); + +#if DF_VERSION_INT >= 43005 + //remove and job postings related. + for (df::job_list_link * listing = &(df::global::world->jobs.list); listing != NULL; listing = listing->next) + { + if (listing->item == NULL) + continue; + auto type = listing->item->job_type; + switch (type) + { + case df::enums::job_type::CarveFortification: + case df::enums::job_type::DetailWall: + case df::enums::job_type::DetailFloor: + case df::enums::job_type::Dig: + case df::enums::job_type::CarveUpwardStaircase: + case df::enums::job_type::CarveDownwardStaircase: + case df::enums::job_type::CarveUpDownStaircase: + case df::enums::job_type::CarveRamp: + case df::enums::job_type::DigChannel: + case df::enums::job_type::FellTree: + case df::enums::job_type::GatherPlants: + case df::enums::job_type::RemoveConstruction: + case df::enums::job_type::CarveTrack: + { + if (listing->item->pos == DFCoord(pos.x(), pos.y(), pos.z())) + { + Job::removeJob(listing->item); + goto JOB_FOUND; + } + break; + } + default: + continue; + } + } + JOB_FOUND: + continue; +#endif + } + + mc.WriteAll(); + return CR_OK; +} + +command_result SetPauseState(color_ostream &stream, const SingleBool *in) +{ + DFHack::World::SetPauseState(in->value()); + return CR_OK; +} diff --git a/plugins/remotefortressreader/dwarf_control.h b/plugins/remotefortressreader/dwarf_control.h new file mode 100644 index 000000000..bb08e8b7a --- /dev/null +++ b/plugins/remotefortressreader/dwarf_control.h @@ -0,0 +1,12 @@ +#ifndef DWARF_CONTROL_H +#define DWARF_CONTROL_H + +#include "RemoteClient.h" +#include "RemoteFortressReader.pb.h" + +DFHack::command_result SendDigCommand(DFHack::color_ostream &stream, const RemoteFortressReader::DigCommand *in); +DFHack::command_result SetPauseState(DFHack::color_ostream &stream, const RemoteFortressReader::SingleBool *in); + +#endif // !DWARF_CONTROL_H + + diff --git a/plugins/remotefortressreader/remotefortressreader.cpp b/plugins/remotefortressreader/remotefortressreader.cpp index 7dced3b9f..8f3ac5b04 100644 --- a/plugins/remotefortressreader/remotefortressreader.cpp +++ b/plugins/remotefortressreader/remotefortressreader.cpp @@ -117,6 +117,7 @@ #include "adventure_control.h" #include "building_reader.h" +#include "dwarf_control.h" #include "item_reader.h" using namespace DFHack; @@ -161,8 +162,6 @@ static command_result GetPlantRaws(color_ostream &stream, const EmptyMessage *in static command_result GetPartialPlantRaws(color_ostream &stream, const ListRequest *in, PlantRawList *out); static command_result CopyScreen(color_ostream &stream, const EmptyMessage *in, ScreenCapture *out); static command_result PassKeyboardEvent(color_ostream &stream, const KeyboardEvent *in); -static command_result SendDigCommand(color_ostream &stream, const DigCommand *in); -static command_result SetPauseState(color_ostream & stream, const SingleBool * in); static command_result GetPauseState(color_ostream & stream, const EmptyMessage * in, SingleBool * out); static command_result GetVersionInfo(color_ostream & stream, const EmptyMessage * in, RemoteFortressReader::VersionInfo * out); static command_result GetReports(color_ostream & stream, const EmptyMessage * in, RemoteFortressReader::Status * out); @@ -2893,91 +2892,6 @@ static command_result PassKeyboardEvent(color_ostream &stream, const KeyboardEve return CR_OK; } -static command_result SendDigCommand(color_ostream &stream, const DigCommand *in) -{ - MapExtras::MapCache mc; - - for (int i = 0; i < in->locations_size(); i++) - { - auto pos = in->locations(i); - auto des = mc.designationAt(DFCoord(pos.x(), pos.y(), pos.z())); - switch (in->designation()) - { - case NO_DIG: - des.bits.dig = tile_dig_designation::No; - break; - case DEFAULT_DIG: - des.bits.dig = tile_dig_designation::Default; - break; - case UP_DOWN_STAIR_DIG: - des.bits.dig = tile_dig_designation::UpDownStair; - break; - case CHANNEL_DIG: - des.bits.dig = tile_dig_designation::Channel; - break; - case RAMP_DIG: - des.bits.dig = tile_dig_designation::Ramp; - break; - case DOWN_STAIR_DIG: - des.bits.dig = tile_dig_designation::DownStair; - break; - case UP_STAIR_DIG: - des.bits.dig = tile_dig_designation::UpStair; - break; - default: - break; - } - mc.setDesignationAt(DFCoord(pos.x(), pos.y(), pos.z()), des); - -#if DF_VERSION_INT >= 43005 - //remove and job postings related. - for (df::job_list_link * listing = &(world->jobs.list); listing != NULL; listing = listing->next) - { - if (listing->item == NULL) - continue; - auto type = listing->item->job_type; - switch (type) - { - case df::enums::job_type::CarveFortification: - case df::enums::job_type::DetailWall: - case df::enums::job_type::DetailFloor: - case df::enums::job_type::Dig: - case df::enums::job_type::CarveUpwardStaircase: - case df::enums::job_type::CarveDownwardStaircase: - case df::enums::job_type::CarveUpDownStaircase: - case df::enums::job_type::CarveRamp: - case df::enums::job_type::DigChannel: - case df::enums::job_type::FellTree: - case df::enums::job_type::GatherPlants: - case df::enums::job_type::RemoveConstruction: - case df::enums::job_type::CarveTrack: - { - if (listing->item->pos == DFCoord(pos.x(), pos.y(), pos.z())) - { - Job::removeJob(listing->item); - goto JOB_FOUND; - } - break; - } - default: - continue; - } - } - JOB_FOUND: - continue; -#endif - } - - mc.WriteAll(); - return CR_OK; -} - -static command_result SetPauseState(color_ostream &stream, const SingleBool *in) -{ - DFHack::World::SetPauseState(in->value()); - return CR_OK; -} - static command_result GetPauseState(color_ostream &stream, const EmptyMessage *in, SingleBool *out) { out->set_value(World::ReadPauseState());