Can someone explain what is going on in this piece of code?

Terradive

Warlord
Joined
Jun 4, 2009
Messages
186
It comes from the Legend of Revolutions Mod. It is from the CVPlayer.cpp file. It is trying to delete a unit and it goes to looking at selection groups. Is a selection group a group of selected units? If yes what happens if a unit is unselectable?

Code:
void CvPlayer::deleteUnit(int iID)																	
{
	m_units.removeAt(iID);
}


CvSelectionGroup* CvPlayer::firstSelectionGroup(int *pIterIdx, bool bRev) const
{
	return !bRev ? m_selectionGroups.beginIter(pIterIdx) : m_selectionGroups.endIter(pIterIdx);
}


CvSelectionGroup* CvPlayer::nextSelectionGroup(int *pIterIdx, bool bRev) const
{
	return !bRev ? m_selectionGroups.nextIter(pIterIdx) : m_selectionGroups.prevIter(pIterIdx);
}


int CvPlayer::getNumSelectionGroups() const																
{
	return m_selectionGroups.getCount();
}


CvSelectionGroup* CvPlayer::getSelectionGroup(int iID) const												
{
	return ((CvSelectionGroup *)(m_selectionGroups.getAt(iID)));
}


CvSelectionGroup* CvPlayer::addSelectionGroup()
{
	return ((CvSelectionGroup *)(m_selectionGroups.add()));
}
 
It comes from the Legend of Revolutions Mod. It is from the CVPlayer.cpp file. It is trying to delete a unit and it goes to looking at selection groups. Is a selection group a group of selected units? If yes what happens if a unit is unselectable?

Code:
void CvPlayer::deleteUnit(int iID)																	
{
	m_units.removeAt(iID);
}


CvSelectionGroup* CvPlayer::firstSelectionGroup(int *pIterIdx, bool bRev) const
{
	return !bRev ? m_selectionGroups.beginIter(pIterIdx) : m_selectionGroups.endIter(pIterIdx);
}


CvSelectionGroup* CvPlayer::nextSelectionGroup(int *pIterIdx, bool bRev) const
{
	return !bRev ? m_selectionGroups.nextIter(pIterIdx) : m_selectionGroups.prevIter(pIterIdx);
}


int CvPlayer::getNumSelectionGroups() const																
{
	return m_selectionGroups.getCount();
}


CvSelectionGroup* CvPlayer::getSelectionGroup(int iID) const												
{
	return ((CvSelectionGroup *)(m_selectionGroups.getAt(iID)));
}


CvSelectionGroup* CvPlayer::addSelectionGroup()
{
	return ((CvSelectionGroup *)(m_selectionGroups.add()));
}

These are totally separate methods from a C++ class. It's not a sequential script. If deleteUnit() gets called, then the only code that gets executed is what's between the curly braces, i.e.

Code:
m_units.removeAt(iID);
 
CvSelectionGroup* CvPlayer::getSelectionGroup(int iID) const
{
return ((CvSelectionGroup *)(m_selectionGroups.getAt(iID)));
}

I am having problems with this piece of code when called. There apparently is no value in it. I believe because it is looking for a unit that has been deleted. I am trying to alter it to this in attempt to get around this. If anyone has a better idea, I would appreciate it.

CvSelectionGroup* CvPlayer::getSelectionGroup(int iID) const
{
if (iID != NULL)
return ((CvSelectionGroup *)(m_selectionGroups.getAt(iID)))
}
 
Back
Top Bottom