Browse Source

Fix "identical expressions on both sides of comparison"

Ivan Savenko 1 year ago
parent
commit
c03196257f
4 changed files with 60 additions and 69 deletions
  1. 46 45
      AI/VCAI/Goals/AbstractGoal.cpp
  2. 5 5
      AI/VCAI/Goals/AbstractGoal.h
  3. 8 14
      lib/int3.h
  4. 1 5
      lib/rmg/float3.h

+ 46 - 45
AI/VCAI/Goals/AbstractGoal.cpp

@@ -109,51 +109,52 @@ bool AbstractGoal::operator==(const AbstractGoal & g) const
 	return false;
 }
 
-bool AbstractGoal::operator<(AbstractGoal & g) //for std::unique
-{
-	//TODO: make sure it gets goals consistent with == operator
-	if (goalType < g.goalType)
-		return true;
-	if (goalType > g.goalType)
-		return false;
-	if (hero < g.hero)
-		return true;
-	if (hero > g.hero)
-		return false;
-	if (tile < g.tile)
-		return true;
-	if (g.tile < tile)
-		return false;
-	if (objid < g.objid)
-		return true;
-	if (objid > g.objid)
-		return false;
-	if (town < g.town)
-		return true;
-	if (town > g.town)
-		return false;
-	if (value < g.value)
-		return true;
-	if (value > g.value)
-		return false;
-	if (priority < g.priority)
-		return true;
-	if (priority > g.priority)
-		return false;
-	if (resID < g.resID)
-		return true;
-	if (resID > g.resID)
-		return false;
-	if (bid < g.bid)
-		return true;
-	if (bid > g.bid)
-		return false;
-	if (aid < g.aid)
-		return true;
-	if (aid > g.aid)
-		return false;
-	return false;
-}
+// FIXME: unused code?
+//bool AbstractGoal::operator<(AbstractGoal & g) //for std::unique
+//{
+//	//TODO: make sure it gets goals consistent with == operator
+//	if (goalType < g.goalType)
+//		return true;
+//	if (goalType > g.goalType)
+//		return false;
+//	if (hero < g.hero)
+//		return true;
+//	if (hero > g.hero)
+//		return false;
+//	if (tile < g.tile)
+//		return true;
+//	if (g.tile < tile)
+//		return false;
+//	if (objid < g.objid)
+//		return true;
+//	if (objid > g.objid)
+//		return false;
+//	if (town < g.town)
+//		return true;
+//	if (town > g.town)
+//		return false;
+//	if (value < g.value)
+//		return true;
+//	if (value > g.value)
+//		return false;
+//	if (priority < g.priority)
+//		return true;
+//	if (priority > g.priority)
+//		return false;
+//	if (resID < g.resID)
+//		return true;
+//	if (resID > g.resID)
+//		return false;
+//	if (bid < g.bid)
+//		return true;
+//	if (bid > g.bid)
+//		return false;
+//	if (aid < g.aid)
+//		return true;
+//	if (aid > g.aid)
+//		return false;
+//	return false;
+//}
 
 //TODO: find out why the following are not generated automatically on MVS?
 bool TSubgoal::operator==(const TSubgoal & rhs) const

+ 5 - 5
AI/VCAI/Goals/AbstractGoal.h

@@ -165,16 +165,16 @@ namespace Goals
 		virtual float accept(FuzzyHelper * f);
 
 		virtual bool operator==(const AbstractGoal & g) const;
-		bool operator<(AbstractGoal & g); //final
+//		bool operator<(AbstractGoal & g); //final
 		virtual bool fulfillsMe(Goals::TSubgoal goal) //TODO: multimethod instead of type check
 		{
 			return false; //use this method to check if goal is fulfilled by another (not equal) goal, operator == is handled spearately
 		}
 
-		bool operator!=(const AbstractGoal & g) const
-		{
-			return !(*this == g);
-		}
+//		bool operator!=(const AbstractGoal & g) const
+//		{
+//			return !(*this == g);
+//		}
 
 		template<typename Handler> void serialize(Handler & h)
 		{

+ 8 - 14
lib/int3.h

@@ -84,19 +84,13 @@ public:
 
 	constexpr bool operator<(const int3 & i) const
 	{
-		if (z < i.z)
-			return true;
-		if (z > i.z)
-			return false;
-		if (y < i.y)
-			return true;
-		if (y > i.y)
-			return false;
-		if (x < i.x)
-			return true;
-		if (x > i.x)
-			return false;
-		return false;
+		if (z != i.z)
+			return z < i.z;
+
+		if (y != i.y)
+			return y < i.y;
+
+		return x < i.x;
 	}
 
 	enum EDistanceFormula
@@ -224,4 +218,4 @@ struct std::hash<VCMI_LIB_WRAP_NAMESPACE(int3)> {
 	std::size_t operator()(VCMI_LIB_WRAP_NAMESPACE(int3) const& pos) const noexcept {
 		return hash_value(pos);
 	}
-};
+};

+ 1 - 5
lib/rmg/float3.h

@@ -126,12 +126,8 @@ public:
 			return true;
 		if (y>i.y)
 			return false;
-		if (x<i.x)
-			return true;
-		if (x>i.x)
-			return false;
 
-		return false;
+		return x<i.x;
 	}
 
 	std::string toString() const