#include "MW4Headers.hpp"

#include "Beagle.hpp"
#include "Vehicle.hpp"
#include "Sensor.hpp"
#include "SubsystemClassData.hpp"

//#############################################################################
//###############################    Beagle    ##############################
//#############################################################################

Beagle::ClassData*
	Beagle::DefaultData = NULL;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	Beagle::InitializeClass()
{
	Verify(!DefaultData);
	DefaultData =
		new ClassData(
			BeagleClassID,
			"MechWarrior4::Beagle",
			Subsystem::DefaultData,
			0, NULL,
			(Entity::Factory)Make,
			(Entity::CreateMessage::Factory)CreateMessage::ConstructCreateMessage,
			ExecutionStateEngine::DefaultData,
			(Entity::GameModel::Factory)GameModel::ConstructGameModel,
			NULL,
			(Entity::GameModel::ReadAndVerifier)GameModel::ReadAndVerify,
			(Entity::GameModel::ModelWrite)GameModel::WriteToText,
			(Entity::GameModel::ModelSave)GameModel::SaveGameModel,
			(Subsystem::StreamCreate) CreateStream
		);
	Register_Object(DefaultData);

	DIRECT_GAME_MODEL_ATTRIBUTE(
		Beagle__GameModel,
		TargeterMissileLockPercent,
		m_targeterMissileLockPercent,
		Scalar
	);

	DIRECT_GAME_MODEL_ATTRIBUTE(
		Beagle__GameModel,
		HolderMissileLockPercent,
		m_holderMissileLockPercent,
		Scalar
	);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	Beagle::TerminateClass()
{
	Unregister_Object(DefaultData);
	delete DefaultData;
	DefaultData = NULL;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Beagle*
	Beagle::Make(
		CreateMessage *message,
		ReplicatorID *base_id
	)
{
	Check_Object(message);
	gos_PushCurrentHeap(Heap);
	Beagle *new_entity = 
		new Beagle(DefaultData, message, base_id, NULL);
	gos_PopCurrentHeap();
	Check_Object(new_entity);
	return new_entity;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Beagle::Beagle(
	ClassData *class_data,
	CreateMessage *message,
	ReplicatorID *base_id,
	ElementRenderer::Element *element
):
	Subsystem(class_data, message, base_id, element)
{
	Check_Object(message);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	Beagle::DestroySubsystem()
{
	Check_Object(this);
	
	MWObject *vehicle = GetParentVehicle();
	Check_Object(vehicle);
	if(vehicle->IsDerivedFrom(Vehicle::DefaultData))
	{
		Vehicle *parent_vehicle = Cast_Object(Vehicle *, vehicle);
		parent_vehicle->DestroyBeagle();
		Sensor *sensor = parent_vehicle->GetSensor();
		sensor->SetSensorMode(parent_vehicle->GetSensorMode() ,parent_vehicle->DoesHaveBeagle());
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Beagle::~Beagle()
{
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	Beagle::TestInstance() const
{
	Verify(IsDerivedFrom(DefaultData));
}

