From 954d40148390a45b0a6f5178dfbdbc273dae315d Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Tue, 8 Jul 2014 21:42:17 +0200 Subject: [PATCH] Considering previous dives for tissue loading This (hopefully) gets the logic to find dives in the previous 48h for tissue pre-loading right. In particular it handles the case of a planned dive which has a number of -1. Signed-off-by: Robert C. Helling Signed-off-by: Dirk Hohndel --- divelist.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/divelist.c b/divelist.c index 632b7703c..1a2111f76 100644 --- a/divelist.c +++ b/divelist.c @@ -365,7 +365,13 @@ double init_decompression(struct dive *dive) divenr = get_divenr(dive); when = dive->when; i = divenr; - while (i && --i) { + if (i < 0) { + i = dive_table.nr - 1; + while (i >= 0 && get_dive(i)->when > when) + --i; + i++; + } + while (i--) { struct dive *pdive = get_dive(i); /* we don't want to mix dives from different trips as we keep looking * for how far back we need to go */ @@ -376,7 +382,7 @@ double init_decompression(struct dive *dive) when = pdive->when; lasttime = when + pdive->duration.seconds; } - while (++i < divenr) { + while (++i < (divenr >= 0 ? divenr : dive_table.nr)) { struct dive *pdive = get_dive(i); /* again skip dives from different trips */ if (dive->divetrip && dive->divetrip != pdive->divetrip)