Пример #1
0
CString ParserCtx::LookupEntity (const CString &sName, bool *retbFound)
	{
	CString *pValue = EntityTable.GetAt(sName);
	if (pValue == NULL)
		{
		if (m_pParentCtx)
			return m_pParentCtx->LookupEntity(sName, retbFound);
		else if (m_pController)
			return m_pController->ResolveExternalEntity(sName, retbFound);
		else
			{
			if (retbFound) *retbFound = false;
			return sName;
			}
		}

	if (retbFound) *retbFound = true;
	return *pValue;
	}
Пример #2
0
void GenerateTopology (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	int i, j, k;

	int iCount = pCmdLine->GetAttributeIntegerBounded(COUNT_SWITCH, 1, -1, 1);

	STopologyStats Stats;

	for (k = 0; k < iCount; k++)
		{
		if (iCount > 1)
			printf("sample %d", k+1);

		TSortMap<CString, SNodeInfo> NodeData;
		TSortMap<CString, int> AttribCount;

		//	Initialize the topology

		CString sError;
		Universe.GetFirstTopologyNode();

		//	Loop over all nodes

		for (i = 0; i < Universe.GetTopologyNodeCount(); i++)
			{
			CTopologyNode *pNode = Universe.GetTopologyNode(i);

			SNodeInfo *pNewNode = NodeData.Insert(pNode->GetID());
			pNewNode->sID = pNode->GetID();
			pNewNode->sName = pNode->GetSystemName();
			pNewNode->dwSystemUNID = pNode->GetSystemDescUNID();
			pNewNode->sAttribs = pNode->GetAttributes();

			//	Add the attributes in this node to the list of 
			//	attributes for this try.

			TArray<CString> Attribs;
			ParseAttributes(pNewNode->sAttribs, &Attribs);
			for (j = 0; j < Attribs.GetCount(); j++)
				{
				int *pCount = AttribCount.GetAt(Attribs[j]);
				if (pCount == NULL)
					{
					pCount = AttribCount.Insert(Attribs[j]);
					*pCount = 0;
					}

				*pCount = (*pCount) + 1;
				}
			}

		//	Compute topology stats
		//	Add the node count for this try

		Stats.NodeCount.Insert(NodeData.GetCount());

		//	Loop over all attributes that we know about. If one doesn't
		//	exist in this try, then we set its min to 0

		if (k > 0)
			{
			for (i = 0; i < Stats.Attribs.GetCount(); i++)
				{
				if (AttribCount.GetAt(Stats.Attribs.GetKey(i)) == NULL)
					Stats.Attribs[i].SetMin(0);
				}
			}

		//	Loop over all attributes in this try and add them to the stats

		SStat *pAttribStat;
		for (i = 0; i < AttribCount.GetCount(); i++)
			{
			//	If we have some attributes that no other try had, then
			//	that means that the minimum value is 0.

			if (pAttribStat = Stats.Attribs.GetAt(AttribCount.GetKey(i)))
				pAttribStat->Insert(AttribCount[i]);
			else
				{
				pAttribStat = Stats.Attribs.Insert(AttribCount.GetKey(i));
				pAttribStat->Insert(AttribCount[i]);
				if (k > 0)
					pAttribStat->SetMin(0);
				}
			}

		//	Output all the nodes

		if (iCount == 1)
			{
			printf("Node\tSystemType\tName\tStargates\tAttributes\n");
			for (i = 0; i < NodeData.GetCount(); i++)
				{
				SNodeInfo *pNode = &NodeData.GetValue(i);
				printf("%s\t%08x\t%s\t%d\t%s\n",
						pNode->sID.GetASCIIZPointer(),
						pNode->dwSystemUNID,
						pNode->sName.GetASCIIZPointer(),
						pNode->Stargates.GetCount(),
						pNode->sAttribs.GetASCIIZPointer());
				}
			}
		else
			{
			Universe.Reinit();
			printf("\n");
			}
		}

	//	Output stats

	if (iCount > 0)
		{
		printf("\n");
		printf("STATS\n\n");
		Stats.NodeCount.Print(CONSTLIT("Nodes"), iCount, Stats.NodeCount.GetAverage(iCount));
		printf("\n");

		printf("ATTRIBS\n\n");
		for (i = 0; i < Stats.Attribs.GetCount(); i++)
			Stats.Attribs[i].Print(Stats.Attribs.GetKey(i), iCount, Stats.NodeCount.GetAverage(iCount));
		printf("\n");
		}
	}
Пример #3
0
void GenerateSimTables (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	ALERROR error;
	int i, j, k;

	int iSystemSample = pCmdLine->GetAttributeInteger(CONSTLIT("count"));
	if (iSystemSample == 0)
		iSystemSample = DEFAULT_SYSTEM_SAMPLE;

	//	Keep track of stats for each type

	TSortMap<DWORD, STypeStats> AllStats;
	for (i = 0; i < iSystemSample; i++)
		{
		TSortMap<DWORD, STypeInfo> AllTypes;

		printf("sample %d...\n", i+1);

		//	Initialize the game

		CString sError;
		if (error = Universe.InitGame(0, &sError))
			{
			printf("%s\n", sError.GetASCIIZPointer());
			return;
			}

		//	Loop over all nodes

		for (j = 0; j < Universe.GetTopologyNodeCount(); j++)
			{
			CTopologyNode *pNode = Universe.GetTopologyNode(j);

			//	Skip end game nodes

			if (pNode->IsEndGame())
				continue;

			//	Create the system

			CSystem *pSystem;
			if (error = Universe.CreateStarSystem(pNode, &pSystem, &sError))
				{
				printf("ERROR: Unable to create star system: %s\n", sError.GetASCIIZPointer());
				return;
				}

			//	Accumulate

			AccumulateSystem(pNode, pSystem, AllTypes);

			//	Done with old system

			Universe.DestroySystem(pSystem);
			}

		//	Now accumulate all stats

		for (j = 0; j < Universe.GetDesignTypeCount(); j++)
			{
			CDesignType *pType = Universe.GetDesignType(j);
			STypeStats *pStats = AllStats.SetAt(pType->GetUNID());

			STypeInfo *pTypeInfo = AllTypes.GetAt(pType->GetUNID());
			if (pTypeInfo)
				{
				pStats->PerGame.Insert(pTypeInfo->iTotalCount);

				for (k = 0; k < MAX_TECH_LEVEL; k++)
					pStats->PerLevel[k].Insert(pTypeInfo->PerLevel[k]);
				}
			else
				{
				pStats->PerGame.Insert(0);

				for (k = 0; k < MAX_TECH_LEVEL; k++)
					pStats->PerLevel[k].Insert(0);
				}
			}

		Universe.Reinit();
		}

	//	Output

	if (error = OutputTypeTable(AllStats, iSystemSample))
		return;

	//	Create a table with the sum of all items for the game

	printf("Total count statistic computed.\n");
	}