Assorted cleanup

develop
Quietust 2014-04-23 08:23:34 -05:00
parent c3d45c3a1e
commit 57fbb1004b
4 changed files with 17 additions and 30 deletions

@ -30,6 +30,7 @@
using namespace std; using namespace std;
using namespace DFHack; using namespace DFHack;
using namespace EventManager; using namespace EventManager;
using namespace df::enums;
/* /*
* TODO: * TODO:
@ -322,12 +323,8 @@ static void manageJobInitiatedEvent(color_ostream& out) {
//helper function for manageJobCompletedEvent //helper function for manageJobCompletedEvent
static int32_t getWorkerID(df::job* job) { static int32_t getWorkerID(df::job* job) {
for ( size_t a = 0; a < job->general_refs.size(); a++ ) { auto ref = findRef(job->general_refs, general_ref_type::UNIT_WORKER);
if ( job->general_refs[a]->getType() != df::enums::general_ref_type::UNIT_WORKER ) return ref ? ref->getID() : -1;
continue;
return ((df::general_ref_unit_workerst*)job->general_refs[a])->unit_id;
}
return -1;
} }
/* /*

@ -534,7 +534,7 @@ bool Items::setOwner(df::item *item, df::unit *unit)
{ {
df::general_ref *ref = item->general_refs[i]; df::general_ref *ref = item->general_refs[i];
if (!strict_virtual_cast<df::general_ref_unit_itemownerst>(ref)) if (ref->getType() != general_ref_type::UNIT_ITEMOWNER)
continue; continue;
if (auto cur = ref->getUnit()) if (auto cur = ref->getUnit())

@ -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]); pnew->job_items[a] = new df::job_item(*pnew->job_items[a]);
for ( size_t a = 0; a < job->general_refs.size(); 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()); pnew->general_refs.push_back(job->general_refs[a]->clone());
return pnew; return pnew;
@ -265,28 +265,18 @@ df::building *DFHack::Job::getHolder(df::job *job)
{ {
CHECK_NULL_POINTER(job); CHECK_NULL_POINTER(job);
for (size_t i = 0; i < job->general_refs.size(); i++) auto ref = getGeneralRef(job, general_ref_type::BUILDING_HOLDER);
{
VIRTUAL_CAST_VAR(ref, df::general_ref_building_holderst, job->general_refs[i]);
if (ref)
return ref->getBuilding();
}
return NULL; return ref ? ref->getBuilding() : NULL;
} }
df::unit *DFHack::Job::getWorker(df::job *job) df::unit *DFHack::Job::getWorker(df::job *job)
{ {
CHECK_NULL_POINTER(job); CHECK_NULL_POINTER(job);
for (size_t i = 0; i < job->general_refs.size(); i++) auto ref = getGeneralRef(job, general_ref_type::UNIT_WORKER);
{
VIRTUAL_CAST_VAR(ref, df::general_ref_unit_workerst, job->general_refs[i]);
if (ref)
return ref->getUnit();
}
return NULL; return ref ? ref->getUnit() : NULL;
} }
void DFHack::Job::setJobCooldown(df::building *workshop, df::unit *worker, int cooldown) 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++) for (size_t i = 0; i < job->general_refs.size(); i++)
{ {
VIRTUAL_CAST_VAR(ref, df::general_ref_unit_workerst, job->general_refs[i]); df::general_ref *ref = job->general_refs[i];
if (!ref) if (ref->getType() != general_ref_type::UNIT_WORKER)
continue; continue;
auto worker = ref->getUnit(); auto worker = ref->getUnit();

@ -584,8 +584,8 @@ bool Maps::canStepBetween(df::coord pos1, df::coord pos2)
if ( dx == 0 && dy == 0 ) { if ( dx == 0 && dy == 0 ) {
//check for forbidden hatches and floors and such //check for forbidden hatches and floors and such
df::enums::tile_building_occ::tile_building_occ upOcc = index_tile<df::tile_occupancy>(block2->occupancy,pos2).bits.building; df::tile_building_occ upOcc = index_tile<df::tile_occupancy>(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 ) if ( upOcc == tile_building_occ::Impassable || upOcc == tile_building_occ::Obstacle || upOcc == tile_building_occ::Floored )
return false; return false;
if ( shape1 == tiletype_shape::STAIR_UPDOWN && shape2 == shape1 ) 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 return false; //unusable ramp
//there has to be an unforbidden hatch above the ramp //there has to be an unforbidden hatch above the ramp
if ( index_tile<df::tile_occupancy>(block2->occupancy,pos2).bits.building != df::enums::tile_building_occ::Dynamic ) if ( index_tile<df::tile_occupancy>(block2->occupancy,pos2).bits.building != tile_building_occ::Dynamic )
return false; return false;
//note that forbidden hatches have Floored occupancy. unforbidden ones have dynamic occupancy //note that forbidden hatches have Floored occupancy. unforbidden ones have dynamic occupancy
df::building* building = Buildings::findAtTile(pos2); 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"; out << __FILE__ << ", line " << __LINE__ << ": couldn't find hatch.\n";
return false; return false;
} }
if ( building->getType() != df::enums::building_type::Hatch ) { if ( building->getType() != building_type::Hatch ) {
return false; return false;
} }
return true; return true;
@ -661,8 +661,8 @@ bool Maps::canStepBetween(df::coord pos1, df::coord pos2)
if ( !blockUp ) if ( !blockUp )
return false; return false;
df::enums::tile_building_occ::tile_building_occ occupancy = index_tile<df::tile_occupancy>(blockUp->occupancy,up).bits.building; df::tile_building_occ occupancy = index_tile<df::tile_occupancy>(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 ) if ( occupancy == tile_building_occ::Obstacle || occupancy == tile_building_occ::Floored || occupancy == tile_building_occ::Impassable )
return false; return false;
return true; return true;
} }