I agree, it is a pity that you have to calculate the actual explosion strength when you were called. There should be a standard function for that as well, otherwise everyone just codes their own function and there is just chaos.
For that, I have no real idea yet.
The problem is that there is actually no standardization at all here. I guess that’s also the reason why you did not get an answer. Nobody had a clue either. ;-)
What you said would be probably useful as a standard function in the Lua API. It would be a pity if everyone had to come up with their own calculations, which would probably not match very well, after all.
Explosions are wrong because they directly call minetest.remove_node. What they should do instead is to call on_blast if it is avaliable. If it is not there, they can fallback to the default behaviour.
Here is the rough idea for the exploder:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
if(node.on_blast ~= nil) then
node.on_blast(pos, power)
else
-- default behaviour (just an example, might additionally also drop an item
minetest.remove_node(pos)
end
For the undestroyable nodes, the solution is trivial:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Yep, this does nothing. This is exactly what we want, because this causes the exploder to
not call remove_node.
This is already sufficient if we do not care about explosion strength, which is the case when you are an immortal node. ;-)
To my understanding, on_blast is NOT actually part of the Lua API. It is just a convention suggested in lua_api.txt. Admittedly, it is a poorly defined convention and almost nobody even uses it. Not even the default game, which is a shame!
On a sidenote:
But at least, I have worked out a standard method to determine a good value for the blast intensity. As the documentation said, 1 TNT explosion shall be a value of 1. But it is not said how to calculate it for other explosions. But this is important, otherwise everyone just picks a value they feel like is right, but is not quite right.
I therefore
propose a method to calculate the blast intensity of an explosion.
My method is pretty simple. I only care about explosions which affect nodes. My blast intensity is determined by the average number of nodes the explosion WOULD destroy, as if we don’t have on_blast for all affected nodes.
Let’s start with TNT:
TNT affects a range of 5*5*5 = 125 nodes. However, not all are destroyed always.
The 3*3*3 = 27 center nodes (including TNT) are destroyed always. Se we have 27 nodes.
The remaining 98 nodes are destroyed with a chance of 80% each. Therefore, on average, 98*0.8 = 78.4 of the remaining nodes are destroyed: Add 78.4 to 27:
In total, 105.4 nodes are destroyed on average.
I define 105.4 destroyed nodes as 1 blast unit (BU). So if your explosion destroys 105.4 nodes on average, your blast intensity is 1.
The nice thing with this approach is that we now can easily calculate the blast intensities for other explosions.
To do that, follow this simple algorithm:
- Count the number of nodes which would be normally (no on_blast) be destroyed by the explosion. On average. Call this number “n”. (if the “exploding node” is destroyed, too, it counts as well.)
- intensity = n/105.4
The variable “intensity” now holds your blast strength in blast units.
I have calculated the intensities of some important explosions:
The TNT minetest_game has a strength of exactly 1 BU, because it destroys 105.4 nodes on average. 105.4/105.4 = 1.
This is important. TNT is detached from the definition of 1 BU. If you have a weaker TNT, the blast intensity is NOT 1 BU, although it is TNT. Also, if the TNT of minetest_game gets weaker or stronger for some reason, its blast strength changes, too.
Simple Mobs: Dungeon Master’s fireball: It destroys 3×3×3=27 nodes. The blast strength is thus 27 / 105.4. It approx. equals to 0.25616…
Uranium mod: The nuclear bomb is really strong. It always would destroy 36138 nodes (I got the number by counting all the iterations of the destruction loop). 36138/105.4 = 342.864
And there you have it, I calculated some (example) blast intensities:
Simple Mobs: Dungeon Master’s fireball: 0.256 BU
Default TNT mod: TNT explosion: 1 BU
Uranium: Nuclear Bomb: 342.865 BU
I like this. Now I can easily compare those numbers. :)
Remember, this is just a proposal!