autochop: Fix marking/unmarking trees (use Designations module)

Fixes #656
Fixes #1076
Closes #1030
develop
lethosor 2017-05-04 21:51:16 -04:00
parent 1e469453fc
commit a527091172
1 changed files with 23 additions and 26 deletions

@ -10,24 +10,26 @@
#include "DataDefs.h"
#include "TileTypes.h"
#include "df/world.h"
#include "df/map_block.h"
#include "df/tile_dig_designation.h"
#include "df/plant_raw.h"
#include "df/plant.h"
#include "df/ui.h"
#include "df/burrow.h"
#include "df/item_flags.h"
#include "df/item.h"
#include "df/item_flags.h"
#include "df/items_other_id.h"
#include "df/job.h"
#include "df/map_block.h"
#include "df/plant.h"
#include "df/plant_raw.h"
#include "df/tile_dig_designation.h"
#include "df/ui.h"
#include "df/viewscreen_dwarfmodest.h"
#include "df/world.h"
#include "modules/Screen.h"
#include "modules/Maps.h"
#include "modules/Burrows.h"
#include "modules/World.h"
#include "modules/MapCache.h"
#include "modules/Designations.h"
#include "modules/Gui.h"
#include "modules/MapCache.h"
#include "modules/Maps.h"
#include "modules/Screen.h"
#include "modules/World.h"
#include <set>
@ -228,38 +230,33 @@ static int do_chop_designation(bool chop, bool count_only)
if (!count_only && !watchedBurrows.isValidPos(plant->pos))
continue;
bool dirty = false;
if (chop && cur->designation[x][y].bits.dig == tile_dig_designation::No)
if (chop && !Designations::isPlantMarked(plant))
{
if (count_only)
{
++count;
if (Designations::canMarkPlant(plant))
count++;
}
else
{
cur->designation[x][y].bits.dig = tile_dig_designation::Default;
dirty = true;
if (Designations::markPlant(plant))
count++;
}
}
if (!chop && cur->designation[x][y].bits.dig == tile_dig_designation::Default)
if (!chop && Designations::isPlantMarked(plant))
{
if (count_only)
{
++count;
if (Designations::canUnmarkPlant(plant))
count++;
}
else
{
cur->designation[x][y].bits.dig = tile_dig_designation::No;
dirty = true;
if (Designations::unmarkPlant(plant))
count++;
}
}
if (dirty)
{
cur->flags.bits.designated = true;
++count;
}
}
return count;