forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathINIMapCache.cpp
More file actions
205 lines (173 loc) · 7.48 KB
/
INIMapCache.cpp
File metadata and controls
205 lines (173 loc) · 7.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: INIMapCache.cpp ///////////////////////////////////////////////////////////////////////////
// Author: Matthew D. Campbell, February 2002
// Desc: Parsing MapCache INI entries
///////////////////////////////////////////////////////////////////////////////////////////////////
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Lib/BaseType.h"
#include "Common/INI.h"
#include "GameClient/MapUtil.h"
#include "GameClient/GameText.h"
#include "GameNetwork/NetworkDefs.h"
#include "Common/NameKeyGenerator.h"
#include "Common/WellKnownKeys.h"
#include "Common/QuotedPrintable.h"
class MapMetaDataReader
{
public:
Region3D m_extent;
Int m_numPlayers;
Bool m_isMultiplayer;
AsciiString m_asciiDisplayName;
AsciiString m_asciiNameLookupTag;
Bool m_isOfficial;
WinTimeStamp m_timestamp;
UnsignedInt m_filesize;
UnsignedInt m_CRC;
Coord3D m_waypoints[MAX_SLOTS];
Coord3D m_initialCameraPosition;
Coord3DList m_supplyPositions;
Coord3DList m_techPositions;
static const FieldParse m_mapFieldParseTable[]; ///< the parse table for INI definition
const FieldParse *getFieldParse() const { return m_mapFieldParseTable; }
};
void parseSupplyPositionCoord3D( INI* ini, void * instance, void * /*store*/, const void* /*userData*/ )
{
MapMetaDataReader *mmdr = (MapMetaDataReader *)instance;
Coord3D coord3d;
INI::parseCoord3D(ini, nullptr, &coord3d,nullptr );
mmdr->m_supplyPositions.push_front(coord3d);
}
void parseTechPositionsCoord3D( INI* ini, void * instance, void * /*store*/, const void* /*userData*/ )
{
MapMetaDataReader *mmdr = (MapMetaDataReader *)instance;
Coord3D coord3d;
INI::parseCoord3D(ini, nullptr, &coord3d,nullptr );
mmdr->m_techPositions.push_front(coord3d);
}
const FieldParse MapMetaDataReader::m_mapFieldParseTable[] =
{
{ "isOfficial", INI::parseBool, nullptr, offsetof( MapMetaDataReader, m_isOfficial ) },
{ "isMultiplayer", INI::parseBool, nullptr, offsetof( MapMetaDataReader, m_isMultiplayer ) },
{ "extentMin", INI::parseCoord3D, nullptr, offsetof( MapMetaDataReader, m_extent.lo ) },
{ "extentMax", INI::parseCoord3D, nullptr, offsetof( MapMetaDataReader, m_extent.hi ) },
{ "numPlayers", INI::parseInt, nullptr, offsetof( MapMetaDataReader, m_numPlayers ) },
{ "fileSize", INI::parseUnsignedInt, nullptr, offsetof( MapMetaDataReader, m_filesize ) },
{ "fileCRC", INI::parseUnsignedInt, nullptr, offsetof( MapMetaDataReader, m_CRC ) },
{ "timestampLo", INI::parseInt, nullptr, offsetof( MapMetaDataReader, m_timestamp.m_lowTimeStamp ) },
{ "timestampHi", INI::parseInt, nullptr, offsetof( MapMetaDataReader, m_timestamp.m_highTimeStamp ) },
{ "displayName", INI::parseAsciiString, nullptr, offsetof( MapMetaDataReader, m_asciiDisplayName ) },
{ "nameLookupTag", INI::parseAsciiString, nullptr, offsetof( MapMetaDataReader, m_asciiNameLookupTag ) },
{ "supplyPosition", parseSupplyPositionCoord3D, nullptr, 0 },
{ "techPosition", parseTechPositionsCoord3D, nullptr, 0 },
{ "Player_1_Start", INI::parseCoord3D, nullptr, offsetof( MapMetaDataReader, m_waypoints ) },
{ "Player_2_Start", INI::parseCoord3D, nullptr, offsetof( MapMetaDataReader, m_waypoints ) + sizeof(Coord3D) * 1 },
{ "Player_3_Start", INI::parseCoord3D, nullptr, offsetof( MapMetaDataReader, m_waypoints ) + sizeof(Coord3D) * 2 },
{ "Player_4_Start", INI::parseCoord3D, nullptr, offsetof( MapMetaDataReader, m_waypoints ) + sizeof(Coord3D) * 3 },
{ "Player_5_Start", INI::parseCoord3D, nullptr, offsetof( MapMetaDataReader, m_waypoints ) + sizeof(Coord3D) * 4 },
{ "Player_6_Start", INI::parseCoord3D, nullptr, offsetof( MapMetaDataReader, m_waypoints ) + sizeof(Coord3D) * 5 },
{ "Player_7_Start", INI::parseCoord3D, nullptr, offsetof( MapMetaDataReader, m_waypoints ) + sizeof(Coord3D) * 6 },
{ "Player_8_Start", INI::parseCoord3D, nullptr, offsetof( MapMetaDataReader, m_waypoints ) + sizeof(Coord3D) * 7 },
{ "InitialCameraPosition", INI::parseCoord3D, nullptr, offsetof( MapMetaDataReader, m_initialCameraPosition ) },
{ nullptr, nullptr, nullptr, 0 }
};
void INI::parseMapCacheDefinition( INI* ini )
{
const char *c;
AsciiString name;
MapMetaDataReader mdr;
MapMetaData md;
// read the name
c = ini->getNextToken(" \n\r\t");
name.set( c );
name = QuotedPrintableToAsciiString(name);
md.m_waypoints.clear();
ini->initFromINI( &mdr, mdr.getFieldParse() );
md.m_extent = mdr.m_extent;
md.m_isOfficial = mdr.m_isOfficial != 0;
md.m_doesExist = TRUE;
md.m_isMultiplayer = mdr.m_isMultiplayer != 0;
md.m_numPlayers = mdr.m_numPlayers;
md.m_filesize = mdr.m_filesize;
md.m_CRC = mdr.m_CRC;
md.m_timestamp = mdr.m_timestamp;
md.m_waypoints[TheNameKeyGenerator->keyToName(TheKey_InitialCameraPosition)] = mdr.m_initialCameraPosition;
#if RTS_GENERALS
md.m_displayName = QuotedPrintableToUnicodeString(mdr.m_asciiDisplayName);
#else
md.m_nameLookupTag = QuotedPrintableToAsciiString(mdr.m_asciiNameLookupTag);
if (md.m_nameLookupTag.isEmpty())
{
// maps without localized name tags
AsciiString tempdisplayname;
const char *lastBackslash = name.reverseFind('\\');
tempdisplayname = lastBackslash ? lastBackslash + 1 : name.str();
md.m_displayName.translate(tempdisplayname);
if (md.m_numPlayers >= 2)
{
UnicodeString extension;
extension.format(L" (%d)", md.m_numPlayers);
md.m_displayName.concat(extension);
}
}
else
{
// official maps with name tags
md.m_displayName = TheGameText->fetch(md.m_nameLookupTag);
if (md.m_numPlayers >= 2)
{
UnicodeString extension;
extension.format(L" (%d)", md.m_numPlayers);
md.m_displayName.concat(extension);
}
}
#endif
AsciiString startingCamName;
for (Int i=0; i<md.m_numPlayers; ++i)
{
startingCamName.format("Player_%d_Start", i+1); // start pos waypoints are 1-based
md.m_waypoints[startingCamName] = mdr.m_waypoints[i];
}
Coord3DList::iterator it = mdr.m_supplyPositions.begin();
while( it != mdr.m_supplyPositions.end())
{
md.m_supplyPositions.push_front(*it);
it++;
}
it = mdr.m_techPositions.begin();
while( it != mdr.m_techPositions.end())
{
md.m_techPositions.push_front(*it);
it++;
}
if(TheMapCache && !md.m_displayName.isEmpty())
{
AsciiString lowerName = name;
lowerName.toLower();
md.m_fileName = lowerName;
// DEBUG_LOG(("INI::parseMapCacheDefinition - adding %s to map cache", lowerName.str()));
(*TheMapCache)[lowerName] = md;
}
}