Game.Net.RoadTypes
Assembly:
Namespace: Game.Net
Type: public enum RoadTypes : byte
Base: System.Enum (underlying type: System.Byte)
Summary: RoadTypes is a flags-style enumeration that represents vehicle/transport modes associated with roads in the game. The enum uses the [Flags] attribute and a byte underlying type, so multiple values can be combined with bitwise operations to represent allowed or present transport types on a single road or in related systems (e.g., lane/segment permissions, routing filters).
Fields
-
None = 0
Represents no transport types selected. Useful as a default/empty value. -
Car = 1
Represents car traffic. -
Watercraft = 2
Represents watercraft (boats) traffic. -
Helicopter = 4
Represents helicopter traffic. -
Airplane = 8
Represents airplane traffic.
Properties
- None specific to this enum. (Use standard System.Enum functionality; the enum itself is a value type with no custom properties.)
Constructors
public RoadTypes()
Enums do not expose custom constructors. The default value isRoadTypes.None
(underlying value 0). Storage size is 1 byte due to the explicit ": byte" underlying type.
Methods
- Standard System.Enum methods are available (ToString, Parse, TryParse, HasFlag via Enum.HasFlag, etc.). Because this is a [Flags] enum, typical operations are bitwise:
- Combine: valueA | valueB
- Check: (value & flag) != 0 or value.HasFlag(flag)
- Remove/clear: value & ~flag
Note: Enum.HasFlag is implemented on System.Enum and accepts an Enum parameter (e.g., myTypes.HasFlag(RoadTypes.Car)). For performance-sensitive code, prefer bitwise checks ((myTypes & RoadTypes.Car) != 0) to avoid boxing.
Usage Example
// Combine flags to represent a road that allows cars and helicopters
RoadTypes allowed = RoadTypes.Car | RoadTypes.Helicopter;
// Check if cars are allowed
bool carsAllowed = (allowed & RoadTypes.Car) != 0;
// or
bool carsAllowedAlt = allowed.HasFlag(RoadTypes.Car);
// Add a flag (allow airplanes too)
allowed |= RoadTypes.Airplane;
// Remove a flag (no more helicopters)
allowed &= ~RoadTypes.Helicopter;
// Compare to None
bool hasAny = allowed != RoadTypes.None;
// Casting to byte for storage or serialization
byte stored = (byte)allowed;
RoadTypes loaded = (RoadTypes)stored;
Notes and recommendations: - Use the bitwise operators for fast checks and modifications in hot code paths. - Because the underlying type is byte, values are limited to the 0–255 range; ensure any future additions remain unique bit flags (1, 2, 4, 8, 16, ...).