src/ai/api/ai_list.hpp
branchnoai
changeset 9593 012f29f59906
parent 9590 16cde7f36a88
child 9594 5009a30f320a
--- a/src/ai/api/ai_list.hpp	Sat Apr 14 20:01:25 2007 +0000
+++ b/src/ai/api/ai_list.hpp	Sat Apr 14 20:17:36 2007 +0000
@@ -1,237 +1,51 @@
 /* $Id$ */
 
-/** @file ai_list.hpp a linked list which can keep item/value pairs */
+/** @file ai_list.hpp a simple list which you can manipulate */
 
 #ifndef AI_LIST_HPP
 #define AI_LIST_HPP
 
-#include "ai_object.hpp"
-#include <map>
-#include <set>
-
-class AIListSorter;
+#include "ai_abstractlist.hpp"
 
 /**
- * Class that creates a linked list which can keep item/value pairs.
+ * Class that creates a simple list of tiles which you can manipulate.
  */
-class AIList : public AIObject {
-private:
-	AIListSorter *sorter;
-
+class AIList : public AIAbstractList {
 public:
-	typedef std::set<int32> AIItemList;               ///< The list of items inside the bucket
-	typedef std::map<int32, AIItemList> AIListBucket; ///< The bucket list per value
-	typedef std::map<int32, int32> AIListMap;         ///< List per item
-
-	AIListMap items;           ///< The items in the list
-	AIListBucket buckets;      ///< The items in the list, sorted by value
-
-public:
-
 	/**
 	 * The name of the class, needed by several sub-processes.
 	 */
 	static const char *GetClassName() { return "AIList"; }
 
-	/**
-	 * Constructor of the AIList.
-	 */
-	AIList();
-
+public:
 	/**
-	 * Destructor of the AIList.
-	 */
-	~AIList();
-
-	/**
-	 * Clear the list, making Count() returning 0 and IsEmpty() returning true.
-	 */
-	void Clear();
-
-	/**
-	 * Add a single item to the list.
-	 * @param item the item to add. Should be unique, otherwise it is ignored.
-	 * @note the value is set to 0 by default.
+	 * Add an item to the list.
+	 * @param item the item to add.
 	 */
 	void AddItem(int32 item);
 
 	/**
-	 * Remove a single item from the list.
-	 * @param item the item to remove. If not existing, it is ignored.
+	 * Remove the item from the list.
+	 * @param item the item to remove.
 	 */
 	void RemoveItem(int32 item);
-
-	/**
-	 * Check if an item is in the list.
-	 * @param item the item to check for.
-	 * @return true if the item is in the list.
-	 */
-	bool HasItem(int32 item);
-
-	/**
-	 * Go to the beginning of the list.
-	 * @return the item value of the first item.
-	 */
-	int32 Begin();
-
-	/**
-	 * Go to the next item in the list.
-	 * @return the item value of the next item.
-	 * @note returns 0 if beyond end-of-list. Use HasNext() to check for end-of-list.
-	 */
-	int32 Next();
-
-	/**
-	 * Check if a list is empty.
-	 * @return true if the list is empty.
-	 **/
-	bool IsEmpty();
-
-	/**
-	 * Check if there is a next element. In other words, if this is true,
-	 *   Next() will return a valid item.
-	 * @return true if there is a next item.
-	 */
-	bool HasNext();
-
-	/**
-	 * Returns the amount of items in the list.
-	 * @return amount of items in the list.
-	 */
-	int32 Count();
-
-	/**
-	 * Get the value that belongs to this item.
-	 * @param item the item to get the value from
-	 * @return the value that belongs to this item.
-	 */
-	int32 GetValue(int32 item);
-
-	/**
-	 * Sort this list by item-value.
-	 * @param ascending if true, lowest value is on top, else at bottom.
-	 * @note the current item stays at the same place.
-	 */
-	void SortByItem(bool ascending);
-
-	/**
-	 * Sort this list by the value of the items.
-	 * @param ascending if true, lowest value is on top, else at bottom.
-	 * @note the current item stays at the same place.
-	 */
-	void SortByValue(bool ascending);
-
-	/**
-	 * Removes all items with a higher value than 'value'.
-	 * @param value the value above which all items are removed.
-	 */
-	void RemoveAboveValue(int32 value);
-
-	/**
-	 * Removes all items with a lower value than 'value'.
-	 * @param value the value below which all items are removed.
-	 */
-	void RemoveBelowValue(int32 value);
-
-	/**
-	 * Removes all items with a value above start and below end.
-	 * @param start the lower bound of the to be removed values (exclusive).
-	 * @param end   the upper bound of the to be removed valuens (exclusive).
-	 */
-	void RemoveBetweenValue(int32 start, int32 end);
-
-	/**
-	 * Remove all items with this value.
-	 * @param value the value to remove.
-	 */
-	void RemoveValue(int32 value);
-
-	/**
-	 * Keep all items with a higher value than 'value'.
-	 * @param value the value above which all items are kept.
-	 */
-	void KeepAboveValue(int32 value);
-
-	/**
-	 * Keep all items with a lower value than 'value'.
-	 * @param value the value below which all items are kept.
-	 */
-	void KeepBelowValue(int32 value);
-
-	/**
-	 * Keep all items with a value above start and below end.
-	 * @param start the lower bound of the to be kept values (exclusive).
-	 * @param end   the upper bound of the to be kept values (exclusive).
-	 */
-	void KeepBetweenValue(int32 start, int32 end);
-
-	/**
-	 * Keep all items with this value.
-	 * @param value the value to keep.
-	 **/
-	void KeepValue(int32 value);
-
-	/**
-	 * The definition how valuators should look.
-	 */
-	class Valuator {
-		/* Make this valuator a friend of AIList, so we can access the private.
-		 *  Nobody else should ever call Valuate. */
-		friend class AIList;
-	public:
-		/**
-		 * Virtual destructor, needed to make compilers happy.
-		 */
-		virtual ~Valuator() {}
-
-	private:
-		virtual int32 Valuate(int32 item) const = 0;
-	};
-
-	/**
-	 * Give all items a value defined by the valuator you give.
-	 * @note the valuator should be a valid instance.
-	 */
-	void Valuate(const AIList::Valuator &proc);
 };
 
 #ifdef DEFINE_SQUIRREL_CLASS
 namespace SQConvert {
-	/* Allow inner classes/structs to be used as Squirrel parameters */
-	template <> const AIList::Valuator &GetParam(ForceType<const AIList::Valuator &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIList::Valuator *)instance; }
-
 	/* Allow AIList to be used as Squirrel parameter */
 	template <> AIList *GetParam(ForceType<AIList *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIList *)instance; }
 }; // namespace SQConvert
 
 void SQAIListRegister(Squirrel *engine) {
 	DefSQClass <AIList> SQAIList("AIList");
-	SQAIList.PreRegister(engine);
+	SQAIList.PreRegister(engine, "AIAbstractList");
 	SQAIList.AddConstructor(engine);
 
 	SQAIList.DefSQStaticMethod(engine, &AIList::GetClassName, "GetClassName", 1, "x");
 
-	SQAIList.DefSQMethod(engine, &AIList::Clear,              "Clear",              1, "x");
-	SQAIList.DefSQMethod(engine, &AIList::AddItem,            "AddItem",            2, "xi");
-	SQAIList.DefSQMethod(engine, &AIList::RemoveItem,         "RemoveItem",         2, "xi");
-	SQAIList.DefSQMethod(engine, &AIList::HasItem,            "HasItem",            2, "xi");
-	SQAIList.DefSQMethod(engine, &AIList::Begin,              "Begin",              1, "x");
-	SQAIList.DefSQMethod(engine, &AIList::Next,               "Next",               1, "x");
-	SQAIList.DefSQMethod(engine, &AIList::IsEmpty,            "IsEmpty",            1, "x");
-	SQAIList.DefSQMethod(engine, &AIList::HasNext,            "HasNext",            1, "x");
-	SQAIList.DefSQMethod(engine, &AIList::Count,              "Count",              1, "x");
-	SQAIList.DefSQMethod(engine, &AIList::GetValue,           "GetValue",           2, "xi");
-	SQAIList.DefSQMethod(engine, &AIList::SortByItem,         "SortByItem",         2, "xb");
-	SQAIList.DefSQMethod(engine, &AIList::SortByValue,        "SortByValue",        2, "xb");
-	SQAIList.DefSQMethod(engine, &AIList::RemoveAboveValue,   "RemoveAboveValue",   2, "xi");
-	SQAIList.DefSQMethod(engine, &AIList::RemoveBelowValue,   "RemoveBelowValue",   2, "xi");
-	SQAIList.DefSQMethod(engine, &AIList::RemoveBetweenValue, "RemoveBetweenValue", 3, "xii");
-	SQAIList.DefSQMethod(engine, &AIList::RemoveValue,        "RemoveValue",        2, "xi");
-	SQAIList.DefSQMethod(engine, &AIList::KeepAboveValue,     "KeepAboveValue",     2, "xi");
-	SQAIList.DefSQMethod(engine, &AIList::KeepBelowValue,     "KeepBelowValue",     2, "xi");
-	SQAIList.DefSQMethod(engine, &AIList::KeepBetweenValue,   "KeepBetweenValue",   3, "xii");
-	SQAIList.DefSQMethod(engine, &AIList::KeepValue,          "KeepValue",          2, "xi");
-	SQAIList.DefSQMethod(engine, &AIList::Valuate,            "Valuate",            2, "xx");
+	SQAIList.DefSQMethod(engine, &AIList::AddItem,         "AddItem",         2, "xi");
+	SQAIList.DefSQMethod(engine, &AIList::RemoveItem,      "RemoveItem",      2, "xi");
 
 	SQAIList.PostRegister(engine);
 }