//===========================================================================//
// 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"
#include "SensorCellMap.hpp"

namespace MechWarrior4
{
	
	extern DWORD Executed_Building_Count;

	//##########################################################################
	//###########################   Building    ################################
	//##########################################################################

	typedef MWObject__ClassData							Building__ClassData;
	typedef MWObject__Message							Building__Message;
	typedef MWObject__ExecutionStateEngine				Building__ExecutionStateEngine;
	typedef MWObject__CreateMessage						Building__CreateMessage;
	typedef MWObject__GameModel							Building__GameModel;
	

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

	//##########################################################################
	// Inheritance support
	//
	public:
		typedef Building__ClassData								ClassData;
		typedef Building__GameModel								GameModel;
		typedef Building__Message								Message;
		typedef Building__ExecutionStateEngine					ExecutionStateEngine;
		typedef Building__CreateMessage							CreateMessage;


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

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

		~Building();

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

		
		void
			LoadAnimationScripts();

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Class Data & Game Model Support
	//
	public:
		virtual void TurnOn (void);
		virtual void TurnOff (void);

		int
			GetTableArray()
				{Check_Object(this); return Adept::NameTable::BuildingArray;}

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// 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:
		int
			GetExecutionSlot();

		void
			PreCollisionExecute(Stuff::Time till);
		#if defined(LAB_ONLY)
			void
				SyncMatrices(bool update_matrix);
		#endif

		virtual
			//I need over ride ReactToDestruction in Turret to score them seperatly
		void
			ReactToDestruction(int damage_mode, int damage_type);

		Stuff::Scalar
			FriendlyFireDamageMultiplier() const;

		virtual void
			GetLineOfSight(Stuff::LinearMatrix4D& line_of_sight);

		bool m_AddedToSensorCellMap;

		//should this building be scored?
		bool m_scoreThisBuilding;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Sensor Cell Map Support
	//
		static bool
			m_BuildingsAddedToCellMap;

		static void
			AddAllBuildingsToSensorCellMap();

		static void
			RemoveAllBuildingsFromSensorCellMap();

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


