| 1 | // SuperTux - Worldmap Spawnpoint |
| 2 | // Copyright (C) 2006 Matthias Braun <matze@braunis.de> |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
| 17 | #include "worldmap/spawn_point.hpp" |
| 18 | |
| 19 | #include <stdexcept> |
| 20 | |
| 21 | #include "util/reader_mapping.hpp" |
| 22 | |
| 23 | namespace worldmap { |
| 24 | |
| 25 | SpawnPoint::SpawnPoint(const ReaderMapping& mapping) : |
| 26 | m_name(), |
| 27 | m_pos(), |
| 28 | m_auto_dir(Direction::NONE) |
| 29 | { |
| 30 | m_pos.x = -1; |
| 31 | m_pos.y = -1; |
| 32 | |
| 33 | mapping.get("name" , m_name); |
| 34 | mapping.get("x" , m_pos.x); |
| 35 | mapping.get("y" , m_pos.y); |
| 36 | |
| 37 | std::string auto_dir_str; |
| 38 | if (mapping.get("auto-dir" , auto_dir_str)) { |
| 39 | m_auto_dir = string_to_direction(auto_dir_str); |
| 40 | } |
| 41 | |
| 42 | if (m_name.empty()) |
| 43 | throw std::runtime_error("No name specified for spawnpoint" ); |
| 44 | |
| 45 | if (m_pos.x < 0 || m_pos.y < 0) |
| 46 | throw std::runtime_error("Invalid coordinates for spawnpoint" ); |
| 47 | } |
| 48 | |
| 49 | } // namespace worldmap |
| 50 | |
| 51 | /* EOF */ |
| 52 | |