diff --git a/fixTexts.sh b/fixTexts.sh index 30ee0c52c..09689c8dc 100755 --- a/fixTexts.sh +++ b/fixTexts.sh @@ -1,3 +1,4 @@ #!/bin/bash rst2html README.rst > Readme.html rst2html COMPILE.rst > Compile.html +rst2html DEVEL.rst > Devel.html diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 935d7cebb..38f7ab382 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -28,7 +28,9 @@ endif() DFHACK_PLUGIN(reveal reveal.cpp) DFHACK_PLUGIN(probe probe.cpp) +DFHACK_PLUGIN(getplants getplants.cpp) DFHACK_PLUGIN(plants plants.cpp) +DFHACK_PLUGIN(fastdwarf fastdwarf.cpp) DFHACK_PLUGIN(prospector prospector.cpp) DFHACK_PLUGIN(cleanmap cleanmap.cpp) DFHACK_PLUGIN(weather weather.cpp) @@ -43,3 +45,8 @@ DFHACK_PLUGIN(cleanowned cleanowned.cpp) DFHACK_PLUGIN(deramp deramp.cpp) DFHACK_PLUGIN(flows flows.cpp) +# this is the skeleton plugin. If you want to make your own, make a copy and then change it +OPTION(BUILD_SKELETON "Build the skeleton plugin." OFF) +if(BUILD_SKELETON) + add_subdirectory(skeleton) +endif() diff --git a/plugins/fastdwarf.cpp b/plugins/fastdwarf.cpp new file mode 100644 index 000000000..9ff77b332 --- /dev/null +++ b/plugins/fastdwarf.cpp @@ -0,0 +1,84 @@ +// foo +// vi:expandtab:sw=4 + +#include +#include +#include +#include +#include +#include +using namespace std; +#include +#include +#include +#include +#include +#include +using namespace DFHack; + +// dfhack interface +DFhackCExport const char * plugin_name ( void ) +{ + return "fastdwarf"; +} + +DFhackCExport command_result plugin_shutdown ( Core * c ) +{ + return CR_OK; +} + +static int enable_fastdwarf; + +// remove that if struct df_creature is updated +#define job_counter unk_540 + +DFhackCExport command_result plugin_onupdate ( Core * c ) +{ + if (!enable_fastdwarf) + return CR_OK; + + static vector *v; + df_creature *cre; + + if (!v) { + OffsetGroup *ogc = c->vinfo->getGroup("Creatures"); + v = (vector*)ogc->getAddress("vector"); + } + + //c->Suspend(); // will deadlock in onupdate + for (unsigned i=0 ; isize() ; ++i) { + cre = v->at(i); + if (cre->race == 241 && cre->job_counter > 0) + cre->job_counter = 0; + // could also patch the cre->current_job->counter + } + //c->Resume(); + + return CR_OK; +} + +static command_result fastdwarf (Core * c, vector & parameters) +{ + if (parameters.size() == 1 && (parameters[0] == "0" || parameters[0] == "1")) { + if (parameters[0] == "0") + enable_fastdwarf = 0; + else + enable_fastdwarf = 1; + c->con.print("fastdwarf %sactivated.\n", (enable_fastdwarf ? "" : "de")); + } else { + c->con.print("Activate fastdwarf with 'fastdwarf 1', deactivate with 'fastdwarf 0'.\nCurrent state: %d.\n", enable_fastdwarf); + } + + return CR_OK; +} + +DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) +{ + commands.clear(); + + commands.push_back(PluginCommand("fastdwarf", + "enable/disable fastdwarf (parameter=0/1)", + fastdwarf)); + + return CR_OK; +} diff --git a/plugins/getplants.cpp b/plugins/getplants.cpp new file mode 100644 index 000000000..cdbdb87f3 --- /dev/null +++ b/plugins/getplants.cpp @@ -0,0 +1,191 @@ +// Designate all matching plants for gathering/cutting + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace DFHack; + +DFhackCExport command_result df_getplants (Core * c, vector & parameters); + +DFhackCExport const char * plugin_name ( void ) +{ + return "getplants"; +} + +DFhackCExport command_result plugin_init ( Core * c, vector &commands) +{ + commands.clear(); + commands.push_back(PluginCommand("getplants", "Cut down all of the specified trees or gather all of the specified shrubs", df_getplants)); + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown ( Core * c ) +{ + return CR_OK; +} + +DFhackCExport command_result df_getplants (Core * c, vector & parameters) +{ + uint32_t x_max,y_max,z_max; + designations40d designations; + tiletypes40d tiles; + t_blockflags blockflags; + string plantMatStr = ""; + set plantIDs; + set plantNames; + bool deselect = false, exclude = false, treesonly = false, shrubsonly = false; + + bool dirty = false; + int count = 0; + for (size_t i = 0; i < parameters.size(); i++) + { + if(parameters[i] == "help" || parameters[i] == "?") + { + c->con.print("Specify the types of trees to cut down and/or shrubs to gather by their plant names, separated by spaces.\n" + "Options:\n" + "\t-t - Select trees only (exclude shrubs)\n" + "\t-s - Select shrubs only (exclude trees)\n" + "\t-c - Clear designations instead of setting them\n" + "\t-x - Apply selected action to all plants except those specified\n" + "Specifying both -t and -s will have no effect.\n" + "If no plant IDs are specified, all valid plant IDs will be listed.\n" + ); + return CR_OK; + } + else if(parameters[i] == "-t") + treesonly = true; + else if(parameters[i] == "-s") + shrubsonly = true; + else if(parameters[i] == "-c") + deselect = true; + else if(parameters[i] == "-x") + exclude = true; + else plantNames.insert(parameters[i]); + } + c->Suspend(); + + Materials *mats = c->getMaterials(); + mats->ReadOrganicMaterials(); + for (vector::const_iterator it = mats->organic.begin(); it != mats->organic.end(); it++) + { + if (plantNames.find((*it).id) != plantNames.end()) + { + plantNames.erase((*it).id); + plantIDs.insert(it - mats->organic.begin()); + } + } + if (plantNames.size() > 0) + { + c->con.printerr("Invalid plant ID(s):"); + for (set::const_iterator it = plantNames.begin(); it != plantNames.end(); it++) + c->con.printerr(" %s", (*it).c_str()); + c->Resume(); + return CR_FAILURE; + } + + if (plantIDs.size() == 0) + { + c->con.print("Valid plant IDs:\n"); + for (vector::const_iterator it = mats->organic.begin(); it != mats->organic.end(); it++) + c->con.print("* %s\n", (*it).id.c_str()); + c->Resume(); + return CR_OK; + } + + Maps *maps = c->getMaps(); + + // init the map + if (!maps->Start()) + { + c->con.printerr("Can't init map.\n"); + c->Resume(); + return CR_FAILURE; + } + + maps->getSize(x_max,y_max,z_max); + // walk the map + for (uint32_t x = 0; x < x_max; x++) + { + for (uint32_t y = 0; y < y_max; y++) + { + for (uint32_t z = 0; z < z_max; z++) + { + if (maps->getBlock(x,y,z)) + { + dirty = false; + maps->ReadDesignations(x,y,z, &designations); + maps->ReadTileTypes(x,y,z, &tiles); + maps->ReadBlockFlags(x,y,z, blockflags); + + vector *plants; + if (maps->ReadVegetation(x, y, z, plants)) + { + for (vector::const_iterator it = plants->begin(); it != plants->end(); it++) + { + const df_plant &plant = *(*it); + uint32_t tx = plant.x % 16; + uint32_t ty = plant.y % 16; + if (plantIDs.find(plant.material) != plantIDs.end()) + { + if (exclude) + continue; + } + else + { + if (!exclude) + continue; + } + + TileShape shape = tileShape(tiles[tx][ty]); + if (plant.is_shrub && (treesonly || shape != SHRUB_OK)) + continue; + if (!plant.is_shrub && (shrubsonly || (shape != TREE_OK && shape != TREE_DEAD))) + continue; + if (designations[tx][ty].bits.hidden) + continue; + if (deselect && designations[tx][ty].bits.dig != designation_no) + { + designations[tx][ty].bits.dig = designation_no; + dirty = true; + ++count; + } + if (!deselect && designations[tx][ty].bits.dig != designation_default) + { + designations[tx][ty].bits.dig = designation_default; + dirty = true; + ++count; + } + } + } + // If anything was changed, write it all. + if (dirty) + { + blockflags.bits.designated = 1; + maps->WriteDesignations(x,y,z, &designations); + maps->WriteBlockFlags(x,y,z, blockflags); + dirty = false; + } + } + } + } + } + c->Resume(); + if (count) + c->con.print("Updated %d plant designations.\n", count); + return CR_OK; +} diff --git a/plugins/skeleton/CMakeLists.txt b/plugins/skeleton/CMakeLists.txt new file mode 100644 index 000000000..542f08fe3 --- /dev/null +++ b/plugins/skeleton/CMakeLists.txt @@ -0,0 +1,33 @@ +PROJECT (skeleton) +# A list of source files +SET(PROJECT_SRCS + skeleton.cpp +) +# A list of headers +SET(PROJECT_HDRS + skeleton.h +) +SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE) + +# mash them together (headers are marked as headers and nothing will try to compile them) +LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS}) + +# option to use a thread for no particular reason +OPTION(SKELETON_THREAD "Use threads in the skeleton plugin." ON) +#linux +IF(UNIX) + add_definitions(-DLINUX_BUILD) + SET(PROJECT_LIBS + # add any extra linux libs here + ${PROJECT_LIBS} + ) +# windows +ELSE(UNIX) + SET(PROJECT_LIBS + # add any extra linux libs here + ${PROJECT_LIBS} + $(NOINHERIT) + ) +ENDIF(UNIX) +# this makes sure all the stuff is put in proper places and linked to dfhack +DFHACK_PLUGIN(skeleton ${PROJECT_SRCS} LINK_LIBRARIES ${PROJECT_LIBS}) diff --git a/plugins/skeleton/skeleton.cpp b/plugins/skeleton/skeleton.cpp new file mode 100644 index 000000000..d69a2dd95 --- /dev/null +++ b/plugins/skeleton/skeleton.cpp @@ -0,0 +1,78 @@ +// This is a generic plugin that does nothing useful apart from acting as an example... of a plugin that does nothing :D + +// some headers required for a plugin. Nothing special, just the basics. +#include +#include +#include +#include +using namespace DFHack; + +// our own, empty header. +#include "skeleton.h" + + +// Here go all the command declarations... +// mostly to allow having the mandatory stuff on top of the file and commands on the bottom +DFhackCExport command_result skeleton (Core * c, std::vector & parameters); + +// A plugins must be able to return its name. This must correspond to the filename - skeleton.plug.so or skeleton.plug.dll +DFhackCExport const char * plugin_name ( void ) +{ + return "skeleton"; +} + +// Mandatory init function. If you have some global state, create it here. +DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) +{ + // Fill the command list with your commands. + commands.clear(); + commands.push_back(PluginCommand("skeleton", + "Do nothing, look pretty.", + skeleton /*, + true or false - true means that the command can't be used from non-interactive user interface'*/)); + return CR_OK; +} + +// This is called right before the plugin library is removed from memory. +DFhackCExport command_result plugin_shutdown ( Core * c ) +{ + // You *MUST* kill all threads you created before this returns. + // If everythin fails, just return CR_FAILURE. Your plugin will be + // in a zombie state, but things won't crash. + return CR_OK; +} + +// Whatever you put here will be done in each game step. Don't abuse it. +// It's optional, so you can just comment it out like this if you don't need it. +/* +DFhackCExport command_result plugin_onupdate ( Core * c ) +{ + // whetever. You don't need to suspend DF execution here. + return CR_OK; +} +*/ + +// A command! It sits around and looks pretty. And it's nice and friendly. +DFhackCExport command_result skeleton (Core * c, std::vector & parameters) +{ + // It's nice to provide a 'help' option for your command. + // It's also nice to print the same help if you get invalid options from the user instead of just acting strange + for(int i = 0; i < parameters.size();i++) + { + if(parameters[i] == "help" || parameters[i] == "?") + { + // Core has a handle to the console. The console is thread-safe. + // Only one thing can read from it at a time though... + c->con.print("This command does nothing!\n"); + return CR_OK; + } + } + // Commands are called from threads other than the DF one. + // Suspend this thread until DF has time for us. + c->Suspend(); + // Actually do something here. Yay. + c->con.print("Hello! I do nothing, remember?\n"); + // Give control back to DF. + c->Resume(); + return CR_OK; +} diff --git a/plugins/skeleton/skeleton.h b/plugins/skeleton/skeleton.h new file mode 100644 index 000000000..7b9637ef9 --- /dev/null +++ b/plugins/skeleton/skeleton.h @@ -0,0 +1 @@ +#pragma once \ No newline at end of file diff --git a/plugins/vdig.cpp b/plugins/vdig.cpp index 2453bacad..f34169b84 100644 --- a/plugins/vdig.cpp +++ b/plugins/vdig.cpp @@ -215,6 +215,8 @@ DFhackCExport command_result digcircle (Core * c, vector & parameters) std::cerr << "allowing tt" << tt << ", is floor\n"; break; } + if(isStairTerrain(tt) && type == designation_channel ) + break; return false; } while(0);