project_files/frontlib/model/scheme.h
changeset 7320 e704706008d4
parent 7314 6171f0bad318
child 7482 d70a5b0d1190
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 SCHEME_H_
       
    25 #define SCHEME_H_
       
    26 
       
    27 #include <stdbool.h>
       
    28 
       
    29 typedef struct {
       
    30     char *name;
       
    31     char *engineCommand;
       
    32     bool maxMeansInfinity;
       
    33     bool times1000;
       
    34     int min;
       
    35     int max;
       
    36     int def;
       
    37 } flib_metascheme_setting;
       
    38 
       
    39 typedef struct {
       
    40     char *name;
       
    41     int bitmaskIndex;
       
    42 } flib_metascheme_mod;
       
    43 
       
    44 /**
       
    45  * The order of the meta information in the arrays is the same as the order
       
    46  * of the mod/setting information in the net protocol messages.
       
    47  */
       
    48 typedef struct {
       
    49 	int _referenceCount;
       
    50 	int settingCount;
       
    51 	int modCount;
       
    52 	flib_metascheme_setting *settings;
       
    53 	flib_metascheme_mod *mods;
       
    54 } flib_metascheme;
       
    55 
       
    56 typedef struct {
       
    57 	int _referenceCount;
       
    58 	flib_metascheme *meta;
       
    59 
       
    60     char *name;
       
    61     int *settings;
       
    62     bool *mods;
       
    63 } flib_scheme;
       
    64 
       
    65 /**
       
    66  * Read the meta-configuration from a .ini file (e.g. which settings exist,
       
    67  * what are their defaults etc.)
       
    68  *
       
    69  * Returns the meta-configuration or NULL.
       
    70  */
       
    71 flib_metascheme *flib_metascheme_from_ini(const char *filename);
       
    72 
       
    73 /**
       
    74  * Increase the reference count of the object. Call this if you store a pointer to it somewhere.
       
    75  * Returns the parameter.
       
    76  */
       
    77 flib_metascheme *flib_metascheme_retain(flib_metascheme *metainfo);
       
    78 
       
    79 /**
       
    80  * Decrease the reference count of the object and free it if this was the last reference.
       
    81  */
       
    82 void flib_metascheme_release(flib_metascheme *metainfo);
       
    83 
       
    84 /**
       
    85  * Create a new configuration with everything set to default or false
       
    86  * Returns NULL on error.
       
    87  */
       
    88 flib_scheme *flib_scheme_create(flib_metascheme *meta, const char *schemeName);
       
    89 
       
    90 /**
       
    91  * Create a copy of the scheme. Returns NULL on error or if NULL was passed.
       
    92  */
       
    93 flib_scheme *flib_scheme_copy(const flib_scheme *scheme);
       
    94 
       
    95 /**
       
    96  * Increase the reference count of the object. Call this if you store a pointer to it somewhere.
       
    97  * Returns the parameter.
       
    98  */
       
    99 flib_scheme *flib_scheme_retain(flib_scheme *scheme);
       
   100 
       
   101 /**
       
   102  * Decrease the reference count of the object and free it if this was the last reference.
       
   103  */
       
   104 void flib_scheme_release(flib_scheme* scheme);
       
   105 
       
   106 /**
       
   107  * Retrieve a mod setting by its name. If the mod is not found, logs an error and returns false.
       
   108  */
       
   109 bool flib_scheme_get_mod(flib_scheme *scheme, const char *name);
       
   110 
       
   111 /**
       
   112  * Retrieve a game setting by its name. If the setting is not found, logs an error and returns def.
       
   113  */
       
   114 int flib_scheme_get_setting(flib_scheme *scheme, const char *name, int def);
       
   115 
       
   116 #endif /* SCHEME_H_ */