[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Enigma-cvs] enigma/src game.cc,1.53,1.54
From: |
Ralf Westram <address@hidden> |
Subject: |
[Enigma-cvs] enigma/src game.cc,1.53,1.54 |
Date: |
Sun, 09 Nov 2003 12:01:07 +0000 |
Update of /cvsroot/enigma/enigma/src
In directory subversions:/tmp/cvs-serv2795/src
Modified Files:
game.cc
Log Message:
- Ctrl-a = Shift-F3
- set negative timerstart in timehunting mode
- play sound when time hunt is lost
- tick second in the last 20% of par time
- again modified level-finish messages
- now non-rounded level time is used
- NextLevel can select non-par levels (todo stuff removed)
- help for F5 changed
- added state LEVELREPEAT
Index: game.cc
===================================================================
RCS file: /cvsroot/enigma/enigma/src/game.cc,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -d -r1.53 -r1.54
*** game.cc 6 Nov 2003 07:19:25 -0000 1.53
--- game.cc 9 Nov 2003 12:01:05 -0000 1.54
***************
*** 71,74 ****
--- 71,75 ----
INGAME, // game is currently running
LEVELFINISHED, // level finished; proceed to next one
+ LEVELREPEAT, // like LEVELFINISHED, but restarts current
level
// PLAYERDEAD, // player is dead; restart level shortly
// NOMORELIVES, // no player has any lives left, restart
***************
*** 92,95 ****
--- 93,97 ----
bool load_level(int ilevel);
void advance_level(int mode = 0);
+ void init_hunted_time(int ilevel);
// Private variables.
***************
*** 102,105 ****
--- 104,108 ----
double overall_level_time;
px::Screen *screen;
+ int hunt_against_time;
};
}
***************
*** 246,250 ****
last_tick_time(0),
overall_level_time(0),
! screen (0)
{
}
--- 249,254 ----
last_tick_time(0),
overall_level_time(0),
! screen (0),
! hunt_against_time(0)
{
}
***************
*** 279,311 ****
player::LevelFinished(); // remove player-controlled actors
! int level_time = int(current_state_dtime + .5); // time
spend in state INGAME!
! const LevelInfo *info =
level_pack->get_info(icurrent_level);
! if (options::SetLevelTime (level_pack->get_name(), info->filename,
! options::Difficulty, info->revision,
! level_time))
! {
! const LevelStatus *stat =
options::GetLevelStatus(level_pack->get_name(), info->filename);
! int par_time, best_user_time;
! string par_name;
! get_best_times(info, stat, par_time, best_user_time,
&par_name);
! if (par_time>0 && best_user_time <= par_time)
! {
! if (best_user_time == par_time) {
! string text = string("Exactly the par time by
")+par_name;
! display::GetStatusBar()->show_text(text.c_str(),
display::TEXT_SCROLLING);
! }
! else {
! display::GetStatusBar()->show_text("Great! A new par
time!", display::TEXT_STATIC);
! }
}
else {
! display::GetStatusBar()->show_text("New best time!",
display::TEXT_STATIC);
}
- } else {
- display::GetStatusBar()->show_text("Level finished!",
display::TEXT_STATIC);
}
if (options::LevelStatusChanged) {
options::Save(); // save options (Enigma sometimes crashes
when loading next level)
--- 283,333 ----
player::LevelFinished(); // remove player-controlled actors
! int level_time = int(current_state_dtime); // time
spend in state INGAME!
! const LevelInfo *info =
level_pack->get_info(icurrent_level);
! const LevelStatus *stat =
options::GetLevelStatus(level_pack->get_name(), info->filename);
! int best_user_time; // old personal best time
! int par_time;
! string par_name;
! string text;
! get_best_times(info, stat, par_time, best_user_time, &par_name);
! if (stat && stat->solved_revision < info->revision) {
! best_user_time = -1;
! }
!
! if (par_time>0) {
! if (best_user_time<0 || best_user_time>par_time) {
! if (level_time == par_time) text = string("Exactly the
par time by ")+par_name+"!";
! else if (level_time<par_time) text = "Great! A new par
time!";
! else if (options::TimeHunting) newstate = LEVELREPEAT;
! }
! }
! if (text.length() == 0 && best_user_time>0) {
! if (level_time == best_user_time) text = "Best time!";
! else if (level_time<best_user_time) text = "New best time!";
! else if (options::TimeHunting) newstate = LEVELREPEAT;
! }
! if (text.length() == 0) {
! if (options::TimeHunting && (par_time>0 || best_user_time>0))
{
! bool with_par = best_user_time == -1 || (par_time >0 &&
par_time<best_user_time);
! int behind = level_time - (with_par ? par_time :
best_user_time);
!
! text = strf("%d:%02d behind %s time.",
static_cast<int>(behind/60)%100, behind%60,
! (with_par ? "par" : "best"));
!
! newstate = LEVELREPEAT; // time hunt failed -> repeat
level
}
else {
! text = "Level finished!";
}
}
+ display::GetStatusBar()->show_text(text.c_str(),
display::TEXT_STATIC);
+
+ options::SetLevelTime (level_pack->get_name(), info->filename,
+ options::Difficulty, info->revision,
+ level_time);
+
if (options::LevelStatusChanged) {
options::Save(); // save options (Enigma sometimes crashes
when loading next level)
***************
*** 336,349 ****
void Game::advance_level(int mode)
! // mode == 0 -> advance according to options::SkipSolvedLevels
! // mode == 1 -> advance to next level
! // mode == 2 -> advance to next unsolved level
{
! bool skip_solved = mode == 2 || (mode == 0 &&
options::SkipSolvedLevels);
! unsigned next_level = NextLevel(level_pack, icurrent_level,
! HighestAvailableLevel(level_pack),
! skip_solved,
! true);
if (next_level) {
--- 358,374 ----
void Game::advance_level(int mode)
! // mode == 0 -> advance according to
options::SkipSolvedLevels/options::TimeHunting
! // mode == 1 -> advance to next level (ignoring solved and par-state)
! // mode == 2 -> advance to next unsolved or non-par level
{
! bool skip_solved = mode == 2 || (mode == 0 &&
options::SkipSolvedLevels);
! bool take_non_par = options::TimeHunting && mode != 1;
! unsigned next_level = NextLevel(level_pack, icurrent_level,
! HighestAvailableLevel(level_pack),
! skip_solved, take_non_par);
!
! fprintf(stderr, "take_non_par=%i skip_solved=%i\n", int(take_non_par),
int(skip_solved));
! fprintf(stderr, "icurrent_level=%u next_level=%u\n", icurrent_level,
next_level);
if (next_level) {
***************
*** 366,372 ****
void Game::tick(double dtime) {
current_state_dtime += dtime;
switch (state) {
case STARTGAME:
! case RESTARTGAME:
player::NewGame(2, level_pack->needs_twoplayers()); // two virtual
players
change_state(load_level(icurrent_level)
--- 391,398 ----
void Game::tick(double dtime) {
current_state_dtime += dtime;
+
switch (state) {
case STARTGAME:
! case RESTARTGAME: {
player::NewGame(2, level_pack->needs_twoplayers()); // two virtual
players
change_state(load_level(icurrent_level)
***************
*** 374,378 ****
: ABORT);
break;
!
case LEVELINFO: {
// show level information (name, author, etc.)
--- 400,404 ----
: ABORT);
break;
! }
case LEVELINFO: {
// show level information (name, author, etc.)
***************
*** 396,399 ****
--- 422,443 ----
}
case INGAME:
+ if (options::TimeHunting) {
+ int second = static_cast<int>(current_state_dtime);
+ int old_second = static_cast<int>(current_state_dtime-dtime);
+
+ if (hunt_against_time && old_second <= hunt_against_time) {
+ if (second > hunt_against_time) {
+ sound::PlaySound("shatter");
+ display::GetStatusBar()->show_text("Too slow.. Ctrl+A",
display::TEXT_2SECONDS, true);
+ }
+ else {
+ if (old_second<second && // tick every second
+ (second >= (hunt_against_time-3) || // at least 3
seconds
+ second >= static_cast<int>(hunt_against_time*.8)))
// or the last 20% before par
+ sound::PlaySound("pickup");
+ }
+ }
+ }
+
handle_events();
world::Tick(dtime);
***************
*** 434,437 ****
--- 478,482 ----
case LEVELFINISHED:
+ case LEVELREPEAT:
if (current_state_dtime <= 2.5) {
handle_events();
***************
*** 441,445 ****
display::Redraw(screen);
} else {
! advance_level();
}
break;
--- 486,494 ----
display::Redraw(screen);
} else {
! switch (state) {
! case LEVELFINISHED: advance_level(); break;
! case LEVELREPEAT: change_state(RELOADLEVEL); break;
! default : break;
! }
}
break;
***************
*** 450,460 ****
}
bool Game::load_level(int ilevel) {
// first set default compatibility mode
// (may be overidden by load_level (from lua))
! {
! const LevelInfo *info = level_pack->get_info(ilevel);
! enigma::GameCompatibility = info->type;
! }
if (level_pack->load_level (ilevel))
--- 499,528 ----
}
+ void Game::init_hunted_time(int ilevel) {
+ hunt_against_time = 0;
+ if (options::TimeHunting) {
+ int par_time, best_user_time;
+ const LevelInfo *info = level_pack->get_info(ilevel);
+ get_best_times(info, options::GetLevelStatus(level_pack->get_name(),
info->filename),
+ par_time, best_user_time, 0);
+
+ if (best_user_time>0 && (par_time == -1 || best_user_time<par_time)) {
+ hunt_against_time = best_user_time;
+ }
+ else if (par_time>0) {
+ hunt_against_time = par_time;
+ }
+ }
+ }
+
bool Game::load_level(int ilevel) {
+ const LevelInfo *info = level_pack->get_info(ilevel);
+
// first set default compatibility mode
// (may be overidden by load_level (from lua))
! enigma::GameCompatibility = info->type;
!
! init_hunted_time(ilevel);
! display::GetStatusBar()->set_timerstart(-hunt_against_time);
if (level_pack->load_level (ilevel))
***************
*** 661,665 ****
case SDLK_F5:
! advance_level(2); // next unsolved level
break;
--- 729,733 ----
case SDLK_F5:
! advance_level(2); // next unsolved or non-par level
break;
***************
*** 670,673 ****
--- 738,746 ----
}
break;
+ case SDLK_a:
+ if (e.key.keysym.mod & KMOD_CTRL) {
+ change_state(RESTARTGAME);
+ }
+ break;
case SDLK_x:
if (e.key.keysym.mod & KMOD_ALT) {
***************
*** 719,723 ****
"Shift+F3:", "Restart the current level",
"F4:", "Skip to next level",
! "F5:", "Skip to next unsolved level",
"F10:", "Make screenshot",
"Left arrow:", "Decrease mouse speed",
--- 792,796 ----
"Shift+F3:", "Restart the current level",
"F4:", "Skip to next level",
! "F5:", 0, // see below
"F10:", "Make screenshot",
"Left arrow:", "Decrease mouse speed",
***************
*** 734,737 ****
--- 807,814 ----
video::ShowMouse();
+ helptext_ingame[15] = options::TimeHunting
+ ? "Skip to next non-par level"
+ : "Skip to next unsolved level";
+
displayHelp(screen, helptext_ingame, 200);
***************
*** 818,822 ****
unsigned
enigma::NextLevel (LevelPack *lp, unsigned levelidx, unsigned max_available,
! bool skip_solved, bool skip_todo)
{
// returns 0 if none found
--- 895,900 ----
unsigned
enigma::NextLevel (LevelPack *lp, unsigned levelidx, unsigned max_available,
! bool skip_solved, // skips solved levels
! bool select_non_par) // always takes non-par levels
(overides skip_solved)
{
// returns 0 if none found
***************
*** 824,859 ****
unsigned size = lp->size();
! while (!found) {
! ++levelidx;
! if (levelidx >= size)
! break; // none found
! const LevelInfo *info = lp->get_info(levelidx);
! if (skip_todo) { // skip "todo" levels
! if (info->filename == "todo") {
! printf("Skipping 'todo' level\n");
! continue;
! }
! // if (info->name == "") {
! // printf("Skipping unnamed level '%s'\n",
info->filename.c_str());
! // continue;
! // }
! }
! // bool available = levelidx <= max_available;
! bool available = true; // level locking disabled for the time being!
! if (skip_solved || !available) {
! options::LevelStatus *ls =
options::GetLevelStatus(lp->get_name(), info->filename);
! if (ls && ls->finished >= options::Difficulty) { // already solved
! if (skip_solved)
! continue; // skip solved
! available = true; // otherwise force available
}
}
!
! if (available)
found = levelidx;
}
--- 902,936 ----
unsigned size = lp->size();
! for (++levelidx; levelidx<size && !found; ++levelidx) {
! // bool available = levelidx <= max_available;
! bool available = true; // level locking disabled for the time
being!
! if (!available) continue;
! if (skip_solved || select_non_par) {
! const LevelInfo *info = lp->get_info(levelidx);
! options::LevelStatus *ls =
options::GetLevelStatus(lp->get_name(), info->filename);
! bool solved = ls && ((ls->finished & options::Difficulty) ||
! (!info->has_easymode && ls->finished));
! if (!solved) { // always play unsolved levels
! found = levelidx;
! }
! else {
! if (select_non_par) {
! int par_time, best_user_time;
! get_best_times(info, ls, par_time, best_user_time, 0);
! bool need_par = best_user_time<0 || (par_time>0 &&
best_user_time>par_time);
! if (need_par)
! found = levelidx;
! }
! else if (skip_solved)
! found = levelidx;
}
}
! else {
found = levelidx;
+ }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Enigma-cvs] enigma/src game.cc,1.53,1.54,
Ralf Westram <address@hidden> <=