2012-01-02 19:13:27 -07:00
|
|
|
// 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"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
2012-01-02 19:13:27 -07:00
|
|
|
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "DataDefs.h"
|
2012-01-11 09:31:23 -07:00
|
|
|
#include "df/world.h"
|
|
|
|
#include "df/map_block.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "TileTypes.h"
|
2012-01-02 19:13:27 -07:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
using df::global::world;
|
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result df_regrass (color_ostream &out, vector <string> & parameters)
|
2012-01-02 19:13:27 -07:00
|
|
|
{
|
2012-01-21 17:31:15 -07:00
|
|
|
if (!parameters.empty())
|
|
|
|
return CR_WRONG_USAGE;
|
2012-01-02 19:13:27 -07:00
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
CoreSuspender suspend;
|
2012-01-02 19:13:27 -07:00
|
|
|
|
2012-01-21 17:31:15 -07:00
|
|
|
int count = 0;
|
2012-01-31 09:55:38 -07:00
|
|
|
for (size_t i = 0; i < world->map.map_blocks.size(); i++)
|
2012-01-21 17:31:15 -07:00
|
|
|
{
|
|
|
|
df::map_block *cur = world->map.map_blocks[i];
|
|
|
|
for (int x = 0; x < 16; x++)
|
|
|
|
{
|
|
|
|
for (int y = 0; y < 16; y++)
|
|
|
|
{
|
2012-02-13 18:17:38 -07:00
|
|
|
if (tileShape(cur->tiletype[x][y]) != tiletype_shape::FLOOR)
|
2012-01-21 17:31:15 -07:00
|
|
|
continue;
|
2012-02-13 18:17:38 -07:00
|
|
|
if (tileMaterial(cur->tiletype[x][y]) != tiletype_material::SOIL)
|
2012-01-21 17:31:15 -07:00
|
|
|
continue;
|
|
|
|
if (cur->designation[x][y].bits.subterranean)
|
|
|
|
continue;
|
|
|
|
if (cur->occupancy[x][y].bits.building)
|
|
|
|
continue;
|
2012-01-02 19:13:27 -07:00
|
|
|
|
2012-02-13 18:17:38 -07:00
|
|
|
cur->tiletype[x][y] = findRandomVariant((rand() & 1) ? tiletype::GrassLightFloor1 : tiletype::GrassDarkFloor1);
|
2012-01-21 17:31:15 -07:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-02 19:13:27 -07:00
|
|
|
|
2012-01-21 17:31:15 -07:00
|
|
|
if (count)
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("Regrew %d tiles of grass.\n", count);
|
2012-01-21 17:31:15 -07:00
|
|
|
return CR_OK;
|
2012-01-02 19:13:27 -07:00
|
|
|
}
|
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("regrass");
|
2012-01-02 19:13:27 -07:00
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
DFhackCExport command_result plugin_init (color_ostream &out, std::vector<PluginCommand> &commands)
|
2012-01-02 19:13:27 -07:00
|
|
|
{
|
2012-01-21 17:31:15 -07:00
|
|
|
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;
|
2012-01-02 19:13:27 -07:00
|
|
|
}
|
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2012-01-02 19:13:27 -07:00
|
|
|
{
|
2012-01-21 17:31:15 -07:00
|
|
|
return CR_OK;
|
2012-02-13 21:54:08 -07:00
|
|
|
}
|