-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcargo_train.cpp
More file actions
64 lines (54 loc) · 2.14 KB
/
Copy pathcargo_train.cpp
File metadata and controls
64 lines (54 loc) · 2.14 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
54
55
56
57
58
59
60
61
62
63
64
/*
* cargo_train.cpp
*
* Created on: Dec 5, 2015
* Author: pavel
*/
#include "cargo_train.h"
#include "cargo_train_generator.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
CCargoTrain::CCargoTrain(CCargoTrainGenerator& generator,
unsigned scheduledStartTime,
unsigned scheduledTargetStationArrival,
unsigned scheduledMainStationArrival,
unsigned scheduledMainStationDeparture)
: CTrain(generator, scheduledStartTime, scheduledTargetStationArrival, scheduledMainStationArrival,
scheduledMainStationDeparture)
{
CMainStation* pMainStation = &CMainStation::GetInstance();
if(&generator.GetStartStation() == pMainStation)
{
m_pTrack = &pMainStation->GetTrack(static_cast<CAdjacentStation&>(generator.GetTargetStation()));
}
else
{
m_pTrack = &pMainStation->GetTrack(static_cast<CAdjacentStation&>(generator.GetStartStation()));
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
CCargoTrain::~CCargoTrain()
{}
////////////////////////////////////////////////////////////////////////////////////////////////////
void CCargoTrain::Behavior()
{
DBG_LOG_T(m_Generator.GetTrainTitle() + ":\t\tGenerated in " + m_Generator.GetStartStation().GetTitle());
// a track needed for the train
m_Generator.GetStartStation().Enter(*this);
// lock the track start
m_Generator.GetStartStation().SeizeTrack(*this, m_pTrack, true);
Wait(STATION_LEAVING_TIME);
// leave the platform
m_Generator.GetStartStation().Leave(*this);
// unlock the track start
m_Generator.GetStartStation().ReleaseTrack(*this, m_pTrack, true);
Travel(m_ScheduledTargetStationArrival - m_ScheduledStartTime);
// lock track end
m_Generator.GetTargetStation().SeizeTrack(*this, m_pTrack, false);
Wait(STATION_ENTERING_TIME);
// enter the station
m_Generator.GetTargetStation().Enter(*this);
// unlock track end
m_Generator.GetTargetStation().ReleaseTrack(*this, m_pTrack, false);
// release the rail
m_Generator.GetTargetStation().Leave(*this);
}