Maniac
Apolyton Sage
I want to add a new function to the SDK. However I'm not sure if I need to declare one of the inputs of the functions as a const or not. I don't really understand the purpose of const's applied practically (despite reading wikipedia).
Can forgetting to make something a const, or needlessly saying something is a const, cause crashes?? Or am I worrying about nothing?
In any case, onwards to my actual situation:
I'm wondering if, in CvPlot.h, I should say:
or rather
I have seen both kinds in CvPlot.h.
For the record, this function is called in CvCity.cpp like this in a doFungalBloom() function I'm creating:
And the actual function in CvPlot.cpp is
Does that pUnitNode stuff look like it'll actually work btw? I want to loop through all units on that plot. I have no theoretical understanding whatsoever about C++. I'm just copying what I saw elsewhere and vaguely looked right.
Can forgetting to make something a const, or needlessly saying something is a const, cause crashes?? Or am I worrying about nothing?
In any case, onwards to my actual situation:
I'm wondering if, in CvPlot.h, I should say:
Code:
int getSpawnValue(CvCity* pCity) const;
Code:
int getSpawnValue(const CvCity* pCity) const;
I have seen both kinds in CvPlot.h.
For the record, this function is called in CvCity.cpp like this in a doFungalBloom() function I'm creating:
Code:
iValue = pLoopPlot->getSpawnValue(this);
And the actual function in CvPlot.cpp is
Code:
int CvPlot::getSpawnValue(CvCity* pCity) const
{
iValue = getSorenRandNum(50, "Spawn Plot Selection")
if (!isUnit())
{
if (getOwner() == pCity->getOwnerINLINE())
{
iValue += 220;
}
if (getFeatureType() != NO_FEATURE && GC.getFeatureInfo(getFeatureType()).getPlanetValue100() > 0)
{
iValue += 110;
}
if (isBeingWorked())
{
iValue += 50;
}
}
else
{
CLLNode<IDInfo>* pUnitNode = headUnitNode();
while (pUnitNode != NULL)
{
CvUnit* pLoopUnit = ::getUnit(pUnitNode->m_data);
pUnitNode = nextUnitNode(pUnitNode);
if (getOwnerINLINE() == BARBARIAN_PLAYER)
{
if (getOwner() == pCity->getOwnerINLINE())
{
iValue += 220;
}
if (getFeatureType() != NO_FEATURE && GC.getFeatureInfo(getFeatureType()).getPlanetValue100() > 0)
{
iValue += 110;
}
if (isBeingWorked())
{
iValue += 50;
}
}
}
}
return iValue
}
Does that pUnitNode stuff look like it'll actually work btw? I want to loop through all units on that plot. I have no theoretical understanding whatsoever about C++. I'm just copying what I saw elsewhere and vaguely looked right.