ai_list.cpp

Go to the documentation of this file.
00001 /* $Id: ai_list.cpp 18809 2010-01-15 16:41:15Z rubidium $ */
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 "ai_list.hpp"
00013 
00014 void AIList::AddItem(int32 item, int32 value)
00015 {
00016   AIAbstractList::AddItem(item);
00017   this->SetValue(item, value);
00018 }
00019 
00020 void AIList::ChangeItem(int32 item, int32 value)
00021 {
00022   this->SetValue(item, value);
00023 }
00024 
00025 void AIList::RemoveItem(int32 item)
00026 {
00027   AIAbstractList::RemoveItem(item);
00028 }
00029 
00030 SQInteger AIList::_set(HSQUIRRELVM vm)
00031 {
00032   if (sq_gettype(vm, 2) != OT_INTEGER) return SQ_ERROR;
00033   if (sq_gettype(vm, 3) != OT_INTEGER || sq_gettype(vm, 3) == OT_NULL) {
00034     return sq_throwerror(vm, _SC("you can only assign integers to this list"));
00035   }
00036 
00037   SQInteger idx, val;
00038   sq_getinteger(vm, 2, &idx);
00039   if (sq_gettype(vm, 3) == OT_NULL) {
00040     this->RemoveItem(idx);
00041     return 0;
00042   }
00043 
00044   sq_getinteger(vm, 3, &val);
00045   if (!this->HasItem(idx)) {
00046     this->AddItem(idx, val);
00047     return 0;
00048   }
00049 
00050   this->ChangeItem(idx, val);
00051   return 0;
00052 }

Generated on Sat Jun 19 17:14:46 2010 for OpenTTD by  doxygen 1.6.1