Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions Generals/Code/GameEngine/Include/GameClient/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "Common/AsciiString.h"
#include "Common/GameMemory.h"
#include "Common/SubsystemInterface.h"
#include <map>

struct FieldParse;
class INI;
Expand Down Expand Up @@ -106,8 +107,6 @@ friend class ImageCollection;
void *m_rawTextureData; ///< raw texture data
UnsignedInt m_status; ///< status bits from ImageStatus

Image *m_next; ///< for maintaining lists as collections

static const FieldParse m_imageFieldParseTable[]; ///< the parse table for INI definition

};
Expand All @@ -130,25 +129,28 @@ class ImageCollection : public SubsystemInterface
void load( Int textureSize ); ///< load images

const Image *findImageByName( const AsciiString& name ); ///< find image based on name
const Image *findImageByFilename( const AsciiString& name ); ///< find image based on filename

Image *firstImage( void ); ///< return first image in list
Image *nextImage( Image *image ); ///< return next image
/// adds the given image to the collection, transfers ownership to this object
void addImage(Image *image);

Image *newImage( void ); ///< return a new, linked image
/// enumerates the list of existing images
Image *Enum(unsigned index)
{
for (std::map<unsigned,Image *>::iterator i=m_imageMap.begin();i!=m_imageMap.end();++i)
if (!index--)
return i->second;
return NULL;
}

protected:

Image *m_imageList; ///< the image list

std::map<unsigned,Image *> m_imageMap; ///< maps named keys to images
};

// INLINING ///////////////////////////////////////////////////////////////////////////////////////
inline void Image::setName( AsciiString name ) { m_name = name; }
inline AsciiString Image::getName( void ) const { return m_name; }
inline void Image::setFilename( AsciiString name ) { m_filename = name; }
inline AsciiString Image::getFilename( void ) const { return m_filename; }
inline Image *ImageCollection::firstImage( void ) { return m_imageList; }
inline void Image::setUV( Region2D *uv ) { if( uv ) m_UVCoords = *uv; }
inline const Region2D *Image::getUV( void ) const { return &m_UVCoords; }
inline void Image::setTextureWidth( Int width ) { m_textureSize.x = width; }
Expand Down
3 changes: 3 additions & 0 deletions Generals/Code/GameEngine/Include/GameClient/MapUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class MapMetaData
{
public:
UnicodeString m_displayName;
AsciiString m_nameLookupTag;
Region3D m_extent;
Int m_numPlayers;
Bool m_isMultiplayer;
Expand Down Expand Up @@ -125,6 +126,8 @@ Int populateMapListboxNoReset( GameWindow *listbox, Bool useSystemMaps, Bool isM
Bool isValidMap( AsciiString mapName, Bool isMultiplayer ); /// Validate a map
Image *getMapPreviewImage( AsciiString mapName );
AsciiString getDefaultMap( Bool isMultiplayer ); /// Find a valid map
AsciiString getDefaultOfficialMap();
Bool isOfficialMap( AsciiString mapName );
Bool parseMapPreviewChunk(DataChunkInput &file, DataChunkInfo *info, void *userData);
void findDrawPositions( Int startX, Int startY, Int width, Int height, Region3D extent,
ICoord2D *ul, ICoord2D *lr );
Expand Down
32 changes: 32 additions & 0 deletions Generals/Code/GameEngine/Source/Common/INI/INIMapCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#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"
Expand All @@ -46,6 +47,7 @@ class MapMetaDataReader
Int m_numPlayers;
Bool m_isMultiplayer;
AsciiString m_asciiDisplayName;
AsciiString m_asciiNameLookupTag;

Bool m_isOfficial;
WinTimeStamp m_timestamp;
Expand Down Expand Up @@ -92,6 +94,7 @@ const FieldParse MapMetaDataReader::m_mapFieldParseTable[] =
{ "timestampLo", INI::parseInt, NULL, offsetof( MapMetaDataReader, m_timestamp.m_lowTimeStamp ) },
{ "timestampHi", INI::parseInt, NULL, offsetof( MapMetaDataReader, m_timestamp.m_highTimeStamp ) },
{ "displayName", INI::parseAsciiString, NULL, offsetof( MapMetaDataReader, m_asciiDisplayName ) },
{ "nameLookupTag", INI::parseAsciiString, NULL, offsetof( MapMetaDataReader, m_asciiNameLookupTag ) },

{ "supplyPosition", parseSupplyPositionCoord3D, NULL, NULL },
{ "techPosition", parseTechPositionsCoord3D, NULL, NULL },
Expand Down Expand Up @@ -136,7 +139,36 @@ void INI::parseMapCacheDefinition( INI* ini )

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;
tempdisplayname = name.reverseFind('\\') + 1;
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ void INI::parseMappedImageDefinition( INI* ini )
{

// image not found, create a new one
image = TheMappedImageCollection->newImage();
image = newInstance(Image);
image->setName( name );
TheMappedImageCollection->addImage(image);
DEBUG_ASSERTCRASH( image, ("parseMappedImage: unable to allocate image for '%s'",
name.str()) );

Expand Down
92 changes: 89 additions & 3 deletions Generals/Code/GameEngine/Source/GameClient/MapUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,12 @@ void MapCache::writeCacheINI( Bool userDir )
fprintf(fp, " extentMin = X:%2.2f Y:%2.2f Z:%2.2f\n", md.m_extent.lo.x, md.m_extent.lo.y, md.m_extent.lo.z);
fprintf(fp, " extentMax = X:%2.2f Y:%2.2f Z:%2.2f\n", md.m_extent.hi.x, md.m_extent.hi.y, md.m_extent.hi.z);

// BAD AND NOW UNUSED: the mapcache.ini should not contain localized data... using the lookup tag instead
#if RTS_GENERALS
fprintf(fp, " displayName = %s\n", UnicodeStringToQuotedPrintable(md.m_displayName).str());
#else
fprintf(fp, " nameLookupTag = %s\n", md.m_nameLookupTag.str());
#endif

Coord3D pos;
WaypointMap::iterator itw = md.m_waypoints.begin();
Expand Down Expand Up @@ -645,6 +650,31 @@ Bool MapCache::addMap( AsciiString dirName, AsciiString fname, FileInfo *fileInf
if ((md.m_filesize == filesize) &&
(md.m_CRC != 0))
{
// Force a lookup so that we don't display the English localization in all builds.
if (md.m_nameLookupTag.isEmpty())
{
// unofficial maps or maps without names
AsciiString tempdisplayname;
tempdisplayname = fname.reverseFind('\\') + 1;
(*this)[lowerFname].m_displayName.translate(tempdisplayname);
if (md.m_numPlayers >= 2)
{
UnicodeString extension;
extension.format(L" (%d)", md.m_numPlayers);
(*this)[lowerFname].m_displayName.concat(extension);
}
}
else
{
// official maps with name tags
(*this)[lowerFname].m_displayName = TheGameText->fetch(md.m_nameLookupTag);
if (md.m_numPlayers >= 2)
{
UnicodeString extension;
extension.format(L" (%d)", md.m_numPlayers);
(*this)[lowerFname].m_displayName.concat(extension);
}
}
// DEBUG_LOG(("MapCache::addMap - found match for map %s", lowerFname.str()));
return FALSE; // OK, it checks out.
}
Expand Down Expand Up @@ -676,6 +706,7 @@ Bool MapCache::addMap( AsciiString dirName, AsciiString fname, FileInfo *fileInf

Bool exists = false;
AsciiString munkee = worldDict.getAsciiString(TheKey_mapName, &exists);
md.m_nameLookupTag = munkee;
if (!exists || munkee.isEmpty())
{
DEBUG_LOG(("Missing TheKey_mapName!"));
Expand Down Expand Up @@ -766,13 +797,15 @@ Int populateMapListboxNoReset( GameWindow *listbox, Bool useSystemMaps, Bool isM
const Image *easyImage = NULL;
const Image *mediumImage = NULL;
const Image *brutalImage = NULL;
const Image *maxBrutalImage = NULL;
SkirmishBattleHonors *battleHonors = NULL;
Int w = 10, h = 10;
if (numColumns > 1)
{
easyImage = TheMappedImageCollection->findImageByName("Star-Bronze");
mediumImage = TheMappedImageCollection->findImageByName("Star-Silver");
brutalImage = TheMappedImageCollection->findImageByName("Star-Gold");
maxBrutalImage = TheMappedImageCollection->findImageByName("RedYell_Star");
battleHonors = new SkirmishBattleHonors;

w = (brutalImage)?brutalImage->getImageWidth():10;
Expand Down Expand Up @@ -843,6 +876,16 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
}
*/

#if RTS_ZEROHOUR
//Patch 1.03 -- Purposely filter out these broken maps that exist in Generals.
if( !asciiMapName.compare( "maps\\armored fury\\armored fury.map" ) ||

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how broken are these? I would rather remove this part from ZH then exclude maps hardcoded.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented this out and tested in Zero Hour and both maps show in the list and do load successfully. I do not know why they were removed here. It is separate investigation. Maybe we can bring them back.

!asciiMapName.compare( "maps\\scorched earth\\scorched earth.map" ) )
{
++tempit;
continue;
}
#endif

DEBUG_ASSERTCRASH(it != TheMapCache->end(), ("Map %s not found in map cache.", tempit->str()));
if (it->first.startsWithNoCase(mapDir.str()) && isMultiplayer == it->second.m_isMultiplayer && !it->second.m_displayName.isEmpty())
{
Expand All @@ -857,8 +900,17 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
Int numBrutal = battleHonors->getEnduranceMedal(it->first.str(), SLOT_BRUTAL_AI);
if (numBrutal)
{
imageItemData = 3;
index = GadgetListBoxAddEntryImage( listbox, brutalImage, index, 0, w, h, TRUE);
int maxBrutalSlots = it->second.m_numPlayers - 1;
if (maxBrutalImage != NULL && numBrutal == maxBrutalSlots)
{
index = GadgetListBoxAddEntryImage( listbox, maxBrutalImage, index, 0, w, h, TRUE);
imageItemData = 4;
}
else
{
index = GadgetListBoxAddEntryImage( listbox, brutalImage, index, 0, w, h, TRUE);
imageItemData = 3;
}
}
else if (numMedium)
{
Expand Down Expand Up @@ -984,6 +1036,39 @@ AsciiString getDefaultMap( Bool isMultiplayer )
return AsciiString::TheEmptyString;
}


AsciiString getDefaultOfficialMap()
{
if(!TheMapCache)
return AsciiString::TheEmptyString;
TheMapCache->updateCache();

MapCache::iterator it = TheMapCache->begin();
while (it != TheMapCache->end())
{
if (it->second.m_isMultiplayer && it->second.m_isOfficial)
{
return it->first;
}
++it;
}
return AsciiString::TheEmptyString;
}


Bool isOfficialMap( AsciiString mapName )
{
if(!TheMapCache || mapName.isEmpty())
return FALSE;
TheMapCache->updateCache();
mapName.toLower();
MapCache::iterator it = TheMapCache->find(mapName);
if (it != TheMapCache->end())
return it->second.m_isOfficial;
return FALSE;
}


const MapMetaData *MapCache::findMap(AsciiString mapName)
{
mapName.toLower();
Expand Down Expand Up @@ -1104,7 +1189,7 @@ Image *getMapPreviewImage( AsciiString mapName )

if (success)
{
image = TheMappedImageCollection->newImage();
image = newInstance(Image);
image->setName(tempName);
//image->setFullPath("mission.tga");
image->setFilename(name);
Expand All @@ -1117,6 +1202,7 @@ Image *getMapPreviewImage( AsciiString mapName )
image->setUV(&uv);
image->setTextureHeight(128);
image->setTextureWidth(128);
TheMappedImageCollection->addImage(image);
}
else
{
Expand Down
Loading
Loading