这篇教程C++ GetHeadingFromVector函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中GetHeadingFromVector函数的典型用法代码示例。如果您正苦于以下问题:C++ GetHeadingFromVector函数的具体用法?C++ GetHeadingFromVector怎么用?C++ GetHeadingFromVector使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了GetHeadingFromVector函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: tempTargetPosbool CWeapon::TryTargetRotate(CUnit* unit, bool userTarget){ float3 tempTargetPos(helper->GetUnitErrorPos(unit,owner->allyteam)); tempTargetPos+=errorVector*(weaponDef->targetMoveError*30*unit->speed.Length()*(1.0f-owner->limExperience)); float appHeight=ground->GetApproximateHeight(tempTargetPos.x,tempTargetPos.z)+2; if(tempTargetPos.y < appHeight){ tempTargetPos.y=appHeight; } short weaponHeadding = GetHeadingFromVector(mainDir.x, mainDir.z); short enemyHeadding = GetHeadingFromVector( tempTargetPos.x - weaponPos.x, tempTargetPos.z - weaponPos.z); return TryTargetHeading(enemyHeadding - weaponHeadding, tempTargetPos,userTarget, unit);}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:12,
示例2: GetHeadingFromVectorvoid CFarTextureHandler::DrawFarTexture(const CSolidObject* obj, CVertexArray* va){ const int farTextureNum = cache[obj->team][obj->model->id]; // not found in the atlas if (farTextureNum <= 0) return; const float3 interPos = obj->drawPos + UpVector * obj->model->height * 0.5f; // indicates the orientation to draw static const int USHRT_MAX_ = (1 << 16); const int orient_step = USHRT_MAX_ / numOrientations; int orient = GetHeadingFromVector(-camera->forward.x, -camera->forward.z) - obj->heading; orient += USHRT_MAX_; // make it positive only orient += (orient_step >> 1); // we want that frontdir is from -orient_step/2 upto orient_step/2 orient %= USHRT_MAX_; // we have an angle so it's periodical orient /= orient_step; // get the final direction index const float iconSizeX = float(this->iconSizeX) / texSizeX; const float iconSizeY = float(this->iconSizeY) / texSizeY; const float2 texcoords = GetTextureCoords(farTextureNum - 1, orient); const float3 curad = camera->up * obj->model->radius; const float3 crrad = camera->right * obj->model->radius; va->AddVertexQT(interPos - curad + crrad, texcoords.x, texcoords.y ); va->AddVertexQT(interPos + curad + crrad, texcoords.x, texcoords.y + iconSizeY); va->AddVertexQT(interPos + curad - crrad, texcoords.x + iconSizeX, texcoords.y + iconSizeY); va->AddVertexQT(interPos - curad - crrad, texcoords.x + iconSizeX, texcoords.y );}
开发者ID:AlexDiede,项目名称:spring,代码行数:32,
示例3: glDisablevoid HUDDrawer::DrawCameraDirectionArrow(const CUnit* unit){ glDisable(GL_TEXTURE_2D); if (unit->moveType->useHeading) { glPushMatrix(); glTranslatef(-0.8f, -0.4f, 0.0f); glScalef(0.33f, 0.33f * globalRendering->aspectRatio, 0.33f); glRotatef( GetHeadingFromVector(camera->forward.x, camera->forward.z) * 180.0f / 32768 + 180, 0.0f, 0.0f, 1.0f ); glScalef(0.4f, 0.4f, 0.3f); glColor4f(0.4f, 0.4f, 1.0f, 0.6f); glBegin(GL_TRIANGLE_FAN); glVertex2f(-0.2f, -0.3f); glVertex2f(-0.2f, 0.3f); glVertex2f( 0.0f, 0.5f); glVertex2f( 0.2f, 0.3f); glVertex2f( 0.2f, -0.3f); glVertex2f(-0.2f, -0.3f); glEnd(); glPopMatrix(); }}
开发者ID:Mocahteam,项目名称:SpringPP,代码行数:27,
示例4: DeleteDeathDependencevoid CUnit::FinishedBuilding(void){ beingBuilt = false; buildProgress = 1.0f; if (soloBuilder) { DeleteDeathDependence(soloBuilder); soloBuilder = NULL; } if (!(immobile && (mass == 100000))) { mass = unitDef->mass; //set this now so that the unit is harder to move during build } ChangeLos(realLosRadius,realAirLosRadius); if (unitDef->startCloaked) { wantCloak = true; isCloaked = true; } if (unitDef->windGenerator>0) { if (wind.curStrength > unitDef->windGenerator) { cob->Call(COBFN_SetSpeed, (int)(unitDef->windGenerator * 3000.0f)); } else { cob->Call(COBFN_SetSpeed, (int)(wind.curStrength * 3000.0f)); } cob->Call(COBFN_SetDirection, (int)GetHeadingFromVector(-wind.curDir.x, -wind.curDir.z)); } if (unitDef->activateWhenBuilt) { Activate(); } gs->Team(team)->metalStorage += unitDef->metalStorage; gs->Team(team)->energyStorage += unitDef->energyStorage; //Sets the frontdir in sync with heading. frontdir = GetVectorFromHeading(heading) + float3(0,frontdir.y,0); if (unitDef->isAirBase) { airBaseHandler->RegisterAirBase(this); } luaCallIns.UnitFinished(this); globalAI->UnitFinished(this); if (unitDef->isFeature) { UnBlock(); CFeature* f = featureHandler->CreateWreckage(pos, wreckName, heading, buildFacing, 0, team, false, ""); if (f) { f->blockHeightChanges = true; } KillUnit(false, true, 0); }}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:58,
示例5: PushWindvoid CUnit::PushWind(float x, float z, float strength){ if(strength > unitDef->windGenerator) { cob->Call(COBFN_SetSpeed, (int)(unitDef->windGenerator*3000.0f)); } else { cob->Call(COBFN_SetSpeed, (int)(strength*3000.0f)); } cob->Call(COBFN_SetDirection, (int)GetHeadingFromVector(-x, -z));}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:13,
示例6: GetVectorFromHeadingvoid CFeature::ForcedSpin(const float3& newDir){ float3 updir = UpVector; if (updir == newDir) { //FIXME perhaps save the old right,up,front directions, so we can // reconstruct the old upvector and generate a better assumption for updir updir -= GetVectorFromHeading(heading); } float3 rightdir = newDir.cross(updir).Normalize(); updir = rightdir.cross(newDir); transMatrix = CMatrix44f(pos, -rightdir, updir, newDir); heading = GetHeadingFromVector(newDir.x, newDir.z);}
开发者ID:Arkazon,项目名称:spring,代码行数:13,
示例7: assertvoid CAirMoveType::SetState(AAirMoveType::AircraftState state){ // this state is only used by CTAAirMoveType assert(state != AIRCRAFT_HOVERING); if (aircraftState == AIRCRAFT_CRASHING || state == aircraftState) return; /* if (state == AIRCRAFT_LANDING) owner->cob->Call(COBFN_Deactivate); else if (state == aircraft_flying) // cob->Call(COBFN_Activate); */ if (state == AIRCRAFT_FLYING) { owner->Activate(); owner->script->StartMoving(); } if (state == AIRCRAFT_LANDED) { owner->heading = GetHeadingFromVector(owner->frontdir.x, owner->frontdir.z); owner->physicalState = CSolidObject::OnGround; owner->useAirLos = false; } else { owner->physicalState = CSolidObject::Flying; owner->useAirLos = true; if (state != AIRCRAFT_LANDING) { reservedLandingPos.x = -1; owner->UnBlock(); } } if (aircraftState == AIRCRAFT_LANDED && reservedLandingPos.x > 0) { reservedLandingPos.x = -1; } subState = 0; // make sure we only go into takeoff if actually landed if (state != AIRCRAFT_TAKEOFF || aircraftState == AIRCRAFT_LANDED) { aircraftState = state; } else { aircraftState = AIRCRAFT_TAKEOFF; }}
开发者ID:Dmytry,项目名称:spring,代码行数:45,
示例8: GetHeadingFromVectorvoid CFeature::ForcedSpin(const float3& newDir){/* heading = GetHeadingFromVector(newDir.x, newDir.z); CalculateTransform(); if (def->drawType >= DRAWTYPE_TREE) { treeDrawer->DeleteTree(pos); treeDrawer->AddTree(def->drawType - 1, pos, 1.0f); }*/ float3 updir = UpVector; if (updir == newDir) { //FIXME perhaps save the old right,up,front directions, so we can // reconstruct the old upvector and generate a better assumption for updir updir -= GetVectorFromHeading(heading); } float3 rightdir = newDir.cross(updir).Normalize(); updir = rightdir.cross(newDir); transMatrix = CMatrix44f(pos, -rightdir, updir, newDir); heading = GetHeadingFromVector(newDir.x, newDir.z);}
开发者ID:DeadnightWarrior,项目名称:spring,代码行数:22,
示例9: ifvoid CAirMoveType::SetState(CAirMoveType::AircraftState state){ if(aircraftState==AIRCRAFT_CRASHING || state==aircraftState) return;/* if (state == AIRCRAFT_LANDING) owner->animator->AnimAction(ANIMFN_Deactivate); else if (state == aircraft_flying) //animator->AnimAction(ANIMFN_Activate); */ if (state == AIRCRAFT_FLYING) { owner->Activate(); owner->animator->AnimAction(ANIMFN_StartMoving); } if(state==AIRCRAFT_LANDED){ owner->heading=GetHeadingFromVector(owner->frontdir.x, owner->frontdir.z); owner->physicalState = CSolidObject::OnGround; owner->useAirLos=false; }else{ owner->physicalState = CSolidObject::Flying; owner->useAirLos=true; if(state!=AIRCRAFT_LANDING){ reservedLandingPos.x=-1; owner->UnBlock(); } } if(aircraftState==AIRCRAFT_LANDED && reservedLandingPos.x>0){ reservedLandingPos.x=-1; } subState=0; if(state!=AIRCRAFT_TAKEOFF || aircraftState==AIRCRAFT_LANDED) //make sure we only go into takeoff if actually landed aircraftState=state; else aircraftState=AIRCRAFT_TAKEOFF;}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:37,
示例10: GetBuildPiecevoid CFactory::UpdateBuild(CUnit* buildee) { if (stunned) return; // factory not under construction and // nanolathing unit: continue building lastBuildUpdateFrame = gs->frameNum; // buildPiece is the rotating platform const int buildPiece = GetBuildPiece(); const float3& buildPos = CalcBuildPos(buildPiece); const CMatrix44f& mat = script->GetPieceMatrix(buildPiece); const int h = GetHeadingFromVector(mat[2], mat[10]); //! x.z, z.z float3 buildeePos = buildPos; // rotate unit nanoframe with platform buildee->heading = (-h + GetHeadingFromFacing(buildFacing)) & (SPRING_CIRCLE_DIVS - 1); if (buildee->unitDef->floatOnWater && (buildeePos.y <= 0.0f)) buildeePos.y = -buildee->unitDef->waterline; buildee->Move3D(buildeePos, false); buildee->UpdateDirVectors(false); buildee->UpdateMidAndAimPos(); const CCommandQueue& queue = commandAI->commandQue; if (!queue.empty() && (queue.front().GetID() == CMD_WAIT)) { buildee->AddBuildPower(0, this); } else { if (buildee->AddBuildPower(buildSpeed, this)) { CreateNanoParticle(); } }}
开发者ID:Finkky,项目名称:spring,代码行数:36,
示例11: UpdateAirPhysicsbool CHoverAirMoveType::Update(){ const float3 lastPos = owner->pos; const float4 lastSpd = owner->speed; AAirMoveType::Update(); if ((owner->IsStunned() && !owner->IsCrashing()) || owner->beingBuilt) { wantedSpeed = ZeroVector; UpdateAirPhysics(); return (HandleCollisions(collide && !owner->beingBuilt && (padStatus == PAD_STATUS_FLYING) && (aircraftState != AIRCRAFT_TAKEOFF))); } // allow us to stop if wanted (changes aircraft state) if (wantToStop) ExecuteStop(); if (aircraftState != AIRCRAFT_CRASHING) { if (owner->UnderFirstPersonControl()) { SetState(AIRCRAFT_FLYING); const FPSUnitController& con = owner->fpsControlPlayer->fpsController; const float3 forward = con.viewDir; const float3 right = forward.cross(UpVector); const float3 nextPos = lastPos + owner->speed; float3 flatForward = forward; flatForward.Normalize2D(); wantedSpeed = ZeroVector; if (con.forward) wantedSpeed += flatForward; if (con.back ) wantedSpeed -= flatForward; if (con.right ) wantedSpeed += right; if (con.left ) wantedSpeed -= right; wantedSpeed.Normalize(); wantedSpeed *= maxSpeed; if (!nextPos.IsInBounds()) { owner->SetVelocityAndSpeed(ZeroVector); } UpdateAirPhysics(); wantedHeading = GetHeadingFromVector(flatForward.x, flatForward.z); } if (reservedPad != NULL) { MoveToRepairPad(); if (padStatus >= PAD_STATUS_LANDING) { flyState = FLY_LANDING; } } } switch (aircraftState) { case AIRCRAFT_LANDED: UpdateLanded(); break; case AIRCRAFT_TAKEOFF: UpdateTakeoff(); break; case AIRCRAFT_FLYING: UpdateFlying(); break; case AIRCRAFT_LANDING: UpdateLanding(); break; case AIRCRAFT_HOVERING: UpdateHovering(); break; case AIRCRAFT_CRASHING: { UpdateAirPhysics(); if ((CGround::GetHeightAboveWater(owner->pos.x, owner->pos.z) + 5.0f + owner->radius) > owner->pos.y) { owner->ClearPhysicalStateBit(CSolidObject::PSTATE_BIT_CRASHING); owner->KillUnit(NULL, true, false); } else { #define SPIN_DIR(o) ((o->id & 1) * 2 - 1) wantedHeading = GetHeadingFromVector(owner->rightdir.x * SPIN_DIR(owner), owner->rightdir.z * SPIN_DIR(owner)); wantedHeight = 0.0f; #undef SPIN_DIR } new CSmokeProjectile(owner, owner->midPos, gs->randVector() * 0.08f, 100 + gs->randFloat() * 50, 5, 0.2f, 0.4f); } break; } if (lastSpd == ZeroVector && owner->speed != ZeroVector) { owner->script->StartMoving(false); } if (lastSpd != ZeroVector && owner->speed == ZeroVector) { owner->script->StopMoving(); } // Banking requires deltaSpeed.y = 0 deltaSpeed = owner->speed - lastSpd; deltaSpeed.y = 0.0f; // Turn and bank and move; update dirs UpdateHeading();//.........这里部分代码省略.........
开发者ID:9heart,项目名称:spring,代码行数:101,
示例12: 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); }}
开发者ID:9heart,项目名称:spring,代码行数:101,
示例13: fabs//.........这里部分代码省略......... case FLY_CIRCLING: waitCounter++; if (waitCounter > 100) { //logOutput.Print("moving circlepos"); float3 relPos = pos - circlingPos; if(relPos.x<0.0001f && relPos.x>-0.0001f) relPos.x=0.0001f; relPos.y = 0; relPos.Normalize(); CMatrix44f rot; rot.RotateY(1.0f); float3 newPos = rot.Mul(relPos); //Make sure the point is on the circle newPos = newPos.Normalize() * goalDistance; //Go there in a straight line goalPos = circlingPos + newPos; waitCounter = 0; } break; case FLY_ATTACKING:{ //logOutput.Print("wait is %d", waitCounter); float3 relPos = pos - circlingPos; if(relPos.x<0.0001f && relPos.x>-0.0001f) relPos.x=0.0001f; relPos.y = 0; relPos.Normalize(); CMatrix44f rot; if (gs->randFloat()>0.5f) rot.RotateY(0.6f+gs->randFloat()*0.6f); else rot.RotateY(-(0.6f+gs->randFloat()*0.6f)); float3 newPos = rot.Mul(relPos); newPos = newPos.Normalize() * goalDistance; //Go there in a straight line goalPos = circlingPos + newPos;// logOutput.Print("Changed circle pos"); break;} case FLY_LANDING:{/* //First check if we can land around here somewhere if (!CanLandAt(pos)) { //Check the surrounding area for a suitable position float3 newPos; bool found = FindLandingSpot(pos, newPos); if (found) { SetState(AIRCRAFT_FLYING); logOutput.Print("Found a landingspot when cruising around"); goalPos = newPos; return; } } else { SetState(AIRCRAFT_LANDING); return; } float3 relPos = pos - circlingPos; relPos.y = 0; CMatrix44f rot; rot.RotateY(2.0f); float3 newPos = rot.Mul(relPos); //Make sure the point is on the circle newPos = newPos.Normalize() * goalDistance; //Go there in a straight line goalPos = circlingPos + newPos; waitCounter = 0; */ break;} } } //no, so go there! dir.y = 0; float realMax = maxSpeed; float dist=dir.Length2D(); //If we are close to our goal, we should go slow enough to be able to break in time //if in attack mode dont slow down if (flyState!=FLY_ATTACKING && dist < breakDistance) { realMax = dist/(speed.Length2D()+0.01f) * decRate; //logOutput.Print("Break! %f %f %f", maxSpeed, dir.Length2D(), realMax); } wantedSpeed = dir.Normalize() * realMax; UpdateAirPhysics(); //Point toward goal or forward if ((flyState == FLY_ATTACKING) || (flyState == FLY_CIRCLING)) { dir = circlingPos - pos; } else { dir = goalPos - pos; } if(dir.SqLength2D()>1) wantedHeading = GetHeadingFromVector(dir.x, dir.z);}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:101,
示例14: SetStatevoid 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); } } }//.........这里部分代码省略.........
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:101,
示例15: ExecuteStopbool CHoverAirMoveType::Update(){ float3& pos = owner->pos; float3& speed = owner->speed; AAirMoveType::Update(); if (owner->stunned || owner->beingBuilt) { wantedSpeed = ZeroVector; wantToStop = true; } // Allow us to stop if wanted if (wantToStop) { ExecuteStop(); } const float3 lastSpeed = speed; if (owner->fpsControlPlayer != NULL) { SetState(AIRCRAFT_FLYING); const FPSUnitController& con = owner->fpsControlPlayer->fpsController; const float3 forward = con.viewDir; const float3 right = forward.cross(UpVector); const float3 nextPos = pos + speed; float3 flatForward = forward; flatForward.y = 0.0f; flatForward.Normalize(); wantedSpeed = ZeroVector; if (con.forward) wantedSpeed += flatForward; if (con.back ) wantedSpeed -= flatForward; if (con.right ) wantedSpeed += right; if (con.left ) wantedSpeed -= right; wantedSpeed.Normalize(); wantedSpeed *= maxSpeed; if (!nextPos.IsInBounds()) { speed = ZeroVector; } UpdateAirPhysics(); wantedHeading = GetHeadingFromVector(flatForward.x, flatForward.z); } else { if (reservedPad != NULL) { MoveToRepairPad(); if (padStatus >= 1) { flyState = FLY_LANDING; } } // Main state handling switch (aircraftState) { case AIRCRAFT_LANDED: UpdateLanded(); break; case AIRCRAFT_TAKEOFF: UpdateTakeoff(); break; case AIRCRAFT_FLYING: UpdateFlying(); break; case AIRCRAFT_LANDING: UpdateLanding(); break; case AIRCRAFT_HOVERING: UpdateHovering(); break; case AIRCRAFT_CRASHING: break; } } // Banking requires deltaSpeed.y = 0 deltaSpeed = speed - lastSpeed; deltaSpeed.y = 0.0f; // Turn and bank and move; update dirs UpdateHeading(); UpdateBanking(aircraftState == AIRCRAFT_HOVERING); return (HandleCollisions());}
开发者ID:azotlikid,项目名称:spring,代码行数:90,
示例16: UseSmoothMesh//.........这里部分代码省略......... SetState(AIRCRAFT_HOVERING); if (waitCounter > (GAME_SPEED << 1)) { wantedHeight = orgWantedHeight; } } else { wantedSpeed = ZeroVector; if (!hasMoreMoveCmds) { wantToStop = true; SetState(AIRCRAFT_HOVERING); } } } else { wantedHeight = orgWantedHeight; SetState(AIRCRAFT_LANDING); } return; } case FLY_CIRCLING: // break; 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; } relPos.y = 0.0f; relPos.Normalize(); static CMatrix44f rot(0.0f,fastmath::PI/4.0f,0.0f); float3 newPos = rot.Mul(relPos); // Make sure the point is on the circle newPos = newPos * goalDistance; // Go there in a straight line goalPos = circlingPos + newPos; } 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; } relPos.y = 0; relPos.Normalize(); CMatrix44f rot; if (gs->randFloat() > 0.5f) { rot.RotateY(0.6f + gs->randFloat() * 0.6f); } else { rot.RotateY(-(0.6f + gs->randFloat() * 0.6f)); } float3 newPos = rot.Mul(relPos); newPos = newPos * goalDistance; // Go there in a straight line goalPos = circlingPos + newPos; } break; } case FLY_LANDING: { break; } } } // not there yet, so keep going goalVec.y = 0.0f; // if we are close to our goal and not in attack mode, // we should go slow enough to be able to break in time const float goalDist = goalVec.Length() + 0.1f; const float approachSpeed = (flyState != FLY_ATTACKING && goalDist < brakeDistance)? (goalDist / (speed.Length2D() + 0.01f) * decRate): maxSpeed; wantedSpeed = (goalVec / goalDist) * approachSpeed; 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 < 120.0f) && ((goalVec.SafeNormalize()).SqDistance(goalVec) > 1.0f); if (b0 && b1) { goalVec = owner->frontdir; } else { goalVec = goalPos - pos; } } if (goalVec.SqLength2D() > 1.0f) { wantedHeading = GetHeadingFromVector(goalVec.x, goalVec.z); }}
开发者ID:AlexDiede,项目名称:spring,代码行数:101,
示例17: CalcBuildPosvoid CFactory::Update(){ if(beingBuilt){ CUnit::Update(); return; } if(quedBuild && inBuildStance){ float3 buildPos = CalcBuildPos(); bool canBuild=true; std::vector<CUnit*> units=qf->GetUnitsExact(buildPos,16); for(std::vector<CUnit*>::iterator ui=units.begin();ui!=units.end();++ui){ if((*ui)!=this) canBuild=false; } if(canBuild){ quedBuild=false; CUnit* b=unitLoader.LoadUnit(nextBuild,buildPos+float3(0.01,0.01,0.01),team,true,buildFacing); AddDeathDependence(b); curBuild=b; animator->AnimAction("StartBuilding"); if(unitDef->sounds.build.id) sound->PlaySound(unitDef->sounds.build.id, pos, unitDef->sounds.build.volume); } else { helper->BuggerOff(buildPos-float3(0.01,0,0.02),radius+8); } } if(curBuild && !beingBuilt){ lastBuild=gs->frameNum; int buildPiece = GetBuildPiece(); CMatrix44f mat=localmodel->GetPieceMatrix(buildPiece); int h=GetHeadingFromVector(mat[2],mat[10]); curBuild->heading=h; float3 buildPos = curBuild->pos = CalcBuildPos(buildPiece); if(curBuild->floatOnWater) curBuild->pos.y=ground->GetHeight(buildPos.x,buildPos.z)-curBuild->unitDef->waterline; curBuild->midPos=curBuild->pos+UpVector*curBuild->relMidPos.y; if(curBuild->AddBuildPower(buildSpeed,this)){ std::vector<int> args; args.push_back(0); animator->AnimAction("QueryNanoPiece",args); if(unitDef->showNanoSpray){ float3 relWeaponFirePos=localmodel->GetPiecePos(args[0]); float3 weaponPos=pos + frontdir*relWeaponFirePos.z + updir*relWeaponFirePos.y + rightdir*relWeaponFirePos.x; float3 dif=curBuild->midPos-weaponPos; float l=dif.Length(); dif/=l; dif+=gs->randVector()*0.15f; float3 color= unitDef->nanoColor; if(gu->teamNanospray){ unsigned char* tcol=gs->Team(team)->color; color = float3(tcol[0]*(1./255.),tcol[1]*(1./255.),tcol[2]*(1./255.)); } new CGfxProjectile(weaponPos,dif,(int)l,color); } } else { if(!curBuild->beingBuilt){ if(group) curBuild->SetGroup(group); Command c; c.id=CMD_MOVE_STATE; c.options=0; c.params.push_back(moveState); curBuild->commandAI->GiveCommand(c); c.params.clear(); c.id=CMD_FIRE_STATE; c.params.push_back(fireState); curBuild->commandAI->GiveCommand(c); if(curBuild->commandAI->commandQue.empty() || (dynamic_cast<CMobileCAI*>(curBuild->commandAI) && ((CMobileCAI*)curBuild->commandAI)->unimportantMove)){ if(((CFactoryCAI*)commandAI)->newUnitCommands.empty()){ SendToEmptySpot(curBuild); } else { for(std::deque<Command>::iterator ci=((CFactoryCAI*)commandAI)->newUnitCommands.begin();ci!=((CFactoryCAI*)commandAI)->newUnitCommands.end();++ci) curBuild->commandAI->GiveCommand(*ci); } } StopBuild(); } } } if(lastBuild+200 < gs->frameNum && !quedBuild && opening && uh->CanCloseYard(this)){ readmap->CloseBlockingYard(this); opening=false; animator->AnimAction(ANIMFN_Deactivate); } CBuilding::Update();}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:97,
示例18: switch//.........这里部分代码省略......... if (dontLand || (++waitCounter < 55 && dynamic_cast<CTransportUnit*>(owner)) || !autoLand) { // transport aircraft need some time to detect that they can pickup if (dynamic_cast<CTransportUnit*>(owner)) { wantedSpeed = ZeroVector; if (waitCounter > 60) { wantedHeight = orgWantedHeight; } } else { wantedSpeed = ZeroVector; if (!owner->commandAI->HasMoreMoveCommands()) wantToStop = true; SetState(AIRCRAFT_HOVERING); } } else { wantedHeight = orgWantedHeight; SetState(AIRCRAFT_LANDING); } return; case FLY_CIRCLING: // break; waitCounter++; if (waitCounter > 100) { if (owner->unitDef->airStrafe) { float3 relPos = pos - circlingPos; if (relPos.x < 0.0001f && relPos.x > -0.0001f) relPos.x = 0.0001f; relPos.y = 0; relPos.Normalize(); CMatrix44f rot; rot.RotateY(1.0f); float3 newPos = rot.Mul(relPos); // Make sure the point is on the circle newPos = newPos.Normalize() * goalDistance; //Go there in a straight line goalPos = circlingPos + newPos; } waitCounter = 0; } break; case FLY_ATTACKING:{ if (owner->unitDef->airStrafe) { float3 relPos = pos - circlingPos; if (relPos.x < 0.0001f && relPos.x > -0.0001f) relPos.x = 0.0001f; relPos.y = 0; relPos.Normalize(); CMatrix44f rot; if (gs->randFloat() > 0.5f) rot.RotateY(0.6f + gs->randFloat() * 0.6f); else rot.RotateY(-(0.6f + gs->randFloat() * 0.6f)); float3 newPos = rot.Mul(relPos); newPos = newPos.Normalize() * goalDistance; // Go there in a straight line goalPos = circlingPos + newPos; } break; } case FLY_LANDING:{ break; } } } // not there yet, so keep going dir.y = 0; float realMax = maxSpeed; float dist = dir.Length2D(); // If we are close to our goal, we should go slow enough to be able to break in time // new additional rule: if in attack mode or if we have more move orders then this is // an intermediate waypoint, don't slow down (FIXME) /// if (flyState != FLY_ATTACKING && dist < breakDistance && !owner->commandAI->HasMoreMoveCommands()) { if (flyState != FLY_ATTACKING && dist < breakDistance) { realMax = dist / (speed.Length2D() + 0.01f) * decRate; } wantedSpeed = dir.Normalize() * realMax; UpdateAirPhysics(); // Point toward goal or forward - unless we just passed it to get to another goal if ((flyState == FLY_ATTACKING) || (flyState == FLY_CIRCLING)) { dir = circlingPos - pos; } else if (flyState != FLY_LANDING && (owner->commandAI->HasMoreMoveCommands() && dist < 120) && (goalPos - pos).Normalize().distance(dir) > 1) { dir = owner->frontdir; } else { dir = goalPos - pos; } if (dir.SqLength2D() > 1) { int h = GetHeadingFromVector(dir.x, dir.z); wantedHeading = (h == 0)? wantedHeading: h; }}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:101,
示例19: newErrorVectorvoid CWeapon::Update(){ if(hasCloseTarget) { std::vector<int> args; args.push_back(0); if(useWeaponPosForAim) { owner->cob->Call(COBFN_QueryPrimary+weaponNum,args); } else { owner->cob->Call(COBFN_AimFromPrimary+weaponNum,args); } relWeaponPos=owner->localmodel->GetPiecePos(args[0]); } if(targetType==Target_Unit) { if(lastErrorVectorUpdate<gs->frameNum-16) { float3 newErrorVector(gs->randVector()); errorVectorAdd=(newErrorVector-errorVector)*(1.0f/16.0f); lastErrorVectorUpdate=gs->frameNum; } errorVector+=errorVectorAdd; if(weaponDef->selfExplode) { //assumes that only flakker like units that need to hit aircrafts has this,change to a separate tag later targetPos=helper->GetUnitErrorPos(targetUnit,owner->allyteam)+targetUnit->speed*(0.5+predictSpeedMod*0.5)*predict; } else { targetPos=helper->GetUnitErrorPos(targetUnit,owner->allyteam)+targetUnit->speed*predictSpeedMod*predict; } targetPos+=errorVector*(weaponDef->targetMoveError*30*targetUnit->speed.Length()*(1.0-owner->limExperience)); if(!weaponDef->waterweapon && targetPos.y<1) targetPos.y=1; } if(weaponDef->interceptor) CheckIntercept(); if(targetType!=Target_None) { if(onlyForward) { float3 goaldir=targetPos-owner->pos; goaldir.Normalize(); angleGood=owner->frontdir.dot(goaldir) > maxAngleDif; } else if(lastRequestedDir.dot(wantedDir)<maxAngleDif || lastRequest+15<gs->frameNum) { angleGood=false; lastRequestedDir=wantedDir; lastRequest=gs->frameNum; short int heading=GetHeadingFromVector(wantedDir.x,wantedDir.z); short int pitch=(short int) (asin(wantedDir.dot(owner->updir))*(32768/PI)); std::vector<int> args; args.push_back(short(heading-owner->heading)); args.push_back(pitch); owner->cob->Call(COBFN_AimPrimary+weaponNum,args,ScriptCallback,this,0); } } if(weaponDef->stockpile && numStockpileQued) { float p=1.0/reloadTime; if(gs->Team(owner->team)->metal>=metalFireCost*p && gs->Team(owner->team)->energy>=energyFireCost*p) { owner->UseEnergy(energyFireCost*p); owner->UseMetal(metalFireCost*p); buildPercent+=p; } if(buildPercent>=1) { buildPercent=0; numStockpileQued--; numStockpiled++; owner->commandAI->StockpileChanged(this); } } if(salvoLeft==0#ifdef DIRECT_CONTROL_ALLOWED && (!owner->directControl || owner->directControl->mouse1 || owner->directControl->mouse2)#endif && targetType!=Target_None && angleGood && subClassReady && reloadStatus<=gs->frameNum && (weaponDef->stockpile || (gs->Team(owner->team)->metal>=metalFireCost && gs->Team(owner->team)->energy>=energyFireCost)) && (!weaponDef->stockpile || numStockpiled) && (weaponDef->waterweapon || weaponPos.y>0) ) { std::vector<int> args; args.push_back(0); owner->cob->Call(COBFN_QueryPrimary+weaponNum,args); relWeaponPos=owner->localmodel->GetPiecePos(args[0]); weaponPos=owner->pos+owner->frontdir*relWeaponPos.z+owner->updir*relWeaponPos.y+owner->rightdir*relWeaponPos.x; useWeaponPosForAim=reloadTime/16+8; if(TryTarget(targetPos,haveUserTarget,targetUnit)) { if(weaponDef->stockpile) { numStockpiled--; owner->commandAI->StockpileChanged(this); } else { owner->UseEnergy(energyFireCost); owner->UseMetal(metalFireCost); } if(weaponDef->stockpile) reloadStatus=gs->frameNum+60; else reloadStatus=gs->frameNum+(int)(reloadTime/owner->reloadSpeed); salvoLeft=salvoSize; nextSalvo=gs->frameNum; salvoError=gs->randVector()*(owner->isMoving?weaponDef->movingAccuracy:accuracy);//.........这里部分代码省略.........
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:101,
示例20: CalcBuildPosvoid CFactory::Update(){ if (beingBuilt) { // factory under construction CUnit::Update(); return; } if (quedBuild && !opening && !stunned) { cob->Call(COBFN_Activate); groundBlockingObjectMap->OpenBlockingYard(this, yardMap); opening = true; } if (quedBuild && inBuildStance && !stunned) { // start building a unit float3 buildPos = CalcBuildPos(); bool canBuild = true; std::vector<CUnit*> units = qf->GetUnitsExact(buildPos, 16); for (std::vector<CUnit*>::iterator ui = units.begin(); ui != units.end(); ++ui) { if ((*ui) != this) canBuild = false; } if (canBuild) { quedBuild = false; CUnit* b = unitLoader.LoadUnit(nextBuild, buildPos + float3(0.01f, 0.01f, 0.01f), team, true, buildFacing, this); b->lineage = this->lineage; if (!unitDef->canBeAssisted) { b->soloBuilder = this; b->AddDeathDependence(this); } AddDeathDependence(b); curBuild = b; cob->Call("StartBuilding"); int soundIdx = unitDef->sounds.build.getRandomIdx(); if (soundIdx >= 0) { sound->PlaySample( unitDef->sounds.build.getID(soundIdx), pos, unitDef->sounds.build.getVolume(0)); } } else { helper->BuggerOff(buildPos - float3(0.01f, 0, 0.02f), radius + 8); } } if (curBuild && !beingBuilt) { if (!stunned) { // factory not under construction and // nanolathing unit: continue building lastBuild = gs->frameNum; // buildPiece is the rotating platform const int buildPiece = GetBuildPiece(); CMatrix44f mat = localmodel->GetPieceMatrix(buildPiece); const int h = GetHeadingFromVector(mat[2], mat[10]); // rotate unit nanoframe with platform curBuild->heading = (h + GetHeadingFromFacing(buildFacing)) & 65535; const float3 buildPos = CalcBuildPos(buildPiece); curBuild->pos = buildPos; if (curBuild->floatOnWater) { curBuild->pos.y = ground->GetHeight(buildPos.x, buildPos.z); curBuild->pos.y -= curBuild->unitDef->waterline; } curBuild->midPos = curBuild->pos + (UpVector * curBuild->relMidPos.y); const CCommandQueue& queue = commandAI->commandQue; if(!queue.empty() && (queue.front().id == CMD_WAIT)) { curBuild->AddBuildPower(0, this); } else { if (curBuild->AddBuildPower(buildSpeed, this)) { CreateNanoParticle(); } } } if (!curBuild->beingBuilt && (!unitDef->fullHealthFactory || (curBuild->health >= curBuild->maxHealth))) { if (group && curBuild->group == 0) { curBuild->SetGroup(group); } bool userOrders = true; if (curBuild->commandAI->commandQue.empty() || (dynamic_cast<CMobileCAI*>(curBuild->commandAI) && ((CMobileCAI*)curBuild->commandAI)->unimportantMove)) {//.........这里部分代码省略.........
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:101,
示例21: newErrorVectorvoid CWeapon::Update(){ if(hasCloseTarget){ std::vector<int> args; args.push_back(0); if(useWeaponPosForAim){ owner->animator->AnimAction(ANIMFN_QueryPrimary+weaponNum,args); } else { owner->animator->AnimAction(ANIMFN_AimFromPrimary+weaponNum,args); } relWeaponPos=owner->localmodel->GetPiecePos(args[0]); } if(targetType==Target_Unit){ if(lastErrorVectorUpdate<gs->frameNum-16){ float3 newErrorVector(gs->randVector()); errorVectorAdd=(newErrorVector-errorVector)*(1.0f/16.0f); lastErrorVectorUpdate=gs->frameNum; } errorVector+=errorVectorAdd; if (predict > 50000) { /* to prevent runaway prediction (happens sometimes when a missile is moving *away* from it's target), we may need to disable missiles in case they fly around too long */ predict = 50000; } if(weaponDef->selfExplode){ //assumes that only flakker like units that need to hit aircrafts has this,change to a separate tag later targetPos=helper->GetUnitErrorPos(targetUnit,owner->allyteam)+targetUnit->speed*(0.5+predictSpeedMod*0.5)*predict; } else { targetPos=helper->GetUnitErrorPos(targetUnit,owner->allyteam)+targetUnit->speed*predictSpeedMod*predict; } targetPos+=errorVector*(weaponDef->targetMoveError*30*targetUnit->speed.Length()*(1.0-owner->limExperience)); float appHeight=ground->GetApproximateHeight(targetPos.x,targetPos.z)+2; if(targetPos.y < appHeight) targetPos.y=appHeight; if(!weaponDef->waterweapon && targetPos.y<1) targetPos.y=1; } if(weaponDef->interceptor) CheckIntercept(); if(targetType!=Target_None){ if(onlyForward){ float3 goaldir=targetPos-owner->pos; goaldir.Normalize(); angleGood=owner->frontdir.dot(goaldir) > maxAngleDif; } else if(lastRequestedDir.dot(wantedDir)<maxAngleDif || lastRequest+15<gs->frameNum){ angleGood=false; lastRequestedDir=wantedDir; lastRequest=gs->frameNum; short int heading=GetHeadingFromVector(wantedDir.x,wantedDir.z); short int pitch=(short int) (asin(wantedDir.dot(owner->updir))*(32768/PI)); std::vector<int> args; args.push_back(short(heading-owner->heading)); args.push_back(pitch); owner->animator->AnimAction(ANIMFN_AimPrimary+weaponNum,args,ScriptCallback,this,0); } } if(weaponDef->stockpile && numStockpileQued){ float p=1.0/reloadTime; if(gs->Team(owner->team)->metal>=metalFireCost*p && gs->Team(owner->team)->energy>=energyFireCost*p){ owner->UseEnergy(energyFireCost*p); owner->UseMetal(metalFireCost*p); buildPercent+=p; } else { // update the energy and metal required counts gs->Team(owner->team)->energyPullAmount += energyFireCost*p; gs->Team(owner->team)->metalPullAmount += metalFireCost*p; } if(buildPercent>=1){ buildPercent=0; numStockpileQued--; numStockpiled++; owner->commandAI->StockpileChanged(this); } } if(salvoLeft==0 #ifdef DIRECT_CONTROL_ALLOWED && (!owner->directControl || owner->directControl->mouse1 || owner->directControl->mouse2)#endif && targetType!=Target_None && angleGood && subClassReady && reloadStatus<=gs->frameNum && (!weaponDef->stockpile || numStockpiled) && (weaponDef->waterweapon || weaponPos.y>0) && (owner->unitDef->maxFuel==0 || owner->currentFuel > 0) ){ if ((weaponDef->stockpile || (gs->Team(owner->team)->metal>=metalFireCost && gs->Team(owner->team)->energy>=energyFireCost))) { std::vector<int> args; args.push_back(0); owner->animator->AnimAction(ANIMFN_QueryPrimary+weaponNum,args); relWeaponPos=owner->localmodel->GetPiecePos(args[0]); weaponPos=owner->pos+owner->frontdir*relWeaponPos.z+owner->updir*relWeaponPos.y+owner->rightdir*relWeaponPos.x; useWeaponPosForAim=reloadTime/16+8; if(TryTarget(targetPos,haveUserTarget,targetUnit)){ if(weaponDef->stockpile){ numStockpiled--;//.........这里部分代码省略.........
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:101,
示例22: SetStatebool CTAAirMoveType::Update(){ float3& pos = owner->pos; float3& speed = owner->speed; // This is only set to false after the plane has finished constructing if (useHeading) { useHeading = false; SetState(AIRCRAFT_TAKEOFF); } if (owner->stunned || owner->beingBuilt) { wantedSpeed = ZeroVector; wantToStop = true; } // Allow us to stop if wanted if (wantToStop) { ExecuteStop(); } const float3 lastSpeed = speed; if (owner->fpsControlPlayer != NULL) { SetState(AIRCRAFT_FLYING); const FPSUnitController& con = owner->fpsControlPlayer->fpsController; const float3 forward = con.viewDir; const float3 right = forward.cross(UpVector); const float3 nextPos = pos + speed; float3 flatForward = forward; flatForward.y = 0.0f; flatForward.Normalize(); wantedSpeed = ZeroVector; if (con.forward) wantedSpeed += flatForward; if (con.back ) wantedSpeed -= flatForward; if (con.right ) wantedSpeed += right; if (con.left ) wantedSpeed -= right; wantedSpeed.Normalize(); wantedSpeed *= maxSpeed; if (!nextPos.IsInBounds()) { speed = ZeroVector; } UpdateAirPhysics(); wantedHeading = GetHeadingFromVector(flatForward.x, flatForward.z); } else { if (reservedPad) { CUnit* unit = reservedPad->GetUnit(); const float3 relPos = unit->script->GetPiecePos(reservedPad->GetPiece()); const 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_FLYING) { SetState(AIRCRAFT_FLYING); } flyState = FLY_LANDING; goalPos = pos; reservedLandingPos = pos; wantedHeight = pos.y - ground->GetHeightAboveWater(pos.x, pos.z); 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 / 30, 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) { airBaseHandler->LeaveLandingPad(reservedPad); reservedPad = NULL; padStatus = 0; goalPos = oldGoalPos; SetState(AIRCRAFT_TAKEOFF); }//.........这里部分代码省略.........
开发者ID:tvo,项目名称:spring,代码行数:101,
示例23: newErrorVectorvoid CWeapon::Update(){ if(hasCloseTarget){ std::vector<int> args; args.push_back(0); if(useWeaponPosForAim){ //if we couldn't get a line of fire from the muzzle try if we can get it from the aim piece owner->cob->Call(COBFN_QueryPrimary+weaponNum,args); } else { owner->cob->Call(COBFN_AimFromPrimary+weaponNum,args); } relWeaponMuzzlePos=owner->localmodel->GetPiecePos(args[0]); owner->cob->Call(COBFN_AimFromPrimary+weaponNum,args); relWeaponPos=owner->localmodel->GetPiecePos(args[0]); } if(targetType==Target_Unit){ if(lastErrorVectorUpdate<gs->frameNum-16){ float3 newErrorVector(gs->randVector()); errorVectorAdd=(newErrorVector-errorVector)*(1.0f/16.0f); lastErrorVectorUpdate=gs->frameNum; } errorVector+=errorVectorAdd; if (predict > 50000) { /* to prevent runaway prediction (happens sometimes when a missile is moving *away* from it's target), we may need to disable missiles in case they fly around too long */ predict = 50000; } float3 lead = targetUnit->speed * (weaponDef->predictBoost+predictSpeedMod * (1.0f - weaponDef->predictBoost)) * predict; if (weaponDef->leadLimit >= 0.0f && lead.Length() > weaponDef->leadLimit + weaponDef->leadBonus * owner->experience) { lead *= (weaponDef->leadLimit + weaponDef->leadBonus*owner->experience) / (lead.Length() + 0.01f); } targetPos = helper->GetUnitErrorPos(targetUnit, owner->allyteam) + lead; targetPos += errorVector * (weaponDef->targetMoveError * 30 * targetUnit->speed.Length() * (1.0f - owner->limExperience)); float appHeight = ground->GetApproximateHeight(targetPos.x, targetPos.z) + 2; if (targetPos.y < appHeight) targetPos.y = appHeight; if (!weaponDef->waterweapon && targetPos.y < 1.0f) targetPos.y = 1.0f; } if (weaponDef->interceptor) { CheckIntercept(); } if (targetType != Target_None){ if (onlyForward) { float3 goaldir = targetPos - owner->pos; goaldir.Normalize(); angleGood = (owner->frontdir.dot(goaldir) > maxAngleDif); } else if (lastRequestedDir.dot(wantedDir) < maxAngleDif || lastRequest + 15 < gs->frameNum) { angleGood=false; lastRequestedDir=wantedDir; lastRequest=gs->frameNum; short int heading=GetHeadingFromVector(wantedDir.x,wantedDir.z); short int pitch=(short int) (asin(wantedDir.dot(owner->updir))*(32768/PI)); std::vector<int> args; args.push_back(short(heading - owner->heading)); args.push_back(pitch); owner->cob->Call(COBFN_AimPrimary+weaponNum,args,ScriptCallback,this,0); } } if(weaponDef->stockpile && numStockpileQued){ float p=1.0f/stockpileTime; if(gs->Team(owner->team)->metal>=metalFireCost*p && gs->Team(owner->team)->energy>=energyFireCost*p){ owner->UseEnergy(energyFireCost*p); owner->UseMetal(metalFireCost*p); buildPercent+=p; } else { // update the energy and metal required counts gs->Team(owner->team)->energyPull += energyFireCost*p; gs->Team(owner->team)->metalPull += metalFireCost*p; } if(buildPercent>=1){ const int oldCount = numStockpiled; buildPercent=0; numStockpileQued--; numStockpiled++; owner->commandAI->StockpileChanged(this); eventHandler.StockpileChanged(owner, this, oldCount); } } if ((salvoLeft == 0)#ifdef DIRECT_CONTROL_ALLOWED && (!owner->directControl || owner->directControl->mouse1 || owner->directControl->mouse2)#endif && (targetType != Target_None) && angleGood && subClassReady && (reloadStatus <= gs->frameNum) && (!weaponDef->stockpile || numStockpiled) && (weaponDef->fireSubmersed || (weaponMuzzlePos.y > 0)) && ((owner->unitDef->maxFuel == 0) || (owner->currentFuel > 0)) )//.........这里部分代码省略.........
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:101,
示例24: assertvoid CMobileCAI::ExecuteAttack(Command &c){ assert(owner->unitDef->canAttack); // limit how far away we fly based on our movestate if (tempOrder && orderTarget) { const float3& closestPos = ClosestPointOnLine(commandPos1, commandPos2, owner->pos); const float curTargetDist = LinePointDist(closestPos, commandPos2, orderTarget->pos); const float maxTargetDist = (500 * owner->moveState + owner->maxRange); if (owner->moveState < MOVESTATE_ROAM && curTargetDist > maxTargetDist) { StopMove(); FinishCommand(); return; } } // check if we are in direct command of attacker if (!inCommand) { if (c.params.size() == 1) { CUnit* targetUnit = unitHandler->GetUnit(c.params[0]); // check if we have valid target parameter and that we aren't attacking ourselves if (targetUnit == NULL) { StopMove(); FinishCommand(); return; } if (targetUnit == owner) { StopMove(); FinishCommand(); return; } if (targetUnit->GetTransporter() != NULL && !modInfo.targetableTransportedUnits) { StopMove(); FinishCommand(); return; } const float3 tgtErrPos = targetUnit->pos + owner->posErrorVector * 128; const float3 tgtPosDir = (tgtErrPos - owner->pos).Normalize(); SetGoal(tgtErrPos - tgtPosDir * targetUnit->radius, owner->pos); SetOrderTarget(targetUnit); owner->AttackUnit(targetUnit, (c.options & INTERNAL_ORDER) == 0, c.GetID() == CMD_MANUALFIRE); inCommand = true; } else if (c.params.size() >= 3) { // user gave force-fire attack command SetGoal(c.GetPos(0), owner->pos); inCommand = true; } } // if our target is dead or we lost it then stop attacking // NOTE: unit should actually just continue to target area! if (targetDied || (c.params.size() == 1 && UpdateTargetLostTimer(int(c.params[0])) == 0)) { // cancel keeppointingto StopMove(); FinishCommand(); return; } // user clicked on enemy unit (note that we handle aircrafts slightly differently) if (orderTarget != NULL) { bool tryTargetRotate = false; bool tryTargetHeading = false; float edgeFactor = 0.0f; // percent offset to target center const float3 targetMidPosVec = owner->midPos - orderTarget->midPos; const float targetGoalDist = (orderTarget->pos + owner->posErrorVector * 128.0f).SqDistance2D(goalPos); const float targetPosDist = Square(10.0f + orderTarget->pos.distance2D(owner->pos) * 0.2f); const float minPointingDist = std::min(1.0f * owner->losRadius * loshandler->losDiv, owner->maxRange * 0.9f); // FIXME? targetMidPosMaxDist is 3D, but compared with a 2D value const float targetMidPosDist2D = targetMidPosVec.Length2D(); //const float targetMidPosMaxDist = owner->maxRange - (orderTarget->speed.SqLength() / owner->unitDef->maxAcc); if (!owner->weapons.empty()) { if (!(c.options & ALT_KEY) && SkipParalyzeTarget(orderTarget)) { StopMove(); FinishCommand(); return; } } for (unsigned int wNum = 0; wNum < owner->weapons.size(); wNum++) { CWeapon* w = owner->weapons[wNum]; if (c.GetID() == CMD_MANUALFIRE) { assert(owner->unitDef->canManualFire); if (!w->weaponDef->manualfire) { continue; } } tryTargetRotate = w->TryTargetRotate(orderTarget, (c.options & INTERNAL_ORDER) == 0); tryTargetHeading = w->TryTargetHeading(GetHeadingFromVector(-targetMidPosVec.x, -targetMidPosVec.z), orderTarget->pos, orderTarget != NULL, orderTarget); if (tryTargetRotate || tryTargetHeading) break; edgeFactor = math::fabs(w->targetBorder); }//.........这里部分代码省略.........
开发者ID:AlexDiede,项目名称:spring,代码行数:101,
示例25: AddDeathDependencevoid CFactory::Update(){ if(beingBuilt){ CUnit::Update(); return; } if(quedBuild && inBuildStance){ std::vector<long> args; args.push_back(0); cob->Call("QueryBuildInfo",args); float3 relBuildPos=localmodel->GetPiecePos(args[0]); float3 buildPos=pos + frontdir*relBuildPos.z + updir*relBuildPos.y + rightdir*relBuildPos.x; bool canBuild=true; std::vector<CUnit*> units=qf->GetUnitsExact(buildPos,16); for(std::vector<CUnit*>::iterator ui=units.begin();ui!=units.end();++ui){ if((*ui)!=this) canBuild=false; } if(canBuild){ quedBuild=false; CUnit* b=unitLoader.LoadUnit(nextBuild,buildPos+float3(0.01,0.01,0.01),team,true); AddDeathDependence(b); curBuild=b; cob->Call("StartBuilding"); if(unitDef->sounds.build.id) sound->PlaySound(unitDef->sounds.build.id, pos, unitDef->sounds.build.volume); } else { helper->BuggerOff(buildPos-float3(0.01,0,0.02),radius+8); } } if(curBuild && !beingBuilt){ lastBuild=gs->frameNum; std::vector<long> args; args.push_back(0); cob->Call("QueryBuildInfo",args); CMatrix44f mat=localmodel->GetPieceMatrix(args[0]); int h=GetHeadingFromVector(mat[2],mat[10]); curBuild->heading=h;// if(curBuild->unitDef->canfly){ //hack to get naval air plant to work correctly, how to do it correctly ? float3 relBuildPos=localmodel->GetPiecePos(args[0]); float3 buildPos=pos + frontdir*relBuildPos.z + updir*relBuildPos.y + rightdir*relBuildPos.x; curBuild->pos=buildPos; if(curBuild->floatOnWater) curBuild->pos.y=ground->GetHeight(buildPos.x,buildPos.z)-curBuild->unitDef->waterline; curBuild->midPos=curBuild->pos+UpVector*curBuild->relMidPos.y;// } if(curBuild->AddBuildPower(buildSpeed,this)){ std::vector<long> args; args.push_back(0); cob->Call("QueryNanoPiece",args); float3 relWeaponFirePos=localmodel->GetPiecePos(args[0]); float3 weaponPos=pos + frontdir*relWeaponFirePos.z + updir*relWeaponFirePos.y + rightdir*relWeaponFirePos.x; float3 dif=curBuild->midPos-weaponPos; float l=dif.Length(); dif/=l; dif+=gs->randVector()*0.15f; new CGfxProjectile(weaponPos,dif,l,float3(0.2f,0.7f,0.2f)); } else { if(!curBuild->beingBuilt){ if(group) curBuild->SetGroup(group); Command c; c.id=CMD_MOVE_STATE; c.options=0; c.params.push_back(moveState); curBuild->commandAI->GiveCommand(c); c.params.clear(); c.id=CMD_FIRE_STATE; c.params.push_back(fireState); curBuild->commandAI->GiveCommand(c); if(curBuild->commandAI->commandQue.empty() || (dynamic_cast<CMobileCAI*>(curBuild->commandAI) && ((CMobileCAI*)curBuild->commandAI)->unimportantMove)){ if(((CFactoryCAI*)commandAI)->newUnitCommands.empty()){ SendToEmptySpot(curBuild); } else { for(std::deque<Command>::iterator ci=((CFactoryCAI*)commandAI)->newUnitCommands.begin();ci!=((CFactoryCAI*)commandAI)->newUnitCommands.end();++ci) curBuild->commandAI->GiveCommand(*ci); } } StopBuild(); } } } if(lastBuild+200 < gs->frameNum && !quedBuild && opening && uh->CanCloseYard(this)){ readmap->CloseBlockingYard(this); opening=false; cob->Call(COBFN_Deactivate); } CBuilding::Update();}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:98,
示例26: UseSmoothMesh//.........这里部分代码省略......... // transport aircraft need some time to detect that they can pickup if (trans) { wantedSpeed = ZeroVector; SetState(AIRCRAFT_HOVERING); if (waitCounter > 60) { wantedHeight = orgWantedHeight; } } else { wantedSpeed = ZeroVector; if (!owner->commandAI->HasMoreMoveCommands()) wantToStop = true; SetState(AIRCRAFT_HOVERING); } } else { wantedHeight = orgWantedHeight; SetState(AIRCRAFT_LANDING); } return; } case FLY_CIRCLING: // break; waitCounter++; if (waitCounter > 100) { if (owner->unitDef->airStrafe) { float3 relPos = pos - circlingPos; if (relPos.x < 0.0001f && relPos.x > -0.0001f) { relPos.x = 0.0001f; } relPos.y = 0.0f; relPos.Normalize(); static CMatrix44f rot(0.0f,fastmath::PI/4.0f,0.0f); float3 newPos = rot.Mul(relPos); // Make sure the point is on the circle newPos = newPos * goalDistance; // Go there in a straight line goalPos = circlingPos + newPos; } waitCounter = 0; } break; case FLY_ATTACKING: { if (owner->unitDef->airStrafe) { float3 relPos = pos - circlingPos; if (relPos.x < 0.0001f && relPos.x > -0.0001f) { relPos.x = 0.0001f; } relPos.y = 0; relPos.Normalize(); CMatrix44f rot; if (gs->randFloat() > 0.5f) { rot.RotateY(0.6f + gs->randFloat() * 0.6f); } else { rot.RotateY(-(0.6f + gs->randFloat() * 0.6f)); } float3 newPos = rot.Mul(relPos); newPos = newPos * goalDistance; // Go there in a straight line goalPos = circlingPos + newPos; } break; } case FLY_LANDING: { break; } } } // not there yet, so keep going dir.y = 0; float realMax = maxSpeed; float dist = dir.Length() + 0.1f; // If we are close to our goal, we should go slow enough to be able to break in time // new additional rule: if in attack mode or if we have more move orders then this is // an intermediate waypoint, don't slow down (FIXME) if (flyState != FLY_ATTACKING && dist < brakeDistance) { realMax = dist / (speed.Length2D() + 0.01f) * decRate; } wantedSpeed = (dir / dist) * realMax; UpdateAirPhysics(); // Point toward goal or forward - unless we just passed it to get to another goal if ((flyState == FLY_ATTACKING) || (flyState == FLY_CIRCLING)) { dir = circlingPos - pos; } else if (flyState != FLY_LANDING && (owner->commandAI->HasMoreMoveCommands() && dist < 120) && (goalPos - pos).Normalize().SqDistance(dir) > 1) { dir = owner->frontdir; } else { dir = goalPos - pos; } if (dir.SqLength2D() > 1) { const int h = GetHeadingFromVector(dir.x, dir.z); wantedHeading = (h == 0)? wantedHeading : h; }}
开发者ID:tvo,项目名称:spring,代码行数:101,
示例27: SetStatevoid CTAAirMoveType::Update(){ float3& pos = owner->pos; 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 { 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); float3 nextPos = pos + speed; 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; if (!nextPos.CheckInBounds()) { speed = ZeroVector; } UpdateAirPhysics(); wantedHeading = GetHeadingFromVector(flatForward.x, flatForward.z); } else { 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_FLYING) SetState(AIRCRAFT_FLYING); flyState = FLY_LANDING; goalPos = pos; reservedLandingPos = pos; wantedHeight = pos.y - ground->GetHeight(pos.x, pos.z); 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 / 30, 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) { airBaseHandler->LeaveLandingPad(reservedPad); reservedPad = 0; padStatus = 0; goalPos = oldGoalPos; SetState(AIRCRAFT_TAKEOFF); } } }//.........这里部分代码省略.........
开发者ID:Dmytry,项目名称:spring,代码行数:101,
示例28: CalcBuildPosvoid CFactory::Update(){ if (beingBuilt) { // factory under construction CUnit::Update(); return; } if (quedBuild && !opening && !stunned) { script->Activate(); groundBlockingObjectMap->OpenBlockingYard(this, curYardMap); opening = true; } if (quedBuild && inBuildStance && !stunned) { // start building a unit const float3 buildPos = CalcBuildPos(); const CSolidObject* solidObj = groundBlockingObjectMap->GroundBlocked(buildPos); if (solidObj == NULL || (dynamic_cast<const CUnit*>(solidObj) == this)) { quedBuild = false; CUnit* b = unitLoader.LoadUnit(nextBuild, buildPos + float3(0.01f, 0.01f, 0.01f), team, true, buildFacing, this); if (!unitDef->canBeAssisted) { b->soloBuilder = this; b->AddDeathDependence(this); } AddDeathDependence(b); curBuild = b; script->StartBuilding(); int soundIdx = unitDef->sounds.build.getRandomIdx(); if (soundIdx >= 0) { Channels::UnitReply.PlaySample( unitDef->sounds.build.getID(soundIdx), pos, unitDef->sounds.build.getVolume(0)); } } else { helper->BuggerOff(buildPos - float3(0.01f, 0, 0.02f), radius + 8, true, true, NULL); } } if (curBuild && !beingBuilt) { if (!stunned) { // factory not under construction and // nanolathing unit: continue building lastBuild = gs->frameNum; // buildPiece is the rotating platform const int buildPiece = GetBuildPiece(); const CMatrix44f& mat = script->GetPieceMatrix(buildPiece); const int h = GetHeadingFromVector(mat[2], mat[10]); //! x.z, z.z // rotate unit nanoframe with platform curBuild->heading = (h + GetHeadingFromFacing(buildFacing)) & 65535; const float3 buildPos = CalcBuildPos(buildPiece); curBuild->pos = buildPos; if (curBuild->floatOnWater) { float waterline = ground->GetHeight(buildPos.x, buildPos.z) - curBuild->unitDef->waterline; if (waterline > curBuild->pos.y) curBuild->pos.y = waterline; } curBuild->midPos = curBuild->pos + (UpVector * curBuild->relMidPos.y); const CCommandQueue& queue = commandAI->commandQue; if(!queue.empty() && (queue.front().id == CMD_WAIT)) { curBuild->AddBuildPower(0, this); } else { if (curBuild->AddBuildPower(buildSpeed, this)) { CreateNanoParticle(); } } } if (!curBuild->beingBuilt && (!unitDef->fullHealthFactory || (curBuild->health >= curBuild->maxHealth))) { if (group && curBuild->group == 0) { curBuild->SetGroup(group); } bool userOrders = true; if (curBuild->commandAI->commandQue.empty() || (dynamic_cast<CMobileCAI*>(curBuild->commandAI) && ((CMobileCAI*)curBuild->commandAI)->unimportantMove)) { userOrders = false; AssignBuildeeOrders(curBuild); waitCommandsAI.AddLocalUnit(curBuild, this); } eventHandler.UnitFromFactory(curBuild, this, userOrders);//.........这里部分代码省略.........
开发者ID:eXLabT,项目名称:spring,代码行数:101,
示例29: assert/*** @brief Causes this CMobileCAI to execute the attack order c*/void CMobileCAI::ExecuteAttack(Command &c){ assert(owner->unitDef->canAttack); // limit how far away we fly if (tempOrder && (owner->moveState < 2) && orderTarget && LinePointDist(ClosestPointOnLine(commandPos1, commandPos2, owner->pos), commandPos2, orderTarget->pos) > (500 * owner->moveState + owner->maxRange)) { StopMove(); FinishCommand(); return; } // check if we are in direct command of attacker if (!inCommand) { // don't start counting until the owner->AttackGround() order is given owner->commandShotCount = -1; if (c.params.size() == 1) { CUnit* targetUnit = uh->GetUnit(c.params[0]); // check if we have valid target parameter and that we aren't attacking ourselves if (targetUnit != NULL && targetUnit != owner) { float3 fix = targetUnit->pos + owner->posErrorVector * 128; float3 diff = float3(fix - owner->pos).Normalize(); SetGoal(fix - diff * targetUnit->radius, owner->pos); orderTarget = targetUnit; AddDeathDependence(orderTarget); inCommand = true; } else { // unit may not fire on itself, cancel order StopMove(); FinishCommand(); return; } } else if (c.params.size() >= 3) { // user gave force-fire attack command float3 pos(c.params[0], c.params[1], c.params[2]); SetGoal(pos, owner->pos); inCommand = true; } } else if ((c.params.size() == 3) && (owner->commandShotCount > 0) && (commandQue.size() > 1)) { // the trailing CMD_SET_WANTED_MAX_SPEED in a command pair does not count if ((commandQue.size() > 2) || (commandQue.back().id != CMD_SET_WANTED_MAX_SPEED)) { StopMove(); FinishCommand(); return; } } // if our target is dead or we lost it then stop attacking // NOTE: unit should actually just continue to target area! if (targetDied || (c.params.size() == 1 && UpdateTargetLostTimer(int(c.params[0])) == 0)) { // cancel keeppointingto StopMove(); FinishCommand(); return; } // user clicked on enemy unit (note that we handle aircrafts slightly differently) if (orderTarget) { //bool b1 = owner->AttackUnit(orderTarget, c.id == CMD_DGUN); bool b2 = false; bool b3 = false; bool b4 = false; float edgeFactor = 0.f; // percent offset to target center float3 diff = owner->pos - orderTarget->midPos; if (owner->weapons.size() > 0) { if (!(c.options & ALT_KEY) && SkipParalyzeTarget(orderTarget)) { StopMove(); FinishCommand(); return; } CWeapon* w = owner->weapons.front(); // if we have at least one weapon then check if we // can hit target with our first (meanest) one b2 = w->TryTargetRotate(orderTarget, c.id == CMD_DGUN); b3 = Square(w->range - (w->relWeaponPos).Length()) > (orderTarget->pos.SqDistance(owner->pos)); b4 = w->TryTargetHeading(GetHeadingFromVector(-diff.x, -diff.z), orderTarget->pos, orderTarget != NULL, orderTarget); edgeFactor = fabs(w->targetBorder); } float diffLength2d = diff.Length2D(); // if w->AttackUnit() returned true then we are already // in range with our biggest weapon so stop moving // also make sure that we're not locked in close-in/in-range state loop // due to rotates invoked by in-range or out-of-range states//.........这里部分代码省略.........
开发者ID:Mocahteam,项目名称:SpringPP,代码行数:101,
注:本文中的GetHeadingFromVector函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ GetHealth函数代码示例 C++ GetHeaderCtrl函数代码示例 |