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
This commit is contained in:
2015-09-03 03:01:34 -04:00
parent d3b0b26deb
commit 9fd65cd597
7 changed files with 79 additions and 24 deletions

View File

@@ -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;
}
}
}

View File

@@ -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);
}

View File

@@ -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 &&

View File

@@ -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;

View File

@@ -1 +1 @@
0h1, 0H2, 0b3, 0B4
0h2, 0H3, 0b4, 0B5

View File

@@ -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");

View File

@@ -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<cTinyTown>();
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);
}
}
}