ai_list.hpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00013 #ifndef AI_LIST_HPP
00014 #define AI_LIST_HPP
00015 
00016 #include "ai_object.hpp"
00017 #include <map>
00018 #include <set>
00019 
00020 class AIListSorter;
00021 
00025 class AIList : public AIObject {
00026 public:
00028   static const char *GetClassName() { return "AIList"; }
00029 
00031   enum SorterType {
00032     SORT_BY_VALUE, 
00033     SORT_BY_ITEM,  
00034   };
00035 
00037   static const bool SORT_ASCENDING = true;
00039   static const bool SORT_DESCENDING = false;
00040 
00041 private:
00042   AIListSorter *sorter;         
00043   SorterType sorter_type;       
00044   bool sort_ascending;          
00045   bool initialized;             
00046   int modifications;            
00047 
00048 public:
00049   typedef std::set<int32> AIItemList;               
00050   typedef std::map<int32, AIItemList> AIListBucket; 
00051   typedef std::map<int32, int32> AIListMap;         
00052 
00053   AIListMap items;           
00054   AIListBucket buckets;      
00055 
00056   AIList();
00057   ~AIList();
00058 
00065   void AddItem(int32 item, int32 value = 0);
00066 
00071   void RemoveItem(int32 item);
00072 
00076   void Clear();
00077 
00083   bool HasItem(int32 item);
00084 
00090   int32 Begin();
00091 
00097   int32 Next();
00098 
00103   bool IsEmpty();
00104 
00110   bool IsEnd();
00111 
00116   int32 Count();
00117 
00123   int32 GetValue(int32 item);
00124 
00133   bool SetValue(int32 item, int32 value);
00134 
00142   void Sort(SorterType sorter, bool ascending);
00143 
00152   void AddList(AIList *list);
00153 
00158   void RemoveAboveValue(int32 value);
00159 
00164   void RemoveBelowValue(int32 value);
00165 
00171   void RemoveBetweenValue(int32 start, int32 end);
00172 
00177   void RemoveValue(int32 value);
00178 
00183   void RemoveTop(int32 count);
00184 
00189   void RemoveBottom(int32 count);
00190 
00196   void RemoveList(AIList *list);
00197 
00202   void KeepAboveValue(int32 value);
00203 
00208   void KeepBelowValue(int32 value);
00209 
00215   void KeepBetweenValue(int32 start, int32 end);
00216 
00221   void KeepValue(int32 value);
00222 
00227   void KeepTop(int32 count);
00228 
00233   void KeepBottom(int32 count);
00234 
00240   void KeepList(AIList *list);
00241 
00242 #ifndef DOXYGEN_SKIP
00243 
00246   SQInteger _get(HSQUIRRELVM vm);
00247 
00251   SQInteger _set(HSQUIRRELVM vm);
00252 
00256   SQInteger _nexti(HSQUIRRELVM vm);
00257 
00261   SQInteger Valuate(HSQUIRRELVM vm);
00262 #else
00263 
00282   void Valuate(void *valuator_function, int params, ...);
00283 #endif /* DOXYGEN_SKIP */
00284 };
00285 
00286 #endif /* AI_LIST_HPP */

Generated on Thu Apr 14 00:48:10 2011 for OpenTTD by  doxygen 1.6.1