Need help with Sitrep to show "fleet health percent"

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

Moderators: Oberlus, Committer

Message
Author
Klaus
Krill Swarm
Posts: 10
Joined: Tue Feb 06, 2018 7:22 pm

Re: Need help with Sitrep to show "fleet health percent"

#16 Post by Klaus »

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

Klaus
Krill Swarm
Posts: 10
Joined: Tue Feb 06, 2018 7:22 pm

Re: Need help with Sitrep to show "fleet health percent"

#17 Post by Klaus »

I went through some more testing and made some progress.

Code: Select all

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: Select all

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: Select all

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: Select all

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: Select all

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: Select all

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

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

Re: Need help with Sitrep to show "fleet health percent"

#18 Post by Dilvish »

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.

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).
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

Klaus
Krill Swarm
Posts: 10
Joined: Tue Feb 06, 2018 7:22 pm

Re: Need help with Sitrep to show "fleet health percent"

#19 Post by Klaus »

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: Select all

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: Select all

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: Select all

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: Select all

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: Select all

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

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

Re: Need help with Sitrep to show "fleet health percent"

#20 Post by Dilvish »

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: Select all

   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      Contains And [
         Ship
         (LocalCandidate.Structure < 0.5* LocalCandidate.MaxStructure)   
      ]
   ]
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

Klaus
Krill Swarm
Posts: 10
Joined: Tue Feb 06, 2018 7:22 pm

Re: Need help with Sitrep to show "fleet health percent"

#21 Post by Klaus »

Ah, now im learnding!

Code: Select all

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: Select all

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: Select all

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?

User avatar
Oberlus
Cosmic Dragon
Posts: 5715
Joined: Mon Apr 10, 2017 4:25 pm

Re: Need help with Sitrep to show "fleet health percent"

#22 Post by Oberlus »

If fleets with 100% does not trigger the sitrep, may it be that the division is operating over integers?
Try

Code: Select all

((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).

Post Reply