1 // $Id: main.cpp 3275 2006-04-09 00:32:34Z sommer $
4 // Copyright (C) 2005 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include "textscroller.hpp"
28 #include "functions.hpp"
29 #include "game_session.hpp"
30 #include "tinygettext/tinygettext.hpp"
31 #include "physfs/physfs_stream.hpp"
32 #include "script_manager.hpp"
33 #include "resources.hpp"
34 #include "gettext.hpp"
36 #include "mainloop.hpp"
37 #include "worldmap.hpp"
39 #include "squirrel_error.hpp"
40 #include "wrapper_util.hpp"
45 int display(HSQUIRRELVM vm)
47 Console::output << squirrel2string(vm, -1) << std::endl;
51 void wait(HSQUIRRELVM vm, float seconds)
53 script_manager->set_wakeup_event(vm, ScriptManager::TIME, seconds);
56 void wait_for_screenswitch(HSQUIRRELVM vm)
58 script_manager->set_wakeup_event(vm, ScriptManager::SCREEN_SWITCHED);
61 std::string translate(const std::string& text)
63 return dictionary_manager.get_dictionary().translate(text);
66 void display_text_file(const std::string& filename)
68 main_loop->push_screen(new TextScroller(filename));
71 void load_worldmap(const std::string& filename)
73 using namespace WorldMapNS;
75 std::auto_ptr<WorldMap> worldmap(new WorldMap());
76 worldmap->loadmap(filename);
77 main_loop->push_screen(worldmap.release());
80 void load_level(const std::string& filename)
82 main_loop->push_screen(new GameSession(filename, ST_GL_PLAY));
85 static SQInteger squirrel_read_char(SQUserPointer file)
87 std::istream* in = reinterpret_cast<std::istream*> (file);
96 void import(HSQUIRRELVM vm, const std::string& filename)
98 IFileStream in(filename);
100 if(SQ_FAILED(sq_compile(vm, squirrel_read_char, &in,
101 filename.c_str(), SQTrue)))
102 throw SquirrelError(vm, "Couldn't parse script");
104 sq_pushroottable(vm);
105 if(SQ_FAILED(sq_call(vm, 1, SQFalse))) {
107 throw SquirrelError(vm, "Couldn't execute script");
112 void add_key(int new_key)
114 player_status->set_keys(new_key);