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