Subversion Repositories svn1-original

Rev

Rev 381 | 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
            {
280 david 97
                // This error is now detected by the caller
98
                //if ( data->members[i].name[0] && use->end >= 0)
99
                //{
100
                //    if( !check_error.leg )
101
                //    {
102
                //        check_error.leg = i + 1;
103
                //        check_error.type = 5;
104
                //    }
105
                //}
245 - 106
                use->elapsed = -1;
244 - 107
                continue;
108
            }
109
 
110
 
111
            // Have a start and  end time
112
            // Calculate the elapsed time
113
            if( ( use->start >= 0 ) && ( use->end >= 0 ) && ( use->end > use->start ) )
114
            {
95 - 115
                t += use->elapsed = use->end - use->start;
244 - 116
            }
95 - 117
            else
118
            {
244 - 119
                // Determine error
95 - 120
                use->elapsed = ( time_t ) - 1;
121
                data->flags.bad_times = TRUE;
122
                if( !check_error.leg )
123
                {
124
                    check_error.leg = i + 1;
244 - 125
                    check_error.type = 1;
95 - 126
                    if( use->start < 0 )
127
                        continue;
244 - 128
                    check_error.type = 2;
95 - 129
                    if( use->end < 0 )
130
                        continue;
244 - 131
                    check_error.type = 3;
95 - 132
                }
133
            }
134
        }
135
    }
136
    data->leg[0].elapsed = t;                    /* total elapsed so far */
137
    data->leg[0].start = data->leg[1].start;     /* Team start */
138
    data->leg[0].end = data->leg[upto_leg].end;  /* Team end */
244 - 139
    return ( data->flags.bad_times );            /* Flag errors, not warnings */
95 - 140
}
141
 
142
/*========================================================================
143
 *
144
 *  Calc start times for each leg
145
 *
146
 *  Purpose:
147
 *      This routine will calculate the start times for each leg of the event
148
 *      where the start time has not been manually entered.
149
 *
150
 *      The routine will allow for  two types of start-time calculations
151
 *          1) End of previous leg = Start of leg.
152
 *          2) Legs run in parallel ( No calcs to do )
153
 *      These are controlled on a global scale
154
 *
155
 *      Note : Break in time caused by the specials for the start of a leg
156
 *
157
 *  Parameters:
158
 *      data        Address of the team data
159
 *
160
 *  Returns:
161
 *      Nothing
162
 *
163
 *========================================================================*/
164
 
165
void set_times( team_type * data )
166
{
167
    int         i;
168
 
169
    if( !parallel_legs )
170
    {
171
        for( i = 2; i <= config.num_legs; i++ )
172
        {
173
            if( data->leg[i].manual )
174
                continue;                        /* Skip manually entered leg start */
175
 
176
            if( data->leg[i - 1].end >= 0 )
177
                data->leg[i].start = data->leg[i - 1].end;
178
            else
179
                data->leg[i].start = ( time_t ) - 1;
180
        }
181
    }
182
}
183
 
184
/********************************* EOF ***********************************/