X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fworldmap.cpp;h=9ef7b6d3ec2765088c49133758313bbf5d34708e;hb=69f9e7f80e7c9e79f9da3672338aa08c447ebef2;hp=872c2859a4c4092701d8173e1c6e6dfa35eba5a8;hpb=8f21eeeae4a09dc90aada92fc5afdc9297bfd0f0;p=supertux.git diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 872c2859a..9ef7b6d3e 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -26,32 +26,32 @@ #include #include -#include "gettext.h" -#include "video/surface.h" -#include "video/screen.h" -#include "video/drawing_context.h" -#include "sprite/sprite_manager.h" -#include "audio/sound_manager.h" -#include "lisp/parser.h" -#include "lisp/lisp.h" -#include "lisp/list_iterator.h" -#include "lisp/writer.h" -#include "game_session.h" -#include "sector.h" -#include "worldmap.h" -#include "resources.h" -#include "misc.h" -#include "player_status.h" -#include "textscroller.h" -#include "main.h" -#include "spawn_point.h" -#include "file_system.h" -#include "gui/menu.h" -#include "gui/mousecursor.h" -#include "control/joystickkeyboardcontroller.h" -#include "object/background.h" -#include "object/tilemap.h" -#include "scripting/script_interpreter.h" +#include "gettext.hpp" +#include "video/surface.hpp" +#include "video/screen.hpp" +#include "video/drawing_context.hpp" +#include "sprite/sprite_manager.hpp" +#include "audio/sound_manager.hpp" +#include "lisp/parser.hpp" +#include "lisp/lisp.hpp" +#include "lisp/list_iterator.hpp" +#include "lisp/writer.hpp" +#include "game_session.hpp" +#include "sector.hpp" +#include "worldmap.hpp" +#include "resources.hpp" +#include "misc.hpp" +#include "player_status.hpp" +#include "textscroller.hpp" +#include "main.hpp" +#include "spawn_point.hpp" +#include "file_system.hpp" +#include "gui/menu.hpp" +#include "gui/mousecursor.hpp" +#include "control/joystickkeyboardcontroller.hpp" +#include "object/background.hpp" +#include "object/tilemap.hpp" +#include "scripting/script_interpreter.hpp" Menu* worldmap_menu = 0; @@ -352,17 +352,13 @@ WorldMap::WorldMap() tux = new Tux(this); add_object(tux); - leveldot_green - = new Surface(datadir + "/images/tiles/worldmap/leveldot_green.png", true); - leveldot_red - = new Surface(datadir + "/images/tiles/worldmap/leveldot_red.png", true); - messagedot - = new Surface(datadir + "/images/tiles/worldmap/messagedot.png", true); - teleporterdot - = new Surface(datadir + "/images/tiles/worldmap/teleporterdot.png", true); + leveldot_green= new Surface("images/tiles/worldmap/leveldot_green.png", true); + leveldot_red = new Surface("images/tiles/worldmap/leveldot_red.png", true); + messagedot = new Surface("images/tiles/worldmap/messagedot.png", true); + teleporterdot = new Surface("images/tiles/worldmap/teleporterdot.png", true); name = ""; - music = "salcon.mod"; + music = "salcon.ogg"; intro_displayed = false; total_stats.reset(); @@ -415,12 +411,11 @@ WorldMap::load_map() try { lisp::Parser parser; - std::string filename = get_resource_filename(map_filename); - std::auto_ptr root (parser.parse(filename)); + std::auto_ptr root (parser.parse(map_filename)); const lisp::Lisp* lisp = root->get_lisp("supertux-worldmap"); if(!lisp) - throw new std::runtime_error("file isn't a supertux-worldmap file."); + throw std::runtime_error("file isn't a supertux-worldmap file."); clear_objects(); lisp::ListIterator iter(lisp); @@ -548,8 +543,7 @@ WorldMap::get_level_title(Level& level) try { lisp::Parser parser; - std::auto_ptr root ( - parser.parse(get_resource_filename(levels_path + level.name))); + std::auto_ptr root (parser.parse(levels_path + level.name)); const lisp::Lisp* level_lisp = root->get_lisp("supertux-level"); if(!level_lisp) @@ -719,7 +713,7 @@ WorldMap::update(float delta) if (special_tile->teleport_dest != Vector(-1,-1)) { // TODO: an animation, camera scrolling or a fading would be a nice touch - sound_manager->play_sound("warp"); + sound_manager->play("sounds/warp.wav"); tux->back_direction = D_NONE; tux->set_tile_pos(special_tile->teleport_dest); SDL_Delay(1000); @@ -745,7 +739,7 @@ WorldMap::update(float delta) // do a shriking fade to the level shrink_fade(Vector((level->pos.x*32 + 16 + offset.x), (level->pos.y*32 + 16 + offset.y)), 500); - GameSession session(get_resource_filename(levels_path + level->name), + GameSession session(levels_path + level->name, ST_GL_LOAD_LEVEL_FILE, &level->statistics); switch (session.run()) @@ -834,7 +828,7 @@ WorldMap::update(float delta) break; } - sound_manager->play_music(song); + sound_manager->play_music(std::string("music/") + music); Menu::set_current(0); if (!savegame_file.empty()) savegame(savegame_file); @@ -843,11 +837,15 @@ WorldMap::update(float delta) the level (in case there is one), don't show anything */ if(level_finished) { if (level->extro_script != "") { - ScriptInterpreter* interpreter = new ScriptInterpreter(levels_path); - std::istringstream in(level->extro_script); - interpreter->load_script(in, "level-extro-script"); - interpreter->start_script(); - add_object(interpreter); + try { + std::auto_ptr interpreter + (new ScriptInterpreter(levels_path)); + std::istringstream in(level->extro_script); + interpreter->run_script(in, "level-extro-script"); + add_object(interpreter.release()); + } catch(std::exception& e) { + std::cerr << "Couldn't run level-extro-script:" << e.what() << "\n"; + } } if (!level->next_worldmap.empty()) @@ -972,7 +970,7 @@ WorldMap::draw_status(DrawingContext& context) } } /* Display a passive message in the map, if needed */ - if(passive_message_timer.check()) + if(passive_message_timer.started()) context.draw_text(gold_text, passive_message, Vector(SCREEN_WIDTH/2, SCREEN_HEIGHT - white_text->get_height() - 60), CENTER_ALLIGN, LAYER_FOREGROUND1); @@ -987,15 +985,19 @@ WorldMap::display() quit = false; - song = sound_manager->load_music(datadir + "/music/" + music); - sound_manager->play_music(song); + sound_manager->play_music(std::string("music/") + music); if(!intro_displayed && intro_script != "") { - ScriptInterpreter* interpreter = new ScriptInterpreter(levels_path); - std::istringstream in(intro_script); - interpreter->load_script(in, "worldmap-intro-script"); - interpreter->start_script(); - add_object(interpreter); + try { + std::auto_ptr interpreter + (new ScriptInterpreter(levels_path)); + std::istringstream in(intro_script); + interpreter->run_script(in, "worldmap-intro-script"); + add_object(interpreter.release()); + } catch(std::exception& e) { + std::cerr << "Couldn't execute worldmap-intro-script: " + << e.what() << "\n"; + } intro_displayed = true; } @@ -1032,6 +1034,7 @@ WorldMap::display() context.pop_transform(); get_input(); update(elapsed_time); + sound_manager->update(); if(Menu::current()) { Menu::current()->draw(context); @@ -1047,8 +1050,7 @@ WorldMap::savegame(const std::string& filename) if(filename == "") return; - std::ofstream file(filename.c_str(), std::ios::out); - lisp::Writer writer(file); + lisp::Writer writer(filename); int nb_solved_levels = 0, total_levels = 0; for(Levels::iterator i = levels.begin(); i != levels.end(); ++i) {