ai_list.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include <squirrel.h>
00013 #include "ai_list.hpp"
00014
00015 void AIList::AddItem(int32 item, int32 value)
00016 {
00017 AIAbstractList::AddItem(item);
00018 this->SetValue(item, value);
00019 }
00020
00021 void AIList::ChangeItem(int32 item, int32 value)
00022 {
00023 this->SetValue(item, value);
00024 }
00025
00026 void AIList::RemoveItem(int32 item)
00027 {
00028 AIAbstractList::RemoveItem(item);
00029 }
00030
00031 SQInteger AIList::_set(HSQUIRRELVM vm)
00032 {
00033 if (sq_gettype(vm, 2) != OT_INTEGER) return SQ_ERROR;
00034 if (sq_gettype(vm, 3) != OT_INTEGER || sq_gettype(vm, 3) == OT_NULL) {
00035 return sq_throwerror(vm, _SC("you can only assign integers to this list"));
00036 }
00037
00038 SQInteger idx, val;
00039 sq_getinteger(vm, 2, &idx);
00040 if (sq_gettype(vm, 3) == OT_NULL) {
00041 this->RemoveItem(idx);
00042 return 0;
00043 }
00044
00045 sq_getinteger(vm, 3, &val);
00046 if (!this->HasItem(idx)) {
00047 this->AddItem(idx, val);
00048 return 0;
00049 }
00050
00051 this->ChangeItem(idx, val);
00052 return 0;
00053 }