Debian Codegraph @

src/common/tracktilebase.hpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2015 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D 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 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #ifndef TRACKTILEBASE_HPP
17 #define TRACKTILEBASE_HPP
18
19 #include <QPoint>
20 #include <QPointF>
21 #include <QString>
22
23 #include <memory>
24
25 /*! Base class for track tiles used in the editor and in the game.
26 *
27 * This is not the most beautiful solution to share tile code between
28 * the editor and the game because it requires us to downcast objects as
29 * both have some incompatible additions to the base class.
30 *
31 * However, we can avoid dynamic_cast<>'s because we "know" what the
32 * objects really are.
33 */
34 class TrackTileBase
35 {
36 public:
37 //! Hints for computer players.
38 enum class ComputerHint
39 {
40 None = 0,
41 BrakeHard,
42 Brake
43 };
44
45 /*! Constructor.
46 * \param location Location (coordinates) in the track scene.
47 * \param matrixLocation Location in the tile matrix.
48 * \param type Type of the tile. See setType(). */
49 TrackTileBase(QPointF location, QPoint matrixLocation, const QString & type = "clear");
50
51 TrackTileBase(TrackTileBase & other) = delete;
52
53 TrackTileBase & operator=(TrackTileBase & other) = delete;
54
55 //! Destructor.
56 virtual ~TrackTileBase();
57
58 //! Get location in world / scene.
59 virtual QPointF location() const;
60
61 virtual void setLocation(QPointF location);
62
63 //! Get location in the tile matrix.
64 virtual QPoint matrixLocation() const;
65
66 virtual void setMatrixLocation(QPoint matrixLocation);
67
68 //! Set type: "corner", "straight", "grass", "finish", "clear"..
69 virtual void setTileType(const QString & type);
70
71 //! Get type
72 const QString & tileType() const;
73
74 //! \return Tile width in pixels
75 static size_t width();
76
77 //! \return Tile height in pixels
78 static size_t height();
79
80 //! Set computer hint
81 virtual void setComputerHint(ComputerHint hint);
82
83 //! Get computer hint
84 ComputerHint computerHint() const;
85
86 /*! Don't show the tile in minimap / preview even if an asphalt tile.
87 * (Some tracks might include asphalt tiles just for looks) */
88 void setExcludeFromMinimap(bool exclude);
89
90 bool excludeFromMinimap() const;
91
92 private:
93 //! Type string.
94 QString m_tileType;
95
96 //! Location in the world / scene.
97 QPointF m_location;
98
99 //! Location in the tile matrix.
100 QPoint m_matrixLocation;
101
102 //! Computer hint
103 ComputerHint m_computerHint;
104
105 bool m_excludeFromMinimap;
106 };
107
108 using TrackTileBasePtr = std::shared_ptr<TrackTileBase>;
109
110 #endif // TRACKTILEBASE_HPP