diff --git a/src/p_map.cpp b/src/p_map.cpp index 233cc50cd..68d0b21f0 100644 --- a/src/p_map.cpp +++ b/src/p_map.cpp @@ -887,6 +887,20 @@ bool PIT_CheckLine(line_t *ld, const FBoundingBox &box, FCheckPosition &tm) return true; } + +//========================================================================== +// +// Isolated to keep the code readable and fix the logic +// +//========================================================================== + +static bool CheckRipLevel(AActor *victim, AActor *projectile) +{ + if (victim->RipLevelMin > 0 && projectile->RipperLevel < victim->RipLevelMin) return false; + if (victim->RipLevelMax > 0 && projectile->RipperLevel > victim->RipLevelMax) return false; + return true; +} + //========================================================================== // // PIT_CheckThing @@ -1207,17 +1221,8 @@ bool PIT_CheckThing(AActor *thing, FCheckPosition &tm) { return true; } - // Rippers will rip through anything with an equivalent ripper level, - // or if the missile's ripper level is within the min/max range, - // or if there's no min/max range and the missile's ripper level is - // >= the monster's, then let 'er rip! - bool ripmin = (thing->RipLevelMin != 0) ? true : false; - bool ripmax = (thing->RipLevelMax != 0) ? true : false; - if ((tm.DoRipping && !(thing->flags5 & MF5_DONTRIP)) && - ((!(ripmin) && !(ripmax) && (thing->RipperLevel <= tm.thing->RipperLevel)) || - ((thing->RipperLevel == tm.thing->RipperLevel) || - (thing->RipLevelMin <= tm.thing->RipperLevel) && - (thing->RipLevelMax >= tm.thing->RipperLevel)))) + + if ((tm.DoRipping && !(thing->flags5 & MF5_DONTRIP)) && CheckRipLevel(thing, tm.thing)) { if (!(tm.thing->flags6 & MF6_NOBOSSRIP) || !(thing->flags2 & MF2_BOSS)) { diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index a00ac62e1..677979276 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -1442,6 +1442,10 @@ DEFINE_PROPERTY(telefogdesttype, S, Actor) DEFINE_PROPERTY(ripperlevel, I, Actor) { PROP_INT_PARM(id, 0); + if (id < 0) + { + I_Error ("RipperLevel must not be negative"); + } defaults->RipperLevel = id; } @@ -1451,6 +1455,10 @@ DEFINE_PROPERTY(ripperlevel, I, Actor) DEFINE_PROPERTY(riplevelmin, I, Actor) { PROP_INT_PARM(id, 0); + if (id < 0) + { + I_Error ("RipLevelMin must not be negative"); + } defaults->RipLevelMin = id; } @@ -1460,6 +1468,10 @@ DEFINE_PROPERTY(riplevelmin, I, Actor) DEFINE_PROPERTY(riplevelmax, I, Actor) { PROP_INT_PARM(id, 0); + if (id < 0) + { + I_Error ("RipLevelMax must not be negative"); + } defaults->RipLevelMax = id; }