diff --git a/src/ct_chat.cpp b/src/ct_chat.cpp index 85e8f0c23..c32a67303 100644 --- a/src/ct_chat.cpp +++ b/src/ct_chat.cpp @@ -375,6 +375,8 @@ static bool DoSubstitution (FString &out, const char *in) { player_t *player = &players[consoleplayer]; AWeapon *weapon = player->ReadyWeapon; + auto ammo1 = weapon ? weapon->Ammo1 : nullptr; + auto ammo2 = weapon ? weapon->Ammo2 : nullptr; const char *a, *b; a = in; @@ -427,10 +429,10 @@ static bool DoSubstitution (FString &out, const char *in) } else { - out.AppendFormat("%d", weapon->Ammo1 != NULL ? weapon->Ammo1->Amount : 0); - if (weapon->Ammo2 != NULL) + out.AppendFormat("%d", ammo1 != NULL ? ammo1->Amount : 0); + if (ammo2 != NULL) { - out.AppendFormat("/%d", weapon->Ammo2->Amount); + out.AppendFormat("/%d", ammo2->Amount); } } } @@ -439,16 +441,16 @@ static bool DoSubstitution (FString &out, const char *in) { if (strnicmp(a, "ammo", 4) == 0) { - if (weapon == NULL || weapon->Ammo1 == NULL) + if (ammo1 == NULL) { out += "no ammo"; } else { - out.AppendFormat("%s", weapon->Ammo1->GetClass()->TypeName.GetChars()); - if (weapon->Ammo2 != NULL) + out.AppendFormat("%s", ammo1->GetClass()->TypeName.GetChars()); + if (ammo2 != NULL) { - out.AppendFormat("/%s", weapon->Ammo2->GetClass()->TypeName.GetChars()); + out.AppendFormat("/%s", ammo2->GetClass()->TypeName.GetChars()); } } } diff --git a/src/g_statusbar/sbarinfo.cpp b/src/g_statusbar/sbarinfo.cpp index 9c3c71017..e0dc3e294 100644 --- a/src/g_statusbar/sbarinfo.cpp +++ b/src/g_statusbar/sbarinfo.cpp @@ -1467,6 +1467,12 @@ public: return TRANSLATION(TRANSLATION_Players, int(CPlayer - players)); } + PClassActor *AmmoType(int no) const + { + auto w = StatusBar->CPlayer->ReadyWeapon; + return w == nullptr ? nullptr : (no == 1 ? w->AmmoType1 : w->AmmoType2); + } + AInventory *ammo1, *ammo2; int ammocount1, ammocount2; AInventory *armor; diff --git a/src/g_statusbar/sbarinfo_commands.cpp b/src/g_statusbar/sbarinfo_commands.cpp index a4249e832..d28298667 100644 --- a/src/g_statusbar/sbarinfo_commands.cpp +++ b/src/g_statusbar/sbarinfo_commands.cpp @@ -1874,7 +1874,7 @@ class CommandUsesAmmo : public SBarInfoNegatableFlowControl { SBarInfoNegatableFlowControl::Tick(block, statusBar, hudChanged); - SetTruth(statusBar->CPlayer->ReadyWeapon != NULL && (statusBar->CPlayer->ReadyWeapon->AmmoType1 != NULL || statusBar->CPlayer->ReadyWeapon->AmmoType2 != NULL), block, statusBar); + SetTruth(statusBar->AmmoType(1) || statusBar->AmmoType(2), block, statusBar); } }; @@ -1891,7 +1891,7 @@ class CommandUsesSecondaryAmmo : public CommandUsesAmmo { SBarInfoCommandFlowControl::Tick(block, statusBar, hudChanged); - SetTruth(statusBar->CPlayer->ReadyWeapon != NULL && statusBar->CPlayer->ReadyWeapon->AmmoType2 != NULL && statusBar->CPlayer->ReadyWeapon->AmmoType1 != statusBar->CPlayer->ReadyWeapon->AmmoType2, block, statusBar); + SetTruth(statusBar->AmmoType(2) && statusBar->AmmoType(2) != statusBar->AmmoType(1), block, statusBar); } }; @@ -3247,8 +3247,8 @@ class CommandWeaponAmmo : public SBarInfoNegatableFlowControl if(statusBar->CPlayer->ReadyWeapon != NULL) { - const PClass *AmmoType1 = statusBar->CPlayer->ReadyWeapon->AmmoType1; - const PClass *AmmoType2 = statusBar->CPlayer->ReadyWeapon->AmmoType2; + const PClass *AmmoType1 = statusBar->AmmoType(1); + const PClass *AmmoType2 = statusBar->AmmoType(2); bool usesammo1 = (AmmoType1 != NULL); bool usesammo2 = (AmmoType2 != NULL); //if(!usesammo1 && !usesammo2) //if the weapon doesn't use ammo don't go though the trouble.