Subversion Repositories svn1

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 root 1
/*************************************************************************
2
*           Copyright (C) 1995 Embedded Solutions
3
*                       All rights reserved
4
*
5
* file:     src\check.c
6
*
7
* purpose:  This module provides routines that are used to test the team's
8
*           times.
9
*
10
*
11
* functions
12
*       test_times              - Recalculate team time information
13
*       set_times               - Calc start times for each leg
14
*
15
* programmer: David Purdie
16
*
17
* revision  date        by      reason
18
*           ??/05/90    MV      Modified May 1990 by Margherita Veroni
19
*   00.0    27/01/95    DDP     Tidies up the program and formatted the file
20
*
21
**************************************************************************/
22
#include    <stdlib.h>
23
 
24
#include    "consts.h"
25
#include    "structs.h"
26
#include    "proto.h"
27
 
28
/* Internal declarations and definitions */
29
 
30
int         parallel_legs = FALSE;               /* Legs run in Parallel */
31
ty_check_error check_error;
32
 
33
/*========================================================================
34
 *
35
 *  Recalculate team time information
36
 *
37
 *  Purpose:
38
 *      This routine will examine the team entry and :-
56 - 39
 *      Calculate the elapsed times for each leg
1 root 40
 *      Calculate the elapsed time for the team
41
 *      Flag any inconsistencies in the data
42
 *          In consistencies are :-
43
 *          No start time
44
 *          No end time
45
 *          End before start
46
 *          Times without team data
47
 *
48
 *
49
 *  Parameters:
50
 *      data            address of the data buffer
51
 *      upto_leg;       Examine upto and including this leg
52
 *
53
 *  Returns:
54
 *      The function returns the bad_times flag
55
 *
56
 *========================================================================*/
57
 
58
bool test_times( team_type * data, int upto_leg )
59
{
60
    int         i;                               /* One of those loopy things */
61
    time_t      t;                               /* Used for time calcs */
62
    leg_type   *use;                             /* pointer to leg entry */
63
 
64
    if( upto_leg == 0 )
65
        upto_leg = config.num_legs;              /* Test all legs */
66
 
67
    data->flags.bad_times = FALSE;               /* Set times ok */
68
    check_error.leg = check_error.type = 0;
69
 
70
    if( !data->flags.valid )
71
    {
72
        for( i = 0; i < upto_leg; i++ )
73
            if( data->leg[i + 1].end >= 0 )
74
            {
75
                check_error.type = 4;            /* Flag error */
76
                check_error.leg = i;
77
                data->flags.bad_times = TRUE;
78
                t = ( time_t ) - 1;
79
            }
80
    }
81
    else
82
    {
83
        for( i = 0, t = 0; i < upto_leg; i++ )
84
        {
85
            use = &data->leg[i + 1];             /* Pointer to leg data */
86
            if( ( use->start >= 0 )
87
                && ( use->end >= 0 ) && ( use->end > use->start ) )
88
                t += use->elapsed = use->end - use->start;
89
            else
90
            {
91
                use->elapsed = ( time_t ) - 1;
92
                data->flags.bad_times = TRUE;
93
                if( !check_error.leg )
94
                {
95
                    check_error.leg = i + 1;
96
                    check_error.type++;
97
                    if( use->start < 0 )
98
                        continue;
99
                    check_error.type++;
100
                    if( use->end < 0 )
101
                        continue;
102
                    check_error.type++;
103
                }
104
            }
105
        }
106
    }
107
 
108
    data->leg[0].elapsed = t;                    /* total elapsed so far */
109
    data->leg[0].start = data->leg[1].start;     /* Team start */
110
    data->leg[0].end = data->leg[upto_leg].end;  /* Team end */
111
    return ( data->flags.bad_times );
112
}
113
 
114
/*========================================================================
115
 *
116
 *  Calc start times for each leg
117
 *
118
 *  Purpose:
119
 *      This routine will calculate the start times for each leg of the event
120
 *      where the start time has not been manually entered.
121
 *
122
 *      The routine will allow for  two types of start-time calculations
123
 *          1) End of previous leg = Start of leg.
124
 *          2) Legs run in parallel ( No calcs to do )
125
 *      These are controlled on a global scale
126
 *
127
 *      Note : Break in time caused by the specials for the start of a leg
128
 *
129
 *  Parameters:
130
 *      data        Address of the team data
131
 *
132
 *  Returns:
133
 *      Nothing
134
 *
135
 *========================================================================*/
136
 
137
void set_times( team_type * data )
138
{
139
    int         i;
140
 
141
    if( !parallel_legs )
142
    {
143
        for( i = 2; i <= config.num_legs; i++ )
144
        {
145
            if( data->leg[i].manual )
146
                continue;                        /* Skip manually entered leg start */
147
 
148
            if( data->leg[i - 1].end >= 0 )
149
                data->leg[i].start = data->leg[i - 1].end;
150
            else
151
                data->leg[i].start = ( time_t ) - 1;
152
 
153
            if( invalid_copy )
154
                data->leg[i].start += rand() % 600;
155
        }
156
    }
157
}
158
 
159
/********************************* EOF ***********************************/