本文整理汇总了C++中CItemType::GetSortName方法的典型用法代码示例。如果您正苦于以下问题:C++ CItemType::GetSortName方法的具体用法?C++ CItemType::GetSortName怎么用?C++ CItemType::GetSortName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CItemType
的用法示例。
在下文中一共展示了CItemType::GetSortName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenerateRandomItemTables
void GenerateRandomItemTables (CUniverse &Universe, CXMLElement *pCmdLine)
{
int i;
printf("RANDOM ITEM TABLES\n\n");
// Create a sorted list of item types
CSymbolTable SortedList(FALSE, TRUE);
for (i = 0; i < Universe.GetItemTypeCount(); i++)
{
CItemType *pType = Universe.GetItemType(i);
SortedList.AddEntry(pType->GetSortName(), (CObject *)pType);
}
// Create the tables
for (int iLevel = 1; iLevel <= MAX_ITEM_LEVEL; iLevel += 2)
{
for (TableTypes iTable = tableTypesFirst; iTable <= tableTypesCount; iTable = (enum TableTypes)((int)iTable + 1))
{
int iCount = 0;
ItemEntry Table[100];
// Fill the table with entries for each
// item at this level
for (i = 0; i < SortedList.GetCount(); i++)
{
CItemType *pType = (CItemType *)SortedList.GetValue(i);
int iScore;
if (iCount < 100 && ItemInTable(pType, iTable, iLevel, &iScore))
{
Table[iCount].pType = pType;
Table[iCount].iScore = iScore;
iCount++;
}
}
// Compute total score
int iTotalScore = 0;
for (i = 0; i < iCount; i++)
iTotalScore += Table[i].iScore;
// Compute chance
for (i = 0; i < iCount; i++)
{
Table[i].iChance = (Table[i].iScore * 100) / iTotalScore;
Table[i].iRemainder = (Table[i].iScore * 100) % iTotalScore;
}
// Compute remainder
int iTotalChance = 0;
for (i = 0; i < iCount; i++)
iTotalChance += Table[i].iChance;
while (iTotalChance < 100)
{
int iBestRemainder = 0;
int iBestEntry = -1;
for (i = 0; i < iCount; i++)
if (Table[i].iRemainder > iBestRemainder)
{
iBestRemainder = Table[i].iRemainder;
iBestEntry = i;
}
Table[iBestEntry].iChance++;
Table[iBestEntry].iRemainder = 0;
iTotalChance++;
}
// Title
if (iCount > 0)
{
switch (iTable)
{
case tableArmorAndWeapons:
printf("LEVEL %d: ARMOR AND WEAPONS\n\n", iLevel);
break;
case tableMiscItems:
printf("LEVEL %d: MISCELLANEOUS ITEMS\n\n", iLevel);
break;
case tableUsefulItems:
printf("LEVEL %d: USEFUL ITEMS\n\n", iLevel);
break;
}
// Print table
for (i = 0; i < iCount; i++)
if (Table[i].iChance > 0)
{
//DWORD dwFlags;
//.........这里部分代码省略.........
示例2: SortItems
void CItemList::SortItems (void)
// SortItems
//
// Sorts items in order:
//
// installed/not-installed
// armor/weapon/device/other
{
if (GetCount() == 0)
return;
int i;
CSymbolTable Sort(false, true);
for (i = 0; i < GetCount(); i++)
{
CItem &Item = GetItem(i);
CItemType *pType = Item.GetType();
// All installed items first
CString sInstalled;
if (Item.IsInstalled())
sInstalled = CONSTLIT("0");
else
sInstalled = CONSTLIT("1");
// Next, sort on category
CString sCat;
switch (pType->GetCategory())
{
case itemcatWeapon:
case itemcatLauncher:
sCat = CONSTLIT("0");
break;
case itemcatMissile:
sCat = CONSTLIT("1");
break;
case itemcatShields:
sCat = CONSTLIT("2");
break;
case itemcatReactor:
sCat = CONSTLIT("3");
break;
case itemcatDrive:
sCat = CONSTLIT("4");
break;
case itemcatCargoHold:
sCat = CONSTLIT("5");
break;
case itemcatMiscDevice:
sCat = CONSTLIT("6");
break;
case itemcatArmor:
sCat = CONSTLIT("7");
break;
case itemcatFuel:
case itemcatUseful:
sCat = CONSTLIT("8");
break;
default:
sCat = CONSTLIT("9");
}
// Next, sort by install location
if (Item.IsInstalled())
sCat.Append(strPatternSubst(CONSTLIT("%03d%08x"), Item.GetInstalled(), Item.GetType()->GetUNID()));
else
sCat.Append(CONSTLIT("99900000000"));
// Within category, sort by level (highest first)
sCat.Append(strPatternSubst(CONSTLIT("%02d"), MAX_ITEM_LEVEL - Item.GetType()->GetApparentLevel()));
// Enhanced items before others
if (Item.IsEnhanced())
sCat.Append(CONSTLIT("0"));
else if (Item.IsDamaged())
sCat.Append(CONSTLIT("2"));
else
sCat.Append(CONSTLIT("1"));
CString sName = pType->GetSortName();
CString sSort = strPatternSubst(CONSTLIT("%s%s%s%d"), sInstalled, sCat, sName, (i * (int)this) % 0x10000);
Sort.AddEntry(sSort, (CObject *)i);
}
//.........这里部分代码省略.........