Junction.hpp 1.59 KB
Newer Older
Martin Kröning's avatar
Martin Kröning committed
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
#pragma once

#include "Lane.hpp"
#include "Named.hpp"
#include <memory>
#include <random>
#include <string>
#include <vector>
class Vehicle;
class MapAppABIWrapper;

class Junction : public Named {
public:
  /// Creates two lanes between \p junctionA and \p junctionB
  static void connect(const std::weak_ptr<Junction> &junctionA,
                      const std::weak_ptr<Junction> &junctionB,
                      const std::string &laneAToBName,
                      const std::string &laneBToAName, double length,
                      double speedLimit, bool noPassing);

  Junction(Junction &&other) noexcept;
  Junction &operator=(Junction &&other) noexcept;

  Junction(std::string name, double fuelAmount);

  void processVehicles(double time);

  void drawVehicles(MapAppABIWrapper &mapApp) const;

  void createCar(std::string name, double topSpeed, double fuelConsumption,
                 double fuelCapacity, double timeOfStart, double time);

  void createBicycle(std::string name, double topSpeed, double timeOfStart,
                     double time);

  void acceptVehicle(std::unique_ptr<Vehicle> vehicle,
                     const std::string &prohibitedLaneName);

private:
  /// Mersenne Twister random number generator
  /// for selection in randomOutboundLaneExcept
  static std::mt19937 gen;

  std::vector<Lane> outboundLanes;

  /// The amount of fuel in l in the filling station
  double fuelAmount;

  /// Refuels the given vehicle using the filling station
  void fillUp(Vehicle &fahrzeug);

  Lane &randomOutboundLane();

  Lane &randomOutboundLaneExcept(const std::string &laneName);
};