Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix game crash when shockdelay is 0 bug #182

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,12 +949,20 @@ namespace game
int millis = lastmillis-d->lastres[WR_SHOCK];
size_t seed = size_t(d) + (millis/50);
float pc = 1, amt = (millis%50)/50.0f, intensity = 0.75f+(detrnd(seed, 25)*(1-amt) + detrnd(seed + 1, 25)*amt)/100.f;
if(shocktime-millis < shockdelay) pc *= float(shocktime-millis)/float(shockdelay);
// When playing on servers with an older version, shockdelay can be 0, thus avoid division by zero by enforcing new lower boundary
int fixed_shockdelay = std::max(shockdelay, 1);
if(shocktime - millis < fixed_shockdelay)
{
pc *= float(shocktime - millis) / float(fixed_shockdelay);
}
else
{
float fluc = float(millis%shockdelay)*(0.25f+0.03f)/shockdelay;
if(fluc >= 0.25f) fluc = (0.25f+0.03f-fluc)*(0.25f/0.03f);
pc *= 0.75f+fluc;
float fluc = float(millis % fixed_shockdelay) * (0.25f + 0.03f) / fixed_shockdelay;
if (fluc >= 0.25f)
{
fluc = (0.25f + 0.03f - fluc) * (0.25f / 0.03f);
}
pc *= 0.75f + fluc;
}
adddynlight(d->center(), d->height*intensity*pc, rescolour(d, PULSE_SHOCK).mul(pc), 0, 0, DL_KEEP);
}
Expand Down
8 changes: 6 additions & 2 deletions src/game/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,12 @@ namespace hud
amt += (float((lastmillis-game::focus->lastres[WR_BURN])%burndelay)/float(burndelay))*0.5f;
if(bleedtime && game::focus->bleeding(lastmillis, bleedtime))
amt += (float((lastmillis-game::focus->lastres[WR_BLEED])%bleeddelay)/float(bleeddelay))*0.5f;
if(shocktime && game::focus->shocking(lastmillis, shocktime))
amt += (float((lastmillis-game::focus->lastres[WR_SHOCK])%shockdelay)/float(shockdelay))*0.5f;
if (shocktime && game::focus->shocking(lastmillis, shocktime))
{
// When playing on servers with an older version, shockdelay can be 0, thus avoid division by zero by enforcing new lower boundary
int fixed_shockdelay = std::max(shockdelay, 1);
amt += (float((lastmillis - game::focus->lastres[WR_SHOCK]) % fixed_shockdelay) / float(fixed_shockdelay)) * 0.5f;
}
break;
}
case 2: amt = motionbluramt; break;
Expand Down
2 changes: 1 addition & 1 deletion src/game/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ GVAR(IDF_GAMEMOD, bleedtime, 0, 5500, VAR_MAX);
GVAR(IDF_GAMEMOD, bleeddelay, 0, 1000, VAR_MAX);
GVAR(IDF_GAMEMOD, bleeddamage, 0, 3, VAR_MAX);
GVAR(IDF_GAMEMOD, shocktime, 0, 5500, VAR_MAX);
GVAR(IDF_GAMEMOD, shockdelay, 0, 1000, VAR_MAX);
GVAR(IDF_GAMEMOD, shockdelay, 1, 1000, VAR_MAX);
GVAR(IDF_GAMEMOD, shockdamage, 0, 2, VAR_MAX);
GVAR(IDF_GAMEMOD, shockstun, 0, W_N_ST, W_N_ALL);
GFVAR(IDF_GAMEMOD, shockstunscale, 0, 0.5f, FVAR_MAX);
Expand Down