Part-based upkeep scripting

Problems and solutions for installing or running FreeOrion, including discussion of bugs if needed before posting a bug report on GitHub. For problems building from source, post in Compile.

Moderator: Oberlus

Post Reply
Message
Author
User avatar
Voker57
Space Kraken
Posts: 135
Joined: Sat Aug 13, 2016 4:46 pm

Part-based upkeep scripting

#1 Post by Voker57 »

We've been using part-based upkeep using this code for long time, and it seems to work ok: https://github.com/Voker57/freeorion/co ... 67e1440eb2

However, in recent version it fails with this rather cryptic error:

Code: Select all

/opt/freeorion/share/freeorion/default/scripting/ship_hulls/SH_BASIC_MEDIUM.focs.txt:13:72: Parse error.  Expected ) here:
    slots = [
        Slot type = External position = (0.65, 0.25)
        Slot type = External position = (0.65, 0.55)
        Slot type = Internal position = (0.35, 0.35)
    ]
    buildCost = 20 * (1 + (0.002 * ShipPartsOwned empire = Source.Owner class = ShortRange) + (0.002 * ShipPartsOwned empire = Source.Owner class = FighterBay) + (0.002 * ShipPartsOwned empire = Source.Owner class = Armour) + (0.002 * ShipPartsOwned empire = Source.Owner class = Troops) + (0.002 * ShipDesignsOwned)) * (GameRule name = "RULE_SHIP_HULL_COST_FACTOR")
                                                                        ^
    buildTime = 2
    tags = [ "PEDIA_HULL_LINE_GENERIC" ]
    location = Contains And [
        Building name = "BLD_SHIPYARD_BASE"
        OwnedBy empire = Source.Owner
I looked through parse/IntComplexValueRefParser.cpp and saw it went through a refactor but essence seems to be the same. Any idea how to fix the macro?
Team S.M.A.C.: destroying dreams of multiplayer 4x since 2017.

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

Re: Part-based upkeep scripting

#2 Post by Geoff the Medio »

Try a simplified version to see how small you can make it and still reproducd the error?

User avatar
Voker57
Space Kraken
Posts: 135
Joined: Sat Aug 13, 2016 4:46 pm

Re: Part-based upkeep scripting

#3 Post by Voker57 »

Geoff the Medio wrote:Try a simplified version to see how small you can make it and still reproducd the error?
This is minimum that does not work:

Code: Select all

FLEET_UPKEEP_MULTIPLICATOR
'''(ShipPartsOwned empire = Source.Owner class = ShortRange)'''
Team S.M.A.C.: destroying dreams of multiplayer 4x since 2017.

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

Re: Part-based upkeep scripting

#4 Post by Geoff the Medio »

I think this change broke the parsing for the case of ShipPartsOwned when specifying a class.

User avatar
Voker57
Space Kraken
Posts: 135
Joined: Sat Aug 13, 2016 4:46 pm

Re: Part-based upkeep scripting

#5 Post by Voker57 »

Geoff the Medio wrote:I think this change broke the parsing for the case of ShipPartsOwned when specifying a class.
Opened an issue. https://github.com/freeorion/freeorion/issues/2089
Team S.M.A.C.: destroying dreams of multiplayer 4x since 2017.

o01eg
Programmer
Posts: 2004
Joined: Sat Dec 10, 2011 5:46 am

Re: Part-based upkeep scripting

#6 Post by o01eg »

I'm trying to implement it with game rule but couldn't understand how to check if it works.

I simplified macro to

Code: Select all

FLEET_UPKEEP_MULTIPLICATOR
'''(1 + 10 * GameRule name = "RULE_SHIP_PART_BASED_UPKEEP") '''
but got 13.0 PP in production list and 6.5 in production queue in both cases.
Attachments
fo.png
fo.png (63.3 KiB) Viewed 8218 times
Gentoo Linux x64, gcc-11.2, boost-1.78.0
Ubuntu Server 22.04 x64, gcc-12, boost-1.74.0
Welcome to the slow multiplayer game at freeorion-lt.dedyn.io.Version 2024-03-15.b3de094.
Donations're welcome:BTC:bc1q007qldm6eppqcukewtfkfcj0naut9njj7audnm

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

Re: Part-based upkeep scripting

#7 Post by Geoff the Medio »

What is your rule script?

o01eg
Programmer
Posts: 2004
Joined: Sat Dec 10, 2011 5:46 am

Re: Part-based upkeep scripting

#8 Post by o01eg »

Geoff the Medio wrote:What is your rule script?

Code: Select all

GameRule
    name = "RULE_SHIP_PART_BASED_UPKEEP"
    description = "RULE_SHIP_PART_BASED_UPKEEP_DESC"
    category = "BALANCE"
    type = Toggle
    default = Off
Gentoo Linux x64, gcc-11.2, boost-1.78.0
Ubuntu Server 22.04 x64, gcc-12, boost-1.74.0
Welcome to the slow multiplayer game at freeorion-lt.dedyn.io.Version 2024-03-15.b3de094.
Donations're welcome:BTC:bc1q007qldm6eppqcukewtfkfcj0naut9njj7audnm

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

Re: Part-based upkeep scripting

#9 Post by Geoff the Medio »

o01eg wrote:...got 13.0 PP in production list and 6.5 in production queue in both cases.
It costs 13 PP and takes at least 2 turns to produce, so it can have up to 13/2 = 6.5 PP/turn allocated to it on the queue.

o01eg
Programmer
Posts: 2004
Joined: Sat Dec 10, 2011 5:46 am

Re: Part-based upkeep scripting

#10 Post by o01eg »

Geoff the Medio wrote:
o01eg wrote:...got 13.0 PP in production list and 6.5 in production queue in both cases.
It costs 13 PP and takes at least 2 turns to produce, so it can have up to 13/2 = 6.5 PP/turn allocated to it on the queue.
Yes, but as I suppose it should calculate with rule disabled

Code: Select all

 SH_BASIC_SMALL = 10 * (1 + 0) [[FLEET_UPKEEP_MULTIPLICATOR]] * 1 [[SHIP_HULL_COST_MULTIPLIER]]
 GT_TROOP_POD = 3 * (1 + 0) [[FLEET_UPKEEP_MULTIPLICATOR]] * 1 [[SHIP_PART_COST_MULTIPLIER]]
Total: 13
And with rule enabled

Code: Select all

 SH_BASIC_SMALL = 10 * (1 + 10) [[FLEET_UPKEEP_MULTIPLICATOR]] * 1 [[SHIP_HULL_COST_MULTIPLIER]]
 GT_TROOP_POD = 3 * (1 + 10) [[FLEET_UPKEEP_MULTIPLICATOR]] * 1 [[SHIP_PART_COST_MULTIPLIER]]
Total: 143
Gentoo Linux x64, gcc-11.2, boost-1.78.0
Ubuntu Server 22.04 x64, gcc-12, boost-1.74.0
Welcome to the slow multiplayer game at freeorion-lt.dedyn.io.Version 2024-03-15.b3de094.
Donations're welcome:BTC:bc1q007qldm6eppqcukewtfkfcj0naut9njj7audnm

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

Re: Part-based upkeep scripting

#11 Post by Geoff the Medio »

I think / suspect that the multiplication attempts to cast the boolean-valued rule to a double (more accurately, it attempts to get a double out of the the boost::any which stores a bool), which fails, so it defaults to returning 0.0 in this case. Should be able to fix. You could quickly try making the rule "type = Real" to test.

Edit: try after https://github.com/freeorion/freeorion/ ... 9c1d09d65d

Post Reply