Fix #14296: Allow early scenario completion in multiplayer

This commit is contained in:
Maximilian Bottin authored and GitHub committed 2021-03-18 20:30:11 +01:00
1 parent e89c37e7ae
commit 6f28914f61
6 files changed
+48 -8

No files matched your search

+17
View File
@@ -21,6 +21,7 @@
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/actions/ScenarioSetSettingAction.h>
#include <openrct2/audio/AudioMixer.h>
#include <openrct2/audio/audio.h>
#include <openrct2/config/Config.h>
@@ -1793,6 +1794,14 @@ static void window_options_misc_mouseup(rct_window* w, rct_widgetindex widgetInd
break;
case WIDX_ALLOW_EARLY_COMPLETION:
gConfigGeneral.allow_early_completion ^= 1;
// Only the server can control this setting and needs to send the
// current value of allow_early_completion to all clients
if (network_get_mode() == NETWORK_MODE_SERVER)
{
auto setAllowEarlyCompletionAction = ScenarioSetSettingAction(
ScenarioSetSetting::AllowEarlyCompletion, gConfigGeneral.allow_early_completion);
GameActions::Execute(&setAllowEarlyCompletionAction);
}
config_save_default();
w->Invalidate();
break;
@@ -1898,6 +1907,14 @@ static void window_options_misc_invalidate(rct_window* w)
{
w->disabled_widgets |= (1ULL << WIDX_REAL_NAME_CHECKBOX);
window_options_misc_widgets[WIDX_REAL_NAME_CHECKBOX].tooltip = STR_OPTION_DISABLED_DURING_NETWORK_PLAY;
// Disable the use of the allow_early_completion option during network play on clients.
// This is to prevent confusion on clients because changing this setting during network play wouldn't change
// the way scenarios are completed during this network-session
if (network_get_mode() == NETWORK_MODE_CLIENT)
{
w->disabled_widgets |= (1ULL << WIDX_ALLOW_EARLY_COMPLETION);
window_options_misc_widgets[WIDX_ALLOW_EARLY_COMPLETION].tooltip = STR_OPTION_DISABLED_DURING_NETWORK_PLAY;
}
}
WidgetSetCheckboxValue(w, WIDX_REAL_NAME_CHECKBOX, gConfigGeneral.show_real_names_of_guests);
@@ -13,6 +13,7 @@
#include "../interface/Window.h"
#include "../management/Finance.h"
#include "../peep/Peep.h"
#include "../scenario/Scenario.h"
#include "../util/Util.h"
#include "../world/Park.h"
@@ -236,6 +237,9 @@ GameActions::Result::Ptr ScenarioSetSettingAction::Execute() const
gParkFlags &= ~PARK_FLAGS_DIFFICULT_GUEST_GENERATION;
}
break;
case ScenarioSetSetting::AllowEarlyCompletion:
gAllowEarlyCompletionInNetworkPlay = _value;
break;
default:
log_error("Invalid setting: %u", _setting);
return MakeResult(GameActions::Status::InvalidParameters, STR_NONE);
@@ -34,6 +34,7 @@ enum class ScenarioSetSetting : uint8_t
ForbidHighConstruction,
ParkRatingHigherDifficultyLevel,
GuestGenerationHigherDifficultyLevel,
AllowEarlyCompletion,
Count
};
+3 -1
View File
@@ -36,7 +36,7 @@
// This string specifies which version of network stream current build uses.
// It is used for making sure only compatible builds get connected, even within
// single OpenRCT2 version.
#define NETWORK_STREAM_VERSION "3"
#define NETWORK_STREAM_VERSION "4"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
static Peep* _pickup_peep = nullptr;
@@ -2754,6 +2754,7 @@ bool NetworkBase::LoadMap(IStream* stream)
gCheatsDisableRideValueAging = stream->ReadValue<uint8_t>() != 0;
gConfigGeneral.show_real_names_of_guests = stream->ReadValue<uint8_t>() != 0;
gCheatsIgnoreResearchStatus = stream->ReadValue<uint8_t>() != 0;
gAllowEarlyCompletionInNetworkPlay = stream->ReadValue<uint8_t>() != 0;
gLastAutoSaveUpdate = AUTOSAVE_PAUSE;
result = true;
@@ -2803,6 +2804,7 @@ bool NetworkBase::SaveMap(IStream* stream, const std::vector<const ObjectReposit
stream->WriteValue<uint8_t>(gCheatsDisableRideValueAging);
stream->WriteValue<uint8_t>(gConfigGeneral.show_real_names_of_guests);
stream->WriteValue<uint8_t>(gCheatsIgnoreResearchStatus);
stream->WriteValue<uint8_t>(gConfigGeneral.allow_early_completion);
result = true;
}
+21 -6
View File
@@ -73,6 +73,7 @@ random_engine_t gScenarioRand;
Objective gScenarioObjective;
bool gAllowEarlyCompletionInNetworkPlay;
uint16_t gScenarioParkRatingWarningDays;
money32 gScenarioCompletedCompanyValue;
money32 gScenarioCompanyValueRecord;
@@ -288,7 +289,6 @@ static void scenario_day_update()
{
finance_update_daily_profit();
peep_update_days_in_queue();
bool allowEarlyCompletion = gConfigGeneral.allow_early_completion && (network_get_mode() == NETWORK_MODE_NONE);
switch (gScenarioObjective.Type)
{
case OBJECTIVE_10_ROLLERCOASTERS:
@@ -299,7 +299,7 @@ static void scenario_day_update()
scenario_objective_check();
break;
default:
if (allowEarlyCompletion)
if (AllowEarlyCompletion())
scenario_objective_check();
break;
}
@@ -713,9 +713,8 @@ ObjectiveStatus Objective::CheckGuestsBy() const
{
int16_t parkRating = gParkRating;
int32_t currentMonthYear = gDateMonthsElapsed;
bool allowEarlyCompletion = gConfigGeneral.allow_early_completion && (network_get_mode() == NETWORK_MODE_NONE);
if (currentMonthYear == MONTH_COUNT * Year || allowEarlyCompletion)
if (currentMonthYear == MONTH_COUNT * Year || AllowEarlyCompletion())
{
if (parkRating >= 600 && gNumGuestsInPark >= NumGuests)
{
@@ -735,9 +734,8 @@ ObjectiveStatus Objective::CheckParkValueBy() const
int32_t currentMonthYear = gDateMonthsElapsed;
money32 objectiveParkValue = Currency;
money32 parkValue = gParkValue;
bool allowEarlyCompletion = gConfigGeneral.allow_early_completion && (network_get_mode() == NETWORK_MODE_NONE);
if (currentMonthYear == MONTH_COUNT * Year || allowEarlyCompletion)
if (currentMonthYear == MONTH_COUNT * Year || AllowEarlyCompletion())
{
if (parkValue >= objectiveParkValue)
{
@@ -944,6 +942,23 @@ ObjectiveStatus Objective::CheckMonthlyFoodIncome() const
return ObjectiveStatus::Undecided;
}
/*
* Returns the AllowEarlyCompletion-Option to be used
* depending on the Current Network-Mode.
*/
bool AllowEarlyCompletion()
{
switch (network_get_mode())
{
case NETWORK_MODE_CLIENT:
return gAllowEarlyCompletionInNetworkPlay;
case NETWORK_MODE_NONE:
case NETWORK_MODE_SERVER:
default:
return gConfigGeneral.allow_early_completion;
}
}
static void scenario_objective_check()
{
auto status = gScenarioObjective.Check();
+2 -1
View File
@@ -431,7 +431,7 @@ extern uint32_t gScenarioTicks;
extern random_engine_t gScenarioRand;
extern Objective gScenarioObjective;
extern bool gAllowEarlyCompletionInNetworkPlay;
extern uint16_t gScenarioParkRatingWarningDays;
extern money32 gScenarioCompletedCompanyValue;
extern money32 gScenarioCompanyValueRecord;
@@ -452,6 +452,7 @@ void load_from_sc6(const char* path);
void scenario_begin();
void scenario_update();
bool scenario_create_ducks();
bool AllowEarlyCompletion();
const random_engine_t::state_type& scenario_rand_state();
void scenario_rand_seed(random_engine_t::result_type s0, random_engine_t::result_type s1);