Informations from virtual function

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Informations from virtual function

Postby Apeirogon » Sat Feb 17, 2018 10:40 am

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?
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Informations from virtual function

Postby Matt » Fri Feb 23, 2018 11:10 pm

The only way I can think of is to create a pointer in the calling actor/thinker and store it in that...
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Informations from virtual function

Postby Arctangent » Sat Feb 24, 2018 1:23 am

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.
User avatar
Arctangent
squawky
 
Joined: 06 Nov 2014
Discord: SquawkyAtan#2371

Re: Informations from virtual function

Postby Matt » Sat Feb 24, 2018 3:07 am

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.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Informations from virtual function

Postby Apeirogon » Sat Feb 24, 2018 5:12 am

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...
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Informations from virtual function

Postby gwHero » Sat Feb 24, 2018 7:12 am

Just thinking.. maybe the event WorldThingDamaged would be of help?
User avatar
gwHero
Be your own Siddhartha
 
Joined: 08 May 2017
Location: The Netherlands

Re: Informations from virtual function

Postby Apeirogon » Sat Feb 24, 2018 2:50 pm

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.
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Informations from virtual function

Postby gwHero » Sat Feb 24, 2018 3:09 pm

Correct, it was more for this specific case.
User avatar
gwHero
Be your own Siddhartha
 
Joined: 08 May 2017
Location: The Netherlands


Return to Scripting

Who is online

Users browsing this forum: No registered users and 3 guests