Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtered despawn #1341

Merged
merged 12 commits into from
Feb 1, 2022
Merged

Filtered despawn #1341

merged 12 commits into from
Feb 1, 2022

Conversation

originalfoo
Copy link
Member

@originalfoo originalfoo commented Jan 30, 2022

Fixes: #270
Updates: #833

TMPE.zip

  • Adds several vehicle-related extensions (see commits)
  • Create a filterable (by ExtVehicleType) DespawnVehicles() method in UtilityManager.
  • Add an in-game-only checkbox group to Maintenance tab allowing user to filter and despawn
  • Beautify missing locale keys, but only in STABLE builds (all strings in image below are missing locale keys)

Edit: Image below is outdated; the text and cims was removed from the All... option as cims are handled by entirely different AI.

image

Toggling All vehicles and cims checkbox will apply the result to all indented checkbox below. Checking all indented checkbox will result in the All... checkbox being checked; and unchecking one or more indented checkbox will result in All... being unchecked.

Note that Parked Vehicles is handled as a speical case; when Despawn button is clicked, it checks that setting individually and queues relevant manager instance method (RemoveParkedVehicles()).

List of filters that can be used by `UtilityManager.Instance.DespawnVehicles()` for reference
    [Flags]
    public enum ExtVehicleType {
        None = 0,
        PassengerCar = 1,
        Bus = 1 << 1,
        Taxi = 1 << 2,
        CargoTruck = 1 << 3,
        Service = 1 << 4,
        Emergency = 1 << 5,
        PassengerTrain = 1 << 6,
        CargoTrain = 1 << 7,
        Tram = 1 << 8,
        Bicycle = 1 << 9,
        Pedestrian = 1 << 10,
        PassengerShip = 1 << 11,
        CargoShip = 1 << 12,
        PassengerPlane = 1 << 13,
        Helicopter = 1 << 14,
        CableCar = 1 << 15,
        PassengerFerry = 1 << 16,
        PassengerBlimp = 1 << 17,
        CargoPlane = 1 << 18,
        Trolleybus = 1 << 19,
        Plane = PassengerPlane | CargoPlane,
        Ship = PassengerShip | CargoShip,
        CargoVehicle = CargoTruck | CargoTrain | CargoShip | CargoPlane,
        PublicTransport = Bus | Taxi | Tram | PassengerTrain | Trolleybus,
        RoadPublicTransport = Bus | Taxi | Trolleybus,
        RoadVehicle = PassengerCar | Bus | Taxi | CargoTruck | Service | Emergency, //may perform u-turn
        RailVehicle = PassengerTrain | CargoTrain,
        NonTransportRoadVehicle = RoadVehicle & ~PublicTransport,
        Ferry = PassengerFerry,
        Blimp = PassengerBlimp,
    }

Although this is a non-trivial change, I'd like to request it go in to 11.6.4.4 release as it will help users despawn their aircraft should they be stuck due to pathfinding issues tackled in PR #1338

- `ToVehicle()` - get `Vehicle` from an id
- `Despawn()` - queue a vehicle for despawning
- `ToExtVehicleType()` - get `ExtVehicleType` for a vehicle
- When called with no params, despawns all vehicles
- Otherwise, despawns vehicles matching specified `ExtVehicleType`
- `ClearTraffic()` => `DespawnVehicles()`
@originalfoo originalfoo added enhancement Improve existing feature DO NOT MERGE YET Don't merge this PR, even if approved, until further notice DESPAWN TOOLS Feature: Clear traffic, toggle despawn, vehicle/parked/cim despawns labels Jan 30, 2022
@originalfoo originalfoo self-assigned this Jan 30, 2022
TLM/TLM/Manager/Impl/ExtVehicleManager.cs Outdated Show resolved Hide resolved
TLM/TLM/Util/Extensions/VehicleExtensions.cs Outdated Show resolved Hide resolved
TLM/TLM/Manager/Impl/UtilityManager.cs Outdated Show resolved Hide resolved
Just for consistency with similar methods.
TEST and DEBUG builds will still show the pilcrow;
but STABLE builds will try and clean the locale key
by removing anything before `:` (if present).
These allow user to choose what to despawn.

The group only appears in-game.
@originalfoo originalfoo added Localisation Localised text and features Settings Road config, mod options, config xml and removed DO NOT MERGE YET Don't merge this PR, even if approved, until further notice labels Jan 31, 2022
@originalfoo
Copy link
Member Author

The Maintenance options tab now has a new group of checkboxen at the bottom with despawn filters!

It will only appear in-game (not in editor or main menu).

Additionally I've beautified the result of missing translations in STABLE builds (only for basic strings, not advisor tutorials). 3960c45 - DEBUG and TEST builds are unaffected by this change (they'll still show pilcrow and the full locale key).

@kvakvs
Copy link
Collaborator

kvakvs commented Jan 31, 2022

To despawn only cims? Will help with crowded bus stops, but really that should be fixed elsewhere, they should lose patience and find another path.

@originalfoo
Copy link
Member Author

To despawn only cims? Will help with crowded bus stops, but really that should be fixed elsewhere, they should lose patience and find another path.

I can add that in easy enough - should it despawn bicycles as well or just the pedestrians?

As for preventing crowded stops, Dymanoid's "Stops and Stations" mod does exactly that :)

@originalfoo
Copy link
Member Author

originalfoo commented Jan 31, 2022

duh, RoadVehicle includes Service and Emergency. my bad

ignore this

Trying to track down what's going on in #1342 and found one possible issue that |= operator isn't working at all on ExtVehicleType :

In previous commit I add a new var mask to store the current "compilation" of the bitmask, and at the end of the foreach loop I then set the main despawnerMask to value of the compiled mask - this is all to track down weirdness as shown below:

Select Road vehicles:

Info 343.8976245: Current despawnerMask = None
Info 343.8984347: mask: None
Info 343.8991240: - Despawn.Checkbox:Road vehicles: mask |= RoadVehicle
Info 343.8998197: - mask now: RoadVehicle
Info 343.9006098: Despawner mask: RoadVehicle

Good so far. Now select Service vehicles:

Info 358.6056609: Current despawnerMask = RoadVehicle
Info 358.6065370: mask: None
Info 358.6072393: - Despawn.Checkbox:Road vehicles: mask |= RoadVehicle
Info 358.6079267: - mask now: RoadVehicle
Info 358.6085545: mask: RoadVehicle
Info 358.6093436: - Despawn.Checkbox:Service vehicles: mask |= Service, Emergency
Info 358.6100668: - mask now: RoadVehicle
Info 358.6107582: Despawner mask: RoadVehicle

So (paraphrasing for sake of brevity) if mask == RoadVehicle and I then mask |= Service, Emergency, how exactly does that result in mask == RoadVehicle???

@originalfoo
Copy link
Member Author

And now it's working perfectly :)

@originalfoo originalfoo added this to the 11.6.4-hotfix-4 milestone Feb 1, 2022
@krzychu124
Copy link
Member

All vehicles and cims

By cims you mean these in passenger cars and public transport vehicles, right?

@originalfoo
Copy link
Member Author

originalfoo commented Feb 1, 2022

All vehicles and cims

By cims you mean these in passenger cars and public transport vehicles, right?

I removed the word cims in a recent commit as they are handled by entirely different AI. That can be added in as a future update if required. The cims in vehicles are citizen units or something like that; I assume the game just teleports them to destination if vehicle despawns.

EDIT: updated OP to note that the image is outdated

@krzychu124
Copy link
Member

Hmm I don't see despawn section in the options in-game, what I'm doing wrong?🤔

@originalfoo
Copy link
Member Author

It should appear at bottom of maintenance tab in options when in-game (does not appear in main menu or editor though)

@krzychu124
Copy link
Member

It should appear at bottom of maintenance tab in options when in-game (does not appear in main menu or editor though)

Yeah, stupid me, I was browsing PR changes but didn't build that version for tests...

@krzychu124 krzychu124 self-requested a review February 1, 2022 20:54
Copy link
Member

@krzychu124 krzychu124 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be working correctly 👍

@originalfoo
Copy link
Member Author

awesome - pls mege (only one reviewer so far) :)

@krzychu124 krzychu124 merged commit 9eea865 into master Feb 1, 2022
@originalfoo originalfoo deleted the filtered-despawn branch February 1, 2022 21:04
originalfoo added a commit that referenced this pull request Feb 1, 2022
- Checks if savegame edition != latest edition
- If so, works out what to despawn
- Then despawns it (see #1341 for how that works)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DESPAWN TOOLS Feature: Clear traffic, toggle despawn, vehicle/parked/cim despawns enhancement Improve existing feature Localisation Localised text and features Settings Road config, mod options, config xml
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Button to despawn just trains
3 participants