def checkPlayer(self): iPlayer = GAME.getActivePlayer() CyPlayer = GC.getActivePlayer() if CyPlayer and not CyPlayer.isAlive(): if GAME.getAIAutoPlay(iPlayer) > 0: try: bCanCancelAuto = SdToolKit.sdObjectGetVal( "AIAutoPlay", GAME, "bCanCancelAuto") if bCanCancelAuto is None: bCanCancelAuto = True SdToolKit.sdObjectSetVal("AIAutoPlay", GAME, "bCanCancelAuto", True) except: print "Error! AIAutoPlay: Can't find bCanCancelAuto, assuming it would be True" bCanCancelAuto = True if bCanCancelAuto: if self.refortify: RevUtils.doRefortify(iPlayer) self.disableMultiCheck(iPlayer) self.checkPlayer() popup = PyPopup.PyPopup( RevDefs.pickHumanPopup, contextType=EventContextTypes.EVENTCONTEXT_ALL, bDynamic=False) popup.setHeaderString( TRNSLTR.getText("TXT_KEY_AIAUTOPLAY_PICK_CIV", ())) popup.setBodyString( TRNSLTR.getText("TXT_KEY_AIAUTOPLAY_CIV_DIED", ())) popup.addSeparator() popup.createPythonPullDown( TRNSLTR.getText("TXT_KEY_AIAUTOPLAY_TAKE_CONTROL_CIV", ()), 1) for iPlayerX in range(GC.getMAX_PC_PLAYERS()): if iPlayerX == iPlayer: continue CyPlayerX = GC.getPlayer(iPlayerX) if CyPlayerX.isAlive(): popup.addPullDownString( TRNSLTR.getText("TXT_KEY_AIAUTOPLAY_OF_THE", ()) % (CyPlayerX.getName(), CyPlayerX.getCivilizationDescription(0)), iPlayerX, 1) popup.popup.setSelectedPulldownID(iPlayer, 1) popup.addSeparator() popup.addButton(TRNSLTR.getText("TXT_KEY_AIAUTOPLAY_NONE", ())) print 'Launching pick human popup' popup.launch() for i in range(GC.getMAX_PC_TEAMS()): CyPlayer.setEspionageSpendingWeightAgainstTeam( i, CyPlayer.getEspionageSpendingWeightAgainstTeam(i) / 10)
def onGameLoad(self, argsList): # Init things which require a game object or other game data to exist if not SdToolKit.sdObjectExists("AIAutoPlay", GAME): SdToolKit.sdObjectInit("AIAutoPlay", GAME, {}) SdToolKit.sdObjectSetVal("AIAutoPlay", GAME, "bCanCancelAuto", True) elif SdToolKit.sdObjectGetVal("AIAutoPlay", GAME, "bCanCancelAuto") is None: SdToolKit.sdObjectSetVal("AIAutoPlay", GAME, "bCanCancelAuto", True) for i in range(GC.getMAX_PC_PLAYERS()): CyPlayer = GC.getPlayer(i) if CyPlayer.isHumanDisabled() and not GAME.isForcedAIAutoPlay(i): GAME.setAIAutoPlay(i, 1)
def onCombatResult(argsList): CyUnitW, CyUnitL = argsList # Spartacus Capture Event if CyUnitW.getUnitClassType() == giSparticus: # Capture % Random # 0 to 3 or 25% if not GAME.getSorenRandNum(4, "Gods"): pClearPlot = findClearPlot(CyUnitL) CyPlot = CyUnitL.plot() if pClearPlot != -1 and CyPlot.getNumUnits() == 1: CyPlot = CyUnitL.plot() CyUnitL.setXY(pClearPlot.getX(), pClearPlot.getY(), False, True, True) else: CyPlot = CyUnitW.plot() iPlayer = CyUnitW.getOwner() GC.getPlayer(iPlayer).initUnit(giGladiator, CyPlot.getX(), CyPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH).finishMoves() CyUnitL.setDamage(100000, False) msg = TRNSLTR.getText("TXT_KEY_SPARTACUS_CAPTURE_SUCCESS",()) icon = ',Art/Interface/Buttons/Units/ICBM.dds,Art/Interface/Buttons/Warlords_Atlas_1.dds,3,11' CvUtil.sendMessage(msg, iPlayer, 15, icon, ColorTypes(44), CyUnitL.getX(), CyUnitL.getY(), True, True, 0, "", False) # Field Medic if CyUnitW.isHasPromotion(giFieldMedic): # 10% chance if not GAME.getSorenRandNum(10, "Gods"): if not SDTK.sdObjectExists('Heroes', CyUnitW): iHealTurn = -1 else: iHealTurn = SDTK.sdObjectGetVal( 'Heroes', CyUnitW, 'HealTurn' ) if iHealTurn == None or GAME.getGameTurn() > iHealTurn: CyUnitW.setDamage(0, False) if not SDTK.sdObjectExists('Heroes', CyUnitW): SDTK.sdObjectInit('Heroes', CyUnitW, {}) SDTK.sdObjectSetVal('Heroes', CyUnitW, 'HealTurn', GAME.getGameTurn())
def onKbdEvent(self, argsList): eventType, key, mx, my, px, py = argsList if eventType == 6 and self.customEM.bShift and self.customEM.bCtrl: if key == InputTypes.KB_X: iPlayer = GAME.getActivePlayer() if GAME.getAIAutoPlay(iPlayer) > 0: try: bCanCancelAuto = SdToolKit.sdObjectGetVal( "AIAutoPlay", GAME, "bCanCancelAuto") if bCanCancelAuto is None: bCanCancelAuto = True SdToolKit.sdObjectSetVal("AIAutoPlay", GAME, "bCanCancelAuto", True) except: print "Error! AIAutoPlay: Can't find bCanCancelAuto, assuming it would be True" bCanCancelAuto = True if bCanCancelAuto: if self.refortify: RevUtils.doRefortify(iPlayer) self.disableMultiCheck(iPlayer) self.checkPlayer() else: self.toAIChooser() elif key == InputTypes.KB_M: # Toggle auto moves if self.LOG_DEBUG: CyInterface().addImmediateMessage( TRNSLTR.getText("TXT_KEY_AIAUTOPLAY_MOVING", ()), "") GAME.setAIAutoPlay(GAME.getActivePlayer(), 1) elif key == InputTypes.KB_O: RevUtils.doRefortify(GAME.getActivePlayer())
def revObjectSetVal(object, var, val): if (not revObjectExists(object)): if (isinstance(object, CvPythonExtensions.CyPlayer)): print "RevData: Initializing player object" initPlayer(object) elif (isinstance(object, CvPythonExtensions.CyCity)): print "RevData: Initializing city object" initCity(object) else: # SDTK will fail print "ERROR: Not recognized: ", object pass return SdToolKit.sdObjectSetVal('Revolution', object, var, val)