-
Notifications
You must be signed in to change notification settings - Fork 0
/
routemanager.cpp
98 lines (88 loc) · 2.25 KB
/
routemanager.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
/*
* routemanager.cpp
*
* Created on: 7.5.2014
* Author: Atte
*/
#include "routemanager.h"
#include <vector>
#include <pthread.h>
RouteManager::RouteManager(Randomizer* randomizer_h): routes(), randomizer(randomizer_h)
{
pthread_mutex_init(&this->signal_guard, NULL);
ConstructRoutes();
}
RouteManager::~RouteManager()
{
pthread_mutex_destroy(&this->signal_guard);
}
void RouteManager::GetRoute(std::vector<ERouteBlock>* route)
{
pthread_mutex_lock(&this->signal_guard);
*route = routes.at(randomizer->Randomize((unsigned int)ROUTE_B_D));
pthread_mutex_unlock(&this->signal_guard);
}
void RouteManager::ConstructRoutes()
{
std::vector<ERouteBlock> empty;
for( int i = ROUTE_A_C; i <= ROUTE_B_D; ++i )
{
routes.push_back(empty);
switch (i)
{
case ROUTE_A_C:
{
routes.at(i).push_back(BLOCK_A);
AddRoads( routes.at(i), 4);
routes.at(i).push_back(BLOCK_TRAFFICL);
AddRoads( routes.at(i), 7);
routes.at(i).push_back(BLOCK_C);
break;
}
case ROUTE_A_D:
{
routes.at(i).push_back(BLOCK_A);
AddRoads( routes.at(i), 4);
routes.at(i).push_back(BLOCK_TRAFFICL);
AddRoads( routes.at(i), 5);
routes.at(i).push_back(BLOCK_L);
routes.at(i).push_back(BLOCK_FERRY);
routes.at(i).push_back(BLOCK_D);
break;
}
case ROUTE_B_C:
{
routes.at(i).push_back(BLOCK_B);
AddRoads( routes.at(i), 1);
routes.at(i).push_back(BLOCK_TRAFFICL);
AddRoads( routes.at(i), 7);
routes.at(i).push_back(BLOCK_C);
break;
}
case ROUTE_B_D:
{
routes.at(i).push_back(BLOCK_B);
AddRoads( routes.at(i), 1);
routes.at(i).push_back(BLOCK_TRAFFICL);
AddRoads( routes.at(i), 5);
routes.at(i).push_back(BLOCK_L);
routes.at(i).push_back(BLOCK_FERRY);
routes.at(i).push_back(BLOCK_D);
break;
}
default:
{
break;
}
}
}
return;
}
void RouteManager::AddRoads(std::vector<ERouteBlock>& route, unsigned int amount)
{
for(unsigned int i = 0; i < amount; ++i )
{
route.push_back(BLOCK_ROAD);
}
return;
}