3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
5 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include "worldmap.hpp"
33 #include "gettext.hpp"
35 #include "mainloop.hpp"
36 #include "shrinkfade.hpp"
37 #include "video/surface.hpp"
38 #include "video/drawing_context.hpp"
39 #include "sprite/sprite_manager.hpp"
40 #include "audio/sound_manager.hpp"
41 #include "lisp/parser.hpp"
42 #include "lisp/lisp.hpp"
43 #include "lisp/list_iterator.hpp"
44 #include "lisp/writer.hpp"
45 #include "game_session.hpp"
47 #include "worldmap.hpp"
48 #include "resources.hpp"
51 #include "player_status.hpp"
52 #include "textscroller.hpp"
54 #include "spawn_point.hpp"
55 #include "file_system.hpp"
56 #include "gui/menu.hpp"
57 #include "gui/mousecursor.hpp"
58 #include "control/joystickkeyboardcontroller.hpp"
59 #include "object/background.hpp"
60 #include "object/tilemap.hpp"
61 #include "options_menu.hpp"
62 #include "scripting/squirrel_error.hpp"
63 #include "scripting/squirrel_util.hpp"
64 #include "worldmap/level.hpp"
65 #include "worldmap/special_tile.hpp"
66 #include "worldmap/tux.hpp"
67 #include "worldmap/sprite_change.hpp"
69 namespace WorldMapNS {
71 enum WorldMapMenuIDs {
76 WorldMap* WorldMap::current_ = NULL;
78 Direction reverse_dir(Direction direction)
97 direction_to_string(Direction direction)
115 string_to_direction(const std::string& directory)
117 if (directory == "west")
119 else if (directory == "east")
121 else if (directory == "north")
123 else if (directory == "south")
129 //---------------------------------------------------------------------------
131 WorldMap::WorldMap(const std::string& filename)
134 tile_manager.reset(new TileManager("images/worldmap.strf"));
140 music = "music/salcon.ogg";
144 worldmap_menu.reset(new Menu());
145 worldmap_menu->add_label(_("Pause"));
146 worldmap_menu->add_hl();
147 worldmap_menu->add_entry(MNID_RETURNWORLDMAP, _("Continue"));
148 worldmap_menu->add_submenu(_("Options"), get_options_menu());
149 worldmap_menu->add_hl();
150 worldmap_menu->add_entry(MNID_QUITWORLDMAP, _("Quit World"));
154 // create a new squirrel table for the worldmap
155 using namespace Scripting;
157 sq_collectgarbage(global_vm);
158 sq_newtable(global_vm);
159 sq_pushroottable(global_vm);
160 if(SQ_FAILED(sq_setdelegate(global_vm, -2)))
161 throw Scripting::SquirrelError(global_vm, "Couldn't set worldmap_table delegate");
163 sq_resetobject(&worldmap_table);
164 if(SQ_FAILED(sq_getstackobj(global_vm, -1, &worldmap_table)))
165 throw Scripting::SquirrelError(global_vm, "Couldn't get table from stack");
167 sq_addref(global_vm, &worldmap_table);
168 sq_pop(global_vm, 1);
171 WorldMap::~WorldMap()
173 using namespace Scripting;
175 for(ScriptList::iterator i = scripts.begin();
176 i != scripts.end(); ++i) {
177 HSQOBJECT& object = *i;
178 sq_release(global_vm, &object);
180 sq_release(global_vm, &worldmap_table);
182 sq_collectgarbage(global_vm);
187 for(GameObjects::iterator i = game_objects.begin();
188 i != game_objects.end(); ++i)
191 for(SpawnPoints::iterator i = spawn_points.begin();
192 i != spawn_points.end(); ++i) {
198 WorldMap::add_object(GameObject* object)
200 TileMap* tilemap = dynamic_cast<TileMap*> (object);
201 if(tilemap != 0 && tilemap->is_solid()) {
205 game_objects.push_back(object);
209 WorldMap::load(const std::string& filename)
211 map_filename = filename;
212 levels_path = FileSystem::dirname(map_filename);
216 std::auto_ptr<lisp::Lisp> root (parser.parse(map_filename));
218 const lisp::Lisp* lisp = root->get_lisp("supertux-level");
220 throw std::runtime_error("file isn't a supertux-level file.");
222 lisp->get("name", name);
224 const lisp::Lisp* sector = lisp->get_lisp("sector");
226 throw std::runtime_error("No sector sepcified in worldmap file.");
228 lisp::ListIterator iter(sector);
230 if(iter.item() == "tilemap") {
231 add_object(new TileMap(*(iter.lisp()), tile_manager.get()));
232 } else if(iter.item() == "background") {
233 add_object(new Background(*(iter.lisp())));
234 } else if(iter.item() == "music") {
235 iter.value()->get(music);
236 } else if(iter.item() == "init-script") {
237 iter.value()->get(init_script);
238 } else if(iter.item() == "worldmap-spawnpoint") {
239 SpawnPoint* sp = new SpawnPoint(iter.lisp());
240 spawn_points.push_back(sp);
241 } else if(iter.item() == "level") {
242 LevelTile* level = new LevelTile(levels_path, iter.lisp());
243 levels.push_back(level);
244 game_objects.push_back(level);
245 } else if(iter.item() == "special-tile") {
246 SpecialTile* special_tile = new SpecialTile(iter.lisp());
247 special_tiles.push_back(special_tile);
248 game_objects.push_back(special_tile);
249 } else if(iter.item() == "sprite-change") {
250 SpriteChange* sprite_change = new SpriteChange(iter.lisp());
251 sprite_changes.push_back(sprite_change);
252 game_objects.push_back(sprite_change);
253 } else if(iter.item() == "name") {
256 log_warning << "Unknown token '" << iter.item() << "' in worldmap" << std::endl;
260 throw std::runtime_error("No solid tilemap specified");
262 // search for main spawnpoint
263 for(SpawnPoints::iterator i = spawn_points.begin();
264 i != spawn_points.end(); ++i) {
266 if(sp->name == "main") {
268 tux->set_tile_pos(p);
273 } catch(std::exception& e) {
274 std::stringstream msg;
275 msg << "Problem when parsing worldmap '" << map_filename << "': " <<
277 throw std::runtime_error(msg.str());
282 WorldMap::get_level_title(LevelTile& level)
284 /** get special_tile's title */
285 level.title = "<no title>";
289 std::auto_ptr<lisp::Lisp> root (parser.parse(levels_path + level.name));
291 const lisp::Lisp* level_lisp = root->get_lisp("supertux-level");
295 level_lisp->get("name", level.title);
296 } catch(std::exception& e) {
297 log_warning << "Problem when reading leveltitle: " << e.what() << std::endl;
302 void WorldMap::calculate_total_stats()
305 for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
306 LevelTile* level = *i;
308 total_stats += level->statistics;
314 WorldMap::on_escape_press()
316 // Show or hide the menu
317 if(!Menu::current()) {
318 Menu::set_current(worldmap_menu.get());
319 tux->set_direction(D_NONE); // stop tux movement when menu is called
321 Menu::set_current(NULL);
326 WorldMap::get_next_tile(Vector pos, Direction direction)
348 WorldMap::path_ok(Direction direction, const Vector& old_pos, Vector* new_pos)
350 *new_pos = get_next_tile(old_pos, direction);
352 if (!(new_pos->x >= 0 && new_pos->x < solids->get_width()
353 && new_pos->y >= 0 && new_pos->y < solids->get_height()))
354 { // New position is outsite the tilemap
358 { // Check if the tile allows us to go to new_pos
362 return (at(old_pos)->getData() & Tile::WORLDMAP_WEST
363 && at(*new_pos)->getData() & Tile::WORLDMAP_EAST);
366 return (at(old_pos)->getData() & Tile::WORLDMAP_EAST
367 && at(*new_pos)->getData() & Tile::WORLDMAP_WEST);
370 return (at(old_pos)->getData() & Tile::WORLDMAP_NORTH
371 && at(*new_pos)->getData() & Tile::WORLDMAP_SOUTH);
374 return (at(old_pos)->getData() & Tile::WORLDMAP_SOUTH
375 && at(*new_pos)->getData() & Tile::WORLDMAP_NORTH);
378 assert(!"path_ok() can't walk if direction is NONE");
385 WorldMap::finished_level(Level* gamelevel)
387 // TODO use Level* parameter here?
388 LevelTile* level = at_level();
390 bool old_level_state = level->solved;
391 level->solved = true;
392 level->sprite->set_action("solved");
394 // deal with statistics
395 level->statistics.merge(gamelevel->stats);
396 calculate_total_stats();
399 if(World::current() != NULL)
400 World::current()->save_state();
402 if (old_level_state != level->solved && level->auto_path) {
403 // Try to detect the next direction to which we should walk
404 // FIXME: Mostly a hack
405 Direction dir = D_NONE;
407 const Tile* tile = at(tux->get_tile_pos());
409 // first, test for crossroads
410 if (tile->getData() & Tile::WORLDMAP_CNSE || tile->getData() && Tile::WORLDMAP_CNSW
411 || tile->getData() & Tile::WORLDMAP_CNEW || tile->getData() && Tile::WORLDMAP_CSEW
412 || tile->getData() & Tile::WORLDMAP_CNSEW)
414 else if (tile->getData() & Tile::WORLDMAP_NORTH
415 && tux->back_direction != D_NORTH)
417 else if (tile->getData() & Tile::WORLDMAP_SOUTH
418 && tux->back_direction != D_SOUTH)
420 else if (tile->getData() & Tile::WORLDMAP_EAST
421 && tux->back_direction != D_EAST)
423 else if (tile->getData() & Tile::WORLDMAP_WEST
424 && tux->back_direction != D_WEST)
428 tux->set_direction(dir);
432 if (level->extro_script != "") {
434 std::istringstream in(level->extro_script);
435 run_script(in, "worldmap:extro_script");
436 } catch(std::exception& e) {
437 log_fatal << "Couldn't run level-extro-script: " << e.what() << std::endl;
443 WorldMap::update(float delta)
445 Menu* menu = Menu::current();
449 if(menu == worldmap_menu.get()) {
450 switch (worldmap_menu->check())
452 case MNID_RETURNWORLDMAP: // Return to game
453 Menu::set_current(0);
455 case MNID_QUITWORLDMAP: // Quit Worldmap
456 main_loop->exit_screen();
464 // update GameObjects
465 for(GameObjects::iterator i = game_objects.begin();
466 i != game_objects.end(); ++i) {
467 GameObject* object = *i;
468 object->update(delta);
471 // remove old GameObjects
472 for(GameObjects::iterator i = game_objects.begin();
473 i != game_objects.end(); ) {
474 GameObject* object = *i;
475 if(!object->is_valid()) {
477 i = game_objects.erase(i);
484 Vector tux_pos = tux->get_pos();
485 camera_offset.x = tux_pos.x - SCREEN_WIDTH/2;
486 camera_offset.y = tux_pos.y - SCREEN_HEIGHT/2;
488 if (camera_offset.x < 0)
490 if (camera_offset.y < 0)
493 if (camera_offset.x > solids->get_width()*32 - SCREEN_WIDTH)
494 camera_offset.x = solids->get_width()*32 - SCREEN_WIDTH;
495 if (camera_offset.y > solids->get_height()*32 - SCREEN_HEIGHT)
496 camera_offset.y = solids->get_height()*32 - SCREEN_HEIGHT;
499 bool enter_level = false;
500 if(main_controller->pressed(Controller::ACTION)
501 || main_controller->pressed(Controller::JUMP)
502 || main_controller->pressed(Controller::MENU_SELECT))
504 if(main_controller->pressed(Controller::PAUSE_MENU))
507 if (enter_level && !tux->is_moving())
509 /* Check special tile action */
510 SpecialTile* special_tile = at_special_tile();
513 if (special_tile->teleport_dest != Vector(-1,-1))
515 // TODO: an animation, camera scrolling or a fading would be a nice touch
516 sound_manager->play("sounds/warp.wav");
517 tux->back_direction = D_NONE;
518 tux->set_tile_pos(special_tile->teleport_dest);
523 /* Check level action */
524 LevelTile* level = at_level();
526 log_warning << "No level to enter at: " << tux->get_tile_pos().x << ", " << tux->get_tile_pos().y << std::endl;
530 if (level->pos == tux->get_tile_pos()) {
532 Vector shrinkpos = Vector(level->pos.x*32 + 16 - camera_offset.x,
533 level->pos.y*32 + 16 - camera_offset.y);
534 std::string levelfile = levels_path + level->name;
535 main_loop->push_screen(new GameSession(levelfile, &level->statistics),
536 new ShrinkFade(shrinkpos, 0.5));
537 } catch(std::exception& e) {
538 log_fatal << "Couldn't load level: " << e.what() << std::endl;
544 // tux->set_direction(input_direction);
549 WorldMap::at(Vector p)
551 return solids->get_tile((int) p.x, (int) p.y);
557 for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
558 LevelTile* level = *i;
559 if (level->pos == tux->get_tile_pos())
567 WorldMap::at_special_tile()
569 for(SpecialTiles::iterator i = special_tiles.begin();
570 i != special_tiles.end(); ++i) {
571 SpecialTile* special_tile = *i;
572 if (special_tile->pos == tux->get_tile_pos())
580 WorldMap::at_sprite_change(const Vector& pos)
582 for(SpriteChanges::iterator i = sprite_changes.begin();
583 i != sprite_changes.end(); ++i) {
584 SpriteChange* sprite_change = *i;
585 if(sprite_change->pos == pos)
586 return sprite_change;
593 WorldMap::draw(DrawingContext& context)
595 context.push_transform();
596 context.set_translation(camera_offset);
598 for(GameObjects::iterator i = game_objects.begin();
599 i != game_objects.end(); ++i) {
600 GameObject* object = *i;
601 object->draw(context);
604 draw_status(context);
605 context.pop_transform();
609 WorldMap::draw_status(DrawingContext& context)
611 context.push_transform();
612 context.set_translation(Vector(0, 0));
614 player_status->draw(context);
616 if (!tux->is_moving()) {
617 for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
618 LevelTile* level = *i;
620 if (level->pos == tux->get_tile_pos()) {
621 if(level->title == "")
622 get_level_title(*level);
624 context.draw_text(white_text, level->title,
625 Vector(SCREEN_WIDTH/2,
626 SCREEN_HEIGHT - white_text->get_height() - 30),
627 CENTER_ALLIGN, LAYER_FOREGROUND1);
629 level->statistics.draw_worldmap_info(context);
634 for(SpecialTiles::iterator i = special_tiles.begin();
635 i != special_tiles.end(); ++i) {
636 SpecialTile* special_tile = *i;
638 if (special_tile->pos == tux->get_tile_pos()) {
639 /* Display an in-map message in the map, if any as been selected */
640 if(!special_tile->map_message.empty() && !special_tile->passive_message)
641 context.draw_text(gold_text, special_tile->map_message,
642 Vector(SCREEN_WIDTH/2,
643 SCREEN_HEIGHT - white_text->get_height() - 60),
644 CENTER_ALLIGN, LAYER_FOREGROUND1);
650 /* Display a passive message in the map, if needed */
651 if(passive_message_timer.started())
652 context.draw_text(gold_text, passive_message,
653 Vector(SCREEN_WIDTH/2, SCREEN_HEIGHT - white_text->get_height() - 60),
654 CENTER_ALLIGN, LAYER_FOREGROUND1);
656 context.pop_transform();
662 sound_manager->play_music(music);
663 Menu::set_current(NULL);
668 // register worldmap_table as worldmap in scripting
669 using namespace Scripting;
671 sq_pushroottable(global_vm);
672 sq_pushstring(global_vm, "worldmap", -1);
673 sq_pushobject(global_vm, worldmap_table);
674 if(SQ_FAILED(sq_createslot(global_vm, -3)))
675 throw SquirrelError(global_vm, "Couldn't set worldmap in roottable");
676 sq_pop(global_vm, 1);
678 if(init_script != "") {
679 std::istringstream in(init_script);
680 run_script(in, "WorldMap::init");
687 // remove worldmap_table from roottable
688 using namespace Scripting;
690 sq_pushroottable(global_vm);
691 sq_pushstring(global_vm, "worldmap", -1);
692 if(SQ_FAILED(sq_deleteslot(global_vm, -2, SQFalse)))
693 throw SquirrelError(global_vm, "Couldn't unset worldmap in roottable");
694 sq_pop(global_vm, 1);
697 static void store_float(HSQUIRRELVM vm, const char* name, float val)
699 sq_pushstring(vm, name, -1);
700 sq_pushfloat(vm, val);
701 if(SQ_FAILED(sq_createslot(vm, -3)))
702 throw Scripting::SquirrelError(vm, "Couldn't add float value to table");
706 static void store_int(HSQUIRRELVM vm, const char* name, int val)
708 sq_pushstring(vm, name, -1);
709 sq_pushinteger(vm, val);
710 if(SQ_FAILED(sq_createslot(vm, -3)))
711 throw Scripting::SquirrelError(vm, "Couldn't add float value to table");
715 static void store_string(HSQUIRRELVM vm, const char* name, const std::string& val)
717 sq_pushstring(vm, name, -1);
718 sq_pushstring(vm, val.c_str(), val.length());
719 if(SQ_FAILED(sq_createslot(vm, -3)))
720 throw Scripting::SquirrelError(vm, "Couldn't add float value to table");
723 static void store_bool(HSQUIRRELVM vm, const char* name, bool val)
725 sq_pushstring(vm, name, -1);
726 sq_pushbool(vm, val ? SQTrue : SQFalse);
727 if(SQ_FAILED(sq_createslot(vm, -3)))
728 throw Scripting::SquirrelError(vm, "Couldn't add float value to table");
731 static float read_float(HSQUIRRELVM vm, const char* name)
733 sq_pushstring(vm, name, -1);
734 if(SQ_FAILED(sq_get(vm, -2))) {
735 std::ostringstream msg;
736 msg << "Couldn't get float value for '" << name << "' from table";
737 throw Scripting::SquirrelError(vm, msg.str());
741 if(SQ_FAILED(sq_getfloat(vm, -1, &result))) {
742 std::ostringstream msg;
743 msg << "Couldn't get float value for '" << name << "' from table";
744 throw Scripting::SquirrelError(vm, msg.str());
751 static std::string read_string(HSQUIRRELVM vm, const char* name)
753 sq_pushstring(vm, name, -1);
754 if(SQ_FAILED(sq_get(vm, -2))) {
755 std::ostringstream msg;
756 msg << "Couldn't get string value for '" << name << "' from table";
757 throw Scripting::SquirrelError(vm, msg.str());
761 if(SQ_FAILED(sq_getstring(vm, -1, &result))) {
762 std::ostringstream msg;
763 msg << "Couldn't get string value for '" << name << "' from table";
764 throw Scripting::SquirrelError(vm, msg.str());
768 return std::string(result);
771 static bool read_bool(HSQUIRRELVM vm, const char* name)
773 sq_pushstring(vm, name, -1);
774 if(SQ_FAILED(sq_get(vm, -2))) {
775 std::ostringstream msg;
776 msg << "Couldn't get bool value for '" << name << "' from table";
777 throw Scripting::SquirrelError(vm, msg.str());
781 if(SQ_FAILED(sq_getbool(vm, -1, &result))) {
782 std::ostringstream msg;
783 msg << "Couldn't get bool value for '" << name << "' from table";
784 throw Scripting::SquirrelError(vm, msg.str());
788 return result == SQTrue;
792 WorldMap::save_state()
794 using namespace Scripting;
796 HSQUIRRELVM vm = global_vm;
797 int oldtop = sq_gettop(vm);
801 sq_pushroottable(vm);
802 sq_pushstring(vm, "state", -1);
803 if(SQ_FAILED(sq_get(vm, -2)))
804 throw Scripting::SquirrelError(vm, "Couldn't get state table");
806 // get or create worlds table
807 sq_pushstring(vm, "worlds", -1);
808 if(SQ_FAILED(sq_get(vm, -2))) {
809 sq_pushstring(vm, "worlds", -1);
811 if(SQ_FAILED(sq_createslot(vm, -3)))
812 throw Scripting::SquirrelError(vm, "Couldn't create state.worlds");
814 sq_pushstring(vm, "worlds", -1);
815 if(SQ_FAILED(sq_get(vm, -2)))
816 throw Scripting::SquirrelError(vm, "Couldn't create.get state.worlds");
819 sq_pushstring(vm, map_filename.c_str(), map_filename.length());
820 if(SQ_FAILED(sq_deleteslot(vm, -2, SQFalse)))
823 // construct new table for this worldmap
824 sq_pushstring(vm, map_filename.c_str(), map_filename.length());
828 sq_pushstring(vm, "tux", -1);
831 store_float(vm, "x", tux->get_tile_pos().x);
832 store_float(vm, "y", tux->get_tile_pos().y);
833 store_string(vm, "back", direction_to_string(tux->back_direction));
835 sq_createslot(vm, -3);
838 sq_pushstring(vm, "levels", -1);
841 for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
842 LevelTile* level = *i;
845 sq_pushstring(vm, level->name.c_str(), -1);
848 store_bool(vm, "solved", true);
849 // TODO write statistics
850 // i->statistics.write(writer);
852 sq_createslot(vm, -3);
856 sq_createslot(vm, -3);
858 // push world into worlds table
859 sq_createslot(vm, -3);
860 } catch(std::exception& e) {
861 sq_settop(vm, oldtop);
864 sq_settop(vm, oldtop);
868 WorldMap::load_state()
870 using namespace Scripting;
872 HSQUIRRELVM vm = global_vm;
873 int oldtop = sq_gettop(vm);
877 sq_pushroottable(vm);
878 sq_pushstring(vm, "state", -1);
879 if(SQ_FAILED(sq_get(vm, -2)))
880 throw Scripting::SquirrelError(vm, "Couldn't get state table");
883 sq_pushstring(vm, "worlds", -1);
884 if(SQ_FAILED(sq_get(vm, -2)))
885 throw Scripting::SquirrelError(vm, "Couldn't get state.worlds");
887 // get table for our world
888 sq_pushstring(vm, map_filename.c_str(), map_filename.length());
889 if(SQ_FAILED(sq_get(vm, -2)))
890 throw Scripting::SquirrelError(vm, "Couldn't get state.world.mapfilename");
893 sq_pushstring(vm, "tux", -1);
894 if(SQ_FAILED(sq_get(vm, -2)))
895 throw Scripting::SquirrelError(vm, "Couldn't get tux");
898 p.x = read_float(vm, "x");
899 p.y = read_float(vm, "y");
900 std::string back_str = read_string(vm, "back");
901 tux->back_direction = string_to_direction(back_str);
902 tux->set_tile_pos(p);
907 sq_pushstring(vm, "levels", -1);
908 if(SQ_FAILED(sq_get(vm, -2)))
909 throw Scripting::SquirrelError(vm, "Couldn't get levels");
911 for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
912 LevelTile* level = *i;
913 sq_pushstring(vm, level->name.c_str(), -1);
914 if(SQ_SUCCEEDED(sq_get(vm, -2))) {
915 level->solved = read_bool(vm, "solved");
916 level->sprite->set_action(level->solved ? "solved" : "default");
917 // i->statistics.parse(*level);
923 } catch(std::exception& e) {
924 log_debug << "Not loading worldmap state: " << e.what() << std::endl;
926 sq_settop(vm, oldtop);
930 WorldMap::level_count()
932 return levels.size();
936 WorldMap::solved_level_count()
939 for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
940 LevelTile* level = *i;
950 WorldMap::run_script(std::istream& in, const std::string& sourcename)
952 using namespace Scripting;
954 // garbage collect thread list
955 for(ScriptList::iterator i = scripts.begin();
956 i != scripts.end(); ) {
957 HSQOBJECT& object = *i;
958 HSQUIRRELVM vm = object_to_vm(object);
960 if(sq_getvmstate(vm) != SQ_VMSTATE_SUSPENDED) {
961 sq_release(global_vm, &object);
962 i = scripts.erase(i);
969 HSQOBJECT object = create_thread(global_vm);
970 scripts.push_back(object);
972 HSQUIRRELVM vm = object_to_vm(object);
974 // set worldmap_table as roottable for the thread
975 sq_pushobject(vm, worldmap_table);
978 compile_and_run(vm, in, sourcename);
983 } // namespace WorldMapNS