Page 1 of 1

Move tech/building values to a single macro file

Posted: Tue Aug 14, 2018 6:53 am
by Oberlus
The effects of buildings and non-theoretical techs are scripted in their respective building or tech FOCS file, with some values (user-defined constants) included from extern files and some others only defined in the own file. E.g., the boost from Algorithmic Elegance is calculated as Target.Population * 0.5 * [[RESEARCH_PER_POP]], where 0.5 is defined only in that file and RESEARCH_PER_POP is included from /scripting/common/base_prod.macros.

I've been fiddling with research/production techs/buildings to mitigate the snowball effect. The changes in a (say) tech file will not be reflected on the pedia (documentation) unless you also edit the corresponding descriptions on all the stringtable files (one for each language), and to be sure to cover everything related to a given meter you have to review many files in different folders.

I'm suggesting here to move all those 0.5, 1, 2.5, etc. constant values used in the tech/building files to a macro file in the common folder to be referenced from stringtables (can this be done?) and FOCS files.

Advantages:
- Group all values relevant to a given meter (e.g. research) in a single file, which eases any rebalancing and is less prone to buggy omissions.
- Immediate updating of documentation when some values are changed for rebalance.


If developers see this as an improvement, and since this only implies FOCS changes, I could try to make a PR for this (after proper discussion/guidance).

Re: Move tech/building values to a single macro file

Posted: Tue Aug 14, 2018 2:33 pm
by Geoff the Medio
Oberlus wrote: Tue Aug 14, 2018 6:53 amI'm suggesting here [that scripted constants] be referenced from stringtables (can this be done?)
I don't think so. You can look up stringtable entries in a FOCS script, and there are tag substitutions in some strings that can make links to objects or content or substitute the name of an in-game object (eg. [[metertype METER_STEALTH]]), and there are the numbered substitutions which match up with substitutions in the C++ code (like %18%), and strings can include macros to other stingtable keys. But there is no way to access a scripting macro from within a stringtable entry directly. It probably wouldn't be difficult to add the ability to #include macros within the stringtable (treating the macros as stringtable entries), which might be enough to do what you want, but the feature doesn't currently exist. It might get tricky to do this though, as you'd need to be sure that there are no duplicate macros included from different macro files, and that none of the string keys conflict with macro keys.

Re: Move tech/building values to a single macro file

Posted: Thu Aug 16, 2018 7:37 pm
by Ophiuchus
From a maintainability standpoint: it would be good to have base values used in FOCS defined in single place for all three of the following uses, so they are always in sync: AI, encyclopedia, and of course FOCS

Re: Move tech/building values to a single macro file

Posted: Wed Nov 14, 2018 5:08 pm
by em3
Geoff the Medio wrote: Tue Aug 14, 2018 2:33 pm It might get tricky to do this though, as you'd need to be sure that there are no duplicate macros included from different macro files, and that none of the string keys conflict with macro keys.
The keys imported from scripts could have a commonc prefix (like FOCS_ or SCRIPT_) or even be prefixed with the script name that contains them.

Re: Move tech/building values to a single macro file

Posted: Thu Nov 15, 2018 9:34 am
by Dilvish
Geoff the Medio wrote: Tue Aug 14, 2018 2:33 pmIt probably wouldn't be difficult to add the ability to #include macros within the stringtable (treating the macros as stringtable entries)
I believe that's already possible, and is essentially the same thing I did when I added content_specific_parameters.txt and common_user_customizations.txt (at least it is my vague recollection I added those lol).

Re: Move tech/building values to a single macro file

Posted: Thu Nov 15, 2018 10:15 am
by Geoff the Medio
Dilvish wrote: Thu Nov 15, 2018 9:34 am
Geoff the Medio wrote: Tue Aug 14, 2018 2:33 pmIt probably wouldn't be difficult to add the ability to #include macros within the stringtable (treating the macros as stringtable entries)
I believe that's already possible...
Appears so: https://github.com/freeorion/freeorion/ ... txt#L18769