Page 1 of 1
Informations from virtual function
Posted: Sat Feb 17, 2018 9:40 am
by Apeirogon
Is there are any way to obtain data from virtual function? And I talk not about result, but for pointers. Mostly pointers...
Like, inside damage modj processed pointer "inflictor" and "source". I want extract that pointers, without rewriting damage mobj functions.
Is it possible?
Re: Informations from virtual function
Posted: Fri Feb 23, 2018 10:10 pm
by Matt
The only way I can think of is to create a pointer in the calling actor/thinker and store it in that...
Re: Informations from virtual function
Posted: Sat Feb 24, 2018 12:23 am
by Arctangent
I mean, if you mean actually rewriting the functions as opposed to avoiding overriding them entirely, you can just call i.e. return Super.DamageMobj( inflictor, source, damage, mod, flags, angle ); at the end of your overriden DamageMobj( inflictor, source, damage, mod, flags, angle ) and you'll retain the standard DamageMobj() functionality while being able to tack on your own, such as storing inflictor and source elsewhere.
Re: Informations from virtual function
Posted: Sat Feb 24, 2018 2:07 am
by Matt
Arctangent: "And I talk not about result, but for pointers."
I think Apeirogon means that sometimes an overridden virtual does some extra stuff that results in new data being produced that could be useful outside of the function. E.g., damagemobj might get you new information on damagetype, source, source's actual intended target, mass of inflictor, etc.
One other alternative would be to take whatever it is you want to do and actually put it inside that function, but that can get a bit bloaty.
Re: Informations from virtual function
Posted: Sat Feb 24, 2018 4:12 am
by Apeirogon
When I say "dont rewrite virtual functions" I mean "DONT TOUCH IT AT ALL, and left it pure and innocent as it was".
Like, I want make monster that remember all actors that hit it, pushing it into array "thing that I hate!!!!ONEONE", and pick target to chase from it depending of how much damage each of this actors inflict to it. Like, if caco inflict 30 damage to cyberdemon, imp 44 and player 12, cyberdemon first seek and destroy imp, then caco and only then player. Of course only if some one hit cyberdemon, while he chase player/dont have any target yet.
This can be easily, well....relatively easy, done with overiding damage mobj virtual. But it only works only for this cyberdemon/all actors that inherit from this base actor.
If I want do this for monster from other mod I need copy-paste code from my mod or change inheritance tree in other mod to make it inherit from my "monster base class".
I try do so using inventory items, give out each monster "thing that I hate" token/mark using spawn event handler, but they can get access to owners virtual functions "owner.super.damagemobj (paramethers)".
I focused on pointers, in case if this cant be done exactly as I want, save pointers and damage, to at least have monster that act "You hit me!? DIE!! And you hit me?! DIE!!! And you! And you! Oooo.... I see you come back from dead... I still remeber what you did last summer five minutes ago!!! DIE!!".
Maybe I should write this in first post...but this just example that I came up with one minutes ago...
Re: Informations from virtual function
Posted: Sat Feb 24, 2018 6:12 am
by gwHero
Just thinking.. maybe the event WorldThingDamaged would be of help?
Re: Informations from virtual function
Posted: Sat Feb 24, 2018 1:50 pm
by Apeirogon
It work only for this particular case.
But do we have, as example, can collide with events?
Looks like in this moment there are no way to obtain anything from virtual functions, without rewriting it.
Re: Informations from virtual function
Posted: Sat Feb 24, 2018 2:09 pm
by gwHero
Correct, it was more for this specific case.