Update jobs when committing MapCache changes

The map_block->designation.{dig,smooth} are reset to zeros when a job
posting is created for the designation. The job is then used to override
the designation state in the map_block. To make the new designation set
propogate to jobs the job structure would require updating. The update
would be possible a complex operation. The simple alternative is to
remove the job and let df create a new job in the next tick.

Fixes #1229
develop
Pauli 2018-06-18 15:53:13 +03:00
parent 6a151353e3
commit 1b5ec7ce69
2 changed files with 48 additions and 17 deletions

@ -38,6 +38,8 @@ distribution.
#include "df/item.h"
#include "df/inclusion_type.h"
#include <bitset>
namespace df {
struct world_region_details;
}
@ -265,14 +267,17 @@ public:
{
return index_tile(designation,p);
}
bool setDesignationAt(df::coord2d p, df::tile_designation des)
bool setDesignationAt(df::coord2d p, df::tile_designation des, int32_t priority = 4000)
{
if(!valid) return false;
dirty_designations = true;
designated_tiles[(p.x&15) + (p.y&15)*16] = true;
//printf("setting block %d/%d/%d , %d %d\n",x,y,z, p.x, p.y);
index_tile(designation,p) = des;
if(des.bits.dig && block)
if((des.bits.dig || des.bits.smooth) && block) {
block->flags.bits.designated = true;
setPriorityAt(p, priority);
}
return true;
}
@ -342,13 +347,15 @@ private:
void init();
bool valid;
bool valid:1;
bool dirty_designations:1;
bool dirty_tiles:1;
bool dirty_veins:1;
bool dirty_temperatures:1;
bool dirty_occupancies:1;
std::bitset<16*16> designated_tiles;
DFCoord bcoord;
// Custom tags for floodfill
@ -548,13 +555,11 @@ class DFHACK_EXPORT MapCache
return b ? b->DesignationAt(tilecoord) : df::tile_designation();
}
// priority is optional, only set if >= 0
bool setDesignationAt (DFCoord tilecoord, df::tile_designation des, int32_t priority = -1)
bool setDesignationAt (DFCoord tilecoord, df::tile_designation des, int32_t priority = 4000)
{
if (Block *b = BlockAtTile(tilecoord))
{
if (!b->setDesignationAt(tilecoord, des))
return false;
if (priority >= 0 && b->setPriorityAt(tilecoord, priority))
if (!b->setDesignationAt(tilecoord, des, priority))
return false;
return true;
}
@ -599,15 +604,8 @@ class DFHACK_EXPORT MapCache
return b ? b->removeItemOnGround(item) : false;
}
bool WriteAll()
{
std::map<DFCoord, Block *>::iterator p;
for(p = blocks.begin(); p != blocks.end(); p++)
{
p->second->Write();
}
return true;
}
bool WriteAll();
void trash()
{
std::map<DFCoord, Block *>::iterator p;

@ -45,6 +45,7 @@ using namespace std;
#include "modules/Buildings.h"
#include "modules/MapCache.h"
#include "modules/Maps.h"
#include "modules/Job.h"
#include "modules/Materials.h"
#include "df/block_burrow.h"
@ -57,6 +58,7 @@ using namespace std;
#include "df/burrow.h"
#include "df/feature_init.h"
#include "df/flow_info.h"
#include "df/job.h"
#include "df/plant.h"
#include "df/plant_tree_info.h"
#include "df/plant_tree_tile.h"
@ -91,7 +93,9 @@ const BiomeInfo MapCache::biome_stub = {
#define COPY(a,b) memcpy(&a,&b,sizeof(a))
MapExtras::Block::Block(MapCache *parent, DFCoord _bcoord) : parent(parent)
MapExtras::Block::Block(MapCache *parent, DFCoord _bcoord) :
parent(parent),
designated_tiles{}
{
dirty_designations = false;
dirty_tiles = false;
@ -1250,6 +1254,35 @@ MapExtras::MapCache::MapCache()
}
}
bool MapExtras::MapCache::WriteAll()
{
auto world = df::global::world;
df::job_list_link* job_link = world->jobs.list.next;
df::job_list_link* next = nullptr;
for (;job_link;job_link = next) {
next = job_link->next;
df::job* job = job_link->item;
df::coord pos = job->pos;
df::coord blockpos(pos.x>>4,pos.y>>4,pos.z);
auto iter = blocks.find(blockpos);
if (iter == blocks.end())
continue;
df::coord2d bpos(pos.x - (blockpos.x<<4),pos.y - (blockpos.y<<4));
auto block = iter->second;
if (!block->designated_tiles.test(bpos.x+bpos.y*16))
continue;
// Remove designation job. DF will create a new one in the next tick
// processing.
Job::removeJob(job);
}
std::map<DFCoord, Block *>::iterator p;
for(p = blocks.begin(); p != blocks.end(); p++)
{
p->second->Write();
}
return true;
}
MapExtras::Block *MapExtras::MapCache::BlockAt(DFCoord blockcoord)
{
if(!valid)