// $Id$
-//
+//
// SuperTux
-// Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
-// Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
-// Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-//
+//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <SDL.h>
#include "game_session.hpp"
-#include "msg.hpp"
+#include "log.hpp"
#include "worldmap.hpp"
#include "mainloop.hpp"
#include "video/screen.hpp"
#include "lisp/lisp.hpp"
#include "lisp/parser.hpp"
#include "resources.hpp"
-#include "worldmap.hpp"
#include "misc.hpp"
#include "statistics.hpp"
#include "timer.hpp"
// binary fraction...
static const float LOGICAL_FPS = 64.0;
-namespace {
- const char* consoleCommands[] = {
- "foo",
- "whereami",
- "camera",
- "grease",
- "invincible",
- "mortal",
- "shrink",
- "kill",
- "gotoend",
- "flip",
- "finish",
- "restart",
- "quit"
- };
-}
-
using namespace WorldMapNS;
GameSession* GameSession::current_ = 0;
game_pause = false;
fps_fps = 0;
- for (uint16_t i=0; i < sizeof(::consoleCommands)/sizeof(typeof(consoleCommands[0])); i++) {
- Console::registerCommand(consoleCommands[i], this);
- }
-
- statistics_backdrop = new Surface("images/engine/menu/score-backdrop.png");
+ statistics_backdrop.reset(new Surface("images/engine/menu/score-backdrop.png"));
restart_level(true);
}
main_controller->reset();
- delete level;
currentsector = 0;
- level = new Level;
+ level.reset(new Level);
level->load(levelfile);
global_stats.reset();
delete demo_controller;
delete end_sequence_controller;
- delete level;
-
- delete statistics_backdrop;
current_ = NULL;
}
}
}
-bool
-GameSession::consoleCommand(std::string command, std::vector<std::string>)
-{
- if (command == "foo") {
- msg_info << "bar" << std::endl;
- return true;
- }
-
- if (currentsector == 0) return false;
- Player& tux = *currentsector->player;
-
- // Cheating words (the goal of this is really for debugging,
- // but could be used for some cheating, nothing wrong with that)
- if (command == "grease") {
- tux.physic.set_velocity_x(tux.physic.get_velocity_x()*3);
- return true;
- }
- if (command == "invincible") {
- // be invincle for the rest of the level
- tux.invincible_timer.start(10000);
- return true;
- }
- if (command == "mortal") {
- // give up invincibility
- tux.invincible_timer.stop();
- return true;
- }
- if (command == "shrink") {
- // remove powerups
- tux.kill(tux.SHRINK);
- return true;
- }
- if (command == "kill") {
- tux.kill(tux.KILL);
- return true;
- }
- if (command == "restart") {
- restart_level(true);
- return true;
- }
- if (command == "whereami") {
- msg_info << "You are at x " << tux.get_pos().x << ", y " << tux.get_pos().y << std::endl;
- return true;
- }
- if (command == "gotoend") {
- // goes to the end of the level
- tux.move(Vector(
- (currentsector->solids->get_width()*32) - (SCREEN_WIDTH*2), 0));
- currentsector->camera->reset(
- Vector(tux.get_pos().x, tux.get_pos().y));
- return true;
- }
- if (command == "flip") {
- FlipLevelTransformer flip_transformer;
- flip_transformer.transform(GameSession::current()->get_current_level());
- return true;
- }
- if (command == "finish") {
- finish(true);
- return true;
- }
- if (command == "camera") {
- msg_info << "Camera is at " << Sector::current()->camera->get_translation().x << "," << Sector::current()->camera->get_translation().y << std::endl;
- return true;
- }
- if (command == "quit") {
- main_loop->quit();
- return true;
- }
-
- return false;
-}
-
void
GameSession::check_end_conditions()
{
if(newsector != "" && newspawnpoint != "") {
Sector* sector = level->get_sector(newsector);
if(sector == 0) {
- msg_warning << "Sector '" << newsector << "' not found" << std::endl;
+ log_warning << "Sector '" << newsector << "' not found" << std::endl;
}
sector->activate(newspawnpoint);
sector->play_music(LEVEL_MUSIC);
sound_manager->set_listener_position(currentsector->player->get_pos());
/* Handle music: */
- if (currentsector->player->invincible_timer.started() &&
- currentsector->player->invincible_timer.get_timeleft()
- > TUX_INVINCIBLE_TIME_WARNING && !end_sequence) {
- currentsector->play_music(HERRING_MUSIC);
- } else if(currentsector->get_music_type() != LEVEL_MUSIC && !end_sequence) {
+ if (end_sequence)
+ return;
+
+ if(currentsector->player->invincible_timer.started()) {
+ if(currentsector->player->invincible_timer.get_timeleft() <=
+ TUX_INVINCIBLE_TIME_WARNING) {
+ currentsector->play_music(HERRING_WARNING_MUSIC);
+ } else {
+ currentsector->play_music(HERRING_MUSIC);
+ }
+ } else if(currentsector->get_music_type() != LEVEL_MUSIC) {
currentsector->play_music(LEVEL_MUSIC);
}
}
}
} else if(sequencename == "stoptux") {
if(!end_sequence) {
- msg_warning << "Final target reached without an active end sequence" << std::endl;
+ log_warning << "Final target reached without an active end sequence" << std::endl;
this->start_sequence("endsequence");
}
end_sequence = ENDSEQUENCE_WAITING;
} else {
- msg_warning << "Unknown sequence '" << sequencename << "'" << std::endl;
+ log_warning << "Unknown sequence '" << sequencename << "'" << std::endl;
}
}
// draw level stats while end_sequence is running
if (end_sequence) {
- global_stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop);
+ global_stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop.get());
}
}