src/supertux/sector.hpp

Go to the documentation of this file.
00001 //  SuperTux -  A Jump'n Run
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef HEADER_SUPERTUX_SUPERTUX_SECTOR_HPP
00018 #define HEADER_SUPERTUX_SUPERTUX_SECTOR_HPP
00019 
00020 #include <list>
00021 #include <squirrel.h>
00022 #include <stdint.h>
00023 
00024 #include "scripting/ssector.hpp"
00025 #include "supertux/direction.hpp"
00026 #include "util/reader_fwd.hpp"
00027 #include "util/writer_fwd.hpp"
00028 #include "util/currenton.hpp"
00029 #include "video/color.hpp"
00030 #include "object/anchor_point.hpp"
00031 
00032 namespace collision {
00033 class Constraints;
00034 }
00035 
00036 class Vector;
00037 class Rectf;
00038 class Sprite;
00039 class GameObject;
00040 class Player;
00041 class PlayerStatus;
00042 class Camera;
00043 class TileMap;
00044 class Bullet;
00045 class ScriptInterpreter;
00046 class SpawnPoint;
00047 class MovingObject;
00048 class CollisionHit;
00049 class Level;
00050 class Portable;
00051 class DrawingContext;
00052 class DisplayEffect;
00053 
00054 enum MusicType {
00055   LEVEL_MUSIC,
00056   HERRING_MUSIC,
00057   HERRING_WARNING_MUSIC
00058 };
00059 
00065 class Sector : public scripting::SSector,
00066                public Currenton<Sector>
00067 {
00068 public:
00069   Sector(Level* parent);
00070   ~Sector();
00071 
00073   Level* get_level();
00074 
00076   void parse(const Reader& lisp);
00077   void parse_old_format(const Reader& lisp);
00078   
00080   void activate(const std::string& spawnpoint);
00081   void activate(const Vector& player_pos);
00082   void deactivate();
00083 
00084   void update(float elapsed_time);
00085   void update_game_objects();
00086 
00087   void draw(DrawingContext& context);
00088 
00093   HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
00094 
00096   void add_object(GameObject* object);
00097 
00098   void set_name(const std::string& name)
00099   { this->name = name; }
00100   const std::string& get_name() const
00101   { return name; }
00102 
00107   bool inside(const Rectf& rectangle) const;
00108 
00109   void play_music(MusicType musictype);
00110   MusicType get_music_type();
00111 
00112   bool add_bullet(const Vector& pos, const PlayerStatus* player_status, float xm, Direction dir);
00113   bool add_smoke_cloud(const Vector& pos);
00114 
00116   static Sector* current()
00117   { return _current; }
00118 
00120   int get_total_badguys();
00121 
00123   template<class T> int get_total_count()
00124   {
00125     int total = 0;
00126     for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) {
00127       if (dynamic_cast<T*>(*i)) total++;
00128     }
00129     return total;
00130   }
00131 
00132   void collision_tilemap(collision::Constraints* constraints,
00133                          const Vector& movement, const Rectf& dest,
00134                          MovingObject &object) const;
00135 
00140   bool is_free_of_tiles(const Rectf& rect, const bool ignoreUnisolid = false) const;
00147   bool is_free_of_statics(const Rectf& rect, const MovingObject* ignore_object = 0, const bool ignoreUnisolid = false) const;
00154   bool is_free_of_movingstatics(const Rectf& rect, const MovingObject* ignore_object = 0) const;
00155 
00159   std::vector<Player*> get_players() {
00160     return std::vector<Player*>(1, this->player);
00161   }
00162   Player *get_nearest_player (const Vector& pos);
00163   Player *get_nearest_player (const Rectf& pos)
00164   {
00165     return (get_nearest_player (get_anchor_pos (pos, ANCHOR_MIDDLE)));
00166   }
00167 
00168   std::vector<MovingObject*> get_nearby_objects (const Vector& center, float max_distance);
00169 
00170   Rectf get_active_region();
00171 
00175   float get_width() const;
00176 
00180   float get_height() const;
00181 
00185   void change_solid_tiles(uint32_t old_tile_id, uint32_t new_tile_id);
00186 
00187   typedef std::vector<GameObject*> GameObjects;
00188   typedef std::vector<MovingObject*> MovingObjects;
00189   typedef std::vector<SpawnPoint*> SpawnPoints;
00190   typedef std::vector<Portable*> Portables;
00191 
00192   // --- scripting ---
00196   void set_ambient_light(float red, float green, float blue);
00197   float get_ambient_red();
00198   float get_ambient_green();
00199   float get_ambient_blue();
00200 
00204   void set_gravity(float gravity);
00205   float get_gravity() const;
00206 
00207 private:
00208   uint32_t collision_tile_attributes(const Rectf& dest) const;
00209 
00210   void before_object_remove(GameObject* object);
00211   bool before_object_add(GameObject* object);
00212 
00213   void try_expose(GameObject* object);
00214   void try_unexpose(GameObject* object);
00215   void try_expose_me();
00216   void try_unexpose_me();
00217 
00221   void handle_collisions();
00222 
00227   void collision_object(MovingObject* object1, MovingObject* object2) const;
00228 
00238   void collision_static(collision::Constraints* constraints,
00239                         const Vector& movement, const Rectf& dest, MovingObject& object);
00240 
00241   void collision_static_constrains(MovingObject& object);
00242 
00243   GameObject* parse_object(const std::string& name, const Reader& lisp);
00244 
00245   void fix_old_tiles();
00246 
00247 private:
00248   static Sector* _current;
00249 
00250   Level* level; 
00252   std::string name;
00253 
00254   std::vector<Bullet*> bullets;
00255 
00256   std::string init_script;
00257 
00259   GameObjects gameobjects_new;
00260 
00261   MusicType currentmusic;
00262 
00263   HSQOBJECT sector_table;
00265   typedef std::vector<HSQOBJECT> ScriptList;
00266   ScriptList scripts;
00267 
00268   Color ambient_light;
00269 
00270 public: // TODO make this private again
00272   static bool show_collrects;
00273   static bool draw_solids_only;
00274 
00275   GameObjects gameobjects;
00276   MovingObjects moving_objects;
00277   SpawnPoints spawnpoints;
00278   Portables portables;
00279 
00280   std::string music;
00281   float gravity;
00282 
00283   // some special objects, where we need direct access
00284   // (try to avoid accessing them directly)
00285   Player* player;
00286   std::list<TileMap*> solid_tilemaps;
00287   Camera* camera;
00288   DisplayEffect* effect;
00289 
00290 private:
00291   Sector(const Sector&);
00292   Sector& operator=(const Sector&);
00293 };
00294 
00295 #endif
00296 
00297 /* EOF */

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