Populace

This document covers all aspects of the map's populace - deciding when and where to spawn peds and cars, and when to remove peds and cars.

Spawn rectangles

There are three concentric rectangles that surround the player:

The despawn area essentially has unlimited size, since it covers the area outside the spawn area (although a buffer area inbetween the two may be added). The spawn area has a limited size; the algorithm for determining its size is yet to be decided.

Desired population count

At the moment, there is no accomodation for setting a population count for each map zone. This means that the current version of the code will use static population numbers; there will be two numbers, one for the desired ped count, and one for the car count. In the future these numbers may be changed to population densities (i.e. peds/cars per tile) instead. Each frame, the current population count will be checked against these values, and extra peds/cars spawned if needed (up to a certain maximum number)

Population tracking

There are, generally speaking, three types of ped/car that can be in the world:

  1. General populace - these can safely be deleted if they wander into the despawn zone
  2. Player toys - These are peds or cars that the player has interacted with. For example, a ped toy would be a police or emergency services member that has been created in response to the player's actions; whereas a car toy would be a car which the player owns or has stolen, or has attacked, etc. Generally, these will be left alone if they wander into the despawn zone - but some method of controlling their population is required if the map is not to fill with them. For example, police may have a timer after which time they give up chasing the player, at which point they will automatically turn back into members of the general populace and be removed as soon as they stray into the despawn zone. Similarly, an unoccupied car which the player has interacted with may have a small, random chance of being 'stolen', and thus vanishing. Or, alternatively, there may be a cap of (for example) 32 cars which the player can have as toys, with the least-recently-used (or seen) car being removed if the list becomes full. Additionally, if a toy dies, it will immediately become a member of the general populace.
  3. Mission entities - These are peds or cars that are being used by the mission script. These will never be deleted by the populace code, and don't even count towards the populace of the city. They can be easily identified, for they will have at least one mvar referencing them or at least one event attached to them.

TODO:
MUST-CODE: DELAYED: Once AI is implemented, tweak populace code to get better results
MUST-DOCS: MED: Decide how toys/populace are identified - do they have a special flag to say they're a toy/populace member? Or can it be identified in terms of their AI goals (for peds)? Cars don't have AI goals though, so no way of knowing whether an empty car is a parked one spawned by the populace code or one the player has left behind. Since populace check likely involves scanning the whole ped/car list, there is no need for a car toy list - instead, each car can have a toy counter to indicate when it was least used, and each frame the least-recently-used toy car can be checked to see if it should be deleted (i.e. list is full and it's in the despawn zone) Maybe swap the CAR_MISSION and PED_MISSION flags for CAR_TOY and PED_TOY, seeing as mission state can be checked simply by presence of mvar references? Or is there still use of these flags? (E.g. if events are attached)
MUST-CODE: MED: Implement ped & toy code, as designed above
MUST-DOCS: MED: Objects - is any populace control needed for these? or can they all be spawned at map generation time?
MUST-CODE: MED: Upgrade zone/zonedef stuff to contain population count/density values
MUST-CODE: QUICK: Add DEREF script command to force a mission script ped/car to lose all its references and/or events, thus returning it to the general populace
MUST-CODE: MED: Proper ped-in-car spawning code
???
Profit!