Sector Class Reference

Represents one of (potentially) multiple, separate parts of a Level. More...

#include <sector.hpp>

Inherits scripting::SSector, and Currenton< Sector >.

List of all members.

Public Types

typedef std::vector< GameObject * > GameObjects
typedef std::vector< MovingObject * > MovingObjects
typedef std::vector< SpawnPoint * > SpawnPoints
typedef std::vector< Portable * > Portables

Public Member Functions

 Sector (Level *parent)
 ~Sector ()
Levelget_level ()
 get parent level
void parse (const Reader &lisp)
 read sector from lisp file
void parse_old_format (const Reader &lisp)
void activate (const std::string &spawnpoint)
 activates this sector (change music, initialize player class, ...)
void activate (const Vector &player_pos)
void deactivate ()
void update (float elapsed_time)
void update_game_objects ()
void draw (DrawingContext &context)
HSQUIRRELVM run_script (std::istream &in, const std::string &sourcename)
 runs a script in the context of the sector (sector_table will be the roottable of this squirrel VM)
void add_object (GameObject *object)
 adds a gameobject
void set_name (const std::string &name)
const std::string & get_name () const
bool inside (const Rectf &rectangle) const
 tests if a given rectangle is inside the sector (a rectangle that is on top of the sector is considered inside)
void play_music (MusicType musictype)
MusicType get_music_type ()
bool add_bullet (const Vector &pos, const PlayerStatus *player_status, float xm, Direction dir)
bool add_smoke_cloud (const Vector &pos)
int get_total_badguys ()
 Get total number of badguys.
template<class T>
int get_total_count ()
 Get total number of GameObjects of given type.
void collision_tilemap (collision::Constraints *constraints, const Vector &movement, const Rectf &dest, MovingObject &object) const
bool is_free_of_tiles (const Rectf &rect, const bool ignoreUnisolid=false) const
 Checks if the specified rectangle is free of (solid) tiles.
bool is_free_of_statics (const Rectf &rect, const MovingObject *ignore_object=0, const bool ignoreUnisolid=false) const
 Checks if the specified rectangle is free of both 1.
bool is_free_of_movingstatics (const Rectf &rect, const MovingObject *ignore_object=0) const
 Checks if the specified rectangle is free of both 1.
std::vector< Player * > get_players ()
 returns a list of players currently in the sector
Playerget_nearest_player (const Vector &pos)
Playerget_nearest_player (const Rectf &pos)
std::vector< MovingObject * > get_nearby_objects (const Vector &center, float max_distance)
Rectf get_active_region ()
float get_width () const
 returns the width (in px) of a sector)
float get_height () const
 returns the height (in px) of a sector)
void change_solid_tiles (uint32_t old_tile_id, uint32_t new_tile_id)
 globally changes solid tilemaps' tile ids
void set_ambient_light (float red, float green, float blue)
 get/set color of ambient light
float get_ambient_red ()
float get_ambient_green ()
float get_ambient_blue ()
void set_gravity (float gravity)
 set gravity throughout sector
float get_gravity () const

Static Public Member Functions

static Sectorcurrent ()
 get currently activated sector.

Public Attributes

GameObjects gameobjects
MovingObjects moving_objects
SpawnPoints spawnpoints
Portables portables
std::string music
float gravity
Playerplayer
std::list< TileMap * > solid_tilemaps
Cameracamera
DisplayEffecteffect

Static Public Attributes

static bool show_collrects
 show collision rectangles of moving objects (for debugging)
static bool draw_solids_only

Private Types

typedef std::vector< HSQOBJECT > ScriptList
 sector scripts

Private Member Functions

uint32_t collision_tile_attributes (const Rectf &dest) const
void before_object_remove (GameObject *object)
bool before_object_add (GameObject *object)
void try_expose (GameObject *object)
void try_unexpose (GameObject *object)
void try_expose_me ()
void try_unexpose_me ()
void handle_collisions ()
 Checks for all possible collisions.
void collision_object (MovingObject *object1, MovingObject *object2) const
 Does collision detection between 2 objects and does instant collision response handling in case of a collision.
void collision_static (collision::Constraints *constraints, const Vector &movement, const Rectf &dest, MovingObject &object)
 Does collision detection of an object against all other static objects (and the tilemap) in the level.
void collision_static_constrains (MovingObject &object)
GameObjectparse_object (const std::string &name, const Reader &lisp)
void fix_old_tiles ()
 Sector (const Sector &)
Sectoroperator= (const Sector &)

Private Attributes

Levellevel
 Parent level containing this sector.
std::string name
std::vector< Bullet * > bullets
std::string init_script
GameObjects gameobjects_new
 container for newly created objects, they'll be added in Sector::update
MusicType currentmusic
HSQOBJECT sector_table
ScriptList scripts
Color ambient_light

Static Private Attributes

static Sector_current


Detailed Description

Represents one of (potentially) multiple, separate parts of a Level.

Sectors contain GameObjects, e.g. Badguys and Players.

Definition at line 65 of file sector.hpp.


Member Typedef Documentation

typedef std::vector<GameObject*> Sector::GameObjects

Definition at line 187 of file sector.hpp.

typedef std::vector<MovingObject*> Sector::MovingObjects

Definition at line 188 of file sector.hpp.

typedef std::vector<SpawnPoint*> Sector::SpawnPoints

Definition at line 189 of file sector.hpp.

typedef std::vector<Portable*> Sector::Portables

Definition at line 190 of file sector.hpp.

typedef std::vector<HSQOBJECT> Sector::ScriptList [private]

sector scripts

Definition at line 265 of file sector.hpp.


Constructor & Destructor Documentation

Sector::Sector ( Level parent  ) 

Definition at line 67 of file sector.cpp.

References add_object(), Currenton< GameSession >::current(), scripting::global_vm, SoundManager::preload(), sector_table, and sound_manager.

00067                             :
00068   level(parent), 
00069   name(),
00070   bullets(),
00071   init_script(),
00072   gameobjects_new(),
00073   currentmusic(LEVEL_MUSIC),
00074   sector_table(),
00075   scripts(),
00076   ambient_light( 1.0f, 1.0f, 1.0f, 1.0f ), 
00077   gameobjects(),
00078   moving_objects(),
00079   spawnpoints(),
00080   portables(),
00081   music(),
00082   gravity(10.0), 
00083   player(0), 
00084   solid_tilemaps(),
00085   camera(0), 
00086   effect(0)
00087 {
00088   add_object(new Player(GameSession::current()->get_player_status(), "Tux"));
00089   add_object(new DisplayEffect("Effect"));
00090   add_object(new TextObject("Text"));
00091 
00092   sound_manager->preload("sounds/shoot.wav");
00093 
00094   // create a new squirrel table for the sector
00095   using namespace scripting;
00096 
00097   sq_collectgarbage(global_vm);
00098 
00099   sq_newtable(global_vm);
00100   sq_pushroottable(global_vm);
00101   if(SQ_FAILED(sq_setdelegate(global_vm, -2)))
00102     throw scripting::SquirrelError(global_vm, "Couldn't set sector_table delegate");
00103 
00104   sq_resetobject(&sector_table);
00105   if(SQ_FAILED(sq_getstackobj(global_vm, -1, &sector_table)))
00106     throw scripting::SquirrelError(global_vm, "Couldn't get sector table");
00107   sq_addref(global_vm, &sector_table);
00108   sq_pop(global_vm, 1);
00109 }

Sector::~Sector (  ) 

Definition at line 111 of file sector.cpp.

References before_object_remove(), deactivate(), gameobjects, gameobjects_new, scripting::global_vm, scripts, sector_table, spawnpoints, and update_game_objects().

00112 {
00113   using namespace scripting;
00114 
00115   deactivate();
00116 
00117   for(ScriptList::iterator i = scripts.begin();
00118       i != scripts.end(); ++i) {
00119     HSQOBJECT& object = *i;
00120     sq_release(global_vm, &object);
00121   }
00122   sq_release(global_vm, &sector_table);
00123   sq_collectgarbage(global_vm);
00124 
00125   update_game_objects();
00126   assert(gameobjects_new.size() == 0);
00127 
00128   for(GameObjects::iterator i = gameobjects.begin();
00129       i != gameobjects.end(); ++i) {
00130     GameObject* object = *i;
00131     before_object_remove(object);
00132     object->unref();
00133   }
00134 
00135   for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
00136       ++i)
00137     delete *i;
00138 }

Sector::Sector ( const Sector  )  [private]


Member Function Documentation

Level * Sector::get_level (  ) 

get parent level

Definition at line 141 of file sector.cpp.

References level.

Referenced by activate(), Coin::collect(), OneUp::collision(), SecretAreaTrigger::event(), BadGuy::run_dead_script(), and BonusBlock::try_open().

00142 {
00143   return level;
00144 }

void Sector::parse ( const Reader lisp  ) 

read sector from lisp file

Definition at line 186 of file sector.cpp.

References add_object(), ambient_light, camera, fix_old_tiles(), lisp::Lisp::get(), gravity, init_script, lisp::ListIterator::item(), lisp::ListIterator::lisp(), log_warning, music, name, lisp::ListIterator::next(), parse_object(), Gradient::set_gradient(), solid_tilemaps, spawnpoints, update_game_objects(), and lisp::ListIterator::value().

Referenced by Level::load().

00187 {
00188   bool has_background = false;
00189   lisp::ListIterator iter(&sector);
00190   while(iter.next()) {
00191     const std::string& token = iter.item();
00192     if(token == "name") {
00193       iter.value()->get(name);
00194     } else if(token == "gravity") {
00195       iter.value()->get(gravity);
00196     } else if(token == "music") {
00197       iter.value()->get(music);
00198     } else if(token == "spawnpoint") {
00199       SpawnPoint* sp = new SpawnPoint(*iter.lisp());
00200       spawnpoints.push_back(sp);
00201     } else if(token == "init-script") {
00202       iter.value()->get(init_script);
00203     } else if(token == "ambient-light") {
00204       std::vector<float> vColor;
00205       sector.get( "ambient-light", vColor );
00206       if(vColor.size() < 3) {
00207         log_warning << "(ambient-light) requires a color as argument" << std::endl;
00208       } else {
00209         ambient_light = Color( vColor );
00210       }
00211     } else {
00212       GameObject* object = parse_object(token, *(iter.lisp()));
00213       if(object) {
00214         if(dynamic_cast<Background *>(object)) {
00215           has_background = true;
00216         } else if(dynamic_cast<Gradient *>(object)) {
00217           has_background = true;
00218         }
00219         add_object(object);
00220       }
00221     }
00222   }
00223 
00224   if(!has_background) {
00225     Gradient* gradient = new Gradient();
00226     gradient->set_gradient(Color(0.3, 0.4, 0.75), Color(1, 1, 1));
00227     add_object(gradient);
00228   }
00229 
00230   update_game_objects();
00231 
00232   if(solid_tilemaps.size() < 1) log_warning << "sector '" << name << "' does not contain a solid tile layer." << std::endl;
00233 
00234   fix_old_tiles();
00235   if(!camera) {
00236     log_warning << "sector '" << name << "' does not contain a camera." << std::endl;
00237     update_game_objects();
00238     add_object(new Camera(this, "Camera"));
00239   }
00240 
00241   update_game_objects();
00242 }

void Sector::parse_old_format ( const Reader lisp  ) 

Definition at line 245 of file sector.cpp.

References add_object(), Color::blue, camera, fix_old_tiles(), lisp::Lisp::get(), lisp::Lisp::get_lisp(), Level::get_tileset(), gravity, Color::green, lisp::ListIterator::item(), LAYER_BACKGROUNDTILES, LAYER_FOREGROUNDTILES, LAYER_TILES, level, lisp::ListIterator::lisp(), log_warning, music, SpawnPoint::name, name, lisp::ListIterator::next(), parse_object(), SpawnPoint::pos, Color::red, Gradient::set_gradient(), Background::set_image(), solid_tilemaps, spawnpoints, update_game_objects(), Vector::x, and Vector::y.

Referenced by Level::load_old_format().

00246 {
00247   name = "main";
00248   reader.get("gravity", gravity);
00249 
00250   std::string backgroundimage;
00251   if (reader.get("background", backgroundimage) && (backgroundimage != "")) {
00252     if (backgroundimage == "arctis.png") backgroundimage = "arctis.jpg";
00253     if (backgroundimage == "arctis2.jpg") backgroundimage = "arctis.jpg";
00254     if (backgroundimage == "ocean.png") backgroundimage = "ocean.jpg";
00255     backgroundimage = "images/background/" + backgroundimage;
00256     if (!PHYSFS_exists(backgroundimage.c_str())) {
00257       log_warning << "Background image \"" << backgroundimage << "\" not found. Ignoring." << std::endl;
00258       backgroundimage = "";
00259     }
00260   }
00261 
00262   float bgspeed = .5;
00263   reader.get("bkgd_speed", bgspeed);
00264   bgspeed /= 100;
00265 
00266   Color bkgd_top, bkgd_bottom;
00267   int r = 0, g = 0, b = 128;
00268   reader.get("bkgd_red_top", r);
00269   reader.get("bkgd_green_top",  g);
00270   reader.get("bkgd_blue_top",  b);
00271   bkgd_top.red = static_cast<float> (r) / 255.0f;
00272   bkgd_top.green = static_cast<float> (g) / 255.0f;
00273   bkgd_top.blue = static_cast<float> (b) / 255.0f;
00274 
00275   reader.get("bkgd_red_bottom",  r);
00276   reader.get("bkgd_green_bottom", g);
00277   reader.get("bkgd_blue_bottom", b);
00278   bkgd_bottom.red = static_cast<float> (r) / 255.0f;
00279   bkgd_bottom.green = static_cast<float> (g) / 255.0f;
00280   bkgd_bottom.blue = static_cast<float> (b) / 255.0f;
00281 
00282   if(backgroundimage != "") {
00283     Background* background = new Background();
00284     background->set_image(backgroundimage, bgspeed);
00285     add_object(background);
00286   } else {
00287     Gradient* gradient = new Gradient();
00288     gradient->set_gradient(bkgd_top, bkgd_bottom);
00289     add_object(gradient);
00290   }
00291 
00292   std::string particlesystem;
00293   reader.get("particle_system", particlesystem);
00294   if(particlesystem == "clouds")
00295     add_object(new CloudParticleSystem());
00296   else if(particlesystem == "snow")
00297     add_object(new SnowParticleSystem());
00298   else if(particlesystem == "rain")
00299     add_object(new RainParticleSystem());
00300 
00301   Vector startpos(100, 170);
00302   reader.get("start_pos_x", startpos.x);
00303   reader.get("start_pos_y", startpos.y);
00304 
00305   SpawnPoint* spawn = new SpawnPoint;
00306   spawn->pos = startpos;
00307   spawn->name = "main";
00308   spawnpoints.push_back(spawn);
00309 
00310   music = "chipdisko.ogg";
00311   // skip reading music filename. It's all .ogg now, anyway
00312   /*
00313     reader.get("music", music);
00314   */
00315   music = "music/" + music;
00316 
00317   int width = 30, height = 15;
00318   reader.get("width", width);
00319   reader.get("height", height);
00320 
00321   std::vector<unsigned int> tiles;
00322   if(reader.get("interactive-tm", tiles)
00323      || reader.get("tilemap", tiles)) {
00324     TileMap* tilemap = new TileMap(level->get_tileset());
00325     tilemap->set(width, height, tiles, LAYER_TILES, true);
00326 
00327     // replace tile id 112 (old invisible tile) with 1311 (new invisible tile)
00328     for(size_t x=0; x < tilemap->get_width(); ++x) {
00329       for(size_t y=0; y < tilemap->get_height(); ++y) {
00330         uint32_t id = tilemap->get_tile_id(x, y);
00331         if(id == 112)
00332           tilemap->change(x, y, 1311);
00333       }
00334     }
00335 
00336     if (height < 19) tilemap->resize(width, 19);
00337     add_object(tilemap);
00338   }
00339 
00340   if(reader.get("background-tm", tiles)) {
00341     TileMap* tilemap = new TileMap(level->get_tileset());
00342     tilemap->set(width, height, tiles, LAYER_BACKGROUNDTILES, false);
00343     if (height < 19) tilemap->resize(width, 19);
00344     add_object(tilemap);
00345   }
00346 
00347   if(reader.get("foreground-tm", tiles)) {
00348     TileMap* tilemap = new TileMap(level->get_tileset());
00349     tilemap->set(width, height, tiles, LAYER_FOREGROUNDTILES, false);
00350 
00351     // fill additional space in foreground with tiles of ID 2035 (lightmap/black)
00352     if (height < 19) tilemap->resize(width, 19, 2035);
00353 
00354     add_object(tilemap);
00355   }
00356 
00357   // read reset-points (now spawn-points)
00358   const lisp::Lisp* resetpoints = reader.get_lisp("reset-points");
00359   if(resetpoints) {
00360     lisp::ListIterator iter(resetpoints);
00361     while(iter.next()) {
00362       if(iter.item() == "point") {
00363         Vector sp_pos;
00364         if(reader.get("x", sp_pos.x) && reader.get("y", sp_pos.y))
00365         {
00366           SpawnPoint* sp = new SpawnPoint;
00367           sp->name = "main";
00368           sp->pos = sp_pos;
00369           spawnpoints.push_back(sp);
00370         }
00371       } else {
00372         log_warning << "Unknown token '" << iter.item() << "' in reset-points." << std::endl;
00373       }
00374     }
00375   }
00376 
00377   // read objects
00378   const lisp::Lisp* objects = reader.get_lisp("objects");
00379   if(objects) {
00380     lisp::ListIterator iter(objects);
00381     while(iter.next()) {
00382       GameObject* object = parse_object(iter.item(), *(iter.lisp()));
00383       if(object) {
00384         add_object(object);
00385       } else {
00386         log_warning << "Unknown object '" << iter.item() << "' in level." << std::endl;
00387       }
00388     }
00389   }
00390 
00391   // add a camera
00392   Camera* camera = new Camera(this, "Camera");
00393   add_object(camera);
00394 
00395   update_game_objects();
00396 
00397   if(solid_tilemaps.size() < 1) log_warning << "sector '" << name << "' does not contain a solid tile layer." << std::endl;
00398 
00399   fix_old_tiles();
00400   update_game_objects();
00401 }

void Sector::activate ( const std::string &  spawnpoint  ) 

activates this sector (change music, initialize player class, ...)

Definition at line 525 of file sector.cpp.

References log_warning, SpawnPoint::pos, and spawnpoints.

Referenced by TitleScreen::make_tux_jump(), GameSession::restart_level(), TitleScreen::setup(), GameSession::setup(), and GameSession::update().

00526 {
00527   SpawnPoint* sp = 0;
00528   for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
00529       ++i) {
00530     if((*i)->name == spawnpoint) {
00531       sp = *i;
00532       break;
00533     }
00534   }
00535   if(!sp) {
00536     log_warning << "Spawnpoint '" << spawnpoint << "' not found." << std::endl;
00537     if(spawnpoint != "main") {
00538       activate("main");
00539     } else {
00540       activate(Vector(0, 0));
00541     }
00542   } else {
00543     activate(sp->pos);
00544   }
00545 }

void Sector::activate ( const Vector player_pos  ) 

Definition at line 548 of file sector.cpp.

References _current, camera, deactivate(), FileSystem::dirname(), gameobjects, get_level(), MovingObject::get_pos(), scripting::global_vm, init_script, is_free_of_tiles(), log_warning, player, Camera::reset(), run_script(), sector_table, try_expose(), try_expose_me(), update_game_objects(), and Vector::y.

00549 {
00550   if(_current != this) {
00551     if(_current != NULL)
00552       _current->deactivate();
00553     _current = this;
00554 
00555     // register sectortable as sector in scripting
00556     HSQUIRRELVM vm = scripting::global_vm;
00557     sq_pushroottable(vm);
00558     sq_pushstring(vm, "sector", -1);
00559     sq_pushobject(vm, sector_table);
00560     if(SQ_FAILED(sq_createslot(vm, -3)))
00561       throw scripting::SquirrelError(vm, "Couldn't set sector in roottable");
00562     sq_pop(vm, 1);
00563 
00564     for(GameObjects::iterator i = gameobjects.begin();
00565         i != gameobjects.end(); ++i) {
00566       GameObject* object = *i;
00567 
00568       try_expose(object);
00569     }
00570   }
00571   try_expose_me();
00572 
00573 
00574   // two-player hack: move other players to main player's position
00575   // Maybe specify 2 spawnpoints in the level?
00576   for(GameObjects::iterator i = gameobjects.begin();
00577       i != gameobjects.end(); ++i) {
00578     Player* p = dynamic_cast<Player*>(*i);
00579     if (!p) continue;
00580 
00581     // spawn smalltux below spawnpoint
00582     if (!p->is_big()) {
00583       p->move(player_pos + Vector(0,32));
00584     } else {
00585       p->move(player_pos);
00586     }
00587 
00588     // spawning tux in the ground would kill him
00589     if(!is_free_of_tiles(p->get_bbox())) {
00590       log_warning << "Tried spawning Tux in solid matter. Compensating." << std::endl;
00591       Vector npos = p->get_bbox().p1;
00592       npos.y-=32;
00593       p->move(npos);
00594     }
00595   }
00596 
00597   camera->reset(player->get_pos());
00598   update_game_objects();
00599 
00600   //Run default.nut just before init script
00601   //Check to see if it's in a levelset (info file)
00602   std::string basedir = FileSystem::dirname(get_level()->filename);
00603   if(PHYSFS_exists((basedir + "/info").c_str())) {
00604     try {
00605       IFileStream in(basedir + "/default.nut");
00606       run_script(in, "default.nut");
00607     } catch(std::exception& ) {
00608       // doesn't exist or erroneous; do nothing
00609     }
00610   }
00611 
00612   // Run init script
00613   if(init_script != "") {
00614     std::istringstream in(init_script);
00615     run_script(in, "init-script");
00616   }
00617 }

void Sector::deactivate (  ) 

Definition at line 620 of file sector.cpp.

References _current, gameobjects, scripting::global_vm, try_unexpose(), and try_unexpose_me().

Referenced by activate(), TitleScreen::leave(), and ~Sector().

00621 {
00622   if(_current != this)
00623     return;
00624 
00625   // remove sector entry from global vm
00626   HSQUIRRELVM vm = scripting::global_vm;
00627   sq_pushroottable(vm);
00628   sq_pushstring(vm, "sector", -1);
00629   if(SQ_FAILED(sq_deleteslot(vm, -2, SQFalse)))
00630     throw scripting::SquirrelError(vm, "Couldn't unset sector in roottable");
00631   sq_pop(vm, 1);
00632 
00633   for(GameObjects::iterator i = gameobjects.begin();
00634       i != gameobjects.end(); ++i) {
00635     GameObject* object = *i;
00636 
00637     try_unexpose(object);
00638   }
00639 
00640   try_unexpose_me();
00641   _current = NULL;
00642 }

void Sector::update ( float  elapsed_time  ) 

Definition at line 653 of file sector.cpp.

References Player::check_bounds(), gameobjects, handle_collisions(), player, and update_game_objects().

Referenced by TitleScreen::update(), and GameSession::update().

00654 {
00655   player->check_bounds();
00656 
00657   /* update objects */
00658   for(GameObjects::iterator i = gameobjects.begin();
00659       i != gameobjects.end(); ++i) {
00660     GameObject* object = *i;
00661     if(!object->is_valid())
00662       continue;
00663 
00664     object->update(elapsed_time);
00665   }
00666 
00667   /* Handle all possible collisions. */
00668   handle_collisions();
00669   update_game_objects();
00670 }

void Sector::update_game_objects (  ) 

Definition at line 673 of file sector.cpp.

References before_object_add(), before_object_remove(), gameobjects, gameobjects_new, and solid_tilemaps.

Referenced by activate(), parse(), parse_old_format(), update(), and ~Sector().

00674 {
00676   for(std::vector<GameObject*>::iterator i = gameobjects.begin();
00677       i != gameobjects.end(); /* nothing */) {
00678     GameObject* object = *i;
00679 
00680     if(object->is_valid()) {
00681       ++i;
00682       continue;
00683     }
00684 
00685     before_object_remove(object);
00686 
00687     object->unref();
00688     i = gameobjects.erase(i);
00689   }
00690 
00691   /* add newly created objects */
00692   for(std::vector<GameObject*>::iterator i = gameobjects_new.begin();
00693       i != gameobjects_new.end(); ++i)
00694   {
00695     GameObject* object = *i;
00696 
00697     before_object_add(object);
00698 
00699     gameobjects.push_back(object);
00700   }
00701   gameobjects_new.clear();
00702 
00703   /* update solid_tilemaps list */
00704   //FIXME: this could be more efficient
00705   solid_tilemaps.clear();
00706   for(std::vector<GameObject*>::iterator i = gameobjects.begin();
00707       i != gameobjects.end(); ++i)
00708   {
00709     TileMap* tm = dynamic_cast<TileMap*>(*i);
00710     if (!tm) continue;
00711     if (tm->is_solid()) solid_tilemaps.push_back(tm);
00712   }
00713 
00714 }

void Sector::draw ( DrawingContext context  ) 

Definition at line 847 of file sector.cpp.

References ambient_light, camera, DrawingContext::draw_filled_rect(), draw_solids_only, gameobjects, Camera::get_translation(), TileMap::is_solid(), LAYER_FOREGROUND1, moving_objects, DrawingContext::pop_transform(), DrawingContext::push_transform(), DrawingContext::set_ambient_color(), DrawingContext::set_translation(), and show_collrects.

Referenced by TitleScreen::draw(), and GameSession::draw().

00848 {
00849   context.set_ambient_color( ambient_light );
00850   context.push_transform();
00851   context.set_translation(camera->get_translation());
00852 
00853   for(GameObjects::iterator i = gameobjects.begin();
00854       i != gameobjects.end(); ++i) {
00855     GameObject* object = *i;
00856     if(!object->is_valid())
00857       continue;
00858 
00859     if (draw_solids_only)
00860     {
00861       TileMap* tm = dynamic_cast<TileMap*>(object);
00862       if (tm && !tm->is_solid())
00863         continue;
00864     }
00865 
00866     object->draw(context);
00867   }
00868 
00869   if(show_collrects) {
00870     Color color(1.0f, 0.0f, 0.0f, 0.75f);
00871     for(MovingObjects::iterator i = moving_objects.begin();
00872         i != moving_objects.end(); ++i) {
00873       MovingObject* object = *i;
00874       const Rectf& rect = object->get_bbox();
00875 
00876       context.draw_filled_rect(rect, color, LAYER_FOREGROUND1 + 10);
00877     }
00878   }
00879 
00880   context.pop_transform();
00881 }

HSQUIRRELVM Sector::run_script ( std::istream &  in,
const std::string &  sourcename 
)

runs a script in the context of the sector (sector_table will be the roottable of this squirrel VM)

Definition at line 468 of file sector.cpp.

References scripting::compile_and_run(), scripting::create_thread(), scripting::global_vm, log_warning, name, scripting::object_to_vm(), scripts, and sector_table.

Referenced by activate(), Door::collision(), PushButton::collision(), PowerUp::collision(), WillOWisp::collision_player(), ScriptTrigger::event(), BadGuy::run_dead_script(), Switch::update(), and Ispy::update().

00469 {
00470   using namespace scripting;
00471 
00472   // garbage collect thread list
00473   for(ScriptList::iterator i = scripts.begin();
00474       i != scripts.end(); ) {
00475     HSQOBJECT& object = *i;
00476     HSQUIRRELVM vm = object_to_vm(object);
00477 
00478     if(sq_getvmstate(vm) != SQ_VMSTATE_SUSPENDED) {
00479       sq_release(global_vm, &object);
00480       i = scripts.erase(i);
00481       continue;
00482     }
00483 
00484     ++i;
00485   }
00486 
00487   HSQOBJECT object = create_thread(global_vm);
00488   scripts.push_back(object);
00489 
00490   HSQUIRRELVM vm = object_to_vm(object);
00491 
00492   // set sector_table as roottable for the thread
00493   sq_pushobject(vm, sector_table);
00494   sq_setroottable(vm);
00495 
00496   try {
00497     compile_and_run(vm, in, "Sector " + name + " - " + sourcename);
00498   } catch(std::exception& e) {
00499     log_warning << "Error running script: " << e.what() << std::endl;
00500   }
00501 
00502   return vm;
00503 }

void Sector::add_object ( GameObject object  ) 

adds a gameobject

Definition at line 506 of file sector.cpp.

References gameobjects, gameobjects_new, and RefCounter::ref().

Referenced by GhostTree::active_update(), FlyingSnowBall::active_update(), add_bullet(), add_smoke_cloud(), Block::break_me(), Coin::collect(), Firefly::collision(), Player::collision_solid(), Stumpy::collision_squished(), Snowman::collision_squished(), PoisonIvy::collision_squished(), MrTree::collision_squished(), MrBomb::collision_squished(), Thunderstorm::electrify(), Explosion::explode(), SkyDive::explode(), ShortFuse::explode(), Bomb::explode(), DartTrap::fire(), fix_old_tiles(), scripting::FloatingImage::FloatingImage(), Player::handle_horizontal_input(), Owl::initialize(), MrBomb::kill_fall(), Haywire::kill_fall(), Dispenser::launch_badguy(), parse(), parse_old_format(), Candle::puff_smoke(), Sector(), Player::set_bonus(), GhostTree::spawn_lantern(), GameSession::start_sequence(), EndSequenceFireworks::starting(), Mole::throw_rock(), Brick::try_break(), BonusBlock::try_open(), Wind::update(), SpecialRiser::update(), RainParticleSystem::update(), PneumaticPlatform::update(), Player::update(), CometParticleSystem::update(), and BicyclePlatform::update().

00507 {
00508   // make sure the object isn't already in the list
00509 #ifndef NDEBUG
00510   for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end();
00511       ++i) {
00512     assert(*i != object);
00513   }
00514   for(GameObjects::iterator i = gameobjects_new.begin();
00515       i != gameobjects_new.end(); ++i) {
00516     assert(*i != object);
00517   }
00518 #endif
00519 
00520   object->ref();
00521   gameobjects_new.push_back(object);
00522 }

void Sector::set_name ( const std::string &  name  )  [inline]

Definition at line 98 of file sector.hpp.

00099   { this->name = name; }

const std::string& Sector::get_name (  )  const [inline]

Definition at line 100 of file sector.hpp.

References name.

Referenced by Level::add_sector().

00101   { return name; }

bool Sector::inside ( const Rectf rectangle  )  const

tests if a given rectangle is inside the sector (a rectangle that is on top of the sector is considered inside)

Definition at line 1509 of file sector.cpp.

References Rectf::contains(), Rectf::p1, solid_tilemaps, and Vector::y.

01510 {
01511   for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
01512     TileMap* solids = *i;
01513 
01514     Rectf bbox = solids->get_bbox();
01515     bbox.p1.y = -INFINITY; // pretend the tilemap extends infinitely far upwards
01516 
01517     if (bbox.contains(rect))
01518       return true;
01519   }
01520   return false;
01521 }

void Sector::play_music ( MusicType  musictype  ) 

Definition at line 1469 of file sector.cpp.

References currentmusic, HERRING_MUSIC, HERRING_WARNING_MUSIC, LEVEL_MUSIC, music, SoundManager::play_music(), sound_manager, SoundManager::stop_music(), and TUX_INVINCIBLE_TIME_WARNING.

Referenced by Player::make_invincible(), GameSession::restart_level(), TitleScreen::setup(), GameSession::setup(), and GameSession::update().

01470 {
01471   currentmusic = type;
01472   switch(currentmusic) {
01473     case LEVEL_MUSIC:
01474       sound_manager->play_music(music);
01475       break;
01476     case HERRING_MUSIC:
01477       sound_manager->play_music("music/invincible.ogg");
01478       break;
01479     case HERRING_WARNING_MUSIC:
01480       sound_manager->stop_music(TUX_INVINCIBLE_TIME_WARNING);
01481       break;
01482     default:
01483       sound_manager->play_music("");
01484       break;
01485   }
01486 }

MusicType Sector::get_music_type (  ) 

Definition at line 1489 of file sector.cpp.

References currentmusic.

Referenced by GameSession::update().

01490 {
01491   return currentmusic;
01492 }

bool Sector::add_bullet ( const Vector pos,
const PlayerStatus player_status,
float  xm,
Direction  dir 
)

Definition at line 1443 of file sector.cpp.

References add_object(), PlayerStatus::bonus, bullets, FIRE_BONUS, ICE_BONUS, PlayerStatus::max_fire_bullets, PlayerStatus::max_ice_bullets, SoundManager::play(), player_status, and sound_manager.

Referenced by Player::handle_input().

01444 {
01445   // TODO remove this function and move these checks elsewhere...
01446 
01447   Bullet* new_bullet = 0;
01448   if((player_status->bonus == FIRE_BONUS &&
01449       (int)bullets.size() >= player_status->max_fire_bullets) ||
01450      (player_status->bonus == ICE_BONUS &&
01451       (int)bullets.size() >= player_status->max_ice_bullets))
01452     return false;
01453   new_bullet = new Bullet(pos, xm, dir, player_status->bonus);
01454   add_object(new_bullet);
01455 
01456   sound_manager->play("sounds/shoot.wav");
01457 
01458   return true;
01459 }

bool Sector::add_smoke_cloud ( const Vector pos  ) 

Definition at line 1462 of file sector.cpp.

References add_object().

01463 {
01464   add_object(new SmokeCloud(pos));
01465   return true;
01466 }

static Sector* Sector::current (  )  [inline, static]

get currently activated sector.

Reimplemented from Currenton< Sector >.

Definition at line 116 of file sector.hpp.

References _current.

Referenced by Totem::active_update(), Igel::active_update(), GhostTree::active_update(), FlyingSnowBall::active_update(), Player::adjust_height(), Block::break_me(), scripting::camera(), Player::check_bounds(), Coin::collect(), Door::collision(), PushButton::collision(), PowerUp::collision(), ParticleSystem_Interactive::collision(), OneUp::collision(), Firefly::collision(), WillOWisp::collision_player(), Player::collision_solid(), IceCrusher::collision_solid(), Stumpy::collision_squished(), Snowman::collision_squished(), PoisonIvy::collision_squished(), Owl::collision_squished(), MrTree::collision_squished(), MrBomb::collision_squished(), Player::draw(), InfoBlock::draw(), Background::draw(), Background::draw_image(), Yeti::drop_stalactite(), Electrifier::Electrifier(), Thunderstorm::electrify(), SecretAreaTrigger::event(), ScriptTrigger::event(), Explosion::explode(), SkyDive::explode(), ShortFuse::explode(), Bomb::explode(), DartTrap::fire(), scripting::FloatingImage::FloatingImage(), IceCrusher::found_victim(), Ispy::free_line_of_sight(), Physic::get_movement(), get_nearby_objects(), get_nearest_player(), InfoBlock::get_nearest_player(), BadGuy::get_nearest_player(), scripting::ghost(), scripting::gotoend(), scripting::grease(), Player::handle_horizontal_input(), Player::handle_input(), InfoBlock::hit(), Owl::initialize(), scripting::invincible(), Owl::is_above_player(), Player::kill(), MrBomb::kill_fall(), Haywire::kill_fall(), Dispenser::launch_badguy(), Player::make_invincible(), CaptainSnowball::might_climb(), BadGuy::might_fall(), scripting::mortal(), Candle::puff_smoke(), BadGuy::run_dead_script(), EndSequenceWalkRight::running(), EndSequenceWalkLeft::running(), Player::set_bonus(), TitleScreen::setup(), GameSession::setup(), GhostTree::spawn_lantern(), WeakBlock::spreadHit(), EndSequence::start(), EndSequenceFireworks::starting(), Mole::throw_rock(), Brick::try_break(), Player::try_grab(), BonusBlock::try_open(), Switch::update(), Wind::update(), SpriteParticle::update(), SpecialRiser::update(), SkullTile::update(), RainParticleSystem::update(), PneumaticPlatform::update(), Player::update(), Platform::update(), Particles::update(), OneUp::update(), MagicBlock::update(), LevelTime::update(), Ispy::update(), Fireworks::update(), Electrifier::update(), CometParticleSystem::update(), Bullet::update(), BicyclePlatform::update(), AmbientSound::update(), BadGuy::update(), scripting::validate_sector_player(), and scripting::whereami().

00117   { return _current; }

int Sector::get_total_badguys (  ) 

Get total number of badguys.

Definition at line 1495 of file sector.cpp.

References gameobjects.

01496 {
01497   int total_badguys = 0;
01498   for(GameObjects::iterator i = gameobjects.begin();
01499       i != gameobjects.end(); ++i) {
01500     BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
01501     if (badguy && badguy->countMe)
01502       total_badguys++;
01503   }
01504 
01505   return total_badguys;
01506 }

template<class T>
int Sector::get_total_count (  )  [inline]

Get total number of GameObjects of given type.

Definition at line 123 of file sector.hpp.

References gameobjects.

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   }

void Sector::collision_tilemap ( collision::Constraints constraints,
const Vector movement,
const Rectf dest,
MovingObject object 
) const

Definition at line 961 of file sector.cpp.

References Rect::bottom, check_collisions(), MovingObject::get_bbox(), Rectf::get_bottom(), Rectf::get_left(), Rectf::get_right(), Rectf::get_top(), Tile::getData(), Tile::is_slope(), Tile::is_solid(), Tile::is_unisolid(), Rect::left, collision::rectangle_aatriangle(), Rect::right, solid_tilemaps, Rect::top, AATriangle::vertical_flip(), and VERTICAL_FLIP.

Referenced by collision_static().

00964 {
00965   // calculate rectangle where the object will move
00966   float x1 = dest.get_left();
00967   float x2 = dest.get_right();
00968   float y1 = dest.get_top();
00969   float y2 = dest.get_bottom();
00970 
00971   for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
00972     TileMap* solids = *i;
00973 
00974     // test with all tiles in this rectangle
00975     Rect test_tiles = solids->get_tiles_overlapping(Rectf(x1, y1, x2, y2));
00976 
00977     for(int x = test_tiles.left; x < test_tiles.right; ++x) {
00978       for(int y = test_tiles.top; y < test_tiles.bottom; ++y) {
00979         const Tile* tile = solids->get_tile(x, y);
00980         if(!tile)
00981           continue;
00982         // skip non-solid tiles
00983         if(!tile->is_solid ())
00984           continue;
00985         Rectf tile_bbox = solids->get_tile_bbox(x, y);
00986 
00987         /* If the tile is a unisolid tile, the "is_solid()" function above
00988          * didn't do a thorough check. Calculate the position and (relative)
00989          * movement of the object and determine whether or not the tile is
00990          * solid with regard to those parameters. */
00991         if(tile->is_unisolid ()) {
00992           Vector relative_movement = movement
00993             - solids->get_movement(/* actual = */ true);
00994 
00995           if (!tile->is_solid (tile_bbox, object.get_bbox(), relative_movement))
00996             continue;
00997         } /* if (tile->is_unisolid ()) */
00998 
00999         if(tile->is_slope ()) { // slope tile
01000           AATriangle triangle;
01001           int slope_data = tile->getData();
01002           if (solids->get_drawing_effect() == VERTICAL_FLIP)
01003             slope_data = AATriangle::vertical_flip(slope_data);
01004           triangle = AATriangle(tile_bbox, slope_data);
01005 
01006           collision::rectangle_aatriangle(constraints, dest, triangle,
01007               solids->get_movement(/* actual = */ false));
01008         } else { // normal rectangular tile
01009           check_collisions(constraints, movement, dest, tile_bbox, NULL, NULL,
01010               solids->get_movement(/* actual = */ false));
01011         }
01012       }
01013     }
01014   }
01015 }

bool Sector::is_free_of_tiles ( const Rectf rect,
const bool  ignoreUnisolid = false 
) const

Checks if the specified rectangle is free of (solid) tiles.

Note that this does not include static objects, e.g. bonus blocks.

Definition at line 1365 of file sector.cpp.

References Rect::bottom, Tile::getAttributes(), Tile::getData(), Tile::is_slope(), Tile::is_unisolid(), Rect::left, collision::rectangle_aatriangle(), Rect::right, Tile::SOLID, solid_tilemaps, and Rect::top.

Referenced by activate(), is_free_of_movingstatics(), and is_free_of_statics().

01366 {
01367   using namespace collision;
01368 
01369   for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
01370     TileMap* solids = *i;
01371 
01372     // test with all tiles in this rectangle
01373     Rect test_tiles = solids->get_tiles_overlapping(rect);
01374 
01375     for(int x = test_tiles.left; x < test_tiles.right; ++x) {
01376       for(int y = test_tiles.top; y < test_tiles.bottom; ++y) {
01377         const Tile* tile = solids->get_tile(x, y);
01378         if(!tile) continue;
01379         if(!(tile->getAttributes() & Tile::SOLID))
01380           continue;
01381         if(tile->is_unisolid () && ignoreUnisolid)
01382           continue;
01383         if(tile->is_slope ()) {
01384           AATriangle triangle;
01385           Rectf tbbox = solids->get_tile_bbox(x, y);
01386           triangle = AATriangle(tbbox, tile->getData());
01387           Constraints constraints;
01388           if(!collision::rectangle_aatriangle(&constraints, rect, triangle))
01389             continue;
01390         }
01391         // We have a solid tile that overlaps the given rectangle.
01392         return false;
01393       }
01394     }
01395   }
01396 
01397   return true;
01398 }

bool Sector::is_free_of_statics ( const Rectf rect,
const MovingObject ignore_object = 0,
const bool  ignoreUnisolid = false 
) const

Checks if the specified rectangle is free of both 1.

) solid tiles and 2.) MovingObjects in COLGROUP_STATIC. Note that this does not include badguys or players.

Definition at line 1401 of file sector.cpp.

References COLGROUP_STATIC, collision::intersects(), is_free_of_tiles(), and moving_objects.

Referenced by TitleScreen::make_tux_jump(), and BadGuy::might_fall().

01402 {
01403   using namespace collision;
01404 
01405   if (!is_free_of_tiles(rect, ignoreUnisolid)) return false;
01406 
01407   for(MovingObjects::const_iterator i = moving_objects.begin();
01408       i != moving_objects.end(); ++i) {
01409     const MovingObject* moving_object = *i;
01410     if (moving_object == ignore_object) continue;
01411     if (!moving_object->is_valid()) continue;
01412     if (moving_object->get_group() == COLGROUP_STATIC) {
01413       if(intersects(rect, moving_object->get_bbox())) return false;
01414     }
01415   }
01416 
01417   return true;
01418 }

bool Sector::is_free_of_movingstatics ( const Rectf rect,
const MovingObject ignore_object = 0 
) const

Checks if the specified rectangle is free of both 1.

) solid tiles and 2.) MovingObjects in COLGROUP_STATIC, COLGROUP_MOVINGSTATIC or COLGROUP_MOVING. This includes badguys and players.

Definition at line 1421 of file sector.cpp.

References COLGROUP_MOVING, COLGROUP_MOVING_STATIC, COLGROUP_STATIC, collision::intersects(), is_free_of_tiles(), and moving_objects.

01422 {
01423   using namespace collision;
01424 
01425   if (!is_free_of_tiles(rect)) return false;
01426 
01427   for(MovingObjects::const_iterator i = moving_objects.begin();
01428       i != moving_objects.end(); ++i) {
01429     const MovingObject* moving_object = *i;
01430     if (moving_object == ignore_object) continue;
01431     if (!moving_object->is_valid()) continue;
01432     if ((moving_object->get_group() == COLGROUP_MOVING)
01433         || (moving_object->get_group() == COLGROUP_MOVING_STATIC)
01434         || (moving_object->get_group() == COLGROUP_STATIC)) {
01435       if(intersects(rect, moving_object->get_bbox())) return false;
01436     }
01437   }
01438 
01439   return true;
01440 }

std::vector<Player*> Sector::get_players (  )  [inline]

returns a list of players currently in the sector

Definition at line 159 of file sector.hpp.

References player.

Referenced by GameSession::force_ghost_mode(), get_nearby_objects(), get_nearest_player(), InfoBlock::get_nearest_player(), GameSession::set_editmode(), GameSession::start_sequence(), GameSession::update(), Platform::update(), and Ispy::update().

00159                                    {
00160     return std::vector<Player*>(1, this->player);
00161   }

Player * Sector::get_nearest_player ( const Vector pos  ) 

Definition at line 1598 of file sector.cpp.

References current(), and get_players().

Referenced by Owl::collision_squished(), IceCrusher::found_victim(), get_nearest_player(), BadGuy::get_nearest_player(), and Owl::is_above_player().

01599 {
01600   Player *nearest_player = NULL;
01601   float nearest_dist = std::numeric_limits<float>::max();
01602 
01603   std::vector<Player*> players = Sector::current()->get_players();
01604   for (std::vector<Player*>::iterator playerIter = players.begin();
01605       playerIter != players.end();
01606       ++playerIter)
01607   {
01608     Player *this_player = *playerIter;
01609     if (this_player->is_dying() || this_player->is_dead())
01610       continue;
01611 
01612     float this_dist = this_player->get_bbox ().distance(pos);
01613 
01614     if (this_dist < nearest_dist) {
01615       nearest_player = this_player;
01616       nearest_dist = this_dist;
01617     }
01618   }
01619 
01620   return nearest_player;
01621 } /* Player *get_nearest_player */

Player* Sector::get_nearest_player ( const Rectf pos  )  [inline]

Definition at line 163 of file sector.hpp.

References ANCHOR_MIDDLE, get_anchor_pos(), and get_nearest_player().

00164   {
00165     return (get_nearest_player (get_anchor_pos (pos, ANCHOR_MIDDLE)));
00166   }

std::vector< MovingObject * > Sector::get_nearby_objects ( const Vector center,
float  max_distance 
)

Definition at line 1624 of file sector.cpp.

References current(), get_players(), and moving_objects.

Referenced by Explosion::explode().

01625 {
01626   std::vector<MovingObject*> ret;
01627   std::vector<Player*> players = Sector::current()->get_players();
01628 
01629   for (size_t i = 0; i < players.size (); i++) {
01630     float distance = players[i]->get_bbox ().distance (center);
01631     if (distance <= max_distance)
01632       ret.push_back (players[i]);
01633   }
01634 
01635   for (size_t i = 0; i < moving_objects.size (); i++) {
01636     float distance = moving_objects[i]->get_bbox ().distance (center);
01637     if (distance <= max_distance)
01638       ret.push_back (moving_objects[i]);
01639   }
01640 
01641   return (ret);
01642 }

Rectf Sector::get_active_region (  ) 

Definition at line 645 of file sector.cpp.

References camera, Camera::get_translation(), SCREEN_HEIGHT, and SCREEN_WIDTH.

00646 {
00647   return Rectf(
00648     camera->get_translation() - Vector(1600, 1200),
00649     camera->get_translation() + Vector(1600, 1200) + Vector(SCREEN_WIDTH,SCREEN_HEIGHT));
00650 }

float Sector::get_width (  )  const

returns the width (in px) of a sector)

Definition at line 1524 of file sector.cpp.

References solid_tilemaps.

Referenced by InfoBlock::draw(), Camera::keep_in_bounds(), TitleScreen::make_tux_jump(), and Camera::update_scroll_normal().

01525 {
01526   float width = 0;
01527   for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin();
01528       i != solid_tilemaps.end(); i++) {
01529     TileMap* solids = *i;
01530     width = std::max(width, solids->get_bbox().get_right());
01531   }
01532 
01533   return width;
01534 }

float Sector::get_height (  )  const

returns the height (in px) of a sector)

Definition at line 1537 of file sector.cpp.

References solid_tilemaps.

Referenced by Camera::keep_in_bounds(), FlipLevelTransformer::transform_sector(), and Camera::update_scroll_normal().

01538 {
01539   float height = 0;
01540   for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin();
01541       i != solid_tilemaps.end(); i++) {
01542     TileMap* solids = *i;
01543     height = std::max(height, solids->get_bbox().get_bottom());
01544   }
01545 
01546   return height;
01547 }

void Sector::change_solid_tiles ( uint32_t  old_tile_id,
uint32_t  new_tile_id 
)

globally changes solid tilemaps' tile ids

Definition at line 1550 of file sector.cpp.

References solid_tilemaps.

Referenced by Electrifier::Electrifier(), and Electrifier::update().

01551 {
01552   for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
01553     TileMap* solids = *i;
01554     solids->change_all(old_tile_id, new_tile_id);
01555   }
01556 }

void Sector::set_ambient_light ( float  red,
float  green,
float  blue 
) [virtual]

get/set color of ambient light

Implements scripting::SSector.

Definition at line 1559 of file sector.cpp.

References ambient_light, Color::blue, Color::green, and Color::red.

01560 {
01561   ambient_light.red = red;
01562   ambient_light.green = green;
01563   ambient_light.blue = blue;
01564 }

float Sector::get_ambient_red (  )  [virtual]

Implements scripting::SSector.

Definition at line 1567 of file sector.cpp.

References ambient_light, and Color::red.

01568 {
01569   return ambient_light.red;
01570 }

float Sector::get_ambient_green (  )  [virtual]

Implements scripting::SSector.

Definition at line 1573 of file sector.cpp.

References ambient_light, and Color::green.

01574 {
01575   return ambient_light.green;
01576 }

float Sector::get_ambient_blue (  )  [virtual]

Implements scripting::SSector.

Definition at line 1579 of file sector.cpp.

References ambient_light, and Color::blue.

01580 {
01581   return ambient_light.blue;
01582 }

void Sector::set_gravity ( float  gravity  )  [virtual]

set gravity throughout sector

Implements scripting::SSector.

Definition at line 1585 of file sector.cpp.

References log_warning.

01586 {
01587   log_warning << "Changing a Sector's gravitational constant might have unforeseen side-effects" << std::endl;
01588   this->gravity = gravity;
01589 }

float Sector::get_gravity (  )  const

Definition at line 1592 of file sector.cpp.

References gravity.

Referenced by FlyingSnowBall::active_update(), and Physic::get_movement().

01593 {
01594   return gravity;
01595 }

uint32_t Sector::collision_tile_attributes ( const Rectf dest  )  const [private]

Definition at line 1018 of file sector.cpp.

References Rect::bottom, Tile::getAttributes(), Tile::ICE, Rect::left, Rectf::p1, Rectf::p2, Rect::right, SHIFT_DELTA, solid_tilemaps, Rect::top, Vector::x, and Vector::y.

Referenced by handle_collisions().

01019 {
01020   float x1 = dest.p1.x;
01021   float y1 = dest.p1.y;
01022   float x2 = dest.p2.x;
01023   float y2 = dest.p2.y;
01024 
01025   uint32_t result = 0;
01026   for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
01027     TileMap* solids = *i;
01028 
01029     // test with all tiles in this rectangle
01030     Rect test_tiles = solids->get_tiles_overlapping(Rectf(x1, y1, x2, y2));
01031     // For ice (only), add a little fudge to recognize tiles Tux is standing on.
01032     Rect test_tiles_ice = solids->get_tiles_overlapping(Rectf(x1, y1, x2, y2 + SHIFT_DELTA));
01033 
01034     for(int x = test_tiles.left; x < test_tiles.right; ++x) {
01035       int y;
01036       for(y = test_tiles.top; y < test_tiles.bottom; ++y) {
01037         const Tile* tile = solids->get_tile(x, y);
01038         if(!tile)
01039           continue;
01040         result |= tile->getAttributes();
01041       }
01042       for(; y < test_tiles_ice.bottom; ++y) {
01043         const Tile* tile = solids->get_tile(x, y);
01044         if(!tile)
01045           continue;
01046         result |= (tile->getAttributes() & Tile::ICE);
01047       }
01048     }
01049   }
01050 
01051   return result;
01052 }

void Sector::before_object_remove ( GameObject object  )  [private]

Definition at line 796 of file sector.cpp.

References _current, bullets, moving_objects, portables, and try_unexpose().

Referenced by update_game_objects(), and ~Sector().

00797 {
00798   Portable* portable = dynamic_cast<Portable*> (object);
00799   if(portable != NULL) {
00800     portables.erase(std::find(portables.begin(), portables.end(), portable));
00801   }
00802   Bullet* bullet = dynamic_cast<Bullet*> (object);
00803   if(bullet != NULL) {
00804     bullets.erase(std::find(bullets.begin(), bullets.end(), bullet));
00805   }
00806   MovingObject* moving_object = dynamic_cast<MovingObject*> (object);
00807   if(moving_object != NULL) {
00808     moving_objects.erase(
00809       std::find(moving_objects.begin(), moving_objects.end(), moving_object));
00810   }
00811 
00812   if(_current == this)
00813     try_unexpose(object);
00814 }

bool Sector::before_object_add ( GameObject object  )  [private]

Definition at line 717 of file sector.cpp.

References _current, bullets, camera, effect, TileMap::is_solid(), log_warning, moving_objects, player, portables, solid_tilemaps, and try_expose().

Referenced by update_game_objects().

00718 {
00719   Bullet* bullet = dynamic_cast<Bullet*> (object);
00720   if(bullet != NULL) {
00721     bullets.push_back(bullet);
00722   }
00723 
00724   MovingObject* movingobject = dynamic_cast<MovingObject*> (object);
00725   if(movingobject != NULL) {
00726     moving_objects.push_back(movingobject);
00727   }
00728 
00729   Portable* portable = dynamic_cast<Portable*> (object);
00730   if(portable != NULL) {
00731     portables.push_back(portable);
00732   }
00733 
00734   TileMap* tilemap = dynamic_cast<TileMap*> (object);
00735   if(tilemap != NULL && tilemap->is_solid()) {
00736     solid_tilemaps.push_back(tilemap);
00737   }
00738 
00739   Camera* camera = dynamic_cast<Camera*> (object);
00740   if(camera != NULL) {
00741     if(this->camera != 0) {
00742       log_warning << "Multiple cameras added. Ignoring" << std::endl;
00743       return false;
00744     }
00745     this->camera = camera;
00746   }
00747 
00748   Player* player = dynamic_cast<Player*> (object);
00749   if(player != NULL) {
00750     if(this->player != 0) {
00751       log_warning << "Multiple players added. Ignoring" << std::endl;
00752       return false;
00753     }
00754     this->player = player;
00755   }
00756 
00757   DisplayEffect* effect = dynamic_cast<DisplayEffect*> (object);
00758   if(effect != NULL) {
00759     if(this->effect != 0) {
00760       log_warning << "Multiple DisplayEffects added. Ignoring" << std::endl;
00761       return false;
00762     }
00763     this->effect = effect;
00764   }
00765 
00766   if(_current == this) {
00767     try_expose(object);
00768   }
00769 
00770   return true;
00771 }

void Sector::try_expose ( GameObject object  )  [private]

Definition at line 774 of file sector.cpp.

References ScriptInterface::expose(), scripting::global_vm, and sector_table.

Referenced by activate(), and before_object_add().

00775 {
00776   ScriptInterface* object_ = dynamic_cast<ScriptInterface*> (object);
00777   if(object_ != NULL) {
00778     HSQUIRRELVM vm = scripting::global_vm;
00779     sq_pushobject(vm, sector_table);
00780     object_->expose(vm, -1);
00781     sq_pop(vm, 1);
00782   }
00783 }

void Sector::try_unexpose ( GameObject object  )  [private]

Definition at line 817 of file sector.cpp.

References scripting::global_vm, log_warning, sector_table, and ScriptInterface::unexpose().

Referenced by before_object_remove(), and deactivate().

00818 {
00819   ScriptInterface* object_ = dynamic_cast<ScriptInterface*> (object);
00820   if(object_ != NULL) {
00821     HSQUIRRELVM vm = scripting::global_vm;
00822     SQInteger oldtop = sq_gettop(vm);
00823     sq_pushobject(vm, sector_table);
00824     try {
00825       object_->unexpose(vm, -1);
00826     } catch(std::exception& e) {
00827       log_warning << "Couldn't unregister object: " << e.what() << std::endl;
00828     }
00829     sq_settop(vm, oldtop);
00830   }
00831 }

void Sector::try_expose_me (  )  [private]

Definition at line 786 of file sector.cpp.

References scripting::expose_object(), scripting::global_vm, and sector_table.

Referenced by activate().

00787 {
00788   HSQUIRRELVM vm = scripting::global_vm;
00789   sq_pushobject(vm, sector_table);
00790   scripting::SSector* this_ = static_cast<scripting::SSector*> (this);
00791   expose_object(vm, -1, this_, "settings", false);
00792   sq_pop(vm, 1);
00793 }

void Sector::try_unexpose_me (  )  [private]

Definition at line 834 of file sector.cpp.

References scripting::global_vm, log_warning, sector_table, and scripting::unexpose_object().

Referenced by deactivate().

00835 {
00836   HSQUIRRELVM vm = scripting::global_vm;
00837   SQInteger oldtop = sq_gettop(vm);
00838   sq_pushobject(vm, sector_table);
00839   try {
00840     scripting::unexpose_object(vm, -1, "settings");
00841   } catch(std::exception& e) {
00842     log_warning << "Couldn't unregister object: " << e.what() << std::endl;
00843   }
00844   sq_settop(vm, oldtop);
00845 }

void Sector::handle_collisions (  )  [private]

Checks for all possible collisions.

And calls the collision_handlers, which the collision_objects provide for this case (or not).

Definition at line 1251 of file sector.cpp.

References COLGROUP_MOVING, COLGROUP_MOVING_ONLY_STATIC, COLGROUP_MOVING_STATIC, COLGROUP_TOUCHABLE, collision_object(), collision_static_constrains(), collision_tile_attributes(), Tile::FIRST_INTERESTING_FLAG, get_hit_normal(), collision::intersects(), MAX_SPEED, moving_objects, Vector::norm(), Vector::unit(), Vector::x, and Vector::y.

Referenced by update().

01252 {
01253   using namespace collision;
01254 
01255   // calculate destination positions of the objects
01256   for(MovingObjects::iterator i = moving_objects.begin();
01257       i != moving_objects.end(); ++i) {
01258     MovingObject* moving_object = *i;
01259     Vector mov = moving_object->get_movement();
01260 
01261     // make sure movement is never faster than MAX_SPEED. Norm is pretty fat, so two addl. checks are done before.
01262     if (((mov.x > MAX_SPEED * M_SQRT1_2) || (mov.y > MAX_SPEED * M_SQRT1_2)) && (mov.norm() > MAX_SPEED)) {
01263       moving_object->movement = mov.unit() * MAX_SPEED;
01264       //log_debug << "Temporarily reduced object's speed of " << mov.norm() << " to " << moving_object->movement.norm() << "." << std::endl;
01265     }
01266 
01267     moving_object->dest = moving_object->get_bbox();
01268     moving_object->dest.move(moving_object->get_movement());
01269   }
01270 
01271   // part1: COLGROUP_MOVING vs COLGROUP_STATIC and tilemap
01272   for(MovingObjects::iterator i = moving_objects.begin();
01273       i != moving_objects.end(); ++i) {
01274     MovingObject* moving_object = *i;
01275     if((moving_object->get_group() != COLGROUP_MOVING
01276         && moving_object->get_group() != COLGROUP_MOVING_STATIC
01277         && moving_object->get_group() != COLGROUP_MOVING_ONLY_STATIC)
01278        || !moving_object->is_valid())
01279       continue;
01280 
01281     collision_static_constrains(*moving_object);
01282   }
01283 
01284   // part2: COLGROUP_MOVING vs tile attributes
01285   for(MovingObjects::iterator i = moving_objects.begin();
01286       i != moving_objects.end(); ++i) {
01287     MovingObject* moving_object = *i;
01288     if((moving_object->get_group() != COLGROUP_MOVING
01289         && moving_object->get_group() != COLGROUP_MOVING_STATIC
01290         && moving_object->get_group() != COLGROUP_MOVING_ONLY_STATIC)
01291        || !moving_object->is_valid())
01292       continue;
01293 
01294     uint32_t tile_attributes = collision_tile_attributes(moving_object->dest);
01295     if(tile_attributes >= Tile::FIRST_INTERESTING_FLAG) {
01296       moving_object->collision_tile(tile_attributes);
01297     }
01298   }
01299 
01300   // part2.5: COLGROUP_MOVING vs COLGROUP_TOUCHABLE
01301   for(MovingObjects::iterator i = moving_objects.begin();
01302       i != moving_objects.end(); ++i) {
01303     MovingObject* moving_object = *i;
01304     if((moving_object->get_group() != COLGROUP_MOVING
01305         && moving_object->get_group() != COLGROUP_MOVING_STATIC)
01306        || !moving_object->is_valid())
01307       continue;
01308 
01309     for(MovingObjects::iterator i2 = moving_objects.begin();
01310         i2 != moving_objects.end(); ++i2) {
01311       MovingObject* moving_object_2 = *i2;
01312       if(moving_object_2->get_group() != COLGROUP_TOUCHABLE
01313          || !moving_object_2->is_valid())
01314         continue;
01315 
01316       if(intersects(moving_object->dest, moving_object_2->dest)) {
01317         Vector normal;
01318         CollisionHit hit;
01319         get_hit_normal(moving_object->dest, moving_object_2->dest,
01320                        hit, normal);
01321         if(!moving_object->collides(*moving_object_2, hit))
01322           continue;
01323         if(!moving_object_2->collides(*moving_object, hit))
01324           continue;
01325 
01326         moving_object->collision(*moving_object_2, hit);
01327         moving_object_2->collision(*moving_object, hit);
01328       }
01329     }
01330   }
01331 
01332   // part3: COLGROUP_MOVING vs COLGROUP_MOVING
01333   for(MovingObjects::iterator i = moving_objects.begin();
01334       i != moving_objects.end(); ++i) {
01335     MovingObject* moving_object = *i;
01336 
01337     if((moving_object->get_group() != COLGROUP_MOVING
01338         && moving_object->get_group() != COLGROUP_MOVING_STATIC)
01339        || !moving_object->is_valid())
01340       continue;
01341 
01342     for(MovingObjects::iterator i2 = i+1;
01343         i2 != moving_objects.end(); ++i2) {
01344       MovingObject* moving_object_2 = *i2;
01345       if((moving_object_2->get_group() != COLGROUP_MOVING
01346           && moving_object_2->get_group() != COLGROUP_MOVING_STATIC)
01347          || !moving_object_2->is_valid())
01348         continue;
01349 
01350       collision_object(moving_object, moving_object_2);
01351     }
01352   }
01353 
01354   // apply object movement
01355   for(MovingObjects::iterator i = moving_objects.begin();
01356       i != moving_objects.end(); ++i) {
01357     MovingObject* moving_object = *i;
01358 
01359     moving_object->bbox = moving_object->dest;
01360     moving_object->movement = Vector(0, 0);
01361   }
01362 }

void Sector::collision_object ( MovingObject object1,
MovingObject object2 
) const [private]

Does collision detection between 2 objects and does instant collision response handling in case of a collision.

Definition at line 1085 of file sector.cpp.

References CollisionHit::bottom, MovingObject::collides(), MovingObject::collision(), CONTINUE, DELTA, MovingObject::dest, FORCE_MOVE, get_hit_normal(), collision::intersects(), CollisionHit::left, Rectf::move(), CollisionHit::right, and CollisionHit::top.

Referenced by handle_collisions().

01086 {
01087   using namespace collision;
01088 
01089   const Rectf& r1 = object1->dest;
01090   const Rectf& r2 = object2->dest;
01091 
01092   CollisionHit hit;
01093   if(intersects(object1->dest, object2->dest)) {
01094     Vector normal;
01095     get_hit_normal(r1, r2, hit, normal);
01096 
01097     if(!object1->collides(*object2, hit))
01098       return;
01099     std::swap(hit.left, hit.right);
01100     std::swap(hit.top, hit.bottom);
01101     if(!object2->collides(*object1, hit))
01102       return;
01103     std::swap(hit.left, hit.right);
01104     std::swap(hit.top, hit.bottom);
01105 
01106     HitResponse response1 = object1->collision(*object2, hit);
01107     std::swap(hit.left, hit.right);
01108     std::swap(hit.top, hit.bottom);
01109     HitResponse response2 = object2->collision(*object1, hit);
01110     if(response1 == CONTINUE && response2 == CONTINUE) {
01111       normal *= (0.5 + DELTA);
01112       object1->dest.move(-normal);
01113       object2->dest.move(normal);
01114     } else if (response1 == CONTINUE && response2 == FORCE_MOVE) {
01115       normal *= (1 + DELTA);
01116       object1->dest.move(-normal);
01117     } else if (response1 == FORCE_MOVE && response2 == CONTINUE) {
01118       normal *= (1 + DELTA);
01119       object2->dest.move(normal);
01120     }
01121   }
01122 }

void Sector::collision_static ( collision::Constraints constraints,
const Vector movement,
const Rectf dest,
MovingObject object 
) [private]

Does collision detection of an object against all other static objects (and the tilemap) in the level.

Collision response is done for the first hit in time. (other hits get ignored, the function should be called repeatedly to resolve those)

returns true if the collision detection should be aborted for this object (because of ABORT_MOVE in the collision response or no collisions)

Definition at line 1125 of file sector.cpp.

References check_collisions(), COLGROUP_MOVING_STATIC, COLGROUP_STATIC, collision_tilemap(), and moving_objects.

Referenced by collision_static_constrains().

01128 {
01129   collision_tilemap(constraints, movement, dest, object);
01130 
01131   // collision with other (static) objects
01132   for(MovingObjects::iterator i = moving_objects.begin();
01133       i != moving_objects.end(); ++i) {
01134     MovingObject* moving_object = *i;
01135     if(moving_object->get_group() != COLGROUP_STATIC
01136        && moving_object->get_group() != COLGROUP_MOVING_STATIC)
01137       continue;
01138     if(!moving_object->is_valid())
01139       continue;
01140 
01141     if(moving_object != &object)
01142       check_collisions(constraints, movement, dest, moving_object->bbox,
01143                        &object, moving_object);
01144   }
01145 }

void Sector::collision_static_constrains ( MovingObject object  )  [private]

Definition at line 1148 of file sector.cpp.

References CollisionHit::bottom, MovingObject::collision_solid(), collision_static(), CollisionHit::crush, DELTA, MovingObject::dest, MovingObject::get_bbox(), Rectf::get_height(), MovingObject::get_movement(), Rectf::get_width(), CollisionHit::left, Rectf::move(), Rectf::p1, Rectf::p2, CollisionHit::right, SHIFT_DELTA, CollisionHit::top, Vector::x, and Vector::y.

Referenced by handle_collisions().

01149 {
01150   using namespace collision;
01151   float infinity = (std::numeric_limits<float>::has_infinity ? std::numeric_limits<float>::infinity() : std::numeric_limits<float>::max());
01152 
01153   Constraints constraints;
01154   Vector movement = object.get_movement();
01155   Rectf& dest = object.dest;
01156 
01157   for(int i = 0; i < 2; ++i) {
01158     collision_static(&constraints, Vector(0, movement.y), dest, object);
01159     if(!constraints.has_constraints())
01160       break;
01161 
01162     // apply calculated horizontal constraints
01163     if(constraints.get_position_bottom() < infinity) {
01164       float height = constraints.get_height ();
01165       if(height < object.get_bbox().get_height()) {
01166         // we're crushed, but ignore this for now, we'll get this again
01167         // later if we're really crushed or things will solve itself when
01168         // looking at the vertical constraints
01169       }
01170       dest.p2.y = constraints.get_position_bottom() - DELTA;
01171       dest.p1.y = dest.p2.y - object.get_bbox().get_height();
01172     } else if(constraints.get_position_top() > -infinity) {
01173       dest.p1.y = constraints.get_position_top() + DELTA;
01174       dest.p2.y = dest.p1.y + object.get_bbox().get_height();
01175     }
01176   }
01177   if(constraints.has_constraints()) {
01178     if(constraints.hit.bottom) {
01179       dest.move(constraints.ground_movement);
01180     }
01181     if(constraints.hit.top || constraints.hit.bottom) {
01182       constraints.hit.left = false;
01183       constraints.hit.right = false;
01184       object.collision_solid(constraints.hit);
01185     }
01186   }
01187 
01188   constraints = Constraints();
01189   for(int i = 0; i < 2; ++i) {
01190     collision_static(&constraints, movement, dest, object);
01191     if(!constraints.has_constraints())
01192       break;
01193 
01194     // apply calculated vertical constraints
01195     float width = constraints.get_width ();
01196     if(width < infinity) {
01197       if(width + SHIFT_DELTA < object.get_bbox().get_width()) {
01198 #if 0
01199         printf("Object %p crushed horizontally... L:%f R:%f\n", &object,
01200                constraints.get_position_left(), constraints.get_position_right());
01201 #endif
01202         CollisionHit h;
01203         h.left = true;
01204         h.right = true;
01205         h.crush = true;
01206         object.collision_solid(h);
01207       } else {
01208         float xmid = constraints.get_x_midpoint ();
01209         dest.p1.x = xmid - object.get_bbox().get_width()/2;
01210         dest.p2.x = xmid + object.get_bbox().get_width()/2;
01211       }
01212     } else if(constraints.get_position_right() < infinity) {
01213       dest.p2.x = constraints.get_position_right() - DELTA;
01214       dest.p1.x = dest.p2.x - object.get_bbox().get_width();
01215     } else if(constraints.get_position_left() > -infinity) {
01216       dest.p1.x = constraints.get_position_left() + DELTA;
01217       dest.p2.x = dest.p1.x + object.get_bbox().get_width();
01218     }
01219   }
01220 
01221   if(constraints.has_constraints()) {
01222     if( constraints.hit.left || constraints.hit.right
01223         || constraints.hit.top || constraints.hit.bottom
01224         || constraints.hit.crush )
01225       object.collision_solid(constraints.hit);
01226   }
01227 
01228   // an extra pass to make sure we're not crushed horizontally
01229   constraints = Constraints();
01230   collision_static(&constraints, movement, dest, object);
01231   if(constraints.get_position_bottom() < infinity) {
01232     float height = constraints.get_height ();
01233     if(height + SHIFT_DELTA < object.get_bbox().get_height()) {
01234 #if 0
01235       printf("Object %p crushed vertically...\n", &object);
01236 #endif
01237       CollisionHit h;
01238       h.top = true;
01239       h.bottom = true;
01240       h.crush = true;
01241       object.collision_solid(h);
01242     }
01243   }
01244 }

GameObject * Sector::parse_object ( const std::string &  name,
const Reader lisp 
) [private]

Definition at line 147 of file sector.cpp.

References camera, ObjectFactory::create(), ObjectFactory::instance(), log_warning, CloudParticleSystem::parse(), GhostParticleSystem::parse(), CometParticleSystem::parse(), RainParticleSystem::parse(), SnowParticleSystem::parse(), and Camera::parse().

Referenced by parse(), and parse_old_format().

00148 {
00149   if(name == "camera") {
00150     Camera* camera = new Camera(this, "Camera");
00151     camera->parse(reader);
00152     return camera;
00153   } else if(name == "particles-snow") {
00154     SnowParticleSystem* partsys = new SnowParticleSystem();
00155     partsys->parse(reader);
00156     return partsys;
00157   } else if(name == "particles-rain") {
00158     RainParticleSystem* partsys = new RainParticleSystem();
00159     partsys->parse(reader);
00160     return partsys;
00161   } else if(name == "particles-comets") {
00162     CometParticleSystem* partsys = new CometParticleSystem();
00163     partsys->parse(reader);
00164     return partsys;
00165   } else if(name == "particles-ghosts") {
00166     GhostParticleSystem* partsys = new GhostParticleSystem();
00167     partsys->parse(reader);
00168     return partsys;
00169   } else if(name == "particles-clouds") {
00170     CloudParticleSystem* partsys = new CloudParticleSystem();
00171     partsys->parse(reader);
00172     return partsys;
00173   } else if(name == "money") { // for compatibility with old maps
00174     return new Jumpy(reader);
00175   } else {
00176     try {
00177       return ObjectFactory::instance().create(name, reader);
00178     } catch(std::exception& e) {
00179       log_warning << e.what() << "" << std::endl;
00180       return 0;
00181     }
00182   }
00183 }

void Sector::fix_old_tiles (  )  [private]

Definition at line 404 of file sector.cpp.

References add_object(), Tile::BRICK, Tile::COIN, Tile::FULLBOX, gameobjects, Tile::getAttributes(), Tile::getData(), Tile::GOAL, solid_tilemaps, and Vector::x.

Referenced by parse(), and parse_old_format().

00405 {
00406   for(std::list<TileMap*>::iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
00407     TileMap* solids = *i;
00408     for(size_t x=0; x < solids->get_width(); ++x) {
00409       for(size_t y=0; y < solids->get_height(); ++y) {
00410         uint32_t    id   = solids->get_tile_id(x, y);
00411         const Tile *tile = solids->get_tile(x, y);
00412         Vector pos = solids->get_tile_position(x, y);
00413 
00414         if(id == 112) {
00415           add_object(new InvisibleBlock(pos));
00416           solids->change(x, y, 0);
00417         } else if(tile->getAttributes() & Tile::COIN) {
00418           add_object(new Coin(pos, solids));
00419           solids->change(x, y, 0);
00420         } else if(tile->getAttributes() & Tile::FULLBOX) {
00421           add_object(new BonusBlock(pos, tile->getData()));
00422           solids->change(x, y, 0);
00423         } else if(tile->getAttributes() & Tile::BRICK) {
00424           add_object(new Brick(pos, tile->getData()));
00425           solids->change(x, y, 0);
00426         } else if(tile->getAttributes() & Tile::GOAL) {
00427           std::string sequence = tile->getData() == 0 ? "endsequence" : "stoptux";
00428           add_object(new SequenceTrigger(pos, sequence));
00429           solids->change(x, y, 0);
00430         }
00431       }
00432     }
00433   }
00434 
00435   // add lights for special tiles
00436   for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); i++) {
00437     TileMap* tm = dynamic_cast<TileMap*>(*i);
00438     if (!tm) continue;
00439     for(size_t x=0; x < tm->get_width(); ++x) {
00440       for(size_t y=0; y < tm->get_height(); ++y) {
00441         uint32_t id = tm->get_tile_id(x, y);
00442         Vector pos = tm->get_tile_position(x, y);
00443         Vector center = pos + Vector(16, 16);
00444 
00445         // torch
00446         if (id == 1517) {
00447           float pseudo_rnd = (float)((int)pos.x % 10) / 10;
00448           add_object(new PulsingLight(center, 1.0f + pseudo_rnd, 0.9f, 1.0f, Color(1.0f, 1.0f, 0.6f, 1.0f)));
00449         }
00450         // lava or lavaflow
00451         if ((id == 173) || (id == 1700) || (id == 1705) || (id == 1706)) {
00452           // space lights a bit
00453           if ((((tm->get_tile_id(x-1, y)) != tm->get_tile_id(x,y))
00454                && (tm->get_tile_id(x, y-1) != tm->get_tile_id(x,y)))
00455               || ((x % 3 == 0) && (y % 3 == 0))) {
00456             float pseudo_rnd = (float)((int)pos.x % 10) / 10;
00457             add_object(new PulsingLight(center, 1.0f + pseudo_rnd, 0.8f, 1.0f, Color(1.0f, 0.3f, 0.0f, 1.0f)));
00458           }
00459         }
00460 
00461       }
00462     }
00463   }
00464 
00465 }

Sector& Sector::operator= ( const Sector  )  [private]


Member Data Documentation

Sector * Sector::_current [static, private]

Definition at line 248 of file sector.hpp.

Referenced by activate(), before_object_add(), before_object_remove(), current(), and deactivate().

Level* Sector::level [private]

Parent level containing this sector.

Definition at line 250 of file sector.hpp.

Referenced by get_level(), and parse_old_format().

std::string Sector::name [private]

Definition at line 252 of file sector.hpp.

Referenced by get_name(), parse(), parse_old_format(), and run_script().

std::vector<Bullet*> Sector::bullets [private]

Definition at line 254 of file sector.hpp.

Referenced by add_bullet(), before_object_add(), and before_object_remove().

std::string Sector::init_script [private]

Definition at line 256 of file sector.hpp.

Referenced by activate(), and parse().

GameObjects Sector::gameobjects_new [private]

container for newly created objects, they'll be added in Sector::update

Definition at line 259 of file sector.hpp.

Referenced by add_object(), update_game_objects(), and ~Sector().

MusicType Sector::currentmusic [private]

Definition at line 261 of file sector.hpp.

Referenced by get_music_type(), and play_music().

HSQOBJECT Sector::sector_table [private]

Definition at line 263 of file sector.hpp.

Referenced by activate(), run_script(), Sector(), try_expose(), try_expose_me(), try_unexpose(), try_unexpose_me(), and ~Sector().

ScriptList Sector::scripts [private]

Definition at line 266 of file sector.hpp.

Referenced by run_script(), and ~Sector().

Color Sector::ambient_light [private]

Definition at line 268 of file sector.hpp.

Referenced by draw(), get_ambient_blue(), get_ambient_green(), get_ambient_red(), parse(), and set_ambient_light().

bool Sector::show_collrects [static]

show collision rectangles of moving objects (for debugging)

Definition at line 272 of file sector.hpp.

Referenced by scripting::debug_collrects(), and draw().

bool Sector::draw_solids_only [static]

Definition at line 273 of file sector.hpp.

Referenced by scripting::debug_draw_solids_only(), and draw().

GameObjects Sector::gameobjects

Definition at line 275 of file sector.hpp.

Referenced by activate(), Igel::active_update(), add_object(), deactivate(), draw(), Yeti::drop_stalactite(), SecretAreaTrigger::event(), fix_old_tiles(), get_total_badguys(), get_total_count(), InfoBlock::hit(), WeakBlock::spreadHit(), GameSession::start_sequence(), FlipLevelTransformer::transform_sector(), update(), update_game_objects(), and ~Sector().

MovingObjects Sector::moving_objects

Definition at line 276 of file sector.hpp.

Referenced by Totem::active_update(), before_object_add(), before_object_remove(), collision_static(), draw(), Ispy::free_line_of_sight(), get_nearby_objects(), handle_collisions(), is_free_of_movingstatics(), and is_free_of_statics().

SpawnPoints Sector::spawnpoints

Definition at line 277 of file sector.hpp.

Referenced by activate(), parse(), parse_old_format(), FlipLevelTransformer::transform_sector(), and ~Sector().

Portables Sector::portables

Definition at line 278 of file sector.hpp.

Referenced by before_object_add(), and before_object_remove().

std::string Sector::music

Definition at line 280 of file sector.hpp.

Referenced by parse(), parse_old_format(), and play_music().

float Sector::gravity

Definition at line 281 of file sector.hpp.

Referenced by get_gravity(), parse(), and parse_old_format().

Player* Sector::player

Definition at line 285 of file sector.hpp.

Referenced by activate(), before_object_add(), GameSession::check_end_conditions(), Coin::collect(), get_players(), scripting::ghost(), scripting::gotoend(), scripting::grease(), scripting::invincible(), TitleScreen::make_tux_jump(), scripting::mortal(), GameSession::on_escape_press(), GameSession::play_demo(), EndSequenceWalkRight::running(), EndSequenceWalkLeft::running(), TitleScreen::setup(), GameSession::setup(), EndSequence::start(), GameSession::start_sequence(), FlipLevelTransformer::transform_sector(), Brick::try_break(), BonusBlock::try_open(), update(), GameSession::update(), LevelTime::update(), Camera::update_scroll_autoscroll(), Camera::update_scroll_normal(), and scripting::whereami().

std::list<TileMap*> Sector::solid_tilemaps

Definition at line 286 of file sector.hpp.

Referenced by before_object_add(), change_solid_tiles(), ParticleSystem_Interactive::collision(), collision_tile_attributes(), collision_tilemap(), fix_old_tiles(), Ispy::free_line_of_sight(), get_height(), get_width(), inside(), is_free_of_tiles(), parse(), parse_old_format(), and update_game_objects().

Camera* Sector::camera

Definition at line 287 of file sector.hpp.

Referenced by activate(), before_object_add(), scripting::camera(), Player::collision_solid(), IceCrusher::collision_solid(), draw(), Player::draw(), Yeti::drop_stalactite(), get_active_region(), scripting::gotoend(), TitleScreen::make_tux_jump(), parse(), parse_object(), parse_old_format(), FlipLevelTransformer::transform_sector(), GameSession::update(), SpriteParticle::update(), RainParticleSystem::update(), Particles::update(), MagicBlock::update(), Fireworks::update(), CometParticleSystem::update(), Bullet::update(), and AmbientSound::update().

DisplayEffect* Sector::effect

Definition at line 288 of file sector.hpp.

Referenced by before_object_add(), and Player::kill().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:36 2014 for SuperTux by  doxygen 1.5.1