Пример #1
0
bool CMultiverseModel::GetResourceFileRefs (const TArray<CString> &Filespecs, TArray<CMultiverseFileRef> *retFileRefs) const

//	GetResourceFilePaths
//
//	Returns a filepath for each of the files

	{
	CSmartLock Lock(m_cs);
	int i;

	retFileRefs->DeleteAll();
	for (i = 0; i < Filespecs.GetCount(); i++)
		{
		//	We index by filename

		CString sFilename = pathGetFilename(Filespecs[i]);

		//	Look up the resource

		SResourceDesc *pDesc = m_Resources.GetAt(sFilename);
		if (pDesc == NULL)
			{
			::kernelDebugLogMessage("Unable to find TDB resource file: %s.", sFilename);
			continue;
			}

		//	Return a copy of it

		CMultiverseFileRef *pNewRef = retFileRefs->Insert();
		*pNewRef = pDesc->pEntry->GetResourceRef(pDesc->iIndex);

		//	Set the local filespec that we expect.

		pNewRef->SetFilespec(Filespecs[i]);
		}

	//	Done

	return (retFileRefs->GetCount() > 0);
	}
Пример #2
0
void CreateTDB (const CString &sInputFilespec, CXMLElement *pCmdLine)
	{
	ALERROR error;
	CString sError;
	int i;

	//	Prepare a context block

	CTDBCompiler Ctx;

	//	Figure out the output filespec

	CString sOutputFilespec = pCmdLine->GetAttribute(ATTRIB_OUTPUT);
	if (sOutputFilespec.IsBlank() && !sInputFilespec.IsBlank())
		sOutputFilespec = strPatternSubst(CONSTLIT("%s.tdb"), pathStripExtension(pathGetFilename(sInputFilespec)));

	//	Optional entities file.

	CString sEntities = pCmdLine->GetAttribute(ATTRIB_ENTITIES);
	TArray<CString> EntityFilespecs;
	if (strDelimitEx(sEntities, ',', DELIMIT_TRIM_WHITESPACE, 0, &EntityFilespecs) != NOERROR)
		{
		printf("error : Unable to parse list of entity filespecs.\n");
		return;
		}

	//	Initialize our compiler.

	if (!Ctx.Init(sInputFilespec, sOutputFilespec, EntityFilespecs, pCmdLine, &sError))
		{
		printf("error: %s.\n", sError.GetASCIIZPointer());
		return;
		}

	//	Create the output file

	if (error = CDataFile::Create(sOutputFilespec, 4096, 0))
		{
		printf("error : Unable to create '%s'\n", sOutputFilespec.GetASCIIZPointer());
		return;
		}

	CDataFile Out(sOutputFilespec);
	if (error = Out.Open())
		{
		printf("error : Unable to open '%s'\n", sOutputFilespec.GetASCIIZPointer());
		return;
		}

	//	Write out the main module and recurse

	int iGameFile;
	if (error = WriteModule(Ctx, pathGetFilename(sInputFilespec), NULL_STR, Out, &iGameFile))
		goto Done;

	//	Write out the header

	if (error = WriteHeader(Ctx, iGameFile, Out))
		goto Done;

	//	Done with the file

	Out.Close();

	//	If necessary create a digest

	if (pCmdLine->GetAttributeBool(ATTRIB_DIGEST))
		{
		CIntegerIP Digest;

		if (fileCreateDigest(sOutputFilespec, &Digest) != NOERROR)
			{
			Ctx.ReportError(strPatternSubst(CONSTLIT("Unable to create digest for '%s'."), sOutputFilespec));
			goto Done;
			}

		//	Output C++ style constant

		printf("\nstatic BYTE g_Digest[] =\n\t{");

		BYTE *pDigest = Digest.GetBytes();
		for (i = 0; i < Digest.GetLength(); i++)
			{
			if ((i % 10) == 0)
				printf("\n\t");

			printf("%3d, ", (DWORD)pDigest[i]);
			}
			
		printf("\n\t};\n");
		}

Done:

	Ctx.ReportErrorCount();
	}
Пример #3
0
void CListSaveFilesTask::CreateFileEntry (CGameFile &GameFile, const CTimeDate &ModifiedTime, int yStart, IAnimatron **retpEntry, int *retcyHeight)

//	CreateFileEntry
//
//	Creates a display entry for the save file

	{
	const CVisualPalette &VI = m_HI.GetVisuals();
	const CG16bitFont &MediumFont = VI.GetFont(fontMedium);
	const CG16bitFont &SubTitleFont = VI.GetFont(fontSubTitle);

	int x = 0;
	int y = 0;
	int xText = x + ADVENTURE_ICON_WIDTH + ICON_SPACING_HORZ;
	int cxText = m_cxWidth - (ADVENTURE_ICON_WIDTH + 2 * ICON_SPACING_HORZ + SHIP_IMAGE_WIDTH);

	//	Start with a sequencer

	CAniSequencer *pRoot = new CAniSequencer;
	pRoot->SetPropertyVector(PROP_POSITION, CVector(0, yStart));

	//	Add the character name and current star system

	CString sHeading = strPatternSubst(CONSTLIT("%s — %s"), GameFile.GetPlayerName(), GameFile.GetSystemName());

	IAnimatron *pName = new CAniText;
	pName->SetPropertyVector(PROP_POSITION, CVector(xText, y));
	pName->SetPropertyVector(PROP_SCALE, CVector(10000, 1000));
	pName->SetPropertyColor(PROP_COLOR, VI.GetColor(colorTextDialogInput));
	pName->SetPropertyFont(PROP_FONT, &SubTitleFont);
	pName->SetPropertyString(PROP_TEXT, sHeading);

	pRoot->AddTrack(pName, 0);
	y += SubTitleFont.GetHeight();

	//	Now add some additional information

	CShipClass *pClass = g_pUniverse->FindShipClass(GameFile.GetPlayerShip());
	CString sShipClass = (pClass ? pClass->GetName() : NULL_STR);
	CString sGenome = strCapitalize(GetGenomeName(GameFile.GetPlayerGenome()));

	CString sState;
	if (GameFile.IsGameResurrect())
		sState = strPatternSubst(CONSTLIT("Resurrect in the %s System"), GameFile.GetSystemName());
	else
		sState = strPatternSubst(CONSTLIT("Continue in the %s System"), GameFile.GetSystemName());

	CString sDesc;
	if (!sGenome.IsBlank() && !sShipClass.IsBlank())
		sDesc = strPatternSubst(CONSTLIT("%s — %s — %s"), sGenome, sShipClass, sState);
	else
		sDesc = sState;

	IAnimatron *pDesc = new CAniText;
	pDesc->SetPropertyVector(PROP_POSITION, CVector(xText, y));
	pDesc->SetPropertyVector(PROP_SCALE, CVector(cxText, 1000));
	pDesc->SetPropertyColor(PROP_COLOR, VI.GetColor(colorTextDialogInput));
	pDesc->SetPropertyFont(PROP_FONT, &MediumFont);
	pDesc->SetPropertyString(PROP_TEXT, sDesc);

	RECT rcLine;
	pDesc->GetSpacingRect(&rcLine);

	pRoot->AddTrack(pDesc, 0);
	y += RectHeight(rcLine);

	//	Adventure info

	CExtension *pAdventure = NULL;
	bool bHasAdventureIcon = false;

	if (g_pUniverse->FindExtension(GameFile.GetAdventure(), 0, &pAdventure))
		{
		//	Adventure icon

		CG16bitImage *pIcon;
		pAdventure->CreateIcon(ADVENTURE_ICON_WIDTH, ADVENTURE_ICON_HEIGHT, &pIcon);

		if (pIcon)
			{
			int xOffset = (ADVENTURE_ICON_WIDTH - pIcon->GetWidth()) / 2;
			IAnimatron *pIconAni = new CAniRect;
			pIconAni->SetPropertyVector(PROP_POSITION, CVector(x + xOffset, 0));
			pIconAni->SetPropertyVector(PROP_SCALE, CVector(pIcon->GetWidth(), pIcon->GetHeight()));
			pIconAni->SetFillMethod(new CAniImageFill(pIcon, true));

			pRoot->AddTrack(pIconAni, 0);

			bHasAdventureIcon = true;
			}

		//	Adventure name

		pName = new CAniText;
		pName->SetPropertyVector(PROP_POSITION, CVector(xText, y));
		pName->SetPropertyVector(PROP_SCALE, CVector(10000, 1000));
		pName->SetPropertyColor(PROP_COLOR, VI.GetColor(colorTextDialogLabel));
		pName->SetPropertyFont(PROP_FONT, &MediumFont);
		pName->SetPropertyString(PROP_TEXT, pAdventure->GetName());

		pRoot->AddTrack(pName, 0);
		y += MediumFont.GetHeight();
		}

	//	Create an image of the ship class

	if (pClass)
		{
		const CObjectImageArray &ObjImage = pClass->GetImage();
		if (ObjImage.IsLoaded())
			{
			RECT rcRect = ObjImage.GetImageRect();
			CG16bitImage &Image = ObjImage.GetImage(NULL_STR);
			int cxImage = RectWidth(rcRect);
			int cyImage = RectHeight(rcRect);

			int cxNewWidth = Min(SHIP_IMAGE_WIDTH, cxImage);
			int cyNewHeight = cxNewWidth;

			CG16bitImage *pNewImage = new CG16bitImage;
			pNewImage->CreateFromImageTransformed(Image, 
					rcRect.left, 
					rcRect.top, 
					cxImage,
					cyImage,
					(Metric)cxNewWidth / cxImage,
					(Metric)cyNewHeight / cyImage,
					0.0);

			//	Position

			int xImage = x + m_cxWidth - SHIP_IMAGE_WIDTH + (SHIP_IMAGE_WIDTH - cxNewWidth) / 2;
			int yImage = (SHIP_IMAGE_HEIGHT - cyNewHeight) / 2;

			//	New image frame

			IAnimatron *pImageFrame = new CAniRect;
			pImageFrame->SetPropertyVector(PROP_POSITION, CVector(xImage, yImage));
			pImageFrame->SetPropertyVector(PROP_SCALE, CVector(cxNewWidth, cyNewHeight));
			pImageFrame->SetFillMethod(new CAniImageFill(pNewImage, true));

			pRoot->AddTrack(pImageFrame, 0);
			}
		}

	//	Extra information

	CString sEpitaph = GameFile.GetEpitaph();
	int iScore = GameFile.GetScore();
	CTimeDate LocalTime = ModifiedTime.ToLocalTime();
	CString sModifiedTime = LocalTime.Format("%d %B %Y %I:%M %p");
	CString sFilename = pathGetFilename(GameFile.GetFilespec());

	CString sGameType;
	if (GameFile.IsRegistered())
		sGameType = CONSTLIT("Registered");
	else if (GameFile.IsDebug())
		sGameType = CONSTLIT("Debug");
	else
		sGameType = CONSTLIT("Unregistered");

	CString sExtra;
	if (!sEpitaph.IsBlank())
		sExtra = strPatternSubst(CONSTLIT("Score %d — %s\n%s — %s — %s"), iScore, sEpitaph, sGameType, sModifiedTime, sFilename);
	else if (iScore > 0)
		sExtra = strPatternSubst(CONSTLIT("Score %d\n%s — %s — %s"), iScore, sGameType, sModifiedTime, sFilename);
	else
		sExtra = strPatternSubst(CONSTLIT("%s — %s — %s"), sGameType, sModifiedTime, sFilename);

	pDesc = new CAniText;
	pDesc->SetPropertyVector(PROP_POSITION, CVector(xText, y));
	pDesc->SetPropertyVector(PROP_SCALE, CVector(cxText, 1000));
	pDesc->SetPropertyColor(PROP_COLOR, VI.GetColor(colorTextDialogLabel));
	pDesc->SetPropertyFont(PROP_FONT, &MediumFont);
	pDesc->SetPropertyString(PROP_TEXT, sExtra);

	pDesc->GetSpacingRect(&rcLine);

	pRoot->AddTrack(pDesc, 0);
	y += RectHeight(rcLine);

	//	Done

	*retpEntry = pRoot;

	if (retcyHeight)
		*retcyHeight = (bHasAdventureIcon ? Max(ADVENTURE_ICON_HEIGHT, y) : y);
	}
Пример #4
0
CResourceDb::CResourceDb (const CString &sFilespec, CResourceDb *pMainDb, bool bExtension) : 
		m_iVersion(TDB_VERSION),
		m_pDb(NULL),
		m_pResourceMap(NULL),
		m_pMainDb(NULL)

//	CResourceDb constructor
//
//	sFilespec = "Extensions/MyExtension"
//
//	If Extensions/MyExtension.tdb exists, then look for the definitions
//	and the resources in the .tdb file.
//
//	Otherwise, use Extensions/MyExtension.xml for the definitions and
//	Look for resource files in the Extensions folder.

	{
	if (pMainDb || bExtension)
		{
		//	We assume this is an extension

		CString sTDB = sFilespec;
		sTDB.Append(CONSTLIT("."));
		sTDB.Append(FILE_TYPE_TDB);

		if (pathExists(sTDB))
			{
			m_pDb = new CDataFile(sTDB);

			m_sRoot = pathGetPath(sTDB);
			m_sGameFile = pathGetFilename(sTDB);
			m_bGameFileInDb = true;
			m_bResourcesInDb = true;
			}
		else
			{
			CString sXML = sFilespec;
			sXML.Append(CONSTLIT("."));
			sXML.Append(FILE_TYPE_XML);

			m_pDb = NULL;

			m_sRoot = pathGetPath(sFilespec);
			m_sGameFile = pathGetFilename(sXML);
			m_bGameFileInDb = false;
			m_bResourcesInDb = false;
			}

		m_pMainDb = pMainDb;
		}
	else
		{
		CString sType = pathGetExtension(sFilespec);
		if (sType.IsBlank())
			{
			CString sXML = sFilespec;
			sXML.Append(CONSTLIT("."));
			sXML.Append(FILE_TYPE_XML);

			//	If Transcendence.xml exists, then use the file and load
			//	the resources from the same location.

			if (pathExists(sXML))
				{
				m_sRoot = pathGetPath(sXML);
				m_sGameFile = pathGetFilename(sXML);
				m_bGameFileInDb = false;

				//	If a resources path exists, then use the resources in the
				//	folder. Otherwise, use resources in the tdb

				CString sResourcesPath = pathAddComponent(m_sRoot, RESOURCES_FOLDER);
				if (pathExists(sResourcesPath))
					{
					m_pDb = NULL;
					m_bResourcesInDb = false;
					}

				//	Otherwise, use the tdb file

				else
					{
					CString sTDB = sFilespec;
					sTDB.Append(CONSTLIT("."));
					sTDB.Append(FILE_TYPE_TDB);
					m_pDb = new CDataFile(sTDB);
					m_bResourcesInDb = true;
					}
				}

			//	Otherwise, use the .tdb file for both

			else
				{
				CString sTDB = sFilespec;
				sTDB.Append(CONSTLIT("."));
				sTDB.Append(FILE_TYPE_TDB);
				m_pDb = new CDataFile(sTDB);

				m_bGameFileInDb = true;
				m_bResourcesInDb = true;
				}
			}
		else if (strEquals(sType, FILE_TYPE_XML))
			{
			m_sRoot = pathGetPath(sFilespec);
			m_sGameFile = pathGetFilename(sFilespec);
			m_pDb = NULL;

			m_bGameFileInDb = false;
			m_bResourcesInDb = false;
			}
		else
			{
			m_pDb = new CDataFile(sFilespec);
			m_bGameFileInDb = true;
			m_bResourcesInDb = true;
			}

		//	This is the main file

		m_pMainDb = NULL;
		}
	}