Quick Modding Questions Thread

How do you assign starting units to a civ?

I thought it was the ifreeunits bit in the civinfo.xml, but in my file it only has settler there, and everyone also starts with a scout.. and when i try to add an extra unit, they still only have a settler and scout (this may be because the extra unit i add has a ibuild of -1, I don't know) But I still cannot figure out where the scout is coming from and therefore where i need to go to change him to something else?
 
Lib check out EraInfos it has iStartingDefenseUnits, iStartingWorkerUnits, iStartingExploreUnits, and iStartingUnitMultiplier. In the normal game everyone starts with one explore unit in the ancient era. This means a warrior for many, but those with the correct technology start with a scout instead.
 
I think forests are often directly handled in mapscripts which is much more complicated, however I have added ruins, vaults and fallout all using this method and it is surprisingly effective. It depends how much more of whatever it is you want to add you want to add...and if it is actually forests or something else, forests and jungles i think are one of the many weird exceptions that firaxis makes to there rules of how they control things, but it you wanted to cover your map with forest on every square that can take a forest, whack iappearance up high enough (like 10000) and I think you will get that result, it happened for me with ruins..
 
Anyone have any idea what to do about this Python exception?

UnboundLocalError:local variable 'Unit Type' referenced before assignment

I have two theories about what may be causing it, but not how to solve it.

Possible Causes:

1. I just added Orions Python Immagration Mod (I think it was orion) and I have not done something in the python quite right...

2. I have a unit that cannot be built, only upgraded to, that one faction has as it's starting unit..

A following exception references onUnitBuilt..

EDIT: ok it is a definate bit of immagrant code:

Spoiler :
Code:
	def onUnitBuilt(self, argsList):
		if (AutologOpt.isLogBuildCompleted()):
			pCity = argsList[0]
			unit = argsList[1]
			if pCity.getOwner() == CyGame().getActivePlayer():
				message = BugUtil.getText("TXT_KEY_AUTOLOG_FINISH_UNIT", (pCity.getName(), gc.getUnitInfo(unit.getUnitType()).getDescription()))
				Logger.writeLog(message, vColor="Purple")
# Immigration Mod
			iOwner = city.getOwner()
			pPlayer = gc.getPlayer(iOwner)
			UnitType = unit.getUnitType()
			iImmigrant = gc.getInfoTypeForString("UNIT_IMMIGRANT")
			intCity = Immigration.getLeastPopulatedCity(iOwner)
		
		if UnitType == iImmigrant: [COLOR="Red"]'this seems to be the line it don't like'[/COLOR]
			#CyInterface().addImmediateMessage("B", "")
			if pPlayer.isAlive() and not pPlayer.isBarbarian():
				ReducedCityPopulation = city.getPopulation() - 2
				city.setPopulation(ReducedCityPopulation)				
				if intCity != -1:
					MigrationCity = pPlayer.getCity(intCity)
					Immigration.doImmigrantPlacementAI(unit, MigrationCity)					
# End Immigration Mod
 
UnitType is only defined when Autolog is completed since the variables definitions are after that if statement.
 
The 5 lines after the first immigration mod comment need to be indented 1 tab level less. As it is now they are "inside" the first if statement, which is wrong.
 
How do you assign starting units to a civ?

I thought it was the ifreeunits bit in the civinfo.xml, but in my file it only has settler there, and everyone also starts with a scout.. and when i try to add an extra unit, they still only have a settler and scout (this may be because the extra unit i add has a ibuild of -1, I don't know)

Yes, you can do it in the CIV4CivilizationInfos.xml file. No, the icost of -1 doesn't prevent it (just tested it). You don't even need all the Prereqs (technology, bonus, etc). So I don't know what is so special about your unit. Is your Civilization allowed to have such a unit? Because if you prevent them from training one and if you try to give one for free at the start, there could be a conflict.
 
Hey guys, I get this python error for this bit of code, i am just not sure what I need to do to fix it...

NameError: global name 'city' is not defined

Spoiler :
Code:
def onUnitBuilt(self, argsList):
		if (AutologOpt.isLogBuildCompleted()):
			pCity = argsList[0]
			unit = argsList[1]
			if pCity.getOwner() == CyGame().getActivePlayer():
				message = BugUtil.getText("TXT_KEY_AUTOLOG_FINISH_UNIT", (pCity.getName(), gc.getUnitInfo(unit.getUnitType()).getDescription()))
				Logger.writeLog(message, vColor="Purple")
# Immigration Mod
		iOwner = city.getOwner()         [COLOR="Red"]<--this is the line[/COLOR]
		pPlayer = gc.getPlayer(iOwner)
		UnitType = unit.getUnitType()
		iImmigrant = gc.getInfoTypeForString("UNIT_IMMIGRANT")
		intCity = Immigration.getLeastPopulatedCity(iOwner)
		
		if UnitType == iImmigrant:
			#CyInterface().addImmediateMessage("B", "")
			if pPlayer.isAlive() and not pPlayer.isBarbarian():
				ReducedCityPopulation = city.getPopulation() - 2
				city.setPopulation(ReducedCityPopulation)				
				if intCity != -1:
					MigrationCity = pPlayer.getCity(intCity)
					Immigration.doImmigrantPlacementAI(unit, MigrationCity)					
# End Immigration Mod

do I need to bring the first five lines of imagration back <-- 1 tab so that they are outside the first if statement?
 
The part that looks like this
Code:
		if (AutologOpt.isLogBuildCompleted()):
			pCity = argsList[0]
			unit = argsList[1]
should look like this
Code:
		pCity = argsList[0]
		unit = argsList[1]
		if (AutologOpt.isLogBuildCompleted()):
That is, move the declarations before that first "if" so they are available to things not inside it, making sure their indentation level is 1 less tab than it used to be (and matches the "if" that is now after them).

Then also do what The_J said above and change the "city" to "pCity" on the line having the problem. Also do that change in the two places after that where it just uses "city"; there is a "city.getPopulation" and a "city.setPopulation".

(Alternatively you could change all the existing "pCity" usage in the function to be just "city". But "pWhatever" is actually the standard used in the Python that comes with Civ for variables that are the actual objects. Technically, based on that standard, the "unit" variable should be "pUnit" everywhere in the function, but since that is already just "unit" everywhere I would suggest you just leave it as-is.)

There would be fewer of these merging issues if everyone would just use the same variable naming standard used by the existing Civ Python...
 
Top Bottom