From: LMH Date: Fri, 6 Sep 2013 03:22:38 +0000 (-1000) Subject: Added ability to define a 'target time' for levels which is taken into consideration... X-Git-Url: https://git.octo.it/?a=commitdiff_plain;ds=sidebyside;h=b840ee034a2fb290d3d3e16ba0ef78eea8815033;p=supertux.git Added ability to define a 'target time' for levels which is taken into consideration when marking a level 'perfect'. As a proof of principle, Icy Island levels prior to the underground sequence have been assigned arbitrary but attainable target times. However, this feature probably should only be used with great care in the main game (if at all). Statistics still need to be modified to display the target time if defined, otherwise it will be confusing to players trying for perfet stats. --- diff --git a/data/levels/world1/01 - Welcome to Antarctica.stl b/data/levels/world1/01 - Welcome to Antarctica.stl index 3440892e7..02c851539 100755 --- a/data/levels/world1/01 - Welcome to Antarctica.stl +++ b/data/levels/world1/01 - Welcome to Antarctica.stl @@ -2,6 +2,7 @@ (version 2) (name (_ "Welcome to Antarctica")) (author "SuperTux Team") + (target-time 30) (license "GPL 2+ / CC-by-sa 3.0") (sector (name "main") diff --git a/data/levels/world1/02 - The Journey Begins.stl b/data/levels/world1/02 - The Journey Begins.stl index 4e73adbce..9169cdb1c 100755 --- a/data/levels/world1/02 - The Journey Begins.stl +++ b/data/levels/world1/02 - The Journey Begins.stl @@ -2,6 +2,7 @@ (version 2) (name (_ "The Journey Begins")) (author "SuperTux Team") + (target-time 30) (license "GPL 2+ / CC-by-sa 3.0") (sector (name "main") diff --git a/data/levels/world1/03 - Via Nostalgica.stl b/data/levels/world1/03 - Via Nostalgica.stl index f73e39a61..ff3a213da 100755 --- a/data/levels/world1/03 - Via Nostalgica.stl +++ b/data/levels/world1/03 - Via Nostalgica.stl @@ -2,6 +2,7 @@ (version 2) (name (_ "Via Nostalgica")) (author "SuperTux Team") + (target-time 60) (license "GPL 2+ / CC-by-sa 3.0") (sector (name "main") diff --git a/data/levels/world1/04 - Tobgle Road.stl b/data/levels/world1/04 - Tobgle Road.stl index aef2eb0dc..da6c50882 100755 --- a/data/levels/world1/04 - Tobgle Road.stl +++ b/data/levels/world1/04 - Tobgle Road.stl @@ -2,6 +2,7 @@ (version 2) (name (_ "Tobgle Road")) (author "SuperTux Team") + (target-time 60) (license "GPL 2+ / CC-by-sa 3.0") (sector (name "main") diff --git a/data/levels/world1/05 - The Somewhat Smaller Bath.stl b/data/levels/world1/05 - The Somewhat Smaller Bath.stl index 3158bc188..3bc1174ba 100755 --- a/data/levels/world1/05 - The Somewhat Smaller Bath.stl +++ b/data/levels/world1/05 - The Somewhat Smaller Bath.stl @@ -3,6 +3,7 @@ (name (_ "The Somewhat Smaller Bath")) (author "Philippe Saint-Pierre") (license "GPL 2+ / CC-by-sa 3.0") + (target-time 60) (sector (name "main") (music "music/chipdisko.ogg") diff --git a/data/levels/world1/06 - The Frosted Fields.stl b/data/levels/world1/06 - The Frosted Fields.stl index f16bccc85..4605f2c26 100755 --- a/data/levels/world1/06 - The Frosted Fields.stl +++ b/data/levels/world1/06 - The Frosted Fields.stl @@ -3,6 +3,7 @@ (name (_ "The Frosted Fields")) (author "SuperTux Team") (license "GPL 2+ / CC-by-sa 3.0") + (target-time 80) (sector (name "main") (music "music/chipdisko.ogg") diff --git a/data/levels/world1/07 - Oh No More Snowballs.stl b/data/levels/world1/07 - Oh No More Snowballs.stl index e6899245d..f38a3f8a1 100755 --- a/data/levels/world1/07 - Oh No More Snowballs.stl +++ b/data/levels/world1/07 - Oh No More Snowballs.stl @@ -3,6 +3,7 @@ (name (_ "Oh no! More Snowballs!")) (author "Voluptuous Pachyderm") (license "GPL 2+ / CC-by-sa 3.0") + (target-time 80) (sector (name "main") (music "music/voc-daytime2.music") diff --git a/data/levels/world1/08 - Stone Cold.stl b/data/levels/world1/08 - Stone Cold.stl index 98b94ba5e..23527f523 100755 --- a/data/levels/world1/08 - Stone Cold.stl +++ b/data/levels/world1/08 - Stone Cold.stl @@ -3,6 +3,7 @@ (name (_ "Stone Cold")) (author "SuperTux Team") (license "GPL 2+ / CC-by-sa 3.0") + (target-time 80) (sector (name "main") (music "music/chipdisko.ogg") diff --git a/data/levels/world1/09 - Grumbels Sense of Snow.stl b/data/levels/world1/09 - Grumbels Sense of Snow.stl index ce6abc2de..1eef5b9ab 100755 --- a/data/levels/world1/09 - Grumbels Sense of Snow.stl +++ b/data/levels/world1/09 - Grumbels Sense of Snow.stl @@ -3,6 +3,7 @@ (name (_ "Grumbel's Sense of Snow")) (author "SuperTux Team") (license "GPL 2+ / CC-by-sa 3.0") + (target-time 80) (sector (name "main") (music "music/chipdisko.ogg") diff --git a/data/levels/world1/10 - 23rd Airborne.stl b/data/levels/world1/10 - 23rd Airborne.stl index 13705fc7c..15d02c4a8 100755 --- a/data/levels/world1/10 - 23rd Airborne.stl +++ b/data/levels/world1/10 - 23rd Airborne.stl @@ -3,6 +3,7 @@ (name (_ "23rd Airborne")) (author "SuperTux Team") (license "GPL 2+ / CC-by-sa 3.0") + (target-time 80) (sector (name "main") (music "music/airship_remix.music") diff --git a/data/levels/world1/11 - Night Chill.stl b/data/levels/world1/11 - Night Chill.stl index 48f991bec..4f3b45efa 100755 --- a/data/levels/world1/11 - Night Chill.stl +++ b/data/levels/world1/11 - Night Chill.stl @@ -3,6 +3,7 @@ (name (_ "Night Chill")) (author "SuperTux Team") (license "GPL 2+ / CC-by-sa 3.0") + (target-time 100) (sector (name "main") (music "music/voc-night.music") diff --git a/data/levels/world1/12 - Into the Stars.stl b/data/levels/world1/12 - Into the Stars.stl index 4bfae2cc6..89afa5798 100755 --- a/data/levels/world1/12 - Into the Stars.stl +++ b/data/levels/world1/12 - Into the Stars.stl @@ -3,6 +3,7 @@ (name (_ "Into the Stars")) (author "SuperTux Team") (license "GPL 2+ / CC-by-sa 3.0") + (target-time 80) (sector (name "main") (music "music/voc-night.music") diff --git a/data/levels/world1/13 - Above the Arctic Skies.stl b/data/levels/world1/13 - Above the Arctic Skies.stl index 90cf22aff..b24bfec49 100755 --- a/data/levels/world1/13 - Above the Arctic Skies.stl +++ b/data/levels/world1/13 - Above the Arctic Skies.stl @@ -3,6 +3,7 @@ (name (_ "Above the Arctic Skies")) (author "SuperTux Team") (license "GPL 2+ / CC-by-sa 3.0") + (target-time 40) (sector (name "main") (music "music/airship_remix.music") diff --git a/data/levels/world1/14 - Entrance to the Cave.stl b/data/levels/world1/14 - Entrance to the Cave.stl index 5dd1f8ca2..b4eeedfbf 100755 --- a/data/levels/world1/14 - Entrance to the Cave.stl +++ b/data/levels/world1/14 - Entrance to the Cave.stl @@ -3,6 +3,7 @@ (name (_ "Entrance to the Cave")) (author "SuperTux Team") (license "GPL 2+ / CC-by-sa 3.0") + (target-time 80) (sector (name "main") (music "music/chipdisko.ogg") diff --git a/data/levels/world1/Fork_in_the_Road.stl b/data/levels/world1/Fork_in_the_Road.stl index 523b64a77..a441a59aa 100644 --- a/data/levels/world1/Fork_in_the_Road.stl +++ b/data/levels/world1/Fork_in_the_Road.stl @@ -4,6 +4,7 @@ (author "LMH") (contact "lmh.0013@gmail.com") (license "GPL 2 / CC-by-sa 3.0") + (target-time 60) (sector (name "main") (music "music/voc-daytime2.ogg") diff --git a/src/supertux/level.cpp b/src/supertux/level.cpp index 0d78d531d..9b179bcdc 100644 --- a/src/supertux/level.cpp +++ b/src/supertux/level.cpp @@ -40,6 +40,7 @@ Level::Level() : on_menukey_script(), sectors(), stats(), + target_time(), tileset(NULL), free_tileset(false) { @@ -120,6 +121,8 @@ Level::load(const std::string& filepath) Sector* sector = new Sector(this); sector->parse(*(iter.lisp())); add_sector(sector); + } else if(token == "target-time") { + iter.value()->get(target_time); } else { log_warning << "Unknown token '" << token << "' in level file" << std::endl; } diff --git a/src/supertux/level.hpp b/src/supertux/level.hpp index b2b8dd937..aadc49b78 100644 --- a/src/supertux/level.hpp +++ b/src/supertux/level.hpp @@ -41,6 +41,7 @@ public: std::string on_menukey_script; Sectors sectors; Statistics stats; + float target_time; TileSet *tileset; bool free_tileset; diff --git a/src/supertux/statistics.cpp b/src/supertux/statistics.cpp index 0dd695d4c..975880acc 100644 --- a/src/supertux/statistics.cpp +++ b/src/supertux/statistics.cpp @@ -273,11 +273,12 @@ Statistics::operator+=(const Statistics& s2) } bool -Statistics::completed(const Statistics& stats) +Statistics::completed(const Statistics& stats, const float target_time) { return (stats.coins == stats.total_coins && stats.badguys == stats.total_badguys && - stats.secrets == stats.total_secrets); + stats.secrets == stats.total_secrets && + ((!target_time) || (stats.time <= target_time))); } void diff --git a/src/supertux/statistics.hpp b/src/supertux/statistics.hpp index 880cd474c..e11c39d0d 100644 --- a/src/supertux/statistics.hpp +++ b/src/supertux/statistics.hpp @@ -65,7 +65,7 @@ public: void reset(); /**< Set stats (but not totals) to zero */ void merge(const Statistics& stats); /**< Given another Statistics object finds the best of each one */ void operator+=(const Statistics& o); /**< Add two Statistics objects */ - bool completed(const Statistics& stats); /* Check if stats match total stats */ + bool completed(const Statistics& stats, const float target_time); /* Check if stats match total stats */ void declare_invalid(); /**< marks statistics as invalid for their entire lifetime (e.g. after cheating). Invalid statistics will not be merged or drawn. */ diff --git a/src/worldmap/level.cpp b/src/worldmap/level.cpp index 569f31f48..b60fad07c 100644 --- a/src/worldmap/level.cpp +++ b/src/worldmap/level.cpp @@ -37,6 +37,7 @@ LevelTile::LevelTile(const std::string& basedir, const Reader& lisp) : auto_play(false), sprite(), statistics(), + target_time(), extro_script(), basedir(basedir), picture_cached(false), diff --git a/src/worldmap/level.hpp b/src/worldmap/level.hpp index 8730d2956..58935b193 100644 --- a/src/worldmap/level.hpp +++ b/src/worldmap/level.hpp @@ -50,6 +50,7 @@ public: /** Statistics for level tiles */ Statistics statistics; + float target_time; /** Script that is run when the level is successfully finished */ std::string extro_script; diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index e082d8f2b..31d631cf3 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -364,6 +364,24 @@ WorldMap::get_level_title(LevelTile& level) } } +void +WorldMap::get_level_target_time(LevelTile& level) +{ + try { + lisp::Parser parser; + const lisp::Lisp* root = parser.parse(levels_path + level.get_name()); + + const lisp::Lisp* level_lisp = root->get_lisp("supertux-level"); + if(!level_lisp) + return; + + level_lisp->get("target-time", level.target_time); + } catch(std::exception& e) { + log_warning << "Problem when reading level target time: " << e.what() << std::endl; + return; + } +} + void WorldMap::calculate_total_stats() { total_stats.zero(); @@ -461,7 +479,8 @@ WorldMap::finished_level(Level* gamelevel) // deal with statistics level->statistics.merge(gamelevel->stats); calculate_total_stats(); - if(level->statistics.completed(level->statistics)) { + get_level_target_time(*level); + if(level->statistics.completed(level->statistics, level->target_time)) { level->perfect = true; level->sprite->set_action("perfect"); } diff --git a/src/worldmap/worldmap.hpp b/src/worldmap/worldmap.hpp index 1fbf85875..29cd50f37 100644 --- a/src/worldmap/worldmap.hpp +++ b/src/worldmap/worldmap.hpp @@ -225,6 +225,7 @@ public: private: void get_level_title(LevelTile& level); + void get_level_target_time(LevelTile& level); void draw_status(DrawingContext& context); void calculate_total_stats();