- removed all direct access to AWeapon's members to prepare moving this class fully to the script side.

Disregarding UI-side and setup-related calls there's unfortunately still 6 places in the native game code which require direct access.
This commit is contained in:
Christoph Oelckers 2018-11-25 08:17:37 +01:00
parent 00a48b09e5
commit b5c4ab8c47
18 changed files with 95 additions and 76 deletions

View file

@ -369,8 +369,10 @@ void DBot::WhatToGet (AActor *item)
{
if (!weapgiveammo)
return;
if ((heldWeapon->Ammo1 == NULL || heldWeapon->Ammo1->Amount >= heldWeapon->Ammo1->MaxAmount) &&
(heldWeapon->Ammo2 == NULL || heldWeapon->Ammo2->Amount >= heldWeapon->Ammo2->MaxAmount))
auto ammo1 = heldWeapon->PointerVar<AInventory>(NAME_Ammo1);
auto ammo2 = heldWeapon->PointerVar<AInventory>(NAME_Ammo2);
if ((ammo1 == NULL || ammo1->Amount >= ammo1->MaxAmount) &&
(ammo2 == NULL || ammo2->Amount >= ammo2->MaxAmount))
{
return;
}

View file

@ -375,8 +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;
auto ammo1 = weapon ? weapon->PointerVar<AInventory>(NAME_Ammo1) : nullptr;
auto ammo2 = weapon ? weapon->PointerVar<AInventory>(NAME_Ammo2) : nullptr;
const char *a, *b;
a = in;

View file

@ -1583,13 +1583,15 @@ static int PatchAmmo (int ammoNum)
else if (type->IsDescendantOf (RUNTIME_CLASS(AWeapon)))
{
AWeapon *defWeap = (AWeapon *)GetDefaultByType (type);
if (defWeap->AmmoType1 == ammoType)
if (defWeap->PointerVar<PClassActor>(NAME_AmmoType1) == ammoType)
{
defWeap->AmmoGive1 = Scale (defWeap->AmmoGive1, *per, oldclip);
auto &AmmoGive1 = defWeap->IntVar(NAME_AmmoGive1);
AmmoGive1 = Scale (AmmoGive1, *per, oldclip);
}
if (defWeap->AmmoType2 == ammoType)
if (defWeap->PointerVar<PClassActor>(NAME_AmmoType2) == ammoType)
{
defWeap->AmmoGive2 = Scale (defWeap->AmmoGive2, *per, oldclip);
auto &AmmoGive2 = defWeap->IntVar(NAME_AmmoGive2);
AmmoGive2 = Scale (AmmoGive2, *per, oldclip);
}
}
}
@ -1655,13 +1657,15 @@ static int PatchWeapon (int weapNum)
{
val = 5;
}
info->AmmoType1 = AmmoNames[val];
if (info->AmmoType1 != NULL)
auto &AmmoType = info->PointerVar<PClassActor>(NAME_AmmoType1);
AmmoType = AmmoNames[val];
if (AmmoType != nullptr)
{
info->AmmoGive1 = ((AInventory*)GetDefaultByType (info->AmmoType1))->Amount * 2;
if (info->AmmoUse1 == 0)
info->IntVar(NAME_AmmoGive1) = ((AInventory*)GetDefaultByType (AmmoType))->Amount * 2;
auto &AmmoUse = info->IntVar(NAME_AmmoUse1);
if (AmmoUse == 0)
{
info->AmmoUse1 = 1;
AmmoUse = 1;
}
}
}
@ -1685,12 +1689,12 @@ static int PatchWeapon (int weapNum)
}
else if (stricmp (Line1, "Ammo use") == 0 || stricmp (Line1, "Ammo per shot") == 0)
{
info->AmmoUse1 = val;
info->IntVar(NAME_AmmoUse1) = val;
info->flags6 |= MF6_INTRYMOVE; // flag the weapon for postprocessing (reuse a flag that can't be set by external means)
}
else if (stricmp (Line1, "Min ammo") == 0)
{
info->MinSelAmmo1 = val;
info->IntVar(NAME_MinSelAmmo1) = val;
}
else
{
@ -1698,9 +1702,9 @@ static int PatchWeapon (int weapNum)
}
}
if (info->AmmoType1 == NULL)
if (info->PointerVar<PClassActor>(NAME_AmmoType1) == nullptr)
{
info->AmmoUse1 = 0;
info->IntVar(NAME_AmmoUse1) = 0;
}
if (patchedStates)
@ -3095,8 +3099,8 @@ void FinishDehPatch ()
}
else
{
weap->bDehAmmo = true;
weap->AmmoUse1 = 0;
weap->BoolVar(NAME_bDehAmmo) = true;
weap->IntVar(NAME_AmmoUse1) = 0;
// to allow proper checks in CheckAmmo we have to find the first attack pointer in the Fire sequence
// and set its default ammo use as the weapon's AmmoUse1.
@ -3123,7 +3127,7 @@ void FinishDehPatch ()
found = true;
int use = AmmoPerAttacks[j].ammocount;
if (use < 0) use = deh.BFGCells;
weap->AmmoUse1 = use;
weap->IntVar(NAME_AmmoUse1) = use;
break;
}
}

View file

@ -799,7 +799,7 @@ static int LookAdjust(int look)
if (players[consoleplayer].playerstate != PST_DEAD && // No adjustment while dead.
players[consoleplayer].ReadyWeapon != NULL) // No adjustment if no weapon.
{
auto scale = players[consoleplayer].ReadyWeapon->FOVScale;
auto scale = players[consoleplayer].ReadyWeapon->FloatVar(NAME_FOVScale);
if (scale > 0) // No adjustment if it is non-positive.
{
look = int(look * scale);
@ -1301,8 +1301,8 @@ void G_PlayerFinishLevel (int player, EFinishLevelType mode, int flags)
item = next;
}
if (p->ReadyWeapon != NULL &&
p->ReadyWeapon->WeaponFlags&WIF_POWERED_UP &&
p->PendingWeapon == p->ReadyWeapon->SisterWeapon)
p->ReadyWeapon->IntVar(NAME_WeaponFlags) & WIF_POWERED_UP &&
p->PendingWeapon == p->ReadyWeapon->PointerVar<AInventory>(NAME_SisterWeapon))
{
// Unselect powered up weapons if the unpowered counterpart is pending
p->ReadyWeapon=p->PendingWeapon;

View file

@ -55,6 +55,7 @@ IMPLEMENT_POINTERS_START(AWeapon)
IMPLEMENT_POINTER(SisterWeapon)
IMPLEMENT_POINTERS_END
/*
DEFINE_FIELD(AWeapon, AmmoType1)
DEFINE_FIELD(AWeapon, AmmoType2)
DEFINE_FIELD(AWeapon, AmmoGive1)
@ -85,6 +86,7 @@ DEFINE_FIELD(AWeapon, GivenAsMorphWeapon)
DEFINE_FIELD(AWeapon, bAltFire)
DEFINE_FIELD(AWeapon, WeaponFlags)
DEFINE_FIELD(AWeapon, bDehAmmo)
*/
//===========================================================================
//

View file

@ -139,7 +139,7 @@ public:
int MinAmmo1, MinAmmo2; // Minimum ammo needed to switch to this weapon
int AmmoUse1, AmmoUse2; // How much ammo to use with each shot
int Kickback;
float YAdjust; // For viewing the weapon fullscreen (visual only so no need to be a double)
double YAdjust; // For viewing the weapon fullscreen (visual only so no need to be a double)
FSoundIDNoInit UpSound, ReadySound; // Sounds when coming up and idle
PClassActor *SisterWeaponType; // Another weapon to pick up with this one
int SelectionOrder; // Lower-numbered weapons get picked first
@ -152,32 +152,24 @@ public:
// In-inventory instance variables
TObjPtr<AInventory*> Ammo1, Ammo2;
TObjPtr<AWeapon*> SisterWeapon;
float FOVScale;
double FOVScale;
int Crosshair; // 0 to use player's crosshair
bool GivenAsMorphWeapon; // *** only accessed from ZScript.
bool GivenAsMorphWeapon;
bool bAltFire; // *** only accessed from ZScript. Set when this weapon's alternate fire is used.
bool bAltFire;
bool bDehAmmo;
void Serialize(FSerializer &arc) override;
};
enum
{
PrimaryFire,
AltFire,
EitherFire
};
enum
{
BobNormal,
BobInverse,
BobAlpha,
BobInverseAlpha,
BobSmooth,
BobInverseSmooth
};
enum class EBobStyle
{
BobNormal,
BobInverse,
BobAlpha,
BobInverseAlpha,
BobSmooth,
BobInverseSmooth
};
enum

View file

@ -512,7 +512,7 @@ static void AddAmmoToList(AWeapon * weapdef)
for (int i = 0; i < 2; i++)
{
auto ti = i == 0 ? weapdef->AmmoType1 : weapdef->AmmoType2;
auto ti = weapdef->PointerVar<PClassActor>(i == 0 ? NAME_AmmoType1 : NAME_AmmoType2);
if (ti)
{
auto ammodef = (AInventory*)GetDefaultByType(ti);
@ -643,7 +643,7 @@ static int DrawAmmo(player_t *CPlayer, int x, int y)
FTextureID icon = !AltIcon.isNull()? AltIcon : inv->Icon;
if (!icon.isValid()) continue;
double trans= (wi && (type==wi->AmmoType1 || type==wi->AmmoType2)) ? 0.75 : 0.375;
double trans= (wi && (type==wi->PointerVar<PClassActor>(NAME_AmmoType1) || type==wi->PointerVar<PClassActor>(NAME_AmmoType2))) ? 0.75 : 0.375;
int maxammo = inv->MaxAmount;
int ammo = ammoitem? ammoitem->Amount : 0;
@ -741,13 +741,14 @@ static void DrawOneWeapon(player_t * CPlayer, int x, int & y, AWeapon * weapon)
double trans;
// Powered up weapons and inherited sister weapons are not displayed.
if (weapon->WeaponFlags & WIF_POWERED_UP) return;
if (weapon->SisterWeapon && weapon->IsKindOf(weapon->SisterWeapon->GetClass())) return;
if (weapon->IntVar(NAME_WeaponFlags) & WIF_POWERED_UP) return;
auto SisterWeapon = weapon->PointerVar<AInventory>(NAME_SisterWeapon);
if (SisterWeapon && weapon->IsKindOf(SisterWeapon->GetClass())) return;
trans=0.4;
if (CPlayer->ReadyWeapon)
{
if (weapon==CPlayer->ReadyWeapon || weapon==CPlayer->ReadyWeapon->SisterWeapon) trans = 0.85;
if (weapon==CPlayer->ReadyWeapon || SisterWeapon == CPlayer->ReadyWeapon) trans = 0.85;
}
FTextureID picnum = GetInventoryIcon(weapon, DI_ALTICONFIRST);

View file

@ -1039,22 +1039,22 @@ public:
}
wrapper->ForceHUDScale(script->huds[hud]->ForceScaled());
if (CPlayer->ReadyWeapon != NULL)
if (CPlayer->ReadyWeapon != nullptr)
{
ammo1 = CPlayer->ReadyWeapon->Ammo1;
ammo2 = CPlayer->ReadyWeapon->Ammo2;
if (ammo1 == NULL)
ammo1 = CPlayer->ReadyWeapon->PointerVar<AInventory>(NAME_Ammo1);
ammo2 = CPlayer->ReadyWeapon->PointerVar<AInventory>(NAME_Ammo2);
if (ammo1 == nullptr)
{
ammo1 = ammo2;
ammo2 = NULL;
ammo2 = nullptr;
}
}
else
{
ammo1 = ammo2 = NULL;
ammo1 = ammo2 = nullptr;
}
ammocount1 = ammo1 != NULL ? ammo1->Amount : 0;
ammocount2 = ammo2 != NULL ? ammo2->Amount : 0;
ammocount1 = ammo1 != nullptr ? ammo1->Amount : 0;
ammocount2 = ammo2 != nullptr ? ammo2->Amount : 0;
//prepare ammo counts
armor = CPlayer->mo->FindInventory(NAME_BasicArmor);
@ -1470,7 +1470,7 @@ public:
PClassActor *AmmoType(int no) const
{
auto w = StatusBar->CPlayer->ReadyWeapon;
return w == nullptr ? nullptr : (no == 1 ? w->AmmoType1 : w->AmmoType2);
return w == nullptr ? nullptr : (w->PointerVar<PClassActor>(no == 1 ? NAME_AmmoType1 : NAME_AmmoType2));
}
AInventory *ammo1, *ammo2;

View file

@ -245,7 +245,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl
else if(type == AMMO1)
{
auto ammo = statusBar->ammo1;
if(ammo != NULL)
if(ammo != NULL)
GetIcon(ammo);
}
else if(type == AMMO2)

View file

@ -175,7 +175,7 @@ void ST_LoadCrosshair(bool alwaysload)
players[consoleplayer].camera->player != NULL &&
players[consoleplayer].camera->player->ReadyWeapon != NULL)
{
num = players[consoleplayer].camera->player->ReadyWeapon->Crosshair;
num = players[consoleplayer].camera->player->ReadyWeapon->IntVar(NAME_Crosshair);
}
if (num == 0)
{

View file

@ -988,3 +988,21 @@ xx(snd_resampler)
xx(ScriptUtil)
xx(SetMarineWeapon)
xx(SetMarineSprite)
// Weapon member fields that need direct access
xx(Ammo1)
xx(Ammo2)
xx(AmmoType1)
xx(AmmoType2)
xx(AmmoGive1)
xx(AmmoGive2)
xx(AmmoUse1)
xx(SisterWeapon)
xx(BobStyle)
xx(Kickback)
xx(MinSelAmmo1)
xx(bDehAmmo)
xx(FOVScale)
xx(YAdjust)
xx(Crosshair)
xx(WeaponFlags)

View file

@ -965,7 +965,7 @@ static void HandleReply(player_t *player, bool isconsole, int nodenum, int reply
if (item->GetClass()->TypeName == NAME_FlameThrower)
{
// The flame thrower gives less ammo when given in a dialog
static_cast<AWeapon*>(item)->AmmoGive1 = 40;
item->IntVar(NAME_AmmoGive1) = 40;
}
item->flags |= MF_DROPPED;
if (!item->CallTryPickup(player->mo))

View file

@ -1029,7 +1029,7 @@ void P_NewChaseDir(AActor * actor)
{
// melee range of player weapon is a parameter of the action function and cannot be checked here.
// Add a new weapon property?
ismeleeattacker = ((target->player->ReadyWeapon->WeaponFlags & WIF_MELEEWEAPON) && dist < 192);
ismeleeattacker = ((target->player->ReadyWeapon->IntVar(NAME_WeaponFlags) & WIF_MELEEWEAPON) && dist < 192);
}
if (ismeleeattacker)
{

View file

@ -4459,7 +4459,7 @@ DAngle P_AimLineAttack(AActor *t1, DAngle angle, double distance, FTranslatedLin
{
// [BB] Disable autoaim on weapons with WIF_NOAUTOAIM.
AWeapon *weapon = t1->player->ReadyWeapon;
if (weapon && (weapon->WeaponFlags & WIF_NOAUTOAIM))
if ((weapon && (weapon->IntVar(NAME_WeaponFlags) & WIF_NOAUTOAIM)) && !(flags & ALF_NOWEAPONCHECK))
{
vrange = 0.5;
}

View file

@ -7284,7 +7284,7 @@ AActor *P_SpawnPlayerMissile (AActor *source, double x, double y, double z,
DAngle vrange = nofreeaim ? 35. : 0.;
if (!pLineTarget) pLineTarget = &scratch;
if (source->player && source->player->ReadyWeapon && ((source->player->ReadyWeapon->WeaponFlags & WIF_NOAUTOAIM) || noautoaim))
if (!(flags & ALF_NOWEAPONCHECK) && source->player && source->player->ReadyWeapon && ((source->player->ReadyWeapon->IntVar(NAME_WeaponFlags) & WIF_NOAUTOAIM) || noautoaim))
{
// Keep exactly the same angle and pitch as the player's own aim
an = angle;

View file

@ -1150,16 +1150,16 @@ float DPSprite::GetYAdjust(bool fullscreen)
AWeapon *weapon = dyn_cast<AWeapon>(GetCaller());
if (weapon != nullptr)
{
float fYAd = weapon->YAdjust;
auto fYAd = weapon->FloatVar(NAME_YAdjust);
if (fYAd != 0)
{
if (fullscreen)
{
return fYAd;
return (float)fYAd;
}
else
{
return (float)StatusBar->GetDisplacement() * fYAd;
return (float)(StatusBar->GetDisplacement() * fYAd);
}
}
}

View file

@ -1181,7 +1181,7 @@ DEFINE_CLASS_PROPERTY(pickupannouncerentry, S, Inventory)
//==========================================================================
DEFINE_CLASS_PROPERTY(defaultkickback, 0, Weapon)
{
defaults->Kickback = gameinfo.defKickback;
defaults->IntVar(NAME_Kickback) = gameinfo.defKickback;
}
//==========================================================================
@ -1190,9 +1190,9 @@ DEFINE_CLASS_PROPERTY(defaultkickback, 0, Weapon)
DEFINE_CLASS_PROPERTY(bobstyle, S, Weapon)
{
static const char *names[] = { "Normal", "Inverse", "Alpha", "InverseAlpha", "Smooth", "InverseSmooth", NULL };
static const int styles[] = { AWeapon::BobNormal,
AWeapon::BobInverse, AWeapon::BobAlpha, AWeapon::BobInverseAlpha,
AWeapon::BobSmooth, AWeapon::BobInverseSmooth, };
static const EBobStyle styles[] = { EBobStyle::BobNormal,
EBobStyle::BobInverse, EBobStyle::BobAlpha, EBobStyle::BobInverseAlpha,
EBobStyle::BobSmooth, EBobStyle::BobInverseSmooth, };
PROP_STRING_PARM(id, 0);
int match = MatchString(id, names);
if (match < 0)
@ -1200,7 +1200,7 @@ DEFINE_CLASS_PROPERTY(bobstyle, S, Weapon)
I_Error("Unknown bobstyle %s", id);
match = 0;
}
defaults->BobStyle = styles[match];
defaults->IntVar(NAME_BobStyle) = (int)styles[match];
}
//==========================================================================

View file

@ -10,13 +10,13 @@ class Weapon : StateProvider native
const ZOOM_INSTANT = 1;
const ZOOM_NOSCALETURNING = 2;
native uint WeaponFlags;
deprecated("3.7") native uint WeaponFlags; // not to be used directly.
native class<Ammo> AmmoType1, AmmoType2; // Types of ammo used by self weapon
native int AmmoGive1, AmmoGive2; // Amount of each ammo to get when picking up weapon
native int MinAmmo1, MinAmmo2; // not used anywhere.
deprecated("3.7") native int MinAmmo1, MinAmmo2; // not used anywhere and thus deprecated.
native int AmmoUse1, AmmoUse2; // How much ammo to use with each shot
native int Kickback;
native float YAdjust; // For viewing the weapon fullscreen (visual only so no need to be a double)
native double YAdjust; // For viewing the weapon fullscreen
native sound UpSound, ReadySound; // Sounds when coming up and idle
native class<Weapon> SisterWeaponType; // Another weapon to pick up with self one
native int SelectionOrder; // Lower-numbered weapons get picked first
@ -27,7 +27,7 @@ class Weapon : StateProvider native
native float BobRangeX, BobRangeY; // [XA] Bobbing range. Defines how far a weapon bobs in either direction.
native Ammo Ammo1, Ammo2; // In-inventory instance variables
native Weapon SisterWeapon;
native float FOVScale;
native double FOVScale;
native int Crosshair; // 0 to use player's crosshair
native bool GivenAsMorphWeapon;
native bool bAltFire; // Set when this weapon's alternate fire is used.