[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Enigma-cvs] enigma/src game.hh,1.26,1.27 game.cc,1.55,1.56
From: |
Daniel Heck <address@hidden> |
Subject: |
[Enigma-cvs] enigma/src game.hh,1.26,1.27 game.cc,1.55,1.56 |
Date: |
Sun, 16 Nov 2003 19:25:42 +0000 |
Update of /cvsroot/enigma/enigma/src
In directory subversions:/tmp/cvs-serv14721/src
Modified Files:
game.hh game.cc
Log Message:
* src/game.cc: Removed unused code + general cleanup. Use new
options:: code. Added GetDifficulty(), SetMouseSpeed(),
GetMouseSpeed(). Removed GetStatus().
* src/game.hh: Added {MIN,MAX}_MouseSpeed (from options.hh),
SetMouseSpeed(), GetMouseSpeed(), GetDifficulty().
Index: game.hh
===================================================================
RCS file: /cvsroot/enigma/enigma/src/game.hh,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** game.hh 9 Nov 2003 12:01:34 -0000 1.26
--- game.hh 16 Nov 2003 19:25:40 -0000 1.27
***************
*** 31,37 ****
enum {
DIFFICULTY_EASY = 1,
! DIFFICULTY_HARD
};
extern vector<LevelPack *> LevelPacks;
--- 31,39 ----
enum {
DIFFICULTY_EASY = 1,
! DIFFICULTY_HARD = 2
};
+ /* -------------------- Global variables -------------------- */
+
extern vector<LevelPack *> LevelPacks;
***************
*** 73,76 ****
--- 75,86 ----
/* -------------------- Functions -------------------- */
+
+ const int MIN_MouseSpeed = 1;
+ const int MAX_MouseSpeed = 15;
+
+ double SetMouseSpeed (double speed);
+ double GetMouseSpeed ();
+
+ int GetDifficulty();
void RegisterLevelPack (LevelPack *lp);
Index: game.cc
===================================================================
RCS file: /cvsroot/enigma/enigma/src/game.cc,v
retrieving revision 1.55
retrieving revision 1.56
diff -C2 -d -r1.55 -r1.56
*** game.cc 12 Nov 2003 09:34:44 -0000 1.55
--- game.cc 16 Nov 2003 19:25:40 -0000 1.56
***************
*** 19,22 ****
--- 19,23 ----
*/
#include "display.hh"
+ #include "main.hh"
#include "game.hh"
#include "menus.hh"
***************
*** 35,42 ****
using namespace px;
using namespace std;
! //----------------------------------------
! // Data types
! //----------------------------------------
namespace
{
--- 36,42 ----
using namespace px;
using namespace std;
+
! /* -------------------- Data Types -------------------- */
namespace
{
***************
*** 72,77 ****
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
STARTGAME, // start the current level (when called from
level menu)
RESTARTGAME, // restart the current level (new lives)
--- 72,75 ----
***************
*** 100,104 ****
unsigned icurrent_level;
Uint32 last_tick_time;
- // double actor_dead_dtime;
double current_state_dtime;
double overall_level_time;
--- 98,101 ----
***************
*** 109,116 ****
- //----------------------------------------
- // GameMenu impl
- //----------------------------------------
GameMenu::GameMenu(int zoomxpos_, int zoomypos_)
: resume(new gui::TextButton("Resume Level", this)),
--- 106,112 ----
+ /* -------------------- GameMenu -------------------- */
+
GameMenu::GameMenu(int zoomxpos_, int zoomypos_)
: resume(new gui::TextButton("Resume Level", this)),
***************
*** 236,246 ****
! //======================================================================
! // MAIN PROGRAM
! //======================================================================
- //----------------------------------------------------------------------
- // GAME IMPLEMENTATION
- //----------------------------------------------------------------------
Game::Game()
--- 232,237 ----
! /* -------------------- Game implementation -------------------- */
Game::Game()
***************
*** 282,310 ****
sound::PlaySound("finished");
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 (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);
--- 273,306 ----
sound::PlaySound("finished");
player::LevelFinished(); // remove player-controlled actors
+
+ int difficulty = GetDifficulty();
+ int level_time = int(current_state_dtime); // time spend
in state INGAME!
+ int par_time = level_pack->get_par_time (icurrent_level,
difficulty);
+ string par_name = level_pack->get_par_holder
(icurrent_level, difficulty);
+ int best_user_time = level_pack->get_best_user_time
(icurrent_level);
! string text;
! 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::GetBool("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::GetBool("TimeHunting"))
! newstate = LEVELREPEAT;
}
if (text.length() == 0) {
! if (options::GetBool("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);
***************
*** 322,328 ****
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) {
--- 318,322 ----
display::GetStatusBar()->show_text(text.c_str(),
display::TEXT_STATIC);
! level_pack->set_level_time (icurrent_level, GetDifficulty(),
level_time);
if (options::LevelStatusChanged) {
***************
*** 333,340 ****
return; // do not enter state
break;
- // case PLAYERDEAD:
- // actor_dead_dtime = 0;
- // // display::ShowText("You lost", display::TEXT_STATIC);
- // break;
case LEVELINIT:
--- 327,330 ----
***************
*** 359,364 ****
{
! 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),
--- 349,354 ----
{
! bool skip_solved = mode == 2 || (mode == 0 &&
options::GetBool("SkipSolvedLevels"));
! bool take_non_par = options::GetBool("TimeHunting") && mode != 1;
unsigned next_level = NextLevel(level_pack, icurrent_level,
HighestAvailableLevel(level_pack),
***************
*** 415,419 ****
}
case INGAME:
! if (options::TimeHunting) {
int second = static_cast<int>(current_state_dtime);
int old_second = static_cast<int>(current_state_dtime-dtime);
--- 405,409 ----
}
case INGAME:
! if (options::GetBool("TimeHunting")) {
int second = static_cast<int>(current_state_dtime);
int old_second = static_cast<int>(current_state_dtime-dtime);
***************
*** 440,462 ****
break;
- // case PLAYERDEAD:
- // actor_dead_dtime += dtime;
- // if (actor_dead_dtime <= 0.5) {
- // handle_events();
- // player::Tick(dtime);
- // world::Tick(dtime);
- // display::Tick(dtime);
- // display::Redraw(screen);
- // } else {
- // change_state (RESTARTGAME);
- // }
- // break;
-
- // case NOMORELIVES:
- // if (current_state_dtime >= 2.0) {
- // change_state(RESTARTGAME);
- // }
- // break;
-
case RELOADLEVEL:
if (current_state_dtime >= 1.0) {
--- 430,433 ----
***************
*** 494,502 ****
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)) {
--- 465,471 ----
void Game::init_hunted_time(int ilevel) {
hunt_against_time = 0;
! if (options::GetBool("TimeHunting")) {
! int par_time = level_pack->get_par_time (ilevel, GetDifficulty());
! int best_user_time = level_pack->get_best_user_time (ilevel);
if (best_user_time>0 && (par_time == -1 || best_user_time<par_time)) {
***************
*** 581,590 ****
icurrent_level = ilevel;
! sdl::TempInputGrab grab(options::Nograb ? SDL_GRAB_OFF : SDL_GRAB_ON);
video::HideMouse();
sound::FadeoutMusic();
! if (options::InGameMusic) {
! sound::PlayMusic( options::LevelMusicFile.c_str());
} else {
sound::StopMusic();
--- 550,559 ----
icurrent_level = ilevel;
! sdl::TempInputGrab grab(enigma::Nograb ? SDL_GRAB_OFF : SDL_GRAB_ON);
video::HideMouse();
sound::FadeoutMusic();
! if (options::GetBool("InGameMusic")) {
! sound::PlayMusic (options::GetString("LevelMusicFile"));
} else {
sound::StopMusic();
***************
*** 631,635 ****
break;
case SDL_MOUSEMOTION:
! world::SetMouseForce (options::MouseSpeed *
V2 (e.motion.xrel, e.motion.yrel));
break;
--- 600,604 ----
break;
case SDL_MOUSEMOTION:
! world::SetMouseForce (options::GetDouble("MouseSpeed") *
V2 (e.motion.xrel, e.motion.yrel));
break;
***************
*** 681,693 ****
}
! static void set_mousespeed(double spd)
{
! int ms = int(spd+.5);
!
! if (ms<options::minMouseSpeed) ms = options::minMouseSpeed;
! else if (ms>options::maxMouseSpeed) ms = options::maxMouseSpeed;
!
! options::MouseSpeed = int(ms+.5);
! display::GetStatusBar()->show_text(strf("Mouse speed: %d", ms),
display::TEXT_2SECONDS);
}
--- 650,658 ----
}
! static void set_mousespeed(double speed)
{
! SetMouseSpeed (static_cast<int> (speed + 0.5));
! display::GetStatusBar()->show_text(strf("Mouse speed: %d",
(int)GetMouseSpeed()),
! display::TEXT_2SECONDS);
}
***************
*** 698,703 ****
break;
! case SDLK_LEFT: set_mousespeed(options::MouseSpeed - 1); break;
! case SDLK_RIGHT: set_mousespeed(options::MouseSpeed + 1); break;
case SDLK_F1:
--- 663,668 ----
break;
! case SDLK_LEFT: set_mousespeed(GetMouseSpeed() - 1); break;
! case SDLK_RIGHT: set_mousespeed(GetMouseSpeed() + 1); break;
case SDLK_F1:
***************
*** 745,752 ****
}
! if (options::WizardMode > 0.0) {
switch (e.key.keysym.sym) {
case SDLK_f:
! options::ShowFPS = !options::ShowFPS;
break;
case SDLK_l:
--- 710,717 ----
}
! if (options::GetBool ("WizardMode")) {
switch (e.key.keysym.sym) {
case SDLK_f:
! // options::ShowFPS = !options::ShowFPS;
break;
case SDLK_l:
***************
*** 800,804 ****
video::ShowMouse();
! helptext_ingame[15] = options::TimeHunting
? "Skip to next non-par level"
: "Skip to next unsolved level";
--- 765,769 ----
video::ShowMouse();
! helptext_ingame[15] = options::GetBool("TimeHunting")
? "Skip to next non-par level"
: "Skip to next unsolved level";
***************
*** 852,855 ****
--- 817,837 ----
/* -------------------- Functions -------------------- */
+ int enigma::GetDifficulty() {
+ return options::GetInt ("Difficulty");
+ }
+
+ double enigma::SetMouseSpeed (double speed) {
+ double oldspeed = GetMouseSpeed();
+ double newspeed = Clamp(speed, (double)MIN_MouseSpeed,
(double)MAX_MouseSpeed);
+ options::SetOption("MouseSpeed", newspeed);
+ return oldspeed;
+ }
+
+ double enigma::GetMouseSpeed () {
+ return options::GetDouble ("MouseSpeed");
+ }
+
+
+
void enigma::RegisterLevelPack (LevelPack *lp)
{
***************
*** 901,909 ****
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
--- 883,888 ----
if (skip_solved || select_non_par) {
! int difficulty = GetDifficulty();
! bool solved = lp->is_solved (levelidx, difficulty);
if (!solved) { // always play unsolved levels
***************
*** 912,918 ****
else { // solved levels
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)
--- 891,897 ----
else { // solved levels
if (select_non_par) {
! int par_time = lp->get_par_time (levelidx,
difficulty);
! int best_user_time = lp->get_best_user_time (levelidx);
! bool need_par = best_user_time<0 || (par_time>0 &&
best_user_time>par_time);
if (need_par)
***************
*** 934,938 ****
enigma::HighestAvailableLevel(LevelPack *lp)
{
! if( options::WizardMode || // No restriction in WizardMode
lp->get_name() == "TestLevels") // and test-levelpack
return lp->size()-1;
--- 913,917 ----
enigma::HighestAvailableLevel(LevelPack *lp)
{
! if (options::GetBool("WizardMode") || // No restriction in WizardMode
lp->get_name() == "TestLevels") // and test-levelpack
return lp->size()-1;
***************
*** 941,964 ****
unsigned max_available = 10-1; // level numbers start at 0
! for( unsigned i = 0; i < lp->size() && i <= max_available; i++) {
! const LevelInfo *levelinfo = lp->get_info(i);
! if (options::LevelStatus *ls=options::GetLevelStatus(lp->get_name(),
levelinfo->filename)) {
! if (ls->finished != 0) {
! max_available++; // for each solved level, an additional
level is available;
! }
! }
}
return max_available;
}
! static options::LevelStatus *
! GetStatus (LevelPack *lp, size_t index)
! {
! return options::GetLevelStatus (lp->get_name(),
! lp->get_info(index)->filename);
! }
!
! bool
! enigma::LevelIsLocked (LevelPack *lp, size_t index)
{
return false; // For now, do not lock any levels
--- 920,933 ----
unsigned max_available = 10-1; // level numbers start at 0
! LevelStatus levelstat;
!
! for (unsigned i = 0; i < lp->size() && i <= max_available; i++) {
! if (lp->get_status (i, levelstat) && levelstat.finished != 0)
! max_available++; // for each solved level, an additional level
is available;
}
return max_available;
}
! bool enigma::LevelIsLocked (LevelPack *lp, size_t index)
{
return false; // For now, do not lock any levels
***************
*** 967,974 ****
int finished = 0;
! if (options::LevelStatus *ls = GetStatus (lp, index))
! finished = ls->finished;
! return !(index <= max_available || finished >= options::Difficulty);
}
--- 936,944 ----
int finished = 0;
! LevelStatus levelstat;
! if (lp->get_status(index, levelstat))
! finished = levelstat.finished;
! return !(index <= max_available || finished >= GetDifficulty());
}
***************
*** 977,987 ****
{
unsigned cnt = 0;
for (unsigned i=0; i<lp->size(); ++i)
{
! if (LevelStatus *ls = GetStatus(lp, i)) {
! if (ls && ls->finished >= options::Difficulty) {
++cnt;
}
! else if (ls->finished>0) {
// level has been finished in easy-mode
const LevelInfo *info = lp->get_info(i);
--- 947,959 ----
{
unsigned cnt = 0;
+ int difficulty = GetDifficulty();
+ LevelStatus levelstat;
for (unsigned i=0; i<lp->size(); ++i)
{
! if (lp->get_status(i, levelstat)) {
! if (levelstat.finished >= difficulty) {
++cnt;
}
! else if (levelstat.finished>0) {
// level has been finished in easy-mode
const LevelInfo *info = lp->get_info(i);
***************
*** 993,998 ****
return cnt;
}
-
-
void enigma::FinishLevel() {
--- 965,968 ----
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Enigma-cvs] enigma/src game.hh,1.26,1.27 game.cc,1.55,1.56,
Daniel Heck <address@hidden> <=