diff options
author | Robert C. Helling <helling@atdotde.de> | 2015-04-04 18:38:56 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-04-04 10:21:40 -0700 |
commit | e03c5ce8e9c587fce40679184762c6c5d6935623 (patch) | |
tree | f27882d4bad6ab8bbe4b89a17a04ca240c63940d /planner.c | |
parent | acaedee159abfc0121e7a9997d3e7a4ae24e8933 (diff) | |
download | subsurface-e03c5ce8e9c587fce40679184762c6c5d6935623.tar.gz |
Take gas consumption into account for recreational mode
If there is valid gas information (cylinder size and starting pressure),
also ascent before gas runs out (taking a 40bar reserve into account).
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r-- | planner.c | 34 |
1 files changed, 32 insertions, 2 deletions
@@ -17,6 +17,8 @@ #define TIMESTEP 3 /* second */ #define DECOTIMESTEP 60 /* seconds. Unit of deco stop times */ +#define RESERVE 40000 /* Remaining gas in recreational mode */ + int decostoplevels[] = { 0, 3000, 6000, 9000, 12000, 15000, 18000, 21000, 24000, 27000, 30000, 33000, 36000, 39000, 42000, 45000, 48000, 51000, 54000, 57000, 60000, 63000, 66000, 69000, 72000, 75000, 78000, 81000, 84000, 87000, @@ -800,6 +802,17 @@ int ascend_velocity(int depth, int avg_depth, int bottom_time) } } +void track_ascent_gas(int depth, cylinder_t *cylinder, int avg_depth, int bottom_time) +{ + while (depth > 0) { + int deltad = ascend_velocity(depth, avg_depth, bottom_time) * TIMESTEP; + if (deltad > depth) + deltad = depth; + update_cylinder_pressure(&displayed_dive, depth, depth - deltad, TIMESTEP, prefs.bottomsac, cylinder, true); + depth -= deltad; + } +} + bool trial_ascent(int trial_depth, int stoplevel, int avg_depth, int bottom_time, double tissue_tolerance, struct gasmix *gasmix, int po2, double surface_pressure) { @@ -825,6 +838,20 @@ bool trial_ascent(int trial_depth, int stoplevel, int avg_depth, int bottom_time return clear_to_ascend; } +bool enough_gas(int current_cylinder) +{ + cylinder_t *cyl; + + cyl = &displayed_dive.cylinder[current_cylinder]; + + if (!cyl->start.mbar) + return true; + if (cyl->type.size.mliter) + return (float) (cyl->end.mbar - RESERVE) * cyl->type.size.mliter / 1000.0 > (float) cyl->deco_gas_used.mliter; + else + return true; +} + int plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool show_disclaimer) { struct sample *sample; @@ -906,16 +933,19 @@ int plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool s gi = gaschangenr - 1; if(prefs.recreational_mode) { bool safety_stop = prefs.safetystop && max_depth >= 10000; + track_ascent_gas(depth, &displayed_dive.cylinder[current_cylinder], avg_depth, bottom_time); // How long can we stay at the current depth and still directly ascent to the surface? while (trial_ascent(depth, 0, avg_depth, bottom_time, tissue_tolerance, &displayed_dive.cylinder[current_cylinder].gasmix, - po2, diveplan->surface_pressure / 1000.0)) { + po2, diveplan->surface_pressure / 1000.0) && + enough_gas(current_cylinder)) { tissue_tolerance = add_segment(depth_to_mbar(depth, &displayed_dive) / 1000.0, &displayed_dive.cylinder[current_cylinder].gasmix, DECOTIMESTEP, po2, &displayed_dive, prefs.bottomsac); + update_cylinder_pressure(&displayed_dive, depth, depth, DECOTIMESTEP, prefs.bottomsac, &displayed_dive.cylinder[current_cylinder], false); clock += DECOTIMESTEP; } clock -= DECOTIMESTEP; - plan_add_segment(diveplan, clock - previous_point_time, depth, gas, po2, false); + plan_add_segment(diveplan, clock - previous_point_time, depth, gas, po2, true); previous_point_time = clock; do { /* Ascend to surface */ |