From: Rudolf Polzer Date: Sun, 27 May 2012 16:41:45 +0000 (+0200) Subject: equivalent rewrite of fireball code X-Git-Tag: xonotic-v0.7.0~312^2~35^2~6 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=52a9f8bea2f461e9be1fb542cf1b8d802fff62ff;p=xonotic%2Fxonotic-data.pk3dir.git equivalent rewrite of fireball code --- diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc index a49aad27b..621df85a1 100644 --- a/qcsrc/server/g_damage.qc +++ b/qcsrc/server/g_damage.qc @@ -1269,43 +1269,30 @@ float Fire_AddDamage(entity e, entity o, float d, float t, float dt) if(maxtime > mintime || maxdps > mindps) { + // Constraints: + + // damage we have right now mindamage = mindps * mintime; + + // damage we want to get maxdamage = mindamage + d; - // interval [mintime, maxtime] * [mindps, maxdps] - // intersected with - // [mindamage, maxdamage] - // maximum of this! + // but we can't exceed maxtime * maxdps! + totaldamage = min(maxdamage, maxtime * maxdps); - if(maxdamage >= maxtime * maxdps) - { - totaltime = maxtime; - totaldamage = maxtime * maxdps; + /* + // how long do we damage then? + // at least as long as before + // but, never exceed maxdps + totaltime = max(mintime, totaldamage / maxdps); // always <= maxtime + */ - // this branch increases totaldamage if either t > mintime, or dps > mindps - } - else - { - // maxdamage is inside the interval! - // first, try to use mindps; only if this fails, increase dps as needed - totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime - totaldamage = maxdamage; - // can totaldamage / totaltime be >= maxdps? - // max(mindps, maxdamage / maxtime) >= maxdps? - // we know maxdamage < maxtime * maxdps - // so it cannot be - - // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps - } + // alternate: + // at most as long as maximum allowed + // but, try mindps + totaltime = min(maxtime, totaldamage / mindps); // always >= mintime - // total conditions for increasing: - // maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage - // however: - // if maxtime = mintime, maxdps = mindps - // then: - // maxdamage = mindamage + d - // mindamage = mindps * mintime = maxdps * maxtime < maxdamage! - // so the last condition is not needed + // can these two ever differ? e.fire_damagepersec = totaldamage / totaltime; e.fire_endtime = time + totaltime;