//LRC void CBaseDoor :: PostSpawn( void ) { if (m_pMoveWith) m_vecPosition1 = pev->origin - m_pMoveWith->pev->origin; else m_vecPosition1 = pev->origin; // Subtract 2 from size because the engine expands bboxes by 1 in all directions m_vecPosition2 = m_vecPosition1 + (pev->movedir * (fabs( pev->movedir.x * (pev->size.x-2) ) + fabs( pev->movedir.y * (pev->size.y-2) ) + fabs( pev->movedir.z * (pev->size.z-2) ) - m_flLip)); ASSERTSZ(m_vecPosition1 != m_vecPosition2, "door start/end positions are equal"); if ( FBitSet (pev->spawnflags, SF_DOOR_START_OPEN) ) { // swap pos1 and pos2, put door at pos2 if (m_pMoveWith) { m_vecSpawnOffset = m_vecSpawnOffset + (m_vecPosition2 + m_pMoveWith->pev->origin) - pev->origin; UTIL_AssignOrigin(this, m_vecPosition2 + m_pMoveWith->pev->origin); } else { m_vecSpawnOffset = m_vecSpawnOffset + m_vecPosition2 - pev->origin; UTIL_AssignOrigin(this, m_vecPosition2); } Vector vecTemp = m_vecPosition2; m_vecPosition2 = m_vecPosition1; m_vecPosition1 = vecTemp; // ALERT(at_console, "func_door postspawn: origin %f %f %f\n", pev->origin.x, pev->origin.y, pev->origin.z); } }
// LRC- bInitiator is true if this is being called directly, rather than because pEntity is moving with something else. void UTIL_AssignOrigin(CBaseEntity *pEntity, const Vector vecOrigin, BOOL bInitiator) { Vector vecDiff = vecOrigin - pEntity->pev->origin; UTIL_SetOrigin(pEntity, vecOrigin); if (bInitiator && pEntity->m_pMoveWith) { pEntity->m_vecOffsetOrigin = pEntity->pev->origin - pEntity->m_pMoveWith->pev->origin; } if (pEntity->m_pChildMoveWith) // now I've moved pEntity, does anything else have to move with it? { CBaseEntity* pChild = pEntity->m_pChildMoveWith; Vector vecTemp; while (pChild) { if (pChild->pev->movetype != MOVETYPE_PUSH || pChild->pev->velocity == pEntity->pev->velocity) // if the child isn't moving under its own power { UTIL_AssignOrigin(pChild, vecOrigin + pChild->m_vecOffsetOrigin, FALSE); } else { vecTemp = vecDiff + pChild->pev->origin; UTIL_AssignOrigin(pChild, vecTemp, FALSE); } pChild = pChild->m_pSiblingMoveWith; } } }
void CBaseDoor :: SetToggleState( int state ) { if ( state == TS_AT_TOP ) { if (m_pMoveWith) UTIL_AssignOrigin( this, m_vecPosition2 + m_pMoveWith->pev->origin); else UTIL_AssignOrigin( this, m_vecPosition2 ); } else { if (m_pMoveWith) UTIL_AssignOrigin( this, m_vecPosition1 + m_pMoveWith->pev->origin); else UTIL_AssignOrigin( this, m_vecPosition1 ); } }
void CTriggerCamera::Move( void ) { // Not moving on a path, return if (!m_pGoalEnt) return; // Subtract movement from the previous frame pev->frags -= pev->speed * gpGlobals->frametime; // Have we moved enough to reach the target? if ( pev->frags <= 0 ) { // Fire the passtarget if there is one if ( m_pGoalEnt->pev->message ) { UTIL_FireTargets( m_pGoalEnt->pev->message, this, this, USE_TOGGLE, 0 ); if ( FBitSet( m_pGoalEnt->pev->spawnflags, SF_CORNER_FIREONCE ) ) m_pGoalEnt->pev->message = 0; } if ( FBitSet( m_pGoalEnt->pev->spawnflags, SF_CORNER_TELEPORT ) ) { m_pGoalEnt = m_pGoalEnt->GetNext(); if ( m_pGoalEnt ) UTIL_AssignOrigin( this, m_pGoalEnt->pev->origin ); } if ( FBitSet( m_pGoalEnt->pev->spawnflags, SF_CORNER_WAITFORTRIG ) ) { //strange feature... } // Time to go to the next target m_pGoalEnt = m_pGoalEnt->GetNext(); // Set up next corner if ( !m_pGoalEnt ) UTIL_SetVelocity( this, g_vecZero ); else { pev->message = m_pGoalEnt->pev->targetname; //save last corner pev->armorvalue = m_pGoalEnt->pev->speed; Vector delta = m_pGoalEnt->pev->origin - pev->origin; pev->frags = delta.Length(); pev->movedir = delta.Normalize(); m_flDelay = gpGlobals->time + m_pGoalEnt->GetDelay(); } } if ( m_flDelay > gpGlobals->time ) pev->speed = UTIL_Approach( 0, pev->speed, 500 * gpGlobals->frametime ); else pev->speed = UTIL_Approach( pev->armorvalue, pev->speed, 500 * gpGlobals->frametime ); if( !pTarget ) UTIL_WatchTarget( this, m_pGoalEnt ); // watch for track float fraction = 2 * gpGlobals->frametime; UTIL_SetVelocity( this, ((pev->movedir * pev->speed) * fraction) + (pev->velocity * ( 1 - fraction ))); }
void UTIL_MergePos(CBaseEntity *pEnt, int loopbreaker) { if (loopbreaker <= 0)return; if (!pEnt->m_pMoveWith)return; Vector forward, right, up, vecOrg, vecAngles; UTIL_MakeVectorsPrivate(pEnt->m_pMoveWith->pev->angles, forward, right, up); if (pEnt->m_pMoveWith->pev->flags & FL_MONSTER) vecOrg = pEnt->m_vecPostAssistOrg = pEnt->m_pMoveWith->pev->origin + (forward * pEnt->m_vecOffsetOrigin.x) + (right * pEnt->m_vecOffsetOrigin.y) + (up * pEnt->m_vecOffsetOrigin.z); else vecOrg = pEnt->m_vecPostAssistOrg = pEnt->m_pMoveWith->pev->origin + (forward * pEnt->m_vecOffsetOrigin.x) + (-right * pEnt->m_vecOffsetOrigin.y) + (up * pEnt->m_vecOffsetOrigin.z); vecAngles = pEnt->m_vecPostAssistAng = pEnt->m_pMoveWith->pev->angles + pEnt->m_vecOffsetAngles; if (pEnt->m_pChildMoveWith) { CBaseEntity *pMoving = pEnt->m_pChildMoveWith; int sloopbreaker = MAX_MOVEWITH_DEPTH; while (pMoving) { UTIL_MergePos(pMoving, loopbreaker - 1); pMoving = pMoving->m_pSiblingMoveWith; sloopbreaker--; if (sloopbreaker <= 0)break; } } if (pEnt->m_iLFlags & LF_MERGEPOS) { UTIL_AssignOrigin(pEnt, vecOrg); UTIL_AssignAngles(pEnt, vecAngles); ClearBits(pEnt->m_iLFlags, LF_MERGEPOS); } if (pEnt->m_iLFlags & LF_POSTORG) { pEnt->pev->origin = vecOrg; pEnt->pev->angles = vecAngles; SetBits(pEnt->m_iLFlags, LF_DODESIRED); //refresh position every frame if (!pEnt->m_pAssistLink) UTIL_AddToAssistList(pEnt); } }
void CMomentaryDoor::Spawn( void ) { SetMovedir (pev); pev->solid = SOLID_BSP; pev->movetype = MOVETYPE_PUSH; UTIL_SetOrigin(this, pev->origin); SET_MODEL( ENT(pev), STRING(pev->model) ); // if (pev->speed == 0) // pev->speed = 100; if (pev->dmg == 0) pev->dmg = 2; m_iState = STATE_OFF; m_vecPosition1 = pev->origin; // Subtract 2 from size because the engine expands bboxes by 1 in all directions making the size too big m_vecPosition2 = m_vecPosition1 + (pev->movedir * (fabs( pev->movedir.x * (pev->size.x-2) ) + fabs( pev->movedir.y * (pev->size.y-2) ) + fabs( pev->movedir.z * (pev->size.z-2) ) - m_flLip)); ASSERTSZ(m_vecPosition1 != m_vecPosition2, "door start/end positions are equal"); //LRC: FIXME, move to PostSpawn if ( FBitSet (pev->spawnflags, SF_DOOR_START_OPEN) ) { // swap pos1 and pos2, put door at pos2 UTIL_AssignOrigin(this, m_vecPosition2); Vector vecTemp = m_vecPosition2; m_vecPosition2 = m_vecPosition1; m_vecPosition1 = vecTemp; } if (m_pMoveWith) { m_vecPosition1 = m_vecPosition1 - m_pMoveWith->pev->origin; m_vecPosition2 = m_vecPosition2 - m_pMoveWith->pev->origin; } Precache(); SetTouch( NULL ); }
void CBaseToggle :: LinearMoveDoneNow( void ) { Vector vecDest; // ALERT(at_console, "LMDone %s\n", STRING(pev->targetname)); UTIL_SetVelocity(this, g_vecZero);//, TRUE); // pev->velocity = g_vecZero; if (m_pMoveWith) { vecDest = m_vecFinalDest + m_pMoveWith->pev->origin; // ALERT(at_console, "LMDone %s: p.origin = %f %f %f, origin = %f %f %f. Set it to %f %f %f\n", STRING(pev->targetname), m_pMoveWith->pev->origin.x, m_pMoveWith->pev->origin.y, m_pMoveWith->pev->origin.z, pev->origin.x, pev->origin.y, pev->origin.z, vecDest.x, vecDest.y, vecDest.z); } else { vecDest = m_vecFinalDest; // ALERT(at_console, "LMDone %s: origin = %f %f %f. Set it to %f %f %f\n", STRING(pev->targetname), pev->origin.x, pev->origin.y, pev->origin.z, vecDest.x, vecDest.y, vecDest.z); } UTIL_AssignOrigin(this, vecDest); DontThink(); //LRC //pev->nextthink = -1; if ( m_pfnCallWhenMoveDone ) (this->*m_pfnCallWhenMoveDone)(); }
// LRC- change the origin to the given position, and bring any movewiths along too. void UTIL_AssignOrigin(CBaseEntity *pEntity, const Vector vecOrigin) { UTIL_AssignOrigin(pEntity, vecOrigin, TRUE); }