Skip to content

Game.Prefabs.CompositionFlags

Assembly:
Assembly-CSharp

Namespace:
Game.Prefabs

Type:
struct

Base:
Implements: Colossal.Serialization.Entities.ISerializable, System.IEquatable

Summary:
A compact representation of composition flags used by prefabs (roads, nodes and their sides) in Cities: Skylines 2. It stores three bitfield groups: General flags and Side flags for left and right sides. Provides serialization/deserialization (with compatibility logic for older versions), common bitwise operators, equality/HashCode implementations, and predefined masks for node-related and option-related flag sets.


Fields

  • public General m_General
    Holds the combined General flags (see General enum) that describe node-level and overall composition properties (node/edge, traffic lights, median, elevated/tunnel, etc.).

  • public Side m_Left
    Holds the Side flags for the left side of a segment (see Side enum). Includes flags such as sidewalks, lanes, tracks and beautification.

  • public Side m_Right
    Holds the Side flags for the right side of a segment.

  • private const General NODE_MASK_GENERAL
    Internal constant mask combining General flags that are relevant for node detection/behavior (Node, DeadEnd, Intersection, Roundabout, LevelCrossing, MedianBreak, TrafficLights, RemoveTrafficLights, AllWayStop, FixedNodeSize).

  • private const General OPTION_MASK_GENERAL
    Internal constant mask for option-related General flags (WideMedian, PrimaryMiddleBeautification, SecondaryMiddleBeautification).

  • private const Side NODE_MASK_SIDE
    Internal constant mask for side flags relevant to nodes (LowTransition, HighTransition).

  • private const Side OPTION_MASK_SIDE
    Internal constant mask for option-related side flags (PrimaryBeautification, SecondaryBeautification, WideSidewalk).

  • public static CompositionFlags nodeMask
    Prebuilt CompositionFlags instance representing the node-related mask (General NODE_MASK_GENERAL and NODE_MASK_SIDE for both left and right).

  • public static CompositionFlags optionMask
    Prebuilt CompositionFlags instance representing option-related flags (OPTION_MASK_GENERAL and OPTION_MASK_SIDE for both left and right).

Properties

  • public static CompositionFlags nodeMask
    A ready-to-use CompositionFlags representing node-detection flags. Useful for masking out node-related bits when checking or modifying flags.

  • public static CompositionFlags optionMask
    A ready-to-use CompositionFlags representing option/beautification-related flags. Useful for masking option bits.

Constructors

  • public CompositionFlags(General general, Side left, Side right)
    Initializes a CompositionFlags instance with the specified General, left Side and right Side bitfields.

(Note: as a struct, a parameterless default constructor exists implicitly and yields zero flags.)

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the three bitfields (uint) to the supplied writer in the order: m_General, m_Left, m_Right. Used to persist composition flags.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads stored flags back. If reader.context.version is at or after Version.compositionFlagRefactoring, the method reads three uints (general, left, right) and assigns them directly. For older versions it reads a single uint and maps older bit semantics into current Side flags for backward compatibility (specifically sets PrimaryTrack on left/right depending on legacy bits 0x1000/0x2000).

  • public static CompositionFlags operator |(CompositionFlags lhs, CompositionFlags rhs)
    Returns a new CompositionFlags combining (bitwise OR) corresponding General, left and right fields.

  • public static CompositionFlags operator &(CompositionFlags lhs, CompositionFlags rhs)
    Returns a new CompositionFlags with bitwise AND applied to each field group.

  • public static CompositionFlags operator ^(CompositionFlags lhs, CompositionFlags rhs)
    Returns a new CompositionFlags with bitwise XOR applied to each field group.

  • public static CompositionFlags operator ~(CompositionFlags rhs)
    Returns a new CompositionFlags with bitwise NOT applied to each field group.

  • public static bool operator ==(CompositionFlags lhs, CompositionFlags rhs)
    Equality operator comparing General, left and right fields for equality.

  • public static bool operator !=(CompositionFlags lhs, CompositionFlags rhs)
    Inequality operator.

  • public bool Equals(CompositionFlags other)
    IEquatable implementation delegating to the == operator.

  • public override bool Equals(object obj)
    Overrides Object.Equals; returns true if obj is a CompositionFlags equal to this instance.

  • public override int GetHashCode()
    Generates a combined hash code based on the three underlying uint values (m_General, m_Left, m_Right).

Enums

  • public enum General : uint
    Flags describing general composition properties. Notable values include:
  • Node, Edge, Invert, Flip
  • DeadEnd, Intersection, Roundabout, LevelCrossing
  • Crosswalk, MedianBreak, TrafficLights, RemoveTrafficLights, AllWayStop
  • Pavement, Gravel, Tiles, Lighting, Inside, StyleBreak
  • Elevated, Tunnel, MiddlePlatform, WideMedian
  • PrimaryMiddleBeautification, SecondaryMiddleBeautification, FixedNodeSize (Each enum entry is a bitmask value; see source for full listing.)

  • public enum Side : uint
    Flags describing per-side composition. Notable values include:

  • Raised, Lowered, LowTransition, HighTransition
  • PrimaryTrack, SecondaryTrack, TertiaryTrack, QuaternaryTrack
  • PrimaryStop, SecondaryStop
  • PrimaryBeautification, SecondaryBeautification, WideSidewalk
  • Sidewalk, WideSidewalk, ParkingSpaces, SoundBarrier
  • PrimaryLane, SecondaryLane, TertiaryLane, QuaternaryLane
  • ForbidLeftTurn, ForbidRightTurn, ForbidStraight, AddCrosswalk, RemoveCrosswalk (Each enum entry is a bitmask value; see source for full listing.)

Usage Example

// Create a flag set representing a node with a raised left sidewalk and right sidewalk.
var flags = new CompositionFlags(
    CompositionFlags.General.Node | CompositionFlags.General.TrafficLights,
    CompositionFlags.Side.Raised | CompositionFlags.Side.Sidewalk,
    CompositionFlags.Side.Raised | CompositionFlags.Side.Sidewalk
);

// Combine flags using bitwise OR (e.g., add wide sidewalk on left)
flags = flags | new CompositionFlags(0, CompositionFlags.Side.WideSidewalk, 0);

// Mask out node-related bits
var onlyNodeBits = flags & CompositionFlags.nodeMask;

// Check equality
if (flags == onlyNodeBits)
{
    // ...
}

// Serialization (writer must implement IWriter)
flags.Serialize(writer);

// Deserialization (reader must implement IReader)
// Handles older save formats by mapping legacy bits to current Side flags.
flags.Deserialize(reader);

Notes: - Use the provided static masks (nodeMask and optionMask) to filter or test specific categories of flags. - Deserialize includes compatibility handling for pre-refactor versions (Version.compositionFlagRefactoring), so older saved data maps into current enums where possible.