src/supertux/object_factory.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2004 Ricardo Cruz <rick2@aeiou.pt>
00003 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00004 //
00005 //  This program is free software: you can redistribute it and/or modify
00006 //  it under the terms of the GNU General Public License as published by
00007 //  the Free Software Foundation, either version 3 of the License, or
00008 //  (at your option) any later version.
00009 //
00010 //  This program is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //  GNU General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU General Public License
00016 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 #include <sstream>
00019 #include <stdexcept>
00020 
00021 #include "lisp/parser.hpp"
00022 #include "math/vector.hpp"
00023 #include "util/reader.hpp"
00024 #include "supertux/object_factory.hpp"
00025 
00026 #include "badguy/angrystone.hpp"
00027 #include "badguy/badguy.hpp"
00028 #include "badguy/bomb.hpp"
00029 #include "badguy/skydive.hpp"
00030 #include "badguy/bouncing_snowball.hpp"
00031 #include "badguy/captainsnowball.hpp"
00032 #include "badguy/crystallo.hpp"
00033 #include "badguy/dart.hpp"
00034 #include "badguy/darttrap.hpp"
00035 #include "badguy/dispenser.hpp"
00036 #include "badguy/fish.hpp"
00037 #include "badguy/flame.hpp"
00038 #include "badguy/flyingsnowball.hpp"
00039 #include "badguy/ghosttree.hpp"
00040 #include "badguy/haywire.hpp"
00041 #include "badguy/igel.hpp"
00042 #include "badguy/jumpy.hpp"
00043 #include "badguy/kamikazesnowball.hpp"
00044 #include "badguy/kugelblitz.hpp"
00045 #include "badguy/mole.hpp"
00046 #include "badguy/mole_rock.hpp"
00047 #include "badguy/mrbomb.hpp"
00048 #include "badguy/mriceblock.hpp"
00049 #include "badguy/mrtree.hpp"
00050 #include "badguy/owl.hpp"
00051 #include "badguy/plant.hpp"
00052 #include "badguy/poisonivy.hpp"
00053 #include "badguy/root.hpp"
00054 #include "badguy/short_fuse.hpp"
00055 #include "badguy/skullyhop.hpp"
00056 #include "badguy/smartball.hpp"
00057 #include "badguy/snail.hpp"
00058 #include "badguy/snowball.hpp"
00059 #include "badguy/snowman.hpp"
00060 #include "badguy/spidermite.hpp"
00061 #include "badguy/spiky.hpp"
00062 #include "badguy/sspiky.hpp"
00063 #include "badguy/stalactite.hpp"
00064 #include "badguy/stumpy.hpp"
00065 #include "badguy/toad.hpp"
00066 #include "badguy/totem.hpp"
00067 #include "badguy/treewillowisp.hpp"
00068 #include "badguy/walking_badguy.hpp"
00069 #include "badguy/walkingleaf.hpp"
00070 #include "badguy/willowisp.hpp"
00071 #include "badguy/yeti.hpp"
00072 #include "badguy/yeti_stalactite.hpp"
00073 #include "badguy/zeekling.hpp"
00074 
00075 #include "object/ambient_sound.hpp"
00076 #include "object/anchor_point.hpp"
00077 #include "object/background.hpp"
00078 #include "object/bicycle_platform.hpp"
00079 #include "object/block.hpp"
00080 #include "object/bonus_block.hpp"
00081 #include "object/bouncy_coin.hpp"
00082 #include "object/brick.hpp"
00083 #include "object/broken_brick.hpp"
00084 #include "object/bullet.hpp"
00085 #include "object/camera.hpp"
00086 #include "object/candle.hpp"
00087 #include "object/cloud_particle_system.hpp"
00088 #include "object/coin.hpp"
00089 #include "object/comet_particle_system.hpp"
00090 #include "object/decal.hpp"
00091 #include "object/display_effect.hpp"
00092 #include "object/electrifier.hpp"
00093 #include "object/endsequence_fireworks.hpp"
00094 #include "object/endsequence.hpp"
00095 #include "object/endsequence_walkleft.hpp"
00096 #include "object/endsequence_walkright.hpp"
00097 #include "object/explosion.hpp"
00098 #include "object/falling_coin.hpp"
00099 #include "object/firefly.hpp"
00100 #include "object/fireworks.hpp"
00101 #include "object/floating_image.hpp"
00102 #include "object/floating_text.hpp"
00103 #include "object/flower.hpp"
00104 #include "object/ghost_particle_system.hpp"
00105 #include "object/gradient.hpp"
00106 #include "object/growup.hpp"
00107 #include "object/hurting_platform.hpp"
00108 #include "object/icecrusher.hpp"
00109 #include "object/infoblock.hpp"
00110 #include "object/invisible_block.hpp"
00111 #include "object/invisible_wall.hpp"
00112 #include "object/ispy.hpp"
00113 #include "object/lantern.hpp"
00114 #include "object/level_time.hpp"
00115 #include "object/light.hpp"
00116 #include "object/magicblock.hpp"
00117 #include "object/moving_sprite.hpp"
00118 #include "object/oneup.hpp"
00119 #include "object/particles.hpp"
00120 #include "object/particlesystem.hpp"
00121 #include "object/particlesystem_interactive.hpp"
00122 #include "object/path.hpp"
00123 #include "object/path_walker.hpp"
00124 #include "object/platform.hpp"
00125 #include "object/player.hpp"
00126 #include "object/pneumatic_platform.hpp"
00127 #include "object/portable.hpp"
00128 #include "object/powerup.hpp"
00129 #include "object/pulsing_light.hpp"
00130 #include "object/pushbutton.hpp"
00131 #include "object/rain_particle_system.hpp"
00132 #include "object/rainsplash.hpp"
00133 #include "object/rock.hpp"
00134 #include "object/scripted_object.hpp"
00135 #include "object/skull_tile.hpp"
00136 #include "object/smoke_cloud.hpp"
00137 #include "object/snow_particle_system.hpp"
00138 #include "object/specialriser.hpp"
00139 #include "object/spotlight.hpp"
00140 #include "object/sprite_particle.hpp"
00141 #include "object/star.hpp"
00142 #include "object/text_object.hpp"
00143 #include "object/thunderstorm.hpp"
00144 #include "object/tilemap.hpp"
00145 #include "object/trampoline.hpp"
00146 #include "object/unstable_tile.hpp"
00147 #include "object/weak_block.hpp"
00148 #include "object/wind.hpp"
00149 
00150 #include "trigger/climbable.hpp"
00151 #include "trigger/door.hpp"
00152 #include "trigger/scripttrigger.hpp"
00153 #include "trigger/secretarea_trigger.hpp"
00154 #include "trigger/sequence_trigger.hpp"
00155 #include "trigger/switch.hpp"
00156 
00157 ObjectFactory&
00158 ObjectFactory::instance()
00159 {
00160   static ObjectFactory instance_;
00161   return instance_;
00162 }
00163 
00164 ObjectFactory::ObjectFactory() :
00165   factories()
00166 {
00167   init_factories();
00168 }
00169 
00170 ObjectFactory::~ObjectFactory()
00171 {
00172 }
00173 
00174 void
00175 ObjectFactory::init_factories()
00176 {
00177   // badguys
00178   add_factory<AngryStone>("angrystone");
00179   add_factory<BouncingSnowball>("bouncingsnowball");
00180   add_factory<CaptainSnowball>("captainsnowball");
00181   add_factory<Crystallo>("crystallo");
00182   add_factory<Dart>("dart");
00183   add_factory<DartTrap>("darttrap");
00184   add_factory<Dispenser>("dispenser");
00185   add_factory<Fish>("fish");
00186   add_factory<Flame>("flame");
00187   add_factory<FlyingSnowBall>("flyingsnowball");
00188   add_factory<GhostTree>("ghosttree");
00189   add_factory<Haywire>("haywire");
00190   add_factory<Igel>("igel");
00191   add_factory<Jumpy>("jumpy");
00192   add_factory<KamikazeSnowball>("kamikazesnowball");
00193   add_factory<Kugelblitz>("kugelblitz");
00194   add_factory<Mole>("mole");
00195   add_factory<MoleRock>("mole_rock");
00196   add_factory<MrBomb>("mrbomb");
00197   add_factory<MrIceBlock>("mriceblock");
00198   add_factory<MrTree>("mrtree");
00199   add_factory<Owl>("owl");
00200   add_factory<Plant>("plant");
00201   add_factory<PoisonIvy>("poisonivy");
00202   add_factory<ShortFuse>("short_fuse");
00203   add_factory<SSpiky>("sspiky");
00204   add_factory<SkyDive>("skydive");
00205   add_factory<SkullyHop>("skullyhop");
00206   add_factory<SmartBall>("smartball");
00207   add_factory<Snail>("snail");
00208   add_factory<SnowBall>("snowball");
00209   add_factory<Snowman>("snowman");
00210   add_factory<SpiderMite>("spidermite");
00211   add_factory<Spiky>("spiky");
00212   add_factory<Stalactite>("stalactite");
00213   add_factory<Stumpy>("stumpy");
00214   add_factory<Toad>("toad");
00215   add_factory<Totem>("totem");
00216   add_factory<WalkingLeaf>("walkingleaf");
00217   add_factory<WillOWisp>("willowisp");
00218   add_factory<Yeti>("yeti");
00219   add_factory<YetiStalactite>("yeti_stalactite");
00220   add_factory<Zeekling>("zeekling");
00221 
00222   // other objects
00223   add_factory<AmbientSound>("ambient_sound");
00224   add_factory<Background>("background");
00225   add_factory<BicyclePlatform>("bicycle-platform");
00226   add_factory<BonusBlock>("bonusblock");
00227   add_factory<Candle>("candle");
00228   add_factory<Coin>("coin");
00229   add_factory<Decal>("decal");
00230   add_factory<Explosion>("explosion");
00231   add_factory<Firefly>("firefly");
00232   add_factory<Gradient>("gradient");
00233   add_factory<HurtingPlatform>("hurting_platform");
00234   add_factory<IceCrusher>("icecrusher");
00235   add_factory<InfoBlock>("infoblock");
00236   add_factory<InvisibleWall>("invisible_wall");
00237   add_factory<Ispy>("ispy");
00238   add_factory<Lantern>("lantern");
00239   add_factory<LevelTime>("leveltime");
00240   add_factory<MagicBlock>("magicblock");
00241   add_factory<Platform>("platform");
00242   add_factory<PneumaticPlatform>("pneumatic-platform");
00243   add_factory<PowerUp>("powerup");
00244   add_factory<PushButton>("pushbutton");
00245   add_factory<Rock>("rock");
00246   add_factory<ScriptedObject>("scriptedobject");
00247   add_factory<SkullTile>("skull_tile");
00248   add_factory<Spotlight>("spotlight");
00249   add_factory<Thunderstorm>("thunderstorm");
00250   add_factory<TileMap>("tilemap");
00251   add_factory<Trampoline>("trampoline");
00252   add_factory<UnstableTile>("unstable_tile");
00253   add_factory<WeakBlock>("weak_block");
00254   add_factory<Wind>("wind");
00255 
00256   // trigger
00257   add_factory<Climbable>("climbable");
00258   add_factory<Door>("door");
00259   add_factory<ScriptTrigger>("scripttrigger");
00260   add_factory<SecretAreaTrigger>("secretarea");
00261   add_factory<SequenceTrigger>("sequencetrigger");
00262   add_factory<Switch>("switch");
00263 }
00264 
00265 GameObject*
00266 ObjectFactory::create(const std::string& name, const Reader& reader)
00267 {
00268   Factories::iterator i = factories.find(name);
00269 
00270   if (i == factories.end()) 
00271   {
00272     std::stringstream msg;
00273     msg << "No factory for object '" << name << "' found.";
00274     throw std::runtime_error(msg.str());
00275   }
00276   else
00277   {
00278     return i->second->create(reader);
00279   }
00280 }
00281 
00282 GameObject*
00283 ObjectFactory::create(const std::string& name, const Vector& pos, const Direction dir)
00284 {
00285   std::stringstream lisptext;
00286   lisptext << "((x " << pos.x << ")"
00287            << " (y " << pos.y << ")";
00288   if(dir != AUTO)
00289     lisptext << " (direction " << dir << "))";
00290 
00291   lisp::Parser parser;
00292   const lisp::Lisp* lisp = parser.parse(lisptext, "create_object");
00293   
00294   GameObject* object = create(name, *(lisp->get_car()));
00295   return object;
00296 }
00297 
00298 /* EOF */

Generated on Mon Jun 9 03:38:23 2014 for SuperTux by  doxygen 1.5.1