Excruciating FOCS doubts

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

Moderators: Oberlus, Committer

Message
Author
User avatar
LienRag
Cosmic Dragon
Posts: 2146
Joined: Fri May 17, 2019 5:03 pm

Re: Excruciating FOCS doubts

#31 Post by LienRag »

Looking at monster ship designs, I noticed that they have a uuid.
I didn't find the reason in the documentation, though.
Is it just a number that must be different from all other ship designs ?
Are there rules to build that number or just adding a digit (and doing a grep to check that it's not used elsewhere) is enough ?

User avatar
LienRag
Cosmic Dragon
Posts: 2146
Joined: Fri May 17, 2019 5:03 pm

Re: Excruciating FOCS doubts

#32 Post by LienRag »

Also, I guess it's not FOCS strictly speaking, but what are the conditions for icons to "parse" ?
I've made (very badly) some on GIMP and many are not accepted by FreeOrion (no error message, the part that refers them just doesn't appear in the game).

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

Re: Excruciating FOCS doubts

#33 Post by Geoff the Medio »

LienRag wrote: Fri Nov 06, 2020 1:15 amLooking at monster ship designs, I noticed that they have a uuid.
I didn't find the reason in the documentation, though.
As referenced here, the UUIDs of ship designs were added to allow a persistent ordering of the designs in the GUI by players.
Is it just a number that must be different from all other ship designs ?
Are there rules to build that number or just adding a digit (and doing a grep to check that it's not used elsewhere) is enough ?
According to this comment, a valid UUID looks like 01234567-89ab-cdef-0123-456789abcdef
I don't know how flexible the conversion is if numbers or letters or dashes are removed or added.
what are the conditions for icons to "parse"
Not clear what you mean. Icon files are loaded as image file by, for instance, the PNG library, which I think does involve some parsing, but I don't think that's what you're talking about. If you just put an icon in the default directory, the game probably won't notice or care, unless you reference that icon in the FOCS for some content. Generally there's something like this:

Code: Select all

graphic = "icons/specials_huge/honeycomb.png"
in a content script that specifies what icon / graphic to use for some content, which is where you'd point it to the new icon file.

User avatar
LienRag
Cosmic Dragon
Posts: 2146
Joined: Fri May 17, 2019 5:03 pm

Re: Excruciating FOCS doubts

#34 Post by LienRag »

Geoff the Medio wrote: Fri Nov 06, 2020 8:45 am
LienRag wrote: Fri Nov 06, 2020 1:15 amwhat are the conditions for icons to "parse"
Not clear what you mean. Icon files are loaded as image file by, for instance, the PNG library, which I think does involve some parsing, but I don't think that's what you're talking about. If you just put an icon in the default directory, the game probably won't notice or care, unless you reference that icon in the FOCS for some content. Generally there's something like this:

Code: Select all

graphic = "icons/specials_huge/honeycomb.png"
in a content script that specifies what icon / graphic to use for some content, which is where you'd point it to the new icon file.
Well, I don't know how to say it precisely : I've refered some icons in some FOCS files and the FOCS itself parses, but some icons are accepted and some are not, though all are in PNG format.
I didn't find rules for what is acceptable and what is not for icons, and anyway I'm not very knowledgeable on icon formatting.

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

Re: Excruciating FOCS doubts

#35 Post by Geoff the Medio »

LienRag wrote: Sat Nov 07, 2020 1:41 am...some icons are accepted and some are not, though all are in PNG format.
What does "accepted" mean for icons? Post an error message or in-game screenshot along with the relevant FOCS and icon file.

User avatar
LienRag
Cosmic Dragon
Posts: 2146
Joined: Fri May 17, 2019 5:03 pm

Re: Excruciating FOCS doubts

#36 Post by LienRag »

Geoff the Medio wrote: Sat Nov 07, 2020 9:12 am
LienRag wrote: Sat Nov 07, 2020 1:41 am...some icons are accepted and some are not, though all are in PNG format.
What does "accepted" mean for icons? Post an error message or in-game screenshot along with the relevant FOCS and icon file.
Well, as I wrote earlier, there is nothing to show as there are no error messages (neither at start when I launch FreeOrion from the console as you explained I should nor during the game; that's what I called "parse" for lack of a better word) and for ship parts the part just doesn't appear in the Ship Design panel.
I had this appear for a Special, and I'm very surprised since I used the starvation.png icon (which isn't used anymore AFAIK) that I just renamed without any modification of the icon itself
Arrakiwheat .png
Arrakiwheat .png (27.68 KiB) Viewed 1133 times
.

For the ship parts, icons which didn't appear (I repeat, that meant that the ship part itself didn't appear, not that a slot was there with a missing icon) where icons that I modified in GIMP, either by cropping them
Gravitic resonator.png
Gravitic resonator.png (10.04 KiB) Viewed 1133 times
or by copying another icon on them
gasgiantcoating.png
gasgiantcoating.png (5.58 KiB) Viewed 1133 times
. The ones which were accepted are icons that I modified only by using rotation, color saturation and the like
test_icon.png
test_icon.png (8.46 KiB) Viewed 1133 times
gasgianthidden.png
gasgianthidden.png (6 KiB) Viewed 1133 times
graviticresonator.png
graviticresonator.png (22.22 KiB) Viewed 1133 times
.
Here are the corresponding FOCS files (yes, they reference the icon that "parse", not anymore the one that doesn't):
Variable pressure nanocoating :

Code: Select all

Part
    name = "ST_COATING_GG"
    description = "ST_COATING_GG_DESC"
    exclusions = "ST_COATING_GG"
    class = Stealth
    capacity = 00
    mountableSlotTypes = Internal
    buildcost = 2 * [[FLEET_UPKEEP_MULTIPLICATOR]] * [[SHIP_PART_COST_MULTIPLIER]]
    buildtime = 5
    tags = [ "PEDIA_PC_STEALTH" ]
    location = OwnedBy empire = Source.Owner
    effectsgroups = [
        EffectsGroup
            scope = Source
            activation = ContainedBy And [
                System 
                Contains Planet type = GasGiant
            ]
	    stackinggroup = "STEALTH_GG_STACK"
            accountinglabel = "GAS_GIANT_FIELD_STEALTH"
            effects = [SetStealth value = Value + 20
            SetSpeed value = Value - 10 
	    ]

    ]
    icon = "icons/ship_parts/gasgianthidden.png"

#include "stealth.macros"

#include "/scripting/common/upkeep.macros"

Gravitic Resonator :

Code: Select all

Part
    name = "SP_GRAVITIC_RESONATOR"
    description = "SP_GRAVITIC_RESONATOR_DESC"
    exclusions = "SP_GRAVITIC_RESONATOR"
    class = General
    mountableSlotTypes = Internal
    buildcost = 10 * [[FLEET_UPKEEP_MULTIPLICATOR]] * [[SHIP_PART_COST_MULTIPLIER]]
    buildtime = 10
    tags = [ "PEDIA_PC_GENERAL" ]
    location = OwnedBy empire = Source.Owner
    effectsgroups = 
        EffectsGroup
            scope = WithinDistance distance = 0 condition = Source            

            activation = ContainedBy And [
                System 
                Contains Planet size = Tiny
            ]
	    stackinggroup = "SP_GRAVITIC_RESONATOR_STACK"
            accountinglabel = "PLANET_RESONANCE"
            effects = SetStealth value = Value - 20
            

    
    icon = "icons/ship_parts/graviticresonator.png"



#include "/scripting/common/upkeep.macros"

Arrakis Wheat :

Code: Select all

Special
    name = "ARRAKIWHEAT_SPECIAL"
    description = "ARRAKIWHEAT_SPECIAL_DESC"
    stealth = 0
    spawnrate = 1.0
    spawnlimit = 9999
    location = And [
        Planet
        Not Planet type = [Asteroids GasGiant]
        Not ContainedBy And [
            System 
            Contains Capital
        ]
        Not WithinStarlaneJumps jumps = 2 condition = And [
            System
            Contains And [
                Planet
                OwnedBy affiliation = AnyEmpire
            ]
        ]
    ]
    effectsgroups = [
        EffectsGroup
            scope = And [
                Planet
                Focus type = "FOCUS_GROWTH"
                OwnedBy empire = Source.Owner
            ]
            activation = And [
                Focus type = "FOCUS_INFLUENCE"
                HasTag name = "TELEPATHIC"
            ]
            stackinggroup = "ARRAKIWHEAT_STACK"
            priority = [[LATE_PRIORITY]]
            effects = SetTargetInfluence value = Value + Target.Population * 0.1 

        

	EffectsGroup
            description = "GROWTH_SPECIAL_POPULATION_ORGANIC_INCREASE"
            scope = And [
                Source
                HasTag name = "ORGANIC"
            ]
            stackinggroup = "ARRAKIWHEAT_STACK"
            priority = [[TARGET_POPULATION_AFTER_SCALING_PRIORITY]]
            effects = SetTargetPopulation value = Value + 1 * Target.HabitableSize  // Provides the bonus locally, no matter the focus
        [[CHANCE_OF_GUARD_2]]
    ]
    graphic = "icons/specials_huge/arrakiwheat.png"

#include "monster_guard.macros"

#include "/scripting/common/base_prod.macros"

#include "/scripting/common/priorities.macros"



This one still references the icon that doesn't "parse" since I don't understand what the problem is.

User avatar
LienRag
Cosmic Dragon
Posts: 2146
Joined: Fri May 17, 2019 5:03 pm

Re: Excruciating FOCS doubts

#37 Post by LienRag »

Here are the screenshots of what is shown for the Special (I wasn't able to upload more than five pictures in the preceding post).
Attachments
bug arrakis wheat.png
bug arrakis wheat.png (722.38 KiB) Viewed 1133 times
bug arrakis wheat2.png
bug arrakis wheat2.png (673.65 KiB) Viewed 1133 times

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

Re: Excruciating FOCS doubts

#38 Post by Oberlus »

LienRag wrote: Mon Nov 09, 2020 2:34 am...
Check out you are referencing the right file names. I spotted you have a file "Arrakiwheat .png" (with capital A and a space before the dot) and reference an icon "arrakiwheat.png" (without capital letters or spaces).

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

Re: Excruciating FOCS doubts

#39 Post by Geoff the Medio »

LienRag wrote: Mon Nov 09, 2020 2:34 am...there is nothing to show as there are no error messages (neither at start when I launch FreeOrion from the console as you explained I should nor during the game...
Then there's no parsing error. Rather, you've probably specified a file that doesn't exist or can't be read. The parser doesn't verify that such file exist (or not), but rather the client / UI does when it attempts to display the graphic for the first time. There might be something in freeorion.log that indicates that the texture file couldn't be loaded. As Oberlus noted, the filenames in what you've posted are inconstent.

User avatar
LienRag
Cosmic Dragon
Posts: 2146
Joined: Fri May 17, 2019 5:03 pm

Re: Excruciating FOCS doubts

#40 Post by LienRag »

It seems you are right, the problem with arrakiswheat was indeed a typo, and the log file¹ showed an error message "inexisting texture".
What really puzzles me is that for the other icons (cropped and copied over), I had double and triple-checked that they were the cause of the problem (copying the exact name with F2 and Ctrl C) but today I tested by replacing "flak.png" in the flak FOCS file by the name of these icons (I used flak so I could test just by going to the ship design panel on turn 1) and the flak appeared with the copied over (at first try) and the cropped (on second test) icon...
So, copied over and cropped icons are accepted by FreeOrion, I guess that's good to know, especially for someone with little graphic skills like me.
I did the first thorough tests some time ago, with version 4.9 I think, so theorically the new version could have a more tolerant texture importing tool, but I'm not aware that something had been changed in the codebase to that aspect.
Sorry for the bother then and thanks for your patience and help.


¹ Which is here in Snap builds, actually : ~/snap/freeorion/current/.local/share/freeorion/freeorion.log - not very easy to find !

User avatar
LienRag
Cosmic Dragon
Posts: 2146
Joined: Fri May 17, 2019 5:03 pm

Re: Excruciating FOCS doubts

#41 Post by LienRag »

On another topic, I'm trying to modify the way the Derelict Tanker works.
For memory, here is the original Derelict Tanker FOCS file :

Code: Select all

 Special
    name = "DERELICT_SPECIAL3"               //  FUEL
    description = "DERELICT_SPECIAL_DESC"
    stealth = 45
    spawnrate = 0.5
    spawnlimit = 100
    location = And [
        System
        Not Contains Capital
    ]
    effectsgroups = [
        EffectsGroup
            scope = And [
                Ship
                InSystem id = Source.SystemID
                OwnedBy affiliation = AnyEmpire
            ]
            activation = And [
                System
                Contains And [
                    Ship
                    OwnedBy affiliation = AnyEmpire
                ]
            ]
            effects = [
                AddSpecial name = "DERELICT_SPECIAL3"
                GenerateSitRepMessage
                    message = "EFFECT_DERELICT_FUEL"
                    label = "EFFECT_DERELICT_FUEL_LABEL"
                    icon = "icons/meter/fuel.png"
                    parameters = [
                        tag = "system" data = Source.ID
                        tag = "special" data = "DERELICT_SPECIAL3"
                    ]
                    empire = Target.Owner
            ]

        EffectsGroup
            scope = And [
                Source
                System
            ]
            activation = And [
                System
                Contains And [
                    Ship
                    OwnedBy affiliation = AnyEmpire
                ]
            ]
            effects = [
                RemoveSpecial name = "DERELICT_SPECIAL3"
            ]

        EffectsGroup
            scope = And [
                Source
                Ship
            ]
            effects = [
                SetFuel value = Value + 100
                RemoveSpecial name = "DERELICT_SPECIAL3"
            ]
    ]
    graphic = "icons/specials_huge/derelict.png"
I had some trouble understanding why it created and destroyed a Special but I finally understood that it was to be able to send the sitrep message with the parameter "tag "special". Why it has to add itself to do that is still beyond my comprehension.

I also did not understand why it had to destroy itself twice and I supposed that was to destroy the initial Special and also destroy the new Special of the same name, so I tried creating a different special and destroying each of them separately. Derelict_special4 has no effect, nor location (so it wouldn't spawn on its own).


Code: Select all

Special
    name = "DERELICT_SPECIAL3"               //  FUEL
    description = "DERELICT_SPECIAL_DESC"
    stealth = 45
    spawnrate = 0.5
    spawnlimit = 100
    location = And [
        System
        Not Contains Capital
    ]
    effectsgroups = [
        EffectsGroup
            scope = And [
                Ship
                InSystem id = Source.SystemID
                OwnedBy affiliation = AnyEmpire
            ]
            activation = And [
                System
                Contains And [
                    Ship
                    OwnedBy affiliation = AnyEmpire
                ]
            ]
            effects = [
                AddSpecial name = "DERELICT_SPECIAL4"
                GenerateSitRepMessage
                    message = "EFFECT_DERELICT_FUEL"
                    label = "EFFECT_DERELICT_FUEL_LABEL"
                    icon = "icons/meter/fuel.png"
                    parameters = [
                        tag = "system" data = Source.ID
                        tag = "special" data = "DERELICT_SPECIAL4"
                    ]
                    empire = Target.Owner
            ]

        EffectsGroup
            scope = And [
                Source
                System
            ]
            activation = And [
                System
                Contains And [
                    Ship
                    OwnedBy affiliation = AnyEmpire
                ]
            ]
            effects = [
                RemoveSpecial name = "DERELICT_SPECIAL4"
            ]

        EffectsGroup
            scope = And [
                Source
                Ship
            ]
            effects = [
                SetFuel value = Value + 100
                RemoveSpecial name = "DERELICT_SPECIAL3"
            ]
    ]
    graphic = "icons/specials_huge/derelict.png"
It more or less works (at least the sitrep message is correctly sent), but if I destroy the Special4 at the second effect group (here above) it doesn't destroy the Derelict tanker : ships are refueled each time they pass through the system, and I'm not sure I understand why (yes, this effect group has its scope in the system and the third and last effect group doesn't, so I might understand why it would not remove the initial Derelict Tanker - Derelict_Special4 - in the last effect group, but then why in the original code is this deletion put in the third effect group ?).

And if I destroy the Special4 at the third effect group (here below) it does destroy the Derelict tanker but the ships are never refueled, and I have even less clue why.
Is the created Special attached to the ship instead of the system ? Is there recursion involved, that's why it won't work if I split the specials ?

Code: Select all

Special
    name = "DERELICT_SPECIAL3"               //  FUEL
    description = "DERELICT_SPECIAL_DESC"
    stealth = 45
    spawnrate = 0.5
    spawnlimit = 100
    location = And [
        System
        Not Contains Capital
    ]
    effectsgroups = [
        EffectsGroup
            scope = And [
                Ship
                InSystem id = Source.SystemID
                OwnedBy affiliation = AnyEmpire
            ]
            activation = And [
                System
                Contains And [
                    Ship
                    OwnedBy affiliation = AnyEmpire
                ]
            ]
            effects = [
                AddSpecial name = "DERELICT_SPECIAL4"
                GenerateSitRepMessage
                    message = "EFFECT_DERELICT_FUEL"
                    label = "EFFECT_DERELICT_FUEL_LABEL"
                    icon = "icons/meter/fuel.png"
                    parameters = [
                        tag = "system" data = Source.ID
                        tag = "special" data = "DERELICT_SPECIAL4"
                    ]
                    empire = Target.Owner
            ]

        EffectsGroup
            scope = And [
                Source
                System
            ]
            activation = And [
                System
                Contains And [
                    Ship
                    OwnedBy affiliation = AnyEmpire
                ]
            ]
            effects = [
                RemoveSpecial name = "DERELICT_SPECIAL3"
            ]

        EffectsGroup
            scope = And [
                Source
                Ship
            ]
            effects = [
                SetFuel value = Value + 100
                RemoveSpecial name = "DERELICT_SPECIAL4"
            ]
    ]
    graphic = "icons/specials_huge/derelict.png"

BTW, is there a FOCS IDE for Linux ? I've read that Notepad++ has one, but it's for Windows...

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

Re: Excruciating FOCS doubts

#42 Post by Ophiuchus »

LienRag wrote: Wed Nov 11, 2020 1:47 am On another topic, I'm trying to modify the way the Derelict Tanker works.

I had some trouble understanding why it created and destroyed a Special but I finally understood that it was to be able to send the sitrep message with the parameter "tag "special".
Well, wrong. The special tag uses the not the special universe object, but the special definition name. Does not need an existing object.

Each object can have a special only once (It gets stored in a map with the special name as key).

So, on what kind of object(s) the special gets actually added?
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
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Excruciating FOCS doubts

#43 Post by Geoff the Medio »

LienRag wrote: Wed Nov 11, 2020 1:47 am...but if I destroy the Special4 at the second effect group (here above) it doesn't destroy the Derelict tanker : ships are refueled each time they pass through the system, and I'm not sure I understand why...
When attached to a system, your first DERELICT_SPECIAL3 (second code block) adds DERELICT_SPECIAL4 to ships in the system and removes DERELICT_SPECIAL4 from the system (which probably does nothing unless there happens to also be a DERELICT_SPECIAL4 special in the system). When attached to a ship (which presumably never happens unless in some other code?), it removes DERELICT_SPECIAL3 (itself) from the ship while refueling the ship. You didn't post a DERELICT_SPECIAL4 definition, so I don't know what it does.
And if I destroy the Special4 at the third effect group (here below) it does destroy the Derelict tanker but the ships are never refueled, and I have even less clue why.
When attached to a system, your second DERELICT_SPECIAL3 (third code block) adds DERELICT_SPECIAL4 to ships in the system and removes DERELICT_SPECIAL3 from the system. When attached to a ship (when presumably never happens unless in some other code?), it would remove DERELICT_SPECIAL4 (that isn't present on the ship unless coindidentally added by something else) while refueling the ship. Again, there's no posted DERELICT_SPECIAL4 definition, so I don't know what it does.
Is the created Special attached to the ship instead of the system ?
What is "the created Special"?
Is there recursion involved, that's why it won't work if I split the specials ?
Not clear what you mean.

User avatar
LienRag
Cosmic Dragon
Posts: 2146
Joined: Fri May 17, 2019 5:03 pm

Re: Excruciating FOCS doubts

#44 Post by LienRag »

OK, with your explanations and a lot of testing, I was finally able to figure it out, so thanks for your answers and your patience.

If I get it correctly (and since I was able to change the code and make it work, I think that I do), the code (there is a commented version of the original code below) first creates a Special (a new instance of itself) that it attaches to the ship that enters the system (if I understand correctly, this code is applied to all ships entering the system in the same turn, which means that each of these ships will get an instance of the Derelict3 Special attached to it). It also sends a sitrep message to the player, telling him that his ships have been refueled in the system by a Derelict Tanker.

Then (second effect group) it removes itself from the system, as the Derelict tanker is supposed to refuel ships only once, so we don't want the Special attached to the system to affect ships next or subsequent turns.

The third Effect Group is actually NOT executed on the Derelict3 Special attached to the system, but only when the code is re-executed on the newly created instance (the "created special" I was refering to in the previous message, and the reason I was talking of recursion). It then refuels the ship and removes itself from said ship as we want the refueling to operate only once.
That is very clever coding but also very hard to understand.
It's especially extremely confusing, for someone who's seen only the frontend, to understand when working on the FOCS file about a Special that is attached to a system, that this Special could actually backend-wise be attached to anything.
It really should be recommended practice to put comments on the FOCS code when it is that much non-obvious, especially if the goal is to allow interested players to contribute to the game by writing FOCS files or modifying existing ones themselves.

Code: Select all

Special
    name = "DERELICT_SPECIAL3"               //  FUEL
    description = "DERELICT_SPECIAL_DESC"
    stealth = 45
    spawnrate = 0.5
    spawnlimit = 100
    location = And [
        System
        Not Contains Capital
    ]
    effectsgroups = [
        EffectsGroup
            scope = And [
                Ship
                InSystem id = Source.SystemID
                OwnedBy affiliation = AnyEmpire
            ]
            activation = And [
                System
                Contains And [
                    Ship
                    OwnedBy affiliation = AnyEmpire
                ]
            ]
            effects = [
                AddSpecial name = "DERELICT_SPECIAL3" // we add the Derelict tanker Special to the Ship in order to later be able to affect the ships characteristics
                GenerateSitRepMessage
                    message = "EFFECT_DERELICT_FUEL"
                    label = "EFFECT_DERELICT_FUEL_LABEL"
                    icon = "icons/meter/fuel.png"
                    parameters = [
                        tag = "system" data = Source.ID
                        tag = "special" data = "DERELICT_SPECIAL3"
                    ]
                    empire = Target.Owner
            ]

        EffectsGroup 		// here we remove the Derelict tanker special from the system, since it's a one-time event
            scope = And [
                Source
                System
            ]
            activation = And [
                System
                Contains And [
                    Ship
                    OwnedBy affiliation = AnyEmpire
                ]
            ]
            effects = [
                RemoveSpecial name = "DERELICT_SPECIAL3"
            ]

        EffectsGroup	// the code runs here not on the original Derelict3 Special attached to the system, but to the one newly attached to the ship
            scope = And [
                Source
                Ship
            ]
            effects = [
                SetFuel value = Value + 100
                RemoveSpecial name = "DERELICT_SPECIAL3" // after having refueled the ship, we remove the Special that has been attached to it
            ]
    ]
    graphic = "icons/specials_huge/derelict.png"



Wnat I wanted to do originally is make the Derelict Tanker works in two steps, being discoverd on one turn and refueling fleets the next time a ship enters the system.
This allows for more strategic exploration as a player may want to save it for a more important move later (like an invasion fleet of a Colony ship) instead of simply refueling the ship that discovered the tanker initially.

So I split the code in two FOCS files, the initial Derelict3 that only discovers the tanker but doesn't refill the ship :

Code: Select all

Special
    name = "DERELICT_SPECIAL3"               //  THE ONE WHICH DISCOVERS THE TANKER
    description = "DERELICT_SPECIAL_DESC"
    stealth = 45
    spawnrate = 0.5
    spawnlimit = 100
    location = And [
        System
        Not Contains Capital
    ]
    effectsgroups = [
        EffectsGroup // here we send a sitrep message to whoever sent a ship in the system
            scope = And [
                Ship
                InSystem id = Source.SystemID
                OwnedBy affiliation = AnyEmpire
            ]
            activation = And [
                System
                Contains And [
                    Ship
                    OwnedBy affiliation = AnyEmpire
                ]
            ]
            effects = [
               
                GenerateSitRepMessage
                    message = "EFFECT_DERELICT_FUEL_TANKER"
                    label = "EFFECT_DERELICT_FUEL_LABEL"
                    icon = "icons/meter/fuel.png"
                    parameters = [
                        tag = "system" data = Source.ID
			tag = "ship" data = RootCandidate.ID // test
                        tag = "special" data = "DERELICT_TANKER_SPECIAL"
                    ]
                    empire = Target.Owner
            ]

      
        EffectsGroup // here we add a Derelict tanker Special that will be used next time a Ship will enter the system, and remove the Derelict3 Special since the tanker has already been discovered
            scope = And [
                Source
                System
            ]
            activation = And [
                System
                Contains And [
                    Ship
                    OwnedBy affiliation = AnyEmpire
                ]
            ]
            effects = [
                AddSpecial name = "DERELICT_TANKER_SPECIAL"
		
                RemoveSpecial name = "DERELICT_SPECIAL3"
            ]

    ]
    graphic = "icons/specials_huge/derelict.png"

And the one that actually refills the fleet(s) entering the system in a later turn (to avoid micromanagement, I didn't want to add any button - that I wouldn't know how to implement anyway - to refuel the fleet : just entering a System where a discovered Derelict tanker is refuels the fleet and destroys the Tanker) :

Code: Select all

Special
    name = "DERELICT_TANKER_SPECIAL"               //  THE ONE WHICH ACTUALLY GIVES THE FUEL
    description = "DERELICT_SPECIAL_DESC"
    stealth = 5
    spawnrate = 0.5
    spawnlimit = 100
// This one doesn't spawn at Galaxy creation
    
    effectsgroups = [
        EffectsGroup     // we add the Derelict tanker Special to the Ship in order to later be able to affect the ships characteristics
            scope = And [
                Ship
                InSystem id = Source.SystemID
                OwnedBy affiliation = AnyEmpire
            ]
            activation = And [
                System
                Contains And [
                    Ship
                    OwnedBy affiliation = AnyEmpire
                ]
		Turn low = Source.CreationTurn + 1
            ]
            effects = AddSpecial name = "DERELICT_TANKER_SPECIAL"
               

        EffectsGroup // here we remove the Derelict tanker special from the system, since the fictional tanker is destroyed at the end of the refueling operation
            scope = And [
                Source
                System
            ]
            activation = And [
                System
                Contains And [
                    Ship
                    OwnedBy affiliation = AnyEmpire
                ]
		Turn low = Source.CreationTurn + 1
            ]
            effects = RemoveSpecial name = "DERELICT_TANKER_SPECIAL"
		

        EffectsGroup // here the code runs not on the original Derelict tanker Special attached to the system, but to the one newly attached to the ship. It refuels the ship, warns the player of the refueling operation and the destruction of the fictional tanker, then removes the Derelict tanker Special from the ship.
            scope = And [
                Source
                Ship
            ]

            effects = [
		GenerateSitRepMessage
                    message = "EFFECT_TANKER_IMPLODED"
                    label = "EFFECT_DERELICT_FUEL_LABEL"
                    icon = "icons/meter/fuel.png"
                    parameters = [
                        tag = "ship" data = Source.ID
                        tag = "special" data = "DERELICT_TANKER"
                    ]            
		    empire = Target.Owner
                SetFuel value = Value + 100
                RemoveSpecial name = "DERELICT_TANKER_SPECIAL"
            ]
    ]
    graphic = "icons/specials_huge/derelict.png"
I tested it and it works (well, it did not at first, but now it does).
I think it would improve the game if it was included in FreeOrion in replacement of the Derelict Tanker (derelict3.focs.txt) that exists as of now.
Is it a problem if I put this code under the AGPL license ?

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

Re: Excruciating FOCS doubts

#45 Post by Geoff the Medio »

LienRag wrote: Sun Nov 15, 2020 5:11 amIt really should be recommended practice to put comments on the FOCS code when it is that much non-obvious...
Feel free to submit some patches / pull requests that do such documentation as you review the scripts.
Wnat I wanted to do originally is make the Derelict Tanker works in two steps, being discoverd on one turn and refueling fleets the next time a ship enters the system.
This sounds a bit awkward to use in practice, as it would seem to require the initial scout to leave the system immediately to avoid triggering the refuel effect.
Is it a problem if I put this code under the AGPL license ?
It must be CC-BY-SA 3.0 and GPL 2.0 licensed. See https://github.com/freeorion/freeorion/ ... lt/COPYING

Post Reply