From 9fd65cd59756e7272b7ef3e22e43cb6877dbe1f3 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Thu, 3 Sep 2015 03:01:34 -0400 Subject: [PATCH] Vehicles fixes - Fix boats being saved as horses - Fix first boat/horse not saving property status in scenario map data - Game finally supports boats that start outdoors... probably --- src/boe.party.cpp | 4 +++ src/scenedit/scen.fileio.cpp | 12 +++---- src/scenedit/scen.graphics.cpp | 1 - src/tools/fileio_scen.cpp | 6 ++-- test/files/maps/vehicles.map | 2 +- test/map_read.cpp | 16 ++++----- test/map_write.cpp | 62 +++++++++++++++++++++++++++++++--- 7 files changed, 79 insertions(+), 24 deletions(-) diff --git a/src/boe.party.cpp b/src/boe.party.cpp index 027913f7..6f72d859 100644 --- a/src/boe.party.cpp +++ b/src/boe.party.cpp @@ -132,6 +132,8 @@ static void init_party_scen_data() { if(!univ.party.boats[i].exists) { univ.party.boats[i] = univ.scenario.boats[i]; univ.party.boats[i].exists = true; + if(univ.party.boats[i].which_town == 200) + univ.party.boats[i].loc_in_sec = univ.party.boats[i].loc; } } } @@ -140,6 +142,8 @@ static void init_party_scen_data() { if(!univ.party.horses[i].exists) { univ.party.horses[i] = univ.scenario.horses[i]; univ.party.horses[i].exists = true; + if(univ.party.horses[i].which_town == 200) + univ.party.horses[i].loc_in_sec = univ.party.horses[i].loc; } } } diff --git a/src/scenedit/scen.fileio.cpp b/src/scenedit/scen.fileio.cpp index 161ae2d7..96acc942 100644 --- a/src/scenedit/scen.fileio.cpp +++ b/src/scenedit/scen.fileio.cpp @@ -857,14 +857,14 @@ map_data buildOutMapData(location which, cScenario& scenario) { } 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; + int j = i + 1; if(scenario.boats[i].property) j *= -1; - terrain.addFeature(scenario.boats[i].loc.x, scenario.boats[i].loc.y, eMapFeature::HORSE, j); + terrain.addFeature(scenario.boats[i].loc.x, scenario.boats[i].loc.y, eMapFeature::BOAT, 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; + int j = i + 1; if(scenario.horses[i].property) j *= -1; terrain.addFeature(scenario.horses[i].loc.x, scenario.horses[i].loc.y, eMapFeature::HORSE, j); } @@ -905,14 +905,14 @@ map_data buildTownMapData(size_t which, cScenario& scenario) { } for(size_t i = 0; i < scenario.boats.size(); i++) { if(scenario.boats[i].which_town == which) { - int j = i; + int j = i + 1; if(scenario.boats[i].property) j *= -1; - terrain.addFeature(scenario.boats[i].loc.x, scenario.boats[i].loc.y, eMapFeature::HORSE, j); + terrain.addFeature(scenario.boats[i].loc.x, scenario.boats[i].loc.y, eMapFeature::BOAT, j); } } for(size_t i = 0; i < scenario.horses.size(); i++) { if(scenario.horses[i].which_town == which) { - int j = i; + int j = i + 1; if(scenario.horses[i].property) j *= -1; terrain.addFeature(scenario.horses[i].loc.x, scenario.horses[i].loc.y, eMapFeature::HORSE, j); } diff --git a/src/scenedit/scen.graphics.cpp b/src/scenedit/scen.graphics.cpp index b0173b0f..400948c7 100644 --- a/src/scenedit/scen.graphics.cpp +++ b/src/scenedit/scen.graphics.cpp @@ -815,7 +815,6 @@ void draw_terrain(){ which_pt.x = cen_x + q - 4; which_pt.y =cen_y + r - 4; - // TODO: I'm not quite sure whether these should be testing loc or loc_in_sec if(!editing_town) { for(i = 0; i < scenario.boats.size(); i++) { if(scenario.boats[i].which_town == 200 && diff --git a/src/tools/fileio_scen.cpp b/src/tools/fileio_scen.cpp index 8a6ab0ea..0f1e5cba 100644 --- a/src/tools/fileio_scen.cpp +++ b/src/tools/fileio_scen.cpp @@ -1865,10 +1865,10 @@ 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)[abs(feat.second)]; + what = &(is_boat ? scen.boats : scen.horses)[abs(feat.second) - 1]; what->which_town = 200; what->sector = which; - what->loc_in_sec = loc(x,y); + what->loc = loc(x,y); what->property = feat.second < 0; break; case eMapFeature::FIELD: @@ -1913,7 +1913,7 @@ 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)[abs(feat.second)]; + what = &(is_boat ? scen.boats : scen.horses)[abs(feat.second) - 1]; what->which_town = which; what->loc = loc(x,y); what->property = feat.second < 0; diff --git a/test/files/maps/vehicles.map b/test/files/maps/vehicles.map index 3b94548c..ce7c7b82 100644 --- a/test/files/maps/vehicles.map +++ b/test/files/maps/vehicles.map @@ -1 +1 @@ -0h1, 0H2, 0b3, 0B4 \ No newline at end of file +0h2, 0H3, 0b4, 0B5 \ No newline at end of file diff --git a/test/map_read.cpp b/test/map_read.cpp index 6493a62b..92eb4c20 100644 --- a/test/map_read.cpp +++ b/test/map_read.cpp @@ -37,14 +37,14 @@ TEST_CASE("Loading map data from file") { SECTION("With vehicles") { fin.open("files/maps/vehicles.map"); map = load_map(fin, true, "vehicles.map"); - test.emplace_back(make_pair(eMapFeature::HORSE, 1)); + test.emplace_back(make_pair(eMapFeature::HORSE, 2)); CHECK(map.getFeatures(0, 0) == test); - test[0].second = -2; + test[0].second = -3; CHECK(map.getFeatures(1, 0) == test); test[0].first = eMapFeature::BOAT; - test[0].second = 3; + test[0].second = 4; CHECK(map.getFeatures(2, 0) == test); - test[0].second = -4; + test[0].second = -5; CHECK(map.getFeatures(3, 0) == test); } } @@ -85,20 +85,20 @@ TEST_CASE("Interpreting loaded map data") { CHECK_FALSE(scen.horses[1].property); CHECK(scen.horses[1].sector == loc(0,0)); CHECK(scen.horses[1].which_town == 200); - CHECK(scen.horses[1].loc_in_sec == loc(0,0)); + CHECK(scen.horses[1].loc == loc(0,0)); CHECK(scen.horses[2].property); CHECK(scen.horses[2].sector == loc(0,0)); CHECK(scen.horses[2].which_town == 200); - CHECK(scen.horses[2].loc_in_sec == loc(1,0)); + CHECK(scen.horses[2].loc == loc(1,0)); REQUIRE(scen.boats.size() >= 5); CHECK_FALSE(scen.boats[3].property); CHECK(scen.boats[3].sector == loc(0,0)); CHECK(scen.boats[3].which_town == 200); - CHECK(scen.boats[3].loc_in_sec == loc(2,0)); + CHECK(scen.boats[3].loc == loc(2,0)); CHECK(scen.boats[4].property); CHECK(scen.boats[4].sector == loc(0,0)); CHECK(scen.boats[4].which_town == 200); - CHECK(scen.boats[4].loc_in_sec == loc(3,0)); + CHECK(scen.boats[4].loc == loc(3,0)); } SECTION("In town") { map = load_map(fin, true, "vehicles.map"); diff --git a/test/map_write.cpp b/test/map_write.cpp index c141b3a2..0d528e2e 100644 --- a/test/map_write.cpp +++ b/test/map_write.cpp @@ -38,16 +38,18 @@ static void in_and_out(string name, map_data& map, bool town) { } static void in_and_out(cScenario& scen, bool town) { + map_data map = town ? buildTownMapData(0, scen) : buildOutMapData(loc(0,0), scen); + // Reconstruct the scenario, to ensure that it doesn't just pass due to old data still being around + scen.~cScenario(); + new(&scen) cScenario(); + scen.ter_types.resize(50); if(town) { - map_data map = buildTownMapData(0, scen); // Reconstruct the town, to ensure that it doesn't just pass due to old data still being around - delete scen.towns[0]; - scen.towns[0] = new cTinyTown(scen); + scen.addTown(); loadTownMapData(move(map), 0, scen); } else { - map_data map = buildOutMapData(loc(0,0), scen); // Reconstruct the sector, to ensure that it doesn't just pass due to old data still being around - delete scen.outdoors[0][0]; + scen.outdoors.resize(1,1); scen.outdoors[0][0] = new cOutdoors(scen); loadOutMapData(move(map), loc(0,0), scen); } @@ -120,4 +122,54 @@ TEST_CASE("Building map data") { } } } + SECTION("With vehicles") { + scen.boats[0].property = true; + scen.boats[0].loc = {1,1}; + scen.boats[1].property = false; + scen.boats[1].loc = {2,2}; + scen.horses[0].property = true; + scen.horses[0].loc = {3,3}; + scen.horses[1].property = false; + scen.horses[1].loc = {4,4}; + SECTION("Outdoors") { + scen.boats[0].which_town = scen.horses[0].which_town = 200; + scen.boats[1].which_town = scen.horses[1].which_town = 200; + scen.boats[0].sector = scen.horses[0].sector = {0,0}; + scen.boats[1].sector = scen.horses[1].sector = {0,0}; + in_and_out(scen, false); + CHECK(scen.boats[0].property); + CHECK(scen.boats[0].loc == loc(1,1)); + CHECK(scen.boats[0].which_town == 200); + CHECK(scen.boats[0].sector == loc(0,0)); + CHECK_FALSE(scen.boats[1].property); + CHECK(scen.boats[1].loc == loc(2,2)); + CHECK(scen.boats[1].which_town == 200); + CHECK(scen.boats[1].sector == loc(0,0)); + CHECK(scen.horses[0].property); + CHECK(scen.horses[0].loc == loc(3,3)); + CHECK(scen.horses[0].which_town == 200); + CHECK(scen.horses[0].sector == loc(0,0)); + CHECK_FALSE(scen.horses[1].property); + CHECK(scen.horses[1].loc == loc(4,4)); + CHECK(scen.horses[1].which_town == 200); + CHECK(scen.horses[1].sector == loc(0,0)); + } + SECTION("In town") { + scen.boats[0].which_town = scen.horses[0].which_town = 0; + scen.boats[1].which_town = scen.horses[1].which_town = 0; + in_and_out(scen, true); + CHECK(scen.boats[0].property); + CHECK(scen.boats[0].loc == loc(1,1)); + CHECK(scen.boats[0].which_town == 0); + CHECK_FALSE(scen.boats[1].property); + CHECK(scen.boats[1].loc == loc(2,2)); + CHECK(scen.boats[1].which_town == 0); + CHECK(scen.horses[0].property); + CHECK(scen.horses[0].loc == loc(3,3)); + CHECK(scen.horses[0].which_town == 0); + CHECK_FALSE(scen.horses[1].property); + CHECK(scen.horses[1].loc == loc(4,4)); + CHECK(scen.horses[1].which_town == 0); + } + } }