project_files/frontlib/model/cfg.h
changeset 7320 e704706008d4
parent 7318 a446eafcddeb
child 7322 18e1fba30f99
equal deleted inserted replaced
7318:a446eafcddeb 7320:e704706008d4
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or
       
     6  * modify it under the terms of the GNU General Public License
       
     7  * as published by the Free Software Foundation; either version 2
       
     8  * of the License, or (at your option) any later version.
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program; if not, write to the Free Software
       
    17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
       
    18  */
       
    19 
       
    20 /**
       
    21  * Data structures for game scheme information.
       
    22  */
       
    23 
       
    24 #ifndef CFG_H_
       
    25 #define CFG_H_
       
    26 
       
    27 #include <stdbool.h>
       
    28 
       
    29 // TODO: cfg/config -> scheme
       
    30 
       
    31 typedef struct {
       
    32     char *name;
       
    33     char *engineCommand;
       
    34     bool maxMeansInfinity;
       
    35     bool times1000;
       
    36     int min;
       
    37     int max;
       
    38     int def;
       
    39 } flib_cfg_setting_meta;
       
    40 
       
    41 typedef struct {
       
    42     char *name;
       
    43     int bitmaskIndex;
       
    44 } flib_cfg_mod_meta;
       
    45 
       
    46 /**
       
    47  * The order of the meta information in the arrays is the same as the order
       
    48  * of the mod/setting information in the net protocol messages.
       
    49  */
       
    50 typedef struct {
       
    51 	int _referenceCount;
       
    52 	int settingCount;
       
    53 	int modCount;
       
    54     flib_cfg_setting_meta *settings;
       
    55     flib_cfg_mod_meta *mods;
       
    56 } flib_cfg_meta;
       
    57 
       
    58 typedef struct {
       
    59 	int _referenceCount;
       
    60     flib_cfg_meta *meta;
       
    61 
       
    62     char *name;
       
    63     int *settings;
       
    64     bool *mods;
       
    65 } flib_cfg;
       
    66 
       
    67 /**
       
    68  * Read the meta-configuration from a .ini file (e.g. which settings exist,
       
    69  * what are their defaults etc.)
       
    70  *
       
    71  * Returns the meta-configuration or NULL.
       
    72  */
       
    73 flib_cfg_meta *flib_cfg_meta_from_ini(const char *filename);
       
    74 
       
    75 /**
       
    76  * Increase the reference count of the object. Call this if you store a pointer to it somewhere.
       
    77  * Returns the parameter.
       
    78  */
       
    79 flib_cfg_meta *flib_cfg_meta_retain(flib_cfg_meta *metainfo);
       
    80 
       
    81 /**
       
    82  * Decrease the reference count of the object and free it if this was the last reference.
       
    83  */
       
    84 void flib_cfg_meta_release(flib_cfg_meta *metainfo);
       
    85 
       
    86 /**
       
    87  * Create a new configuration with everything set to default or false
       
    88  * Returns NULL on error.
       
    89  */
       
    90 flib_cfg *flib_cfg_create(flib_cfg_meta *meta, const char *schemeName);
       
    91 
       
    92 /**
       
    93  * Create a copy of the scheme. Returns NULL on error or if NULL was passed.
       
    94  */
       
    95 flib_cfg *flib_cfg_copy(const flib_cfg *cfg);
       
    96 
       
    97 /**
       
    98  * Increase the reference count of the object. Call this if you store a pointer to it somewhere.
       
    99  * Returns the parameter.
       
   100  */
       
   101 flib_cfg *flib_cfg_retain(flib_cfg *cfg);
       
   102 
       
   103 /**
       
   104  * Decrease the reference count of the object and free it if this was the last reference.
       
   105  */
       
   106 void flib_cfg_release(flib_cfg* cfg);
       
   107 
       
   108 /**
       
   109  * Retrieve a mod setting by its name. If the mod is not found, logs an error and returns false.
       
   110  */
       
   111 bool flib_cfg_get_mod(flib_cfg *cfg, const char *name);
       
   112 
       
   113 /**
       
   114  * Retrieve a game setting by its name. If the setting is not found, logs an error and returns def.
       
   115  */
       
   116 int flib_cfg_get_setting(flib_cfg *cfg, const char *name, int def);
       
   117 
       
   118 #endif /* CFG_H_ */