00001 // SuperTux 00002 // Copyright (C) 2006 Matthias Braun <matze@braunis.de> 00003 // 00004 // This program is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 00017 #include <stdexcept> 00018 00019 #include "lisp/list_iterator.hpp" 00020 #include "supertux/spawn_point.hpp" 00021 #include "util/log.hpp" 00022 00023 SpawnPoint::SpawnPoint() : 00024 name(), 00025 pos() 00026 {} 00027 00028 SpawnPoint::SpawnPoint(const SpawnPoint& other) : 00029 name(other.name), 00030 pos(other.pos) 00031 {} 00032 00033 SpawnPoint::SpawnPoint(const Reader& slisp) : 00034 name(), 00035 pos() 00036 { 00037 pos.x = -1; 00038 pos.y = -1; 00039 lisp::ListIterator iter(&slisp); 00040 while(iter.next()) { 00041 const std::string& token = iter.item(); 00042 if(token == "name") { 00043 iter.value()->get(name); 00044 } else if(token == "x") { 00045 iter.value()->get(pos.x); 00046 } else if(token == "y") { 00047 iter.value()->get(pos.y); 00048 } else { 00049 log_warning << "unknown token '" << token << "' in SpawnPoint" << std::endl; 00050 } 00051 } 00052 00053 if(name == "") 00054 throw std::runtime_error("No name specified for spawnpoint"); 00055 if(pos.x < 0 || pos.y < 0) 00056 throw std::runtime_error("Invalid coordinates for spawnpoint"); 00057 } 00058 00059 /* EOF */