
#include "MW4Headers.hpp"

#include "InputTrainer.hpp"
#include "VehicleInterface.hpp"
#include "Torso.hpp"



using namespace MechWarrior4;

InputTrainer* InputTrainer::m_Instance = 0;

InputTrainer* InputTrainer::GetInstance()
{
	return (m_Instance);
}

InputTrainer::InputTrainer()
	: m_Flags(ALL)
{
	Verify(m_Instance == 0);
	m_Instance = this;
}

InputTrainer::~InputTrainer()
{
	Verify(m_Instance == this);
	m_Instance = 0;
}

bool InputTrainer::GetEnabled(InputType t) const
{
	return ((m_Flags & t) != 0);
}

void InputTrainer::SetEnabled(InputType t, bool enabled)
{
	if (enabled == true)
	{
		m_Flags |= t;
	}
	else
	{
		m_Flags &= ~t;
	}

	if ((VehicleInterface::GetInstance() != 0) &&
		(VehicleInterface::GetInstance()->vehicle != 0))
	{
		Vehicle* v = VehicleInterface::GetInstance()->vehicle;

		if (GetEnabled(THROTTLE) == false)
		{
			v->speedDemand = 0.0f;
		}

		if ((GetEnabled(TORSO) == false) &&
			(v->GetTorso() != 0))
		{
			v->GetTorso()->pitchDemand = 0.0f;
			v->GetTorso()->yawDemand = 0.0f;
		}

		if (GetEnabled(TURN) == false)
		{
			v->yawDemand = 0.0f;
		}
	}
}
