ai_list.cpp

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

Generated on Tue Dec 1 00:06:14 2009 for OpenTTD by  doxygen 1.5.6