• Civ7 is already available! Happy playing :).

Feature question/request

No here has not.

JosEPh
 
Looking at the code (one python module only) it seems almost trivial to do. Wonder why it has not been done? It is something I would like to have.

Hum, I don't see anything to save the mission location so they are probably lost and need to be reset if you exit.
 
Hum, I don't see anything to save the mission location so they are probably lost and need to be reset if you exit.

I've used the BTS version of it and and if I remember correctly (I haven't played vanilla BTS in quite some time) the mission information does get preserved even if you exit.
 
I've been tinkering with this off and on since my original post to try and make it into a mod that can be loaded in AND. My conclusion is that I'm making zero progress with regard to understanding Python and the API, so advice, assistance or smacks up side the head would be appreciated. ;)


Code:
## A New Dawn Mod Code
##

# based on Repeating Air Recon Mission mod by rickb
# 2007 version:
# http://forums.civfanatics.com/showthread.php?t=242923
#
# 2005 version:
# http://forums.civfanatics.com/showthread.php?t=143835
#
# To use:
# with a unit selected that can conduct an air recon mission press R or click on Recon button
# holding down alt while setting recon mission target will add the unit to the recon queue.
# shift+R will execute all recon missions queued up in this manner.

# add unit to queue
# Check mission type, if mission is recon check if alt key is down, if so add unit to auto recon queue

# remove unit from queue manually
# If unit is in queue and R and control are pressed remove from queue

# execute queue
# If R and shift are pressed execute auto recon queue
#		 already done in the rickb mod

# remove unit from queue if lost, killed or gifted
# If unit is killed, lost or given to another player remove from queue
#		 already done in the rickb mod
#		 unit given to another player needs to be done

# remove unit from queue if moved
# If unit is moved remove from queue
#		 already done in the rickb mod?

# Save auto recon queue as part of save file

# Load auto recon queue from save file

from CvPythonExtensions import *
import CvUtil
import CvScreensInterface
import CvDebugTools
import CvWBPopups
import PyHelpers
import Popup as PyPopup
import CvCameraControls
import CvTopCivs
import sys
import CvWorldBuilderScreen
import CvAdvisorUtils
import CvTechChooser
import autolog

gc = CyGlobalContext()
localText = CyTranslator()
PyPlayer = PyHelpers.PyPlayer
PyInfo = PyHelpers.PyInfo


class AutoReconEventManager:
	def __init__(self, eventManager):
		self.bShift = False

		self.EventKeyDown=6
		
		self.autorecon = {}
		
		eventManager.addEventHandler("kbdEvent",self.onKbdEvent)
		self.eventManager = eventManager
		
		self.EventHandlerMap = {
			'kbdEvent' 				: self.onKbdEvent,
			'unitSetXY' 			: self.onUnitSetXY,
			'unitKilled'			: self.onUnitKilled,
			'unitLost'				: self.onUnitLost,
			'unitGifted'			: self.onUnitGifted,
		}


	def onKbdEvent(self, argsList):
		'keypress handler - return 1 if the event was consumed'

		eventType,key,mx,my,px,py = argsList
		game = gc.getGame()
		
		if ( eventType == self.EventKeyDown ):
			theKey=int(key)
			
			CvCameraControls.g_CameraControls.handleInput( theKey )
			
			self.autoReconKdbEvent(theKey)
		return 0

	def onUpdate(self, argsList):
		'Called every frame'
		fDeltaTime = argsList[0]

		# allow camera to be updated
		CvCameraControls.g_CameraControls.onUpdate( fDeltaTime )
		
		player = gc.getPlayer(CyGame().getActivePlayer())

		(unit, iter) = player.firstUnit(false)
		while (unit):
			if(unit.getGroup().getLengthMissionQueue() > 0):
				mission = unit.getGroup().getMissionFromQueue(0)
				if(mission.eMissionType == MissionTypes.MISSION_RECON):
					autorecon[unit.getID()] = (unit, mission.iData1, mission.iData2)
				elif (unit.getID() in autorecon):
					del autorecon[unit.getID()]
			(unit, iter) = player.nextUnit(iter, false)

	def onUnitSetXY(self, argsList):
		'units xy coords set manually'
		pPlot,pUnit = argsList
		player = PyPlayer(pUnit.getOwner())
		unitInfo = PyInfo.UnitInfo(pUnit.getUnitType())
		
		self.autoReconRemoveUnit(pUnit)

		if (not self.__LOG_MOVEMENT):
			return
	
	def onUnitKilled(self, argsList):
		'Unit Killed'
		unit, iAttacker = argsList
		player = PyPlayer(unit.getOwner())
		attacker = PyPlayer(iAttacker)
		
		self.autoReconRemoveUnit(unit)
		
		if (not self.__LOG_UNITKILLED):
			return
		CvUtil.pyPrint('Player %d Civilization %s Unit %s was killed by Player %d' 
			%(player.getID(), player.getCivilizationName(), PyInfo.UnitInfo(unit.getUnitType()).getDescription(), attacker.getID()))

	def onUnitLost(self, argsList):
		'Unit Lost'
		unit = argsList[0]
		player = PyPlayer(unit.getOwner())

		self.autoReconRemoveUnit(unit)

		if (not self.__LOG_UNITLOST):
			return
		CvUtil.pyPrint('%s was lost by Player %d Civilization %s' 
			%(PyInfo.UnitInfo(unit.getUnitType()).getDescription(), player.getID(), player.getCivilizationName()))

	def onUnitGifted(self, argsList):
		'Unit is gifted from one player to another'
		pUnit, iGiftingPlayer, pPlotLocation = argsList
		
		self.autoReconRemoveUnit(unit)
			
	def autoReconRemoveUnit(self, unit):
		if(pUnit.getID() in self.autorecon):
			CvUtil.pyPrint("autorecon remove")
			del self.autorecon[unit.getID()]

	def autoReconKdbEvent(self, theKey):	
		if (theKey == int(InputTypes.KB_R) and self.bShift):
			CvUtil.pyPrint("autorecon shift R")
			for data in self.autorecon.values():
				unit = data[0]
				x = data[1]
				y = data[2]
				CvUtil.pyPrint("autorecon execute %d %d" %(x,y))
				unit.getGroup().pushMission(MissionTypes.MISSION_RECON,x,y,0,False,True,MissionAITypes.NO_MISSIONAI,unit.plot(),unit)
		
		if (theKey == int(InputTypes.KB_R) ):
			player = gc.getPlayer(gc.getGame().getActivePlayer())
			(unit, iter) = player.firstUnit(false)
			mission = unit.getGroup().getMissionType(0)
			#eMissionType = pUnit.getGroup().getMissionType(0)
			
			if(mission == MissionTypes.MISSION_RECON and self.bAlt):
				CvUtil.pyPrint("autorecon add")
				
				while (unit):
					if (unit.IsSelected()):
						CvUtil.pyPrint("autorecon add")
						plot = unit.getReconPlot()
						self.autorecon[unit.getID()] = (unit,plot.getX(),plot.getY())
					(unit, iter) = player.nextUnit(iter, false)
 
Top Bottom