func_friction: Added implementation of a friction modifier for player entities. This affects pmove.c as well.
This commit is contained in:
parent
a3ade0deab
commit
1b27e26582
3 changed files with 106 additions and 5 deletions
|
@ -5,5 +5,6 @@
|
|||
#includelist
|
||||
shared/decals.cpp
|
||||
shared/spraylogo.cpp
|
||||
shared/func_friction.cpp
|
||||
shared/trigger_gravity.cpp
|
||||
#endlist
|
||||
|
|
90
src/gs-entbase/shared/func_friction.cpp
Normal file
90
src/gs-entbase/shared/func_friction.cpp
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/*QUAKED func_friction (0 .5 .8) ?
|
||||
"targetname" Name
|
||||
"modifier" Friction modifier.
|
||||
|
||||
Volume that permanently adds a modifier that affects an entities' friction.
|
||||
Higher value = less friction.
|
||||
*/
|
||||
|
||||
#ifdef CLIENT
|
||||
class func_friction:CBaseEntity
|
||||
#else
|
||||
class func_friction:CBaseTrigger
|
||||
#endif
|
||||
{
|
||||
float m_flFriction;
|
||||
void(void) func_friction;
|
||||
virtual void(void) touch;
|
||||
virtual void(void) Respawn;
|
||||
|
||||
#ifdef CLIENT
|
||||
virtual void(void) Initialized;
|
||||
virtual void(string, string) SpawnKey;
|
||||
#endif
|
||||
};
|
||||
|
||||
void func_friction::touch(void)
|
||||
{
|
||||
other.friction = m_flFriction;
|
||||
}
|
||||
|
||||
/* TODO: Make this redundant */
|
||||
void func_friction::Respawn(void)
|
||||
{
|
||||
solid = SOLID_BSPTRIGGER;
|
||||
#ifdef GS_DEVELOPER
|
||||
alpha = 0.5f;
|
||||
#endif
|
||||
}
|
||||
|
||||
void func_friction::func_friction(void)
|
||||
{
|
||||
#ifdef SERVER
|
||||
for (int i = 1; i < (tokenize(__fullspawndata) - 1); i += 2) {
|
||||
switch (argv(i)) {
|
||||
case "modifier":
|
||||
m_flFriction = stof(argv(i+1));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
CBaseEntity::CBaseEntity();
|
||||
CBaseTrigger::InitBrushTrigger();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef CLIENT
|
||||
void func_friction::Initialized (void)
|
||||
{
|
||||
setmodel(this, model);
|
||||
movetype = MOVETYPE_NONE;
|
||||
solid = SOLID_BSPTRIGGER;
|
||||
}
|
||||
void func_friction::SpawnKey(string strField, string strKey)
|
||||
{
|
||||
switch (strField) {
|
||||
case "modifier":
|
||||
m_flFriction = stof(strKey);
|
||||
break;
|
||||
default:
|
||||
CBaseEntity::SpawnKey(strField, strKey);
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -382,10 +382,19 @@ PMove_AccelLadder(float move_time, float premove, vector wish_dir, float wish_sp
|
|||
void
|
||||
PMove_AccelFriction(float move_time, float premove, vector wish_dir, float wish_speed)
|
||||
{
|
||||
float flApplyFriction;
|
||||
float flFriction;
|
||||
vector vecTemp;
|
||||
|
||||
// friction
|
||||
flApplyFriction = serverkeyfloat("phy_friction");
|
||||
|
||||
/* per frame basis friction modifier */
|
||||
if (self.friction != 0.0f) {
|
||||
flApplyFriction /= self.friction;
|
||||
self.friction = 0.0f;
|
||||
}
|
||||
|
||||
/* apply friction */
|
||||
if (self.velocity[0] || self.velocity[1]) {
|
||||
vecTemp = self.velocity;
|
||||
vecTemp[2] = 0;
|
||||
|
@ -398,15 +407,16 @@ PMove_AccelFriction(float move_time, float premove, vector wish_dir, float wish_
|
|||
// apply friction
|
||||
if (trace_fraction == 1.0) {
|
||||
if (flFriction < serverkeyfloat("phy_stopspeed")) {
|
||||
flFriction = 1 - move_time * (serverkeyfloat("phy_stopspeed") / flFriction) * serverkeyfloat("phy_friction") * serverkeyfloat("phy_edgefriction");
|
||||
flFriction = 1 - move_time * (serverkeyfloat("phy_stopspeed") / flFriction) * flApplyFriction * serverkeyfloat("phy_edgefriction");
|
||||
} else {
|
||||
flFriction = 1 - move_time * serverkeyfloat("phy_friction") * serverkeyfloat("phy_edgefriction");
|
||||
flFriction = 1 - move_time * flApplyFriction * serverkeyfloat("phy_edgefriction");
|
||||
}
|
||||
} else {
|
||||
if (flFriction < serverkeyfloat("phy_stopspeed")) {
|
||||
flFriction = 1 - move_time * (serverkeyfloat("phy_stopspeed") / flFriction) * serverkeyfloat("phy_friction");
|
||||
flFriction = 1 - move_time * (serverkeyfloat("phy_stopspeed") / flFriction) * flApplyFriction;
|
||||
} else {
|
||||
flFriction = 1 - move_time * serverkeyfloat("phy_friction");
|
||||
|
||||
flFriction = 1 - move_time * flApplyFriction;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue