# Starting Points

from CvPythonExtensions import *
import BugUtil
###Starting points part 1 start###
import StartingPointsUtil
import BugPath
###Starting points part 1 end###
gc = CyGlobalContext()

def onGameStart(argsList):
	'Called at the start of the game'
	#Starting points part 2 start#
	MapName = CyMap().getMapScriptName()
	if ((".civ" in MapName) or (".Civ" in MapName)) and (not gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ADVANCED_START)) and (gc.getGame().getGameTurnYear() == gc.getDefineINT("START_YEAR")):
		if "civbeyondswordwbsave" in MapName:
			MapName = MapName[0:-21]
		if "CivBeyondSwordWBSave" in MapName:
			MapName = MapName[0:-21]
		if "CivWarlordsWBSave" in MapName:
			MapName = MapName[0:-18]
		if "Civ4WorldBuilderSave" in MapName:
			MapName = MapName[0:-21]
		if "civ4worldbuildersave" in MapName:
			MapName = MapName[0:-21]
						
		Debuging = False
		AddPositionsToMap = False
		bNoIOError = True;
		try:
			MyFile=open("Mods/"+BugPath.getModFolder()+"/Assets/XML/CustomXML/"+MapName+"_StartingPoints.xml")
		except IOError, err:
			iNameLength = len(MapName)
			iCutPoint = -1
			for iChar in xrange(iNameLength):
				if MapName[iChar]=="\\":
					iCutPoint = iChar
			MapName = MapName[iCutPoint:iNameLength]
			try:
				MyFile=open("Mods/"+BugPath.getModFolder()+"/Assets/XML/CustomXML/"+MapName+"_StartingPoints.xml")
			except IOError, err:
				bNoIOError = False;
		if(bNoIOError == True):
			StartingPointsUtil.ReadMyFile(MyFile,Debuging,AddPositionsToMap)
			MyFile.close()
	#Starting points part 2 end#
