src/ai/api/ai_abstractlist.cpp
author truebrain
Fri, 13 Jun 2008 19:12:55 +0000
branchnoai
changeset 10956 82aa600a9922
parent 10921 f50864092014
child 10957 7a140b4cd91d
permissions -rw-r--r--
(svn r13510) [NoAI] -Fix: be a tiny bit more strict for AIAbstract.Valuate() (check the type of the first 2 params)
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
	/**
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    29
	 * 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
    30
	 */
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    31
	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
    32
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    33
	/**
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
	 * 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
    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 bool HasNext() = 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
/**
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
 * 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
    41
 */
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    42
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
    43
private:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    44
	AIAbstractList::AIAbstractListBucket::iterator bucket_iter;
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    45
	AIAbstractList::AIItemList *bucket_list;
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    46
	AIAbstractList::AIItemList::iterator 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
    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
public:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    49
	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
    50
	{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
		this->list = list;
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
    52
		this->bucket_list = NULL;
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
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    54
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    55
	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
    56
	{
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
    57
		if (this->list->buckets.empty()) return 0;
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
    58
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
		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
    60
		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
    61
		this->bucket_list_iter = this->bucket_list->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
    62
		return *bucket_list_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
    63
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    64
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
	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
    66
	{
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
    67
		if (this->list->buckets.empty() || this->bucket_list == NULL) return 0;
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
    68
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
    69
		this->bucket_list_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
    70
		if (this->bucket_list_iter == this->bucket_list->end()) {
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    71
			this->bucket_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
    72
			if (this->bucket_iter == this->list->buckets.end()) 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
    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();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    75
		}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    76
		return *bucket_list_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
    77
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    78
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    79
	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
    80
	{
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
    81
		if (this->list->buckets.empty() || this->bucket_list == NULL) return false;
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
    82
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
    83
		return this->bucket_iter != this->list->buckets.end() && this->bucket_list_iter != this->bucket_list->end();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    84
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    85
};
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    86
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    87
/**
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    88
 * 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
    89
 */
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    90
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
    91
private:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    92
	AIAbstractList::AIAbstractListBucket::reverse_iterator bucket_iter;
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    93
	AIAbstractList::AIItemList *bucket_list;
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    94
	AIAbstractList::AIItemList::reverse_iterator 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
    95
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    96
public:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
    97
	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
    98
	{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
    99
		this->list = list;
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
   100
		this->bucket_list = NULL;
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
   101
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   102
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   103
	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
   104
	{
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   105
		if (this->list->buckets.empty()) return 0;
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   106
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
		this->bucket_iter = this->list->buckets.rbegin();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
		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
   109
		this->bucket_list_iter = this->bucket_list->rbegin();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
		return *bucket_list_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
   111
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   112
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   113
	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
   114
	{
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
   115
		if (this->list->buckets.empty() || this->bucket_list == NULL) return 0;
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   116
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
   117
		this->bucket_list_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
   118
		if (this->bucket_list_iter == this->bucket_list->rend()) {
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   119
			this->bucket_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
   120
			if (this->bucket_iter == this->list->buckets.rend()) 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
   121
			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
   122
			this->bucket_list_iter = this->bucket_list->rbegin();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   123
		}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   124
		return *bucket_list_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
   125
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
	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
   128
	{
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
   129
		if (this->list->buckets.empty() || this->bucket_list == NULL) return false;
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   130
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
   131
		return this->bucket_iter != this->list->buckets.rend() && this->bucket_list_iter != this->bucket_list->rend();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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 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
   137
 */
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   138
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
   139
private:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   140
	AIAbstractList::AIAbstractListMap::iterator item_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
   141
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   142
public:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   143
	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
   144
	{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
		this->list = list;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   147
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
	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
   149
	{
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   150
		if (this->list->items.empty()) return 0;
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   151
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
   152
		this->item_iter = this->list->items.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
   153
		return (*this->item_iter).first;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   155
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   156
	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
   157
	{
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   158
		if (this->list->items.empty()) return 0;
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   159
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
   160
		this->item_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
   161
		return (*this->item_iter).first;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   162
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   163
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   164
	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
   165
	{
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   166
		if (this->list->items.empty()) return false;
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   167
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
   168
		return this->item_iter != this->list->items.end();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   169
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   170
};
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   171
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   172
/**
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   173
 * 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
   174
 */
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   175
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
   176
private:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   177
	AIAbstractList::AIAbstractListMap::reverse_iterator item_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
   178
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   179
public:
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   180
	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
   181
	{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   182
		this->list = list;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   183
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   184
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   185
	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
   186
	{
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   187
		if (this->list->items.empty()) return 0;
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   188
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
   189
		this->item_iter = this->list->items.rbegin();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   190
		return (*this->item_iter).first;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   191
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   192
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   193
	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
   194
	{
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   195
		if (this->list->items.empty()) return 0;
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   196
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
   197
		this->item_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
   198
		return (*this->item_iter).first;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   199
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
	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
   202
	{
9606
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   203
		if (this->list->items.empty()) return false;
91086d7330a5 (svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents: 9593
diff changeset
   204
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
   205
		return this->item_iter != this->list->items.rend();
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   206
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   207
};
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   208
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   209
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   210
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   211
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
   212
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   213
	/* 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
   214
	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
   215
	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
   216
	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
   217
	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
   218
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   220
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
   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
	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
   223
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   224
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   225
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
   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
	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
   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
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   230
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
   231
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
	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
   233
	this->buckets.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
   234
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   235
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   236
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
   237
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   238
	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
   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->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
   241
	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
   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
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   244
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
   245
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   246
	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
   247
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   248
	this->buckets[this->GetValue(item)].erase(item);
9664
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   249
	if (this->buckets[this->GetValue(item)].empty()) this->buckets.erase(this->GetValue(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
   250
	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
   251
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   252
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   253
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
   254
{
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
   255
	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
   256
	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
   257
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   258
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   259
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
   260
{
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
   261
	if (this->initialized == false) {
9755
d1d7e7738985 (svn r12240) [NoAI] -Fix r12235: minor typo (glx)
truebrain
parents: 9752
diff changeset
   262
		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
   263
		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
   264
	}
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
   265
	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
   266
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   267
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   268
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
   269
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
	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
   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
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   273
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
   274
{
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
   275
	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
   276
		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
   277
		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
   278
	}
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
   279
	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
   280
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   281
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   282
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
   283
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   284
	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
   285
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   286
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   287
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
   288
{
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
	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
   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
	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
   292
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   293
9664
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   294
bool AIAbstractList::SetValue(int32 item, int32 value)
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   295
{
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   296
	if (!this->HasItem(item)) return false;
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   297
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   298
	this->buckets[this->GetValue(item)].erase(item);
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   299
	if (this->buckets[this->GetValue(item)].empty()) this->buckets.erase(this->GetValue(item));
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   300
	this->items[item] = value;
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   301
	this->buckets[value].insert(item);
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   302
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   303
	return true;
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   304
}
c5741021bf59 (svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents: 9606
diff changeset
   305
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   306
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
   307
{
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   308
	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
   309
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
   310
	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
   311
	switch (sorter) {
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   312
		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
   313
			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
   314
			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
   315
			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
   316
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   317
		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
   318
			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
   319
			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
   320
			break;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   321
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   322
		default:
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   323
			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
   324
			return;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   325
	}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   326
	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
   327
	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
   328
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   329
9796
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   330
void AIAbstractList::AddList(AIAbstractList *list)
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   331
{
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   332
	AIAbstractListMap *list_items = &list->items;
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   333
	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
   334
		this->AddItem((*iter).first);
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   335
		this->SetValue((*iter).first, (*iter).second);
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   336
	}
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   337
}
83d54622190c (svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents: 9775
diff changeset
   338
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   339
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
   340
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   341
	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
   342
		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
   343
		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
   344
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   345
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   346
	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
   347
		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
   348
		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
   349
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   350
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   351
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   352
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
   353
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   354
	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
   355
		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
   356
		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
   357
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   358
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   359
	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
   360
		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
   361
		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
   362
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   363
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   365
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
   366
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   367
	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
   368
		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
   369
		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
   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
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   372
	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
   373
		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
   374
		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
   375
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
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
   379
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   380
	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
   381
		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
   382
		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
   383
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   385
	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
   386
		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
   387
		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
   388
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   391
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
   392
{
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   393
	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
   394
		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
   395
		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
   396
		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
   397
		return;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   398
	}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   399
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   400
	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
   401
		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
   402
		case SORT_BY_VALUE:
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   403
			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
   404
				AIItemList *items = &(*iter).second;
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   405
				size_t size = items->size();
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   406
				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
   407
					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
   408
					this->RemoveItem(*iter);
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   409
					/* 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
   410
					 * 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
   411
					 */
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   412
					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
   413
				}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   414
			}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   415
			break;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   416
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   417
		case SORT_BY_ITEM:
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   418
			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
   419
				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
   420
				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
   421
			}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   422
			break;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   423
	}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   424
}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   425
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   426
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
   427
{
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   428
	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
   429
		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
   430
		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
   431
		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
   432
		return;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   433
	}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   434
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   435
	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
   436
		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
   437
		case SORT_BY_VALUE:
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   438
			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
   439
				AIItemList *items = &(*iter).second;
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   440
				size_t size = items->size();
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   441
				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
   442
					if (--count < 0) return;
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   443
					this->RemoveItem(*iter);
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   444
					/* 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
   445
					 * 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
   446
					 */
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   447
					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
   448
				}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   449
			}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   450
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   451
		case SORT_BY_ITEM:
9731
9b1552d0fd9b (svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents: 9721
diff changeset
   452
			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
   453
				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
   454
				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
   455
			}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   456
			break;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   457
	}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   458
}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   459
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   460
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
   461
{
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   462
	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
   463
	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
   464
		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
   465
	}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   466
}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   467
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   468
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
   469
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   470
	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
   471
		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
   472
		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
   473
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   474
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   475
	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
   476
		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
   477
		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
   478
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   479
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   480
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   481
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
   482
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   483
	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
   484
		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
   485
		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
   486
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   487
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   488
	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
   489
		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
   490
		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
   491
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   492
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   494
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
   495
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   496
	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
   497
		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
   498
		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
   499
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   500
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   501
	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
   502
		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
   503
		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
   504
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   506
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   507
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
   508
{
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   509
	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
   510
		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
   511
		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
   512
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   514
	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
   515
		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
   516
		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
   517
	}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), 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
}
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   519
9665
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   520
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
   521
{
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   522
	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
   523
}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   524
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   525
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
   526
{
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   527
	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
   528
}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   529
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   530
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
   531
{
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   532
	AIAbstractList tmp;
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   533
	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
   534
		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
   535
		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
   536
	}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   537
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   538
	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
   539
	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
   540
}
e889ac1e663a (svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents: 9664
diff changeset
   541
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   542
SQInteger AIAbstractList::Valuate(HSQUIRRELVM vm) {
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   543
	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
   544
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   545
	/* 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
   546
	HSQOBJECT obj_list, obj_func;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   547
	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
   548
	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
   549
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
   550
	if (sq_isclass(obj_list)) {
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
   551
		sq_throwerror(vm, _SC("parameter 1 has an invalid type (expected instance)"));
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
   552
		return -1;
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
   553
	}
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
   554
	if (sq_isfunction(obj_func)) {
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
   555
		sq_throwerror(vm, _SC("parameter 2 has an invalid type (expected function)"));
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
   556
		return -1;
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
   557
	}
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
   558
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   559
	/* Read the params */
10921
f50864092014 (svn r13474) [NoAI] -Fix: remove the restriction of 10 params per Valuator
truebrain
parents: 9833
diff changeset
   560
	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
   561
	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
   562
		sq_getstackobj(vm, i + 3, &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
   563
	}
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   564
	/* Remove all unneeded stuff */
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   565
	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
   566
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   567
	/* 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
   568
	this->buckets.clear();
9593
012f29f59906 (svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents: 9589
diff changeset
   569
	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
   570
		/* The function to call */
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   571
		sq_pushobject(vm, obj_func);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   572
		/* 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
   573
		sq_pushobject(vm, obj_list);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   574
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   575
		/* Now send the params */
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   576
		sq_pushinteger(vm, (*iter).first);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   577
		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
   578
			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
   579
		}
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   580
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   581
		/* Call the function */
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   582
		if (SQ_FAILED(sq_call(vm, nparam + 2, SQTrue, SQTrue))) return -1;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   583
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   584
		/* Retreive the return value */
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   585
		SQInteger value;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   586
		switch (sq_gettype(vm, -1)) {
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   587
			case OT_INTEGER: {
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   588
				sq_getinteger(vm, -1, &value);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   589
			} break;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   590
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   591
			case OT_BOOL: {
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   592
				SQBool v;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   593
				sq_getbool(vm, -1, &v);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   594
				value = v ? 1 : 0;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   595
			} break;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   596
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   597
			default: {
9819
fe876b1e5138 (svn r12422) [NoAI] -Fix (r12411): unicode compilation was broken
glx
parents: 9816
diff changeset
   598
				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
   599
				return -1;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   600
			}
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   601
		}
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   602
		/* Remove junk */
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   603
		sq_pop(vm, 2);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   604
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
   605
		(*iter).second = value;
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   606
		this->buckets[value].insert((*iter).first);
632263c0cf5a (svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff changeset
   607
	}
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   608
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9802
diff changeset
   609
	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
   610
}