Game.Prefabs.PoliceCar
Assembly: Game
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Prefab component that describes police vehicle behavior and data for police cars (and police aircraft when paired with an AircraftPrefab). Exposes configuration used to initialize entity component data (PoliceCarData, UpdateFrameData) and to define which archetype components are required when creating police vehicle entities. Includes editor attributes to place this prefab under the Vehicles menu and to exclude generated mod tags unless explicitly added.
Fields
-
public int m_CriminalCapacity = 2
Number of criminals (passenger capacity for criminal transport) this police vehicle can carry. Default: 2. -
public float m_CrimeReductionRate = 10000f
Rate at which the vehicle reduces crime while on duty. Interpreted by the PoliceCarData component; default value is 10000. -
public float m_ShiftDuration = 1f
Length of a police shift in seconds (float). Internally converted to the simulation's fixed-point unit when initializing PoliceCarData (multiplied by 262,144 and stored as a uint). -
[EnumFlag] public PolicePurpose m_Purposes = PolicePurpose.Patrol | PolicePurpose.Emergency
Bitflag enum specifying permitted purposes/roles for this vehicle (default includes Patrol and Emergency). Controls how the vehicle is dispatched and what tasks it can perform.
Properties
public override IEnumerable<string> modTags { get }
Returns the mod tags for this prefab. Yields base.modTags and then adds either "PoliceCarAircraft" if the GameObject has an AircraftPrefab component, or "PoliceCar" otherwise. This is used by mod systems and filtering to identify the type of prefab at runtime or in tooling.
Constructors
public PoliceCar()
No explicit constructor is defined in the source; the default parameterless constructor is used. Initialization of component data occurs in the overridden Initialize method rather than in a constructor.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds component types that must exist on the created entity for this prefab: PoliceCarData and UpdateFrameData. Called when building entity prefab data. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds required archetype component types for police vehicle runtime behavior: Game.Vehicles.PoliceCar, Passenger, and PointOfInterest. Additionally, if the archetype already contains Moving(), this method adds PathInformation and ServiceDispatch components so moving police vehicles support pathfinding and dispatch functionality. -
public override void Initialize(EntityManager entityManager, Entity entity)
Initializes entity component data for a newly created police vehicle entity: - Converts the m_ShiftDuration float to the engine's fixed-point unit by multiplying by 262,144 and casting to uint.
- Sets PoliceCarData on the entity with m_CriminalCapacity, m_CrimeReductionRate, converted shiftDuration, and m_Purposes.
- If the entity has a CarData component, sets UpdateFrameData(5) (controls update frequency/frame grouping for updates).
Notes: - The multiplication by 262,144f (2^18) suggests the game uses a 18-bit fractional fixed-point representation for time/shift values. - The method relies on EntityManager APIs (EntityManager.SetComponentData, EntityManager.HasComponent) to initialize ECS data.
Usage Example
// Example: The prefab system calls Initialize for you, but if manually constructing/testing:
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity policeEntity = em.CreateEntity(); // archetype must include required components
// Suppose you have a PoliceCar prefab MonoBehaviour instance 'prefab'
prefab.Initialize(em, policeEntity);
// The Initialize implementation will:
// - set PoliceCarData with criminal capacity, crime reduction rate, shift duration (converted), purposes
// - set UpdateFrameData(5) if this entity has CarData
Additional editor attributes: - [ExcludeGeneratedModTag] — prevents automatic generation of certain mod tags. - [ComponentMenu("Vehicles/", new Type[] { typeof(CarPrefab), typeof(AircraftPrefab) })] — places this prefab under the Vehicles menu in the editor and associates it with CarPrefab and AircraftPrefab types.