FreeOrion

Forums for the FreeOrion project
It is currently Sat Dec 16, 2017 5:28 am

All times are UTC




Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Mon Sep 18, 2017 12:12 pm 
Offline
Graphics
User avatar

Joined: Tue Jul 01, 2003 8:27 pm
Posts: 708
In the following example, how do I retreive the turn of creation of the special itself?

Code:
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.


Top
 Profile  
 
PostPosted: Mon Sep 18, 2017 1:23 pm 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12042
Location: Munich
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).


Top
 Profile  
 
PostPosted: Mon Sep 18, 2017 4:16 pm 
Offline
Graphics
User avatar

Joined: Tue Jul 01, 2003 8:27 pm
Posts: 708
Thanks, following your description I came across Source.HasSpecialSinceTurn. However, this bit still isn't working:

Code:
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.


Top
 Profile  
 
PostPosted: Mon Sep 18, 2017 4:43 pm 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12042
Location: Munich
"Source.HasSpecialSinceTurn" doesn't make sense. A condition is not expressed as a .Property of an object.


Top
 Profile  
 
PostPosted: Mon Sep 18, 2017 4:50 pm 
Offline
Graphics
User avatar

Joined: Tue Jul 01, 2003 8:27 pm
Posts: 708
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.


Top
 Profile  
 
PostPosted: Mon Sep 18, 2017 4:51 pm 
Offline
AI Lead, Programmer
User avatar

Joined: Sat Sep 22, 2012 6:25 pm
Posts: 4390
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


Top
 Profile  
 
PostPosted: Tue Sep 19, 2017 2:52 pm 
Offline
Graphics
User avatar

Joined: Tue Jul 01, 2003 8:27 pm
Posts: 708
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.)

Quote:
..., 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.


Top
 Profile  
 
PostPosted: Tue Sep 19, 2017 5:28 pm 
Offline
Creative Contributor
User avatar

Joined: Fri Jun 28, 2013 11:45 pm
Posts: 3295
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.


Top
 Profile  
 
PostPosted: Tue Sep 19, 2017 6:35 pm 
Offline
AI Lead, Programmer
User avatar

Joined: Sat Sep 22, 2012 6:25 pm
Posts: 4390
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

Quote:
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:
// 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


Top
 Profile  
 
PostPosted: Tue Sep 19, 2017 7:10 pm 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12042
Location: Munich
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.
Quote:
...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:
// 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.


Top
 Profile  
 
PostPosted: Tue Sep 19, 2017 7:19 pm 
Offline
AI Lead, Programmer
User avatar

Joined: Sat Sep 22, 2012 6:25 pm
Posts: 4390
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


Top
 Profile  
 
PostPosted: Tue Sep 19, 2017 11:46 pm 
Offline
Programmer

Joined: Sun Feb 14, 2016 12:08 am
Posts: 359
@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)


Top
 Profile  
 
PostPosted: Wed Sep 20, 2017 12:42 am 
Offline
AI Lead, Programmer
User avatar

Joined: Sat Sep 22, 2012 6:25 pm
Posts: 4390
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


Top
 Profile  
 
PostPosted: Wed Sep 20, 2017 12:15 pm 
Offline
Graphics
User avatar

Joined: Tue Jul 01, 2003 8:27 pm
Posts: 708
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.


Top
 Profile  
 
PostPosted: Wed Sep 20, 2017 4:54 pm 
Offline
Dyson Forest

Joined: Tue Sep 30, 2014 10:01 am
Posts: 221
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group