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

Re: FOCS: how to get turn of special creation

#16 Post by The Silent One » Thu Sep 21, 2017 5:23 pm

Ophiuchus wrote: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
Thanks, that's useful indeed. Do you know if there is a way to directly retrieve the special capacity value? That'd be helpful for creating a tooltip for the pdc countdown special, to show how many turns are remaining until the planet's destruction.

Having rewritten the .focs code to use capacity instead of multiple specials, freeoriond.exe now crashes when starting a new game or loading a game. I don't really have a clue why this is happening, no parsing errors are reported. I've attached the logs, and the PR is updated with my current development build, if someone can help me figure out what's going on I'd very much appreciate it.
Attachments
freeoriond.log
(10.83 KiB) Downloaded 5 times
freeorion.log
(16.27 KiB) Downloaded 4 times
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: 12247
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: FOCS: how to get turn of special creation

#17 Post by Geoff the Medio » Thu Sep 21, 2017 6:16 pm

The Silent One wrote:Do you know if there is a way to directly retrieve the special capacity value?
https://github.com/freeorion/freeorion/ ... b2acb1449d
freeoriond.exe now crashes when starting a new game or loading a game. I don't really have a clue why this is happening, no parsing errors are reported.
There's an access violation in parse::specials.

Code: Select all

Unhandled exception at 0x008939CE in FreeOrionD.exe: 0xC0000005: Access violation reading location 0x00000020.
Might help to have quotes around DESTRUCTION_COUNTDOWN_SPECIAL in

Code: Select all

effects = RemoveSpecial name = "DESTRUCTION_COUNTDOWN_SPECIAL"

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

#18 Post by The Silent One » Thu Sep 21, 2017 7:09 pm

Geoff the Medio wrote:Might help to have quotes around DESTRUCTION_COUNTDOWN_SPECIAL in

Code: Select all

effects = RemoveSpecial name = "DESTRUCTION_COUNTDOWN_SPECIAL"
Indeed, thank you.
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
The Silent One
Graphics
Posts: 712
Joined: Tue Jul 01, 2003 8:27 pm

Re: FOCS: how to get turn of special creation

#19 Post by The Silent One » Fri Sep 22, 2017 7:08 pm

Sorry to have to ask for help yet again, I tried for the last week to figure this one out, but no luck.

The countdown using SpecialCapacity does work as it is supposed to. However, when the countdown reaches 0, the planet is not completely destroyed, only the population and resource output vanish, buildings and specials and the planet type remain (it is just reduced to outpost status maybe?). No destruction sitreps are generated. But on the next turn, if the Destroy Button is pushed again, the planet is destroyed. I've attached an image of the current situation below. Relevant focs parts are:

Code: Select all

         // if countdown ends, destroy planet
         EffectsGroup
            scope = And [
                [[PDC_SCOPE]]
                HasSpecialCapacity name = "DESTRUCTION_COUNTDOWN_SPECIAL" high = 0.5
            ]
            [[PLANET_DESTRUCTION_EFFECT]]
(Don't see what could go wrong here.)
as well as

Code: Select all

PLANET_DESTRUCTION_EFFECT
'''         effects = [
                GenerateSitRepMessage  // sitrep for destroying empire
                    message = "EFFECT_PLANET_DESTRUCTION"
                    label = "EFFECT_PLANET_DESTRUCTION_LABEL"
                    icon = "icons/sitrep/planet_destroyed.png"
                    parameters = [
                        tag = "planet" data = Target.ID
                        tag = "empire" data = Target.Owner
                    ]
                    empire = Source.Owner
                GenerateSitRepMessage  // sitrep for targeted empire
                    message = "EFFECT_PLANET_DESTRUCTION_OWN"
                    label = "EFFECT_PLANET_DESTRUCTION_LABEL"
                    icon = "icons/sitrep/planet_destroyed.png"
                    parameters = [
                        tag = "planet" data = Target.ID
                        tag = "empire" data = Source.Owner
                    ]
                    empire = Target.Owner
                RemoveAllSpecials
                RemoveAllBuildings
                SetOwner empire = -1
                SetSpecies name = ""
                SetPopulation value = 0
                SetPlanetType type = Asteroids
            ]
'''
Any idea what might cause this behaviour?

[Edit]I should add that the planet destruction focs code works if the countdown isn't involved; "direct" destruction with the lvl 2 pdc works!
Attachments
bug.jpg
bug.jpg (78.2 KiB) Viewed 221 times
If I provided any images, 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

#20 Post by dbenage-cx » Fri Sep 22, 2017 8:56 pm

Have any log errors? Possibly the PDC_LVL2 activation macro is not replaced, since planet_destruction.macros does not end in newline.

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

Re: FOCS: how to get turn of special creation

#21 Post by Dilvish » Fri Sep 22, 2017 8:58 pm

I posted in your PR, with what I think is a fix. When confronted with bugs, always remember to check your logs.
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

#22 Post by The Silent One » Sat Sep 23, 2017 8:05 am

dbenage-cx wrote:Have any log errors? Possibly the PDC_LVL2 activation macro is not replaced, since planet_destruction.macros does not end in newline.
I'm sure it is being replaced, because planet destruction without a countdown is working, and that uses the macro as well.
Dilvish wrote:I posted in your PR, with what I think is a fix. When confronted with bugs, always remember to check your logs.
:oops: I hadn't seen anything on the console, but I'll make sure to check the logs as well in the future.
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
The Silent One
Graphics
Posts: 712
Joined: Tue Jul 01, 2003 8:27 pm

Re: FOCS: how to get turn of special creation

#23 Post by The Silent One » Sat Sep 23, 2017 5:30 pm

I think I've tracked the bug down, but it's really ...weird. See the code below; unexplicably, SetPopulation value = 0 is already executed when the countdown hits 1, but everything else is executed on the turn after, how it is actually supposed to... :? After commenting out SetPopulation, everything works as intended and at the right time (except that some population remains after planet destruction). Console doesn't show anything, and I can't find anything conspicuous in the logs. A save is attached, Celtsi Alpha is awaiting destruction on the south part of the map.

Any bright ideas what may be happening here?

From SP_PLANET_DESTROYER.focs.txt:

Code: Select all

          // if countdown ends, destroy planet
          EffectsGroup
              scope = And [ [[PDC_SCOPE]] ]
             // HasSpecialCapacity name = "DESTRUCTION_COUNTDOWN_SPECIAL" high = 0.5

             activation = Number low = 1 condition = HasSpecialCapacity name = "DESTRUCTION_COUNTDOWN_SPECIAL" high = 0.5
             effects = [
                 GenerateSitRepMessage
                     message = "TEST_MESSAGE"
                     label = "TEST_MESSAGE"
                     icon = "icons/sitrep/planet_destroyed.png"
                     empire = Source.Owner
                 RemoveAllSpecials
                 RemoveAllBuildings
                 SetOwner empire = -1
                 SetSpecies name = ""
                 SetPlanetType type = Asteroids
                 SetPopulation value = 0
            ] 
Attachments

[The extension sav has been deactivated and can no longer be displayed.]

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

Re: FOCS: how to get turn of special creation

#24 Post by Dilvish » Sat Sep 23, 2017 6:47 pm

Regarding the SetPopulation issue, unlike that is the others that is a meter effect, and so gets processed an additional time towards the end of the turn (the stated intent of which is to cover newly created objects, but I think this is getting caught up in it also).

fleets_move
combat
all effects applied, including building new "current" meter values from "initial" meter values
supply & resources updated
things made
scripted events processed
meter effects applied again (rebuilds new "current" meter values from "initial" meter values, not adding another dollop to current meter values)
population growth
back-propagation of meters ("initial" values overwritten by "current" values)
turn number advanced

The best solution that comes to mind to me is to use an additional special along with the new SpecialAddedOnTurn condition Geoff made-- when the first special finishes its countdown it adds the second special, and the second special (with the additional condition that it must have been created on the previous turn) serves as the trigger for all the effects.

I also want to note, I am pretty sure that you'll need to keep that SpecialCapacity condition in the scope, or tighten up the scope in some other way (like maybe tightening the OrderedBombarded condition). Otherwise, it looks to me like in a situation with multiple planet destructions proceeding in the system with different countdowns, a single activation could trigger them all to destroy at once.
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

#25 Post by The Silent One » Sun Sep 24, 2017 6:00 am

Found a way to fix this (finally :) ). Solution was to create a special after planet destruction, which then takes care of removing the population. This will synchronise population removal with the other destruction effects. Thanks for the help getting this sorted out.
If I provided any images, code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0.

Post Reply