Skip to content

Commit 4086038

Browse files
committed
autosave option
1 parent ffdfb34 commit 4086038

14 files changed

Lines changed: 164 additions & 239 deletions

src/Battlescape/BattlescapeState.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
#include "../Interface/Bar.h"
5858
#include "../Interface/ImageButton.h"
5959
#include "../Interface/NumberText.h"
60-
#include "../Menu/AutoSaveState.h"
6160
#include "../Savegame/SavedGame.h"
6261
#include "../Savegame/SavedBattleGame.h"
6362
#include "../Savegame/Tile.h"
@@ -1248,9 +1247,9 @@ inline void BattlescapeState::handle(Action *action)
12481247
}
12491248
// quick save and quick load
12501249
else if (action->getDetails()->key.keysym.sym == Options::getInt("keyQuickSave") && Options::getInt("autosave") == 1)
1251-
_game->pushState(new AutoSaveState(_game, true));
1250+
_game->pushState(new SaveState(_game, false, true));
12521251
else if (action->getDetails()->key.keysym.sym == Options::getInt("keyQuickLoad") && Options::getInt("autosave") == 1)
1253-
_game->pushState(new AutoSaveState(_game, true, true));
1252+
_game->pushState(new LoadState(_game, false, true));
12541253
}
12551254
}
12561255
}

src/Engine/Game.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "Logger.h"
3131
#include "../Interface/Cursor.h"
3232
#include "../Interface/FpsCounter.h"
33-
#include "../Menu/AutoSaveState.h"
3433
#include "../Resource/ResourcePack.h"
3534
#include "../Ruleset/Ruleset.h"
3635
#include "../Savegame/SavedGame.h"
@@ -132,8 +131,7 @@ Game::~Game()
132131
{
133132
if (_save != 0 && Options::getInt("autosave") == 3)
134133
{
135-
AutoSaveState *as = new AutoSaveState(this, true);
136-
as->quickSave();
134+
SaveState *ss = new SaveState(this, true, true);
137135
}
138136

139137
Mix_HaltChannel(-1);
@@ -181,8 +179,8 @@ void Game::run()
181179
// Initialize active state
182180
if (!_init)
183181
{
184-
_states.back()->init();
185182
_init = true;
183+
_states.back()->init();
186184

187185
// Unpress buttons
188186
_states.back()->resetAll();

src/Geoscape/AbandonGameState.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "../Interface/Window.h"
2727
#include "../Interface/Text.h"
2828
#include "../Savegame/SavedGame.h"
29-
#include "../Menu/AutoSaveState.h"
3029
#include "../Menu/MainMenuState.h"
3130
#include "../Engine/Options.h"
3231

@@ -93,8 +92,7 @@ void AbandonGameState::btnYesClick(Action *)
9392
{
9493
if (Options::getInt("autosave") == 3)
9594
{
96-
AutoSaveState *as = new AutoSaveState(_game, true);
97-
as->quickSave();
95+
SaveState *ss = new SaveState(_game, true, false);
9896
}
9997

10098
_game->setState(new MainMenuState(_game));

src/Geoscape/GeoscapeState.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "../Interface/Cursor.h"
3737
#include "../Interface/FpsCounter.h"
3838
#include "../Engine/Timer.h"
39-
#include "../Menu/AutoSaveState.h"
4039
#include "../Savegame/GameTime.h"
4140
#include "../Engine/Music.h"
4241
#include "../Savegame/SavedGame.h"
@@ -415,9 +414,9 @@ void GeoscapeState::handle(Action *action)
415414
}
416415
// quick save and quick load
417416
else if (action->getDetails()->key.keysym.sym == Options::getInt("keyQuickSave") && Options::getInt("autosave") == 1)
418-
_game->pushState(new AutoSaveState(_game, true));
417+
_game->pushState(new SaveState(_game, true, true));
419418
else if (action->getDetails()->key.keysym.sym == Options::getInt("keyQuickLoad") && Options::getInt("autosave") == 1)
420-
_game->pushState(new AutoSaveState(_game, true, true));
419+
_game->pushState(new LoadState(_game, true, true));
421420
}
422421
if(!_dogfights.empty())
423422
{
@@ -1532,8 +1531,9 @@ void GeoscapeState::time1Day()
15321531
std::for_each(_game->getSavedGame()->getAlienBases()->begin(), _game->getSavedGame()->getAlienBases()->end(),
15331532
GenerateSupplyMission(*_game->getRuleset(), *_game->getSavedGame()));
15341533

1534+
// Autosave
15351535
if (Options::getInt("autosave") >= 2)
1536-
_game->pushState(new AutoSaveState(_game, true, true));
1536+
_game->pushState(new SaveState(_game, true, false));
15371537
}
15381538

15391539
/**

src/Menu/AutoSaveState.cpp

Lines changed: 0 additions & 162 deletions
This file was deleted.

src/Menu/AutoSaveState.h

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Menu/LoadState.cpp

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,22 @@ namespace OpenXcom
4444
*/
4545
LoadState::LoadState(Game *game, bool geo) : SavedGameState(game, geo)
4646
{
47-
_geo = geo;
4847
// Set up objects
4948
_txtTitle->setText(_game->getLanguage()->getString("STR_SELECT_GAME_TO_LOAD"));
50-
5149
_lstSaves->onMousePress((ActionHandler)&LoadState::lstSavesPress);
5250
}
5351

52+
/**
53+
* Initializes all the elements in the Load Game screen.
54+
* @param game Pointer to the core game.
55+
* @param geo True to use Geoscape palette, false to use Battlescape palette.
56+
* @param showMsg True if need to show messages like "Loading game" or "Saving game".
57+
*/
58+
LoadState::LoadState(Game *game, bool geo, bool showMsg) : SavedGameState(game, geo, showMsg)
59+
{
60+
quickLoad();
61+
}
62+
5463
/**
5564
*
5665
*/
@@ -118,4 +127,55 @@ void LoadState::lstSavesPress(Action *action)
118127
}
119128
}
120129

130+
/**
131+
* Quick load game.
132+
*/
133+
void LoadState::quickLoad()
134+
{
135+
if (_showMsg) updateStatus("STR_LOADING_GAME");
136+
137+
#ifdef _WIN32
138+
std::string filename = Language::wstrToCp(L"autosave");
139+
#else
140+
std::string filename = Language::wstrToUtf8(L"autosave");
141+
#endif
142+
143+
SavedGame *s = new SavedGame();
144+
try
145+
{
146+
s->load(filename, _game->getRuleset());
147+
_game->setSavedGame(s);
148+
_game->setState(new GeoscapeState(_game));
149+
if (_game->getSavedGame()->getBattleGame() != 0)
150+
{
151+
_game->getSavedGame()->getBattleGame()->loadMapResources(_game->getResourcePack());
152+
BattlescapeState *bs = new BattlescapeState(_game);
153+
_game->pushState(bs);
154+
_game->getSavedGame()->getBattleGame()->setBattleState(bs);
155+
}
156+
}
157+
catch (Exception &e)
158+
{
159+
Log(LOG_ERROR) << e.what();
160+
std::wstringstream error;
161+
error << _game->getLanguage()->getString("STR_LOAD_UNSUCCESSFUL") << L'\x02' << Language::utf8ToWstr(e.what());
162+
if (_geo)
163+
_game->pushState(new ErrorMessageState(_game, error.str(), Palette::blockOffset(8)+10, "BACK01.SCR", 6));
164+
else
165+
_game->pushState(new ErrorMessageState(_game, error.str(), Palette::blockOffset(0), "TAC00.SCR", -1));
166+
delete s;
167+
}
168+
catch (YAML::Exception &e)
169+
{
170+
Log(LOG_ERROR) << e.what();
171+
std::wstringstream error;
172+
error << _game->getLanguage()->getString("STR_LOAD_UNSUCCESSFUL") << L'\x02' << Language::utf8ToWstr(e.what());
173+
if (_geo)
174+
_game->pushState(new ErrorMessageState(_game, error.str(), Palette::blockOffset(8)+10, "BACK01.SCR", 6));
175+
else
176+
_game->pushState(new ErrorMessageState(_game, error.str(), Palette::blockOffset(0), "TAC00.SCR", -1));
177+
delete s;
178+
}
179+
}
180+
121181
}

0 commit comments

Comments
 (0)