From 57fbb1004b0c79fcd350a5a3a064f05b1f26c7ba Mon Sep 17 00:00:00 2001 From: Quietust Date: Wed, 23 Apr 2014 08:23:34 -0500 Subject: [PATCH] Assorted cleanup --- library/modules/EventManager.cpp | 9 +++------ library/modules/Items.cpp | 2 +- library/modules/Job.cpp | 24 +++++++----------------- library/modules/Maps.cpp | 12 ++++++------ 4 files changed, 17 insertions(+), 30 deletions(-) diff --git a/library/modules/EventManager.cpp b/library/modules/EventManager.cpp index bfc7c4907..88f4d56d6 100644 --- a/library/modules/EventManager.cpp +++ b/library/modules/EventManager.cpp @@ -30,6 +30,7 @@ using namespace std; using namespace DFHack; using namespace EventManager; +using namespace df::enums; /* * TODO: @@ -322,12 +323,8 @@ static void manageJobInitiatedEvent(color_ostream& out) { //helper function for manageJobCompletedEvent static int32_t getWorkerID(df::job* job) { - for ( size_t a = 0; a < job->general_refs.size(); a++ ) { - if ( job->general_refs[a]->getType() != df::enums::general_ref_type::UNIT_WORKER ) - continue; - return ((df::general_ref_unit_workerst*)job->general_refs[a])->unit_id; - } - return -1; + auto ref = findRef(job->general_refs, general_ref_type::UNIT_WORKER); + return ref ? ref->getID() : -1; } /* diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index 6673e6f1b..b243e5d85 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -534,7 +534,7 @@ bool Items::setOwner(df::item *item, df::unit *unit) { df::general_ref *ref = item->general_refs[i]; - if (!strict_virtual_cast(ref)) + if (ref->getType() != general_ref_type::UNIT_ITEMOWNER) continue; if (auto cur = ref->getUnit()) diff --git a/library/modules/Job.cpp b/library/modules/Job.cpp index 8750db4c7..1cfc0fa78 100644 --- a/library/modules/Job.cpp +++ b/library/modules/Job.cpp @@ -93,7 +93,7 @@ df::job *DFHack::Job::cloneJobStruct(df::job *job, bool keepEverything) pnew->job_items[a] = new df::job_item(*pnew->job_items[a]); for ( size_t a = 0; a < job->general_refs.size(); a++ ) - if ( keepEverything || job->general_refs[a]->getType() != df::enums::general_ref_type::UNIT_WORKER ) + if ( keepEverything || job->general_refs[a]->getType() != general_ref_type::UNIT_WORKER ) pnew->general_refs.push_back(job->general_refs[a]->clone()); return pnew; @@ -265,28 +265,18 @@ df::building *DFHack::Job::getHolder(df::job *job) { CHECK_NULL_POINTER(job); - for (size_t i = 0; i < job->general_refs.size(); i++) - { - VIRTUAL_CAST_VAR(ref, df::general_ref_building_holderst, job->general_refs[i]); - if (ref) - return ref->getBuilding(); - } + auto ref = getGeneralRef(job, general_ref_type::BUILDING_HOLDER); - return NULL; + return ref ? ref->getBuilding() : NULL; } df::unit *DFHack::Job::getWorker(df::job *job) { CHECK_NULL_POINTER(job); - for (size_t i = 0; i < job->general_refs.size(); i++) - { - VIRTUAL_CAST_VAR(ref, df::general_ref_unit_workerst, job->general_refs[i]); - if (ref) - return ref->getUnit(); - } + auto ref = getGeneralRef(job, general_ref_type::UNIT_WORKER); - return NULL; + return ref ? ref->getUnit() : NULL; } void DFHack::Job::setJobCooldown(df::building *workshop, df::unit *worker, int cooldown) @@ -326,8 +316,8 @@ bool DFHack::Job::removeWorker(df::job *job, int cooldown) for (size_t i = 0; i < job->general_refs.size(); i++) { - VIRTUAL_CAST_VAR(ref, df::general_ref_unit_workerst, job->general_refs[i]); - if (!ref) + df::general_ref *ref = job->general_refs[i]; + if (ref->getType() != general_ref_type::UNIT_WORKER) continue; auto worker = ref->getUnit(); diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 655371091..fd1ccc523 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -584,8 +584,8 @@ bool Maps::canStepBetween(df::coord pos1, df::coord pos2) if ( dx == 0 && dy == 0 ) { //check for forbidden hatches and floors and such - df::enums::tile_building_occ::tile_building_occ upOcc = index_tile(block2->occupancy,pos2).bits.building; - if ( upOcc == df::enums::tile_building_occ::Impassable || upOcc == df::enums::tile_building_occ::Obstacle || upOcc == df::enums::tile_building_occ::Floored ) + df::tile_building_occ upOcc = index_tile(block2->occupancy,pos2).bits.building; + if ( upOcc == tile_building_occ::Impassable || upOcc == tile_building_occ::Obstacle || upOcc == tile_building_occ::Floored ) return false; if ( shape1 == tiletype_shape::STAIR_UPDOWN && shape2 == shape1 ) @@ -617,7 +617,7 @@ bool Maps::canStepBetween(df::coord pos1, df::coord pos2) return false; //unusable ramp //there has to be an unforbidden hatch above the ramp - if ( index_tile(block2->occupancy,pos2).bits.building != df::enums::tile_building_occ::Dynamic ) + if ( index_tile(block2->occupancy,pos2).bits.building != tile_building_occ::Dynamic ) return false; //note that forbidden hatches have Floored occupancy. unforbidden ones have dynamic occupancy df::building* building = Buildings::findAtTile(pos2); @@ -625,7 +625,7 @@ bool Maps::canStepBetween(df::coord pos1, df::coord pos2) out << __FILE__ << ", line " << __LINE__ << ": couldn't find hatch.\n"; return false; } - if ( building->getType() != df::enums::building_type::Hatch ) { + if ( building->getType() != building_type::Hatch ) { return false; } return true; @@ -661,8 +661,8 @@ bool Maps::canStepBetween(df::coord pos1, df::coord pos2) if ( !blockUp ) return false; - df::enums::tile_building_occ::tile_building_occ occupancy = index_tile(blockUp->occupancy,up).bits.building; - if ( occupancy == df::enums::tile_building_occ::Obstacle || occupancy == df::enums::tile_building_occ::Floored || occupancy == df::enums::tile_building_occ::Impassable ) + df::tile_building_occ occupancy = index_tile(blockUp->occupancy,up).bits.building; + if ( occupancy == tile_building_occ::Obstacle || occupancy == tile_building_occ::Floored || occupancy == tile_building_occ::Impassable ) return false; return true; }