- a little bit of cleanup on some code that repeatedly accessed some fields in AWeapon and produced far too many search results when looking for this.

This commit is contained in:
Christoph Oelckers 2018-11-24 23:51:09 +01:00
parent 8eb4697fbd
commit b75ee1027a
3 changed files with 19 additions and 11 deletions

View file

@ -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());
}
}
}

View file

@ -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;

View file

@ -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.