1 // SuperTux - A Jump'n Run
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "supertux/sector.hpp"
22 #include "audio/sound_manager.hpp"
23 #include "badguy/jumpy.hpp"
24 #include "lisp/list_iterator.hpp"
25 #include "math/aatriangle.hpp"
26 #include "object/background.hpp"
27 #include "object/bonus_block.hpp"
28 #include "object/brick.hpp"
29 #include "object/bullet.hpp"
30 #include "object/camera.hpp"
31 #include "object/cloud_particle_system.hpp"
32 #include "object/coin.hpp"
33 #include "object/comet_particle_system.hpp"
34 #include "object/display_effect.hpp"
35 #include "object/ghost_particle_system.hpp"
36 #include "object/gradient.hpp"
37 #include "object/invisible_block.hpp"
38 #include "object/particlesystem.hpp"
39 #include "object/particlesystem_interactive.hpp"
40 #include "object/player.hpp"
41 #include "object/portable.hpp"
42 #include "object/pulsing_light.hpp"
43 #include "object/rain_particle_system.hpp"
44 #include "object/smoke_cloud.hpp"
45 #include "object/snow_particle_system.hpp"
46 #include "object/text_object.hpp"
47 #include "object/tilemap.hpp"
48 #include "physfs/ifile_streambuf.hpp"
49 #include "scripting/scripting.hpp"
50 #include "scripting/squirrel_util.hpp"
51 #include "supertux/collision.hpp"
52 #include "supertux/constants.hpp"
53 #include "supertux/game_session.hpp"
54 #include "supertux/globals.hpp"
55 #include "supertux/level.hpp"
56 #include "supertux/object_factory.hpp"
57 #include "supertux/player_status.hpp"
58 #include "supertux/savegame.hpp"
59 #include "supertux/spawn_point.hpp"
60 #include "supertux/tile.hpp"
61 #include "trigger/secretarea_trigger.hpp"
62 #include "trigger/sequence_trigger.hpp"
63 #include "util/file_system.hpp"
65 Sector* Sector::_current = 0;
67 bool Sector::show_collrects = false;
68 bool Sector::draw_solids_only = false;
70 Sector::Sector(Level* parent) :
76 currentmusic(LEVEL_MUSIC),
79 ambient_light( 1.0f, 1.0f, 1.0f, 1.0f ),
92 add_object(std::make_shared<Player>(GameSession::current()->get_savegame().get_player_status(), "Tux"));
93 add_object(std::make_shared<DisplayEffect>("Effect"));
94 add_object(std::make_shared<TextObject>("Text"));
96 SoundManager::current()->preload("sounds/shoot.wav");
98 // create a new squirrel table for the sector
99 using namespace scripting;
101 sq_collectgarbage(global_vm);
103 sq_newtable(global_vm);
104 sq_pushroottable(global_vm);
105 if(SQ_FAILED(sq_setdelegate(global_vm, -2)))
106 throw scripting::SquirrelError(global_vm, "Couldn't set sector_table delegate");
108 sq_resetobject(§or_table);
109 if(SQ_FAILED(sq_getstackobj(global_vm, -1, §or_table)))
110 throw scripting::SquirrelError(global_vm, "Couldn't get sector table");
111 sq_addref(global_vm, §or_table);
112 sq_pop(global_vm, 1);
114 foremost_layer = calculate_foremost_layer();
119 using namespace scripting;
123 for(auto i = scripts.begin(); i != scripts.end(); ++i) {
124 HSQOBJECT& object = *i;
125 sq_release(global_vm, &object);
127 sq_release(global_vm, §or_table);
128 sq_collectgarbage(global_vm);
130 update_game_objects();
131 assert(gameobjects_new.size() == 0);
133 for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i) {
134 GameObjectPtr object = *i;
135 before_object_remove(object);
146 Sector::parse_object(const std::string& name_, const Reader& reader)
148 if(name_ == "camera") {
149 auto camera_ = std::make_shared<Camera>(this, "Camera");
150 camera_->parse(reader);
152 } else if(name_ == "particles-snow") {
153 auto partsys = std::make_shared<SnowParticleSystem>();
154 partsys->parse(reader);
156 } else if(name_ == "particles-rain") {
157 auto partsys = std::make_shared<RainParticleSystem>();
158 partsys->parse(reader);
160 } else if(name_ == "particles-comets") {
161 auto partsys = std::make_shared<CometParticleSystem>();
162 partsys->parse(reader);
164 } else if(name_ == "particles-ghosts") {
165 auto partsys = std::make_shared<GhostParticleSystem>();
166 partsys->parse(reader);
168 } else if(name_ == "particles-clouds") {
169 auto partsys = std::make_shared<CloudParticleSystem>();
170 partsys->parse(reader);
172 } else if(name_ == "money") { // for compatibility with old maps
173 return std::make_shared<Jumpy>(reader);
176 return ObjectFactory::instance().create(name_, reader);
177 } catch(std::exception& e) {
178 log_warning << e.what() << "" << std::endl;
185 Sector::parse(const Reader& sector)
187 bool has_background = false;
188 lisp::ListIterator iter(§or);
190 const std::string& token = iter.item();
191 if(token == "name") {
192 iter.value()->get(name);
193 } else if(token == "gravity") {
194 iter.value()->get(gravity);
195 } else if(token == "music") {
196 iter.value()->get(music);
197 } else if(token == "spawnpoint") {
198 auto sp = std::make_shared<SpawnPoint>(*iter.lisp());
199 spawnpoints.push_back(sp);
200 } else if(token == "init-script") {
201 iter.value()->get(init_script);
202 } else if(token == "ambient-light") {
203 std::vector<float> vColor;
204 sector.get( "ambient-light", vColor );
205 if(vColor.size() < 3) {
206 log_warning << "(ambient-light) requires a color as argument" << std::endl;
208 ambient_light = Color( vColor );
211 GameObjectPtr object = parse_object(token, *(iter.lisp()));
213 if(std::dynamic_pointer_cast<Background>(object)) {
214 has_background = true;
215 } else if(std::dynamic_pointer_cast<Gradient>(object)) {
216 has_background = true;
223 if(!has_background) {
224 auto gradient = std::make_shared<Gradient>();
225 gradient->set_gradient(Color(0.3, 0.4, 0.75), Color(1, 1, 1));
226 add_object(gradient);
229 update_game_objects();
231 if(solid_tilemaps.empty()) { log_warning << "sector '" << name << "' does not contain a solid tile layer." << std::endl; }
235 log_warning << "sector '" << name << "' does not contain a camera." << std::endl;
236 update_game_objects();
237 add_object(std::make_shared<Camera>(this, "Camera"));
240 update_game_objects();
244 Sector::parse_old_format(const Reader& reader)
247 reader.get("gravity", gravity);
249 std::string backgroundimage;
250 if (reader.get("background", backgroundimage) && (backgroundimage != "")) {
251 if (backgroundimage == "arctis.png") backgroundimage = "arctis.jpg";
252 if (backgroundimage == "arctis2.jpg") backgroundimage = "arctis.jpg";
253 if (backgroundimage == "ocean.png") backgroundimage = "ocean.jpg";
254 backgroundimage = "images/background/" + backgroundimage;
255 if (!PHYSFS_exists(backgroundimage.c_str())) {
256 log_warning << "Background image \"" << backgroundimage << "\" not found. Ignoring." << std::endl;
257 backgroundimage = "";
262 reader.get("bkgd_speed", bgspeed);
265 Color bkgd_top, bkgd_bottom;
266 int r = 0, g = 0, b = 128;
267 reader.get("bkgd_red_top", r);
268 reader.get("bkgd_green_top", g);
269 reader.get("bkgd_blue_top", b);
270 bkgd_top.red = static_cast<float> (r) / 255.0f;
271 bkgd_top.green = static_cast<float> (g) / 255.0f;
272 bkgd_top.blue = static_cast<float> (b) / 255.0f;
274 reader.get("bkgd_red_bottom", r);
275 reader.get("bkgd_green_bottom", g);
276 reader.get("bkgd_blue_bottom", b);
277 bkgd_bottom.red = static_cast<float> (r) / 255.0f;
278 bkgd_bottom.green = static_cast<float> (g) / 255.0f;
279 bkgd_bottom.blue = static_cast<float> (b) / 255.0f;
281 if(backgroundimage != "") {
282 auto background = std::make_shared<Background>();
283 background->set_image(backgroundimage, bgspeed);
284 add_object(background);
286 auto gradient = std::make_shared<Gradient>();
287 gradient->set_gradient(bkgd_top, bkgd_bottom);
288 add_object(gradient);
291 std::string particlesystem;
292 reader.get("particle_system", particlesystem);
293 if(particlesystem == "clouds")
294 add_object(std::make_shared<CloudParticleSystem>());
295 else if(particlesystem == "snow")
296 add_object(std::make_shared<SnowParticleSystem>());
297 else if(particlesystem == "rain")
298 add_object(std::make_shared<RainParticleSystem>());
300 Vector startpos(100, 170);
301 reader.get("start_pos_x", startpos.x);
302 reader.get("start_pos_y", startpos.y);
304 auto spawn = std::make_shared<SpawnPoint>();
305 spawn->pos = startpos;
306 spawn->name = "main";
307 spawnpoints.push_back(spawn);
309 music = "chipdisko.ogg";
310 // skip reading music filename. It's all .ogg now, anyway
312 reader.get("music", music);
314 music = "music/" + music;
316 int width = 30, height = 15;
317 reader.get("width", width);
318 reader.get("height", height);
320 std::vector<unsigned int> tiles;
321 if(reader.get("interactive-tm", tiles)
322 || reader.get("tilemap", tiles)) {
323 auto tilemap = std::make_shared<TileMap>(level->get_tileset());
324 tilemap->set(width, height, tiles, LAYER_TILES, true);
326 // replace tile id 112 (old invisible tile) with 1311 (new invisible tile)
327 for(size_t x=0; x < tilemap->get_width(); ++x) {
328 for(size_t y=0; y < tilemap->get_height(); ++y) {
329 uint32_t id = tilemap->get_tile_id(x, y);
331 tilemap->change(x, y, 1311);
335 if (height < 19) tilemap->resize(width, 19);
339 if(reader.get("background-tm", tiles)) {
340 auto tilemap = std::make_shared<TileMap>(level->get_tileset());
341 tilemap->set(width, height, tiles, LAYER_BACKGROUNDTILES, false);
342 if (height < 19) tilemap->resize(width, 19);
346 if(reader.get("foreground-tm", tiles)) {
347 auto tilemap = std::make_shared<TileMap>(level->get_tileset());
348 tilemap->set(width, height, tiles, LAYER_FOREGROUNDTILES, false);
350 // fill additional space in foreground with tiles of ID 2035 (lightmap/black)
351 if (height < 19) tilemap->resize(width, 19, 2035);
356 // read reset-points (now spawn-points)
357 const lisp::Lisp* resetpoints = reader.get_lisp("reset-points");
359 lisp::ListIterator iter(resetpoints);
361 if(iter.item() == "point") {
363 if(reader.get("x", sp_pos.x) && reader.get("y", sp_pos.y))
365 auto sp = std::make_shared<SpawnPoint>();
368 spawnpoints.push_back(sp);
371 log_warning << "Unknown token '" << iter.item() << "' in reset-points." << std::endl;
377 const lisp::Lisp* objects = reader.get_lisp("objects");
379 lisp::ListIterator iter(objects);
381 auto object = parse_object(iter.item(), *(iter.lisp()));
385 log_warning << "Unknown object '" << iter.item() << "' in level." << std::endl;
391 auto camera_ = std::make_shared<Camera>(this, "Camera");
394 update_game_objects();
396 if(solid_tilemaps.empty()) { log_warning << "sector '" << name << "' does not contain a solid tile layer." << std::endl; }
399 update_game_objects();
403 Sector::fix_old_tiles()
405 for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
406 TileMap* solids = *i;
407 for(size_t x=0; x < solids->get_width(); ++x) {
408 for(size_t y=0; y < solids->get_height(); ++y) {
409 uint32_t id = solids->get_tile_id(x, y);
410 const Tile *tile = solids->get_tile(x, y);
411 Vector pos = solids->get_tile_position(x, y);
414 add_object(std::make_shared<InvisibleBlock>(pos));
415 solids->change(x, y, 0);
416 } else if(tile->getAttributes() & Tile::COIN) {
417 add_object(std::make_shared<Coin>(pos, solids));
418 solids->change(x, y, 0);
419 } else if(tile->getAttributes() & Tile::FULLBOX) {
420 add_object(std::make_shared<BonusBlock>(pos, tile->getData()));
421 solids->change(x, y, 0);
422 } else if(tile->getAttributes() & Tile::BRICK) {
423 if( ( id == 3159 ) || ( id == 3160 ) ){
424 add_object( std::make_shared<Brick>(pos, tile->getData(), "images/objects/bonus_block/brickWeb.sprite") );
425 } else if( ( id == 78 ) || ( id == 105 ) ){
426 add_object( std::make_shared<Brick>(pos, tile->getData(), "images/objects/bonus_block/brickIce.sprite") );
427 } else if( ( id == 77 ) || ( id == 104 ) ){
428 add_object( std::make_shared<Brick>(pos, tile->getData(), "images/objects/bonus_block/brick.sprite") );
430 log_warning << "attribute 'brick #t' is not supported for tile-id " << id << std::endl;
431 add_object( std::make_shared<Brick>(pos, tile->getData(), "images/objects/bonus_block/brick.sprite") );
433 solids->change(x, y, 0);
434 } else if(tile->getAttributes() & Tile::GOAL) {
435 std::string sequence = tile->getData() == 0 ? "endsequence" : "stoptux";
436 add_object(std::make_shared<SequenceTrigger>(pos, sequence));
437 solids->change(x, y, 0);
443 // add lights for special tiles
444 for(auto i = gameobjects.begin(); i != gameobjects.end(); i++) {
445 TileMap* tm = dynamic_cast<TileMap*>(i->get());
447 for(size_t x=0; x < tm->get_width(); ++x) {
448 for(size_t y=0; y < tm->get_height(); ++y) {
449 uint32_t id = tm->get_tile_id(x, y);
450 Vector pos = tm->get_tile_position(x, y);
451 Vector center = pos + Vector(16, 16);
455 float pseudo_rnd = (float)((int)pos.x % 10) / 10;
456 add_object(std::make_shared<PulsingLight>(center, 1.0f + pseudo_rnd, 0.9f, 1.0f, Color(1.0f, 1.0f, 0.6f, 1.0f)));
459 if ((id == 173) || (id == 1700) || (id == 1705) || (id == 1706)) {
460 // space lights a bit
461 if ((((tm->get_tile_id(x-1, y)) != tm->get_tile_id(x,y))
462 && (tm->get_tile_id(x, y-1) != tm->get_tile_id(x,y)))
463 || ((x % 3 == 0) && (y % 3 == 0))) {
464 float pseudo_rnd = (float)((int)pos.x % 10) / 10;
465 add_object(std::make_shared<PulsingLight>(center, 1.0f + pseudo_rnd, 0.8f, 1.0f, Color(1.0f, 0.3f, 0.0f, 1.0f)));
476 Sector::run_script(std::istream& in, const std::string& sourcename)
478 using namespace scripting;
480 // garbage collect thread list
481 for(auto i = scripts.begin(); i != scripts.end(); ) {
482 HSQOBJECT& object = *i;
483 HSQUIRRELVM vm = object_to_vm(object);
485 if(sq_getvmstate(vm) != SQ_VMSTATE_SUSPENDED) {
486 sq_release(global_vm, &object);
487 i = scripts.erase(i);
494 HSQOBJECT object = create_thread(global_vm);
495 scripts.push_back(object);
497 HSQUIRRELVM vm = object_to_vm(object);
499 // set sector_table as roottable for the thread
500 sq_pushobject(vm, sector_table);
504 compile_and_run(vm, in, "Sector " + name + " - " + sourcename);
505 } catch(std::exception& e) {
506 log_warning << "Error running script: " << e.what() << std::endl;
513 Sector::add_object(GameObjectPtr object)
515 // make sure the object isn't already in the list
517 for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i) {
518 assert(*i != object);
520 for(auto i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i) {
521 assert(*i != object);
525 gameobjects_new.push_back(object);
529 Sector::activate(const std::string& spawnpoint)
531 std::shared_ptr<SpawnPoint> sp;
532 for(auto i = spawnpoints.begin(); i != spawnpoints.end(); ++i) {
533 if((*i)->name == spawnpoint) {
539 log_warning << "Spawnpoint '" << spawnpoint << "' not found." << std::endl;
540 if(spawnpoint != "main") {
543 activate(Vector(0, 0));
551 Sector::activate(const Vector& player_pos)
553 if(_current != this) {
555 _current->deactivate();
558 // register sectortable as sector in scripting
559 HSQUIRRELVM vm = scripting::global_vm;
560 sq_pushroottable(vm);
561 sq_pushstring(vm, "sector", -1);
562 sq_pushobject(vm, sector_table);
563 if(SQ_FAILED(sq_createslot(vm, -3)))
564 throw scripting::SquirrelError(vm, "Couldn't set sector in roottable");
567 for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i) {
568 GameObjectPtr object = *i;
576 // two-player hack: move other players to main player's position
577 // Maybe specify 2 spawnpoints in the level?
578 for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i) {
579 Player* p = dynamic_cast<Player*>(i->get());
582 // spawn smalltux below spawnpoint
584 p->move(player_pos + Vector(0,32));
589 // spawning tux in the ground would kill him
590 if(!is_free_of_tiles(p->get_bbox())) {
591 log_warning << "Tried spawning Tux in solid matter. Compensating." << std::endl;
592 Vector npos = p->get_bbox().p1;
598 //FIXME: This is a really dirty workaround for this strange camera jump
599 player->move(player->get_pos()+Vector(-32, 0));
600 camera->reset(player->get_pos());
602 player->move(player->get_pos()+(Vector(32, 0)));
605 update_game_objects();
607 //Run default.nut just before init script
608 //Check to see if it's in a levelset (info file)
609 std::string basedir = FileSystem::dirname(get_level()->filename);
610 if(PHYSFS_exists((basedir + "/info").c_str())) {
612 IFileStreambuf ins(basedir + "/default.nut");
613 std::istream in(&ins);
614 run_script(in, "default.nut");
615 } catch(std::exception& ) {
616 // doesn't exist or erroneous; do nothing
621 if(init_script != "") {
622 std::istringstream in(init_script);
623 run_script(in, "init-script");
633 // remove sector entry from global vm
634 HSQUIRRELVM vm = scripting::global_vm;
635 sq_pushroottable(vm);
636 sq_pushstring(vm, "sector", -1);
637 if(SQ_FAILED(sq_deleteslot(vm, -2, SQFalse)))
638 throw scripting::SquirrelError(vm, "Couldn't unset sector in roottable");
641 for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i) {
642 GameObjectPtr object = *i;
644 try_unexpose(object);
652 Sector::get_active_region()
655 camera->get_translation() - Vector(1600, 1200),
656 camera->get_translation() + Vector(1600, 1200) + Vector(SCREEN_WIDTH,SCREEN_HEIGHT));
660 Sector::calculate_foremost_layer()
663 std::vector<std::string> secret_area_tilemaps;
664 for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i)
666 SecretAreaTrigger* trigger = dynamic_cast<SecretAreaTrigger*>(i->get());
667 if (!trigger) continue;
668 secret_area_tilemaps.push_back(trigger->get_fade_tilemap_name());
671 for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i)
673 TileMap* tm = dynamic_cast<TileMap*>(i->get());
675 if(tm->get_layer() > foremost_layer)
677 if (std::find(secret_area_tilemaps.begin(), secret_area_tilemaps.end(), tm->get_name())
678 != secret_area_tilemaps.end() || tm->is_solid())
680 layer = tm->get_layer();
688 Sector::get_foremost_layer()
690 return foremost_layer;
694 Sector::update(float elapsed_time)
696 player->check_bounds();
699 for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i) {
700 GameObjectPtr& object = *i;
701 if(!object->is_valid())
704 object->update(elapsed_time);
707 /* Handle all possible collisions. */
709 update_game_objects();
713 Sector::update_game_objects()
715 /** cleanup marked objects */
716 for(auto i = gameobjects.begin();
717 i != gameobjects.end(); /* nothing */) {
718 GameObjectPtr& object = *i;
720 if(object->is_valid()) {
725 before_object_remove(object);
727 i = gameobjects.erase(i);
730 /* add newly created objects */
731 for(auto i = gameobjects_new.begin();
732 i != gameobjects_new.end(); ++i)
734 GameObjectPtr object = *i;
736 before_object_add(object);
738 gameobjects.push_back(object);
740 gameobjects_new.clear();
742 /* update solid_tilemaps list */
743 //FIXME: this could be more efficient
744 solid_tilemaps.clear();
745 for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i)
747 TileMap* tm = dynamic_cast<TileMap*>(i->get());
749 if (tm->is_solid()) solid_tilemaps.push_back(tm);
755 Sector::before_object_add(GameObjectPtr object)
757 auto bullet = dynamic_cast<Bullet*>(object.get());
760 bullets.push_back(bullet);
763 auto movingobject = dynamic_cast<MovingObject*>(object.get());
766 moving_objects.push_back(movingobject);
769 auto portable = dynamic_cast<Portable*>(object.get());
772 portables.push_back(portable);
775 auto tilemap = dynamic_cast<TileMap*>(object.get());
776 if(tilemap && tilemap->is_solid()) {
777 solid_tilemaps.push_back(tilemap);
780 auto camera_ = dynamic_cast<Camera*>(object.get());
782 if(this->camera != 0) {
783 log_warning << "Multiple cameras added. Ignoring" << std::endl;
786 this->camera = camera_;
789 auto player_ = dynamic_cast<Player*>(object.get());
791 if(this->player != 0) {
792 log_warning << "Multiple players added. Ignoring" << std::endl;
795 this->player = player_;
798 auto effect_ = dynamic_cast<DisplayEffect*>(object.get());
800 if(this->effect != 0) {
801 log_warning << "Multiple DisplayEffects added. Ignoring" << std::endl;
804 this->effect = effect_;
807 if(_current == this) {
815 Sector::try_expose(GameObjectPtr object)
817 ScriptInterface* object_ = dynamic_cast<ScriptInterface*>(object.get());
818 if(object_ != NULL) {
819 HSQUIRRELVM vm = scripting::global_vm;
820 sq_pushobject(vm, sector_table);
821 object_->expose(vm, -1);
827 Sector::try_expose_me()
829 HSQUIRRELVM vm = scripting::global_vm;
830 sq_pushobject(vm, sector_table);
831 scripting::SSector* this_ = static_cast<scripting::SSector*>(this);
832 expose_object(vm, -1, this_, "settings", false);
837 Sector::before_object_remove(GameObjectPtr object)
839 Portable* portable = dynamic_cast<Portable*>(object.get());
841 portables.erase(std::find(portables.begin(), portables.end(), portable));
843 Bullet* bullet = dynamic_cast<Bullet*>(object.get());
845 bullets.erase(std::find(bullets.begin(), bullets.end(), bullet));
847 MovingObject* moving_object = dynamic_cast<MovingObject*>(object.get());
849 moving_objects.erase(
850 std::find(moving_objects.begin(), moving_objects.end(), moving_object));
854 try_unexpose(object);
858 Sector::try_unexpose(GameObjectPtr object)
860 ScriptInterface* object_ = dynamic_cast<ScriptInterface*>(object.get());
861 if(object_ != NULL) {
862 HSQUIRRELVM vm = scripting::global_vm;
863 SQInteger oldtop = sq_gettop(vm);
864 sq_pushobject(vm, sector_table);
866 object_->unexpose(vm, -1);
867 } catch(std::exception& e) {
868 log_warning << "Couldn't unregister object: " << e.what() << std::endl;
870 sq_settop(vm, oldtop);
875 Sector::try_unexpose_me()
877 HSQUIRRELVM vm = scripting::global_vm;
878 SQInteger oldtop = sq_gettop(vm);
879 sq_pushobject(vm, sector_table);
881 scripting::unexpose_object(vm, -1, "settings");
882 } catch(std::exception& e) {
883 log_warning << "Couldn't unregister object: " << e.what() << std::endl;
885 sq_settop(vm, oldtop);
888 Sector::draw(DrawingContext& context)
890 context.set_ambient_color( ambient_light );
891 context.push_transform();
892 context.set_translation(camera->get_translation());
894 for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i) {
895 GameObjectPtr& object = *i;
896 if(!object->is_valid())
899 if (draw_solids_only)
901 TileMap* tm = dynamic_cast<TileMap*>(object.get());
902 if (tm && !tm->is_solid())
906 object->draw(context);
910 Color color(1.0f, 0.0f, 0.0f, 0.75f);
911 for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
912 MovingObject* object = *i;
913 const Rectf& rect = object->get_bbox();
915 context.draw_filled_rect(rect, color, LAYER_FOREGROUND1 + 10);
919 context.pop_transform();
922 /*-------------------------------------------------------------------------
923 * Collision Detection
924 *-------------------------------------------------------------------------*/
926 /** r1 is supposed to be moving, r2 a solid object */
927 void check_collisions(collision::Constraints* constraints,
928 const Vector& obj_movement, const Rectf& obj_rect, const Rectf& other_rect,
929 GameObject* object = NULL, MovingObject* other = NULL, const Vector& other_movement = Vector(0,0))
931 if(!collision::intersects(obj_rect, other_rect))
934 MovingObject *moving_object = dynamic_cast<MovingObject*> (object);
936 if(other != NULL && !other->collides(*object, dummy))
938 if(moving_object != NULL && !moving_object->collides(*other, dummy))
941 // calculate intersection
942 float itop = obj_rect.get_bottom() - other_rect.get_top();
943 float ibottom = other_rect.get_bottom() - obj_rect.get_top();
944 float ileft = obj_rect.get_right() - other_rect.get_left();
945 float iright = other_rect.get_right() - obj_rect.get_left();
947 if(fabsf(obj_movement.y) > fabsf(obj_movement.x)) {
948 if(ileft < SHIFT_DELTA) {
949 constraints->constrain_right(other_rect.get_left(), other_movement.x);
951 } else if(iright < SHIFT_DELTA) {
952 constraints->constrain_left(other_rect.get_right(), other_movement.x);
956 // shiftout bottom/top
957 if(itop < SHIFT_DELTA) {
958 constraints->constrain_bottom(other_rect.get_top(), other_movement.y);
960 } else if(ibottom < SHIFT_DELTA) {
961 constraints->constrain_top(other_rect.get_bottom(), other_movement.y);
966 constraints->ground_movement += other_movement;
968 HitResponse response = other->collision(*object, dummy);
969 if(response == ABORT_MOVE)
972 if(other->get_movement() != Vector(0, 0)) {
973 // TODO what todo when we collide with 2 moving objects?!?
974 constraints->ground_movement = other->get_movement();
978 float vert_penetration = std::min(itop, ibottom);
979 float horiz_penetration = std::min(ileft, iright);
980 if(vert_penetration < horiz_penetration) {
982 constraints->constrain_bottom(other_rect.get_top(), other_movement.y);
983 constraints->hit.bottom = true;
985 constraints->constrain_top(other_rect.get_bottom(), other_movement.y);
986 constraints->hit.top = true;
990 constraints->constrain_right(other_rect.get_left(), other_movement.x);
991 constraints->hit.right = true;
993 constraints->constrain_left(other_rect.get_right(), other_movement.x);
994 constraints->hit.left = true;
1000 Sector::collision_tilemap(collision::Constraints* constraints,
1001 const Vector& movement, const Rectf& dest,
1002 MovingObject& object) const
1004 // calculate rectangle where the object will move
1005 float x1 = dest.get_left();
1006 float x2 = dest.get_right();
1007 float y1 = dest.get_top();
1008 float y2 = dest.get_bottom();
1010 for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
1011 TileMap* solids = *i;
1013 // test with all tiles in this rectangle
1014 Rect test_tiles = solids->get_tiles_overlapping(Rectf(x1, y1, x2, y2));
1016 for(int x = test_tiles.left; x < test_tiles.right; ++x) {
1017 for(int y = test_tiles.top; y < test_tiles.bottom; ++y) {
1018 const Tile* tile = solids->get_tile(x, y);
1021 // skip non-solid tiles
1022 if(!tile->is_solid ())
1024 Rectf tile_bbox = solids->get_tile_bbox(x, y);
1026 /* If the tile is a unisolid tile, the "is_solid()" function above
1027 * didn't do a thorough check. Calculate the position and (relative)
1028 * movement of the object and determine whether or not the tile is
1029 * solid with regard to those parameters. */
1030 if(tile->is_unisolid ()) {
1031 Vector relative_movement = movement
1032 - solids->get_movement(/* actual = */ true);
1034 if (!tile->is_solid (tile_bbox, object.get_bbox(), relative_movement))
1036 } /* if (tile->is_unisolid ()) */
1038 if(tile->is_slope ()) { // slope tile
1039 AATriangle triangle;
1040 int slope_data = tile->getData();
1041 if (solids->get_drawing_effect() & VERTICAL_FLIP)
1042 slope_data = AATriangle::vertical_flip(slope_data);
1043 triangle = AATriangle(tile_bbox, slope_data);
1045 collision::rectangle_aatriangle(constraints, dest, triangle,
1046 solids->get_movement(/* actual = */ false));
1047 } else { // normal rectangular tile
1048 check_collisions(constraints, movement, dest, tile_bbox, NULL, NULL,
1049 solids->get_movement(/* actual = */ false));
1057 Sector::collision_tile_attributes(const Rectf& dest) const
1059 float x1 = dest.p1.x;
1060 float y1 = dest.p1.y;
1061 float x2 = dest.p2.x;
1062 float y2 = dest.p2.y;
1064 uint32_t result = 0;
1065 for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
1066 TileMap* solids = *i;
1068 // test with all tiles in this rectangle
1069 Rect test_tiles = solids->get_tiles_overlapping(Rectf(x1, y1, x2, y2));
1070 // For ice (only), add a little fudge to recognize tiles Tux is standing on.
1071 Rect test_tiles_ice = solids->get_tiles_overlapping(Rectf(x1, y1, x2, y2 + SHIFT_DELTA));
1073 for(int x = test_tiles.left; x < test_tiles.right; ++x) {
1075 for(y = test_tiles.top; y < test_tiles.bottom; ++y) {
1076 const Tile* tile = solids->get_tile(x, y);
1079 result |= tile->getAttributes();
1081 for(; y < test_tiles_ice.bottom; ++y) {
1082 const Tile* tile = solids->get_tile(x, y);
1085 result |= (tile->getAttributes() & Tile::ICE);
1093 /** fills in CollisionHit and Normal vector of 2 intersecting rectangle */
1094 static void get_hit_normal(const Rectf& r1, const Rectf& r2, CollisionHit& hit,
1097 float itop = r1.get_bottom() - r2.get_top();
1098 float ibottom = r2.get_bottom() - r1.get_top();
1099 float ileft = r1.get_right() - r2.get_left();
1100 float iright = r2.get_right() - r1.get_left();
1102 float vert_penetration = std::min(itop, ibottom);
1103 float horiz_penetration = std::min(ileft, iright);
1104 if(vert_penetration < horiz_penetration) {
1105 if(itop < ibottom) {
1107 normal.y = vert_penetration;
1110 normal.y = -vert_penetration;
1113 if(ileft < iright) {
1115 normal.x = horiz_penetration;
1118 normal.x = -horiz_penetration;
1124 Sector::collision_object(MovingObject* object1, MovingObject* object2) const
1126 using namespace collision;
1128 const Rectf& r1 = object1->dest;
1129 const Rectf& r2 = object2->dest;
1132 if(intersects(object1->dest, object2->dest)) {
1134 get_hit_normal(r1, r2, hit, normal);
1136 if(!object1->collides(*object2, hit))
1138 std::swap(hit.left, hit.right);
1139 std::swap(hit.top, hit.bottom);
1140 if(!object2->collides(*object1, hit))
1142 std::swap(hit.left, hit.right);
1143 std::swap(hit.top, hit.bottom);
1145 HitResponse response1 = object1->collision(*object2, hit);
1146 std::swap(hit.left, hit.right);
1147 std::swap(hit.top, hit.bottom);
1148 HitResponse response2 = object2->collision(*object1, hit);
1149 if(response1 == CONTINUE && response2 == CONTINUE) {
1150 normal *= (0.5 + DELTA);
1151 object1->dest.move(-normal);
1152 object2->dest.move(normal);
1153 } else if (response1 == CONTINUE && response2 == FORCE_MOVE) {
1154 normal *= (1 + DELTA);
1155 object1->dest.move(-normal);
1156 } else if (response1 == FORCE_MOVE && response2 == CONTINUE) {
1157 normal *= (1 + DELTA);
1158 object2->dest.move(normal);
1164 Sector::collision_static(collision::Constraints* constraints,
1165 const Vector& movement, const Rectf& dest,
1166 MovingObject& object)
1168 collision_tilemap(constraints, movement, dest, object);
1170 // collision with other (static) objects
1171 for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
1172 MovingObject* moving_object = *i;
1173 if(moving_object->get_group() != COLGROUP_STATIC
1174 && moving_object->get_group() != COLGROUP_MOVING_STATIC)
1176 if(!moving_object->is_valid())
1179 if(moving_object != &object)
1180 check_collisions(constraints, movement, dest, moving_object->bbox,
1181 &object, moving_object);
1186 Sector::collision_static_constrains(MovingObject& object)
1188 using namespace collision;
1189 float infinity = (std::numeric_limits<float>::has_infinity ? std::numeric_limits<float>::infinity() : std::numeric_limits<float>::max());
1191 Constraints constraints;
1192 Vector movement = object.get_movement();
1193 Rectf& dest = object.dest;
1195 for(int i = 0; i < 2; ++i) {
1196 collision_static(&constraints, Vector(0, movement.y), dest, object);
1197 if(!constraints.has_constraints())
1200 // apply calculated horizontal constraints
1201 if(constraints.get_position_bottom() < infinity) {
1202 float height = constraints.get_height ();
1203 if(height < object.get_bbox().get_height()) {
1204 // we're crushed, but ignore this for now, we'll get this again
1205 // later if we're really crushed or things will solve itself when
1206 // looking at the vertical constraints
1208 dest.p2.y = constraints.get_position_bottom() - DELTA;
1209 dest.p1.y = dest.p2.y - object.get_bbox().get_height();
1210 } else if(constraints.get_position_top() > -infinity) {
1211 dest.p1.y = constraints.get_position_top() + DELTA;
1212 dest.p2.y = dest.p1.y + object.get_bbox().get_height();
1215 if(constraints.has_constraints()) {
1216 if(constraints.hit.bottom) {
1217 dest.move(constraints.ground_movement);
1219 if(constraints.hit.top || constraints.hit.bottom) {
1220 constraints.hit.left = false;
1221 constraints.hit.right = false;
1222 object.collision_solid(constraints.hit);
1226 constraints = Constraints();
1227 for(int i = 0; i < 2; ++i) {
1228 collision_static(&constraints, movement, dest, object);
1229 if(!constraints.has_constraints())
1232 // apply calculated vertical constraints
1233 float width = constraints.get_width ();
1234 if(width < infinity) {
1235 if(width + SHIFT_DELTA < object.get_bbox().get_width()) {
1237 printf("Object %p crushed horizontally... L:%f R:%f\n", &object,
1238 constraints.get_position_left(), constraints.get_position_right());
1244 object.collision_solid(h);
1246 float xmid = constraints.get_x_midpoint ();
1247 dest.p1.x = xmid - object.get_bbox().get_width()/2;
1248 dest.p2.x = xmid + object.get_bbox().get_width()/2;
1250 } else if(constraints.get_position_right() < infinity) {
1251 dest.p2.x = constraints.get_position_right() - DELTA;
1252 dest.p1.x = dest.p2.x - object.get_bbox().get_width();
1253 } else if(constraints.get_position_left() > -infinity) {
1254 dest.p1.x = constraints.get_position_left() + DELTA;
1255 dest.p2.x = dest.p1.x + object.get_bbox().get_width();
1259 if(constraints.has_constraints()) {
1260 if( constraints.hit.left || constraints.hit.right
1261 || constraints.hit.top || constraints.hit.bottom
1262 || constraints.hit.crush )
1263 object.collision_solid(constraints.hit);
1266 // an extra pass to make sure we're not crushed horizontally
1267 constraints = Constraints();
1268 collision_static(&constraints, movement, dest, object);
1269 if(constraints.get_position_bottom() < infinity) {
1270 float height = constraints.get_height ();
1271 if(height + SHIFT_DELTA < object.get_bbox().get_height()) {
1273 printf("Object %p crushed vertically...\n", &object);
1279 object.collision_solid(h);
1285 const float MAX_SPEED = 16.0f;
1289 Sector::handle_collisions()
1291 using namespace collision;
1293 // calculate destination positions of the objects
1294 for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
1295 MovingObject* moving_object = *i;
1296 Vector mov = moving_object->get_movement();
1298 // make sure movement is never faster than MAX_SPEED. Norm is pretty fat, so two addl. checks are done before.
1299 if (((mov.x > MAX_SPEED * M_SQRT1_2) || (mov.y > MAX_SPEED * M_SQRT1_2)) && (mov.norm() > MAX_SPEED)) {
1300 moving_object->movement = mov.unit() * MAX_SPEED;
1301 //log_debug << "Temporarily reduced object's speed of " << mov.norm() << " to " << moving_object->movement.norm() << "." << std::endl;
1304 moving_object->dest = moving_object->get_bbox();
1305 moving_object->dest.move(moving_object->get_movement());
1308 // part1: COLGROUP_MOVING vs COLGROUP_STATIC and tilemap
1309 for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
1310 MovingObject* moving_object = *i;
1311 if((moving_object->get_group() != COLGROUP_MOVING
1312 && moving_object->get_group() != COLGROUP_MOVING_STATIC
1313 && moving_object->get_group() != COLGROUP_MOVING_ONLY_STATIC)
1314 || !moving_object->is_valid())
1317 collision_static_constrains(*moving_object);
1320 // part2: COLGROUP_MOVING vs tile attributes
1321 for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
1322 MovingObject* moving_object = *i;
1323 if((moving_object->get_group() != COLGROUP_MOVING
1324 && moving_object->get_group() != COLGROUP_MOVING_STATIC
1325 && moving_object->get_group() != COLGROUP_MOVING_ONLY_STATIC)
1326 || !moving_object->is_valid())
1329 uint32_t tile_attributes = collision_tile_attributes(moving_object->dest);
1330 if(tile_attributes >= Tile::FIRST_INTERESTING_FLAG) {
1331 moving_object->collision_tile(tile_attributes);
1335 // part2.5: COLGROUP_MOVING vs COLGROUP_TOUCHABLE
1336 for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
1337 MovingObject* moving_object = *i;
1338 if((moving_object->get_group() != COLGROUP_MOVING
1339 && moving_object->get_group() != COLGROUP_MOVING_STATIC)
1340 || !moving_object->is_valid())
1343 for(auto i2 = moving_objects.begin(); i2 != moving_objects.end(); ++i2) {
1344 MovingObject* moving_object_2 = *i2;
1345 if(moving_object_2->get_group() != COLGROUP_TOUCHABLE
1346 || !moving_object_2->is_valid())
1349 if(intersects(moving_object->dest, moving_object_2->dest)) {
1352 get_hit_normal(moving_object->dest, moving_object_2->dest,
1354 if(!moving_object->collides(*moving_object_2, hit))
1356 if(!moving_object_2->collides(*moving_object, hit))
1359 moving_object->collision(*moving_object_2, hit);
1360 moving_object_2->collision(*moving_object, hit);
1365 // part3: COLGROUP_MOVING vs COLGROUP_MOVING
1366 for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
1367 MovingObject* moving_object = *i;
1369 if((moving_object->get_group() != COLGROUP_MOVING
1370 && moving_object->get_group() != COLGROUP_MOVING_STATIC)
1371 || !moving_object->is_valid())
1374 for(auto i2 = i+1; i2 != moving_objects.end(); ++i2) {
1375 MovingObject* moving_object_2 = *i2;
1376 if((moving_object_2->get_group() != COLGROUP_MOVING
1377 && moving_object_2->get_group() != COLGROUP_MOVING_STATIC)
1378 || !moving_object_2->is_valid())
1381 collision_object(moving_object, moving_object_2);
1385 // apply object movement
1386 for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
1387 MovingObject* moving_object = *i;
1389 moving_object->bbox = moving_object->dest;
1390 moving_object->movement = Vector(0, 0);
1395 Sector::is_free_of_tiles(const Rectf& rect, const bool ignoreUnisolid) const
1397 using namespace collision;
1399 for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
1400 TileMap* solids = *i;
1402 // test with all tiles in this rectangle
1403 Rect test_tiles = solids->get_tiles_overlapping(rect);
1405 for(int x = test_tiles.left; x < test_tiles.right; ++x) {
1406 for(int y = test_tiles.top; y < test_tiles.bottom; ++y) {
1407 const Tile* tile = solids->get_tile(x, y);
1409 if(!(tile->getAttributes() & Tile::SOLID))
1411 if(tile->is_unisolid () && ignoreUnisolid)
1413 if(tile->is_slope ()) {
1414 AATriangle triangle;
1415 Rectf tbbox = solids->get_tile_bbox(x, y);
1416 triangle = AATriangle(tbbox, tile->getData());
1417 Constraints constraints;
1418 if(!collision::rectangle_aatriangle(&constraints, rect, triangle))
1421 // We have a solid tile that overlaps the given rectangle.
1431 Sector::is_free_of_statics(const Rectf& rect, const MovingObject* ignore_object, const bool ignoreUnisolid) const
1433 using namespace collision;
1435 if (!is_free_of_tiles(rect, ignoreUnisolid)) return false;
1437 for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
1438 const MovingObject* moving_object = *i;
1439 if (moving_object == ignore_object) continue;
1440 if (!moving_object->is_valid()) continue;
1441 if (moving_object->get_group() == COLGROUP_STATIC) {
1442 if(intersects(rect, moving_object->get_bbox())) return false;
1450 Sector::is_free_of_movingstatics(const Rectf& rect, const MovingObject* ignore_object) const
1452 using namespace collision;
1454 if (!is_free_of_tiles(rect)) return false;
1456 for(auto i = moving_objects.begin(); i != moving_objects.end(); ++i) {
1457 const MovingObject* moving_object = *i;
1458 if (moving_object == ignore_object) continue;
1459 if (!moving_object->is_valid()) continue;
1460 if ((moving_object->get_group() == COLGROUP_MOVING)
1461 || (moving_object->get_group() == COLGROUP_MOVING_STATIC)
1462 || (moving_object->get_group() == COLGROUP_STATIC)) {
1463 if(intersects(rect, moving_object->get_bbox())) return false;
1471 Sector::add_bullet(const Vector& pos, const PlayerStatus* player_status, float xm, Direction dir)
1473 // TODO remove this function and move these checks elsewhere...
1474 if((player_status->bonus == FIRE_BONUS &&
1475 (int)bullets.size() >= player_status->max_fire_bullets) ||
1476 (player_status->bonus == ICE_BONUS &&
1477 (int)bullets.size() >= player_status->max_ice_bullets))
1479 auto new_bullet = std::make_shared<Bullet>(pos, xm, dir, player_status->bonus);
1480 add_object(new_bullet);
1482 SoundManager::current()->play("sounds/shoot.wav");
1488 Sector::add_smoke_cloud(const Vector& pos)
1490 add_object(std::make_shared<SmokeCloud>(pos));
1495 Sector::play_music(MusicType type)
1497 currentmusic = type;
1498 switch(currentmusic) {
1500 SoundManager::current()->play_music(music);
1503 SoundManager::current()->play_music("music/invincible.ogg");
1505 case HERRING_WARNING_MUSIC:
1506 SoundManager::current()->stop_music(TUX_INVINCIBLE_TIME_WARNING);
1509 SoundManager::current()->play_music("");
1515 Sector::get_music_type()
1517 return currentmusic;
1521 Sector::get_total_badguys()
1523 int total_badguys = 0;
1524 for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i) {
1525 BadGuy* badguy = dynamic_cast<BadGuy*>(i->get());
1526 if (badguy && badguy->countMe)
1530 return total_badguys;
1534 Sector::inside(const Rectf& rect) const
1536 for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
1537 TileMap* solids = *i;
1539 Rectf bbox = solids->get_bbox();
1540 bbox.p1.y = -INFINITY; // pretend the tilemap extends infinitely far upwards
1542 if (bbox.contains(rect))
1549 Sector::get_width() const
1552 for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
1553 TileMap* solids = *i;
1554 width = std::max(width, solids->get_bbox().get_right());
1561 Sector::get_height() const
1564 for(auto i = solid_tilemaps.begin();
1565 i != solid_tilemaps.end(); i++) {
1566 TileMap* solids = *i;
1567 height = std::max(height, solids->get_bbox().get_bottom());
1574 Sector::change_solid_tiles(uint32_t old_tile_id, uint32_t new_tile_id)
1576 for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
1577 TileMap* solids = *i;
1578 solids->change_all(old_tile_id, new_tile_id);
1583 Sector::set_ambient_light(float red, float green, float blue)
1585 ambient_light.red = red;
1586 ambient_light.green = green;
1587 ambient_light.blue = blue;
1591 Sector::get_ambient_red()
1593 return ambient_light.red;
1597 Sector::get_ambient_green()
1599 return ambient_light.green;
1603 Sector::get_ambient_blue()
1605 return ambient_light.blue;
1609 Sector::set_gravity(float gravity_)
1611 log_warning << "Changing a Sector's gravitational constant might have unforeseen side-effects" << std::endl;
1612 this->gravity = gravity_;
1616 Sector::get_gravity() const
1622 Sector::get_nearest_player (const Vector& pos)
1624 Player *nearest_player = NULL;
1625 float nearest_dist = std::numeric_limits<float>::max();
1627 std::vector<Player*> players = Sector::current()->get_players();
1628 for (auto playerIter = players.begin(); playerIter != players.end(); ++playerIter)
1630 Player *this_player = *playerIter;
1631 if (this_player->is_dying() || this_player->is_dead())
1634 float this_dist = this_player->get_bbox ().distance(pos);
1636 if (this_dist < nearest_dist) {
1637 nearest_player = this_player;
1638 nearest_dist = this_dist;
1642 return nearest_player;
1643 } /* Player *get_nearest_player */
1645 std::vector<MovingObject*>
1646 Sector::get_nearby_objects (const Vector& center, float max_distance)
1648 std::vector<MovingObject*> ret;
1649 std::vector<Player*> players = Sector::current()->get_players();
1651 for (size_t i = 0; i < players.size (); i++) {
1652 float distance = players[i]->get_bbox ().distance (center);
1653 if (distance <= max_distance)
1654 ret.push_back (players[i]);
1657 for (size_t i = 0; i < moving_objects.size (); i++) {
1658 float distance = moving_objects[i]->get_bbox ().distance (center);
1659 if (distance <= max_distance)
1660 ret.push_back (moving_objects[i]);
1666 /* vim: set sw=2 sts=2 et : */