#pragma once

#include "style.h"
#include "vector3d.h"

class Environment
{
	#if defined(USE_SIGNATURE)
		friend int Is_Signature_Bad(const Environment *p);
	#endif

public:
	Scalar		gravityConstant;
	Scalar		airDensity;
	Scalar		audioReverbTime;
	Scalar		audioAverageSurfaceReflectivity;
	Scalar		audioAirAbsorption;
	Vector3D	windVelocity;
	Scalar		ambientTemperature;        // Kelvin

	const Vector3D& GetWindVelocity()	{ return windVelocity; }

	Environment()	{}
	Environment(Scalar gravity, Scalar air_density, Scalar reverb_time, Scalar surface_reflectivity, Scalar air_absorption, const Vector3D &wind_velocity, Scalar ambient_temperature)
		: gravityConstant(gravity), airDensity(air_density), audioReverbTime(reverb_time), audioAverageSurfaceReflectivity(surface_reflectivity), audioAirAbsorption(air_absorption), windVelocity(wind_velocity), ambientTemperature(ambient_temperature)
	{
	}

	Logical TestInstance() const;
};

//~~~~~~~~~~~~~~~~~~~~~~~~~ Environment functions ~~~~~~~~~~~~~~~~~~~~~~~~~~

void Convert_From_Ascii(const char *str, Environment *environment);

inline MemoryStream& MemoryStream_Read(MemoryStream* stream, Environment *output)
{
	return stream->ReadBytes(output, sizeof(*output));
}
inline MemoryStream& MemoryStream_Write(MemoryStream* stream, const Environment *input)
{
	return stream->WriteBytes(input, sizeof(*input));
}

//##########################################################################
//######################    EnvironmentList    #############################
//##########################################################################

class EnvironmentList SIGNATURED
{
protected:
	int environmentCount;

	Environment *environmentArray;

public:
	EnvironmentList(int environments);
	virtual ~EnvironmentList();

	int GetEnvironmentCount()
	{
		Check(this);
		return environmentCount;
	}

	virtual Environment& GetEnvironment(int index)
	{
		Check(this);
		Verify((unsigned)index < environmentCount);
		return environmentArray[index];
	}

	Logical TestInstance() const;
};

extern EnvironmentList *Environments;
