void Camera::MenuCameraRotation()
{
	// Create rotation matrix
	m_menuRotation += (float)GLOBAL::GetInstance().GetDeltaTime() / 16.0f;
	if (m_menuRotation > 6.28f)
	{
		m_menuRotation = 0.0f;
	}
	DirectX::XMMATRIX rotation = DirectX::XMMatrixRotationY(m_menuRotation);

	// Lock shadows in center.
	DirectX::XMFLOAT3 shadowPosition = GetPosition();
	DirectX::XMStoreFloat3(&shadowPosition, DirectX::XMVector3TransformCoord(DirectX::XMLoadFloat3(&shadowPosition), rotation));
	shadowPosition.x *= 0.8f;
	DirectX::XMFLOAT3 position = DirectX::XMFLOAT3(25.0f + shadowPosition.x, 100.0f, 50.0f);

	UpdatePosition(position);
	UpdateTarget(DirectX::XMFLOAT3(shadowPosition.x, 5.0f, 0.0f));
	UpdateViewMatrix();
	UpdateProjectionMatrix(true);
	GraphicsEngine::SetLightViewAndProjection(GetViewMatrix(), GetProjectionMatrix());

	// Lock camera in center and rotate camera.	
	position = DirectX::XMFLOAT3(0.0f, 40.0f, -24.0f);

	UpdatePosition(position);
	UpdateTarget(DirectX::XMFLOAT3(0.0f, 7.5f, 0.0f));
	UpdateViewMatrix();
	UpdateProjectionMatrix(false);

	DirectX::XMStoreFloat4x4(&m_viewMatrix, DirectX::XMMatrixMultiply(rotation, DirectX::XMLoadFloat4x4(&m_viewMatrix)));

	GraphicsEngine::SetViewAndProjection(GetViewMatrix(), GetProjectionMatrix());
}
Ejemplo n.º 2
0
// BUGBUG: This design causes a latentcy.  When the button is retriggered, the first impulse
// will send the target in the wrong direction because the parameter is calculated based on the
// current, not future position.
void CMomentaryRotButton::__MAKE_VHOOK(Use)(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
{
	pev->ideal_yaw = CBaseToggle::AxisDelta(pev->spawnflags, pev->angles, m_start) / m_flMoveDistance;

	UpdateAllButtons(pev->ideal_yaw, 1);
	UpdateTarget(pev->ideal_yaw);

#if 0
	// Calculate destination angle and use it to predict value, this prevents sending target in wrong direction on retriggering
	Vector dest = pev->angles + pev->avelocity * (pev->nextthink - pev->ltime);
	float value1 = CBaseToggle::AxisDelta(pev->spawnflags, dest, m_start) / m_flMoveDistance;
	UpdateTarget(value1);
#endif
}
void Camera::FollowCharacter(DirectX::XMFLOAT3 p_playerPos)
{
	// Lock shadows on the player.
	DirectX::XMFLOAT3 playerPosition = p_playerPos;
	DirectX::XMFLOAT3 position = DirectX::XMFLOAT3(playerPosition.x + 25.0f, playerPosition.y + 100.0f, playerPosition.z + 50.0f);
	DirectX::XMFLOAT3 target = playerPosition;

	UpdatePosition(position);
	UpdateTarget(target);
	UpdateViewMatrix();
	UpdateProjectionMatrix(true);
	GraphicsEngine::SetLightViewAndProjection(GetViewMatrix(), GetProjectionMatrix());

	// Visibility view projection..
	playerPosition = p_playerPos;
	position = DirectX::XMFLOAT3(playerPosition.x, playerPosition.y + 30.0f, playerPosition.z);
	target = playerPosition;

	UpdatePosition(position);
	UpdateTarget(target);
	UpdateViewMatrix();
	GraphicsEngine::SetViewPolygonMatrix(GetViewMatrix());
	

	// Lock camera on the player.
	playerPosition = p_playerPos;
	position = DirectX::XMFLOAT3(playerPosition.x, playerPosition.y + 30.0f, playerPosition.z - 15.0f);
	target = playerPosition;

	SetOutliningRayPosition(position);
	SetOutliningRayTarget(target);

	if (GLOBAL::GetInstance().CAMERA_MOVING)
	{
		MovingCamera(playerPosition);
	}
	else
	{
		UpdatePosition(position);
		UpdateTarget(target);
		UpdateViewMatrix();
		UpdateProjectionMatrix(false);
		GraphicsEngine::SetViewAndProjection(GetViewMatrix(), GetProjectionMatrix());
		m_oldPosition = position;
	}	

	GraphicsEngine::UpdateVisibilityPolygon(Point(playerPosition.x, playerPosition.z), (float)GLOBAL::GetInstance().GetDeltaTime());
}
Ejemplo n.º 4
0
//-----------------------------------------------------------------------------
// Purpose: MoveDone function for rotating back to the start position.
//-----------------------------------------------------------------------------
void CMomentaryRotButton::ReturnMoveDone( void )
{
	float value = GetPos( GetLocalAngles() );
	if ( value <= 0 )
	{
		//
		// Got back to the start, stop spinning.
		//
		SetLocalAngularVelocity( vec3_angle );
		SetLocalAngles( m_start );

		UpdateTarget( 0, NULL );

		SetMoveDoneTime( -1 );
		SetMoveDone( NULL );

		SetNextThink( TICK_NEVER_THINK );
		SetThink( NULL );
	}
	else
	{
		SetLocalAngularVelocity( -m_returnSpeed * m_vecMoveAng );
		SetMoveDoneTime( 0.1f );

		SetThink( &CMomentaryRotButton::UpdateThink );
		SetNextThink( gpGlobals->curtime + 0.01f );
	}
}
Ejemplo n.º 5
0
//-----------------------------------------------------------------------------
// Purpose: Handles the end of motion caused by player use.
//-----------------------------------------------------------------------------
void CMomentaryRotButton::UseMoveDone( void )
{
	SetLocalAngularVelocity( vec3_angle );

	// Make sure our targets stop where we stopped.
	float flPos = GetPos( GetLocalAngles() );
	UpdateTarget( flPos, this );

	// Alert that we've been unpressed
	m_OnUnpressed.FireOutput( m_hActivator, this );

	m_lastUsed = 0;

	if ( !HasSpawnFlags( SF_BUTTON_TOGGLE ) && m_returnSpeed > 0 )
	{
		SetMoveDone( &CMomentaryRotButton::ReturnMoveDone );
		m_direction = -1;

		// Delay before autoreturn.
		SetMoveDoneTime( 0.1f );
	}
	else
	{
		SetThink( NULL );
		SetMoveDone( NULL );
	}
}
Ejemplo n.º 6
0
//------------------------------------------------------------------------------
// Purpose: MoveDone function for the SetPosition input handler. Tracks our
//			progress toward a movement goal and updates our outputs.
//------------------------------------------------------------------------------
void CMomentaryRotButton::SetPositionMoveDone(void)
{
	float flCurPos = GetPos( GetLocalAngles() );

	if ((( flCurPos >= m_IdealYaw ) && ( m_direction == 1 )) ||
		(( flCurPos <= m_IdealYaw ) && ( m_direction == -1 )))
	{
		//
		// We reached or surpassed our movement goal.
		//
		SetLocalAngularVelocity( vec3_angle );
		// BUGBUG: Won't this get the player stuck?
		SetLocalAngles( m_start + m_vecMoveAng * ( m_IdealYaw * m_flMoveDistance ) );
		SetNextThink( TICK_NEVER_THINK );
		SetMoveDoneTime( -1 );
		UpdateTarget( m_IdealYaw, this );
		OutputMovementComplete();
		return;
	}

	// TODO: change this to use a Think function like ReturnThink.
	QAngle vecNewAngles = m_start + m_vecMoveAng * ( m_IdealYaw * m_flMoveDistance );
	float flAngleDelta = fabs( AxisDelta( m_spawnflags, vecNewAngles, GetLocalAngles() ));
	float dt = flAngleDelta / m_flSpeed;
	if ( dt < TICK_INTERVAL )
	{
		dt = TICK_INTERVAL;
		float speed = flAngleDelta / TICK_INTERVAL;
		SetLocalAngularVelocity( speed * m_vecMoveAng * m_direction );
	}
	dt = clamp( dt, TICK_INTERVAL, TICK_INTERVAL * 6);

	SetMoveDoneTime( dt );
}
Ejemplo n.º 7
0
// BUGBUG: This design causes a latentcy.  When the button is retriggered, the first impulse
// will send the target in the wrong direction because the parameter is calculated based on the
// current, not future position.
void CMomentaryRotButton::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	pev->ideal_yaw = CBaseToggle::AxisDelta( pev->spawnflags, pev->angles, m_start ) / m_flMoveDistance;

	UpdateAllButtons( pev->ideal_yaw, 1 );
	UpdateTarget( pev->ideal_yaw );
}
Ejemplo n.º 8
0
    void UpdateAI(const uint32 diff)
    {
        if(DelayTimer > diff)
        {
            DelayTimer -= diff;
            return;
        }
        else if(DelayTimer)
        {
            DelayTimer = 0;
        }

        UpdateTarget(diff);

        if(CheckTeronTimer < diff)
        {
            Creature *pTeron = pInstance->GetCreature(pInstance->GetData64(DATA_TERONGOREFIEND));
            if(!pTeron || !pTeron->isInCombat())
                 m_creature->Kill(m_creature, false);

            CheckTeronTimer = 2000;
        }
        else
            CheckTeronTimer -= diff;

        DoMeleeAttackIfReady();
    }
Ejemplo n.º 9
0
CTool::CTool(CScene* scene)
    : DScene(scene),
      DActive(false)
{
    DPropertiesWidget = new QWidget();
    UpdateTarget(scene);
}
Ejemplo n.º 10
0
bool CItemState::Update(time_point tick)
{
    if (tick > GetEntryTime() + m_castTime && !IsCompleted())
    {
        m_interrupted = false;
        m_interruptable = false;
        UpdateTarget(m_PEntity->IsValidTarget(m_targid, m_PItem->getValidTarget(), m_errorMsg));

        action_t action;

        // attempt to interrupt
        InterruptItem(action);

        if (!m_interrupted)
        {
            FinishItem(action);
        }
        m_PEntity->PAI->EventHandler.triggerListener("ITEM_USE", m_PEntity, m_PItem, &action);
        m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));
        Complete();
    }
    else if (IsCompleted() && tick > GetEntryTime() + m_castTime + m_animationTime)
    {
        m_PEntity->PAI->EventHandler.triggerListener("ITEM_STATE_EXIT", m_PEntity, m_PItem);
        return true;
    }
    return false;
}
void Camera::ResetCameraToLight()
{
	// Reset camera.
	DirectX::XMFLOAT3 target = DirectX::XMFLOAT3(0, 0, 0);
	DirectX::XMFLOAT3 position = DirectX::XMFLOAT3(25.0f, 100.0f, 50.0f);

	UpdatePosition(position);
	UpdateTarget(target);

	m_upVector = DirectX::XMFLOAT3(-25.0f, 100.0f, -50.0f);
	DirectX::XMStoreFloat3(&m_upVector, DirectX::XMVector3Normalize(DirectX::XMLoadFloat3(&m_upVector)));

	m_look = DirectX::XMFLOAT3(-25.0f, -100.0f, -50.0f);
	DirectX::XMStoreFloat3(&m_look, DirectX::XMVector3Normalize(DirectX::XMLoadFloat3(&m_look)));

	m_right = DirectX::XMFLOAT3(25.0f, 0.0f, -50.0f);
	DirectX::XMStoreFloat3(&m_right, DirectX::XMVector3Normalize(DirectX::XMLoadFloat3(&m_right)));

	// Projection data.
	float aspectRatio = (float)GLOBAL::GetInstance().MAX_SCREEN_WIDTH / (float)GLOBAL::GetInstance().MAX_SCREEN_HEIGHT;
	UpdateAspectRatio(aspectRatio);
	UpdateFieldOfView(3.141592f * 0.25f);
	UpdateClippingPlanes(0.1f, 1000.0f);
	UpdateViewMatrix();
	UpdateProjectionMatrix(true);

	GraphicsEngine::SetLightViewAndProjection(GetViewMatrix(), GetProjectionMatrix());
}
Ejemplo n.º 12
0
void GBDebuggerView::StartStopBrain() {
	UpdateTarget();
	if ( ! target ) return;
	GBBrain * brain = target->Brain();
	if ( ! brain ) return;
	brain->SetStatus(brain->Status() == bsOK ? bsStopped : bsOK);
}
Ejemplo n.º 13
0
void CMomentaryRotButton :: ReturnMoveDone( void )
{
	float value = GetPos( GetLocalAngles() );

	SetUse( &CMomentaryRotButton::ButtonUse );

	if( value <= 0 )
	{
		// Got back to the start, stop spinning.
		SetLocalAvelocity( g_vecZero );
		SetLocalAngles( m_start );

		m_iState = STATE_OFF;

		UpdateTarget( 0 );

		SetMoveDoneTime( -1 );
		SetMoveDone( NULL );

		SetNextThink( -1 );
		SetThink( NULL );
	}
	else
	{
		m_iState = STATE_TURN_OFF;

		SetLocalAvelocity( -m_returnSpeed * pev->movedir );
		SetMoveDoneTime( 0.1f );

		SetThink( &CMomentaryRotButton::UpdateThink );
		SetNextThink( 0.01f );
	}
}
Ejemplo n.º 14
0
bool psEntityLabels::HandleEvent(iEvent& /*ev*/)
{
    static unsigned int count = 0;
    if (++count%10 != 0)  // Update once every 10th frame
        return false;

    if (celClient->GetMainPlayer() == NULL)
        return false;  // Not loaded yet

    if (visItems == LABEL_ALWAYS || visCreatures == LABEL_ALWAYS)
    {
        UpdateVisibility();
    }

    if (visItems == LABEL_ONMOUSE || visCreatures == LABEL_ONMOUSE)
    {
        UpdateMouseover();
    }

    if (visItems == LABEL_ONTARGET || visCreatures == LABEL_ONTARGET)
    {
        UpdateTarget();
    }   

    return false;
}
Ejemplo n.º 15
0
void CMomentaryRotButton :: UseMoveDone( void )
{
	SetLocalAvelocity( g_vecZero );

	// make sure our targets stop where we stopped.
	float flPos = GetPos( GetLocalAngles( ));
	UpdateTarget( flPos );

	m_lastUsed = 0;

	if( FBitSet( pev->spawnflags, SF_MOMENTARY_ROT_BUTTON_AUTO_RETURN ) && m_returnSpeed > 0 )
	{
		SetMoveDone( &CMomentaryRotButton::ReturnMoveDone );
		m_direction = -1;

		if( flPos >= 1.0f )
		{
			// disable use until button is waiting
			SetUse( NULL );

			// delay before autoreturn.
			SetMoveDoneTime( m_flDelay + 0.1f );
		}
		else SetMoveDoneTime( 0.1f );
	}
	else
	{
		SetThink( NULL );
		SetMoveDone( NULL );
	}
}
Ejemplo n.º 16
0
void CState::SetTarget(uint16 _targid)
{
    if (_targid != m_targid)
    {
        m_targid = _targid;
        UpdateTarget(_targid);
    }
}
Ejemplo n.º 17
0
void CMomentaryRotButton::Return( void )
{
	float value = CBaseToggle::AxisDelta( pev->spawnflags, pev->angles, m_start ) / m_flMoveDistance;

	UpdateAllButtons( value, 0 );	// This will end up calling UpdateSelfReturn() n times, but it still works right
	if ( value > 0 )
		UpdateTarget( value );
}
Ejemplo n.º 18
0
CAttackState::CAttackState(CBattleEntity* PEntity, uint16 targid) :
    CState(PEntity, targid),
    m_PEntity(PEntity)
{
    PEntity->animation = ANIMATION_ATTACK;
    PEntity->updatemask |= UPDATE_HP;
    UpdateTarget();
    m_PEntity->PAI->EventHandler.triggerListener("ENGAGE", m_PEntity, GetTarget());
}
Ejemplo n.º 19
0
bool GBDebuggerView::Step() {
	UpdateTarget();
	if ( ! target ) return true;
	GBBrain * brain = target->Brain();
	if ( ! brain ) return true;
	if ( ! brain->Ready() ) return true;
	redrawAnyway = true;
	brain->Step(target, &world);
	return ! brain->Ready();
}
Ejemplo n.º 20
0
void GBDebuggerView::Draw() {
	UpdateTarget();
	DrawBackground();
	GBRect box;
	if ( ! target ) {
		DrawStringLeft("No robot selected", 4, 20, 12);
		box.top = kEdgeSpace;
		box.bottom = box.top + kProfileBoxHeight;
		box.right = Width() - kEdgeSpace;
		box.left = box.right - kProfileBoxWidth;
		DrawProfileBox(box);
	} else {
	// draw robot name
		box.left = box.top = kEdgeSpace;
		box.right = Width() - kEdgeSpace;
		box.bottom = box.top + kStatusBoxHeight;
		DrawStatusBox(box);
	// get brain
		const GBStackBrain * sbrain = dynamic_cast<GBStackBrain *>(target->Brain());
		if ( sbrain ) {
		// draw pc
			box.top = box.bottom + kEdgeSpace;
			box.bottom = box.top + kPCBoxHeight;
			box.right -= kHardwareBoxWidth + kEdgeSpace;
			DrawPCBox(box, sbrain);
		// draw stack
			box.top = box.bottom + kEdgeSpace;
			box.bottom = box.top + kStackBoxHeight;
			box.right = (Width() - kHardwareBoxWidth - kEdgeSpace) / 2;
			DrawStackBox(box, sbrain);
		// draw return stack
			box.left = (Width() - kHardwareBoxWidth + kEdgeSpace) / 2;
			box.right = Width() - kHardwareBoxWidth - kEdgeSpace * 2;
			DrawReturnStackBox(box, sbrain);
		// draw variables
			box.top = box.bottom + kEdgeSpace;
			box.bottom = box.top + (sbrain->NumVariables() + sbrain->NumVectorVariables()) * 10 + 15;
			box.left = kEdgeSpace;
			DrawVariablesBox(box, sbrain);
		// draw prints
			box.top = box.bottom + kEdgeSpace;
			box.bottom = box.top + kPrintBoxHeight;
			DrawPrintBox(box, sbrain);
		}
	// draw hardware
		box.top = kStatusBoxHeight + kEdgeSpace * 2;
		box.right = Width() - kEdgeSpace;
		box.left = box.right - kHardwareBoxWidth;
		box.bottom = box.top + kHardwareBoxHeight;
		DrawHardwareBox(box);
	}
// record
	worldChanges = world.ChangeCount();
	redrawAnyway = false;
}
Ejemplo n.º 21
0
void CMomentaryRotButton::Return(void)
{
	float value = CBaseToggle::AxisDelta(pev->spawnflags, pev->angles, m_start) / m_flMoveDistance;
	UpdateAllButtons(value, 0);

	if (value > 0)
	{
		if (!FStringNull(pev->target))
			UpdateTarget(value);
	}
}
Ejemplo n.º 22
0
void CInterfaceUnit::OnLoop()
{
    CInterface::OnLoop();

	CleanUpTargetSurf();
    CleanUpHealthBar();

    UpdateUnit();

	UpdateTarget();

    UpdateHealth();
}
void Camera::MovingCamera(DirectX::XMFLOAT3 p_pos)
{
	float moveX, moveY, centerX, centerY, posX, posY;
	centerX = GLOBAL::GetInstance().CURRENT_SCREEN_WIDTH * 0.5f;
	centerY = GLOBAL::GetInstance().CURRENT_SCREEN_HEIGHT * 0.5f;
	posX = InputManager::GetInstance()->GetMousePositionX() - centerX;
	posY = InputManager::GetInstance()->GetMousePositionY() - centerY;
	float procX = posX / 440;
	float procY = posY / 352; // 512 *0,68 //0.68 = 440/640;
	if (procX > 1.0)
		procX = 1.0;
	if (procX < -1.0)
		procX = -1.0;
	if (procY > 1.0)
		procY = 1.0;
	if (procY < -1.0)
		procY = -1.0;

	moveX = 8 * procX;
	moveY = 8 * procY;

	DirectX::XMFLOAT3 position, target, finalPos;
	DirectX::XMFLOAT3 playerPosition = p_pos;
	position = DirectX::XMFLOAT3(playerPosition.x + moveX, playerPosition.y + 30.0f, playerPosition.z - moveY - 15.0f);
	target = DirectX::XMFLOAT3(playerPosition.x + moveX, 0, playerPosition.z - moveY);

	DirectX::XMStoreFloat3(&finalPos, SmoothStep(DirectX::XMLoadFloat3(&m_oldPosition), DirectX::XMLoadFloat3(&position), 0.25f));
	
	// Set max limits
	if (finalPos.x < -38)
		finalPos.x = -38;
	if (finalPos.x > 38)
		finalPos.x = 38;
	if (finalPos.z > 35)
		finalPos.z = 35;
	if (finalPos.z < -58)
		finalPos.z = -58;

	target = DirectX::XMFLOAT3(finalPos.x, 0, finalPos.z + 15.0f);

	UpdatePosition(finalPos);
	UpdateTarget(target);
	UpdateViewMatrix();
	UpdateProjectionMatrix(false);
	GraphicsEngine::SetViewAndProjection(GetViewMatrix(), GetProjectionMatrix());

	m_oldPosition = finalPos;

	SetOutliningRayPosition(finalPos);
	SetOutliningRayTarget(playerPosition);
};
Ejemplo n.º 24
0
void
BasicCanvasLayer::Paint(DrawTarget* aTarget, SourceSurface* aMaskSurface)
{
  if (IsHidden())
    return;

  FirePreTransactionCallback();
  UpdateTarget();
  FireDidTransactionCallback();

  CompositionOp mixBlendMode = GetEffectiveMixBlendMode();
  PaintWithOpacity(aTarget,
                   GetEffectiveOpacity(),
                   aMaskSurface,
                   mixBlendMode != CompositionOp::OP_OVER ? mixBlendMode : GetOperator());
}
Ejemplo n.º 25
0
CAttackState::CAttackState(CBattleEntity* PEntity, uint16 targid) :
    CState(PEntity, targid),
    m_PEntity(PEntity)
{
    PEntity->SetBattleTargetID(targid);
    PEntity->SetBattleStartTime(server_clock::now());
    UpdateTarget();
    if (!GetTarget() || m_errorMsg)
    {
        PEntity->SetBattleTargetID(0);
        throw CStateInitException(std::move(m_errorMsg));
    }
    if (PEntity->PAI->PathFind)
    {
        PEntity->PAI->PathFind->Clear();
    }
}
Ejemplo n.º 26
0
void
BasicCanvasLayer::Paint(DrawTarget* aDT,
                        const Point& aDeviceOffset,
                        Layer* aMaskLayer)
{
  if (IsHidden())
    return;

  if (IsDirty()) {
    Painted();

    FirePreTransactionCallback();
    UpdateTarget();
    FireDidTransactionCallback();
  }

  if (!mSurface) {
    return;
  }

  const bool needsYFlip = (mOriginPos == gl::OriginPos::BottomLeft);

  Matrix oldTM;
  if (needsYFlip) {
    oldTM = aDT->GetTransform();
    aDT->SetTransform(Matrix(oldTM).
                        PreTranslate(0.0f, mBounds.height).
                        PreScale(1.0f, -1.0f));
  }

  FillRectWithMask(aDT, aDeviceOffset,
                   Rect(0, 0, mBounds.width, mBounds.height),
                   mSurface, ToFilter(mFilter),
                   DrawOptions(GetEffectiveOpacity(), GetEffectiveOperator(this)),
                   aMaskLayer);

  if (needsYFlip) {
    aDT->SetTransform(oldTM);
  }
}
Ejemplo n.º 27
0
void CcsTest::OnCststReverse() 
{
	CWnd* errorPtr;
	CString tmpSystem;
	double tmpXY [3];

	// Capture status of the check boxes before we proceed.
	if (!UpdateData (TRUE)) return;
	tmpSystem = m_SrcKeyName;
	m_SrcKeyName = m_TrgKeyName;
	m_TrgKeyName = tmpSystem;
	SetLabels (false);
	SetLabels (true);
	tmpXY [0] = m_SourceXY [0];
	tmpXY [1] = m_SourceXY [1];
	tmpXY [2] = m_SourceXY [2];
	m_SourceXY [0] = m_TargetXY [0];
	m_SourceXY [1] = m_TargetXY [1];
	m_SourceXY [2] = m_TargetXY [2];
	m_TargetXY [0] = tmpXY [0];
	m_TargetXY [1] = tmpXY [1];
	m_TargetXY [2] = tmpXY [2];
	UpdateSource ();
	FetchSource ();
	errorPtr = Calculate ();
	if (errorPtr == NULL)
	{
		UpdateTarget ();
		errorPtr = GetDlgItem (IDC_CSTST_SRCXLAT);
	}
	else
	{
		char ctemp [256];
		CS_errmsg (ctemp,sizeof (ctemp));
		AfxMessageBox (ctemp);
	}
	GotoDlgCtrl (errorPtr);
	UpdateData (FALSE);
	return;
}
Ejemplo n.º 28
0
BOOL CcsTest::OnInitDialog ()
{
	CWnd *wp;

	CDialog::OnInitDialog ();

	UpdateSource ();
	if (m_SrcKeyName.IsEmpty ()) m_SrcKeyName = "US48";
	if (m_TrgKeyName.IsEmpty ()) m_TrgKeyName = "LL27";
	SetLabels (true);
	SetLabels (false);
	FetchSource ();
	Calculate ();
	UpdateSource ();
	UpdateTarget ();
	UpdateData (FALSE);

	// Disable the Help button if help is not available.
	wp = GetDlgItem (ID_CSTST_HELP);
	if (wp != NULL) wp->EnableWindow (CS_isHlpAvailable ());

	return (TRUE);
};
Ejemplo n.º 29
0
CItemState::CItemState(CCharEntity* PEntity, uint16 targid, uint8 loc, uint8 slotid) :
    CState(PEntity, targid),
    m_PEntity(PEntity),
    m_location(loc),
    m_slot(slotid),
    m_PItem(nullptr)
{
    auto PItem = dynamic_cast<CItemUsable*>(m_PEntity->getStorage(loc)->GetItem(slotid));
    m_PItem = PItem;

    if (m_PItem && m_PItem->isType(ITEM_USABLE))
    {
        if (m_PItem->isType(ITEM_ARMOR))
        {
            // check if this item is equipped
            bool found = false;
            for (auto equipslot = 0; equipslot < 18; ++equipslot)
            {
                if (m_PEntity->getEquip((SLOTTYPE)equipslot) == m_PItem && m_PItem->getCurrentCharges() > 0)
                {
                    found = true;
                    break;
                }
            }
            if (!found)
                m_PItem = nullptr;
        }
        else if (m_PItem->isSubType(ITEM_LOCKED))
        {
            m_PItem = nullptr;
        }
    }

    if (!m_PItem)
    {
        throw CStateInitException(std::make_unique<CMessageBasicPacket>(m_PEntity, m_PEntity, 0, 0, 56));
    }

    auto PTarget = m_PEntity->IsValidTarget(targid, m_PItem->getValidTarget(), m_errorMsg);
    auto error = luautils::OnItemCheck(PTarget, m_PItem);

    if (!PTarget || m_errorMsg)
    {
        throw CStateInitException(std::move(m_errorMsg));
    }

    if (error || m_PEntity->StatusEffectContainer->HasPreventActionEffect())
    {
        auto param = m_PItem->getFlag() & ITEM_FLAG_SCROLL ? m_PItem->getSubID() : m_PItem->getID();

        throw CStateInitException(std::make_unique<CMessageBasicPacket>(m_PEntity, m_PEntity, param, 0, error == -1 ? 56 : error));
    }

    m_PEntity->UContainer->SetType(UCONTAINER_USEITEM);
    m_PEntity->UContainer->SetItem(0, m_PItem);

    UpdateTarget(m_targid);

    m_startPos = m_PEntity->loc.p;
    m_castTime = std::chrono::milliseconds(m_PItem->getActivationTime());
    m_animationTime = std::chrono::milliseconds(PItem->getAnimationTime());

    action_t action;
    action.id = m_PEntity->id;
    action.actiontype = ACTION_ITEM_START;

    actionList_t& actionList = action.getNewActionList();
    actionList.ActionTargetID = PTarget->id;

    actionTarget_t& actionTarget = actionList.getNewActionTarget();

    actionTarget.reaction = REACTION_NONE;
    actionTarget.speceffect = SPECEFFECT_NONE;
    actionTarget.animation = 0;
    actionTarget.param = m_PItem->getID();
    actionTarget.messageID = 28;
    actionTarget.knockback = 0;

    m_PEntity->PAI->EventHandler.triggerListener("ITEM_START", PTarget, m_PItem, &action);
    m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));

    m_PItem->setSubType(ITEM_LOCKED);

    m_PEntity->pushPacket(new CInventoryAssignPacket(m_PItem, INV_NOSELECT));
    m_PEntity->pushPacket(new CInventoryFinishPacket());
}
void GuardControllerSubSystem::Update(Actor& actor, double DeltaTime)
{
    Opt<GuardControllerComponent> guardCC=actor.Get<IControllerComponent>();
    if (!guardCC.IsValid()||!guardCC->IsEnabled())
    {
        return;
    }
    if (mProgramState.mMode == core::ProgramState::Client)
    {
        return;
    }
    auto targetHolderC = actor.Get<ITargetHolderComponent>();
    if (!targetHolderC.IsValid())
    {
        return;
    }
    auto healthC = actor.Get<IHealthComponent>();
    if (!healthC.IsValid() || !healthC->IsAlive())
    {
        return;
    }
    UpdateTarget( actor, targetHolderC );
    Opt<Actor> currentTarget( mScene.GetActor( targetHolderC->GetTargetGUID() ) );
    auto moveC( actor.Get<IMoveComponent>() );
    guardCC->SetNextMoveTimer( guardCC->GetNextMoveTimer() - DeltaTime );
    if (currentTarget.IsValid())
    {
        auto positionC( actor.Get<IPositionComponent>() );
        auto targetPositionC( currentTarget->Get<IPositionComponent>() );
        auto const distSqr = GetDistanceSqr( positionC, targetPositionC );
        glm::vec2 const distV( (targetPositionC->GetX() - positionC->GetX()), (targetPositionC->GetY() - positionC->GetY()) );
        double const Rot = atan2( distV.y, distV.x );
        positionC->SetOrientation( Rot );
        auto inventoryC = actor.Get<IInventoryComponent>();
        if (inventoryC.IsValid())
        {
            Opt<Weapon> weapon = inventoryC->GetSelectedWeapon();
            if (weapon.IsValid())
            {
                int32_t const aggroAltDistSqr = guardCC->GetAggroAltDist() * guardCC->GetAggroAltDist();
                if (distSqr < aggroAltDistSqr)
                {
                    weapon->SetShoot( false );
                    weapon->SetShootAlt( true );
                }
                else
                {
                    weapon->SetShoot( true );
                    weapon->SetShootAlt( false );
                }
            }
        }




        if (guardCC->GetNextMoveTimer() <= 0.0)
        {
            const int32_t ran = RandomGenerator::global()() % 3;
            if (ran == 0)
            {
                guardCC->SetMoveDirection( GuardControllerComponent::Left );
            }
            else if (ran == 1)
            {
                guardCC->SetMoveDirection( GuardControllerComponent::Right );
            }
            else
            {
                guardCC->SetMoveDirection( GuardControllerComponent::None );
            }
            guardCC->SetNextMoveTimer(guardCC->GetNextMoveTimerMax() 
                + (RandomGenerator::global()() % 100*0.02*- 1)*guardCC->GetNextMoveTimerVariance() );
        }
        int32_t const tooCloseDistSqr = guardCC->GetCloseDist() * guardCC->GetCloseDist();
        int32_t const walkAwayDistSqr = guardCC->GetWalkAwayDist() * guardCC->GetWalkAwayDist();
        double heading = 0.0;
        static const double pi = boost::math::constants::pi<double>();
        if (distSqr > tooCloseDistSqr)
        {
            heading = Rot;
            if (guardCC->GetMoveDirection() == GuardControllerComponent::Left)
            {
                heading -= pi / 4;
            }
            else if (guardCC->GetMoveDirection() == GuardControllerComponent::Right)
            {
                heading += pi / 4;
            }
            moveC->SetMoving( true );
        }
        else if (distSqr < walkAwayDistSqr)
        {
            heading = Rot-pi;
            if (guardCC->GetMoveDirection() == GuardControllerComponent::Left)
            {
                heading += pi / 4;
            }
            else if (guardCC->GetMoveDirection() == GuardControllerComponent::Right)
            {
                heading -= pi / 4;
            }
            moveC->SetMoving( true );
        }
        else
        {
            heading = Rot;
            if (guardCC->GetMoveDirection() == GuardControllerComponent::Left)
            {
                heading -= pi / 2;
                moveC->SetMoving( true );
            }
            else if (guardCC->GetMoveDirection() == GuardControllerComponent::Right)
            {
                heading += pi / 2;
                moveC->SetMoving( true );
            }
            else
            {
                moveC->SetMoving( false );
            }
        }
        moveC->SetHeading( heading );
    }
    else
    {
        moveC->SetMoving( false );
        Opt<IInventoryComponent> inventoryC = actor.Get<IInventoryComponent>();
        if (inventoryC.IsValid())
        {
            Opt<Weapon> weapon = inventoryC->GetSelectedWeapon();
            if (weapon.IsValid())
            {
                weapon->SetShoot( false );
                weapon->SetShootAlt( false );
            }
        }
    }
}