/**
 * Main Event Handler for Square.
 */
class SquareEventHandler : StaticEventHandler
{
	/**
	 * Map-start events.
	 */
	override void WorldLoaded(WorldEvent e)
	{
		// Level modification stuff. Only do this on first load,
		// since these values are persisted in savegames & hubs.
		if(!e.IsReopen && !e.IsSavegame) {

			// Global aircontrol override. This sets the aircontrol if it happens
			// to be equal to ZDoom's bizarro default -- this way, custom maps
			// can modify it via MAPINFO by normal means, if folks wish.
			if(level.aircontrol == GZDOOM_AIRCONTROL) {
				SetAirControl(SQUARE_AIRCONTROL);
			}
		}
	}

	/**
	 * Set air control. This also involves setting air friction too, so do that
	 * here instead of inline. Formula's the same as GZDoom's internal one.
	 */
	static void SetAirControl(double val)
	{
		level.aircontrol = val;

		if (val <= 1/256.) {
			level.airfriction = 1.;
		} else {
			level.airfriction = val * -0.0941 + 1.0004; // [XA] It's magic!
		}
	}
}
