author | truebrain |
Wed, 26 Mar 2008 15:17:40 +0000 | |
branch | noai |
changeset 9823 | 0b7f816cf46f |
parent 9819 | fe876b1e5138 |
child 9833 | 89a64246458f |
permissions | -rw-r--r-- |
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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
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" |
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
|
8 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
/** |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
10 |
* 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
|
11 |
*/ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
12 |
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
|
13 |
protected: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
14 |
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
|
15 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
17 |
/** |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
* 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
|
19 |
*/ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
20 |
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
|
21 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
* 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
|
24 |
*/ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
26 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
* 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
|
29 |
*/ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
31 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
* 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
|
34 |
*/ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
36 |
}; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
* 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
|
40 |
*/ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
41 |
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
|
42 |
private: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
43 |
AIAbstractList::AIAbstractListBucket::iterator bucket_iter; |
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
44 |
AIAbstractList::AIItemList *bucket_list; |
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
45 |
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
|
46 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
public: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
48 |
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
|
49 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
50 |
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
|
51 |
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
|
52 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
55 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
56 |
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
|
57 |
|
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
63 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
65 |
{ |
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
|
66 |
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
|
67 |
|
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
76 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
79 |
{ |
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
|
80 |
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
|
81 |
|
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
|
82 |
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
|
83 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
* 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
|
88 |
*/ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
89 |
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
|
90 |
private: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
91 |
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
|
92 |
AIAbstractList::AIItemList *bucket_list; |
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
93 |
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
|
94 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
public: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
96 |
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
|
97 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
99 |
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
|
100 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
103 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
104 |
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
|
105 |
|
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
113 |
{ |
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
|
114 |
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
|
115 |
|
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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
124 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
127 |
{ |
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
|
128 |
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
|
129 |
|
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
|
130 |
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
|
131 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
* 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
|
136 |
*/ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
137 |
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
|
138 |
private: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
139 |
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
|
140 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
public: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
142 |
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
|
143 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
145 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
146 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
148 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
149 |
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
|
150 |
|
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
151 |
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
|
152 |
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
|
153 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
156 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
157 |
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
|
158 |
|
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
|
159 |
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
|
160 |
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
|
161 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
164 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
165 |
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
|
166 |
|
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
|
167 |
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
|
168 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
* 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
|
173 |
*/ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
174 |
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
|
175 |
private: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
176 |
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
|
177 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
public: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
179 |
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
|
180 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
182 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
185 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
186 |
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
|
187 |
|
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
|
188 |
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
|
189 |
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
|
190 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
193 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
194 |
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
|
195 |
|
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
|
196 |
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
|
197 |
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
|
198 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
201 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
202 |
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
|
203 |
|
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
|
204 |
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
|
205 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
210 |
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
|
211 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
/* 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
|
213 |
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
|
214 |
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
|
215 |
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
|
216 |
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
|
217 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
219 |
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
|
220 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
221 |
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
|
222 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
224 |
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
|
225 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
226 |
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
|
227 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
228 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
229 |
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
|
230 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
232 |
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
|
233 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
235 |
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
|
236 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
237 |
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
|
238 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
240 |
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
|
241 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
243 |
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
|
244 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
246 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
this->buckets[this->GetValue(item)].erase(item); |
9664
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
248 |
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
|
249 |
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
|
250 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
252 |
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
|
253 |
{ |
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
|
254 |
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
|
255 |
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
|
256 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
258 |
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
|
259 |
{ |
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
|
260 |
if (this->initialized == false) { |
9755
d1d7e7738985
(svn r12240) [NoAI] -Fix r12235: minor typo (glx)
truebrain
parents:
9752
diff
changeset
|
261 |
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
|
262 |
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
|
263 |
} |
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
|
264 |
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
|
265 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
267 |
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
|
268 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
270 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
271 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
272 |
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
|
273 |
{ |
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
|
274 |
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
|
275 |
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
|
276 |
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
|
277 |
} |
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
|
278 |
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
|
279 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
281 |
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
|
282 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
284 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
286 |
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
|
287 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
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
|
289 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
290 |
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
|
291 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9664
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
293 |
bool AIAbstractList::SetValue(int32 item, int32 value) |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
294 |
{ |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
295 |
if (!this->HasItem(item)) return false; |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
296 |
|
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
297 |
this->buckets[this->GetValue(item)].erase(item); |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
298 |
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
|
299 |
this->items[item] = value; |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
300 |
this->buckets[value].insert(item); |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
301 |
|
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
302 |
return true; |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
303 |
} |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
304 |
|
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
305 |
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
|
306 |
{ |
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
307 |
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
|
308 |
|
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
|
309 |
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
|
310 |
switch (sorter) { |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
311 |
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
|
312 |
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
|
313 |
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
|
314 |
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
|
315 |
|
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
316 |
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
|
317 |
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
|
318 |
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
|
319 |
break; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
320 |
|
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
321 |
default: |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
322 |
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
|
323 |
return; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
324 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
325 |
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
|
326 |
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
|
327 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9796
83d54622190c
(svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents:
9775
diff
changeset
|
329 |
void AIAbstractList::AddList(AIAbstractList *list) |
83d54622190c
(svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents:
9775
diff
changeset
|
330 |
{ |
83d54622190c
(svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents:
9775
diff
changeset
|
331 |
AIAbstractListMap *list_items = &list->items; |
83d54622190c
(svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents:
9775
diff
changeset
|
332 |
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
|
333 |
this->AddItem((*iter).first); |
83d54622190c
(svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents:
9775
diff
changeset
|
334 |
this->SetValue((*iter).first, (*iter).second); |
83d54622190c
(svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
truebrain
parents:
9775
diff
changeset
|
335 |
} |
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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
338 |
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
|
339 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
340 |
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
|
341 |
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
|
342 |
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
|
343 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
345 |
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
|
346 |
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
|
347 |
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
|
348 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
351 |
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
|
352 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
353 |
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
|
354 |
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
|
355 |
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
|
356 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
358 |
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
|
359 |
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
|
360 |
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
|
361 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
364 |
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
|
365 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
366 |
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
|
367 |
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
|
368 |
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
|
369 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
371 |
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
|
372 |
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
|
373 |
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
|
374 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
377 |
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
|
378 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
379 |
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
|
380 |
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
|
381 |
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
|
382 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
384 |
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
|
385 |
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
|
386 |
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
|
387 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
390 |
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
|
391 |
{ |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
392 |
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
|
393 |
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
|
394 |
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
|
395 |
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
|
396 |
return; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
397 |
} |
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 |
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
|
400 |
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
|
401 |
case SORT_BY_VALUE: |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
402 |
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
|
403 |
AIItemList *items = &(*iter).second; |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
404 |
size_t size = items->size(); |
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
405 |
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
|
406 |
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
|
407 |
this->RemoveItem(*iter); |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
408 |
/* 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
|
409 |
* 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
|
410 |
*/ |
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
411 |
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
|
412 |
} |
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 |
break; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
415 |
|
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
416 |
case SORT_BY_ITEM: |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
417 |
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
|
418 |
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
|
419 |
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
|
420 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
421 |
break; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
422 |
} |
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 |
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
|
426 |
{ |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
427 |
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
|
428 |
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
|
429 |
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
|
430 |
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
|
431 |
return; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
432 |
} |
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 |
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
|
435 |
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
|
436 |
case SORT_BY_VALUE: |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
437 |
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
|
438 |
AIItemList *items = &(*iter).second; |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
439 |
size_t size = items->size(); |
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
440 |
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
|
441 |
if (--count < 0) return; |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
442 |
this->RemoveItem(*iter); |
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
443 |
/* 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
|
444 |
* 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
|
445 |
*/ |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
446 |
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
|
447 |
} |
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 |
case SORT_BY_ITEM: |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
451 |
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
|
452 |
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
|
453 |
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
|
454 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
455 |
break; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
456 |
} |
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 |
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
|
460 |
{ |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
461 |
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
|
462 |
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
|
463 |
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
|
464 |
} |
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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
467 |
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
|
468 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
469 |
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
|
470 |
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
|
471 |
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
|
472 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
474 |
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
|
475 |
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
|
476 |
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
|
477 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
480 |
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
|
481 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
482 |
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
|
483 |
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
|
484 |
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
|
485 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
487 |
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
|
488 |
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
|
489 |
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
|
490 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
493 |
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
|
494 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
495 |
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
|
496 |
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
|
497 |
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
|
498 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
500 |
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
|
501 |
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
|
502 |
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
|
503 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
506 |
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
|
507 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
508 |
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
|
509 |
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
|
510 |
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
|
511 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
513 |
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
|
514 |
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
|
515 |
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
|
516 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), 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 |
|
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
519 |
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
|
520 |
{ |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
521 |
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
|
522 |
} |
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 |
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
|
525 |
{ |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
526 |
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
|
527 |
} |
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 |
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
|
530 |
{ |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
531 |
AIAbstractList tmp; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
532 |
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
|
533 |
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
|
534 |
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
|
535 |
} |
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 |
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
|
538 |
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
|
539 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
540 |
|
9814
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
541 |
SQInteger AIAbstractList::Valuate(HSQUIRRELVM vm) { |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
542 |
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
|
543 |
|
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
544 |
/* 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
|
545 |
HSQOBJECT obj_list, obj_func; |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
546 |
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
|
547 |
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
|
548 |
|
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
549 |
/* Read the params */ |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
550 |
HSQOBJECT obj_params[10]; |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
551 |
assert(nparam < 10); |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
552 |
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
|
553 |
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
|
554 |
} |
9814
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
555 |
/* Remove all unneeded stuff */ |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
556 |
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
|
557 |
|
9814
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
558 |
/* 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
|
559 |
this->buckets.clear(); |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
560 |
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
|
561 |
/* The function to call */ |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
562 |
sq_pushobject(vm, obj_func); |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
563 |
/* 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
|
564 |
sq_pushobject(vm, obj_list); |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
565 |
|
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
566 |
/* Now send the params */ |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
567 |
sq_pushinteger(vm, (*iter).first); |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
568 |
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
|
569 |
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
|
570 |
} |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
571 |
|
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
572 |
/* Call the function */ |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
573 |
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
|
574 |
|
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
575 |
/* Retreive the return value */ |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
576 |
SQInteger value; |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
577 |
switch (sq_gettype(vm, -1)) { |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
578 |
case OT_INTEGER: { |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
579 |
sq_getinteger(vm, -1, &value); |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
580 |
} break; |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
581 |
|
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
582 |
case OT_BOOL: { |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
583 |
SQBool v; |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
584 |
sq_getbool(vm, -1, &v); |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
585 |
value = v ? 1 : 0; |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
586 |
} break; |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
587 |
|
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
588 |
default: { |
9819
fe876b1e5138
(svn r12422) [NoAI] -Fix (r12411): unicode compilation was broken
glx
parents:
9816
diff
changeset
|
589 |
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
|
590 |
return -1; |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
591 |
} |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
592 |
} |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
593 |
/* Remove junk */ |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
594 |
sq_pop(vm, 2); |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
595 |
|
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
|
596 |
(*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
|
597 |
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
|
598 |
} |
9814
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
599 |
|
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9802
diff
changeset
|
600 |
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
|
601 |
} |