src/worldmap/spawn_point.cpp

Go to the documentation of this file.
00001 //  SuperTux - Worldmap Spawnpoint
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 "util/log.hpp"
00021 #include "util/reader.hpp"
00022 #include "worldmap/spawn_point.hpp"
00023 
00024 namespace worldmap {
00025 
00026 SpawnPoint::SpawnPoint(const Reader& slisp) : 
00027   name(),
00028   pos(),
00029   auto_dir(D_NONE)
00030 {
00031   pos.x = -1;
00032   pos.y = -1;
00033   lisp::ListIterator iter(&slisp);
00034   while(iter.next()) {
00035     const std::string& token = iter.item();
00036     if(token == "name") {
00037       iter.value()->get(name);
00038     } else if(token == "x") {
00039       iter.value()->get(pos.x);
00040     } else if(token == "y") {
00041       iter.value()->get(pos.y);
00042     } else if(token == "auto-dir") {
00043       std::string s = "";
00044       iter.value()->get(s);
00045       auto_dir = string_to_direction(s);
00046     } else {
00047       log_warning << "unknown token '" << token << "' in SpawnPoint" << std::endl;
00048     }
00049   }
00050 
00051   if(name == "")
00052     throw std::runtime_error("No name specified for spawnpoint");
00053   if(pos.x < 0 || pos.y < 0)
00054     throw std::runtime_error("Invalid coordinates for spawnpoint");
00055 }
00056 
00057 }
00058 
00059 /* EOF */

Generated on Mon Jun 9 03:38:23 2014 for SuperTux by  doxygen 1.5.1