Unified Messaging Subsystem
[supertux.git] / src / spawn_point.cpp
1 #include <config.h>
2
3 #include <stdexcept>
4 #include <iostream>
5 #include "spawn_point.hpp"
6 #include "lisp/lisp.hpp"
7 #include "lisp/list_iterator.hpp"
8 #include "msg.hpp"
9
10 SpawnPoint::SpawnPoint()
11 {}
12
13 SpawnPoint::SpawnPoint(const SpawnPoint& other)
14     : name(other.name), pos(other.pos)
15 {}
16
17 SpawnPoint::SpawnPoint(const lisp::Lisp* slisp)
18 {
19     pos.x = -1;
20     pos.y = -1;
21     lisp::ListIterator iter(slisp);
22     while(iter.next()) {
23         const std::string& token = iter.item();
24         if(token == "name") {
25             iter.value()->get(name);
26         } else if(token == "x") {
27             iter.value()->get(pos.x);
28         } else if(token == "y") {
29             iter.value()->get(pos.y);
30         } else {
31             msg_warning("unknown token '" << token 
32                       << "' in SpawnPoint");
33         }
34     }
35
36     if(name == "")
37         throw std::runtime_error("No name specified for spawnpoint");
38     if(pos.x < 0 || pos.y < 0)
39         throw std::runtime_error("Invalid coordinates for spawnpoint");
40 }