Skip to content

Commit

Permalink
Add per-actor friction
Browse files Browse the repository at this point in the history
- This is multiplied by the sector's friction.
- This is intentionally not serialized yet, while awaiting feedback.
  • Loading branch information
Randy Heit committed Jul 29, 2014
1 parent 0f8a002 commit ea7ba9d
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/actor.h
Expand Up @@ -906,6 +906,7 @@ class AActor : public DThinker
fixed_t wallbouncefactor; // The bounce factor for walls can be different.
int bouncecount; // Strife's grenades only bounce twice before exploding
fixed_t gravity; // [GRB] Gravity factor
fixed_t Friction;
int FastChaseStrafeCount;
fixed_t pushfactor;
int lastpush;
Expand Down
7 changes: 6 additions & 1 deletion src/p_acs.cpp
Expand Up @@ -3605,7 +3605,8 @@ enum
APROP_MeleeRange = 38,
APROP_ViewHeight = 39,
APROP_AttackZOffset = 40,
APROP_StencilColor = 41
APROP_StencilColor = 41,
APROP_Friction = 42,
};

// These are needed for ACS's APROP_RenderStyle
Expand Down Expand Up @@ -3839,6 +3840,9 @@ void DLevelScript::DoSetActorProperty (AActor *actor, int property, int value)
actor->SetShade(value);
break;

case APROP_Friction:
actor->Friction = value;

default:
// do nothing.
break;
Expand Down Expand Up @@ -3937,6 +3941,7 @@ int DLevelScript::GetActorProperty (int tid, int property, const SDWORD *stack,
case APROP_Species: return GlobalACSStrings.AddString(actor->GetSpecies(), stack, stackdepth);
case APROP_NameTag: return GlobalACSStrings.AddString(actor->GetTag(), stack, stackdepth);
case APROP_StencilColor:return actor->fillcolor;
case APROP_Friction: return actor->Friction;

default: return 0;
}
Expand Down
8 changes: 7 additions & 1 deletion src/p_map.cpp
Expand Up @@ -554,7 +554,13 @@ int P_GetFriction (const AActor *mo, int *frictionfactor)
}
}
}


if (mo->Friction != FRACUNIT)
{
friction = clamp(FixedMul(friction, mo->Friction), 0, FRACUNIT);
movefactor = FrictionToMoveFactor(friction);
}

if (frictionfactor)
*frictionfactor = movefactor;

Expand Down
18 changes: 2 additions & 16 deletions src/p_spec.cpp
Expand Up @@ -1990,26 +1990,12 @@ void P_SetSectorFriction (int tag, int amount, bool alterFlag)
friction = (0x1EB8*amount)/0x80 + 0xD001;

// killough 8/28/98: prevent odd situations
if (friction > FRACUNIT)
friction = FRACUNIT;
if (friction < 0)
friction = 0;
friction = clamp(friction, 0, FRACUNIT);

// The following check might seem odd. At the time of movement,
// the move distance is multiplied by 'friction/0x10000', so a
// higher friction value actually means 'less friction'.

// [RH] Twiddled these values so that velocity on ice (with
// friction 0xf900) is the same as in Heretic/Hexen.
if (friction >= ORIG_FRICTION) // ice
// movefactor = ((0x10092 - friction)*(0x70))/0x158;
movefactor = ((0x10092 - friction) * 1024) / 4352 + 568;
else
movefactor = ((friction - 0xDB34)*(0xA))/0x80;

// killough 8/28/98: prevent odd situations
if (movefactor < 32)
movefactor = 32;
movefactor = FrictionToMoveFactor(friction);

for (s = -1; (s = P_FindSectorFromTag (tag,s)) >= 0; )
{
Expand Down
19 changes: 19 additions & 0 deletions src/p_spec.h
Expand Up @@ -172,6 +172,25 @@ void P_PlayerOnSpecialFlat (player_t *player, int floorType);
void P_SectorDamage(int tag, int amount, FName type, const PClass *protectClass, int flags);
void P_SetSectorFriction (int tag, int amount, bool alterFlag);

inline fixed_t FrictionToMoveFactor(fixed_t friction)
{
fixed_t movefactor;

// [RH] Twiddled these values so that velocity on ice (with
// friction 0xf900) is the same as in Heretic/Hexen.
if (friction >= ORIG_FRICTION) // ice
// movefactor = ((0x10092 - friction)*(0x70))/0x158;
movefactor = ((0x10092 - friction) * 1024) / 4352 + 568;
else
movefactor = ((friction - 0xDB34)*(0xA))/0x80;

// killough 8/28/98: prevent odd situations
if (movefactor < 32)
movefactor = 32;

return movefactor;
}

void P_GiveSecret(AActor *actor, bool printmessage, bool playsound, int sectornum);

//
Expand Down
11 changes: 11 additions & 0 deletions src/thingdef/thingdef_properties.cpp
Expand Up @@ -1297,6 +1297,17 @@ DEFINE_PROPERTY(gravity, F, Actor)
defaults->gravity = i;
}

//==========================================================================
//
//==========================================================================
DEFINE_PROPERTY(friction, F, Actor)
{
PROP_FIXED_PARM(i, 0);

if (i < 0) I_Error ("Friction must not be negative.");
defaults->Friction = i;
}

//==========================================================================
//
//==========================================================================
Expand Down
1 change: 1 addition & 0 deletions wadsrc/static/actors/actor.txt
Expand Up @@ -18,6 +18,7 @@ ACTOR Actor native //: Thinker
FloatSpeed 4
FloatBobPhase -1 // randomly initialize by default
Gravity 1
Friction 1
DamageFactor 1.0
PushFactor 0.25
WeaveIndexXY 0
Expand Down

0 comments on commit ea7ba9d

Please sign in to comment.