Merge remote-tracking branch 'quietust/master'

develop
Mike Stewart 2012-01-22 15:31:34 -08:00
commit 0d79fd9b15
28 changed files with 778 additions and 886 deletions

@ -321,7 +321,7 @@ extern DFHACK_EXPORT bool SortBlockEvents(uint32_t x, uint32_t y, uint32_t z,
extern DFHACK_EXPORT bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which ); extern DFHACK_EXPORT bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which );
/// read all plants in this block /// read all plants in this block
extern DFHACK_EXPORT bool ReadVegetation(uint32_t x, uint32_t y, uint32_t z, std::vector<df_plant *>*& plants); extern DFHACK_EXPORT bool ReadVegetation(uint32_t x, uint32_t y, uint32_t z, std::vector<df::plant *>*& plants);
} }
} }

@ -253,25 +253,25 @@ namespace DFHack
std::vector<t_colormodifier> ColorModifier; std::vector<t_colormodifier> ColorModifier;
std::vector<t_bodypart> bodypart; std::vector<t_bodypart> bodypart;
t_attrib strength; int32_t strength[7];
t_attrib agility; int32_t agility[7];
t_attrib toughness; int32_t toughness[7];
t_attrib endurance; int32_t endurance[7];
t_attrib recuperation; int32_t recuperation[7];
t_attrib disease_resistance; int32_t disease_resistance[7];
t_attrib analytical_ability; int32_t analytical_ability[7];
t_attrib focus; int32_t focus[7];
t_attrib willpower; int32_t willpower[7];
t_attrib creativity; int32_t creativity[7];
t_attrib intuition; int32_t intuition[7];
t_attrib patience; int32_t patience[7];
t_attrib memory; int32_t memory[7];
t_attrib linguistic_ability; int32_t linguistic_ability[7];
t_attrib spatial_sense; int32_t spatial_sense[7];
t_attrib musicality; int32_t musicality[7];
t_attrib kinesthetic_sense; int32_t kinesthetic_sense[7];
t_attrib empathy; int32_t empathy[7];
t_attrib social_awareness; int32_t social_awareness[7];
}; };
/** /**

@ -34,48 +34,13 @@ distribution.
#include "Module.h" #include "Module.h"
#include "Types.h" #include "Types.h"
#include "DataDefs.h" #include "DataDefs.h"
#include "df/language_name.h" #include "df/plant.h"
namespace DFHack namespace DFHack
{ {
/** /**
* \ingroup grp_vegetation * \ingroup grp_vegetation
*/ */
const uint32_t sapling_to_tree_threshold = 0x1D880; const uint32_t sapling_to_tree_threshold = 0x1D880;
/**
* \ingroup grp_vegetation
*/
#pragma pack(push, 2)
struct df_plant
{
df::language_name name;
union
{
uint16_t type;
struct
{
bool watery : 1;
bool is_shrub : 1;
};
};
uint16_t material; // +0x3E
uint16_t x; // +0x40
uint16_t y; // +0x42
uint16_t z; // +0x44
uint16_t padding; // +0x46
uint32_t grow_counter; // +0x48
uint16_t temperature_1; // +0x4C
uint16_t temperature_2; // +0x4E - maybe fraction?
uint32_t is_burning; // 0x50: yes, just one flag
uint32_t hitpoints; // 0x54
/**
* 0x58 - the updates are staggered into 9? groups. this seems to be what differentiates the plants.
*/
uint16_t update_order;
uint16_t padding2;
// a vector is here
// some more temperature stuff after that
};
#pragma pack(pop)
/** /**
* The Vegetation module * The Vegetation module
* \ingroup grp_vegetation * \ingroup grp_vegetation
@ -87,7 +52,6 @@ namespace DFHack
Vegetation(); Vegetation();
~Vegetation(); ~Vegetation();
bool Finish(){return true;}; bool Finish(){return true;};
std::vector <df_plant *> *all_plants;
}; };
} }
#endif #endif

@ -592,12 +592,12 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
return true; return true;
} }
bool Maps::ReadVegetation(uint32_t x, uint32_t y, uint32_t z, std::vector<df_plant *>*& plants) bool Maps::ReadVegetation(uint32_t x, uint32_t y, uint32_t z, std::vector<df::plant *>*& plants)
{ {
df::map_block *block = getBlock(x,y,z); df::map_block *block = getBlock(x,y,z);
if (!block) if (!block)
return false; return false;
plants = (vector<DFHack::df_plant *> *)&block->plants; plants = &block->plants;
return true; return true;
} }

@ -60,9 +60,14 @@ using namespace std;
#include "df/descriptor_pattern.h" #include "df/descriptor_pattern.h"
#include "df/descriptor_shape.h" #include "df/descriptor_shape.h"
#include "df/physical_attribute_type.h"
#include "df/mental_attribute_type.h"
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using df::global::world; using df::global::world;
using df::global::ui;
bool MaterialInfo::decode(df::item *item) bool MaterialInfo::decode(df::item *item)
{ {
@ -90,7 +95,7 @@ bool MaterialInfo::decode(int16_t type, int32_t index)
inorganic = NULL; plant = NULL; creature = NULL; inorganic = NULL; plant = NULL; creature = NULL;
figure = NULL; figure = NULL;
df::world_raws &raws = df::global::world->raws; df::world_raws &raws = world->raws;
if (type < 0 || type >= sizeof(raws.mat_table.builtin)/sizeof(void*)) if (type < 0 || type >= sizeof(raws.mat_table.builtin)/sizeof(void*))
return false; return false;
@ -191,7 +196,7 @@ bool MaterialInfo::findBuiltin(const std::string &token)
return true; return true;
} }
df::world_raws &raws = df::global::world->raws; df::world_raws &raws = world->raws;
for (int i = 1; i < NUM_BUILTIN; i++) for (int i = 1; i < NUM_BUILTIN; i++)
if (raws.mat_table.builtin[i]->id == token) if (raws.mat_table.builtin[i]->id == token)
return decode(i, -1); return decode(i, -1);
@ -208,7 +213,7 @@ bool MaterialInfo::findInorganic(const std::string &token)
return true; return true;
} }
df::world_raws &raws = df::global::world->raws; df::world_raws &raws = world->raws;
for (unsigned i = 0; i < raws.inorganics.size(); i++) for (unsigned i = 0; i < raws.inorganics.size(); i++)
{ {
df::inorganic_raw *p = raws.inorganics[i]; df::inorganic_raw *p = raws.inorganics[i];
@ -222,7 +227,7 @@ bool MaterialInfo::findPlant(const std::string &token, const std::string &subtok
{ {
if (token.empty()) if (token.empty())
return decode(-1); return decode(-1);
df::world_raws &raws = df::global::world->raws; df::world_raws &raws = world->raws;
for (unsigned i = 0; i < raws.plants.all.size(); i++) for (unsigned i = 0; i < raws.plants.all.size(); i++)
{ {
df::plant_raw *p = raws.plants.all[i]; df::plant_raw *p = raws.plants.all[i];
@ -246,7 +251,7 @@ bool MaterialInfo::findCreature(const std::string &token, const std::string &sub
{ {
if (token.empty() || subtoken.empty()) if (token.empty() || subtoken.empty())
return decode(-1); return decode(-1);
df::world_raws &raws = df::global::world->raws; df::world_raws &raws = world->raws;
for (unsigned i = 0; i < raws.creatures.all.size(); i++) for (unsigned i = 0; i < raws.creatures.all.size(); i++)
{ {
df::creature_raw *p = raws.creatures.all[i]; df::creature_raw *p = raws.creatures.all[i];
@ -388,7 +393,7 @@ void MaterialInfo::getMatchBits(df::job_item_flags1 &ok, df::job_item_flags1 &ma
ok.whole = mask.whole = 0; ok.whole = mask.whole = 0;
if (!isValid()) return; if (!isValid()) return;
#define MAT_FLAG(name) material->flags.is_set(df::enums::material_flags::name) #define MAT_FLAG(name) material->flags.is_set(material_flags::name)
#define FLAG(field, name) (field && field->flags.is_set(name)) #define FLAG(field, name) (field && field->flags.is_set(name))
#define TEST(bit, check) \ #define TEST(bit, check) \
mask.bits.bit = true; ok.bits.bit = !!(check); mask.bits.bit = true; ok.bits.bit = !!(check);
@ -433,8 +438,8 @@ void MaterialInfo::getMatchBits(df::job_item_flags2 &ok, df::job_item_flags2 &ma
TEST(fire_safe, material->heat.melting_point > 11000); TEST(fire_safe, material->heat.melting_point > 11000);
TEST(magma_safe, material->heat.melting_point > 12000); TEST(magma_safe, material->heat.melting_point > 12000);
TEST(deep_material, FLAG(inorganic, df::enums::inorganic_flags::DEEP_ANY)); TEST(deep_material, FLAG(inorganic, inorganic_flags::DEEP_ANY));
TEST(non_economic, inorganic && !(df::global::ui && df::global::ui->economic_stone[index])); TEST(non_economic, inorganic && !(ui && ui->economic_stone[index]));
TEST(plant, plant); TEST(plant, plant);
TEST(silk, MAT_FLAG(SILK)); TEST(silk, MAT_FLAG(SILK));
@ -646,10 +651,8 @@ bool Materials::ReadCreatureTypes (void)
bool Materials::ReadOthers(void) bool Materials::ReadOthers(void)
{ {
uint32_t size = df::enums::builtin_mats::_last_item_of_builtin_mats + 1;
other.clear(); other.clear();
other.reserve(size); FOR_ENUM_ITEMS(builtin_mats, i)
for (uint32_t i = 0; i < size;i++)
{ {
t_matglossOther mat; t_matglossOther mat;
mat.id = world->raws.mat_table.builtin[i]->id; mat.id = world->raws.mat_table.builtin[i]->id;
@ -747,48 +750,28 @@ bool Materials::ReadCreatureTypesEx (void)
caste.bodypart.push_back(part); caste.bodypart.push_back(part);
} }
t_attrib *phys[] = { for (int32_t k = 0; k < 7; k++)
&caste.strength, {
&caste.agility, caste.strength[k] = ca->attributes.phys_att_range[df::physical_attribute_type::STRENGTH][k];
&caste.toughness, caste.agility[k] = ca->attributes.phys_att_range[df::physical_attribute_type::AGILITY][k];
&caste.endurance, caste.toughness[k] = ca->attributes.phys_att_range[df::physical_attribute_type::TOUGHNESS][k];
&caste.recuperation, caste.endurance[k] = ca->attributes.phys_att_range[df::physical_attribute_type::ENDURANCE][k];
&caste.disease_resistance caste.recuperation[k] = ca->attributes.phys_att_range[df::physical_attribute_type::RECUPERATION][k];
}; caste.disease_resistance[k] = ca->attributes.phys_att_range[df::physical_attribute_type::DISEASE_RESISTANCE][k];
for (uint32_t k = 0; k < 6; k++)
{ caste.analytical_ability[k] = ca->attributes.phys_att_range[df::mental_attribute_type::ANALYTICAL_ABILITY][k];
phys[k]->level = ca->attributes.phys_att_range[k][0]; caste.focus[k] = ca->attributes.phys_att_range[df::mental_attribute_type::FOCUS][k];
phys[k]->field_4 = ca->attributes.phys_att_range[k][1]; caste.willpower[k] = ca->attributes.phys_att_range[df::mental_attribute_type::WILLPOWER][k];
phys[k]->field_8 = ca->attributes.phys_att_range[k][2]; caste.creativity[k] = ca->attributes.phys_att_range[df::mental_attribute_type::CREATIVITY][k];
phys[k]->field_C = ca->attributes.phys_att_range[k][3]; caste.intuition[k] = ca->attributes.phys_att_range[df::mental_attribute_type::INTUITION][k];
phys[k]->leveldiff = ca->attributes.phys_att_range[k][4]; caste.patience[k] = ca->attributes.phys_att_range[df::mental_attribute_type::PATIENCE][k];
phys[k]->field_14 = ca->attributes.phys_att_range[k][5]; caste.memory[k] = ca->attributes.phys_att_range[df::mental_attribute_type::MEMORY][k];
phys[k]->field_18 = ca->attributes.phys_att_range[k][6]; caste.linguistic_ability[k] = ca->attributes.phys_att_range[df::mental_attribute_type::LINGUISTIC_ABILITY][k];
} caste.spatial_sense[k] = ca->attributes.phys_att_range[df::mental_attribute_type::SPATIAL_SENSE][k];
t_attrib *ment[] = { caste.musicality[k] = ca->attributes.phys_att_range[df::mental_attribute_type::MUSICALITY][k];
&caste.analytical_ability, caste.kinesthetic_sense[k] = ca->attributes.phys_att_range[df::mental_attribute_type::KINESTHETIC_SENSE][k];
&caste.focus, caste.empathy[k] = ca->attributes.phys_att_range[df::mental_attribute_type::EMPATHY][k];
&caste.willpower, caste.social_awareness[k] = ca->attributes.phys_att_range[df::mental_attribute_type::SOCIAL_AWARENESS][k];
&caste.creativity,
&caste.intuition,
&caste.patience,
&caste.memory,
&caste.linguistic_ability,
&caste.spatial_sense,
&caste.musicality,
&caste.kinesthetic_sense,
&caste.empathy,
&caste.social_awareness
};
for (uint32_t k = 0; k < 13; k++)
{
ment[k]->level = ca->attributes.ment_att_range[k][0];
ment[k]->field_4 = ca->attributes.ment_att_range[k][1];
ment[k]->field_8 = ca->attributes.ment_att_range[k][2];
ment[k]->field_C = ca->attributes.ment_att_range[k][3];
ment[k]->leveldiff = ca->attributes.ment_att_range[k][4];
ment[k]->field_14 = ca->attributes.ment_att_range[k][5];
ment[k]->field_18 = ca->attributes.ment_att_range[k][6];
} }
mat.castes.push_back(caste); mat.castes.push_back(caste);
} }

@ -46,16 +46,6 @@ Module* DFHack::createVegetation()
Vegetation::Vegetation() Vegetation::Vegetation()
{ {
Core & c = Core::getInstance();
try
{
OffsetGroup * OG_Veg = c.vinfo->getGroup("Vegetation");
all_plants = (vector<df_plant *> *) OG_Veg->getAddress ("vector");
}
catch(exception &)
{
all_plants = 0;
}
} }
Vegetation::~Vegetation() Vegetation::~Vegetation()

@ -26,6 +26,8 @@ using namespace std;
#include "df/general_ref.h" #include "df/general_ref.h"
using namespace DFHack; using namespace DFHack;
using namespace df::enums;
using MapExtras::Block; using MapExtras::Block;
using MapExtras::MapCache; using MapExtras::MapCache;
using df::global::world; using df::global::world;
@ -291,9 +293,9 @@ DFhackCExport command_result df_autodump_destroy_item(Core * c, vector <string>
return CR_FAILURE; return CR_FAILURE;
// Allow undoing the destroy // Allow undoing the destroy
if (df::global::world->frame_counter != last_frame) if (world->frame_counter != last_frame)
{ {
last_frame = df::global::world->frame_counter; last_frame = world->frame_counter;
pending_destroy.clear(); pending_destroy.clear();
} }
@ -327,7 +329,7 @@ DFhackCExport command_result df_autodump_destroy_item(Core * c, vector <string>
for (unsigned i = 0; i < item->itemrefs.size(); i++) for (unsigned i = 0; i < item->itemrefs.size(); i++)
{ {
df::general_ref *ref = item->itemrefs[i]; df::general_ref *ref = item->itemrefs[i];
if (ref->getType() == df::general_ref_type::UNIT_HOLDER) if (ref->getType() == general_ref_type::UNIT_HOLDER)
{ {
c->con.printerr("Choosing not to destroy items in unit inventory.\n"); c->con.printerr("Choosing not to destroy items in unit inventory.\n");
return CR_FAILURE; return CR_FAILURE;

@ -17,6 +17,7 @@ using std::vector;
using std::string; using std::string;
using namespace DFHack; using namespace DFHack;
using namespace DFHack::Simple; using namespace DFHack::Simple;
using namespace df::enums;
using df::global::world; using df::global::world;
using df::global::cursor; using df::global::cursor;
@ -40,20 +41,20 @@ command_result cleanmap (Core * c, bool snow, bool mud)
for (int j = 0; j < block->block_events.size(); j++) for (int j = 0; j < block->block_events.size(); j++)
{ {
df::block_square_event *evt = block->block_events[j]; df::block_square_event *evt = block->block_events[j];
if (evt->getType() != df::block_square_event_type::material_spatter) if (evt->getType() != block_square_event_type::material_spatter)
continue; continue;
// type verified - recast to subclass // type verified - recast to subclass
df::block_square_event_material_spatterst *spatter = (df::block_square_event_material_spatterst *)evt; df::block_square_event_material_spatterst *spatter = (df::block_square_event_material_spatterst *)evt;
// filter snow // filter snow
if(!snow if(!snow
&& spatter->mat_type == df::builtin_mats::WATER && spatter->mat_type == builtin_mats::WATER
&& spatter->mat_state == df::matter_state::Powder) && spatter->mat_state == matter_state::Powder)
continue; continue;
// filter mud // filter mud
if(!mud if(!mud
&& spatter->mat_type == df::builtin_mats::MUD && spatter->mat_type == builtin_mats::MUD
&& spatter->mat_state == df::matter_state::Solid) && spatter->mat_state == matter_state::Solid)
continue; continue;
delete evt; delete evt;
@ -119,7 +120,7 @@ DFhackCExport command_result spotclean (Core * c, vector <string> & parameters)
if (cursor->x == -30000) if (cursor->x == -30000)
{ {
c->con.printerr("The cursor is not active.\n"); c->con.printerr("The cursor is not active.\n");
return CR_FAILURE; return CR_WRONG_USAGE;
} }
df::map_block *block = Maps::getBlockAbs(cursor->x, cursor->y, cursor->z); df::map_block *block = Maps::getBlockAbs(cursor->x, cursor->y, cursor->z);
if (block == NULL) if (block == NULL)
@ -131,7 +132,7 @@ DFhackCExport command_result spotclean (Core * c, vector <string> & parameters)
for (int i = 0; i < block->block_events.size(); i++) for (int i = 0; i < block->block_events.size(); i++)
{ {
df::block_square_event *evt = block->block_events[i]; df::block_square_event *evt = block->block_events[i];
if (evt->getType() != df::block_square_event_type::material_spatter) if (evt->getType() != block_square_event_type::material_spatter)
continue; continue;
// type verified - recast to subclass // type verified - recast to subclass
df::block_square_event_material_spatterst *spatter = (df::block_square_event_material_spatterst *)evt; df::block_square_event_material_spatterst *spatter = (df::block_square_event_material_spatterst *)evt;
@ -189,14 +190,13 @@ DFhackCExport command_result clean (Core * c, vector <string> & parameters)
); );
return CR_OK; return CR_OK;
} }
c->Suspend(); CoreSuspender suspend(c);
if(map) if(map)
cleanmap(c,snow,mud); cleanmap(c,snow,mud);
if(units) if(units)
cleanunits(c); cleanunits(c);
if(items) if(items)
cleanitems(c); cleanitems(c);
c->Resume();
return CR_OK; return CR_OK;
} }

@ -18,11 +18,13 @@ using namespace std;
#include "modules/Units.h" #include "modules/Units.h"
#include "modules/Materials.h" #include "modules/Materials.h"
#include "modules/Translation.h" #include "modules/Translation.h"
using namespace DFHack;
using namespace DFHack::Simple;
#include "DataDefs.h" #include "DataDefs.h"
#include "df/world.h" #include "df/world.h"
using namespace DFHack;
using namespace DFHack::Simple;
using namespace df::enums;
using df::global::world; using df::global::world;
DFhackCExport command_result df_cleanowned (Core * c, vector <string> & parameters); DFhackCExport command_result df_cleanowned (Core * c, vector <string> & parameters);
@ -91,7 +93,9 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
return CR_FAILURE; return CR_FAILURE;
} }
} }
c->Suspend();
CoreSuspender suspend(c);
DFHack::Materials *Materials = c->getMaterials(); DFHack::Materials *Materials = c->getMaterials();
DFHack::Units *Creatures = c->getUnits(); DFHack::Units *Creatures = c->getUnits();
DFHack::Translation *Tran = c->getTranslation(); DFHack::Translation *Tran = c->getTranslation();
@ -132,13 +136,13 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
else if (item->flags.bits.on_ground) else if (item->flags.bits.on_ground)
{ {
int32_t type = item->getType(); int32_t type = item->getType();
if(type == df::item_type::MEAT || if(type == item_type::MEAT ||
type == df::item_type::FISH || type == item_type::FISH ||
type == df::item_type::VERMIN || type == item_type::VERMIN ||
type == df::item_type::PET || type == item_type::PET ||
type == df::item_type::PLANT || type == item_type::PLANT ||
type == df::item_type::CHEESE || type == item_type::CHEESE ||
type == df::item_type::FOOD type == item_type::FOOD
) )
{ {
confiscate = true; confiscate = true;
@ -207,6 +211,5 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
c->con.print("\n"); c->con.print("\n");
} }
} }
c->Resume();
return CR_OK; return CR_OK;
} }

@ -66,10 +66,9 @@ DFhackCExport command_result colonies (Core * c, vector <string> & parameters)
if (destroy && convert) if (destroy && convert)
{ {
c->con.printerr("Kill or make bees? DECIDE!\n"); c->con.printerr("Kill or make bees? DECIDE!\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
c->Suspend(); CoreSuspender suspend(c);
Materials * materials = c->getMaterials(); Materials * materials = c->getMaterials();
@ -84,7 +83,6 @@ DFhackCExport command_result colonies (Core * c, vector <string> & parameters)
materials->Finish(); materials->Finish();
c->Resume();
return CR_OK; return CR_OK;
} }
@ -110,11 +108,13 @@ void convertColonies(Materials *Materials)
{ {
int bee_idx = -1; int bee_idx = -1;
for (size_t i = 0; i < Materials->raceEx.size(); i++) for (size_t i = 0; i < Materials->raceEx.size(); i++)
{
if (Materials->raceEx[i].id == "HONEY_BEE") if (Materials->raceEx[i].id == "HONEY_BEE")
{ {
bee_idx = i; bee_idx = i;
break; break;
} }
}
if (bee_idx == -1) if (bee_idx == -1)
{ {

@ -12,10 +12,10 @@
using std::vector; using std::vector;
using std::string; using std::string;
using namespace DFHack; using namespace DFHack;
using namespace DFHack::Simple;
using namespace df::enums;
using df::global::world; using df::global::world;
using namespace DFHack;
using namespace DFHack::Simple;
DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters) DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
{ {
@ -48,7 +48,7 @@ DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
{ {
int16_t oldT = block->tiletype[x][y]; int16_t oldT = block->tiletype[x][y];
if ((tileShape(oldT) == RAMP) && if ((tileShape(oldT) == RAMP) &&
(block->designation[x][y].bits.dig == df::tile_dig_designation::Default)) (block->designation[x][y].bits.dig == tile_dig_designation::Default))
{ {
// Current tile is a ramp. // Current tile is a ramp.
// Set current tile, as accurately as can be expected // Set current tile, as accurately as can be expected
@ -59,7 +59,7 @@ DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
continue; continue;
// Set new tile type, clear designation // Set new tile type, clear designation
block->tiletype[x][y] = newT; block->tiletype[x][y] = newT;
block->designation[x][y].bits.dig = df::tile_dig_designation::No; block->designation[x][y].bits.dig = tile_dig_designation::No;
// Check the tile above this one, in case a downward slope needs to be removed. // Check the tile above this one, in case a downward slope needs to be removed.
if ((above) && (tileShape(above->tiletype[x][y]) == RAMP_TOP)) if ((above) && (tileShape(above->tiletype[x][y]) == RAMP_TOP))

@ -13,6 +13,7 @@
using std::string; using std::string;
using std::vector; using std::vector;
using namespace DFHack; using namespace DFHack;
using namespace df::enums;
using df::global::world; using df::global::world;
@ -27,7 +28,7 @@ DFhackCExport command_result df_drybuckets (Core * c, vector <string> & paramete
for (int i = 0; i < world->items.all.size(); i++) for (int i = 0; i < world->items.all.size(); i++)
{ {
df::item *item = world->items.all[i]; df::item *item = world->items.all[i];
if ((item->getType() == df::item_type::LIQUID_MISC) && (item->getMaterial() == df::builtin_mats::WATER)) if ((item->getType() == item_type::LIQUID_MISC) && (item->getMaterial() == builtin_mats::WATER))
{ {
item->flags.bits.garbage_colect = 1; item->flags.bits.garbage_colect = 1;
dried_total++; dried_total++;

@ -15,6 +15,7 @@
using std::stack; using std::stack;
using MapExtras::MapCache; using MapExtras::MapCache;
using namespace DFHack; using namespace DFHack;
using namespace df::enums;
//Function pointer type for whole-map tile checks. //Function pointer type for whole-map tile checks.
typedef void (*checkTile)(DFHack::DFCoord, MapExtras::MapCache &); typedef void (*checkTile)(DFHack::DFCoord, MapExtras::MapCache &);
@ -57,8 +58,8 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
//Maximum map size. //Maximum map size.
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
//Source and target traffic types. //Source and target traffic types.
df::tile_traffic source = df::tile_traffic::Normal; df::tile_traffic source = tile_traffic::Normal;
df::tile_traffic target = df::tile_traffic::Normal; df::tile_traffic target = tile_traffic::Normal;
//Option flags //Option flags
bool updown = false; bool updown = false;
bool checkpit = true; bool checkpit = true;
@ -89,13 +90,13 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
switch (toupper(params[i][0])) switch (toupper(params[i][0]))
{ {
case 'H': case 'H':
target = df::tile_traffic::High; break; target = tile_traffic::High; break;
case 'N': case 'N':
target = df::tile_traffic::Normal; break; target = tile_traffic::Normal; break;
case 'L': case 'L':
target = df::tile_traffic::Low; break; target = tile_traffic::Low; break;
case 'R': case 'R':
target = df::tile_traffic::Restricted; break; target = tile_traffic::Restricted; break;
case 'X': case 'X':
updown = true; break; updown = true; break;
case 'B': case 'B':
@ -106,13 +107,12 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
} }
//Initialization. //Initialization.
c->Suspend(); CoreSuspender suspend(c);
DFHack::Gui * Gui = c->getGui(); DFHack::Gui * Gui = c->getGui();
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -124,7 +124,6 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
while(cx == -30000) while(cx == -30000)
{ {
c->con.printerr("Cursor is not active.\n"); c->con.printerr("Cursor is not active.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -142,28 +141,24 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
if(source == target) if(source == target)
{ {
c->con.printerr("This tile is already set to the target traffic type.\n"); c->con.printerr("This tile is already set to the target traffic type.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
if(DFHack::isWallTerrain(tt)) if(DFHack::isWallTerrain(tt))
{ {
c->con.printerr("This tile is a wall. Please select a passable tile.\n"); c->con.printerr("This tile is a wall. Please select a passable tile.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
if(checkpit && DFHack::isOpenTerrain(tt)) if(checkpit && DFHack::isOpenTerrain(tt))
{ {
c->con.printerr("This tile is a hole. Please select a passable tile.\n"); c->con.printerr("This tile is a hole. Please select a passable tile.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
if(checkbuilding && oc.bits.building) if(checkbuilding && oc.bits.building)
{ {
c->con.printerr("This tile contains a building. Please select an empty tile.\n"); c->con.printerr("This tile contains a building. Please select an empty tile.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -231,7 +226,6 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
} }
MCache.WriteAll(); MCache.WriteAll();
c->Resume();
return CR_OK; return CR_OK;
} }
@ -281,13 +275,12 @@ DFhackCExport command_result setAllMatching(DFHack::Core * c, checkTile checkPro
DFHack::DFCoord minCoord, DFHack::DFCoord maxCoord) DFHack::DFCoord minCoord, DFHack::DFCoord maxCoord)
{ {
//Initialization. //Initialization.
c->Suspend(); CoreSuspender suspend(c);
DFHack::Gui * Gui = c->getGui(); DFHack::Gui * Gui = c->getGui();
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -306,19 +299,16 @@ DFhackCExport command_result setAllMatching(DFHack::Core * c, checkTile checkPro
if (minCoord.x > maxCoord.x) if (minCoord.x > maxCoord.x)
{ {
c->con.printerr("Minimum x coordinate is greater than maximum x coordinate.\n"); c->con.printerr("Minimum x coordinate is greater than maximum x coordinate.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
if (minCoord.y > maxCoord.y) if (minCoord.y > maxCoord.y)
{ {
c->con.printerr("Minimum y coordinate is greater than maximum y coordinate.\n"); c->con.printerr("Minimum y coordinate is greater than maximum y coordinate.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
if (minCoord.z > maxCoord.y) if (minCoord.z > maxCoord.y)
{ {
c->con.printerr("Minimum z coordinate is greater than maximum z coordinate.\n"); c->con.printerr("Minimum z coordinate is greater than maximum z coordinate.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -341,7 +331,6 @@ DFhackCExport command_result setAllMatching(DFHack::Core * c, checkTile checkPro
MCache.WriteAll(); MCache.WriteAll();
c->con.print("Complete!\n"); c->con.print("Complete!\n");
c->Resume();
return CR_OK; return CR_OK;
} }
@ -349,24 +338,24 @@ DFhackCExport command_result setAllMatching(DFHack::Core * c, checkTile checkPro
void allHigh(DFHack::DFCoord coord, MapExtras::MapCache &map) void allHigh(DFHack::DFCoord coord, MapExtras::MapCache &map)
{ {
df::tile_designation des = map.designationAt(coord); df::tile_designation des = map.designationAt(coord);
des.bits.traffic = df::tile_traffic::High; des.bits.traffic = tile_traffic::High;
map.setDesignationAt(coord, des); map.setDesignationAt(coord, des);
} }
void allNormal(DFHack::DFCoord coord, MapExtras::MapCache &map) void allNormal(DFHack::DFCoord coord, MapExtras::MapCache &map)
{ {
df::tile_designation des = map.designationAt(coord); df::tile_designation des = map.designationAt(coord);
des.bits.traffic = df::tile_traffic::Normal; des.bits.traffic = tile_traffic::Normal;
map.setDesignationAt(coord, des); map.setDesignationAt(coord, des);
} }
void allLow(DFHack::DFCoord coord, MapExtras::MapCache &map) void allLow(DFHack::DFCoord coord, MapExtras::MapCache &map)
{ {
df::tile_designation des = map.designationAt(coord); df::tile_designation des = map.designationAt(coord);
des.bits.traffic = df::tile_traffic::Low; des.bits.traffic = tile_traffic::Low;
map.setDesignationAt(coord, des); map.setDesignationAt(coord, des);
} }
void allRestricted(DFHack::DFCoord coord, MapExtras::MapCache &map) void allRestricted(DFHack::DFCoord coord, MapExtras::MapCache &map)
{ {
df::tile_designation des = map.designationAt(coord); df::tile_designation des = map.designationAt(coord);
des.bits.traffic = df::tile_traffic::Restricted; des.bits.traffic = tile_traffic::Restricted;
map.setDesignationAt(coord, des); map.setDesignationAt(coord, des);
} }

@ -15,6 +15,7 @@
using std::string; using std::string;
using std::vector; using std::vector;
using namespace DFHack; using namespace DFHack;
using namespace df::enums;
using df::global::world; using df::global::world;
@ -29,7 +30,7 @@ command_result df_fixwagons (Core *c, vector<string> &parameters)
for (int i = 0; i < world->raws.creatures.all.size(); i++) for (int i = 0; i < world->raws.creatures.all.size(); i++)
{ {
df::creature_raw *cr = world->raws.creatures.all[i]; df::creature_raw *cr = world->raws.creatures.all[i];
if (cr->flags.is_set(df::creature_raw_flags::EQUIPMENT_WAGON) && (wagon_creature == -1)) if (cr->flags.is_set(creature_raw_flags::EQUIPMENT_WAGON) && (wagon_creature == -1))
{ {
wagon = cr; wagon = cr;
wagon_creature = i; wagon_creature = i;
@ -55,7 +56,7 @@ command_result df_fixwagons (Core *c, vector<string> &parameters)
{ {
bool updated = false; bool updated = false;
df::historical_entity *ent = world->entities.all[i]; df::historical_entity *ent = world->entities.all[i];
if (!ent->entity_raw->flags.is_set(df::entity_raw_flags::COMMON_DOMESTIC_PULL)) if (!ent->entity_raw->flags.is_set(entity_raw_flags::COMMON_DOMESTIC_PULL))
continue; continue;
if (ent->resources.animals.wagon_races.size() == 0) if (ent->resources.animals.wagon_races.size() == 0)
{ {

@ -13,6 +13,7 @@
using std::string; using std::string;
using std::vector; using std::vector;
using namespace DFHack; using namespace DFHack;
using namespace df::enums;
using df::global::world; using df::global::world;
@ -26,11 +27,11 @@ DFhackCExport command_result df_flows (Core * c, vector <string> & parameters)
for (int i = 0; i < world->map.map_blocks.size(); i++) for (int i = 0; i < world->map.map_blocks.size(); i++)
{ {
df::map_block *cur = world->map.map_blocks[i]; df::map_block *cur = world->map.map_blocks[i];
if (cur->flags.is_set(df::block_flags::UpdateLiquid)) if (cur->flags.is_set(block_flags::UpdateLiquid))
flow1++; flow1++;
if (cur->flags.is_set(df::block_flags::UpdateLiquidTwice)) if (cur->flags.is_set(block_flags::UpdateLiquidTwice))
flow2++; flow2++;
if (cur->flags.is_set(df::block_flags::UpdateLiquid) && cur->flags.is_set(df::block_flags::UpdateLiquidTwice)) if (cur->flags.is_set(block_flags::UpdateLiquid) && cur->flags.is_set(block_flags::UpdateLiquidTwice))
flowboth++; flowboth++;
for (int x = 0; x < 16; x++) for (int x = 0; x < 16; x++)
{ {
@ -39,9 +40,9 @@ DFhackCExport command_result df_flows (Core * c, vector <string> & parameters)
// only count tiles with actual liquid in them // only count tiles with actual liquid in them
if (cur->designation[x][y].bits.flow_size == 0) if (cur->designation[x][y].bits.flow_size == 0)
continue; continue;
if (cur->designation[x][y].bits.liquid_type == df::tile_liquid::Magma) if (cur->designation[x][y].bits.liquid_type == tile_liquid::Magma)
magma++; magma++;
if (cur->designation[x][y].bits.liquid_type == df::tile_liquid::Water) if (cur->designation[x][y].bits.liquid_type == tile_liquid::Water)
water++; water++;
} }
} }

@ -1,4 +1,4 @@
// Designate all matching plants for gathering/cutting // (un)designate matching plants for gathering/cutting
#include "Core.h" #include "Core.h"
#include "Console.h" #include "Console.h"
@ -19,6 +19,7 @@ using std::string;
using std::vector; using std::vector;
using std::set; using std::set;
using namespace DFHack; using namespace DFHack;
using namespace df::enums;
using df::global::world; using df::global::world;
@ -34,7 +35,7 @@ DFhackCExport command_result df_getplants (Core * c, vector <string> & parameter
{ {
if(parameters[i] == "help" || parameters[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" c->con.print("Specify the types of trees to cut down and/or shrubs to gather by their plant IDs, separated by spaces.\n"
"Options:\n" "Options:\n"
"\t-t - Select trees only (exclude shrubs)\n" "\t-t - Select trees only (exclude shrubs)\n"
"\t-s - Select shrubs only (exclude trees)\n" "\t-s - Select shrubs only (exclude trees)\n"
@ -43,7 +44,7 @@ DFhackCExport command_result df_getplants (Core * c, vector <string> & parameter
"Specifying both -t and -s will have no effect.\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" "If no plant IDs are specified, all valid plant IDs will be listed.\n"
); );
return CR_OK; return CR_WRONG_USAGE;
} }
else if(parameters[i] == "-t") else if(parameters[i] == "-t")
treesonly = true; treesonly = true;
@ -53,7 +54,13 @@ DFhackCExport command_result df_getplants (Core * c, vector <string> & parameter
deselect = true; deselect = true;
else if(parameters[i] == "-x") else if(parameters[i] == "-x")
exclude = true; exclude = true;
else plantNames.insert(parameters[i]); else
plantNames.insert(parameters[i]);
}
if (treesonly && shrubsonly)
{
c->con.printerr("Cannot specify both -t and -s at the same time!\n");
return CR_WRONG_USAGE;
} }
CoreSuspender suspend(c); CoreSuspender suspend(c);
@ -82,9 +89,9 @@ DFhackCExport command_result df_getplants (Core * c, vector <string> & parameter
for (int i = 0; i < world->raws.plants.all.size(); i++) for (int i = 0; i < world->raws.plants.all.size(); i++)
{ {
df::plant_raw *plant = world->raws.plants.all[i]; df::plant_raw *plant = world->raws.plants.all[i];
if (plant->flags.is_set(df::plant_raw_flags::GRASS)) if (plant->flags.is_set(plant_raw_flags::GRASS))
continue; continue;
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->con.print("* (%s) %s - %s\n", plant->flags.is_set(plant_raw_flags::TREE) ? "tree" : "shrub", plant->id.c_str(), plant->name.c_str());
} }
return CR_OK; return CR_OK;
} }
@ -96,9 +103,9 @@ DFhackCExport command_result df_getplants (Core * c, vector <string> & parameter
bool dirty = false; bool dirty = false;
for (int j = 0; j < cur->plants.size(); j++) for (int j = 0; j < cur->plants.size(); j++)
{ {
const df_plant *plant = (df_plant *)cur->plants[i]; const df::plant *plant = cur->plants[i];
int x = plant->x % 16; int x = plant->pos.x % 16;
int y = plant->y % 16; int y = plant->pos.y % 16;
if (plantIDs.find(plant->material) != plantIDs.end()) if (plantIDs.find(plant->material) != plantIDs.end())
{ {
if (exclude) if (exclude)
@ -110,27 +117,27 @@ DFhackCExport command_result df_getplants (Core * c, vector <string> & parameter
continue; continue;
} }
TileShape shape = tileShape(cur->tiletype[x][y]); TileShape shape = tileShape(cur->tiletype[x][y]);
if (plant->is_shrub && (treesonly || shape != SHRUB_OK)) if (plant->flags.bits.is_shrub && (treesonly || shape != SHRUB_OK))
continue; continue;
if (!plant->is_shrub && (shrubsonly || (shape != TREE_OK && shape != TREE_DEAD))) if (!plant->flags.bits.is_shrub && (shrubsonly || (shape != TREE_OK && shape != TREE_DEAD)))
continue; continue;
if (cur->designation[x][y].bits.hidden) if (cur->designation[x][y].bits.hidden)
continue; continue;
if (deselect && cur->designation[x][y].bits.dig != df::tile_dig_designation::No) if (deselect && cur->designation[x][y].bits.dig == tile_dig_designation::Default)
{ {
cur->designation[x][y].bits.dig = df::tile_dig_designation::No; cur->designation[x][y].bits.dig = tile_dig_designation::No;
dirty = true; dirty = true;
++count; ++count;
} }
if (!deselect && cur->designation[x][y].bits.dig != df::tile_dig_designation::Default) if (!deselect && cur->designation[x][y].bits.dig == tile_dig_designation::No)
{ {
cur->designation[x][y].bits.dig = df::tile_dig_designation::Default; cur->designation[x][y].bits.dig = tile_dig_designation::Default;
dirty = true; dirty = true;
++count; ++count;
} }
} }
if (dirty) if (dirty)
cur->flags.set(df::block_flags::Designated); cur->flags.set(block_flags::Designated);
} }
if (count) if (count)
c->con.print("Updated %d plant designations.\n", count); c->con.print("Updated %d plant designations.\n", count);

@ -43,7 +43,7 @@ DFhackCExport command_result plugin_shutdown ( Core * c )
DFhackCExport command_result twaterlvl(Core * c, vector <string> & parameters) DFhackCExport command_result twaterlvl(Core * c, vector <string> & parameters)
{ {
// HOTKEY COMMAND: CORE ALREADY SUSPENDED // HOTKEY COMMAND: CORE ALREADY SUSPENDED
df::global::d_init->flags1.toggle(d_init_flags1::SHOW_FLOW_AMOUNTS); d_init->flags1.toggle(d_init_flags1::SHOW_FLOW_AMOUNTS);
c->con << "Toggled the display of water/magma depth." << endl; c->con << "Toggled the display of water/magma depth." << endl;
return CR_OK; return CR_OK;
} }

@ -20,8 +20,8 @@ using std::set;
#include "modules/MapCache.h" #include "modules/MapCache.h"
using namespace MapExtras; using namespace MapExtras;
using namespace DFHack; using namespace DFHack;
using namespace df::enums;
typedef vector <DFHack::DFCoord> coord_vec; typedef vector <df::coord> coord_vec;
class Brush class Brush
{ {
@ -358,7 +358,7 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
amount = 7; amount = 7;
else if(command.empty()) else if(command.empty())
{ {
c->Suspend(); CoreSuspender suspend(c);
Maps::getSize(x_max,y_max,z_max); Maps::getSize(x_max,y_max,z_max);
Position = c->getGui(); Position = c->getGui();
do do
@ -409,7 +409,7 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
mcache.setTiletypeAt(*iter, 90); mcache.setTiletypeAt(*iter, 90);
df::tile_designation a = mcache.designationAt(*iter); df::tile_designation a = mcache.designationAt(*iter);
a.bits.liquid_type = df::tile_liquid::Water; a.bits.liquid_type = tile_liquid::Water;
a.bits.liquid_static = false; a.bits.liquid_static = false;
a.bits.flow_size = 7; a.bits.flow_size = 7;
mcache.setTemp1At(*iter,10015); mcache.setTemp1At(*iter,10015);
@ -478,13 +478,13 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
} }
if(amount != 0 && mode == "magma") if(amount != 0 && mode == "magma")
{ {
des.bits.liquid_type = df::tile_liquid::Magma; des.bits.liquid_type = tile_liquid::Magma;
mcache.setTemp1At(current,12000); mcache.setTemp1At(current,12000);
mcache.setTemp2At(current,12000); mcache.setTemp2At(current,12000);
} }
else if(amount != 0 && mode == "water") else if(amount != 0 && mode == "water")
{ {
des.bits.liquid_type = df::tile_liquid::Water; des.bits.liquid_type = tile_liquid::Water;
mcache.setTemp1At(current,10015); mcache.setTemp1At(current,10015);
mcache.setTemp2At(current,10015); mcache.setTemp2At(current,10015);
} }
@ -528,7 +528,6 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
else else
c->con << "Something failed horribly! RUN!" << endl; c->con << "Something failed horribly! RUN!" << endl;
} while (0); } while (0);
c->Resume();
} }
else else
{ {

@ -18,6 +18,7 @@
using std::vector; using std::vector;
using std::string; using std::string;
using namespace DFHack; using namespace DFHack;
using df::global::world;
DFhackCExport command_result df_grow (Core * c, vector <string> & parameters); DFhackCExport command_result df_grow (Core * c, vector <string> & parameters);
DFhackCExport command_result df_immolate (Core * c, vector <string> & parameters); DFhackCExport command_result df_immolate (Core * c, vector <string> & parameters);
@ -98,30 +99,23 @@ static command_result immolations (Core * c, do_what what, bool shrubs, bool tre
); );
return CR_OK; return CR_OK;
} }
c->Suspend(); CoreSuspender suspend(c);
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
DFHack::Gui * Gui = c->getGui(); DFHack::Gui * Gui = c->getGui();
uint32_t x_max, y_max, z_max; uint32_t x_max, y_max, z_max;
Maps::getSize(x_max, y_max, z_max); Maps::getSize(x_max, y_max, z_max);
MapExtras::MapCache map; MapExtras::MapCache map;
DFHack::Vegetation *veg = c->getVegetation();
if (!veg->all_plants)
{
std::cerr << "Unable to read vegetation!" << std::endl;
return CR_FAILURE;
}
if(shrubs || trees) if(shrubs || trees)
{ {
int destroyed = 0; int destroyed = 0;
for(size_t i = 0 ; i < veg->all_plants->size(); i++) for(size_t i = 0 ; i < world->plants.all.size(); i++)
{ {
DFHack::df_plant *p = veg->all_plants->at(i); df::plant *p = world->plants.all[i];
if(shrubs && p->is_shrub || trees && !p->is_shrub) if(shrubs && p->flags.bits.is_shrub || trees && !p->flags.bits.is_shrub)
{ {
if (what == do_immolate) if (what == do_immolate)
p->is_burning = true; p->is_burning = true;
@ -136,14 +130,14 @@ static command_result immolations (Core * c, do_what what, bool shrubs, bool tre
int32_t x,y,z; int32_t x,y,z;
if(Gui->getCursorCoords(x,y,z)) if(Gui->getCursorCoords(x,y,z))
{ {
vector<DFHack::df_plant *> * alltrees; vector<df::plant *> * alltrees;
if(Maps::ReadVegetation(x/16,y/16,z,alltrees)) if(Maps::ReadVegetation(x/16,y/16,z,alltrees))
{ {
bool didit = false; bool didit = false;
for(size_t i = 0 ; i < alltrees->size(); i++) for(size_t i = 0 ; i < alltrees->size(); i++)
{ {
DFHack::df_plant * tree = alltrees->at(i); df::plant * tree = alltrees->at(i);
if(tree->x == x && tree->y == y && tree->z == z) if(tree->pos.x == x && tree->pos.y == y && tree->pos.z == z)
{ {
if(what == do_immolate) if(what == do_immolate)
tree->is_burning = true; tree->is_burning = true;
@ -165,9 +159,6 @@ static command_result immolations (Core * c, do_what what, bool shrubs, bool tre
c->con.printerr("No mass destruction and no cursor...\n" ); c->con.printerr("No mass destruction and no cursor...\n" );
} }
} }
// Cleanup
veg->Finish();
c->Resume();
return CR_OK; return CR_OK;
} }
@ -209,33 +200,25 @@ DFhackCExport command_result df_grow (Core * c, vector <string> & parameters)
return CR_OK; return CR_OK;
} }
} }
c->Suspend(); CoreSuspender suspend(c);
Console & con = c->con; Console & con = c->con;
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
MapExtras::MapCache map; MapExtras::MapCache map;
DFHack::Vegetation *veg = c->getVegetation();
if (!veg->all_plants)
{
con.printerr("Unable to read vegetation!\n");
c->Resume();
return CR_FAILURE;
}
DFHack::Gui *Gui = c->getGui(); DFHack::Gui *Gui = c->getGui();
int32_t x,y,z; int32_t x,y,z;
if(Gui->getCursorCoords(x,y,z)) if(Gui->getCursorCoords(x,y,z))
{ {
vector<DFHack::df_plant *> * alltrees; vector<df::plant *> * alltrees;
if(Maps::ReadVegetation(x/16,y/16,z,alltrees)) if(Maps::ReadVegetation(x/16,y/16,z,alltrees))
{ {
for(size_t i = 0 ; i < alltrees->size(); i++) for(size_t i = 0 ; i < alltrees->size(); i++)
{ {
DFHack::df_plant * tree = alltrees->at(i); df::plant * tree = alltrees->at(i);
if(tree->x == x && tree->y == y && tree->z == z) if(tree->pos.x == x && tree->pos.y == y && tree->pos.z == z)
{ {
if(DFHack::tileShape(map.tiletypeAt(DFHack::DFCoord(x,y,z))) == DFHack::SAPLING_OK) if(DFHack::tileShape(map.tiletypeAt(DFHack::DFCoord(x,y,z))) == DFHack::SAPLING_OK)
{ {
@ -249,20 +232,17 @@ DFhackCExport command_result df_grow (Core * c, vector <string> & parameters)
else else
{ {
int grown = 0; int grown = 0;
for(size_t i = 0 ; i < veg->all_plants->size(); i++) for(size_t i = 0 ; i < world->plants.all.size(); i++)
{ {
DFHack::df_plant *p = veg->all_plants->at(i); df::plant *p = world->plants.all[i];
uint16_t ttype = map.tiletypeAt(DFHack::DFCoord(p->x,p->y,p->z)); uint16_t ttype = map.tiletypeAt(df::coord(p->pos.x,p->pos.y,p->pos.z));
if(!p->is_shrub && DFHack::tileShape(ttype) == DFHack::SAPLING_OK) if(!p->flags.bits.is_shrub && DFHack::tileShape(ttype) == DFHack::SAPLING_OK)
{ {
p->grow_counter = DFHack::sapling_to_tree_threshold; p->grow_counter = DFHack::sapling_to_tree_threshold;
} }
} }
} }
// Cleanup
veg->Finish();
c->Resume();
return CR_OK; return CR_OK;
} }

@ -24,6 +24,7 @@ using namespace std;
using std::vector; using std::vector;
using std::string; using std::string;
using namespace DFHack; using namespace DFHack;
using namespace df::enums;
DFhackCExport command_result df_probe (Core * c, vector <string> & parameters); DFhackCExport command_result df_probe (Core * c, vector <string> & parameters);
DFhackCExport command_result df_cprobe (Core * c, vector <string> & parameters); DFhackCExport command_result df_cprobe (Core * c, vector <string> & parameters);
@ -53,7 +54,7 @@ DFhackCExport command_result plugin_shutdown ( Core * c )
DFhackCExport command_result df_cprobe (Core * c, vector <string> & parameters) DFhackCExport command_result df_cprobe (Core * c, vector <string> & parameters)
{ {
Console & con = c->con; Console & con = c->con;
c->Suspend(); CoreSuspender suspend(c);
DFHack::Gui *Gui = c->getGui(); DFHack::Gui *Gui = c->getGui();
DFHack::Units * cr = c->getUnits(); DFHack::Units * cr = c->getUnits();
int32_t cursorX, cursorY, cursorZ; int32_t cursorX, cursorY, cursorZ;
@ -76,7 +77,6 @@ DFhackCExport command_result df_cprobe (Core * c, vector <string> & parameters)
} }
} }
} }
c->Resume();
return CR_OK; return CR_OK;
} }
@ -93,8 +93,7 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
} }
*/ */
BEGIN_PROBE: CoreSuspender suspend(c);
c->Suspend();
DFHack::Gui *Gui = c->getGui(); DFHack::Gui *Gui = c->getGui();
DFHack::Materials *Materials = c->getMaterials(); DFHack::Materials *Materials = c->getMaterials();
@ -105,7 +104,6 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
MapExtras::MapCache mc; MapExtras::MapCache mc;
@ -118,7 +116,6 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
if(cursorX == -30000) if(cursorX == -30000)
{ {
con.printerr("No cursor; place cursor over tile to probe.\n"); con.printerr("No cursor; place cursor over tile to probe.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
DFCoord cursor (cursorX,cursorY,cursorZ); DFCoord cursor (cursorX,cursorY,cursorZ);
@ -132,7 +129,6 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
if(!b && !b->valid) if(!b && !b->valid)
{ {
con.printerr("No data.\n"); con.printerr("No data.\n");
c->Resume();
return CR_OK; return CR_OK;
} }
mapblock40d & block = b->raw; mapblock40d & block = b->raw;
@ -220,7 +216,7 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
// liquids // liquids
if(des.bits.flow_size) if(des.bits.flow_size)
{ {
if(des.bits.liquid_type == df::tile_liquid::Magma) if(des.bits.liquid_type == tile_liquid::Magma)
con <<"magma: "; con <<"magma: ";
else con <<"water: "; else con <<"water: ";
con << des.bits.flow_size << std::endl; con << des.bits.flow_size << std::endl;
@ -275,6 +271,5 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
<< endl; << endl;
con << "mystery: " << block.mystery << endl; con << "mystery: " << block.mystery << endl;
con << std::endl; con << std::endl;
c->Resume();
return CR_OK; return CR_OK;
} }

@ -23,6 +23,7 @@ using namespace std;
#include "df/world.h" #include "df/world.h"
using namespace DFHack; using namespace DFHack;
using namespace df::enums;
using df::global::world; using df::global::world;
struct matdata struct matdata
@ -69,7 +70,7 @@ bool operator>(const matdata & q1, const matdata & q2)
typedef std::map<int16_t, matdata> MatMap; typedef std::map<int16_t, matdata> MatMap;
typedef std::vector< pair<int16_t, matdata> > MatSorter; typedef std::vector< pair<int16_t, matdata> > MatSorter;
typedef std::vector<DFHack::df_plant *> PlantList; typedef std::vector<df::plant *> PlantList;
#define TO_PTR_VEC(obj_vec, ptr_vec) \ #define TO_PTR_VEC(obj_vec, ptr_vec) \
ptr_vec.clear(); \ ptr_vec.clear(); \
@ -223,11 +224,10 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
} }
} }
uint32_t x_max = 0, y_max = 0, z_max = 0; uint32_t x_max = 0, y_max = 0, z_max = 0;
c->Suspend(); CoreSuspender suspend(c);
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
Maps::getSize(x_max, y_max, z_max); Maps::getSize(x_max, y_max, z_max);
@ -283,7 +283,7 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
Maps::GetLocalFeature(blockFeatureLocal, blockCoord, index); Maps::GetLocalFeature(blockFeatureLocal, blockCoord, index);
} }
int global_z = df::global::world->map.region_z + z; int global_z = world->map.region_z + z;
// Iterate over all the tiles in the block // Iterate over all the tiles in the block
for(uint32_t y = 0; y < 16; y++) for(uint32_t y = 0; y < 16; y++)
@ -316,7 +316,7 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
// Check for liquid // Check for liquid
if (des.bits.flow_size) if (des.bits.flow_size)
{ {
if (des.bits.liquid_type == df::tile_liquid::Magma) if (des.bits.liquid_type == tile_liquid::Magma)
liquidMagma.add(global_z); liquidMagma.add(global_z);
else else
liquidWater.add(global_z); liquidWater.add(global_z);
@ -344,7 +344,7 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
so as to exclude any holes mined by the player. */ so as to exclude any holes mined by the player. */
if (info->material == DFHack::AIR && if (info->material == DFHack::AIR &&
des.bits.feature_local && des.bits.hidden && des.bits.feature_local && des.bits.hidden &&
blockFeatureLocal.type == df::feature_type::deep_special_tube) blockFeatureLocal.type == feature_type::deep_special_tube)
{ {
tubeTiles.add(global_z); tubeTiles.add(global_z);
} }
@ -368,20 +368,20 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
case DFHack::FEATSTONE: case DFHack::FEATSTONE:
if (blockFeatureLocal.type != -1 && des.bits.feature_local) if (blockFeatureLocal.type != -1 && des.bits.feature_local)
{ {
if (blockFeatureLocal.type == df::feature_type::deep_special_tube if (blockFeatureLocal.type == feature_type::deep_special_tube
&& blockFeatureLocal.main_material == 0) // stone && blockFeatureLocal.main_material == 0) // stone
{ {
veinMats[blockFeatureLocal.sub_material].add(global_z); veinMats[blockFeatureLocal.sub_material].add(global_z);
} }
else if (showTemple else if (showTemple
&& blockFeatureLocal.type == df::feature_type::deep_surface_portal) && blockFeatureLocal.type == feature_type::deep_surface_portal)
{ {
hasDemonTemple = true; hasDemonTemple = true;
} }
} }
if (showSlade && blockFeatureGlobal.type != -1 && des.bits.feature_global if (showSlade && blockFeatureGlobal.type != -1 && des.bits.feature_global
&& blockFeatureGlobal.type == df::feature_type::feature_underworld_from_layer && blockFeatureGlobal.type == feature_type::feature_underworld_from_layer
&& blockFeatureGlobal.main_material == 0) // stone && blockFeatureGlobal.main_material == 0) // stone
{ {
layerMats[blockFeatureGlobal.sub_material].add(global_z); layerMats[blockFeatureGlobal.sub_material].add(global_z);
@ -403,12 +403,12 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
{ {
for (PlantList::const_iterator it = plants->begin(); it != plants->end(); it++) for (PlantList::const_iterator it = plants->begin(); it != plants->end(); it++)
{ {
const DFHack::df_plant & plant = *(*it); const df::plant & plant = *(*it);
df::coord2d loc(plant.x, plant.y); df::coord2d loc(plant.pos.x, plant.pos.y);
loc = loc % 16; loc = loc % 16;
if (showHidden || !b->DesignationAt(loc).bits.hidden) if (showHidden || !b->DesignationAt(loc).bits.hidden)
{ {
if(plant.is_shrub) if(plant.flags.bits.is_shrub)
plantMats[plant.material].add(global_z); plantMats[plant.material].add(global_z);
else else
treeMats[plant.material].add(global_z); treeMats[plant.material].add(global_z);
@ -494,7 +494,6 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
veg->Finish(); veg->Finish();
} }
mats->Finish(); mats->Finish();
c->Resume();
con << std::endl; con << std::endl;
return CR_OK; return CR_OK;
} }

@ -12,6 +12,7 @@
#include "modules/Gui.h" #include "modules/Gui.h"
using MapExtras::MapCache; using MapExtras::MapCache;
using namespace DFHack; using namespace DFHack;
using namespace df::enums;
using df::global::world; using df::global::world;
/* /*
@ -27,10 +28,10 @@ bool isSafe(df::coord c)
return false; return false;
// Adamantine tubes and temples lead to Hell // Adamantine tubes and temples lead to Hell
if (local_feature.type == df::feature_type::deep_special_tube || local_feature.type == df::feature_type::deep_surface_portal) if (local_feature.type == feature_type::deep_special_tube || local_feature.type == feature_type::deep_surface_portal)
return false; return false;
// And Hell *is* Hell. // And Hell *is* Hell.
if (global_feature.type == df::feature_type::feature_underworld_from_layer) if (global_feature.type == feature_type::feature_underworld_from_layer)
return false; return false;
// otherwise it's safe. // otherwise it's safe.
return true; return true;
@ -157,20 +158,18 @@ DFhackCExport command_result reveal(DFHack::Core * c, std::vector<std::string> &
return CR_FAILURE; return CR_FAILURE;
} }
c->Suspend(); CoreSuspender suspend(c);
DFHack::World *World =c->getWorld(); DFHack::World *World =c->getWorld();
t_gamemodes gm; t_gamemodes gm;
World->ReadGameMode(gm); World->ReadGameMode(gm);
if(gm.g_mode != GAMEMODE_DWARF) if(gm.g_mode != GAMEMODE_DWARF)
{ {
con.printerr("Only in fortress mode.\n"); con.printerr("Only in fortress mode.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -209,7 +208,6 @@ DFhackCExport command_result reveal(DFHack::Core * c, std::vector<std::string> &
else else
revealed = DEMON_REVEALED; revealed = DEMON_REVEALED;
} }
c->Resume();
con.print("Map revealed.\n"); con.print("Map revealed.\n");
if(!no_hell) if(!no_hell)
con.print("Unpausing can unleash the forces of hell, so it has been temporarily disabled.\n"); con.print("Unpausing can unleash the forces of hell, so it has been temporarily disabled.\n");
@ -233,7 +231,7 @@ DFhackCExport command_result unreveal(DFHack::Core * c, std::vector<std::string>
con.printerr("There's nothing to revert!\n"); con.printerr("There's nothing to revert!\n");
return CR_FAILURE; return CR_FAILURE;
} }
c->Suspend(); CoreSuspender suspend(c);
DFHack::World *World =c->getWorld(); DFHack::World *World =c->getWorld();
t_gamemodes gm; t_gamemodes gm;
@ -241,13 +239,11 @@ DFhackCExport command_result unreveal(DFHack::Core * c, std::vector<std::string>
if(gm.g_mode != GAMEMODE_DWARF) if(gm.g_mode != GAMEMODE_DWARF)
{ {
con.printerr("Only in fortress mode.\n"); con.printerr("Only in fortress mode.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -257,7 +253,6 @@ DFhackCExport command_result unreveal(DFHack::Core * c, std::vector<std::string>
if(x_max != x_max_b || y_max != y_max_b || z_max != z_max_b) if(x_max != x_max_b || y_max != y_max_b || z_max != z_max_b)
{ {
con.printerr("The map is not of the same size...\n"); con.printerr("The map is not of the same size...\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -274,7 +269,6 @@ DFhackCExport command_result unreveal(DFHack::Core * c, std::vector<std::string>
hidesaved.clear(); hidesaved.clear();
revealed = NOT_REVEALED; revealed = NOT_REVEALED;
con.print("Map hidden!\n"); con.print("Map hidden!\n");
c->Resume();
return CR_OK; return CR_OK;
} }
@ -310,20 +304,18 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
return CR_OK; return CR_OK;
} }
} }
c->Suspend(); CoreSuspender suspend(c);
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
Gui * Gui = c->getGui(); Gui * Gui = c->getGui();
World * World = c->getWorld(); World * World = c->getWorld();
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
if(revealed != NOT_REVEALED) if(revealed != NOT_REVEALED)
{ {
c->con.printerr("This is only safe to use with non-revealed map.\n"); c->con.printerr("This is only safe to use with non-revealed map.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
t_gamemodes gm; t_gamemodes gm;
@ -331,7 +323,6 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
if(gm.g_type != GAMETYPE_DWARF_MAIN && gm.g_mode != GAMEMODE_DWARF ) if(gm.g_type != GAMETYPE_DWARF_MAIN && gm.g_mode != GAMEMODE_DWARF )
{ {
c->con.printerr("Only in proper dwarf mode.\n"); c->con.printerr("Only in proper dwarf mode.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
int32_t cx, cy, cz; int32_t cx, cy, cz;
@ -343,7 +334,6 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
if(cx == -30000) if(cx == -30000)
{ {
c->con.printerr("Cursor is not active. Point the cursor at some empty space you want to be unhidden.\n"); c->con.printerr("Cursor is not active. Point the cursor at some empty space you want to be unhidden.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz); DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz);
@ -353,7 +343,6 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
{ {
c->con.printerr("Point the cursor at some empty space you want to be unhidden.\n"); c->con.printerr("Point the cursor at some empty space you want to be unhidden.\n");
delete MCache; delete MCache;
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
// hide all tiles, flush cache // hide all tiles, flush cache
@ -467,6 +456,5 @@ DFhackCExport command_result revflood(DFHack::Core * c, std::vector<std::string>
} }
MCache->WriteAll(); MCache->WriteAll();
delete MCache; delete MCache;
c->Resume();
return CR_OK; return CR_OK;
} }

@ -17,7 +17,7 @@
using namespace DFHack; using namespace DFHack;
using namespace DFHack::Simple; using namespace DFHack::Simple;
using namespace df::enums;
using df::global::world; using df::global::world;
const int buffer = 20; // seed number buffer - 20 is reasonable const int buffer = 20; // seed number buffer - 20 is reasonable
@ -102,7 +102,7 @@ DFhackCExport command_result df_seedwatch(Core* pCore, std::vector<std::string>&
{ {
return CR_FAILURE; return CR_FAILURE;
} }
core.Suspend(); CoreSuspender suspend(pCore);
std::map<std::string, t_materialIndex> materialsReverser; std::map<std::string, t_materialIndex> materialsReverser;
for(std::size_t i = 0; i < world->raws.plants.all.size(); ++i) for(std::size_t i = 0; i < world->raws.plants.all.size(); ++i)
@ -119,7 +119,6 @@ DFhackCExport command_result df_seedwatch(Core* pCore, std::vector<std::string>&
{ {
// just print the help // just print the help
printHelp(core); printHelp(core);
core.Resume();
return CR_OK; return CR_OK;
} }
@ -184,7 +183,6 @@ DFhackCExport command_result df_seedwatch(Core* pCore, std::vector<std::string>&
/* /*
else if(par == "dumpmaps") else if(par == "dumpmaps")
{ {
core.con.print("Plants:\n"); core.con.print("Plants:\n");
for(auto i = plantMaterialTypes.begin(); i != plantMaterialTypes.end(); i++) for(auto i = plantMaterialTypes.begin(); i != plantMaterialTypes.end(); i++)
{ {
@ -242,7 +240,6 @@ DFhackCExport command_result df_seedwatch(Core* pCore, std::vector<std::string>&
break; break;
} }
core.Resume();
return CR_OK; return CR_OK;
} }
@ -328,10 +325,10 @@ DFhackCExport command_result plugin_onupdate(Core* pCore)
t_materialIndex materialIndex = item->getMaterialIndex(); t_materialIndex materialIndex = item->getMaterialIndex();
switch(item->getType()) switch(item->getType())
{ {
case df::item_type::SEEDS: case item_type::SEEDS:
if(!ignoreSeeds(item->flags)) ++seedCount[materialIndex]; if(!ignoreSeeds(item->flags)) ++seedCount[materialIndex];
break; break;
case df::item_type::PLANT: case item_type::PLANT:
break; break;
} }
} }

@ -22,6 +22,7 @@ using std::set;
#include "df/tile_dig_designation.h" #include "df/tile_dig_designation.h"
using namespace MapExtras; using namespace MapExtras;
using namespace DFHack; using namespace DFHack;
using namespace df::enums;
//zilpin: These two functions were giving me compile errors in VS2008, so I cheated with the C style loop below, just to get it to build. //zilpin: These two functions were giving me compile errors in VS2008, so I cheated with the C style loop below, just to get it to build.
//Original code is commented out. //Original code is commented out.
@ -753,12 +754,11 @@ DFhackCExport command_result df_tiletypes (Core * c, vector <string> & parameter
continue; continue;
} }
c->Suspend(); CoreSuspender suspend(c);
gui = c->getGui(); gui = c->getGui();
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
Maps::getSize(x_max, y_max, z_max); Maps::getSize(x_max, y_max, z_max);
@ -766,7 +766,6 @@ DFhackCExport command_result df_tiletypes (Core * c, vector <string> & parameter
if (!(gui->Start() && gui->getCursorCoords(x,y,z))) if (!(gui->Start() && gui->getCursorCoords(x,y,z)))
{ {
c->con.printerr("Can't get cursor coords! Make sure you have a cursor active in DF.\n"); c->con.printerr("Can't get cursor coords! Make sure you have a cursor active in DF.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
c->con.print("Cursor coords: (%d, %d, %d)\n",x,y,z); c->con.print("Cursor coords: (%d, %d, %d)\n",x,y,z);
@ -785,7 +784,7 @@ DFhackCExport command_result df_tiletypes (Core * c, vector <string> & parameter
|| (filter.material > -1 && filter.material != source->material) || (filter.material > -1 && filter.material != source->material)
|| (filter.special > -1 && filter.special != source->special) || (filter.special > -1 && filter.special != source->special)
|| (filter.variant > -1 && filter.variant != source->variant) || (filter.variant > -1 && filter.variant != source->variant)
|| (filter.dig > -1 && (filter.dig != 0) != (des.bits.dig != df::tile_dig_designation::No)) || (filter.dig > -1 && (filter.dig != 0) != (des.bits.dig != tile_dig_designation::No))
) )
{ {
continue; continue;
@ -890,7 +889,6 @@ DFhackCExport command_result df_tiletypes (Core * c, vector <string> & parameter
{ {
c->con.printerr("Something failed horribly! RUN!\n"); c->con.printerr("Something failed horribly! RUN!\n");
} }
c->Resume();
} }
} }
return CR_OK; return CR_OK;

@ -15,6 +15,7 @@
using namespace DFHack; using namespace DFHack;
using namespace DFHack::Simple; using namespace DFHack::Simple;
using namespace df::enums;
using df::global::world; using df::global::world;
DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string> & params); DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string> & params);
@ -50,11 +51,10 @@ DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string>
return CR_OK; return CR_OK;
} }
} }
c->Suspend(); CoreSuspender suspend(c);
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -69,7 +69,7 @@ DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string>
DFCoord coord(block->map_pos.x >> 4, block->map_pos.y >> 4, block->map_pos.z); DFCoord coord(block->map_pos.x >> 4, block->map_pos.y >> 4, block->map_pos.z);
if (!Maps::GetLocalFeature(feature, coord, block->local_feature)) if (!Maps::GetLocalFeature(feature, coord, block->local_feature))
continue; continue;
if (feature.type != df::feature_type::deep_special_tube) if (feature.type != feature_type::deep_special_tube)
continue; continue;
for (uint32_t x = 0; x < 16; x++) for (uint32_t x = 0; x < 16; x++)
{ {
@ -106,7 +106,6 @@ DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string>
} }
} }
} }
c->Resume();
c->con.print("Found and changed %d tiles.\n", count); c->con.print("Found and changed %d tiles.\n", count);
return CR_OK; return CR_OK;
} }

@ -14,6 +14,7 @@ using std::vector;
using std::string; using std::string;
using std::stack; using std::stack;
using namespace DFHack; using namespace DFHack;
using namespace df::enums;
DFhackCExport command_result vdig (Core * c, vector <string> & parameters); DFhackCExport command_result vdig (Core * c, vector <string> & parameters);
DFhackCExport command_result vdigx (Core * c, vector <string> & parameters); DFhackCExport command_result vdigx (Core * c, vector <string> & parameters);
@ -107,7 +108,7 @@ bool dig (MapExtras::MapCache & MCache,
break; break;
} }
if(isFloorTerrain(tt) if(isFloorTerrain(tt)
&& (type == df::tile_dig_designation::DownStair || type == df::tile_dig_designation::Channel) && (type == tile_dig_designation::DownStair || type == tile_dig_designation::Channel)
&& ts != TREE_OK && ts != TREE_OK
&& ts != TREE_DEAD && ts != TREE_DEAD
) )
@ -115,7 +116,7 @@ bool dig (MapExtras::MapCache & MCache,
std::cerr << "allowing tt" << tt << ", is floor\n"; std::cerr << "allowing tt" << tt << ", is floor\n";
break; break;
} }
if(isStairTerrain(tt) && type == df::tile_dig_designation::Channel ) if(isStairTerrain(tt) && type == tile_dig_designation::Channel )
break; break;
return false; return false;
} }
@ -124,25 +125,25 @@ bool dig (MapExtras::MapCache & MCache,
switch(what) switch(what)
{ {
case circle_set: case circle_set:
if(des.bits.dig == df::tile_dig_designation::No) if(des.bits.dig == tile_dig_designation::No)
{ {
des.bits.dig = type; des.bits.dig = type;
} }
break; break;
case circle_unset: case circle_unset:
if (des.bits.dig != df::tile_dig_designation::No) if (des.bits.dig != tile_dig_designation::No)
{ {
des.bits.dig = df::tile_dig_designation::No; des.bits.dig = tile_dig_designation::No;
} }
break; break;
case circle_invert: case circle_invert:
if(des.bits.dig == df::tile_dig_designation::No) if(des.bits.dig == tile_dig_designation::No)
{ {
des.bits.dig = type; des.bits.dig = type;
} }
else else
{ {
des.bits.dig = df::tile_dig_designation::No; des.bits.dig = tile_dig_designation::No;
} }
break; break;
} }
@ -183,7 +184,7 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
{ {
static bool filled = false; static bool filled = false;
static circle_what what = circle_set; static circle_what what = circle_set;
static df::tile_dig_designation type = df::tile_dig_designation::Default; static df::tile_dig_designation type = tile_dig_designation::Default;
static int diameter = 0; static int diameter = 0;
auto saved_d = diameter; auto saved_d = diameter;
bool force_help = false; bool force_help = false;
@ -215,27 +216,27 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
} }
else if(parameters[i] == "dig") else if(parameters[i] == "dig")
{ {
type = df::tile_dig_designation::Default; type = tile_dig_designation::Default;
} }
else if(parameters[i] == "ramp") else if(parameters[i] == "ramp")
{ {
type = df::tile_dig_designation::Ramp; type = tile_dig_designation::Ramp;
} }
else if(parameters[i] == "dstair") else if(parameters[i] == "dstair")
{ {
type = df::tile_dig_designation::DownStair; type = tile_dig_designation::DownStair;
} }
else if(parameters[i] == "ustair") else if(parameters[i] == "ustair")
{ {
type = df::tile_dig_designation::UpStair; type = tile_dig_designation::UpStair;
} }
else if(parameters[i] == "xstair") else if(parameters[i] == "xstair")
{ {
type = df::tile_dig_designation::UpDownStair; type = tile_dig_designation::UpDownStair;
} }
else if(parameters[i] == "chan") else if(parameters[i] == "chan")
{ {
type = df::tile_dig_designation::Channel; type = tile_dig_designation::Channel;
} }
else if (!from_string(diameter,parameters[i], std::dec)) else if (!from_string(diameter,parameters[i], std::dec))
{ {
@ -246,7 +247,8 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
diameter = -diameter; diameter = -diameter;
if(force_help || diameter == 0) if(force_help || diameter == 0)
{ {
c->con.print( "A command for easy designation of filled and hollow circles.\n" c->con.print(
"A command for easy designation of filled and hollow circles.\n"
"\n" "\n"
"Options:\n" "Options:\n"
" hollow = Set the circle to hollow (default)\n" " hollow = Set the circle to hollow (default)\n"
@ -273,12 +275,11 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
return CR_OK; return CR_OK;
} }
int32_t cx, cy, cz; int32_t cx, cy, cz;
c->Suspend(); CoreSuspender suspend(c);
Gui * gui = c->getGui(); Gui * gui = c->getGui();
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -288,7 +289,6 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
MapExtras::MapCache MCache; MapExtras::MapCache MCache;
if(!gui->getCursorCoords(cx,cy,cz) || cx == -30000) if(!gui->getCursorCoords(cx,cy,cz) || cx == -30000)
{ {
c->Resume();
c->con.printerr("Can't get the cursor coords...\n"); c->con.printerr("Can't get the cursor coords...\n");
return CR_FAILURE; return CR_FAILURE;
} }
@ -359,7 +359,6 @@ DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
lastwhole = whole; lastwhole = whole;
} }
MCache.WriteAll(); MCache.WriteAll();
c->Resume();
return CR_OK; return CR_OK;
} }
typedef char digmask[16][16]; typedef char digmask[16][16];
@ -756,25 +755,25 @@ bool stamp_pattern (uint32_t bx, uint32_t by, int z_level,
continue; continue;
if(how == EXPLO_CLEAR) if(how == EXPLO_CLEAR)
{ {
des.bits.dig = df::tile_dig_designation::No; des.bits.dig = tile_dig_designation::No;
continue; continue;
} }
if(dm[y][x]) if(dm[y][x])
{ {
if(what == EXPLO_ALL if(what == EXPLO_ALL
|| des.bits.dig == df::tile_dig_designation::Default && what == EXPLO_DESIGNATED || des.bits.dig == tile_dig_designation::Default && what == EXPLO_DESIGNATED
|| des.bits.hidden && what == EXPLO_HIDDEN) || des.bits.hidden && what == EXPLO_HIDDEN)
{ {
des.bits.dig = df::tile_dig_designation::Default; des.bits.dig = tile_dig_designation::Default;
} }
} }
else if(what == EXPLO_DESIGNATED) else if(what == EXPLO_DESIGNATED)
{ {
des.bits.dig = df::tile_dig_designation::No; des.bits.dig = tile_dig_designation::No;
} }
} }
} }
bl->flags.set(df::block_flags::Designated); bl->flags.set(block_flags::Designated);
return true; return true;
}; };
@ -828,7 +827,8 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
} }
if(force_help || how == EXPLO_NOTHING) if(force_help || how == EXPLO_NOTHING)
{ {
c->con.print("This command can be used for exploratory mining.\n" c->con.print(
"This command can be used for exploratory mining.\n"
"http://df.magmawiki.com/index.php/DF2010:Exploratory_mining\n" "http://df.magmawiki.com/index.php/DF2010:Exploratory_mining\n"
"\n" "\n"
"There are two variables that can be set: pattern and filter.\n" "There are two variables that can be set: pattern and filter.\n"
@ -850,20 +850,18 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
); );
return CR_OK; return CR_OK;
} }
c->Suspend(); CoreSuspender suspend(c);
Gui * gui = c->getGui(); Gui * gui = c->getGui();
uint32_t x_max, y_max, z_max; uint32_t x_max, y_max, z_max;
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); c->con.printerr("Map is not available!\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
Maps::getSize(x_max,y_max,z_max); Maps::getSize(x_max,y_max,z_max);
int32_t xzzz,yzzz,z_level; int32_t xzzz,yzzz,z_level;
if(!gui->getViewCoords(xzzz,yzzz,z_level)) if(!gui->getViewCoords(xzzz,yzzz,z_level))
{ {
c->Resume();
c->con.printerr("Can't get view coords...\n"); c->con.printerr("Can't get view coords...\n");
return CR_FAILURE; return CR_FAILURE;
} }
@ -939,7 +937,7 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
continue; continue;
if(cross[y][x]) if(cross[y][x])
{ {
des.bits.dig = df::tile_dig_designation::Default; des.bits.dig = tile_dig_designation::Default;
mx.setDesignationAt(pos,des); mx.setDesignationAt(pos,des);
} }
} }
@ -953,7 +951,6 @@ DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
how, what, x_max, y_max); how, what, x_max, y_max);
} }
} }
c->Resume();
return CR_OK; return CR_OK;
} }
@ -1090,32 +1087,32 @@ DFhackCExport command_result vdig (Core * c, vector <string> & parameters)
{ {
flood.push(current-1); flood.push(current-1);
if(des_minus.bits.dig == df::tile_dig_designation::DownStair) if(des_minus.bits.dig == tile_dig_designation::DownStair)
des_minus.bits.dig = df::tile_dig_designation::UpDownStair; des_minus.bits.dig = tile_dig_designation::UpDownStair;
else else
des_minus.bits.dig = df::tile_dig_designation::UpStair; des_minus.bits.dig = tile_dig_designation::UpStair;
MCache->setDesignationAt(current-1,des_minus); MCache->setDesignationAt(current-1,des_minus);
des.bits.dig = df::tile_dig_designation::DownStair; des.bits.dig = tile_dig_designation::DownStair;
} }
if(current.z < z_max - 1 && above && vmat_plus == vmat2) if(current.z < z_max - 1 && above && vmat_plus == vmat2)
{ {
flood.push(current+ 1); flood.push(current+ 1);
if(des_plus.bits.dig == df::tile_dig_designation::UpStair) if(des_plus.bits.dig == tile_dig_designation::UpStair)
des_plus.bits.dig = df::tile_dig_designation::UpDownStair; des_plus.bits.dig = tile_dig_designation::UpDownStair;
else else
des_plus.bits.dig = df::tile_dig_designation::DownStair; des_plus.bits.dig = tile_dig_designation::DownStair;
MCache->setDesignationAt(current+1,des_plus); MCache->setDesignationAt(current+1,des_plus);
if(des.bits.dig == df::tile_dig_designation::DownStair) if(des.bits.dig == tile_dig_designation::DownStair)
des.bits.dig = df::tile_dig_designation::UpDownStair; des.bits.dig = tile_dig_designation::UpDownStair;
else else
des.bits.dig = df::tile_dig_designation::UpStair; des.bits.dig = tile_dig_designation::UpStair;
} }
} }
if(des.bits.dig == df::tile_dig_designation::No) if(des.bits.dig == tile_dig_designation::No)
des.bits.dig = df::tile_dig_designation::Default; des.bits.dig = tile_dig_designation::Default;
MCache->setDesignationAt(current,des); MCache->setDesignationAt(current,des);
} }
} }

@ -81,12 +81,12 @@ DFhackCExport command_result weather (Core * c, vector <string> & parameters)
return CR_FAILURE; return CR_FAILURE;
} }
bool something = lock || unlock || rain || snow || clear; bool something = lock || unlock || rain || snow || clear;
c->Suspend();
CoreSuspender suspend(c);
DFHack::World * w = c->getWorld(); DFHack::World * w = c->getWorld();
if(!w->wmap) if(!w->wmap)
{ {
con << "Weather support seems broken :(" << std::endl; con << "Weather support seems broken :(" << std::endl;
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
if(!something) if(!something)
@ -99,13 +99,13 @@ DFhackCExport command_result weather (Core * c, vector <string> & parameters)
{ {
switch((*w->wmap)[x][y]) switch((*w->wmap)[x][y])
{ {
case DFHack::CLEAR: case CLEAR:
con << "C "; con << "C ";
break; break;
case DFHack::RAINING: case RAINING:
con << "R "; con << "R ";
break; break;
case DFHack::SNOWING: case SNOWING:
con << "S "; con << "S ";
break; break;
default: default:
@ -136,6 +136,5 @@ DFhackCExport command_result weather (Core * c, vector <string> & parameters)
} }
// FIXME: weather lock needs map ID to work reliably... needs to be implemented. // FIXME: weather lock needs map ID to work reliably... needs to be implemented.
} }
c->Resume();
return CR_OK; return CR_OK;
} }