if (pLoopPlot->getBonusType(pCity->getTeam()) == GC.getUnitInfo(eUnit).getPrereqVicinityBonus())
BonusTypes CvPlot::getBonusType(TeamTypes eTeam) const
{
if (eTeam != NO_TEAM)
{
if (m_eBonusType != NO_BONUS)
{
if (!GET_TEAM(eTeam).isHasTech((TechTypes)(GC.getBonusInfo((BonusTypes)m_eBonusType).getTechReveal())) && !GET_TEAM(eTeam).isForceRevealedBonus((BonusTypes)m_eBonusType))
{
return NO_BONUS;
}
}
}
return (BonusTypes)m_eBonusType;
}
<AppearanceTechs>
<AppearanceTech>
<AppearanceTechType>TECH_MINING</AppearanceTechType>
<iAppearanceTech>50</iAppearanceTech>
</AppearanceTech>
</AppearanceTechs>
int iAppearance = (GC.getUnitInfo(eLoopUnit).getAppearanceProb());
for (int iI = 0; iI < GC.getNumTechInfos(); iI++)
{
if (GC.getUnitInfo(eLoopUnit).getAppearanceTechs(iI))
{
int iTech = iI;
if (iTech != 0)
{
for (int iJ = 0; iJ < MAX_TEAMS; iJ++)
{
if (GET_TEAM((TeamTypes)iJ).isEverAlive())
{
if (GET_TEAM((TeamTypes)iJ).isHasTech((TechTypes)iTech))
{
iAppearance += (GC.getUnitInfo(eLoopUnit).getAppearanceTechs(iTech));
}
}
}
}
}
}
if (iAppearance > -1)
{
iValue = (1 + GC.getUnitInfo(eLoopUnit).getAppearanceProb() + getSorenRandNum(100, "Animal Unit Selection"));
if (iValue > iBestValue)
{
eBestUnit = eLoopUnit;
iBestValue = iValue;
}
}
int iAppearance = (GC.getUnitInfo(eLoopUnit).getAppearanceProb());
for (int iI = 0; iI < GC.getNumTechInfos(); iI++)
{
for (int iJ = 0; iJ < MAX_TEAMS; iJ++)
{
if (GET_TEAM((TeamTypes)iJ).isEverAlive())
{
if (GET_TEAM((TeamTypes)iJ).isHasTech((TechTypes)iI))
{
iAppearance += (GC.getUnitInfo(eLoopUnit).getAppearanceTechs(iI));
}
}
}
}
if (iAppearance > -1)
{
iValue = (1 + iAppearance + getSorenRandNum(100, "Animal Unit Selection"));
if (iValue > iBestValue)
{
eBestUnit = eLoopUnit;
iBestValue = iValue;
}
}
iValue = (1 + GC.getUnitInfo(eLoopUnit).getAppearanceProb() + getSorenRandNum(100, "Animal Unit Selection"));
iValue = (1 + iAppearance + getSorenRandNum(100, "Animal Unit Selection"));
int iAppearance = (GC.getUnitInfo(eLoopUnit).getAppearanceProb());
for (int iI = 0; iI < GC.getNumTechInfos(); iI++)
{
iAppearance += (GC.getUnitInfo(eLoopUnit).getAppearanceTechs(iI)) * countKnownTechNumTeams((TechTypes)iI);
}
if (iAppearance > -1)
{
iValue = getSorenRandNum(iAppearance, "Animal Unit Selection");
if (iValue > iBestValue)
{
eBestUnit = eLoopUnit;
iBestValue = iValue;
}
}
Will transfer gold between Unit owner and City Owner each turn, or simply add/remove gold from the treasury if Owners are the same
<CityBonus>
<bApplyRival>1</bApplyRival>
<fGold>-5</fGold>
<fDiplo>-.05</fDiplo>
</CityBonus>
For the XML loading, I forgot that what I am talking about is set up as a general structure for you in XMLLoadUtility, so just use SetVariableListTagPair and you'll be set. No need for a complicated load method.
The problem with your code is that you are only using the tech values to see if the unit is ALLOWED to spawn, you then return to the value in UnitInfos and ONLY that value to decide which of the legal units should spawn. Use something like this instead:
Code:int iAppearance = (GC.getUnitInfo(eLoopUnit).getAppearanceProb()); for (int iI = 0; iI < GC.getNumTechInfos(); iI++) { iAppearance += (GC.getUnitInfo(eLoopUnit).getAppearanceTechs(iI)) * countKnownTechNumTeams((TechTypes)iI); } if (iAppearance > -1) { iValue = getSorenRandNum(iAppearance, "Animal Unit Selection"); if (iValue > iBestValue) { eBestUnit = eLoopUnit; iBestValue = iValue; } }
As for your edit, you WANT to use a random number still, as this is the PROBABILITY, and without a random, you will ONLY spawn the highest value unit which is allowed in the tile, ever.
Also notice that I removed a loop in the beginning, but only technically. The loop still is performed in the function now being called, but it makes this segment easier to read.
iValue = getSorenRandNum(iAppearance, "Animal Unit Selection");
Valk: Yes, this version gives you a random number from 0 up to the maximum appearance value. This way, ANY unit with a valid appearance value can show up. Your way, the only way you will have a chance between two units is if their appearance values are within 100 of each other. Now, you might WANT to shut off weaker animals without directly adjusting their appearance values based on the presence of a superior animal, but I think it is nice to continue to have the occasional wolf show up, even when the entire world knows iron working.