//===========================================================================//
// File:	MissileWeapon_Tool.cpp										
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
//---------------------------------------------------------------------------//
// Copyright (C) 1998, Fasa Interactive										 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#include "MW4Headers.hpp"

#include "LBXWeaponSub.hpp"
#include "MWTool.hpp"

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

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

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
bool
	LBXWeaponSub__GameModel::ReadAndVerify(
		LBXWeaponSub__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 = 
		ProjectileWeapon__GameModel::ReadAndVerify(
			model, 
			attribute_entry, 
			data,
			error,
			error_buffer
		);
	//
	//---------------------------
	//Verify all the model values
	//---------------------------
	//
	switch(attribute_entry->attributeID)
	{
	case DisipationStartAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 100.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if(model->m_disipationStart < 0.0f)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]DisipationStart=%f}: value must be > 0!",
					model->m_disipationStart
				);
				result = false;
			}
			break;
		}
	case MaxDisipationAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 1.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if(model->m_maxDisipation < 0.0f)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]MaxDisipation=%f}: value must be > 0!",
					model->m_maxDisipation
				);
				result = false;
			}
			break;
		}
	}

	return result;
}