ALERROR WriteResource (const CString &sFilename, const CString &sFolder, CSymbolTable &Resources, CDataFile &Out) { ALERROR error; CString sFilespec = pathAddComponent(sFolder, sFilename); CFileReadBlock theFile(sFilespec); if (error = theFile.Open()) { printf("Unable to open '%s'\n", sFilespec.GetASCIIZPointer()); return error; } CString sData(theFile.GetPointer(0, -1), theFile.GetLength(), TRUE); int iEntry; if (error = Out.AddEntry(sData, &iEntry)) { printf("Unable to store '%s'\n", sFilespec.GetASCIIZPointer()); return error; } Resources.AddEntry(sFilespec, (CObject *)iEntry); printf(" %s\n", sFilespec.GetASCIIZPointer()); return NOERROR; }
ALERROR LoadTotalCount (const CString &sFilename, CSymbolTable &TotalCount) { ALERROR error; CFileReadBlock Input(sFilename); if (error = Input.Open()) { printf("ERROR: Unable to open total count file. Use /generateSimTables."); return error; } char *pPos = Input.GetPointer(0, -1); char *pEndPos = pPos + Input.GetLength(); while (pPos < pEndPos) { // Read an UNID DWORD dwUNID = (DWORD)strParseInt(pPos, 0, &pPos); if (dwUNID == 0) break; // Read an count if (pPos >= pEndPos) { printf("ERROR: Unexpected end of file."); return ERR_FAIL; } int iCount = strParseInt(pPos, 0, &pPos); // Add the entry CString sKey = strFromInt(dwUNID, false); EntryInfo *pEntry = new EntryInfo; pEntry->dwUNID = dwUNID; pEntry->rTotalCount = (double)iCount / 1000.0; if (error = TotalCount.AddEntry(sKey, pEntry)) { printf("ERROR: Invalid UNID."); return error; } } return NOERROR; }
void CUIHelper::PaintReferenceDamageAdj (CG16bitImage &Dest, int x, int y, int iLevel, int iHP, const int *iDamageAdj) const // PaintReferenceDamageAdj // // Takes an array of damage type adj values and displays them { int i; bool bSortByDamageType = true; bool bOptionShowDamageAdjAsHP = false; const CVisualPalette &VI = m_HI.GetVisuals(); const CG16bitFont &Small = VI.GetFont(fontSmall); const CG16bitFont &Medium = VI.GetFont(fontMedium); WORD wColorRef = VI.GetColor(colorTextHighlight); // Must have positive HP if (iHP == 0) return; // Sort damage types from highest to lowest CSymbolTable Sorted; int iLengthEstimate = 0; int iImmuneCount = 0; for (i = 0; i < damageCount; i++) { // Skip if this damage type is not appropriate to our level int iDamageLevel = GetDamageTypeLevel((DamageTypes)i); if (iDamageLevel < iLevel - 5 || iDamageLevel > iLevel + 3) continue; // Skip if the damage adj is 100% if (iDamageAdj[i] == iHP) continue; // Figure out the sort order CString sKey; if (bSortByDamageType) sKey = strPatternSubst(CONSTLIT("%02d"), i); else { DWORD dwHighToLow = (iDamageAdj[i] == -1 ? 0 : 1000000 - iDamageAdj[i]); sKey = strPatternSubst(CONSTLIT("%08x %02d"), dwHighToLow, i); } // Add to list DWORD dwValue = MAKELONG((WORD)i, (WORD)(short)iDamageAdj[i]); Sorted.AddEntry(sKey, (CObject *)dwValue); // Estimate how many entries we will have (so we can decide the font size) // We assume that immune entries get collapsed. if (iDamageAdj[i] != -1) iLengthEstimate++; else iImmuneCount++; } // If we have six or more icons, then we need to paint smaller iLengthEstimate += Min(2, iImmuneCount); const CG16bitFont &TheFont = (iLengthEstimate >= 6 ? Small : Medium); int cyOffset = (Medium.GetHeight() - TheFont.GetHeight()) / 2; // Paint the icons for (i = 0; i < Sorted.GetCount(); i++) { DWORD dwValue = (DWORD)Sorted.GetValue(i); int iDamageType = LOWORD(dwValue); int iDamageAdj = (int)(short)HIWORD(dwValue); int iPercentAdj = (100 * (iDamageAdj - iHP) / iHP); // Prettify the % by rounding to a number divisible by 5 int iPrettyPercent = 5 * ((iPercentAdj + 2 * Sign(iPercentAdj)) / 5); // Skip if prettify results in 0% if (bOptionShowDamageAdjAsHP && iPrettyPercent == 0) continue; // Draw icon g_pHI->GetVisuals().DrawDamageTypeIcon(Dest, x, y, (DamageTypes)iDamageType); x += DAMAGE_TYPE_ICON_WIDTH + DAMAGE_ADJ_ICON_SPACING_X; // If we have a bunch of entries with "immune", then compress them if (i < (Sorted.GetCount() - 1) && iDamageAdj == -1 && (iDamageAdj == (int)(short)HIWORD((DWORD)Sorted.GetValue(i + 1)))) continue; // Figure out how to display damage adj CString sStat; if (iDamageAdj == -1) sStat = CONSTLIT("immune"); else if (bOptionShowDamageAdjAsHP) sStat = strFromInt(iDamageAdj); else sStat = strPatternSubst(CONSTLIT("%s%d%%"), (iPrettyPercent > 0 ? CONSTLIT("+") : NULL_STR), iPrettyPercent); // Draw Dest.DrawText(x, y + cyOffset, TheFont, wColorRef, sStat, 0, &x); x += DAMAGE_ADJ_SPACING_X; } }
ALERROR WriteModule (const CString &sFilename, const CString &sFolder, CExternalEntityTable *pEntityTable, CSymbolTable &Resources, CDataFile &Out, int *retiModuleEntry) { ALERROR error; int i; // Parse the file CXMLElement *pModule; CExternalEntityTable EntityTable; if (pEntityTable) { CFileReadBlock DataFile(sFilename); CString sError; printf("Parsing %s...", sFilename.GetASCIIZPointer()); if (error = CXMLElement::ParseXML(&DataFile, pEntityTable, &pModule, &sError)) { printf("\n%s\n", sError.GetASCIIZPointer()); return error; } printf("done.\n"); } else { CFileReadBlock DataFile(sFilename); CString sError; printf("Parsing %s...", sFilename.GetASCIIZPointer()); if (error = CXMLElement::ParseXML(&DataFile, &pModule, &sError, &EntityTable)) { printf("\n%s\n", sError.GetASCIIZPointer()); return error; } pEntityTable = &EntityTable; printf("done.\n"); } // Write the module itself int iEntry; if (error = WriteGameFile(sFilename, Out, &iEntry)) return error; // If the caller doesn't want the module entry, then it means that this is // a module (instead of the main file). If so, add it to the resources table if (retiModuleEntry == NULL) Resources.AddEntry(sFilename, (CObject *)iEntry); // Store all the image resources if (error = WriteModuleImages(pModule, sFolder, Resources, Out)) return error; // Store all the sound resources if (error = WriteModuleSounds(pModule, sFolder, Resources, Out)) return error; // Store all modules CXMLElement *pModules = pModule->GetContentElementByTag(TAG_MODULES); if (pModules) { for (i = 0; i < pModules->GetContentElementCount(); i++) { CXMLElement *pItem = pModules->GetContentElement(i); CString sFilename = pItem->GetAttribute(ATTRIB_FILENAME); if (error = WriteModule(sFilename, sFolder, pEntityTable, Resources, Out, NULL)) continue; } } // Done if (retiModuleEntry) *retiModuleEntry = iEntry; return NOERROR; }