Skip to content

Commit

Permalink
Merge pull request #1671 from OutpostUniverse/Rename-Mine-to-OreDeposit
Browse files Browse the repository at this point in the history
Rename mine to ore deposit
  • Loading branch information
DanRStevens authored Mar 11, 2025
2 parents ab42a74 + 16680c0 commit b0a0893
Show file tree
Hide file tree
Showing 31 changed files with 240 additions and 239 deletions.
10 changes: 5 additions & 5 deletions appOPHD/Constants/Strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ namespace constants
const std::string TileDifficult = "Difficult";
const std::string TileImpassable = "Impassable";

const std::string MineYieldLow = "Low";
const std::string MineYieldMedium = "Medium";
const std::string MineYieldHigh = "High";
const std::string OreDepositYieldLow = "Low";
const std::string OreDepositYieldMedium = "Medium";
const std::string OreDepositYieldHigh = "High";

const std::string ProductTransferTitle = "Remaining Product";
const std::string ProductTransferMessage = "Bulldozing this Warehouse will result in some products being discarded due to insufficient storage space at other warehouses.\n\nDo you want to discard these products?";
Expand Down Expand Up @@ -262,7 +262,7 @@ namespace constants

const std::string AlertLanderLocation = "Lander Location";
const std::string AlertSeedTerrain = "The " + SeedLander + " cannot be placed on or near Impassable terrain.";
const std::string AlertSeedMine = "The " + SeedLander + " cannot be placed on or near a tile flagged with a Mine.";
const std::string AlertSeedOreDeposit = "The " + SeedLander + " cannot be placed on or near a tile flagged with a mine beacon.";
const std::string AlertSeedEdgeBuffer = SeedLander + "'s cannot be placed within 3 tiles of the edge of the site map.";

const std::string AlertLanderTileObstructed = "Cannot place Lander because there is an object on the selected tile.";
Expand All @@ -273,7 +273,7 @@ namespace constants
const std::string AlertStructureTileObstructed = "The selected tile already has a structure on it. You must bulldoze the existing structure in order to build here.";
const std::string AlertStructureTileMapObject = "The selected tile is occupied by another object.";
const std::string AlertStructureTerrain = "The selected tile is not bulldozed. Structures can only be built on bulldozed tiles.";
const std::string AlertStructureMineInWay = "The selected tile contains a Mine. Structures cannot be built on Mines.";
const std::string AlertStructureOreDepositInWay = "The selected tile contains an ore deposit. Structures cannot be built on ore deposits.";
const std::string AlertStructureExcavated = "Structures can only be placed on a tile that has been excavated and bulldozed.";
const std::string AlertStructureNoTube = "The selected tile has no connection to the Command Center.";
const std::string AlertStructureInsufficientResources = "You have insufficient resources to build this Structure. To build this structure, you will need an additional:\n\n";
Expand Down
18 changes: 9 additions & 9 deletions appOPHD/Map/Tile.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Tile.h"

#include "../MapObjects/Mine.h"
#include "../MapObjects/OreDeposit.h"
#include "../MapObjects/Robot.h"
#include "../MapObjects/Structure.h"

Expand All @@ -19,12 +19,12 @@ Tile::Tile(Tile&& other) noexcept :
mIndex{other.mIndex},
mPosition{other.mPosition},
mMapObject{other.mMapObject},
mMine{other.mMine},
mOreDeposit{other.mOreDeposit},
mOverlay{other.mOverlay},
mExcavated{other.mExcavated}
{
other.mMapObject = nullptr;
other.mMine = nullptr;
other.mOreDeposit = nullptr;
}


Expand All @@ -33,20 +33,20 @@ Tile& Tile::operator=(Tile&& other) noexcept
mIndex = other.mIndex;
mPosition = other.mPosition;
mMapObject = other.mMapObject;
mMine = other.mMine;
mOreDeposit = other.mOreDeposit;
mOverlay = other.mOverlay;
mExcavated = other.mExcavated;

other.mMapObject = nullptr;
other.mMine = nullptr;
other.mOreDeposit = nullptr;

return *this;
}


Tile::~Tile()
{
delete mMine;
delete mOreDeposit;
delete mMapObject;
}

Expand Down Expand Up @@ -100,10 +100,10 @@ void Tile::removeMapObject()
}


void Tile::pushMine(Mine* mine)
void Tile::placeOreDeposit(OreDeposit* oreDeposit)
{
delete mMine;
mMine = mine;
delete mOreDeposit;
mOreDeposit = oreDeposit;
}


Expand Down
12 changes: 6 additions & 6 deletions appOPHD/Map/Tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <NAS2D/Math/Vector.h>


class Mine;
class OreDeposit;
class MapObject;
class Robot;
class Structure;
Expand Down Expand Up @@ -54,7 +54,7 @@ class Tile

bool empty() const { return mMapObject == nullptr; }

bool hasMine() const { return mMine != nullptr; }
bool hasOreDeposit() const { return mOreDeposit != nullptr; }

Structure* structure() const;
Robot* robot() const;
Expand All @@ -67,9 +67,9 @@ class Tile

void removeMapObject();

const Mine* mine() const { return mMine; }
Mine* mine() { return mMine; }
void pushMine(Mine*);
const OreDeposit* oreDeposit() const { return mOreDeposit; }
OreDeposit* oreDeposit() { return mOreDeposit; }
void placeOreDeposit(OreDeposit*);

void overlay(Overlay overlay) { mOverlay = overlay; }
Overlay overlay() const { return mOverlay; }
Expand All @@ -82,7 +82,7 @@ class Tile
MapCoordinate mPosition;

MapObject* mMapObject = nullptr;
Mine* mMine = nullptr;
OreDeposit* mOreDeposit = nullptr;

Overlay mOverlay{Overlay::None};

Expand Down
75 changes: 38 additions & 37 deletions appOPHD/Map/TileMap.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "TileMap.h"

#include "../MapObjects/Mine.h"
#include "../MapObjects/OreDeposit.h"
#include "../MapObjects/Structure.h"

#include <libOPHD/DirectionOffset.h>
Expand Down Expand Up @@ -39,7 +39,7 @@ namespace {
}


std::vector<NAS2D::Point<int>> generateMineLocations(NAS2D::Vector<int> mapSize, std::size_t mineCount)
std::vector<NAS2D::Point<int>> generateOreDeposits(NAS2D::Vector<int> mapSize, std::size_t oreDepositCount)
{
auto randPoint = [mapSize]() {
return NAS2D::Point{
Expand All @@ -49,13 +49,13 @@ namespace {
};

std::vector<NAS2D::Point<int>> locations;
locations.reserve(mineCount);
locations.reserve(oreDepositCount);

// Some locations might not be acceptable, so try up to twice as many locations
// A high density of mines could result in many rejected locations
// A high density of ore deposits could result in many rejected locations
// Don't try indefinitely to avoid possibility of infinite loop
std::vector<bool> usedLocations(linearSize(mapSize));
for (std::size_t i = 0; (locations.size() < mineCount) && (i < mineCount * 2); ++i)
for (std::size_t i = 0; (locations.size() < oreDepositCount) && (i < oreDepositCount * 2); ++i)
{
// Generate a location and check surroundings for minimum spacing
const auto point = randPoint();
Expand All @@ -74,32 +74,32 @@ namespace {
}


void placeMines(TileMap& tileMap, const std::vector<NAS2D::Point<int>>& locations, const TileMap::MineYields& mineYields)
void placeOreDeposits(TileMap& tileMap, const std::vector<NAS2D::Point<int>>& locations, const TileMap::OreDepositYields& oreDepositYields)
{
const auto total = std::accumulate(mineYields.begin(), mineYields.end(), 0);
const auto total = std::accumulate(oreDepositYields.begin(), oreDepositYields.end(), 0);

const auto randYield = [mineYields, total]() {
const auto randYield = [oreDepositYields, total]() {
const auto randValue = randomNumber.generate<int>(1, total);
return (randValue <= mineYields[0]) ? MineProductionRate::Low :
(randValue <= mineYields[0] + mineYields[1]) ? MineProductionRate::Medium :
MineProductionRate::High;
return (randValue <= oreDepositYields[0]) ? OreDepositYield::Low :
(randValue <= oreDepositYields[0] + oreDepositYields[1]) ? OreDepositYield::Medium :
OreDepositYield::High;
};

for (const auto& location : locations)
{
auto& tile = tileMap.getTile({location, 0});
tile.pushMine(new Mine(randYield()));
tile.placeOreDeposit(new OreDeposit(randYield()));
tile.index(TerrainType::Dozed);
}
}
}


TileMap::TileMap(const std::string& mapPath, int maxDepth, std::size_t mineCount, const MineYields& mineYields) :
TileMap::TileMap(const std::string& mapPath, int maxDepth, std::size_t oreDepositCount, const OreDepositYields& oreDepositYields) :
TileMap{mapPath, maxDepth}
{
mMineLocations = generateMineLocations(mSizeInTiles, mineCount);
placeMines(*this, mMineLocations, mineYields);
mOreDepositLocations = generateOreDeposits(mSizeInTiles, oreDepositCount);
placeOreDeposits(*this, mOreDepositLocations, oreDepositYields);
}


Expand All @@ -111,16 +111,16 @@ TileMap::TileMap(const std::string& mapPath, int maxDepth) :
}


void TileMap::removeMineLocation(const NAS2D::Point<int>& pt)
void TileMap::removeOreDepositLocation(const NAS2D::Point<int>& pt)
{
auto& tile = getTile({pt, 0});
if (!tile.hasMine())
if (!tile.hasOreDeposit())
{
throw std::runtime_error("No mine found to remove");
throw std::runtime_error("No ore deposit found to remove");
}

mMineLocations.erase(find(mMineLocations.begin(), mMineLocations.end(), pt));
tile.pushMine(nullptr);
mOreDepositLocations.erase(find(mOreDepositLocations.begin(), mOreDepositLocations.end(), pt));
tile.placeOreDeposit(nullptr);
}


Expand Down Expand Up @@ -177,15 +177,15 @@ void TileMap::buildTerrainMap(const std::string& path)
void TileMap::serialize(NAS2D::Xml::XmlElement* element)
{
// ==========================================
// MINES
// ORE DEPOSITS (MINES)
// ==========================================
auto* mines = new NAS2D::Xml::XmlElement("mines");
element->linkEndChild(mines);
auto* oreDeposits = new NAS2D::Xml::XmlElement("mines");
element->linkEndChild(oreDeposits);

for (const auto& location : mMineLocations)
for (const auto& location : mOreDepositLocations)
{
auto& mine = *getTile({location, 0}).mine();
mines->linkEndChild(mine.serialize(location));
auto& oreDeposit = *getTile({location, 0}).oreDeposit();
oreDeposits->linkEndChild(oreDeposit.serialize(location));
}


Expand All @@ -204,7 +204,7 @@ void TileMap::serialize(NAS2D::Xml::XmlElement* element)
auto& tile = getTile({point, depth});
if (
((depth > 0 && tile.excavated()) || (tile.index() == TerrainType::Dozed)) &&
(tile.empty() && tile.mine() == nullptr)
(tile.empty() && tile.oreDeposit() == nullptr)
)
{
tiles->linkEndChild(
Expand All @@ -226,21 +226,22 @@ void TileMap::serialize(NAS2D::Xml::XmlElement* element)

void TileMap::deserialize(NAS2D::Xml::XmlElement* element)
{
for (auto* mineElement = element->firstChildElement("mines")->firstChildElement("mine"); mineElement; mineElement = mineElement->nextSiblingElement())
// ORE DEPOSITS (MINES)
for (auto* oreDepositElement = element->firstChildElement("mines")->firstChildElement("mine"); oreDepositElement; oreDepositElement = oreDepositElement->nextSiblingElement())
{
const auto mineDictionary = NAS2D::attributesToDictionary(*mineElement);
const auto oreDepositDictionary = NAS2D::attributesToDictionary(*oreDepositElement);

const auto x = mineDictionary.get<int>("x");
const auto y = mineDictionary.get<int>("y");
const auto x = oreDepositDictionary.get<int>("x");
const auto y = oreDepositDictionary.get<int>("y");

Mine* mine = new Mine();
mine->deserialize(mineElement);
OreDeposit* oreDeposit = new OreDeposit();
oreDeposit->deserialize(oreDepositElement);

auto& tile = getTile({{x, y}, 0});
tile.pushMine(mine);
tile.placeOreDeposit(oreDeposit);
tile.index(TerrainType::Dozed);

mMineLocations.push_back(Point{x, y});
mOreDepositLocations.push_back(Point{x, y});
}

// TILES AT INDEX 0 WITH NO THINGS
Expand Down Expand Up @@ -294,9 +295,9 @@ void TileMap::AdjacentCost(void* state, std::vector<micropather::StateCost>* adj
}


bool TileMap::isTileBlockedByMine(const Tile& tile) const
bool TileMap::isTileBlockedByOreDeposit(const Tile& tile) const
{
return getTile({tile.xy(), 0}).hasMine();
return getTile({tile.xy(), 0}).hasOreDeposit();
}


Expand Down
12 changes: 6 additions & 6 deletions appOPHD/Map/TileMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ enum class Direction;
class TileMap : public micropather::Graph
{
public:
using MineYields = std::array<int, 3>; // {low, med, high}
using OreDepositYields = std::array<int, 3>; // {low, med, high}

TileMap(const std::string& mapPath, int maxDepth, std::size_t mineCount, const MineYields& mineYields);
TileMap(const std::string& mapPath, int maxDepth, std::size_t oreDepositCount, const OreDepositYields& oreDepositYields);
TileMap(const std::string& mapPath, int maxDepth);
TileMap(const TileMap&) = delete;
TileMap& operator=(const TileMap&) = delete;
Expand All @@ -44,8 +44,8 @@ class TileMap : public micropather::Graph
const Tile& getTile(const MapCoordinate& position) const;
Tile& getTile(const MapCoordinate& position);

const std::vector<NAS2D::Point<int>>& mineLocations() const { return mMineLocations; }
void removeMineLocation(const NAS2D::Point<int>& pt);
const std::vector<NAS2D::Point<int>>& oreDepositLocations() const { return mOreDepositLocations; }
void removeOreDepositLocation(const NAS2D::Point<int>& pt);

void serialize(NAS2D::Xml::XmlElement* element);
void deserialize(NAS2D::Xml::XmlElement* element);
Expand All @@ -56,7 +56,7 @@ class TileMap : public micropather::Graph
void AdjacentCost(void* state, std::vector<micropather::StateCost>* adjacent) override;
void PrintStateInfo(void* /*state*/) override {}

bool isTileBlockedByMine(const Tile&) const;
bool isTileBlockedByOreDeposit(const Tile&) const;

private:
std::size_t linearSize() const;
Expand All @@ -68,7 +68,7 @@ class TileMap : public micropather::Graph
const NAS2D::Vector<int> mSizeInTiles;
const int mMaxDepth = 0;
std::vector<Tile> mTileMap;
std::vector<NAS2D::Point<int>> mMineLocations;
std::vector<NAS2D::Point<int>> mOreDepositLocations;

std::string mMapPath;
};
Loading

0 comments on commit b0a0893

Please sign in to comment.