//===========================================================================//
// File:	vtvpwr.hh                                                           //
// Project: Red Planet                                                       //
// Contents: Interface specification for vectored thrust vehicles            //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 01/23/95  JMA  Initial coding.                                            //
//---------------------------------------------------------------------------//
// Copyright (C) 1995, Virtual World Entertainment, Inc.                     //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#if !defined(THRUSTER_HPP)
#	define THRUSTER_HPP

#	if !defined(VTVSUB_HPP)
#		include <vtvsub.hpp>
#	endif

	class Joint;

	//##########################################################################
	//##################    Thruster::SubsystemResource    #####################
	//##########################################################################

	struct Thruster__SubsystemResource:
		public Subsystem::SubsystemResource
	{
		int 	jointIndex;
		Scalar maxThrusterRotationRate;
		Logical primeThruster;
	};

	//##########################################################################
	//###################    Thruster::UpdateRecord         ####################
	//##########################################################################

	struct Thruster__UpdateRecord :
		public VTVSubsystem::UpdateRecord
	{
		Scalar
			thrusterRotation;
	};

	//##########################################################################
	//############################    Thruster    ##############################
	//##########################################################################

	class Thruster:
		public Subsystem
	{
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Shared Data support
	//
	public:
		static Derivation ClassDerivations;
		static SharedData DefaultData;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Message Support
	//
	#if 0
	private:
		static const HandlerEntry MessageHandlerEntries[];

	protected:
		static MessageHandlerSet MessageHandlers;
	#endif

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Attribute Support
	//
	public:
		enum {
			ThrusterOffsetAttributeID = Subsystem::NextAttributeID,
			ThrusterPositionAttributeID,
			CurrentAccelerationAttributeID,
			CurrentHeightAttributeID,
			MaxThrusterRotationRateAttributeID,
			MomentArmAttributeID,
			MomentArmLengthAttributeID,
			NextAttributeID
		};

	private:
		static const IndexEntry AttributePointers[];

	protected:
		static AttributeIndexSet	AttributeIndex;

	//
	// public attribute declarations go here
	//
	public:
		Point3D thrusterOffset;
		Joint *thrusterPosition;
		Scalar
			currentAcceleration,
			currentHeight,
			maxThrusterRotationRate,
			powerScale,
			momentArmLength;
		Vector3D
			momentArm;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Model Support
	//
	public:
		typedef void
			(Thruster::*Performance)(Scalar time_slice);
		typedef Thruster__UpdateRecord UpdateRecord;

		void
			PrimeThruster(Scalar time_slice);
		void
			SlaveThruster(Scalar time_slice);
		void
			PrimeDeadReckon(Scalar time_slice);
		void
			SlaveDeadReckon(Scalar time_slice);

		void
			SetPerformance(Performance performance)
				{
					Check(this);
					activePerformance = (Simulation::Performance)performance;
				}

		VTV*
			GetEntity()
				{Check(this); return Cast_Object(VTV*, Subsystem::GetEntity());}

	protected:
		void
			WriteUpdateRecord(Simulation::UpdateRecord *message, int update_model);
		void
			ReadUpdateRecord(Simulation::UpdateRecord *message);

		Scalar
			updatedPosition;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Construction and Destruction
	//
	public:
		typedef Thruster__SubsystemResource SubsystemResource;
		Thruster(
			VTV *owner,
         int subsystem_ID,
			SubsystemResource *subsystem_resource
		);
		~Thruster();

		Logical
      	TestInstance() const;
	};

#endif
