Changes between Version 2 and Version 3 of ModdingResources


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

Continued updating

Legend:

Unmodified
Added
Removed
Modified
  • ModdingResources

    v2 v3  
    3232=== Change a resource name or other aspects === #resourceData
    3333The resources themselves are defined each in a separate `{resource}.json` file in `simulation/data/resources/`
    34 
    35 
    36 
    37 == To remove a resource == #removeResource
    38 Substraction 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.
    39 
    40 
    41 
    42 == How to add a new resource to 0AD == #addResource
    43 
    44 1.  Create a new file in the folder `simulation/data/resources` named something sensible (ie. `water.json`). If you like, copy one of the currently existing resources and amend as needed.
    45 
    46     The contents of the file follow the following syntax:
    47     {{{
     34Let's have a look at the complete file of resource number one, food, to see how it works; `food.json`:
     35{{{
    4836#!js
    4937{
    50         "code": "water",
    51         "name": "Water",
    52         "order": 1.1,
    53         "subtypes": {
    54                 "well": "Well Water"
    55         },
    56         "truePrice": 50,
    57         "aiAnalysisInfluenceGroup": "ignore",
     38  "code": "food",
     39  "name": "Food",
     40  "description": "Harvest from animals, berry bushes, fish, or fields.",
     41  "order": 1,
     42  "subtypes": {
     43    "fish": "Fish",
     44    "fruit": "Fruit",
     45    "grain": "Grain",
     46    "meat": "Meat"
     47  },
     48  "truePrice": 100,
     49  "aiAnalysisInfluenceGroup": "ignore"
    5850}
    59     }}}
    60     * **`code`** - Internal identifying code for this resource. Cannot be the same as another resource
    61     * **`name`** - Player-friendly name of the resource. This will be localized into the player's chosen language (if localizing data exists for it)
    62     * **`order`** - The order it appears in the in-game GUI. Resources will appear in numerical order of this attribute.
    63     * **`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).
    64     * **`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.
    65     * **`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:
    66       * **`ignore`** - The AI will ignore this resource when it comes to planning where to build gather sites. This could be for several reasons, for instance that supplies of this resource move around (ie. animals) or can be built by the player (ie. farms)
    67       * **`abundant`** - This resource is abundant (very common) on the average map, but each deposit only contains a small amount of the given resource. (ie. `wood`)
    68       * **`scarce`** - The resource has few deposits on the average map, but each deposit contains a fair to large quantity of the given resource. (ie. `stone` or `metal`)
    69 
    70 2.  Provide two icons, with names in the form of `{res}.png` and `{res}_small.png` (ie. `water.png` and `water_small.png`), and place them in the folder `art/textures/ui/session/icons/resources`. The icons should be 64x64 pixels and 16x16 pixels respectively.
    71 
    72 3.  Amend `gui/common/setup_resources.xml` so that you can use `[icon=icon_{res}]` in game UI texts. For example, adding the following to the file
    73     {{{
    74 #!xml
    75         <icon name="icon_water"
    76                 sprite="stretched:session/icons/resources/water_small.png"
    77                 size="16 16"
    78         />
    79     }}}
    80     permits using `[icon=icon_water]` within the game's UI text.
    81 
    82 **Congratulations! ** Your new resource is now usable for tribute, loot or barter.
    83 
    84 **However! ** Starting a new game within 0AD will present
     51}}}
     52It contains the following elements:
     53* **`code`** - Internal identifying code for this resource. Cannot be the same as another resource
     54* **`name`** - Player-friendly name of the resource. This will be localized into the player's chosen language (if localizing data exists for it)
     55* **`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).
     57* **`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.
     58* **`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:
     59* **`ignore`** - The AI will ignore this resource when it comes to planning where to build gather sites. This could be for several reasons, for instance that supplies of this resource move around (e.g. animals) or can be built by the player (e.g. farms)
     60  * **`abundant`** - This resource is abundant (very common) on the average map, but each deposit only contains a small amount of the given resource. (e.g. `wood`)
     61  * **`scarce`** - The resource has few deposits on the average map, but each deposit contains a fair to large quantity of the given resource. (e.g. `stone` or `metal`)
     62**NB** It is imperative that a `{resource.json}` file contains all these entries. So even if you do not want to use any subtype resources, you can not simply remove the `"subtypes"` element; a resource has to contain at least one subtype (the name does not really matter).
     63
     64Examples of things you can easily change here:
     65* add a “cheese” subtype in `food.json`
     66* display “stone” consistently before “wood” everywhere in the game by swapping the `order` values in `stone.json` and `wood.json`
     67* rename all entries of “Metal” in the game into “Iron” (0 A.D. is situated in the Iron Age) by changing the `"name":` element into `"Iron",` in `metal.json`
     68* making a resource twice as expensive or half as valuable by changing the ``truePrice:`` element into `200,` respectively `50,`
     69
     70
     71
     72== To remove a resource == #removeResource
     73Substraction 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:
     74* remove all entries (e.g. Cost, Loot, ResourceGatherer, etc.) in all `simulation/data/` and `simulation/templates/` (e.g. using `grep food *` is very helpful)
     75* edit the `simulation/ai` files to prevent the AI from looking for the resource
     76* remove the resource (objects) from the `maps/` files
     77* edit the `gui/session/` files
     78* edit `gui/common/setup_resources.xml`
     79* finally, remove the file in `simulation/data/resources/` by adding “.DELETED” behind the file name (e.g. create an empty file called `food.json.DELETED`)
     80
     81
     82== How to add a new resource == #addResource
     83Adding resources is not particularly difficult, provided you do not overlook any files (and there are quite a few you have to edit). Suppose you would want to add a new resource, e.g. “water”, then here is what you have to do.
     84
     85=== Create the resource ===
     86
     871. Create two icons:
     88  * `art/textures/ui/session/icons/resources/water.json` (64×64 pixels)
     89  * `art/textures/ui/session/icons/resources/water_small.json` (16×16 pixels)
     90
     912. Create a new resource file: `simulation/data/resources/water.json`, e.g.:
    8592{{{
    8693#!js
    87 WARNING: Current GUI limits prevent displaying more than 4 resources in the top panel!
    88 }}}
    89 
    90 
    91 === Displaying more resources within the session UI === #displayMoreIcons
    92 
    93 Due to 0AD's requirement to support a minimum screen resolution of 1024x768px, there isn't really enough space in the top panel for more than four resources plus the population count. If you don't care about this, the easiest solution is to modify `gui/session/top_panel/resources.xml` line four to a number larger than 4, ie. `<repeat count="5">`. (A harder solution is to redesign the session UI. Good luck with that.)
    94 
    95 Whilst the ''Trade'' and ''Diplomacy'' dialogs have a higher limit of displayable resources (at the time of writing: 8), once you build a market, you will find that selecting it will only display the first four resources. The easiest solution to this is to use a patch that moves the Barter options from the Barter panel into the Trade Dialog. You can find that patch in ticket #4366.
     94{
     95  "code": "water",
     96  "name": "Water",
     97  "order": 1.1,
     98  "subtypes": {
     99    "well": "Well Water"
     100  },
     101  "truePrice": 50,
     102  "aiAnalysisInfluenceGroup": "ignore",
     103}
     104}}}
     105
     1063.  Amend `gui/common/setup_resources.xml` so that you can use the icon in game UI texts (e.g. tech tree, tooltips); insert e.g.:
     107{{{
     108#!xml
     109  <icon name="icon_water"
     110    sprite="stretched:session/icons/resources/water_small.png"
     111    size="16 16"
     112  />
     113}}}
     114
     1154. Modify the following files to a display a number of resources larger than four:
     116  * `gui/session/selection_panels.js`: search for `g_SelectionPanels.Barter` (currently line 96) and change the `"getMaxNumberOfItems"` and `"rowLength"` elements, e.g.:
     117{{{
     118#!js
     119  {
     120    return 4;
     121  },
     122  "rowLength": 4,
     123}}}
     124  * `gui/session/selection_panels_left/barter_panel.xml` (currently line 6): e.g. `<repeat count="5">` (this value must match the return value of the JS file)
     125  * `gui/session/top_panel/resources.xml` (currently line 4): e.g. `<repeat count="5">`
     126(Note that due to 0 A.D.'s requirement to support a minimum screen resolution of 1024x768px, there isn't really enough space in the top panel for more than four resources plus the population count, nor is their in the market barter panel. If you do not care about this, the easiest solution, perfectly fine. If you do care, then the harder solution is to redesign the session UI. Good luck with that.)
     127
     1285. Insert `Player/BarterMultiplier/` `Buy/` and `Sell/` elements, e.g. `<water>1.0</water>`, into:
     129  * `simulation/templates/special/player.xml`
     130  * `simulation/templates/special/player_gaia.xml`
     131
     1326. Insert a `Production/TechCostMultiplier/` element, e.g. `<water>1.0</water>`, into:
     133  * `simulation/templates/template_structure.xml` (you can also do it in any of its descendants instead, but better do it here, in case you forget later)
     134  * any trainer unit templates (use `grep TechCostMultiplier *` to find them), e.g. `simulation/templates/units/athen_ship_trireme.xml`
     135
     136
     137Congratulations! You can now have, display, trade, barter, and spend “water”!
    96138
    97139