Page 1 of 1

Explosion Expert: maybe the most confusing formula in game

Posted: Fri Dec 27, 2019 4:22 pm
by starsapphire
There are many complex mechanisms across this game.
However, while being a rather 'plain' class, not having so many fancy skills, Alchemist's bomb attack have a more complex damage calculation formula than it seems.
In fact, this complex formula have little effect in gameplay side, so the only thing that might get satisified is your curiosity.
However, if you love to dive more into the code to find some shiny things, then there are something intresting to be found. Believe me, it may be more complex than your thought.

---

Throw Bomb - The one mundane but powerful tool of Alchemists

The raw damage of alchemist bomb is 150 cTSpD (combatTalentSpellDamage, a common scaling among spell damage).
The Spellpower used here is a bit special, it's the average of your spellpower and the alchemist_power of the gem, so both the gem quality and your spell damage will affect the damage. Gems have the alchemist_power of 20/35/50/65/70 according to their tiers. Aside from that, there is nothing strange about it.
The 150 cTSpD damage here just mediocre. To compare, Manathrust is 230, Chill of the Tomb is 280, Fireflash is 330, Freeze is 390 in 1.6.5 (it would become 300 in later version) and Reality Breach is 370.
However, everyone have played Alchemist will admit, that the real power of alchemist will only surface after they reach Explosion Expert, so we will analyze the real power of this talent here.

Aside from increasing the radius, the description says like this:

Explosion damage may increase by 0% if the explosion is not contained, to 27/40/66/101/216% if the area of effect is confined.

However, this description state nothing how the damage would be like in the middle, and yet this description is not accurate, I will answer both two questions here.

Explosion Expert - What does it really means?

The code of damage calculation is like this:

Code: Select all

    local theoretical_nb = (2 * t.getRadius(self, t) + 1)^1.94 -- Maximum grids hit vs. talent level

    local lostgrids = math.max(theoretical_nb - grids, 0)
    local mult = math.max(0,math.log10(lostgrids)) / (6 - math.min(self:getTalentLevelRaw(self.T_EXPLOSION_EXPERT), 5))
The formula of theoretical_nb is very weird, but as the comment suggests, it is supposed to be the theoretical maximum grids hit with the current talent radius, so we will temporarily skip it, assuming it is the correct value.
Here, we can see the formula of explosion damage: it scales logarithmically with the number of grids "lost" (grids being blocked with wall / border of the map), divided by 6-TL.
The division here is a really powerful one, which means TL5 damage boost is 2x stronger than TL4 even at same grids confined, not to mention that additional radius provides more blocks.
And the logarithm function is a really harsh scaling mechanism, which means the first few grids blocked would be critical, but it is really hard to go up after than.

This is a plot showing the damage scaling with % of girds blocked goes up:

Image

As you can see on the plot, the damage boost will go up really quick at first, reaching 154% damage increment if 25% grids is blocked at TL5, but the growth will slow down shortly after that.
In fact, it is rather uncommon for a place in game that would leave the bomb explode with full grids count, so the overall damage boost would be somewhere near 150%~216% in most cases, reaching an equivalent base damage nearing 362~453 (the damage boost is applied after the ^1.04 nonlinear rescaling).
While Alchemist is an overall weak class, have a pool of not very helpful class talents, and don't have much stats boosting passives, the damage boost is in fact more stable than it seems.
This can explain that the effects of alchemist bombs are in fact much better than its description implies, maybe being the only strong offensive skill Alchemists have.

The mysterious ^1.94 in the formula

However, the above discussion completely ignores that confusion forumla for theoretical_nb:

Code: Select all

    local theoretical_nb = (2 * t.getRadius(self, t) + 1)^1.94
2 * t.getRadius(self, t) + 1 is the diameter of the hitting circle, but 1.94 is a confusing value, not showing anywhere in other parts of the game.
diameter ^ 2 would be the area of square, where diameter ^ 2 * PI / 4 is the area of circle, but both of them are quadratic.
This magic 1.94 was the most confusing formula in the whole ToME game, until I digged into the git log of this line, showing a commit back in 2013, introducing infinite scaling to all spells. Before that, the code is shaped like this:

Code: Select all

    local theorical_nb = ({ 9, 25, 45, 77, 109, 145 })[1 + self:getTalentLevelRaw(self.T_EXPLOSION_EXPERT)] or 145
This seemed to be a hard coded array of number of grids hitted from radius 1~6.
But, while 9 is a right number, you would remember that radius 2 hit for 21 grids, leaving 4 blanked corners, not 25.
I had been confused by it for a while, until I tried to use Excel to count the number of grids hit myselves... and got the exact same result as those numbers.

When I first trying to draw a circle like this, I was using X^2+Y^2 < (radius+1)^2.
And yes, I got a perfect 5*5 square.
Image
This is our familiar radius 2 circle, and it is got from formula X^2+Y^2 < (radius+0.5)^2.
Image

The below picture is the +1 version of radius 6 circle, you don't need to count it yourselves, it has 145 grids.
Image
And the below picture is the +0.5 version of raidus 6 circle, having 137 grids.
Image
I will present a screenshot in game, to show that the picture above is identicial to the circle in game.
Image

In fact, the +1 version area of radius 1~6 circle will have 9 / 25 / 45 / 77 / 109 / 145 grids respectively, which is same as the array above.
At the same time, the +0.5 version of circle currently used in game will have 9 / 21 / 37 / 69 / 97 / 137 grids.

I am not sure about the real cause of this problem, but I would suggest that, the +1 circle had been used in game long before, and had got changed into the +0.5 to make radius-2 seems more like a circle, while the damage calculation code of Explosion Expert haven't been changed.

Then, we will back to that mysterious 1.94
Judging from the commit message, it seems Darkgod want to extend this damage calculation function to infinite.
However, counting lattice points inside a circle is not an easy math problem...
It's called Gauss's Circle Problem, related with various other math problems, and have an OEIS entry A000328 (you should subtract it by 4, for the outermost 4 points is ignored in this formula)
The +0.5 sequence also have an OEIS entry A036704.

Here, as my math is rather bad, I would guess that solving this problem in a time complexity less than O(N) would be definetly too hard to me, maybe also for DG.
So, I will guess the n^1.94 might be a function to give estimation to that hard-to-calculate sequence.
After putting FindFit[{{3,9}, {5,25},{7,45},{9,77},{11,109},{13,145}}, x^a,{a},x] into WolframAlpha, it gives out the Least Squares Fitting y=x^a (short saying, the function that is most close to that sequence) for that:
Image
Here, the best x^a is 1.94945, which is very close to 1.94
I would guess that the 1.94 may come from the rounding error of Bisection search for finding the best constant here when DG is trying to fit this sequence.

Computing the real damage

So, after knowing the real meaning of that mysterious 1.94, we would compare it with the real grids hit.
While the x^1.94 is a close estimation function , it still gives different values on that points.
I will present the grid count for now and before the targeting circle radius changed, also the result given by the estimation function here:
Grid count Now: 9 / 21 / 37 / 69 / 97 / 137
Grid count Estimation: 8.43 / 22.70 / 43.60 / 71.00 / 104.79 / 144.89
Grid count Before: 9 / 25 / 45 / 77 / 109 / 145
When the radius 1 is not used, the other values coincidencely follows this pattern:
The estimated grid count is higher than the real grid count now, but lower than before.

Then, when it is used to count the number of "lost" grids that has been blocked by wall
Currently, you will get 1.7 / 6.6 / 2.0 / 7.8 / 7.9 "free" grids when counting lost grids for TL 1-5, respectively.
For example, even if you hit for a completely empty field with a TL5 bomb, this formula will still treat you as you have hit with 8 grids blocked by wall.
On completely empty space, while the bomb is not contained at all, the damage boost would be 5% / 20% / 10% / 45% / 90% respectively.
You can try it youselves to confirm this.
The bonus grids furtherly kickstarted the logarithmic damage growth, reaching nearly 50% the whole boost as the start value while bombing blank field, but only faster into saturation, and only affect less than 1% about the final damage boost.
In fact, the curve of damage boost and % of grids blocked would be like this:
Image

At the same time, if the hit circle is a larger +1 circle like before, you will "lose" some grid counts, 2.3 / 1.4 / 6.0 / 4.2 / 0.1 for TL1-5 respectively. Which means even you have a few grid blocked, your damage boost may still be zero. The damage curve is here:
Image

In fact, the difference of damage is not as big as it seems.
Here is the damage curve when TL5, for the damage boost currently, the damage boost if we use an old +1 circle, and the damage boost if we correct the grids count.
Image
You can see in this graph, that when their difference seemed big at the start of the curve, due to the nature of logarithmic growth, their difference is erased very soon after that.
In fact, as you may have experienced trying to found a complete empty space to confirm the bomb damage I have stated above, it is really hard to find such a blank place.
In typical environment in this game while you are throwing the bomb, the damage difference of them can be neglected.

Under infinite scaling

As the purpose of this formula is to extend the power of this talent to infinte, we will also analyze the infinte scaling of boost damage.

When under TL5, since the damage boost is divided by 6-MAX(TL,5), the talent level is very critical for the damage boost, reaching 216% damage boost at TL5.
However, after that, the increased max hitting area grows just ^1.94 (estimated) or quadratically (≈pi/4*diameter^2, theoretically), and they are alike under logarithmic scaling, making them 1.94*log(TL) or 2*log(TL) respectively.
The damage curve as radius grows shows in this plot.
Image
It is quite a slow growth, not to mention that the radius itself also scales witha a square root function.
Image
Even for the most crazy randbosses in this game, its max damage boost would not exceed about 310% at most.

TL;DR: the Conclusion

We can go to the conclusion here for Explosion Expert damage boost:
  • Terrain will not affect much about damage boost.
  • Talent level below TL5 will be critical for damage boost, but it would not affect much afterwards.
  • At TL5, the damage boost starts from 90% if not contained, and is around +150%~216% in nearly all cases.
This is a rather straight-forward conclusion. It states the guaranteed strength of Alchemist Bombs, and you would not need to care about the terrain for most of the case.

More chattering
From probably the most confusing formula in this game, we draw to a rather simple conclusion, that the damage boost of Explosion Expert acts not much different from a plain ~175% damage boost.
The damage boost mechanism scaling with terrain is atmospheric for a bomb talent, as we know that it would have better effect in a small area. Game design wise, it is seemed to make up for reduced AoE affect in a complex terrain, making it can alter between 'useful against a large group of enemy' and 'fatal to a single enemy'.
However, unlike its description seems, the design of this talent does not tie tightly with the game. Because of the nature of logarithmic growth and a bit designing flaws, differences between terrains is largely reduced, to the point that terrain would have little effect in game however.

We can hardly say the final effect is not good, however.

Terrain is one of the few things that player have little control to, so the end effect would be uncontrollable and map-specific. In the few case they would choose to change it, like digging Z-tunnels, the end result is often tied with tedious gameplay experience.
Also, it's rather hard to tell the real hitting area size by your bare eyes, so the damage would be hard to predict for player before throwing it, and the unpredictability is the nature enemy of strategical playing.
In fact, as you may have experienced in this game various times, that a open space with full of enemies is definetly more dangerous than a narrow path with them lining up. When narrowed space is already prefered for safety reasons, and open space is considered to be more dangerous, further nerfing damage in open space does not provide meaningful tradeoff, and is an unnecessary addition to game difficulty.

The current status of Alchemist bomb may also beyond its original intention. In fact, the power of bomb itself alone may be in line with other most powerful damage spells in game, and maybe the only strong attack spell Alchemist have.
Definitely, this doesn't means Alchemist bomb is OP. Judging from the overall poor status of Alchemist, the power of bomb can only donminate from mid-early to mid-late game, and its shine will fade in late game for lacking supportive talents and Alchemists' overall poor or over-conservative +damage / damage penetration / crit damage. However, this talent alone will support this lame duck's offensive ability.
The power split between Throw Bomb and Explosion Expert also make the bomb itself becoming one of worst attacking talents without support from Explosion Expert. Under the current randboss talent choosing scheme, the chance of alchemist randboss with Explosion Expert is relatively low, making this class just meat on the chopping board for most of time. And while a boss get chance to be equiped with Explosion Expert in late game, they mostly won't have a high respen to fully show its potential.

Just like Snarvid has said in a post, one of the most attracting respect of ToME4 is a system encouraging so many 'weird' classes, not 'being a model of balanced class choices'. While the design of Explosion Expert is rather strange, and the end result is rather simple, it's lucky that it fullfilled this designing philosophy, and won't ruin your playing experience, maybe by coincidence. This may be one of the reasons that it is one of the few talents survived for so long and haven't been changed ever.

Then, after peeping a little bit into the very long developing process of ToME4 and its tons of legacy designs, foresights and maybe problems, hope this post would be helpful to your curiosity on that tiny thing, or future revamp onto Alchemists.

Also, when I solved this finally, I will hope someone would find answer to the one most confusing formula in my opinion, in current game:

The mysterious ^1.04 on nearly ALL damage.

Re: Explosion Expert: maybe the most confusing formula in ga

Posted: Fri Dec 27, 2019 6:57 pm
by darkgod
This post. Amazing it is! :)

I've often wondered if I should keep this weird thing when I rework Alchemist to hum .. well, not suck ;)