## Sid Meier's Civilization 4 ## Copyright Firaxis Games 2005 ## ## CvEventManager ## This class is passed an argsList from CvAppInterface.onEvent ## The argsList can contain anything from mouse location to key info ## The EVENTLIST that are being notified can be found from CvPythonExtensions import * import CvUtil import CvScreensInterface import CvDebugTools import CvWBPopups import PyHelpers import Popup as PyPopup import CvCameraControls import CvTopCivs import sys import CvWorldBuilderScreen import CvAdvisorUtils import CvTechChooser import CvEventManager import pickle # import SdReligion import SdCultureConquest gc = CyGlobalContext() localText = CyTranslator() PyPlayer = PyHelpers.PyPlayer PyInfo = PyHelpers.PyInfo ################ UTILITY FUNCTIONS ################## def SdEcho(argsList): printToScr = True printToLog = True message = "%s" %(argsList) if (printToScr): CyInterface().addImmediateMessage(message,"") if (printToLog): CvUtil.pyPrint(message) return 0 ##################################################### class SdEventManager(CvEventManager.CvEventManager): def __init__(self): # initialize base class self.parent = CvEventManager.CvEventManager self.parent.__init__(self) self.SdReligion = SdReligion.SdReligion() self.SdCultureConquest = SdCultureConquest.SdCultureConquest() #################### ON EVENTS ###################### def onReligionFounded(self, argsList): # self.SdReligion.DistributeReligionTechs(argsList) self.parent.onReligionFounded(self, argsList) def onReligionSpread(self, argsList): # self.SdReligion.HolyCityCheck(argsList) self.parent.onReligionSpread(self, argsList) def onBuildingBuilt(self, argsList): # self.BuildInquisition(argsList) self.parent.onBuildingBuilt(self, argsList) def onCityAcquired(self, argsList): self.SdCultureConquest.CultureConquestCapture(argsList) # self.TechConquest(argsList) self.parent.onCityAcquired(self, argsList) def onEndGameTurn(self, argsList): self.SdCultureConquest.CultureConquestEndGameTurn() self.CultureDecay() self.parent.onEndGameTurn(self, argsList) #################### 3RD PARTY ###################### # Inquisition def BuildInquisition(self, argsList): 'Inquisition Completed' pCity, iBuildingType = argsList Inquisition = gc.getInfoTypeForString('BUILDINGCLASS_INQUISITION') if iBuildingType == Inquisition: szReligionList = [ ] StateBelief = gc.getPlayer(pCity.getOwner()).getStateReligion() for i in range(gc.getNumReligionInfos()): if (not StateBelief == i and pCity.isHasReligion(i) and not pCity.isHolyCityByType(i)): szReligionList.append(i) if len(szReligionList) != 0: iTarget = szReligionList[CyRandom().get(len(szReligionList), "Get a random number for religion removal.")] pCity.setHasReligion(iTarget, False, True, True) pCity.setHasRealBuilding(Inquisition, False) popup = PyPopup.PyPopup() popup.setBodyString( 'Inquisition Strikes again!' ) popup.launch() # Inquisition # TechConquest def TechConquest(self, argsList): 'City Acquired - Tech Capture' owner,playerType,city,bConquest,bTrade = argsList if bConquest: dice = gc.getGame().getMapRand() loserTeam = gc.getTeam(owner) conqTeam = gc.getTeam(city.getOwner()) listTechDiff = [] tradeData = TradeData() tradeData.ItemType = TradeableItems.TRADE_TECHNOLOGIES for iLoopTech in range(gc.getNumTechInfos()): tradeData.iData = iLoopTech if (loserTeam.isHasTech(iLoopTech) == True) and (conqTeam.isHasTech(iLoopTech) == False): listTechDiff.append(iLoopTech) if len(listTechDiff) > 0: randTech = dice.get(len(listTechDiff), "Tech Chooser - TechConquest PYTHON") techData = gc.getTechInfo(listTechDiff[randTech]) techCost = techData.getResearchCost() baseMultiplier = city.getPopulation() / 4 baseTechPointsAdded = (techCost / 20) * baseMultiplier extraTechPointsAdded = dice.get((techCost / 10) * baseMultiplier, "Tech Chooser - TechConquest PYTHON") totalTechPointsAdded = baseTechPointsAdded + extraTechPointsAdded currentTechPoints = conqTeam.getResearchProgress(listTechDiff[randTech]) if (totalTechPointsAdded > (techCost - currentTechPoints)): totalTechPoints = techCost else: totalTechPoints = currentTechPoints + totalTechPointsAdded conqTeam.changeResearchProgress(listTechDiff[randTech], totalTechPoints, city.getOwner()) if city.getOwner().isHuman(): popup = PyPopup.PyPopup() popup.setBodyString("From the inhabitants of %s, you learn some of the secrets of %s" %(city.getName(), techData.getDescription())) popup.launch() SdEcho('%s captured by %s. %d tech points awarded towards %s.' %(city.getName(), gc.getPlayer(city.getOwner()).getCivilizationDescription(0), totalTechPointsAdded, techData.getDescription())) else: SdEcho('%s captured by %s. No unknown techs found.' %(city.getName(), gc.getPlayer(city.getOwner()).getCivilizationDescription(0))) # TechConquest # Culture Decay def getMaxCulture3x3(self, iXOrig, iYOrig, pMap, iPlayer): iRetCulture = 0 for iX in range(3): for iY in range(3): iXPt = iXOrig + iX - 1 iYPt = iYOrig + iY - 1 if (iXPt < 0) or (iXPt >= pMap.getGridWidth()): continue if (iYPt < 0) or (iYPt >= pMap.getGridHeight()): continue if (iXPt == iXOrig) and (iYPt == iYOrig): continue iLclCulture = pMap.plot(iXPt, iYPt).getCulture(iPlayer) if (iLclCulture > iRetCulture): iRetCulture = iLclCulture return iRetCulture def CultureDecay(self): pMap = CyMap() for iX in range(pMap.getGridWidth()): for iY in range(pMap.getGridHeight()): pPlot = pMap.plot(iX, iY) if (pPlot.countTotalCulture() > 0): for iLoop in range(gc.getMAX_PLAYERS()): pPlayer = gc.getPlayer(iLoop) if (pPlayer.isAlive()) or (pPlayer.isBarbarian()): iCulture = pPlot.getCulture(iLoop) iNumCultureCities = pPlot.getNumCultureRangeCities(iLoop) if (iCulture > 0) and (iNumCultureCities == 0): iCultureDecay = (int)(iCulture * 0.05) if (iCultureDecay < 1): iCultureDecay = 1 pPlot.changeCulture(iLoop, -iCultureDecay) elif (iNumCultureCities == 1) and (pPlot.isCity() == false): iMaxCulture = self.getMaxCulture3x3(iX, iY, pMap, iLoop) if (iCulture > iMaxCulture): iCultureDecay = (int)(iCulture * 0.05) if (iCultureDecay < 1): iCultureDecay = 1 if ((iCulture - iCultureDecay) < iMaxCulture): iCultureDecay = iCulture - iMaxCulture pPlot.changeCulture(iLoop, -iCultureDecay) # Culture Decay #################### TRIGGERED EVENTS ##################