Added Kirby badguy
[supertux.git] / src / supertux / object_factory.cpp
1 //  SuperTux
2 //  Copyright (C) 2004 Ricardo Cruz <rick2@aeiou.pt>
3 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 //
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.
9 //
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.
14 //
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/>.
17
18 #include <sstream>
19 #include <stdexcept>
20
21 #include "lisp/parser.hpp"
22 #include "math/vector.hpp"
23 #include "util/reader.hpp"
24 #include "supertux/object_factory.hpp"
25
26 #include "badguy/angrystone.hpp"
27 #include "badguy/badguy.hpp"
28 #include "badguy/bomb.hpp"
29 #include "badguy/skydive.hpp"
30 #include "badguy/bouncing_snowball.hpp"
31 #include "badguy/captainsnowball.hpp"
32 #include "badguy/crystallo.hpp"
33 #include "badguy/dart.hpp"
34 #include "badguy/darttrap.hpp"
35 #include "badguy/dispenser.hpp"
36 #include "badguy/fish.hpp"
37 #include "badguy/flame.hpp"
38 #include "badguy/flyingsnowball.hpp"
39 #include "badguy/ghostflame.hpp"
40 #include "badguy/ghosttree.hpp"
41 #include "badguy/goldbomb.hpp"
42 #include "badguy/haywire.hpp"
43 #include "badguy/iceflame.hpp"
44 #include "badguy/igel.hpp"
45 #include "badguy/jumpy.hpp"
46 #include "badguy/kamikazesnowball.hpp"
47 #include "badguy/kirby.hpp"
48 #include "badguy/kugelblitz.hpp"
49 #include "badguy/livefire.hpp"
50 #include "badguy/mole.hpp"
51 #include "badguy/mole_rock.hpp"
52 #include "badguy/mrbomb.hpp"
53 #include "badguy/mriceblock.hpp"
54 #include "badguy/mrtree.hpp"
55 #include "badguy/owl.hpp"
56 #include "badguy/plant.hpp"
57 #include "badguy/poisonivy.hpp"
58 #include "badguy/root.hpp"
59 #include "badguy/short_fuse.hpp"
60 #include "badguy/skullyhop.hpp"
61 #include "badguy/smartball.hpp"
62 #include "badguy/snail.hpp"
63 #include "badguy/snowball.hpp"
64 #include "badguy/snowman.hpp"
65 #include "badguy/spidermite.hpp"
66 #include "badguy/spiky.hpp"
67 #include "badguy/sspiky.hpp"
68 #include "badguy/stalactite.hpp"
69 #include "badguy/stumpy.hpp"
70 #include "badguy/toad.hpp"
71 #include "badguy/totem.hpp"
72 #include "badguy/treewillowisp.hpp"
73 #include "badguy/walking_badguy.hpp"
74 #include "badguy/walkingleaf.hpp"
75 #include "badguy/willowisp.hpp"
76 #include "badguy/yeti.hpp"
77 #include "badguy/yeti_stalactite.hpp"
78 #include "badguy/zeekling.hpp"
79
80 #include "object/ambient_sound.hpp"
81 #include "object/anchor_point.hpp"
82 #include "object/background.hpp"
83 #include "object/bicycle_platform.hpp"
84 #include "object/block.hpp"
85 #include "object/bonus_block.hpp"
86 #include "object/bouncy_coin.hpp"
87 #include "object/brick.hpp"
88 #include "object/broken_brick.hpp"
89 #include "object/bullet.hpp"
90 #include "object/camera.hpp"
91 #include "object/candle.hpp"
92 #include "object/cloud_particle_system.hpp"
93 #include "object/coin.hpp"
94 #include "object/coin_explode.hpp"
95 #include "object/coin_rain.hpp"
96 #include "object/comet_particle_system.hpp"
97 #include "object/decal.hpp"
98 #include "object/display_effect.hpp"
99 #include "object/electrifier.hpp"
100 #include "object/endsequence_fireworks.hpp"
101 #include "object/endsequence.hpp"
102 #include "object/endsequence_walkleft.hpp"
103 #include "object/endsequence_walkright.hpp"
104 #include "object/explosion.hpp"
105 #include "object/falling_coin.hpp"
106 #include "object/firefly.hpp"
107 #include "object/fireworks.hpp"
108 #include "object/floating_image.hpp"
109 #include "object/floating_text.hpp"
110 #include "object/flower.hpp"
111 #include "object/ghost_particle_system.hpp"
112 #include "object/gradient.hpp"
113 #include "object/growup.hpp"
114 #include "object/hurting_platform.hpp"
115 #include "object/icecrusher.hpp"
116 #include "object/infoblock.hpp"
117 #include "object/invisible_block.hpp"
118 #include "object/invisible_wall.hpp"
119 #include "object/ispy.hpp"
120 #include "object/lantern.hpp"
121 #include "object/level_time.hpp"
122 #include "object/light.hpp"
123 #include "object/magicblock.hpp"
124 #include "object/moving_sprite.hpp"
125 #include "object/oneup.hpp"
126 #include "object/particles.hpp"
127 #include "object/particlesystem.hpp"
128 #include "object/particlesystem_interactive.hpp"
129 #include "object/path.hpp"
130 #include "object/path_walker.hpp"
131 #include "object/platform.hpp"
132 #include "object/player.hpp"
133 #include "object/pneumatic_platform.hpp"
134 #include "object/portable.hpp"
135 #include "object/powerup.hpp"
136 #include "object/pulsing_light.hpp"
137 #include "object/pushbutton.hpp"
138 #include "object/rain_particle_system.hpp"
139 #include "object/rainsplash.hpp"
140 #include "object/rock.hpp"
141 #include "object/rusty_trampoline.hpp"
142 #include "object/scripted_object.hpp"
143 #include "object/skull_tile.hpp"
144 #include "object/smoke_cloud.hpp"
145 #include "object/snow_particle_system.hpp"
146 #include "object/specialriser.hpp"
147 #include "object/spotlight.hpp"
148 #include "object/sprite_particle.hpp"
149 #include "object/star.hpp"
150 #include "object/text_object.hpp"
151 #include "object/thunderstorm.hpp"
152 #include "object/tilemap.hpp"
153 #include "object/trampoline.hpp"
154 #include "object/unstable_tile.hpp"
155 #include "object/weak_block.hpp"
156 #include "object/wind.hpp"
157
158 #include "trigger/climbable.hpp"
159 #include "trigger/door.hpp"
160 #include "trigger/scripttrigger.hpp"
161 #include "trigger/secretarea_trigger.hpp"
162 #include "trigger/sequence_trigger.hpp"
163 #include "trigger/switch.hpp"
164
165 ObjectFactory&
166 ObjectFactory::instance()
167 {
168   static ObjectFactory instance_;
169   return instance_;
170 }
171
172 ObjectFactory::ObjectFactory() :
173   factories()
174 {
175   init_factories();
176 }
177
178 ObjectFactory::~ObjectFactory()
179 {
180 }
181
182 void
183 ObjectFactory::init_factories()
184 {
185   // badguys
186   add_factory<AngryStone>("angrystone");
187   add_factory<BouncingSnowball>("bouncingsnowball");
188   add_factory<CaptainSnowball>("captainsnowball");
189   add_factory<Crystallo>("crystallo");
190   add_factory<Dart>("dart");
191   add_factory<DartTrap>("darttrap");
192   add_factory<Dispenser>("dispenser");
193   add_factory<Fish>("fish");
194   add_factory<Flame>("flame");
195   add_factory<FlyingSnowBall>("flyingsnowball");
196   add_factory<Ghostflame>("ghostflame");
197   add_factory<GhostTree>("ghosttree");
198   add_factory<GoldBomb>("goldbomb");
199   add_factory<Haywire>("haywire");
200   add_factory<Iceflame>("iceflame");
201   add_factory<Igel>("igel");
202   add_factory<Jumpy>("jumpy");
203   add_factory<KamikazeSnowball>("kamikazesnowball");
204   add_factory<Kirby>("kirby");
205   add_factory<Kugelblitz>("kugelblitz");
206   add_factory<LiveFire>("livefire");
207   add_factory<LiveFireAsleep>("livefire_asleep");
208   add_factory<LiveFireDormant>("livefire_dormant");
209   add_factory<Mole>("mole");
210   add_factory<MoleRock>("mole_rock");
211   add_factory<MrBomb>("mrbomb");
212   add_factory<MrIceBlock>("mriceblock");
213   add_factory<MrTree>("mrtree");
214   add_factory<Owl>("owl");
215   add_factory<Plant>("plant");
216   add_factory<PoisonIvy>("poisonivy");
217   add_factory<ShortFuse>("short_fuse");
218   add_factory<SSpiky>("sspiky");
219   add_factory<SkyDive>("skydive");
220   add_factory<SkullyHop>("skullyhop");
221   add_factory<SmartBall>("smartball");
222   add_factory<SmartBlock>("smartblock");
223   add_factory<Snail>("snail");
224   add_factory<SnowBall>("snowball");
225   add_factory<Snowman>("snowman");
226   add_factory<SpiderMite>("spidermite");
227   add_factory<Spiky>("spiky");
228   add_factory<Stalactite>("stalactite");
229   add_factory<Stumpy>("stumpy");
230   add_factory<Toad>("toad");
231   add_factory<Totem>("totem");
232   add_factory<WalkingLeaf>("walkingleaf");
233   add_factory<WillOWisp>("willowisp");
234   add_factory<Yeti>("yeti");
235   add_factory<YetiStalactite>("yeti_stalactite");
236   add_factory<Zeekling>("zeekling");
237
238   // other objects
239   add_factory<AmbientSound>("ambient_sound");
240   add_factory<Background>("background");
241   add_factory<BicyclePlatform>("bicycle-platform");
242   add_factory<BonusBlock>("bonusblock");
243   add_factory<Candle>("candle");
244   add_factory<Coin>("coin");
245   add_factory<Decal>("decal");
246   add_factory<Explosion>("explosion");
247   add_factory<Firefly>("firefly");
248   add_factory<Gradient>("gradient");
249   add_factory<HeavyCoin>("heavycoin");
250   add_factory<HurtingPlatform>("hurting_platform");
251   add_factory<IceCrusher>("icecrusher");
252   add_factory<InfoBlock>("infoblock");
253   add_factory<InvisibleWall>("invisible_wall");
254   add_factory<Ispy>("ispy");
255   add_factory<Lantern>("lantern");
256   add_factory<LevelTime>("leveltime");
257   add_factory<MagicBlock>("magicblock");
258   add_factory<Platform>("platform");
259   add_factory<PneumaticPlatform>("pneumatic-platform");
260   add_factory<PowerUp>("powerup");
261   add_factory<PushButton>("pushbutton");
262   add_factory<Rock>("rock");
263   add_factory<ScriptedObject>("scriptedobject");
264   add_factory<SkullTile>("skull_tile");
265   add_factory<Spotlight>("spotlight");
266   add_factory<Thunderstorm>("thunderstorm");
267   add_factory<TileMap>("tilemap");
268   add_factory<Trampoline>("trampoline");
269   add_factory<RustyTrampoline>("rustytrampoline");
270   add_factory<UnstableTile>("unstable_tile");
271   add_factory<WeakBlock>("weak_block");
272   add_factory<Wind>("wind");
273
274   // trigger
275   add_factory<Climbable>("climbable");
276   add_factory<Door>("door");
277   add_factory<ScriptTrigger>("scripttrigger");
278   add_factory<SecretAreaTrigger>("secretarea");
279   add_factory<SequenceTrigger>("sequencetrigger");
280   add_factory<Switch>("switch");
281 }
282
283 GameObjectPtr
284 ObjectFactory::create(const std::string& name, const Reader& reader)
285 {
286   Factories::iterator i = factories.find(name);
287
288   if (i == factories.end())
289   {
290     std::stringstream msg;
291     msg << "No factory for object '" << name << "' found.";
292     throw std::runtime_error(msg.str());
293   }
294   else
295   {
296     return i->second->create(reader);
297   }
298 }
299
300 GameObjectPtr
301 ObjectFactory::create(const std::string& name, const Vector& pos, const Direction dir)
302 {
303   std::stringstream lisptext;
304   lisptext << "((x " << pos.x << ")"
305            << " (y " << pos.y << ")";
306   if(dir != AUTO)
307     lisptext << " (direction " << dir << "))";
308
309   lisp::Parser parser;
310   const lisp::Lisp* lisp = parser.parse(lisptext, "create_object");
311
312   return create(name, *(lisp->get_car()));
313 }
314
315 /* EOF */