1 /*
2  *  This file is part of Dune Legacy.
3  *
4  *  Dune Legacy 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 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  Dune Legacy is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with Dune Legacy.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MAPMIRROR_H
19 #define MAPMIRROR_H
20 
21 #include <DataTypes.h>
22 
23 typedef enum {
24     MirrorModeNone,
25     MirrorModeHorizontal,
26     MirrorModeVertical,
27     MirrorModeBoth,
28     MirrorModePoint
29 } MirrorMode;
30 
31 class MapMirror {
32 public:
33     MapMirror(int mapsizeX, int mapsizeY);
34 
35     virtual ~MapMirror();
36 
37     virtual int getSize() const = 0;
38 
39     virtual bool mirroringPossible(Coord coord, Coord objectSize = Coord(1,1)) const = 0;
40 
41     virtual Coord getCoord(Coord originalCoord, int i, Coord objectSize = Coord(1,1)) const = 0;
42 
43     virtual int getAngle(int angle, int i) const = 0;
44 
45     static MapMirror* createMapMirror(MirrorMode mirrorMode, int mapsizeX, int mapsizeY);
46 
47 protected:
48     int mapsizeX;
49     int mapsizeY;
50 };
51 
52 
53 
54 class MapMirrorNone : public MapMirror {
55 public:
56     MapMirrorNone(int mapsizeX, int mapsizeY);
57 
getSize()58     virtual int getSize() const { return 1; };
59 
60     virtual bool mirroringPossible(Coord coord, Coord objectSize = Coord(1,1)) const {
61         return true;
62     }
63 
64     virtual Coord getCoord(Coord originalCoord, int i, Coord objectSize = Coord(1,1)) const;
65 
66     virtual int getAngle(int angle, int i) const;
67 };
68 
69 
70 
71 class MapMirrorHorizontal : public MapMirror {
72 public:
73     MapMirrorHorizontal(int mapsizeX, int mapsizeY);
74 
getSize()75     virtual int getSize() const { return 2; };
76 
77     virtual bool mirroringPossible(Coord coord, Coord objectSize = Coord(1,1)) const {
78         return !(coord.x < mapsizeX/2 && coord.x + objectSize.x - 1 >= mapsizeX/2);
79     }
80 
81     virtual Coord getCoord(Coord originalCoord, int i, Coord objectSize = Coord(1,1)) const;
82 
83     virtual int getAngle(int angle, int i) const;
84 };
85 
86 
87 
88 class MapMirrorVertical : public MapMirror {
89 public:
90     MapMirrorVertical(int mapsizeX, int mapsizeY);
91 
getSize()92     virtual int getSize() const { return 2; };
93 
94     virtual bool mirroringPossible(Coord coord, Coord objectSize = Coord(1,1)) const {
95         return !(coord.y < mapsizeY/2 && coord.y + objectSize.y - 1 >= mapsizeY/2);
96     }
97 
98     virtual Coord getCoord(Coord originalCoord, int i, Coord objectSize = Coord(1,1)) const;
99 
100     virtual int getAngle(int angle, int i) const;
101 };
102 
103 
104 
105 class MapMirrorBoth : public MapMirror {
106 public:
107     MapMirrorBoth(int mapsizeX, int mapsizeY);
108 
getSize()109     virtual int getSize() const { return 4; };
110 
111     virtual bool mirroringPossible(Coord coord, Coord objectSize = Coord(1,1)) const {
112         return !((coord.x < mapsizeX/2 && coord.x + objectSize.x - 1 >= mapsizeX/2) || (coord.y < mapsizeY/2 && coord.y + objectSize.y - 1 >= mapsizeY/2));
113     }
114 
115     virtual Coord getCoord(Coord originalCoord, int i, Coord objectSize = Coord(1,1)) const;
116 
117     virtual int getAngle(int angle, int i) const;
118 };
119 
120 
121 
122 class MapMirrorPoint : public MapMirror {
123 public:
124     MapMirrorPoint(int mapsizeX, int mapsizeY);
125 
getSize()126     virtual int getSize() const { return 2; };
127 
128     virtual bool mirroringPossible(Coord coord, Coord objectSize = Coord(1,1)) const {
129         return !((coord.x < mapsizeX/2 && coord.x + objectSize.x - 1 >= mapsizeX/2) && (coord.y < mapsizeY/2 && coord.y + objectSize.y - 1 >= mapsizeY/2));
130     }
131 
132     virtual Coord getCoord(Coord originalCoord, int i, Coord objectSize = Coord(1,1)) const;
133 
134     virtual int getAngle(int angle, int i) const;
135 };
136 
137 
138 #endif // MAPMIRROR_H
139