//===========================================================================//
// File:	ProjectileWeapon_Tool.cpp										
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 09/09/98  JSE  Inital base class based off of Shadowrun/Adept      
// 09/24/98  BDB  Inital Weapon subsystem class based off of Subsystem_Tool.cpp
// 10/19/98  BDB  Created LauchedWeapon subsytem based off of Weapon		 //
//---------------------------------------------------------------------------//
// Copyright (C) 1998, Fasa Interactive										 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#include "MW4Headers.hpp"

#include "ProjectileWeapon.hpp"
#include "MWTool.hpp"

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

	//
	//--------------
	// Set up stream
	//--------------
	//
	MemoryStream *model_stream = script->modelStream;
	Check_Object(model_stream);
	model_stream->AllocateBytes(sizeof(ProjectileWeapon__GameModel));
	Weapon__GameModel::ConstructGameModel(script);
#if 0
	ProjectileWeapon__GameModel *model =
		Cast_Pointer(ProjectileWeapon__GameModel*, model_stream->GetPointer());

	//
	//------------------------------------
	// Set up the The Beam Entity Resource
	//------------------------------------
	//
	NotationFile *model_file = script->modelFile;
	Check_Object(model_file);
	Check_Object(Tool::Instance);
	Tool::Instance->PushFilePath(model_file);

	model->projectileModelID = ResourceID::Null;
	const char *projectile_entity_name;
	if(model_file->GetEntry("GameData", "ProjectileResource", &projectile_entity_name))
	{
		Resource projectile_resource;
		Tool::Instance->ConstructDataList(&projectile_resource, projectile_entity_name);
		Check_Object(&projectile_resource);
		Verify(projectile_resource.DoesResourceExist());
		model->projectileModelID = projectile_resource.GetResourceID();
	}

	Tool::Instance->PopFilePath();
#endif
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
bool
	ProjectileWeapon__GameModel::ReadAndVerify(
		ProjectileWeapon__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 = 
		Weapon__GameModel::ReadAndVerify(
			model, 
			attribute_entry, 
			data,
			error,
			error_buffer
		);
	//
	//---------------------------
	//Verify all the model values
	//---------------------------
	//
	switch(attribute_entry->attributeID)
	{
	case FireRateAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 1.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if (model->fireRate <= 0)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]FireRate=%f}: value must be > 0!",
					model->fireRate
				);
				result = false;
			}

			break;
		}
	
	case InitialLinearVelocityAttributeID:
		{
			if(!valid_data)
			{
				Vector3D value = Vector3D::Identity;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if (model->initialLinearVelocity.x < 0)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]InitialLinearVelocity=%f %f %f}: value must be > 0!",
					model->initialLinearVelocity.x,
					model->initialLinearVelocity.y,
					model->initialLinearVelocity.z
				);
				result = false;
			}
			break;
		}
	case InitialLinearAccelerationAttributeID:
		{
			if(!valid_data)
			{
				Vector3D value = Vector3D::Identity;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if ((model->initialLinearAcceleration.x < 0) ||
				(model->initialLinearAcceleration.z < 0))
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]InitialLinearAcceleration=%f %f %f}: value must be > 0!",
					model->initialLinearAcceleration.x,
					model->initialLinearAcceleration.y,
					model->initialLinearAcceleration.z
				);
				result = false;
			}
			break;
		}
	case ProjectileModelResourceAttributeID:
		{
			if(!valid_data)
			{
				ResourceID value = ResourceID::Null;
				attribute_entry->SetValue(model, (void *)&value);
				result = true;
			}
			break;
		}
	case TargetLockTimeAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 0.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if (model->targetLockTime < 0)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]TargetLockTime=%f}: value must be >= 0!",
					model->targetLockTime
				);
				result = false;
			}
			break;
		}
	case TimeToPotentialJamAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 0.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if (model->m_timeToPotentialJam < 0)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]TimeToPotentialJam=%f}: value must be >= 0!",
					model->m_timeToPotentialJam
				);
				result = false;
			}
			break;
		}
	case TimeToJamAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 0.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if (model->m_timeToJam < 0)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]TimeToJam=%f}: value must be >= 0!",
					model->m_timeToJam
				);
				result = false;
			}
			break;
		}
	case TimeToUnjamAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 0.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if (model->m_timeToUnjam < 0)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]TimeToUnjam=%f}: value must be >= 0!",
					model->m_timeToUnjam
				);
				result = false;
			}
			break;
		}
	case HeatToJamAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 66.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if (model->m_heatToJam < 0)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]HeatToJam=%f}: value must be >= 0!",
					model->m_heatToJam
				);
				result = false;
			}
			break;
		}
	case HeatToUnjamAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 0.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if (model->m_heatToUnjam < 0)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]HeatToUnjam=%f}: value must be >= 0!",
					model->m_heatToUnjam
				);
				result = false;
			}
			break;
		}
	case TimeToAmmoBayAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 7.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if (model->m_timeToAmmoBay < 0)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]TimeToAmmoBay=%f}: value must be >= 0!",
					model->m_timeToAmmoBay
				);
				result = false;
			}
			break;
		}

	}
	return result;
}
