//===========================================================================//
// File:	Buidling.hpp													
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 05/06/99  DPB  Inital base class
//---------------------------------------------------------------------------//
// Copyright (C) 1998, Fasa Interactive										 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#pragma once

#include "MW4.hpp"
#include "MWObject.hpp"

namespace MechWarrior4
{
	
	extern DWORD Executed_NonCom_Count;

	//##########################################################################
	//###########################   NonCom    ################################
	//##########################################################################

	typedef MWObject__ClassData							NonCom__ClassData;
	typedef MWObject__Message							NonCom__Message;
	typedef MWObject__ExecutionStateEngine				NonCom__ExecutionStateEngine;
	typedef MWObject__CreateMessage						NonCom__CreateMessage;
	typedef MWObject__GameModel							NonCom__GameModel;
	

	class NonCom: public MWObject
	{
	public:
		static void InitializeClass();
		static void TerminateClass();

	//##########################################################################
	// Inheritance support
	//
	public:
		typedef NonCom__ClassData								ClassData;
		typedef NonCom__GameModel								GameModel;
		typedef NonCom__Message								Message;
		typedef NonCom__ExecutionStateEngine					ExecutionStateEngine;
		typedef NonCom__CreateMessage							CreateMessage;


	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Run-time Construction and Destruction Support
	//
	public:
		static NonCom* Make(CreateMessage *message,ReplicatorID *base_id);
	
		void CommonCreation(CreateMessage *message);
		void Respawn(Adept::Entity::CreateMessage *message);

	protected:
		NonCom(ClassData *class_data,CreateMessage *message,ReplicatorID *base_id,ElementRenderer::Element *element);

		~NonCom();

		void Reuse(const CreateMessage *message,ReplicatorID *base_id);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Class Data & Game Model Support
	//
	protected:
		Stuff::Time m_FrameTime;
		Stuff::Point3D m_UVs[4];
		int m_AnimFrame;
		int m_TextureID;
		Stuff::Scalar m_Speed;
		int m_LastIndex;
		Stuff::AffineMatrix4D UVMatrix;
		Stuff::Point3D m_LastPos;
		Stuff::Scalar m_LastFacing;
		enum {
			UVMatrixAttributeID = BaseClass::NextAttributeID,
			NextAttributeID
		};

		bool m_IsAnimal;
		bool m_Visible;

	public:
		virtual void TurnOn (void);
		virtual void TurnOff (void);

		void DetermineUV (Stuff::Time till);
		void Speed (Stuff::Scalar speed)
		{ m_Speed = speed<0 ? speed*-1.0f : speed; }
		void TextureID (int id)
		{ m_TextureID = id;  }

		virtual bool				// TEMPORARY until Fang fixes the SlidingShapeComponent NonCom bug -- PAULTOZ
			IsNonCom() const
				{	return (true);	}

		void SetAsAnimal();

	private:
		Stuff::Scalar FrameWidth() const;
		Stuff::Scalar FrameHeight() const;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Damage/Destruction Support
	//
	public:
		void ReactToHit(const Adept::Entity__TakeDamageMessage *message,Adept::DamageObject *part_hit);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Shared Data support
	//
	public:
		static ClassData *DefaultData;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Simulation Support
	//
	public:
		void PreCollisionExecute(Stuff::Time till);
		void ReactToDestruction(int damage_mode, int damage_type);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Test Support
	//
	public:
		void TestInstance() const;
	};
}


