Exemplo n.º 1
0
void CDesignCollection::ReadDynamicTypes (SUniverseLoadCtx &Ctx)

//	ReadDynamicTypes
	
	{
	int i;

	m_DynamicTypes.ReadFromStream(Ctx);

	//	Read dynamic UNIDs

	m_DynamicUNIDs.DeleteAll();

	DWORD dwCount;
	Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));

	for (i = 0; i < (int)dwCount; i++)
		{
		CString sName;
		sName.ReadFromStream(Ctx.pStream);

		DWORD dwAtom;
		m_DynamicUNIDs.atom_Insert(sName, &dwAtom);
		ASSERT(dwAtom == (DWORD)i);
		}
	}
Exemplo n.º 2
0
void CTextPainter::OnReadFromStream (SLoadCtx &Ctx)

//	OnReadFromStream
//
//	Reads from a stream
//
//	CString			m_sText

	{
	m_sText.ReadFromStream(Ctx.pStream);
	MeasureText();
	}
Exemplo n.º 3
0
ALERROR IEffectPainter::ValidateClass (SLoadCtx &Ctx, const CString &sOriginalClass)

//	ValidateClass
//
//	Reads the class string. If the class does not match the current painter,
//	we read the old data and return ERR_FAIL.

	{
	if (Ctx.dwVersion >= 40)
		{
		CString sClass;
		sClass.ReadFromStream(Ctx.pStream);

		//	If the original class doesn't match the current one, then it means
		//	that the design changed. In that case, we load the painter using the
		//	old class.

		if (!strEquals(sClass, sOriginalClass))
			{
			//	If sClass is blank, then it means that the original did not have
			//	an effect painter (but the current design does)

			if (!sClass.IsBlank())
				{
				//	Get the original creator

				CEffectCreator *pOriginalCreator;
				if (CEffectCreator::CreateFromTag(sClass, &pOriginalCreator) != NOERROR)
					{
					kernelDebugLogMessage("Unable to find original effect creator: %s", sClass.GetASCIIZPointer());
					return ERR_FAIL;
					}

				//	Load the original painter

				IEffectPainter *pOriginalPainter = pOriginalCreator->CreatePainter();
				pOriginalPainter->ReadFromStream(Ctx);

				//	Discard

				pOriginalPainter->Delete();
				delete pOriginalCreator;
				}

			//	Done

			return ERR_FAIL;
			}
		}

	return NOERROR;
	}
Exemplo n.º 4
0
void CBeam::OnReadFromStream (SLoadCtx &Ctx)

//	OnReadFromStream
//
//	Read object data from a stream
//
//	CString		CWeaponFireDesc UNID
//	DWORD		m_iBonus
//	DWORD		m_iCause
//	DWORD		m_iRotation
//	Vector		m_vPaintTo
//	DWORD		m_iTick
//	DWORD		m_iLifeLeft
//	DWORD		m_Source (CSpaceObject Ref)
//	DWORD		m_pSovereign (UNID)
//	DWORD		m_pHit (CSpaceObject Ref)
//	DWORD		m_iHitDir

{
    DWORD dwLoad;

#ifdef DEBUG_LOAD
    ::OutputDebugString("CBeam::OnReadFromStream\n");
#endif
    //	Load descriptor

    CString sDescUNID;
    sDescUNID.ReadFromStream(Ctx.pStream);
    m_pDesc = g_pUniverse->FindWeaponFireDesc(sDescUNID);

    Ctx.pStream->Read((char *)&m_iBonus, sizeof(DWORD));
    if (Ctx.dwVersion >= 18)
    {
        Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
        m_iCause = (DestructionTypes)dwLoad;
    }
    else
        m_iCause = killedByDamage;

    Ctx.pStream->Read((char *)&m_iRotation, sizeof(DWORD));
    Ctx.pStream->Read((char *)&m_vPaintTo, sizeof(CVector));
    Ctx.pStream->Read((char *)&m_iTick, sizeof(DWORD));
    Ctx.pStream->Read((char *)&m_iLifeLeft, sizeof(m_iLifeLeft));
    m_Source.ReadFromStream(Ctx);
    CSystem::ReadSovereignRefFromStream(Ctx, &m_pSovereign);
    CSystem::ReadObjRefFromStream(Ctx, &m_pHit);
    Ctx.pStream->Read((char *)&m_iHitDir, sizeof(DWORD));

    ComputeOffsets();
}
Exemplo n.º 5
0
CString IEffectPainter::ReadUNID (SLoadCtx &Ctx)

//	ReadUNID
//
//	Returns the UNID saved to a stream

	{
	CString sUNID;

	if (Ctx.dwVersion >= 15)
		sUNID.ReadFromStream(Ctx.pStream);
	else
		{
		DWORD dwUNID;
		Ctx.pStream->Read((char *)&dwUNID, sizeof(DWORD));
		sUNID = strFromInt(dwUNID, FALSE);
		}

	return sUNID;
	}
Exemplo n.º 6
0
void CDesignCollection::ReadDynamicTypes (SUniverseLoadCtx &Ctx)

//	ReadDynamicTypes
	
	{
	int i;

	//	We need to unbind because there may be some dynamic types from a previous
	//	game that we're about to delete.
	//
	//	This HACK is caused by the fact that Universe::Init is also calling 
	//	BindDesign but ReadDynamicTypes must be called before Init.
	//
	//	A better way to fix this is to load the dynamic types into a separate
	//	structure and pass them into Init to be added then.

	for (i = 0; i < m_AllTypes.GetCount(); i++)
		m_AllTypes.GetEntry(i)->UnbindDesign();
	m_AllTypes.DeleteAll();

	//	Read them

	m_DynamicTypes.ReadFromStream(Ctx);

	//	Read dynamic UNIDs

	m_DynamicUNIDs.DeleteAll();

	DWORD dwCount;
	Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));

	for (i = 0; i < (int)dwCount; i++)
		{
		CString sName;
		sName.ReadFromStream(Ctx.pStream);

		DWORD dwAtom;
		m_DynamicUNIDs.atom_Insert(sName, &dwAtom);
		ASSERT(dwAtom == (DWORD)i);
		}
	}
Exemplo n.º 7
0
void IEffectPainter::OnReadFromStream (SLoadCtx &Ctx)

//	OnReadFromStream
//
//	This is the default for reading painter parameters. We ask the painter for
//	a list of its parameters and read those.

	{
	int i;

	//	Read parameters

	if (Ctx.dwVersion >= 90)
		{
		//	Read the number of parameters

		DWORD dwCount;
		Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));

		for (i = 0; i < (int)dwCount; i++)
			{
			//	Read the parameter name

			CString sParam;
			sParam.ReadFromStream(Ctx.pStream);

			//	Read the value

			CEffectParamDesc Value;
			Value.ReadFromStream(Ctx);

			//	Set it

			SetParam(CCreatePainterCtx(), sParam, Value);
			}
		}
	}
Exemplo n.º 8
0
void CCurrencyBlock::ReadFromStream (SLoadCtx &Ctx)

//	ReadFromStream
//
//	DWORD		Count of currencies
//	DWORD			CEconomyType UNID
//	LONGLONG		value

{
    int i;

    DWORD dwCount;
    Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));

    for (i = 0; i < (int)dwCount; i++)
    {
        DWORD dwUNID;
        if (Ctx.dwVersion >= 62)
        {
            Ctx.pStream->Read((char *)&dwUNID, sizeof(DWORD));
        }
        else
        {
            CString sCurrency;
            sCurrency.ReadFromStream(Ctx.pStream);

            //	Previous to 62 we never stored any currency
            //	other than credits

            dwUNID = DEFAULT_ECONOMY_UNID;
        }

        SEntry *pEntry = m_Block.Insert(dwUNID);
        Ctx.pStream->Read((char *)&pEntry->iValue, sizeof(CurrencyValue));
    }
}
Exemplo n.º 9
0
void CTopologyNode::CreateFromStream (SUniverseLoadCtx &Ctx, CTopologyNode **retpNode)

//	CreateFromStream
//
//	Creates a node from a stream
//
//	CString		m_sID
//	DWORD		m_SystemUNID
//	DWORD		m_pMap (UNID)
//	DWORD		m_xPos
//	DWORD		m_yPos
//	CString		m_sName
//	CString		m_sAttributes
//	DWORD		m_iLevel
//	DWORD		m_dwID
//
//	DWORD		No of named gates
//	CString		gate: sName
//	CString		gate: sDestNode
//	CString		gate: sDestEntryPoint
//
//	DWORD		No of variant labels
//	CString		variant label
//
//	CAttributeDataBlock	m_Data
//	DWORD		flags
//
//	CString		m_sEpitaph
//	CString		m_sEndGameReason

	{
	int i;
	DWORD dwLoad;
	CTopologyNode *pNode;

	CString sID;
	sID.ReadFromStream(Ctx.pStream);

	DWORD dwSystemUNID;
	Ctx.pStream->Read((char *)&dwSystemUNID, sizeof(DWORD));

	CSystemMap *pMap;
	if (Ctx.dwVersion >= 6)
		{
		DWORD dwMapUNID;
		Ctx.pStream->Read((char *)&dwMapUNID, sizeof(DWORD));
		pMap = CSystemMap::AsType(g_pUniverse->FindDesignType(dwMapUNID));
		}
	else
		pMap = NULL;

	pNode = new CTopologyNode(sID, dwSystemUNID, pMap);

	if (Ctx.dwVersion >= 6)
		{
		Ctx.pStream->Read((char *)&pNode->m_xPos, sizeof(DWORD));
		Ctx.pStream->Read((char *)&pNode->m_yPos, sizeof(DWORD));
		}
	
	pNode->m_sName.ReadFromStream(Ctx.pStream);
	if (Ctx.dwVersion >= 23)
		pNode->m_sAttributes.ReadFromStream(Ctx.pStream);

	Ctx.pStream->Read((char *)&pNode->m_iLevel, sizeof(DWORD));
	Ctx.pStream->Read((char *)&pNode->m_dwID, sizeof(DWORD));

	DWORD dwCount;
	Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));
	for (i = 0; i < (int)dwCount; i++)
		{
		StarGateDesc *pDesc = new StarGateDesc;
		CString sName;
		sName.ReadFromStream(Ctx.pStream);
		pDesc->sDestNode.ReadFromStream(Ctx.pStream);
		pDesc->sDestEntryPoint.ReadFromStream(Ctx.pStream);
		pDesc->pDestNode = NULL;

		pNode->m_NamedGates.AddEntry(sName, (CObject *)pDesc);
		}

	Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));
	for (i = 0; i < (int)dwCount; i++)
		{
		CString sLabel;
		sLabel.ReadFromStream(Ctx.pStream);
		pNode->m_VariantLabels.Insert(sLabel);
		}

	if (Ctx.dwVersion >= 1)
		pNode->m_Data.ReadFromStream(Ctx.pStream);

	//	Flags

	if (Ctx.dwVersion >= 6)
		Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
	else
		dwLoad = 0;

	pNode->m_bKnown = (dwLoad & 0x00000001 ? true : false);
	pNode->m_bMarked = false;

	//	More

	if (Ctx.dwVersion >= 5)
		{
		pNode->m_sEpitaph.ReadFromStream(Ctx.pStream);
		pNode->m_sEndGameReason.ReadFromStream(Ctx.pStream);
		}
	else
		{
		//	For previous version, we forgot to save this, so do it now

		if (pNode->IsEndGame())
			{
			pNode->m_sEpitaph = CONSTLIT("left Human Space on a journey to the Galactic Core");
			pNode->m_sEndGameReason = CONSTLIT("leftHumanSpace");
			}
		}

	//	Done

	*retpNode = pNode;
	}
Exemplo n.º 10
0
IEffectPainter *CEffectCreator::CreatePainterFromStream (SLoadCtx &Ctx, bool bNullCreator)

//	CreatePainterFromStream
//
//	Load a painter from a stream

	{
	CEffectCreator *pCreator;

	//	For previous versions, we only stored UNID if we had a creator

	if (Ctx.dwVersion < 43 && bNullCreator)
		return NULL;

	//	At version 15 we started saving versions as string UNIDs. We need to do this
	//	because sometimes the effect creator is inside a weapon fire desc
	//	structure (also identified by string UNIDs).

	if (Ctx.dwVersion >= 15)
		{
		CString sUNID;
		sUNID.ReadFromStream(Ctx.pStream);

		pCreator = (sUNID.IsBlank() ? NULL : CEffectCreator::FindEffectCreator(sUNID));

		//	Load the creator class that saved the painter

		if (IEffectPainter::ValidateClass(Ctx, (pCreator ? pCreator->GetTag() : NULL_STR)) != NOERROR)
			return NULL;

		//	Error

		if (pCreator == NULL)
			{
			if (!sUNID.IsBlank())
				kernelDebugLogMessage("Invalid painter creator: %s", sUNID.GetASCIIZPointer());
			return NULL;
			}
		}

	//	Old style uses DWORD UNIDs

	else
		{
		//	The first DWORD is the UNID of the creator

		DWORD dwUNID;
		Ctx.pStream->Read((char *)&dwUNID, sizeof(DWORD));
		if (dwUNID == 0)
			return NULL;

		pCreator = g_pUniverse->FindEffectType(dwUNID);

		//	Error

		if (pCreator == NULL)
			{
			kernelDebugLogMessage("Invalid painter creator: %x", dwUNID);
			return NULL;
			}
		}

	//	Let the creator create the object

	IEffectPainter *pPainter = pCreator->CreatePainter();

	//	Load it

	pPainter->ReadFromStream(Ctx);

	//	Done

	return pPainter;
	}
Exemplo n.º 11
0
void CMissile::OnReadFromStream (SLoadCtx &Ctx)

//	OnReadFromStream
//
//	Read object data from a stream
//
//	CString		CWeaponFireDesc UNID
//	DWORD		m_iBonus
//	DWORD		m_iCause
//	DWORD		m_iHitPoints
//	DWORD		m_iLifeLeft
//	DWORD		m_Source (CSpaceObject ref)
//	DWORD		m_pSovereign (CSovereign ref)
//	DWORD		m_pHit (CSpaceObject ref)
//	Vector		m_vHitPos
//	DWORD		m_iHitDir
//	DWORD		m_iRotation
//	DWORD		m_pTarget (CSpaceObject ref)
//	DWORD		m_iTick
//
//	IEffectPainter	m_pPainter
//
//	DWORD		Number of exhaust particles
//	Vector		exhaust: vPos
//	Vector		exhaust: vVel
//
//	-- version > 0 -----------------------
//	DWORD		flags
//	DWORD		Number of saved rotations
//	DWORD		rotation[]

{
    DWORD dwLoad;

#ifdef DEBUG_LOAD
    ::OutputDebugString("CMissile::OnReadFromStream\n");
#endif
    //	Load descriptor

    CString sDescUNID;
    sDescUNID.ReadFromStream(Ctx.pStream);
    m_pDesc = g_pUniverse->FindWeaponFireDesc(sDescUNID);

    //	Load other stuff

    Ctx.pStream->Read((char *)&m_iBonus, sizeof(m_iBonus));
    if (Ctx.dwVersion >= 18)
    {
        Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
        m_iCause = (DestructionTypes)dwLoad;
    }
    else
        m_iCause = killedByDamage;

    if (Ctx.dwVersion >= 28)
        Ctx.pStream->Read((char *)&m_iHitPoints, sizeof(DWORD));
    else
        m_iHitPoints = 0;

    Ctx.pStream->Read((char *)&m_iLifeLeft, sizeof(DWORD));
    m_Source.ReadFromStream(Ctx);
    Ctx.pSystem->ReadSovereignRefFromStream(Ctx, &m_pSovereign);
    Ctx.pSystem->ReadObjRefFromStream(Ctx, &m_pHit);
    Ctx.pStream->Read((char *)&m_vHitPos, sizeof(CVector));
    Ctx.pStream->Read((char *)&m_iHitDir, sizeof(DWORD));
    Ctx.pStream->Read((char *)&m_iRotation, sizeof(DWORD));
    Ctx.pSystem->ReadObjRefFromStream(Ctx, &m_pTarget);
    Ctx.pStream->Read((char *)&m_iTick, sizeof(DWORD));

    //	Load painter

    m_pPainter = CEffectCreator::CreatePainterFromStream(Ctx, (m_pDesc->GetEffect() == NULL));

    //	Load exhaust

    if (m_pDesc->m_iExhaustRate > 0)
    {
        int iCount = (m_pDesc->m_iExhaustLifetime / m_pDesc->m_iExhaustRate) + 1;
        m_pExhaust = new TQueue<SExhaustParticle>(iCount);
    }

    Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
    for (int i = 0; i < (int)dwLoad; i++)
    {
        CVector vPos;
        CVector vVel;
        Ctx.pStream->Read((char *)&vPos, sizeof(CVector));
        Ctx.pStream->Read((char *)&vVel, sizeof(CVector));

        if (m_pExhaust && i < m_pExhaust->GetMaxCount())
        {
            SExhaustParticle &Particle = m_pExhaust->GetAt(m_pExhaust->Queue());
            Particle.vPos = vPos;
            Particle.vVel = vVel;
        }
    }

    //	Load saved rotations

    if (Ctx.dwVersion >= 1)
    {
        Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
        m_fDestroyed =		((dwLoad & 0x00000001) ? true : false);
        m_fReflection =		((dwLoad & 0x00000002) ? true : false);
        m_fDetonate =		((dwLoad & 0x00000004) ? true : false);
        m_fPassthrough =	((dwLoad & 0x00000008) ? true : false);

        Ctx.pStream->Read((char *)&m_iSavedRotationsCount, sizeof(DWORD));
        if (m_iSavedRotationsCount > 0)
        {
            m_pSavedRotations = new int [m_pDesc->GetVaporTrailLength()];
            Ctx.pStream->Read((char *)m_pSavedRotations, sizeof(DWORD) * m_iSavedRotationsCount);
        }
        else
            m_iSavedRotationsCount = 0;
    }
}
Exemplo n.º 12
0
ALERROR CResourceDb::Open (DWORD dwFlags)

//	Open
//
//	Initializes database

	{
	ALERROR error;

	//	Load the resource map, if necessary

	if (m_pDb)
		{
		ASSERT(m_pResourceMap == NULL);

		if ((error = m_pDb->Open(dwFlags)))
			return error;

		CString sData;
		if ((error = m_pDb->ReadEntry(m_pDb->GetDefaultEntry(), &sData)))
			return error;

		CMemoryReadStream Stream(sData.GetASCIIZPointer(), sData.GetLength());
		if ((error = Stream.Open()))
			return error;

		//	Check the signature

		DWORD dwLoad;
		Stream.Read((char *)&dwLoad, sizeof(DWORD));
		if (dwLoad != TDB_SIGNATURE)
			return ERR_FAIL;

		//	Check the version

		Stream.Read((char *)&dwLoad, sizeof(DWORD));
		if (dwLoad > TDB_VERSION)
			return ERR_FAIL;

		m_iVersion = (int)dwLoad;

		//	Read the game file

		Stream.Read((char *)&m_iGameFile, sizeof(DWORD));

		//	Read the game title

		CString sLoad;
		sLoad.ReadFromStream(&Stream);

		//	Read the flattened symbol table

		sLoad.ReadFromStream(&Stream);

		//	Unflatten the symbol table

		if ((error = CObject::Unflatten(sLoad, (CObject **)&m_pResourceMap)))
			return error;
		}

	return NOERROR;
	}
Exemplo n.º 13
0
void CPlayerGameStats::ReadFromStream (SLoadCtx &Ctx)

//	ReadFromStream
//
//	Read from stream
//
//	DWORD		m_iScore
//	DWORD		m_iExtraSystemsVisited
//	DWORD		m_iExtraEnemyShipsDestroyed
//	CTimeSpan	m_PlayTime
//	CTimeSpan	m_GameTime
//
//	DWORD		Count of item types
//	DWORD			UNID
//	DWORD			iCountSold
//	LONGLONG		iValueSold
//	DWORD			iCountBought
//	LONGLONG		iValueBought
//	DWORD			iCountInstalled
//	DWORD			dwFirstInstalled
//	DWORD			dwLastInstalled
//	DWORD			dwLastUninstalled
//	DWORD			dwTotalInstalledTime
//	DWORD			iCountFired
//
//	DWORD		Count of ship classes
//	DWORD			UNID
//	DWORD			iEnemyDestroyed
//	DWORD			iFriendDestroyed
//
//	DWORD		Count of station types
//	DWORD			UNID
//	DWORD			iDestroyed
//
//	DWORD		Count of systems
//	CString			NodeID
//	DWORD			dwFirstEntered
//	DWORD			dwLastEntered
//	DWORD			dwLastLeft
//	DWORD			dwTotalTime
//
//	DWORD		Count of systems
//	CString			NodeID
//	DWORD			count of key events
//	DWORD				iType
//	DWORD				dwTime
//	DWORD				dwObjUNID
//	DWORD				dwCauseUNID
//	DWORD				dwObjNameFlags
//	CString				sObjName

	{
	int i, j;
	DWORD dwLoad, dwCount;

	//	Prior to version 49 we only saved:
	//
	//	DWORD		m_iScore
	//	DWORD		m_iSystemsVisited
	//	DWORD		m_iEnemiesDestroyed
	//	DWORD		m_pBestEnemyDestroyed (UNID)
	//	DWORD		m_iBestEnemyDestroyedCount

	if (Ctx.dwVersion < 49)
		{
		Ctx.pStream->Read((char *)&m_iScore, sizeof(DWORD));
		Ctx.pStream->Read((char *)&m_iExtraSystemsVisited, sizeof(DWORD));
		Ctx.pStream->Read((char *)&m_iExtraEnemyShipsDestroyed, sizeof(DWORD));

		//	Load the ship class and count of the best enemy

		Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
		Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));

		if (dwLoad)
			{
			SShipClassStats *pShipStats = GetShipStats(dwLoad);
			pShipStats->iEnemyDestroyed += dwCount;

			//	We subtract from extra ships (because these ships are already
			//	included there)

			m_iExtraEnemyShipsDestroyed -= dwCount;
			ASSERT(m_iExtraEnemyShipsDestroyed >= 0);
			}

		return;
		}

	//	New version

	Ctx.pStream->Read((char *)&m_iScore, sizeof(DWORD));
	Ctx.pStream->Read((char *)&m_iExtraSystemsVisited, sizeof(DWORD));
	Ctx.pStream->Read((char *)&m_iExtraEnemyShipsDestroyed, sizeof(DWORD));
	if (Ctx.dwVersion >= 53)
		{
		Ctx.pStream->Read((char *)&m_PlayTime, sizeof(CTimeSpan));
		Ctx.pStream->Read((char *)&m_GameTime, sizeof(CTimeSpan));
		}

	Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));
	for (i = 0; i < (int)dwCount; i++)
		{
		Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
		SItemTypeStats *pStats = m_ItemStats.Insert(dwLoad);

		Ctx.pStream->Read((char *)&pStats->iCountSold, sizeof(DWORD));
		Ctx.pStream->Read((char *)&pStats->iValueSold, sizeof(CurrencyValue));
		Ctx.pStream->Read((char *)&pStats->iCountBought, sizeof(DWORD));
		Ctx.pStream->Read((char *)&pStats->iValueBought, sizeof(CurrencyValue));
		Ctx.pStream->Read((char *)&pStats->iCountInstalled, sizeof(DWORD));
		Ctx.pStream->Read((char *)&pStats->dwFirstInstalled, sizeof(DWORD));
		Ctx.pStream->Read((char *)&pStats->dwLastInstalled, sizeof(DWORD));
		Ctx.pStream->Read((char *)&pStats->dwLastUninstalled, sizeof(DWORD));
		Ctx.pStream->Read((char *)&pStats->dwTotalInstalledTime, sizeof(DWORD));
		Ctx.pStream->Read((char *)&pStats->iCountFired, sizeof(DWORD));
		}

	Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));
	for (i = 0; i < (int)dwCount; i++)
		{
		Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
		SShipClassStats *pStats = m_ShipStats.Insert(dwLoad);

		Ctx.pStream->Read((char *)&pStats->iEnemyDestroyed, sizeof(DWORD));
		Ctx.pStream->Read((char *)&pStats->iFriendDestroyed, sizeof(DWORD));
		}

	Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));
	for (i = 0; i < (int)dwCount; i++)
		{
		Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
		SStationTypeStats *pStats = m_StationStats.Insert(dwLoad);

		Ctx.pStream->Read((char *)&pStats->iDestroyed, sizeof(DWORD));
		}

	Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));
	for (i = 0; i < (int)dwCount; i++)
		{
		CString sNodeID;
		sNodeID.ReadFromStream(Ctx.pStream);
		SSystemStats *pStats = m_SystemStats.Insert(sNodeID);

		Ctx.pStream->Read((char *)&pStats->dwFirstEntered, sizeof(DWORD));
		Ctx.pStream->Read((char *)&pStats->dwLastEntered, sizeof(DWORD));
		Ctx.pStream->Read((char *)&pStats->dwLastLeft, sizeof(DWORD));
		Ctx.pStream->Read((char *)&pStats->dwTotalTime, sizeof(DWORD));
		}

	//	Read the m_KeyEventStats

	if (Ctx.dwVersion >= 74)
		{
		Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));
		for (i = 0; i < (int)dwCount; i++)
			{
			CString sNodeID;
			sNodeID.ReadFromStream(Ctx.pStream);
			TArray<SKeyEventStats> *pEventList = m_KeyEventStats.Insert(sNodeID);

			DWORD dwListCount;
			Ctx.pStream->Read((char *)&dwListCount, sizeof(DWORD));
			for (j = 0; j < (int)dwListCount; j++)
				{
				SKeyEventStats *pStats = pEventList->Insert();

				Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
				pStats->iType = (EEventTypes)dwLoad;

				Ctx.pStream->Read((char *)&pStats->dwTime, sizeof(DWORD));
				Ctx.pStream->Read((char *)&pStats->dwObjUNID, sizeof(DWORD));
				Ctx.pStream->Read((char *)&pStats->dwCauseUNID, sizeof(DWORD));
				Ctx.pStream->Read((char *)&pStats->dwObjNameFlags, sizeof(DWORD));
				pStats->sObjName.ReadFromStream(Ctx.pStream);
				}
			}
		}
	}
Exemplo n.º 14
0
void CParticleDamage::OnReadFromStream (SLoadCtx &Ctx)

//	OnReadFromStream
//
//	Restore from stream

	{
	DWORD dwLoad;

#ifdef DEBUG_LOAD
	::OutputDebugString("CParticleDamage::OnReadFromStream\n");
#endif

	//	Load descriptor

	CString sDescUNID;
	sDescUNID.ReadFromStream(Ctx.pStream);
	m_pDesc = g_pUniverse->FindWeaponFireDesc(sDescUNID);

	//	Old style bonus

	if (Ctx.dwVersion < 92)
		{
		int iBonus;
		Ctx.pStream->Read((char *)&iBonus, sizeof(DWORD));
		if (iBonus != 0)
			{
			m_pEnhancements = new CItemEnhancementStack;
			m_pEnhancements->InsertHPBonus(iBonus);
			}
		}

	//	Load other stuff

	if (Ctx.dwVersion >= 18)
		{
		Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
		m_iCause = (DestructionTypes)dwLoad;
		}
	else
		m_iCause = killedByDamage;

	Ctx.pStream->Read((char *)&m_iLifeLeft, sizeof(m_iLifeLeft));
	m_Source.ReadFromStream(Ctx);
	CSystem::ReadSovereignRefFromStream(Ctx, &m_pSovereign);
	Ctx.pStream->Read((char *)&m_iTick, sizeof(m_iTick));
	Ctx.pStream->Read((char *)&m_iDamage, sizeof(m_iDamage));
	if (Ctx.dwVersion >= 3 && Ctx.dwVersion < 67)
		{
		CVector vDummy;
		Ctx.pStream->Read((char *)&vDummy, sizeof(CVector));
		}

	//	The newer version uses a different particle array

	if (Ctx.dwVersion >= 21)
		{
		Ctx.pStream->Read((char *)&m_vEmitSourcePos, sizeof(CVector));
		Ctx.pStream->Read((char *)&m_vEmitSourceVel, sizeof(CVector));
		Ctx.pStream->Read((char *)&m_iEmitDirection, sizeof(DWORD));
		Ctx.pStream->Read((char *)&m_iEmitTime, sizeof(DWORD));
		Ctx.pStream->Read((char *)&m_iParticleCount, sizeof(DWORD));

		//	Load painter

		m_pPainter = CEffectCreator::CreatePainterFromStreamAndCreator(Ctx, m_pDesc->GetEffect());

		m_Particles.ReadFromStream(Ctx);
		}

	//	Read the previous version, but no need to convert

	else
		{
		DWORD dwCount;
		Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));
		if (dwCount > 0)
			{
			char *pDummy = new char [5 * sizeof(DWORD) * dwCount];
			Ctx.pStream->Read(pDummy, 5 * sizeof(DWORD) * dwCount);
			delete pDummy;
			}

		m_iEmitTime = 0;
		m_iEmitDirection = -1;
		}

	//	Read the target

	if (Ctx.dwVersion >= 67)
		CSystem::ReadObjRefFromStream(Ctx, &m_pTarget);
	else
		m_pTarget = NULL;

	//	Enhancements

	if (Ctx.dwVersion >= 92)
		CItemEnhancementStack::ReadFromStream(Ctx, &m_pEnhancements);
	}
Exemplo n.º 15
0
void COrderList::ReadFromStream (SLoadCtx &Ctx)

//	ReadFromStream
//
//	Read

	{
	int i;
	DWORD dwLoad;
	DWORD dwCount;

	Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));
	m_List.InsertEmpty(dwCount);

	//	Read new version

	if (Ctx.dwVersion >= 87)
		{
		for (i = 0; i < (int)dwCount; i++)
			{
			SOrderEntry *pEntry = &m_List[i];

			Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
			pEntry->dwOrderType = LOWORD(dwLoad);
			pEntry->dwDataType = HIWORD(dwLoad);

			CSystem::ReadObjRefFromStream(Ctx, &pEntry->pTarget);

			switch (pEntry->dwDataType)
				{
				case IShipController::dataInteger:
				case IShipController::dataPair:
					Ctx.pStream->Read((char *)&pEntry->dwData, sizeof(DWORD));
					break;

				case IShipController::dataString:
					{
					CString *pString = new CString;
					pString->ReadFromStream(Ctx.pStream);
					pEntry->dwData = (DWORD)pString;
					break;
					}

				case IShipController::dataVector:
					{
					CVector *pVector = new CVector;
					Ctx.pStream->Read((char *)pVector, sizeof(CVector));
					pEntry->dwData = (DWORD)pVector;
					break;
					}
				}
			}
		}

	//	Backwards compatible

	else
		{
		for (i = 0; i < (int)dwCount; i++)
			{
			SOrderEntry *pEntry = &m_List[i];

			Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
			pEntry->dwOrderType = dwLoad;
			pEntry->dwDataType = IShipController::dataInteger;

			CSystem::ReadObjRefFromStream(Ctx, &pEntry->pTarget);
			Ctx.pStream->Read((char *)&pEntry->dwData, sizeof(DWORD));
			}
		}
	}