void CStimResponseCollection::CreateTimer(const idDict& args, const CStimPtr& stim, int index) { CStimResponseTimer* timer = stim->GetTimer(); timer->m_Reload = args.GetInt(va("sr_timer_reload_%u", index) , "-1"); idStr str = args.GetString(va("sr_timer_type_%u", index), ""); timer->m_Type = (str == "RELOAD") ? CStimResponseTimer::SRTT_RELOAD : CStimResponseTimer::SRTT_SINGLESHOT; args.GetString(va("sr_timer_time_%u", index), "0:0:0:0", str); TimerValue val = CStimResponseTimer::ParseTimeString(str); // if timer is actually set if (val.Time.Hour || val.Time.Minute || val.Time.Second || val.Time.Millisecond) { // TODO: Return a bool here so that the outer function knows not to add this to m_Stim in the collection? stim->AddTimerToGame(); timer->SetTimer(val.Time.Hour, val.Time.Minute, val.Time.Second, val.Time.Millisecond); // timer starts on map startup by default, otherwise wait for start if (!args.GetBool(va("sr_timer_waitforstart_%u", index), "0")) { timer->Start(static_cast<unsigned long>(sys->GetClockTicks())); } } }
// // 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); }
/* ================ 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(); }
void CInventoryItem::ParseSpawnargs(const idDict& spawnArgs) { m_Persistent = spawnArgs.GetBool("inv_persistent", "0"); m_LightgemModifier = spawnArgs.GetInt("inv_lgmodifier", "0"); m_MovementModifier = spawnArgs.GetFloat("inv_movement_modifier", "1"); m_FrobDistanceCap = spawnArgs.GetFloat("inv_frob_distance_cap", "-1"); m_Icon = spawnArgs.GetString("inv_icon", ""); }
/* ================ idDemoFile::WriteDict ================ */ void idDemoFile::WriteDict( const idDict &dict ) { int i, c; c = dict.GetNumKeyVals(); WriteInt( c ); for( i = 0; i < c; i++ ) { WriteHashString( dict.GetKeyVal( i )->GetKey() ); WriteHashString( dict.GetKeyVal( i )->GetValue() ); } }
/* ============ idCVarSystemLocal::MoveCVarsToDict ============ */ const idDict* idCVarSystemLocal::MoveCVarsToDict( int flags ) const { moveCVarsToDict.Clear(); for( int i = 0; i < cvars.Num(); i++ ) { idCVar *cvar = cvars[i]; if ( cvar->GetFlags() & flags ) { moveCVarsToDict.Set( cvar->GetName(), cvar->GetString() ); } } return &moveCVarsToDict; }
/* ============ idCVarSystemLocal::SetCVarsFromDict ============ */ void idCVarSystemLocal::SetCVarsFromDict( const idDict &dict ) { idInternalCVar *internal; for( int i = 0; i < dict.GetNumKeyVals(); i++ ) { const idKeyValue *kv = dict.GetKeyVal( i ); internal = FindInternal( kv->GetKey() ); if ( internal ) { internal->InternalServerSetString( kv->GetValue() ); } } }
/* ================ idDemoFile::ReadDict ================ */ void idDemoFile::ReadDict( idDict &dict ) { int i, c; idStr key, val; dict.Clear(); ReadInt( c ); for( i = 0; i < c; i++ ) { key = ReadHashString(); val = ReadHashString(); dict.Set( key, val ); } }
void Setting::ParseFromDict(const idDict& dict, int level, int index) { isValid = true; // in dubio pro reo // Get the classname, target spawnarg and argument className = dict.GetString(va(PATTERN_CLASS, level, index)); spawnArg = dict.GetString(va(PATTERN_CHANGE, level, index)); argument = dict.GetString(va(PATTERN_ARG, level, index)); // Parse the application type appType = EAssign; if (!argument.IsEmpty()) { // Check for ignore argument if (argument == APPTYPE_IGNORE) { appType = EIgnore; argument.Empty(); // clear the argument } else if (argument.Find(' ') != -1) { // greebo: We have a space in the argument, hence it cannot be // a mathematical operation. This usually applies to vector arguments // like '-205 10 20', which can contain a leading minus sign. } // Check for special modifiers else if (argument[0] == '+') { appType = EAdd; // Remove the first character argument = idStr(argument, 1, argument.Length()); } else if (argument[0] == '*') { appType = EMultiply; // Remove the first character argument = idStr(argument, 1, argument.Length()); } else if (argument[0] == '-') { appType = EAdd; // Leave the "-" sign, it will be the sign of the parsed int } } if (spawnArg.IsEmpty()) { // Spawnarg must not be empty isValid = false; } // classname can be empty (this is valid for entity-specific difficulties) }
END_CLASS /* ================ sdVehicleJointAimer::Setup ================ */ bool sdVehicleJointAimer::Setup( sdTransport* _vehicle, const angleClamp_t& yaw, const angleClamp_t& pitch, const idDict& ikParms ) { joint = INVALID_JOINT; if ( !sdVehicleIKSystem::Setup( _vehicle, yaw, pitch, ikParms ) ) { return false; } yawSound = NULL; if ( clampYaw.sound != NULL ) { yawSound = vehicle->GetMotorSounds().Alloc(); yawSound->Start( clampYaw.sound ); } pitchSound = NULL; if ( clampPitch.sound != NULL ) { pitchSound = vehicle->GetMotorSounds().Alloc(); pitchSound->Start( clampPitch.sound ); } idAnimator* animator = vehicle->GetAnimator(); joint = animator->GetJointHandle( ikParms.GetString( "joint" ) ); if ( joint == INVALID_JOINT ) { return false; } animator->GetJointTransform( joint, gameLocal.time, baseAxis ); angles = baseAxis.ToAngles(); const char* weapon2Name = ikParms.GetString( "weapon2" ); if ( *weapon2Name ) { weapon2 = _vehicle->GetWeapon( weapon2Name ); if ( !weapon2 ) { gameLocal.Warning( "sdVehicleIKSystem::Setup Invalid Weapon '%s'", weapon2Name ); return false; } } else { weapon2 = NULL; } return true; }
DifficultySettings::InheritanceChain DifficultySettings::GetInheritanceChain(const idDict& dict) { std::string className = dict.GetString("classname"); // stgatilov: Look the class name up in the chains cache InheritanceChainsMap::iterator it = _inheritanceChains.find(className); if (it != _inheritanceChains.end()) return it->second; InheritanceChain inheritanceChain; // Add the classname itself to the end of the list inheritanceChain.push_back(className); // greebo: Extract the inherit value from the raw declaration text, // as the "inherit" key has been removed in the given "dict" for (std::string inherit = GetInheritValue(className); !inherit.empty(); inherit = GetInheritValue(inherit)) { // Has parent, add to list inheritanceChain.push_back(inherit); } // stgatilov: reverse the chain so that parents go first std::reverse(inheritanceChain.begin(), inheritanceChain.end()); // stgatilov: save the chain in cache _inheritanceChains[className] = inheritanceChain; return inheritanceChain; }
void DifficultySettings::ApplySettings(idDict& target) { std::string eclass = target.GetString("classname"); if (eclass.empty()) { return; // no classname, no rules } // greebo: First, get the list of entity-specific difficulty settings from the dictionary // Everything processed here will be ignored in the second run (where the default settings are applied) idList<Setting> entSettings = Setting::ParseSettingsFromDict(target, _level); DM_LOG(LC_DIFFICULTY, LT_DEBUG)LOGSTRING("Found %d difficulty settings on the entity %s.\r", entSettings.Num(), target.GetString("name")); // Apply the settings one by one for (int i = 0; i < entSettings.Num(); i++) { DM_LOG(LC_DIFFICULTY, LT_DEBUG)LOGSTRING("Applying entity-specific setting: %s => %s.\r", entSettings[i].spawnArg.c_str(), entSettings[i].argument.c_str()); entSettings[i].Apply(target); } // Second step: apply global settings // Get the inheritancechain for the given target dict const InheritanceChain &inheritanceChain = GetInheritanceChain(target); // Go through the inheritance chain front to back and apply the settings for (InheritanceChain::const_iterator c = inheritanceChain.begin(); c != inheritanceChain.end(); ++c) { std::string className = *c; // Process the list of default settings that apply to this entity class, // but ignore all keys that have been addressed by the entity-specific settings. for (SettingsMap::iterator i = _settings.find(className); i != _settings.upper_bound(className) && i != _settings.end(); ++i) { Setting& setting = i->second; bool settingApplicable = true; // Check if the spawnarg has been processed in the entity-specific settings for (int k = 0; k < entSettings.Num(); k++) { if (entSettings[k].spawnArg == setting.spawnArg) { // This target spawnarg has already been processed in the first run, skip it DM_LOG(LC_DIFFICULTY, LT_DEBUG)LOGSTRING("Ignoring global setting: %s => %s.\r", setting.spawnArg.c_str(), setting.argument.c_str()); settingApplicable = false; break; } } if (settingApplicable) { // We have green light, apply the setting DM_LOG(LC_DIFFICULTY, LT_DEBUG)LOGSTRING("Applying global setting: %s => %s.\r", setting.spawnArg.c_str(), setting.argument.c_str()); setting.Apply(target); } } } }
void CStimResponseCollection::InitFromSpawnargs(const idDict& args, idEntity* owner) { if (owner == NULL) { DM_LOG(LC_STIM_RESPONSE, LT_ERROR)LOGSTRING("Owner set to NULL is not allowed!\r"); return; } idStr name; for (int i = 1; /* in-loop break */; ++i) { idStr name = va("sr_class_%u", i); DM_LOG(LC_STIM_RESPONSE, LT_DEBUG)LOGSTRING("Looking for %s\r", name.c_str()); idStr str; if (!args.GetString(name, "X", str)) { break; } char sr_class = str[0]; if (ParseSpawnArg(args, owner, sr_class, i) == false) { break; } } }
END_CLASS /* ================ sdVehicleSwivel::Setup ================ */ bool sdVehicleSwivel::Setup( sdTransport* _vehicle, const angleClamp_t& yaw, const angleClamp_t& pitch, const idDict& ikParms ) { joint = INVALID_JOINT; if ( !sdVehicleIKSystem::Setup( _vehicle, yaw, pitch, ikParms ) ) { return false; } angles.Zero(); idAnimator* animator = vehicle->GetAnimator(); joint = animator->GetJointHandle( ikParms.GetString( "joint" ) ); animator->GetJointTransform( joint, gameLocal.time, baseAxis ); yawSound = NULL; if ( clampYaw.sound != NULL ) { yawSound = vehicle->GetMotorSounds().Alloc(); yawSound->Start( clampYaw.sound ); } return true; }
END_CLASS /* ================ sdVehicleIKSystem::Setup ================ */ bool sdVehicleIKSystem::Setup( sdTransport* _vehicle, const angleClamp_t& yaw, const angleClamp_t& pitch, const idDict& ikParms ) { vehicle = _vehicle; clampYaw = yaw; clampPitch = pitch; const char* weaponName = ikParms.GetString( "weapon" ); if ( *weaponName ) { weapon = _vehicle->GetWeapon( weaponName ); if ( !weapon ) { gameLocal.Warning( "sdVehicleIKSystem::Setup Invalid Weapon '%s'", weaponName ); return false; } } else { weapon = NULL; } return true; }
/* ============ idCVarSystemLocal::Shutdown ============ */ void idCVarSystemLocal::Shutdown( void ) { cvars.DeleteContents( true ); cvarHash.Free(); moveCVarsToDict.Clear(); initialized = false; }
/* ======================== idAchievementManager::SavePersistentData ======================== */ void idAchievementManager::SavePersistentData( idDict& playerInfo ) { for( int i = 0; i < ACHIEVEMENTS_NUM; ++i ) { playerInfo.SetInt( va( "ach_%d", i ), counts[i] ); } }
/* ======================== idAchievementManager::RestorePersistentData ======================== */ void idAchievementManager::RestorePersistentData( const idDict& spawnArgs ) { for( int i = 0; i < ACHIEVEMENTS_NUM; ++i ) { counts[i] = spawnArgs.GetInt( va( "ach_%d", i ), "0" ); } }
/* ============== idSpawner::CopyPrefixedSpawnArgs ============== */ void idSpawner::CopyPrefixedSpawnArgs( idEntity *src, const char *prefix, idDict &args ){ const idKeyValue *kv = src->spawnArgs.MatchPrefix( prefix, NULL ); while ( kv ) { args.Set( kv->GetKey().c_str() + idStr::Length( prefix ), kv->GetValue() ); kv = src->spawnArgs.MatchPrefix( prefix, kv ); } }
/* ============ sdGameRulesStopWatch::InhibitEntitySpawn ============ */ bool sdGameRulesStopWatch::InhibitEntitySpawn( idDict &spawnArgs ) const { if ( spawnArgs.GetBool( "noStopwatch" ) ) { return true; } return false; }
bool DifficultyManager::InhibitEntitySpawn( const idDict &target ) { bool isAllowed( true ); // Construct the key ("diff_0_spawn") idStr key = va( "diff_%d_nospawn", _difficulty ); // The entity is allowed to spawn by default, must be set to 1 by the mapper isAllowed = !target.GetBool( key, "0" ); DM_LOG( LC_DIFFICULTY, LT_INFO )LOGSTRING( "Entity %s is allowed to spawn on difficulty %i: %s.\r", target.GetString( "name" ), _difficulty, isAllowed ? "YES" : "NO" ); // Tels: #3223: See if this entity should spawn this time float random_remove = target.GetFloat( "random_remove", "1.1" ); float random_value = gameLocal.random.RandomFloat(); if( random_remove < random_value ) { isAllowed = false; DM_LOG( LC_ENTITY, LT_INFO )LOGSTRING( "Removing entity %s due to random_remove %f < %f.\r", target.GetString( "name" ), random_remove, random_value ); } // Return false if the entity is allowed to spawn return !isAllowed; }
/* ================ sdRequirementCheck_Ability::Check ================ */ void sdRequirementCheck_Ability::Init( const idDict& parms ) { const char* abilityValue = parms.GetString( "value" ); if ( !*abilityValue ) { gameLocal.Error( "sdRequirementCheck_Ability::Init No 'value' key specified" ); } abilityHandle = sdRequirementManager::GetInstance().RegisterAbility( abilityValue ); }
/* ============ sdGameRulesStopWatch::UpdateClientFromServerInfo ============ */ void sdGameRulesStopWatch::UpdateClientFromServerInfo( const idDict& serverInfo, bool allowMedia ) { sdGameRules::UpdateClientFromServerInfo( serverInfo, allowMedia ); idStr mapName = serverInfo.GetString( "si_map" ); if( mapName.IsEmpty() ) { return; } mapName.StripFileExtension(); using namespace sdProperties; // update status if ( sdUserInterfaceScope* scope = gameLocal.globalProperties.GetSubScope( "campaignInfo" ) ) { const idDict* metaData = gameLocal.mapMetaDataList->FindMetaData( mapName, &gameLocal.defaultMetaData ); if( allowMedia ) { const sdDeclMapInfo* mapInfo = gameLocal.declMapInfoType.LocalFind( metaData->GetString( "mapinfo", "_default" ) ); // setup the backdrop if ( sdProperty* property = scope->GetProperty( "backdrop", PT_STRING ) ) { *property->value.stringValue = mapInfo->GetData().GetString( "mtr_backdrop", "guis/assets/black" ); } const char* status = "current"; if( winningTeam != NULL ) { status = winningTeam->GetLookupName(); } SetupLoadScreenUI( *scope, status, true, 1, *metaData, mapInfo ); } // setup the name if ( sdProperty* property = scope->GetProperty( "name", PT_WSTRING ) ) { *property->value.wstringValue = va( L"%hs", metaData->GetString( "pretty_name" ) ); } if ( sdProperty* property = scope->GetProperty( "numMaps", PT_FLOAT ) ) { *property->value.floatValue = 1.0f; } if ( sdProperty* property = scope->GetProperty( "currentMap", PT_FLOAT ) ) { *property->value.floatValue = 1.0f; } idWStr text; if( timeToBeat > 0 ) { idWStr::hmsFormat_t format; format.showZeroMinutes = true; idWStrList args( 1 ); args.Append( idWStr::MS2HMS( timeToBeat, format ) ); text = common->LocalizeText( "guis/mainmenu/timetobeat", args ); } // setup the status if ( sdProperty* property = scope->GetProperty( "ruleStatus", PT_WSTRING ) ) { *property->value.wstringValue = text; } } }
/* ================ sdRequirementCheck_Team::Init ================ */ void sdRequirementCheck_Team::Init( const idDict& parms ) { const char* teamName = parms.GetString( "value" ); if ( !idStr::Icmp( teamName, "none" ) ) { index = -1; } else { sdTeamInfo& team = sdTeamManager::GetInstance().GetTeam( teamName ); index = team.GetIndex(); } }
/* ================ 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() ]; } } }
/* ================ idItem::GetAttributes ================ */ void idItem::GetAttributes( idDict &attributes ) { int i; const idKeyValue *arg; for( i = 0; i < spawnArgs.GetNumKeyVals(); i++ ) { arg = spawnArgs.GetKeyVal( i ); if ( arg->GetKey().Left( 4 ) == "inv_" ) { attributes.Set( arg->GetKey().Right( arg->GetKey().Length() - 4 ), arg->GetValue() ); } } }
void CVARSetting::ParseFromDict(const idDict& dict, int level, int index) { // Call the base class first to parse the arguments and stuff Setting::ParseFromDict(dict, level, index); // Parse the CVAR name cvar = dict.GetString(va(PATTERN_CVAR, level, index)); // CVAR must not be empty, everything else is not that important isValid = !cvar.IsEmpty(); }
/* ================ sdRequirementCheck_EntityBin::Init ================ */ void sdRequirementCheck_EntityBin::Init( const idDict& parms ) { const char* typeName = parms.GetString( "type" ); if ( !*typeName ) { gameLocal.Error( "sdRequirementCheck_EntityBin::Init - No 'type' key specified" ); } type = gameLocal.declEntityDefType[ typeName ]; if ( type == NULL ) { gameLocal.Error( "sdRequirementCheck_EntityBin::Init - Couldn't find entityDef for '%s'", typeName ); } }
/* ================ sdRequirementCheck_Allegiance::Check ================ */ void sdRequirementCheck_Allegiance::Init( const idDict& parms ) { const char* value = parms.GetString( "value" ); if ( !idStr::Icmp( value, "friend" ) ) { allegiance = TA_FRIEND; } else if ( !idStr::Icmp( value, "enemy" ) ) { allegiance = TA_ENEMY; } else if ( !idStr::Icmp( value, "neutral" ) ) { allegiance = TA_NEUTRAL; } else { gameLocal.Error( "sdRequirementCheck_Allegiance::Init Invalid Allegiance Type '%s'", value ); } }
void CShop::LoadFromDict(const idDict& dict) { // greebo: Assemble the difficulty prefix (e.g. "diff_0_") idStr diffPrefix = "diff_" + idStr(gameLocal.m_DifficultyManager.GetDifficultyLevel()) + "_"; if (dict.GetBool("shop_skip","0") || dict.GetBool(diffPrefix + "shop_skip","0")) { // if skip flag is set, skip the shop _skipShop = true; // No need to parse any further, the shop will be skipped anyway return; } // Check for loot carry-over rules LoadLootRules(dict); // Check for an "all-difficulty" gold value if (dict.FindKey("shop_gold_start") != NULL) { SetGold(dict.GetInt("shop_gold_start")); } // Try to retrieve the starting gold for the given difficulty level if (dict.FindKey(diffPrefix + "shop_gold_start") != NULL) { SetGold(dict.GetInt(diffPrefix + "shop_gold_start")); } // items for sale AddItems(dict, "shopItem", _itemsForSale); // starting items (items that player already has AddItems(dict, "startingItem", _startingItems); }