phungus420
Deity
- Joined
- Mar 1, 2003
- Messages
- 6,296
I've been trying to fix an introduced bug caused by the new limited religions game option. Basically founding religions in an advanced start game isn't working correctly, so I wrote a new function to deal with founding religions in the first few turns of a game when a custom game is set to start up after players already have some the techs to found some religions. Debugging it, I'm getting this really odd behavior I do not understand. Here is the full code of the function:
The thing I don't understand is here, I threw in some debugging code so I could see what's going on:
TestVariable is true. WTF? How, I'm telling pb_teamCanFound[eBestTeam] to false, yet it stays true. Why, and how is this possible? It doesn't make any sense to me, what am I missing here?
Spoiler :
Code:
void CvGame::doHolyCityGameStart()
{
int iLoopTeam;
int iLoopReligion;
int iLoopPlayer;
TeamTypes eLoopTeam;
ReligionTypes eLoopReligion;
PlayerTypes eLoopPlayer;
int iLotteryIncrement = MAX_TEAMS * GC.getNumReligionInfos();
bool *pb_ReligionCanFoundNow = new bool[GC.getNumReligionInfos()];
for(iLoopReligion = 0; iLoopReligion < GC.getNumReligionInfos(); ++iLoopReligion)
{
pb_ReligionCanFoundNow[iLoopReligion] = false;
eLoopReligion = ReligionTypes(iLoopReligion);
if(eLoopReligion != NO_RELIGION)
{
CvReligionInfo& kLoopReligion = GC.getReligionInfo(eLoopReligion);
for(iLoopTeam = 0; iLoopTeam < MAX_TEAMS; iLoopTeam++)
{
eLoopTeam = TeamTypes(iLoopTeam);
if(eLoopTeam != NO_TEAM)
{
CvTeam& kLoopTeam = GET_TEAM(eLoopTeam);
if(kLoopTeam.isHasTech(TechTypes(kLoopReligion.getTechPrereq())))
{
if(!(isReligionSlotTaken(eLoopReligion)))
{
pb_ReligionCanFoundNow[eLoopReligion] = true;
break;
}
}
}
}
}
}
bool *pb_teamCanFound = new bool[MAX_TEAMS];
for(iLoopTeam = 0; iLoopTeam < MAX_TEAMS; ++iLoopTeam)
{
bool bValid = false;
eLoopTeam = TeamTypes(iLoopTeam);
if(eLoopTeam != NO_TEAM && eLoopTeam != BARBARIAN_TEAM)
{
CvTeam& kLoopTeam = GET_TEAM(eLoopTeam);
if(kLoopTeam.isAlive())
{
for (iLoopPlayer = 0; iLoopPlayer < MAX_PLAYERS; iLoopPlayer++)
{
eLoopPlayer = PlayerTypes(iLoopPlayer);
if(eLoopPlayer != NO_PLAYER && eLoopPlayer != BARBARIAN_PLAYER)
{
CvPlayer& kLoopPlayer = GET_PLAYER(eLoopPlayer);
if(kLoopPlayer.getTeam() == eLoopTeam && kLoopPlayer.isAlive())
{
FAssert(kLoopPlayer.isPlayable());
if(kLoopPlayer.canFoundReligion())
{
pb_teamCanFound[eLoopTeam] = true;
bValid = true;
break;
}
}
}
}
if(bValid)
{
continue;
}
}
}
pb_teamCanFound[eLoopTeam] = false;
}
int iTeamsLeft = countCivTeamsAlive();
for(iLoopReligion = 0; iLoopReligion < GC.getNumReligionInfos(); ++iLoopReligion)
{
if(iTeamsLeft == 0)
{
break;
}
eLoopReligion = ReligionTypes(iLoopReligion);
int iScore = MAX_INT;
int iTempScore;
TeamTypes eBestTeam = NO_TEAM;
if(eLoopReligion != NO_RELIGION)
{
CvReligionInfo& kLoopReligion = GC.getReligionInfo(eLoopReligion);
if(pb_ReligionCanFoundNow[eLoopReligion])
{
for(iLoopTeam = 0; iLoopTeam < MAX_TEAMS; iLoopTeam++)
{
eLoopTeam = TeamTypes(iLoopTeam);
if(eLoopTeam != NO_TEAM && eLoopTeam != BARBARIAN_TEAM)
{
CvTeam& kLoopTeam = GET_TEAM(eLoopTeam);
if( pb_teamCanFound[eLoopTeam] && kLoopTeam.isHasTech(TechTypes(kLoopReligion.getTechPrereq())) )
{
iTempScore = getSorenRandNum(iLotteryIncrement, "Early Religion Lottery");
for (iLoopPlayer = 0; iLoopPlayer < MAX_PLAYERS; iLoopPlayer++)
{
eLoopPlayer = PlayerTypes(iLoopPlayer);
if(eLoopPlayer != NO_PLAYER)
{
CvPlayer& kLoopPlayer = GET_PLAYER(eLoopPlayer);
if(kLoopPlayer.getTeam() == eLoopTeam)
{
int iILoopReligion;
for(iILoopReligion = 0; iILoopReligion < GC.getNumReligionInfos(); iILoopReligion++)
{
if(kLoopPlayer.hasHolyCity(ReligionTypes(iILoopReligion)))
{
iTempScore += iLotteryIncrement;
}
}
}
}
}
if( pb_teamCanFound[eLoopTeam])
{
bool Stop = true;
}
if(iTempScore < iScore)
{
iScore = iTempScore;
eBestTeam = eLoopTeam;
}
}
}
}
if(eBestTeam != NO_TEAM && eBestTeam != BARBARIAN_TEAM)
{
pb_teamCanFound[eBestTeam] = false;
bool TestVariable;
TestVariable = pb_teamCanFound[eBestTeam];
doHolyCityGameStartPlayer(eBestTeam, eLoopReligion);
iTeamsLeft--;
}
else
{
bool NotGood = true;
}
}
}
}
if(pb_ReligionCanFoundNow)
{
delete [] pb_ReligionCanFoundNow;
}
if(pb_teamCanFound)
{
delete [] pb_teamCanFound;
}
}
The thing I don't understand is here, I threw in some debugging code so I could see what's going on:
Code:
if(eBestTeam != NO_TEAM && eBestTeam != BARBARIAN_TEAM)
{
pb_teamCanFound[eBestTeam] = false;
bool TestVariable;
TestVariable = pb_teamCanFound[eBestTeam];
doHolyCityGameStartPlayer(eBestTeam, eLoopReligion);
iTeamsLeft--;
}
TestVariable is true. WTF? How, I'm telling pb_teamCanFound[eBestTeam] to false, yet it stays true. Why, and how is this possible? It doesn't make any sense to me, what am I missing here?