本文整理汇总了C++中idDict::FindKeyIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ idDict::FindKeyIndex方法的具体用法?C++ idDict::FindKeyIndex怎么用?C++ idDict::FindKeyIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类idDict
的用法示例。
在下文中一共展示了idDict::FindKeyIndex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetFromArgs
bool CRelations::SetFromArgs(const idDict& args)
{
idList<SEntryData> entries;
idList<int> addedDiags;
for (const idKeyValue* kv = args.MatchPrefix("rel ", NULL ); kv != NULL; kv = args.MatchPrefix("rel ", kv))
{
try
{
// Try to parse the entry, this will throw on errors
SEntryData entry = ParseEntryData(kv);
// Successfully parsed, add to list
entries.Append(entry);
// Will the current matrix dimension be increased by this entry?
if (entry.row < m_RelMat.Dim() && entry.col < m_RelMat.Dim())
{
// No, matrix will not be extended, no need to check for
// diagonals and asymmetric values
continue;
}
// The matrix will be extended by this entry, let's check for diagonals
// Check for diagonal element of the ROW team
if (args.FindKeyIndex( va("rel %d,%d", entry.row, entry.row) ) == -1 &&
addedDiags.FindIndex(entry.row) == -1)
{
// ROW team diagonal not set, fill with default team relation entry
SEntryData defaultDiagonal(entry.row, entry.row, s_DefaultSameTeamRel);
entries.Append(defaultDiagonal);
// Remember the diagonal number, so that we don't add it a second time
addedDiags.Append(entry.row);
DM_LOG(LC_AI, LT_DEBUG)LOGSTRING("Relmat Parser: Added missing diagonal %d, %d\r", entry.row, entry.row);
}
// Check for diagonal element of the COLUMN team
if (args.FindKeyIndex( va("rel %d,%d", entry.col, entry.col) ) == -1 &&
addedDiags.FindIndex(entry.col) == -1)
{
// COLUMN team diagonal not set, fill with default team relation entry
SEntryData defaultDiagonal(entry.col, entry.col, s_DefaultSameTeamRel);
entries.Append(defaultDiagonal);
// Remember the diagonal number, so that we don't add it a second time
addedDiags.Append(entry.col);
DM_LOG(LC_AI, LT_DEBUG)LOGSTRING("Relmat Parser: Added missing diagonal %d, %d\r", entry.col, entry.col);
}
// Check for asymmetric element and append one with same value if
// it is not set on this dictionary
if (args.FindKeyIndex( va("rel %d,%d", entry.col, entry.row) ) == -1)
{
// Pass col as first arg, row as second to define the asymmetric value
SEntryData asymmRel(entry.col, entry.row, entry.val);
entries.Append(asymmRel);
DM_LOG(LC_AI, LT_DEBUG)LOGSTRING("Relmat Parser: Added missing asymmetric element %d, %d\r", entry.row, entry.col );
}
}
catch (std::runtime_error e)
{
gameLocal.Warning("Parse error: %s", e.what());
}
}
// Commit the found values to the relations matrix
for (int i = 0; i < entries.Num(); ++i)
{
const SEntryData& entry = entries[i];
// Use the SetRel() method, which automatically takes care of initialising new teams
SetRel(entry.row, entry.col, entry.val);
}
return true;
}