//===========================================================================//
// File:	Missile_Tool.cpp																	 
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 05/27/99  DPB  Created File and Initial Functionality
//---------------------------------------------------------------------------//
// Copyright (C) 1998, Fasa Interactive										 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#include "MW4Headers.hpp"

#include "Missile.hpp"
#include "MWTool.hpp"

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	Missile__GameModel::ConstructGameModel(Script *script)
{
	Check_Object(script);

	//
	//--------------
	// Set up stream
	//--------------
	//
	MemoryStream *model_stream = script->modelStream;
	Check_Object(model_stream);
	model_stream->AllocateBytes(sizeof(Missile__GameModel));
	WeaponMover__GameModel::ConstructGameModel(script);
	
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
bool
	Missile__GameModel::ReadAndVerify(
		Missile__GameModel *model,
		ModelAttributeEntry *attribute_entry, 
		const char *data,
		char **error,
		int error_buffer
	)
{
	Check_Object(attribute_entry);
	
	bool result = false;
	bool valid_data = (*data != '\0');

	//
	//----------------------------------------
	//Read in the values from the data entered
	//----------------------------------------
	//
	result = 
		WeaponMover__GameModel::ReadAndVerify(
			model, 
			attribute_entry, 
			data,
			error,
			error_buffer
		);
	//
	//---------------------------
	//Verify all the model values
	//---------------------------
	//
	switch(attribute_entry->attributeID)
	{
	case MaxTurnAngleAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 1.00f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			else
			{
				model->maxTurnAngle *= Radians_Per_Degree;
			}
			if(model->maxTurnAngle <= 0.0f)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]MaxTurnAngle=%f}: value must be > 0!",
					model->maxTurnAngle
				);
				result = false;
			}
			break;
		}
	
	case ThrusterAccelerationAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 35.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if(model->thrusterAcceleration <= 0.0f)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]ThrusterAcceleration=%f}: value must be > 0!",
					model->thrusterAcceleration
				);
				result = false;
			}
			break;
		}
	case MaxLiveTimeAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 7.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if(model->maxLiveTime <= 0.0f)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]MaxLiveTime=%f}: value must be > 0!",
					model->maxLiveTime
				);
				result = false;
			}
			break;
		}
	case ProximityFuseDistanceAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 2.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}

      //
      // To speed the test up we use the square of this number
      //
      model->proximityFuseDistance *= model->proximityFuseDistance;

			if(model->proximityFuseDistance <= 0.0f)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]ProximityFuseDistance=%f}: value must be > 0!",
					model->proximityFuseDistance
				);
				result = false;
			}
			break;
		}
	}

	return result;
}