Skip to content

Commit 3631d56

Browse files
committed
unify(client): Merge DisplayString, GameText, GlobalLanguage, SelectionInfo code (TheSuperHackers#2337)
1 parent 09f3a84 commit 3631d56

File tree

10 files changed

+55
-17
lines changed

10 files changed

+55
-17
lines changed

Generals/Code/GameEngine/Include/GameClient/ClientInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** Command & Conquer Generals Zero Hour(tm)
2+
** Command & Conquer Generals(tm)
33
** Copyright 2025 TheSuperHackers
44
**
55
** This program is free software: you can redistribute it and/or modify

Generals/Code/GameEngine/Include/GameClient/GlobalLanguage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class GlobalLanguage : public SubsystemInterface
9090
AsciiString m_unicodeFontFileName;
9191
Bool m_useHardWrap;
9292
Int m_militaryCaptionSpeed;
93+
Int m_militaryCaptionDelayMS;
9394
FontDesc m_copyrightFont;
9495
FontDesc m_messageFont;
9596
FontDesc m_militaryCaptionTitleFont;

Generals/Code/GameEngine/Include/GameClient/SelectionInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ struct PickDrawableStruct
6464
{
6565
// List to fill with Drawables. This should be provided by the caller.
6666
DrawableList *drawableListToFill;
67+
68+
Bool isPointSelection;
6769
Bool forceAttackMode;
6870

6971
// Note, this is OR'd with the things we are attempting to select.

Generals/Code/GameEngine/Source/GameClient/ClientInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** Command & Conquer Generals Zero Hour(tm)
2+
** Command & Conquer Generals(tm)
33
** Copyright 2025 TheSuperHackers
44
**
55
** This program is free software: you can redistribute it and/or modify

Generals/Code/GameEngine/Source/GameClient/DisplayString.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void DisplayString::removeLastChar( void )
136136
// DisplayString::truncateBy ==================================================
137137
/** Remove the last charCount characters from the string text */
138138
//=============================================================================
139-
void DisplayString::truncateBy(const Int charCount)
139+
void DisplayString::truncateBy( const Int charCount )
140140
{
141141
m_textString.truncateBy(charCount);
142142

@@ -148,8 +148,8 @@ void DisplayString::truncateBy(const Int charCount)
148148
// DisplayString::truncateTo ==================================================
149149
/** Remove the last characters from the string text so it's at the most
150150
* maxLength characters long */
151-
//=============================================================================
152-
void DisplayString::truncateTo(const Int maxLength)
151+
//=============================================================================
152+
void DisplayString::truncateTo( const Int maxLength )
153153
{
154154
m_textString.truncateTo(maxLength);
155155

Generals/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static const FieldParse TheGlobalLanguageDataFieldParseTable[] =
8787
{ "CopyrightFont", GlobalLanguage::parseFontDesc, nullptr, offsetof( GlobalLanguage, m_copyrightFont ) },
8888
{ "MessageFont", GlobalLanguage::parseFontDesc, nullptr, offsetof( GlobalLanguage, m_messageFont) },
8989
{ "MilitaryCaptionTitleFont", GlobalLanguage::parseFontDesc, nullptr, offsetof( GlobalLanguage, m_militaryCaptionTitleFont) },
90+
{ "MilitaryCaptionDelayMS", INI::parseInt, nullptr, offsetof( GlobalLanguage, m_militaryCaptionDelayMS ) },
9091
{ "MilitaryCaptionFont", GlobalLanguage::parseFontDesc, nullptr, offsetof( GlobalLanguage, m_militaryCaptionFont) },
9192
{ "SuperweaponCountdownNormalFont", GlobalLanguage::parseFontDesc, nullptr, offsetof( GlobalLanguage, m_superweaponCountdownNormalFont) },
9293
{ "SuperweaponCountdownReadyFont", GlobalLanguage::parseFontDesc, nullptr, offsetof( GlobalLanguage, m_superweaponCountdownReadyFont) },
@@ -128,6 +129,7 @@ GlobalLanguage::GlobalLanguage()
128129
m_useHardWrap = FALSE;
129130
m_resolutionFontSizeAdjustment = 0.7f;
130131
m_resolutionFontSizeMethod = ResolutionFontSizeMethod_Default;
132+
m_militaryCaptionDelayMS = 750;
131133

132134
m_userResolutionFontSizeAdjustment = -1.0f;
133135
}
@@ -152,7 +154,7 @@ void GlobalLanguage::init( void )
152154

153155
INI ini;
154156
ini.loadFileDirectory( fname, INI_LOAD_OVERWRITE, nullptr );
155-
}
157+
}
156158

157159
StringListIt it = m_localFonts.begin();
158160
while( it != m_localFonts.end())

Generals/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
596596
DrawableList drawablesThatWillSelect;
597597
PickDrawableStruct pds;
598598
pds.drawableListToFill = &drawablesThatWillSelect;
599+
pds.isPointSelection = isPoint;
599600
TheTacticalView->iterateDrawablesInRegion(&selectionRegion, addDrawableToList, &pds);
600601

601602
if (drawablesThatWillSelect.empty())

Generals/Code/GameEngine/Source/GameClient/SelectionInfo.cpp

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@
2323
////////////////////////////////////////////////////////////////////////////////
2424

2525
#include "PreRTS.h"
26-
#include "GameClient/SelectionInfo.h"
2726

28-
#include "Common/ActionManager.h"
2927
#include "GameLogic/Damage.h"
30-
#include "Common/Player.h"
31-
#include "Common/PlayerList.h"
28+
#include "GameLogic/Module/ContainModule.h"
29+
30+
#include "Common/ActionManager.h"
3231
#include "Common/ThingTemplate.h"
32+
#include "Common/PlayerList.h"
33+
#include "Common/Player.h"
3334

35+
#include "GameClient/SelectionInfo.h"
3436
#include "GameClient/CommandXlat.h"
3537
#include "GameClient/ControlBar.h"
3638
#include "GameClient/Drawable.h"
@@ -61,9 +63,8 @@ SelectionInfo::SelectionInfo() :
6163
{ }
6264

6365
//-------------------------------------------------------------------------------------------------
64-
PickDrawableStruct::PickDrawableStruct() : drawableListToFill(nullptr)
66+
PickDrawableStruct::PickDrawableStruct() : drawableListToFill(nullptr), isPointSelection(FALSE)
6567
{
66-
drawableListToFill = FALSE;
6768
forceAttackMode = TheInGameUI->isInForceAttackMode();
6869
UnsignedInt pickType = getPickTypesForContext(forceAttackMode);
6970
translatePickTypesToKindof(pickType, kindofsToMatch);
@@ -360,7 +361,36 @@ Bool addDrawableToList( Drawable *draw, void *userData )
360361
return FALSE;
361362

362363
if (!draw->isSelectable())
363-
return FALSE;
364+
{
365+
const Object *obj = draw->getObject();
366+
if ( obj && obj->getContainedBy() )//hmm, interesting... he is not selectable but he is contained
367+
{// What we are after here is to propagate the selection the selection ti the container
368+
// if the container is non-enclosing... see also SelectionXlat, in the left_click case
369+
370+
ContainModuleInterface *contain = obj->getContainedBy()->getContain();
371+
Drawable *containDraw = obj->getContainedBy()->getDrawable();
372+
if (contain && ! contain->isEnclosingContainerFor( obj ) && containDraw )
373+
return addDrawableToList( containDraw, userData );
374+
}
375+
else
376+
return FALSE;
377+
}
378+
379+
#if !RTS_GENERALS && PRESERVE_RETAIL_BEHAVIOR
380+
// TheSuperHackers @info
381+
// In retail, hidden objects such as passengers are included here when drag-selected, which causes
382+
// enemy selection logic to exit early (only 1 enemy unit can be selected at a time). Some players
383+
// exploit this bug to determine if a transport contains passengers and consider this an important
384+
// feature and an advanced skill to pull off, so we must leave the exploit.
385+
if (!pds->isPointSelection)
386+
{
387+
const Object *obj = draw->getObject();
388+
if (obj)
389+
if (obj->getControllingPlayer() != ThePlayerList->getLocalPlayer())
390+
if (obj->getContain() && draw->getObject()->getContain()->getContainCount() > 0)
391+
return FALSE;
392+
}
393+
#endif
364394

365395
pds->drawableListToFill->push_back(draw);
366396
return TRUE;

GeneralsMD/Code/GameEngine/Source/GameClient/GameText.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ GameTextManager::GameTextManager()
266266
m_buffer2[i] = 0;
267267
m_buffer3[i] = 0;
268268
}
269-
//
270269
}
271270

272271
//============================================================================
@@ -1459,4 +1458,3 @@ static int __cdecl compareLUT ( const void *i1, const void*i2)
14591458

14601459
return stricmp( lut1->label->str(), lut2->label->str());
14611460
}
1462-

GeneralsMD/Code/GameEngine/Source/GameClient/SelectionInfo.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
#include "GameClient/SelectionInfo.h"
3636
#include "GameClient/CommandXlat.h"
3737
#include "GameClient/ControlBar.h"
38-
#include "GameClient/GameClient.h"
3938
#include "GameClient/Drawable.h"
39+
#include "GameClient/GameClient.h"
4040
#include "GameClient/KeyDefs.h"
4141

4242

@@ -202,7 +202,7 @@ extern Bool contextCommandForNewSelection(const DrawableList *currentlySelectedD
202202

203203
if (outSelectionInfo->newCountMine > 0) {
204204
if (outSelectionInfo->newCountMine == 1 && selectionIsPoint && !TheInGameUI->isInPreferSelectionMode()) {
205-
return TheGameClient->evaluateContextCommand(newMine, newMine->getPosition(), CommandTranslator::EVALUATE_ONLY) != GameMessage::MSG_INVALID;
205+
return TheGameClient->evaluateContextCommand(newMine, newMine->getPosition(), CommandTranslator::EVALUATE_ONLY) != GameMessage::MSG_INVALID;
206206
}
207207

208208
return FALSE;
@@ -346,6 +346,10 @@ Bool addDrawableToList( Drawable *draw, void *userData )
346346
return FALSE;
347347

348348
#if !RTS_GENERALS || !PRESERVE_RETAIL_BEHAVIOR
349+
// TheSuperHackers @info
350+
// In retail, drag-selecting allows the player to select stealthed objects and objects through the
351+
// fog. Some players exploit this bug to determine where an opponent's units are and consider this
352+
// an important feature and an advanced skill to pull off, so we must leave the exploit.
349353
if (draw->getFullyObscuredByShroud())
350354
return FALSE;
351355

0 commit comments

Comments
 (0)