.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   Detecting when func_door_rotating entities open (http://forums.bots-united.com/showthread.php?t=1594)

two_masks 04-05-2004 23:34

Detecting when func_door_rotating entities open
 
Just wondering: how can I determine what state {open, closed} a rotating door entity is in? I know how to get the edict of the door entity, but I'm not sure if there's anything to check in that edict- the angle?

In Worldcraft, there's a parameter for this kind of entity called "message"- I tried adding a new message name for a door, but it never seemed to be sent when I opened that door.

Any hints?

-JB

Pierre-Marie Baty 05-05-2004 00:27

Re: Detecting when func_door_rotating entities open
 
I've been searching this for a while too, but there's no miracle solution here AFAIK.

You can check pEdict->v.nextthink. If it is greater than zero, the door is either opening, either in open state and about to close, either closing. If it is equal or smaller to zero, the door is closed.

Else, if you know the location of the door, just do a TraceLine through it. If the TraceLine passes, the door is open, if the TraceLine is blocked, then it is closed.

sfx1999 05-05-2004 03:21

Re: Detecting when func_door_rotating entities open
 
I was peeking around in the source code and found a variable called m_toggle_state. When the door is at the top/open it gets set to TS_AT_TOP.

Code:

void CBaseDoor::DoorHitTop( void )
 {
        if ( !FBitSet( pev->spawnflags, SF_DOOR_SILENT ) )
        {
                STOP_SOUND(ENT(pev), CHAN_STATIC, (char*)STRING(pev->noiseMoving) );
                EMIT_SOUND(ENT(pev), CHAN_STATIC, (char*)STRING(pev->noiseArrived), 1, ATTN_NORM);
        }
 
        ASSERT(m_toggle_state == TS_GOING_UP);
        m_toggle_state = TS_AT_TOP; //RIGHT HERE RIGHT HERE
       
        // toggle-doors don't come down automatically, they wait for refire.
        if (FBitSet(pev->spawnflags, SF_DOOR_NO_AUTO_RETURN))
        {
                // Re-instate touch method, movement is complete
                if ( !FBitSet ( pev->spawnflags, SF_DOOR_USE_ONLY ) )
                        SetTouch( DoorTouch );
        }
        else
        {
                // In flWait seconds, DoorGoDown will fire, unless wait is -1, then door stays open
                pev->nextthink = pev->ltime + m_flWait;
                SetThink( DoorGoDown );
 
                if ( m_flWait == -1 )
                {
                        pev->nextthink = -1;
                }
        }
 
        // Fire the close target (if startopen is set, then "top" is closed) - netname is the close target
        if ( pev->netname && (pev->spawnflags & SF_DOOR_START_OPEN) )
                FireTargets( STRING(pev->netname), m_hActivator, this, USE_TOGGLE, 0 );
 
        SUB_UseTargets( m_hActivator, USE_TOGGLE, 0 ); // this isn't finished
 }



Digging further, I find this:

Code:

typedef enum
 {
  TS_AT_TOP,
  TS_AT_BOTTOM,
  TS_GOING_UP,
  TS_GOING_DOWN
 } TOGGLE_STATE;

m_toggle_state is part of CBaseAnimating. Also, you may need to use some hacks (hope that is the proper term) if the door starts open, is closing, or is opening.

botman 05-05-2004 14:54

Re: Detecting when func_door_rotating entities open
 
You'll also need to use the pvPrivateData pointer and determine the offset of this class member variable yourself (although more than likely, it's the same offset used by the Half-Life SDK), since you can't access class member variables directly outside the MOD source code.

botman

Pierre-Marie Baty 05-05-2004 15:18

Re: Detecting when func_door_rotating entities open
 
...and as botman says, this is a very unreliable method. More advanced MODs may very well decide to change the way the door code works in HL. Then you will read an incorrect variable. Or they simply relocated this variable elsewhere.

I'd not advise anybody to do anything with pvPrivateData if you want robust code. You will figure out the offset and it will work, but it will be guaranteed to work ONLY for your version of the engine and your version of the MOD.

The only thing that'll work for sure no matter which MOD you play is v.nextthink.


All times are GMT +2. The time now is 06:24.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.