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