Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
mgr_inz_rafal

[zDoom Dev] Spawning and destroying map things

Recommended Posts

Hello All,

I have a question to guys that know zDoom source code. I tried to register on "forum.zdoom.org", but they asked me some questions about zombies in Plutonia and official wikis that I don't know the answer to. Now I cannot register at all (maximum number of tries reached).

 

So I'll try my luck here.

 

I am looking for an ultimate place in the code that will let me track spawning and destroying of map items.

 

What I found so far:

 

Destroying:

I hooked myself to the "void AActor::RemoveFromHash()" function of p_mobj.cpp file. This seem to be working correctly.

 

Spawning:

I hooked myself to the end of "AActor *AActor::StaticSpawn (PClassActor *type, const DVector3 &pos, replace_t allowreplacement, bool SpawningMapThing)" function.

 

This works kinda ok until I, for example, pickup Plasma Gun. In that case the gun is removed from map, but new thing at position 0,0,0 is spawned. The tag says "$AMMO_CELLS", so I think this is an inventory item that is spawned in game but not on the map, maybe (see picture)? But this doesn't happen for Chaingun and regular ammo, making me confused :/

 

My idea is to track spawning and destroying of every map thing (I mean the things that appear on automap after "iddtiddt"). Can anyone comment if I hooked myself to correct places?

 

image.png.7fbaaf70e3b320ee12e90eb9ee6bd68b.png

 

Share this post


Link to post
3 hours ago, mgr_inz_rafal said:

This works kinda ok until I, for example, pickup Plasma Gun. In that case the gun is removed from map, but new thing at position 0,0,0 is spawned. The tag says "$AMMO_CELLS", so I think this is an inventory item that is spawned in game but not on the map, maybe (see picture)? But this doesn't happen for Chaingun and regular ammo, making me confused :/

It's spawned in the player's inventory, which is why coordinates don't matter. For the chaingun, since it uses bullets, and the player already starts the game with bullets, there's no need to spawn anything.

Share this post


Link to post

Thank you, that gives me some insight.

 

Can you help me, assuming I have an AActor class object, how can I check if it is going to be spawned on a map? I tried to figure it out from LinkToWorld(), but failed.

 

Another question: having the same object how can I tell which class it belongs to? Is it an Imp, a Berserk or a Megasphere, for example? Like the "Type" property shown in Doom Builder (2002 = Chaingun, 3005 = Cacodemon). Once I know this I'll be able to manually filter the things I am interested in.

Share this post


Link to post

OK, here's what I found. To get an exact type name of an actor you can use

actor->GetClass()->TypeName.GetChars()

But this will give you, for example "Cell" for items spawned either in Inventory or on the map.

 

To ignore the items spawned in the inventory I use the following condition

actor->IsKindOf(RUNTIME_CLASS(AInventory))

 

Share this post


Link to post

Hello,

Today I had some more time to work on this issue and I feel obligated to give you an update, since it turned out that what I wrote above is bulls*.*it :)

 

Correct apporach to monitor all active actors:

  1. Monitor each thing spawned by engine (even if it's spawned in the inventory) [AActor::StaticSpawn]
  2. Remove from monitoring things that are converted into inventory items (Clips, Pistol, etc.) [AInventory::BecomeItem]
  3. Remove from monitoring all things that are destroyed (BulletPuffs, etc.) [AActor::OnDestroy]

Thanks for your attention :)

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×