FlightGear next
AIWingman.hxx
Go to the documentation of this file.
1/*
2 * SPDX-FileName: AIWingman.hxx
3 * SPDX-FileComment: AIBllistic-derived class creates an AI Wingman
4 * SPDX-FileCopyrightText: Written by Vivian Meazza, started February 2008 - vivian.meazza at lineone.net
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8#pragma once
9
10#include <string_view>
11
12#include <simgear/sg_inlines.h>
13
14#include "AIBallistic.hxx"
15#include "AIBase.hxx"
16#include "AIManager.hxx"
17
18
20{
21public:
23 virtual ~FGAIWingman() = default;
24
25 std::string_view getTypeString(void) const override { return "wingman"; }
26 void readFromScenario(SGPropertyNode* scFileNode) override;
27
28 bool init(ModelSearchOrder searchOrder) override;
29 void bind() override;
30 void reinit() override;
31 void update(double dt) override;
32
33private:
34 void formateToAC(double dt);
35 void Break(double dt);
36 void Join(double dt);
37 void Run(double dt);
38
39 double getDistanceToOffset() const;
40 double getElevToOffset() const;
41
42 double calcAngle(double rangeM, SGGeod pos1, SGGeod pos2);
43 double calcDistanceM(SGGeod pos1, SGGeod pos2) const;
44
45 bool _formate_to_ac;
46 bool _break;
47 bool _join;
48
49 double _break_angle; //degrees relative
50 double _coeff_hdg; //dimensionless coefficient
51 double _coeff_pch; //dimensionless coefficient
52 double _coeff_bnk; //dimensionless coefficient
53 double _coeff_spd; //dimensionless coefficient
54
55 SGPropertyNode_ptr user_WoW_node;
56
57 inline void setFormate(bool f);
58 inline void setTgtHdg(double hdg);
59 inline void setTgtSpd(double spd);
60 inline void setBrkHdg(double angle);
61 inline void setBrkAng(double angle);
62 inline void setCoeffHdg(double h);
63 inline void setCoeffPch(double p);
64 inline void setCoeffBnk(double r);
65 inline void setCoeffSpd(double s);
66
67 inline bool getFormate() const { return _formate_to_ac; }
68
69 inline double getTgtHdg() const { return tgt_heading; }
70 inline double getTgtSpd() const { return tgt_speed; }
71 inline double getBrkAng() const { return _break_angle; }
72
73 inline SGVec3d getCartInPos(SGGeod in_pos) const;
74};
75
76void FGAIWingman::setFormate(bool f)
77{
78 _formate_to_ac = f;
79}
80
81void FGAIWingman::setTgtHdg(double h)
82{
83 tgt_heading = h;
84}
85
86void FGAIWingman::setTgtSpd(double s)
87{
88 tgt_speed = s;
89}
90
91void FGAIWingman::setBrkHdg(double a)
92{
93 tgt_heading = hdg + a;
94 SG_NORMALIZE_RANGE(tgt_heading, 0.0, 360.0);
95}
96
97void FGAIWingman::setBrkAng(double a)
98{
99 _break_angle = a;
100 SG_NORMALIZE_RANGE(_break_angle, -180.0, 180.0);
101}
102
103void FGAIWingman::setCoeffHdg(double h)
104{
105 _coeff_hdg = h;
106}
107
108void FGAIWingman::setCoeffPch(double p)
109{
110 _coeff_pch = p;
111}
112
113void FGAIWingman::setCoeffBnk(double b)
114{
115 _coeff_bnk = b;
116}
117
118void FGAIWingman::setCoeffSpd(double s)
119{
120 _coeff_spd = s;
121}
122
123//bool FGAIWingman::getFormate() const {
124// return _formate_to_ac;
125//}
126
127//double FGAIWingman::getTgtHdg() const{
128// return tgt_heading;
129//}
130
131//double FGAIWingman::getTgtSpd() const{
132// return tgt_speed;
133//}
134
135//double FGAIWingman::getBrkAng() const{
136// return _break_angle;
137//}
138
139SGVec3d FGAIWingman::getCartInPos(SGGeod in_pos) const
140{
141 SGVec3d cartPos = SGVec3d::fromGeod(in_pos);
142 return cartPos;
143}
#define p(x)
FGAIBallistic(object_type ot=object_type::otBallistic)
double tgt_heading
Definition AIBase.hxx:229
double hdg
Definition AIBase.hxx:213
double tgt_speed
Definition AIBase.hxx:231
ModelSearchOrder
Definition AIBase.hxx:63
void update(double dt) override
void bind() override
Definition AIWingman.cxx:77
virtual ~FGAIWingman()=default
std::string_view getTypeString(void) const override
Definition AIWingman.hxx:25
bool init(ModelSearchOrder searchOrder) override
void reinit() override
void readFromScenario(SGPropertyNode *scFileNode) override
Definition AIWingman.cxx:47