0x004775A5
| 161 | |
| 162 | // 0x004775A5 |
| 163 | static uint32_t removeRoad(const RoadRemovalArgs& args, uint8_t flags) |
| 164 | { |
| 165 | setExpenditureType(ExpenditureType::Construction); |
| 166 | setPosition(args.pos + World::Pos3{ 16, 16, 0 }); |
| 167 | |
| 168 | // 0x0047762D |
| 169 | auto* roadEl = getRoadElement(args.pos, args, args.sequenceIndex, flags); |
| 170 | if (roadEl == nullptr) |
| 171 | { |
| 172 | return kFailure; |
| 173 | } |
| 174 | |
| 175 | const CompanyId roadOwner = roadEl->owner(); |
| 176 | |
| 177 | if (!sub_431E6A(roadOwner, reinterpret_cast<const World::TileElement*>(roadEl))) |
| 178 | { |
| 179 | return kFailure; |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | // Remove check for is road in use when removing roads. It is |
| 184 | // quite annoying when it's sometimes only the player's own |
| 185 | // vehicles that are using it. |
| 186 | // TODO: turn this into a setting? |
| 187 | if (companyId != CompanyId::neutral && (roadEl->hasUnk7_40() || roadEl->hasUnk7_80())) |
| 188 | { |
| 189 | setErrorText(StringIds::empty); |
| 190 | |
| 191 | auto nearest = TownManager::getClosestTownAndDensity(args.pos); |
| 192 | if (nearest.has_value()) |
| 193 | { |
| 194 | auto* town = TownManager::get(nearest->first); |
| 195 | FormatArguments::common(town->name); |
| 196 | setErrorText(StringIds::stringid_local_authority_wont_allow_removal_in_use); |
| 197 | } |
| 198 | return kFailure; |
| 199 | } |
| 200 | */ |
| 201 | |
| 202 | currency32_t totalRemovalCost = 0; |
| 203 | |
| 204 | // 0x004776E3 |
| 205 | |
| 206 | if (roadEl->hasStationElement()) |
| 207 | { |
| 208 | // We only want to remove the road station if the target road element is the only |
| 209 | // user of the road station. |
| 210 | const auto overlaps = OverlapRoads(args.pos); |
| 211 | const auto hasOtherRoadStationUsers = std::ranges::any_of(overlaps, [roadEl](const World::RoadElement& el) { |
| 212 | if (&el == roadEl) |
| 213 | { |
| 214 | return false; |
| 215 | } |
| 216 | return el.hasStationElement(); |
| 217 | }); |
| 218 | |
| 219 | if (!hasOtherRoadStationUsers) |
| 220 | { |
nothing calls this directly
no test coverage detected