| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * CMapEditManager.h, part of VCMI engine | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Authors: listed in file AUTHORS in main folder | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * License: GNU General Public License v2.0 or later | 
					
						
							|  |  |  |  * Full text of license available in license.txt file, in main folder | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "../CRandomGenerator.h"
 | 
					
						
							| 
									
										
										
										
											2015-12-02 21:05:10 +02:00
										 |  |  | #include "../int3.h"
 | 
					
						
							|  |  |  | #include "../GameConstants.h"
 | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class CGObjectInstance; | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | class CTerrainViewPatternConfig; | 
					
						
							| 
									
										
										
										
											2013-04-21 12:49:26 +00:00
										 |  |  | struct TerrainViewPattern; | 
					
						
							| 
									
										
										
										
											2015-12-02 21:05:10 +02:00
										 |  |  | class CMap; | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | /// Represents a map rectangle.
 | 
					
						
							|  |  |  | struct DLL_LINKAGE MapRect | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-22 14:49:28 +00:00
										 |  |  | 	MapRect(); | 
					
						
							|  |  |  | 	MapRect(int3 pos, si32 width, si32 height); | 
					
						
							|  |  |  | 	si32 x, y, z; | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 	si32 width, height; | 
					
						
							| 
									
										
										
										
											2013-04-22 14:49:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	si32 left() const; | 
					
						
							|  |  |  | 	si32 right() const; | 
					
						
							|  |  |  | 	si32 top() const; | 
					
						
							|  |  |  | 	si32 bottom() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int3 topLeft() const; /// Top left corner of this rect.
 | 
					
						
							|  |  |  | 	int3 topRight() const; /// Top right corner of this rect.
 | 
					
						
							|  |  |  | 	int3 bottomLeft() const; /// Bottom left corner of this rect.
 | 
					
						
							|  |  |  | 	int3 bottomRight() const; /// Bottom right corner of this rect.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/// Returns a MapRect of the intersection of this rectangle and the given one.
 | 
					
						
							|  |  |  | 	MapRect operator&(const MapRect & rect) const; | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	template<typename Func> | 
					
						
							|  |  |  | 	void forEach(Func f) const | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2013-05-03 10:15:59 +00:00
										 |  |  | 		for(int j = y; j < bottom(); ++j) | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2013-05-03 10:15:59 +00:00
										 |  |  | 			for(int i = x; i < right(); ++i) | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				f(int3(i, j, z)); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// Generic selection class to select any type
 | 
					
						
							|  |  |  | template<typename T> | 
					
						
							|  |  |  | class DLL_LINKAGE CMapSelection | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	explicit CMapSelection(CMap * map) : map(map) { } | 
					
						
							|  |  |  | 	virtual ~CMapSelection() { }; | 
					
						
							|  |  |  | 	void select(const T & item) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		selectedItems.insert(item); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	void deselect(const T & item) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		selectedItems.erase(item); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	std::set<T> getSelectedItems() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return selectedItems; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	CMap * getMap() { return map; } | 
					
						
							|  |  |  | 	virtual void selectRange(const MapRect & rect) { } | 
					
						
							|  |  |  | 	virtual void deselectRange(const MapRect & rect) { } | 
					
						
							|  |  |  | 	virtual void selectAll() { } | 
					
						
							|  |  |  | 	virtual void clearSelection() { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	std::set<T> selectedItems; | 
					
						
							|  |  |  | 	CMap * map; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// Selection class to select terrain.
 | 
					
						
							|  |  |  | class DLL_LINKAGE CTerrainSelection : public CMapSelection<int3> | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	explicit CTerrainSelection(CMap * map); | 
					
						
							|  |  |  | 	void selectRange(const MapRect & rect) override; | 
					
						
							|  |  |  | 	void deselectRange(const MapRect & rect) override; | 
					
						
							|  |  |  | 	void selectAll() override; | 
					
						
							|  |  |  | 	void clearSelection() override; | 
					
						
							| 
									
										
										
										
											2014-05-24 14:06:08 +02:00
										 |  |  | 	void setSelection(std::vector<int3> & vec); | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// Selection class to select objects.
 | 
					
						
							|  |  |  | class DLL_LINKAGE CObjectSelection: public CMapSelection<CGObjectInstance *> | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	explicit CObjectSelection(CMap * map); | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// The abstract base class CMapOperation defines an operation that can be executed, undone and redone.
 | 
					
						
							| 
									
										
										
										
											2013-04-22 14:49:28 +00:00
										 |  |  | class DLL_LINKAGE CMapOperation : public boost::noncopyable | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 	explicit CMapOperation(CMap * map); | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 	virtual ~CMapOperation() { }; | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 	virtual void execute() = 0; | 
					
						
							|  |  |  | 	virtual void undo() = 0; | 
					
						
							|  |  |  | 	virtual void redo() = 0; | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 	virtual std::string getLabel() const = 0; /// Returns a display-able name of the operation.
 | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 19:16:21 +02:00
										 |  |  | 	static const int FLIP_PATTERN_HORIZONTAL = 1; | 
					
						
							|  |  |  | 	static const int FLIP_PATTERN_VERTICAL = 2; | 
					
						
							|  |  |  | 	static const int FLIP_PATTERN_BOTH = 3; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-03 05:03:44 +03:00
										 |  |  | protected:	 | 
					
						
							|  |  |  | 	MapRect extendTileAround(const int3 & centerPos) const; | 
					
						
							|  |  |  | 	MapRect extendTileAroundSafely(const int3 & centerPos) const; /// doesn't exceed map size	
 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 	CMap * map; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// The CMapUndoManager provides the functionality to save operations and undo/redo them.
 | 
					
						
							| 
									
										
										
										
											2013-04-22 14:49:28 +00:00
										 |  |  | class DLL_LINKAGE CMapUndoManager : boost::noncopyable | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	CMapUndoManager(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void undo(); | 
					
						
							|  |  |  | 	void redo(); | 
					
						
							|  |  |  | 	void clearAll(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/// The undo redo limit is a number which says how many undo/redo items can be saved. The default
 | 
					
						
							|  |  |  | 	/// value is 10. If the value is 0, no undo/redo history will be maintained.
 | 
					
						
							|  |  |  | 	int getUndoRedoLimit() const; | 
					
						
							|  |  |  | 	void setUndoRedoLimit(int value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const CMapOperation * peekRedo() const; | 
					
						
							|  |  |  | 	const CMapOperation * peekUndo() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-29 05:43:33 +03:00
										 |  |  | 	void addOperation(std::unique_ptr<CMapOperation> && operation); /// Client code does not need to call this method.
 | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2015-12-29 05:43:33 +03:00
										 |  |  | 	typedef std::list<std::unique_ptr<CMapOperation> > TStack; | 
					
						
							| 
									
										
										
										
											2013-01-26 13:48:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-22 14:49:28 +00:00
										 |  |  | 	void doOperation(TStack & fromStack, TStack & toStack, bool doUndo); | 
					
						
							|  |  |  | 	const CMapOperation * peek(const TStack & stack) const; | 
					
						
							| 
									
										
										
										
											2013-01-26 13:48:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 	TStack undoStack; | 
					
						
							|  |  |  | 	TStack redoStack; | 
					
						
							|  |  |  | 	int undoRedoLimit; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | /// The map edit manager provides functionality for drawing terrain and placing
 | 
					
						
							|  |  |  | /// objects on the map.
 | 
					
						
							| 
									
										
										
										
											2013-04-20 11:34:01 +00:00
										 |  |  | class DLL_LINKAGE CMapEditManager : boost::noncopyable | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	CMapEditManager(CMap * map); | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 	CMap * getMap(); | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/// Clears the terrain. The free level is filled with water and the underground level with rock.
 | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 	void clearTerrain(CRandomGenerator * gen = nullptr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/// Draws terrain at the current terrain selection. The selection will be cleared automatically.
 | 
					
						
							|  |  |  | 	void drawTerrain(ETerrainType terType, CRandomGenerator * gen = nullptr); | 
					
						
							| 
									
										
										
										
											2015-01-03 02:29:42 +03:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/// Draws roads at the current terrain selection. The selection will be cleared automatically.
 | 
					
						
							|  |  |  | 	void drawRoad(ERoadType::ERoadType roadType, CRandomGenerator * gen = nullptr); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	void insertObject(CGObjectInstance * obj, const int3 & pos);	 | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 	CTerrainSelection & getTerrainSelection(); | 
					
						
							|  |  |  | 	CObjectSelection & getObjectSelection(); | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	CMapUndoManager & getUndoManager(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2015-12-29 05:43:33 +03:00
										 |  |  | 	void execute(std::unique_ptr<CMapOperation> && operation); | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	CMap * map; | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 	CMapUndoManager undoManager; | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 	CRandomGenerator gen; | 
					
						
							|  |  |  | 	CTerrainSelection terrainSel; | 
					
						
							|  |  |  | 	CObjectSelection objectSel; | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ---------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /* Implementation/Detail classes, Private API */ | 
					
						
							|  |  |  | /* ---------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | /// The CComposedOperation is an operation which consists of several operations.
 | 
					
						
							|  |  |  | class CComposedOperation : public CMapOperation | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	CComposedOperation(CMap * map); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void execute() override; | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-29 05:43:33 +03:00
										 |  |  | 	void addOperation(std::unique_ptr<CMapOperation> && operation); | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2015-12-29 05:43:33 +03:00
										 |  |  | 	std::list<std::unique_ptr<CMapOperation> > operations; | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-22 14:49:28 +00:00
										 |  |  | namespace ETerrainGroup | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	enum ETerrainGroup | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		NORMAL, | 
					
						
							|  |  |  | 		DIRT, | 
					
						
							|  |  |  | 		SAND, | 
					
						
							|  |  |  | 		WATER, | 
					
						
							|  |  |  | 		ROCK | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | /// The terrain view pattern describes a specific composition of terrain tiles
 | 
					
						
							|  |  |  | /// in a 3x3 matrix and notes which terrain view frame numbers can be used.
 | 
					
						
							| 
									
										
										
										
											2013-04-22 14:49:28 +00:00
										 |  |  | struct DLL_LINKAGE TerrainViewPattern | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct WeightedRule | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-08-11 07:49:08 +02:00
										 |  |  | 		WeightedRule(std::string &Name); | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 		/// Gets true if this rule is a standard rule which means that it has a value of one of the RULE_* constants.
 | 
					
						
							| 
									
										
										
										
											2016-08-11 09:20:50 +02:00
										 |  |  | 		inline bool isStandardRule() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return standardRule; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		inline bool isAnyRule() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return anyRule; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		inline bool isDirtRule() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return dirtRule; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		inline bool isSandRule() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return sandRule; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		inline bool isTransition() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return transitionRule; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		inline bool isNativeStrong() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return nativeStrongRule; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		inline bool isNativeRule() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return nativeRule; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		void setNative(); | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/// The name of the rule. Can be any value of the RULE_* constants or a ID of a another pattern.
 | 
					
						
							| 
									
										
										
										
											2016-08-11 09:20:50 +02:00
										 |  |  | 		//FIXME: remove string variable altogether, use only in constructor
 | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 		std::string name; | 
					
						
							|  |  |  | 		/// Optional. A rule can have points. Patterns may have a minimum count of points to reach to be successful.
 | 
					
						
							|  |  |  | 		int points; | 
					
						
							| 
									
										
										
										
											2016-08-11 07:49:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	private:		 | 
					
						
							|  |  |  | 		bool standardRule; | 
					
						
							| 
									
										
										
										
											2016-08-11 09:20:50 +02:00
										 |  |  | 		bool anyRule; | 
					
						
							|  |  |  | 		bool dirtRule; | 
					
						
							|  |  |  | 		bool sandRule; | 
					
						
							|  |  |  | 		bool transitionRule; | 
					
						
							|  |  |  | 		bool nativeStrongRule; | 
					
						
							|  |  |  | 		bool nativeRule; | 
					
						
							| 
									
										
										
										
											2016-08-11 07:49:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		WeightedRule(); //only allow string constructor
 | 
					
						
							| 
									
										
										
										
											2013-01-26 13:48:20 +00:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-03 10:15:59 +00:00
										 |  |  | 	static const int PATTERN_DATA_SIZE = 9; | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 	/// Constant for the flip mode different images. Pattern will be flipped and different images will be used(mapping area is divided into 4 parts)
 | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | 	static const std::string FLIP_MODE_DIFF_IMAGES; | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 	/// Constant for the rule dirt, meaning a dirty border is required.
 | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | 	static const std::string RULE_DIRT; | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 	/// Constant for the rule sand, meaning a sandy border is required.
 | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | 	static const std::string RULE_SAND; | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 	/// Constant for the rule transition, meaning a dirty OR sandy border is required.
 | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | 	static const std::string RULE_TRANSITION; | 
					
						
							| 
									
										
										
										
											2013-05-03 10:15:59 +00:00
										 |  |  | 	/// Constant for the rule native, meaning a native border is required.
 | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | 	static const std::string RULE_NATIVE; | 
					
						
							| 
									
										
										
										
											2013-05-03 10:15:59 +00:00
										 |  |  | 	/// Constant for the rule native strong, meaning a native type is required.
 | 
					
						
							|  |  |  | 	static const std::string RULE_NATIVE_STRONG; | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 	/// Constant for the rule any, meaning a native type, dirty OR sandy border is required.
 | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | 	static const std::string RULE_ANY; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TerrainViewPattern(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 	/// The pattern data can be visualized as a 3x3 matrix:
 | 
					
						
							|  |  |  | 	/// [ ][ ][ ]
 | 
					
						
							|  |  |  | 	/// [ ][ ][ ]
 | 
					
						
							|  |  |  | 	/// [ ][ ][ ]
 | 
					
						
							|  |  |  | 	///
 | 
					
						
							|  |  |  | 	/// The box in the center belongs always to the native terrain type and
 | 
					
						
							|  |  |  | 	/// is the point of origin. Depending on the terrain type different rules
 | 
					
						
							|  |  |  | 	/// can be used. Their meaning differs also from type to type.
 | 
					
						
							|  |  |  | 	///
 | 
					
						
							|  |  |  | 	/// std::vector -> several rules can be used in one cell
 | 
					
						
							| 
									
										
										
										
											2013-05-03 10:15:59 +00:00
										 |  |  | 	std::array<std::vector<WeightedRule>, PATTERN_DATA_SIZE> data; | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 	/// The identifier of the pattern, if it's referenced from a another pattern.
 | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | 	std::string id; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | 	/// This describes the mapping between this pattern and the corresponding range of frames
 | 
					
						
							|  |  |  | 	/// which should be used for the ter view.
 | 
					
						
							|  |  |  | 	///
 | 
					
						
							|  |  |  | 	/// std::vector -> size=1: typical, size=2: if this pattern should map to two different types of borders
 | 
					
						
							|  |  |  | 	/// std::pair   -> 1st value: lower range, 2nd value: upper range
 | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | 	std::vector<std::pair<int, int> > mapping; | 
					
						
							| 
									
										
										
										
											2013-04-26 15:57:47 +00:00
										 |  |  | 	/// If diffImages is true, different images/frames are used to place a rotated terrain view. If it's false
 | 
					
						
							|  |  |  | 	/// the same frame will be used and rotated.
 | 
					
						
							|  |  |  | 	bool diffImages; | 
					
						
							|  |  |  | 	/// The rotationTypesCount is only used if diffImages is true and holds the number how many rotation types(horizontal, etc...)
 | 
					
						
							|  |  |  | 	/// are supported.
 | 
					
						
							|  |  |  | 	int rotationTypesCount; | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-25 16:09:48 +00:00
										 |  |  | 	/// The minimum and maximum points to reach to validate the pattern successfully.
 | 
					
						
							|  |  |  | 	int minPoints, maxPoints; | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-16 13:16:58 +00:00
										 |  |  | /// The terrain view pattern config loads pattern data from the filesystem.
 | 
					
						
							| 
									
										
										
										
											2013-04-22 14:49:28 +00:00
										 |  |  | class DLL_LINKAGE CTerrainViewPatternConfig : public boost::noncopyable | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2016-08-12 21:40:22 +02:00
										 |  |  | 	typedef std::vector<TerrainViewPattern> TVPVector; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-17 12:46:48 +00:00
										 |  |  | 	CTerrainViewPatternConfig(); | 
					
						
							|  |  |  | 	~CTerrainViewPatternConfig(); | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 21:40:22 +02:00
										 |  |  | 	const std::vector<TVPVector> & getTerrainViewPatternsForGroup(ETerrainGroup::ETerrainGroup terGroup) const; | 
					
						
							| 
									
										
										
										
											2013-05-03 10:15:59 +00:00
										 |  |  | 	boost::optional<const TerrainViewPattern &> getTerrainViewPatternById(ETerrainGroup::ETerrainGroup terGroup, const std::string & id) const; | 
					
						
							| 
									
										
										
										
											2016-08-12 21:40:22 +02:00
										 |  |  | 	boost::optional<const TVPVector &> getTerrainViewPatternsById(ETerrainGroup::ETerrainGroup terGroup, const std::string & id) const; | 
					
						
							|  |  |  | 	const TVPVector * getTerrainTypePatternById(const std::string & id) const; | 
					
						
							| 
									
										
										
										
											2013-04-22 14:49:28 +00:00
										 |  |  | 	ETerrainGroup::ETerrainGroup getTerrainGroup(const std::string & terGroup) const; | 
					
						
							| 
									
										
										
										
											2016-08-12 19:16:21 +02:00
										 |  |  | 	void flipPattern(TerrainViewPattern & pattern, int flip) const; | 
					
						
							| 
									
										
										
										
											2013-01-26 13:48:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2016-08-12 21:40:22 +02:00
										 |  |  | 	std::map<ETerrainGroup::ETerrainGroup, std::vector<TVPVector> > terrainViewPatterns; | 
					
						
							|  |  |  | 	std::map<std::string, TVPVector> terrainTypePatterns; | 
					
						
							| 
									
										
										
										
											2013-01-06 19:30:12 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-22 15:08:04 +00:00
										 |  |  | /// The CDrawTerrainOperation class draws a terrain area on the map.
 | 
					
						
							|  |  |  | class CDrawTerrainOperation : public CMapOperation | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 	CDrawTerrainOperation(CMap * map, const CTerrainSelection & terrainSel, ETerrainType terType, CRandomGenerator * gen); | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-22 14:49:28 +00:00
										 |  |  | 	void execute() override; | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							|  |  |  | 	std::string getLabel() const override; | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	struct ValidationResult | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		ValidationResult(bool result, const std::string & transitionReplacement = ""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bool result; | 
					
						
							|  |  |  | 		/// The replacement of a T rule, either D or S.
 | 
					
						
							|  |  |  | 		std::string transitionReplacement; | 
					
						
							| 
									
										
										
										
											2013-04-25 16:09:48 +00:00
										 |  |  | 		int flip; | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 	struct InvalidTiles | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		std::set<int3> foreignTiles, nativeTiles; | 
					
						
							| 
									
										
										
										
											2015-03-22 20:32:22 +01:00
										 |  |  | 		bool centerPosValid; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		InvalidTiles() : centerPosValid(false) { } | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void updateTerrainTypes(); | 
					
						
							|  |  |  | 	void invalidateTerrainViews(const int3 & centerPos); | 
					
						
							|  |  |  | 	InvalidTiles getInvalidTiles(const int3 & centerPos) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void updateTerrainViews(); | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 	ETerrainGroup::ETerrainGroup getTerrainGroup(ETerrainType terType) const; | 
					
						
							| 
									
										
										
										
											2013-04-25 16:09:48 +00:00
										 |  |  | 	/// Validates the terrain view of the given position and with the given pattern. The first method wraps the
 | 
					
						
							|  |  |  | 	/// second method to validate the terrain view with the given pattern in all four flip directions(horizontal, vertical).
 | 
					
						
							| 
									
										
										
										
											2016-08-12 19:16:21 +02:00
										 |  |  | 	ValidationResult validateTerrainView(const int3 & pos, const std::vector<TerrainViewPattern> * pattern, int recDepth = 0) const; | 
					
						
							| 
									
										
										
										
											2013-04-25 16:09:48 +00:00
										 |  |  | 	ValidationResult validateTerrainViewInner(const int3 & pos, const TerrainViewPattern & pattern, int recDepth = 0) const; | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 	/// Tests whether the given terrain type is a sand type. Sand types are: Water, Sand and Rock
 | 
					
						
							|  |  |  | 	bool isSandType(ETerrainType terType) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 	CTerrainSelection terrainSel; | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 	ETerrainType terType; | 
					
						
							|  |  |  | 	CRandomGenerator * gen; | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 	std::set<int3> invalidatedTerViews; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-22 20:32:22 +01:00
										 |  |  | class DLL_LINKAGE CTerrainViewPatternUtils | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	static void printDebuggingInfoAboutTile(const CMap * map, int3 pos); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | /// The CClearTerrainOperation clears+initializes the terrain.
 | 
					
						
							|  |  |  | class CClearTerrainOperation : public CComposedOperation | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	CClearTerrainOperation(CMap * map, CRandomGenerator * gen); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	std::string getLabel() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-22 15:08:04 +00:00
										 |  |  | /// The CInsertObjectOperation class inserts an object to the map.
 | 
					
						
							|  |  |  | class CInsertObjectOperation : public CMapOperation | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2013-04-29 15:51:39 +00:00
										 |  |  | 	CInsertObjectOperation(CMap * map, CGObjectInstance * obj, const int3 & pos); | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-22 14:49:28 +00:00
										 |  |  | 	void execute() override; | 
					
						
							|  |  |  | 	void undo() override; | 
					
						
							|  |  |  | 	void redo() override; | 
					
						
							|  |  |  | 	std::string getLabel() const override; | 
					
						
							| 
									
										
										
										
											2013-04-19 11:43:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	int3 pos; | 
					
						
							|  |  |  | 	CGObjectInstance * obj; | 
					
						
							|  |  |  | }; |