2015-01-03 01:29:42 +02:00
|
|
|
/*
|
|
|
|
* CDrawRoadsOperation.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"
|
|
|
|
#include "CMapEditManager.h"
|
|
|
|
|
2015-12-02 21:05:10 +02:00
|
|
|
struct TerrainTile;
|
2015-01-03 01:29:42 +02:00
|
|
|
|
|
|
|
class CDrawRoadsOperation : public CMapOperation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CDrawRoadsOperation(CMap * map, const CTerrainSelection & terrainSel, ERoadType::ERoadType roadType, CRandomGenerator * gen);
|
|
|
|
void execute() override;
|
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
|
|
|
std::string getLabel() const override;
|
|
|
|
private:
|
2015-01-03 02:04:49 +02:00
|
|
|
|
|
|
|
struct RoadPattern
|
|
|
|
{
|
2015-01-03 04:03:44 +02:00
|
|
|
std::string data[9];
|
2015-01-03 02:04:49 +02:00
|
|
|
std::pair<int, int> roadMapping, riverMapping;
|
2015-01-03 04:03:44 +02:00
|
|
|
bool hasHFlip, hasVFlip;
|
2015-01-03 02:04:49 +02:00
|
|
|
};
|
|
|
|
|
2015-01-03 04:03:44 +02:00
|
|
|
struct ValidationResult
|
|
|
|
{
|
|
|
|
ValidationResult(bool result): result(result), flip(0){};
|
|
|
|
bool result;
|
|
|
|
int flip;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const std::vector<RoadPattern> patterns;
|
|
|
|
|
|
|
|
void flipPattern(RoadPattern & pattern, int flip) const;
|
|
|
|
|
|
|
|
void updateTiles(std::set<int3> & invalidated);
|
|
|
|
|
|
|
|
ValidationResult validateTile(const RoadPattern & pattern, const int3 & pos);
|
|
|
|
void updateTile(TerrainTile & tile, const RoadPattern & pattern, const int flip);
|
|
|
|
|
|
|
|
bool canApplyPattern(const RoadPattern & pattern) const;
|
|
|
|
bool needUpdateTile(const TerrainTile & tile) const;
|
|
|
|
bool tileHasSomething(const int3 & pos) const;
|
2015-01-03 02:04:49 +02:00
|
|
|
|
2015-01-03 01:29:42 +02:00
|
|
|
CTerrainSelection terrainSel;
|
|
|
|
ERoadType::ERoadType roadType;
|
|
|
|
CRandomGenerator * gen;
|
|
|
|
};
|