ai_list.cpp

Go to the documentation of this file.
00001 /* $Id: ai_list.cpp 17692 2009-10-04 17:10:57Z smatz $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
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 }

Generated on Tue Jan 5 21:02:52 2010 for OpenTTD by  doxygen 1.5.6