-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar.cpp
114 lines (108 loc) · 1.96 KB
/
car.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* car.cpp
*
* Created on: 8.5.2014
* Author: Atte
*/
#include "car.h"
#include <string>
Car::Car(unsigned int id, Ferry* ferry_h, TrafficLight* traffic_light_h,
RouteManager* routemanager_h)
: car_id(id), ferry(ferry_h),
traffic_light(traffic_light_h),
routemanager(routemanager_h), route()
{
routemanager->GetRoute( &route );
pos_route = 0;
pos_block = 0;
char start;
switch (route.at(0))
{
case BLOCK_A:
{
start = 'A';
break;
}
case BLOCK_B:
{
start = 'B';
break;
}
default:
break;
}
char end;
switch (route.at(route.size()-1))
{
case BLOCK_C:
{
end = 'C';
break;
}
case BLOCK_D:
{
end = 'D';
break;
}
default:
break;
}
mycerr("Auto luotu %i, reitti %c->%c\n", car_id, start, end);
}
Car::~Car()
{
}
void Car::Execute()
{
while(!Terminated)
{
heartbeat.WaitSignal();
//take the block and act on it
if( pos_block < TICKS_PER_BLOCK )
{
pos_block++;
continue;
}
pos_block = 0;
pos_route++;
//move the car to new routeblock
switch (route.at(pos_route))
{
case BLOCK_A:
case BLOCK_B:
case BLOCK_ROAD:
case BLOCK_L:
{
//do nothing
break;
}
//the destroy case
case BLOCK_C:
{
mycerr("Auto %u, poistuu C\n", car_id);
Terminate();
break;
}
case BLOCK_D:
{
//derp
mycerr("Auto %u, poistuu D\n", car_id);
Terminate();
break;
}
case BLOCK_TRAFFICL:
{
traffic_light->TrafficLightWait(*&this->car_id);
break;
}
case BLOCK_FERRY:
{
ferry->UseFerry(*&this->car_id);
break;
}
default:
break;
}
pos_block++;
}
}