Level statistics panel shown during level's end sequence
[supertux.git] / src / game_session.cpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 //  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; either version 2
11 //  of the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 // 
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 #include <config.h>
22
23 #include <fstream>
24 #include <sstream>
25 #include <cassert>
26 #include <cstdio>
27 #include <cstdlib>
28 #include <cmath>
29 #include <cstring>
30 #include <cerrno>
31 #include <unistd.h>
32 #include <ctime>
33 #include <stdexcept>
34
35 #include <SDL.h>
36
37 #include "game_session.hpp"
38 #include "msg.hpp"
39 #include "worldmap.hpp"
40 #include "mainloop.hpp"
41 #include "video/screen.hpp"
42 #include "audio/sound_manager.hpp"
43 #include "gui/menu.hpp"
44 #include "sector.hpp"
45 #include "level.hpp"
46 #include "tile.hpp"
47 #include "player_status.hpp"
48 #include "object/particlesystem.hpp"
49 #include "object/background.hpp"
50 #include "object/gradient.hpp"
51 #include "object/tilemap.hpp"
52 #include "object/camera.hpp"
53 #include "object/player.hpp"
54 #include "object/level_time.hpp"
55 #include "lisp/lisp.hpp"
56 #include "lisp/parser.hpp"
57 #include "resources.hpp"
58 #include "worldmap.hpp"
59 #include "misc.hpp"
60 #include "statistics.hpp"
61 #include "timer.hpp"
62 #include "object/fireworks.hpp"
63 #include "textscroller.hpp"
64 #include "control/codecontroller.hpp"
65 #include "control/joystickkeyboardcontroller.hpp"
66 #include "main.hpp"
67 #include "file_system.hpp"
68 #include "gameconfig.hpp"
69 #include "gettext.hpp"
70 #include "exceptions.hpp"
71 #include "flip_level_transformer.hpp"
72
73 // the engine will be run with a logical framerate of 64fps.
74 // We chose 64fps here because it is a power of 2, so 1/64 gives an "even"
75 // binary fraction...
76 static const float LOGICAL_FPS = 64.0;
77
78 namespace {
79   const char* consoleCommands[] = {
80           "foo",
81           "whereami",
82           "camera",
83           "grow", 
84           "fire", 
85           "ice",
86           "coins",
87           "numberofthebeast",
88           "grease",
89           "invincible",
90           "mortal",
91           "shrink", 
92           "kill",
93           "gotoend",
94           "flip",
95           "finish",
96           "restart",
97           "quit"
98   };
99 }
100
101 using namespace WorldMapNS;
102
103 GameSession* GameSession::current_ = 0;
104
105 GameSession::GameSession(const std::string& levelfile_, GameSessionMode mode,
106     Statistics* statistics)
107   : level(0), currentsector(0), mode(mode),
108     end_sequence(NO_ENDSEQUENCE), end_sequence_controller(0),
109     levelfile(levelfile_), best_level_statistics(statistics),
110     capture_demo_stream(0), playback_demo_stream(0), demo_controller(0)
111 {
112   current_ = this;
113   currentsector = 0;
114   
115   game_pause = false;
116   fps_fps = 0;
117
118   for (uint16_t i=0; i < sizeof(::consoleCommands)/sizeof(typeof(consoleCommands[0])); i++) {
119     Console::registerCommand(consoleCommands[i], this);
120   }
121
122   statistics_backdrop = new Surface("images/engine/menu/score-backdrop.png");
123
124   restart_level(true);
125 }
126
127 void
128 GameSession::restart_level(bool fromBeginning)
129 {
130   game_pause   = false;
131   end_sequence = NO_ENDSEQUENCE;
132
133   main_controller->reset();
134
135   delete level;
136   currentsector = 0;
137
138   level = new Level;
139   level->load(levelfile);
140
141   global_stats.reset();
142   global_stats.set_total_points(COINS_COLLECTED_STAT, level->get_total_coins());
143   global_stats.set_total_points(BADGUYS_KILLED_STAT, level->get_total_badguys());
144   
145   // get time
146   int time = 0;
147   for(std::vector<Sector*>::iterator i = level->sectors.begin(); i != level->sectors.end(); ++i)
148   {
149     Sector* sec = *i;
150
151     for(std::vector<GameObject*>::iterator j = sec->gameobjects.begin();
152         j != sec->gameobjects.end(); ++j)
153     {
154       GameObject* obj = *j;
155       
156       LevelTime* lt = dynamic_cast<LevelTime*> (obj);
157       if(lt)
158         time += int(lt->get_level_time());
159     }
160   }
161   global_stats.set_total_points(TIME_NEEDED_STAT, (time == 0) ? -1 : time);
162
163   if (fromBeginning) reset_sector="";
164   if(reset_sector != "") {
165     currentsector = level->get_sector(reset_sector);
166     if(!currentsector) {
167       std::stringstream msg;
168       msg << "Couldn't find sector '" << reset_sector << "' for resetting tux.";
169       throw std::runtime_error(msg.str());
170     }
171     currentsector->activate(reset_pos);
172   } else {
173     currentsector = level->get_sector("main");
174     if(!currentsector)
175       throw std::runtime_error("Couldn't find main sector");
176     currentsector->activate("main");
177   }
178   
179   if(mode == ST_GL_PLAY || mode == ST_GL_LOAD_LEVEL_FILE)
180     levelintro();
181
182   currentsector->play_music(LEVEL_MUSIC);
183
184   if(capture_file != "")
185     record_demo(capture_file);
186 }
187
188 GameSession::~GameSession()
189 {
190   delete capture_demo_stream;
191   delete playback_demo_stream;
192   delete demo_controller;
193
194   delete end_sequence_controller;
195   delete level;
196   for (uint16_t i=0; i < sizeof(::consoleCommands)/sizeof(typeof(consoleCommands[0])); i++) {
197     Console::unregisterCommand(consoleCommands[i], this);
198   }
199
200   delete statistics_backdrop;
201
202   current_ = NULL;
203 }
204
205 void
206 GameSession::record_demo(const std::string& filename)
207 {
208   delete capture_demo_stream;
209   
210   capture_demo_stream = new std::ofstream(filename.c_str()); 
211   if(!capture_demo_stream->good()) {
212     std::stringstream msg;
213     msg << "Couldn't open demo file '" << filename << "' for writing.";
214     throw std::runtime_error(msg.str());
215   }
216   capture_file = filename;
217 }
218
219 void
220 GameSession::play_demo(const std::string& filename)
221 {
222   delete playback_demo_stream;
223   delete demo_controller;
224   
225   playback_demo_stream = new std::ifstream(filename.c_str());
226   if(!playback_demo_stream->good()) {
227     std::stringstream msg;
228     msg << "Couldn't open demo file '" << filename << "' for reading.";
229     throw std::runtime_error(msg.str());
230   }
231
232   Player& tux = *currentsector->player;
233   demo_controller = new CodeController();
234   tux.set_controller(demo_controller);
235 }
236
237 void
238 GameSession::levelintro()
239 {
240   char str[60];
241
242   sound_manager->stop_music();
243
244   DrawingContext context;
245   for(Sector::GameObjects::iterator i = currentsector->gameobjects.begin();
246       i != currentsector->gameobjects.end(); ++i) {
247     Background* background = dynamic_cast<Background*> (*i);
248     if(background) {
249       background->draw(context);
250     }
251     Gradient* gradient = dynamic_cast<Gradient*> (*i);
252     if(gradient) {
253       gradient->draw(context);
254     }
255   }
256
257 //  context.draw_text(gold_text, level->get_name(), Vector(SCREEN_WIDTH/2, 160),
258 //      CENTER_ALLIGN, LAYER_FOREGROUND1);
259   context.draw_center_text(gold_text, level->get_name(), Vector(0, 160),
260       LAYER_FOREGROUND1);
261
262   sprintf(str, "Coins: %d", player_status->coins);
263   context.draw_text(white_text, str, Vector(SCREEN_WIDTH/2, 210),
264       CENTER_ALLIGN, LAYER_FOREGROUND1);
265
266   if((level->get_author().size()) && (level->get_author() != "SuperTux Team"))
267     //TODO make author check case/blank-insensitive
268     context.draw_text(white_small_text,
269       std::string(_("contributed by ")) + level->get_author(), 
270       Vector(SCREEN_WIDTH/2, 350), CENTER_ALLIGN, LAYER_FOREGROUND1);
271
272
273   if(best_level_statistics != NULL)
274     best_level_statistics->draw_message_info(context, _("Best Level Statistics"));
275
276   wait_for_event(1.0, 3.0);
277 }
278
279 void
280 GameSession::on_escape_press()
281 {
282   if(currentsector->player->is_dying() || end_sequence != NO_ENDSEQUENCE)
283     return;   // don't let the player open the menu, when he is dying
284   
285   if(mode == ST_GL_TEST) {
286     main_loop->exit_screen();
287   } else if (!Menu::current()) {
288     Menu::set_current(game_menu);
289     game_menu->set_active_item(MNID_CONTINUE);
290     game_pause = true;
291   } else {
292     game_pause = false;
293   }
294 }
295
296 void
297 GameSession::process_events()
298 {
299   Player& tux = *currentsector->player;
300
301   // end of pause mode?
302   if(!Menu::current() && game_pause) {
303     game_pause = false;
304   }
305
306   if (end_sequence != NO_ENDSEQUENCE) {
307     if(end_sequence_controller == 0) {
308       end_sequence_controller = new CodeController();
309       tux.set_controller(end_sequence_controller);
310     }
311
312     end_sequence_controller->press(Controller::RIGHT);
313     
314     if (int(last_x_pos) == int(tux.get_pos().x))
315       end_sequence_controller->press(Controller::JUMP);    
316     last_x_pos = tux.get_pos().x;
317   }
318
319   // playback a demo?
320   if(playback_demo_stream != 0) {
321     demo_controller->update();
322     char left = false;
323     char right = false;
324     char up = false;
325     char down = false;
326     char jump = false;
327     char action = false;
328     playback_demo_stream->get(left);
329     playback_demo_stream->get(right);
330     playback_demo_stream->get(up);
331     playback_demo_stream->get(down);
332     playback_demo_stream->get(jump);
333     playback_demo_stream->get(action);
334     demo_controller->press(Controller::LEFT, left);
335     demo_controller->press(Controller::RIGHT, right);
336     demo_controller->press(Controller::UP, up);
337     demo_controller->press(Controller::DOWN, down);
338     demo_controller->press(Controller::JUMP, jump);
339     demo_controller->press(Controller::ACTION, action);
340   }
341
342   // save input for demo?
343   if(capture_demo_stream != 0) {
344     capture_demo_stream ->put(main_controller->hold(Controller::LEFT));
345     capture_demo_stream ->put(main_controller->hold(Controller::RIGHT));
346     capture_demo_stream ->put(main_controller->hold(Controller::UP));
347     capture_demo_stream ->put(main_controller->hold(Controller::DOWN));
348     capture_demo_stream ->put(main_controller->hold(Controller::JUMP));   
349     capture_demo_stream ->put(main_controller->hold(Controller::ACTION));
350   }
351 }
352
353 bool
354 GameSession::consoleCommand(std::string command, std::vector<std::string> arguments)
355 {
356   if (command == "foo") {
357     msg_info << "bar" << std::endl;
358     return true;
359   }
360
361   if (currentsector == 0) return false;
362   Player& tux = *currentsector->player;
363   
364   // Cheating words (the goal of this is really for debugging,
365   // but could be used for some cheating, nothing wrong with that)
366   if (command == "grow") {
367     tux.set_bonus(GROWUP_BONUS, false);
368     return true;
369   }
370   if (command == "fire") {
371     tux.set_bonus(FIRE_BONUS, false);
372     return true;
373   }
374   if (command == "ice") {
375     tux.set_bonus(ICE_BONUS, false);
376     return true;
377   }
378   if (command == "coins") {
379     if ((arguments.size() < 1) || (!Console::string_is<int>(arguments[0]))) {
380       msg_info << "Usage: coins <number>" << std::endl;
381     } else {
382       player_status->coins = Console::string_to<int>(arguments[0]);
383     }
384     return true;
385   }
386   if (command == "numberofthebeast") {
387     player_status->coins += 55;
388     return true;
389   }
390   if (command == "grease") {
391     tux.physic.set_velocity_x(tux.physic.get_velocity_x()*3);
392     return true;
393   }
394   if (command == "invincible") {
395     // be invincle for the rest of the level
396     tux.invincible_timer.start(10000);
397     return true;
398   }
399   if (command == "mortal") {
400     // give up invincibility
401     tux.invincible_timer.stop();
402     return true;
403   }
404   if (command == "shrink") {
405     // remove powerups
406     tux.kill(tux.SHRINK);
407     return true;
408   }
409   if (command == "kill") {
410     tux.kill(tux.KILL);
411     return true;
412   }
413   if (command == "restart") {
414     restart_level(true);
415     return true;
416   }
417   if (command == "whereami") {
418     msg_info << "You are at x " << tux.get_pos().x << ", y " << tux.get_pos().y << std::endl;
419     return true;
420   }
421   if (command == "gotoend") {
422     // goes to the end of the level
423     tux.move(Vector(
424           (currentsector->solids->get_width()*32) - (SCREEN_WIDTH*2), 0));
425     currentsector->camera->reset(
426         Vector(tux.get_pos().x, tux.get_pos().y));
427     return true;
428   }
429   if (command == "flip") {
430     FlipLevelTransformer flip_transformer;
431     flip_transformer.transform(GameSession::current()->get_current_level());
432     return true;
433   }
434   if (command == "finish") {
435     finish(true);
436     return true;
437   }
438   if (command == "camera") {
439     msg_info << "Camera is at " << Sector::current()->camera->get_translation().x << "," << Sector::current()->camera->get_translation().y << std::endl;
440     return true;
441   }
442   if (command == "quit") {
443     main_loop->quit();
444     return true;
445   }
446
447   return false;
448 }
449
450 void
451 GameSession::check_end_conditions()
452 {
453   Player* tux = currentsector->player;
454
455   /* End of level? */
456   if(end_sequence && endsequence_timer.check()) {
457     finish(true);
458     return;
459   } else if (!end_sequence && tux->is_dead()) {
460     if (player_status->coins < 0) { 
461       // No more coins: restart level from beginning
462       player_status->coins = 0;
463       restart_level(true);
464     } else { 
465       // Still has coins: restart level from last reset point
466       restart_level(false);
467     }
468     
469     return;
470   }
471 }
472
473 void 
474 GameSession::draw(DrawingContext& context)
475 {
476   currentsector->draw(context);
477   drawstatus(context);
478
479   if(game_pause)
480     draw_pause(context);
481 }
482
483 void
484 GameSession::draw_pause(DrawingContext& context)
485 {
486   context.draw_filled_rect(
487       Vector(0,0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
488       Color(.2, .2, .2, .5), LAYER_FOREGROUND1);
489 }
490   
491 void
492 GameSession::process_menu()
493 {
494   Menu* menu = Menu::current();
495   if(menu) {
496     menu->update();
497
498     if(menu == game_menu) {
499       switch (game_menu->check()) {
500         case MNID_CONTINUE:
501           Menu::set_current(0);
502           break;
503         case MNID_ABORTLEVEL:
504           Menu::set_current(0);
505           main_loop->exit_screen();
506           break;
507       }
508     } else if(menu == options_menu) {
509       process_options_menu();
510     }
511   }
512 }
513
514 void
515 GameSession::setup()
516 {
517   Menu::set_current(NULL);
518   current_ = this;
519
520   // Eat unneeded events
521   SDL_Event event;
522   while(SDL_PollEvent(&event))
523   {}
524 }
525
526 void
527 GameSession::update(float elapsed_time)
528 {
529   process_events();
530   process_menu();
531
532   check_end_conditions();
533
534   // handle controller
535   if(main_controller->pressed(Controller::PAUSE_MENU))
536     on_escape_press();
537   
538   // respawning in new sector?
539   if(newsector != "" && newspawnpoint != "") {
540     Sector* sector = level->get_sector(newsector);
541     if(sector == 0) {
542       msg_warning << "Sector '" << newsector << "' not found" << std::endl;
543     }
544     sector->activate(newspawnpoint);
545     sector->play_music(LEVEL_MUSIC);
546     currentsector = sector;
547     newsector = "";
548     newspawnpoint = "";
549   }
550
551   // Update the world state and all objects in the world
552   if(!game_pause) {
553     // Update the world
554     if (end_sequence == ENDSEQUENCE_RUNNING) {
555       currentsector->update(elapsed_time/2);
556     } else if(end_sequence == NO_ENDSEQUENCE) {
557       if(!currentsector->player->growing_timer.started())
558         currentsector->update(elapsed_time);
559     } 
560   }
561
562   // update sounds
563   sound_manager->set_listener_position(currentsector->player->get_pos());
564
565   /* Handle music: */
566   if (currentsector->player->invincible_timer.started() && 
567       currentsector->player->invincible_timer.get_timeleft() 
568       > TUX_INVINCIBLE_TIME_WARNING && !end_sequence) {
569     currentsector->play_music(HERRING_MUSIC);
570   } else if(currentsector->get_music_type() != LEVEL_MUSIC && !end_sequence) {
571     currentsector->play_music(LEVEL_MUSIC);
572   }
573 }
574
575 #if 0
576 GameSession::ExitStatus
577 GameSession::run()
578 {
579   Menu::set_current(0);
580   current_ = this;
581   
582   int fps_cnt = 0;
583
584   // Eat unneeded events
585   SDL_Event event;
586   while(SDL_PollEvent(&event))
587   {}
588
589   draw();
590
591   Uint32 fps_ticks = SDL_GetTicks();
592   Uint32 fps_nextframe_ticks = SDL_GetTicks();
593   Uint32 ticks;
594   bool skipdraw = false;
595
596   while (exit_status == ES_NONE) {
597     // we run in a logical framerate so elapsed time is a constant
598     // This will make the game run determistic and not different on different
599     // machines
600     static const float elapsed_time = 1.0 / LOGICAL_FPS;
601     // old code... float elapsed_time = float(ticks - lastticks) / 1000.;
602     if(!game_pause)
603       game_time += elapsed_time;
604
605     // regulate fps
606     ticks = SDL_GetTicks();
607     if(ticks > fps_nextframe_ticks) {
608       if(skipdraw == true) {
609         // already skipped last frame? we have to slow down the game then...
610         skipdraw = false;
611         fps_nextframe_ticks -= (Uint32) (1000.0 / LOGICAL_FPS);
612       } else {
613         // don't draw all frames when we're getting too slow
614         skipdraw = true;
615       }
616     } else {
617       skipdraw = false;
618       while(fps_nextframe_ticks > ticks) {
619         /* just wait */
620         // If we really have to wait long, then do an imprecise SDL_Delay()
621         Uint32 diff = fps_nextframe_ticks - ticks;
622         if(diff > 15) {
623           SDL_Delay(diff - 10);
624         } 
625         ticks = SDL_GetTicks();
626       }
627     }
628     fps_nextframe_ticks = ticks + (Uint32) (1000.0 / LOGICAL_FPS);
629
630     process_events();
631     process_menu();
632
633     // Update the world state and all objects in the world
634     if(!game_pause)
635     {
636       // Update the world
637       check_end_conditions();
638       if (end_sequence == ENDSEQUENCE_RUNNING)
639         update(elapsed_time/2);
640       else if(end_sequence == NO_ENDSEQUENCE)
641         update(elapsed_time);
642     }
643
644     if(!skipdraw)
645       draw();
646
647     // update sounds
648     sound_manager->update();
649
650     /* Time stops in pause mode */
651     if(game_pause || Menu::current())
652     {
653       continue;
654     }
655
656     /* Handle music: */
657     if (currentsector->player->invincible_timer.started() && 
658             currentsector->player->invincible_timer.get_timeleft() 
659             > TUX_INVINCIBLE_TIME_WARNING && !end_sequence)
660     {
661       currentsector->play_music(HERRING_MUSIC);
662     }
663     /* or just normal music? */
664     else if(currentsector->get_music_type() != LEVEL_MUSIC && !end_sequence)
665     {
666       currentsector->play_music(LEVEL_MUSIC);
667     }
668
669     /* Calculate frames per second */
670     if(config->show_fps)
671     {
672       ++fps_cnt;
673       
674       if(SDL_GetTicks() - fps_ticks >= 500)
675       {
676         fps_fps = (float) fps_cnt / .5;
677         fps_cnt = 0;
678         fps_ticks = SDL_GetTicks();
679       }
680     }
681   }
682  
683   // just in case
684   currentsector = 0;
685   main_controller->reset();
686   return exit_status;
687 }
688 #endif
689
690 void
691 GameSession::finish(bool win)
692 {
693   if(win) {
694     if(WorldMap::current())
695       WorldMap::current()->finished_level(levelfile);
696   }
697   
698   main_loop->exit_screen();
699 }
700
701 void
702 GameSession::respawn(const std::string& sector, const std::string& spawnpoint)
703 {
704   newsector = sector;
705   newspawnpoint = spawnpoint;
706 }
707
708 void
709 GameSession::set_reset_point(const std::string& sector, const Vector& pos)
710 {
711   reset_sector = sector;
712   reset_pos = pos;
713 }
714
715 std::string
716 GameSession::get_working_directory()
717 {
718   return FileSystem::dirname(levelfile);
719 }
720
721 void
722 GameSession::display_info_box(const std::string& text)
723 {
724   InfoBox* box = new InfoBox(text);
725
726   bool running = true;
727   DrawingContext context;
728   
729   while(running)  {
730
731     main_controller->update();
732     SDL_Event event;
733     while (SDL_PollEvent(&event)) {
734       main_controller->process_event(event);
735       if(event.type == SDL_QUIT)
736         throw graceful_shutdown();
737     }
738
739     if(main_controller->pressed(Controller::JUMP)
740         || main_controller->pressed(Controller::ACTION)
741         || main_controller->pressed(Controller::PAUSE_MENU)
742         || main_controller->pressed(Controller::MENU_SELECT))
743       running = false;
744     else if(main_controller->pressed(Controller::DOWN))
745       box->scrolldown();
746     else if(main_controller->pressed(Controller::UP))
747       box->scrollup();
748     box->draw(context);
749     draw(context);
750     context.do_drawing();
751     sound_manager->update();
752   }
753
754   delete box;
755 }
756
757 void
758 GameSession::start_sequence(const std::string& sequencename)
759 {
760   if(sequencename == "endsequence" || sequencename == "fireworks") {
761     if(end_sequence)
762       return;
763
764     end_sequence = ENDSEQUENCE_RUNNING;
765     endsequence_timer.start(7.3);
766     last_x_pos = -1;
767     sound_manager->play_music("music/leveldone.ogg", false);
768     currentsector->player->invincible_timer.start(7.3);
769
770     // Stop all clocks.
771     for(std::vector<GameObject*>::iterator i = currentsector->gameobjects.begin();
772         i != currentsector->gameobjects.end(); ++i)
773     {
774       GameObject* obj = *i;
775
776       LevelTime* lt = dynamic_cast<LevelTime*> (obj);
777       if(lt)
778         lt->stop();
779     }
780
781     // add time spent to statistics
782     int tottime = 0, remtime = 0;
783     for(std::vector<Sector*>::iterator i = level->sectors.begin(); i != level->sectors.end(); ++i)
784     {
785       Sector* sec = *i;
786
787       for(std::vector<GameObject*>::iterator j = sec->gameobjects.begin();
788           j != sec->gameobjects.end(); ++j)
789       {
790         GameObject* obj = *j;
791
792         LevelTime* lt = dynamic_cast<LevelTime*> (obj);
793         if(lt)
794         {
795           tottime += int(lt->get_level_time());
796           remtime += int(lt->get_remaining_time());
797         }
798       }
799     }
800     global_stats.set_points(TIME_NEEDED_STAT, (tottime == 0 ? -1 : (tottime-remtime)));
801
802     if(sequencename == "fireworks") {
803       currentsector->add_object(new Fireworks());
804     }
805   } else if(sequencename == "stoptux") {
806     if(!end_sequence) {
807       msg_warning << "Final target reached without an active end sequence" << std::endl;
808       this->start_sequence("endsequence");
809     }
810     end_sequence =  ENDSEQUENCE_WAITING;
811   } else {
812     msg_warning << "Unknown sequence '" << sequencename << "'" << std::endl;
813   }
814 }
815
816 /* (Status): */
817 void
818 GameSession::drawstatus(DrawingContext& context)
819 {
820   player_status->draw(context);
821
822   if(config->show_fps) {
823     char str[60];
824     snprintf(str, sizeof(str), "%3.1f", fps_fps);
825     const char* fpstext = "FPS";
826     context.draw_text(white_text, fpstext, Vector(SCREEN_WIDTH - white_text->get_text_width(fpstext) - gold_text->get_text_width(" 99999") - BORDER_X, BORDER_Y + 20), LEFT_ALLIGN, LAYER_FOREGROUND1);
827     context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y + 20), RIGHT_ALLIGN, LAYER_FOREGROUND1);
828   }
829
830   // draw level stats while end_sequence is running
831   if (end_sequence) {
832     global_stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop);
833   }
834 }
835