本文整理汇总了C++中idDict::MatchPrefix方法的典型用法代码示例。如果您正苦于以下问题:C++ idDict::MatchPrefix方法的具体用法?C++ idDict::MatchPrefix怎么用?C++ idDict::MatchPrefix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类idDict
的用法示例。
在下文中一共展示了idDict::MatchPrefix方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadState
/*
================
idAF::LoadState
================
*/
void idAF::LoadState( const idDict &args )
{
const idKeyValue *kv;
idStr name;
idAFBody *body;
idVec3 origin;
idAngles angles;
kv = args.MatchPrefix( "body ", NULL );
while( kv )
{
name = kv->GetKey();
name.Strip( "body " );
body = physicsObj.GetBody( name );
if( body )
{
sscanf( kv->GetValue(), "%f %f %f %f %f %f", &origin.x, &origin.y, &origin.z, &angles.pitch, &angles.yaw, &angles.roll );
body->SetWorldOrigin( origin );
body->SetWorldAxis( angles.ToMat3() );
}
else
{
gameLocal.DWarning( "Unknown body part %s in articulated figure %s", name.c_str(), this->name.c_str() );
}
kv = args.MatchPrefix( "body ", kv );
}
physicsObj.UpdateClipModels();
}
示例2: StripReactionPrefix
//
// stripReactionPrefix()
//
void hhReactionHandler::StripReactionPrefix(idDict &dict) {
const idKeyValue *kv = NULL;//dict.MatchPrefix("reaction");
idDict newDict;
for(int i=0;i<dict.GetNumKeyVals();i++) {
kv = dict.GetKeyVal(i);
idStr key;
key = kv->GetKey();
// Do we have a reaction token to strip out?
if(idStr::FindText(key.c_str(), "reaction") != -1) {
int endPrefix = idStr::FindChar(key.c_str(), '_');
if(endPrefix == -1) {
gameLocal.Error("reactionX_ prefix not found.");
}
idStr realKey(key);
realKey = key.Mid(endPrefix+1, key.Length() - endPrefix - 1);
key = realKey;
}
//dict.Delete(kv->GetKey().c_str());
newDict.Set(key.c_str(), kv->GetValue());
kv = dict.MatchPrefix("reaction", kv);
}
dict.Clear();
dict.Copy(newDict);
}
示例3: LoadData
/*
================
sdVehiclePosition::LoadData
================
*/
void sdVehiclePosition::LoadData( const idDict& dict ) {
requirements.Load( dict, "require" );
const char* tipName = dict.GetString( "tt_blocked" );
if ( *tipName ) {
blockedTip = gameLocal.declToolTipType[ tipName ];
}
maxViewOffset = dict.GetFloat( "max_view_offset", "0.f" );
viewOffsetRate = dict.GetFloat( "view_offset_rate", "0.f" );
if ( maxViewOffset ) {
viewOffsetRate /= maxViewOffset;
}
const char* attachJointName = dict.GetString( "joint_attach" );
if ( !*attachJointName ) {
attachJointName = "origin";
}
attachAnim = dict.GetString( "player_anim", "VehicleDefault" );
showPlayer = dict.GetBool( "show_player" );
minZfrac = dict.GetFloat( "min_z_frac", "-2.f" );
ejectOnKilled = dict.GetBool( "use_fallback" );
takesDamage = dict.GetBool( "take_damage" );
playerHeight = dict.GetFloat( "player_height" );
allowWeapon = dict.GetBool( "allow_weapon" );
allowAdjustBodyAngles = dict.GetBool( "adjust_body_angles" );
resetViewOnEnter = dict.GetBool( "reset_view_on_enter", "1" );
damageScale = dict.GetFloat( "damage_scale", "1" );
playerStance = dict.GetBool( "player_stance_crouch" ) ? PS_CROUCH : PS_NORMAL;
const char* iconJointName = dict.GetString( "joint_icon" );
if ( *iconJointName != '\0' ) {
iconJoint = transport->GetAnimator()->GetJointHandle( iconJointName );
} else {
iconJoint = INVALID_JOINT;
}
const idKeyValue* kv = NULL;
while ( kv = dict.MatchPrefix( "ability", kv ) ) {
abilities.Add( kv->GetValue() );
}
attachJoint = transport->GetAnimator()->GetJointHandle( attachJointName );
if ( attachJoint == INVALID_JOINT ) {
gameLocal.Warning( "sdVehiclePosition::LoadData Joint \"%s\" does not exist in vscript %s", attachJointName, transport->GetVehicleScript()->GetName() );
}
cockpitName = dict.GetString( "cockpit", "" );
const char* statName = dict.GetString( "stat_name" );
if ( *statName ) {
sdStatsTracker& tracker = sdGlobalStatsTracker::GetInstance();
statTimeSpent = tracker.GetStat( tracker.AllocStat( va( "%s_time_spent", statName ), sdNetStatKeyValue::SVT_INT ) );
} else {
gameLocal.Warning( "Missing Stat Name on '%s'", name.c_str() );
}
}
示例4: CacheFromDict
/*
================
sdDeclDamage::CacheFromDict
================
*/
void sdDeclDamage::CacheFromDict( const idDict& dict ) {
const idKeyValue *kv;
kv = NULL;
while( kv = dict.MatchPrefix( "dmg_", kv ) ) {
if ( kv->GetValue().Length() ) {
gameLocal.declDamageType[ kv->GetValue() ];
}
}
}
示例5: idStr
// Static parsing function
idList<Setting> Setting::ParseSettingsFromDict(const idDict& dict, int level)
{
idList<Setting> list;
// Cycle through all difficulty settings (looking for "diff_0_change_*")
idStr prefix = idStr(va(PATTERN_DIFF, level)) + PREFIX_CHANGE;
for (const idKeyValue* keyVal = dict.MatchPrefix(prefix);
keyVal != NULL;
keyVal = dict.MatchPrefix(prefix, keyVal))
{
DM_LOG(LC_DIFFICULTY, LT_INFO)LOGSTRING("Parsing keyvalue: %s = %s.\r", keyVal->GetKey().c_str(), keyVal->GetValue().c_str());
// Get the index from this keyvalue (remove the prefix and convert to int)
idStr key = keyVal->GetKey();
key.StripLeadingOnce(prefix);
if (key.IsNumeric())
{
// Extract the index
int index = atoi(key);
// Parse the settings with the given index
Setting s;
s.ParseFromDict(dict, level, index);
// Check for validity and insert into map
if (s.isValid)
{
list.Append(s);
}
}
else
{
gameLocal.Warning("Found invalid difficulty settings index: %s.", keyVal->GetKey().c_str());
DM_LOG(LC_DIFFICULTY, LT_ERROR)LOGSTRING("Found invalid difficulty settings index: %s.\r", keyVal->GetKey().c_str());
}
}
return list;
}
示例6: LoadFromEntityDef
void CVARDifficultySettings::LoadFromEntityDef(const idDict& dict)
{
// Cycle through all difficulty settings (looking for "diff_0_cvar_*")
idStr prefix = idStr(va(PATTERN_DIFF, _level)) + PREFIX_CVAR;
for (const idKeyValue* keyVal = dict.MatchPrefix(prefix);
keyVal != NULL;
keyVal = dict.MatchPrefix(prefix, keyVal))
{
DM_LOG(LC_DIFFICULTY, LT_INFO)LOGSTRING("Parsing cvar keyvalue: %s = %s.\r", keyVal->GetKey().c_str(), keyVal->GetValue().c_str());
// Get the index from this keyvalue (remove the prefix and convert to int)
idStr key = keyVal->GetKey();
key.StripLeadingOnce(prefix);
if (key.IsNumeric())
{
// Extract the index
int index = atoi(key);
// Parse the setting with the given index
CVARSetting s;
s.ParseFromDict(dict, _level, index);
// Check for validity and insert into map
if (s.isValid)
{
_settings.Append(s);
}
}
else
{
gameLocal.Warning("Found invalid cvar difficulty settings index: %s.", keyVal->GetKey().c_str());
DM_LOG(LC_DIFFICULTY, LT_ERROR)LOGSTRING("Found invalid cvar difficulty settings index: %s.\r", keyVal->GetKey().c_str());
}
}
}
示例7: Set
//
// Set()
//
void hhReactionDesc::Set(const idDict &keys) {
cause = StrToCause(keys.GetString("cause"));
effect = StrToEffect(keys.GetString("effect"));
flags = 0;
effectRadius = keys.GetFloat("effect_radius","-1.0f");
effectMinRadius = keys.GetFloat("effect_min_radius","0.0f");
if(keys.GetBool("snap_to_point")) {
flags |= flag_SnapToPoint;
}
if(keys.GetBool("effect_all_players")) {
flags |= flag_EffectAllPlayers;
}
if(keys.GetBool("effect_all_monsters")) {
flags |= flag_EffectAllMonsters;
}
if(keys.GetBool("req_novehicle")) {
flags |= flagReq_NoVehicle;
}
if(keys.GetBool("exclusive")) {
flags |= flag_Exclusive;
}
if(keys.GetBool("effect_listener")) {
flags |= flag_EffectListener;
}
if(keys.GetBool("anim_face_cause_dir")) {
flags |= flag_AnimFaceCauseDir;
}
if(keys.GetBool("anim_trigger_cause")) {
flags |= flag_AnimTriggerCause;
}
idStr keyString("");
if(keys.GetString("req_key", "", keyString)) {
if(keyString.Length() > 1) {
flags |= flagReq_KeyValue;
int firstSpace = keyString.Find(' ');
if( firstSpace >= 0 ) {
key = keyString.Left( firstSpace);
keyVal = keyString.Right( keyString.Length() - firstSpace -1);
}
}
else
gameLocal.Error("Invalide key for 'reaction_req_ley' value: %s", (const char*)keyString);
}
//MDC begin
keyString.Empty();
if( keys.GetString( "finish_key", "", keyString)) {
if( keyString.Length() > 1 ) {
int firstSpace = keyString.Find(' ');
if( firstSpace >= 0 ) {
finish_key = keyString.Left( firstSpace );
finish_val = keyString.Right( keyString.Length() - firstSpace - 1 );
}
}
}
//MDC end
idStr animString("");
if(keys.GetString("req_anim", "", animString)) {
flags |= flagReq_Anim;
anim = animString;
}
if(keys.GetBool("req_rangeattack")) {
flags |= flagReq_RangeAttack;
}
if(keys.GetBool("req_meleeattack")) {
flags |= flagReq_MeleeAttack;
}
if(keys.GetBool("req_can_see")) {
flags |= flagReq_CanSee;
}
if(keys.GetBool("req_telepathic") || cause == hhReactionDesc::Cause_Telepathic_Throw || cause == hhReactionDesc::Cause_Telepathic_Trigger) {
flags |= flagReq_Telepathic;
}
// Effect volumes
effectVolumes.Clear();
const idKeyValue *kv = keys.MatchPrefix("effect_volume", NULL);
while(kv) {
idStr effectVolName = kv->GetValue();
if(effectVolName.Length() > 0) {
idEntity *e = gameLocal.FindEntity(effectVolName.c_str());
if(!e) {
gameLocal.Error("Failed to find effect_volume named %s", effectVolName.c_str());
}
if(!e->IsType(hhReactionVolume::Type)) {
gameLocal.Error("effect_volume named %s was of incorrect spawn type. Must be hhReactionVolume", effectVolName.c_str());
}
//.........这里部分代码省略.........
示例8: AddItems
int CShop::AddItems(const idDict& mapDict, const idStr& itemKey, ShopItemList& list)
{
int diffLevel = gameLocal.m_DifficultyManager.GetDifficultyLevel();
int itemsAdded = 0;
// grayman (#2376)
// Convert itemKey to lowercase. mapDict methods ignore case, but
// StripLeadingOnce() doesn't. This change allows recognition of shop items defined as
// "startingItem_*", "startingitem_*", "shopItem_*", and "shopitem_*.
idStr itemKeyLower = itemKey;
itemKeyLower.ToLower();
bool isShopList = (itemKeyLower.Find("shop") >= 0); // for lockpick checking
for (const idKeyValue* kv = mapDict.MatchPrefix(itemKeyLower); kv != NULL; kv = mapDict.MatchPrefix(itemKeyLower, kv))
{
// Inspect the matching prefix, check whether the difficulty level applies
idStr postfix = kv->GetKey();
postfix.ToLower(); // grayman (#2376) convert postfix to lowercase so StripLeadingOnce()
// matches lowercase against lowercase
// Cut off the prefix including the following underscore _
postfix.StripLeadingOnce(itemKeyLower + "_");
int pos = postfix.Find("_item");
if (pos == -1 || pos != postfix.Length() - 5)
{
continue; // no suitable "_item" found
}
// This is the number portion, like "1_2" or merely "2"
idStr indexStr = postfix.Mid(0, pos);
// Check if we have still an underscore in the index string, this implies
// that there is a difficulty number included
int underScorePos = indexStr.Find('_');
// Extract the item index
int itemIndex = (underScorePos != -1) ? atoi(indexStr.Mid(0, underScorePos)) : atoi(indexStr);
if (underScorePos != -1)
{
// Check out the second number, this is the difficulty level
idStr diffStr = indexStr.Mid(underScorePos + 1, indexStr.Length() - underScorePos);
// Check if the difficulty level matches
if (atoi(diffStr) != diffLevel)
{
// Ignore this spawnarg
continue;
}
}
idStr itemName = kv->GetValue();
if (itemName.IsEmpty())
{
continue; // Empty names are not considered
}
// greebo: Assemble the item prefix (e.g. "shopItem_1_") to look up the rest of the spawnargs
idStr itemPrefix = itemKey + "_" + idStr(itemIndex);
idStr diffLevelStr = "_" + idStr(diffLevel);
// look for quantity, but let a difficulty-specific setting override the general one
int quantity = mapDict.GetInt(itemPrefix + "_qty");
if (mapDict.FindKey(itemPrefix + diffLevelStr + "_qty") != NULL)
{
quantity = mapDict.GetInt(itemPrefix + diffLevelStr + "_qty");
}
// put the item in the shop
if (quantity > 0)
{
// grayman (#2376) - Special handling for weapon quantities.
int index = itemName.Find("weapon_");
if (index >= 0)
{
// A shop entity should use atdm:weapon_*, but there's at least one
// that uses weapon_*, so convert the latter to the former.
idStr weaponName;
if (index == 0)
{
weaponName = "atdm:" + itemName;
}
else
{
weaponName = itemName;
}
// Weapon quantities have limits. (Arrows in particular.)
int max_ammo = GetMaxAmmo(weaponName);
quantity = (quantity > max_ammo) ? max_ammo : quantity;
//.........这里部分代码省略.........
示例9: InitFromSpawnArgs
void Conversation::InitFromSpawnArgs( const idDict &dict, int index ) {
idStr prefix = va( "conv_%d_", index );
// A non-empty name is mandatory for a conversation
if( !dict.GetString( prefix + "name", "", _name ) || _name.IsEmpty() ) {
// No conv_N_name spawnarg found, bail out
_isValid = false;
return;
}
// Parse "global" conversation settings
_talkDistance = dict.GetFloat( prefix + "talk_distance", "60" );
// Parse participant actors
// Check if this entity can be used by others.
idStr actorPrefix = prefix + "actor_";
for( const idKeyValue *kv = dict.MatchPrefix( actorPrefix ); kv != NULL; kv = dict.MatchPrefix( actorPrefix, kv ) ) {
// Add each actor name to the list
DM_LOG( LC_CONVERSATION, LT_DEBUG )LOGSTRING( "Adding actor %s to conversation %s.\r", kv->GetValue().c_str(), _name.c_str() );
_actors.AddUnique( kv->GetValue() );
}
DM_LOG( LC_CONVERSATION, LT_DEBUG )LOGSTRING( "Conversation %s has %d actors.\r", _name.c_str(), _actors.Num() );
if( _actors.Num() == 0 ) {
_isValid = false; // no actors, no conversation
gameLocal.Warning( "Ignoring conversation %s as it has no actors.", _name.c_str() );
return;
}
// Start parsing the conversation scripts (i.e. the commands), start with index 1
for( int i = 1; i < INT_MAX; i++ ) {
idStr cmdPrefix = va( prefix + "cmd_%d_", i );
DM_LOG( LC_CONVERSATION, LT_DEBUG )LOGSTRING( "Attempting to find command with index %d matching prefix %s.\r", i, cmdPrefix.c_str() );
if( dict.MatchPrefix( cmdPrefix ) != NULL ) {
// Found a matching "conv_N_cmd_M..." spawnarg, start parsing
ConversationCommandPtr cmd( new ConversationCommand );
// Let the command parse itself
if( cmd->Parse( dict, cmdPrefix ) ) {
// Parsing succeeded, add this to the command list
_commands.Append( cmd );
}
} else {
DM_LOG( LC_CONVERSATION, LT_DEBUG )LOGSTRING( "No match found, terminating loop on index %d.\r", i );
break;
}
}
DM_LOG( LC_CONVERSATION, LT_DEBUG )LOGSTRING( "%d Commands found for Conversation %s.\r", _commands.Num(), _name.c_str() );
// Sanity check the commands
if( _commands.Num() == 0 ) {
// No commands, what kind of conversation is this?
_isValid = false;
gameLocal.Warning( "Ignoring conversation %s as it has no commands.", _name.c_str() );
return;
}
// Sanity check the talk distance
if( _talkDistance <= 0.0f ) {
_isValid = false;
gameLocal.Warning( "Ignoring conversation %s as it has a talk distance <= 0.", _name.c_str() );
return;
}
// get max play count, default is -1, which means infinitely often
_maxPlayCount = dict.GetInt( prefix + "max_play_count", "-1" );
// per default, the actors should be within talk distance before they start talking
_actorsMustBeWithinTalkDistance = dict.GetBool( prefix + "actors_must_be_within_talkdistance", "1" );
_actorsAlwaysFaceEachOtherWhileTalking = dict.GetBool( prefix + "actors_always_face_each_other_while_talking", "1" );
// greebo: For conversations with one actor some flags don't make sense
if( _actors.Num() == 1 ) {
_actorsMustBeWithinTalkDistance = false;
_actorsAlwaysFaceEachOtherWhileTalking = false;
}
// Seems like we have everything we need
_isValid = true;
}
示例10: 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;
}