void CHoverAirMoveType::UpdateLanding()
{
	const float3& pos = owner->pos;
	const float3& speed = owner->speed;

	// We want to land, and therefore cancel our speed first
	wantedSpeed = ZeroVector;

	// Hang around for a while so queued commands have a chance to take effect
	if ((++waitCounter) < GAME_SPEED) {
		UpdateAirPhysics();
		return;
	}

	if (reservedLandingPos.x < 0) {
		if (CanLandAt(pos)) {
			// found a landing spot
			reservedLandingPos = pos;
			goalPos = pos;
			owner->physicalState = CSolidObject::OnGround;
			owner->Block();
			owner->physicalState = CSolidObject::Flying;
			owner->Deactivate();
			owner->script->StopMoving();
		} else {
			if (goalPos.SqDistance2D(pos) < 900) {
				goalPos = goalPos + gs->randVector() * 300;
				goalPos.ClampInBounds();
				progressState = AMoveType::Failed; // exact landing pos failed, make sure finishcommand is called anyway
			}
			flyState = FLY_LANDING;
			UpdateFlying();
			return;
		}
	}
	// We should wait until we actually have stopped smoothly
	if (speed.SqLength2D() > 1.0f) {
		UpdateFlying();
		return;
	}

	// We have stopped, time to land
	// NOTE: wantedHeight is interpreted as RELATIVE altitude
	const float gh = ground->GetHeightAboveWater(pos.x, pos.z);
	const float gah = ground->GetHeightReal(pos.x, pos.z);
	float altitude = (wantedHeight = 0.0f);

	// can we submerge and are we still above water?
	if ((owner->unitDef->canSubmerge) && (gah < 0.0f)) {
		altitude = pos.y - gah;
	} else {
		altitude = pos.y - gh;
	}

	UpdateAirPhysics();

	if (altitude <= 1.0f) {
		SetState(AIRCRAFT_LANDED);
	}
}
void CHoverAirMoveType::UpdateLanding()
{
	const float3& pos = owner->pos;

	if (!HaveLandingPos()) {
		if (CanLandAt(pos)) {
			// found a landing spot
			reservedLandingPos = pos;
			goalPos = pos;
			wantedHeight = 0;
			UpdateLandingHeight();

			const float3 originalPos = pos;

			owner->Move(reservedLandingPos, false);
			owner->Block();
			owner->Move(originalPos, false);
			owner->script->StopMoving();
		} else {
			if (goalPos.SqDistance2D(pos) < (30.0f * 30.0f)) {
				// randomly pick another landing spot and try again
				goalPos += (gs->randVector() * 300.0f);
				goalPos.ClampInBounds();

				// exact landing pos failed, make sure finishcommand is called anyway
				progressState = AMoveType::Failed;
			}

			flyState = FLY_LANDING;
			UpdateFlying();
			return;
		}
	}



	flyState = FLY_LANDING;

	const float altitude = pos.y - reservedLandingPos.y;
	const float distSq2D = reservedLandingPos.SqDistance2D(pos);

	if (distSq2D > landRadiusSq) {
		const float tmpWantedHeight = wantedHeight;
		SetGoal(reservedLandingPos);

		wantedHeight = std::min((orgWantedHeight - wantedHeight) * distSq2D / altitude + wantedHeight, orgWantedHeight);
		UpdateFlying();
		wantedHeight = tmpWantedHeight;
		return;
	}

	// We want to land, and therefore cancel our speed first
	wantedSpeed = ZeroVector;

	AAirMoveType::UpdateLanding();

	UpdateAirPhysics();
}
void CTAAirMoveType::UpdateLanding()
{
	float3 &pos = owner->pos;
	float3 &speed = owner->speed;

	//We want to land, and therefore cancel our speed first
	wantedSpeed = ZeroVector;

	waitCounter++;

	//Hang around for a while so queued commands have a chance to take effect
	if (waitCounter < 30) {
		//logOutput.Print("want to land, but.. %d", waitCounter);
		UpdateAirPhysics();
		return;
	}

	if(reservedLandingPos.x<0){
//		logOutput.Print("Searching for landing spot");
		if(CanLandAt(pos)){
//			logOutput.Print("Found landing spot");
			reservedLandingPos=pos;
			goalPos=pos;
			owner->physicalState = CSolidObject::OnGround;
			owner->Block();
			owner->physicalState = CSolidObject::Flying;
			owner->Deactivate();
			owner->cob->Call(COBFN_StopMoving);
		} else {
			if(goalPos.distance2D(pos)<30){
				goalPos=goalPos+gs->randVector()*300;
				goalPos.CheckInBounds();
			}
			flyState = FLY_LANDING;
			UpdateFlying();
			return;
		}
	}
	//We should wait until we actually have stopped smoothly
	if (speed.SqLength2D() > 1) {
		UpdateFlying();
		return;
	}

	//We have stopped, time to land
	wantedHeight=-2;
	UpdateAirPhysics();
	float h = pos.y - ground->GetHeight(pos.x, pos.z);

	if (h <= 0) {
		//logOutput.Print("Landed");
		SetState(AIRCRAFT_LANDED);
		pos.y = ground->GetHeight(pos.x, pos.z);
	}
}
Exemple #4
0
void CTAAirMoveType::UpdateLanding()
{
    float3& pos = owner->pos;
    float3& speed = owner->speed;

    // We want to land, and therefore cancel our speed first
    wantedSpeed = ZeroVector;

    waitCounter++;

    // Hang around for a while so queued commands have a chance to take effect
    if (waitCounter < 30) {
        UpdateAirPhysics();
        return;
    }

    if (reservedLandingPos.x < 0) {
        if (CanLandAt(pos)) {
            // found a landing spot
            reservedLandingPos = pos;
            goalPos = pos;
            owner->physicalState = CSolidObject::OnGround;
            owner->Block();
            owner->physicalState = CSolidObject::Flying;
            owner->Deactivate();
            owner->script->StopMoving();
        } else {
            if (goalPos.SqDistance2D(pos) < 900) {
                goalPos = goalPos + gs->randVector() * 300;
                goalPos.CheckInBounds();
            }
            flyState = FLY_LANDING;
            UpdateFlying();
            return;
        }
    }
    // We should wait until we actually have stopped smoothly
    if (speed.SqLength2D() > 1.0f) {
        UpdateFlying();
        return;
    }

    // We have stopped, time to land
    const float gah = ground->GetApproximateHeight(pos.x, pos.z);
    float h = 0.0f;

    // if aircraft submergible and above water we want height of ocean floor
    if ((owner->unitDef->canSubmerge) && (gah < 0.0f)) {
        h = pos.y - gah;
        wantedHeight = gah;
    } else {
        h = pos.y - ground->GetHeightAboveWater(pos.x, pos.z);
        wantedHeight = -2.0;
    }

    UpdateAirPhysics();

    if (h <= 0) {
        SetState(AIRCRAFT_LANDED);

        pos.y = gah;
    }
}
Exemple #5
0
void CHoverAirMoveType::UpdateLanding()
{
	const float3& pos = owner->pos;
	const float4& spd = owner->speed;

	// We want to land, and therefore cancel our speed first
	wantedSpeed = ZeroVector;

	// Hang around for a while so queued commands have a chance to take effect
	if ((++waitCounter) < GAME_SPEED) {
		UpdateAirPhysics();
		return;
	}

	if (reservedLandingPos.x < 0.0f) {
		if (CanLandAt(pos)) {
			// found a landing spot
			reservedLandingPos = pos;
			goalPos = pos;

			owner->Block();
			owner->Deactivate();
			owner->script->StopMoving();
		} else {
			if (goalPos.SqDistance2D(pos) < (30.0f * 30.0f)) {
				// randomly pick another landing spot and try again
				goalPos += (gs->randVector() * 300.0f);
				goalPos.ClampInBounds();

				// exact landing pos failed, make sure finishcommand is called anyway
				progressState = AMoveType::Failed;
			}

			flyState = FLY_LANDING;
			UpdateFlying();
			return;
		}
	}

	// We should wait until we actually have stopped smoothly
	if (spd.SqLength2D() > 1.0f) {
		UpdateFlying();
		UpdateAirPhysics();
		return;
	}

	// We have stopped, time to land
	// NOTE: wantedHeight is interpreted as RELATIVE altitude
	const float gh = CGround::GetHeightAboveWater(pos.x, pos.z);
	const float gah = CGround::GetHeightReal(pos.x, pos.z);
	float altitude = (wantedHeight = 0.0f);

	// can we submerge and are we still above water?
	if ((owner->unitDef->canSubmerge) && (gah < 0.0f)) {
		altitude = pos.y - gah;
	} else {
		altitude = pos.y - gh;
	}

	UpdateAirPhysics();

	// collision detection does not let us get
	// closer to the ground than <radius> elmos
	// (wrt. midPos.y)
	if (altitude <= owner->radius) {
		SetState(AIRCRAFT_LANDED);
	}
}