Nuke unsafe behavior in Buildings::findAtTile from orbit.

develop
Alexander Gavrilov 2013-02-13 15:03:15 +04:00
parent a17760af4f
commit 9ca435544e
1 changed files with 12 additions and 23 deletions

@ -249,31 +249,21 @@ df::building *Buildings::findAtTile(df::coord pos)
if (!occ || !occ->bits.building) if (!occ || !occ->bits.building)
return NULL; return NULL;
auto a = locationToBuilding.find(pos); // Try cache lookup in case it works:
if ( a == locationToBuilding.end() ) { auto cached = locationToBuilding.find(pos);
cerr << __FILE__ << ", " << __LINE__ << ": can't find building at " << pos.x << ", " << pos.y << ", " <<pos.z << "." << endl; if (cached != locationToBuilding.end())
exit(1); {
} auto building = df::building::find(cached->second);
int32_t id = (*a).second;
int32_t index = df::building::binsearch_index(df::global::world->buildings.all, id);
if ( index == -1 ) {
cerr << __FILE__ << ", " << __LINE__ << ": can't find building at " << pos.x << ", " << pos.y << ", " <<pos.z << "." << endl;
exit(1);
}
df::building* building = df::global::world->buildings.all[index];
if (!building->isSettingOccupancy())
return NULL;
if (building->room.extents && building->isExtentShaped()) if (building && building->z == pos.z &&
building->isSettingOccupancy() &&
containsTile(building, pos, false))
{ {
auto etile = getExtentTile(building->room, pos);
if (!etile || !*etile)
return NULL;
}
return building; return building;
}
}
/* // The authentic method, i.e. how the game generally does this:
//old method: brute-force
auto &vec = df::building::get_vector(); auto &vec = df::building::get_vector();
for (size_t i = 0; i < vec.size(); i++) for (size_t i = 0; i < vec.size(); i++)
{ {
@ -298,7 +288,6 @@ df::building *Buildings::findAtTile(df::coord pos)
} }
return NULL; return NULL;
*/
} }
bool Buildings::findCivzonesAt(std::vector<df::building_civzonest*> *pvec, df::coord pos) bool Buildings::findCivzonesAt(std::vector<df::building_civzonest*> *pvec, df::coord pos)