Function generate_spreads

Source
pub fn generate_spreads(
    spawn_distances_ct: &[SpawnDistance],
    spawn_distances_t: &[SpawnDistance],
    area_to_group: &FxHashMap<u32, GroupId>,
    perceiption: &Perceivability,
) -> Vec<SpreadResult>
Expand description

Generate spread steps from the distances of areas to CT and T spawns.

The slices of spawn_distances_ct and spawn_distances_t need to be pre-sorted by distance. Also requires a mapping of areas to close groups to ensure a reduced number of spread points. In the extreme case this can just be AreaID -> AreaID to indicate no grouping at all. Usually a 4x4 to 10x10 grid structure is sensible. See group_nav_areas.

Logic wise we iterate over the T and CT distances in parallel and always take the closest distance to the spawn points. We keep track of all of the processed (reachable) areas for both sides.

Then we try to check which reachable areas of the other side can be seen from the new area. We only consider that have not already been spotted. We determine this “spottednes” by whether it or its last path step are in a group that has been spotted. We only consider the parent and not the full path to not mark areas that have separated from that group before it was spotted. For example if you could have a look at the spawn of the other side after 2 seconds, then you would not have seen player that moved away from the spawn and behind walls within that time.

There is some significant difficulty here with getting this perfect because paths do not go from one area to the next but skip over them or take one every so slightly at an angle. This means that we do not mark areas as spotted that sensibly already have.

Meanwhile the grouping can cause areas to be declared spotted that were separated by small walls or other obstacles from the actually spotted one. Without any grouping we get >1000 spread points for each map which is excssive. With grouping 5x5 or 10x10 we get around 200-300 spread points which is much more manageable.