Skip to content

Commit

Permalink
change eop's hidden resource functions too
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Oct 4, 2024
1 parent 5ad1b2e commit 2fdc702
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
10 changes: 10 additions & 0 deletions M2TWEOP Code/M2TWEOP library/types/eopBuildings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ void eopHiddenResources::addHiddenResourceToRegion(const int regionId, const std
m_HiddenResources[regionId].push_back(getHiddenResourceIndex(name));
}

void eopHiddenResources::removeHiddenResourceFromRegion(int regionId, const std::string& name)
{
const auto res = getHiddenResourceIndex(name);
if (res == -1)
return;
auto& hiddenRes = m_HiddenResources[regionId];
if (const auto it = std::find(hiddenRes.begin(), hiddenRes.end(), res); it != hiddenRes.end())
hiddenRes.erase(it);
}

void eopHiddenResources::addHiddenResourceToRegionIndex(const std::string& name, const int id)
{
if (m_NamesToIndexes.find(name) == m_NamesToIndexes.end())
Expand Down
1 change: 1 addition & 0 deletions M2TWEOP Code/M2TWEOP library/types/eopBuildings.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ class eopHiddenResources
static void addHiddenResource(const std::string& name);
static void addHiddenResourceWithId(const std::string& name, int id);
static void addHiddenResourceToRegion(int regionId, const std::string& name);
static void removeHiddenResourceFromRegion(int regionId, const std::string& name);
static void addHiddenResourceToRegionIndex(const std::string& name, int id);
static bool hasHiddenResource(int regionId, int id);
static bool isInitialized() { return m_Initialized; }
Expand Down
18 changes: 6 additions & 12 deletions M2TWEOP Code/M2TWEOP library/types/strategyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,24 +186,18 @@ void regionStruct::changeRebelsName(const char* newName)

bool regionStruct::hasHiddenResource(const char* newName)
{
const auto edb = eopBuildings::getEdb();
if (!edb)
const auto res = eopHiddenResources::getHiddenResourceIndex(newName);
if (res == -1)
return false;
const int index = edb->getHiddenResourceIndex(newName);
if (index < 0)
return false;
return hasHiddenResourceId(index);
return eopHiddenResources::hasHiddenResource(regionID, res);
}

void regionStruct::setHiddenResource(const char* name, const bool enable)
{
const auto edb = eopBuildings::getEdb();
if (!edb)
return;
const int index = edb->getHiddenResourceIndex(name);
if (index < 0)
const auto res = eopHiddenResources::getHiddenResourceIndex(name);
if (res == -1)
return;
setHiddenResourceId(index, enable);
setHiddenResourceId(res, enable);
}

std::pair<int, int> oneTile::getTileCoords()
Expand Down
20 changes: 13 additions & 7 deletions M2TWEOP Code/M2TWEOP library/types/strategyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,20 +513,26 @@ struct regionStruct {
void setHiddenResource(const char* name, bool enable);
bool hasHiddenResourceId(const int index)
{
if (index < 0 || index >= 64)
if (index < 0)
return false;
const uint64_t* hiddenResourcesPtr = reinterpret_cast<uint64_t*>(&hiddenResources);
return *hiddenResourcesPtr & (1ULL << index);
return eopHiddenResources::hasHiddenResource(regionID, index);
}
void setHiddenResourceId(const int index, const bool enable)
{
if (index < 0 || index >= 64)
if (index < 0)
return;
const auto hiddenResourcesPtr = reinterpret_cast<uint64_t*>(&hiddenResources);
if (index < 64)
{
const auto hiddenResourcesPtr = reinterpret_cast<uint64_t*>(&hiddenResources);
if (enable)
*hiddenResourcesPtr |= (1ULL << index);
else
*hiddenResourcesPtr &= ~(1ULL << index);
}
if (enable)
*hiddenResourcesPtr |= (1ULL << index);
eopHiddenResources::addHiddenResourceToRegion(index, regionName);
else
*hiddenResourcesPtr &= ~(1ULL << index);
eopHiddenResources::removeHiddenResourceFromRegion(index, regionName);
}
int getHostileArmiesStrength(const int factionId)
{
Expand Down

0 comments on commit 2fdc702

Please sign in to comment.