## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005

from CvPythonExtensions import *
import CvUtil
import PyHelpers
import CvEventManager
import sys
import CvGreatPersonScreen
import RandomNameUtils

# Change the value to enable or disable the features from the Great Person Mod.
# Default value is true
g_bGreatPersonModFeaturesEnabled = true

gc = CyGlobalContext()

PyPlayer = PyHelpers.PyPlayer


# globals
###################################################
class CvGreatPersonModEventManager:

	def __init__(self, eventManager):

		eventManager.addEventHandler("greatPersonBorn", self.onGreatPersonBorn)

	"""
	# Test code to make sure that we can go through the vanilla great person
	# names and test the random names
	def onMouseEvent(self, argsList):
	
		gc.getPlayer(0).getCapitalCity().createGreatPeople(gc.getInfoTypeForString("UNIT_ARTIST"), true)
	"""		

	# GreatPerson Mod -------- begin
	def onGreatPersonBorn(self, argsList):
		'Great Person Born'
		pUnit, iPlayer, pCity = argsList
		player = PyPlayer(iPlayer)

		if(not g_bGreatPersonModFeaturesEnabled):
			return
                
		# Check if we should even show the popup:
		if pUnit.isNone() or pCity.isNone():
			return
		    
		#If Person doesn't have unique name, give him a random one
		if(len(pUnit.getNameNoDesc()) == 0):
                    iCivilizationType = player.player.getCivilizationType()
                    pUnit.setName(RandomNameUtils.getRandomCivilizationName(iCivilizationType))
                    

		#Show fancy lil popup if *we* got the great person:
		iActivePlayer = CyGame().getActivePlayer()
		if iActivePlayer == iPlayer:
			CvGreatPersonScreen.CvGreatPersonScreen().interfaceScreen(pUnit, pCity)
	# GreatPerson Mod -------- end