FreeOrion

Forums for the FreeOrion project
It is currently Sat May 25, 2013 5:12 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Suggestion: A centralized place for game rules
PostPosted: Mon Sep 01, 2003 5:01 pm 
Offline
Creative Contributor

Joined: Thu Jun 26, 2003 4:33 pm
Posts: 226
Location: Baltimore, MD
When we get to implementing the game logic for 0.1, and future revisions, there are a lot of constants that will need to be defined someplace.

For example: Initial population for new colonies, production numbers, ratios for starlane/non-starlane movement, etc etc

I've already got one of them, the initial colony population, as a constant declared in order.cpp, but I really dont want it to stay there.
These "rule-constants" would be cumbersome and difficult to change if we had their definitions scattered all over the code. Therefore, I propose we create a singleton class to centralize all of the rules in a single location.

The idea is that whenever you need one of these 'rule constants', you add it to the rules file, and update the rule manager class, adding accessors and data members for the constant. This way, all the rules are centralized in an external location, they're easy to change, and we're all getting at them the same way.

I've already specced out a class definition:

Code:
/**
* GameRuleSet is a singleton class to manage all of the various
* game parameters which should be constant during a game, but which
* we may wish to change or tweak.  This includes things like
* default population levels in a colony, production numbers,
* default ship speeds, and the like.  Any constant values pertaining
* to the rules of the game should be accessed through this class
*
*/
class GameRuleSet
{
public:
    /// Instance method -- this guy's a singleton
    static GameRuleSet& instance();
   
    /// Method to read game rules from a rule file.
    /**
    * This method will read the specified rule file and obtain data
    * for all of the game rule constants.
    *  The method should throw an std::runtime_error if any problems occur
    */
    void LoadRuleFile(const std::string& filename);

    /// Returns the default initial population level for a new colony
    int InitialColonyPop() const;

private:

    /// Constructor - initializes all members
    /**
    * Initializes all member variables to some meaningless default value
    * (like 0 or NULL).  LoadRuleFile() should be called at game-start
    * to read actual values from a configuration file.
    */
    GameRuleSet();

    /// default initial population for a new colony (amount of ppl carried on colony ship)
    int m_initial_pop;
   
    /*
        Add any other rule related constants that we need.  Candidates are
        default planet population caps, default ship speeds, offroad vs starlane ratio
        etc etc etc
    */

};
[/code]

_________________
Empire Team Lead


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 10:45 pm 
Offline
Space Squid

Joined: Fri Sep 05, 2003 8:47 pm
Posts: 53
I like to suggest a different place for the game constans.
You use Phyton, like a script language. Phyton is easier to understand for a beginner, like a game designer, so maybe better, if you put all this important game constans in a script. This way you have a big advantage: the designers can modify them and instantly try the new values without any programmer support (and valuable time) and one needn't compile again and again, when the designers try to find the right balance for the game.

_________________
-------------------------------------------
Te vagy a Blade Runner. :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 06, 2003 4:44 am 
Offline
Programming Lead Emeritus
User avatar

Joined: Thu Jun 26, 2003 1:33 pm
Posts: 1092
Blade Runner wrote:
I like to suggest a different place for the game constans.
You use Phyton, like a script language. Phyton is easier to understand for a beginner, like a game designer, so maybe better, if you put all this important game constans in a script. This way you have a big advantage: the designers can modify them and instantly try the new values without any programmer support (and valuable time) and one needn't compile again and again, when the designers try to find the right balance for the game.


Or, instead of adding support for an entire other language, we could just keep these constants in a config file. Text files are easier for designers to work with than any language. Fortunately, there's a function that indicates this approach in Josh's example code:
Code:
void LoadRuleFile(const std::string& filename);


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 06, 2003 4:52 am 
Offline
Programming Lead Emeritus
User avatar

Joined: Thu Jun 26, 2003 1:33 pm
Posts: 1092
As for the overall concept, I'm in favor of centralizing the rules and having a means of serializing them to and from config files. But I think a singleton might be a bit too burdensome to use. How about having a namespace called RuleConst, so we can get RuleConst::foo, RuleConst::Bar, etc? We can have a save and a load function in the namespace, since we only need to load at game startup anyway. This roughly mirrors the usage of the ClientUI constants for UI colors, etc., and that seems pretty usable so far.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 07, 2003 6:17 pm 
Offline
Creative Contributor

Joined: Thu Jun 26, 2003 4:33 pm
Posts: 226
Location: Baltimore, MD
That would work too. The general idea is that we want something that's centrally located and globally accessible.

_________________
Empire Team Lead


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group