Junction.hpp 1.57 KB
Newer Older
Martin Kröning's avatar
Martin Kröning committed
1 2 3 4 5 6 7
#pragma once

#include "Lane.hpp"
#include "Named.hpp"
#include <memory>
#include <random>
#include <string>
8
#include <string_view>
Martin Kröning's avatar
Martin Kröning committed
9 10
#include <vector>
class Vehicle;
11
class MapWindowWrapper;
Martin Kröning's avatar
Martin Kröning committed
12 13 14 15 16 17

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,
18 19
                      std::string laneAToBName, std::string laneBToAName,
                      double length, double speedLimit, bool noPassing);
Martin Kröning's avatar
Martin Kröning committed
20 21 22 23 24 25 26 27

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

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

  void processVehicles(double time);

28
  void drawVehicles(MapWindowWrapper &mapWindow) const;
Martin Kröning's avatar
Martin Kröning committed
29 30 31 32 33 34 35 36

  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,
37
                     std::string_view prohibitedLaneName);
Martin Kröning's avatar
Martin Kröning committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

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();

54
  Lane &randomOutboundLaneExcept(std::string_view laneName);
Martin Kröning's avatar
Martin Kröning committed
55
};