Skip to content
Permalink
Browse files

- scriptified the remaining PlayerPawn methods.

  • Loading branch information...
coelckers committed Jan 3, 2019
1 parent 2258a71 commit 3314a1efe55a474c2d3872af69dde3f8847d7183
Showing with 159 additions and 159 deletions.
  1. +1 −21 src/d_player.h
  2. +1 −0 src/namedef.h
  3. +69 −50 src/p_mobj.cpp
  4. +25 −86 src/p_user.cpp
  5. +2 −2 src/scripting/thingdef_properties.cpp
  6. +61 −0 wadsrc/static/zscript/shared/player.txt
@@ -87,22 +87,6 @@ class APlayerPawn : public AActor

virtual void Serialize(FSerializer &arc);

virtual void PostBeginPlay() override;
virtual void Tick() override;
virtual void BeginPlay () override;
virtual bool UpdateWaterLevel (bool splash) override;


enum EInvulState
{
INVUL_Start,
INVUL_Active,
INVUL_Stop,
INVUL_GetAlpha
};


int crouchsprite;
int BonusHealth;

int MugShotMaxHealth;
@@ -122,6 +106,7 @@ class APlayerPawn : public AActor
double UseRange; // [NS] Distance at which player can +use

// Everything below this point is only used by scripted code or through the scripted variable interface.
int crouchsprite;
int MaxHealth;
int RunHealth;
TObjPtr<AActor*> InvFirst; // first inventory item displayed on inventory bar
@@ -492,11 +477,6 @@ class player_t
}
}

bool CanCrouch() const
{
return morphTics == 0 || mo->PlayerFlags & PPF_CROUCHABLEMORPH;
}

int GetSpawnClass();

// PSprite layers
@@ -1042,6 +1042,7 @@ xx(SoundClass)
xx(ViewBob)
xx(DamageFade)
xx(MaxHealth)
xx(crouchsprite)

xx(BlueCard)
xx(YellowCard)
@@ -4267,79 +4267,98 @@ bool AActor::UpdateWaterLevel(bool dosplash)

double fh = -FLT_MAX;
bool reset = false;
int oldlevel = waterlevel;

waterlevel = 0;

if (Sector == NULL)
{
return false;
}

if (Sector->MoreFlags & SECMF_UNDERWATER) // intentionally not SECMF_UNDERWATERMASK
{
waterlevel = 3;
}
else
if (Sector != nullptr)
{
const sector_t *hsec = Sector->GetHeightSec();
if (hsec != NULL)
if (Sector->MoreFlags & SECMF_UNDERWATER) // intentionally not SECMF_UNDERWATERMASK
{
fh = hsec->floorplane.ZatPoint(this);
if (hsec->MoreFlags & SECMF_UNDERWATERMASK) // also check Boom-style non-swimmable sectors
waterlevel = 3;
}
else
{
const sector_t *hsec = Sector->GetHeightSec();
if (hsec != NULL)
{
if (Z() < fh)
fh = hsec->floorplane.ZatPoint(this);
if (hsec->MoreFlags & SECMF_UNDERWATERMASK) // also check Boom-style non-swimmable sectors
{
waterlevel = 1;
if (Center() < fh)
if (Z() < fh)
{
waterlevel = 2;
if ((player && Z() + player->viewheight <= fh) ||
(Top() <= fh))
waterlevel = 1;
if (Center() < fh)
{
waterlevel = 3;
waterlevel = 2;
if ((player && Z() + player->viewheight <= fh) ||
(Top() <= fh))
{
waterlevel = 3;
}
}
}
}
else if (!(hsec->MoreFlags & SECMF_FAKEFLOORONLY) && (Top() > hsec->ceilingplane.ZatPoint(this)))
{
waterlevel = 3;
}
else
{
waterlevel = 0;
else if (!(hsec->MoreFlags & SECMF_FAKEFLOORONLY) && (Top() > hsec->ceilingplane.ZatPoint(this)))
{
waterlevel = 3;
}
else
{
waterlevel = 0;
}
}
}
}
else
{
// Check 3D floors as well!
for (auto rover : Sector->e->XFloor.ffloors)
else
{
if (!(rover->flags & FF_EXISTS)) continue;
if (rover->flags & FF_SOLID) continue;
if (!(rover->flags & FF_SWIMMABLE)) continue;
// Check 3D floors as well!
for (auto rover : Sector->e->XFloor.ffloors)
{
if (!(rover->flags & FF_EXISTS)) continue;
if (rover->flags & FF_SOLID) continue;
if (!(rover->flags & FF_SWIMMABLE)) continue;

double ff_bottom = rover->bottom.plane->ZatPoint(this);
double ff_top = rover->top.plane->ZatPoint(this);
double ff_bottom = rover->bottom.plane->ZatPoint(this);
double ff_top = rover->top.plane->ZatPoint(this);

if (ff_top <= Z() || ff_bottom > (Center())) continue;
if (ff_top <= Z() || ff_bottom > (Center())) continue;

fh = ff_top;
if (Z() < fh)
{
waterlevel = 1;
if (Center() < fh)
fh = ff_top;
if (Z() < fh)
{
waterlevel = 2;
if ((player && Z() + player->viewheight <= fh) ||
(Top() <= fh))
waterlevel = 1;
if (Center() < fh)
{
waterlevel = 3;
waterlevel = 2;
if ((player && Z() + player->viewheight <= fh) ||
(Top() <= fh))
{
waterlevel = 3;
}
}
}

break;
}
}
}

break;
// Play surfacing and diving sounds, as appropriate.
if (player != nullptr)
{
if (oldlevel < 3 && waterlevel == 3)
{
// Our head just went under.
S_Sound(this, CHAN_VOICE, "*dive", 1, ATTN_NORM);
}
else if (oldlevel == 3 && waterlevel < 3)
{
// Our head just came up.
if (player->air_finished > level.time)
{
// We hadn't run out of air yet.
S_Sound(this, CHAN_VOICE, "*surface", 1, ATTN_NORM);
}
// If we were running out of air, then ResetAirSupply() will play *gasp.
}
}
}
@@ -634,6 +634,13 @@ void player_t::SendPitchLimits() const
}
}

DEFINE_ACTION_FUNCTION(_PlayerInfo, SendPitchLimits)
{
PARAM_SELF_STRUCT_PROLOGUE(player_t);
self->SendPitchLimits();
return 0;
}


bool player_t::HasWeaponsInSlot(int slot) const
{
@@ -830,11 +837,8 @@ void APlayerPawn::Serialize(FSerializer &arc)
//
//===========================================================================

void APlayerPawn::BeginPlay ()
static int SetupCrouchSprite(AActor *self, int crouchsprite)
{
Super::BeginPlay ();
ChangeStatNum (STAT_PLAYER);
FullHeight = Height;
// Check whether a PWADs normal sprite is to be combined with the base WADs
// crouch sprite. In such a case the sprites normally don't match and it is
// best to disable the crouch sprite.
@@ -843,110 +847,44 @@ void APlayerPawn::BeginPlay ()
// This assumes that player sprites always exist in rotated form and
// that the front view is always a separate sprite. So far this is
// true for anything that exists.
FString normspritename = sprites[SpawnState->sprite].name;
FString normspritename = sprites[self->SpawnState->sprite].name;
FString crouchspritename = sprites[crouchsprite].name;

int spritenorm = Wads.CheckNumForName(normspritename + "A1", ns_sprites);
if (spritenorm==-1)
if (spritenorm == -1)
{
spritenorm = Wads.CheckNumForName(normspritename + "A0", ns_sprites);
}

int spritecrouch = Wads.CheckNumForName(crouchspritename + "A1", ns_sprites);
if (spritecrouch==-1)
if (spritecrouch == -1)
{
spritecrouch = Wads.CheckNumForName(crouchspritename + "A0", ns_sprites);
}
if (spritenorm==-1 || spritecrouch ==-1)

if (spritenorm == -1 || spritecrouch == -1)
{
// Sprites do not exist so it is best to disable the crouch sprite.
crouchsprite = 0;
return;
return false;
}

int wadnorm = Wads.GetLumpFile(spritenorm);
int wadcrouch = Wads.GetLumpFile(spritenorm);

if (wadnorm > Wads.GetIwadNum() && wadcrouch <= Wads.GetIwadNum())
{
// Question: Add an option / disable crouching or do what?
crouchsprite = 0;
return false;
}
}
return true;
}

//===========================================================================
//
// APlayerPawn :: Tick
//
//===========================================================================

void APlayerPawn::Tick()
{
if (player != NULL && player->mo == this && player->CanCrouch() && player->playerstate != PST_DEAD)
{
Height = FullHeight * player->crouchfactor;
}
else
{
if (health > 0) Height = FullHeight;
}
Super::Tick();
}

//===========================================================================
//
// APlayerPawn :: PostBeginPlay
//
//===========================================================================

void APlayerPawn::PostBeginPlay()
{
Super::PostBeginPlay();
FWeaponSlots::SetupWeaponSlots(this);

// Voodoo dolls: restore original floorz/ceilingz logic
if (player == NULL || player->mo != this)
{
P_FindFloorCeiling(this, FFCF_ONLYSPAWNPOS|FFCF_NOPORTALS);
SetZ(floorz);
P_FindFloorCeiling(this, FFCF_ONLYSPAWNPOS);
}
else
{
player->SendPitchLimits();
}
}

//===========================================================================
//
// APlayerPawn :: UpdateWaterLevel
//
// Plays surfacing and diving sounds, as appropriate.
//
//===========================================================================

bool APlayerPawn::UpdateWaterLevel (bool splash)
DEFINE_ACTION_FUNCTION_NATIVE(APlayerPawn, SetupCrouchSprite, SetupCrouchSprite)
{
int oldlevel = waterlevel;
bool retval = Super::UpdateWaterLevel (splash);
if (player != NULL)
{
if (oldlevel < 3 && waterlevel == 3)
{ // Our head just went under.
S_Sound (this, CHAN_VOICE, "*dive", 1, ATTN_NORM);
}
else if (oldlevel == 3 && waterlevel < 3)
{ // Our head just came up.
if (player->air_finished > level.time)
{ // We hadn't run out of air yet.
S_Sound (this, CHAN_VOICE, "*surface", 1, ATTN_NORM);
}
// If we were running out of air, then ResetAirSupply() will play *gasp.
}
}
return retval;
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT(crouchsprite);
ACTION_RETURN_INT(SetupCrouchSprite(self, crouchsprite));
}

//===========================================================================
@@ -1068,9 +1006,10 @@ void P_CheckPlayerSprite(AActor *actor, int &spritenum, DVector2 &scale)
// Set the crouch sprite?
if (player->crouchfactor < 0.75)
{
if (spritenum == actor->SpawnState->sprite || spritenum == player->mo->crouchsprite)
int crouchsprite = player->mo->IntVar(NAME_crouchsprite);
if (spritenum == actor->SpawnState->sprite || spritenum == crouchsprite)
{
crouchspriteno = player->mo->crouchsprite;
crouchspriteno = crouchsprite;
}
else if (!(actor->flags4 & MF4_NOSKIN) &&
(spritenum == Skins[player->userinfo.GetSkin()].sprite ||
@@ -1585,11 +1585,11 @@ DEFINE_CLASS_PROPERTY_PREFIX(player, crouchsprite, S, PlayerPawn)
PROP_STRING_PARM(z, 0);
if (strlen(z) == 4)
{
defaults->crouchsprite = GetSpriteIndex (z);
defaults->IntVar(NAME_crouchsprite) = GetSpriteIndex (z);
}
else if (*z == 0)
{
defaults->crouchsprite = 0;
defaults->IntVar(NAME_crouchsprite) = 0;
}
else
{
Oops, something went wrong.

0 comments on commit 3314a1e

Please sign in to comment.
You can’t perform that action at this time.