Options.h

Go to the documentation of this file.
00001 /*
00002 RealTimeBattle, a robot programming game for Unix
00003 Copyright (C) 1998-2000  Erik Ouchterlony and Ragnar Ouchterlony
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software Foundation,
00017 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef __OPTIONS__
00021 #define __OPTIONS__
00022 
00023 #include "Various.h"
00024 #include "String.h"
00025 
00026 //class String;
00027 class OptionsWindow;
00028 
00029 #ifndef NO_GRAPHICS
00030 struct _GtkWidget;
00031 typedef struct _GtkWidget GtkWidget;
00032 #endif
00033 
00034 enum option_double_t
00035 {
00036   OPTION_GRAV_CONST,
00037   OPTION_AIR_RESISTANCE,
00038   OPTION_ROLL_FRICTION,
00039   OPTION_SLIDE_FRICTION,
00040   OPTION_ROBOT_MAX_ACCELERATION,
00041   OPTION_ROBOT_MIN_ACCELERATION,
00042 
00043   OPTION_ROBOT_RADIUS,
00044   OPTION_ROBOT_MASS,
00045 
00046   OPTION_ROBOT_BOUNCE_COEFF,
00047   OPTION_ROBOT_HARDNESS,
00048   OPTION_ROBOT_PROTECTION,
00049 
00050   OPTION_ROBOT_FRONT_BOUNCE_COEFF,
00051   OPTION_ROBOT_FRONT_HARDNESS,
00052   OPTION_ROBOT_FRONT_PROTECTION,
00053 
00054   OPTION_ROBOT_FRONTSIZE,
00055 
00056   OPTION_ROBOT_START_ENERGY,
00057   OPTION_ROBOT_MAX_ENERGY,
00058 
00059   OPTION_ROBOT_MAX_ROTATE,
00060   OPTION_ROBOT_CANNON_MAX_ROTATE,
00061   OPTION_ROBOT_RADAR_MAX_ROTATE,
00062 
00063   OPTION_SHOT_RADIUS,
00064   OPTION_SHOT_SPEED,
00065   OPTION_SHOOTING_PENALTY,
00066   OPTION_SHOT_MIN_ENERGY,
00067   OPTION_SHOT_MAX_ENERGY,
00068   OPTION_SHOT_ENERGY_INCREASE_SPEED,
00069 
00070   OPTION_COOKIE_MAX_ENERGY,
00071   OPTION_COOKIE_MIN_ENERGY,
00072   OPTION_COOKIE_FREQUENCY,
00073   OPTION_COOKIE_RADIUS,
00074 
00075   OPTION_MINE_MAX_ENERGY,
00076   OPTION_MINE_MIN_ENERGY,
00077   OPTION_MINE_FREQUENCY,
00078   OPTION_MINE_RADIUS,
00079 
00080   OPTION_ARENA_SCALE,
00081   OPTION_FAST_FORWARD_FACTOR,
00082 
00083   OPTION_TIMEOUT,
00084   OPTION_MAX_TIMESTEP,
00085   OPTION_TIMESCALE,
00086   OPTION_UPDATE_INTERVAL,
00087   OPTION_ROBOT_STARTUP_TIME,
00088 
00089   OPTION_CPU_START_LIMIT,
00090   OPTION_CPU_EXTRA,
00091   OPTION_CPU_PERIOD,
00092   OPTION_CPU_WARNING_PERCENT,
00093 
00094   OPTION_CHECK_INTERVAL,
00095 
00096   LAST_DOUBLE_OPTION
00097 };
00098 
00099 enum option_long_t
00100 {
00101   OPTION_SEND_ROBOT_COORDINATES,
00102   OPTION_MAX_ROBOTS_ALLOWED, 
00103 
00104   OPTION_ROBOT_ENERGY_LEVELS,
00105 
00106   OPTION_BACKGROUND_COLOUR,
00107   OPTION_FOREGROUND_COLOUR,
00108   OPTION_RTB_MESSAGE_COLOUR,
00109   OPTION_COOKIE_COLOUR,
00110   OPTION_MINE_COLOUR,
00111 
00112   OPTION_LOG_EVERY_NTH_UPDATE_INTERVAL,
00113 
00114   OPTION_ARENA_WINDOW_SIZE_X,
00115   OPTION_ARENA_WINDOW_SIZE_Y,
00116   OPTION_ARENA_WINDOW_POS_X,
00117   OPTION_ARENA_WINDOW_POS_Y,
00118   OPTION_CONTROL_WINDOW_POS_X,
00119   OPTION_CONTROL_WINDOW_POS_Y,
00120   OPTION_MESSAGE_WINDOW_SIZE_X,
00121   OPTION_MESSAGE_WINDOW_SIZE_Y,
00122   OPTION_MESSAGE_WINDOW_POS_X,
00123   OPTION_MESSAGE_WINDOW_POS_Y,
00124   OPTION_SCORE_WINDOW_SIZE_X,
00125   OPTION_SCORE_WINDOW_SIZE_Y,
00126   OPTION_SCORE_WINDOW_POS_X,
00127   OPTION_SCORE_WINDOW_POS_Y,
00128   OPTION_STATISTICS_WINDOW_SIZE_X,
00129   OPTION_STATISTICS_WINDOW_SIZE_Y,
00130 
00131   LAST_LONG_OPTION
00132 };
00133 
00134 enum option_string_t
00135 {
00136   OPTION_ROBOT_SEARCH_PATH,
00137   OPTION_ARENA_SEARCH_PATH,
00138   OPTION_TMP_RTB_DIR,
00139   LAST_STRING_OPTION
00140 };
00141 
00142 enum option_bool_t
00143 {
00144   LAST_BOOL_OPTION
00145 };
00146 
00147 enum pages_in_options_t
00148 {
00149   PAGE_ENVIRONMENT,
00150   PAGE_ROBOT,
00151   PAGE_SHOT,
00152   PAGE_EXTRAS,
00153   PAGE_TIME,
00154   PAGE_SIZE_OF_WINDOWS,
00155   PAGE_MISC,
00156   LAST_PAGE
00157 };
00158 
00159 template<class T>
00160 struct option_info_t
00161 {
00162   option_info_t() {}
00163   option_info_t(const entry_datatype_t d, const pages_in_options_t p,
00164                 const T v, const T mn, const T mx, const int l,
00165                 const bool bo, const bool lo, const String& s,
00166                 const String& t ) :
00167     datatype(d), page(p), value(v), default_value(v), min_value(mn),
00168     max_value(mx), max_letters_in_entry(l), broadcast_option(bo),
00169     log_option(lo), label(s), translated_label(t) {}
00170 
00171   option_info_t& operator=(const option_info_t& n) { 
00172     datatype=n.datatype; page=n.page; value=n.value; 
00173     default_value=n.default_value; min_value=n.min_value;
00174     max_value=n.max_value; max_letters_in_entry=n.max_letters_in_entry;
00175     broadcast_option=n.broadcast_option; log_option=n.log_option;
00176     label=n.label;translated_label=n.translated_label;
00177 #ifndef NO_GRAPHICS
00178     entry=n.entry; 
00179 #endif 
00180     return *this; }
00181 
00182   entry_datatype_t datatype;
00183   pages_in_options_t page;
00184   T value;
00185   T default_value;
00186   T min_value;
00187   T max_value;
00188   int max_letters_in_entry;
00189   bool broadcast_option;
00190   bool log_option;
00191   String label;
00192   String translated_label;
00193 #ifndef NO_GRAPHICS
00194   GtkWidget * entry;
00195 #endif
00196 };
00197 
00198 struct option_return_t
00199 {
00200   option_return_t( const entry_datatype_t d, const int n ) :
00201     datatype(d), option_number(n) {}
00202 
00203   option_return_t& operator=( const option_return_t& n )
00204     { datatype = n.datatype; option_number = n.option_number; return *this; }
00205 
00206   entry_datatype_t datatype;
00207   int option_number;
00208 };
00209 
00210 class Options
00211 {
00212 public:
00213   Options                                      ();
00214   ~Options                                     () {}
00215   //static void set_options();
00216 
00217   inline double get_d                          ( option_double_t  option )
00218     { return all_double_options[option].value; }
00219   inline long   get_l                          ( option_long_t    option )
00220     { return all_long_options[option].value; }
00221   inline const String get_s                    ( option_string_t  option )
00222     { return all_string_options[option].value.chars(); }
00223   //  inline bool get_b                        ( option_bool_t option )
00224   // { return all_bool_options[option].value; }
00225 
00226   void broadcast_opts                          ();
00227   void log_all_options                         ();
00228 
00229   void save_all_options_to_file                ( String filename,
00230                                                  const bool as_default );
00231   void get_options_from_rtbrc                  ();
00232   void read_options_file                       ( String file_string,
00233                                                  const bool as_default );
00234 
00235   option_info_t<double>* get_all_double_options() { return all_double_options; }
00236   option_info_t<long>* get_all_long_options    () { return all_long_options; }
00237   option_info_t<String>* get_all_string_options() { return all_string_options; }
00238 
00239   option_return_t get_option_from_string       ( const String& option_name );
00240 
00241 #ifndef NO_GRAPHICS
00242   OptionsWindow* get_optionswindow_p           ()
00243     { return optionswindow_p; }
00244   bool is_optionswindow_up                     ();
00245   void open_optionswindow                      ();
00246   void close_optionswindow                     ();
00247 #endif
00248 
00249 private:
00250   option_info_t<double> all_double_options[LAST_DOUBLE_OPTION];
00251   option_info_t<long> all_long_options[LAST_LONG_OPTION];
00252 
00253   option_info_t<String> all_string_options[LAST_STRING_OPTION];
00254   //  option_info_t<bool> all_bool_options[LAST_BOOL_OPTION];
00255 
00256 #ifndef NO_GRAPHICS
00257   OptionsWindow* optionswindow_p;
00258 #endif
00259 };
00260 #endif 

Generated on Fri Oct 15 15:47:37 2004 for Real Time Battle by  doxygen 1.3.9.1