Пример #1
0
void AHAI::executeShootToClear()
{
    switch(iStateStep)
    {
    case AH_STATE_STEP_ENTER:

        pTargetPosition.y = pMyPosition.y;
        pTargetPosition.x = (pMyPosition.x > 0)? -AH_TABLE_WIDTH / 3.0f: AH_TABLE_WIDTH / 3.0f;

        iStateStep = AH_STATE_STEP_EXECUTE;

        break;

    case AH_STATE_STEP_EXECUTE:

        fSpeed = cLevel.SpeedForClearing;
        
        if(targetPositionReached())           
        {
            iStateStep = AH_STATE_STEP_EXIT;
        }
        
        break;

    case AH_STATE_STEP_EXIT:

        selectState(AH_STATE_NOTHING);

        break;

    default:
        break;
    }
}
Пример #2
0
void AHAI::executeGoToBack()
{
    switch(iStateStep)
    {
    case AH_STATE_STEP_ENTER:

        pTargetPosition.x = 0.0;
        pTargetPosition.y = fNearBackBorder;

        iStateStep = AH_STATE_STEP_EXECUTE;

        break;

    case AH_STATE_STEP_EXECUTE:

        fSpeed = cLevel.SpeedForDefending;

        if(targetPositionReached() ||
           (pPuckPosition.y < pMyPosition.y && abs(pPuckPosition.x) < (AH_TABLE_WIDTH / 6)))
        {
            iStateStep = AH_STATE_STEP_EXIT;
        }

        break;

    case AH_STATE_STEP_EXIT:

        selectState(AH_STATE_NOTHING);

        break;

    default:
        break;
    }
}
Пример #3
0
void AHAI::executeBeAlert()
{
    switch(iStateStep)
    {
    case AH_STATE_STEP_ENTER:

        iStateStep = AH_STATE_STEP_EXECUTE;

        // average point between puck and goal in my zone
        pTargetPosition.x = pPuckPosition.x / 4.0f;
        pTargetPosition.y = fMinimumGoalDistance + rand() % round(fAlertZoneHeight);
        fSpeed = cLevel.DefaultSpeed;

        break;

    case AH_STATE_STEP_EXECUTE:

        if((targetPositionReached() && (vPuckVelocity.x != 0.0 || vPuckVelocity.y != 0.0)) ||
            vPuckVelocity.y < 0.0)
        {
            iStateStep = AH_STATE_STEP_EXIT;
        }

        break;

    case AH_STATE_STEP_EXIT:

        selectState(AH_STATE_NOTHING);

        break;

    default:
        break;
    }
}
Пример #4
0
AHPoint AHAI::go()
{
    if(targetPositionReached())
        return pMyPosition;

    AHPoint pNewPosition;
    AHVector vTargetDirection;

    vTargetDirection.x = pTargetPosition.x - pMyPosition.x;
    vTargetDirection.y = pTargetPosition.y - pMyPosition.y;

    setVectorLength(&vTargetDirection, fSpeed);

    pNewPosition = pMyPosition;
    pNewPosition.x += vTargetDirection.x;
    pNewPosition.y += vTargetDirection.y;

    return pNewPosition;
}
/**
 * \brief Timer status update slot
 */
void	focusercontrollerwidget::statusUpdate() {
	if (!_focuser) {
		return;
	}
	int	current = _focuser->current();
	if (current != _previousposition) {
		double	f = current / 5000.;
		ui->positionButton->update(f);
		_previousposition = current;
	}
	int	target = ui->positionSpinBox->value();
	bool	targetreached = current == target;
	ui->positionButton->setEnabled(!targetreached);
	displayCurrent(current);
	if ((targetreached) && (delta != 0)) {
		emit targetPositionReached();
	}
	delta = current - target;
}
Пример #6
0
void AHAI::executeClearPuck()
{
    switch(iStateStep)
    {
    case AH_STATE_STEP_ENTER:

        pTargetPosition.x = (pMyPosition.x < 0)? -AH_TABLE_WIDTH / 6.0f: AH_TABLE_WIDTH / 6.0f;
        pTargetPosition.y = AH_MALLET_RADIUS;

        iStateStep = AH_STATE_STEP_EXECUTE;

        break;

    case AH_STATE_STEP_EXECUTE:

        if(targetPositionReached() || 
           pPuckPosition.y > fNearBackBorder ||
           abs(pPuckPosition.x) > (AH_TABLE_WIDTH / 6))
        {
            iStateStep = AH_STATE_STEP_EXIT;
        }

        fSpeed = cLevel.SpeedForClearing;

        break;

    case AH_STATE_STEP_EXIT:

        selectState(AH_STATE_SHOOT_TO_CLEAR);

        break;

    default:
        break;
    }
}
Пример #7
0
void AHAI::executePrepareShoot()
{
    AHPoint pPuckFuturePosition;
    CLine* cShotLine;

    float fTimeForThePuckToCome;
    float fDistanceToTarget;

    int iChoice;

    switch(iStateStep)
    {
    case AH_STATE_STEP_ENTER:

        // default: direct shot
        pShotPoint = calculateGoalPoint();
        iChoice = rand() % 2;

        // with bounce
        if(iChoice == 1)
        {
            // against the left wall
            if(pMyPosition.x >= 0.0 && pPuckPosition.x < -fHoleToShoot)
                pShotPoint.x -= AH_TABLE_WIDTH * (1 + rand() % 2);    // one or two bounces

            // against the right wall
            else if(pMyPosition.x < 0.0 && pPuckPosition.x > fHoleToShoot)
                pShotPoint.x += AH_TABLE_WIDTH * (1 + rand() % 2);
        }

        // puck's future position
        fImpulseDistance = fBackSpace;
        pPuckFuturePosition.y = pMyPosition.y + fImpulseDistance;
        pPuckFuturePosition.x = predictPositionX(pPuckFuturePosition.y);

        // shot line
        cShotLine = new CLine(pShotPoint.x, pShotPoint.y, pPuckFuturePosition.x, pPuckFuturePosition.y);
        pTargetPosition = pMyPosition;

        if(cShotLine->can_calculate_x())
            pTargetPosition.x = (float)cShotLine->x(pTargetPosition.y);

        // speed
        if(abs(vPuckVelocity.y) > fStopped)
        {
            fTimeForThePuckToCome = (pPuckFuturePosition.y - pPuckPosition.y) / vPuckVelocity.y;
            fTimeForThePuckToCome = abs(fTimeForThePuckToCome);
            fTimeForThePuckToCome -= 2.0;        // state change frames

            if(fTimeForThePuckToCome < 0.0)
            {
                fCalculatedSpeed = cLevel.SpeedForShooting;
            }
            else
            {
                fDistanceToTarget = (pTargetPosition.x - pMyPosition.x) * (pTargetPosition.x - pMyPosition.x);
                fDistanceToTarget += (pTargetPosition.y - pMyPosition.y) * (pTargetPosition.y - pMyPosition.y);
                fDistanceToTarget = sqrt(fDistanceToTarget);

                fCalculatedSpeed = fDistanceToTarget / fTimeForThePuckToCome;
                fCalculatedSpeed = min(cLevel.SpeedForShooting, fCalculatedSpeed);
            }
        }
        else
        {
            fCalculatedSpeed = cLevel.DefaultSpeed;
        }

        iStateStep = AH_STATE_STEP_EXECUTE;

        break;

    case AH_STATE_STEP_EXECUTE:

        fSpeed = fCalculatedSpeed;

        if(targetPositionReached() ||                        // ready for the shot
           pPuckPosition.y <= pMyPosition.y ||                 // the puck has escaped
           pPuckPosition.y > (AH_TABLE_HEIGHT / 2) ||        // the puck is out of my zone
           abs(vPuckVelocity.y) < fStopped)                    // the puck is stopped
        {
            iStateStep = AH_STATE_STEP_EXIT;
        }

        break;

    case AH_STATE_STEP_EXIT:

        if(pPuckPosition.y > pMyPosition.y)
            selectState(AH_STATE_SHOOT_TO_GOAL);
        else
            selectState(AH_STATE_NOTHING);

        break;

    default:
        break;
    }
}