Skip to content

Commit e7af119

Browse files
committed
unify(userpreferences): Merge UserPreferences and related code (TheSuperHackers#2182)
1 parent 2fb478a commit e7af119

8 files changed

Lines changed: 76 additions & 9 deletions

File tree

Generals/Code/GameEngine/Include/Common/GlobalData.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class GlobalData : public SubsystemInterface
110110
Bool m_useTrees;
111111
Bool m_useTreeSway;
112112
Bool m_useDrawModuleLOD;
113+
Bool m_useHeatEffects;
113114
Bool m_useFpsLimit;
114115
Bool m_dumpAssetUsage;
115116
Int m_framesPerSecondLimit;
@@ -138,6 +139,8 @@ class GlobalData : public SubsystemInterface
138139
Bool m_enableStaticLOD;
139140
Int m_terrainLODTargetTimeMS;
140141
Bool m_useAlternateMouse;
142+
Bool m_clientRetaliationModeEnabled;
143+
Bool m_doubleClickAttackMove;
141144
Bool m_rightMouseAlwaysScrolls;
142145
Bool m_useWaterPlane;
143146
Bool m_useCloudPlane;

Generals/Code/GameEngine/Include/Common/PlayerTemplate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class PlayerTemplate
125125

126126
AsciiString getLoadScreenMusic( void ) const {return m_loadScreenMusic; }
127127

128+
Bool isOldFaction( void ) const { return m_oldFaction; }
128129

129130
static const FieldParse* getFieldParse();
130131

@@ -162,6 +163,7 @@ class PlayerTemplate
162163
AsciiString m_tooltip; ///< The tooltip describing this player template
163164
Bool m_observer;
164165
Bool m_playableSide;
166+
Bool m_oldFaction; ///< Faction existed in the original Generals
165167

166168
Int m_intrinsicSPP;
167169

Generals/Code/GameEngine/Include/Common/UserPreferences.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class OptionPreferences : public UserPreferences
9191
void setOnlineIPAddress(UnsignedInt IP); // convenience function
9292
Bool getArchiveReplaysEnabled() const; // convenience function
9393
Bool getAlternateMouseModeEnabled(void); // convenience function
94+
Bool getRetaliationModeEnabled(); // convenience function
95+
Bool getDoubleClickAttackMoveEnabled(void); // convenience function
9496
Real getScrollFactor(void); // convenience function
9597
Bool getDrawScrollAnchor(void);
9698
Bool getMoveScrollAnchor(void);
@@ -130,6 +132,7 @@ class OptionPreferences : public UserPreferences
130132
Bool getSmoothWaterEnabled(void);
131133
Bool getTreesEnabled(void);
132134
Bool getExtraAnimationsDisabled(void);
135+
Bool getUseHeatEffects(void);
133136
Bool getDynamicLODEnabled(void);
134137
Bool getFPSLimitEnabled(void);
135138
Bool getNoDynamicLODEnabled(void);

Generals/Code/GameEngine/Source/Common/GlobalData.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ GlobalData* GlobalData::m_theOriginal = nullptr;
311311
{ "MaxTranslucentObjects", INI::parseInt, nullptr, offsetof( GlobalData, m_maxVisibleTranslucentObjects) },
312312
{ "OccludedColorLuminanceScale", INI::parseReal, nullptr, offsetof( GlobalData, m_occludedLuminanceScale) },
313313

314-
/* These are internal use only, they do not need file definitons
314+
/* These are internal use only, they do not need file definitions
315315
{ "TerrainAmbientRGB", INI::parseRGBColor, nullptr, offsetof( GlobalData, m_terrainAmbient ) },
316316
{ "TerrainDiffuseRGB", INI::parseRGBColor, nullptr, offsetof( GlobalData, m_terrainDiffuse ) },
317317
{ "TerrainLightPos", INI::parseCoord3D, nullptr, offsetof( GlobalData, m_terrainLightPos ) },
@@ -331,7 +331,7 @@ GlobalData* GlobalData::m_theOriginal = nullptr;
331331
{ "VideoOn", INI::parseBool, nullptr, offsetof( GlobalData, m_videoOn ) },
332332
{ "DisableCameraMovements", INI::parseBool, nullptr, offsetof( GlobalData, m_disableCameraMovement ) },
333333

334-
/* These are internal use only, they do not need file definitons
334+
/* These are internal use only, they do not need file definitions
335335
/// @todo remove this hack
336336
{ "InGame", INI::parseBool, nullptr, offsetof( GlobalData, m_inGame ) },
337337
*/
@@ -365,7 +365,7 @@ GlobalData* GlobalData::m_theOriginal = nullptr;
365365
{ "AutoAflameParticleSystem", INI::parseAsciiString, nullptr, offsetof( GlobalData, m_autoAflameParticleSystem ) },
366366
{ "AutoAflameParticleMax", INI::parseInt, nullptr, offsetof( GlobalData, m_autoAflameParticleMax ) },
367367

368-
/* These are internal use only, they do not need file definitons
368+
/* These are internal use only, they do not need file definitions
369369
{ "LatencyAverage", INI::parseInt, nullptr, offsetof( GlobalData, m_latencyAverage ) },
370370
{ "LatencyAmplitude", INI::parseInt, nullptr, offsetof( GlobalData, m_latencyAmplitude ) },
371371
{ "LatencyPeriod", INI::parseInt, nullptr, offsetof( GlobalData, m_latencyPeriod ) },
@@ -621,6 +621,7 @@ GlobalData::GlobalData()
621621
m_useTrees = 0;
622622
m_useTreeSway = TRUE;
623623
m_useDrawModuleLOD = FALSE;
624+
m_useHeatEffects = TRUE;
624625
m_useFpsLimit = FALSE;
625626
m_dumpAssetUsage = FALSE;
626627
m_framesPerSecondLimit = 0;
@@ -1027,6 +1028,8 @@ GlobalData::GlobalData()
10271028

10281029
m_keyboardCameraRotateSpeed = 0.1f;
10291030

1031+
m_clientRetaliationModeEnabled = TRUE; //On by default.
1032+
10301033
}
10311034

10321035
//-------------------------------------------------------------------------------------------------
@@ -1182,7 +1185,9 @@ void GlobalData::parseGameDataDefinition( INI* ini )
11821185

11831186
// override INI values with user preferences
11841187
OptionPreferences optionPref;
1185-
TheWritableGlobalData->m_useAlternateMouse = optionPref.getAlternateMouseModeEnabled();
1188+
TheWritableGlobalData->m_useAlternateMouse = optionPref.getAlternateMouseModeEnabled();
1189+
TheWritableGlobalData->m_clientRetaliationModeEnabled = optionPref.getRetaliationModeEnabled();
1190+
TheWritableGlobalData->m_doubleClickAttackMove = optionPref.getDoubleClickAttackMoveEnabled();
11861191
TheWritableGlobalData->m_keyboardScrollFactor = optionPref.getScrollFactor();
11871192
TheWritableGlobalData->m_drawScrollAnchor = optionPref.getDrawScrollAnchor();
11881193
TheWritableGlobalData->m_moveScrollAnchor = optionPref.getMoveScrollAnchor();

Generals/Code/GameEngine/Source/Common/RTS/PlayerTemplate.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
{ "SpecialPowerShortcutWinName" ,INI::parseAsciiString, nullptr, offsetof( PlayerTemplate, m_specialPowerShortcutWinName) },
9595
{ "SpecialPowerShortcutButtonCount",INI::parseInt, nullptr, offsetof( PlayerTemplate, m_specialPowerShortcutButtonCount ) },
9696
{ "IsObserver", INI::parseBool, nullptr, offsetof( PlayerTemplate, m_observer ) },
97+
{ "OldFaction", INI::parseBool, nullptr, offsetof( PlayerTemplate, m_oldFaction ) },
9798
{ "IntrinsicSciencePurchasePoints", INI::parseInt, nullptr, offsetof( PlayerTemplate, m_intrinsicSPP ) },
9899
{ "ScoreScreenImage", INI::parseAsciiString, nullptr, offsetof( PlayerTemplate, m_scoreScreenImage ) },
99100
{ "LoadScreenImage", INI::parseAsciiString, nullptr, offsetof( PlayerTemplate, m_loadScreenImage ) },
@@ -183,6 +184,7 @@ PlayerTemplate::PlayerTemplate() :
183184
m_nameKey(NAMEKEY_INVALID),
184185
m_observer(false),
185186
m_playableSide(false),
187+
m_oldFaction(false),
186188
m_intrinsicSPP(0),
187189
m_specialPowerShortcutButtonCount(0)
188190
{

Generals/Code/GameEngine/Source/Common/UserPreferences.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "Common/QuotedPrintable.h"
4949
#include "Common/MultiplayerSettings.h"
5050
#include "GameClient/MapUtil.h"
51+
#include "GameClient/ChallengeGenerals.h"
5152
#include "GameNetwork/GameSpy/PeerDefs.h"
5253

5354

@@ -529,6 +530,18 @@ Int CustomMatchPreferences::getPreferredFaction(void)
529530
ret = PLAYERTEMPLATE_RANDOM;
530531
else if (fac->getStartingBuilding().isEmpty())
531532
ret = PLAYERTEMPLATE_RANDOM;
533+
else if (TheGameInfo && TheGameInfo->oldFactionsOnly() && !fac->isOldFaction())
534+
ret = PLAYERTEMPLATE_RANDOM;
535+
else {
536+
// Prevent from loading the disabled Generals, in case you had previously selected one as your preferred faction.
537+
// This is also enforced at GUI setup (GUIUtil.cpp and GameLogic.cpp).
538+
// @todo: unlock these when something rad happens
539+
Bool disallowLockedGenerals = TRUE;
540+
const GeneralPersona *general = TheChallengeGenerals->getGeneralByTemplateName(fac->getName());
541+
Bool startsLocked = general ? !general->isStartingEnabled() : FALSE;
542+
if (disallowLockedGenerals && startsLocked)
543+
ret = PLAYERTEMPLATE_RANDOM;
544+
}
532545
}
533546

534547
return ret;
@@ -650,19 +663,22 @@ AsciiString CustomMatchPreferences::getPreferredMap(void)
650663
AsciiString ret;
651664
CustomMatchPreferences::const_iterator it = find("Map");
652665
if (it == end())
653-
{
654-
ret = getDefaultMap(TRUE);
666+
{ //map not found, use default instead
667+
ret = getDefaultOfficialMap();
655668
return ret;
656669
}
657670

658671
ret = QuotedPrintableToAsciiString(it->second);
659672
ret.trim();
660673
if (ret.isEmpty() || !isValidMap(ret, TRUE))
661-
{
662-
ret = getDefaultMap(TRUE);
674+
{ //map is invalid, use default instead
675+
ret = getDefaultOfficialMap();
663676
return ret;
664677
}
665678

679+
//can only use official maps if recording stats
680+
if( getUseStats() && !isOfficialMap(ret) )
681+
ret = getDefaultOfficialMap();
666682
return ret;
667683
}
668684

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,29 @@ Bool OptionPreferences::getAlternateMouseModeEnabled(void)
330330
return FALSE;
331331
}
332332

333+
Bool OptionPreferences::getRetaliationModeEnabled(void)
334+
{
335+
OptionPreferences::const_iterator it = find("Retaliation");
336+
if (it == end())
337+
return TheGlobalData->m_clientRetaliationModeEnabled;
338+
339+
if (stricmp(it->second.str(), "yes") == 0) {
340+
return TRUE;
341+
}
342+
return FALSE;
343+
}
344+
345+
Bool OptionPreferences::getDoubleClickAttackMoveEnabled(void)
346+
{
347+
OptionPreferences::const_iterator it = find("UseDoubleClickAttackMove");
348+
if( it == end() )
349+
return TheGlobalData->m_doubleClickAttackMove;
350+
351+
if( stricmp( it->second.str(), "yes" ) == 0 )
352+
return TRUE;
353+
354+
return FALSE;
355+
}
333356

334357
Real OptionPreferences::getScrollFactor(void)
335358
{
@@ -729,6 +752,18 @@ Bool OptionPreferences::getExtraAnimationsDisabled(void)
729752
return TRUE;
730753
}
731754

755+
Bool OptionPreferences::getUseHeatEffects(void)
756+
{
757+
OptionPreferences::const_iterator it = find("HeatEffects");
758+
if (it == end())
759+
return TheGlobalData->m_useHeatEffects;
760+
761+
if (stricmp(it->second.str(), "yes") == 0) {
762+
return TRUE;
763+
}
764+
return FALSE;
765+
}
766+
732767
Bool OptionPreferences::getDynamicLODEnabled(void)
733768
{
734769
OptionPreferences::const_iterator it = find("DynamicLOD");

GeneralsMD/Code/GameEngine/Source/Common/UserPreferences.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ AsciiString CustomMatchPreferences::getPreferredMap(void)
663663
AsciiString ret;
664664
CustomMatchPreferences::const_iterator it = find("Map");
665665
if (it == end())
666-
{ //found find map, use default instead
666+
{ //map not found, use default instead
667667
ret = getDefaultOfficialMap();
668668
return ret;
669669
}
@@ -814,6 +814,7 @@ Int GameSpyMiscPreferences::getMaxMessagesPerUpdate( void )
814814
{
815815
return getInt("MaxMessagesPerUpdate", 100);
816816
}
817+
817818
//-----------------------------------------------------------------------------
818819
// IgnorePreferences base class
819820
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)