phungus420
Deity
- Joined
- Mar 1, 2003
- Messages
- 6,296
So in Barbarian Civ (a RevDCM option which causes new civilizations to spawn in barbarian cities) we have a function that gives techs. Now according to jdog it's supposed to only give techs to new world civs based on what the Barbarians know. But he must have coded it wrong, because new world civs are still way too advanced, and a quick check in WB shows that they know alot more techs when they spawn then just what the barbarians know. I need help getting this to work correctly, so that civs that spawn in the newworld do so in a backwards state. Here is the code, it's long so I'll put it in spoilers:
I know I can accomplish what I need in this function alone. I've messed around with it and disabled certain parts and the spawned civs can be as advanced or as backwards as I want. My problem is discriminating against new world spawning civs only. Does anyone know how I can do this? Basically I want to disable the whole function (except for the very beginning portion) for New World civs, but allow the function to run normally for civs that spawn in the old world.
Spoiler :
Code:
def giveTechs( self, newPlayerIdx, closeTeams, bNewWorldMethod = False, bBuilderBonus = 0, militaryStyle = None, bVerbose = True ) :
# Give techs to new player, with variables for extra techs for builders or military style
newPlayer = gc.getPlayer( newPlayerIdx )
newTeam = gc.getTeam(newPlayer.getTeam())
barbTechFrac = self.config.getfloat("BarbarianCiv", "BarbTechFrac", 0.60)
newWorldFrac = self.config.getfloat("BarbarianCiv", "NewWorldReduction", 0.15)
barbTeam = gc.getTeam( gc.getBARBARIAN_TEAM() )
iPartials = 2
for techID in range(0,gc.getNumTechInfos()) :
numTeams = game.countCivTeamsAlive() + 1
numTeamsWhoKnow = game.countKnownTechNumTeams(techID)
fracKnow = numTeamsWhoKnow/(1.0*numTeams)
if( bNewWorldMethod and self.iNewWorldPolicy > 0 ) :
iNewWorldEra = gc.getPlayer(gc.getBARBARIAN_PLAYER()).getCurrentEra()
iMaxEra = 0
for i in range(0,gc.getMAX_CIV_PLAYERS()):
iMaxEra = max([iMaxEra,gc.getPlayer(i).getCurrentEra()])
if( gc.getPlayer(i).getTeam() in closeTeams ) :
iNewWorldEra = max([iNewWorldEra,gc.getPlayer(i).getCurrentEra()])
iTechEra = gc.getTechInfo(techID).getEra()
iGiveEra = min( [iNewWorldEra, iMaxEra - max([0,self.config.getint("BarbarianCiv", "NewWorldErasBehind", 1)])] )
iGiveEra = max([0,iGiveEra])
if( iTechEra < iGiveEra ) :
if( not newTeam.isHasTech(techID) ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - NewWorld: Giving %s by era"%(PyInfo.TechnologyInfo(techID).getDescription()))
newTeam.setHasTech(techID,True,newPlayerIdx,False,False)
elif( iTechEra == iGiveEra ) :
if( fracKnow >= min([barbTechFrac+newWorldFrac,0.99]) and newPlayer.canEverResearch(techID) ) :
if( not newTeam.isHasTech(techID) ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - NewWorld: Giving %s %f no loc"%(PyInfo.TechnologyInfo(techID).getDescription(),fracKnow))
newTeam.setHasTech(techID,True,newPlayerIdx,False,False)
iPartials -= 1
else :
if( barbTeam.isHasTech(techID) and not newTeam.isHasTech(techID) ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving %s from barb"%(PyInfo.TechnologyInfo(techID).getDescription()))
newTeam.setHasTech(techID,True,newPlayerIdx,False,False)
continue
if( len(closeTeams) > 0 ) :
localNumTeamsWhoKnow = 0
for idx in closeTeams :
teamI = gc.getTeam(idx)
if( teamI.isHasTech(techID) ) :
localNumTeamsWhoKnow += 1
modFracKnow = fracKnow/2.0 + localNumTeamsWhoKnow/(2.0*(len(closeTeams) + .5))
else :
modFracKnow = fracKnow
if( modFracKnow >= barbTechFrac and newPlayer.canEverResearch(techID) ) :
if( not newTeam.isHasTech(techID) ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving %s %f with %f loc"%(PyInfo.TechnologyInfo(techID).getDescription(),fracKnow,modFracKnow))
newTeam.setHasTech(techID,True,newPlayerIdx,False,False)
if( not militaryStyle == None ) :
iPartials += 2
iHorseback = CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),RevDefs.sXMLHorseback)
iSailing = CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),RevDefs.sXMLSailing)
iWheel = CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),RevDefs.sXMLWheel)
iHusbandry = CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),RevDefs.sXMLAnimal)
iBronze = CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),RevDefs.sXMLBronze)
iIron = CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),RevDefs.sXMLIron)
iGuilds = CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),RevDefs.sXMLGuilds)
if( militaryStyle == 'viking' ) :
if( not newTeam.isHasTech(iSailing) ) :
newTeam.setHasTech(iSailing,True,newPlayerIdx,False,False)
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving military %s"%(PyInfo.TechnologyInfo(iSailing).getDescription()))
iPartials -= 1
if( not newTeam.isHasTech(iBronze) ) :
newTeam.setHasTech(iBronze,True,newPlayerIdx,False,False)
if( self.LOG_DEBUG ) : CvUtil.pyPrint(" BC - Giving military %s"%(PyInfo.TechnologyInfo(iBronze).getDescription()))
iPartials -= 1
else :
if( not newTeam.isHasTech(iIron) ) :
newTeam.setHasTech(iIron,True,newPlayerIdx,False,False)
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving military %s"%(PyInfo.TechnologyInfo(iIron).getDescription()))
iPartials -= 1
elif( militaryStyle == 'chariot' ) :
if( not newTeam.isHasTech(iWheel) ) :
newTeam.setHasTech(iWheel,True,newPlayerIdx,False,False)
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving military %s"%(PyInfo.TechnologyInfo(iWheel).getDescription()))
iPartials -= 1
if( not newTeam.isHasTech(iHusbandry) ) :
newTeam.setHasTech(iHusbandry,True,newPlayerIdx,False,False)
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving military %s"%(PyInfo.TechnologyInfo(iHusbandry).getDescription()))
iPartials -= 1
if( not newTeam.isHasTech(iBronze) ) :
newTeam.setHasTech(iBronze,True,newPlayerIdx,False,False)
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving military %s"%(PyInfo.TechnologyInfo(iBronze).getDescription()))
iPartials -= 1
else :
if( not newTeam.isHasTech(iIron) ) :
newTeam.setHasTech(iIron,True,newPlayerIdx,False,False)
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving military %s"%(PyInfo.TechnologyInfo(iIron).getDescription()))
iPartials -= 1
elif( militaryStyle == 'horse' ) :
if( not newTeam.isHasTech(iHorseback) ) :
newTeam.setHasTech(iHorseback,True,newPlayerIdx,False,False)
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving military %s"%(PyInfo.TechnologyInfo(iHorseback).getDescription()))
iPartials -= 1
else :
if( game.countKnownTechNumTeams(iGuilds) > 1 ) :
if( not newTeam.isHasTech(iGuilds) ) :
newTeam.setHasTech(iGuilds,True,newPlayerIdx,False,False)
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving military %s"%(PyInfo.TechnologyInfo(iGuilds).getDescription()))
iPartials -= 1
else : #( militaryStyle == 'balance' ) :
if( not newTeam.isHasTech(iBronze) ) :
newTeam.setHasTech(iBronze,True,newPlayerIdx,False,False)
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving military %s"%(PyInfo.TechnologyInfo(iBronze).getDescription()))
iPartials -= 1
elif( not newTeam.isHasTech(iIron) ) :
newTeam.setHasTech(iIron,True,newPlayerIdx,False,False)
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving military %s"%(PyInfo.TechnologyInfo(iIron).getDescription()))
iPartials -= 1
elif( not newTeam.isHasTech(iHorseback) ) :
newTeam.setHasTech(iHorseback,True,newPlayerIdx,False,False)
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving military %s"%(PyInfo.TechnologyInfo(iHorseback).getDescription()))
iPartials -= 1
else :
if( game.countKnownTechNumTeams(iGuilds) > 0 ) :
if( not newTeam.isHasTech(iGuilds) ) :
newTeam.setHasTech(iGuilds,True,newPlayerIdx,False,False)
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving military %s"%(PyInfo.TechnologyInfo(iGuilds).getDescription()))
iPartials -= 1
elif( bBuilderBonus > 0 ) :
# Extra techs
maxCount = self.config.getint("BarbarianCiv", "BuilderBonusTechs", 3)
iPartials += 3
if( bNewWorldMethod and self.iNewWorldPolicy > 0 ) :
maxCount -= 1
newTechList = list()
for techID in range(0,gc.getNumTechInfos()) :
if( not newTeam.isHasTech(techID) and newPlayer.canResearch(techID,True) ) :
newTechList.append(techID)
for k in range(0,maxCount) :
if( len(newTechList) > 0 ) :
techID = newTechList.pop(game.getSorenRandNum(len(newTechList),'BC: Builder tech'))
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving builder %s"%(PyInfo.TechnologyInfo(techID).getDescription()))
newTeam.setHasTech(techID,True,newPlayerIdx,False,False)
iPass = 0
while (iPartials > 0 and iPass < 4) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving %d partial techs, pass %d"%(iPartials,iPass))
for techID in range(0,gc.getNumTechInfos()) :
tech = gc.getTechInfo( techID )
iTechPower = tech.getPowerValue()
iTechEra = tech.getEra()
if( not newTeam.isHasTech(techID) and iTechEra <= newPlayer.getCurrentEra() + 1 and tech.getEra() < gc.getNumEraInfos() ) :
iTechCost = newTeam.getResearchCost(techID)
iResearchProgress = newTeam.getResearchProgress(techID)
iThreshold = iTechCost/2
if( bBuilderBonus ) : iThreshold += iTechCost/5
if( iResearchProgress < iThreshold ) :
anyAndFalse = False
for k in range(gc.getDefineINT("NUM_AND_TECH_PREREQS")):
iPrereqTech = tech.getPrereqAndTechs( k )
if( iPrereqTech > 0 and iPrereqTech < gc.getNumTechInfos() ) :
if( not newTeam.isHasTech( iPrereqTech ) ) :
anyAndFalse = True
break
allOrFalse = -1
for k in range(gc.getDefineINT("NUM_OR_TECH_PREREQS")):
iPrereqTech = tech.getPrereqOrTechs( k )
if( iPrereqTech > 0 and iPrereqTech < gc.getNumTechInfos() ) :
allOrFalse = 1
if( newTeam.isHasTech( iPrereqTech ) ) :
allOrFalse = 0
break
if( not anyAndFalse and allOrFalse <= 0 ) :
numTeams = game.countCivTeamsAlive() + 1
numTeamsWhoKnow = game.countKnownTechNumTeams(techID)
fracKnow = numTeamsWhoKnow/(1.0*numTeams)
fTechFrac = .35 + fracKnow/2.0 + game.getSorenRandNum(10 + 7*iPartials,"BarbCiv - give partial tech")/100.0
iNewProgress = int(iResearchProgress + fTechFrac * iTechCost)
iNewProgress = min([iNewProgress, (85*iTechCost)/100])
iBase = (40*gc.getGameSpeedInfo(game.getGameSpeedType()).getResearchPercent())/100
iRand = iTechCost + 4*iBase
if( bBuilderBonus ) :
iRand += max([0, iBase*(iTechPower - iPartials)])
elif( not militaryStyle == None ) :
iRand += 4*iBase - iBase*iTechPower
else :
iRand += 8*iBase + iBase*iTechPower
if( iNewProgress > game.getSorenRandNum( iRand, "BarbCiv - give partial tech") ) :
if( self.LOG_DEBUG and bVerbose ) : CvUtil.pyPrint(" BC - Giving partial %s: %2.1f perc (power %d)"%(tech.getDescription(),(100.0*iNewProgress)/iTechCost,iTechPower))
newTeam.setResearchProgress( techID, iNewProgress, newPlayer.getID() )
iPartials -= 1
if( iPartials <= 0 ) :
break
iPass += 1
I know I can accomplish what I need in this function alone. I've messed around with it and disabled certain parts and the spawned civs can be as advanced or as backwards as I want. My problem is discriminating against new world spawning civs only. Does anyone know how I can do this? Basically I want to disable the whole function (except for the very beginning portion) for New World civs, but allow the function to run normally for civs that spawn in the old world.