Macros!

For topics that do not fit in another sub-forum.

Moderator: Oberlus

Message
Author
User avatar
eleazar
Design & Graphics Lead Emeritus
Posts: 3858
Joined: Sat Sep 23, 2006 7:09 pm
Location: USA — midwest

Re: Macros!

#16 Post by eleazar »

Geoff the Medio wrote:You need to have a newline at the end of the file.
Opps. You're right.


OK, how can i write and effect to make a certain species' ships 25% more destructive in battle, or is that possible?

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Macros!

#17 Post by Geoff the Medio »

eleazar wrote:OK, how can i write and effect to make a certain species' ships 25% more destructive in battle, or is that possible?
I don't think that's possible at the moment, for several reasons:

At present, I think I recently posted about how ship part stats are mostly gotten directly from the numbers written into the part definitions, and not through effects. A ship doesn't actually have a single damage meter, but rather has a stat for each weapon part that gets added up to determine its damage as reported and used in game. Consequently, there's no effect usable to modify that stat. This is different from ship meters (not part meters) like stealth or structure, which (I think) are modifiable with effects.

More generally, even if effects could usefully modify ship part meters, there's an issue with order of effects being applied... When deciding what effects get applied to what objects, currently the order is: species, specials, techs, buildings, ships (hull of a ship, then parts of the ship). That means all effects related to species in the universe get applied, then all effects related to specials, then techs, etc. For ships, it's the hull of ship 1, then the parts of ship 1, then the hull of ship 2, parts of ship 2, etc.

The consequence of this is that if effects were determining the actual stats of ship parts, there would still be no way to have a species give a 25% boost to those stats because the ship part effects come after the species effects, and thus at the time the species effect could be applied, all ship part meters would be 0.

The whole effects system of FreeOrion has a limitation or incompatibility with modifications of this type (+25%). This is notable because lots of people seem to want to default to using percentage based modifications, when really the FreeOrion effects work better for fixed modifications like +5, or modifications that vary based on things other than the meter being modified and that are persistent between turns. So, +2*population is OK, but +2*target_population is not, as the population is roughly persistent between turns, but target population is recalculated from 0 each turn by adding up all relevant effects. Similarly, +0.25*current_meter_value works differently depending on what other effects have already acted on a particular meter that turn.

That said, if / once part meter effects have been implemented, you could do something in the part itself to give certain species a bonus. For example, the part could have a base damage of 8, and then there could be an effectsgroup for the part to give +2 to the damage if the species of the ship is one of those in a list.

User avatar
eleazar
Design & Graphics Lead Emeritus
Posts: 3858
Joined: Sat Sep 23, 2006 7:09 pm
Location: USA — midwest

Re: Macros!

#18 Post by eleazar »

OK, well that was just the first thing i thought of. I'd be happy with some sort of bonus that makes the species effectively more warlike -- even if it doesn't entirely make sense.

For instance, I've implemented sneaky, spy oriented bonus by giving the species extra detection, and sometimes stealth for their planets. Even though there is no espionage, this starts to give the species the right feel.

The macros are working nicely so far. Here's what a typical species definition is now:

Code: Select all

Species
    name = "SP_LAENFA"
    description = "SP_LAENFA_DESC"
    Playable
    CanProduceShips
    CanColonize
    
    foci = [
        [[HAS_FARMING_FOCUS]]
        [[HAS_MINING_FOCUS]]
        [[HAS_INDUSTRY_FOCUS]]
        [[HAS_RESEARCH_FOCUS]]
        [[HAS_ADVANCED_FOCI]]
    ]
    
    effectsgroups = [
        [[GREAT_DETECTION]]
        [[ULTIMATE_STEALTH]]
        
        [[TERRIBLE_FARMING]]
        [[TERRIBLE_MINING]]
        [[TERRIBLE_INDUSTRY]]
        [[TERRIBLE_RESEARCH]]
        
        [[ADVANCED_FOCUS_EFFECTS]]
        
        [[TERRIBLE_GROUND_TROOPS]]
        
        [[NO_FOOD_USE]]
        [[STANDARD_HEALTH_AND_POPULATION]]
    ]
    
    [[OCEAN_STANDARD_EP]]
    
    graphic = "icons/species/laenfa.png"


User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Macros!

#19 Post by Geoff the Medio »

Certainly an improvement.

In case it wasn't clear, you can use macros inside other macro definitions. Just avoid cyclic macro references.

User avatar
eleazar
Design & Graphics Lead Emeritus
Posts: 3858
Joined: Sat Sep 23, 2006 7:09 pm
Location: USA — midwest

Re: Macros!

#20 Post by eleazar »

Geoff the Medio wrote:
eleazar wrote:OK, how can i write and effect to make a certain species' ships 25% more destructive in battle, or is that possible?
I don't think that's possible at the moment, for several reasons:

...

More generally, even if effects could usefully modify ship part meters, there's an issue with order of effects being applied... When deciding what effects get applied to what objects, currently the order is: species, specials, techs, buildings, ships (hull of a ship, then parts of the ship). That means all effects related to species in the universe get applied, then all effects related to specials, then techs, etc. For ships, it's the hull of ship 1, then the parts of ship 1, then the hull of ship 2, parts of ship 2, etc.

The consequence of this is that if effects were determining the actual stats of ship parts, there would still be no way to have a species give a 25% boost to those stats because the ship part effects come after the species effects, and thus at the time the species effect could be applied, all ship part meters would be 0.
Is there a reason species effects can't be applied last instead?
Multiplication seems like the only way to give a species bonus to species that doesn't quickly become nearly irrelevant due to tech increases.

User avatar
eleazar
Design & Graphics Lead Emeritus
Posts: 3858
Joined: Sat Sep 23, 2006 7:09 pm
Location: USA — midwest

Re: Macros!

#21 Post by eleazar »

So having species with different abilities will drive everyone crazy if the differences aren't documented. So that's my next priority before any sort of balancing.

It occurs to me that i could make macros in eng-stringtable.txt that describe what exactly "ULTIMATE_FARMING" etc. is, and then include the appropriate macros in each species description. That would help, but it seems likely that the stringtable list of a species picks and the ones they are actually given in species.txt would end up out of sync. We'll need something to handle automated descriptions eventually when players design their own species.

Is there something clever with macros and/or code that can make the species description depend on what happens in species.txt with these various distinguishing effects and so-forth?

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Macros!

#22 Post by Geoff the Medio »

eleazar wrote:Is there a reason species effects can't be applied last instead?
Effects from various types of sources can be done in any order. I put species first just because it seemed like the "baseline" effects would arise from them, which would be modified by subsequent things like techs or buildings.
Multiplication seems like the only way to give a species bonus to species that doesn't quickly become nearly irrelevant due to tech increases.
You can have each tech or building modification have two or more cases, with one case for typical species, and another case for species that are better at whatever the effect is about. This will make the effects breakdown a bit more understandable, rather than +X, +Y, and +Z from various buildings or techs, and then +(X+Y+Z) attributed to the species due to a multiplier.
Is there something clever with macros and/or code that can make the species description depend on what happens in species.txt with these various distinguishing effects and so-forth?
It might be possible to put species (or whatever content type) property references into stringtable entries in some manner, but I'm not sure how this would be useful.

There could be a list of stringtable entires, instead of a single entry, for the description of most types of content. The scripter would indicate a series of strings, and these would be all looked up and stuck together to produce the final in-game description string. That could be done fairly easily in the stringtable itself, though, by making the entry for a species be a series of references to other strings. I'd rather not have to add a bunch of code to duplicate that functionality.

User avatar
Bigjoe5
Designer and Programmer
Posts: 2058
Joined: Tue Aug 14, 2007 6:33 pm
Location: Orion

Re: Macros!

#23 Post by Bigjoe5 »

Geoff the Medio wrote:
Multiplication seems like the only way to give a species bonus to species that doesn't quickly become nearly irrelevant due to tech increases.
You can have each tech or building modification have two or more cases, with one case for typical species, and another case for species that are better at whatever the effect is about. This will make the effects breakdown a bit more understandable, rather than +X, +Y, and +Z from various buildings or techs, and then +(X+Y+Z) attributed to the species due to a multiplier.
That's not really possible right now without listing all the species in each effects group (is it?). Could there perhaps be a way to attach arbitrary flags to species such as "HasAwesomeFarming" such that the condition for a building or tech effect could be something like "Species HasAwesomeFarming"?
Warning: Antarans in dimensional portal are closer than they appear.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Macros!

#24 Post by Geoff the Medio »

Bigjoe5 wrote:That's not really possible right now without listing all the species in each effects group (is it?).
You'd presently need to list every affected species, though I think the species-matching condition can take a list of species to check for, so it's not a separate condition for each species.
Could there perhaps be a way to attach arbitrary flags to species such as "HasAwesomeFarming" such that the condition for a building or tech effect could be something like "Species HasAwesomeFarming"?
"Tags" have been proposed to serve a purpose similar to what you describe. There'd presumably be a HasTag name ="WHATEVER_TAG" type condition added.

User avatar
Bigjoe5
Designer and Programmer
Posts: 2058
Joined: Tue Aug 14, 2007 6:33 pm
Location: Orion

Re: Features for post v0.4

#25 Post by Bigjoe5 »

Geoff the Medio wrote:Once you get a build of FO that allows recursive macros and start using them, see if you find yourself wanting to use parameters. I suspect they'll be felt necessary quite quickly...
Your prophesy has been fulfilled. I just glanced over shiphulls.txt with the intention of macro-ifying space monster movement, and found that most of the movement effectsgroups are identical except for the probability of moving.
Warning: Antarans in dimensional portal are closer than they appear.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Features for post v0.4

#26 Post by Geoff the Medio »

Bigjoe5 wrote:
Geoff the Medio wrote:Once you get a build of FO that allows recursive macros and start using them, see if you find yourself wanting to use parameters. I suspect they'll be felt necessary quite quickly...
Your prophesy has been fulfilled.
Geoff the Medio wrote:There's a potential workaround without parameters, which would be to have two macros, one of which has all the text up to the place where the 2 appears, and another that has all the text after that, and then you'd use [[MACRO_BEFORE_NUMBER]]2[[MACRO_AFTER_NUMBER]] to effectively create your own parametrized macros without built-in support for it, but that would be awkward in anything but simple cases.
Your situation appears to be a simple case.

User avatar
eleazar
Design & Graphics Lead Emeritus
Posts: 3858
Joined: Sat Sep 23, 2006 7:09 pm
Location: USA — midwest

Re: Macros!

#27 Post by eleazar »

Geoff the Medio wrote:The whole effects system of FreeOrion has a limitation or incompatibility with modifications of this type (+25%). This is notable because lots of people seem to want to default to using percentage based modifications, when really the FreeOrion effects work better for fixed modifications like +5, or modifications that vary based on things other than the meter being modified and that are persistent between turns. So, +2*population is OK, but +2*target_population is not, as the population is roughly persistent between turns, but target population is recalculated from 0 each turn by adding up all relevant effects. Similarly, +0.25*current_meter_value works differently depending on what other effects have already acted on a particular meter that turn.

That said, if / once part meter effects have been implemented, you could do something in the part itself to give certain species a bonus. For example, the part could have a base damage of 8, and then there could be an effectsgroup for the part to give +2 to the damage if the species of the ship is one of those in a list.
The classic Alkiri bonus (and it's opposite) seems to be the most important species differentiation we currently can't do. If/once you add the effects, i'll add in species that are better/worse at combat.

Post Reply