本文整理汇总了C++中CItemType::GetDataField方法的典型用法代码示例。如果您正苦于以下问题:C++ CItemType::GetDataField方法的具体用法?C++ CItemType::GetDataField怎么用?C++ CItemType::GetDataField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CItemType
的用法示例。
在下文中一共展示了CItemType::GetDataField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenerateShieldStats
void GenerateShieldStats (CUniverse &Universe, CXMLElement *pCmdLine)
{
int i;
CString sUNID = pCmdLine->GetAttribute(CONSTLIT("unid"));
DWORD dwUNID = strToInt(sUNID, 0, NULL);
CItemType *pItem = Universe.FindItemType(dwUNID);
if (pItem == NULL)
{
CItemCriteria Crit;
CItem::InitCriteriaAll(&Crit);
CItem Item = CItem::CreateItemByName(sUNID, Crit);
pItem = Item.GetType();
if (pItem == NULL)
{
printf("ERROR: Unknown item '%s'\n", sUNID.GetASCIIZPointer());
return;
}
}
if (pItem->GetCategory() != itemcatShields)
{
printf("ERROR: Item '%s' is not a shield generator\n", pItem->GetNounPhrase().GetASCIIZPointer());
return;
}
bool bVerbose = pCmdLine->GetAttributeBool(CONSTLIT("verbose"));
bool bEval = pCmdLine->GetAttributeBool(CONSTLIT("eval"));
// Get the stats for the shield
Metric rHP = (Metric)pItem->GetDataFieldInteger(FIELD_HP);
Metric rHPRegenPerTick = pItem->GetDataFieldInteger(FIELD_REGEN) / 1000.0;
int iDamageAdj[damageCount];
CString sDamageAdj = pItem->GetDataField(CONSTLIT("damageAdj"));
char *pPos = sDamageAdj.GetASCIIZPointer();
int iCount = 0;
while (iCount < damageCount)
{
iDamageAdj[iCount] = strParseInt(pPos, 0, &pPos, NULL);
if (*pPos != '\0')
pPos++;
iCount++;
}
// Print header
printf("%s\n\n", pItem->GetNounPhrase().GetASCIIZPointer());
// Loop over all weapons and sort them by level and then name
CSymbolTable List(FALSE, TRUE);
for (i = 0; i < Universe.GetItemTypeCount(); i++)
{
CItemType *pWeapon = Universe.GetItemType(i);
if (pWeapon->GetCategory() != itemcatWeapon)
continue;
CString sLevel = (pWeapon->GetLevel() < 10 ? strPatternSubst(CONSTLIT("0%d"), pWeapon->GetLevel()) : strFromInt(pWeapon->GetLevel(), FALSE));
CString sSortName = strPatternSubst(CONSTLIT("%s%s"), sLevel, pWeapon->GetNounPhrase());
List.AddEntry(sSortName, (CObject *)pWeapon);
}
// Loop over sorted list and output data
for (i = 0; i < List.GetCount(); i++)
{
CItemType *pWeapon = (CItemType *)List.GetValue(i);
// Get the data for the weapon
int iFireDelay = pWeapon->GetDataFieldInteger(CONSTLIT("fireDelay"));
Metric rAverageDamage = pWeapon->GetDataFieldInteger(CONSTLIT("averageDamage")) / 1000.0;
int iDamageType = pWeapon->GetDataFieldInteger(CONSTLIT("damageType"));
if (iDamageType < 0 || iDamageType >= damageCount)
iDamageType = 0;
// Adjust damage for type
rAverageDamage = rAverageDamage * (iDamageAdj[iDamageType] / 100.0);
if (rAverageDamage < 1.0)
rAverageDamage = 0.0;
// Calculate how many shots it would take to pierce through the shields
char szBuffer[256];
Metric rShotsToDeplete;
Metric rRegenPerShot = rHPRegenPerTick * (Metric)iFireDelay;
if (rRegenPerShot >= rAverageDamage)
{
rShotsToDeplete = 1000000.0;
lstrcpy(szBuffer, "ineffective");
}
else
{
Metric rDrainPerShot = rAverageDamage - rRegenPerShot;
rShotsToDeplete = rHP / rDrainPerShot;
sprintf(szBuffer, "%.2f", rShotsToDeplete);
//.........这里部分代码省略.........
示例2: GenerateItemTable
//.........这里部分代码省略.........
if (Table.GetCount())
{
// Generate a list of columns to display
CStringArray Cols;
Cols.AppendString(FIELD_LEVEL);
Cols.AppendString(FIELD_TYPE);
Cols.AppendString(FIELD_FREQUENCY);
Cols.AppendString(FIELD_NAME);
// More columns from command-line
if (pCmdLine->GetAttributeBool(FIELD_AVERAGE_COUNT))
Cols.AppendString(FIELD_AVERAGE_COUNT);
if (pCmdLine->GetAttributeBool(FIELD_BALANCE))
Cols.AppendString(FIELD_BALANCE);
if (pCmdLine->GetAttributeBool(FIELD_COST))
Cols.AppendString(FIELD_COST);
if (pCmdLine->GetAttributeBool(FIELD_INSTALL_COST))
Cols.AppendString(FIELD_INSTALL_COST);
if (pCmdLine->GetAttributeBool(FIELD_MASS))
Cols.AppendString(FIELD_MASS);
if (pCmdLine->GetAttributeBool(FIELD_TOTAL_COUNT))
Cols.AppendString(FIELD_TOTAL_COUNT);
if (pCmdLine->GetAttributeBool(FIELD_REFERENCE))
Cols.AppendString(FIELD_REFERENCE);
if (pCmdLine->GetAttributeBool(FIELD_HP))
Cols.AppendString(FIELD_HP);
if (pCmdLine->GetAttributeBool(FIELD_HP_BONUS))
Cols.AppendString(FIELD_HP_BONUS);
if (pCmdLine->GetAttributeBool(FIELD_REGEN))
Cols.AppendString(FIELD_REGEN);
if (pCmdLine->GetAttributeBool(FIELD_FIRE_DELAY))
Cols.AppendString(FIELD_FIRE_DELAY);
if (pCmdLine->GetAttributeBool(FIELD_THRUST))
Cols.AppendString(FIELD_THRUST);
if (pCmdLine->GetAttributeBool(FIELD_POWER))
Cols.AppendString(FIELD_POWER);
if (pCmdLine->GetAttributeBool(FIELD_POWER_PER_SHOT))
Cols.AppendString(FIELD_POWER_PER_SHOT);
if (pCmdLine->GetAttributeBool(FIELD_AVERAGE_DAMAGE))
Cols.AppendString(FIELD_AVERAGE_DAMAGE);
if (pCmdLine->GetAttributeBool(FIELD_MAX_SPEED))
Cols.AppendString(FIELD_MAX_SPEED);
// Output the header
for (j = 0; j < Cols.GetCount(); j++)
{
if (j != 0)
printf("\t");
printf(Cols.GetStringValue(j).GetASCIIZPointer());
}
printf("\n");
// Output each row
for (i = 0; i < Table.GetCount(); i++)
{
CItemType *pType = (CItemType *)Table.GetValue(i);
for (j = 0; j < Cols.GetCount(); j++)
{
if (j != 0)
printf("\t");
CString sField = Cols.GetStringValue(j);
CString sValue = pType->GetDataField(sField);
if (strEquals(sField, FIELD_AVERAGE_DAMAGE) || strEquals(sField, FIELD_POWER_PER_SHOT))
printf("%.2f", strToInt(sValue, 0, NULL) / 1000.0);
else if (strEquals(sField, FIELD_POWER))
printf("%.1f", strToInt(sValue, 0, NULL) / 1000.0);
else if (strEquals(sField, FIELD_TOTAL_COUNT))
{
double rCount = 0.0;
CString sKey = strFromInt(pType->GetUNID(), FALSE);
EntryInfo *pEntry;
if (TotalCount.Lookup(sKey, (CObject **)&pEntry) == NOERROR)
rCount = pEntry->rTotalCount;
printf("%.2f", rCount);
}
else
printf(sValue.GetASCIIZPointer());
}
printf("\n");
}
printf("\n");
}
else
printf("No entries match criteria.\n");
}