I'd like to report two Python bugs; one bug is in RFCUtils.py on line 987 as of commit ac3fb91c on branch riseandfall, and one is in History.py on line 614 as of commit 468f8886 also on branch riseandfall (History.py on line 635 as of latest commit ac3fb91c as of this post).
The first bug, which is the function
flipOrRelocateGarrison, I could sort of fix by catching the thrown exception from the function. I have reproduced the original code below:
Code:
def flipOrRelocateGarrison(city, iNumDefenders):
lRelocatedUnits = []
lFlippedUnits = []
for plot in plots.surrounding(city, radius=2).where(lambda p: not p.isCity() or location(p) == location(city)):
for unit in units.at(plot).owner(city.getOwner()).domain(DomainTypes.DOMAIN_LAND):
if unit.canFight() and len(lFlippedUnits) < iNumDefenders:
lFlippedUnits.append(unit)
else:
lRelocatedUnits.append(unit)
return lFlippedUnits, lRelocatedUnits
By wrapping the for loop with a try and except, I was able to avoid the Python exception (it was something about city being None, which I could not figure out. The original bug occurred one turn before a very large AI-controlled Roman Empire collapsed, but I forgot to save a copy of the save file as I had sort of fixed the bug as described below:
Code:
def flipOrRelocateGarrison(city, iNumDefenders):
lRelocatedUnits = []
lFlippedUnits = []
try:
for plot in plots.surrounding(city, radius=2).where(lambda p: not p.isCity() or location(p) == location(city)):
for unit in units.at(plot).owner(city.getOwner()).domain(DomainTypes.DOMAIN_LAND):
if unit.canFight() and len(lFlippedUnits) < iNumDefenders:
lFlippedUnits.append(unit)
else:
lRelocatedUnits.append(unit)
except TypeError:
return lFlippedUnits, lRelocatedUnits
return lFlippedUnits, lRelocatedUnits
The second bug, which is in the function
handleColonialAcquisition, seems to be attempting to access the None variable
dColonialAcquisitionCities, which is causing the array access to fail. I checked where the other defines are set (following the name pattern such as
dRespawnCapitals,
dBirthArea, etc.) and found that there was no variable definition for
dColonialAcquisitionCities either in this file or anywhere in the copy of RFC DoC that I had downloaded. Only three results occur for this variable, all of which are in History.py in the functions
acceptColonialAcquisition,
refuseColonialAcquisition, and
handleColonialAcquisition. I have reproduced a reduced version of the original code here for your convenience:
Code:
def handleColonialAcquisition(iPlayer):
pPlayer = player(iPlayer)
iCiv = civ(iPlayer)
...
for iTarget in targetPlayers:
if player(iTarget).isHuman():
askedCities = cityPlots.cities().owner(iTarget)
askedCityNames = askedCities.format(formatter=CyCity.getName)
iAskGold = askedCities.count() * 200
data.dColonialAcquisitionCities[iPlayer] = askedCities
...
...
pPlayer.setGold(max(0, iNewGold))