void CExternalEntityTable::AddTable (CSymbolTable &Table) // AddTable // // Adds all entities in the given table { int i; for (i = 0; i < Table.GetCount(); i++) m_Entities.Insert(Table.GetKey(i), *(CString *)Table.GetValue(i)); }
ALERROR OutputItemTable (CSymbolTable &AllSystems, int iSystemSample) { ALERROR error; int i, j; CSymbolTable AllItems(TRUE, TRUE); for (i = 0; i < AllSystems.GetCount(); i++) { SystemInfo *pSystemEntry = (SystemInfo *)AllSystems.GetValue(i); for (j = 0; j < pSystemEntry->Items.GetCount(); j++) { ItemInfo *pEntry = (ItemInfo *)pSystemEntry->Items.GetValue(j); CString sKey = strFromInt(pEntry->pType->GetUNID(), false); ItemInfo *pDestEntry; if (error = AllItems.Lookup(sKey, (CObject **)&pDestEntry)) { pDestEntry = new ItemInfo; pDestEntry->pType = pEntry->pType; pDestEntry->rTotalCount = ((double)pEntry->iTotalCount / (double)iSystemSample); AllItems.AddEntry(sKey, pDestEntry); } else pDestEntry->rTotalCount += ((double)pEntry->iTotalCount / (double)iSystemSample); } } // Output all items to a well-known file CTextFileLog Output(ITEM_COUNT_FILENAME); if (error = Output.Create(FALSE)) { printf("ERROR: Unable to create output file: %s\n", ITEM_COUNT_FILENAME.GetASCIIZPointer()); return error; } for (i = 0; i < AllItems.GetCount(); i++) { ItemInfo *pEntry = (ItemInfo *)AllItems.GetValue(i); Output.LogOutput(0, "0x%x\t%d", pEntry->pType->GetUNID(), (int)((pEntry->rTotalCount * 1000) + 0.5)); } if (error = Output.Close()) { printf("ERROR: Unable to create output file: %s\n", ITEM_COUNT_FILENAME.GetASCIIZPointer()); return error; } return NOERROR; }
/******************************************************************************* Function Name : OnAdd Input(s) : - Output : - Functionality : This will take selected element from first two list and add it to the third one.The element selected from the second list will be added to acAltKey array at the place where the first list element is stored in acUnSptdKey array. Member of : - Friend of : - Author(s) : Amit Ranjan Date Created : 23.04.2004 Modifications : *******************************************************************************/ void CEnvVarHandlerDlg::OnAdd() { int m = 0; CString uns,alt,uns1; m = m_UnSupKeys.GetCurSel(); m_UnSupKeys.GetText( m,uns );//store selected element from first list m_UnSupKeys.GetText( m,uns1 ); m_UnSupKeys.DeleteString( m );//delete it m = m_AltKeys.GetCurSel(); m_AltKeys.GetText( m,alt );//store selected element from second list m_AltKeys.DeleteString( m ); uns = uns+" ---> "; uns = uns + alt; m_EquiKeys.AddString( uns );//add both to third list acAltKey[ouUnSptdKey.nFind(uns1)] = alt[0];//add the key to acAltKeylist m_UnSupKeys.SetCurSel(0);//set first item selected m_AltKeys.SetCurSel(0); m_EquiKeys.SetCurSel(0); if(m_UnSupKeys.GetCount() == 0 || m_AltKeys.GetCount() == 0 ) { GetDlgItem( IDC_CBTN_ADD )->EnableWindow(FALSE); } else { GetDlgItem( IDC_CBTN_ADD )->EnableWindow(TRUE); } GetDlgItem( IDC_CBTN_RMV )->EnableWindow(TRUE); }
/******************************************************************************* Function Name : OnRemove Input(s) : - Output : - Functionality : This will will remove the selected item from the third list and will put the first element in the first list and second element in the second list. Member of : - Friend of : - Author(s) : Amit Ranjan Date Created : 23.04.2004 Modifications : *******************************************************************************/ void CEnvVarHandlerDlg::OnRemove() { CString ekey; if((m = m_EquiKeys.GetCurSel()) != LB_ERR) { GetDlgItem( IDC_CBTN_ADD )->EnableWindow(TRUE); m_EquiKeys.GetText( m,ekey ); int k = ekey.Find(' ',0); if( k != -1) { m_UnSupKeys.AddString(ekey.Left(k)); m_AltKeys.AddString(ekey.Right(1)); } acAltKey [ ouUnSptdKey.nFind( ekey.Left( k)) ] = -1; m_EquiKeys.DeleteString(m); m_UnSupKeys.SetCurSel(0); m_AltKeys.SetCurSel(0); m_EquiKeys.SetCurSel(0); } if(m_EquiKeys.GetCount()==0) { GetDlgItem(IDC_CBTN_RMV)->EnableWindow(FALSE); } }
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; }
int GetSymbolicAttribute (CSymbolTable &Symbols, CXMLElement *pElement, const CString &sAttribute) { CString sValue = pElement->GetAttribute(sAttribute); int iValue; if (Symbols.Lookup(sValue, (CObject **)&iValue) == NOERROR) return iValue; else return strToInt(sValue, 0, NULL); }
/******************************************************************************* Function Name : OnTerminate Input(s) : - Output : - Functionality : This will take first item from list one and first item from list two to make the default selection of available keys for the unsupported keys.This will write the user intervention for the alternate keys in the log file also. Member of : - Friend of : - Author(s) : Amit Ranjan Date Created : 27.04.2004 Modifications : *******************************************************************************/ void CEnvVarHandlerDlg::OnTerminate() { CString buffer; CString uns,alt,uns1; if(m_UnSupKeys.GetCount()>0) { if ( m_AltKeys.GetCount() > 0 ) { MessageBox(defSTR_Warning6,MB_OK); } while(m_UnSupKeys.GetCount()!=0) { if(m_AltKeys.GetCount()>0) { m_UnSupKeys.GetText(0,uns); m_UnSupKeys.GetText(0,uns1); m_UnSupKeys.DeleteString(0); m_AltKeys.GetText(0,alt); m_AltKeys.DeleteString(0); uns = uns+" ---> "; uns = uns + alt; m_EquiKeys.AddString(uns); acAltKey[ ouUnSptdKey.nFind(uns1) ] = alt[0]; } else { m_UnSupKeys.DeleteString(0); } } } /*if( m_EquiKeys.GetCount() > 0 ) { fprintf(pFileLog,"---***********************************---"); fprintf(pFileLog,"\n---*****CEnvVarHandlerDlg Of User Intervention*****---"); fprintf(pFileLog,"\n---***********************************---"); fprintf(pFileLog,"\n Unsupported Key -->Equivalent Key"); fprintf(pFileLog,"\n --------------- ---------------\n"); } for(int m = 0; m <= m_EquiKeys.GetCount()-1; m++ ) { m_EquiKeys.GetText( m,buffer ); fprintf(pFileLog,"\t%s\n",buffer); }*/ m_UnSupKeys.ResetContent(); m_EquiKeys.ResetContent(); m_AltKeys.ResetContent(); CEnvVarHandlerDlg::OnOK(); }
void ArrangeByCell (CSymbolTable &Table, int cxDesiredWidth, CPaintMap &Map) { int i; // Compute the size of each image cell int cxCell = 32; int cyCell = 32; // Compute the number of rows & columns int iInitCols = (cxDesiredWidth / cxCell) + ((cxDesiredWidth % cxCell) ? 1 : 0); int iInitRows = AlignUp(20 * Table.GetCount(), iInitCols) / iInitCols; // Create an array that keeps track of which cells we've used up CCellMap CellMap(iInitCols, iInitRows); // Figure out where to place all the ships for (i = 0; i < Table.GetCount(); i++) { CShipClass *pClass = (CShipClass *)Table.GetValue(i); // Figure out how many cells we need int cxSize = RectWidth(pClass->GetImage().GetImageRect()); int iCellsNeeded = AlignUp(cxSize, cxCell) / cxCell; int cxAreaSize = iCellsNeeded * cxCell; // Position the ship int x, y; if (CellMap.GetSpace(iCellsNeeded, &x, &y)) Map.Place(i, x * cxCell + (cxAreaSize - cxSize) / 2, y * cyCell + (cxAreaSize - cxSize) / 2, cxSize, cxSize); } }
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; }
CSymbolTable* CSymbolTable::Create() { CSymbolTable* retval = new CSymbolTable(); retval->Init(); return retval; }
/******************************************************************************* Function Name : OnInitDialog Input(s) : - Output : - Functionality : This will populate the first list box with unsupported keys and environment handlers and the second list box with available keys. Member of : - Friend of : - Author(s) : Amit Ranjan Date Created : 22.04.2004 Modifications : *******************************************************************************/ BOOL CEnvVarHandlerDlg::OnInitDialog() { try { int Flag = 0; int m = 0; char allkey[]= {'a','b','c','d','e','f','g','h','i','j','k','l','m','n', 'o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E', 'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V', 'W','X','Y','Z','0','1','2','3','4','5','6','7','8','9',0 }; CDialog::OnInitDialog(); for(m = 0; m < ouUnSptdKey.nGetSize(); m++) { m_UnSupKeys.AddString( ouUnSptdKey.omGetAt(m) ); } for( m = 0; m < defINT_SizeofacAltKeyArray ; m++ ) { Flag = 0; for( int p = 0; p <= cIndex2-1; p++) { if(allkey[m] == acSptdKey[p]) { Flag = 1; break; } } if( Flag == 0) { m_AltKeys.AddString( CString( allkey[m] ) ); } } m_UnSupKeys.SetCurSel(0); m_AltKeys.SetCurSel(0); if( m_AltKeys.GetCount() == 0) { //if no key is available GetDlgItem( IDC_CBTN_ADD )->EnableWindow(FALSE); ShowWindow(SW_SHOW); MessageBox("No Key is avilable",NULL,MB_OK); } } catch(...) { CString cs; cs.Format(ExceptionFormat,"\"OnInitDialog\"",__FILE__,__LINE__); MessageBox(cs); exit(0); } return TRUE; }
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; } }
void ArrangeByRow (CSymbolTable &Table, SArrangeDesc &Desc, CPaintMap &Map) { int iNext = 0; int y = 0; int cyHeader = Desc.pHeader->GetHeight(); int cxInternalSpacing = 8; int cyInternalSpacing = 2 * Desc.pHeader->GetHeight(); int cyNameSpacing = Desc.pHeader->GetHeight() / 2; while (iNext < Table.GetCount()) { int i; int cxWidthLeft = Desc.cxDesiredWidth; int cyRowHeight = 0; int iStart = iNext; // First figure out how many ships will fit while (iNext < Table.GetCount()) { CShipClass *pClass = (CShipClass *)Table.GetValue(iNext); int cxSize = RectWidth(pClass->GetImage().GetImageRect()); if (cxSize > cxWidthLeft && iStart != iNext) break; int cxCell = Max(cxSize + cxInternalSpacing, Desc.cxSpacing); cxWidthLeft -= cxCell; if (cxSize > cyRowHeight) cyRowHeight = cxSize; iNext++; } // Compute the total width int cxRowWidth = Min(Desc.cxDesiredWidth - cxWidthLeft, Desc.cxDesiredWidth); int xOffset = (Desc.cxDesiredWidth - cxRowWidth) / 2; // See if any of the ships overlap the text from the previous ships // If so, we increase y a little bit int x = Desc.cxSpacing + Desc.cxExtraMargin; for (i = iStart; i < iNext; i++) { CShipClass *pClass = (CShipClass *)Table.GetValue(i); int cxSize = RectWidth(pClass->GetImage().GetImageRect()); int yOffset = (cyRowHeight - cxSize) / 2; int xPoint = x + xOffset + cxSize / 2; int yPoint = y + yOffset; for (int j = 0; j < iStart; j++) { int xText = Map.GetTextX(j); int yText = Map.GetTextY(j); int cxText = Map.GetTextWidth(j); int cyText = Map.GetTextHeight(j) + cyInternalSpacing; if (xPoint >= xText && xPoint < xText + cxText && yPoint < yText + cyText) y = yText + cyText + cyInternalSpacing; } int cxCell = Max(cxSize + cxInternalSpacing, Desc.cxSpacing); x += cxCell; } // Place the ships x = Desc.cxSpacing + Desc.cxExtraMargin; int yOverlapOffset = 0; for (i = iStart; i < iNext; i++) { CShipClass *pClass = (CShipClass *)Table.GetValue(i); int cxSize = RectWidth(pClass->GetImage().GetImageRect()); int cxCell = Max(cxSize + cxInternalSpacing, Desc.cxSpacing); // Center vertically int yOffset = (cyRowHeight - cxSize) / 2; // Place Map.Place(i, x + xOffset, y + yOffset, cxSize, cxSize); // Figure out the position of the text int cyName; int cxName = Desc.pHeader->MeasureText(pClass->GetNounPhrase(0), &cyName); if (cxName <= cxSize) { int yText = y + yOffset + cxSize + cyNameSpacing; Map.PlaceText(i, x + xOffset + (cxSize - cxName) / 2, yText, cxName, cyName); yOverlapOffset = yText + cyName + cyNameSpacing; } else { // See if the name fits above the previous name int yText; if (yOverlapOffset > 0 && i > iStart && (x + xOffset + cxSize - (Map.GetX(i - 1) + Map.GetWidth(i - 1) / 2)) > cxName + 8) { yText = y + yOffset + cxSize + cyNameSpacing; if (yText < Map.GetY(i - 1) + Map.GetHeight(i - 1)) yText = Map.GetY(i - 1) + Map.GetHeight(i - 1) + cyNameSpacing; if (yText > Map.GetTextY(i - 1) - (cyName + cyNameSpacing)) yText = yOverlapOffset; } // Otherwise, use the overlap, if it exits else if (yOverlapOffset == 0) yText = y + yOffset + cxSize + cyNameSpacing; else yText = yOverlapOffset; Map.PlaceText(i, x + xOffset + cxSize - cxName, yText, cxName, cyName); yOverlapOffset = yText + cyName + cyNameSpacing; } x += cxCell; } y += cyRowHeight; } // Add a margin to the right and bottom Map.AddMargin(Desc.cxSpacing + Desc.cxExtraMargin, cyInternalSpacing); }
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; }