def readRaceFile(fileName):
	race = Race()
	
	#Read race file
	with open(fileName, 'r') as raceFile:
		lineNumber = 1
		sections = raceFile.read().split("--------------------------\n")
		i = 0
		for section in sections:
			section = section.strip()
			if section != "":
				if i==0:
					#Names section
					nameFull, nameShort, nameSpecies, lineNumber = readRaceNames(section, fileName, lineNumber)
				elif i==1:
					#Race Sheet section
					startingUnits, startingTechs, specialAbilities, history, lineNumber =  readRaceSheet(section, fileName, lineNumber)
				elif i==2:
					#Trade Contracts section
					tradeContracts, lineNumber = readTradeContracts(section, fileName, lineNumber)
				elif i==3:
					#Home System section
					homeSystem, lineNumber = readHomeSystem(section, fileName, lineNumber)
				elif i==4:
					#Home Planet section
					homePlanet, lineNumber = readHomePlanet(section, fileName, lineNumber)
					homeSystem.addPlanetDetails(homePlanet.getName(), homePlanet.getFlavorText(), homePlanet.getResources(), homePlanet.getInfluence())
				elif i==5:
					#Objective section
					objective, lineNumber = readObjective(section, fileName, lineNumber, True)
				elif i==6:
					#Treaties section
					treaties, lineNumber = readTreaties(section, fileName, lineNumber, True)
			i += 1
	
	#Set race attributes
	race.setNameFull(nameFull)
	race.setNameShort(nameShort)
	race.setNameSpecies(nameSpecies)
	race.setExpansion("Shards of the Throne")
	for unit in startingUnits.keys():
		race.addStartingUnit(unit, startingUnits[unit])
	for tech in startingTechs:
		race.addStartingTech(tech)
	for ability in specialAbilities:
		race.addSpecialAbility(ability)
	for paragraph in history:
		race.addHistoryParagraph(paragraph)
	for contract in tradeContracts:
		race.addTradeContract(contract)
	race.addHomeSystem(homeSystem)
	
	return race, objective, treaties
def readRaceNames(fileName, races):
	with open(fileName, 'r') as namesFile:
		lineNumber = 1
		blocks = namesFile.read().split("\n\n")
		for block in blocks:
			lines = block.split("\n")
			assertNumLines(lines, 3, fileName, lineNumber)
			assertNotEmpty(lines[0], fileName, lineNumber)
			assertNotSeparator(lines[0], fileName, lineNumber)
			race = Race()
			race.setNameFull(lines[0].strip())
			lineNumber+=1
			assertNotEmpty(lines[1], fileName, lineNumber)
			assertNotSeparator(lines[1], fileName, lineNumber)
			race.setNameShort(lines[1].strip())
			lineNumber+=1
			assertNotEmpty(lines[2], fileName, lineNumber)
			assertNotSeparator(lines[2], fileName, lineNumber)
			race.setNameSpecies(lines[2].strip())
			races[race.getNameFull()] = race
			lineNumber+=2