Bug #1341: Summons don't vanish on death

Everything about development and the OpenMW source code.
Post Reply
Hallfaer
Posts: 10
Joined: 15 May 2014, 17:10

Bug #1341: Summons don't vanish on death

Post by Hallfaer »

Note: Title summarised due to maximum thread title length. Original text is: Summoned Creatures do not immediately disappear when killed.

I looked into this for a short while, but I'm not too familiar with the code. I think this is the relevant code from actors.cpp:534

Code: Select all

if (found != (magnitude > 0))
            {
                if (magnitude > 0)
                {
                    //The creature was not found, but the magnitude is greater than zero. The creature should be spawned.
                }
                else
                {
                    //The creature was found, but the magnitude is zero (or lower?). The creature exists, but the duration has ended, and it should be removed.
                }
            }
I do not understand the underlying system enough to fix it right away, but maybe someone someone can give me a pointer on how to check whether the found creature is still alive. I propose to change the code to this:

Code: Select all

if (found && (magnitude <= 0 || [found creature is dead]))
{
     //The creature should be removed because the spell expired, or the creature died. (I think the same code can be used in both cases)
}
else if (magnitude > 0)
{
        //The creature was not found but the magnitude is greater than zero. The creature should be spawned.
}
The main reason why I have not made the change, is that I do not know how to check whether the creature is dead or not.
Can anyone give me a pointer? Or explain why I'm totally wrong about this, in case I am.
Last edited by Hallfaer on 07 Jun 2014, 12:07, edited 1 time in total.
User avatar
cc9cii
Posts: 523
Joined: 28 Mar 2013, 04:01

Re: Bug #1341: Summons don't vanish on death

Post by cc9cii »

Not familiar with the code you've quoted, but to check if an actor is dead:

Code: Select all

actor.getClass().getCreatureStats(actor).isDead()
I've not tried it, but in your case it might be:

Code: Select all

ref.getPtr().getClass().getCreatureStats(ref.getPtr()).isDead()
Hallfaer
Posts: 10
Joined: 15 May 2014, 17:10

Re: Bug #1341: Summons don't vanish on death

Post by Hallfaer »

Hmm...
I'm not sure anymore whether this is the right way to do this.
Looking up all summons, every tick, to check whether they're still alive is ugly. An event driven solution would be much nicer. Is there a flag on creatures that indicates whether they are a summon or not? If so, it would make sense to handle this in a logical fashion upon creature death.
User avatar
cc9cii
Posts: 523
Joined: 28 Mar 2013, 04:01

Re: Bug #1341: Summons don't vanish on death

Post by cc9cii »

Yes. If you create a good pattern hopefully others will start using the same elsewhere... Might be a bit of work... IMHO of course.
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Bug #1341: Summons don't vanish on death

Post by scrawl »

One way you can identify summons is that they have an AiFollow package that never ends. That's definitely not used by anything else.
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Bug #1341: Summons don't vanish on death

Post by scrawl »

Or you just iterate over all registered Actors and check if any of them own this creature.
User avatar
silentthief
Posts: 456
Joined: 18 Apr 2013, 01:20
Location: Currently traversing the Ascadian Isles

Re: Bug #1341: Summons don't vanish on death

Post by silentthief »

Regarding summoned creatures not vanishing properly, vanilla Morrowind had an exploit where if you could open the "dead body" container fast enough you could loot the corpse before it vanished. Golden Saints almost always had money items worth selling off. I think this should NOT be allowed, IMHO.

ST
Hallfaer
Posts: 10
Joined: 15 May 2014, 17:10

Re: Bug #1341: Summons don't vanish on death

Post by Hallfaer »

silentthief wrote:Regarding summoned creatures not vanishing properly, vanilla Morrowind had an exploit where if you could open the "dead body" container fast enough you could loot the corpse before it vanished. Golden Saints almost always had money items worth selling off. I think this should NOT be allowed, IMHO.

ST
This was patched I think, but it was in one of the early version numbers of Morrowind. I never managed it in the GotY edition.
scrawl wrote:One way you can identify summons is that they have an AiFollow package that never ends. That's definitely not used by anything else.
That'd be implicit, and would be a bad idea, since it is entirely valid for mods to have the same behaviour on non-summon creatures. Pack animals (e.g. guars) may have this behaviour, but be bought instead of summoned. The player uses them to store items, and disappearing them on death would be bad form. Though treating it as an in-game scam by a savvy conjurer could lead to a hilarious side-quest. (I kind of want that such a mod now)
scrawl wrote:Or you just iterate over all registered Actors and check if any of them own this creature.
That's actually what I'd like to avoid, since iterating over all actors every frame is something to be avoided at best, and if it needs to be done, I'd design a monolithic iterator to handle it, that handles everything that requires iteration over all actors. That's far more time-efficient than iterating the heck out of things, simply because it's the easy solution.

You do however create an interesting point. Upon the death of a creature, we may check whether it has an owner. Then we can grab the owner without iteration, and check whether that owner summoned this creature, and if so, treat the creature as a summon, and handle it's death that way. I'll look into that.
cc9cii wrote:Yes. If you create a good pattern hopefully others will start using the same elsewhere... Might be a bit of work... IMHO of course.
I was thinking of adding it to the creature-data, but make it optional, that way it would not conflict with native mods and save-games, nor would it be initialised and gobble up memory for non-summoned creatures. However if what Scrawl says is true, the data can already be gleaned from the current creature-data with low time and space complexity.
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Bug #1341: Summons don't vanish on death

Post by scrawl »

That'd be implicit, and would be a bad idea, since it is entirely valid for mods to have the same behaviour on non-summon creatures.
No, that is not possible. The AiFollow constructor we are talking about is not exposed by the aifollow console commands. Only summons can use it.
Hallfaer
Posts: 10
Joined: 15 May 2014, 17:10

Re: Bug #1341: Summons don't vanish on death

Post by Hallfaer »

scrawl wrote:
That'd be implicit, and would be a bad idea, since it is entirely valid for mods to have the same behaviour on non-summon creatures.
No, that is not possible. The AiFollow constructor we are talking about is not exposed by the aifollow console commands. Only summons can use it.
That is interesting. I already had a similar idea:

Upon creature death, check AiFollow to check who they're following, check whether that actor has a corresponding summon, if so, delete the creature, and end the summon magic-effect on the actor.

However I could not find in the code how to access:
An on-death function for creatures (I could find a script handle, but I don't think it should go there)
Check the owner of the creature (as mentioned above, but I could not find a stat that correlated with a creature's owner)
Check the AiFollow target of the creature.

I do not understand the code that well, and I wish it was more expansively commented. Maybe someone can give me a few hints?

EDIT: Also, I'll probably be busy this week, so maybe I'll have to postpone this to later.
Post Reply