(svn r12300) [NoAI] -Add: added AIAbstractList.AddList() (on request by Progman)
--- a/bin/ai/regression/regression.nut Wed Feb 27 23:15:46 2008 +0000
+++ b/bin/ai/regression/regression.nut Wed Feb 27 23:28:34 2008 +0000
@@ -475,6 +475,16 @@
for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
print(" " + i + " => " + list.GetValue(i));
}
+ list2.Clear();
+ for (local i = 4000; i < 4003; i++) {
+ list2.AddItem(i, i);
+ }
+ list2.AddItem(1005, 1005);
+ list.AddList(list2);
+ print(" AddList({1005, 4000, 4001, 4002}):");
+ for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
+ print(" " + i + " => " + list.GetValue(i));
+ }
list.Clear();
print(" IsEmpty(): " + list.IsEmpty());
--- a/bin/ai/regression/regression.txt Wed Feb 27 23:15:46 2008 +0000
+++ b/bin/ai/regression/regression.txt Wed Feb 27 23:28:34 2008 +0000
@@ -275,6 +275,11 @@
1005 => -429346856
KeepList({1003, 1004, 1005}):
1005 => -429346856
+ AddList({1005, 4000, 4001, 4002}):
+ 1005 => 1005
+ 4000 => 4000
+ 4001 => 4001
+ 4002 => 4002
IsEmpty(): true
--AIAirport--
--- a/src/ai/api/ai_abstractlist.cpp Wed Feb 27 23:15:46 2008 +0000
+++ b/src/ai/api/ai_abstractlist.cpp Wed Feb 27 23:28:34 2008 +0000
@@ -325,6 +325,15 @@
this->sort_ascending = ascending;
}
+void AIAbstractList::AddList(AIAbstractList *list)
+{
+ AIAbstractListMap *list_items = &list->items;
+ for (AIAbstractListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) {
+ this->AddItem((*iter).first);
+ this->SetValue((*iter).first, (*iter).second);
+ }
+}
+
void AIAbstractList::RemoveAboveValue(int32 value)
{
for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) {
--- a/src/ai/api/ai_abstractlist.hpp Wed Feb 27 23:15:46 2008 +0000
+++ b/src/ai/api/ai_abstractlist.hpp Wed Feb 27 23:28:34 2008 +0000
@@ -134,6 +134,16 @@
void Sort(SorterType sorter, bool ascending);
/**
+ * Add one list to an other one.
+ * @param list The list that will be added to the caller.
+ * @post The list to be added ('list') stays unmodified.
+ * @note All added items keep their value as it was in 'list'.
+ * @note If the item already exists inside the caller, the value of the
+ * list that is added is set on the item.
+ */
+ void AddList(AIAbstractList *list);
+
+ /**
* Removes all items with a higher value than 'value'.
* @param value the value above which all items are removed.
*/
--- a/src/ai/api/ai_abstractlist.hpp.sq Wed Feb 27 23:15:46 2008 +0000
+++ b/src/ai/api/ai_abstractlist.hpp.sq Wed Feb 27 23:28:34 2008 +0000
@@ -39,6 +39,7 @@
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::GetValue, "GetValue", 2, "xi");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::SetValue, "SetValue", 3, "xii");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::Sort, "Sort", 3, "xib");
+ SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::AddList, "AddList", 2, "xx");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::RemoveAboveValue, "RemoveAboveValue", 2, "xi");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::RemoveBelowValue, "RemoveBelowValue", 2, "xi");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::RemoveBetweenValue, "RemoveBetweenValue", 3, "xii");