void ComputeAverages (const TArray<int> &Records, int *retiMax, int *retiAverage, int *retiMin) { int i; if (Records.GetCount() == 0) { *retiMax = 0; *retiAverage = 0; *retiMin = 0; return; } int iMax = Records[0]; int iMin = Records[0]; int iTotal = Records[0]; for (i = 1; i < Records.GetCount(); i++) { if (Records[i] < iMin) iMin = Records[i]; else if (Records[i] > iMax) iMax = Records[i]; iTotal += Records[i]; } *retiMax = iMax; *retiAverage = iTotal / Records.GetCount(); *retiMin = iMin; }
void CAeonEngine::MsgHousekeeping (const SArchonMessage &Msg, const CHexeSecurityCtx *pSecurityCtx) // MsgHousekeeping // // Arc.housekeeping { int i; ASSERT(pSecurityCtx == NULL); // Get the list of all tables (in a semaphore) TArray<CAeonTable *> AllTables; GetTables(&AllTables); if (AllTables.GetCount() == 0) return; // Compute how much memory data we want each table to keep in memory // before it flushes to disk. (x2 because most tables won't use the // maximum. DWORD dwMemoryPerTable = 2 * m_dwMaxMemoryUse / AllTables.GetCount(); // Loop over all tables and let them do some housekeeping tasks (such as // saving updated rows and compacting segments). for (i = 0; i < AllTables.GetCount(); i++) AllTables[i]->Housekeeping(dwMemoryPerTable); }
bool CDatum::CreateFromAttributeList (const CAttributeList &Attribs, CDatum *retdDatum) // CreateFromAttributeList // // Creates a datum from an attribute list { int i; TArray<CString> AllAttribs; Attribs.GetAll(&AllAttribs); if (AllAttribs.GetCount() == 0) { *retdDatum = CDatum(); return true; } CComplexArray *pArray = new CComplexArray; for (i = 0; i < AllAttribs.GetCount(); i++) pArray->Insert(AllAttribs[i]); *retdDatum = CDatum(pArray); return true; }
void CSystemCreateStats::AddLabelExpansion (const CString &sAttributes, const CString &sPrefix) // AddLabelExpansion // // Expands and adds the given attributes to the label counter { int i; TArray<CString> Attribs; ParseAttributes(sAttributes, &Attribs); // Add each of the attributes alone (and make a list of permutations) TArray<CString> Permutable; for (i = 0; i < Attribs.GetCount(); i++) { if (m_PermuteAttribs.Find(Attribs[i])) Permutable.Insert(Attribs[i]); else AddEntry(Attribs[i]); } // Now add all permutations if (Permutable.GetCount() >= 1) AddEntryPermutations(NULL_STR, Permutable, 0); }
CurrencyValue CLevelTableOfItemGenerators::GetAverageValue (int iLevel) // GetAverageValue // // Returns the average value. { int i; // Compute the table for this level. Metric rTotal = 0.0; int iTotalChance = 0; for (i = 0; i < m_Table.GetCount(); i++) { int iChance = GetFrequencyByLevel(m_Table[i].sLevelFrequency, iLevel); iTotalChance += iChance; } for (i = 0; i < m_Table.GetCount(); i++) { int iChance = GetFrequencyByLevel(m_Table[i].sLevelFrequency, iLevel); if (iChance > 0) rTotal += (m_Table[i].Count.GetAveValueFloat() * (Metric)m_Table[i].pEntry->GetAverageValue(iLevel) * (Metric)iChance / (Metric)iTotalChance); } return (CurrencyValue)(rTotal + 0.5); }
Metric CGroupOfGenerators::GetCountAdj (int iLevel) // GetCountAdj // // Returns the count adjusment for the given level. { int i; if (iLevel >= 0 && iLevel < m_CountAdj.GetCount()) { Metric rCountAdj = m_CountAdj[iLevel]; if (rCountAdj < 0.0) { // Loop over all our children and compute the average value. Metric rTotal = 0.0; for (i = 0; i < m_Table.GetCount(); i++) rTotal += (Metric)m_Table[i].pItem->GetAverageValue(iLevel); // Compute the factor that we have to multiply the total to get to // the desired value. rCountAdj = (rTotal > 0.0 ? (Metric)m_AverageValue[iLevel] / rTotal : 0.0); // Remember so we don't have to compute it again. m_CountAdj[iLevel] = rCountAdj; } return rCountAdj; } else return 0.0; }
CurrencyValue CGroupOfGenerators::GetAverageValue (int iLevel) // GetAverageValue // // Returns the average value. { int i; if (SetsAverageValue()) { if (iLevel >= 0 && iLevel < m_AverageValue.GetCount()) return m_AverageValue[iLevel]; else return 0; } else { // Average value is proportional to chances. Metric rTotal = 0.0; for (i = 0; i < m_Table.GetCount(); i++) { if (m_Table[i].iChance < 100) rTotal += (m_Table[i].Count.GetAveValueFloat() * (Metric)m_Table[i].pItem->GetAverageValue(iLevel) * (Metric)m_Table[i].iChance / 100.0); else rTotal += m_Table[i].Count.GetAveValueFloat() * m_Table[i].pItem->GetAverageValue(iLevel); } return (CurrencyValue)(rTotal + 0.5); } }
ALERROR CGroupOfGenerators::LoadFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc) // LoadFromXML // // Load from XML { int i; ALERROR error; // Load content elements m_Table.InsertEmpty(pDesc->GetContentElementCount()); for (i = 0; i < m_Table.GetCount(); i++) { CXMLElement *pEntry = pDesc->GetContentElement(i); m_Table[i].iChance = pEntry->GetAttributeInteger(CHANCE_ATTRIB); if (m_Table[i].iChance == 0) m_Table[i].iChance = 100; CString sCount = pEntry->GetAttribute(COUNT_ATTRIB); if (sCount.IsBlank()) m_Table[i].Count = DiceRange(0, 0, 1); else m_Table[i].Count.LoadFromXML(sCount); if (error = IItemGenerator::CreateFromXML(Ctx, pEntry, &m_Table[i].pItem)) return error; } // See if we force an average value CString sAttrib; if (pDesc->FindAttribute(LEVEL_VALUE_ATTRIB, &sAttrib)) { TArray<int> Values; ParseIntegerList(sAttrib, 0, &Values); m_AverageValue.InsertEmpty(MAX_ITEM_LEVEL + 1); m_AverageValue[0] = 0; for (i = 0; i < Values.GetCount(); i++) m_AverageValue[i + 1] = Values[i]; for (i = Values.GetCount() + 1; i <= MAX_ITEM_LEVEL; i++) m_AverageValue[i] = 0; } else if (pDesc->FindAttribute(VALUE_ATTRIB, &sAttrib)) { int iValue = strToInt(sAttrib, 0); m_AverageValue.InsertEmpty(MAX_ITEM_LEVEL + 1); m_AverageValue[0] = 0; for (i = 1; i <= MAX_ITEM_LEVEL; i++) m_AverageValue[i] = iValue; } return NOERROR; }
CString CPlayerGameStats::GetKeyEventStat (const CString &sStat, const CString &sNodeID, const CDesignTypeCriteria &Crit) const // GetKeyEventStat // // Returns the given key event stat { int i; // Get the list of stats TArray<SKeyEventStatsResult> List; if (!GetMatchingKeyEvents(sNodeID, Crit, &List)) return NIL_VALUE; if (strEquals(sStat, OBJS_DESTROYED_STAT)) { // Mark the events that we're interested in for (i = 0; i < List.GetCount(); i++) List[i].bMarked = ((List[i].pStats->iType == eventEnemyDestroyedByPlayer) || (List[i].pStats->iType == eventFriendDestroyedByPlayer) || (List[i].pStats->iType == eventMajorDestroyed)); // Done return GenerateKeyEventStat(List); } else if (strEquals(sStat, ENEMY_OBJS_DESTROYED_STAT)) { // Mark the events that we're interested in for (i = 0; i < List.GetCount(); i++) List[i].bMarked = (List[i].pStats->iType == eventEnemyDestroyedByPlayer); // Done return GenerateKeyEventStat(List); } else if (strEquals(sStat, FRIENDLY_OBJS_DESTROYED_STAT)) { // Mark the events that we're interested in for (i = 0; i < List.GetCount(); i++) List[i].bMarked = (List[i].pStats->iType == eventFriendDestroyedByPlayer); // Done return GenerateKeyEventStat(List); } else return NULL_STR; }
CMultiverseNewsEntry *CMultiverseModel::GetNextNewsEntry (void) // GetNextNewsEntry // // Returns the next news entry to display. // // NOTE: We return a copy which the callers are responsible for freeing. { CSmartLock Lock(m_cs); int i; // First make a list of all available news entries TArray<CMultiverseNewsEntry *> Available; for (i = 0; i < m_News.GetCount(); i++) { CMultiverseNewsEntry *pEntry = m_News.GetEntry(i); // If we've already shown this entry, skip it. if (pEntry->IsShown()) continue; // If this entry does not match the collection criteria, then skip it. if (m_Collection.HasAnyUNID(pEntry->GetExcludedUNIDs())) continue; if (!m_Collection.HasAllUNIDs(pEntry->GetRequiredUNIDs())) continue; Available.Insert(pEntry); } // If none available, nothing if (Available.GetCount() == 0) return NULL; // Pick a random entry CMultiverseNewsEntry *pEntry = Available[mathRandom(0, Available.GetCount() - 1)]; // Mark the entry as having been shown m_News.ShowNews(pEntry); // return this entry return new CMultiverseNewsEntry(*pEntry); }
void OutputByAttribute (SItemTableCtx &Ctx, const SItemTypeList &ItemList) { int i, j; // Make a categorized list by attribute SByAttributeTypeList ByAttributeTable; for (i = 0; i < ItemList.GetCount(); i++) { const CString &sKey = ItemList.GetKey(i); CItemType *pType = ItemList[i]; // Loop over all attributes TArray<CString> Attribs; ParseAttributes(pType->GetAttributes(), &Attribs); for (j = 0; j < Attribs.GetCount(); j++) { bool bNew; SAttributeEntry *pEntry = ByAttributeTable.SetAt(Attribs[j], &bNew); if (bNew) pEntry->sAttribute = Attribs[j]; pEntry->ItemTable.Insert(sKey, pType); } // If no attribute if (Attribs.GetCount() == 0) { bool bNew; SAttributeEntry *pEntry = ByAttributeTable.SetAt(CONSTLIT("(none)"), &bNew); if (bNew) pEntry->sAttribute = CONSTLIT("(none)"); pEntry->ItemTable.Insert(sKey, pType); } } // Now loop over all attributes for (i = 0; i < ByAttributeTable.GetCount(); i++) { const SAttributeEntry &Entry = ByAttributeTable[i]; printf("%s\n\n", Entry.sAttribute.GetASCIIZPointer()); OutputHeader(Ctx); OutputTable(Ctx, Entry.ItemTable); printf("\n"); } }
bool CAeonEngine::FlushTableRows (void) // FlushTableRows // // Save all in-memory rows to disk { int i; // Get a list of all tables TArray<CAeonTable *> AllTables; GetTables(&AllTables); // Loop over each table bool bAllSucceeded = true; for (i = 0; i < AllTables.GetCount(); i++) { CString sError; if (!AllTables[i]->Save(&sError)) { Log(MSG_LOG_ERROR, strPattern("Unable to save table %s: %s", AllTables[i]->GetName(), sError)); bAllSucceeded = false; // Continue saving other tables } } // Done return bAllSucceeded; }
void CTableOfDeviceGenerators::AddDevices (SDeviceGenerateCtx &Ctx) // AddDevices // // Add devices { int i, j; int iCount = m_Count.Roll(); for (j = 0; j < iCount; j++) { int iRoll = mathRandom(1, m_iTotalChance); for (i = 0; i < m_Table.GetCount(); i++) { iRoll -= m_Table[i].iChance; if (iRoll <= 0) { m_Table[i].pDevice->AddDevices(Ctx); break; } } } }
CString CreateDataFieldFromItemList (const TArray<CItem> &List) // CreateDataFieldFromItemList // // Creates a data field string from a list of items { int i; CCodeChain &CC = g_pUniverse->GetCC(); CMemoryWriteStream Output(10000); if (Output.Create() != NOERROR) return NULL_STR; Output.Write("='(", 3); for (i = 0; i < List.GetCount(); i++) { ICCItem *pItem = List[i].WriteToCCItem(CC); if (pItem->IsError()) { pItem->Discard(&CC); return NULL_STR; } CString sItem = pItem->Print(&CC); Output.Write(sItem.GetASCIIZPointer(), sItem.GetLength()); Output.Write(" ", 1); pItem->Discard(&CC); } Output.Write(")", 1); Output.Close(); return CString(Output.GetPointer(), Output.GetLength()); }
int CConquerNodesProc::CalcNodeWeight (CTopologyNode *pNode, TArray<SNodeWeight> &Weights, int *retiSuccessChance) // CalcNodeWeight // // Calculates the weight of the given node { int i; CTopologyNode::SCriteriaCtx Ctx; Ctx.pTopology = NULL; for (i = 0; i < Weights.GetCount(); i++) { if (pNode->MatchesCriteria(Ctx, Weights[i].Criteria)) { if (retiSuccessChance) *retiSuccessChance = Weights[i].iSuccessChance; return Weights[i].iWeight; } } if (retiSuccessChance) *retiSuccessChance = 0; return 0; }
JoystickImageImpl(float sensitivity) : m_sensitivity(sensitivity), m_bJoystickEnabled(false), m_bButtonsEnabled(false), m_bJustEnabled(false) { //Imago 7/10 for (int index = 0; index < m_ppboolButton.GetCount(); index++) { m_ppnumber[index] = new ModifiableNumber(false); } for (int index = 0; index < m_ppboolButton.GetCount(); index++) { m_ppboolButton[index] = new ModifiableBoolean(false); } }
CGlowingRingPainter::CGlowingRingPainter (CG32bitImage &Dest, int iRadius, int iWidth, const TArray<CG32bitPixel> &ColorRamp, BYTE byOpacity) : m_Dest(Dest), m_rcClip(Dest.GetClipRect()), m_iRadius(iRadius), m_iWidth(iWidth) // CGlowingRingPainter constructor { int i; // Pre-multiply the color ramp m_ColorRamp.InsertEmpty(ColorRamp.GetCount()); m_pColorRamp = &m_ColorRamp; if (byOpacity == 0xff) { for (i = 0; i < m_ColorRamp.GetCount(); i++) m_ColorRamp[i] = CG32bitPixel::PreMult(ColorRamp[i]); } else { for (i = 0; i < m_ColorRamp.GetCount(); i++) { CG32bitPixel rgbPreMult = CG32bitPixel::PreMult(ColorRamp[i]); m_ColorRamp[i] = CG32bitPixel(CG32bitPixel::Blend(0, rgbPreMult, byOpacity), CG32bitPixel::BlendAlpha(rgbPreMult.GetAlpha(), byOpacity)); } } }
bool CAeonView::CreateSecondaryRows (const CTableDimensions &PrimaryDims, CHexeProcess &Process, const CRowKey &PrimaryKey, CDatum dFullData, SEQUENCENUMBER RowID, CAeonRowArray *Rows) // CreateSecondaryRow // // Returns the key and data for a secondary view row. If the secondary key has // all non-nil values then we return TRUE. FALSE otherwise. { int i; // Compute columns, if necessary dFullData = ComputeColumns(Process, dFullData); // Create keys TArray<CRowKey> Keys; if (!CreateSecondaryKeys(Process, dFullData, RowID, &Keys)) return false; // Create row data CDatum dRowData; CreateSecondaryData(PrimaryDims, PrimaryKey, dFullData, RowID, &dRowData); for (i = 0; i < Keys.GetCount(); i++) Rows->Insert(Keys[i], dRowData, RowID); return true; }
void CComplexArea::AddRect (TArray<SRect> &Array, int x, int y, int cxWidth, int cyHeight, int iRotation) // AddRect // // Adds the rect { int i; if (cxWidth <= 0 || cyHeight <= 0) return; // See if we already have a rect like this for (i = 0; i < Array.GetCount(); i++) { SRect &Test = Array[i]; if (Test.x == x && Test.y == y && Test.iRotation == iRotation && Test.cxWidth == cxWidth && Test.cyHeight == cyHeight) return; } // Add it SRect *pRect = Array.Insert(); pRect->x = x; pRect->y = y; pRect->cxWidth = cxWidth; pRect->cyHeight = cyHeight; pRect->iRotation = (iRotation > 0 ? (iRotation % 360) : 0); // Add to bounds if (iRotation > 0) { int xLL = 0; int yLL = 0; int xLR, yLR; IntPolarToVector(iRotation, cxWidth, &xLR, &yLR); int xUL, yUL; IntPolarToVector(iRotation + 90, cyHeight, &xUL, &yUL); int xUR = xUL + xLR; int yUR = yUL + yLR; int xLeft = Min(Min(xLL, xLR), Min(xUL, xUR)); int xRight = Max(Max(xLL, xLR), Max(xUL, xUR)); int yTop = Max(Max(yLL, yLR), Max(yUL, yUR)); int yBottom = Min(Min(yLL, yLR), Min(yUL, yUR)); AddToBounds(x + xLeft, y + yTop, x + xRight, y + yBottom); } else AddToBounds(x, y + cyHeight, x + cxWidth, y); }
void CAeonEngine::MsgGetTables (const SArchonMessage &Msg, const CHexeSecurityCtx *pSecurityCtx) // MsgGetTables // // Aeon.getTables { int i; if (!m_bReady) { SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, ERR_NOT_READY, Msg); return; } // Get a list of all tables TArray<CAeonTable *> AllTables; GetTables(&AllTables); // Return an array of table descriptors CComplexArray *pArray = new CComplexArray; for (i = 0; i < AllTables.GetCount(); i++) { if (pSecurityCtx && !pSecurityCtx->IsNamespaceAccessible(AllTables[i]->GetName())) continue; pArray->Insert(AllTables[i]->GetDesc()); } // Reply SendMessageReply(MSG_AEON_RESULT_TABLES, CDatum(pArray), Msg); }
ALERROR CMultiverseModel::SetCollection (const TArray<CMultiverseCatalogEntry *> &NewCollection) // SetCollection // // Sets the collection from a list of entries. // NOTE: We take ownership of the catalog entries. { CSmartLock Lock(m_cs); int i; // Replace our collection. DeleteCollection(); for (i = 0; i < NewCollection.GetCount(); i++) { m_Collection.Insert(NewCollection[i]); // Get the resources in this entry and add them to our list AddResources(*NewCollection[i]); } // Done m_fCollectionLoaded = true; m_fLoadingCollection = false; return NOERROR; }
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); }
void CSystemCreateStats::AddEntryPermutations (const CString &sPrefix, const TArray<CString> &Attribs, int iPos) // AddEntryPermutations // // Adds permutions { // If nothing, then nothing if (iPos >= Attribs.GetCount()) return; // Get the base case CString sNewPrefix; if (!sPrefix.IsBlank()) sNewPrefix = strPatternSubst(CONSTLIT("%s,%s"), sPrefix, Attribs[iPos]); else sNewPrefix = Attribs[iPos]; AddEntry(sNewPrefix); // Permute with the base case AddEntryPermutations(sNewPrefix, Attribs, iPos + 1); // Permute the remainder AddEntryPermutations(sPrefix, Attribs, iPos + 1); }
ALERROR CLocationCriteriaTableEntry::InitFromXML (SDesignLoadCtx &Ctx, CIDCounter &IDGen, CXMLElement *pDesc) // InitFromXML // // Initialize from XML { ALERROR error; int i; m_dwID = IDGen.GetID(); m_iDefault = -1; // Load each sub-entry in turn int iCount = pDesc->GetContentElementCount(); if (iCount == 0) return NOERROR; m_Table.InsertEmpty(iCount); for (i = 0; i < iCount; i++) { CXMLElement *pItem = pDesc->GetContentElement(i); if (error = CCompositeImageDesc::InitEntryFromXML(Ctx, pItem, IDGen, &m_Table[i].pImage)) return error; // Load the criteria CString sCriteria = pItem->GetAttribute(CRITERIA_ATTRIB); if (error = m_Table[i].Criteria.Parse(sCriteria, 0, &Ctx.sError)) return error; if (m_iDefault == -1 && m_Table[i].Criteria.MatchesDefault()) m_iDefault = i; } // If we don't have a default, the pick the last item. if (m_iDefault == -1 && m_Table.GetCount() > 0) m_iDefault = m_Table.GetCount() - 1; // Done return NOERROR; }
void CLevelTableOfItemGenerators::AddItems (SItemAddCtx &Ctx) // AddItems // // Adds items { int i, j; // Compute probabilities, if necessary if (m_iComputedLevel != Ctx.iLevel) { // Create a table of probabilities m_iTotalChance = 0; for (i = 0; i < m_Table.GetCount(); i++) { m_Table[i].iChance = GetFrequencyByLevel(m_Table[i].sLevelFrequency, Ctx.iLevel); m_iTotalChance += m_Table[i].iChance; } m_iComputedLevel = Ctx.iLevel; } // Generate if (m_iTotalChance) { int iRoll = mathRandom(1, m_iTotalChance); for (i = 0; i < m_Table.GetCount(); i++) { iRoll -= m_Table[i].iChance; if (iRoll <= 0) { int iCount = m_Table[i].Count.Roll(); for (j = 0; j < iCount; j++) m_Table[i].pEntry->AddItems(Ctx); break; } } } }
void CLevelTableOfDeviceGenerators::AddDevices (SDeviceGenerateCtx &Ctx) // AddDevices // // Adds devices { int i, j; // Compute probabilities if (Ctx.iLevel != m_iComputedLevel) { m_iTotalChance = 0; for (i = 0; i < m_Table.GetCount(); i++) { m_Table[i].iChance = GetFrequencyByLevel(m_Table[i].sLevelFrequency, Ctx.iLevel); m_iTotalChance += m_Table[i].iChance; } m_iComputedLevel = Ctx.iLevel; } // Generate if (m_iTotalChance) { int iCount = m_Count.Roll(); for (i = 0; i < iCount; i++) { int iRoll = mathRandom(1, m_iTotalChance); for (j = 0; j < m_Table.GetCount(); j++) { iRoll -= m_Table[j].iChance; if (iRoll <= 0) { m_Table[j].pDevice->AddDevices(Ctx); break; } } } } }
bool CSystemCreateStats::FindEncounterTable (TArray<CStationTableCache::SEntry> &Src, SEncounterTable **retpTable) const // FindEncounterTable // // Looks for an encounter table that matches the source. If we find one, we // return a pointer to the table. Otherwise we return FALSE. { int i, j; for (i = 0; i < m_EncounterTables.GetCount(); i++) { const TProbabilityTable<CStationType *> &Table = m_EncounterTables[i].Table; // If we have different counts, then we're different if (Table.GetCount() != Src.GetCount()) continue; // Compare each entry bool bMatches = true; for (j = 0; j < Src.GetCount(); j++) { if (Src[j].pType != Table.GetAt(j) || Src[j].iChance != Table.GetChance(j)) { bMatches = false; break; } } // If we match, then we found a table. if (bMatches) { if (retpTable) *retpTable = &m_EncounterTables[i]; return true; } } // Otherwise, we did not find it. return false; }
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 }
void CUIHelper::PaintDisplayAttributes (CG16bitImage &Dest, TArray<SDisplayAttribute> &Attribs) const // PaintDisplayAttributes // // Paints all display attributes. We assume that FormatDisplayAttributes // has already been called. { int i; const CVisualPalette &VI = m_HI.GetVisuals(); const CG16bitFont &Medium = VI.GetFont(fontMedium); for (i = 0; i < Attribs.GetCount(); i++) { WORD wBackColor; WORD wTextColor; // Figure out the colors switch (Attribs[i].iType) { case attribPositive: wBackColor = VI.GetColor(colorAreaAdvantage); wTextColor = VI.GetColor(colorTextAdvantage); break; case attribNegative: wBackColor = VI.GetColor(colorAreaDisadvantage); wTextColor = VI.GetColor(colorTextDisadvantage); break; default: wBackColor = RGB_MODIFIER_NORMAL_BACKGROUND; wTextColor = RGB_MODIFIER_NORMAL_TEXT; break; } // Draw the background ::DrawRoundedRect(Dest, Attribs[i].rcRect.left, Attribs[i].rcRect.top, RectWidth(Attribs[i].rcRect), RectHeight(Attribs[i].rcRect), 4, wBackColor); // Draw the text Medium.DrawText(Dest, Attribs[i].rcRect.left + ATTRIB_PADDING_X, Attribs[i].rcRect.top + ATTRIB_PADDING_Y, wTextColor, 255, Attribs[i].sText); } }
void CSystemCreateStats::AddStationTable (CSystem *pSystem, const CString &sStationCriteria, const CString &sLocationAttribs, TArray<CStationTableCache::SEntry> &Table) // AddStationTable // // Adds the station table. { int i; // See if we already have an entry for this table. // If we don't we add it. SEncounterTable *pEntry; if (!FindEncounterTable(Table, &pEntry)) { pEntry = m_EncounterTables.Insert(); pEntry->iLevel = pSystem->GetLevel(); pEntry->pSystemType = pSystem->GetType(); pEntry->sStationCriteria = sStationCriteria; pEntry->iCount = 1; ParseAttributes(sLocationAttribs, &pEntry->LabelAttribs); pEntry->bHasStation = false; for (i = 0; i < Table.GetCount(); i++) { pEntry->Table.Insert(Table[i].pType, Table[i].iChance); if (Table[i].pType->GetScale() == scaleStructure || Table[i].pType->GetScale() == scaleShip) pEntry->bHasStation = true; } return; } // If we already have the table we need to aggregate the entry. We start // by incrementing the count. pEntry->iCount++; // Next we remove any location/label attributes that are not common to // both tables. [We assume that if we have two identical tables then only // the attributes in common count to make the table unique.] TArray<CString> NewAttribs; ParseAttributes(sLocationAttribs, &NewAttribs); for (i = 0; i < pEntry->LabelAttribs.GetCount(); i++) { if (!NewAttribs.Find(pEntry->LabelAttribs[i])) { pEntry->LabelAttribs.Delete(i); i--; } } }