src/ai/api/ai_abstractlist.cpp
author truebrain
Mon, 23 Jun 2008 16:23:36 +0000
branchnoai
changeset 11059 b1751c5973cc
parent 11058 3305a425f55b
child 11063 bd71d932973e
permissions -rw-r--r--
(svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
     1
/* $Id$ */
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
     2
9833
89a64246458f (svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents: 9819
diff changeset
     3
/** @file ai_abstractlist.cpp Implementation of AIAbstractList. */
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
     4
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
     5
#include <squirrel.h>
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
     6
#include "ai_abstractlist.hpp"
9752
bd87e54186f2 (svn r12235) [NoAI] -Fix: don't segfault if you do a Next() on an empty list (tnx Progman)
truebrain
parents: 9731
diff changeset
     7
#include "../../debug.h"
10921
f50864092014 (svn r13474) [NoAI] -Fix: remove the restriction of 10 params per Valuator
truebrain
parents: 9833
diff changeset
     8
#include "../../core/alloc_func.hpp"
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
     9
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    10
/**
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    11
 * Base class for any AIAbstractList sorter.
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    12
 */
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    13
class AIAbstractListSorter {
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    14
protected:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    15
	AIAbstractList *list;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    16
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    17
public:
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    18
	/**
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    19
	 * Virtual dtor, needed to mute warnings.
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    20
	 */
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    21
	virtual ~AIAbstractListSorter() { }
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    22
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    23
	/**
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    24
	 * Get the first item of the sorter.
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    25
	 */
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    26
	virtual int32 Begin() = 0;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    27
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    28
	/**
11059
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
    29
	 * Stop iterating a sorter.
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
    30
	 */
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
    31
	virtual void End() = 0;
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
    32
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
    33
	/**
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    34
	 * Get the next item of the sorter.
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    35
	 */
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    36
	virtual int32 Next() = 0;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    37
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    38
	/**
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    39
	 * See if there is a next item of the sorter.
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    40
	 */
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    41
	virtual bool HasNext() = 0;
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    42
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    43
	/**
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    44
	 * Callback from the list if an item gets removed.
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    45
	 */
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    46
	virtual void Remove(int item) = 0;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    47
};
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    48
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    49
/**
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    50
 * Sort by value, ascending.
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    51
 */
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    52
class AIAbstractListSorterValueAscending : public AIAbstractListSorter {
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    53
private:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    54
	AIAbstractList::AIAbstractListBucket::iterator bucket_iter;
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    55
	AIAbstractList::AIItemList *bucket_list;
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    56
	AIAbstractList::AIItemList::iterator bucket_list_iter;
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    57
	bool has_no_more_items;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    58
	int32 item_next;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    59
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    60
public:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    61
	AIAbstractListSorterValueAscending(AIAbstractList *list)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    62
	{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    63
		this->list = list;
11059
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
    64
		this->End();
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    65
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    66
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    67
	int32 Begin()
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    68
	{
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
    69
		if (this->list->buckets.empty()) return 0;
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    70
		this->has_no_more_items = false;
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
    71
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    72
		this->bucket_iter = this->list->buckets.begin();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    73
		this->bucket_list = &(*this->bucket_iter).second;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    74
		this->bucket_list_iter = this->bucket_list->begin();
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    75
		this->item_next = *this->bucket_list_iter;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    76
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    77
		int32 item_current = this->item_next;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    78
		FindNext();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    79
		return item_current;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    80
	}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    81
11059
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
    82
	void End()
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
    83
	{
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
    84
		this->bucket_list = NULL;
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
    85
		this->has_no_more_items = true;
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
    86
		this->item_next = 0;
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
    87
	}
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
    88
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    89
	void FindNext()
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    90
	{
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    91
		if (this->bucket_list == NULL) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    92
			this->has_no_more_items = true;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    93
			return;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    94
		}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    95
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    96
		this->bucket_list_iter++;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    97
		if (this->bucket_list_iter == this->bucket_list->end()) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    98
			this->bucket_iter++;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
    99
			if (this->bucket_iter == this->list->buckets.end()) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   100
				this->bucket_list = NULL;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   101
				return;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   102
			}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   103
			this->bucket_list = &(*this->bucket_iter).second;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   104
			this->bucket_list_iter = this->bucket_list->begin();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   105
		}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   106
		this->item_next = *this->bucket_list_iter;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   107
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   108
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   109
	int32 Next()
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   110
	{
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   111
		if (!this->HasNext()) return 0;
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   112
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   113
		int32 item_current = this->item_next;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   114
		FindNext();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   115
		return item_current;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   116
	}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   117
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   118
	void Remove(int item)
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   119
	{
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   120
		if (!this->HasNext()) return;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   121
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   122
		/* If we remove the 'next' item, skip to the next */
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   123
		if (item == this->item_next) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   124
			FindNext();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   125
			return;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   126
		}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   127
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   128
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   129
	bool HasNext()
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   130
	{
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   131
		return !(this->list->buckets.empty() || this->has_no_more_items);
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   132
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   133
};
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   134
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   135
/**
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   136
 * Sort by value, descending.
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   137
 */
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   138
class AIAbstractListSorterValueDescending : public AIAbstractListSorter {
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   139
private:
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   140
	AIAbstractList::AIAbstractListBucket::iterator bucket_iter;
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   141
	AIAbstractList::AIItemList *bucket_list;
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   142
	AIAbstractList::AIItemList::iterator bucket_list_iter;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   143
	bool has_no_more_items;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   144
	int32 item_next;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   145
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   146
public:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   147
	AIAbstractListSorterValueDescending(AIAbstractList *list)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   148
	{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   149
		this->list = list;
11059
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   150
		this->End();
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   151
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   152
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   153
	int32 Begin()
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   154
	{
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   155
		if (this->list->buckets.empty()) return 0;
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   156
		this->has_no_more_items = false;
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   157
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   158
		/* Go to the end of the bucket-list */
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   159
		this->bucket_iter = this->list->buckets.begin();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   160
		for (int i = this->list->buckets.size(); i > 1; i--) this->bucket_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   161
		this->bucket_list = &(*this->bucket_iter).second;
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   162
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   163
		/* Go to the end of the items in the bucket */
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   164
		this->bucket_list_iter = this->bucket_list->begin();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   165
		for (int i = this->bucket_list->size(); i > 1; i--) this->bucket_list_iter++;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   166
		this->item_next = *this->bucket_list_iter;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   167
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   168
		int32 item_current = this->item_next;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   169
		FindNext();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   170
		return item_current;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   171
	}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   172
11059
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   173
	void End() {
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   174
		this->bucket_list = NULL;
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   175
		this->has_no_more_items = true;
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   176
		this->item_next = 0;
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   177
	}
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   178
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   179
	void FindNext()
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   180
	{
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   181
		if (this->bucket_list == NULL) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   182
			this->has_no_more_items = true;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   183
			return;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   184
		}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   185
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   186
		if (this->bucket_list_iter == this->bucket_list->begin()) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   187
			if (this->bucket_iter == this->list->buckets.begin()) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   188
				this->bucket_list = NULL;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   189
				return;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   190
			}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   191
			this->bucket_iter--;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   192
			this->bucket_list = &(*this->bucket_iter).second;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   193
			/* Go to the end of the items in the bucket */
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   194
			this->bucket_list_iter = this->bucket_list->begin();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   195
			for (int i = this->bucket_list->size(); i > 1; i--) this->bucket_list_iter++;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   196
		} else {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   197
			this->bucket_list_iter--;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   198
		}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   199
		this->item_next = *this->bucket_list_iter;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   200
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   201
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   202
	int32 Next()
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   203
	{
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   204
		if (!this->HasNext()) return 0;
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   205
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   206
		int32 item_current = this->item_next;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   207
		FindNext();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   208
		return item_current;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   209
	}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   210
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   211
	void Remove(int item)
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   212
	{
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   213
		if (!this->HasNext()) return;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   214
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   215
		/* If we remove the 'next' item, skip to the next */
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   216
		if (item == this->item_next) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   217
			FindNext();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   218
			return;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   219
		}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   220
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   221
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   222
	bool HasNext()
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   223
	{
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   224
		return !(this->list->buckets.empty() || this->has_no_more_items);
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   225
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   226
};
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   227
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   228
/**
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   229
 * Sort by item, ascending.
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   230
 */
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   231
class AIAbstractListSorterItemAscending : public AIAbstractListSorter {
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   232
private:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   233
	AIAbstractList::AIAbstractListMap::iterator item_iter;
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   234
	bool has_no_more_items;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   235
	int32 item_next;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   236
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   237
public:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   238
	AIAbstractListSorterItemAscending(AIAbstractList *list)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   239
	{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   240
		this->list = list;
11059
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   241
		this->End();
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   242
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   243
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   244
	int32 Begin()
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   245
	{
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   246
		if (this->list->items.empty()) return 0;
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   247
		this->has_no_more_items = false;
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   248
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   249
		this->item_iter = this->list->items.begin();
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   250
		this->item_next = (*this->item_iter).first;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   251
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   252
		int32 item_current = this->item_next;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   253
		FindNext();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   254
		return item_current;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   255
	}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   256
11059
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   257
	void End()
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   258
	{
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   259
		this->has_no_more_items = true;
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   260
	}
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   261
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   262
	void FindNext()
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   263
	{
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   264
		if (this->item_iter == this->list->items.end()) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   265
			this->has_no_more_items = true;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   266
			return;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   267
		}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   268
		this->item_iter++;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   269
		if (this->item_iter != this->list->items.end()) item_next = (*this->item_iter).first;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   270
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   271
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   272
	int32 Next()
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   273
	{
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   274
		if (!this->HasNext()) return 0;
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   275
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   276
		int32 item_current = this->item_next;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   277
		FindNext();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   278
		return item_current;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   279
	}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   280
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   281
	void Remove(int item) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   282
		if (!this->HasNext()) return;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   283
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   284
		/* If we remove the 'next' item, skip to the next */
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   285
		if (item == this->item_next) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   286
			FindNext();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   287
			return;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   288
		}
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   289
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   290
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   291
	bool HasNext()
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   292
	{
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   293
		return !(this->list->items.empty() || this->has_no_more_items);
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   294
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   295
};
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   296
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   297
/**
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   298
 * Sort by item, descending.
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   299
 */
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   300
class AIAbstractListSorterItemDescending : public AIAbstractListSorter {
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   301
private:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   302
	AIAbstractList::AIAbstractListMap::reverse_iterator item_iter;
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   303
	bool has_no_more_items;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   304
	int32 item_next;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   305
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   306
public:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   307
	AIAbstractListSorterItemDescending(AIAbstractList *list)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   308
	{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   309
		this->list = list;
11059
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   310
		this->End();
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   311
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   312
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   313
	int32 Begin()
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   314
	{
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   315
		if (this->list->items.empty()) return 0;
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   316
		this->has_no_more_items = false;
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   317
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   318
		this->item_iter = this->list->items.rbegin();
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   319
		this->item_next = (*this->item_iter).first;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   320
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   321
		int32 item_current = this->item_next;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   322
		FindNext();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   323
		return item_current;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   324
	}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   325
11059
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   326
	void End()
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   327
	{
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   328
		this->has_no_more_items = true;
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   329
	}
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   330
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   331
	void FindNext()
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   332
	{
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   333
		if (this->item_iter == this->list->items.rend()) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   334
			this->has_no_more_items = true;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   335
			return;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   336
		}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   337
		this->item_iter++;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   338
		if (this->item_iter != this->list->items.rend()) item_next = (*this->item_iter).first;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   339
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   340
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   341
	int32 Next()
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   342
	{
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   343
		if (!this->HasNext()) return 0;
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   344
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   345
		int32 item_current = this->item_next;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   346
		FindNext();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   347
		return item_current;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   348
	}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   349
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   350
	void Remove(int item)
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   351
	{
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   352
		if (!this->HasNext()) return;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   353
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   354
		/* If we remove the 'next' item, skip to the next */
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   355
		if (item == this->item_next) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   356
			FindNext();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   357
			return;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   358
		}
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   359
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   360
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   361
	bool HasNext()
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   362
	{
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   363
		return !(this->list->items.empty() || this->has_no_more_items);
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   364
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   365
};
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   366
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   367
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   368
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   369
AIAbstractList::AIAbstractList()
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   370
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   371
	/* Default sorter */
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   372
	this->sorter         = new AIAbstractListSorterValueDescending(this);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   373
	this->sorter_type    = SORT_BY_VALUE;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   374
	this->sort_ascending = false;
9752
bd87e54186f2 (svn r12235) [NoAI] -Fix: don't segfault if you do a Next() on an empty list (tnx Progman)
truebrain
parents: 9731
diff changeset
   375
	this->initialized    = false;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   376
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   377
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   378
AIAbstractList::~AIAbstractList()
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   379
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   380
	delete this->sorter;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   381
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   382
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   383
bool AIAbstractList::HasItem(int32 item)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   384
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   385
	return this->items.count(item) == 1;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   386
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   387
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   388
void AIAbstractList::Clear()
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   389
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   390
	this->items.clear();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   391
	this->buckets.clear();
11059
b1751c5973cc (svn r13616) [NoAI] -Fix: on AIAbstractList->Clear(), make sure the sorter is invalidated too
truebrain
parents: 11058
diff changeset
   392
	this->sorter->End();
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   393
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   394
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   395
void AIAbstractList::AddItem(int32 item)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   396
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   397
	if (this->HasItem(item)) return;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   398
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   399
	this->items[item] = 0;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   400
	this->buckets[0].insert(item);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   401
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   402
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   403
void AIAbstractList::RemoveItem(int32 item)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   404
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   405
	if (!this->HasItem(item)) return;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   406
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   407
	int32 value = this->GetValue(item);
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   408
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   409
	this->sorter->Remove(item);
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   410
	this->buckets[value].erase(item);
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   411
	if (this->buckets[value].empty()) this->buckets.erase(value);
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   412
	this->items.erase(item);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   413
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   414
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   415
int32 AIAbstractList::Begin()
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   416
{
9752
bd87e54186f2 (svn r12235) [NoAI] -Fix: don't segfault if you do a Next() on an empty list (tnx Progman)
truebrain
parents: 9731
diff changeset
   417
	this->initialized = true;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   418
	return this->sorter->Begin();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   419
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   420
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   421
int32 AIAbstractList::Next()
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   422
{
9752
bd87e54186f2 (svn r12235) [NoAI] -Fix: don't segfault if you do a Next() on an empty list (tnx Progman)
truebrain
parents: 9731
diff changeset
   423
	if (this->initialized == false) {
9755
d1d7e7738985 (svn r12240) [NoAI] -Fix r12235: minor typo (glx)
truebrain
parents: 9752
diff changeset
   424
		DEBUG(ai, 0, "ERROR: Next() is invalid as Begin() is never called");
9752
bd87e54186f2 (svn r12235) [NoAI] -Fix: don't segfault if you do a Next() on an empty list (tnx Progman)
truebrain
parents: 9731
diff changeset
   425
		return false;
bd87e54186f2 (svn r12235) [NoAI] -Fix: don't segfault if you do a Next() on an empty list (tnx Progman)
truebrain
parents: 9731
diff changeset
   426
	}
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   427
	return this->sorter->Next();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   428
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   429
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   430
bool AIAbstractList::IsEmpty()
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   431
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   432
	return this->items.empty();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   433
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   434
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   435
bool AIAbstractList::HasNext()
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   436
{
9752
bd87e54186f2 (svn r12235) [NoAI] -Fix: don't segfault if you do a Next() on an empty list (tnx Progman)
truebrain
parents: 9731
diff changeset
   437
	if (this->initialized == false) {
bd87e54186f2 (svn r12235) [NoAI] -Fix: don't segfault if you do a Next() on an empty list (tnx Progman)
truebrain
parents: 9731
diff changeset
   438
		DEBUG(ai, 0, "ERROR: HasNext() is invalid as Begin() is never called");
bd87e54186f2 (svn r12235) [NoAI] -Fix: don't segfault if you do a Next() on an empty list (tnx Progman)
truebrain
parents: 9731
diff changeset
   439
		return false;
bd87e54186f2 (svn r12235) [NoAI] -Fix: don't segfault if you do a Next() on an empty list (tnx Progman)
truebrain
parents: 9731
diff changeset
   440
	}
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   441
	return this->sorter->HasNext();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   442
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   443
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   444
int32 AIAbstractList::Count()
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   445
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   446
	return this->items.size();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   447
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   448
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   449
int32 AIAbstractList::GetValue(int32 item)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   450
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   451
	if (!this->HasItem(item)) return 0;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   452
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   453
	return this->items[item];
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   454
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   455
9664
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   456
bool AIAbstractList::SetValue(int32 item, int32 value)
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   457
{
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   458
	if (!this->HasItem(item)) return false;
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   459
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   460
	int32 value_old = this->GetValue(item);
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   461
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   462
	this->sorter->Remove(item);
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   463
	this->buckets[value_old].erase(item);
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   464
	if (this->buckets[value_old].empty()) this->buckets.erase(value_old);
9664
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   465
	this->items[item] = value;
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   466
	this->buckets[value].insert(item);
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   467
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   468
	return true;
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   469
}
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   470
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   471
void AIAbstractList::Sort(SorterType sorter, bool ascending)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   472
{
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   473
	if (sorter == this->sorter_type && ascending == this->sort_ascending) return;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   474
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   475
	delete this->sorter;
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   476
	switch (sorter) {
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   477
		case SORT_BY_ITEM:
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   478
			if (ascending) this->sorter = new AIAbstractListSorterItemAscending(this);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   479
			else           this->sorter = new AIAbstractListSorterItemDescending(this);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   480
			break;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   481
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   482
		case SORT_BY_VALUE:
9702
e782b59f1f6a (svn r11075) [NoAI] -Fix: sorting on value did not work as expected. Patch by GeekToo.
rubidium
parents: 9665
diff changeset
   483
			if (ascending) this->sorter = new AIAbstractListSorterValueAscending(this);
e782b59f1f6a (svn r11075) [NoAI] -Fix: sorting on value did not work as expected. Patch by GeekToo.
rubidium
parents: 9665
diff changeset
   484
			else           this->sorter = new AIAbstractListSorterValueDescending(this);
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   485
			break;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   486
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   487
		default:
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   488
			this->Sort(SORT_BY_ITEM, false);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   489
			return;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   490
	}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   491
	this->sorter_type    = sorter;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   492
	this->sort_ascending = ascending;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   493
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   494
9796
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   495
void AIAbstractList::AddList(AIAbstractList *list)
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   496
{
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   497
	AIAbstractListMap *list_items = &list->items;
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   498
	for (AIAbstractListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) {
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   499
		this->AddItem((*iter).first);
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   500
		this->SetValue((*iter).first, (*iter).second);
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   501
	}
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   502
}
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   503
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   504
void AIAbstractList::RemoveAboveValue(int32 value)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   505
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   506
	for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   507
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   508
		if ((*iter).second > value) this->items.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   509
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   510
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   511
	for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   512
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   513
		if ((*iter).first > value) this->buckets.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   514
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   515
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   516
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   517
void AIAbstractList::RemoveBelowValue(int32 value)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   518
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   519
	for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   520
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   521
		if ((*iter).second < value) this->items.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   522
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   523
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   524
	for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   525
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   526
		if ((*iter).first < value) this->buckets.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   527
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   528
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   529
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   530
void AIAbstractList::RemoveBetweenValue(int32 start, int32 end)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   531
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   532
	for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   533
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   534
		if ((*iter).second > start && (*iter).second < end) this->items.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   535
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   536
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   537
	for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   538
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   539
		if ((*iter).first > start && (*iter).first < end) this->buckets.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   540
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   541
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   542
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   543
void AIAbstractList::RemoveValue(int32 value)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   544
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   545
	for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   546
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   547
		if ((*iter).second == value) this->items.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   548
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   549
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   550
	for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   551
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   552
		if ((*iter).first == value) this->buckets.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   553
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   554
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   555
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   556
void AIAbstractList::RemoveTop(int32 count)
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   557
{
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   558
	if (!this->sort_ascending) {
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   559
		this->Sort(this->sorter_type, !this->sort_ascending);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   560
		this->RemoveBottom(count);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   561
		this->Sort(this->sorter_type, !this->sort_ascending);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   562
		return;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   563
	}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   564
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   565
	switch (this->sorter_type) {
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   566
		default: NOT_REACHED();
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   567
		case SORT_BY_VALUE:
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   568
			for (AIAbstractListBucket::iterator iter = this->buckets.begin(); iter != this->buckets.end(); iter = this->buckets.begin()) {
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   569
				AIItemList *items = &(*iter).second;
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   570
				size_t size = items->size();
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   571
				for (AIItemList::iterator iter = items->begin(); iter != items->end(); iter = items->begin()) {
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   572
					if (--count < 0) return;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   573
					this->RemoveItem(*iter);
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   574
					/* When the last item is removed from the bucket, the bucket itself is removed.
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   575
					 * This means that the iterators can be invalid after a call to RemoveItem.
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   576
					 */
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   577
					if (--size == 0) break;
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   578
				}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   579
			}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   580
			break;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   581
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   582
		case SORT_BY_ITEM:
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   583
			for (AIAbstractListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter = this->items.begin()) {
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   584
				if (--count < 0) return;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   585
				this->RemoveItem((*iter).first);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   586
			}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   587
			break;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   588
	}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   589
}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   590
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   591
void AIAbstractList::RemoveBottom(int32 count)
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   592
{
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   593
	if (!this->sort_ascending) {
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   594
		this->Sort(this->sorter_type, !this->sort_ascending);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   595
		this->RemoveTop(count);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   596
		this->Sort(this->sorter_type, !this->sort_ascending);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   597
		return;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   598
	}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   599
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   600
	switch (this->sorter_type) {
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   601
		default: NOT_REACHED();
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   602
		case SORT_BY_VALUE:
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   603
			for (AIAbstractListBucket::reverse_iterator iter = this->buckets.rbegin(); iter != this->buckets.rend(); iter = this->buckets.rbegin()) {
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   604
				AIItemList *items = &(*iter).second;
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   605
				size_t size = items->size();
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   606
				for (AIItemList::reverse_iterator iter = items->rbegin(); iter != items->rend(); iter = items->rbegin()) {
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   607
					if (--count < 0) return;
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   608
					this->RemoveItem(*iter);
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   609
					/* When the last item is removed from the bucket, the bucket itself is removed.
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   610
					 * This means that the iterators can be invalid after a call to RemoveItem.
9721
9a27928bcd5e (svn r11497) [NoAI] -Fix: when removing the last item from a bucket, the bucket gets removed invalidating iterators. Based on a patch by xargonax.
rubidium
parents: 9702
diff changeset
   611
					 */
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   612
					if (--size == 0) break;
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   613
				}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   614
			}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   615
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   616
		case SORT_BY_ITEM:
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   617
			for (AIAbstractListMap::reverse_iterator iter = this->items.rbegin(); iter != this->items.rend(); iter = this->items.rbegin()) {
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   618
				if (--count < 0) return;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   619
				this->RemoveItem((*iter).first);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   620
			}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   621
			break;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   622
	}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   623
}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   624
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   625
void AIAbstractList::RemoveList(AIAbstractList *list)
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   626
{
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   627
	AIAbstractListMap *list_items = &list->items;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   628
	for (AIAbstractListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) {
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   629
		this->RemoveItem((*iter).first);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   630
	}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   631
}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   632
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   633
void AIAbstractList::KeepAboveValue(int32 value)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   634
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   635
	for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   636
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   637
		if ((*iter).second <= value) this->items.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   638
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   639
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   640
	for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   641
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   642
		if ((*iter).first <= value) this->buckets.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   643
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   644
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   645
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   646
void AIAbstractList::KeepBelowValue(int32 value)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   647
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   648
	for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   649
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   650
		if ((*iter).second >= value) this->items.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   651
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   652
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   653
	for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   654
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   655
		if ((*iter).first >= value) this->buckets.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   656
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   657
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   658
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   659
void AIAbstractList::KeepBetweenValue(int32 start, int32 end)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   660
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   661
	for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   662
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   663
		if ((*iter).second <= start || (*iter).second >= end) this->items.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   664
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   665
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   666
	for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   667
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   668
		if ((*iter).first <= start || (*iter).first >= end) this->buckets.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   669
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   670
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   671
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   672
void AIAbstractList::KeepValue(int32 value)
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   673
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   674
	for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   675
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   676
		if ((*iter).second != value) this->items.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   677
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   678
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   679
	for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) {
9581
398688c1a07a (svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents: 9580
diff changeset
   680
		next_iter = iter; next_iter++;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   681
		if ((*iter).first != value) this->buckets.erase(iter);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   682
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   683
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   684
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   685
void AIAbstractList::KeepTop(int32 count)
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   686
{
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   687
	this->RemoveBottom(this->Count() - count);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   688
}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   689
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   690
void AIAbstractList::KeepBottom(int32 count)
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   691
{
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   692
	this->RemoveTop(this->Count() - count);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   693
}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   694
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   695
void AIAbstractList::KeepList(AIAbstractList *list)
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   696
{
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   697
	AIAbstractList tmp;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   698
	for (AIAbstractListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter++) {
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   699
		tmp.AddItem((*iter).first);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   700
		tmp.SetValue((*iter).first, (*iter).second);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   701
	}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   702
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   703
	tmp.RemoveList(list);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   704
	this->RemoveList(&tmp);
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   705
}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   706
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   707
SQInteger AIAbstractList::_get(HSQUIRRELVM vm) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   708
	if (sq_gettype(vm, 2) != OT_INTEGER) return SQ_ERROR;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   709
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   710
	SQInteger idx;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   711
	sq_getinteger(vm, 2, &idx);
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   712
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   713
	if (!this->HasItem(idx)) return SQ_ERROR;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   714
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   715
	sq_pushinteger(vm, this->GetValue(idx));
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   716
	return 1;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   717
}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   718
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   719
SQInteger AIAbstractList::_nexti(HSQUIRRELVM vm) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   720
	if (sq_gettype(vm, 2) == OT_NULL) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   721
		sq_pushinteger(vm, this->Begin());
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   722
		return 1;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   723
	}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   724
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   725
	SQInteger idx;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   726
	sq_getinteger(vm, 2, &idx);
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   727
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   728
	int val = this->Next();
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   729
	if (!this->HasNext()) {
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   730
		sq_pushnull(vm);
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   731
		return 1;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   732
	}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   733
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   734
	sq_pushinteger(vm, val);
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   735
	return 1;
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   736
}
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   737
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   738
SQInteger AIAbstractList::Valuate(HSQUIRRELVM vm) {
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   739
	int nparam = sq_gettop(vm) - 2;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   740
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   741
	/* Get the list instance and the function to call */
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   742
	HSQOBJECT obj_list, obj_func;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   743
	sq_getstackobj(vm, 1, &obj_list);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   744
	sq_getstackobj(vm, 2, &obj_func);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   745
10956
82aa600a9922 (svn r13510) [NoAI] -Fix: be a tiny bit more strict for AIAbstract.Valuate() (check the type of the first 2 params)
truebrain
parents: 10921
diff changeset
   746
	if (sq_isclass(obj_list)) {
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   747
		return sq_throwerror(vm, _SC("parameter 1 has an invalid type (expected instance)"));
10956
82aa600a9922 (svn r13510) [NoAI] -Fix: be a tiny bit more strict for AIAbstract.Valuate() (check the type of the first 2 params)
truebrain
parents: 10921
diff changeset
   748
	}
82aa600a9922 (svn r13510) [NoAI] -Fix: be a tiny bit more strict for AIAbstract.Valuate() (check the type of the first 2 params)
truebrain
parents: 10921
diff changeset
   749
	if (sq_isfunction(obj_func)) {
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   750
		return sq_throwerror(vm, _SC("parameter 2 has an invalid type (expected function)"));
10956
82aa600a9922 (svn r13510) [NoAI] -Fix: be a tiny bit more strict for AIAbstract.Valuate() (check the type of the first 2 params)
truebrain
parents: 10921
diff changeset
   751
	}
82aa600a9922 (svn r13510) [NoAI] -Fix: be a tiny bit more strict for AIAbstract.Valuate() (check the type of the first 2 params)
truebrain
parents: 10921
diff changeset
   752
10957
7a140b4cd91d (svn r13511) [NoAI] -Fix: add a reference to objects given in Valuate(), so they remain valid during their usage. This allows nameless functions (lambda functions) in Valuate() on long lists.
truebrain
parents: 10956
diff changeset
   753
	sq_addref(vm, &obj_func);
7a140b4cd91d (svn r13511) [NoAI] -Fix: add a reference to objects given in Valuate(), so they remain valid during their usage. This allows nameless functions (lambda functions) in Valuate() on long lists.
truebrain
parents: 10956
diff changeset
   754
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   755
	/* Read the params */
10921
f50864092014 (svn r13474) [NoAI] -Fix: remove the restriction of 10 params per Valuator
truebrain
parents: 9833
diff changeset
   756
	HSQOBJECT *obj_params = AllocaM(HSQOBJECT, nparam);
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   757
	for (int i = 0; i < nparam; i++) {
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   758
		sq_getstackobj(vm, i + 3, &obj_params[i]);
10957
7a140b4cd91d (svn r13511) [NoAI] -Fix: add a reference to objects given in Valuate(), so they remain valid during their usage. This allows nameless functions (lambda functions) in Valuate() on long lists.
truebrain
parents: 10956
diff changeset
   759
		sq_addref(vm, &obj_params[i]);
9772
c1035f0ac732 (svn r12265) [NoAI] -Add: added a general protection that doesn't allow people using valuators on lists that aren't ment for those valuators
truebrain
parents: 9755
diff changeset
   760
	}
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   761
	/* Remove all unneeded stuff */
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   762
	sq_pop(vm, nparam + 1);
9772
c1035f0ac732 (svn r12265) [NoAI] -Add: added a general protection that doesn't allow people using valuators on lists that aren't ment for those valuators
truebrain
parents: 9755
diff changeset
   763
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   764
	/* Walk all items, and query the result */
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   765
	this->buckets.clear();
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   766
	for (AIAbstractListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter++) {
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   767
		/* The function to call */
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   768
		sq_pushobject(vm, obj_func);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   769
		/* The 'list' instance; this is most likely wrong, but we need to send something ;) */
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   770
		sq_pushobject(vm, obj_list);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   771
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   772
		/* Now send the params */
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   773
		sq_pushinteger(vm, (*iter).first);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   774
		for (int i = 0; i < nparam; i++) {
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   775
			sq_pushobject(vm, obj_params[i]);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   776
		}
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   777
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   778
		/* Call the function */
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   779
		if (SQ_FAILED(sq_call(vm, nparam + 2, SQTrue, SQTrue))) return SQ_ERROR;
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   780
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   781
		/* Retreive the return value */
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   782
		SQInteger value;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   783
		switch (sq_gettype(vm, -1)) {
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   784
			case OT_INTEGER: {
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   785
				sq_getinteger(vm, -1, &value);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   786
			} break;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   787
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   788
			case OT_BOOL: {
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   789
				SQBool v;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   790
				sq_getbool(vm, -1, &v);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   791
				value = v ? 1 : 0;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   792
			} break;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   793
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   794
			default: {
10957
7a140b4cd91d (svn r13511) [NoAI] -Fix: add a reference to objects given in Valuate(), so they remain valid during their usage. This allows nameless functions (lambda functions) in Valuate() on long lists.
truebrain
parents: 10956
diff changeset
   795
				sq_pop(vm, 3);
7a140b4cd91d (svn r13511) [NoAI] -Fix: add a reference to objects given in Valuate(), so they remain valid during their usage. This allows nameless functions (lambda functions) in Valuate() on long lists.
truebrain
parents: 10956
diff changeset
   796
				sq_release(vm, &obj_func);
7a140b4cd91d (svn r13511) [NoAI] -Fix: add a reference to objects given in Valuate(), so they remain valid during their usage. This allows nameless functions (lambda functions) in Valuate() on long lists.
truebrain
parents: 10956
diff changeset
   797
				for (int i = 0; i < nparam; i++) sq_release(vm, &obj_params[i]);
7a140b4cd91d (svn r13511) [NoAI] -Fix: add a reference to objects given in Valuate(), so they remain valid during their usage. This allows nameless functions (lambda functions) in Valuate() on long lists.
truebrain
parents: 10956
diff changeset
   798
11058
3305a425f55b (svn r13615) [NoAI] -Fix: fixed most, if not all, problems around AIAbstractList. It is now safe to remove values while looping, among other things.
truebrain
parents: 10957
diff changeset
   799
				return sq_throwerror(vm, _SC("return value of valuator is not valid (not integer/bool)"));
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   800
			}
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   801
		}
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   802
		/* Remove junk */
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   803
		sq_pop(vm, 2);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   804
10957
7a140b4cd91d (svn r13511) [NoAI] -Fix: add a reference to objects given in Valuate(), so they remain valid during their usage. This allows nameless functions (lambda functions) in Valuate() on long lists.
truebrain
parents: 10956
diff changeset
   805
		(*iter).second = (int32)value;
7a140b4cd91d (svn r13511) [NoAI] -Fix: add a reference to objects given in Valuate(), so they remain valid during their usage. This allows nameless functions (lambda functions) in Valuate() on long lists.
truebrain
parents: 10956
diff changeset
   806
		this->buckets[(int32)value].insert((*iter).first);
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   807
	}
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   808
10957
7a140b4cd91d (svn r13511) [NoAI] -Fix: add a reference to objects given in Valuate(), so they remain valid during their usage. This allows nameless functions (lambda functions) in Valuate() on long lists.
truebrain
parents: 10956
diff changeset
   809
	sq_release(vm, &obj_func);
7a140b4cd91d (svn r13511) [NoAI] -Fix: add a reference to objects given in Valuate(), so they remain valid during their usage. This allows nameless functions (lambda functions) in Valuate() on long lists.
truebrain
parents: 10956
diff changeset
   810
	for (int i = 0; i < nparam; i++) sq_release(vm, &obj_params[i]);
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   811
	return 0;
9579
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   812
}