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.
20 #include "cave/object/caveobject.hpp"
21 #include "cave/helper/namevaluepair.hpp"
24 #include "misc/smartptr.hpp"
25 #include "cave/object/caveobjectboundaryfill.hpp"
26 #include "cave/object/caveobjectcopypaste.hpp"
27 #include "cave/object/caveobjectfillrect.hpp"
28 #include "cave/object/caveobjectfloodfill.hpp"
29 #include "cave/object/caveobjectjoin.hpp"
30 #include "cave/object/caveobjectline.hpp"
31 #include "cave/object/caveobjectmaze.hpp"
32 #include "cave/object/caveobjectpoint.hpp"
33 #include "cave/object/caveobjectrandomfill.hpp"
34 #include "cave/object/caveobjectraster.hpp"
35 #include "cave/object/caveobjectrectangle.hpp"
38 /// Check if the object is visible on all levels.
39 /// @return True, if visible.
40 bool CaveObject::is_seen_on_all() const {
41 for (unsigned i
=0; i
<5; ++i
)
43 return false; // if invisible on any, not seen on all.
47 /// Check if the object is invisible - not visible on any level.
48 /// @return True, if fully invisible.
49 bool CaveObject::is_invisible() const {
50 for (unsigned i
=0; i
<5; i
++)
52 return false; // if seen on any, not invisible.
56 /// Enable object on all levels.
57 void CaveObject::enable_on_all() {
58 for (unsigned i
=0; i
<5; ++i
)
62 /// Disable object on all levels.
63 void CaveObject::disable_on_all() {
64 for (unsigned i
=0; i
<5; ++i
)
68 static NameValuePair
<SmartPtr
<CaveObject
> > object_prototypes
;
70 void gd_cave_objects_init() {
71 object_prototypes
.add("Point", new CavePoint
);
72 object_prototypes
.add("Line", new CaveLine
);
73 object_prototypes
.add("Rectangle", new CaveRectangle
);
74 object_prototypes
.add("FillRect", new CaveFillRect
);
75 object_prototypes
.add("Raster", new CaveRaster
);
76 object_prototypes
.add("Join", new CaveJoin
);
77 object_prototypes
.add("Add", new CaveJoin
);
78 object_prototypes
.add("AddBackward", new CaveJoin
);
79 object_prototypes
.add("BoundaryFill", new CaveBoundaryFill
);
80 object_prototypes
.add("FloodFill", new CaveFloodFill
);
81 object_prototypes
.add("Maze", new CaveMaze
);
82 object_prototypes
.add("CopyPaste", new CaveCopyPaste
);
83 object_prototypes
.add("RandomFill", new CaveRandomFill
);
84 object_prototypes
.add("RandomFillC64", new CaveRandomFill
);
88 CaveObject
*CaveObject::create_from_bdcff(const std::string
&str
) {
89 std::string::size_type f
=str
.find('=');
90 if (f
==std::string::npos
)
92 std::string type
=str
.substr(0, f
);
93 if (!object_prototypes
.has_name(type
))
94 return NULL
; // if no such object, return
96 std::istringstream
is(str
.substr(f
+1));
97 return object_prototypes
.lookup_name(type
)->clone_from_bdcff(type
, is
);