#include "supertux/savegame.hpp"
#include "supertux/spawn_point.hpp"
#include "supertux/tile.hpp"
+#include "trigger/secretarea_trigger.hpp"
#include "trigger/sequence_trigger.hpp"
#include "util/file_system.hpp"
sector_table(),
scripts(),
ambient_light( 1.0f, 1.0f, 1.0f, 1.0f ),
+ foremost_layer(),
gameobjects(),
moving_objects(),
spawnpoints(),
throw scripting::SquirrelError(global_vm, "Couldn't get sector table");
sq_addref(global_vm, §or_table);
sq_pop(global_vm, 1);
+
+ foremost_layer = calculate_foremost_layer();
}
Sector::~Sector()
deactivate();
- for(ScriptList::iterator i = scripts.begin();
- i != scripts.end(); ++i) {
+ for(auto i = scripts.begin(); i != scripts.end(); ++i) {
HSQOBJECT& object = *i;
sq_release(global_vm, &object);
}
update_game_objects();
assert(gameobjects_new.size() == 0);
- for(GameObjects::iterator i = gameobjects.begin();
- i != gameobjects.end(); ++i) {
+ for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i) {
GameObjectPtr object = *i;
before_object_remove(object);
}
void
Sector::fix_old_tiles()
{
- for(std::list<TileMap*>::iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
+ for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
for(size_t x=0; x < solids->get_width(); ++x) {
for(size_t y=0; y < solids->get_height(); ++y) {
add_object(std::make_shared<BonusBlock>(pos, tile->getData()));
solids->change(x, y, 0);
} else if(tile->getAttributes() & Tile::BRICK) {
- if( ( id == 78 ) || ( id == 105 ) ){
+ if( ( id == 3159 ) || ( id == 3160 ) ){
+ add_object( std::make_shared<Brick>(pos, tile->getData(), "images/objects/bonus_block/brickWeb.sprite") );
+ } else if( ( id == 78 ) || ( id == 105 ) ){
add_object( std::make_shared<Brick>(pos, tile->getData(), "images/objects/bonus_block/brickIce.sprite") );
} else if( ( id == 77 ) || ( id == 104 ) ){
add_object( std::make_shared<Brick>(pos, tile->getData(), "images/objects/bonus_block/brick.sprite") );
}
// add lights for special tiles
- for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); i++) {
+ for(auto i = gameobjects.begin(); i != gameobjects.end(); i++) {
TileMap* tm = dynamic_cast<TileMap*>(i->get());
if (!tm) continue;
for(size_t x=0; x < tm->get_width(); ++x) {
using namespace scripting;
// garbage collect thread list
- for(ScriptList::iterator i = scripts.begin();
- i != scripts.end(); ) {
+ for(auto i = scripts.begin(); i != scripts.end(); ) {
HSQOBJECT& object = *i;
HSQUIRRELVM vm = object_to_vm(object);
{
// make sure the object isn't already in the list
#ifndef NDEBUG
- for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end();
- ++i) {
+ for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i) {
assert(*i != object);
}
- for(GameObjects::iterator i = gameobjects_new.begin();
- i != gameobjects_new.end(); ++i) {
+ for(auto i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i) {
assert(*i != object);
}
#endif
Sector::activate(const std::string& spawnpoint)
{
std::shared_ptr<SpawnPoint> sp;
- for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
- ++i) {
+ for(auto i = spawnpoints.begin(); i != spawnpoints.end(); ++i) {
if((*i)->name == spawnpoint) {
sp = *i;
break;
camera->get_translation() + Vector(1600, 1200) + Vector(SCREEN_WIDTH,SCREEN_HEIGHT));
}
+int
+Sector::calculate_foremost_layer()
+{
+ int layer = 0;
+ std::vector<std::string> secret_area_layers;
+ for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i)
+ {
+ SecretAreaTrigger* trigger = dynamic_cast<SecretAreaTrigger*>(i->get());
+ if (!trigger) continue;
+ secret_area_layers.push_back(trigger->get_fade_tilemap_name());
+ }
+
+ for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i)
+ {
+ TileMap* tm = dynamic_cast<TileMap*>(i->get());
+ if (!tm) continue;
+ if(tm->get_layer() > foremost_layer)
+ {
+ if (std::find(secret_area_layers.begin(), secret_area_layers.end(), tm->get_name())
+ != secret_area_layers.end() || tm->is_solid())
+ {
+ layer = tm->get_layer();
+ }
+ }
+ }
+ return layer;
+}
+
+int
+Sector::get_foremost_layer()
+{
+ return foremost_layer;
+}
+
void
Sector::update(float elapsed_time)
{
if(show_collrects) {
Color color(1.0f, 0.0f, 0.0f, 0.75f);
- for(MovingObjects::iterator i = moving_objects.begin();
- i != moving_objects.end(); ++i) {
+ for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
MovingObject* object = *i;
const Rectf& rect = object->get_bbox();
float y1 = dest.get_top();
float y2 = dest.get_bottom();
- for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
+ for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
// test with all tiles in this rectangle
float y2 = dest.p2.y;
uint32_t result = 0;
- for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
+ for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
// test with all tiles in this rectangle
collision_tilemap(constraints, movement, dest, object);
// collision with other (static) objects
- for(MovingObjects::iterator i = moving_objects.begin();
- i != moving_objects.end(); ++i) {
+ for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
MovingObject* moving_object = *i;
if(moving_object->get_group() != COLGROUP_STATIC
&& moving_object->get_group() != COLGROUP_MOVING_STATIC)
using namespace collision;
// calculate destination positions of the objects
- for(MovingObjects::iterator i = moving_objects.begin();
- i != moving_objects.end(); ++i) {
+ for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
MovingObject* moving_object = *i;
Vector mov = moving_object->get_movement();
}
// part1: COLGROUP_MOVING vs COLGROUP_STATIC and tilemap
- for(MovingObjects::iterator i = moving_objects.begin();
- i != moving_objects.end(); ++i) {
+ for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
MovingObject* moving_object = *i;
if((moving_object->get_group() != COLGROUP_MOVING
&& moving_object->get_group() != COLGROUP_MOVING_STATIC
}
// part2: COLGROUP_MOVING vs tile attributes
- for(MovingObjects::iterator i = moving_objects.begin();
- i != moving_objects.end(); ++i) {
+ for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
MovingObject* moving_object = *i;
if((moving_object->get_group() != COLGROUP_MOVING
&& moving_object->get_group() != COLGROUP_MOVING_STATIC
}
// part2.5: COLGROUP_MOVING vs COLGROUP_TOUCHABLE
- for(MovingObjects::iterator i = moving_objects.begin();
- i != moving_objects.end(); ++i) {
+ for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
MovingObject* moving_object = *i;
if((moving_object->get_group() != COLGROUP_MOVING
&& moving_object->get_group() != COLGROUP_MOVING_STATIC)
|| !moving_object->is_valid())
continue;
- for(MovingObjects::iterator i2 = moving_objects.begin();
- i2 != moving_objects.end(); ++i2) {
+ for(auto i2 = moving_objects.begin(); i2 != moving_objects.end(); ++i2) {
MovingObject* moving_object_2 = *i2;
if(moving_object_2->get_group() != COLGROUP_TOUCHABLE
|| !moving_object_2->is_valid())
}
// part3: COLGROUP_MOVING vs COLGROUP_MOVING
- for(MovingObjects::iterator i = moving_objects.begin();
- i != moving_objects.end(); ++i) {
+ for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
MovingObject* moving_object = *i;
if((moving_object->get_group() != COLGROUP_MOVING
|| !moving_object->is_valid())
continue;
- for(MovingObjects::iterator i2 = i+1;
- i2 != moving_objects.end(); ++i2) {
+ for(auto i2 = i+1; i2 != moving_objects.end(); ++i2) {
MovingObject* moving_object_2 = *i2;
if((moving_object_2->get_group() != COLGROUP_MOVING
&& moving_object_2->get_group() != COLGROUP_MOVING_STATIC)
}
// apply object movement
- for(MovingObjects::iterator i = moving_objects.begin();
- i != moving_objects.end(); ++i) {
+ for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
MovingObject* moving_object = *i;
moving_object->bbox = moving_object->dest;
{
using namespace collision;
- for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
+ for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
// test with all tiles in this rectangle
if (!is_free_of_tiles(rect, ignoreUnisolid)) return false;
- for(MovingObjects::const_iterator i = moving_objects.begin();
- i != moving_objects.end(); ++i) {
+ for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
const MovingObject* moving_object = *i;
if (moving_object == ignore_object) continue;
if (!moving_object->is_valid()) continue;
if (!is_free_of_tiles(rect)) return false;
- for(MovingObjects::const_iterator i = moving_objects.begin();
- i != moving_objects.end(); ++i) {
+ for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
const MovingObject* moving_object = *i;
if (moving_object == ignore_object) continue;
if (!moving_object->is_valid()) continue;
bool
Sector::inside(const Rectf& rect) const
{
- for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
+ for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
Rectf bbox = solids->get_bbox();
Sector::get_width() const
{
float width = 0;
- for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin();
- i != solid_tilemaps.end(); i++) {
+ for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
width = std::max(width, solids->get_bbox().get_right());
}
Sector::get_height() const
{
float height = 0;
- for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin();
+ for(auto i = solid_tilemaps.begin();
i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
height = std::max(height, solids->get_bbox().get_bottom());
void
Sector::change_solid_tiles(uint32_t old_tile_id, uint32_t new_tile_id)
{
- for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
+ for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
solids->change_all(old_tile_id, new_tile_id);
}
float nearest_dist = std::numeric_limits<float>::max();
std::vector<Player*> players = Sector::current()->get_players();
- for (std::vector<Player*>::iterator playerIter = players.begin();
- playerIter != players.end();
- ++playerIter)
+ for (auto playerIter = players.begin(); playerIter != players.end(); ++playerIter)
{
Player *this_player = *playerIter;
if (this_player->is_dying() || this_player->is_dead())