Petr Mrázek 2012-01-08 16:17:28 +01:00
commit 3a8bc4dbb5
4 changed files with 242 additions and 331 deletions

@ -2,99 +2,69 @@
#include <Console.h> #include <Console.h>
#include <Export.h> #include <Export.h>
#include <PluginManager.h> #include <PluginManager.h>
#include <modules/Maps.h>
#include <modules/Items.h>
#include <modules/Units.h>
#include <modules/Gui.h>
using namespace DFHack; #include "DataDefs.h"
#include "df/world.h"
#include "df/map_block.h"
#include "df/block_square_event.h"
#include "df/block_square_event_material_spatterst.h"
#include "df/item_actual.h"
#include "df/unit.h"
#include "df/matter_state.h"
#include "df/cursor.h"
#include "modules/Materials.h"
#include <vector>
#include <string>
#include <string.h>
using std::vector; using std::vector;
using std::string; using std::string;
using namespace DFHack;
DFhackCExport command_result clean (Core * c, vector <string> & parameters); using df::global::world;
DFhackCExport command_result spotclean (Core * c, vector <string> & parameters); using df::global::cursor;
DFhackCExport const char * plugin_name ( void )
{
return "cleaners";
}
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("clean","Removes contaminants from map tiles, items and creatures.",clean));
commands.push_back(PluginCommand("spotclean","Cleans map tile under cursor.",spotclean,cursor_hotkey));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK;
}
command_result cleanmap (Core * c, bool snow, bool mud) command_result cleanmap (Core * c, bool snow, bool mud)
{ {
const uint32_t water_idx = 6; // Invoked from clean(), already suspended
const uint32_t mud_idx = 12; int num_blocks = 0, blocks_total = world->map.map_blocks.size();
vector<DFHack::t_spattervein *> splatter; for (int i = 0; i < blocks_total; i++)
DFHack::Maps *Mapz = c->getMaps();
// init the map
if(!Mapz->Start())
{
c->con << "Can't init map." << std::endl;
c->Resume();
return CR_FAILURE;
}
uint32_t x_max,y_max,z_max;
Mapz->getSize(x_max,y_max,z_max);
int num_blocks = 0;
int blocks_total = 0;
// walk the map
for(uint32_t x = 0; x< x_max;x++)
{ {
for(uint32_t y = 0; y< y_max;y++) df::map_block *block = world->map.map_blocks[i];
bool cleaned = false;
for(int x = 0; x < 16; x++)
{ {
for(uint32_t z = 0; z< z_max;z++) for(int y = 0; y < 16; y++)
{ {
df_block * block = Mapz->getBlock(x,y,z); block->occupancy[x][y].bits.arrow_color = 0;
if(block) block->occupancy[x][y].bits.arrow_variant = 0;
{
blocks_total ++;
bool cleaned = false;
Mapz->SortBlockEvents(x,y,z,0,0,&splatter);
for(int i = 0; i < 16; i++)
for(int j = 0; j < 16; j++)
{
block->occupancy[i][j].bits.arrow_color = 0;
block->occupancy[i][j].bits.broken_arrows_variant = 0;
}
for(uint32_t i = 0; i < splatter.size(); i++)
{
DFHack::t_spattervein * vein = splatter[i];
// filter snow
if(!snow
&& vein->mat1 == DFHack::Materials::WATER
&& vein->matter_state == DFHack::state_powder)
continue;
// filter mud
if(!mud
&& vein->mat1 == DFHack::Materials::MUD
&& vein->matter_state == DFHack::state_solid)
continue;
Mapz->RemoveBlockEvent(x,y,z,(t_virtual *) vein);
cleaned = true;
}
num_blocks += cleaned;
}
} }
} }
for (int j = 0; j < block->block_events.size(); j++)
{
df::block_square_event *evt = block->block_events[j];
if (evt->getType() != df::block_square_event_type::material_spatter)
continue;
// type verified - recast to subclass
df::block_square_event_material_spatterst *spatter = (df::block_square_event_material_spatterst *)evt;
// filter snow
if(!snow
&& spatter->mat_type == DFHack::Materials::WATER
&& spatter->mat_state == df::matter_state::Powder)
continue;
// filter mud
if(!mud
&& spatter->mat_type == DFHack::Materials::MUD
&& spatter->mat_state == df::matter_state::Solid)
continue;
delete evt;
block->block_events.erase(block->block_events.begin() + j);
j--;
cleaned = true;
}
num_blocks += cleaned;
} }
if(num_blocks) if(num_blocks)
c->con.print("Cleaned %d of %d map blocks.\n", num_blocks, blocks_total); c->con.print("Cleaned %d of %d map blocks.\n", num_blocks, blocks_total);
return CR_OK; return CR_OK;
@ -102,94 +72,82 @@ command_result cleanmap (Core * c, bool snow, bool mud)
command_result cleanitems (Core * c) command_result cleanitems (Core * c)
{ {
DFHack::Items * Items = c->getItems(); // Invoked from clean(), already suspended
vector <df_item*> p_items;
if(!Items->readItemVector(p_items))
{
c->con.printerr("Can't access the item vector.\n");
c->Resume();
return CR_FAILURE;
}
std::size_t numItems = p_items.size();
int cleaned_items = 0, cleaned_total = 0; int cleaned_items = 0, cleaned_total = 0;
for (std::size_t i = 0; i < numItems; i++) for (int i = 0; i < world->items.all.size(); i++)
{ {
df_item * itm = p_items[i]; // currently, all item classes extend item_actual, so this should be safe
if(!itm->contaminants) df::item_actual *item = (df::item_actual *)world->items.all[i];
continue; if (item->contaminants && item->contaminants->size())
if (itm->contaminants->size())
{ {
for(int j = 0; j < itm->contaminants->size(); j++) for (int j = 0; j < item->contaminants->size(); j++)
delete itm->contaminants->at(j); delete item->contaminants->at(j);
cleaned_items++; cleaned_items++;
cleaned_total += itm->contaminants->size(); cleaned_total += item->contaminants->size();
itm->contaminants->clear(); item->contaminants->clear();
} }
} }
if(cleaned_total) if (cleaned_total)
c->con.print("Removed %d contaminants from %d items.\n", cleaned_total, cleaned_items); c->con.print("Removed %d contaminants from %d items.\n", cleaned_total, cleaned_items);
return CR_OK; return CR_OK;
} }
command_result cleanunits (Core * c) command_result cleanunits (Core * c)
{ {
DFHack::Units * Creatures = c->getUnits(); // Invoked from clean(), already suspended
int num_units = world->units.all.size();
uint32_t num_creatures;
if (!Creatures->Start(num_creatures))
{
c->con.printerr("Can't read unit list!\n");
c->Resume();
return CR_FAILURE;
}
int cleaned_units = 0, cleaned_total = 0; int cleaned_units = 0, cleaned_total = 0;
for (std::size_t i = 0; i < num_creatures; i++) for (int i = 0; i < num_units; i++)
{ {
df_unit *unit = Creatures->creatures->at(i); df::unit *unit = world->units.all[i];
int num = unit->contaminants.size(); if (unit->body.spatters.size())
if (num)
{ {
for(int j = 0; j < unit->contaminants.size(); j++) for (int j = 0; j < unit->body.spatters.size(); j++)
delete unit->contaminants.at(j); delete unit->body.spatters[j];
cleaned_units++; cleaned_units++;
cleaned_total += num; cleaned_total += unit->body.spatters.size();
unit->contaminants.clear(); unit->body.spatters.clear();
} }
} }
if(cleaned_total) if (cleaned_total)
c->con.print("Removed %d contaminants from %d creatures.\n", cleaned_total, cleaned_units); c->con.print("Removed %d contaminants from %d creatures.\n", cleaned_total, cleaned_units);
return CR_OK; return CR_OK;
} }
// This is slightly different from what's in the Maps module - it takes tile coordinates rather than block coordinates
df::map_block *getBlock (int32_t x, int32_t y, int32_t z)
{
if ((x < 0) || (y < 0) || (z < 0))
return NULL;
if ((x >= world->map.x_count) || (y >= world->map.y_count) || (z >= world->map.z_count))
return NULL;
// block_index isn't declared correctly - needs one more level of indirection
return ((df::map_block ****)world->map.block_index)[x >> 4][y >> 4][z];
}
DFhackCExport command_result spotclean (Core * c, vector <string> & parameters) DFhackCExport command_result spotclean (Core * c, vector <string> & parameters)
{ {
// HOTKEY COMMAND: CORE ALREADY SUSPENDED // HOTKEY COMMAND: CORE ALREADY SUSPENDED
vector<DFHack::t_spattervein *> splatter; if (cursor->x == -30000)
DFHack::Maps *Mapz = c->getMaps();
DFHack::Gui *Gui = c->getGui();
// init the map
if(!Mapz->Start())
{ {
c->con.printerr("Can't init map.\n"); c->con.printerr("The cursor is not active.\n");
return CR_FAILURE; return CR_FAILURE;
} }
int32_t cursorX, cursorY, cursorZ; df::map_block *block = getBlock(cursor->x, cursor->y, cursor->z);
Gui->getCursorCoords(cursorX,cursorY,cursorZ); if (block == NULL)
if(cursorX == -30000)
{ {
c->con.printerr("The cursor is not active.\n"); c->con.printerr("Invalid map block selected!\n");
return CR_FAILURE; return CR_FAILURE;
} }
int32_t blockX = cursorX / 16, blockY = cursorY / 16;
int32_t tileX = cursorX % 16, tileY = cursorY % 16; for (int i = 0; i < block->block_events.size(); i++)
df_block *b = Mapz->getBlock(blockX,blockY,cursorZ);
vector <t_spattervein *> spatters;
Mapz->SortBlockEvents(blockX, blockY, cursorZ, 0,0, &spatters);
for(int i = 0; i < spatters.size(); i++)
{ {
spatters[i]->intensity[tileX][tileY] = 0; df::block_square_event *evt = block->block_events[i];
if (evt->getType() != df::block_square_event_type::material_spatter)
continue;
// type verified - recast to subclass
df::block_square_event_material_spatterst *spatter = (df::block_square_event_material_spatterst *)evt;
spatter->amount[cursor->x % 16][cursor->y % 16] = 0;
} }
return CR_OK; return CR_OK;
} }
@ -230,17 +188,17 @@ DFhackCExport command_result clean (Core * c, vector <string> & parameters)
if(help) if(help)
{ {
c->con.print("Removes contaminants from map tiles, items and creatures.\n" c->con.print("Removes contaminants from map tiles, items and creatures.\n"
"Options:\n" "Options:\n"
"map - clean the map tiles\n" "map - clean the map tiles\n"
"items - clean all items\n" "items - clean all items\n"
"units - clean all creatures\n" "units - clean all creatures\n"
"all - clean everything.\n" "all - clean everything.\n"
"More options for 'map':\n" "More options for 'map':\n"
"snow - also remove snow\n" "snow - also remove snow\n"
"mud - also remove mud\n" "mud - also remove mud\n"
"Example: clean all mud snow\n" "Example: clean all mud snow\n"
"This removes all spatter, including mud and snow from map tiles." "This removes all spatter, including mud and snow from map tiles."
); );
return CR_OK; return CR_OK;
} }
c->Suspend(); c->Suspend();
@ -253,3 +211,21 @@ DFhackCExport command_result clean (Core * c, vector <string> & parameters)
c->Resume(); c->Resume();
return CR_OK; return CR_OK;
} }
DFhackCExport const char * plugin_name ( void )
{
return "cleaners";
}
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("clean","Removes contaminants from map tiles, items and creatures.",clean));
commands.push_back(PluginCommand("spotclean","Cleans map tile under cursor.",spotclean,cursor_hotkey));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK;
}

@ -1,24 +1,43 @@
// Dry Buckets : Remove all "water" objects from buckets scattered around the fortress // Dry Buckets : Remove all "water" objects from buckets scattered around the fortress
#include <iostream>
#include <iomanip>
#include <sstream>
#include <climits>
#include <vector>
#include <set>
using namespace std;
#include "Core.h" #include "Core.h"
#include <Console.h> #include <Console.h>
#include <Export.h> #include <Export.h>
#include <PluginManager.h> #include <PluginManager.h>
#include <vector>
#include <string>
#include <algorithm>
#include <modules/Items.h>
#include <DataDefs.h>
#include "df/world.h"
#include "df/item.h"
#include "modules/Materials.h"
using std::string;
using std::vector;
using namespace DFHack; using namespace DFHack;
DFhackCExport command_result df_drybuckets (Core * c, vector <string> & parameters); using df::global::world;
DFhackCExport command_result df_drybuckets (Core * c, vector <string> & parameters)
{
if (!parameters.empty())
return CR_WRONG_USAGE;
CoreSuspender suspend(c);
int dried_total = 0;
for (int i = 0; i < world->items.all.size(); i++)
{
df::item *item = world->items.all[i];
if ((item->getType() == df::item_type::LIQUID_MISC) && (item->getMaterial() == DFHack::Materials::WATER))
{
item->flags.bits.garbage_colect = 1;
dried_total++;
}
}
if (dried_total)
c->con.print("Done. %d buckets of water marked for emptying.\n", dried_total);
return CR_OK;
}
DFhackCExport const char * plugin_name ( void ) DFhackCExport const char * plugin_name ( void )
{ {
@ -35,42 +54,4 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
DFhackCExport command_result plugin_shutdown ( Core * c ) DFhackCExport command_result plugin_shutdown ( Core * c )
{ {
return CR_OK; return CR_OK;
}
DFhackCExport command_result df_drybuckets (Core * c, vector <string> & parameters)
{
if(parameters.size() > 0)
{
string & p = parameters[0];
if(p == "?" || p == "help")
{
c->con.print("This utility removes all objects of type LIQUID_MISC:NONE and material WATER:NONE - that is, water stored in buckets.\n");
return CR_OK;
}
}
c->Suspend();
DFHack::Items * Items = c->getItems();
vector <df_item *> p_items;
if(!Items->readItemVector(p_items))
{
c->con.printerr("Can't access the item vector.\n");
c->Resume();
return CR_FAILURE;
}
std::size_t numItems = p_items.size();
int dried_total = 0;
for (std::size_t i = 0; i < numItems; i++)
{
df_item *item = p_items[i];
if ((item->getType() == Items::LIQUID_MISC) && (item->getMaterial() == Materials::WATER))
{
item->flags.garbage_colect = 1;
dried_total++;
}
}
c->Resume();
c->con.print("Done. %d buckets of water emptied.\n", dried_total);
return CR_OK;
} }

@ -6,21 +6,17 @@
#include <PluginManager.h> #include <PluginManager.h>
#include <DataDefs.h> #include <DataDefs.h>
#include <df/world.h> #include "df/world.h"
#include <df/historical_entity.h> #include "df/historical_entity.h"
#include <df/entity_raw.h> #include "df/entity_raw.h"
#include <df/creature_raw.h> #include "df/creature_raw.h"
#include <df/caste_raw.h> #include "df/caste_raw.h"
using std::string; using std::string;
using std::vector; using std::vector;
using namespace DFHack; using namespace DFHack;
using df::global::world; using df::global::world;
using df::historical_entity;
using df::entity_raw_flags;
using df::creature_raw;
using df::creature_raw_flags;
command_result df_fixwagons (Core *c, vector<string> &parameters) command_result df_fixwagons (Core *c, vector<string> &parameters)
{ {
@ -29,11 +25,11 @@ command_result df_fixwagons (Core *c, vector<string> &parameters)
CoreSuspender suspend(c); CoreSuspender suspend(c);
int32_t wagon_creature = -1, wagon_puller_creature = -1; int32_t wagon_creature = -1, wagon_puller_creature = -1;
creature_raw *wagon, *wagon_puller; df::creature_raw *wagon, *wagon_puller;
for (int i = 0; i < world->raws.creatures.all.size(); i++) for (int i = 0; i < world->raws.creatures.all.size(); i++)
{ {
creature_raw *cr = world->raws.creatures.all[i]; df::creature_raw *cr = world->raws.creatures.all[i];
if (cr->flags.is_set(creature_raw_flags::EQUIPMENT_WAGON) && (wagon_creature == -1)) if (cr->flags.is_set(df::creature_raw_flags::EQUIPMENT_WAGON) && (wagon_creature == -1))
{ {
wagon = cr; wagon = cr;
wagon_creature = i; wagon_creature = i;
@ -58,8 +54,8 @@ command_result df_fixwagons (Core *c, vector<string> &parameters)
for (int i = 0; i < world->entities.all.size(); i++) for (int i = 0; i < world->entities.all.size(); i++)
{ {
bool updated = false; bool updated = false;
historical_entity *ent = world->entities.all[i]; df::historical_entity *ent = world->entities.all[i];
if (!ent->entity_raw->flags.is_set(entity_raw_flags::COMMON_DOMESTIC_PULL)) if (!ent->entity_raw->flags.is_set(df::entity_raw_flags::COMMON_DOMESTIC_PULL))
continue; continue;
if (ent->resources.animals.wagon_races.size() == 0) if (ent->resources.animals.wagon_races.size() == 0)
{ {
@ -107,4 +103,4 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
DFhackCExport command_result plugin_shutdown ( Core * c ) DFhackCExport command_result plugin_shutdown ( Core * c )
{ {
return CR_OK; return CR_OK;
} }

@ -1,56 +1,34 @@
// Designate all matching plants for gathering/cutting // Designate all matching plants for gathering/cutting
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stddef.h>
#include <assert.h>
#include <string.h>
#include "Core.h" #include "Core.h"
#include <Console.h> #include <Console.h>
#include <Export.h> #include <Export.h>
#include <PluginManager.h> #include <PluginManager.h>
#include <modules/Maps.h>
#include <modules/Materials.h>
#include <modules/Vegetation.h>
#include <TileTypes.h>
using namespace std; #include <DataDefs.h>
using namespace DFHack; #include <TileTypes.h>
#include "df/world.h"
DFhackCExport command_result df_getplants (Core * c, vector <string> & parameters); #include "df/map_block.h"
#include "df/tile_dig_designation.h"
#include "df/plant_raw.h"
DFhackCExport const char * plugin_name ( void ) #include "modules/Vegetation.h"
{ #include <set>
return "getplants";
}
DFhackCExport command_result plugin_init ( Core * c, vector <PluginCommand> &commands) using std::string;
{ using std::vector;
commands.clear(); using std::set;
commands.push_back(PluginCommand("getplants", "Cut down all of the specified trees or gather all of the specified shrubs", df_getplants)); using namespace DFHack;
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( Core * c ) using df::global::world;
{
return CR_OK;
}
DFhackCExport command_result df_getplants (Core * c, vector <string> & parameters) DFhackCExport command_result df_getplants (Core * c, vector <string> & parameters)
{ {
uint32_t x_max,y_max,z_max;
designations40d designations;
tiletypes40d tiles;
t_blockflags blockflags;
string plantMatStr = ""; string plantMatStr = "";
set<int> plantIDs; set<int> plantIDs;
set<string> plantNames; set<string> plantNames;
bool deselect = false, exclude = false, treesonly = false, shrubsonly = false; bool deselect = false, exclude = false, treesonly = false, shrubsonly = false;
bool dirty = false;
int count = 0; int count = 0;
for (size_t i = 0; i < parameters.size(); i++) for (size_t i = 0; i < parameters.size(); i++)
{ {
@ -77,16 +55,16 @@ DFhackCExport command_result df_getplants (Core * c, vector <string> & parameter
exclude = true; exclude = true;
else plantNames.insert(parameters[i]); else plantNames.insert(parameters[i]);
} }
c->Suspend();
Materials *mats = c->getMaterials(); CoreSuspender suspend(c);
for (vector<df_plant_type *>::const_iterator it = mats->df_organic->begin(); it != mats->df_organic->end(); it++)
for (int i = 0; i < world->raws.plants.all.size(); i++)
{ {
df_plant_type &plant = **it; df::plant_raw *plant = world->raws.plants.all[i];
if (plantNames.find(plant.ID) != plantNames.end()) if (plantNames.find(plant->id) != plantNames.end())
{ {
plantNames.erase(plant.ID); plantNames.erase(plant->id);
plantIDs.insert(it - mats->df_organic->begin()); plantIDs.insert(i);
} }
} }
if (plantNames.size() > 0) if (plantNames.size() > 0)
@ -95,103 +73,83 @@ DFhackCExport command_result df_getplants (Core * c, vector <string> & parameter
for (set<string>::const_iterator it = plantNames.begin(); it != plantNames.end(); it++) for (set<string>::const_iterator it = plantNames.begin(); it != plantNames.end(); it++)
c->con.printerr(" %s", it->c_str()); c->con.printerr(" %s", it->c_str());
c->con.printerr("\n"); c->con.printerr("\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
if (plantIDs.size() == 0) if (plantIDs.size() == 0)
{ {
c->con.print("Valid plant IDs:\n"); c->con.print("Valid plant IDs:\n");
for (vector<df_plant_type *>::const_iterator it = mats->df_organic->begin(); it != mats->df_organic->end(); it++) for (int i = 0; i < world->raws.plants.all.size(); i++)
{ {
df_plant_type &plant = **it; df::plant_raw *plant = world->raws.plants.all[i];
if (plant.flags.is_set(PLANT_GRASS)) if (plant->flags.is_set(df::plant_raw_flags::GRASS))
continue; continue;
c->con.print("* (%s) %s - %s\n", plant.flags.is_set(PLANT_TREE) ? "tree" : "shrub", plant.ID.c_str(), plant.name.c_str()); c->con.print("* (%s) %s - %s\n", plant->flags.is_set(df::plant_raw_flags::TREE) ? "tree" : "shrub", plant->id.c_str(), plant->name.c_str());
} }
c->Resume();
return CR_OK; return CR_OK;
} }
Maps *maps = c->getMaps(); int count = 0;
for (int i = 0; i < world->map.map_blocks.size(); i++)
// 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++) df::map_block *cur = world->map.map_blocks[i];
bool dirty = false;
for (int j = 0; j < cur->plants.size(); j++)
{ {
for (uint32_t z = 0; z < z_max; z++) const df_plant *plant = (df_plant *)cur->plants[i];
int x = plant->x % 16;
int y = plant->y % 16;
if (plantIDs.find(plant->material) != plantIDs.end())
{ {
if (maps->getBlock(x,y,z)) if (exclude)
{ continue;
dirty = false; }
maps->ReadDesignations(x,y,z, &designations); else
maps->ReadTileTypes(x,y,z, &tiles); {
maps->ReadBlockFlags(x,y,z, blockflags); if (!exclude)
continue;
vector<df_plant *> *plants; }
if (maps->ReadVegetation(x, y, z, plants)) TileShape shape = tileShape(cur->tiletype[x][y]);
{ if (plant->is_shrub && (treesonly || shape != SHRUB_OK))
for (vector<df_plant *>::const_iterator it = plants->begin(); it != plants->end(); it++) continue;
{ if (!plant->is_shrub && (shrubsonly || (shape != TREE_OK && shape != TREE_DEAD)))
const df_plant &plant = **it; continue;
uint32_t tx = plant.x % 16; if (cur->designation[x][y].bits.hidden)
uint32_t ty = plant.y % 16; continue;
if (plantIDs.find(plant.material) != plantIDs.end()) if (deselect && cur->designation[x][y].bits.dig != df::tile_dig_designation::No)
{ {
if (exclude) cur->designation[x][y].bits.dig = df::tile_dig_designation::No;
continue; dirty = true;
} ++count;
else }
{ if (!deselect && cur->designation[x][y].bits.dig != df::tile_dig_designation::Default)
if (!exclude) {
continue; cur->designation[x][y].bits.dig = df::tile_dig_designation::Default;
} dirty = true;
++count;
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;
}
}
} }
} }
if (dirty)
cur->flags.set(df::block_flags::Designated);
} }
c->Resume();
if (count) if (count)
c->con.print("Updated %d plant designations.\n", count); c->con.print("Updated %d plant designations.\n", count);
return CR_OK; return CR_OK;
} }
DFhackCExport const char * plugin_name ( void )
{
return "getplants";
}
DFhackCExport command_result plugin_init ( Core * c, vector <PluginCommand> &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;
}