Getting Civ4 Units into Civ4Col : A Tutorial

Deliverator

Graphical Hackificator
Joined
Feb 12, 2008
Messages
4,806
Location
London, UK
This is a method for editing Civ4 nif files for use in Civ4Col using NifSkope.

This assumes that you already have mod set up and know your way around CIV4ArtDefines_Unit.xml and CIV4UnitInfos.xml. (I can explain this bit another time if people are unsure.)

Why can't I just use the current models?

Well, you can, but they may look wrong. People have said that the solution is to use the _fx version of the nif file, but this doesn't completely solve the issue. The _fx version is just a prettier version of the nif with extra layers of gloss/lighting. _fx does not mean Civ4Col compatible. See this screenshot of japanesesamurai_fx.nif in C4C:



I'm using the _fx.nif but I still have a yellow sword. The following method can be used to fix this, but it can also be used to migrate units that don't have a _fx NIF.

Editing Samurai for use in Civ4Col

1) Copy the entire samurai directory from the BTS Assets/Art/Units/Unique/Japan into Mods/<YourMod>/Assets/Art/Units. (You don't have to use the Samurai - this is just an example)
2) Open the copied japanesesamurai_fx.nif in NifSkope.
3) Under View in the Menu Bar make sure Block List and Block Details are checked and then select Show Blocks in List:



4) Scroll until you spot the element TeamColor.bmp then Right Click -> Block -> Remove:



5) In View switch back to Show Blocks in Tree. The 3D components of a NIF are either called NiTriShape or NiTriStrips (NiTriStrips is just a stripped version of NiTriShape - they basically have the same structure otherwise). We need to select the NiTriShape for the swords and edit some of its properties. The easiest way is simply to click on a sword in the 3D view. The Block List should automatically highlight the selected NiTriShape in blue. Using the little plus sign expand the tree until you see NiTexturingProperty, then expand that as well. Note the node number of the base NiSourceTexture - in this case the base texture is samurai_128.dds and the node number 42:



6) Set 'Has Decal 0 Texture' to 'no' by clicking on 'yes'. (The swords will turn white but don't worry). Set 'Has Base Texture' to 'yes' by clicking on 'no'. Finally, expand the BaseTexture node and enter the node number for the base texture - which we noted was 42. (On doing this the swords will turn back to the proper texture)



7) Finally save the file. File -> Save As... Providing you have made a copy of the NIF file in you Mod folder tree you can safely overwrite the existing .nif file with the edited one.



8) That's it! Now on loading up our mod - the samurai's sword is it's proper colour. :)



How does Team Color work?

Team Color in Civ4Col is applied by the shader. You can see that the samurai we just converted still has Team Color even though we have removed TeamColor.bmp:



Here's a little demonstration. I've ported the Aztec Jaguar from normal Civ4 into Civ4Col using the process just described.



Notice that the loincloth is team colour, but that the feathers are transparent. Why are some parts of the model transparent and some team colour? Here's why.




In aztec_jaguar_fx.nif, the NiTriShape for the Body has the shader set to TCiv4Skinning whereas the NiTriShape for the Feathers has the shader set to TCiv4SkinningNoTeamColor. If I swap these so the Body has TCiv4SkinningNoTeamColor and the Feathers have TCiv4Skinning this is the in game result:



Not very desirable in this case, but you take the point. In terms of model customization and texturing this gives me control over what is transparent and what is team color.

Unit Sound and Effects

If you're bringing across a Civ4 unit or a custom unit and want the sound and effects too (why wouldn't you?!) then the first thing you need to figure out is which sounds/effects go with the unit in question. This isn't always obvious as a lot of vanilla units share the same sounds. The sound and effects are associated with the KF animation files rather than the NIF. (An exception is the Civilization order and select sounds which are specified in CIV4CivilizationInfos.xml - CivilizationSelectionSound and CivilizationActionSound tags)

To determine which sounds a unit requires:

1) Open up a KF file in NifSkope and locate a node called NiTextKeyExtraData in the Block List (normally at the bottom of the list).

2) View Block Details for NiTextKeyExtraData and expand the Text Keys like so:



The Text Key Values correspond to entries in Audio3DScripts.xml such as:
Code:
	<Script3DSound>
		<ScriptID>AS3D_UN_WARR_ATTK_VOX</ScriptID>
		<SoundID>SND_WARR_ATTK_VOX</SoundID>
		<SoundType>GAME_SFX</SoundType>
		<iMinVolume>75</iMinVolume>
		<iMaxVolume>100</iMaxVolume>
		<iPitchChangeDown>-3000</iPitchChangeDown>
		<iPitchChangeUp>3000</iPitchChangeUp>
		<bLooping>0</bLooping>
		<iMinTimeDelay>0</iMinTimeDelay>
		<iMaxTimeDelay>0</iMaxTimeDelay>
		<StartPosition>NONE</StartPosition>
		<EndPosition>NONE</EndPosition>
		<iMinVelocity>0</iMinVelocity>
		<iMaxVelocity>0</iMaxVelocity>
		<iMinDistanceFromListener>0</iMinDistanceFromListener>
		<iMaxDistanceFromListener>0</iMaxDistanceFromListener>
		<iMinDistanceForMaxVolume>500</iMinDistanceForMaxVolume>
		<iMaxDistanceForMaxVolume>1000</iMaxDistanceForMaxVolume>
		<iMinCutoffDistance>7000</iMinCutoffDistance>
		<iMaxCutoffDistance>7000</iMaxCutoffDistance>
		<bTaperForSoundtracks>0</bTaperForSoundtracks>
		<iLengthOfSound>0</iLengthOfSound>
		<fMinDryLevel>1.0</fMinDryLevel>
		<fMaxDryLevel>1.0</fMaxDryLevel>
		<fMinWetLevel>0.5</fMinWetLevel>
		<fMaxWetLevel>0.5</fMaxWetLevel>
		<iNotPlayPercent>0</iNotPlayPercent>
	</Script3DSound>
These entries refer to entries in AudioDefines.xml such as:
Code:
		<SoundData>
			<SoundID>SND_WARR_ATTK_VOX</SoundID>
			<Filename>Sounds/Units/WarrAttkVox</Filename>
			<LoadType>DYNAMIC_RES</LoadType>
			<bIsCompressed>1</bIsCompressed>
			<bInGeneric>1</bInGeneric>
		</SoundData>
The AudioDefines.xml refers the actual mp3 file location in the Filename tag. So in order to port unit sounds you will have to copy the relevant entries in Audio3DScripts.xml and AudioDefines.xml and copy the mp3 files into the Sound folder. It is not usually necessary to go through every single KF file for the unit as you will quickly figure out that the unit uses, for example, the Swordsman sounds and then you can just copy all the Swordsman stuff over. A certain number of Civ4 sounds are already included in Civ4Col too.

Effects (such as flying arrows and smoke) follow a similar pattern except that Effects are NIFs and associated DDS files which need to copied to your mod's Effects subdirectory. The XML in question is XML/Misc/CIV4EffectInfos.xml. Effects look like this in the Text Key values:

Effect:RifleBlast:EFFECT_RIFLEBLAST

Happy unit migration! :)
 

Attachments

  • tut1.jpg
    tut1.jpg
    52.7 KB · Views: 3,741
  • tut2.jpg
    tut2.jpg
    97.1 KB · Views: 3,910
  • tut3.jpg
    tut3.jpg
    146.3 KB · Views: 3,749
  • tut_sam_fixed.jpg
    tut_sam_fixed.jpg
    61.5 KB · Views: 3,514
  • aztecNormal.jpg
    aztecNormal.jpg
    60.6 KB · Views: 4,297
  • aztecFeathers.jpg
    aztecFeathers.jpg
    124.9 KB · Views: 3,508
  • sounds.jpg
    sounds.jpg
    112.4 KB · Views: 3,204
I used this tutorial this weekend to get a Civ4 unit into the game (I must say the Tupi were surprised to see their camp surrounded by war elephants). Pretty good and straight-forward.

However, I am having a terrible time getting custom Civ4 units into Colonization. I'm assuming this is because they rely on assets from vanilla civ4 units which are not present in Colonization. Though come to think of it, I forgot to test them in BTS to make sure they work at all.

I did notice when looking at them in nifskope, however, that the reference color palettes and stuff from pre-existing Civ4 units. Frustratingly, the units I was working (like this one) with all referenced units that I couldn't find art files for in my Civ4 directory (like the Incan Quechua, for example).
 
A complete Civ4 (or Civ4Col) unit folder needs the following files:

1) A NIF file (*): the 3D Model itself - viewable in NifSkope, which references...
2) One or more DDS files: 2D texture files - viewable/editable in Paint.NET
3) A KFM file: the master animation file, lists which events trigger which animation KF file. Can be viewed in NifSkope, but I find the easiest way to edit is this tool.
4) Several KF files - the individual animations themselves - viewed and edited in NifSkope.

* sometimes vanilla units will have a FX version of the NIF that just has extra eye candy basically.

It is customary for people to upload only the NIF and DDS files. The reason is that custom animations are difficult to create and are hence rare, so pretty much every custom unit uses the animations of an existing vanilla unit. The person uploading should , on the download page or in a readme.txt, tell people which vanilla animations to use for the unit. On sezereth's download page he says (albeit a bit cryptically) that these units use the Aztec Jaguar animations. Personally, I don't know why people don't just include the necessary KFM and KF files for the sake of convenience - they're not THAT big...

The zombie download pack contains three different units, hence three different NIF files and three different DDS texture files. The fact that the Incan Quechua is mentioned in the NIF is not significant, this is common in custom units and it's just because sezereth must have based the unit on the Incan Quechua.

The only thing that is necessary for animations to work with a given NIF is that the correct bones referenced in the KF file need to be present in the NIF. Typically skeletons/bones begin either BIP/Bip01. So if your NIF skeleton/bones begin BIP, the easiest thing to do is use animations for another unit with a BIP skeleton. The fact that Firaxis didn't have a consistent naming convention and stick to one or the other is a much lamented fact. (You can actually edit animations in NifSkope so that you can use Bip01 animations with a BIP NIF, but it is more hassle...)

I've attached the Jaguar animation files, but if you want to get them yourself you probably need to unpack the vanilla art:

http://forums.civfanatics.com/showthread.php?t=136023

Use PakBuild to unpack every Art pack you can find - Civ4, Warlords and BeyondTheSword. That way if you have another custom unit that needs animation you should have the files at hand.

Once you have the KFM/KF files in place it should just be a question of pointing the Art Defines XML to the correct NIF and KFM file.

Hope this helps :)
 
Thanks for mentioning pakbuild. That is something I've heard of, but didn't know enough about to know to use it to look for vanilla units. Now I know where to look for that blasted Quechua, lol.

There is something about these zombie nif files (and a couple others I was working with like a few of the Fury Road units) that causes Colonization to crash. I had been using the missionary.kfm as a placeholder (knowing it wouldn't look right), but was getting the crashes. When using the aztec_jaguar.kfm I got a crash also.

I did just test out this specific file (zombie) in BTS using the aztec jaguar.kfm and it worked correctly, though it seemed like it had a few minor quirks. I wonder what it is about these files that causes them to crash the game while the vanilla units work fine for the most part?
 
Rather than give you advice that might not work, I'll see if I can get them working and come back to you. I've done quite a bit of this so I have a few ideas what it might be...
 
The good news:



The bad news:

The solution is not as straightforward as I hoped. There are basically two steps:

1) Import the NIF into Blender and then export it. You'll need blender and the blender nifscripts - these are dependent on having a particular version of python installed too. You don't need to understand anything about blender to do this. It is just a workaround as it can clean up dodgy NIFs without you having to figure out exactly what is wrong with them. Once you've got everything installed, open blender and use the little icon drop down to switch to the snake icon which is the scripts screen. From there choose Scripts -> Import/Export -> NetImmerse/Gamebryo (.nif)



Basically, we are just importing and exporting the NIF into/from blender to clean it.

2) Find an existing unit NIF that you are going to turn into a zombie. I used the warrior, but you can use any unit (It will be easier if it has a BIP skeleton rather than Bip01). Copy both NIFs to the same directory. Open both NIFs in NifSkope simultaneously. Go to the warrior.nif (or whatever you chose). Find the TriShape/TriStrips for the body mesh - in my case called Warrior_Body. Right click -> Block -> Remove Branch. Then in the zombie NifSkope instance find the node Zombie.00 (or whatever the body is called), Right click -> Block -> Copy Branch. Then back in the warrior NIF, do Right Click -> Block -> Paste Branch so that the Zombie mesh is pasted where the Warrior_Body used to be. (In the latest NifSkope you can use Ctrl-C and Ctrl-V to Copy/Paste branches) Save the warrior.nif. Now you have a working NIF. This process is sometimes referred to as Nifswapping and is used a lot. If you don't want the weapons you should be able to get away with removing them and the animation should still work. Final result should look like this in NifSkope:

 

Attachments

  • zombie.jpg
    zombie.jpg
    46 KB · Views: 3,185
  • blender_nif.jpg
    blender_nif.jpg
    35 KB · Views: 3,233
  • nifskope_zombie.jpg
    nifskope_zombie.jpg
    67.7 KB · Views: 3,228
YES! Dude you are the best.

It took a bit of doing, as I already python and blender, but the 64-bit versions, so I had to uninstall/reinstall the 32-bit versions. I am happy to report, however, that I was able to successfully get that zombie unit into the game thanks to your directions. I'm looking forward to playing with more units now!
 
No worries, man. Glad to be of service! :)
 
I've updated the opening post to include information on sound and effects since I've been meaning to do it and it has been requested.
 
Hello Deliverator,

Despite the explanations you give, I can not use the "Musketman" from "CIV 4" and other units, and incorporated its on "CIV 4Colonization".
My units are white, without textures.
Could you explain the exact procedure?! I would like, if it is possible, you explain me in the "Musketman" unit.
I downloaded "Davy Crockett". It is the same matter, impossible to use(wear out) it. And nevertheless, I really need it.
Thanks you in advance!!!
Dazio
 
If the unit is white it sounds like it is still showing team colour. Have you followed the steps described in NifSkope to remove the TeamColor.bmp node? The steps described in the opening post should work for most units.
 
Hello Deliverator,
I observed well your post. "Musketman" does not possess TeamColor.
But thanks to you, I was able to find what did not go. Just a number, which was not written in the NiTexturingProperty, preventing proper operation.
 
Top Bottom