def onGameLoad( self, argsList ) : # Init things which require a game object or other game data to exist if( not SdToolKitCustom.sdObjectExists( "AIAutoPlay", game ) ) : SdToolKitCustom.sdObjectInit( "AIAutoPlay", game, {} ) SdToolKitCustom.sdObjectSetVal( "AIAutoPlay", game, "bCanCancelAuto", True ) elif( SdToolKitCustom.sdObjectGetVal( "AIAutoPlay", game, "bCanCancelAuto" ) == None ) : SdToolKitCustom.sdObjectSetVal( "AIAutoPlay", game, "bCanCancelAuto", True )
def onGameLoad( self, argsList ) : # Init things which require a game object or other game data to exist if( not SdToolKitCustom.sdObjectExists( "AIAutoPlay", game ) ) : SdToolKitCustom.sdObjectInit( "AIAutoPlay", game, {} ) SdToolKitCustom.sdObjectSetVal( "AIAutoPlay", game, "bCanCancelAuto", True ) elif( SdToolKitCustom.sdObjectGetVal( "AIAutoPlay", game, "bCanCancelAuto" ) == None ) : SdToolKitCustom.sdObjectSetVal( "AIAutoPlay", game, "bCanCancelAuto", True ) for idx in range(0,gc.getMAX_CIV_PLAYERS()) : playerI = gc.getPlayer(idx) if(playerI.isHumanDisabled()): if(not game.isForcedAIAutoPlay(idx)): game.setAIAutoPlay(idx, 1)
def onKbdEvent(self, argsList): 'keypress handler' eventType, key, mx, my, px, py = argsList if (eventType == RevDefs.EventKeyDown): theKey = int(key) if (theKey == int(InputTypes.KB_X) and self.customEM.bShift and self.customEM.bCtrl): # Get it? Shift ... control ... to the AI #------------------------------------------------------------------------------------------------- # Lemmy101 RevolutionMP edit #------------------------------------------------------------------------------------------------- if (game.getAIAutoPlay(game.getActivePlayer()) > 0): try: bCanCancelAuto = SdToolKitCustom.sdObjectGetVal( "AIAutoPlay", game, "bCanCancelAuto") if (bCanCancelAuto is None): bCanCancelAuto = True SdToolKitCustom.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(game.getActivePlayer()) self.disableMultiCheck(game.getActivePlayer()) #------------------------------------------------------------------------------------------------- # END Lemmy101 RevolutionMP edit #------------------------------------------------------------------------------------------------- self.checkPlayer() else: self.toAIChooser() if (theKey == int(InputTypes.KB_M) and self.customEM.bShift and self.customEM.bCtrl): # Toggle auto moves if (self.LOG_DEBUG): CyInterface().addImmediateMessage("Moving your units...", "") #self.playerID = gc.getActivePlayer().getID() game.setAIAutoPlay(game.getActivePlayer(), 1) if (theKey == int(InputTypes.KB_O) and self.customEM.bShift and self.customEM.bCtrl): RevUtils.doRefortify(game.getActivePlayer())
def onGameLoad(self, argsList): # Init things which require a game object or other game data to exist if (not SdToolKitCustom.sdObjectExists("AIAutoPlay", game)): SdToolKitCustom.sdObjectInit("AIAutoPlay", game, {}) SdToolKitCustom.sdObjectSetVal("AIAutoPlay", game, "bCanCancelAuto", True) elif (SdToolKitCustom.sdObjectGetVal("AIAutoPlay", game, "bCanCancelAuto") == None): SdToolKitCustom.sdObjectSetVal("AIAutoPlay", game, "bCanCancelAuto", True) for idx in range(0, gc.getMAX_CIV_PLAYERS()): playerI = gc.getPlayer(idx) if (playerI.isHumanDisabled()): if (not game.isForcedAIAutoPlay(idx)): game.setAIAutoPlay(idx, 1)
def onKbdEvent( self, argsList ) : 'keypress handler' eventType,key,mx,my,px,py = argsList if ( eventType == RevDefs.EventKeyDown ): theKey=int(key) if( theKey == int(InputTypes.KB_X) and self.customEM.bShift and self.customEM.bCtrl ) : # Get it? Shift ... control ... to the AI #------------------------------------------------------------------------------------------------- # Lemmy101 RevolutionMP edit #------------------------------------------------------------------------------------------------- if( game.getAIAutoPlay(game.getActivePlayer()) > 0 ) : try : bCanCancelAuto = SdToolKitCustom.sdObjectGetVal( "AIAutoPlay", game, "bCanCancelAuto" ) if( bCanCancelAuto is None ) : bCanCancelAuto = True SdToolKitCustom.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( game.getActivePlayer() ) self.disableMultiCheck(game.getActivePlayer()) #------------------------------------------------------------------------------------------------- # END Lemmy101 RevolutionMP edit #------------------------------------------------------------------------------------------------- self.checkPlayer() else : self.toAIChooser() if( theKey == int(InputTypes.KB_M) and self.customEM.bShift and self.customEM.bCtrl ) : # Toggle auto moves if( self.LOG_DEBUG ) : CyInterface().addImmediateMessage("Moving your units...","") #self.playerID = gc.getActivePlayer().getID() game.setAIAutoPlay( game.getActivePlayer(), 1 ) if( theKey == int(InputTypes.KB_O) and self.customEM.bShift and self.customEM.bCtrl ) : RevUtils.doRefortify( game.getActivePlayer() )
def abdicate( self, playerID, numTurns = -1, voluntary = False ) : 'Turn over control to the AI' if( numTurns > 0 ) : self.TurnsToAuto[playerID] = numTurns if( self.TurnsToAuto[playerID] < 1 ) : return #if( voluntary and self.SHOW_NEW_LEADER_POPUP and game.getActivePlayer()==playerID ) : # popup = PyPopup.PyPopup(RevDefs.abdicatePopup,contextType = EventContextTypes.EVENTCONTEXT_ALL) # popup.setHeaderString( localText.getText("TXT_KEY_AIAUTOPLAY_NEW_LEADER", ()) ) # if( voluntary ) : # bodStr = localText.getText("TXT_KEY_AIAUTOPLAY_ABDICATE", ()) # else : # bodStr = localText.getText("TXT_KEY_AIAUTOPLAY_USURPATOR", ()) # bodStr = bodStr + localText.getText("TXT_KEY_AIAUTOPLAY_GOOD_NEWS", ()) %(self.TurnsToAuto[playerID]) # popup.setBodyString( bodStr ) # popup.launch() #else : if( voluntary ) : SdToolKitCustom.sdObjectSetVal( "AIAutoPlay", game, "bCanCancelAuto", True ) game.setAIAutoPlay( playerID, self.TurnsToAuto[playerID] )
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 SdToolKitCustom.sdObjectSetVal('Revolution', object, var, val)
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 SdToolKitCustom.sdObjectSetVal( 'Revolution', object, var, val )
def abdicate(self, playerID, numTurns=-1, voluntary=False): 'Turn over control to the AI' if (numTurns > 0): self.TurnsToAuto[playerID] = numTurns if (self.TurnsToAuto[playerID] < 1): return #if( voluntary and self.SHOW_NEW_LEADER_POPUP and game.getActivePlayer()==playerID ) : # popup = PyPopup.PyPopup(RevDefs.abdicatePopup,contextType = EventContextTypes.EVENTCONTEXT_ALL) # popup.setHeaderString( localText.getText("TXT_KEY_AIAUTOPLAY_NEW_LEADER", ()) ) # if( voluntary ) : # bodStr = localText.getText("TXT_KEY_AIAUTOPLAY_ABDICATE", ()) # else : # bodStr = localText.getText("TXT_KEY_AIAUTOPLAY_USURPATOR", ()) # bodStr = bodStr + localText.getText("TXT_KEY_AIAUTOPLAY_GOOD_NEWS", ()) %(self.TurnsToAuto[playerID]) # popup.setBodyString( bodStr ) # popup.launch() #else : if (voluntary): SdToolKitCustom.sdObjectSetVal("AIAutoPlay", game, "bCanCancelAuto", True) game.setAIAutoPlay(playerID, self.TurnsToAuto[playerID])