Jump to content

How to modify 0 A.D.?


Recommended Posts

How difficult is it to create a game modification for 0 A.D.? Is there a guide where to start?
Things I would like to do include changing unit statistics (e.g. health, armour, training time), introducing new unit types, overhauling the damage counter system, and adding six new factions (Armenia, Attalids, Boeotians, Parthia, Ponthus, Scythians) but reusing the existing graphics etc. Any advice or help to get started would be appreciated.

Edited by Nescio
thread title
  • Like 2
Link to comment
Share on other sites

That is defined in the simulation templates ( http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/templates/ )

F.e. the default attack of the archer is defined to be 6.5 pierce for the moment: http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/templates/template_unit_champion_infantry_archer.xml#L3

Note that templates inherit from each other. So you can define a default value for the generic archer, but define a special value for a special archer unit.

To redefine it in your mod, you must just copy the file to your mod, and change the values. Your file will override the version that's used in the game. F.e. in millenium A.D., they altered some resource templates to have other stats: https://github.com/0ADMods/millenniumad/tree/master/simulation/templates (in this case, they changed to colour of those elements on the minimap, which is also a stat).

  • Like 3
Link to comment
Share on other sites

You edit the relevant units XML template file if your a Windows guy install notepad++ it can be set for various coding languages XML being just one it also handles json files which cover GUI and simulation features for your mod remember to do a copy of the default files rename the folder there in to some like mymod then edit those not the originals this is just basic strategy for all coding/modding that and KISS which is "keep it simple stupid" to start till you get familiar with the whole process small steps at a time that make sense to you at the time as you gain experience getting things to work the way you what them to,and feel free to ask questions as you may have noticed by now we don't bite ;) 

Enjoy the Choice :)  

Edited by Loki1950
  • Like 2
Link to comment
Share on other sites

Thank you all for your quick and helpful replies! I've had a look at those links and indeed, the data structure seems pretty straightforward, and i think I understand which files I need to modify unit statistics. If I would like to lower the health of all champion swordsmen, I simply edit template_unit_champion_infantry_swordsman.xml, and if I want to improve the attack of the Mauryan champion warrior (yoddha) only, i edit the units/maur_champion_infantry.xml file.
However, I do have several additional questions:


1. Where exactly do I put the files of “mynewmod”?
a. in .local/share/0ad/mods/ ?
b. in .local/share/0ad/mods/mynewmod ?
c. in .local/share/0ad/mods/mod/ ?
d. in .local/share/0ad/mods/mod/mynewmod ?
e. in .local/share/0ad/mods/public ?
f. in .local/share/0ad/mods/public/mynewmod ?
g. in .local/share/0ad/mods/user ?
h. in .local/share/0ad/mods/user/mynewmod ?
i. somewhere else?


2. How can I add damage counters? For instance, I would like to have melee cavalry inflict 0.5× damage vs all elephants (because a horse won't attack an elephant; one of the main functions of elephantry in Indian warfare (until the British changed everything) was to shield the vulnerable infantry against cavalry attacks), 0.75× vs camels (because horses don't like the smell of camels, which is why several camel corps were created in late Antiquity, to panic the enemy cavalry), and 1.5× vs ranged infantry (the primary function of cavalry on the battlefields in Antiquity was to take out those enemy skirmishers).
Cavalry javelinists should have a normal attack vs all those, but 1.5× damage vs chariots (because Alexander's light cavalry (skirmishers) devastated the Indian chariotry during his campaigns there).


3. How to change the availability? For instance, I want to make the Mauryan elephant stables available in age I, disable worker elephants at the civic centre, and enable them in age I at the elephant stables.


4. How to remove a unit? For instance, I would like to disable the Mauryan bireme, because they already have a more powerful trireme (the Britons, Gauls, and Celts don't have biremes either).


5. How to enable a newly added unit? For instance, I would like to have quadriremes (basically an improved trireme; age III, 1600 health, 40 garrison capacity, 4 population, 4+12 arrows), available to Carthage, Rome, Macedon, Seleucids, and Ptolemies, because quadriremes were one of the most widely used hellenistic warships. So I create:
What else should i do to make them available in game?


6. How to copy an existing civilization (e.g. the Persians) to start as the basis for a new faction (e.g. the Parthians, who peaked in the middle of the first century BC)? Which files do I need, and which can I omit?


PS No, I'm not a “Windows guy” (any version newer than XP is too difficult for me); I'm currently using Fedora 24.

  • Like 1
Link to comment
Share on other sites

1. b: .local/share/0ad/mods/mynewmod

2. Yes, we have hard counters, though most hard counters have been removed from the stats, as they were considered confusing for users and balancers. Without hard counters, you have some less variables to take into account, and it makes balancing easier. The code is still present though, and we still use it in a few templates, like spearmen still have a hard counter against cav: http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/templates/template_unit_champion_infantry_spearman.xml#L14

3. That's defined in the "RequiredTechnology" key, you can make buildings available on any tech research, and phases are mostly just like other techs: http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/templates/structures/maur_elephant_stables.xml#L26

4. adding ".DELETE" to the end of the file name will delete the file from the parent mod. But in this case, you can also remove it from their Builder Entities list for all Mauryan units: http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/templates/units/maur_infantry_archer_b.xml

5. For a building, add it to the Builder Entities of certain units, for a unit, add it to the ProductionQueue of a building. Do watch out with the {civ} codes, as it makes a difference with captured buildings. The civ is the civ of the owner, so the units you can make in a building depends on who has captured it, unless you hard-code the civs in the templates, in which case the capturer can produce units of a different civ.

6. Millenium A.D. is a good example of this (adding 2 factions with custom art and only few other changes). So best take a look there. If you don't want to modify the art yet, copying the unit and structure templates and the civ.json is probably enough. http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/data/civs

  • Like 2
Link to comment
Share on other sites

sanderd17, thanks again for your helpful reply!

1. Thank you for the confirmation

2. Well, I'm not sure I fully understand your answer. Yes, I've noticed the spearman bonus, and changed it to 4× for pikemen, 3× for hoplites, and 2× for other spearmen. However, now I want to give infantry swordsmen a 1.5× attack vs pikeman; how should I do that?

3. Seems straightforward. The Mauryans can now build elephant stables in the village phase, and elephant archers in the town phase.

4. That was not really what I meant, but I already figured how to do it, by putting an hyphen-minus in front. For instance, to disable biremes and triremes at the Carthaginian commercial port (cart_dock.xml), insert:
  <Entities datatype="tokens">

5. That's easier than expected!

6. Again, i had expected more difficulty. I've added Pontus and, although there are some minor issues to solve, it seems to be working!


Again, I really appreciate your help. Now I've starting modifying I get additional ideas and have a few more related questions:


7. Which files do I need to add new or edit existing:
a. civilization bonuses?
b. team bonuses?
c. technologies?

Link to comment
Share on other sites

2. Yes, that sounds correct, the name of the bonus doesn't matter, it just has to be unique in the file to allow our tools to parse it.

For the techs, see here: http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/data/technologies

Civ bonuses are just techs with an "autoresearch" flag set. And team bonuses are implemented as auras because auras can be undone again (and diplomacies see also not fixed in the game).

  • Like 1
Link to comment
Share on other sites

2. How unique has to be unique? Yes, I understand it must be different from other commands, but can I use <BonusX></BonusX> for different units vs different classes?
By the way, how are classes defined? Are they the same as <VisibleClasses datatype="tokens">Melee Spear Pike</VisibleClasses>, or <GenericName>Champion Pikeman</GenericName> (I suppose not), or is there a different <class></class> defined somewhere else?
And how
are they interpreted? E.g. would the following affect ranged infantry only, or all infantry and all ranged units?
    <Classes>Infantry Ranged</Classes>
And if I want to give a unit two different bonus attacks (e.g. spear cavalry a bonus attack vs infantry skirmishers and one vs cavalry archers), how am I supposed to do that?


7. Yes, I've seen those technology files, but technologies are also listed in the civ files. The current relationship is not fully clear to me. For instance, simulation/data/civs/maur.json contains:
    "Name": "Evangelism.",
    "History": "Ashoka the Great sent embassies West to spread knowledge of the Buddha.",
    "Description": "Allied Temple techs -50% cost and research time."
However, I have been unable to find the “Evangelism” bonus or technology.

Link to comment
Share on other sites


I think you have yet read all the links sanderd17 had provided to you.

The technologies are in simulation/data/technologies/

You will find most of the civbonus here. In the civ specific folder.

The auras are in simulation/data/auras/

You will find the teambonus in the ad hoc folder. (But there is still some work to do for team bonuses).

Some civbonuses can be implemented directly in the templates.

In simulation/data/civs there are mainly informations about civs. The civ bonus written here are just for information, some are not implemented or will perhaps never been implemented.

At last, Evangelism is currently the aura of Ashoka the Great.

Link to comment
Share on other sites

The classes are defined as the union of the VisibleClasses and the Classes lists (with the only difference being that the VisibleClasses list is also displayed in the GUI). And unique is just different from the other names in the file. So <BonusX> works if you use a different X every time in the file.

And the civ bonuses are defined in the technologies only. The things you see in the civ.json files are just descriptions for the GUI (namely the history section of the game).

Link to comment
Share on other sites

Two other things:

8. When garrisoned in a building or loaded into a ship, I want cavalry and camels to occupy two spaces instead of one, bigae (two-horse chariots), bolt shooters and catapults four, and quadrigae (four-horse chariots), elephants, battering rams and siege towers six. How should I do that?

9. Is it possible for a unit to have two different attacks? E.g. I'd like the quinqereme to have a simple pierce attack by default (as has the trireme), and a crush attack when it has any catapults garrisoned inside.

Link to comment
Share on other sites

2 hours ago, Nescio said:

9. Is it possible for a unit to have two different attacks? E.g. I'd like the quinqereme to have a simple pierce attack by default (as has the trireme), and a crush attack when it has any catapults garrisoned inside.

Not yet see #252 (and #4000 for this issue too)

Link to comment
Share on other sites

9. Do you mean damage or attack ? For doing something like that you'll need to modify BuildingAI.js. You can look at auras too (but I guess it will not work). There were unachieved work to make them visible (and then they'll use their own attack) but it introduced lots of issues.

8. That's something I had yet thought too. You need to modify a bit GarrisonHolder.js

Link to comment
Share on other sites

  • 11 months later...

Hi all! Because I have several additional questions, I revived this old topic of mine:

10. How to delete an unit entirely? Yes, I know that if I would want to remove an unit from being available at a certain building, I would put a - in front of the name in the production queue (e.g. -units/{civ}_cavalry_javelinist_b if I want to disable training the Perioikoi cavalryman from the Spartan civil centre). But what if I wanted to remove the existence of the Spartan Perioikoi cavalryman completely from my mod?

11. I always assumed bonus attacks act as multipliers, e.g. 1.5 means 1.5× thus +50% and 0.5 means 0.5× thus -50%. Can you confirm this is the case? Because an alternative interpretation (1.5 means +150% thus 2.5× and 0.5 means +50% thus 1.5×) would disrupt the counter system in my mod.

12. How do bonus attacks combine? For instance, I lowered the battering ram's base damage but gave it two bonus attacks:

Now, how does this effectively work out?
a. bonuses amplify each other, i.e. the ram does 2× damage vs structures not gates or gates not structures (if these would exist), and 2×2×=4× vs targets which are both a gate and a structure
b. bonuses work independently of each other, i.e. 2× means +100%, therefore vs targets which are both a gate and a structure the ram does +100%+100%=+200% thus 3× damage
c. bonuses do not combine, i.e. the ram does 2× damage vs gates or structures, and 2× damage vs targets which are both a gate and a structure

I assume it's (a), but I'd like to have a confirmation.

13. And what if the code were:
          <Classes>Gates Structure</Classes>

Where would this result into?
a. rams do 2× damage vs gates or structures or targets which are both a gate and a structure
b. rams do 2× damage vs  targets which are both a gate and a structure, but not vs targets which are either gates or structures (or neither)
c. rams do 2× damage vs targets which are either gates or structures, but 2×2×=4× damage vs targets which are both a gate and a structure
Again, I assuming (a), but I would appreciate a confirmation.

14. How to disable the feature of the Iberians starting a game with city walls around their civil centre?

Edited by Nescio
Link to comment
Share on other sites

10: dunno if there is a better solution than putting the - on all productionqueues...

11: the values are multipliers indeed so 1.5 == +50% and so 0.5 == -50%

12: a)

attackBonus *= bonus.Multiplier;

a gate would get 4* bonus

13: for some reason the code is a bit strange here

if (bonus.Classes && bonus.Classes.split(/\s+/).some(cls => !cmpIdentity.HasClass(cls)))

so the target should have all classes b).

(usually a " " is taken as a logical "or", i might write a patch for this...)

Link to comment
Share on other sites

10. Just add the ".DELETED" suffix to the template file you want to remove.  And put it in your mod. I don't see why you would do that since if it can't be recruited in game the unit shouldn't be a problem.

14. You cant easily. Every skirmish map has prebuilt walls. Might want to take a look at the civ.json file for Iberians though

Link to comment
Share on other sites

Thank you for your quick replies, both of you! One more question:

15. How to add multiple tooltips to a unit description? E.g. for the Siege Tower:
    <Tooltip>Garrison units for transport and to increase firepower.</Tooltip>
    <Tooltip>Counters: 2.0× vs. Fortresses, Towers.</Tooltip>
This results in the second tooltip replacing the first. Of course, both could be merged into one:
    <Tooltip>Garrison units for transport and to increase firepower. Counters: 2.0× vs. Fortresses, Towers.</Tooltip>
But the result looks a bit cluttered and is undesirable in my opinion. Ideally I want to have each tooltip on a seperate line.


EDIT: Accidently I discovered the answer myself. Just putting the second tooltip on a new line works:
    <Tooltip>Garrison units for transport and to increase firepower.
Counters: 2.0× vs. Fortresses, Towers.</Tooltip>
It's much easier than I had thought; I actually feel a bit ashamed for asking in the first place :)

Edited by Nescio
Found it!
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...