(svn r12265) [NoAI] -Add: added a general protection that doesn't allow people using valuators on lists that aren't ment for those valuators noai
authortruebrain
Tue, 26 Feb 2008 10:55:07 +0000
branchnoai
changeset 9772 c1035f0ac732
parent 9771 769496a7b02e
child 9773 d2c20cd38f18
(svn r12265) [NoAI] -Add: added a general protection that doesn't allow people using valuators on lists that aren't ment for those valuators
src/ai/api/ai_abstractlist.cpp
src/ai/api/ai_abstractlist.hpp
src/ai/api/ai_enginelist.hpp
src/ai/api/ai_enginelist_valuator.hpp
src/ai/api/ai_industrylist.hpp
src/ai/api/ai_industrylist_valuator.hpp
src/ai/api/ai_list.hpp
src/ai/api/ai_list_valuator.hpp
src/ai/api/ai_stationlist.hpp
src/ai/api/ai_stationlist_valuator.hpp
src/ai/api/ai_tilelist.hpp
src/ai/api/ai_tilelist_valuator.hpp
src/ai/api/ai_townlist.hpp
src/ai/api/ai_townlist_valuator.hpp
src/ai/api/ai_vehiclelist.hpp
src/ai/api/ai_vehiclelist_valuator.hpp
--- a/src/ai/api/ai_abstractlist.cpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_abstractlist.cpp	Tue Feb 26 10:55:07 2008 +0000
@@ -530,6 +530,11 @@
 
 void AIAbstractList::Valuate(const AIAbstractList::Valuator &proc)
 {
+	if (this->GetListName() != NULL && strcmp(this->GetListName(), proc.GetListName()) != 0) {
+		DEBUG(ai, 0, "WARNING: You are trying to use a valuator for %s on a list which\n", this->GetListName());
+		DEBUG(ai, 0, " is based on %s. In general, this can't work. Expect fuzzy results!\n", proc.GetListName());
+	}
+
 	this->buckets.clear();
 	for (AIAbstractListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter++) {
 		int32 value = proc.Valuate((*iter).first);
--- a/src/ai/api/ai_abstractlist.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_abstractlist.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -236,6 +236,7 @@
 
 	private:
 		virtual int32 Valuate(int32 item) const = 0;
+		virtual const char *GetListName() const = 0;
 	};
 
 	/**
@@ -243,6 +244,12 @@
 	 * @note the valuator should be a valid instance.
 	 */
 	void Valuate(const AIAbstractList::Valuator &proc);
+
+private:
+	/**
+	 * The name of the list, to check if a Valuator can be used on this list.
+	 */
+	virtual const char *GetListName() const { return NULL; };
 };
 
 #endif /* AI_LIST_HPP */
--- a/src/ai/api/ai_enginelist.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_enginelist.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -22,6 +22,12 @@
 	 * The constructor to make a list of engines.
 	 */
 	AIEngineList(AIVehicle::VehicleType type);
+
+private:
+	/**
+	 * The name of this list, to check if a Valuator can be used on this list.
+	 */
+	const char *GetListName() const { return "AIEngineList"; }
 };
 
 #endif /* AI_ENGINELIST_HPP */
--- a/src/ai/api/ai_enginelist_valuator.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_enginelist_valuator.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -20,6 +20,11 @@
 	static const char *GetClassName() { return "AIEngineList_vCargoType"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIEngineList"; }
+
 	int32 Valuate(int32 engine) const;
 };
 
@@ -36,6 +41,11 @@
 	static const char *GetClassName() { return "AIEngineList_vCapacity"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIEngineList"; }
+
 	int32 Valuate(int32 engine) const;
 };
 
@@ -52,6 +62,11 @@
 	static const char *GetClassName() { return "AIEngineList_vReliability"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIEngineList"; }
+
 	int32 Valuate(int32 engine) const;
 };
 
@@ -68,6 +83,11 @@
 	static const char *GetClassName() { return "AIEngineList_vMaxSpeed"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIEngineList"; }
+
 	int32 Valuate(int32 engine) const;
 };
 
@@ -84,6 +104,11 @@
 	static const char *GetClassName() { return "AIEngineList_vPrice"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIEngineList"; }
+
 	int32 Valuate(int32 engine) const;
 };
 
--- a/src/ai/api/ai_industrylist.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_industrylist.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -21,6 +21,12 @@
 	 * The constructor to make a list of industries.
 	 */
 	AIIndustryList();
+
+private:
+	/**
+	 * The name of this list, to check if a Valuator can be used on this list.
+	 */
+	const char *GetListName() const { return "AIIndustryList"; }
 };
 
 #endif /* AI_INDUSTRYLIST_HPP */
--- a/src/ai/api/ai_industrylist_valuator.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_industrylist_valuator.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -27,6 +27,11 @@
 private:
 	CargoID cargo_type;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIIndustryList"; }
+
 	int32 Valuate(int32 industry) const;
 };
 
@@ -50,6 +55,11 @@
 private:
 	CargoID cargo_type;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIIndustryList"; }
+
 	int32 Valuate(int32 industry) const;
 };
 
@@ -66,6 +76,11 @@
 	static const char *GetClassName() { return "AIIndustryList_vGetLocation"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIIndustryList"; }
+
 	int32 Valuate(int32 industry) const;
 };
 
@@ -89,6 +104,11 @@
 private:
 	TileIndex tile;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIIndustryList"; }
+
 	int32 Valuate(int32 station) const;
 };
 
@@ -112,6 +132,11 @@
 private:
 	TileIndex tile;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIIndustryList"; }
+
 	int32 Valuate(int32 station) const;
 };
 
--- a/src/ai/api/ai_list.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_list.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -17,6 +17,12 @@
 	 */
 	static const char *GetClassName() { return "AIList"; }
 
+private:
+	/**
+	 * The name of this list, to check if a Valuator can be used on this list.
+	 */
+	const char *GetListName() const { return "AIList"; }
+
 public:
 	/**
 	 * Add an item to the list.
--- a/src/ai/api/ai_list_valuator.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_list_valuator.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -20,6 +20,11 @@
 	static const char *GetClassName() { return "AIList_vRandomize"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIList"; }
+
 	int32 Valuate(int32 item) const;
 };
 
--- a/src/ai/api/ai_stationlist.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_stationlist.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -23,6 +23,12 @@
 	 * @param type The type of station you want a list of.
 	 */
 	AIStationList(AIStation::StationType type);
+
+private:
+	/**
+	 * The name of this list, to check if a Valuator can be used on this list.
+	 */
+	const char *GetListName() const { return "AIStationList"; }
 };
 
 /**
@@ -40,6 +46,12 @@
 	 * @param vehicle_id The vehicles to get the list of stations he goes to from.
 	 */
 	AIStationList_Vehicle(VehicleID vehicle_id);
+
+private:
+	/**
+	 * The name of this list, to check if a Valuator can be used on this list.
+	 */
+	const char *GetListName() const { return "AIStationList"; }
 };
 
 #endif /* AI_STATIONLIST_HPP */
--- a/src/ai/api/ai_stationlist_valuator.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_stationlist_valuator.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -20,6 +20,11 @@
 	static const char *GetClassName() { return "AIStationList_vGetLocation"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIStationList"; }
+
 	int32 Valuate(int32 station) const;
 };
 
@@ -43,6 +48,11 @@
 private:
 	CargoID cargo_type;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIStationList"; }
+
 	int32 Valuate(int32 station) const;
 };
 
@@ -66,6 +76,11 @@
 private:
 	CargoID cargo_type;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIStationList"; }
+
 	int32 Valuate(int32 station) const;
 };
 
@@ -89,6 +104,11 @@
 private:
 	TileIndex tile;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIStationList"; }
+
 	int32 Valuate(int32 station) const;
 };
 
@@ -112,6 +132,11 @@
 private:
 	TileIndex tile;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIStationList"; }
+
 	int32 Valuate(int32 station) const;
 };
 
--- a/src/ai/api/ai_tilelist.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_tilelist.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -20,13 +20,18 @@
 
 private:
 	/**
+	 * The name of this list, to check if a Valuator can be used on this list.
+	 */
+	const char *GetListName() const { return "AITileList"; }
+
+private:
+	/**
 	 * Make sure t1.x is smaller than t2.x and t1.y is smaller than t2.y.
 	 * They are swapped to ensure they are after calling this function.
 	 */
 	void FixRectangleSpan(TileIndex &t1, TileIndex &t2);
 
 public:
-
 	/**
 	 * Adds the rectangle between tile_from and tile_to to the to-be-evaluated tiles.
 	 * @param tile_from one corner of the tiles to add.
--- a/src/ai/api/ai_tilelist_valuator.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_tilelist_valuator.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -20,6 +20,11 @@
 	static const char *GetClassName() { return "AITileList_vBuildable"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITileList"; }
+
 	int32 Valuate(int32 tile) const;
 };
 
@@ -36,6 +41,11 @@
 	static const char *GetClassName() { return "AITileList_vWater"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITileList"; }
+
 	int32 Valuate(int32 tile) const;
 };
 
@@ -59,6 +69,11 @@
 private:
 	uint width, height;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITileList"; }
+
 	int32 Valuate(int32 tile) const;
 };
 
@@ -75,6 +90,11 @@
 	static const char *GetClassName() { return "AITileList_vSlope"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITileList"; }
+
 	int32 Valuate(int32 tile) const;
 };
 
@@ -91,6 +111,11 @@
 	static const char *GetClassName() { return "AITileList_vHeight"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITileList"; }
+
 	int32 Valuate(int32 tile) const;
 };
 
@@ -108,6 +133,11 @@
 	static const char *GetClassName() { return "AITileList_vNeighbourRoad"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITileList"; }
+
 	int32 Valuate(int32 tile) const;
 };
 
@@ -124,6 +154,11 @@
 	static const char *GetClassName() { return "AITileList_vRoadTile"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITileList"; }
+
 	int32 Valuate(int32 tile) const;
 };
 
@@ -152,6 +187,11 @@
 	CargoID cargo_type;
 	uint width, height, radius;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITileList"; }
+
 	int32 Valuate(int32 tile) const;
 };
 
@@ -179,6 +219,11 @@
 	CargoID cargo_type;
 	uint width, height, radius;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITileList"; }
+
 	int32 Valuate(int32 tile) const;
 };
 
@@ -202,6 +247,11 @@
 private:
 	TileIndex tile;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITileList"; }
+
 	int32 Valuate(int32 station) const;
 };
 
@@ -225,6 +275,11 @@
 private:
 	TileIndex tile;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITileList"; }
+
 	int32 Valuate(int32 station) const;
 };
 
--- a/src/ai/api/ai_townlist.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_townlist.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -21,6 +21,12 @@
 	 * The constructor to make a list of towns.
 	 */
 	AITownList();
+
+private:
+	/**
+	 * The name of this list, to check if a Valuator can be used on this list.
+	 */
+	const char *GetListName() const { return "AITownList"; }
 };
 
 #endif /* AI_TOWNLIST_HPP */
--- a/src/ai/api/ai_townlist_valuator.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_townlist_valuator.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -20,6 +20,11 @@
 	static const char *GetClassName() { return "AITownList_vRandomize"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITownList"; }
+
 	int32 Valuate(int32 town) const;
 };
 
@@ -36,6 +41,11 @@
 	static const char *GetClassName() { return "AITownList_vGetPopulation"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITownList"; }
+
 	int32 Valuate(int32 town) const;
 };
 
@@ -52,6 +62,11 @@
 	static const char *GetClassName() { return "AITownList_vGetLocation"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITownList"; }
+
 	int32 Valuate(int32 town) const;
 };
 
@@ -75,6 +90,11 @@
 private:
 	TileIndex tile;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITownList"; }
+
 	int32 Valuate(int32 station) const;
 };
 
@@ -98,6 +118,11 @@
 private:
 	TileIndex tile;
 
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AITownList"; }
+
 	int32 Valuate(int32 station) const;
 };
 
--- a/src/ai/api/ai_vehiclelist.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_vehiclelist.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -21,6 +21,12 @@
 	 * The constructor to make a list of vehicles.
 	 */
 	AIVehicleList();
+
+private:
+	/**
+	 * The name of this list, to check if a Valuator can be used on this list.
+	 */
+	const char *GetListName() const { return "AIVehicleList"; }
 };
 
 /**
@@ -38,6 +44,12 @@
 	 * @param station_id The station to get the list of vehicles that go here from.
 	 */
 	AIVehicleList_Station(StationID station_id);
+
+private:
+	/**
+	 * The name of this list, to check if a Valuator can be used on this list.
+	 */
+	const char *GetListName() const { return "AIVehicleList"; }
 };
 
 #endif /* AI_VEHICLELIST_HPP */
--- a/src/ai/api/ai_vehiclelist_valuator.hpp	Tue Feb 26 10:47:22 2008 +0000
+++ b/src/ai/api/ai_vehiclelist_valuator.hpp	Tue Feb 26 10:55:07 2008 +0000
@@ -20,6 +20,11 @@
 	static const char *GetClassName() { return "AIVehicleList_vGetLocation"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIVehicleList"; }
+
 	int32 Valuate(int32 vehicle_id) const;
 };
 
@@ -36,6 +41,11 @@
 	static const char *GetClassName() { return "AIVehicleList_vEngineType"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIVehicleList"; }
+
 	int32 Valuate(int32 vehicle_id) const;
 };
 
@@ -52,6 +62,11 @@
 	static const char *GetClassName() { return "AIVehicleList_vUnitNumber"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIVehicleList"; }
+
 	int32 Valuate(int32 vehicle_id) const;
 };
 
@@ -68,6 +83,11 @@
 	static const char *GetClassName() { return "AIVehicleList_vAge"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIVehicleList"; }
+
 	int32 Valuate(int32 vehicle_id) const;
 };
 
@@ -84,6 +104,11 @@
 	static const char *GetClassName() { return "AIVehicleList_vMaxAge"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIVehicleList"; }
+
 	int32 Valuate(int32 vehicle_id) const;
 };
 
@@ -100,6 +125,11 @@
 	static const char *GetClassName() { return "AIVehicleList_vAgeLeft"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIVehicleList"; }
+
 	int32 Valuate(int32 vehicle_id) const;
 };
 
@@ -116,6 +146,11 @@
 	static const char *GetClassName() { return "AIVehicleList_vProfitThisYear"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIVehicleList"; }
+
 	int32 Valuate(int32 vehicle_id) const;
 };
 
@@ -132,6 +167,11 @@
 	static const char *GetClassName() { return "AIVehicleList_vProfitLastYear"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIVehicleList"; }
+
 	int32 Valuate(int32 vehicle_id) const;
 };
 
@@ -148,6 +188,11 @@
 	static const char *GetClassName() { return "AIVehicleList_vVehicleType"; }
 
 private:
+	/**
+	 * The name of this list, to check if we can be used with a List.
+	 */
+	const char *GetListName() const { return "AIVehicleList"; }
+
 	int32 Valuate(int32 vehicle_id) const;
 };