#include "MW4Headers.hpp"

#include "HeatSink.hpp"
#include "MWTool.hpp"


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

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

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
bool
	HeatSink__GameModel::ReadAndVerify(
		HeatSink__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 = 
		Subsystem__GameModel::ReadAndVerify(
			model, 
			attribute_entry, 
			data,
			error,
			error_buffer
		);
	//
	//---------------------------
	//Verify all the model values
	//---------------------------
	//
	switch(attribute_entry->attributeID)
	{
	case HeatSinkPointsAttributeID:
		{
			if(!valid_data)
			{
				Scalar value = 1.0f;
				attribute_entry->SetValue(model, &value);
				result = true;
			}
			if(model->m_heatSinkPoints < 0.0f)
			{
				_snprintf(
					*error,
					error_buffer,
					"{[GameData]HeatSinkPoints=%f}: value must be >= 0!",
					model->m_heatSinkPoints
				);
				result = false;
			}
			break;
		}
	}
	return result;
}
