Modders Guide to FfH2

Im trying to create a unique unit for the Hippus which replaces the normal Champion unit. I have no problem actually creating the unit in Civ4UnitInfos (I can place it in world builder), but I cant build the unit in game or upgrade to it from an axeman. Instead it just upgrades to the normal champion. What other file do I need to change?

Under CIV4CivilizationInfos.xml, for every civ, there is a section called Units which defines what UUs they have. In FFH it's also used to prevent many civs from building unique world units like dragons, Apocalypse riders, and heroes (except for their civs).

Code:
            <Units>
[COLOR="Red"]                <Unit>
                    <UnitClassType>UNITCLASS_CHAMPION</UnitClassType>
                    <UnitType>UNIT_HIPPUS_CHAMPION</UnitType>
                </Unit>[/COLOR]
                <Unit>
                    <UnitClassType>UNITCLASS_DEMAGOG</UnitClassType>
                    <UnitType>NONE</UnitType>
                </Unit>
                <Unit>
                    <UnitClassType>UNITCLASS_FLAGBEARER</UnitClassType>
                    <UnitType>NONE</UnitType>
                </Unit>
                <Unit>
                    <UnitClassType>UNITCLASS_MERCENARY</UnitClassType>
                    <UnitType>UNIT_MERCENARY_MOUNTED</UnitType>
                </Unit>

HIPPUS_CHAMPION would be your unit. It tells the game that, instead of building UNITCLASS_CHAMPION's default UNIT_CHAMPION that the Hippus build UNIT_HIPPUS_CHAMPION.
 
That's an easy one, you need to edit CIV4CivilizationInfos.xml to actually give a civ a UU.

Code:
                <Unit>
                    <UnitClassType>UNITCLASS_CHAMPION</UnitClassType>
                    <UnitType>UNIT_CHAMPION_HIPPUS_UU</UnitType>
                </Unit>
 
One of the players of my mod has been getting a weird error when using the civ the Legion of D'Tesh. It is a fallow civ and seems to be making a divide by zero error in CvCityAI::AI_bestPlotBuild.
Could it be part of Fallow or just a random thing?



Attached is the savegame with the CtD if anyone wants to test it out.

Edit: Found another thing. It seems to occur after the Blight. Perhaps it is due to a massive influx of unhealth.
 

Attachments

I'd like to modify the way Assimilation works so that new Elohim cities (founded by Elohim) take on aspect of any nearby civilitions (so no conquest required for this feature). This is sort of a "super-assimilation" version of Elohim. I'm good enough with python to find nearby civilition, but I'm wondering if there is any easy way to change original owner (in python) after or as a city is built. Something like pCity.setOriginalOwner(pPlayer) would be nice -- but I'm sure that's too easy. Some kludges I've thought of that involve EventManager intervention: Put a point of the other civ's culture on the tile before the Elohim city is built. Found the city (in python) with the other civ as owner, then transfer ownership to Elohim (this would cause all kinds of headache with city names and such). Since I don't know how Assimilation works, I'm not sure how best to kludge. I'm somewhat resistant to learning SDK/dll changes. This is for a small modmod with only a few xml, python changes, hopefully. Any one have a solution for me?
 
If you are willing to modify the DLL very slightly, you need to expose CvCity::setPreviousOwner to python control and then you can do it almost exactly how you stated. Short of that, you would have to create the city under the other person, then auto-gift it to the Elohim to pull it off with only python and existing tools.
 
I am getting some problems with my code for reviving units killed near power plant. All this is Orbis (mechanos thing), but I have linked it to soul forge code in onUnitKilled in CvEventManager.py

Here is the current code (including soul forge bit):
Code:
if pCity.getNumRealBuilding(iSoulForge) > 0:
	pCity.changeProduction(unit.getExperience() + 10)
	CyInterface().addMessage(pCity.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_SOUL_FORGE",()),'AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/Buildings/Soulforge.dds',ColorTypes(7),pCity.getX(),pCity.getY(),True,True)

if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_POWER_PLANT')) > 0:
	if pCity.getOwner() == unit.getOwner():
		if CyGame().getSorenRandNum(100, "Revive Chance") >= 70:
			newUnit = pPlayer.initUnit(unit.getUnitType(), pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			unit.setDamage(95, -1)
			newUnit.convert(unit)
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REVIVED'), True)
			iXP = unit.getExperience() / 3
			newUnit.setExperience(iXP, -1)
Well, it works. Even too well. Sometimes I get 3 or 4 units out of one killed - a bit too much to my taste :crazyeye:. Any ideas what is causing it? I can't figure it out.
Also, any way to disable a free promotion pick for revived units? Currently they can get a new one every time unit gets revived.
 
I got this sometimes when I was making Necromancy for my mod. It doesn't look like it would fit anywhere in your code because mine deals with units but when I ran this it seemed to stop making multiple units.

Code:
			for iiX in range(iX-1, iX+2, 1):
				for iiY in range(iY-1, iY+2, 1):
					pPlot2 = CyMap().plot(iiX,iiY)
					if pPlot2.isCity():
						pCity = pPlot2.getPlotCity()
						if pCity.getNumRealBuilding(iSoulForge) > 0:
							pCity.changeProduction(unit.getExperience() + 10)
							CyInterface().addMessage(pCity.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_SOUL_FORGE",()),'AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/Buildings/Soulforge.dds',ColorTypes(7),pCity.getX(),pCity.getY(),True,True)
					[COLOR="Blue"]for i in range(pPlot2.getNumUnits(), -1, -1):[/COLOR]


Also, this will change the FreePromotions
Code:
newunit.changeFreePromotionPick()
 
The Convert Command will also kill the unit, so is it possible that you are calling this function multiple times? Not sure why it would bother to stop from being an endless loop if that was indeed the case though...

If you imported my CvUnit::setMustDie function, then you could tap into that one to prevent re-animation of units which convert (which this function as written would most likely do, assuming that is also an exploit available for Soul Forge exploitation, see if upgrading a unit while in range of the city gives you a free copy of what the unit used to be...). If you want to use that tag, then you would preface your function in python with an "if not pUnit.isMustDie()"
 
The Convert Command will also kill the unit, so is it possible that you are calling this function multiple times? Not sure why it would bother to stop from being an endless loop if that was indeed the case though...
I believe it would stop because their is only a 30% chance for it to reach the part of the code that uses the convert function.
 
I had it imported already, and it works like a charm. Thanks!
Once again your modcomp saved my day :)

Unfortunatelly, I still have problem with free promotion pick. Adding
Code:
	newUnit.changeFreePromotionPick(-1)
at the end of the above code does nothing. I can increase the number of free promotionions with (1) but (-1) does not work.:confused:
 
Well, cyther wrote it without any argument. Maybe entering changeFreePromotionPick() alone remove any free promotion?
 
This is where it appears in the python under unit built:

Code:
		iFreeProm = unit.getFreePromotionPick().....

		if unit.getFreePromotionPick() < iFreeProm:
			unit.changeFreePromotionPick(iFreeProm - unit.getFreePromotionPick())

This is all of the placed where it appears so with a few changes that would probably set it to zero.
 
Hi,

(1) I would like to change the way heroes are handled. I would like to allow an hero to be recreated if not present on map (i.e each time he is killed or 'abandon your civ', someone else or you can recreate it). How could I do that? Basically, I need to edit the construction test to check only for the current count and not if the unit was ever created...

(2) How can I enable again the 'gift unit' button?

(3) How can I enable to have workers being able to improve even not in your own's lands? (neutral or friendly)

Thanks everybody in advance!
 
Thanks xienwolf for the amazingly prompt respose above!

I'm now hung up on something that should be really easy. I'm trying to add a new unit (and unit class) that is available to anyone. All my attempts result in a unit that is un-buildable and indicates "Cannot be built by any civilization" in the pedia. I've even tried copying existing units and unit classes that are currently buildable by anyone (e.g., warrior), only altering unit name and unit class name. This results in a unit exactly like the copied unit but un-buildable and indicating "Cannot be built by any civilization" in the pedia (argh!!!). The only thing that worked for me is to add the unit to every civilization in the Civ4Civilization.xml. This works but is un-elegant because mouseover now indicates "Unique unit for Bannor", "Unique unit for Balseraph", "Unique unit for Calabim", etc. Surely I'm missing something very obvious.

I don't think it makes any difference, but just in case: I'm having this problem while modding Orbis mod.
 
We really should have a Mod-Modders thread in Orbis forum :mischief:

I suggest that you show the XML you added so we can take a look at it and see if something is wrong.

If you want, create a new thread in Orbis' forum :)
 
Default Unit in UnitClassInfos needs to point to an actual unit. Actual unit needs to be buildable. Can you build them when you do the UU definitions in CivilizationInfos? If you can, then you know it isn't that. So check UnitClassInfos for a typo.
 
I'll post this in Orbis also. I was wondering, is the "Cannot be built by any civilization" text (in the pedia for some units) from Ffh or is that an Orbis modification?

Here's an example of what I just tried. I copied entries for UNITCLASS_ADEPT (UnitclassInfos.xml) and UNIT_ADEPT (UnitInfos.xml) and pasted these at the end of their respective files. In UnitClassInfos, I changed exactly 2 things, type and Default unit. So here is the whole entree:
Code:
		<UnitClassInfo>
			<Type>UNITCLASS_TEST</Type>
			<Description>TXT_KEY_UNIT_ADEPT</Description>
			<iMaxGlobalInstances>-1</iMaxGlobalInstances>
			<iMaxTeamInstances>-1</iMaxTeamInstances>
			<iMaxPlayerInstances>-1</iMaxPlayerInstances>
			<iInstanceCostModifier>0</iInstanceCostModifier>
			<bUnique>1</bUnique>
			<DefaultUnit>UNIT_TEST</DefaultUnit>
		</UnitClassInfo>

Then I changed exactly 2 things in UnitInfos. I'm only showing the begining but this really is all that I changed:
Code:
        <UnitInfo>
            <Class>UNITCLASS_TEST</Class>
            <Type>UNIT_TEST</Type>
OK. Now when I start the game, I have 2 "adepts" in the civilopedia. This is expected because I did not change text fields. So, to the best of my understanding, these 2 units should be identical in every respect. They are idenical in every respect EXCEPT that one has the words "Cannot be built by any civilization" (just above the "build air node", "build body not", etc. text) and the other does not. Also, there is only one "adept" image in the tech tree at Arcane Knowledge. So why is my unit unbuildable and the other buildable (when they should be identical)?

OK. Now I go to CivilizationInfos.xml and add my unit to Bannor and Malakim, using this:
Code:
                <Unit>
                    <UnitClassType>UNITCLASS_TEST</UnitClassType>
                    <UnitType>UNIT_TEST</UnitType>
                </Unit>
Then I start a game as Bannor. Now I have two "adepts" that I can build with Arcane Knowledge. If I mouse over the second one, I see the text "Unique unit for Bannor" \newline "Unique unit for Malakim".

Same exact results with warrior.

So, in summary, I can successfully add a new "unique unit" (to one or even all civs). But I can't seem to add a non-unique unit that is buildable by any civ.
 
It is your use of the <bUnique> tag. That simulates placing NONE as the replacement for all civs for this unit. If you want everyone to build it, bUnique = 0, if you want only a few to build it, bUnique = 1 and list on those few the default unit as a replacement so they get it back. I assumed that was your issue when you first posted, but if you had copied a Warrior that should not have been set to 1 (same for adept)
 
Back
Top Bottom