void FileWeaponInfo_t::Parse( KeyValues *pKeyValuesData, const char *szWeaponName ) { // Okay, we tried at least once to look this up... bParsedScript = true; // Classname Q_strncpy( szClassName, szWeaponName, MAX_WEAPON_STRING ); // Printable name Q_strncpy( szPrintName, pKeyValuesData->GetString( "printname", WEAPON_PRINTNAME_MISSING ), MAX_WEAPON_STRING ); // View model & world model Q_strncpy( szViewModel, pKeyValuesData->GetString( "viewmodel" ), MAX_WEAPON_STRING ); Q_strncpy( szWorldModel, pKeyValuesData->GetString( "playermodel" ), MAX_WEAPON_STRING ); Q_strncpy( szAnimationPrefix, pKeyValuesData->GetString( "anim_prefix" ), MAX_WEAPON_PREFIX ); Q_strncpy( szWeaponType, pKeyValuesData->GetString("weapon_type"), MAX_WEAPON_STRING ); iSlot = pKeyValuesData->GetInt( "bucket", 0 ); iPosition = pKeyValuesData->GetInt( "bucket_position", 0 ); // Use the console (X360) buckets if hud_fastswitch is set to 2. #ifdef CLIENT_DLL if ( hud_fastswitch.GetInt() == 2 ) #else if ( IsX360() ) #endif { iSlot = pKeyValuesData->GetInt( "bucket_360", iSlot ); iPosition = pKeyValuesData->GetInt( "bucket_position_360", iPosition ); } iMaxClip1 = pKeyValuesData->GetInt( "clip_size", WEAPON_NOCLIP ); // Max primary clips gun can hold (assume they don't use clips by default) iMaxClip2 = pKeyValuesData->GetInt( "clip2_size", WEAPON_NOCLIP ); // Max secondary clips gun can hold (assume they don't use clips by default) iDefaultClip1 = pKeyValuesData->GetInt( "default_clip", iMaxClip1 ); // amount of primary ammo placed in the primary clip when it's picked up iDefaultClip2 = pKeyValuesData->GetInt( "default_clip2", iMaxClip2 ); // amount of secondary ammo placed in the secondary clip when it's picked up iWeight = pKeyValuesData->GetInt( "weight", 0 ); iRumbleEffect = pKeyValuesData->GetInt( "rumble", -1 ); // LAME old way to specify item flags. // Weapon scripts should use the flag names. iFlags = pKeyValuesData->GetInt( "item_flags", ITEM_FLAG_LIMITINWORLD ); for ( int i=0; i < ARRAYSIZE( g_ItemFlags ); i++ ) { int iVal = pKeyValuesData->GetInt( g_ItemFlags[i].m_pFlagName, -1 ); if ( iVal == 0 ) { iFlags &= ~g_ItemFlags[i].m_iFlagValue; } else if ( iVal == 1 ) { iFlags |= g_ItemFlags[i].m_iFlagValue; } } bShowUsageHint = ( pKeyValuesData->GetInt( "showusagehint", 0 ) != 0 ) ? true : false; bAutoSwitchTo = ( pKeyValuesData->GetInt( "autoswitchto", 1 ) != 0 ) ? true : false; bAutoSwitchFrom = ( pKeyValuesData->GetInt( "autoswitchfrom", 1 ) != 0 ) ? true : false; m_bBuiltRightHanded = ( pKeyValuesData->GetInt( "BuiltRightHanded", 1 ) != 0 ) ? true : false; m_bAllowFlipping = ( pKeyValuesData->GetInt( "AllowFlipping", 1 ) != 0 ) ? true : false; m_bMeleeWeapon = ( pKeyValuesData->GetInt( "MeleeWeapon", 0 ) != 0 ) ? true : false; m_bUseMagStyleReloads = (pKeyValuesData->GetInt("MagazineStyledReloads", 0) != 0) ? true : false; m_bUseMuzzleSmoke = (pKeyValuesData->GetInt("UseMuzzleSmoke", 0) != 0) ? true : false; m_bUseIronsight = (pKeyValuesData->GetInt("useironsights", 1) != 0) ? true : false; m_bLowerWeapon = (pKeyValuesData->GetInt("LowerWeapon", 1) != 0) ? true : false; m_bUseIronsightCrosshair = (pKeyValuesData->GetInt("useironsightcrosshair", 1) != 0) ? true : false; #if defined(_DEBUG) && defined(HL2_CLIENT_DLL) // make sure two weapons aren't in the same slot & position if ( iSlot >= MAX_WEAPON_SLOTS || iPosition >= MAX_WEAPON_POSITIONS ) { Warning( "Invalid weapon slot or position [slot %d/%d max], pos[%d/%d max]\n", iSlot, MAX_WEAPON_SLOTS - 1, iPosition, MAX_WEAPON_POSITIONS - 1 ); } else { if (g_bUsedWeaponSlots[iSlot][iPosition]) { Warning( "Duplicately assigned weapon slots in selection hud: %s (%d, %d)\n", szPrintName, iSlot, iPosition ); } g_bUsedWeaponSlots[iSlot][iPosition] = true; } #endif // Primary ammo used cAmmoType = pKeyValuesData->GetString("primary_ammo", "None"); if (strcmp("None", cAmmoType) == 0) Q_strncpy( szAmmo1, "", sizeof( szAmmo1 ) ); else Q_strncpy(szAmmo1, cAmmoType, sizeof(szAmmo1)); iAmmoType = GetAmmoDef()->Index( szAmmo1 ); // Secondary ammo used cAmmo2Type = pKeyValuesData->GetString("secondary_ammo", "None"); if (strcmp("None", cAmmo2Type) == 0) Q_strncpy( szAmmo2, "", sizeof( szAmmo2 ) ); else Q_strncpy(szAmmo2, cAmmo2Type, sizeof(szAmmo2)); iAmmo2Type = GetAmmoDef()->Index( szAmmo2 ); //ironsights KeyValues *pSights = pKeyValuesData->FindKey("IronSight"); if (pSights) { vecIronsightPosOffset.x = pSights->GetFloat("forward", 0.0f); vecIronsightPosOffset.y = pSights->GetFloat("right", 0.0f); vecIronsightPosOffset.z = pSights->GetFloat("up", 0.0f); angIronsightAngOffset[PITCH] = pSights->GetFloat("pitch", 0.0f); angIronsightAngOffset[YAW] = pSights->GetFloat("yaw", 0.0f); angIronsightAngOffset[ROLL] = pSights->GetFloat("roll", 0.0f); flIronsightFOVOffset = pSights->GetFloat("fov", 0.0f); } else { //m_bUseIronsight = false; vecIronsightPosOffset = vec3_origin; angIronsightAngOffset.Init(); } //Adjust KeyValues *pAdjust = pKeyValuesData->FindKey("Adjust"); if (pAdjust) { vecAdjustPosOffset.x = pAdjust->GetFloat("forward", 0.0f); vecAdjustPosOffset.y = pAdjust->GetFloat("right", 0.0f); vecAdjustPosOffset.z = pAdjust->GetFloat("up", 0.0f); angAdjustAngOffset[PITCH] = pAdjust->GetFloat("pitch", 0.0f); angAdjustAngOffset[YAW] = pAdjust->GetFloat("yaw", 0.0f); angAdjustAngOffset[ROLL] = pAdjust->GetFloat("roll", 0.0f); } else { vecAdjustPosOffset = vec3_origin; angAdjustAngOffset.Init(); } KeyValues *pWeaponSpec = pKeyValuesData->FindKey("WeaponSpec"); if (pWeaponSpec) { KeyValues *pWeaponOptions = pWeaponSpec->FindKey("WeaponOptions"); if (pWeaponOptions) { m_sWeaponOptions = true; m_sCanReloadSingly = (pWeaponOptions->GetInt("CanReloadSingly", 1) != 0) ? true : false; m_sDualWeapons = (pWeaponOptions->GetInt("DualWeapons", 1) != 0) ? true : false; m_sCustomMelee = (pWeaponOptions->GetInt("IsMelee", 1) != 0) ? true : false; m_sCustomMeleeSecondary = (pWeaponOptions->GetInt("SecondaryCanMelee", 1) != 0) ? true : false; } else { m_sWeaponOptions = false; } KeyValues *pPrimaryFire = pWeaponSpec->FindKey("PrimaryFire"); if (pPrimaryFire) { m_sHasPrimaryFire = true; m_sPrimaryFireRate = pPrimaryFire->GetFloat("FireRate", 1.0f); m_sPrimaryIronsightFireRate = pPrimaryFire->GetFloat("IronsightFireRate", m_sPrimaryFireRate); m_sPrimaryZoomFireRate = pPrimaryFire->GetFloat("ZoomFireRate", m_sPrimaryFireRate); m_sPrimaryInfiniteAmmoEnabled = (pPrimaryFire->GetInt("InfiniteAmmo", 1) != 0) ? true : false; m_sPrimaryMinRange = pPrimaryFire->GetInt("MinRange", 0); m_sPrimaryMinRange = pPrimaryFire->GetInt("MaxRange", 0); m_sCanPrimaryFireUnderwater = (pPrimaryFire->GetInt("CanFireUnderwater", 1) != 0) ? true : false; m_sFireBothOnPrimary = (pWeaponOptions->GetInt("FireBothGuns", 1) != 0) ? true : false; KeyValues *pBullet1 = pPrimaryFire->FindKey("Bullet"); if (pBullet1) { m_sPrimaryBulletEnabled = true; m_sPrimaryDamage = pBullet1->GetFloat("Damage", 0); m_sPrimaryShotCount = pBullet1->GetInt("ShotCount", 0); KeyValues *pSpread1 = pBullet1->FindKey("Spread"); if (pSpread1) { m_vPrimarySpread.x = sin((pSpread1->GetFloat("x", 0.0f) / 2.0f)); m_vPrimarySpread.y = sin((pSpread1->GetFloat("y", 0.0f) / 2.0f)); m_vPrimarySpread.z = sin((pSpread1->GetFloat("z", 0.0f) / 2.0f)); } else { m_vPrimarySpread.x = 0.0f; m_vPrimarySpread.y = 0.0f; m_vPrimarySpread.z = 0.0f; } KeyValues *pIronsightSpread1 = pBullet1->FindKey("IronsightSpread"); if (pIronsightSpread1) { m_vPrimaryIronsightSpread.x = sin((pIronsightSpread1->GetFloat("x", 0.0f) / 2.0f)); m_vPrimaryIronsightSpread.y = sin((pIronsightSpread1->GetFloat("y", 0.0f) / 2.0f)); m_vPrimaryIronsightSpread.z = sin((pIronsightSpread1->GetFloat("z", 0.0f) / 2.0f)); } else { m_vPrimaryIronsightSpread.x = m_vPrimarySpread.x; m_vPrimaryIronsightSpread.y = m_vPrimarySpread.y; m_vPrimaryIronsightSpread.z = m_vPrimarySpread.z; } KeyValues *pZoomSpread1 = pBullet1->FindKey("ZoomSpread"); if (pZoomSpread1) { m_vPrimaryZoomSpread.x = sin((pZoomSpread1->GetFloat("x", 0.0f) / 2.0f)); m_vPrimaryZoomSpread.y = sin((pZoomSpread1->GetFloat("y", 0.0f) / 2.0f)); m_vPrimaryZoomSpread.z = sin((pZoomSpread1->GetFloat("z", 0.0f) / 2.0f)); } else { m_vPrimaryZoomSpread.x = m_vPrimarySpread.x; m_vPrimaryZoomSpread.y = m_vPrimarySpread.y; m_vPrimaryZoomSpread.z = m_vPrimarySpread.z; } } else { m_sPrimaryDamage = 0.0f; m_sPrimaryShotCount = 0; m_sPrimaryBulletEnabled = false; } KeyValues *pMissle1 = pPrimaryFire->FindKey("Missle"); if (pMissle1) //No params yet, but setting this will enable missles { m_sPrimaryMissleEnabled = true; m_sPrimaryHasRecoilRPGMissle = (pMissle1->GetInt("UseRecoil", 1) != 0) ? true : false; } else { m_sPrimaryMissleEnabled = false; } KeyValues *pSMGGrenade1 = pPrimaryFire->FindKey("SMGGrenade"); if (pSMGGrenade1) //No params yet, but setting this will enable missles { m_sPrimarySMGGrenadeEnabled = true; m_sSMGGrenadePrimaryDamage = pSMGGrenade1->GetFloat("Damage", 0); m_sPrimaryHasRecoilSMGGrenade = (pSMGGrenade1->GetInt("UseRecoil", 1) != 0) ? true : false; } else { m_sPrimarySMGGrenadeEnabled = false; m_sSMGGrenadePrimaryDamage = 0.0; } KeyValues *pAR2EnergyBall1 = pPrimaryFire->FindKey("AR2EnergyBall"); if (pAR2EnergyBall1) //No params yet, but setting this will enable missles { m_sPrimaryAR2EnergyBallEnabled = true; m_sPrimaryCombineBallRadius = pAR2EnergyBall1->GetFloat("Radius", 0); m_sPrimaryCombineBallMass = pAR2EnergyBall1->GetFloat("Mass", 0); m_sPrimaryCombineBallDuration = pAR2EnergyBall1->GetFloat("Duration", 0); } else { m_sPrimaryAR2EnergyBallEnabled = false; m_sPrimaryCombineBallRadius = 0.0; m_sPrimaryCombineBallMass = 0.0; m_sPrimaryCombineBallDuration = 0.0; } KeyValues *pRecoil1 = pPrimaryFire->FindKey("Recoil"); if (pRecoil1) //No params yet, but setting this will enable missles { m_sPrimaryRecoilEasyDampen = pRecoil1->GetFloat("EasyDampen", 0); m_sPrimaryRecoilDegrees = pRecoil1->GetFloat("Degrees", 0); m_sPrimaryRecoilSeconds = pRecoil1->GetFloat("Seconds", 0); } else { m_sPrimaryRecoilEasyDampen = 0.0; m_sPrimaryRecoilDegrees = 0.0; m_sPrimaryRecoilSeconds = 0.0; } } else { m_sHasPrimaryFire = false; } KeyValues *pSecondaryFire = pWeaponSpec->FindKey("SecondaryFire"); if (pSecondaryFire) { m_sHasSecondaryFire = true; m_sSecondaryFireRate = pSecondaryFire->GetFloat("FireRate", 1.0f); m_sSecondaryIronsightFireRate = pSecondaryFire->GetFloat("IronsightFireRate", m_sSecondaryFireRate); m_sSecondaryZoomFireRate = pSecondaryFire->GetFloat("ZoomFireRate", m_sSecondaryFireRate); m_sUsePrimaryAmmo = (pSecondaryFire->GetInt("UsePrimaryAmmo", 0) != 0) ? true : false; m_sSecondaryInfiniteAmmoEnabled = (pSecondaryFire->GetInt("InfiniteAmmo", 1) != 0) ? true : false; m_sSecondaryMinRange = pSecondaryFire->GetInt("MinRange", 0); m_sSecondaryMinRange = pSecondaryFire->GetInt("MaxRange", 0); m_sCanSecondaryFireUnderwater = (pSecondaryFire->GetInt("CanFireUnderwater", 1) != 0) ? true : false; m_sFireBothOnSecondary = (pWeaponOptions->GetInt("FireBothGuns", 1) != 0) ? true : false; KeyValues *pBullet2 = pSecondaryFire->FindKey("Bullet"); if (pBullet2) { m_sSecondaryBulletEnabled = true; m_sSecondaryDamage = pBullet2->GetFloat("Damage", 0); m_sSecondaryShotCount = pBullet2->GetInt("ShotCount", 0); KeyValues *pSpread2 = pBullet2->FindKey("Spread"); if (pSpread2) { m_vSecondarySpread.x = sin(pSpread2->GetFloat("x", 0.0f) / 2.0f); m_vSecondarySpread.y = sin(pSpread2->GetFloat("y", 0.0f) / 2.0f); m_vSecondarySpread.z = sin(pSpread2->GetFloat("z", 0.0f) / 2.0f); } else { m_vSecondarySpread.x = 0.0f; m_vSecondarySpread.y = 0.0f; m_vSecondarySpread.z = 0.0f; } KeyValues *pIronsightSpread2 = pBullet2->FindKey("IronsightSpread"); if (pIronsightSpread2) { m_vSecondaryIronsightSpread.x = sin((pIronsightSpread2->GetFloat("x", 0.0f) / 2.0f)); m_vSecondaryIronsightSpread.y = sin((pIronsightSpread2->GetFloat("y", 0.0f) / 2.0f)); m_vSecondaryIronsightSpread.z = sin((pIronsightSpread2->GetFloat("z", 0.0f) / 2.0f)); } else { m_vSecondaryIronsightSpread.x = m_vSecondarySpread.x; m_vSecondaryIronsightSpread.y = m_vSecondarySpread.y; m_vSecondaryIronsightSpread.z = m_vSecondarySpread.z; } KeyValues *pZoomSpread2 = pBullet2->FindKey("ZoomSpread"); if (pZoomSpread2) { m_vSecondaryZoomSpread.x = sin((pZoomSpread2->GetFloat("x", 0.0f) / 2.0f)); m_vSecondaryZoomSpread.y = sin((pZoomSpread2->GetFloat("y", 0.0f) / 2.0f)); m_vSecondaryZoomSpread.z = sin((pZoomSpread2->GetFloat("z", 0.0f) / 2.0f)); } else { m_vSecondaryZoomSpread.x = m_vSecondarySpread.x; m_vSecondaryZoomSpread.y = m_vSecondarySpread.y; m_vSecondaryZoomSpread.z = m_vSecondarySpread.z; } } else { m_sSecondaryDamage = 0.0f; m_sSecondaryShotCount = 0; m_sSecondaryBulletEnabled = false; } KeyValues *pMissle2 = pSecondaryFire->FindKey("Missle"); if (pMissle2) //No params yet, but setting this will enable missles { m_sSecondaryMissleEnabled = true; m_sSecondaryHasRecoilRPGMissle = (pMissle2->GetInt("UseRecoil", 1) != 0) ? true : false; } else { m_sSecondaryMissleEnabled = false; } KeyValues *pSMGGrenade2 = pSecondaryFire->FindKey("SMGGrenade"); if (pSMGGrenade2) //No params yet, but setting this will enable missles { m_sSecondarySMGGrenadeEnabled = true; m_sSMGGrenadeSecondaryDamage = pSMGGrenade2->GetFloat("Damage", 0); m_sSecondaryHasRecoilSMGGrenade = (pSMGGrenade2->GetInt("UseRecoil", 1) != 0) ? true : false; } else { m_sSecondarySMGGrenadeEnabled = false; m_sSMGGrenadeSecondaryDamage = 0.0; } KeyValues *pAR2EnergyBall2 = pSecondaryFire->FindKey("AR2EnergyBall"); if (pAR2EnergyBall2) //No params yet, but setting this will enable missles { m_sSecondaryAR2EnergyBallEnabled = true; m_sSecondaryCombineBallRadius = pAR2EnergyBall2->GetFloat("Radius", 0); m_sSecondaryCombineBallMass = pAR2EnergyBall2->GetFloat("Mass", 0); m_sSecondaryCombineBallDuration = pAR2EnergyBall2->GetFloat("Duration", 0); } else { m_sSecondaryAR2EnergyBallEnabled = false; m_sSecondaryCombineBallRadius = 0.0; m_sSecondaryCombineBallMass = 0.0; m_sSecondaryCombineBallDuration = 0.0; } KeyValues *pRecoil2 = pSecondaryFire->FindKey("Recoil"); if (pRecoil2) //No params yet, but setting this will enable missles { m_sSecondaryRecoilEasyDampen = pRecoil2->GetFloat("EasyDampen", 0); m_sSecondaryRecoilDegrees = pRecoil2->GetFloat("Degrees", 0); m_sSecondaryRecoilSeconds = pRecoil2->GetFloat("Seconds", 0); } else { m_sSecondaryRecoilEasyDampen = 0.0; m_sSecondaryRecoilDegrees = 0.0; m_sSecondaryRecoilSeconds = 0.0; } } else { m_sHasSecondaryFire = false; } KeyValues *pMeleeOptions = pWeaponSpec->FindKey("Melee"); if (pMeleeOptions) { m_sHasMeleeOptions = true; m_sMeleeDamage = pMeleeOptions->GetFloat("Damage", 0); m_sMeleeRange = pMeleeOptions->GetFloat("Range", 0); KeyValues *pRecoilM = pMeleeOptions->FindKey("Kick"); if (pRecoilM) //No params yet, but setting this will enable missles { m_sMeleeKickEasyDampen = pRecoilM->GetFloat("EasyDampen", 0); m_sMeleeKickDegrees = pRecoilM->GetFloat("Degrees", 0); m_sMeleeKickSeconds = pRecoilM->GetFloat("Seconds", 0); } else { m_sMeleeKickEasyDampen = 0.0; m_sMeleeKickDegrees = 0.0; m_sMeleeKickSeconds = 0.0; } } else { m_sHasMeleeOptions = false; } KeyValues *pZoom = pWeaponSpec->FindKey("Zoom"); if (pZoom) { m_sUsesZoom = true; m_sUseZoomOnPrimaryFire = (pZoom->GetInt("UseOnPrimaryFire", 1) != 0) ? true : false; m_sUsesZoomSound = (pZoom->GetInt("UsesSound", 1) != 0) ? true : false; m_sUsesZoomColor = (pZoom->GetInt("UsesColor", 1) != 0) ? true : false; KeyValues *pZoomColor = pZoom->FindKey("ZoomColor"); { if (pZoomColor) { m_sZoomColorRed = pZoomColor->GetInt("Red", 0); m_sZoomColorGreen = pZoomColor->GetInt("Green", 0); m_sZoomColorBlue = pZoomColor->GetInt("Blue", 0); m_sZoomColorAlpha = pZoomColor->GetInt("Alpha", 0); } } } else { m_sUsesZoom = false; } KeyValues *pCustomization = pWeaponSpec->FindKey("Customization"); if (pCustomization) { m_sUsesCustomization = true; m_sWeaponSkin = pCustomization->GetInt("Skin", 0); KeyValues *pBodygroup1 = pWeaponSpec->FindKey("Bodygroup1"); { if (pBodygroup1) { m_sBodygroup1 = pBodygroup1->GetInt("Bodygroup", 0); m_sSubgroup1 = pBodygroup1->GetInt("Subgroup", 0); } } KeyValues *pBodygroup2 = pWeaponSpec->FindKey("Bodygroup2"); { if (pBodygroup2) { m_sBodygroup2 = pBodygroup2->GetInt("Bodygroup", 0); m_sSubgroup2 = pBodygroup2->GetInt("Subgroup", 0); } } KeyValues *pBodygroup3 = pWeaponSpec->FindKey("Bodygroup3"); { if (pBodygroup3) { m_sBodygroup3 = pBodygroup3->GetInt("Bodygroup", 0); m_sSubgroup3 = pBodygroup3->GetInt("Subgroup", 0); } } KeyValues *pBodygroup4 = pWeaponSpec->FindKey("Bodygroup4"); { if (pBodygroup4) { m_sBodygroup4 = pBodygroup4->GetInt("Bodygroup", 0); m_sSubgroup4 = pBodygroup4->GetInt("Subgroup", 0); } } KeyValues *pBodygroup5 = pWeaponSpec->FindKey("Bodygroup5"); { if (pBodygroup5) { m_sBodygroup5 = pBodygroup5->GetInt("Bodygroup", 0); m_sSubgroup5 = pBodygroup5->GetInt("Subgroup", 0); } } KeyValues *pBodygroup6 = pWeaponSpec->FindKey("Bodygroup6"); { if (pBodygroup6) { m_sBodygroup6 = pBodygroup6->GetInt("Bodygroup", 0); m_sSubgroup6 = pBodygroup6->GetInt("Subgroup", 0); } } } else { m_sUsesCustomization = false; } } // Now read the weapon sounds memset( aShootSounds, 0, sizeof( aShootSounds ) ); KeyValues *pSoundData = pKeyValuesData->FindKey( "SoundData" ); if ( pSoundData ) { for ( int i = EMPTY; i < NUM_SHOOT_SOUND_TYPES; i++ ) { const char *soundname = pSoundData->GetString( pWeaponSoundCategories[i] ); if ( soundname && soundname[0] ) { Q_strncpy( aShootSounds[i], soundname, MAX_WEAPON_STRING ); } } } }
int CPhysicsSurfaceProps::ParseSurfaceData(const char* pFilename, const char* pTextfile) { if (!AddFileToDatabase(pFilename)) return 0; KeyValues* surfprops = new KeyValues(""); surfprops->LoadFromBuffer(pFilename, pTextfile); for (KeyValues* surface = surfprops; surface; surface = surface->GetNextKey()) { CSurface prop; int baseMaterial = GetSurfaceIndex("default"); memset(&prop.data, 0, sizeof(prop.data)); prop.m_name = m_strings->AddString(surface->GetName()); prop.data.game.material = 0; prop.data.game.maxSpeedFactor = 1.0f; prop.data.game.jumpFactor = 1.0f; prop.data.game.climbable = 0.0f; CopyPhysicsProperties(&prop, baseMaterial); for (KeyValues* data = surface->GetFirstSubKey(); data; data = data->GetNextKey()) { const char* key = data->GetName(); if (!strcmpi(key, "base")) { baseMaterial = GetSurfaceIndex(data->GetString()); CopyPhysicsProperties(&prop, baseMaterial); } else if (!strcmpi(key, "thickness")) { prop.data.physics.thickness = data->GetFloat(); } else if (!strcmpi(key, "density")) { prop.data.physics.density = data->GetFloat(); } else if (!strcmpi(key, "elasticity")) { prop.data.physics.elasticity = data->GetFloat(); } else if (!strcmpi(key, "friction")) { prop.data.physics.friction = data->GetFloat(); } else if (!strcmpi(key, "dampening")) { prop.data.physics.dampening = data->GetFloat(); } else if (!strcmpi(key, "audioreflectivity")) { prop.data.audio.reflectivity = data->GetFloat(); } else if (!strcmpi(key, "audiohardnessfactor")) { prop.data.audio.hardnessFactor = data->GetFloat(); } else if (!strcmpi(key, "audioroughnessfactor")) { prop.data.audio.roughnessFactor = data->GetFloat(); } else if (!strcmpi(key, "scrapeRoughThreshold")) { prop.data.audio.roughThreshold = data->GetFloat(); } else if (!strcmpi(key, "impactHardThreshold")) { prop.data.audio.hardThreshold = data->GetFloat(); } else if (!strcmpi(key, "audioHardMinVelocity")) { prop.data.audio.hardVelocityThreshold = data->GetFloat(); } else if (!strcmpi(key, "maxspeedfactor")) { prop.data.game.maxSpeedFactor = data->GetFloat(); } else if (!strcmpi(key, "jumpfactor")) { prop.data.game.jumpFactor = data->GetFloat(); } else if (!strcmpi(key, "climbable")) { prop.data.game.climbable = data->GetInt(); } else if (!strcmpi(key, "gamematerial")) { if (data->GetDataType() == KeyValues::TYPE_STRING && strlen(data->GetString()) == 1) { prop.data.game.material = toupper(data->GetString()[0]); } else { prop.data.game.material = data->GetInt(); } } else if (!strcmpi(key, "stepleft")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.stepleft = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "stepright")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.stepright = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "impactsoft")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.impactSoft = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "impacthard")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.impactHard = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "scrapesmooth")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.scrapeSmooth = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "scraperough")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.scrapeRough = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "bulletimpact")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.bulletImpact = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "break")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.breakSound = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "strain")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.strainSound = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "rolling")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.rolling = m_soundList.AddToTail(sym); } else { AssertMsg2(0, "Bad surfaceprop key %s (%s)\n", key, data->GetString()); } } if (GetSurfaceIndex(m_strings->String(prop.m_name)) >= 0) break; m_props.AddToTail(prop); } surfprops->deleteThis(); return 0; }
//----------------------------------------------------------------------------- // Parses the key-value pairs in the detail.rad file //----------------------------------------------------------------------------- static void ParseDetailGroup( int detailId, KeyValues* pGroupKeyValues ) { // Sort the group by alpha float alpha = pGroupKeyValues->GetFloat( "alpha", 1.0f ); int i = s_DetailObjectDict[detailId].m_Groups.Count(); while ( --i >= 0 ) { if (alpha > s_DetailObjectDict[detailId].m_Groups[i].m_Alpha) break; } // Insert after the first guy who's more transparent that we are! i = s_DetailObjectDict[detailId].m_Groups.InsertAfter(i); DetailObjectGroup_t& group = s_DetailObjectDict[detailId].m_Groups[i]; group.m_Alpha = alpha; // Add in all the model groups KeyValues* pIter = pGroupKeyValues->GetFirstSubKey(); float totalAmount = 0.0f; while( pIter ) { if (pIter->GetFirstSubKey()) { int i = group.m_Models.AddToTail(); DetailModel_t &model = group.m_Models[i]; model.m_ModelName = pIter->GetString( "model", 0 ); if (model.m_ModelName != UTL_INVAL_SYMBOL) { model.m_Type = DETAIL_PROP_TYPE_MODEL; } else { const char *pSpriteData = pIter->GetString( "sprite", 0 ); if (pSpriteData) { model.m_Type = DETAIL_PROP_TYPE_SPRITE; model.m_Tex[0].Init(); model.m_Tex[1].Init(); float x = 0, y = 0, flWidth = 64, flHeight = 64, flTextureSize = 512; int nValid = sscanf( pSpriteData, "%f %f %f %f %f", &x, &y, &flWidth, &flHeight, &flTextureSize ); if ( (nValid != 5) || (flTextureSize == 0) ) { Error( "Invalid arguments to \"sprite\" in detail.vbsp!\n" ); } model.m_Tex[0].x = ( x + 0.5f ) / flTextureSize; model.m_Tex[0].y = ( y + 0.5f ) / flTextureSize; model.m_Tex[1].x = ( x + flWidth - 0.5f ) / flTextureSize; model.m_Tex[1].y = ( y + flHeight - 0.5f ) / flTextureSize; model.m_Pos[0].Init( -10, 20 ); model.m_Pos[1].Init( 10, 0 ); pSpriteData = pIter->GetString( "spritesize", 0 ); if (pSpriteData) { sscanf( pSpriteData, "%f %f %f %f", &x, &y, &flWidth, &flHeight ); float ox = flWidth * x; float oy = flHeight * y; model.m_Pos[0].x = -ox; model.m_Pos[0].y = flHeight - oy; model.m_Pos[1].x = flWidth - ox; model.m_Pos[1].y = -oy; } model.m_flRandomScaleStdDev = pIter->GetFloat( "spriterandomscale", 0.0f ); } } model.m_Amount = pIter->GetFloat( "amount", 1.0 ) + totalAmount; totalAmount = model.m_Amount; model.m_Flags = 0; if (pIter->GetInt( "upright", 0 )) { model.m_Flags |= MODELFLAG_UPRIGHT; } // These are used to prevent emission on steep surfaces float minAngle = pIter->GetFloat( "minAngle", 180 ); float maxAngle = pIter->GetFloat( "maxAngle", 180 ); model.m_MinCosAngle = cos(minAngle * M_PI / 180.f); model.m_MaxCosAngle = cos(maxAngle * M_PI / 180.f); model.m_Orientation = pIter->GetInt( "detailOrientation", 0 ); // Make sure minAngle < maxAngle if ( model.m_MinCosAngle < model.m_MaxCosAngle) { model.m_MinCosAngle = model.m_MaxCosAngle; } } pIter = pIter->GetNextKey(); } // renormalize the amount if the total > 1 if (totalAmount > 1.0f) { for (i = 0; i < group.m_Models.Count(); ++i) { group.m_Models[i].m_Amount /= totalAmount; } } }
void CWeapons::LoadWeapons(const char *szWeaponListName, WeaponsData_t *pDefault) { if ((szWeaponListName != NULL) && (szWeaponListName[0] != 0)) { KeyValues *kv = new KeyValues("Weapons"); char szFilename[1024]; CBotGlobals::BuildFileName(szFilename, "weapons", BOT_CONFIG_FOLDER, "ini", false); if (kv) { if (kv->LoadFromFile(filesystem, szFilename, NULL)) { kv = kv->FindKey(szWeaponListName); if (kv) { kv = kv->GetFirstSubKey(); if (0) kv = kv->GetFirstTrueSubKey(); while (kv != NULL) { WeaponsData_t newWeapon; memset(&newWeapon, 0, sizeof(WeaponsData_t)); const char *szKeyName = kv->GetName(); char lowered[64]; strncpy(lowered, szKeyName, 63); lowered[63] = 0; __strlow(lowered); newWeapon.szWeaponName = CStrings::GetString(lowered); newWeapon.iId = kv->GetInt("id"); newWeapon.iSlot = kv->GetInt("slot"); newWeapon.minPrimDist = kv->GetFloat("minPrimDist"); newWeapon.maxPrimDist = kv->GetFloat("maxPrimDist"); newWeapon.m_fProjSpeed = kv->GetFloat("m_fProjSpeed"); newWeapon.m_iAmmoIndex = kv->GetInt("m_iAmmoIndex"); newWeapon.m_iPreference = kv->GetInt("m_iPreference"); KeyValues *flags = kv->FindKey("flags"); if (flags) { int i = 0; while (szWeaponFlags[i][0] != '\0') { if (flags->FindKey(szWeaponFlags[i]) && (flags->GetInt(szWeaponFlags[i]) == 1)) newWeapon.m_iFlags |= (1 << i); i++; } } AddWeapon(new CWeapon(&newWeapon)); kv = kv->GetNextTrueSubKey(); } } } kv->deleteThis(); } } if (pDefault != NULL) { // No weapons from INI file then add default if (m_theWeapons.size() == 0) { while (pDefault->szWeaponName[0] != '\0') { AddWeapon(new CWeapon(pDefault)); pDefault++; } } } }
bool CMapAdd::RunLabel( const char *mapaddMap, const char *szLabel) { if(AllocPooledString(mapaddMap) == AllocPooledString("") || !mapaddMap || !szLabel || AllocPooledString(szLabel) == AllocPooledString("")) return false; //Failed to load! //FileHandle_t fh = filesystem->Open(szMapadd,"r","MOD"); // Open the mapadd data file, and abort if we can't KeyValues *pMapAdd = new KeyValues( "MapAdd" ); if(pMapAdd->LoadFromFile( filesystem, mapaddMap, "MOD" )) { KeyValues *pMapAdd2 = pMapAdd->FindKey(szLabel); if(pMapAdd2) { KeyValues *pMapAddEnt = pMapAdd2->GetFirstTrueSubKey(); while (pMapAddEnt) { if(!HandlePlayerEntity(pMapAddEnt, false) && !HandleRemoveEnitity( pMapAddEnt ) && !HandleSMODEntity(pMapAddEnt) && !HandleSpecialEnitity(pMapAddEnt)) { Vector SpawnVector = Vector(0,0,0); QAngle SpawnAngle = QAngle(0,0,0); SpawnVector.x = pMapAddEnt->GetFloat("x", SpawnVector.x); SpawnVector.y = pMapAddEnt->GetFloat("y", SpawnVector.y); SpawnVector.z = pMapAddEnt->GetFloat("z", SpawnVector.z); SpawnAngle[PITCH] = pMapAddEnt->GetFloat("pitch", SpawnAngle[PITCH]); SpawnAngle[YAW] = pMapAddEnt->GetFloat("yaw", SpawnAngle[YAW]); SpawnAngle[ROLL] = pMapAddEnt->GetFloat("roll", SpawnAngle[ROLL]); CBaseEntity *createEnt = CBaseEntity::CreateNoSpawn(pMapAddEnt->GetName(),SpawnVector,SpawnAngle); KeyValues *pEntKeyValues = pMapAddEnt->FindKey("KeyValues"); if(pEntKeyValues && createEnt) { Msg("keyvalue for %s Found!\n",pMapAddEnt->GetName()); KeyValues *pEntKeyValuesAdd = pEntKeyValues->GetFirstValue(); while(pEntKeyValuesAdd && createEnt) { if(AllocPooledString(pEntKeyValuesAdd->GetName()) == AllocPooledString("model")) { PrecacheModel(pEntKeyValuesAdd->GetString("")); createEnt->SetModel(pEntKeyValuesAdd->GetString("")); } /* else if(AllocPooledString(pEntKeyValuesAdd->GetName()) == AllocPooledString("name")) { createEnt->SetName(AllocPooledString(pEntKeyValuesAdd->GetString(""))); } else if(AllocPooledString(pEntKeyValuesAdd->GetName()) == AllocPooledString("spawnflags")) { createEnt->AddSpawnFlags(pEntKeyValuesAdd->GetInt()); }*/ else { createEnt->KeyValue(pEntKeyValuesAdd->GetName(),pEntKeyValuesAdd->GetString("")); } pEntKeyValuesAdd = pEntKeyValuesAdd->GetNextValue(); } } //createEnt->Activate();//Is this a good idea? Not sure! //createEnt->Spawn(); DispatchSpawn( createEnt ); //I derped } pMapAddEnt = pMapAddEnt->GetNextTrueSubKey(); //Got to keep this! } } } pMapAdd->deleteThis(); return true; }
BasicShaderCfg_t *BuildShaderData( const char *dumpFileName ) { KeyValues *pKV = new KeyValues( dumpFileName ); char _path[MAX_PATH]; Q_snprintf( _path, MAX_PATH, "%s/%s.dump", ::GetDumpDirectory(), dumpFileName ); Q_FixSlashes( _path ); pKV->LoadFromFile( g_pFullFileSystem, _path, "MOD" ); BasicShaderCfg_t *data = new BasicShaderCfg_t(); const char *szT = pKV->GetString( "vs_name" ); int len = Q_strlen( szT ) + 1; data->ProcVSName = new char[ len ]; Q_snprintf( data->ProcVSName, len, "%s", szT ); szT = pKV->GetString( "ps_name" ); len = Q_strlen( szT ) + 1; data->ProcPSName = new char[ len ]; Q_snprintf( data->ProcPSName, len, "%s", szT ); szT = pKV->GetString( "shader_filename" ); len = Q_strlen( szT ) + 1; data->Filename = new char[ len ]; Q_snprintf( data->Filename, len, "%s", szT ); Q_FixSlashes( data->Filename ); szT = pKV->GetName(); len = Q_strlen( szT ) + 1; data->CanvasName = new char[ len ]; Q_snprintf( data->CanvasName, len, "%s", szT ); Q_snprintf( data->dumpversion, sizeof(data->dumpversion), "%s", pKV->GetString( GetDumpVersion_KeyName() ) ); data->iShaderModel = pKV->GetInt( "i_sm" ); data->iCullmode = pKV->GetInt( "i_cull" ); data->iAlphablendmode = pKV->GetInt( "i_ablend" ); data->flAlphaTestRef = pKV->GetFloat( "fl_atestref" ); data->iDepthtestmode = pKV->GetInt( "i_dtest" ); data->iDepthwritemode = pKV->GetInt( "i_dwrite" ); data->bsRGBWrite = !!pKV->GetInt( "i_srgbw" ); data->iVFMT_flags = pKV->GetInt( "i_vfmt_flags" ); data->iVFMT_numTexcoords = pKV->GetInt( "i_vfmt_texcoords" ); data->iVFMT_numUserData = pKV->GetInt( "i_vfmt_udata" ); for ( int i = 0; i < 3; i++ ) { char tmp[48]; Q_snprintf( tmp, sizeof(tmp), "i_vfmt_texcoordDim_%i", i ); data->iVFMT_texDim[i] = pKV->GetInt( tmp, GetVarFlagsVarValue( HLSLVAR_FLOAT2 ) + 1 ); } data->bVertexLighting = !!pKV->GetInt( "i_vlit" ); data->bRefractionSupport = !!pKV->GetInt( "i_vrefract" ); KeyValues *pSubIdent_VS = pKV->FindKey( "identifiers_VS" ); if ( pSubIdent_VS ) ReadIdents( *data->pVS_Identifiers, pSubIdent_VS ); KeyValues *pSubIdent_PS = pKV->FindKey( "identifiers_PS" ); if ( pSubIdent_PS ) ReadIdents( *data->pPS_Identifiers, pSubIdent_PS ); pKV->deleteThis(); return data; }
void LoadObjectInfos( IBaseFileSystem *pFileSystem ) { const char *pFilename = "scripts/objects.txt"; // Make sure this stuff hasn't already been loaded. Assert( !AreObjectInfosLoaded() ); KeyValues *pValues = new KeyValues( "Object descriptions" ); if ( !pValues->LoadFromFile( pFileSystem, pFilename, "GAME" ) ) { Error( "Can't open %s for object info.", pFilename ); pValues->deleteThis(); return; } // Now read each class's information in. for ( int iObj=0; iObj < ARRAYSIZE( g_ObjectInfos ); iObj++ ) { CObjectInfo *pInfo = &g_ObjectInfos[iObj]; KeyValues *pSub = pValues->FindKey( pInfo->m_pObjectName ); if ( !pSub ) { Error( "Missing section '%s' from %s.", pInfo->m_pObjectName, pFilename ); pValues->deleteThis(); return; } // Read all the info in. if ( (pInfo->m_flBuildTime = pSub->GetFloat( "BuildTime", -999 )) == -999 || (pInfo->m_nMaxObjects = pSub->GetInt( "MaxObjects", -999 )) == -999 || (pInfo->m_Cost = pSub->GetInt( "Cost", -999 )) == -999 || (pInfo->m_CostMultiplierPerInstance = pSub->GetFloat( "CostMultiplier", -999 )) == -999 || (pInfo->m_UpgradeCost = pSub->GetInt( "UpgradeCost", -999 )) == -999 || (pInfo->m_MaxUpgradeLevel = pSub->GetInt( "MaxUpgradeLevel", -999 )) == -999 || (pInfo->m_SelectionSlot = pSub->GetInt( "SelectionSlot", -999 )) == -999 || (pInfo->m_SelectionPosition = pSub->GetInt( "SelectionPosition", -999 )) == -999 ) { Error( "Missing data for object '%s' in %s.", pInfo->m_pObjectName, pFilename ); pValues->deleteThis(); return; } pInfo->m_pClassName = ReadAndAllocStringValue( pSub, "ClassName", pFilename ); pInfo->m_pStatusName = ReadAndAllocStringValue( pSub, "StatusName", pFilename ); pInfo->m_pBuilderWeaponName = ReadAndAllocStringValue( pSub, "BuilderWeaponName", pFilename ); pInfo->m_pBuilderPlacementString = ReadAndAllocStringValue( pSub, "BuilderPlacementString", pFilename ); pInfo->m_bSolidToPlayerMovement = pSub->GetInt( "SolidToPlayerMovement", 0 ) ? true : false; pInfo->m_pIconActive = ReadAndAllocStringValue( pSub, "IconActive", pFilename ); pInfo->m_pIconInactive = ReadAndAllocStringValue( pSub, "IconInactive", pFilename ); pInfo->m_pViewModel = ReadAndAllocStringValue( pSub, "Viewmodel", pFilename ); pInfo->m_pPlayerModel = ReadAndAllocStringValue( pSub, "Playermodel", pFilename ); pInfo->m_iDisplayPriority = pSub->GetInt( "DisplayPriority", 0 ); pInfo->m_pHudStatusIcon = ReadAndAllocStringValue( pSub, "HudStatusIcon", pFilename ); pInfo->m_bVisibleInWeaponSelection = ( pSub->GetInt( "VisibleInWeaponSelection", 1 ) > 0 ); pInfo->m_pExplodeSound = ReadAndAllocStringValue( pSub, "ExplodeSound", pFilename ); pInfo->m_pExplosionParticleEffect = ReadAndAllocStringValue( pSub, "ExplodeEffect", pFilename ); pInfo->m_bAutoSwitchTo = ( pSub->GetInt( "autoswitchto", 0 ) > 0 ); pInfo->m_iMetalToDropInGibs = pSub->GetInt( "MetalToDropInGibs", 0 ); } pValues->deleteThis(); }
void FileWeaponInfo_t::Parse( KeyValues *pKeyValuesData, const char *szWeaponName ) { // Okay, we tried at least once to look this up... bParsedScript = true; // Classname Q_strncpy( szClassName, szWeaponName, MAX_WEAPON_STRING ); // Printable name Q_strncpy( szPrintName, pKeyValuesData->GetString( "printname", WEAPON_PRINTNAME_MISSING ), MAX_WEAPON_STRING ); // View model & world model Q_strncpy( szViewModel, pKeyValuesData->GetString( "viewmodel" ), MAX_WEAPON_STRING ); Q_strncpy( szWorldModel, pKeyValuesData->GetString( "playermodel" ), MAX_WEAPON_STRING ); Q_strncpy( szClipModel, pKeyValuesData->GetString( "clipmodel" ), MAX_WEAPON_STRING ); Q_strncpy( szAnimationPrefix, pKeyValuesData->GetString( "anim_prefix" ), MAX_WEAPON_PREFIX ); iSlot = pKeyValuesData->GetInt( "bucket", 0 ); iPosition = pKeyValuesData->GetInt( "bucket_position", 0 ); iMaxClip1 = pKeyValuesData->GetInt( "clip_size", WEAPON_NOCLIP ); // Max primary clips gun can hold (assume they don't use clips by default) iMaxClip2 = pKeyValuesData->GetInt( "clip2_size", WEAPON_NOCLIP ); // Max secondary clips gun can hold (assume they don't use clips by default) iDefaultClip1 = pKeyValuesData->GetInt( "default_clip", iMaxClip1 ); // amount of primary ammo placed in the primary clip when it's picked up iDefaultClip2 = pKeyValuesData->GetInt( "default_clip2", iMaxClip2 ); // amount of secondary ammo placed in the secondary clip when it's picked up iWeight = pKeyValuesData->GetInt( "weight", 0 ); iRumbleEffect = pKeyValuesData->GetInt( "rumble", -1 ); // Viewmodel FOV flViewFov = pKeyValuesData->GetFloat( "view_fov", 0.0f ); // Bash DMG m_flBashDamage = pKeyValuesData->GetFloat("damage_bash", 1.0f); // LAME old way to specify item flags. // Weapon scripts should use the flag names. iFlags = pKeyValuesData->GetInt( "item_flags", ITEM_FLAG_LIMITINWORLD ); for ( int i=0; i < ARRAYSIZE( g_ItemFlags ); i++ ) { int iVal = pKeyValuesData->GetInt( g_ItemFlags[i].m_pFlagName, -1 ); if ( iVal == 0 ) { iFlags &= ~g_ItemFlags[i].m_iFlagValue; } else if ( iVal == 1 ) { iFlags |= g_ItemFlags[i].m_iFlagValue; } } bShowUsageHint = ( pKeyValuesData->GetInt( "showusagehint", 0 ) != 0 ) ? true : false; bAutoSwitchTo = ( pKeyValuesData->GetInt( "autoswitchto", 1 ) != 0 ) ? true : false; bAutoSwitchFrom = ( pKeyValuesData->GetInt( "autoswitchfrom", 1 ) != 0 ) ? true : false; m_bBuiltRightHanded = ( pKeyValuesData->GetInt( "BuiltRightHanded", 1 ) != 0 ) ? true : false; m_bAllowFlipping = ( pKeyValuesData->GetInt( "AllowFlipping", 1 ) != 0 ) ? true : false; m_bMeleeWeapon = ( pKeyValuesData->GetInt( "MeleeWeapon", 0 ) != 0 ) ? true : false; #if defined(_DEBUG) && defined(HL2_CLIENT_DLL) // make sure two weapons aren't in the same slot & position if ( iSlot >= MAX_WEAPON_SLOTS || iPosition >= MAX_WEAPON_POSITIONS ) { Warning( "Invalid weapon slot or position [slot %d/%d max], pos[%d/%d max]\n", iSlot, MAX_WEAPON_SLOTS - 1, iPosition, MAX_WEAPON_POSITIONS - 1 ); } else { if (g_bUsedWeaponSlots[iSlot][iPosition]) { Warning( "Duplicately assigned weapon slots in selection hud: %s (%d, %d)\n", szPrintName, iSlot, iPosition ); } g_bUsedWeaponSlots[iSlot][iPosition] = true; } #endif // Primary ammo used const char *pAmmo = pKeyValuesData->GetString( "primary_ammo", "None" ); if ( strcmp("None", pAmmo) == 0 ) Q_strncpy( szAmmo1, "", sizeof( szAmmo1 ) ); else Q_strncpy( szAmmo1, pAmmo, sizeof( szAmmo1 ) ); iAmmoType = GetAmmoDef()->Index( szAmmo1 ); // Secondary ammo used pAmmo = pKeyValuesData->GetString( "secondary_ammo", "None" ); if ( strcmp("None", pAmmo) == 0) Q_strncpy( szAmmo2, "", sizeof( szAmmo2 ) ); else Q_strncpy( szAmmo2, pAmmo, sizeof( szAmmo2 ) ); iAmmo2Type = GetAmmoDef()->Index( szAmmo2 ); // Ironsight KeyValues *pSights = pKeyValuesData->FindKey( "IronSight" ); if (pSights) { vecIronsightPosOffset.x = pSights->GetFloat( "forward", 0.0f ); vecIronsightPosOffset.y = pSights->GetFloat( "right", 0.0f ); vecIronsightPosOffset.z = pSights->GetFloat( "up", 0.0f ); angIronsightAngOffset[PITCH] = pSights->GetFloat( "pitch", 0.0f ); angIronsightAngOffset[YAW] = pSights->GetFloat( "yaw", 0.0f ); angIronsightAngOffset[ROLL] = pSights->GetFloat( "roll", 0.0f ); flIronsightFOVOffset = pSights->GetFloat( "fov", 0.0f ); } else { //note: you can set a bool here if you'd like to disable ironsights for weapons with no IronSight-key vecIronsightPosOffset = vec3_origin; angIronsightAngOffset.Init(); flIronsightFOVOffset = 0.0f; } // Now read the weapon sounds memset( aShootSounds, 0, sizeof( aShootSounds ) ); KeyValues *pSoundData = pKeyValuesData->FindKey( "SoundData" ); if ( pSoundData ) { for ( int i = EMPTY; i < NUM_SHOOT_SOUND_TYPES; i++ ) { const char *soundname = pSoundData->GetString( pWeaponSoundCategories[i] ); if ( soundname && soundname[0] ) { Q_strncpy( aShootSounds[i], soundname, MAX_WEAPON_STRING ); } } } }
//----------------------------------------------------------------------------- // Purpose: Gets the specified value from a panel //----------------------------------------------------------------------------- AnimationController::Value_t AnimationController::GetValue(ActiveAnimation_t& anim, Panel *panel, UtlSymId_t var) { Value_t val = { 0, 0, 0, 0 }; if (var == m_sPosition) { int x, y; panel->GetPos(x, y); val.a = (float)(x - GetRelativeOffset( anim.align, true ) ); val.b = (float)(y - GetRelativeOffset( anim.align, false ) ); } else if (var == m_sSize) { int w, t; panel->GetSize(w, t); val.a = (float)w; val.b = (float)t; } else if (var == m_sFgColor) { Color col = panel->GetFgColor(); val.a = col[0]; val.b = col[1]; val.c = col[2]; val.d = col[3]; } else if (var == m_sBgColor) { Color col = panel->GetBgColor(); val.a = col[0]; val.b = col[1]; val.c = col[2]; val.d = col[3]; } else if ( var == m_sXPos ) { int x, y; panel->GetPos(x, y); val.a = (float)( x - GetRelativeOffset( anim.align, true ) ); } else if ( var == m_sYPos ) { int x, y; panel->GetPos(x, y); val.a = (float)( y - GetRelativeOffset( anim.align, false ) ); } else if ( var == m_sWide ) { int w, h; panel->GetSize(w, h); val.a = (float)w; } else if ( var == m_sTall ) { int w, h; panel->GetSize(w, h); val.a = (float)h; } else { KeyValues *outputData = new KeyValues(g_ScriptSymbols.String(var)); if (panel->RequestInfo(outputData)) { // find the var and lookup it's type KeyValues *kv = outputData->FindKey(g_ScriptSymbols.String(var)); if (kv && kv->GetDataType() == KeyValues::TYPE_FLOAT) { val.a = kv->GetFloat(); val.b = 0.0f; val.c = 0.0f; val.d = 0.0f; } else if (kv && kv->GetDataType() == KeyValues::TYPE_COLOR) { Color col = kv->GetColor(); val.a = col[0]; val.b = col[1]; val.c = col[2]; val.d = col[3]; } } else { // Assert(!("Unhandlable var in AnimationController::GetValue())")); } outputData->deleteThis(); } return val; }
void LoadObjectInfos( IBaseFileSystem *pFileSystem ) { const char *pFilename = "scripts/objects.txt"; // Make sure this stuff hasn't already been loaded. Assert( !AreObjectInfosLoaded() ); KeyValues *pValues = new KeyValues( "Object descriptions" ); if ( !pValues->LoadFromFile( pFileSystem, pFilename, "GAME" ) ) { Error( "Can't open %s for object info.", pFilename ); pValues->deleteThis(); return; } // Now read each class's information in. for ( int iObj=0; iObj < ARRAYSIZE( g_ObjectInfos ); iObj++ ) { CObjectInfo *pInfo = &g_ObjectInfos[iObj]; KeyValues *pSub = pValues->FindKey( pInfo->m_pObjectName ); if ( !pSub ) { Error( "Missing section '%s' from %s.", pInfo->m_pObjectName, pFilename ); pValues->deleteThis(); return; } // Read all the info in. if ( (pInfo->m_flBuildTime = pSub->GetFloat( "BuildTime", -999 )) == -999 || (pInfo->m_nMaxObjects = pSub->GetInt( "MaxObjects", -999 )) == -999 || (pInfo->m_Cost = pSub->GetInt( "Cost", -999 )) == -999 || (pInfo->m_CostMultiplierPerInstance = pSub->GetFloat( "CostMultiplier", -999 )) == -999 || (pInfo->m_UpgradeCost = pSub->GetInt( "UpgradeCost", -999 )) == -999 || (pInfo->m_flUpgradeDuration = pSub->GetFloat( "UpgradeDuration", -999)) == -999 || (pInfo->m_MaxUpgradeLevel = pSub->GetInt( "MaxUpgradeLevel", -999 )) == -999 || (pInfo->m_SelectionSlot = pSub->GetInt( "SelectionSlot", -999 )) == -999 || (pInfo->m_BuildCount = pSub->GetInt( "BuildCount", -999 )) == -999 || (pInfo->m_SelectionPosition = pSub->GetInt( "SelectionPosition", -999 )) == -999 ) { Error( "Missing data for object '%s' in %s.", pInfo->m_pObjectName, pFilename ); pValues->deleteThis(); return; } pInfo->m_pClassName = ReadAndAllocStringValue( pSub, "ClassName", pFilename ); pInfo->m_pStatusName = ReadAndAllocStringValue( pSub, "StatusName", pFilename ); pInfo->m_pBuilderWeaponName = ReadAndAllocStringValue( pSub, "BuilderWeaponName", pFilename ); pInfo->m_pBuilderPlacementString = ReadAndAllocStringValue( pSub, "BuilderPlacementString", pFilename ); pInfo->m_bSolidToPlayerMovement = pSub->GetInt( "SolidToPlayerMovement", 0 ) ? true : false; pInfo->m_pIconActive = ReadAndAllocStringValue( pSub, "IconActive", pFilename ); pInfo->m_pIconInactive = ReadAndAllocStringValue( pSub, "IconInactive", pFilename ); pInfo->m_pIconMenu = ReadAndAllocStringValue( pSub, "IconMenu", pFilename ); pInfo->m_bUseItemInfo = pSub->GetInt( "UseItemInfo", 0 ) ? true : false; pInfo->m_pViewModel = ReadAndAllocStringValue( pSub, "Viewmodel", pFilename ); pInfo->m_pPlayerModel = ReadAndAllocStringValue( pSub, "Playermodel", pFilename ); pInfo->m_iDisplayPriority = pSub->GetInt( "DisplayPriority", 0 ); pInfo->m_pHudStatusIcon = ReadAndAllocStringValue( pSub, "HudStatusIcon", pFilename ); pInfo->m_bVisibleInWeaponSelection = ( pSub->GetInt( "VisibleInWeaponSelection", 1 ) > 0 ); pInfo->m_pExplodeSound = ReadAndAllocStringValue( pSub, "ExplodeSound", pFilename ); pInfo->m_pUpgradeSound = ReadAndAllocStringValue( pSub, "UpgradeSound", pFilename ); pInfo->m_pExplosionParticleEffect = ReadAndAllocStringValue( pSub, "ExplodeEffect", pFilename ); pInfo->m_bAutoSwitchTo = ( pSub->GetInt( "autoswitchto", 0 ) > 0 ); pInfo->m_iMetalToDropInGibs = pSub->GetInt( "MetalToDropInGibs", 0 ); pInfo->m_bRequiresOwnBuilder = pSub->GetBool( "RequiresOwnBuilder", 0 ); // PistonMiner: Added Object Mode key KeyValues *pAltModes = pSub->FindKey("AltModes"); if (pAltModes) { for (int i = 0; i < 4; ++i) // load at most 4 object modes { char altModeBuffer[256]; // Max size of 0x100 V_snprintf(altModeBuffer, ARRAYSIZE(altModeBuffer), "AltMode%d", i); KeyValues *pCurAltMode = pAltModes->FindKey(altModeBuffer); if (!pCurAltMode) break; // Save logic here pInfo->m_AltModes.AddToTail(ReadAndAllocStringValue( pCurAltMode, "StatusName", pFilename )); pInfo->m_AltModes.AddToTail(ReadAndAllocStringValue( pCurAltMode, "ModeName", pFilename )); pInfo->m_AltModes.AddToTail(ReadAndAllocStringValue( pCurAltMode, "IconMenu", pFilename )); } } } pValues->deleteThis(); }
//----------------------------------------------------------------------------- // Parses the key-value pairs in the detail.rad file //----------------------------------------------------------------------------- static void ParseDetailGroup( int detailId, KeyValues* pGroupKeyValues ) { // Sort the group by alpha float alpha = pGroupKeyValues->GetFloat( "alpha", 1.0f ); int i = s_DetailObjectDict[detailId].m_Groups.Count(); while ( --i >= 0 ) { if (alpha > s_DetailObjectDict[detailId].m_Groups[i].m_Alpha) break; } // Insert after the first guy who's more transparent that we are! i = s_DetailObjectDict[detailId].m_Groups.InsertAfter(i); DetailObjectGroup_t& group = s_DetailObjectDict[detailId].m_Groups[i]; group.m_Alpha = alpha; // Add in all the model groups KeyValues* pIter = pGroupKeyValues->GetFirstSubKey(); float totalAmount = 0.0f; while( pIter ) { if (pIter->GetFirstSubKey()) { int i = group.m_Models.AddToTail(); DetailModel_t &model = group.m_Models[i]; model.m_ModelName = pIter->GetString( "model", 0 ); if (model.m_ModelName != UTL_INVAL_SYMBOL) { model.m_Type = DETAIL_PROP_TYPE_MODEL; } else { const char *pSpriteData = pIter->GetString( "sprite", 0 ); if (pSpriteData) { const char *pProcModelType = pIter->GetString( "sprite_shape", 0 ); if ( pProcModelType ) { if ( !Q_stricmp( pProcModelType, "cross" ) ) { model.m_Type = DETAIL_PROP_TYPE_SHAPE_CROSS; } else if ( !Q_stricmp( pProcModelType, "tri" ) ) { model.m_Type = DETAIL_PROP_TYPE_SHAPE_TRI; } else model.m_Type = DETAIL_PROP_TYPE_SPRITE; } else { // card sprite model.m_Type = DETAIL_PROP_TYPE_SPRITE; } model.m_Tex[0].Init(); model.m_Tex[1].Init(); float x = 0, y = 0, flWidth = 64, flHeight = 64, flTextureSize = 512; int nValid = sscanf( pSpriteData, "%f %f %f %f %f", &x, &y, &flWidth, &flHeight, &flTextureSize ); if ( (nValid != 5) || (flTextureSize == 0) ) { Error( "Invalid arguments to \"sprite\" in detail.vbsp (model %s)!\n", model.m_ModelName ); } model.m_Tex[0].x = ( x + 0.5f ) / flTextureSize; model.m_Tex[0].y = ( y + 0.5f ) / flTextureSize; model.m_Tex[1].x = ( x + flWidth - 0.5f ) / flTextureSize; model.m_Tex[1].y = ( y + flHeight - 0.5f ) / flTextureSize; model.m_Pos[0].Init( -10, 20 ); model.m_Pos[1].Init( 10, 0 ); pSpriteData = pIter->GetString( "spritesize", 0 ); if (pSpriteData) { sscanf( pSpriteData, "%f %f %f %f", &x, &y, &flWidth, &flHeight ); float ox = flWidth * x; float oy = flHeight * y; model.m_Pos[0].x = -ox; model.m_Pos[0].y = flHeight - oy; model.m_Pos[1].x = flWidth - ox; model.m_Pos[1].y = -oy; } model.m_flRandomScaleStdDev = pIter->GetFloat( "spriterandomscale", 0.0f ); // sway is a percent of max sway, cl_detail_max_sway float flSway = clamp( pIter->GetFloat( "sway", 0.0f ), 0.0, 1.0 ); model.m_SwayAmount = (unsigned char)( 255.0 * flSway ); // shape angle // for the tri shape, this is the angle each side is fanned out model.m_ShapeAngle = pIter->GetInt( "shape_angle", 0 ); // shape size // for the tri shape, this is the distance from the origin to the center of a side float flShapeSize = clamp( pIter->GetFloat( "shape_size", 0.0f ), 0.0, 1.0 ); model.m_ShapeSize = (unsigned char)( 255.0 * flShapeSize ); } } model.m_Amount = pIter->GetFloat( "amount", 1.0 ) + totalAmount; totalAmount = model.m_Amount; model.m_Flags = 0; if (pIter->GetInt( "upright", 0 )) { model.m_Flags |= MODELFLAG_UPRIGHT; } // These are used to prevent emission on steep surfaces float minAngle = pIter->GetFloat( "minAngle", 180 ); float maxAngle = pIter->GetFloat( "maxAngle", 180 ); model.m_MinCosAngle = cos(minAngle * M_PI / 180.f); model.m_MaxCosAngle = cos(maxAngle * M_PI / 180.f); model.m_Orientation = pIter->GetInt( "detailOrientation", 0 ); // Make sure minAngle < maxAngle if ( model.m_MinCosAngle < model.m_MaxCosAngle) { model.m_MinCosAngle = model.m_MaxCosAngle; } } pIter = pIter->GetNextKey(); } // renormalize the amount if the total > 1 if (totalAmount > 1.0f) { for (i = 0; i < group.m_Models.Count(); ++i) { group.m_Models[i].m_Amount /= totalAmount; } } }
void ControlPanel::CenterOnFace( void ) { if ( !models->GetActiveStudioModel() ) return; StudioModel *mdl = models->GetActiveStudioModel(); if ( !mdl ) return; CStudioHdr *hdr = mdl->GetStudioHdr(); if ( !hdr ) return; setSpeed( 1.0f ); int oldSeq = models->GetActiveStudioModel()->GetSequence(); int seq = models->GetActiveStudioModel()->LookupSequence( "idle_suble" ); if ( seq == -1 ) seq = 0; if ( seq != oldSeq ) { Con_Printf( "Centering changed model sequence # to %d\n", seq ); } setSequence( seq ); initPoseParameters( ); mdl->m_angles.Init(); mdl->m_origin.Init(); Vector size; VectorSubtract( hdr->hull_max(), hdr->hull_min(), size ); float eyeheight = hdr->hull_min().z + 0.9 * size.z; if ( hdr->GetNumAttachments() > 0 ) { for (int i = 0; i < hdr->GetNumAttachments(); i++) { const mstudioattachment_t &attachment = hdr->pAttachment( i ); int iBone = hdr->GetAttachmentBone( i ); if ( Q_stricmp( attachment.pszName(), "eyes" ) ) continue; mstudiobone_t *bone = hdr->pBone( iBone ); if ( !bone ) continue; matrix3x4_t boneToPose; MatrixInvert( bone->poseToBone, boneToPose ); matrix3x4_t attachmentPoseToLocal; ConcatTransforms( boneToPose, attachment.local, attachmentPoseToLocal ); Vector localSpaceEyePosition; VectorITransform( vec3_origin, attachmentPoseToLocal, localSpaceEyePosition ); // Not sure why this must be negative? eyeheight = -localSpaceEyePosition.z + hdr->hull_min().z; break; } } KeyValues *seqKeyValues = new KeyValues(""); if ( seqKeyValues->LoadFromBuffer( mdl->GetFileName( ), mdl->GetKeyValueText( seq ) ) ) { // Do we have a build point section? KeyValues *pkvAllFaceposer = seqKeyValues->FindKey("faceposer"); if ( pkvAllFaceposer ) { float flEyeheight = pkvAllFaceposer->GetFloat( "eye_height", -9999.0f ); if ( flEyeheight != -9999.0f ) { eyeheight = flEyeheight; } } } seqKeyValues->deleteThis(); mdl->m_origin.x = size.z * .65f; mdl->m_origin.z += eyeheight; CUtlVector< StudioModel * > modellist; modellist.AddToTail( models->GetActiveStudioModel() ); int i; if ( models->CountVisibleModels() > 0 ) { modellist.RemoveAll(); for ( i = 0; i < models->Count(); i++ ) { if ( models->IsModelShownIn3DView( i ) ) { modellist.AddToTail( models->GetStudioModel( i ) ); } } } int modelcount = modellist.Count(); int countover2 = modelcount / 2; int ydelta = GetModelGap(); int yoffset = -countover2 * ydelta; for ( i = 0 ; i < modelcount; i++ ) { if ( models->GetStudioHeader( i ) == hdr ) { mdl->m_origin.y = -yoffset; } yoffset += ydelta; } g_pMatSysWindow->redraw(); }
void FileWeaponInfo_t::Parse( KeyValues *pKeyValuesData, const char *szWeaponName ) { // Okay, we tried at least once to look this up... bParsedScript = true; // Classname Q_strncpy(szClassName, szWeaponName, MAX_WEAPON_STRING); // Printable name Q_strncpy(szPrintName, pKeyValuesData->GetString("printname", WEAPON_PRINTNAME_MISSING), MAX_WEAPON_STRING); // View model & world model Q_strncpy(szViewModel, pKeyValuesData->GetString("viewmodel"), MAX_WEAPON_STRING); Q_strncpy(szWorldModel, pKeyValuesData->GetString("playermodel"), MAX_WEAPON_STRING); Q_strncpy(szAnimationPrefix, pKeyValuesData->GetString("anim_prefix"), MAX_WEAPON_PREFIX); iSlot = pKeyValuesData->GetInt("bucket", 0); iPosition = pKeyValuesData->GetInt("bucket_position", 0); // Use the console (X360) buckets if hud_fastswitch is set to 2. #ifdef CLIENT_DLL if (hud_fastswitch.GetInt() == 2) #else if (IsX360()) #endif { iSlot = pKeyValuesData->GetInt("bucket_360", iSlot); iPosition = pKeyValuesData->GetInt("bucket_position_360", iPosition); } iMaxClip1 = pKeyValuesData->GetInt("clip_size", WEAPON_NOCLIP); // Max primary clips gun can hold (assume they don't use clips by default) iMaxClip2 = pKeyValuesData->GetInt("clip2_size", WEAPON_NOCLIP); // Max secondary clips gun can hold (assume they don't use clips by default) iDefaultClip1 = pKeyValuesData->GetInt("default_clip", iMaxClip1); // amount of primary ammo placed in the primary clip when it's picked up iDefaultClip2 = pKeyValuesData->GetInt("default_clip2", iMaxClip2); // amount of secondary ammo placed in the secondary clip when it's picked up iWeight = pKeyValuesData->GetInt("weight", 0); iRumbleEffect = pKeyValuesData->GetInt("rumble", -1); // LAME old way to specify item flags. // Weapon scripts should use the flag names. iFlags = pKeyValuesData->GetInt("item_flags", ITEM_FLAG_LIMITINWORLD); for (int i = 0; i < ARRAYSIZE(g_ItemFlags); i++) { int iVal = pKeyValuesData->GetInt(g_ItemFlags[i].m_pFlagName, -1); if (iVal == 0) iFlags &= ~g_ItemFlags[i].m_iFlagValue; else if (iVal == 1) iFlags |= g_ItemFlags[i].m_iFlagValue; } bShowUsageHint = (pKeyValuesData->GetInt("showusagehint", 0) != 0) ? true : false; bAutoSwitchTo = (pKeyValuesData->GetInt("autoswitchto", 1) != 0) ? true : false; bAutoSwitchFrom = (pKeyValuesData->GetInt("autoswitchfrom", 1) != 0) ? true : false; m_bBuiltRightHanded = (pKeyValuesData->GetInt("BuiltRightHanded", 1) != 0) ? true : false; m_bAllowFlipping = (pKeyValuesData->GetInt("AllowFlipping", 1) != 0) ? true : false; m_bMeleeWeapon = (pKeyValuesData->GetInt("MeleeWeapon", 0) != 0) ? true : false; #if defined(_DEBUG) && defined(HL2_CLIENT_DLL) // make sure two weapons aren't in the same slot & position if ( iSlot >= MAX_WEAPON_SLOTS || iPosition >= MAX_WEAPON_POSITIONS ) { Warning( "Invalid weapon slot or position [slot %d/%d max], pos[%d/%d max]\n", iSlot, MAX_WEAPON_SLOTS - 1, iPosition, MAX_WEAPON_POSITIONS - 1 ); } else { if (g_bUsedWeaponSlots[iSlot][iPosition]) { Warning( "Duplicately assigned weapon slots in selection hud: %s (%d, %d)\n", szPrintName, iSlot, iPosition ); } g_bUsedWeaponSlots[iSlot][iPosition] = true; } #endif // Primary ammo used const char *pAmmo = pKeyValuesData->GetString("primary_ammo", "None"); if (strcmp("None", pAmmo) == 0) Q_strncpy(szAmmo1, "", sizeof(szAmmo1)); else Q_strncpy(szAmmo1, pAmmo, sizeof(szAmmo1)); iAmmoType = GetAmmoDef()->Index(szAmmo1); // Secondary ammo used pAmmo = pKeyValuesData->GetString("secondary_ammo", "None"); if (strcmp("None", pAmmo) == 0) Q_strncpy(szAmmo2, "", sizeof(szAmmo2)); else Q_strncpy(szAmmo2, pAmmo, sizeof(szAmmo2)); iAmmo2Type = GetAmmoDef()->Index(szAmmo2); // Now read the weapon sounds memset(aShootSounds, 0, sizeof(aShootSounds)); KeyValues *pSoundData = pKeyValuesData->FindKey("SoundData"); if (pSoundData) { for (int i = EMPTY; i < NUM_SHOOT_SOUND_TYPES; i++) { const char *soundname = pSoundData->GetString(pWeaponSoundCategories[i]); if (soundname && soundname[0]) Q_strncpy(aShootSounds[i], soundname, MAX_WEAPON_STRING); } } // this just saves off the data in the script file for later use KeyValues *pEt = pKeyValuesData->FindKey("Ironsight"); if (pEt) { m_expOffset.x = pEt->GetFloat("x", 0.0f); m_expOffset.y = pEt->GetFloat("y", 0.0f); m_expOffset.z = pEt->GetFloat("z", 0.0f); m_expOriOffset.x = pEt->GetFloat("xori", 0.0f); m_expOriOffset.y = pEt->GetFloat("yori", 0.0f); m_expOriOffset.z = pEt->GetFloat("zori", 0.0f); } else { m_expOffset = vec3_origin; m_expOriOffset.Init(); } m_WeaponWeight = pKeyValuesData->GetFloat("weapon_weight", 0.0f); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CModelPanel::SetupModel( void ) { if ( !m_pModelInfo ) return; MDLCACHE_CRITICAL_SECTION(); // remove any current models we're using DeleteModelData(); const char *pszModelName = GetModelName(); if ( !pszModelName || !pszModelName[0] ) return; // create the new model CModelPanelModel *pEnt = new CModelPanelModel; if ( !pEnt ) return; if ( pEnt->InitializeAsClientEntity( pszModelName, false ) == false ) { // we failed to initialize this entity so just return gracefully pEnt->Remove(); return; } // setup the handle m_hModel = pEnt; pEnt->DontRecordInTools(); pEnt->AddEffects( EF_NODRAW ); // don't let the renderer draw the model normally if ( m_pModelInfo->m_nSkin >= 0 ) { pEnt->SetSkin( m_pModelInfo->m_nSkin ); } // do we have any animation information? if ( m_pModelInfo->m_Animations.Count() > 0 && m_pModelInfo->m_Animations.IsValidIndex( m_iDefaultAnimation ) ) { CModelPanelModelAnimation *pAnim = m_pModelInfo->m_Animations[ m_iDefaultAnimation ]; int sequence = ACT_INVALID; if ( pAnim->m_pszActivity && pAnim->m_pszActivity[0] ) { Activity activity = (Activity)ActivityList_IndexForName( pAnim->m_pszActivity ); sequence = pEnt->SelectWeightedSequence( activity ); } else if ( pAnim->m_pszSequence && pAnim->m_pszSequence[0] ) { sequence = pEnt->LookupSequence( pAnim->m_pszSequence ); } if ( sequence != ACT_INVALID ) { pEnt->ResetSequence( sequence ); pEnt->SetCycle( 0 ); if ( pAnim->m_pPoseParameters ) { for ( KeyValues *pData = pAnim->m_pPoseParameters->GetFirstSubKey(); pData != NULL; pData = pData->GetNextKey() ) { const char *pName = pData->GetName(); float flValue = pData->GetFloat(); pEnt->SetPoseParameter( pName, flValue ); } } pEnt->m_flAnimTime = gpGlobals->curtime; } } // setup any attached models for ( int i = 0 ; i < m_pModelInfo->m_AttachedModelsInfo.Count() ; i++ ) { CModelPanelAttachedModelInfo *pInfo = m_pModelInfo->m_AttachedModelsInfo[i]; C_BaseAnimating *pTemp = new C_BaseAnimating; if ( pTemp ) { if ( pTemp->InitializeAsClientEntity( pInfo->m_pszModelName, false ) == false ) { // we failed to initialize this model so just skip it pTemp->Remove(); continue; } pTemp->DontRecordInTools(); pTemp->AddEffects( EF_NODRAW ); // don't let the renderer draw the model normally pTemp->FollowEntity( m_hModel.Get() ); // attach to parent model if ( pInfo->m_nSkin >= 0 ) { pTemp->SetSkin( pInfo->m_nSkin ); } pTemp->m_flAnimTime = gpGlobals->curtime; m_AttachedModels.AddToTail( pTemp ); } } CalculateFrameDistance(); }
void IFaceposerModels::CFacePoserModel::CreateNewBitmap( char const *pchBitmapFilename, int sequence, int nSnapShotSize, bool bZoomInOnFace, CExpression *pExpression, mxbitmapdata_t *bitmap ) { MatSysWindow *pWnd = g_pMatSysWindow; if ( !pWnd ) return; StudioModel *model = m_pModel; if ( !model ) return; CStudioHdr *hdr = model->GetStudioHdr(); if ( !hdr ) return; if ( sequence < 0 || sequence >= hdr->GetNumSeq() ) return; mstudioseqdesc_t &seqdesc = hdr->pSeqdesc( sequence ); Con_ColorPrintf( FILE_COLOR, "Creating bitmap %s for sequence '%s'\n", pchBitmapFilename, seqdesc.pszLabel() ); model->ClearOverlaysSequences(); int iLayer = model->GetNewAnimationLayer(); model->SetOverlaySequence( iLayer, sequence, 1.0 ); model->SetOverlayRate( iLayer, FindPoseCycle( model, sequence ), 0.0 ); for (int i = 0; i < hdr->GetNumPoseParameters(); i++) { model->SetPoseParameter( i, 0.0 ); } float flexValues[ GLOBAL_STUDIO_FLEX_CONTROL_COUNT ] = { 0 }; if ( pExpression ) { float *settings = pExpression->GetSettings(); float *weights = pExpression->GetWeights(); // Save existing settings from model for ( LocalFlexController_t i = LocalFlexController_t(0); i < hdr->numflexcontrollers(); ++i ) { int j = hdr->pFlexcontroller( i )->localToGlobal; if ( j == -1 ) continue; flexValues[ i ] = model->GetFlexController( i ); // Set Value from passed in settings model->SetFlexController( i, settings[ j ] * weights[ j ] ); } } model->ClearLookTargets( ); QAngle oldrot, oldLight; Vector oldtrans; VectorCopy( model->m_angles, oldrot ); VectorCopy( model->m_origin, oldtrans ); VectorCopy( g_viewerSettings.lightrot, oldLight ); model->m_angles.Init(); model->m_origin.Init(); g_viewerSettings.lightrot.Init(); g_viewerSettings.lightrot.y = -180; bool bSaveGround = g_viewerSettings.showGround; g_viewerSettings.showGround = false; if ( bZoomInOnFace ) { Vector size; VectorSubtract( hdr->hull_max(), hdr->hull_min(), size ); float eyeheight = hdr->hull_min().z + 0.9 * size.z; // float width = ( size.x + size.y ) / 2.0f; model->m_origin.x = size.z * .6f; if ( hdr->GetNumAttachments() > 0 ) { for (int i = 0; i < hdr->GetNumAttachments(); i++) { const mstudioattachment_t &attachment = hdr->pAttachment( i ); int iBone = hdr->GetAttachmentBone( i ); if ( Q_stricmp( attachment.pszName(), "eyes" ) ) continue; mstudiobone_t *bone = hdr->pBone( iBone ); if ( !bone ) continue; matrix3x4_t boneToPose; MatrixInvert( bone->poseToBone, boneToPose ); matrix3x4_t attachmentPoseToLocal; ConcatTransforms( boneToPose, attachment.local, attachmentPoseToLocal ); Vector localSpaceEyePosition; VectorITransform( vec3_origin, attachmentPoseToLocal, localSpaceEyePosition ); // Not sure why this must be negative? eyeheight = -localSpaceEyePosition.z + hdr->hull_min().z; break; } } KeyValues *seqKeyValues = new KeyValues(""); if ( seqKeyValues->LoadFromBuffer( model->GetFileName( ), model->GetKeyValueText( sequence ) ) ) { // Do we have a build point section? KeyValues *pkvAllFaceposer = seqKeyValues->FindKey("faceposer"); if ( pkvAllFaceposer ) { float flEyeheight = pkvAllFaceposer->GetFloat( "eye_height", -9999.0f ); if ( flEyeheight != -9999.0f ) { eyeheight = flEyeheight; } } } model->m_origin.z += eyeheight; } else { Vector mins, maxs; model->ExtractBbox(mins, maxs); Vector size; VectorSubtract( maxs, mins, size ); float maxdim = size.x; if ( size.y > maxdim ) maxdim = size.y; if ( size.z > maxdim ) maxdim = size.z; float midpoint = mins.z + 0.5 * size.z; model->m_origin.x = 3 * maxdim; model->m_origin.z += midpoint; } pWnd->SuppressResize( true ); RECT rcClient; HWND wnd = (HWND)pWnd->getHandle(); WINDOWPLACEMENT wp; GetWindowPlacement( wnd, &wp ); GetClientRect( wnd, &rcClient ); MoveWindow( wnd, 0, 0, nSnapShotSize + 16, nSnapShotSize + 16, TRUE ); // Snapshots are taken of the back buffer; // we need to render to the back buffer but not move it to the front pWnd->SuppressBufferSwap( true ); pWnd->redraw(); pWnd->SuppressBufferSwap( false ); // make it square, assumes w > h char fullpath[ 512 ]; Q_snprintf( fullpath, sizeof( fullpath ), "%s%s", GetGameDirectory(), pchBitmapFilename ); pWnd->TakeSnapshotRect( fullpath, 0, 0, nSnapShotSize, nSnapShotSize ); // Move back to original position SetWindowPlacement( wnd, &wp ); pWnd->SuppressResize( false ); VectorCopy( oldrot, model->m_angles ); VectorCopy( oldtrans, model->m_origin ); VectorCopy( oldLight, g_viewerSettings.lightrot ); g_viewerSettings.showGround = bSaveGround; if ( pExpression ) { // Save existing settings from model for ( LocalFlexController_t i = LocalFlexController_t(0); i < hdr->numflexcontrollers(); ++i ) { int j = hdr->pFlexcontroller( i )->localToGlobal; if ( j == -1 ) continue; model->SetFlexController( i, flexValues[ i ] ); } } model->ClearOverlaysSequences(); if ( bitmap->valid ) { DeleteObject( bitmap->image ); bitmap->image = 0; bitmap->valid = false; } LoadBitmapFromFile( pchBitmapFilename, *bitmap ); }
//----------------------------------------------------------------------------- // Purpose: Reloads all scheme fonts //----------------------------------------------------------------------------- void CScheme::ReloadFontGlyphs() { // get our current resolution if ( m_SizingPanel != 0 ) { g_pIPanel->GetSize( m_SizingPanel, m_nScreenWide, m_nScreenTall ); } else { g_pSurface->GetScreenSize( m_nScreenWide, m_nScreenTall ); } // check our language; some have minimum sizes int minimumFontHeight = GetMinimumFontHeightForCurrentLanguage(); // add the data to all the fonts KeyValues *fonts = m_pData->FindKey("Fonts", true); for (int i = 0; i < m_FontAliases.Count(); i++) { KeyValues *kv = fonts->FindKey(m_FontAliases[i]._trueFontName.String(), true); // walk through creating adding the first matching glyph set to the font for (KeyValues *fontdata = kv->GetFirstSubKey(); fontdata != NULL; fontdata = fontdata->GetNextKey()) { // skip over fonts not meant for this resolution int fontYResMin = 0, fontYResMax = 0; sscanf(fontdata->GetString("yres", ""), "%d %d", &fontYResMin, &fontYResMax); if (fontYResMin) { if (!fontYResMax) { fontYResMax = fontYResMin; } // check the range if (m_nScreenTall < fontYResMin || m_nScreenTall > fontYResMax) continue; } int flags = 0; if (fontdata->GetInt( "italic" )) { flags |= ISurface::FONTFLAG_ITALIC; } if (fontdata->GetInt( "underline" )) { flags |= ISurface::FONTFLAG_UNDERLINE; } if (fontdata->GetInt( "strikeout" )) { flags |= ISurface::FONTFLAG_STRIKEOUT; } if (fontdata->GetInt( "symbol" )) { flags |= ISurface::FONTFLAG_SYMBOL; } if (fontdata->GetInt( "antialias" ) && g_pSurface->SupportsFeature(ISurface::ANTIALIASED_FONTS)) { flags |= ISurface::FONTFLAG_ANTIALIAS; } if (fontdata->GetInt( "dropshadow" ) && g_pSurface->SupportsFeature(ISurface::DROPSHADOW_FONTS)) { flags |= ISurface::FONTFLAG_DROPSHADOW; } if (fontdata->GetInt( "outline" ) && g_pSurface->SupportsFeature(ISurface::OUTLINE_FONTS)) { flags |= ISurface::FONTFLAG_OUTLINE; } if (fontdata->GetInt( "custom" )) { flags |= ISurface::FONTFLAG_CUSTOM; } if (fontdata->GetInt( "bitmap" )) { flags |= ISurface::FONTFLAG_BITMAP; } if (fontdata->GetInt( "rotary" )) { flags |= ISurface::FONTFLAG_ROTARY; } if (fontdata->GetInt( "additive" )) { flags |= ISurface::FONTFLAG_ADDITIVE; } int tall = fontdata->GetInt("tall"); int blur = fontdata->GetInt("blur"); int scanlines = fontdata->GetInt("scanlines"); if ( (!fontYResMin && !fontYResMax) && m_FontAliases[i].m_bProportional ) // only grow this font if it doesn't have a resolution filter specified { tall = g_Scheme.GetProportionalScaledValueEx( this, tall ); blur = g_Scheme.GetProportionalScaledValueEx( this, blur ); scanlines = g_Scheme.GetProportionalScaledValueEx( this, scanlines ); } // clip the font size so that fonts can't be too big if (tall > 127) { tall = 127; } // check our minimum font height if (tall < minimumFontHeight) { tall = minimumFontHeight; } if ( flags & ISurface::FONTFLAG_BITMAP ) { // add the new set g_pSurface->SetBitmapFontGlyphSet( m_FontAliases[i]._font, g_pSurface->GetBitmapFontName( fontdata->GetString( "name" ) ), fontdata->GetFloat( "scalex", 1.0f ), fontdata->GetFloat( "scaley", 1.0f ), flags); } else { // add the new set g_pSurface->SetFontGlyphSet( m_FontAliases[i]._font, fontdata->GetString( "name" ), tall, fontdata->GetInt( "weight" ), blur, scanlines, flags); } // don't add any more break; } } }