/*
	Trampoline Sim.
	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_OBJECT_BASE_H
#define GAME_OBJECT_BASE_H

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

#include "Game\GameObjectManager.h"

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

namespace Game
{
	//=================================================================================================================
	//=================================================================================================================
	
	class GameObjectManager;
	class Camera3D;

	//=================================================================================================================
	/// @brief		Base class for all game entities or game objects
	//=================================================================================================================

	class GameObjectBase : public ObjectBase 
	{
		public:
		
			//=========================================================================================================
			// Friends
			//=========================================================================================================
			
				/// The game object manager is a friend of this class. Only it can set id's for objects.
				
				friend class GameObjectManager;

			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				/// Base class constructor. Initialises the ID and manager of the object
				
				GameObjectBase()
				{ 
					m_id		= GameObjectManager::INVALID_ID; 
					m_manager	= 0;
				}

				/// Update function. called once for every frame. 
				
				#pragma warning(disable:4100)

					virtual void OnUpdate( float time_delta ){}
				
				#pragma warning(default:4100)

				/// Draw function. Makes the object render itself.

				#pragma warning(disable:4100)

					virtual void OnDraw( Camera3D * c ){}
				
				#pragma warning(default:4100)

				/// Called when the object is added into the game object manager
				
				virtual void OnGameAdded(){}
				
				/// Called when the object is removed from the game object manager
				
				virtual void OnGameRemoved(){}
				
				/// Called when a global event is sent through the game object manager to all objects
				
				#pragma warning(disable:4100)
				
					virtual void OnGlobalEvent( unsigned event_id , long event_data ){}
					
				#pragma warning(default:4100)
				
				/// Returns the ID of the game object
				
				inline unsigned GetID(){ return m_id; }
				
				/// Returns the name of the object as a pointer:
				
				inline const char * GetCName(){ return m_name.c_str(); }
				
				/// Returns the name of the object as a reference:
				
				inline const std::string & GetName(){ return m_name; }			
				
				/// Sets the name of the object:
				
				void SetName( const char * name );
				
				/// Sets the name of the object 
				
				inline void SetName( std::string & name ){ SetName(name.c_str()); }
				
				/// Gets the game object manager this object belongs to:
				
				inline GameObjectManager * GetManager(){ return m_manager; }
				
				/// Tells if the game object has a manager, if it has no manager then it is not in the game
				
				inline bool HasManager(){ return m_manager != 0; }
				
		private:
		
			//=========================================================================================================
			// Functions
			//=========================================================================================================		
		
				/// Copying is disallowed
				
				GameObjectBase( const GameObjectBase & other );

				/// Copying is disallowed
				
				GameObjectBase & operator = ( const GameObjectBase & other );				
		
			//=========================================================================================================
			// Variables
			//=========================================================================================================
			
				/// Id of the game object this should be unique in the game
				
				unsigned m_id;
				
				/// Name of the object. Doesn't have to be unique. Names are case insensitive.
				
				std::string m_name;
				
				/// Game object manager the object belongs to
				
				GameObjectManager * m_manager;
	};
};

#endif 
