Inquiry about custom sitreps

For topics that do not fit in another sub-forum.

Moderator: Oberlus

Message
Author
User avatar
Hyperant
Space Kraken
Posts: 125
Joined: Sat Nov 11, 2017 1:33 am

Inquiry about custom sitreps

#1 Post by Hyperant »

So it turned out one can get the sitrep to print basically almost anything you want, and so i took to a small mini project of mine.

It involves fetching all visible systems, and parsing it into a svg-like form so i can recreate it in a vector drawing program. It seems i have hit a bit of a snag.

This is the code:

Code: Select all

EffectsGroup
     scope = And [
        System
        VisibleToEmpire empire = Source.Owner
     ]
     activation = Source
     effects =
         GenerateSitRepMessage
             message = "<circle r='4' cy='%rawtext:yval%' cx='%rawtext:xval%' id='%rawtext:planet%!' style='opacity:1;fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1' />"
             label = "Map Readout"
             NoStringtableLookup
             icon = "icons/meter/troops.png"
             parameters = [
                tag = "planet" data = Target.Name
		tag = "xval" data = Target.X
		tag = "yval" data = Target.Y
             ]
             empire = Source.Owner
And this is what it looks like:

sitrep.PNG
sitrep.PNG (47.17 KiB) Viewed 7311 times

So far so good, but is there any way to have it all be in one message so it could be copy and pasted easily instead of having to copy and paste each individual message?

Follow up question, i looked for a bit but i haven't seen any information on whether starlanes can be printed or not. Is it possible, and if so, what would be the appropriate way of fetching it?
Monarch of the following realms:
-Lumin Federation
-Gamma Republic
-Holy Commune
-Supreme League
-Frost Syndicate

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Inquiry about custom sitreps

#2 Post by Geoff the Medio »

Your problem here is that you're calling GenerateSitRepMessage separately for each object matching the scope condition. That will, unsurprisingly, generate a separate sitrep message for each effect target (ie. systems visible to the source empire).

I don't immediately see a workaround... The format for GenerateSitRepMessage takes a message parameter, which in your case is the XML for a single drawing primitive. But other than one-to-one substitution, there's no way to dynamically modify the format of this primitive to account for variable numbers of matched objects with variable numbers of parameters.

There might be some sort of hack involving the parameters being text format strings themselves, which contain additional placeholders for more text substitutions, which can be chained to keep growing extending the format string, but I doubt it can be set up as things are now. If that were possible, you'd likely need to move the selection of systems from the scope into a sub-condition within the GenerateSitRepMessage effect, and I don't think the parameter filling with system-specific info would work using the existing parameters list.

You could perhaps set up something very limited involving picking from multiple GenerateSitRepMessage effects based on how many objects match a condition. If there were 3 systems matching, then you'd execute the GenerateSitRepMessage effect with message = "TO_SVG_3_MATCHES" and then somehow set up the parameter tags to separately match the 3 systems... but that is completely impractical and inflexible.

I think that doing this cleanly would require substantially more flexible support from the internal GenerateSitRepMessage effect than is presently available.

Easier might be setting up some way to copy all the text of all shown sitreps at once, in the client UI, rather than trying to actually combine them into a single sitrep in the effects system.

For starlanes, the best I can suggest is that you could set up a condition that matches systems that are within 1 starlane jump of a particular system, eg. where a building is located, and then generate a sitrep for each of those matches, which indicates the two system names.

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Inquiry about custom sitreps

#3 Post by Ophiuchus »

Grouping/aggregagtion capability for sitreps would be great. Just saying.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
Hyperant
Space Kraken
Posts: 125
Joined: Sat Nov 11, 2017 1:33 am

Re: Inquiry about custom sitreps

#4 Post by Hyperant »

Hmmmm, then is there any other way to print readouts besides using sitreps, like for example dumping it in messages?
Monarch of the following realms:
-Lumin Federation
-Gamma Republic
-Holy Commune
-Supreme League
-Frost Syndicate

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

Re: Inquiry about custom sitreps

#5 Post by Oberlus »

Hyperant wrote: Fri Apr 17, 2020 3:34 pm Hmmmm, then is there any other way to print readouts besides using sitreps, like for example dumping it in messages?
I tried showing all systems in objects window to "debug data dump", using GUI, but it must be done one by one... Maybe there's a way to call for that "debug data dump" in FOCS?

User avatar
Hyperant
Space Kraken
Posts: 125
Joined: Sat Nov 11, 2017 1:33 am

Re: Inquiry about custom sitreps

#6 Post by Hyperant »

Hm, is there any reference for all the effects that can be used for such a task, or at least all effects in general?

From what i can see the wiki pages aren't very clear at that
Monarch of the following realms:
-Lumin Federation
-Gamma Republic
-Holy Commune
-Supreme League
-Frost Syndicate

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Inquiry about custom sitreps

#7 Post by Geoff the Medio »

Hyperant wrote: Fri Apr 17, 2020 5:04 pmHm, is there any reference for all the effects that can be used for such a task, or at least all effects in general?
Not a good one, but I just searched the parser code to compile this not-very-helpful list:

Code: Select all

General Meters:

SetTargetIndustry
SetTargetPopulation
SetTargetResearch
SetTargetTrade
SetTargetHappiness

SetMaxDefense
SetMaxFuel
SetMaxShield
SetMaxStructure
SetMaxTroops
SetMaxSupply
SetMaxStockpile

SetConstruction
SetIndustry
SetPopulation
SetResearch
SetTrade
SetHappiness

SetDefense
SetFuel
SetShield
SetStructure
SetTroops
SetSupply
SetStockpile

SetRebelTroops
SetStealth
SetDetection
SetSpeed
SetSize


Ships Meters:

SetMaxCapacity
SetMaxDamage
SetMaxSecondaryStat
SetCapacity
SetDamage
SetSecondaryStat


General:

SetEmpireMeter
GiveEmpireTech
SetEmpireTechProgress
GenerateSitrepMessage
SetOverlayTexture
SetEmpireStockpile
SetEmpireCapital
SetPlanetType
SetPlanetSize
SetSpecies
SetOwner
SetSpeciesOpinion
SetVisibility
MoveTo
MoveInOrbit
MoveTowards
SetDestination
SetAggressive
SetPassive
Destroy
NoOp
Victory
AddSpecial
SetSpecialCapacity
RemoveSpecial
AddStarlanes
RemoveStarlanes
SetStarType
SetTexture
CreatePlanet
CreateBuilding
CreateShip
CreateField
CreateSystem
If

User avatar
Hyperant
Space Kraken
Posts: 125
Joined: Sat Nov 11, 2017 1:33 am

Re: Inquiry about custom sitreps

#8 Post by Hyperant »

Hm, so it seems that i have reached my definite dead end, considering there doesn't seem to be any effects that allows one to print in the message board, or anything related to that for the matter.

Thank you to all who have gave their input.
Monarch of the following realms:
-Lumin Federation
-Gamma Republic
-Holy Commune
-Supreme League
-Frost Syndicate

Morlic
AI Contributor
Posts: 296
Joined: Tue Feb 17, 2015 11:54 am

Re: Inquiry about custom sitreps

#9 Post by Morlic »

Hyperant wrote: Fri Apr 17, 2020 3:34 pm Hmmmm, then is there any other way to print readouts besides using sitreps, like for example dumping it in messages?
You could use python turn_event scripts which are run on the server to generate a sitrep (or even simpler: just print to a file)

Code: Select all

--- a/default/python/turn_events/turn_events.py
+++ b/default/python/turn_events/turn_events.py
@@ -68,4 +68,20 @@ def execute_turn_events():
                 if monster == fo.invalid_object():
                     print("Turn events: unable to create monster in fleet", file=sys.stderr)

+    sitrep_message = "This is a sitrep message"
+    universe = fo.get_universe()
+    human_player_id = [empire_id for empire_id in fo.get_all_empires() if "AI_" not in fo.get_empire(empire_id).playerName]
+    print("HUMANS: %s", human_player_id)
+    if len(human_player_id) == 1:
+        human_player_id = human_player_id[0]
+
+        for sys_id in universe.systemIDs:
+            system = universe.getSystem(sys_id)
+            if universe.getVisibility(sys_id, human_player_id) == fo.visibility.basic:
+                sitrep_message += "\n %s: x=%f, y=%f" % ("???", system.x, system.y)
+            if universe.getVisibility(sys_id, human_player_id) >= fo.visibility.partial:
+                sitrep_message += "\n %s: x=%f, y=%f" % (system.name, system.x, system.y)
+
+        fo.generate_sitrep(human_player_id, sitrep_message, {}, "")
+
     return True
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
Hyperant
Space Kraken
Posts: 125
Joined: Sat Nov 11, 2017 1:33 am

Re: Inquiry about custom sitreps

#10 Post by Hyperant »

Ah, many thanks.

Looks like i get to learn Python it seems
Monarch of the following realms:
-Lumin Federation
-Gamma Republic
-Holy Commune
-Supreme League
-Frost Syndicate

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Inquiry about custom sitreps

#11 Post by Geoff the Medio »

Hyperant wrote: Fri Apr 17, 2020 6:46 pmHm, so it seems that i have reached my definite dead end, considering there doesn't seem to be any effects that allows one to print in the message board, or anything related to that for the matter.
Effects are for gamestate manipulations, which the in-game chat is not.

User avatar
Hyperant
Space Kraken
Posts: 125
Joined: Sat Nov 11, 2017 1:33 am

Re: Inquiry about custom sitreps

#12 Post by Hyperant »

Ah yes there we go

After much trial and error:

Ingame:
svg1.PNG
svg1.PNG (212.67 KiB) Viewed 7227 times
svg:
svg2.PNG
svg2.PNG (15.02 KiB) Viewed 7227 times

Really basic for now, but i hope to expand on this when i can.

Follow up question, in my searches i have found the different fo.visibility values. What i was unable to find was such a value that indicates that the empire knows that the system is there, but doesn't have any radar coverage at the time, sorta like the following:
svg3.PNG
svg3.PNG (117.64 KiB) Viewed 7227 times
The systems were explored, yet it doesn't show up when using fo.visibility.basic when fetching the systems.

What would be the appropriate way to fetch such objects as well, while ensuring that completely unknown systems that don't show up at all don't appear?
Monarch of the following realms:
-Lumin Federation
-Gamma Republic
-Holy Commune
-Supreme League
-Frost Syndicate

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Inquiry about custom sitreps

#13 Post by Geoff the Medio »

Hyperant wrote: Sat Apr 18, 2020 1:57 amFollow up question, in my searches i have found the different fo.visibility values.
[...]
The systems were explored, yet it doesn't show up when using fo.visibility.basic when fetching the systems.
Visibility indicates what an empire can see now, not what it has seen.
What i was unable to find was such a value that indicates that the empire knows that the system is there, but doesn't have any radar coverage at the time, sorta like the following:
[...]
What would be the appropriate way to fetch such objects as well, while ensuring that completely unknown systems that don't show up at all don't appear?
[Edit]Assuming FOCS implementation: [/Edit] This is a bit tricky, because empires remember what they last observed about objects, but that information may be out of date or wrong if they can't observe an object on the current turn. Fleets or systems can move or be destroyed after being observed, but the empire will still remember where they last were observed...

I could add a way to access or test the turns when an empire last observed objects (which currently isn't exposed to FOCS). But this may not be consistent with what a player sees in the game, as a player empire could remember that a ship or system was located somewhere, but not have visibility of it on the current turn, and thus not know that the object has moved or been destroyed.

Morlic
AI Contributor
Posts: 296
Joined: Tue Feb 17, 2015 11:54 am

Re: Inquiry about custom sitreps

#14 Post by Morlic »

Hyperant wrote: Sat Apr 18, 2020 1:57 am What would be the appropriate way to fetch such objects as well, while ensuring that completely unknown systems that don't show up at all don't appear?
Assuming you are using the python scripts, you probably want to get the VisibilityTurnsMap like this:

Code: Select all

vis_by_turn_map = universe.getVisibilityTurnsMap(system_id, human_player_id)  # some boost map, not a python dict
vis_by_turn_as_dict = {elem.key(): elem.value() for elem in vis_by_turn}
It is indexed by fo.visibility type and contains the last turn the relevant empire had at leastthat visibility as value (i.e. having partial visibility implies having basic visibility).
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
Hyperant
Space Kraken
Posts: 125
Joined: Sat Nov 11, 2017 1:33 am

Re: Inquiry about custom sitreps

#15 Post by Hyperant »

Getting an error that i am unsure how to resolve:

Code: Select all

13:41:33.743151 {0x00001908} [error] server : commonframework.cpp:158 : Traceback (most recent call last):
13:41:33.743151 {0x00001908} [error] server : commonframework.cpp:158 :   File "C:/Games/Freeorion 0.4.9/FreeOrion/default/python/turn_events\turn_events.py", line 84, in execute_turn_events
    vis_by_turn_as_dict = {elem.key(): elem.value() for elem in vis_by_turn_map}
13:41:33.743151 {0x00001908} [error] server : commonframework.cpp:158 :   File "C:/Games/Freeorion 0.4.9/FreeOrion/default/python/turn_events\turn_events.py", line 84, in <dictcomp>
    vis_by_turn_as_dict = {elem.key(): elem.value() for elem in vis_by_turn_map}
13:41:33.744083 {0x00001908} [error] server : commonframework.cpp:158 : AttributeError: 'map_indexing_suite_VisibilityIntMap_entry' object has no attribute 'value'
13:41:33.744083 {0x00001908} [error] server : serverapp.cpp:1573 : Python scripted turn events failed.
Code:

Code: Select all

    sitrep_message = "This is a sitrep message"
    universe = fo.get_universe()
    human_player_id = [empire_id for empire_id in fo.get_all_empires() if "AI_" not in fo.get_empire(empire_id).playerName]
    print("HUMANS: %s", human_player_id)
    if len(human_player_id) == 1:
        human_player_id = human_player_id[0]
        for sys_id in universe.systemIDs:
            system = universe.getSystem(sys_id)
            vis_by_turn_map = universe.getVisibilityTurnsMap(sys_id, human_player_id)
            vis_by_turn_as_dict = {elem.key(): elem.value() for elem in vis_by_turn_map}
            if universe.getVisibility(sys_id, human_player_id) >= fo.visibility.basic:
                for sys_id2 in universe.systemIDs:
                    system2 = universe.getSystem(sys_id2)
Monarch of the following realms:
-Lumin Federation
-Gamma Republic
-Holy Commune
-Supreme League
-Frost Syndicate

Post Reply