// ---------------------------------------------------------------------------
// 
//   Lily Engine alpha
// 
//   Copyright (c) 2010 Clifford Jolly
//     http://cliffjolly.com
//     cliff@cliffjolly.com
// 
// ---------------------------------------------------------------------------
// 
//   This program is free software; you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation; either version 2 of the License, or
//   (at your option) any later version.
//  
//   This program is distributed in the hope that it will be useful, but
//   WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//   General Public License for more details.
// 
//   You should have received a copy of the GNU General Public License
//   along with this program; if not, write to the Free Software
//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
//   USA
// -------------------------- END HEADER -------------------------------------

#pragma once

#include "boundingbox.h"
#include "entity.h"
#include "polygon.h"

/** @brief Static terrain block. Uses a polygon shape. Blocks movement,
 * and is editable in the editor. Generally doesn't move or do anything
 * fancy beyond that. */
class TerrainBlock : public Entity {
	
	public:
	
		/** @brief Constructor.
		 * @param world The world to attach this to.
		 * */
		TerrainBlock(World *world);
		
		/** @brief Constructor for loading XML levels.
		 * @param world The World to attach this to.
		 * @param xml An XML element containing Entity information with
		 *   child elements containing polygon data.
		 * */
		TerrainBlock(World *world, TiXmlElement *xml);
		
		/** @brief Render the object.
		 * @note This should probably only do something in the editor.
		 * */
		void draw(void) const;
		
		/** @brief Standard Entity update. */
		void update(void);
		
		/** @brief Get the bounding box (cached).
		 * @return The bounding box of this object the last time
		 *   buildBoundingBox() was called.
		 * */
		BoundingBox getBoundingBox(void) const;
		
		/** @brief Get the polygon for this block.
		 * @return Pretty much the same Polygon that it stores inside.
		 * */
		Polygon getCollisionArea(void) const;
		
		/** @brief Rebuild the bounding box. Do this any time it
		 * changes shape or is moved. */
		void buildBoundingBox(void);
		
		// Inherited from Entity.
		void setPos(const Vector2D &pos);
		void collided(Entity *otherEnt);
		void updateEditor(EditorUI *ui);
		void updateFromEditor(EditorUI *ui);
			
		/** @brief The Polygon adds extra child data to the XML
		 * element. */
		TiXmlElement *toXml(void) const;
		
		/// Set this to true to make it one of those platforms that characters can jump up through but also stand on.
		bool blocksDownOnly;
		
	private:
	
		BoundingBox box;
		Polygon poly;
		
		// The editor can edit polygons directly. Nothing else has that
		// excuse to mess around with the private parts in here.
		friend class EditorUI;
};
