From 2d9da061704bcdd9b9273c9fc8a40881508866c3 Mon Sep 17 00:00:00 2001 From: Roy Falk Date: Sat, 2 Dec 2023 19:25:04 +0200 Subject: [PATCH] Disable tests with hardcoded build folder Reintroduce mission based random cargo. --- engine/src/resource/manifest.cpp | 24 ++++++++++++++++---- engine/src/resource/manifest.h | 1 + engine/src/resource/tests/manifest_tests.cpp | 6 +++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/engine/src/resource/manifest.cpp b/engine/src/resource/manifest.cpp index 0216bb3474..73bee5bdd2 100644 --- a/engine/src/resource/manifest.cpp +++ b/engine/src/resource/manifest.cpp @@ -131,15 +131,20 @@ Cargo Manifest::GetRandomCargo(int quantity) { return c; } + + Cargo Manifest::GetRandomCargoFromCategory(std::string category, int quantity) { - Manifest category_manifest = GetCategoryManifest(category); + Manifest manifest = GetCategoryManifest(category); // If category is empty, return randomly from MPL itself. - if(category_manifest._items.empty()) { - return GetRandomCargo(quantity); + if(manifest._items.empty()) { + manifest = GetMissionManifest(); + if(manifest._items.empty()) { + return GetRandomCargo(quantity); + } } - return category_manifest.GetRandomCargo(quantity); + return manifest.GetRandomCargo(quantity); } Manifest Manifest::GetCategoryManifest(std::string category) { @@ -152,3 +157,14 @@ Manifest Manifest::GetCategoryManifest(std::string category) { return manifest; } + +Manifest Manifest::GetMissionManifest() { + Manifest manifest; + + std::copy_if(_items.begin(), _items.end(), back_inserter(manifest._items), + [](Cargo c) { + return c.name.find("mission") != std::string::npos; + }); + + return manifest; +} diff --git a/engine/src/resource/manifest.h b/engine/src/resource/manifest.h index 233d65ef45..71d65aeced 100644 --- a/engine/src/resource/manifest.h +++ b/engine/src/resource/manifest.h @@ -47,6 +47,7 @@ class Manifest { Cargo GetRandomCargo(int quantity = 0); Cargo GetRandomCargoFromCategory(std::string category, int quantity = 0); Manifest GetCategoryManifest(std::string category); + Manifest GetMissionManifest(); std::vector getItems() { return _items; } bool empty() { return _items.empty(); } diff --git a/engine/src/resource/tests/manifest_tests.cpp b/engine/src/resource/tests/manifest_tests.cpp index ff53f62e09..a1a742e8b3 100644 --- a/engine/src/resource/tests/manifest_tests.cpp +++ b/engine/src/resource/tests/manifest_tests.cpp @@ -48,7 +48,9 @@ TEST(Manifest, Random) { TEST(Manifest, MPL) { - boost::filesystem::path full_path(boost::filesystem::current_path()); + // TODO: reenable once we figure out how to find out the data folder location + + /*boost::filesystem::path full_path(boost::filesystem::current_path()); std::cerr << "Current path is : " << full_path << std::endl; std::string path = boost::filesystem::current_path().c_str(); path = path + "/../data/"; @@ -69,5 +71,5 @@ TEST(Manifest, MPL) { std::cout << c.GetName() << std::endl; - EXPECT_GT(c.GetName().size(), 0); + EXPECT_GT(c.GetName().size(), 0);*/ } \ No newline at end of file