project_files/frontlib/model/scheme.h
changeset 7497 7e1d72fc03c7
parent 7482 d70a5b0d1190
child 10017 de822cd3df3a
equal deleted inserted replaced
7494:e65adfc99f15 7497:7e1d72fc03c7
    19 
    19 
    20 /**
    20 /**
    21  * Data structures for game scheme information.
    21  * Data structures for game scheme information.
    22  *
    22  *
    23  * The scheme consists of settings (integers) and mods (booleans). These are not fixed, but
    23  * The scheme consists of settings (integers) and mods (booleans). These are not fixed, but
    24  * described in a "metascheme" file, which describes how each setting and mod is sent to the
    24  * described in a "metascheme", which describes how each setting and mod is sent to the
    25  * engine, and in which order they appear in the network protocol.
    25  * engine, and in which order they appear in the network protocol. The metascheme is defined
       
    26  * in hwconsts.h
    26  */
    27  */
    27 
    28 
    28 #ifndef SCHEME_H_
    29 #ifndef SCHEME_H_
    29 #define SCHEME_H_
    30 #define SCHEME_H_
    30 
    31 
    31 #include <stdbool.h>
    32 #include <stdbool.h>
    32 
    33 #include <stddef.h>
    33 typedef struct {
    34 #include "../hwconsts.h"
    34     char *name;				// A name identifying this setting (used as key in the schemes file)
       
    35     char *engineCommand;	// The command needed to send the setting to the engine. May be null if the setting is not sent to the engine (for the "health" setting)
       
    36     bool maxMeansInfinity;	// If true, send a very high number to the engine if the setting is equal to its maximum
       
    37     bool times1000;			// If true (for time-based settings), multiply the setting by 1000 before sending it to the engine.
       
    38     int min;				// The smallest allowed value
       
    39     int max;				// The highest allowed value
       
    40     int def;				// The default value
       
    41 } flib_metascheme_setting;
       
    42 
       
    43 typedef struct {
       
    44     char *name;				// A name identifying this mod (used as key in the schemes file)
       
    45     int bitmaskIndex;		// Mods are sent to the engine in a single integer, this field describes which bit of that integer is used
       
    46     						// for this particular mod.
       
    47 } flib_metascheme_mod;
       
    48 
       
    49 /**
       
    50  * The order of the meta information in the arrays is the same as the order
       
    51  * of the mod/setting information in the net protocol messages.
       
    52  */
       
    53 typedef struct {
       
    54 	int _referenceCount;
       
    55 	int settingCount;
       
    56 	int modCount;
       
    57 	flib_metascheme_setting *settings;
       
    58 	flib_metascheme_mod *mods;
       
    59 } flib_metascheme;
       
    60 
    35 
    61 /**
    36 /**
    62  * The settings and mods arrays have the same number and order of elements
    37  * The settings and mods arrays have the same number and order of elements
    63  * as the corresponding arrays in the metascheme.
    38  * as the corresponding arrays in the metascheme.
    64  */
    39  */
    65 typedef struct {
    40 typedef struct {
    66 	flib_metascheme *meta;
       
    67 
       
    68     char *name;
    41     char *name;
    69     int *settings;
    42     int *settings;
    70     bool *mods;
    43     bool *mods;
    71 } flib_scheme;
    44 } flib_scheme;
    72 
    45 
    73 /**
    46 /**
    74  * Read the meta-configuration from a .ini file (e.g. which settings exist,
       
    75  * what are their defaults etc.)
       
    76  *
       
    77  * Returns the meta-configuration or NULL.
       
    78  */
       
    79 flib_metascheme *flib_metascheme_from_ini(const char *filename);
       
    80 
       
    81 /**
       
    82  * Increase the reference count of the object. Call this if you store a pointer to it somewhere.
       
    83  * Returns the parameter.
       
    84  */
       
    85 flib_metascheme *flib_metascheme_retain(flib_metascheme *metainfo);
       
    86 
       
    87 /**
       
    88  * Decrease the reference count of the object and free it if this was the last reference.
       
    89  */
       
    90 void flib_metascheme_release(flib_metascheme *metainfo);
       
    91 
       
    92 /**
       
    93  * Create a new configuration with everything set to default or false
    47  * Create a new configuration with everything set to default or false
    94  * Returns NULL on error.
    48  * Returns NULL on error.
    95  */
    49  */
    96 flib_scheme *flib_scheme_create(flib_metascheme *meta, const char *schemeName);
    50 flib_scheme *flib_scheme_create(const char *schemeName);
    97 
    51 
    98 /**
    52 /**
    99  * Create a copy of the scheme. Returns NULL on error or if NULL was passed.
    53  * Create a copy of the scheme. Returns NULL on error or if NULL was passed.
   100  */
    54  */
   101 flib_scheme *flib_scheme_copy(const flib_scheme *scheme);
    55 flib_scheme *flib_scheme_copy(const flib_scheme *scheme);
   106 void flib_scheme_destroy(flib_scheme* scheme);
    60 void flib_scheme_destroy(flib_scheme* scheme);
   107 
    61 
   108 /**
    62 /**
   109  * Retrieve a mod setting by its name. If the mod is not found, logs an error and returns false.
    63  * Retrieve a mod setting by its name. If the mod is not found, logs an error and returns false.
   110  */
    64  */
   111 bool flib_scheme_get_mod(flib_scheme *scheme, const char *name);
    65 bool flib_scheme_get_mod(const flib_scheme *scheme, const char *name);
   112 
    66 
   113 /**
    67 /**
   114  * Retrieve a game setting by its name. If the setting is not found, logs an error and returns def.
    68  * Retrieve a game setting by its name. If the setting is not found, logs an error and returns def.
   115  */
    69  */
   116 int flib_scheme_get_setting(flib_scheme *scheme, const char *name, int def);
    70 int flib_scheme_get_setting(const flib_scheme *scheme, const char *name, int def);
   117 
    71 
   118 #endif /* SCHEME_H_ */
    72 #endif /* SCHEME_H_ */