Changeset 106
- Timestamp:
- Oct 4, 2022, 3:40:36 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UEngine.pas
r105 r106 128 128 procedure FindTargetStation; 129 129 function GetTargetStationDistance: Integer; 130 function GetPosition: TPoint;131 function GetAngle: Double;132 function GetVector: TVector;133 130 constructor Create; 134 131 destructor Destroy; override; … … 190 187 CarriageCountVisible: Boolean; 191 188 TerminalCountVisible: Boolean; 189 GrabbedTrainLastTrackPosition: TTrackPosition; 190 GrabbedTrainDirection: Integer; 192 191 function GetServedDaysCount: Integer; 193 192 procedure ResizeView; … … 326 325 MaxPassengersOveloadTime = 2; 327 326 MetroLineThickness = 13; 328 TrackClickDistance = 20;327 TrackClickDistance = 10; 329 328 EndStationLength = 50; 330 329 ShowDistances = False; … … 404 403 function TMetroCarriage.GetVector: TVector; 405 404 begin 406 Result := Train. GetVector;405 Result := Train.TrackPosition.GetVector; 407 406 Result.Position := AddPoint(Result.Position, Point(TrainSize, TrainSize)); 408 407 end; … … 829 828 Result := Result + Trunc(TrackPosition.RelPos); 830 829 end else Result := Trunc(TrackPosition.RelPos); 831 end;832 end;833 834 function TMetroTrain.GetPosition: TPoint;835 var836 D: Integer;837 Delta: TPoint;838 UpPoint: TTrackPoint;839 begin840 Result := Point(0, 0);841 if Assigned(TrackPosition.BaseTrackPoint) then842 with TrackPosition.BaseTrackPoint do begin843 UpPoint := TrackPosition.BaseTrackPoint.GetNeighUp;844 if Assigned(UpPoint) then begin845 D := Distance(UpPoint.Position, Position);846 if D > 0 then begin847 Delta := SubPoint(UpPoint.Position, Position);848 Result := Point(Trunc(Position.X + Delta.X * TrackPosition.RelPos / D),849 Trunc(Position.Y + Delta.Y * TrackPosition.RelPos / D));850 end;851 end;852 end;853 end;854 855 function TMetroTrain.GetAngle: Double;856 var857 UpPoint: TTrackPoint;858 begin859 Result := 0;860 if Assigned(TrackPosition.BaseTrackPoint) then861 with TrackPosition.BaseTrackPoint do begin862 UpPoint := TrackPosition.BaseTrackPoint.GetNeighUp;863 if Assigned(UpPoint) then begin864 Result := ArcTan2(UpPoint.Position.Y - Position.Y,865 UpPoint.Position.X - Position.X);866 end;867 end;868 end;869 870 function TMetroTrain.GetVector: TVector;871 var872 D: Integer;873 UpPoint: TTrackPoint;874 begin875 Result.Position := Point(0, 0);876 if Assigned(TrackPosition.BaseTrackPoint) then877 with TrackPosition.BaseTrackPoint do begin878 UpPoint := TrackPosition.BaseTrackPoint.GetNeighUp;879 if Assigned(UpPoint) then begin880 D := Distance(UpPoint.Position, Position);881 if D > 0 then begin882 Result.Direction := SubPoint(UpPoint.Position, Position);883 Result.Position := Point(Trunc(Position.X + Result.Direction.X * TrackPosition.RelPos / D),884 Trunc(Position.Y + Result.Direction.Y * TrackPosition.RelPos / D));885 end;886 end;887 830 end; 888 831 end; … … 1183 1126 MinDistance := High(Integer); 1184 1127 for I := 0 to Trains.Count - 1 do 1185 with T rains[I]do begin1186 D := Distance( GetPosition, Pos);1128 with TMetroTrain(Trains[I]) do begin 1129 D := Distance(TrackPosition.GetVector.Position, Pos); 1187 1130 if (D < (TrainSize div 2)) and (D < MinDistance) then begin 1188 1131 Result := Trains[I]; … … 2196 2139 Canvas.Brush.Style := bsSolid; 2197 2140 Canvas.Pen.Style := psClear; 2198 Vector := GetVector;2141 Vector := TrackPosition.GetVector; 2199 2142 Pos := Vector.Position; 2200 2143 Angle := Vector.GetAngle; … … 2781 2724 Pos: TPoint; 2782 2725 Angle: Double; 2726 FocusedTrack: TTrackLink; 2727 Vector: TVector; 2728 Intersect: TPoint; 2729 TrackPosition: TTrackPosition; 2783 2730 begin 2784 2731 // Show train grabbed by mouse 2732 Angle := 0; 2733 Pos := LastMousePos; 2734 2785 2735 if Assigned(SelectedTrain) then begin 2736 FocusedTrack := GetTrackOnPos(View.PointDestToSrc(Pos), Intersect); 2737 if Assigned(FocusedTrack.Points[0]) then begin 2738 TrackPosition.BaseTrackPoint := FocusedTrack.Points[0]; 2739 TrackPosition.RelPos := Distance(FocusedTrack.Points[0].Position, 2740 Intersect); 2741 Vector := TrackPosition.GetVector; 2742 Angle := Vector.GetAngle; 2743 2744 if TrackPosition.GetTrackPosition > 2745 GrabbedTrainLastTrackPosition.GetTrackPosition then 2746 GrabbedTrainDirection := 1 2747 else 2748 if TrackPosition.GetTrackPosition < 2749 GrabbedTrainLastTrackPosition.GetTrackPosition then 2750 GrabbedTrainDirection := -1; 2751 2752 GrabbedTrainLastTrackPosition := TrackPosition; 2753 end; 2754 FocusedTrack.Free; 2755 2756 if GrabbedTrainDirection = -1 then Angle := Angle + Pi; 2786 2757 Canvas.Brush.Color := Colors.Text; //SelectedTrain.Line.Color; 2787 2758 Canvas.Brush.Style := bsSolid; 2788 2759 Canvas.Pen.Style := psClear; 2789 Pos := LastMousePos;2790 Angle := 0;2791 2792 2760 Canvas.Polygon([ 2793 2761 RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y - TrainSize div 3), Angle), 2794 RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y - TrainSize div 3), Angle), 2795 RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y + TrainSize div 3), Angle), 2762 RotatePoint(Pos, Point(Pos.X + TrainSize div 2 - 10, Pos.Y - TrainSize div 3), Angle), 2763 RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y), Angle), 2764 RotatePoint(Pos, Point(Pos.X + TrainSize div 2 - 10, Pos.Y + TrainSize div 3), Angle), 2796 2765 RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y + TrainSize div 3), Angle) 2797 2766 ]); … … 3029 2998 SelectedTrain.TrackPosition.RelPos := Distance(FocusedTrack.Points[0].Position, 3030 2999 Intersect); 3031 if (SelectedTrain.Direction <> 1) and (SelectedTrain.Direction <> -1) then 3032 SelectedTrain.Direction := 1 3033 else SelectedTrain.Direction := -SelectedTrain.Direction; 3000 SelectedTrain.Direction := GrabbedTrainDirection; 3034 3001 SelectedTrain.FindTargetStation; 3035 3002 SelectedTrain.LastTrainMoveTime := Time; -
trunk/UTrack.pas
r93 r106 18 18 BaseTrackPoint: TTrackPoint; 19 19 RelPos: Double; 20 function GetTrackPosition: Integer; 20 21 function GetVector: TVector; 21 22 procedure Move(Distance: Double); … … 43 44 function GetLinkDown: TTrackLink; 44 45 function GetLinkUp: TTrackLink; 46 function GetTrackPosition: Integer; 47 45 48 // Move to TTrackLink later 46 49 function GetDistance: Integer; … … 109 112 110 113 { TTrackPosition } 114 115 function TTrackPosition.GetTrackPosition: Integer; 116 begin 117 Result := Round(RelPos); 118 if Assigned(BaseTrackPoint) then 119 Result := Result + BaseTrackPoint.GetTrackPosition; 120 end; 111 121 112 122 function TTrackPosition.GetVector: TVector; … … 411 421 end; 412 422 423 function TTrackPoint.GetTrackPosition: Integer; 424 var 425 Index: Integer; 426 I: Integer; 427 begin 428 Result := 0; 429 Index := Track.Points.IndexOf(Self); 430 for I := 0 to Index - 1 do 431 Result := Result + Track.Points[I].GetDistance; 432 end; 433 413 434 function TTrackPoint.GetDistance: Integer; 414 435 var
Note:
See TracChangeset
for help on using the changeset viewer.