--- a/bin/ai/regression/regression.nut Sun Jul 15 11:28:52 2007 +0000
+++ b/bin/ai/regression/regression.nut Sun Jul 15 11:45:25 2007 +0000
@@ -203,13 +203,14 @@
print("--List--");
print(" IsEmpty(): " + list.IsEmpty());
- list.AddItem(1);
- list.AddItem(2);
+ list.AddItem(1, 1);
+ list.AddItem(2, 2);
for (local i = 1000; i < 1100; i++) {
- list.AddItem(i);
+ list.AddItem(i, i);
}
list.RemoveItem(1050);
list.RemoveItem(1150);
+ list.ChangeItem(1051, 12);
print(" Count(): " + list.Count());
print(" HasItem(1050): " + list.HasItem(1050));
print(" HasItem(1051): " + list.HasItem(1051));
--- a/bin/ai/regression/regression.txt Sun Jul 15 11:28:52 2007 +0000
+++ b/bin/ai/regression/regression.txt Sun Jul 15 11:45:25 2007 +0000
@@ -765,107 +765,107 @@
HasItem(1051): true
IsEmpty(): false
List Dump:
- 1 => 0
- 2 => 0
- 1000 => 0
- 1001 => 0
- 1002 => 0
- 1003 => 0
- 1004 => 0
- 1005 => 0
- 1006 => 0
- 1007 => 0
- 1008 => 0
- 1009 => 0
- 1010 => 0
- 1011 => 0
- 1012 => 0
- 1013 => 0
- 1014 => 0
- 1015 => 0
- 1016 => 0
- 1017 => 0
- 1018 => 0
- 1019 => 0
- 1020 => 0
- 1021 => 0
- 1022 => 0
- 1023 => 0
- 1024 => 0
- 1025 => 0
- 1026 => 0
- 1027 => 0
- 1028 => 0
- 1029 => 0
- 1030 => 0
- 1031 => 0
- 1032 => 0
- 1033 => 0
- 1034 => 0
- 1035 => 0
- 1036 => 0
- 1037 => 0
- 1038 => 0
- 1039 => 0
- 1040 => 0
- 1041 => 0
- 1042 => 0
- 1043 => 0
- 1044 => 0
- 1045 => 0
- 1046 => 0
- 1047 => 0
- 1048 => 0
- 1049 => 0
- 1051 => 0
- 1052 => 0
- 1053 => 0
- 1054 => 0
- 1055 => 0
- 1056 => 0
- 1057 => 0
- 1058 => 0
- 1059 => 0
- 1060 => 0
- 1061 => 0
- 1062 => 0
- 1063 => 0
- 1064 => 0
- 1065 => 0
- 1066 => 0
- 1067 => 0
- 1068 => 0
- 1069 => 0
- 1070 => 0
- 1071 => 0
- 1072 => 0
- 1073 => 0
- 1074 => 0
- 1075 => 0
- 1076 => 0
- 1077 => 0
- 1078 => 0
- 1079 => 0
- 1080 => 0
- 1081 => 0
- 1082 => 0
- 1083 => 0
- 1084 => 0
- 1085 => 0
- 1086 => 0
- 1087 => 0
- 1088 => 0
- 1089 => 0
- 1090 => 0
- 1091 => 0
- 1092 => 0
- 1093 => 0
- 1094 => 0
- 1095 => 0
- 1096 => 0
- 1097 => 0
- 1098 => 0
- 1099 => 0
+ 1 => 1
+ 2 => 2
+ 1000 => 1000
+ 1001 => 1001
+ 1002 => 1002
+ 1003 => 1003
+ 1004 => 1004
+ 1005 => 1005
+ 1006 => 1006
+ 1007 => 1007
+ 1008 => 1008
+ 1009 => 1009
+ 1010 => 1010
+ 1011 => 1011
+ 1012 => 1012
+ 1013 => 1013
+ 1014 => 1014
+ 1015 => 1015
+ 1016 => 1016
+ 1017 => 1017
+ 1018 => 1018
+ 1019 => 1019
+ 1020 => 1020
+ 1021 => 1021
+ 1022 => 1022
+ 1023 => 1023
+ 1024 => 1024
+ 1025 => 1025
+ 1026 => 1026
+ 1027 => 1027
+ 1028 => 1028
+ 1029 => 1029
+ 1030 => 1030
+ 1031 => 1031
+ 1032 => 1032
+ 1033 => 1033
+ 1034 => 1034
+ 1035 => 1035
+ 1036 => 1036
+ 1037 => 1037
+ 1038 => 1038
+ 1039 => 1039
+ 1040 => 1040
+ 1041 => 1041
+ 1042 => 1042
+ 1043 => 1043
+ 1044 => 1044
+ 1045 => 1045
+ 1046 => 1046
+ 1047 => 1047
+ 1048 => 1048
+ 1049 => 1049
+ 1051 => 12
+ 1052 => 1052
+ 1053 => 1053
+ 1054 => 1054
+ 1055 => 1055
+ 1056 => 1056
+ 1057 => 1057
+ 1058 => 1058
+ 1059 => 1059
+ 1060 => 1060
+ 1061 => 1061
+ 1062 => 1062
+ 1063 => 1063
+ 1064 => 1064
+ 1065 => 1065
+ 1066 => 1066
+ 1067 => 1067
+ 1068 => 1068
+ 1069 => 1069
+ 1070 => 1070
+ 1071 => 1071
+ 1072 => 1072
+ 1073 => 1073
+ 1074 => 1074
+ 1075 => 1075
+ 1076 => 1076
+ 1077 => 1077
+ 1078 => 1078
+ 1079 => 1079
+ 1080 => 1080
+ 1081 => 1081
+ 1082 => 1082
+ 1083 => 1083
+ 1084 => 1084
+ 1085 => 1085
+ 1086 => 1086
+ 1087 => 1087
+ 1088 => 1088
+ 1089 => 1089
+ 1090 => 1090
+ 1091 => 1091
+ 1092 => 1092
+ 1093 => 1093
+ 1094 => 1094
+ 1095 => 1095
+ 1096 => 1096
+ 1097 => 1097
+ 1098 => 1098
+ 1099 => 1099
Randomize ListDump:
1 => -2039536299
2 => 796838333
--- a/src/ai/api/ai_abstractlist.cpp Sun Jul 15 11:28:52 2007 +0000
+++ b/src/ai/api/ai_abstractlist.cpp Sun Jul 15 11:45:25 2007 +0000
@@ -238,6 +238,7 @@
if (!this->HasItem(item)) return;
this->buckets[this->GetValue(item)].erase(item);
+ if (this->buckets[this->GetValue(item)].empty()) this->buckets.erase(this->GetValue(item));
this->items.erase(item);
}
@@ -273,6 +274,18 @@
return this->items[item];
}
+bool AIAbstractList::SetValue(int32 item, int32 value)
+{
+ if (!this->HasItem(item)) return false;
+
+ this->buckets[this->GetValue(item)].erase(item);
+ if (this->buckets[this->GetValue(item)].empty()) this->buckets.erase(this->GetValue(item));
+ this->items[item] = value;
+ this->buckets[value].insert(item);
+
+ return true;
+}
+
void AIAbstractList::SortByItem(bool ascending)
{
delete this->sorter;
--- a/src/ai/api/ai_abstractlist.hpp Sun Jul 15 11:28:52 2007 +0000
+++ b/src/ai/api/ai_abstractlist.hpp Sun Jul 15 11:45:25 2007 +0000
@@ -108,6 +108,14 @@
int32 GetValue(int32 item);
/**
+ * Set a value of an item directly.
+ * @param item the item to set the value for.
+ * @param value the value to give to the item
+ * @return true if we could set the item to value, false otherwise.
+ */
+ bool SetValue(int32 item, int32 value);
+
+ /**
* Sort this list by item-value.
* @param ascending if true, lowest value is on top, else at bottom.
* @note the current item stays at the same place.
--- a/src/ai/api/ai_abstractlist.hpp.sq Sun Jul 15 11:28:52 2007 +0000
+++ b/src/ai/api/ai_abstractlist.hpp.sq Sun Jul 15 11:45:25 2007 +0000
@@ -29,6 +29,7 @@
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::HasNext, "HasNext", 1, "x");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::Count, "Count", 1, "x");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::GetValue, "GetValue", 2, "xi");
+ SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::SetValue, "SetValue", 3, "xii");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::SortByItem, "SortByItem", 2, "xb");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::SortByValue, "SortByValue", 2, "xb");
SQAIAbstractList.DefSQMethod(engine, &AIAbstractList::RemoveAboveValue, "RemoveAboveValue", 2, "xi");
--- a/src/ai/api/ai_list.cpp Sun Jul 15 11:28:52 2007 +0000
+++ b/src/ai/api/ai_list.cpp Sun Jul 15 11:45:25 2007 +0000
@@ -1,8 +1,14 @@
#include "ai_list.hpp"
-void AIList::AddItem(int32 item)
+void AIList::AddItem(int32 item, int32 value)
{
AIAbstractList::AddItem(item);
+ this->SetValue(item, value);
+}
+
+void AIList::ChangeItem(int32 item, int32 value)
+{
+ this->SetValue(item, value);
}
void AIList::RemoveItem(int32 item)
--- a/src/ai/api/ai_list.hpp Sun Jul 15 11:28:52 2007 +0000
+++ b/src/ai/api/ai_list.hpp Sun Jul 15 11:45:25 2007 +0000
@@ -21,8 +21,16 @@
/**
* Add an item to the list.
* @param item the item to add.
+ * @param value the value to assign.
*/
- void AddItem(int32 item);
+ void AddItem(int32 item, int32 value);
+
+ /**
+ * Change the value of an item in the list.
+ * @param item the item to change
+ * @param value the value to assign.
+ */
+ void ChangeItem(int32 item, int32 value);
/**
* Remove the item from the list.
--- a/src/ai/api/ai_list.hpp.sq Sun Jul 15 11:28:52 2007 +0000
+++ b/src/ai/api/ai_list.hpp.sq Sun Jul 15 11:45:25 2007 +0000
@@ -15,7 +15,8 @@
SQAIList.DefSQStaticMethod(engine, &AIList::GetClassName, "GetClassName", 1, "x");
- SQAIList.DefSQMethod(engine, &AIList::AddItem, "AddItem", 2, "xi");
+ SQAIList.DefSQMethod(engine, &AIList::AddItem, "AddItem", 3, "xii");
+ SQAIList.DefSQMethod(engine, &AIList::ChangeItem, "ChangeItem", 3, "xii");
SQAIList.DefSQMethod(engine, &AIList::RemoveItem, "RemoveItem", 2, "xi");
SQAIList.PostRegister(engine);