Jump to content

Adding new resources


wowgetoffyourcellphone
 Share

Recommended Posts

The resource agnostic branch was merged in r18964.

You might have noticed the new simulation data directory simulation/data/resources/ path and the setup_resources.xml file for the icon.

In order to add a new resource, simply add a new JSON file to the path and an icon entry in the XML file.

To remove an existing resource, do the same in reverse and remove all links to that resource from the templates.

The situation with treasures isn't entirely satisfactory right now since there is still some hardcoding, it seems treasure can't become a regular resource subtype and sometimes even need a different logic (refs #4355).

  • Like 1
Link to comment
Share on other sites

  • Icon file & GUI Limitations

Unfortunately we don't have a way to load external constants in XML files. This also means that we have a number of places where the maxPlayer=8 constant is hardcoded, or the number of resources that can be displayed in the GUI of vanilla 0ad.

The top panel is too crowded for more than 5 resources and can't show resource quantities above 6 figures then. The barter dialog also would get a linebreak when using more than 6ish resources. The author of the code ( s0600204), has an example here https://github.com/s0600204/0ad/tree/resource_agnostic-example and there was some code in that or the resource_agnostic branch to rework the trade/barter dialog to improve the limitations a bit (which we decided to merge at that time, so we need a ticket actually as the other is closed.)

  • AI Influence group - It is a constant used by the terrain-analysis part of the Petra AI. As far as I understand the matter, the AI ignores the food on the map (0), considers wood (1) and really focuses on mines (2). This number is passed around in the code as the strength of the influence, so greater numbers should reflect greater importance. Not sure what happens if one specifies the a number great than 2. You would have to ask our Petra healer mimo for more details.
Link to comment
Share on other sites

So ehhhh it's not quite agnostic yet, or more to the point there are bugs, but additional resources technically work. 

I've gotten one to work. Though, I get this warning:

WARNING: JavaScript warning: globalscripts/Templates.js line 375 reference to undefined property template.cost[type]

 

Does this mean there must be a subtype listed in the json or that there the line must be ommitted if I do not want any subtypes.

Link to comment
Share on other sites

The subtypes are used for distinguishing gatherrates (they vastly differ for food). The ResourceGatherer component code could be reworked to support having no subtypes at all I guess but for now I assume defining one as a default being mandatory.

If you see errors like this, add a warn(uneval(type)) and similar things, potentailly warn(new Error().stack) to the code to see some context, for example which template causes the error.

Link to comment
Share on other sites

The current barter panel has space for at most 4 resources. The 2 most recent commits in https://github.com/s0600204/0ad/commits/barterIconShift move the bartering UI from the bottom panel to the trade dialog, alleviating this issue:

new_barter.jpg

If we go with this, everyone who has played 0 A.D. before will be confused and report this as a bug.

On first sight it might seem like a usability penalty, but on second sight it doesn't. Currently, in order to barter one has to either recall where the market was built or recall how a market model looks and select it before being able to access the barter UI. With the patch, one can skip the first part, so it might be faster. On the other hand if one knows where a market was built (good practice: market at well known locations like besides CC), opening the trade dialog requires more mouse movement (distance in pixels). A hotkey to open the trade dialog would solve that issue again.

Link to comment
Share on other sites

I can see how that is faster for player. My concern/critic of it though would be that now vital economic things are being remove from the Market, reducing the usefulness of the building. At the least, the trade and barter dialog should not be accessible unless the a market is build. Show the button gray out and tool tip that say:

Barter & Trade Goods
Requires: 1 Market

 

Also, the resource I am add is Glory. It come from killing units and buildings and build (maybe) patron god statues (trickle). If we ever get relics, I make the relic trickle Glory too. This is not a resource I want to have barter and trade. Should have a way to deterine what resource shows in trade and barter and what does not, maybe a line or two in the json.

Edited by wowgetoffyourcellphone
Link to comment
Share on other sites

On 25/11/2016 at 1:20 AM, elexis said:
  • AI Influence group - It is a constant used by the terrain-analysis part of the Petra AI. As far as I understand the matter, the AI ignores the food on the map (0), considers wood (1) and really focuses on mines (2). This number is passed around in the code as the strength of the influence, so greater numbers should reflect greater importance. Not sure what happens if one specifies the a number great than 2. You would have to ask our Petra healer mimo for more details.

 

It is not really linked to the importance, but to the way the resource is spread on the map, which determines how the AI build its own resourceMaps, which are themselves used for cc and dropsite positioning. So 0 means that we don't make resourceMap with this resource (which is then not used for positioning), 1 is used for resources which are abondant but usually with a small amount each (like wood) and 2 is for resources which are sparse but wich large amount each (as stone and metal).

Concerning what happens if a modder would put another value: before r18964, the resource would have been ignored (equivalent to 0), but since this commit i guess a flood of warnings will be printed as some early-continue "if (influence != 1 && influence != 2)" in terrain-analysis.js have been replaced by "if (!influence)". I think this should be fixed.

There is a lot of information in this thread which can be useful for modders. It would be nice to summarize it in the wiki, if somebody has time to do it.

 

  • Like 1
Link to comment
Share on other sites

4 hours ago, wowgetoffyourcellphone said:

Also, the resource I am add is Glory. It come from killing units and buildings and build (maybe) patron god statues (trickle). If we ever get relics, I make the relic trickle Glory too. This is not a resource I want to have barter and trade. Should have a way to deterine what resource shows in trade and barter and what does not, maybe a line or two in the json.

i agree, and this will also require some (small) changes in the AI when some resources cannot be used for trade or barter. And what will glory used for in your mod? (just to know if that would require other changes)

Link to comment
Share on other sites

> At the least, the trade and barter dialog should not be accessible unless the a market is build.

That is the case. The question remains whether the proposal is the best solution to increase the nr of resources that can be bartered from 4, whether we don't support more resources there or whether someone comes up with a better idea. I've created #4366 so that we accept or reject, not forget the patch.

> before r18964, the resource would have been ignored (equivalent to 0), but since this commit i guess a flood of warnings will be printed as some early-continue "if (influence != 1 && influence != 2)" in terrain-analysis.js have been replaced by "if (!influence)".

So for influence=3 it should be treated like influence=0, not creating a terrain analysis for resources which are even more sparse but with larger amount than stone and metal? Using a value different from 0, 1, 2 indeed bugs due to the init in shared.js this.normalizationFactor = { "1": 50, "2": 90 }; and following 2 lines.

If we support only 3 values there, then those should become strings ["none", "abundant", "sparse"], otherwise change the init to work with the provided values IMO.

Link to comment
Share on other sites

1 hour ago, elexis said:

> before r18964, the resource would have been ignored (equivalent to 0), but since this commit i guess a flood of warnings will be printed as some early-continue "if (influence != 1 && influence != 2)" in terrain-analysis.js have been replaced by "if (!influence)".

So for influence=3 it should be treated like influence=0, not creating a terrain analysis for resources which are even more sparse but with larger amount than stone and metal? Using a value different from 0, 1, 2 indeed bugs due to the init in shared.js this.normalizationFactor = { "1": 50, "2": 90 }; and following 2 lines.

If we support only 3 values there, then those should become strings ["none", "abundant", "sparse"], otherwise change the init to work with the provided values IMO.

 

The problem is that you can't make it work with values nobody said what they mean, nor anybody wrote the AI code to deal with them: why would you believe that an additional value  would mean even sparser? it certainly depends on the kind of resource added, how useful it is to take it into account for dropsite position and any other need of the modder. So the only solution now is to not treat these additional values (as was done before, possibly adding a warning only printed once and not one by entity).

Replacing the integer values by string is certainly a good idea.

  • Like 1
Link to comment
Share on other sites

13 hours ago, mimo said:

And what will glory used for in your mod? (just to know if that would require other changes)

to train hero, to research some strong techs (like unit promotions, special techs, etc.), to upgrade units (for ex: can upgrade 2 of your Spartiates to Spartan Olympic Champions using Glory), build buildings like Wonder (in DE Wonder is required to go to Phase IV).

Link to comment
Share on other sites

On 26/11/2016 at 9:22 AM, mimo said:

There is a lot of information in this thread which can be useful for modders. It would be nice to summarize it in the wiki, if somebody has time to do it.

Unless things have changed recently, the creation of wiki pages on trac is still restricted to trac admins. If one of them would like to create a page (perhaps linking to it somewhere on the "Modding Guide" page) the "scripting notes" in the readme of the original resource_agnostic mod (https://github.com/0ADMods/resource_agnostic#scripting-notes) could be used as a starting point, albeit with a few alterations (the "To Remove a Resource" instructions are wrong). I'm busy with work for the next week or so, but if no-one else has done it by then I'll look into amending the instructions to match the current implementation. But I'll need the page created first...

Edit: feneur has very generously granted me the permissions on trac to create wiki pages. So unless someone beats me to it, I'll get a wiki page written and up within the next week or two.

Edited by s0600204
Improvement of circumstances
  • Like 4
Link to comment
Share on other sites

On 30/11/2016 at 11:31 AM, s0600204 said:

So unless someone beats me to it, I'll get a wiki page written and up within the next week or two.

First draft: http://trac.wildfiregames.com/wiki/ModdingResources

 

On 25/11/2016 at 0:39 AM, wowgetoffyourcellphone said:

I get this warning:

WARNING: JavaScript warning: globalscripts/Templates.js line 375 reference to undefined property template.cost[type]

Try

Spoiler

diff --git a/binaries/data/mods/public/globalscripts/Templates.js b/binaries/data/mods/public/globalscripts/Templates.js
index 366c58e..75870bc 100644
--- a/binaries/data/mods/public/globalscripts/Templates.js
+++ b/binaries/data/mods/public/globalscripts/Templates.js
@@ -372,7 +372,7 @@ function GetTechnologyDataHelper(template, civ, resources)
 
        ret.cost = { "time": template.researchTime ? +template.researchTime : 0 }
        for (let type of resources.GetCodes())
-               ret.cost[type] = template.cost ? +template.cost[type] : 0;
+               ret.cost[type] = template.cost && template.cost[type] ? +template.cost[type] : 0;
 
        ret.tooltip = template.tooltip;
        ret.requirementsTooltip = template.requirementsTooltip || "";

 

 

  • Like 3
Link to comment
Share on other sites

On 12/5/2016 at 3:49 PM, s0600204 said:

 

On 11/24/2016 at 7:39 PM, wowgetoffyourcellphone said:

I get this warning:

WARNING: JavaScript warning: globalscripts/Templates.js line 375 reference to undefined property template.cost[type]

Try

  Hide contents


diff --git a/binaries/data/mods/public/globalscripts/Templates.js b/binaries/data/mods/public/globalscripts/Templates.js
index 366c58e..75870bc 100644
--- a/binaries/data/mods/public/globalscripts/Templates.js
+++ b/binaries/data/mods/public/globalscripts/Templates.js
@@ -372,7 +372,7 @@ function GetTechnologyDataHelper(template, civ, resources)
 
        ret.cost = { "time": template.researchTime ? +template.researchTime : 0 }
        for (let type of resources.GetCodes())
-               ret.cost[type] = template.cost ? +template.cost[type] : 0;
+               ret.cost[type] = template.cost && template.cost[type] ? +template.cost[type] : 0;
 
        ret.tooltip = template.tooltip;
        ret.requirementsTooltip = template.requirementsTooltip || "";

 

 

s06, this seems to work! WOOO

 

Also, your instructions here allow me to add the 5th resource to top panel!

http://trac.wildfiregames.com/wiki/ModdingResources#displayMoreIcons

 

screenshot0859.jpg

 

Side note: I wish screenshots would capture the cursor too.

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

#4379 is nice to setup resources on a game by game basis when needed, but there should be also some global way to setup different starting resources for different resources.

A simple way would be to add in the json of each resource a new property startingRatio which would allow to scale the starting resources (when not explicitely specified by the player when #4379 is implemented). For example a resource with startingRatio= 0.5 would start with 150 instead of 300 when the "low" starting resource is used.

  • Like 2
Link to comment
Share on other sites

7 hours ago, mimo said:

#4379 is nice to setup resources on a game by game basis when needed, but there should be also some global way to setup different starting resources for different resources.

A simple way would be to add in the json of each resource a new property startingRatio which would allow to scale the starting resources (when not explicitely specified by the player when #4379 is implemented). For example a resource with startingRatio= 0.5 would start with 150 instead of 300 when the "low" starting resource is used.

elexis's ticket would be nice, but mimo's comment is what i specificly talk about. like, the I would like to mod the default resource amounts to be something like:

500 food, 500 wood, 500 stone, 300 metal, 0 glory.

 

A ratio can work, but might give weird starting amounts, like 176 or something. And while I might want 0 glory for start at a low level, I might want the player to start with 500 or more at the extreme high end. 

 

Maybe somkething code like these for default file:

 

{
	"TranslatedKeys": ["Title"],
	"TranslationContext": "startingResources",
	"Data":
	[
		{
			"Resources": {
				"food": 0,
				"wood": 0,
				"stone": 0,
				"metal": 0,
				"glory": 0
			},
			"Title": "None"
		},
		{
			"Resources": {
				"food": 100,
				"wood": 100,
				"stone": 100,
				"metal": 100,
				"glory": 0
			},
			"Title": "Very Low"
		},
		{
			"Resources": {
				"food": 300,
				"wood": 300,
				"stone": 300,
				"metal": 200,
				"glory": 0
			},
			"Title": "Low"
		},
		{
			"Resources": {
				"food": 500,
				"wood": 500,
				"stone": 500,
				"metal": 300,
				"glory": 0
			},
			"Title": "Medium",
			"Default": true
		},
		{
			"Resources": {
				"food": 1000,
				"wood": 1000,
				"stone": 1000,
				"metal": 600,
				"glory": 100
			},
			"Title": "High"
		},
		{
			"Resources": {
				"food": 10000,
				"wood": 10000,
				"stone": 10000,
				"metal": 6000,
				"glory": 1000
			},
			"Title": "Very High"
		},
		{
			"Resources": {
				"food": 25000,
				"wood": 25000,
				"stone": 25000,
				"metal": 10000,
				"glory": 2000
			},
			"Title": "Extremely High"
		}
	]
}

 

Notice rename "Deathmatch" to "Extremely High" because Deathmatch is a mode not resource amount.

Edited by wowgetoffyourcellphone
suggest code change for json
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.

Guest
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.

 Share

×
×
  • Create New...