From 2af3b49e0993f55822624ee7ea7be157fc3b9b30 Mon Sep 17 00:00:00 2001 From: Quietust Date: Mon, 2 Jan 2012 20:13:27 -0600 Subject: [PATCH] Add "regrass" plugin, regrows grass for pre-0.31.19 fortresses --- plugins/CMakeLists.txt | 1 + plugins/regrass.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 plugins/regrass.cpp diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 133905727..671036626 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -61,6 +61,7 @@ DFHACK_PLUGIN(initflags initflags.cpp) DFHACK_PLUGIN(stockpiles stockpiles.cpp) DFHACK_PLUGIN(rename rename.cpp) DFHACK_PLUGIN(fixwagons fixwagons.cpp) +DFHACK_PLUGIN(regrass regrass.cpp) #DFHACK_PLUGIN(versionosd versionosd.cpp) # this is the skeleton plugin. If you want to make your own, make a copy and then change it diff --git a/plugins/regrass.cpp b/plugins/regrass.cpp new file mode 100644 index 000000000..bd227638e --- /dev/null +++ b/plugins/regrass.cpp @@ -0,0 +1,83 @@ +// All above-ground soil not covered by buildings will be covered with grass. +// Necessary for worlds generated prior to version 0.31.19 - otherwise, outdoor shrubs and trees no longer grow. + +#include "Core.h" +#include +#include +#include + +#include +#include +#include +#include + +using std::string; +using std::vector; +using namespace DFHack; + +using df::global::world; +using df::map_block; + +DFhackCExport command_result df_regrass (Core * c, vector & parameters) +{ + if (!parameters.empty()) + return CR_WRONG_USAGE; + + CoreSuspender suspend(c); + + int count = 0; + for (int i = 0; i < world->map.map_blocks.size(); i++) + { + map_block *cur = world->map.map_blocks[i]; + for (int x = 0; x < 16; x++) + { + for (int y = 0; y < 16; y++) + { + if (DFHack::tileShape(cur->tiletype[x][y]) != DFHack::FLOOR) + continue; + if (DFHack::tileMaterial(cur->tiletype[x][y]) != DFHack::SOIL) + continue; + if (cur->designation[x][y].bits.subterranean) + continue; + if (cur->occupancy[x][y].bits.building) + continue; + + switch (rand() % 8) + { + // light grass + case 0: cur->tiletype[x][y] = 0x015C; break; + case 1: cur->tiletype[x][y] = 0x015D; break; + case 2: cur->tiletype[x][y] = 0x015E; break; + case 3: cur->tiletype[x][y] = 0x015F; break; + // dark grass + case 4: cur->tiletype[x][y] = 0x018E; break; + case 5: cur->tiletype[x][y] = 0x018F; break; + case 6: cur->tiletype[x][y] = 0x0190; break; + case 7: cur->tiletype[x][y] = 0x0191; break; + } + count++; + } + } + } + + if (count) + c->con.print("Regrew %d tiles of grass.\n", count); + return CR_OK; +} + +DFhackCExport const char *plugin_name ( void ) +{ + return "regrass"; +} + +DFhackCExport command_result plugin_init (Core *c, std::vector &commands) +{ + commands.clear(); + commands.push_back(PluginCommand("regrass", "Regrows all surface grass, restoring outdoor plant growth for pre-0.31.19 worlds.", df_regrass)); + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown ( Core * c ) +{ + return CR_OK; +}