コード例 #1
0
void CSpaceObjectAddressResolver::ResolveRefs (DWORD dwObjID, CSpaceObject *pObj)

//	ResolveRefs
//
//	Resolve a reference

	{
	int i;

	int iPos;
	if (!m_List.FindPos(dwObjID, &iPos))
		return;

	TArray<SEntry> *pList = &m_List[iPos];

	for (i = 0; i < pList->GetCount(); i++)
		{
		SEntry *pEntry = &pList->GetAt(i);

		//	If we have a callback function, invoke it now.

		if (pEntry->pfnResolveProc)
			(pEntry->pfnResolveProc)(pEntry->pCtx, dwObjID, pObj);

		//	Otherwise we fix up the address

		else
			(*(CSpaceObject **)pEntry->pCtx) = pObj;
		}

	//	Remove the entry (since we've resolved all entries)

	m_List.Delete(iPos);
	}
コード例 #2
0
ファイル: Stats.cpp プロジェクト: AvanWolf/Transcendence
void AddTypeToIsland (CUniverse &Universe, ReverseIndexMap &ReverseIndex, IslandMap *pIsland, CDesignType *pType)
	{
	int i;

	//	Skip images

	if (pType->GetType() == designImage)
		return;

	if (pType->GetType() == designShipTable)
		return;

	//	Exclude default types

	if (g_DefaultTypes.Find(pType->GetUNID()))
		return;

	//	If this type is already on the island, then there is nothing to do.

	if (pIsland->Find(pType->GetUNID()))
		return;

	//	Add the type to the island (we do this first because we want it to be
	//	here in case we recurse below).

	pIsland->Insert(pType->GetUNID(), true);

	//	Now get the list of all types that this type uses and add them to the
	//	island.

	IslandMap TypesUsed;
	pType->AddTypesUsed(&TypesUsed);
	for (i = 0; i < TypesUsed.GetCount(); i++)
		{
		CDesignType *pTypeUsed = Universe.FindDesignType(TypesUsed.GetKey(i));
		if (pTypeUsed == NULL)
			continue;

		AddTypeToIsland(Universe, ReverseIndex, pIsland, pTypeUsed);
		}

	//	Now get the lists that use this type and add them to the island.

#if 0
	TArray<DWORD> *pList = ReverseIndex.GetAt(pType->GetUNID());
	if (pList)
		{
		for (i = 0; i < pList->GetCount(); i++)
			{
			CDesignType *pTypeUsing = Universe.FindDesignType(pList->GetAt(i));
			if (pTypeUsing == NULL)
				continue;

			AddTypeToIsland(Universe, ReverseIndex, pIsland, pTypeUsing);
			}
		}
#endif
	}
コード例 #3
0
bool CSpaceObjectAddressResolver::HasUnresolved (void)

//	HasUnresolved
//
//	For all callback reference, we call them with NULL. If there are any address
//	references left, then we return TRUE.

	{
	int i, j;

	bool bUnresolved = false;

	for (i = 0; i < m_List.GetCount(); i++)
		{
		TArray<SEntry> *pList = &m_List[i];

		for (j = 0; j < pList->GetCount(); j++)
			{
			SEntry *pEntry = &pList->GetAt(j);

			//	If we have a callback function, invoke it now.
			//	The function may throw if it does not want to leave an object
			//	unresolved.

			if (pEntry->pfnResolveProc)
				(pEntry->pfnResolveProc)(pEntry->pCtx, m_List.GetKey(i), NULL);

			//	Otherwise this is unresolved

			else
				{
				kernelDebugLogMessage("Unresolved object: %x", m_List.GetKey(i));
				bUnresolved = true;
				}
			}
		}

	return bUnresolved;
	}
コード例 #4
0
ファイル: ItemTable.cpp プロジェクト: bmer/Transmuter
void OutputByShipClass (SItemTableCtx &Ctx, const SItemTypeList &ItemList, bool bShowUsage)
	{
	int i, j;

	//	Make a map of ship classes for each item

	TSortMap<DWORD, TArray<CShipClass *>> ItemToShipClass;
	for (i = 0; i < g_pUniverse->GetShipClassCount(); i++)
		{
		CShipClass *pClass = g_pUniverse->GetShipClass(i);

		//	Skip non-generic ones

		if (!pClass->HasLiteralAttribute(CONSTLIT("genericClass")))
			continue;

		//	Add the list of types used by the ship

		TSortMap<DWORD, bool> TypesUsed;
		pClass->AddTypesUsed(&TypesUsed);

		//	For each item type, add it to the map

		for (j = 0; j < TypesUsed.GetCount(); j++)
			{
			CDesignType *pType = g_pUniverse->FindDesignType(TypesUsed.GetKey(j));
			if (pType && pType->GetType() == designItemType)
				{
				TArray<CShipClass *> *pList = ItemToShipClass.SetAt(pType->GetUNID());
				pList->Insert(pClass);
				}
			}
		}

	//	If we want to show usage, then we print each item along with the 
	//	ship classes using each item.

	if (bShowUsage)
		{
		for (i = 0; i < ItemList.GetCount(); i++)
			{
			CItemType *pType = ItemList[i];
			printf("%s\n", (LPSTR)pType->GetNounPhrase());

			TArray<CShipClass *> *pList = ItemToShipClass.SetAt(pType->GetUNID());
			for (j = 0; j < pList->GetCount(); j++)
				printf("\t%s\n", (LPSTR)pList->GetAt(j)->GetName());

			if (pList->GetCount() == 0)
				printf("\t(none)\n");

			printf("\n");
			}
		}

	//	Otherwise we categorize by ship class

	else
		{
		//	Now make a list of all ship classes that have our items

		SByShipClassTypeList ByShipClassTable;
		for (i = 0; i < ItemList.GetCount(); i++)
			{
			const CString &sKey = ItemList.GetKey(i);
			CItemType *pType = ItemList[i];

			//	Loop over all ship classes

			TArray<CShipClass *> *pList = ItemToShipClass.SetAt(pType->GetUNID());
			for (j = 0; j < pList->GetCount(); j++)
				{
				CString sClassName = pList->GetAt(j)->GetName();

				bool bNew;
				SShipClassEntry *pEntry = ByShipClassTable.SetAt(sClassName, &bNew);
				if (bNew)
					pEntry->sShipClassName = sClassName;

				pEntry->ItemTable.Insert(sKey, pType);
				}

			//	If no ship class

			if (pList->GetCount() == 0)
				{
				bool bNew;
				SShipClassEntry *pEntry = ByShipClassTable.SetAt(CONSTLIT("(none)"), &bNew);
				if (bNew)
					pEntry->sShipClassName = CONSTLIT("(none)");

				pEntry->ItemTable.Insert(sKey, pType);
				}
			}

		//	Now loop over all attributes

		for (i = 0; i < ByShipClassTable.GetCount(); i++)
			{
			const SShipClassEntry &Entry = ByShipClassTable[i];
			printf("%s\n\n", Entry.sShipClassName.GetASCIIZPointer());

			OutputHeader(Ctx);
			OutputTable(Ctx, Entry.ItemTable);
			printf("\n");
			}
		}
	}
コード例 #5
0
void CPlayerGameStats::WriteToStream (IWriteStream *pStream)

//	WriteToStream
//
//	Write to 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

	{
	DWORD dwSave;
	CMapIterator i;
	int j;

	pStream->Write((char *)&m_iScore, sizeof(DWORD));
	pStream->Write((char *)&m_iExtraSystemsVisited, sizeof(DWORD));
	pStream->Write((char *)&m_iExtraEnemyShipsDestroyed, sizeof(DWORD));
	pStream->Write((char *)&m_PlayTime, sizeof(CTimeSpan));
	pStream->Write((char *)&m_GameTime, sizeof(CTimeSpan));

	dwSave = m_ItemStats.GetCount();
	pStream->Write((char *)&dwSave, sizeof(DWORD));
	m_ItemStats.Reset(i);
	while (m_ItemStats.HasMore(i))
		{
		SItemTypeStats *pStats;
		DWORD dwUNID = m_ItemStats.GetNext(i, &pStats);

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

	dwSave = m_ShipStats.GetCount();
	pStream->Write((char *)&dwSave, sizeof(DWORD));
	m_ShipStats.Reset(i);
	while (m_ShipStats.HasMore(i))
		{
		SShipClassStats *pStats;
		DWORD dwUNID = m_ShipStats.GetNext(i, &pStats);

		pStream->Write((char *)&dwUNID, sizeof(DWORD));
		pStream->Write((char *)&pStats->iEnemyDestroyed, sizeof(DWORD));
		pStream->Write((char *)&pStats->iFriendDestroyed, sizeof(DWORD));
		}

	dwSave = m_StationStats.GetCount();
	pStream->Write((char *)&dwSave, sizeof(DWORD));
	m_StationStats.Reset(i);
	while (m_StationStats.HasMore(i))
		{
		SStationTypeStats *pStats;
		DWORD dwUNID = m_StationStats.GetNext(i, &pStats);

		pStream->Write((char *)&dwUNID, sizeof(DWORD));
		pStream->Write((char *)&pStats->iDestroyed, sizeof(DWORD));
		}

	dwSave = m_SystemStats.GetCount();
	pStream->Write((char *)&dwSave, sizeof(DWORD));
	m_SystemStats.Reset(i);
	while (m_SystemStats.HasMore(i))
		{
		SSystemStats *pStats;
		const CString &sNodeID = m_SystemStats.GetNext(i, &pStats);

		sNodeID.WriteToStream(pStream);
		pStream->Write((char *)&pStats->dwFirstEntered, sizeof(DWORD));
		pStream->Write((char *)&pStats->dwLastEntered, sizeof(DWORD));
		pStream->Write((char *)&pStats->dwLastLeft, sizeof(DWORD));
		pStream->Write((char *)&pStats->dwTotalTime, sizeof(DWORD));
		}

	dwSave = m_KeyEventStats.GetCount();
	pStream->Write((char *)&dwSave, sizeof(DWORD));
	m_KeyEventStats.Reset(i);
	while (m_KeyEventStats.HasMore(i))
		{
		TArray<SKeyEventStats> *pEventList;
		const CString &sNodeID = m_KeyEventStats.GetNext(i, &pEventList);

		sNodeID.WriteToStream(pStream);

		DWORD dwCount = pEventList->GetCount();
		pStream->Write((char *)&dwCount, sizeof(DWORD));
		for (j = 0; j < (int)dwCount; j++)
			{
			SKeyEventStats *pStats = &pEventList->GetAt(j);

			dwSave = (DWORD)pStats->iType;
			pStream->Write((char *)&dwSave, sizeof(DWORD));

			pStream->Write((char *)&pStats->dwTime, sizeof(DWORD));
			pStream->Write((char *)&pStats->dwObjUNID, sizeof(DWORD));
			pStream->Write((char *)&pStats->dwCauseUNID, sizeof(DWORD));
			pStream->Write((char *)&pStats->dwObjNameFlags, sizeof(DWORD));
			pStats->sObjName.WriteToStream(pStream);
			}
		}
	}