Advertisement
Guest User

Untitled

a guest
Sep 29th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 171.26 KB | None | 0 0
  1. # Sid Meier's Civilization 4
  2. # Copyright Firaxis Games 2006
  3. #
  4. # CvEventManager
  5. # This class is passed an argsList from CvAppInterface.onEvent
  6. # The argsList can contain anything from mouse location to key info
  7. # The EVENTLIST that are being notified can be found
  8.  
  9. from CvPythonExtensions import *
  10. import CvUtil
  11. import CvScreensInterface
  12. import CvDebugTools
  13. #import CvWBPopups
  14. import PyHelpers
  15. import Popup as PyPopup
  16. import CvCameraControls
  17. import CvTopCivs
  18. import sys
  19. #import CvWorldBuilderScreen
  20. import CvAdvisorUtils
  21. import CvTechChooser
  22.  
  23. import CvIntroMovieScreen
  24. import CustomFunctions
  25. import ScenarioFunctions
  26.  
  27. #FfH: Card Game: begin
  28. import CvSomniumInterface
  29. import CvCorporationScreen
  30. #FfH: Card Game: end
  31.  
  32. #FfH: Added by Kael 10/15/2008 for OOS Logging
  33. import OOSLogger
  34. #FfH: End Add
  35.  
  36. ## Ultrapack ##
  37. import WBCityEditScreen
  38. import WBUnitScreen
  39. import WBPlayerScreen
  40. import WBGameDataScreen
  41. import WBPlotScreen
  42. import CvPlatyBuilderScreen
  43. ## Ultrapack ##
  44.  
  45. #My pickle for the x and y values when moving the Stack of Doom#
  46. import pickle
  47. #My BugData for storing the x and y values when moving the SoD#
  48. import BugData
  49.  
  50. # globals
  51. cf = CustomFunctions.CustomFunctions()
  52. gc = CyGlobalContext()
  53. localText = CyTranslator()
  54. PyPlayer = PyHelpers.PyPlayer
  55. PyInfo = PyHelpers.PyInfo
  56. sf = ScenarioFunctions.ScenarioFunctions()
  57. game = gc.getGame()
  58.  
  59. #FfH: Card Game: begin
  60. cs = CvCorporationScreen.cs
  61. #FfH: Card Game: end
  62.  
  63.  
  64. # globals
  65. ###################################################
  66. class CvEventManager:
  67.     def __init__(self):
  68.         #################### ON EVENT MAP ######################
  69.         #print "EVENTMANAGER INIT"
  70.  
  71.         self.bCtrl = False
  72.         self.bShift = False
  73.         self.bAlt = False
  74.         self.bAllowCheats = False
  75.  
  76.         # OnEvent Enums
  77.         self.EventLButtonDown=1
  78.         self.EventLcButtonDblClick=2
  79.         self.EventRButtonDown=3
  80.         self.EventBack=4
  81.         self.EventForward=5
  82.         self.EventKeyDown=6
  83.         self.EventKeyUp=7
  84.  
  85.         self.__LOG_MOVEMENT = 0
  86.         self.__LOG_BUILDING = 0
  87.         self.__LOG_COMBAT = 0
  88.         self.__LOG_CONTACT = 0
  89.         self.__LOG_IMPROVEMENT =0
  90.         self.__LOG_CITYLOST = 0
  91.         self.__LOG_CITYBUILDING = 0
  92.         self.__LOG_TECH = 0
  93.         self.__LOG_UNITBUILD = 0
  94.         self.__LOG_UNITKILLED = 1
  95.         self.__LOG_UNITLOST = 0
  96.         self.__LOG_UNITPROMOTED = 0
  97.         self.__LOG_UNITSELECTED = 0
  98.         self.__LOG_UNITPILLAGE = 0
  99.         self.__LOG_GOODYRECEIVED = 0
  100.         self.__LOG_GREATPERSON = 0
  101.         self.__LOG_RELIGION = 0
  102.         self.__LOG_RELIGIONSPREAD = 0
  103.         self.__LOG_GOLDENAGE = 0
  104.         self.__LOG_ENDGOLDENAGE = 0
  105.         self.__LOG_WARPEACE = 0
  106.         self.__LOG_PUSH_MISSION = 0
  107.  
  108.         ## EVENTLIST
  109.         self.EventHandlerMap = {
  110.             'mouseEvent'            : CvEventManager.onMouseEvent.__get__(self,CvEventManager),
  111.             'kbdEvent'              : CvEventManager.onKbdEvent.__get__(self,CvEventManager),
  112.             'ModNetMessage'                 : CvEventManager.onModNetMessage.__get__(self,CvEventManager),
  113.             'Init'                  : CvEventManager.onInit.__get__(self,CvEventManager),
  114.             'Update'                : CvEventManager.onUpdate.__get__(self,CvEventManager),
  115.             'UnInit'                : CvEventManager.onUnInit.__get__(self,CvEventManager),
  116.             'OnSave'                : CvEventManager.onSaveGame.__get__(self,CvEventManager),
  117.             'OnPreSave'             : CvEventManager.onPreSave.__get__(self,CvEventManager),
  118.             'OnLoad'                : CvEventManager.onLoadGame.__get__(self,CvEventManager),
  119.             'GameStart'             : CvEventManager.onGameStart.__get__(self,CvEventManager),
  120.             'GameEnd'               : CvEventManager.onGameEnd.__get__(self,CvEventManager),
  121.             'plotRevealed'          : CvEventManager.onPlotRevealed.__get__(self,CvEventManager),
  122.             'plotFeatureRemoved'    : CvEventManager.onPlotFeatureRemoved.__get__(self,CvEventManager),
  123.             'plotPicked'            : CvEventManager.onPlotPicked.__get__(self,CvEventManager),
  124.             'nukeExplosion'         : CvEventManager.onNukeExplosion.__get__(self,CvEventManager),
  125.             'gotoPlotSet'           : CvEventManager.onGotoPlotSet.__get__(self,CvEventManager),
  126.             'BeginGameTurn'         : CvEventManager.onBeginGameTurn.__get__(self,CvEventManager),
  127.             'EndGameTurn'           : CvEventManager.onEndGameTurn.__get__(self,CvEventManager),
  128.             'BeginPlayerTurn'       : CvEventManager.onBeginPlayerTurn.__get__(self,CvEventManager),
  129.             'EndPlayerTurn'         : CvEventManager.onEndPlayerTurn.__get__(self,CvEventManager),
  130.             'endTurnReady'          : CvEventManager.onEndTurnReady.__get__(self,CvEventManager),
  131.             'combatResult'          : CvEventManager.onCombatResult.__get__(self,CvEventManager),
  132.             'combatLogCalc'         : CvEventManager.onCombatLogCalc.__get__(self,CvEventManager),
  133.             'combatLogHit'          : CvEventManager.onCombatLogHit.__get__(self,CvEventManager),
  134.             'improvementBuilt'      : CvEventManager.onImprovementBuilt.__get__(self,CvEventManager),
  135.             'improvementDestroyed'  : CvEventManager.onImprovementDestroyed.__get__(self,CvEventManager),
  136.             'routeBuilt'            : CvEventManager.onRouteBuilt.__get__(self,CvEventManager),
  137.             'firstContact'          : CvEventManager.onFirstContact.__get__(self,CvEventManager),
  138.             'cityBuilt'             : CvEventManager.onCityBuilt.__get__(self,CvEventManager),
  139.             'cityRazed'             : CvEventManager.onCityRazed.__get__(self,CvEventManager),
  140.             'cityAcquired'          : CvEventManager.onCityAcquired.__get__(self,CvEventManager),
  141.             'cityAcquiredAndKept'   : CvEventManager.onCityAcquiredAndKept.__get__(self,CvEventManager),
  142.             'cityLost'              : CvEventManager.onCityLost.__get__(self,CvEventManager),
  143.             'cultureExpansion'      : CvEventManager.onCultureExpansion.__get__(self,CvEventManager),
  144.             'cityGrowth'            : CvEventManager.onCityGrowth.__get__(self,CvEventManager),
  145.             'cityDoTurn'            : CvEventManager.onCityDoTurn.__get__(self,CvEventManager),
  146.             'cityBuildingUnit'  : CvEventManager.onCityBuildingUnit.__get__(self,CvEventManager),
  147.             'cityBuildingBuilding'  : CvEventManager.onCityBuildingBuilding.__get__(self,CvEventManager),
  148.             'cityRename'                : CvEventManager.onCityRename.__get__(self,CvEventManager),
  149.             'cityHurry'             : CvEventManager.onCityHurry.__get__(self,CvEventManager),
  150.             'selectionGroupPushMission'     : CvEventManager.onSelectionGroupPushMission.__get__(self,CvEventManager),
  151.             'unitMove'              : CvEventManager.onUnitMove.__get__(self,CvEventManager),
  152.             'unitSetXY'             : CvEventManager.onUnitSetXY.__get__(self,CvEventManager),
  153.             'unitCreated'           : CvEventManager.onUnitCreated.__get__(self,CvEventManager),
  154.             'unitBuilt'             : CvEventManager.onUnitBuilt.__get__(self,CvEventManager),
  155.             'unitKilled'            : CvEventManager.onUnitKilled.__get__(self,CvEventManager),
  156.             'unitLost'              : CvEventManager.onUnitLost.__get__(self,CvEventManager),
  157.             'unitPromoted'          : CvEventManager.onUnitPromoted.__get__(self,CvEventManager),
  158.             'unitSelected'          : CvEventManager.onUnitSelected.__get__(self,CvEventManager),
  159.             'UnitRename'                : CvEventManager.onUnitRename.__get__(self,CvEventManager),
  160.             'unitPillage'               : CvEventManager.onUnitPillage.__get__(self,CvEventManager),
  161.             'unitSpreadReligionAttempt' : CvEventManager.onUnitSpreadReligionAttempt.__get__(self,CvEventManager),
  162.             'unitGifted'                : CvEventManager.onUnitGifted.__get__(self,CvEventManager),
  163.             'unitBuildImprovement'              : CvEventManager.onUnitBuildImprovement.__get__(self,CvEventManager),
  164.             'goodyReceived'         : CvEventManager.onGoodyReceived.__get__(self,CvEventManager),
  165.             'greatPersonBorn'       : CvEventManager.onGreatPersonBorn.__get__(self,CvEventManager),
  166.             'buildingBuilt'         : CvEventManager.onBuildingBuilt.__get__(self,CvEventManager),
  167.             'projectBuilt'          : CvEventManager.onProjectBuilt.__get__(self,CvEventManager),
  168.             'techAcquired'          : CvEventManager.onTechAcquired.__get__(self,CvEventManager),
  169.             'techSelected'          : CvEventManager.onTechSelected.__get__(self,CvEventManager),
  170.             'religionFounded'       : CvEventManager.onReligionFounded.__get__(self,CvEventManager),
  171.             'religionSpread'        : CvEventManager.onReligionSpread.__get__(self,CvEventManager),
  172.             'religionRemove'        : CvEventManager.onReligionRemove.__get__(self,CvEventManager),
  173.             'corporationFounded'    : CvEventManager.onCorporationFounded.__get__(self,CvEventManager),
  174.             'corporationSpread'     : CvEventManager.onCorporationSpread.__get__(self,CvEventManager),
  175.             'corporationRemove'     : CvEventManager.onCorporationRemove.__get__(self,CvEventManager),
  176.             'goldenAge'             : CvEventManager.onGoldenAge.__get__(self,CvEventManager),
  177.             'endGoldenAge'          : CvEventManager.onEndGoldenAge.__get__(self,CvEventManager),
  178.             'chat'                  : CvEventManager.onChat.__get__(self,CvEventManager),
  179.             'victory'               : CvEventManager.onVictory.__get__(self,CvEventManager),
  180.             'vassalState'           : CvEventManager.onVassalState.__get__(self,CvEventManager),
  181.             'changeWar'             : CvEventManager.onChangeWar.__get__(self,CvEventManager),
  182.             'setPlayerAlive'        : CvEventManager.onSetPlayerAlive.__get__(self,CvEventManager),
  183.             'playerChangeStateReligion'     : CvEventManager.onPlayerChangeStateReligion.__get__(self,CvEventManager),
  184.             'playerGoldTrade'       : CvEventManager.onPlayerGoldTrade.__get__(self,CvEventManager),
  185.             'windowActivation'      : CvEventManager.onWindowActivation.__get__(self,CvEventManager),
  186.             'gameUpdate'            : CvEventManager.onGameUpdate.__get__(self,CvEventManager),     # sample generic event
  187.         }
  188.  
  189.         ################## Events List ###############################
  190.         #
  191.         # Dictionary of Events, indexed by EventID (also used at popup context id)
  192.         #   entries have name, beginFunction, applyFunction [, randomization weight...]
  193.         #
  194.         # Normal events first, random events after
  195.         #
  196.         ################## Events List ###############################
  197.         self.Events={
  198.             CvUtil.EventEditCityName : ('EditCityName', self.__eventEditCityNameApply, self.__eventEditCityNameBegin),
  199.             CvUtil.EventPlaceObject : ('PlaceObject', self.__eventPlaceObjectApply, self.__eventPlaceObjectBegin),
  200.             CvUtil.EventAwardTechsAndGold: ('AwardTechsAndGold', self.__eventAwardTechsAndGoldApply, self.__eventAwardTechsAndGoldBegin),
  201.             CvUtil.EventEditUnitName : ('EditUnitName', self.__eventEditUnitNameApply, self.__eventEditUnitNameBegin),
  202. ## Platy Builder ##
  203.             CvUtil.EventWBLandmarkPopup : ('WBLandmarkPopup', self.__eventWBLandmarkPopupApply, self.__eventWBScriptPopupBegin),
  204.             CvUtil.EventShowWonder: ('ShowWonder', self.__eventShowWonderApply, self.__eventShowWonderBegin),
  205.             1111 : ('WBPlayerScript', self.__eventWBPlayerScriptPopupApply, self.__eventWBScriptPopupBegin),
  206.             2222 : ('WBCityScript', self.__eventWBCityScriptPopupApply, self.__eventWBScriptPopupBegin),
  207.             3333 : ('WBUnitScript', self.__eventWBUnitScriptPopupApply, self.__eventWBScriptPopupBegin),
  208.             4444 : ('WBGameScript', self.__eventWBGameScriptPopupApply, self.__eventWBScriptPopupBegin),
  209.             5555 : ('WBPlotScript', self.__eventWBPlotScriptPopupApply, self.__eventWBScriptPopupBegin),
  210.  
  211. #magister
  212.             6666 : ('WBPlayerRename', self.__eventEditPlayerNameApply, self.__eventEditPlayerNameBegin),
  213.             6777 : ('WBPlayerRename', self.__eventEditCivNameApply, self.__eventEditCivNameBegin),
  214.             6888 : ('WBPlayerRename', self.__eventEditCivShortNameApply, self.__eventEditCivShortNameBegin),
  215.             6999 : ('WBPlayerRename', self.__eventEditCivAdjApply, self.__eventEditCivAdjBegin),
  216.  
  217. #magister
  218.  
  219.  
  220. ## Platy Builder ##
  221.         }
  222. ## FfH Card Game: begin
  223.         self.Events[CvUtil.EventSelectSolmniumPlayer] = ('selectSolmniumPlayer', self.__EventSelectSolmniumPlayerApply, self.__EventSelectSolmniumPlayerBegin)
  224.         self.Events[CvUtil.EventSolmniumAcceptGame] = ('solmniumAcceptGame', self.__EventSolmniumAcceptGameApply, self.__EventSolmniumAcceptGameBegin)
  225.         self.Events[CvUtil.EventSolmniumConcedeGame] = ('solmniumConcedeGame', self.__EventSolmniumConcedeGameApply, self.__EventSolmniumConcedeGameBegin)
  226. ## FfH Card Game: end
  227.  
  228. #################### EVENT STARTERS ######################
  229.     def handleEvent(self, argsList):
  230.         'EventMgr entry point'
  231.         # extract the last 6 args in the list, the first arg has already been consumed
  232.         self.origArgsList = argsList    # point to original
  233.         tag = argsList[0]               # event type string
  234.         idx = len(argsList)-6
  235.         bDummy = false
  236.         self.bDbg, bDummy, self.bAlt, self.bCtrl, self.bShift, self.bAllowCheats = argsList[idx:]
  237.         ret = 0
  238.         if self.EventHandlerMap.has_key(tag):
  239.             fxn = self.EventHandlerMap[tag]
  240.             ret = fxn(argsList[1:idx])
  241.         return ret
  242.  
  243. #################### EVENT APPLY ######################
  244.     def beginEvent( self, context, argsList=-1 ):
  245.         'Begin Event'
  246.         entry = self.Events[context]
  247.         return entry[2]( argsList )
  248.  
  249.     def applyEvent( self, argsList ):
  250.         'Apply the effects of an event '
  251.         context, playerID, netUserData, popupReturn = argsList
  252.  
  253.         if context == CvUtil.PopupTypeEffectViewer:
  254.             return CvDebugTools.g_CvDebugTools.applyEffectViewer( playerID, netUserData, popupReturn )
  255.  
  256.         entry = self.Events[context]
  257.  
  258.         if ( context not in CvUtil.SilentEvents ):
  259.             self.reportEvent(entry, context, (playerID, netUserData, popupReturn) )
  260.         return entry[1]( playerID, netUserData, popupReturn )   # the apply function
  261.  
  262.     def reportEvent(self, entry, context, argsList):
  263.         'Report an Event to Events.log '
  264.         if (gc.getGame().getActivePlayer() != -1):
  265.             message = "DEBUG Event: %s (%s)" %(entry[0], gc.getActivePlayer().getName())
  266.             CyInterface().addImmediateMessage(message,"")
  267.             CvUtil.pyPrint(message)
  268.         return 0
  269.  
  270. #################### ON EVENTS ######################
  271.     def onKbdEvent(self, argsList):
  272.         'keypress handler - return 1 if the event was consumed'
  273.  
  274.         eventType,key,mx,my,px,py = argsList
  275.         game = gc.getGame()
  276.  
  277.         if (self.bAllowCheats):
  278.             # notify debug tools of input to allow it to override the control
  279.             argsList = (eventType,key,self.bCtrl,self.bShift,self.bAlt,mx,my,px,py,gc.getGame().isNetworkMultiPlayer())
  280.             if ( CvDebugTools.g_CvDebugTools.notifyInput(argsList) ):
  281.                 return 0
  282.  
  283.         if ( eventType == self.EventKeyDown ):
  284.             theKey=int(key)
  285.  
  286. #FfH: Added by Kael 07/05/2008
  287.             if (theKey == int(InputTypes.KB_LEFT)):
  288.                 if self.bCtrl:
  289.                         CyCamera().SetBaseTurn(CyCamera().GetBaseTurn() - 45.0)
  290.                         return 1
  291.                 elif self.bShift:
  292.                         CyCamera().SetBaseTurn(CyCamera().GetBaseTurn() - 10.0)
  293.                         return 1
  294.  
  295.             if (theKey == int(InputTypes.KB_RIGHT)):
  296.                     if self.bCtrl:
  297.                             CyCamera().SetBaseTurn(CyCamera().GetBaseTurn() + 45.0)
  298.                             return 1
  299.                     elif self.bShift:
  300.                             CyCamera().SetBaseTurn(CyCamera().GetBaseTurn() + 10.0)
  301.                             return 1
  302. #FfH: End Add
  303.  
  304.  
  305.             CvCameraControls.g_CameraControls.handleInput( theKey )
  306.  
  307.             if (self.bAllowCheats):
  308.                 # Shift - T (Debug - No MP)
  309.                 if (theKey == int(InputTypes.KB_T)):
  310.                     if ( self.bShift ):
  311.                         CvEventManager.beginEvent(self,CvUtil.EventAwardTechsAndGold)
  312.                         #self.beginEvent(CvUtil.EventCameraControlPopup)
  313.                         return 1
  314.  
  315.                 elif (theKey == int(InputTypes.KB_W)):
  316.                     if ( self.bShift and self.bCtrl):
  317.                         CvEventManager.beginEvent(self,CvUtil.EventShowWonder)
  318.                         return 1
  319.  
  320.                 # Shift - ] (Debug - currently mouse-overd unit, health += 10
  321.                 elif (theKey == int(InputTypes.KB_LBRACKET) and self.bShift ):
  322.                     unit = CyMap().plot(px, py).getUnit(0)
  323.                     if ( not unit.isNone() ):
  324.                         d = min( unit.maxHitPoints()-1, unit.getDamage() + 10 )
  325.                         unit.setDamage( d, PlayerTypes.NO_PLAYER )
  326.  
  327.                 # Shift - [ (Debug - currently mouse-overd unit, health -= 10
  328.                 elif (theKey == int(InputTypes.KB_RBRACKET) and self.bShift ):
  329.                     unit = CyMap().plot(px, py).getUnit(0)
  330.                     if ( not unit.isNone() ):
  331.                         d = max( 0, unit.getDamage() - 10 )
  332.                         unit.setDamage( d, PlayerTypes.NO_PLAYER )
  333.  
  334.                 elif (theKey == int(InputTypes.KB_F1)):
  335.                     if ( self.bShift ):
  336.                         CvScreensInterface.replayScreen.showScreen(False)
  337.                         return 1
  338.                     # don't return 1 unless you want the input consumed
  339.  
  340.                 elif (theKey == int(InputTypes.KB_F2)):
  341.                     if ( self.bShift ):
  342.                         import CvDebugInfoScreen
  343.                         CvScreensInterface.showDebugInfoScreen()
  344.                         return 1
  345.  
  346.                 elif (theKey == int(InputTypes.KB_F3)):
  347.                     if ( self.bShift ):
  348.                         CvScreensInterface.showDanQuayleScreen(())
  349.                         return 1
  350.  
  351.                 elif (theKey == int(InputTypes.KB_F4)):
  352.                     if ( self.bShift ):
  353.                         CvScreensInterface.showUnVictoryScreen(())
  354.                         return 1
  355.  
  356.         return 0
  357.  
  358.     def onModNetMessage(self, argsList):
  359.         'Called whenever CyMessageControl().sendModNetMessage() is called - this is all for you modders!'
  360.  
  361.         iData1, iData2, iData3, iData4, iData5 = argsList
  362.  
  363. #       print("Modder's net message!")
  364. #       CvUtil.pyPrint( 'onModNetMessage' )
  365.  
  366. #FfH Card Game: begin
  367.         if iData1 == CvUtil.Somnium : # iData1 == 0 : Solmnium message, iData2 = function, iData3 to iData5 = parameters
  368.             if iData2 == 0 :
  369.                 if (iData3 == gc.getGame().getActivePlayer()):
  370.                     self.__EventSelectSolmniumPlayerBegin()
  371.             elif iData2 == 1 :
  372.                 if (iData4 == gc.getGame().getActivePlayer()):
  373.                     self.__EventSolmniumConcedeGameBegin((iData3, iData4))
  374.             else :
  375.                 cs.applyAction(iData2, iData3, iData4, iData5)
  376. # FfH Card Game: end
  377.  
  378. ## OOS fix by Snarko
  379.         elif (iData1 == CvUtil.ChangeCiv): #iData1 is unused, to allow for a condition here. It must not be zero (would trigger somnium)
  380.             CyGame().reassignPlayerAdvanced(iData2, iData3, -1)
  381. ## Declare war to Barbarians.
  382.         elif (iData1 == CvUtil.BarbarianWar):
  383.             gc.getTeam(iData2).declareWar(iData3, false, WarPlanTypes.WARPLAN_TOTAL)
  384.  
  385.  
  386.     def onInit(self, argsList):
  387.         'Called when Civ starts up'
  388.         CvUtil.pyPrint( 'OnInit' )
  389.  
  390.     def onUpdate(self, argsList):
  391.         'Called every frame'
  392.         fDeltaTime = argsList[0]
  393.  
  394.         # allow camera to be updated
  395.         CvCameraControls.g_CameraControls.onUpdate( fDeltaTime )
  396.  
  397.     def onWindowActivation(self, argsList):
  398.         'Called when the game window activates or deactivates'
  399.         bActive = argsList[0]
  400.  
  401.     def onUnInit(self, argsList):
  402.         'Called when Civ shuts down'
  403.         CvUtil.pyPrint('OnUnInit')
  404.  
  405.     def onPreSave(self, argsList):
  406.         "called before a game is actually saved"
  407.         CvUtil.pyPrint('OnPreSave')
  408.  
  409.     def onSaveGame(self, argsList):
  410.         "return the string to be saved - Must be a string"
  411.         return ""
  412.  
  413.     def onLoadGame(self, argsList):
  414.         CvAdvisorUtils.resetNoLiberateCities()
  415.         return 0
  416.  
  417.     def onGameStart(self, argsList):
  418.         'Called at the start of the game'
  419.  
  420.         #if CyGame().getWBMapScript():
  421.             #sf.gameStart()
  422.         #else:
  423.             #introMovie = CvIntroMovieScreen.CvIntroMovieScreen()
  424.             #introMovie.interfaceScreen()
  425.             #Get rid of the intro movie
  426.  
  427.         if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_THAW):
  428.             iDesert = gc.getInfoTypeForString('TERRAIN_DESERT')
  429.             iGrass = gc.getInfoTypeForString('TERRAIN_GRASS')
  430.             iPlains = gc.getInfoTypeForString('TERRAIN_PLAINS')
  431.             iSnow = gc.getInfoTypeForString('TERRAIN_SNOW')
  432.             iTundra = gc.getInfoTypeForString('TERRAIN_TUNDRA')
  433.             for i in range (CyMap().numPlots()):
  434.                 pPlot = CyMap().plotByIndex(i)
  435.                 if pPlot.getFeatureType() == -1:
  436.                     if pPlot.getImprovementType() == -1:
  437.                         if pPlot.isWater() == False:
  438.                             iTerrain = pPlot.getTerrainType()
  439.                             if iTerrain == iTundra:
  440.                                 pPlot.setTempTerrainType(iSnow, CyGame().getSorenRandNum(90, "Bob") + 10)
  441.                             if iTerrain == iGrass:
  442.                                 pPlot.setTempTerrainType(iTundra, CyGame().getSorenRandNum(90, "Bob") + 10)
  443.                             if iTerrain == iPlains:
  444.                                 pPlot.setTempTerrainType(iTundra, CyGame().getSorenRandNum(90, "Bob") + 10)
  445.                             if iTerrain == iDesert:
  446.                                 pPlot.setTempTerrainType(iPlains, CyGame().getSorenRandNum(90, "Bob") + 10)
  447.  
  448.         for iPlayer in range(gc.getMAX_PLAYERS()):
  449.             player = gc.getPlayer(iPlayer)
  450.             if player.isAlive():
  451.                 if player.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_ELOHIM'):
  452.                     cf.showUniqueImprovements(iPlayer)
  453.  
  454.         if not gc.getGame().isNetworkMultiPlayer():
  455.             t = "TROPHY_FEAT_INTRODUCTION"
  456.             if not CyGame().isHasTrophy(t):
  457.                 CyGame().changeTrophyValue(t, 1)
  458.                 sf.addPopupWB(CyTranslator().getText("TXT_KEY_FFH_INTRO",()),'art/interface/popups/FfHIntro.dds')
  459.  
  460.         if CyGame().isOption(gc.getInfoTypeForString('GAMEOPTION_NO_BARBARIANS')) == False and (not CyGame().getWBMapScript()):
  461.             iGoblinFort = gc.getInfoTypeForString('IMPROVEMENT_GOBLIN_FORT')
  462.             bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
  463.             for i in range (CyMap().numPlots()):
  464.                 pPlot = CyMap().plotByIndex(i)
  465.                 if pPlot.getImprovementType() == iGoblinFort:
  466.                     bPlayer.initUnit(gc.getInfoTypeForString('UNIT_ARCHER_SCORPION_CLAN'), pPlot.getX(), pPlot.getY(), UnitAITypes.UNITAI_LAIRGUARDIAN, DirectionTypes.DIRECTION_SOUTH)
  467.  
  468.         if (gc.getGame().getGameTurnYear() == gc.getDefineINT("START_YEAR") and not gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ADVANCED_START)):
  469.             if not CyGame().getWBMapScript():
  470.                 for iPlayer in range(gc.getMAX_PLAYERS()):
  471.                     player = gc.getPlayer(iPlayer)
  472.                     if (player.isAlive() and player.isHuman()):
  473.                         popupInfo = CyPopupInfo()
  474.                         popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
  475.                         popupInfo.setText(u"showDawnOfMan")
  476.                         popupInfo.addPopup(iPlayer)
  477.         else:
  478.             CyInterface().setSoundSelectionReady(true)
  479.  
  480.         if gc.getGame().isPbem():
  481.             for iPlayer in range(gc.getMAX_PLAYERS()):
  482.                 player = gc.getPlayer(iPlayer)
  483.                 if (player.isAlive() and player.isHuman()):
  484.                     popupInfo = CyPopupInfo()
  485.                     popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_DETAILS)
  486.                     popupInfo.setOption1(true)
  487.                     popupInfo.addPopup(iPlayer)
  488.  
  489.         # Super Forts
  490.         CyMap().calculateCanalAndChokePoints()
  491.  
  492.         CvAdvisorUtils.resetNoLiberateCities()
  493.        
  494.        
  495.         #Set the AC to at least 10
  496.         CyGame().changeGlobalCounter(10)
  497.        
  498.         #Check line 2279 of CustomFunctions - true is lower case and not highlighted - is it working???
  499.         #Make the good civs all at peace and the evil civs all at peace and the good and evil civs at war
  500.         #Sometimes this seems to cause "expected read buffer: dict found" error after the first turn but the error says that it is related to the pickle in BANE DIVINE section
  501.        
  502.        
  503.         #Make the pop-up text for this scenario
  504.         #Write a story in CIV4GameText_FFH2.xml
  505.         sf.addPopupWB(CyTranslator().getText("TXT_KEY_WB_ELOHIM_SCENARIO_INTRO",()), 'art/interface/popups/Blood of Angels.dds')
  506.        
  507.        
  508.        
  509.         #Find and set the Team (i.e. player) ID numbers for each civ in the game (could be done manually since it is a scenario with fixed civs)
  510.         for iGoodAndEvilPlayer in range(gc.getMAX_PLAYERS()):
  511.             pGoodAndEvilPlayer = gc.getPlayer(iGoodAndEvilPlayer)
  512.             if pGoodAndEvilPlayer.isAlive():
  513.                 if pGoodAndEvilPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_BANNOR'):
  514.                     iBannorTeamID = gc.getPlayer(iGoodAndEvilPlayer).getTeam()
  515.                 if pGoodAndEvilPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_CALABIM'):
  516.                     iCalabimTeamID = gc.getPlayer(iGoodAndEvilPlayer).getTeam()
  517.                 if pGoodAndEvilPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_CLAN_OF_EMBERS'):
  518.                     iClanOfEmbersTeamID = gc.getPlayer(iGoodAndEvilPlayer).getTeam()
  519.                 if pGoodAndEvilPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_DOVIELLO'):
  520.                     iDovielloTeamID = gc.getPlayer(iGoodAndEvilPlayer).getTeam()
  521.                 if pGoodAndEvilPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_ELOHIM'):
  522.                     iElohimTeamID = gc.getPlayer(iGoodAndEvilPlayer).getTeam()
  523.                 if pGoodAndEvilPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_KURIOTATES'):
  524.                     iKuriotatesTeamID = gc.getPlayer(iGoodAndEvilPlayer).getTeam()
  525.                 if pGoodAndEvilPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LJOSALFAR'):
  526.                     iLjosalfarTeamID = gc.getPlayer(iGoodAndEvilPlayer).getTeam()
  527.                 if pGoodAndEvilPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LUCHUIRP'):
  528.                     iLuchuirpTeamID = gc.getPlayer(iGoodAndEvilPlayer).getTeam()
  529.                 if pGoodAndEvilPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_SHEAIM'):
  530.                     iSheaimTeamID = gc.getPlayer(iGoodAndEvilPlayer).getTeam()
  531.                 if pGoodAndEvilPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_SVARTALFAR'):
  532.                     iSvartalfarTeamID = gc.getPlayer(iGoodAndEvilPlayer).getTeam()
  533.  
  534.                
  535.                    
  536.        
  537.         #If the setPermanentWarPeace boolean is True then the civs cannot change their peace or war status.  Use declareWar first to keep them at war with the True boolean.
  538.         #If the declareWar boolean is True then you get a pop-up message that the civ declares war on you, if it is False then there is no pop-up message
  539.         #If the meet boolean is True then you get a pop-up message that you met them for the first time, if it is False then there is no pop-up message
  540.        
  541.        
  542.         for iWarAndPeaceTeam in range(gc.getMAX_CIV_TEAMS()):
  543.             pWarAndPeaceTeam = gc.getTeam(iWarAndPeaceTeam)
  544.             if pWarAndPeaceTeam.isAlive():
  545.                 #Make good civs meet other good civs
  546.                 if iWarAndPeaceTeam == iBannorTeamID:
  547.                     pWarAndPeaceTeam.meet(iElohimTeamID, False)
  548.                     pWarAndPeaceTeam.meet(iKuriotatesTeamID, False)
  549.                     pWarAndPeaceTeam.meet(iLjosalfarTeamID, False)
  550.                     pWarAndPeaceTeam.meet(iLuchuirpTeamID, False)
  551.                 if iWarAndPeaceTeam == iElohimTeamID:
  552.                     pWarAndPeaceTeam.meet(iKuriotatesTeamID, False)
  553.                     pWarAndPeaceTeam.meet(iLjosalfarTeamID, False)
  554.                     pWarAndPeaceTeam.meet(iLuchuirpTeamID, False)
  555.                 if iWarAndPeaceTeam == iKuriotatesTeamID:
  556.                     pWarAndPeaceTeam.meet(iLjosalfarTeamID, False)
  557.                     pWarAndPeaceTeam.meet(iLuchuirpTeamID, False)
  558.                 if iWarAndPeaceTeam == iLjosalfarTeamID:
  559.                     pWarAndPeaceTeam.meet(iLuchuirpTeamID, False)
  560.                 #Make evil civs meet other evil civs
  561.                 if iWarAndPeaceTeam == iCalabimTeamID:
  562.                     pWarAndPeaceTeam.meet(iClanOfEmbersTeamID, False)
  563.                     pWarAndPeaceTeam.meet(iDovielloTeamID, False)
  564.                     pWarAndPeaceTeam.meet(iSheaimTeamID, False)
  565.                     pWarAndPeaceTeam.meet(iSvartalfarTeamID, False)
  566.                 if iWarAndPeaceTeam == iClanOfEmbersTeamID:
  567.                     pWarAndPeaceTeam.meet(iDovielloTeamID, False)
  568.                     pWarAndPeaceTeam.meet(iSheaimTeamID, False)
  569.                     pWarAndPeaceTeam.meet(iSvartalfarTeamID, False)
  570.                 if iWarAndPeaceTeam == iDovielloTeamID:
  571.                     pWarAndPeaceTeam.meet(iSheaimTeamID, False)
  572.                     pWarAndPeaceTeam.meet(iSvartalfarTeamID, False)
  573.                 if iWarAndPeaceTeam == iSheaimTeamID:
  574.                     pWarAndPeaceTeam.meet(iSvartalfarTeamID, False)        
  575.                 #This section makes the evils civs at war with the good civs
  576.                 if iWarAndPeaceTeam == iCalabimTeamID:
  577.                     pWarAndPeaceTeam.declareWar(iBannorTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  578.                     pWarAndPeaceTeam.setPermanentWarPeace(iBannorTeamID, True)
  579.                     pWarAndPeaceTeam.declareWar(iElohimTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  580.                     pWarAndPeaceTeam.setPermanentWarPeace(iElohimTeamID, True)
  581.                     pWarAndPeaceTeam.declareWar(iKuriotatesTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  582.                     pWarAndPeaceTeam.setPermanentWarPeace(iKuriotatesTeamID, True)
  583.                     pWarAndPeaceTeam.declareWar(iLjosalfarTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  584.                     pWarAndPeaceTeam.setPermanentWarPeace(iLjosalfarTeamID, True)
  585.                     pWarAndPeaceTeam.declareWar(iLuchuirpTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  586.                     pWarAndPeaceTeam.setPermanentWarPeace(iLuchuirpTeamID, True)
  587.                 if iWarAndPeaceTeam == iClanOfEmbersTeamID:
  588.                     pWarAndPeaceTeam.declareWar(iBannorTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  589.                     pWarAndPeaceTeam.setPermanentWarPeace(iBannorTeamID, True)
  590.                     pWarAndPeaceTeam.declareWar(iElohimTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  591.                     pWarAndPeaceTeam.setPermanentWarPeace(iElohimTeamID, True)
  592.                     pWarAndPeaceTeam.declareWar(iKuriotatesTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  593.                     pWarAndPeaceTeam.setPermanentWarPeace(iKuriotatesTeamID, True)
  594.                     pWarAndPeaceTeam.declareWar(iLjosalfarTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  595.                     pWarAndPeaceTeam.setPermanentWarPeace(iLjosalfarTeamID, True)
  596.                     pWarAndPeaceTeam.declareWar(iLuchuirpTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  597.                     pWarAndPeaceTeam.setPermanentWarPeace(iLuchuirpTeamID, True)
  598.                 if iWarAndPeaceTeam == iDovielloTeamID:
  599.                     pWarAndPeaceTeam.declareWar(iBannorTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  600.                     pWarAndPeaceTeam.setPermanentWarPeace(iBannorTeamID, True)
  601.                     pWarAndPeaceTeam.declareWar(iElohimTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  602.                     pWarAndPeaceTeam.setPermanentWarPeace(iElohimTeamID, True)
  603.                     pWarAndPeaceTeam.declareWar(iKuriotatesTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  604.                     pWarAndPeaceTeam.setPermanentWarPeace(iKuriotatesTeamID, True)
  605.                     pWarAndPeaceTeam.declareWar(iLjosalfarTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  606.                     pWarAndPeaceTeam.setPermanentWarPeace(iLjosalfarTeamID, True)
  607.                     pWarAndPeaceTeam.declareWar(iLuchuirpTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  608.                     pWarAndPeaceTeam.setPermanentWarPeace(iLuchuirpTeamID, True)
  609.                 if iWarAndPeaceTeam == iSheaimTeamID:
  610.                     pWarAndPeaceTeam.declareWar(iBannorTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  611.                     pWarAndPeaceTeam.setPermanentWarPeace(iBannorTeamID, True)
  612.                     pWarAndPeaceTeam.declareWar(iElohimTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  613.                     pWarAndPeaceTeam.setPermanentWarPeace(iElohimTeamID, True)
  614.                     pWarAndPeaceTeam.declareWar(iKuriotatesTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  615.                     pWarAndPeaceTeam.setPermanentWarPeace(iKuriotatesTeamID, True)
  616.                     pWarAndPeaceTeam.declareWar(iLjosalfarTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  617.                     pWarAndPeaceTeam.setPermanentWarPeace(iLjosalfarTeamID, True)
  618.                     pWarAndPeaceTeam.declareWar(iLuchuirpTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  619.                     pWarAndPeaceTeam.setPermanentWarPeace(iLuchuirpTeamID, True)
  620.                 if iWarAndPeaceTeam == iSvartalfarTeamID:
  621.                     pWarAndPeaceTeam.declareWar(iBannorTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  622.                     pWarAndPeaceTeam.setPermanentWarPeace(iBannorTeamID, True)
  623.                     pWarAndPeaceTeam.declareWar(iElohimTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  624.                     pWarAndPeaceTeam.setPermanentWarPeace(iElohimTeamID, True)
  625.                     pWarAndPeaceTeam.declareWar(iKuriotatesTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  626.                     pWarAndPeaceTeam.setPermanentWarPeace(iKuriotatesTeamID, True)
  627.                     pWarAndPeaceTeam.declareWar(iLjosalfarTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  628.                     pWarAndPeaceTeam.setPermanentWarPeace(iLjosalfarTeamID, True)
  629.                     pWarAndPeaceTeam.declareWar(iLuchuirpTeamID, False, WarPlanTypes.WARPLAN_TOTAL)
  630.                     pWarAndPeaceTeam.setPermanentWarPeace(iLuchuirpTeamID, True)
  631.                 #This makes good civs be at peace with good civs
  632.                 if iWarAndPeaceTeam == iBannorTeamID:
  633.                     pWarAndPeaceTeam.setPermanentWarPeace(iElohimTeamID, True)
  634.                     pWarAndPeaceTeam.setPermanentWarPeace(iKuriotatesTeamID, True)
  635.                     pWarAndPeaceTeam.setPermanentWarPeace(iLjosalfarTeamID, True)
  636.                     pWarAndPeaceTeam.setPermanentWarPeace(iLuchuirpTeamID, True)
  637.                 if iWarAndPeaceTeam == iElohimTeamID:
  638.                     pWarAndPeaceTeam.setPermanentWarPeace(iKuriotatesTeamID, True)
  639.                     pWarAndPeaceTeam.setPermanentWarPeace(iLjosalfarTeamID, True)
  640.                     pWarAndPeaceTeam.setPermanentWarPeace(iLuchuirpTeamID, True)
  641.                 if iWarAndPeaceTeam == iKuriotatesTeamID:
  642.                     pWarAndPeaceTeam.setPermanentWarPeace(iLjosalfarTeamID, True)
  643.                     pWarAndPeaceTeam.setPermanentWarPeace(iLuchuirpTeamID, True)
  644.                 if iWarAndPeaceTeam == iLjosalfarTeamID:
  645.                     pWarAndPeaceTeam.setPermanentWarPeace(iLuchuirpTeamID, True)
  646.  
  647.                    
  648.            
  649.        
  650.  
  651.     def onGameEnd(self, argsList):
  652.         'Called at the End of the game'
  653.         print("Game is ending")
  654.         return
  655.  
  656.     def onBeginGameTurn(self, argsList):
  657.         'Called at the beginning of the end of each turn'
  658.         iGameTurn = argsList[0]
  659.        
  660.        
  661.        
  662.         #Makes the human Elohim player win if the AC = 0, #2 is a conquest victory (maybe modify this)
  663.         iElohimPlayer = 0
  664.         pElohimPlayer = gc.getPlayer(iElohimPlayer)
  665.         if CyGame().getGlobalCounter() <= 0:
  666.             gc.getGame().setWinner(pElohimPlayer.getTeam(), 2)
  667.            
  668.         #Debug to test if the victory condition is working
  669.         #CyGame().changeGlobalCounter(-2)
  670.            
  671.        
  672.            
  673.            
  674.  
  675.         iOrthusTurn = 75
  676.         if not CyGame().isUnitClassMaxedOut(gc.getInfoTypeForString('UNITCLASS_ORTHUS'), 0):
  677.             if not CyGame().isOption(gc.getInfoTypeForString('GAMEOPTION_NO_ORTHUS')):
  678.                 bOrthus = False
  679.                 if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_QUICK'):
  680.                     if iGameTurn >= iOrthusTurn / 3 * 2:
  681.                         bOrthus = True
  682.                 elif CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_NORMAL'):
  683.                     if iGameTurn >= iOrthusTurn:
  684.                         bOrthus = True
  685.                 elif CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_EPIC'):
  686.                     if iGameTurn >= iOrthusTurn * 3 / 2:
  687.                         bOrthus = True
  688.                 elif CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_MARATHON'):
  689.                     if iGameTurn >= iOrthusTurn * 3:
  690.                         bOrthus = True
  691.                 if bOrthus:
  692.                     bValid=True
  693.                     for i in range (CyMap().numPlots()):
  694.                         pPlot = CyMap().plotByIndex(i)
  695.                         iPlot = -1
  696.                         if pPlot.getImprovementType()==gc.getInfoTypeForString('IMPROVEMENT_GOBLIN_FORT'):
  697.                             bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
  698.                             if not pPlot.isVisibleOtherUnit(gc.getBARBARIAN_PLAYER()):
  699.                                 bPlayer.initUnit(gc.getInfoTypeForString('UNIT_ORTHUS'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  700.                                 bValid=False
  701.                                 break
  702.                     if bValid:
  703.                         iUnit = gc.getInfoTypeForString('UNIT_ORTHUS')
  704.                         cf.addUnit(iUnit)
  705.                         if( CyGame().getAIAutoPlay(CyGame().getActivePlayer()) == 0 ) :
  706.                             cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_ORTHUS_CREATION",()), str(gc.getUnitInfo(iUnit).getImage()))
  707.  
  708.                                
  709.  
  710.                    
  711.        
  712.         #NEW MANUAL-ISH MOVING CODE STARTS HERE#
  713.         #This code should give all units in tile(10,10) the HELD promotion so that they can't move anywhere.
  714.         #iTargetX and iTargetY give the coordinates of the tile that the unit stack is moving into
  715.         iTargetX = 60
  716.         iTargetY = 20
  717.         pTargetPlot = CyMap().plot(iTargetX,iTargetY)
  718.        
  719.         if iGameTurn < 5:
  720.             iOldX = 67
  721.             iOldY = 28
  722.             pOldPlot = CyMap().plot(iOldX,iOldY)
  723.             for i in range(pOldPlot.getNumUnits()):
  724.                 pUnit = pOldPlot.getUnit(i)
  725.                 pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD'), True)
  726.             #Remember the x and y values between turns 4 and 5
  727.             myPickle = [iOldX, iOldY]
  728.             serializedMyPickle = pickle.dumps(myPickle)
  729.             BugData.getTable("MY_TABLE").setData(serializedMyPickle)
  730.  
  731.        
  732.         if iGameTurn >= 5 and iGameTurn <= 20:
  733.             #Load x and y values
  734.             serializedMyPickle = BugData.getTable("MY_TABLE").data
  735.             myPickle = pickle.loads(serializedMyPickle)
  736.             iOldX = myPickle[0]
  737.             iOldY = myPickle[1]
  738.             pOldPlot = CyMap().plot(iOldX, iOldY)
  739.             UnitsMoved = -1
  740.            
  741.            
  742.             if iOldY == iTargetY and iOldX > iTargetX:
  743.                 #First choice is to move W if possible
  744.                 if UnitsMoved == -1:
  745.                     iNewX = iOldX - 1
  746.                     iNewY = iOldY
  747.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  748.                     if pNewPlot.isNone() == False:
  749.                         if pNewPlot.getNumUnits() == 0:
  750.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  751.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  752.                                     pUnit = pOldPlot.getUnit(i)
  753.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  754.                                 UnitsMoved = 1
  755.                
  756.                 #Second choice is to move NW if possible
  757.                 if UnitsMoved == -1:
  758.                     iNewY = iNewY + 1
  759.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  760.                     if pNewPlot.isNone() == False:
  761.                         if pNewPlot.getNumUnits() == 0:
  762.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  763.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  764.                                     pUnit = pOldPlot.getUnit(i)
  765.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  766.                                 UnitsMoved = 1
  767.                                
  768.                 #Third choice is to move SW if possible
  769.                 if UnitsMoved == -1:
  770.                     iNewY = iNewY - 2
  771.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  772.                     if pNewPlot.isNone() == False:
  773.                         if pNewPlot.getNumUnits() == 0:
  774.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  775.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  776.                                     pUnit = pOldPlot.getUnit(i)
  777.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  778.                                 UnitsMoved = 1
  779.                                
  780.                 #Fourth choice is to stay in the same tile
  781.                 if UnitsMoved == -1:
  782.                     iNewY = iNewY + 1
  783.                     iNewX = iNewX + 1
  784.                     pNewPlot = CyMap().plot(iNewX,iNewY)
  785.                     for i in range(pOldPlot.getNumUnits(), -1, -1):
  786.                         pUnit = pOldPlot.getUnit(i)
  787.                         pUnit.setXY(iNewX, iNewY, False, True, True)
  788.                     UnitsMoved = 1
  789.                
  790.                 #Remember the x and y values between turns
  791.                 iOldX = iNewX
  792.                 iOldY = iNewY
  793.                 myPickle = [iOldX, iOldY]
  794.                 serializedMyPickle = pickle.dumps(myPickle)
  795.                 BugData.getTable("MY_TABLE").setData(serializedMyPickle)
  796.  
  797.            
  798.             if iOldY > iTargetY and iOldY < iTargetY + 5 and iOldX > iTargetX:
  799.                 #First choice is to move SW if possible
  800.                 if UnitsMoved == -1:
  801.                     iNewX = iOldX - 1
  802.                     iNewY = iOldY - 1
  803.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  804.                     if pNewPlot.isNone() == False:
  805.                         if pNewPlot.getNumUnits() == 0:
  806.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  807.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  808.                                     pUnit = pOldPlot.getUnit(i)
  809.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  810.                                 UnitsMoved = 1
  811.                
  812.                 #Second choice is to move W if possible
  813.                 if UnitsMoved == -1:
  814.                     iNewY = iNewY + 1
  815.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  816.                     if pNewPlot.isNone() == False:
  817.                         if pNewPlot.getNumUnits() == 0:
  818.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  819.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  820.                                     pUnit = pOldPlot.getUnit(i)
  821.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  822.                                 UnitsMoved = 1
  823.                                
  824.                 #Third choice is to move NW if possible
  825.                 if UnitsMoved == -1:
  826.                     iNewY = iNewY + 1
  827.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  828.                     if pNewPlot.isNone() == False:
  829.                         if pNewPlot.getNumUnits() == 0:
  830.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  831.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  832.                                     pUnit = pOldPlot.getUnit(i)
  833.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  834.                                 UnitsMoved = 1
  835.                                
  836.                 #Fourth choice is to stay in the same tile
  837.                 if UnitsMoved == -1:
  838.                     iNewY = iNewY - 1
  839.                     iNewX = iNewX + 1
  840.                     pNewPlot = CyMap().plot(iNewX,iNewY)
  841.                     for i in range(pOldPlot.getNumUnits(), -1, -1):
  842.                         pUnit = pOldPlot.getUnit(i)
  843.                         pUnit.setXY(iNewX, iNewY, False, True, True)
  844.                     UnitsMoved = 1
  845.                
  846.                 #Remember the x and y values between turns
  847.                 iOldX = iNewX
  848.                 iOldY = iNewY
  849.                 myPickle = [iOldX, iOldY]
  850.                 serializedMyPickle = pickle.dumps(myPickle)
  851.                 BugData.getTable("MY_TABLE").setData(serializedMyPickle)
  852.  
  853.                
  854.             if iOldY < iTargetY and iOldY > iTargetY - 5 and iOldX > iTargetX:
  855.                 #First choice is to move NW if possible
  856.                 if UnitsMoved == -1:
  857.                     iNewX = iOldX - 1
  858.                     iNewY = iOldY + 1
  859.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  860.                     if pNewPlot.isNone() == False:
  861.                         if pNewPlot.getNumUnits() == 0:
  862.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  863.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  864.                                     pUnit = pOldPlot.getUnit(i)
  865.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  866.                                 UnitsMoved = 1
  867.                
  868.                 #Second choice is to move W if possible
  869.                 if UnitsMoved == -1:
  870.                     iNewY = iNewY - 1
  871.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  872.                     if pNewPlot.isNone() == False:
  873.                         if pNewPlot.getNumUnits() == 0:
  874.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  875.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  876.                                     pUnit = pOldPlot.getUnit(i)
  877.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  878.                                 UnitsMoved = 1
  879.                                
  880.                 #Third choice is to move SW if possible
  881.                 if UnitsMoved == -1:
  882.                     iNewY = iNewY - 1
  883.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  884.                     if pNewPlot.isNone() == False:
  885.                         if pNewPlot.getNumUnits() == 0:
  886.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  887.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  888.                                     pUnit = pOldPlot.getUnit(i)
  889.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  890.                                 UnitsMoved = 1
  891.                                
  892.                 #Fourth choice is to stay in the same tile
  893.                 if UnitsMoved == -1:
  894.                     iNewY = iNewY + 1
  895.                     iNewX = iNewX + 1
  896.                     pNewPlot = CyMap().plot(iNewX,iNewY)
  897.                     for i in range(pOldPlot.getNumUnits(), -1, -1):
  898.                         pUnit = pOldPlot.getUnit(i)
  899.                         pUnit.setXY(iNewX, iNewY, False, True, True)
  900.                     UnitsMoved = 1
  901.                
  902.                 #Remember the x and y values between turns
  903.                 iOldX = iNewX
  904.                 iOldY = iNewY
  905.                 myPickle = [iOldX, iOldY]
  906.                 serializedMyPickle = pickle.dumps(myPickle)
  907.                 BugData.getTable("MY_TABLE").setData(serializedMyPickle)
  908.                
  909.                
  910.             if iOldY >= iTargetY + 5 and iOldX > iTargetX:
  911.                 #First choice is to move SW if possible
  912.                 if UnitsMoved == -1:
  913.                     iNewX = iOldX - 1
  914.                     iNewY = iOldY - 1
  915.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  916.                     if pNewPlot.isNone() == False:
  917.                         if pNewPlot.getNumUnits() == 0:
  918.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  919.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  920.                                     pUnit = pOldPlot.getUnit(i)
  921.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  922.                                 UnitsMoved = 1
  923.                                                
  924.                 #Second choice is to stay in the same tile
  925.                 if UnitsMoved == -1:
  926.                     iNewY = iNewY + 1
  927.                     iNewX = iNewX + 1
  928.                     pNewPlot = CyMap().plot(iNewX,iNewY)
  929.                     for i in range(pOldPlot.getNumUnits(), -1, -1):
  930.                         pUnit = pOldPlot.getUnit(i)
  931.                         pUnit.setXY(iNewX, iNewY, False, True, True)
  932.                     UnitsMoved = 1
  933.                
  934.                 #Remember the x and y values between turns
  935.                 iOldX = iNewX
  936.                 iOldY = iNewY
  937.                 myPickle = [iOldX, iOldY]
  938.                 serializedMyPickle = pickle.dumps(myPickle)
  939.                 BugData.getTable("MY_TABLE").setData(serializedMyPickle)
  940.                
  941.  
  942.             if iOldY <= iTargetY - 5 and iOldX > iTargetX:
  943.                 #First choice is to move NW if possible
  944.                 if UnitsMoved == -1:
  945.                     iNewX = iOldX - 1
  946.                     iNewY = iOldY + 1
  947.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  948.                     if pNewPlot.isNone() == False:
  949.                         if pNewPlot.getNumUnits() == 0:
  950.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  951.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  952.                                     pUnit = pOldPlot.getUnit(i)
  953.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  954.                                 UnitsMoved = 1
  955.                                
  956.                 #Second choice is to stay in the same tile
  957.                 if UnitsMoved == -1:
  958.                     iNewY = iNewY -1
  959.                     iNewX = iNewX + 1
  960.                     pNewPlot = CyMap().plot(iNewX,iNewY)
  961.                     for i in range(pOldPlot.getNumUnits(), -1, -1):
  962.                         pUnit = pOldPlot.getUnit(i)
  963.                         pUnit.setXY(iNewX, iNewY, False, True, True)
  964.                     UnitsMoved = 1
  965.                
  966.                 #Remember the x and y values between turns
  967.                 iOldX = iNewX
  968.                 iOldY = iNewY
  969.                 myPickle = [iOldX, iOldY]
  970.                 serializedMyPickle = pickle.dumps(myPickle)
  971.                 BugData.getTable("MY_TABLE").setData(serializedMyPickle)
  972.                
  973.             #Flaw in this programming!!!
  974.             if iOldY < iTargetY and iOldY > iTargetY - 5 and iOldX == iTargetX:
  975.                 #First choice is to move N if possible
  976.                 if UnitsMoved == -1:
  977.                     iNewX = iOldX
  978.                     iNewY = iOldY + 1
  979.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  980.                     if pNewPlot.isNone() == False:
  981.                         if pNewPlot.getNumUnits() == 0:
  982.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  983.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  984.                                     pUnit = pOldPlot.getUnit(i)
  985.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  986.                                 UnitsMoved = 1
  987.            
  988.                 #Second choice is to stay in the same tile
  989.                 if UnitsMoved == -1:
  990.                     iNewY = iNewY - 1
  991.                     iNewX = iNewX
  992.                     pNewPlot = CyMap().plot(iNewX,iNewY)
  993.                     for i in range(pOldPlot.getNumUnits(), -1, -1):
  994.                         pUnit = pOldPlot.getUnit(i)
  995.                         pUnit.setXY(iNewX, iNewY, False, True, True)
  996.                     UnitsMoved = 1
  997.                
  998.                 #Remember the x and y values between turns
  999.                 iOldX = iNewX
  1000.                 iOldY = iNewY
  1001.                 myPickle = [iOldX, iOldY]
  1002.                 serializedMyPickle = pickle.dumps(myPickle)
  1003.                 BugData.getTable("MY_TABLE").setData(serializedMyPickle)
  1004.                
  1005.             if iOldY > iTargetY and iOldY < iTargetY + 5 and iOldX == iTargetX:
  1006.                 #First choice is to move S if possible
  1007.                 if UnitsMoved == -1:
  1008.                     iNewX = iOldX
  1009.                     iNewY = iOldY - 1
  1010.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  1011.                     if pNewPlot.isNone() == False:
  1012.                         if pNewPlot.getNumUnits() == 0:
  1013.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  1014.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  1015.                                     pUnit = pOldPlot.getUnit(i)
  1016.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  1017.                                 UnitsMoved = 1
  1018.            
  1019.                 #Second choice is to stay in the same tile
  1020.                 if UnitsMoved == -1:
  1021.                     iNewY = iNewY + 1
  1022.                     iNewX = iNewX
  1023.                     pNewPlot = CyMap().plot(iNewX,iNewY)
  1024.                     for i in range(pOldPlot.getNumUnits(), -1, -1):
  1025.                         pUnit = pOldPlot.getUnit(i)
  1026.                         pUnit.setXY(iNewX, iNewY, False, True, True)
  1027.                     UnitsMoved = 1
  1028.                
  1029.                 #Remember the x and y values between turns
  1030.                 iOldX = iNewX
  1031.                 iOldY = iNewY
  1032.                 myPickle = [iOldX, iOldY]
  1033.                 serializedMyPickle = pickle.dumps(myPickle)
  1034.                 BugData.getTable("MY_TABLE").setData(serializedMyPickle)
  1035.                                
  1036.             if iOldY <= iTargetY - 5 and iOldX == iTargetX:
  1037.                 #cf.addUnit(gc.getInfoTypeForString('UNIT_HUNTER'))
  1038.                 #First choice is to move N if possible
  1039.                 if UnitsMoved == -1:
  1040.                     iNewX = iOldX
  1041.                     iNewY = iOldY + 1
  1042.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  1043.                     if pNewPlot.isNone() == False:
  1044.                         if pNewPlot.getNumUnits() == 0:
  1045.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  1046.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  1047.                                     pUnit = pOldPlot.getUnit(i)
  1048.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  1049.                                 UnitsMoved = 1
  1050.                                
  1051.                 #Second choice is to stay in the same tile
  1052.                 if UnitsMoved == -1:
  1053.                     iNewY = iNewY -1
  1054.                     iNewX = iNewX
  1055.                     pNewPlot = CyMap().plot(iNewX,iNewY)
  1056.                     for i in range(pOldPlot.getNumUnits(), -1, -1):
  1057.                         pUnit = pOldPlot.getUnit(i)
  1058.                         pUnit.setXY(iNewX, iNewY, False, True, True)
  1059.                     UnitsMoved = 1
  1060.                
  1061.                 #Remember the x and y values between turns
  1062.                 iOldX = iNewX
  1063.                 iOldY = iNewY
  1064.                 myPickle = [iOldX, iOldY]
  1065.                 serializedMyPickle = pickle.dumps(myPickle)
  1066.                 BugData.getTable("MY_TABLE").setData(serializedMyPickle)
  1067.                
  1068.                
  1069.             if iOldY >= iTargetY + 5 and iOldX == iTargetX:
  1070.                 cf.addUnit(gc.getInfoTypeForString('UNIT_HUNTER'))
  1071.                 #First choice is to move S if possible
  1072.                 if UnitsMoved == -1:
  1073.                     iNewX = iOldX
  1074.                     iNewY = iOldY - 1
  1075.                     pNewPlot = CyMap().plot(iNewX,iNewY)           
  1076.                     if pNewPlot.isNone() == False:
  1077.                         if pNewPlot.getNumUnits() == 0:
  1078.                             if (pNewPlot.isWater() == False and pNewPlot.isPeak() == False and pNewPlot.isCity() == False):
  1079.                                 for i in range(pOldPlot.getNumUnits(), -1, -1):
  1080.                                     pUnit = pOldPlot.getUnit(i)
  1081.                                     pUnit.setXY(iNewX, iNewY, False, True, True)
  1082.                                 UnitsMoved = 1
  1083.                                
  1084.                 #Second choice is to stay in the same tile
  1085.                 if UnitsMoved == -1:
  1086.                     iNewY = iNewY +1
  1087.                     iNewX = iNewX
  1088.                     pNewPlot = CyMap().plot(iNewX,iNewY)
  1089.                     for i in range(pOldPlot.getNumUnits(), -1, -1):
  1090.                         pUnit = pOldPlot.getUnit(i)
  1091.                         pUnit.setXY(iNewX, iNewY, False, True, True)
  1092.                     UnitsMoved = 1
  1093.                
  1094.                 #Remember the x and y values between turns
  1095.                 iOldX = iNewX
  1096.                 iOldY = iNewY
  1097.                 myPickle = [iOldX, iOldY]
  1098.                 serializedMyPickle = pickle.dumps(myPickle)
  1099.                 BugData.getTable("MY_TABLE").setData(serializedMyPickle)
  1100.                
  1101.  
  1102.             #Get rid of the HELD promotion when the stack reaches the target tile
  1103.             #This is still indented to be included within iGameTurn >5 and <20
  1104.             if iOldX == iTargetX and iOldY == iTargetY:
  1105.                 #cf.addUnit(gc.getInfoTypeForString('UNIT_HUNTER'))
  1106.                 for i in range(pTargetPlot.getNumUnits()):
  1107.                     pUnit = pTargetPlot.getUnit(i)
  1108.                     pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD'), False)
  1109.                    
  1110.             #iUnit = gc.getInfoTypeForString('UNIT_HUNTER')
  1111.             #cf.addUnit(gc.getInfoTypeForString('UNIT_HUNTER'))
  1112.                
  1113.  
  1114.  
  1115.                
  1116.  
  1117.         #Create a ritual on a particular turn and/or when the Stack of Doom reaches (iTargetX, iTargetY)
  1118.         #Push order: 1st BOOL to set it to make it forever; 2nd BOOL to replace current production; 3rd BOOL to put the new production on bottom of the queue; 4th BOOL to force the production even if you can't normally make it
  1119.  
  1120.         for iBaneCreatePlayer in range(gc.getMAX_PLAYERS()):
  1121.             pTargetPlayer = gc.getPlayer(iBaneCreatePlayer)
  1122.             if pTargetPlayer.isAlive():
  1123.                 if pTargetPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LUCHUIRP'):
  1124.                     #cf.addUnit(gc.getInfoTypeForString('UNIT_HUNTER'))
  1125.                     if not pTargetPlayer.isHuman():
  1126.                         for pyCity in PyPlayer(iBaneCreatePlayer).getCityList():
  1127.                             pTargetCity = pyCity.GetCy()
  1128.                             if pTargetCity.isCapital():
  1129.                                 #if iGameTurn == 3:
  1130.                                 #Load current (x,y) values of the Stack of Doom and then check if the stack is at the target tile
  1131.                                 serializedMyPickle = BugData.getTable("MY_TABLE").data
  1132.                                 myPickle = pickle.loads(serializedMyPickle)
  1133.                                 iOldX = myPickle[0]
  1134.                                 iOldY = myPickle[1]
  1135.                                 iTargetX = 60
  1136.                                 iTargetY = 20
  1137.                                 if iOldX == iTargetX and iOldY == iTargetY:                    
  1138.                                     #cf.addUnit(gc.getInfoTypeForString('UNIT_HUNTER'))
  1139.                                     if pTargetCity.canCreate(gc.getInfoTypeForString('PROJECT_BANE_DIVINE'), True, True):
  1140.                                         pTargetCity.pushOrder(OrderTypes.ORDER_CREATE, gc.getInfoTypeForString('PROJECT_BANE_DIVINE'), -1, False, True, False, False)
  1141.                                         pTargetCity.setProduction(10000)
  1142.                                         return 1
  1143.                        
  1144.                        
  1145.                        
  1146.            
  1147.         if not CyGame().isOption(gc.getInfoTypeForString('GAMEOPTION_NO_PLOT_COUNTER')):
  1148.             cf.doHellTerrain()
  1149.  
  1150.         if CyGame().getWBMapScript():
  1151.             sf.doTurn()
  1152.  
  1153. # FfH Card Game: begin
  1154.         cs.doTurn()
  1155. # FfH Card Game: end
  1156.  
  1157. #       if( CyGame().getAIAutoPlay(self) == 0 ) :
  1158.         if( game.getAIAutoPlay(game.getActivePlayer()) == 0 ) :
  1159.             CvTopCivs.CvTopCivs().turnChecker(iGameTurn)
  1160.  
  1161.     def onEndGameTurn(self, argsList):
  1162.         'Called at the end of the end of each turn'
  1163.         iGameTurn = argsList[0]
  1164.  
  1165.  
  1166.     def onBeginPlayerTurn(self, argsList):
  1167.         'Called at the beginning of a players turn'
  1168.         iGameTurn, iPlayer = argsList
  1169.         pPlayer = gc.getPlayer(iPlayer)
  1170.         player = PyPlayer(iPlayer)
  1171.  
  1172.         if not pPlayer.isHuman():
  1173.             if not CyGame().getWBMapScript():
  1174.                 cf.warScript(iPlayer)
  1175.  
  1176.         if pPlayer.getCivics(gc.getInfoTypeForString('CIVICOPTION_CULTURAL_VALUES')) == gc.getInfoTypeForString('CIVIC_CRUSADE'):
  1177.             cf.doCrusade(iPlayer)
  1178.  
  1179.         if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_KHAZAD'):
  1180.             cf.doTurnKhazad(iPlayer)
  1181.         elif pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LUCHUIRP'):
  1182.             cf.doTurnLuchuirp(iPlayer)
  1183.  
  1184.         if pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_INSANE')):
  1185.             if CyGame().getSorenRandNum(1000, "Insane") < 20:
  1186.                 iEvent = CvUtil.findInfoTypeNum(gc.getEventTriggerInfo, gc.getNumEventTriggerInfos(),'EVENTTRIGGER_TRAIT_INSANE')
  1187.                 triggerData = pPlayer.initTriggeredData(iEvent, true, -1, -1, -1, iPlayer, -1, -1, -1, -1, -1)
  1188.  
  1189.         if pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_ADAPTIVE')):
  1190.             iBaseCycle = 100
  1191.             iCycle = (iBaseCycle * gc.getGameSpeedInfo(CyGame().getGameSpeedType()).getVictoryDelayPercent()) / 100
  1192.  
  1193.             for i in range(10):
  1194.                 if (i * iCycle) - 5 == iGameTurn:
  1195.                     iEvent = CvUtil.findInfoTypeNum(gc.getEventTriggerInfo, gc.getNumEventTriggerInfos(),'EVENTTRIGGER_TRAIT_ADAPTIVE')
  1196.                     triggerData = pPlayer.initTriggeredData(iEvent, true, -1, -1, -1, iPlayer, -1, -1, -1, -1, -1)
  1197.  
  1198.         if pPlayer.isHuman():
  1199.             if pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_BARBARIAN')):
  1200.                 eTeam = gc.getTeam(gc.getPlayer(gc.getBARBARIAN_PLAYER()).getTeam())
  1201.                 iTeam = pPlayer.getTeam()
  1202.                 if eTeam.isAtWar(iTeam) == False:
  1203.                     if 2 * CyGame().getPlayerScore(iPlayer) >= 3 * CyGame().getPlayerScore(CyGame().getRankPlayer(1)):
  1204.                         if iGameTurn >= 20:
  1205.                             eTeam.declareWar(iTeam, false, WarPlanTypes.WARPLAN_TOTAL)
  1206.                             if iPlayer == CyGame().getActivePlayer():
  1207.                                 cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_BARBARIAN_DECLARE_WAR",()), 'art/interface/popups/Barbarian.dds')
  1208.  
  1209.  
  1210.     def onEndPlayerTurn(self, argsList):
  1211.         'Called at the end of a players turn'
  1212.         iGameTurn, iPlayer = argsList
  1213.  
  1214.         if (gc.getGame().getElapsedGameTurns() == 1):
  1215.             if (gc.getPlayer(iPlayer).isHuman()):
  1216.                 if (gc.getPlayer(iPlayer).canRevolution(0)):
  1217.                     popupInfo = CyPopupInfo()
  1218.                     popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_CHANGECIVIC)
  1219.                     popupInfo.addPopup(iPlayer)
  1220.  
  1221.         CvAdvisorUtils.resetAdvisorNags()
  1222.         CvAdvisorUtils.endTurnFeats(iPlayer)
  1223.  
  1224.  
  1225.     def onEndTurnReady(self, argsList):
  1226.         iGameTurn = argsList[0]
  1227.  
  1228.     def onFirstContact(self, argsList):
  1229.         'Contact'
  1230.         iTeamX,iHasMetTeamY = argsList
  1231.         if (not self.__LOG_CONTACT):
  1232.             return
  1233.         CvUtil.pyPrint('Team %d has met Team %d' %(iTeamX, iHasMetTeamY))
  1234.  
  1235.     def onCombatResult(self, argsList):
  1236.         'Combat Result'
  1237.         pWinner,pLoser = argsList
  1238.         playerX = PyPlayer(pWinner.getOwner())
  1239.         unitX = PyInfo.UnitInfo(pWinner.getUnitType())
  1240.         playerY = PyPlayer(pLoser.getOwner())
  1241.         unitY = PyInfo.UnitInfo(pLoser.getUnitType())
  1242.  
  1243. ## Advanced Tactics Start - ships and siege engines can be captured
  1244. ## adopted from mechaerik War Prize ModComp
  1245.         if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ADVANCED_TACTICS):
  1246.             pPlayer = gc.getPlayer(pWinner.getOwner())
  1247.             pPlayerLoser = gc.getPlayer(pLoser.getOwner())
  1248.             if (not pWinner.isHiddenNationality()):
  1249.                 if (pLoser.canMoveInto(pWinner.plot(), True, True, False)):
  1250.                     if (unitX.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_NAVAL")):
  1251.                         if (unitY.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_NAVAL")):
  1252.                             if CyGame().getSorenRandNum(100, "WarPrizes Naval") <= 25:
  1253.                                 iUnit = pLoser.getUnitType()
  1254.                                 newUnit = pPlayer.initUnit(pLoser.getUnitType(), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
  1255.                                 newUnit.finishMoves()
  1256.                                 newUnit.setDamage(75, pWinner.getOwner())
  1257.                                 if (pPlayer.isHuman()):
  1258.                                     CyInterface().addMessage(pWinner.getOwner(),false,20,CyTranslator().getText("TXT_KEY_WEHAVECAPTUREDSOMETHING",(pLoser.getName(),)),'',0,gc.getUnitInfo(newUnit.getUnitType()).getButton(),ColorTypes(gc.getInfoTypeForString("COLOR_GREEN")), pWinner.getX(), pWinner.getY(), True,True)
  1259.                                 elif (pPlayerLoser.isHuman()):
  1260.                                     CyInterface().addMessage(pLoser.getOwner(),false,20,CyTranslator().getText("TXT_KEY_WEHAVELOSTSOMETHING",(pLoser.getName(),)),'',0,gc.getUnitInfo(newUnit.getUnitType()).getButton(),ColorTypes(gc.getInfoTypeForString("COLOR_RED")), pLoser.getX(), pLoser.getY(), True,True)
  1261.                     if (unitY.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_SIEGE")):
  1262.                         if CyGame().getSorenRandNum(100, "WarPrizes Siege") <= 15:
  1263.                             iUnit = pLoser.getUnitType()
  1264.                             newUnit = pPlayer.initUnit(pLoser.getUnitType(), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
  1265.                             newUnit.finishMoves()
  1266.                             newUnit.setDamage(75, pWinner.getOwner())
  1267.                             if (pPlayer.isHuman()):
  1268.                                 CyInterface().addMessage(pWinner.getOwner(),false,20,CyTranslator().getText("TXT_KEY_MISC_WARPRIZES_SUCCESS",(pLoser.getName(),)),'',0,gc.getUnitInfo(newUnit.getUnitType()).getButton(),ColorTypes(gc.getInfoTypeForString("COLOR_GREEN")), pWinner.getX(), pWinner.getY(), True,True)
  1269.                             elif (pPlayerLoser.isHuman()):
  1270.                                 CyInterface().addMessage(pLoser.getOwner(),false,20,CyTranslator().getText("TXT_KEY_MISC_WARPRIZES_FAILURE",(pLoser.getName(),)),'',0,gc.getUnitInfo(newUnit.getUnitType()).getButton(),ColorTypes(gc.getInfoTypeForString("COLOR_RED")), pLoser.getX(), pLoser.getY(), True,True)
  1271. ## End Advanced Tactics
  1272.  
  1273.         if (not self.__LOG_COMBAT):
  1274.             return
  1275.         if playerX and playerX and unitX and playerY:
  1276.             CvUtil.pyPrint('Player %d Civilization %s Unit %s has defeated Player %d Civilization %s Unit %s'
  1277.                 %(playerX.getID(), playerX.getCivilizationName(), unitX.getDescription(),
  1278.                 playerY.getID(), playerY.getCivilizationName(), unitY.getDescription()))
  1279.  
  1280.     def onCombatLogCalc(self, argsList):
  1281.         'Combat Result'
  1282.         genericArgs = argsList[0][0]
  1283.         cdAttacker = genericArgs[0]
  1284.         cdDefender = genericArgs[1]
  1285.         iCombatOdds = genericArgs[2]
  1286.         CvUtil.combatMessageBuilder(cdAttacker, cdDefender, iCombatOdds)
  1287.  
  1288.     def onCombatLogHit(self, argsList):
  1289.         'Combat Message'
  1290.         global gCombatMessages, gCombatLog
  1291.         genericArgs = argsList[0][0]
  1292.         cdAttacker = genericArgs[0]
  1293.         cdDefender = genericArgs[1]
  1294.         iIsAttacker = genericArgs[2]
  1295.         iDamage = genericArgs[3]
  1296.  
  1297.         if cdDefender.eOwner == cdDefender.eVisualOwner:
  1298.             szDefenderName = gc.getPlayer(cdDefender.eOwner).getNameKey()
  1299.         else:
  1300.             szDefenderName = localText.getText("TXT_KEY_TRAIT_PLAYER_UNKNOWN", ())
  1301.         if cdAttacker.eOwner == cdAttacker.eVisualOwner:
  1302.             szAttackerName = gc.getPlayer(cdAttacker.eOwner).getNameKey()
  1303.         else:
  1304.             szAttackerName = localText.getText("TXT_KEY_TRAIT_PLAYER_UNKNOWN", ())
  1305.  
  1306.         if (iIsAttacker == 0):
  1307.             combatMessage = localText.getText("TXT_KEY_COMBAT_MESSAGE_HIT", (szDefenderName, cdDefender.sUnitName, iDamage, cdDefender.iCurrHitPoints, cdDefender.iMaxHitPoints))
  1308.             CyInterface().addCombatMessage(cdAttacker.eOwner,combatMessage)
  1309.             CyInterface().addCombatMessage(cdDefender.eOwner,combatMessage)
  1310.             if (cdDefender.iCurrHitPoints <= 0):
  1311.                 combatMessage = localText.getText("TXT_KEY_COMBAT_MESSAGE_DEFEATED", (szAttackerName, cdAttacker.sUnitName, szDefenderName, cdDefender.sUnitName))
  1312.                 CyInterface().addCombatMessage(cdAttacker.eOwner,combatMessage)
  1313.                 CyInterface().addCombatMessage(cdDefender.eOwner,combatMessage)
  1314.         elif (iIsAttacker == 1):
  1315.             combatMessage = localText.getText("TXT_KEY_COMBAT_MESSAGE_HIT", (szAttackerName, cdAttacker.sUnitName, iDamage, cdAttacker.iCurrHitPoints, cdAttacker.iMaxHitPoints))
  1316.             CyInterface().addCombatMessage(cdAttacker.eOwner,combatMessage)
  1317.             CyInterface().addCombatMessage(cdDefender.eOwner,combatMessage)
  1318.             if (cdAttacker.iCurrHitPoints <= 0):
  1319.                 combatMessage = localText.getText("TXT_KEY_COMBAT_MESSAGE_DEFEATED", (szDefenderName, cdDefender.sUnitName, szAttackerName, cdAttacker.sUnitName))
  1320.                 CyInterface().addCombatMessage(cdAttacker.eOwner,combatMessage)
  1321.                 CyInterface().addCombatMessage(cdDefender.eOwner,combatMessage)
  1322.  
  1323.     def onImprovementBuilt(self, argsList):
  1324.         'Improvement Built'
  1325.         iImprovement, iX, iY = argsList
  1326.         pPlot = CyMap().plot(iX, iY)
  1327.  
  1328.         if gc.getImprovementInfo(iImprovement).isUnique():
  1329.             CyEngine().addLandmark(pPlot, CvUtil.convertToStr(gc.getImprovementInfo(iImprovement).getDescription()))
  1330.  
  1331.             if iImprovement == gc.getInfoTypeForString('IMPROVEMENT_RING_OF_CARCER'):
  1332.                 pPlot.setMinLevel(15)
  1333.                 bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
  1334.                 bPlayer.initUnit(gc.getInfoTypeForString('UNIT_BRIGIT_HELD'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  1335.             elif iImprovement == gc.getInfoTypeForString('IMPROVEMENT_SEVEN_PINES'):
  1336.                 pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_GRASS'), True, True)
  1337.                 pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST'), 1)
  1338.  
  1339.         if (not self.__LOG_IMPROVEMENT):
  1340.             return
  1341.         CvUtil.pyPrint('Improvement %s was built at %d, %d'
  1342.             %(PyInfo.ImprovementInfo(iImprovement).getDescription(), iX, iY))
  1343.  
  1344.     def onImprovementDestroyed(self, argsList):
  1345.         'Improvement Destroyed'
  1346.         iImprovement, iOwner, iX, iY = argsList
  1347.  
  1348.         if gc.getImprovementInfo(iImprovement).isUnique():
  1349.             pPlot = CyMap().plot(iX, iY)
  1350.             CyEngine().removeLandmark(pPlot)
  1351.  
  1352.             if iImprovement == gc.getInfoTypeForString('IMPROVEMENT_RING_OF_CARCER'):
  1353.                 pPlot.setMinLevel(-1)
  1354.  
  1355.         if iImprovement == gc.getInfoTypeForString('IMPROVEMENT_NECROTOTEM'):
  1356.             CyGame().changeGlobalCounter(-2)
  1357.  
  1358.         if CyGame().getWBMapScript():
  1359.             sf.onImprovementDestroyed(iImprovement, iOwner, iX, iY)
  1360.  
  1361.         if (not self.__LOG_IMPROVEMENT):
  1362.             return
  1363.         CvUtil.pyPrint('Improvement %s was Destroyed at %d, %d'
  1364.             %(PyInfo.ImprovementInfo(iImprovement).getDescription(), iX, iY))
  1365.  
  1366.     def onRouteBuilt(self, argsList):
  1367.         'Route Built'
  1368.         iRoute, iX, iY = argsList
  1369.         if (not self.__LOG_IMPROVEMENT):
  1370.             return
  1371.         CvUtil.pyPrint('Route %s was built at %d, %d'
  1372.             %(gc.getRouteInfo(iRoute).getDescription(), iX, iY))
  1373.  
  1374.     def onPlotRevealed(self, argsList):
  1375.         'Plot Revealed'
  1376.         pPlot = argsList[0]
  1377.         iTeam = argsList[1]
  1378.  
  1379.     def onPlotFeatureRemoved(self, argsList):
  1380.         'Plot Revealed'
  1381.         pPlot = argsList[0]
  1382.         iFeatureType = argsList[1]
  1383.         pCity = argsList[2] # This can be null
  1384.  
  1385.     def onPlotPicked(self, argsList):
  1386.         'Plot Picked'
  1387.         pPlot = argsList[0]
  1388.         CvUtil.pyPrint('Plot was picked at %d, %d'
  1389.             %(pPlot.getX(), pPlot.getY()))
  1390.  
  1391.     def onNukeExplosion(self, argsList):
  1392.         'Nuke Explosion'
  1393.         pPlot, pNukeUnit = argsList
  1394.         CvUtil.pyPrint('Nuke detonated at %d, %d'
  1395.             %(pPlot.getX(), pPlot.getY()))
  1396.  
  1397.     def onGotoPlotSet(self, argsList):
  1398.         'Nuke Explosion'
  1399.         pPlot, iPlayer = argsList
  1400.  
  1401.     def onBuildingBuilt(self, argsList):
  1402.         'Building Completed'
  1403.         pCity, iBuildingType = argsList
  1404.         player = pCity.getOwner()
  1405.         pPlayer = gc.getPlayer(player)
  1406.         pPlot = pCity.plot()
  1407.         game = gc.getGame()
  1408.         iBuildingClass = gc.getBuildingInfo(iBuildingType).getBuildingClassType()
  1409.  
  1410.  
  1411.         if ((not gc.getGame().isNetworkMultiPlayer()) and (pCity.getOwner() == gc.getGame().getActivePlayer()) and isWorldWonderClass(iBuildingClass)):
  1412.             if gc.getBuildingInfo(iBuildingType).getMovie():
  1413.                 # If this is a wonder...
  1414.                 popupInfo = CyPopupInfo()
  1415.                 popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
  1416.                 popupInfo.setData1(iBuildingType)
  1417.                 popupInfo.setData2(pCity.getID())
  1418.                 popupInfo.setData3(0)
  1419.                 popupInfo.setText(u"showWonderMovie")
  1420.                 popupInfo.addPopup(pCity.getOwner())
  1421.  
  1422.         if iBuildingType == gc.getInfoTypeForString('BUILDING_INFERNAL_GRIMOIRE'):
  1423.             if CyGame().getSorenRandNum(100, "Bob") < 20:
  1424.                 pPlot2 = cf.findClearPlot(-1, pPlot)
  1425.                 if pPlot2 != -1:
  1426.                     bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
  1427.                     newUnit = bPlayer.initUnit(gc.getInfoTypeForString('UNIT_BALOR'), pPlot2.getX(), pPlot2.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  1428.                     CyInterface().addMessage(pCity.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_INFERNAL_GRIMOIRE_BALOR",()),'AS2D_BALOR',1,'Art/Interface/Buttons/Units/Balor.dds',ColorTypes(7),newUnit.getX(),newUnit.getY(),True,True)
  1429.                     if pCity.getOwner() == CyGame().getActivePlayer():
  1430.                         cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_INFERNAL_GRIMOIRE_BALOR",()), 'art/interface/popups/Balor.dds')
  1431.  
  1432.         elif iBuildingType == gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_FINAL'):
  1433.             pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_EXALTED'), 0)
  1434.         elif iBuildingType == gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_EXALTED'):
  1435.             pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_DIVINE'), 0)
  1436.         elif iBuildingType == gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_DIVINE'):
  1437.             pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_CONSECRATED'), 0)
  1438.         elif iBuildingType == gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_CONSECRATED'):
  1439.             pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_BLESSED'), 0)
  1440.         elif iBuildingType == gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_BLESSED'):
  1441.             pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_ANOINTED'), 0)
  1442.         elif iBuildingType == gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_ANOINTED'):
  1443.             pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR'), 0)
  1444.  
  1445.         elif iBuildingType == gc.getInfoTypeForString('BUILDING_MERCURIAN_GATE'):
  1446.             for iLoop in range(pPlot.getNumUnits(), -1, -1):
  1447.                 pUnit = pPlot.getUnit(iLoop)
  1448.                 pUnit.jumpToNearestValidPlot()
  1449.  
  1450.             iMercurianPlayer = pPlayer.initNewEmpire(gc.getInfoTypeForString('LEADER_BASIUM'), gc.getInfoTypeForString('CIVILIZATION_MERCURIANS'))
  1451.             if iMercurianPlayer != PlayerTypes.NO_PLAYER:
  1452.                 pMercurianPlayer = gc.getPlayer(iMercurianPlayer)
  1453.                 iTeam = pPlayer.getTeam()
  1454.                 iMercurianTeam = pMercurianPlayer.getTeam()
  1455.                 if iTeam < iMercurianTeam:
  1456.                     gc.getTeam(iTeam).addTeam(iMercurianTeam)
  1457.                 else:
  1458.                     gc.getTeam(iMercurianTeam).addTeam(iTeam)
  1459.  
  1460.                 pBasiumUnit = gc.getPlayer(iMercurianPlayer).initUnit(gc.getInfoTypeForString('UNIT_BASIUM'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  1461.                 pBasiumUnit.setAvatarOfCivLeader(True)
  1462.                 gc.getPlayer(iMercurianPlayer).initUnit(gc.getInfoTypeForString('UNIT_SETTLER'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  1463.                 gc.getPlayer(iMercurianPlayer).initUnit(gc.getInfoTypeForString('UNIT_ANGEL'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  1464.                 gc.getPlayer(iMercurianPlayer).initUnit(gc.getInfoTypeForString('UNIT_ANGEL'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  1465.                 gc.getPlayer(iMercurianPlayer).initUnit(gc.getInfoTypeForString('UNIT_ANGEL'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  1466.                 gc.getPlayer(iMercurianPlayer).initUnit(gc.getInfoTypeForString('UNIT_ANGEL'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  1467.                 gc.getPlayer(iMercurianPlayer).initUnit(gc.getInfoTypeForString('UNIT_ANGEL'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  1468.                 gc.getPlayer(iMercurianPlayer).initUnit(gc.getInfoTypeForString('UNIT_ANGEL'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  1469.                 gc.getPlayer(iMercurianPlayer).initUnit(gc.getInfoTypeForString('UNIT_WORKER'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  1470.  
  1471.                 if pPlayer.isHuman():
  1472.                     popupInfo = CyPopupInfo()
  1473.                     popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON)
  1474.                     popupInfo.setText(CyTranslator().getText("TXT_KEY_POPUP_CONTROL_MERCURIANS",()))
  1475.                     popupInfo.setData1(player)
  1476.                     popupInfo.setData2(iMercurianPlayer)
  1477.                     popupInfo.addPythonButton(CyTranslator().getText("TXT_KEY_POPUP_YES", ()), "")
  1478.                     popupInfo.addPythonButton(CyTranslator().getText("TXT_KEY_POPUP_NO", ()), "")
  1479.                     popupInfo.setOnClickedPythonCallback("reassignPlayer")
  1480.                     popupInfo.addPopup(player)
  1481.  
  1482.         elif iBuildingType == gc.getInfoTypeForString('BUILDING_TOWER_OF_THE_ELEMENTS'):
  1483.             lList = ['UNIT_AIR_ELEMENTAL', 'UNIT_EARTH_ELEMENTAL', 'UNIT_FIRE_ELEMENTAL', 'UNIT_WATER_ELEMENTAL']
  1484.             iUnit = gc.getInfoTypeForString(lList[CyGame().getSorenRandNum(len(lList), "Pick Elemental")-1])
  1485.             newUnit = pPlayer.initUnit(iUnit, pCity.getX(), pCity.getY(), UnitAITypes.UNITAI_CITY_DEFENSE, DirectionTypes.DIRECTION_SOUTH)
  1486.             newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD'), True)
  1487.             CyInterface().addMessage(player,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TOWER_OF_THE_ELEMENTS_SPAWN",()),'',1,gc.getUnitInfo(iUnit).getButton(),ColorTypes(8),pCity.getX(),pCity.getY(),True,True)
  1488.             iElemental = gc.getInfoTypeForString('PROMOTION_ELEMENTAL')
  1489.             iStrong = gc.getInfoTypeForString('PROMOTION_STRONG')
  1490.             apUnitList = PyPlayer(player).getUnitList()
  1491.             for pUnit in apUnitList:
  1492.                 if pUnit.isHasPromotion(iElemental):
  1493.                     pUnit.setHasPromotion(iStrong, True)
  1494.  
  1495.         elif iBuildingType == gc.getInfoTypeForString('BUILDING_TOWER_OF_NECROMANCY'):
  1496.             iUndead = gc.getInfoTypeForString('PROMOTION_UNDEAD')
  1497.             iStrong = gc.getInfoTypeForString('PROMOTION_STRONG')
  1498.             apUnitList = PyPlayer(player).getUnitList()
  1499.             for pUnit in apUnitList:
  1500.                 if pUnit.isHasPromotion(iUndead):
  1501.                     pUnit.setHasPromotion(iStrong, True)
  1502.  
  1503.         elif iBuildingType == gc.getInfoTypeForString('BUILDING_TEMPLE_OF_THE_HAND'):
  1504.             iSnow = gc.getInfoTypeForString('TERRAIN_SNOW')
  1505.             iFlames = gc.getInfoTypeForString('FEATURE_FLAMES')
  1506.             iFloodPlains = gc.getInfoTypeForString('FEATURE_FLOOD_PLAINS')
  1507.             iForest = gc.getInfoTypeForString('FEATURE_FOREST')
  1508.             iJungle = gc.getInfoTypeForString('FEATURE_JUNGLE')
  1509.             iScrub = gc.getInfoTypeForString('FEATURE_SCRUB')
  1510.             iSmoke = gc.getInfoTypeForString('IMPROVEMENT_SMOKE')
  1511.             iBlizzard = gc.getInfoTypeForString('FEATURE_BLIZZARD')
  1512.             iX = pCity.getX()
  1513.             iY = pCity.getY()
  1514.             for iiX in range(iX-2, iX+3, 1):
  1515.                 for iiY in range(iY-2, iY+3, 1):
  1516.                     pLoopPlot = CyMap().plot(iiX,iiY)
  1517.                     if not pLoopPlot.isNone():
  1518.                         if not pLoopPlot.isWater():
  1519.                             pLoopPlot.setTerrainType(iSnow, True, True)
  1520.                             if pLoopPlot.getImprovementType() == iSmoke:
  1521.                                 pLoopPlot.setImprovementType(-1)
  1522.                             iFeature = pLoopPlot.getFeatureType()
  1523.                             if iFeature == iForest:
  1524.                                 pLoopPlot.setFeatureType(iForest, 2)
  1525.                             if iFeature == iJungle:
  1526.                                 pLoopPlot.setFeatureType(iForest, 2)
  1527.                             if iFeature == iFlames:
  1528.                                 pLoopPlot.setFeatureType(-1, -1)
  1529.                             if iFeature == iFloodPlains:
  1530.                                 pLoopPlot.setFeatureType(-1, -1)
  1531.                             if iFeature == iScrub:
  1532.                                 pLoopPlot.setFeatureType(-1, -1)
  1533.                             if CyGame().getSorenRandNum(100, "Snowfall") < 2:
  1534.                                 pLoopPlot.setFeatureType(iBlizzard, -1)
  1535.             CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SNOWFALL'),pPlot.getPoint())
  1536.  
  1537.         elif iBuildingType == gc.getInfoTypeForString('BUILDING_GRAND_MENAGERIE'):
  1538.             if pPlayer.isHuman():
  1539.                 if not CyGame().getWBMapScript():
  1540.                     t = "TROPHY_FEAT_GRAND_MENAGERIE"
  1541.                     if not CyGame().isHasTrophy(t):
  1542.                         CyGame().changeTrophyValue(t, 1)
  1543.  
  1544.         CvAdvisorUtils.buildingBuiltFeats(pCity, iBuildingType)
  1545.  
  1546.         if (not self.__LOG_BUILDING):
  1547.             return
  1548.         CvUtil.pyPrint('%s was finished by Player %d Civilization %s'
  1549.             %(PyInfo.BuildingInfo(iBuildingType).getDescription(), pCity.getOwner(), gc.getPlayer(pCity.getOwner()).getCivilizationDescription(0)))
  1550.  
  1551.     def onProjectBuilt(self, argsList):
  1552.         'Project Completed'
  1553.         pCity, iProjectType = argsList
  1554.         game = gc.getGame()
  1555.         iPlayer = pCity.getOwner()
  1556.         pPlayer = gc.getPlayer(iPlayer)
  1557.         if ((not gc.getGame().isNetworkMultiPlayer()) and (pCity.getOwner() == gc.getGame().getActivePlayer())):
  1558.             popupInfo = CyPopupInfo()
  1559.             popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
  1560.             popupInfo.setData1(iProjectType)
  1561.             popupInfo.setData2(pCity.getID())
  1562.             popupInfo.setData3(2)
  1563.             popupInfo.setText(u"showWonderMovie")
  1564.             popupInfo.addPopup(iPlayer)
  1565.  
  1566.         if iProjectType == gc.getInfoTypeForString('PROJECT_BANE_DIVINE'):
  1567.             iCombatDisciple = gc.getInfoTypeForString('UNITCOMBAT_DISCIPLE')
  1568.             for iLoopPlayer in range(gc.getMAX_PLAYERS()):
  1569.                 pLoopPlayer = gc.getPlayer(iLoopPlayer)
  1570.                 if pLoopPlayer.isAlive() :
  1571.                     apUnitList = PyPlayer(iLoopPlayer).getUnitList()
  1572.                     for pUnit in apUnitList:
  1573.                         if pUnit.getUnitCombatType() == iCombatDisciple:
  1574.                             pUnit.kill(False, pCity.getOwner())
  1575.  
  1576.         elif iProjectType == gc.getInfoTypeForString('PROJECT_GENESIS'):
  1577.             if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_ILLIANS'):
  1578.                 cf.snowgenesis(iPlayer)
  1579.             else:
  1580.                 cf.genesis(iPlayer)
  1581.  
  1582.         elif iProjectType == gc.getInfoTypeForString('PROJECT_GLORY_EVERLASTING'):
  1583.             iDemon = gc.getInfoTypeForString('PROMOTION_DEMON')
  1584.             iUndead = gc.getInfoTypeForString('PROMOTION_UNDEAD')
  1585.             for iLoopPlayer in range(gc.getMAX_PLAYERS()):
  1586.                 pLoopPlayer = gc.getPlayer(iLoopPlayer)
  1587.                 player = PyPlayer(iLoopPlayer)
  1588.                 if pLoopPlayer.isAlive():
  1589.                     apUnitList = player.getUnitList()
  1590.                     for pUnit in apUnitList:
  1591.                         if (pUnit.isHasPromotion(iDemon) or pUnit.isHasPromotion(iUndead)):
  1592.                             pUnit.kill(False, iPlayer)
  1593.  
  1594.         elif iProjectType == gc.getInfoTypeForString('PROJECT_RITES_OF_OGHMA'):
  1595.             i = 7
  1596.             if CyMap().getWorldSize() == gc.getInfoTypeForString('WORLDSIZE_DUEL'):
  1597.                 i = i - 3
  1598.             if CyMap().getWorldSize() == gc.getInfoTypeForString('WORLDSIZE_TINY'):
  1599.                 i = i - 2
  1600.             if CyMap().getWorldSize() == gc.getInfoTypeForString('WORLDSIZE_SMALL'):
  1601.                 i = i - 1
  1602.             if CyMap().getWorldSize() == gc.getInfoTypeForString('WORLDSIZE_LARGE'):
  1603.                 i = i + 1
  1604.             if CyMap().getWorldSize() == gc.getInfoTypeForString('WORLDSIZE_HUGE'):
  1605.                 i = i + 3
  1606.             cf.addBonus('BONUS_MANA',i,'Art/Interface/Buttons/WorldBuilder/mana_button.dds')
  1607.  
  1608.         elif iProjectType == gc.getInfoTypeForString('PROJECT_NATURES_REVOLT'):
  1609.             bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
  1610.             py = PyPlayer(gc.getBARBARIAN_PLAYER())
  1611.             iAxeman = gc.getInfoTypeForString('UNITCLASS_AXEMAN')
  1612.             iBear = gc.getInfoTypeForString('UNIT_BEAR')
  1613.             iHeroicDefense = gc.getInfoTypeForString('PROMOTION_HEROIC_DEFENSE')
  1614.             iHeroicDefense2 = gc.getInfoTypeForString('PROMOTION_HEROIC_DEFENSE2')
  1615.             iHeroicStrength = gc.getInfoTypeForString('PROMOTION_HEROIC_STRENGTH')
  1616.             iHeroicStrength2 = gc.getInfoTypeForString('PROMOTION_HEROIC_STRENGTH2')
  1617.             iHunter = gc.getInfoTypeForString('UNITCLASS_HUNTER')
  1618.             iLion = gc.getInfoTypeForString('UNIT_LION')
  1619.             iScout = gc.getInfoTypeForString('UNITCLASS_SCOUT')
  1620.             iTiger = gc.getInfoTypeForString('UNIT_TIGER')
  1621.             iWarrior = gc.getInfoTypeForString('UNITCLASS_WARRIOR')
  1622.             iWolf = gc.getInfoTypeForString('UNIT_WOLF')
  1623.             iWorker = gc.getInfoTypeForString('UNITCLASS_WORKER')
  1624.             for pUnit in py.getUnitList():
  1625.                 bValid = False
  1626.                 if pUnit.getUnitClassType() == iWorker:
  1627.                     iNewUnit = iWolf
  1628.                     bValid = True
  1629.                 elif pUnit.getUnitClassType() == iScout:
  1630.                     iNewUnit = iLion
  1631.                     bValid = True
  1632.                 elif pUnit.getUnitClassType() == iWarrior:
  1633.                     iNewUnit = iLion
  1634.                     bValid = True
  1635.                 elif pUnit.getUnitClassType() == iHunter:
  1636.                     iNewUnit = iTiger
  1637.                     bValid = True
  1638.                 elif pUnit.getUnitClassType() == iAxeman:
  1639.                     iNewUnit = iBear
  1640.                     bValid = True
  1641.                 if bValid:
  1642.                     newUnit = bPlayer.initUnit(iNewUnit, pUnit.getX(), pUnit.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  1643.                     newUnit = bPlayer.initUnit(iNewUnit, pUnit.getX(), pUnit.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  1644.                     newUnit = bPlayer.initUnit(iNewUnit, pUnit.getX(), pUnit.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  1645.                     pUnit.kill(True, PlayerTypes.NO_PLAYER)
  1646.             for iLoopPlayer in range(gc.getMAX_PLAYERS()):
  1647.                 pLoopPlayer = gc.getPlayer(iLoopPlayer)
  1648.                 if pLoopPlayer.isAlive():
  1649.                     py = PyPlayer(iLoopPlayer)
  1650.                     for pUnit in py.getUnitList():
  1651.                         if pUnit.isAnimal():
  1652.                             pUnit.setHasPromotion(iHeroicDefense, True)
  1653.                             pUnit.setHasPromotion(iHeroicDefense2, True)
  1654.                             pUnit.setHasPromotion(iHeroicStrength, True)
  1655.                             pUnit.setHasPromotion(iHeroicStrength2, True)
  1656.  
  1657.         elif iProjectType == gc.getInfoTypeForString('PROJECT_BLOOD_OF_THE_PHOENIX'):
  1658.             py = PyPlayer(iPlayer)
  1659.             apUnitList = py.getUnitList()
  1660.             for pUnit in apUnitList:
  1661.                 if pUnit.isAlive():
  1662.                     if pUnit.getUnitCombatType() != UnitCombatTypes.NO_UNITCOMBAT:
  1663.                         pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_IMMORTAL'), True)
  1664.  
  1665.         elif iProjectType == gc.getInfoTypeForString('PROJECT_PURGE_THE_UNFAITHFUL'):
  1666.             for pyCity in PyPlayer(iPlayer).getCityList():
  1667.                 pCity2 = pyCity.GetCy()
  1668.                 iRnd = CyGame().getSorenRandNum(2, "Bob")
  1669.                 StateBelief = pPlayer.getStateReligion()
  1670.                 if StateBelief == gc.getInfoTypeForString('RELIGION_THE_ORDER'):
  1671.                     iRnd = iRnd - 1
  1672.                 for iTarget in range(gc.getNumReligionInfos()):
  1673.                     if (StateBelief != iTarget and pCity2.isHasReligion(iTarget) and pCity2.isHolyCityByType(iTarget) == False):
  1674.                         pCity2.setHasReligion(iTarget, False, True, True)
  1675.                         iRnd = iRnd + 1
  1676.                         for i in range(gc.getNumBuildingInfos()):
  1677.                             if gc.getBuildingInfo(i).getPrereqReligion() == iTarget:
  1678.                                 pCity2.setNumRealBuilding(i, 0)
  1679.                 if iRnd > 0:
  1680.                     pCity2.setOccupationTimer(iRnd)
  1681.  
  1682.         elif iProjectType == gc.getInfoTypeForString('PROJECT_BIRTHRIGHT_REGAINED'):
  1683.             pPlayer.setFeatAccomplished(FeatTypes.FEAT_GLOBAL_SPELL, False)
  1684.  
  1685.         elif iProjectType == gc.getInfoTypeForString('PROJECT_SAMHAIN'):
  1686.             for pyCity in PyPlayer(iPlayer).getCityList():
  1687.                 pCity = pyCity.GetCy()
  1688.                 pCity.changeHappinessTimer(20)
  1689.             iCount = CyGame().countCivPlayersAlive() + int(CyGame().getHandicapType()) - 5
  1690.             for i in range(iCount):
  1691.                 cf.addUnit(gc.getInfoTypeForString('UNIT_FROSTLING'))
  1692.                 cf.addUnit(gc.getInfoTypeForString('UNIT_FROSTLING'))
  1693.                 cf.addUnit(gc.getInfoTypeForString('UNIT_FROSTLING_ARCHER'))
  1694.                 cf.addUnit(gc.getInfoTypeForString('UNIT_FROSTLING_WOLF_RIDER'))
  1695.             cf.addUnit(gc.getInfoTypeForString('UNIT_MOKKA'))
  1696.  
  1697.         elif iProjectType == gc.getInfoTypeForString('PROJECT_THE_WHITE_HAND'):
  1698.             newUnit1 = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_PRIEST_OF_WINTER'), pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  1699.             newUnit1.setName("Dumannios")
  1700.             newUnit2 = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_PRIEST_OF_WINTER'), pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  1701.             newUnit2.setName("Riuros")
  1702.             newUnit3 = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_PRIEST_OF_WINTER'), pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  1703.             newUnit3.setName("Anagantios")
  1704.  
  1705.         elif iProjectType == gc.getInfoTypeForString('PROJECT_THE_DEEPENING'):
  1706.             iDesert = gc.getInfoTypeForString('TERRAIN_DESERT')
  1707.             iGrass = gc.getInfoTypeForString('TERRAIN_GRASS')
  1708.             iMarsh = gc.getInfoTypeForString('TERRAIN_MARSH')
  1709.             iPlains = gc.getInfoTypeForString('TERRAIN_PLAINS')
  1710.             iSnow = gc.getInfoTypeForString('TERRAIN_SNOW')
  1711.             iTundra = gc.getInfoTypeForString('TERRAIN_TUNDRA')
  1712.             iBlizzard = gc.getInfoTypeForString('FEATURE_BLIZZARD')
  1713.             iModifier = (gc.getGameSpeedInfo(CyGame().getGameSpeedType()).getVictoryDelayPercent() * 20) / 100
  1714.             iTimer = 40 + iModifier
  1715.             for i in range (CyMap().numPlots()):
  1716.                 pPlot = CyMap().plotByIndex(i)
  1717.                 bValid = False
  1718.                 if pPlot.isWater() == False:
  1719.                     if CyGame().getSorenRandNum(100, "The Deepening") < 25:
  1720.                         iTerrain = pPlot.getTerrainType()
  1721.                         chance = CyGame().getSorenRandNum(100, "Bob")
  1722.                         if iTerrain == iSnow:
  1723.                             bValid = True
  1724.                         elif iTerrain == iTundra:
  1725.                             pPlot.setTempTerrainType(iSnow, CyGame().getSorenRandNum(iTimer, "Bob") + 10)
  1726.                             bValid = True
  1727.                         elif iTerrain == iGrass or iTerrain == iMarsh:
  1728.                             if chance < 40:
  1729.                                 pPlot.setTempTerrainType(iSnow, CyGame().getSorenRandNum(iTimer, "Bob") + 10)
  1730.                             else:
  1731.                                 pPlot.setTempTerrainType(iTundra, CyGame().getSorenRandNum(iTimer, "Bob") + 10)
  1732.                             bValid = True
  1733.                         elif iTerrain == iPlains:
  1734.                             if chance < 60:
  1735.                                 pPlot.setTempTerrainType(iSnow, CyGame().getSorenRandNum(iTimer, "Bob") + 10)
  1736.                             else:
  1737.                                 pPlot.setTempTerrainType(iTundra, CyGame().getSorenRandNum(iTimer, "Bob") + 10)
  1738.                             bValid = True
  1739.                         elif iTerrain == iDesert:
  1740.                             if chance < 10:
  1741.                                 pPlot.setTempTerrainType(iSnow, CyGame().getSorenRandNum(iTimer, "Bob") + 10)
  1742.                             elif chance < 30:
  1743.                                 pPlot.setTempTerrainType(iTundra, CyGame().getSorenRandNum(iTimer, "Bob") + 10)
  1744.                             else:
  1745.                                 pPlot.setTempTerrainType(iPlains, CyGame().getSorenRandNum(iTimer, "Bob") + 10)
  1746.                         if bValid:
  1747.                             if CyGame().getSorenRandNum(750, "The Deepening") < 10:
  1748.                                 pPlot.setFeatureType(iBlizzard,-1)
  1749.  
  1750.         elif iProjectType == gc.getInfoTypeForString('PROJECT_STIR_FROM_SLUMBER'):
  1751.             pPlayer.initUnit(gc.getInfoTypeForString('UNIT_DRIFA'), pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  1752.  
  1753.         elif iProjectType == gc.getInfoTypeForString('PROJECT_THE_DRAW'):
  1754.             iTeam = pPlayer.getTeam()
  1755.             eTeam = gc.getTeam(iTeam)
  1756.             for iLoopPlayer in range(gc.getMAX_PLAYERS()):
  1757.                 pLoopPlayer = gc.getPlayer(iLoopPlayer)
  1758.                 if pLoopPlayer.isAlive() and pLoopPlayer.getTeam() == iTeam:
  1759.                     pLoopPlayer.changeNoDiplomacyWithEnemies(1)
  1760.             for iLoopTeam in range(gc.getMAX_TEAMS()):
  1761.                 if iLoopTeam != iTeam:
  1762.                     if iLoopTeam != gc.getPlayer(gc.getBARBARIAN_PLAYER()).getTeam():
  1763.                         eLoopTeam = gc.getTeam(iLoopTeam)
  1764.                         if eLoopTeam.isAlive():
  1765.                             if not eLoopTeam.isAVassal():
  1766.                                 eTeam.declareWar(iLoopTeam, false, WarPlanTypes.WARPLAN_LIMITED)
  1767.             py = PyPlayer(iPlayer)
  1768.             for pUnit in py.getUnitList():
  1769.                 iDmg = pUnit.getDamage() * 2
  1770.                 if iDmg > 99:
  1771.                     iDmg = 99
  1772.                 if iDmg < 50:
  1773.                     iDmg = 50
  1774.                 pUnit.setDamage(iDmg, iPlayer)
  1775.             for pyCity in PyPlayer(iPlayer).getCityList():
  1776.                 pLoopCity = pyCity.GetCy()
  1777.                 iPop = int(pLoopCity.getPopulation() / 2)
  1778.                 if iPop < 1:
  1779.                     iPop = 1
  1780.                 pLoopCity.setPopulation(iPop)
  1781.  
  1782.         elif iProjectType == gc.getInfoTypeForString('PROJECT_ASCENSION'):
  1783.             pAuricUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_AURIC_ASCENDED'), pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  1784.             pAuricUnit.setAvatarOfCivLeader(True)
  1785.             if pPlayer.isHuman():
  1786.                 t = "TROPHY_FEAT_ASCENSION"
  1787.                 if not CyGame().isHasTrophy(t):
  1788.                     CyGame().changeTrophyValue(t, 1)
  1789.             if not CyGame().getWBMapScript():
  1790.                 iBestPlayer = -1
  1791.                 iBestValue = 0
  1792.                 for iLoopPlayer in range(gc.getMAX_PLAYERS()):
  1793.                     pLoopPlayer = gc.getPlayer(iLoopPlayer)
  1794.                     if pLoopPlayer.isAlive():
  1795.                         if not pLoopPlayer.isBarbarian():
  1796.                             if pLoopPlayer.getTeam() != pPlayer.getTeam():
  1797.                                 iValue = CyGame().getSorenRandNum(500, "Ascension")
  1798.                                 if pLoopPlayer.isHuman():
  1799.                                     iValue += 2000
  1800.                                 iValue += (20 - CyGame().getPlayerRank(iLoopPlayer)) * 50
  1801.                                 if iValue > iBestValue:
  1802.                                     iBestValue = iValue
  1803.                                     iBestPlayer = iLoopPlayer
  1804.                 if iBestPlayer != -1:
  1805.                     pBestPlayer = gc.getPlayer(iBestPlayer)
  1806.                     pBestCity = pBestPlayer.getCapitalCity()
  1807.                     if pBestPlayer.isHuman():
  1808.                         iEvent = CvUtil.findInfoTypeNum(gc.getEventTriggerInfo, gc.getNumEventTriggerInfos(),'EVENTTRIGGER_GODSLAYER')
  1809.                         triggerData = gc.getPlayer(iBestPlayer).initTriggeredData(iEvent, true, -1, pBestCity.getX(), pBestCity.getY(), iBestPlayer, -1, -1, -1, -1, -1)
  1810.                     else:
  1811.                         pBestPlayer.initUnit(gc.getInfoTypeForString('EQUIPMENT_GODSLAYER'), pBestCity.getX(), pBestCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  1812.  
  1813.         elif iProjectType == gc.getInfoTypeForString('PROJECT_PACT_OF_THE_NILHORN'):
  1814.             newUnit1 = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_HILL_GIANT'), pCity.getX(), pCity.getY(), UnitAITypes.UNITAI_ATTACK, DirectionTypes.DIRECTION_NORTH)
  1815.             newUnit1.setName("Larry")
  1816.             newUnit1.AI_setGroupflag(10)
  1817.             newUnit1.setUnitAIType(gc.getInfoTypeForString('UNITAI_ATTACK_CITY'))
  1818.             newUnit2 = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_HILL_GIANT'), pCity.getX(), pCity.getY(), UnitAITypes.UNITAI_ATTACK, DirectionTypes.DIRECTION_NORTH)
  1819.             newUnit2.setName("Curly")
  1820.             newUnit2.AI_setGroupflag(10)
  1821.             newUnit2.setUnitAIType(gc.getInfoTypeForString('UNITAI_ATTACK_CITY'))
  1822.             newUnit3 = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_HILL_GIANT'), pCity.getX(), pCity.getY(), UnitAITypes.UNITAI_ATTACK, DirectionTypes.DIRECTION_NORTH)
  1823.             newUnit3.setName("Moe")
  1824.             newUnit3.AI_setGroupflag(10)
  1825.             newUnit3.setUnitAIType(gc.getInfoTypeForString('UNITAI_ATTACK_CITY'))
  1826.  
  1827. #some AI help
  1828.             if pPlayer.isHuman():
  1829.                 newUnit1.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY'), True)
  1830.                 newUnit2.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY'), True)
  1831.                 newUnit3.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY'), True)
  1832.  
  1833.  
  1834.  
  1835.     def onSelectionGroupPushMission(self, argsList):
  1836.         'selection group mission'
  1837.         eOwner = argsList[0]
  1838.         eMission = argsList[1]
  1839.         iNumUnits = argsList[2]
  1840.         listUnitIds = argsList[3]
  1841.  
  1842.         if (not self.__LOG_PUSH_MISSION):
  1843.             return
  1844.         if pHeadUnit:
  1845.             CvUtil.pyPrint("Selection Group pushed mission %d" %(eMission))
  1846.  
  1847.     def onUnitMove(self, argsList):
  1848.         'unit move'
  1849.         pPlot,pUnit,pOldPlot = argsList
  1850.         player = PyPlayer(pUnit.getOwner())
  1851.         unitInfo = PyInfo.UnitInfo(pUnit.getUnitType())
  1852.  
  1853.         if (not self.__LOG_MOVEMENT):
  1854.             return
  1855.         if player and unitInfo:
  1856.             CvUtil.pyPrint('Player %d Civilization %s unit %s is moving to %d, %d'
  1857.                 %(player.getID(), player.getCivilizationName(), unitInfo.getDescription(),
  1858.                 pUnit.getX(), pUnit.getY()))
  1859.  
  1860.     def onUnitSetXY(self, argsList):
  1861.         'units xy coords set manually'
  1862.         pPlot,pUnit = argsList
  1863.         player = PyPlayer(pUnit.getOwner())
  1864.         unitInfo = PyInfo.UnitInfo(pUnit.getUnitType())
  1865.         if (not self.__LOG_MOVEMENT):
  1866.             return
  1867.  
  1868.     def onUnitCreated(self, argsList):
  1869.         'Unit Completed'
  1870.         unit = argsList[0]
  1871.         player = PyPlayer(unit.getOwner())
  1872.         pPlayer = gc.getPlayer(unit.getOwner())
  1873.         iChanneling2 = gc.getInfoTypeForString('PROMOTION_CHANNELING2')
  1874.         iChanneling3 = gc.getInfoTypeForString('PROMOTION_CHANNELING3')
  1875.  
  1876.         if unit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ADEPT'):
  1877.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_AIR'))
  1878.             if iNum > 1:
  1879.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_AIR1'), True)
  1880.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1881.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_AIR2'), True)
  1882.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1883.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_AIR3'), True)
  1884.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_BODY'))
  1885.             if iNum > 1:
  1886.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BODY1'), True)
  1887.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1888.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BODY2'), True)
  1889.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1890.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BODY3'), True)
  1891.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_CHAOS'))
  1892.             if iNum > 1:
  1893.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHAOS1'), True)
  1894.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1895.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHAOS2'), True)
  1896.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1897.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHAOS3'), True)
  1898.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_DEATH'))
  1899.             if iNum > 1:
  1900.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH1'), True)
  1901.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1902.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH2'), True)
  1903.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1904.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH3'), True)
  1905.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_EARTH'))
  1906.             if iNum > 1:
  1907.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_EARTH1'), True)
  1908.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1909.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_EARTH2'), True)
  1910.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1911.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_EARTH3'), True)
  1912.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_ENCHANTMENT'))
  1913.             if iNum > 1:
  1914.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENCHANTMENT1'), True)
  1915.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1916.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENCHANTMENT2'), True)
  1917.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1918.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENCHANTMENT3'), True)
  1919.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_ENTROPY'))
  1920.             if iNum > 1:
  1921.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY1'), True)
  1922.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1923.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY2'), True)
  1924.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1925.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY3'), True)
  1926.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_FIRE'))
  1927.             if iNum > 1:
  1928.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_FIRE1'), True)
  1929.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1930.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_FIRE2'), True)
  1931.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1932.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_FIRE3'), True)
  1933.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_ICE'))
  1934.             if iNum > 1:
  1935.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ICE1'), True)
  1936.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1937.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ICE2'), True)
  1938.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1939.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ICE3'), True)
  1940.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_LAW'))
  1941.             if iNum > 1:
  1942.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LAW1'), True)
  1943.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1944.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LAW2'), True)
  1945.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1946.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LAW3'), True)
  1947.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_LIFE'))
  1948.             if iNum > 1:
  1949.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LIFE1'), True)
  1950.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1951.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LIFE2'), True)
  1952.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1953.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LIFE3'), True)
  1954.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_METAMAGIC'))
  1955.             if iNum > 1:
  1956.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_METAMAGIC1'), True)
  1957.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1958.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_METAMAGIC2'), True)
  1959.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1960.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_METAMAGIC3'), True)
  1961.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_MIND'))
  1962.             if iNum > 1:
  1963.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MIND1'), True)
  1964.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1965.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MIND2'), True)
  1966.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1967.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MIND3'), True)
  1968.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_NATURE'))
  1969.             if iNum > 1:
  1970.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_NATURE1'), True)
  1971.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1972.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_NATURE2'), True)
  1973.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1974.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_NATURE3'), True)
  1975.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_SHADOW'))
  1976.             if iNum > 1:
  1977.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOW1'), True)
  1978.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1979.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOW2'), True)
  1980.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1981.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOW3'), True)
  1982.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_SPIRIT'))
  1983.             if iNum > 1:
  1984.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SPIRIT1'), True)
  1985.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1986.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SPIRIT2'), True)
  1987.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1988.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SPIRIT3'), True)
  1989.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_SUN'))
  1990.             if iNum > 1:
  1991.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SUN1'), True)
  1992.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  1993.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SUN2'), True)
  1994.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  1995.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SUN3'), True)
  1996.             iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_WATER'))
  1997.             if iNum > 1:
  1998.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WATER1'), True)
  1999.                 if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
  2000.                     unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WATER2'), True)
  2001.                     if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
  2002.                         unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WATER3'), True)
  2003.  
  2004.         if unit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ELEMENTAL')):
  2005.             if pPlayer.getNumBuilding(gc.getInfoTypeForString('BUILDING_TOWER_OF_THE_ELEMENTS')) > 0:
  2006.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), True)
  2007.  
  2008.         if unit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_UNDEAD')):
  2009.             if pPlayer.getNumBuilding(gc.getInfoTypeForString('BUILDING_TOWER_OF_NECROMANCY')) > 0:
  2010.                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), True)
  2011.  
  2012. #UNITAI for Adepts and Terraformers
  2013.         if ((not pPlayer.isHuman()) and (not pPlayer.isBarbarian())):
  2014.             if unit.getUnitType() == gc.getInfoTypeForString('UNIT_DEVOUT'):
  2015.                 numberterraformer=0
  2016.                 for pUnit in player.getUnitList():
  2017.                     if pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_DEVOUT'):
  2018.                         if pUnit.getUnitAIType() == gc.getInfoTypeForString('UNITAI_TERRAFORMER'):
  2019.                             numberterraformer = numberterraformer+1
  2020.                 if  numberterraformer<(pPlayer.getNumCities()*CyGame().getGlobalCounter()/100):
  2021.                     unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_TERRAFORMER'))
  2022.                 elif numberterraformer<3:
  2023.                     unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_TERRAFORMER'))
  2024.  
  2025.             numTreeTerraformer=0
  2026.             if unit.getUnitType() == gc.getInfoTypeForString('UNIT_PRIEST_OF_LEAVES'):
  2027.                 neededTreeTerraformer = 1
  2028.                 if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LJOSALFAR') or pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_SVARTALFAR'):
  2029.                     neededTreeTerraformer = neededTreeTerraformer + (pPlayer.getNumCities() / 3)
  2030.                 for pUnit in player.getUnitList():
  2031.                     if pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_PRIEST_OF_LEAVES'):
  2032.                         if pUnit.getUnitAIType() == gc.getInfoTypeForString('UNITAI_TERRAFORMER'):
  2033.                             numTreeTerraformer = numTreeTerraformer+1
  2034.                 if numTreeTerraformer < neededTreeTerraformer:
  2035.                     unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_TERRAFORMER'))
  2036.  
  2037.             if unit.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_ADEPT'):
  2038.  
  2039.                 bCanMageTerraform = false
  2040.                 if pPlayer.countOwnedBonuses(gc.getInfoTypeForString('BONUS_MANA_WATER'), False) > 0:
  2041.                     bCanMageTerraform = true
  2042.                 elif pPlayer.countOwnedBonuses(gc.getInfoTypeForString('BONUS_MANA_SUN'), False) > 0:
  2043.                     bCanMageTerraform = true
  2044.  
  2045.                 numbermageterrafomer = (pPlayer.AI_getNumAIUnits(gc.getInfoTypeForString('UNITAI_TERRAFORMER')) - numTreeTerraformer)
  2046.                 numbermanaupgrade = pPlayer.AI_getNumAIUnits(gc.getInfoTypeForString('UNITAI_MANA_UPGRADE'))
  2047.  
  2048.                 bHasAI = false
  2049.                 canupgrademana = false
  2050.  
  2051.                 if pPlayer.isHasTech(gc.getInfoTypeForString('TECH_SORCERY')):
  2052.                     canupgrademana=true
  2053.                 elif pPlayer.isHasTech(gc.getInfoTypeForString('TECH_ALTERATION')):
  2054.                     canupgrademana=true
  2055.                 elif pPlayer.isHasTech(gc.getInfoTypeForString('TECH_DIVINATION')):
  2056.                     canupgrademana=true
  2057.                 elif pPlayer.isHasTech(gc.getInfoTypeForString('TECH_ELEMENTALISM')):
  2058.                     canupgrademana=true
  2059.                 elif pPlayer.isHasTech(gc.getInfoTypeForString('TECH_NECROMANCY')):
  2060.                     canupgrademana=true
  2061.  
  2062.  
  2063.                 if numbermanaupgrade == 0:
  2064.                     unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_MANA_UPGRADE'))
  2065.                     bHasAI = true
  2066.                 if canupgrademana:
  2067.                     if (pPlayer.countOwnedBonuses(gc.getInfoTypeForString('BONUS_MANA'), False) > (numbermanaupgrade * 2)):
  2068.                         unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_MANA_UPGRADE'))
  2069.                         bHasAI = true
  2070.  
  2071.                 if bHasAI == false:
  2072.                     if bCanMageTerraform:
  2073.                         if numbermageterrafomer < 2:
  2074.                             unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_TERRAFORMER'))
  2075.                             bHasAI = true
  2076.  
  2077.                 if bHasAI == false:
  2078.                     pPlot = unit.plot()
  2079.                     if (pPlayer.AI_getNumAIUnits(gc.getInfoTypeForString('UNITAI_MAGE')) < (pPlayer.getNumCities() / 2)):
  2080.                         unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_MAGE'))
  2081.                     elif pPlot.area().getAreaAIType(pPlayer.getTeam()) == AreaAITypes.AREAAI_DEFENSIVE:
  2082.                         unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_MAGE'))
  2083.                     else:
  2084.                         unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_WARWIZARD'))
  2085.  
  2086.  
  2087.  
  2088.         if CyGame().getWBMapScript():
  2089.             sf.onUnitCreated(unit)
  2090.  
  2091.         if (not self.__LOG_UNITBUILD):
  2092.             return
  2093.  
  2094.     def onUnitBuilt(self, argsList):
  2095.         'Unit Completed'
  2096.         city = argsList[0]
  2097.         unit = argsList[1]
  2098.         player = PyPlayer(city.getOwner())
  2099.         pPlayer = gc.getPlayer(unit.getOwner())
  2100.  
  2101.         # Advanced Tactics - Diverse Grigori (idea and base code taken from FFH Tweakmod)
  2102.         if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ADVANCED_TACTICS):
  2103.             if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_GRIGORI'):
  2104.                 unit.setReligion(-1)
  2105.                 if unit.getRace() == -1:
  2106.                     iChance = 40
  2107.                     if CyGame().getSorenRandNum(100, "Grigori Racial Diversity") <= iChance:
  2108.                         race = CyGame().getSorenRandNum(3, "Bob")
  2109.                         if race == 0 and unit.isAlive():
  2110.                             unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ORC'), True)
  2111.                         elif race == 1 and unit.isAlive():
  2112.                             race = CyGame().getSorenRandNum(2, "Elvish division")
  2113.                             if race == 0:
  2114.                                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ELF'), True)
  2115.                             elif race == 1:
  2116.                                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DARK_ELF'), True)
  2117.                         elif race == 2:
  2118.                             if (unit.isAlive()):
  2119.                                 unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DWARF'), True)
  2120.         # End Advanced Tactics
  2121.  
  2122.         if unit.getUnitType() == gc.getInfoTypeForString('UNIT_BEAST_OF_AGARES'):
  2123.             if city.getCivilizationType() != gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
  2124.                 iPop = city.getPopulation() - 4
  2125.                 if iPop <= 1:
  2126.                     iPop = 1
  2127.                 city.setPopulation(iPop)
  2128.                 city.setOccupationTimer(4)
  2129.  
  2130.         elif unit.getUnitType() == gc.getInfoTypeForString('UNIT_ACHERON'):
  2131.             unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD'), True)
  2132.             city.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_THE_DRAGONS_HORDE'), 1)
  2133.             iX = city.getX()
  2134.             iY = city.getY()
  2135.             for iiX in range(iX-1, iX+2, 1):
  2136.                 for iiY in range(iY-1, iY+2, 1):
  2137.                     pPlot = CyMap().plot(iiX,iiY)
  2138.                     if (pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_JUNGLE')):
  2139.                         pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FLAMES'), 0)
  2140.             if( game.getAIAutoPlay(game.getActivePlayer()) == 0 ) :
  2141.                 cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_ACHERON_CREATION",()), str(gc.getUnitInfo(unit.getUnitType()).getImage()))
  2142.  
  2143.         if city.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_WARRENS')) > 0:
  2144.             if isWorldUnitClass(unit.getUnitClassType()) == False:
  2145.                 if isNationalUnitClass(unit.getUnitClassType()) == False:
  2146.                     if not unit.isMechUnit():
  2147. #                       if unit.getUnitCombatType() != UnitCombatTypes.NO_UNITCOMBAT:
  2148.                         if unit.isAlive():
  2149.                             newUnit = pPlayer.initUnit(unit.getUnitType(), city.getX(), city.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  2150.                             city.applyBuildEffects(newUnit)
  2151.  
  2152.         CvAdvisorUtils.unitBuiltFeats(city, unit)
  2153.  
  2154.         if (not self.__LOG_UNITBUILD):
  2155.             return
  2156.         CvUtil.pyPrint('%s was finished by Player %d Civilization %s'
  2157.             %(PyInfo.UnitInfo(unit.getUnitType()).getDescription(), player.getID(), player.getCivilizationName()))
  2158.  
  2159.     def onUnitKilled(self, argsList):
  2160.         'Unit Killed'
  2161.         unit, iAttacker = argsList
  2162.         iPlayer = unit.getOwner()
  2163.         player = PyPlayer(iPlayer)
  2164.         attacker = PyPlayer(iAttacker)
  2165.         pPlayer = gc.getPlayer(iPlayer)
  2166.         iX = unit.getX()
  2167.         iY = unit.getY()
  2168.         pPlot = CyMap().plot(iX,iY)
  2169.  
  2170.         if (unit.isAlive() and unit.isImmortal() == False):
  2171.             iSoulForge = gc.getInfoTypeForString('BUILDING_SOUL_FORGE')
  2172.             if gc.getGame().getBuildingClassCreatedCount(gc.getInfoTypeForString("BUILDINGCLASS_SOUL_FORGE")) > 0:
  2173.                 for iiX in range(iX-1, iX+2, 1):
  2174.                     for iiY in range(iY-1, iY+2, 1):
  2175.                         pPlot2 = CyMap().plot(iiX,iiY)
  2176.                         if pPlot2.isCity():
  2177.                             pCity = pPlot2.getPlotCity()
  2178.                             if pCity.getNumRealBuilding(iSoulForge) > 0:
  2179.                                 pCity.changeProduction(unit.getExperience() + 10)
  2180.                                 CyInterface().addMessage(pCity.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_SOUL_FORGE",()),'AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/Buildings/Soulforge.dds',ColorTypes(7),pCity.getX(),pCity.getY(),True,True)
  2181.                
  2182.             if pPlot.isCity():
  2183.                 pCity = pPlot.getPlotCity()
  2184.                 if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_MOKKAS_CAULDRON')) > 0:
  2185.                     if pCity.getOwner() == unit.getOwner():
  2186.                         iUnit = cf.getUnholyVersion(unit)
  2187.                         if iUnit != -1:
  2188.                             newUnit = pPlayer.initUnit(iUnit, pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  2189.                             newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON'), True)
  2190.                             newUnit.setDamage(50, PlayerTypes.NO_PLAYER)
  2191.                             newUnit.finishMoves()
  2192.                             szBuffer = gc.getUnitInfo(newUnit.getUnitType()).getDescription()
  2193.                             CyInterface().addMessage(unit.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_MOKKAS_CAULDRON",((szBuffer, ))),'AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/Buildings/Mokkas Cauldron.dds',ColorTypes(7),pCity.getX(),pCity.getY(),True,True)
  2194.  
  2195.             if (unit.getReligion() == gc.getInfoTypeForString('RELIGION_COUNCIL_OF_ESUS') or unit.getReligion() == gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL') or unit.getReligion() == gc.getInfoTypeForString('RELIGION_OCTOPUS_OVERLORDS') or unit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH1')) or unit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY1'))):
  2196.                 cf.giftUnit(gc.getInfoTypeForString('UNIT_MANES'), gc.getInfoTypeForString('CIVILIZATION_INFERNAL'), 0, unit.plot(), unit.getOwner())
  2197.                 cf.giftUnit(gc.getInfoTypeForString('UNIT_MANES'), gc.getInfoTypeForString('CIVILIZATION_INFERNAL'), 0, unit.plot(), unit.getOwner())
  2198.             elif (unit.getReligion() == gc.getInfoTypeForString('RELIGION_THE_EMPYREAN') or unit.getReligion() == gc.getInfoTypeForString('RELIGION_THE_ORDER') or unit.getReligion() == gc.getInfoTypeForString('RELIGION_RUNES_OF_KILMORPH') or (unit.getUnitCombatType() != gc.getInfoTypeForString('UNITCOMBAT_ANIMAL') and pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_MERCURIANS'))):
  2199.                 cf.giftUnit(gc.getInfoTypeForString('UNIT_ANGEL'), gc.getInfoTypeForString('CIVILIZATION_MERCURIANS'), unit.getExperience(), unit.plot(), unit.getOwner())
  2200.  
  2201.             if unit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SPIRIT_GUIDE')):
  2202.                 if unit.getExperience() > 0:
  2203.                     py = PyPlayer(iPlayer)
  2204.                     lUnits = []
  2205.                     for pLoopUnit in py.getUnitList():
  2206.                         if pLoopUnit.isAlive():
  2207.                             if not pLoopUnit.isOnlyDefensive():
  2208.                                 if not pLoopUnit.isDelayedDeath():
  2209.                                     lUnits.append(pLoopUnit)
  2210.                     if len(lUnits) > 0:
  2211.                         pUnit = lUnits[CyGame().getSorenRandNum(len(lUnits), "Spirit Guide")-1]
  2212.                         iXP = unit.getExperience() / 2
  2213.                         pUnit.changeExperience(iXP, -1, false, false, false)
  2214. #                       unit.changeExperience(iXP * -1, -1, false, false, false)
  2215.                         CyInterface().addMessage(unit.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_SPIRIT_GUIDE",()),'AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/Promotions/SpiritGuide.dds',ColorTypes(7),pUnit.getX(),pUnit.getY(),True,True)
  2216.  
  2217.         if unit.getUnitType() == gc.getInfoTypeForString('UNIT_ACHERON'):
  2218.             unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD'), False)
  2219.  
  2220.         if CyGame().getWBMapScript():
  2221.             sf.onUnitKilled(unit, iAttacker)
  2222.  
  2223. #       if (not self.__LOG_UNITKILLED):
  2224. #           return
  2225. #       CvUtil.pyPrint('Player %d Civilization %s Unit %s was killed by Player %d'
  2226. #           %(player.getID(), player.getCivilizationName(), PyInfo.UnitInfo(unit.getUnitType()).getDescription(), attacker.getID()))
  2227.  
  2228.     def onUnitLost(self, argsList):
  2229.         'Unit Lost'
  2230.         unit = argsList[0]
  2231.         pPlayer = unit.getOwner()
  2232.         player = PyPlayer(unit.getOwner())
  2233.         pPlot = unit.plot()
  2234.  
  2235.         if unit.getUnitType() == gc.getInfoTypeForString('UNIT_TREANT'):
  2236.             if pPlot.getFeatureType() == -1:
  2237.                 if pPlot.canHaveFeature(gc.getInfoTypeForString('FEATURE_FOREST_NEW')):
  2238.                     if pPlot.getOwner() == pPlayer:
  2239.                         if CyGame().getSorenRandNum(100, "Treant Spawn Chance") < 50:
  2240.                             pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST_NEW'), 0)
  2241.  
  2242.         if (not self.__LOG_UNITLOST):
  2243.             return
  2244.         CvUtil.pyPrint('%s was lost by Player %d Civilization %s'
  2245.             %(PyInfo.UnitInfo(unit.getUnitType()).getDescription(), player.getID(), player.getCivilizationName()))
  2246.  
  2247.     def onUnitPromoted(self, argsList):
  2248.         'Unit Promoted'
  2249.         pUnit, iPromotion = argsList
  2250.         player = PyPlayer(pUnit.getOwner())
  2251.         if (not self.__LOG_UNITPROMOTED):
  2252.             return
  2253.         CvUtil.pyPrint('Unit Promotion Event: %s - %s' %(player.getCivilizationName(), pUnit.getName(),))
  2254.  
  2255.     def onUnitSelected(self, argsList):
  2256.         'Unit Selected'
  2257.         unit = argsList[0]
  2258.         player = PyPlayer(unit.getOwner())
  2259.         if (not self.__LOG_UNITSELECTED):
  2260.             return
  2261.         CvUtil.pyPrint('%s was selected by Player %d Civilization %s'
  2262.             %(PyInfo.UnitInfo(unit.getUnitType()).getDescription(), player.getID(), player.getCivilizationName()))
  2263.  
  2264.     def onUnitRename(self, argsList):
  2265.         'Unit is renamed'
  2266.         pUnit = argsList[0]
  2267.         if (pUnit.getOwner() == gc.getGame().getActivePlayer()):
  2268.             self.__eventEditUnitNameBegin(pUnit)
  2269.  
  2270.     def onUnitPillage(self, argsList):
  2271.         'Unit pillages a plot'
  2272.         pUnit, iImprovement, iRoute, iOwner = argsList
  2273.         iPlotX = pUnit.getX()
  2274.         iPlotY = pUnit.getY()
  2275.         pPlot = CyMap().plot(iPlotX, iPlotY)
  2276.         pPlayer = gc.getPlayer(pUnit.getOwner())
  2277.  
  2278.         if (not self.__LOG_UNITPILLAGE):
  2279.             return
  2280.         CvUtil.pyPrint("Player %d's %s pillaged improvement %d and route %d at plot at (%d, %d)"
  2281.             %(iOwner, PyInfo.UnitInfo(pUnit.getUnitType()).getDescription(), iImprovement, iRoute, iPlotX, iPlotY))
  2282.  
  2283.     def onUnitSpreadReligionAttempt(self, argsList):
  2284.         'Unit tries to spread religion to a city'
  2285.         pUnit, iReligion, bSuccess = argsList
  2286.  
  2287.         iX = pUnit.getX()
  2288.         iY = pUnit.getY()
  2289.         pPlot = CyMap().plot(iX, iY)
  2290.         pCity = pPlot.getPlotCity()
  2291.  
  2292.     def onUnitGifted(self, argsList):
  2293.         'Unit is gifted from one player to another'
  2294.         pUnit, iGiftingPlayer, pPlotLocation = argsList
  2295.  
  2296.     def onUnitBuildImprovement(self, argsList):
  2297.         'Unit begins enacting a Build (building an Improvement or Route)'
  2298.         pUnit, iBuild, bFinished = argsList
  2299.  
  2300.     def onGoodyReceived(self, argsList):
  2301.         'Goody received'
  2302.         iPlayer, pPlot, pUnit, iGoodyType = argsList
  2303.         if (not self.__LOG_GOODYRECEIVED):
  2304.             return
  2305.         CvUtil.pyPrint('%s received a goody' %(gc.getPlayer(iPlayer).getCivilizationDescription(0)),)
  2306.  
  2307.     def onGreatPersonBorn(self, argsList):
  2308.         'Unit Promoted'
  2309.         pUnit, iPlayer, pCity = argsList
  2310.         player = PyPlayer(iPlayer)
  2311.         if pUnit.isNone() or pCity.isNone():
  2312.             return
  2313.         if (not self.__LOG_GREATPERSON):
  2314.             return
  2315.         CvUtil.pyPrint('A %s was born for %s in %s' %(pUnit.getName(), player.getCivilizationName(), pCity.getName()))
  2316.  
  2317.     def onTechAcquired(self, argsList):
  2318.         'Tech Acquired'
  2319.         iTechType, iTeam, iPlayer, bAnnounce = argsList
  2320.         # Note that iPlayer may be NULL (-1) and not a refer to a player object
  2321.         pPlayer = gc.getPlayer(iPlayer)
  2322.  
  2323.         # Show tech splash when applicable
  2324.         if (iPlayer > -1 and bAnnounce and not CyInterface().noTechSplash()):
  2325.             if (gc.getGame().isFinalInitialized() and not gc.getGame().GetWorldBuilderMode()):
  2326.                 if ((not gc.getGame().isNetworkMultiPlayer()) and (iPlayer == gc.getGame().getActivePlayer())):
  2327.                     popupInfo = CyPopupInfo()
  2328.                     popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
  2329.                     popupInfo.setData1(iTechType)
  2330.                     popupInfo.setText(u"showTechSplash")
  2331.                     popupInfo.addPopup(iPlayer)
  2332.  
  2333.         if (iPlayer != -1 and iPlayer != gc.getBARBARIAN_PLAYER()):
  2334.             pPlayer = gc.getPlayer(iPlayer)
  2335.             iReligion = -1
  2336.             if iTechType == gc.getInfoTypeForString('TECH_CORRUPTION_OF_SPIRIT'):
  2337.                 iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_THE_ASHEN_VEIL')
  2338.                 iReligion = gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL')
  2339.             elif iTechType == gc.getInfoTypeForString('TECH_ORDERS_FROM_HEAVEN'):
  2340.                 iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_THE_ORDER')
  2341.                 iReligion = gc.getInfoTypeForString('RELIGION_THE_ORDER')
  2342.             elif iTechType == gc.getInfoTypeForString('TECH_WAY_OF_THE_FORESTS'):
  2343.                 iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_FELLOWSHIP_OF_LEAVES')
  2344.                 iReligion = gc.getInfoTypeForString('RELIGION_FELLOWSHIP_OF_LEAVES')
  2345.             elif iTechType == gc.getInfoTypeForString('TECH_WAY_OF_THE_EARTHMOTHER'):
  2346.                 iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_RUNES_OF_KILMORPH')
  2347.                 iReligion = gc.getInfoTypeForString('RELIGION_RUNES_OF_KILMORPH')
  2348.             elif iTechType == gc.getInfoTypeForString('TECH_MESSAGE_FROM_THE_DEEP'):
  2349.                 iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_OCTOPUS_OVERLORDS')
  2350.                 iReligion = gc.getInfoTypeForString('RELIGION_OCTOPUS_OVERLORDS')
  2351.             elif iTechType == gc.getInfoTypeForString('TECH_HONOR'):
  2352.                 iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_EMPYREAN')
  2353.                 iReligion = gc.getInfoTypeForString('RELIGION_THE_EMPYREAN')
  2354.             elif iTechType == gc.getInfoTypeForString('TECH_DECEPTION'):
  2355.                 iUnit = gc.getInfoTypeForString('UNIT_NIGHTWATCH')
  2356.                 iReligion = gc.getInfoTypeForString('RELIGION_COUNCIL_OF_ESUS')
  2357.             elif iReligion != -1:
  2358.                 if (iReligion==pPlayer.getFavoriteReligion()):
  2359.                     pPlayer.getCapitalCity().setHasReligion(iReligion,True,True,True)  
  2360.                 if CyGame().isReligionFounded(iReligion):
  2361.                     cf.giftUnit(iUnit, pPlayer.getCivilizationType(), 0, -1, -1)
  2362.  
  2363.         if not gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_HYBOREM_OR_BASIUM):
  2364.             if (iTechType == gc.getInfoTypeForString('TECH_INFERNAL_PACT') and iPlayer != -1):
  2365.                 #iCount = 0
  2366.                 #for iTeam in range(gc.getMAX_TEAMS()):
  2367.                     #pTeam = gc.getTeam(iTeam)
  2368.                     #if pTeam.isHasTech(gc.getInfoTypeForString('TECH_INFERNAL_PACT')):
  2369.                         #iCount = iCount + 1
  2370.                 #if iCount == 1:
  2371.                 if not CyGame().isCivEverActive(gc.getInfoTypeForString('CIVILIZATION_INFERNAL')):
  2372.                     iInfernalPlayer = pPlayer.initNewEmpire(gc.getInfoTypeForString('LEADER_HYBOREM'), gc.getInfoTypeForString('CIVILIZATION_INFERNAL'))
  2373.                     if iInfernalPlayer != PlayerTypes.NO_PLAYER:
  2374.                         pInfernalPlayer = gc.getPlayer(iInfernalPlayer)
  2375.                         pTeam = gc.getTeam(pInfernalPlayer.getTeam())
  2376.  
  2377.                         pBestPlot = -1
  2378.                         iBestPlot = -1
  2379.                         for iLoop in range (CyMap().numPlots()):
  2380.                             pPlot = CyMap().plotByIndex(iLoop)
  2381.                             iX = pPlot.getX()
  2382.                             iY = pPlot.getY()
  2383.                             iPlot = -1
  2384.                             if pInfernalPlayer.canFound(iX, iY):
  2385.                                 if pPlot.getNumUnits() == 0:
  2386.                                     iPlot = CyGame().getSorenRandNum(50, "Place Hyborem")
  2387.                                     iPlot += 50
  2388.                                     iPlot += pPlot.area().getNumTiles() * 2
  2389.                                     iPlot += pPlot.area().getNumUnownedTiles() * 10
  2390.  
  2391.                                     ## Check Big Fat Cross for other players, resources and terrain
  2392.                                     for iCityPlotX in range(iX-1, iX+2, 1):
  2393.                                         for iCityPlotY in range(iY-1, iY+2, 1):
  2394.                                             pCityPlot = CyMap().plot(iCityPlotX,iCityPlotY)
  2395.                                             iCityTerrain = pCityPlot.getTerrainType()
  2396.                                             iCityPlot = pCityPlot.getPlotType()
  2397.                                             iCityBonus = pCityPlot.getBonusType(TeamTypes.NO_TEAM)
  2398.  
  2399.                                             for jPlayer in range(gc.getMAX_PLAYERS()):
  2400.                                                 lPlayer = gc.getPlayer(jPlayer)
  2401.                                                 if lPlayer.isAlive():
  2402.                                                     if pCityPlot.getCulture(jPlayer) > 100:
  2403.                                                         iPlot -= 250
  2404.                                             if pPlot.isAdjacentOwned():
  2405.                                                 iPlot -= 25
  2406.                                             else:
  2407.                                                 iPlot += 15
  2408.                                             if (iCityTerrain == gc.getInfoTypeForString('TERRAIN_SNOW')) or (iCityTerrain == gc.getInfoTypeForString("TERRAIN_DESERT")):
  2409.                                                 iPlot -= 25
  2410.                                             elif (iCityTerrain == gc.getInfoTypeForString('TERRAIN_TUNDRA')):
  2411.                                                 iPlot -= 10
  2412.                                             if (pCityPlot.isWater()):
  2413.                                                 iPlot -= 25
  2414.                                             elif not iCityBonus == BonusTypes.NO_BONUS:
  2415.                                                 iPlot += gc.getBonusInfo(iCityBonus).getYieldChange(YieldTypes.YIELD_PRODUCTION) * 25
  2416.                                                 iPlot += gc.getBonusInfo(iCityBonus).getYieldChange(YieldTypes.YIELD_COMMERCE) * 15
  2417.  
  2418.                             if iPlot > iBestPlot:
  2419.                                 iBestPlot = iPlot
  2420.                                 pBestPlot = pPlot
  2421.  
  2422.                         if pBestPlot != -1:
  2423.                             iFounderTeam = gc.getPlayer(iPlayer).getTeam()
  2424.                             pFounderTeam = gc.getTeam(gc.getPlayer(iPlayer).getTeam())
  2425.                             iInfernalTeam = gc.getPlayer(iInfernalPlayer).getTeam()
  2426.                             pInfernalTeam = gc.getTeam(iInfernalTeam)
  2427.  
  2428.                             iBarbTeam = gc.getBARBARIAN_TEAM()
  2429.                             pInfernalTeam.makePeace(iBarbTeam)
  2430.                             pInfernalPlayer.AI_changeAttitudeExtra(iPlayer, 4)
  2431.  
  2432.                             iX = pBestPlot.getX()
  2433.                             iY = pBestPlot.getY()
  2434.                             pNewUnit = pInfernalPlayer.initUnit(gc.getInfoTypeForString('UNIT_HYBOREM'), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  2435.                             pNewUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_IMMORTAL'), True)
  2436.                             pNewUnit.setHasCasted(True)
  2437.                             pNewUnit.setAvatarOfCivLeader(True)
  2438.                             iIronWeapon     = gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS')
  2439.                             iMobility1      = gc.getInfoTypeForString('PROMOTION_MOBILITY1')
  2440.                             iSettlerBonus   = gc.getInfoTypeForString('PROMOTION_STARTING_SETTLER')
  2441.                             liStartingUnits = [ (2, gc.getInfoTypeForString('UNIT_LONGBOWMAN'), [iMobility1]                ),
  2442.                                                 (2, gc.getInfoTypeForString('UNIT_CHAMPION'),   [iMobility1, iIronWeapon]   ),
  2443.                                                 (1, gc.getInfoTypeForString('UNIT_WORKER'),     []                          ),
  2444.                                                 (1, gc.getInfoTypeForString('UNIT_IMP'),        [iMobility1]                ),
  2445.                                                 (3, gc.getInfoTypeForString('UNIT_MANES'),      []                          ),
  2446.                                                 (2, gc.getInfoTypeForString('UNIT_SETTLER'),    [iSettlerBonus]             )   ]
  2447.                             for iNumUnits, iUnit, liPromotions in liStartingUnits:
  2448.                                 for iLoop in range(iNumUnits):
  2449.                                     pNewUnit = pInfernalPlayer.initUnit(iUnit, iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  2450.                                     for iPromotion in liPromotions:
  2451.                                         pNewUnit.setHasPromotion(iPromotion, True)
  2452.  
  2453.                             if (game.isOption(GameOptionTypes.GAMEOPTION_ADVANCED_TACTICS)):
  2454.                                 pFounderTeam.setHasEmbassy(iInfernalTeam, True)
  2455.                                 pInfernalTeam.setHasEmbassy(iFounderTeam, True)
  2456.  
  2457.                             pFounderTeam.signOpenBorders(iInfernalTeam)
  2458.                             pInfernalTeam.signOpenBorders(iFounderTeam)
  2459.                             for iPlotIndex in range(CyMap().numPlots()):
  2460.                                 pLoopPlot = CyMap().plotByIndex(iPlotIndex)
  2461.                                 if pLoopPlot.isRevealed(iFounderTeam, False):
  2462.                                     pLoopPlot.setRevealed(iInfernalTeam, True, False, iFounderTeam)
  2463.                                 if pLoopPlot.isRevealed(iInfernalTeam, False):
  2464.                                     pLoopPlot.setRevealed(iFounderTeam, True, False, iInfernalTeam)
  2465.                             for iLoopTeam in range(gc.getMAX_CIV_TEAMS()):
  2466.                                 pLoopTeam = gc.getTeam(iLoopTeam)
  2467.                                 if pLoopTeam.isHasMet(iFounderTeam):
  2468.                                     if pLoopTeam.isAlive():
  2469.                                         pLoopTeam.meet(iInfernalTeam, True)
  2470.                             for iTeam in range(gc.getMAX_TEAMS()):
  2471.                                 if iTeam != iBarbTeam:
  2472.                                     pTeam = gc.getTeam(iTeam)
  2473.                                     if pTeam.isAlive():
  2474.                                         if pFounderTeam.isAtWar(iTeam):
  2475.                                             pInfernalTeam.declareWar(iTeam, False, WarPlanTypes.WARPLAN_LIMITED)
  2476.  
  2477.                             if gc.getPlayer(iPlayer).isHuman():
  2478.                                 popupInfo = CyPopupInfo()
  2479.                                 popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON)
  2480.                                 popupInfo.setText(CyTranslator().getText("TXT_KEY_POPUP_CONTROL_INFERNAL",()))
  2481.                                 popupInfo.setData1(iPlayer)
  2482.                                 popupInfo.setData2(iInfernalPlayer)
  2483.                                 popupInfo.addPythonButton(CyTranslator().getText("TXT_KEY_POPUP_YES", ()), "")
  2484.                                 popupInfo.addPythonButton(CyTranslator().getText("TXT_KEY_POPUP_NO", ()), "")
  2485.                                 popupInfo.setOnClickedPythonCallback("reassignPlayer")
  2486.                                 popupInfo.addPopup(iPlayer)
  2487.  
  2488.         if CyGame().getWBMapScript():
  2489.             sf.onTechAcquired(iTechType, iTeam, iPlayer, bAnnounce)
  2490.  
  2491.         if (not self.__LOG_TECH):
  2492.             return
  2493.         CvUtil.pyPrint('%s was finished by Team %d'
  2494.             %(PyInfo.TechnologyInfo(iTechType).getDescription(), iTeam))
  2495.  
  2496.     def onTechSelected(self, argsList):
  2497.         'Tech Selected'
  2498.         iTechType, iPlayer = argsList
  2499.         if (not self.__LOG_TECH):
  2500.             return
  2501.         CvUtil.pyPrint('%s was selected by Player %d' %(PyInfo.TechnologyInfo(iTechType).getDescription(), iPlayer))
  2502.  
  2503.     def onReligionFounded(self, argsList):
  2504.         'Religion Founded'
  2505.         iReligion, iFounder = argsList
  2506.         player = PyPlayer(iFounder)
  2507.         pPlayer = gc.getPlayer(iFounder)
  2508.  
  2509.         iCityId = gc.getGame().getHolyCity(iReligion).getID()
  2510.         if (gc.getGame().isFinalInitialized() and not gc.getGame().GetWorldBuilderMode()):
  2511.             if ((not gc.getGame().isNetworkMultiPlayer()) and (iFounder == gc.getGame().getActivePlayer())):
  2512.                 popupInfo = CyPopupInfo()
  2513.                 popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
  2514.                 popupInfo.setData1(iReligion)
  2515.                 popupInfo.setData2(iCityId)
  2516.                 if (iReligion == gc.getInfoTypeForString('RELIGION_THE_EMPYREAN') or iReligion == gc.getInfoTypeForString('RELIGION_COUNCIL_OF_ESUS')):
  2517.                     popupInfo.setData3(3)
  2518.                 else:
  2519.                     popupInfo.setData3(1)
  2520.                 popupInfo.setText(u"showWonderMovie")
  2521.                 popupInfo.addPopup(iFounder)
  2522.  
  2523.  
  2524.         if CyGame().getWBMapScript():
  2525.             sf.onReligionFounded(iReligion, iFounder)
  2526.  
  2527.         if (not self.__LOG_RELIGION):
  2528.             return
  2529.         CvUtil.pyPrint('Player %d Civilization %s has founded %s'
  2530.             %(iFounder, player.getCivilizationName(), gc.getReligionInfo(iReligion).getDescription()))
  2531.  
  2532.     def onReligionSpread(self, argsList):
  2533.         'Religion Has Spread to a City'
  2534.         iReligion, iOwner, pSpreadCity = argsList
  2535.         player = PyPlayer(iOwner)
  2536.         iOrder = gc.getInfoTypeForString('RELIGION_THE_ORDER')
  2537.         iVeil = gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL')
  2538.         pPlayer = gc.getPlayer(iOwner)
  2539.  
  2540.         if iReligion == iOrder and CyGame().getGameTurn() != CyGame().getStartTurn():
  2541.             if (pPlayer.getStateReligion() == iOrder and pSpreadCity.getOccupationTimer() <= 0):
  2542.                 if (CyGame().getSorenRandNum(100, "Order Spawn") < gc.getDefineINT('ORDER_SPAWN_CHANCE')):
  2543.                     eTeam = gc.getTeam(pPlayer.getTeam())
  2544.                     if eTeam.isHasTech(gc.getInfoTypeForString('TECH_FANATICISM')):
  2545.                         iUnit = gc.getInfoTypeForString('UNIT_CRUSADER')
  2546.                         CyInterface().addMessage(iOwner,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ORDER_SPAWN_CRUSADER",()),'AS2D_UNIT_BUILD_UNIT',1,'Art/Interface/Buttons/Units/Crusader.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)
  2547.                     else:
  2548.                         iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_THE_ORDER')
  2549.                         CyInterface().addMessage(iOwner,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ORDER_SPAWN_ACOLYTE",()),'AS2D_UNIT_BUILD_UNIT',1,'Art/Interface/Buttons/Units/Disciple Order.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)
  2550.                     newUnit = pPlayer.initUnit(iUnit, pSpreadCity.getX(), pSpreadCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  2551.         if pSpreadCity.isHasReligion(iVeil) and iReligion == iOrder:
  2552.             if not pSpreadCity.isHolyCity():
  2553.                 result = CyGame().getSorenRandNum(100, "Order-Veil")
  2554.                 if (result < 35):
  2555.                     CyInterface().addMessage(iOwner,True,25,"A bloodbath ensues as the Order and Veil battle for control of the city! In the end, Ritualists lie dead in the streets. The Order is triumphant!",'AS2D_UNIT_BUILD_UNIT',1,'Art/Interface/Buttons/Religions/Order.dds',ColorTypes(14),pSpreadCity.getX(),pSpreadCity.getY(),True,True)
  2556.                     pSpreadCity.setHasReligion(gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'), False, True, True)
  2557.                     iPop = pSpreadCity.getPopulation()-1
  2558.                     if (iPop > 0):
  2559.                         pSpreadCity.setPopulation(iPop)
  2560.                     CyGame().changeGlobalCounter(-1)
  2561.                 else:
  2562.                     CyInterface().addMessage(iOwner,True,25,"A bloodbath ensues as the Order and Veil battle for control of the city! In the end, the streets are coated in Crusader blood. The Veil is victorious!",'AS2D_UNIT_BUILD_UNIT',1,'Art/Interface/Buttons/Religions/Ashen.dds',ColorTypes(5),pSpreadCity.getX(),pSpreadCity.getY(),True,True)
  2563.                     pSpreadCity.setHasReligion(gc.getInfoTypeForString('RELIGION_THE_ORDER'), False, True, True)
  2564.         elif pSpreadCity.isHasReligion(iOrder) and iReligion == iVeil:
  2565.             if not pSpreadCity.isHolyCity():
  2566.                 result = CyGame().getSorenRandNum(100, "Veil-Order")
  2567.                 if (result < 35):
  2568.                     CyInterface().addMessage(iOwner,True,25,"A bloodbath ensues as the Order and Veil battle for control of the city! In the end, the streets are coated in Crusader blood. The Veil is victorious!",'AS2D_UNIT_BUILD_UNIT',1,'Art/Interface/Buttons/Religions/Ashen.dds',ColorTypes(5),pSpreadCity.getX(),pSpreadCity.getY(),True,True)
  2569.                     pSpreadCity.setHasReligion(gc.getInfoTypeForString('RELIGION_THE_ORDER'), False, True, True)
  2570.                     iPop = pSpreadCity.getPopulation()-1
  2571.                     if (iPop > 0):
  2572.                         pSpreadCity.setPopulation(iPop)
  2573.                     CyGame().changeGlobalCounter(1)
  2574.                 else :
  2575.                     CyInterface().addMessage(iOwner,True,25,"A bloodbath ensues as the Order and Veil battle for control of the city! In the end, Ritualists lie dead in the streets. The Order is triumphant!",'AS2D_UNIT_BUILD_UNIT',1,'Art/Interface/Buttons/Religions/Order.dds',ColorTypes(14),pSpreadCity.getX(),pSpreadCity.getY(),True,True)
  2576.                     pSpreadCity.setHasReligion(gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'), False, True, True)
  2577.  
  2578.         if (not self.__LOG_RELIGIONSPREAD):
  2579.             return
  2580.         CvUtil.pyPrint('%s has spread to Player %d Civilization %s city of %s'
  2581.             %(gc.getReligionInfo(iReligion).getDescription(), iOwner, player.getCivilizationName(), pSpreadCity.getName()))
  2582.  
  2583.     def onReligionRemove(self, argsList):
  2584.         'Religion Has been removed from a City'
  2585.         iReligion, iOwner, pRemoveCity = argsList
  2586.         player = PyPlayer(iOwner)
  2587.         if (not self.__LOG_RELIGIONSPREAD):
  2588.             return
  2589.         CvUtil.pyPrint('%s has been removed from Player %d Civilization %s city of %s'
  2590.             %(gc.getReligionInfo(iReligion).getDescription(), iOwner, player.getCivilizationName(), pRemoveCity.getName()))
  2591.  
  2592.     def onCorporationFounded(self, argsList):
  2593.         'Corporation Founded'
  2594.         iCorporation, iFounder = argsList
  2595.         player = PyPlayer(iFounder)
  2596.         if (not self.__LOG_RELIGION):
  2597.             return
  2598.         CvUtil.pyPrint('Player %d Civilization %s has founded %s'
  2599.             %(iFounder, player.getCivilizationName(), gc.getCorporationInfo(iCorporation).getDescription()))
  2600.  
  2601.     def onCorporationSpread(self, argsList):
  2602.         'Corporation Has Spread to a City'
  2603.         iCorporation, iOwner, pSpreadCity = argsList
  2604.         player = PyPlayer(iOwner)
  2605.         if (not self.__LOG_RELIGIONSPREAD):
  2606.             return
  2607.         CvUtil.pyPrint('%s has spread to Player %d Civilization %s city of %s'
  2608.             %(gc.getCorporationInfo(iCorporation).getDescription(), iOwner, player.getCivilizationName(), pSpreadCity.getName()))
  2609.  
  2610.     def onCorporationRemove(self, argsList):
  2611.         'Corporation Has been removed from a City'
  2612.         iCorporation, iOwner, pRemoveCity = argsList
  2613.         player = PyPlayer(iOwner)
  2614.         if (not self.__LOG_RELIGIONSPREAD):
  2615.             return
  2616.         CvUtil.pyPrint('%s has been removed from Player %d Civilization %s city of %s'
  2617.             %(gc.getReligionInfo(iReligion).getDescription(), iOwner, player.getCivilizationName(), pRemoveCity.getName()))
  2618.  
  2619.     def onGoldenAge(self, argsList):
  2620.         'Golden Age'
  2621.         iPlayer = argsList[0]
  2622.         player = PyPlayer(iPlayer)
  2623.         if (not self.__LOG_GOLDENAGE):
  2624.             return
  2625.         CvUtil.pyPrint('Player %d Civilization %s has begun a golden age'
  2626.             %(iPlayer, player.getCivilizationName()))
  2627.  
  2628.     def onEndGoldenAge(self, argsList):
  2629.         'End Golden Age'
  2630.         iPlayer = argsList[0]
  2631.         player = PyPlayer(iPlayer)
  2632.         if (not self.__LOG_ENDGOLDENAGE):
  2633.             return
  2634.         CvUtil.pyPrint('Player %d Civilization %s golden age has ended'
  2635.             %(iPlayer, player.getCivilizationName()))
  2636.  
  2637.     def onChangeWar(self, argsList):
  2638.         'War Status Changes'
  2639.         bIsWar = argsList[0]
  2640.         iTeam = argsList[1]
  2641.         iRivalTeam = argsList[2]
  2642.  
  2643.  
  2644.     def onChat(self, argsList):
  2645.         'Chat Message Event'
  2646.         chatMessage = "%s" %(argsList[0],)
  2647.  
  2648.     def onSetPlayerAlive(self, argsList):
  2649.         'Set Player Alive Event'
  2650.         iPlayerID = argsList[0]
  2651.         bNewValue = argsList[1]
  2652.         CvUtil.pyPrint("Player %d's alive status set to: %d" %(iPlayerID, int(bNewValue)))
  2653.  
  2654.         if (bNewValue == False and gc.getGame().getGameTurnYear() >= 5):
  2655.             pPlayer = gc.getPlayer(iPlayerID)
  2656.  
  2657.  
  2658.             if pPlayer.getAlignment() == gc.getInfoTypeForString('ALIGNMENT_GOOD'):
  2659.                 CyGame().changeGlobalCounter(5)
  2660.             elif pPlayer.getAlignment() == gc.getInfoTypeForString('ALIGNMENT_EVIL'):
  2661.                 CyGame().changeGlobalCounter(-5)
  2662.             if CyGame().getWBMapScript():
  2663.                 sf.playerDefeated(pPlayer)
  2664.             else:
  2665.                 if pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_ALEXIS'):
  2666.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_CALABIM",()),'art/interface/popups/Alexis.dds')
  2667.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_AMELANCHIER'):
  2668.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_LJOSALFAR",()),'art/interface/popups/Amelanchier.dds')
  2669.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_ARENDEL'):
  2670.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_LJOSALFAR",()),'art/interface/popups/Arendel.dds')
  2671.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_ARTURUS'):
  2672.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_KHAZAD",()),'art/interface/popups/Arturus.dds')
  2673.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_AURIC'):
  2674.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_ILLIANS",()),'art/interface/popups/Auric.dds')
  2675.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_BASIUM'):
  2676.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_MERCURIANS",()),'art/interface/popups/Basium.dds')
  2677.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_BEERI'):
  2678.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_LUCHUIRP",()),'art/interface/popups/Beeri.dds')
  2679.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_CAPRIA'):
  2680.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_BANNOR",()),'art/interface/popups/Capria.dds')
  2681.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_CARDITH'):
  2682.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_KURIOTATES",()),'art/interface/popups/Cardith.dds')
  2683.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_CASSIEL'):
  2684.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_GRIGORI",()),'art/interface/popups/Cassiel.dds')
  2685.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_CHARADON'):
  2686.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_DOVIELLO",()),'art/interface/popups/Charadon.dds')
  2687.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_DAIN'):
  2688.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_AMURITES",()),'art/interface/popups/Dain.dds')
  2689.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_DECIUS'):
  2690.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_DECIUS",()),'art/interface/popups/Decius.dds')
  2691.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_EINION'):
  2692.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_ELOHIM",()),'art/interface/popups/Einion.dds')
  2693.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_ETHNE'):
  2694.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_ELOHIM",()),'art/interface/popups/Ethne.dds')
  2695.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_FAERYL'):
  2696.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_SVARTALFAR",()),'art/interface/popups/Faeryl.dds')
  2697.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_FALAMAR'):
  2698.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_LANUN",()),'art/interface/popups/Falamar.dds')
  2699.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_FLAUROS'):
  2700.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_CALABIM",()),'art/interface/popups/Flauros.dds')
  2701.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_GARRIM'):
  2702.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_LUCHUIRP",()),'art/interface/popups/Garrim.dds')
  2703.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_HANNAH'):
  2704.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_HANNAH",()),'art/interface/popups/Hannah.dds')
  2705.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_HYBOREM'):
  2706.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_INFERNAL",()),'art/interface/popups/Hyborem.dds')
  2707.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_JONAS'):
  2708.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_CLAN_OF_EMBERS",()),'art/interface/popups/Jonus.dds')
  2709.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_KANDROS'):
  2710.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_KHAZAD",()),'art/interface/popups/Kandros.dds')
  2711.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_KEELYN'):
  2712.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_KEELYN",()),'art/interface/popups/Keelyn.dds')
  2713.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_MAHALA'):
  2714.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_DOVIELLO",()),'art/interface/popups/Mahala.dds')
  2715.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_SANDALPHON'):
  2716.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_SIDAR",()),'art/interface/popups/Sandalphon.dds')
  2717.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_OS-GABELLA'):
  2718.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_SHEAIM",()),'art/interface/popups/Os-Gabella.dds')
  2719.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_PERPENTACH'):
  2720.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_BALSERAPHS",()),'art/interface/popups/Perpentach.dds')
  2721.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_RHOANNA'):
  2722.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_HIPPUS",()),'art/interface/popups/Rhoanna.dds')
  2723.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_SABATHIEL'):
  2724.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_BANNOR",()),'art/interface/popups/Sabathiel.dds')
  2725.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_SHEELBA'):
  2726.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_CLAN_OF_EMBERS",()),'art/interface/popups/Sheelba.dds')
  2727.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_TASUNKE'):
  2728.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_HIPPUS",()),'art/interface/popups/Tasunke.dds')
  2729.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_TEBRYN'):
  2730.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_SHEAIM",()),'art/interface/popups/Tebryn.dds')
  2731.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_THESSA'):
  2732.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_LJOSALFAR",()),'art/interface/popups/Thessa.dds')
  2733.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_VALLEDIA'):
  2734.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_AMURITES",()),'art/interface/popups/Valledia.dds')
  2735.                 elif pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_VARN'):
  2736.                     cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_DEFEATED_MALAKIM",()),'art/interface/popups/Varn.dds')
  2737.  
  2738.     def onPlayerChangeStateReligion(self, argsList):
  2739.         'Player changes his state religion'
  2740.         iPlayer, iNewReligion, iOldReligion = argsList
  2741.         pPlayer = gc.getPlayer(iPlayer)
  2742.        
  2743.         if iNewReligion != iOldReligion:
  2744.             if iNewReligion == -1:
  2745.                 iCurrentEra = pPlayer.getCurrentEra()
  2746.                 iEra = iCurrentEra
  2747.                 if not (iCurrentEra == gc.getInfoTypeForString('ERA_ANCIENT') or iCurrentEra == gc.getInfoTypeForString('ERA_CLASSICAL') or iCurrentEra == gc.getInfoTypeForString('ERA_MEDIEVAL')):
  2748.                     iEra = gc.getGame().getStartEra()
  2749.                     pPlayer.setCurrentEra(iEra)
  2750.             elif iNewReligion == gc.getInfoTypeForString('RELIGION_THE_ORDER'):
  2751.                 pPlayer.setCurrentEra(gc.getInfoTypeForString('ERA_ORDE'))
  2752.             elif iNewReligion == gc.getInfoTypeForString('RELIGION_THE_EMPYREAN'):
  2753.                 pPlayer.setCurrentEra(gc.getInfoTypeForString('ERA_EMPY'))
  2754.             elif iNewReligion == gc.getInfoTypeForString('RELIGION_RUNES_OF_KILMORPH'):
  2755.                 pPlayer.setCurrentEra(gc.getInfoTypeForString('ERA_RUNE'))
  2756.             elif iNewReligion == gc.getInfoTypeForString('RELIGION_FELLOWSHIP_OF_LEAVES'):
  2757.                 pPlayer.setCurrentEra(gc.getInfoTypeForString('ERA_LEAF'))
  2758.             elif iNewReligion == gc.getInfoTypeForString('RELIGION_OCTOPUS_OVERLORDS'):
  2759.                 pPlayer.setCurrentEra(gc.getInfoTypeForString('ERA_OCTO'))
  2760.             elif iNewReligion == gc.getInfoTypeForString('RELIGION_COUNCIL_OF_ESUS'):
  2761.                 pPlayer.setCurrentEra(gc.getInfoTypeForString('ERA_COUN'))
  2762.             elif iNewReligion == gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'):
  2763.                 pPlayer.setCurrentEra(gc.getInfoTypeForString('ERA_VEIL'))
  2764.  
  2765.     def onPlayerGoldTrade(self, argsList):
  2766.         'Player Trades gold to another player'
  2767.         iFromPlayer, iToPlayer, iGoldAmount = argsList
  2768.  
  2769.     def onCityBuilt(self, argsList):
  2770.         'City Built'
  2771.         city = argsList[0]
  2772.         pPlot = city.plot()
  2773.         pPlayer = gc.getPlayer(city.getOwner())
  2774.  
  2775.         if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
  2776.             city.setHasReligion(gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'), True, True, True)
  2777.             city.setPopulation(3)
  2778.             city.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_ELDER_COUNCIL'), 1)
  2779.             city.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_TRAINING_YARD'), 1)
  2780.             city.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_OBSIDIAN_GATE'), 1)
  2781.             city.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_FORGE'), 1)
  2782.             city.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_MAGE_GUILD'), 1)
  2783.             city.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_DEMONIC_CITIZENS'), 1)
  2784.  
  2785.         elif pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_BARBARIAN'):
  2786.             eTeam = gc.getTeam(gc.getPlayer(gc.getBARBARIAN_PLAYER()).getTeam())
  2787.  
  2788.             iUnit = gc.getInfoTypeForString('UNIT_ARCHER')
  2789.             if (eTeam.isHasTech(gc.getInfoTypeForString('TECH_BOWYERS')) or CyGame().getStartEra() > gc.getInfoTypeForString('ERA_CLASSICAL')):
  2790.                 iUnit = gc.getInfoTypeForString('UNIT_LONGBOWMAN')
  2791.             newUnit2 = pPlayer.initUnit(iUnit, city.getX(), city.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  2792.             newUnit3 = pPlayer.initUnit(iUnit, city.getX(), city.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  2793.             newUnit2.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ORC'), true)
  2794.             newUnit3.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ORC'), true)
  2795.             if ((not eTeam.isHasTech(gc.getInfoTypeForString('TECH_ARCHERY'))) or CyGame().getStartEra() == gc.getInfoTypeForString('ERA_ANCIENT')):
  2796.                 newUnit2.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WEAK'), true)
  2797.                 newUnit3.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WEAK'), true)
  2798.  
  2799.         if CyGame().getWBMapScript():
  2800.             sf.onCityBuilt(city)
  2801.  
  2802.  
  2803.         if (city.getOwner() == CyGame().getActivePlayer())and ( CyGame().getAIAutoPlay(CyGame().getActivePlayer()) == 0 ) :
  2804.             self.__eventEditCityNameBegin(city, False)
  2805.         CvUtil.pyPrint('City Built Event: %s' %(city.getName()))
  2806.  
  2807.  
  2808.     def onCityRazed(self, argsList):
  2809.         'City Razed'
  2810.         city, iPlayer = argsList
  2811.         iOwner = city.findHighestCulture()
  2812.  
  2813.         # Partisans!
  2814. #       if city.getPopulation > 1 and iOwner != -1 and iPlayer != -1:
  2815. #           owner = gc.getPlayer(iOwner)
  2816. #           if not owner.isBarbarian() and owner.getNumCities() > 0:
  2817. #               if gc.getTeam(owner.getTeam()).isAtWar(gc.getPlayer(iPlayer).getTeam()):
  2818. #                   if gc.getNumEventTriggerInfos() > 0: # prevents mods that don't have events from getting an error
  2819. #                       iEvent = CvUtil.findInfoTypeNum(gc.getEventTriggerInfo, gc.getNumEventTriggerInfos(),'EVENTTRIGGER_PARTISANS')
  2820. #                       if iEvent != -1 and gc.getGame().isEventActive(iEvent) and owner.getEventTriggerWeight(iEvent) >= 0:
  2821. #                           triggerData = owner.initTriggeredData(iEvent, true, -1, city.getX(), city.getY(), iPlayer, city.getID(), -1, -1, -1, -1)
  2822.  
  2823.         iAngel = gc.getInfoTypeForString('UNIT_ANGEL')
  2824.         iInfernal = gc.getInfoTypeForString('CIVILIZATION_INFERNAL')
  2825.         iManes = gc.getInfoTypeForString('UNIT_MANES')
  2826.         iMercurians = gc.getInfoTypeForString('CIVILIZATION_MERCURIANS')
  2827.         pPlayer = gc.getPlayer(iPlayer)
  2828.         if gc.getPlayer(city.getOriginalOwner()).getAlignment() == gc.getInfoTypeForString('ALIGNMENT_EVIL'):
  2829.             if gc.getPlayer(city.getOriginalOwner()).getCivilizationType() != iInfernal:
  2830.                 for i in range(city.getPopulation()):
  2831.                     cf.giftUnit(iManes, iInfernal, 0, city.plot(), city.getOwner())
  2832.  
  2833.         elif gc.getPlayer(city.getOriginalOwner()).getAlignment() == gc.getInfoTypeForString('ALIGNMENT_NEUTRAL'):
  2834.             for i in range((city.getPopulation() / 4) + 1):
  2835.                 cf.giftUnit(iManes, iInfernal, 0, city.plot(), city.getOwner())
  2836.                 cf.giftUnit(iManes, iInfernal, 0, city.plot(), city.getOwner())
  2837.                 cf.giftUnit(iAngel, iMercurians, 0, city.plot(), city.getOwner())
  2838.  
  2839.         elif gc.getPlayer(city.getOriginalOwner()).getAlignment() == gc.getInfoTypeForString('ALIGNMENT_GOOD'):
  2840.             for i in range((city.getPopulation() / 2) + 1):
  2841.                 cf.giftUnit(iAngel, iMercurians, 0, city.plot(), city.getOwner())
  2842.  
  2843.         pPlot = city.plot()
  2844.         iPop = city.getPopulation()
  2845.         iCalabim = gc.getInfoTypeForString('CIVILIZATION_CALABIM')
  2846.         if pPlayer.getCivilizationType() == iCalabim and iPop > 2:
  2847.             iVampire = gc.getInfoTypeForString('PROMOTION_VAMPIRE')
  2848.             for i in range(pPlot.getNumUnits()):
  2849.                 if iPop < 3: break
  2850.                 pUnit = pPlot.getUnit(i)
  2851.                 if pUnit.isHasPromotion(iVampire):
  2852.                     pUnit.changeExperience(iPop, -1, false, false, false)
  2853.                     iPop = iPop - 1
  2854.  
  2855.         if CyGame().getWBMapScript():
  2856.             sf.onCityRazed(city, iPlayer)
  2857.  
  2858.         CvUtil.pyPrint("City Razed Event: %s" %(city.getName(),))
  2859.  
  2860.     def onCityAcquired(self, argsList):
  2861.         'City Acquired'
  2862.         iPreviousOwner,iNewOwner,pCity,bConquest,bTrade = argsList
  2863.         pPlayer = gc.getPlayer(iNewOwner)
  2864.         pPrevious = gc.getPlayer(iPreviousOwner)
  2865.  
  2866. ## FFH
  2867.         if pPrevious.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
  2868.             pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_OBSIDIAN_GATE'), 0)
  2869.  
  2870.         if CyGame().getWBMapScript():
  2871.             sf.onCityAcquired(iPreviousOwner, iNewOwner, pCity, bConquest, bTrade)
  2872.  
  2873.         if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
  2874.             pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_ELDER_COUNCIL'), 1)
  2875.             pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_TRAINING_YARD'), 1)
  2876.             pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_OBSIDIAN_GATE'), 1)
  2877.             pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_FORGE'), 1)
  2878.             pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_MAGE_GUILD'), 1)
  2879.             pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_DEMONIC_CITIZENS'), 1)
  2880. ## END FFH
  2881.  
  2882.     def onCityAcquiredAndKept(self, argsList):
  2883.         'City Acquired and Kept'
  2884.         iOwner,pCity = argsList
  2885.  
  2886.         #Functions added here tend to cause OOS issues
  2887.  
  2888.         CvUtil.pyPrint('City Acquired and Kept Event: %s' %(pCity.getName()))
  2889.  
  2890.     def onCityLost(self, argsList):
  2891.         'City Lost'
  2892.         city = argsList[0]
  2893.         player = PyPlayer(city.getOwner())
  2894.         if (not self.__LOG_CITYLOST):
  2895.             return
  2896.         CvUtil.pyPrint('City %s was lost by Player %d Civilization %s'
  2897.             %(city.getName(), player.getID(), player.getCivilizationName()))
  2898.  
  2899.     def onCultureExpansion(self, argsList):
  2900.         'City Culture Expansion'
  2901.         pCity = argsList[0]
  2902.         iPlayer = argsList[1]
  2903.         CvUtil.pyPrint("City %s's culture has expanded" %(pCity.getName(),))
  2904.  
  2905.     def onCityGrowth(self, argsList):
  2906.         'City Population Growth'
  2907.         pCity = argsList[0]
  2908.         iPlayer = argsList[1]
  2909.         CvUtil.pyPrint("%s has grown" %(pCity.getName(),))
  2910.  
  2911.     def onCityDoTurn(self, argsList):
  2912.         'City Production'
  2913.         pCity = argsList[0]
  2914.         iPlayer = argsList[1]
  2915.         pPlot = pCity.plot()
  2916.         iPlayer = pCity.getOwner()
  2917.         pPlayer = gc.getPlayer(iPlayer)
  2918.  
  2919.         if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_CITADEL_OF_LIGHT')) > 0:
  2920.             iX = pCity.getX()
  2921.             iY = pCity.getY()
  2922.             eTeam = gc.getTeam(pPlayer.getTeam())
  2923.             iBestValue = 0
  2924.             pBestPlot = -1
  2925.             for iiX in range(iX-2, iX+3, 1):
  2926.                 for iiY in range(iY-2, iY+3, 1):
  2927.                     pPlot2 = CyMap().plot(iiX,iiY)
  2928.                     bEnemy = false
  2929.                     bNeutral = false
  2930.                     iValue = 0
  2931.                     if pPlot2.isVisibleEnemyUnit(iPlayer):
  2932.                         for i in range(pPlot2.getNumUnits()):
  2933.                             pUnit = pPlot2.getUnit(i)
  2934.                             if eTeam.isAtWar(pUnit.getTeam()):
  2935.                                 iValue += 5 * pUnit.baseCombatStr()
  2936.                             else:
  2937.                                 bNeutral = true
  2938.                         if (iValue > iBestValue and bNeutral == false):
  2939.                             iBestValue = iValue
  2940.                             pBestPlot = pPlot2
  2941.             if pBestPlot != -1:
  2942.                 for i in range(pBestPlot.getNumUnits()):
  2943.                     pUnit = pBestPlot.getUnit(i)
  2944.                     pUnit.doDamageNoCaster(20, 40, gc.getInfoTypeForString('DAMAGE_FIRE'), False)
  2945.                 if (pBestPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST') or pBestPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_JUNGLE')):
  2946.                     bValid = True
  2947.                     iImprovement = pPlot.getImprovementType()
  2948.                     if iImprovement != -1 :
  2949.                         if gc.getImprovementInfo(iImprovement).isPermanent():
  2950.                             bValid = False
  2951.                     if bValid:
  2952.                         if CyGame().getSorenRandNum(100, "Flames Spread") < gc.getDefineINT('FLAMES_SPREAD_CHANCE'):
  2953.                             pBestPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_SMOKE'))
  2954.                 CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_PILLAR_OF_FIRE'),pBestPlot.getPoint())
  2955.  
  2956.         if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_HALL_OF_MIRRORS')) > 0:
  2957.             if CyGame().getSorenRandNum(100, "Hall of Mirrors") < 100:
  2958.                 pUnit = -1
  2959.                 iBestValue = -1
  2960.                 iX = pCity.getX()
  2961.                 iY = pCity.getY()
  2962.                 eTeam = gc.getTeam(pPlayer.getTeam())
  2963.                 for iiX in range(iX-1, iX+2, 1):
  2964.                     for iiY in range(iY-1, iY+2, 1):
  2965.                         pLoopPlot = CyMap().plot(iiX,iiY)
  2966.                         if not pLoopPlot.isNone():
  2967.                             if pLoopPlot.isVisibleEnemyUnit(iPlayer):
  2968.                                 for i in range(pLoopPlot.getNumUnits()):
  2969.                                     pUnit2 = pLoopPlot.getUnit(i)
  2970.                                     if eTeam.isAtWar(pUnit2.getTeam()):
  2971.                                         iValue = CyGame().getSorenRandNum(100, "Hall of Mirrors")
  2972.                                         if (iValue > iBestValue):
  2973.                                             iBestValue = iValue
  2974.                                             pUnit = pUnit2
  2975.                 if pUnit != -1:
  2976.                     newUnit = pPlayer.initUnit(pUnit.getUnitType(), pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
  2977.                     newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ILLUSION'), True)
  2978.  
  2979. ##--------      Unofficial Bug Fix: Modified by Denev   --------##
  2980. # Copy not only unit type, but also unit artstyle.
  2981.                     newUnit.setUnitArtStyleType(pUnit.getUnitArtStyleType())
  2982. ##--------      Unofficial Bug Fix: End Modify          --------##
  2983.  
  2984.                     if pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_SUMMONER')):
  2985.                         newUnit.setDuration(5)
  2986.                     else:
  2987.                         newUnit.setDuration(3)
  2988.  
  2989.         if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_EYES_AND_EARS_NETWORK')) > 0:
  2990.             iArete = gc.getInfoTypeForString('TECH_ARETE')
  2991.             iHiddenPaths = gc.getInfoTypeForString('TECH_HIDDEN_PATHS')
  2992.             iInfernalPact = gc.getInfoTypeForString('TECH_INFERNAL_PACT')
  2993.             iMindStapling = gc.getInfoTypeForString('TECH_MIND_STAPLING')
  2994.             iSeafaring = gc.getInfoTypeForString('TECH_SEAFARING')
  2995.             eTeam = gc.getTeam(pPlayer.getTeam())
  2996.             listTeams = []
  2997.             for iPlayer2 in range(gc.getMAX_PLAYERS()):
  2998.                 pPlayer2 = gc.getPlayer(iPlayer2)
  2999.                 if (pPlayer2.isAlive() and iPlayer2 != iPlayer):
  3000.                     iTeam2 = pPlayer2.getTeam()
  3001.                     if eTeam.isOpenBorders(iTeam2):
  3002.                         listTeams.append(gc.getTeam(iTeam2))
  3003.             if len(listTeams) >= 3:
  3004.                 for iTech in range(gc.getNumTechInfos()):
  3005.                     if (iTech != iArete and iTech != iMindStapling and iTech != iHiddenPaths and iTech != iInfernalPact and iTech != iSeafaring):
  3006.                         if eTeam.isHasTech(iTech) == False:
  3007.                             if pPlayer.canResearch(iTech, False):
  3008.                                 iCount = 0
  3009.                                 for i in range(len(listTeams)):
  3010.                                     if listTeams[i].isHasTech(iTech):
  3011.                                         iCount = iCount + 1
  3012.                                 if iCount >= 3:
  3013.                                     eTeam.setHasTech(iTech, True, iPlayer, False, True)
  3014.                                     CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_EYES_AND_EARS_NETWORK_FREE_TECH",()),'AS2D_TECH_DING',1,'Art/Interface/Buttons/Buildings/Eyesandearsnetwork.dds',ColorTypes(8),pCity.getX(),pCity.getY(),True,True)
  3015.  
  3016.         if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_PLANAR_GATE')) > 0:
  3017.             iMax = 1
  3018.             iMult = 1
  3019.             if CyGame().getGlobalCounter() >= 50:
  3020.                 iMax = 2
  3021.                 iMult = 1.5
  3022.             if CyGame().getGlobalCounter() >= 75:
  3023.                 iMax = 3
  3024.                 iMult = 2
  3025.             if CyGame().getGlobalCounter() == 100:
  3026.                 iMax = 4
  3027.                 iMult = 2.5
  3028.             if CyGame().getSorenRandNum(10000, "Planar Gate") < gc.getDefineINT('PLANAR_GATE_CHANCE') * iMult:
  3029.                 listUnits = []
  3030.                 iMax = iMax * pPlayer.countNumBuildings(gc.getInfoTypeForString('BUILDING_PLANAR_GATE'))
  3031.                 if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_GAMBLING_HOUSE')) > 0:
  3032.                     if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_REVELERS')) < iMax:
  3033.                         listUnits.append(gc.getInfoTypeForString('UNIT_REVELERS'))
  3034.                 if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_MAGE_GUILD')) > 0:
  3035.                     if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_MOBIUS_WITCH')) < iMax:
  3036.                         listUnits.append(gc.getInfoTypeForString('UNIT_MOBIUS_WITCH'))
  3037.                 if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_CARNIVAL')) > 0:
  3038.                     if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_CHAOS_MARAUDER')) < iMax:
  3039.                         listUnits.append(gc.getInfoTypeForString('UNIT_CHAOS_MARAUDER'))
  3040.                 if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_GROVE')) > 0:
  3041.                     if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_MANTICORE')) < iMax:
  3042.                         listUnits.append(gc.getInfoTypeForString('UNIT_MANTICORE'))
  3043.                 if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_PUBLIC_BATHS')) > 0:
  3044.                     if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_SUCCUBUS')) < iMax:
  3045.                         listUnits.append(gc.getInfoTypeForString('UNIT_SUCCUBUS'))
  3046.                 if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_OBSIDIAN_GATE')) > 0:
  3047.                     if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_MINOTAUR')) < iMax:
  3048.                         listUnits.append(gc.getInfoTypeForString('UNIT_MINOTAUR'))
  3049.                 if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_TEMPLE_OF_THE_VEIL')) > 0:
  3050.                     if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_TAR_DEMON')) < iMax:
  3051.                         listUnits.append(gc.getInfoTypeForString('UNIT_TAR_DEMON'))
  3052.                 if len(listUnits) > 0:
  3053.                     iUnit = listUnits[CyGame().getSorenRandNum(len(listUnits), "Planar Gate")]
  3054.                     newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  3055.                     CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_PLANAR_GATE",()),'AS2D_DISCOVERBONUS',1,gc.getUnitInfo(newUnit.getUnitType()).getButton(),ColorTypes(8),pCity.getX(),pCity.getY(),True,True)
  3056.                     if iUnit == gc.getInfoTypeForString('UNIT_MOBIUS_WITCH'):
  3057.                         promotions = [ 'PROMOTION_AIR1','PROMOTION_BODY1','PROMOTION_CHAOS1','PROMOTION_DEATH1','PROMOTION_EARTH1','PROMOTION_ENCHANTMENT1','PROMOTION_ENTROPY1','PROMOTION_FIRE1','PROMOTION_LAW1','PROMOTION_LIFE1','PROMOTION_MIND1','PROMOTION_NATURE1','PROMOTION_SHADOW1','PROMOTION_SPIRIT1','PROMOTION_SUN1','PROMOTION_WATER1' ]
  3058.                         newUnit.setLevel(4)
  3059.                         newUnit.setExperience(14, -1)
  3060.                         for i in promotions:
  3061.                             if CyGame().getSorenRandNum(10, "Bob") == 1:
  3062.                                 newUnit.setHasPromotion(gc.getInfoTypeForString(i), True)
  3063.  
  3064.         if gc.getPlayer(pCity.getOwner()).getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
  3065.             if pCity.isHasReligion(gc.getInfoTypeForString('RELIGION_THE_ORDER')):
  3066.                 pCity.setHasReligion(gc.getInfoTypeForString('RELIGION_THE_ORDER'), False, True, True)
  3067.             if pCity.isHasReligion(gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL')) == False:
  3068.                 pCity.setHasReligion(gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'), True, True, True)
  3069.  
  3070.         if gc.getPlayer(pCity.getOwner()).getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_MERCURIANS'):
  3071.             if pCity.isHasReligion(gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL')):
  3072.                 pCity.setHasReligion(gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'), False, True, True)
  3073.  
  3074.         if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_SHRINE_OF_SIRONA')) > 0:
  3075.             pPlayer.setFeatAccomplished(FeatTypes.FEAT_HEAL_UNIT_PER_TURN, True)
  3076.  
  3077.         if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_THE_DRAGONS_HORDE')) > 0:
  3078.             if pPlayer.isBarbarian():
  3079.                 if CyGame().getSorenRandNum(100, "Bob") < gc.getHandicapInfo(gc.getGame().getHandicapType()).getLairSpawnRate():
  3080.                     iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_OF_ACHERON')
  3081. #                   eTeam = gc.getTeam(pPlayer.getTeam())
  3082. #                   if eTeam.isHasTech(gc.getInfoTypeForString('TECH_SORCERY')):
  3083. #                       iUnit = gc.getInfoTypeForString('UNIT_SON_OF_THE_INFERNO')
  3084.                     newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
  3085.  
  3086.         CvAdvisorUtils.cityAdvise(pCity, iPlayer)
  3087.  
  3088.     def onCityBuildingUnit(self, argsList):
  3089.         'City begins building a unit'
  3090.         pCity = argsList[0]
  3091.         iUnitType = argsList[1]
  3092.         if (not self.__LOG_CITYBUILDING):
  3093.             return
  3094.         CvUtil.pyPrint("%s has begun building a %s" %(pCity.getName(),gc.getUnitInfo(iUnitType).getDescription()))
  3095.  
  3096.     def onCityBuildingBuilding(self, argsList):
  3097.         'City begins building a Building'
  3098.         pCity = argsList[0]
  3099.         iBuildingType = argsList[1]
  3100.         if (not self.__LOG_CITYBUILDING):
  3101.             return
  3102.         CvUtil.pyPrint("%s has begun building a %s" %(pCity.getName(),gc.getBuildingInfo(iBuildingType).getDescription()))
  3103.  
  3104.     def onCityRename(self, argsList):
  3105.         'City is renamed'
  3106.         pCity = argsList[0]
  3107.         if (pCity.getOwner() == gc.getGame().getActivePlayer()):
  3108.             self.__eventEditCityNameBegin(pCity, True)
  3109.  
  3110.     def onCityHurry(self, argsList):
  3111.         'City is renamed'
  3112.         pCity = argsList[0]
  3113.         iHurryType = argsList[1]
  3114.  
  3115.     def onVictory(self, argsList):
  3116.         'Victory'
  3117.         iTeam, iVictory = argsList
  3118.         if (iVictory >= 0 and iVictory < gc.getNumVictoryInfos()):
  3119.             for iPlayer in range(gc.getMAX_PLAYERS()):
  3120.                 pPlayer = gc.getPlayer(iPlayer)
  3121.                 if pPlayer.isAlive():
  3122.                     if pPlayer.isHuman():
  3123.                         if pPlayer.getTeam() == iTeam:
  3124.                             if CyGame().getWBMapScript():
  3125.                                 sf.onVictory(iPlayer, iVictory)
  3126.                             else:
  3127.                                 iCiv = pPlayer.getCivilizationType()
  3128.                                 if iCiv == gc.getInfoTypeForString('CIVILIZATION_AMURITES'):
  3129.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_AMURITES", 1)
  3130.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_BALSERAPHS'):
  3131.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_BALSERAPHS", 1)
  3132.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_BANNOR'):
  3133.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_BANNOR", 1)
  3134.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_CALABIM'):
  3135.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_CALABIM", 1)
  3136.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_CLAN_OF_EMBERS'):
  3137.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_CLAN_OF_EMBERS", 1)
  3138.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_DOVIELLO'):
  3139.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_DOVIELLO", 1)
  3140.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_ELOHIM'):
  3141.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_ELOHIM", 1)
  3142.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_GRIGORI'):
  3143.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_GRIGORI", 1)
  3144.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_HIPPUS'):
  3145.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_HIPPUS", 1)
  3146.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_ILLIANS'):
  3147.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_ILLIANS", 1)
  3148.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
  3149.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_INFERNAL", 1)
  3150.                                 elif iCiv   == gc.getInfoTypeForString('CIVILIZATION_KHAZAD'):
  3151.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_KHAZAD", 1)
  3152.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_KURIOTATES'):
  3153.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_KURIOTATES", 1)
  3154.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_LANUN'):
  3155.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_LANUN", 1)
  3156.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_LJOSALFAR'):
  3157.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_LJOSALFAR", 1)
  3158.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_LUCHUIRP'):
  3159.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_LUCHUIRP", 1)
  3160.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_MALAKIM'):
  3161.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_MALAKIM", 1)
  3162.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_MERCURIANS'):
  3163.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_MERCURIANS", 1)
  3164.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_SHEAIM'):
  3165.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_SHEAIM", 1)
  3166.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_SIDAR'):
  3167.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_SIDAR", 1)
  3168.                                 elif iCiv == gc.getInfoTypeForString('CIVILIZATION_SVARTALFAR'):
  3169.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_SVARTALFAR", 1)
  3170.  
  3171.                                 if iVictory == gc.getInfoTypeForString('VICTORY_ALTAR_OF_THE_LUONNOTAR'):
  3172.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_ALTAR_OF_THE_LUONNOTAR", 1)
  3173.                                 elif iVictory == gc.getInfoTypeForString('VICTORY_CONQUEST'):
  3174.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_CONQUEST", 1)
  3175.                                 elif iVictory == gc.getInfoTypeForString('VICTORY_CULTURAL'):
  3176.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_CULTURAL", 1)
  3177.                                 elif iVictory == gc.getInfoTypeForString('VICTORY_DOMINATION'):
  3178.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_DOMINATION", 1)
  3179.                                 elif iVictory == gc.getInfoTypeForString('VICTORY_RELIGIOUS'):
  3180.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_RELIGIOUS", 1)
  3181.                                 elif iVictory == gc.getInfoTypeForString('VICTORY_SCORE'):
  3182.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_SCORE", 1)
  3183.                                 elif iVictory == gc.getInfoTypeForString('VICTORY_TIME'):
  3184.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_TIME", 1)
  3185.                                 elif iVictory == gc.getInfoTypeForString('VICTORY_TOWER_OF_MASTERY'):
  3186.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_TOWER_OF_MASTERY", 1)
  3187.  
  3188.                                 if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_BARBARIAN_WORLD):
  3189.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_BARBARIAN_WORLD", 1)
  3190.                                 if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_CHALLENGE_CUT_LOSERS):
  3191.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_FINAL_FIVE", 1)
  3192.                                 if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_CHALLENGE_HIGH_TO_LOW):
  3193.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_HIGH_TO_LOW", 1)
  3194.                                 if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_CHALLENGE_INCREASING_DIFFICULTY):
  3195.                                     CyGame().changeTrophyValue("TROPHY_VICTORY_INCREASING_DIFFICULTY", 1)
  3196.  
  3197.             victoryInfo = gc.getVictoryInfo(int(iVictory))
  3198.             CvUtil.pyPrint("Victory!  Team %d achieves a %s victory"
  3199.                 %(iTeam, victoryInfo.getDescription()))
  3200.  
  3201.     def onVassalState(self, argsList):
  3202.         'Vassal State'
  3203.         iMaster, iVassal, bVassal = argsList
  3204.  
  3205.         if (bVassal):
  3206.             CvUtil.pyPrint("Team %d becomes a Vassal State of Team %d"
  3207.                 %(iVassal, iMaster))
  3208.         else:
  3209.             CvUtil.pyPrint("Team %d revolts and is no longer a Vassal State of Team %d"
  3210.                 %(iVassal, iMaster))
  3211.  
  3212.     def onGameUpdate(self, argsList):
  3213.         'sample generic event, called on each game turn slice'
  3214.         genericArgs = argsList[0][0]    # tuple of tuple of my args
  3215.         turnSlice = genericArgs[0]
  3216.  
  3217. #FfH: 10/15/2008 Added by Kael for OOS logging.
  3218.         OOSLogger.doGameUpdate()
  3219. #FfH: End add
  3220.  
  3221.     def onMouseEvent(self, argsList):
  3222.         'mouse handler - returns 1 if the event was consumed'
  3223.         eventType,mx,my,px,py,interfaceConsumed,screens = argsList
  3224.         if ( px!=-1 and py!=-1 ):
  3225.             if ( eventType == self.EventLButtonDown ):
  3226.                 if (self.bAllowCheats and self.bCtrl and self.bAlt and CyMap().plot(px,py).isCity() and not interfaceConsumed):
  3227.                     # Launch Edit City Event
  3228.                     CvEventManager.beginEvent(self, CvUtil.EventEditCity, (px,py) )
  3229.                     return 1
  3230.  
  3231.                 elif (self.bAllowCheats and self.bCtrl and self.bShift and not interfaceConsumed):
  3232.                     # Launch Place Object Event
  3233.                     CvEventManager.beginEvent(self, CvUtil.EventPlaceObject, (px, py) )
  3234.                     return 1
  3235.  
  3236.         if ( eventType == self.EventBack ):
  3237.             return CvScreensInterface.handleBack(screens)
  3238.         elif ( eventType == self.EventForward ):
  3239.             return CvScreensInterface.handleForward(screens)
  3240.  
  3241.         return 0
  3242.  
  3243.  
  3244. #################### TRIGGERED EVENTS ##################
  3245.  
  3246.     def __eventPlaceObjectBegin(self, argsList):
  3247.         'Place Object Event'
  3248.         CvDebugTools.CvDebugTools().initUnitPicker(argsList)
  3249.  
  3250.     def __eventPlaceObjectApply(self, playerID, userData, popupReturn):
  3251.         'Place Object Event Apply'
  3252.         if (getChtLvl() > 0):
  3253.             CvDebugTools.CvDebugTools().applyUnitPicker( (popupReturn, userData) )
  3254.  
  3255.     def __eventAwardTechsAndGoldBegin(self, argsList):
  3256.         'Award Techs & Gold Event'
  3257.         CvDebugTools.CvDebugTools().cheatTechs()
  3258.  
  3259.     def __eventAwardTechsAndGoldApply(self, playerID, netUserData, popupReturn):
  3260.         'Award Techs & Gold Event Apply'
  3261.         if (getChtLvl() > 0):
  3262.             CvDebugTools.CvDebugTools().applyTechCheat( (popupReturn) )
  3263.  
  3264.     def __eventShowWonderBegin(self, argsList):
  3265.         'Show Wonder Event'
  3266.         CvDebugTools.CvDebugTools().wonderMovie()
  3267.  
  3268.     def __eventShowWonderApply(self, playerID, netUserData, popupReturn):
  3269.         'Wonder Movie Apply'
  3270.         if (getChtLvl() > 0):
  3271.             CvDebugTools.CvDebugTools().applyWonderMovie( (popupReturn) )
  3272.  
  3273. ## Platy Builder ##
  3274.    
  3275.     def __eventEditUnitNameBegin(self, argsList):
  3276.         pUnit = argsList
  3277.         popup = PyPopup.PyPopup(CvUtil.EventEditUnitName, EventContextTypes.EVENTCONTEXT_ALL)
  3278.         popup.setUserData((pUnit.getID(), CyGame().getActivePlayer()))
  3279.         popup.setBodyString(localText.getText("TXT_KEY_RENAME_UNIT", ()))
  3280.         popup.createEditBox(pUnit.getNameNoDesc())
  3281.         popup.setEditBoxMaxCharCount(25)
  3282.         popup.launch()
  3283.  
  3284.     def __eventEditUnitNameApply(self, playerID, userData, popupReturn):   
  3285.         unit = gc.getPlayer(userData[1]).getUnit(userData[0])
  3286.         newName = popupReturn.getEditBoxString(0)
  3287.         unit.setName(newName)
  3288.         if CyGame().GetWorldBuilderMode():
  3289.             WBUnitScreen.WBUnitScreen(CvPlatyBuilderScreen.CvWorldBuilderScreen()).placeStats()
  3290.             WBUnitScreen.WBUnitScreen(CvPlatyBuilderScreen.CvWorldBuilderScreen()).placeCurrentUnit()
  3291.  
  3292.     def __eventEditCityNameBegin(self, city, bRename):
  3293.         popup = PyPopup.PyPopup(CvUtil.EventEditCityName, EventContextTypes.EVENTCONTEXT_ALL)
  3294.         popup.setUserData((city.getID(), bRename, CyGame().getActivePlayer()))
  3295.         popup.setHeaderString(localText.getText("TXT_KEY_NAME_CITY", ()))
  3296.         popup.setBodyString(localText.getText("TXT_KEY_SETTLE_NEW_CITY_NAME", ()))
  3297.         popup.createEditBox(city.getName())
  3298.         popup.setEditBoxMaxCharCount(15)
  3299.         popup.launch()
  3300.    
  3301.     def __eventEditCityNameApply(self, playerID, userData, popupReturn):
  3302.         city = gc.getPlayer(userData[2]).getCity(userData[0])
  3303.         cityName = popupReturn.getEditBoxString(0)
  3304.         city.setName(cityName, not userData[1])
  3305.         if CyGame().GetWorldBuilderMode() and not CyGame().isInAdvancedStart():
  3306.             WBCityEditScreen.WBCityEditScreen(CvPlatyBuilderScreen.CvWorldBuilderScreen()).placeStats()
  3307. ## Platy Builder ##
  3308.  
  3309.  
  3310. #magister
  3311.  
  3312.     def __eventEditPlayerNameBegin(self, argsList):
  3313.         pUnit = argsList
  3314.         popup = PyPopup.PyPopup(6666, EventContextTypes.EVENTCONTEXT_ALL)
  3315.         popup.setUserData((pPlayer.getID(),))
  3316.         popup.setBodyString(localText.getText("TXT_KEY_MENU_LEADER_NAME", ()))
  3317.         popup.createEditBox(pPlayer.getName())
  3318.         popup.launch()
  3319.  
  3320.     def __eventEditPlayerNameApply(self, playerID, userData, popupReturn):
  3321.         'Edit Player Name Event'
  3322.         newName = popupReturn.getEditBoxString(0)
  3323.         if (len(newName) > 25):
  3324.             newName = newName[:25]
  3325.         gc.getPlayer(playerID).setName(newName)
  3326.         if CyGame().GetWorldBuilderMode():
  3327.             WBPlayerScreen.WBPlayerScreen(CvPlatyBuilderScreen.CvWorldBuilderScreen()).placeStats()
  3328.  
  3329.     def __eventEditCivNameBegin(self, argsList):
  3330.         pUnit = argsList
  3331.         popup = PyPopup.PyPopup(6777, EventContextTypes.EVENTCONTEXT_ALL)
  3332.         popup.setUserData((pPlayer.getID(),))
  3333.         popup.setBodyString(localText.getText("TXT_KEY_RENAME_PLAYER", ()))
  3334.         popup.setBodyString(CyTranslator().getText("TXT_KEY_MENU_CIV_DESC", ()))
  3335.         popup.createEditBox(pPlayer.getCivilizationDescription(pPlayer.getID()))
  3336.         popup.launch()
  3337.  
  3338.     def __eventEditCivNameApply(self, playerID, userData, popupReturn):
  3339.         'Edit Player Name Event'
  3340.         pPlayer = gc.getPlayer(playerID)
  3341.         szNewDesc = pPlayer.getCivilizationDescription(playerID)
  3342.         szNewShort = pPlayer.getCivilizationShortDescription(playerID)
  3343.         szNewAdj = pPlayer.getCivilizationAdjective(playerID)
  3344.         sNew = popupReturn.getEditBoxString(0)
  3345.         if (len(sNew) > 25):
  3346.             sNew = sNew[:25]
  3347.         pPlayer.setCivName(sNew,szNewShort, szNewAdj)
  3348.         if CyGame().GetWorldBuilderMode():
  3349.             WBPlayerScreen.WBPlayerScreen(CvPlatyBuilderScreen.CvWorldBuilderScreen()).placeStats()
  3350.  
  3351.     def __eventEditCivShortNameBegin(self, argsList):
  3352.         pUnit = argsList
  3353.         popup = PyPopup.PyPopup(6888, EventContextTypes.EVENTCONTEXT_ALL)
  3354.         popup.setUserData((pPlayer.getID(),))
  3355.         popup.setBodyString(localText.getText("TXT_KEY_RENAME_PLAYER", ()))
  3356.         popup.setBodyString(CyTranslator().getText("TXT_KEY_MENU_CIV_SHORT_DESC", ()))
  3357.         popup.createEditBox(pPlayer.getCivilizationShortDescription(pPlayer.getID()))
  3358.         popup.launch()
  3359.  
  3360.     def __eventEditCivShortNameApply(self, playerID, userData, popupReturn):
  3361.         'Edit Player Name Event'
  3362.         pPlayer = gc.getPlayer(playerID)
  3363.         szNewDesc = pPlayer.getCivilizationDescription(playerID)
  3364.         szNewShort = pPlayer.getCivilizationShortDescription(playerID)
  3365.         szNewAdj = pPlayer.getCivilizationAdjective(playerID)
  3366.         sNew = popupReturn.getEditBoxString(0)
  3367.         if (len(sNew) > 25):
  3368.             sNew = sNew[:25]
  3369.         pPlayer.setCivName(szNewDesc,sNew, szNewAdj)
  3370.         if CyGame().GetWorldBuilderMode():
  3371.             WBPlayerScreen.WBPlayerScreen(CvPlatyBuilderScreen.CvWorldBuilderScreen()).placeStats()
  3372.  
  3373.     def __eventEditCivAdjBegin(self, argsList):
  3374.         pUnit = argsList
  3375.         popup = PyPopup.PyPopup(6999, EventContextTypes.EVENTCONTEXT_ALL)
  3376.         popup.setUserData((pPlayer.getID(),))
  3377.         popup.setBodyString(localText.getText("TXT_KEY_RENAME_PLAYER", ()))
  3378.         popup.setBodyString(CyTranslator().getText("TXT_KEY_MENU_CIV_ADJ", ()))
  3379.         popup.createEditBox(pPlayer.getCivilizationAdjective(pPlayer.getID()))
  3380.         popup.launch()
  3381.  
  3382.     def __eventEditCivAdjApply(self, playerID, userData, popupReturn):
  3383.         'Edit Player Name Event'
  3384.         pPlayer = gc.getPlayer(playerID)
  3385.         szNewDesc = pPlayer.getCivilizationDescription(playerID)
  3386.         szNewShort = pPlayer.getCivilizationShortDescription(playerID)
  3387.         szNewAdj = pPlayer.getCivilizationAdjective(playerID)
  3388.         sNew = popupReturn.getEditBoxString(0)
  3389.         if (len(sNew) > 25):
  3390.             sNew = sNew[:25]
  3391.         pPlayer.setCivName(szNewDesc,szNewShort, sNew)
  3392.         if CyGame().GetWorldBuilderMode():
  3393.             WBPlayerScreen.WBPlayerScreen(CvPlatyBuilderScreen.CvWorldBuilderScreen()).placeStats()
  3394. #magister
  3395.  
  3396.  
  3397.     def __eventWBPlayerScriptPopupApply(self, playerID, userData, popupReturn):
  3398.         sScript = popupReturn.getEditBoxString(0)
  3399.         gc.getPlayer(userData[0]).setScriptData(CvUtil.convertToStr(sScript))
  3400.         WBPlayerScreen.WBPlayerScreen(CvPlatyBuilderScreen.CvWorldBuilderScreen()).placeScript()
  3401.         return
  3402.  
  3403.     def __eventWBCityScriptPopupApply(self, playerID, userData, popupReturn):
  3404.         sScript = popupReturn.getEditBoxString(0)
  3405.         pCity = gc.getPlayer(userData[0]).getCity(userData[1])
  3406.         pCity.setScriptData(CvUtil.convertToStr(sScript))
  3407.         WBCityEditScreen.WBCityEditScreen(CvPlatyBuilderScreen.CvWorldBuilderScreen()).placeStats()
  3408.         return
  3409.  
  3410.     def __eventWBUnitScriptPopupApply(self, playerID, userData, popupReturn):
  3411.         sScript = popupReturn.getEditBoxString(0)
  3412.         pUnit = gc.getPlayer(userData[0]).getUnit(userData[1])
  3413.         pUnit.setScriptData(CvUtil.convertToStr(sScript))
  3414.         WBUnitScreen.WBUnitScreen(CvPlatyBuilderScreen.CvWorldBuilderScreen()).placeScript()
  3415.         return
  3416.  
  3417.     def __eventWBScriptPopupBegin(self):
  3418.         return
  3419.  
  3420.     def __eventWBGameScriptPopupApply(self, playerID, userData, popupReturn):
  3421.         sScript = popupReturn.getEditBoxString(0)
  3422.         CyGame().setScriptData(CvUtil.convertToStr(sScript))
  3423.         WBGameDataScreen.WBGameDataScreen(CvPlatyBuilderScreen.CvWorldBuilderScreen()).placeScript()
  3424.         return
  3425.  
  3426.     def __eventWBPlotScriptPopupApply(self, playerID, userData, popupReturn):
  3427.         sScript = popupReturn.getEditBoxString(0)
  3428.         pPlot = CyMap().plot(userData[0], userData[1])
  3429.         pPlot.setScriptData(CvUtil.convertToStr(sScript))
  3430.         WBPlotScreen.WBPlotScreen(CvPlatyBuilderScreen.CvWorldBuilderScreen()).placeScript()
  3431.         return
  3432.  
  3433.     def __eventWBLandmarkPopupApply(self, playerID, userData, popupReturn):
  3434.         sScript = popupReturn.getEditBoxString(0)
  3435.         pPlot = CyMap().plot(userData[0], userData[1])
  3436.         iPlayer = userData[2]
  3437.         if userData[3] > -1:
  3438.             pSign = CyEngine().getSignByIndex(userData[3])
  3439.             iPlayer = pSign.getPlayerType()
  3440.             CyEngine().removeSign(pPlot, iPlayer)
  3441.         if len(sScript):
  3442.             if iPlayer == gc.getBARBARIAN_PLAYER():
  3443.                 CyEngine().addLandmark(pPlot, CvUtil.convertToStr(sScript))
  3444.             else:
  3445.                 CyEngine().addSign(pPlot, iPlayer, CvUtil.convertToStr(sScript))
  3446.         WBPlotScreen.iCounter = 10
  3447.         return
  3448. ## Platy Builder ##
  3449.  
  3450. ## FfH Card Game: begin
  3451.     def __EventSelectSolmniumPlayerBegin(self):
  3452.         iHUPlayer = gc.getGame().getActivePlayer()
  3453.  
  3454.         if iHUPlayer == -1 : return 0
  3455.         if not cs.canStartGame(iHUPlayer) : return 0
  3456.  
  3457.         popup = PyPopup.PyPopup(CvUtil.EventSelectSolmniumPlayer, EventContextTypes.EVENTCONTEXT_ALL)
  3458.  
  3459.         sResText = CyUserProfile().getResolutionString(CyUserProfile().getResolution())
  3460.         sX, sY = sResText.split("x")
  3461.         iXRes = int(sX)
  3462.         iYRes = int(sY)
  3463.  
  3464.         iW = 620
  3465.         iH = 650
  3466.  
  3467.         popup.setSize(iW, iH)
  3468.         popup.setPosition((iXRes - iW) / 2, 30)
  3469.  
  3470.         lStates = []
  3471.  
  3472.         for iPlayer in range(gc.getMAX_CIV_PLAYERS()) :
  3473.             pPlayer = gc.getPlayer(iPlayer)
  3474.  
  3475.             if pPlayer.isNone() : continue
  3476.  
  3477.             if pPlayer.isHuman() :
  3478.                 lPlayerState = cs.getStartGameMPWith(iHUPlayer, iPlayer)
  3479.                 if lPlayerState[0][0] in ["No", "notMet"] : continue
  3480.                 lStates.append([iPlayer, lPlayerState])
  3481.             else :
  3482.                 lPlayerState = cs.getStartGameAIWith(iHUPlayer, iPlayer)
  3483.                 if lPlayerState[0][0] in ["No", "notMet"] : continue
  3484.                 lStates.append([iPlayer, lPlayerState])
  3485.  
  3486.         lPlayerButtons = []
  3487.  
  3488.         popup.addDDS(CyArtFileMgr().getInterfaceArtInfo("SOMNIUM_POPUP_INTRO").getPath(), 0, 0, 512, 128)
  3489.         popup.addSeparator()
  3490.         #popup.setHeaderString(localText.getText("TXT_KEY_SOMNIUM_START", ()), CvUtil.FONT_CENTER_JUSTIFY)
  3491.         if len(lStates) == 0 :
  3492.             popup.setBodyString(localText.getText("TXT_KEY_SOMNIUM_NOONE_MET", ()))
  3493.         else :
  3494.             #popup.setBodyString(localText.getText("TXT_KEY_SOMNIUM_PLAY_WITH", ()))
  3495.             popup.addSeparator()
  3496.             popup.addSeparator()
  3497.  
  3498.             sText = u""
  3499.             for iPlayer, lPlayerState in lStates :
  3500.                 pPlayer = gc.getPlayer(iPlayer)
  3501.                 sPlayerName = pPlayer.getName()
  3502.                 iPositiveChange = gc.getLeaderHeadInfo(pPlayer.getLeaderType()).getMemoryAttitudePercent(MemoryTypes.MEMORY_SOMNIUM_POSITIVE) / 100
  3503.                 iNegativeChange = gc.getLeaderHeadInfo(pPlayer.getLeaderType()).getMemoryAttitudePercent(MemoryTypes.MEMORY_SOMNIUM_NEGATIVE) / 100
  3504.                 bShift = True
  3505.  
  3506.                 for item in lPlayerState :
  3507.  
  3508.                     sTag = item[0]
  3509.                     if (sTag == "atWar") :
  3510.                         if len(sText) > 0 : sText += localText.getText("[NEWLINE]", ())
  3511.                         sText += localText.getText("TXT_KEY_SOMNIUM_AT_WAR", (sPlayerName, ))
  3512.  
  3513.                     elif (sTag == "InGame") :
  3514.                         if len(sText) > 0 : sText += localText.getText("[NEWLINE]", ())
  3515.                         sText += localText.getText("TXT_KEY_SOMNIUM_IN_GAME", (sPlayerName, ))
  3516.  
  3517.                     elif (sTag == "relation") :
  3518.                         delay = item[1]
  3519.                         if (delay > 0) :
  3520.                             if len(sText) > 0 : sText += localText.getText("[NEWLINE]", ())
  3521.                             sText += localText.getText("TXT_KEY_SOMNIUM_GAME_DELAYED", (sPlayerName, delay))
  3522.                         else :
  3523.                             if bShift :
  3524.                                 bShift = False
  3525.                                 popup.addSeparator()
  3526.                             popup.addButton(localText.getText("TXT_KEY_SOMNIUM_GAME_RELATION", (sPlayerName, iPositiveChange, iNegativeChange)))
  3527.                             lPlayerButtons.append((iPlayer, -1))
  3528.  
  3529.                     elif (sTag == "gold") :
  3530.                         for iGold in item[1] :
  3531.                             if bShift :
  3532.                                 bShift = False
  3533.                                 popup.addSeparator()
  3534.                             if iGold == 0 :
  3535.                                 popup.addButton(localText.getText("TXT_KEY_SOMNIUM_GAME_FUN", (sPlayerName, )))
  3536.                                 lPlayerButtons.append((iPlayer, iGold))
  3537.                             else :
  3538.                                 popup.addButton(localText.getText("TXT_KEY_SOMNIUM_GAME_GOLD", (sPlayerName, iGold)))
  3539.                                 lPlayerButtons.append((iPlayer, iGold))
  3540.  
  3541.             if len(sText) > 0 :
  3542.                 popup.addSeparator()
  3543.                 popup.addSeparator()
  3544.                 popup.setBodyString(sText)
  3545.  
  3546.         popup.setUserData(tuple(lPlayerButtons))
  3547.         popup.launch()
  3548.  
  3549.     def __EventSelectSolmniumPlayerApply(self, playerID, userData, popupReturn):
  3550.         if userData :
  3551.             idButtonCliked = popupReturn.getButtonClicked()
  3552.             if idButtonCliked in range(len(userData)) :
  3553.                 iOpponent, iGold = userData[idButtonCliked]
  3554.  
  3555.                 pLeftPlayer = gc.getPlayer(playerID)
  3556.                 pRightPlayer = gc.getPlayer(iOpponent)
  3557.  
  3558.                 if not pRightPlayer.isHuman() :
  3559.                     if (cs.canStartGame(playerID)) and (pLeftPlayer.isAlive()) and (pRightPlayer.isAlive()) :
  3560.                         cs.startGame(playerID, iOpponent, iGold)
  3561.                     else :
  3562.                         CyInterface().addMessage(playerID, True, 25, CyTranslator().getText("TXT_KEY_SOMNIUM_CANT_START_GAME", (gc.getPlayer(iOpponent).getName(), )), '', 1, '', ColorTypes(7), -1, -1, False, False)
  3563.                 else :
  3564.                     if (cs.canStartGame(playerID)) and (cs.canStartGame(iOpponent)) and (pLeftPlayer.isAlive()) and (pRightPlayer.isAlive()) :
  3565.                         if (iOpponent == gc.getGame().getActivePlayer()):
  3566.                             self.__EventSolmniumAcceptGameBegin((playerID, iOpponent, iGold))
  3567.                     else :
  3568.                         CyInterface().addMessage(playerID, True, 25, CyTranslator().getText("TXT_KEY_SOMNIUM_CANT_START_GAME", (gc.getPlayer(iOpponent).getName(), )), '', 1, '', ColorTypes(7), -1, -1, False, False)
  3569.  
  3570.     def __EventSolmniumAcceptGameBegin(self, argslist):
  3571.         iPlayer, iOpponent, iGold = argslist
  3572.         if not gc.getPlayer(iOpponent).isAlive() : return 0
  3573.  
  3574.         popup = PyPopup.PyPopup(CvUtil.EventSolmniumAcceptGame, EventContextTypes.EVENTCONTEXT_ALL)
  3575.  
  3576.         popup.setUserData(argslist)
  3577.  
  3578.         popup.setHeaderString(localText.getText("TXT_KEY_SOMNIUM_START", ()))
  3579.         if iGold > 0 :
  3580.             popup.setBodyString(localText.getText("TXT_KEY_SOMNIUM_ACCEPT_GAME", (gc.getPlayer(iPlayer).getName(), iGold)))
  3581.         else :
  3582.             popup.setBodyString(localText.getText("TXT_KEY_SOMNIUM_ACCEPT_GAME_FUN", (gc.getPlayer(iPlayer).getName(), )))
  3583.  
  3584.         popup.addButton( localText.getText("AI_DIPLO_ACCEPT_1", ()) )
  3585.         popup.addButton( localText.getText("AI_DIPLO_NO_PEACE_3", ()) )
  3586.  
  3587.         popup.launch(False, PopupStates.POPUPSTATE_IMMEDIATE)
  3588.  
  3589.     def __EventSolmniumAcceptGameApply(self, playerID, userData, popupReturn):
  3590.         if userData :
  3591.             iPlayer, iOpponent, iGold = userData
  3592.             idButtonCliked = popupReturn.getButtonClicked()
  3593.             if idButtonCliked == 0 :
  3594.                 if (cs.canStartGame(iPlayer)) and (cs.canStartGame(iOpponent)) and (gc.getPlayer(iPlayer).isAlive()) and (gc.getPlayer(iOpponent).isAlive()) :
  3595.                     cs.startGame(iPlayer, iOpponent, iGold)
  3596.                 else :
  3597.                     CyInterface().addMessage(iPlayer, True, 25, CyTranslator().getText("TXT_KEY_SOMNIUM_CANT_START_GAME", (gc.getPlayer(iOpponent).getName(), )), '', 1, '', ColorTypes(7), -1, -1, False, False)
  3598.                     CyInterface().addMessage(iOpponent, True, 25, CyTranslator().getText("TXT_KEY_SOMNIUM_CANT_START_GAME", (gc.getPlayer(iPlayer).getName(), )), '', 1, '', ColorTypes(7), -1, -1, False, False)
  3599.             else :
  3600.                     CyInterface().addMessage(iPlayer, True, 25, CyTranslator().getText("TXT_KEY_SOMNIUM_REFUSE_GAME", (gc.getPlayer(iOpponent).getName(), iGold)), '', 1, '', ColorTypes(7), -1, -1, False, False)
  3601.  
  3602.     def __EventSolmniumConcedeGameBegin(self, argslist):
  3603.         popup = PyPopup.PyPopup(CvUtil.EventSolmniumConcedeGame, EventContextTypes.EVENTCONTEXT_ALL)
  3604.  
  3605.         popup.setUserData(argslist)
  3606.  
  3607.         popup.setHeaderString(localText.getText("TXT_KEY_SOMNIUM_START", ()))
  3608.         popup.setBodyString(localText.getText("TXT_KEY_SOMNIUM_CONCEDE_GAME", ()))
  3609.  
  3610.         popup.addButton( localText.getText("AI_DIPLO_ACCEPT_1", ()) )
  3611.         popup.addButton( localText.getText("AI_DIPLO_NO_PEACE_3", ()) )
  3612.  
  3613.         popup.launch(False, PopupStates.POPUPSTATE_IMMEDIATE)
  3614.  
  3615.     def __EventSolmniumConcedeGameApply(self, playerID, userData, popupReturn):
  3616.         if userData :
  3617.             idButtonCliked = popupReturn.getButtonClicked()
  3618.             if idButtonCliked == 0 :
  3619.                 cs.endGame(userData[0], userData[1])
  3620. ## FfH Card Game: end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement