Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting rid of undefined set sorting order #10112

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions CvGameCoreDLL_Expansion2/CvAStar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2939,10 +2939,6 @@ map<int,SPath> CvPathFinder::GetMultiplePaths(const CvPlot* pStartPlot, vector<C
}

//sort for fast search
struct PrSortByPlotIndex
{
bool operator()(const CvPlot* lhs, const CvPlot* rhs) const { return lhs->GetPlotIndex() < rhs->GetPlotIndex(); }
};
std::stable_sort( vDestPlots.begin(), vDestPlots.end(), PrSortByPlotIndex() );

//there is no destination! the return value will always be false
Expand Down
2 changes: 1 addition & 1 deletion CvGameCoreDLL_Expansion2/CvMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ inline int coordRange(int iCoord, int iRange, bool bWrap)
}

class CvPlotManager;
typedef std::set<CvPlot*> DeferredFogPlots;
typedef std::set<CvPlot*, PrSortByPlotIndex> DeferredFogPlots;
typedef std::map<PlayerTypes, std::map<int, int>> UnitKillCount;

//
Expand Down
5 changes: 5 additions & 0 deletions CvGameCoreDLL_Expansion2/CvPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,11 @@ SYNC_ARCHIVE_BEGIN(CvPlot)
SYNC_ARCHIVE_VAR(char, m_eFeatureType)
SYNC_ARCHIVE_END()

struct PrSortByPlotIndex
{
bool operator()(const CvPlot* lhs, const CvPlot* rhs) const { return lhs->GetPlotIndex() < rhs->GetPlotIndex(); }
};

#if defined(MOD_BALANCE_CORE_MILITARY)
struct SPlotWithScore
{
Expand Down
12 changes: 8 additions & 4 deletions CvGameCoreDLL_Expansion2/CvTacticalAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2646,7 +2646,7 @@ bool CvTacticalAI::CheckForEnemiesNearArmy(CvArmyAI* pArmy)
return false;

//make a unique set of enemy units
set<CvPlot*> allEnemyPlots;
set<CvPlot*, PrSortByPlotIndex> allEnemyPlots;
vector<CvUnit*> vUnitsInitial, vUnitsFinal;
CvUnit* pUnit = pArmy->GetFirstUnit();
while (pUnit)
Expand Down Expand Up @@ -2685,7 +2685,7 @@ bool CvTacticalAI::CheckForEnemiesNearArmy(CvArmyAI* pArmy)
{
CvUnit* pOurUnit = vUnitsInitial[i];
int iMinDistForThisUnit = INT_MAX;
for (set<CvPlot*>::iterator it = allEnemyPlots.begin(); it != allEnemyPlots.end(); ++it)
for (set<CvPlot*, PrSortByPlotIndex>::iterator it = allEnemyPlots.begin(); it != allEnemyPlots.end(); ++it)
{
int iDistance = plotDistance(*pOurUnit->plot(), **it);
if (pOurUnit->getDomainType() != (*it)->getDomain())
Expand Down Expand Up @@ -10484,10 +10484,14 @@ vector<STacticalAssignment> TacticalAIHelpers::FindBestUnitAssignments(
OutputDebugString("warning, long running simulation\n"); //put a breakpoint here ...

CvString strMsg;
strMsg.Format("tactsim %s, target %d:%d with %d units (agglvl %d). last dangerplots update at %d. tested %d, completed %d, open %d (%.2f ms).",
/*strMsg.Format("tactsim %s, target %d:%d with %d units (agglvl %d). last dangerplots update at %d. tested %d, completed %d, open %d (%.2f ms).",
result.empty() ? "failed" : "success",
pTarget->getX(), pTarget->getY(), ourUnits.size(), eAggLvl, GET_PLAYER(ePlayer).GetDangerPlotAge(),
iUsedPositions, completedPositions.size(), openPositionsHeap.size(), timer.GetDeltaInSeconds()*1000.f );
iUsedPositions, completedPositions.size(), openPositionsHeap.size(), timer.GetDeltaInSeconds()*1000.f );*/
strMsg.Format("tactsim %s, target %d:%d with %d units (agglvl %d). last dangerplots update at %d. tested %d, completed %d, open %d.",
result.empty() ? "failed" : "success",
pTarget->getX(), pTarget->getY(), ourUnits.size(), eAggLvl, GET_PLAYER(ePlayer).GetDangerPlotAge(),
iUsedPositions, completedPositions.size(), openPositionsHeap.size());
GET_PLAYER(ePlayer).GetTacticalAI()->LogTacticalMessage(strMsg);

//debug dump
Expand Down
4 changes: 2 additions & 2 deletions CvGameCoreDLL_Expansion2/CvTacticalAnalysisMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ void CvTacticalAnalysisMap::CreateDominanceZones()
m_IdLookup[0] = 0;

//not all plots belong to a city
std::tr1::unordered_set<CvPlot*> nonCityZonePlots;
std::set<CvPlot*, PrSortByPlotIndex> nonCityZonePlots;

//don't make our zones too large
int iMaxRange = 4;
Expand Down Expand Up @@ -739,7 +739,7 @@ void CvTacticalAnalysisMap::CreateDominanceZones()
//must be same area but do not create extra zones for small lakes or islands
if (neighbor->getArea() == current->getArea() || neighbor->area()->getNumTiles()<4 || current->area()->getNumTiles()<4)
{
std::tr1::unordered_set<CvPlot*>::iterator it = nonCityZonePlots.find(neighbor);
std::set<CvPlot*, PrSortByPlotIndex>::iterator it = nonCityZonePlots.find(neighbor);
if (it != nonCityZonePlots.end())
{
stack.push_back(*it);
Expand Down
6 changes: 3 additions & 3 deletions CvGameCoreDLL_Expansion2/CvUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2859,15 +2859,15 @@ void CvUnit::kill(bool bDelay, PlayerTypes ePlayer /*= NO_PLAYER*/)
//check if this removes a blockade immediately (would be lifted anyhow once the enemy turn starts but nice for humans)
if (IsCombatUnit())
{
set<CvCity*> affectedCities;
vector<CvCity*> affectedCities;
for (int i = 0; i < RING_PLOTS[GetBlockadeRange()]; i++)
{
CvPlot* pNeighbor = iterateRingPlots(pPlot, i);
if (pNeighbor && pNeighbor->getLandmass()==pPlot->getLandmass() && pNeighbor->isBlockaded(pNeighbor->getOwner()))
affectedCities.insert( pPlot->getEffectiveOwningCity() );
affectedCities.push_back( pPlot->getEffectiveOwningCity() );
}

for (set<CvCity*>::iterator it = affectedCities.begin(); it != affectedCities.end(); ++it)
for (vector<CvCity*>::iterator it = affectedCities.begin(); it != affectedCities.end(); ++it)
{
//we assume blockades are lifted ... so find better plot assignments
if ((*it) && (*it)->GetCityCitizens()->DoVerifyWorkingPlots())
Expand Down