void GenerateSimTables (CUniverse &Universe, CXMLElement *pCmdLine) { ALERROR error; int i, j; int iSystemSample = pCmdLine->GetAttributeInteger(CONSTLIT("count")); if (iSystemSample == 0) iSystemSample = DEFAULT_SYSTEM_SAMPLE; // Generate systems for multiple games CSymbolTable AllSystems(TRUE, TRUE); for (i = 0; i < iSystemSample; i++) { printf("sample %d...\n", i+1); CTopologyNode *pNode = Universe.GetFirstTopologyNode(); while (true) { // Create the system CSystem *pSystem; if (error = Universe.CreateStarSystem(pNode, &pSystem)) { printf("ERROR: Unable to create star system.\n"); return; } // Find this system in the table. SystemInfo *pSystemEntry; if (error = AllSystems.Lookup(pNode->GetSystemName(), (CObject **)&pSystemEntry)) { pSystemEntry = new SystemInfo; pSystemEntry->sName = pNode->GetSystemName(); pSystemEntry->iLevel = pNode->GetLevel(); pSystemEntry->dwSystemType = pNode->GetSystemDescUNID(); pSystemEntry->iCount = 1; AllSystems.AddEntry(pSystemEntry->sName, pSystemEntry); } else pSystemEntry->iCount++; // Add the encounters to the appropriate tables for (j = 0; j < pSystem->GetObjectCount(); j++) { CSpaceObject *pObj = pSystem->GetObject(j); if (pObj) { // Add this encounter to the table CStationType *pType; if (pType = pObj->GetEncounterInfo()) { CString sKey = strFromInt(pType->GetUNID(), false); // See if we have this type in the table StationInfo *pEntry; if (error = pSystemEntry->Stations.Lookup(sKey, (CObject **)&pEntry)) { pEntry = new StationInfo; pEntry->pType = pType; pEntry->iSystemCount = 0; pEntry->iTotalCount = 1; pSystemEntry->Stations.AddEntry(sKey, pEntry); } else pEntry->iTotalCount++; } // Enumerate the items in this object CItemListManipulator ItemList(pObj->GetItemList()); ItemList.ResetCursor(); while (ItemList.MoveCursorForward()) { const CItem &Item(ItemList.GetItemAtCursor()); if (!Item.IsInstalled() && !Item.IsDamaged()) { CString sKey = strFromInt(Item.GetType()->GetUNID(), false); // Find the item type in the table ItemInfo *pEntry; if (error = pSystemEntry->Items.Lookup(sKey, (CObject **)&pEntry)) { pEntry = new ItemInfo; pEntry->pType = Item.GetType(); pEntry->iTotalCount = Item.GetCount(); pSystemEntry->Items.AddEntry(sKey, pEntry); } else pEntry->iTotalCount += Item.GetCount(); } } } } // Get the next node CString sEntryPoint; pNode = pSystem->GetStargateDestination(CONSTLIT("Outbound"), &sEntryPoint); if (pNode == NULL || pNode->IsEndGame()) break; // Done with old system Universe.DestroySystem(pSystem); } Universe.Reinit(); } // Output if (error = OutputItemTable(AllSystems, iSystemSample)) return; if (error = OutputEncounterTable(AllSystems, iSystemSample)) return; // Create a table with the sum of all items for the game printf("Total count statistic computed.\n"); }
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"); } }