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 }, {"damaged obsidian wall",WALL,OBSIDIAN,VAR_1, TILE_DAMAGED },
// 330 // 330
{"worn obsidian wall",WALL,OBSIDIAN,VAR_1}, {"worn obsidian wall",WALL,OBSIDIAN,VAR_1, TILE_WORN},
{"obsidian wall",WALL,OBSIDIAN,VAR_1}, {"obsidian wall",WALL,OBSIDIAN,VAR_1},
{"cracked featstone wall",WALL,FEATSTONE,VAR_1, TILE_CRACKED }, {"cracked featstone wall",WALL,FEATSTONE,VAR_1, TILE_CRACKED },
{"damaged featstone wall",WALL,FEATSTONE,VAR_1, TILE_DAMAGED }, {"damaged featstone wall",WALL,FEATSTONE,VAR_1, TILE_DAMAGED },

@ -17,8 +17,12 @@ using MapExtras::MapCache;
typedef std::map <DFCoord, uint32_t> coordmap; 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::ContextManager CM ("Memory.xml");
DFHack::Context * DF; DFHack::Context * DF;
@ -74,27 +78,30 @@ int main ()
int dumped_total = 0; int dumped_total = 0;
int cx, cy, cz; int cx, cy, cz;
DFCoord pos_cursor;
if (!Gui->getCursorCoords(cx,cy,cz)) if(!destroy)
{
cerr << "Cursor position not found. Please enabled the cursor." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFCoord pos_cursor(cx,cy,cz);
{ {
Block * b = MC.BlockAt(pos_cursor / 16); if (!Gui->getCursorCoords(cx,cy,cz))
if(!b)
{ {
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 #ifndef LINUX_BUILD
cin.ignore(); cin.ignore();
#endif #endif
return 1; 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; coordmap counts;
// proceed with the dumpification operation // proceed with the dumpification operation
@ -121,53 +128,62 @@ int main ()
if (!temp.base.flags.dump || !temp.base.flags.on_ground) if (!temp.base.flags.dump || !temp.base.flags.on_ground)
continue; continue;
// Change flags to indicate the dump was completed, as if by super-dwarfs if(!destroy) // move to cursor
temp.base.flags.dump = 0; {
temp.base.flags.forbid = 1; // Change flags to indicate the dump was completed, as if by super-dwarfs
temp.base.flags.dump = false;
// Don't move items if they're already at the cursor temp.base.flags.forbid = true;
if (pos_cursor == pos_item)
continue; // Don't move items if they're already at the cursor
if (pos_cursor == pos_item)
// Move the item continue;
temp.base.x = pos_cursor.x;
temp.base.y = pos_cursor.y; // Move the item
temp.base.z = pos_cursor.z; 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); Items->writeItem(temp);
// keeping track of item pile sizes ;) // keeping track of item pile sizes ;)
it->second --; it->second --;
dumped_total++; dumped_total++;
} }
// for each item pile, see if it reached zero. if so, unset item flag on the tile it's on if(!destroy) // TODO: do we have to do any of this when destroying items?
coordmap::iterator it = counts.begin();
coordmap::iterator end = counts.end();
while(it != end)
{ {
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); if(it->second == 0)
occ.bits.item = false; {
MC.setOccupancyAt(it->first, occ); 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)
// 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)
{ {
t_occupancy occ = MC.occupancyAt(pos_cursor); // assume there is a possibility the cursor points at some weird location with missing block data
occ.bits.item = 1; Block * b = MC.BlockAt(pos_cursor / 16);
MC.setOccupancyAt(pos_cursor,occ); 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(); DF->Detach();
cout << "Done. " << dumped_total << " items quickdumped." << endl; cout << "Done. " << dumped_total << " items quickdumped." << endl;
#ifndef LINUX_BUILD #ifndef LINUX_BUILD