Implementation of parsing for the map format (untested)

- Some stubs inserted for loading new-format scenario data
This commit is contained in:
2014-12-05 00:50:00 -05:00
parent cec15c1cce
commit 4db81f1403
8 changed files with 221 additions and 5 deletions

View File

@@ -331,6 +331,9 @@
915325171A2E1DF0000A9A1C /* oldstructs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 915325161A2E1DA8000A9A1C /* oldstructs.cpp */; };
915325391A2E5F36000A9A1C /* specials_parse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 915325181A2E37EE000A9A1C /* specials_parse.cpp */; };
9153253B1A2E5F37000A9A1C /* specials_parse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 915325181A2E37EE000A9A1C /* specials_parse.cpp */; };
915E090A1A316EE3008BDF00 /* map_parse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 915E09081A316D89008BDF00 /* map_parse.cpp */; };
915E090B1A316EE4008BDF00 /* map_parse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 915E09081A316D89008BDF00 /* map_parse.cpp */; };
915E090C1A317E2E008BDF00 /* map_parse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 915E09081A316D89008BDF00 /* map_parse.cpp */; };
91870F81190C8C1C0081C150 /* winutil.mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 919145FF18E63B70005CF3A4 /* winutil.mac.mm */; };
91870F83190C8C1F0081C150 /* tarball.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91BFA3D81902AD78001686E4 /* tarball.cpp */; };
91870F84190C90980081C150 /* scen.menu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 914CA49F190C4E9200B6ADD1 /* scen.menu.xib */; };
@@ -1250,6 +1253,8 @@
914CA49F190C4E9200B6ADD1 /* scen.menu.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = scen.menu.xib; sourceTree = "<group>"; };
915325161A2E1DA8000A9A1C /* oldstructs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = oldstructs.cpp; path = ../oldstructs.cpp; sourceTree = "<group>"; };
915325181A2E37EE000A9A1C /* specials_parse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = specials_parse.cpp; sourceTree = "<group>"; };
915E09071A316D6A008BDF00 /* map_parse.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = map_parse.hpp; sourceTree = "<group>"; };
915E09081A316D89008BDF00 /* map_parse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = map_parse.cpp; sourceTree = "<group>"; };
917B573F100B956C0096C978 /* undo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = undo.h; sourceTree = "<group>"; };
918D59A718EA513900735B66 /* dialog.keys.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = dialog.keys.h; sourceTree = "<group>"; };
919145FB18E3A32F005CF3A4 /* boe.appleevents.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = boe.appleevents.mm; sourceTree = "<group>"; };
@@ -1690,6 +1695,7 @@
91E5C7A60F9F615400C21460 /* fileio.cpp */,
91B3F10A0F9779C300BF5B67 /* graphtool.cpp */,
91B3F11E0F97801F00BF5B67 /* mathutil.cpp */,
915E09081A316D89008BDF00 /* map_parse.cpp */,
913D005A0F9FEEC200184C18 /* porting.cpp */,
91EC481018FBABB100BB1E86 /* prefs.mac.mm */,
91F6F8F518F8DE6300E3EA15 /* qdpict.cpp */,
@@ -1710,6 +1716,7 @@
91C688E60FD702B9000F6D01 /* cursors.h */,
91E5C7A50F9F615400C21460 /* fileio.h */,
91B3F1090F9779C300BF5B67 /* graphtool.h */,
915E09071A316D6A008BDF00 /* map_parse.hpp */,
91B3F11D0F97801F00BF5B67 /* mathutil.h */,
913D00590F9FEEC200184C18 /* porting.h */,
91EC480E18FBAA8700BB1E86 /* prefs.hpp */,
@@ -2407,6 +2414,7 @@
91BFA3E919033E01001686E4 /* gzstream.cpp in Sources */,
915325171A2E1DF0000A9A1C /* oldstructs.cpp in Sources */,
9153253B1A2E5F37000A9A1C /* specials_parse.cpp in Sources */,
915E090A1A316EE3008BDF00 /* map_parse.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2460,6 +2468,7 @@
91FCC8F418FF0866007026CE /* pc.appleevents.mm in Sources */,
91BFA3DB1902B13F001686E4 /* tarball.cpp in Sources */,
91BFA3EA19033E01001686E4 /* gzstream.cpp in Sources */,
915E090C1A317E2E008BDF00 /* map_parse.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2517,6 +2526,7 @@
91870F81190C8C1C0081C150 /* winutil.mac.mm in Sources */,
91870F83190C8C1F0081C150 /* tarball.cpp in Sources */,
915325391A2E5F36000A9A1C /* specials_parse.cpp in Sources */,
915E090B1A316EE4008BDF00 /* map_parse.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -24,6 +24,7 @@ cScenario::cItemStorage::cItemStorage() : ter_type(-1), property(0) {
//{-1,{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},{0,0,0,0,0,0,0,0,0,0},0}
cScenario& cScenario::operator = (legacy::scenario_data_type& old){
is_legacy = true;
int i,j;
// for(i = 0; i < 3; i++) format.ver[i] = old.ver[i];
// format.min_run_ver = old.min_run_ver;

View File

@@ -96,6 +96,7 @@ public:
char monst_strs[100][256];
bool adjust_diff : 1;
char : 7;
bool is_legacy;
fs::path scen_file; // transient
cOutdoors* outdoors;
cTown* towns;

View File

@@ -15,6 +15,7 @@
#include "gzstream.h"
#include "classes.h"
#include "map_parse.hpp"
#include "graphtool.h"
#include "mathutil.h"
@@ -212,7 +213,7 @@ static long get_town_offset(short which_town){
return len_to_jump;
}
bool load_town(short which_town, cTown*& the_town){
static bool load_town_v1(short which_town, cTown*& the_town) {
short i,n;
long len,len_to_jump = 0;
legacy::town_record_type store_town;
@@ -315,7 +316,26 @@ bool load_town(short which_town, cTown*& the_town){
return true;
}
bool load_town_talk(short which_town){
bool load_town(short which_town, cTown*& the_town) {
if(scenario.is_legacy) return load_town_v1(which_town, the_town);
fs::path town_base = scenario.scen_file/"towns";
std::string base_fname = "t" + std::to_string(which_town), fname;
// TODO: Implement all this.
// First load the main town data.
fname = base_fname + ".xml";
// Next, load in the town map.
fname = base_fname + ".map";
map_data map = load_map(town_base/fname);
// Then load the town's special nodes.
fname = base_fname + ".spec";
// Load the town's special encounter strings
fname = base_fname + ".txt";
// And finally, load the town's dialogue nodes.
load_town_talk(which_town);
return false;
}
static bool load_town_talk_v1(short which_town) {
if(univ.town.prep_talk(which_town)) return true;
short i,n;
@@ -400,6 +420,14 @@ bool load_town_talk(short which_town){
return true;
}
bool load_town_talk(short which_town) {
if(scenario.is_legacy) return load_town_talk_v1(which_town);
fs::path town_base = scenario.scen_file/"towns";
// TODO: Implement this.
std::string fname = "t" + std::to_string(which_town) + "talk.xml";
return false;
}
bool load_town_str(short which_town, short which_str, char* str){
short i,n;
long len,len_to_jump = 0;
@@ -542,7 +570,7 @@ static long get_outdoors_offset(location& which_out){
}
//mode -> 0 - primary load 1 - add to top 2 - right 3 - bottom 4 - left
bool load_outdoors(location which_out,cOutdoors& the_out){
static bool load_outdoors_v1(location which_out,cOutdoors& the_out){
short i,n;
long len,len_to_jump;
legacy::outdoor_record_type store_out;
@@ -593,6 +621,23 @@ bool load_outdoors(location which_out,cOutdoors& the_out){
return true;
}
bool load_outdoors(location which_out,cOutdoors& the_out) {
if(scenario.is_legacy) return load_outdoors_v1(which_out, the_out);
fs::path town_base = scenario.scen_file/"outdoors";
std::string base_fname = "tut" + std::to_string(which_out.x) + "~" + std::to_string(which_out.y), fname;
// TODO: Implement all this.
// First load the main sector data.
fname = base_fname + ".xml";
// Next, load in the sector map.
fname = base_fname + ".map";
map_data map = load_map(town_base/fname);
// Then load the sector's special nodes.
fname = base_fname + ".spec";
// Load the sector's special encounter strings
fname = base_fname + ".txt";
return false;
}
bool load_outdoors(location which_out, short mode, ter_num_t borders[4][50]){
short j,n;
long len,len_to_jump;

109
osx/tools/map_parse.cpp Normal file
View File

@@ -0,0 +1,109 @@
//
// map_parse.cpp
// BoE
//
// Created by Celtic Minstrel on 14-12-04.
//
//
#include "map_parse.hpp"
#include <fstream>
#include <cctype>
using namespace std;
map_data load_map(fs::path path) {
map_data data;
ifstream fin(path.string());
int row = 0;
while(!fin.eof()) {
std::string line;
getline(fin, line);
int n = 0, col = 0;
eMapFeature curFeature = eMapFeature::NONE;
bool vehicle_owned;
for(char c : line) {
if(c == '#') break; // Found a comment
if(isdigit(c)) {
n *= 10;
n += c - '0';
} else if(isblank(c)) {
continue;
} else if(c == '^') {
data.addFeature(col, row, eMapFeature::ENTRANCE_NORTH);
} else if(c == '<') {
data.addFeature(col, row, eMapFeature::ENTRANCE_WEST);
} else if(c == 'v') {
data.addFeature(col, row, eMapFeature::ENTRANCE_SOUTH);
} else if(c == '>') {
data.addFeature(col, row, eMapFeature::ENTRANCE_EAST);
} else {
if(curFeature == eMapFeature::NONE)
data.set(col, row, n);
else {
if((curFeature == eMapFeature::BOAT || curFeature == eMapFeature::HORSE) && !vehicle_owned)
n *= -1;
data.addFeature(col, row, curFeature, n);
}
n = 0;
if(c == '*') {
curFeature = eMapFeature::WANDERING;
} else if(c == ':') {
curFeature = eMapFeature::SPECIAL_NODE;
} else if(c == '!') {
curFeature = eMapFeature::SIGN;
} else if(c == '@') {
curFeature = eMapFeature::TOWN;
} else if(c == '~') {
curFeature = eMapFeature::VEHICLE;
} else if(c == 'h' && curFeature == eMapFeature::VEHICLE) {
vehicle_owned = true;
curFeature = eMapFeature::HORSE;
} else if(c == 'H' && curFeature == eMapFeature::VEHICLE) {
vehicle_owned = false;
curFeature = eMapFeature::HORSE;
} else if(c == 'b' && curFeature == eMapFeature::VEHICLE) {
vehicle_owned = true;
curFeature = eMapFeature::BOAT;
} else if(c == 'B' && curFeature == eMapFeature::VEHICLE) {
vehicle_owned = false;
curFeature = eMapFeature::BOAT;
} else if(c == ',') {
col++;
curFeature = eMapFeature::NONE;
} else {
// TODO: This is an error!
}
}
}
}
return data;
}
void map_data::set(unsigned int x, unsigned int y, unsigned int val) {
// First make sure the location exists
if(y > grid.size())
grid.resize(y + 1);
if(x > grid[y].size())
grid[y].resize(x + 1);
grid[y][x] = val;
}
unsigned int map_data::get(unsigned int x, unsigned int y) {
if(y >= grid.size()) return 0;
if(x >= grid[y].size()) return 0;
return grid[y][x];
}
void map_data::addFeature(unsigned int x, unsigned int y, eMapFeature feature, int val) {
location loc(x,y);
features.insert({loc,{feature,val}});
}
bool loc_compare::operator()(location a, location b) const {
// This is just a lexicographical ordering.
if(a.x != b.x) return a.x < b.x;
if(a.y != b.y) return a.y < b.y;
return false;
}

48
osx/tools/map_parse.hpp Normal file
View File

@@ -0,0 +1,48 @@
//
// map_parse.hpp
// BoE
//
// Created by Celtic Minstrel on 14-12-04.
//
//
#ifndef BoE_map_parse_hpp
#define BoE_map_parse_hpp
#include <vector>
#include <map>
#include <boost/filesystem/path.hpp>
#include "location.h"
namespace fs = boost::filesystem;
enum class eMapFeature {
NONE, // Special value, won't appear in the map.
SPECIAL_NODE,
SIGN,
WANDERING,
TOWN,
VEHICLE, // Another special value that shouldn't appear in the map
BOAT,
HORSE,
ENTRANCE_NORTH,
ENTRANCE_WEST,
ENTRANCE_SOUTH,
ENTRANCE_EAST,
};
struct loc_compare {
bool operator()(location a, location b) const;
};
struct map_data {
std::vector<std::vector<int>> grid;
std::multimap<location,std::pair<eMapFeature,int>,loc_compare> features;
void set(unsigned int x, unsigned int y, unsigned int val);
unsigned int get(unsigned int x, unsigned int y);
void addFeature(unsigned int x, unsigned int y, eMapFeature feature, int val = 0);
};
map_data load_map(fs::path path);
#endif