2 // Copyright (C) 2004 Ricardo Cruz <rick2@aeiou.pt>
3 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "lisp/parser.hpp"
22 #include "math/vector.hpp"
23 #include "util/reader.hpp"
24 #include "supertux/object_factory.hpp"
26 #include "badguy/angrystone.hpp"
27 #include "badguy/badguy.hpp"
28 #include "badguy/bomb.hpp"
29 #include "badguy/bouncing_snowball.hpp"
30 #include "badguy/captainsnowball.hpp"
31 #include "badguy/crystallo.hpp"
32 #include "badguy/dart.hpp"
33 #include "badguy/darttrap.hpp"
34 #include "badguy/dispenser.hpp"
35 #include "badguy/fish.hpp"
36 #include "badguy/flame.hpp"
37 #include "badguy/flyingsnowball.hpp"
38 #include "badguy/ghosttree.hpp"
39 #include "badguy/haywire.hpp"
40 #include "badguy/igel.hpp"
41 #include "badguy/jumpy.hpp"
42 #include "badguy/kamikazesnowball.hpp"
43 #include "badguy/kugelblitz.hpp"
44 #include "badguy/mole.hpp"
45 #include "badguy/mole_rock.hpp"
46 #include "badguy/mrbomb.hpp"
47 #include "badguy/mriceblock.hpp"
48 #include "badguy/mrtree.hpp"
49 #include "badguy/owl.hpp"
50 #include "badguy/plant.hpp"
51 #include "badguy/poisonivy.hpp"
52 #include "badguy/root.hpp"
53 #include "badguy/short_fuse.hpp"
54 #include "badguy/skullyhop.hpp"
55 #include "badguy/smartball.hpp"
56 #include "badguy/snail.hpp"
57 #include "badguy/snowball.hpp"
58 #include "badguy/snowman.hpp"
59 #include "badguy/spidermite.hpp"
60 #include "badguy/spiky.hpp"
61 #include "badguy/sspiky.hpp"
62 #include "badguy/stalactite.hpp"
63 #include "badguy/stumpy.hpp"
64 #include "badguy/toad.hpp"
65 #include "badguy/totem.hpp"
66 #include "badguy/treewillowisp.hpp"
67 #include "badguy/walking_badguy.hpp"
68 #include "badguy/walkingleaf.hpp"
69 #include "badguy/willowisp.hpp"
70 #include "badguy/yeti.hpp"
71 #include "badguy/yeti_stalactite.hpp"
72 #include "badguy/zeekling.hpp"
74 #include "object/ambient_sound.hpp"
75 #include "object/anchor_point.hpp"
76 #include "object/background.hpp"
77 #include "object/bicycle_platform.hpp"
78 #include "object/block.hpp"
79 #include "object/bonus_block.hpp"
80 #include "object/bouncy_coin.hpp"
81 #include "object/brick.hpp"
82 #include "object/broken_brick.hpp"
83 #include "object/bullet.hpp"
84 #include "object/camera.hpp"
85 #include "object/candle.hpp"
86 #include "object/cloud_particle_system.hpp"
87 #include "object/coin.hpp"
88 #include "object/comet_particle_system.hpp"
89 #include "object/decal.hpp"
90 #include "object/display_effect.hpp"
91 #include "object/electrifier.hpp"
92 #include "object/endsequence_fireworks.hpp"
93 #include "object/endsequence.hpp"
94 #include "object/endsequence_walkleft.hpp"
95 #include "object/endsequence_walkright.hpp"
96 #include "object/explosion.hpp"
97 #include "object/falling_coin.hpp"
98 #include "object/firefly.hpp"
99 #include "object/fireworks.hpp"
100 #include "object/floating_image.hpp"
101 #include "object/floating_text.hpp"
102 #include "object/flower.hpp"
103 #include "object/ghost_particle_system.hpp"
104 #include "object/gradient.hpp"
105 #include "object/growup.hpp"
106 #include "object/hurting_platform.hpp"
107 #include "object/icecrusher.hpp"
108 #include "object/infoblock.hpp"
109 #include "object/invisible_block.hpp"
110 #include "object/invisible_wall.hpp"
111 #include "object/ispy.hpp"
112 #include "object/lantern.hpp"
113 #include "object/level_time.hpp"
114 #include "object/light.hpp"
115 #include "object/magicblock.hpp"
116 #include "object/moving_sprite.hpp"
117 #include "object/oneup.hpp"
118 #include "object/particles.hpp"
119 #include "object/particlesystem.hpp"
120 #include "object/particlesystem_interactive.hpp"
121 #include "object/path.hpp"
122 #include "object/path_walker.hpp"
123 #include "object/platform.hpp"
124 #include "object/player.hpp"
125 #include "object/pneumatic_platform.hpp"
126 #include "object/portable.hpp"
127 #include "object/powerup.hpp"
128 #include "object/pulsing_light.hpp"
129 #include "object/pushbutton.hpp"
130 #include "object/rain_particle_system.hpp"
131 #include "object/rainsplash.hpp"
132 #include "object/rock.hpp"
133 #include "object/scripted_object.hpp"
134 #include "object/skull_tile.hpp"
135 #include "object/smoke_cloud.hpp"
136 #include "object/snow_particle_system.hpp"
137 #include "object/specialriser.hpp"
138 #include "object/spotlight.hpp"
139 #include "object/sprite_particle.hpp"
140 #include "object/star.hpp"
141 #include "object/text_object.hpp"
142 #include "object/thunderstorm.hpp"
143 #include "object/tilemap.hpp"
144 #include "object/trampoline.hpp"
145 #include "object/unstable_tile.hpp"
146 #include "object/weak_block.hpp"
147 #include "object/wind.hpp"
149 #include "trigger/climbable.hpp"
150 #include "trigger/door.hpp"
151 #include "trigger/scripttrigger.hpp"
152 #include "trigger/secretarea_trigger.hpp"
153 #include "trigger/sequence_trigger.hpp"
154 #include "trigger/switch.hpp"
157 ObjectFactory::instance()
159 static ObjectFactory instance_;
163 ObjectFactory::ObjectFactory() :
169 ObjectFactory::~ObjectFactory()
174 ObjectFactory::init_factories()
177 add_factory<AngryStone>("angrystone");
178 add_factory<BouncingSnowball>("bouncingsnowball");
179 add_factory<CaptainSnowball>("captainsnowball");
180 add_factory<Crystallo>("crystallo");
181 add_factory<Dart>("dart");
182 add_factory<DartTrap>("darttrap");
183 add_factory<Dispenser>("dispenser");
184 add_factory<Fish>("fish");
185 add_factory<Flame>("flame");
186 add_factory<FlyingSnowBall>("flyingsnowball");
187 add_factory<GhostTree>("ghosttree");
188 add_factory<Haywire>("haywire");
189 add_factory<Igel>("igel");
190 add_factory<Jumpy>("jumpy");
191 add_factory<KamikazeSnowball>("kamikazesnowball");
192 add_factory<Kugelblitz>("kugelblitz");
193 add_factory<Mole>("mole");
194 add_factory<MoleRock>("mole_rock");
195 add_factory<MrBomb>("mrbomb");
196 add_factory<MrIceBlock>("mriceblock");
197 add_factory<MrTree>("mrtree");
198 add_factory<Owl>("owl");
199 add_factory<Plant>("plant");
200 add_factory<PoisonIvy>("poisonivy");
201 add_factory<ShortFuse>("short_fuse");
202 add_factory<SSpiky>("sspiky");
203 add_factory<SkullyHop>("skullyhop");
204 add_factory<SmartBall>("smartball");
205 add_factory<Snail>("snail");
206 add_factory<SnowBall>("snowball");
207 add_factory<Snowman>("snowman");
208 add_factory<SpiderMite>("spidermite");
209 add_factory<Spiky>("spiky");
210 add_factory<Stalactite>("stalactite");
211 add_factory<Stumpy>("stumpy");
212 add_factory<Toad>("toad");
213 add_factory<Totem>("totem");
214 add_factory<WalkingLeaf>("walkingleaf");
215 add_factory<WillOWisp>("willowisp");
216 add_factory<Yeti>("yeti");
217 add_factory<YetiStalactite>("yeti_stalactite");
218 add_factory<Zeekling>("zeekling");
221 add_factory<AmbientSound>("ambient_sound");
222 add_factory<Background>("background");
223 add_factory<BicyclePlatform>("bicycle-platform");
224 add_factory<BonusBlock>("bonusblock");
225 add_factory<Candle>("candle");
226 add_factory<Coin>("coin");
227 add_factory<Decal>("decal");
228 add_factory<Explosion>("explosion");
229 add_factory<Firefly>("firefly");
230 add_factory<Gradient>("gradient");
231 add_factory<HurtingPlatform>("hurting_platform");
232 add_factory<IceCrusher>("icecrusher");
233 add_factory<InfoBlock>("infoblock");
234 add_factory<InvisibleWall>("invisible_wall");
235 add_factory<Ispy>("ispy");
236 add_factory<Lantern>("lantern");
237 add_factory<LevelTime>("leveltime");
238 add_factory<MagicBlock>("magicblock");
239 add_factory<Platform>("platform");
240 add_factory<PneumaticPlatform>("pneumatic-platform");
241 add_factory<PowerUp>("powerup");
242 add_factory<PushButton>("pushbutton");
243 add_factory<Rock>("rock");
244 add_factory<ScriptedObject>("scriptedobject");
245 add_factory<SkullTile>("skull_tile");
246 add_factory<Spotlight>("spotlight");
247 add_factory<Thunderstorm>("thunderstorm");
248 add_factory<TileMap>("tilemap");
249 add_factory<Trampoline>("trampoline");
250 add_factory<UnstableTile>("unstable_tile");
251 add_factory<WeakBlock>("weak_block");
252 add_factory<Wind>("wind");
255 add_factory<Climbable>("climbable");
256 add_factory<Door>("door");
257 add_factory<ScriptTrigger>("scripttrigger");
258 add_factory<SecretAreaTrigger>("secretarea");
259 add_factory<SequenceTrigger>("sequencetrigger");
260 add_factory<Switch>("switch");
264 ObjectFactory::create(const std::string& name, const Reader& reader)
266 Factories::iterator i = factories.find(name);
268 if (i == factories.end())
270 std::stringstream msg;
271 msg << "No factory for object '" << name << "' found.";
272 throw std::runtime_error(msg.str());
276 return i->second->create(reader);
281 ObjectFactory::create(const std::string& name, const Vector& pos, const Direction dir)
283 std::stringstream lisptext;
284 lisptext << "((x " << pos.x << ")"
285 << " (y " << pos.y << ")";
287 lisptext << " (direction " << dir << "))";
290 const lisp::Lisp* lisp = parser.parse(lisptext, "create_object");
292 GameObject* object = create(name, *(lisp->get_car()));