Civzone interop style changes

develop
20k 2023-01-20 18:30:38 +00:00
parent 8c68f54f50
commit 1dbf01e5d1
1 changed files with 17 additions and 41 deletions

@ -169,34 +169,24 @@ void buildings_onUpdate(color_ostream &out)
static void building_into_zone_unidir(df::building* bld, df::building_civzonest* zone) static void building_into_zone_unidir(df::building* bld, df::building_civzonest* zone)
{ {
for (size_t bid = 0; bid < zone->contained_buildings.size(); bid++) for (auto contained_building : zone->contained_buildings)
{ {
if (zone->contained_buildings[bid] == bld) if (contained_building == bld)
return; return;
} }
zone->contained_buildings.push_back(bld); insert_into_vector(zone->contained_buildings, &df::building::id, bld);
std::sort(zone->contained_buildings.begin(), zone->contained_buildings.end(), [](df::building* b1, df::building* b2)
{
return b1->id < b2->id;
});
} }
static void zone_into_building_unidir(df::building* bld, df::building_civzonest* zone) static void zone_into_building_unidir(df::building* bld, df::building_civzonest* zone)
{ {
for (size_t bid = 0; bid < bld->relations.size(); bid++) for (auto relation : bld->relations)
{ {
if (bld->relations[bid] == zone) if (relation == zone)
return; return;
} }
bld->relations.push_back(zone); insert_into_vector(bld->relations, &df::building::id, (df::building*)zone);
std::sort(bld->relations.begin(), bld->relations.end(), [](df::building* b1, df::building* b2)
{
return b1->id < b2->id;
});
} }
static bool is_suitable_building_for_zoning(df::building* bld) static bool is_suitable_building_for_zoning(df::building* bld)
@ -223,10 +213,8 @@ static void add_building_to_all_zones(df::building* bld)
std::vector<df::building_civzonest*> cv; std::vector<df::building_civzonest*> cv;
Buildings::findCivzonesAt(&cv, coord); Buildings::findCivzonesAt(&cv, coord);
for (size_t i=0; i < cv.size(); i++) for (auto zone : cv)
{ add_building_to_zone(bld, zone);
add_building_to_zone(bld, cv[i]);
}
} }
static void add_zone_to_all_buildings(df::building* zone_as_building) static void add_zone_to_all_buildings(df::building* zone_as_building)
@ -239,20 +227,16 @@ static void add_zone_to_all_buildings(df::building* zone_as_building)
if (zone == nullptr) if (zone == nullptr)
return; return;
auto& vec = world->buildings.other[buildings_other_id::IN_PLAY]; for (auto bld : world->buildings.other.IN_PLAY)
for (size_t i = 0; i < vec.size(); i++)
{ {
auto against = vec[i]; if (zone->z != bld->z)
if (zone->z != against->z)
continue; continue;
if (!is_suitable_building_for_zoning(against)) if (!is_suitable_building_for_zoning(bld))
continue; continue;
int32_t cx = against->centerx; int32_t cx = bld->centerx;
int32_t cy = against->centery; int32_t cy = bld->centery;
df::coord2d coord(cx, cy); df::coord2d coord(cx, cy);
@ -263,7 +247,7 @@ static void add_zone_to_all_buildings(df::building* zone_as_building)
if (!etile || !*etile) if (!etile || !*etile)
continue; continue;
add_building_to_zone(against, zone); add_building_to_zone(bld, zone);
} }
} }
} }
@ -296,10 +280,8 @@ static void remove_building_from_all_zones(df::building* bld)
std::vector<df::building_civzonest*> cv; std::vector<df::building_civzonest*> cv;
Buildings::findCivzonesAt(&cv, coord); Buildings::findCivzonesAt(&cv, coord);
for (size_t i=0; i < cv.size(); i++) for (auto zone : cv)
{ remove_building_from_zone(bld, zone);
remove_building_from_zone(bld, cv[i]);
}
} }
static void remove_zone_from_all_buildings(df::building* zone_as_building) static void remove_zone_from_all_buildings(df::building* zone_as_building)
@ -312,16 +294,10 @@ static void remove_zone_from_all_buildings(df::building* zone_as_building)
if (zone == nullptr) if (zone == nullptr)
return; return;
auto& vec = world->buildings.other[buildings_other_id::IN_PLAY];
//this is a paranoid check and slower than it could be. Zones contain a list of children //this is a paranoid check and slower than it could be. Zones contain a list of children
//good for fixing potentially bad game states when deleting a zone //good for fixing potentially bad game states when deleting a zone
for (size_t i = 0; i < vec.size(); i++) for (auto bld : world->buildings.other.IN_PLAY)
{
df::building* bld = vec[i];
remove_building_from_zone(bld, zone); remove_building_from_zone(bld, zone);
}
} }
uint32_t Buildings::getNumBuildings() uint32_t Buildings::getNumBuildings()