A top down learner's guide to modding

zenspiderz

Just some bloke..
Joined
Apr 10, 2006
Messages
1,496
preamble

i am very keen to learn how to mod and have lots of ideas but have at the time of writing little or no knowledge of how to implement my ideas. I have played around with various tutorials here but i struggle with them because i am a top down learner and the tutorial's seem to be written by bottom up learners or at least in the bottom up methodology.

A top down learner needs to start with the big picture and work on the details later, he learns non-linearly and focus on how things work together within the context of the whole. So bottom up style tutorials that start with some narrow focus and build up in step by step increments until the big picture is achieved are not helpful to me. My brain just doesn't work that way!

Thus i have this idea of creating a top down style guide to modding as I learn to do it. Filling in the details as i go. i could do this on a private word doc but i thought a better idea to publish it here so experts could see, advise, add and correct my guide and so others may benefit from my guide.

It may seem silly to some to start a tutorial on a subject before the author has entirely mastered it but for top down learners non-linear development is natural.

Ok we start with the nut shell and from this humble acorn may the mighty tree of knowledge grow!

Nut shell (the state of my knowledge so far)

WARNING! - Before you commit yourself to creating your dream mod there is something you should know. Although CIV4 is a modders dream as it has been purpose built to moddified (Thank you Firaxis!) modding, especially if you are starting (like me) from a position of complete programming innocence, is extremely time consuming and potentially highly frustrating. The learning curve is steep and the potential for time consuming errors is great. If you are undetered read on.
CIV is composed of 5 basic sections; the gamecore, python files, XML, Graphics and Sounds. Thus modding civ means altering some or all of these sections.

Gamecore - ?

Python - ?

XML - XML files detail game data such as unit and building abilities. They are basic text files that can be easily edited with a text editor like notepad. Finding your way around xml folders using notepad is much enhanced if you use its keyword search function which opened by pressing ctrl F in notepad.

Graphics - graphics have 3 elements mesh, skins (textures) and animations.

Meshes are the 3d structure or skeleton of a graphic and in civ are .nif files. .nif files can be edited using 3d graphics software like blender (which is open source and free) or 3Dmax (which is commercial). Plugins maybe needed to use .nif files.
Nifskope is program which allows the user to view .nif files but doesn't seem to alow much editing ability.

Skins - are the colouring and is applied to the surface structural mesh. Civ uses .dds files for textures and skins. buttons are also .dds files (buttons don't need a mesh.) skins/textures can be created/edited in blender/3Dmax and also simple graphic editors like GIMP (open source and free) or photoshop. plugins to use .dds files may be needed.

Animations - animation files desribe how the graphic should change over time to create effects like units fighting and dying. Animations in civ are described in .kf and .kfm files. can be edited with blender or 3Dmax.

Sounds - ?

File structure - The unmodded game has a distinct file structure and like most file structures is tree-like in shape; trunk, branches, twigs and leaves. The trunk of the game is the main folder and branching out from that various sub-folders; game core, assets, public maps and yes mods. Inside these folders are further branches, inside assets (an important folder for the modder) you see; Art, Python, res, XML, sounds as well as some files called assets(number).fpk. Inside each of these folders more files and folders can be found. The thing to realise is that a mod as well as official expansions (like bts and warlords) are 'trees' mirroring the main game in structure. So if you add,for example, a new leaderhead to your mod you will need to mirror the main game structure by putting your leaderhead folder in a folder called LeaderHeads and put that folder in a folder named Art and put that folder in a folder called Assets. Have a look now at the arrangement of folders in the main game and then in the expansions and finally in the mods of each expansion.

You will notice that within a mod some folders are not present that are present in the main game. This is because when the game is playing a mod it will look for any files it can't find in the mod file in the expansion (bts or warlords) that the mod is made for and if it can't find the file there it will look in the main game 'tree'. This is important for modders because it means any files and folders that are unaltered from the expansion or main game DO NOT need to be included in the mod. This saves time in editing and in loading the mod.

Adding units - Adding new is a simple matter of placing the new units graphics (nif mesh, dds textures and kfm animation files) in a suitabley named folder in your mods asset/art/units folder in order to make the graphics available to your mod and then editing the xml to 'tell' your mod where to find the graphics and how and when to use them. So to tell your mod how to use the graphics (and where to find them) you must edit 2 or 3 xml files;

1. CIV4ArtDefines_Unit.xml (in the Assets/Xml/Art folder) - this xml file defines each graphically unique unit and indicates where that unit's graphic files, sound files, animation files can be found.

2. CIV4UnitArtStyleTypeInfos.xml (in Assets/Xml/Civilizations folder) - this xml file defines which 'artstyle' each graphically unit unit belongs to. BTS-ships with these 'artstyle' groups - european, asian, middle-eastern, native, and south american. You do not need to use these styles but you can create your own for each civ or group of civs. If you make your own style you need to define it in the xml file described below.

3. CIV4CivilizationInfos.xml (found or made alongside CIV4UnitArtStyleTypeInfos.xml in the Assets/Xml/Civilizations folder) - this xml file defines which civs use which artstyles and when (amongst other things).

Here is a working example of how to do this. Let us say you want to give your mod african units that actually look african. to get started you found a nice graphic of an african worker in the downloads section of civfanatics and want your mod to use it for the african civs (mali, zulu and ethiopia mainly) instead of the default caucasian worker. First things first you make your graphic availabe to your mod by downloading it and extracting its files into a folder you made called african worker which you place in another folder you made called african units which in turn sits in a folder called Units which in turn sits in a folder named Art which in turn sits in your mods Assets folder. So the complete file path for you african workers mesh will be CIV4/BTS/Mods/(your mod name)/Assets/Art/Units/african/african worker/africanworker.nif. Ok that done it you need to tell you mod how to use these graphics. First thing to do is copy CIV4ArtDefines_Unit.xml, CIV4UnitArtStyleTypeInfos.xml and CIV4CivilizationInfos.xml from BTS and paste them into the appropriate folders in your mods Xml folder.

Now your are ready to edit these files to make your african civs use your african worker. In your mods CIV4ArtDefines_Unit.xml you need to create a new definition for your worker. Since it is a worker it is best to copy the entry for worker as a seperate entry immediately below the original entry for worker. You will have now have an entry something like this..

<UnitArtInfo>
<Type>ART_DEF_UNIT_WORKER</Type>
<Button>,Art/Interface/Buttons/Units/Worker.dds,Art/Interface/Buttons/Unit_Resource_Atlas.dds,3,5</Button>
<fScale>0.44</fScale>
<fInterfaceScale>1.0</fInterfaceScale>
<bActAsLand>0</bActAsLand>
<bActAsAir>0</bActAsAir>
<NIF>Art/Units/Worker/Worker.nif</NIF>
<KFM>Art/Units/Worker/Worker.kfm</KFM>
<SHADERNIF>Art/Units/Worker/Worker_FX.nif</SHADERNIF>
<ShadowDef>
<ShadowNIF>Art/Units/01_UnitShadows/UnitShadow.nif</ShadowNIF>
<ShadowAttachNode>BIP Pelvis</ShadowAttachNode>
<fShadowScale>0.9</fShadowScale>
</ShadowDef>
<fBattleDistance>0.35</fBattleDistance>
<fRangedDeathTime>0.31</fRangedDeathTime>
<bActAsRanged>0</bActAsRanged>
<TrainSound>AS2D_UNIT_BUILD_UNIT</TrainSound>
<AudioRunSounds>
<AudioRunTypeLoop/>
<AudioRunTypeEnd/>
</AudioRunSounds>
</UnitArtInfo>

To make your mod use your new graphics you need it to look like this..

<UnitArtInfo>
<Type>ART_DEF_UNIT_WORKER_AFRICAN</Type>
<Button>,Art/Interface/Buttons/Units/Worker.dds,Art/Interface/Buttons/Unit_Resource_Atlas.dds,3,5</Button>
<fScale>0.44</fScale>
<fInterfaceScale>1.0</fInterfaceScale>
<bActAsLand>0</bActAsLand>
<bActAsAir>0</bActAsAir>
<NIF>Art/Units/African/AfricanWorker/worker_african.nif</NIF>
<KFM>Art/Units/Unique/India/Worker/IndianFastWorker.kfm</KFM>
<SHADERNIF>Art/Units/African/AfricanWorker/worker_african_FX.nif</SHADERNIF>
<ShadowDef>
<ShadowNIF>Art/Units/01_UnitShadows/UnitShadow.nif</ShadowNIF>
<ShadowAttachNode>BIP Pelvis</ShadowAttachNode>
<fShadowScale>0.9</fShadowScale>
</ShadowDef>
<fBattleDistance>0.35</fBattleDistance>
<fRangedDeathTime>0.31</fRangedDeathTime>
<bActAsRanged>0</bActAsRanged>
<TrainSound>AS2D_UNIT_BUILD_UNIT</TrainSound>
<AudioRunSounds>
<AudioRunTypeLoop/>
<AudioRunTypeEnd/>
</AudioRunSounds>
</UnitArtInfo>

The red print indicates the changes made. the first change; the addition of 'african' on the end of 'worker' tells your mod that there is another kind of worker that has the name african. The changed <NIF> entry tells the mod where to find the mesh for its WORKER_AFRICAN and the <KFM> where to find its animation file. As it happens this african worker graphic uses the same animations as the indian fast worker. The <shadernif> entry should point to the same file as the <NIF> entry unless your graphic uses an 'FX' version of the mesh in which case it should point to that file. If you open your graphic folder you will see whether the graphic has an FX version or not. Note that this african worker uses the same button as the default worker. If it had its own button that you wanted to use then the <Button> entry should point to that file if you want to use it.

Now your mod knows that there such a thing as a WORKER_AFRICAN and how to draw it etc. It needs to know when to draw it and for who. So now we need an entry in the UnitArtStyleTypeInfos.xml file. In there we will see (in bts) the following artstyles defined european, asian, middle-eastern, native and south american. Whoops no african artstyle! And we see that for each artstyle certain units are defined as haveing a style counterpart for the artstyle. Well since we don't have a an artstyle for africans we shall have to make one. copy any of the style sections and paste it alongside the others whereever you want being sure to maintain the tag nests, rename it UNIT_ARTSTYLE_AFRICAN and chop out all the entries inside it. You should now have something like this..

<UnitArtStyleTypeInfo>
<Type>UNIT_ARTSTYLE_AFRICAN</Type>
<StyleUnits>
</StyleUnit>
</StyleUnits>
</UnitArtStyleTypeInfo>

Ok an empty artsyle! To link our unit to this artstyle we just have to make an entry into this artstyle definition. copy and paste a worker definition from another artstyle into your new artstyle and change its <EarlyArtDefineTag> and <MiddleArtdefineTag> to WORKER_AFRICAN. You should now have something like this..

<UnitArtStyleTypeInfo>
<Type>UNIT_ARTSTYLE_AFRICAN</Type>
<StyleUnits>
<StyleUnit>
<UnitType>UNIT_WORKER</UnitType>
<UnitMeshGroup>
<EarlyArtDefineTag>ART_DEF_UNIT_WORKER_AFRICAN</EarlyArtDefineTag>
<LateArtDefineTag>ART_DEF_UNIT_WORKERMODERN</LateArtDefineTag>
<MiddleArtDefineTag>ART_DEF_UNIT_WORKER_AFRICAN</MiddleArtDefineTag>
</UnitMeshGroup>
</StyleUnit>
</StyleUnits>
</UnitArtStyleTypeInfo>

Ok so now your mod knows where to find your african workers graphics and animations, and it knows that the graphic is a worker and that it belongs in an artstyle called african, but it doesn't yet know which civilizations USE an african worker.. time to open your CIV4CivilizationInfos.xml file.

find definiton of one of the civs that you want to use the AFRICAN unit artstyle. Say zulu.. you will see that the entry begins thus..

<CivilizationInfo>
<Type>CIVILIZATION_ZULU</Type>
<Description>TXT_KEY_CIV_ZULU_DESC</Description>
<ShortDescription>TXT_KEY_CIV_ZULU_SHORT_DESC</ShortDescription>
<Adjective>TXT_KEY_CIV_ZULU_ADJECTIVE</Adjective>
<Civilopedia>TXT_KEY_CIV_ZULU_PEDIA</Civilopedia>
<DefaultPlayerColor>PLAYERCOLOR_LIGHT_YELLOW</DefaultPlayerColor>
<ArtDefineTag>ART_DEF_CIVILIZATION_ZULU</ArtDefineTag>
<ArtStyleType>ARTSTYLE_MIDDLE_EAST</ArtStyleType>
<UnitArtStyleType>UNIT_ARTSTYLE_MIDDLE_EAST</UnitArtStyleType>

The part I have coloured red is the bit we are interested in now.. You see at present your mod like bts thinks that it should use the MIDDLE_EAST artstyle for the very african zulu civ! This won't do. Change the the red definitions to ...._AFRICAN and your mod will now know to use the AFRICAN artstyles and thus the africa worker for this civ. Do the same for ethiopia and mali if you like. Now save your files and load up BTS and then you mod, start a game and see if your african worker appears! If you get the default vanilla worker, a red blob or a system crash you did something wrong. (to be continued)
 
reserved for future use
 
I have been reading tutorials for about a year and have done a few minor mods, nothing fancy just some minor XML editing. I have already learned quite a bit from your post and am more of a top down learner myself. Keep it up because this seems to be my best shot at really learning how to mod.
 
I think its it's kfm not kdf
 
I would like to thank you. With your tutorial i have gotten father than any before. Is there any other steps to this that i am missing. I am trying to replace the generic knight for the french with a graphic i downloaded. I get an error message saying unit type is incorrect
 
I would like to thank you. With your tutorial i have gotten father than any before. Is there any other steps to this that i am missing. I am trying to replace the generic knight for the french with a graphic i downloaded. I get an error message saying unit type is incorrect

i am sorry i haven't updated the guide in a long time still i am glad it has been helpful to someone. To help with your problem i need a little more information also if you post the xml entries you made and a link to the actual model you trying to include. My best guess on the information you have given is that the problem could a spelling mistake in xml entries.
 
Soylentblue do you want this unit to be a Unique Unit, or do you want it to be an ethnic graphic?
 
Back
Top Bottom