Chapter 2. Spellbooks - I want my Fire Giant! And I want it now!
OK. Now that the pesky Altarians are out of the picture, lets get our own spells.
We have a few things we need to setup before we can do this though. This will introduce how various XML files rely on each other.
Before we get started it is important to realise how spell books work. First of all you get spell books from your sovereigns. By default all of them have all spell books already turned on. Hopefully this will be seriously nerfed in future patches to make magic more of a choice - but I digress. The second method of getting spellbooks is through your race.
We will be using the second method.
In this example we are going to be using the Capitar Mancers as our race.
First of all, lets create our spell book. In this example we are just going to have a single spell that is accessible from the very start of the game. And yes, because I like Fire Giants, the spell is going to be the Fire Giant summon spell.
You can create your own spells in the XML but we're not going to do that here. We are simply going to piggy back off the current Fire Giant spell.
Create a new XML file called 'DasTut_SpellBooks.xml.
By the way, the file-names don't actually have any bearing on what gets loaded. You could call these files anything you like and it will still work as long as the XML inside is correctly formed. I tend to use a reference back to the core file I borrowed the code from - so this file will mainly come from CoreSpellBooks.xml.
In the file, type the following:
Code: xml
- <?xml version="1.0" encoding="utf-8"?>
- <Spells>
- <Spellbook InternalName="MancersSpellbook">
- <DisplayName>Mancers</DisplayName>
- <Icon>Fire_Dot.png</Icon>
- <Cost>3</Cost>
- <SpellbookNode InternalName="Node00">
- <NodeID>0</NodeID>
- <SpellDef>SummonFireGiant</SpellDef>
- <StartingKnown>1</StartingKnown>
- <StartingResearch>1</StartingResearch>
- </SpellbookNode>
- </Spellbook>
-
- </Spells>
So, everything is contained in a 'Spells' tag.
Then we have our SpellBook tag with the InternalName of 'MancersSpellbook'. MancersSpellbook is the name we ultimately use to reference and load the spell book.
The DisplayName is the name of the spell book.
The Icon is the image it will use. If you want your own, just build a PNG file and store that in your Mods directory.
SpellbookNode and its NodeID are references.
SpellDef is the name of the spell you will be calling. These are defined in the various CoreSpells_ files. In this case Fire Giants are defined in CoreSpells_FIRE_Strategic.xml. You can create your own spells but I won't be going into that sort of detail here. If i was I would create another XML file called DasTut_CoreSpells_Mancers.xml and work in that.
StartingKnown with a value of 1 tell the game that if you have the Mancers spell book, you start off knowing this spell. Which is what we want in this example.
Right. At this point we have our spell book but the game doesn't know that our Mancers want to use it. We'll soon fix that.
The current problem with the core files is that all the Kingdom races are the same and use the Altarian spells, techs, etc etc. We're going to change this.
Open your DasTut_RaceConfig.xml file again and add the following under the Altar RaceType:
Code: xml
- <RaceConfig InternalName="KingdomOfCapitar">
- <Spellbook>MancersSpellbook</Spellbook><!-- Adds to basic spell books loaded from core -->
- </RaceConfig>
We are now using a RaceConfig with an InternalName of "KingdomOfCapitar" which corresponds to the core files.
So the full code should now be:
Code: xml
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <RaceConfigs>
- <DataChecksum NoParse="1">
- <Ignore>DisplayName, ShortName, Capitol, Description, UnitSkinColor, UnitHairColor, UnitClothColor, BuildingPrimaryColor, BuildingSecondaryColor, BuildingRoofColor, BuildingStyle, UnitStyle, WorkerName</Ignore>
- <Translate>DisplayName, ShortName, Capitol, Description, WorkerName</Translate>
- </DataChecksum>
- <RaceConfig InternalName="KingdomOfAltar">
- <HideInSetupLists>1</HideInSetupLists> <!-- Hides the race -->
- </RaceConfig>
- <RaceConfig InternalName="KingdomOfCapitar">
- <Spellbook>MancersSpellbook</Spellbook><!-- Adds to basic spell books loaded from core -->
- </RaceConfig>
- </RaceConfigs>
Note the command <Spellbook>MancersSpellbook</Spellbook> where 'MancersSpellbook' is the same name as the Spellbook InternalName from the start of this chapter.
Basically we've just added (not replaced) the Mancers spell book to the Capitar Mancers. You can have multiple spell books for each race. In the core files the Mancers start with the Life spell book, and that isn't replaced.
Try the game again. You'll now see you have the FireGiant spell available right from the start as long as you choose the Capitar Mancers race.