Game.Citizens.CitizenFlags
Assembly:
Namespace: Game.Citizens
Type: enum (with [Flags] attribute)
Base: System.Int16 (short)
Summary: A flag-style enumeration used to represent multiple boolean/state attributes for a citizen in Cities: Skylines 2. The enum uses a 16-bit underlying type (short) and individual bits encode age bits, education bits, gender, status flags (tourist/commuter), relationship/job needs, and education failure markers. Because it is marked with [Flags], values may be combined with bitwise operations to represent multiple states simultaneously.
Fields
-
None = 0
Represents no flags set. Typically used as the default value for a citizen with no special states. -
AgeBit1 = 1
Low-order bit for encoding age information. Combined with AgeBit2 to encode an age range/state. -
AgeBit2 = 2
Second bit for encoding age information. Together with AgeBit1 this creates a 2-bit age field. -
MovingAwayReachOC = 4
Flag indicating the citizen is in the process of moving away (or part of move-out logic). The exact meaning may be game-specific (e.g., used by reach/occlusion logic). -
Male = 8
Gender flag; when set, the citizen is male. Absence implies not-male (female/other depending on system). -
EducationBit1 = 0x10
Lowest bit of the education level encoding. Combined with EducationBit2 and EducationBit3 to form a 3-bit education level/state. -
EducationBit2 = 0x20
Middle bit of the education level encoding. -
EducationBit3 = 0x40
Highest bit of the education level encoding. -
FailedEducationBit1 = 0x80
Lowest bit in a small field marking failed education states (two bits total). -
FailedEducationBit2 = 0x100
Second bit for failed education marking. -
Tourist = 0x200
Flag showing the citizen is a tourist (temporary/visiting). -
Commuter = 0x400
Flag showing the citizen is a commuter (travels to/from city). -
LookingForPartner = 0x800
Flag indicating the citizen is currently looking for a partner (relationship status). -
NeedsNewJob = 0x1000
Flag indicating the citizen needs a new job (job-seeking state).
Properties
- This enum type does not declare properties. Use bitwise operators or Enum methods to inspect/manipulate values.
Constructors
- Enums do not have instance constructors in C#. The default value is
CitizenFlags.None
(0). Values are assigned by their numeric constants; you can cast from or to the underlying short type: - Example:
CitizenFlags flags = (CitizenFlags)someShortValue;
Methods
- The enum itself defines no methods. Common runtime operations are performed using:
- bitwise OR (|) to combine flags,
- bitwise AND (&) to test for flags,
- bitwise XOR (^) to toggle flags,
- bitwise NOT (~) to invert bits,
- Enum.HasFlag to check presence of a flag (note: HasFlag is slower than bitwise tests; prefer (flags & flag) != 0 for performance-critical code),
- casting to/from the underlying short for serialization or native interop.
Usage Example
// Create flags
CitizenFlags flags = CitizenFlags.None;
// Set flags (combine)
flags |= CitizenFlags.Male | CitizenFlags.Commuter;
// Check flag presence (preferred for performance)
bool isMale = (flags & CitizenFlags.Male) != 0;
bool isTourist = (flags & CitizenFlags.Tourist) != 0;
// Clear a flag
flags &= ~CitizenFlags.Commuter;
// Toggle a flag
flags ^= CitizenFlags.LookingForPartner;
// Using HasFlag (works but slower)
if (flags.HasFlag(CitizenFlags.NeedsNewJob)) {
// handle job seeking
}
// Working with underlying short (e.g., for save/load or native interop)
short packed = (short)flags;
CitizenFlags restored = (CitizenFlags)packed;
// Extract age bits (AgeBit1 + AgeBit2 form a 2-bit field)
int ageBits = ((int)flags & ((int)CitizenFlags.AgeBit1 | (int)CitizenFlags.AgeBit2));
// Extract education 3-bit value
int educationMask = (int)(CitizenFlags.EducationBit1 | CitizenFlags.EducationBit2 | CitizenFlags.EducationBit3);
int educationBits = ((int)flags & educationMask) >> 4; // shift to get 0..7
// Clear education bits and set to a new value (example value 3)
flags &= ~(CitizenFlags.EducationBit1 | CitizenFlags.EducationBit2 | CitizenFlags.EducationBit3);
flags |= (CitizenFlags)((3 << 4) & educationMask);
Notes: - Treat the defined bit groups (age bits, education bits, failed-education bits) as packed bitfields rather than independent boolean flags when encoding/decoding values. - Prefer explicit bitwise checks ((flags & flag) != 0) for performance-sensitive code over Enum.HasFlag.