Excruciating FOCS doubts

Creation, discussion, and balancing of game content such as techs, buildings, ship parts.

Moderators: Oberlus, Committer

Message
Author
Ophiuchus
Programmer
Posts: 2177
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Excruciating FOCS doubts

#106 Post by Ophiuchus »

Geoff the Medio wrote: Wed Jul 14, 2021 3:39 pm
Ophiuchus wrote: Wed Jul 14, 2021 1:55 pmA kind of (probability based) switch statement would be more clear regarding the final probabilities.
There is already a chance condition, so you could probably already construct something like with If-Else and Chance.
You mean like it is currently implemented, specifying the dependent probabities right (because there is no "Chance").
Dependend picks have different probabilities p(A, 1/3), p(B, 1/3), p(C, 1/3), but if a is picked p(B|A, 1/2), p(C|A, 1/2).

But it is a bit hard to read the specified chances are 1/3, 1/2, 1/2 are meant in the end to result in 1/3 1/3 1/3 probabilites.
Geoff the Medio wrote: Wed Jul 14, 2021 3:39 pm -Are you assuming just a single target object? What happens if there are multiples? Does it apply the same effect to all, or independently decide for each?
My idea would be a (more complex) multiple weighted random sampling without replacement. So you want to pick N different objects and state the probabilities for each of the objects so p(A), p(B), p(C) or in order to circumvent leaving a gap because of user mistakes and how floats work not stating p(C).
Geoff the Medio wrote: Wed Jul 14, 2021 3:39 pm -If it picks an effect for an object, but that effect doesn't really apply to that object, so that nothing actually happens, it will end up doing not exactly one but rather none of these.
If I read you you mean it would be good to be able to skip a choice conditionially. It seems you suggest using (valueref) amounts instead of probabilites, which seems fine to me. It seems you have your own suggestion/use cases in your head - why dont you write it down?
Geoff the Medio wrote: Wed Jul 14, 2021 3:39 pm -How are those probabilities evaluated? Summed an normalized to 1, or successive independent checks? So 50% + 50% + default means 50% of the first and 25% of the latter two, or 50% of the first two and 0% of the default last?
Not successive checks.
The values are probabilities, the specified probabilities plus the unstated "default"/leftover probability should sum 1. Probably you would rather specify (50%, default) instead of (50%, 50%, default). It certainly would have utility to specify amounts instead of probabilities, which would need to be completely specified (so no default in that case). That version would also be fine to me.
Geoff the Medio wrote: Wed Jul 14, 2021 3:39 pm Also, for that specific example, you could probably just have a single effect for most of it, but with OneOf("SP_BANFORO", "SP_KILANDOW", "SP_MISIORLA") for the inner ValueRef that specifies what species to apply, as long as the effectsgroup just needs to pick what species to apply at a single location.
edit: yes, OneOf should suffice choosing one with equal probabilites and sounds like the right thing for cleaning up that content.
No, without remembering the result/specifying the seed (so you get the same "random" result) it is not possible to do the right thing. Functions/Named effects could also work. Metaprogramming with python would also be an option (which would create the if-else structure in FOCS). Currently you need the species name in multiple places.

So taking in geoffs suggestions with more features

Code: Select all

effects = PickEffects picks = 1 from = [
  WeightedEffects weight = [[ONE_IF_SPECIES_EXISTS_ELSE_ZERO("SP_BANFORO")]] effects = [ ... ] // revive Banforo
  WeightedEffects weight = [[ONE_IF_SPECIES_EXISTS_ELSE_ZERO("SP_KILANDOW")]] effects = [ ... ] // revive Kilandow
  WeightedEffects weight = [[ONE_IF_SPECIES_EXISTS_ELSE_ZERO("SP_MISIORLA")]] effects = [ ... ] // revive Misiorla
] instead = [ ...] // already got all those species - give something else
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
LienRag
Large Juggernaut
Posts: 926
Joined: Fri May 17, 2019 5:03 pm

Re: Excruciating FOCS doubts

#107 Post by LienRag »

I'm doing the annoyer once again :
LienRag wrote: Fri Apr 30, 2021 7:26 pm I noticed that there is a "tag = monster" but apparently monsters do not have it ?
Thanks for the previous answers, too.

User avatar
Oberlus
Cosmic Dragon
Posts: 3864
Joined: Mon Apr 10, 2017 4:25 pm

Re: Excruciating FOCS doubts

#108 Post by Oberlus »

Can I use macros within adoptioncost in policies definitions?

At the end of /scripting/policies/policies.macros I added this:

Code: Select all

SHIPS_OWNED_BY_EMPIRE
'''(Statistic Count condition = And [Ship OwnedBy empire = Source.Owner])'''
This (i.e. no using the macro, but keeping in declared in the macros file) works:

Code: Select all

Policy
    name = "PLC_EXPLORATION"
    description = "PLC_EXPLORATION_DESC"
    short_description = "PLC_EXPLORATION_SHORT_DESC"
    category = "MILITARY_CATEGORY"
    adoptioncost = 5 + Statistic Count condition = And [Ship OwnedBy empire = Source.Owner]
//[...]
#include "/scripting/policies/policies.macros"
#include "/scripting/common/priorities.macros"
This doesn't work:

Code: Select all

Policy
    name = "PLC_EXPLORATION"
    description = "PLC_EXPLORATION_DESC"
    short_description = "PLC_EXPLORATION_SHORT_DESC"
    category = "MILITARY_CATEGORY"
    adoptioncost = 5 + SHIPS_OWNED_BY_EMPIRE
//[...]
#include "/scripting/policies/policies.macros"
#include "/scripting/common/priorities.macros"
It gives error:

Code: Select all

scripting/policies/EXPLORATION.focs.txt:6:21: Parse error.  Expected (?-i:graphic) here:
Policy
    name = "PLC_EXPLORATION"
    description = "PLC_EXPLORATION_DESC"
    short_description = "PLC_EXPLORATION_SHORT_DESC"
    category = "MILITARY_CATEGORY"
    adoptioncost = 5 + SHIPS_OWNED_BY_EMPIRE
                     ^
If I remove the parenthesis around the macro in policies.macros, the error changes:

Code: Select all

scripting/policies/EXPLORATION.focs.txt:6:24: Parse error.  Expected real number expression here:
Policy
    name = "PLC_EXPLORATION"
    description = "PLC_EXPLORATION_DESC"
    short_description = "PLC_EXPLORATION_SHORT_DESC"
    category = "MILITARY_CATEGORY"
    adoptioncost = 5 + (SHIPS_OWNED_BY_EMPIRE)
                        ^
Adding or removing parenthesis around the macro in the policy file does not change anything (it doesn't work).

Sometimes FOCS obscure syntaxes makes me sad...

Ophiuchus
Programmer
Posts: 2177
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Excruciating FOCS doubts

#109 Post by Ophiuchus »

Double brackets should work. Macro expansion does not know about FOCS at all, it just substitutes text parts.

Check for typos and make sure the macro is visible
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
Oberlus
Cosmic Dragon
Posts: 3864
Joined: Mon Apr 10, 2017 4:25 pm

Re: Excruciating FOCS doubts

#110 Post by Oberlus »

Ophiuchus wrote: Mon Jul 19, 2021 9:27 am Double brackets should work
Doh!
Thanks.

Ophiuchus
Programmer
Posts: 2177
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Excruciating FOCS doubts

#111 Post by Ophiuchus »

LienRag wrote: Sat Jul 17, 2021 3:44 pm I'm doing the annoyer once again :
LienRag wrote: Fri Apr 30, 2021 7:26 pm I noticed that there is a "tag = monster" but apparently monsters do not have it ?
Thanks for the previous answers, too.
Where did you find that?
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

Ophiuchus
Programmer
Posts: 2177
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Excruciating FOCS doubts

#112 Post by Ophiuchus »

Ophiuchus wrote: Thu Jul 15, 2021 7:06 am
Geoff the Medio wrote: Wed Jul 14, 2021 3:39 pm
Ophiuchus wrote: Wed Jul 14, 2021 1:55 pmA kind of (probability based) switch statement would be more clear regarding the final probabilities.
There is already a chance condition, so you could probably already construct something like with If-Else and Chance.
Geoff the Medio wrote: Wed Jul 14, 2021 3:39 pm Also, for that specific example, you could probably just have a single effect for most of it, but with OneOf("SP_BANFORO", "SP_KILANDOW", "SP_MISIORLA") for the inner ValueRef that specifies what species to apply, as long as the effectsgroup just needs to pick what species to apply at a single location.
without remembering the result/specifying the seed (so you get the same "random" result) it is not possible to do the right thing.... Currently you need the species name in multiple places.
Digged a bit into the existing stuff. I think a condition like LocalCandidate.Species = OneOf("SP_BANFORO", "SP_KILANDOW", "SP_MISIORLA") would not work - OneOf would be executed more than once probably giving different results each time(?).

Actually I do not see how to pump a non-object to a another context. Even for the same-effect for each choice we would need some new kind of placeholder (e.g. topic, parameter1, ...) .

Code: Select all

effects = Let topic = OneOf("SP_BANFORO", "SP_KILANDOW", "SP_MISIORLA") effects = [
     SetSpecies name = Topic
     GenerateSitRepMessage ...  tag = "species" data = Topic
]
the way our stuff works ensuring that the Let is executed means only nesting structures are possible or it would need to be pulled out to toplevel; also it would need to be passed down application of nested effects. Maybe specifying a seed/correlator is actually preferrable to this

Code: Select all

effects = [ // the effect can happen only once per planet per game, so it is enough to correlate via Planet id
     SetSpecies name = OneOf("SP_BANFORO", "SP_KILANDOW", "SP_MISIORLA") correlators = (Source.PlanetID))
     GenerateSitRepMessage ...  tag = "species" data = (OneOf("SP_BANFORO", "SP_KILANDOW", "SP_MISIORLA") correlators = (Source.PlanetID)) 
]
all in all I think a specialised effect seems more bloated, but probably more straightforward for scripters (also note that restricting the species to ones which do not yet exist in the empire would not be possible with the simple OneOf in the examples above)

Code: Select all

effects = PickEffects picks = 1 from = [
  WeightedEffects weight = [[ONE_IF_SPECIES_EXISTS_ELSE_ZERO("SP_BANFORO")]] effects = [[REVIVE_SPECIES("SP_BANFORO")]] 
  WeightedEffects weight = [[ONE_IF_SPECIES_EXISTS_ELSE_ZERO("SP_KILANDOW")]] effects = [[REVIVE_SPECIES("SP_KILANDOW")]] 
  WeightedEffects weight = [[ONE_IF_SPECIES_EXISTS_ELSE_ZERO("SP_MISIORLA")]] effects = [[REVIVE_SPECIES("SP_MISIORLA")]] 
] instead = [ ...] // already got all those species - give something else
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
LienRag
Large Juggernaut
Posts: 926
Joined: Fri May 17, 2019 5:03 pm

Re: Excruciating FOCS doubts

#113 Post by LienRag »

Ophiuchus wrote: Mon Jul 26, 2021 7:37 am
LienRag wrote: Fri Apr 30, 2021 7:26 pm I noticed that there is a "tag = monster" but apparently monsters do not have it ?
Where did you find that?
Don't remember, actually.
In FOCS Scripting details there is :

Code: Select all

Monster

Matches space monsters. 
Maybe that's that that I interpreted as a tag ?
Anyway how to use it ?
Source ship Monster ?

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

Re: Excruciating FOCS doubts

#114 Post by Geoff the Medio »

Ophiuchus wrote: Mon Jul 26, 2021 8:06 amActually I do not see how to pump a non-object to a another context. Even for the same-effect for each choice we would need some new kind of placeholder (e.g. topic, parameter1, ...) .
This is running into limits of the declarative format of FOCS and how effect objects are internally structured... Storing state between effect executions would instead generally be done with gamestate, rather than internal to the scripting context.

Ophiuchus
Programmer
Posts: 2177
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Excruciating FOCS doubts

#115 Post by Ophiuchus »

LienRag wrote: Mon Jul 26, 2021 9:56 am
In FOCS Scripting details there is :

Code: Select all

Monster

Matches space monsters. 
Maybe that's that that I interpreted as a tag ?
Anyway how to use it ?
Source ship Monster ?
Its a condition. You do not need the Ship condition (because monster is always a ship; though it would be nice to have a monster planet).
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

Ophiuchus
Programmer
Posts: 2177
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Excruciating FOCS doubts

#116 Post by Ophiuchus »

Geoff the Medio wrote: Mon Jul 26, 2021 11:30 am
Ophiuchus wrote: Mon Jul 26, 2021 8:06 amActually I do not see how to pump a non-object to a another context. Even for the same-effect for each choice we would need some new kind of placeholder (e.g. topic, parameter1, ...) .
This is running into limits of the declarative format of FOCS and how effect objects are internally structured... Storing state between effect executions would instead generally be done with gamestate, rather than internal to the scripting context.
I guess I would prefer strictly nested state (by having something like a stack in the context) to a global registry (which would introduce concurrency issues). With nesting there is a partially strict order imposed. This idea would also apply to conditions. I think the only nested effect we currently have is the "If"/Conditional effect, isnt it?
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

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

Re: Excruciating FOCS doubts

#117 Post by Geoff the Medio »

Ophiuchus wrote: Mon Jul 26, 2021 4:22 pmI think the only nested effect we currently have is the "If"/Conditional effect, isnt it?
I believe there are also some post-creation effects that can be nested within a CreateX effect.

Ophiuchus
Programmer
Posts: 2177
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Excruciating FOCS doubts

#118 Post by Ophiuchus »

Geoff the Medio wrote: Mon Jul 26, 2021 7:10 pm
Ophiuchus wrote: Mon Jul 26, 2021 4:22 pmI think the only nested effect we currently have is the "If"/Conditional effect, isnt it?
I believe there are also some post-creation effects that can be nested within a CreateX effect.
Oh, that is handy to know
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

Ophiuchus
Programmer
Posts: 2177
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Excruciating FOCS doubts

#119 Post by Ophiuchus »

I got geoff's input in the dev meetup, as the stated use case is possible with current implementation (chained if-else effects with dependent probabilities) he doesn't want to complicate the scripting context with adding something maybe more complex (e.g. complexity like the LocalCandidate (e.g. what would happen about invariants?, would one need to store very different values e.g. string, int, float, vector<*>..)).

Weighted selection of objects (without replacement) in a condition makes more sense for him, but also there we do not have a pressing use case (there are usually workarounds). So for the moment I guess wait/dig for valid use cases (anyway having a selection-without-replacement function in random would not hurt).
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

Post Reply