浏览代码

vcmi:towns now can choose if moat render is needed

Using invalid points. Also removed unused variable.
Konstantin 2 年之前
父节点
当前提交
c4d5a7a2d6

+ 3 - 3
client/battle/BattleSiegeController.cpp

@@ -118,7 +118,7 @@ void BattleSiegeController::showWallPiece(Canvas & canvas, EWallVisual::EWallVis
 	auto & ci = town->town->clientInfo;
 	auto const & pos = ci.siegePositions[what];
 
-	if ( wallPieceImages[what])
+	if ( wallPieceImages[what] && pos.isValid())
 		canvas.draw(wallPieceImages[what], Point(pos.x, pos.y));
 }
 
@@ -135,8 +135,8 @@ bool BattleSiegeController::getWallPieceExistance(EWallVisual::EWallVisual what)
 
 	switch (what)
 	{
-	case EWallVisual::MOAT:              return town->hasBuilt(BuildingID::CITADEL) && town->town->faction->getIndex() != ETownType::TOWER;
-	case EWallVisual::MOAT_BANK:         return town->hasBuilt(BuildingID::CITADEL) && town->town->faction->getIndex() != ETownType::TOWER && town->town->faction->getIndex() != ETownType::NECROPOLIS;
+	case EWallVisual::MOAT:              return town->hasBuilt(BuildingID::CITADEL) && town->town->clientInfo.siegePositions.at(EWallVisual::MOAT).isValid();
+	case EWallVisual::MOAT_BANK:         return town->hasBuilt(BuildingID::CITADEL) && town->town->clientInfo.siegePositions.at(EWallVisual::MOAT_BANK).isValid();
 	case EWallVisual::KEEP_BATTLEMENT:   return town->hasBuilt(BuildingID::CITADEL) && owner.curInt->cb->battleGetWallState(EWallPart::KEEP) != EWallState::DESTROYED;
 	case EWallVisual::UPPER_BATTLEMENT:  return town->hasBuilt(BuildingID::CASTLE) && owner.curInt->cb->battleGetWallState(EWallPart::UPPER_TOWER) != EWallState::DESTROYED;
 	case EWallVisual::BOTTOM_BATTLEMENT: return town->hasBuilt(BuildingID::CASTLE) && owner.curInt->cb->battleGetWallState(EWallPart::BOTTOM_TOWER) != EWallState::DESTROYED;

+ 0 - 2
client/renderSDL/CursorSoftware.cpp

@@ -53,8 +53,6 @@ void CursorSoftware::createTexture(const Point & dimensions)
 
 void CursorSoftware::updateTexture()
 {
-	Point dimensions(-1, -1);
-
 	if (!cursorSurface ||  Point(cursorSurface->w, cursorSurface->h) != cursorImage->dimensions())
 		createTexture(cursorImage->dimensions());
 

+ 0 - 1
config/factions/necropolis.json

@@ -221,7 +221,6 @@
 				},
 				"moat" :
 				{
-					"bank" : { "x" : -1, "y" : -1 }, // Should not be present
 					"moat" : { "x" : 406, "y" : 77 }
 				},
 				"static" :

+ 0 - 2
config/factions/tower.json

@@ -209,8 +209,6 @@
 				},
 				"moat" :
 				{
-					"bank" : { "x" : 410, "y" : 80 },
-					"moat" : { "x" : 410, "y" : 90 }
 				},
 				"static" :
 				{

+ 3 - 0
lib/CTownHandler.cpp

@@ -778,6 +778,9 @@ void CTownHandler::loadTownHall(CTown &town, const JsonNode & source) const
 
 Point JsonToPoint(const JsonNode & node)
 {
+	if(!node.isStruct())
+		return Point::makeInvalid();
+
 	Point ret;
 	ret.x = static_cast<si32>(node["x"].Float());
 	ret.y = static_cast<si32>(node["y"].Float());

+ 22 - 13
lib/Point.h

@@ -19,44 +19,48 @@ public:
 	int x, y;
 
 	//constructors
-	Point()
+	constexpr Point() : x(0), y(0)
 	{
-		x = y = 0;
 	}
 
-	Point(int X, int Y)
+	constexpr Point(int X, int Y)
 		: x(X)
 		, y(Y)
 	{
 	}
 
+	constexpr static Point makeInvalid()
+	{
+		return Point(std::numeric_limits<int>::min(), std::numeric_limits<int>::min());
+	}
+
 	explicit DLL_LINKAGE Point(const int3 &a);
 
 	template<typename T>
-	Point operator+(const T &b) const
+	constexpr Point operator+(const T &b) const
 	{
 		return Point(x+b.x,y+b.y);
 	}
 
 	template<typename T>
-	Point operator/(const T &div) const
+	constexpr Point operator/(const T &div) const
 	{
 		return Point(x/div, y/div);
 	}
 
 	template<typename T>
-	Point operator*(const T &mul) const
+	constexpr Point operator*(const T &mul) const
 	{
 		return Point(x*mul, y*mul);
 	}
 
-	Point operator*(const Point &b) const
+	constexpr Point operator*(const Point &b) const
 	{
 		return Point(x*b.x,y*b.y);
 	}
 
 	template<typename T>
-	Point& operator+=(const T &b)
+	constexpr Point& operator+=(const T &b)
 	{
 		x += b.x;
 		y += b.y;
@@ -64,34 +68,39 @@ public:
 	}
 
 	template<typename T>
-	Point operator-(const T &b) const
+	constexpr Point operator-(const T &b) const
 	{
 		return Point(x - b.x, y - b.y);
 	}
 
 	template<typename T>
-	Point& operator-=(const T &b)
+	constexpr Point& operator-=(const T &b)
 	{
 		x -= b.x;
 		y -= b.y;
 		return *this;
 	}
 
-	template<typename T> Point& operator=(const T &t)
+	template<typename T> constexpr Point& operator=(const T &t)
 	{
 		x = t.x;
 		y = t.y;
 		return *this;
 	}
-	template<typename T> bool operator==(const T &t) const
+	template<typename T> constexpr bool operator==(const T &t) const
 	{
 		return x == t.x  &&  y == t.y;
 	}
-	template<typename T> bool operator!=(const T &t) const
+	template<typename T> constexpr bool operator!=(const T &t) const
 	{
 		return !(*this == t);
 	}
 
+	constexpr bool isValid() const
+	{
+		return x > std::numeric_limits<int>::min() && y > std::numeric_limits<int>::min();
+	}
+
 	template <typename Handler>
 	void serialize(Handler &h, const int version)
 	{