Page 2 of 2

Re: FOCS: how to get turn of special creation

Posted: Thu Sep 21, 2017 5:23 pm
by The Silent One
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.

Re: FOCS: how to get turn of special creation

Posted: Thu Sep 21, 2017 6:16 pm
by Geoff the Medio
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"

Re: FOCS: how to get turn of special creation

Posted: Thu Sep 21, 2017 7:09 pm
by The Silent One
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.

Re: FOCS: how to get turn of special creation

Posted: Fri Sep 22, 2017 7:08 pm
by The Silent One
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!

Re: FOCS: how to get turn of special creation

Posted: Fri Sep 22, 2017 8:56 pm
by dbenage-cx
Have any log errors? Possibly the PDC_LVL2 activation macro is not replaced, since planet_destruction.macros does not end in newline.

Re: FOCS: how to get turn of special creation

Posted: Fri Sep 22, 2017 8:58 pm
by Dilvish
I posted in your PR, with what I think is a fix. When confronted with bugs, always remember to check your logs.

Re: FOCS: how to get turn of special creation

Posted: Sat Sep 23, 2017 8:05 am
by The Silent One
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.

Re: FOCS: how to get turn of special creation

Posted: Sat Sep 23, 2017 5:30 pm
by The Silent One
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
            ] 

Re: FOCS: how to get turn of special creation

Posted: Sat Sep 23, 2017 6:47 pm
by Dilvish
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.

Re: FOCS: how to get turn of special creation

Posted: Sun Sep 24, 2017 6:00 am
by The Silent One
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.