Advanced Strategic Command
gameoptions.cpp
Go to the documentation of this file.
1 
5 /***************************************************************************
6  gameoptions.cpp - description
7  -------------------
8  begin : Thu Jun 29 2000
9  copyright : (C) 2000 by frank landgraf
10  email :
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 #include "global.h"
22 #include "gameoptions.h"
23 #include "basestrm.h"
24 
25 
27 
28 class Destroyer
29 {
30  public:
32  {
33  delete pStaticGameOptions;
34  };
35 }
36 destroyer;
37 
39 {
40  if (!pStaticGameOptions)
41  pStaticGameOptions = new CGameOptions;
42  return pStaticGameOptions;
43 }
44 
45 const int CGameOptions::maxSearchPathNum = 30;
46 
47 /*
48 CGameOptions::CGameOptions( const CGameOptions& cgo )
49 {
50  copy ( cgo );
51 }
52 
53 CGameOptions::CGameOptions(void)
54 {
55  setDefaults();
56 }
57 
58 */
59 
60 const int mouseButtonNum = 6;
62  { "none",
63  "left",
64  "center",
65  "right",
66  "4",
67  "5" };
68 
69 
70 
71 void CGameOptions::load( const ASCString& filename )
72 {
73  tnfilestream s ( filename, tnstream::reading );
74 
75  TextFormatParser tfp ( &s );
76  auto_ptr<TextPropertyGroup> tpg ( tfp.run());
77 
78  PropertyReadingContainer pc ( "config", tpg.get() );
79 
80  runTextIO( pc );
81 }
82 
83 void CGameOptions::save( const ASCString& filename )
84 {
85  tn_file_buf_stream s ( filename, tnstream::writing );
86  PropertyWritingContainer pc ( "config", s );
87  runTextIO( pc );
88 }
89 
90 
91 
93 {
94 
95  pc.addInteger("XResolution", xresolution, xresolution);
96  pc.addInteger("YResolution", yresolution, yresolution);
97  pc.addString("GraphicsDriver", graphicsDriver, graphicsDriver );
98  pc.addBool("HardwareSurface", hardwareSurface, hardwareSurface );
99 
100  pc.addInteger("MapEditor_XResolution", mapeditor_xresolution, mapeditor_xresolution);
101  pc.addInteger("MapEditor_YResolution", mapeditor_yresolution, mapeditor_yresolution);
102 
103  pc.openBracket("Sound");
104  pc.addBool("MuteEffects", sound.muteEffects, sound.muteEffects);
105  pc.addBool("MuteMusic", sound.muteMusic, sound.muteMusic);
106  pc.addBool("Sound.Off", sound.off, sound.off);
107  pc.addInteger("EffectsVolume", sound.soundVolume, sound.soundVolume );
108  pc.addInteger("MusicVolume", sound.musicVolume, sound.musicVolume );
109  pc.closeBracket();
110 
111  pc.addBool("FastMove", fastmove, fastmove);
112  pc.addInteger("MovementSpeed", movespeed, movespeed );
113  pc.addInteger("ReplayMoveSpeedFactor", replayMoveSpeedFactor, replayMoveSpeedFactor );
114  pc.addBool("EndTurnPrompt", endturnquestion, endturnquestion );
115  pc.addBool("UnitsGrayAfterMove", units_gray_after_move, units_gray_after_move );
116  pc.addInteger( "MapZoom", mapzoom, mapzoom);
117  pc.addInteger( "MapZoomEditor", mapzoomeditor, mapzoomeditor );
118  pc.addInteger( "AttackSpeed1", attackspeed1, 30 );
119  pc.addInteger( "AttackSpeed2", attackspeed2, 50 );
120  pc.addInteger( "AttackSpeed3", attackspeed3, 30 );
121 
122  pc.addBool( "ForceWindowedMode", forceWindowedMode, forceWindowedMode );
123  pc.addBool( "MapeditWindowedMode", mapeditWindowedMode, mapeditWindowedMode );
124  pc.addBool( "MapeditModalSelectionWindow", maped_modalSelectionWindow, maped_modalSelectionWindow );
125  pc.addBool( "AutomaticTraining", automaticTraining, automaticTraining );
126 
127  pc.openBracket("Mouse");
128  // add(new IntProperty("Mouse.ScrollButton" ,&_pOptions->mouse.scrollbutton));
130  // add(new IntProperty("Mouse.SmallGuiIconButton" ,&_pOptions->mouse.smallguibutton));
131  // add(new IntProperty("Mouse.LargeGuiIconButton" ,&_pOptions->mouse.largeguibutton));
132  // add(new IntProperty("Mouse.SmallGuiIconUnderMouse" ,&_pOptions->mouse.smalliconundermouse ));
137  // add(new IntProperty("Mouse.UnitWeaponInfoButton" ,&_pOptions->mouse.unitweaponinfo));
138  pc.addBool("SingleClickAction", mouse.singleClickAction, false );
139  // add(new IntProperty("Mouse.dragndropmovement" ,&_pOptions->mouse.dragndropmovement));
140  pc.addBool("HideOnScreenUpdates",hideMouseOnScreenUpdates, hideMouseOnScreenUpdates );
141  pc.closeBracket();
142 
143  pc.addBool("AmmoProductionOnRefuelling", autoproduceammunition, autoproduceammunition );
144  // pc.addInteger("FillUnitsAutomatically", container.filleverything, container.filleverything );
145 
146  // pc.addInteger("ToolTipHelpDelay", onlinehelptime, onlinehelptime );
147  // add(new IntProperty("SmallGuiIconOpensAfterMove" , &_pOptions->smallguiiconopenaftermove));
148  pc.addString("DefaultPassword", defaultPassword, defaultPassword );
149  pc.addString("DefaultSupervisorPassword", defaultSuperVisorPassword, defaultSuperVisorPassword );
150  pc.addInteger("ReplayDelay", replayspeed, replayspeed );
151  // add(new IntProperty("ShowUnitOwner" , &_pOptions->showUnitOwner));
152  pc.addString("StartupMap", startupMap, startupMap );
153  pc.addBool("DebugReplay", debugReplay, debugReplay );
154  pc.addBool("RecordCampaignMaps", recordCampaignMaps, recordCampaignMaps );
155 
156  pc.addString("BI3.path", BI3directory, BI3directory );
157 
158  pc.openBracket("UnitProduction");
159  pc.addBool("fillResources", unitProduction.fillResources, true );
160  pc.addBool("fillAmmo", unitProduction.fillAmmo, true );
161  pc.closeBracket();
162 
163  pc.openBracket("replayVideo");
164  pc.addInteger("FrameRate", video.framerate, video.framerate );
165  pc.addInteger("ASCFrameRateLimit", video.ascframeratelimit, video.ascframeratelimit );
166  pc.addInteger("Quality", video.quality, video.quality);
167  pc.closeBracket();
168 
169  if ( !pc.isReading() || pc.find("VisibleMapLayer" ))
170  pc.addStringArray("VisibleMapLayer", visibleMapLayer );
171 
172 
173  pc.openBracket("PBEMServer");
174  pc.addString("hostname", pbemServer.hostname, pbemServer.hostname );
175  pc.addString("username", pbemServer.username, pbemServer.username );
176  pc.addInteger("port", pbemServer.port, pbemServer.port );
177  pc.closeBracket();
178 
179  /*
180  add(new IntProperty("BI3.interpolate.terrain" , &_pOptions->bi3.interpolate.terrain));
181  add(new IntProperty("BI3.interpolate.units" , &_pOptions->bi3.interpolate.units));
182  add(new IntProperty("BI3.interpolate.objects" , &_pOptions->bi3.interpolate.objects));
183  add(new IntProperty("BI3.interpolate.buildings" , &_pOptions->bi3.interpolate.buildings));
184 */
185 
186  int spn = 0;
187 
188  if ( pc.isReading() )
189  pc.addInteger("SearchPathNum", spn, 0 );
190  else {
191  pc.addInteger("SearchPathNum", searchPathNum, 0 );
192  spn = searchPathNum;
193  }
194 
195 
196  for ( int i = 0; i < min(spn, 30); ++i )
197  pc.addString(ASCString("SearchPath") + strrr(i), searchPath[i] );
198 
199  searchPathNum = spn;
200 
201 
202  pc.addBool( "cacheASCGUI", cacheASCGUI, cacheASCGUI );
203 
204 
205  vector<ASCString> panels;
206  if ( pc.isReading() ) {
207  if ( pc.find( "Panels"))
208  pc.addStringArray( "Panels", panels );
209  } else {
210  for ( PanelDataContainer::iterator i = panelData.begin(); i != panelData.end(); ++i )
211  panels.push_back( i->first );
212  pc.addStringArray( "Panels", panels );
213  }
214 
215  for ( vector<ASCString>::iterator i = panels.begin(); i != panels.end(); ++i ){
216  PanelData& pd = panelData[*i];
217  pc.openBracket( *i );
218  pc.addInteger( "x", pd.x );
219  pc.addInteger( "y", pd.y );
220  pc.addBool( "active", pd.visible );
221  pc.closeBracket();
222  }
223 
224 
225  pc.openBracket("DialogMemory");
226  vector<ASCString> dialogMemory;
227  if ( pc.isReading() ) {
228  if ( pc.find( "dialogs"))
229  pc.addStringArray( "dialogs", dialogMemory );
230  } else {
231  for ( DialogAnswers::iterator i = dialogAnswers.begin(); i != dialogAnswers.end(); ++i )
232  dialogMemory.push_back( i->first );
233  pc.addStringArray( "dialogs", dialogMemory );
234  }
235 
236  for ( vector<ASCString>::iterator i = dialogMemory.begin(); i != dialogMemory.end(); ++i ) {
237  int& value = dialogAnswers[*i];
238  pc.addInteger( *i, value );
239  }
240 
241  pc.closeBracket();
242 
243  pc.addInteger( "PanelColumns", panelColumns, 2 );
244 
245  pc.addString("mailProgram", mailProgram, "");
246 
247  pc.addInteger( "AircraftCrashWarnTime", aircraftCrashWarningTime, 1 );
248 
249  pc.addBool("SaveEventMessagesExternal", saveEventMessagesExternal, false );
250  pc.addString("LanguageOverride", languageOverride, "" );
251 
252  pc.addBool("LogKillsToConsole", logKillsToConsole, false );
253 }
254 
256 {
257  setDefaults();
258 }
259 
260 
262 {
264  forceWindowedMode = false;
265  mapeditWindowedMode = true;
267  fastmove = true;
268  movespeed=15;
269  endturnquestion=false;
270  // smallmapactive=1;
271  units_gray_after_move=false;
272  mapzoom=100;
273  mapzoomeditor=60;
274  // startupcount=0;
275  // dontMarkFieldsNotAccessible_movement=0;
276 
277  attackspeed1=30;
278  attackspeed2=50;
279  attackspeed3=30;
280 
281  sound.off=false;
282  sound.muteEffects=false;
283  sound.muteMusic=false;
284  sound.soundVolume=100;
285  sound.musicVolume=100;
286 
287  // mouse.scrollbutton=0;
289  // mouse.smallguibutton=1;
290  // mouse.largeguibutton=0;
291  //mouse.smalliconundermouse=2; // 0: nie=0; 1: immer=0; 2: nur wenn vehicle, gebude, oder temp unter MAUS
292  mouse.centerbutton=2; // Maustaste zum zentrieren des fielder, ?ber dem sich die Maus befindet=0;
294  mouse.zoomoutbutton = 4;
295  mouse.zoominbutton = 5;
296  mouse.singleClickAction = false;
297 
298  replayspeed=0;
299  debugReplay = 0;
300 
301  autoproduceammunition = true;
302 /*
303  bi3.dir.setName( NULL );
304  bi3.interpolate.terrain=0;
305  bi3.interpolate.units=0;
306  bi3.interpolate.objects=0;
307  bi3.interpolate.buildings=0;
308  */
309 
310  // defaultSuperVisorPassword.setName ( "" );
311  startupMap = "asc001.map";
312 
313  cacheASCGUI = true;
314 
316 
317  xresolution = -1;
318  yresolution = -1;
319 
320  mapeditor_xresolution = 1024;
321  mapeditor_yresolution = 740;
322 
323  graphicsDriver = "default";
324  hardwareSurface = false;
325 
326  automaticTraining = true;
327 
328  replayMovieMode = false;
329 
330  unitProduction.fillAmmo = true;
331  unitProduction.fillResources = true;
332 
333  video.quality = 100;
334  video.framerate = 15;
335  video.ascframeratelimit = 30;
336 
337  panelColumns = 2;
338 
339  pbemServer.username="";
340  pbemServer.port = 8080;
341  pbemServer.hostname="terdon.asc-hq.org";
342 
344  recordCampaignMaps = false;
345 
347 
349 
350  logKillsToConsole = false;
351 
352  setChanged();
353 }
354 
355 
357 {
358 #if USE_HOME_DIRECTORY == 0
359 
360  searchPathNum = 1;
361  searchPath[0] = ".\\" ;
362 #else
363 
364  searchPathNum = 6;
365 
366  searchPath[0] = "~/.asc/" ;
367  searchPath[1] = GAME_DATADIR ;
368  searchPath[2] = "/var/local/games/asc/" ;
369  searchPath[3] = "/var/games/asc/" ;
370  searchPath[4] = "/usr/local/share/games/asc/" ;
371  searchPath[5] = "/usr/share/games/asc/" ;
372 #endif
373 
374 }
375 
377 {
378  static const char* my_mouseButtonNames[] = { "None", "Left", "Center", "Right", "4", "5", NULL };
379  if ( button <= 3 )
380  return my_mouseButtonNames[button];
381  else
382  return ASCString::toString( button );
383 }
384 
385 
387 {
388  return searchPathNum;
389 }
390 
391 void CGameOptions :: setSearchPath ( int i, const ASCString& path )
392 {
393  searchPath[i] = path;
394 }
395 
397 {
398  setSearchPath( searchPathNum++, path );
399 }
400 
402 {
403  return searchPath[i];
404 }
405 
406 
407 
409 {
410  Password pwd;
411  if ( !defaultPassword.empty() )
412  pwd.setEncoded ( defaultPassword );
413 
414  return pwd;
415 }
416 
417 
419 {
420  Password pwd;
421  if ( !defaultSuperVisorPassword.empty() )
423 
424  return pwd;
425 }
426 
428 {
429  panelData[name] = data;
430  setChanged();
431 }
432 
434 {
435  if ( panelData.find( name ) != panelData.end() ) {
436  data = panelData[name];
437  return true;
438  } else
439  return false;
440 }
441 
int aircraftCrashWarningTime
the number of turns after which a unit will crash until the player is warned
Definition: gameoptions.h:209
int movespeed
1/100 sec for a unit to move from one field to the next
Definition: gameoptions.h:63
ASCString searchPath[30]
Definition: gameoptions.h:249
bool forceWindowedMode
force ASC to run in windowed mode (and not fullscreen, which is default)
Definition: gameoptions.h:93
void addSearchPath(const ASCString &path)
void addBool(const ASCString &name, bool &property)
int centerbutton
the button to select a field and open the menu there
Definition: gameoptions.h:146
bool units_gray_after_move
are units that cannot move but shoot displayed in gray ?
Definition: gameoptions.h:72
const int mouseButtonNum
Definition: gameoptions.cpp:60
void setDefaultDirectories()
TextPropertyGroup * run()
Password getDefaultSupervisorPassword()
bool recordCampaignMaps
Definition: gameoptions.h:204
ASCString defaultPassword
Definition: gameoptions.h:236
int mapeditor_xresolution
the horizontal resolution the mapeditor uses
Definition: gameoptions.h:114
int fieldmarkbutton
the button to select a field without opening the menu
Definition: gameoptions.h:130
void load(const ASCString &filename)
Definition: gameoptions.cpp:71
static const int maxSearchPathNum
Definition: gameoptions.h:247
bool muteMusic
muted soud can be reactivated during the game
Definition: gameoptions.h:174
bool hardwareSurface
use screen buffer on the graphics card instead of main memory
Definition: gameoptions.h:96
int yresolution
the vertical resolution ASC uses
Definition: gameoptions.h:111
void runTextIO(PropertyContainer &pc)
Definition: gameoptions.cpp:92
Global platform dependant definitions. This file just branches to the platform specific files in thei...
bool endturnquestion
question "do you want to end your turn"
Definition: gameoptions.h:69
void updatePanelData(const ASCString &name, PanelData data)
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
const char * mouseButtons[mouseButtonNum]
Definition: gameoptions.cpp:61
bool fastmove
the number of steps to perform a move: 0 -> 3 step; != 0 -> 2 steps
Definition: gameoptions.h:60
bool debugReplay
enables the option to review your own replay to find replay bugs
Definition: gameoptions.h:102
PanelDataContainer panelData
Definition: gameoptions.h:218
bool saveEventMessagesExternal
will save all Immediate Game Event messages into a seperate file for doing translations ...
Definition: gameoptions.h:257
void addStringArray(const ASCString &name, vector< ASCString > &property)
void setEncoded(const string &s)
Definition: password.cpp:32
bool autoproduceammunition
produce required ammo upon refuelling
Definition: gameoptions.h:191
int mapzoomeditor
the zoom of the map display in the map editor
Definition: gameoptions.h:78
ASCString defaultSuperVisorPassword
Definition: gameoptions.h:237
bool automaticTraining
are units automatically trained in training centers
Definition: gameoptions.h:122
bool mapeditWindowedMode
force the mapeditor to run in fullscreen mode (and not windowed, which is default) ...
Definition: gameoptions.h:105
struct CGameOptions::@9 unitProduction
ASCString BI3directory
Definition: gameoptions.h:223
bool getPanelData(const ASCString &name, PanelData &data)
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
void setChanged(bool flag=true)
Definition: gameoptions.h:272
bool replayMovieMode
Definition: gameoptions.h:203
char * strrr(int a)
converts a to a string.
Definition: misc.cpp:66
Password getDefaultPassword()
int dragndropbutton
used in the container dialog
Definition: gameoptions.h:149
bool hideMouseOnScreenUpdates
hides the mouse cursor when screen updates are performed
Definition: gameoptions.h:99
struct CGameOptions::SoundSettings sound
DialogAnswers dialogAnswers
Definition: gameoptions.h:252
bool muteEffects
muted soud can be reactivated during the game
Definition: gameoptions.h:171
The interface for the various streams that ASC offers, like file and memory streams.
int getSearchPathNum()
int attackspeed1
are fields marked that a unit could move to if there was no other unit standing
Definition: gameoptions.h:84
int mapeditor_yresolution
the vertical resolution the mapeditor uses
Definition: gameoptions.h:117
CGameOptions * pStaticGameOptions
Definition: gameoptions.cpp:26
class Destroyer destroyer
bool singleClickAction
marks a field and opens the small gui buttons with a single click (default: first click mark...
Definition: gameoptions.h:161
Parses a .ASCTXT file and returns a TextPropertyGroup.
static CGameOptions * Instance()
returns the only Instance
Definition: gameoptions.cpp:38
struct CGameOptions::@10 pbemServer
struct CGameOptions::Mouse mouse
bool maped_modalSelectionWindow
Definition: gameoptions.h:119
int mapzoom
the zoom of the map display in ASC
Definition: gameoptions.h:75
void addInteger(const ASCString &name, int &property)
virtual void closeBracket()
int attackspeed3
second delay in attack display
Definition: gameoptions.h:90
void addNamedInteger(const ASCString &name, int &property, int tagNum, const char **tags)
ASCString graphicsDriver
Definition: gameoptions.h:233
void setSearchPath(int i, const ASCString &path)
static ASCString getButtonName(int button)
void setDefaults()
ASCString getSearchPath(int i)
struct CGameOptions::@11 video
bool logKillsToConsole
Definition: gameoptions.h:259
virtual void openBracket(const ASCString &name)
const T & min(const T &a, const T &b, const T &c)
Definition: misc.h:80
int attackspeed2
speed of moving bars in attack display
Definition: gameoptions.h:87
void addString(const ASCString &name, ASCString &property)
int zoomoutbutton
the button to display the vehicle information
Definition: gameoptions.h:157
ASCString languageOverride
Definition: gameoptions.h:254
bool off
if the sound is off, it can only be reactivated by restarting asc, but doesn't lock the sound device ...
Definition: gameoptions.h:177
int replayMoveSpeedFactor
how much faster are unit going to move in replays (percent)
Definition: gameoptions.h:66
bool find(const ASCString &name)
ASCString mailProgram
Definition: gameoptions.h:231
void save(const ASCString &filename)
Definition: gameoptions.cpp:83
ASCString startupMap
Definition: gameoptions.h:235
int xresolution
the horizontal resolution ASC uses
Definition: gameoptions.h:108
vector< ASCString > visibleMapLayer
Definition: gameoptions.h:206
bool cacheASCGUI
Definition: gameoptions.h:201