PropData: debris/gibs can now create decals upon impact with a surface

This commit is contained in:
Marco Cawthorne 2023-09-20 15:10:29 -07:00
parent d9d3220833
commit 4a8df93395
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
6 changed files with 52 additions and 8 deletions

13
src/shared/NSDebris.h Normal file
View File

@ -0,0 +1,13 @@
#ifdef CLIENT
class NSDebris:NSRenderableEntity
{
public:
void NSDebris(void);
virtual void Touch(entity);
nonvirtual void SetImpactDecal(string);
private:
string m_strImpactDecal;
};
#endif

20
src/shared/NSDebris.qc Normal file
View File

@ -0,0 +1,20 @@
#ifdef CLIENT
void
NSDebris::NSDebris(void)
{
m_strImpactDecal = __NULL__;
}
void
NSDebris::Touch(entity touchingEnt)
{
if (m_strImpactDecal)
DecalGroups_Place(m_strImpactDecal, origin);
}
void
NSDebris::SetImpactDecal(string impactDecal)
{
m_strImpactDecal = impactDecal;
}
#endif

View File

@ -31,15 +31,16 @@ DecalGroups_CountLine(string line)
break;
case "}":
braced--;
if (t_name)
g_decalgroup_count++;
t_name = "";
break;
default:
/* new definition starts */
if (c == 1 && braced == 0) {
t_name = strtolower(line);
if (t_name)
g_decalgroup_count++;
}
}
return;
@ -64,8 +65,11 @@ DecalGroups_Parse(string line)
break;
case "}":
/* increase counter when done */
if (t_name)
if (t_name) {
hash_add(g_hashdecalgroup, t_name, (int)i);
g_decalgroup_count++;
i++;
}
braced--;
t_name = "";
@ -86,8 +90,6 @@ DecalGroups_Parse(string line)
#endif
} else if (braced == 0) {
t_name = strtolower(line);
hash_add(g_hashdecalgroup, t_name, (int)i);
g_decalgroup_count++;
}
}
}
@ -161,6 +163,7 @@ DecalGroups_Precache(void)
for (int x = 0; x < c; x++) {
Decal_Precache(argv(x));
}
}
}

View File

@ -97,6 +97,7 @@ string __fullspawndata;
#include "NSItem.h"
#include "NSSpraylogo.h"
#include "NSPortal.h"
#include "NSDebris.h"
#include "../xr/defs.h"
#include "NSClient.h"

View File

@ -18,6 +18,7 @@ NSTalkMonster.qc
NSProjectile.qc
NSItem.qc
NSPortal.qc
NSDebris.qc
NSClient.qc
NSClientSpectator.qc

View File

@ -497,7 +497,7 @@ BreakModel_SpawnID(vector smins, vector smaxs, vector dir, float speed, int coun
string mname;
string fullline;
float fadetime;
NSRenderableEntity gib;
NSDebris gib;
int r;
int p;
int bodygroup = 0;
@ -505,6 +505,7 @@ BreakModel_SpawnID(vector smins, vector smaxs, vector dir, float speed, int coun
float renderamt = 1.0f;
float rendermode = RM_NORMAL;
float renderfx = RFX_NORMAL;
string impactDecal = __NULL__;
/* pick a model between 0 and num) */
r = floor(random(0, modelcount));
@ -544,6 +545,9 @@ BreakModel_SpawnID(vector smins, vector smaxs, vector dir, float speed, int coun
case "renderfx":
renderfx = stof(value);
break;
case "impactdecal":
impactDecal = value;
break;
default:
print(sprintf("^1BreakModel_Spawn: Unrecognized model attribute %S with value %S\n",
key, value));
@ -559,7 +563,7 @@ BreakModel_SpawnID(vector smins, vector smaxs, vector dir, float speed, int coun
endpos[1] = smins[1] + ( random() * ( smaxs[1] - smins[1] ) );
endpos[2] = smins[2] + ( random() * ( smaxs[2] - smins[2] ) );
gib = spawn(NSRenderableEntity);
gib = spawn(NSDebris);
gib.SetModel(mname);
gib.SetBody(bodygroup);
gib.SetRenderColor(rendercolor);
@ -575,7 +579,9 @@ BreakModel_SpawnID(vector smins, vector smaxs, vector dir, float speed, int coun
gib.velocity[2] += (random() - 0.5) * (speed * 0.25);
gib.SetAngularVelocity(vectoangles(gib.velocity));
gib.SetMovetype(MOVETYPE_BOUNCE);
gib.SetSolid(SOLID_BBOX);
gib.ScheduleThink(NSEntity::Destroy, fadetime);
gib.SetImpactDecal(impactDecal);
#ifdef CLIENT
gib.drawmask = MASK_ENGINE;