I want to create an object that has a custom explosion effect when it hits the landscape. I added
to the object script, hoping that it would overload the global function. Why does this not work?
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?
Because that is never called in an object context, you need to declare it global.

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;
).


global func Explode(int level, bool silent)
{
if(!this) FatalError("Function Explode must be called from object context");
[...]
I could call
DoExplosion(x, y, level)
in global context before.


Well, xkcd holds once more :-)

ExplosionEffect
that just plays the visuals without the damage stuff :)(Even in CR, for Keepers/Caedes for example)
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.
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.

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.
The flint jump can be implemented in a OnShockwaveHit()-function in the Clonk, if we need it.

Not saying it looks better. Just that we should try it out before blindly making things "more realistic".
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.
Also, I hate the idea of not being able to gain more height in midair with lighting more dynamites.
Oh, I am not about making things "more realistic". I'll see what I can do.
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!.
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!.
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill