Skip to content

Commit

Permalink
Updated routes to fly GOTO instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Skipper-is committed Nov 16, 2023
1 parent 79f1be1 commit 1246b9a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 12 deletions.
34 changes: 32 additions & 2 deletions src/autopilot/fsautopilot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3216,7 +3216,7 @@ YSRESULT FsGotoPosition::ApplyControl(FsAirplane &air,FsSimulation *sim,const do
return YSOK;
}

YSBOOL FsGotoPosition::MissionAccomplished(FsAirplane &air,FsSimulation *) const
YSBOOL FsGotoPosition::MissionAccomplished(FsAirplane &air,FsSimulation *sim) const
{
if(destinationIdx==destination.GetN()-1)
{
Expand All @@ -3225,7 +3225,20 @@ YSBOOL FsGotoPosition::MissionAccomplished(FsAirplane &air,FsSimulation *) const
dz=destination.GetEnd().z()-air.GetPosition().z();
if(dx*dx+dz*dz<100.0*100.0) // If it comes to 80m radius, the index will be reset to zero.
{
printf("Mission Accomplished\n");
FsAirplane *airPtr;
airPtr = NULL;
while (NULL!=(airPtr=sim->FindNextAirplane(airPtr)))
{
printf("airPtr->airFlag=%d\n",airPtr->airFlag);
if(airPtr->airFlag&FSAIRFLAG_AUTOGENERATED){
printf("Mission Accomplished\n");

airPtr->Prop().SetFlightState(FSDEAD,FSDIEDOF_NULL);
}
}
return YSTRUE;

}
}
return YSFALSE;
Expand Down Expand Up @@ -6646,6 +6659,8 @@ YSRESULT FsAirRouteAutopilot::MakeDecision(FsAirplane &air,FsSimulation *sim,con
{
AIRROUTE_STATE prevState=state;

flareDispenser.MakeDecision(air,sim,dt);

// printf("Flying To: %s Occupying: %s State: %d\n",CurrentSegmentLabel(),occupyingSegLabel.Txt(),state);

switch(state)
Expand Down Expand Up @@ -6946,6 +6961,7 @@ YSRESULT FsAirRouteAutopilot::MakeDecision(FsAirplane &air,FsSimulation *sim,con

YSRESULT FsAirRouteAutopilot::ApplyControl(FsAirplane &air,FsSimulation *sim,const double &dt)
{
flareDispenser.ApplyControl(air,sim,dt);
air.Prop().NeutralDirectAttitudeControl();

#ifdef CRASHINVESTIGATION_AIRROUTE
Expand Down Expand Up @@ -7675,7 +7691,7 @@ YSRESULT FsAirRouteAutopilot::SetUpDepartureFromAircraftCarrier(const FsAirplane
return YSERR;
}

void FsAirRouteAutopilot::IncrementRouteIndexForDeparture(const FsAirplane &air,const FsSimulation *)
void FsAirRouteAutopilot::IncrementRouteIndexForDeparture(const FsAirplane &air,const FsSimulation *sim)
{
// Don't rely on occupyingSegIdx. It may be cleared before departure.
if(YSTRUE==airRouteCache->routeSequence.IsInRange(airRouteIdx))
Expand All @@ -7698,7 +7714,21 @@ void FsAirRouteAutopilot::IncrementRouteIndexForDeparture(const FsAirplane &air,
if(rgnArray[rgnIdx]->GetId()==FS_RGNID_AIRPORT_AREA &&
0==strcmp(rgnArray[rgnIdx]->GetTag(),airRouteCache->routeSequence[airRouteIdx].label))
{
int prevAirRouteIdx=airRouteIdx;
airRouteIdx=(airRouteIdx+1)%airRouteCache->routeSequence.GetN();

if (airRouteIdx <= prevAirRouteIdx) {
FsAirplane *airPtr;
airPtr = NULL;
while (NULL!=(airPtr=sim->FindNextAirplane(airPtr)))
{
if(airPtr->airFlag&FSAIRFLAG_AUTOGENERATED){
airPtr->Prop().SetFlightState(FSDEAD,FSDIEDOF_NULL);
}
}
}


return;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/autopilot/fsautopilot.h
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ class FsAirRouteAutopilot : public FsAutopilot
private:
AIRROUTE_STATE state;
double sameStateTimer;
AutoFlareDispenser flareDispenser;

int airRouteIdx;
YsVec3 legStart;
Expand Down
8 changes: 7 additions & 1 deletion src/core/fsnetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1427,8 +1427,14 @@ YSRESULT FsSocketServer::StartVIPMission(int clientId,unsigned char dat[],unsign
route=(char *)ptr;
ptr+=32;

int usersOnline=0;
for(int i=0;i<FS_MAX_NUM_USER;i++){
if(user[i].state==FSUSERSTATE_LOGGEDON){
usersOnline++;
}
}

sim->GenerateAIAirplane(YsVec3(41061,1,-18615),YsAtt3(),"AIRBUS320","EUROFIGHTER_TYPHOON","MOLOKAI-KONA-VIP",FS_IFF1);
sim->GenerateAIAirplane(YsVec3(41061,1,-18615),YsAtt3(),"AIRBUS320","EUROFIGHTER_TYPHOON","MOLOKAI-KONA-VIP",FS_IFF1, usersOnline);

return YSOK;
}
Expand Down
24 changes: 17 additions & 7 deletions src/core/fssimulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3379,7 +3379,7 @@ void FsSimulation::GenerateFriendlyAirplane(FsInterceptMissionInfo &info)
}

void FsSimulation::GenerateAIAirplane(YsVec3 pos, YsAtt3 atti,
const char vipAircraft[], const char escorts[],YsString airRoute, FSIFF iff)
const char vipAircraft[], const char escorts[],YsString airRoute, FSIFF iff, const int usersOnline)
{
FsAirplane *vip;
vip = world->AddAirplane((char*)vipAircraft, YSFALSE);
Expand All @@ -3388,7 +3388,7 @@ void FsSimulation::GenerateAIAirplane(YsVec3 pos, YsAtt3 atti,
return;
}
vip->SendCommand("INITFUEL 30%");
vip->airFlag=FSAIRFLAG_INDEPENDENT;
vip->airFlag=FSAIRFLAG_INDEPENDENT | FSAIRFLAG_AUTOGENERATED;
YsVec3 vel;

vel.Set(0.0,.0,0.0);
Expand All @@ -3398,10 +3398,19 @@ void FsSimulation::GenerateAIAirplane(YsVec3 pos, YsAtt3 atti,
vip->iff=iff;
vip->name.Set(YsString("VIP"));
vip->Prop().SetDamageTolerance(1000);
FsAirRouteAutopilot *ap;
ap = FsAirRouteAutopilot::Create();
ap->SetAirRouteTag(airRoute);
// FsAirRouteAutopilot *ap;
// ap = FsAirRouteAutopilot::Create();
// ap->SetAirRouteTag(airRoute);
// vip->SetAutopilot(ap);
YsVec3 pos2;
pos2.Set(52194.0, 1000, -5077.60);
FsGotoPosition *ap;
ap = FsGotoPosition::Create();
ap->SetSingleDestination(pos2);
vip->SetAutopilot(ap);
ap = FsGotoPosition::Create();
ap->SetSingleDestination(pos);
vip->AddAutoPilot(ap);
if(netServer!=NULL){
netServer->BroadcastAddAirplane(vip, FSNET_REMOTE);
}
Expand Down Expand Up @@ -3434,9 +3443,10 @@ void FsSimulation::GenerateAIAirplane(YsVec3 pos, YsAtt3 atti,
for(auto &cmd : reloadCommand)
{
neo2->SendCommand(cmd);
printf(cmd);
}

neo2->airFlag=FSAIRFLAG_INDEPENDENT;
neo2->airFlag=FSAIRFLAG_INDEPENDENT | FSAIRFLAG_AUTOGENERATED;

YsVec3 vel=-diff;
vel.Normalize();
Expand All @@ -3449,7 +3459,7 @@ void FsSimulation::GenerateAIAirplane(YsVec3 pos, YsAtt3 atti,

FsDogfight *df;
df=FsDogfight::Create();
df->gLimit=20.0; //Because UV wants our pilots to have an aneurysm
df->gLimit=8; //Because UV wants our pilots to have an aneurysm
df->minAlt=333.0;
neo2->SetAutopilot(df);
if (netServer != NULL) {
Expand Down
7 changes: 5 additions & 2 deletions src/core/fssimulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,9 @@ class FsSimulation : public FsHasInFlightDialog
int nEnemy,const class FsMissionEnemyGroundAttackerInfo &info,const double &iniDistFixedWing,const double &iniDistRotorWing,
YSBOOL reducedAttackDist,const double initialSpeed);
void GenerateFriendlyAirplane(FsInterceptMissionInfo &info);
void GenerateAIAirplane(YsVec3 pos,YsAtt3 atti, const char vipAircraft[], const char escorts[], YsString airRoute, FSIFF iff);
void GenerateAIAirplane
(YsVec3 pos,YsAtt3 atti, const char vipAircraft[],
const char escorts[], YsString airRoute, FSIFF iff, const int usersOnline);
void GenerateTank
(int nTank,FsCloseAirSupportMissionInfo &info,
YSBOOL mobile,YSBOOL incremental,YSBOOL primaryTarget,
Expand Down Expand Up @@ -998,6 +1000,7 @@ class FsSimulation : public FsHasInFlightDialog
YSBOOL IsLockedOn(const FsExistence *ex, YSBOOL missileLockOnly = YSFALSE) const;
YSBOOL IsMissileChasing(FSWEAPONTYPE &wpnType,YsVec3 &wpnPos,const FsExistence *ex) const;
FsWeapon* GetLockedOn(const FsExistence* ex) const;
YSRESULT DestroyAutoGeneratedAirAndGnd(void);

protected:
YSBOOL AllRecordedFlightsAreOver(double &lastRecordTime);
Expand All @@ -1009,7 +1012,7 @@ class FsSimulation : public FsHasInFlightDialog
void UpdateViewpointAccordingToPlayerAirplane(const double &distance,YSBOOL reset);

void AirplaneCrash(FsAirplane *crashedPlane,FSDIEDOF diedOf,int collType); // collType 1:Ground 2:Shell
YSRESULT DestroyAutoGeneratedAirAndGnd(void);


YSBOOL CheckContinue(void);
YSBOOL CheckContinueOneStep(void);
Expand Down

0 comments on commit 1246b9a

Please sign in to comment.