SurfData: Goodbye to DAMAGE_MATERIAL. We streamline that process now so

that all entities will use surfaceParm defined info by default unless
overriden by an entity. + Set up sane defaults for surface properties.
This commit is contained in:
Marco Cawthorne 2021-11-13 01:38:20 +01:00
parent 40da8b09f9
commit 08c3a4a576
Signed by: eukara
GPG Key ID: C196CD8BA993248A
9 changed files with 225 additions and 195 deletions

View File

@ -59,5 +59,4 @@ class NSPhysicsEntity:NSSurfacePropEntity
virtual void(vector, vector) ApplyForceOffset;
virtual void(vector) ApplyTorqueCenter;
virtual float(int, int) CalculateImpactDamage;
};

View File

@ -27,7 +27,7 @@ Client-side decorative model entity.
This entity was introduced in Half-Life 2 (2004).
*/
class prop_dynamic:NSRenderableEntity
class prop_dynamic:NSSurfacePropEntity
{
void(void) prop_dynamic;
@ -40,11 +40,16 @@ prop_dynamic::Respawn(void)
super::Respawn();
SetModel(GetSpawnModel());
SetSolid(SOLID_CORPSE);
takedamage = DAMAGE_MATERIAL;
if (HasPropData()) {
health = GetPropData(PROPINFO_HEALTH);
takedamage = DAMAGE_YES;
} else {
}
}
void
prop_dynamic::prop_dynamic(void)
{
super::NSRenderableEntity();
super::NSSurfacePropEntity();
}

View File

@ -51,7 +51,6 @@ prop_static::Respawn(void)
super::Respawn();
SetModel(GetSpawnModel());
SetSolid(SOLID_CORPSE);
takedamage = DAMAGE_MATERIAL;
}
void

View File

@ -896,4 +896,4 @@ NSMonster_ReadEntity(float new)
}
me.ReceiveEntity(readfloat());
}
#endif
#endif

View File

@ -120,6 +120,7 @@ NSSurfacePropEntity::SpawnKey(string strKey, string strValue)
case "propdata":
SetPropData(strValue);
break;
case "surfdata":
case "materialdata":
SetSurfaceData(strValue);
break;
@ -195,4 +196,4 @@ NSSurfacePropEntity::NSSurfacePropEntity(void)
SurfaceDataFinish();
PropDataFinish();
#endif
}
}

View File

@ -1,50 +1,44 @@
/*
* 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.
*/
typedef enumflags
{
DMG_GENERIC,
DMG_CRUSH,
DMG_BULLET,
DMG_SLASH,
DMG_BURN,
DMG_VEHICLE,
DMG_FALL,
DMG_EXPLODE,
DMG_BLUNT,
DMG_ELECTRO,
DMG_SOUND,
DMG_ENERGYBEAM,
DMG_GIB_NEVER,
DMG_GIB_ALWAYS,
DMG_DROWN,
DMG_PARALYZE,
DMG_NERVEGAS,
DMG_POISON,
DMG_RADIATION,
DMG_DROWNRECOVER,
DMG_ACID,
DMG_SLOWBURN,
DMG_SLOWFREEZE,
DMG_SKIP_ARMOR,
DMG_SKIP_RAGDOLL
} damageType_t;
/* takedamage types */
const float DAMAGE_NO = 0;
const float DAMAGE_YES = 1;
const float DAMAGE_AIM = 2;
const float DAMAGE_MATERIAL = 3;
/*
* 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.
*/
typedef enumflags
{
DMG_GENERIC,
DMG_CRUSH,
DMG_BULLET,
DMG_SLASH,
DMG_BURN,
DMG_VEHICLE,
DMG_FALL,
DMG_EXPLODE,
DMG_BLUNT,
DMG_ELECTRO,
DMG_SOUND,
DMG_ENERGYBEAM,
DMG_GIB_NEVER,
DMG_GIB_ALWAYS,
DMG_DROWN,
DMG_PARALYZE,
DMG_NERVEGAS,
DMG_POISON,
DMG_RADIATION,
DMG_DROWNRECOVER,
DMG_ACID,
DMG_SLOWBURN,
DMG_SLOWFREEZE,
DMG_SKIP_ARMOR,
DMG_SKIP_RAGDOLL
} damageType_t;

View File

@ -190,4 +190,4 @@ setorigin_safe(entity target, vector testorg)
}
setorigin(target, testorg);
}
}

View File

@ -1,133 +1,133 @@
/*
* Copyright (c) 2016-2021 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.
*/
/*
Surface Data Specs
Scripts are formatted like our sound shaders:
typename
{
key/value pairs
...
}
Available keys are:
"base" <string> what type to inherit
"gamematerial" <char> material character, e.g. W for wood
"climbable" <bool> ???
"thickness" <float> non-solid, air (?) thickness
"density" <int> material density in kg / m^3
"elasticity" <float> 0.0 - 1.0 ; soft to hard
"friction" <float> friction multiplier
"dampening" <float> drag multiplier
"jumpfactor" <float> bouncyness?
"maxspeedfactor" <float> maxvelocity?
/*
* Copyright (c) 2016-2021 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.
*/
"stepleft" <string> footstep left
"stepright" <string> footstep right
"bulletimpact" <string> sound shader to play on impact
"scraperough" <string> sound shader to play on rough scraping
"scrapesmooth" <string> sound shader to play on smooth scraping
"impacthard" <string> sound shader for hard impacts
"impactsoft" <string> sound shader for soft impacts
"shake" <string> sound to play when object is being shaken
"strain" <string> sound to play when object is being strained?
"break" <string> sound to play when object breaks
"roll/rolling" <string> sound to play when object rolls
/*
Surface Data Specs
none of these are concerning us right now:
"audioreflectivity" <float>
"audiohardnessfactor" <float>
"audioroughnessfactor" <float>
"scrapeRoughThreshold" <float>
"impactHardThreshold" <float>
"audioHardMinVelocity" <float>
*/
#ifdef SERVER
typedef struct
{
string m_strBase;
float m_flMaterial;
float m_flThickness;
float m_flDensity;
float m_flElasticity;
float m_flFriction;
float m_flDampening;
float m_flJumpFactor;
float m_flMaxSpeedFactor;
string m_sndStepLeft;
string m_sndStepRight;
string m_sndBulletImpact;
string m_sndScrapeRough;
string m_sndScrapeSoft;
string m_sndImpactHard;
string m_sndImpactSoft;
string m_sndShake;
string m_sndStrain;
string m_sndRoll;
string m_sndBreak;
} surfaceData_t;
/* entity will have to have a .surfdata field pointing to an id */
surfaceData_t *g_surfdata;
int g_surfdata_count;
var hashtable g_hashsurfdata;
/* querying API */
typedef enum
{
SURFDATA_MATERIAL,
SURFDATA_THICKNESS,
SURFDATA_DENSITY,
SURFDATA_ELASTICITY,
SURFDATA_FRICTION,
SURFDATA_DAMPENING,
SURFDATA_JUMPFACTOR,
SURFDATA_MAXSPEEDFACTOR,
SURFDATA_SND_STEPLEFT,
SURFDATA_SND_STEPRIGHT,
SURFDATA_SND_BULLETIMPACT,
SURFDATA_SND_SCRAPEROUGH,
SURFDATA_SND_SCRAPESOFT,
SURFDATA_SND_IMPACTHARD,
SURFDATA_SND_IMPACTSOFT,
SURFDATA_SND_SHAKE,
SURFDATA_SND_STRAIN,
SURFDATA_SND_ROLL,
SURFDATA_SND_BREAK,
SURFDATA_FX_IMPACT,
} surfinfo_t;
/* initialized SurfaceKit */
void SurfData_Init(void);
/* Prepares an object for SurfaceKit initialization */
void SurfData_SetStage(string type);
/* Finishes initialization, returns valid SurfaceKit id */
int SurfData_Finish(void);
/* Call an impact effect against an entity surface */
void SurfData_Impact(entity e, int fl, vector org, vector ang);
/* Get information from a Surface */
__variant SurfData_GetInfo(int, int);
#endif
Scripts are formatted like our sound shaders:
typename
{
key/value pairs
...
}
Available keys are:
"base" <string> what type to inherit
"gamematerial" <char> material character, e.g. W for wood
"climbable" <bool> ???
"thickness" <float> non-solid, air (?) thickness
"density" <int> material density in kg / m^3
"elasticity" <float> 0.0 - 1.0 ; soft to hard
"friction" <float> friction multiplier
"dampening" <float> drag multiplier
"jumpfactor" <float> bouncyness?
"maxspeedfactor" <float> maxvelocity?
"stepleft" <string> footstep left
"stepright" <string> footstep right
"bulletimpact" <string> sound shader to play on impact
"scraperough" <string> sound shader to play on rough scraping
"scrapesmooth" <string> sound shader to play on smooth scraping
"impacthard" <string> sound shader for hard impacts
"impactsoft" <string> sound shader for soft impacts
"shake" <string> sound to play when object is being shaken
"strain" <string> sound to play when object is being strained?
"break" <string> sound to play when object breaks
"roll/rolling" <string> sound to play when object rolls
none of these are concerning us right now:
"audioreflectivity" <float>
"audiohardnessfactor" <float>
"audioroughnessfactor" <float>
"scrapeRoughThreshold" <float>
"impactHardThreshold" <float>
"audioHardMinVelocity" <float>
*/
#ifdef SERVER
typedef struct
{
string m_strBase;
float m_flMaterial;
float m_flThickness;
float m_flDensity;
float m_flElasticity;
float m_flFriction;
float m_flDampening;
float m_flJumpFactor;
float m_flMaxSpeedFactor;
string m_sndStepLeft;
string m_sndStepRight;
string m_sndBulletImpact;
string m_sndScrapeRough;
string m_sndScrapeSoft;
string m_sndImpactHard;
string m_sndImpactSoft;
string m_sndShake;
string m_sndStrain;
string m_sndRoll;
string m_sndBreak;
} surfaceData_t;
/* entity will have to have a .surfdata field pointing to an id */
surfaceData_t *g_surfdata;
int g_surfdata_count;
var hashtable g_hashsurfdata;
/* querying API */
typedef enum
{
SURFDATA_MATERIAL,
SURFDATA_THICKNESS,
SURFDATA_DENSITY,
SURFDATA_ELASTICITY,
SURFDATA_FRICTION,
SURFDATA_DAMPENING,
SURFDATA_JUMPFACTOR,
SURFDATA_MAXSPEEDFACTOR,
SURFDATA_SND_STEPLEFT,
SURFDATA_SND_STEPRIGHT,
SURFDATA_SND_BULLETIMPACT,
SURFDATA_SND_SCRAPEROUGH,
SURFDATA_SND_SCRAPESOFT,
SURFDATA_SND_IMPACTHARD,
SURFDATA_SND_IMPACTSOFT,
SURFDATA_SND_SHAKE,
SURFDATA_SND_STRAIN,
SURFDATA_SND_ROLL,
SURFDATA_SND_BREAK,
SURFDATA_FX_IMPACT,
} surfinfo_t;
/* initialized SurfaceKit */
void SurfData_Init(void);
/* Prepares an object for SurfaceKit initialization */
void SurfData_SetStage(string type);
/* Finishes initialization, returns valid SurfaceKit id */
int SurfData_Finish(void);
/* Call an impact effect against an entity surface */
void SurfData_Impact(entity e, int fl, vector org, vector ang);
/* Get information from a Surface */
__variant SurfData_GetInfo(int, int);
#endif

View File

@ -364,8 +364,6 @@ SurfData_Init(void)
g_hashsurfdata = hash_createtab(2, HASH_ADD);
}
/* Defaults go here */
fh = fopen("scripts/surfaceproperties.txt", FILE_READ);
if (fh < 0) {
print("^1[SURFDATA] Can't find surfaceproperties.txt\n");
@ -380,6 +378,31 @@ SurfData_Init(void)
/* alocate our stuff */
g_surfdata = (surfaceData_t *)memalloc(sizeof(surfaceData_t) * g_surfdata_count);
/* Defaults */
for (int i = 0; i < g_surfdata_count; i++) {
g_surfdata[i].m_strBase = "";
g_surfdata[i].m_flMaterial = -1;
g_surfdata[i].m_flThickness = 1.0f;
g_surfdata[i].m_flDensity = 1.0f;
g_surfdata[i].m_flElasticity = 1.0f;
g_surfdata[i].m_flFriction = 1.0f;
g_surfdata[i].m_flDampening = 1.0f;
g_surfdata[i].m_flJumpFactor = 1.0f;
g_surfdata[i].m_flMaxSpeedFactor = 1.0f;
g_surfdata[i].m_sndStepLeft = "";
g_surfdata[i].m_sndStepRight = "";
g_surfdata[i].m_sndBulletImpact = "";
g_surfdata[i].m_sndScrapeRough = "";
g_surfdata[i].m_sndScrapeSoft = "";
g_surfdata[i].m_sndImpactHard = "";
g_surfdata[i].m_sndImpactSoft = "";
g_surfdata[i].m_sndShake = "";
g_surfdata[i].m_sndStrain = "";
g_surfdata[i].m_sndRoll = "";
g_surfdata[i].m_sndBreak = "";
}
fseek(fh, 0);
while ((line = fgets(fh))) {
@ -415,7 +438,7 @@ SurfData_Finish(void)
void
SurfData_Impact(entity e, int fl, vector org, vector ang)
{
if (e == world || e.health == 0 || e.takedamage == 3) { /* the static world */
static void SurfData_Impact_SurfaceParm(entity e, int fl, vector org, vector ang) {
switch (serverkeyfloat("*bspversion")) {
case BSPVER_HL:
float surf;
@ -432,9 +455,18 @@ SurfData_Impact(entity e, int fl, vector org, vector ang)
default:
FX_Impact(IMPACT_DEFAULT, org, ang);
}
} else { /* props */
}
/* the static world */
if (e == world || e.takedamage == DAMAGE_NO) {
SurfData_Impact_SurfaceParm(e, fl, org, ang);
} else { /* anything with takedamage = DAMAGE_YES is a NSurfacePropEntity. */
NSSurfacePropEntity foo = (NSSurfacePropEntity)e;
FX_Impact(foo.GetSurfaceData(SURFDATA_FX_IMPACT), org, ang);
if (foo.GetSurfaceData(SURFDATA_MATERIAL) == -1)
SurfData_Impact_SurfaceParm(e, fl, org, ang);
else
FX_Impact(foo.GetSurfaceData(SURFDATA_FX_IMPACT), org, ang);
}
}
#endif
#endif