ff17c4e4fe6ab65dea12954dc14aa781f6ec0b0f
[supertux.git] / src / object / path.hpp
1 //  $Id$
2 //
3 //  SuperTux Path
4 //  Copyright (C) 2005 Philipp <balinor@pnxs.de>
5 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
6 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; either version 2
11 //  of the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 //
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 //  02111-1307, USA.
22 #ifndef __PATH_HPP__
23 #define __PATH_HPP__
24
25 #include <vector>
26 #include "math/vector.hpp"
27 #include "lisp/lisp.hpp"
28 #include "serializable.hpp"
29
30 class Path : public Serializable
31 {
32 public:
33   Path();
34   ~Path();
35
36   void read(const lisp::Lisp& reader);
37   void write(lisp::Writer& writer);
38
39   Vector get_base() const;
40
41   /**
42    * Helper class that stores an individual node of a Path
43    */
44   class Node
45   {
46   public:
47     Vector position; /**< the position of this node */
48     float time; /**< time (in seconds) to get from this node to next node */
49   };
50
51   std::vector<Node> nodes;
52
53   /**
54    * returns Node index nearest to reference_point or -1 if not applicable
55    */
56   int get_nearest_node_no(Vector reference_point) const;
57
58   /**
59    * returns Node index farthest from reference_point or -1 if not applicable
60    */
61   int get_farthest_node_no(Vector reference_point) const;
62
63 private:
64   friend class PathWalker;
65
66   enum WalkMode {
67     // moves from first to last path node and stops
68     ONE_SHOT,
69     // moves from first to last node then in reverse order back to first
70     PING_PONG,
71     // moves from last node back to the first node
72     CIRCULAR
73   };
74
75   WalkMode mode;
76 };
77
78 #endif