Explosives! [explosives] [WIP]

Grissess
Member
 
Posts: 11
Joined: Tue Feb 04, 2014 00:14

Explosives! [explosives] [WIP]

by Grissess » Tue Feb 04, 2014 01:16

So, I've been toying around with Minetest, and I must say that I'm decently impressed with the amount of mods there are out there for it. In particular, I've found pipeworks, mesecons, digilines, technic, and they're all rather neat :P

...one thing I haven't found among those mods is an explosives mod--though, maybe I didn't look hard enough :P . This repository is my attempt at making one:

https://github.com/Grissess/minetest_explosives

Of course, it's not really anywhere near completion; I'm still looking to develop the code further, and (on that note) I have some questions:

  • How much would you be interested in this? What would I have to do to make this interesting?
  • I'd like to think the current recursive algorithm is better than Minecraft's supposed ray-casting algorithm, but I'm not sure about it. In any case, it has the unfortunate side effect that explosions can tunnel around obstacles. Does anyone know how to efficiently prevent this in a recursion stack like this?
  • How might one go about making the TNT entity physically realistic? The physical=true parameter doesn't appear to prevent interpenetration at all, and I'm currently using a cheap trick from builtin/item_entity.lua. Perhaps I'm confusing the setvelocity/setacceleration interfaces with something that would permit more physical behavior?
  • The implementation of on_blast, right now, does not specify a required return. I'm thinking about making the return value have the same interpretation as modfunc's return: the resultant blast power after propagating through this block (like blast_resistance). nil would imply the default resistance. Thoughts?
  • Would anyone care to help with textures? That's the most dreadful part of this process, so I've learned--you might be able to tell :P

Thanks in advance :D
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Tue Feb 04, 2014 01:36

There are two explosives mods, but it is always nice to have variants.

Grissess wrote:Would anyone care to help with textures? That's the most dreadful part of this process, so I've learned--you might be able to tell :P


Sure. I might be able to get some decent textures to you in a couple of days. Depends on my homework load.

Also, Welcome and nice mod.
Last edited by philipbenr on Tue Feb 04, 2014 01:40, edited 1 time in total.
"The Foot is down!"
 

Grissess
Member
 
Posts: 11
Joined: Tue Feb 04, 2014 00:14

by Grissess » Tue Feb 04, 2014 01:41

philipbenr wrote:There are two explosives mods, but it is always nice to have variants.


Ah, good to know, I'll have to look harder for them :P

philipbenr wrote:Sure. I might be able to get some decent textures to you in a couple of days. Depends on my homework load.


Sounds awesome; feel free to go wild with whatever you think explosive things should look like--entities, particles, nodes, et cetera. I'll spend some time looking over whatever needs to be integrated soon (especially particles would be neat :D).
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Tue Feb 04, 2014 05:54

If you go to google and use the following search terms, you should easily find the other explosive mods. :)


minetest tnt mod

minetest nuke mod
 

Grissess
Member
 
Posts: 11
Joined: Tue Feb 04, 2014 00:14

by Grissess » Tue Feb 04, 2014 16:05

I found at least these two:


The former's "boom" function destroys blocks in a 5x5x5 cube centered on the TNT at a 4 in 5 chance, without doing drops, and using a special-cased "if" to "boom" other TNT :P

The latter's "on_step" for the TNT functions handle the explosion logic, which does entity damage and uses the distance formula to carve out a sphere (with radius sqrt(r*(r+1)), oddly), also using "activate_if_tnt" to activate other TNTs in the affected volume (the implementation of which also does node name comparisons) :P

The implementation in explosives/lib.lua here is a recursive function that attempts to mimic the natural outward radiation of an explosion by traversing outward in orthogonal directions, and using the blast_resistance group to determine how much energy is absorbed. It also will activate blocks in the explosive group with the specified power (though it doesn't keep the block's original appearance--bug :P), and obeys the "on_blast" callback in the node definition, which is overridden in explosives to activate them--when not defined, it also handles item drops and obeys "can_dig" :D

Certainly no offense to the other developers, their implementations are much more lightweight than mine (running the numbers at present, a full 16-deep traversal, the current default, encompasses at most the number of cells in the orthogonal von Neumann neighborhood, r=16, or about 6015 function calls nested at most 16 deep; see http://www.wolframalpha.com/input/?i=2*%28sum+from+r%3D1+to+15+of+2r%28r%2B1%29%2B1%29+%2B+%282*16*17%2B1%29 for my calculations :P . This also assumes that the cache is fast, because it has to cull an average of 3 hits out of 6 accesses per call, or 36090 accesses over the traversal :P). My goal was mostly to make the explosions very realistic, and that unfortunately costs processor cycles. Someone with a worse computer than mine should try this :P
 

Grissess
Member
 
Posts: 11
Joined: Tue Feb 04, 2014 00:14

by Grissess » Wed Feb 05, 2014 22:38

...pardon my bumping, this might be worth another topic :P

I managed to add a voxel raytrace algorithm to this project for the sake of calculating object visibility between explosions; it probably can be used for more general purposes :P

The code is here, pardon my long theory intro at the beginning: https://github.com/Grissess/minetest_explosives/blob/master/raytrace.lua

Feel free to use it in your projects!
 

Grissess
Member
 
Posts: 11
Joined: Tue Feb 04, 2014 00:14

by Grissess » Thu Feb 06, 2014 21:47

Update!

It's a big one :P

  • Fixed raytrace (oddly, block boundaries are on half-integer coordinates, not on integer coordinates--the raytrace library was misconceived in some small part :P)
  • Implemented entity damage using inverse square law (with an absolute maximum)
  • Fixed bugs that caused explosive-resistant blocks to succumb to blast damage
  • Made "ignore" equivalent to "air" in explosion handling
  • Added some configuration options
  • Removed an ancillary part of the entity code for the primed_tnt entity when it wasn't behaving physically
  • Probably some other small things I'm forgetting :P

Have at it (and have some fun meantime :D)
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Thu Feb 06, 2014 23:10

I think there is a problem with the references in your modpaths at the bottom.

[spoiler=Reasons being:]
15:06:14: ERROR[main]: Failed to load and run script from
15:06:14: ERROR[main]: C:\Users\-----\Documents\minetest-0.4.9-win32\bin\..\mods\minetest_explosives\init.lua:
15:06:14: ERROR[main]: ...est-0.4.9-win32\bin\..\mods\minetest_explosives\init.lua:48: attempt to concatenate field 'modpath' (a nil value)
15:06:14: ERROR[main]: stack traceback:
15:06:14: ERROR[main]: ...est-0.4.9-win32\bin\..\mods\minetest_explosives\init.lua:48: in main chunk
[/spoiler]

Edit: I've PM you the textures I made.
Last edited by philipbenr on Thu Feb 06, 2014 23:47, edited 1 time in total.
"The Foot is down!"
 

Grissess
Member
 
Posts: 11
Joined: Tue Feb 04, 2014 00:14

by Grissess » Fri Feb 07, 2014 00:17

philipbenr wrote:I think there is a problem with the references in your modpaths at the bottom.

[spoiler=Reasons being:]
15:06:14: ERROR[main]: Failed to load and run script from
15:06:14: ERROR[main]: C:\Users\-----\Documents\minetest-0.4.9-win32\bin\..\mods\minetest_explosives\init.lua:
15:06:14: ERROR[main]: ...est-0.4.9-win32\bin\..\mods\minetest_explosives\init.lua:48: attempt to concatenate field 'modpath' (a nil value)
15:06:14: ERROR[main]: stack traceback:
15:06:14: ERROR[main]: ...est-0.4.9-win32\bin\..\mods\minetest_explosives\init.lua:48: in main chunk
[/spoiler]

Edit: I've PM you the textures I made.


First, thank you, I'll merge them in as soon as I can :D

Second, the issue appears to be that you forgot to rename the folder; the mod expects to be called "explosives", and it might have been a bad idea to name the repository minetest_explosives--that's going to cause some confusion :P
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Fri Feb 07, 2014 04:31

Okay. Thank you.
"The Foot is down!"
 

User avatar
Jonathan
Member
 
Posts: 119
Joined: Tue Apr 02, 2013 14:07

by Jonathan » Fri Feb 07, 2014 20:33

This seems like it could be a really neat mod! Especially if it does not "tunnel around obstacles", explodes more realistically than the other explosion mods, and does not lag horribly.

FYI, I could not get any of the TNT types to explode for me. I could place them, but I could not find any way to make them explode. Also, when I used the mesecons mod, the game would crash if I sent power to the TNT (I am using version 0.4.9 on Windows 7).

Idea:
It might be neat if certain blocks were resistant, but not indestructible. So let's say for example a cobblestone block has a resistance of 3, and the regular TNT is 3 blocks away when it explodes, it will not be destroyed. Yet, if a Mega TNT explodes 3 blocks away it would be destroyed.

Edit/Update: When I try to make it explode with fire, it also crashes.
Last edited by Jonathan on Fri Feb 07, 2014 20:53, edited 1 time in total.
By perseverance the snail reached the ark.
- Charles Spurgeon
 

Grissess
Member
 
Posts: 11
Joined: Tue Feb 04, 2014 00:14

by Grissess » Sat Feb 08, 2014 14:17

Jonathan wrote:This seems like it could be a really neat mod! Especially if it does not "tunnel around obstacles", explodes more realistically than the other explosion mods, and does not lag horribly.

FYI, I could not get any of the TNT types to explode for me. I could place them, but I could not find any way to make them explode. Also, when I used the mesecons mod, the game would crash if I sent power to the TNT (I am using version 0.4.9 on Windows 7).

Idea:
It might be neat if certain blocks were resistant, but not indestructible. So let's say for example a cobblestone block has a resistance of 3, and the regular TNT is 3 blocks away when it explodes, it will not be destroyed. Yet, if a Mega TNT explodes 3 blocks away it would be destroyed.

Edit/Update: When I try to make it explode with fire, it also crashes.


The blast resistance you're talking about is implemented; blocks in the blast_resistance group may set custom values as to how much blast power they can take before succumbing (explosives:blastproofing exists primarily to demonstrate that proof of concept; it can't be destroyed by anything less than Ultra TNT :P). Of course, I also want to add some groups to the default: mod blocks at load time (to do things like implement stronger obsidian, weaker leaves, etc.), but I haven't yet--it's on my to-do list. Currently, the blast resistance of a block without an explicit blast resistance is explosives.DEFAULT_RESISTANCE (=0.35, about 1/3), where 1 is the initial blast power of a regular TNT (so, in theory, that should carve out a nice 3-radius hole in something like stone; in practice, the propagation algorithm is a little greedier than that, due to tunneling effect).

Ah, I'm guessing the crash is in the general explosion algorithm :P . Does it give you any helpful error messages?

In any case, it might be because I have the settings turned up a little bit optimistically for my desktop, which might be a little better-than-average--that's one of the reasons I was looking for someone else to test it :D . In theory, you could modify your configuration/settings file for the game to add a setting for "explosion_maxdepth=<some number>", but (until I make sure that function actually works) the fool-proof way of getting it to work is to open init.lua in a good text editor (like Wordpad, Notepad++, etc.), find line 8, and change the "16" in:

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
    MAX_DEPTH={key="explosion_maxdepth", type="n", default=16}, --How deep the call stack goes in the recursive general_explosion algorithm


to something slightly more sane, like 12 or 10 :D

(Just as a side note: this will limit the explosion radius equivalently.)

At the same time, I should note I'm building against the bleeding-edge newest version of minetest (especially as of late, having rebuilt it) from their git repository. I am definitely going for compatibility here; as far as I know, the API docs on the developer wiki apply to most of the 0.4.x releases.

Let me know how that works for you! :D
Last edited by Grissess on Sat Feb 08, 2014 14:18, edited 1 time in total.
 

User avatar
Jonathan
Member
 
Posts: 119
Joined: Tue Apr 02, 2013 14:07

by Jonathan » Sat Feb 08, 2014 18:17

Grissess wrote:
Jonathan wrote:This seems like it could be a really neat mod! Especially if it does not "tunnel around obstacles", explodes more realistically than the other explosion mods, and does not lag horribly.

FYI, I could not get any of the TNT types to explode for me. I could place them, but I could not find any way to make them explode. Also, when I used the mesecons mod, the game would crash if I sent power to the TNT (I am using version 0.4.9 on Windows 7).

Idea:
It might be neat if certain blocks were resistant, but not indestructible. So let's say for example a cobblestone block has a resistance of 3, and the regular TNT is 3 blocks away when it explodes, it will not be destroyed. Yet, if a Mega TNT explodes 3 blocks away it would be destroyed.

Edit/Update: When I try to make it explode with fire, it also crashes.


The blast resistance you're talking about is implemented; blocks in the blast_resistance group may set custom values as to how much blast power they can take before succumbing (explosives:blastproofing exists primarily to demonstrate that proof of concept; it can't be destroyed by anything less than Ultra TNT :P). Of course, I also want to add some groups to the default: mod blocks at load time (to do things like implement stronger obsidian, weaker leaves, etc.), but I haven't yet--it's on my to-do list. Currently, the blast resistance of a block without an explicit blast resistance is explosives.DEFAULT_RESISTANCE (=0.35, about 1/3), where 1 is the initial blast power of a regular TNT (so, in theory, that should carve out a nice 3-radius hole in something like stone; in practice, the propagation algorithm is a little greedier than that, due to tunneling effect).

Ah, I'm guessing the crash is in the general explosion algorithm :P . Does it give you any helpful error messages?

In any case, it might be because I have the settings turned up a little bit optimistically for my desktop, which might be a little better-than-average--that's one of the reasons I was looking for someone else to test it :D . In theory, you could modify your configuration/settings file for the game to add a setting for "explosion_maxdepth=<some number>", but (until I make sure that function actually works) the fool-proof way of getting it to work is to open init.lua in a good text editor (like Wordpad, Notepad++, etc.), find line 8, and change the "16" in:

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
    MAX_DEPTH={key="explosion_maxdepth", type="n", default=16}, --How deep the call stack goes in the recursive general_explosion algorithm


to something slightly more sane, like 12 or 10 :D

(Just as a side note: this will limit the explosion radius equivalently.)

At the same time, I should note I'm building against the bleeding-edge newest version of minetest (especially as of late, having rebuilt it) from their git repository. I am definitely going for compatibility here; as far as I know, the API docs on the developer wiki apply to most of the 0.4.x releases.

Let me know how that works for you! :D


Well, I got it to work. I don't know if it was because I used a different computer (with 32GB of RAM :D), or if it was because I used Blockmen's latest dev version of Minetest. When it was crashing on me on the other PC, it did not give me any info on the crash in the debug.txt file.

By the way, when the TNT blows up and removes a node directly under a sand node, it does not make the sand fall. Also, when I tried the hyper TNT it did not blow up a sand block that was almost directly by it. As a result, it looked weird having a giant crater with a single sand node suspended in mid air. :P

FYI, instead of having fire ignite TNT (Since, fire is only caused by lava by a flammable material with no additional mods), I would recommend TNT be ignited like PilzAdam's TNT mod (by punching a TNT node with a torch).

Keep up the good work :)
By perseverance the snail reached the ark.
- Charles Spurgeon
 

Grissess
Member
 
Posts: 11
Joined: Tue Feb 04, 2014 00:14

by Grissess » Sat Feb 08, 2014 22:51

Jonathan wrote:-snip-

Well, I got it to work. I don't know if it was because I used a different computer (with 32GB of RAM :D), or if it was because I used Blockmen's latest dev version of Minetest. When it was crashing on me on the other PC, it did not give me any info on the crash in the debug.txt file.


That definitely smells of memory usage issues; definitely, the maximum depth being 16 does lead to some pretty surprisingly big numbers in processor and memory usage (it's not exponential, but definitely at least cubic; you can see some of my off-the-cuff calculations above :P).

Jonathan wrote:By the way, when the TNT blows up and removes a node directly under a sand node, it does not make the sand fall. Also, when I tried the hyper TNT it did not blow up a sand block that was almost directly by it. As a result, it looked weird having a giant crater with a single sand node suspended in mid air. :P


Ah, yes, there are integration issues with some mods that expect to be notified when their blocks are removed by hooking on_dignode. This isn't really a good idea anymore, since the on_destruct hook was added. However, the definition of falling nodes is in builtin/falling.lua, where there is no "minetest.register_on_destruct" function yet :P

I added a hack for fire (which would forget to update the area), but I just might make it so that on_dignode is called for the appropriate nodes; this is trivial to implement, since the player causing the explosion is already stored with the node for the purpose of doing candig anyways :P . However, this might require on_dignode handlers to deal with null (empty string) player names, which isn't always expected. The more proper way of calling on_destruct will have to wait until that support becomes widespread :D

Jonathan wrote:FYI, instead of having fire ignite TNT (Since, fire is only caused by lava by a flammable material with no additional mods), I would recommend TNT be ignited like PilzAdam's TNT mod (by punching a TNT node with a torch).


Easy enough, just setting the default TNT on_punchnode to check if the puncher has a torch and calling explosives.detonate(pos) if it does :D

(The explosion is still "caused" by the player who placed the TNT, as far as candig and, eventually, on_dignode are concerned. That can also be changed if needed :P)

Jonathan wrote:Keep up the good work :)


Thanks :D
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

by philipbenr » Sat Feb 08, 2014 23:21

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
15:17:57: ERROR[main]: ServerError: LuaError: error running function 'on_step': ....4.7-72b9b0f-fixes-win32\bin\..\mods\explosives/defs.lua:91: bad argument #3 to 'add_particle' (number expected, got nil)


I get this error after trying to detonate. I am using Blockmen's 0.4.9 3d person view and Pilzadam's 0.4.772b9b0f-fixes-win32 build.

Also, this is from the latest of your mod.
"The Foot is down!"
 

Grissess
Member
 
Posts: 11
Joined: Tue Feb 04, 2014 00:14

by Grissess » Sun Feb 09, 2014 04:23

philipbenr wrote:
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
15:17:57: ERROR[main]: ServerError: LuaError: error running function 'on_step': ....4.7-72b9b0f-fixes-win32\bin\..\mods\explosives/defs.lua:91: bad argument #3 to 'add_particle' (number expected, got nil)


I get this error after trying to detonate. I am using Blockmen's 0.4.9 3d person view and Pilzadam's 0.4.772b9b0f-fixes-win32 build.

Also, this is from the latest of your mod.


That's...curious. I cracked lua_particles.cpp open not too long ago, and it is true that there's a "deprecated" form of call to add_particle that expects each of the arguments to be given positionally; as far as I know, the proper way of calling it is with a table of parameters :P

(Furthermore, since some unspecified time, the keys for acceleration and velocity were changed to acc and vel, and this was never documented--this being why I had to open it :P)

Furthermore, in my version (off git), the third argument should be a vector (its check function is check_v3f, and the result gets assigned to "acc"; it should not be expecting a number '-'

...I'll have to do some more research into this stuff; until then, keep in mind that I'm using the vanilla Minetest from the repository, so other builds might have unusual or difficult-to-support features--that doesn't mean I won't at least make some attempt to support them, though it might be a bit of a daunting task :P

EDIT: According to your doc/lua_api.txt (assuming you're using https://www.dropbox.com/sh/am3ddzfm8qxz9w0/q4Fu0wjAq_/minetest-0.4.7-72b9b0f-fixes-win32.zip ):

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
Particles:
minetest.add_particle(pos, velocity, acceleration, expirationtime,
    size, collisiondetection, texture, playername)


...which means not only are you a little bit behind on adopting the 1arg table style, but you're also missing the size parameter, which makes interoperability difficult. Nonetheless, I think I was able to make it work, hopefully without user intervention :D
Last edited by Grissess on Sun Feb 09, 2014 04:47, edited 1 time in total.
 

Grissess
Member
 
Posts: 11
Joined: Tue Feb 04, 2014 00:14

by Grissess » Wed Feb 12, 2014 23:27

Just as a note (double post :P):

  • Only stability improvements are going into the dev-branch; I've moved my daily screwing-around into dev-latest, which is going to include some neat new technologies that might not be stable or production-ready :P
  • If you have any compatibility issues, please tell me, and I'll integrate some kind of workaround; Lua is surprisingly flexible with that sort of thing :P
  • As always, suggestions and comments are totally welcome :D

Also, there's some schoolwork I need to be doing, so the dev-latest isn't on any strict schedule; I'll tell you when things happen, but that's not happening now :P
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 14 guests

cron