Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

gameoptions.cpp

Go to the documentation of this file.
00001 
00005 /***************************************************************************
00006                           gameoptions.cpp  -  description
00007                              -------------------
00008     begin                : Thu Jun 29 2000
00009     copyright            : (C) 2000 by frank landgraf
00010     email                : 
00011  ***************************************************************************/
00012 
00013 /***************************************************************************
00014  *                                                                         *
00015  *   This program is free software; you can redistribute it and/or modify  *
00016  *   it under the terms of the GNU General Public License as published by  *
00017  *   the Free Software Foundation; either version 2 of the License, or     *
00018  *   (at your option) any later version.                                   *
00019  *                                                                         *
00020  ***************************************************************************/
00021 #include "global.h"
00022 #include "gameoptions.h"
00023 #include "basestrm.h"
00024 
00025 
00026 CGameOptions* pStaticGameOptions=NULL;
00027 
00028 class Destroyer
00029 {
00030    public:
00031       ~Destroyer()
00032       {
00033          delete pStaticGameOptions;
00034       };
00035 }
00036 destroyer;
00037 
00038 CGameOptions* CGameOptions::Instance()
00039 {
00040    if (!pStaticGameOptions)
00041       pStaticGameOptions = new CGameOptions;
00042    return pStaticGameOptions;
00043 }
00044 
00045 const int CGameOptions::maxSearchPathNum = 30;
00046 
00047 /*
00048 CGameOptions::CGameOptions( const CGameOptions& cgo )
00049 {
00050    copy ( cgo );
00051 }
00052 
00053 CGameOptions::CGameOptions(void)
00054 {
00055    setDefaults();
00056 }
00057 
00058 */
00059 
00060 const int mouseButtonNum = 6;
00061 const char* mouseButtons[mouseButtonNum] =
00062    { "none",
00063      "left",
00064      "center",
00065      "right",
00066      "4",
00067      "5" };
00068 
00069 
00070      
00071 void CGameOptions::load( const ASCString& filename )
00072 {
00073    tnfilestream s ( filename, tnstream::reading );
00074 
00075    TextFormatParser tfp ( &s );
00076    auto_ptr<TextPropertyGroup> tpg ( tfp.run());
00077    
00078    PropertyReadingContainer pc ( "config", tpg.get() );
00079  
00080    runTextIO( pc );
00081 }   
00082 
00083 void CGameOptions::save( const ASCString& filename )
00084 {
00085    tn_file_buf_stream s ( filename, tnstream::writing );
00086    PropertyWritingContainer pc ( "config", s );
00087    runTextIO( pc );
00088 }   
00089    
00090   
00091 
00092 void CGameOptions::runTextIO ( PropertyContainer& pc )
00093 {
00094    
00095    pc.addInteger("XResolution", xresolution, xresolution);
00096    pc.addInteger("YResolution", yresolution, yresolution);
00097    pc.addString("GraphicsDriver", graphicsDriver, graphicsDriver );
00098    pc.addBool("HardwareSurface", hardwareSurface, hardwareSurface );
00099 
00100    pc.addInteger("MapEditor_XResolution", mapeditor_xresolution, mapeditor_xresolution);
00101    pc.addInteger("MapEditor_YResolution", mapeditor_yresolution, mapeditor_yresolution);
00102 
00103    pc.openBracket("Sound");
00104    pc.addBool("MuteEffects", sound.muteEffects, sound.muteEffects);
00105    pc.addBool("MuteMusic", sound.muteMusic, sound.muteMusic);
00106    pc.addBool("Sound.Off", sound.off, sound.off);
00107    pc.addInteger("EffectsVolume", sound.soundVolume, sound.soundVolume );
00108    pc.addInteger("MusicVolume", sound.musicVolume, sound.musicVolume );
00109    pc.closeBracket();
00110 
00111    pc.addBool("FastMove", fastmove, fastmove);
00112    pc.addInteger("MovementSpeed", movespeed, movespeed );
00113    pc.addBool("EndTurnPrompt", endturnquestion, endturnquestion );
00114    pc.addBool("UnitsGrayAfterMove", units_gray_after_move, units_gray_after_move );
00115    pc.addInteger( "MapZoom", mapzoom, mapzoom);
00116    pc.addInteger( "MapZoomEditor", mapzoomeditor, mapzoomeditor );
00117    pc.addInteger( "AttackSpeed1", attackspeed1, 30 );
00118    pc.addInteger( "AttackSpeed2", attackspeed2, 50 );
00119    pc.addInteger( "AttackSpeed3", attackspeed3, 30 );
00120 
00121    pc.addBool( "ForceWindowedMode", forceWindowedMode, forceWindowedMode );
00122    pc.addBool( "MapeditWindowedMode", mapeditWindowedMode, mapeditWindowedMode );
00123    pc.addBool( "MapeditModalSelectionWindow", maped_modalSelectionWindow, maped_modalSelectionWindow );
00124    pc.addBool( "AutomaticTraining", automaticTraining, automaticTraining );
00125 
00126    pc.openBracket("Mouse");
00127    // add(new IntProperty("Mouse.ScrollButton"                                  ,&_pOptions->mouse.scrollbutton));
00128    pc.addNamedInteger("SelectFieldButton", mouse.fieldmarkbutton, mouseButtonNum, mouseButtons, mouse.fieldmarkbutton );
00129    // add(new IntProperty("Mouse.SmallGuiIconButton"                    ,&_pOptions->mouse.smallguibutton));
00130    // add(new IntProperty("Mouse.LargeGuiIconButton"                    ,&_pOptions->mouse.largeguibutton));
00131    // add(new IntProperty("Mouse.SmallGuiIconUnderMouse"                ,&_pOptions->mouse.smalliconundermouse ));
00132    pc.addNamedInteger("MapCenterButton", mouse.centerbutton, mouseButtonNum, mouseButtons, mouse.centerbutton );
00133    pc.addNamedInteger("DragNdrop", mouse.dragndropbutton, mouseButtonNum, mouseButtons, mouse.dragndropbutton );
00134    pc.addNamedInteger("ZoomOut", mouse.zoomoutbutton, mouseButtonNum, mouseButtons, mouse.zoomoutbutton );
00135    pc.addNamedInteger("ZoomIn", mouse.zoominbutton, mouseButtonNum, mouseButtons, mouse.zoominbutton );
00136    // add(new IntProperty("Mouse.UnitWeaponInfoButton"          ,&_pOptions->mouse.unitweaponinfo));
00137    pc.addBool("SingleClickAction", mouse.singleClickAction, false );
00138    // add(new IntProperty("Mouse.dragndropmovement"             ,&_pOptions->mouse.dragndropmovement));
00139    pc.addBool("HideOnScreenUpdates",hideMouseOnScreenUpdates, hideMouseOnScreenUpdates );
00140    pc.closeBracket();
00141 
00142    pc.addBool("AmmoProductionOnRefuelling", autoproduceammunition, autoproduceammunition );
00143    // pc.addInteger("FillUnitsAutomatically", container.filleverything, container.filleverything );
00144 
00145    // pc.addInteger("ToolTipHelpDelay", onlinehelptime, onlinehelptime );
00146    // add(new IntProperty("SmallGuiIconOpensAfterMove"  ,       &_pOptions->smallguiiconopenaftermove));
00147    pc.addString("DefaultPassword", defaultPassword, defaultPassword );
00148    pc.addString("DefaultSupervisorPassword", defaultSuperVisorPassword, defaultSuperVisorPassword );
00149    pc.addInteger("ReplayDelay", replayspeed, replayspeed );
00150    // add(new IntProperty("ShowUnitOwner"                ,  &_pOptions->showUnitOwner));
00151    pc.addString("StartupMap", startupMap, startupMap );
00152    pc.addBool("DebugReplay", debugReplay, debugReplay );
00153 
00154    pc.addString("BI3.path", BI3directory, BI3directory );
00155 
00156    pc.openBracket("UnitProduction");
00157    pc.addBool("fillResources", unitProduction.fillResources, true );
00158    pc.addBool("fillAmmo", unitProduction.fillAmmo, true );
00159    pc.closeBracket();
00160    
00161    pc.openBracket("replayVideo");
00162    pc.addInteger("FrameRate", video.framerate, video.framerate );
00163    pc.addInteger("Quality", video.quality, video.quality);
00164    pc.closeBracket();
00165    
00166    if ( !pc.isReading() || pc.find("VisibleMapLayer" ))
00167       pc.addStringArray("VisibleMapLayer", visibleMapLayer );
00168 
00169 
00170    pc.openBracket("PBEMServer");
00171    pc.addString("hostname", pbemServer.hostname, pbemServer.hostname );
00172    pc.addString("username", pbemServer.username, pbemServer.username );
00173    pc.addInteger("port", pbemServer.port, pbemServer.port );
00174    pc.closeBracket();
00175 
00176    /*
00177    add(new IntProperty("BI3.interpolate.terrain"                ,       &_pOptions->bi3.interpolate.terrain));
00178    add(new IntProperty("BI3.interpolate.units"                  ,       &_pOptions->bi3.interpolate.units));
00179    add(new IntProperty("BI3.interpolate.objects"                ,       &_pOptions->bi3.interpolate.objects));
00180    add(new IntProperty("BI3.interpolate.buildings"              ,       &_pOptions->bi3.interpolate.buildings));
00181 */
00182 
00183    int spn = 0;
00184 
00185    if ( pc.isReading() ) 
00186       pc.addInteger("SearchPathNum", spn, 0 );
00187    else {
00188       pc.addInteger("SearchPathNum", searchPathNum, 0 );
00189       spn = searchPathNum;
00190    }   
00191    
00192          
00193    for ( int i = 0; i < min(spn, 30); ++i )
00194       pc.addString(ASCString("SearchPath") + strrr(i), searchPath[i] );
00195       
00196    searchPathNum = spn;   
00197 
00198 
00199    pc.addBool( "cacheASCGUI", cacheASCGUI, cacheASCGUI );
00200 
00201 
00202    vector<ASCString> panels;
00203    if ( pc.isReading() ) {
00204       if ( pc.find( "Panels"))
00205          pc.addStringArray( "Panels", panels );
00206    } else {
00207       for ( PanelDataContainer::iterator i = panelData.begin(); i != panelData.end(); ++i )
00208          panels.push_back( i->first );
00209       pc.addStringArray( "Panels", panels );
00210    }
00211 
00212    for ( vector<ASCString>::iterator i = panels.begin(); i != panels.end(); ++i ){
00213       PanelData& pd = panelData[*i];
00214       pc.openBracket( *i );
00215       pc.addInteger( "x", pd.x );
00216       pc.addInteger( "y", pd.y );
00217       pc.addBool( "active", pd.visible );
00218       pc.closeBracket();
00219    }
00220 
00221    pc.addInteger( "PanelColumns", panelColumns, 2 );
00222      
00223    pc.addString("mailProgram", mailProgram, "");
00224      
00225 }
00226 
00227 CGameOptions::CGameOptions()
00228 {
00229    setDefaults();
00230 }   
00231 
00232 
00233 void CGameOptions::setDefaults ( void )
00234 {
00235    hideMouseOnScreenUpdates = true;
00236    forceWindowedMode = false;
00237    mapeditWindowedMode = true;
00238    maped_modalSelectionWindow = true;
00239    fastmove = true;
00240    movespeed=15;
00241    endturnquestion=false;
00242    // smallmapactive=1;
00243    units_gray_after_move=false;
00244    mapzoom=75;
00245    mapzoomeditor=60;
00246    // startupcount=0;
00247    // dontMarkFieldsNotAccessible_movement=0;
00248    
00249    attackspeed1=30;
00250    attackspeed2=50;
00251    attackspeed3=30;
00252    
00253    sound.off=false;
00254    sound.muteEffects=false;
00255    sound.muteMusic=false;
00256    sound.soundVolume=100;
00257    sound.musicVolume=100;
00258 
00259    // mouse.scrollbutton=0;
00260    mouse.fieldmarkbutton=1;
00261    // mouse.smallguibutton=1;
00262    // mouse.largeguibutton=0;
00263    //mouse.smalliconundermouse=2;  // 0: nie=0;  1: immer=0; 2: nur wenn vehicle, gebude, oder temp unter MAUS
00264    mouse.centerbutton=2;    // Maustaste zum zentrieren des fielder, ?ber dem sich die Maus befindet=0;
00265    mouse.dragndropbutton = 3;
00266    mouse.zoomoutbutton = 4;
00267    mouse.zoominbutton = 5;
00268    mouse.singleClickAction = false;
00269 
00270    replayspeed=0;
00271    debugReplay = 0;
00272 
00273    autoproduceammunition = false;
00274 /*
00275    bi3.dir.setName( NULL );
00276    bi3.interpolate.terrain=0;
00277    bi3.interpolate.units=0;
00278    bi3.interpolate.objects=0;
00279    bi3.interpolate.buildings=0;
00280    */
00281 
00282    // defaultSuperVisorPassword.setName ( "" );
00283    startupMap =  "asc001.map";
00284 
00285    cacheASCGUI = true;
00286 
00287    setDefaultDirectories();
00288 
00289    xresolution = 1024;
00290    yresolution = 768;
00291 
00292    mapeditor_xresolution = 1024;
00293    mapeditor_yresolution = 740;
00294 
00295    graphicsDriver = "default";
00296    hardwareSurface = false;
00297 
00298    automaticTraining = true;
00299 
00300    replayMovieMode = false;
00301 
00302    unitProduction.fillAmmo = true;
00303    unitProduction.fillResources = true;
00304 
00305    video.quality = 100;
00306    video.framerate = 15;
00307    
00308    panelColumns = 2;
00309 
00310    pbemServer.username="";
00311    pbemServer.port = 8080;
00312    pbemServer.hostname="terdon.asc-hq.org";
00313 
00314    setChanged();
00315 }
00316 
00317 
00318 void CGameOptions::setDefaultDirectories()
00319 {
00320 #if USE_HOME_DIRECTORY == 0
00321 
00322    searchPathNum = 1;
00323    searchPath[0] =  ".\\" ;
00324 #else
00325 
00326    searchPathNum = 6;
00327    
00328    searchPath[0] =  "~/.asc/" ;
00329    searchPath[1] = GAME_DATADIR ;
00330    searchPath[2] = "/var/local/games/asc/" ;
00331    searchPath[3] = "/var/games/asc/" ;
00332    searchPath[4] = "/usr/local/share/games/asc/" ;
00333    searchPath[5] =  "/usr/share/games/asc/" ;
00334 #endif
00335 
00336 }
00337 
00338 ASCString CGameOptions::Mouse::getButtonName(int button)
00339 {
00340    static const char* my_mouseButtonNames[] = { "None", "Left", "Center", "Right", "4", "5", NULL };
00341    if ( button <= 3 ) 
00342       return my_mouseButtonNames[button];
00343    else
00344       return ASCString::toString( button );
00345 }
00346 
00347 
00348 /*
00349 void CGameOptions::copy ( const CGameOptions& cgo )
00350 {
00351    fastmove              = cgo.fastmove;
00352    movespeed             = cgo.movespeed;
00353    endturnquestion       = cgo.endturnquestion;
00354    smallmapactive        = cgo.smallmapactive;
00355    units_gray_after_move = cgo.units_gray_after_move;
00356    mapzoom               = cgo.mapzoom;
00357    mapzoomeditor         = cgo.mapzoomeditor;
00358    startupcount          = cgo.startupcount;
00359    debugReplay           = cgo.debugReplay;
00360    // dontMarkFieldsNotAccessible_movement=cgo.dontMarkFieldsNotAccessible_movement;
00361    attackspeed1          = cgo.attackspeed1;
00362    attackspeed2          = cgo.attackspeed2;
00363    attackspeed3          = cgo.attackspeed3;
00364    sound.off             = cgo.sound.off;
00365    sound.muteEffects     = cgo.sound.muteEffects;
00366    sound.muteMusic       = cgo.sound.muteMusic;
00367    sound.soundVolume     = cgo.sound.soundVolume;
00368    sound.musicVolume     = cgo.sound.musicVolume;
00369 
00370    mouse.scrollbutton    = cgo.mouse.scrollbutton;
00371    mouse.fieldmarkbutton = cgo.mouse.fieldmarkbutton;
00372    mouse.smallguibutton  = cgo.mouse.smallguibutton;
00373    mouse.largeguibutton  = cgo.mouse.largeguibutton;
00374    mouse.smalliconundermouse = cgo.mouse.smalliconundermouse;
00375    mouse.centerbutton    = cgo.mouse.centerbutton;
00376    mouse.unitweaponinfo  = cgo.mouse.unitweaponinfo;
00377    mouse.dragndropmovement=cgo.mouse.dragndropmovement;
00378    mouse.singleClickAction=cgo.mouse.singleClickAction;
00379 
00380    container.autoproduceammunition = cgo.container.autoproduceammunition;
00381    container.filleverything = cgo.container.filleverything;
00382 
00383    onlinehelptime            = cgo.onlinehelptime;
00384    smallguiiconopenaftermove = cgo.smallguiiconopenaftermove;
00385    defaultPassword           = cgo.defaultPassword;
00386    defaultSuperVisorPassword = cgo.defaultSuperVisorPassword;
00387 
00388    replayspeed               = cgo.replayspeed;
00389    showUnitOwner             = cgo.showUnitOwner;
00390 
00391    xresolution               = cgo.xresolution;
00392    yresolution               = cgo.yresolution;
00393    automaticTraining         = cgo.automaticTraining;
00394 
00395    bi3.dir.setName( cgo.bi3.dir.getName() );
00396    bi3.interpolate.terrain = cgo.bi3.interpolate.terrain;
00397    bi3.interpolate.units   = cgo.bi3.interpolate.units;
00398    bi3.interpolate.objects = cgo.bi3.interpolate.objects;
00399    bi3.interpolate.buildings = cgo.bi3.interpolate.buildings;
00400    for ( int i = 0; i < getSearchPathNum(); i++ )
00401       searchPath[i].setName ( cgo.searchPath[i].getName() );
00402 
00403    startupMap = cgo.startupMap;
00404    setChanged();
00405 }
00406 */
00407 
00408 int CGameOptions :: getSearchPathNum ( void )
00409 {
00410    return searchPathNum;
00411 }
00412 
00413 void  CGameOptions ::  setSearchPath ( int i, const ASCString& path )
00414 {
00415    searchPath[i] = path;
00416 }
00417 
00418 void  CGameOptions ::  addSearchPath ( const ASCString& path )
00419 {
00420    setSearchPath( searchPathNum++, path );
00421 }
00422 
00423 ASCString CGameOptions :: getSearchPath( int i)
00424 {
00425    return searchPath[i];
00426 }   
00427 
00428 
00429 
00430 Password CGameOptions :: getDefaultPassword ( )
00431 {
00432    Password pwd;
00433    if ( !defaultPassword.empty() )
00434       pwd.setEncoded ( defaultPassword );
00435 
00436    return pwd;
00437 }
00438 
00439 
00440 Password CGameOptions :: getDefaultSupervisorPassword ( )
00441 {
00442    Password pwd;
00443    if ( !defaultSuperVisorPassword.empty() )
00444       pwd.setEncoded ( defaultSuperVisorPassword );
00445 
00446    return pwd;
00447 }
00448 
00449 void CGameOptions :: updatePanelData( const ASCString& name, PanelData data )
00450 {
00451    panelData[name] = data;
00452    setChanged();
00453 }
00454 
00455 bool CGameOptions :: getPanelData( const ASCString& name, PanelData& data )
00456 {
00457    if ( panelData.find( name ) != panelData.end() ) {
00458       data = panelData[name];
00459       return true;
00460    } else
00461       return false;
00462 }
00463 

Generated on Tue Jun 24 01:27:43 2008 for Advanced Strategic Command by  doxygen 1.4.2