void DoTradeSim (CUniverse &Universe, CXMLElement *pCmdLine) { ALERROR error; int i, j; CSovereign *pPlayer = Universe.FindSovereign(g_PlayerSovereignUNID); int iSystemSample = pCmdLine->GetAttributeIntegerBounded(CONSTLIT("count"), 1, -1, 1); bool bLogo = !pCmdLine->GetAttributeBool(NO_LOGO_SWITCH); // For each station type we keep track of the items that it sells and the // various prices that each instances charges. SStationData AllStations; // For each item type we keep track of the stations that sell and/or // buy it. SItemData AllItems; // Generate systems for multiple games for (i = 0; i < iSystemSample; i++) { if (bLogo) printf("pass %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; } // For all active stations in the system, get their trading information for (j = 0; j < pSystem->GetObjectCount(); j++) { CSpaceObject *pObj = pSystem->GetObject(j); if (pObj && pObj->GetCategory() == CSpaceObject::catStation) CompileTradeData(pObj, &AllStations, &AllItems); } // 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(); } if (bLogo) printf("FINAL STATISTICS\n\n"); // Loop over each item and output the best trading strategy printf("Item\tSeller\tSell Price\tBuyer\tBuy Price\tProfit\n"); for (i = 0; i < AllItems.GetCount(); i++) { ComputeAverages(&AllItems[i]); OutputTradingStrategy(AllItems[i]); } }
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 GenerateStationPlaceSim (CUniverse &Universe, CXMLElement *pCmdLine) { ALERROR error; int i, j, k; CSovereign *pPlayer = Universe.FindSovereign(g_PlayerSovereignUNID); int iSystemSample = pCmdLine->GetAttributeIntegerBounded(CONSTLIT("count"), 1, -1, 1); bool bLogo = !pCmdLine->GetAttributeBool(NO_LOGO_SWITCH); // Generate systems for multiple games CSymbolTable AllSystems(TRUE, TRUE); for (i = 0; i < iSystemSample; i++) { if (bLogo) printf("pass %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. SPSimSystemInfo *pSystemEntry; if (error = AllSystems.Lookup(pNode->GetSystemName(), (CObject **)&pSystemEntry)) { pSystemEntry = new SPSimSystemInfo; pSystemEntry->sName = pNode->GetSystemName(); pSystemEntry->iLevel = pNode->GetLevel(); pSystemEntry->dwSystemType = pNode->GetSystemTypeUNID(); pSystemEntry->iCount = 1; for (j = 0; j < DIST_BUCKET_COUNT; j++) pSystemEntry->iEnemies[j] = 0; AllSystems.AddEntry(pSystemEntry->sName, pSystemEntry); } else pSystemEntry->iCount++; // For all active stations in the system, count the number of enemy stations // within certain distance buckets for (j = 0; j < pSystem->GetObjectCount(); j++) { CSpaceObject *pObj = pSystem->GetObject(j); // Find any objects that are lootable by the player if (pObj && pObj->GetCategory() == CSpaceObject::catStation && pObj->CanAttack()) { // Count to see how many enemy stations are in range for (k = 0; k < pSystem->GetObjectCount(); k++) { CSpaceObject *pEnemy = pSystem->GetObject(k); if (pEnemy && pEnemy->GetCategory() == CSpaceObject::catStation && pEnemy->CanAttack() && (pEnemy->IsEnemy(pObj) || pObj->IsEnemy(pEnemy))) { Metric rDist = pObj->GetDistance(pEnemy); int iDist = DistToBucketIndex(rDist); if (iDist != -1) { ASSERT(iDist < DIST_BUCKET_COUNT && iDist >= 0); pSystemEntry->iEnemies[iDist]++; int iLSDist = (int)((rDist / LIGHT_SECOND) + 0.5); if (iLSDist < 30) { printf("%s: %s (%x) and %s (%x) within %d ls\n", pSystem->GetName().GetASCIIZPointer(), pObj->GetNounPhrase().GetASCIIZPointer(), pObj->GetID(), pEnemy->GetNounPhrase().GetASCIIZPointer(), pEnemy->GetID(), iLSDist); } } } } } } // 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(); } if (bLogo) printf("FINAL SYSTEM STATISTICS\n\n"); // Output total value stats printf("Level\tSystem\t<10 ls\t<25 ls\t<50ls\t<100 ls\n"); int iTotals[DIST_BUCKET_COUNT]; for (i = 0; i < DIST_BUCKET_COUNT; i++) iTotals[i] = 0; for (i = 0; i < AllSystems.GetCount(); i++) { SPSimSystemInfo *pSystemEntry = (SPSimSystemInfo *)AllSystems.GetValue(i); printf("%d\t%s", pSystemEntry->iLevel, pSystemEntry->sName.GetASCIIZPointer()); for (j = 0; j < DIST_BUCKET_COUNT; j++) { printf("\t%.2f", (double)pSystemEntry->iEnemies[j] / (double)pSystemEntry->iCount); iTotals[j] += pSystemEntry->iEnemies[j]; } printf("\n"); } // Totals printf("\n"); printf("Within 10 ls: %.2f\n", iTotals[0] / (double)iSystemSample); printf("Within 25 ls: %.2f\n", iTotals[1] / (double)iSystemSample); printf("Within 50 ls: %.2f\n", iTotals[2] / (double)iSystemSample); printf("Within 100 ls: %.2f\n", iTotals[3] / (double)iSystemSample); printf("\n"); }
void GenerateSnapshot (CUniverse &Universe, CXMLElement *pCmdLine) { ALERROR error; int i; // Get some parameters int iInitialUpdateTime = 10; int iUpdateTime = pCmdLine->GetAttributeInteger(CONSTLIT("wait")); // Criteria CString sNode = pCmdLine->GetAttribute(CONSTLIT("node")); CString sCriteria = pCmdLine->GetAttribute(CONSTLIT("criteria")); // Output int cxWidth; int cyHeight; if (pCmdLine->FindAttributeInteger(CONSTLIT("size"), &cxWidth)) { cyHeight = cxWidth; } else { cxWidth = 1024; cyHeight = 1024; } // Output file CString sFilespec = pCmdLine->GetAttribute(CONSTLIT("output")); if (!sFilespec.IsBlank()) sFilespec = pathAddExtensionIfNecessary(sFilespec, CONSTLIT(".bmp")); // Loop over all systems until we find what we're looking for int iLoops = 20; 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; } // If this is the node we want, then search CSpaceObject *pTarget; if (sNode.IsBlank() || strEquals(sNode, pNode->GetID())) { printf("Searching %s...\n", pNode->GetSystemName().GetASCIIZPointer()); // Set the POV CSpaceObject *pPOV = pSystem->GetObject(0); Universe.SetPOV(pPOV); pSystem->SetPOVLRS(pPOV); // Prepare system Universe.UpdateExtended(); Universe.GarbageCollectLibraryBitmaps(); // Update for a while for (i = 0; i < iInitialUpdateTime; i++) Universe.Update(g_SecondsPerUpdate, true); // Compose the criteria CSpaceObject::Criteria Criteria; CSpaceObject::ParseCriteria(pPOV, sCriteria, &Criteria); // Get the list of all objects in the system that match the criteria CSpaceObject::SCriteriaMatchCtx Ctx(Criteria); TArray<CSpaceObject *> Results; for (i = 0; i < pSystem->GetObjectCount(); i++) { CSpaceObject *pObj = pSystem->GetObject(i); if (pObj && pObj->MatchesCriteria(Ctx, Criteria)) Results.Insert(pObj); } // Pick the appropriate object from the list if (Results.GetCount() == 0) pTarget = NULL; else if (Criteria.bNearestOnly || Criteria.bFarthestOnly) pTarget = Ctx.pBestObj; else pTarget = Results[mathRandom(0, Results.GetCount() - 1)]; } else pTarget = NULL; // If we found the target, then output if (pTarget) { // If we found the target, take a snapshot printf("Found %s.\n", pTarget->GetNounPhrase(0).GetASCIIZPointer()); // Wait a bit for (i = 0; i < iUpdateTime; i++) { if ((i % 100) == 99) printf("."); Universe.Update(g_SecondsPerUpdate, true); } if (iUpdateTime >= 99) printf("\n"); // Paint CG16bitImage Output; Output.CreateBlank(cxWidth, cyHeight, false); RECT rcViewport; rcViewport.left = 0; rcViewport.top = 0; rcViewport.right = cxWidth; rcViewport.bottom = cyHeight; pSystem->PaintViewport(Output, rcViewport, pTarget, false); // Write to file if (!sFilespec.IsBlank()) { CFileWriteStream OutputFile(sFilespec); if (OutputFile.Create() != NOERROR) { printf("ERROR: Unable to create '%s'\n", sFilespec.GetASCIIZPointer()); return; } Output.WriteToWindowsBMP(&OutputFile); OutputFile.Close(); printf("%s\n", sFilespec.GetASCIIZPointer()); } // Otherwise, clipboard else { if (error = Output.CopyToClipboard()) { printf("ERROR: Unable to copy image to clipboard.\n"); return; } printf("Image copied to clipboard.\n"); } // Done break; } // Otherwise, loop to the next system CString sEntryPoint; pNode = pSystem->GetStargateDestination(CONSTLIT("Outbound"), &sEntryPoint); // Done with old system Universe.DestroySystem(pSystem); // If no next node, then we loop through another universe if (pNode == NULL || pNode->IsEndGame()) { if (--iLoops > 0) { Universe.Reinit(); pNode = Universe.GetFirstTopologyNode(); } else { printf("ERROR: Specified target could not be found.\n"); return; } } } }
void DoSmokeTest (CUniverse &Universe, CXMLElement *pCmdLine) { ALERROR error; int i, j; int iSystemSample = pCmdLine->GetAttributeInteger(CONSTLIT("count")); if (iSystemSample == 0) iSystemSample = DEFAULT_SYSTEM_SAMPLE; int iSystemUpdateTime = 100; // Generate systems for multiple games CSymbolTable AllSystems(TRUE, TRUE); for (i = 0; i < iSystemSample; i++) { printf("sample %d", 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; } // Set the POV CSpaceObject *pPOV = pSystem->GetObject(0); Universe.SetPOV(pPOV); pSystem->SetPOVLRS(pPOV); // Prepare system Universe.UpdateExtended(); Universe.GarbageCollectLibraryBitmaps(); Universe.LoadLibraryBitmaps(); // Update for a while for (j = 0; j < iSystemUpdateTime; j++) Universe.Update(g_SecondsPerUpdate, true); // 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); printf("."); } Universe.Reinit(); printf("\n"); } // Done printf("Test successful.\n"); }