How to count something SDK?

Duke176

Warlord
Joined
Oct 19, 2006
Messages
241
Location
Turin - Italy
I was trying to study the way to add a counter in order to return the number of something owned by a civ.

I was thinking at something like this:
Code:
int iI;
	
	for (iI = 0; iI < GC.getNumImprovementInfos(); iI++)
	{
		if GC.getImprovementInfo(eImprovement) = GC.getImprovementInfo(GC.getTypeForString("IMPROVEMENT_WELL"));
		iT++;

where I say if you get all the improvements and you find any called IMPROVEMENT_WELL add 1 to iT.
Is this correct?

I'm finding really hard to understand how does the counter works...
Can anyone help me? or even point me to a good tutoral about this?
Thx.
 
I was trying to study the way to add a counter in order to return the number of something owned by a civ.

I was thinking at something like this:
Code:
int iI;
	
	for (iI = 0; iI < GC.getNumImprovementInfos(); iI++)
	{
		if GC.getImprovementInfo(eImprovement) = GC.getImprovementInfo(GC.getTypeForString("IMPROVEMENT_WELL"));
		iT++;

where I say if you get all the improvements and you find any called IMPROVEMENT_WELL add 1 to iT.
Is this correct?

I'm finding really hard to understand how does the counter works...
Can anyone help me? or even point me to a good tutoral about this?
Thx.

I think you will get 1, because you are both looping through and matching against improvement infos.

I think it is more likely that you would have to loop through the plots.

Maybe the code behind CyPlayer.countOwnedBonuses() could be adapted for your needs? (I haven't looked at it.)
 
thx for answering 1st of all.
My prb is this:
there's a function called getNumAvailableBonuses((BonusType) eBonus); the prb of this function is that it returns only the bonuses that you own and doesn't have anything relted to the improvement you built on it. So If I use that function I'll have all the bonuses OIL the civ owns but not how many Wells or Platforms have been built.

getNumAvailableBonuses(...) is based on a function called getNumBonuses() that have have the correspondent getNumImprovements() - inside CvArea.cpp. I've tried to extend getNumImprovements() - that takes no arguments so I canno specify the improvement I want to be counted - but seems not work.

What I would try to do in the end is to create a counter that loop throw the plots and returns the number of Wells or Platoforms, inside player owned territory, it finds.

Could work better something like this?
Code:
int CvPlayer::getNumAvailableOilImprovements()
{
	CvPlot* pLoopPlot;
int iCounter = 0;
int iI;

for( iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++ )
{
     pLoopPlot = GC.getMapINLINE().getPlot(iI);
     if( pLoopPlot != NULL && pLoopPlot->hasIsImporvement((ImprovementTypes(GC.getInfoTypeForString("IMPROVEMENT_OFFSHORE_PLATFORM")))))
     {
          iCounter += 1;
     }
}

return iCounter;
}

there could be a way, if anyone knows, to use getNumAvailableBonuses(...) making a distinction between terrain / water bonuses? because this function returns only the bonuses that are linked with improvement and roads to cities. so if it's possible to create and if.... maybe iswater... so return.
What do you think?
 
what about this?
Code:
int CvPlayer::getNumAvailableOilImprovements()

//	int NumImprovements;
//	NumImprovements = GC.getNumImprovementInfos(GC.getInfoTypeForString("IMPROVEMENT_WELL"));
//	return NumImprovements;
{
	CvPlot* pLoopPlot;
int iCounter = 0;
int iI;

for( iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++ )
{
     pLoopPlot = GC.getMapINLINE().numPlots();
     if( pLoopPlot != NULL && pLoopPlot->getImprovementType() == GC.getInfoTypeForString("IMPROVEMENT_OFFSHORE_PLATFORM"))
     {
          iCounter += 1;
     }
     return iCounter;
}
 
all right I really need someone to help me or show me good tutorial in order to obtain a thing I'm not able to do at this point and alone.

I would like to create a counter that tell the game to:

1) get all the plot owned by the player
2) look for those that don't are NULL && look for those that have Available Bonuses (so in use, so roads and improvement) && add +1 to the counter each time that it finds one that is BONUS_OIL != isWater=true.

So it should reaturns me the number of platforms and if I change True with False it should returns me the number of Wells.

Do you think is possible???
and an indication of how?
Because it doesn't exist getNumAvailableImprovements and if I create a whole group of function to have it exactly the same as getNumAvailableBonuses the compiler returns me this error:
http://forums.civfanatics.com/showthread.php?t=198986
 
resolved prb thx again for KAEL :D
Code:
int CvPlayer::getNumAvailableOilImprovements()
{
	CvPlot* pLoopPlot;
	int iCount = 0;
	int iI;

	for (iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++)
		{
			pLoopPlot = GC.getMapINLINE().plotByIndexINLINE(iI);
			if (pLoopPlot->getImprovementType() == GC.getInfoTypeForString("IMPROVEMENT_WELL"))
			{
			iCount = iCount + 1;
			}
		}
    return iCount;
}
 
Back
Top Bottom