Not logged inOpenClonk Forum
Up Topic General / Help and Questions / Overloading the explosion effect.
- - By Marky [de] Date 2015-07-08 20:07
I want to create an object that has a custom explosion effect when it hits the landscape. I added


public func ExplosionEffect(int level, int x, int y, int smoothness)
{
  ...
}


to the object script, hoping that it would overload the global function. Why does this not work?
Parent - By Maikel Date 2015-07-08 20:45
Because that is never called in an object context, you need to declare it global.
Parent - - By B_E Date 2015-07-08 20:47
I'm not sure about the specifics of OC explosions, but this is tricky. You'd have to overload

global func ExplosionEffect(int level, int x, int y, int smoothness)

but this function does already not no anything about the calling object. This probably means you'd have to overload the global Explode, and then the cleanest way would be to add a callback for the exploding object there (something like if(obj->~CustomExplosionEffect()) return;).
Parent - By Marky [de] Date 2015-07-08 20:55
Then I'll do that. Actually I want to be able to play a custom sound, overload the particle effect, maybe even overload the way an explosion damages objects, without sacrificing the way that explosions work inside of containers.
Parent - - By Sven2 [us] Date 2015-07-08 20:57
I've indirected the call so it's overloadable now (latest commit).
Parent - - By Marky [de] Date 2015-07-08 21:04
This makes explosions without object context impossible.
Parent - - By Sven2 [us] Date 2015-07-08 21:13
They have never been possible:


global func Explode(int level, bool silent)
{
  if(!this) FatalError("Function Explode must be called from object context");
[...]
Parent - - By Marky [de] Date 2015-07-09 04:32
I could call DoExplosion(x, y, level) in global context before.
Parent - - By Sven2 [us] Date 2015-07-09 06:04
Oh, OK. Also moved sound to ExplosionEffects and passed the silent-paramter through. Before, DoExplosion wouldn't play any sound.
Parent - - By B_E Date 2015-07-09 10:25 Edited 2015-07-09 19:39
This is okay, but we'd use multiple calls to DoExplosion in CR in CMC to make explosions more fierce without expanding. I guess one would have to build a custom damage effect for something like this.
Well, xkcd holds once more :-)
Parent - By Zapper [de] Date 2015-07-09 10:32
I think I once added the function ExplosionEffect that just plays the visuals without the damage stuff :)
(Even in CR, for Keepers/Caedes for example)
Parent - By Marky [de] Date 2015-07-09 19:10
Yes, this is also a feature that I want (more damage without increasing radius - not the overheating spacebar :p). I'll implement the changes on my private branch and post it before I commit.
Parent - - By Marky [de] Date 2015-07-11 15:59
Just came back from analysing the Explode() function and it's relatives a bit more. It is very hard to understand why the damaging function is done in such a complicated way. Can I please change this? Before I do, however, I need some help in understandig it, so that the object behaviour is not changed.

1) BlastObject() does damage to objects. This apparently does not affect living beings - their energy is not changed. Then it reduces the energy of living beings by level/3. This is done to every object in a 10-by-10 rectangle around the point of explosion.

2) the shockwave damages objects. This is done to all objects in the explosion/shockwave radius. Living beings get damaged and their energy reduced by level/2. Non-living beings are not damaged (very strange?).

I see some issues here:
- if a living being is at the center of the explosion it will lose ~0.83 * level energy, otherwise 0.5 * level energy. All objects get damage 1.5 * level at the center and 0.5 * level in the shockwave radius.
- if an explosion happens inside a container then all the objects inside are treated as being at the center of the explosion. However, they do not get hit by the shockwave which means that they lose only ~0.33 * level energy / take 1.0 * level damage.
- the code has a comment for extracting the shockwave to a separate global function. I am all for it! However: the damage part should be optional or handled in the explosion, so that we can have shockwaves that just push objects around
- objects that are stuck are not hit by shockwaves! See BlastObjectsShockwaveCheck(). Let's say there is a monster stuck in earth and I throw a super-bomb with Explode(500) next to it (so it is not in the center of the explosion). Then it will take no damage at all, because it is stuck?!

Suggested changes:
- I want to implement a separate function that handles the shockwaves
- the amount of damage that is done to an object should be more clear and it should possibly not be applied at two different places
- there should be a parameter that allows overriding the damage that is applied to an object, so that hacks with multiple explosions as done in CMC are not necessary
- [optional] return all objects that were hit by the explosion/blastobjects/shockwave in an array, so that the item that exploded can do more stuff to these objects (think of a slime-bomb that coats the objects in slime). This could cause more problems though, so I probably will not do that.
Parent - - By Sven2 [us] Date 2015-07-11 16:18
I don't see any problems with changing damage/energy loss of explosions.

Also, I'm not sure if the shockwave is still implemented the same way as in CR, but it could be made more logical, i.e. blast away from the shockwave. Iirc, vertical and horizontal blast were calculated independently in Clonk Rage so a blast at the same vertical position with horizontal offset would cause the target to be blasted vertically only. This was used by players to do aimed flint jumps of course. I don't know if this is a "pro move" we want to keep or if stuff looks better if we make it physically more correct.
Parent - - By Marky [de] Date 2015-07-11 16:33
The flint jump can be implemented in a OnShockwaveHit()-function in the Clonk, if we need it.
Parent - - By Sven2 [us] Date 2015-07-11 17:43
It's not just about the flint jump. It's also e.g. using explosions to blast stuff into the enemy base or across large gaps. It's quite nice visually if a big explosion in a base with lots of stuff causes things to jump up even if that's not physically correct.

Not saying it looks better. Just that we should try it out before blindly making things "more realistic".
Parent - By Armin [de] Date 2015-07-11 18:41
Ack. Objects being pushed against the ground is imo very boring.

Also, I hate the idea of not being able to gain more height in midair with lighting more dynamites.
Parent - By Marky [de] Date 2015-07-11 19:08
Oh, I am not about making things "more realistic". I'll see what I can do.
Parent - - By Marky [de] Date 2015-07-11 20:25
The changes are on my branch for now: changed if-order, damage override parameter, DoShockwave()-function

I wanted to do the upwards fling now, but I found an obstacle: I want objects that are above the explosion, and objects that have contact with the ground and are slightly (5px) below the explosion flinged upwards more. Not all objects have a CNAT value for their vertices, so GetContact(-1) returns 0. It would be great if GetContact() could return nil or something else if the object has no contact with the landscape at all!.
Parent - By Marky [de] Date 2015-09-13 11:25
I totally forgot about these changes and did not push them. I'll test it again since a lot of things have changed in these two months and I had some merge conflicts.
Up Topic General / Help and Questions / Overloading the explosion effect.

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill