Untested item deletion mode for the autodump tool.

develop
Petr Mrázek 2011-04-30 04:48:28 +02:00
parent 456a979244
commit 3318487ad9
2 changed files with 68 additions and 52 deletions

@ -404,7 +404,7 @@ namespace DFHack
{"damaged obsidian wall",WALL,OBSIDIAN,VAR_1, TILE_DAMAGED },
// 330
{"worn obsidian wall",WALL,OBSIDIAN,VAR_1},
{"worn obsidian wall",WALL,OBSIDIAN,VAR_1, TILE_WORN},
{"obsidian wall",WALL,OBSIDIAN,VAR_1},
{"cracked featstone wall",WALL,FEATSTONE,VAR_1, TILE_CRACKED },
{"damaged featstone wall",WALL,FEATSTONE,VAR_1, TILE_DAMAGED },

@ -17,8 +17,12 @@ using MapExtras::MapCache;
typedef std::map <DFCoord, uint32_t> coordmap;
int main ()
int main (int argc, char * argv[])
{
// Command line options
bool destroy = false;
if(argc > 1 && strcmp(argv[1],"-d") == 0)
destroy = true;
DFHack::ContextManager CM ("Memory.xml");
DFHack::Context * DF;
@ -74,27 +78,30 @@ int main ()
int dumped_total = 0;
int cx, cy, cz;
if (!Gui->getCursorCoords(cx,cy,cz))
{
cerr << "Cursor position not found. Please enabled the cursor." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFCoord pos_cursor(cx,cy,cz);
DFCoord pos_cursor;
if(!destroy)
{
Block * b = MC.BlockAt(pos_cursor / 16);
if(!b)
if (!Gui->getCursorCoords(cx,cy,cz))
{
cerr << "Cursor is in an invalid area. Place it over something save first." << endl;
cerr << "Cursor position not found. Please enabled the cursor." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
// TODO: check if the target is floor? maybe?
pos_cursor = DFCoord(cx,cy,cz);
{
Block * b = MC.BlockAt(pos_cursor / 16);
if(!b)
{
cerr << "Cursor is in an invalid area. Place it over something save first." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
// TODO: check if the target is floor? maybe?
}
}
coordmap counts;
// proceed with the dumpification operation
@ -121,53 +128,62 @@ int main ()
if (!temp.base.flags.dump || !temp.base.flags.on_ground)
continue;
// Change flags to indicate the dump was completed, as if by super-dwarfs
temp.base.flags.dump = 0;
temp.base.flags.forbid = 1;
// Don't move items if they're already at the cursor
if (pos_cursor == pos_item)
continue;
// Move the item
temp.base.x = pos_cursor.x;
temp.base.y = pos_cursor.y;
temp.base.z = pos_cursor.z;
if(!destroy) // move to cursor
{
// Change flags to indicate the dump was completed, as if by super-dwarfs
temp.base.flags.dump = false;
temp.base.flags.forbid = true;
// Don't move items if they're already at the cursor
if (pos_cursor == pos_item)
continue;
// Move the item
temp.base.x = pos_cursor.x;
temp.base.y = pos_cursor.y;
temp.base.z = pos_cursor.z;
}
else // destroy
{
temp.base.flags.garbage_colect = true;
}
Items->writeItem(temp);
// keeping track of item pile sizes ;)
it->second --;
dumped_total++;
}
// for each item pile, see if it reached zero. if so, unset item flag on the tile it's on
coordmap::iterator it = counts.begin();
coordmap::iterator end = counts.end();
while(it != end)
if(!destroy) // TODO: do we have to do any of this when destroying items?
{
if(it->second == 0)
// for each item pile, see if it reached zero. if so, unset item flag on the tile it's on
coordmap::iterator it = counts.begin();
coordmap::iterator end = counts.end();
while(it != end)
{
t_occupancy occ = MC.occupancyAt(it->first);
occ.bits.item = false;
MC.setOccupancyAt(it->first, occ);
if(it->second == 0)
{
t_occupancy occ = MC.occupancyAt(it->first);
occ.bits.item = false;
MC.setOccupancyAt(it->first, occ);
}
it++;
}
it++;
}
// Set "item here" flag on target tile, if we moved any items to the target tile.
if (dumped_total > 0)
{
// assume there is a possibility the cursor points at some weird location with missing block data
Block * b = MC.BlockAt(pos_cursor / 16);
if(b)
// Set "item here" flag on target tile, if we moved any items to the target tile.
if (dumped_total > 0)
{
t_occupancy occ = MC.occupancyAt(pos_cursor);
occ.bits.item = 1;
MC.setOccupancyAt(pos_cursor,occ);
// assume there is a possibility the cursor points at some weird location with missing block data
Block * b = MC.BlockAt(pos_cursor / 16);
if(b)
{
t_occupancy occ = MC.occupancyAt(pos_cursor);
occ.bits.item = 1;
MC.setOccupancyAt(pos_cursor,occ);
}
}
// write map changes back to DF.
MC.WriteAll();
// Is this necessary? Is "forbid" a dirtyable attribute like "dig" is?
Maps->WriteDirtyBit(cx/16, cy/16, cz, true);
}
// write map changes back to DF.
MC.WriteAll();
// Is this necessary? Is "forbid" a dirtyable attribute like "dig" is?
Maps->WriteDirtyBit(cx/16, cy/16, cz, true);
DF->Detach();
cout << "Done. " << dumped_total << " items quickdumped." << endl;
#ifndef LINUX_BUILD