本文整理汇总了C++中UpdateAirPhysics函数的典型用法代码示例。如果您正苦于以下问题:C++ UpdateAirPhysics函数的具体用法?C++ UpdateAirPhysics怎么用?C++ UpdateAirPhysics使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UpdateAirPhysics函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UpdateAirPhysics
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);
}
}
示例2: 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);
}
}
示例3: NOZERO
// Move the unit around a bit..
void CHoverAirMoveType::UpdateHovering()
{
#if 0
#define NOZERO(x) std::max(x, 0.0001f)
float3 deltaVec = goalPos - owner->pos;
float3 deltaDir = float3(deltaVec.x, 0.0f, deltaVec.z);
const float driftSpeed = math::fabs(owner->unitDef->dlHoverFactor);
const float goalDistance = NOZERO(deltaDir.Length2D());
const float brakeDistance = 0.5f * owner->speed.SqLength2D() / decRate;
// move towards goal position if it's not immediately
// behind us when we have more waypoints to get to
// *** this behavior interferes with the loading procedure of transports ***
const bool b0 = (aircraftState != AIRCRAFT_LANDING && owner->commandAI->HasMoreMoveCommands());
const bool b1 = (goalDistance < brakeDistance && goalDistance > 1.0f);
if (b0 && b1 && dynamic_cast<CTransportUnit*>(owner) == NULL) {
deltaDir = owner->frontdir;
} else {
deltaDir *= smoothstep(0.0f, 20.0f, goalDistance) / goalDistance;
deltaDir -= owner->speed;
}
if (deltaDir.SqLength2D() > (maxSpeed * maxSpeed)) {
deltaDir *= (maxSpeed / NOZERO(math::sqrt(deltaDir.SqLength2D())));
}
// random movement (a sort of fake wind effect)
// random drift values are in range -0.5 ... 0.5
randomWind.x = randomWind.x * 0.9f + (gs->randFloat() - 0.5f) * 0.5f;
randomWind.z = randomWind.z * 0.9f + (gs->randFloat() - 0.5f) * 0.5f;
wantedSpeed = owner->speed + deltaDir;
wantedSpeed += (randomWind * driftSpeed * 0.5f);
UpdateAirPhysics();
#endif
#if 1
randomWind.x = randomWind.x * 0.9f + (gs->randFloat() - 0.5f) * 0.5f;
randomWind.z = randomWind.z * 0.9f + (gs->randFloat() - 0.5f) * 0.5f;
// randomly drift (but not too far from goal-position)
wantedSpeed = (randomWind * math::fabs(owner->unitDef->dlHoverFactor) * 0.5f);
wantedSpeed += (smoothstep(0.0f, 20.0f * 20.0f, (goalPos - owner->pos)) * (goalPos - owner->pos));
UpdateAirPhysics();
#endif
}
示例4: switch
void CAirMoveType::UpdateManeuver(void)
{
#ifdef DEBUG_AIRCRAFT
if(selectedUnits.selectedUnits.find(this)!=selectedUnits.selectedUnits.end()){
info->AddLine("UpdataMan %i %i",maneuver,maneuverSubState);
}
#endif
float speedf=owner->speed.Length();
switch(maneuver){
case 1:{
int aileron=0,elevator=0;
if(owner->updir.y>0){
if(owner->rightdir.y>maxAileron*speedf){
aileron=1;
}else if(owner->rightdir.y<-maxAileron*speedf){
aileron=-1;
}
}
if(fabs(owner->rightdir.y)<maxAileron*3*speedf || owner->updir.y<0)
elevator=1;
UpdateAirPhysics(0,aileron,elevator,1,owner->frontdir);
if((owner->updir.y<0 && owner->frontdir.y<0) || speedf<0.8)
maneuver=0;
break;}
case 2:{
int aileron=0,elevator=0;
if(maneuverSubState==0){
if(owner->rightdir.y>=0){
aileron=-1;
}else{
aileron=1;
}
}
if(owner->frontdir.y<-0.7)
maneuverSubState=1;
if(maneuverSubState==1 || owner->updir.y<0)
elevator=1;
UpdateAirPhysics(0,aileron,elevator,1,owner->frontdir);
if((owner->updir.y>0 && owner->frontdir.y>0 && maneuverSubState==1) || speedf<0.2)
maneuver=0;
break;}
default:
UpdateAirPhysics(0,0,0,1,owner->frontdir);
maneuver=0;
break;
}
}
示例5: NOZERO
// Move the unit around a bit..
void CTAAirMoveType::UpdateHovering()
{
#define NOZERO(x) std::max(x, 0.0001f)
const float driftSpeed = fabs(owner->unitDef->dlHoverFactor);
float3 deltaVec = goalPos - owner->pos;
float3 deltaDir = float3(deltaVec.x, 0, deltaVec.z);
float l = NOZERO(deltaDir.Length2D());
deltaDir *= smoothstep(0.0f, 20.0f, l) / l;
// move towards goal position if it's not immediately
// behind us when we have more waypoints to get to
// *** this behavior interferes with the loading procedure of transports ***
if (aircraftState != AIRCRAFT_LANDING && owner->commandAI->HasMoreMoveCommands() &&
(l < 120) && (deltaDir.SqDistance(deltaVec) > 1.0f) && dynamic_cast<CTransportUnit*>(owner) == NULL) {
deltaDir = owner->frontdir;
}
deltaDir -= owner->speed;
l = deltaDir.SqLength2D();
if (l > (maxSpeed * maxSpeed)) {
deltaDir *= maxSpeed / NOZERO(sqrt(l));
}
wantedSpeed = owner->speed + deltaDir;
// random movement (a sort of fake wind effect)
// random drift values are in range -0.5 ... 0.5
randomWind = float3(randomWind.x * 0.9f + (gs->randFloat() - 0.5f) * 0.5f, 0,
randomWind.z * 0.9f + (gs->randFloat() - 0.5f) * 0.5f);
wantedSpeed += randomWind * driftSpeed * 0.5f;
UpdateAirPhysics();
}
示例6: UpdateLandingHeight
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();
}
示例7: float3
// Move the unit around a bit.. and when it gets too far away from goal position it switches to normal flying instead
void CTAAirMoveType::UpdateHovering()
{
float driftSpeed = owner->unitDef->dlHoverFactor;
// move towards goal position
float3 dir = goalPos - owner->pos;
wantedSpeed += float3(dir.x, 0.0f, dir.z) * driftSpeed * 0.03f;
// damping
wantedSpeed *= 0.97f;
// random movement (a sort of fake wind effect)
wantedSpeed += float3(gs->randFloat()-.5f, 0.0f, gs->randFloat()-0.5f) * driftSpeed * 0.5f;
UpdateAirPhysics();
}
示例8: UpdateAirPhysics
void CHoverAirMoveType::UpdateTakeoff()
{
const float3& pos = owner->pos;
wantedSpeed = ZeroVector;
wantedHeight = orgWantedHeight;
UpdateAirPhysics();
const float altitude = owner->unitDef->canSubmerge?
(pos.y - CGround::GetHeightReal(pos.x, pos.z)):
(pos.y - CGround::GetHeightAboveWater(pos.x, pos.z));
if (altitude > orgWantedHeight * 0.8f) {
SetState(AIRCRAFT_FLYING);
}
}
示例9: UpdateAirPhysics
void CTAAirMoveType::UpdateTakeoff()
{
float3 &pos = owner->pos;
wantedSpeed = ZeroVector;
wantedHeight = orgWantedHeight;
UpdateAirPhysics();
float h = 0.0f;
if (owner->unitDef->canSubmerge) {
h = pos.y - ground->GetApproximateHeight(pos.x, pos.z);
} else {
h = pos.y - ground->GetHeightAboveWater(pos.x, pos.z);
}
if (h > orgWantedHeight * 0.8f) {
SetState(AIRCRAFT_FLYING);
}
}
示例10: UpdateAirPhysics
void CHoverAirMoveType::UpdateTakeoff()
{
float3& pos = owner->pos;
wantedSpeed = ZeroVector;
wantedHeight = orgWantedHeight;
UpdateAirPhysics();
float altitude = 0.0f;
if (owner->unitDef->canSubmerge) {
altitude = pos.y - ground->GetHeightReal(pos.x, pos.z);
} else {
altitude = pos.y - ground->GetHeightAboveWater(pos.x, pos.z);
}
if (altitude > orgWantedHeight * 0.8f) {
SetState(AIRCRAFT_FLYING);
}
}
示例11: float3
// Move the unit around a bit.. and when it gets too far away from goal position
// it switches to normal flying instead
void CTAAirMoveType::UpdateHovering()
{
float driftSpeed = owner->unitDef->dlHoverFactor;
float3 dir = goalPos - owner->pos;
// move towards goal position if it's not immediately behind us when we have
// more waypoints to get to
if (aircraftState != AIRCRAFT_LANDING && (owner->commandAI->HasMoreMoveCommands() &&
dir.Length2D() < 120) && (goalPos - owner->pos).Normalize().distance(dir) > 1) {
dir = owner->frontdir;
}
wantedSpeed += float3(dir.x, 0.0f, dir.z) * driftSpeed * 0.03f;
// damping
wantedSpeed *= 0.97f;
// random movement (a sort of fake wind effect)
wantedSpeed += float3(gs->randFloat() - 0.5f, 0.0f, gs->randFloat() - 0.5f) * driftSpeed * 0.5f;
UpdateAirPhysics();
}
示例12: SetState
void CAirMoveType::Update(void)
{
float3 &pos=owner->pos;
//This is only set to false after the plane has finished constructing
if (useHeading){
useHeading = false;
SetState(AIRCRAFT_TAKEOFF);
}
if(owner->stunned){
UpdateAirPhysics(0,lastAileronPos,lastElevatorPos,0,ZeroVector);
goto EndNormalControl;
}
#ifdef DIRECT_CONTROL_ALLOWED
if(owner->directControl && !(aircraftState==AIRCRAFT_CRASHING)){
SetState(AIRCRAFT_FLYING);
DirectControlStruct* dc=owner->directControl;
inefficientAttackTime=0;
if(dc->forward || dc->back || dc->left || dc->right){
float aileron=0;
float elevator=0;
if(dc->forward)
elevator-=1;
if(dc->back)
elevator+=1;
if(dc->right)
aileron+=1;
if(dc->left)
aileron-=1;
UpdateAirPhysics(0,aileron,elevator,1,owner->frontdir);
maneuver=0;
goto EndNormalControl; //ok so goto is bad i know
}
}
#endif
if(reservedPad){
CUnit* unit=reservedPad->unit;
float3 relPos=unit->localmodel->GetPiecePos(reservedPad->piece);
float3 pos=unit->pos + unit->frontdir*relPos.z + unit->updir*relPos.y + unit->rightdir*relPos.x;
if(padStatus==0){
if(aircraftState!=AIRCRAFT_FLYING && aircraftState!=AIRCRAFT_TAKEOFF)
SetState(AIRCRAFT_FLYING);
goalPos=pos;
if(pos.distance(owner->pos)<400){
padStatus=1;
}
// geometricObjects->AddLine(owner->pos,pos,1,0,1);
} else if(padStatus==1){
if(aircraftState!=AIRCRAFT_LANDING)
SetState(AIRCRAFT_LANDING);
goalPos=pos;
reservedLandingPos=pos;
if(owner->pos.distance(pos)<3 || aircraftState==AIRCRAFT_LANDED){
padStatus=2;
}
// geometricObjects->AddLine(owner->pos,pos,10,0,1);
} else {
if(aircraftState!=AIRCRAFT_LANDED)
SetState(AIRCRAFT_LANDED);
owner->pos=pos;
owner->AddBuildPower(20,unit);
if(owner->health>=owner->maxHealth-1){
airBaseHandler->LeaveLandingPad(reservedPad);
reservedPad=0;
padStatus=0;
goalPos=oldGoalPos;
SetState(AIRCRAFT_TAKEOFF);
}
}
}
switch(aircraftState){
case AIRCRAFT_FLYING:
#ifdef DEBUG_AIRCRAFT
if(selectedUnits.selectedUnits.find(this)!=selectedUnits.selectedUnits.end()){
info->AddLine("Flying %i %i %.1f %i",moveState,fireState,inefficientAttackTime,(int)isFighter);
}
#endif
owner->restTime=0;
if(owner->userTarget || owner->userAttackGround){
inefficientAttackTime=min(inefficientAttackTime,(float)gs->frameNum-owner->lastFireWeapon);
if(owner->userTarget){
goalPos=owner->userTarget->pos;
} else {
goalPos=owner->userAttackPos;
}
if(maneuver){
UpdateManeuver();
inefficientAttackTime=0;
//.........这里部分代码省略.........
示例13: UseSmoothMesh
//.........这里部分代码省略.........
case FLY_CIRCLING: {
if ((++waitCounter) > ((GAME_SPEED * 3) + 10)) {
if (airStrafe) {
float3 relPos = pos - circlingPos;
if (relPos.x < 0.0001f && relPos.x > -0.0001f) {
relPos.x = 0.0001f;
}
static CMatrix44f rot(0.0f, fastmath::PI / 4.0f, 0.0f);
// make sure the point is on the circle, go there in a straight line
goalPos = circlingPos + (rot.Mul(relPos.Normalize2D()) * goalDistance);
}
waitCounter = 0;
}
} break;
case FLY_ATTACKING: {
if (airStrafe) {
float3 relPos = pos - circlingPos;
if (relPos.x < 0.0001f && relPos.x > -0.0001f) {
relPos.x = 0.0001f;
}
CMatrix44f rot;
if (gs->randFloat() > 0.5f) {
rot.RotateY(0.6f + gs->randFloat() * 0.6f);
} else {
rot.RotateY(-(0.6f + gs->randFloat() * 0.6f));
}
// Go there in a straight line
goalPos = circlingPos + (rot.Mul(relPos.Normalize2D()) * goalDistance);
}
} break;
case FLY_LANDING: {
} break;
}
}
// not "close" to goal yet, so keep going
// use 2D math since goal is on the ground
// but we are not
goalVec.y = 0.0f;
// if we are close to our goal, we should
// adjust speed st. we never overshoot it
// (by respecting current brake-distance)
const float curSpeed = owner->speed.Length2D();
const float brakeDist = (0.5f * curSpeed * curSpeed) / decRate;
const float goalDist = goalVec.Length() + 0.1f;
const float goalSpeed =
(maxSpeed ) * (goalDist > brakeDist) +
(curSpeed - decRate) * (goalDist <= brakeDist);
if (goalDist > goalSpeed) {
// update our velocity and heading so long as goal is still
// further away than the distance we can cover in one frame
// we must use a variable-size "dead zone" to avoid freezing
// in mid-air or oscillation behavior at very close distances
// NOTE:
// wantedSpeed is a vector, so even aircraft with turnRate=0
// are coincidentally able to reach any goal by side-strafing
wantedHeading = GetHeadingFromVector(goalVec.x, goalVec.z);
wantedSpeed = (goalVec / goalDist) * goalSpeed;
} else {
// switch to hovering (if !CanLand()))
if (flyState != FLY_ATTACKING) {
ExecuteStop();
}
}
// redundant, done in Update()
// UpdateHeading();
UpdateAirPhysics();
// Point toward goal or forward - unless we just passed it to get to another goal
if ((flyState == FLY_ATTACKING) || (flyState == FLY_CIRCLING)) {
goalVec = circlingPos - pos;
} else {
const bool b0 = (flyState != FLY_LANDING && (owner->commandAI->HasMoreMoveCommands()));
const bool b1 = (goalDist < brakeDist && goalDist > 1.0f);
if (b0 && b1) {
goalVec = owner->frontdir;
} else {
goalVec = goalPos - pos;
}
}
if (goalVec.SqLength2D() > 1.0f) {
// update heading again in case goalVec changed
wantedHeading = GetHeadingFromVector(goalVec.x, goalVec.z);
}
}
示例14: SetState
void CTAAirMoveType::Update()
{
//Handy stuff. Wonder if there is a better way?
float3 &pos=owner->pos;
SyncedFloat3 &rightdir = owner->rightdir;
SyncedFloat3 &frontdir = owner->frontdir;
SyncedFloat3 &updir = owner->updir;
float3 &speed = owner->speed;
//This is only set to false after the plane has finished constructing
if (useHeading){
useHeading = false;
SetState(AIRCRAFT_TAKEOFF);
}
//Allow us to stop if wanted
if (wantToStop)
ExecuteStop();
float3 lastSpeed = speed;
if(owner->stunned){
wantedSpeed=ZeroVector;
UpdateAirPhysics();
} else {
#ifdef DIRECT_CONTROL_ALLOWED
if(owner->directControl){
DirectControlStruct* dc=owner->directControl;
SetState(AIRCRAFT_FLYING);
float3 forward=dc->viewDir;
float3 flatForward=forward;
flatForward.y=0;
flatForward.Normalize();
float3 right=forward.cross(UpVector);
wantedSpeed=ZeroVector;
if(dc->forward)
wantedSpeed+=flatForward;
if(dc->back)
wantedSpeed-=flatForward;
if(dc->right)
wantedSpeed+=right;
if(dc->left)
wantedSpeed-=right;
wantedSpeed.Normalize();
wantedSpeed*=maxSpeed;
UpdateAirPhysics();
wantedHeading=GetHeadingFromVector(flatForward.x,flatForward.z);
} else
#endif
{
if(reservedPad){
CUnit* unit=reservedPad->unit;
float3 relPos=unit->localmodel->GetPiecePos(reservedPad->piece);
float3 pos=unit->pos + unit->frontdir*relPos.z + unit->updir*relPos.y + unit->rightdir*relPos.x;
if(padStatus==0){
if(aircraftState!=AIRCRAFT_FLYING && aircraftState!=AIRCRAFT_TAKEOFF)
SetState(AIRCRAFT_FLYING);
goalPos=pos;
if(pos.distance(owner->pos)<400){
padStatus=1;
}
//geometricObjects->AddLine(owner->pos,pos,1,0,1);
} else if(padStatus==1){
if(aircraftState!=AIRCRAFT_FLYING)
SetState(AIRCRAFT_FLYING);
flyState=FLY_LANDING;
goalPos=pos;
reservedLandingPos=pos;
wantedHeight=pos.y-ground->GetHeight(pos.x,pos.z);
if(owner->pos.distance(pos)<3 || aircraftState==AIRCRAFT_LANDED){
padStatus=2;
}
//geometricObjects->AddLine(owner->pos,pos,10,0,1);
} else {
if(aircraftState!=AIRCRAFT_LANDED)
SetState(AIRCRAFT_LANDED);
owner->pos=pos;
owner->AddBuildPower(unit->unitDef->buildSpeed/30,unit);
owner->currentFuel = min (owner->unitDef->maxFuel, owner->currentFuel + (owner->unitDef->maxFuel / (GAME_SPEED * owner->unitDef->refuelTime)));
if(owner->health>=owner->maxHealth-1 && owner->currentFuel >= owner->unitDef->maxFuel){
airBaseHandler->LeaveLandingPad(reservedPad);
reservedPad=0;
padStatus=0;
goalPos=oldGoalPos;
SetState(AIRCRAFT_TAKEOFF);
}
}
}
//.........这里部分代码省略.........
示例15: SetState
void CAirMoveType::Update(void)
{
float3& pos = owner->pos;
// note: this is only set to false after
// the plane has finished constructing
if (useHeading) {
useHeading = false;
SetState(AIRCRAFT_TAKEOFF);
}
if (owner->stunned) {
UpdateAirPhysics(0, lastAileronPos, lastElevatorPos, 0, ZeroVector);
goto EndNormalControl;
}
if (owner->directControl && !(aircraftState == AIRCRAFT_CRASHING)) {
SetState(AIRCRAFT_FLYING);
DirectControlStruct* dc = owner->directControl;
inefficientAttackTime = 0;
if (dc->forward || dc->back || dc->left || dc->right) {
float aileron = 0;
float elevator = 0;
if (dc->forward)
elevator -= 1;
if (dc->back)
elevator += 1;
if (dc->right)
aileron += 1;
if (dc->left)
aileron -= 1;
UpdateAirPhysics(0, aileron, elevator, 1, owner->frontdir);
maneuver = 0;
goto EndNormalControl; // bad
}
}
if (reservedPad) {
CUnit* unit = reservedPad->GetUnit();
float3 relPos = unit->script->GetPiecePos(reservedPad->GetPiece());
float3 pos = unit->pos + (unit->frontdir * relPos.z) + (unit->updir * relPos.y) + (unit->rightdir * relPos.x);
if (padStatus == 0) {
if (aircraftState != AIRCRAFT_FLYING && aircraftState != AIRCRAFT_TAKEOFF) {
SetState(AIRCRAFT_FLYING);
}
goalPos = pos;
if (pos.SqDistance2D(owner->pos) < (400*400)) {
padStatus = 1;
}
} else if (padStatus == 1) {
if (aircraftState != AIRCRAFT_LANDING) {
SetState(AIRCRAFT_LANDING);
}
goalPos = pos;
reservedLandingPos = pos;
if (owner->pos.SqDistance(pos) < 9 || aircraftState == AIRCRAFT_LANDED) {
padStatus = 2;
}
} else {
if (aircraftState != AIRCRAFT_LANDED) {
SetState(AIRCRAFT_LANDED);
}
owner->pos = pos;
owner->AddBuildPower(unit->unitDef->buildSpeed / GAME_SPEED, unit);
owner->currentFuel = std::min(owner->unitDef->maxFuel, owner->currentFuel + (owner->unitDef->maxFuel / (GAME_SPEED * owner->unitDef->refuelTime)));
if (owner->health >= owner->maxHealth - 1 && owner->currentFuel >= owner->unitDef->maxFuel) {
// repaired and filled up, leave the pad
airBaseHandler->LeaveLandingPad(reservedPad);
reservedPad = 0;
padStatus = 0;
goalPos = oldGoalPos;
SetState(AIRCRAFT_TAKEOFF);
}
}
} else if ((owner->unitDef->maxFuel > 0.0f && owner->currentFuel <= 0.0f) &&
padStatus == 0 && maxWantedSpeed > 0.0f) {
// keep us in the air to reach our landing goalPos
// (which is hopefully in the vicinity of a pad)
SetState(AIRCRAFT_FLYING);
}
switch (aircraftState) {
case AIRCRAFT_FLYING: {
#ifdef DEBUG_AIRCRAFT
GML_RECMUTEX_LOCK(sel); // Update
//.........这里部分代码省略.........