FOCS: how to get turn of special creation

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

Moderator: Committer

Message
Author
User avatar
The Silent One
Graphics
Posts: 712
Joined: Tue Jul 01, 2003 8:27 pm

FOCS: how to get turn of special creation

#1 Post by The Silent One » Mon Sep 18, 2017 12:12 pm

In the following example, how do I retreive the turn of creation of the special itself?

Code: Select all

Special
    name = "DESTRUCTION_COUNTDOWN_SPECIAL_1"
    description = "DESTRUCTION_COUNTDOWN_SPECIAL_1_DESC"
    spawnrate = 0.0
    spawnlimit = 0
    effectsgroups = [
        EffectsGroup
            scope = And [
                Source
                OrderedDestroyedBy condition = All
            ]
            activation = Turn low = ([???].CreationTurn + 1)
            [[PLANET_DESTRUCTION_EFFECT]]
        EffectsGroup
            scope = Source
            activation = Turn low = ([???].CreationTurn + 1)
            effects = RemoveSpecial name = "DESTRUCTION_COUNTDOWN_SPECIAL_1"
    ]
    graphic = "icons/specials_huge/countdown_1.png"
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

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

Re: FOCS: how to get turn of special creation

#2 Post by Geoff the Medio » Mon Sep 18, 2017 1:23 pm

I don't think that's implemented.

There would need to be a ValueRef::ComplexVariable<int>::Eval case for "SpecialAddedOnTurn" or similar, which uses two parameters: an int for object id and a string for the special name, as well as parsing for it. In Eval, it would look up the relevant UniverseObject, and then check ->SpecialAddedOnTurn(special_name) for that object.

It would notably not be just a .PropertyName reference, since you also need to specify the special name (making it have to be a ComplexVariable lookup).

User avatar
The Silent One
Graphics
Posts: 712
Joined: Tue Jul 01, 2003 8:27 pm

Re: FOCS: how to get turn of special creation

#3 Post by The Silent One » Mon Sep 18, 2017 4:16 pm

Thanks, following your description I came across Source.HasSpecialSinceTurn. However, this bit still isn't working:

Code: Select all

activation = Source.HasSpecialSinceTurn name = "DESTRUCTION_COUNTDOWN_SPECIAL_1" low = CurrentTurn - 1 high = CurrentTurn - 1
Possibly because CurrentTurn isn't an int? If so can it be converted?
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

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

Re: FOCS: how to get turn of special creation

#4 Post by Geoff the Medio » Mon Sep 18, 2017 4:43 pm

"Source.HasSpecialSinceTurn" doesn't make sense. A condition is not expressed as a .Property of an object.

User avatar
The Silent One
Graphics
Posts: 712
Joined: Tue Jul 01, 2003 8:27 pm

Re: FOCS: how to get turn of special creation

#5 Post by The Silent One » Mon Sep 18, 2017 4:50 pm

Geoff the Medio wrote:"Source.HasSpecialSinceTurn" doesn't make sense. A condition is not expressed as a .Property of an object.
Thanks.
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
Dilvish
AI Lead, Programmer
Posts: 4707
Joined: Sat Sep 22, 2012 6:25 pm

Re: FOCS: how to get turn of special creation

#6 Post by Dilvish » Mon Sep 18, 2017 4:51 pm

I'm doubtful that you really need to be paying attention to the turn of creation of the special, what is your thinking with that?

I suggest you take a look at CONC_CAMP_MASTER_SPECIAL and CONC_CAMP_SLAVE_SPECIAL for an example of an advancing special sequence (albeit a shorter sequence than has been discussed for planet destruction). And now that I am reminded of that special sequence, the idea comes to mind that the stochastic aspect of the sequence would be nice here too.

If the odds of advancing to the next stage in the sequence were 6/(PlanetSize+5), then a Tiny planet would always get destroyed in the minimum amount of time, and there would be a chance that larger planets might also be destroyed in that min time, but for larger planets there would be a greater and greater chance of it taking longer for them to be destroyed.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
The Silent One
Graphics
Posts: 712
Joined: Tue Jul 01, 2003 8:27 pm

Re: FOCS: how to get turn of special creation

#7 Post by The Silent One » Tue Sep 19, 2017 2:52 pm

Dilvish wrote:I'm doubtful that you really need to be paying attention to the turn of creation of the special, what is your thinking with that?
So, what I've been doing is trying out an idea for a pdc countdown. As of now, there is an unrefined version of the pdc which needs 2 turns to destroy a planet, and two refinements that (are very expensive and) take one turn less per level. It's almost working, and the countdown (special) itself does work as I would expect it to. However, if planet destruction is triggered by the countdown special, (1) that happens on the same turn the special is created and not on the next one, which is why I was looking for HasSpecialSinceTurn (so the destruction would be triggered on the turn after the special is created); and (2), for some reason I do not grok the planet will not be depopulated as it will be when no countdown special is involved. (So I'm still working on this problem, current situation is at the PR.)
..., the idea comes to mind that the stochastic aspect of the sequence would be nice here too.

If the odds of advancing to the next stage in the sequence were 6/(PlanetSize+5), then a Tiny planet would always get destroyed in the minimum amount of time, and there would be a chance that larger planets might also be destroyed in that min time, but for larger planets there would be a greater and greater chance of it taking longer for them to be destroyed.
Not sure I like this idea so much - if the death star fires (or not) shouldn't depend on chance.
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: FOCS: how to get turn of special creation

#8 Post by MatGB » Tue Sep 19, 2017 5:28 pm

There was a way at one point to add a capacity to a special, I don't think it was ever actually used and may have been taken out, Geoff?

Because if you've got a capacity that reduced by one per turn, you've got a countdown. You could also then use follow up shots, etc to reduce the capacity faster.

IIRC the Experimentor nova dragon thing uses some sort of special for targetting and there was some weird stuff in that I didn't ever understand that might help.
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
Dilvish
AI Lead, Programmer
Posts: 4707
Joined: Sat Sep 22, 2012 6:25 pm

Re: FOCS: how to get turn of special creation

#9 Post by Dilvish » Tue Sep 19, 2017 6:35 pm

The Silent One wrote:Not sure I like this idea so much - if the death star fires (or not) shouldn't depend on chance.
Sorry I did not explain it better-- I was not intending that to represent some chance of an unreliable machine working or not. I meant it more along the lines of, destroying planets is a big deal, a lot of work, takes a lot of energy being applied for some extended period of time (i.e. the extended destruction sequence), and unless the deathstar operators do about 60 turns of analysis (which they never have the patience for) before beginning to fire then there is a fair amount of uncertainty as to how long they will have to blast away at it before it explodes, and the larger the planet the more the uncertainty
and the countdown (special) itself does work as I would expect it to. However, if planet destruction is triggered by the countdown special, (1) that happens on the same turn the special is created and not on the next one, which is why I was looking for HasSpecialSinceTurn (so the destruction would be triggered on the turn after the special is created); and (2), for some reason I do not grok the planet will not be depopulated as it will be when no countdown special is involved
Hmm, it's hard to help debug anything without seeing the exact script being used, and it sounds like at least some of this is not with the current language of the PR. You could make auxiliary branches with the various different approaches you are trying, and make PRs into your own home repo for them and direct us to take a look there, so that there would be more flexibility to discuss a number of variations without cluttering up the main repo with lots of parallel PRs.

Regarding destruction happening on same turn as special being created, I'm not thinking of how that could happen unless you were trying to use a conditional effect structure instead of leaving all the conditions in scope and activation. So it would be helpful to see the exact script that led to that result.

I agree with Mat that perhaps you could use Special capacity to help regulate your progression and only when they have a high enough or low enough capacity (whether you count up or down) letting them move on to their main effects (or only then being a sufficient trigger for the destruction effect from the weapon).

Also, to improve clarity and help with debugging, since you have so many repetitive structures I think it would help to use parameterized macro substitution. Geoff, or anyone, do we have a writeup anywhere on using those? I couldn't find one to refresh my memory with, so I did so by reviewing some examples and the parser code itself, but I'm not quite 100% sure I am right in thinking an empty parameter list is fine and about the manner of recursive macro substitution within parameters themselves. But here is a restructuring I came up with that I think helps make the part specification more clear, it lets you look at the meat of the specification and compare different prongs without needing to scroll around so much.

Code: Select all

// single argument is any additional conditions for scope
PDC_SCOPE
'''
And [
                 Planet
                 InSystem id = Source.SystemID
                 OrderedDestroyedBy condition = Source
                 Or [
                     OwnedBy affiliation = EnemyOf empire = Source.Owner
                     Unowned
                 ]
                 VisibleToEmpire empire = Source.Owner
                 @1@
]
'''
PDC_NEITHER_SPECIAL
'''
                 Not HasSpecial name = "DESTRUCTION_COUNTDOWN_SPECIAL_2"
                 Not HasSpecial name = "DESTRUCTION_COUNTDOWN_SPECIAL_1"
'''

PDC_SPECIAL_1
'''
                 HasSpecial name = "DESTRUCTION_COUNTDOWN_SPECIAL_1"
'''

PDC_SCOPE_NEITHER_SPECIAL
'''
[[PDC_SCOPE( [[PDC_NEITHER_SPECIAL]] )]]
'''

PDC_SCOPE_SPECIAL_1
'''
[[PDC_SCOPE( [[PDC_SPECIAL_1]] )]]
'''

PDC_SCOPE_PLAIN
'''
[[PDC_SCOPE()]]
'''


Part
     name = "SP_PLANET_DESTROYER"
     description = "SP_PLANET_DESTROYER_DESC"
     class = Destroy
     mountableSlotTypes = Core
     buildcost = 800 * [[FLEET_UPKEEP_MULTIPLICATOR]] * [[SHIP_PART_COST_MULTIPLIER]]
     buildtime = 8
     tags = [ "CTRL_ALWAYS_BOMBARD" ]
     location = All
     effectsgroups = [    
 
         // if pdc tech is lvl 0 and no countdown is set, start countdown at 2
         EffectsGroup
             scope = [[PDC_SCOPE_NEITHER_SPECIAL]]
             activation = And [
                 Not OwnerHasTech name = "SHP_PLANET_DESTROYER_REF_1"
                 Not OwnerHasTech name = "SHP_PLANET_DESTROYER_REF_2"
             ]
             effects = [
                 AddSpecial name = "DESTRUCTION_COUNTDOWN_SPECIAL_2"
                 [[PLANET_DESTRUCTION_WARNING_SITREP]]
             ]
 
          // if pdc tech is lvl 1 and no countdown is set, start countdown at 1
          EffectsGroup
             scope = [[PDC_SCOPE_NEITHER_SPECIAL]]
             activation = And [
                 OwnerHasTech name = "SHP_PLANET_DESTROYER_REF_1"
                 Not OwnerHasTech name = "SHP_PLANET_DESTROYER_REF_2"
             ]
             effects = [
                 AddSpecial name = "DESTRUCTION_COUNTDOWN_SPECIAL_1"
                 [[PLANET_DESTRUCTION_WARNING_SITREP]]
             ]
 
          // if pdc tech is lvl 2, destroy planet instantly
          EffectsGroup
             scope = [[PDC_SCOPE_PLAIN]]
             activation = OwnerHasTech name = "SHP_PLANET_DESTROYER_REF_2"
             [[PLANET_DESTRUCTION_EFFECT]]
 
         // if countdown is over, destroy planet
         EffectsGroup
             scope = [[PDC_SCOPE_SPECIAL_1]]
             // activation = HasSpecialSinceTurn name = "DESTRUCTION_COUNTDOWN_SPECIAL_1" low = CurrentTurn - 1 high = CurrentTurn - 1
             [[PLANET_DESTRUCTION_EFFECT]]
 
     ]
     icon = "icons/ship_parts/planet_destroyer.png"
 
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

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

Re: FOCS: how to get turn of special creation

#10 Post by Geoff the Medio » Tue Sep 19, 2017 7:10 pm

Dilvish wrote:...I think it would help to use parameterized macro substitution. Geoff, or anyone, do we have a writeup anywhere on using those?
Not that I know of.
...I'm not quite 100% sure I am right in thinking an empty parameter list is fine and about the manner of recursive macro substitution within parameters themselves.
Based on some tests just now, with these macros put into an effect definition:

Code: Select all

// one
[[DUMMY_MACRO([[NOTHING]])]]    // works

// two
[[DUMMY_MACRO([[]])]]           // parse error, replaced with [[]]

// three
[[DUMMY_MACRO( )]]              // works

// four
[[DUMMY_MACRO()]]               // parse error, doesn't recognize as a macro / doesn't substitute

// five
[[DUMMY_MACRO]]                 // parse error, replaces with @1@

DUMMY_MACRO
'''
// empty macro except for parameter
@1@
'''

NOTHING
'''
// also empty macro
'''
MatGB wrote:There was a way at one point to add a capacity to a special, I don't think it was ever actually used and may have been taken out, Geoff?
There is a SetSpecialCapacity effect and a HasSpecialCapacity condition.

User avatar
Dilvish
AI Lead, Programmer
Posts: 4707
Joined: Sat Sep 22, 2012 6:25 pm

Re: FOCS: how to get turn of special creation

#11 Post by Dilvish » Tue Sep 19, 2017 7:19 pm

Geoff the Medio wrote:Based on some tests just now, with these macros put into an effect definition:
Ah, thanks much

The Silent One, so if you try out my reorganization above, be sure to add a space into the empty parameter list for that definition of PDC_SCOPE_PLAIN. (At least, that's the only change I noticed being indicated as needed by Geoff's tests.)
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

dbenage-cx
Programmer
Posts: 389
Joined: Sun Feb 14, 2016 12:08 am

Re: FOCS: how to get turn of special creation

#12 Post by dbenage-cx » Tue Sep 19, 2017 11:46 pm

@Dilvish I think there is a forum post for original implementation of macros, the only explanation in wiki is in EffectsTutorial

@The Silent One : I don't think the specials effect will take place until the following turn, since it is in the middle of being added (e.g. ancient ruins and extinct species)

User avatar
Dilvish
AI Lead, Programmer
Posts: 4707
Joined: Sat Sep 22, 2012 6:25 pm

Re: FOCS: how to get turn of special creation

#13 Post by Dilvish » Wed Sep 20, 2017 12:42 am

dbenage-cx wrote:@Dilvish I think there is a forum post for original implementation of macros, the only explanation in wiki is in EffectsTutorial
Before asking, I searched for such a post, and found a few where they were incidentally mentioned, but that none that seemed directed towards explaining even the general rules of construction for macro substitutions, let alone the specific questions I had re empty parameter lists and recursive substitution in parameter values.

I had also checked the wiki Effects page, but hadn't known of the Effects Tutorial, which hadn't existed last time I looked into such things. It's a great addition, and I have now added a link back to it from the Effects page. (And I think both of them should really get a name change since they are not really just about Effects). Thanks much for mentioning the EffectsTutorial.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
The Silent One
Graphics
Posts: 712
Joined: Tue Jul 01, 2003 8:27 pm

Re: FOCS: how to get turn of special creation

#14 Post by The Silent One » Wed Sep 20, 2017 12:15 pm

Dilvish wrote:The Silent One, so if you try out my reorganization above, be sure to add a space into the empty parameter list for that definition of PDC_SCOPE_PLAIN. (At least, that's the only change I noticed being indicated as needed by Geoff's tests.)
I'll hopefully have some time tonight to try it out. Thanks for the help.
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

Ophiuchus
Vacuum Dragon
Posts: 539
Joined: Tue Sep 30, 2014 10:01 am

Re: FOCS: how to get turn of special creation

#15 Post by Ophiuchus » Wed Sep 20, 2017 4:54 pm

For countdown you could also think of using a capacity .

I was the last one playing around with specials for the supply ships idea I think. Maybe the UNLOADING_SUPPLIES.focs.txt special will help you with creation turn and/or capacity:

https://github.com/agrrr3/freeorion/blo ... S.focs.txt
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Post Reply