Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a save realism mode #3620

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "qtscript.h"
#include "template.h"
#include "activity.h"
#include "warzoneconfig.h"

struct CHEAT_ENTRY
{
Expand Down Expand Up @@ -183,6 +184,10 @@ void sendProcessDebugMappings(bool val)
{
return;
}
if (war_getSaveRealism())
{
return;
}
NETbeginEncode(NETgameQueue(selectedPlayer), GAME_DEBUG_MODE);
NETbool(&val);
NETend();
Expand Down
2 changes: 2 additions & 0 deletions src/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ bool loadConfig()
war_setPointLightPerPixelLighting(value.value_or(false));
}

war_setSaveRealism(iniGetBool("saveRealism", war_getSaveRealism()).value());
ActivityManager::instance().endLoadingSettings();
return true;
}
Expand Down Expand Up @@ -779,6 +780,7 @@ bool saveConfig()
iniSetInteger("shadowFilterSize", (int)war_getShadowFilterSize());
iniSetInteger("shadowMapResolution", (int)war_getShadowMapResolution());
iniSetBool("pointLightsPerpixel", war_getPointLightPerPixelLighting());
iniSetBool("saveRealism", war_getSaveRealism());
iniSetInteger("configVersion", CURRCONFVERSION);

// write out ini file changes
Expand Down
34 changes: 34 additions & 0 deletions src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2641,6 +2641,11 @@ static std::string gameOptionsCameraSpeedString()
return cameraSpeed;
}

char const *gameOptionsSaveRealism()
{
return war_getSaveRealism() ? _("On") : _("Off");
}

// ////////////////////////////////////////////////////////////////////////////
// Game Options Menu

Expand Down Expand Up @@ -2861,6 +2866,7 @@ static std::shared_ptr<WIDGET> makeLanguageDropdown()
widgSetString(psWScreen, FRONTEND_COLOUR_CAM, _("Campaign"));
widgSetString(psWScreen, FRONTEND_COLOUR_MP, _("Skirmish/Multiplayer"));
widgSetString(psWScreen, FRONTEND_DIFFICULTY, _("Campaign Difficulty"));
widgSetString(psWScreen, FRONTEND_SAVEREALISM, _("Save Realism"));
widgSetString(psWScreen, FRONTEND_CAMERASPEED, _("Camera Speed"));
widgSetString(psWScreen, FRONTEND_DIFFICULTY_R, gameOptionsDifficultyString());

Expand Down Expand Up @@ -2920,6 +2926,12 @@ void startGameOptionsMenu()
makeTextButton(FRONTEND_DIFFICULTY_R, gameOptionsDifficultyString(), WBUT_SECONDARY, MINIMUM_GAME_OPTIONS_RIGHT_BUTTON_WIDTH)
);

// Save Realism
gridBuilder.addRow(
makeTextButton(FRONTEND_SAVEREALISM, _("Save Realism"), WBUT_SECONDARY, MINIMUM_GAME_OPTIONS_BUTTON_WIDTH),
makeTextButton(FRONTEND_SAVEREALISM_R, gameOptionsSaveRealism(), WBUT_SECONDARY, MINIMUM_GAME_OPTIONS_RIGHT_BUTTON_WIDTH)
);

// Camera speed
gridBuilder.addRow(
makeTextButton(FRONTEND_CAMERASPEED, _("Camera Speed"), WBUT_SECONDARY, MINIMUM_GAME_OPTIONS_BUTTON_WIDTH),
Expand Down Expand Up @@ -3044,6 +3056,28 @@ bool runGameOptionsMenu()
widgSetString(psWScreen, FRONTEND_CAMERASPEED_R, gameOptionsCameraSpeedString().c_str());
break;

case FRONTEND_SAVEREALISM:
case FRONTEND_SAVEREALISM_R:
war_setSaveRealism(!war_getSaveRealism());
widgSetString(psWScreen, FRONTEND_SAVEREALISM_R, gameOptionsSaveRealism());
if (war_getSaveRealism())
{
const std::string REAL_TAG = "Realism";

if (!hasNotificationsWithTag(REAL_TAG))
{
WZ_Notification notification;
notification.duration = 8 * GAME_TICKS_PER_SEC;
notification.contentTitle = _("Realism mode");
notification.contentText = _("One automatic save per mission and no cheats!");
notification.tag = REAL_TAG;
notification.largeIcon = WZ_Notification_Image("images/notifications/skull_crossbones.png");

addNotification(notification, WZ_Notification_Trigger::Immediate());
}
}
break;

case FRONTEND_QUIT:
changeTitleMode(OPTIONS);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ enum
FRONTEND_DIFFICULTY_R,
FRONTEND_CAMERASPEED,
FRONTEND_CAMERASPEED_R,
FRONTEND_SAVEREALISM,
FRONTEND_SAVEREALISM_R,

FRONTEND_GRAPHICSOPTIONS = 22000, // Graphics Options Menu
FRONTEND_FMVMODE,
Expand Down
9 changes: 6 additions & 3 deletions src/ingameop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,12 @@ static bool _intAddInGameOptions()
// add 'load'
addIGTextButton(INTINGAMEOP_LOAD_MISSION, INTINGAMEOP_1_X, INTINGAMEOPAUTO_Y_LINE(row), INTINGAMEOP_OP_W, _("Load Game"), OPALIGN);
row++;
// add 'save'
addIGTextButton(INTINGAMEOP_SAVE_MISSION, INTINGAMEOP_1_X, INTINGAMEOPAUTO_Y_LINE(row), INTINGAMEOP_OP_W, _("Save Game"), OPALIGN);
row++;
if (!war_getSaveRealism())
{
// add 'save'
addIGTextButton(INTINGAMEOP_SAVE_MISSION, INTINGAMEOP_1_X, INTINGAMEOPAUTO_Y_LINE(row), INTINGAMEOP_OP_W, _("Save Game"), OPALIGN);
row++;
}
}
}

Expand Down
14 changes: 12 additions & 2 deletions src/keybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ void kf_MakeMeHero()
if (psDroid->selected && psDroid->droidType == DROID_COMMAND)
{
psDroid->experience = 8 * 65536 * 128;
}
}
else if (psDroid->selected)
{
psDroid->experience = 4 * 65536 * 128;
Expand Down Expand Up @@ -746,7 +746,7 @@ void kf_ListDroids()
debug(LOG_INFO, "droid %i;%s;%i;%i;%i", i, psDroid->aName, psDroid->droidType, x, y);
}
}

}


Expand Down Expand Up @@ -2543,6 +2543,11 @@ void kf_QuickSave()
{
return;
}
if (war_getSaveRealism())
{
console(_("QuickSave not allowed during realism mode"));
return;
}

const char *filename = bMultiPlayer ? QUICKSAVE_SKI_FILENAME : QUICKSAVE_CAM_FILENAME;
const char *quickSaveFolder = bMultiPlayer ? QUICKSAVE_SKI_FOLDER : QUICKSAVE_CAM_FOLDER;
Expand Down Expand Up @@ -2572,6 +2577,11 @@ void kf_QuickLoad()
{
return;
}
if (war_getSaveRealism())
{
console(_("QuickLoad not allowed during realism mode"));
return;
}

const char *filename = bMultiPlayer ? QUICKSAVE_SKI_FILENAME : QUICKSAVE_CAM_FILENAME;
// check for .json version, because that's what going to be loaded anyway
Expand Down
11 changes: 8 additions & 3 deletions src/loadsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "ingameop.h"
#include "game.h"
#include "version.h"
#include "warzoneconfig.h"
#define totalslots 36 // saves slots
#define slotsInColumn 12 // # of slots in a column
#define totalslotspace 64 // guessing 64 max chars for filename.
Expand Down Expand Up @@ -390,7 +391,7 @@ bool addLoadSave(LOADSAVE_MODE savemode, const char *title)
ASSERT(latestTagResult.has_value(), "No extractable latest tag?? - Please try re-downloading the latest official source bundle");
const TagVer buildTagVer = latestTagResult.value_or(TagVer());
try
{
{
WZ_PHYSFS_enumerateFolders(NewSaveGamePath, [NewSaveGamePath, &buildTagVer, &saveGameNamesAndTimes](const char* dirName){
if (strcmp(dirName, "auto") == 0)
{
Expand Down Expand Up @@ -1132,14 +1133,18 @@ static void freeAutoSaveSlot(SAVEGAME_LOC loc)
deleteSaveGame_classic(savefile);
}

bool autoSave()
bool autoSave(bool forceRealismSaveIfPossible)
{
// Bail out if we're running a _true_ multiplayer game or are playing a tutorial/debug/cheating/autogames
const DebugInputManager& dbgInputManager = gInputManager.debugManager();
if (!autosaveEnabled || runningMultiplayer() || bInTutorial || dbgInputManager.debugMappingsAllowed() || Cheated || autogame_enabled())
{
return false;
}
if (war_getSaveRealism() && !forceRealismSaveIfPossible)
{
return false;
}
// Bail out if we're running a replay
if (NETisReplay())
{
Expand All @@ -1152,7 +1157,7 @@ bool autoSave()
// no old .gam found: check for new saves
freeAutoSaveSlot(bMultiPlayer ? SAVEGAME_LOC_SKI_AUTO : SAVEGAME_LOC_CAM_AUTO);
}

time_t now = time(nullptr);
struct tm timeinfo = getLocalTime(now);
char savedate[PATH_MAX];
Expand Down
2 changes: 1 addition & 1 deletion src/loadsave.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ void loadSaveScreenSizeDidChange(unsigned int oldWidth, unsigned int oldHeight,

bool findLastSave();

bool autoSave();
bool autoSave(bool forceRealismSaveIfPossible=false);

#endif // __INCLUDED_SRC_LOADSAVE_H__
9 changes: 9 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ char MultiCustomMapsPath[PATH_MAX];
char MultiPlayersPath[PATH_MAX];
char KeyMapPath[PATH_MAX];
char FavoriteStructuresPath[PATH_MAX];
static unsigned int realismSaveTime = 0;
// Start game in title mode:
static GS_GAMEMODE gameStatus = GS_TITLE_SCREEN;
// Status of the gameloop
Expand Down Expand Up @@ -986,6 +987,7 @@ static void startGameLoop()
addMissionTimerInterface();
}
triggerEvent(TRIGGER_START_LEVEL);
realismSaveTime = gameTime + 1000; //Really just to prevent Intel videos messages from not getting saved if run immediately.
screen_disableMapPreview();

GameStoryLogger::instance().logStartGame();
Expand Down Expand Up @@ -1084,6 +1086,7 @@ static void stopGameLoop()
GameStoryLogger::instance().reset();

gameInitialised = false;
realismSaveTime = 0;
}


Expand Down Expand Up @@ -1316,6 +1319,12 @@ void mainLoop()
realTimeUpdate(); // Update realTime.
}

if (!bMultiPlayer && war_getSaveRealism() && (realismSaveTime != 0) && (gameTime > realismSaveTime))
{
realismSaveTime = 0;
autoSave(true);
}

wzApplyCursor();
runNotifications();
#if defined(ENABLE_DISCORD)
Expand Down
12 changes: 12 additions & 0 deletions src/warzoneconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ struct WARZONE_GLOBALS
bool pointLightLighting = false;
// groups UI
bool groupsMenuEnabled = true;
// save realism
bool saveRealism = false;

// run-time only settings (not persisted to config!)
bool allowVulkanImplicitLayers = false;
Expand Down Expand Up @@ -680,3 +682,13 @@ bool war_getAllowVulkanImplicitLayers()
{
return warGlobs.allowVulkanImplicitLayers;
}

bool war_getSaveRealism()
{
return warGlobs.saveRealism;
}

void war_setSaveRealism(bool mode)
{
warGlobs.saveRealism = mode;
}
2 changes: 2 additions & 0 deletions src/warzoneconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ void war_setGroupsMenuEnabled(bool enabled);
void war_runtimeOnlySetAllowVulkanImplicitLayers(bool allowed); // not persisted to config
bool war_getAllowVulkanImplicitLayers();

bool war_getSaveRealism();
void war_setSaveRealism(bool mode);
/**
* Enable or disable sound initialization
*
Expand Down
Loading