Revises job scanning for dig-now

develop
Josh Cooper 2023-02-15 13:03:31 -08:00 committed by Josh Cooper
parent 1e21f1ece9
commit 8beb947c82
1 changed files with 49 additions and 25 deletions

@ -54,6 +54,7 @@ struct designation{
df::coord pos; df::coord pos;
df::tile_designation type; df::tile_designation type;
df::tile_occupancy occupancy; df::tile_occupancy occupancy;
designation() = default;
designation(const df::coord &c, const df::tile_designation &td, const df::tile_occupancy &to) : pos(c), type(td), occupancy(to) {} designation(const df::coord &c, const df::tile_designation &td, const df::tile_occupancy &to) : pos(c), type(td), occupancy(to) {}
bool operator==(const designation &rhs) const { bool operator==(const designation &rhs) const {
@ -75,40 +76,62 @@ namespace std {
}; };
} }
class DigJobs { class DesignationJobs {
private: private:
std::unordered_map<df::coord, df::tile_dig_designation> designations; std::unordered_map<df::coord, designation> designations;
std::unordered_map<df::coord, df::job*> jobs; std::unordered_map<df::coord, df::job*> jobs;
public: public:
void load() { void load(MapExtras::MapCache &map) {
designations.clear(); designations.clear();
df::job_list_link* node = df::global::world->jobs.list.next; df::job_list_link* node = df::global::world->jobs.list.next;
while (node) { while (node) {
df::job* job = node->item; df::job* job = node->item;
jobs.emplace(job->pos, job); jobs.emplace(job->pos, job);
node = node->next; node = node->next;
df::tile_designation td = map.designationAt(job->pos);
df::tile_occupancy to = map.occupancyAt(job->pos);
const auto ctd = td.whole;
const auto cto = to.whole;
switch (job->job_type){ switch (job->job_type){
case df::enums::job_type::Dig: case job_type::Dig:
designations.emplace(job->pos, df::tile_dig_designation::Default); td.bits.dig = tile_dig_designation::Default;
break; break;
case df::enums::job_type::DigChannel: case job_type::DigChannel:
designations.emplace(job->pos, df::tile_dig_designation::Channel); td.bits.dig = tile_dig_designation::Channel;
break; break;
case df::enums::job_type::CarveRamp: case job_type::CarveRamp:
designations.emplace(job->pos, df::tile_dig_designation::Ramp); td.bits.dig = tile_dig_designation::Ramp;
break; break;
case df::enums::job_type::CarveUpwardStaircase: case job_type::CarveUpwardStaircase:
designations.emplace(job->pos, df::tile_dig_designation::UpStair); td.bits.dig = tile_dig_designation::UpStair;
break; break;
case df::enums::job_type::CarveDownwardStaircase: case job_type::CarveDownwardStaircase:
designations.emplace(job->pos, df::tile_dig_designation::DownStair); td.bits.dig = tile_dig_designation::DownStair;
break; break;
case df::enums::job_type::CarveUpDownStaircase: case job_type::CarveUpDownStaircase:
designations.emplace(job->pos, df::tile_dig_designation::UpDownStair); td.bits.dig = tile_dig_designation::UpDownStair;
break;
case job_type::DetailWall:
case job_type::DetailFloor: {
df::tiletype tt = map.tiletypeAt(job->pos);
if (tileSpecial(tt) != df::tiletype_special::SMOOTH) {
td.bits.smooth = 1;
}
break;
}
case job_type::CarveTrack:
to.bits.carve_track_north = 0 < (job->item_category.whole & 18);
to.bits.carve_track_south = 0 < (job->item_category.whole & 19);
to.bits.carve_track_west = 0 < (job->item_category.whole & 20);
to.bits.carve_track_east = 0 < (job->item_category.whole & 21);
break; break;
default: default:
break; break;
} }
if (ctd != td.whole || cto != to.whole) {
// we found a designation job
designations.emplace(job->pos, designation(job->pos, td, to));
}
} }
} }
void remove(const df::coord &pos) { void remove(const df::coord &pos) {
@ -117,11 +140,14 @@ public:
jobs.erase(pos); jobs.erase(pos);
} }
} }
df::tile_dig_designation get(const df::coord &pos) { designation get(const df::coord &pos) {
if (designations.count(pos)) { if (designations.count(pos)) {
return designations[pos]; return designations[pos];
} }
return df::enums::tile_dig_designation::No; return {};
}
bool count(const df::coord &pos) {
return jobs.count(pos);
} }
}; };
@ -705,9 +731,9 @@ static void do_dig(color_ostream &out, std::vector<DFCoord> &dug_coords,
item_coords_t &item_coords, const dig_now_options &options) { item_coords_t &item_coords, const dig_now_options &options) {
MapExtras::MapCache map; MapExtras::MapCache map;
Random::MersenneRNG rng; Random::MersenneRNG rng;
DigJobs jobs; DesignationJobs jobs;
jobs.load(); jobs.load(map);
rng.init(); rng.init();
std::unordered_set<designation> buffer; std::unordered_set<designation> buffer;
@ -723,13 +749,11 @@ static void do_dig(color_ostream &out, std::vector<DFCoord> &dug_coords,
DFCoord pos(x, y, z); DFCoord pos(x, y, z);
df::tile_designation td = map.designationAt(pos); df::tile_designation td = map.designationAt(pos);
df::tile_occupancy to = map.occupancyAt(pos); df::tile_occupancy to = map.occupancyAt(pos);
if (jobs.get(pos) != df::enums::tile_dig_designation::No) { if (jobs.count(pos)) {
// todo: check if the designation is removed from the map buffer.emplace(jobs.get(pos));
jobs.remove(pos); jobs.remove(pos);
// if it does get removed, then we're gonna buffer the jobs info then remove the job // if it does get removed, then we're gonna buffer the jobs info then remove the job
} } else if ((td.bits.dig != df::tile_dig_designation::No && !to.bits.dig_marked)
if ((td.bits.dig != df::tile_dig_designation::No && !to.bits.dig_marked)
|| td.bits.smooth == 1 || td.bits.smooth == 1
|| to.bits.carve_track_north == 1 || to.bits.carve_track_north == 1
|| to.bits.carve_track_east == 1 || to.bits.carve_track_east == 1
@ -772,7 +796,7 @@ static void do_dig(color_ostream &out, std::vector<DFCoord> &dug_coords,
// todo: check mark mode of smooth designations // todo: check mark mode of smooth designations
} else if (td.bits.smooth == 1) { } else if (td.bits.smooth == 1) {
if (smooth_tile(out, map, pos)) { if (smooth_tile(out, map, pos)) {
to = map.occupancyAt(pos); td = map.designationAt(pos);
td.bits.smooth = 0; td.bits.smooth = 0;
map.setDesignationAt(pos, td); map.setDesignationAt(pos, td);
} }