/*
	Lan Wars.
	Copyright (c) 2009, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
	ARE DISCLAIMED. IN NO EVENT SHALL DARRAGH COY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
	OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef GAME_BUILD_PATH_SUBSECTOR_H
#define GAME_BUILD_PATH_SUBSECTOR_H

//=====================================================================================================================
//=====================================================================================================================

namespace Game
{	
	//=================================================================================================================
	//=================================================================================================================
	
	struct DoomGLSubsectorV2;
	class DoomLevel;
	class BuildPathNode;

	//=================================================================================================================
	/// @brief		Represents a subsector in the doom level. This structure is used as a helper class to help build
	///				the path network; it holds inter-connectivity information with other subsectors in the level.
	//=================================================================================================================

	class BuildPathSubsector
	{
		public:
			
			//=========================================================================================================
			// Functions
			//=========================================================================================================
		
				//=====================================================================================================	
				/// @brief		Creates the path subsector
				/// @param		level - level the subsector belongs to
				/// @param		subsector - subsector this is in the level
				//=====================================================================================================
				
				BuildPathSubsector( const DoomLevel & level , const DoomGLSubsectorV2 & subsector );
				
				//=====================================================================================================
				/// @brief		Sets the closest node to this subsector
				/// @param		n - closest node to this subsector
				//=====================================================================================================
				
				inline void SetClosestNode( BuildPathNode * n ){ m_closest_node = n; }

				//=====================================================================================================
				/// @brief		Gets the closest node to this subsector
				/// @returns	The closest node to this subsector
				//=====================================================================================================
				
				inline BuildPathNode * GetClosestNode(){ return m_closest_node; }
				
				//=====================================================================================================
				/// @brief		Tells if there is a closest node to this subsector
				/// @returns	True if there is a closest node to this subsector
				//=====================================================================================================
				
				inline bool HasClosestNode() const { return m_closest_node != 0; }
				
				//=====================================================================================================
				/// @brief		Returns the center of this subsector
				/// @returns	Center of the subsector
				//=====================================================================================================
				
				inline const Vec2f & GetCenter() const { return m_center; }
				
				//=====================================================================================================
				/// @brief		Returns the array of connected subsectors to this subsector that we can reach from
				///				this subsector.
				/// @returns	The subsector array
				//=====================================================================================================
				
				inline const std::vector<const DoomGLSubsectorV2*> & GetConnectedSubsectors() const 
				{
					return m_connected_subsectors;
				}
				
				//=====================================================================================================
				/// @brief		Returns the doom subsector that this node network subsector reprsents
				/// @returns	The doom subsector
				//=====================================================================================================
				
				inline const DoomGLSubsectorV2 & GetDoomSubsector() const { return * m_subsector; }
				
				/// Tells if it is possible to traverse from this subsector to the given subsector
				
				bool CanTraverseTo( const DoomGLSubsectorV2 & other ) const;				
				
		private:

			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				/// Builds a list of other subsectors that the path subsector is directly connected to
				
				void BuildConnectedSubsectorsList();
				
				/// Calculates the center of the subsector
				
				void FindSubsectorCenter();			

			//=========================================================================================================
			// Variables
			//=========================================================================================================
			
				/// This is the doom level the path node belongs to
				
				const DoomLevel * m_level;
				
				/// This is the doom subsector that this susbector in the path network represents
				
				const DoomGLSubsectorV2 * m_subsector;
				
				/// This is the closest path node to this subsector
				
				BuildPathNode * m_closest_node;
				
				/// This is a list of subsectors that this subsector is directly connected to
				
				std::vector<const DoomGLSubsectorV2*> m_connected_subsectors;
				
				/// This is the center of the subsector
				
				Vec2f m_center;
	};
};

#endif
