diff options
author | yexo <yexo@openttd.org> | 2010-08-19 15:19:40 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2010-08-19 15:19:40 +0000 |
commit | 6c7384cabd9ffe684697f98a65a32871500284f8 (patch) | |
tree | 5fc1db4722624c680022fa6d0b5647dcb136b98a /src/ai/api/ai_abstractlist.cpp | |
parent | 1fe3ce9993fbb54dcb87eb1e6487cd2a2d049bbf (diff) | |
download | openttd-6c7384cabd9ffe684697f98a65a32871500284f8.tar.xz |
(svn r20562) -Change: [NoAI] Move all functions from AIList to AIAbstractList
Diffstat (limited to 'src/ai/api/ai_abstractlist.cpp')
-rw-r--r-- | src/ai/api/ai_abstractlist.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/ai/api/ai_abstractlist.cpp b/src/ai/api/ai_abstractlist.cpp index e51713465..a9e111153 100644 --- a/src/ai/api/ai_abstractlist.cpp +++ b/src/ai/api/ai_abstractlist.cpp @@ -404,7 +404,7 @@ void AIAbstractList::Clear() this->sorter->End(); } -void AIAbstractList::AddItem(int32 item) +void AIAbstractList::AddItem(int32 item, int32 value) { this->modifications++; @@ -412,6 +412,8 @@ void AIAbstractList::AddItem(int32 item) this->items[item] = 0; this->buckets[0].insert(item); + + this->SetValue(item, value); } void AIAbstractList::RemoveItem(int32 item) @@ -734,6 +736,30 @@ SQInteger AIAbstractList::_get(HSQUIRRELVM vm) return 1; } +SQInteger AIAbstractList::_set(HSQUIRRELVM vm) +{ + if (sq_gettype(vm, 2) != OT_INTEGER) return SQ_ERROR; + if (sq_gettype(vm, 3) != OT_INTEGER || sq_gettype(vm, 3) == OT_NULL) { + return sq_throwerror(vm, _SC("you can only assign integers to this list")); + } + + SQInteger idx, val; + sq_getinteger(vm, 2, &idx); + if (sq_gettype(vm, 3) == OT_NULL) { + this->RemoveItem(idx); + return 0; + } + + sq_getinteger(vm, 3, &val); + if (!this->HasItem(idx)) { + this->AddItem(idx, val); + return 0; + } + + this->SetValue(idx, val); + return 0; +} + SQInteger AIAbstractList::_nexti(HSQUIRRELVM vm) { if (sq_gettype(vm, 2) == OT_NULL) { |