- Timestamp:
- Nov 25, 2020, 11:59:46 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BigMetro.lpi
r55 r59 58 58 <Other> 59 59 <CompilerMessages> 60 <IgnoredMessages idx 5024="True"/>60 <IgnoredMessages idx6058="True" idx5024="True" idx3124="True"/> 61 61 </CompilerMessages> 62 62 </Other> … … 151 151 <Other> 152 152 <CompilerMessages> 153 <IgnoredMessages idx 5024="True"/>153 <IgnoredMessages idx6058="True" idx5024="True" idx3124="True"/> 154 154 </CompilerMessages> 155 155 <CustomOptions Value="-dDEBUG"/> -
trunk/UEngine.pas
r52 r59 188 188 public 189 189 Passengers: TMetroPassengers; 190 191 190 BaseTrackPoint: TTrackPoint; 192 191 RelPos: Double; … … 371 370 I := 0; 372 371 while (I < 0) and 373 (( TTrackLink(Items[I]).Points.First <> Point1) or (TTrackLink(Items[I]).Points.Last <> Point2))374 and (( TTrackLink(Items[I]).Points.First <> Point2) or (TTrackLink(Items[I]).Points.Last <> Point1)) do372 ((Items[I].Points.First <> Point1) or (Items[I].Points.Last <> Point2)) 373 and ((Items[I].Points.First <> Point2) or (Items[I].Points.Last <> Point1)) do 375 374 Inc(I); 376 if I < 0 then Result := TTrackLink(Items[I])375 if I < 0 then Result := Items[I] 377 376 else Result := nil; 378 377 end; … … 406 405 Points.Free; 407 406 Links.Free; 408 inherited Destroy;407 inherited; 409 408 end; 410 409 … … 420 419 begin 421 420 Points.Free; 422 inherited Destroy;421 inherited; 423 422 end; 424 423 … … 442 441 begin 443 442 Rivers.Free; 444 inherited Destroy;443 inherited; 445 444 end; 446 445 … … 510 509 begin 511 510 I := 0; 512 while (I < Count) and ( TTrackLink(Items[I]).Points[1] <> TrackPoint) and (TTrackLink(Items[I])<> Skip) do Inc(I);513 if I < Count then Result := TTrackLink(Items[I])511 while (I < Count) and (Items[I].Points[1] <> TrackPoint) and (Items[I] <> Skip) do Inc(I); 512 if I < Count then Result := Items[I] 514 513 else Result := nil; 515 514 end; … … 520 519 begin 521 520 I := 0; 522 while (I < Count) and ( TTrackLink(Items[I]).Points[0] <> TrackPoint) and (TTrackLink(Items[I])<> Skip) do Inc(I);523 if I < Count then Result := TTrackLink(Items[I])521 while (I < Count) and (Items[I].Points[0] <> TrackPoint) and (Items[I] <> Skip) do Inc(I); 522 if I < Count then Result := Items[I] 524 523 else Result := nil; 525 524 end; … … 532 531 begin 533 532 I := 0; 534 while (I < Count) and ( TTrackPointsAngle(Items[I]).Angle <> Angle) do Inc(I);535 if I < Count then Result := TTrackPointsAngle(Items[I])533 while (I < Count) and (Items[I].Angle <> Angle) do Inc(I); 534 if I < Count then Result := Items[I] 536 535 else Result := nil; 537 536 end; … … 548 547 begin 549 548 TrackLinks.Free; 550 inherited Destroy;549 inherited; 551 550 end; 552 551 … … 594 593 begin 595 594 I := Track.Points.IndexOf(Self) - 1; 596 while (I >= 0) and not Assigned(T TrackPoint(Track.Points[I]).LineStation) do595 while (I >= 0) and not Assigned(Track.Points[I].LineStation) do 597 596 Dec(I); 598 if I >= 0 then Result := T TrackPoint(Track.Points[I])597 if I >= 0 then Result := Track.Points[I] 599 598 else Result := nil; 600 599 end; … … 605 604 begin 606 605 I := Track.Points.IndexOf(Self) + 1; 607 while (I < Track.Points.Count) and not Assigned(T TrackPoint(Track.Points[I]).LineStation) do606 while (I < Track.Points.Count) and not Assigned(Track.Points[I].LineStation) do 608 607 Inc(I); 609 if I < Track.Points.Count then Result := T TrackPoint(Track.Points[I])608 if I < Track.Points.Count then Result := Track.Points[I] 610 609 else Result := nil; 611 610 end; … … 617 616 Result := nil; 618 617 NewIndex := Track.Points.IndexOf(Self) - 1; 619 if NewIndex >= 0 then Result := T TrackPoint(Track.Points[NewIndex]);618 if NewIndex >= 0 then Result := Track.Points[NewIndex]; 620 619 end; 621 620 … … 627 626 if Assigned(Track) then begin 628 627 NewIndex := Track.Points.IndexOf(Self) + 1; 629 if NewIndex < Track.Points.Count then Result := T TrackPoint(Track.Points[NewIndex]);628 if NewIndex < Track.Points.Count then Result := Track.Points[NewIndex]; 630 629 end; 631 630 end; … … 660 659 begin 661 660 Index := Track.Points.IndexOf(Self); 662 Result := Distance(TTrackPoint(Track.Points[Index + 1]).Position, 663 TTrackPoint(Track.Points[Index]).Position); 661 Result := Distance(Track.Points[Index + 1].Position, Track.Points[Index].Position); 664 662 end; 665 663 … … 676 674 NeighLinks.Free; 677 675 NeighPoints.Free; 678 inherited Destroy;676 inherited; 679 677 end; 680 678 … … 686 684 begin 687 685 I := 0; 688 while (I < Count) and ( TLineStation(Items[I]).MapStation <> Station) do Inc(I);689 if I < Count then Result := TLineStation(Items[I])686 while (I < Count) and (Items[I].MapStation <> Station) do Inc(I); 687 if I < Count then Result := Items[I] 690 688 else Result := nil; 691 689 end; … … 708 706 begin 709 707 I := 0; 710 while (I < Count) and (Assigned( TMetroTrain(Items[I]).Line)) do Inc(I);711 if I < Count then Result := TMetroTrain(Items[I])708 while (I < Count) and (Assigned(Items[I].Line)) do Inc(I); 709 if I < Count then Result := Items[I] 712 710 else Result := nil; 713 711 end; … … 719 717 Result := 0; 720 718 for I := 0 to Count - 1 do 721 if not Assigned( TMetroTrain(Items[I]).Line) then Inc(Result);719 if not Assigned(Items[I].Line) then Inc(Result); 722 720 end; 723 721 … … 735 733 begin 736 734 if Count > 0 then begin 737 with TMapStation(Items[0])do735 with Items[0] do 738 736 Result := Rect(Position.X, Position.Y, Position.X, Position.Y); 739 737 for I := 1 to Count - 1 do 740 with TMapStation(Items[I])do begin738 with Items[I] do begin 741 739 if Position.X < Result.Left then Result.Left := Position.X; 742 740 if Position.X > Result.Right then Result.Right := Position.X; … … 769 767 MinD := High(Integer); 770 768 for I := 0 to Engine.Stations.Count - 1 do begin 771 D := Distance( TMapStation(Engine.Stations[I]).Position, Result.Position);769 D := Distance(Engine.Stations[I].Position, Result.Position); 772 770 if D < MinD then MinD := D; 773 771 end; … … 797 795 begin 798 796 I := 0; 799 while (I < Count) and ( TMetroLine(Items[I]).Color <> Color) do Inc(I);800 if I < Count then Result := TMetroLine(Items[I])797 while (I < Count) and (Items[I].Color <> Color) do Inc(I); 798 if I < Count then Result := Items[I] 801 799 else Result := nil; 802 800 end; … … 812 810 begin 813 811 if LineStations.Count >= 2 then begin 814 Index := Track.Points.IndexOf( TLineStation(LineStations.First).TrackPoint);812 Index := Track.Points.IndexOf(LineStations.First.TrackPoint); 815 813 if Index = 0 then begin 816 814 NewTrackPoint := Track.Points.AddNew; 817 815 Track.Points.Insert(0, NewTrackPoint); 818 816 end; 819 Index := Track.Points.IndexOf( TLineStation(LineStations.Last).TrackPoint);817 Index := Track.Points.IndexOf(LineStations.Last.TrackPoint); 820 818 if Index = Track.Points.Count - 1 then begin 821 819 NewTrackPoint := Track.Points.AddNew; … … 823 821 end; 824 822 825 Angle := ArcTan2((T TrackPoint(Track.Points[2]).PositionDesigned.Y - TTrackPoint(Track.Points[1]).PositionDesigned.Y),826 (T TrackPoint(Track.Points[2]).PositionDesigned.X - TTrackPoint(Track.Points[1]).PositionDesigned.X));827 EndPoint := Point(Round(T TrackPoint(Track.Points[1]).PositionDesigned.X - EndStationLength * Cos(Angle)),828 Round(T TrackPoint(Track.Points[1]).PositionDesigned.Y - EndStationLength * Sin(Angle)));829 T TrackPoint(Track.Points.First).PositionDesigned := EndPoint;830 T TrackPoint(Track.Points.First).Position := EndPoint;831 832 Angle := ArcTan2((T TrackPoint(Track.Points[Track.Points.Count - 2]).PositionDesigned.Y - TTrackPoint(Track.Points[Track.Points.Count - 3]).PositionDesigned.Y),833 (T TrackPoint(Track.Points[Track.Points.Count - 2]).PositionDesigned.X - TTrackPoint(Track.Points[Track.Points.Count - 3]).PositionDesigned.X));834 EndPoint := Point(Round(T TrackPoint(Track.Points[Track.Points.Count - 2]).PositionDesigned.X + EndStationLength * Cos(Angle)),835 Round(T TrackPoint(Track.Points[Track.Points.Count - 2]).PositionDesigned.Y + EndStationLength * Sin(Angle)));836 T TrackPoint(Track.Points.Last).PositionDesigned := EndPoint;837 T TrackPoint(Track.Points.Last).Position := EndPoint;823 Angle := ArcTan2((Track.Points[2].PositionDesigned.Y - Track.Points[1].PositionDesigned.Y), 824 (Track.Points[2].PositionDesigned.X - Track.Points[1].PositionDesigned.X)); 825 EndPoint := Point(Round(Track.Points[1].PositionDesigned.X - EndStationLength * Cos(Angle)), 826 Round(Track.Points[1].PositionDesigned.Y - EndStationLength * Sin(Angle))); 827 Track.Points.First.PositionDesigned := EndPoint; 828 Track.Points.First.Position := EndPoint; 829 830 Angle := ArcTan2((Track.Points[Track.Points.Count - 2].PositionDesigned.Y - Track.Points[Track.Points.Count - 3].PositionDesigned.Y), 831 (Track.Points[Track.Points.Count - 2].PositionDesigned.X - Track.Points[Track.Points.Count - 3].PositionDesigned.X)); 832 EndPoint := Point(Round(Track.Points[Track.Points.Count - 2].PositionDesigned.X + EndStationLength * Cos(Angle)), 833 Round(Track.Points[Track.Points.Count - 2].PositionDesigned.Y + EndStationLength * Sin(Angle))); 834 Track.Points.Last.PositionDesigned := EndPoint; 835 Track.Points.Last.Position := EndPoint; 838 836 end; 839 837 end; … … 879 877 if Assigned(Train) then begin 880 878 Train.Line := Self; 881 Train.TargetStation := TLineStation(LineStations[0]);882 Train.BaseTrackPoint := T TrackPoint(Track.Points.First);879 Train.TargetStation := LineStations[0]; 880 Train.BaseTrackPoint := Track.Points.First; 883 881 Trains.Add(Train); 884 882 end; … … 899 897 // Determine track point range to be removed 900 898 TP1 := ALineStation.TrackPoint.GetDown; 901 if not Assigned(TP1) then TP1 := T TrackPoint(Track.Points.First);899 if not Assigned(TP1) then TP1 := Track.Points.First; 902 900 TP2 := ALineStation.TrackPoint.GetUp; 903 if not Assigned(TP2) then TP2 := T TrackPoint(Track.Points.Last);901 if not Assigned(TP2) then TP2 := Track.Points.Last; 904 902 905 903 // Remove track points from trains 906 904 for I := 0 to Trains.Count - 1 do 907 with T MetroTrain(Trains[I])do begin905 with Trains[I] do begin 908 906 IsOnTrack := False; 909 907 for J := Track.Points.IndexOf(TP1) to Track.Points.IndexOf(TP2) do 910 if T TrackPoint(Track.Points[J])= BaseTrackPoint then begin908 if Track.Points[J] = BaseTrackPoint then begin 911 909 IsOnTrack := True; 912 910 Break; … … 924 922 // Delete old trackpoints 925 923 Index := Track.Points.IndexOf(ALineStation.TrackPoint) - 1; 926 while (Index >= 0) and (not Assigned(T TrackPoint(Track.Points[Index]).LineStation)) do begin924 while (Index >= 0) and (not Assigned(Track.Points[Index].LineStation)) do begin 927 925 Track.Points.Delete(Index); 928 926 Dec(Index); … … 930 928 Index := Index + 1; 931 929 Track.Points.Delete(Index); 932 while (Index < Track.Points.Count) and (not Assigned(T TrackPoint(Track.Points[Index]).LineStation)) do930 while (Index < Track.Points.Count) and (not Assigned(Track.Points[Index].LineStation)) do 933 931 Track.Points.Delete(Index); 934 932 935 933 if ((Index - 1) >= 0) and (Index < Track.Points.Count) then 936 Track.RouteTrack(T TrackPoint(Track.Points[Index - 1]), TTrackPoint(Track.Points[Index]));934 Track.RouteTrack(Track.Points[Index - 1], Track.Points[Index]); 937 935 938 936 ALineStation.MapStation.Lines.Remove(Self); … … 940 938 941 939 for I := 0 to Trains.Count - 1 do 942 with T MetroTrain(Trains[I])do begin940 with Trains[I] do begin 943 941 if TargetStation = ALineStation then 944 TargetStation := TLineStation(LineStations[(Index + 1) mod LineStations.Count]);942 TargetStation := LineStations[(Index + 1) mod LineStations.Count]; 945 943 end; 946 944 … … 950 948 if LineStations.Count < 2 then 951 949 for I := Trains.Count - 1 downto 0 do begin 952 T MetroTrain(Trains[I]).Line := nil;950 Trains[I].Line := nil; 953 951 Trains.Delete(I); 954 952 end; … … 968 966 Index1 := Points.IndexOf(TP1); 969 967 Index2 := Points.IndexOf(TP2); 970 P1 := TTrackPoint(Points[Index1]).PositionDesigned;971 P2 := TTrackPoint(Points[Index2]).PositionDesigned;968 P1 := Points[Index1].PositionDesigned; 969 P2 := Points[Index2].PositionDesigned; 972 970 NewTrackPoint := Points.AddNew; 973 971 Delta := Point(P2.X - P1.X, P2.Y - P1.Y); … … 1010 1008 for I := 0 to Track.Points.Count - 1 do 1011 1009 if I > 0 then 1012 Result := Result + Distance(T TrackPoint(Track.Points[I]).Position, TTrackPoint(Track.Points[I - 1]).Position);1010 Result := Result + Distance(Track.Points[I].Position, Track.Points[I - 1].Position); 1013 1011 end; 1014 1012 … … 1028 1026 LineStations.Free; 1029 1027 Track.Free; 1030 inherited Destroy;1028 inherited; 1031 1029 end; 1032 1030 … … 1035 1033 Result := False; 1036 1034 if LineStations.Count >= 2 then 1037 Result := ( TLineStation(LineStations.Last).MapStation = TLineStation(LineStations.First).MapStation);1035 Result := (LineStations.Last.MapStation = LineStations.First.MapStation); 1038 1036 end; 1039 1037 … … 1063 1061 if Current < Target then begin 1064 1062 for I := Current to Target - 1 do 1065 Result := Result + TTrackPoint(Line.Track.Points[I]).GetDistance;1063 Result := Result + Line.Track.Points[I].GetDistance; 1066 1064 Result := Result - Trunc(RelPos); 1067 1065 end else 1068 1066 if Current > Target then begin 1069 1067 for I := Current - 1 downto Target do 1070 Result := Result + TTrackPoint(Line.Track.Points[I]).GetDistance;1068 Result := Result + Line.Track.Points[I].GetDistance; 1071 1069 Result := Result + Trunc(RelPos); 1072 1070 end else Result := Trunc(RelPos); … … 1121 1119 begin 1122 1120 Passengers.Free; 1123 inherited Destroy;1121 inherited; 1124 1122 end; 1125 1123 … … 1149 1147 SortLines; 1150 1148 for I := 0 to Lines.Count - 1 do begin 1151 Line := TMetroLine(Lines[I]);1149 Line := Lines[I]; 1152 1150 LS := Line.LineStations.SearchMapStation(Self); 1153 1151 TP := LS.TrackPoint; 1154 1152 Index := Line.Track.Points.IndexOf(TP); 1155 1153 if Index > 0 then begin 1156 NewTrackLink := TTrackPoint(Line.Track.Points[Index]).GetLinkDown;1154 NewTrackLink := Line.Track.Points[Index].GetLinkDown; 1157 1155 TrackLinks.Add(NewTrackLink); 1158 1156 end; 1159 1157 if Index < (Line.Track.Points.Count - 1) then begin 1160 NewTrackLink := TTrackPoint(Line.Track.Points[Index]).GetLinkUp;1158 NewTrackLink := Line.Track.Points[Index].GetLinkUp; 1161 1159 TrackLinks.Add(NewTrackLink); 1162 1160 end; 1163 if Line.IsCircular and (Self = TLineStation(Line.LineStations.First).MapStation) and1164 (Self = TLineStation(Line.LineStations.Last).MapStation) then begin1165 LS := TLineStation(Line.LineStations.Last);1161 if Line.IsCircular and (Self = Line.LineStations.First.MapStation) and 1162 (Self = Line.LineStations.Last.MapStation) then begin 1163 LS := Line.LineStations.Last; 1166 1164 TP := LS.TrackPoint; 1167 1165 Index := Line.Track.Points.IndexOf(TP); 1168 1166 if Index > 0 then begin 1169 NewTrackLink := TTrackPoint(Line.Track.Points[Index]).GetLinkDown;1167 NewTrackLink := Line.Track.Points[Index].GetLinkDown; 1170 1168 TrackLinks.Add(NewTrackLink); 1171 1169 end; 1172 1170 if Index < (Line.Track.Points.Count - 1) then begin 1173 NewTrackLink := TTrackPoint(Line.Track.Points[Index]).GetLinkUp;1171 NewTrackLink := Line.Track.Points[Index].GetLinkUp; 1174 1172 TrackLinks.Add(NewTrackLink); 1175 1173 end; … … 1180 1178 TPAngleGroup := TTrackPointsAngleGroup.Create; 1181 1179 for I := 0 to TrackLinks.Count - 1 do begin 1182 P1 := T TrackPoint(TTrackLink(TrackLinks[I]).Points[0]).PositionDesigned;1183 P2 := T TrackPoint(TTrackLink(TrackLinks[I]).Points[1]).PositionDesigned;1180 P1 := TrackLinks[I].Points[0].PositionDesigned; 1181 P2 := TrackLinks[I].Points[1].PositionDesigned; 1184 1182 if ComparePoint(P1, Position) and not ComparePoint(P2, Position) then begin 1185 1183 Angle := ArcTan2(P2.Y - Position.Y, P2.X - Position.X); … … 1195 1193 TPAngleGroup.Add(GroupItem); 1196 1194 end; 1197 GroupItem.TrackLinks.Add(T TrackLink(TrackLinks[I]))1195 GroupItem.TrackLinks.Add(TrackLinks[I]) 1198 1196 end; 1199 1197 1200 1198 // Shift TrackLinks according number of lines in group 1201 1199 for I := 0 to TPAngleGroup.Count - 1 do 1202 with T TrackPointsAngle(TPAngleGroup[I])do begin1200 with TPAngleGroup[I] do begin 1203 1201 for J := 0 to TrackLinks.Count - 1 do 1204 with T TrackLink(TrackLinks[J])do begin1202 with TrackLinks[J] do begin 1205 1203 // Get orthogonal angle 1206 1204 HAngle := Angle + Pi / 2; … … 1244 1242 Distance := High(Integer); 1245 1243 for I := 0 to Lines.Count - 1 do 1246 with TMetroLine(Lines[I])do begin1244 with Lines[I] do begin 1247 1245 CurrentLineStation := LineStations.SearchMapStation(Current.MapStation); 1248 1246 StationIndex := LineStations.IndexOf(CurrentLineStation); … … 1251 1249 DirectionDown := False; 1252 1250 for T := 0 to Trains.Count - 1 do begin 1253 if T MetroTrain(Trains[T]).Direction = 1 then DirectionUp := True;1254 if T MetroTrain(Trains[T]).Direction = -1 then DirectionDown := True;1251 if Trains[T].Direction = 1 then DirectionUp := True; 1252 if Trains[T].Direction = -1 then DirectionDown := True; 1255 1253 end; 1256 1254 if StationIndex = 0 then 1257 NextStationDown := TLineStation(LineStations[LineStations.Count - 2])1255 NextStationDown := LineStations[LineStations.Count - 2] 1258 1256 else 1259 1257 if StationIndex > 0 then 1260 NextStationDown := TLineStation(LineStations[StationIndex - 1]);1258 NextStationDown := LineStations[StationIndex - 1]; 1261 1259 1262 1260 if (StationIndex >= 0) and (StationIndex = LineStations.Count - 1) then 1263 NextStationUp := TLineStation(LineStations[1])1261 NextStationUp := LineStations[1] 1264 1262 else 1265 1263 if (StationIndex >= 0) and (StationIndex < LineStations.Count - 1) then 1266 NextStationUp := TLineStation(LineStations[StationIndex + 1]);1264 NextStationUp := LineStations[StationIndex + 1]; 1267 1265 end else begin 1268 1266 if StationIndex > 0 then begin 1269 1267 DirectionDown := True; 1270 NextStationDown := TLineStation(LineStations[StationIndex - 1])1268 NextStationDown := LineStations[StationIndex - 1] 1271 1269 end else DirectionDown := False; 1272 1270 if (StationIndex >= 0) and (StationIndex < LineStations.Count - 1) then begin 1273 1271 DirectionUp := True; 1274 NextStationUp := TLineStation(LineStations[StationIndex + 1]);1272 NextStationUp := LineStations[StationIndex + 1]; 1275 1273 end else DirectionUp := False; 1276 1274 end; … … 1284 1282 end; 1285 1283 end; 1286 Result := (Check.MapStation.ShapeDistance[Shape] <> -1) and (Check.MapStation.ShapeDistance[Shape] <= Distance); 1284 Result := (Check.MapStation.ShapeDistance[Shape] <> -1) and 1285 (Check.MapStation.ShapeDistance[Shape] <= Distance); 1287 1286 end; 1288 1287 … … 1299 1298 FreeAndNil(Lines); 1300 1299 FreeAndNil(Passengers); 1301 inherited Destroy;1300 inherited; 1302 1301 end; 1303 1302 … … 1336 1335 begin 1337 1336 I := 0; 1338 while (I < Stations.Count) and (Distance( TMapStation(Stations[I]).Position, Pos) > ClickDistance) do Inc(I);1339 if I < Stations.Count then Result := TMapStation(Stations[I])1337 while (I < Stations.Count) and (Distance(Stations[I].Position, Pos) > ClickDistance) do Inc(I); 1338 if I < Stations.Count then Result := Stations[I] 1340 1339 else Result := nil; 1341 1340 end; … … 1355 1354 MinD := High(Integer); 1356 1355 while (I < Lines.Count) do 1357 with TMetroLine(Lines[I])do begin1356 with Lines[I] do begin 1358 1357 for T := 1 to Track.Points.Count - 1 do begin 1359 D := PointToLineDistance(Pos, T TrackPoint(Track.Points[T - 1]).Position, TTrackPoint(Track.Points[T]).Position);1358 D := PointToLineDistance(Pos, Track.Points[T - 1].Position, Track.Points[T].Position); 1360 1359 if (D < MinD) and (D < TrackClickDistance) then begin 1361 1360 MinD := D; 1362 Result.Points[0] := T TrackPoint(Track.Points[T - 1]);1363 Result.Points[1] := T TrackPoint(Track.Points[T]);1361 Result.Points[0] := Track.Points[T - 1]; 1362 Result.Points[1] := Track.Points[T]; 1364 1363 end; 1365 1364 end; … … 1377 1376 MinDistance := High(Integer); 1378 1377 for I := 0 to Trains.Count - 1 do 1379 with T MetroTrain(Trains[I])do begin1378 with Trains[I] do begin 1380 1379 D := Distance(GetPosition, Pos); 1381 1380 if (D < (TrainSize div 2)) and (D < MinDistance) then begin 1382 Result := T MetroTrain(Trains[I]);1381 Result := Trains[I]; 1383 1382 MinDistance := D; 1384 1383 end; … … 1561 1560 // Do for all lines connected to station 1562 1561 for I := 0 to Lines.Count - 1 do 1563 with TMetroLine(Lines[I])do1562 with Lines[I] do 1564 1563 for StationIndex := 0 to LineStations.Count - 1 do 1565 if TLineStation(LineStations[StationIndex]).MapStation = Station then begin1564 if LineStations[StationIndex].MapStation = Station then begin 1566 1565 if not IsCircular then begin 1567 1566 // Update for all adjecent stations 1568 1567 if StationIndex > 0 then 1569 ComputeShapeDistanceStation( TLineStation(LineStations[StationIndex - 1]).MapStation,1568 ComputeShapeDistanceStation(LineStations[StationIndex - 1].MapStation, 1570 1569 UpdatedShape, Station.ShapeDistance[UpdatedShape] + 1); 1571 1570 if (StationIndex >= 0) and (StationIndex < LineStations.Count - 1) then 1572 ComputeShapeDistanceStation( TLineStation(LineStations[StationIndex + 1]).MapStation,1571 ComputeShapeDistanceStation(LineStations[StationIndex + 1].MapStation, 1573 1572 UpdatedShape, Station.ShapeDistance[UpdatedShape] + 1); 1574 1573 end else begin … … 1578 1577 DirectionDown := False; 1579 1578 for T := 0 to Trains.Count - 1 do begin 1580 if T MetroTrain(Trains[T]).Direction = 1 then DirectionUp := True;1581 if T MetroTrain(Trains[T]).Direction = -1 then DirectionDown := True;1579 if Trains[T].Direction = 1 then DirectionUp := True; 1580 if Trains[T].Direction = -1 then DirectionDown := True; 1582 1581 end; 1583 1582 // Update for all adjecent stations 1584 1583 if DirectionUp then begin 1585 1584 if StationIndex = 0 then 1586 ComputeShapeDistanceStation( TLineStation(LineStations[LineStations.Count - 2]).MapStation,1585 ComputeShapeDistanceStation(LineStations[LineStations.Count - 2].MapStation, 1587 1586 UpdatedShape, Station.ShapeDistance[UpdatedShape] + 1); 1588 1587 if StationIndex > 0 then 1589 ComputeShapeDistanceStation( TLineStation(LineStations[StationIndex - 1]).MapStation,1588 ComputeShapeDistanceStation(LineStations[StationIndex - 1].MapStation, 1590 1589 UpdatedShape, Station.ShapeDistance[UpdatedShape] + 1); 1591 1590 end; 1592 1591 if DirectionDown then begin 1593 1592 if (StationIndex >= 0) and (StationIndex = LineStations.Count - 1) then 1594 ComputeShapeDistanceStation( TLineStation(LineStations[1]).MapStation,1593 ComputeShapeDistanceStation(LineStations[1].MapStation, 1595 1594 UpdatedShape, Station.ShapeDistance[UpdatedShape] + 1); 1596 1595 if (StationIndex >= 0) and (StationIndex < LineStations.Count - 1) then 1597 ComputeShapeDistanceStation( TLineStation(LineStations[StationIndex + 1]).MapStation,1596 ComputeShapeDistanceStation(LineStations[StationIndex + 1].MapStation, 1598 1597 UpdatedShape, Station.ShapeDistance[UpdatedShape] + 1); 1599 1598 end; … … 1617 1616 // Move trains 1618 1617 for I := 0 to Trains.Count - 1 do 1619 with T MetroTrain(Trains[I])do begin1618 with Trains[I] do begin 1620 1619 if not Assigned(TargetStation) and Assigned(BaseTrackPoint) then begin 1621 1620 if (Direction <> 1) and (Direction <> -1) then Direction := 1 … … 1638 1637 if Line.IsCircular then begin 1639 1638 TargetStationIndex := Line.LineStations.Count - 2; 1640 BaseTrackPoint := TLineStation(Line.LineStations.Last).TrackPoint;1639 BaseTrackPoint := Line.LineStations.Last.TrackPoint; 1641 1640 RelPos := 0; 1642 1641 end else begin … … 1648 1647 if Line.IsCircular then begin 1649 1648 TargetStationIndex := 1; 1650 BaseTrackPoint := TLineStation(Line.LineStations.First).TrackPoint;1649 BaseTrackPoint := Line.LineStations.First.TrackPoint; 1651 1650 RelPos := 0; 1652 1651 end else begin … … 1655 1654 end; 1656 1655 end; 1657 TargetStation := TLineStation(Line.LineStations[TargetStationIndex]);1656 TargetStation := Line.LineStations[TargetStationIndex]; 1658 1657 1659 1658 // Unload passengers in target station 1660 1659 if Assigned(CurrentStation) then 1661 1660 for P := Passengers.Count - 1 downto 0 do begin 1662 if TMetroPassenger(Passengers[P]).Shape = CurrentStation.MapStation.Shape then begin1663 Passenger := TMetroPassenger(Passengers[P]);1661 if Passengers[P].Shape = CurrentStation.MapStation.Shape then begin 1662 Passenger := Passengers[P]; 1664 1663 Passengers.Delete(P); 1665 1664 Self.Passengers.Remove(Passenger); … … 1670 1669 if Assigned(CurrentStation) then 1671 1670 for P := Passengers.Count - 1 downto 0 do begin 1672 if not CurrentStation.MapStation.IsBestStationForShape( TMetroPassenger(Passengers[P]).Shape,1671 if not CurrentStation.MapStation.IsBestStationForShape(Passengers[P].Shape, 1673 1672 TargetStation, CurrentStation) then begin 1674 Passenger := TMetroPassenger(Passengers[P]);1673 Passenger := Passengers[P]; 1675 1674 Passengers.Delete(P); 1676 1675 CurrentStation.MapStation.Passengers.Add(Passenger); … … 1685 1684 for P := CurrentStation.MapStation.Passengers.Count - 1 downto 0 do begin 1686 1685 if (Passengers.Count < TrainPassengerCount) then begin 1687 Passenger := TMetroPassenger(CurrentStation.MapStation.Passengers[P]);1686 Passenger := CurrentStation.MapStation.Passengers[P]; 1688 1687 if CurrentStation.MapStation.IsBestStationForShape(Passenger.Shape, 1689 1688 TargetStation, CurrentStation) then begin … … 1691 1690 CurrentStation.MapStation.Passengers.Delete(P); 1692 1691 Passengers.Add(Passenger); 1693 Passenger.Train := T MetroTrain(Trains[I]);1692 Passenger.Train := Trains[I]; 1694 1693 end; 1695 1694 end else Break; // No more space … … 1707 1706 if Assigned(BaseTrackPoint) then 1708 1707 while (Direction = -1) and (RelPos < 0) do begin 1709 if BaseTrackPoint <> TLineStation(Line.LineStations.First).TrackPoint then begin1708 if BaseTrackPoint <> Line.LineStations.First.TrackPoint then begin 1710 1709 BaseTrackPoint := BaseTrackPoint.GetNeighDown; 1711 1710 if Assigned(BaseTrackPoint) then 1712 1711 RelPos := RelPos + BaseTrackPoint.GetDistance 1713 1712 else begin 1714 BaseTrackPoint := TLineStation(Line.LineStations.First).TrackPoint;1713 BaseTrackPoint := Line.LineStations.First.TrackPoint; 1715 1714 RelPos := 0; 1716 1715 end; 1717 1716 end else 1718 1717 if Line.IsCircular then begin 1719 BaseTrackPoint := TLineStation(Line.LineStations.Last).TrackPoint;1718 BaseTrackPoint := Line.LineStations.Last.TrackPoint; 1720 1719 RelPos := RelPos + BaseTrackPoint.GetDistance; 1721 1720 end else begin … … 1726 1725 if Assigned(BaseTrackPoint) then 1727 1726 while (Direction = 1) and (RelPos > BaseTrackPoint.GetDistance) do begin 1728 if BaseTrackPoint <> TLineStation(Line.LineStations.Last).TrackPoint then begin1727 if BaseTrackPoint <> Line.LineStations.Last.TrackPoint then begin 1729 1728 RelPos := RelPos - BaseTrackPoint.GetDistance; 1730 1729 BaseTrackPoint := BaseTrackPoint.GetNeighUp; 1731 1730 if not Assigned(BaseTrackPoint) then begin 1732 BaseTrackPoint := TLineStation(Line.LineStations.Last).TrackPoint;1731 BaseTrackPoint := Line.LineStations.Last.TrackPoint; 1733 1732 RelPos := 0; 1734 1733 end; … … 1736 1735 if Line.IsCircular then begin 1737 1736 RelPos := RelPos - BaseTrackPoint.GetDistance; 1738 BaseTrackPoint := TLineStation(Line.LineStations.First).TrackPoint;1737 BaseTrackPoint := Line.LineStations.First.TrackPoint; 1739 1738 end else begin 1740 1739 RelPos := BaseTrackPoint.GetDistance; … … 1762 1761 begin 1763 1762 I := 0; 1764 while (I < Lines.Count) and ( TMetroLine(Lines[I]).Track.Points.Count > 0) do Inc(I);1765 if I < Lines.Count then Result := TMetroLine(Lines[I])1763 while (I < Lines.Count) and (Lines[I].Track.Points.Count > 0) do Inc(I); 1764 if I < Lines.Count then Result := Lines[I] 1766 1765 else Result := nil; 1767 1766 end; … … 2025 2024 ((Line.LineStations.SearchMapStation(FocusedStation) = nil) or 2026 2025 ((Line.LineStations.Count > 0) and 2027 (( TLineStation(Line.LineStations.First).MapStation = FocusedStation) or2028 ( TLineStation(Line.LineStations.Last).MapStation = FocusedStation)) and2026 ((Line.LineStations.First.MapStation = FocusedStation) or 2027 (Line.LineStations.Last.MapStation = FocusedStation)) and 2029 2028 ((TrackStationDown = nil) or (TrackStationUp = nil)) and 2030 2029 (not Line.IsCircular))) then begin … … 2058 2057 FocusedTrack := GetTrackOnPos(View.PointDestToSrc(Position)); 2059 2058 if Assigned(FocusedTrack.Points[0]) then begin 2060 SelectedTrain.Line := TTrackPoint(FocusedTrack.Points[0]).Track.Line;2059 SelectedTrain.Line := FocusedTrack.Points[0].Track.Line; 2061 2060 SelectedTrain.Line.Trains.Add(SelectedTrain); 2062 SelectedTrain.BaseTrackPoint := TTrackPoint(FocusedTrack.Points[0]);2061 SelectedTrain.BaseTrackPoint := FocusedTrack.Points[0]; 2063 2062 end else 2064 2063 if Assigned(FocusedTrack.Points[1]) then begin 2065 SelectedTrain.Line := TTrackPoint(FocusedTrack.Points[1]).Track.Line;2064 SelectedTrain.Line := FocusedTrack.Points[1].Track.Line; 2066 2065 SelectedTrain.Line.Trains.Add(SelectedTrain); 2067 SelectedTrain.BaseTrackPoint := TTrackPoint(FocusedTrack.Points[1]);2066 SelectedTrain.BaseTrackPoint := FocusedTrack.Points[1]; 2068 2067 end; 2069 2068 FocusedTrack.Free; … … 2074 2073 if Distance(Point(View.DestRect.Right div 2 - Length(LineColors) div 2 * LineColorsDist + I * LineColorsDist, 2075 2074 View.DestRect.Bottom - LineColorsDist), Position) < 20 then begin 2076 SelectedLine := TMetroLine(Lines[I]);2075 SelectedLine := Lines[I]; 2077 2076 Exit; 2078 2077 end; … … 2080 2079 // Remove single line station on line 2081 2080 if Assigned(TrackStationDown) and (TrackStationDown.Track.Line.LineStations.Count = 1) then begin 2082 TrackStationDown.Track.Line.DisconnectStation(T LineStation(TrackStationDown.Track.Line.LineStations.First));2081 TrackStationDown.Track.Line.DisconnectStation(TrackStationDown.Track.Line.LineStations.First); 2083 2082 end; 2084 2083 if Assigned(TrackStationUp) and (TrackStationUp.Track.Line.LineStations.Count = 1) then begin 2085 TrackStationUp.Track.Line.DisconnectStation(T LineStation(TrackStationUp.Track.Line.LineStations.First));2084 TrackStationUp.Track.Line.DisconnectStation(TrackStationUp.Track.Line.LineStations.First); 2086 2085 end; 2087 2086 end else … … 2123 2122 Track := GetTrackOnPos(View.PointDestToSrc(Position)); 2124 2123 if Assigned(Track) and Assigned(Track.Points[0]) and Assigned(Track.Points[1]) then begin 2125 SelectedLine := T TrackPoint(Track.Points[0]).Track.Line;2126 2127 TrackStationDown := T TrackPoint(Track.Points[0]);2124 SelectedLine := Track.Points[0].Track.Line; 2125 2126 TrackStationDown := Track.Points[0]; 2128 2127 NewIndex := TrackStationDown.Track.Points.IndexOf(TrackStationDown); 2129 2128 while Assigned(TrackStationDown) and (not Assigned(TrackStationDown.LineStation)) do begin 2130 2129 NewIndex := NewIndex - 1; 2131 if NewIndex >= 0 then TrackStationDown := T TrackPoint(TrackStationDown.Track.Points[NewIndex])2130 if NewIndex >= 0 then TrackStationDown := TrackStationDown.Track.Points[NewIndex] 2132 2131 else TrackStationDown := nil; 2133 2132 end; 2134 TrackStationUp := T TrackPoint(Track.Points[1]);2133 TrackStationUp := Track.Points[1]; 2135 2134 NewIndex := TrackStationUp.Track.Points.IndexOf(TrackStationDown); 2136 2135 while Assigned(TrackStationUp) and (not Assigned(TrackStationUp.LineStation)) do begin 2137 2136 NewIndex := NewIndex + 1; 2138 2137 if NewIndex < TrackStationUp.Track.Points.Count then 2139 TrackStationUp := T TrackPoint(TrackStationUp.Track.Points[NewIndex])2138 TrackStationUp := TrackStationUp.Track.Points[NewIndex] 2140 2139 else TrackStationUp := nil; 2141 2140 end; … … 2152 2151 if Assigned(NewLine) then begin 2153 2152 NewLine.ConnectStation(Station, nil, nil); 2154 TrackStationDown := TTrackPoint(NewLine.Track.Points.Last);2153 TrackStationDown := NewLine.Track.Points.Last; 2155 2154 TrackStationUp := nil; 2156 2155 LastFocusedStation := Station; … … 2239 2238 FreeAndNil(Stations); 2240 2239 FreeAndNil(Lines); 2241 inherited Destroy;2240 inherited; 2242 2241 end; 2243 2242 … … 2293 2292 { if (S = TrackPoints.Count - 1) then begin 2294 2293 Canvas.Pen.EndCap := pecSquare; 2295 Angle := arctan2(( TTrackPoint(TrackPoints[S]).Position.Y - TTrackPoint(TrackPoints[S - 1]).Position.Y),2296 (T TrackPoint(TrackPoints[S]).Position.X - TTrackPoint(TrackPoints[S - 1]).Position.X));2297 EndPoint := Point(Round(T TrackPoint(TrackPoints[S]).Position.X + EndStationLength * Cos(Angle)),2298 Round(T TrackPoint(TrackPoints[S]).Position.Y + EndStationLength * Sin(Angle)));2294 Angle := arctan2(((TrackPoints[S].Position.Y - TrackPoints[S - 1].Position.Y), 2295 (TrackPoints[S].Position.X - TrackPoints[S - 1].Position.X)); 2296 EndPoint := Point(Round(TrackPoints[S].Position.X + EndStationLength * Cos(Angle)), 2297 Round(TrackPoints[S].Position.Y + EndStationLength * Sin(Angle))); 2299 2298 Canvas.LineTo(EndPoint); 2300 2299 Canvas.MoveTo(Point(Round(EndPoint.X + Cos(Angle + Pi / 2) * EndStationLength / 3), … … 2308 2307 Canvas.Pen.Style := psSolid; 2309 2308 Canvas.Pen.Width := MetroLineThickness div 2; 2310 if Track.Points.Count > 0 then Canvas.MoveTo(T TrackPoint(Track.Points[0]).PositionDesigned);2309 if Track.Points.Count > 0 then Canvas.MoveTo(Track.Points[0].PositionDesigned); 2311 2310 for S := 1 to Track.Points.Count - 1 do begin 2312 Canvas.LineTo(T TrackPoint(Track.Points[S]).PositionDesigned);2311 Canvas.LineTo(Track.Points[S].PositionDesigned); 2313 2312 { if (S = TrackPoints.Count - 1) then begin 2314 2313 Canvas.Pen.EndCap := pecSquare; 2315 Angle := arctan2((T TrackPoint(TrackPoints[S]).Position.Y - TTrackPoint(TrackPoints[S - 1]).Position.Y),2316 (T TrackPoint(TrackPoints[S]).Position.X - TTrackPoint(TrackPoints[S - 1]).Position.X));2317 EndPoint := Point(Round(T TrackPoint(TrackPoints[S]).Position.X + EndStationLength * Cos(Angle)),2318 Round(T TrackPoint(TrackPoints[S]).Position.Y + EndStationLength * Sin(Angle)));2314 Angle := arctan2((TrackPoints[S].Position.Y - TrackPoints[S - 1].Position.Y), 2315 (TrackPoints[S].Position.X - TrackPoints[S - 1].Position.X)); 2316 EndPoint := Point(Round(TrackPoints[S].Position.X + EndStationLength * Cos(Angle)), 2317 Round(TrackPoints[S].Position.Y + EndStationLength * Sin(Angle))); 2319 2318 Canvas.LineTo(EndPoint); 2320 2319 Canvas.MoveTo(Point(Round(EndPoint.X + Cos(Angle + Pi / 2) * EndStationLength / 3), … … 2328 2327 if (TrackPoints.Count > 1) then begin 2329 2328 Canvas.Pen.EndCap := pecSquare; 2330 Angle := arctan2((T TrackPoint(TrackPoints[1]).Position.Y - TTrackPoint(TrackPoints[0]).Position.Y),2331 (T TrackPoint(TrackPoints[1]).Position.X - TTrackPoint(TrackPoints[0]).Position.X));2332 Canvas.MoveTo(T TrackPoint(TrackPoints[0]).Position);2333 EndPoint := Point(Round(T TrackPoint(TrackPoints[0]).Position.X - EndStationLength * Cos(Angle)),2334 Round(T TrackPoint(TrackPoints[0]).Position.Y - EndStationLength * Sin(Angle)));2329 Angle := arctan2((TrackPoints[1].Position.Y - TrackPoints[0].Position.Y), 2330 (TrackPoints[1].Position.X - TrackPoints[0].Position.X)); 2331 Canvas.MoveTo(TrackPoints[0].Position); 2332 EndPoint := Point(Round(TrackPoints[0].Position.X - EndStationLength * Cos(Angle)), 2333 Round(TrackPoints[0].Position.Y - EndStationLength * Sin(Angle))); 2335 2334 Canvas.LineTo(EndPoint); 2336 2335 Canvas.MoveTo(Point(Round(EndPoint.X - Cos(Angle + Pi / 2) * EndStationLength / 3), -
trunk/UTrack.pas
r29 r59 6 6 7 7 uses 8 Classes, SysUtils, Contnrs;8 Classes, SysUtils, fgl; 9 9 10 10 type … … 28 28 { TTrackPoints } 29 29 30 TTrackPoints = class(T ObjectList)30 TTrackPoints = class(TFPGObjectList<TTrackPoint>) 31 31 end; 32 32 … … 42 42 { TTrackLinks } 43 43 44 TTrackLinks = class(T ObjectList)44 TTrackLinks = class(TFPGObjectList<TTrackLink>) 45 45 function SearchPoints(Point1, Point2: TTrackPoint): TTrackLink; 46 46 end; … … 58 58 end; 59 59 60 60 61 implementation 61 62 … … 68 69 I := 0; 69 70 while (I < 0) and 70 (( TTrackLink(Items[I]).Points.First <> Point1) or (TTrackLink(Items[I]).Points.Last <> Point2))71 and (( TTrackLink(Items[I]).Points.First <> Point2) or (TTrackLink(Items[I]).Points.Last <> Point1)) do71 ((Items[I].Points.First <> Point1) or (Items[I].Points.Last <> Point2)) 72 and ((Items[I].Points.First <> Point2) or (Items[I].Points.Last <> Point1)) do 72 73 Inc(I); 73 if I < 0 then Result := TTrackLink(Items[I])74 if I < 0 then Result := Items[I] 74 75 else Result := nil; 75 76 end; … … 86 87 begin 87 88 Points.Free; 88 inherited Destroy;89 inherited; 89 90 end; 90 91 … … 146 147 // Disconnect from all before destruction 147 148 for I := NeighPoints.Count - 1 downto 0 do 148 TTrackPoint(NeighPoints[I]).Disconnect(Self);149 NeighPoints[I].Disconnect(Self); 149 150 if Assigned(Track) then Track.Points.Remove(Self); 150 151 NeighPoints.Free; 151 inherited Destroy;152 inherited; 152 153 end; 153 154 … … 162 163 begin 163 164 Points.Free; 164 inherited Destroy;165 inherited; 165 166 end; 166 167
Note:
See TracChangeset
for help on using the changeset viewer.