Game Rules declared in the backend?

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
User avatar
Oberlus
Cosmic Dragon
Posts: 5704
Joined: Mon Apr 10, 2017 4:25 pm

Game Rules declared in the backend?

#1 Post by Oberlus »

If I got this right, RULE_NUM_COMBAT_ROUNDS is not declared in default/scripting/game_rules.focs.txt, but in the backend:

https://github.com/freeorion/freeorion/ ... ts.cpp#L19

Code: Select all

        rules.Add<int>(UserStringNop("RULE_NUM_COMBAT_ROUNDS"),
                       UserStringNop("RULE_NUM_COMBAT_ROUNDS_DESC"),
                       "", 4, true, RangedValidator<int>(2, 20));
Is there a reason to not have all game rules in the same file or to need to recompile FreeOrion if one wants to change that value?

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

Re: Game Rules declared in the backend?

#2 Post by o01eg »

Oberlus wrote: Mon Nov 16, 2020 8:01 am If I got this right, RULE_NUM_COMBAT_ROUNDS is not declared in default/scripting/game_rules.focs.txt, but in the backend:

https://github.com/freeorion/freeorion/ ... ts.cpp#L19

Code: Select all

        rules.Add<int>(UserStringNop("RULE_NUM_COMBAT_ROUNDS"),
                       UserStringNop("RULE_NUM_COMBAT_ROUNDS_DESC"),
                       "", 4, true, RangedValidator<int>(2, 20));
Is there a reason to not have all game rules in the same file or to need to recompile FreeOrion if one wants to change that value?
Rules used in C++ should be declared in C++.
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-01-30.0dd6806.
Donations're welcome:BTC:bc1q007qldm6eppqcukewtfkfcj0naut9njj7audnm

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

Re: Game Rules declared in the backend?

#3 Post by Oberlus »

o01eg wrote: Mon Nov 16, 2020 10:54 am Rules used in C++ should be declared in C++.
Isn't C++ using the value of (e.g.) RULE_HABITABLE_SIZE_TINY declared in game_rules.focs.txt?
https://github.com/freeorion/freeorion/ ... t.cpp#L206

Couldn't the same be done for number of bouts per combat turn?

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

Re: Game Rules declared in the backend?

#4 Post by o01eg »

Oberlus wrote: Mon Nov 16, 2020 11:04 am
o01eg wrote: Mon Nov 16, 2020 10:54 am Rules used in C++ should be declared in C++.
Isn't C++ using the value of (e.g.) RULE_HABITABLE_SIZE_TINY declared in game_rules.focs.txt?
https://github.com/freeorion/freeorion/ ... t.cpp#L206

Couldn't the same be done for number of bouts per combat turn?
I suppose it's mistake because even if someone fully rewrite game content scripts C++ code should be usable still.
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-01-30.0dd6806.
Donations're welcome:BTC:bc1q007qldm6eppqcukewtfkfcj0naut9njj7audnm

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

Re: Game Rules declared in the backend?

#5 Post by Oberlus »

o01eg wrote: Mon Nov 16, 2020 11:23 am I suppose it's mistake because even if someone fully rewrite game content scripts C++ code should be usable still.
If I understand you correctly, it's a mistake that those two rules are added only in C++ code instead of in the game_rules.focs.txt file, and so I could make a PR about it, am I right?

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

Re: Game Rules declared in the backend?

#6 Post by Oberlus »

C++ files that add rules not defined in game_rules.focs.txt:

https://github.com/freeorion/freeorion/ ... lomacy.cpp
https://github.com/freeorion/freeorion/ ... rnment.cpp
https://github.com/freeorion/freeorion/ ... nQueue.cpp
https://github.com/freeorion/freeorion/ ... ngType.cpp
https://github.com/freeorion/freeorion/ ... ipHull.cpp
https://github.com/freeorion/freeorion/ ... Events.cpp
https://github.com/freeorion/freeorion/ ... Common.cpp

For example, we have RULE_ENABLE_ALLIED_REPAIR in game_rules.focs.txt but RULE_THRESHOLD_HUMAN_PLAYER_WIN, RULE_ONLY_ALLIANCE_WIN, RULE_ALLOW_CONCEDE, RULE_CONCEDE_COLONIES_THRESHOLD in MultiplayerCommon.cpp.

Do you envision any problem from moving them all to the focs file?

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

Re: Game Rules declared in the backend?

#7 Post by Geoff the Medio »

Oberlus wrote: Mon Nov 16, 2020 11:38 am
o01eg wrote: Mon Nov 16, 2020 11:23 am I suppose it's mistake because even if someone fully rewrite game content scripts C++ code should be usable still.
If I understand you correctly, it's a mistake that those two rules are added only in C++ code instead of in the game_rules.focs.txt file, and so I could make a PR about it, am I right?
The opposite: if a rule is referenced in C++, it needs to / should be defined in C++ and does not need to be also defined in game_rules.focs.txt. If a rule is defined in game_rules.focs.txt and not in C++, but is used in C++, that's a potential bug and the rule should be moved into C++ and removed from game_rules.focs.txt

Post Reply