-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvehicle.h
133 lines (121 loc) · 2.3 KB
/
vehicle.h
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#ifndef VEHICLE_H
#define VEHICLE_H
#include <vector>
#include <list>
#include "drawing.h"
#include "package.h"
#include "customer.h"
class Vehicle : public DrawableObject , public PackageContainer
{
public:
Vehicle():
_rotation(0),
_speed(1),
_capacity(300),
_currentLoad(0.0),
_isRoute(false),
_asset(nullptr)
{}
Vehicle(int speed, int capacity):
_speed(speed),
_capacity(capacity),
_currentLoad(0.0),
_isRoute(false)
{}
void PlanRoute(std::vector<DrawableObject*> route);
bool isOnRoute() const
{
return _isRoute;
}
DrawableObject *CurrentAsset()
{
return _asset;
}
//Override package load handlers to add capacity handling (exception thrown)//
void PutPackage(Package *pack);
Package *GetPackage(ConstIterator &i);
double Capacity()
{
return _capacity;
}
void Step() = 0;
void Draw();
bool Move();
protected:
double _rotation;
int _speed;
double _capacity;
double _currentLoad;
bool _isRoute;
std::list<DrawableObject*> _route;
DrawableObject *_asset;
};
class VehicleContainer
{
public:
using ConstIterator = std::vector<Vehicle*>::const_iterator;
void Arrive(Vehicle &v);
void Dispatch(Vehicle &v);
ConstIterator begin()
{
return _vehicles.begin();
}
ConstIterator end()
{
return _vehicles.end();
}
protected:
std::vector<Vehicle*> _vehicles;
};
class DistributionVehicle : public Vehicle
{
public:
DistributionVehicle()
{}
void Distribute()
{
_isRoute = true;
}
void Step();
};
class Truck : public Vehicle
{
public:
Truck(Point startpos)
{
_position = startpos;
_speed = 3;
_capacity = 15000;
_isRoute = false;
}
void Transit()
{
_isRoute = true;
}
void Step();
};
class Van : public DistributionVehicle
{
public:
Van(Point startpos)
{
_position = startpos;
_speed = 5;
_capacity = 300;
_isRoute = false;
}
void Draw();
};
class Scooter : public DistributionVehicle
{
public:
Scooter(Point startpos)
{
_position = startpos;
_speed = 8;
_capacity = 40;
_isRoute = false;
}
void Draw();
};
#endif // VEHICLE_H