/************************************************************************* * Copyright (C) 1995 Embedded Solutions * All rights reserved * * file: src\check.c * * purpose: This module provides routines that are used to test the team's * times. * * * functions * test_times - Recalculate team time information * set_times - Calc start times for each leg * * programmer: David Purdie * * revision date by reason * ??/05/90 MV Modified May 1990 by Margherita Veroni * 00.0 27/01/95 DDP Tidies up the program and formatted the file * **************************************************************************/ #include #include "consts.h" #include "structs.h" #include "proto.h" /* Internal declarations and definitions */ int parallel_legs = FALSE; /* Legs run in Parallel */ ty_check_error check_error; /*======================================================================== * * Recalculate team time information * * Purpose: * This routine will examine the team entry and :- * Claculate the elapsed times for each leg * Calculate the elapsed time for the team * Flag any inconsistencies in the data * In consistencies are :- * No start time * No end time * End before start * Times without team data * * * Parameters: * data address of the data buffer * upto_leg; Examine upto and including this leg * * Returns: * The function returns the bad_times flag * *========================================================================*/ bool test_times( team_type * data, int upto_leg ) { int i; /* One of those loopy things */ time_t t; /* Used for time calcs */ leg_type *use; /* pointer to leg entry */ if( upto_leg == 0 ) upto_leg = config.num_legs; /* Test all legs */ data->flags.bad_times = FALSE; /* Set times ok */ check_error.leg = check_error.type = 0; if( !data->flags.valid ) { for( i = 0; i < upto_leg; i++ ) if( data->leg[i + 1].end >= 0 ) { check_error.type = 4; /* Flag error */ check_error.leg = i; data->flags.bad_times = TRUE; t = ( time_t ) - 1; } } else { for( i = 0, t = 0; i < upto_leg; i++ ) { use = &data->leg[i + 1]; /* Pointer to leg data */ if( ( use->start >= 0 ) && ( use->end >= 0 ) && ( use->end > use->start ) ) t += use->elapsed = use->end - use->start; else { use->elapsed = ( time_t ) - 1; data->flags.bad_times = TRUE; if( !check_error.leg ) { check_error.leg = i + 1; check_error.type++; if( use->start < 0 ) continue; check_error.type++; if( use->end < 0 ) continue; check_error.type++; } } } } data->leg[0].elapsed = t; /* total elapsed so far */ data->leg[0].start = data->leg[1].start; /* Team start */ data->leg[0].end = data->leg[upto_leg].end; /* Team end */ return ( data->flags.bad_times ); } /*======================================================================== * * Calc start times for each leg * * Purpose: * This routine will calculate the start times for each leg of the event * where the start time has not been manually entered. * * The routine will allow for two types of start-time calculations * 1) End of previous leg = Start of leg. * 2) Legs run in parallel ( No calcs to do ) * These are controlled on a global scale * * Note : Break in time caused by the specials for the start of a leg * * Parameters: * data Address of the team data * * Returns: * Nothing * *========================================================================*/ void set_times( team_type * data ) { int i; if( !parallel_legs ) { for( i = 2; i <= config.num_legs; i++ ) { if( data->leg[i].manual ) continue; /* Skip manually entered leg start */ if( data->leg[i - 1].end >= 0 ) data->leg[i].start = data->leg[i - 1].end; else data->leg[i].start = ( time_t ) - 1; if( invalid_copy ) data->leg[i].start += rand() % 600; } } } /********************************* EOF ***********************************/