Skip to content

Commit

Permalink
Disable tests with hardcoded build folder
Browse files Browse the repository at this point in the history
Reintroduce mission based random cargo.
  • Loading branch information
royfalk committed Dec 2, 2023
1 parent 7080b98 commit 2d9da06
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
24 changes: 20 additions & 4 deletions engine/src/resource/manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
1 change: 1 addition & 0 deletions engine/src/resource/manifest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cargo> getItems() { return _items; }
bool empty() { return _items.empty(); }
Expand Down
6 changes: 4 additions & 2 deletions engine/src/resource/tests/manifest_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand All @@ -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);*/
}

0 comments on commit 2d9da06

Please sign in to comment.