Skip to content

Commit d5e1088

Browse files
committed
unify(ini): Merge INI and related code (TheSuperHackers#2180)
1 parent f7c898f commit d5e1088

9 files changed

Lines changed: 375 additions & 11 deletions

File tree

Generals/Code/GameEngine/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ set(GAMEENGINE_SRC
132132
# Include/Common/XferSave.h
133133
Include/GameClient/Anim2D.h
134134
Include/GameClient/AnimateWindowManager.h
135+
Include/GameClient/ChallengeGenerals.h
135136
Include/GameClient/CampaignManager.h
136137
Include/GameClient/CDCheck.h
137138
Include/GameClient/ClientInstance.h
@@ -657,6 +658,7 @@ set(GAMEENGINE_SRC
657658
Source/GameClient/GlobalLanguage.cpp
658659
Source/GameClient/GraphDraw.cpp
659660
Source/GameClient/GUI/AnimateWindowManager.cpp
661+
Source/GameClient/GUI/ChallengeGenerals.cpp
660662
Source/GameClient/GUI/ControlBar/ControlBar.cpp
661663
Source/GameClient/GUI/ControlBar/ControlBarBeacon.cpp
662664
Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ typedef void (*BuildMultiIniFieldProc)(MultiIniFieldParse& p);
160160
//-------------------------------------------------------------------------------------------------
161161
class INI
162162
{
163+
INI(const INI&);
164+
INI& operator=(const INI&);
163165

164166
public:
165167

@@ -217,6 +219,7 @@ class INI
217219
static void parseObjectCreationListDefinition( INI* ini );
218220
static void parseMultiplayerSettingsDefinition( INI* ini );
219221
static void parseMultiplayerColorDefinition( INI* ini );
222+
static void parseMultiplayerStartingMoneyChoiceDefinition( INI* ini );
220223
static void parseOnlineChatColorDefinition( INI* ini );
221224
static void parseMapCacheDefinition( INI* ini );
222225
static void parseVideoDefinition( INI* ini );
@@ -243,7 +246,7 @@ class INI
243246
static void parseEvaEvent( INI* ini );
244247
static void parseCredits( INI* ini );
245248
static void parseWindowTransitions( INI* ini );
246-
249+
static void parseChallengeModeDefinition( INI* ini );
247250

248251
AsciiString getFilename( void ) const { return m_filename; }
249252
INILoadType getLoadType( void ) const { return m_loadType; }
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
** Command & Conquer Generals(tm)
3+
** Copyright 2025 Electronic Arts Inc.
4+
**
5+
** This program is free software: you can redistribute it and/or modify
6+
** it under the terms of the GNU General Public License as published by
7+
** the Free Software Foundation, either version 3 of the License, or
8+
** (at your option) any later version.
9+
**
10+
** This program is distributed in the hope that it will be useful,
11+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
** GNU General Public License for more details.
14+
**
15+
** You should have received a copy of the GNU General Public License
16+
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
////////////////////////////////////////////////////////////////////////////////
20+
// //
21+
// (c) 2001-2003 Electronic Arts Inc. //
22+
// //
23+
////////////////////////////////////////////////////////////////////////////////
24+
25+
// FILE: ChallengeGenerals.h //////////////////////////////////////////////////////////////////////
26+
// Author: Steve Copeland, 6/24/2003
27+
// Desc: This is a manager for data pertaining to the Generals' Challenge personas and related GUI.
28+
///////////////////////////////////////////////////////////////////////////////////////////////////
29+
30+
#pragma once
31+
32+
// INCLUDES //////////////////////////////////////////////////////////////////////////////////
33+
#include "Common/GameType.h"
34+
#include "Common/INI.h"
35+
#include "Common/Overridable.h"
36+
37+
// DEFINES ////////////////////////////////////////////////////////////////////////////////////////
38+
//static const Int NUM_GENERALS = 12; // ChallengeMenu.wnd dependent
39+
#define NUM_GENERALS (12)
40+
41+
// FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
42+
class Image;
43+
44+
// CLASS DEFINITIONS //////////////////////////////////////////////////////////////////////////////
45+
class GeneralPersona
46+
{
47+
friend class ChallengeGenerals;
48+
49+
private:
50+
Bool m_bStartsEnabled;
51+
AsciiString m_strBioName;
52+
AsciiString m_strBioDOB;
53+
AsciiString m_strBioBirthplace;
54+
AsciiString m_strBioStrategy;
55+
AsciiString m_strBioRank;
56+
AsciiString m_strBioBranch;
57+
AsciiString m_strBioClassNumber;
58+
Image *m_imageBioPortraitSmall;
59+
Image *m_imageBioPortraitLarge;
60+
AsciiString m_strCampaign;
61+
AsciiString m_strPlayerTemplateName;
62+
AsciiString m_strPortraitMovieLeftName;
63+
AsciiString m_strPortraitMovieRightName;
64+
Image *m_imageDefeated;
65+
Image *m_imageVictorious;
66+
AsciiString m_strDefeated;
67+
AsciiString m_strVictorious;
68+
AsciiString m_strSelectionSound;
69+
AsciiString m_strTauntSound1;
70+
AsciiString m_strTauntSound2;
71+
AsciiString m_strTauntSound3;
72+
AsciiString m_strWinSound;
73+
AsciiString m_strLossSound;
74+
AsciiString m_strPreviewSound;
75+
AsciiString m_strNameSound ;
76+
77+
78+
public:
79+
GeneralPersona( void ) :
80+
m_imageBioPortraitSmall(nullptr),
81+
m_imageBioPortraitLarge(nullptr)
82+
{
83+
}
84+
// ~GeneralPersona( void );
85+
86+
Bool isStartingEnabled() const { return m_bStartsEnabled; }
87+
const AsciiString& getBioName() const { return m_strBioName; }
88+
const AsciiString& getBioDOB() const { return m_strBioDOB; }
89+
const AsciiString& getBioBirthplace() const { return m_strBioBirthplace; }
90+
const AsciiString& getBioStrategy() const { return m_strBioStrategy; }
91+
const AsciiString& getBioRank() const { return m_strBioRank; }
92+
const AsciiString& getBioClassNumber() const { return m_strBioClassNumber; }
93+
const AsciiString& getBioBranch() const { return m_strBioBranch; }
94+
const Image *getBioPortraitSmall() const { return m_imageBioPortraitSmall; }
95+
const Image *getBioPortraitLarge() const { return m_imageBioPortraitLarge; }
96+
const AsciiString& getPortraitMovieLeftName() const { return m_strPortraitMovieLeftName; }
97+
const AsciiString& getPortraitMovieRightName() const { return m_strPortraitMovieRightName; }
98+
const AsciiString& getCampaign() const { return m_strCampaign; }
99+
const AsciiString& getPlayerTemplateName() const { return m_strPlayerTemplateName; } // template name, as parsed in from ini
100+
const Image *getImageDefeated() const { return m_imageDefeated; }
101+
const Image *getImageVictorious() const { return m_imageVictorious; }
102+
const AsciiString& getStringDefeated() const { return m_strDefeated; }
103+
const AsciiString& getStringVictorious() const { return m_strVictorious; }
104+
const AsciiString& getSelectionSound() const { return m_strSelectionSound; }
105+
const AsciiString& getRandomTauntSound() const {
106+
switch (rand()%3) // don't care about distribution or exactly how random this is
107+
{
108+
case 0: return m_strTauntSound1;
109+
case 1: return m_strTauntSound2;
110+
}
111+
return m_strTauntSound3;
112+
}
113+
const AsciiString& getWinSound() const { return m_strWinSound; }
114+
const AsciiString& getLossSound() const { return m_strLossSound; }
115+
const AsciiString& getPreviewSound() const { return m_strPreviewSound; }
116+
const AsciiString& getNameSound() const { return m_strNameSound; }
117+
};
118+
119+
120+
class ChallengeGenerals
121+
{
122+
123+
private:
124+
/*const*/ GeneralPersona m_position[ NUM_GENERALS ];
125+
Int m_PlayerTemplateNum; // the template number as ThePlayerTemplateStore has it
126+
GameDifficulty m_currentDifficulty; // the last selected game difficulty for the challenge generals
127+
128+
static void parseGeneralPersona( INI* ini, void *instance, void *store, const void *userData );
129+
130+
public:
131+
ChallengeGenerals( void );
132+
~ChallengeGenerals( void );
133+
134+
void init( void );
135+
const GeneralPersona* getChallengeGenerals() const { return m_position; }
136+
const FieldParse* getFieldParse( void ) const { return s_fieldParseTable; } // for INI file parsing
137+
const GeneralPersona* getPlayerGeneralByCampaignName( AsciiString name ) const;
138+
const GeneralPersona* getGeneralByGeneralName( AsciiString name ) const;
139+
const GeneralPersona* getGeneralByTemplateName( AsciiString name ) const;
140+
141+
void setCurrentPlayerTemplateNum( Int playerTemplateNum) { m_PlayerTemplateNum = playerTemplateNum; }
142+
Int getCurrentPlayerTemplateNum( void ) { return m_PlayerTemplateNum; }
143+
144+
void setCurrentDifficulty( GameDifficulty diff ) { m_currentDifficulty = diff; }
145+
GameDifficulty getCurrentDifficulty( void ) { return m_currentDifficulty; }
146+
protected:
147+
static const FieldParse s_fieldParseTable[];
148+
149+
};
150+
151+
152+
153+
// EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
154+
extern ChallengeGenerals *TheChallengeGenerals;
155+
extern ChallengeGenerals *createChallengeGenerals( void );

Generals/Code/GameEngine/Include/GameLogic/ScriptEngine.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,11 @@ class ScriptEngine : public SubsystemInterface,
352352
//#if defined(RTS_DEBUG)
353353
void debugVictory( void );
354354
//#endif
355+
356+
357+
static void parseScriptAction( INI* ini );
358+
static void parseScriptCondition( INI* ini );
359+
355360
protected:
356361

357362
// snapshot methods

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include "GameLogic/ExperienceTracker.h"
5757
#include "GameLogic/FPUControl.h"
5858
#include "GameLogic/ObjectCreationList.h"
59+
#include "GameLogic/ScriptEngine.h"
5960
#include "GameLogic/Weapon.h"
6061

6162

@@ -84,6 +85,7 @@ static const BlockParse theTypeTable[] =
8485
{ "AudioSettings", INI::parseAudioSettingsDefinition },
8586
{ "Bridge", INI::parseTerrainBridgeDefinition },
8687
{ "Campaign", INI::parseCampaignDefinition },
88+
{ "ChallengeGenerals", INI::parseChallengeModeDefinition },
8789
{ "CommandButton", INI::parseCommandButtonDefinition },
8890
{ "CommandMap", INI::parseMetaMapDefinition },
8991
{ "CommandSet", INI::parseCommandSetDefinition },
@@ -108,6 +110,7 @@ static const BlockParse theTypeTable[] =
108110
{ "Mouse", INI::parseMouseDefinition },
109111
{ "MouseCursor", INI::parseMouseCursorDefinition },
110112
{ "MultiplayerColor", INI::parseMultiplayerColorDefinition },
113+
{ "MultiplayerStartingMoneyChoice", INI::parseMultiplayerStartingMoneyChoiceDefinition },
111114
{ "OnlineChatColors", INI::parseOnlineChatColorDefinition },
112115
{ "MultiplayerSettings",INI::parseMultiplayerSettingsDefinition },
113116
{ "MusicTrack", INI::parseMusicTrackDefinition },
@@ -135,6 +138,8 @@ static const BlockParse theTypeTable[] =
135138
{ "LODPreset", INI::parseLODPreset },
136139
{ "BenchProfile", INI::parseBenchProfile },
137140
{ "ReallyLowMHz", parseReallyLowMHz },
141+
{ "ScriptAction", ScriptEngine::parseScriptAction },
142+
{ "ScriptCondition", ScriptEngine::parseScriptCondition },
138143

139144
{ nullptr, nullptr },
140145
};
@@ -819,20 +824,27 @@ AsciiString INI::getNextAsciiString()
819824
else
820825
{
821826
static char buff[INI_MAX_CHARS_PER_LINE];
822-
827+
buff[0] = 0;
823828
if (strlen(token) > 1)
824829
{
825830
strlcpy(buff, &token[1], ARRAY_SIZE(buff));
826831
}
827832

828-
token = getNextToken(getSepsQuote());
829-
830-
if (strlen(token) > 1 && token[1] != '\t')
831-
{
832-
strlcat(buff, " ", ARRAY_SIZE(buff));
833+
token = getNextTokenOrNull(getSepsQuote());
834+
if (token) {
835+
if (strlen(token) > 1 && token[1] != '\t')
836+
{
837+
strlcat(buff, " ", ARRAY_SIZE(buff));
838+
}
839+
strlcat(buff, token, ARRAY_SIZE(buff));
840+
result.set(buff);
841+
} else {
842+
Int len = strlen(buff);
843+
if (len && buff[len-1] == '"') { // strip off trailing quote jba. [2/12/2003]
844+
buff[len-1] = 0;
845+
}
846+
result.set(buff);
833847
}
834-
strlcat(buff, token, ARRAY_SIZE(buff));
835-
result.set(buff);
836848
}
837849
}
838850
return result;
@@ -1395,7 +1407,10 @@ void INI::parseSpecialPowerTemplate( INI* ini, void * /*instance*/, void *store,
13951407
}
13961408

13971409
const SpecialPowerTemplate *sPowerT = TheSpecialPowerStore->findSpecialPowerTemplate( AsciiString( token ) );
1398-
DEBUG_ASSERTCRASH( sPowerT || stricmp( token, "None" ) == 0, ("Specialpower %s not found!",token) );
1410+
if( !sPowerT && stricmp( token, "None" ) != 0 )
1411+
{
1412+
DEBUG_CRASH( ("[LINE: %d in '%s'] Specialpower %s not found!", ini->getLineNum(), ini->getFilename().str(), token) );
1413+
}
13991414

14001415
typedef const SpecialPowerTemplate* ConstSpecialPowerTemplatePtr;
14011416
ConstSpecialPowerTemplatePtr* theSpecialPowerTemplate = (ConstSpecialPowerTemplatePtr *)store;

Generals/Code/GameEngine/Source/Common/INI/INIMultiplayer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,6 @@ void INI::parseMultiplayerColorDefinition( INI* ini )
7878
multiplayerColorDefinition->setNightColor(multiplayerColorDefinition->getRGBNightValue());
7979
}
8080

81+
void INI::parseMultiplayerStartingMoneyChoiceDefinition( INI* ini )
82+
{
83+
}

0 commit comments

Comments
 (0)