forked from FaresAtef1/Shipping-Company
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPromoteEvent.cpp
More file actions
53 lines (42 loc) · 1.26 KB
/
PromoteEvent.cpp
File metadata and controls
53 lines (42 loc) · 1.26 KB
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
#include "PromoteEvent.h"
#include "Company.h"
bool PromoteEvent::Execute(Company& Comp)
{
//removing the cargo from the normal waiting list if found by ID
bool Check = true;
if (Comp.GetNormalLoadingTruck())
{
int Index = Comp.GetWaitingIndex(ID);
int Cap;
Truck* TempTruck;
TempTruck = Comp.GetNormalLoadingTruck();
if (dynamic_cast<NormalTruck*>(TempTruck))
Cap = NormalTruck::GetTruckCapacity();
if (dynamic_cast<SpecialTruck*>(TempTruck))
Cap = SpecialTruck::GetTruckCapacity();
if (dynamic_cast<VIPTruck*>(TempTruck))
Cap = VIPTruck::GetTruckCapacity();
Check = Cap - TempTruck->GetCargoCount() < Index;
}
if (Check)
{
Cargo* CargoToBePromoted = Comp.RemoveWNC(ID);
if (CargoToBePromoted)
{
//changing the cargo type into VIP
CargoToBePromoted->SetCargoType('V');
//increasing the cost of the cargo
CargoToBePromoted->SetCost(CargoToBePromoted->GetCost() + ExtraCost);
//adding the cargo into the VIP list
int Priority = 10000 * ((CargoToBePromoted->GetCost()) / (CargoToBePromoted->GetDeliveryDistance() * (EventTime.day * 24.0 + EventTime.hour)));
Comp.enqueueWVC(CargoToBePromoted, Priority);
return true;
}
return false;
}
}
void PromoteEvent::SetParameters(int id, int EC)
{
ID = id;
ExtraCost = EC;
}