diff --git a/src/gs-entbase/server.src b/src/gs-entbase/server.src index ac8e0cd5..5ba38f1e 100644 --- a/src/gs-entbase/server.src +++ b/src/gs-entbase/server.src @@ -55,6 +55,7 @@ server/func_wall_toggle.cpp server/func_conveyor.cpp server/func_rotating.cpp server/func_rot_button.cpp +server/func_physbox.cpp server/func_plat.cpp server/func_pendulum.cpp server/func_vehicle.cpp diff --git a/src/gs-entbase/server/basephysics.cpp b/src/gs-entbase/server/basephysics.cpp index 38b8dacc..46b08bc3 100644 --- a/src/gs-entbase/server/basephysics.cpp +++ b/src/gs-entbase/server/basephysics.cpp @@ -14,10 +14,110 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +void +CBasePhysics::PhysicsEnable(void) +{ +#ifdef GS_PHYSICS + physics_enable(this, TRUE); +#else + print("^1CBasePhysics::PhysicsEnable: "); + print("^7Physics simulator not enabled.\n"); +#endif + m_iEnabled = TRUE; +} + +void +CBasePhysics::PhysicsDisable(void) +{ +#ifdef GS_PHYSICS + physics_enable(this, FALSE); +#else + print("^1CBasePhysics::PhysicsDisable: "); + print("^7Physics simulator not enabled.\n"); +#endif + m_iEnabled = FALSE; +} + +void +CBasePhysics::SetMass(float val) +{ + mass = val; +} +float +CBasePhysics::GetMass(void) +{ + return mass; +} + +void +CBasePhysics::SetFriction(float val) +{ + friction = val; +} +float +CBasePhysics::GetFriction(void) +{ + return friction; +} + +void +CBasePhysics::SetBounceFactor(float val) +{ + bouncefactor = val; +} +float +CBasePhysics::GetBounceFactor(void) +{ + return bouncefactor; +} + +void +CBasePhysics::SetInertia(float val) +{ + m_flInertiaScale = val; +} +float +CBasePhysics::GetInertia(void) +{ + return m_flInertiaScale; +} + +void +CBasePhysics::ApplyForceCenter(vector vecForce) +{ +#ifdef GS_PHYSICS + physics_addforce(this, vecForce, [0,0,0]); +#else + print("^1CBasePhysics::ApplyForceCenter: "); + print("^7Physics simulator not enabled.\n"); +#endif +} + +void +CBasePhysics::ApplyForceOffset(vector vecForce, vector vecOffset) +{ +#ifdef GS_PHYSICS + physics_addforce(this, vecForce, vecOffset); +#else + print("^1CBasePhysics::ApplyForceOffset: "); + print("^7Physics simulator not enabled.\n"); +#endif +} + +void +CBasePhysics::ApplyTorqueCenter(vector vecTorque) +{ +#ifdef GS_PHYSICS + physics_addtorque(this, vecTorque * m_flInertia); +#else + print("^1CBasePhysics::ApplyTorqueCenter: "); + print("^7Physics simulator not enabled.\n"); +#endif +} + void CBasePhysics::TouchThink(void) { -#ifdef GS_BULLET_PHYSICS /* let players collide */ dimension_solid = 255; dimension_hit = 255; @@ -27,15 +127,15 @@ CBasePhysics::TouchThink(void) /* stuck */ if (trace_startsolid) { if (trace_ent.flags & FL_CLIENT) { - physics_enable(this, TRUE); + PhysicsEnable(); makevectors(vectoangles(origin - trace_ent.origin)); - velocity = v_forward * 256; + ApplyTorqueCenter([25,0,0]); } } /* If we barely move, disable the physics simulator */ - if (vlen(velocity) <= 1) { - physics_enable(this, FALSE); + if (vlen(velocity) <= 1 && m_iEnabled) { + PhysicsDisable(); } /* don't let players collide */ @@ -45,43 +145,41 @@ CBasePhysics::TouchThink(void) /* continue testing next frame */ nextthink = time; effects &= ~EF_NOSHADOW; -#endif } void CBasePhysics::touch(void) { -#ifdef GS_BULLET_PHYSICS + PhysicsEnable(); makevectors(vectoangles(origin - other.origin)); - physics_addforce(this, v_forward, other.origin); - physics_enable(this, TRUE); -#endif + ApplyForceOffset(v_forward, origin - other.origin); } void CBasePhysics::Pain(void) { -#ifdef GS_BULLET_PHYSICS + if (m_iFlags & BPHY_NODMGPUSH) + return; + + PhysicsEnable(); makevectors(vectoangles(origin - trace_endpos)); - physics_addforce(this, v_forward * 20, trace_endpos); + ApplyForceOffset(v_forward * 20, origin - trace_endpos); health = 100000; - physics_enable(this, TRUE); -#endif } void CBasePhysics::Respawn(void) { -#ifdef GS_BULLET_PHYSICS - movetype = MOVETYPE_PHYSICS; - solid = SOLID_PHYSICS_BOX + m_iShape; + SetMovetype(MOVETYPE_PHYSICS); + SetSolid(SOLID_PHYSICS_BOX + m_iShape); geomtype = GEOMTYPE_BOX; SetModel(m_oldModel); SetOrigin(m_oldOrigin); - physics_enable(this, TRUE); takedamage = DAMAGE_YES; health = 100000; - mass = m_flMass; + PhysicsDisable(); + SetFriction(2.0f); + SetBounceFactor(0.25f); /* don't let players collide */ dimension_solid = 1; @@ -89,12 +187,6 @@ CBasePhysics::Respawn(void) think = TouchThink; nextthink = time + 0.1f; -#else - movetype = MOVETYPE_NONE; - solid = SOLID_BBOX; - SetModel(m_oldModel); - SetOrigin(m_oldOrigin); -#endif effects &= ~EF_NOSHADOW; } @@ -110,13 +202,24 @@ CBasePhysics::SpawnKey(string strKey, string strValue) } break; case "massscale": - m_flMass = stof(strValue); + mass = stof(strValue); + break; + case "inertiascale": + m_flInertiaScale = stof(strValue); break; case "physdamagescale": break; case "material": m_iMaterial = stof(strValue); break; + case "nodamageforces": + if (strValue == "1") + m_iFlags |= BPHY_NODMGPUSH; + break; + case "Damagetype": + if (strValue == "1") + m_iFlags |= BPHY_SHARP; + break; default: CBaseEntity::SpawnKey(strKey, strValue); break; @@ -126,6 +229,8 @@ CBasePhysics::SpawnKey(string strKey, string strValue) void CBasePhysics::CBasePhysics(void) { + mass = 1.0f; + m_flInertiaScale = 1.0f; + CBaseEntity::CBaseEntity(); - m_flMass = 1.0f; } diff --git a/src/gs-entbase/server/basephysics.h b/src/gs-entbase/server/basephysics.h index 0624d3fe..6b7ca39c 100644 --- a/src/gs-entbase/server/basephysics.h +++ b/src/gs-entbase/server/basephysics.h @@ -23,16 +23,37 @@ enum PHYSM_CYLINDER }; +enumflags +{ + BPHY_NODMGPUSH, + BPHY_SHARP +}; + class CBasePhysics:CBaseEntity { + int m_iEnabled; int m_iShape; int m_iMaterial; - float m_flMass; + int m_iFlags; + float m_flInertiaScale; void(void) CBasePhysics; virtual void(void) Respawn; virtual void(void) touch; virtual void(void) TouchThink; virtual void(void) Pain; + + virtual void(float) SetMass; + virtual float(void) GetMass; + virtual void(float) SetFriction; + virtual float(void) GetFriction; + virtual void(float) SetBounceFactor; + virtual float(void) GetBounceFactor; + virtual void(void) PhysicsEnable; + virtual void(void) PhysicsDisable; + virtual void(vector) ApplyForceCenter; + virtual void(vector, vector) ApplyForceOffset; + virtual void(vector) ApplyTorqueCenter; + virtual void(string, string) SpawnKey; }; diff --git a/src/gs-entbase/server/func_door_rotating.cpp b/src/gs-entbase/server/func_door_rotating.cpp index 0fb89c58..46f26e8a 100644 --- a/src/gs-entbase/server/func_door_rotating.cpp +++ b/src/gs-entbase/server/func_door_rotating.cpp @@ -71,12 +71,12 @@ class func_door_rotating:CBaseTrigger virtual void(vector angle, void(void) func) RotToDest; virtual void(string, string) SpawnKey; -#ifdef GS_BULLET_PHYSICS +#ifdef GS_PHYSICS virtual void(void) Unhinge; #endif }; -#ifdef GS_BULLET_PHYSICS +#ifdef GS_PHYSICS void func_door_rotating::Unhinge(void) { takedamage = DAMAGE_NO; @@ -297,7 +297,7 @@ void func_door_rotating::Respawn(void) { func_door_rotating::SetMovementDirection(); -#ifdef GS_BULLET_PHYSICS +#ifdef GS_PHYSICS takedamage = DAMAGE_YES; health = 100; Death = func_door_rotating::Unhinge; diff --git a/src/gs-entbase/server/func_physbox_multiplayer.cpp b/src/gs-entbase/server/func_physbox.cpp similarity index 60% rename from src/gs-entbase/server/func_physbox_multiplayer.cpp rename to src/gs-entbase/server/func_physbox.cpp index 09d2bd75..263d0756 100644 --- a/src/gs-entbase/server/func_physbox_multiplayer.cpp +++ b/src/gs-entbase/server/func_physbox.cpp @@ -14,64 +14,35 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/*QUAKED func_physbox_multiplayer (0 .5 .8) ? -"targetname" Name - -Physics brush (server) - same for all player on server -*/ - /*QUAKED func_physbox (0 .5 .8) ? "targetname" Name Physics brush (client) */ -class func_physbox:CBaseEntity +class func_physbox:CBasePhysics { int m_iShape; void(void) func_physbox; - virtual void(void) Respawn; - virtual void(void) touch; virtual void(string, string) SpawnKey; }; -void func_physbox::touch(void) -{ - //physics_addforce(this, other.velocity, other.origin); -} - void func_physbox::Respawn(void) { - SetMovetype(MOVETYPE_PHYSICS); - SetSolid(SOLID_PHYSICS_BOX); // SOLID_PHYSICS_TRIMESH - SetModel(m_oldModel); - SetOrigin(m_oldOrigin); - physics_enable(this, TRUE); + CBasePhysics::Respawn(); } void func_physbox::SpawnKey(string strKey, string strValue) { switch (strKey) { - case "material": - //m_iMaterial = stof(strValue); - break; default: - CBaseEntity::SpawnKey(strKey, strValue); + CBasePhysics::SpawnKey(strKey, strValue); } } void func_physbox::func_physbox(void) { - if (!model) { - remove(this); - return; - } - - CBaseEntity::CBaseEntity(); - + CBasePhysics::CBasePhysics(); } - -CLASSEXPORT(func_physbox, func_physbox) -CLASSEXPORT(func_physbox_multiplayer, func_physbox)