Levelreihenfolge, -fixes.
[hackover2013-badge-firmware.git] / mock / tools / level-converter.cc
index 04651af..eb8b1c6 100644 (file)
@@ -6,6 +6,7 @@ extern "C" {
 }
 
 #include <boost/spirit/include/qi_symbols.hpp>
+#include <boost/algorithm/string/trim.hpp>
 
 #include <algorithm>
 #include <fstream>
@@ -18,10 +19,10 @@ extern "C" {
 #include <vector>
 
 enum {
-  LEVEL_LINE_COUNT = 13
+  LEVEL_LINE_COUNT = 14
 };
 
-#define PATH_PREFIX "../badge/jumpnrun/"
+#define PATH_PREFIX "../badge/jumpnrun/levels/"
 
 namespace jnrcpp {
   struct descriptors {
@@ -33,23 +34,32 @@ namespace jnrcpp {
         ("tube_right"    , JUMPNRUN_TILE_TYPE_TUBE_RIGHT    )
         ("brick"         , JUMPNRUN_TILE_TYPE_BRICK         )
         ("square"        , JUMPNRUN_TILE_TYPE_SQUARE        )
+        ("spike_up"      , JUMPNRUN_TILE_TYPE_SPIKE_UP      )
+        ("spike_right"   , JUMPNRUN_TILE_TYPE_SPIKE_RIGHT   )
+        ("spike_down"    , JUMPNRUN_TILE_TYPE_SPIKE_DOWN    )
+        ("spike_left"    , JUMPNRUN_TILE_TYPE_SPIKE_LEFT    )
         ;
 
       items.add
-        ("doc", JUMPNRUN_ITEM_TYPE_DOCUMENT)
+        ("doc"          , JUMPNRUN_ITEM_TYPE_DOCUMENT          )
+        ("checkpoint"   , JUMPNRUN_ITEM_TYPE_CHECKPOINT        )
+        ("key"          , JUMPNRUN_ITEM_TYPE_KEY               )
+        ("doc_encrypted", JUMPNRUN_ITEM_TYPE_ENCRYPTED_DOCUMENT)
         ;
 
       enemies.add
-        ("cat"      , JUMPNRUN_ENEMY_TYPE_CAT      )
-        ("mushroom" , JUMPNRUN_ENEMY_TYPE_MUSHROOM )
-        ("bunny"    , JUMPNRUN_ENEMY_TYPE_BUNNY    )
-        ("kaninchen", JUMPNRUN_ENEMY_TYPE_BUNNY    ) // legacy
-        ("snake"    , JUMPNRUN_ENEMY_TYPE_SNAKE    )
-        ("spiral"   , JUMPNRUN_ENEMY_TYPE_SPIRAL   )
-        ("rotor"    , JUMPNRUN_ENEMY_TYPE_ROTOR    )
-        ("dog"      , JUMPNRUN_ENEMY_TYPE_DOG      )
-        ("giraffe"  , JUMPNRUN_ENEMY_TYPE_GIRAFFE  )
-        ("bird"     , JUMPNRUN_ENEMY_TYPE_BIRD     )
+        ("cat"          , JUMPNRUN_ENEMY_TYPE_CAT          )
+        ("mushroom"     , JUMPNRUN_ENEMY_TYPE_MUSHROOM     )
+        ("bunny"        , JUMPNRUN_ENEMY_TYPE_BUNNY        )
+        ("kaninchen"    , JUMPNRUN_ENEMY_TYPE_BUNNY        ) // legacy
+        ("snake"        , JUMPNRUN_ENEMY_TYPE_SNAKE        )
+        ("spiral"       , JUMPNRUN_ENEMY_TYPE_SPIRAL       )
+        ("rotor"        , JUMPNRUN_ENEMY_TYPE_ROTOR        )
+        ("dog"          , JUMPNRUN_ENEMY_TYPE_DOG          )
+        ("giraffe"      , JUMPNRUN_ENEMY_TYPE_GIRAFFE      )
+        ("bird"         , JUMPNRUN_ENEMY_TYPE_BIRD         )
+        ("bird_straight", JUMPNRUN_ENEMY_TYPE_BIRD_STRAIGHT)
+        ("bird_dip"     , JUMPNRUN_ENEMY_TYPE_BIRD_DIP     )
         ;
     }
 
@@ -60,15 +70,15 @@ namespace jnrcpp {
 
   struct level_name_map {
     level_name_map() {
-      std::ifstream in(PATH_PREFIX "levels.txt");
+      std::ifstream in("levels.txt");
 
       if(!in) {
-        throw std::logic_error(PATH_PREFIX "levels.txt konnte nicht geöffnet werden.");
+        throw std::logic_error("levels.txt konnte nicht geöffnet werden.");
       }
 
       std::string name;
       while(std::getline(in, name)) {
-        if(name != "") {
+        if(boost::trim_copy(name) != "") {
           names.push_back(name);
         }
       }
@@ -105,10 +115,12 @@ namespace jnrcpp {
             objmap = &item_types;
           } else if(line == "[enemies]") {
             objmap = &enemy_types;
+          } else if(line == "[parameters]") {
+            objmap = &level_params;
           } else {
             throw std::invalid_argument("Unkown type: " + line);
           }
-        } else if(line != "") {
+        } else if(boost::trim_right_copy(line) != "") {
           char c;
           std::string tok;
           std::istringstream parser(line);
@@ -174,7 +186,7 @@ namespace jnrcpp {
 
           if(iter != objmap.end()) {
             unsigned char buf[3];
-            buf[0] = static_cast<uint8_t>(y + 1) << 4 | static_cast<uint8_t>(x >> 8);
+            buf[0] = static_cast<uint8_t>(y) << 4 | static_cast<uint8_t>(x >> 8);
             buf[1] = static_cast<uint8_t>(x);
             buf[2] = static_cast<uint8_t>(find_type(types, iter->second, error));
 
@@ -227,8 +239,21 @@ namespace jnrcpp {
         static_cast<uint16_t>(player_pos.second)
       };
 
-      dest.write(static_cast<char const *>(static_cast<void const *>(head)), sizeof(head));
-      dest.write(static_cast<char const *>(static_cast<void const *>(spos)), sizeof(spos));
+      uint8_t lives = 3;
+      {
+        std::map<char, std::string>::const_iterator iter = level_params.find('L');
+        if(iter != level_params.end()) {
+          unsigned x;
+          std::istringstream parser(iter->second);
+          if(parser >> x) {
+            lives = static_cast<uint8_t>(x);
+          }
+        }
+      }
+
+      dest.write(static_cast<char const *>(static_cast<void const *>(head  )), sizeof(head ));
+      dest.write(static_cast<char const *>(static_cast<void const *>(spos  )), sizeof(spos ));
+      dest.write(static_cast<char const *>(static_cast<void const *>(&lives)), sizeof(lives));
 
       dump_tiles(dest);
       dump_items(dest);
@@ -241,6 +266,7 @@ namespace jnrcpp {
     std::map<char, std::string> tile_types;
     std::map<char, std::string> item_types;
     std::map<char, std::string> enemy_types;
+    std::map<char, std::string> level_params;
   };
 }
 
This page took 0.033971 seconds and 4 git commands to generate.