Page 1 of 1

Part-based upkeep scripting

Posted: Wed May 09, 2018 11:18 am
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?

Re: Part-based upkeep scripting

Posted: Wed May 09, 2018 2:09 pm
by Geoff the Medio
Try a simplified version to see how small you can make it and still reproducd the error?

Re: Part-based upkeep scripting

Posted: Wed May 09, 2018 5:12 pm
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)'''

Re: Part-based upkeep scripting

Posted: Wed May 09, 2018 6:16 pm
by Geoff the Medio
I think this change broke the parsing for the case of ShipPartsOwned when specifying a class.

Re: Part-based upkeep scripting

Posted: Wed May 09, 2018 7:01 pm
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

Re: Part-based upkeep scripting

Posted: Thu May 10, 2018 6:54 pm
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.

Re: Part-based upkeep scripting

Posted: Thu May 10, 2018 7:44 pm
by Geoff the Medio
What is your rule script?

Re: Part-based upkeep scripting

Posted: Thu May 10, 2018 7:46 pm
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

Re: Part-based upkeep scripting

Posted: Fri May 11, 2018 9:38 am
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.

Re: Part-based upkeep scripting

Posted: Fri May 11, 2018 10:04 am
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

Re: Part-based upkeep scripting

Posted: Fri May 11, 2018 10:22 am
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