Skip to content

Commit

Permalink
Gameplay|All Games: Compatibility option for pushable momentum
Browse files Browse the repository at this point in the history
When pushing objects with the MF2_PUSHABLE flag, the previous (vanillla?) behavior is that the pushed objects may accumulate unlimited amounts of momentum.

The new compatibility cvar “game-objects-pushable-limit” (default 1) causes the pushed objects’ momentum to not exceed the speed of the object doing the pushing. This makes the behavior more physically accurate.
  • Loading branch information
skyjake committed Dec 2, 2018
1 parent b6969b4 commit e581e99
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions doomsday/apps/plugins/common/include/config.h
Expand Up @@ -54,6 +54,7 @@ typedef struct libcommon_config_s {
// Gameplay:
byte switchSoundOrigin;
byte defaultRuleFastMonsters;
byte pushableMomentumLimitedToPusher;

// Weapons:
byte weaponCycleSequential; // if true multiple next/prev weapon impulses can be chained to allow the user to "count-click-switch".
Expand Down
1 change: 1 addition & 0 deletions doomsday/apps/plugins/common/src/common.cpp
Expand Up @@ -115,4 +115,5 @@ void Common_Register()
#ifdef __JDOOM__
C_VAR_BYTE2("game-monsters-fast", &cfg.common.defaultRuleFastMonsters, 0, 0, 1, fastMonstersChanged);
#endif
C_VAR_BYTE ("game-objects-pushable-limit", &cfg.common.pushableMomentumLimitedToPusher, 0, 0, 1);
}
1 change: 1 addition & 0 deletions doomsday/apps/plugins/common/src/game/g_game.cpp
Expand Up @@ -314,6 +314,7 @@ void G_CommonPreInit()
::quitInProgress = false;

// Apply the default game rules.
cfg.common.pushableMomentumLimitedToPusher = true;
gfw_Session()->applyNewRules(gfw_DefaultGameRules() = GameRules());

// Register hooks.
Expand Down
8 changes: 8 additions & 0 deletions doomsday/apps/plugins/common/src/hu_menu.cpp
Expand Up @@ -1150,6 +1150,14 @@ void Hu_MenuInitGameplayOptionsPage()
.setGroup(1)
.setShortcut('w');

page->addWidget(new LabelWidget("Pushable Speed Limit"))
.setLeft()
.setGroup(1);
page->addWidget(new CVarToggleWidget("game-objects-pushable-limit"))
.setRight()
.setGroup(1)
.setShortcut('p');

# if __JDOOM__ || __JDOOM64__

page->addWidget(new LabelWidget("Zombie Players Can\n Exit Maps")).setLeft()
Expand Down
30 changes: 26 additions & 4 deletions doomsday/apps/plugins/common/src/world/p_map.cpp
Expand Up @@ -850,10 +850,32 @@ static int PIT_CheckThing(mobj_t *thing, void * /*context*/)

if((thing->flags2 & MF2_PUSHABLE) && !(tmThing->flags2 & MF2_CANNOTPUSH))
{
// Push thing
thing->mom[MX] += tmThing->mom[MX] / 4;
thing->mom[MY] += tmThing->mom[MY] / 4;
NetSv_PlayerMobjImpulse(thing, tmThing->mom[MX]/4, tmThing->mom[MY]/4, 0);
// Push thing.
coord_t pushImpulse[2] = {tmThing->mom[MX] / 4, tmThing->mom[MY] / 4};

for (int axis = 0; axis < 2; ++axis)
{
// Do not exceed the momentum of the thing doing the pushing.
if (cfg.common.pushableMomentumLimitedToPusher)
{
coord_t maxIncrement = tmThing->mom[axis] - thing->mom[axis];
if (thing->mom[axis] > 0 && pushImpulse[axis] > 0)
{
pushImpulse[axis] = de::max(0.0, de::min(pushImpulse[axis], maxIncrement));
}
else if (thing->mom[axis] < 0 && pushImpulse[axis] < 0)
{
pushImpulse[axis] = de::min(0.0, de::max(pushImpulse[axis], maxIncrement));
}
}

thing->mom[axis] += pushImpulse[axis];
}

if (!de::fequal(pushImpulse[MX], 0) || !de::fequal(pushImpulse[MY], 0))
{
NetSv_PlayerMobjImpulse(thing, float(pushImpulse[MX]), float(pushImpulse[MY]), 0);
}
}

// @fixme Kludge: Always treat blood as a solid.
Expand Down

0 comments on commit e581e99

Please sign in to comment.