Changes between Version 3 and Version 4 of ModdingResources


Ignore:
Timestamp:
Oct 28, 2017, 2:51:48 PM (7 years ago)
Author:
Nescio
Comment:

Finished (for now)

Legend:

Unmodified
Added
Removed
Modified
  • ModdingResources

    v3 v4  
    33= Modding Resources =
    44
    5 As of r18964, the code base of 0AD attempts to deal with gatherable/tradable/tributable resources (ie. `food`, `wood`) in an agnostic fashion. In other words, the resources are not hardcoded inside simulation components, the GUI or the AI.
     5As of r18964, the code base of 0AD attempts to deal with gatherable/tradable/tributable resources (e.g. `food`, `wood`) in an agnostic fashion. In other words, the resources are not hardcoded inside simulation components, the GUI or the AI.
    66
    77This means that adding or removing resources are somewhat easier for modders to do, should they wish. The following guide attempts to show how to do just that.
     
    5454* **`name`** - Player-friendly name of the resource. This will be localized into the player's chosen language (if localizing data exists for it)
    5555* **`order`** - The order it appears in the in-game GUI. Resources will appear in numerical order of this attribute.
    56 * **`subtypes`** - An object of Subtypes of this resource. At least one must be specified. The entries within this object follow the form `"{subtype-code}": "{subtype-name}"` where `subtype-code` is the internal reference to this subtype, and `subtype-name` is the user-friendly translatable name of the subtype. Resources can have the same subtype codes (ie. both `wood` and `stone` both possess a `ruin` subtype).
     56* **`subtypes`** - An object of Subtypes of this resource. At least one must be specified. The entries within this object follow the form `"{subtype-code}": "{subtype-name}"` where `subtype-code` is the internal reference to this subtype, and `subtype-name` is the user-friendly translatable name of the subtype. Resources can have the same subtype codes (e.g. both `wood` and `stone` both possess a `ruin` subtype).
    5757* **`truePrice`** - This is the true worth of the resource. This is used in calculating how much should be exchanged per click in the markets' Barter dialogue compared to other resources. See the `Barter` component for further details.
    5858* **`aiAnalysisInfluenceGroup`** - This is used by the AI to help determine where to build resource deposit sites and where to allocate workers. There are three possible values:
     
    7070
    7171
    72 == To remove a resource == #removeResource
     72== How to remove a resource == #removeResource
    7373Substraction is the inverse of addition. To remove a resource, in short, follow the instructions to add a resource (below), but in reverse making sure to remove all reference to the resource. Although not really difficult, it is a lot of work. Suppose you would want to remove a certain resource, e.g. food (because your units are not children anymore, they can look after themselves, and get their own food; just because AoE includes food as a resource doens't mean 0 A.D. has to as well). A sensible, though not necessary complete approach, could be:
    7474* remove all entries (e.g. Cost, Loot, ResourceGatherer, etc.) in all `simulation/data/` and `simulation/templates/` (e.g. using `grep food *` is very helpful)
     
    135135
    136136
    137 Congratulations! You can now have, display, trade, barter, and spend “water”!
     137Congratulations! You can now have, display, trade, barter, tribute, and spend “water”! You can now also “water” in technologies and templates (e.g. as costs, loot, resource trickle rate, etc.).
    138138
    139139
     
    1541542.  Provide something to gather from. For this you will need to create or modify an xml file to define the entity that will be your gather-site.
    155155
    156     The parent template you may wish to inherit from will differ depending on your resource, for instance if your resource is something mined then inheriting from `template_gaia_geo` would be a good start, or if your resource comes from a plant then inherit from `template_gaia_flora`, or if gathered from some kind of structure (ie. a farm) `template_structure_resource`.
     156    The parent template you may wish to inherit from will differ depending on your resource, for instance if your resource is something mined then inheriting from `template_gaia_geo` would be a good start, or if your resource comes from a plant then inherit from `template_gaia_flora`, or if gathered from some kind of structure (e.g. a farm) `template_structure_resource`.
    157157
    158158    Either way, in order to make the gather-site provide your resource you must include the `ResourceSupply` component into the template of your gather-site:
    159     {{{
     159{{{
    160160#!xml
    161161  <ResourceSupply>
     
    165165    <MaxGatherers>1</MaxGatherers>
    166166  </ResourceSupply>
    167     }}}
     167}}}
    168168
    169169    For the specifics of what tag does what here, see the schema of the [source:/ps/trunk/binaries/data/mods/public/simulation/components/ResourceSupply.js ResourceSupply] component.
    170170
    1711713.  To the templates of the units that will be doing the gathering (or the parent templates of those units), add a gather rate and carry capacity to the `ResourceGatherer` component. For example:
    172     {{{
     172{{{
    173173#!xml
    174174  <ResourceGatherer>
     
    180180    </Capacities>
    181181  </ResourceGatherer>
    182     }}}
     182}}}
    183183
    1841844.  Your units will then need to drop the resource off somewhere. If the resource is to be dropped off at a structure (or worker elephant) that already permits resource dropping off, add your resource type to the existing `Types` list inside the `ResourceDropsite` component. Else add the component to the structure:
    185     {{{
     185{{{
    186186#!xml
    187187  <ResourceDropsite>
     
    189189    <Sharable>true</Sharable>
    190190  </ResourceDropsite>
    191     }}}
     191}}}
    192192
    1931935.  Lastly, modify the `art/actor` xml files of **all** the actors of **all** the units you wish to gather this new resource so as to tell the game which animations and props to use on units for gathering and returning with your new resource. Every civ that has that unit, every promotion level. The easiest way to do this is to use `variants` (see the contents of the `art/variants` folder for some idea of how this works), but it will still require modifying a lot of actor templates.
    194194
    195195    This step could be seen as optional, as the gathering will still take place without error, but without it units will just stand at the resource (playing the idle animation) until their resource capacity is full.
     196
     197
     198
     199== Teaching the AI to gather the new resource ==
     200For this you will have to edit some of the `simulation/ai/` files.
     201
     202
     203
     204== Including your resource objects on maps ==
     205If you have created new objects from which your new resource can be gathered (e.g. water wells), you might want to include these into the `maps/` files.
    196206
    197207
     
    210220* `simulation/templates/special/player_gaia.xml`
    211221* `simulation/templates/template_structure.xml`
    212 This sufficient for having, displaying, trading, bartering, and using a resource.
     222This sufficient for having, displaying, trading, bartering, tributing, and using a resource.
    213223
    214224If you also want to make your resource gatherable, you'll need more icons, create templates, and edit AI files and maps; see the relevant sections (above).