#include "munga.h"
#pragma hdrstop

#include "envirnmt.h"
#include "cstr.h"

//#############################################################################
//###########################    Environment    ###############################
//#############################################################################

#if defined(USE_SIGNATURE)
	int Is_Signature_Bad(const Environment *)
	{
		return False;
	}
#endif

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Logical Environment::TestInstance() const
{
	return True;
}

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

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void Convert_From_Ascii(const char *str, Environment *environment)
{
	Check_Pointer(str);
	Check_Signature(environment);

	CString parse_string(str);
	Check(&parse_string);

	Check_Pointer(parse_string.GetNthToken(0));
	environment->gravityConstant = atof(parse_string.GetNthToken(0));

	Check_Pointer(parse_string.GetNthToken(1));
	environment->airDensity = atof(parse_string.GetNthToken(1));

	Check_Pointer(parse_string.GetNthToken(2));
	environment->audioReverbTime = atof(parse_string.GetNthToken(2));

	Check_Pointer(parse_string.GetNthToken(3));
	environment->audioAverageSurfaceReflectivity = atof(parse_string.GetNthToken(3));

	Check_Pointer(parse_string.GetNthToken(4));
	environment->audioAirAbsorption = atof(parse_string.GetNthToken(4));

	Check_Pointer(parse_string.GetNthToken(5));
	environment->windVelocity.x = atof(parse_string.GetNthToken(5));

	Check_Pointer(parse_string.GetNthToken(6));
	environment->windVelocity.y = atof(parse_string.GetNthToken(6));

	Check_Pointer(parse_string.GetNthToken(7));
	environment->windVelocity.z = atof(parse_string.GetNthToken(7));

	Check_Pointer(parse_string.GetNthToken(8));
	environment->ambientTemperature = atof(parse_string.GetNthToken(8));

	Check(environment);
}

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

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
EnvironmentList::EnvironmentList(int environments)
{
	Verify(environments > 0);

	environmentCount = environments;
	environmentArray = new Environment[environments];
	Register_Pointer(environmentArray);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
EnvironmentList::~EnvironmentList()
{
	Unregister_Pointer(environmentArray);
	delete[] environmentArray;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Logical EnvironmentList::TestInstance() const
{
	return True;
}

EnvironmentList *Environments;
