diff --git a/Core/GameEngine/Include/GameClient/Snow.h b/Core/GameEngine/Include/GameClient/Snow.h index 862820eb520..3fb798c75a0 100644 --- a/Core/GameEngine/Include/GameClient/Snow.h +++ b/Core/GameEngine/Include/GameClient/Snow.h @@ -36,6 +36,17 @@ class WeatherSetting : public Overridable MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( WeatherSetting, "WeatherSetting" ) public: + enum DynamicProfile + { + DYNAMIC_AUTO, + DYNAMIC_DRY, + DYNAMIC_SNOW, + DYNAMIC_RAIN, + DYNAMIC_HEAVY_RAIN, + DYNAMIC_STORM + }; + + Int m_dynamicWeatherProfile = DYNAMIC_AUTO; AsciiString m_snowTexture; Real m_snowFrequencyScaleX; ///isInMultiplayerGame() && !TheGameLogic->isInReplayGame()) + if ((TheGameLogic->isInMultiplayerGame() +#if GENERALS_ONLINE_WEATHER_DEBUG + || TheGameLogic->isInSkirmishGame() +#endif + ) && !TheGameLogic->isInReplayGame()) { Player *localPlayer = ThePlayerList->getLocalPlayer(); // TheSuperHackers @tweak skyaero 19/07/2025 Observers can now chat @@ -5720,6 +5724,9 @@ static Bool isSystemMessage( const GameMessage *msg ) case GameMessage::MSG_DESTROY_SELECTED_GROUP: case GameMessage::MSG_LOGIC_CRC: case GameMessage::MSG_SET_REPLAY_CAMERA: +#if defined(GENERALS_ONLINE) + case GameMessage::MSG_START_DYNAMIC_WEATHER: +#endif case GameMessage::MSG_FRAME_TICK: case GameMessage::MSG_META_DEMO_INSTANT_QUIT: return TRUE; diff --git a/Core/GameEngine/Source/GameClient/Snow.cpp b/Core/GameEngine/Source/GameClient/Snow.cpp index 8760800b921..cfce2cfcbba 100644 --- a/Core/GameEngine/Source/GameClient/Snow.cpp +++ b/Core/GameEngine/Source/GameClient/Snow.cpp @@ -30,6 +30,11 @@ #include "PreRTS.h" // This must go first in EVERY cpp file in the Game #include "GameClient/Snow.h" #include "GameClient/View.h" +#include "GameClient/Display.h" +#include "GameLogic/GameLogic.h" +#include "GameLogic/TerrainLogic.h" +#include "Common/AudioEventRTS.h" +#include "Common/AudioHandleSpecialValues.h" SnowManager *TheSnowManager=nullptr; @@ -85,13 +90,96 @@ void SnowManager::setVisible(Bool showWeather) m_isVisible = showWeather; } +void SnowManager::setDynamicWeatherVisible(Bool visible) +{ + m_useDynamicVisibility = TRUE; + m_dynamicVisible = visible; +} + +void SnowManager::stopDynamicRain() +{ + if (TheAudio) + { + TheAudio->removeAudioEvent(m_rainSound); + TheAudio->removeAudioEvent(m_thunderSound); + } + m_rainSound = AHSV_Error; + m_thunderSound = AHSV_Error; + m_nextLightningFrame = 0; + m_thunderFrame = 0; +} + +void SnowManager::setDynamicRain(Int profile, UnsignedInt seed) +{ + stopDynamicRain(); + if (TheAudio) + { + // Dynamic weather takes over the stock rain sounds from any map scripts. + TheAudio->removeAudioEvent(AsciiString("RainStereoLoop")); + TheAudio->removeAudioEvent(AsciiString("ThunderAmbienceStereo")); + TheAudio->removeAudioEvent(AsciiString("ThunderStrikesStereo")); + if (profile == WeatherSetting::DYNAMIC_HEAVY_RAIN || profile == WeatherSetting::DYNAMIC_STORM) + { + AudioEventRTS rain("RainStereoLoop"); + m_rainSound = TheAudio->addAudioEvent(&rain); + } + } + if (profile == WeatherSetting::DYNAMIC_STORM && TheGameLogic) + { + m_stormSeed = seed; + m_nextLightningFrame = TheGameLogic->getFrame() + 2 * LOGICFRAMES_PER_SECOND; + } +} + +void SnowManager::update() +{ + if (m_nextLightningFrame == 0 || !TheGameLogic) + return; + + const UnsignedInt frame = TheGameLogic->getFrame(); + if (m_thunderFrame != 0 && frame >= m_thunderFrame) + { + if (TheAudio) + { + TheAudio->removeAudioEvent(m_thunderSound); + AudioEventRTS thunder("ThunderStrikesStereo"); + m_thunderSound = TheAudio->addAudioEvent(&thunder); + } + m_thunderFrame = 0; + } + if (frame < m_nextLightningFrame) + return; + + if (TheDisplay && TheTerrainLogic) + { + Region3D extent; + TheTerrainLogic->getExtent(&extent); + const Coord3D position = { + (extent.lo.x + extent.hi.x) * 0.5f, + (extent.lo.y + extent.hi.y) * 0.5f, + extent.hi.z + 200.0f + }; + const RGBColor color = { 0.65f, 0.7f, 0.85f }; + const Real radius = max(extent.hi.x - extent.lo.x, extent.hi.y - extent.lo.y) + 500.0f; + TheDisplay->createLightPulse(&position, &color, radius, 100.0f, 1, LOGICFRAMES_PER_SECOND / 4); + } + + // Visual randomness stays separate from the simulation and is seeded by the shared weather roll. + m_stormSeed = m_stormSeed * 1664525u + 1013904223u; + m_thunderFrame = frame + LOGICFRAMES_PER_SECOND / 2 + m_stormSeed % LOGICFRAMES_PER_SECOND; + m_nextLightningFrame = frame + (8 + (m_stormSeed >> 16) % 11) * LOGICFRAMES_PER_SECOND; +} + void SnowManager::reset() { + stopDynamicRain(); m_isVisible = TRUE; //default to showing if it's enabled via INI. + m_useDynamicVisibility = FALSE; } SnowManager::~SnowManager() { + stopDynamicRain(); delete [] m_startingHeights; m_startingHeights=nullptr; @@ -102,9 +190,12 @@ SnowManager::~SnowManager() OVERRIDE TheWeatherSetting = nullptr; +static const char *const dynamicWeatherProfiles[] = { "AUTO", "DRY", "SNOW", "RAIN", "HEAVY_RAIN", "STORM", nullptr }; + // PRIVATE DATA /////////////////////////////////////////////////////////////////////////////////// const FieldParse WeatherSetting::m_weatherSettingFieldParseTable[] = { + { "DynamicWeatherProfile", INI::parseIndexList, dynamicWeatherProfiles, offsetof( WeatherSetting, m_dynamicWeatherProfile ) }, { "SnowTexture", INI::parseAsciiString,nullptr, offsetof( WeatherSetting, m_snowTexture ) }, { "SnowFrequencyScaleX", INI::parseReal,nullptr, offsetof( WeatherSetting, m_snowFrequencyScaleX ) }, { "SnowFrequencyScaleY", INI::parseReal,nullptr, offsetof( WeatherSetting, m_snowFrequencyScaleY ) }, diff --git a/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp index c9c7cbb7602..55ca08079d4 100644 --- a/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp +++ b/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp @@ -367,6 +367,23 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) return; } +#if defined(GENERALS_ONLINE) + if (msg->getType() == GameMessage::MSG_START_DYNAMIC_WEATHER) + { + if (msg->getArgumentCount() == 0) + startDynamicWeather(msgPlayer); +#if GENERALS_ONLINE_WEATHER_DEBUG + else if (msg->getArgumentCount() == 1 && msg->getArgumentDataType(0) == ARGUMENTDATATYPE_INTEGER) + { + const Int profile = msg->getArgument(0)->integer; + if (profile >= 0 && profile <= 5) + startDynamicWeather(msgPlayer, profile); + } +#endif + return; + } +#endif + AIGroupPtr currentlySelectedGroup = nullptr; if (isInGame()) diff --git a/Core/GameEngine/Source/GameNetwork/Network.cpp b/Core/GameEngine/Source/GameNetwork/Network.cpp index a149bca7179..dccaa14a99a 100644 --- a/Core/GameEngine/Source/GameNetwork/Network.cpp +++ b/Core/GameEngine/Source/GameNetwork/Network.cpp @@ -52,6 +52,10 @@ #include "Common/Recorder.h" #include "GameClient/MessageBox.h" #include "../NGMP_include.h" +#if defined(GENERALS_ONLINE) +#include "GameNetwork/GeneralsOnline/NGMPGame.h" +#include "GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h" +#endif #if defined(DEBUG_CRC) && !RETAIL_COMPATIBLE_NETWORKING @@ -545,6 +549,15 @@ Bool Network::processCommand(GameMessage* msg) m_localStatus = NETLOCALSTATUS_INGAME; NetCommandList *netcmdlist = m_conMgr->getFrameCommandList(0); // clear out frame 0 since we skipped it deleteInstance(netcmdlist); +#if defined(GENERALS_ONLINE) + if (TheNGMPGame && TheGameInfo == TheNGMPGame && TheNGMPGame->amIHost() + && !TheNGMPGame->isQMGame() && TheNGMPGame->getDynamicWeather()) + { + GameMessage *weather = newInstance(GameMessage)(GameMessage::MSG_START_DYNAMIC_WEATHER); + m_conMgr->sendLocalGameMessage(weather, getExecutionFrame()); + deleteInstance(weather); + } +#endif } else { return FALSE; } diff --git a/Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h b/Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h index c994c5a2758..5dfb661197f 100644 --- a/Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h +++ b/Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h @@ -38,6 +38,7 @@ class W3DSnowManager : public SnowManager virtual void reset() override; virtual void update () override; virtual void updateIniSettings() override; + void reloadWeather() override; void render(RenderInfoClass &rinfo); void renderAsQuads(RenderInfoClass &rinfo, Int cubeOriginX, Int cubeOriginY, Int cubeDimX, Int cubeDimY); diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp index 62ece01ed24..92032e273ac 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp @@ -154,8 +154,15 @@ void W3DSnowManager::reset() SnowManager::reset(); } +void W3DSnowManager::reloadWeather() +{ + SnowManager::updateIniSettings(); + ReleaseResources(); // Recreated by render() on the next visible frame. +} + void W3DSnowManager::update() { + SnowManager::update(); // TheSuperHackers @tweak The snow render update is now decoupled from the logic step. m_time += WW3D::Get_Logic_Frame_Time_Seconds(); @@ -322,7 +329,7 @@ void W3DSnowManager::renderSubBox(RenderInfoClass &rinfo, Int originX, Int origi void W3DSnowManager::render(RenderInfoClass &rinfo) { - if (!TheWeatherSetting->m_snowEnabled || !m_isVisible) + if (!TheWeatherSetting->m_snowEnabled || !isWeatherVisible()) return; Int usePointSprites = DX8Wrapper::Get_Current_Caps()->Support_PointSprites() && TheWeatherSetting->m_usePointSprites; @@ -401,11 +408,8 @@ void W3DSnowManager::render(RenderInfoClass &rinfo) REF_PTR_RELEASE(vmat); //make sure we have all the resources we need - if (usePointSprites && !m_VertexBufferD3D) - ReAcquireResources(); - - if (!usePointSprites && !m_indexBuffer) - ReAcquireResources(); + if ((usePointSprites ? m_VertexBufferD3D == nullptr : m_indexBuffer == nullptr) && !ReAcquireResources()) + return; DX8Wrapper::Set_Texture(0,m_snowTexture); diff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h index bcecd9e7003..bba8b8ae0b5 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h @@ -619,6 +619,7 @@ class GameMessage : public MemoryPoolObject MSG_LOGIC_CRC, ///< CRC from the logic passed around in a network game :) MSG_SET_MINE_CLEARING_DETAIL, ///< CRC from the logic passed around in a network game :) MSG_ENABLE_RETALIATION_MODE, ///< Turn retaliation mode on or off. + MSG_START_DYNAMIC_WEATHER, ///< Start the host's weather cycle on a synchronized frame. MSG_BEGIN_DEBUG_NETWORK_MESSAGES = 1900, ///< network messages that exist only in debug/internal builds. all grouped separately. diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h index c3a66f6c326..337e0fbf99d 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h @@ -56,6 +56,7 @@ class AudioEventRTS; class Object; class Drawable; class Player; +class WeatherSetting; class ThingTemplate; class Team; class CommandList; @@ -171,6 +172,9 @@ class GameLogic : public SubsystemInterface, public Snapshot // super hack void startNewGame(Bool loadSaveGame); void loadMapINI(AsciiString mapName); +#if defined(GENERALS_ONLINE) + void startDynamicWeather(const Player *sender, Int debugProfile = -1); +#endif void updateLoadProgress( Int progress ); void deleteLoadScreen(); @@ -431,6 +435,12 @@ class GameLogic : public SubsystemInterface, public Snapshot Bool m_startNewGame; WindowLayout* m_background; +#if defined(GENERALS_ONLINE) + UnsignedInt m_weatherRoll = 0; + WeatherSetting *m_weatherOverride = nullptr; + NameKeyType m_weatherHost = NAMEKEY_INVALID; +#endif + Object* m_objList; ///< All of the objects in the world. // ObjectPtrHash m_objHash; ///< Used for ObjectID lookups ObjectPtrVector m_objVector; diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NGMPGame.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NGMPGame.h index 0d11c6a51b3..d3fdaaccf77 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NGMPGame.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NGMPGame.h @@ -54,6 +54,7 @@ class NGMPGame : public GameInfo UnsignedInt m_exeCRC; UnsignedInt m_iniCRC; Bool m_isQM; + Bool m_dynamicWeather = TRUE; AsciiString m_ladderIP; AsciiString m_pingStr; @@ -166,6 +167,8 @@ class NGMPGame : public GameInfo AsciiString generateLadderGameResultsPacket(void); void markGameAsQM(void) { m_isQM = TRUE; } Bool isQMGame(void) { return m_isQM; } + Bool getDynamicWeather() const { return m_dynamicWeather; } + void setDynamicWeather(Bool enabled) { m_dynamicWeather = enabled; } virtual void init(void); virtual void resetAccepted(void); ///< Reset the accepted flag on all players diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h index b78109bc4c4..67a37e29ce0 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h @@ -8,6 +8,11 @@ #define GENERALS_ONLINE_COMMUNITY_PATCH_CHANGES 1 +// Temporary weather testing through the in-game /weather command. Set to 0 to disable. +#ifndef GENERALS_ONLINE_WEATHER_DEBUG +#define GENERALS_ONLINE_WEATHER_DEBUG 0 +#endif + #define GENERALS_ONLINE_USE_PLUGINS_INTERFACE //#define USE_MAULLER_ONEDRIVE_FIX 1 diff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp index f46fe9d73ca..e1873b6ade8 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp @@ -661,6 +661,7 @@ const char *GameMessage::getCommandTypeAsString(GameMessage::Type t) CASE_LABEL(MSG_LOGIC_CRC) CASE_LABEL(MSG_SET_MINE_CLEARING_DETAIL) CASE_LABEL(MSG_ENABLE_RETALIATION_MODE) + CASE_LABEL(MSG_START_DYNAMIC_WEATHER) CASE_LABEL(MSG_BEGIN_DEBUG_NETWORK_MESSAGES) #if defined(RTS_DEBUG) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE) diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp index 61cf0d4f8a6..968108f0495 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp @@ -32,6 +32,7 @@ #include "Common/Player.h" #include "Common/PlayerList.h" +#include "Common/MessageStream.h" #include "GameClient/DisconnectMenu.h" #include "GameClient/GameWindow.h" #include "GameClient/Gadget.h" @@ -42,6 +43,7 @@ #include "GameClient/GUICallbacks.h" #include "GameClient/InGameUI.h" #include "GameClient/LanguageFilter.h" +#include "GameClient/Snow.h" #include "GameLogic/GameLogic.h" #include "GameNetwork/GameInfo.h" #include "GameNetwork/NetworkInterface.h" @@ -177,6 +179,41 @@ Bool handleInGameSlashCommands(UnicodeString uText) remainder.nextToken(&token); token.toLower(); +#if GENERALS_ONLINE_WEATHER_DEBUG + if (token == "weather") + { + if (TheNetwork && (!TheNGMPGame || TheGameInfo != TheNGMPGame || !TheNGMPGame->amIHost())) + { + TheInGameUI->message(UnicodeString(L"Weather testing is available to the match host.")); + return TRUE; + } + + AsciiString option; + remainder.nextToken(&option); + option.toLower(); + Int profile = WeatherSetting::DYNAMIC_AUTO; + if (option == "rain") + profile = WeatherSetting::DYNAMIC_RAIN; + else if (option == "heavy") + profile = WeatherSetting::DYNAMIC_HEAVY_RAIN; + else if (option == "storm") + profile = WeatherSetting::DYNAMIC_STORM; + else if (option == "snow") + profile = WeatherSetting::DYNAMIC_SNOW; + else if (option == "dry") + profile = WeatherSetting::DYNAMIC_DRY; + else if (!option.isEmpty() && option != "auto") + { + TheInGameUI->message(UnicodeString(L"Weather testing: /weather [auto|rain|heavy|storm|snow|dry]")); + return TRUE; + } + + GameMessage *weather = TheMessageStream->appendMessage(GameMessage::MSG_START_DYNAMIC_WEATHER); + weather->appendIntegerArgument(profile); + return TRUE; + } +#endif + if (token == "host") { UnicodeString s; @@ -203,7 +240,11 @@ void ToggleInGameChat( Bool immediate ) return; #if defined(GENERALS_ONLINE) - if (TheNGMPGame == nullptr) + if (TheNGMPGame == nullptr +#if GENERALS_ONLINE_WEATHER_DEBUG + && !TheGameLogic->isInSkirmishGame() +#endif + ) #else if (!TheGameInfo->isMultiPlayer() && TheGlobalData->m_netMinPlayers) #endif @@ -221,7 +262,7 @@ void ToggleInGameChat( Bool immediate ) // Send what is there, clear it out, and hide the window UnicodeString msg = GadgetTextEntryGetText( chatTextEntry ); msg.trim(); - if (!msg.isEmpty() && !handleInGameSlashCommands(msg)) + if (!msg.isEmpty() && !handleInGameSlashCommands(msg) && TheNetwork) { const Player *localPlayer = ThePlayerList->getLocalPlayer(); AsciiString playerName; diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp index d8c0b2c2eba..6b28adbef69 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp @@ -212,6 +212,7 @@ static bool s_matchStartCountdownWasRunning = false; static NameKeyType windowMapSelectMapID = NAMEKEY_INVALID; static NameKeyType checkBoxUseStatsID = NAMEKEY_INVALID; static NameKeyType checkBoxLimitSuperweaponsID = NAMEKEY_INVALID; +static NameKeyType checkBoxRandomWeatherID = NAMEKEY_INVALID; static NameKeyType comboBoxStartingCashID = NAMEKEY_INVALID; static NameKeyType checkBoxLimitArmiesID = NAMEKEY_INVALID; @@ -225,6 +226,7 @@ static GameWindow *textEntryChat = NULL; static GameWindow *textEntryMapDisplay = NULL; static GameWindow *windowMap = NULL; static GameWindow *checkBoxUseStats = NULL; +static GameWindow *checkBoxRandomWeather = NULL; static GameWindow *checkBoxLimitSuperweapons = NULL; static GameWindow *comboBoxStartingCash = NULL; static GameWindow *checkBoxLimitArmies = NULL; @@ -961,10 +963,60 @@ static void handleLimitSuperweaponsClick() #endif } +static void createRandomWeatherCheckbox() +{ + checkBoxRandomWeatherID = NAMEKEY("GameSpyGameOptionsMenu.wnd:CheckBoxRandomWeather"); + checkBoxRandomWeather = TheWindowManager->winGetWindowFromId(parentWOLGameSetup, checkBoxRandomWeatherID); + if (!checkBoxRandomWeather) + { + Int width, height, chatWidth, chatHeight, chatX, chatY; + Int screenX, screenY, chatScreenX, chatScreenY, parentX, parentY; + checkBoxLimitSuperweapons->winGetSize(&width, &height); + listboxGameSetupChat->winGetSize(&chatWidth, &chatHeight); + listboxGameSetupChat->winGetPosition(&chatX, &chatY); + checkBoxLimitSuperweapons->winGetScreenPosition(&screenX, &screenY); + listboxGameSetupChat->winGetScreenPosition(&chatScreenX, &chatScreenY); + parentWOLGameSetup->winGetScreenPosition(&parentX, &parentY); + if (chatHeight <= height * 2) + return; + + // Reserve one row above the chat and reuse the active checkbox theme and scale. + checkBoxRandomWeather = TheWindowManager->gogoGadgetCheckbox(parentWOLGameSetup, + checkBoxLimitSuperweapons->winGetStatus(), screenX - parentX, chatScreenY - parentY, + width, height, checkBoxLimitSuperweapons->winGetInstanceData(), + checkBoxLimitSuperweapons->winGetFont(), FALSE); + if (!checkBoxRandomWeather) + return; + checkBoxRandomWeather->winSetWindowId(checkBoxRandomWeatherID); + listboxGameSetupChat->winSetPosition(chatX, chatY + height); + listboxGameSetupChat->winSetSize(chatWidth, chatHeight - height); + } + + WinInstanceData *data = checkBoxRandomWeather->winGetInstanceData(); + data->m_decoratedNameString = "GameSpyGameOptionsMenu.wnd:CheckBoxRandomWeather"; + data->m_textLabelString.clear(); + data->m_tooltipString.clear(); + checkBoxRandomWeather->winSetTooltip(UnicodeString::TheEmptyString); + GadgetCheckBoxSetText(checkBoxRandomWeather, UnicodeString(L"Random Weather")); +} + +static void refreshRandomWeatherCheckbox() +{ + if (!checkBoxRandomWeather || !TheNGMPGame) + return; + const Bool isHost = TheNGMPGame->amIHost(); + checkBoxRandomWeather->winHide(!isHost); + checkBoxRandomWeather->winEnable(isHost && !TheNGMPGame->IsCountdownStarted()); + if (GadgetCheckBoxIsChecked(checkBoxRandomWeather) != TheNGMPGame->getDynamicWeather()) + GadgetCheckBoxSetChecked(checkBoxRandomWeather, TheNGMPGame->getDynamicWeather()); +} + static void WOLLockSettings() { buttonBack->winEnable(false); checkBoxLimitSuperweapons->winEnable(false); + if (checkBoxRandomWeather) + checkBoxRandomWeather->winEnable(false); comboBoxStartingCash->winEnable(false); for (Int i = 0; i < MAX_SLOTS; ++i) @@ -1377,6 +1429,7 @@ void WOLDisplayGameOptions() Bool limitSuperweapons = (theGame->getSuperweaponRestriction() != 0); if ( limitSuperweapons != GadgetCheckBoxIsChecked(checkBoxLimitSuperweapons)) GadgetCheckBoxSetChecked( checkBoxLimitSuperweapons, limitSuperweapons ); + refreshRandomWeatherCheckbox(); Int itemCount = GadgetComboBoxGetLength(comboBoxStartingCash); Int index = 0; @@ -1655,6 +1708,7 @@ void InitWOLGameGadgets() #endif checkBoxLimitArmies = TheWindowManager->winGetWindowFromId( parentWOLGameSetup, checkBoxLimitArmiesID ); DEBUG_ASSERTCRASH(windowMap, ("Could not find the GameSpyGameOptionsMenu.wnd:CheckBoxLimitArmies" )); + createRandomWeatherCheckbox(); // Limit Armies can ONLY be set in the Host Game window (PopupHostGame.wnd) checkBoxLimitArmies->winEnable( false ); @@ -1851,6 +1905,7 @@ void DeinitWOLGameGadgets() windowMap = NULL; } checkBoxUseStats = NULL; + checkBoxRandomWeather = NULL; checkBoxLimitSuperweapons = NULL; comboBoxStartingCash = NULL; @@ -2472,6 +2527,7 @@ void WOLGameSetupMenuUpdate( WindowLayout * layout, void *userData) { // Refresh only the fast-changing connection indicators each frame. WOLRefreshConnectionIndicators(); + refreshRandomWeatherCheckbox(); // need to exit? if (NGMP_OnlineServicesManager::GetInstance() != nullptr && NGMP_OnlineServicesManager::GetInstance()->IsPendingFullTeardown()) @@ -4190,6 +4246,12 @@ WindowMsgHandledType WOLGameSetupMenuSystem( GameWindow *window, UnsignedInt msg { handleLimitSuperweaponsClick(); } + else if (controlID == checkBoxRandomWeatherID) + { + if (TheNGMPGame && TheNGMPGame->amIHost() && !TheNGMPGame->IsCountdownStarted()) + TheNGMPGame->setDynamicWeather(GadgetCheckBoxIsChecked(checkBoxRandomWeather)); + refreshRandomWeatherCheckbox(); + } else { NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index 1fa00d1b2e6..714583c46a1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -55,6 +55,7 @@ #include "Common/ThingFactory.h" #include "Common/Team.h" #include "Common/ThingTemplate.h" +#include "Common/TerrainTypes.h" #include "GameClient/Water.h" #include "GameClient/Snow.h" #include "Common/WellKnownKeys.h" @@ -120,6 +121,10 @@ struct QuitGameException {}; #include "../NextGenMP_defines.h" +#if defined(GENERALS_ONLINE) +#include +#endif + DECLARE_PERF_TIMER(SleepyMaintenance) #include "Common/UnitTimings.h" //Contains the DO_UNIT_TIMINGS define jba. @@ -314,6 +319,11 @@ void GameLogic::setDefaults(Bool loadingSaveGame) { m_frame = 0; m_hasUpdated = FALSE; +#if defined(GENERALS_ONLINE) + m_weatherRoll = 0; + m_weatherOverride = nullptr; + m_weatherHost = NAMEKEY_INVALID; +#endif #if defined(GENERALS_ONLINE_HIGH_FPS_SERVER) m_frameLegacy = 0; m_frameLegacyLast = 0; @@ -558,6 +568,9 @@ void GameLogic::reset() // clear any table of contents we have m_objectTOC.clear(); +#if defined(GENERALS_ONLINE) + const Bool hadWeatherPreset = m_weatherOverride != nullptr; +#endif setDefaults(FALSE); m_isScoringEnabled = TRUE; @@ -573,6 +586,10 @@ void GameLogic::reset() // Clean up any weather overrides that were generated for this map. WeatherSetting* ws = (WeatherSetting*)TheWeatherSetting.getNonOverloadedPointer(); TheWeatherSetting = (WeatherSetting*)ws->deleteOverrides(); +#if defined(GENERALS_ONLINE) + if (hadWeatherPreset && TheSnowManager && TheWeatherSetting != nullptr) + TheSnowManager->reloadWeather(); +#endif m_rankPointsToAddAtGameStart = 0; } @@ -1393,6 +1410,30 @@ void GameLogic::tryStartNewGame( Bool loadingSaveGame ) } } +#if defined(GENERALS_ONLINE) + m_weatherRoll = 0; + m_weatherOverride = nullptr; + m_weatherHost = NAMEKEY_INVALID; + if (TheNetwork && TheNGMPGame && game == TheNGMPGame && !TheNGMPGame->isQMGame()) + { + auto *lobbyInterface = NGMP_OnlineServicesManager::GetInterface(); + if (lobbyInterface) + { + const LobbyEntry &lobby = lobbyInterface->GetCurrentLobby(); + for (const LobbyMemberEntry &member : lobby.members) + { + if (member.IsHuman() && member.user_id == lobby.owner && member.m_SlotIndex < MAX_SLOTS) + { + AsciiString name; + name.format("player%d", static_cast(member.m_SlotIndex)); + m_weatherHost = TheNameKeyGenerator->nameToKey(name); + break; + } + } + } + } +#endif + checkForDuplicateColors(game); Bool isSkirmishOrSkirmishReplay = FALSE; @@ -2604,6 +2645,181 @@ static void findAndSelectCommandCenter(Object *obj, void* alreadyFound) // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ +#if defined(GENERALS_ONLINE) +static Int getDynamicWeatherProfileFromTerrain() +{ + if (TheGlobalData->m_weather == WEATHER_SNOWY) + return WeatherSetting::DYNAMIC_SNOW; + + Region3D extent; + TheTerrainLogic->getExtent(&extent); + if (!TheTerrainVisual || extent.hi.x <= extent.lo.x || extent.hi.y <= extent.lo.y) + return WeatherSetting::DYNAMIC_DRY; + + Int snow = 0; + Int desert = 0; + Int temperate = 0; + // A regular grid weights materials by their coverage instead of counting texture names. + const Int samplesPerAxis = 32; + for (Int y = 0; y < samplesPerAxis; ++y) + { + const Real worldY = extent.lo.y + (y + 0.5f) * (extent.hi.y - extent.lo.y) / samplesPerAxis; + for (Int x = 0; x < samplesPerAxis; ++x) + { + const Real worldX = extent.lo.x + (x + 0.5f) * (extent.hi.x - extent.lo.x) / samplesPerAxis; + TerrainType *terrain = TheTerrainVisual->getTerrainTile(worldX, worldY); + if (!terrain) + continue; + + switch (terrain->getClass()) + { + case TERRAIN_SNOW_1: + case TERRAIN_SNOW_2: + case TERRAIN_SNOW_3: + case TERRAIN_RUGGED_SNOW: + case TERRAIN_FLAT_SNOW: + ++snow; + break; + case TERRAIN_DESERT_1: + case TERRAIN_DESERT_2: + case TERRAIN_DESERT_3: + case TERRAIN_LIVE_DESERT: + case TERRAIN_DRY_DESERT: + case TERRAIN_ACCENT_SAND: + case TERRAIN_SAND: + ++desert; + break; + case TERRAIN_EASTERN_EUROPE_1: + case TERRAIN_EASTERN_EUROPE_2: + case TERRAIN_EASTERN_EUROPE_3: + case TERRAIN_SWISS_1: + case TERRAIN_SWISS_2: + case TERRAIN_SWISS_3: + case TERRAIN_DIRT: + case TERRAIN_GRASS: + case TERRAIN_TROPICAL_BEACH: + case TERRAIN_BEACH_PARK: + case TERRAIN_COBBLESTONE_GRASS: + case TERRAIN_ACCENT_GRASS: + case TERRAIN_RESIDENTIAL: + case TERRAIN_FIELD: + case TERRAIN_ASPHALT: + case TERRAIN_CONCRETE: + case TERRAIN_CHINA: + case TERRAIN_URBAN: + ++temperate; + break; + } + } + } + + if (snow > 0 && snow >= desert && snow >= temperate) + return WeatherSetting::DYNAMIC_SNOW; + if (temperate > desert) + return WeatherSetting::DYNAMIC_RAIN; + return WeatherSetting::DYNAMIC_DRY; +} + +void GameLogic::startDynamicWeather(const Player *sender, Int debugProfile) +{ + const Bool debugRoll = debugProfile >= WeatherSetting::DYNAMIC_AUTO; + if (!TheGameInfo || (m_weatherRoll != 0 && !debugRoll)) + return; + + const Bool replay = TheRecorder && TheRecorder->isPlaybackMode(); + if (!replay) + { + if (TheNetwork) + { + if (m_weatherHost == NAMEKEY_INVALID || sender->getPlayerNameKey() != m_weatherHost) + return; + } + else if (!isInSkirmishGame() || sender != ThePlayerList->getLocalPlayer()) + return; + } + + // Each roll is reproducible in multiplayer and replays without consuming logic randomness. + std::mt19937 weatherRandom(static_cast(TheGameInfo->getSeed()) + m_weatherRoll); + ++m_weatherRoll; + const TimeOfDay time = static_cast( + TIME_OF_DAY_FIRST + weatherRandom() % (TIME_OF_DAY_COUNT - TIME_OF_DAY_FIRST)); + const Bool randomPrecipitation = (weatherRandom() & 1u) != 0; + Int profile = WeatherSetting::DYNAMIC_DRY; + Bool precipitation = FALSE; + if (TheSnowManager && TheWeatherSetting != nullptr) + { + const Int configuredProfile = TheWeatherSetting->m_dynamicWeatherProfile; + profile = debugRoll && debugProfile != WeatherSetting::DYNAMIC_AUTO ? debugProfile : configuredProfile; + if (profile == WeatherSetting::DYNAMIC_AUTO) + profile = getDynamicWeatherProfileFromTerrain(); + precipitation = profile != WeatherSetting::DYNAMIC_DRY + && (randomPrecipitation || (debugRoll && debugProfile != WeatherSetting::DYNAMIC_AUTO)); + if (precipitation && profile == WeatherSetting::DYNAMIC_RAIN + && !(debugRoll && debugProfile == WeatherSetting::DYNAMIC_RAIN)) + { + profile = WeatherSetting::DYNAMIC_RAIN + weatherRandom() % 3; + } + + if (precipitation) + { + if (!m_weatherOverride) + { + // Reuse one temporary override for all debug rolls. Map cleanup owns it. + m_weatherOverride = newInstance(WeatherSetting); + m_weatherOverride->m_dynamicWeatherProfile = configuredProfile; + m_weatherOverride->markAsOverride(); + auto *base = const_cast(TheWeatherSetting.getNonOverloadedPointer()); + base->friend_getFinalOverride()->setNextOverride(m_weatherOverride); + } + + WeatherSetting *weather = m_weatherOverride; + struct RainPreset + { + Real density; + Real amplitude; + Real pointSize; + Real quadSize; + }; + static const RainPreset rainPresets[] = { + { 0.35f, 0.1f, 0.18f, 0.06f }, // Light rain + { 1.0f, 0.1f, 0.3f, 0.1f }, // Heavy rain + { 1.4f, 0.5f, 0.3f, 0.1f } // Storm + }; + const RainPreset *rain = profile >= WeatherSetting::DYNAMIC_RAIN + ? &rainPresets[profile - WeatherSetting::DYNAMIC_RAIN] : nullptr; + weather->m_snowEnabled = TRUE; + weather->m_snowTexture = rain ? "EXRainDrop.tga" : "EXSnowFlake.tga"; + weather->m_snowBoxDimensions = 100.0f; + weather->m_snowBoxDensity = rain ? rain->density : 1.0f; + weather->m_snowFrequencyScaleX = rain ? 1.0f : 0.0533f; + weather->m_snowFrequencyScaleY = rain ? 1.0f : 0.0275f; + weather->m_snowAmplitude = rain ? rain->amplitude : 4.0f; + weather->m_snowVelocity = rain ? 25.0f : 3.0f; + weather->m_snowPointSize = rain ? rain->pointSize : 0.16f; + weather->m_snowQuadSize = rain ? rain->quadSize : 0.5f; + weather->m_snowMaxPointSize = rain ? 64.0f : 10.0f; + TheSnowManager->reloadWeather(); + } + TheSnowManager->setDynamicWeatherVisible(precipitation); + TheSnowManager->setDynamicRain(precipitation ? profile : WeatherSetting::DYNAMIC_DRY, weatherRandom()); + } + + if (TheWritableGlobalData->setTimeOfDay(time)) + TheGameClient->setTimeOfDay(time); + +#if GENERALS_ONLINE_WEATHER_DEBUG + if (debugRoll && TheInGameUI) + { + static const char *const profileNames[] = { "AUTO", "DRY", "SNOW", "LIGHT RAIN", "HEAVY RAIN", "STORM" }; + UnicodeString message; + message.format(L"Weather #%u: %hs / %hs (profile %hs)", m_weatherRoll, + TimeOfDayNames[time], precipitation ? profileNames[profile] : "DRY", profileNames[profile]); + TheInGameUI->message(message); + } +#endif +} +#endif + void GameLogic::loadMapINI(AsciiString mapName) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp index 62f7b703cba..265db65551a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp @@ -582,6 +582,7 @@ void NGMPGame::reset(void) { GameInfo::reset(); m_isQM = FALSE; + m_dynamicWeather = TRUE; } void NGMPGame::StartCountdown()