mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Implement planner option to switch only at required stops
When option is enabled, if a stop is not otherwise required, a gas switch will be delayed until a stop is reached. This option is ignored if the current gas is hypoxic. Signed-off-by: Rick Walsh <rickmwalsh@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
425020d2de
commit
f763da66b3
1 changed files with 36 additions and 12 deletions
48
planner.c
48
planner.c
|
|
@ -876,6 +876,7 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
|
||||||
int gaschangenr;
|
int gaschangenr;
|
||||||
unsigned int *stoplevels = NULL;
|
unsigned int *stoplevels = NULL;
|
||||||
bool stopping = false;
|
bool stopping = false;
|
||||||
|
bool pendinggaschange = false;
|
||||||
bool clear_to_ascend;
|
bool clear_to_ascend;
|
||||||
int clock, previous_point_time;
|
int clock, previous_point_time;
|
||||||
int avg_depth, max_depth, bottom_time = 0;
|
int avg_depth, max_depth, bottom_time = 0;
|
||||||
|
|
@ -1041,7 +1042,7 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
|
||||||
if (depth <= 0)
|
if (depth <= 0)
|
||||||
break; /* We are at the surface */
|
break; /* We are at the surface */
|
||||||
|
|
||||||
if (gi >= 0 && stoplevels[stopidx] == gaschanges[gi].depth) {
|
if (gi >= 0 && stoplevels[stopidx] <= gaschanges[gi].depth) {
|
||||||
/* We have reached a gas change.
|
/* We have reached a gas change.
|
||||||
* Record this in the dive plan */
|
* Record this in the dive plan */
|
||||||
plan_add_segment(diveplan, clock - previous_point_time, depth, gas, po2, false);
|
plan_add_segment(diveplan, clock - previous_point_time, depth, gas, po2, false);
|
||||||
|
|
@ -1049,21 +1050,29 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
|
||||||
stopping = true;
|
stopping = true;
|
||||||
|
|
||||||
/* Check we need to change cylinder.
|
/* Check we need to change cylinder.
|
||||||
* We might not if the cylinder was chosen by the user */
|
* We might not if the cylinder was chosen by the user
|
||||||
|
* or user has selected only to switch only at required stops.
|
||||||
|
* If current gas is hypoxic, we want to switch asap */
|
||||||
if (current_cylinder != gaschanges[gi].gasidx) {
|
if (current_cylinder != gaschanges[gi].gasidx) {
|
||||||
current_cylinder = gaschanges[gi].gasidx;
|
if (!prefs.switch_at_req_stop ||
|
||||||
gas = displayed_dive.cylinder[current_cylinder].gasmix;
|
!trial_ascent(depth, stoplevels[stopidx - 1], avg_depth, bottom_time, tissue_tolerance,
|
||||||
|
&displayed_dive.cylinder[current_cylinder].gasmix, po2, diveplan->surface_pressure / 1000.0) || get_o2(&displayed_dive.cylinder[current_cylinder].gasmix) < 160) {
|
||||||
|
current_cylinder = gaschanges[gi].gasidx;
|
||||||
|
gas = displayed_dive.cylinder[current_cylinder].gasmix;
|
||||||
#if DEBUG_PLAN & 16
|
#if DEBUG_PLAN & 16
|
||||||
printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi].gasidx,
|
printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi].gasidx,
|
||||||
(get_o2(&gas) + 5) / 10, (get_he(&gas) + 5) / 10, gaschanges[gi].depth / 1000.0);
|
(get_o2(&gas) + 5) / 10, (get_he(&gas) + 5) / 10, gaschanges[gi].depth / 1000.0);
|
||||||
#endif
|
#endif
|
||||||
/* Stop for the minimum duration to switch gas */
|
/* Stop for the minimum duration to switch gas */
|
||||||
tissue_tolerance = add_segment(depth_to_mbar(depth, &displayed_dive) / 1000.0,
|
tissue_tolerance = add_segment(depth_to_mbar(depth, &displayed_dive) / 1000.0,
|
||||||
&displayed_dive.cylinder[current_cylinder].gasmix,
|
&displayed_dive.cylinder[current_cylinder].gasmix,
|
||||||
prefs.min_switch_duration, po2, &displayed_dive, prefs.decosac);
|
prefs.min_switch_duration, po2, &displayed_dive, prefs.decosac);
|
||||||
clock += prefs.min_switch_duration;
|
clock += prefs.min_switch_duration;
|
||||||
}
|
} else {
|
||||||
|
pendinggaschange = true;
|
||||||
|
}
|
||||||
gi--;
|
gi--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
--stopidx;
|
--stopidx;
|
||||||
|
|
@ -1085,6 +1094,21 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
|
||||||
stopping = true;
|
stopping = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pendinggaschange) {
|
||||||
|
current_cylinder = gaschanges[gi + 1].gasidx;
|
||||||
|
gas = displayed_dive.cylinder[current_cylinder].gasmix;
|
||||||
|
#if DEBUG_PLAN & 16
|
||||||
|
printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi + 1].gasidx,
|
||||||
|
(get_o2(&gas) + 5) / 10, (get_he(&gas) + 5) / 10, gaschanges[gi + 1].depth / 1000.0);
|
||||||
|
#endif
|
||||||
|
/* Stop for the minimum duration to switch gas */
|
||||||
|
tissue_tolerance = add_segment(depth_to_mbar(depth, &displayed_dive) / 1000.0,
|
||||||
|
&displayed_dive.cylinder[current_cylinder].gasmix,
|
||||||
|
prefs.min_switch_duration, po2, &displayed_dive, prefs.decosac);
|
||||||
|
clock += prefs.min_switch_duration;
|
||||||
|
pendinggaschange = false;
|
||||||
|
}
|
||||||
|
|
||||||
/* Deco stop should end when runtime is at a whole minute */
|
/* Deco stop should end when runtime is at a whole minute */
|
||||||
int this_decotimestep;
|
int this_decotimestep;
|
||||||
this_decotimestep = DECOTIMESTEP - clock % DECOTIMESTEP;
|
this_decotimestep = DECOTIMESTEP - clock % DECOTIMESTEP;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue