View Full Version : Civ 4 XML Tutorial Part 1


BrentRitchie
Oct 30, 2005, 06:29 PM
Creating a new Civilization

First we need to find where the Civilization Entries are entered. Under the Civ 4 folder you will see an assests folder and inside there is where all of the game definitions and logic are held. We are interested in the XML folder. In the XML directory you see a few more folders. The Civilizations folder is where all the different civilizations are defined. Now to add a new civ we need to open the CIV4CivilizationInfos.xml file. This is where all Civilizations in civ 4 are defined.

Looking through the file, you will see alot of tags. Here is the basic layout of each civ definition with comments inlied. Also the actual data inbetween the tags is the data needed for my own Canadian Civ mod.

This tut is ment for those with little XML experience and find the civ 4 files too unwieldly

Pay careful attention to the tags, you can't define <CivilizationInfos> like <CiviliZAtionINFos> The schema forbids it.

<!-- Declareing the root node and namespace -->
<Civ4CivilizationInfos xmlns="x-schema:CIV4CivilizationsSchema.xml">
<!-- Just for organization Saying that there is more then one Civilization definition coning up. -->
<CivilizationInfos>
<!-- This is the starting of a new Civ definition. -->
<CivilizationInfo>
<!-- This tag allows you to create a refrence name for your new Civ -->
<!-- This is a definition tag it allows refrence to your new civ
please keep to the naming standards -->
<Type>CIVILIZATION_CANADA</Type>

<!-- The next six tags are part of the Type tag but are all refrences -->
<!-- A refrence means that these things are defined in another XML file -->
<!-- This tag allows us to give our civ a name that is then displayed by the game -->
<!-- Example of a description is "Canadian Empire" -->
<Description>TXT_KEY_CIV_CANADA_DESC</Description>

<!-- This is a shorter description -->
<!-- Anexample is "Canada", not that much shorter eh? -->
<ShortDescription>TXT_KEY_CIV_CANADA_SHORT_DESC</ShortDescription>

<!-- This is the adjective of the new civ -->
<!-- Example "Canadian" -->
<Adjective>TXT_KEY_CIV_CANADA_ADJECTIVE</Adjective>

<!-- This is interesting, This tag allows us to create a new civilopedia entry for our new civ -->
<Civilopedia>TXT_KEY_CIV_CANADA_PEDIA</Civilopedia>

<!-- This is what the standard player color is -->
<DefaultPlayerColor>PLAYERCOLOR_BLUE</DefaultPlayerColor>

<!-- This tag makes refrence to your Civs Flag -->
<!-- Just set this to america because I don't have the tools to create a new flag ->
<!-- Later in the tutorial I will show you how to edit this however -->
<ArtDefineTag>ART_DEF_CIVILIZATION_AMERICA</ArtDefineTag>

<!-- Tis next tag allows you to set how your buildings look -->
<!-- Since canadians are actually european settlers we'll set it to european style -->
<ArtStyleType>ARTSTYLE_EUROPEAN</ArtStyleType>

<!-- This tag tells the game if humans can play as this civ -->
<!-- Just a note 1 = true, 0 = false -->
<bPlayable>1</bPlayable>

<!-- If the AI can play as the new Civ -->
<bAIPlayable>1</bAIPlayable>

<!-- Now this is where alot of the work is -->
<!-- This tag allows you to list a bunch of city names that your new civ will build -->
<Cities>

<!-- This is actually a refrence to a city that was defined in another file -->
<!-- The more of these there are the more Definitions you need to create -->
<!-- for now I will only use one city - St. Johns, because it is the oldest city in north america -->
<City>TXT_KEY_CITY_NAME_ST_JOHNS</City>

<!-- This means that there are no more city definitions -->
</Cities>

<!-- This tag defines all of this civ's unique units -->
<Units>

<-- This is the new unique unit definition -->
<Unit>

<!-- This is the unit to be replaced -->
<!-- Again these are refrences to graphics and what not so I will set them to the american equiv -->
<UnitClassType>UNITCLASS_MARINE</UnitClassType>

<!-- This is the unit that will do the replacing -->
<!-- This is still the american equivilant -->
<UnitType>UNIT_AMERICAN_NAVY_SEAL</UnitType>

<!-- Finished Defining this UU -->
</Unit>

<!-- Finished defining all UU's for this Civ -->
</Units>

<!-- This portion defines which units a civ starts the game with -->
<FreeUnitClasses>

<!-- Defines each free unit individually -->
<FreeUnitClass>

<!-- The actual free unit that you get -->
<UnitClassType>UNITCLASS_SETTLER</UnitClassType>

<!-- How many of this type of unit? -->
<iFreeUnits>1</iFreeUnits>

<!-- finished defining this free unit -->
</FreeUnitClass>

<!-- Finished defining all free units -->
</FreeUnitClasses>

<!-- This Defines a list of which free buildings your first city will have -->
<FreeBuildingClasses>

<!-- this is the actual building definition -->
<FreeBuildingClass>

<!-- This tag tells us exactly which building is free -->
<BuildingClassType>BUILDING_CLASS_PALACE</BuildingClassType>

<!-- This tag sets if the free building is prebuilt or not -->
<!-- If you set this tag to 0 then the building will have to be built normally -->
<bFreeBuildingClass>1</bFreeBuildingClass>

<!-- Finished defining this free building -->
</FreeBuildingClass>

<!-- Finished defining all free buildings -->
</FreeBuildingClasses>

<!-- This sectio defines all the free techs that you start with -->
<FreeTechs>

<!-- This tag starts the free tech definition -->
<FreeTech>

<!-- This tag allows you to define which tech is free -->
<TechType>TECH_FISHING</TechType>

<!-- This tag specifies if you start with this tech researched -->
<!-- remember 1 = True, 0 = False -->
<bFreeTech>1</bFreeTech>

<!-- Ends the free tech definition -->
</FreeTech>

<!-- No more free tech's to define -->
</FreeTechs>

<!-- This tag I haven't played with but I assume it's to list techs that this civ can't use -->
<!-- I'll look into the schema later -->
<DisableTechs />

<!-- This section deals with starting civics -->
<!-- You can define which civics a civilization can start with here -->
<InitialCivics>

<!-- This line can be used to define the first initial civic -->
<!-- It is important to keep the following pattern so you don't miss any -->
<!-- if you do miss one then none of the civics from that on one will be selected -->
<!-- Define the initial government civic -->
<CivicType>CIVIC_DESPOTISM</CivicType>

<!-- Define the initial legal civic -->
<CivicType>CIVIC_BARBARISM</CivicType>

<!-- Define the initial Labor civic -->
<CivicType>CIVIC_TRIBALISM</CivicType>

<!-- Define the initial economy civic -->
<CivicType>CIVIC_DECENTRALIZATION</CivicType>

<!-- Define the initial religion civic -->
<CivicType>CIVIC_PAGANISM</CivicType>

<!-- No more initial civics to define -->
</InitialCivics>

<!-- These tell the game which civics to use during anarchy -->
<!-- These should be the same as the initial civics but don't have to be-->
<!-- Just to note that if you mess this up then some of the anarchy civics will default to nothing -->
<AnarchyCivics>

<!-- Define the anarchy government civic -->
<CivicType>CIVIC_DESPOTISM</CivicType>

<!-- Define the anarchy legal civic -->
<CivicType>CIVIC_BARBARISM</CivicType>

<!-- Define the anarchy Labor civic -->
<CivicType>CIVIC_TRIBALISM</CivicType>

<!-- Define the anarchy economy civic -->
<CivicType>CIVIC_DECENTRALIZATION</CivicType>

<!-- Define the anarchy religion civic -->
<CivicType>CIVIC_PAGANISM</CivicType>

<!-- nomore anarchy civics to define -->
</AnarchyCivics>

<!-- This defines which leaders are available for this civilization -->
<Leaders>

<!-- This section defines one leader that is available -->
<Leader>

<!-- This defines the leaders name -->
<LeaderName>LEADER_JOHN_MACDONALD</LeaderName>

<!-- Is the leader available to olay as? -->
<!-- you can set this to 0 if you want to hide this leader -->
<bLeaderAvailability>1</bLeaderAvailability>

<!-- finished with this leader -->
</Leader>

<!-- finished defining all leaders -->
</Leaders>

<!-- This tag tells the game which sound schemes to use for when something is selected -->
<CivilizationSelectionSound>AS3D_AMERICA_SELECT</CivilizationSelectionSound>

<!-- This tag tells the game which sounds to play when units are taking actions -->
<CivilizationActionSound>AS3D_AMERICA_ORDER</CivilizationActionSound>

<!-- Finished defining our new civilization -->
</CivilizationInfo>

<!-- Finished defining all civilizations -->
</CivilizationInfos>

<!-- Tell the game our XML file is done -->
</Civ4CivilizationInfos>

Ok now that we made all those changes we have a brand new civ to play right? Wrong, There are still more files to go through just to make it work. I'll cover that in part 2 though.

BrentRitchie
Nov 03, 2005, 10:51 PM
Bumping so it can be moved to the appropriate section.

Yanez
Nov 05, 2005, 07:53 PM
i have to delete another civ right? i cant me a new one completely

PeteT
Nov 06, 2005, 08:23 AM
i have to delete another civ right? i cant me a new one completely

No, you can add a completely new one. But you'll also have to add new leader/s to CIV4LeaderHeadInfos.xml and all the necessary text references (e.g., <Description>TXT_KEY_CIV_CANADA_DESC</Description>) to make it work.

4_HoTA
Nov 25, 2005, 11:23 PM
Cheers for the time and effort taken brent,much appreciated mate.

immortals84
Dec 15, 2005, 04:26 AM
I want to add the "new mod pack" with all those new civilizations created by that civarmy s 1994 guy. Now i used to do alot of adding stuff for civ3. So i figure i just copy and paste the xml data from the assets/XML/Civilizations/CIV4CivilizationInfos out of the New mod pack folder into the CIV4CivilizationInfos already in the game. But when i open CIV4CivilizationInfos out of the New mod pack folder i get this error message:

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Error opening input file: 'CIV4CivilizationsSchema.xml'. Access is denied. Error processing resource 'CIV4CivilizationsSch...


WHAT DO I DO?!?!?!?!?!

Seven05
Dec 16, 2005, 12:42 AM
Right click on it and edit it, that will open it with notepad instead of trying to open it with your web browser.

Der_Meister
Mar 01, 2006, 08:58 AM
Thanks thanks thanks. It's clear and useful.

Marshall Rommel
Sep 04, 2006, 10:29 PM
Ok, this is easy enough to understand

As an experiment, i went to the civilizationxml, down to the descriptions for the german civ, and everywhere there was the word "german" or "germany", i replaced it with "austria" or "austrian", thinking that this would simply rename the civilization. I was wrong though, as when i tried to load up the civ, instead of appearing as "austrian empire" as i thought it would, it said something like "txt_xml..." well, you get the point. Luckily enough, i was able to fix it easily by retyping in "german" on everything i had changed, but how do i rename a civ, since this didnt work?:confused:

Saketh
Sep 05, 2006, 02:37 PM
Ok, this is easy enough to understand

As an experiment, i went to the civilizationxml, down to the descriptions for the german civ, and everywhere there was the word "german" or "germany", i replaced it with "austria" or "austrian", thinking that this would simply rename the civilization. I was wrong though, as when i tried to load up the civ, instead of appearing as "austrian empire" as i thought it would, it said something like "txt_xml..." well, you get the point. Luckily enough, i was able to fix it easily by retyping in "german" on everything i had changed, but how do i rename a civ, since this didnt work?:confused:
You probably changed the word GERMAN as it appeared in the XML tags. If you replace only the tag data (i.e. <tag>data</tag>), then the word German should be properly changed to Austrian.

The game writes TXT_KEY... when it can't find the string which the TXT_KEY refers to. In this case, since you changed the TXT_KEY itself, the game does this.

cubsaver
Sep 16, 2006, 02:59 PM
Where is part 2? I found part 3...

kristopherb
Sep 20, 2006, 03:36 PM
small question do you do this in word or a different program

Iluwen
Sep 21, 2006, 06:42 PM
I am having a similar problem to Marshall Rommel.

I am trying to add a new tech. So, I copied Horseback Riding, in TechInfos.
Then I changed <Type>TECH_HORSEBACk_RIDING</Type> to <Type>TECH_CAVALRY_TACTICS</Type>. At that point, the game loaded fine, and gave me two entries for Horseback Riding, one of which contained only the quote and decription.

I changed Civilopedia>TXT_KEY_TECH_HORSEBACK_RIDING_PEDIA</Civilopedia>, as above, to reda CAVALRY_TACTICS, and supplied a new entry with that name in GameText_Civopedia_Techs. And eveyrthing was still fine, the game now gave a new description for the second Horseback Riding entry in the Civopedia.

Then, I changed <Description>TXT_KEY_TECH_HORSEBACK_RIDING</Description> again as above, so that the tech would read Cavalry Tactics when I loaded the game. But no, it read TXT_KEY etc. What am I missing? What other file is being referenced where I actually name the tech?

And, a second problem: When I change <Quote>TXT_KEY_TECH_HORSEBACK_RIDING_QUOTE</Quote>, suppling a new entry and quote in GameTextInfos, the game won't even load properly, crashing with an error message about being "unable to read" followed by a list of numbers with a hyphen somewher in the middle.

What am I doing wrong here?

zattifier
Jan 13, 2007, 09:58 AM
i have no idea about xml files and all that stuff, how do i add a new civ cos it won't just let me add stuff to the file

Aliestor
Jul 05, 2009, 05:19 PM
Im trying the best i can to keep the modding within the allready provided material and I was trying to make Byzantian UU into a Polish UU and to name it Hussar but how do i do that?

The_J
Jul 06, 2009, 01:35 PM
Can you add a normal unit?

If yes, then it should be no problem, when you look at the Civ4CivilizationsInfos.xml.

Aliestor
Jul 09, 2009, 06:23 PM
Could you trow me an example, my brain is fried for the moment :p

The_J
Jul 10, 2009, 04:00 PM
The examples are there...in the XMLs ;).

To create an UU, you have to add it in the XML\Civilizations\CivilizationsInfos.xml.
Just look at the file ;).

Copy this section:

<Units>
<Unit>
<UnitClassType>UNITCLASS_KNIGHT</UnitClassType>
<UnitType>UNIT_BYZANTINE_CATAPHRACT</UnitType>
</Unit>
</Units>

to the right part of your poland civ.
Then you have to go to the text xmls (XML\Text\), and in this folder, in some file (i guess CIV4GameText_Objects_BTS.xml) is the name of the unit. Change it there. Done :).

Phrossack
Jul 15, 2009, 09:02 PM
Samurai start with Drill 1, and can receive the other Drill promotions, even though melee units can't normally get these. I gave Keshiks Drill 1, but they can't get the other Drills. How can you let them receive the other Drills?

EDIT: Never mind, got it to work. FEAR THE HORDE!

Drunk Link
Jul 21, 2009, 12:55 PM
Right click on it and edit it, that will open it with notepad instead of trying to open it with your web browser.

I tryed doing this. All it said was I can't save because it isn't the right file type. How do I save it if I edited it on Notepad?

The_J
Jul 21, 2009, 01:02 PM
Just clicking "save" should work.


You're not running vista, aren't you?

Drunk Link
Aug 22, 2009, 11:58 PM
I am running Vista. It says it doesn't support the file type. It's pissing me off!!!

The_J
Aug 23, 2009, 06:21 PM
It says it doesn't support the file type.

:confused: what? When does it say that? Can you take a screenshot?

Drunk Link
Aug 24, 2009, 06:18 PM
I guess. I couldn't save it so I have to do it all over again.

The_J
Aug 24, 2009, 06:29 PM
:confused: that's strange.

Beside that problem: Are you logged in as administrator/do you run notepad with administrator rights?

Drunk Link
Aug 24, 2009, 06:33 PM
Yes I do. It is n administrator.

The_J
Aug 25, 2009, 05:58 PM
I have no real idea, where the problem could be.

Maybe it's still a problem with the access rights. Did you try to copy the file to your desktop and to change it there?

Greggorion
Dec 15, 2009, 04:29 PM
for me, it says the civilizations folder is empty. no xml files what so ever

The_J
Dec 16, 2009, 03:37 AM
Welcome to CFC :).

To the question: Err...what :confused:?

22bebo
Dec 18, 2009, 09:17 PM
I liked the tutorial, it was good. If you highlighted the actual code in a different colour, it might be easier to read.

22bebo
Dec 21, 2009, 04:49 PM
I can't find the designated folders. In mine it has CustomAssests/Xml/Civilizations, and it stops there.

The_J
Dec 21, 2009, 04:56 PM
:confused: maybe i can't read the tutorial clearly enough, but what folders else do you need?

22bebo
Dec 21, 2009, 05:03 PM
I wanted to see one of the original game files to kind of get a look at the format. I know what he's got is one, but I just wanted to check.

The_J
Dec 21, 2009, 05:16 PM
Original game files are under C:\Program Files\Firaxis Games\Civ\BtS\.

22bebo
Dec 21, 2009, 06:13 PM
Ah! Thank you! That makes life much easier.

bwcbwc
Apr 25, 2010, 02:43 PM
A few gotchas I've found doing a simple mod to GlobalDefinesAlt.xml in Vista:
1) If you use an XML editor like XML Copy Editor, make sure the file is being saved in Windows (CRLF) as opposed to Unix (CR) line termination format. Civ IV will throw a syntax error on the XML file if it is not in windows format.
2) If you attempt to save the file directly in \Program Files\Firaxis Games\Sid Meier's Civilization 4\Assets\XML, it will instead save a shadow copy to your \Users\yourname\AppData\Virtual Store\Program Files\... etc. This file will not be readable by other users on the computer. In fact, it appears that if you originally installed Civ 4 with one ID and are running it under another ID it will not read the file in any case.

I did find that putting the file in \Users\myName\Documents\My Games\Sid Meier's Civilization 4\CustomAssets\xml worked fine once I got past the syntax error issue. Note that in addition to my own changes, I also set the value of the override define to 1. I'm not sure if this is required, but I don't see any reason to change it.
<Define>
<DefineName>MODS_SHOULD_OVERRIDE_GLOBAL_DEFINES_HERE</DefineName>
<iDefineIntVal>1</iDefineIntVal>
</Define>

In order to ensure you save in Windows format, you can use Notepad, but when you save, if you do "Save As" be sure to change the file type in the save dialog from Text file to All Files, or it will append a .txt extension.

I've found my best option is to use a one of several free text editors that do XML syntax highlighting and allow you to set the line termination format if that becomes necessary. Some examples are Programmers' Notepad ( http://www.pnotepad.org/download/ ) and Notepad++ (Sourceforge: http://notepad-plus.sourceforge.net/uk/download.php ). These are both Open Source Freeware. As is XML Copy Editor...

Zmon
Jun 01, 2010, 03:20 PM
Does all this work the same for bts???

The_J
Jun 01, 2010, 04:54 PM
Nearly.
There are some differences, some tags have been moved, some have been newly added, but in general it's the same.

TMaxwell86
Aug 27, 2010, 03:44 AM
Thank you bwcbwc for that last input - it explains why I kept get some kind of syntax error when I was trying to create a Canadian Civ. I don't recall the specific wording, but something about "XML at top of page" blah blah blah. I got so frustrated that I eventually gave up.
Thank you also to The_J. I may just try again to create my Canadian Civ and make sure I follow your tutorial...

TMaxwell86
Aug 27, 2010, 03:48 AM
Also, Thank you especially to Brent - great job on the Tutorial, Now if only I can get Vista to behave. Any idea if Windows 7 behaves the same way?