forked from AlbertBall/railway-dot-exe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestFunction code.txt
474 lines (442 loc) · 19 KB
/
TestFunction code.txt
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
//Code to test train splits especially with named points & crossovers, with warnings about points set wrongly and obstructing trains
//includes additional code in Interface.h & .cpp
In TestFunction:
//---------------------------------------------------------------------------
AnsiString LocationName = "";
bool Derail; //not used
int FrontTrainFrontPos, FrontTrainRearPos, RearTrainFrontPos, RearTrainRearPos;
int LeadElement, LeadEntryPos, LeadExitPos, MidElement, MidEntryPos, MidExitPos;
TTrackElement TELead, TEMid, FTFElement, FTRElement, RTFElement, RTRElement;
randomize();
if(TestFunctionCount >= int(Track->TrackVector.size()))
{
ShowMessage("Complete");
goto END;
}
{ //need this as goto END above bypasses local variable initialisation
int TrainIDCount = 0;
if(TestFunctionFirstPass) //set up a list of random TrainIDs & store them, then display them every time round loop
{
while(true)
{
if(TrainIDCount >= int(Track->TrackVector.size()))
{
break;
}
TTrackElement TE = Track->TrackElementAt(-1, TrainIDCount);
int randval = (rand() % 8);
if(randval == 0)
{
if(TE.ActiveTrackElementName == "aaa")
{
IDList.push_back(TrainIDCount);
}
}
TrainIDCount++;
}
}
TestFunctionFirstPass = false;
while(Track->TrackElementAt(-1, TestFunctionCount).ActiveTrackElementName != "aaa")
{
TestFunctionCount++;
if(TestFunctionCount >= int(Track->TrackVector.size()))
{
ShowMessage("Complete");
goto END;
}
}
TELead = Track->TrackElementAt(-1, TestFunctionCount);
if(TELead.ActiveTrackElementName != "")
{
LocationName = TELead.ActiveTrackElementName;
LeadElement = TestFunctionCount;
int ConnLink = 0; //keep incrementing this to max of 3
if(TELead.Conn[ConnLink] > -1)
{
LeadEntryPos = ConnLink;
LeadExitPos = Track->GetAnyElementOppositeLinkPos(-2, LeadElement, LeadEntryPos, Derail);
MidElement = TELead.Conn[ConnLink];
TEMid = Track->TrackElementAt(-2, MidElement);
MidExitPos = TELead.ConnLinkPos[ConnLink];
MidEntryPos = Track->GetAnyElementOppositeLinkPos(-1, MidElement, MidExitPos, Derail);
}
else
{
goto END;
}
//centre leadElement on screen
Display->DisplayOffsetH = ((TELead.HLoc * 16) - Interface->MainScreen->Width / 2) / 16; // ScreenPosH = HPos - (DisplayOffsetH * 16)
Display->DisplayOffsetV = ((TELead.VLoc * 16) - Interface->MainScreen->Height / 2) / 16;
ClearandRebuildRailway(-1);
Display->PlotOutput(-1, (TELead.HLoc * 16), (TELead.VLoc * 16), RailGraphics->bmRedRect); //LeadElement Red Square
Display->PlotOutput(-1, (TEMid.HLoc * 16), (TEMid.VLoc * 16), RailGraphics->bmGreenRect); //MidElement Green Square
for(unsigned int x = 0; x < Track->TrackVector.size(); x++)
{
unsigned int y = IDList.front();
IDList.pop_front();
IDList.push_back(y);
TTrackElement &TE = Track->TrackElementAt(-1, y);
TE.TrainIDOnElement = 2; //can't be 1 as that's own train ID
Display->PlotOutput(-1, (TE.HLoc * 16), (TE.VLoc * 16), RailGraphics->CodeT);
}
bool TemporaryDelay = false;
if(Track->ThisLocationLongEnoughForSplit(-1, "1A00", 100, LocationName, LeadElement, LeadExitPos, //100 is own train TrainID
MidElement, MidEntryPos, FrontTrainFrontPos, FrontTrainRearPos, RearTrainFrontPos, RearTrainRearPos, TemporaryDelay))
{
if(!TemporaryDelay)
{
if((FrontTrainFrontPos != LeadElement) && (FrontTrainFrontPos != MidElement))
{
FTFElement = Track->TrackElementAt(-3, FrontTrainFrontPos);
Display->PlotOutput(-1, (FTFElement.HLoc * 16), (FTFElement.VLoc * 16), RailGraphics->CodeF);
}
if((FrontTrainRearPos != LeadElement) && (FrontTrainRearPos != MidElement))
{
FTRElement = Track->TrackElementAt(-3, FrontTrainRearPos);
Display->PlotOutput(-1, (FTRElement.HLoc * 16), (FTRElement.VLoc * 16), RailGraphics->Code_f);
}
if((RearTrainFrontPos != LeadElement) && (RearTrainFrontPos != MidElement))
{
RTFElement = Track->TrackElementAt(-3, RearTrainFrontPos);
Display->PlotOutput(-1, (RTFElement.HLoc * 16), (RTFElement.VLoc * 16), RailGraphics->Code_r);
}
if((RearTrainRearPos != LeadElement) && (RearTrainRearPos != MidElement))
{
RTRElement = Track->TrackElementAt(-3, RearTrainRearPos);
Display->PlotOutput(-1, (RTRElement.HLoc * 16), (RTRElement.VLoc * 16), RailGraphics->CodeR);
}
}
}
else
{
ShowMessage("Too short or points or obstructing train failure");
}
}
else
{
while(Track->TrackElementAt(-1, TestFunctionCount).ActiveTrackElementName == "")
{
TestFunctionCount++;
if(TestFunctionCount >= int(Track->TrackVector.size()))
{
ShowMessage("Complete");
}
}
// TestFunctionCount--;
}
}
END:
//As above in Interface.cpp
//---------------------------------------------------------------------------
#include <stdlib.h> //for rand() function in TestFunction()
TestFunctionCount = 0; //used only in test function
TestFunctionFirstPass = true; //used only in test function
//---------------------------------------------------------------------------
void __fastcall TInterface::MainScreenDblClick(TObject *Sender)
{
TestFunctionCount++;
TestFunction();
}
//---------------------------------------------------------------------------
void __fastcall TInterface::FormDblClick(TObject *Sender)
{
while(Track->TrackElementAt(-1, TestFunctionCount).ActiveTrackElementName != "aaa")
{
TestFunctionCount;
if(TestFunctionCount == 0)
{
break;
}
}
TestFunction();
}
//---------------------------------------------------------------------------
//As above in Interface.h
//---------------------------------------------------------------------------
void __fastcall MainScreenDblClick(TObject *Sender);
void __fastcall FormDblClick(TObject *Sender); //added atv2.17.0
int TestFunctionCount; //used only in test function
bool TestFunctionFirstPass; //used only in test function
std::list<unsigned int> IDList;
//---------------------------------------------------------------------------
//this displays all location stop positions on a railway to check for correct positioning (only in TestFunction)
//---------------------------------------------------------------------------
for(TTrack::TTrackVectorIterator TVIt = Track->TrackVector.begin(); TVIt != Track->TrackVector.end(); TVIt++)
{
if(TVIt->StationEntryStopLinkPos1 > -1)
{
Display->PlotOutput(-1, (TVIt->HLoc * 16), (TVIt->VLoc * 16), RailGraphics->smBrightGreen);
}
if(TVIt->StationEntryStopLinkPos2 > -1)
{
Display->PlotOutput(-1, (TVIt->HLoc * 16), (TVIt->VLoc * 16 + 4), RailGraphics->smMagenta);
}
if(TVIt->StationEntryStopLinkPos3 > -1)
{
Display->PlotOutput(-1, (TVIt->HLoc * 16), (TVIt->VLoc * 16 + 8), RailGraphics->smOrange);
}
if(TVIt->StationEntryStopLinkPos4 > -1)
{ ddd
Display->PlotOutput(-1, (TVIt->HLoc * 16), (TVIt->VLoc * 16 + 12), RailGraphics->smRed);
}
}
//---------------------------------------------------------------------------
//this tests the error function
//---------------------------------------------------------------------------
throw Exception("test error");
//---------------------------------------------------------------------------
This was used to test the time order function. It adds a 'Key' variable to allow a location name to be used instead of the train starting time - explained in the code below. The time order code in the program just uses the train starting time.
//---------------------------------------------------------------------------
AnsiString Key = "Start"; //For train start time order use 'Key = "Start";', any other location name value uses the
//time order of the first appearance of that name (e.g. 'Key = "Manchester Victoria";)
if(TimetableEditVector.empty())
{
Utilities->CallLogPop(-1);
return;
}
TrainController->LogEvent("TimeOrder");
Utilities->CallLog.push_back(Utilities->TimeStamp() + ",TimeOrder");
TTEVIterator SortStart, SortEnd;
AnsiString Time = "", StartTime = "";
int StartPos = 0;
bool PreStart = true, MainBody = false, PostEnd = false;
for(TTimetableEditVector::iterator x = TimetableEditVector.begin(); x < TimetableEditVector.end(); x++)
{
if(PreStart)
{
StartTime = (*x).SubString(1,5);
if(((StartTime[1] >= '0') && (StartTime[1] <= '9')) &&
((StartTime[2] >= '0') && (StartTime[2] <= '9')) &&
((StartTime[3] == ':')))
{
*x = "//:58" + (*x);
PreStart = false;
MainBody = true;
}
else
{
*x = "//:57" + (*x);
}
}
else if(MainBody)
{
if(*x == "") //end of MainBody
{
MainBody = false;
PostEnd = true;
*x = "::::;";
continue;
}
if((*x)[1] == '*')
{
*x = "//:59" + (*x); //so all go up front after start time
continue;
}
if(Key == "Start")
{
StartPos = (*x).Pos(";Snt");
if(StartPos == 0)
{
StartPos = (*x).Pos(";Sns");
}
if(StartPos == 0)
{
StartPos = (*x).Pos(";Sfs");
}
if((StartPos == 0) || (StartPos < 11)) //11 allows for min length of headcode (4), comma (1), time (5) and the ';' (1)
{
ShowMessage("No start entry or other error in " + (*x));
Utilities->CallLogPop(-1);
return;
}
//now work forwards from the last comma to make sure there's room for the time
int y = StartPos;
while((y > 0) && ((*x)[y] != ','))
{
y--;
}
if(y == 0)
{
ShowMessage("No comma prior to time entry in " + (*x));
Utilities->CallLogPop(-1);
return;
}
else if((StartPos - y) < 6) //StartPos -> ';' and y -> ',' so if less than 6 there's no room for the time
{
ShowMessage("No room for the time entry in " + (*x));
Utilities->CallLogPop(-1);
return;
}
}
else
{
StartPos = (*x).Pos(";" + Key);
if(StartPos == 0) //can't find name so add these to end of main body
{
*x = ":::::" + (*x);
continue;
}
//now work forwards from the last comma to make sure there's room for the time
int y = StartPos;
while((y > 0) && ((*x)[y] != ','))
{
y--;
} //if y == 0 it means that the name hasn't been found, so continue and the service will appear after the end of the main body
if((StartPos - y) < 6) //StartPos -> ';' and y -> ',' so if less than 6 there's no room for the time
{
ShowMessage("No room for the time entry in " + (*x));
Utilities->CallLogPop(-1);
return;
}
else
{
StartPos = y + 6; //point to the ';' after the first time on the line (may have arrival & departure ot a 'pas' entry)
}
}
Time = (*x).SubString(StartPos - 5,5);
*x = Time + (*x);
}
else if(PostEnd)
{
*x = ":::;;" + (*x);
}
else
{
ShowMessage("Can't identify entry " + (*x));
Utilities->CallLogPop(-1);
return;
}
}
TTSelectedEntry = *TTCurrentEntryIterator;
OriginalTimetableEditVector = TimetableEditVector;
SortStart = TimetableEditVector.begin(); // if no start time set sort from beginning
if(TTFirstServiceIterator != TimetableEditVector.end())
{
SortStart = TTFirstServiceIterator;
}
SortEnd = TimetableEditVector.end(); // if no last service set sort to end
if(TTLastServiceIterator != TimetableEditVector.end())
{
SortEnd = TTLastServiceIterator + 1;
}
std::sort(SortStart, SortEnd);
//now remove the times at start of each entry
for(TTimetableEditVector::iterator x = TimetableEditVector.begin(); x < TimetableEditVector.end(); x++)
{
*x = (*x).SubString(6, (*x).Length() - 5);
}
CompileAllEntriesMemoAndSetIterators(-1);
bool CurrentEntryChanged = false;
TimetableChangedFlag = true;
for(TTimetableEditVector::iterator x = TimetableEditVector.begin(); x < TimetableEditVector.end(); x++)
{
if(TTSelectedEntry == *x)
{
TTCurrentEntryIterator = x;
CurrentEntryChanged = true;
}
}
if(!CurrentEntryChanged)
{
TTCurrentEntryIterator = TTStartTimeIterator;
}
TimetableValidFlag = false;
Level1Mode = TimetableMode;
SetLevel1Mode(-1);
//---------------------------------------------------------------------------
Simulate train failure:
TrainController->TrainVectorAt(-1, 0).TrainFailurePending = true;
//---------------------------------------------------------------------------
Test for no incorrect entries or exits in Manchester Area simulation
for(TTimetableEditVector::iterator x = TimetableEditVector.begin(); x < TimetableEditVector.end(); x++)
{
AnsiString ServRef = (*x).SubString(1,8);
if((*x).Pos("Fer;N26-12") != 0) //Bolton
{
int a = 4; //error
}
if((*x).Pos("Snt;N26-13") != 0)
{
int a = 4; //error
}
if((*x).Pos("Fer;N26-15") != 0) //Wigan
{
int a = 4; //error
}
if((*x).Pos("Snt;N26-16") != 0)
{
int a = 4; //error
}
if((*x).Pos("Fer;N26-18") != 0) //Liverpool
{
int a = 4; //error
}
if((*x).Pos("Snt;N26-19") != 0)
{
int a = 4; //error
}
if((*x).Pos("Fer;N26-24") != 0) //Warrington
{
int a = 4; //error
}
if((*x).Pos("Snt;N26-25") != 0)
{
int a = 4; //error
}
if((*x).Pos("Fer;51-34") != 0) //Rochdale
{
int a = 4; //error
}
if((*x).Pos("Snt;51-33") != 0)
{
int a = 4; //error
}
if((*x).Pos("Fer;51-41") != 0) //Huddersfield
{
int a = 4; //error
}
if((*x).Pos("Snt;51-40") != 0)
{
int a = 4; //error
}
if((*x).Pos("Fer;51-48") != 0) //Sheffield
{
int a = 4; //error
}
if((*x).Pos("Snt;51-47") != 0)
{
int a = 4; //error
}
if((*x).Pos("Fer;51-52") != 0) //Lon out error
{
int a = 4; //error
}
if((*x).Pos("Fer;51-54") != 0) //Lon out error
{
int a = 4; //error
}
if((*x).Pos("Fer;51-55") != 0) //Lon out error
{
int a = 4; //error
}
if((*x).Pos("Snt;51-51") != 0) //Lon in error
{
int a = 4; //error
}
if((*x).Pos("Snt;51-53") != 0) //Lon in error
{
int a = 4; //error
}
}
//---------------------------------------------------------------------------
find tt entries that contain both Man Vic & Man Picc
for(TTimetableEditVector::iterator x = TimetableEditVector.begin(); x < TimetableEditVector.end(); x++)
{
AnsiString ServRef = (*x).SubString(1,8);
if(((*x).Pos("Manchester Piccadilly") != 0) && ((*x).Pos("Manchester Victoria") != 0))
{
AnsiString xx = (*x).SubString(1,70);
int a = 4; //error
}
}
//---------------------------------------------------------------------------