00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00049
00050
00051
00052
00053
00054
00055
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.addInteger("ReplayMoveSpeedFactor", replayMoveSpeedFactor, replayMoveSpeedFactor );
00114 pc.addBool("EndTurnPrompt", endturnquestion, endturnquestion );
00115 pc.addBool("UnitsGrayAfterMove", units_gray_after_move, units_gray_after_move );
00116 pc.addInteger( "MapZoom", mapzoom, mapzoom);
00117 pc.addInteger( "MapZoomEditor", mapzoomeditor, mapzoomeditor );
00118 pc.addInteger( "AttackSpeed1", attackspeed1, 30 );
00119 pc.addInteger( "AttackSpeed2", attackspeed2, 50 );
00120 pc.addInteger( "AttackSpeed3", attackspeed3, 30 );
00121
00122 pc.addBool( "ForceWindowedMode", forceWindowedMode, forceWindowedMode );
00123 pc.addBool( "MapeditWindowedMode", mapeditWindowedMode, mapeditWindowedMode );
00124 pc.addBool( "MapeditModalSelectionWindow", maped_modalSelectionWindow, maped_modalSelectionWindow );
00125 pc.addBool( "AutomaticTraining", automaticTraining, automaticTraining );
00126
00127 pc.openBracket("Mouse");
00128
00129 pc.addNamedInteger("SelectFieldButton", mouse.fieldmarkbutton, mouseButtonNum, mouseButtons, mouse.fieldmarkbutton );
00130
00131
00132
00133 pc.addNamedInteger("MapCenterButton", mouse.centerbutton, mouseButtonNum, mouseButtons, mouse.centerbutton );
00134 pc.addNamedInteger("DragNdrop", mouse.dragndropbutton, mouseButtonNum, mouseButtons, mouse.dragndropbutton );
00135 pc.addNamedInteger("ZoomOut", mouse.zoomoutbutton, mouseButtonNum, mouseButtons, mouse.zoomoutbutton );
00136 pc.addNamedInteger("ZoomIn", mouse.zoominbutton, mouseButtonNum, mouseButtons, mouse.zoominbutton );
00137
00138 pc.addBool("SingleClickAction", mouse.singleClickAction, false );
00139
00140 pc.addBool("HideOnScreenUpdates",hideMouseOnScreenUpdates, hideMouseOnScreenUpdates );
00141 pc.closeBracket();
00142
00143 pc.addBool("AmmoProductionOnRefuelling", autoproduceammunition, autoproduceammunition );
00144
00145
00146
00147
00148 pc.addString("DefaultPassword", defaultPassword, defaultPassword );
00149 pc.addString("DefaultSupervisorPassword", defaultSuperVisorPassword, defaultSuperVisorPassword );
00150 pc.addInteger("ReplayDelay", replayspeed, replayspeed );
00151
00152 pc.addString("StartupMap", startupMap, startupMap );
00153 pc.addBool("DebugReplay", debugReplay, debugReplay );
00154 pc.addBool("RecordCampaignMaps", recordCampaignMaps, recordCampaignMaps );
00155
00156 pc.addString("BI3.path", BI3directory, BI3directory );
00157
00158 pc.openBracket("UnitProduction");
00159 pc.addBool("fillResources", unitProduction.fillResources, true );
00160 pc.addBool("fillAmmo", unitProduction.fillAmmo, true );
00161 pc.closeBracket();
00162
00163 pc.openBracket("replayVideo");
00164 pc.addInteger("FrameRate", video.framerate, video.framerate );
00165 pc.addInteger("ASCFrameRateLimit", video.ascframeratelimit, video.ascframeratelimit );
00166 pc.addInteger("Quality", video.quality, video.quality);
00167 pc.closeBracket();
00168
00169 if ( !pc.isReading() || pc.find("VisibleMapLayer" ))
00170 pc.addStringArray("VisibleMapLayer", visibleMapLayer );
00171
00172
00173 pc.openBracket("PBEMServer");
00174 pc.addString("hostname", pbemServer.hostname, pbemServer.hostname );
00175 pc.addString("username", pbemServer.username, pbemServer.username );
00176 pc.addInteger("port", pbemServer.port, pbemServer.port );
00177 pc.closeBracket();
00178
00179
00180
00181
00182
00183
00184
00185
00186 int spn = 0;
00187
00188 if ( pc.isReading() )
00189 pc.addInteger("SearchPathNum", spn, 0 );
00190 else {
00191 pc.addInteger("SearchPathNum", searchPathNum, 0 );
00192 spn = searchPathNum;
00193 }
00194
00195
00196 for ( int i = 0; i < min(spn, 30); ++i )
00197 pc.addString(ASCString("SearchPath") + strrr(i), searchPath[i] );
00198
00199 searchPathNum = spn;
00200
00201
00202 pc.addBool( "cacheASCGUI", cacheASCGUI, cacheASCGUI );
00203
00204
00205 vector<ASCString> panels;
00206 if ( pc.isReading() ) {
00207 if ( pc.find( "Panels"))
00208 pc.addStringArray( "Panels", panels );
00209 } else {
00210 for ( PanelDataContainer::iterator i = panelData.begin(); i != panelData.end(); ++i )
00211 panels.push_back( i->first );
00212 pc.addStringArray( "Panels", panels );
00213 }
00214
00215 for ( vector<ASCString>::iterator i = panels.begin(); i != panels.end(); ++i ){
00216 PanelData& pd = panelData[*i];
00217 pc.openBracket( *i );
00218 pc.addInteger( "x", pd.x );
00219 pc.addInteger( "y", pd.y );
00220 pc.addBool( "active", pd.visible );
00221 pc.closeBracket();
00222 }
00223
00224
00225 pc.openBracket("DialogMemory");
00226 vector<ASCString> dialogMemory;
00227 if ( pc.isReading() ) {
00228 if ( pc.find( "dialogs"))
00229 pc.addStringArray( "dialogs", dialogMemory );
00230 } else {
00231 for ( DialogAnswers::iterator i = dialogAnswers.begin(); i != dialogAnswers.end(); ++i )
00232 dialogMemory.push_back( i->first );
00233 pc.addStringArray( "dialogs", dialogMemory );
00234 }
00235
00236 for ( vector<ASCString>::iterator i = dialogMemory.begin(); i != dialogMemory.end(); ++i ) {
00237 int& value = dialogAnswers[*i];
00238 pc.addInteger( *i, value );
00239 }
00240
00241 pc.closeBracket();
00242
00243 pc.addInteger( "PanelColumns", panelColumns, 2 );
00244
00245 pc.addString("mailProgram", mailProgram, "");
00246
00247 pc.addInteger( "AircraftCrashWarnTime", aircraftCrashWarningTime, 1 );
00248
00249 pc.addBool("SaveEventMessagesExternal", saveEventMessagesExternal, false );
00250 pc.addString("LanguageOverride", languageOverride, "" );
00251
00252 pc.addBool("LogKillsToConsole", logKillsToConsole, false );
00253 }
00254
00255 CGameOptions::CGameOptions()
00256 {
00257 setDefaults();
00258 }
00259
00260
00261 void CGameOptions::setDefaults ( void )
00262 {
00263 hideMouseOnScreenUpdates = true;
00264 forceWindowedMode = false;
00265 mapeditWindowedMode = true;
00266 maped_modalSelectionWindow = true;
00267 fastmove = true;
00268 movespeed=15;
00269 endturnquestion=false;
00270
00271 units_gray_after_move=false;
00272 mapzoom=100;
00273 mapzoomeditor=60;
00274
00275
00276
00277 attackspeed1=30;
00278 attackspeed2=50;
00279 attackspeed3=30;
00280
00281 sound.off=false;
00282 sound.muteEffects=false;
00283 sound.muteMusic=false;
00284 sound.soundVolume=100;
00285 sound.musicVolume=100;
00286
00287
00288 mouse.fieldmarkbutton=1;
00289
00290
00291
00292 mouse.centerbutton=2;
00293 mouse.dragndropbutton = 3;
00294 mouse.zoomoutbutton = 4;
00295 mouse.zoominbutton = 5;
00296 mouse.singleClickAction = false;
00297
00298 replayspeed=0;
00299 debugReplay = 0;
00300
00301 autoproduceammunition = true;
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311 startupMap = "asc001.map";
00312
00313 cacheASCGUI = true;
00314
00315 setDefaultDirectories();
00316
00317 xresolution = -1;
00318 yresolution = -1;
00319
00320 mapeditor_xresolution = 1024;
00321 mapeditor_yresolution = 740;
00322
00323 graphicsDriver = "default";
00324 hardwareSurface = false;
00325
00326 automaticTraining = true;
00327
00328 replayMovieMode = false;
00329
00330 unitProduction.fillAmmo = true;
00331 unitProduction.fillResources = true;
00332
00333 video.quality = 100;
00334 video.framerate = 15;
00335 video.ascframeratelimit = 30;
00336
00337 panelColumns = 2;
00338
00339 pbemServer.username="";
00340 pbemServer.port = 8080;
00341 pbemServer.hostname="terdon.asc-hq.org";
00342
00343 aircraftCrashWarningTime = 1;
00344 recordCampaignMaps = false;
00345
00346 saveEventMessagesExternal = false;
00347
00348 replayMoveSpeedFactor= 150;
00349
00350 logKillsToConsole = false;
00351
00352 setChanged();
00353 }
00354
00355
00356 void CGameOptions::setDefaultDirectories()
00357 {
00358 #if USE_HOME_DIRECTORY == 0
00359
00360 searchPathNum = 1;
00361 searchPath[0] = ".\\" ;
00362 #else
00363
00364 searchPathNum = 6;
00365
00366 searchPath[0] = "~/.asc/" ;
00367 searchPath[1] = GAME_DATADIR ;
00368 searchPath[2] = "/var/local/games/asc/" ;
00369 searchPath[3] = "/var/games/asc/" ;
00370 searchPath[4] = "/usr/local/share/games/asc/" ;
00371 searchPath[5] = "/usr/share/games/asc/" ;
00372 #endif
00373
00374 }
00375
00376 ASCString CGameOptions::Mouse::getButtonName(int button)
00377 {
00378 static const char* my_mouseButtonNames[] = { "None", "Left", "Center", "Right", "4", "5", NULL };
00379 if ( button <= 3 )
00380 return my_mouseButtonNames[button];
00381 else
00382 return ASCString::toString( button );
00383 }
00384
00385
00386 int CGameOptions :: getSearchPathNum ( void )
00387 {
00388 return searchPathNum;
00389 }
00390
00391 void CGameOptions :: setSearchPath ( int i, const ASCString& path )
00392 {
00393 searchPath[i] = path;
00394 }
00395
00396 void CGameOptions :: addSearchPath ( const ASCString& path )
00397 {
00398 setSearchPath( searchPathNum++, path );
00399 }
00400
00401 ASCString CGameOptions :: getSearchPath( int i)
00402 {
00403 return searchPath[i];
00404 }
00405
00406
00407
00408 Password CGameOptions :: getDefaultPassword ( )
00409 {
00410 Password pwd;
00411 if ( !defaultPassword.empty() )
00412 pwd.setEncoded ( defaultPassword );
00413
00414 return pwd;
00415 }
00416
00417
00418 Password CGameOptions :: getDefaultSupervisorPassword ( )
00419 {
00420 Password pwd;
00421 if ( !defaultSuperVisorPassword.empty() )
00422 pwd.setEncoded ( defaultSuperVisorPassword );
00423
00424 return pwd;
00425 }
00426
00427 void CGameOptions :: updatePanelData( const ASCString& name, PanelData data )
00428 {
00429 panelData[name] = data;
00430 setChanged();
00431 }
00432
00433 bool CGameOptions :: getPanelData( const ASCString& name, PanelData& data )
00434 {
00435 if ( panelData.find( name ) != panelData.end() ) {
00436 data = panelData[name];
00437 return true;
00438 } else
00439 return false;
00440 }
00441