1// SuperTux Path
2// Copyright (C) 2005 Philipp <balinor@pnxs.de>
3// Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
4// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5//
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19#ifndef HEADER_SUPERTUX_OBJECT_PATH_HPP
20#define HEADER_SUPERTUX_OBJECT_PATH_HPP
21
22#include <memory>
23#include <string>
24#include <vector>
25
26#include "math/vector.hpp"
27
28class ObjectOption;
29class ReaderMapping;
30class Writer;
31
32enum class WalkMode {
33 // moves from first to last path node and stops
34 ONE_SHOT,
35 // moves from first to last node then in reverse order back to first
36 PING_PONG,
37 // moves from last node back to the first node
38 CIRCULAR
39};
40
41WalkMode string_to_walk_mode(const std::string& mode_string);
42std::string walk_mode_to_string(WalkMode walk_mode);
43
44class Path final
45{
46public:
47 /** Helper class that stores an individual node of a Path */
48 class Node
49 {
50 public:
51 Vector position; /**< the position of this node */
52 float time; /**< time (in seconds) to get from this node to next node */
53
54 Node() :
55 position(),
56 time()
57 {}
58 };
59
60public:
61 Path();
62 Path(const Vector& pos);
63
64 void read(const ReaderMapping& reader);
65 void save(Writer& writer);
66
67 Vector get_base() const;
68
69 /** returns Node index nearest to reference_point or -1 if not applicable */
70 int get_nearest_node_no(const Vector& reference_point) const;
71
72 /** returns Node index farthest from reference_point or -1 if not applicable */
73 int get_farthest_node_no(const Vector& reference_point) const;
74
75 /** Moves all nodes by given shift. */
76 void move_by(const Vector& shift);
77
78 /** Puts node markers to the nodes to edit them. */
79 void edit_path();
80
81 /** Returns false when has no nodes */
82 bool is_valid() const;
83
84 const std::vector<Node>& get_nodes() const { return m_nodes; }
85
86public:
87 std::vector<Node> m_nodes;
88
89 WalkMode m_mode;
90
91private:
92 Path(const Path&) = delete;
93 Path& operator=(const Path&) = delete;
94};
95
96#endif
97
98/* EOF */
99