Code:
def onKbdEvent(self, argsList):
'Keypress handler - return 1 if the event was consumed'
eventType, key, mx, my, px, py = argsList
if self.bAllowCheats:
# Notify debug tools of input to allow it to override the control
argsList = (eventType, key, self.bCtrl, self.bShift, self.bAlt, mx, my, px, py, CyGame().isNetworkMultiPlayer())
if CvDebugTools.g_CvDebugTools.notifyInput(argsList):
return 0
if eventType == self.EventKeyDown:
# Use 'if' instead of 'elif' or keys will not be detected
theKey = int(key)
CvCameraControls.g_CameraControls.handleInput(theKey)
# AI Auto Play
if CyGame().getAIAutoPlay():
if theKey == int(InputTypes.KB_SPACE) or theKey == int(InputTypes.KB_ESCAPE):
CyGame().setAIAutoPlay(0)
return 1
# Tenets Advisor
if theKey == int(InputTypes.KB_F8) and not self.bShift:
CvScreensInterface.showTenetsScreen()
return 1
# Strategy Overlay
if theKey == int(InputTypes.KB_X):
if self.bCtrl:
CvStrategyOverlay.toggleDotMapEditMode()
return 1
elif self.bAlt:
CvStrategyOverlay.toggleDotMapVisibility()
return 1
# Break Endless AI Turn
if theKey == int(InputTypes.KB_C) and self.bCtrl:
for iPlayer in xrange(gc.getMAX_PLAYERS()):
pPlayer = gc.getPlayer(iPlayer)
if not pPlayer.isNone():
if pPlayer.isTurnActive():
CyMessageControl().sendModNetMessage(666, iPlayer, -1, -1, -1)
return 1
# Dump OOSLog
if theKey == int(InputTypes.KB_K) and self.bCtrl:
CyMessageControl().sendModNetMessage(667, -1, -1, -1, -1)
return 1
return 0
def onModNetMessage(self, argsList):
'Called whenever CyMessageControl().sendModNetMessage() is called - this is all for you modders!'
iData1, iData2, iData3, iData4, iData5 = argsList
# Colonists (iData1 = MessageID, iData2 = PlayerID, iData3 = CityID)
if iData1 == 700:
pPlayer = gc.getPlayer(iData2)
pCity = pPlayer.getCity(iData3)
for iBuildingClass in HR.Unit.ColonistFreeBuildingClass:
iBuilding = HR.getPlayerBuilding(pPlayer, iBuildingClass)
if iBuilding > -1:
pCity.setNumRealBuilding(iBuilding, 1)
self.onBuildingBuilt((pCity, iBuilding))
# Founding Religions
elif iData1 == HR.Mission['MISSION_FOUND_RELIGION']:
pPlayer = gc.getPlayer(iData2)
pUnit = pPlayer.getUnit(iData3)
if pUnit.movesLeft() > 0:
HR_Religion.foundReligion(iData4, pPlayer, pUnit.plot().getPlotCity())
pUnit.kill(False, -1)
# Reformation
elif iData1 == HR.Mission['MISSION_REFORMATION']:
pPlayer = gc.getPlayer(iData2)
pUnit = pPlayer.getUnit(iData3)
if pUnit.movesLeft() > 0:
HR_Religion.Tenets().callReformation(pPlayer, [])
pUnit.kill(False, -1)
elif iData1 == HR.Mission['MISSION_REFORMATION_RESOLVE']:
pPlayer = gc.getPlayer(iData2)
TenetList = []
TenetDict = {}
TenetString = str(iData3)
iCount = 0
for iTenet in xrange(gc.getNumCivicInfos()):
if not HR_Religion.Tenets().isTenet(iTenet):
if pPlayer.isCivic(iTenet):
TenetList.append(iTenet)
iCount += 1
else:
iCategory = gc.getCivicInfo(iTenet).getCivicOptionType()
iPosition = iCategory - iCount
if not (iPosition) in TenetDict.keys():
TenetDict[iPosition] = []
TenetDict[iPosition].append(iTenet)
for i in xrange(len(TenetString)):
key = i
index = int(TenetString[i]) - 1
TenetList.append(TenetDict[key][index])
bAnarchy = True
if iData4 == 0:
bAnarchy = False
HR_Religion.Tenets().doReformation(pPlayer, TenetList, bAnarchy)
# Repentance
elif iData1 == HR.Mission['MISSION_REPENTANCE']:
pPlayer = gc.getPlayer(iData2)
pUnit = pPlayer.getUnit(iData3)
if pUnit.movesLeft() > 0:
HR_Religion.Tenets().doRepentance(pPlayer)
pUnit.kill(False, -1)
# Great Temples
elif iData1 == HR.Mission['MISSION_GREAT_TEMPLE']:
pPlayer = gc.getPlayer(iData2)
pUnit = pPlayer.getUnit(iData3)
pCity = pUnit.plot().getPlotCity()
pCity.setNumRealBuilding(iData4, 1)
self.onBuildingBuilt((pCity, iData4))
pUnit.kill(False, -1)
# Inquisition
elif iData1 == HR.Mission['MISSION_INQUISITION']:
pPlayer = gc.getPlayer(iData2)
pUnit = pPlayer.getUnit(iData3)
if pUnit.movesLeft() > 0:
HR_Religion.Inquisition().doInquisition(pUnit, iData4, pPlayer)
# Widgets
elif iData1 == HR.Widget['WIDGET_HR_CHANGE_SPECIALIST']:
pCity = HR.decodeCity(iData2)
pCity.alterSpecialistCount(iData3, iData4)
# Break Endless AI Turn
elif iData1 == 666:
pPlayer = gc.getPlayer(iData2)
CyInterface().addImmediateMessage("DEBUG: Attempting to break endless AI turn!", "")
print "### BREAK ENDLESS AI TURN ###"
print "Active Player: %d (%s)" % (pPlayer.getID(), gc.getCivilizationInfo(pPlayer.getCivilizationType()).getDescription())
(loopUnit, iter) = pPlayer.firstUnit(False)
while(loopUnit):
if loopUnit.movesLeft() > 0 or loopUnit.getGroup().readyToMove(False):
print "- Unit %d: %s at (%d, %d) Moves = %d, Cargo = %d, Group = %d" % (loopUnit.getID(), loopUnit.getName(), loopUnit.getX(), loopUnit.getY(), loopUnit.movesLeft(), loopUnit.getCargo(), loopUnit.getGroupID())
loopUnit.finishMoves()
(loopUnit, iter) = pPlayer.nextUnit(iter, False)
return 1
# Dump OOSLog
elif iData1 == 667:
OOSLogger.doOOSCheck(True)
print "Modder's net message!"
CvUtil.pyPrint('onModNetMessage')