TaskAdvanceSmart: include cleanup
[xcsoar.git] / src / Engine / Task / Ordered / TaskAdvanceSmart.cpp
blob8471194ffed3c8990b2e45dd494b410d01edf3a7
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "TaskAdvanceSmart.hpp"
24 #include "Task/Points/TaskPoint.hpp"
25 #include "Points/StartPoint.hpp"
26 #include "Points/AATPoint.hpp"
27 #include "Points/IntermediatePoint.hpp"
28 #include "Task/Factory/TaskFactoryConstraints.hpp"
30 TaskAdvanceSmart::TaskAdvanceSmart()
31 :state(TaskAdvance::MANUAL),
32 start_requires_arm(false)
36 void
37 TaskAdvanceSmart::SetFactoryConstraints(const TaskFactoryConstraints &constraints)
39 start_requires_arm = constraints.start_requires_arm;
42 bool
43 TaskAdvanceSmart::CheckReadyToAdvance(const TaskPoint &tp,
44 const AircraftState &aircraft,
45 const bool x_enter, const bool x_exit)
47 const bool state_ready = IsStateReady(tp, aircraft, x_enter, x_exit);
49 if (armed)
50 request_armed = false;
52 if (tp.GetType() == TaskPointType::START) {
53 const StartPoint &sp = (const StartPoint &)tp;
54 if (start_requires_arm) {
55 if (armed) {
56 state = TaskAdvance::START_ARMED;
57 } else {
58 state = TaskAdvance::START_DISARMED;
59 if (sp.IsInSector(aircraft))
60 request_armed = true;
62 return armed && state_ready;
63 } else {
64 state = TaskAdvance::AUTO;
65 return state_ready;
67 } else if (tp.GetType() == TaskPointType::AAT) {
68 if (armed) {
69 state = TaskAdvance::TURN_ARMED;
70 } else {
71 state = TaskAdvance::TURN_DISARMED;
72 if (state_ready)
73 request_armed = true;
75 return armed && state_ready;
76 } else if (tp.IsIntermediatePoint()) {
77 state = TaskAdvance::AUTO;
78 return state_ready;
81 return false;
84 TaskAdvance::State
85 TaskAdvanceSmart::GetState() const
87 return state;
90 void
91 TaskAdvanceSmart::UpdateState()
93 switch (state) {
94 case TaskAdvance::START_ARMED:
95 if (!armed)
96 state = TaskAdvance::START_DISARMED;
98 return;
99 case TaskAdvance::START_DISARMED:
100 if (armed)
101 state = TaskAdvance::START_ARMED;
103 return;
104 case TaskAdvance::TURN_ARMED:
105 if (!armed)
106 state = TaskAdvance::TURN_DISARMED;
108 return;
109 case TaskAdvance::TURN_DISARMED:
110 if (armed)
111 state = TaskAdvance::TURN_ARMED;
113 return;
114 default:
115 break;