Skip to content

Commit

Permalink
Correct weapon misfire formulae in SOC and CS (#382 and #392)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Oct 8, 2022
1 parent ca89824 commit 151b91d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 33 deletions.
60 changes: 39 additions & 21 deletions src/xrGame/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,29 @@ void CWeapon::Load(LPCSTR section)
fireDispersionConditionFactor = pSettings->r_float(section, "fire_dispersion_condition_factor");

// modified by Peacemaker [17.10.08]
const float misfireProbability = pSettings->read_if_exists<float>(section, "misfire_probability", 0.001f);
const float misfireConditionK = pSettings->read_if_exists<float>(section, "misfire_condition_k", 1.0f);

misfireStartCondition = pSettings->read_if_exists<float>(section, "misfire_start_condition", 0.95f);
misfireEndCondition = pSettings->read_if_exists<float>(section, "misfire_end_condition", 0.f);
if (pSettings->line_exist(section, "misfire_start_condition") ||
pSettings->line_exist(section, "misfire_end_condition") ||
pSettings->line_exist(section, "misfire_start_prob") ||
pSettings->line_exist(section, "misfire_end_prob"))
{
misfireStartCondition = pSettings->r_float(section, "misfire_start_condition");
misfireEndCondition = pSettings->r_float(section, "misfire_end_condition");
misfireStartProbability = pSettings->r_float(section, "misfire_start_prob");
misfireEndProbability = pSettings->r_float(section, "misfire_end_prob");
}
else
{
misfireUseOldFormula = true;

misfireStartProbability = pSettings->read_if_exists<float>(section, "misfire_start_prob",
misfireProbability + powf(1.f - misfireStartCondition, 3.f) * misfireConditionK);
misfireEndProbability = pSettings->read_if_exists<float>(section, "misfire_end_prob",
misfireProbability + powf(1.f - misfireEndCondition, 3.f) * misfireConditionK);
misfireProbability = pSettings->r_float(section, "misfire_probability");
misfireConditionK = pSettings->read_if_exists<float>(section, "misfire_condition_k", 1.0f);

// For UI indicators to work correctly
misfireStartCondition = 0.95f;
misfireEndCondition = 0.0f;
misfireStartProbability = misfireProbability;
misfireEndProbability = (misfireProbability + misfireConditionK) * 0.25f;
}
conditionDecreasePerShot = pSettings->r_float(section, "condition_shot_dec");
conditionDecreasePerQueueShot = pSettings->read_if_exists<float>(section, "condition_queue_shot_dec", conditionDecreasePerShot);

Expand Down Expand Up @@ -1189,20 +1201,26 @@ int CWeapon::GetAmmoCount_forType(shared_str const& ammo_type) const

float CWeapon::GetConditionMisfireProbability() const
{
// modified by Peacemaker [17.10.08]
// if(GetCondition() > 0.95f)
// return 0.0f;
if (GetCondition() > misfireStartCondition)
return 0.0f;
if (GetCondition() < misfireEndCondition)
return misfireEndProbability;
// float mis = misfireProbability+powf(1.f-GetCondition(), 3.f)*misfireConditionK;
float mis = misfireStartProbability +
((misfireStartCondition - GetCondition()) * // condition goes from 1.f to 0.f
(misfireEndProbability - misfireStartProbability) / // probability goes from 0.f to 1.f
((misfireStartCondition == misfireEndCondition) ? // !!!say "No" to devision by zero
float mis;
if (misfireUseOldFormula)
{
if (GetCondition() > 0.95f)
return 0.0f;
mis = misfireProbability + powf(1.f - GetCondition(), 3.f) * misfireConditionK;
}
else // modified by Peacemaker [17.10.08]
{
if (GetCondition() > misfireStartCondition)
return 0.0f;
if (GetCondition() < misfireEndCondition)
return misfireEndProbability;
mis = misfireStartProbability +
((misfireStartCondition - GetCondition()) * // condition goes from 1.f to 0.f
(misfireEndProbability - misfireStartProbability) / // probability goes from 0.f to 1.f
((misfireStartCondition == misfireEndCondition) ? // !!!say "No" to devision by zero
misfireStartCondition :
(misfireStartCondition - misfireEndCondition)));
}
clamp(mis, 0.0f, 0.99f);
return mis;
}
Expand Down
12 changes: 7 additions & 5 deletions src/xrGame/Weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,12 @@ class CWeapon : public CHudItemObject, public CShootingObject
//фактор увеличения дисперсии при максимальной изношености
//(на сколько процентов увеличится дисперсия)
float fireDispersionConditionFactor;
//вероятность осечки при максимальной изношености

//вероятность осечки при максимальной изношености
float misfireProbability;
float misfireConditionK;
// modified by Peacemaker [17.10.08]
// float misfireProbability;
// float misfireConditionK;
bool misfireUseOldFormula;
float misfireStartCondition; //изношенность, при которой появляется шанс осечки
float misfireEndCondition; //изношеность при которой шанс осечки становится константным
float misfireStartProbability; //шанс осечки при изношености больше чем misfireStartCondition
Expand All @@ -369,8 +370,9 @@ class CWeapon : public CHudItemObject, public CShootingObject
float conditionDecreasePerShot; //увеличение изношености при одиночном выстреле

public:
float GetMisfireStartCondition() const { return misfireStartCondition; };
float GetMisfireEndCondition() const { return misfireEndCondition; };
float GetMisfireStartCondition() const { return misfireStartCondition; }
float GetMisfireEndCondition() const { return misfireEndCondition; }

protected:
struct SPDM
{
Expand Down
11 changes: 4 additions & 7 deletions src/xrGame/WeaponUpgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,14 @@ bool CWeapon::install_upgrade_disp(LPCSTR section, bool test)
result |=
process_if_exists(section, "PDM_disp_crouch_no_acc", &CInifile::r_float, m_pdm.m_fPDM_disp_crouch_no_acc, test);

// result |= process_if_exists( section, "misfire_probability", &CInifile::r_float, misfireProbability, test
//);
// result |= process_if_exists( section, "misfire_condition_k", &CInifile::r_float, misfireConditionK, test
//);
result |= process_if_exists(section, "condition_shot_dec", &CInifile::r_float, conditionDecreasePerShot, test);
result |=
process_if_exists(section, "condition_queue_shot_dec", &CInifile::r_float, conditionDecreasePerQueueShot, test);
result |= process_if_exists(section, "misfire_probability", &CInifile::r_float, misfireProbability, test);
result |= process_if_exists(section, "misfire_condition_k", &CInifile::r_float, misfireConditionK, test);
result |= process_if_exists(section, "misfire_start_condition", &CInifile::r_float, misfireStartCondition, test);
result |= process_if_exists(section, "misfire_end_condition", &CInifile::r_float, misfireEndCondition, test);
result |= process_if_exists(section, "misfire_start_prob", &CInifile::r_float, misfireStartProbability, test);
result |= process_if_exists(section, "misfire_end_prob", &CInifile::r_float, misfireEndProbability, test);
result |= process_if_exists(section, "condition_shot_dec", &CInifile::r_float, conditionDecreasePerShot, test);
result |= process_if_exists(section, "condition_queue_shot_dec", &CInifile::r_float, conditionDecreasePerQueueShot, test);

bool value = m_zoom_params.m_bZoomEnabled;
bool result2 = process_if_exists_set(section, "zoom_enabled", &CInifile::r_bool, value, test);
Expand Down

0 comments on commit 151b91d

Please sign in to comment.