Afforess
The White Wizard
I'm very new to pointers. I don't understand them very much, so keep that in mind in any explanations.
Now, I'm trying to get a city's ID in CvDeal.cpp, but can't seem to get it to work. I'm sure it's very simple, but I always have trouble with simple tasks. This is the line of code I used:
The compiler says it can not convert an int to CvCity*.
For reference, the rest of the code block is:
And because CvPlayer::getBestHQCity() is a new function , I'll post that too:
Now, I'm trying to get a city's ID in CvDeal.cpp, but can't seem to get it to work. I'm sure it's very simple, but I always have trouble with simple tasks. This is the line of code I used:
Code:
CvCity* pHQCity = pNewHQCity->getID();
The compiler says it can not convert an int to CvCity*.
For reference, the rest of the code block is:
Spoiler :
Code:
case TRADE_CORPORATION:
if (GC.getGameINLINE().isOption(GAMEOPTION_ADVANCED_DIPLOMACY))
{
CvCity* pOldHeadquarters = GC.getGameINLINE().getHeadquarters((CorporationTypes)trade.m_iData);
pNewHQCity = GET_PLAYER(eToPlayer).getBestHQCity((CorporationTypes)trade.m_iData);
[COLOR="Red"] CvCity* pHQCity = pNewHQCity->getID();[/COLOR]
GC.getGameINLINE().setHeadquarters((CorporationTypes)trade.m_iData, pNewHQCity, true);
GET_PLAYER(eToPlayer).updateCorporation();
GET_PLAYER(eFromPlayer).updateCorporation();
if (pOldHeadquarters != NULL && pHQCity != NULL)
{
pNewHQCity->isActiveCorporation((CorporationTypes)trade.m_iData);
//The old HQ city still has the corporation, just not the HQ.
pOldHeadquarters->setHasCorporation((CorporationTypes)trade.m_iData, true, false, false);
}
for (int i = 0; i < MAX_PLAYERS; i++)
{
if (GET_TEAM(GET_PLAYER((PlayerTypes)i).getTeam()).isHasMet(GET_PLAYER(eToPlayer).getTeam()) || GET_TEAM(GET_PLAYER((PlayerTypes)i).getTeam()).isHasMet(GET_PLAYER(eFromPlayer).getTeam()))
{
szBuffer = gDLL->getText("TXT_KEY_MISC_CORPORATION_TRADE", GC.getCorporationInfo((CorporationTypes)trade.m_iData).getDescription(), GET_PLAYER(eFromPlayer).getCivilizationDescriptionKey(), GET_PLAYER(eToPlayer).getCivilizationDescriptionKey()).GetCString();
gDLL->getInterfaceIFace()->addMessage(((PlayerTypes)i), true, GC.getEVENT_MESSAGE_TIME(), szBuffer, "AS2D_GOLDAGESTART", MESSAGE_TYPE_MAJOR_EVENT, NULL, (ColorTypes)GC.getInfoTypeForString("COLOR_HIGHLIGHT_TEXT"));
}
}
}
break;
And because CvPlayer::getBestHQCity() is a new function , I'll post that too:
Spoiler :
Code:
CvCity* CvPlayer::getBestHQCity(CorporationTypes eCorporation) const
{
CvCity* pCurrentHQ = GC.getGameINLINE().getHeadquarters(eCorporation);
CvCity* pLoopCity;
CvCity* pBestCity;
int iValue;
int iBestValue = 0;
int iLoop;
for (pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))
{
iValue = 0;
if (!pLoopCity->isHasCorporation(eCorporation))
{
if (pLoopCity->isConnectedTo(pCurrentHQ))
{
for (int iCorporation = 0; iCorporation < GC.getNumCorporationInfos(); ++iCorporation)
{
if (pLoopCity->isHeadquarters((CorporationTypes)iCorporation))
{
if (GC.getGameINLINE().isCompetingCorporation((CorporationTypes)iCorporation, eCorporation))
{
continue;
}
iValue -= 25;
}
}
bool bFoundBonus = false;
for (int i = 0; i < GC.getNUM_CORPORATION_PREREQ_BONUSES(); ++i)
{
BonusTypes eBonus = (BonusTypes)GC.getCorporationInfo(eCorporation).getPrereqBonus(i);
if (NO_BONUS != eBonus)
{
if (pLoopCity->hasBonus(eBonus))
{
bFoundBonus = true;
iValue += 50;
}
}
}
if (!bFoundBonus)
{
continue;
}
iValue += 100;
}
}
else
{
iValue = 300;
if (pLoopCity->isConnectedTo(pCurrentHQ))
{
iValue += 100;
}
for (int i = 0; i < GC.getNUM_CORPORATION_PREREQ_BONUSES(); ++i)
{
BonusTypes eBonus = (BonusTypes)GC.getCorporationInfo(eCorporation).getPrereqBonus(i);
if (NO_BONUS != eBonus)
{
if (pLoopCity->hasBonus(eBonus))
{
iValue += 50;
}
}
}
for (int iCorporation = 0; iCorporation < GC.getNumCorporationInfos(); ++iCorporation)
{
if (pLoopCity->isHeadquarters((CorporationTypes)iCorporation))
{
iValue -= 25;
}
}
}
if (iValue > iBestValue)
{
iBestValue = iValue;
pBestCity = pLoopCity;
}
}
return pBestCity;
}