20130313
[gdash.git] / src / cave / object / caveobjectmaze.hpp
blobee04b37637ac777835c1f3abcb7a46d97464d71f
1 /*
2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 #ifndef _GD_CAVEOBJECTMAZE
17 #define _GD_CAVEOBJECTMAZE
19 #include "config.h"
21 #include "cave/object/caveobject.hpp"
22 #include "cave/object/caveobjectrectangular.hpp"
24 /* forward declarations for maze object */
25 class RandomGenerator;
26 template <class T> class CaveMap;
28 /// Cave maze objects.
29 ///
30 /// There are three types of them:
31 /// - perfect maze
32 /// - braid maze (with no dead ends)
33 /// - unicursal maze (which is a one long closed path).
34 /// This is stored in the maze_type member, but also the object type
35 /// is different for all three maze types.
36 ///
37 /// Mazes have path and wall elements; and have path and wall widths.
38 /// They have random number seed values for all levels, so it is possible
39 /// to generate a different maze for all levels. If the seed
40 /// value is set to -1, a different maze is generated every time a cave is rendered.
41 /// The horizontal parameter is a value between 0 and 100; it determines how
42 /// much the maze generator algorithm prefers long horizontal paths. Default is 50.
43 ///
44 /// If the size of the maze object is larger than the "common multiple" determined
45 /// by the wall and path width, the remaining part is filled with wall.
46 /// No border for the maze is drawn - if the user wants a border, he can use
47 /// a rectangle object.
48 class CaveMaze : public CaveRectangular {
49 public:
50 enum MazeType {
51 Perfect,
52 Braid,
53 Unicursal
56 private:
57 MazeType const maze_type; ///< Type of the maze, perfect, braid, unicursal.
58 GdInt wall_width; ///< Width of the walls in the maze (in cells); >=1
59 GdInt path_width; ///< Width of the paths in the maze; >=1
60 GdElement wall_element; ///< Walls are made of this element
61 GdElement path_element; ///< Paths are made of this.
62 GdInt horiz; ///< 0..100, with greater numbers, horizontal paths are preferred
63 GdIntLevels seed; ///< Seed values for difficulty levels.
65 static void mazegen(CaveMap<bool> &maze, RandomGenerator &rand, int x, int y, int horiz);
66 static void braidmaze(CaveMap<bool> &maze, RandomGenerator &rand);
67 static void unicursalmaze(CaveMap<bool> &maze, int &w, int &h);
69 public:
70 CaveMaze(Coordinate _p1, Coordinate _p2, GdElementEnum _wall, GdElementEnum _path, MazeType _type);
71 CaveMaze(): CaveRectangular(GD_MAZE), maze_type(Perfect) {}
72 virtual CaveMaze *clone() const { return new CaveMaze(*this); };
73 virtual void draw(CaveRendered &cave) const;
74 void set_horiz(int _horiz) { horiz=_horiz; }
75 void set_widths(int wall, int path);
76 void set_seed(int s1, int s2, int s3, int s4, int s5);
77 virtual std::string get_bdcff() const;
78 virtual CaveMaze* clone_from_bdcff(const std::string &name, std::istream &is) const;
80 private:
81 static PropertyDescription const descriptor[];
83 public:
84 virtual PropertyDescription const* get_description_array() const;
86 virtual GdElementEnum get_characteristic_element() const { return path_element; }
87 virtual std::string get_description_markup() const;
91 #endif