Subversion Repositories svn1-original

Rev

Rev 245 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
95 - 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 :-
39
 *      Calculate the elapsed times for each leg
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
244 - 47
 *          NE team with a named NE competitor
95 - 48
 *
49
 *
50
 *  Parameters:
51
 *      data            address of the data buffer
52
 *      upto_leg;       Examine upto and including this leg
53
 *
54
 *  Returns:
55
 *      The function returns the bad_times flag
56
 *
57
 *========================================================================*/
58
 
59
bool test_times( team_type * data, int upto_leg )
60
{
61
    int         i;                               /* One of those loopy things */
62
    time_t      t;                               /* Used for time calcs */
63
    leg_type   *use;                             /* pointer to leg entry */
64
 
65
    if( upto_leg == 0 )
66
        upto_leg = config.num_legs;              /* Test all legs */
67
 
68
    data->flags.bad_times = FALSE;               /* Set times ok */
69
    check_error.leg = check_error.type = 0;
70
 
71
    if( !data->flags.valid )
72
    {
244 - 73
        /*
74
        ** Test for invalid team with time information present
75
        */
95 - 76
        for( i = 0; i < upto_leg; i++ )
77
            if( data->leg[i + 1].end >= 0 )
78
            {
79
                check_error.type = 4;            /* Flag error */
80
                check_error.leg = i;
81
                data->flags.bad_times = TRUE;
82
                t = ( time_t ) - 1;
83
            }
84
    }
85
    else
86
    {
87
        for( i = 0, t = 0; i < upto_leg; i++ )
88
        {
89
            use = &data->leg[i + 1];             /* Pointer to leg data */
244 - 90
 
91
            // Is this the NE leg ?
92
            // If NE then
93
            //      If we have a competitor name - warn
94
            //      Don't add in time
95
            if ( i + 1 == config.equestrian_leg && data->flags.non_equestrian   )
96
            {
97
                if ( data->members[i].name[0] && use->end >= 0)
98
                {
99
                    if( !check_error.leg )
100
                    {
101
                        check_error.leg = i + 1;
102
                        check_error.type = 5;
103
                    }
104
                }
245 - 105
                use->elapsed = -1;
244 - 106
                continue;
107
            }
108
 
109
 
110
            // Have a start and  end time
111
            // Calculate the elapsed time
112
            if( ( use->start >= 0 ) && ( use->end >= 0 ) && ( use->end > use->start ) )
113
            {
95 - 114
                t += use->elapsed = use->end - use->start;
244 - 115
            }
95 - 116
            else
117
            {
244 - 118
                // Determine error
95 - 119
                use->elapsed = ( time_t ) - 1;
120
                data->flags.bad_times = TRUE;
121
                if( !check_error.leg )
122
                {
123
                    check_error.leg = i + 1;
244 - 124
                    check_error.type = 1;
95 - 125
                    if( use->start < 0 )
126
                        continue;
244 - 127
                    check_error.type = 2;
95 - 128
                    if( use->end < 0 )
129
                        continue;
244 - 130
                    check_error.type = 3;
95 - 131
                }
132
            }
133
        }
134
    }
135
    data->leg[0].elapsed = t;                    /* total elapsed so far */
136
    data->leg[0].start = data->leg[1].start;     /* Team start */
137
    data->leg[0].end = data->leg[upto_leg].end;  /* Team end */
244 - 138
    return ( data->flags.bad_times );            /* Flag errors, not warnings */
95 - 139
}
140
 
141
/*========================================================================
142
 *
143
 *  Calc start times for each leg
144
 *
145
 *  Purpose:
146
 *      This routine will calculate the start times for each leg of the event
147
 *      where the start time has not been manually entered.
148
 *
149
 *      The routine will allow for  two types of start-time calculations
150
 *          1) End of previous leg = Start of leg.
151
 *          2) Legs run in parallel ( No calcs to do )
152
 *      These are controlled on a global scale
153
 *
154
 *      Note : Break in time caused by the specials for the start of a leg
155
 *
156
 *  Parameters:
157
 *      data        Address of the team data
158
 *
159
 *  Returns:
160
 *      Nothing
161
 *
162
 *========================================================================*/
163
 
164
void set_times( team_type * data )
165
{
166
    int         i;
167
 
168
    if( !parallel_legs )
169
    {
170
        for( i = 2; i <= config.num_legs; i++ )
171
        {
172
            if( data->leg[i].manual )
173
                continue;                        /* Skip manually entered leg start */
174
 
175
            if( data->leg[i - 1].end >= 0 )
176
                data->leg[i].start = data->leg[i - 1].end;
177
            else
178
                data->leg[i].start = ( time_t ) - 1;
179
        }
180
    }
181
}
182
 
183
/********************************* EOF ***********************************/