FreeOrion
http://www.freeorion.org/forum/

Need help with Sitrep to show "fleet health percent"
http://www.freeorion.org/forum/viewtopic.php?f=15&t=10875
Page 2 of 2

Author:  Klaus [ Thu Feb 08, 2018 11:38 pm ]
Post subject:  Re: Need help with Sitrep to show "fleet health percent"

Thanks you guys are awesome!
Will look into it tomorrow :D

Author:  Klaus [ Sat Feb 10, 2018 12:02 am ]
Post subject:  Re: Need help with Sitrep to show "fleet health percent"

I went through some more testing and made some progress.

Code:
scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      Number low = ((LocalCandidate.NumShips * 1 / 2) +1) condition = And [   
         Ship
         ContainedBy RootCandidate
         Structure high = (LocalCandidate.MaxStructure * 0.50)   
      ]
]

Its my way to get around the "Sum" not working. I count the ships that are below x% up to at least x% of NumShips in fleet.
The exact numbers are not final and this is just for testing.

I tried to do

Code:
Statistic If condition = (LocalCandidate.Structure < LocalCandidate.MaxStructure)


But it always gives me the "]" Error. I use Notepad++ to check for matching parentheses.
If i replace the line "Structure high = (LocalCandidate.MaxStructure * 0.50) " with the code above,
i would expect to get 1 = true for damaged ships(any), and 0 = false for ships at MaxStructure.

But the "<" does not seem to be valid, i guess only "low 0" or "high =" works with comparing values?
I tried all sorts of combinations

Code:
Statistic If condition = (LocalCandidate.Structure < LocalCandidate.MaxStructure)
If condition = (LocalCandidate.Structure < LocalCandidate.MaxStructure)
Statistic If condition = (LocalCandidate.Structure high = LocalCandidate.MaxStructure)
If condition = (LocalCandidate.Structure high = LocalCandidate.MaxStructure)


I also dont get why "Statistic" needs to be before the If, if i leave it out it i also get "]" error.

Code:
scripting/empire_statistics/MILITARY_STRENGTH.focs.txt:2:    Statistic Sum value = (LocalCandidate.Attack * (LocalCandidate.Structure + 2 * LocalCandidate.MaxShield))


Here its used for Sum.
When i first saw this file i did not know what "Statistic" meant and thought its just a variable used for game graphs.
Then "Sum" is only used 3 times in all accessable scripts?

In the wiki the example is just

Code:
Sum value = LocalCandidate.Population condition = Planet


Thats why im confused. Statistic yes/no?
I still dont get it why i cant use "Sum" or "If" in a supposed valid boolean expression.
To check if Sum of values is lower/greater some other Sum.

I currently try to do all conditions in the scope to fire the SitRep only when all conditions are met.
The SitRep output is just fleet values, no conditions atm.
Also text is not final, but should not matter for testing anyways.
So why do i get "]" error if i try to use "If" or "Sum" and other code runs fine, like the "Number" solution i use for now.

Complete SitRep

Code:
EffectsGroup
scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      Number low = ((LocalCandidate.NumShips * 1 / 2) +1) condition = And [   
         Ship
         ContainedBy RootCandidate
         Structure high = (LocalCandidate.MaxStructure * 0.50)   
      ]
]
activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the ship is at %rawtext% percent test 123."
            label = "Fleet_Detail"
            NoStringtableLookup
            icon = "icons/planet/gasgiant.png"
            parameters = [
            tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips  // works, shows number of ships in fleet
         ]
            empire = Source.Owner

Author:  Dilvish [ Sat Feb 10, 2018 4:44 am ]
Post subject:  Re: Need help with Sitrep to show "fleet health percent"

Klaus wrote:
But the "<" does not seem to be valid, i guess only "low 0" or "high =" works with comparing values?
No, "<", ">", "<=" etc should all work fine in the general manner you showed there, but they are not interchangeable with "low" and "high"-- the latter are keywords used by various specific conditions, as opposed to the comparison operators which specify value comparison conditions themselves. (The concepts are related, but distinct). If you want more specific feedback post the exact sitrep you tried for that, and the error log lines / message you are getting.


Quote:
I also dont get why "Statistic" needs to be before the If, if i leave it out it i also get "]" error....
When i first saw this file i did not know what "Statistic" meant and thought its just a variable used for game graphs.
"Statistic" is required, and I've now edited that tutorial section to clarify. Without being preceded by the keyword "Statistic", I believe the keyword "If" is only valid in the Effects section, so the parser was telling you that your scripting parts were not fitting together properly (the parser was waiting for a terminating bracket when you used "If" in a place it was not valid).

Author:  Klaus [ Sat Feb 10, 2018 6:20 pm ]
Post subject:  Re: Need help with Sitrep to show "fleet health percent"

Ok here a some of my failed tries with Parser error. Im also posting the tries with "<" to "high =" change.
At the end is the current work around example without error.

Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      
      Contains And [
         Ship
         Statistic If condition = (LocalCandidate.Structure high = LocalCandidate.MaxStructure)   // Parse Error: Expected ] here
      ]
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair."
             label = "Fleet_Detail_Test"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner

Parse Error: Expected ] here

Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      
      Contains And [
         Ship
         Statistic If condition = (LocalCandidate.Structure < LocalCandidate.MaxStructure)   // Parse Error: Expected ] here
      ]
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair."
             label = "Fleet_Detail_Test"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner

Parse Error: Expected ] here

Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      
      Number low = ((LocalCandidate.NumShips * 1 / 2) +1) condition = And [   
         Ship
         ContainedBy RootCandidate
         Statistic If condition = (LocalCandidate.Structure < LocalCandidate.MaxStructure)   // Parse Error: Expected ] here
         
      ]
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair."
             label = "Fleet_Detail_Test"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner


Parse Error: Expected ] here


Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      
      Number low = ((LocalCandidate.NumShips * 1 / 2) +1) condition = And [   
         Ship
         ContainedBy RootCandidate
         Statistic If condition = (LocalCandidate.Structure high = LocalCandidate.MaxStructure)   // Parse Error: Expected ] here
         
      ]
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair."
             label = "Fleet_Detail_Test"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner

Parse Error: Expected ] here


Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      
      Number low = ((LocalCandidate.NumShips * 1 / 2) +1) condition = And [   
         Ship
         ContainedBy RootCandidate
         Structure high = (LocalCandidate.MaxStructure * 0.50)   // works
         
      ]
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair."
             label = "Fleet_Detail_Test"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner

working

Author:  Dilvish [ Sat Feb 10, 2018 7:04 pm ]
Post subject:  Re: Need help with Sitrep to show "fleet health percent"

Ah, it took a little while to sink in, but here you are trying to use this "If" type Statistic as part of a list of Conditions, but Statistics are ValueRefs (the If type returns either a 1 or a 0).

Changing it to something like the following works just fine
Code:
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      Contains And [
         Ship
         (LocalCandidate.Structure < 0.5* LocalCandidate.MaxStructure)   
      ]
   ]

Author:  Klaus [ Sun Feb 11, 2018 12:27 pm ]
Post subject:  Re: Need help with Sitrep to show "fleet health percent"

Ah, now im learnding!

Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      
      Number low = ((LocalCandidate.NumShips * 1 / 2) +1) condition = And [   // low = (LocalCandidate.NumShips * 1 / 3) works
         Ship
         ContainedBy RootCandidate
         ((Statistic Sum value = LocalCandidate.Structure condition = ContainedBy RootCandidate) / (Statistic Sum value = LocalCandidate.MaxStructure condition = ContainedBy RootCandidate) < 0.5)
         
      ]
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair."
             label = "Fleet_Detail_Test"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner


I had to add "Statistic" to make this work and compare "<" the result to some number.

Question is now, how do i do it without "Number".
Could i just do

Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      ((Statistic Sum value = LocalCandidate.Structure condition = ContainedBy RootCandidate) / (Statistic Sum value = LocalCandidate.MaxStructure condition = ContainedBy RootCandidate) < 0.5)
         
      
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair."
             label = "Fleet_Detail_Test"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner




Edit:

In my test with

Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      ((Statistic Sum value = LocalCandidate.Structure condition = ContainedBy RootCandidate) / (Statistic Sum value = LocalCandidate.MaxStructure condition = ContainedBy RootCandidate) < 0.75)
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair75."
             label = "Fleet_Detail_Test75"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner


A fleet with ~90% Structure/MaxStructure reported to be below 75%. Which means it does not quite do what i think it does/should.
Is it maybe because of RootCandidate and LocalCandidate now have a different meaning than before when i had this check in my "Number" block?

Author:  Oberlus [ Sun Feb 11, 2018 7:00 pm ]
Post subject:  Re: Need help with Sitrep to show "fleet health percent"

If fleets with 100% does not trigger the sitrep, may it be that the division is operating over integers?
Try
Code:
((Statistic Sum value = LocalCandidate.Structure condition = ContainedBy RootCandidate) < (0.75 * (Statistic Sum value = LocalCandidate.MaxStructure condition = ContainedBy RootCandidate)))

(No idea about operators preference in FOCS, so I added extra parenthesis).

Page 2 of 2 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/