Tweak showmood, add a few validity checks, commit a dfhack.init example.

develop
Alexander Gavrilov 2012-01-24 15:36:30 +04:00
parent 6adadb396e
commit 174d9d0739
7 changed files with 123 additions and 21 deletions

@ -0,0 +1,34 @@
##############################
# Generic dwarfmode bindings #
##############################
keybinding add Ctrl-W twaterlvl
# with cursor:
keybinding add Ctrl-V vdig
keybinding add Ctrl-Shift-V "vdig x"
keybinding add Ctrl-C spotclean
keybinding add Ctrl-Shift-K autodump-destroy-here
# any item:
keybinding add Ctrl-K autodump-destroy-item
#############################
# Context-specific bindings #
#############################
# q->stockpile; p
keybinding add Alt-P copystock
# q->workshop
keybinding add Ctrl-D job-duplicate
# materials: q->workshop; b->select items
keybinding add Shift-A "job-material ALUNITE"
keybinding add Shift-M "job-material MICROCLINE"
keybinding add Shift-D "job-material DACITE"
keybinding add Shift-R "job-material RHYOLITE"
keybinding add Shift-I "job-material CINNABAR"
keybinding add Shift-B "job-material COBALTITE"
keybinding add Shift-O "job-material OBSIDIAN"
keybinding add Shift-G "job-material GLASS_GREEN"

@ -74,6 +74,7 @@ namespace DFHack
df::material *material;
enum Mode {
None,
Builtin,
Inorganic,
Creature,
@ -94,6 +95,15 @@ namespace DFHack
bool isValid() const { return material != NULL; }
bool isNone() const { return mode == None; }
bool isBuiltin() const { return mode == Builtin; }
bool isInorganic() const { return mode == Inorganic; }
bool isCreature() const { return mode == Creature; }
bool isPlant() const { return mode == Plant; }
bool isAnyInorganic() const { return type == 0; }
bool isInorganicWildcard() const { return isAnyInorganic() && isBuiltin(); }
bool decode(int16_t type, int32_t index = -1);
bool decode(df::item *item);
bool decode(const df::material_vec_ref &vr, int idx);
@ -110,6 +120,7 @@ namespace DFHack
bool findPlant(const std::string &token, const std::string &subtoken);
bool findCreature(const std::string &token, const std::string &subtoken);
std::string getToken();
std::string toString(uint16_t temp = 10015, bool named = true);
bool isAnyCloth();

@ -95,9 +95,14 @@ bool MaterialInfo::decode(int16_t type, int32_t index)
inorganic = NULL; plant = NULL; creature = NULL;
figure = NULL;
if (type < 0) {
mode = None;
return false;
}
df::world_raws &raws = world->raws;
if (type < 0 || type >= sizeof(raws.mat_table.builtin)/sizeof(void*))
if (type >= sizeof(raws.mat_table.builtin)/sizeof(void*))
return false;
if (index < 0)
@ -159,7 +164,7 @@ bool MaterialInfo::find(const std::string &token)
std::vector<std::string> items;
split_string(&items, token, ":");
if (items[0] == "INORGANIC")
if (items[0] == "INORGANIC" && items.size() > 1)
return findInorganic(vector_get(items,1));
if (items[0] == "CREATURE_MAT" || items[0] == "CREATURE")
return findCreature(vector_get(items,1), vector_get(items,2));
@ -267,12 +272,35 @@ bool MaterialInfo::findCreature(const std::string &token, const std::string &sub
return decode(-1);
}
std::string MaterialInfo::toString(uint16_t temp, bool named)
std::string MaterialInfo::getToken()
{
if (type == -1)
if (isNone())
return "NONE";
if (!material)
return stl_sprintf("INVALID:%d:%d", type, index);
switch (mode) {
case Builtin:
return material->id;
case Inorganic:
return "INORGANIC:" + inorganic->id;
case Creature:
return "CREATURE:" + creature->creature_id + ":" + material->id;
case Plant:
return "PLANT:" + plant->id + ":" + material->id;
default:
return stl_sprintf("INVALID_MODE:%d:%d", type, index);
}
}
std::string MaterialInfo::toString(uint16_t temp, bool named)
{
if (isNone())
return "any";
if (!material)
return stl_sprintf("INVALID %d:%d", type, index);
return stl_sprintf("INVALID:%d:%d", type, index);
df::matter_state state = matter_state::Solid;
if (temp >= material->heat.melting_point)

@ -122,6 +122,11 @@ DFhackCExport command_result spotclean (Core * c, vector <string> & parameters)
c->con.printerr("The cursor is not active.\n");
return CR_WRONG_USAGE;
}
if (!Maps::IsValid())
{
c->con.printerr("Map is not available.\n");
return CR_FAILURE;
}
df::map_block *block = Maps::getBlockAbs(cursor->x, cursor->y, cursor->z);
if (block == NULL)
{

@ -33,6 +33,12 @@ DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
CoreSuspender suspend(c);
if (!Maps::IsValid())
{
c->con.printerr("Map is not available!\n");
return CR_FAILURE;
}
int count = 0;
int countbad = 0;

@ -180,6 +180,13 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters)
return CR_OK;
}
}
if (!Maps::IsValid())
{
c->con.printerr("Map is not available!\n");
return CR_FAILURE;
}
Brush * brush = new RectangleBrush(1,1);
string brushname = "point";
bool end = false;

@ -6,6 +6,7 @@
#include "PluginManager.h"
#include "modules/Materials.h"
#include "modules/Translation.h"
#include "modules/Items.h"
#include "DataDefs.h"
#include "df/world.h"
@ -157,8 +158,6 @@ DFhackCExport command_result df_showmood (Core * c, vector <string> & parameters
MaterialInfo matinfo(item->mat_type, item->mat_index);
string mat_name = matinfo.toString();
if (mat_name == "NONE")
mat_name = "any";
switch (item->item_type)
{
@ -172,9 +171,9 @@ DFhackCExport command_result df_showmood (Core * c, vector <string> & parameters
c->con.print("%s logs", mat_name.c_str());
break;
case item_type::BAR:
if (mat_name == "rock")
if (matinfo.isInorganicWildcard())
mat_name = "metal";
if ((matinfo.mode == MaterialInfo::Inorganic) && (matinfo.inorganic->flags.is_set(inorganic_flags::WAFERS)))
if (matinfo.inorganic && matinfo.inorganic->flags.is_set(inorganic_flags::WAFERS))
c->con.print("%s wafers", mat_name.c_str());
else
c->con.print("%s bars", mat_name.c_str());
@ -183,9 +182,9 @@ DFhackCExport command_result df_showmood (Core * c, vector <string> & parameters
c->con.print("%s cut gems", mat_name.c_str());
break;
case item_type::ROUGH:
if (item->mat_type == 0)
if (matinfo.isAnyInorganic())
{
if (item->mat_index == -1)
if (matinfo.isInorganicWildcard())
mat_name = "any";
c->con.print("%s rough gems", mat_name.c_str());
}
@ -196,7 +195,7 @@ DFhackCExport command_result df_showmood (Core * c, vector <string> & parameters
c->con.print("%s leather", mat_name.c_str());
break;
case item_type::CLOTH:
if (mat_name == "any")
if (matinfo.isNone())
{
if (item->flags2.bits.plant)
mat_name = "any plant fiber";
@ -221,20 +220,32 @@ DFhackCExport command_result df_showmood (Core * c, vector <string> & parameters
else if (item->flags2.bits.ivory_tooth)
c->con.print("%s ivory/teeth", mat_name.c_str());
else
c->con.print("%s unknown body parts (%08x:%08x:%08x)", mat_name.c_str(), item->flags1.whole, item->flags2.whole, item->flags3.whole);
c->con.print("%s unknown body parts (%s:%s:%s)",
mat_name.c_str(),
bitfieldToString(item->flags1).c_str(),
bitfieldToString(item->flags2).c_str(),
bitfieldToString(item->flags3).c_str());
}
else
c->con.print("indeterminate %s item (%08x:%08x:%08x)", mat_name.c_str(), item->flags1.whole, item->flags2.whole, item->flags3.whole);
c->con.print("indeterminate %s item (%s:%s:%s)",
mat_name.c_str(),
bitfieldToString(item->flags1).c_str(),
bitfieldToString(item->flags2).c_str(),
bitfieldToString(item->flags3).c_str());
break;
default:
c->con.print("item %s:%s with flags %08x,%08x,%08x",
df::enums::item_type::get_key(item->item_type),
(item->item_subtype == -1) ? "NONE" : "???",
item->flags1.whole,
item->flags2.whole,
item->flags3.whole);
break;
{
ItemTypeInfo itinfo(item->item_type, item->item_subtype);
c->con.print("item %s material %s flags (%s:%s:%s)",
itinfo.toString().c_str(), mat_name.c_str(),
bitfieldToString(item->flags1).c_str(),
bitfieldToString(item->flags2).c_str(),
bitfieldToString(item->flags3).c_str());
break;
}
}
c->con.print(", quantity %i\n", item->quantity);
}
}