forked from GokuMK/TSRE5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActivityTimetable.cpp
166 lines (147 loc) · 4.48 KB
/
ActivityTimetable.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* This file is part of TSRE5.
*
* TSRE5 - train sim game engine and MSTS/OR Editors.
* Copyright (C) 2016 Piotr Gadecki <[email protected]>
*
* Licensed under GNU General Public License 3.0 or later.
*
* See LICENSE.md or https://www.gnu.org/licenses/gpl.html
*/
#include "ActivityTimetable.h"
#include "ParserX.h"
#include "FileBuffer.h"
#include <qDebug>
#include <QTextStream>
#include "ActLib.h"
#include "Service.h"
#include "Path.h"
ActivityTimetable::ActivityTimetable() {
}
ActivityTimetable::ActivityTimetable(QString n, int t){
name = n;
time = t;
nameTime = name + QString::number(time);
empty = false;
}
ActivityTimetable::ActivityTimetable(const ActivityTimetable& orig) {
}
ActivityTimetable::~ActivityTimetable() {
}
void ActivityTimetable::setService(QString sn){
name = sn;
nameTime = name + QString::number(time);
reloadTimetable();
modified = true;
}
void ActivityTimetable::setTime(int t){
time = t;
nameTime = name + QString::number(time);
reloadTimetable();
modified = true;
}
void ActivityTimetable::setArrival(int id, int t){
if(id < 0)
return;
if(arrivalTime.size() <= id)
return;
arrivalTime[id] = t;
modified = true;
}
void ActivityTimetable::setDepart(int id, int t){
if(id < 0)
return;
if(departTime.size() <= id)
return;
departTime[id] = t;
modified = true;
}
void ActivityTimetable::reloadTimetable(){
clear();
Service *s = ActLib::GetServiceByName(name);
if(s == NULL){
qDebug() << "s == NILL " << name;
return;
}
empty = false;
for(int i = 0; i < s->stationStop.size(); i++ ){
arrivalTime.push_back(time);
departTime.push_back(time);
skipCount.push_back(s->stationStop[i].skipCount);
distanceDownPath.push_back(s->stationStop[i].distanceDownPath);
platformStartID.push_back(s->stationStop[i].platformStartID);
}
modified = true;
}
void ActivityTimetable::clear(){
empty = true;
arrivalTime.clear();
departTime.clear();
skipCount.clear();
distanceDownPath.clear();
platformStartID.clear();
modified = true;
}
bool ActivityTimetable::isModified(){
return modified;
}
void ActivityTimetable::load(FileBuffer* data) {
QString sh;
if(actTimetable){
name = "";
time = ParserX::GetNumber(data);
} else {
name = ParserX::GetStringInside(data);
time = ParserX::GetNumber(data);
}
nameTime = name+QString::number(time);
empty = false;
while (!((sh = ParserX::NextTokenInside(data).toLower()) == "")) {
if (sh == ("arrivaltime")) {
arrivalTime.push_back(ParserX::GetNumber(data));
ParserX::SkipToken(data);
continue;
}
if (sh == ("departtime")) {
departTime.push_back(ParserX::GetNumber(data));
ParserX::SkipToken(data);
continue;
}
if (sh == ("skipcount")) {
skipCount.push_back(ParserX::GetNumber(data));
ParserX::SkipToken(data);
continue;
}
if (sh == ("distancedownpath")) {
distanceDownPath.push_back(ParserX::GetNumber(data));
ParserX::SkipToken(data);
continue;
}
if (sh == ("platformstartid")) {
platformStartID.push_back(ParserX::GetNumber(data));
ParserX::SkipToken(data);
continue;
}
qDebug() << "#trafficDefinition-Timetable - undefined token: " << sh;
ParserX::SkipToken(data);
continue;
}
}
void ActivityTimetable::save(QTextStream* out, QString off) {
if(empty){
modified = false;
return;
}
if(actTimetable)
*out << off << "Player_Traffic_Definition ( "<< time <<"\n";
else
*out << off << "Service_Definition ( "<< ParserX::AddComIfReq(name) << " "<< time <<"\n";
for(int i = 0; i<arrivalTime.size(); i++){
*out << off << " ArrivalTime ( "<<arrivalTime[i]<<" )\n";
*out << off << " DepartTime ( "<<departTime[i]<<" )\n";
*out << off << " SkipCount ( "<<skipCount[i]<<" )\n";
*out << off << " DistanceDownPath ( "<<distanceDownPath[i]<<" )\n";
*out << off << " PlatformStartID ( "<<platformStartID[i]<<" )\n";
}
*out << off << ")\n";
modified = false;
}