-
Notifications
You must be signed in to change notification settings - Fork 0
/
Port.cpp
67 lines (54 loc) · 1.6 KB
/
Port.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
//
// Created by Admin on 6/18/2021.
//
#include <algorithm>
#include "Port.h"
#include "Freighter.h"
#include "Boat_patrol.h"
void Port::update() {
if (_fuelQueue.empty() == false) {
if (_fuelQueue.front()->getType() == object_type::freighter) {
double fuelNeeded =
FREIGHTER_FUEL_TANK_CAPACITY
- dynamic_cast<Freighter*>(_fuelQueue.front().get())->getFuel();
dynamic_cast<Freighter*>(_fuelQueue.front().get())->refuel(
(_fuel >= fuelNeeded) ? fuelNeeded : _fuel);
_fuelQueue.pop();
} else if (_fuelQueue.front()->getType() == object_type::patrol) {
double fuelNeeded =
PATROL_BOAT_FUEL_TANK_CAPACITY
- dynamic_cast<Boat_patrol*>(_fuelQueue.front().get())->getFuel();
dynamic_cast<Boat_patrol*>(_fuelQueue.front().get())->reFuel(
(_fuel >= fuelNeeded) ? fuelNeeded : _fuel);
}
}
}
Port::Port(std::string name, double x, double y, double Fuel, int containers,
int FPH) :
Sim_object(std::move(name), object_type::port), _coordinates(
Point(x, y)), _fuel(Fuel), _containers(containers), _FPH(FPH) {
}
void Port::setCoordinates(const Point &coordinates) {
Port::_coordinates = coordinates;
}
const Point& Port::getPosition() const {
return _coordinates;
}
void Port::addShipToFuelQueue(Ship *a) {
if (a->getType() == object_type::patrol) {
if (_fuelQueue.empty()) {
_fuelQueue.push(std::unique_ptr<Ship>(a));
}
} else {
_fuelQueue.push(std::unique_ptr<Ship>(a));
}
}
int Port::getContainers() const {
return _containers;
}
void Port::setContainers(int containers) {
Port::_containers = containers;
}
void Port::status() {
Sim_object::status();
}