TPW CROWD - Larger CPU friendly civilian crowds.

Author: tpw
Requires: CBA A3, tpw_core.sqf
Compatibility: SP only

Description
-----------
Ever since TPW SOAP was released I've experienced a bit of cognitive dissonance - A3 maps now sound like there's plenty of people around, but you only ever see the few civilians that TPW CIVS spawns. TPW CROWD is my attempt to partly remedy this situation by spawning large numbers of civilians around the player, but disabling their simulation and movement unless you're actually looking at them. Using this (not so simple) expedient it's now possible to have dozens of civilians around the player without melting down your CPU. As you move through populated areas you'll see groups of people standing around the side of the road bullshitting. They'll disperse and move off to houses if you get too close, if it rains, or if there is nearby gunfire. You may use it standalone or in conjunction with TPW CIVS to greatly increase the visual civilian ambience on any map.  

How it works
------------
TPW CROWD scans for habitable houses in a defined radius around the player, and spawns civs at a user defined density per house, up to a user defined maximum. Civs are spawned at a distance so that you'll rarely notice them popping in. Distant civs and those the player can't see have their simulation disabled and consume very few CPU/GPU resources. If you look at distant civs through optics, their simulation is enabled and they'll appear to move on the spot talking. If you get closer than a user defined distance then they'll animate even without optics. Closer still (user defined) and they'll randomly head towards nearby houses. After a few seconds of being out of sight they'll be despawned. 

Fewer civs will spawn and night or during rain.

During gunfire the civs will quickly disperse / despawn, and no new ones will respawn for a minute or so. This feature requires TPW SOAP to be active (and why wouldn't it be?!?).

Spawn points are selected on roadsides if possible, otherwise near houses. There should be no more than 5 or so civs per 50 m, this avoids the situation where you turn a corner and are confronted by 30 simulation enabled civs who tank your FPS.

Civs are spawned with as many CPU eating AI features nerfed as possible. They have no waypoints, and do minimal pathfinding once dispersed. They are region specific and will wear appropriate clothing for the weather (TPW FOG must be enabled). Even when simulation disabled they cannot be walked or driven through, and other AI will interact accordingly. They will despawn if damaged in any way. Civs are spawned with randomised movement speeds. 

Usage
-----
I've spent a lot of time playtesting and find the following default values work well to provide the illusion of crowds, whilst only costing a couple of FPS:

tpw_crowd_max = 20; // maximum number of civs 
tpw_crowd_density = 2; // civs per house
tpw_crowd_radius = 120; // radius to scan around player to spawn civs
tpw_crowd_animradius = 80; // units closer than this will animate
tpw_crowd_moveradius = 40; // units closer than this will disperse
tpw_crowd_scantime = 1.5; // time (sec) between scanning, spawning and visibility checks. Higher saves CPU but distant units viewed through optics will take longer to start animating  

You are of course free to change values if you want more civs around, but be aware that TPW CROWD is a balancing act between the numbers of simulation enabled civs, and the CPU cycles used to scan them all for visibility calculations. All of these values may be changed on the fly, for instance to create a town with higher or lower civ density via trigger. 

Setting tpw_crowd_moveradius = 0 will generate crowds which never disperse, which may help FPS as no civ pathfinding is then required. Even more extreme, setting tpw_crowd_moveradius and tpw_crowd_animradius to 0 will generate "mannequin" crowds which never animate or move, sacrificing realism for even greater reductions in CPU overhead.

TPW CROWD can be disabled at any time using tpw_crowd_enable = false in a script, shell or trigger.

Issues
------
TPW CROWD is based on a simple premise that is complicated to implement, and thus probably contains bugs and room for improvement. The whole point of the exercise is to make it CPU friendly, the trade off being the occasional anomaly such as civs popping in or disappearing in front of you, or initially appearing 50cm above or below the ground surface on hilly terrain.
 
Having large numbers of civs around can clutter/slow down TPW HUD's display. Civilian scanning in the HUD can be toggled using Ctrl + Alt + C.

TPW CROWD IS SINGLE PLAYER ONLY. If you're playing SP than you can chose to run TPW CIVS or TPW CROWD or both at once. If MP then you're stuck with TPW CIVS.