TNT Problem

User avatar
srifqi
Member
 
Posts: 508
Joined: Sat Jun 28, 2014 04:31
GitHub: srifqi
IRC: srifqi
In-game: srifqi

TNT Problem

by srifqi » Wed Sep 17, 2014 13:11

When I turn on TNT near unbreakable nodes, that unbreakable nodes also gone!

Is this a feature, or a bug, or a mistake?
Thanks,
I'm from Indonesia! Saya dari Indonesia!
Terjemahkan Minetest!
Mods by me. Modifikasi oleh saya.

Pronounce my nick as in: es-rifqi (IPA: /es rifˈki/)
 

User avatar
sfan5
Member
 
Posts: 3636
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5

Re: TNT Problem

by sfan5 » Wed Sep 17, 2014 16:20

Probaby a bug.
Mods: Mesecons | WorldEdit | Nuke
Minetest builds for Windows (32-bit & 64-bit)
 

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: TNT Problem

by Wuzzy » Fri Sep 26, 2014 05:49

This is because TNT does not honor on_blast,
and the so-called “unbreakable” nodes probably do not provide on_blast.

on_blast is a function mentioned in lua_api.txt. Sadly almost nobody uses it. Maybe this should change, starting with the default (!) TNT mod. ;-)
 

4aiman
Member
 
Posts: 1208
Joined: Mon Jul 30, 2012 05:47

Re: TNT Problem

by 4aiman » Fri Sep 26, 2014 07:56

So, maybe you can clear out how to use that function?
I've been asking question about it for nearly 2 years and got nothing...

My question is simple, though. I'll copy & paste my last try to obtain the knowledge:


I've a question:
lua_api.txt clearly states that
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
    on_blast = func(pos, intensity),
    ^ intensity: 1.0 = mid range of regular TNT
    ^ If defined, called when an explosion touches the node, instead of
      removing the node


But how can I use it?
I mean, there's NO problem in adding this to a nodedef and toying with it using the intensity param as a basis.

But what CAUSES a blast?

There's nothing about this out there in lua_api.txt.
It's cool and stuff that 1.0 is a mid range of a regular TNT, but TNT never uses on_blast itself and never checks for it.

What I'm looking for is a way to invoke blast with intensity of my choice at the chosen by me pos.
I hope there is such a callback and that it will calculate intensity on it's own like this:
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
    A  B  C  D  E  F  G  H  I  J  K  L  M
01 [ ][ ][ ][ ][ ][ ][1][ ][ ][ ][ ][ ][ ]
02 [ ][ ][ ][ ][ ][1][2][1][ ][ ][ ][ ][ ]
03 [ ][ ][ ][ ][1][2][3][2][1][ ][ ][ ][ ]
04 [ ][ ][ ][1][2][3][4][3][2][1][ ][ ][ ]
05 [ ][ ][1][2][3][4][5][4][3][2][1][ ][ ]
06 [ ][1][2][3][4][5][6][5][4][3][2][1][ ]
07 [1][2][3][4][5][6][B][6][5][4][3][2][1]
08 [ ][1][2][3][4][5][6][5][4][3][2][1][ ]
09 [ ][ ][1][2][S][S][S][S][S][2][1][ ][ ]
10 [ ][ ][ ][1][ ][1][2][1][ ][1][ ][ ][ ]
11 [ ][ ][ ][ ][ ][ ][1][ ][ ][ ][ ][ ][ ]


Let us say, stone has on_blast and can affect the intensity of a blast behind it.

Let us assume that stone's blast_protection is only 2 points.

Then we will see a picture like this:
B stands for "blast point".
Numbers mean intensity of a blast wave.
At G9 intensity should be at 5.
But there's a block of Stone.
It reduces Intensity by it's 2 points of blast_protection and gets destroyed.
Nearby Stones also decrease intensity and got destroyed.

The picture illustrates the final intensity.
_________________________________________

Wuzzy, please, show us the light, if you're able to! :)
 

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: TNT Problem

by Wuzzy » Fri Sep 26, 2014 18:27

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.
Code: Select all
on_blast = function() return end

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:
  1. 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.)
  2. 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!
 


Return to Minetest Problems

Who is online

Users browsing this forum: Google [Bot] and 8 guests

cron