View Full Version : Civ 4 XML Tutorial Part 2


BrentRitchie
Oct 30, 2005, 08:33 PM
Ok, in the first tutorial we went through and changed alot of options in the CIV4CivilizationInfos.xml file. This will make the civilization available but we didn't really add much information. Remember the Description, short description, adjective, and civilopedia tags? Well all we did was tell the game where to find the correct information. Now we will actually create this information.

So the folder that holds all of the text in the game is in the Assets/XML/Text folder. The file that holds all of the short identifying text (Like unit names and such) is CIV4GameTextInfos_Objects.xml. We need to create 3 new entries one for each of the descriptions and one for the adjective.

Now before we actually start modding you must realize that Civ 4 was released world wide. So these files in the text folder actually define *ALL* of the languages that are supported. Something really interesting though is the fact that this folder lacks a schema. This means we could add Language support for any language we want including the cool ones like Klingon ;).

Ok, so we have the file open. Lets look at the first entry. BTW I have inlined the comments for this code again.

<!-- Create the new text element -->
<!-- you need to define a new text element for *every* tag made -->
<TEXT>

<!-- This is where we define those refrences we made before -->
<!-- One of our refrences were TXT_KEY_CIV_CANADA_TEXT -->
<Tag>TXT_KEY_IMPROVEMENT_LAND_WORKED</Tag>

<!-- This tag looks a little different then the ones below thats because the english language is asexual in nature -->
<!-- Being asexual we don't have to have different sentence structures to say the same thing like french -->
<!-- If you have your game settings to english this is the text that will show up -->
<!-- Nothing fancy just plain english -->
<English>Land Worked</English>

<!-- This tag tells the game that this is the french language description -->
<!-- you could just as easily write <Klingon> and the game would not care because of the lack of a schema -->
<French>

<!-- This is the text that will appear if the french language option is selected -->
<Text>En travaux</Text>

<!-- This tag is a little wierd, because in french and other languages words have genders -->
<!-- In this case "En Traveux" is male, this effects the words that appear around this text -->
<Gender>Male</Gender>

<!-- This simply states if the word is in plural form -->
<Plural>0</Plural>

<!-- End french language definition -->
</French>

<!-- Start German language definition -->
<!-- this is as far as I go I don't want to repeat myself three more times -->
<!-- you should get the basic idea for now -->
<German>
<Text>Bearbeitetes Land</Text>
<Gender>Male</Gender>
<Plural>0</Plural>
</German>
<Italian>
<Text>Terreno bonificato:Terreni bonificati</Text>
<Gender>Male</Gender>
<Plural>0</Plural>
</Italian>
<Spanish>
<Text>Tierra trabajada:Tierras trabajadas</Text>
<Gender>Female</Gender>
<Plural>0:1</Plural>
</Spanish>
</TEXT>


OK, so now we know the basic structure, lets start adding our definitions.

I like to add my definitions inside the files in alphabetical order, but you can add this stuff anywhere you want I suggest for this tutorial you just add it at the end of the file after the last </TEXT> tag but before the </Civ4GameText>.

So We'll add the descriptions in order, first is the TXT_KEY_CIV_AMERICA_DESC.

Add this:

Remember this is the Long or standard description, you see this at the leader select screen.

<TEXT>
<Tag>TXT_KEY_CIV_CANADA_DESC</Tag>
<English>Canadian Empire</English>
</TEXT>

This is fairly trivial and what it means is that when the game is set to english anywhere you refrence TXT_KEY_CIV_CANADA_DESC the phrase "Canadian Empire" will replace it. If you use a different language then there will be no description. I don't know french or anyother language that well so if somebody could help me translate these things that would be appreciated.

The next two entries are as follows:

<TEXT>
<Tag>TXT_KEY_CIV_CANADA_SHORT_DESC</Tag>
<English>Canada</English>
</TEXT>
<TEXT>
<Tag>TXT_KEY_CIV_CANADA_ADJECTIVE</Tag>
<English>Canadian</English>
</TEXT>

Remeber there is no schema so I can put in or leave out as many languages as I want.

Next is kind of cool. Remember the tag <Civilopedia>? This tag allows our civ to have a civilopedia entry of it's own. I think thats a nice touch. Now we are done with the CIV4GameTextInfos_Objects.xml file, We now have to open the CIV4GameText_Civilopedia_CivLeaders.xml. This holds all of the text for the civilopedia that relates to Civs and their leaders. If you glance through it you will see that this is just the text that shows up in the civilopedia and it has the same structure as the text object file. So I don't think that this part really needs an explanation. at the end of the file after the last </TEXT> tag and before the </Civ4GameText> tag add the following:

<TEXT>
<Tag>TXT_KEY_CIV_CANADA_PEDIA</Tag>
<English>*****Testing Canadian Mod</English>
</TEXT>
<TEXT>
<Tag>TXT_KEY_LEADER_JOHN_MACDONALD_PEDIA</Tag>
<English>[H1]John A. Macdonald [\H1][NEWLINE][BOLD]Prime Minister of Canada [\BOLD][NEWLINE][BOLD]Lived: [\BOLD] c. ???? - c. ???? BC[NEWLINE][PARAGRAPH:2][BOLD]Background:[\BOLD][NEWLINE]*****John A. Macdonald Played a major role in Canada's confederation. Through many meetings he finally joined upper and lower Canada to create the two provinces Quebec and Ontario.</English>
</TEXT>

Ok I said I wasn't going to explain the XML, so I won't. But I will explain the embedded tags. These tags are nothing more then HTML enclosed in square brackets instead of pointy brackets. HTML isn't necessary for modding civ 4 but it makes everything more interesting. So I would say take a crash course in basic HTML to add some flavor to your Civilopedia texts.

We now are looking at the <DefaultPlayerColor> tag. All we did was set it to red. But what if we wanted to add our own custom color? well color definitions can be found in the Assets/XML/Interface/ folder in the file CIV4ColorVals.xml. Color definitions are very straight forward. Take COLOR_CLEAR for example:

<!-- This starts the color definition -->
<ColorVal>

<!-- This is how we refrence the color -->
<!-- We should follow the naming scheme because it makes life easier -->
<Type>COLOR_CLEAR</Type>

<!-- This tells us the intensity of the red in this color. 0.00 is no red, 1.00 is ful intensity -->
<!-- It is *Very* important to use numbers in the format 0.00 or else the game will act funny or not even load -->
<!-- You must keep the values between 0.00 and 1.00 or the game will either act funny of crash -->
<fRed>1.00</fRed>

<!-- Tells us the intensity of green used for the color -->
<fGreen>1.00</fGreen>

<!-- Tells us the intensity of blue used for the color -->
<fBlue>1.00</fBlue>

<!-- This tag tells us how transparent the color is. -->
<!-- 1.0 means that the color is totally opaque, 0.0 means invisible -->
<fAlpha>0.00<fAlpha>

<!-- end color definition -->
</ColorVal>

Thats it for colors, Now I want to see someone implement every color they know ;)

I will skip the ArtDefineTag and ArtStyleTag because they deserve their own tutorial.

Now on to defining cities, these definitions go in the text directory in the CIV4GameTextInfos_Cities.xml file. There isn't anything new here so I will just add the St. Johns city definition we did in the last tutorial.

<TEXT>
<Tag>TXT_KEY_CITY_NAME_ST_JOHNS</Tag>
<English>St.John's</English>
</TEXT>

For every city you add in the cities list of your civ there has to be an accomponying definition in the CIV4GameTextInfos_Cities.xml file.

Thats it for adding the text entries for your civ. In the next tutorial I will explain how to add the John A Macdonald Leader for your new civ. If you want to play test you can use the Leader definition from Another civ.

Weasel Op
Oct 30, 2005, 08:37 PM
Great job. I'm linking to these in my modding thread.

BrentRitchie
Oct 30, 2005, 08:42 PM
No problem, glad to help. Part 3 should be up Saturday evening. Got lots of school stuff this week.

thedaian
Oct 30, 2005, 08:49 PM
I can see great things from using the language tags... amoung using <klingon> and such. I do have a question, does anyone know where the list of languages are (as in, which files has the language selection options, so a <klingon> tag would actually do something), and, do you need to have every language, or can you just skip some? (it looks like you can, so I'll assume yes)

Weasel Op
Oct 30, 2005, 08:51 PM
I can see great possibilities here with a LotR mod.
<sindarin>
<quenya>
:D:D:D

BrentRitchie
Oct 30, 2005, 09:31 PM
thedaian:

You do not need all the language tags but probably a good idea if distributing a real mod not just a tutorial mod. As to the actual language option definition, I haven't waded through the GameInfo or Misc folders, That's more then likely where it is though.

Tabris
Oct 31, 2005, 02:51 PM
I'm having some problem trying to implement Byzantines in a mod, i'm trying to make a flag like the one of england but red with a yellow cross, i've notice that if i set the color to dark purple i'll get a purple flag with a yellow cross, but using red i get a red flag with a white cross, how can i put red flag with a yellow cross?

Hikaro Takayama
Oct 31, 2005, 08:19 PM
Even though it will be some time before I buy Civ IV (let alone start modding it), I would like to know what all can be used to edit XML (besides notepad and wordpad, of course :rolleyes: )? I have Microsoft Frontpage 2K, which are HTML editors, but I'm not sure if it can handle XML as well (I'ts been a while since I last used the program and checked its save file options, and I have to re-install it since my notebook crashed.....).

I was just curious as to how much of a headache I'll have editing this stuff.

BrentRitchie
Oct 31, 2005, 08:26 PM
Tabris, I've been playing with the flags also and haven't come up with anything yet. In my early testing It seems that maybe the secondary color of the Player_Color tags might do the trick but my testing isn't done yet. Maybe give it a try?

Hikaro Takayama, I only use Internet Explorer for reading the original Civ 4 XML files. I have Notepad open at the same time so I can take notes and write my mods into it. I have tried other XML editors and never liked any of them.

Hikaro Takayama
Oct 31, 2005, 08:38 PM
Hikaro Takayama, I only use Internet Explorer for reading the original Civ 4 XML files. I have Notepad open at the same time so I can take notes and write my mods into it. I have tried other XML editors and never liked any of them.

Well, if IE can open them, then FrontPage can edit them. It's not that I find the XML that difficult, it's just like HTML for me: I hate nothing more than typing 3 pages of HTML for a webpage only to find, after loading it in IE for the first time, that I missed a </font> tag somewhere in the middle of the whole mess. FrontPage takes a lot of the hassle out of the process and allowed me to create a page in about 2 minutes that took me 2 hours to do the long way (using Notepad).

THanks answering my question.

BrentRitchie
Oct 31, 2005, 08:46 PM
If your comfortable with frontpage go for it, it should handle xml files great, especially if it is fairly recent. I hope to see some of your mods when you get the game.

Hikaro Takayama
Oct 31, 2005, 08:53 PM
If your comfortable with frontpage go for it, it should handle xml files great, especially if it is fairly recent. I hope to see some of your mods when you get the game.


You'll be waiting a couple of years..... I'm not getting Civ IV untill all the expansion packs and patches are out, so that I can 1) avoid some of the hassle and expense that I experienced with buying Civ III piecemeal, 2) so I can also finish up my Civ III projects, and 3) so I can get a better idea of what Civ IV minus all the "JUST RELEASED!!!!!!" hype is really like.

cursif
Nov 02, 2005, 05:41 AM
Is there any way to get the first part of this tutorial moved into this "section"? With the searching disabled it's harder to find things. I know you can use the Google search but it searches every single forum and section and doesn't tell you which section the result is from.

Granias
Nov 03, 2005, 06:39 AM
Great tutorial :goodjob:

And I also can't seem to find the first part. Perhaps it can be linked in this thread?

BrentRitchie
Nov 03, 2005, 09:52 PM
Civ 4 XML Tutorial Part 1 (http://forums.civfanatics.com/showthread.php?t=135459)

Just FYI, I was supposed to have part 3 of my series done for saturday but I'm going home for the weekend. My mom is cooking homemede lasagna, MMMmmmmmm. So I will hove it done early next week instead. Sorry for any inconvience.

Belaflek
Nov 04, 2005, 07:40 AM
...nm...
Just saw the link

ainwood
Nov 04, 2005, 01:43 PM
Moved to the tutorials section.

Wolfshanze
Nov 05, 2005, 08:07 PM
Okay, I read the post... maybe my eyes are fogging or something... how do I change a unit name and which XML files need changing? I tried to change the name of the Spearman and kept getting errors.

Which file(s) do I need to edit to change a unit name?

Feet
Nov 11, 2005, 05:27 AM
Any chance of seeing the third part any time soon?

BrentRitchie
Nov 15, 2005, 07:05 PM
Part three will be up tomorrow.

evantis
Feb 21, 2006, 11:20 PM
<!-- This tag is a little wierd, because in french and other languages words have genders -->
<!-- In this case "En Traveux" is male, this effects the words that appear around this text -->
<Gender>Male</Gender>

<!-- This simply states if the word is in plural form -->
<Plural>0</Plural>

<!-- End french language definition -->
</French>

<!-- Start German language definition -->
<!-- this is as far as I go I don't want to repeat myself three more times -->
<!-- you should get the basic idea for now -->
<German>
<Text>Bearbeitetes Land</Text>
<Gender>Male</Gender>
<Plural>0</Plural>
</German>


I've sent you a Private Message, but maybe someone else will also know this. In some xml's there is a [NUM1:something:something_else] text, which chooses a text depending of <plural> text state (0 or 1). My question is: can I do the same (and if, how?) with the <gender> tag? For now, it seems to me quite useless, because i didn't find any use of <gender> in xml files. Please, correct me if I'm wrong. I'd like to translate Civ4 correctly to Polish, and my language uses genders as well as French.

<Italian>
<Text>Terreno bonificato:Terreni bonificati</Text>
<Gender>Male</Gender>
<Plural>0</Plural>
</Italian>
<Spanish>
<Text>Tierra trabajada:Tierras trabajadas</Text>
<Gender>Female</Gender>
<Plural>0:1</Plural>
</Spanish>
</TEXT>

And explain, please, how does Civ4 'know', which one to choose in Italian: Terreno bonificato or Terreni bonificati (first case).

mikezang
Mar 23, 2006, 07:54 PM
I added Chineses characters to section <Chinese></Chinese>, and modified
<?xml version="1.0" encoding="ISO-8859-1"?> to
<?xml version="1.0" encoding="UTF-8"?>
and save xml file in UTF-8 format.
The problem is font, in default, civ4 is using western font, how and where can I config it to use Chinese font in my PC?

BFD8656
Mar 31, 2006, 05:49 PM
I loved this explaination! I had made a Civ from another HOW TO guide and they left out a few important things. I knew nothing and what they skipped over caused me to have major problems.

Would you make one of these for adding a unit? I know how to add a UU but to just make my own units is causing me some troubles.

I have made a War Wagon, Warhound and a Milita (fighting worker) but I have having troubles getting them to work without errors.

If you know of another thread like this that could help me I would LOVE a link!

Kahkonen
Apr 07, 2006, 03:29 PM
<TEXT>
<Tag>TXT_KEY_CITY_NAME_ST_JOHNS</Tag>
<English>St.John's</English>
</TEXT>


If I want to translate civ4 into fluent Finnish, I have to use grammatical cases:
<Tag>TXT_KEY_UNIT_WOLF</Tag>
<Finnish>susi:suden:sutta</Finnish>
(As you can notice, I can not simply add "'s" after words like in English...)

And so can I write "%s1:2" and it takes "suden".

But when I do the same for city names:

<Tag>TXT_KEY_CITY_NAME_ST_JOHNS</Tag>
<Finnish>St.John:St.Johnin:St.Johnissa</Finnish>

For some reason every new city is then named after the civ's capital. If the first city is London, second is London, third is London, ...

Why's that?

mikezang
Apr 08, 2006, 02:54 AM
I knew the reason, because civ4 will check all city names and compare if the name exists, if there ie no the name, it will prompt. You can try to modify name when build a new city, next when you build another city, the same city name will be displayed.

In your case, the displayed name is compared with name saved in xml file, they have differnt internal code as decode and encode, so Capital name always showed.

Kahkonen
Apr 08, 2006, 04:50 AM
In your case, the displayed name is compared with name saved in xml file, they have differnt internal code as decode and encode, so Capital name always showed.

Any possibilities to have grammatical cases with cities? I need them *really*.

Papa Smurf
Mar 05, 2007, 08:10 PM
Is it wrong if a put...
<Text>
instead of
<TEXT>

Liberace_2211
Aug 20, 2007, 02:28 PM
Really useful post. Thank you for your time =D