ALERROR CSingleItem::LoadFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc) // LoadFromXML // // Load from XML { ALERROR error; if (error = m_pItemType.LoadUNID(Ctx, pDesc->GetAttribute(ITEM_ATTRIB))) return error; m_iDamaged = pDesc->GetAttributeInteger(DAMAGED_ATTRIB); m_bDebugOnly = pDesc->GetAttributeBool(DEBUG_ONLY_ATTRIB); if (m_pItemType.GetUNID() == 0) { CString sUNID = pDesc->GetAttribute(ITEM_ATTRIB); if (sUNID.IsBlank()) Ctx.sError = strPatternSubst(CONSTLIT("<Item> element missing item attribute.")); else Ctx.sError = strPatternSubst(CONSTLIT("Invalid item UNID: %s"), sUNID); return ERR_FAIL; } if (error = m_Enhanced.InitFromXML(Ctx, pDesc)) return error; return NOERROR; }
CString CDeviceClass::GetReferencePower (CItemCtx &Ctx) // GetReferencePower // // Returns a string for the reference relating to the power required for // this device. { int iPower = GetPowerRating(Ctx); // Compute the power units CString sUnit; if (iPower == 0) return NULL_STR; else if (iPower >= 10000) { sUnit = CONSTLIT("GW"); iPower = iPower / 1000; } else sUnit = CONSTLIT("MW"); // Decimal int iMW = iPower / 10; int iMWDecimal = iPower % 10; if (iMW >= 100 || iMWDecimal == 0) return strPatternSubst(CONSTLIT("%d %s"), iMW, sUnit); else return strPatternSubst(CONSTLIT("%d.%d %s"), iMW, iMWDecimal, sUnit); }
void CUIHelper::CreateClassInfoCargo (CShipClass *pClass, const CDeviceDescList &Devices, int x, int y, int cxWidth, DWORD dwOptions, int *retcyHeight, IAnimatron **retpInfo) const // CreateClassInfoCargo // // Creates info about the ship class' cargo { const CVisualPalette &VI = m_HI.GetVisuals(); CDeviceClass *pCargoExtension = Devices.GetNamedDevice(devCargo); int iCargoSpace = pClass->GetCargoSpace(); if (pCargoExtension) iCargoSpace += pCargoExtension->GetCargoSpace(); // Icon CItemType *pItemIcon = (pCargoExtension ? pCargoExtension->GetItemType() : g_pUniverse->FindItemType(CARGO_HOLD_EXPANSION_UNID)); // Text CString sText = strPatternSubst(CONSTLIT("{/rtf {/f:LargeBold;/c:%d; %s} {/f:MediumBold;/c:%d; %s}\n{/f:Medium;/c:%d; %s}}"), CG16bitImage::RGBFromPixel(VI.GetColor(colorTextDialogLabel)), strFromInt(iCargoSpace, TRUE), CG16bitImage::RGBFromPixel(VI.GetColor(colorTextDialogInput)), (pCargoExtension ? strPatternSubst(CONSTLIT("ton %s"), CTextBlock::Escape(pCargoExtension->GetItemType()->GetNounPhrase(nounActual))) : CONSTLIT("ton cargo hold")), CG16bitImage::RGBFromPixel(VI.GetColor(colorTextDialogLabel)), (iCargoSpace < pClass->GetMaxCargoSpace() ? strPatternSubst(CONSTLIT("optional expansion up to %d tons"), pClass->GetMaxCargoSpace()) : CONSTLIT("cargo space cannot be expanded"))); CreateClassInfoSpecialItem(pItemIcon, sText, x, y, cxWidth, dwOptions, retcyHeight, retpInfo); }
CString CCInteger::Print (CCodeChain *pCC, DWORD dwFlags) // Print // // Returns a text representation of this item { // If this is an error code, translate it if (IsError()) { switch (m_iValue) { case CCRESULT_NOTFOUND: return strPatternSubst(LITERAL("[%d] Item not found."), m_iValue); case CCRESULT_CANCEL: return strPatternSubst(LITERAL("[%d] Operation canceled."), m_iValue); case CCRESULT_DISKERROR: return strPatternSubst(LITERAL("[%d] Disk error."), m_iValue); default: return strPatternSubst(LITERAL("[%d] Unknown error."), m_iValue); } } // Otherwise, just print the integer value else return strFromInt(m_iValue, TRUE); }
ALERROR CDesignCollection::AddEntry (SDesignLoadCtx &Ctx, CDesignType *pEntry) // AddEntry // // Adds an entry to the collection { ALERROR error; DWORD dwUNID = pEntry->GetUNID(); // If this is an extension, then add to the appropriate extension CDesignTable *pTable = NULL; if (Ctx.pExtension) { pTable = &Ctx.pExtension->Table; // If the UNID of the entry does not belong to the extension, then make sure it // overrides a valid base entry if (!Ctx.pExtension->bRegistered && (dwUNID & UNID_DOMAIN_AND_MODULE_MASK) != (Ctx.pExtension->dwUNID & UNID_DOMAIN_AND_MODULE_MASK)) { // Cannot override AdventureDesc if (pEntry->GetType() == designAdventureDesc) { Ctx.sError = CONSTLIT("<AdventureDesc> UNID must be part of extension."); return ERR_FAIL; } // Make sure we override a base type else if (m_Base.FindByUNID(dwUNID) == NULL) { Ctx.sError = strPatternSubst(CONSTLIT("Invalid UNID: %x [does not match extension UNID or override base type]"), dwUNID); return ERR_FAIL; } } } // Otherwise, add to the base design types else pTable = &m_Base; // Add if (error = pTable->AddEntry(pEntry)) { if (pTable->FindByUNID(dwUNID)) Ctx.sError = strPatternSubst(CONSTLIT("Duplicate UNID: %x"), dwUNID); else Ctx.sError = strPatternSubst(CONSTLIT("Error adding design entry UNID: %x"), dwUNID); return error; } return NOERROR; }
ALERROR CMarkovWordGenerator::WriteAsXML (IWriteStream *pOutput) // WriteAsXML // // Writes out the Markov chain data to an XML element { ALERROR error; int i; // Open tag CString sData; sData = CONSTLIT("\t<WordGenerator>\r\n"); if (error = pOutput->Write(sData.GetPointer(), sData.GetLength(), NULL)) return error; // Fragments for (i = 0; i < m_Table.GetCount(); i++) { sData = CONSTLIT("\t\t<Syl>"); if (error = pOutput->Write(sData.GetPointer(), sData.GetLength(), NULL)) return error; sData = strPatternSubst(CONSTLIT("%s;%d;%d;"), strToXMLText(CString(m_Table[i]->sFrag)), m_Table[i]->dwCount, m_Table[i]->dwFlags); if (error = pOutput->Write(sData.GetPointer(), sData.GetLength(), NULL)) return error; SChainChar *pChain = GetChain(m_Table[i]); while ((*(DWORD *)pChain) != 0) { char chChar[2]; chChar[0] = pChain->chChar; chChar[1] = '\0'; CString sChar = strToXMLText(CString(chChar, 1, true)); sData = strPatternSubst(CONSTLIT("%s;%d;"), sChar, pChain->dwCount); if (error = pOutput->Write(sData.GetPointer(), sData.GetLength(), NULL)) return error; pChain++; } sData = CONSTLIT("</Syl>\r\n"); if (error = pOutput->Write(sData.GetPointer(), sData.GetLength(), NULL)) return error; } // Done // Close tag sData = CONSTLIT("\t</WordGenerator>\r\n"); if (error = pOutput->Write(sData.GetPointer(), sData.GetLength(), NULL)) return error; return NOERROR; }
bool arcDecompressFile (const CString &sArchive, const CString &sFilename, IWriteStream &Output, CString *retsError) // arcDecompressFile // // Unzips to a stream. { unzFile theZipFile = unzOpen(sArchive.GetASCIIZPointer()); if (theZipFile == NULL) { *retsError = strPatternSubst(CONSTLIT("Unable to open file: %s."), sArchive); return false; } if (unzLocateFile(theZipFile, sFilename.GetASCIIZPointer(), 0) != UNZ_OK) { unzClose(theZipFile); *retsError = strPatternSubst(CONSTLIT("Unable to find file in archive: %s."), sFilename); return false; } if (unzOpenCurrentFile(theZipFile) != UNZ_OK) { unzClose(theZipFile); *retsError = strPatternSubst(CONSTLIT("Unable to open file in archive: %s."), sFilename); return false; } while (true) { char szBuffer[BUFFER_SIZE]; int iRead = unzReadCurrentFile(theZipFile, szBuffer, BUFFER_SIZE); if (iRead == 0) break; else if (iRead < 0) { unzCloseCurrentFile(theZipFile); unzClose(theZipFile); *retsError = CONSTLIT("Error reading archive."); return false; } Output.Write(szBuffer, iRead); } // Returns UNZ_CRCERROR if the file failed its CRC check. if (unzCloseCurrentFile(theZipFile) != UNZ_OK) { unzClose(theZipFile); *retsError = strPatternSubst(CONSTLIT("File in archive corrupted: %s."), sArchive); return false; } unzClose(theZipFile); return true; }
CString GetTypeDesc (CDesignType *pType) { CString sName = pType->GetTypeName(); if (sName.IsBlank()) return strPatternSubst(CONSTLIT("%08x: [%s]"), pType->GetUNID(), pType->GetTypeClassName()); else return strPatternSubst(CONSTLIT("%08x: %s [%s]"), pType->GetUNID(), sName, pType->GetTypeClassName()); }
CString CShieldClass::GetReference (CItemCtx &Ctx, int iVariant, DWORD dwFlags) // GetReference // // Returns a string that describes the basic attributes // of this shield // // Example: // // 20 hp (average regen); 100MW { int i; CString sReference; CString sRegeneration; const CItemEnhancement &Mods = Ctx.GetMods(); // Compute the strength string int iMin, iMax; CalcMinMaxHP(Ctx, m_iMaxCharges, 0, 0, &iMin, &iMax); // Compute the regeneration if (m_iRegenHP > 0) { int iRate = (int)((10.0 * g_TicksPerSecond * m_iRegenHP / m_iRegenRate) + 0.5); if (iRate == 0) sRegeneration = CONSTLIT("<0.1 hp/sec"); else if ((iRate % 10) == 0) sRegeneration = strPatternSubst(CONSTLIT("%d hp/sec"), iRate / 10); else sRegeneration = strPatternSubst(CONSTLIT("%d.%d hp/sec"), iRate / 10, iRate % 10); } else sRegeneration = CONSTLIT("none"); sReference = strPatternSubst("%s — regen @ %s", GetReferencePower(Ctx), sRegeneration); // Reflection for (i = 0; i < damageCount; i++) { if (m_Reflective.InSet((DamageTypes)i) || (Mods.IsReflective() && Mods.GetDamageType() == i)) sReference.Append(strPatternSubst(CONSTLIT(" — %s-reflecting"), GetDamageShortName((DamageTypes)i))); } return sReference; }
ALERROR CImageLibrary::AddImage (SDesignLoadCtx &Ctx, CXMLElement *pDesc) // AddImage // // Add an image to the library { ALERROR error; // Create the image desc CObjectImage *pNewImage; if (error = CObjectImage::CreateFromXML(Ctx, pDesc, &pNewImage)) return error; // If we defer loading, at least make sure that the images exist if (pDesc->GetAttributeBool(LOAD_ON_USE_ATTRIB)) { if (error = pNewImage->Exists(Ctx)) { delete pNewImage; return error; } } // Otherwise, load and lock the image else { if (error = pNewImage->Lock(Ctx)) { delete pNewImage; return error; } } // Add to the library if (error = m_Library.AddEntry(pNewImage->GetUNID(), (CObject *)pNewImage)) { if (FindImage(pNewImage->GetUNID())) Ctx.sError = strPatternSubst(CONSTLIT("Duplicate UNID: %x"), pNewImage->GetUNID()); else Ctx.sError = strPatternSubst(CONSTLIT("Unable to add image to library: %x"), pNewImage->GetUNID()); delete pNewImage; return error; } return NOERROR; }
ALERROR CResourceDb::LoadEntities (CString *retsError) // LoadEntities // // Loads the entities of a game file { ALERROR error; if (m_pMainDb == NULL) { if (m_bGameFileInDb && m_pDb) { ASSERT(m_pResourceMap); CString sGameFile; if ((error = m_pDb->ReadEntry(m_iGameFile, &sGameFile))) { *retsError = strPatternSubst(CONSTLIT("%s is corrupt"), m_sGameFile.GetASCIIZPointer()); return error; } // Parse the XML file from the buffer CBufferReadBlock GameFile(sGameFile); CString sError; if ((error = CXMLElement::ParseEntityTable(&GameFile, &m_Entities, &sError))) { *retsError = strPatternSubst(CONSTLIT("Unable to parse %s: %s"), m_sGameFile.GetASCIIZPointer(), sError.GetASCIIZPointer()); return error; } } else { // Parse the XML file on disk CFileReadBlock DataFile(pathAddComponent(m_sRoot, m_sGameFile)); CString sError; if ((error = CXMLElement::ParseEntityTable(&DataFile, &m_Entities, &sError))) { *retsError = strPatternSubst(CONSTLIT("Unable to parse %s: %s"), m_sGameFile.GetASCIIZPointer(), sError.GetASCIIZPointer()); return error; } } } return NOERROR; }
ALERROR CEffectCreator::CreateSimpleFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, const CString &sUNID, CEffectCreator **retpCreator) // CreateSimpleFromXML // // Creates the creator from an XML element { ALERROR error; CEffectCreator *pCreator; // Create the effect based on the tag if (error = CreateFromTag(pDesc->GetTag(), &pCreator)) { Ctx.sError = strPatternSubst(CONSTLIT("Invalid painter tag: %s"), pDesc->GetTag()); return error; } if (pCreator == NULL) return ERR_MEMORY; pCreator->m_sUNID = sUNID; // Type-specific creation if (error = pCreator->OnEffectCreateFromXML(Ctx, pDesc, sUNID)) return error; // Done *retpCreator = pCreator; return NOERROR; }
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); }
ICCItem *CCodeChain::CreateError (const CString &sError, ICCItem *pData) // CreateError // // Creates an item // // sError: Error messages // pData: Item that caused error. { ICCItem *pError; CString sArg; CString sErrorLine; // Convert the argument to a string if (pData) { sArg = pData->Print(this); sErrorLine = strPatternSubst(LITERAL("%s [%s]"), sError, sArg); } else sErrorLine = sError; // Create the error pError = CreateString(sErrorLine); pError->SetError(); return pError; }
ALERROR CMultiverseCatalogEntry::CreateBasicEntry (const SEntryCreate &Create, CMultiverseCatalogEntry **retpEntry) // CreateBasicEntry // // Creates a hard-coded catalog entry for Steam. { CMultiverseCatalogEntry *pNewEntry = new CMultiverseCatalogEntry; pNewEntry->m_dwUNID = Create.dwUNID; pNewEntry->m_sUNID = strPatternSubst(CONSTLIT("Transcendence:%08x"), Create.dwUNID); pNewEntry->m_dwRelease = 1; pNewEntry->m_dwVersion = 1; pNewEntry->m_sName = Create.sName; pNewEntry->m_sDesc = Create.sDesc; pNewEntry->m_iType = Create.iType; pNewEntry->m_iLicenseType = Create.iLicense; // Initialize status pNewEntry->m_iStatus = statusUnknown; pNewEntry->m_pIcon = NULL; // Done *retpEntry = pNewEntry; return NOERROR; }
ALERROR CAdventureDesc::GetStartingShipClasses (TSortMap<CString, CShipClass *> *retClasses, CString *retsError) // GetStartingShipClasses // // Returns a sorted list of ship classes for this adventure { int i; bool bShowDebugShips = g_pUniverse->InDebugMode(); // Make a list retClasses->DeleteAll(); for (i = 0; i < g_pUniverse->GetShipClassCount(); i++) { CShipClass *pClass = g_pUniverse->GetShipClass(i); if (pClass->IsShownAtNewGame() && IsValidStartingClass(pClass) && (!pClass->IsDebugOnly() || bShowDebugShips)) { CString sKey = strPatternSubst(CONSTLIT("%d %s !%x"), (pClass->IsDebugOnly() ? 2 : 1), pClass->GetName(), pClass->GetUNID()); retClasses->Insert(sKey, pClass); } } return NOERROR; }
ALERROR CUniverse::LoadSound (SDesignLoadCtx &Ctx, CXMLElement *pElement) // LoadSound // // Load a sound element { ALERROR error; if (Ctx.bNoResources) return NOERROR; DWORD dwUNID = LoadUNID(Ctx, pElement->GetAttribute(UNID_ATTRIB)); CString sFilename = pElement->GetAttribute(FILENAME_ATTRIB); // Load the image int iChannel; if (error = Ctx.pResDb->LoadSound(*m_pSoundMgr, NULL_STR, sFilename, &iChannel)) { Ctx.sError = strPatternSubst(CONSTLIT("Unable to load sound: %s"), sFilename.GetASCIIZPointer()); return error; } if (error = m_Sounds.AddEntry((int)dwUNID, (CObject *)iChannel)) { Ctx.sError = CONSTLIT("Unable to add sound"); return error; } #ifdef DEBUG_SOURCE_LOAD_TRACE kernelDebugLogMessage("Loaded sound: %x", dwUNID); #endif return NOERROR; }
CString FormatTwoUnits (const CString &sMajor, const CString &sMinor, int iMinor) { if (iMinor == 0) return sMajor; else return strPatternSubst(CONSTLIT("%s and %s"), sMajor, sMinor); }
ALERROR CUniverse::LoadSystemNode (SDesignLoadCtx &Ctx, CXMLElement *pElement) // LoadSystemNode // // Loads a topology node { #if 0 ALERROR error; // See if the node already exists CString sNodeID = pElement->GetAttribute(ID_ATTRIB); if (m_TopologyDesc.Lookup(sNodeID, NULL) == NOERROR) { Ctx.sError = strPatternSubst(CONSTLIT("SystemNode '%s' already defined."), sNodeID); return ERR_FAIL; } // Add the element if (error = m_TopologyDesc.AddEntry(sNodeID, pElement->OrphanCopy())) { Ctx.sError = CONSTLIT("Unable to add topology node."); return error; } #endif return NOERROR; }
ALERROR CRandomItems::LoadFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc) // LoadFromXML // // Load from XML { ALERROR error; CString sCriteria = pDesc->GetAttribute(CRITERIA_ATTRIB); if (sCriteria.IsBlank()) { CString sAttributes = pDesc->GetAttribute(ATTRIBUTES_ATTRIB); if (sAttributes.IsBlank()) sAttributes = pDesc->GetAttribute(MODIFIERS_ATTRIB); sCriteria = strPatternSubst(CONSTLIT("%s %s"), pDesc->GetAttribute(CATEGORIES_ATTRIB), sAttributes); } CItem::ParseCriteria(sCriteria, &m_Criteria); m_sLevelFrequency = pDesc->GetAttribute(LEVEL_FREQUENCY_ATTRIB); m_iLevel = pDesc->GetAttributeInteger(LEVEL_ATTRIB); m_iLevelCurve = pDesc->GetAttributeInteger(LEVEL_CURVE_ATTRIB); m_iDamaged = pDesc->GetAttributeInteger(DAMAGED_ATTRIB); if (error = m_Enhanced.InitFromXML(Ctx, pDesc)) return error; m_Table = NULL; m_iCount = 0; return NOERROR; }
ALERROR CSingleDevice::OnDesignLoadComplete (SDesignLoadCtx &Ctx) // OnDesignLoadComplete // // Resolve references { ALERROR error; if (error = m_pItemType.Bind(Ctx)) return error; if (m_pExtraItems) if (error = m_pExtraItems->OnDesignLoadComplete(Ctx)) return error; // Error checking if (m_pItemType) if (m_pItemType->GetDeviceClass() == NULL) { Ctx.sError = strPatternSubst(CONSTLIT("%s is not a device"), m_pItemType->GetName(NULL, true)); return ERR_FAIL; } return NOERROR; }
ALERROR WriteHeader (CTDBCompiler &Ctx, int iGameFile, CDataFile &Out) { ALERROR error; CMemoryWriteStream Stream; if (error = Stream.Create()) { Ctx.ReportError(CONSTLIT("Out of memory")); return error; } // Write it CString sError; if (!Ctx.WriteHeader(Stream, iGameFile, &sError)) { Ctx.ReportError(strPatternSubst(CONSTLIT("Unable to write header: %s"), sError)); return ERR_FAIL; } // Write out the header Stream.Close(); CString sData(Stream.GetPointer(), Stream.GetLength(), TRUE); int iEntry; if (error = Out.AddEntry(sData, &iEntry)) { Ctx.ReportError(CONSTLIT("Unable to write header")); return error; } Out.SetDefaultEntry(iEntry); return NOERROR; }
ALERROR CFlareEffectCreator::OnEffectCreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, const CString &sUNID) // OnEffectCreateFromXML // // Initializes from XML { CString sStyle = pDesc->GetAttribute(STYLE_ATTRIB); if (strEquals(sStyle, STYLE_FADING_BLAST)) m_iStyle = styleFadingBlast; else if (strEquals(sStyle, STYLE_FLICKER)) m_iStyle = styleFlicker; else if (sStyle.IsBlank() || strEquals(sStyle, STYLE_PLAIN)) m_iStyle = stylePlain; else { Ctx.sError = strPatternSubst(CONSTLIT("Invalid Flare style: %s"), sStyle); return ERR_FAIL; } m_iRadius = pDesc->GetAttributeIntegerBounded(RADIUS_ATTRIB, 0, -1, 100); m_iLifetime = pDesc->GetAttributeIntegerBounded(LIFETIME_ATTRIB, 0, -1, 1); m_rgbPrimaryColor = ::LoadRGBColor(pDesc->GetAttribute(PRIMARY_COLOR_ATTRIB)); CString sAttrib; if (pDesc->FindAttribute(SECONDARY_COLOR_ATTRIB, &sAttrib)) m_rgbSecondaryColor = ::LoadRGBColor(sAttrib); else m_rgbSecondaryColor = m_rgbPrimaryColor; return NOERROR; }
CG16bitImage *CObjectImage::CreateCopy (CString *retsError) // CreateCopy // // Creates a copy of the image. Caller must manually free the image when done. { // If we have the image, the we need to make a copy if (m_pBitmap) { CG16bitImage *pResult = new CG16bitImage; if (pResult->CreateFromImage(*m_pBitmap) != NOERROR) return NULL; return pResult; } // Otherwise, we load a copy CResourceDb ResDb(m_sResourceDb, NULL, !strEquals(m_sResourceDb, g_pUniverse->GetResourceDb())); if (ResDb.Open(DFOPEN_FLAG_READ_ONLY) != NOERROR) { if (retsError) *retsError = strPatternSubst(CONSTLIT("Unable to open resource db: '%s'"), m_sResourceDb); return NULL; } CG16bitImage *pResult = GetImage(ResDb, retsError); m_pBitmap = NULL; // Clear out because we don't keep a copy return pResult; }
ALERROR CEffectVariantCreator::OnEffectCreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, const CString &sUNID) // OnEffectCreateFromXML // // Creates from XML { ALERROR error; int i; // Allocate the creator array int iCount = pDesc->GetContentElementCount(); if (iCount == 0) { Ctx.sError = CONSTLIT("<Variants> effect must have at least one sub-element."); return ERR_FAIL; } m_Effects.InsertEmpty(iCount); for (i = 0; i < iCount; i++) { CString sSubUNID = strPatternSubst(CONSTLIT("%s/%d"), sUNID, i); CXMLElement *pCreatorDesc = pDesc->GetContentElement(i); if (error = CEffectCreator::CreateFromXML(Ctx, pCreatorDesc, sSubUNID, &m_Effects[i].pEffect)) return error; m_Effects[i].iMaxValue = pCreatorDesc->GetAttributeInteger(MAX_VALUE_ATTRIB); } return NOERROR; }
ALERROR CEconomyTypeRef::Bind (SDesignLoadCtx &Ctx) // Bind // // Bind the design { if (m_sUNID.IsBlank()) { if (g_pDefaultEconomy == NULL) g_pDefaultEconomy = CEconomyType::AsType(g_pUniverse->FindDesignType(DEFAULT_ECONOMY_UNID)); m_pType = g_pDefaultEconomy; } else { m_pType = GetEconomyTypeFromString(m_sUNID); if (m_pType == NULL) { Ctx.sError = strPatternSubst(CONSTLIT("Unable to find economy type: %s"), m_sUNID); return ERR_FAIL; } } return NOERROR; }
ALERROR CDeviceClass::ParseLinkedFireOptions (SDesignLoadCtx &Ctx, const CString &sDesc, DWORD *retdwOptions) // ParseLinkedFireOptions // // Parses a linked-fire options string. { DWORD dwOptions = 0; if (sDesc.IsBlank()) ; else if (strEquals(sDesc, LINKED_FIRE_ALWAYS)) dwOptions |= CDeviceClass::lkfAlways; else if (strEquals(sDesc, LINKED_FIRE_TARGET)) dwOptions |= CDeviceClass::lkfTargetInRange; else if (strEquals(sDesc, LINKED_FIRE_ENEMY)) dwOptions |= CDeviceClass::lkfEnemyInRange; else { Ctx.sError = strPatternSubst(CONSTLIT("Invalid linkedFire option: %s"), sDesc); return ERR_FAIL; } *retdwOptions = dwOptions; return NOERROR; }
ALERROR CObjectImageArray::OnDesignLoadComplete (SDesignLoadCtx &Ctx) // OnDesignLoadComplete // // All design elements have been loaded { #ifdef NO_RESOURCES if (Ctx.bNoResources) return NOERROR; #endif if (m_dwBitmapUNID) { m_pImage = g_pUniverse->FindLibraryImage(m_dwBitmapUNID); if (m_pImage == NULL) { Ctx.sError = strPatternSubst(CONSTLIT("Unknown image: %x"), m_dwBitmapUNID); return ERR_FAIL; } } return NOERROR; }
ICCItem *CCPrimitive::Execute (CEvalContext *pCtx, ICCItem *pArgs) // Execute // // Executes the function and returns a result { bool bCustomArgEval = ((m_dwFlags & PPFLAG_CUSTOM_ARG_EVAL) ? true : false); // Evaluate args, if necessary ICCItem *pEvalArgs; if (!bCustomArgEval) { pEvalArgs = pCtx->pCC->EvaluateArgs(pCtx, pArgs, m_sArgPattern); if (pEvalArgs->IsError()) return pEvalArgs; } else pEvalArgs = pArgs; // Invoke the function ICCItem *pResult; bool bReportError = false; try { pResult = m_pfFunction(pCtx, pEvalArgs, m_dwData); } catch (...) { bReportError = true; } // Report error if (bReportError) { CString sArgs; try { sArgs = pEvalArgs->Print(pCtx->pCC); } catch (...) { sArgs = CONSTLIT("[invalid arg item]"); } CString sError = strPatternSubst(CONSTLIT("Exception in %s; arg = %s"), m_sName, sArgs); pResult = pCtx->pCC->CreateError(sError, pEvalArgs); kernelDebugLogMessage(sError.GetASCIIZPointer()); } // Done if (!bCustomArgEval) pEvalArgs->Discard(pCtx->pCC); return pResult; }
void CGameSession::PaintSoundtrackTitles (CG32bitImage &Dest) // PaintSoundtrackTitles // // Paints the info about the currently playing soundtrack. { int iPos; CMusicResource *pTrack = m_Soundtrack.GetCurrentTrack(&iPos); if (pTrack == NULL) return; int iSegment = pTrack->FindSegment(iPos); // Time int iMilliseconds = iPos % 1000; int iSeconds = (iPos / 1000) % 60; int iMinutes = (iPos / 60000); // Add all the components TArray<CString> Desc; Desc.InsertEmpty(3); Desc[0] = pTrack->GetPerformedBy(); Desc[1] = pTrack->GetFilename(); Desc[2] = strPatternSubst(CONSTLIT("Segment %d of %d [%02d:%02d.%03d]"), iSegment + 1, pTrack->GetSegmentCount(), iMinutes, iSeconds, iMilliseconds); // Paint PaintInfoText(Dest, pTrack->GetTitle(), Desc, true); }