//===========================================================================//
// File:	DropZone.hpp																	     //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
//	03/09/99  DPB	Created File                  //
//---------------------------------------------------------------------------//
// Copyright (C) 1998, Fasa Interactive										 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#pragma once

#include "Adept.hpp"
#include "Entity.hpp"
#include "EntityClassData.hpp"

namespace Adept
{

	class DropZone__RequestDropMessage;

	//##########################################################################
	//##################    DropZone::CreateMessage    #########################
	//##########################################################################

	class DropZone__CreateMessage:
		public Entity__CreateMessage
	{
	public:
		ResourceID
			dropPointsResourceID;

		DropZone__CreateMessage(
			size_t length,
			int priority,
			int message_flags,
			Stuff::RegisteredClass::ClassID class_id,
			int replicator_flags,
			const ResourceID& data_list_id,
			const Stuff::LinearMatrix4D &creation_matrix,
			Stuff::Scalar age,
			int execution_state,
			int name_id,
			int entity_alignment,
			ResourceID drop_points
		):
			Entity__CreateMessage(
				length, 
				priority, 
				message_flags, 
				class_id,
				replicator_flags,
				data_list_id,
				creation_matrix,
				age,
				execution_state,
				name_id,
				entity_alignment
			),
				dropPointsResourceID(drop_points)
				{}

		static void
			ConstructCreateMessage(Script *script);
	};

	//##########################################################################
	//###########################   DropZone    ################################
	//##########################################################################

	class DropZone:
		public Entity
	{
	public:
		static void
			InitializeClass();
		static void
			TerminateClass();

		typedef Entity BaseClass;

		static ClassData
			*DefaultData;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Inheritance Support
	//
		typedef DropZone__CreateMessage					CreateMessage;
		typedef DropZone__RequestDropMessage			RequestDropMessage;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Run-time Construction and Destruction Support
	//
	public:
		static DropZone* 
			Make(
				CreateMessage *message,
				ReplicatorID *base_id
			);
		Replicator::CreateMessage*
			SaveMakeMessage(Stuff::MemoryStream *stream, ResourceFile *res_file);
		void
			SaveInstanceText(Stuff::Page *page);
		void
			SavePointsFile(const char *file_name);

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

		~DropZone();

	public:
		Stuff::LinearMatrix4D RequestDrop(void);
	

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Simulation Support
	//

	public:
		int chainSize;

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

		enum{
			Null = -1,
			NextDropZoneID
		};

		ResourceID dropPointsResourceID;

		typedef Stuff::PlugOf<Stuff::LinearMatrix4D> MatrixPlug; 

		Stuff::ChainOf<MatrixPlug *>	dropMats;
		Stuff::ChainOf<MatrixPlug *>	origDropMats;

		bool
			IsWithin(
				Entity *target,
				Stuff::Scalar distance,
				bool ignorey = false
			);

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


}


