Code fix for very slow blockading

Gyathaar

Warlock
GOTM Staff
Retired Moderator
Joined
Nov 19, 2003
Messages
3,754
Location
Trondheim, Norway
I noticed that using boats to blockade takes very long time...

I re-programmed two functions in the DLL to speed it up:
Code:
void CvUnit::updatePlunder(int iChange)
{
	int iBlockadeRange = GC.getDefineINT("SHIP_BLOCKADE_RANGE");

	bool btradeNetChanged[MAX_TEAMS];
	bool bOldTradeNet;

	for (int iTeam = 0; iTeam < MAX_TEAMS; ++iTeam)
	{
		btradeNetChanged[iTeam] = false;
		if (isEnemy((TeamTypes)iTeam))
		{
			for (int i = -iBlockadeRange; i <= iBlockadeRange; ++i)
			{
				for (int j = -iBlockadeRange; j <= iBlockadeRange; ++j)
				{
					CvPlot* pLoopPlot = ::plotXY(getX_INLINE(), getY_INLINE(), i, j);

					if (NULL != pLoopPlot && pLoopPlot->isWater() && pLoopPlot->area() == area())
					{
						if(!btradeNetChanged[iTeam])
						{
							bOldTradeNet = pLoopPlot->isTradeNetwork((TeamTypes)iTeam);
						}
						pLoopPlot->changeBlockadedCount((TeamTypes)iTeam, iChange);
						if(!btradeNetChanged[iTeam])
						{
							btradeNetChanged[iTeam] = (bOldTradeNet != pLoopPlot->isTradeNetwork((TeamTypes)iTeam));
						}
					}
				}
			}
		}
	}
	bool bChanged=false;
	for (int iTeam = 0; iTeam < MAX_TEAMS; ++iTeam)
	{
		bChanged = bChanged || btradeNetChanged[iTeam];
	}
	if(bChanged)
	{
		gDLL->getInterfaceIFace()->setDirty(BlockadedPlots_DIRTY_BIT, true);
		for (int iPlayer = 0; iPlayer < MAX_PLAYERS; ++iPlayer)
		{
			CvPlayer& kPlayer = GET_PLAYER((PlayerTypes)iPlayer);
			if (kPlayer.isAlive())
			{
				TeamTypes kTeam = kPlayer.getTeam();
				if(kTeam != NO_TEAM && btradeNetChanged[kTeam]){
					kPlayer.updatePlotGroups();
				}
			}
		}
	}
}
and
Code:
void CvPlot::changeBlockadedCount(TeamTypes eTeam, int iChange)
{
	FAssertMsg(eTeam >= 0, "eTeam is expected to be non-negative (invalid Index)");
	FAssertMsg(eTeam < MAX_TEAMS, "eTeam is expected to be within maximum bounds (invalid Index)");

	if (iChange != 0)
	{
		if (NULL == m_aiBlockadedCount)
		{
			m_aiBlockadedCount = new short[MAX_TEAMS];
			for (int iI = 0; iI < MAX_TEAMS; ++iI)
			{
				m_aiBlockadedCount[iI] = 0;
			}
		}

		m_aiBlockadedCount[eTeam] += iChange;
		FAssert(getBlockadedCount(eTeam) >= 0);
		FAssert(getBlockadedCount(eTeam) == 0 || isWater())

		CvCity* pWorkingCity = getWorkingCity();
		if (NULL != pWorkingCity)
		{
			pWorkingCity->AI_setAssignWorkDirty(true);
		}
	}
}

With these modified functions, placing a blockade on my normal sized test-map dropped from 20 secs to less than 1 sec
 
Wow that's great, blockades were freezing up my screen forever. Is this going to be added to the Unofficial BtS Patch?
 
Please incorporate this to the patch....that slow blockades makes me sick!
 
Similar speed up code for alliance forming:

in CvTeam::addTeam
replace this section:
Code:
		if (pLoopPlot->isRevealed(eTeam, false))
		{
			pLoopPlot->setRevealed(getID(), true, false, eTeam);
		}
	}
with
Code:
		if (pLoopPlot->isRevealed(eTeam, false))
		{
			pLoopPlot->setRevealed(getID(), true, false, eTeam ,false);
		}
	}

	for (iI = 0; iI < MAX_PLAYERS; iI++) 
	{ 
		if (GET_PLAYER((PlayerTypes)iI).isAlive()) 
		{ 
			if (GET_PLAYER((PlayerTypes)iI).getTeam() == getID()) 
			{ 
				GET_PLAYER((PlayerTypes)iI).updatePlotGroups(); 
			} 
		} 
	}
 
Top Bottom