CBasePhysics: add support for explosions upon destruction, provided via

propdata.
This commit is contained in:
Marco Cawthorne 2021-09-21 21:11:02 +02:00
parent 251713121c
commit 451beedb0c
Signed by: eukara
GPG key ID: C196CD8BA993248A
3 changed files with 19 additions and 8 deletions

View file

@ -32,8 +32,8 @@ CBasePhysics::PhysicsDisable(void)
if (physics_supported() == TRUE) {
physics_enable(this, FALSE);
} else {
SetMovetype(MOVETYPE_NONE);
SetSolid(SOLID_NOT);
SetMovetype(MOVETYPE_BOUNCE);
SetSolid(SOLID_CORPSE);
}
m_iEnabled = FALSE;
}
@ -184,7 +184,6 @@ CBasePhysics::Pain(void)
makevectors(vectoangles(origin - trace_endpos));
ApplyForceOffset(v_forward * 20, origin - trace_endpos);
if (!HasPropData()) {
health = 100000;
}
@ -198,6 +197,19 @@ CBasePhysics::Death(void)
string gibeffect = GetPropData(PROPINFO_BREAKMODEL);
int breakcount = GetPropData(PROPINFO_BREAKCOUNT);
BreakModel_Spawn(origin, [0,0,0], [100,100], 100, breakcount, gibeffect);
/* handle explosions */
float flExplodeMag, flExplodeRad;
flExplodeMag = GetPropData(PROPINFO_EXPLOSIVE_DMG);
flExplodeRad = GetPropData(PROPINFO_EXPLOSIVE_RADIUS);
if (flExplodeMag) {
if (!flExplodeRad)
flExplodeRad = flExplodeMag * 2.5f;
FX_Explosion(origin);
Damage_Radius(origin, this, flExplodeMag, flExplodeRad, TRUE, 0);
}
}
void

View file

@ -967,7 +967,7 @@ CBaseEntity::SetModel(string newModel)
SetSendFlags(BASEFL_CHANGED_MODELINDEX);
if (model && m_iPropData == -1) {
PropData_ForModel(model);
m_iPropData = PropData_ForModel(model);
}
}
void

View file

@ -140,7 +140,7 @@ PropData_Parse(int i, string line, string type)
/* name/identifer of our message */
t_name = strtolower(key);
if (t_name == type) {
if (t_name == "prop_data") {
/* I guess it's what we want */
g_propdata[i].name = type;
} else {
@ -197,9 +197,10 @@ PropData_ForModel(string modelname)
}
while ((line = fgets(fh))) {
/* when we found it, quit */
if (PropData_Parse(index, line, "prop_data") == TRUE) {
if (PropData_Parse(index, line, modelname) == TRUE) {
fclose(fh);
hash_add(g_hashpropdata, modelname, (int)index);
print(sprintf("adding propdata %s at %i\n", modelname, index));
return index;
}
}
@ -427,8 +428,6 @@ BreakModel_Spawn(vector pos, vector dir, vector spread, float speed, int count,
float x = tokenize(g_breakmodel[index].data);
int modelcount = x / 2;
print(sprintf("breakmodel: %s, %i\n", type, count));
for (int i = 0; i < count; i++) {
string mname;
float fadetime;