Tests for reading and writing map data
- Fix saving and loading boat/horse positions and property flag
This commit is contained in:
@@ -243,6 +243,8 @@
|
||||
91C749B81A2D6670008E0E10 /* strings in Copy Strings */ = {isa = PBXBuildFile; fileRef = 91C749B71A2D6432008E0E10 /* strings */; };
|
||||
91C749BA1A2D670D008E0E10 /* dialogs in Copy Dialog Definitions */ = {isa = PBXBuildFile; fileRef = 91C749B91A2D66F7008E0E10 /* dialogs */; };
|
||||
91C763D91B4C50710086D879 /* enums.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91C763D81B4C4BB30086D879 /* enums.cpp */; };
|
||||
91C763DB1B4EE77F0086D879 /* map_read.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91C763DA1B4EE6E00086D879 /* map_read.cpp */; };
|
||||
91C763DD1B4EE7950086D879 /* map_write.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91C763DC1B4EE7950086D879 /* map_write.cpp */; };
|
||||
91CC173C1B421CA0003D9A69 /* catch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91CC17391B421CA0003D9A69 /* catch.cpp */; };
|
||||
91CC173E1B421CA0003D9A69 /* scen_write.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91CC173B1B421CA0003D9A69 /* scen_write.cpp */; };
|
||||
91CC17491B422D5C003D9A69 /* scen_read.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91CC173A1B421CA0003D9A69 /* scen_read.cpp */; };
|
||||
@@ -733,6 +735,8 @@
|
||||
91C749B71A2D6432008E0E10 /* strings */ = {isa = PBXFileReference; lastKnownFileType = folder; path = strings; sourceTree = "<group>"; };
|
||||
91C749B91A2D66F7008E0E10 /* dialogs */ = {isa = PBXFileReference; lastKnownFileType = folder; path = dialogs; sourceTree = "<group>"; };
|
||||
91C763D81B4C4BB30086D879 /* enums.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = enums.cpp; sourceTree = "<group>"; };
|
||||
91C763DA1B4EE6E00086D879 /* map_read.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = map_read.cpp; sourceTree = "<group>"; };
|
||||
91C763DC1B4EE7950086D879 /* map_write.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = map_write.cpp; sourceTree = "<group>"; };
|
||||
91CC172D1B421C0A003D9A69 /* boe_test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = boe_test; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
91CC17391B421CA0003D9A69 /* catch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = catch.cpp; sourceTree = "<group>"; };
|
||||
91CC173A1B421CA0003D9A69 /* scen_read.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scen_read.cpp; sourceTree = "<group>"; };
|
||||
@@ -1300,6 +1304,8 @@
|
||||
91CC173A1B421CA0003D9A69 /* scen_read.cpp */,
|
||||
91CC173B1B421CA0003D9A69 /* scen_write.cpp */,
|
||||
91C763D81B4C4BB30086D879 /* enums.cpp */,
|
||||
91C763DA1B4EE6E00086D879 /* map_read.cpp */,
|
||||
91C763DC1B4EE7950086D879 /* map_write.cpp */,
|
||||
);
|
||||
name = src;
|
||||
sourceTree = "<group>";
|
||||
@@ -1791,6 +1797,8 @@
|
||||
91CC17491B422D5C003D9A69 /* scen_read.cpp in Sources */,
|
||||
91BC33981B4481EF0008882C /* scen.fileio.cpp in Sources */,
|
||||
91C763D91B4C50710086D879 /* enums.cpp in Sources */,
|
||||
91C763DB1B4EE77F0086D879 /* map_read.cpp in Sources */,
|
||||
91C763DD1B4EE7950086D879 /* map_write.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@@ -43,6 +43,8 @@ void load_spec_graphics();
|
||||
|
||||
// These aren't static solely so that the test cases can access them.
|
||||
void writeScenarioToXml(ticpp::Printer&& data, cScenario& scenario);
|
||||
map_data buildOutMapData(location which, cScenario& scenario);
|
||||
map_data buildTownMapData(size_t which, cScenario& scenario);
|
||||
|
||||
template<typename Container> static void writeSpecialNodes(std::ostream& fout, Container nodes) {
|
||||
static_assert(std::is_same<typename Container::value_type, cSpecial>::value,
|
||||
@@ -819,7 +821,7 @@ static void writeDialogueToXml(ticpp::Printer&& data, cSpeech& talk, int town_nu
|
||||
data.CloseElement("dialogue");
|
||||
}
|
||||
|
||||
static map_data buildOutMapData(location which) {
|
||||
map_data buildOutMapData(location which, cScenario& scenario) {
|
||||
cOutdoors& sector = *scenario.outdoors[which.x][which.y];
|
||||
map_data terrain;
|
||||
for(size_t x = 0; x < 48; x++) {
|
||||
@@ -847,21 +849,21 @@ static map_data buildOutMapData(location which) {
|
||||
for(size_t i = 0; i < scenario.boats.size(); i++) {
|
||||
if(scenario.boats[i].which_town == 200 && scenario.boats[i].sector == which) {
|
||||
int j = i;
|
||||
if(scenario.boats[i].property) j += 10000;
|
||||
if(scenario.boats[i].property) j *= -1;
|
||||
terrain.addFeature(scenario.boats[i].loc.x, scenario.boats[i].loc.y, eMapFeature::HORSE, j);
|
||||
}
|
||||
}
|
||||
for(size_t i = 0; i < scenario.horses.size(); i++) {
|
||||
if(scenario.horses[i].which_town == 200 && scenario.horses[i].sector == which) {
|
||||
int j = i;
|
||||
if(scenario.horses[i].property) j += 10000;
|
||||
if(scenario.horses[i].property) j *= -1;
|
||||
terrain.addFeature(scenario.horses[i].loc.x, scenario.horses[i].loc.y, eMapFeature::HORSE, j);
|
||||
}
|
||||
}
|
||||
return terrain;
|
||||
}
|
||||
|
||||
static map_data buildTownMapData(size_t which) {
|
||||
map_data buildTownMapData(size_t which, cScenario& scenario) {
|
||||
cTown& town = *scenario.towns[which];
|
||||
map_data terrain;
|
||||
for(size_t x = 0; x < town.max_dim(); x++) {
|
||||
@@ -971,7 +973,7 @@ void save_scenario(bool rename) {
|
||||
|
||||
// Then the map.
|
||||
std::ostream& out_map = scen_file.newFile("scenario/out/" + file_basename + ".map");
|
||||
buildOutMapData(loc(x,y)).writeTo(out_map);
|
||||
buildOutMapData(loc(x,y), scenario).writeTo(out_map);
|
||||
|
||||
// And the special nodes.
|
||||
std::ostream& out_spec = scen_file.newFile("scenario/out/" + file_basename + ".spec");
|
||||
@@ -988,7 +990,7 @@ void save_scenario(bool rename) {
|
||||
|
||||
// Then the map.
|
||||
std::ostream& town_map = scen_file.newFile("scenario/towns/" + file_basename + ".map");
|
||||
buildTownMapData(i).writeTo(town_map);
|
||||
buildTownMapData(i, scenario).writeTo(town_map);
|
||||
|
||||
// And the special nodes.
|
||||
std::ostream& town_spec = scen_file.newFile("scenario/towns/" + file_basename + ".spec");
|
||||
|
@@ -45,6 +45,8 @@ static bool load_scenario_v2(fs::path file_to_load, cScenario& scenario, bool on
|
||||
// Some of these are non-static so that the test cases can access them.
|
||||
ticpp::Document xmlDocFromStream(std::istream& stream, std::string name);
|
||||
void readScenarioFromXml(ticpp::Document&& data, cScenario& scenario);
|
||||
void loadOutMapData(map_data&& data, location which, cScenario& scen);
|
||||
void loadTownMapData(map_data&& data, int which, cScenario& scen);
|
||||
|
||||
bool load_scenario(fs::path file_to_load, cScenario& scenario, bool only_header) {
|
||||
// Before loading a scenario, we may need to pop scenario resource paths.
|
||||
@@ -1811,7 +1813,7 @@ static void readDialogueFromXml(ticpp::Document&& data, cSpeech& talk, int town_
|
||||
}
|
||||
}
|
||||
|
||||
static void loadOutMapData(map_data&& data, location which, cScenario& scen) {
|
||||
void loadOutMapData(map_data&& data, location which, cScenario& scen) {
|
||||
cOutdoors& out = *scen.outdoors[which.x][which.y];
|
||||
int num_towns = 0;
|
||||
for(int x = 0; x < 48; x++) {
|
||||
@@ -1823,7 +1825,7 @@ static void loadOutMapData(map_data&& data, location which, cScenario& scen) {
|
||||
cVehicle* what;
|
||||
switch(feat.first) {
|
||||
// Special values
|
||||
case eMapFeature::NONE: case eMapFeature::VEHICLE:
|
||||
case eMapFeature::NONE:
|
||||
break;
|
||||
// Town-only features
|
||||
case eMapFeature::ENTRANCE_EAST: case eMapFeature::ENTRANCE_NORTH: case eMapFeature::ENTRANCE_SOUTH:
|
||||
@@ -1842,11 +1844,11 @@ static void loadOutMapData(map_data&& data, location which, cScenario& scen) {
|
||||
case eMapFeature::BOAT:
|
||||
is_boat = true;
|
||||
case eMapFeature::HORSE:
|
||||
what = &(is_boat ? scen.boats : scen.horses)[feat.second % 10000];
|
||||
what = &(is_boat ? scen.boats : scen.horses)[abs(feat.second)];
|
||||
what->which_town = 200;
|
||||
what->sector = which;
|
||||
what->loc_in_sec = loc(x,y);
|
||||
what->property = feat.second >= 10000;
|
||||
what->property = feat.second < 0;
|
||||
break;
|
||||
case eMapFeature::FIELD:
|
||||
if(feat.second == SPECIAL_SPOT)
|
||||
@@ -1869,7 +1871,7 @@ static void loadOutMapData(map_data&& data, location which, cScenario& scen) {
|
||||
}
|
||||
}
|
||||
|
||||
static void loadTownMapData(map_data&& data, int which, cScenario& scen) {
|
||||
void loadTownMapData(map_data&& data, int which, cScenario& scen) {
|
||||
cTown& town = *scen.towns[which];
|
||||
for(int x = 0; x < town.max_dim(); x++) {
|
||||
for(int y = 0; y < town.max_dim(); y++) {
|
||||
@@ -1880,7 +1882,7 @@ static void loadTownMapData(map_data&& data, int which, cScenario& scen) {
|
||||
cVehicle* what;
|
||||
switch(feat.first) {
|
||||
// Special values
|
||||
case eMapFeature::NONE: case eMapFeature::VEHICLE:
|
||||
case eMapFeature::NONE:
|
||||
break;
|
||||
// Outdoor-only features
|
||||
case eMapFeature::TOWN: break;
|
||||
@@ -1890,10 +1892,10 @@ static void loadTownMapData(map_data&& data, int which, cScenario& scen) {
|
||||
case eMapFeature::BOAT:
|
||||
is_boat = true;
|
||||
case eMapFeature::HORSE:
|
||||
what = &(is_boat ? scen.boats : scen.horses)[feat.second % 10000];
|
||||
what = &(is_boat ? scen.boats : scen.horses)[abs(feat.second)];
|
||||
what->which_town = which;
|
||||
what->loc = loc(x,y);
|
||||
what->property = feat.second >= 10000;
|
||||
what->property = feat.second < 0;
|
||||
break;
|
||||
case eMapFeature::SIGN:
|
||||
if(feat.second >= town.sign_locs.size())
|
||||
|
@@ -53,7 +53,7 @@ map_data load_map(std::istream& fin, bool isTown, std::string name) {
|
||||
data.set(col, row, n);
|
||||
else {
|
||||
if((curFeature == eMapFeature::BOAT || curFeature == eMapFeature::HORSE) && !vehicle_owned)
|
||||
n += 10000;
|
||||
n *= -1;
|
||||
data.addFeature(col, row, curFeature, n);
|
||||
}
|
||||
n = 0;
|
||||
@@ -71,18 +71,16 @@ map_data load_map(std::istream& fin, bool isTown, std::string name) {
|
||||
curFeature = eMapFeature::FIELD;
|
||||
} else if(c == '$') {
|
||||
curFeature = eMapFeature::CREATURE;
|
||||
} else if(c == '~') {
|
||||
curFeature = eMapFeature::VEHICLE;
|
||||
} else if(c == 'h' && curFeature == eMapFeature::VEHICLE) {
|
||||
} else if(c == 'h') {
|
||||
vehicle_owned = true;
|
||||
curFeature = eMapFeature::HORSE;
|
||||
} else if(c == 'H' && curFeature == eMapFeature::VEHICLE) {
|
||||
} else if(c == 'H') {
|
||||
vehicle_owned = false;
|
||||
curFeature = eMapFeature::HORSE;
|
||||
} else if(c == 'b' && curFeature == eMapFeature::VEHICLE) {
|
||||
} else if(c == 'b') {
|
||||
vehicle_owned = true;
|
||||
curFeature = eMapFeature::BOAT;
|
||||
} else if(c == 'B' && curFeature == eMapFeature::VEHICLE) {
|
||||
} else if(c == 'B') {
|
||||
vehicle_owned = false;
|
||||
curFeature = eMapFeature::BOAT;
|
||||
} else if(c == ',') {
|
||||
@@ -97,7 +95,7 @@ map_data load_map(std::istream& fin, bool isTown, std::string name) {
|
||||
data.set(col, row, n);
|
||||
else {
|
||||
if((curFeature == eMapFeature::BOAT || curFeature == eMapFeature::HORSE) && !vehicle_owned)
|
||||
n += 10000;
|
||||
n *= -1;
|
||||
data.addFeature(col, row, curFeature, n);
|
||||
}
|
||||
row++;
|
||||
@@ -150,7 +148,7 @@ void map_data::writeTo(std::ostream& out) {
|
||||
out << grid[y][x];
|
||||
for(auto feat : getFeatures(x,y)) {
|
||||
switch(feat.first) {
|
||||
case eMapFeature::NONE: case eMapFeature::VEHICLE: break;
|
||||
case eMapFeature::NONE: break;
|
||||
case eMapFeature::SPECIAL_NODE: out << ':' << feat.second; break;
|
||||
case eMapFeature::SIGN: out << '!' << feat.second; break;
|
||||
case eMapFeature::WANDERING: out << '*' << feat.second; break;
|
||||
@@ -161,8 +159,8 @@ void map_data::writeTo(std::ostream& out) {
|
||||
case eMapFeature::ENTRANCE_NORTH: out << '^'; break;
|
||||
case eMapFeature::ENTRANCE_SOUTH: out << 'v'; break;
|
||||
case eMapFeature::ENTRANCE_WEST: out << '<'; break;
|
||||
case eMapFeature::BOAT: out << (feat.second < 0 ? 'b' : 'B') << abs(feat.second); break;
|
||||
case eMapFeature::HORSE: out << (feat.second < 0 ? 'h' : 'H') << abs(feat.second); break;
|
||||
case eMapFeature::BOAT: out << (feat.second > 0 ? 'b' : 'B') << abs(feat.second); break;
|
||||
case eMapFeature::HORSE: out << (feat.second > 0 ? 'h' : 'H') << abs(feat.second); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,6 @@ enum class eMapFeature {
|
||||
SIGN,
|
||||
WANDERING,
|
||||
TOWN,
|
||||
VEHICLE, // Another special value that shouldn't appear in the map
|
||||
BOAT,
|
||||
HORSE,
|
||||
ENTRANCE_NORTH,
|
||||
|
Reference in New Issue
Block a user