Merge git://github.com/peterix/dfhack

Conflicts:
	plugins/mapexport/mapexport.cpp
develop
Quietust 2012-01-26 23:07:09 -06:00
commit be0d8c4a88
14 changed files with 58 additions and 201 deletions

@ -653,6 +653,7 @@ bool Console::init(bool sharing)
FD_SET(STDIN_FILENO, &d->descriptor_set); FD_SET(STDIN_FILENO, &d->descriptor_set);
FD_SET(d->exit_pipe[0], &d->descriptor_set); FD_SET(d->exit_pipe[0], &d->descriptor_set);
inited = true; inited = true;
return true;
} }
bool Console::shutdown(void) bool Console::shutdown(void)

@ -145,11 +145,13 @@ typedef int16_t t_blockmaterials [16][16];
* \ingroup grp_maps * \ingroup grp_maps
*/ */
typedef df::tile_designation designations40d [16][16]; typedef df::tile_designation designations40d [16][16];
typedef df::tile_designation t_designation;
/** /**
* 16x16 array of occupancy flags * 16x16 array of occupancy flags
* \ingroup grp_maps * \ingroup grp_maps
*/ */
typedef df::tile_occupancy occupancies40d [16][16]; typedef df::tile_occupancy occupancies40d [16][16];
typedef df::tile_occupancy t_occupancy;
/** /**
* array of 16 biome indexes valid for the block * array of 16 biome indexes valid for the block
* \ingroup grp_maps * \ingroup grp_maps

@ -169,6 +169,7 @@ DFHACK_EXPORT bool isValid();
/* Read Functions */ /* Read Functions */
// Read creatures in a box, starting with index. Returns -1 if no more creatures // Read creatures in a box, starting with index. Returns -1 if no more creatures
// found. Call repeatedly do get all creatures in a specified box (uses tile coords) // found. Call repeatedly do get all creatures in a specified box (uses tile coords)
DFHACK_EXPORT int32_t getNumCreatures();
DFHACK_EXPORT int32_t GetCreatureInBox(const int32_t index, df::unit ** furball, DFHACK_EXPORT int32_t GetCreatureInBox(const int32_t index, df::unit ** furball,
const uint16_t x1, const uint16_t y1,const uint16_t z1, const uint16_t x1, const uint16_t y1,const uint16_t z1,
const uint16_t x2, const uint16_t y2,const uint16_t z2); const uint16_t x2, const uint16_t y2,const uint16_t z2);

@ -62,6 +62,7 @@ using namespace std;
#include "df/physical_attribute_type.h" #include "df/physical_attribute_type.h"
#include "df/mental_attribute_type.h" #include "df/mental_attribute_type.h"
#include <df/color_modifier_raw.h>
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
@ -746,26 +747,26 @@ bool Materials::ReadCreatureTypesEx (void)
caste.singular = ca->caste_name[0]; caste.singular = ca->caste_name[0];
caste.plural = ca->caste_name[1]; caste.plural = ca->caste_name[1];
caste.adjective = ca->caste_name[2]; caste.adjective = ca->caste_name[2];
/*
// color mod reading // color mod reading
// Caste + offset > color mod vector // Caste + offset > color mod vector
vector <char *> & p_colormod = *(vector<char*> *) (world->raws.creatures.all[i]->caste + caste_colormod_offset); auto & colorings = ca->color_modifiers;
uint32_t sizecolormod = p_colormod.size(); uint32_t sizecolormod = colorings.size();
caste.ColorModifier.resize(sizecolormod); caste.ColorModifier.resize(sizecolormod);
for(uint32_t k = 0; k < sizecolormod;k++) for(uint32_t k = 0; k < sizecolormod;k++)
{ {
// color mod [0] -> color list // color mod [0] -> color list
vector <uint32_t> & p_colorlist = *(vector<uint32_t> *) (p_colormod[k]); auto & indexes = colorings[k]->color_indexes;
uint32_t sizecolorlist = p_colorlist.size(); uint32_t sizecolorlist = indexes.size();
caste.ColorModifier[k].colorlist.resize(sizecolorlist); caste.ColorModifier[k].colorlist.resize(sizecolorlist);
for(uint32_t l = 0; l < sizecolorlist; l++) for(uint32_t l = 0; l < sizecolorlist; l++)
caste.ColorModifier[k].colorlist[l] = p_colorlist[l]; caste.ColorModifier[k].colorlist[l] = indexes[l];
// color mod [color_modifier_part_offset] = string part // color mod [color_modifier_part_offset] = string part
caste.ColorModifier[k].part = p->readSTLString( p_colormod[k] + color_modifier_part_offset); caste.ColorModifier[k].part = colorings[k]->part;
caste.ColorModifier[k].startdate = p->readDWord( p_colormod[k] + color_modifier_startdate_offset ); caste.ColorModifier[k].startdate = colorings[k]->start_date;
caste.ColorModifier[k].enddate = p->readDWord( p_colormod[k] + color_modifier_enddate_offset ); caste.ColorModifier[k].enddate = colorings[k]->end_date;
} }
*/
// body parts // body parts
caste.bodypart.empty(); caste.bodypart.empty();
uint32_t sizebp = ca->unknown1.body_parts.size(); uint32_t sizebp = ca->unknown1.body_parts.size();

@ -59,6 +59,11 @@ bool Units::isValid()
return (world->units.all.size() > 0); return (world->units.all.size() > 0);
} }
int32_t Units::getNumCreatures()
{
return world->units.all.size();
}
df::unit * Units::GetCreature (const int32_t index) df::unit * Units::GetCreature (const int32_t index)
{ {
if (!isValid()) return NULL; if (!isValid()) return NULL;

@ -1 +1 @@
Subproject commit 7082ed13d10fb7934486362390ae1959410ca696 Subproject commit 6359571fd7d0a846b87709b55343a1a1d72f02fe

@ -43,10 +43,9 @@ DFhackCExport DFHack::command_result readFlag (Core * c, vector <string> & param
{ {
c->Suspend(); c->Suspend();
DFHack::Maps * Maps = c->getMaps();
DFHack::Gui * Gui = c->getGui(); DFHack::Gui * Gui = c->getGui();
// init the map // init the map
if(!Maps->Start()) if(!Maps::IsValid())
{ {
c->con.printerr("Can't init map. Make sure you have a map loaded in DF.\n"); c->con.printerr("Can't init map. Make sure you have a map loaded in DF.\n");
c->Resume(); c->Resume();
@ -64,7 +63,7 @@ DFhackCExport DFHack::command_result readFlag (Core * c, vector <string> & param
DFHack::DFCoord cursor = DFHack::DFCoord(cx,cy,cz); DFHack::DFCoord cursor = DFHack::DFCoord(cx,cy,cz);
MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps); MapExtras::MapCache * MCache = new MapExtras::MapCache();
DFHack::t_occupancy oc = MCache->occupancyAt(cursor); DFHack::t_occupancy oc = MCache->occupancyAt(cursor);
c->con.print("Current Value: %d\n", oc.bits.building); c->con.print("Current Value: %d\n", oc.bits.building);
@ -111,10 +110,9 @@ DFhackCExport DFHack::command_result writeFlag (Core * c, vector <string> & para
c->Suspend(); c->Suspend();
DFHack::Maps * Maps = c->getMaps();
DFHack::Gui * Gui = c->getGui(); DFHack::Gui * Gui = c->getGui();
// init the map // init the map
if(!Maps->Start()) if(!Maps::IsValid())
{ {
c->con.printerr("Can't init map. Make sure you have a map loaded in DF.\n"); c->con.printerr("Can't init map. Make sure you have a map loaded in DF.\n");
c->Resume(); c->Resume();
@ -132,7 +130,7 @@ DFhackCExport DFHack::command_result writeFlag (Core * c, vector <string> & para
DFHack::DFCoord cursor = DFHack::DFCoord(cx,cy,cz); DFHack::DFCoord cursor = DFHack::DFCoord(cx,cy,cz);
MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps); MapExtras::MapCache * MCache = new MapExtras::MapCache();
DFHack::t_occupancy oc = MCache->occupancyAt(cursor); DFHack::t_occupancy oc = MCache->occupancyAt(cursor);
oc.bits.building = value; oc.bits.building = value;

@ -15,11 +15,11 @@ using namespace DFHack;
////////////////////// //////////////////////
// START item choosers // START item choosers
////////////////////// //////////////////////
/*
class item_chooser class item_chooser
{ {
public: public:
item_chooser(Core* _c, DFHack::Items* _Items) : c(_c), Items(_Items) item_chooser(Core* _c) : c(_c)
{ {
} }
@ -31,13 +31,12 @@ public:
protected: protected:
Core *c; Core *c;
DFHack::Items *Items;
}; };
class choose_all : public item_chooser class choose_all : public item_chooser
{ {
public: public:
choose_all(Core* _c, ::Items* _Items) : item_chooser(_c, _Items) choose_all(Core* _c) : item_chooser(_c)
{ {
} }
@ -51,7 +50,7 @@ public:
class choose_unknown : public item_chooser class choose_unknown : public item_chooser
{ {
public: public:
choose_unknown(Core* _c, ::Items* _Items) : item_chooser(_c, _Items) choose_unknown(Core* _c) : item_chooser(_c)
{ {
} }
@ -66,9 +65,8 @@ public:
t_itemflags &f = itm->origin->flags; t_itemflags &f = itm->origin->flags;
return (f.unk1 || f.unk2 || f.unk3 || f.unk4 || /*f.unk5 ||*/ return (f.unk1 || f.unk2 || f.unk3 || f.unk4 ||
f.unk6 || f.unk7 || f.unk6 || f.unk7 ||
// f.unk8 || f.unk9 || /* Too common */
f.unk10 || f.unk11); f.unk10 || f.unk11);
} }
@ -263,6 +261,7 @@ DFhackCExport command_result df_dumpitems (Core * c, vector <string> & parameter
} }
} }
*/ */
/*
} }
c->Resume(); c->Resume();
@ -271,3 +270,4 @@ DFhackCExport command_result df_dumpitems (Core * c, vector <string> & parameter
return CR_OK; return CR_OK;
} }
*/

@ -9,10 +9,13 @@
#include "modules/Items.h" #include "modules/Items.h"
#include <modules/Gui.h> #include <modules/Gui.h>
#include <llimits.h> #include <llimits.h>
#include <df/caste_raw.h>
#include <df/creature_raw.h>
using std::vector; using std::vector;
using std::string; using std::string;
using namespace DFHack; using namespace DFHack;
using namespace DFHack::Simple;
//FIXME: possible race conditions with calling kittens from the IO thread and shutdown from Core. //FIXME: possible race conditions with calling kittens from the IO thread and shutdown from Core.
bool shutdown_flag = false; bool shutdown_flag = false;
bool final_flag = true; bool final_flag = true;
@ -26,12 +29,9 @@ uint64_t timeLast = 0;
DFhackCExport command_result kittens (Core * c, vector <string> & parameters); DFhackCExport command_result kittens (Core * c, vector <string> & parameters);
DFhackCExport command_result ktimer (Core * c, vector <string> & parameters); DFhackCExport command_result ktimer (Core * c, vector <string> & parameters);
DFhackCExport command_result bflags (Core * c, vector <string> & parameters);
DFhackCExport command_result trackmenu (Core * c, vector <string> & parameters); DFhackCExport command_result trackmenu (Core * c, vector <string> & parameters);
DFhackCExport command_result trackpos (Core * c, vector <string> & parameters); DFhackCExport command_result trackpos (Core * c, vector <string> & parameters);
DFhackCExport command_result mapitems (Core * c, vector <string> & parameters); DFhackCExport command_result colormods (Core * c, vector <string> & parameters);
DFhackCExport command_result test_creature_offsets (Core * c, vector <string> & parameters);
DFhackCExport command_result creat_job (Core * c, vector <string> & parameters);
DFhackCExport const char * plugin_name ( void ) DFhackCExport const char * plugin_name ( void )
{ {
@ -43,12 +43,9 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
commands.clear(); commands.clear();
commands.push_back(PluginCommand("nyan","NYAN CAT INVASION!",kittens, true)); commands.push_back(PluginCommand("nyan","NYAN CAT INVASION!",kittens, true));
commands.push_back(PluginCommand("ktimer","Measure time between game updates and console lag (toggle).",ktimer)); commands.push_back(PluginCommand("ktimer","Measure time between game updates and console lag (toggle).",ktimer));
commands.push_back(PluginCommand("blockflags","Look up block flags",bflags));
commands.push_back(PluginCommand("trackmenu","Track menu ID changes (toggle).",trackmenu)); commands.push_back(PluginCommand("trackmenu","Track menu ID changes (toggle).",trackmenu));
commands.push_back(PluginCommand("trackpos","Track mouse and designation coords (toggle).",trackpos)); commands.push_back(PluginCommand("trackpos","Track mouse and designation coords (toggle).",trackpos));
commands.push_back(PluginCommand("mapitems","Check item ids under cursor against item ids in map block.",mapitems)); commands.push_back(PluginCommand("colormods","Dump colormod vectors.",colormods));
commands.push_back(PluginCommand("test_creature_offsets","Bleh.",test_creature_offsets));
commands.push_back(PluginCommand("creat_job","Bleh.",creat_job));
return CR_OK; return CR_OK;
} }
@ -107,59 +104,6 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
return CR_OK; return CR_OK;
} }
DFhackCExport command_result mapitems (Core * c, vector <string> & parameters)
{
c->Suspend();
vector <df_item *> vec_items;
Gui * g = c-> getGui();
Maps* m = c->getMaps();
Items* it = c->getItems();
if(!m->Start())
{
c->con.printerr("No map to probe\n");
return CR_FAILURE;
}
if(!it->Start() || !it->readItemVector(vec_items))
{
c->con.printerr("Failed to get items\n");
return CR_FAILURE;
}
int32_t cx,cy,cz;
g->getCursorCoords(cx,cy,cz);
if(cx != -30000)
{
df_block * b = m->getBlock(cx/16,cy/16,cz);
if(b)
{
c->con.print("Item IDs present in block:\n");
auto iter_b = b->items.begin();
while (iter_b != b->items.end())
{
df_item * itmz = it->findItemByID(*iter_b);
string s;
itmz->getItemDescription(&s);
c->con.print("%d = %s\n",*iter_b, s.c_str());
iter_b++;
}
c->con.print("Items under cursor:\n");
auto iter_it = vec_items.begin();
while (iter_it != vec_items.end())
{
df_item * itm = *iter_it;
if(itm->x == cx && itm->y == cy && itm->z == cz)
{
string s;
itm->getItemDescription(&s,0);
c->con.print("%d = %s\n",itm->id, s.c_str());
}
iter_it ++;
}
}
}
c->Resume();
return CR_OK;
}
DFhackCExport command_result trackmenu (Core * c, vector <string> & parameters) DFhackCExport command_result trackmenu (Core * c, vector <string> & parameters)
{ {
if(trackmenu_flg) if(trackmenu_flg)
@ -189,53 +133,19 @@ DFhackCExport command_result trackpos (Core * c, vector <string> & parameters)
trackpos_flg = !trackpos_flg; trackpos_flg = !trackpos_flg;
return CR_OK; return CR_OK;
} }
DFhackCExport command_result bflags (Core * c, vector <string> & parameters)
DFhackCExport command_result colormods (Core * c, vector <string> & parameters)
{ {
c->Suspend(); c->Suspend();
Gui * g = c-> getGui(); auto & vec = df::global::world->raws.creatures.alphabetic;
Maps* m = c->getMaps(); for(int i = 0; i < vec.size();i++)
if(!m->Start())
{
c->con.printerr("No map to probe\n");
return CR_FAILURE;
}
int32_t cx,cy,cz;
g->getCursorCoords(cx,cy,cz);
if(cx == -30000)
{
// get map size in blocks
uint32_t sx,sy,sz;
m->getSize(sx,sy,sz);
std::map <uint8_t, df_block *> counts;
// for each block
for(size_t x = 0; x < sx; x++)
for(size_t y = 0; y < sx; y++)
for(size_t z = 0; z < sx; z++)
{
df_block * b = m->getBlock(x,y,z);
if(!b) continue;
auto iter = counts.find(b->flags.size);
if(iter == counts.end())
{
counts[b->flags.bits[0]] = b;
}
}
for(auto iter = counts.begin(); iter != counts.end(); iter++)
{
c->con.print("%2x : 0x%x\n",iter->first, iter->second);
}
}
else
{ {
df_block * b = m->getBlock(cx/16,cy/16,cz); df::creature_raw* rawlion = vec[i];
if(b) df::caste_raw * caste = rawlion->caste[0];
c->con.print("%s\nCaste addr 0x%x\n",rawlion->creature_id.c_str(), &caste->color_modifiers);
for(int j = 0; j < caste->color_modifiers.size();j++)
{ {
c->con << "Block flags:" << b->flags << std::endl; c->con.print("mod %d: 0x%x\n", j, caste->color_modifiers[j]);
}
else
{
c->con.printerr("No block here\n");
return CR_FAILURE;
} }
} }
c->Resume(); c->Resume();
@ -328,71 +238,3 @@ DFhackCExport command_result kittens (Core * c, vector <string> & parameters)
color = Console::COLOR_BLUE; color = Console::COLOR_BLUE;
} }
} }
#include "modules/Units.h"
#include "VersionInfo.h"
#include <stddef.h>
command_result test_creature_offsets(Core* c, vector< string >& parameters)
{
uint32_t off_vinfo = c->vinfo->getGroup("Creatures")->getGroup("creature")->/*getGroup("advanced")->*/getOffset("custom_profession");
uint32_t off_struct = offsetof(df_unit,custom_profession);
c->con.print("Struct 0x%x, vinfo 0x%x\n", off_struct, off_vinfo);
return CR_OK;
};
command_result creat_job (Core * c, vector< string >& parameters)
{
c->Suspend();
Units * cr = c->getUnits();
Gui * g = c-> getGui();
uint32_t num_cr = 0;
int32_t cx,cy,cz;
g->getCursorCoords(cx,cy,cz);
if(cx == -30000)
{
c->con.printerr("No cursor.\n");
c->Resume();
return CR_FAILURE;
}
if(!cr->Start(num_cr) || num_cr == 0)
{
c->con.printerr("No creatures.\n");
c->Resume();
return CR_FAILURE;
}
auto iter = cr->creatures->begin();
while (iter != cr->creatures->end())
{
df_unit * unit = *iter;
if(cx == unit->x && cy == unit->y && cz == unit->z)
{
c->con.print("%d:%s - address 0x%x - job 0x%x\n"
"Soul: 0x%x, likes: 0x%x\n",
unit->id,
unit->name.first_name.c_str(),
unit,
uint32_t(unit) + offsetof(df_unit,current_job),
uint32_t(unit) + offsetof(df_unit,current_soul),
uint32_t(unit->current_soul) + offsetof(df_soul,likes)
);
df_soul * s = unit->current_soul;
if(s)
{
c->con.print("LIKES:\n");
int idx = 1;
auto iter = s->likes.begin();
while(iter != s->likes.end())
{
df_like * l = *iter;
c->con.print("%3d: %f\n", idx, float(l->mystery));
iter++;
idx++;
}
}
}
iter++;
}
c->Resume();
return CR_OK;
};

@ -6,7 +6,7 @@
#include <string> #include <string>
#include <modules/Materials.h> #include <modules/Materials.h>
#include <stdlib.h> #include <stdlib.h>
/*
using std::vector; using std::vector;
using std::string; using std::string;
using namespace DFHack; using namespace DFHack;
@ -136,4 +136,4 @@ DFhackCExport command_result rawdump_p (Core * c, vector <string> & parameters)
c->Resume(); c->Resume();
return CR_OK; return CR_OK;
} }
*/

@ -1 +1 @@
Subproject commit c114ec5f995aec69631187212254309464f82775 Subproject commit 23fbb78edaff35a62887803e178a24f9148ffc84

@ -39,7 +39,7 @@ LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS})
#Generate sources from our proto files and store them in the source tree #Generate sources from our proto files and store them in the source tree
ADD_CUSTOM_COMMAND( ADD_CUSTOM_COMMAND(
OUTPUT ${PROJECT_PROTO_SRCS} ${PROJECT_PROTO_HDRS} OUTPUT ${PROJECT_PROTO_SRCS} ${PROJECT_PROTO_HDRS}
COMMAND protoc-bin -I=${CMAKE_CURRENT_SOURCE_DIR}/proto --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/proto ${PROJECT_PROTOS} COMMAND protoc-bin -I=${CMAKE_CURRENT_SOURCE_DIR}/proto/ --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/proto/ ${PROJECT_PROTOS}
DEPENDS protoc-bin ${PROJECT_PROTOS} DEPENDS protoc-bin ${PROJECT_PROTOS}
) )

@ -12,6 +12,8 @@ using namespace DFHack;
#include "proto/Map.pb.h" #include "proto/Map.pb.h"
using namespace DFHack::Simple;
DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & parameters); DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & parameters);
DFhackCExport const char * plugin_name ( void ) DFhackCExport const char * plugin_name ( void )
@ -67,6 +69,11 @@ DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & pa
MapExtras::MapCache map; MapExtras::MapCache map;
DFHack::Materials *mats = c->getMaterials(); DFHack::Materials *mats = c->getMaterials();
if (!Vegetation::isValid())
{
c->con.printerr("Unable to read vegetation; plants won't be listed!\n" );
}
dfproto::Map protomap; dfproto::Map protomap;
protomap.set_x_size(x_max); protomap.set_x_size(x_max);
protomap.set_y_size(y_max); protomap.set_y_size(y_max);

@ -1 +1 @@
Subproject commit 92627e39cb3502812cd5a131716d3d1da8ef625a Subproject commit 66115070844f3bc1ae3f9142e43f7c110aa18159