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"
|
2012-04-11 06:08:47 -06:00
|
|
|
#include "df/world_raws.h"
|
|
|
|
#include "df/plant_raw.h"
|
|
|
|
|
2012-01-11 09:31:23 -07:00
|
|
|
#include "df/map_block.h"
|
2012-04-11 06:08:47 -06:00
|
|
|
#include "df/block_square_event.h"
|
|
|
|
//#include "df/block_square_event_type.h"
|
|
|
|
#include "df/block_square_event_grassst.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;
|
2012-04-11 06:08:47 -06:00
|
|
|
using namespace std;
|
2012-01-02 19:13:27 -07:00
|
|
|
using namespace DFHack;
|
|
|
|
|
2012-04-11 06:08:47 -06:00
|
|
|
DFHACK_PLUGIN("regrass");
|
2014-12-06 16:47:35 -07:00
|
|
|
REQUIRE_GLOBAL(world);
|
2012-04-11 06:08:47 -06:00
|
|
|
|
|
|
|
command_result df_regrass (color_ostream &out, vector <string> & parameters);
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init (color_ostream &out, std::vector<PluginCommand> &commands)
|
|
|
|
{
|
2013-10-30 14:58:14 -06:00
|
|
|
commands.push_back(PluginCommand("regrass", "Regrows surface grass.", df_regrass, false,
|
|
|
|
"Specify parameter 'max' to set all grass types to full density, otherwise only one type of grass will be restored per tile.\n"));
|
2012-04-11 06:08:47 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
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-04-11 06:08:47 -06:00
|
|
|
bool max = false;
|
2012-01-21 17:31:15 -07:00
|
|
|
if (!parameters.empty())
|
2012-04-11 06:08:47 -06:00
|
|
|
{
|
|
|
|
if(parameters[0] == "max")
|
|
|
|
max = true;
|
|
|
|
else
|
|
|
|
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];
|
2012-04-11 06:08:47 -06:00
|
|
|
|
|
|
|
// check block for grass events before looking at 16x16 tiles
|
|
|
|
df::block_square_event_grassst * grev = NULL;
|
|
|
|
for(size_t e=0; e<cur->block_events.size(); e++)
|
|
|
|
{
|
|
|
|
df::block_square_event * blev = cur->block_events[e];
|
|
|
|
df::block_square_event_type blevtype = blev->getType();
|
|
|
|
if(blevtype == df::block_square_event_type::grass)
|
|
|
|
{
|
|
|
|
grev = (df::block_square_event_grassst *)blev;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!grev)
|
2012-01-21 17:31:15 -07:00
|
|
|
{
|
2012-04-11 06:08:47 -06:00
|
|
|
// in this worst case we should check other blocks, create a new event etc
|
|
|
|
// but looking at some maps that should happen very very rarely if at all
|
|
|
|
// a standard map block seems to always have up to 10 grass events we can refresh
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int y = 0; y < 16; y++)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < 16; x++)
|
2012-01-21 17:31:15 -07:00
|
|
|
{
|
2012-04-11 06:08:47 -06:00
|
|
|
if ( tileShape(cur->tiletype[x][y]) != tiletype_shape::FLOOR
|
|
|
|
|| cur->designation[x][y].bits.subterranean
|
2012-04-22 16:34:19 -06:00
|
|
|
|| cur->occupancy[x][y].bits.building
|
|
|
|
|| cur->occupancy[x][y].bits.no_grow)
|
2012-01-21 17:31:15 -07:00
|
|
|
continue;
|
2012-04-11 06:08:47 -06:00
|
|
|
|
2012-04-22 12:25:10 -06:00
|
|
|
// don't touch furrowed tiles (dirt roads made on soil)
|
|
|
|
if(tileSpecial(cur->tiletype[x][y]) == tiletype_special::FURROWED)
|
|
|
|
continue;
|
|
|
|
|
2012-04-11 06:08:47 -06:00
|
|
|
int mat = tileMaterial(cur->tiletype[x][y]);
|
|
|
|
if ( mat != tiletype_material::SOIL
|
|
|
|
&& mat != tiletype_material::GRASS_DARK // refill existing grass, too
|
|
|
|
&& mat != tiletype_material::GRASS_LIGHT // refill existing grass, too
|
|
|
|
)
|
2012-01-21 17:31:15 -07:00
|
|
|
continue;
|
2012-01-02 19:13:27 -07:00
|
|
|
|
2012-04-22 12:25:10 -06:00
|
|
|
|
2012-04-11 06:08:47 -06:00
|
|
|
// max = set amounts of all grass events on that tile to 100
|
|
|
|
if(max)
|
|
|
|
{
|
|
|
|
for(size_t e=0; e<cur->block_events.size(); e++)
|
|
|
|
{
|
|
|
|
df::block_square_event * blev = cur->block_events[e];
|
|
|
|
df::block_square_event_type blevtype = blev->getType();
|
|
|
|
if(blevtype == df::block_square_event_type::grass)
|
|
|
|
{
|
|
|
|
df::block_square_event_grassst * gr_ev = (df::block_square_event_grassst *)blev;
|
|
|
|
gr_ev->amount[x][y] = 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-11 09:01:20 -06:00
|
|
|
// try to find the 'original' event
|
|
|
|
bool regrew = false;
|
|
|
|
for(size_t e=0; e<cur->block_events.size(); e++)
|
|
|
|
{
|
|
|
|
df::block_square_event * blev = cur->block_events[e];
|
|
|
|
df::block_square_event_type blevtype = blev->getType();
|
|
|
|
if(blevtype == df::block_square_event_type::grass)
|
|
|
|
{
|
|
|
|
df::block_square_event_grassst * gr_ev = (df::block_square_event_grassst *)blev;
|
|
|
|
if(gr_ev->amount[x][y] > 0)
|
|
|
|
{
|
|
|
|
gr_ev->amount[x][y] = 100;
|
|
|
|
regrew = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if original could not be found (meaning it was already depleted):
|
2012-04-15 23:03:27 -06:00
|
|
|
// refresh random grass event in the map block
|
2012-04-11 09:01:20 -06:00
|
|
|
if(!regrew)
|
2012-04-15 23:03:27 -06:00
|
|
|
{
|
|
|
|
vector <df::block_square_event_grassst *> gr_evs;
|
|
|
|
for(size_t e=0; e<cur->block_events.size(); e++)
|
|
|
|
{
|
|
|
|
df::block_square_event * blev = cur->block_events[e];
|
|
|
|
df::block_square_event_type blevtype = blev->getType();
|
|
|
|
if(blevtype == df::block_square_event_type::grass)
|
|
|
|
{
|
|
|
|
df::block_square_event_grassst * gr_ev = (df::block_square_event_grassst *)blev;
|
|
|
|
gr_evs.push_back(gr_ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int r = rand() % gr_evs.size();
|
|
|
|
gr_evs[r]->amount[x][y]=100;
|
|
|
|
}
|
2012-04-11 06:08:47 -06: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
|
|
|
}
|