wowgetoffyourcellphone Posted November 24, 2016 Report Share Posted November 24, 2016 Recently a commit make resources agnostic so that modding can add more resources. Can someone on the team show how to do this? 1 Quote Link to comment Share on other sites More sharing options...
elexis Posted November 24, 2016 Report Share Posted November 24, 2016 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). 1 Quote Link to comment Share on other sites More sharing options...
wowgetoffyourcellphone Posted November 25, 2016 Author Report Share Posted November 25, 2016 (edited) 5 minutes ago, elexis said: the setup_resources.xml file for the icon. This was the step I miss. Thank you. There is also the problem that the GUI will not display a 5th resource, but that is beyond me. Edited November 25, 2016 by wowgetoffyourcellphone Quote Link to comment Share on other sites More sharing options...
wowgetoffyourcellphone Posted November 25, 2016 Author Report Share Posted November 25, 2016 ELI5 "aiAnalysisInfluenceGroup" in the resource json? Thank. Quote Link to comment Share on other sites More sharing options...
elexis Posted November 25, 2016 Report Share Posted November 25, 2016 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. Quote Link to comment Share on other sites More sharing options...
wowgetoffyourcellphone Posted November 25, 2016 Author Report Share Posted November 25, 2016 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. Quote Link to comment Share on other sites More sharing options...
elexis Posted November 25, 2016 Report Share Posted November 25, 2016 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. Quote Link to comment Share on other sites More sharing options...
elexis Posted November 26, 2016 Report Share Posted November 26, 2016 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: 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. Quote Link to comment Share on other sites More sharing options...
wowgetoffyourcellphone Posted November 26, 2016 Author Report Share Posted November 26, 2016 (edited) 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 GoodsRequires: 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 November 26, 2016 by wowgetoffyourcellphone Quote Link to comment Share on other sites More sharing options...
mimo Posted November 26, 2016 Report Share Posted November 26, 2016 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. 1 Quote Link to comment Share on other sites More sharing options...
mimo Posted November 26, 2016 Report Share Posted November 26, 2016 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) Quote Link to comment Share on other sites More sharing options...
elexis Posted November 26, 2016 Report Share Posted November 26, 2016 > 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. Quote Link to comment Share on other sites More sharing options...
mimo Posted November 26, 2016 Report Share Posted November 26, 2016 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. 1 Quote Link to comment Share on other sites More sharing options...
wowgetoffyourcellphone Posted November 26, 2016 Author Report Share Posted November 26, 2016 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). Quote Link to comment Share on other sites More sharing options...
elexis Posted November 27, 2016 Report Share Posted November 27, 2016 Seems weird to use something abstract as a resource (how is that resource gathered?), but I like that phase 4 idea. (The wonder was not as valuable as it should be before the population bonus became stackable). Quote Link to comment Share on other sites More sharing options...
wowgetoffyourcellphone Posted November 27, 2016 Author Report Share Posted November 27, 2016 44 minutes ago, elexis said: Seems weird to use something abstract as a resource (how is that resource gathered?) I said how. lol Kill units, build statues, capture relics. But influence is definitely a resource. 1 Quote Link to comment Share on other sites More sharing options...
elexis Posted November 28, 2016 Report Share Posted November 28, 2016 Description added to wiki:Mod_Layout, patch for using strings instead of integers for the AI influence group here. 1 Quote Link to comment Share on other sites More sharing options...
Lion.Kanzen Posted November 28, 2016 Report Share Posted November 28, 2016 You can create more discrete resource I mean no big decisive. I love your work. You can considerate some counter system like @Eraser doing for meta data mod? Quote Link to comment Share on other sites More sharing options...
s0600204 Posted November 30, 2016 Report Share Posted November 30, 2016 (edited) 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 November 30, 2016 by s0600204 Improvement of circumstances 4 Quote Link to comment Share on other sites More sharing options...
s0600204 Posted December 5, 2016 Report Share Posted December 5, 2016 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 || ""; 3 Quote Link to comment Share on other sites More sharing options...
wowgetoffyourcellphone Posted December 7, 2016 Author Report Share Posted December 7, 2016 (edited) 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 Side note: I wish screenshots would capture the cursor too. Edited December 7, 2016 by wowgetoffyourcellphone 2 Quote Link to comment Share on other sites More sharing options...
wowgetoffyourcellphone Posted December 7, 2016 Author Report Share Posted December 7, 2016 Would it be possible to vary the amount of each starting resource? Right to now the number in starting_resource.json (300, 500, etc.) is apply to all resource. I would like my resource to always start much lower than the others (I would also like to make metal start lower too). Possible? 1 Quote Link to comment Share on other sites More sharing options...
elexis Posted December 7, 2016 Report Share Posted December 7, 2016 Possible yes, implemented no #4379 Arbitrary starting resources in the gamesetup (see also Player.js SetResourceCounts) 1 Quote Link to comment Share on other sites More sharing options...
mimo Posted December 7, 2016 Report Share Posted December 7, 2016 #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. 2 Quote Link to comment Share on other sites More sharing options...
wowgetoffyourcellphone Posted December 7, 2016 Author Report Share Posted December 7, 2016 (edited) 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 December 8, 2016 by wowgetoffyourcellphone suggest code change for json Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.