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
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.
30 /// There are three types of them:
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.
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.
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
{
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
);
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;
81 static PropertyDescription
const descriptor
[];
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;